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
b0be3542
Commit
b0be3542
authored
Aug 27, 2018
by
Patrick Chen
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add new type 'Expectation' for scripting test
parent
574f0816
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
99 additions
and
4 deletions
+99
-4
Makefile
Makefile
+2
-2
Config.h
include/test/Config.h
+8
-1
Expectation.h
include/test/Expectation.h
+34
-0
Service.h
include/test/Service.h
+0
-1
Config.cc
src/test/Config.cc
+23
-0
Expectation.cc
src/test/Expectation.cc
+32
-0
No files found.
Makefile
View file @
b0be3542
...
...
@@ -25,8 +25,8 @@ LD_FLAGS=-L/usr/local/lib \
-lpthread
XSTEST_HDRS
=
$(INCLUDE_DIR)
/test/Config.h
$(INCLUDE_DIR)
/test/Service.h
$(INCLUDE_DIR)
/test/Tester.h
XSTEST_SRCS
=
$(SRC_DIR)
/xs-test.cc
$(SRC_DIR)
/test/Config.cc
$(SRC_DIR)
/test/Service.cc
$(SRC_DIR)
/test/Tester.cc
XSTEST_HDRS
=
$(INCLUDE_DIR)
/test/Config.h
$(INCLUDE_DIR)
/test/Service.h
$(INCLUDE_DIR)
/test/Tester.h
$(INCLUDE_DIR)
/test/Expectation.h
XSTEST_SRCS
=
$(SRC_DIR)
/xs-test.cc
$(SRC_DIR)
/test/Config.cc
$(SRC_DIR)
/test/Service.cc
$(SRC_DIR)
/test/Tester.cc
$(SRC_DIR)
/test/Expectation.cc
XSTEST_OBJS
=
$
(
subst
$(REPO_DIR)
,
$(BUILD_DIR)
,
$
(
XSTEST_SRCS:.cc
=
.o
))
HELLO_WORLD_SRCS
=
$(REPO_DIR)
/example/hello-world.cc
...
...
include/test/Config.h
View file @
b0be3542
...
...
@@ -8,6 +8,7 @@
#include <boost/range/iterator_range.hpp>
#include <nlohmann/json.hpp>
#include "test/Expectation.h"
#include "test/Service.h"
...
...
@@ -17,6 +18,7 @@ namespace xs { namespace test
{
private
:
using
service_range_type
=
std
::
deque
<
Service
>
;
using
expectation_range_type
=
std
::
deque
<
Expectation
>
;
public
:
Config
()
=
delete
;
...
...
@@ -32,11 +34,16 @@ namespace xs { namespace test
service_range_type
::
const_iterator
>
getServices
()
const
noexcept
;
boost
::
iterator_range
<
expectation_range_type
::
const_iterator
>
getExpectations
()
const
noexcept
;
private
:
static
bool
verify
(
const
nlohmann
::
json
&
object
)
noexcept
;
private
:
std
::
deque
<
Service
>
services_
;
service_range_type
services_
;
expectation_range_type
expectations_
;
};
}
}
...
...
include/test/Expectation.h
0 → 100644
View file @
b0be3542
#ifndef XS_TEST_EXPECTATION_H_INCLUDED
#define XS_TEST_EXPECTATION_H_INCLUDED
#include <nlohmann/json.hpp>
#include <string>
namespace
xs
{
namespace
test
{
class
Expectation
{
public
:
Expectation
()
=
delete
;
Expectation
(
const
Expectation
&
)
=
delete
;
Expectation
(
Expectation
&&
)
noexcept
=
default
;
~
Expectation
()
noexcept
=
default
;
Expectation
&
operator
=
(
const
Expectation
&
)
=
delete
;
Expectation
&
operator
=
(
Expectation
&&
)
=
delete
;
explicit
Expectation
(
const
nlohmann
::
json
&
object
);
static
bool
verify
(
const
nlohmann
::
json
&
object
)
noexcept
;
private
:
Expectation
(
std
::
string
name
,
nlohmann
::
json
value
)
noexcept
;
public
:
std
::
string
name_
;
nlohmann
::
json
value_
;
};
}
}
#endif
include/test/Service.h
View file @
b0be3542
...
...
@@ -3,7 +3,6 @@
#include <nlohmann/json.hpp>
#include <memory>
#include <string>
...
...
src/test/Config.cc
View file @
b0be3542
...
...
@@ -41,6 +41,10 @@ Config::Config(const boost::filesystem::path& file)
for
(
const
auto
element
:
object
[
"mockData"
])
{
services_
.
emplace_back
(
Service
(
element
));
}
for
(
const
auto
element
:
object
[
"script"
])
{
expectations_
.
emplace_back
(
Expectation
(
element
));
}
}
boost
::
iterator_range
<
...
...
@@ -52,18 +56,37 @@ boost::iterator_range<
);
}
boost
::
iterator_range
<
Config
::
expectation_range_type
::
const_iterator
>
Config
::
getExpectations
()
const
noexcept
{
return
boost
::
make_iterator_range
(
std
::
begin
(
expectations_
),
std
::
end
(
expectations_
)
);
}
bool
Config
::
verify
(
const
nlohmann
::
json
&
object
)
noexcept
{
if
(
!
(
object
.
count
(
"mockData"
)
&&
object
[
"mockData"
].
is_array
()))
{
return
false
;
}
if
(
!
(
object
.
count
(
"script"
)
&&
object
[
"script"
].
is_array
()))
{
return
false
;
}
for
(
const
auto
element
:
object
[
"mockData"
])
{
if
(
!
Service
::
verify
(
element
))
{
return
false
;
}
}
for
(
const
auto
element
:
object
[
"script"
])
{
if
(
!
Expectation
::
verify
(
element
))
{
return
false
;
}
}
return
true
;
}
...
...
src/test/Expectation.cc
0 → 100644
View file @
b0be3542
#include "test/Expectation.h"
#include <nlohmann/json.hpp>
namespace
xs
{
namespace
test
{
Expectation
::
Expectation
(
const
nlohmann
::
json
&
object
)
:
Expectation
(
object
[
"command"
].
get
<
std
::
string
>
(),
object
[
"expect"
])
{
}
bool
Expectation
::
verify
(
const
nlohmann
::
json
&
object
)
noexcept
{
if
(
!
(
object
.
is_object
()
&&
object
.
count
(
"command"
)
&&
object
.
count
(
"expect"
)))
{
return
false
;
}
return
(
object
[
"command"
].
is_string
()
&&
(
object
[
"expect"
].
is_string
()
||
object
[
"expect"
].
is_object
()
)
);
}
Expectation
::
Expectation
(
std
::
string
name
,
nlohmann
::
json
value
)
noexcept
:
name_
(
std
::
move
(
name
))
,
value_
(
std
::
move
(
value
))
{
}
}
}
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