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
1d3070fb
Commit
1d3070fb
authored
Oct 31, 2014
by
Milo Yip
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #184 from drewnoakes/master
Add unit tests for StringBuffer
parents
4fa43bd4
0bfd0a52
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
113 additions
and
0 deletions
+113
-0
stringbuffertest.cpp
test/unittest/stringbuffertest.cpp
+113
-0
No files found.
test/unittest/stringbuffertest.cpp
0 → 100644
View file @
1d3070fb
// Copyright (C) 2011 Milo Yip
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
#include "unittest.h"
#include "rapidjson/stringbuffer.h"
#include "rapidjson/writer.h"
using
namespace
rapidjson
;
TEST
(
StringBuffer
,
InitialSize
)
{
StringBuffer
buffer
;
EXPECT_EQ
(
0u
,
buffer
.
GetSize
());
EXPECT_STREQ
(
""
,
buffer
.
GetString
());
}
TEST
(
StringBuffer
,
Put
)
{
StringBuffer
buffer
;
buffer
.
Put
(
'A'
);
EXPECT_EQ
(
1u
,
buffer
.
GetSize
());
EXPECT_STREQ
(
"A"
,
buffer
.
GetString
());
}
TEST
(
StringBuffer
,
Clear
)
{
StringBuffer
buffer
;
buffer
.
Put
(
'A'
);
buffer
.
Put
(
'B'
);
buffer
.
Put
(
'C'
);
buffer
.
Clear
();
EXPECT_EQ
(
0u
,
buffer
.
GetSize
());
EXPECT_STREQ
(
""
,
buffer
.
GetString
());
}
TEST
(
StringBuffer
,
Push
)
{
StringBuffer
buffer
;
buffer
.
Push
(
5
);
EXPECT_EQ
(
5u
,
buffer
.
GetSize
());
}
TEST
(
StringBuffer
,
Pop
)
{
StringBuffer
buffer
;
buffer
.
Put
(
'A'
);
buffer
.
Put
(
'B'
);
buffer
.
Put
(
'C'
);
buffer
.
Put
(
'D'
);
buffer
.
Put
(
'E'
);
buffer
.
Pop
(
3
);
EXPECT_EQ
(
2u
,
buffer
.
GetSize
());
EXPECT_STREQ
(
"AB"
,
buffer
.
GetString
());
}
#if RAPIDJSON_HAS_CXX11_RVALUE_REFS
TEST
(
StringBuffer
,
MoveConstructor
)
{
StringBuffer
x
;
x
.
Put
(
'A'
);
x
.
Put
(
'B'
);
x
.
Put
(
'C'
);
x
.
Put
(
'D'
);
EXPECT_EQ
(
4u
,
x
.
GetSize
());
EXPECT_STREQ
(
"ABCD"
,
x
.
GetString
());
// StringBuffer y(x); // should not compile
StringBuffer
y
(
std
::
move
(
x
));
EXPECT_EQ
(
0u
,
x
.
GetSize
());
EXPECT_EQ
(
4u
,
y
.
GetSize
());
EXPECT_STREQ
(
"ABCD"
,
y
.
GetString
());
// StringBuffer z = y; // should not compile
StringBuffer
z
=
std
::
move
(
y
);
EXPECT_EQ
(
0u
,
y
.
GetSize
());
EXPECT_EQ
(
4u
,
z
.
GetSize
());
EXPECT_STREQ
(
"ABCD"
,
z
.
GetString
());
}
TEST
(
StringBuffer
,
MoveAssignment
)
{
StringBuffer
x
;
x
.
Put
(
'A'
);
x
.
Put
(
'B'
);
x
.
Put
(
'C'
);
x
.
Put
(
'D'
);
EXPECT_EQ
(
4u
,
x
.
GetSize
());
EXPECT_STREQ
(
"ABCD"
,
x
.
GetString
());
StringBuffer
y
;
// y = x; // should not compile
y
=
std
::
move
(
x
);
EXPECT_EQ
(
0u
,
x
.
GetSize
());
EXPECT_EQ
(
4u
,
y
.
GetSize
());
EXPECT_STREQ
(
"ABCD"
,
y
.
GetString
());
}
#endif // RAPIDJSON_HAS_CXX11_RVALUE_REFS
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