mirror of
https://github.com/bblanchon/ArduinoJson.git
synced 2025-07-30 02:37:35 +02:00
Converted EscapedString tests to gtest
This commit is contained in:
87
tests/EscapedStringTests.cpp
Normal file
87
tests/EscapedStringTests.cpp
Normal file
@ -0,0 +1,87 @@
|
|||||||
|
#include <gtest/gtest.h>
|
||||||
|
|
||||||
|
#include "EscapedString.h"
|
||||||
|
#include "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\"");
|
||||||
|
}
|
@ -85,6 +85,7 @@
|
|||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ClCompile Include="..\third-party\gtest-1.7.0\src\gtest-all.cc" />
|
<ClCompile Include="..\third-party\gtest-1.7.0\src\gtest-all.cc" />
|
||||||
<ClCompile Include="..\third-party\gtest-1.7.0\src\gtest_main.cc" />
|
<ClCompile Include="..\third-party\gtest-1.7.0\src\gtest_main.cc" />
|
||||||
|
<ClCompile Include="EscapedStringTests.cpp" />
|
||||||
<ClCompile Include="JsonObjectSerializationTests.cpp" />
|
<ClCompile Include="JsonObjectSerializationTests.cpp" />
|
||||||
<ClCompile Include="JsonObjectTests.cpp" />
|
<ClCompile Include="JsonObjectTests.cpp" />
|
||||||
<ClCompile Include="JsonValueTests.cpp" />
|
<ClCompile Include="JsonValueTests.cpp" />
|
||||||
|
@ -36,5 +36,8 @@
|
|||||||
<ClCompile Include="JsonObjectSerializationTests.cpp">
|
<ClCompile Include="JsonObjectSerializationTests.cpp">
|
||||||
<Filter>Source Files</Filter>
|
<Filter>Source Files</Filter>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
|
<ClCompile Include="EscapedStringTests.cpp">
|
||||||
|
<Filter>Source Files</Filter>
|
||||||
|
</ClCompile>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
</Project>
|
</Project>
|
Reference in New Issue
Block a user