forked from bblanchon/ArduinoJson
Changed unit testing framework from Google Test to Catch
This commit is contained in:
@ -5,78 +5,60 @@
|
||||
// https://bblanchon.github.io/ArduinoJson/
|
||||
// If you like this project, please add a star!
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
#include <catch.hpp>
|
||||
|
||||
#include <ArduinoJson/Serialization/JsonWriter.hpp>
|
||||
#include <ArduinoJson/Serialization/StaticStringBuilder.hpp>
|
||||
|
||||
using namespace ArduinoJson::Internals;
|
||||
|
||||
class JsonWriter_WriteString_Tests : public testing::Test {
|
||||
protected:
|
||||
void whenInputIs(const char *input) {
|
||||
StaticStringBuilder sb(buffer, sizeof(buffer));
|
||||
JsonWriter writer(sb);
|
||||
writer.writeString(input);
|
||||
returnValue = writer.bytesWritten();
|
||||
void check(const char* input, std::string expected) {
|
||||
char output[1024];
|
||||
StaticStringBuilder sb(output, sizeof(output));
|
||||
JsonWriter writer(sb);
|
||||
writer.writeString(input);
|
||||
REQUIRE(expected == output);
|
||||
REQUIRE(writer.bytesWritten() == expected.size());
|
||||
}
|
||||
|
||||
TEST_CASE("JsonWriter::writeString()") {
|
||||
SECTION("Null") {
|
||||
check(0, "null");
|
||||
}
|
||||
|
||||
void outputMustBe(const char *expected) {
|
||||
EXPECT_STREQ(expected, buffer);
|
||||
EXPECT_EQ(strlen(expected), returnValue);
|
||||
SECTION("EmptyString") {
|
||||
check("", "\"\"");
|
||||
}
|
||||
|
||||
private:
|
||||
char buffer[1024];
|
||||
size_t returnValue;
|
||||
};
|
||||
SECTION("QuotationMark") {
|
||||
check("\"", "\"\\\"\"");
|
||||
}
|
||||
|
||||
TEST_F(JsonWriter_WriteString_Tests, Null) {
|
||||
whenInputIs(0);
|
||||
outputMustBe("null");
|
||||
}
|
||||
SECTION("ReverseSolidus") {
|
||||
check("\\", "\"\\\\\"");
|
||||
}
|
||||
|
||||
TEST_F(JsonWriter_WriteString_Tests, EmptyString) {
|
||||
whenInputIs("");
|
||||
outputMustBe("\"\"");
|
||||
}
|
||||
SECTION("Solidus") {
|
||||
check("/", "\"/\""); // but the JSON format allows \/
|
||||
}
|
||||
|
||||
TEST_F(JsonWriter_WriteString_Tests, QuotationMark) {
|
||||
whenInputIs("\"");
|
||||
outputMustBe("\"\\\"\"");
|
||||
}
|
||||
SECTION("Backspace") {
|
||||
check("\b", "\"\\b\"");
|
||||
}
|
||||
|
||||
TEST_F(JsonWriter_WriteString_Tests, ReverseSolidus) {
|
||||
whenInputIs("\\");
|
||||
outputMustBe("\"\\\\\"");
|
||||
}
|
||||
SECTION("Formfeed") {
|
||||
check("\f", "\"\\f\"");
|
||||
}
|
||||
|
||||
TEST_F(JsonWriter_WriteString_Tests, Solidus) {
|
||||
whenInputIs("/");
|
||||
outputMustBe("\"/\""); // but the JSON format allows \/
|
||||
}
|
||||
SECTION("Newline") {
|
||||
check("\n", "\"\\n\"");
|
||||
}
|
||||
|
||||
TEST_F(JsonWriter_WriteString_Tests, Backspace) {
|
||||
whenInputIs("\b");
|
||||
outputMustBe("\"\\b\"");
|
||||
}
|
||||
SECTION("CarriageReturn") {
|
||||
check("\r", "\"\\r\"");
|
||||
}
|
||||
|
||||
TEST_F(JsonWriter_WriteString_Tests, Formfeed) {
|
||||
whenInputIs("\f");
|
||||
outputMustBe("\"\\f\"");
|
||||
}
|
||||
|
||||
TEST_F(JsonWriter_WriteString_Tests, Newline) {
|
||||
whenInputIs("\n");
|
||||
outputMustBe("\"\\n\"");
|
||||
}
|
||||
|
||||
TEST_F(JsonWriter_WriteString_Tests, CarriageReturn) {
|
||||
whenInputIs("\r");
|
||||
outputMustBe("\"\\r\"");
|
||||
}
|
||||
|
||||
TEST_F(JsonWriter_WriteString_Tests, HorizontalTab) {
|
||||
whenInputIs("\t");
|
||||
outputMustBe("\"\\t\"");
|
||||
SECTION("HorizontalTab") {
|
||||
check("\t", "\"\\t\"");
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user