Added a test class for StringBuilder.appendEscaped()

This commit is contained in:
Benoît Blanchon
2014-06-26 13:05:49 +02:00
parent 7ab728e996
commit 25118ad8c0
4 changed files with 78 additions and 9 deletions

View File

@ -86,7 +86,8 @@
<ClCompile Include="JsonArrayTests.cpp" />
<ClCompile Include="JsonObjectBase.cpp" />
<ClCompile Include="StringBuilder.cpp" />
<ClCompile Include="StringBuilderTests.cpp" />
<ClCompile Include="StringBuilderAppendEscapedTests.cpp" />
<ClCompile Include="StringBuilderAppendTests.cpp" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="JsonArray.h" />

View File

@ -27,7 +27,10 @@
<ClCompile Include="JsonObjectBase.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="StringBuilderTests.cpp">
<ClCompile Include="StringBuilderAppendEscapedTests.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="StringBuilderAppendTests.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>

View File

@ -0,0 +1,66 @@
#include "CppUnitTest.h"
#include "StringBuilder.h"
using namespace Microsoft::VisualStudio::CppUnitTestFramework;
namespace JsonGeneratorTests
{
TEST_CLASS(StringBuilderAppendEscapedTests)
{
char buffer[16];
StringBuilder* sb;
public:
TEST_METHOD_INITIALIZE(Initialize)
{
sb = new StringBuilder(buffer, sizeof(buffer));
}
TEST_METHOD(InitialState)
{
assertResultIs("");
}
TEST_METHOD(EmptyString)
{
append("");
assertResultIs("\"\"");
}
TEST_METHOD(OneString)
{
append("ABCD");
assertResultIs("\"ABCD\"");
}
TEST_METHOD(OneTwoStrings)
{
append("ABCD");
append("EFGH");
assertResultIs("\"ABCD\"\"EFGH\"");
}
TEST_METHOD(OverCapacity)
{
append("ABCDEFGHIJKLMNOPQRSTUVWXYZ");
assertResultIs("\"ABCDEFGHIJKLM\"");
}
/*
TEST_METHOD(SpecialChars)
{
append("\\\"\b\f\n\r");
assertResultIs("\\\\\\\"\\\b\\\f\\\n\\\r");
}
*/
void append(const char* s)
{
sb->appendEscaped(s);
}
void assertResultIs(const char* expected)
{
Assert::AreEqual(expected, buffer);
}
};
}

View File

@ -5,12 +5,11 @@ using namespace Microsoft::VisualStudio::CppUnitTestFramework;
namespace JsonGeneratorTests
{
TEST_CLASS(StringBuilderTests)
TEST_CLASS(StringBuilderAppendTests)
{
char buffer[16];
StringBuilder* sb;
public:
TEST_METHOD_INITIALIZE(Initialize)
@ -23,32 +22,32 @@ namespace JsonGeneratorTests
assertResultIs("");
}
TEST_METHOD(AppendEmptyString)
TEST_METHOD(EmptyString)
{
append("");
assertResultIs("");
}
TEST_METHOD(AppendOneString)
TEST_METHOD(OneString)
{
append("ABCD");
assertResultIs("ABCD");
}
TEST_METHOD(AppendOneTwoStrings)
TEST_METHOD(TwoStrings)
{
append("ABCD");
append("EFGH");
assertResultIs("ABCDEFGH");
}
TEST_METHOD(AppendOverCapacity)
TEST_METHOD(OverCapacity)
{
append("ABCDEFGHIJKLMNOPQRSTUVWXYZ");
assertResultIs("ABCDEFGHIJKLMNO");
}
TEST_METHOD(AppendSpecialChars)
TEST_METHOD(SpecialChars)
{
append("\\\"\/\b\f\n\r");
assertResultIs("\\\"\/\b\f\n\r");