mirror of
				https://github.com/eledio-devices/thirdparty-ArduinoJson.git
				synced 2025-10-31 08:42:39 +01:00 
			
		
		
		
	
		
			
				
	
	
		
			54 lines
		
	
	
		
			1.3 KiB
		
	
	
	
		
			C++
		
	
	
	
	
	
			
		
		
	
	
			54 lines
		
	
	
		
			1.3 KiB
		
	
	
	
		
			C++
		
	
	
	
	
	
| // Copyright Benoit Blanchon 2014-2017
 | |
| // MIT License
 | |
| //
 | |
| // Arduino JSON library
 | |
| // https://bblanchon.github.io/ArduinoJson/
 | |
| // If you like this project, please add a star!
 | |
| 
 | |
| #include <ArduinoJson.h>
 | |
| #include <catch.hpp>
 | |
| 
 | |
| using namespace ArduinoJson::Internals;
 | |
| 
 | |
| template <typename StringBuilder, typename String>
 | |
| void common_tests(StringBuilder& sb, const String& output) {
 | |
|   SECTION("InitialState") {
 | |
|     REQUIRE(std::string("") == output);
 | |
|   }
 | |
| 
 | |
|   SECTION("EmptyString") {
 | |
|     REQUIRE(0 == sb.print(""));
 | |
|     REQUIRE(std::string("") == output);
 | |
|   }
 | |
| 
 | |
|   SECTION("OneString") {
 | |
|     REQUIRE(4 == sb.print("ABCD"));
 | |
|     REQUIRE(std::string("ABCD") == output);
 | |
|   }
 | |
| 
 | |
|   SECTION("TwoStrings") {
 | |
|     REQUIRE(4 == sb.print("ABCD"));
 | |
|     REQUIRE(4 == sb.print("EFGH"));
 | |
|     REQUIRE(std::string("ABCDEFGH") == output);
 | |
|   }
 | |
| }
 | |
| 
 | |
| TEST_CASE("StaticStringBuilder") {
 | |
|   char output[20];
 | |
|   StaticStringBuilder sb(output, sizeof(output));
 | |
| 
 | |
|   common_tests(sb, static_cast<const char*>(output));
 | |
| 
 | |
|   SECTION("OverCapacity") {
 | |
|     REQUIRE(19 == sb.print("ABCDEFGHIJKLMNOPQRSTUVWXYZ"));
 | |
|     REQUIRE(0 == sb.print("ABC"));
 | |
|     REQUIRE(std::string("ABCDEFGHIJKLMNOPQRS") == output);
 | |
|   }
 | |
| }
 | |
| 
 | |
| TEST_CASE("DynamicStringBuilder") {
 | |
|   std::string output;
 | |
|   DynamicStringBuilder<std::string> sb(output);
 | |
|   common_tests(sb, output);
 | |
| }
 |