mirror of
				https://github.com/eledio-devices/thirdparty-ArduinoJson.git
				synced 2025-10-31 08:42:39 +01:00 
			
		
		
		
	JsonVariant: add tests for size()
				
					
				
			This commit is contained in:
		| @@ -8,8 +8,8 @@ add_executable(JsonVariantTests | |||||||
| 	clear.cpp | 	clear.cpp | ||||||
| 	compare.cpp | 	compare.cpp | ||||||
| 	containsKey.cpp | 	containsKey.cpp | ||||||
| 	copy.cpp |  | ||||||
| 	converters.cpp | 	converters.cpp | ||||||
|  | 	copy.cpp | ||||||
| 	createNested.cpp | 	createNested.cpp | ||||||
| 	is.cpp | 	is.cpp | ||||||
| 	isnull.cpp | 	isnull.cpp | ||||||
| @@ -20,6 +20,7 @@ add_executable(JsonVariantTests | |||||||
| 	overflow.cpp | 	overflow.cpp | ||||||
| 	remove.cpp | 	remove.cpp | ||||||
| 	set.cpp | 	set.cpp | ||||||
|  | 	size.cpp | ||||||
| 	subscript.cpp | 	subscript.cpp | ||||||
| 	types.cpp | 	types.cpp | ||||||
| 	unbound.cpp | 	unbound.cpp | ||||||
|   | |||||||
							
								
								
									
										44
									
								
								extras/tests/JsonVariant/size.cpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										44
									
								
								extras/tests/JsonVariant/size.cpp
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,44 @@ | |||||||
|  | // ArduinoJson - https://arduinojson.org | ||||||
|  | // Copyright © 2014-2022, Benoit BLANCHON | ||||||
|  | // MIT License | ||||||
|  |  | ||||||
|  | #include <ArduinoJson.h> | ||||||
|  | #include <catch.hpp> | ||||||
|  |  | ||||||
|  | TEST_CASE("JsonVariant::size()") { | ||||||
|  |   DynamicJsonDocument doc(4096); | ||||||
|  |   JsonVariant variant = doc.to<JsonVariant>(); | ||||||
|  |  | ||||||
|  |   SECTION("unbound reference") { | ||||||
|  |     JsonVariant unbound; | ||||||
|  |  | ||||||
|  |     CHECK(unbound.size() == 0); | ||||||
|  |   } | ||||||
|  |  | ||||||
|  |   SECTION("int") { | ||||||
|  |     variant.set(42); | ||||||
|  |  | ||||||
|  |     CHECK(variant.size() == 0); | ||||||
|  |   } | ||||||
|  |  | ||||||
|  |   SECTION("string") { | ||||||
|  |     variant.set("hello"); | ||||||
|  |  | ||||||
|  |     CHECK(variant.size() == 0); | ||||||
|  |   } | ||||||
|  |  | ||||||
|  |   SECTION("object") { | ||||||
|  |     variant["a"] = 1; | ||||||
|  |     variant["b"] = 2; | ||||||
|  |  | ||||||
|  |     CHECK(variant.size() == 2); | ||||||
|  |   } | ||||||
|  |  | ||||||
|  |   SECTION("linked object") { | ||||||
|  |     StaticJsonDocument<1024> doc2; | ||||||
|  |     doc2["hello"] = "world"; | ||||||
|  |     variant.link(doc2); | ||||||
|  |  | ||||||
|  |     CHECK(variant.size() == 1); | ||||||
|  |   } | ||||||
|  | } | ||||||
		Reference in New Issue
	
	Block a user