add arduino json lib

#182
This commit is contained in:
1technophile
2018-03-07 20:52:36 +01:00
parent f0546fab8c
commit 3b4c9d2d98
209 changed files with 25587 additions and 0 deletions

View File

@@ -0,0 +1,61 @@
// ArduinoJson - arduinojson.org
// Copyright Benoit Blanchon 2014-2018
// MIT License
#include <catch.hpp>
#include <ArduinoJson/Serialization/JsonWriter.hpp>
#include <ArduinoJson/Serialization/StaticStringBuilder.hpp>
using namespace ArduinoJson::Internals;
void check(const char* input, std::string expected) {
char output[1024];
StaticStringBuilder sb(output, sizeof(output));
JsonWriter<StaticStringBuilder> writer(sb);
writer.writeString(input);
REQUIRE(expected == output);
REQUIRE(writer.bytesWritten() == expected.size());
}
TEST_CASE("JsonWriter::writeString()") {
SECTION("Null") {
check(0, "null");
}
SECTION("EmptyString") {
check("", "\"\"");
}
SECTION("QuotationMark") {
check("\"", "\"\\\"\"");
}
SECTION("ReverseSolidus") {
check("\\", "\"\\\\\"");
}
SECTION("Solidus") {
check("/", "\"/\""); // but the JSON format allows \/
}
SECTION("Backspace") {
check("\b", "\"\\b\"");
}
SECTION("Formfeed") {
check("\f", "\"\\f\"");
}
SECTION("Newline") {
check("\n", "\"\\n\"");
}
SECTION("CarriageReturn") {
check("\r", "\"\\r\"");
}
SECTION("HorizontalTab") {
check("\t", "\"\\t\"");
}
}