mirror of
				https://github.com/eledio-devices/thirdparty-ArduinoJson.git
				synced 2025-10-31 16:14:11 +01:00 
			
		
		
		
	Refactored StringBuilder into StringStorage
This commit is contained in:
		| @@ -7,7 +7,7 @@ add_executable(MemoryPoolTests | ||||
| 	allocString.cpp | ||||
| 	clear.cpp | ||||
| 	size.cpp | ||||
| 	StringBuilder.cpp | ||||
| 	StringCopier.cpp | ||||
| ) | ||||
|  | ||||
| add_test(MemoryPool MemoryPoolTests) | ||||
|   | ||||
| @@ -2,40 +2,44 @@ | ||||
| // Copyright Benoit Blanchon 2014-2020
 | ||||
| // MIT License
 | ||||
| 
 | ||||
| #include <ArduinoJson/Memory/MemoryPool.hpp> | ||||
| #include <ArduinoJson/Memory/StringBuilder.hpp> | ||||
| #include <ArduinoJson/StringStorage/StringCopier.hpp> | ||||
| #include <catch.hpp> | ||||
| 
 | ||||
| using namespace ARDUINOJSON_NAMESPACE; | ||||
| 
 | ||||
| TEST_CASE("StringBuilder") { | ||||
| TEST_CASE("StringCopier") { | ||||
|   char buffer[4096]; | ||||
| 
 | ||||
|   SECTION("Works when buffer is big enough") { | ||||
|     MemoryPool pool(buffer, addPadding(JSON_STRING_SIZE(6))); | ||||
|     StringCopier str; | ||||
| 
 | ||||
|     StringBuilder str(&pool); | ||||
|     str.startString(&pool); | ||||
|     str.append("hello"); | ||||
|     str.append('\0'); | ||||
| 
 | ||||
|     REQUIRE(str.complete() == std::string("hello")); | ||||
|     REQUIRE(str.isValid() == true); | ||||
|     REQUIRE(str.c_str() == std::string("hello")); | ||||
|   } | ||||
| 
 | ||||
|   SECTION("Returns null when too small") { | ||||
|     MemoryPool pool(buffer, sizeof(void*)); | ||||
|     StringCopier str; | ||||
| 
 | ||||
|     StringBuilder str(&pool); | ||||
|     str.startString(&pool); | ||||
|     str.append("hello world!"); | ||||
| 
 | ||||
|     REQUIRE(str.complete() == 0); | ||||
|     REQUIRE(str.isValid() == false); | ||||
|   } | ||||
| 
 | ||||
|   SECTION("Increases size of memory pool") { | ||||
|     MemoryPool pool(buffer, addPadding(JSON_STRING_SIZE(6))); | ||||
|     StringCopier str; | ||||
| 
 | ||||
|     StringBuilder str(&pool); | ||||
|     str.startString(&pool); | ||||
|     str.append('h'); | ||||
|     str.complete(); | ||||
|     str.commit(&pool); | ||||
| 
 | ||||
|     REQUIRE(JSON_STRING_SIZE(1) == pool.size()); | ||||
|     REQUIRE(1 == pool.size()); | ||||
|   } | ||||
| } | ||||
| @@ -22,11 +22,6 @@ TEST_CASE("MemoryPool::size()") { | ||||
|     REQUIRE(0 == pool.size()); | ||||
|   } | ||||
|  | ||||
|   SECTION("size() == capacity() after allocExpandableString()") { | ||||
|     pool.allocExpandableString(); | ||||
|     REQUIRE(pool.size() == pool.capacity()); | ||||
|   } | ||||
|  | ||||
|   SECTION("Decreases after freezeString()") { | ||||
|     StringSlot a = pool.allocExpandableString(); | ||||
|     pool.freezeString(a, 1); | ||||
|   | ||||
		Reference in New Issue
	
	Block a user