Просмотр исходного кода

Test casting a JsonValue to a double

Benoit Blanchon 11 лет назад
Родитель
Сommit
c10bcee324
2 измененных файлов с 16 добавлено и 6 удалено
  1. 5 0
      JsonGenerator/JsonValue.h
  2. 11 6
      JsonGeneratorTests/JsonValue_Cast_Tests.cpp

+ 5 - 0
JsonGenerator/JsonValue.h

@@ -69,6 +69,11 @@ namespace ArduinoJson
                 return "";
             }
 
+            operator double()
+            {
+                return content.asDouble;
+            }
+
             operator int()
             {
                 return content.asLong;

+ 11 - 6
JsonGeneratorTests/JsonValue_Cast_Tests.cpp

@@ -19,9 +19,15 @@ namespace JsonGeneratorTests
 
     public:
 
-        TEST_METHOD(String)
-        {            
-            setValueAndCheckCast("hello");
+        TEST_METHOD(Bool)
+        {
+            setValueAndCheckCast(true);
+            setValueAndCheckCast(false);
+        }
+
+        TEST_METHOD(Double)
+        {
+            setValueAndCheckCast(3.14156);
         }
 
         TEST_METHOD(Integer)
@@ -34,10 +40,9 @@ namespace JsonGeneratorTests
             setValueAndCheckCast(42L);
         }
 
-        TEST_METHOD(Bool)
+        TEST_METHOD(String)
         {
-            setValueAndCheckCast(true);
-            setValueAndCheckCast(false);
+            setValueAndCheckCast("hello");
         }
 
     private: