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
977e708e
Commit
977e708e
authored
Aug 28, 2018
by
Patrick Chen
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
handle command with diff params
parent
e1b7d7de
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
30 additions
and
12 deletions
+30
-12
Tester.h
include/test/Tester.h
+0
-2
Tester.cc
src/test/Tester.cc
+30
-10
No files found.
include/test/Tester.h
View file @
977e708e
...
@@ -47,8 +47,6 @@ namespace xs { namespace test
...
@@ -47,8 +47,6 @@ namespace xs { namespace test
private
:
private
:
Config
config_
;
Config
config_
;
ExchangeServer
server_
;
ExchangeServer
server_
;
std
::
unordered_map
<
std
::
string
,
const
Service
*>
acceptCommands_
;
std
::
unordered_map
<
std
::
string
,
const
Service
*>
acceptEvents_
;
std
::
unordered_map
<
std
::
string
,
unsigned
>
receivedCommandCount_
;
std
::
unordered_map
<
std
::
string
,
unsigned
>
receivedCommandCount_
;
std
::
unordered_map
<
std
::
string
,
unsigned
>
receivedEventCount_
;
std
::
unordered_map
<
std
::
string
,
unsigned
>
receivedEventCount_
;
};
};
...
...
src/test/Tester.cc
View file @
977e708e
...
@@ -32,9 +32,6 @@ Tester::Tester(const boost::filesystem::path& file)
...
@@ -32,9 +32,6 @@ Tester::Tester(const boost::filesystem::path& file)
void
Tester
::
registerServices
()
noexcept
void
Tester
::
registerServices
()
noexcept
{
{
acceptCommands_
.
clear
();
acceptEvents_
.
clear
();
using
namespace
std
::
placeholders
;
using
namespace
std
::
placeholders
;
for
(
const
auto
&
service
:
config_
.
getServices
())
{
for
(
const
auto
&
service
:
config_
.
getServices
())
{
if
(
service
.
isCommand
())
{
if
(
service
.
isCommand
())
{
...
@@ -42,13 +39,11 @@ void Tester::registerServices() noexcept
...
@@ -42,13 +39,11 @@ void Tester::registerServices() noexcept
service
.
name_
,
service
.
name_
,
std
::
bind
(
&
Tester
::
onCommand
,
this
,
_1
,
_2
)
std
::
bind
(
&
Tester
::
onCommand
,
this
,
_1
,
_2
)
);
);
acceptCommands_
[
service
.
name_
]
=
&
service
;
}
else
{
}
else
{
server_
.
onEvent
(
server_
.
onEvent
(
service
.
name_
,
service
.
name_
,
std
::
bind
(
&
Tester
::
onEvent
,
this
,
_1
,
_2
)
std
::
bind
(
&
Tester
::
onEvent
,
this
,
_1
,
_2
)
);
);
acceptEvents_
[
service
.
name_
]
=
&
service
;
}
}
}
}
}
}
...
@@ -95,13 +90,38 @@ Tester::Report Tester::createReport(const std::string& response, const Expectati
...
@@ -95,13 +90,38 @@ Tester::Report Tester::createReport(const std::string& response, const Expectati
std
::
string
Tester
::
onCommand
(
const
std
::
string
&
name
,
const
std
::
string
&
params
)
noexcept
std
::
string
Tester
::
onCommand
(
const
std
::
string
&
name
,
const
std
::
string
&
params
)
noexcept
{
{
const
auto
found
=
acceptCommands_
.
find
(
name
);
using
namespace
boost
::
adaptors
;
const
auto
*
service
=
std
::
get
<
1
>
(
*
found
);
using
namespace
std
::
placeholders
;
const
auto
&
response
=
service
->
response_
;
const
auto
handlers
=
config_
.
getServices
()
|
filtered
(
std
::
bind
(
&
Service
::
isCommand
,
_1
));
for
(
const
auto
&
handler
:
handlers
)
{
if
(
handler
.
name_
!=
name
)
{
continue
;
}
if
(
!
handler
.
condition_
)
{
receivedCommandCount_
[
name
]
++
;
return
detail
::
toString
(
*
handler
.
response_
);
}
receivedCommandCount_
[
name
]
++
;
auto
&
receiveCount
=
receivedCommandCount_
[
name
];
const
auto
&
condition
=
*
handler
.
condition_
;
const
bool
isString
=
condition
.
is_string
();
if
(
isString
)
{
if
(
params
==
condition
.
get
<
std
::
string
>
())
{
receiveCount
++
;
return
detail
::
toString
(
*
handler
.
response_
);
}
}
else
{
if
(
nlohmann
::
json
::
parse
(
params
)
==
condition
)
{
receiveCount
++
;
return
detail
::
toString
(
*
handler
.
response_
);
}
}
}
return
detail
::
toString
(
*
response
)
;
return
""
;
}
}
void
Tester
::
onEvent
(
const
std
::
string
&
name
,
const
std
::
string
&
params
)
noexcept
void
Tester
::
onEvent
(
const
std
::
string
&
name
,
const
std
::
string
&
params
)
noexcept
...
...
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