forked from bblanchon/ArduinoJson
Test that JsonArray grows after calling add()
This commit is contained in:
@ -16,7 +16,10 @@ public:
|
||||
|
||||
// JsonValue operator[](int index);
|
||||
|
||||
// template<typename T>
|
||||
// void add(T value);
|
||||
template<typename T>
|
||||
void add(T value)
|
||||
{
|
||||
addChild(createNode(JSON_UNDEFINED));
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -32,12 +32,20 @@ bool JsonContainer::operator==(const JsonContainer & other) const
|
||||
return _node == other._node;
|
||||
}
|
||||
|
||||
void JsonContainer::insertChildAfter(JsonNode* newChild, JsonNode* previous)
|
||||
void JsonContainer::addChild(JsonNode* newChild)
|
||||
{
|
||||
if (previous)
|
||||
previous->next = newChild;
|
||||
else
|
||||
_node->content.asContainer.child = newChild;
|
||||
JsonNode* lastChild = _node->content.asContainer.child;
|
||||
|
||||
if (!lastChild)
|
||||
{
|
||||
_node->content.asContainer.child = newChild = newChild;
|
||||
return;
|
||||
}
|
||||
|
||||
while (lastChild->next)
|
||||
lastChild = lastChild->next;
|
||||
|
||||
lastChild->next = newChild;
|
||||
}
|
||||
|
||||
void JsonContainer::removeChildAfter(JsonNode* child, JsonNode* previous)
|
||||
|
@ -41,7 +41,7 @@ protected:
|
||||
return JsonNodeIterator(0);
|
||||
}
|
||||
|
||||
void insertChildAfter(JsonNode* newChild, JsonNode* insertAfterMe);
|
||||
void addChild(JsonNode* newChild);
|
||||
void removeChildAfter(JsonNode* child, JsonNode* previous);
|
||||
JsonNode* createNode(JsonNodeType type);
|
||||
|
||||
|
@ -38,16 +38,12 @@ JsonNode* JsonObject::getOrCreateNodeAt(const char* key)
|
||||
{
|
||||
if (!checkNodeType(JSON_OBJECT)) return 0;
|
||||
|
||||
JsonNode* lastChild = 0;
|
||||
|
||||
for (JsonNodeIterator it = beginChildren(); it != endChildren(); ++it)
|
||||
{
|
||||
const char* childKey = it->content.asKey.key;
|
||||
|
||||
if (!strcmp(childKey, key))
|
||||
return it->content.asKey.value;
|
||||
|
||||
lastChild = *it;
|
||||
}
|
||||
|
||||
JsonNode* newValueNode = createNode(JSON_UNDEFINED);
|
||||
@ -59,7 +55,7 @@ JsonNode* JsonObject::getOrCreateNodeAt(const char* key)
|
||||
newKeyNode->content.asKey.key = key;
|
||||
newKeyNode->content.asKey.value = newValueNode;
|
||||
|
||||
insertChildAfter(newKeyNode, lastChild);
|
||||
addChild(newKeyNode);
|
||||
|
||||
return newValueNode;
|
||||
}
|
||||
|
@ -18,7 +18,7 @@ TEST_F(JsonArray_Container_Tests, InitialSizeIsZero)
|
||||
{
|
||||
EXPECT_EQ(0, array.size());
|
||||
}
|
||||
/*
|
||||
|
||||
TEST_F(JsonArray_Container_Tests, Grow_WhenValuesAreAdded)
|
||||
{
|
||||
array.add("hello");
|
||||
@ -27,7 +27,7 @@ TEST_F(JsonArray_Container_Tests, Grow_WhenValuesAreAdded)
|
||||
array.add("world");
|
||||
EXPECT_EQ(2, array.size());
|
||||
}
|
||||
|
||||
/*
|
||||
TEST_F(JsonArray_Container_Tests, CanStoreIntegers)
|
||||
{
|
||||
array.add(123);
|
||||
|
Reference in New Issue
Block a user