mirror of
				https://github.com/eledio-devices/thirdparty-ArduinoJson.git
				synced 2025-10-31 08:42:39 +01:00 
			
		
		
		
	* Added DynamicJsonArray and StaticJsonArray * Added DynamicJsonObject and StaticJsonObject * Added DynamicJsonVariant and StaticJsonVariant * Added deserializeJson() * Removed JsonBuffer::parseArray(), parseObject() and parse() * Removed JsonBuffer::createArray() and createObject()
		
			
				
	
	
		
			60 lines
		
	
	
		
			1.4 KiB
		
	
	
	
		
			C++
		
	
	
	
	
	
			
		
		
	
	
			60 lines
		
	
	
		
			1.4 KiB
		
	
	
	
		
			C++
		
	
	
	
	
	
| // ArduinoJson - arduinojson.org
 | |
| // Copyright Benoit Blanchon 2014-2018
 | |
| // MIT License
 | |
| 
 | |
| #include <ArduinoJson.h>
 | |
| #include <catch.hpp>
 | |
| 
 | |
| TEST_CASE("JsonArray::copyFrom()") {
 | |
|   SECTION("OneDimension") {
 | |
|     DynamicJsonArray array;
 | |
|     char json[32];
 | |
|     int source[] = {1, 2, 3};
 | |
| 
 | |
|     bool ok = array.copyFrom(source);
 | |
|     REQUIRE(ok);
 | |
| 
 | |
|     array.printTo(json, sizeof(json));
 | |
|     REQUIRE(std::string("[1,2,3]") == json);
 | |
|   }
 | |
| 
 | |
|   SECTION("OneDimension_JsonBufferTooSmall") {
 | |
|     const size_t SIZE = JSON_ARRAY_SIZE(2);
 | |
|     StaticJsonArray<SIZE> array;
 | |
|     char json[32];
 | |
|     int source[] = {1, 2, 3};
 | |
| 
 | |
|     bool ok = array.copyFrom(source);
 | |
|     REQUIRE_FALSE(ok);
 | |
| 
 | |
|     array.printTo(json, sizeof(json));
 | |
|     REQUIRE(std::string("[1,2]") == json);
 | |
|   }
 | |
| 
 | |
|   SECTION("TwoDimensions") {
 | |
|     DynamicJsonArray array;
 | |
|     char json[32];
 | |
|     int source[][3] = {{1, 2, 3}, {4, 5, 6}};
 | |
| 
 | |
|     bool ok = array.copyFrom(source);
 | |
|     REQUIRE(ok);
 | |
| 
 | |
|     array.printTo(json, sizeof(json));
 | |
|     REQUIRE(std::string("[[1,2,3],[4,5,6]]") == json);
 | |
|   }
 | |
| 
 | |
|   SECTION("TwoDimensions_JsonBufferTooSmall") {
 | |
|     const size_t SIZE =
 | |
|         JSON_ARRAY_SIZE(2) + JSON_ARRAY_SIZE(3) + JSON_ARRAY_SIZE(2);
 | |
|     StaticJsonArray<SIZE> array;
 | |
|     char json[32];
 | |
|     int source[][3] = {{1, 2, 3}, {4, 5, 6}};
 | |
| 
 | |
|     bool ok = array.copyFrom(source);
 | |
|     REQUIRE_FALSE(ok);
 | |
| 
 | |
|     array.printTo(json, sizeof(json));
 | |
|     REQUIRE(std::string("[[1,2,3],[4,5]]") == json);
 | |
|   }
 | |
| }
 |