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
872aba66
Commit
872aba66
authored
Apr 14, 2015
by
Milo Yip
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Improve coverage of encoded streams
parent
4be4857a
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
26 additions
and
15 deletions
+26
-15
encodedstream.h
include/rapidjson/encodedstream.h
+3
-4
encodedstreamtest.cpp
test/unittest/encodedstreamtest.cpp
+23
-11
No files found.
include/rapidjson/encodedstream.h
View file @
872aba66
...
...
@@ -109,6 +109,7 @@ public:
\param type UTF encoding type if it is not detected from the stream.
*/
AutoUTFInputStream
(
InputByteStream
&
is
,
UTFType
type
=
kUTF8
)
:
is_
(
&
is
),
type_
(
type
),
hasBOM_
(
false
)
{
RAPIDJSON_ASSERT
(
type
>=
kUTF8
&&
type
<=
kUTF32BE
);
DetectType
();
static
const
TakeFunc
f
[]
=
{
RAPIDJSON_ENCODINGS_FUNC
(
Take
)
};
takeFunc_
=
f
[
type_
];
...
...
@@ -189,8 +190,6 @@ private:
case
kUTF32BE
:
RAPIDJSON_ASSERT
(
sizeof
(
Ch
)
>=
4
);
break
;
default:
RAPIDJSON_ASSERT
(
false
);
// Invalid type
}
}
...
...
@@ -220,6 +219,8 @@ public:
\param putBOM Whether to write BOM at the beginning of the stream.
*/
AutoUTFOutputStream
(
OutputByteStream
&
os
,
UTFType
type
,
bool
putBOM
)
:
os_
(
&
os
),
type_
(
type
)
{
RAPIDJSON_ASSERT
(
type
>=
kUTF8
&&
type
<=
kUTF32BE
);
// RUntime check whether the size of character type is sufficient. It only perform checks with assertion.
switch
(
type_
)
{
case
kUTF16LE
:
...
...
@@ -233,8 +234,6 @@ public:
case
kUTF8
:
// Do nothing
break
;
default
:
RAPIDJSON_ASSERT
(
false
);
// Invalid UTFType
}
static
const
PutFunc
f
[]
=
{
RAPIDJSON_ENCODINGS_FUNC
(
Put
)
};
...
...
test/unittest/encodedstreamtest.cpp
View file @
872aba66
...
...
@@ -119,10 +119,11 @@ protected:
}
EXPECT_EQ
(
'\0'
,
s
.
Peek
());
free
(
data
);
EXPECT_EQ
(
size
,
eis
.
Tell
());
}
}
void
TestAutoUTFInputStream
(
const
char
*
filename
)
{
void
TestAutoUTFInputStream
(
const
char
*
filename
,
bool
expectHasBOM
)
{
// Test FileReadStream
{
char
buffer
[
16
];
...
...
@@ -130,6 +131,7 @@ protected:
ASSERT_TRUE
(
fp
!=
0
);
FileReadStream
fs
(
fp
,
buffer
,
sizeof
(
buffer
));
AutoUTFInputStream
<
unsigned
,
FileReadStream
>
eis
(
fs
);
EXPECT_EQ
(
expectHasBOM
,
eis
.
HasBOM
());
StringStream
s
(
json_
);
while
(
eis
.
Peek
()
!=
'\0'
)
{
unsigned
expected
,
actual
;
...
...
@@ -147,6 +149,7 @@ protected:
char
*
data
=
ReadFile
(
filename
,
true
,
&
size
);
MemoryStream
ms
(
data
,
size
);
AutoUTFInputStream
<
unsigned
,
MemoryStream
>
eis
(
ms
);
EXPECT_EQ
(
expectHasBOM
,
eis
.
HasBOM
());
StringStream
s
(
json_
);
while
(
eis
.
Peek
()
!=
'\0'
)
{
...
...
@@ -264,16 +267,25 @@ TEST_F(EncodedStreamTest, EncodedInputStream) {
}
TEST_F
(
EncodedStreamTest
,
AutoUTFInputStream
)
{
TestAutoUTFInputStream
(
"utf8.json"
);
TestAutoUTFInputStream
(
"utf8bom.json"
);
TestAutoUTFInputStream
(
"utf16le.json"
);
TestAutoUTFInputStream
(
"utf16lebom.json"
);
TestAutoUTFInputStream
(
"utf16be.json"
);
TestAutoUTFInputStream
(
"utf16bebom.json"
);
TestAutoUTFInputStream
(
"utf32le.json"
);
TestAutoUTFInputStream
(
"utf32lebom.json"
);
TestAutoUTFInputStream
(
"utf32be.json"
);
TestAutoUTFInputStream
(
"utf32bebom.json"
);
TestAutoUTFInputStream
(
"utf8.json"
,
false
);
TestAutoUTFInputStream
(
"utf8bom.json"
,
true
);
TestAutoUTFInputStream
(
"utf16le.json"
,
false
);
TestAutoUTFInputStream
(
"utf16lebom.json"
,
true
);
TestAutoUTFInputStream
(
"utf16be.json"
,
false
);
TestAutoUTFInputStream
(
"utf16bebom.json"
,
true
);
TestAutoUTFInputStream
(
"utf32le.json"
,
false
);
TestAutoUTFInputStream
(
"utf32lebom.json"
,
true
);
TestAutoUTFInputStream
(
"utf32be.json"
,
false
);
TestAutoUTFInputStream
(
"utf32bebom.json"
,
true
);
{
// Auto detection fail, use user defined UTF type
const
char
json
[]
=
"{}"
;
MemoryStream
ms
(
json
,
sizeof
(
json
));
AutoUTFInputStream
<
unsigned
,
MemoryStream
>
eis
(
ms
,
kUTF8
);
EXPECT_FALSE
(
eis
.
HasBOM
());
EXPECT_EQ
(
kUTF8
,
eis
.
GetType
());
}
}
TEST_F
(
EncodedStreamTest
,
EncodedOutputStream
)
{
...
...
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