Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
R
rapidjson
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
submodule
rapidjson
Commits
056d0daf
Commit
056d0daf
authored
Sep 01, 2014
by
Kosta
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add unit test for testing edge cases of the `short string optimization`
parent
697cf407
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
23 additions
and
0 deletions
+23
-0
valuetest.cpp
test/unittest/valuetest.cpp
+23
-0
No files found.
test/unittest/valuetest.cpp
View file @
056d0daf
...
...
@@ -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)
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment