Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
A
Actor Framework
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
Operations
Operations
Metrics
Environments
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
cpp-libs
Actor Framework
Commits
04a26387
Commit
04a26387
authored
Feb 15, 2021
by
Dominik Charousset
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix handling of member maps in the JSON reader
parent
b6c394c5
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
64 additions
and
3 deletions
+64
-3
libcaf_core/src/json_reader.cpp
libcaf_core/src/json_reader.cpp
+4
-3
libcaf_core/test/core-test.hpp
libcaf_core/test/core-test.hpp
+22
-0
libcaf_core/test/json_reader.cpp
libcaf_core/test/json_reader.cpp
+6
-0
libcaf_core/test/json_writer.cpp
libcaf_core/test/json_writer.cpp
+32
-0
No files found.
libcaf_core/src/json_reader.cpp
View file @
04a26387
...
...
@@ -356,9 +356,10 @@ bool json_reader::begin_associative_array(size_t& size) {
FN_DECL
;
return
consume
<
false
>
(
fn
,
[
this
,
&
size
](
const
detail
::
json
::
value
&
val
)
{
if
(
val
.
data
.
index
()
==
detail
::
json
::
value
::
object_index
)
{
auto
&
obj
=
get
<
detail
::
json
::
object
>
(
val
.
data
);
size
=
obj
.
size
();
push
(
members
{
obj
.
begin
(),
obj
.
end
()});
auto
*
obj
=
std
::
addressof
(
get
<
detail
::
json
::
object
>
(
val
.
data
));
pop
();
size
=
obj
->
size
();
push
(
members
{
obj
->
begin
(),
obj
->
end
()});
return
true
;
}
else
{
emplace_error
(
sec
::
runtime_error
,
class_name
,
fn
,
...
...
libcaf_core/test/core-test.hpp
View file @
04a26387
...
...
@@ -347,6 +347,27 @@ bool inspect(Inspector& f, dummy_user& x) {
f
.
field
(
"nickname"
,
x
.
nickname
));
}
struct
phone_book
{
std
::
string
city
;
std
::
map
<
std
::
string
,
int64_t
>
entries
;
};
[[
maybe_unused
]]
constexpr
bool
operator
==
(
const
phone_book
&
x
,
const
phone_book
&
y
)
noexcept
{
return
std
::
tie
(
x
.
city
,
x
.
entries
)
==
std
::
tie
(
y
.
city
,
y
.
entries
);
}
[[
maybe_unused
]]
constexpr
bool
operator
!=
(
const
phone_book
&
x
,
const
phone_book
&
y
)
noexcept
{
return
!
(
x
==
y
);
}
template
<
class
Inspector
>
bool
inspect
(
Inspector
&
f
,
phone_book
&
x
)
{
return
f
.
object
(
x
).
fields
(
f
.
field
(
"city"
,
x
.
city
),
f
.
field
(
"entries"
,
x
.
entries
));
}
// -- type IDs for for all unit test suites ------------------------------------
#define ADD_TYPE_ID(type) CAF_ADD_TYPE_ID(core_test, type)
...
...
@@ -370,6 +391,7 @@ CAF_BEGIN_TYPE_ID_BLOCK(core_test, caf::first_custom_type_id)
ADD_TYPE_ID
((
int_actor
))
ADD_TYPE_ID
((
level
))
ADD_TYPE_ID
((
my_request
))
ADD_TYPE_ID
((
phone_book
))
ADD_TYPE_ID
((
point
))
ADD_TYPE_ID
((
raw_struct
))
ADD_TYPE_ID
((
rectangle
))
...
...
libcaf_core/test/json_reader.cpp
View file @
04a26387
...
...
@@ -87,6 +87,12 @@ fixture::fixture() {
add_test_case
(
R"_({"top-left":{"x":100,"y":200},"bottom-right":{"x":10,"y":20}})_"
,
rectangle
{{
100
,
200
},
{
10
,
20
}});
add_test_case
(
R"({"@type": "phone_book",)"
R"( "city": "Model City",)"
R"( "entries": )"
R"({"Bob": 5556837,)"
R"( "Jon": 5559347}})"
,
phone_book
{
"Model City"
,
{{
"Bob"
,
5556837
},
{
"Jon"
,
5559347
}}});
}
}
// namespace
...
...
libcaf_core/test/json_writer.cpp
View file @
04a26387
...
...
@@ -175,6 +175,38 @@ SCENARIO("the JSON writer converts nested structs to strings") {
}
}
SCENARIO
(
"the JSON writer converts structs with member dictionaries"
)
{
GIVEN
(
"a phone_book object"
)
{
phone_book
x
;
x
.
city
=
"Model City"
;
x
.
entries
[
"Bob"
]
=
555'6837
;
x
.
entries
[
"Jon"
]
=
555'9347
;
WHEN
(
"converting it to JSON with indentation factor 0"
)
{
THEN
(
"the JSON output is a single line"
)
{
std
::
string
out
=
R"({"@type": "phone_book",)"
R"( "city": "Model City",)"
R"( "entries": )"
R"({"Bob": 5556837,)"
R"( "Jon": 5559347}})"
;
CHECK_EQ
(
to_json_string
(
x
,
0
),
out
);
}
}
WHEN
(
"converting it to JSON with indentation factor 2"
)
{
THEN
(
"the JSON output uses multiple lines"
)
{
std
::
string
out
=
R"({
"@type": "phone_book",
"city": "Model City",
"entries": {
"Bob": 5556837,
"Jon": 5559347
}
})"
;
CHECK_EQ
(
to_json_string
(
x
,
2
),
out
);
}
}
}
}
SCENARIO
(
"the JSON writer omits or nulls missing values"
)
{
GIVEN
(
"a dummy_user object without nickname"
)
{
dummy_user
user
;
...
...
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