forked from bblanchon/ArduinoJson
Test that CreateObject() returns an empty JsonObject
This commit is contained in:
42
srcs/JsonObject.h
Normal file
42
srcs/JsonObject.h
Normal file
@ -0,0 +1,42 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
class JsonBuffer;
|
||||||
|
struct JsonNode;
|
||||||
|
class JsonValue;
|
||||||
|
|
||||||
|
class JsonObject
|
||||||
|
{
|
||||||
|
// friend class JsonValue;
|
||||||
|
//
|
||||||
|
//public:
|
||||||
|
// JsonObject(JsonBuffer& buffer, JsonNode& node)
|
||||||
|
// : _buffer(buffer), _node(node)
|
||||||
|
// {
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// JsonObject createObject(const char* key)
|
||||||
|
// {
|
||||||
|
// JsonObject innerObject = _buffer.createObject();
|
||||||
|
// addNodeAt(key, innerObject._node);
|
||||||
|
// return innerObject;
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// JsonValue& operator[](const char* key);
|
||||||
|
|
||||||
|
public:
|
||||||
|
|
||||||
|
int size()
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
//private:
|
||||||
|
// JsonBuffer& _buffer;
|
||||||
|
// JsonNode& _node;
|
||||||
|
//
|
||||||
|
// void addNodeAt(char const* key, JsonNode& node);
|
||||||
|
// JsonNode& getNodeAt(const char* key);
|
||||||
|
//
|
||||||
|
// // TODO: pull up
|
||||||
|
// void appendChild(JsonNode& newChild);
|
||||||
|
};
|
@ -1,6 +1,7 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "JsonBuffer.h"
|
#include "JsonBuffer.h"
|
||||||
|
#include "JsonObject.h"
|
||||||
|
|
||||||
template<int CAPACITY>
|
template<int CAPACITY>
|
||||||
class StaticJsonBuffer //: public JsonBuffer
|
class StaticJsonBuffer //: public JsonBuffer
|
||||||
@ -14,11 +15,12 @@ public:
|
|||||||
|
|
||||||
virtual ~StaticJsonBuffer() {}
|
virtual ~StaticJsonBuffer() {}
|
||||||
|
|
||||||
/*JsonObject*/
|
JsonObject createObject()
|
||||||
void createObject()
|
|
||||||
{
|
{
|
||||||
if (_size < CAPACITY)
|
if (_size < CAPACITY)
|
||||||
_size++;
|
_size++;
|
||||||
|
|
||||||
|
return JsonObject();
|
||||||
}
|
}
|
||||||
|
|
||||||
int capacity()
|
int capacity()
|
||||||
|
@ -65,6 +65,7 @@
|
|||||||
</Link>
|
</Link>
|
||||||
</ItemDefinitionGroup>
|
</ItemDefinitionGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
<ClInclude Include="JsonObject.h" />
|
||||||
<ClInclude Include="StaticJsonBuffer.h" />
|
<ClInclude Include="StaticJsonBuffer.h" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
||||||
|
@ -18,5 +18,8 @@
|
|||||||
<ClInclude Include="StaticJsonBuffer.h">
|
<ClInclude Include="StaticJsonBuffer.h">
|
||||||
<Filter>Header Files</Filter>
|
<Filter>Header Files</Filter>
|
||||||
</ClInclude>
|
</ClInclude>
|
||||||
|
<ClInclude Include="JsonObject.h">
|
||||||
|
<Filter>Header Files</Filter>
|
||||||
|
</ClInclude>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
</Project>
|
</Project>
|
@ -34,3 +34,11 @@ TEST(StaticJsonBuffer, GivenBufferIsFull_WhenCreateObjectIsCalled_ThenSizeDoesNo
|
|||||||
json.createObject();
|
json.createObject();
|
||||||
EXPECT_EQ(1, json.size());
|
EXPECT_EQ(1, json.size());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST(StaticJsonBuffer, WhenWhenCreateObjectIsCalled_ThenAnEmptyJsonObjectIsReturned)
|
||||||
|
{
|
||||||
|
StaticJsonBuffer<42> json;
|
||||||
|
|
||||||
|
JsonObject obj = json.createObject();
|
||||||
|
EXPECT_EQ(0, obj.size());
|
||||||
|
}
|
Reference in New Issue
Block a user