|
|
@@ -10,11 +10,12 @@
|
|
|
#include <ArduinoJson/JsonValue.hpp>
|
|
|
#include <ArduinoJson/StaticJsonBuffer.hpp>
|
|
|
|
|
|
-using namespace ArduinoJson;
|
|
|
+using namespace ArduinoJson;
|
|
|
+using namespace ArduinoJson::Internals;
|
|
|
|
|
|
-class JsonObject_Serialization_Tests : public testing::Test {
|
|
|
+class JsonObject_PrintTo_Tests : public testing::Test {
|
|
|
public:
|
|
|
- JsonObject_Serialization_Tests() : object(json.createObject()) {}
|
|
|
+ JsonObject_PrintTo_Tests() : object(json.createObject()) {}
|
|
|
|
|
|
protected:
|
|
|
void outputMustBe(const char *expected) {
|
|
|
@@ -25,26 +26,26 @@ class JsonObject_Serialization_Tests : public testing::Test {
|
|
|
EXPECT_EQ(strlen(expected), result);
|
|
|
}
|
|
|
|
|
|
+ StaticJsonBuffer<JSON_OBJECT_SIZE(2)> json;
|
|
|
JsonObject &object;
|
|
|
- StaticJsonBuffer<5> json;
|
|
|
};
|
|
|
|
|
|
-TEST_F(JsonObject_Serialization_Tests, EmptyObject) { outputMustBe("{}"); }
|
|
|
+TEST_F(JsonObject_PrintTo_Tests, EmptyObject) { outputMustBe("{}"); }
|
|
|
|
|
|
-TEST_F(JsonObject_Serialization_Tests, OneString) {
|
|
|
+TEST_F(JsonObject_PrintTo_Tests, OneString) {
|
|
|
object["key"] = "value";
|
|
|
|
|
|
outputMustBe("{\"key\":\"value\"}");
|
|
|
}
|
|
|
|
|
|
-TEST_F(JsonObject_Serialization_Tests, TwoStrings) {
|
|
|
+TEST_F(JsonObject_PrintTo_Tests, TwoStrings) {
|
|
|
object["key1"] = "value1";
|
|
|
object["key2"] = "value2";
|
|
|
|
|
|
outputMustBe("{\"key1\":\"value1\",\"key2\":\"value2\"}");
|
|
|
}
|
|
|
|
|
|
-TEST_F(JsonObject_Serialization_Tests, RemoveFirst) {
|
|
|
+TEST_F(JsonObject_PrintTo_Tests, RemoveFirst) {
|
|
|
object["key1"] = "value1";
|
|
|
object["key2"] = "value2";
|
|
|
object.remove("key1");
|
|
|
@@ -52,7 +53,7 @@ TEST_F(JsonObject_Serialization_Tests, RemoveFirst) {
|
|
|
outputMustBe("{\"key2\":\"value2\"}");
|
|
|
}
|
|
|
|
|
|
-TEST_F(JsonObject_Serialization_Tests, RemoveLast) {
|
|
|
+TEST_F(JsonObject_PrintTo_Tests, RemoveLast) {
|
|
|
object["key1"] = "value1";
|
|
|
object["key2"] = "value2";
|
|
|
object.remove("key2");
|
|
|
@@ -60,7 +61,7 @@ TEST_F(JsonObject_Serialization_Tests, RemoveLast) {
|
|
|
outputMustBe("{\"key1\":\"value1\"}");
|
|
|
}
|
|
|
|
|
|
-TEST_F(JsonObject_Serialization_Tests, RemoveUnexistingKey) {
|
|
|
+TEST_F(JsonObject_PrintTo_Tests, RemoveUnexistingKey) {
|
|
|
object["key1"] = "value1";
|
|
|
object["key2"] = "value2";
|
|
|
object.remove("key3");
|
|
|
@@ -68,14 +69,14 @@ TEST_F(JsonObject_Serialization_Tests, RemoveUnexistingKey) {
|
|
|
outputMustBe("{\"key1\":\"value1\",\"key2\":\"value2\"}");
|
|
|
}
|
|
|
|
|
|
-TEST_F(JsonObject_Serialization_Tests, ReplaceExistingKey) {
|
|
|
+TEST_F(JsonObject_PrintTo_Tests, ReplaceExistingKey) {
|
|
|
object["key"] = "value1";
|
|
|
object["key"] = "value2";
|
|
|
|
|
|
outputMustBe("{\"key\":\"value2\"}");
|
|
|
}
|
|
|
|
|
|
-TEST_F(JsonObject_Serialization_Tests, OneStringOverCapacity) {
|
|
|
+TEST_F(JsonObject_PrintTo_Tests, OneStringOverCapacity) {
|
|
|
object["key1"] = "value1";
|
|
|
object["key2"] = "value2";
|
|
|
object["key3"] = "value3";
|
|
|
@@ -83,37 +84,37 @@ TEST_F(JsonObject_Serialization_Tests, OneStringOverCapacity) {
|
|
|
outputMustBe("{\"key1\":\"value1\",\"key2\":\"value2\"}");
|
|
|
}
|
|
|
|
|
|
-TEST_F(JsonObject_Serialization_Tests, OneInteger) {
|
|
|
+TEST_F(JsonObject_PrintTo_Tests, OneInteger) {
|
|
|
object["key"] = 1;
|
|
|
outputMustBe("{\"key\":1}");
|
|
|
}
|
|
|
|
|
|
-TEST_F(JsonObject_Serialization_Tests, OneDoubleFourDigits) {
|
|
|
+TEST_F(JsonObject_PrintTo_Tests, OneDoubleFourDigits) {
|
|
|
object["key"].set(3.14159265358979323846, 4);
|
|
|
outputMustBe("{\"key\":3.1416}");
|
|
|
}
|
|
|
|
|
|
-TEST_F(JsonObject_Serialization_Tests, OneDoubleDefaultDigits) {
|
|
|
+TEST_F(JsonObject_PrintTo_Tests, OneDoubleDefaultDigits) {
|
|
|
object["key"] = 3.14159265358979323846;
|
|
|
outputMustBe("{\"key\":3.14}");
|
|
|
}
|
|
|
|
|
|
-TEST_F(JsonObject_Serialization_Tests, OneNull) {
|
|
|
+TEST_F(JsonObject_PrintTo_Tests, OneNull) {
|
|
|
object["key"] = static_cast<char *>(0);
|
|
|
outputMustBe("{\"key\":null}");
|
|
|
}
|
|
|
|
|
|
-TEST_F(JsonObject_Serialization_Tests, OneTrue) {
|
|
|
+TEST_F(JsonObject_PrintTo_Tests, OneTrue) {
|
|
|
object["key"] = true;
|
|
|
outputMustBe("{\"key\":true}");
|
|
|
}
|
|
|
|
|
|
-TEST_F(JsonObject_Serialization_Tests, OneFalse) {
|
|
|
+TEST_F(JsonObject_PrintTo_Tests, OneFalse) {
|
|
|
object["key"] = false;
|
|
|
outputMustBe("{\"key\":false}");
|
|
|
}
|
|
|
|
|
|
-TEST_F(JsonObject_Serialization_Tests, OneEmptyNestedArrayViaProxy) {
|
|
|
+TEST_F(JsonObject_PrintTo_Tests, OneEmptyNestedArrayViaProxy) {
|
|
|
JsonArray &nestedArray = json.createArray();
|
|
|
|
|
|
object["key"] = nestedArray;
|
|
|
@@ -121,7 +122,7 @@ TEST_F(JsonObject_Serialization_Tests, OneEmptyNestedArrayViaProxy) {
|
|
|
outputMustBe("{\"key\":[]}");
|
|
|
}
|
|
|
|
|
|
-TEST_F(JsonObject_Serialization_Tests, OneEmptyNestedObjectViaProxy) {
|
|
|
+TEST_F(JsonObject_PrintTo_Tests, OneEmptyNestedObjectViaProxy) {
|
|
|
JsonObject &nestedArray = json.createObject();
|
|
|
|
|
|
object["key"] = nestedArray;
|
|
|
@@ -129,13 +130,13 @@ TEST_F(JsonObject_Serialization_Tests, OneEmptyNestedObjectViaProxy) {
|
|
|
outputMustBe("{\"key\":{}}");
|
|
|
}
|
|
|
|
|
|
-TEST_F(JsonObject_Serialization_Tests, OneEmptyNestedObject) {
|
|
|
+TEST_F(JsonObject_PrintTo_Tests, OneEmptyNestedObject) {
|
|
|
object.createNestedObject("key");
|
|
|
|
|
|
outputMustBe("{\"key\":{}}");
|
|
|
}
|
|
|
|
|
|
-TEST_F(JsonObject_Serialization_Tests, OneEmptyNestedArray) {
|
|
|
+TEST_F(JsonObject_PrintTo_Tests, OneEmptyNestedArray) {
|
|
|
object.createNestedArray("key");
|
|
|
|
|
|
outputMustBe("{\"key\":[]}");
|