Переглянути джерело

Renamed tests/ into test/

Benoit Blanchon 11 роки тому
батько
коміт
b847576bb4

+ 1 - 1
CMakeLists.txt

@@ -4,4 +4,4 @@ project(ArduinoJson)
 enable_testing()
 
 add_subdirectory(srcs)
-add_subdirectory(tests)
+add_subdirectory(test)

+ 18 - 18
tests/CMakeLists.txt → 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)

+ 86 - 86
tests/EscapedStringTests.cpp → test/EscapedStringTests.cpp

@@ -1,87 +1,87 @@
-#include <gtest/gtest.h>
-
-#include <ArduinoJson/Internals/EscapedString.h>
-#include <ArduinoJson/Internals/StringBuilder.h>
-
-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 <gtest/gtest.h>
+
+#include <ArduinoJson/Internals/EscapedString.h>
+#include <ArduinoJson/Internals/StringBuilder.h>
+
+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\"");
 }

+ 80 - 80
tests/Issue10.cpp → test/Issue10.cpp

@@ -1,80 +1,80 @@
-#include <gtest/gtest.h>
-#include <ArduinoJson/JsonArray.h>
-#include <ArduinoJson/JsonObject.h>
-#include <ArduinoJson/JsonValue.h>
-#include <ArduinoJson/StaticJsonBuffer.h>
-
-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 <gtest/gtest.h>
+#include <ArduinoJson/JsonArray.h>
+#include <ArduinoJson/JsonObject.h>
+#include <ArduinoJson/JsonValue.h>
+#include <ArduinoJson/StaticJsonBuffer.h>
+
+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);
+}

+ 149 - 149
tests/JsonArray_Container_Tests.cpp → test/JsonArray_Container_Tests.cpp

@@ -1,150 +1,150 @@
-#include <gtest/gtest.h>
-#include <ArduinoJson/StaticJsonBuffer.h>
-#include <ArduinoJson/JsonValue.h>
-
-class JsonArray_Container_Tests : public ::testing::Test
-{
-protected:
-    virtual void SetUp()
-    {
-        array = json.createArray();
-    }
-
-    void nodeCountMustBe(int expected)
-    {
-        EXPECT_EQ(expected, json.size());
-    }
-
-    template<typename T>
-    void firstElementMustBe(T expected)
-    {
-        elementAtIndexMustBe(0, expected);
-    }
-
-    template<typename T>
-    void secondElementMustBe(T expected)
-    {
-        elementAtIndexMustBe(1, expected);
-    }
-
-    void sizeMustBe(int expected)
-    {
-        EXPECT_EQ(expected, array.size());
-    }
-
-    StaticJsonBuffer<42> json;
-    JsonArray array;
-
-private:
-    template<typename T>
-    void elementAtIndexMustBe(int index, T expected)
-    {
-        EXPECT_EQ(expected, static_cast<T>(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 <gtest/gtest.h>
+#include <ArduinoJson/StaticJsonBuffer.h>
+#include <ArduinoJson/JsonValue.h>
+
+class JsonArray_Container_Tests : public ::testing::Test
+{
+protected:
+    virtual void SetUp()
+    {
+        array = json.createArray();
+    }
+
+    void nodeCountMustBe(int expected)
+    {
+        EXPECT_EQ(expected, json.size());
+    }
+
+    template<typename T>
+    void firstElementMustBe(T expected)
+    {
+        elementAtIndexMustBe(0, expected);
+    }
+
+    template<typename T>
+    void secondElementMustBe(T expected)
+    {
+        elementAtIndexMustBe(1, expected);
+    }
+
+    void sizeMustBe(int expected)
+    {
+        EXPECT_EQ(expected, array.size());
+    }
+
+    StaticJsonBuffer<42> json;
+    JsonArray array;
+
+private:
+    template<typename T>
+    void elementAtIndexMustBe(int index, T expected)
+    {
+        EXPECT_EQ(expected, static_cast<T>(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);
 }

+ 0 - 0
tests/JsonArray_Parser_Tests.cpp → test/JsonArray_Parser_Tests.cpp


+ 91 - 91
tests/JsonArray_PrettyPrintTo_Tests.cpp → test/JsonArray_PrettyPrintTo_Tests.cpp

@@ -1,92 +1,92 @@
-/*
-* Arduino JSON library
-* Benoit Blanchon 2014 - MIT License
-*/
-
-#include <gtest/gtest.h>
-#include <ArduinoJson/JsonArray.h>
-#include <ArduinoJson/JsonObject.h>
-#include <ArduinoJson/JsonValue.h>
-#include <ArduinoJson/StaticJsonBuffer.h>
-
-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 <gtest/gtest.h>
+#include <ArduinoJson/JsonArray.h>
+#include <ArduinoJson/JsonObject.h>
+#include <ArduinoJson/JsonValue.h>
+#include <ArduinoJson/StaticJsonBuffer.h>
+
+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"
+        "]");
 }

+ 147 - 147
tests/JsonArray_PrintTo_Tests.cpp → test/JsonArray_PrintTo_Tests.cpp

@@ -1,148 +1,148 @@
-/*
-* Arduino JSON library
-* Benoit Blanchon 2014 - MIT License
-*/
-
-#include <gtest/gtest.h>
-#include <ArduinoJson/JsonArray.h>
-#include <ArduinoJson/JsonObject.h>
-#include <ArduinoJson/StaticJsonBuffer.h>
-
-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 <gtest/gtest.h>
+#include <ArduinoJson/JsonArray.h>
+#include <ArduinoJson/JsonObject.h>
+#include <ArduinoJson/StaticJsonBuffer.h>
+
+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("[{}]");
 }

+ 119 - 119
tests/JsonObject_Container_Tests.cpp → test/JsonObject_Container_Tests.cpp

@@ -1,120 +1,120 @@
-#include <gtest/gtest.h>
-#include <ArduinoJson/StaticJsonBuffer.h>
-#include <ArduinoJson/JsonValue.h>
-
-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 <gtest/gtest.h>
+#include <ArduinoJson/StaticJsonBuffer.h>
+#include <ArduinoJson/JsonValue.h>
+
+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"]);
 }

+ 88 - 88
tests/JsonObject_PrettyPrintTo_Tests.cpp → test/JsonObject_PrettyPrintTo_Tests.cpp

@@ -1,89 +1,89 @@
-/*
-* Arduino JSON library
-* Benoit Blanchon 2014 - MIT License
-*/
-
-#include <gtest/gtest.h>
-#include <ArduinoJson/JsonObject.h>
-#include <ArduinoJson/JsonValue.h>
-#include <ArduinoJson/StaticJsonBuffer.h>
-
-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 <gtest/gtest.h>
+#include <ArduinoJson/JsonObject.h>
+#include <ArduinoJson/JsonValue.h>
+#include <ArduinoJson/StaticJsonBuffer.h>
+
+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"
+        "}");
 }

+ 157 - 157
tests/JsonObject_Serialization_Tests.cpp → test/JsonObject_Serialization_Tests.cpp

@@ -1,158 +1,158 @@
-#include <gtest/gtest.h>
-#include <ArduinoJson/JsonArray.h>
-#include <ArduinoJson/JsonObject.h>
-#include <ArduinoJson/JsonValue.h>
-#include <ArduinoJson/StaticJsonBuffer.h>
-
-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 <gtest/gtest.h>
+#include <ArduinoJson/JsonArray.h>
+#include <ArduinoJson/JsonObject.h>
+#include <ArduinoJson/JsonValue.h>
+#include <ArduinoJson/StaticJsonBuffer.h>
+
+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\":[]}");
 }

+ 118 - 118
tests/JsonValueTests.cpp → test/JsonValueTests.cpp

@@ -1,119 +1,119 @@
-#include <gtest/gtest.h>
-#include <ArduinoJson/StaticJsonBuffer.h>
-#include <ArduinoJson/JsonValue.h>
-
-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 <gtest/gtest.h>
+#include <ArduinoJson/StaticJsonBuffer.h>
+#include <ArduinoJson/JsonValue.h>
+
+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());
 }

+ 68 - 68
tests/StaticJsonBufferTests.cpp → test/StaticJsonBufferTests.cpp

@@ -1,69 +1,69 @@
-#include <gtest/gtest.h>
-#include <ArduinoJson/StaticJsonBuffer.h>
-#include <ArduinoJson/JsonValue.h>
-
-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 <gtest/gtest.h>
+#include <ArduinoJson/StaticJsonBuffer.h>
+#include <ArduinoJson/JsonValue.h>
+
+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());
 }

+ 74 - 74
tests/StringBuilderTests.cpp → test/StringBuilderTests.cpp

@@ -1,75 +1,75 @@
-#include <gtest/gtest.h>
-#include <ArduinoJson/Internals/StringBuilder.h>
-
-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 <gtest/gtest.h>
+#include <ArduinoJson/Internals/StringBuilder.h>
+
+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");
 }