Test capacity after calling BasicJsonDocument's copy assignment

This commit is contained in:
Benoit Blanchon
2021-12-16 14:28:30 +01:00
parent abdd9d81db
commit 3166356484
2 changed files with 8 additions and 8 deletions

View File

@ -14,7 +14,8 @@ HEAD
* Remove `DeserializationError == bool` and `DeserializationError != bool`
* Fix `JsonVariant::memoryUsage()` for raw strings
* Fix `call of overloaded 'swap(BasicJsonDocument&, BasicJsonDocument&)' is ambiguous` (issue #1678)
* Fix inconsistent pool size in `BasicJsonDocument`'s copy constructor
* Fix inconsistent pool capacity between `BasicJsonDocument`'s copy and move constructors
* Fix inconsistent pool capacity between `BasicJsonDocument`'s copy and move assignments
* Fix return type of `StaticJsonDocument::operator=`
v6.18.5 (2021-09-28)

View File

@ -138,27 +138,26 @@ TEST_CASE("DynamicJsonDocument constructor") {
}
TEST_CASE("DynamicJsonDocument assignment") {
SECTION("Copy assignment preserves the buffer when capacity is sufficient") {
SECTION("Copy assignment reallocates when capacity is smaller") {
DynamicJsonDocument doc1(1234);
deserializeJson(doc1, "{\"hello\":\"world\"}");
DynamicJsonDocument doc2(8);
DynamicJsonDocument doc2(doc1.capacity());
doc2 = doc1;
REQUIRE_JSON(doc2, "{\"hello\":\"world\"}");
REQUIRE(doc2.capacity() == doc1.capacity());
}
SECTION("Copy assignment realloc the buffer when capacity is insufficient") {
DynamicJsonDocument doc1(1234);
SECTION("Copy assignment reallocates when capacity is larger") {
DynamicJsonDocument doc1(100);
deserializeJson(doc1, "{\"hello\":\"world\"}");
DynamicJsonDocument doc2(8);
DynamicJsonDocument doc2(1234);
REQUIRE(doc2.capacity() < doc1.memoryUsage());
doc2 = doc1;
REQUIRE(doc2.capacity() >= doc1.memoryUsage());
REQUIRE_JSON(doc2, "{\"hello\":\"world\"}");
REQUIRE(doc2.capacity() == doc1.capacity());
}
SECTION("Assign from StaticJsonDocument") {