2014-10-16 21:54:42 +02:00
|
|
|
#include <gtest/gtest.h>
|
2014-10-18 22:12:43 +02:00
|
|
|
#include <ArduinoJson/Internals/QuotedString.h>
|
2014-10-16 21:54:42 +02:00
|
|
|
|
2014-10-18 22:12:43 +02:00
|
|
|
using namespace ArduinoJson::Internals;
|
|
|
|
|
|
|
|
class QuotedString_ExtractFrom_Tests : public testing::Test
|
2014-10-16 21:54:42 +02:00
|
|
|
{
|
|
|
|
protected:
|
|
|
|
void whenInputIs(const char* json)
|
|
|
|
{
|
|
|
|
strcpy(_jsonString, json);
|
2014-10-18 22:12:43 +02:00
|
|
|
_result = QuotedString::extractFrom(_jsonString, &_endp);
|
2014-10-16 21:54:42 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void outputMustBe(const char* expected)
|
|
|
|
{
|
|
|
|
EXPECT_STREQ(expected, _result);
|
2014-10-18 22:12:43 +02:00
|
|
|
EXPECT_EQ(_endp, _result + )
|
2014-10-16 21:54:42 +02:00
|
|
|
}
|
|
|
|
|
2014-10-18 21:54:08 +02:00
|
|
|
private:
|
2014-10-16 21:54:42 +02:00
|
|
|
char _jsonString[256];
|
2014-10-18 22:12:43 +02:00
|
|
|
char* _result;
|
|
|
|
char* _endp;
|
2014-10-16 21:54:42 +02:00
|
|
|
};
|
|
|
|
|
2014-10-17 19:57:00 +02:00
|
|
|
|
2014-10-18 22:12:43 +02:00
|
|
|
TEST_F(QuotedString_ExtractFrom_Tests, EmptyDoubleQuotedString)
|
2014-10-17 19:57:00 +02:00
|
|
|
{
|
|
|
|
whenInputIs("\"\"");
|
|
|
|
outputMustBe("");
|
|
|
|
}
|
|
|
|
|
2014-10-18 22:12:43 +02:00
|
|
|
TEST_F(QuotedString_ExtractFrom_Tests, EmptySingleQuotedString)
|
2014-10-18 21:54:08 +02:00
|
|
|
{
|
|
|
|
whenInputIs("''");
|
|
|
|
outputMustBe("");
|
|
|
|
}
|
|
|
|
|
2014-10-18 22:12:43 +02:00
|
|
|
TEST_F(QuotedString_ExtractFrom_Tests, SimpleDoubleQuotedString)
|
2014-10-16 21:54:42 +02:00
|
|
|
{
|
|
|
|
whenInputIs("\"hello world\"");
|
|
|
|
outputMustBe("hello world");
|
|
|
|
}
|
|
|
|
|
2014-10-18 22:12:43 +02:00
|
|
|
TEST_F(QuotedString_ExtractFrom_Tests, CurlyBraces)
|
2014-10-16 21:54:42 +02:00
|
|
|
{
|
|
|
|
whenInputIs("\"{hello:world}\"");
|
|
|
|
outputMustBe("{hello:world}");
|
|
|
|
}
|
|
|
|
|
2014-10-18 22:12:43 +02:00
|
|
|
TEST_F(QuotedString_ExtractFrom_Tests, SquareBraquets)
|
2014-10-16 21:54:42 +02:00
|
|
|
{
|
|
|
|
whenInputIs("\"[hello,world]\"");
|
|
|
|
outputMustBe("[hello,world]");
|
|
|
|
}
|
|
|
|
|
2014-10-18 22:12:43 +02:00
|
|
|
TEST_F(QuotedString_ExtractFrom_Tests, EscapedDoubleQuote)
|
2014-10-16 21:54:42 +02:00
|
|
|
{
|
|
|
|
whenInputIs("\"hello \\\"world\\\"\"");
|
|
|
|
outputMustBe("hello \"world\"");
|
2014-10-17 19:57:00 +02:00
|
|
|
}
|
|
|
|
|
2014-10-18 22:12:43 +02:00
|
|
|
TEST_F(QuotedString_ExtractFrom_Tests, EscapedSingleQuote)
|
2014-10-17 19:57:00 +02:00
|
|
|
{
|
|
|
|
whenInputIs("\"hello \\\'world\\\'\"");
|
|
|
|
outputMustBe("hello 'world'");
|
2014-10-17 22:32:55 +02:00
|
|
|
}
|
|
|
|
|
2014-10-18 22:12:43 +02:00
|
|
|
TEST_F(QuotedString_ExtractFrom_Tests, EscapedSolidus)
|
2014-10-17 22:32:55 +02:00
|
|
|
{
|
|
|
|
whenInputIs("\"hello \\/world\\/\"");
|
|
|
|
outputMustBe("hello /world/");
|
|
|
|
}
|
|
|
|
|
2014-10-18 22:12:43 +02:00
|
|
|
TEST_F(QuotedString_ExtractFrom_Tests, EscapedReverseSolidus)
|
2014-10-17 22:32:55 +02:00
|
|
|
{
|
|
|
|
whenInputIs("\"hello \\\\world\\\\\"");
|
|
|
|
outputMustBe("hello \\world\\");
|
|
|
|
}
|
|
|
|
|
2014-10-18 22:12:43 +02:00
|
|
|
TEST_F(QuotedString_ExtractFrom_Tests, EscapedBackspace)
|
2014-10-17 22:32:55 +02:00
|
|
|
{
|
2014-10-18 21:54:08 +02:00
|
|
|
whenInputIs("\"hello \\bworld\\b\"");
|
2014-10-17 22:32:55 +02:00
|
|
|
outputMustBe("hello \bworld\b");
|
|
|
|
}
|
|
|
|
|
2014-10-18 22:12:43 +02:00
|
|
|
TEST_F(QuotedString_ExtractFrom_Tests, EscapedFormfeed)
|
2014-10-17 22:32:55 +02:00
|
|
|
{
|
2014-10-18 21:54:08 +02:00
|
|
|
whenInputIs("\"hello \\fworld\\f\"");
|
2014-10-17 22:32:55 +02:00
|
|
|
outputMustBe("hello \fworld\f");
|
|
|
|
}
|
|
|
|
|
2014-10-18 22:12:43 +02:00
|
|
|
TEST_F(QuotedString_ExtractFrom_Tests, EscapedNewline)
|
2014-10-17 22:32:55 +02:00
|
|
|
{
|
2014-10-18 21:54:08 +02:00
|
|
|
whenInputIs("\"hello \\nworld\\n\"");
|
2014-10-17 22:32:55 +02:00
|
|
|
outputMustBe("hello \nworld\n");
|
|
|
|
}
|
|
|
|
|
2014-10-18 22:12:43 +02:00
|
|
|
TEST_F(QuotedString_ExtractFrom_Tests, EscapedCarriageReturn)
|
2014-10-17 22:32:55 +02:00
|
|
|
{
|
2014-10-18 21:54:08 +02:00
|
|
|
whenInputIs("\"hello \\rworld\\r\"");
|
2014-10-17 22:32:55 +02:00
|
|
|
outputMustBe("hello \rworld\r");
|
|
|
|
}
|
|
|
|
|
2014-10-18 22:12:43 +02:00
|
|
|
TEST_F(QuotedString_ExtractFrom_Tests, EscapedTab)
|
2014-10-17 22:32:55 +02:00
|
|
|
{
|
2014-10-18 21:54:08 +02:00
|
|
|
whenInputIs("\"hello \\tworld\\t\"");
|
2014-10-17 22:32:55 +02:00
|
|
|
outputMustBe("hello \tworld\t");
|
|
|
|
}
|
|
|
|
|
2014-10-18 22:12:43 +02:00
|
|
|
TEST_F(QuotedString_ExtractFrom_Tests, AllEscapedCharsTogether)
|
2014-10-17 22:32:55 +02:00
|
|
|
{
|
|
|
|
whenInputIs("\"1\\\"2\\\\3\\/4\\b5\\f6\\n7\\r8\\t9\"");
|
|
|
|
outputMustBe("1\"2\\3/4\b5\f6\n7\r8\t9");
|
2014-10-16 21:54:42 +02:00
|
|
|
}
|