瀏覽代碼

Test casting a JsonValue to a bool

Benoit Blanchon 11 年之前
父節點
當前提交
028ff6676e
共有 2 個文件被更改,包括 11 次插入0 次删除
  1. 5 0
      JsonGenerator/JsonValue.h
  2. 6 0
      JsonGeneratorTests/JsonValue_Cast_Tests.cpp

+ 5 - 0
JsonGenerator/JsonValue.h

@@ -59,6 +59,11 @@ namespace ArduinoJson
                 content.asDouble = value;
             }
 
+            operator bool()
+            {
+                return content.asBool;
+            }
+
             operator const char*()
             {
                 return "";

+ 6 - 0
JsonGeneratorTests/JsonValue_Cast_Tests.cpp

@@ -34,6 +34,12 @@ namespace JsonGeneratorTests
             setValueAndCheckCast(42L);
         }
 
+        TEST_METHOD(Bool)
+        {
+            setValueAndCheckCast(true);
+            setValueAndCheckCast(false);
+        }
+
     private:
 
         template<typename T>