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
818f6f1f
Commit
818f6f1f
authored
Sep 03, 2014
by
miloyip
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add random tests for ParseNumber
parent
0580d42d
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
84 additions
and
0 deletions
+84
-0
readertest.cpp
test/unittest/readertest.cpp
+71
-0
unittest.h
test/unittest/unittest.h
+13
-0
No files found.
test/unittest/readertest.cpp
View file @
818f6f1f
...
...
@@ -21,6 +21,8 @@
#include "unittest.h"
#include "rapidjson/reader.h"
#include "rapidjson/internal/dtoa.h"
#include "rapidjson/internal/itoa.h"
using
namespace
rapidjson
;
...
...
@@ -172,6 +174,75 @@ TEST(Reader, ParseNumberHandler) {
n1e308
[
309
]
=
'\0'
;
TEST_DOUBLE
(
n1e308
,
1E308
);
}
// Random test for uint32_t/int32_t
{
union
{
uint32_t
u
;
int32_t
i
;
}
u
;
Random
r
;
for
(
unsigned
i
=
0
;
i
<
100000
;
i
++
)
{
u
.
u
=
r
();
char
buffer
[
32
];
*
internal
::
u32toa
(
u
.
u
,
buffer
)
=
'\0'
;
TEST_NUMBER
(
ParseUintHandler
,
buffer
,
u
.
u
);
if
(
u
.
i
<
0
)
{
*
internal
::
i32toa
(
u
.
i
,
buffer
)
=
'\0'
;
TEST_NUMBER
(
ParseIntHandler
,
buffer
,
u
.
i
);
}
}
}
// Random test for uint64_t/int64_t
{
union
{
uint64_t
u
;
int64_t
i
;
}
u
;
Random
r
;
for
(
unsigned
i
=
0
;
i
<
100000
;
i
++
)
{
u
.
u
=
uint64_t
(
r
())
<<
32
;
u
.
u
|=
r
();
char
buffer
[
32
];
if
(
u
.
u
>=
4294967296ULL
)
{
*
internal
::
u64toa
(
u
.
u
,
buffer
)
=
'\0'
;
TEST_NUMBER
(
ParseUint64Handler
,
buffer
,
u
.
u
);
}
if
(
u
.
i
<=
-
2147483649LL
)
{
*
internal
::
i64toa
(
u
.
i
,
buffer
)
=
'\0'
;
TEST_NUMBER
(
ParseInt64Handler
,
buffer
,
u
.
i
);
}
}
}
// Random test for double
{
union
{
double
d
;
uint64_t
u
;
}
u
;
Random
r
;
for
(
unsigned
i
=
0
;
i
<
100000
;
i
++
)
{
do
{
// Need to call r() in two statements for cross-platform coherent sequence.
u
.
u
=
uint64_t
(
r
())
<<
32
;
u
.
u
|=
uint64_t
(
r
());
}
while
(
isnan
(
u
.
d
)
||
isinf
(
u
.
d
));
char
buffer
[
32
];
*
internal
::
dtoa
(
u
.
d
,
buffer
)
=
'\0'
;
TEST_DOUBLE
(
buffer
,
u
.
d
);
}
}
#undef TEST_NUMBER
#undef TEST_DOUBLE
}
...
...
test/unittest/unittest.h
View file @
818f6f1f
...
...
@@ -102,4 +102,17 @@ private:
#define RAPIDJSON_ASSERT(x) if (!(x)) throw AssertException(RAPIDJSON_STRINGIFY(x))
class
Random
{
public
:
Random
(
unsigned
seed
=
0
)
:
mSeed
(
seed
)
{}
unsigned
operator
()()
{
mSeed
=
214013
*
mSeed
+
2531011
;
return
mSeed
;
}
private
:
unsigned
mSeed
;
};
#endif // UNITTEST_H_
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