From b847576bb4f847b9f29f6ee0a54fecf9d717aa89 Mon Sep 17 00:00:00 2001 From: Benoit Blanchon Date: Thu, 16 Oct 2014 16:23:24 +0200 Subject: [PATCH] Renamed tests/ into test/ --- CMakeLists.txt | 2 +- {tests => test}/CMakeLists.txt | 36 +- {tests => test}/EscapedStringTests.cpp | 172 +++++----- {tests => test}/Issue10.cpp | 160 ++++----- {tests => test}/JsonArray_Container_Tests.cpp | 298 ++++++++--------- {tests => test}/JsonArray_Parser_Tests.cpp | 0 .../JsonArray_PrettyPrintTo_Tests.cpp | 182 +++++----- {tests => test}/JsonArray_PrintTo_Tests.cpp | 294 ++++++++-------- .../JsonObject_Container_Tests.cpp | 238 ++++++------- .../JsonObject_PrettyPrintTo_Tests.cpp | 176 +++++----- .../JsonObject_Serialization_Tests.cpp | 314 +++++++++--------- {tests => test}/JsonValueTests.cpp | 236 ++++++------- {tests => test}/StaticJsonBufferTests.cpp | 136 ++++---- {tests => test}/StringBuilderTests.cpp | 148 ++++----- 14 files changed, 1196 insertions(+), 1196 deletions(-) rename {tests => test}/CMakeLists.txt (95%) rename {tests => test}/EscapedStringTests.cpp (94%) rename {tests => test}/Issue10.cpp (95%) rename {tests => test}/JsonArray_Container_Tests.cpp (95%) rename {tests => test}/JsonArray_Parser_Tests.cpp (100%) rename {tests => test}/JsonArray_PrettyPrintTo_Tests.cpp (94%) rename {tests => test}/JsonArray_PrintTo_Tests.cpp (94%) rename {tests => test}/JsonObject_Container_Tests.cpp (95%) rename {tests => test}/JsonObject_PrettyPrintTo_Tests.cpp (95%) rename {tests => test}/JsonObject_Serialization_Tests.cpp (95%) rename {tests => test}/JsonValueTests.cpp (94%) rename {tests => test}/StaticJsonBufferTests.cpp (95%) rename {tests => test}/StringBuilderTests.cpp (94%) diff --git a/CMakeLists.txt b/CMakeLists.txt index 830c7037..d4e85e90 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -4,4 +4,4 @@ project(ArduinoJson) enable_testing() add_subdirectory(srcs) -add_subdirectory(tests) \ No newline at end of file +add_subdirectory(test) \ No newline at end of file diff --git a/tests/CMakeLists.txt b/test/CMakeLists.txt similarity index 95% rename from tests/CMakeLists.txt rename to test/CMakeLists.txt index 4f140ead..af4728fd 100644 --- a/tests/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -1,19 +1,19 @@ -set(GTEST_DIR ../third-party/gtest-1.7.0) - -file(GLOB_RECURSE INC_FILES ../include/*.h) -file(GLOB TESTS_FILES *.cpp) - -include_directories( - ../include - ${GTEST_DIR} - ${GTEST_DIR}/include) - -add_executable(ArduinoJsonTests - ${TESTS_FILES} - ${INC_FILES} - ${GTEST_DIR}/src/gtest-all.cc - ${GTEST_DIR}/src/gtest_main.cc) - -target_link_libraries(ArduinoJsonTests ArduinoJson) - +set(GTEST_DIR ../third-party/gtest-1.7.0) + +file(GLOB_RECURSE INC_FILES ../include/*.h) +file(GLOB TESTS_FILES *.cpp) + +include_directories( + ../include + ${GTEST_DIR} + ${GTEST_DIR}/include) + +add_executable(ArduinoJsonTests + ${TESTS_FILES} + ${INC_FILES} + ${GTEST_DIR}/src/gtest-all.cc + ${GTEST_DIR}/src/gtest_main.cc) + +target_link_libraries(ArduinoJsonTests ArduinoJson) + add_test(ArduinoJsonTests ArduinoJsonTests) \ No newline at end of file diff --git a/tests/EscapedStringTests.cpp b/test/EscapedStringTests.cpp similarity index 94% rename from tests/EscapedStringTests.cpp rename to test/EscapedStringTests.cpp index 04de670b..e8606636 100644 --- a/tests/EscapedStringTests.cpp +++ b/test/EscapedStringTests.cpp @@ -1,87 +1,87 @@ -#include - -#include -#include - -using namespace ArduinoJson::Internals; - -class EscapedStringTests : public testing::Test -{ -protected: - void whenInputIs(const char* input) - { - StringBuilder sb(buffer, sizeof(buffer)); - returnValue = EscapedString::printTo(input, &sb); - } - - void outputMustBe(const char* expected) - { - EXPECT_STREQ(expected, buffer); - EXPECT_EQ(strlen(expected), returnValue); - } - -private: - char buffer[1024]; - size_t returnValue; - -}; - -TEST_F(EscapedStringTests, Null) -{ - whenInputIs(0); - outputMustBe("null"); -} - -TEST_F(EscapedStringTests, EmptyString) -{ - whenInputIs(""); - outputMustBe("\"\""); -} - -TEST_F(EscapedStringTests, QuotationMark) -{ - whenInputIs("\""); - outputMustBe("\"\\\"\""); -} - -TEST_F(EscapedStringTests, ReverseSolidus) -{ - whenInputIs("\\"); - outputMustBe("\"\\\\\""); -} - -TEST_F(EscapedStringTests, Solidus) -{ - whenInputIs("/"); - outputMustBe("\"/\""); // but the JSON format allows \/ -} - -TEST_F(EscapedStringTests, Backspace) -{ - whenInputIs("\b"); - outputMustBe("\"\\b\""); -} - -TEST_F(EscapedStringTests, Formfeed) -{ - whenInputIs("\f"); - outputMustBe("\"\\f\""); -} - -TEST_F(EscapedStringTests, Newline) -{ - whenInputIs("\n"); - outputMustBe("\"\\n\""); -} - -TEST_F(EscapedStringTests, CarriageReturn) -{ - whenInputIs("\r"); - outputMustBe("\"\\r\""); -} - -TEST_F(EscapedStringTests, HorizontalTab) -{ - whenInputIs("\t"); - outputMustBe("\"\\t\""); +#include + +#include +#include + +using namespace ArduinoJson::Internals; + +class EscapedStringTests : public testing::Test +{ +protected: + void whenInputIs(const char* input) + { + StringBuilder sb(buffer, sizeof(buffer)); + returnValue = EscapedString::printTo(input, &sb); + } + + void outputMustBe(const char* expected) + { + EXPECT_STREQ(expected, buffer); + EXPECT_EQ(strlen(expected), returnValue); + } + +private: + char buffer[1024]; + size_t returnValue; + +}; + +TEST_F(EscapedStringTests, Null) +{ + whenInputIs(0); + outputMustBe("null"); +} + +TEST_F(EscapedStringTests, EmptyString) +{ + whenInputIs(""); + outputMustBe("\"\""); +} + +TEST_F(EscapedStringTests, QuotationMark) +{ + whenInputIs("\""); + outputMustBe("\"\\\"\""); +} + +TEST_F(EscapedStringTests, ReverseSolidus) +{ + whenInputIs("\\"); + outputMustBe("\"\\\\\""); +} + +TEST_F(EscapedStringTests, Solidus) +{ + whenInputIs("/"); + outputMustBe("\"/\""); // but the JSON format allows \/ +} + +TEST_F(EscapedStringTests, Backspace) +{ + whenInputIs("\b"); + outputMustBe("\"\\b\""); +} + +TEST_F(EscapedStringTests, Formfeed) +{ + whenInputIs("\f"); + outputMustBe("\"\\f\""); +} + +TEST_F(EscapedStringTests, Newline) +{ + whenInputIs("\n"); + outputMustBe("\"\\n\""); +} + +TEST_F(EscapedStringTests, CarriageReturn) +{ + whenInputIs("\r"); + outputMustBe("\"\\r\""); +} + +TEST_F(EscapedStringTests, HorizontalTab) +{ + whenInputIs("\t"); + outputMustBe("\"\\t\""); } \ No newline at end of file diff --git a/tests/Issue10.cpp b/test/Issue10.cpp similarity index 95% rename from tests/Issue10.cpp rename to test/Issue10.cpp index 3bf04c4b..f3976f9e 100644 --- a/tests/Issue10.cpp +++ b/test/Issue10.cpp @@ -1,80 +1,80 @@ -#include -#include -#include -#include -#include - -using namespace ArduinoJson::Generator; - -struct Person -{ - int id; - char name[32]; -}; - -class Issue10 : public testing::Test -{ -protected: - - virtual void SetUp() - { - Person boss; - boss.id = 1; - strcpy(boss.name, "Jeff"); - Person employee; - employee.id = 2; - strcpy(employee.name, "John"); - persons[0] = boss; - persons[1] = employee; - } - - void checkJsonString(JsonContainer& p) - { - char buffer[256]; - p.printTo(buffer, sizeof(buffer)); - - EXPECT_STREQ("[{\"id\":1,\"name\":\"Jeff\"},{\"id\":2,\"name\":\"John\"}]", buffer); - } - - void nodeCountMustBe(int expected) - { - EXPECT_EQ(expected, json.size()); - } - - Person persons[2]; - StaticJsonBuffer<20> json; -}; - -TEST_F(Issue10, PopulateArrayByAddingAnObject) -{ - JsonArray array= json.createArray(); - - for (int i = 0; i < 2; i++) - { - JsonObject object = json.createObject(); - - object["id"] = persons[i].id; - object["name"] = persons[i].name; - - array.add(object); // <- adds a reference to an existing objet (creates 2 extra proxy nodes) - } - - checkJsonString(array); - nodeCountMustBe(15); -} - -TEST_F(Issue10, PopulateArrayByCreatingNestedObjects) -{ - JsonArray array = json.createArray(); - - for (int i = 0; i < 2; i++) - { - JsonObject object = array.createNestedObject(); - - object["id"] = persons[i].id; - object["name"] = persons[i].name; - } - - checkJsonString(array); - nodeCountMustBe(11); -} +#include +#include +#include +#include +#include + +using namespace ArduinoJson::Generator; + +struct Person +{ + int id; + char name[32]; +}; + +class Issue10 : public testing::Test +{ +protected: + + virtual void SetUp() + { + Person boss; + boss.id = 1; + strcpy(boss.name, "Jeff"); + Person employee; + employee.id = 2; + strcpy(employee.name, "John"); + persons[0] = boss; + persons[1] = employee; + } + + void checkJsonString(JsonContainer& p) + { + char buffer[256]; + p.printTo(buffer, sizeof(buffer)); + + EXPECT_STREQ("[{\"id\":1,\"name\":\"Jeff\"},{\"id\":2,\"name\":\"John\"}]", buffer); + } + + void nodeCountMustBe(int expected) + { + EXPECT_EQ(expected, json.size()); + } + + Person persons[2]; + StaticJsonBuffer<20> json; +}; + +TEST_F(Issue10, PopulateArrayByAddingAnObject) +{ + JsonArray array= json.createArray(); + + for (int i = 0; i < 2; i++) + { + JsonObject object = json.createObject(); + + object["id"] = persons[i].id; + object["name"] = persons[i].name; + + array.add(object); // <- adds a reference to an existing objet (creates 2 extra proxy nodes) + } + + checkJsonString(array); + nodeCountMustBe(15); +} + +TEST_F(Issue10, PopulateArrayByCreatingNestedObjects) +{ + JsonArray array = json.createArray(); + + for (int i = 0; i < 2; i++) + { + JsonObject object = array.createNestedObject(); + + object["id"] = persons[i].id; + object["name"] = persons[i].name; + } + + checkJsonString(array); + nodeCountMustBe(11); +} diff --git a/tests/JsonArray_Container_Tests.cpp b/test/JsonArray_Container_Tests.cpp similarity index 95% rename from tests/JsonArray_Container_Tests.cpp rename to test/JsonArray_Container_Tests.cpp index 03042397..fef0536c 100644 --- a/tests/JsonArray_Container_Tests.cpp +++ b/test/JsonArray_Container_Tests.cpp @@ -1,150 +1,150 @@ -#include -#include -#include - -class JsonArray_Container_Tests : public ::testing::Test -{ -protected: - virtual void SetUp() - { - array = json.createArray(); - } - - void nodeCountMustBe(int expected) - { - EXPECT_EQ(expected, json.size()); - } - - template - void firstElementMustBe(T expected) - { - elementAtIndexMustBe(0, expected); - } - - template - void secondElementMustBe(T expected) - { - elementAtIndexMustBe(1, expected); - } - - void sizeMustBe(int expected) - { - EXPECT_EQ(expected, array.size()); - } - - StaticJsonBuffer<42> json; - JsonArray array; - -private: - template - void elementAtIndexMustBe(int index, T expected) - { - EXPECT_EQ(expected, static_cast(array[index])); - } -}; - -TEST_F(JsonArray_Container_Tests, InitialSizeIsZero) -{ - sizeMustBe(0); - nodeCountMustBe(1); -} - -TEST_F(JsonArray_Container_Tests, Grow_WhenValuesAreAdded) -{ - array.add("hello"); - sizeMustBe(1); - nodeCountMustBe(2); - - array.add("world"); - sizeMustBe(2); - nodeCountMustBe(3); -} - -TEST_F(JsonArray_Container_Tests, CanStoreIntegers) -{ - array.add(123); - array.add(456); - - firstElementMustBe(123); - secondElementMustBe(456); - nodeCountMustBe(3); -} - -TEST_F(JsonArray_Container_Tests, CanStoreDoubles) -{ - array.add(123.45); - array.add(456.78); - - firstElementMustBe(123.45); - secondElementMustBe(456.78); - nodeCountMustBe(3); -} - -TEST_F(JsonArray_Container_Tests, CanStoreBooleans) -{ - array.add(true); - array.add(false); - - firstElementMustBe(true); - secondElementMustBe(false); - nodeCountMustBe(3); -} - -TEST_F(JsonArray_Container_Tests, CanStoreStrings) -{ - const char* firstString = "h3110"; - const char* secondString = "w0r1d"; - - array.add(firstString); - array.add(secondString); - - firstElementMustBe(firstString); - secondElementMustBe(secondString); - nodeCountMustBe(3); -} - -TEST_F(JsonArray_Container_Tests, CanStoreNestedArrays) -{ - JsonArray innerarray1 = json.createArray(); - JsonArray innerarray2 = json.createArray(); - - array.add(innerarray1); - array.add(innerarray2); - - firstElementMustBe(innerarray1); - secondElementMustBe(innerarray2); - nodeCountMustBe(1 + 3 + 3); -} - -TEST_F(JsonArray_Container_Tests, CanStoreNestedObjects) -{ - JsonObject innerObject1 = json.createObject(); - JsonObject innerObject2 = json.createObject(); - - array.add(innerObject1); - array.add(innerObject2); - - firstElementMustBe(innerObject1); - secondElementMustBe(innerObject2); - nodeCountMustBe(1 + 3 + 3); -} - -TEST_F(JsonArray_Container_Tests, CanCreateNestedArrays) -{ - JsonArray innerarray1 = array.createNestedArray(); - JsonArray innerarray2 = array.createNestedArray(); - - firstElementMustBe(innerarray1); - secondElementMustBe(innerarray2); - nodeCountMustBe(1 + 1 + 1); -} - -TEST_F(JsonArray_Container_Tests, CanCreateNestedObjects) -{ - JsonObject innerObject1 = array.createNestedObject(); - JsonObject innerObject2 = array.createNestedObject(); - - firstElementMustBe(innerObject1); - secondElementMustBe(innerObject2); - nodeCountMustBe(3); +#include +#include +#include + +class JsonArray_Container_Tests : public ::testing::Test +{ +protected: + virtual void SetUp() + { + array = json.createArray(); + } + + void nodeCountMustBe(int expected) + { + EXPECT_EQ(expected, json.size()); + } + + template + void firstElementMustBe(T expected) + { + elementAtIndexMustBe(0, expected); + } + + template + void secondElementMustBe(T expected) + { + elementAtIndexMustBe(1, expected); + } + + void sizeMustBe(int expected) + { + EXPECT_EQ(expected, array.size()); + } + + StaticJsonBuffer<42> json; + JsonArray array; + +private: + template + void elementAtIndexMustBe(int index, T expected) + { + EXPECT_EQ(expected, static_cast(array[index])); + } +}; + +TEST_F(JsonArray_Container_Tests, InitialSizeIsZero) +{ + sizeMustBe(0); + nodeCountMustBe(1); +} + +TEST_F(JsonArray_Container_Tests, Grow_WhenValuesAreAdded) +{ + array.add("hello"); + sizeMustBe(1); + nodeCountMustBe(2); + + array.add("world"); + sizeMustBe(2); + nodeCountMustBe(3); +} + +TEST_F(JsonArray_Container_Tests, CanStoreIntegers) +{ + array.add(123); + array.add(456); + + firstElementMustBe(123); + secondElementMustBe(456); + nodeCountMustBe(3); +} + +TEST_F(JsonArray_Container_Tests, CanStoreDoubles) +{ + array.add(123.45); + array.add(456.78); + + firstElementMustBe(123.45); + secondElementMustBe(456.78); + nodeCountMustBe(3); +} + +TEST_F(JsonArray_Container_Tests, CanStoreBooleans) +{ + array.add(true); + array.add(false); + + firstElementMustBe(true); + secondElementMustBe(false); + nodeCountMustBe(3); +} + +TEST_F(JsonArray_Container_Tests, CanStoreStrings) +{ + const char* firstString = "h3110"; + const char* secondString = "w0r1d"; + + array.add(firstString); + array.add(secondString); + + firstElementMustBe(firstString); + secondElementMustBe(secondString); + nodeCountMustBe(3); +} + +TEST_F(JsonArray_Container_Tests, CanStoreNestedArrays) +{ + JsonArray innerarray1 = json.createArray(); + JsonArray innerarray2 = json.createArray(); + + array.add(innerarray1); + array.add(innerarray2); + + firstElementMustBe(innerarray1); + secondElementMustBe(innerarray2); + nodeCountMustBe(1 + 3 + 3); +} + +TEST_F(JsonArray_Container_Tests, CanStoreNestedObjects) +{ + JsonObject innerObject1 = json.createObject(); + JsonObject innerObject2 = json.createObject(); + + array.add(innerObject1); + array.add(innerObject2); + + firstElementMustBe(innerObject1); + secondElementMustBe(innerObject2); + nodeCountMustBe(1 + 3 + 3); +} + +TEST_F(JsonArray_Container_Tests, CanCreateNestedArrays) +{ + JsonArray innerarray1 = array.createNestedArray(); + JsonArray innerarray2 = array.createNestedArray(); + + firstElementMustBe(innerarray1); + secondElementMustBe(innerarray2); + nodeCountMustBe(1 + 1 + 1); +} + +TEST_F(JsonArray_Container_Tests, CanCreateNestedObjects) +{ + JsonObject innerObject1 = array.createNestedObject(); + JsonObject innerObject2 = array.createNestedObject(); + + firstElementMustBe(innerObject1); + secondElementMustBe(innerObject2); + nodeCountMustBe(3); } \ No newline at end of file diff --git a/tests/JsonArray_Parser_Tests.cpp b/test/JsonArray_Parser_Tests.cpp similarity index 100% rename from tests/JsonArray_Parser_Tests.cpp rename to test/JsonArray_Parser_Tests.cpp diff --git a/tests/JsonArray_PrettyPrintTo_Tests.cpp b/test/JsonArray_PrettyPrintTo_Tests.cpp similarity index 94% rename from tests/JsonArray_PrettyPrintTo_Tests.cpp rename to test/JsonArray_PrettyPrintTo_Tests.cpp index a61432f2..eb6e0574 100644 --- a/tests/JsonArray_PrettyPrintTo_Tests.cpp +++ b/test/JsonArray_PrettyPrintTo_Tests.cpp @@ -1,92 +1,92 @@ -/* -* Arduino JSON library -* Benoit Blanchon 2014 - MIT License -*/ - -#include -#include -#include -#include -#include - -class JsonArray_PrettyPrintTo_Tests : public testing::Test -{ -protected: - JsonArray array; - StaticJsonBuffer<30> json; - - virtual void SetUp() - { - array = json.createArray(); - } - - void outputMustBe(const char* expected) - { - size_t n = array.prettyPrintTo(buffer, sizeof(buffer)); - EXPECT_STREQ(expected, buffer); - EXPECT_EQ(strlen(expected), n); - } - -private: - char buffer[256]; -}; - -TEST_F(JsonArray_PrettyPrintTo_Tests, Empty) -{ - outputMustBe("[]"); -} - -TEST_F(JsonArray_PrettyPrintTo_Tests, OneElement) -{ - array.add(1); - - outputMustBe( - "[\r\n" - " 1\r\n" - "]"); -} - -TEST_F(JsonArray_PrettyPrintTo_Tests, TwoElements) -{ - array.add(1); - array.add(2); - - outputMustBe( - "[\r\n" - " 1,\r\n" - " 2\r\n" - "]"); -} - -TEST_F(JsonArray_PrettyPrintTo_Tests, EmptyNestedArrays) -{ - array.createNestedArray(); - array.createNestedArray(); - - outputMustBe( - "[\r\n" - " [],\r\n" - " []\r\n" - "]"); -} - -TEST_F(JsonArray_PrettyPrintTo_Tests, NestedArrays) -{ - JsonArray nested1 = array.createNestedArray(); - nested1.add(1); - nested1.add(2); - - JsonObject nested2 = array.createNestedObject(); - nested2["key"] = 3; - - outputMustBe( - "[\r\n" - " [\r\n" - " 1,\r\n" - " 2\r\n" - " ],\r\n" - " {\r\n" - " \"key\": 3\r\n" - " }\r\n" - "]"); +/* +* Arduino JSON library +* Benoit Blanchon 2014 - MIT License +*/ + +#include +#include +#include +#include +#include + +class JsonArray_PrettyPrintTo_Tests : public testing::Test +{ +protected: + JsonArray array; + StaticJsonBuffer<30> json; + + virtual void SetUp() + { + array = json.createArray(); + } + + void outputMustBe(const char* expected) + { + size_t n = array.prettyPrintTo(buffer, sizeof(buffer)); + EXPECT_STREQ(expected, buffer); + EXPECT_EQ(strlen(expected), n); + } + +private: + char buffer[256]; +}; + +TEST_F(JsonArray_PrettyPrintTo_Tests, Empty) +{ + outputMustBe("[]"); +} + +TEST_F(JsonArray_PrettyPrintTo_Tests, OneElement) +{ + array.add(1); + + outputMustBe( + "[\r\n" + " 1\r\n" + "]"); +} + +TEST_F(JsonArray_PrettyPrintTo_Tests, TwoElements) +{ + array.add(1); + array.add(2); + + outputMustBe( + "[\r\n" + " 1,\r\n" + " 2\r\n" + "]"); +} + +TEST_F(JsonArray_PrettyPrintTo_Tests, EmptyNestedArrays) +{ + array.createNestedArray(); + array.createNestedArray(); + + outputMustBe( + "[\r\n" + " [],\r\n" + " []\r\n" + "]"); +} + +TEST_F(JsonArray_PrettyPrintTo_Tests, NestedArrays) +{ + JsonArray nested1 = array.createNestedArray(); + nested1.add(1); + nested1.add(2); + + JsonObject nested2 = array.createNestedObject(); + nested2["key"] = 3; + + outputMustBe( + "[\r\n" + " [\r\n" + " 1,\r\n" + " 2\r\n" + " ],\r\n" + " {\r\n" + " \"key\": 3\r\n" + " }\r\n" + "]"); } \ No newline at end of file diff --git a/tests/JsonArray_PrintTo_Tests.cpp b/test/JsonArray_PrintTo_Tests.cpp similarity index 94% rename from tests/JsonArray_PrintTo_Tests.cpp rename to test/JsonArray_PrintTo_Tests.cpp index 57e6434c..afa18cbd 100644 --- a/tests/JsonArray_PrintTo_Tests.cpp +++ b/test/JsonArray_PrintTo_Tests.cpp @@ -1,148 +1,148 @@ -/* -* Arduino JSON library -* Benoit Blanchon 2014 - MIT License -*/ - -#include -#include -#include -#include - -class JsonArray_PrintTo_Tests : public testing::Test -{ -protected: - JsonArray array; - StaticJsonBuffer<3> json; - - virtual void SetUp() - { - array = json.createArray(); - } - - void outputMustBe(const char* expected) - { - size_t n = array.printTo(buffer, sizeof(buffer)); - EXPECT_STREQ(expected, buffer); - EXPECT_EQ(strlen(expected), n); - } - -private: - char buffer[256]; -}; - -TEST_F(JsonArray_PrintTo_Tests, Empty) -{ - outputMustBe("[]"); -} - -TEST_F(JsonArray_PrintTo_Tests, Null) -{ - array.add((char*) 0); - - outputMustBe("[null]"); -} - -TEST_F(JsonArray_PrintTo_Tests, OneString) -{ - array.add("hello"); - - outputMustBe("[\"hello\"]"); -} - -TEST_F(JsonArray_PrintTo_Tests, TwoStrings) -{ - array.add("hello"); - array.add("world"); - - outputMustBe("[\"hello\",\"world\"]"); -} - -TEST_F(JsonArray_PrintTo_Tests, OneStringOverCapacity) -{ - array.add("hello"); - array.add("world"); - array.add("lost"); - - outputMustBe("[\"hello\",\"world\"]"); -} - -TEST_F(JsonArray_PrintTo_Tests, OneDoubleDefaultDigits) -{ - array.add(3.14159265358979323846); - outputMustBe("[3.14]"); -} - -TEST_F(JsonArray_PrintTo_Tests, OneDoubleFourDigits) -{ - array.add(3.14159265358979323846, 4); - outputMustBe("[3.1416]"); -} - -TEST_F(JsonArray_PrintTo_Tests, OneInteger) -{ - array.add(1); - - outputMustBe("[1]"); -} - -TEST_F(JsonArray_PrintTo_Tests, TwoIntegers) -{ - array.add(1); - array.add(2); - - outputMustBe("[1,2]"); -} - -TEST_F(JsonArray_PrintTo_Tests, OneIntegerOverCapacity) -{ - array.add(1); - array.add(2); - array.add(3); - - outputMustBe("[1,2]"); -} - -TEST_F(JsonArray_PrintTo_Tests, OneTrue) -{ - array.add(true); - - outputMustBe("[true]"); -} - -TEST_F(JsonArray_PrintTo_Tests, OneFalse) -{ - array.add(false); - - outputMustBe("[false]"); -} - -TEST_F(JsonArray_PrintTo_Tests, TwoBooleans) -{ - array.add(false); - array.add(true); - - outputMustBe("[false,true]"); -} - -TEST_F(JsonArray_PrintTo_Tests, OneBooleanOverCapacity) -{ - array.add(false); - array.add(true); - array.add(false); - - outputMustBe("[false,true]"); -} - -TEST_F(JsonArray_PrintTo_Tests, OneEmptyNestedArray) -{ - array.createNestedArray(); - - outputMustBe("[[]]"); -} - -TEST_F(JsonArray_PrintTo_Tests, OneEmptyNestedHash) -{ - array.createNestedObject(); - - outputMustBe("[{}]"); +/* +* Arduino JSON library +* Benoit Blanchon 2014 - MIT License +*/ + +#include +#include +#include +#include + +class JsonArray_PrintTo_Tests : public testing::Test +{ +protected: + JsonArray array; + StaticJsonBuffer<3> json; + + virtual void SetUp() + { + array = json.createArray(); + } + + void outputMustBe(const char* expected) + { + size_t n = array.printTo(buffer, sizeof(buffer)); + EXPECT_STREQ(expected, buffer); + EXPECT_EQ(strlen(expected), n); + } + +private: + char buffer[256]; +}; + +TEST_F(JsonArray_PrintTo_Tests, Empty) +{ + outputMustBe("[]"); +} + +TEST_F(JsonArray_PrintTo_Tests, Null) +{ + array.add((char*) 0); + + outputMustBe("[null]"); +} + +TEST_F(JsonArray_PrintTo_Tests, OneString) +{ + array.add("hello"); + + outputMustBe("[\"hello\"]"); +} + +TEST_F(JsonArray_PrintTo_Tests, TwoStrings) +{ + array.add("hello"); + array.add("world"); + + outputMustBe("[\"hello\",\"world\"]"); +} + +TEST_F(JsonArray_PrintTo_Tests, OneStringOverCapacity) +{ + array.add("hello"); + array.add("world"); + array.add("lost"); + + outputMustBe("[\"hello\",\"world\"]"); +} + +TEST_F(JsonArray_PrintTo_Tests, OneDoubleDefaultDigits) +{ + array.add(3.14159265358979323846); + outputMustBe("[3.14]"); +} + +TEST_F(JsonArray_PrintTo_Tests, OneDoubleFourDigits) +{ + array.add(3.14159265358979323846, 4); + outputMustBe("[3.1416]"); +} + +TEST_F(JsonArray_PrintTo_Tests, OneInteger) +{ + array.add(1); + + outputMustBe("[1]"); +} + +TEST_F(JsonArray_PrintTo_Tests, TwoIntegers) +{ + array.add(1); + array.add(2); + + outputMustBe("[1,2]"); +} + +TEST_F(JsonArray_PrintTo_Tests, OneIntegerOverCapacity) +{ + array.add(1); + array.add(2); + array.add(3); + + outputMustBe("[1,2]"); +} + +TEST_F(JsonArray_PrintTo_Tests, OneTrue) +{ + array.add(true); + + outputMustBe("[true]"); +} + +TEST_F(JsonArray_PrintTo_Tests, OneFalse) +{ + array.add(false); + + outputMustBe("[false]"); +} + +TEST_F(JsonArray_PrintTo_Tests, TwoBooleans) +{ + array.add(false); + array.add(true); + + outputMustBe("[false,true]"); +} + +TEST_F(JsonArray_PrintTo_Tests, OneBooleanOverCapacity) +{ + array.add(false); + array.add(true); + array.add(false); + + outputMustBe("[false,true]"); +} + +TEST_F(JsonArray_PrintTo_Tests, OneEmptyNestedArray) +{ + array.createNestedArray(); + + outputMustBe("[[]]"); +} + +TEST_F(JsonArray_PrintTo_Tests, OneEmptyNestedHash) +{ + array.createNestedObject(); + + outputMustBe("[{}]"); } \ No newline at end of file diff --git a/tests/JsonObject_Container_Tests.cpp b/test/JsonObject_Container_Tests.cpp similarity index 95% rename from tests/JsonObject_Container_Tests.cpp rename to test/JsonObject_Container_Tests.cpp index 5234df82..7a37d447 100644 --- a/tests/JsonObject_Container_Tests.cpp +++ b/test/JsonObject_Container_Tests.cpp @@ -1,120 +1,120 @@ -#include -#include -#include - -class JsonObject_Container_Tests : public ::testing::Test -{ -protected: - virtual void SetUp() - { - object = json.createObject(); - } - - StaticJsonBuffer<42> json; - JsonObject object; -}; - -TEST_F(JsonObject_Container_Tests, InitialSizeIsZero) -{ - EXPECT_EQ(0, object.size()); -} - -TEST_F(JsonObject_Container_Tests, Grow_WhenValuesAreAdded) -{ - object["hello"]; - EXPECT_EQ(1, object.size()); - - object["world"]; - EXPECT_EQ(2, object.size()); -} - -TEST_F(JsonObject_Container_Tests, DoNotGrow_WhenSameValueIsAdded) -{ - object["hello"]; - EXPECT_EQ(1, object.size()); - - object["hello"]; - EXPECT_EQ(1, object.size()); -} - -TEST_F(JsonObject_Container_Tests, Shrink_WhenValuesAreRemoved) -{ - object["hello"]; - object["world"]; - - object.remove("hello"); - EXPECT_EQ(1, object.size()); - - object.remove("world"); - EXPECT_EQ(0, object.size()); -} - -TEST_F(JsonObject_Container_Tests, DoNotShrink_WhenRemoveIsCalledWithAWrongKey) -{ - object["hello"]; - object["world"]; - - object.remove(":-P"); - - EXPECT_EQ(2, object.size()); -} - -TEST_F(JsonObject_Container_Tests, CanStoreIntegers) -{ - object["hello"] = 123; - object["world"] = 456; - - EXPECT_EQ(123, (int) object["hello"]); - EXPECT_EQ(456, (int) object["world"]); -} - -TEST_F(JsonObject_Container_Tests, CanStoreDoubles) -{ - object["hello"] = 123.45; - object["world"] = 456.78; - - EXPECT_EQ(123.45, (double) object["hello"]); - EXPECT_EQ(456.78, (double) object["world"]); -} - -TEST_F(JsonObject_Container_Tests, CanStoreBooleans) -{ - object["hello"] = true; - object["world"] = false; - - EXPECT_TRUE((bool) object["hello"]); - EXPECT_FALSE((bool) object["world"]); -} - -TEST_F(JsonObject_Container_Tests, CanStoreStrings) -{ - object["hello"] = "h3110"; - object["world"] = "w0r1d"; - - EXPECT_STREQ("h3110", (const char*) object["hello"]); - EXPECT_STREQ("w0r1d", (const char*) object["world"]); -} - -TEST_F(JsonObject_Container_Tests, CanStoreInnerArrays) -{ - JsonArray innerarray1 = json.createArray(); - JsonArray innerarray2 = json.createArray(); - - object["hello"] = innerarray1; - object["world"] = innerarray2; - - EXPECT_EQ(innerarray1, (JsonArray) object["hello"]); - EXPECT_EQ(innerarray2, (JsonArray) object["world"]); -} - -TEST_F(JsonObject_Container_Tests, CanStoreInnerObjects) -{ - JsonObject innerObject1 = json.createObject(); - JsonObject innerObject2 = json.createObject(); - - object["hello"] = innerObject1; - object["world"] = innerObject2; - - EXPECT_EQ(innerObject1, (JsonObject) object["hello"]); - EXPECT_EQ(innerObject2, (JsonObject) object["world"]); +#include +#include +#include + +class JsonObject_Container_Tests : public ::testing::Test +{ +protected: + virtual void SetUp() + { + object = json.createObject(); + } + + StaticJsonBuffer<42> json; + JsonObject object; +}; + +TEST_F(JsonObject_Container_Tests, InitialSizeIsZero) +{ + EXPECT_EQ(0, object.size()); +} + +TEST_F(JsonObject_Container_Tests, Grow_WhenValuesAreAdded) +{ + object["hello"]; + EXPECT_EQ(1, object.size()); + + object["world"]; + EXPECT_EQ(2, object.size()); +} + +TEST_F(JsonObject_Container_Tests, DoNotGrow_WhenSameValueIsAdded) +{ + object["hello"]; + EXPECT_EQ(1, object.size()); + + object["hello"]; + EXPECT_EQ(1, object.size()); +} + +TEST_F(JsonObject_Container_Tests, Shrink_WhenValuesAreRemoved) +{ + object["hello"]; + object["world"]; + + object.remove("hello"); + EXPECT_EQ(1, object.size()); + + object.remove("world"); + EXPECT_EQ(0, object.size()); +} + +TEST_F(JsonObject_Container_Tests, DoNotShrink_WhenRemoveIsCalledWithAWrongKey) +{ + object["hello"]; + object["world"]; + + object.remove(":-P"); + + EXPECT_EQ(2, object.size()); +} + +TEST_F(JsonObject_Container_Tests, CanStoreIntegers) +{ + object["hello"] = 123; + object["world"] = 456; + + EXPECT_EQ(123, (int) object["hello"]); + EXPECT_EQ(456, (int) object["world"]); +} + +TEST_F(JsonObject_Container_Tests, CanStoreDoubles) +{ + object["hello"] = 123.45; + object["world"] = 456.78; + + EXPECT_EQ(123.45, (double) object["hello"]); + EXPECT_EQ(456.78, (double) object["world"]); +} + +TEST_F(JsonObject_Container_Tests, CanStoreBooleans) +{ + object["hello"] = true; + object["world"] = false; + + EXPECT_TRUE((bool) object["hello"]); + EXPECT_FALSE((bool) object["world"]); +} + +TEST_F(JsonObject_Container_Tests, CanStoreStrings) +{ + object["hello"] = "h3110"; + object["world"] = "w0r1d"; + + EXPECT_STREQ("h3110", (const char*) object["hello"]); + EXPECT_STREQ("w0r1d", (const char*) object["world"]); +} + +TEST_F(JsonObject_Container_Tests, CanStoreInnerArrays) +{ + JsonArray innerarray1 = json.createArray(); + JsonArray innerarray2 = json.createArray(); + + object["hello"] = innerarray1; + object["world"] = innerarray2; + + EXPECT_EQ(innerarray1, (JsonArray) object["hello"]); + EXPECT_EQ(innerarray2, (JsonArray) object["world"]); +} + +TEST_F(JsonObject_Container_Tests, CanStoreInnerObjects) +{ + JsonObject innerObject1 = json.createObject(); + JsonObject innerObject2 = json.createObject(); + + object["hello"] = innerObject1; + object["world"] = innerObject2; + + EXPECT_EQ(innerObject1, (JsonObject) object["hello"]); + EXPECT_EQ(innerObject2, (JsonObject) object["world"]); } \ No newline at end of file diff --git a/tests/JsonObject_PrettyPrintTo_Tests.cpp b/test/JsonObject_PrettyPrintTo_Tests.cpp similarity index 95% rename from tests/JsonObject_PrettyPrintTo_Tests.cpp rename to test/JsonObject_PrettyPrintTo_Tests.cpp index f27b3fc0..772e614b 100644 --- a/tests/JsonObject_PrettyPrintTo_Tests.cpp +++ b/test/JsonObject_PrettyPrintTo_Tests.cpp @@ -1,89 +1,89 @@ -/* -* Arduino JSON library -* Benoit Blanchon 2014 - MIT License -*/ - -#include -#include -#include -#include - -class JsonObject_PrettyPrintTo_Tests : public testing::Test -{ -protected: - JsonObject object; - StaticJsonBuffer<30> json; - - virtual void SetUp() - { - object = json.createObject(); - } - - void outputMustBe(const char* expected) - { - size_t n = object.prettyPrintTo(buffer, sizeof(buffer)); - EXPECT_STREQ(expected, buffer); - EXPECT_EQ(strlen(expected), n); - } - -private: - char buffer[256]; -}; - -TEST_F(JsonObject_PrettyPrintTo_Tests, EmptyObject) -{ - outputMustBe("{}"); -} - -TEST_F(JsonObject_PrettyPrintTo_Tests, OneMember) -{ - object["key"] = "value"; - - outputMustBe( - "{\r\n" - " \"key\": \"value\"\r\n" - "}"); -} - -TEST_F(JsonObject_PrettyPrintTo_Tests, TwoMembers) -{ - object["key1"] = "value1"; - object["key2"] = "value2"; - - outputMustBe( - "{\r\n" - " \"key1\": \"value1\",\r\n" - " \"key2\": \"value2\"\r\n" - "}"); -} - -TEST_F(JsonObject_PrettyPrintTo_Tests, EmptyNestedContainers) -{ - object.createNestedObject("key1"); - object.createNestedArray("key2"); - - outputMustBe( - "{\r\n" - " \"key1\": {},\r\n" - " \"key2\": []\r\n" - "}"); -} - -TEST_F(JsonObject_PrettyPrintTo_Tests, NestedContainers) -{ - JsonObject nested1 = object.createNestedObject("key1"); - nested1["a"] = 1; - - JsonArray nested2 = object.createNestedArray("key2"); - nested2.add(2); - - outputMustBe( - "{\r\n" - " \"key1\": {\r\n" - " \"a\": 1\r\n" - " },\r\n" - " \"key2\": [\r\n" - " 2\r\n" - " ]\r\n" - "}"); +/* +* Arduino JSON library +* Benoit Blanchon 2014 - MIT License +*/ + +#include +#include +#include +#include + +class JsonObject_PrettyPrintTo_Tests : public testing::Test +{ +protected: + JsonObject object; + StaticJsonBuffer<30> json; + + virtual void SetUp() + { + object = json.createObject(); + } + + void outputMustBe(const char* expected) + { + size_t n = object.prettyPrintTo(buffer, sizeof(buffer)); + EXPECT_STREQ(expected, buffer); + EXPECT_EQ(strlen(expected), n); + } + +private: + char buffer[256]; +}; + +TEST_F(JsonObject_PrettyPrintTo_Tests, EmptyObject) +{ + outputMustBe("{}"); +} + +TEST_F(JsonObject_PrettyPrintTo_Tests, OneMember) +{ + object["key"] = "value"; + + outputMustBe( + "{\r\n" + " \"key\": \"value\"\r\n" + "}"); +} + +TEST_F(JsonObject_PrettyPrintTo_Tests, TwoMembers) +{ + object["key1"] = "value1"; + object["key2"] = "value2"; + + outputMustBe( + "{\r\n" + " \"key1\": \"value1\",\r\n" + " \"key2\": \"value2\"\r\n" + "}"); +} + +TEST_F(JsonObject_PrettyPrintTo_Tests, EmptyNestedContainers) +{ + object.createNestedObject("key1"); + object.createNestedArray("key2"); + + outputMustBe( + "{\r\n" + " \"key1\": {},\r\n" + " \"key2\": []\r\n" + "}"); +} + +TEST_F(JsonObject_PrettyPrintTo_Tests, NestedContainers) +{ + JsonObject nested1 = object.createNestedObject("key1"); + nested1["a"] = 1; + + JsonArray nested2 = object.createNestedArray("key2"); + nested2.add(2); + + outputMustBe( + "{\r\n" + " \"key1\": {\r\n" + " \"a\": 1\r\n" + " },\r\n" + " \"key2\": [\r\n" + " 2\r\n" + " ]\r\n" + "}"); } \ No newline at end of file diff --git a/tests/JsonObject_Serialization_Tests.cpp b/test/JsonObject_Serialization_Tests.cpp similarity index 95% rename from tests/JsonObject_Serialization_Tests.cpp rename to test/JsonObject_Serialization_Tests.cpp index 795a9ce6..33cdbe05 100644 --- a/tests/JsonObject_Serialization_Tests.cpp +++ b/test/JsonObject_Serialization_Tests.cpp @@ -1,158 +1,158 @@ -#include -#include -#include -#include -#include - -class JsonObject_Serialization_Tests : public testing::Test -{ -protected: - virtual void SetUp() - { - object = json.createObject(); - } - - void outputMustBe(const char* expected) - { - char actual[256]; - int result = object.printTo(actual, sizeof(actual)); - - EXPECT_STREQ(expected, actual); - EXPECT_EQ(strlen(expected), result); - } - - JsonObject object; - StaticJsonBuffer<5> json; -}; - -TEST_F(JsonObject_Serialization_Tests, EmptyObject) -{ - outputMustBe("{}"); -} - -TEST_F(JsonObject_Serialization_Tests, OneString) -{ - object["key"] = "value"; - - outputMustBe("{\"key\":\"value\"}"); -} - -TEST_F(JsonObject_Serialization_Tests, TwoStrings) -{ - object["key1"] = "value1"; - object["key2"] = "value2"; - - outputMustBe("{\"key1\":\"value1\",\"key2\":\"value2\"}"); -} - -TEST_F(JsonObject_Serialization_Tests, RemoveFirst) -{ - object["key1"] = "value1"; - object["key2"] = "value2"; - object.remove("key1"); - - outputMustBe("{\"key2\":\"value2\"}"); -} - -TEST_F(JsonObject_Serialization_Tests, RemoveLast) -{ - object["key1"] = "value1"; - object["key2"] = "value2"; - object.remove("key2"); - - outputMustBe("{\"key1\":\"value1\"}"); -} - -TEST_F(JsonObject_Serialization_Tests, RemoveUnexistingKey) -{ - object["key1"] = "value1"; - object["key2"] = "value2"; - object.remove("key3"); - - outputMustBe("{\"key1\":\"value1\",\"key2\":\"value2\"}"); -} - -TEST_F(JsonObject_Serialization_Tests, ReplaceExistingKey) -{ - object["key"] = "value1"; - object["key"] = "value2"; - - outputMustBe("{\"key\":\"value2\"}"); -} - -TEST_F(JsonObject_Serialization_Tests, OneStringOverCapacity) -{ - object["key1"] = "value1"; - object["key2"] = "value2"; - object["key3"] = "value3"; - - outputMustBe("{\"key1\":\"value1\",\"key2\":\"value2\"}"); -} - -TEST_F(JsonObject_Serialization_Tests, OneInteger) -{ - object["key"] = 1; - outputMustBe("{\"key\":1}"); -} - -TEST_F(JsonObject_Serialization_Tests, OneDoubleFourDigits) -{ - object["key"].set(3.14159265358979323846, 4); - outputMustBe("{\"key\":3.1416}"); -} - -TEST_F(JsonObject_Serialization_Tests, OneDoubleDefaultDigits) -{ - object["key"] = 3.14159265358979323846; - outputMustBe("{\"key\":3.14}"); -} - -TEST_F(JsonObject_Serialization_Tests, OneNull) -{ - object["key"] = (char*) 0; - outputMustBe("{\"key\":null}"); -} - -TEST_F(JsonObject_Serialization_Tests, OneTrue) -{ - object["key"] = true; - outputMustBe("{\"key\":true}"); -} - -TEST_F(JsonObject_Serialization_Tests, OneFalse) -{ - object["key"] = false; - outputMustBe("{\"key\":false}"); -} - -TEST_F(JsonObject_Serialization_Tests, OneEmptyNestedArrayViaProxy) -{ - JsonArray nestedArray = json.createArray(); - - object["key"] = nestedArray; - - outputMustBe("{\"key\":[]}"); -} - -TEST_F(JsonObject_Serialization_Tests, OneEmptyNestedObjectViaProxy) -{ - JsonObject nestedArray = json.createObject(); - - object["key"] = nestedArray; - - outputMustBe("{\"key\":{}}"); -} - -TEST_F(JsonObject_Serialization_Tests, OneEmptyNestedObject) -{ - object.createNestedObject("key"); - - outputMustBe("{\"key\":{}}"); -} - -TEST_F(JsonObject_Serialization_Tests, OneEmptyNestedArray) -{ - object.createNestedArray("key"); - - outputMustBe("{\"key\":[]}"); +#include +#include +#include +#include +#include + +class JsonObject_Serialization_Tests : public testing::Test +{ +protected: + virtual void SetUp() + { + object = json.createObject(); + } + + void outputMustBe(const char* expected) + { + char actual[256]; + int result = object.printTo(actual, sizeof(actual)); + + EXPECT_STREQ(expected, actual); + EXPECT_EQ(strlen(expected), result); + } + + JsonObject object; + StaticJsonBuffer<5> json; +}; + +TEST_F(JsonObject_Serialization_Tests, EmptyObject) +{ + outputMustBe("{}"); +} + +TEST_F(JsonObject_Serialization_Tests, OneString) +{ + object["key"] = "value"; + + outputMustBe("{\"key\":\"value\"}"); +} + +TEST_F(JsonObject_Serialization_Tests, TwoStrings) +{ + object["key1"] = "value1"; + object["key2"] = "value2"; + + outputMustBe("{\"key1\":\"value1\",\"key2\":\"value2\"}"); +} + +TEST_F(JsonObject_Serialization_Tests, RemoveFirst) +{ + object["key1"] = "value1"; + object["key2"] = "value2"; + object.remove("key1"); + + outputMustBe("{\"key2\":\"value2\"}"); +} + +TEST_F(JsonObject_Serialization_Tests, RemoveLast) +{ + object["key1"] = "value1"; + object["key2"] = "value2"; + object.remove("key2"); + + outputMustBe("{\"key1\":\"value1\"}"); +} + +TEST_F(JsonObject_Serialization_Tests, RemoveUnexistingKey) +{ + object["key1"] = "value1"; + object["key2"] = "value2"; + object.remove("key3"); + + outputMustBe("{\"key1\":\"value1\",\"key2\":\"value2\"}"); +} + +TEST_F(JsonObject_Serialization_Tests, ReplaceExistingKey) +{ + object["key"] = "value1"; + object["key"] = "value2"; + + outputMustBe("{\"key\":\"value2\"}"); +} + +TEST_F(JsonObject_Serialization_Tests, OneStringOverCapacity) +{ + object["key1"] = "value1"; + object["key2"] = "value2"; + object["key3"] = "value3"; + + outputMustBe("{\"key1\":\"value1\",\"key2\":\"value2\"}"); +} + +TEST_F(JsonObject_Serialization_Tests, OneInteger) +{ + object["key"] = 1; + outputMustBe("{\"key\":1}"); +} + +TEST_F(JsonObject_Serialization_Tests, OneDoubleFourDigits) +{ + object["key"].set(3.14159265358979323846, 4); + outputMustBe("{\"key\":3.1416}"); +} + +TEST_F(JsonObject_Serialization_Tests, OneDoubleDefaultDigits) +{ + object["key"] = 3.14159265358979323846; + outputMustBe("{\"key\":3.14}"); +} + +TEST_F(JsonObject_Serialization_Tests, OneNull) +{ + object["key"] = (char*) 0; + outputMustBe("{\"key\":null}"); +} + +TEST_F(JsonObject_Serialization_Tests, OneTrue) +{ + object["key"] = true; + outputMustBe("{\"key\":true}"); +} + +TEST_F(JsonObject_Serialization_Tests, OneFalse) +{ + object["key"] = false; + outputMustBe("{\"key\":false}"); +} + +TEST_F(JsonObject_Serialization_Tests, OneEmptyNestedArrayViaProxy) +{ + JsonArray nestedArray = json.createArray(); + + object["key"] = nestedArray; + + outputMustBe("{\"key\":[]}"); +} + +TEST_F(JsonObject_Serialization_Tests, OneEmptyNestedObjectViaProxy) +{ + JsonObject nestedArray = json.createObject(); + + object["key"] = nestedArray; + + outputMustBe("{\"key\":{}}"); +} + +TEST_F(JsonObject_Serialization_Tests, OneEmptyNestedObject) +{ + object.createNestedObject("key"); + + outputMustBe("{\"key\":{}}"); +} + +TEST_F(JsonObject_Serialization_Tests, OneEmptyNestedArray) +{ + object.createNestedArray("key"); + + outputMustBe("{\"key\":[]}"); } \ No newline at end of file diff --git a/tests/JsonValueTests.cpp b/test/JsonValueTests.cpp similarity index 94% rename from tests/JsonValueTests.cpp rename to test/JsonValueTests.cpp index 5d6bcb89..a398ce60 100644 --- a/tests/JsonValueTests.cpp +++ b/test/JsonValueTests.cpp @@ -1,119 +1,119 @@ -#include -#include -#include - -class JsonValueTests : public ::testing::Test -{ -protected: - virtual void SetUp() - { - jsonValue1 = json.createValue(); - jsonValue2 = json.createValue(); - } - - StaticJsonBuffer<42> json; - JsonValue jsonValue1; - JsonValue jsonValue2; -}; - - -TEST_F(JsonValueTests, CanStoreInteger) -{ - jsonValue1 = 123; - - EXPECT_EQ(123, (int) jsonValue1); -} - -TEST_F(JsonValueTests, CanStoreDouble) -{ - jsonValue1 = 123.45; - - EXPECT_EQ(123.45, (double) jsonValue1); -} - -TEST_F(JsonValueTests, CanStoreTrue) -{ - jsonValue1 = true; - EXPECT_TRUE((bool) jsonValue1); -} - -TEST_F(JsonValueTests, CanStoreFalse) -{ - jsonValue1 = false; - EXPECT_FALSE((bool) jsonValue1); -} - -TEST_F(JsonValueTests, CanStoreString) -{ - jsonValue1 = "hello"; - - EXPECT_STREQ("hello", (const char*) jsonValue1); -} - -TEST_F(JsonValueTests, CanStoreObject) -{ - JsonObject innerObject1 = json.createObject(); - - jsonValue1 = innerObject1; - - EXPECT_EQ(innerObject1, (JsonObject) jsonValue1); -} - -TEST_F(JsonValueTests, IntegersAreCopiedByValue) -{ - jsonValue1 = 123; - jsonValue2 = jsonValue1; - jsonValue1 = 456; - - EXPECT_EQ(123, (int) jsonValue2); -} - -TEST_F(JsonValueTests, DoublesAreCopiedByValue) -{ - jsonValue1 = 123.45; - jsonValue2 = jsonValue1; - jsonValue1 = 456.78; - - EXPECT_EQ(123.45, (double) jsonValue2); -} - -TEST_F(JsonValueTests, BooleansAreCopiedByValue) -{ - jsonValue1 = true; - jsonValue2 = jsonValue1; - jsonValue1 = false; - - EXPECT_TRUE((bool) jsonValue2); -} - -TEST_F(JsonValueTests, StringsAreCopiedByValue) -{ - jsonValue1 = "hello"; - jsonValue2 = jsonValue1; - jsonValue1 = "world"; - - EXPECT_STREQ("hello", (const char*) jsonValue2); -} - - -TEST_F(JsonValueTests, ObjectsAreCopiedByReference) -{ - JsonObject object = json.createObject(); - - jsonValue1 = object; - - object["hello"] = "world"; - - EXPECT_EQ(1, ((JsonObject) jsonValue1).size()); -} - -TEST_F(JsonValueTests, ArraysAreCopiedByReference) -{ - JsonArray array = json.createArray(); - - jsonValue1 = array; - - array.add("world"); - - EXPECT_EQ(1, ((JsonObject) jsonValue1).size()); +#include +#include +#include + +class JsonValueTests : public ::testing::Test +{ +protected: + virtual void SetUp() + { + jsonValue1 = json.createValue(); + jsonValue2 = json.createValue(); + } + + StaticJsonBuffer<42> json; + JsonValue jsonValue1; + JsonValue jsonValue2; +}; + + +TEST_F(JsonValueTests, CanStoreInteger) +{ + jsonValue1 = 123; + + EXPECT_EQ(123, (int) jsonValue1); +} + +TEST_F(JsonValueTests, CanStoreDouble) +{ + jsonValue1 = 123.45; + + EXPECT_EQ(123.45, (double) jsonValue1); +} + +TEST_F(JsonValueTests, CanStoreTrue) +{ + jsonValue1 = true; + EXPECT_TRUE((bool) jsonValue1); +} + +TEST_F(JsonValueTests, CanStoreFalse) +{ + jsonValue1 = false; + EXPECT_FALSE((bool) jsonValue1); +} + +TEST_F(JsonValueTests, CanStoreString) +{ + jsonValue1 = "hello"; + + EXPECT_STREQ("hello", (const char*) jsonValue1); +} + +TEST_F(JsonValueTests, CanStoreObject) +{ + JsonObject innerObject1 = json.createObject(); + + jsonValue1 = innerObject1; + + EXPECT_EQ(innerObject1, (JsonObject) jsonValue1); +} + +TEST_F(JsonValueTests, IntegersAreCopiedByValue) +{ + jsonValue1 = 123; + jsonValue2 = jsonValue1; + jsonValue1 = 456; + + EXPECT_EQ(123, (int) jsonValue2); +} + +TEST_F(JsonValueTests, DoublesAreCopiedByValue) +{ + jsonValue1 = 123.45; + jsonValue2 = jsonValue1; + jsonValue1 = 456.78; + + EXPECT_EQ(123.45, (double) jsonValue2); +} + +TEST_F(JsonValueTests, BooleansAreCopiedByValue) +{ + jsonValue1 = true; + jsonValue2 = jsonValue1; + jsonValue1 = false; + + EXPECT_TRUE((bool) jsonValue2); +} + +TEST_F(JsonValueTests, StringsAreCopiedByValue) +{ + jsonValue1 = "hello"; + jsonValue2 = jsonValue1; + jsonValue1 = "world"; + + EXPECT_STREQ("hello", (const char*) jsonValue2); +} + + +TEST_F(JsonValueTests, ObjectsAreCopiedByReference) +{ + JsonObject object = json.createObject(); + + jsonValue1 = object; + + object["hello"] = "world"; + + EXPECT_EQ(1, ((JsonObject) jsonValue1).size()); +} + +TEST_F(JsonValueTests, ArraysAreCopiedByReference) +{ + JsonArray array = json.createArray(); + + jsonValue1 = array; + + array.add("world"); + + EXPECT_EQ(1, ((JsonObject) jsonValue1).size()); } \ No newline at end of file diff --git a/tests/StaticJsonBufferTests.cpp b/test/StaticJsonBufferTests.cpp similarity index 95% rename from tests/StaticJsonBufferTests.cpp rename to test/StaticJsonBufferTests.cpp index f5061442..37609886 100644 --- a/tests/StaticJsonBufferTests.cpp +++ b/test/StaticJsonBufferTests.cpp @@ -1,69 +1,69 @@ -#include -#include -#include - -TEST(StaticJsonBuffer, CapacityMatchTemplateParameter) -{ - StaticJsonBuffer<42> json; - EXPECT_EQ(42, json.capacity()); -} - -TEST(StaticJsonBuffer, InitialSizeIsZero) -{ - StaticJsonBuffer<42> json; - EXPECT_EQ(0, json.size()); -} - -TEST(StaticJsonBuffer, WhenCreateObjectIsCalled_ThenSizeIsIncreasedByOne) -{ - StaticJsonBuffer<42> json; - - json.createObject(); - EXPECT_EQ(1, json.size()); - - json.createObject(); - EXPECT_EQ(2, json.size()); -} - -TEST(StaticJsonBuffer, GivenBufferIsFull_WhenCreateObjectIsCalled_ThenSizeDoesNotChange) -{ - StaticJsonBuffer<1> json; - - json.createObject(); - EXPECT_EQ(1, json.size()); - - json.createObject(); - EXPECT_EQ(1, json.size()); -} - -TEST(StaticJsonBuffer, WhenCreateObjectIsCalled_ThenAnEmptyJsonObjectIsReturned) -{ - StaticJsonBuffer<42> json; - - JsonObject obj = json.createObject(); - EXPECT_EQ(0, obj.size()); -} - -TEST(StaticJsonBuffer, GivenAJsonObject_WhenValuesAreAdded_ThenSizeIsIncreasedByTwo) -{ - StaticJsonBuffer<42> json; - JsonObject obj = json.createObject(); - - obj["hello"]; - EXPECT_EQ(3, json.size()); - - obj["world"]; - EXPECT_EQ(5, json.size()); -} - -TEST(StaticJsonBuffer, GivenAJsonObject_WhenSameValuesAreAddedTwice_ThenSizeIsOnlyIncreasedByTwo) -{ - StaticJsonBuffer<42> json; - JsonObject obj = json.createObject(); - - obj["hello"]; - EXPECT_EQ(3, json.size()); - - obj["hello"]; - EXPECT_EQ(3, json.size()); +#include +#include +#include + +TEST(StaticJsonBuffer, CapacityMatchTemplateParameter) +{ + StaticJsonBuffer<42> json; + EXPECT_EQ(42, json.capacity()); +} + +TEST(StaticJsonBuffer, InitialSizeIsZero) +{ + StaticJsonBuffer<42> json; + EXPECT_EQ(0, json.size()); +} + +TEST(StaticJsonBuffer, WhenCreateObjectIsCalled_ThenSizeIsIncreasedByOne) +{ + StaticJsonBuffer<42> json; + + json.createObject(); + EXPECT_EQ(1, json.size()); + + json.createObject(); + EXPECT_EQ(2, json.size()); +} + +TEST(StaticJsonBuffer, GivenBufferIsFull_WhenCreateObjectIsCalled_ThenSizeDoesNotChange) +{ + StaticJsonBuffer<1> json; + + json.createObject(); + EXPECT_EQ(1, json.size()); + + json.createObject(); + EXPECT_EQ(1, json.size()); +} + +TEST(StaticJsonBuffer, WhenCreateObjectIsCalled_ThenAnEmptyJsonObjectIsReturned) +{ + StaticJsonBuffer<42> json; + + JsonObject obj = json.createObject(); + EXPECT_EQ(0, obj.size()); +} + +TEST(StaticJsonBuffer, GivenAJsonObject_WhenValuesAreAdded_ThenSizeIsIncreasedByTwo) +{ + StaticJsonBuffer<42> json; + JsonObject obj = json.createObject(); + + obj["hello"]; + EXPECT_EQ(3, json.size()); + + obj["world"]; + EXPECT_EQ(5, json.size()); +} + +TEST(StaticJsonBuffer, GivenAJsonObject_WhenSameValuesAreAddedTwice_ThenSizeIsOnlyIncreasedByTwo) +{ + StaticJsonBuffer<42> json; + JsonObject obj = json.createObject(); + + obj["hello"]; + EXPECT_EQ(3, json.size()); + + obj["hello"]; + EXPECT_EQ(3, json.size()); } \ No newline at end of file diff --git a/tests/StringBuilderTests.cpp b/test/StringBuilderTests.cpp similarity index 94% rename from tests/StringBuilderTests.cpp rename to test/StringBuilderTests.cpp index e0edea59..9b47004e 100644 --- a/tests/StringBuilderTests.cpp +++ b/test/StringBuilderTests.cpp @@ -1,75 +1,75 @@ -#include -#include - -using namespace ArduinoJson::Internals; - -class StringBuilderTests : public testing::Test -{ -protected: - - virtual void SetUp() - { - sb = new StringBuilder(buffer, sizeof(buffer)); - } - - void print(const char* value) - { - returnValue = sb->print(value); - } - - void outputMustBe(const char* expected) - { - EXPECT_STREQ(expected, buffer); - } - - void resultMustBe(size_t expected) - { - EXPECT_EQ(expected, returnValue); - } - -private: - char buffer[20]; - Print* sb; - size_t returnValue; -}; - -TEST_F(StringBuilderTests, InitialState) -{ - outputMustBe(""); -} - -TEST_F(StringBuilderTests, OverCapacity) -{ - print("ABCDEFGHIJKLMNOPQRSTUVWXYZ"); - resultMustBe(19); - - print("ABC"); - resultMustBe(0); - - outputMustBe("ABCDEFGHIJKLMNOPQRS"); -} - -TEST_F(StringBuilderTests, EmptyString) -{ - print(""); - resultMustBe(0); - outputMustBe(""); -} - -TEST_F(StringBuilderTests, OneString) -{ - print("ABCD"); - resultMustBe(4); - outputMustBe("ABCD"); -} - -TEST_F(StringBuilderTests, TwoStrings) -{ - print("ABCD"); - resultMustBe(4); - - print("EFGH"); - resultMustBe(4); - - outputMustBe("ABCDEFGH"); +#include +#include + +using namespace ArduinoJson::Internals; + +class StringBuilderTests : public testing::Test +{ +protected: + + virtual void SetUp() + { + sb = new StringBuilder(buffer, sizeof(buffer)); + } + + void print(const char* value) + { + returnValue = sb->print(value); + } + + void outputMustBe(const char* expected) + { + EXPECT_STREQ(expected, buffer); + } + + void resultMustBe(size_t expected) + { + EXPECT_EQ(expected, returnValue); + } + +private: + char buffer[20]; + Print* sb; + size_t returnValue; +}; + +TEST_F(StringBuilderTests, InitialState) +{ + outputMustBe(""); +} + +TEST_F(StringBuilderTests, OverCapacity) +{ + print("ABCDEFGHIJKLMNOPQRSTUVWXYZ"); + resultMustBe(19); + + print("ABC"); + resultMustBe(0); + + outputMustBe("ABCDEFGHIJKLMNOPQRS"); +} + +TEST_F(StringBuilderTests, EmptyString) +{ + print(""); + resultMustBe(0); + outputMustBe(""); +} + +TEST_F(StringBuilderTests, OneString) +{ + print("ABCD"); + resultMustBe(4); + outputMustBe("ABCD"); +} + +TEST_F(StringBuilderTests, TwoStrings) +{ + print("ABCD"); + resultMustBe(4); + + print("EFGH"); + resultMustBe(4); + + outputMustBe("ABCDEFGH"); } \ No newline at end of file