Splitted the indentation tests into 3 files

This commit is contained in:
Benoit Blanchon
2014-08-25 10:42:00 +02:00
parent 76f9ecce75
commit 514a6c0879
5 changed files with 107 additions and 26 deletions

View 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);
}
};
}

View File

@ -18,12 +18,6 @@ namespace JsonGeneratorTests
size_t returnValue; size_t returnValue;
public: public:
TEST_METHOD(EmptyString)
{
whenInputIs("");
outputMustBe("");
}
TEST_METHOD(EmptyObject) TEST_METHOD(EmptyObject)
{ {
@ -31,13 +25,7 @@ namespace JsonGeneratorTests
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(

View 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);
}
};
}

View File

@ -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" />

View File

@ -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>