forked from bblanchon/ArduinoJson
Splitted the indentation tests into 3 files
This commit is contained in:
44
JsonGeneratorTests/Intented_Array_Tests.cpp
Normal file
44
JsonGeneratorTests/Intented_Array_Tests.cpp
Normal file
@ -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);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
@ -19,25 +19,13 @@ namespace JsonGeneratorTests
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
TEST_METHOD(EmptyString)
|
|
||||||
{
|
|
||||||
whenInputIs("");
|
|
||||||
outputMustBe("");
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST_METHOD(EmptyObject)
|
TEST_METHOD(EmptyObject)
|
||||||
{
|
{
|
||||||
whenInputIs("{}");
|
whenInputIs("{}");
|
||||||
outputMustBe("{}");
|
outputMustBe("{}");
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_METHOD(EmptyArray)
|
TEST_METHOD(OneMember)
|
||||||
{
|
|
||||||
whenInputIs("[]");
|
|
||||||
outputMustBe("[]");
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST_METHOD(ObjectWithOneMember)
|
|
||||||
{
|
{
|
||||||
whenInputIs("{\"key\":\"value\"}");
|
whenInputIs("{\"key\":\"value\"}");
|
||||||
outputMustBe(
|
outputMustBe(
|
||||||
@ -46,7 +34,7 @@ namespace JsonGeneratorTests
|
|||||||
"}");
|
"}");
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_METHOD(ObjectWithTwoMembers)
|
TEST_METHOD(TwoMembers)
|
||||||
{
|
{
|
||||||
whenInputIs("{\"key1\":\"value1\",\"key2\":\"value2\"}");
|
whenInputIs("{\"key1\":\"value1\",\"key2\":\"value2\"}");
|
||||||
outputMustBe(
|
outputMustBe(
|
||||||
@ -56,16 +44,7 @@ namespace JsonGeneratorTests
|
|||||||
"}");
|
"}");
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_METHOD(ObjectTrickyCharacters)
|
TEST_METHOD(EmptyNestedObjects)
|
||||||
{
|
|
||||||
whenInputIs("{\"key\":\":\\\"',\"}");
|
|
||||||
outputMustBe(
|
|
||||||
"{\n"
|
|
||||||
" \"key\": \":\\\"',\"\n"
|
|
||||||
"}");
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST_METHOD(ObjectWithEmptyNestedObjects)
|
|
||||||
{
|
{
|
||||||
whenInputIs("{\"key1\":{},\"key2\":{}}");
|
whenInputIs("{\"key1\":{},\"key2\":{}}");
|
||||||
outputMustBe(
|
outputMustBe(
|
50
JsonGeneratorTests/Intented_String_Tests.cpp
Normal file
50
JsonGeneratorTests/Intented_String_Tests.cpp
Normal file
@ -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);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
@ -85,7 +85,9 @@
|
|||||||
</ItemDefinitionGroup>
|
</ItemDefinitionGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ClCompile Include="EscapedStringTests.cpp" />
|
<ClCompile Include="EscapedStringTests.cpp" />
|
||||||
<ClCompile Include="IntentedPrintTests.cpp" />
|
<ClCompile Include="Intented_Array_Tests.cpp" />
|
||||||
|
<ClCompile Include="Intented_Object_Tests.cpp" />
|
||||||
|
<ClCompile Include="Intented_String_Tests.cpp" />
|
||||||
<ClCompile Include="Issue10.cpp" />
|
<ClCompile Include="Issue10.cpp" />
|
||||||
<ClCompile Include="JsonArrayTests.cpp" />
|
<ClCompile Include="JsonArrayTests.cpp" />
|
||||||
<ClCompile Include="JsonObject_Indexer_Tests.cpp" />
|
<ClCompile Include="JsonObject_Indexer_Tests.cpp" />
|
||||||
|
@ -39,7 +39,13 @@
|
|||||||
<ClCompile Include="Issue10.cpp">
|
<ClCompile Include="Issue10.cpp">
|
||||||
<Filter>Source Files</Filter>
|
<Filter>Source Files</Filter>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
<ClCompile Include="IntentedPrintTests.cpp">
|
<ClCompile Include="Intented_Array_Tests.cpp">
|
||||||
|
<Filter>Source Files</Filter>
|
||||||
|
</ClCompile>
|
||||||
|
<ClCompile Include="Intented_Object_Tests.cpp">
|
||||||
|
<Filter>Source Files</Filter>
|
||||||
|
</ClCompile>
|
||||||
|
<ClCompile Include="Intented_String_Tests.cpp">
|
||||||
<Filter>Source Files</Filter>
|
<Filter>Source Files</Filter>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
Reference in New Issue
Block a user