Files
ArduinoJson/test/QuotedString_PrintTo_Tests.cpp

86 lines
1.6 KiB
C++
Raw Normal View History

2014-10-16 16:23:24 +02:00
#include <gtest/gtest.h>
#include <ArduinoJson/Internals/QuotedString.h>
2014-10-16 16:23:24 +02:00
#include <ArduinoJson/Internals/StringBuilder.h>
using namespace ArduinoJson::Internals;
class QuotedString_PrintTo_Tests : public testing::Test
2014-10-16 16:23:24 +02:00
{
protected:
void whenInputIs(const char* input)
{
StringBuilder sb(buffer, sizeof(buffer));
returnValue = QuotedString::printTo(input, &sb);
2014-10-16 16:23:24 +02:00
}
void outputMustBe(const char* expected)
{
EXPECT_STREQ(expected, buffer);
EXPECT_EQ(strlen(expected), returnValue);
}
private:
char buffer[1024];
size_t returnValue;
};
TEST_F(QuotedString_PrintTo_Tests, Null)
2014-10-16 16:23:24 +02:00
{
whenInputIs(0);
outputMustBe("null");
}
TEST_F(QuotedString_PrintTo_Tests, EmptyString)
2014-10-16 16:23:24 +02:00
{
whenInputIs("");
outputMustBe("\"\"");
}
TEST_F(QuotedString_PrintTo_Tests, QuotationMark)
2014-10-16 16:23:24 +02:00
{
whenInputIs("\"");
outputMustBe("\"\\\"\"");
}
TEST_F(QuotedString_PrintTo_Tests, ReverseSolidus)
2014-10-16 16:23:24 +02:00
{
whenInputIs("\\");
outputMustBe("\"\\\\\"");
}
TEST_F(QuotedString_PrintTo_Tests, Solidus)
2014-10-16 16:23:24 +02:00
{
whenInputIs("/");
outputMustBe("\"/\""); // but the JSON format allows \/
}
TEST_F(QuotedString_PrintTo_Tests, Backspace)
2014-10-16 16:23:24 +02:00
{
whenInputIs("\b");
outputMustBe("\"\\b\"");
}
TEST_F(QuotedString_PrintTo_Tests, Formfeed)
2014-10-16 16:23:24 +02:00
{
whenInputIs("\f");
outputMustBe("\"\\f\"");
}
TEST_F(QuotedString_PrintTo_Tests, Newline)
2014-10-16 16:23:24 +02:00
{
whenInputIs("\n");
outputMustBe("\"\\n\"");
}
TEST_F(QuotedString_PrintTo_Tests, CarriageReturn)
2014-10-16 16:23:24 +02:00
{
whenInputIs("\r");
outputMustBe("\"\\r\"");
}
TEST_F(QuotedString_PrintTo_Tests, HorizontalTab)
2014-10-16 16:23:24 +02:00
{
whenInputIs("\t");
outputMustBe("\"\\t\"");
2014-09-30 18:03:17 +02:00
}