diff --git a/srcs/JsonObject.cpp b/srcs/JsonObject.cpp index 1979a26b..da408a3e 100644 --- a/srcs/JsonObject.cpp +++ b/srcs/JsonObject.cpp @@ -87,4 +87,9 @@ JsonNode* JsonObject::getOrCreateNodeAt(char const* key) _node->content.asObject.child = newKeyNode; return newValueNode; +} + +void JsonObject::serialize(char* buffer, size_t bufferSize) const +{ + strcpy_s(buffer, bufferSize, "{}"); } \ No newline at end of file diff --git a/srcs/JsonObject.h b/srcs/JsonObject.h index 5b4e5657..02364810 100644 --- a/srcs/JsonObject.h +++ b/srcs/JsonObject.h @@ -24,6 +24,8 @@ public: bool operator==(const JsonObject& other) const; + void serialize(char* buffer, size_t bufferSize) const; + private: JsonNode* _node; diff --git a/tests/JsonObjectSerializationTests.cpp b/tests/JsonObjectSerializationTests.cpp new file mode 100644 index 00000000..54c46045 --- /dev/null +++ b/tests/JsonObjectSerializationTests.cpp @@ -0,0 +1,30 @@ +#include +#include +#include + +class JsonObjectSerializationTests : public testing::Test +{ +protected: + virtual void SetUp() + { + object = json.createObject(); + } + + void jsonMustBe(const char* expected) + { + char actual[256]; + object.serialize(actual, sizeof(actual)); + + EXPECT_STREQ(expected, actual); + } + + JsonObject object; + +private: + StaticJsonBuffer<42> json; +}; + +TEST_F(JsonObjectSerializationTests, EmptyObject) +{ + jsonMustBe("{}"); +} \ No newline at end of file diff --git a/tests/JsonValueTests.cpp b/tests/JsonValueTests.cpp index edea27e6..4d92b142 100644 --- a/tests/JsonValueTests.cpp +++ b/tests/JsonValueTests.cpp @@ -93,4 +93,16 @@ TEST_F(JsonValueTests, CharPointersAreCopied) jsonValue1 = "world"; EXPECT_STREQ("hello", (const char*) jsonValue2); +} + +TEST_F(JsonValueTests, ObjectPointsAreCopied) +{ + JsonObject object = json.createObject(); + + jsonValue1 = object; + jsonValue2 = jsonValue1; + + object["hello"] = "world"; + + EXPECT_EQ(1, ((JsonObject) jsonValue2).size()); } \ No newline at end of file diff --git a/tests/tests.vcxproj b/tests/tests.vcxproj index 7db8b342..ff24a906 100644 --- a/tests/tests.vcxproj +++ b/tests/tests.vcxproj @@ -85,6 +85,7 @@ + diff --git a/tests/tests.vcxproj.filters b/tests/tests.vcxproj.filters index 582073a8..d64a95af 100644 --- a/tests/tests.vcxproj.filters +++ b/tests/tests.vcxproj.filters @@ -33,5 +33,8 @@ Source Files + + Source Files + \ No newline at end of file