mirror of
				https://github.com/eledio-devices/thirdparty-ArduinoJson.git
				synced 2025-10-31 16:14:11 +01:00 
			
		
		
		
	Added an printTo(char[N]) and prettyPrintTo(char[N]) (issue #292)
				
					
				
			This commit is contained in:
		| @@ -4,6 +4,7 @@ ArduinoJson: change log | ||||
| HEAD | ||||
| ---- | ||||
|  | ||||
| * Added an `printTo(char[N])` and `prettyPrintTo(char[N])` (issue #292) | ||||
| * Added ability to set a nested value like this: `root["A"]["B"] = "C"` (issue #352) | ||||
| * Renamed `*.ipp` to `*Impl.hpp` because they were ignored by Arduino IDE (issue #396) | ||||
|  | ||||
|   | ||||
| @@ -50,6 +50,11 @@ class JsonPrintable { | ||||
|     return printTo(sb); | ||||
|   } | ||||
|  | ||||
|   template <size_t N> | ||||
|   size_t printTo(char (&buffer)[N]) const { | ||||
|     return printTo(buffer, N); | ||||
|   } | ||||
|  | ||||
|   template <typename TString> | ||||
|   typename TypeTraits::EnableIf<StringFuncs<TString>::has_append, size_t>::type | ||||
|   printTo(TString &str) const { | ||||
| @@ -67,6 +72,11 @@ class JsonPrintable { | ||||
|     return prettyPrintTo(sb); | ||||
|   } | ||||
|  | ||||
|   template <size_t N> | ||||
|   size_t prettyPrintTo(char (&buffer)[N]) const { | ||||
|     return prettyPrintTo(buffer, N); | ||||
|   } | ||||
|  | ||||
|   size_t prettyPrintTo(Print &print) const { | ||||
|     IndentedPrint indentedPrint = IndentedPrint(print); | ||||
|     return prettyPrintTo(indentedPrint); | ||||
|   | ||||
| @@ -5,8 +5,8 @@ | ||||
| // https://github.com/bblanchon/ArduinoJson | ||||
| // If you like this project, please add a star! | ||||
|  | ||||
| #include <gtest/gtest.h> | ||||
| #include <ArduinoJson.h> | ||||
| #include <gtest/gtest.h> | ||||
|  | ||||
| class JsonArray_PrettyPrintTo_Tests : public testing::Test { | ||||
|  public: | ||||
| @@ -19,7 +19,7 @@ class JsonArray_PrettyPrintTo_Tests : public testing::Test { | ||||
|   void outputMustBe(const char* expected) { | ||||
|     char actual[256]; | ||||
|  | ||||
|     size_t actualLen = array.prettyPrintTo(actual, sizeof(actual)); | ||||
|     size_t actualLen = array.prettyPrintTo(actual); | ||||
|     size_t measuredLen = array.measurePrettyLength(); | ||||
|  | ||||
|     EXPECT_STREQ(expected, actual); | ||||
| @@ -28,7 +28,9 @@ class JsonArray_PrettyPrintTo_Tests : public testing::Test { | ||||
|   } | ||||
| }; | ||||
|  | ||||
| TEST_F(JsonArray_PrettyPrintTo_Tests, Empty) { outputMustBe("[]"); } | ||||
| TEST_F(JsonArray_PrettyPrintTo_Tests, Empty) { | ||||
|   outputMustBe("[]"); | ||||
| } | ||||
|  | ||||
| TEST_F(JsonArray_PrettyPrintTo_Tests, OneElement) { | ||||
|   array.add(1); | ||||
|   | ||||
| @@ -5,8 +5,8 @@ | ||||
| // https://github.com/bblanchon/ArduinoJson | ||||
| // If you like this project, please add a star! | ||||
|  | ||||
| #include <gtest/gtest.h> | ||||
| #include <ArduinoJson.h> | ||||
| #include <gtest/gtest.h> | ||||
|  | ||||
| class JsonArray_PrintTo_Tests : public testing::Test { | ||||
|  public: | ||||
| @@ -17,7 +17,7 @@ class JsonArray_PrintTo_Tests : public testing::Test { | ||||
|   JsonArray &array; | ||||
|  | ||||
|   void outputMustBe(const char *expected) { | ||||
|     size_t actualLen = array.printTo(buffer, sizeof(buffer)); | ||||
|     size_t actualLen = array.printTo(buffer); | ||||
|     size_t measuredLen = array.measureLength(); | ||||
|  | ||||
|     EXPECT_STREQ(expected, buffer); | ||||
| @@ -29,7 +29,9 @@ class JsonArray_PrintTo_Tests : public testing::Test { | ||||
|   char buffer[256]; | ||||
| }; | ||||
|  | ||||
| TEST_F(JsonArray_PrintTo_Tests, Empty) { outputMustBe("[]"); } | ||||
| TEST_F(JsonArray_PrintTo_Tests, Empty) { | ||||
|   outputMustBe("[]"); | ||||
| } | ||||
|  | ||||
| TEST_F(JsonArray_PrintTo_Tests, Null) { | ||||
|   array.add(static_cast<char *>(0)); | ||||
|   | ||||
| @@ -5,8 +5,8 @@ | ||||
| // https://github.com/bblanchon/ArduinoJson | ||||
| // If you like this project, please add a star! | ||||
|  | ||||
| #include <gtest/gtest.h> | ||||
| #include <ArduinoJson.h> | ||||
| #include <gtest/gtest.h> | ||||
|  | ||||
| class JsonObject_PrettyPrintTo_Tests : public testing::Test { | ||||
|  public: | ||||
| @@ -19,7 +19,7 @@ class JsonObject_PrettyPrintTo_Tests : public testing::Test { | ||||
|   void outputMustBe(const char *expected) { | ||||
|     char buffer[256]; | ||||
|  | ||||
|     size_t actualLen = _object.prettyPrintTo(buffer, sizeof(buffer)); | ||||
|     size_t actualLen = _object.prettyPrintTo(buffer); | ||||
|     size_t measuredLen = _object.measurePrettyLength(); | ||||
|  | ||||
|     EXPECT_STREQ(expected, buffer); | ||||
| @@ -28,7 +28,9 @@ class JsonObject_PrettyPrintTo_Tests : public testing::Test { | ||||
|   } | ||||
| }; | ||||
|  | ||||
| TEST_F(JsonObject_PrettyPrintTo_Tests, EmptyObject) { outputMustBe("{}"); } | ||||
| TEST_F(JsonObject_PrettyPrintTo_Tests, EmptyObject) { | ||||
|   outputMustBe("{}"); | ||||
| } | ||||
|  | ||||
| TEST_F(JsonObject_PrettyPrintTo_Tests, OneMember) { | ||||
|   _object["key"] = "value"; | ||||
|   | ||||
| @@ -15,7 +15,7 @@ class JsonObject_PrintTo_Tests : public testing::Test { | ||||
|  protected: | ||||
|   void outputMustBe(const char *expected) { | ||||
|     char actual[256]; | ||||
|     size_t actualLen = _object.printTo(actual, sizeof(actual)); | ||||
|     size_t actualLen = _object.printTo(actual); | ||||
|     size_t measuredLen = _object.measureLength(); | ||||
|  | ||||
|     EXPECT_STREQ(expected, actual); | ||||
| @@ -27,7 +27,9 @@ class JsonObject_PrintTo_Tests : public testing::Test { | ||||
|   JsonObject &_object; | ||||
| }; | ||||
|  | ||||
| TEST_F(JsonObject_PrintTo_Tests, EmptyObject) { outputMustBe("{}"); } | ||||
| TEST_F(JsonObject_PrintTo_Tests, EmptyObject) { | ||||
|   outputMustBe("{}"); | ||||
| } | ||||
|  | ||||
| TEST_F(JsonObject_PrintTo_Tests, TwoStrings) { | ||||
|   _object["key1"] = "value1"; | ||||
|   | ||||
| @@ -5,8 +5,8 @@ | ||||
| // https://github.com/bblanchon/ArduinoJson | ||||
| // If you like this project, please add a star! | ||||
|  | ||||
| #include <gtest/gtest.h> | ||||
| #include <ArduinoJson.h> | ||||
| #include <gtest/gtest.h> | ||||
|  | ||||
| class JsonObject_Subscript_Tests : public ::testing::Test { | ||||
|  public: | ||||
|   | ||||
		Reference in New Issue
	
	Block a user