mirror of
				https://github.com/eledio-devices/thirdparty-ArduinoJson.git
				synced 2025-10-31 08:42:39 +01:00 
			
		
		
		
	Fixed support for volatile float and double (fixes #1557)
This commit is contained in:
		| @@ -135,3 +135,29 @@ TEST_CASE("JsonVariant set()/get()") { | ||||
|     checkValue<JsonObject>(object); | ||||
|   } | ||||
| } | ||||
|  | ||||
| TEST_CASE("volatile") { | ||||
|   DynamicJsonDocument doc(4096); | ||||
|   JsonVariant variant = doc.to<JsonVariant>(); | ||||
|  | ||||
|   SECTION("volatile int") { | ||||
|     volatile int f = 42; | ||||
|     variant.set(f); | ||||
|     CHECK(variant.is<int>() == true); | ||||
|     CHECK(variant.as<int>() == 42); | ||||
|   } | ||||
|  | ||||
|   SECTION("volatile float") {  // issue #1557 | ||||
|     volatile float f = 3.14f; | ||||
|     variant.set(f); | ||||
|     CHECK(variant.is<float>() == true); | ||||
|     CHECK(variant.as<float>() == 3.14f); | ||||
|   } | ||||
|  | ||||
|   SECTION("volatile double") { | ||||
|     volatile double f = 3.14; | ||||
|     variant.set(f); | ||||
|     CHECK(variant.is<double>() == true); | ||||
|     CHECK(variant.as<double>() == 3.14); | ||||
|   } | ||||
| } | ||||
|   | ||||
| @@ -32,6 +32,12 @@ TEST_CASE("Polyfills/type_traits") { | ||||
|   SECTION("is_integral") { | ||||
|     CHECK(is_integral<double>::value == false); | ||||
|     CHECK(is_integral<float>::value == false); | ||||
|     CHECK(is_integral<const double>::value == false); | ||||
|     CHECK(is_integral<const float>::value == false); | ||||
|     CHECK(is_integral<volatile double>::value == false); | ||||
|     CHECK(is_integral<volatile float>::value == false); | ||||
|     CHECK(is_integral<const volatile double>::value == false); | ||||
|     CHECK(is_integral<const volatile float>::value == false); | ||||
|  | ||||
|     CHECK(is_integral<bool>::value == true); | ||||
|     CHECK(is_integral<char>::value == true); | ||||
| @@ -43,6 +49,36 @@ TEST_CASE("Polyfills/type_traits") { | ||||
|     CHECK(is_integral<unsigned int>::value == true); | ||||
|     CHECK(is_integral<unsigned long>::value == true); | ||||
|     CHECK(is_integral<unsigned short>::value == true); | ||||
|     CHECK(is_integral<const bool>::value == true); | ||||
|     CHECK(is_integral<const char>::value == true); | ||||
|     CHECK(is_integral<const signed char>::value == true); | ||||
|     CHECK(is_integral<const signed int>::value == true); | ||||
|     CHECK(is_integral<const signed long>::value == true); | ||||
|     CHECK(is_integral<const signed short>::value == true); | ||||
|     CHECK(is_integral<const unsigned char>::value == true); | ||||
|     CHECK(is_integral<const unsigned int>::value == true); | ||||
|     CHECK(is_integral<const unsigned long>::value == true); | ||||
|     CHECK(is_integral<const unsigned short>::value == true); | ||||
|     CHECK(is_integral<volatile bool>::value == true); | ||||
|     CHECK(is_integral<volatile char>::value == true); | ||||
|     CHECK(is_integral<volatile signed char>::value == true); | ||||
|     CHECK(is_integral<volatile signed int>::value == true); | ||||
|     CHECK(is_integral<volatile signed long>::value == true); | ||||
|     CHECK(is_integral<volatile signed short>::value == true); | ||||
|     CHECK(is_integral<volatile unsigned char>::value == true); | ||||
|     CHECK(is_integral<volatile unsigned int>::value == true); | ||||
|     CHECK(is_integral<volatile unsigned long>::value == true); | ||||
|     CHECK(is_integral<volatile unsigned short>::value == true); | ||||
|     CHECK(is_integral<const volatile bool>::value == true); | ||||
|     CHECK(is_integral<const volatile char>::value == true); | ||||
|     CHECK(is_integral<const volatile signed char>::value == true); | ||||
|     CHECK(is_integral<const volatile signed int>::value == true); | ||||
|     CHECK(is_integral<const volatile signed long>::value == true); | ||||
|     CHECK(is_integral<const volatile signed short>::value == true); | ||||
|     CHECK(is_integral<const volatile unsigned char>::value == true); | ||||
|     CHECK(is_integral<const volatile unsigned int>::value == true); | ||||
|     CHECK(is_integral<const volatile unsigned long>::value == true); | ||||
|     CHECK(is_integral<const volatile unsigned short>::value == true); | ||||
|  | ||||
|     CHECK(is_integral<UInt>::value == true); | ||||
|   } | ||||
| @@ -56,6 +92,33 @@ TEST_CASE("Polyfills/type_traits") { | ||||
|     CHECK(is_signed<float>::value == true); | ||||
|     CHECK(is_signed<double>::value == true); | ||||
|     CHECK(is_signed<bool>::value == false); | ||||
|  | ||||
|     CHECK(is_signed<const char>::value == true); | ||||
|     CHECK(is_signed<const signed char>::value == true); | ||||
|     CHECK(is_signed<const signed int>::value == true); | ||||
|     CHECK(is_signed<const signed short>::value == true); | ||||
|     CHECK(is_signed<const signed long>::value == true); | ||||
|     CHECK(is_signed<const float>::value == true); | ||||
|     CHECK(is_signed<const double>::value == true); | ||||
|     CHECK(is_signed<const bool>::value == false); | ||||
|  | ||||
|     CHECK(is_signed<volatile char>::value == true); | ||||
|     CHECK(is_signed<volatile signed char>::value == true); | ||||
|     CHECK(is_signed<volatile signed int>::value == true); | ||||
|     CHECK(is_signed<volatile signed short>::value == true); | ||||
|     CHECK(is_signed<volatile signed long>::value == true); | ||||
|     CHECK(is_signed<volatile float>::value == true); | ||||
|     CHECK(is_signed<volatile double>::value == true); | ||||
|     CHECK(is_signed<volatile bool>::value == false); | ||||
|  | ||||
|     CHECK(is_signed<const volatile char>::value == true); | ||||
|     CHECK(is_signed<const volatile signed char>::value == true); | ||||
|     CHECK(is_signed<const volatile signed int>::value == true); | ||||
|     CHECK(is_signed<const volatile signed short>::value == true); | ||||
|     CHECK(is_signed<const volatile signed long>::value == true); | ||||
|     CHECK(is_signed<const volatile float>::value == true); | ||||
|     CHECK(is_signed<const volatile double>::value == true); | ||||
|     CHECK(is_signed<const volatile bool>::value == false); | ||||
|   } | ||||
|  | ||||
|   SECTION("is_unsigned") { | ||||
| @@ -67,6 +130,45 @@ TEST_CASE("Polyfills/type_traits") { | ||||
|     CHECK(is_unsigned<char>::value == false); | ||||
|     CHECK(is_unsigned<float>::value == false); | ||||
|     CHECK(is_unsigned<double>::value == false); | ||||
|  | ||||
|     CHECK(is_unsigned<const unsigned char>::value == true); | ||||
|     CHECK(is_unsigned<const unsigned int>::value == true); | ||||
|     CHECK(is_unsigned<const unsigned short>::value == true); | ||||
|     CHECK(is_unsigned<const unsigned long>::value == true); | ||||
|     CHECK(is_unsigned<const bool>::value == true); | ||||
|     CHECK(is_unsigned<const char>::value == false); | ||||
|     CHECK(is_unsigned<const float>::value == false); | ||||
|     CHECK(is_unsigned<const double>::value == false); | ||||
|  | ||||
|     CHECK(is_unsigned<volatile unsigned char>::value == true); | ||||
|     CHECK(is_unsigned<volatile unsigned int>::value == true); | ||||
|     CHECK(is_unsigned<volatile unsigned short>::value == true); | ||||
|     CHECK(is_unsigned<volatile unsigned long>::value == true); | ||||
|     CHECK(is_unsigned<volatile bool>::value == true); | ||||
|     CHECK(is_unsigned<volatile char>::value == false); | ||||
|     CHECK(is_unsigned<volatile float>::value == false); | ||||
|     CHECK(is_unsigned<volatile double>::value == false); | ||||
|  | ||||
|     CHECK(is_unsigned<const volatile unsigned char>::value == true); | ||||
|     CHECK(is_unsigned<const volatile unsigned int>::value == true); | ||||
|     CHECK(is_unsigned<const volatile unsigned short>::value == true); | ||||
|     CHECK(is_unsigned<const volatile unsigned long>::value == true); | ||||
|     CHECK(is_unsigned<const volatile bool>::value == true); | ||||
|     CHECK(is_unsigned<const volatile char>::value == false); | ||||
|     CHECK(is_unsigned<const volatile float>::value == false); | ||||
|     CHECK(is_unsigned<const volatile double>::value == false); | ||||
|   } | ||||
|  | ||||
|   SECTION("is_floating_point") { | ||||
|     CHECK(is_floating_point<int>::value == false); | ||||
|     CHECK(is_floating_point<float>::value == true); | ||||
|     CHECK(is_floating_point<double>::value == true); | ||||
|     CHECK(is_floating_point<const float>::value == true); | ||||
|     CHECK(is_floating_point<const double>::value == true); | ||||
|     CHECK(is_floating_point<volatile float>::value == true); | ||||
|     CHECK(is_floating_point<volatile double>::value == true); | ||||
|     CHECK(is_floating_point<const volatile float>::value == true); | ||||
|     CHECK(is_floating_point<const volatile double>::value == true); | ||||
|   } | ||||
|  | ||||
|   SECTION("is_convertible") { | ||||
|   | ||||
		Reference in New Issue
	
	Block a user