Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
J
json
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Libraries
json
Commits
fff46ea9
Unverified
Commit
fff46ea9
authored
May 09, 2020
by
Niels Lohmann
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
✅
add tests for binary type
parent
34430994
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
24 additions
and
2 deletions
+24
-2
include/nlohmann/detail/input/binary_reader.hpp
include/nlohmann/detail/input/binary_reader.hpp
+1
-1
single_include/nlohmann/json.hpp
single_include/nlohmann/json.hpp
+1
-1
test/src/unit-cbor.cpp
test/src/unit-cbor.cpp
+22
-0
No files found.
include/nlohmann/detail/input/binary_reader.hpp
View file @
fff46ea9
...
...
@@ -2211,7 +2211,7 @@ class binary_reader
{
success
=
false
;
}
return
static_cast
<
uint8_t
>
(
current
);
return
static_cast
<
std
::
uint8_t
>
(
current
);
});
return
success
;
}
...
...
single_include/nlohmann/json.hpp
View file @
fff46ea9
...
...
@@ -7738,7 +7738,7 @@ class binary_reader
{
success
=
false
;
}
return
static_cast
<
uint8_t
>
(
current
);
return
static_cast
<
std
::
uint8_t
>
(
current
);
});
return
success
;
}
...
...
test/src/unit-cbor.cpp
View file @
fff46ea9
...
...
@@ -1429,6 +1429,16 @@ TEST_CASE("CBOR")
}
}
SECTION
(
"indefinite size"
)
{
std
::
vector
<
std
::
uint8_t
>
input
=
{
0x5F
,
0x44
,
0xaa
,
0xbb
,
0xcc
,
0xdd
,
0x43
,
0xee
,
0xff
,
0x99
,
0xFF
};
auto
j
=
json
::
from_cbor
(
input
);
CHECK
(
j
.
is_binary
());
auto
k
=
json
::
binary_array
({
0xaa
,
0xbb
,
0xcc
,
0xdd
,
0xee
,
0xff
,
0x99
});
CAPTURE
(
j
.
dump
(
0
,
' '
,
false
,
json
::
error_handler_t
::
strict
,
true
));
CHECK
(
j
==
k
);
}
SECTION
(
"binary in array"
)
{
// array with three empty byte strings
...
...
@@ -1545,6 +1555,9 @@ TEST_CASE("CBOR")
CHECK_THROWS_AS
(
_
=
json
::
from_cbor
(
std
::
vector
<
uint8_t
>
({
0xBF
,
0x61
,
0x61
,
0xF5
})),
json
::
parse_error
&
);
CHECK_THROWS_AS
(
_
=
json
::
from_cbor
(
std
::
vector
<
uint8_t
>
({
0xA1
,
0x61
,
0X61
})),
json
::
parse_error
&
);
CHECK_THROWS_AS
(
_
=
json
::
from_cbor
(
std
::
vector
<
uint8_t
>
({
0xBF
,
0x61
,
0X61
})),
json
::
parse_error
&
);
CHECK_THROWS_AS
(
_
=
json
::
from_cbor
(
std
::
vector
<
uint8_t
>
({
0x5F
})),
json
::
parse_error
&
);
CHECK_THROWS_AS
(
_
=
json
::
from_cbor
(
std
::
vector
<
uint8_t
>
({
0x5F
,
0x00
})),
json
::
parse_error
&
);
CHECK_THROWS_AS
(
_
=
json
::
from_cbor
(
std
::
vector
<
uint8_t
>
({
0x41
})),
json
::
parse_error
&
);
CHECK_THROWS_WITH
(
_
=
json
::
from_cbor
(
std
::
vector
<
uint8_t
>
({
0x18
})),
"[json.exception.parse_error.110] parse error at byte 2: syntax error while parsing CBOR number: unexpected end of input"
);
...
...
@@ -1594,6 +1607,12 @@ TEST_CASE("CBOR")
"[json.exception.parse_error.110] parse error at byte 4: syntax error while parsing CBOR value: unexpected end of input"
);
CHECK_THROWS_WITH
(
_
=
json
::
from_cbor
(
std
::
vector
<
uint8_t
>
({
0xBF
,
0x61
,
0x61
})),
"[json.exception.parse_error.110] parse error at byte 4: syntax error while parsing CBOR value: unexpected end of input"
);
CHECK_THROWS_WITH
(
_
=
json
::
from_cbor
(
std
::
vector
<
uint8_t
>
({
0x5F
})),
"[json.exception.parse_error.110] parse error at byte 2: syntax error while parsing CBOR binary: unexpected end of input"
);
CHECK_THROWS_WITH
(
_
=
json
::
from_cbor
(
std
::
vector
<
uint8_t
>
({
0x5F
,
0x00
})),
"[json.exception.parse_error.113] parse error at byte 2: syntax error while parsing CBOR binary: expected length specification (0x40-0x5B) or indefinite binary array type (0x5F); last byte: 0x00"
);
CHECK_THROWS_WITH
(
_
=
json
::
from_cbor
(
std
::
vector
<
uint8_t
>
({
0x41
})),
"[json.exception.parse_error.110] parse error at byte 2: syntax error while parsing CBOR binary: unexpected end of input"
);
CHECK
(
json
::
from_cbor
(
std
::
vector
<
uint8_t
>
({
0x18
}),
true
,
false
).
is_discarded
());
CHECK
(
json
::
from_cbor
(
std
::
vector
<
uint8_t
>
({
0x19
}),
true
,
false
).
is_discarded
());
...
...
@@ -1619,6 +1638,9 @@ TEST_CASE("CBOR")
CHECK
(
json
::
from_cbor
(
std
::
vector
<
uint8_t
>
({
0xBF
,
0x61
,
0x61
,
0xF5
}),
true
,
false
).
is_discarded
());
CHECK
(
json
::
from_cbor
(
std
::
vector
<
uint8_t
>
({
0xA1
,
0x61
,
0x61
}),
true
,
false
).
is_discarded
());
CHECK
(
json
::
from_cbor
(
std
::
vector
<
uint8_t
>
({
0xBF
,
0x61
,
0x61
}),
true
,
false
).
is_discarded
());
CHECK
(
json
::
from_cbor
(
std
::
vector
<
uint8_t
>
({
0x5F
}),
true
,
false
).
is_discarded
());
CHECK
(
json
::
from_cbor
(
std
::
vector
<
uint8_t
>
({
0x5F
,
0x00
}),
true
,
false
).
is_discarded
());
CHECK
(
json
::
from_cbor
(
std
::
vector
<
uint8_t
>
({
0x41
}),
true
,
false
).
is_discarded
());
}
SECTION
(
"unsupported bytes"
)
...
...
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