Fixed object keys not being duplicated

This commit is contained in:
Benoit Blanchon
2018-10-04 11:16:23 +02:00
parent 527dc19794
commit 6b985b2d1f
30 changed files with 368 additions and 218 deletions

View File

@ -17,6 +17,8 @@ struct NoMemoryAllocator {
TEST_CASE("DynamicMemoryPool no memory") {
DynamicMemoryPoolBase<NoMemoryAllocator> _memoryPool;
typedef DynamicMemoryPoolBase<NoMemoryAllocator>::StringBuilder StringBuilder;
SECTION("FixCodeCoverage") {
// call this function to fix code coverage
NoMemoryAllocator().deallocate(NULL);
@ -33,9 +35,8 @@ TEST_CASE("DynamicMemoryPool no memory") {
// }
SECTION("startString()") {
DynamicMemoryPoolBase<NoMemoryAllocator>::String str =
_memoryPool.startString();
StringBuilder str = _memoryPool.startString();
str.append('!');
REQUIRE(0 == str.c_str());
REQUIRE(str.complete().isNull());
}
}

View File

@ -7,43 +7,45 @@
using namespace ARDUINOJSON_NAMESPACE;
typedef DynamicMemoryPool::StringBuilder StringBuilder;
TEST_CASE("DynamicMemoryPool::startString()") {
SECTION("WorksWhenBufferIsBigEnough") {
DynamicMemoryPool memoryPool(6);
DynamicMemoryPool::String str = memoryPool.startString();
StringBuilder str = memoryPool.startString();
str.append('h');
str.append('e');
str.append('l');
str.append('l');
str.append('o');
REQUIRE(std::string("hello") == str.c_str());
REQUIRE(str.complete().equals("hello"));
}
SECTION("GrowsWhenBufferIsTooSmall") {
DynamicMemoryPool memoryPool(5);
DynamicMemoryPool::String str = memoryPool.startString();
StringBuilder str = memoryPool.startString();
str.append('h');
str.append('e');
str.append('l');
str.append('l');
str.append('o');
REQUIRE(std::string("hello") == str.c_str());
REQUIRE(str.complete().equals("hello"));
}
SECTION("SizeIncreases") {
DynamicMemoryPool memoryPool(5);
DynamicMemoryPool::String str = memoryPool.startString();
StringBuilder str = memoryPool.startString();
REQUIRE(0 == memoryPool.size());
str.append('h');
REQUIRE(1 == memoryPool.size());
str.c_str();
str.complete();
REQUIRE(2 == memoryPool.size());
}
}