forked from bblanchon/ArduinoJson
Test that JsonObject.size() is increased when values are added
This commit is contained in:
38
srcs/JsonObject.cpp
Normal file
38
srcs/JsonObject.cpp
Normal file
@ -0,0 +1,38 @@
|
|||||||
|
//#include "JsonBuffer.h"
|
||||||
|
#include "JsonObject.h"
|
||||||
|
#include "JsonValue.h"
|
||||||
|
//#include "JsonNode.h"
|
||||||
|
|
||||||
|
|
||||||
|
//JsonValue& JsonObject::operator[](char const* key)
|
||||||
|
//{
|
||||||
|
// addNodeAt(key, innerObject._node);
|
||||||
|
// return innerObject;
|
||||||
|
//}
|
||||||
|
//
|
||||||
|
//void JsonObject::addNodeAt(const char* key, JsonNode& node)
|
||||||
|
//{
|
||||||
|
// JsonNode& keyNode = _buffer.createNode();
|
||||||
|
// keyNode.becomeKey(key, node);
|
||||||
|
// appendChild(keyNode);
|
||||||
|
//}
|
||||||
|
//
|
||||||
|
//void JsonObject::appendChild(JsonNode& newChild)
|
||||||
|
//{
|
||||||
|
// JsonNode* lastChild = _node.asObjectNode.child;
|
||||||
|
// while (lastChild->next)
|
||||||
|
// {
|
||||||
|
// lastChild = lastChild->next;
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// if (lastChild)
|
||||||
|
// lastChild->next = &newChild;
|
||||||
|
// else
|
||||||
|
// _node.asObjectNode.child = &newChild;
|
||||||
|
//}
|
||||||
|
|
||||||
|
JsonValue JsonObject::operator[](char const* key)
|
||||||
|
{
|
||||||
|
_size++;
|
||||||
|
return JsonValue();
|
||||||
|
}
|
@ -1,42 +1,52 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
class JsonBuffer;
|
class JsonBuffer;
|
||||||
struct JsonNode;
|
|
||||||
class JsonValue;
|
class JsonValue;
|
||||||
|
struct JsonNode;
|
||||||
|
|
||||||
class JsonObject
|
class JsonObject
|
||||||
{
|
{
|
||||||
// friend class JsonValue;
|
// friend class JsonValue;
|
||||||
//
|
//
|
||||||
//public:
|
//public:
|
||||||
// JsonObject(JsonBuffer& buffer, JsonNode& node)
|
// JsonObject(JsonBuffer& buffer, JsonNode& node)
|
||||||
// : _buffer(buffer), _node(node)
|
// : _buffer(buffer), _node(node)
|
||||||
// {
|
// {
|
||||||
// }
|
// }
|
||||||
//
|
//
|
||||||
// JsonObject createObject(const char* key)
|
// JsonObject createObject(const char* key)
|
||||||
// {
|
// {
|
||||||
// JsonObject innerObject = _buffer.createObject();
|
// JsonObject innerObject = _buffer.createObject();
|
||||||
// addNodeAt(key, innerObject._node);
|
// addNodeAt(key, innerObject._node);
|
||||||
// return innerObject;
|
// return innerObject;
|
||||||
// }
|
// }
|
||||||
//
|
//
|
||||||
// JsonValue& operator[](const char* key);
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
int size()
|
|
||||||
|
explicit JsonObject()
|
||||||
|
: _size(0)
|
||||||
{
|
{
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//private:
|
int size()
|
||||||
// JsonBuffer& _buffer;
|
{
|
||||||
// JsonNode& _node;
|
return _size;
|
||||||
//
|
}
|
||||||
// void addNodeAt(char const* key, JsonNode& node);
|
|
||||||
// JsonNode& getNodeAt(const char* key);
|
JsonValue operator[](const char* key);
|
||||||
//
|
|
||||||
// // TODO: pull up
|
private:
|
||||||
// void appendChild(JsonNode& newChild);
|
|
||||||
|
int _size;
|
||||||
|
|
||||||
|
// JsonBuffer& _buffer;
|
||||||
|
// JsonNode& _node;
|
||||||
|
//
|
||||||
|
// void addNodeAt(char const* key, JsonNode& node);
|
||||||
|
// JsonNode& getNodeAt(const char* key);
|
||||||
|
//
|
||||||
|
// // TODO: pull up
|
||||||
|
// void appendChild(JsonNode& newChild);
|
||||||
};
|
};
|
26
srcs/JsonValue.h
Normal file
26
srcs/JsonValue.h
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
//class JsonBuffer;
|
||||||
|
//class JsonNode;
|
||||||
|
//class JsonObject;
|
||||||
|
|
||||||
|
class JsonValue
|
||||||
|
{
|
||||||
|
//public:
|
||||||
|
//
|
||||||
|
// JsonValue(JsonBuffer& buffer, JsonNode& node)
|
||||||
|
// : _buffer(buffer), _node(node)
|
||||||
|
// {
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// void operator=(const JsonObject& object);
|
||||||
|
// void operator=(int);
|
||||||
|
//
|
||||||
|
// operator JsonObject();
|
||||||
|
// operator int();
|
||||||
|
//
|
||||||
|
//private:
|
||||||
|
// JsonBuffer& _buffer;
|
||||||
|
// JsonNode& _node;
|
||||||
|
};
|
||||||
|
|
@ -66,8 +66,12 @@
|
|||||||
</ItemDefinitionGroup>
|
</ItemDefinitionGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ClInclude Include="JsonObject.h" />
|
<ClInclude Include="JsonObject.h" />
|
||||||
|
<ClInclude Include="JsonValue.h" />
|
||||||
<ClInclude Include="StaticJsonBuffer.h" />
|
<ClInclude Include="StaticJsonBuffer.h" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<ClCompile Include="JsonObject.cpp" />
|
||||||
|
</ItemGroup>
|
||||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
||||||
<ImportGroup Label="ExtensionTargets">
|
<ImportGroup Label="ExtensionTargets">
|
||||||
</ImportGroup>
|
</ImportGroup>
|
||||||
|
@ -21,5 +21,13 @@
|
|||||||
<ClInclude Include="JsonObject.h">
|
<ClInclude Include="JsonObject.h">
|
||||||
<Filter>Header Files</Filter>
|
<Filter>Header Files</Filter>
|
||||||
</ClInclude>
|
</ClInclude>
|
||||||
|
<ClInclude Include="JsonValue.h">
|
||||||
|
<Filter>Header Files</Filter>
|
||||||
|
</ClInclude>
|
||||||
|
</ItemGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<ClCompile Include="JsonObject.cpp">
|
||||||
|
<Filter>Source Files</Filter>
|
||||||
|
</ClCompile>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
</Project>
|
</Project>
|
16
tests/JsonObjectTests.cpp
Normal file
16
tests/JsonObjectTests.cpp
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
#include <gtest/gtest.h>
|
||||||
|
#include <StaticJsonBuffer.h>
|
||||||
|
#include <JsonValue.h>
|
||||||
|
|
||||||
|
TEST(JsonObjectTests, WhenValueIsAdded_ThenSizeIsIncreasedByOne)
|
||||||
|
{
|
||||||
|
StaticJsonBuffer<42> json;
|
||||||
|
|
||||||
|
JsonObject object = json.createObject();
|
||||||
|
|
||||||
|
object["hello"];
|
||||||
|
EXPECT_EQ(1, object.size());
|
||||||
|
|
||||||
|
object["world"];
|
||||||
|
EXPECT_EQ(2, object.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="JsonObjectTests.cpp" />
|
||||||
<ClCompile Include="StaticJsonBufferTests.cpp" />
|
<ClCompile Include="StaticJsonBufferTests.cpp" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
@ -27,5 +27,8 @@
|
|||||||
<ClCompile Include="StaticJsonBufferTests.cpp">
|
<ClCompile Include="StaticJsonBufferTests.cpp">
|
||||||
<Filter>Source Files</Filter>
|
<Filter>Source Files</Filter>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
|
<ClCompile Include="JsonObjectTests.cpp">
|
||||||
|
<Filter>Source Files</Filter>
|
||||||
|
</ClCompile>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
</Project>
|
</Project>
|
Reference in New Issue
Block a user