mirror of
				https://github.com/eledio-devices/thirdparty-ArduinoJson.git
				synced 2025-10-31 16:14:11 +01:00 
			
		
		
		
	Gathered the tests of MemberProxy in one file
This commit is contained in:
		| @@ -15,7 +15,6 @@ add_subdirectory(JsonDocument) | |||||||
| add_subdirectory(JsonObject) | add_subdirectory(JsonObject) | ||||||
| add_subdirectory(JsonSerializer) | add_subdirectory(JsonSerializer) | ||||||
| add_subdirectory(JsonVariant) | add_subdirectory(JsonVariant) | ||||||
| add_subdirectory(MemberProxy) |  | ||||||
| add_subdirectory(MemoryPool) | add_subdirectory(MemoryPool) | ||||||
| add_subdirectory(Misc) | add_subdirectory(Misc) | ||||||
| add_subdirectory(MixedConfiguration) | add_subdirectory(MixedConfiguration) | ||||||
|   | |||||||
| @@ -11,6 +11,7 @@ add_executable(JsonDocumentTests | |||||||
| 	DynamicJsonDocument.cpp | 	DynamicJsonDocument.cpp | ||||||
| 	ElementProxy.cpp | 	ElementProxy.cpp | ||||||
| 	isNull.cpp | 	isNull.cpp | ||||||
|  | 	MemberProxy.cpp | ||||||
| 	nesting.cpp | 	nesting.cpp | ||||||
| 	overflowed.cpp | 	overflowed.cpp | ||||||
| 	remove.cpp | 	remove.cpp | ||||||
|   | |||||||
							
								
								
									
										236
									
								
								extras/tests/JsonDocument/MemberProxy.cpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										236
									
								
								extras/tests/JsonDocument/MemberProxy.cpp
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,236 @@ | |||||||
|  | // ArduinoJson - arduinojson.org | ||||||
|  | // Copyright Benoit Blanchon 2014-2020 | ||||||
|  | // MIT License | ||||||
|  |  | ||||||
|  | #include <ArduinoJson.h> | ||||||
|  | #include <catch.hpp> | ||||||
|  |  | ||||||
|  | using namespace ARDUINOJSON_NAMESPACE; | ||||||
|  |  | ||||||
|  | TEST_CASE("MemberProxy::add()") { | ||||||
|  |   DynamicJsonDocument doc(4096); | ||||||
|  |   MemberProxy<JsonDocument &, const char *> mp = doc["hello"]; | ||||||
|  |  | ||||||
|  |   SECTION("add(int)") { | ||||||
|  |     mp.add(42); | ||||||
|  |  | ||||||
|  |     REQUIRE(doc.as<std::string>() == "{\"hello\":[42]}"); | ||||||
|  |   } | ||||||
|  |  | ||||||
|  |   SECTION("add(const char*)") { | ||||||
|  |     mp.add("world"); | ||||||
|  |  | ||||||
|  |     REQUIRE(doc.as<std::string>() == "{\"hello\":[\"world\"]}"); | ||||||
|  |   } | ||||||
|  | } | ||||||
|  |  | ||||||
|  | TEST_CASE("MemberProxy::clear()") { | ||||||
|  |   DynamicJsonDocument doc(4096); | ||||||
|  |   MemberProxy<JsonDocument &, const char *> mp = doc["hello"]; | ||||||
|  |  | ||||||
|  |   SECTION("size goes back to zero") { | ||||||
|  |     mp.add(42); | ||||||
|  |     mp.clear(); | ||||||
|  |  | ||||||
|  |     REQUIRE(mp.size() == 0); | ||||||
|  |   } | ||||||
|  |  | ||||||
|  |   SECTION("isNull() return true") { | ||||||
|  |     mp.add("hello"); | ||||||
|  |     mp.clear(); | ||||||
|  |  | ||||||
|  |     REQUIRE(mp.isNull() == true); | ||||||
|  |   } | ||||||
|  | } | ||||||
|  |  | ||||||
|  | TEST_CASE("MemberProxy::operator==()") { | ||||||
|  |   DynamicJsonDocument doc(4096); | ||||||
|  |  | ||||||
|  |   SECTION("1 vs 1") { | ||||||
|  |     doc["a"] = 1; | ||||||
|  |     doc["b"] = 1; | ||||||
|  |  | ||||||
|  |     REQUIRE(doc["a"] <= doc["b"]); | ||||||
|  |     REQUIRE(doc["a"] == doc["b"]); | ||||||
|  |     REQUIRE(doc["a"] >= doc["b"]); | ||||||
|  |     REQUIRE_FALSE(doc["a"] != doc["b"]); | ||||||
|  |     REQUIRE_FALSE(doc["a"] < doc["b"]); | ||||||
|  |     REQUIRE_FALSE(doc["a"] > doc["b"]); | ||||||
|  |   } | ||||||
|  |  | ||||||
|  |   SECTION("1 vs 2") { | ||||||
|  |     doc["a"] = 1; | ||||||
|  |     doc["b"] = 2; | ||||||
|  |  | ||||||
|  |     REQUIRE(doc["a"] != doc["b"]); | ||||||
|  |     REQUIRE(doc["a"] < doc["b"]); | ||||||
|  |     REQUIRE(doc["a"] <= doc["b"]); | ||||||
|  |     REQUIRE_FALSE(doc["a"] == doc["b"]); | ||||||
|  |     REQUIRE_FALSE(doc["a"] > doc["b"]); | ||||||
|  |     REQUIRE_FALSE(doc["a"] >= doc["b"]); | ||||||
|  |   } | ||||||
|  |  | ||||||
|  |   SECTION("'abc' vs 'bcd'") { | ||||||
|  |     doc["a"] = "abc"; | ||||||
|  |     doc["b"] = "bcd"; | ||||||
|  |  | ||||||
|  |     REQUIRE(doc["a"] != doc["b"]); | ||||||
|  |     REQUIRE(doc["a"] < doc["b"]); | ||||||
|  |     REQUIRE(doc["a"] <= doc["b"]); | ||||||
|  |     REQUIRE_FALSE(doc["a"] == doc["b"]); | ||||||
|  |     REQUIRE_FALSE(doc["a"] > doc["b"]); | ||||||
|  |     REQUIRE_FALSE(doc["a"] >= doc["b"]); | ||||||
|  |   } | ||||||
|  | } | ||||||
|  |  | ||||||
|  | TEST_CASE("MemberProxy::containsKey()") { | ||||||
|  |   DynamicJsonDocument doc(4096); | ||||||
|  |   MemberProxy<JsonDocument &, const char *> mp = doc["hello"]; | ||||||
|  |  | ||||||
|  |   SECTION("containsKey(const char*)") { | ||||||
|  |     mp["key"] = "value"; | ||||||
|  |  | ||||||
|  |     REQUIRE(mp.containsKey("key") == true); | ||||||
|  |     REQUIRE(mp.containsKey("key") == true); | ||||||
|  |   } | ||||||
|  |  | ||||||
|  |   SECTION("containsKey(std::string)") { | ||||||
|  |     mp["key"] = "value"; | ||||||
|  |  | ||||||
|  |     REQUIRE(mp.containsKey(std::string("key")) == true); | ||||||
|  |     REQUIRE(mp.containsKey(std::string("key")) == true); | ||||||
|  |   } | ||||||
|  | } | ||||||
|  |  | ||||||
|  | TEST_CASE("MemberProxy::operator|()") { | ||||||
|  |   DynamicJsonDocument doc(4096); | ||||||
|  |  | ||||||
|  |   SECTION("const char*") { | ||||||
|  |     doc["a"] = "hello"; | ||||||
|  |  | ||||||
|  |     REQUIRE((doc["a"] | "world") == std::string("hello")); | ||||||
|  |     REQUIRE((doc["b"] | "world") == std::string("world")); | ||||||
|  |   } | ||||||
|  |  | ||||||
|  |   SECTION("Issue #1411") { | ||||||
|  |     doc["sensor"] = "gps"; | ||||||
|  |  | ||||||
|  |     const char *test = "test";  // <- the literal must be captured in a variable | ||||||
|  |                                 // to trigger the bug | ||||||
|  |     const char *sensor = doc["sensor"] | test;  // "gps" | ||||||
|  |  | ||||||
|  |     REQUIRE(sensor == std::string("gps")); | ||||||
|  |   } | ||||||
|  | } | ||||||
|  |  | ||||||
|  | TEST_CASE("MemberProxy::remove()") { | ||||||
|  |   DynamicJsonDocument doc(4096); | ||||||
|  |   MemberProxy<JsonDocument &, const char *> mp = doc["hello"]; | ||||||
|  |  | ||||||
|  |   SECTION("remove(int)") { | ||||||
|  |     mp.add(1); | ||||||
|  |     mp.add(2); | ||||||
|  |     mp.add(3); | ||||||
|  |  | ||||||
|  |     mp.remove(1); | ||||||
|  |  | ||||||
|  |     REQUIRE(mp.as<std::string>() == "[1,3]"); | ||||||
|  |   } | ||||||
|  |  | ||||||
|  |   SECTION("remove(const char *)") { | ||||||
|  |     mp["a"] = 1; | ||||||
|  |     mp["b"] = 2; | ||||||
|  |  | ||||||
|  |     mp.remove("a"); | ||||||
|  |  | ||||||
|  |     REQUIRE(mp.as<std::string>() == "{\"b\":2}"); | ||||||
|  |   } | ||||||
|  |  | ||||||
|  |   SECTION("remove(std::string)") { | ||||||
|  |     mp["a"] = 1; | ||||||
|  |     mp["b"] = 2; | ||||||
|  |  | ||||||
|  |     mp.remove(std::string("b")); | ||||||
|  |  | ||||||
|  |     REQUIRE(mp.as<std::string>() == "{\"a\":1}"); | ||||||
|  |   } | ||||||
|  |  | ||||||
|  | #ifdef HAS_VARIABLE_LENGTH_ARRAY | ||||||
|  |   SECTION("remove(vla)") { | ||||||
|  |     mp["a"] = 1; | ||||||
|  |     mp["b"] = 2; | ||||||
|  |  | ||||||
|  |     int i = 4; | ||||||
|  |     char vla[i]; | ||||||
|  |     strcpy(vla, "b"); | ||||||
|  |     mp.remove(vla); | ||||||
|  |  | ||||||
|  |     REQUIRE(mp.as<std::string>() == "{\"a\":1}"); | ||||||
|  |   } | ||||||
|  | #endif | ||||||
|  | } | ||||||
|  |  | ||||||
|  | TEST_CASE("MemberProxy::set()") { | ||||||
|  |   DynamicJsonDocument doc(4096); | ||||||
|  |   MemberProxy<JsonDocument &, const char *> mp = doc["hello"]; | ||||||
|  |  | ||||||
|  |   SECTION("set(int)") { | ||||||
|  |     mp.set(42); | ||||||
|  |  | ||||||
|  |     REQUIRE(doc.as<std::string>() == "{\"hello\":42}"); | ||||||
|  |   } | ||||||
|  |  | ||||||
|  |   SECTION("set(const char*)") { | ||||||
|  |     mp.set("world"); | ||||||
|  |  | ||||||
|  |     REQUIRE(doc.as<std::string>() == "{\"hello\":\"world\"}"); | ||||||
|  |   } | ||||||
|  |  | ||||||
|  |   SECTION("set(char[])") {  // issue #1191 | ||||||
|  |     char s[] = "world"; | ||||||
|  |     mp.set(s); | ||||||
|  |     strcpy(s, "!!!!!"); | ||||||
|  |  | ||||||
|  |     REQUIRE(doc.as<std::string>() == "{\"hello\":\"world\"}"); | ||||||
|  |   } | ||||||
|  | } | ||||||
|  |  | ||||||
|  | TEST_CASE("MemberProxy::size()") { | ||||||
|  |   DynamicJsonDocument doc(4096); | ||||||
|  |   MemberProxy<JsonDocument &, const char *> mp = doc["hello"]; | ||||||
|  |  | ||||||
|  |   SECTION("returns 0") { | ||||||
|  |     REQUIRE(mp.size() == 0); | ||||||
|  |   } | ||||||
|  |  | ||||||
|  |   SECTION("as an array, return 2") { | ||||||
|  |     mp.add(1); | ||||||
|  |     mp.add(2); | ||||||
|  |  | ||||||
|  |     REQUIRE(mp.size() == 2); | ||||||
|  |   } | ||||||
|  |  | ||||||
|  |   SECTION("as an object, return 2") { | ||||||
|  |     mp["a"] = 1; | ||||||
|  |     mp["b"] = 2; | ||||||
|  |  | ||||||
|  |     REQUIRE(mp.size() == 2); | ||||||
|  |   } | ||||||
|  | } | ||||||
|  |  | ||||||
|  | TEST_CASE("MemberProxy::operator[]") { | ||||||
|  |   DynamicJsonDocument doc(4096); | ||||||
|  |   MemberProxy<JsonDocument &, const char *> mp = doc["hello"]; | ||||||
|  |  | ||||||
|  |   SECTION("set member") { | ||||||
|  |     mp["world"] = 42; | ||||||
|  |  | ||||||
|  |     REQUIRE(doc.as<std::string>() == "{\"hello\":{\"world\":42}}"); | ||||||
|  |   } | ||||||
|  |  | ||||||
|  |   SECTION("set element") { | ||||||
|  |     mp[2] = 42; | ||||||
|  |  | ||||||
|  |     REQUIRE(doc.as<std::string>() == "{\"hello\":[null,null,42]}"); | ||||||
|  |   } | ||||||
|  | } | ||||||
| @@ -1,17 +0,0 @@ | |||||||
| # ArduinoJson - arduinojson.org |  | ||||||
| # Copyright Benoit Blanchon 2014-2020 |  | ||||||
| # MIT License |  | ||||||
|  |  | ||||||
| add_executable(MemberProxyTests |  | ||||||
| 	add.cpp |  | ||||||
| 	clear.cpp |  | ||||||
| 	compare.cpp |  | ||||||
| 	containsKey.cpp |  | ||||||
| 	or.cpp |  | ||||||
| 	remove.cpp |  | ||||||
| 	set.cpp |  | ||||||
| 	size.cpp |  | ||||||
| 	subscript.cpp |  | ||||||
| ) |  | ||||||
|  |  | ||||||
| add_test(MemberProxy MemberProxyTests) |  | ||||||
| @@ -1,25 +0,0 @@ | |||||||
| // ArduinoJson - arduinojson.org |  | ||||||
| // Copyright Benoit Blanchon 2014-2020 |  | ||||||
| // MIT License |  | ||||||
|  |  | ||||||
| #include <ArduinoJson.h> |  | ||||||
| #include <catch.hpp> |  | ||||||
|  |  | ||||||
| using namespace ARDUINOJSON_NAMESPACE; |  | ||||||
|  |  | ||||||
| TEST_CASE("MemberProxy::add()") { |  | ||||||
|   DynamicJsonDocument doc(4096); |  | ||||||
|   MemberProxy<JsonDocument&, const char*> mp = doc["hello"]; |  | ||||||
|  |  | ||||||
|   SECTION("add(int)") { |  | ||||||
|     mp.add(42); |  | ||||||
|  |  | ||||||
|     REQUIRE(doc.as<std::string>() == "{\"hello\":[42]}"); |  | ||||||
|   } |  | ||||||
|  |  | ||||||
|   SECTION("add(const char*)") { |  | ||||||
|     mp.add("world"); |  | ||||||
|  |  | ||||||
|     REQUIRE(doc.as<std::string>() == "{\"hello\":[\"world\"]}"); |  | ||||||
|   } |  | ||||||
| } |  | ||||||
| @@ -1,27 +0,0 @@ | |||||||
| // ArduinoJson - arduinojson.org |  | ||||||
| // Copyright Benoit Blanchon 2014-2020 |  | ||||||
| // MIT License |  | ||||||
|  |  | ||||||
| #include <ArduinoJson.h> |  | ||||||
| #include <catch.hpp> |  | ||||||
|  |  | ||||||
| using namespace ARDUINOJSON_NAMESPACE; |  | ||||||
|  |  | ||||||
| TEST_CASE("MemberProxy::clear()") { |  | ||||||
|   DynamicJsonDocument doc(4096); |  | ||||||
|   MemberProxy<JsonDocument&, const char*> mp = doc["hello"]; |  | ||||||
|  |  | ||||||
|   SECTION("size goes back to zero") { |  | ||||||
|     mp.add(42); |  | ||||||
|     mp.clear(); |  | ||||||
|  |  | ||||||
|     REQUIRE(mp.size() == 0); |  | ||||||
|   } |  | ||||||
|  |  | ||||||
|   SECTION("isNull() return true") { |  | ||||||
|     mp.add("hello"); |  | ||||||
|     mp.clear(); |  | ||||||
|  |  | ||||||
|     REQUIRE(mp.isNull() == true); |  | ||||||
|   } |  | ||||||
| } |  | ||||||
| @@ -1,48 +0,0 @@ | |||||||
| // ArduinoJson - arduinojson.org |  | ||||||
| // Copyright Benoit Blanchon 2014-2020 |  | ||||||
| // MIT License |  | ||||||
|  |  | ||||||
| #include <ArduinoJson.h> |  | ||||||
| #include <catch.hpp> |  | ||||||
|  |  | ||||||
| using namespace ARDUINOJSON_NAMESPACE; |  | ||||||
|  |  | ||||||
| TEST_CASE("MemberProxy::operator==()") { |  | ||||||
|   DynamicJsonDocument doc(4096); |  | ||||||
|  |  | ||||||
|   SECTION("1 vs 1") { |  | ||||||
|     doc["a"] = 1; |  | ||||||
|     doc["b"] = 1; |  | ||||||
|  |  | ||||||
|     REQUIRE(doc["a"] <= doc["b"]); |  | ||||||
|     REQUIRE(doc["a"] == doc["b"]); |  | ||||||
|     REQUIRE(doc["a"] >= doc["b"]); |  | ||||||
|     REQUIRE_FALSE(doc["a"] != doc["b"]); |  | ||||||
|     REQUIRE_FALSE(doc["a"] < doc["b"]); |  | ||||||
|     REQUIRE_FALSE(doc["a"] > doc["b"]); |  | ||||||
|   } |  | ||||||
|  |  | ||||||
|   SECTION("1 vs 2") { |  | ||||||
|     doc["a"] = 1; |  | ||||||
|     doc["b"] = 2; |  | ||||||
|  |  | ||||||
|     REQUIRE(doc["a"] != doc["b"]); |  | ||||||
|     REQUIRE(doc["a"] < doc["b"]); |  | ||||||
|     REQUIRE(doc["a"] <= doc["b"]); |  | ||||||
|     REQUIRE_FALSE(doc["a"] == doc["b"]); |  | ||||||
|     REQUIRE_FALSE(doc["a"] > doc["b"]); |  | ||||||
|     REQUIRE_FALSE(doc["a"] >= doc["b"]); |  | ||||||
|   } |  | ||||||
|  |  | ||||||
|   SECTION("'abc' vs 'bcd'") { |  | ||||||
|     doc["a"] = "abc"; |  | ||||||
|     doc["b"] = "bcd"; |  | ||||||
|  |  | ||||||
|     REQUIRE(doc["a"] != doc["b"]); |  | ||||||
|     REQUIRE(doc["a"] < doc["b"]); |  | ||||||
|     REQUIRE(doc["a"] <= doc["b"]); |  | ||||||
|     REQUIRE_FALSE(doc["a"] == doc["b"]); |  | ||||||
|     REQUIRE_FALSE(doc["a"] > doc["b"]); |  | ||||||
|     REQUIRE_FALSE(doc["a"] >= doc["b"]); |  | ||||||
|   } |  | ||||||
| } |  | ||||||
| @@ -1,27 +0,0 @@ | |||||||
| // ArduinoJson - arduinojson.org |  | ||||||
| // Copyright Benoit Blanchon 2014-2020 |  | ||||||
| // MIT License |  | ||||||
|  |  | ||||||
| #include <ArduinoJson.h> |  | ||||||
| #include <catch.hpp> |  | ||||||
|  |  | ||||||
| using namespace ARDUINOJSON_NAMESPACE; |  | ||||||
|  |  | ||||||
| TEST_CASE("MemberProxy::containsKey()") { |  | ||||||
|   DynamicJsonDocument doc(4096); |  | ||||||
|   MemberProxy<JsonDocument&, const char*> mp = doc["hello"]; |  | ||||||
|  |  | ||||||
|   SECTION("containsKey(const char*)") { |  | ||||||
|     mp["key"] = "value"; |  | ||||||
|  |  | ||||||
|     REQUIRE(mp.containsKey("key") == true); |  | ||||||
|     REQUIRE(mp.containsKey("key") == true); |  | ||||||
|   } |  | ||||||
|  |  | ||||||
|   SECTION("containsKey(std::string)") { |  | ||||||
|     mp["key"] = "value"; |  | ||||||
|  |  | ||||||
|     REQUIRE(mp.containsKey(std::string("key")) == true); |  | ||||||
|     REQUIRE(mp.containsKey(std::string("key")) == true); |  | ||||||
|   } |  | ||||||
| } |  | ||||||
| @@ -1,29 +0,0 @@ | |||||||
| // ArduinoJson - arduinojson.org |  | ||||||
| // Copyright Benoit Blanchon 2014-2020 |  | ||||||
| // MIT License |  | ||||||
|  |  | ||||||
| #include <ArduinoJson.h> |  | ||||||
| #include <catch.hpp> |  | ||||||
|  |  | ||||||
| using namespace ARDUINOJSON_NAMESPACE; |  | ||||||
|  |  | ||||||
| TEST_CASE("MemberProxy::operator|()") { |  | ||||||
|   DynamicJsonDocument doc(4096); |  | ||||||
|  |  | ||||||
|   SECTION("const char*") { |  | ||||||
|     doc["a"] = "hello"; |  | ||||||
|  |  | ||||||
|     REQUIRE((doc["a"] | "world") == std::string("hello")); |  | ||||||
|     REQUIRE((doc["b"] | "world") == std::string("world")); |  | ||||||
|   } |  | ||||||
|  |  | ||||||
|   SECTION("Issue #1411") { |  | ||||||
|     doc["sensor"] = "gps"; |  | ||||||
|  |  | ||||||
|     const char *test = "test";  // <- the literal must be captured in a variable |  | ||||||
|                                 // to trigger the bug |  | ||||||
|     const char *sensor = doc["sensor"] | test;  // "gps" |  | ||||||
|  |  | ||||||
|     REQUIRE(sensor == std::string("gps")); |  | ||||||
|   } |  | ||||||
| } |  | ||||||
| @@ -1,55 +0,0 @@ | |||||||
| // ArduinoJson - arduinojson.org |  | ||||||
| // Copyright Benoit Blanchon 2014-2020 |  | ||||||
| // MIT License |  | ||||||
|  |  | ||||||
| #include <ArduinoJson.h> |  | ||||||
| #include <catch.hpp> |  | ||||||
|  |  | ||||||
| using namespace ARDUINOJSON_NAMESPACE; |  | ||||||
|  |  | ||||||
| TEST_CASE("MemberProxy::remove()") { |  | ||||||
|   DynamicJsonDocument doc(4096); |  | ||||||
|   MemberProxy<JsonDocument&, const char*> mp = doc["hello"]; |  | ||||||
|  |  | ||||||
|   SECTION("remove(int)") { |  | ||||||
|     mp.add(1); |  | ||||||
|     mp.add(2); |  | ||||||
|     mp.add(3); |  | ||||||
|  |  | ||||||
|     mp.remove(1); |  | ||||||
|  |  | ||||||
|     REQUIRE(mp.as<std::string>() == "[1,3]"); |  | ||||||
|   } |  | ||||||
|  |  | ||||||
|   SECTION("remove(const char *)") { |  | ||||||
|     mp["a"] = 1; |  | ||||||
|     mp["b"] = 2; |  | ||||||
|  |  | ||||||
|     mp.remove("a"); |  | ||||||
|  |  | ||||||
|     REQUIRE(mp.as<std::string>() == "{\"b\":2}"); |  | ||||||
|   } |  | ||||||
|  |  | ||||||
|   SECTION("remove(std::string)") { |  | ||||||
|     mp["a"] = 1; |  | ||||||
|     mp["b"] = 2; |  | ||||||
|  |  | ||||||
|     mp.remove(std::string("b")); |  | ||||||
|  |  | ||||||
|     REQUIRE(mp.as<std::string>() == "{\"a\":1}"); |  | ||||||
|   } |  | ||||||
|  |  | ||||||
| #ifdef HAS_VARIABLE_LENGTH_ARRAY |  | ||||||
|   SECTION("remove(vla)") { |  | ||||||
|     mp["a"] = 1; |  | ||||||
|     mp["b"] = 2; |  | ||||||
|  |  | ||||||
|     int i = 4; |  | ||||||
|     char vla[i]; |  | ||||||
|     strcpy(vla, "b"); |  | ||||||
|     mp.remove(vla); |  | ||||||
|  |  | ||||||
|     REQUIRE(mp.as<std::string>() == "{\"a\":1}"); |  | ||||||
|   } |  | ||||||
| #endif |  | ||||||
| } |  | ||||||
| @@ -1,33 +0,0 @@ | |||||||
| // ArduinoJson - arduinojson.org |  | ||||||
| // Copyright Benoit Blanchon 2014-2020 |  | ||||||
| // MIT License |  | ||||||
|  |  | ||||||
| #include <ArduinoJson.h> |  | ||||||
| #include <catch.hpp> |  | ||||||
|  |  | ||||||
| using namespace ARDUINOJSON_NAMESPACE; |  | ||||||
|  |  | ||||||
| TEST_CASE("MemberProxy::set()") { |  | ||||||
|   DynamicJsonDocument doc(4096); |  | ||||||
|   MemberProxy<JsonDocument&, const char*> mp = doc["hello"]; |  | ||||||
|  |  | ||||||
|   SECTION("set(int)") { |  | ||||||
|     mp.set(42); |  | ||||||
|  |  | ||||||
|     REQUIRE(doc.as<std::string>() == "{\"hello\":42}"); |  | ||||||
|   } |  | ||||||
|  |  | ||||||
|   SECTION("set(const char*)") { |  | ||||||
|     mp.set("world"); |  | ||||||
|  |  | ||||||
|     REQUIRE(doc.as<std::string>() == "{\"hello\":\"world\"}"); |  | ||||||
|   } |  | ||||||
|  |  | ||||||
|   SECTION("set(char[])") {  // issue #1191 |  | ||||||
|     char s[] = "world"; |  | ||||||
|     mp.set(s); |  | ||||||
|     strcpy(s, "!!!!!"); |  | ||||||
|  |  | ||||||
|     REQUIRE(doc.as<std::string>() == "{\"hello\":\"world\"}"); |  | ||||||
|   } |  | ||||||
| } |  | ||||||
| @@ -1,31 +0,0 @@ | |||||||
| // ArduinoJson - arduinojson.org |  | ||||||
| // Copyright Benoit Blanchon 2014-2020 |  | ||||||
| // MIT License |  | ||||||
|  |  | ||||||
| #include <ArduinoJson.h> |  | ||||||
| #include <catch.hpp> |  | ||||||
|  |  | ||||||
| using namespace ARDUINOJSON_NAMESPACE; |  | ||||||
|  |  | ||||||
| TEST_CASE("MemberProxy::size()") { |  | ||||||
|   DynamicJsonDocument doc(4096); |  | ||||||
|   MemberProxy<JsonDocument&, const char*> mp = doc["hello"]; |  | ||||||
|  |  | ||||||
|   SECTION("returns 0") { |  | ||||||
|     REQUIRE(mp.size() == 0); |  | ||||||
|   } |  | ||||||
|  |  | ||||||
|   SECTION("as an array, return 2") { |  | ||||||
|     mp.add(1); |  | ||||||
|     mp.add(2); |  | ||||||
|  |  | ||||||
|     REQUIRE(mp.size() == 2); |  | ||||||
|   } |  | ||||||
|  |  | ||||||
|   SECTION("as an object, return 2") { |  | ||||||
|     mp["a"] = 1; |  | ||||||
|     mp["b"] = 2; |  | ||||||
|  |  | ||||||
|     REQUIRE(mp.size() == 2); |  | ||||||
|   } |  | ||||||
| } |  | ||||||
| @@ -1,25 +0,0 @@ | |||||||
| // ArduinoJson - arduinojson.org |  | ||||||
| // Copyright Benoit Blanchon 2014-2020 |  | ||||||
| // MIT License |  | ||||||
|  |  | ||||||
| #include <ArduinoJson.h> |  | ||||||
| #include <catch.hpp> |  | ||||||
|  |  | ||||||
| using namespace ARDUINOJSON_NAMESPACE; |  | ||||||
|  |  | ||||||
| TEST_CASE("MemberProxy::operator[]") { |  | ||||||
|   DynamicJsonDocument doc(4096); |  | ||||||
|   MemberProxy<JsonDocument&, const char*> mp = doc["hello"]; |  | ||||||
|  |  | ||||||
|   SECTION("set member") { |  | ||||||
|     mp["world"] = 42; |  | ||||||
|  |  | ||||||
|     REQUIRE(doc.as<std::string>() == "{\"hello\":{\"world\":42}}"); |  | ||||||
|   } |  | ||||||
|  |  | ||||||
|   SECTION("set element") { |  | ||||||
|     mp[2] = 42; |  | ||||||
|  |  | ||||||
|     REQUIRE(doc.as<std::string>() == "{\"hello\":[null,null,42]}"); |  | ||||||
|   } |  | ||||||
| } |  | ||||||
		Reference in New Issue
	
	Block a user