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
8a96a95d
Unverified
Commit
8a96a95d
authored
Sep 10, 2018
by
Milo Yip
Committed by
GitHub
Sep 10, 2018
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'master' into fix-noexcept
parents
f54f6b5a
f5f6052c
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
14 changed files
with
154 additions
and
119 deletions
+154
-119
prettywriter.h
include/rapidjson/prettywriter.h
+12
-12
rapidjson.h
include/rapidjson/rapidjson.h
+15
-7
reader.h
include/rapidjson/reader.h
+23
-23
platformtest.cpp
test/perftest/platformtest.cpp
+1
-1
allocatorstest.cpp
test/unittest/allocatorstest.cpp
+12
-14
cursorstreamwrappertest.cpp
test/unittest/cursorstreamwrappertest.cpp
+18
-18
istreamwrappertest.cpp
test/unittest/istreamwrappertest.cpp
+9
-9
itoatest.cpp
test/unittest/itoatest.cpp
+7
-7
pointertest.cpp
test/unittest/pointertest.cpp
+12
-12
prettywritertest.cpp
test/unittest/prettywritertest.cpp
+29
-0
readertest.cpp
test/unittest/readertest.cpp
+0
-0
stringbuffertest.cpp
test/unittest/stringbuffertest.cpp
+4
-4
valuetest.cpp
test/unittest/valuetest.cpp
+11
-11
gtest
thirdparty/gtest
+1
-1
No files found.
include/rapidjson/prettywriter.h
View file @
8a96a95d
...
...
@@ -92,26 +92,26 @@ public:
*/
//@{
bool
Null
()
{
PrettyPrefix
(
kNullType
);
return
Base
::
WriteNull
(
);
}
bool
Bool
(
bool
b
)
{
PrettyPrefix
(
b
?
kTrueType
:
kFalseType
);
return
Base
::
WriteBool
(
b
);
}
bool
Int
(
int
i
)
{
PrettyPrefix
(
kNumberType
);
return
Base
::
WriteInt
(
i
);
}
bool
Uint
(
unsigned
u
)
{
PrettyPrefix
(
kNumberType
);
return
Base
::
WriteUint
(
u
);
}
bool
Int64
(
int64_t
i64
)
{
PrettyPrefix
(
kNumberType
);
return
Base
::
WriteInt64
(
i64
);
}
bool
Uint64
(
uint64_t
u64
)
{
PrettyPrefix
(
kNumberType
);
return
Base
::
WriteUint64
(
u64
);
}
bool
Double
(
double
d
)
{
PrettyPrefix
(
kNumberType
);
return
Base
::
WriteDouble
(
d
);
}
bool
Null
()
{
PrettyPrefix
(
kNullType
);
return
Base
::
EndValue
(
Base
::
WriteNull
()
);
}
bool
Bool
(
bool
b
)
{
PrettyPrefix
(
b
?
kTrueType
:
kFalseType
);
return
Base
::
EndValue
(
Base
::
WriteBool
(
b
)
);
}
bool
Int
(
int
i
)
{
PrettyPrefix
(
kNumberType
);
return
Base
::
EndValue
(
Base
::
WriteInt
(
i
)
);
}
bool
Uint
(
unsigned
u
)
{
PrettyPrefix
(
kNumberType
);
return
Base
::
EndValue
(
Base
::
WriteUint
(
u
)
);
}
bool
Int64
(
int64_t
i64
)
{
PrettyPrefix
(
kNumberType
);
return
Base
::
EndValue
(
Base
::
WriteInt64
(
i64
)
);
}
bool
Uint64
(
uint64_t
u64
)
{
PrettyPrefix
(
kNumberType
);
return
Base
::
EndValue
(
Base
::
WriteUint64
(
u64
)
);
}
bool
Double
(
double
d
)
{
PrettyPrefix
(
kNumberType
);
return
Base
::
EndValue
(
Base
::
WriteDouble
(
d
)
);
}
bool
RawNumber
(
const
Ch
*
str
,
SizeType
length
,
bool
copy
=
false
)
{
RAPIDJSON_ASSERT
(
str
!=
0
);
(
void
)
copy
;
PrettyPrefix
(
kNumberType
);
return
Base
::
WriteString
(
str
,
length
);
return
Base
::
EndValue
(
Base
::
WriteString
(
str
,
length
)
);
}
bool
String
(
const
Ch
*
str
,
SizeType
length
,
bool
copy
=
false
)
{
RAPIDJSON_ASSERT
(
str
!=
0
);
(
void
)
copy
;
PrettyPrefix
(
kStringType
);
return
Base
::
WriteString
(
str
,
length
);
return
Base
::
EndValue
(
Base
::
WriteString
(
str
,
length
)
);
}
#if RAPIDJSON_HAS_STDSTRING
...
...
@@ -146,7 +146,7 @@ public:
Base
::
os_
->
Put
(
'\n'
);
WriteIndent
();
}
bool
ret
=
Base
::
WriteEndObject
(
);
bool
ret
=
Base
::
EndValue
(
Base
::
WriteEndObject
()
);
(
void
)
ret
;
RAPIDJSON_ASSERT
(
ret
==
true
);
if
(
Base
::
level_stack_
.
Empty
())
// end of json text
...
...
@@ -170,7 +170,7 @@ public:
Base
::
os_
->
Put
(
'\n'
);
WriteIndent
();
}
bool
ret
=
Base
::
WriteEndArray
(
);
bool
ret
=
Base
::
EndValue
(
Base
::
WriteEndArray
()
);
(
void
)
ret
;
RAPIDJSON_ASSERT
(
ret
==
true
);
if
(
Base
::
level_stack_
.
Empty
())
// end of json text
...
...
@@ -201,7 +201,7 @@ public:
bool
RawValue
(
const
Ch
*
json
,
size_t
length
,
Type
type
)
{
RAPIDJSON_ASSERT
(
json
!=
0
);
PrettyPrefix
(
type
);
return
Base
::
WriteRawValue
(
json
,
length
);
return
Base
::
EndValue
(
Base
::
WriteRawValue
(
json
,
length
)
);
}
protected
:
...
...
include/rapidjson/rapidjson.h
View file @
8a96a95d
...
...
@@ -269,16 +269,11 @@
/*! \ingroup RAPIDJSON_CONFIG
\param x pointer to align
Some machines require strict data alignment. Currently the default uses 4 bytes
alignment on 32-bit platforms and 8 bytes alignment for 64-bit platforms.
Some machines require strict data alignment. The default is 8 bytes.
User can customize by defining the RAPIDJSON_ALIGN function macro.
*/
#ifndef RAPIDJSON_ALIGN
#if RAPIDJSON_64BIT == 1
#define RAPIDJSON_ALIGN(x) (((x) + static_cast<uint64_t>(7u)) & ~static_cast<uint64_t>(7u))
#else
#define RAPIDJSON_ALIGN(x) (((x) + 3u) & ~3u)
#endif
#define RAPIDJSON_ALIGN(x) (((x) + static_cast<size_t>(7u)) & ~static_cast<size_t>(7u))
#endif
///////////////////////////////////////////////////////////////////////////////
...
...
@@ -617,6 +612,19 @@ RAPIDJSON_NAMESPACE_END
#endif // RAPIDJSON_HAS_CXX11_NOEXCEPT
#endif // RAPIDJSON_NOEXCEPT_ASSERT
///////////////////////////////////////////////////////////////////////////////
// RAPIDJSON_NOEXCEPT_ASSERT
#ifdef RAPIDJSON_ASSERT_THROWS
#if RAPIDJSON_HAS_CXX11_NOEXCEPT
#define RAPIDJSON_NOEXCEPT_ASSERT(x)
#else
#define RAPIDJSON_NOEXCEPT_ASSERT(x) RAPIDJSON_ASSERT(x)
#endif // RAPIDJSON_HAS_CXX11_NOEXCEPT
#else
#define RAPIDJSON_NOEXCEPT_ASSERT(x) RAPIDJSON_ASSERT(x)
#endif // RAPIDJSON_ASSERT_THROWS
///////////////////////////////////////////////////////////////////////////////
// new/delete
...
...
include/rapidjson/reader.h
View file @
8a96a95d
...
...
@@ -606,7 +606,7 @@ public:
parseResult_
.
Clear
();
state_
=
IterativeParsingStartState
;
}
//! Parse one token from JSON text
/*! \tparam InputStream Type of input stream, implementing Stream concept
\tparam Handler Type of handler, implementing Handler concept.
...
...
@@ -618,11 +618,11 @@ public:
bool
IterativeParseNext
(
InputStream
&
is
,
Handler
&
handler
)
{
while
(
RAPIDJSON_LIKELY
(
is
.
Peek
()
!=
'\0'
))
{
SkipWhitespaceAndComments
<
parseFlags
>
(
is
);
Token
t
=
Tokenize
(
is
.
Peek
());
IterativeParsingState
n
=
Predict
(
state_
,
t
);
IterativeParsingState
d
=
Transit
<
parseFlags
>
(
state_
,
t
,
n
,
is
,
handler
);
// If we've finished or hit an error...
if
(
RAPIDJSON_UNLIKELY
(
IsIterativeParsingCompleteState
(
d
)))
{
// Report errors.
...
...
@@ -630,11 +630,11 @@ public:
HandleError
(
state_
,
is
);
return
false
;
}
// Transition to the finish state.
RAPIDJSON_ASSERT
(
d
==
IterativeParsingFinishState
);
state_
=
d
;
// If StopWhenDone is not set...
if
(
!
(
parseFlags
&
kParseStopWhenDoneFlag
))
{
// ... and extra non-whitespace data is found...
...
...
@@ -645,11 +645,11 @@ public:
return
false
;
}
}
// Success! We are done!
return
true
;
}
// Transition to the new state.
state_
=
d
;
...
...
@@ -657,7 +657,7 @@ public:
if
(
!
IsIterativeParsingDelimiterState
(
n
))
return
true
;
}
// We reached the end of file.
stack_
.
Clear
();
...
...
@@ -665,10 +665,10 @@ public:
HandleError
(
state_
,
is
);
return
false
;
}
return
true
;
}
//! Check if token-by-token parsing JSON text is complete
/*! \return Whether the JSON has been fully decoded.
*/
...
...
@@ -1523,7 +1523,7 @@ private:
}
}
}
if
(
RAPIDJSON_UNLIKELY
(
!
useNanOrInf
))
{
RAPIDJSON_PARSE_ERROR
(
kParseErrorValueInvalid
,
s
.
Tell
());
}
...
...
@@ -1701,7 +1701,7 @@ private:
d
=
internal
::
StrtodNormalPrecision
(
d
,
p
);
// Use > max, instead of == inf, to fix bogus warning -Wfloat-equal
if
(
d
>
std
::
numeric_limits
<
double
>::
max
())
{
if
(
d
>
(
std
::
numeric_limits
<
double
>::
max
)
())
{
// Overflow
// TODO: internal::StrtodX should report overflow (or underflow)
RAPIDJSON_PARSE_ERROR
(
kParseErrorNumberTooBig
,
startOffset
);
...
...
@@ -1769,12 +1769,12 @@ private:
// Single value state
IterativeParsingValueState
,
// Delimiter states (at bottom)
IterativeParsingElementDelimiterState
,
IterativeParsingMemberDelimiterState
,
IterativeParsingKeyValueDelimiterState
,
cIterativeParsingStateCount
};
...
...
@@ -2167,43 +2167,43 @@ private:
RAPIDJSON_FORCEINLINE
bool
IsIterativeParsingDelimiterState
(
IterativeParsingState
s
)
const
{
return
s
>=
IterativeParsingElementDelimiterState
;
}
RAPIDJSON_FORCEINLINE
bool
IsIterativeParsingCompleteState
(
IterativeParsingState
s
)
const
{
return
s
<=
IterativeParsingErrorState
;
}
template
<
unsigned
parseFlags
,
typename
InputStream
,
typename
Handler
>
ParseResult
IterativeParse
(
InputStream
&
is
,
Handler
&
handler
)
{
parseResult_
.
Clear
();
ClearStackOnExit
scope
(
*
this
);
IterativeParsingState
state
=
IterativeParsingStartState
;
SkipWhitespaceAndComments
<
parseFlags
>
(
is
);
RAPIDJSON_PARSE_ERROR_EARLY_RETURN
(
parseResult_
);
while
(
is
.
Peek
()
!=
'\0'
)
{
Token
t
=
Tokenize
(
is
.
Peek
());
IterativeParsingState
n
=
Predict
(
state
,
t
);
IterativeParsingState
d
=
Transit
<
parseFlags
>
(
state
,
t
,
n
,
is
,
handler
);
if
(
d
==
IterativeParsingErrorState
)
{
HandleError
(
state
,
is
);
break
;
}
state
=
d
;
// Do not further consume streams if a root JSON has been parsed.
if
((
parseFlags
&
kParseStopWhenDoneFlag
)
&&
state
==
IterativeParsingFinishState
)
break
;
SkipWhitespaceAndComments
<
parseFlags
>
(
is
);
RAPIDJSON_PARSE_ERROR_EARLY_RETURN
(
parseResult_
);
}
// Handle the end of file.
if
(
state
!=
IterativeParsingFinishState
)
HandleError
(
state
,
is
);
return
parseResult_
;
}
...
...
test/perftest/platformtest.cpp
View file @
8a96a95d
...
...
@@ -76,7 +76,7 @@ TEST_F(Platform, strlen) {
TEST_F
(
Platform
,
memcmp
)
{
for
(
int
i
=
0
;
i
<
kTrialCount
;
i
++
)
{
EXPECT_EQ
(
0
,
memcmp
(
temp_
,
json_
,
length_
));
EXPECT_EQ
(
0
u
,
memcmp
(
temp_
,
json_
,
length_
));
}
}
...
...
test/unittest/allocatorstest.cpp
View file @
8a96a95d
...
...
@@ -63,23 +63,21 @@ TEST(Allocator, MemoryPoolAllocator) {
}
TEST
(
Allocator
,
Alignment
)
{
#if RAPIDJSON_64BIT == 1
EXPECT_EQ
(
RAPIDJSON_UINT64_C2
(
0x00000000
,
0x00000000
),
RAPIDJSON_ALIGN
(
0
));
for
(
uint64_t
i
=
1
;
i
<
8
;
i
++
)
{
EXPECT_EQ
(
RAPIDJSON_UINT64_C2
(
0x00000000
,
0x00000008
),
RAPIDJSON_ALIGN
(
i
));
EXPECT_EQ
(
RAPIDJSON_UINT64_C2
(
0x00000000
,
0x00000010
),
RAPIDJSON_ALIGN
(
RAPIDJSON_UINT64_C2
(
0x00000000
,
0x00000008
)
+
i
));
EXPECT_EQ
(
RAPIDJSON_UINT64_C2
(
0x00000001
,
0x00000000
),
RAPIDJSON_ALIGN
(
RAPIDJSON_UINT64_C2
(
0x00000000
,
0xFFFFFFF8
)
+
i
));
EXPECT_EQ
(
RAPIDJSON_UINT64_C2
(
0xFFFFFFFF
,
0xFFFFFFF8
),
RAPIDJSON_ALIGN
(
RAPIDJSON_UINT64_C2
(
0xFFFFFFFF
,
0xFFFFFFF0
)
+
i
));
if
(
sizeof
(
size_t
)
>=
8
)
{
EXPECT_EQ
(
RAPIDJSON_UINT64_C2
(
0x00000000
,
0x00000000
),
RAPIDJSON_ALIGN
(
0
));
for
(
uint64_t
i
=
1
;
i
<
8
;
i
++
)
{
EXPECT_EQ
(
RAPIDJSON_UINT64_C2
(
0x00000000
,
0x00000008
),
RAPIDJSON_ALIGN
(
i
));
EXPECT_EQ
(
RAPIDJSON_UINT64_C2
(
0x00000000
,
0x00000010
),
RAPIDJSON_ALIGN
(
RAPIDJSON_UINT64_C2
(
0x00000000
,
0x00000008
)
+
i
));
EXPECT_EQ
(
RAPIDJSON_UINT64_C2
(
0x00000001
,
0x00000000
),
RAPIDJSON_ALIGN
(
RAPIDJSON_UINT64_C2
(
0x00000000
,
0xFFFFFFF8
)
+
i
));
EXPECT_EQ
(
RAPIDJSON_UINT64_C2
(
0xFFFFFFFF
,
0xFFFFFFF8
),
RAPIDJSON_ALIGN
(
RAPIDJSON_UINT64_C2
(
0xFFFFFFFF
,
0xFFFFFFF0
)
+
i
));
}
}
#else
EXPECT_EQ
(
0u
,
RAPIDJSON_ALIGN
(
0u
));
for
(
uint32_t
i
=
1
;
i
<
4
;
i
++
)
{
EXPECT_EQ
(
4u
,
RAPIDJSON_ALIGN
(
i
));
EXPECT_EQ
(
8u
,
RAPIDJSON_ALIGN
(
4u
+
i
));
EXPECT_EQ
(
0xFFFFFFF8u
,
RAPIDJSON_ALIGN
(
0xFFFFFFF4u
+
i
));
EXPECT_EQ
(
0xFFFFFFFCu
,
RAPIDJSON_ALIGN
(
0xFFFFFFF8u
+
i
));
for
(
uint32_t
i
=
1
;
i
<
8
;
i
++
)
{
EXPECT_EQ
(
8u
,
RAPIDJSON_ALIGN
(
i
));
EXPECT_EQ
(
0xFFFFFFF8u
,
RAPIDJSON_ALIGN
(
0xFFFFFFF0u
+
i
));
}
#endif
}
TEST
(
Allocator
,
Issue399
)
{
...
...
test/unittest/cursorstreamwrappertest.cpp
View file @
8a96a95d
...
...
@@ -38,8 +38,8 @@ TEST(CursorStreamWrapper, MissingFirstBracket) {
size_t
col
,
line
;
bool
ret
=
testJson
(
json
,
line
,
col
);
EXPECT_TRUE
(
ret
);
EXPECT_EQ
(
line
,
3
);
EXPECT_EQ
(
col
,
0
);
EXPECT_EQ
(
line
,
3
u
);
EXPECT_EQ
(
col
,
0
u
);
}
TEST
(
CursorStreamWrapper
,
MissingQuotes
)
{
...
...
@@ -47,8 +47,8 @@ TEST(CursorStreamWrapper, MissingQuotes) {
size_t
col
,
line
;
bool
ret
=
testJson
(
json
,
line
,
col
);
EXPECT_TRUE
(
ret
);
EXPECT_EQ
(
line
,
1
);
EXPECT_EQ
(
col
,
8
);
EXPECT_EQ
(
line
,
1
u
);
EXPECT_EQ
(
col
,
8
u
);
}
TEST
(
CursorStreamWrapper
,
MissingColon
)
{
...
...
@@ -56,8 +56,8 @@ TEST(CursorStreamWrapper, MissingColon) {
size_t
col
,
line
;
bool
ret
=
testJson
(
json
,
line
,
col
);
EXPECT_TRUE
(
ret
);
EXPECT_EQ
(
line
,
3
);
EXPECT_EQ
(
col
,
0
);
EXPECT_EQ
(
line
,
3
u
);
EXPECT_EQ
(
col
,
0
u
);
}
TEST
(
CursorStreamWrapper
,
MissingSecondQuotes
)
{
...
...
@@ -65,8 +65,8 @@ TEST(CursorStreamWrapper, MissingSecondQuotes) {
size_t
col
,
line
;
bool
ret
=
testJson
(
json
,
line
,
col
);
EXPECT_TRUE
(
ret
);
EXPECT_EQ
(
line
,
3
);
EXPECT_EQ
(
col
,
1
);
EXPECT_EQ
(
line
,
3
u
);
EXPECT_EQ
(
col
,
1
u
);
}
TEST
(
CursorStreamWrapper
,
MissingComma
)
{
...
...
@@ -74,8 +74,8 @@ TEST(CursorStreamWrapper, MissingComma) {
size_t
col
,
line
;
bool
ret
=
testJson
(
json
,
line
,
col
);
EXPECT_TRUE
(
ret
);
EXPECT_EQ
(
line
,
3
);
EXPECT_EQ
(
col
,
12
);
EXPECT_EQ
(
line
,
3
u
);
EXPECT_EQ
(
col
,
12
u
);
}
TEST
(
CursorStreamWrapper
,
MissingArrayBracket
)
{
...
...
@@ -83,8 +83,8 @@ TEST(CursorStreamWrapper, MissingArrayBracket) {
size_t
col
,
line
;
bool
ret
=
testJson
(
json
,
line
,
col
);
EXPECT_TRUE
(
ret
);
EXPECT_EQ
(
line
,
4
);
EXPECT_EQ
(
col
,
9
);
EXPECT_EQ
(
line
,
4
u
);
EXPECT_EQ
(
col
,
9
u
);
}
TEST
(
CursorStreamWrapper
,
MissingArrayComma
)
{
...
...
@@ -92,8 +92,8 @@ TEST(CursorStreamWrapper, MissingArrayComma) {
size_t
col
,
line
;
bool
ret
=
testJson
(
json
,
line
,
col
);
EXPECT_TRUE
(
ret
);
EXPECT_EQ
(
line
,
4
);
EXPECT_EQ
(
col
,
6
);
EXPECT_EQ
(
line
,
4
u
);
EXPECT_EQ
(
col
,
6
u
);
}
TEST
(
CursorStreamWrapper
,
MissingLastArrayBracket
)
{
...
...
@@ -101,8 +101,8 @@ TEST(CursorStreamWrapper, MissingLastArrayBracket) {
size_t
col
,
line
;
bool
ret
=
testJson
(
json8
,
line
,
col
);
EXPECT_TRUE
(
ret
);
EXPECT_EQ
(
line
,
4
);
EXPECT_EQ
(
col
,
15
);
EXPECT_EQ
(
line
,
4
u
);
EXPECT_EQ
(
col
,
15
u
);
}
TEST
(
CursorStreamWrapper
,
MissingLastBracket
)
{
...
...
@@ -110,6 +110,6 @@ TEST(CursorStreamWrapper, MissingLastBracket) {
size_t
col
,
line
;
bool
ret
=
testJson
(
json9
,
line
,
col
);
EXPECT_TRUE
(
ret
);
EXPECT_EQ
(
line
,
4
);
EXPECT_EQ
(
col
,
16
);
EXPECT_EQ
(
line
,
4
u
);
EXPECT_EQ
(
col
,
16
u
);
}
test/unittest/istreamwrappertest.cpp
View file @
8a96a95d
...
...
@@ -35,21 +35,21 @@ static void TestStringStream() {
{
StringStreamType
iss
;
BasicIStreamWrapper
<
StringStreamType
>
is
(
iss
);
EXPECT_EQ
(
0
,
is
.
Tell
());
EXPECT_EQ
(
0
u
,
is
.
Tell
());
if
(
sizeof
(
Ch
)
==
1
)
{
EXPECT_EQ
(
0
,
is
.
Peek4
());
EXPECT_EQ
(
0
,
is
.
Tell
());
EXPECT_EQ
(
0
u
,
is
.
Tell
());
}
EXPECT_EQ
(
0
,
is
.
Peek
());
EXPECT_EQ
(
0
,
is
.
Take
());
EXPECT_EQ
(
0
,
is
.
Tell
());
EXPECT_EQ
(
0
u
,
is
.
Tell
());
}
{
Ch
s
[]
=
{
'A'
,
'B'
,
'C'
,
'\0'
};
StringStreamType
iss
(
s
);
BasicIStreamWrapper
<
StringStreamType
>
is
(
iss
);
EXPECT_EQ
(
0
,
is
.
Tell
());
EXPECT_EQ
(
0
u
,
is
.
Tell
());
if
(
sizeof
(
Ch
)
==
1
)
{
EXPECT_EQ
(
0
,
is
.
Peek4
());
// less than 4 bytes
}
...
...
@@ -59,7 +59,7 @@ static void TestStringStream() {
EXPECT_EQ
(
'A'
+
i
,
is
.
Peek
());
EXPECT_EQ
(
'A'
+
i
,
is
.
Take
());
}
EXPECT_EQ
(
3
,
is
.
Tell
());
EXPECT_EQ
(
3
u
,
is
.
Tell
());
EXPECT_EQ
(
0
,
is
.
Peek
());
EXPECT_EQ
(
0
,
is
.
Take
());
}
...
...
@@ -72,7 +72,7 @@ static void TestStringStream() {
const
Ch
*
c
=
is
.
Peek4
();
for
(
int
i
=
0
;
i
<
4
;
i
++
)
EXPECT_EQ
(
'A'
+
i
,
c
[
i
]);
EXPECT_EQ
(
0
,
is
.
Tell
());
EXPECT_EQ
(
0
u
,
is
.
Tell
());
}
for
(
int
i
=
0
;
i
<
5
;
i
++
)
{
EXPECT_EQ
(
static_cast
<
size_t
>
(
i
),
is
.
Tell
());
...
...
@@ -80,7 +80,7 @@ static void TestStringStream() {
EXPECT_EQ
(
'A'
+
i
,
is
.
Peek
());
EXPECT_EQ
(
'A'
+
i
,
is
.
Take
());
}
EXPECT_EQ
(
5
,
is
.
Tell
());
EXPECT_EQ
(
5
u
,
is
.
Tell
());
EXPECT_EQ
(
0
,
is
.
Peek
());
EXPECT_EQ
(
0
,
is
.
Take
());
}
...
...
@@ -129,7 +129,7 @@ TEST(IStreamWrapper, ifstream) {
Document
d
;
EXPECT_TRUE
(
!
d
.
ParseStream
(
eis
).
HasParseError
());
EXPECT_TRUE
(
d
.
IsObject
());
EXPECT_EQ
(
5
,
d
.
MemberCount
());
EXPECT_EQ
(
5
u
,
d
.
MemberCount
());
}
TEST
(
IStreamWrapper
,
fstream
)
{
...
...
@@ -140,7 +140,7 @@ TEST(IStreamWrapper, fstream) {
Document
d
;
EXPECT_TRUE
(
!
d
.
ParseStream
(
eis
).
HasParseError
());
EXPECT_TRUE
(
d
.
IsObject
());
EXPECT_EQ
(
5
,
d
.
MemberCount
());
EXPECT_EQ
(
5
u
,
d
.
MemberCount
());
}
// wifstream/wfstream only works on C++11 with codecvt_utf16
...
...
test/unittest/itoatest.cpp
View file @
8a96a95d
// Tencent is pleased to support the open source community by making RapidJSON available.
//
//
// Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip. All rights reserved.
//
// Licensed under the MIT License (the "License"); you may not use this file except
...
...
@@ -7,9 +7,9 @@
//
// http://opensource.org/licenses/MIT
//
// Unless required by applicable law or agreed to in writing, software distributed
// under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
// CONDITIONS OF ANY KIND, either express or implied. See the License for the
// Unless required by applicable law or agreed to in writing, software distributed
// under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
// CONDITIONS OF ANY KIND, either express or implied. See the License for the
// specific language governing permissions and limitations under the License.
#include "unittest.h"
...
...
@@ -61,7 +61,7 @@ static void VerifyValue(T value, void(*f)(T, char*), char* (*g)(T, char*)) {
f
(
value
,
buffer1
);
*
g
(
value
,
buffer2
)
=
'\0'
;
EXPECT_STREQ
(
buffer1
,
buffer2
);
}
...
...
@@ -79,12 +79,12 @@ static void Verify(void(*f)(T, char*), char* (*g)(T, char*)) {
do
{
VerifyValue
<
T
>
(
i
-
1
,
f
,
g
);
VerifyValue
<
T
>
(
i
,
f
,
g
);
if
(
std
::
numeric_limits
<
T
>::
min
()
<
0
)
{
if
(
(
std
::
numeric_limits
<
T
>::
min
)
()
<
0
)
{
VerifyValue
<
T
>
(
Traits
<
T
>::
Negate
(
i
),
f
,
g
);
VerifyValue
<
T
>
(
Traits
<
T
>::
Negate
(
i
+
1
),
f
,
g
);
}
last
=
i
;
if
(
i
>
static_cast
<
T
>
(
std
::
numeric_limits
<
T
>::
max
()
/
static_cast
<
T
>
(
power
)))
if
(
i
>
static_cast
<
T
>
(
(
std
::
numeric_limits
<
T
>::
max
)
()
/
static_cast
<
T
>
(
power
)))
break
;
i
*=
static_cast
<
T
>
(
power
);
}
while
(
last
<
i
);
...
...
test/unittest/pointertest.cpp
View file @
8a96a95d
...
...
@@ -634,13 +634,13 @@ TEST(Pointer, Get) {
EXPECT_TRUE
(
Pointer
(
"/abc"
).
Get
(
d
)
==
0
);
size_t
unresolvedTokenIndex
;
EXPECT_TRUE
(
Pointer
(
"/foo/2"
).
Get
(
d
,
&
unresolvedTokenIndex
)
==
0
);
// Out of boundary
EXPECT_EQ
(
1
,
unresolvedTokenIndex
);
EXPECT_EQ
(
1
u
,
unresolvedTokenIndex
);
EXPECT_TRUE
(
Pointer
(
"/foo/a"
).
Get
(
d
,
&
unresolvedTokenIndex
)
==
0
);
// "/foo" is an array, cannot query by "a"
EXPECT_EQ
(
1
,
unresolvedTokenIndex
);
EXPECT_EQ
(
1
u
,
unresolvedTokenIndex
);
EXPECT_TRUE
(
Pointer
(
"/foo/0/0"
).
Get
(
d
,
&
unresolvedTokenIndex
)
==
0
);
// "/foo/0" is an string, cannot further query
EXPECT_EQ
(
2
,
unresolvedTokenIndex
);
EXPECT_EQ
(
2
u
,
unresolvedTokenIndex
);
EXPECT_TRUE
(
Pointer
(
"/foo/0/a"
).
Get
(
d
,
&
unresolvedTokenIndex
)
==
0
);
// "/foo/0" is an string, cannot further query
EXPECT_EQ
(
2
,
unresolvedTokenIndex
);
EXPECT_EQ
(
2
u
,
unresolvedTokenIndex
);
}
TEST
(
Pointer
,
GetWithDefault
)
{
...
...
@@ -959,13 +959,13 @@ TEST(Pointer, GetValueByPointer) {
size_t
unresolvedTokenIndex
;
EXPECT_TRUE
(
GetValueByPointer
(
d
,
"/foo/2"
,
&
unresolvedTokenIndex
)
==
0
);
// Out of boundary
EXPECT_EQ
(
1
,
unresolvedTokenIndex
);
EXPECT_EQ
(
1
u
,
unresolvedTokenIndex
);
EXPECT_TRUE
(
GetValueByPointer
(
d
,
"/foo/a"
,
&
unresolvedTokenIndex
)
==
0
);
// "/foo" is an array, cannot query by "a"
EXPECT_EQ
(
1
,
unresolvedTokenIndex
);
EXPECT_EQ
(
1
u
,
unresolvedTokenIndex
);
EXPECT_TRUE
(
GetValueByPointer
(
d
,
"/foo/0/0"
,
&
unresolvedTokenIndex
)
==
0
);
// "/foo/0" is an string, cannot further query
EXPECT_EQ
(
2
,
unresolvedTokenIndex
);
EXPECT_EQ
(
2
u
,
unresolvedTokenIndex
);
EXPECT_TRUE
(
GetValueByPointer
(
d
,
"/foo/0/a"
,
&
unresolvedTokenIndex
)
==
0
);
// "/foo/0" is an string, cannot further query
EXPECT_EQ
(
2
,
unresolvedTokenIndex
);
EXPECT_EQ
(
2
u
,
unresolvedTokenIndex
);
// const version
const
Value
&
v
=
d
;
...
...
@@ -973,13 +973,13 @@ TEST(Pointer, GetValueByPointer) {
EXPECT_EQ
(
&
d
[
"foo"
][
0
],
GetValueByPointer
(
v
,
"/foo/0"
));
EXPECT_TRUE
(
GetValueByPointer
(
v
,
"/foo/2"
,
&
unresolvedTokenIndex
)
==
0
);
// Out of boundary
EXPECT_EQ
(
1
,
unresolvedTokenIndex
);
EXPECT_EQ
(
1
u
,
unresolvedTokenIndex
);
EXPECT_TRUE
(
GetValueByPointer
(
v
,
"/foo/a"
,
&
unresolvedTokenIndex
)
==
0
);
// "/foo" is an array, cannot query by "a"
EXPECT_EQ
(
1
,
unresolvedTokenIndex
);
EXPECT_EQ
(
1
u
,
unresolvedTokenIndex
);
EXPECT_TRUE
(
GetValueByPointer
(
v
,
"/foo/0/0"
,
&
unresolvedTokenIndex
)
==
0
);
// "/foo/0" is an string, cannot further query
EXPECT_EQ
(
2
,
unresolvedTokenIndex
);
EXPECT_EQ
(
2
u
,
unresolvedTokenIndex
);
EXPECT_TRUE
(
GetValueByPointer
(
v
,
"/foo/0/a"
,
&
unresolvedTokenIndex
)
==
0
);
// "/foo/0" is an string, cannot further query
EXPECT_EQ
(
2
,
unresolvedTokenIndex
);
EXPECT_EQ
(
2
u
,
unresolvedTokenIndex
);
}
...
...
test/unittest/prettywritertest.cpp
View file @
8a96a95d
...
...
@@ -339,6 +339,35 @@ TEST(PrettyWriter, MoveCtor) {
}
#endif
TEST
(
PrettyWriter
,
Issue_1336
)
{
#define T(meth, val, expected) \
{ \
StringBuffer buffer; \
PrettyWriter<StringBuffer> writer(buffer); \
writer.meth(val); \
\
EXPECT_STREQ(expected, buffer.GetString()); \
EXPECT_TRUE(writer.IsComplete()); \
}
T
(
Bool
,
false
,
"false"
);
T
(
Bool
,
true
,
"true"
);
T
(
Int
,
0
,
"0"
);
T
(
Uint
,
0
,
"0"
);
T
(
Int64
,
0
,
"0"
);
T
(
Uint64
,
0
,
"0"
);
T
(
Double
,
0
,
"0.0"
);
T
(
String
,
"Hello"
,
"
\"
Hello
\"
"
);
#undef T
StringBuffer
buffer
;
PrettyWriter
<
StringBuffer
>
writer
(
buffer
);
writer
.
Null
();
EXPECT_STREQ
(
"null"
,
buffer
.
GetString
());
EXPECT_TRUE
(
writer
.
IsComplete
());
}
#ifdef __clang__
RAPIDJSON_DIAG_POP
#endif
test/unittest/readertest.cpp
View file @
8a96a95d
This diff is collapsed.
Click to expand it.
test/unittest/stringbuffertest.cpp
View file @
8a96a95d
...
...
@@ -41,11 +41,11 @@ TEST(StringBuffer, Put) {
TEST
(
StringBuffer
,
PutN_Issue672
)
{
GenericStringBuffer
<
UTF8
<>
,
MemoryPoolAllocator
<>
>
buffer
;
EXPECT_EQ
(
0
,
buffer
.
GetSize
());
EXPECT_EQ
(
0
,
buffer
.
GetLength
());
EXPECT_EQ
(
0
u
,
buffer
.
GetSize
());
EXPECT_EQ
(
0
u
,
buffer
.
GetLength
());
rapidjson
::
PutN
(
buffer
,
' '
,
1
);
EXPECT_EQ
(
1
,
buffer
.
GetSize
());
EXPECT_EQ
(
1
,
buffer
.
GetLength
());
EXPECT_EQ
(
1
u
,
buffer
.
GetSize
());
EXPECT_EQ
(
1
u
,
buffer
.
GetLength
());
}
TEST
(
StringBuffer
,
Clear
)
{
...
...
test/unittest/valuetest.cpp
View file @
8a96a95d
...
...
@@ -26,11 +26,11 @@ using namespace rapidjson;
TEST
(
Value
,
Size
)
{
if
(
sizeof
(
SizeType
)
==
4
)
{
#if RAPIDJSON_48BITPOINTER_OPTIMIZATION
EXPECT_EQ
(
16
,
sizeof
(
Value
));
EXPECT_EQ
(
16
u
,
sizeof
(
Value
));
#elif RAPIDJSON_64BIT
EXPECT_EQ
(
24
,
sizeof
(
Value
));
EXPECT_EQ
(
24
u
,
sizeof
(
Value
));
#else
EXPECT_EQ
(
16
,
sizeof
(
Value
));
EXPECT_EQ
(
16
u
,
sizeof
(
Value
));
#endif
}
}
...
...
@@ -1135,10 +1135,10 @@ TEST(Value, ArrayHelper) {
a
.
PushBack
(
1
,
allocator
);
Value
::
Array
a2
(
a
);
// copy constructor
EXPECT_EQ
(
1
,
a2
.
Size
());
EXPECT_EQ
(
1
u
,
a2
.
Size
());
Value
::
Array
a3
=
a
;
EXPECT_EQ
(
1
,
a3
.
Size
());
EXPECT_EQ
(
1
u
,
a3
.
Size
());
Value
::
ConstArray
y
=
static_cast
<
const
Value
&>
(
x
).
GetArray
();
(
void
)
y
;
...
...
@@ -1175,7 +1175,7 @@ TEST(Value, ArrayHelper) {
y
.
PushBack
(
123
,
allocator
);
x
.
PushBack
(
y
.
GetArray
(),
allocator
);
// Implicit constructor to convert Array to GenericValue
EXPECT_EQ
(
1
,
x
.
Size
());
EXPECT_EQ
(
1
u
,
x
.
Size
());
EXPECT_EQ
(
123
,
x
[
0
][
0
].
GetInt
());
EXPECT_TRUE
(
y
.
IsArray
());
EXPECT_TRUE
(
y
.
Empty
());
...
...
@@ -1424,7 +1424,7 @@ static void TestObject(T& x, Allocator& allocator) {
for
(;
itr
!=
x
.
MemberEnd
();
++
itr
)
{
size_t
i
=
static_cast
<
size_t
>
((
itr
-
x
.
MemberBegin
()))
+
1
;
EXPECT_STREQ
(
itr
->
name
.
GetString
(),
keys
[
i
]);
EXPECT_EQ
(
i
,
itr
->
value
[
0
].
GetInt
());
EXPECT_EQ
(
static_cast
<
int
>
(
i
)
,
itr
->
value
[
0
].
GetInt
());
}
// Erase the last
...
...
@@ -1435,7 +1435,7 @@ static void TestObject(T& x, Allocator& allocator) {
for
(;
itr
!=
x
.
MemberEnd
();
++
itr
)
{
size_t
i
=
static_cast
<
size_t
>
(
itr
-
x
.
MemberBegin
())
+
1
;
EXPECT_STREQ
(
itr
->
name
.
GetString
(),
keys
[
i
]);
EXPECT_EQ
(
i
,
itr
->
value
[
0
].
GetInt
());
EXPECT_EQ
(
static_cast
<
int
>
(
i
)
,
itr
->
value
[
0
].
GetInt
());
}
// Erase the middle
...
...
@@ -1447,7 +1447,7 @@ static void TestObject(T& x, Allocator& allocator) {
size_t
i
=
static_cast
<
size_t
>
(
itr
-
x
.
MemberBegin
());
i
+=
(
i
<
4
)
?
1
:
2
;
EXPECT_STREQ
(
itr
->
name
.
GetString
(),
keys
[
i
]);
EXPECT_EQ
(
i
,
itr
->
value
[
0
].
GetInt
());
EXPECT_EQ
(
static_cast
<
int
>
(
i
)
,
itr
->
value
[
0
].
GetInt
());
}
// EraseMember(ConstMemberIterator, ConstMemberIterator)
...
...
@@ -1516,10 +1516,10 @@ TEST(Value, ObjectHelper) {
o
.
AddMember
(
"1"
,
1
,
allocator
);
Value
::
Object
o2
(
o
);
// copy constructor
EXPECT_EQ
(
1
,
o2
.
MemberCount
());
EXPECT_EQ
(
1
u
,
o2
.
MemberCount
());
Value
::
Object
o3
=
o
;
EXPECT_EQ
(
1
,
o3
.
MemberCount
());
EXPECT_EQ
(
1
u
,
o3
.
MemberCount
());
Value
::
ConstObject
y
=
static_cast
<
const
Value
&>
(
x
).
GetObject
();
(
void
)
y
;
...
...
gtest
@
ba96d0b1
Subproject commit
0a439623f75c029912728d80cb7f1b8b48739ca4
Subproject commit
ba96d0b1161f540656efdaed035b3c062b60e006
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