Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
U
uniset2
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
1
Issues
1
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
UniSet project repositories
uniset2
Commits
c3c97227
Commit
c3c97227
authored
Oct 08, 2014
by
Pavel Vainerman
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
(tests): добавил тесты для TriggerOR и Trigger
parent
a510d139
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
136 additions
and
20 deletions
+136
-20
TriggerOR.h
include/TriggerOR.h
+0
-2
TriggerOR.tcc
include/TriggerOR.tcc
+6
-16
Makefile.am
tests/Makefile.am
+3
-2
trigger.cc
tests/trigger.cc
+33
-0
triggerOR.cc
tests/triggerOR.cc
+94
-0
No files found.
include/TriggerOR.h
View file @
c3c97227
...
@@ -86,7 +86,6 @@ class TriggerOR
...
@@ -86,7 +86,6 @@ class TriggerOR
inline
bool
state
(){
return
out
;
}
inline
bool
state
(){
return
out
;
}
bool
getState
(
InputType
in
);
bool
getState
(
InputType
in
);
bool
commit
(
InputType
in
,
bool
state
);
bool
commit
(
InputType
in
,
bool
state
);
...
@@ -115,7 +114,6 @@ class TriggerOR
...
@@ -115,7 +114,6 @@ class TriggerOR
bool
out
;
bool
out
;
Caller
*
cal
;
Caller
*
cal
;
Action
act
;
Action
act
;
};
};
//---------------------------------------------------------------------------
//---------------------------------------------------------------------------
...
...
include/TriggerOR.tcc
View file @
c3c97227
...
@@ -25,6 +25,7 @@
...
@@ -25,6 +25,7 @@
//---------------------------------------------------------------------------
//---------------------------------------------------------------------------
template<class Caller, typename InputType>
template<class Caller, typename InputType>
TriggerOR<Caller,InputType>::TriggerOR(Caller* c, Action a):
TriggerOR<Caller,InputType>::TriggerOR(Caller* c, Action a):
out(false),
cal(c),
cal(c),
act(a)
act(a)
{
{
...
@@ -84,21 +85,16 @@ template<class Caller, typename InputType>
...
@@ -84,21 +85,16 @@ template<class Caller, typename InputType>
void TriggerOR<Caller,InputType>::check()
void TriggerOR<Caller,InputType>::check()
{
{
bool old = out;
bool old = out;
for(
typename InputMap::iterator
it=inputs.begin(); it!=inputs.end(); ++it )
for(
auto
it=inputs.begin(); it!=inputs.end(); ++it )
{
{
if( it->second )
if( it->second )
{
{
// если хоть один вход "1" на выходе "1"
// если хоть один вход "1"
выставляем
на выходе "1"
// и прекращаем дальнейший поиск
// и прекращаем дальнейший поиск
out = true;
out = true;
if( old != out )
if( old != out )
{
(cal->*act)(out);
// try
// {
(cal->*act)(out);
// }
// catch(...){}
}
return;
return;
}
}
}
}
...
@@ -106,13 +102,7 @@ void TriggerOR<Caller,InputType>::check()
...
@@ -106,13 +102,7 @@ void TriggerOR<Caller,InputType>::check()
out = false;
out = false;
if( old != out )
if( old != out )
{
(cal->*act)(out);
// try
// {
(cal->*act)(out);
// }
// catch(...){}
}
}
}
//---------------------------------------------------------------------------
//---------------------------------------------------------------------------
template<class Caller, typename InputType>
template<class Caller, typename InputType>
...
...
tests/Makefile.am
View file @
c3c97227
...
@@ -2,11 +2,12 @@
...
@@ -2,11 +2,12 @@
# This file is part of the UniSet library #
# This file is part of the UniSet library #
############################################################################
############################################################################
check_PROGRAMS
=
tests tests_with_conf
#check_PROGRAMS = tests tests_with_conf
noinst_PROGRAMS
=
tests tests_with_conf
#umutex threadtst dlog
#umutex threadtst dlog
tests_SOURCES
=
tests.cc passivetimer.cc hourglass.cc delaytimer.cc unixml.cc sscanf_hex.cc
\
tests_SOURCES
=
tests.cc passivetimer.cc hourglass.cc delaytimer.cc unixml.cc sscanf_hex.cc
\
callbacktimer.cc
callbacktimer.cc
trigger.cc triggerOR.cc triggerAND.cc
tests_LDADD
=
$(top_builddir)
/lib/libUniSet2.la
$(SIGC_LIBS)
$(COMCPP_LIBS)
tests_LDADD
=
$(top_builddir)
/lib/libUniSet2.la
$(SIGC_LIBS)
$(COMCPP_LIBS)
tests_CPPFLAGS
=
-I
$(top_builddir)
/include
-I
$(includedir)
/Catch
$(SIGC_CFLAGS)
$(COMCPP_CFLAGS)
tests_CPPFLAGS
=
-I
$(top_builddir)
/include
-I
$(includedir)
/Catch
$(SIGC_CFLAGS)
$(COMCPP_CFLAGS)
...
...
tests/trigger.cc
0 → 100644
View file @
c3c97227
#include <catch.hpp>
// --------------------------------------------------------------------------
#include "Trigger.h"
// --------------------------------------------------------------------------
using
namespace
std
;
// --------------------------------------------------------------------------
TEST_CASE
(
"Trigger"
,
"[Trigger]"
)
{
SECTION
(
"Constructor"
)
{
Trigger
tr
;
CHECK_FALSE
(
tr
.
hi
(
false
)
);
CHECK
(
tr
.
hi
(
true
)
);
Trigger
trHi
;
CHECK
(
tr
.
low
(
false
)
);
CHECK
(
tr
.
hi
(
true
)
);
}
SECTION
(
"Working"
)
{
Trigger
tr
;
CHECK_FALSE
(
tr
.
low
(
false
)
);
CHECK_FALSE
(
tr
.
change
(
false
)
);
CHECK
(
tr
.
hi
(
true
)
);
CHECK_FALSE
(
tr
.
change
(
true
)
);
CHECK
(
tr
.
low
(
false
)
);
CHECK
(
tr
.
change
(
true
)
);
CHECK
(
tr
.
low
(
false
)
);
CHECK
(
tr
.
hi
(
true
)
);
CHECK_FALSE
(
tr
.
hi
(
false
)
);
}
}
tests/triggerOR.cc
0 → 100644
View file @
c3c97227
#include <catch.hpp>
#include "TriggerOR.h"
#include "UniSetTypes.h"
using
namespace
std
;
class
MyTestClass
{
public
:
MyTestClass
()
:
num
(
0
){}
~
MyTestClass
(){}
void
setOut
(
bool
newstate
)
{
num
++
;
}
inline
int
getNum
(){
return
num
;
}
private
:
int
num
;
};
TEST_CASE
(
"TriggerOR"
,
"[TriggerOR]"
)
{
SECTION
(
"Constructor"
)
{
MyTestClass
tc
;
TriggerOR
<
MyTestClass
,
int
>
tr
(
&
tc
,
&
MyTestClass
::
setOut
);
REQUIRE
(
tc
.
getNum
()
==
0
);
tr
.
add
(
1
,
true
);
tr
.
add
(
2
,
false
);
tr
.
add
(
3
,
false
);
REQUIRE
(
tc
.
getNum
()
==
1
);
CHECK
(
tr
.
state
()
);
CHECK
(
tr
.
getState
(
1
)
);
CHECK_FALSE
(
tr
.
getState
(
2
)
);
CHECK_FALSE
(
tr
.
getState
(
3
)
);
}
SECTION
(
"Working"
)
{
MyTestClass
tc
;
TriggerOR
<
MyTestClass
,
bool
>
tr
(
&
tc
,
&
MyTestClass
::
setOut
);
REQUIRE
(
tc
.
getNum
()
==
0
);
tr
.
add
(
1
,
true
);
REQUIRE
(
tc
.
getNum
()
==
1
);
CHECK
(
tr
.
state
()
);
tr
.
add
(
2
,
false
);
REQUIRE
(
tc
.
getNum
()
==
1
);
tr
.
add
(
3
,
false
);
REQUIRE
(
tc
.
getNum
()
==
1
);
CHECK
(
tr
.
state
()
);
CHECK
(
tr
.
getState
(
1
)
);
CHECK_FALSE
(
tr
.
getState
(
2
)
);
CHECK_FALSE
(
tr
.
getState
(
3
)
);
tr
.
reset
();
REQUIRE
(
tc
.
getNum
()
==
2
);
CHECK_FALSE
(
tr
.
state
()
);
CHECK
(
tr
.
getState
(
1
)
);
CHECK_FALSE
(
tr
.
getState
(
2
)
);
CHECK_FALSE
(
tr
.
getState
(
3
)
);
tr
.
commit
(
1
,
false
);
tr
.
commit
(
2
,
true
);
CHECK
(
tr
.
state
()
);
REQUIRE
(
tc
.
getNum
()
==
3
);
CHECK_FALSE
(
tr
.
getState
(
1
)
);
CHECK
(
tr
.
getState
(
2
)
);
CHECK_FALSE
(
tr
.
getState
(
3
)
);
tr
.
remove
(
2
);
CHECK_FALSE
(
tr
.
getState
(
1
)
);
CHECK_FALSE
(
tr
.
getState
(
3
)
);
CHECK_FALSE
(
tr
.
state
()
);
REQUIRE
(
tc
.
getNum
()
==
4
);
// обращение к несуществующему входу
CHECK_FALSE
(
tr
.
getState
(
10
)
);
CHECK_FALSE
(
tr
.
getState
(
-
10
)
);
CHECK_FALSE
(
tr
.
getState
(
0
)
);
tr
.
commit
(
10
,
true
);
CHECK_FALSE
(
tr
.
state
()
);
tr
.
commit
(
-
10
,
true
);
CHECK_FALSE
(
tr
.
state
()
);
tr
.
commit
(
0
,
true
);
CHECK_FALSE
(
tr
.
state
()
);
}
}
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