mirror of
https://github.com/bblanchon/ArduinoJson.git
synced 2025-07-16 12:02:14 +02:00
Test empty object serialization
This commit is contained in:
@ -87,4 +87,9 @@ JsonNode* JsonObject::getOrCreateNodeAt(char const* key)
|
|||||||
_node->content.asObject.child = newKeyNode;
|
_node->content.asObject.child = newKeyNode;
|
||||||
|
|
||||||
return newValueNode;
|
return newValueNode;
|
||||||
|
}
|
||||||
|
|
||||||
|
void JsonObject::serialize(char* buffer, size_t bufferSize) const
|
||||||
|
{
|
||||||
|
strcpy_s(buffer, bufferSize, "{}");
|
||||||
}
|
}
|
@ -24,6 +24,8 @@ public:
|
|||||||
|
|
||||||
bool operator==(const JsonObject& other) const;
|
bool operator==(const JsonObject& other) const;
|
||||||
|
|
||||||
|
void serialize(char* buffer, size_t bufferSize) const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
JsonNode* _node;
|
JsonNode* _node;
|
||||||
|
|
||||||
|
30
tests/JsonObjectSerializationTests.cpp
Normal file
30
tests/JsonObjectSerializationTests.cpp
Normal 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("{}");
|
||||||
|
}
|
@ -93,4 +93,16 @@ TEST_F(JsonValueTests, CharPointersAreCopied)
|
|||||||
jsonValue1 = "world";
|
jsonValue1 = "world";
|
||||||
|
|
||||||
EXPECT_STREQ("hello", (const char*) jsonValue2);
|
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());
|
||||||
}
|
}
|
@ -85,6 +85,7 @@
|
|||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ClCompile Include="..\third-party\gtest-1.7.0\src\gtest-all.cc" />
|
<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="..\third-party\gtest-1.7.0\src\gtest_main.cc" />
|
||||||
|
<ClCompile Include="JsonObjectSerializationTests.cpp" />
|
||||||
<ClCompile Include="JsonObjectTests.cpp" />
|
<ClCompile Include="JsonObjectTests.cpp" />
|
||||||
<ClCompile Include="JsonValueTests.cpp" />
|
<ClCompile Include="JsonValueTests.cpp" />
|
||||||
<ClCompile Include="StaticJsonBufferTests.cpp" />
|
<ClCompile Include="StaticJsonBufferTests.cpp" />
|
||||||
|
@ -33,5 +33,8 @@
|
|||||||
<ClCompile Include="JsonValueTests.cpp">
|
<ClCompile Include="JsonValueTests.cpp">
|
||||||
<Filter>Source Files</Filter>
|
<Filter>Source Files</Filter>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
|
<ClCompile Include="JsonObjectSerializationTests.cpp">
|
||||||
|
<Filter>Source Files</Filter>
|
||||||
|
</ClCompile>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
</Project>
|
</Project>
|
Reference in New Issue
Block a user