mirror of
				https://github.com/eledio-devices/thirdparty-ArduinoJson.git
				synced 2025-10-31 16:14:11 +01:00 
			
		
		
		
	
		
			
				
	
	
		
			36 lines
		
	
	
		
			929 B
		
	
	
	
		
			C++
		
	
	
	
	
	
			
		
		
	
	
			36 lines
		
	
	
		
			929 B
		
	
	
	
		
			C++
		
	
	
	
	
	
| // ArduinoJson - arduinojson.org
 | |
| // Copyright Benoit Blanchon 2014-2018
 | |
| // MIT License
 | |
| 
 | |
| #include <ArduinoJson.h>
 | |
| #include <catch.hpp>
 | |
| 
 | |
| TEST_CASE("deserializeJson(const std::string&)") {
 | |
|   DynamicJsonDocument doc;
 | |
| 
 | |
|   SECTION("should accept const string") {
 | |
|     const std::string input("[42]");
 | |
| 
 | |
|     DeserializationError err = deserializeJson(doc, input);
 | |
| 
 | |
|     REQUIRE(err == DeserializationError::Ok);
 | |
|   }
 | |
| 
 | |
|   SECTION("should accept temporary string") {
 | |
|     DeserializationError err = deserializeJson(doc, std::string("[42]"));
 | |
| 
 | |
|     REQUIRE(err == DeserializationError::Ok);
 | |
|   }
 | |
| 
 | |
|   SECTION("should duplicate content") {
 | |
|     std::string input("[\"hello\"]");
 | |
| 
 | |
|     DeserializationError err = deserializeJson(doc, input);
 | |
|     input[2] = 'X';  // alter the string tomake sure we made a copy
 | |
| 
 | |
|     JsonArray &array = doc.as<JsonArray>();
 | |
|     REQUIRE(err == DeserializationError::Ok);
 | |
|     REQUIRE(std::string("hello") == array[0]);
 | |
|   }
 | |
| }
 |