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
9d6b3731
Unverified
Commit
9d6b3731
authored
Jan 14, 2018
by
Niels Lohmann
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
✅
improved test coverage
parent
f85f4967
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
54 additions
and
27 deletions
+54
-27
Makefile
Makefile
+1
-1
develop/detail/parsing/binary_writer.hpp
develop/detail/parsing/binary_writer.hpp
+14
-9
src/json.hpp
src/json.hpp
+14
-9
test/src/unit-ubjson.cpp
test/src/unit-ubjson.cpp
+25
-8
No files found.
Makefile
View file @
9d6b3731
...
@@ -79,7 +79,7 @@ coverage:
...
@@ -79,7 +79,7 @@ coverage:
mkdir
build_coverage
mkdir
build_coverage
cd
build_coverage
;
CXX
=
g++-5 cmake ..
-GNinja
-DJSON_Coverage
=
ON
cd
build_coverage
;
CXX
=
g++-5 cmake ..
-GNinja
-DJSON_Coverage
=
ON
cd
build_coverage
;
ninja
cd
build_coverage
;
ninja
cd
build_coverage
;
ctest
cd
build_coverage
;
ctest
-j10
cd
build_coverage
;
ninja lcov_html
cd
build_coverage
;
ninja lcov_html
open build_coverage/test/html/index.html
open build_coverage/test/html/index.html
...
...
develop/detail/parsing/binary_writer.hpp
View file @
9d6b3731
...
@@ -813,7 +813,16 @@ class binary_writer
...
@@ -813,7 +813,16 @@ class binary_writer
}
}
}
}
char
ubjson_prefix
(
const
BasicJsonType
&
j
)
/*!
@brief determine the type prefix of container values
@note This function does not need to be 100% accurate when it comes to
integer limits. In case a number exceeds the limits of int64_t,
this will be detected by a later call to function
write_number_with_ubjson_prefix. Therefore, we return 'L' for any
value that does not fit the previous limits.
*/
char
ubjson_prefix
(
const
BasicJsonType
&
j
)
const
noexcept
{
{
switch
(
j
.
type
())
switch
(
j
.
type
())
{
{
...
@@ -841,11 +850,10 @@ class binary_writer
...
@@ -841,11 +850,10 @@ class binary_writer
{
{
return
'l'
;
return
'l'
;
}
}
else
if
((
std
::
numeric_limits
<
int64_t
>::
min
)()
<=
j
.
m_value
.
number_integer
and
j
.
m_value
.
number_integer
<=
(
std
::
numeric_limits
<
int64_t
>::
max
)()
)
else
// no check and assume int64_t (see note above
)
{
{
return
'L'
;
return
'L'
;
}
}
break
;
}
}
case
value_t
:
:
number_unsigned
:
case
value_t
:
:
number_unsigned
:
...
@@ -866,11 +874,10 @@ class binary_writer
...
@@ -866,11 +874,10 @@ class binary_writer
{
{
return
'l'
;
return
'l'
;
}
}
else
if
(
j
.
m_value
.
number_unsigned
<=
(
std
::
numeric_limits
<
int64_t
>::
max
)()
)
else
// no check and assume int64_t (see note above
)
{
{
return
'L'
;
return
'L'
;
}
}
break
;
}
}
case
value_t
:
:
number_float
:
case
value_t
:
:
number_float
:
...
@@ -885,11 +892,9 @@ class binary_writer
...
@@ -885,11 +892,9 @@ class binary_writer
case
value_t
:
:
object
:
case
value_t
:
:
object
:
return
'{'
;
return
'{'
;
default:
default:
// discarded values
break
;
return
'N'
;
}
}
return
'\0'
;
}
}
private:
private:
...
...
src/json.hpp
View file @
9d6b3731
...
@@ -6965,7 +6965,16 @@ class binary_writer
...
@@ -6965,7 +6965,16 @@ class binary_writer
}
}
}
}
char
ubjson_prefix
(
const
BasicJsonType
&
j
)
/*!
@brief determine the type prefix of container values
@note This function does not need to be 100% accurate when it comes to
integer limits. In case a number exceeds the limits of int64_t,
this will be detected by a later call to function
write_number_with_ubjson_prefix. Therefore, we return 'L' for any
value that does not fit the previous limits.
*/
char
ubjson_prefix
(
const
BasicJsonType
&
j
)
const
noexcept
{
{
switch
(
j
.
type
())
switch
(
j
.
type
())
{
{
...
@@ -6993,11 +7002,10 @@ class binary_writer
...
@@ -6993,11 +7002,10 @@ class binary_writer
{
{
return
'l'
;
return
'l'
;
}
}
else
if
((
std
::
numeric_limits
<
int64_t
>::
min
)()
<=
j
.
m_value
.
number_integer
and
j
.
m_value
.
number_integer
<=
(
std
::
numeric_limits
<
int64_t
>::
max
)()
)
else
// no check and assume int64_t (see note above
)
{
{
return
'L'
;
return
'L'
;
}
}
break
;
}
}
case
value_t
:
:
number_unsigned
:
case
value_t
:
:
number_unsigned
:
...
@@ -7018,11 +7026,10 @@ class binary_writer
...
@@ -7018,11 +7026,10 @@ class binary_writer
{
{
return
'l'
;
return
'l'
;
}
}
else
if
(
j
.
m_value
.
number_unsigned
<=
(
std
::
numeric_limits
<
int64_t
>::
max
)()
)
else
// no check and assume int64_t (see note above
)
{
{
return
'L'
;
return
'L'
;
}
}
break
;
}
}
case
value_t
:
:
number_float
:
case
value_t
:
:
number_float
:
...
@@ -7037,11 +7044,9 @@ class binary_writer
...
@@ -7037,11 +7044,9 @@ class binary_writer
case
value_t
:
:
object
:
case
value_t
:
:
object
:
return
'{'
;
return
'{'
;
default:
default:
// discarded values
break
;
return
'N'
;
}
}
return
'\0'
;
}
}
private:
private:
...
...
test/src/unit-ubjson.cpp
View file @
9d6b3731
...
@@ -1386,8 +1386,8 @@ TEST_CASE("UBJSON")
...
@@ -1386,8 +1386,8 @@ TEST_CASE("UBJSON")
{
{
SECTION
(
"array of i"
)
SECTION
(
"array of i"
)
{
{
json
j
=
{
1
,
2
};
json
j
=
{
1
,
-
1
};
std
::
vector
<
uint8_t
>
expected
=
{
'['
,
'$'
,
'i'
,
'#'
,
'i'
,
2
,
1
,
2
};
std
::
vector
<
uint8_t
>
expected
=
{
'['
,
'$'
,
'i'
,
'#'
,
'i'
,
2
,
1
,
0xff
};
CHECK
(
json
::
to_ubjson
(
j
,
true
,
true
)
==
expected
);
CHECK
(
json
::
to_ubjson
(
j
,
true
,
true
)
==
expected
);
}
}
...
@@ -1400,22 +1400,22 @@ TEST_CASE("UBJSON")
...
@@ -1400,22 +1400,22 @@ TEST_CASE("UBJSON")
SECTION
(
"array of I"
)
SECTION
(
"array of I"
)
{
{
json
j
=
{
30000
,
30001
};
json
j
=
{
30000
,
-
30000
};
std
::
vector
<
uint8_t
>
expected
=
{
'['
,
'$'
,
'I'
,
'#'
,
'i'
,
2
,
0x75
,
0x30
,
0x
75
,
0x31
};
std
::
vector
<
uint8_t
>
expected
=
{
'['
,
'$'
,
'I'
,
'#'
,
'i'
,
2
,
0x75
,
0x30
,
0x
8a
,
0xd0
};
CHECK
(
json
::
to_ubjson
(
j
,
true
,
true
)
==
expected
);
CHECK
(
json
::
to_ubjson
(
j
,
true
,
true
)
==
expected
);
}
}
SECTION
(
"array of l"
)
SECTION
(
"array of l"
)
{
{
json
j
=
{
70000
,
70001
};
json
j
=
{
70000
,
-
70000
};
std
::
vector
<
uint8_t
>
expected
=
{
'['
,
'$'
,
'l'
,
'#'
,
'i'
,
2
,
0x00
,
0x01
,
0x11
,
0x70
,
0x
00
,
0x01
,
0x11
,
0x71
};
std
::
vector
<
uint8_t
>
expected
=
{
'['
,
'$'
,
'l'
,
'#'
,
'i'
,
2
,
0x00
,
0x01
,
0x11
,
0x70
,
0x
FF
,
0xFE
,
0xEE
,
0x90
};
CHECK
(
json
::
to_ubjson
(
j
,
true
,
true
)
==
expected
);
CHECK
(
json
::
to_ubjson
(
j
,
true
,
true
)
==
expected
);
}
}
SECTION
(
"array of L"
)
SECTION
(
"array of L"
)
{
{
json
j
=
{
5000000000
,
5000000001
};
json
j
=
{
5000000000
,
-
5000000000
};
std
::
vector
<
uint8_t
>
expected
=
{
'['
,
'$'
,
'L'
,
'#'
,
'i'
,
2
,
0x00
,
0x00
,
0x00
,
0x01
,
0x2A
,
0x05
,
0xF2
,
0x00
,
0x
00
,
0x00
,
0x00
,
0x01
,
0x2A
,
0x05
,
0xF2
,
0x01
};
std
::
vector
<
uint8_t
>
expected
=
{
'['
,
'$'
,
'L'
,
'#'
,
'i'
,
2
,
0x00
,
0x00
,
0x00
,
0x01
,
0x2A
,
0x05
,
0xF2
,
0x00
,
0x
FF
,
0xFF
,
0xFF
,
0xFE
,
0xD5
,
0xFA
,
0x0E
,
0x00
};
CHECK
(
json
::
to_ubjson
(
j
,
true
,
true
)
==
expected
);
CHECK
(
json
::
to_ubjson
(
j
,
true
,
true
)
==
expected
);
}
}
}
}
...
@@ -1426,37 +1426,54 @@ TEST_CASE("UBJSON")
...
@@ -1426,37 +1426,54 @@ TEST_CASE("UBJSON")
{
{
json
j
=
{
1u
,
2u
};
json
j
=
{
1u
,
2u
};
std
::
vector
<
uint8_t
>
expected
=
{
'['
,
'$'
,
'i'
,
'#'
,
'i'
,
2
,
1
,
2
};
std
::
vector
<
uint8_t
>
expected
=
{
'['
,
'$'
,
'i'
,
'#'
,
'i'
,
2
,
1
,
2
};
std
::
vector
<
uint8_t
>
expected_size
=
{
'['
,
'#'
,
'i'
,
2
,
'i'
,
1
,
'i'
,
2
};
CHECK
(
json
::
to_ubjson
(
j
,
true
,
true
)
==
expected
);
CHECK
(
json
::
to_ubjson
(
j
,
true
,
true
)
==
expected
);
CHECK
(
json
::
to_ubjson
(
j
,
true
)
==
expected_size
);
}
}
SECTION
(
"array of U"
)
SECTION
(
"array of U"
)
{
{
json
j
=
{
200u
,
201u
};
json
j
=
{
200u
,
201u
};
std
::
vector
<
uint8_t
>
expected
=
{
'['
,
'$'
,
'U'
,
'#'
,
'i'
,
2
,
0xC8
,
0xC9
};
std
::
vector
<
uint8_t
>
expected
=
{
'['
,
'$'
,
'U'
,
'#'
,
'i'
,
2
,
0xC8
,
0xC9
};
std
::
vector
<
uint8_t
>
expected_size
=
{
'['
,
'#'
,
'i'
,
2
,
'U'
,
0xC8
,
'U'
,
0xC9
};
CHECK
(
json
::
to_ubjson
(
j
,
true
,
true
)
==
expected
);
CHECK
(
json
::
to_ubjson
(
j
,
true
,
true
)
==
expected
);
CHECK
(
json
::
to_ubjson
(
j
,
true
)
==
expected_size
);
}
}
SECTION
(
"array of I"
)
SECTION
(
"array of I"
)
{
{
json
j
=
{
30000u
,
30001u
};
json
j
=
{
30000u
,
30001u
};
std
::
vector
<
uint8_t
>
expected
=
{
'['
,
'$'
,
'I'
,
'#'
,
'i'
,
2
,
0x75
,
0x30
,
0x75
,
0x31
};
std
::
vector
<
uint8_t
>
expected
=
{
'['
,
'$'
,
'I'
,
'#'
,
'i'
,
2
,
0x75
,
0x30
,
0x75
,
0x31
};
std
::
vector
<
uint8_t
>
expected_size
=
{
'['
,
'#'
,
'i'
,
2
,
'I'
,
0x75
,
0x30
,
'I'
,
0x75
,
0x31
};
CHECK
(
json
::
to_ubjson
(
j
,
true
,
true
)
==
expected
);
CHECK
(
json
::
to_ubjson
(
j
,
true
,
true
)
==
expected
);
CHECK
(
json
::
to_ubjson
(
j
,
true
)
==
expected_size
);
}
}
SECTION
(
"array of l"
)
SECTION
(
"array of l"
)
{
{
json
j
=
{
70000u
,
70001u
};
json
j
=
{
70000u
,
70001u
};
std
::
vector
<
uint8_t
>
expected
=
{
'['
,
'$'
,
'l'
,
'#'
,
'i'
,
2
,
0x00
,
0x01
,
0x11
,
0x70
,
0x00
,
0x01
,
0x11
,
0x71
};
std
::
vector
<
uint8_t
>
expected
=
{
'['
,
'$'
,
'l'
,
'#'
,
'i'
,
2
,
0x00
,
0x01
,
0x11
,
0x70
,
0x00
,
0x01
,
0x11
,
0x71
};
std
::
vector
<
uint8_t
>
expected_size
=
{
'['
,
'#'
,
'i'
,
2
,
'l'
,
0x00
,
0x01
,
0x11
,
0x70
,
'l'
,
0x00
,
0x01
,
0x11
,
0x71
};
CHECK
(
json
::
to_ubjson
(
j
,
true
,
true
)
==
expected
);
CHECK
(
json
::
to_ubjson
(
j
,
true
,
true
)
==
expected
);
CHECK
(
json
::
to_ubjson
(
j
,
true
)
==
expected_size
);
}
}
SECTION
(
"array of L"
)
SECTION
(
"array of L"
)
{
{
json
j
=
{
5000000000u
,
5000000001u
};
json
j
=
{
5000000000u
,
5000000001u
};
std
::
vector
<
uint8_t
>
expected
=
{
'['
,
'$'
,
'L'
,
'#'
,
'i'
,
2
,
0x00
,
0x00
,
0x00
,
0x01
,
0x2A
,
0x05
,
0xF2
,
0x00
,
0x00
,
0x00
,
0x00
,
0x01
,
0x2A
,
0x05
,
0xF2
,
0x01
};
std
::
vector
<
uint8_t
>
expected
=
{
'['
,
'$'
,
'L'
,
'#'
,
'i'
,
2
,
0x00
,
0x00
,
0x00
,
0x01
,
0x2A
,
0x05
,
0xF2
,
0x00
,
0x00
,
0x00
,
0x00
,
0x01
,
0x2A
,
0x05
,
0xF2
,
0x01
};
std
::
vector
<
uint8_t
>
expected_size
=
{
'['
,
'#'
,
'i'
,
2
,
'L'
,
0x00
,
0x00
,
0x00
,
0x01
,
0x2A
,
0x05
,
0xF2
,
0x00
,
'L'
,
0x00
,
0x00
,
0x00
,
0x01
,
0x2A
,
0x05
,
0xF2
,
0x01
};
CHECK
(
json
::
to_ubjson
(
j
,
true
,
true
)
==
expected
);
CHECK
(
json
::
to_ubjson
(
j
,
true
,
true
)
==
expected
);
CHECK
(
json
::
to_ubjson
(
j
,
true
)
==
expected_size
);
}
}
}
}
SECTION
(
"discarded"
)
{
json
j
=
{
json
::
value_t
::
discarded
,
json
::
value_t
::
discarded
};
std
::
vector
<
uint8_t
>
expected
=
{
'['
,
'$'
,
'N'
,
'#'
,
'i'
,
2
};
CHECK
(
json
::
to_ubjson
(
j
,
true
,
true
)
==
expected
);
}
}
}
}
}
...
...
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