Skip to content

Commit 61b60c3

Browse files
committed
test
Signed-off-by: Abhijat Malviya <[email protected]>
1 parent 3ff681f commit 61b60c3

File tree

1 file changed

+25
-5
lines changed

1 file changed

+25
-5
lines changed

src/core/compact_object_test.cc

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -444,16 +444,25 @@ TEST_F(CompactObjectTest, MimallocUnderutilzationWithRealloc) {
444444
}
445445
}
446446

447-
TEST_F(CompactObjectTest, JsonTypeTest) {
448-
using namespace jsoncons;
449-
// This test verify that we can set a json type
450-
// and that we "know", it JSON and not a string
451-
std::string_view json_str = R"(
447+
namespace {
448+
std::string_view json_str = R"(
452449
{"firstName":"John","lastName":"Smith","age":27,"weight":135.25,"isAlive":true,
453450
"address":{"street":"21 2nd Street","city":"New York","state":"NY","zipcode":"10021-3100"},
454451
"phoneNumbers":[{"type":"home","number":"212 555-1234"},{"type":"office","number":"646 555-4567"}],
455452
"children":[],"spouse":null}
456453
)";
454+
455+
size_t JsonSize(const JsonType& j) {
456+
return j.compute_memory_size([](const auto* p) { return p ? mi_usable_size(p) : 0; });
457+
}
458+
459+
} // namespace
460+
461+
TEST_F(CompactObjectTest, JsonTypeTest) {
462+
using namespace jsoncons;
463+
// This test verify that we can set a json type
464+
// and that we "know", it JSON and not a string
465+
457466
std::optional<JsonType> json_option2 =
458467
JsonFromString(R"({"a":{}, "b":{"a":1}, "c":{"a":1, "b":2}})", CompactObj::memory_resource());
459468

@@ -599,6 +608,17 @@ TEST_F(CompactObjectTest, DefragSet) {
599608
ASSERT_FALSE(cobj_.DefragIfNeeded(&page_usage));
600609
}
601610

611+
TEST_F(CompactObjectTest, DefragJsonCons) {
612+
std::optional<JsonType> json_option = JsonFromString(json_str, CompactObj::memory_resource());
613+
ASSERT_TRUE(json_option.has_value());
614+
cobj_.SetJson(std::move(json_option.value()));
615+
616+
PageUsage page_usage{CollectPageStats::YES, 0.1};
617+
page_usage.SetForceReallocate(true);
618+
619+
cobj_.DefragIfNeeded(&page_usage);
620+
}
621+
602622
TEST_F(CompactObjectTest, StrEncodingAndMaterialize) {
603623
for (bool ascii : {true, false}) {
604624
for (size_t len : {64, 128, 256, 512, 1024}) {

0 commit comments

Comments
 (0)