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
1bfa188d
Commit
1bfa188d
authored
Apr 15, 2016
by
Milo Yip
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Improve encodings coverage
parent
105c92ee
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
63 additions
and
14 deletions
+63
-14
encodingstest.cpp
test/unittest/encodingstest.cpp
+25
-0
writertest.cpp
test/unittest/writertest.cpp
+38
-14
No files found.
test/unittest/encodingstest.cpp
View file @
1bfa188d
...
...
@@ -423,3 +423,28 @@ TEST(EncodingsTest, UTF32) {
}
}
}
TEST
(
EncodingsTest
,
ASCII
)
{
StringBuffer
os
,
os2
;
for
(
unsigned
codepoint
=
0
;
codepoint
<
128
;
codepoint
++
)
{
os
.
Clear
();
ASCII
<>::
Encode
(
os
,
codepoint
);
const
ASCII
<>::
Ch
*
encodedStr
=
os
.
GetString
();
{
StringStream
is
(
encodedStr
);
unsigned
decodedCodepoint
;
bool
result
=
ASCII
<>::
Decode
(
is
,
&
decodedCodepoint
);
if
(
!
result
||
codepoint
!=
decodedCodepoint
)
std
::
cout
<<
std
::
hex
<<
codepoint
<<
" "
<<
decodedCodepoint
<<
std
::
endl
;
}
// Validate
{
StringStream
is
(
encodedStr
);
os2
.
Clear
();
bool
result
=
ASCII
<>::
Validate
(
is
,
os2
);
EXPECT_TRUE
(
result
);
EXPECT_EQ
(
0
,
StrCmp
(
encodedStr
,
os2
.
GetString
()));
}
}
}
test/unittest/writertest.cpp
View file @
1bfa188d
...
...
@@ -18,6 +18,7 @@
#include "rapidjson/reader.h"
#include "rapidjson/writer.h"
#include "rapidjson/stringbuffer.h"
#include "rapidjson/memorybuffer.h"
using
namespace
rapidjson
;
...
...
@@ -107,35 +108,58 @@ TEST(Writer, Double) {
}
// UTF8 -> TargetEncoding -> UTF8
template
<
typename
TargetEncoding
>
void
TestTranscode
(
const
char
*
json
)
{
StringStream
s
(
json
);
GenericStringBuffer
<
TargetEncoding
>
buffer
;
Writer
<
GenericStringBuffer
<
TargetEncoding
>
,
UTF8
<>
,
TargetEncoding
>
writer
(
buffer
);
Reader
reader
;
reader
.
Parse
(
s
,
writer
);
StringBuffer
buffer2
;
Writer
<
StringBuffer
>
writer2
(
buffer2
);
GenericReader
<
TargetEncoding
,
UTF8
<>
>
reader2
;
GenericStringStream
<
TargetEncoding
>
s2
(
buffer
.
GetString
());
reader2
.
Parse
(
s2
,
writer2
);
EXPECT_STREQ
(
json
,
buffer2
.
GetString
());
}
TEST
(
Writer
,
Transcode
)
{
const
char
json
[]
=
"{
\"
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\"
}"
;
// UTF8 -> UTF16 -> UTF8
{
StringStream
s
(
json
);
StringBuffer
buffer
;
Writer
<
StringBuffer
,
UTF16
<>
,
UTF8
<>
>
writer
(
buffer
);
GenericReader
<
UTF8
<>
,
UTF16
<>
>
reader
;
reader
.
Parse
(
s
,
writer
);
EXPECT_STREQ
(
json
,
buffer
.
GetString
());
}
TestTranscode
<
UTF8
<>
>
(
json
);
// UTF8 -> ASCII -> UTF8
TestTranscode
<
ASCII
<>
>
(
json
);
// UTF8 -> UTF16 -> UTF8
TestTranscode
<
UTF16
<>
>
(
json
);
// UTF8 -> UTF32 -> UTF8
TestTranscode
<
UTF32
<>
>
(
json
);
// UTF8 ->
UTF8 -> ASCII -> UTF8
-> UTF8
// UTF8 ->
AutoUTF (UTF16BE)
-> UTF8
{
StringStream
s
(
json
);
StringBuffer
buffer
;
Writer
<
StringBuffer
,
UTF8
<>
,
ASCII
<>
>
writer
(
buffer
);
MemoryBuffer
buffer
;
AutoUTFOutputStream
<
unsigned
,
MemoryBuffer
>
os
(
buffer
,
kUTF16BE
,
true
);
Writer
<
AutoUTFOutputStream
<
unsigned
,
MemoryBuffer
>
,
UTF8
<>
,
AutoUTF
<
unsigned
>
>
writer
(
os
);
Reader
reader
;
reader
.
Parse
(
s
,
writer
);
StringBuffer
buffer2
;
Writer
<
StringBuffer
>
writer2
(
buffer2
);
GenericReader
<
ASCII
<>
,
UTF8
<>
>
reader2
;
StringStream
s2
(
buffer
.
GetString
());
reader2
.
Parse
(
s2
,
writer2
);
GenericReader
<
AutoUTF
<
unsigned
>
,
UTF8
<>
>
reader2
;
MemoryStream
s2
(
buffer
.
GetBuffer
(),
buffer
.
GetSize
());
AutoUTFInputStream
<
unsigned
,
MemoryStream
>
is
(
s2
);
reader2
.
Parse
(
is
,
writer2
);
EXPECT_STREQ
(
json
,
buffer2
.
GetString
());
}
}
#include <sstream>
...
...
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