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
0bff4ffd
Commit
0bff4ffd
authored
Jul 04, 2014
by
Milo Yip
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Adds unit tests about streams.
parent
b01093b1
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
121 additions
and
0 deletions
+121
-0
documenttest.cpp
test/unittest/documenttest.cpp
+38
-0
readertest.cpp
test/unittest/readertest.cpp
+44
-0
writertest.cpp
test/unittest/writertest.cpp
+39
-0
No files found.
test/unittest/documenttest.cpp
View file @
0bff4ffd
...
...
@@ -101,6 +101,44 @@ TEST(Document, ParseStream_EncodedInputStream) {
}
}
TEST
(
Document
,
ParseStream_AutoUTFInputStream
)
{
// Any -> UTF8
FILE
*
fp
=
OpenEncodedFile
(
"utf32BE.json"
);
char
buffer
[
256
];
FileReadStream
bis
(
fp
,
buffer
,
sizeof
(
buffer
));
AutoUTFInputStream
<
unsigned
,
FileReadStream
>
eis
(
bis
);
Document
d
;
d
.
ParseStream
<
0
,
AutoUTF
<
unsigned
>
>
(
eis
);
EXPECT_FALSE
(
d
.
HasParseError
());
fclose
(
fp
);
char
expected
[]
=
"I can eat glass and it doesn't hurt me."
;
Value
&
v
=
d
[
"en"
];
EXPECT_TRUE
(
v
.
IsString
());
EXPECT_EQ
(
sizeof
(
expected
)
-
1
,
v
.
GetStringLength
());
EXPECT_EQ
(
0
,
StrCmp
(
expected
,
v
.
GetString
()));
// UTF8 -> UTF8 in memory
StringBuffer
bos
;
Writer
<
StringBuffer
>
writer
(
bos
);
d
.
Accept
(
writer
);
{
// Condense the original file and compare.
FILE
*
fp
=
OpenEncodedFile
(
"utf8.json"
);
FileReadStream
is
(
fp
,
buffer
,
sizeof
(
buffer
));
Reader
reader
;
StringBuffer
bos2
;
Writer
<
StringBuffer
>
writer
(
bos2
);
reader
.
Parse
(
is
,
writer
);
EXPECT_EQ
(
bos
.
GetSize
(),
bos2
.
GetSize
());
EXPECT_EQ
(
0
,
memcmp
(
bos
.
GetString
(),
bos2
.
GetString
(),
bos2
.
GetSize
()));
}
}
TEST
(
Document
,
Swap
)
{
Document
d1
;
Document
::
AllocatorType
&
a
=
d1
.
GetAllocator
();
...
...
test/unittest/readertest.cpp
View file @
0bff4ffd
...
...
@@ -662,6 +662,50 @@ TEST(Reader, CustomStringStream) {
EXPECT_EQ
(
20u
,
h
.
step_
);
}
#include <sstream>
class
IStreamWrapper
{
public
:
typedef
char
Ch
;
IStreamWrapper
(
std
::
istream
&
is
)
:
is_
(
is
)
{}
Ch
Peek
()
const
{
int
c
=
is_
.
peek
();
return
c
==
std
::
char_traits
<
char
>::
eof
()
?
'\0'
:
(
Ch
)
c
;
}
Ch
Take
()
{
int
c
=
is_
.
get
();
return
c
==
std
::
char_traits
<
char
>::
eof
()
?
'\0'
:
(
Ch
)
c
;
}
size_t
Tell
()
const
{
return
(
size_t
)
is_
.
tellg
();
}
Ch
*
PutBegin
()
{
assert
(
false
);
return
0
;
}
void
Put
(
Ch
)
{
assert
(
false
);
}
void
Flush
()
{
assert
(
false
);
}
size_t
PutEnd
(
Ch
*
)
{
assert
(
false
);
return
0
;
}
private
:
IStreamWrapper
(
const
IStreamWrapper
&
);
IStreamWrapper
&
operator
=
(
const
IStreamWrapper
&
);
std
::
istream
&
is_
;
};
TEST
(
Reader
,
Parse_IStreamWrapper_StringStream
)
{
const
char
*
json
=
"[1,2,3,4]"
;
std
::
stringstream
ss
(
json
);
IStreamWrapper
is
(
ss
);
Reader
reader
;
ParseArrayHandler
<
4
>
h
;
reader
.
ParseArray
<
0
>
(
is
,
h
);
EXPECT_FALSE
(
reader
.
HasParseError
());
}
#ifdef __GNUC__
#pragma GCC diagnostic pop
#endif
test/unittest/writertest.cpp
View file @
0bff4ffd
...
...
@@ -121,3 +121,42 @@ TEST(Writer, Transcode) {
reader
.
Parse
<
0
>
(
s
,
writer
);
EXPECT_STREQ
(
"{
\"
hello
\"
:
\"
world
\"
,
\"
t
\"
:true,
\"
f
\"
:false,
\"
n
\"
:null,
\"
i
\"
:123,
\"
pi
\"
:3.1416,
\"
a
\"
:[1,2,3],
\"
dollar
\"
:
\"\x24\"
,
\"
cents
\"
:
\"\xC2\xA2\"
,
\"
euro
\"
:
\"\xE2\x82\xAC\"
,
\"
gclef
\"
:
\"\xF0\x9D\x84\x9E\"
}"
,
buffer
.
GetString
());
}
#include <sstream>
class
OStreamWrapper
{
public
:
typedef
char
Ch
;
OStreamWrapper
(
std
::
ostream
&
os
)
:
os_
(
os
)
{}
Ch
Peek
()
const
{
assert
(
false
);
return
'\0'
;
}
Ch
Take
()
{
assert
(
false
);
return
'\0'
;
}
size_t
Tell
()
const
{
}
Ch
*
PutBegin
()
{
assert
(
false
);
return
0
;
}
void
Put
(
Ch
c
)
{
os_
.
put
(
c
);
}
void
Flush
()
{
os_
.
flush
();
}
size_t
PutEnd
(
Ch
*
)
{
assert
(
false
);
return
0
;
}
private
:
OStreamWrapper
(
const
OStreamWrapper
&
);
OStreamWrapper
&
operator
=
(
const
OStreamWrapper
&
);
std
::
ostream
&
os_
;
};
TEST
(
Writer
,
OStreamWrapper
)
{
StringStream
s
(
"{
\"
hello
\"
:
\"
world
\"
,
\"
t
\"
: true ,
\"
f
\"
: false,
\"
n
\"
: null,
\"
i
\"
:123,
\"
pi
\"
: 3.1416,
\"
a
\"
:[1, 2, 3] } "
);
std
::
stringstream
ss
;
OStreamWrapper
os
(
ss
);
Writer
<
OStreamWrapper
>
writer
(
os
);
Reader
reader
;
reader
.
Parse
<
0
>
(
s
,
writer
);
std
::
string
actual
=
ss
.
str
();
EXPECT_STREQ
(
"{
\"
hello
\"
:
\"
world
\"
,
\"
t
\"
:true,
\"
f
\"
:false,
\"
n
\"
:null,
\"
i
\"
:123,
\"
pi
\"
:3.1416,
\"
a
\"
:[1,2,3]}"
,
actual
.
c_str
());
}
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