From a27bb3097af959c79ebd5f38d47ffc272a6fe7ba Mon Sep 17 00:00:00 2001 From: Benoit Blanchon Date: Tue, 24 Jun 2014 21:15:07 +0200 Subject: [PATCH] Generator: added a tests that adds a 'true' to an array --- JsonGeneratorTests/JsonArray.h | 17 ++++++++++++++++- JsonGeneratorTests/JsonArrayTests.cpp | 7 +++++++ 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/JsonGeneratorTests/JsonArray.h b/JsonGeneratorTests/JsonArray.h index d8bca15c..f670e983 100644 --- a/JsonGeneratorTests/JsonArray.h +++ b/JsonGeneratorTests/JsonArray.h @@ -11,12 +11,14 @@ enum JsonObjectType { JSON_STRING, JSON_NUMBER, + JSON_BOOLEAN, }; union JsonObjectValue { const char* string; - double number; + 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; } } diff --git a/JsonGeneratorTests/JsonArrayTests.cpp b/JsonGeneratorTests/JsonArrayTests.cpp index 941b099f..03400c5f 100644 --- a/JsonGeneratorTests/JsonArrayTests.cpp +++ b/JsonGeneratorTests/JsonArrayTests.cpp @@ -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];