mirror of
https://github.com/Tencent/rapidjson.git
synced 2025-03-09 19:24:23 +01:00
add unit test for testing edge cases of the short string optimization
This commit is contained in:
parent
697cf407c2
commit
056d0dafe4
@ -1084,3 +1084,26 @@ TEST(Document, CrtAllocator) {
|
||||
V a(kArrayType);
|
||||
a.PushBack(1, allocator); // Should not call destructor on uninitialized Value of newly allocated elements.
|
||||
}
|
||||
|
||||
static void TestShortStringOptimization(const char* str) {
|
||||
const int len = (int)strlen(str);
|
||||
|
||||
rapidjson::Document doc;
|
||||
rapidjson::Document::AllocatorType& allocator = doc.GetAllocator();
|
||||
rapidjson::Value objVal(rapidjson::kObjectType);
|
||||
|
||||
objVal.AddMember(str, str, allocator);
|
||||
EXPECT_TRUE(objVal.HasMember(str));
|
||||
|
||||
const rapidjson::Value& member = objVal[str];
|
||||
EXPECT_EQ(member.GetStringLength(), strlen(str));
|
||||
}
|
||||
|
||||
TEST(Value, AllocateShortString) {
|
||||
TestShortStringOptimization(""); // edge case: empty string
|
||||
TestShortStringOptimization("12345678"); // regular case for short strings: 8 chars
|
||||
TestShortStringOptimization("12345678901"); // edge case: 11 chars in 32-bit mode (=> short string)
|
||||
TestShortStringOptimization("123456789012"); // edge case: 12 chars in 32-bit mode (=> regular string)
|
||||
TestShortStringOptimization("123456789012345"); // edge case: 15 chars in 64-bit mode (=> short string)
|
||||
TestShortStringOptimization("1234567890123456"); // edge case: 16 chars in 64-bit mode (=> regular string)
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user