Changed unit testing framework from Google Test to Catch

This commit is contained in:
Benoit Blanchon
2017-04-18 18:22:24 +02:00
parent f2ef338cb8
commit df541a2a22
266 changed files with 15955 additions and 146149 deletions

View File

@ -6,147 +6,140 @@
// If you like this project, please add a star!
#include <ArduinoJson.h>
#include <gtest/gtest.h>
#include <catch.hpp>
class JsonArray_PrintTo_Tests : public testing::Test {
public:
JsonArray_PrintTo_Tests() : array(json.createArray()) {}
static void check(JsonArray &array, std::string expected) {
std::string actual;
size_t actualLen = array.printTo(actual);
size_t measuredLen = array.measureLength();
CHECK(actualLen == expected.size());
CHECK(measuredLen == expected.size());
REQUIRE(expected == actual);
}
protected:
StaticJsonBuffer<JSON_ARRAY_SIZE(2)> json;
JsonArray &array;
TEST_CASE("JsonArray::printTo()") {
StaticJsonBuffer<JSON_ARRAY_SIZE(2)> jb;
JsonArray &array = jb.createArray();
void outputMustBe(const char *expected) {
size_t actualLen = array.printTo(buffer);
size_t measuredLen = array.measureLength();
EXPECT_STREQ(expected, buffer);
EXPECT_EQ(strlen(expected), actualLen);
EXPECT_EQ(strlen(expected), measuredLen);
SECTION("Empty") {
check(array, "[]");
}
private:
char buffer[256];
};
SECTION("Null") {
array.add(static_cast<char *>(0));
TEST_F(JsonArray_PrintTo_Tests, Empty) {
outputMustBe("[]");
}
TEST_F(JsonArray_PrintTo_Tests, Null) {
array.add(static_cast<char *>(0));
outputMustBe("[null]");
}
TEST_F(JsonArray_PrintTo_Tests, OneString) {
array.add("hello");
outputMustBe("[\"hello\"]");
}
TEST_F(JsonArray_PrintTo_Tests, TwoStrings) {
array.add("hello");
array.add("world");
outputMustBe("[\"hello\",\"world\"]");
}
TEST_F(JsonArray_PrintTo_Tests, OneStringOverCapacity) {
array.add("hello");
array.add("world");
array.add("lost");
outputMustBe("[\"hello\",\"world\"]");
}
TEST_F(JsonArray_PrintTo_Tests, OneDoubleDefaultDigits) {
array.add(3.14159265358979323846);
outputMustBe("[3.14]");
}
TEST_F(JsonArray_PrintTo_Tests, OneDoubleFourDigits) {
array.add(3.14159265358979323846, 4);
outputMustBe("[3.1416]");
}
TEST_F(JsonArray_PrintTo_Tests, OneDoubleFourDigits_AlternativeSyntax) {
array.add(double_with_n_digits(3.14159265358979323846, 4));
outputMustBe("[3.1416]");
}
TEST_F(JsonArray_PrintTo_Tests, OneFloatDefaultDigits) {
array.add(3.14159f);
outputMustBe("[3.14]");
}
TEST_F(JsonArray_PrintTo_Tests, OneFloatFourDigits) {
array.add(3.14159f, 4);
outputMustBe("[3.1416]");
}
TEST_F(JsonArray_PrintTo_Tests, OneInteger) {
array.add(1);
outputMustBe("[1]");
}
TEST_F(JsonArray_PrintTo_Tests, TwoIntegers) {
array.add(1);
array.add(2);
outputMustBe("[1,2]");
}
TEST_F(JsonArray_PrintTo_Tests, RawJson) {
array.add(RawJson("{\"key\":\"value\"}"));
outputMustBe("[{\"key\":\"value\"}]");
}
TEST_F(JsonArray_PrintTo_Tests, OneIntegerOverCapacity) {
array.add(1);
array.add(2);
array.add(3);
outputMustBe("[1,2]");
}
TEST_F(JsonArray_PrintTo_Tests, OneTrue) {
array.add(true);
outputMustBe("[true]");
}
TEST_F(JsonArray_PrintTo_Tests, OneFalse) {
array.add(false);
outputMustBe("[false]");
}
TEST_F(JsonArray_PrintTo_Tests, TwoBooleans) {
array.add(false);
array.add(true);
outputMustBe("[false,true]");
}
TEST_F(JsonArray_PrintTo_Tests, OneBooleanOverCapacity) {
array.add(false);
array.add(true);
array.add(false);
outputMustBe("[false,true]");
}
TEST_F(JsonArray_PrintTo_Tests, OneEmptyNestedArray) {
array.createNestedArray();
outputMustBe("[[]]");
}
TEST_F(JsonArray_PrintTo_Tests, OneEmptyNestedHash) {
array.createNestedObject();
outputMustBe("[{}]");
check(array, "[null]");
}
SECTION("OneString") {
array.add("hello");
check(array, "[\"hello\"]");
}
SECTION("TwoStrings") {
array.add("hello");
array.add("world");
check(array, "[\"hello\",\"world\"]");
}
SECTION("OneStringOverCapacity") {
array.add("hello");
array.add("world");
array.add("lost");
check(array, "[\"hello\",\"world\"]");
}
SECTION("OneDoubleDefaultDigits") {
array.add(3.14159265358979323846);
check(array, "[3.14]");
}
SECTION("OneDoubleFourDigits") {
array.add(3.14159265358979323846, 4);
check(array, "[3.1416]");
}
SECTION("OneDoubleFourDigits_AlternativeSyntax") {
array.add(double_with_n_digits(3.14159265358979323846, 4));
check(array, "[3.1416]");
}
SECTION("OneFloatDefaultDigits") {
array.add(3.14159f);
check(array, "[3.14]");
}
SECTION("OneFloatFourDigits") {
array.add(3.14159f, 4);
check(array, "[3.1416]");
}
SECTION("OneInteger") {
array.add(1);
check(array, "[1]");
}
SECTION("TwoIntegers") {
array.add(1);
array.add(2);
check(array, "[1,2]");
}
SECTION("RawJson") {
array.add(RawJson("{\"key\":\"value\"}"));
check(array, "[{\"key\":\"value\"}]");
}
SECTION("OneIntegerOverCapacity") {
array.add(1);
array.add(2);
array.add(3);
check(array, "[1,2]");
}
SECTION("OneTrue") {
array.add(true);
check(array, "[true]");
}
SECTION("OneFalse") {
array.add(false);
check(array, "[false]");
}
SECTION("TwoBooleans") {
array.add(false);
array.add(true);
check(array, "[false,true]");
}
SECTION("OneBooleanOverCapacity") {
array.add(false);
array.add(true);
array.add(false);
check(array, "[false,true]");
}
SECTION("OneEmptyNestedArray") {
array.createNestedArray();
check(array, "[[]]");
}
SECTION("OneEmptyNestedHash") {
array.createNestedObject();
check(array, "[{}]");
}
}