mirror of
https://github.com/bblanchon/ArduinoJson.git
synced 2025-07-17 20:42:24 +02:00
Generator: added a tests that adds a 'true' to an array
This commit is contained in:
@ -11,12 +11,14 @@ enum JsonObjectType
|
||||
{
|
||||
JSON_STRING,
|
||||
JSON_NUMBER,
|
||||
JSON_BOOLEAN,
|
||||
};
|
||||
|
||||
union JsonObjectValue
|
||||
{
|
||||
const char* string;
|
||||
double number;
|
||||
bool boolean;
|
||||
};
|
||||
|
||||
struct JsonObject
|
||||
@ -54,6 +56,15 @@ public:
|
||||
itemCount++;
|
||||
}
|
||||
|
||||
void add(bool value)
|
||||
{
|
||||
if (itemCount >= N) return;
|
||||
|
||||
items[itemCount].type = JSON_BOOLEAN;
|
||||
items[itemCount].value.boolean = value;
|
||||
itemCount++;
|
||||
}
|
||||
|
||||
void writeTo(char* buffer, size_t bufferSize)
|
||||
{
|
||||
buffer[0] = 0;
|
||||
@ -74,6 +85,10 @@ public:
|
||||
case JSON_NUMBER:
|
||||
append(buffer, bufferSize, "%lg", items[i].value.number);
|
||||
break;
|
||||
|
||||
case JSON_BOOLEAN:
|
||||
append(buffer, bufferSize, "true");
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -64,6 +64,13 @@ namespace JsonGeneratorTests
|
||||
AssertJsonIs("[3.14,2.72]");
|
||||
}
|
||||
|
||||
TEST_METHOD(AddTrue)
|
||||
{
|
||||
arr.add(true);
|
||||
|
||||
AssertJsonIs("[true]");
|
||||
}
|
||||
|
||||
void AssertJsonIs(const char* expected)
|
||||
{
|
||||
char buffer[256];
|
||||
|
Reference in New Issue
Block a user