From 514a6c0879fe3e3cf69176044c2c8401c64164e3 Mon Sep 17 00:00:00 2001 From: Benoit Blanchon Date: Mon, 25 Aug 2014 10:42:00 +0200 Subject: [PATCH] Splitted the indentation tests into 3 files --- JsonGeneratorTests/Intented_Array_Tests.cpp | 44 ++++++++++++++++ ...intTests.cpp => Intented_Object_Tests.cpp} | 27 ++-------- JsonGeneratorTests/Intented_String_Tests.cpp | 50 +++++++++++++++++++ JsonGeneratorTests/JsonGeneratorTests.vcxproj | 4 +- .../JsonGeneratorTests.vcxproj.filters | 8 ++- 5 files changed, 107 insertions(+), 26 deletions(-) create mode 100644 JsonGeneratorTests/Intented_Array_Tests.cpp rename JsonGeneratorTests/{IntentedPrintTests.cpp => Intented_Object_Tests.cpp} (69%) create mode 100644 JsonGeneratorTests/Intented_String_Tests.cpp diff --git a/JsonGeneratorTests/Intented_Array_Tests.cpp b/JsonGeneratorTests/Intented_Array_Tests.cpp new file mode 100644 index 00000000..193b4ba4 --- /dev/null +++ b/JsonGeneratorTests/Intented_Array_Tests.cpp @@ -0,0 +1,44 @@ +/* +* Arduino JSON library +* Benoit Blanchon 2014 - MIT License +*/ + +#include "CppUnitTest.h" +#include "IndentedPrintDecorator.h" +#include "StringBuilder.h" + +using namespace ArduinoJson::Internals; +using namespace Microsoft::VisualStudio::CppUnitTestFramework; + +namespace JsonGeneratorTests +{ + TEST_CLASS(IntentedPrintTests) + { + char buffer[1024]; + size_t returnValue; + + public: + + TEST_METHOD(EmptyArray) + { + whenInputIs("[]"); + outputMustBe("[]"); + } + + private: + + void whenInputIs(const char input[]) + { + StringBuilder sb(buffer, sizeof(buffer)); + IndentedPrintDecorator decorator(sb); + + returnValue = decorator.print(input); + } + + void outputMustBe(const char* expected) + { + Assert::AreEqual(expected, buffer); + Assert::AreEqual(strlen(expected), returnValue); + } + }; +} \ No newline at end of file diff --git a/JsonGeneratorTests/IntentedPrintTests.cpp b/JsonGeneratorTests/Intented_Object_Tests.cpp similarity index 69% rename from JsonGeneratorTests/IntentedPrintTests.cpp rename to JsonGeneratorTests/Intented_Object_Tests.cpp index deec99ec..7dc42257 100644 --- a/JsonGeneratorTests/IntentedPrintTests.cpp +++ b/JsonGeneratorTests/Intented_Object_Tests.cpp @@ -18,12 +18,6 @@ namespace JsonGeneratorTests size_t returnValue; public: - - TEST_METHOD(EmptyString) - { - whenInputIs(""); - outputMustBe(""); - } TEST_METHOD(EmptyObject) { @@ -31,13 +25,7 @@ namespace JsonGeneratorTests outputMustBe("{}"); } - TEST_METHOD(EmptyArray) - { - whenInputIs("[]"); - outputMustBe("[]"); - } - - TEST_METHOD(ObjectWithOneMember) + TEST_METHOD(OneMember) { whenInputIs("{\"key\":\"value\"}"); outputMustBe( @@ -46,7 +34,7 @@ namespace JsonGeneratorTests "}"); } - TEST_METHOD(ObjectWithTwoMembers) + TEST_METHOD(TwoMembers) { whenInputIs("{\"key1\":\"value1\",\"key2\":\"value2\"}"); outputMustBe( @@ -56,16 +44,7 @@ namespace JsonGeneratorTests "}"); } - TEST_METHOD(ObjectTrickyCharacters) - { - whenInputIs("{\"key\":\":\\\"',\"}"); - outputMustBe( - "{\n" - " \"key\": \":\\\"',\"\n" - "}"); - } - - TEST_METHOD(ObjectWithEmptyNestedObjects) + TEST_METHOD(EmptyNestedObjects) { whenInputIs("{\"key1\":{},\"key2\":{}}"); outputMustBe( diff --git a/JsonGeneratorTests/Intented_String_Tests.cpp b/JsonGeneratorTests/Intented_String_Tests.cpp new file mode 100644 index 00000000..f29ad88f --- /dev/null +++ b/JsonGeneratorTests/Intented_String_Tests.cpp @@ -0,0 +1,50 @@ +/* +* Arduino JSON library +* Benoit Blanchon 2014 - MIT License +*/ + +#include "CppUnitTest.h" +#include "IndentedPrintDecorator.h" +#include "StringBuilder.h" + +using namespace ArduinoJson::Internals; +using namespace Microsoft::VisualStudio::CppUnitTestFramework; + +namespace JsonGeneratorTests +{ + TEST_CLASS(IntentedPrintTests) + { + char buffer[1024]; + size_t returnValue; + + public: + + TEST_METHOD(EmptyString) + { + whenInputIs(""); + outputMustBe(""); + } + + TEST_METHOD(TrickyCharacters) + { + whenInputIs ("\":\\\"',\""); + outputMustBe("\":\\\"',\""); + } + + private: + + void whenInputIs(const char input[]) + { + StringBuilder sb(buffer, sizeof(buffer)); + IndentedPrintDecorator decorator(sb); + + returnValue = decorator.print(input); + } + + void outputMustBe(const char* expected) + { + Assert::AreEqual(expected, buffer); + Assert::AreEqual(strlen(expected), returnValue); + } + }; +} \ No newline at end of file diff --git a/JsonGeneratorTests/JsonGeneratorTests.vcxproj b/JsonGeneratorTests/JsonGeneratorTests.vcxproj index 22132844..e9456dc5 100644 --- a/JsonGeneratorTests/JsonGeneratorTests.vcxproj +++ b/JsonGeneratorTests/JsonGeneratorTests.vcxproj @@ -85,7 +85,9 @@ - + + + diff --git a/JsonGeneratorTests/JsonGeneratorTests.vcxproj.filters b/JsonGeneratorTests/JsonGeneratorTests.vcxproj.filters index 47af2728..b6cd652c 100644 --- a/JsonGeneratorTests/JsonGeneratorTests.vcxproj.filters +++ b/JsonGeneratorTests/JsonGeneratorTests.vcxproj.filters @@ -39,7 +39,13 @@ Source Files - + + Source Files + + + Source Files + + Source Files