From c10bcee3243c2cbf6f6b77bb3ff87c31e0606311 Mon Sep 17 00:00:00 2001 From: Benoit Blanchon Date: Fri, 1 Aug 2014 14:56:46 +0200 Subject: [PATCH] Test casting a JsonValue to a double --- JsonGenerator/JsonValue.h | 5 +++++ JsonGeneratorTests/JsonValue_Cast_Tests.cpp | 17 +++++++++++------ 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/JsonGenerator/JsonValue.h b/JsonGenerator/JsonValue.h index 12b491df..3ba9e2d7 100644 --- a/JsonGenerator/JsonValue.h +++ b/JsonGenerator/JsonValue.h @@ -69,6 +69,11 @@ namespace ArduinoJson return ""; } + operator double() + { + return content.asDouble; + } + operator int() { return content.asLong; diff --git a/JsonGeneratorTests/JsonValue_Cast_Tests.cpp b/JsonGeneratorTests/JsonValue_Cast_Tests.cpp index 3bbd73a7..591cb690 100644 --- a/JsonGeneratorTests/JsonValue_Cast_Tests.cpp +++ b/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: