mirror of
				https://github.com/eledio-devices/thirdparty-ArduinoJson.git
				synced 2025-10-31 16:14:11 +01:00 
			
		
		
		
	Added support for CMake's unity builds
This commit is contained in:
		| @@ -9,4 +9,5 @@ add_executable(NumbersTests | ||||
| ) | ||||
|  | ||||
| target_link_libraries(NumbersTests catch) | ||||
|  | ||||
| add_test(Numbers NumbersTests) | ||||
|   | ||||
| @@ -12,7 +12,7 @@ | ||||
| using namespace ARDUINOJSON_NAMESPACE; | ||||
|  | ||||
| template <typename T> | ||||
| void check(const char* input, T expected) { | ||||
| void checkFloat(const char* input, T expected) { | ||||
|   CAPTURE(input); | ||||
|   REQUIRE(parseFloat<T>(input) == Approx(expected)); | ||||
| } | ||||
| @@ -38,51 +38,54 @@ void checkInf(const char* input, bool negative) { | ||||
|  | ||||
| TEST_CASE("parseFloat<float>()") { | ||||
|   SECTION("Float_Short_NoExponent") { | ||||
|     check<float>("3.14", 3.14f); | ||||
|     check<float>("-3.14", -3.14f); | ||||
|     check<float>("+3.14", +3.14f); | ||||
|     checkFloat<float>("3.14", 3.14f); | ||||
|     checkFloat<float>("-3.14", -3.14f); | ||||
|     checkFloat<float>("+3.14", +3.14f); | ||||
|   } | ||||
|  | ||||
|   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); | ||||
|     checkFloat<float>("1E+38", 1E+38f); | ||||
|     checkFloat<float>("-1E+38", -1E+38f); | ||||
|     checkFloat<float>("+1E-38", +1E-38f); | ||||
|     checkFloat<float>("+1e+38", +1e+38f); | ||||
|     checkFloat<float>("-1e-38", -1e-38f); | ||||
|   } | ||||
|  | ||||
|   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); | ||||
|     checkFloat<float>("340.2823e+36", 3.402823e+38f); | ||||
|     checkFloat<float>("34.02823e+37", 3.402823e+38f); | ||||
|     checkFloat<float>("3.402823e+38", 3.402823e+38f); | ||||
|     checkFloat<float>("0.3402823e+39", 3.402823e+38f); | ||||
|     checkFloat<float>("0.03402823e+40", 3.402823e+38f); | ||||
|     checkFloat<float>("0.003402823e+41", 3.402823e+38f); | ||||
|   } | ||||
|  | ||||
|   SECTION("VeryLong") { | ||||
|     check<float>("0.00000000000000000000000000000001", 1e-32f); | ||||
|     check<float>("100000000000000000000000000000000.0", 1e+32f); | ||||
|     check<float>( | ||||
|     checkFloat<float>("0.00000000000000000000000000000001", 1e-32f); | ||||
|     checkFloat<float>("100000000000000000000000000000000.0", 1e+32f); | ||||
|     checkFloat<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); | ||||
|     checkFloat<float>("0.340282346638528861111111111111", 0.34028234663852886f); | ||||
|     checkFloat<float>("34028234663852886.11111111111111", 34028234663852886.0f); | ||||
|     checkFloat<float>("34028234.66385288611111111111111", 34028234.663852886f); | ||||
|  | ||||
|     check<float>("-0.340282346638528861111111111111", -0.34028234663852886f); | ||||
|     check<float>("-34028234663852886.11111111111111", -34028234663852886.0f); | ||||
|     check<float>("-34028234.66385288611111111111111", -34028234.663852886f); | ||||
|     checkFloat<float>("-0.340282346638528861111111111111", | ||||
|                       -0.34028234663852886f); | ||||
|     checkFloat<float>("-34028234663852886.11111111111111", | ||||
|                       -34028234663852886.0f); | ||||
|     checkFloat<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); | ||||
|     checkFloat<float>("1e-255", 0.0f); | ||||
|   } | ||||
|  | ||||
|   SECTION("NaN") { | ||||
| @@ -105,58 +108,61 @@ TEST_CASE("parseFloat<float>()") { | ||||
|  | ||||
| TEST_CASE("parseFloat<double>()") { | ||||
|   SECTION("Short_NoExponent") { | ||||
|     check<double>("3.14", 3.14); | ||||
|     check<double>("-3.14", -3.14); | ||||
|     check<double>("+3.14", +3.14); | ||||
|     checkFloat<double>("3.14", 3.14); | ||||
|     checkFloat<double>("-3.14", -3.14); | ||||
|     checkFloat<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); | ||||
|     checkFloat<double>("1E+308", 1E+308); | ||||
|     checkFloat<double>("-1E+308", -1E+308); | ||||
|     checkFloat<double>("+1E-308", +1E-308); | ||||
|     checkFloat<double>("+1e+308", +1e+308); | ||||
|     checkFloat<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); | ||||
|     checkFloat<double>(".017976931348623147e+310", 1.7976931348623147e+308); | ||||
|     checkFloat<double>(".17976931348623147e+309", 1.7976931348623147e+308); | ||||
|     checkFloat<double>("1.7976931348623147e+308", 1.7976931348623147e+308); | ||||
|     checkFloat<double>("17.976931348623147e+307", 1.7976931348623147e+308); | ||||
|     checkFloat<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); | ||||
|     checkFloat<double>(".022250738585072014e-306", 2.2250738585072014e-308); | ||||
|     checkFloat<double>(".22250738585072014e-307", 2.2250738585072014e-308); | ||||
|     checkFloat<double>("2.2250738585072014e-308", 2.2250738585072014e-308); | ||||
|     checkFloat<double>("22.250738585072014e-309", 2.2250738585072014e-308); | ||||
|     checkFloat<double>("222.50738585072014e-310", 2.2250738585072014e-308); | ||||
|   } | ||||
|  | ||||
|   SECTION("VeryLong") { | ||||
|     check<double>("0.00000000000000000000000000000001", 1e-32); | ||||
|     check<double>("100000000000000000000000000000000.0", 1e+32); | ||||
|     check<double>( | ||||
|     checkFloat<double>("0.00000000000000000000000000000001", 1e-32); | ||||
|     checkFloat<double>("100000000000000000000000000000000.0", 1e+32); | ||||
|     checkFloat<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); | ||||
|     checkFloat<double>("0.179769313486231571111111111111", 0.17976931348623157); | ||||
|     checkFloat<double>("17976931348623157.11111111111111", 17976931348623157.0); | ||||
|     checkFloat<double>("1797693.134862315711111111111111", 1797693.1348623157); | ||||
|  | ||||
|     check<double>("-0.179769313486231571111111111111", -0.17976931348623157); | ||||
|     check<double>("-17976931348623157.11111111111111", -17976931348623157.0); | ||||
|     check<double>("-1797693.134862315711111111111111", -1797693.1348623157); | ||||
|     checkFloat<double>("-0.179769313486231571111111111111", | ||||
|                        -0.17976931348623157); | ||||
|     checkFloat<double>("-17976931348623157.11111111111111", | ||||
|                        -17976931348623157.0); | ||||
|     checkFloat<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); | ||||
|     checkFloat<double>("1e-65535", 0.0); | ||||
|   } | ||||
|  | ||||
|   SECTION("NaN") { | ||||
|   | ||||
| @@ -9,59 +9,59 @@ | ||||
| using namespace ARDUINOJSON_NAMESPACE; | ||||
|  | ||||
| template <typename T> | ||||
| void check(const char* input, T expected) { | ||||
| void checkInteger(const char* input, T expected) { | ||||
|   CAPTURE(input); | ||||
|   T actual = parseInteger<T>(input); | ||||
|   REQUIRE(expected == actual); | ||||
| } | ||||
|  | ||||
| TEST_CASE("parseInteger<int8_t>()") { | ||||
|   check<int8_t>("-128", -128); | ||||
|   check<int8_t>("127", 127); | ||||
|   check<int8_t>("+127", 127); | ||||
|   check<int8_t>("3.14", 3); | ||||
|   check<int8_t>("x42", 0); | ||||
|   check<int8_t>("128", 0);   // overflow | ||||
|   check<int8_t>("-129", 0);  // overflow | ||||
|   checkInteger<int8_t>("-128", -128); | ||||
|   checkInteger<int8_t>("127", 127); | ||||
|   checkInteger<int8_t>("+127", 127); | ||||
|   checkInteger<int8_t>("3.14", 3); | ||||
|   checkInteger<int8_t>("x42", 0); | ||||
|   checkInteger<int8_t>("128", 0);   // overflow | ||||
|   checkInteger<int8_t>("-129", 0);  // overflow | ||||
| } | ||||
|  | ||||
| TEST_CASE("parseInteger<int16_t>()") { | ||||
|   check<int16_t>("-32768", -32768); | ||||
|   check<int16_t>("32767", 32767); | ||||
|   check<int16_t>("+32767", 32767); | ||||
|   check<int16_t>("3.14", 3); | ||||
|   check<int16_t>("x42", 0); | ||||
|   check<int16_t>("-32769", 0);  // overflow | ||||
|   check<int16_t>("32768", 0);   // overflow | ||||
|   checkInteger<int16_t>("-32768", -32768); | ||||
|   checkInteger<int16_t>("32767", 32767); | ||||
|   checkInteger<int16_t>("+32767", 32767); | ||||
|   checkInteger<int16_t>("3.14", 3); | ||||
|   checkInteger<int16_t>("x42", 0); | ||||
|   checkInteger<int16_t>("-32769", 0);  // overflow | ||||
|   checkInteger<int16_t>("32768", 0);   // overflow | ||||
| } | ||||
|  | ||||
| TEST_CASE("parseInteger<int32_t>()") { | ||||
|   check<int32_t>("-2147483648", (-2147483647 - 1)); | ||||
|   check<int32_t>("2147483647", 2147483647); | ||||
|   check<int32_t>("+2147483647", 2147483647); | ||||
|   check<int32_t>("3.14", 3); | ||||
|   check<int32_t>("x42", 0); | ||||
|   check<int32_t>("-2147483649", 0);  // overflow | ||||
|   check<int32_t>("2147483648", 0);   // overflow | ||||
|   checkInteger<int32_t>("-2147483648", (-2147483647 - 1)); | ||||
|   checkInteger<int32_t>("2147483647", 2147483647); | ||||
|   checkInteger<int32_t>("+2147483647", 2147483647); | ||||
|   checkInteger<int32_t>("3.14", 3); | ||||
|   checkInteger<int32_t>("x42", 0); | ||||
|   checkInteger<int32_t>("-2147483649", 0);  // overflow | ||||
|   checkInteger<int32_t>("2147483648", 0);   // overflow | ||||
| } | ||||
|  | ||||
| TEST_CASE("parseInteger<uint8_t>()") { | ||||
|   check<uint8_t>("0", 0); | ||||
|   check<uint8_t>("255", 255); | ||||
|   check<uint8_t>("+255", 255); | ||||
|   check<uint8_t>("3.14", 3); | ||||
|   check<uint8_t>("x42", 0); | ||||
|   check<uint8_t>("-1", 0); | ||||
|   check<uint8_t>("256", 0); | ||||
|   checkInteger<uint8_t>("0", 0); | ||||
|   checkInteger<uint8_t>("255", 255); | ||||
|   checkInteger<uint8_t>("+255", 255); | ||||
|   checkInteger<uint8_t>("3.14", 3); | ||||
|   checkInteger<uint8_t>("x42", 0); | ||||
|   checkInteger<uint8_t>("-1", 0); | ||||
|   checkInteger<uint8_t>("256", 0); | ||||
| } | ||||
|  | ||||
| TEST_CASE("parseInteger<uint16_t>()") { | ||||
|   check<uint16_t>("0", 0); | ||||
|   check<uint16_t>("65535", 65535); | ||||
|   check<uint16_t>("+65535", 65535); | ||||
|   check<uint16_t>("3.14", 3); | ||||
|   // check<uint16_t>(" 42", 0); | ||||
|   check<uint16_t>("x42", 0); | ||||
|   check<uint16_t>("-1", 0); | ||||
|   check<uint16_t>("65536", 0); | ||||
|   checkInteger<uint16_t>("0", 0); | ||||
|   checkInteger<uint16_t>("65535", 65535); | ||||
|   checkInteger<uint16_t>("+65535", 65535); | ||||
|   checkInteger<uint16_t>("3.14", 3); | ||||
|   // checkInteger<uint16_t>(" 42", 0); | ||||
|   checkInteger<uint16_t>("x42", 0); | ||||
|   checkInteger<uint16_t>("-1", 0); | ||||
|   checkInteger<uint16_t>("65536", 0); | ||||
| } | ||||
|   | ||||
		Reference in New Issue
	
	Block a user