Test empty object serialization

This commit is contained in:
Benoit Blanchon
2014-09-30 16:31:22 +02:00
parent d3cf568d07
commit ab2587f089
6 changed files with 53 additions and 0 deletions

View File

@ -88,3 +88,8 @@ JsonNode* JsonObject::getOrCreateNodeAt(char const* key)
return newValueNode;
}
void JsonObject::serialize(char* buffer, size_t bufferSize) const
{
strcpy_s(buffer, bufferSize, "{}");
}

View File

@ -24,6 +24,8 @@ public:
bool operator==(const JsonObject& other) const;
void serialize(char* buffer, size_t bufferSize) const;
private:
JsonNode* _node;

View File

@ -0,0 +1,30 @@
#include <gtest/gtest.h>
#include <JsonObject.h>
#include <StaticJsonBuffer.h>
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("{}");
}

View File

@ -94,3 +94,15 @@ TEST_F(JsonValueTests, CharPointersAreCopied)
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());
}

View File

@ -85,6 +85,7 @@
<ItemGroup>
<ClCompile Include="..\third-party\gtest-1.7.0\src\gtest-all.cc" />
<ClCompile Include="..\third-party\gtest-1.7.0\src\gtest_main.cc" />
<ClCompile Include="JsonObjectSerializationTests.cpp" />
<ClCompile Include="JsonObjectTests.cpp" />
<ClCompile Include="JsonValueTests.cpp" />
<ClCompile Include="StaticJsonBufferTests.cpp" />

View File

@ -33,5 +33,8 @@
<ClCompile Include="JsonValueTests.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="JsonObjectSerializationTests.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
</Project>