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

@ -12,5 +12,5 @@ add_executable(PolyfillsTests
parseInteger.cpp
)
target_link_libraries(PolyfillsTests gtest)
target_link_libraries(PolyfillsTests catch)
add_test(Polyfills PolyfillsTests)

View File

@ -5,81 +5,75 @@
// https://bblanchon.github.io/ArduinoJson/
// If you like this project, please add a star!
#include <gtest/gtest.h>
#include <ArduinoJson/Polyfills/isFloat.hpp>
#include <catch.hpp>
using namespace ArduinoJson::Polyfills;
struct Polyfills_IsFloat_Tests : testing::Test {
void check(bool expected, const char* input) {
bool actual = isFloat(input);
EXPECT_EQ(expected, actual) << input;
TEST_CASE("isFloat()") {
SECTION("Input is NULL") {
REQUIRE(isFloat(NULL) == false);
}
};
#define TEST_(X) TEST_F(Polyfills_IsFloat_Tests, X)
TEST_(Null) {
check(false, NULL);
}
SECTION("NoExponent") {
REQUIRE(isFloat("3.14"));
REQUIRE(isFloat("-3.14"));
REQUIRE(isFloat("+3.14"));
}
TEST_(NoExponent) {
check(true, "3.14");
check(true, "-3.14");
check(true, "+3.14");
}
SECTION("IntegralPartMissing") {
REQUIRE(isFloat(".14"));
REQUIRE(isFloat("-.14"));
REQUIRE(isFloat("+.14"));
}
TEST_(IntegralPartMissing) {
check(true, ".14");
check(true, "-.14");
check(true, "+.14");
}
SECTION("FractionalPartMissing") {
REQUIRE(isFloat("3."));
REQUIRE(isFloat("-3.e14"));
REQUIRE(isFloat("+3.e-14"));
}
TEST_(FractionalPartMissing) {
check(true, "3.");
check(true, "-3.e14");
check(true, "+3.e-14");
}
SECTION("NoDot") {
REQUIRE(isFloat("3e14"));
REQUIRE(isFloat("3e-14"));
REQUIRE(isFloat("3e+14"));
}
TEST_(NoDot) {
check(true, "3e14");
check(true, "3e-14");
check(true, "3e+14");
}
SECTION("Integer") {
REQUIRE_FALSE(isFloat("14"));
REQUIRE_FALSE(isFloat("-14"));
REQUIRE_FALSE(isFloat("+14"));
}
TEST_(Integer) {
check(false, "14");
check(false, "-14");
check(false, "+14");
}
SECTION("ExponentMissing") {
REQUIRE_FALSE(isFloat("3.14e"));
REQUIRE_FALSE(isFloat("3.14e-"));
REQUIRE_FALSE(isFloat("3.14e+"));
}
TEST_(ExponentMissing) {
check(false, "3.14e");
check(false, "3.14e-");
check(false, "3.14e+");
}
SECTION("JustASign") {
REQUIRE_FALSE(isFloat("-"));
REQUIRE_FALSE(isFloat("+"));
}
TEST_(JustASign) {
check(false, "-");
check(false, "+");
}
SECTION("Empty") {
REQUIRE_FALSE(isFloat(""));
}
TEST_(Empty) {
check(false, "");
}
SECTION("NaN") {
REQUIRE(isFloat("NaN"));
REQUIRE_FALSE(isFloat("n"));
REQUIRE_FALSE(isFloat("N"));
REQUIRE_FALSE(isFloat("nan"));
REQUIRE_FALSE(isFloat("-NaN"));
REQUIRE_FALSE(isFloat("+NaN"));
}
TEST_(NaN) {
check(true, "NaN");
check(false, "n");
check(false, "N");
check(false, "nan");
check(false, "-NaN");
check(false, "+NaN");
}
TEST_(Infinity) {
check(true, "Infinity");
check(true, "+Infinity");
check(true, "-Infinity");
check(false, "infinity");
check(false, "Inf");
SECTION("Infinity") {
REQUIRE(isFloat("Infinity"));
REQUIRE(isFloat("+Infinity"));
REQUIRE(isFloat("-Infinity"));
REQUIRE_FALSE(isFloat("infinity"));
REQUIRE_FALSE(isFloat("Inf"));
}
}

View File

@ -5,41 +5,35 @@
// https://bblanchon.github.io/ArduinoJson/
// If you like this project, please add a star!
#include <gtest/gtest.h>
#include <ArduinoJson/Polyfills/isInteger.hpp>
#include <catch.hpp>
using namespace ArduinoJson::Polyfills;
struct Polyfills_IsInteger_Tests : testing::Test {
void check(bool expected, const char* input) {
bool actual = isInteger(input);
EXPECT_EQ(expected, actual) << input;
TEST_CASE("isInteger()") {
SECTION("Null") {
REQUIRE_FALSE(isInteger(NULL));
}
};
#define TEST_(X) TEST_F(Polyfills_IsInteger_Tests, X)
TEST_(Null) {
check(false, NULL);
}
SECTION("FloatNotInteger") {
REQUIRE_FALSE(isInteger("3.14"));
REQUIRE_FALSE(isInteger("-3.14"));
REQUIRE_FALSE(isInteger("+3.14"));
}
TEST_(FloatNotInteger) {
check(false, "3.14");
check(false, "-3.14");
check(false, "+3.14");
}
SECTION("Spaces") {
REQUIRE_FALSE(isInteger("42 "));
REQUIRE_FALSE(isInteger(" 42"));
}
TEST_(Spaces) {
check(false, "42 ");
check(false, " 42");
}
SECTION("Valid") {
REQUIRE(isInteger("42"));
REQUIRE(isInteger("-42"));
REQUIRE(isInteger("+42"));
}
TEST_(Valid) {
check(true, "42");
check(true, "-42");
check(true, "+42");
}
TEST_(ExtraSign) {
check(false, "--42");
check(false, "++42");
SECTION("ExtraSign") {
REQUIRE_FALSE(isInteger("--42"));
REQUIRE_FALSE(isInteger("++42"));
}
}

View File

@ -5,179 +5,166 @@
// https://bblanchon.github.io/ArduinoJson/
// If you like this project, please add a star!
#include <gtest/gtest.h>
#include <ArduinoJson/Polyfills/parseFloat.hpp>
#include <catch.hpp>
using namespace ArduinoJson::Polyfills;
struct Polyfills_ParseFloat_Float_Tests : testing::Test {
void check(const char* input, float expected) {
float actual = parseFloat<float>(input);
EXPECT_FLOAT_EQ(expected, actual) << input;
template <typename T>
void check(const char* input, T expected) {
CAPTURE(input);
REQUIRE(parseFloat<T>(input) == Approx(expected));
}
template <typename T>
void checkNaN(const char* input) {
CAPTURE(input);
T result = parseFloat<T>(input);
REQUIRE(result != result);
}
template <typename T>
void checkInf(const char* input, bool negative) {
CAPTURE(input);
T x = parseFloat<T>(input);
if (negative)
REQUIRE(x < 0);
else
REQUIRE(x > 0);
REQUIRE(x == x); // not a NaN
REQUIRE(x * 2 == x); // a property of infinity
}
TEST_CASE("parseFloat<float>()") {
SECTION("Null") {
check<float>(NULL, 0);
}
void checkNaN(const char* input) {
float result = parseFloat<float>(input);
EXPECT_TRUE(result != result) << input;
SECTION("Float_Short_NoExponent") {
check<float>("3.14", 3.14f);
check<float>("-3.14", -3.14f);
check<float>("+3.14", +3.14f);
}
void checkInf(const char* input, bool negative) {
float x = parseFloat<float>(input);
if (negative)
EXPECT_TRUE(x < 0) << input;
else
EXPECT_TRUE(x > 0) << input;
EXPECT_TRUE(x == x && x * 2 == x) << input;
}
};
#define TEST_FLOAT(X) TEST_F(Polyfills_ParseFloat_Float_Tests, X)
struct Polyfills_ParseFloat_Double_Tests : testing::Test {
void check(const char* input, double expected) {
double actual = parseFloat<double>(input);
EXPECT_DOUBLE_EQ(expected, actual) << input;
SECTION("Short_NoDot") {
check<float>("1E+38", 1E+38f);
check<float>("-1E+38", -1E+38f);
check<float>("+1E-38", +1E-38f);
check<float>("+1e+38", +1e+38f);
check<float>("-1e-38", -1e-38f);
}
void checkNaN(const char* input) {
double result = parseFloat<double>(input);
EXPECT_TRUE(result != result) << input;
SECTION("Max") {
check<float>("340.2823e+36", 3.402823e+38f);
check<float>("34.02823e+37", 3.402823e+38f);
check<float>("3.402823e+38", 3.402823e+38f);
check<float>("0.3402823e+39", 3.402823e+38f);
check<float>("0.03402823e+40", 3.402823e+38f);
check<float>("0.003402823e+41", 3.402823e+38f);
}
void checkInf(const char* input, bool negative) {
double x = parseFloat<double>(input);
if (negative)
EXPECT_TRUE(x < 0) << input;
else
EXPECT_TRUE(x > 0) << input;
EXPECT_TRUE(x == x && x * 2 == x) << input;
}
};
#define TEST_DOUBLE(X) TEST_F(Polyfills_ParseFloat_Double_Tests, X)
TEST_DOUBLE(Null) {
check(NULL, 0);
}
TEST_FLOAT(Null) {
check(NULL, 0);
}
TEST_DOUBLE(Short_NoExponent) {
check("3.14", 3.14);
check("-3.14", -3.14);
check("+3.14", +3.14);
}
TEST_FLOAT(Float_Short_NoExponent) {
check("3.14", 3.14f);
check("-3.14", -3.14f);
check("+3.14", +3.14f);
}
TEST_DOUBLE(Short_NoDot) {
check("1E+308", 1E+308);
check("-1E+308", -1E+308);
check("+1E-308", +1E-308);
check("+1e+308", +1e+308);
check("-1e-308", -1e-308);
}
TEST_FLOAT(Short_NoDot) {
check("1E+38", 1E+38f);
check("-1E+38", -1E+38f);
check("+1E-38", +1E-38f);
check("+1e+38", +1e+38f);
check("-1e-38", -1e-38f);
}
TEST_FLOAT(Max) {
check("340.2823e+36", 3.402823e+38f);
check("34.02823e+37", 3.402823e+38f);
check("3.402823e+38", 3.402823e+38f);
check("0.3402823e+39", 3.402823e+38f);
check("00.3402823e+40", 3.402823e+38f);
check("000.3402823e+41", 3.402823e+38f);
}
TEST_DOUBLE(Max) {
check(".017976931348623147e+310", 1.7976931348623147e+308);
check(".17976931348623147e+309", 1.7976931348623147e+308);
check("1.7976931348623147e+308", 1.7976931348623147e+308);
check("17.976931348623147e+307", 1.7976931348623147e+308);
check("179.76931348623147e+306", 1.7976931348623147e+308);
}
TEST_DOUBLE(Min) {
check(".022250738585072014e-306", 2.2250738585072014e-308);
check(".22250738585072014e-307", 2.2250738585072014e-308);
check("2.2250738585072014e-308", 2.2250738585072014e-308);
check("22.250738585072014e-309", 2.2250738585072014e-308);
check("222.50738585072014e-310", 2.2250738585072014e-308);
}
TEST_DOUBLE(VeryLong) {
check("0.00000000000000000000000000000001", 1e-32);
check("100000000000000000000000000000000.0", 1e+32);
check("100000000000000000000000000000000.00000000000000000000000000000",
1e+32);
}
TEST_FLOAT(VeryLong) {
check("0.00000000000000000000000000000001", 1e-32f);
check("100000000000000000000000000000000.0", 1e+32f);
check("100000000000000000000000000000000.00000000000000000000000000000",
SECTION("VeryLong") {
check<float>("0.00000000000000000000000000000001", 1e-32f);
check<float>("100000000000000000000000000000000.0", 1e+32f);
check<float>(
"100000000000000000000000000000000.00000000000000000000000000000",
1e+32f);
}
SECTION("MantissaTooLongToFit") {
check<float>("0.340282346638528861111111111111", 0.34028234663852886f);
check<float>("34028234663852886.11111111111111", 34028234663852886.0f);
check<float>("34028234.66385288611111111111111", 34028234.663852886f);
check<float>("-0.340282346638528861111111111111", -0.34028234663852886f);
check<float>("-34028234663852886.11111111111111", -34028234663852886.0f);
check<float>("-34028234.66385288611111111111111", -34028234.663852886f);
}
SECTION("ExponentTooBig") {
checkInf<float>("1e39", false);
checkInf<float>("-1e39", true);
checkInf<float>("1e255", false);
check<float>("1e-255", 0.0f);
}
SECTION("NaN") {
checkNaN<float>("NaN");
checkNaN<float>("nan");
}
SECTION("Infinity") {
checkInf<float>("Infinity", false);
checkInf<float>("+Infinity", false);
checkInf<float>("-Infinity", true);
checkInf<float>("inf", false);
checkInf<float>("+inf", false);
checkInf<float>("-inf", true);
}
}
TEST_DOUBLE(MantissaTooLongToFit) {
check("0.179769313486231571111111111111", 0.17976931348623157);
check("17976931348623157.11111111111111", 17976931348623157.0);
check("1797693.134862315711111111111111", 1797693.1348623157);
TEST_CASE("parseFloat<double>()") {
SECTION("Null") {
check<double>(NULL, 0);
}
check("-0.179769313486231571111111111111", -0.17976931348623157);
check("-17976931348623157.11111111111111", -17976931348623157.0);
check("-1797693.134862315711111111111111", -1797693.1348623157);
}
TEST_FLOAT(MantissaTooLongToFit) {
check("0.340282346638528861111111111111", 0.34028234663852886f);
check("34028234663852886.11111111111111", 34028234663852886.0f);
check("34028234.66385288611111111111111", 34028234.663852886f);
check("-0.340282346638528861111111111111", -0.34028234663852886f);
check("-34028234663852886.11111111111111", -34028234663852886.0f);
check("-34028234.66385288611111111111111", -34028234.663852886f);
}
TEST_DOUBLE(ExponentTooBig) {
checkInf("1e309", false);
checkInf("-1e309", true);
checkInf("1e65535", false);
check("1e-65535", 0.0);
}
TEST_FLOAT(ExponentTooBig) {
checkInf("1e39", false);
checkInf("-1e39", true);
checkInf("1e255", false);
check("1e-255", 0.0f);
}
TEST_DOUBLE(NaN) {
checkNaN("NaN");
checkNaN("nan");
}
TEST_FLOAT(NaN) {
checkNaN("NaN");
checkNaN("nan");
}
TEST_FLOAT(Infinity) {
checkInf("Infinity", false);
checkInf("+Infinity", false);
checkInf("-Infinity", true);
checkInf("inf", false);
checkInf("+inf", false);
checkInf("-inf", true);
SECTION("Short_NoExponent") {
check<double>("3.14", 3.14);
check<double>("-3.14", -3.14);
check<double>("+3.14", +3.14);
}
SECTION("Short_NoDot") {
check<double>("1E+308", 1E+308);
check<double>("-1E+308", -1E+308);
check<double>("+1E-308", +1E-308);
check<double>("+1e+308", +1e+308);
check<double>("-1e-308", -1e-308);
}
SECTION("Max") {
check<double>(".017976931348623147e+310", 1.7976931348623147e+308);
check<double>(".17976931348623147e+309", 1.7976931348623147e+308);
check<double>("1.7976931348623147e+308", 1.7976931348623147e+308);
check<double>("17.976931348623147e+307", 1.7976931348623147e+308);
check<double>("179.76931348623147e+306", 1.7976931348623147e+308);
}
SECTION("Min") {
check<double>(".022250738585072014e-306", 2.2250738585072014e-308);
check<double>(".22250738585072014e-307", 2.2250738585072014e-308);
check<double>("2.2250738585072014e-308", 2.2250738585072014e-308);
check<double>("22.250738585072014e-309", 2.2250738585072014e-308);
check<double>("222.50738585072014e-310", 2.2250738585072014e-308);
}
SECTION("VeryLong") {
check<double>("0.00000000000000000000000000000001", 1e-32);
check<double>("100000000000000000000000000000000.0", 1e+32);
check<double>(
"100000000000000000000000000000000.00000000000000000000000000000",
1e+32);
}
SECTION("MantissaTooLongToFit") {
check<double>("0.179769313486231571111111111111", 0.17976931348623157);
check<double>("17976931348623157.11111111111111", 17976931348623157.0);
check<double>("1797693.134862315711111111111111", 1797693.1348623157);
check<double>("-0.179769313486231571111111111111", -0.17976931348623157);
check<double>("-17976931348623157.11111111111111", -17976931348623157.0);
check<double>("-1797693.134862315711111111111111", -1797693.1348623157);
}
SECTION("ExponentTooBig") {
checkInf<double>("1e309", false);
checkInf<double>("-1e309", true);
checkInf<double>("1e65535", false);
check<double>("1e-65535", 0.0);
}
SECTION("NaN") {
checkNaN<double>("NaN");
checkNaN<double>("nan");
}
}

View File

@ -5,23 +5,20 @@
// https://bblanchon.github.io/ArduinoJson/
// If you like this project, please add a star!
#include <gtest/gtest.h>
#include <stdint.h>
#include <ArduinoJson/Polyfills/parseInteger.hpp>
#include <catch.hpp>
using namespace ArduinoJson::Polyfills;
struct Polyfills_ParseInteger_Tests : testing::Test {
template <typename T>
void check(const char* input, T expected) {
T actual = parseInteger<T>(input);
EXPECT_EQ(expected, actual) << input;
}
};
template <typename T>
void check(const char* input, T expected) {
CAPTURE(input);
T actual = parseInteger<T>(input);
REQUIRE(expected == actual);
}
#define TEST_(X) TEST_F(Polyfills_ParseInteger_Tests, X)
TEST_(int8_t) {
TEST_CASE("parseInteger<int8_t>()") {
check<int8_t>("-128", -128);
check<int8_t>("127", 127);
check<int8_t>("+127", 127);
@ -33,7 +30,7 @@ TEST_(int8_t) {
check<int8_t>(NULL, 0);
}
TEST_(int16_t) {
TEST_CASE("parseInteger<int16_t>()") {
check<int16_t>("-32768", -32768);
check<int16_t>("32767", 32767);
check<int16_t>("+32767", 32767);
@ -45,7 +42,7 @@ TEST_(int16_t) {
check<int16_t>(NULL, 0);
}
TEST_(int32_t) {
TEST_CASE("parseInteger<int32_t>()") {
check<int32_t>("-2147483648", (-2147483647 - 1));
check<int32_t>("2147483647", 2147483647);
check<int32_t>("+2147483647", 2147483647);
@ -56,7 +53,7 @@ TEST_(int32_t) {
check<int32_t>("2147483648", (-2147483647 - 1));
}
TEST_(uint8_t) {
TEST_CASE("parseInteger<uint8_t>()") {
check<uint8_t>("0", 0);
check<uint8_t>("255", 255);
check<uint8_t>("+255", 255);
@ -67,7 +64,7 @@ TEST_(uint8_t) {
check<uint8_t>("256", 0);
}
TEST_(uint16_t) {
TEST_CASE("parseInteger<uint16_t>()") {
check<uint16_t>("0", 0);
check<uint16_t>("65535", 65535);
check<uint16_t>("+65535", 65535);