2021-03-29 17:14:01 +02:00
|
|
|
// ArduinoJson - https://arduinojson.org
|
2024-01-03 08:47:06 +01:00
|
|
|
// Copyright © 2014-2024, Benoit BLANCHON
|
2019-02-25 11:44:22 +01:00
|
|
|
// MIT License
|
|
|
|
|
|
|
|
#include <ArduinoJson.h>
|
|
|
|
#include <stdint.h>
|
|
|
|
#include <catch.hpp>
|
|
|
|
|
2023-07-24 17:21:25 +02:00
|
|
|
#include "Allocators.hpp"
|
2024-06-07 09:35:45 +02:00
|
|
|
#include "Literals.hpp"
|
2023-07-24 17:21:25 +02:00
|
|
|
|
2019-02-25 11:44:22 +01:00
|
|
|
TEST_CASE("JsonVariant::clear()") {
|
2023-07-25 14:53:54 +02:00
|
|
|
SpyingAllocator spy;
|
|
|
|
JsonDocument doc(&spy);
|
2019-02-25 11:44:22 +01:00
|
|
|
JsonVariant var = doc.to<JsonVariant>();
|
|
|
|
|
|
|
|
SECTION("size goes back to zero") {
|
|
|
|
var.add(42);
|
|
|
|
var.clear();
|
|
|
|
|
|
|
|
REQUIRE(var.size() == 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
SECTION("isNull() return true") {
|
|
|
|
var.add("hello");
|
|
|
|
var.clear();
|
|
|
|
|
|
|
|
REQUIRE(var.isNull() == true);
|
|
|
|
}
|
2023-04-17 09:46:41 +02:00
|
|
|
|
|
|
|
SECTION("releases owned string") {
|
2024-06-07 09:35:45 +02:00
|
|
|
var.set("hello"_s);
|
2023-04-17 09:46:41 +02:00
|
|
|
var.clear();
|
2023-07-24 17:21:25 +02:00
|
|
|
|
2023-07-26 06:06:38 +02:00
|
|
|
REQUIRE(spy.log() == AllocatorLog{
|
|
|
|
Allocate(sizeofString("hello")),
|
|
|
|
Deallocate(sizeofString("hello")),
|
|
|
|
});
|
2023-04-17 09:46:41 +02:00
|
|
|
}
|
2019-02-25 11:44:22 +01:00
|
|
|
}
|