mirror of
https://github.com/bblanchon/ArduinoJson.git
synced 2025-07-15 03:26:39 +02:00
Changed unit testing framework from Google Test to Catch
This commit is contained in:
@ -6,128 +6,104 @@
|
||||
// If you like this project, please add a star!
|
||||
|
||||
#include <ArduinoJson.h>
|
||||
#include <gtest/gtest.h>
|
||||
#include <catch.hpp>
|
||||
#include <limits>
|
||||
|
||||
class JsonVariant_PrintTo_Tests : public testing::Test {
|
||||
protected:
|
||||
JsonVariant variant;
|
||||
void check(JsonVariant variant, const std::string &expected) {
|
||||
char buffer[256] = "";
|
||||
size_t returnValue = variant.printTo(buffer, sizeof(buffer));
|
||||
REQUIRE(expected == buffer);
|
||||
REQUIRE(expected.size() == returnValue);
|
||||
}
|
||||
|
||||
void outputMustBe(const char *expected) {
|
||||
char buffer[256] = "";
|
||||
size_t n = variant.printTo(buffer, sizeof(buffer));
|
||||
ASSERT_STREQ(expected, buffer);
|
||||
ASSERT_EQ(strlen(expected), n);
|
||||
TEST_CASE("JsonVariant::printTo()") {
|
||||
SECTION("Empty") {
|
||||
check(JsonVariant(), "");
|
||||
}
|
||||
};
|
||||
|
||||
TEST_F(JsonVariant_PrintTo_Tests, Empty) {
|
||||
outputMustBe("");
|
||||
}
|
||||
SECTION("Null") {
|
||||
check(static_cast<char *>(0), "null");
|
||||
}
|
||||
|
||||
TEST_F(JsonVariant_PrintTo_Tests, Null) {
|
||||
variant = static_cast<char *>(0);
|
||||
outputMustBe("null");
|
||||
}
|
||||
SECTION("String") {
|
||||
check("hello", "\"hello\"");
|
||||
}
|
||||
|
||||
TEST_F(JsonVariant_PrintTo_Tests, String) {
|
||||
variant = "hello";
|
||||
outputMustBe("\"hello\"");
|
||||
}
|
||||
SECTION("DoubleZero") {
|
||||
check(0.0, "0.00");
|
||||
}
|
||||
|
||||
TEST_F(JsonVariant_PrintTo_Tests, DoubleZero) {
|
||||
variant = 0.0;
|
||||
outputMustBe("0.00");
|
||||
}
|
||||
SECTION("DoubleDefaultDigits") {
|
||||
check(3.14159265358979323846, "3.14");
|
||||
}
|
||||
|
||||
TEST_F(JsonVariant_PrintTo_Tests, DoubleDefaultDigits) {
|
||||
variant = 3.14159265358979323846;
|
||||
outputMustBe("3.14");
|
||||
}
|
||||
SECTION("DoubleFourDigits") {
|
||||
check(JsonVariant(3.14159265358979323846, 4), "3.1416");
|
||||
}
|
||||
|
||||
TEST_F(JsonVariant_PrintTo_Tests, DoubleFourDigits) {
|
||||
variant = JsonVariant(3.14159265358979323846, 4);
|
||||
outputMustBe("3.1416");
|
||||
}
|
||||
SECTION("Infinity") {
|
||||
check(std::numeric_limits<double>::infinity(), "Infinity");
|
||||
}
|
||||
|
||||
TEST_F(JsonVariant_PrintTo_Tests, Infinity) {
|
||||
variant = std::numeric_limits<double>::infinity();
|
||||
outputMustBe("Infinity");
|
||||
}
|
||||
SECTION("MinusInfinity") {
|
||||
check(-std::numeric_limits<double>::infinity(), "-Infinity");
|
||||
}
|
||||
|
||||
TEST_F(JsonVariant_PrintTo_Tests, MinusInfinity) {
|
||||
variant = -std::numeric_limits<double>::infinity();
|
||||
outputMustBe("-Infinity");
|
||||
}
|
||||
SECTION("SignalingNaN") {
|
||||
check(std::numeric_limits<double>::signaling_NaN(), "NaN");
|
||||
}
|
||||
|
||||
TEST_F(JsonVariant_PrintTo_Tests, SignalingNaN) {
|
||||
variant = std::numeric_limits<double>::signaling_NaN();
|
||||
outputMustBe("NaN");
|
||||
}
|
||||
SECTION("QuietNaN") {
|
||||
check(std::numeric_limits<double>::quiet_NaN(), "NaN");
|
||||
}
|
||||
|
||||
TEST_F(JsonVariant_PrintTo_Tests, QuietNaN) {
|
||||
variant = std::numeric_limits<double>::quiet_NaN();
|
||||
outputMustBe("NaN");
|
||||
}
|
||||
SECTION("VeryBigPositiveDouble") {
|
||||
check(JsonVariant(3.14159265358979323846e42, 4), "3.1416e42");
|
||||
}
|
||||
|
||||
TEST_F(JsonVariant_PrintTo_Tests, VeryBigPositiveDouble) {
|
||||
variant = JsonVariant(3.14159265358979323846e42, 4);
|
||||
outputMustBe("3.1416e42");
|
||||
}
|
||||
SECTION("VeryBigNegativeDouble") {
|
||||
check(JsonVariant(-3.14159265358979323846e42, 4), "-3.1416e42");
|
||||
}
|
||||
|
||||
TEST_F(JsonVariant_PrintTo_Tests, VeryBigNegativeDouble) {
|
||||
variant = JsonVariant(-3.14159265358979323846e42, 4);
|
||||
outputMustBe("-3.1416e42");
|
||||
}
|
||||
SECTION("VerySmallPositiveDouble") {
|
||||
check(JsonVariant(3.14159265358979323846e-42, 4), "3.1416e-42");
|
||||
}
|
||||
|
||||
TEST_F(JsonVariant_PrintTo_Tests, VerySmallPositiveDouble) {
|
||||
variant = JsonVariant(3.14159265358979323846e-42, 4);
|
||||
outputMustBe("3.1416e-42");
|
||||
}
|
||||
SECTION("VerySmallNegativeDouble") {
|
||||
check(JsonVariant(-3.14159265358979323846e-42, 4), "-3.1416e-42");
|
||||
}
|
||||
|
||||
TEST_F(JsonVariant_PrintTo_Tests, VerySmallNegativeDouble) {
|
||||
variant = JsonVariant(-3.14159265358979323846e-42, 4);
|
||||
outputMustBe("-3.1416e-42");
|
||||
}
|
||||
SECTION("Integer") {
|
||||
check(42, "42");
|
||||
}
|
||||
|
||||
TEST_F(JsonVariant_PrintTo_Tests, Integer) {
|
||||
variant = 42;
|
||||
outputMustBe("42");
|
||||
}
|
||||
SECTION("NegativeLong") {
|
||||
check(-42, "-42");
|
||||
}
|
||||
|
||||
TEST_F(JsonVariant_PrintTo_Tests, NegativeLong) {
|
||||
variant = -42;
|
||||
outputMustBe("-42");
|
||||
}
|
||||
SECTION("UnsignedLong") {
|
||||
check(4294967295UL, "4294967295");
|
||||
}
|
||||
|
||||
TEST_F(JsonVariant_PrintTo_Tests, UnsignedLong) {
|
||||
variant = 4294967295UL;
|
||||
outputMustBe("4294967295");
|
||||
}
|
||||
SECTION("True") {
|
||||
check(true, "true");
|
||||
}
|
||||
|
||||
TEST_F(JsonVariant_PrintTo_Tests, True) {
|
||||
variant = true;
|
||||
outputMustBe("true");
|
||||
}
|
||||
|
||||
TEST_F(JsonVariant_PrintTo_Tests, OneFalse) {
|
||||
variant = false;
|
||||
outputMustBe("false");
|
||||
}
|
||||
SECTION("OneFalse") {
|
||||
check(false, "false");
|
||||
}
|
||||
|
||||
#if ARDUINOJSON_USE_LONG_LONG || ARDUINOJSON_USE_INT64
|
||||
TEST_F(JsonVariant_PrintTo_Tests, NegativeInt64) {
|
||||
variant = -9223372036854775807 - 1;
|
||||
outputMustBe("-9223372036854775808");
|
||||
}
|
||||
SECTION("NegativeInt64") {
|
||||
check(-9223372036854775807 - 1, "-9223372036854775808");
|
||||
}
|
||||
|
||||
TEST_F(JsonVariant_PrintTo_Tests, PositiveInt64) {
|
||||
variant = 9223372036854775807;
|
||||
outputMustBe("9223372036854775807");
|
||||
}
|
||||
SECTION("PositiveInt64") {
|
||||
check(9223372036854775807, "9223372036854775807");
|
||||
}
|
||||
|
||||
TEST_F(JsonVariant_PrintTo_Tests, UInt64) {
|
||||
variant = 18446744073709551615;
|
||||
outputMustBe("18446744073709551615");
|
||||
}
|
||||
SECTION("UInt64") {
|
||||
check(18446744073709551615, "18446744073709551615");
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
Reference in New Issue
Block a user