diff --git a/tests/Makefile.am b/tests/Makefile.am index 53c752e5c..736b00d27 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -92,8 +92,9 @@ parser_test_SOURCES = test-runner.cpp \ types_test.cpp types_test.hpp program_test_SOURCES = test-runner.cpp \ - function_test.cpp function_test.hpp \ - program_test.cpp program_test.hpp + function_test.cpp function_test.hpp + +# program_test.cpp program_test.hpp state_test_SOURCES = test-runner.cpp \ state_test.cpp state_test.hpp diff --git a/tests/buffers_test.cpp b/tests/buffers_test.cpp index 548eb4dc7..dcbfa1155 100644 --- a/tests/buffers_test.cpp +++ b/tests/buffers_test.cpp @@ -21,6 +21,7 @@ #include "buffers_test.hpp" #include #include +#include using namespace std; @@ -40,6 +41,11 @@ struct Dummy { return d.d1 == d1 && d.d2 == d2 && d.d3 == d3; } + bool operator!=(const Dummy& d) const + { + return d.d1 != d1 || d.d2 != d2 || d.d3 != d3; + } + bool operator<(const Dummy& d) const { return d1+d2+d3 < d.d1 + d.d2 + d.d3; @@ -73,6 +79,9 @@ BuffersTest::setUp() dataobj = new DataObjectLockFree("name"); mslist = new SortedList(); + + listlockfree = new ListLockFree(10, 4); + } @@ -87,6 +96,8 @@ BuffersTest::tearDown() delete dataobj; delete mslist; + + delete listlockfree; } void BuffersTest::testAtomic() @@ -127,6 +138,7 @@ void BuffersTest::testAtomicCounted() */ Dummy* d = new Dummy; + Dummy* e = new Dummy; Dummy* c = d; CPPUNIT_ASSERT( aqueue->dequeueCounted(c) == 0 ); @@ -149,6 +161,18 @@ void BuffersTest::testAtomicCounted() CPPUNIT_ASSERT( aqueue->isFull() == false ); CPPUNIT_ASSERT( aqueue->isEmpty() == true ); + CPPUNIT_ASSERT( aqueue->enqueueCounted( d ) != 0 ); + CPPUNIT_ASSERT( aqueue->enqueueCounted( e ) != 0 ); + CPPUNIT_ASSERT( aqueue->enqueueCounted( d ) != 0 ); + c = 0; + CPPUNIT_ASSERT( aqueue->dequeueCounted( c ) != 0 ); + CPPUNIT_ASSERT( c == d ); + CPPUNIT_ASSERT( aqueue->dequeueCounted( c ) != 0 ); + CPPUNIT_ASSERT( c == e ); + CPPUNIT_ASSERT( aqueue->dequeueCounted( c ) != 0 ); + CPPUNIT_ASSERT( c == d ); + + delete e; delete d; } @@ -368,14 +392,14 @@ void BuffersTest::testSortedList() CPPUNIT_ASSERT( mslist->erase(Dummy(1,2,4)) == true ); CPPUNIT_ASSERT( mslist->hasKey(Dummy(1,2,4)) == false ); - mslist->apply( &addOne ); + mslist->applyOnData( &addOne ); CPPUNIT_ASSERT( mslist->hasKey(Dummy(2,3,2)) == true ); CPPUNIT_ASSERT( mslist->hasKey(Dummy(2,3,3)) == true ); CPPUNIT_ASSERT( mslist->hasKey(Dummy(2,3,4)) == true ); CPPUNIT_ASSERT( mslist->hasKey(Dummy(2,3,6)) == true ); CPPUNIT_ASSERT( mslist->hasKey(Dummy(2,3,7)) == true ); - mslist->apply( &subOne ); + mslist->applyOnData( &subOne ); CPPUNIT_ASSERT( mslist->hasKey(Dummy(1,2,1)) == true ); CPPUNIT_ASSERT( mslist->hasKey(Dummy(1,2,2)) == true ); CPPUNIT_ASSERT( mslist->hasKey(Dummy(1,2,3)) == true ); @@ -390,3 +414,115 @@ void BuffersTest::testSortedList() CPPUNIT_ASSERT( mslist->empty() ); } + +struct LLFWorker : public ORO_OS::RunnableInterface +{ + bool stop; + typedef ListLockFree T; + T* mlst; + int i; + int appends; + int erases; + LLFWorker(T* l ) : stop(false), mlst(l), i(1) {} + bool initialize() { + stop = false; i = 1; + appends = 0; erases = 0; + return true; + } + void step() { + while (stop == false ) { + //cout << "Appending, i="<append( Dummy(i,i,i) ) ) { ++i; ++appends; } + //cout << "Erasing, i="<erase( Dummy(i-1,i-1,i-1) ) ) { --i; ++erases; } + } + //cout << "Stopping, i="< T; + T* mlst; + int i; + LLFGrower(T* l ) : stop(false), mlst(l), i(1) {} + bool initialize() { + stop = false; i = 1; + return true; + } + void step() { + // stress growing of list during append/erase. + while (stop == false && i < 2500 ) { + // reserve is quite slow. + mlst->reserve(i); + ++i; + } + } + + void finalize() {} + + bool breakLoop() { + stop = true; + return true; + } +}; + +void BuffersTest::testListLockFree() +{ + LLFWorker* aworker = new LLFWorker( listlockfree ); + LLFWorker* bworker = new LLFWorker( listlockfree ); + LLFWorker* cworker = new LLFWorker( listlockfree ); + LLFGrower* grower = new LLFGrower( listlockfree ); + + { + boost::scoped_ptr athread( new SingleThread(1,"ThreadA", aworker )); + boost::scoped_ptr bthread( new SingleThread(1,"ThreadB", bworker )); + boost::scoped_ptr cthread( new SingleThread(1,"ThreadC", cworker )); + boost::scoped_ptr gthread( new SingleThread(1,"ThreadG", grower )); + + athread->start(); + bthread->start(); + cthread->start(); + + sleep(5); + gthread->start(); + sleep(1); + gthread->stop(); + sleep(5); + + athread->stop(); + bthread->stop(); + cthread->stop(); + } + + cout << "Athread appends: " << aworker->appends<erases<appends<erases<appends<erases<capacity()<size()<empty() == false ) { +// Dummy d = listlockfree->back(); +// //cout << "Left: "<< d <erase( d ) ); +// } + + CPPUNIT_ASSERT( aworker->appends == aworker->erases ); + CPPUNIT_ASSERT( bworker->appends == bworker->erases ); + CPPUNIT_ASSERT( cworker->appends == cworker->erases ); + + delete aworker; + delete bworker; + delete cworker; + delete grower; +} diff --git a/tests/buffers_test.hpp b/tests/buffers_test.hpp index 20d5ed875..4a261b698 100644 --- a/tests/buffers_test.hpp +++ b/tests/buffers_test.hpp @@ -24,10 +24,14 @@ #include #include +#include #include #include +#include + using namespace ORO_CoreLib; +using namespace ORO_OS; class Dummy; @@ -39,12 +43,18 @@ class BuffersTest : public CppUnit::TestFixture CPPUNIT_TEST( testBufLockFree ); CPPUNIT_TEST( testDObjLockFree ); CPPUNIT_TEST( testSortedList ); + CPPUNIT_TEST( testListLockFree ); CPPUNIT_TEST_SUITE_END(); AtomicQueue* aqueue; BufferLockFree* lockfree; DataObjectLockFree* dataobj; SortedList* mslist; + + ThreadInterface* athread; + ThreadInterface* bthread; + + ListLockFree* listlockfree; public: void setUp(); @@ -56,6 +66,8 @@ class BuffersTest : public CppUnit::TestFixture void testDObjLockFree(); void testSortedList(); + + void testListLockFree(); }; #endif diff --git a/tests/dispatch_test.cpp b/tests/dispatch_test.cpp index de2cef5df..12fd11ad7 100644 --- a/tests/dispatch_test.cpp +++ b/tests/dispatch_test.cpp @@ -21,7 +21,7 @@ #include "dispatch_test.hpp" #include #include -#include +#include #include #include @@ -31,10 +31,12 @@ using namespace std; CPPUNIT_TEST_SUITE_REGISTRATION( DispatchTest ); DispatchTest::DispatchTest() - : gtask( 0.1, &gprocessor ), mtask(0.05, &mprocessor), ltask(0.01, &lprocessor), - gtc("root", &gprocessor), - mtc("space", &mprocessor), - ltc("subspace", &lprocessor) + : gtc("root"), + mtc("space"), + ltc("subspace"), + gtask(0.1, gtc.engine() ), + mtask(0.05, mtc.engine()), + ltask(0.01, ltc.engine()) {} @@ -135,9 +137,9 @@ void DispatchTest::testParseDispatch() this->doDispatch( prog, >c ); - CPPUNIT_ASSERT( gprocessor.getProgramStatus("x") != Processor::ProgramStatus::error ); - CPPUNIT_ASSERT( gprocessor.getProgramStatus("x") != Processor::ProgramStatus::running ); - CPPUNIT_ASSERT( gprocessor.getProgramStatus("x") == Processor::ProgramStatus::stopped ); + CPPUNIT_ASSERT( gtc.getExecutionEngine()->getProgramProcessor()->getProgramStatus("x") != ProgramInterface::Status::error ); + CPPUNIT_ASSERT( gtc.getExecutionEngine()->getProgramProcessor()->getProgramStatus("x") != ProgramInterface::Status::running ); + CPPUNIT_ASSERT( gtc.getExecutionEngine()->getProgramProcessor()->getProgramStatus("x") == ProgramInterface::Status::stopped ); this->finishDispatch( >c, "x"); } @@ -151,7 +153,7 @@ void DispatchTest::testDispatchFailure() this->doDispatch( prog, >c ); - CPPUNIT_ASSERT( gprocessor.getProgramStatus("x") == Processor::ProgramStatus::error ); + CPPUNIT_ASSERT( gtc.getExecutionEngine()->getProgramProcessor()->getProgramStatus("x") == ProgramInterface::Status::error ); this->finishDispatch( >c, "x"); } @@ -170,8 +172,8 @@ void DispatchTest::testDispatchCondition() + " }"; this->doDispatch( prog, >c ); - CPPUNIT_ASSERT( gprocessor.getProgramStatus("x") != Processor::ProgramStatus::error ); - CPPUNIT_ASSERT( gprocessor.getProgramStatus("x") == Processor::ProgramStatus::stopped ); + CPPUNIT_ASSERT( gtc.getExecutionEngine()->getProgramProcessor()->getProgramStatus("x") != ProgramInterface::Status::error ); + CPPUNIT_ASSERT( gtc.getExecutionEngine()->getProgramProcessor()->getProgramStatus("x") == ProgramInterface::Status::stopped ); this->finishDispatch( >c, "x"); } @@ -188,8 +190,8 @@ void DispatchTest::testDispatchAnd() + " }"; this->doDispatch( prog, >c ); - CPPUNIT_ASSERT( gprocessor.getProgramStatus("x") != Processor::ProgramStatus::error ); - CPPUNIT_ASSERT( gprocessor.getProgramStatus("x") == Processor::ProgramStatus::stopped ); + CPPUNIT_ASSERT( gtc.getExecutionEngine()->getProgramProcessor()->getProgramStatus("x") != ProgramInterface::Status::error ); + CPPUNIT_ASSERT( gtc.getExecutionEngine()->getProgramProcessor()->getProgramStatus("x") == ProgramInterface::Status::stopped ); this->finishDispatch( >c, "x"); } @@ -208,8 +210,9 @@ void DispatchTest::testDispatchTry() + " }"; this->doDispatch( prog, >c ); - CPPUNIT_ASSERT( gprocessor.getProgramStatus("x") != Processor::ProgramStatus::error ); - CPPUNIT_ASSERT( gprocessor.getProgramStatus("x") == Processor::ProgramStatus::stopped ); + CPPUNIT_ASSERT( gtc.getExecutionEngine()->getProgramProcessor()->getProgramStatus("x") != ProgramInterface::Status::error ); + CPPUNIT_ASSERT_MESSAGE( "Status was not 'stopped', but "+gtc.engine()->programs()->getProgramStatusStr("x"), + gtc.engine()->programs()->getProgramStatus("x") == ProgramInterface::Status::stopped); this->finishDispatch( >c, "x"); } @@ -228,8 +231,8 @@ void DispatchTest::testDispatchUntil() + " }"; this->doDispatch( prog, >c ); - CPPUNIT_ASSERT( gprocessor.getProgramStatus("x") != Processor::ProgramStatus::error ); - CPPUNIT_ASSERT( gprocessor.getProgramStatus("x") == Processor::ProgramStatus::stopped ); + CPPUNIT_ASSERT( gtc.getExecutionEngine()->getProgramProcessor()->getProgramStatus("x") != ProgramInterface::Status::error ); + CPPUNIT_ASSERT( gtc.getExecutionEngine()->getProgramProcessor()->getProgramStatus("x") == ProgramInterface::Status::stopped ); this->finishDispatch( >c, "x"); } @@ -244,7 +247,7 @@ void DispatchTest::testDispatchUntilFail() + " }"; this->doDispatch( prog, >c ); - CPPUNIT_ASSERT( gprocessor.getProgramStatus("x") == Processor::ProgramStatus::error ); + CPPUNIT_ASSERT( gtc.getExecutionEngine()->getProgramProcessor()->getProgramStatus("x") == ProgramInterface::Status::error ); this->finishDispatch( >c, "x"); } @@ -256,8 +259,8 @@ void DispatchTest::testSendDispatch() string prog = "program x { send space.subspace.test.assert(false) \n }"; this->doDispatch( prog, >c ); - CPPUNIT_ASSERT( gprocessor.getProgramStatus("x") != Processor::ProgramStatus::error ); - CPPUNIT_ASSERT( gprocessor.getProgramStatus("x") == Processor::ProgramStatus::stopped ); + CPPUNIT_ASSERT( gtc.getExecutionEngine()->getProgramProcessor()->getProgramStatus("x") != ProgramInterface::Status::error ); + CPPUNIT_ASSERT( gtc.getExecutionEngine()->getProgramProcessor()->getProgramStatus("x") == ProgramInterface::Status::stopped ); this->finishDispatch( >c, "x" ); } @@ -266,7 +269,7 @@ void DispatchTest::testSendDispatch() void DispatchTest::doDispatch( const std::string& prog, TaskContext* tc ) { stringstream progs(prog); - std::vector pg_list; + Parser::ParsedPrograms pg_list; try { pg_list = parser.parseProgram( progs, tc ); } @@ -278,12 +281,12 @@ void DispatchTest::doDispatch( const std::string& prog, TaskContext* tc ) { CPPUNIT_ASSERT( false ); } - CPPUNIT_ASSERT( tc->getProcessor()->loadProgram( *pg_list.begin() ) ); + CPPUNIT_ASSERT( tc->getExecutionEngine()->getProgramProcessor()->loadProgram( *pg_list.begin() ) ); SimulationThread::Instance()->start(); - ltask.start(); - mtask.start(); - gtask.start(); - tc->getProcessor()->startProgram( (*pg_list.begin())->getName() ); + CPPUNIT_ASSERT(ltask.start()); + CPPUNIT_ASSERT(mtask.start()); + CPPUNIT_ASSERT(gtask.start()); + CPPUNIT_ASSERT( tc->getExecutionEngine()->getProgramProcessor()->getProgram( (*pg_list.begin())->getName() )->start() ); // while (1) sleep(1); SimulationThread::Instance()->stop(); @@ -294,8 +297,8 @@ void DispatchTest::finishDispatch(TaskContext* tc, std::string prog_name) gtask.stop(); mtask.stop(); ltask.stop(); - tc->getProcessor()->stopProgram( prog_name ); - CPPUNIT_ASSERT( tc->getProcessor()->deleteProgram( prog_name ) ); + tc->getExecutionEngine()->getProgramProcessor()->getProgram( prog_name )->stop(); + CPPUNIT_ASSERT( tc->getExecutionEngine()->getProgramProcessor()->unloadProgram( prog_name ) ); TaskContext* ptc = tc->getPeer("programs")->getPeer(prog_name); tc->getPeer("programs")->removePeer(prog_name); diff --git a/tests/dispatch_test.hpp b/tests/dispatch_test.hpp index 9a9d3ba08..25e64e903 100644 --- a/tests/dispatch_test.hpp +++ b/tests/dispatch_test.hpp @@ -23,7 +23,7 @@ #include #include -#include +#include #include #include #include @@ -47,15 +47,12 @@ class DispatchTest : public CppUnit::TestFixture //CPPUNIT_TEST( testSendDispatch ); Parser parser; - Processor gprocessor; - Processor mprocessor; - Processor lprocessor; - TaskSimulation gtask; - TaskSimulation mtask; - TaskSimulation ltask; TaskContext gtc; TaskContext mtc; TaskContext ltc; + TaskSimulation gtask; + TaskSimulation mtask; + TaskSimulation ltask; MethodFactoryInterface* createMethodFactory(); CommandFactoryInterface* createCommandFactory(); DataSourceFactoryInterface* createDataSourceFactory(); diff --git a/tests/event_test.cpp b/tests/event_test.cpp index 5cde523f9..5aaa9f3d7 100644 --- a/tests/event_test.cpp +++ b/tests/event_test.cpp @@ -453,6 +453,3 @@ void EventTest::testRTEvent() CPPUNIT_ASSERT( t_completer_value == true ); } - - - diff --git a/tests/eventservice_test.cpp b/tests/eventservice_test.cpp index f5135f966..705896451 100644 --- a/tests/eventservice_test.cpp +++ b/tests/eventservice_test.cpp @@ -102,6 +102,22 @@ void EventServiceTest::reset() t_completer_bool = false; } +void EventServiceTest::setup() +{ + es->addEvent( "t_event0", t_event0 ); + es->addEvent( "t_event1", t_event1 ); + es->addEvent( "t_event2", t_event2 ); + es->addEvent( "t_event3", t_event3 ); +} + +void EventServiceTest::cleanup() +{ + es->removeEvent( "t_event0" ); + es->removeEvent( "t_event1" ); + es->removeEvent( "t_event2" ); + es->removeEvent( "t_event3" ); +} + void EventServiceTest::testAddRemove() { bool result; @@ -130,13 +146,6 @@ void EventServiceTest::testAddRemove() CPPUNIT_ASSERT( result == false ); } -void EventServiceTest::setup() -{ - es->addEvent( "t_event0", t_event0 ); - es->addEvent( "t_event1", t_event1 ); - es->addEvent( "t_event2", t_event2 ); - es->addEvent( "t_event3", t_event3 ); -} void EventServiceTest::testSetupSyn() { this->setup(); @@ -153,13 +162,6 @@ void EventServiceTest::testSetupSyn() this->cleanup(); } -void EventServiceTest::cleanup() -{ - es->removeEvent( "t_event0" ); - es->removeEvent( "t_event1" ); - es->removeEvent( "t_event2" ); - es->removeEvent( "t_event3" ); -} void EventServiceTest::testSetupAsyn() { this->setup(); @@ -386,3 +388,58 @@ void EventServiceTest::testEmit3() this->cleanup(); } + + +void EventServiceTest::testEventC() +{ + // Test EventC and ConnectionC... + Handle h1, h2, h3; + + this->setup(); + + try { + h1 = es->createSynConnection("t_event3", bind(&EventServiceTest::listener0,this)). + arg(t_listener_string).arg(t_listener_double).arg(t_listener_bool).handle(); + } catch ( std::exception& e ) { + CPPUNIT_ASSERT_MESSAGE( e.what(), false ); + } + + try { + h2 = es->createAsynConnection("t_event3", bind(&EventServiceTest::completer0,this),event_proc). + arg(t_completer_string).arg(t_completer_double).arg(t_completer_bool).handle(); + } catch ( std::exception& e ) { + CPPUNIT_ASSERT_MESSAGE( e.what(), false ); + } + + EventC evc; + bool evcarg = true; + try { + evc = es->createEmit("t_event3").argC( std::string("hello") ).argC( 0.1234 ).arg( evcarg ); + } catch ( std::exception& e ) { + CPPUNIT_ASSERT_MESSAGE( e.what(), false ); + } + + CPPUNIT_ASSERT( h1.connect() ); + evc.emit(); + CPPUNIT_ASSERT( t_listener_done ); + CPPUNIT_ASSERT( t_listener_string == std::string("hello") ); + CPPUNIT_ASSERT( t_listener_double == 0.1234 ); + CPPUNIT_ASSERT( t_listener_bool == evcarg ); + this->reset(); + CPPUNIT_ASSERT( h1.disconnect() ); + + CPPUNIT_ASSERT( h2.connect() ); + evc.emit(); + CPPUNIT_ASSERT( !t_completer_done ); + event_proc->step(); + CPPUNIT_ASSERT( t_completer_done ); + CPPUNIT_ASSERT( t_completer_string == std::string("hello") ); + CPPUNIT_ASSERT( t_completer_double == 0.1234 ); + CPPUNIT_ASSERT( t_completer_bool == evcarg ); + this->reset(); + CPPUNIT_ASSERT( h2.disconnect() ); + + this->cleanup(); + +} + diff --git a/tests/eventservice_test.hpp b/tests/eventservice_test.hpp index 0cf1632d1..37e35a48e 100644 --- a/tests/eventservice_test.hpp +++ b/tests/eventservice_test.hpp @@ -37,6 +37,7 @@ class EventServiceTest : public CppUnit::TestFixture CPPUNIT_TEST( testEmit1 ); CPPUNIT_TEST( testEmit2 ); CPPUNIT_TEST( testEmit3 ); + CPPUNIT_TEST( testEventC ); CPPUNIT_TEST_SUITE_END(); ORO_CoreLib::Event* t_event0; @@ -79,6 +80,7 @@ class EventServiceTest : public CppUnit::TestFixture void testEmit1(); void testEmit2(); void testEmit3(); + void testEventC(); }; #endif // EVENTTEST_H diff --git a/tests/function_test.cpp b/tests/function_test.cpp index 3f81b1ba6..5863d7a51 100644 --- a/tests/function_test.cpp +++ b/tests/function_test.cpp @@ -23,7 +23,6 @@ #include #include #include -#include #include #include @@ -34,8 +33,8 @@ CPPUNIT_TEST_SUITE_REGISTRATION( FunctionTest ); FunctionTest::FunctionTest() - : gtc("root", &gprocessor), - gtask( 0.01, &gprocessor ) + : gtc("root" ), + gtask( 0.01, gtc.getExecutionEngine() ) {} @@ -327,7 +326,7 @@ void FunctionTest::testFunctionFail() void FunctionTest::doFunction( const std::string& prog, TaskContext* tc, bool test ) { stringstream progs(prog); - std::vector pg_list; + Parser::ParsedPrograms pg_list; try { pg_list = parser.parseProgram( progs, tc ); } @@ -339,8 +338,9 @@ void FunctionTest::doFunction( const std::string& prog, TaskContext* tc, bool te { CPPUNIT_ASSERT_MESSAGE("No program parsed in test.", false ); } - tc->getProcessor()->loadProgram( *pg_list.begin() ); - tc->getProcessor()->startProgram( (*pg_list.begin())->getName() ); + ProgramProcessor* pp = tc->getExecutionEngine()->getProgramProcessor(); + pp->loadProgram( *pg_list.begin() ); + pp->getProgram( (*pg_list.begin())->getName() )->start(); SimulationThread::Instance()->start(); gtask.start(); // while (1) @@ -350,16 +350,16 @@ void FunctionTest::doFunction( const std::string& prog, TaskContext* tc, bool te if (test ) { stringstream errormsg; - errormsg << " on line " << gprocessor.getProgram("x")->getLineNumber() <<"."<getProgram("x")->getLineNumber() <<"."<getProgramStatus("x") != ProgramInterface::Status::error ); + CPPUNIT_ASSERT_MESSAGE( "Program stalled " + errormsg.str(), pp->getProgramStatus("x") == ProgramInterface::Status::stopped ); } } void FunctionTest::finishFunction(TaskContext* tc, std::string prog_name) { - tc->getProcessor()->stopProgram( prog_name ); - tc->getProcessor()->deleteProgram( prog_name ); + tc->getExecutionEngine()->getProgramProcessor()->getProgram( prog_name )->stop(); + tc->getExecutionEngine()->getProgramProcessor()->unloadProgram( prog_name ); TaskContext* ptc= tc->getPeer("programs")->getPeer(prog_name); tc->getPeer("programs")->removePeer(prog_name); diff --git a/tests/function_test.hpp b/tests/function_test.hpp index ac3249540..fccb61801 100644 --- a/tests/function_test.hpp +++ b/tests/function_test.hpp @@ -23,7 +23,7 @@ #include #include -#include +#include #include #include #include @@ -46,7 +46,6 @@ class FunctionTest : public CppUnit::TestFixture CPPUNIT_TEST_SUITE_END(); Parser parser; - Processor gprocessor; TaskContext gtc; TaskSimulation gtask; MethodFactoryInterface* createMethodFactory(); diff --git a/tests/program_test.cpp b/tests/program_test.cpp index 545be09d3..ef556654f 100644 --- a/tests/program_test.cpp +++ b/tests/program_test.cpp @@ -22,7 +22,7 @@ #include #include #include -#include +#include #include #include @@ -33,8 +33,8 @@ CPPUNIT_TEST_SUITE_REGISTRATION( ProgramTest ); ProgramTest::ProgramTest() - : gtc("root", &gprocessor), - gtask( 0.01, &gprocessor ) + : gtc("root"), + gtask( 0.01, gtc.engine() ) {} @@ -180,7 +180,7 @@ void ProgramTest::testProgramFailure() this->doProgram( prog, >c, false ); - CPPUNIT_ASSERT( gprocessor.getProgramStatus("x") == Processor::ProgramStatus::error ); + CPPUNIT_ASSERT( gtc.engine()->programs()->getProgramStatus("x") == ProgramInterface::Status::error ); this->finishProgram( >c, "x"); } @@ -368,7 +368,7 @@ void ProgramTest::testProgramUntilFail() + " }"; this->doProgram( prog, >c, false ); - CPPUNIT_ASSERT( gprocessor.getProgramStatus("x") == Processor::ProgramStatus::error ); + CPPUNIT_ASSERT( gtc.engine()->programs()->getProgramStatus("x") == ProgramInterface::Status::error ); this->finishProgram( >c, "x"); } @@ -376,7 +376,7 @@ void ProgramTest::testProgramUntilFail() void ProgramTest::doProgram( const std::string& prog, TaskContext* tc, bool test ) { stringstream progs(prog); - std::vector pg_list; + Parser::ParsedPrograms pg_list; try { pg_list = parser.parseProgram( progs, tc ); } @@ -388,9 +388,10 @@ void ProgramTest::doProgram( const std::string& prog, TaskContext* tc, bool test { CPPUNIT_ASSERT( false ); } - tc->getProcessor()->loadProgram( *pg_list.begin() ); - std::string pname = (*pg_list.begin())->getName(); - tc->getProcessor()->startProgram( pname ); + ProgramInterfacePtr pi = *pg_list.begin(); + + tc->engine()->programs()->loadProgram( pi ); + pi->start(); SimulationThread::Instance()->start(); gtask.start(); // while (1) @@ -399,16 +400,16 @@ void ProgramTest::doProgram( const std::string& prog, TaskContext* tc, bool test if (test ) { stringstream errormsg; - errormsg << " on line " << gprocessor.getProgram( pname )->getLineNumber() <<"."<getLineNumber() <<"."<getStatus() != ProgramInterface::Status::error ); + CPPUNIT_ASSERT_MESSAGE( "Program stalled " + errormsg.str(), pi->getStatus() == ProgramInterface::Status::stopped ); // Xtra test, only do it if all previous went ok : - loopProgram( *pg_list.begin() ); + loopProgram( pi ); } } -void ProgramTest::loopProgram( FunctionGraph* f) +void ProgramTest::loopProgram( ProgramInterfacePtr f) { //std::cerr <getName(); // especially handy for performance testing : @@ -417,8 +418,8 @@ void ProgramTest::loopProgram( FunctionGraph* f) int loops = 100; f->reset(); while ( loops-- != 0 ) { - while ( !f->isFinished() && !f->inError() ) - f->executeUntil(); + while ( !f->isStopped() && !f->inError() ) + f->execute(); f->reset(); //std::cerr << "."; } @@ -428,8 +429,8 @@ void ProgramTest::loopProgram( FunctionGraph* f) void ProgramTest::finishProgram(TaskContext* tc, std::string prog_name) { gtask.stop(); - tc->getProcessor()->stopProgram( prog_name ); - tc->getProcessor()->deleteProgram( prog_name ); + tc->engine()->programs()->getProgram( prog_name )->stop(); + tc->engine()->programs()->unloadProgram( prog_name ); TaskContext* ptc= tc->getPeer("programs")->getPeer(prog_name); tc->getPeer("programs")->removePeer(prog_name); diff --git a/tests/program_test.hpp b/tests/program_test.hpp index 087dad4d9..5c5127cbc 100644 --- a/tests/program_test.hpp +++ b/tests/program_test.hpp @@ -23,7 +23,6 @@ #include #include -#include #include #include #include @@ -47,7 +46,6 @@ class ProgramTest : public CppUnit::TestFixture CPPUNIT_TEST_SUITE_END(); Parser parser; - Processor gprocessor; TaskContext gtc; TaskSimulation gtask; MethodFactoryInterface* createMethodFactory(); @@ -59,7 +57,7 @@ class ProgramTest : public CppUnit::TestFixture void reset(); void doProgram( const std::string& prog, TaskContext*, bool test=true ); void finishProgram( TaskContext* , std::string ); - void loopProgram( FunctionGraph*); + void loopProgram( ProgramInterfacePtr ); bool true_genCom() { return true; } bool false_genCom() { return false; } diff --git a/tests/state_test.cpp b/tests/state_test.cpp index b68837cb9..09c46a65f 100644 --- a/tests/state_test.cpp +++ b/tests/state_test.cpp @@ -38,7 +38,7 @@ CPPUNIT_TEST_SUITE_REGISTRATION( StateTest ); StateTest::StateTest() :gtc("root"), - gtask( 0.01, gtc.getExecutionEngine() ) + gtask( 0.01, gtc.engine() ) {} @@ -287,7 +287,7 @@ void StateTest::testStateFailure() this->doState( prog, >c, false ); // assert that an error happened : - CPPUNIT_ASSERT( gtc.getExecutionEngine()->getStateMachineProcessor()->getStateMachineStatus("x") == Processor::StateMachineStatus::error ); + CPPUNIT_ASSERT( gtc.getExecutionEngine()->getStateMachineProcessor()->getStateMachineStatus("x") == StateMachine::Status::error ); this->finishState( >c, "x"); } @@ -533,7 +533,7 @@ void StateTest::testStateSubStateCommands() + " final state FINI {\n" + " }\n" + " }\n" - + string("StateMachine X {\n") + + string("StateMachine X {\n") // 1 + " SubMachine Y y1(isnegative = -1.0)\n" + " initial state INIT {\n" + " entry {\n" @@ -544,7 +544,6 @@ void StateTest::testStateSubStateCommands() + " do y1.requestState(\"INIT\")\n" + " do test.assert( y1.inState(\"INIT\") )\n" + " set y1.isnegative = +1.0 \n" - // 40 : + " try y1.requestState(\"ISNEGATIVE\") \n " + " catch \n{\n" + " do test.assert( y1.inState(\"INIT\") )\n" // do not leave INIT @@ -628,10 +627,11 @@ void StateTest::testStateEvents() + " final state FINI {\n" + " }\n" + " }\n" // 40 - + string("StateMachine X {\n") + + string("StateMachine X {\n") // 1 + " SubMachine Y y1()\n" + " initial state INIT {\n" + " run {\n" + // + " do test.assert(false)\n" + " do y1.activate()\n" + " emit d_event(-1.0)\n" + " do nothing\n" @@ -642,19 +642,26 @@ void StateTest::testStateEvents() + " do test.assert( y1.inState(\"INIT\") )\n" + " emit d_event(+1.0)\n" // + " do nothing\n" + + " if ( !y1.inState(\"ISPOSITIVE\") ) then\n" + + " do test.assertMsg( false, y1.getState() )\n" + " do test.assert( y1.inState(\"ISPOSITIVE\") )\n" + " do y1.requestState(\"INIT\")\n" + " do test.assert( y1.inState(\"INIT\") )\n" + " emit b_event(true)\n" // + " do nothing\n" - + " do test.assert( y1.inState(\"ISTRUE\") )\n" + + " if ( !y1.inState(\"ISTRUE\") ) then\n" + + " do test.assertMsg(false, y1.getState() )\n" + + " do test.assertMsg( y1.inState(\"ISTRUE\"), y1.getState() )\n" + " do y1.requestState(\"INIT\")\n" + " do test.assert( y1.inState(\"INIT\") )\n" + " emit b_event(false)\n" // + " do nothing\n" + + " if ( !y1.inState(\"ISFALSE\") ) then\n" + + " do test.assertMsg(false, y1.getState() )\n" + " do test.assert( y1.inState(\"ISFALSE\") )\n" + " do y1.requestState(\"INIT\")\n" + " do test.assert( y1.inState(\"INIT\") )\n" + //+ " do y1.deactivate()\n" + " }\n" + " transitions {\n" + " select FINI\n" @@ -663,6 +670,7 @@ void StateTest::testStateEvents() + " final state FINI {\n" + " entry {\n" + " do y1.deactivate()\n" + //+ " do test.assert(false)\n" + " }\n" + " transitions {\n" + " select INIT\n" @@ -695,7 +703,7 @@ void StateTest::doState( const std::string& prog, TaskContext* tc, bool test ) { stringstream progs(prog); #ifndef NOPARSER - std::vector pg_list; + Parser::ParsedStateMachines pg_list; #else std::vector pg_list; sleep(5); @@ -723,7 +731,7 @@ void StateTest::doState( const std::string& prog, TaskContext* tc, bool test ) CPPUNIT_ASSERT( false ); } try { - tc->getProcessor()->loadStateMachine( *pg_list.begin() ); + tc->engine()->states()->loadStateMachine( *pg_list.begin() ); } catch( const program_load_exception& e) { @@ -734,15 +742,16 @@ void StateTest::doState( const std::string& prog, TaskContext* tc, bool test ) } CPPUNIT_ASSERT( SimulationThread::Instance()->start() ); CPPUNIT_ASSERT( gtask.start() ); - CommandInterface* ca = newCommandFunctor(boost::bind(&Processor::activateStateMachine, tc->getProcessor(),(*pg_list.begin())->getName() )); - CommandInterface* cs = newCommandFunctor(boost::bind(&Processor::startStateMachine,tc->getProcessor(),(*pg_list.begin())->getName() ) ); + StateMachinePtr sm = *pg_list.begin(); + CommandInterface* ca = newCommandFunctor(boost::bind(&StateMachine::activate, sm )); + CommandInterface* cs = newCommandFunctor(boost::bind(&StateMachine::automatic,sm )); // cerr << "Before activate :"<getPeer("states")->getPeer("x")->debug(true); CPPUNIT_ASSERT( ca->execute() ); - CPPUNIT_ASSERT_MESSAGE( "Error : Activate Command for '"+(*pg_list.begin())->getName()+"' did not have effect.", (*pg_list.begin())->isActive() ); + CPPUNIT_ASSERT_MESSAGE( "Error : Activate Command for '"+sm->getName()+"' did not have effect.", sm->isActive() ); // cerr << "After activate :"<getPeer("states")->getPeer("x")->debug(true); - CPPUNIT_ASSERT( gtc.getExecutionEngine()->getCommandProcessor()->process( cs ) != 0 ); + CPPUNIT_ASSERT( gtc.engine()->commands()->process( cs ) != 0 ); // while (1) sleep(1); delete ca; @@ -754,54 +763,58 @@ void StateTest::doState( const std::string& prog, TaskContext* tc, bool test ) // tc->getPeer("__states")->getPeer("Y")->debug(false); // cerr << " x.y1 running : "<< (gprocessor.getStateMachineStatus("x.y1") == Processor::StateMachineStatus::running) << endl; // cerr << " x running : "<< (gprocessor.getStateMachineStatus("x") == Processor::StateMachineStatus::running) << endl; + string sline; if (test ) { // check error status of parent : - CPPUNIT_ASSERT_MESSAGE( "Error : State Context '"+(*pg_list.begin())->getName()+"' did not get activated.", (*pg_list.begin())->isActive() ); + CPPUNIT_ASSERT_MESSAGE( "Error : State Context '"+sm->getName()+"' did not get activated.", sm->isActive() ); stringstream errormsg; - int line = (*pg_list.begin())->getLineNumber(); - errormsg <<" in StateContext "+(*pg_list.begin())->getName() - <<" in state "<< (*pg_list.begin())->currentState()->getName() + int line = sm->getLineNumber(); + errormsg <<" in StateContext "+sm->getName() + <<" in state "<< sm->currentState()->getName() <<" on line " << line <<" of that StateContext:"<getText() ); + stringstream sctext( sm->getText() ); int cnt = 1; while ( cnt++ " << sline << endl; - CPPUNIT_ASSERT_MESSAGE( "Runtime error encountered" + errormsg.str(), (*pg_list.begin())->inError() == false ); + CPPUNIT_ASSERT_MESSAGE( "Runtime error encountered" + errormsg.str(), sm->inError() == false ); // check error status of all children: - StateMachine::ChildList cl = (*pg_list.begin())->getChildren(); + StateMachine::ChildList cl = sm->getChildren(); StateMachine::ChildList::iterator clit = cl.begin(); while( clit != cl.end() ) { stringstream cerrormsg; if ( (*clit)->currentState() ) - cerrormsg <<" in state "<<(*clit)->currentState()->getName()<< " on line " << (*clit)->getLineNumber() <<" of that StateContext."<currentState()->getName()<< " on line " << (*clit)->getLineNumber() <<" of that StateContext."< " << sline << endl; else - cerrormsg <<" (deactivated) on line " << (*clit)->getLineNumber() <<" of that StateContext."<getLineNumber() <<" of that StateContext."< " << sline << endl; CPPUNIT_ASSERT_MESSAGE( "Runtime error encountered in child "+(*clit)->getName() + cerrormsg.str(), (*clit)->inError() == false ); ++clit; } } - tc->getProcessor()->stopStateMachine( (*pg_list.begin())->getName() ); + tc->engine()->states()->getStateMachine( sm->getName() )->stop(); sleep(1); - // after gtask.stop() it must be stopped. - CPPUNIT_ASSERT( gtask.stop() ); + // special property of sim: this does not stop the gtask. SimulationThread::Instance()->stop(); stringstream errormsg; - errormsg << " on line " << (*pg_list.begin())->getLineNumber() <<", status is "<< int(gtc.getExecutionEngine()->getStateMachineProcessor()->getStateMachineStatus("x")) <getStateMachineProcessor()->getStateMachineStatus("x") == Processor::StateMachineStatus::stopped ); + errormsg << " on line " << sm->getLineNumber() <<", status is "<< gtc.engine()->states()->getStateMachineStatusStr("x") < " << sline << endl;; + CPPUNIT_ASSERT_MESSAGE( "StateMachine stalled " + errormsg.str(), sm->isStopped() ); } void StateTest::finishState(TaskContext* tc, std::string prog_name) { // you can call deactivate even when the proc is not running. // but deactivation may be 'in progress if exit state has commands in it. - CPPUNIT_ASSERT( tc->getProcessor()->deactivateStateMachine( prog_name ) ); + CPPUNIT_ASSERT( tc->engine()->states()->getStateMachine( prog_name )->deactivate() ); + CPPUNIT_ASSERT( tc->engine()->states()->getStateMachine( prog_name )->isActive() == false ); + + // only stop now, since deactivate won't work if simtask not running. + CPPUNIT_ASSERT( gtask.stop() ); + try { - tc->getProcessor()->deleteStateMachine( prog_name ); + tc->engine()->states()->unloadStateMachine( prog_name ); } catch( const program_unload_exception& e) { diff --git a/tests/state_test.hpp b/tests/state_test.hpp index c0c08b065..3821d9770 100644 --- a/tests/state_test.hpp +++ b/tests/state_test.hpp @@ -27,7 +27,6 @@ #include #endif -#include #include #include #include diff --git a/tests/tasks_test.cpp b/tests/tasks_test.cpp index 15dbd7305..99ca34eed 100644 --- a/tests/tasks_test.cpp +++ b/tests/tasks_test.cpp @@ -317,6 +317,7 @@ void TasksTest::testNonPeriodic() sleep(1); CPPUNIT_ASSERT( t_run_int_nonper->stepped ); CPPUNIT_ASSERT( t_run_int_nonper->init ); + t_task_nonper->stop(); CPPUNIT_ASSERT( t_run_int_nonper->fini ); CPPUNIT_ASSERT( !t_task_nonper->isRunning() ); t_task_nonper->run( 0 ); diff --git a/tests/template_factory_test.cpp b/tests/template_factory_test.cpp index 20e6dea5c..a8e0b4bc5 100644 --- a/tests/template_factory_test.cpp +++ b/tests/template_factory_test.cpp @@ -2,11 +2,14 @@ #include "template_factory_test.hpp" #include #include -#include +#include #include #include #include +#include +#include + #include #ifdef OROPKG_GEOMETRY #include @@ -22,19 +25,23 @@ CPPUNIT_TEST_SUITE_REGISTRATION( Template_FactoryTest ); void Template_FactoryTest::setUp() { - tc = new TaskContext( "root", &processor); + tc = new TaskContext( "root" ); tc->methodFactory.registerObject("methods", this->createMethodFactory() ); tc->commandFactory.registerObject("commands", this->createCommandFactory() ); tc->dataFactory.registerObject("data", this->createDataSourceFactory() ); + tsim = new TaskSimulation(0.001, tc->engine() ); } void Template_FactoryTest::tearDown() { - if ( tc->getPeer("programs") ) - delete tc->getPeer("programs"); +// if ( tc->getPeer("programs") ) +// delete tc->getPeer("programs"); + tsim->stop(); + SimulationThread::Instance()->stop(); delete tc; + delete tsim; } bool Template_FactoryTest::assertBool( bool b) { @@ -87,6 +94,23 @@ CommandFactoryInterface* Template_FactoryTest::createCommandFactory() return dat; } +void Template_FactoryTest::executePrograms(const Parser::ParsedPrograms& pg_list ) +{ + tc->getExecutionEngine()->getProgramProcessor()->loadProgram( *pg_list.begin() ); + SimulationThread::Instance()->start(); + tsim->start(); + CPPUNIT_ASSERT( (*pg_list.begin())->start() ); + sleep(1); + CPPUNIT_ASSERT( (*pg_list.begin())->stop() ); + tsim->stop(); + SimulationThread::Instance()->stop(); + if ( (*pg_list.begin())->inError() ) { + stringstream errormsg; + errormsg << " Program error on line " << (*pg_list.begin())->getLineNumber() <<"."< pg_list; + Parser::ParsedPrograms pg_list; try { pg_list = parser.parseProgram( progs, tc); } @@ -118,8 +142,37 @@ void Template_FactoryTest::testMethods() CPPUNIT_ASSERT( false ); } // execute - CPPUNIT_ASSERT( (*pg_list.begin())->executeAll() ); - delete *pg_list.begin(); + executePrograms( pg_list ); +} + +void Template_FactoryTest::testMethodsC() +{ + MethodC mc; + double r = 0.0; + mc = tc->methods()->create("methods", "m0").ret( r ); + CPPUNIT_ASSERT( mc.execute() ); + CPPUNIT_ASSERT( r == -1.0 ); + + mc = tc->methods()->create("methods", "m2").argC(1).argC(1.0).ret( r ); + CPPUNIT_ASSERT( mc.execute() ); + CPPUNIT_ASSERT( r == -3.0 ); + + mc = tc->methods()->create("methods", "m3").ret( r ).argC(1).argC(1.0).argC(true); + CPPUNIT_ASSERT( mc.execute() ); + CPPUNIT_ASSERT( r == -4.0 ); + +#if 0 + +" set r = methods.m0()\n" + +" do methods.assert( r == -1.0 )\n" + +" set r = methods.m1(1)\n" + +" do methods.assert( r == -2.0 )\n" + +" set r = methods.m2(1, 1.0)\n" + +" do methods.assert( r == -3.0 )\n" + +" set r = methods.m3(1, 1.0, true)\n" + +" do methods.assert( r == -4.0 )\n" + +" set r = methods.m4(1, 1.0, true, \"hello\")\n" + +" do methods.assert( r == -5.0 )\n" +#endif } void Template_FactoryTest::testData() @@ -139,7 +192,7 @@ void Template_FactoryTest::testData() +" do methods.assert( r == 5.0 )\n" +"}"; stringstream progs(prog); - std::vector pg_list; + Parser::ParsedPrograms pg_list; try { pg_list = parser.parseProgram( progs, tc); } @@ -152,8 +205,7 @@ void Template_FactoryTest::testData() CPPUNIT_ASSERT( false ); } // execute - CPPUNIT_ASSERT( (*pg_list.begin())->executeAll() ); - delete *pg_list.begin(); + executePrograms( pg_list ); } void Template_FactoryTest::testCommands() @@ -170,7 +222,7 @@ void Template_FactoryTest::testCommands() +" do commands.c33(1, 1.0, 'a')\n" +"}"; stringstream progs(prog); - std::vector pg_list; + Parser::ParsedPrograms pg_list; try { pg_list = parser.parseProgram( progs, tc); } @@ -183,8 +235,49 @@ void Template_FactoryTest::testCommands() CPPUNIT_ASSERT( false ); } // execute - CPPUNIT_ASSERT( (*pg_list.begin())->executeAll() ); - delete *pg_list.begin(); + executePrograms( pg_list ); +} + +void Template_FactoryTest::testCommandsC() +{ + CommandC cc = tc->commands()->create("commands","c00"); + CommandC c20 = tc->commands()->create("commands","c20").argC(1).argC(1.0); + CommandC c32 = tc->commands()->create("commands","c31").argC(1).argC(1.0).argC('a'); + CommandC c33 = tc->commands()->create("commands","c33").argC(1).argC(1.0).argC('a'); + SimulationThread::Instance()->start(); + tsim->start(); + CPPUNIT_ASSERT( cc.execute() ); + CPPUNIT_ASSERT( c20.execute() ); + CPPUNIT_ASSERT( c32.execute() ); + CPPUNIT_ASSERT( c33.execute() ); + sleep(1); + CPPUNIT_ASSERT( cc.accepted() ); + CPPUNIT_ASSERT( c20.accepted() ); + CPPUNIT_ASSERT( c32.accepted() ); + CPPUNIT_ASSERT( c33.accepted() ); + CPPUNIT_ASSERT( cc.valid() ); + CPPUNIT_ASSERT( c20.valid() ); + CPPUNIT_ASSERT( c32.valid() ); + CPPUNIT_ASSERT( c33.valid() ); + CPPUNIT_ASSERT( cc.evaluate() ); + CPPUNIT_ASSERT( c20.evaluate() ); + CPPUNIT_ASSERT( c32.evaluate() ); + CPPUNIT_ASSERT( c33.evaluate() ); + tsim->stop(); + SimulationThread::Instance()->stop(); +#if 0 + string prog = string("program x { ") + +" do commands.c00()\n" + +" do commands.c10(1)\n" + +" do commands.c11(1)\n" + +" do commands.c20(1, 1.0)\n" + +" do commands.c21(1, 1.0)\n" + +" do commands.c22(1, 1.0)\n" + +" do commands.c30(1, 1.0, 'a')\n" + +" do commands.c31(1, 1.0, 'a')\n" + +" do commands.c33(1, 1.0, 'a')\n" + +"}"; +#endif } void Template_FactoryTest::testManual() diff --git a/tests/template_factory_test.hpp b/tests/template_factory_test.hpp index ed86fe1a0..6891c5b09 100644 --- a/tests/template_factory_test.hpp +++ b/tests/template_factory_test.hpp @@ -4,7 +4,7 @@ #include #include -#include +#include #include #include #include @@ -16,18 +16,22 @@ class Template_FactoryTest : public CppUnit::TestFixture { CPPUNIT_TEST_SUITE( Template_FactoryTest ); CPPUNIT_TEST( testMethods ); + CPPUNIT_TEST( testMethodsC ); CPPUNIT_TEST( testData ); CPPUNIT_TEST( testCommands ); + CPPUNIT_TEST( testCommandsC ); CPPUNIT_TEST( testManual ); CPPUNIT_TEST_SUITE_END(); Parser parser; TaskContext* tc; - Processor processor; + TaskInterface* tsim; + CommandProcessor processor; MethodFactoryInterface* createMethodFactory(); DataSourceFactoryInterface* createDataSourceFactory(); CommandFactoryInterface* createCommandFactory(); + void executePrograms(const Parser::ParsedPrograms& pg_list ); double m0() { return -d0(); } double m1(int i) { return -d1(i); } double m2(int i, double d) { return -d2(i,d); } @@ -57,8 +61,10 @@ class Template_FactoryTest : public CppUnit::TestFixture void tearDown(); void testMethods(); + void testMethodsC(); void testData(); void testCommands(); + void testCommandsC(); void testManual(); }; diff --git a/tests/types_test.cpp b/tests/types_test.cpp index e27e03023..431c03cec 100644 --- a/tests/types_test.cpp +++ b/tests/types_test.cpp @@ -21,13 +21,10 @@ #include "types_test.hpp" #include #include -#include +#include #include -#include -#ifdef OROPKG_GEOMETRY -#include -using namespace ORO_Geometry; -#endif +#include +#include using namespace std; @@ -38,15 +35,19 @@ CPPUNIT_TEST_SUITE_REGISTRATION( TypesTest ); void TypesTest::setUp() { - tc = new TaskContext( "root", &processor); + tc = new TaskContext( "root" ); tc->methodFactory.registerObject("test", this->createMethodFactory() ); + tsim = new TaskSimulation( 0.001, tc->engine() ); } void TypesTest::tearDown() { + tsim->stop(); + SimulationThread::Instance()->stop(); delete tc; + delete tsim; } @@ -68,13 +69,16 @@ bool TypesTest::assertMsg( bool b, const std::string& msg) { "Assert", "bool", "") ); dat->add( "assertMsg", method( &TypesTest::assertMsg, "Assert message", "bool", "", "text", "text" ) ); +#ifdef OROPKG_GEOMETRY dat->add( "equalFrames", method( &TypesTest::equalFrames, "Assert equal frames", "f1", "", "f2", "" ) ); dat->add( "equalVectors", method( &TypesTest::equalVectors, "Assert equal vectors", "v1", "", "v2", "" ) ); +#endif return dat; } +#ifdef OROPKG_GEOMETRY bool TypesTest::equalFrames(const Frame& f1, Frame& f2) { return f1 == f2; @@ -84,12 +88,13 @@ bool TypesTest::equalVectors(const Vector& f1, Vector& f2) { return f1 == f2; } +#endif void TypesTest::testEmptyProgram() { string prog = ""; stringstream progs(prog); - std::vector pg_list; + Parser::ParsedPrograms pg_list; try { pg_list = parser.parseProgram( progs, tc ); } @@ -107,7 +112,7 @@ void TypesTest::testReturnProgram() { string prog = "program x { return \n }"; stringstream progs(prog); - std::vector pg_list; + Parser::ParsedPrograms pg_list; try { pg_list = parser.parseProgram( progs, tc); } @@ -120,8 +125,7 @@ void TypesTest::testReturnProgram() CPPUNIT_ASSERT( false ); } // execute - CPPUNIT_ASSERT( (*pg_list.begin())->executeAll() ); - delete *pg_list.begin(); + executePrograms(pg_list); } void TypesTest::testTypes() @@ -209,7 +213,7 @@ void TypesTest::testTypes() "do test.assert( str[10] == '\\0' )\n"+ "}"; stringstream progs(prog); - std::vector pg_list; + Parser::ParsedPrograms pg_list; try { pg_list = parser.parseProgram( progs, tc ); } @@ -222,13 +226,7 @@ void TypesTest::testTypes() CPPUNIT_ASSERT( false ); } // execute - if ( (*pg_list.begin())->executeAll() == false ) { - stringstream errormsg; - errormsg << " Program error on line " << (*pg_list.begin())->getLineNumber() <<"."< pg_list; + Parser::ParsedPrograms pg_list; try { pg_list = parser.parseProgram( progs, tc ); } @@ -268,13 +266,25 @@ void TypesTest::testOperators() CPPUNIT_ASSERT( false ); } // execute - if ( (*pg_list.begin())->executeAll() == false ) { + executePrograms(pg_list); +} + +void TypesTest::executePrograms(const Parser::ParsedPrograms& pg_list ) +{ + tc->getExecutionEngine()->getProgramProcessor()->loadProgram( *pg_list.begin() ); + SimulationThread::Instance()->start(); + tsim->start(); + CPPUNIT_ASSERT( (*pg_list.begin())->start() ); + sleep(1); + CPPUNIT_ASSERT( (*pg_list.begin())->stop() ); + tsim->stop(); + SimulationThread::Instance()->stop(); + if ( (*pg_list.begin())->inError() ) { stringstream errormsg; errormsg << " Program error on line " << (*pg_list.begin())->getLineNumber() <<"."<engine()->programs()->unloadProgram( (*pg_list.begin())->getName() ); } void TypesTest::testProperties() @@ -336,7 +346,7 @@ void TypesTest::testProperties() tc->attributeRepository.addProperty( &pb ); stringstream progs(prog); - std::vector pg_list; + Parser::ParsedPrograms pg_list; try { pg_list = parser.parseProgram( progs, tc ); } @@ -349,15 +359,9 @@ void TypesTest::testProperties() CPPUNIT_ASSERT( false ); } // execute - if ( (*pg_list.begin())->executeAll() == false ) { - stringstream errormsg; - errormsg << " Program error on line " << (*pg_list.begin())->getLineNumber() <<"."< #include -#include +#include #include #include -#include #include +#include +#ifdef OROPKG_GEOMETRY +#include +using namespace ORO_Geometry; +#endif using namespace ORO_CoreLib; using namespace ORO_Execution; -using namespace ORO_Geometry; class TypesTest : public CppUnit::TestFixture { @@ -45,12 +48,15 @@ class TypesTest : public CppUnit::TestFixture Parser parser; TaskContext* tc; - Processor processor; + TaskInterface* tsim; MethodFactoryInterface* createMethodFactory(); bool assertBool( bool ); +#ifdef OROPKG_GEOMETRY bool equalFrames(const Frame& f1, Frame& f2); bool equalVectors(const Vector& f1, Vector& f2); +#endif bool assertMsg( bool, const std::string& msg); + void executePrograms(const Parser::ParsedPrograms& pg_list); public: void setUp();