Commit 189567d1 authored by Pavel Vainerman's avatar Pavel Vainerman

(tests): накидал скелет для проверки элементов LogicProcessor

parent b245e46f
......@@ -279,6 +279,7 @@ AC_CONFIG_FILES([Makefile
extensions/ModbusSlave/libUniSet2MBSlave.pc
extensions/LogicProcessor/Makefile
extensions/LogicProcessor/libUniSet2LogicProcessor.pc
extensions/LogicProcessor/unit-tests/Makefile
extensions/SMViewer/Makefile
extensions/UniNetwork/Makefile
extensions/UniNetwork/libUniSet2Network.pc
......
if DISABLE_LOGICPROC
else
SUBDIRS=unit-tests
# не забывайте править версию в2.pc-файле
ULPROC_VER=@LIBVER@
......
......@@ -4,8 +4,8 @@
#include "PassiveTimer.h"
#include "Element.h"
// ---------------------------------------------------------------------------
// add on delay, off delay
// "ON" delay element
// Сбрасывается без задержки.. а срабатывает с задержкой.
class TDelay:
public Element
{
......
noinst_PROGRAMS = tests
tests_SOURCES = tests.cc lproc.cc
tests_LDADD = $(top_builddir)/lib/libUniSet2.la $(top_builddir)/extensions/lib/libUniSet2Extensions.la \
$(top_builddir)/extensions/LogicProcessor/libUniSet2LProcessor.la
tests_CPPFLAGS = -I$(top_builddir)/include -I$(top_builddir)/extensions/include -I$(top_builddir)/extensions/LogicProcessor \
-I$(includedir)/Catch
#include <catch.hpp>
#include <time.h>
#include "LProcessor.h"
#include "UniSetTypes.h"
#include "Schema.h"
#include "TDelay.h"
using namespace std;
using namespace UniSetTypes;
TEST_CASE("Logic processor","[LogicProcessor]")
{
#if 0
SECTION( "ShemaXML" )
{
SchemaXML sch;
sch.read("schema.xml");
CHECK( !sch.empty() );
}
#endif
SECTION( "TOR" )
{
TOR e("1",2); // элемент на два входа..
REQUIRE( e.getOut() == 0 );
e.setIn(1,true);
CHECK( e.getOut() );
e.setIn(2,true);
CHECK( e.getOut() );
e.setIn(1,false);
CHECK( e.getOut() );
e.setIn(2,false);
CHECK_FALSE( e.getOut() );
e.setIn(3,true); // несуществующий вход..
CHECK_FALSE( e.getOut() );
}
SECTION( "TAND" )
{
TAND e("1",2); // элемент на два входа..
REQUIRE( e.getOut() == 0 );
e.setIn(1,true);
CHECK_FALSE( e.getOut() );
e.setIn(2,true);
CHECK( e.getOut() );
e.setIn(1,false);
CHECK_FALSE( e.getOut() );
e.setIn(2,false);
CHECK_FALSE( e.getOut() );
e.setIn(3,true); // несуществующий вход..
CHECK_FALSE( e.getOut() );
}
SECTION( "TNOT" )
{
TNOT e("1",false);
CHECK_FALSE( e.getOut() );
e.setIn(1,true);
CHECK_FALSE( e.getOut() );
e.setIn(1,false);
CHECK( e.getOut() );
// other constructor
TNOT e1("1",true);
CHECK( e1.getOut() );
e1.setIn(1,true);
CHECK_FALSE( e1.getOut() );
e1.setIn(1,false);
CHECK( e1.getOut() );
}
SECTION( "TDelay" )
{
TDelay e("1",50,1);
CHECK_FALSE( e.getOut() );
// ON DELAY
e.setIn(1,true);
CHECK_FALSE( e.getOut() );
msleep(60);
e.tick();
CHECK( e.getOut() );
msleep(60);
e.tick();
CHECK( e.getOut() );
// OFF DELAY
e.setIn(1,false);
CHECK_FALSE( e.getOut() );
// delay 0 msek..
e.setDelay(0);
e.setIn(1,true);
CHECK( e.getOut() );
// delay < 0 === 0
e.setIn(1,false);
e.setDelay(-10);
e.setIn(1,true);
CHECK( e.getOut() );
}
}
<?xml version="1.0" encoding="koi8-r"?>
<Schema>
<text-view>
----
1 --| |
2 --|TOR1|---| 1 -----
| | |----| |
---- 2 | |--|
|----|TAND3| |
---- | | | |
| | | ----- |
1 --|TOR2| | | 1 ---- -------
2 --| |--- | ---- ---| | | | out
| | | 1 | | 2 |TOR5|-----| Delay |----
---- |---|TOR4|-----| | | |
2 ----| | | | | |
---- ---- -------
</text-view>
<elements>
<item id="1" type="OR" inCount="2"/>
<item id="2" type="OR" inCount="2"/>
<item id="3" type="AND" inCount="2"/>
<item id="4" type="OR" inCount="2"/>
<item id="5" type="OR" inCount="2"/>
<item id="6" type="Delay" inCount="1" delayMS="3000"/>
</elements>
<connections>
<item type="ext" from="Input1_S" to="1" toInput="1" />
<item type="ext" from="Input2_S" to="1" toInput="2" />
<item type="ext" from="Input3_S" to="2" toInput="1" />
<item type="ext" from="Input4_S" to="2" toInput="2" />
<item type="ext" from="Input5_S" to="4" toInput="2" />
<item type="ext" from="Input6_S" to="5" toInput="1" />
<item type="int" from="1" to="3" toInput="1" />
<item type="int" from="2" to="3" toInput="2" />
<item type="int" from="3" to="4" toInput="1" />
<item type="int" from="4" to="5" toInput="2" />
<item type="int" from="5" to="6" toInput="1" />
<item type="out" from="6" to="TestMode_S"/>
</connections>
</Schema>
#define CATCH_CONFIG_MAIN
#include <Catch/catch.hpp>
// не удивляйтесь, что тут нет main().. она спрятана в catch.cpp :)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment