mirror of
https://github.com/bblanchon/ArduinoJson.git
synced 2025-07-16 20:12:16 +02:00
Test that string can be stored in JsonObject
This commit is contained in:
@ -26,6 +26,7 @@ struct JsonNode
|
|||||||
bool asBoolean;
|
bool asBoolean;
|
||||||
double asDouble;
|
double asDouble;
|
||||||
int asInteger;
|
int asInteger;
|
||||||
|
const char* asString;
|
||||||
|
|
||||||
struct
|
struct
|
||||||
{
|
{
|
||||||
|
@ -10,6 +10,14 @@ void JsonValue::operator=(bool value)
|
|||||||
_node->content.asBoolean = value;
|
_node->content.asBoolean = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void JsonValue::operator=(char const* value)
|
||||||
|
{
|
||||||
|
if (!_node) return;
|
||||||
|
|
||||||
|
_node->type = JSON_STRING;
|
||||||
|
_node->content.asString = value;
|
||||||
|
}
|
||||||
|
|
||||||
void JsonValue::operator=(double value)
|
void JsonValue::operator=(double value)
|
||||||
{
|
{
|
||||||
if (!_node) return;
|
if (!_node) return;
|
||||||
@ -33,6 +41,13 @@ JsonValue::operator bool()
|
|||||||
return _node->content.asBoolean;
|
return _node->content.asBoolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
JsonValue::operator char const*()
|
||||||
|
{
|
||||||
|
if (!_node || _node->type != JSON_STRING) return 0;
|
||||||
|
|
||||||
|
return _node->content.asString;
|
||||||
|
}
|
||||||
|
|
||||||
JsonValue::operator double()
|
JsonValue::operator double()
|
||||||
{
|
{
|
||||||
if (!_node || _node->type < JSON_DOUBLE_0_DECIMALS) return 0;
|
if (!_node || _node->type < JSON_DOUBLE_0_DECIMALS) return 0;
|
||||||
|
@ -14,10 +14,12 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
void operator=(bool);
|
void operator=(bool);
|
||||||
|
void operator=(const char*);
|
||||||
void operator=(double);
|
void operator=(double);
|
||||||
void operator=(int);
|
void operator=(int);
|
||||||
|
|
||||||
operator bool();
|
operator bool();
|
||||||
|
operator const char*();
|
||||||
operator double();
|
operator double();
|
||||||
operator int();
|
operator int();
|
||||||
|
|
||||||
|
@ -50,7 +50,6 @@ TEST_F(JsonObjectTests, CanStoreDoubles)
|
|||||||
EXPECT_EQ(456.78, (double) object["world"]);
|
EXPECT_EQ(456.78, (double) object["world"]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
TEST_F(JsonObjectTests, CanStoreBooleans)
|
TEST_F(JsonObjectTests, CanStoreBooleans)
|
||||||
{
|
{
|
||||||
object["hello"] = true;
|
object["hello"] = true;
|
||||||
@ -59,3 +58,12 @@ TEST_F(JsonObjectTests, CanStoreBooleans)
|
|||||||
EXPECT_TRUE((bool) object["hello"]);
|
EXPECT_TRUE((bool) object["hello"]);
|
||||||
EXPECT_FALSE((bool) object["world"]);
|
EXPECT_FALSE((bool) object["world"]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST_F(JsonObjectTests, CanStoreStrings)
|
||||||
|
{
|
||||||
|
object["hello"] = "h3110";
|
||||||
|
object["world"] = "w0r1d";
|
||||||
|
|
||||||
|
EXPECT_STREQ("h3110", (const char*) object["hello"]);
|
||||||
|
EXPECT_STREQ("w0r1d", (const char*) object["world"]);
|
||||||
|
}
|
Reference in New Issue
Block a user