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
be973e52
Commit
be973e52
authored
Dec 07, 2016
by
Niels Lohmann
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
✅
more msgpack test cases
parent
a1693bfe
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
91 additions
and
1 deletion
+91
-1
test/src/unit-msgpack.cpp
test/src/unit-msgpack.cpp
+91
-1
No files found.
test/src/unit-msgpack.cpp
View file @
be973e52
...
...
@@ -214,6 +214,47 @@ TEST_CASE("MessagePack")
CHECK
(
json
::
from_msgpack
(
result
)
==
j
);
}
}
SECTION
(
"-32769..-2147483648"
)
{
for
(
int32_t
i
:
{
-
32769l
,
-
65536l
,
-
77777l
,
-
1048576l
,
-
2147483648l
})
{
CAPTURE
(
i
);
// create JSON value with integer number
json
j
=
i
;
// check type
CHECK
(
j
.
is_number_integer
());
// create expected byte vector
std
::
vector
<
uint8_t
>
expected
;
expected
.
push_back
(
0xd2
);
expected
.
push_back
(
static_cast
<
uint8_t
>
((
i
>>
24
)
&
0xff
));
expected
.
push_back
(
static_cast
<
uint8_t
>
((
i
>>
16
)
&
0xff
));
expected
.
push_back
(
static_cast
<
uint8_t
>
((
i
>>
8
)
&
0xff
));
expected
.
push_back
(
static_cast
<
uint8_t
>
(
i
&
0xff
));
// compare result + size
const
auto
result
=
json
::
to_msgpack
(
j
);
CHECK
(
result
==
expected
);
CHECK
(
result
.
size
()
==
5
);
// check individual bytes
CHECK
(
result
[
0
]
==
0xd2
);
uint32_t
restored
=
static_cast
<
uint32_t
>
((
static_cast
<
uint32_t
>
(
result
[
1
])
<<
030
)
+
(
static_cast
<
uint32_t
>
(
result
[
2
])
<<
020
)
+
(
static_cast
<
uint32_t
>
(
result
[
3
])
<<
010
)
+
static_cast
<
uint32_t
>
(
result
[
4
]));
CHECK
(
restored
==
i
);
// roundtrip
CHECK
(
json
::
from_msgpack
(
result
)
==
j
);
}
}
}
SECTION
(
"unsigned"
)
...
...
@@ -316,7 +357,7 @@ TEST_CASE("MessagePack")
{
for
(
uint32_t
i
:
{
65536u
,
77777u
,
1048576u
65536u
,
77777u
,
1048576u
,
4294967295u
})
{
CAPTURE
(
i
);
...
...
@@ -352,6 +393,55 @@ TEST_CASE("MessagePack")
CHECK
(
json
::
from_msgpack
(
result
)
==
j
);
}
}
SECTION
(
"4294967296..18446744073709551615 (uint 64)"
)
{
for
(
uint64_t
i
:
{
4294967296lu
,
18446744073709551615lu
})
{
CAPTURE
(
i
);
// create JSON value with unsigned integer number
json
j
=
i
;
// check type
CHECK
(
j
.
is_number_unsigned
());
// create expected byte vector
std
::
vector
<
uint8_t
>
expected
;
expected
.
push_back
(
0xcf
);
expected
.
push_back
(
static_cast
<
uint8_t
>
((
i
>>
070
)
&
0xff
));
expected
.
push_back
(
static_cast
<
uint8_t
>
((
i
>>
060
)
&
0xff
));
expected
.
push_back
(
static_cast
<
uint8_t
>
((
i
>>
050
)
&
0xff
));
expected
.
push_back
(
static_cast
<
uint8_t
>
((
i
>>
040
)
&
0xff
));
expected
.
push_back
(
static_cast
<
uint8_t
>
((
i
>>
030
)
&
0xff
));
expected
.
push_back
(
static_cast
<
uint8_t
>
((
i
>>
020
)
&
0xff
));
expected
.
push_back
(
static_cast
<
uint8_t
>
((
i
>>
010
)
&
0xff
));
expected
.
push_back
(
static_cast
<
uint8_t
>
(
i
&
0xff
));
// compare result + size
const
auto
result
=
json
::
to_msgpack
(
j
);
CHECK
(
result
==
expected
);
CHECK
(
result
.
size
()
==
9
);
// check individual bytes
CHECK
(
result
[
0
]
==
0xcf
);
uint64_t
restored
=
static_cast
<
uint64_t
>
((
static_cast
<
uint64_t
>
(
result
[
1
])
<<
070
)
+
(
static_cast
<
uint64_t
>
(
result
[
2
])
<<
060
)
+
(
static_cast
<
uint64_t
>
(
result
[
3
])
<<
050
)
+
(
static_cast
<
uint64_t
>
(
result
[
4
])
<<
040
)
+
(
static_cast
<
uint64_t
>
(
result
[
5
])
<<
030
)
+
(
static_cast
<
uint64_t
>
(
result
[
6
])
<<
020
)
+
(
static_cast
<
uint64_t
>
(
result
[
7
])
<<
010
)
+
static_cast
<
uint64_t
>
(
result
[
8
]));
CHECK
(
restored
==
i
);
// roundtrip
CHECK
(
json
::
from_msgpack
(
result
)
==
j
);
}
}
}
SECTION
(
"float"
)
...
...
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