mirror of
				https://github.com/eledio-devices/thirdparty-ArduinoJson.git
				synced 2025-10-31 16:14:11 +01:00 
			
		
		
		
	Added JsonArray::clear() (fixes #1597)
This commit is contained in:
		| @@ -11,6 +11,7 @@ HEAD | |||||||
| * Added fake class `InvalidConversion<T1,T2>` to easily identify invalid conversions (issue #1585) | * Added fake class `InvalidConversion<T1,T2>` to easily identify invalid conversions (issue #1585) | ||||||
| * Added support for `std::string_view` (issue #1578, PR #1554 by @0xFEEDC0DE64) | * Added support for `std::string_view` (issue #1578, PR #1554 by @0xFEEDC0DE64) | ||||||
| * Fixed warning `definition of implicit copy constructor for 'MsgPackDeserializer' is deprecated because it has a user-declared copy assignment operator` | * Fixed warning `definition of implicit copy constructor for 'MsgPackDeserializer' is deprecated because it has a user-declared copy assignment operator` | ||||||
|  | * Added `JsonArray::clear()` (issue #1597) | ||||||
|  |  | ||||||
| v6.18.0 (2021-05-05) | v6.18.0 (2021-05-05) | ||||||
| ------- | ------- | ||||||
|   | |||||||
| @@ -4,6 +4,7 @@ | |||||||
|  |  | ||||||
| add_executable(JsonArrayTests  | add_executable(JsonArrayTests  | ||||||
| 	add.cpp | 	add.cpp | ||||||
|  | 	clear.cpp | ||||||
| 	copyArray.cpp | 	copyArray.cpp | ||||||
| 	createNested.cpp | 	createNested.cpp | ||||||
| 	equals.cpp | 	equals.cpp | ||||||
|   | |||||||
							
								
								
									
										25
									
								
								extras/tests/JsonArray/clear.cpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										25
									
								
								extras/tests/JsonArray/clear.cpp
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,25 @@ | |||||||
|  | // ArduinoJson - https://arduinojson.org | ||||||
|  | // Copyright Benoit Blanchon 2014-2021 | ||||||
|  | // MIT License | ||||||
|  |  | ||||||
|  | #include <ArduinoJson.h> | ||||||
|  | #include <catch.hpp> | ||||||
|  |  | ||||||
|  | TEST_CASE("JsonArray::clear()") { | ||||||
|  |   SECTION("No-op on null JsonArray") { | ||||||
|  |     JsonArray array; | ||||||
|  |     array.clear(); | ||||||
|  |     REQUIRE(array.isNull() == true); | ||||||
|  |     REQUIRE(array.size() == 0); | ||||||
|  |   } | ||||||
|  |  | ||||||
|  |   SECTION("Removes all elements") { | ||||||
|  |     StaticJsonDocument<64> doc; | ||||||
|  |     JsonArray array = doc.to<JsonArray>(); | ||||||
|  |     array.add(1); | ||||||
|  |     array.add(2); | ||||||
|  |     array.clear(); | ||||||
|  |     REQUIRE(array.size() == 0); | ||||||
|  |     REQUIRE(array.isNull() == false); | ||||||
|  |   } | ||||||
|  | } | ||||||
| @@ -3,6 +3,7 @@ | |||||||
| # MIT License | # MIT License | ||||||
|  |  | ||||||
| add_executable(JsonObjectTests  | add_executable(JsonObjectTests  | ||||||
|  | 	clear.cpp | ||||||
| 	containsKey.cpp | 	containsKey.cpp | ||||||
| 	copy.cpp | 	copy.cpp | ||||||
| 	createNestedArray.cpp | 	createNestedArray.cpp | ||||||
|   | |||||||
							
								
								
									
										25
									
								
								extras/tests/JsonObject/clear.cpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										25
									
								
								extras/tests/JsonObject/clear.cpp
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,25 @@ | |||||||
|  | // ArduinoJson - https://arduinojson.org | ||||||
|  | // Copyright Benoit Blanchon 2014-2021 | ||||||
|  | // MIT License | ||||||
|  |  | ||||||
|  | #include <ArduinoJson.h> | ||||||
|  | #include <catch.hpp> | ||||||
|  |  | ||||||
|  | TEST_CASE("JsonObject::clear()") { | ||||||
|  |   SECTION("No-op on null JsonObject") { | ||||||
|  |     JsonObject obj; | ||||||
|  |     obj.clear(); | ||||||
|  |     REQUIRE(obj.isNull() == true); | ||||||
|  |     REQUIRE(obj.size() == 0); | ||||||
|  |   } | ||||||
|  |  | ||||||
|  |   SECTION("Removes all elements") { | ||||||
|  |     StaticJsonDocument<64> doc; | ||||||
|  |     JsonObject obj = doc.to<JsonObject>(); | ||||||
|  |     obj["hello"] = 1; | ||||||
|  |     obj["world"] = 2; | ||||||
|  |     obj.clear(); | ||||||
|  |     REQUIRE(obj.size() == 0); | ||||||
|  |     REQUIRE(obj.isNull() == false); | ||||||
|  |   } | ||||||
|  | } | ||||||
| @@ -161,6 +161,12 @@ class ArrayRef : public ArrayRefBase<CollectionData>, | |||||||
|     _data->removeElement(index); |     _data->removeElement(index); | ||||||
|   } |   } | ||||||
|  |  | ||||||
|  |   void clear() const { | ||||||
|  |     if (!_data) | ||||||
|  |       return; | ||||||
|  |     _data->clear(); | ||||||
|  |   } | ||||||
|  |  | ||||||
|  private: |  private: | ||||||
|   MemoryPool* _pool; |   MemoryPool* _pool; | ||||||
| }; | }; | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user