forked from bblanchon/ArduinoJson
Test that JsonArray can contain doubles
This commit is contained in:
@ -11,4 +11,31 @@ JsonValue JsonArray::operator[](int index) const
|
|||||||
}
|
}
|
||||||
|
|
||||||
return JsonValue();
|
return JsonValue();
|
||||||
|
}
|
||||||
|
|
||||||
|
void JsonArray::add(char const* value)
|
||||||
|
{
|
||||||
|
JsonNode* node = createNode(JSON_STRING);
|
||||||
|
if (!node) return;
|
||||||
|
|
||||||
|
node->content.asString = value;
|
||||||
|
addChild(node);
|
||||||
|
}
|
||||||
|
|
||||||
|
void JsonArray::add(double value, int decimals)
|
||||||
|
{
|
||||||
|
JsonNode* node = createNode((JsonNodeType)(JSON_DOUBLE_0_DECIMALS + decimals));
|
||||||
|
if (!node) return;
|
||||||
|
|
||||||
|
node->content.asDouble = value;
|
||||||
|
addChild(node);
|
||||||
|
}
|
||||||
|
|
||||||
|
void JsonArray::add(long value)
|
||||||
|
{
|
||||||
|
JsonNode* node = createNode(JSON_INTEGER);
|
||||||
|
if (!node) return;
|
||||||
|
|
||||||
|
node->content.asInteger = value;
|
||||||
|
addChild(node);
|
||||||
}
|
}
|
@ -16,16 +16,9 @@ public:
|
|||||||
|
|
||||||
JsonValue operator[](int index) const;
|
JsonValue operator[](int index) const;
|
||||||
|
|
||||||
template<typename T>
|
void add(const char* value);
|
||||||
void add(T value)
|
void add(double value, int decimals=2);
|
||||||
{
|
void add(int value) { add((long) value); }
|
||||||
JsonNode* node = createNode(JSON_UNDEFINED);
|
void add(long value);
|
||||||
if (!node) return;
|
|
||||||
|
|
||||||
JsonValue jsonValue(node);
|
|
||||||
jsonValue = value;
|
|
||||||
|
|
||||||
addChild(node);
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -19,7 +19,7 @@ size_t JsonContainer::printTo(Print& p) const
|
|||||||
JsonNode* JsonContainer::createNode(JsonNodeType type)
|
JsonNode* JsonContainer::createNode(JsonNodeType type)
|
||||||
{
|
{
|
||||||
JsonBuffer* buffer = _node->content.asContainer.buffer;
|
JsonBuffer* buffer = _node->content.asContainer.buffer;
|
||||||
return buffer->createNode(JSON_UNDEFINED);
|
return buffer->createNode(type);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool JsonContainer::checkNodeType(JsonNodeType expectedType)
|
bool JsonContainer::checkNodeType(JsonNodeType expectedType)
|
||||||
|
@ -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);
|
||||||
@ -45,7 +45,7 @@ TEST_F(JsonArray_Container_Tests, CanStoreDoubles)
|
|||||||
EXPECT_EQ(123.45, (double) array[0]);
|
EXPECT_EQ(123.45, (double) array[0]);
|
||||||
EXPECT_EQ(456.78, (double) array[1]);
|
EXPECT_EQ(456.78, (double) array[1]);
|
||||||
}
|
}
|
||||||
|
/*
|
||||||
TEST_F(JsonArray_Container_Tests, CanStoreBooleans)
|
TEST_F(JsonArray_Container_Tests, CanStoreBooleans)
|
||||||
{
|
{
|
||||||
array.add(true);
|
array.add(true);
|
||||||
|
Reference in New Issue
Block a user