Files
ArduinoJson/test/QuotedString_PrintTo_Tests.cpp

79 lines
1.7 KiB
C++
Raw Normal View History

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