From 88510705be97db6753404f849cfbd4fca291162d Mon Sep 17 00:00:00 2001 From: Benoit Blanchon Date: Fri, 1 Aug 2014 14:52:15 +0200 Subject: [PATCH] Test casting a JsonValue to an int --- JsonGenerator/JsonValue.h | 5 +++++ JsonGeneratorTests/JsonValue_Cast_Tests.cpp | 15 +++++++++++---- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/JsonGenerator/JsonValue.h b/JsonGenerator/JsonValue.h index 3f4db084..d93dc004 100644 --- a/JsonGenerator/JsonValue.h +++ b/JsonGenerator/JsonValue.h @@ -64,6 +64,11 @@ namespace ArduinoJson return ""; } + operator int() + { + return content.asLong; + } + size_t printTo(Print& p) const { // handmade polymorphism diff --git a/JsonGeneratorTests/JsonValue_Cast_Tests.cpp b/JsonGeneratorTests/JsonValue_Cast_Tests.cpp index 30e791d2..26108a75 100644 --- a/JsonGeneratorTests/JsonValue_Cast_Tests.cpp +++ b/JsonGeneratorTests/JsonValue_Cast_Tests.cpp @@ -21,15 +21,22 @@ namespace JsonGeneratorTests TEST_METHOD(String) { - value = "hello"; - mustCastTo("hello"); + setValueAndCheckCast("hello"); } + TEST_METHOD(Integer) + { + setValueAndCheckCast(42); + } + + private: - void mustCastTo(const char* expected) + template + void setValueAndCheckCast(T expected) { - const char* actual = value; + value = expected; + T actual = value; Assert::AreEqual(expected, actual); } };