mirror of
https://github.com/bblanchon/ArduinoJson.git
synced 2025-07-16 12:02:14 +02:00
Test that integers can be stored in a JsonObject
This commit is contained in:
@ -24,7 +24,7 @@ struct JsonNode
|
|||||||
|
|
||||||
union
|
union
|
||||||
{
|
{
|
||||||
// int asInteger;
|
int asInteger;
|
||||||
|
|
||||||
struct
|
struct
|
||||||
{
|
{
|
||||||
|
@ -48,7 +48,7 @@ size_t JsonObject::size()
|
|||||||
JsonValue JsonObject::operator[](char const* key)
|
JsonValue JsonObject::operator[](char const* key)
|
||||||
{
|
{
|
||||||
JsonNode* node = getOrCreateNodeAt(key);
|
JsonNode* node = getOrCreateNodeAt(key);
|
||||||
return JsonValue(/*node*/);
|
return JsonValue(node);
|
||||||
}
|
}
|
||||||
|
|
||||||
JsonNode* JsonObject::getOrCreateNodeAt(char const* key)
|
JsonNode* JsonObject::getOrCreateNodeAt(char const* key)
|
||||||
|
28
srcs/JsonValue.cpp
Normal file
28
srcs/JsonValue.cpp
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
#include "JsonObject.h"
|
||||||
|
#include "JsonNode.h"
|
||||||
|
#include "JsonValue.h"
|
||||||
|
|
||||||
|
//void JsonValue::operator=(JsonObject const& object)
|
||||||
|
//{
|
||||||
|
// _node = object._node;
|
||||||
|
//}
|
||||||
|
|
||||||
|
void JsonValue::operator=(int value)
|
||||||
|
{
|
||||||
|
if (!_node) return;
|
||||||
|
|
||||||
|
_node->type = JSON_INTEGER;
|
||||||
|
_node->content.asInteger = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
//JsonValue::operator JsonObject()
|
||||||
|
//{
|
||||||
|
// return JsonObject(_buffer, _node);
|
||||||
|
//}
|
||||||
|
|
||||||
|
JsonValue::operator int()
|
||||||
|
{
|
||||||
|
if (!_node || _node->type != JSON_INTEGER) return 0;
|
||||||
|
|
||||||
|
return _node->content.asInteger;
|
||||||
|
}
|
@ -6,21 +6,21 @@
|
|||||||
|
|
||||||
class JsonValue
|
class JsonValue
|
||||||
{
|
{
|
||||||
//public:
|
public:
|
||||||
//
|
|
||||||
// JsonValue(JsonBuffer& buffer, JsonNode& node)
|
JsonValue(JsonNode* node)
|
||||||
// : _buffer(buffer), _node(node)
|
: _node(node)
|
||||||
// {
|
{
|
||||||
// }
|
}
|
||||||
//
|
|
||||||
// void operator=(const JsonObject& object);
|
// void operator=(const JsonObject& object);
|
||||||
// void operator=(int);
|
void operator=(int);
|
||||||
//
|
|
||||||
// operator JsonObject();
|
// operator JsonObject();
|
||||||
// operator int();
|
operator int();
|
||||||
//
|
|
||||||
//private:
|
private:
|
||||||
// JsonBuffer& _buffer;
|
//JsonBuffer& _buffer;
|
||||||
// JsonNode& _node;
|
JsonNode* _node;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -74,6 +74,7 @@
|
|||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ClCompile Include="JsonBuffer.cpp" />
|
<ClCompile Include="JsonBuffer.cpp" />
|
||||||
<ClCompile Include="JsonObject.cpp" />
|
<ClCompile Include="JsonObject.cpp" />
|
||||||
|
<ClCompile Include="JsonValue.cpp" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
||||||
<ImportGroup Label="ExtensionTargets">
|
<ImportGroup Label="ExtensionTargets">
|
||||||
|
@ -38,5 +38,8 @@
|
|||||||
<ClCompile Include="JsonBuffer.cpp">
|
<ClCompile Include="JsonBuffer.cpp">
|
||||||
<Filter>Source Files</Filter>
|
<Filter>Source Files</Filter>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
|
<ClCompile Include="JsonValue.cpp">
|
||||||
|
<Filter>Source Files</Filter>
|
||||||
|
</ClCompile>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
</Project>
|
</Project>
|
@ -26,4 +26,17 @@ TEST(JsonObjectTests, WhenTheSameValueIsAddedTwice_ThenSizeIsOnlyIncreasedByOne)
|
|||||||
|
|
||||||
object["hello"];
|
object["hello"];
|
||||||
EXPECT_EQ(1, object.size());
|
EXPECT_EQ(1, object.size());
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(JsonObjectTests, WhenAnIntegerIsStore_TheSameIntegerIsRetreived)
|
||||||
|
{
|
||||||
|
StaticJsonBuffer<42> json;
|
||||||
|
|
||||||
|
JsonObject object = json.createObject();
|
||||||
|
|
||||||
|
object["hello"] = 123;
|
||||||
|
object["world"] = 456;
|
||||||
|
|
||||||
|
EXPECT_EQ(123, (int) object["hello"]);
|
||||||
|
EXPECT_EQ(456, (int) object["world"]);
|
||||||
}
|
}
|
Reference in New Issue
Block a user