Commit 89406a14 authored by Pavel Vainerman's avatar Pavel Vainerman

(tests): добавил тест UInterface, но функций которые можно проверить без

SharedMemory. C SM тесты будут в extensions/tests.
parent ecee5cb0
......@@ -121,6 +121,9 @@ long UInterface::getValue( const ObjectId id, const ObjectId node ) const
if ( id == DefaultObjectId )
throw ORepFailed("UI(getValue): error id=UniSetTypes::DefaultObjectId");
if ( node == DefaultObjectId )
throw ORepFailed("UI(getValue): error node=UniSetTypes::DefaultObjectId");
try
{
CORBA::Object_var oref;
......@@ -279,6 +282,9 @@ void UInterface::setValue( const ObjectId id, long value, const ObjectId node )
if ( id == DefaultObjectId )
throw ORepFailed("UI(setValue): попытка обратиться к объекту с id=UniSetTypes::DefaultObjectId");
if ( node == DefaultObjectId )
throw ORepFailed("UI(setValue): error node=UniSetTypes::DefaultObjectId");
try
{
CORBA::Object_var oref;
......@@ -469,6 +475,9 @@ void UInterface::askRemoteSensor( const ObjectId id, UniversalIO::UIOCommand cmd
if ( id == DefaultObjectId )
throw ORepFailed("UI(askRemoteSensor): id=UniSetTypes::DefaultObjectId");
if ( node == DefaultObjectId )
throw ORepFailed("UI(askRemoteSensor): error node=UniSetTypes::DefaultObjectId");
try
{
CORBA::Object_var oref;
......@@ -557,6 +566,9 @@ IOType UInterface::getIOType( const ObjectId id, const ObjectId node ) const
if ( id == DefaultObjectId )
throw ORepFailed("UI(getIOType): попытка обратиться к объекту с id=UniSetTypes::DefaultObjectId");
if ( node == DefaultObjectId )
throw ORepFailed("UI(getIOType): error node=UniSetTypes::DefaultObjectId");
try
{
CORBA::Object_var oref;
......@@ -639,6 +651,9 @@ ObjectType UInterface::getType(const ObjectId name, const ObjectId node) const
if ( name == DefaultObjectId )
throw ORepFailed("UI(getType): попытка обратиться к объекту с id=UniSetTypes::DefaultObjectId");
if ( node == DefaultObjectId )
throw ORepFailed("UI(getType): error node=UniSetTypes::DefaultObjectId");
try
{
CORBA::Object_var oref;
......@@ -762,6 +777,9 @@ ObjectPtr UInterface::resolve( const ObjectId rid , const ObjectId node, int tim
if ( rid == DefaultObjectId )
throw ResolveNameError("UI(resolve): ID=UniSetTypes::DefaultObjectId");
if ( node == DefaultObjectId )
throw ResolveNameError("UI(resolve): error node=UniSetTypes::DefaultObjectId");
CosNaming::NamingContext_var ctx;
rcache.erase(rid, node);
try
......@@ -890,6 +908,9 @@ void UInterface::send( const ObjectId name, const TransportMessage& msg, const O
if ( name == DefaultObjectId )
throw ORepFailed("UI(send): ERROR: id=UniSetTypes::DefaultObjectId");
if ( node == DefaultObjectId )
throw ORepFailed("UI(send): error node=UniSetTypes::DefaultObjectId");
try
{
CORBA::Object_var oref;
......@@ -958,6 +979,9 @@ IOController_i::ShortIOInfo UInterface::getChangedTime( const ObjectId id, const
if( id == DefaultObjectId )
throw ORepFailed("UI(getChangedTime): Unknown id=UniSetTypes::DefaultObjectId");
if ( node == DefaultObjectId )
throw ORepFailed("UI(getChangedTime): error node=UniSetTypes::DefaultObjectId");
try
{
CORBA::Object_var oref;
......@@ -1183,6 +1207,9 @@ void UInterface::askRemoteThreshold( const ObjectId sid, const ObjectId node,
if ( sid == DefaultObjectId )
throw ORepFailed("UI(askRemoteThreshold): попытка обратиться к объекту с id=UniSetTypes::DefaultObjectId");
if ( node == DefaultObjectId )
throw ORepFailed("UI(askRemoteThreshold): error node=UniSetTypes::DefaultObjectId");
try
{
CORBA::Object_var oref;
......@@ -1341,6 +1368,9 @@ long UInterface::getRawValue( const IOController_i::SensorInfo& si )
if ( si.id == DefaultObjectId )
throw ORepFailed("UI(getRawValue): попытка обратиться к объекту с id=UniSetTypes::DefaultObjectId");
if ( si.node == DefaultObjectId )
throw ORepFailed("UI(cgetRawValue): error node=UniSetTypes::DefaultObjectId");
try
{
CORBA::Object_var oref;
......@@ -1417,9 +1447,12 @@ void UInterface::calibrate(const IOController_i::SensorInfo& si,
// if( admId==UniSetTypes::DefaultObjectId )
// throw UniSetTypes::IOBadParam("UI(askTreshold): неизвестен ID администратора");
if ( si.id == DefaultObjectId )
if( si.id == DefaultObjectId )
throw ORepFailed("UI(calibrate): попытка обратиться к объекту с id=UniSetTypes::DefaultObjectId");
if( si.node == DefaultObjectId )
throw ORepFailed("UI(calibrate): error node=UniSetTypes::DefaultObjectId");
try
{
CORBA::Object_var oref;
......@@ -1492,6 +1525,9 @@ IOController_i::CalibrateInfo UInterface::getCalibrateInfo( const IOController_i
if ( si.id == DefaultObjectId )
throw ORepFailed("UI(getCalibrateInfo): попытка обратиться к объекту с id=UniSetTypes::DefaultObjectId");
if ( si.node == DefaultObjectId )
throw ORepFailed("UI(getCalibrateInfo): error node=UniSetTypes::DefaultObjectId");
try
{
CORBA::Object_var oref;
......@@ -1803,6 +1839,12 @@ UniSetTypes::IDSeq_var UInterface::askSensorsSeq( UniSetTypes::IDList& lst,
// -----------------------------------------------------------------------------
IOController_i::ShortMapSeq* UInterface::getSensors( const UniSetTypes::ObjectId id, const UniSetTypes::ObjectId node )
{
if ( id == DefaultObjectId )
throw ORepFailed("UI(getSensors): error node=UniSetTypes::DefaultObjectId");
if ( node == DefaultObjectId )
throw ORepFailed("UI(getSensors): error node=UniSetTypes::DefaultObjectId");
try
{
CORBA::Object_var oref;
......@@ -1871,6 +1913,12 @@ IOController_i::ShortMapSeq* UInterface::getSensors( const UniSetTypes::ObjectId
// -----------------------------------------------------------------------------
bool UInterface::waitReady( const ObjectId id, int msec, int pmsec, const ObjectId node )
{
if( msec < 0 )
msec = 0;
if( pmsec < 0 )
pmsec = 0;
PassiveTimer ptReady(msec);
bool ready = false;
while( !ptReady.checkTime() && !ready )
......@@ -1891,6 +1939,12 @@ bool UInterface::waitReady( const ObjectId id, int msec, int pmsec, const Object
// -----------------------------------------------------------------------------
bool UInterface::waitWorking( const ObjectId id, int msec, int pmsec, const ObjectId node )
{
if( msec < 0 )
msec = 0;
if( pmsec < 0 )
pmsec = 0;
PassiveTimer ptReady(msec);
bool ready = false;
......
......@@ -75,12 +75,12 @@ ostream& UniSetTypes::Configuration::help(ostream& os)
namespace UniSetTypes
{
DebugStream ulog;
Configuration *conf = 0;
Configuration* conf = 0;
Configuration::Configuration():
oind(NULL),
NSName("NameService"),
repeatCount(2),repeatTimeout(100),
repeatCount(2),repeatTimeout(100),
localDBServer(UniSetTypes::DefaultObjectId),
localNode(UniSetTypes::DefaultObjectId),
localNodeName(""),
......@@ -173,10 +173,6 @@ void Configuration::initConfiguration( int argc, const char* const* argv )
rootDir = string(curdir) + "/";
/*! \todo Надо избавляться от глобального conf (!) */
if( !UniSetTypes::conf )
UniSetTypes::conf = this;
{
ostringstream s;
s << this << "NameService";
......
......@@ -3,24 +3,16 @@
############################################################################
noinst_PROGRAMS = tests tests_with_conf
#unixml ui umutex conftest iterator_test sscanf_hex calibration threadtst dlog
#ui umutex sscanf_hexthreadtst dlog
tests_SOURCES = tests.cc passivetimer.cc hourglass.cc delaytimer.cc unixml.cc
tests_LDADD = $(top_builddir)/lib/libUniSet2.la
tests_CPPFLAGS = -I$(top_builddir)/include -I$(includedir)/Catch
tests_with_conf_SOURCES = tests_with_conf.cc conftest.cc
tests_with_conf_LDADD = $(top_builddir)/lib/libUniSet2.la
tests_with_conf_CPPFLAGS = -I$(top_builddir)/include -I$(includedir)/Catch
tests_with_conf_SOURCES = tests_with_conf.cc conftest.cc ui.cc
tests_with_conf_LDADD = $(top_builddir)/lib/libUniSet2.la
tests_with_conf_CPPFLAGS = -I$(top_builddir)/include -I$(includedir)/Catch
# unixml_SOURCES = unixml.cc
# unixml_LDADD = $(top_builddir)/lib/libUniSet2.la ${SIGC_LIBS}
# unixml_CPPFLAGS = -I$(top_builddir)/include ${SIGC_CFLAGS}
#
# iterator_test_SOURCES = iterator_test.cc
# iterator_test_LDADD = $(top_builddir)/lib/libUniSet2.la
# iterator_test_CPPFLAGS = -I$(top_builddir)/include
#
# ui_SOURCES = ui.cc
# ui_LDADD = $(top_builddir)/lib/libUniSet2.la
# ui_CPPFLAGS = -I$(top_builddir)/include
......@@ -31,10 +23,6 @@ tests_with_conf_CPPFLAGS = -I$(top_builddir)/include -I$(includedir)/Catch
#
# sscanf_hex_SOURCES = sscanf_hex.cc
#
# calibration_SOURCES = calibration.cc
# calibration_LDADD = $(top_builddir)/lib/libUniSet2.la ${SIGC_LIBS}
# calibration_CPPFLAGS = -I$(top_builddir)/include ${SIGC_CFLAGS}
#
# threadtst_SOURCES = threadtst.cc
# threadtst_LDADD = $(top_builddir)/lib/libUniSet2.la ${SIGC_LIBS} $(COMCPP_LIBS)
# threadtst_CPPFLAGS = -I$(top_builddir)/include ${SIGC_CFLAGS} $(COMCPP_CFLAGS)
......
......@@ -98,60 +98,3 @@ TEST_CASE( "Configuration", "[Configuration]" )
}
}
#if 0
try
{
int i1 = uni_atoi("-100");
cout << "**** check uni_atoi: '-100' " << ( ( i1 != -100 ) ? "FAILED" : "OK" ) << endl;
int i2 = uni_atoi("20");
cout << "**** check uni_atoi: '20' " << ( ( i2 != 20 ) ? "FAILED" : "OK" ) << endl;
xmlNode* cnode = conf->getNode("testnode");
if( cnode == NULL )
{
cerr << "<testnode name='testnode'> not found" << endl;
return 1;
}
cout << "**** check conf->getNode function [OK] " << endl;
UniXML_iterator it(cnode);
int prop2 = conf->getArgInt("--prop-id2",it.getProp("id2"));
cerr << "**** check conf->getArgInt(arg1,...): " << ( (prop2 == 0) ? "[FAILED]" : "OK" ) << endl;
int prop3 = conf->getArgInt("--prop-dummy",it.getProp("id2"));
cerr << "**** check conf->getArgInt(...,arg2): " << ( (prop3 != -100) ? "[FAILED]" : "OK" ) << endl;
int prop1 = conf->getArgPInt("--prop-id2",it.getProp("id2"),0);
cerr << "**** check conf->getArgPInt(...): " << ( (prop1 == 0) ? "[FAILED]" : "OK" ) << endl;
int prop4 = conf->getArgPInt("--prop-dummy",it.getProp("dummy"),20);
cerr << "**** check conf->getArgPInt(...,...,defval): " << ( (prop4 != 20) ? "[FAILED]" : "OK" ) << endl;
int prop5 = conf->getArgPInt("--prop-dummy",it.getProp("dummy"),0);
cerr << "**** check conf->getArgPInt(...,...,defval): " << ( (prop5 != 0) ? "[FAILED]" : "OK" ) << endl;
return 0;
}
catch(SystemError& err)
{
cerr << "(conftest): " << err << endl;
}
catch(Exception& ex)
{
cerr << "(conftest): " << ex << endl;
}
catch(...)
{
cerr << "(conftest): catch(...)" << endl;
}
return 1;
}
#endif
\ No newline at end of file
#define CATCH_CONFIG_RUNNER
#include <catch.hpp>
#include <iostream>
#include "Configuration.h"
int main( int argc, char* argv[] )
{
Catch::Session session;
Catch::Session session;
try
{
UniSetTypes::uniset_init(argc,argv);
UniSetTypes::uniset_init(argc,argv);
int returnCode = session.applyCommandLine( argc, argv, Catch::Session::OnUnusedOptions::Ignore );
if( returnCode != 0 ) // Indicates a command line error
return returnCode;
return session.run();
}
catch( UniSetTypes::Exception& ex )
{
std::cerr << ex << std::endl;
}
int returnCode = session.applyCommandLine( argc, argv, Catch::Session::OnUnusedOptions::Ignore );
if( returnCode != 0 ) // Indicates a command line error
return returnCode;
return session.run();
return 1;
}
#!/bin/sh
# '--' - нужен для отделения аоргументов catch, от наших..
uniset-start.sh -f ./tests_with_conf -- --confile tests_with_conf.xml --prop-id2 -10 $*
uniset-start.sh -f ./tests_with_conf $* -- --confile tests_with_conf.xml --prop-id2 -10
......@@ -5,7 +5,7 @@
<!-- Общие(стартовые) параметры по UniSet -->
<UniSet>
<NameService host="localhost" port="2809"/>
<LocalNode name="LocalhostNode"/>
<LocalNode name="localhost"/>
<RootSection name="UNISET_PLC"/>
<CountOfNet name="1"/>
......@@ -55,8 +55,8 @@
textname - текстовое имя датчика
-->
<nodes port="2809">
<item id="1000" name="LocalhostNode" alias="" textname="Локальный узел" ip="127.0.0.1"/>
<item id="1001" name="Node2" alias="" textname="Локальный узел" ip="127.0.0.1"/>
<item id="1000" name="localhost" alias="" textname="Локальный узел" ip="127.0.0.1"/>
<item id="1001" name="node2" alias="" textname="Локальный узел" ip="127.0.0.1"/>
</nodes>
<!-- ************************ Датчики ********************** -->
......
#include <catch.hpp>
#include <time.h>
#include "UInterface.h"
#include "UniSetTypes.h"
......@@ -5,64 +7,63 @@
using namespace std;
using namespace UniSetTypes;
int main( int argc, const char **argv )
TEST_CASE("UInterface","[UInterface]")
{
try
{
uniset_init(argc,argv,"test.xml");
UInterface ui;
cout << "** check getSensorID function **" << endl;
ObjectId id1 = conf->getSensorID("Input1_S");
if( id1 != 1 )
{
cout << "** FAILED! check getSensorID function **" << endl;
return 1;
}
cout << "** check getConfIOType function **" << endl;
UniversalIO::IOType t = ui.getConfIOType(id1);
cout << "sensor ID=" << id1 << " iotype=" << t << endl;
if( t != UniversalIO::DI )
{
cout << "** FAILED! check getSensorID function **" << endl;
return 1;
}
int id = conf->getArgInt("--sid");
if( id <= 0 )
{
cerr << "unknown sensor ID. Use --sid " << endl;
return 1;
}
cout << "** check getChangedTime for ID=" << id << ":" << endl;
IOController_i::ShortIOInfo inf = ui.getChangedTime(id,conf->getLocalNode());
struct tm* tms = localtime(&inf.tv_sec);
char t_str[ 150 ];
strftime( t_str, sizeof(t_str), "%d %b %Y %H:%M:%S", tms );
cout << "id=" << id
<< " value=" << inf.value
<< " last changed: " << string(t_str) << endl;
cout << "check getValue: " << ui.getValue(id1) << endl;
cout << "check setValue: id='" << id1 << "' val=2 ...";
ui.setValue(id1,2);
cout << ( ui.getValue(id1) == 2 ? "OK" : "FAIL" ) << endl;
}
catch( Exception& ex )
{
cout << "(uitest):" << ex << endl;
}
catch(...)
{
cout << "(uitest): catch ..."<< endl;
}
return 0;
CHECK( conf!=0 );
std::string sidName("Input1_S");
ObjectId testOID = conf->getObjectID("TestProc");
CHECK( testOID != DefaultObjectId );
ObjectId sid = conf->getSensorID(sidName);
CHECK( sid != DefaultObjectId );
UInterface ui;
CHECK( ui.getObjectIndex() != 0 );
CHECK( ui.getConf() == UniSetTypes::conf );
CHECK( ui.getConfIOType(sid) != UniversalIO::UnknownIOType );
REQUIRE_THROWS_AS( ui.getValue(DefaultObjectId), UniSetTypes::ORepFailed );
REQUIRE_THROWS_AS( ui.getValue(sid), UniSetTypes::Exception );
REQUIRE_THROWS_AS( ui.getValue(sid, DefaultObjectId), UniSetTypes::Exception );
REQUIRE_THROWS_AS( ui.getValue(sid, 100), UniSetTypes::Exception );
REQUIRE_THROWS_AS( ui.resolve(sid), UniSetTypes::ORepFailed );
REQUIRE_THROWS_AS( ui.resolve(sid,10), UniSetTypes::ORepFailed );
REQUIRE_THROWS_AS( ui.resolve(sid,DefaultObjectId), UniSetTypes::ORepFailed );
TransportMessage tm( SensorMessage(sid,10).transport_msg() );
REQUIRE_THROWS_AS( ui.send(testOID,tm), UniSetTypes::Exception );
REQUIRE_THROWS_AS( ui.send(testOID,tm, -20), UniSetTypes::Exception );
REQUIRE_THROWS_AS( ui.send(testOID,tm, DefaultObjectId), UniSetTypes::Exception );
REQUIRE_THROWS_AS( ui.getChangedTime(sid,-20), UniSetTypes::Exception );
REQUIRE_THROWS_AS( ui.getChangedTime(sid,DefaultObjectId), UniSetTypes::Exception );
REQUIRE_THROWS_AS( ui.getChangedTime(sid,conf->getLocalNode()), UniSetTypes::Exception );
CHECK_FALSE( ui.isExist(sid) );
CHECK_FALSE( ui.isExist(sid,DefaultObjectId) );
CHECK_FALSE( ui.isExist(sid,100) );
CHECK_FALSE( ui.waitReady(sid,100,50) );
CHECK_FALSE( ui.waitReady(sid,300,50,DefaultObjectId) );
CHECK_FALSE( ui.waitReady(sid,300,50,-20) );
CHECK_FALSE( ui.waitReady(sid,-1,50) );
CHECK_FALSE( ui.waitReady(sid,300,-1) );
CHECK_FALSE( ui.waitWorking(sid,100,50) );
CHECK_FALSE( ui.waitWorking(sid,100,50,DefaultObjectId) );
CHECK_FALSE( ui.waitWorking(sid,100,50,-20) );
CHECK_FALSE( ui.waitWorking(sid,-1,50) );
CHECK_FALSE( ui.waitWorking(sid,100,-1) );
std::string longName("UNISET_PLC/Sensors/" + sidName);
CHECK( ui.getIdByName(longName) == sid );
CHECK( ui.getNameById(sid) == longName );
CHECK( ui.getTextName(sid) == "Команда 1" );
CHECK( ui.getNodeId("localhost") == 1000 );
}
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