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

@ -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") {