forked from bblanchon/ArduinoJson
Test capacity after calling BasicJsonDocument
's copy assignment
This commit is contained in:
@ -14,7 +14,8 @@ HEAD
|
|||||||
* Remove `DeserializationError == bool` and `DeserializationError != bool`
|
* Remove `DeserializationError == bool` and `DeserializationError != bool`
|
||||||
* Fix `JsonVariant::memoryUsage()` for raw strings
|
* Fix `JsonVariant::memoryUsage()` for raw strings
|
||||||
* Fix `call of overloaded 'swap(BasicJsonDocument&, BasicJsonDocument&)' is ambiguous` (issue #1678)
|
* 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=`
|
* Fix return type of `StaticJsonDocument::operator=`
|
||||||
|
|
||||||
v6.18.5 (2021-09-28)
|
v6.18.5 (2021-09-28)
|
||||||
|
@ -138,27 +138,26 @@ TEST_CASE("DynamicJsonDocument constructor") {
|
|||||||
}
|
}
|
||||||
|
|
||||||
TEST_CASE("DynamicJsonDocument assignment") {
|
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);
|
DynamicJsonDocument doc1(1234);
|
||||||
deserializeJson(doc1, "{\"hello\":\"world\"}");
|
deserializeJson(doc1, "{\"hello\":\"world\"}");
|
||||||
|
DynamicJsonDocument doc2(8);
|
||||||
|
|
||||||
DynamicJsonDocument doc2(doc1.capacity());
|
|
||||||
doc2 = doc1;
|
doc2 = doc1;
|
||||||
|
|
||||||
REQUIRE_JSON(doc2, "{\"hello\":\"world\"}");
|
REQUIRE_JSON(doc2, "{\"hello\":\"world\"}");
|
||||||
REQUIRE(doc2.capacity() == doc1.capacity());
|
REQUIRE(doc2.capacity() == doc1.capacity());
|
||||||
}
|
}
|
||||||
|
|
||||||
SECTION("Copy assignment realloc the buffer when capacity is insufficient") {
|
SECTION("Copy assignment reallocates when capacity is larger") {
|
||||||
DynamicJsonDocument doc1(1234);
|
DynamicJsonDocument doc1(100);
|
||||||
deserializeJson(doc1, "{\"hello\":\"world\"}");
|
deserializeJson(doc1, "{\"hello\":\"world\"}");
|
||||||
DynamicJsonDocument doc2(8);
|
DynamicJsonDocument doc2(1234);
|
||||||
|
|
||||||
REQUIRE(doc2.capacity() < doc1.memoryUsage());
|
|
||||||
doc2 = doc1;
|
doc2 = doc1;
|
||||||
REQUIRE(doc2.capacity() >= doc1.memoryUsage());
|
|
||||||
|
|
||||||
REQUIRE_JSON(doc2, "{\"hello\":\"world\"}");
|
REQUIRE_JSON(doc2, "{\"hello\":\"world\"}");
|
||||||
|
REQUIRE(doc2.capacity() == doc1.capacity());
|
||||||
}
|
}
|
||||||
|
|
||||||
SECTION("Assign from StaticJsonDocument") {
|
SECTION("Assign from StaticJsonDocument") {
|
||||||
|
Reference in New Issue
Block a user