Generator: added a tests that adds a 'true' to an array

This commit is contained in:
Benoit Blanchon
2014-06-24 21:15:07 +02:00
parent 5c119099f3
commit a27bb3097a
2 changed files with 23 additions and 1 deletions

View File

@ -11,12 +11,14 @@ enum JsonObjectType
{ {
JSON_STRING, JSON_STRING,
JSON_NUMBER, JSON_NUMBER,
JSON_BOOLEAN,
}; };
union JsonObjectValue union JsonObjectValue
{ {
const char* string; const char* string;
double number; double number;
bool boolean;
}; };
struct JsonObject struct JsonObject
@ -54,6 +56,15 @@ public:
itemCount++; 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) void writeTo(char* buffer, size_t bufferSize)
{ {
buffer[0] = 0; buffer[0] = 0;
@ -74,6 +85,10 @@ public:
case JSON_NUMBER: case JSON_NUMBER:
append(buffer, bufferSize, "%lg", items[i].value.number); append(buffer, bufferSize, "%lg", items[i].value.number);
break; break;
case JSON_BOOLEAN:
append(buffer, bufferSize, "true");
break;
} }
} }

View File

@ -64,6 +64,13 @@ namespace JsonGeneratorTests
AssertJsonIs("[3.14,2.72]"); AssertJsonIs("[3.14,2.72]");
} }
TEST_METHOD(AddTrue)
{
arr.add(true);
AssertJsonIs("[true]");
}
void AssertJsonIs(const char* expected) void AssertJsonIs(const char* expected)
{ {
char buffer[256]; char buffer[256];