Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
X
xs-test
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
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Patrick Chen
xs-test
Commits
7ad112c4
Commit
7ad112c4
authored
Aug 28, 2018
by
Patrick Chen
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
let event accept no response attribute
parent
6ca724e2
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
24 additions
and
34 deletions
+24
-34
Service.h
include/test/Service.h
+4
-8
Service.cc
src/test/Service.cc
+19
-24
Tester.cc
src/test/Tester.cc
+1
-2
No files found.
include/test/Service.h
View file @
7ad112c4
#ifndef XS_TEST_SERVER_H_INCLUDED
#define XS_TEST_SERVER_H_INCLUDED
#include <boost/optional.hpp>
#include <nlohmann/json.hpp>
#include <string>
...
...
@@ -10,11 +11,6 @@ namespace xs { namespace test
{
class
Service
final
{
public
:
enum
class
Type
{
COMMAND
,
EVENT
};
public
:
Service
()
=
delete
;
Service
(
const
Service
&
)
=
delete
;
...
...
@@ -31,12 +27,12 @@ namespace xs { namespace test
bool
isEvent
()
const
noexcept
;
private
:
Service
(
Type
type
,
std
::
string
name
,
nlohmann
::
json
response
)
noexcept
;
Service
(
std
::
string
name
,
nlohmann
::
json
response
)
noexcept
;
Service
(
std
::
string
name
)
noexcept
;
public
:
Type
type_
;
std
::
string
name_
;
nlohmann
::
json
response_
;
boost
::
optional
<
nlohmann
::
json
>
response_
;
};
}
}
...
...
src/test/Service.cc
View file @
7ad112c4
...
...
@@ -9,48 +9,43 @@ namespace xs { namespace test
{
Service
::
Service
(
const
nlohmann
::
json
&
object
)
:
Service
(
object
.
count
(
"command"
)
?
Type
::
COMMAND
:
Type
::
EVENT
,
object
[
object
.
count
(
"command"
)
?
"command"
:
"event"
].
get
<
std
::
string
>
(),
object
[
"response"
]
object
[
object
.
count
(
"command"
)
?
"command"
:
"event"
].
get
<
std
::
string
>
()
)
{
/// TODO: validate the response string here
if
(
object
.
count
(
"command"
))
{
response_
=
object
[
"response"
];
}
}
bool
Service
::
verify
(
const
nlohmann
::
json
&
object
)
noexcept
{
if
(
!
(
object
.
is_object
()
&&
(
object
.
count
(
"command"
)
||
object
.
count
(
"event"
))
&&
object
.
count
(
"response"
)))
{
if
(
!
object
.
is_object
())
{
return
false
;
}
const
bool
isCommand
=
object
.
count
(
"command"
);
return
(
(
(
isCommand
&&
object
[
"command"
].
is_string
())
||
(
!
isCommand
&&
object
[
"event"
].
is_string
())
)
&&
(
object
[
"response"
].
is_string
()
||
object
[
"response"
].
is_object
()
)
);
if
(
object
.
count
(
"command"
))
{
return
object
[
"command"
].
is_string
()
&&
(
object
[
"response"
].
is_string
()
||
object
[
"response"
].
is_object
())
;
}
else
if
(
object
.
count
(
"event"
))
{
return
object
[
"event"
].
is_string
();
}
return
false
;
}
Service
::
Service
(
Type
type
,
std
::
string
name
,
nlohmann
::
json
response
)
noexcept
:
type_
(
type
)
,
name_
(
std
::
move
(
name
))
,
response_
(
std
::
move
(
response
))
Service
::
Service
(
std
::
string
name
)
noexcept
:
name_
(
std
::
move
(
name
))
,
response_
(
boost
::
none
)
{
}
bool
Service
::
isCommand
()
const
noexcept
{
return
type_
==
Type
::
COMMAND
;
return
static_cast
<
bool
>
(
response_
)
;
}
bool
Service
::
isEvent
()
const
noexcept
{
return
type_
==
Type
::
EVENT
;
return
!
isCommand
()
;
}
}
}
src/test/Tester.cc
View file @
7ad112c4
...
...
@@ -101,14 +101,13 @@ std::string Tester::onCommand(const std::string& name, const std::string& params
receivedCommandCount_
[
name
]
++
;
return
detail
::
toString
(
response
);
return
detail
::
toString
(
*
response
);
}
void
Tester
::
onEvent
(
const
std
::
string
&
name
,
const
std
::
string
&
params
)
noexcept
{
const
auto
found
=
acceptEvents_
.
find
(
name
);
const
auto
*
service
=
std
::
get
<
1
>
(
*
found
);
const
auto
&
response
=
service
->
response_
;
receivedEventCount_
[
name
]
++
;
}
...
...
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