forked from bblanchon/ArduinoJson
Test that JsonArray can store integers
This commit is contained in:
@ -1,2 +1,14 @@
|
|||||||
#include "JsonArray.h"
|
#include "JsonArray.h"
|
||||||
|
|
||||||
|
#include "JsonValue.h"
|
||||||
|
|
||||||
|
JsonValue JsonArray::operator[](int index) const
|
||||||
|
{
|
||||||
|
for (JsonNodeIterator it = beginChildren(); it != endChildren(); ++it)
|
||||||
|
{
|
||||||
|
if (!index) return JsonValue(*it);
|
||||||
|
index--;
|
||||||
|
}
|
||||||
|
|
||||||
|
return JsonValue();
|
||||||
|
}
|
@ -14,12 +14,18 @@ public:
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
// JsonValue operator[](int index);
|
JsonValue operator[](int index) const;
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
void add(T value)
|
void add(T value)
|
||||||
{
|
{
|
||||||
addChild(createNode(JSON_UNDEFINED));
|
JsonNode* node = createNode(JSON_UNDEFINED);
|
||||||
|
if (!node) return;
|
||||||
|
|
||||||
|
JsonValue jsonValue(node);
|
||||||
|
jsonValue = value;
|
||||||
|
|
||||||
|
addChild(node);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
class JsonObject;
|
||||||
struct JsonNode;
|
struct JsonNode;
|
||||||
|
|
||||||
class JsonValue
|
class JsonValue
|
||||||
|
@ -27,7 +27,7 @@ TEST_F(JsonArray_Container_Tests, Grow_WhenValuesAreAdded)
|
|||||||
array.add("world");
|
array.add("world");
|
||||||
EXPECT_EQ(2, array.size());
|
EXPECT_EQ(2, array.size());
|
||||||
}
|
}
|
||||||
/*
|
|
||||||
TEST_F(JsonArray_Container_Tests, CanStoreIntegers)
|
TEST_F(JsonArray_Container_Tests, CanStoreIntegers)
|
||||||
{
|
{
|
||||||
array.add(123);
|
array.add(123);
|
||||||
@ -36,7 +36,7 @@ TEST_F(JsonArray_Container_Tests, CanStoreIntegers)
|
|||||||
EXPECT_EQ(123, (int) array[0]);
|
EXPECT_EQ(123, (int) array[0]);
|
||||||
EXPECT_EQ(456, (int) array[1]);
|
EXPECT_EQ(456, (int) array[1]);
|
||||||
}
|
}
|
||||||
|
/*
|
||||||
TEST_F(JsonArray_Container_Tests, CanStoreDoubles)
|
TEST_F(JsonArray_Container_Tests, CanStoreDoubles)
|
||||||
{
|
{
|
||||||
array.add(123.45);
|
array.add(123.45);
|
||||||
|
Reference in New Issue
Block a user