From df52dceaa177f1330af18739542c9f57f0c9956a Mon Sep 17 00:00:00 2001 From: Benoit Blanchon Date: Mon, 4 Aug 2014 09:21:04 +0200 Subject: [PATCH] Added tests for issue #10 --- JsonGeneratorTests/Issue10.cpp | 73 +++++++++++++++++++ JsonGeneratorTests/JsonGeneratorTests.vcxproj | 1 + .../JsonGeneratorTests.vcxproj.filters | 3 + 3 files changed, 77 insertions(+) create mode 100644 JsonGeneratorTests/Issue10.cpp diff --git a/JsonGeneratorTests/Issue10.cpp b/JsonGeneratorTests/Issue10.cpp new file mode 100644 index 00000000..3fd068de --- /dev/null +++ b/JsonGeneratorTests/Issue10.cpp @@ -0,0 +1,73 @@ +#include "CppUnitTest.h" +#include "JsonArray.h" +#include "JsonObject.h" + +using namespace ArduinoJson::Generator; +using namespace Microsoft::VisualStudio::CppUnitTestFramework; + +namespace JsonGeneratorTests +{ + TEST_CLASS(Issue10) + { + struct Person { + int id; + char name[32]; + }; + + Person persons[2]; + + public: + + TEST_METHOD_INITIALIZE(Initialize) + { + Person boss; + boss.id = 1; + strcpy(boss.name, "Jeff"); + Person employee; + employee.id = 2; + strcpy(employee.name, "John"); + persons[0] = boss; + persons[1] = employee; + } + + TEST_METHOD(WrongWayToAddObjectInAnArray) + { + JsonArray<2> json; + + for (int i = 0; i < 2; i++) + { + JsonObject<2> object; + + object["id"] = persons[i].id; + object["name"] = persons[i].name; + + json.add(object); + } + + char buffer[256]; + json.printTo(buffer, sizeof(buffer)); + + Assert::AreEqual("[]", buffer); + } + + TEST_METHOD(RightWayToAddObjectInAnArray) + { + JsonArray<2> json; + JsonObject<2> object[2]; + + for (int i = 0; i < 1; i++) + { + object[i] = JsonObject<2>(); + object[i]["id"] = persons[i].id; + object[i]["name"] = persons[i].name; + + json.add(object[i]); + } + + char buffer[256]; + json.printTo(buffer, sizeof(buffer)); + + Assert::AreEqual("[TODO]", buffer); + } + }; +} \ No newline at end of file diff --git a/JsonGeneratorTests/JsonGeneratorTests.vcxproj b/JsonGeneratorTests/JsonGeneratorTests.vcxproj index cab05127..d9ee8ff8 100644 --- a/JsonGeneratorTests/JsonGeneratorTests.vcxproj +++ b/JsonGeneratorTests/JsonGeneratorTests.vcxproj @@ -85,6 +85,7 @@ + diff --git a/JsonGeneratorTests/JsonGeneratorTests.vcxproj.filters b/JsonGeneratorTests/JsonGeneratorTests.vcxproj.filters index 791ad5b5..a0439471 100644 --- a/JsonGeneratorTests/JsonGeneratorTests.vcxproj.filters +++ b/JsonGeneratorTests/JsonGeneratorTests.vcxproj.filters @@ -36,5 +36,8 @@ Source Files + + Source Files + \ No newline at end of file