mirror of
				https://github.com/eledio-devices/thirdparty-ArduinoJson.git
				synced 2025-10-31 16:14:11 +01:00 
			
		
		
		
	Added a test that stores a long in a JsonValue
This commit is contained in:
		| @@ -14,13 +14,23 @@ size_t JsonValue::printBoolTo(Print& p) const | ||||
|  | ||||
| size_t JsonValue::printDoubleTo(Print& p) const | ||||
| { | ||||
|     char tmp[16]; | ||||
|     char tmp[32]; | ||||
|  | ||||
|     sprintf(tmp, "%lg", content.asDouble); | ||||
|  | ||||
|     return p.write(tmp); | ||||
| } | ||||
|  | ||||
| size_t JsonValue::printLongTo(Print& p) const | ||||
| { | ||||
|     char tmp[32]; | ||||
|  | ||||
|     sprintf(tmp, "%ld", content.asLong); | ||||
|  | ||||
|     return p.write(tmp); | ||||
| } | ||||
|  | ||||
|  | ||||
| size_t JsonValue::printPrintableTo(Print& p) const | ||||
| { | ||||
|     if (content.asPrintable) | ||||
|   | ||||
| @@ -16,10 +16,10 @@ public: | ||||
|     { | ||||
|     } | ||||
|  | ||||
|     JsonValue(const char* value) | ||||
|         : implementation(&JsonValue::printStringTo) | ||||
|     JsonValue(bool value) | ||||
|         : implementation(&JsonValue::printBoolTo) | ||||
|     { | ||||
|         content.asString = value; | ||||
|         content.asBool = value; | ||||
|     } | ||||
|  | ||||
|     JsonValue(double value) | ||||
| @@ -28,10 +28,10 @@ public: | ||||
|         content.asDouble = value; | ||||
|     } | ||||
|  | ||||
|     JsonValue(bool value) | ||||
|         : implementation(&JsonValue::printBoolTo) | ||||
|     JsonValue(long value) | ||||
|         : implementation(&JsonValue::printLongTo) | ||||
|     { | ||||
|         content.asBool = value; | ||||
|         content.asLong = value; | ||||
|     } | ||||
|  | ||||
|     JsonValue(Printable& value) | ||||
| @@ -40,6 +40,12 @@ public: | ||||
|         content.asPrintable = &value; | ||||
|     } | ||||
|  | ||||
|     JsonValue(const char* value) | ||||
|         : implementation(&JsonValue::printStringTo) | ||||
|     { | ||||
|         content.asString = value; | ||||
|     } | ||||
|  | ||||
|     virtual size_t printTo(Print& p) const | ||||
|     { | ||||
|         // handmade polymorphism | ||||
| @@ -52,6 +58,7 @@ private: | ||||
|     { | ||||
|         bool        asBool; | ||||
|         double      asDouble; | ||||
|         long        asLong; | ||||
|         Printable*  asPrintable; | ||||
|         const char* asString; | ||||
|     }; | ||||
| @@ -62,6 +69,7 @@ private: | ||||
|  | ||||
|     size_t printBoolTo(Print& p) const; | ||||
|     size_t printDoubleTo(Print& p) const; | ||||
|     size_t printLongTo(Print& p) const; | ||||
|     size_t printPrintableTo(Print& p) const; | ||||
|     size_t printStringTo(Print& p) const; | ||||
| }; | ||||
| @@ -76,13 +76,20 @@ namespace JsonGeneratorTests | ||||
|             assertResultIs("\"\\\\\\\"\\b\\f\\n\\r\\t\""); | ||||
|         } | ||||
|  | ||||
|         TEST_METHOD(Number) | ||||
|         TEST_METHOD(Double) | ||||
|         { | ||||
|             write(3.14); | ||||
|             assertReturns(4); | ||||
|             assertResultIs("3.14"); | ||||
|         } | ||||
|  | ||||
|         TEST_METHOD(Long) | ||||
|         { | ||||
|             write(314L); | ||||
|             assertReturns(3); | ||||
|             assertResultIs("314"); | ||||
|         } | ||||
|  | ||||
|         template<typename T> | ||||
|         void write(T value) | ||||
|         { | ||||
|   | ||||
		Reference in New Issue
	
	Block a user