From 4142f5850854e0bf753d4ba41c98bc1cc65ba9c1 Mon Sep 17 00:00:00 2001 From: psoetens Date: Fri, 29 May 2009 11:17:03 +0200 Subject: [PATCH] Removed old cppunit tests directory. --- tests/CMakeLists.txt | 98 ---- tests/FakeAnalogDevice.hpp | 130 ----- tests/FakeDigitalDevice.hpp | 140 ----- tests/buffers_test.cpp | 817 -------------------------- tests/buffers_test.hpp | 90 --- tests/corba_test.cpp | 555 ------------------ tests/corba_test.hpp | 104 ---- tests/dev_test.cpp | 85 --- tests/dev_test.hpp | 41 -- tests/dispatch_test.cpp | 299 ---------- tests/dispatch_test.hpp | 86 --- tests/event_test.cpp | 558 ------------------ tests/event_test.hpp | 85 --- tests/eventservice_test.cpp | 395 ------------- tests/eventservice_test.hpp | 86 --- tests/function_test.cpp | 338 ----------- tests/function_test.hpp | 83 --- tests/generictask_test.cpp | 322 ----------- tests/generictask_test.hpp | 90 --- tests/generictask_test_2.cpp | 773 ------------------------- tests/generictask_test_2.hpp | 113 ---- tests/generictask_test_3.cpp | 997 -------------------------------- tests/generictask_test_3.hpp | 75 --- tests/logger_test.cpp | 116 ---- tests/logger_test.hpp | 50 -- tests/program_test.cpp | 441 -------------- tests/program_test.hpp | 91 --- tests/property_test.cpp | 404 ------------- tests/property_test.hpp | 76 --- tests/property_test_vect.cpf | 14 - tests/state_test.cpp | 972 ------------------------------- tests/state_test.hpp | 97 ---- tests/tasks_multiple_test.cpp | 168 ------ tests/tasks_multiple_test.hpp | 120 ---- tests/tasks_test.cpp | 391 ------------- tests/tasks_test.hpp | 102 ---- tests/taskthread_test.cpp | 580 ------------------- tests/taskthread_test.hpp | 86 --- tests/template_factory_test.cpp | 343 ----------- tests/template_factory_test.hpp | 103 ---- tests/test-runner.cpp | 56 -- tests/time_test.cpp | 286 --------- tests/time_test.hpp | 56 -- tests/types_test.cpp | 370 ------------ tests/types_test.hpp | 60 -- 45 files changed, 11342 deletions(-) delete mode 100644 tests/CMakeLists.txt delete mode 100644 tests/FakeAnalogDevice.hpp delete mode 100644 tests/FakeDigitalDevice.hpp delete mode 100644 tests/buffers_test.cpp delete mode 100644 tests/buffers_test.hpp delete mode 100644 tests/corba_test.cpp delete mode 100644 tests/corba_test.hpp delete mode 100644 tests/dev_test.cpp delete mode 100644 tests/dev_test.hpp delete mode 100644 tests/dispatch_test.cpp delete mode 100644 tests/dispatch_test.hpp delete mode 100644 tests/event_test.cpp delete mode 100644 tests/event_test.hpp delete mode 100644 tests/eventservice_test.cpp delete mode 100644 tests/eventservice_test.hpp delete mode 100644 tests/function_test.cpp delete mode 100644 tests/function_test.hpp delete mode 100644 tests/generictask_test.cpp delete mode 100644 tests/generictask_test.hpp delete mode 100644 tests/generictask_test_2.cpp delete mode 100644 tests/generictask_test_2.hpp delete mode 100644 tests/generictask_test_3.cpp delete mode 100644 tests/generictask_test_3.hpp delete mode 100644 tests/logger_test.cpp delete mode 100644 tests/logger_test.hpp delete mode 100644 tests/program_test.cpp delete mode 100644 tests/program_test.hpp delete mode 100644 tests/property_test.cpp delete mode 100644 tests/property_test.hpp delete mode 100644 tests/property_test_vect.cpf delete mode 100644 tests/state_test.cpp delete mode 100644 tests/state_test.hpp delete mode 100644 tests/tasks_multiple_test.cpp delete mode 100644 tests/tasks_multiple_test.hpp delete mode 100644 tests/tasks_test.cpp delete mode 100644 tests/tasks_test.hpp delete mode 100644 tests/taskthread_test.cpp delete mode 100644 tests/taskthread_test.hpp delete mode 100644 tests/template_factory_test.cpp delete mode 100644 tests/template_factory_test.hpp delete mode 100644 tests/test-runner.cpp delete mode 100644 tests/time_test.cpp delete mode 100644 tests/time_test.hpp delete mode 100644 tests/types_test.cpp delete mode 100644 tests/types_test.hpp diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt deleted file mode 100644 index 0f65f56e0..000000000 --- a/tests/CMakeLists.txt +++ /dev/null @@ -1,98 +0,0 @@ -IF (ENABLE_TESTS AND CPPUNIT) - IF (ENABLE_CORBA) - INCLUDE_DIRECTORIES(${CORBA_INCLUDE_DIRS}) - LINK_DIRECTORIES(${CORBA_LINK_DIRECTORIES}) - ADD_DEFINITIONS(${CORBA_DEFINES}) - LINK_LIBRARIES( ${CORBA_LIBRARIES} ) - ENDIF(ENABLE_CORBA) - - # See ADD_TEST() below. - ENABLE_TESTING() - SET(COMPILE_FLAGS "${CMAKE_CXX_FLAGS_ADD} ${RTT_CFLAGS} -DOROCOS_TARGET=${OROCOS_TARGET}") - INCLUDE_DIRECTORIES( ${PROJ_SOURCE_DIR}/src ${PROJ_BINARY_DIR}/src ${PROJ_BINARY_DIR}/src/os ${PROJ_BINARY_DIR}/src/os/${OROCOS_TARGET} ${CPPUNIT_HEADERS}) - LINK_DIRECTORIES( ${PROJ_BINARY_DIR}/src ) - IF(ENABLE_CORBA) - INCLUDE_DIRECTORIES( ${PROJ_BINARY_DIR}/src/corba/ ) - LINK_DIRECTORIES( ${PROJ_BINARY_DIR}/src/corba/ ) - # Work around unresolved symbols in tests when using CORBA *and* STATIC - IF(BUILD_STATIC) - LINK_LIBRARIES( orocos-rtt-corba-${OROCOS_TARGET} orocos-rtt-${OROCOS_TARGET} orocos-rtt-corba-${OROCOS_TARGET} orocos-rtt-${OROCOS_TARGET}) - ENDIF(BUILD_STATIC) - ENDIF(ENABLE_CORBA) - ADD_DEFINITIONS("-g") - - #EXCLUDE_FROM_ALL is cmake 2.4.4 - SET(DO_EXCLUDE) - IF (${CMAKE_VERSION} STRGREATER "2.4.3" ) - SET(DO_EXCLUDE EXCLUDE_FROM_ALL) - ENDIF (${CMAKE_VERSION} STRGREATER "2.4.3" ) - - # Copy over CPF files. - ADD_CUSTOM_TARGET(prep-cpf - cp -R "${CMAKE_CURRENT_SOURCE_DIR}/*.cpf" "${CMAKE_CURRENT_BINARY_DIR}" - ) - - # repeat for each test - ADD_EXECUTABLE( core-test ${DO_EXCLUDE} test-runner.cpp time_test.cpp property_test.cpp logger_test.cpp buffers_test.cpp ) - TARGET_LINK_LIBRARIES( core-test orocos-rtt-${OROCOS_TARGET} ${CPPUNIT} ) - SET_TARGET_PROPERTIES( core-test PROPERTIES - COMPILE_FLAGS "${CMAKE_CXX_FLAGS_ADD} ${RTT_CFLAGS} -DOROCOS_TARGET=${OROCOS_TARGET}") - ADD_TEST( core-test core-test ) - - ADD_EXECUTABLE( task-test ${DO_EXCLUDE} test-runner.cpp tasks_test.cpp taskthread_test.cpp tasks_multiple_test.cpp ) - TARGET_LINK_LIBRARIES( task-test orocos-rtt-${OROCOS_TARGET} ${CPPUNIT} ) - SET_TARGET_PROPERTIES( task-test PROPERTIES - COMPILE_FLAGS "${CMAKE_CXX_FLAGS_ADD} ${RTT_CFLAGS} -DOROCOS_TARGET=${OROCOS_TARGET}") - ADD_TEST( task-test task-test ) - - ADD_EXECUTABLE( event-test ${DO_EXCLUDE} test-runner.cpp event_test.cpp eventservice_test.cpp ) - TARGET_LINK_LIBRARIES( event-test orocos-rtt-${OROCOS_TARGET} ${CPPUNIT} ) - SET_TARGET_PROPERTIES( event-test PROPERTIES - COMPILE_FLAGS "${CMAKE_CXX_FLAGS_ADD} ${RTT_CFLAGS} -DOROCOS_TARGET=${OROCOS_TARGET}") - ADD_TEST( event-test event-test ) - - ADD_EXECUTABLE( taskcontext-test ${DO_EXCLUDE} test-runner.cpp generictask_test.cpp generictask_test_2.cpp generictask_test_3.cpp ) - TARGET_LINK_LIBRARIES( taskcontext-test orocos-rtt-${OROCOS_TARGET} ${CPPUNIT} ) - SET_TARGET_PROPERTIES( taskcontext-test PROPERTIES - COMPILE_FLAGS "${CMAKE_CXX_FLAGS_ADD} ${RTT_CFLAGS} -DOROCOS_TARGET=${OROCOS_TARGET}") - ADD_TEST( taskcontext-test taskcontext-test ) - - ADD_EXECUTABLE( parser-test ${DO_EXCLUDE} test-runner.cpp types_test.cpp template_factory_test.cpp dispatch_test.cpp ) - TARGET_LINK_LIBRARIES( parser-test orocos-rtt-${OROCOS_TARGET} ${CPPUNIT} ) - SET_TARGET_PROPERTIES( parser-test PROPERTIES - COMPILE_FLAGS "${CMAKE_CXX_FLAGS_ADD} ${RTT_CFLAGS} -DOROCOS_TARGET=${OROCOS_TARGET}") - ADD_TEST( parser-test parser-test ) - - ADD_EXECUTABLE( program-test ${DO_EXCLUDE} test-runner.cpp program_test.cpp function_test.cpp ) - TARGET_LINK_LIBRARIES( program-test orocos-rtt-${OROCOS_TARGET} ${CPPUNIT}) - SET_TARGET_PROPERTIES( program-test PROPERTIES - COMPILE_FLAGS "${CMAKE_CXX_FLAGS_ADD} ${RTT_CFLAGS} -DOROCOS_TARGET=${OROCOS_TARGET}") - ADD_TEST( program-test program-test ) - - ADD_EXECUTABLE( state-test ${DO_EXCLUDE} test-runner.cpp state_test.cpp ) - TARGET_LINK_LIBRARIES( state-test orocos-rtt-${OROCOS_TARGET} ${CPPUNIT} ) - SET_TARGET_PROPERTIES( state-test PROPERTIES - COMPILE_FLAGS "${CMAKE_CXX_FLAGS_ADD} ${RTT_CFLAGS} -DOROCOS_TARGET=${OROCOS_TARGET}") - ADD_TEST( state-test state-test ) - - ADD_EXECUTABLE( dev-test ${DO_EXCLUDE} test-runner.cpp dev_test.cpp ) - TARGET_LINK_LIBRARIES( dev-test orocos-rtt-${OROCOS_TARGET} ${CPPUNIT} ) - SET_TARGET_PROPERTIES( dev-test PROPERTIES - COMPILE_FLAGS "${CMAKE_CXX_FLAGS_ADD} ${RTT_CFLAGS} -DOROCOS_TARGET=${OROCOS_TARGET}") - ADD_TEST( dev-test dev-test ) - - IF(ENABLE_CORBA) - ADD_EXECUTABLE( corba-test ${DO_EXCLUDE} test-runner.cpp corba_test.cpp ) - TARGET_LINK_LIBRARIES( corba-test orocos-rtt-${OROCOS_TARGET} orocos-rtt-corba-${OROCOS_TARGET} ${CPPUNIT} ${ORO_ACETAO_LIBRARIES}) - SET_TARGET_PROPERTIES( corba-test PROPERTIES - COMPILE_FLAGS "${CMAKE_CXX_FLAGS_ADD} ${RTT_CFLAGS} -DOROCOS_TARGET=${OROCOS_TARGET}") - ADD_TEST( corba-test corba-test ) - SET(ORO_EXTRA_TESTS "corba-test") - ENDIF(ENABLE_CORBA) - - ADD_CUSTOM_TARGET(check ctest -V - DEPENDS core-test task-test event-test taskcontext-test parser-test program-test state-test dev-test ${ORO_EXTRA_TESTS} - WORKING_DIRECTORY ${PROJ_BINARY_DIR}/tests) - - ADD_DEPENDENCIES(check prep-cpf) -ENDIF(ENABLE_TESTS AND CPPUNIT) diff --git a/tests/FakeAnalogDevice.hpp b/tests/FakeAnalogDevice.hpp deleted file mode 100644 index 0b835119e..000000000 --- a/tests/FakeAnalogDevice.hpp +++ /dev/null @@ -1,130 +0,0 @@ -/*************************************************************************** - tag: Peter Soetens Thu Apr 22 20:40:59 CEST 2004 FakeAnalogDevice.hpp - - FakeAnalogDevice.hpp - description - ------------------- - begin : Thu April 22 2004 - copyright : (C) 2004 Peter Soetens - email : peter.soetens@mech.kuleuven.ac.be - - *************************************************************************** - * This library is free software; you can redistribute it and/or * - * modify it under the terms of the GNU Lesser General Public * - * License as published by the Free Software Foundation; either * - * version 2.1 of the License, or (at your option) any later version. * - * * - * This library is distributed in the hope that it will be useful, * - * but WITHOUT ANY WARRANTY; without even the implied warranty of * - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * - * Lesser General Public License for more details. * - * * - * You should have received a copy of the GNU Lesser General Public * - * License along with this library; if not, write to the Free Software * - * Foundation, Inc., 59 Temple Place, * - * Suite 330, Boston, MA 02111-1307 USA * - * * - ***************************************************************************/ - -#ifndef FAKEANALOGDEVICE_HPP -#define FAKEANALOGDEVICE_HPP - -#include "dev/AnalogInInterface.hpp" -#include "dev/AnalogOutInterface.hpp" - -namespace RTT -{ - /** - * A test class which replaces a real device driver. - * It reproduces on the output what it gets on the input. - */ - struct FakeAnalogDevice : - public AnalogInInterface, - public AnalogOutInterface - { - unsigned int nbofchans; - int* mchannels; - unsigned int mbin_range; - double mlowest, mhighest; - - FakeAnalogDevice(unsigned int channels=32, unsigned int bin_range=4096, double lowest = -5.0, double highest = +5.0) - : AnalogInInterface("FakeAnalogDevice"), - AnalogOutInterface("FakeAnalogDevice"), - nbofchans(channels), - mchannels( new int[channels] ), - mbin_range( bin_range), - mlowest( lowest), - mhighest( highest) - {} - - ~FakeAnalogDevice() { - delete[] mchannels; - } - - virtual void rangeSet(unsigned int /*chan*/, - unsigned int /*range*/) {} - - virtual void arefSet(unsigned int /*chan*/, - unsigned int /*aref*/) {} - - virtual unsigned int nbOfChannels() const { - return nbofchans; - } - - virtual int read( unsigned int chan, double& value ) - { - if (chan < nbofchans) { - value = mchannels[chan] / resolution(chan) + mlowest; - return 0; - } - return -1; - } - - virtual int write( unsigned int chan, double value ) { - if (chan < nbofchans) { - mchannels[chan] = (unsigned int)((value - mlowest) * resolution(chan)); - return 0; - } - return -1; - } - - virtual int rawRead( unsigned int chan, int & value ) - { - if (chan < nbofchans) { - value = mchannels[chan]; - return 0; - } - return -1; - } - - virtual int rawWrite( unsigned int chan, int value ) { - if (chan < nbofchans) - mchannels[chan] = value; - return 0; - } - - - virtual unsigned int rawRange() const - { - return mbin_range; - } - - virtual double lowest(unsigned int /*chan*/) const - { - return mlowest; - } - - virtual double highest(unsigned int /*chan*/) const - { - return mhighest; - } - - virtual double resolution(unsigned int /*chan*/) const - { - return mbin_range/(mhighest-mlowest); - } - - }; - -} - -#endif diff --git a/tests/FakeDigitalDevice.hpp b/tests/FakeDigitalDevice.hpp deleted file mode 100644 index 9dd592df2..000000000 --- a/tests/FakeDigitalDevice.hpp +++ /dev/null @@ -1,140 +0,0 @@ -/*************************************************************************** - tag: Peter Soetens Thu Apr 22 20:40:58 CEST 2004 FakeDigitalDevice.hpp - - FakeDigitalDevice.hpp - description - ------------------- - begin : Thu April 22 2004 - copyright : (C) 2004 Peter Soetens - email : peter.soetens@mech.kuleuven.ac.be - - *************************************************************************** - * This library is free software; you can redistribute it and/or * - * modify it under the terms of the GNU Lesser General Public * - * License as published by the Free Software Foundation; either * - * version 2.1 of the License, or (at your option) any later version. * - * * - * This library is distributed in the hope that it will be useful, * - * but WITHOUT ANY WARRANTY; without even the implied warranty of * - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * - * Lesser General Public License for more details. * - * * - * You should have received a copy of the GNU Lesser General Public * - * License along with this library; if not, write to the Free Software * - * Foundation, Inc., 59 Temple Place, * - * Suite 330, Boston, MA 02111-1307 USA * - * * - ***************************************************************************/ - -#ifndef FAKEDIGITALDEVICE_HPP -#define FAKEDIGITALDEVICE_HPP - -#include "dev/DigitalInInterface.hpp" -#include "dev/DigitalOutInterface.hpp" -#include - -namespace RTT -{ - /** - * A Fake (Simulated) Digital Input/Output Device which replicates the inputs - * on its outputs. - */ - class FakeDigitalDevice - : public DigitalInInterface, - public DigitalOutInterface - { - public: - std::vector mchannels; - - FakeDigitalDevice(unsigned int channels=32) - : DigitalInInterface("FakeDigitalDevice"), - DigitalOutInterface("FakeDigitalDevice"), - mchannels(channels, false) - {} - - virtual void switchOn( unsigned int n ) - { - if ( n < mchannels.size() ) - mchannels[n] = true; - } - - virtual void switchOff( unsigned int n ) - { - if ( n < mchannels.size() ) - mchannels[n] = false; - } - - virtual void setBit( unsigned int bit, bool value ) - { - if ( bit < mchannels.size() ) - mchannels[bit] = value; - } - - virtual void setSequence(unsigned int start_bit, unsigned int stop_bit, unsigned int value) - { - if ( start_bit < mchannels.size() && stop_bit < mchannels.size() ) - for (unsigned int i = start_bit; i <= stop_bit; ++i) - mchannels[i] = value & ( 1<<( i - start_bit ) ); - } - - virtual bool checkBit(unsigned int n) const - { - if ( n < mchannels.size() ) - return mchannels[n]; - return false; - } - - - virtual unsigned int checkSequence( unsigned int start_bit, unsigned int stop_bit ) const - { - unsigned int result = 0; - if ( start_bit < mchannels.size() && stop_bit < mchannels.size() ) - for (unsigned int i = start_bit; i <= stop_bit; ++i) - result += (mchannels[i] & 1)< -#include -#include - -using namespace std; - -// Registers the fixture into the 'registry' -CPPUNIT_TEST_SUITE_REGISTRATION( BuffersTest ); - -using namespace RTT; - -struct Dummy { - Dummy(double a = 0.0, double b =1.0, double c=2.0) - :d1(a), d2(b), d3(c) {} - double d1; - double d2; - double d3; - bool operator==(const Dummy& d) const - { - 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; - } - -// volatile Dummy& operator=(const Dummy& d) volatile -// { -// d1 = d.d1; -// d2 = d.d2; -// d3 = d.d3; -// return *this; -// } - -}; - - std::ostream& operator<<( std::ostream& os, const Dummy& d ) { - os << "(" << d.d1 <<","<(QS); - - lockfree = new BufferLockFree(QS); - - dataobj = new DataObjectLockFree("name"); - - //mslist = new SortedList(); - - listlockfree = new ListLockFree(10, 4); - - mpool = new MemoryPool(QS); - vpool = new MemoryPool >(QS, std::vector(QS) ); - - fmpool = new FixedSizeMemoryPool(QS); - fvpool = new FixedSizeMemoryPool >(QS, std::vector(QS)); -} - - -void -BuffersTest::tearDown() -{ - aqueue->clear(); - delete aqueue; - - delete lockfree; - - delete dataobj; - - //delete mslist; - - delete listlockfree; - - delete mpool; - delete vpool; - delete fmpool; - delete fvpool; -} - -void BuffersTest::testAtomic() -{ - /** - * Single Threaded test for AtomicQueue. - */ - - Dummy* d = new Dummy; - Dummy* c = d; - - CPPUNIT_ASSERT_EQUAL( AtomicQueue::size_type(QS), aqueue->capacity() ); - CPPUNIT_ASSERT_EQUAL( AtomicQueue::size_type(0), aqueue->size() ); - CPPUNIT_ASSERT( aqueue->isFull() == false ); - CPPUNIT_ASSERT( aqueue->isEmpty() == true ); - CPPUNIT_ASSERT( aqueue->dequeue(c) == false ); - CPPUNIT_ASSERT( c == d ); - - for ( int i = 0; i < QS; ++i) { - CPPUNIT_ASSERT( aqueue->enqueue( d ) == true); - CPPUNIT_ASSERT_EQUAL( AtomicQueue::size_type(i+1), aqueue->size() ); - } - CPPUNIT_ASSERT_EQUAL( AtomicQueue::size_type(QS), aqueue->capacity() ); - CPPUNIT_ASSERT( aqueue->isFull() == true ); - CPPUNIT_ASSERT( aqueue->isEmpty() == false ); - CPPUNIT_ASSERT( aqueue->enqueue( d ) == false ); - CPPUNIT_ASSERT_EQUAL( AtomicQueue::size_type(QS), aqueue->size() ); - - aqueue->dequeue( d ); - CPPUNIT_ASSERT( aqueue->isFull() == false ); - CPPUNIT_ASSERT_EQUAL( AtomicQueue::size_type(QS-1), aqueue->size() ); - - for ( int i = 0; i < QS - 1 ; ++i) { - CPPUNIT_ASSERT( aqueue->dequeue( d ) == true); - CPPUNIT_ASSERT_EQUAL( AtomicQueue::size_type(QS - 2 - i), aqueue->size() ); - } - CPPUNIT_ASSERT( aqueue->isFull() == false ); - CPPUNIT_ASSERT( aqueue->isEmpty() == true ); - - delete d; -} -void BuffersTest::testAtomicCounted() -{ - /** - * Single Threaded test for AtomicQueue. - */ - - Dummy* d = new Dummy; - Dummy* e = new Dummy; - Dummy* c = d; - - CPPUNIT_ASSERT( aqueue->dequeueCounted(c) == 0 ); - CPPUNIT_ASSERT( c == d ); - - // monotonic increasing counts - int cache = 1; - for ( int i = 0; i < QS; ++i) - CPPUNIT_ASSERT( aqueue->enqueueCounted( d ) == cache++ ); - CPPUNIT_ASSERT( aqueue->isFull() == true ); - CPPUNIT_ASSERT( aqueue->isEmpty() == false ); - CPPUNIT_ASSERT( aqueue->enqueueCounted( d ) == 0 ); - - CPPUNIT_ASSERT( aqueue->dequeueCounted( d ) == 1 ); - CPPUNIT_ASSERT( aqueue->isFull() == false ); - - cache = 2; - for ( int i = 0; i < QS - 1 ; ++i) - CPPUNIT_ASSERT( aqueue->dequeueCounted( d ) == cache++ ); - 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; -} - -void BuffersTest::testBufLockFree() -{ - /** - * Single Threaded test for BufferLockFree. - * This is a mixed white/black box test. - */ - - Dummy* d = new Dummy; - Dummy* c = new Dummy(2.0, 1.0, 0.0); - Dummy r; - - CPPUNIT_ASSERT( lockfree->read(r) == false ); - CPPUNIT_ASSERT( lockfree->front() == r ); // return default if empty. - - CPPUNIT_ASSERT( lockfree->write( *d ) ); - CPPUNIT_ASSERT( lockfree->front() == *d ); - CPPUNIT_ASSERT( lockfree->read(r) ); - CPPUNIT_ASSERT( r == *d ); - - CPPUNIT_ASSERT( lockfree->write( *c ) ); - CPPUNIT_ASSERT( lockfree->front() == *c ); - CPPUNIT_ASSERT( lockfree->read(r) ); - CPPUNIT_ASSERT( r == *c ); - - CPPUNIT_ASSERT( lockfree->write( *d ) ); - CPPUNIT_ASSERT( lockfree->front() == *d ); - CPPUNIT_ASSERT( lockfree->write( *c ) ); - CPPUNIT_ASSERT( lockfree->front() == *d ); - CPPUNIT_ASSERT( lockfree->write( *d ) ); - CPPUNIT_ASSERT( lockfree->front() == *d ); - CPPUNIT_ASSERT( lockfree->write( *c ) ); - CPPUNIT_ASSERT( lockfree->front() == *d ); - CPPUNIT_ASSERT( lockfree->write( *d ) ); - CPPUNIT_ASSERT( lockfree->front() == *d ); - CPPUNIT_ASSERT( lockfree->write( *c ) ); - CPPUNIT_ASSERT( lockfree->front() == *d ); - CPPUNIT_ASSERT( lockfree->write( *d ) ); - CPPUNIT_ASSERT( lockfree->front() == *d ); - CPPUNIT_ASSERT( lockfree->write( *c ) ); - CPPUNIT_ASSERT( lockfree->front() == *d ); - CPPUNIT_ASSERT( lockfree->write( *d ) ); - CPPUNIT_ASSERT( lockfree->front() == *d ); - CPPUNIT_ASSERT( lockfree->write( *c ) ); - CPPUNIT_ASSERT( lockfree->front() == *d ); - CPPUNIT_ASSERT( lockfree->write( *c ) == false ); - CPPUNIT_ASSERT( lockfree->front() == *d ); - CPPUNIT_ASSERT( lockfree->write( *c ) == false ); - CPPUNIT_ASSERT( lockfree->write( *c ) == false ); - CPPUNIT_ASSERT( lockfree->write( *c ) == false ); - CPPUNIT_ASSERT( lockfree->write( *c ) == false ); - CPPUNIT_ASSERT( lockfree->write( *c ) == false ); - CPPUNIT_ASSERT( lockfree->write( *c ) == false ); - CPPUNIT_ASSERT( lockfree->write( *c ) == false ); - CPPUNIT_ASSERT( lockfree->write( *c ) == false ); - CPPUNIT_ASSERT( lockfree->write( *c ) == false ); - CPPUNIT_ASSERT( lockfree->write( *c ) == false ); - CPPUNIT_ASSERT( lockfree->write( *c ) == false ); - CPPUNIT_ASSERT( lockfree->read(r) ); - CPPUNIT_ASSERT( r == *d ); - CPPUNIT_ASSERT( lockfree->front() == *c ); - CPPUNIT_ASSERT( lockfree->read(r) ); - CPPUNIT_ASSERT( r == *c ); - CPPUNIT_ASSERT( lockfree->front() == *d ); - CPPUNIT_ASSERT( lockfree->read(r) ); - CPPUNIT_ASSERT( r == *d ); - CPPUNIT_ASSERT( lockfree->front() == *c ); - CPPUNIT_ASSERT( lockfree->read(r) ); - CPPUNIT_ASSERT( r == *c ); - CPPUNIT_ASSERT( lockfree->front() == *d ); - CPPUNIT_ASSERT( lockfree->read(r) ); - CPPUNIT_ASSERT( r == *d ); - CPPUNIT_ASSERT( lockfree->front() == *c ); - - // start writing again half-way - CPPUNIT_ASSERT( lockfree->write( *d ) ); - CPPUNIT_ASSERT( lockfree->front() == *c ); - CPPUNIT_ASSERT( lockfree->write( *c ) ); - CPPUNIT_ASSERT( lockfree->front() == *c ); - CPPUNIT_ASSERT( lockfree->write( *d ) ); - CPPUNIT_ASSERT( lockfree->front() == *c ); - CPPUNIT_ASSERT( lockfree->write( *c ) ); - CPPUNIT_ASSERT( lockfree->front() == *c ); - CPPUNIT_ASSERT( lockfree->write( *d ) ); - CPPUNIT_ASSERT( lockfree->front() == *c ); - - CPPUNIT_ASSERT( lockfree->read(r) ); - CPPUNIT_ASSERT( r == *c ); - CPPUNIT_ASSERT( lockfree->front() == *d ); - CPPUNIT_ASSERT( lockfree->read(r) ); - CPPUNIT_ASSERT( r == *d ); - CPPUNIT_ASSERT( lockfree->front() == *c ); - CPPUNIT_ASSERT( lockfree->read(r) ); - CPPUNIT_ASSERT( r == *c ); - CPPUNIT_ASSERT( lockfree->front() == *d ); - CPPUNIT_ASSERT( lockfree->read(r) ); - CPPUNIT_ASSERT( r == *d ); - CPPUNIT_ASSERT( lockfree->front() == *c ); - CPPUNIT_ASSERT( lockfree->read(r) ); - CPPUNIT_ASSERT( r == *c ); - CPPUNIT_ASSERT( lockfree->front() == *d ); - CPPUNIT_ASSERT( lockfree->read(r) ); - CPPUNIT_ASSERT( r == *d ); - CPPUNIT_ASSERT( lockfree->front() == *c ); - CPPUNIT_ASSERT( lockfree->read(r) ); - CPPUNIT_ASSERT( r == *c ); - CPPUNIT_ASSERT( lockfree->front() == *d ); - CPPUNIT_ASSERT( lockfree->read(r) ); - CPPUNIT_ASSERT( r == *d ); - CPPUNIT_ASSERT( lockfree->front() == *c ); - CPPUNIT_ASSERT( lockfree->read(r) ); - CPPUNIT_ASSERT( r == *c ); - CPPUNIT_ASSERT( lockfree->front() == *d ); - CPPUNIT_ASSERT( lockfree->read(r) ); - CPPUNIT_ASSERT( r == *d ); - - CPPUNIT_ASSERT( lockfree->front() == *d ); - CPPUNIT_ASSERT( lockfree->read(r) == false ); - CPPUNIT_ASSERT( lockfree->read(r) == false ); - CPPUNIT_ASSERT( lockfree->read(r) == false ); - CPPUNIT_ASSERT( lockfree->read(r) == false ); - CPPUNIT_ASSERT( lockfree->read(r) == false ); - CPPUNIT_ASSERT( lockfree->read(r) == false ); - CPPUNIT_ASSERT( lockfree->read(r) == false ); - CPPUNIT_ASSERT( lockfree->read(r) == false ); - CPPUNIT_ASSERT( lockfree->read(r) == false ); - CPPUNIT_ASSERT( lockfree->read(r) == false ); - CPPUNIT_ASSERT( lockfree->read(r) == false ); - - CPPUNIT_ASSERT( lockfree->write( *c ) ); - CPPUNIT_ASSERT( lockfree->front() == *c ); - CPPUNIT_ASSERT( lockfree->write( *d ) ); - CPPUNIT_ASSERT( lockfree->write( *c ) ); - CPPUNIT_ASSERT( lockfree->write( *d ) ); - CPPUNIT_ASSERT( lockfree->write( *c ) ); - - std::vector v; - CPPUNIT_ASSERT( 5 == lockfree->read(v) ); - CPPUNIT_ASSERT( v[0] == *c ); - CPPUNIT_ASSERT( v[1] == *d ); - CPPUNIT_ASSERT( v[2] == *c ); - CPPUNIT_ASSERT( v[3] == *d ); - CPPUNIT_ASSERT( v[4] == *c ); - CPPUNIT_ASSERT( lockfree->front() == *d ); - - BufferBase::size_type sz = 10; - CPPUNIT_ASSERT( lockfree->write( *c ) ); - CPPUNIT_ASSERT( lockfree->write( *d ) ); - CPPUNIT_ASSERT( lockfree->write( v ) == (int)v.size() ); - CPPUNIT_ASSERT( lockfree->write( *c ) ); - CPPUNIT_ASSERT( lockfree->write( *d ) ); - CPPUNIT_ASSERT( lockfree->write( v ) == 1 ); - CPPUNIT_ASSERT( lockfree->write( v ) == 0 ); - CPPUNIT_ASSERT( lockfree->write( v ) == 0 ); - CPPUNIT_ASSERT( lockfree->write( v ) == 0 ); - CPPUNIT_ASSERT( lockfree->write( v ) == 0 ); - CPPUNIT_ASSERT( lockfree->write( v ) == 0 ); - CPPUNIT_ASSERT( lockfree->write( v ) == 0 ); - CPPUNIT_ASSERT( lockfree->write( v ) == 0 ); - CPPUNIT_ASSERT( lockfree->write( v ) == 0 ); - CPPUNIT_ASSERT( lockfree->write( v ) == 0 ); - CPPUNIT_ASSERT( lockfree->write( v ) == 0 ); - CPPUNIT_ASSERT( lockfree->write( v ) == 0 ); - CPPUNIT_ASSERT( lockfree->write( v ) == 0 ); - CPPUNIT_ASSERT_EQUAL( sz, lockfree->read(v) ); - CPPUNIT_ASSERT( v[0] == *c ); - CPPUNIT_ASSERT( v[1] == *d ); - CPPUNIT_ASSERT( v[2] == *c ); - CPPUNIT_ASSERT( v[3] == *d ); - CPPUNIT_ASSERT( v[4] == *c ); - CPPUNIT_ASSERT( v[5] == *d ); - CPPUNIT_ASSERT( v[6] == *c ); - CPPUNIT_ASSERT( v[7] == *c ); - CPPUNIT_ASSERT( v[8] == *d ); - CPPUNIT_ASSERT( v[9] == *c ); - CPPUNIT_ASSERT( 0 == lockfree->read(v) ); - delete d; - delete c; -} - -void BuffersTest::testDObjLockFree() -{ - Dummy* c = new Dummy(2.0, 1.0, 0.0); - Dummy d; - dataobj->Set( *c ); - CPPUNIT_ASSERT_EQUAL( *c, dataobj->Get() ); - int i = 0; - while ( i != 3.5*DataObjectLockFree::MAX_THREADS ) { - dataobj->Set( *c ); - dataobj->Set( d ); - ++i; - } - CPPUNIT_ASSERT_EQUAL( d , dataobj->Get() ); - CPPUNIT_ASSERT_EQUAL( d , dataobj->Get() ); - - delete c; -} - -void BuffersTest::testMemoryPool() -{ - // Test initial conditions. - MemoryPool::size_type sz = QS; - // for MemoryPool - CPPUNIT_ASSERT_EQUAL( sz, mpool->size() ); - CPPUNIT_ASSERT_EQUAL( sz, vpool->size() ); - // for FixedSizeMemoryPool - CPPUNIT_ASSERT_EQUAL( sz, fmpool->size() ); - CPPUNIT_ASSERT_EQUAL( sz, fvpool->size() ); - // Capacity test - CPPUNIT_ASSERT_EQUAL( sz, mpool->capacity() ); - CPPUNIT_ASSERT_EQUAL( sz, vpool->capacity() ); - CPPUNIT_ASSERT_EQUAL( sz, fmpool->capacity() ); - CPPUNIT_ASSERT_EQUAL( sz, fvpool->capacity() ); - - // test default initialiser: - for (MemoryPool::size_type i = 0; i <3*sz; ++i ) { - // MemoryPool: - std::vector* v = vpool->allocate(); - std::vector::size_type szv = QS; - CPPUNIT_ASSERT_EQUAL( szv, v->size() ); - CPPUNIT_ASSERT_EQUAL( szv, v->capacity() ); - CPPUNIT_ASSERT(vpool->deallocate( v )); - - // FixedSizeMemoryPool: - v = fvpool->allocate(); - CPPUNIT_ASSERT_EQUAL( szv, v->size() ); - CPPUNIT_ASSERT_EQUAL( szv, v->capacity() ); - CPPUNIT_ASSERT( fvpool->deallocate( v ) ); - } - - // test Allocation. - std::vector mpv; - // MemoryPool: - for (MemoryPool::size_type i = 0; i allocate() ); - CPPUNIT_ASSERT_EQUAL( sz - i -1 , mpool->size()); - CPPUNIT_ASSERT_EQUAL( sz, mpool->capacity() ); - } - for (MemoryPool::size_type i = 0; i deallocate( mpv.front() )); - mpv.erase( mpv.begin() ); - CPPUNIT_ASSERT_EQUAL( i + 1 , mpool->size()); - CPPUNIT_ASSERT_EQUAL( sz, mpool->capacity() ); - } - CPPUNIT_ASSERT( mpv.size() == 0 ); - // FixedSizeMemoryPool: - for (MemoryPool::size_type i = 0; i allocate() ); - CPPUNIT_ASSERT_EQUAL( sz - i -1 , fmpool->size()); - CPPUNIT_ASSERT_EQUAL( sz, fmpool->capacity() ); - } - for (MemoryPool::size_type i = 0; i deallocate( mpv.front() ) ); - mpv.erase( mpv.begin() ); - CPPUNIT_ASSERT_EQUAL( i + 1 , fmpool->size()); - CPPUNIT_ASSERT_EQUAL( sz, fmpool->capacity() ); - } - - // test capacity increasing: - for (MemoryPool::size_type i = 0; i reserve(); - vpool->reserve(); - } - CPPUNIT_ASSERT_EQUAL( sz, mpool->capacity() ); - CPPUNIT_ASSERT_EQUAL( sz, mpool->size() ); - CPPUNIT_ASSERT_EQUAL( sz, vpool->capacity() ); - CPPUNIT_ASSERT_EQUAL( sz, vpool->size() ); - - // the following reserve() allocates new chunks. - mpool->reserve(); - vpool->reserve(); - CPPUNIT_ASSERT_EQUAL( sz + 2*sz, mpool->capacity() ); - CPPUNIT_ASSERT_EQUAL( sz + 2*sz, mpool->size() ); - CPPUNIT_ASSERT_EQUAL( sz + 2*sz, vpool->capacity() ); - CPPUNIT_ASSERT_EQUAL( sz + 2*sz, vpool->size() ); - for (MemoryPool::size_type i = 0; i reserve(); - vpool->reserve(); - } - CPPUNIT_ASSERT_EQUAL( sz + 2*sz, mpool->capacity() ); - CPPUNIT_ASSERT_EQUAL( sz + 2*sz, mpool->size() ); - CPPUNIT_ASSERT_EQUAL( sz + 2*sz, vpool->capacity() ); - CPPUNIT_ASSERT_EQUAL( sz + 2*sz, vpool->size() ); - - // Extra: - // test default initialiser for extra reserved chunks: - std::vector< std::vector* > vv; - for (MemoryPool::size_type i = 0; i < sz+ 2*sz; ++i ) { - // MemoryPool: - std::vector* v = vpool->allocate(); - std::vector::size_type szv = QS; - vv.push_back( v ); - CPPUNIT_ASSERT_EQUAL( szv, v->size() ); - CPPUNIT_ASSERT_EQUAL( szv, v->capacity() ); - } - CPPUNIT_ASSERT_EQUAL( MemoryPool::size_type(0), vpool->size() ); - for (MemoryPool::size_type i = 0; i < sz+ 2*sz; ++i ) { - // MemoryPool: - CPPUNIT_ASSERT( vpool->deallocate( vv.back() ) ); - vv.erase( vv.end() - 1 ); - } - -} - -void addOne(Dummy& d) -{ - ++d.d1; - ++d.d2; - ++d.d3; -} - -void subOne(Dummy& d) -{ - --d.d1; - --d.d2; - --d.d3; -} - -#if 0 -void BuffersTest::testSortedList() -{ - // 7 elements. - mslist->reserve(7); - CPPUNIT_ASSERT( mslist->empty() ); - - // empty list has no keys. - CPPUNIT_ASSERT( mslist->hasKey(Dummy()) == false ); - - // empty list fails to erase key. - CPPUNIT_ASSERT( mslist->erase(Dummy()) == false ); - - // insert element once - CPPUNIT_ASSERT( mslist->insert(Dummy(1,2,1)) == true ); - CPPUNIT_ASSERT( mslist->hasKey(Dummy(1,2,1)) == true ); - - CPPUNIT_ASSERT( mslist->insert(Dummy(1,2,1)) == false ); - CPPUNIT_ASSERT( mslist->hasKey(Dummy(1,2,1)) == true ); - - // erase element once - CPPUNIT_ASSERT( mslist->erase(Dummy(1,2,1)) == true ); - CPPUNIT_ASSERT( mslist->hasKey(Dummy(1,2,1)) == false ); - CPPUNIT_ASSERT( mslist->erase(Dummy(1,2,1)) == false ); - CPPUNIT_ASSERT( mslist->hasKey(Dummy(1,2,1)) == false ); - - CPPUNIT_ASSERT( mslist->insert(Dummy(1,2,1)) == true ); - CPPUNIT_ASSERT( mslist->insert(Dummy(1,2,2)) == true ); - CPPUNIT_ASSERT( mslist->insert(Dummy(1,2,3)) == true ); - CPPUNIT_ASSERT( mslist->insert(Dummy(1,2,4)) == true ); - CPPUNIT_ASSERT( mslist->insert(Dummy(1,2,5)) == true ); - CPPUNIT_ASSERT( mslist->insert(Dummy(1,2,6)) == true ); - CPPUNIT_ASSERT( mslist->insert(Dummy(1,2,7)) == true ); - - CPPUNIT_ASSERT( mslist->hasKey(Dummy(1,2,4)) == true ); - CPPUNIT_ASSERT( mslist->hasKey(Dummy(1,2,7)) == true ); - - CPPUNIT_ASSERT( mslist->erase(Dummy(1,2,7)) == true ); - CPPUNIT_ASSERT( mslist->hasKey(Dummy(1,2,7)) == false ); - - CPPUNIT_ASSERT( mslist->erase(Dummy(1,2,4)) == true ); - CPPUNIT_ASSERT( mslist->hasKey(Dummy(1,2,4)) == false ); - - 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->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 ); - CPPUNIT_ASSERT( mslist->hasKey(Dummy(1,2,5)) == true ); - CPPUNIT_ASSERT( mslist->hasKey(Dummy(1,2,6)) == true ); - - CPPUNIT_ASSERT( mslist->erase(Dummy(1,2,1)) == true ); - CPPUNIT_ASSERT( mslist->erase(Dummy(1,2,6)) == true ); - CPPUNIT_ASSERT( mslist->erase(Dummy(1,2,5)) == true ); - CPPUNIT_ASSERT( mslist->erase(Dummy(1,2,2)) == true ); - CPPUNIT_ASSERT( mslist->erase(Dummy(1,2,3)) == true ); - - CPPUNIT_ASSERT( mslist->empty() ); -} -#endif - -struct LLFWorker : public RTT::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(20,"ThreadA", aworker )); - boost::scoped_ptr bthread( new SingleThread(20,"ThreadB", bworker )); - boost::scoped_ptr cthread( new SingleThread(20,"ThreadC", cworker )); - boost::scoped_ptr gthread( new SingleThread(20,"ThreadG", grower )); - - // avoid system lock-ups - athread->setScheduler(ORO_SCHED_OTHER); - bthread->setScheduler(ORO_SCHED_OTHER); - cthread->setScheduler(ORO_SCHED_OTHER); - gthread->setScheduler(ORO_SCHED_OTHER); - - athread->start(); - bthread->start(); - cthread->start(); - - sleep(1); - gthread->start(); - sleep(1); - gthread->stop(); - sleep(1); - - athread->stop(); - bthread->stop(); - cthread->stop(); - } - -#if 0 - cout << "Athread appends: " << aworker->appends<erases<appends<erases<appends<erases<capacity()<size()<empty() == false ) { -// Dummy d = listlockfree->back(); -// //cout << "Left: "<< d <erase( d ) ); -// } -#endif - - 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; -} - -struct AQWorker : public RTT::OS::RunnableInterface -{ - bool stop; - typedef QueueType T; - T* mlst; - int appends; - int erases; - AQWorker(T* l ) : stop(false), mlst(l),appends(0), erases(0) {} - bool initialize() { - stop = false; - appends = 0; erases = 0; - return true; - } - void step() { - Dummy* orig = new Dummy( 1,2,3); - Dummy* d = orig; - while (stop == false ) { - //cout << "Appending, i="<enqueue( d ) ) { ++appends; } - //cout << "Erasing, i="<dequeue( d ) ) { ++erases; } - } - delete orig; - //cout << "Stopping, i="<enqueue(d) ) - ++i; - } - delete orig; - } - - void finalize() {} - - bool breakLoop() { - stop = true; - return true; - } -}; - - -void BuffersTest::testAtomicQueue() -{ - QueueType* qt = new QueueType(QS); - AQWorker* aworker = new AQWorker( qt ); - AQWorker* bworker = new AQWorker( qt ); - AQWorker* cworker = new AQWorker( qt ); - AQGrower* grower = new AQGrower( qt ); - - { - boost::scoped_ptr athread( new SingleThread(20,"ThreadA", aworker )); - boost::scoped_ptr bthread( new SingleThread(20,"ThreadB", bworker )); - boost::scoped_ptr cthread( new SingleThread(20,"ThreadC", cworker )); - boost::scoped_ptr gthread( new SingleThread(20,"ThreadG", grower )); - - // avoid system lock-ups - athread->setScheduler(ORO_SCHED_OTHER); - bthread->setScheduler(ORO_SCHED_OTHER); - cthread->setScheduler(ORO_SCHED_OTHER); - gthread->setScheduler(ORO_SCHED_OTHER); - - athread->start(); - bthread->start(); - cthread->start(); - gthread->start(); - sleep(10); - gthread->stop(); - athread->stop(); - bthread->stop(); - cthread->stop(); - } - - //cout <appends + bworker->appends + cworker->appends+ grower->i<erases + bworker->erases+ cworker->erases + qt->size()<size() != 0 ) { - CPPUNIT_ASSERT( qt->dequeue(d) == true); - CPPUNIT_ASSERT( d ); - i++; - } - CPPUNIT_ASSERT( qt->dequeue(d) == false ); - //cout << "Left in Queue: "<< i <appends + bworker->appends + cworker->appends + grower->i - == aworker->erases + bworker->erases + cworker->erases + i ); - - delete aworker; - delete bworker; - delete cworker; - delete grower; -} diff --git a/tests/buffers_test.hpp b/tests/buffers_test.hpp deleted file mode 100644 index 41777e14d..000000000 --- a/tests/buffers_test.hpp +++ /dev/null @@ -1,90 +0,0 @@ -/*************************************************************************** - tag: Peter Soetens Mon Jan 10 15:59:18 CET 2005 buffers_test.hpp - - buffers_test.hpp - description - ------------------- - begin : Mon January 10 2005 - copyright : (C) 2005 Peter Soetens - email : peter.soetens@mech.kuleuven.ac.be - - *************************************************************************** - * * - * This program is free software; you can redistribute it and/or modify * - * it under the terms of the GNU General Public License as published by * - * the Free Software Foundation; either version 2 of the License, or * - * (at your option) any later version. * - * * - ***************************************************************************/ - - -#ifndef BUFFERSTEST_H -#define BUFFERSTEST_H - -#include - -#include -#include -#include -#include -#include -#include -//#include - -#include -#include - -using namespace RTT; -using namespace RTT::OS; - -class Dummy; - -typedef AtomicQueue QueueType; - -class BuffersTest : public CppUnit::TestFixture -{ - CPPUNIT_TEST_SUITE( BuffersTest ); - CPPUNIT_TEST( testAtomic ); - CPPUNIT_TEST( testAtomicCounted ); -#ifdef OROPKG_OS_GNULINUX - // this test assumes a not real-time OS. - //CPPUNIT_TEST( testListLockFree ); - CPPUNIT_TEST( testAtomicQueue ); -#endif - CPPUNIT_TEST( testBufLockFree ); - CPPUNIT_TEST( testDObjLockFree ); - //CPPUNIT_TEST( testSortedList ); - CPPUNIT_TEST( testMemoryPool ); - CPPUNIT_TEST_SUITE_END(); - - AtomicQueue* aqueue; - - BufferLockFree* lockfree; - DataObjectLockFree* dataobj; - //SortedList* mslist; - - ThreadInterface* athread; - ThreadInterface* bthread; - - ListLockFree* listlockfree; - MemoryPool* mpool; - MemoryPool >* vpool; - FixedSizeMemoryPool* fmpool; - FixedSizeMemoryPool >* fvpool; -public: - - void setUp(); - void tearDown(); - - void testAtomic(); - void testAtomicCounted(); - void testAtomicQueue(); - void testBufLockFree(); - void testDObjLockFree(); - void testMemoryPool(); - - void testSortedList(); - - void testListLockFree(); -}; - -#endif diff --git a/tests/corba_test.cpp b/tests/corba_test.cpp deleted file mode 100644 index d93675e6a..000000000 --- a/tests/corba_test.cpp +++ /dev/null @@ -1,555 +0,0 @@ -/*************************************************************************** - tag: Peter Soetens Mon Jun 26 13:26:02 CEST 2006 generictask_test.cpp - - generictask_test.cpp - description - ------------------- - begin : Mon June 26 2006 - copyright : (C) 2006 Peter Soetens - email : peter.soetens@fmtc.be - - *************************************************************************** - * * - * This program is free software; you can redistribute it and/or modify * - * it under the terms of the GNU General Public License as published by * - * the Free Software Foundation; either version 2 of the License, or * - * (at your option) any later version. * - * * - ***************************************************************************/ - - - -#include "corba_test.hpp" -#include -#include - -#include -#include - -using namespace std; -using Corba::ControlTaskProxy; - -// Registers the fixture into the 'registry' -CPPUNIT_TEST_SUITE_REGISTRATION( CorbaTest ); - -void -CorbaTest::setUp() -{ - // connect DataPorts - md1 = new DataPort("md", 1.0); - md1bis = new DataPort("mdbis", 2.0); // a free port. - md2 = new DataPort("md", -1.0); - // connect Write to Read ports (connection direction testing) - mdr1 = new ReadDataPort("mdrwA"); - mdr2 = new ReadDataPort("mdrwB"); - mdw1 = new WriteDataPort("mdrwB", 1.0); - mdw2 = new WriteDataPort("mdrwA", -1.0); - - // connect BufferPorts - mb1 = new BufferPort("mb", 10, 1.0); - mb2 = new BufferPort("mb", 20, -1.0); - - tc = new TaskContext( "root" ); - tc->addObject( this->createMethodFactory() ); - t2 = new TaskContext("other"); - - tc->ports()->addPort( md1 ); - tc->ports()->addPort( md1bis ); - t2->ports()->addPort( md2 ); - tc->ports()->addPort( mdr1 ); - t2->ports()->addPort( mdr2 ); - tc->ports()->addPort( mdw1 ); - t2->ports()->addPort( mdw2 ); - tc->ports()->addPort( mb1 ); - t2->ports()->addPort( mb2 ); -} - - -void -CorbaTest::tearDown() -{ - //delete tc; - //delete ts; - //delete tp; - -} - -bool CorbaTest::assertBool( bool b) { - return b; -} - - -void CorbaTest::setupCorba() -{ - Corba::ControlTaskProxy::InitOrb(0,0); -} - -void CorbaTest::cleanupCorba() -{ - Corba::ControlTaskProxy::DestroyOrb(); -} - - -TaskObject* CorbaTest::createMethodFactory() -{ - TaskObject* to = new TaskObject("methods"); - - to->methods()->addMethod( method("assert", &CorbaTest::assertBool, this), "assert","b","bd"); - - to->methods()->addMethod( method("vm0", &CorbaTest::vm0, this), "VM0"); - to->methods()->addMethod( method("m0", &CorbaTest::m0, this), "M0"); - to->methods()->addMethod( method("m1", &CorbaTest::m1, this), "M1","a","ad"); - to->methods()->addMethod( method("m2", &CorbaTest::m2, this), "M2","a","ad","a","ad"); - to->methods()->addMethod( method("m3", &CorbaTest::m3, this), "M3","a","ad","a","ad","a","ad"); - to->methods()->addMethod( method("m4", &CorbaTest::m4, this), "M4","a","ad","a","ad","a","ad","a","ad"); - return to; -} - -void CorbaTest::testRemoteMethodC() -{ - - ts = Corba::ControlTaskServer::Create( tc, false ); //no-naming - tp = Corba::ControlTaskProxy::Create( ts->server(), true ); - - // This test tests 'transparant' remote invocation of Orocos MethodC objects. - MethodC mc; - double r = 0.0; - mc = tp->getObject("methods")->methods()->create("vm0"); - CPPUNIT_ASSERT( mc.execute() ); - CPPUNIT_ASSERT( r == 0.0 ); - - mc = tp->getObject("methods")->methods()->create("m0").ret( r ); - CPPUNIT_ASSERT( mc.execute() ); - CPPUNIT_ASSERT( r == -1.0 ); - - mc = tp->getObject("methods")->methods()->create("m2").argC(1).argC(1.0).ret( r ); - CPPUNIT_ASSERT( mc.execute() ); - CPPUNIT_ASSERT( r == -3.0 ); - - mc = tp->getObject("methods")->methods()->create("m3").ret( r ).argC(1).argC(1.0).argC(true); - CPPUNIT_ASSERT( mc.execute() ); - CPPUNIT_ASSERT( r == -4.0 ); - -} - - -void CorbaTest::testRemoteMethod() -{ - - ts = Corba::ControlTaskServer::Create( tc, false ); //no-naming - tp = Corba::ControlTaskProxy::Create( ts->server(), true ); - - // This test tests 'transparant' remote invocation of Orocos methods. - // This requires the RemoteMethod class, which does not work yet. - Method m0 = tp->getObject("methods")->methods()->getMethod("m0"); - Method m1 = tp->getObject("methods")->methods()->getMethod("m1"); - Method m2 = tp->getObject("methods")->methods()->getMethod("m2"); - Method m3 = tp->getObject("methods")->methods()->getMethod("m3"); - Method m4 = tp->getObject("methods")->methods()->getMethod("m4"); - - CPPUNIT_ASSERT_EQUAL( -1.0, m0() ); - CPPUNIT_ASSERT_EQUAL( -2.0, m1(1) ); - CPPUNIT_ASSERT_EQUAL( -3.0, m2(1, 2.0) ); - CPPUNIT_ASSERT_EQUAL( -4.0, m3(1, 2.0, false) ); - CPPUNIT_ASSERT_EQUAL( -5.0, m4(1, 2.0, false,"hello") ); -} - -void CorbaTest::testAnyMethod() -{ - - ts = Corba::ControlTaskServer::Create( tc, false ); //no-naming - tp = Corba::ControlTaskProxy::Create( ts->server() , true); - - // This test tests the createMethodAny() function of the server. - Corba::ControlObject_var co = ts->server()->getObject("methods"); - CPPUNIT_ASSERT( co.in() ); - - Corba::MethodInterface_var methods = co->methods(); - CPPUNIT_ASSERT( methods.in() ); - - Corba::AnyArguments_var any_args = new Corba::AnyArguments(0); - Corba::Method_var vm0 = methods->createMethodAny("vm0", any_args.in()); - CPPUNIT_ASSERT( vm0.in() ); - - CPPUNIT_ASSERT( vm0->executeAny( any_args.in() ) ); - - Corba::Method_var m0 = methods->createMethodAny("m0", any_args.in()); - CPPUNIT_ASSERT( m0.in() ); - - CPPUNIT_ASSERT( m0->executeAny( any_args.in() ) ); - - any_args = new Corba::AnyArguments(1); - any_args->length(1); - unsigned int index = 0; - any_args[index] <<= (CORBA::Long) 1; - Corba::Method_var m1; - CPPUNIT_ASSERT_NO_THROW( m1 = methods->createMethodAny("m1", any_args.in())); - CPPUNIT_ASSERT( m1.in() ); - - CPPUNIT_ASSERT(m1->executeAny( any_args.in() )); - - any_args = new Corba::AnyArguments(2); - any_args->length(2); - index = 0; - any_args[index] <<= (CORBA::Long) 1; - ++index; - any_args[index] <<= (CORBA::Double) 2.0; - Corba::Method_var m2; - CPPUNIT_ASSERT_NO_THROW( m2 = methods->createMethodAny("m2", any_args.in())); - CPPUNIT_ASSERT( m2.in() ); - - CPPUNIT_ASSERT(m2->executeAny( any_args.in() )); - - any_args = new Corba::AnyArguments(3); - any_args->length(3); - index = 0; - any_args[index] <<= (CORBA::Long) 1; - ++index; - any_args[index] <<= (CORBA::Double) 2.0; - ++index; - any_args[index] <<= CORBA::Any::from_boolean( false ); - Corba::Method_var m3; - CPPUNIT_ASSERT_NO_THROW( m3= methods->createMethodAny("m3", any_args.in()) ); - CPPUNIT_ASSERT( m3.in() ); - - CPPUNIT_ASSERT(m3->executeAny( any_args.in() )); - - any_args = new Corba::AnyArguments(4); - any_args->length(4); - index = 0; - any_args[index] <<= (CORBA::Long) 1; - ++index; - any_args[index] <<= (CORBA::Double) 2.0; - ++index; - any_args[index] <<= CORBA::Any::from_boolean( false ); - ++index; - any_args[index] <<= "hello"; - Corba::Method_var m4; - CPPUNIT_ASSERT_NO_THROW ( m4 = methods->createMethodAny("m4", any_args.in()) ); - CPPUNIT_ASSERT( m4.in() ); - - CPPUNIT_ASSERT(m4->executeAny( any_args.in() )); -} - -void CorbaTest::testPorts() -{ - // test create channel functions of dataflowinterface. - // write to corba read from C++ and vice verse. - ts = Corba::ControlTaskServer::Create( tc, false ); //no-naming - tp = Corba::ControlTaskProxy::Create( ts->server(), true ); - - // DATA PORTS - ::RTT::Corba::AssignableExpression_var unknown_data = ts->server()->ports()->createDataChannel("does_not_exist"); - CPPUNIT_ASSERT( CORBA::is_nil(unknown_data) ); - ::RTT::Corba::AssignableExpression_var buffer_as_data = ts->server()->ports()->createDataChannel("mb"); - CPPUNIT_ASSERT( CORBA::is_nil(buffer_as_data) ); - ::RTT::Corba::AssignableExpression_var data = ts->server()->ports()->createDataChannel("md"); - CPPUNIT_ASSERT( data.in() ); - - CORBA::Any_var any = new CORBA::Any(); - double value = 5.0; - // Write from corba, read from C++ - any <<= value; - CPPUNIT_ASSERT( data->set( any.in() ) ); - CPPUNIT_ASSERT_EQUAL( value, md1->Get() ); - - // Write from C++, read from corba - value = -5.0; - md1->Set( value ); - any = data->get(); - any >>= value; - CPPUNIT_ASSERT_EQUAL( -5.0, value ); - - // BUFFER PORTS - ::RTT::Corba::BufferChannel_var unknown_buf = ts->server()->ports()->createBufferChannel("does_not_exist"); - CPPUNIT_ASSERT( CORBA::is_nil(unknown_buf) ); - ::RTT::Corba::BufferChannel_var data_as_buffer = ts->server()->ports()->createBufferChannel("md"); - CPPUNIT_ASSERT( CORBA::is_nil(data_as_buffer) ); - ::RTT::Corba::BufferChannel_var buf = ts->server()->ports()->createBufferChannel("mb"); - CPPUNIT_ASSERT(buf.in()); - CPPUNIT_ASSERT_EQUAL( (int)buf->size(), mb1->size() ); - CPPUNIT_ASSERT_EQUAL( (int)buf->capacity(), mb1->capacity() ); - - any = new CORBA::Any(); - value = 5.0; - // Write from corba, read from C++ - any <<= value; - CPPUNIT_ASSERT( buf->push( any.in() ) ); - CPPUNIT_ASSERT_EQUAL( (int)buf->size(), mb1->size() ); - - CPPUNIT_ASSERT_EQUAL( 5.0, mb1->front() ); - CPPUNIT_ASSERT( mb1->Pop( value ) ); - CPPUNIT_ASSERT_EQUAL( 5.0, value ); - CPPUNIT_ASSERT_EQUAL( (int)buf->size(), mb1->size() ); - - // Write from C++, read from corba - value = -5.0; - mb1->Push( value ); - CPPUNIT_ASSERT_EQUAL( (int)buf->size(), mb1->size() ); - - any = buf->front(); - value = 0.0; - any >>= value; - CPPUNIT_ASSERT_EQUAL( -5.0, value ); - CPPUNIT_ASSERT( buf->pull( any.out() ) ); - value = 0.0; - any >>= value; - CPPUNIT_ASSERT_EQUAL( -5.0, value ); - CPPUNIT_ASSERT_EQUAL( (int)buf->size(), mb1->size() ); - -} - -// Test the IDL connectPorts statement. -void CorbaTest::testConnectPortsIDL() -{ - ts = Corba::ControlTaskServer::Create( tc, false ); //no-naming - tp = Corba::ControlTaskProxy::Create( ts->server(), true ); - ts2 = Corba::ControlTaskServer::Create( t2, false ); //no-naming - tp2 = Corba::ControlTaskProxy::Create( ts2->server(), true ); - - // Default direction is from ts to ts2, but it will also need to - // connect ports from ts2 to ts when ts is reader and ts2 is writer. - CPPUNIT_ASSERT( ts->server()->connectPorts( ts2->server() ) ); - - testPortStats(); - testPortDisconnect(); -} - -void CorbaTest::testConnectPortsLR() -{ - ts = Corba::ControlTaskServer::Create( tc, false ); //no-naming - tp = Corba::ControlTaskProxy::Create( ts->server(), true ); - ts2 = Corba::ControlTaskServer::Create( t2, false ); //no-naming - tp2 = Corba::ControlTaskProxy::Create( ts2->server(), true ); - - CPPUNIT_ASSERT( connectPorts(tc, tp2 ) ); - - testPortStats(); - testPortDisconnect(); - -} -void CorbaTest::testConnectPortsRL() -{ - ts = Corba::ControlTaskServer::Create( tc, false ); //no-naming - tp = Corba::ControlTaskProxy::Create( ts->server(), true ); - ts2 = Corba::ControlTaskServer::Create( t2, false ); //no-naming - tp2 = Corba::ControlTaskProxy::Create( ts2->server(), true ); - - CPPUNIT_ASSERT( connectPorts(tp, t2 ) ); - - testPortStats(); - testPortDisconnect(); - -} - -void CorbaTest::testConnectPortsRR() -{ - ts = Corba::ControlTaskServer::Create( tc, false ); //no-naming - tp = Corba::ControlTaskProxy::Create( ts->server(), true ); - ts2 = Corba::ControlTaskServer::Create( t2, false ); //no-naming - tp2 = Corba::ControlTaskProxy::Create( ts2->server(), true ); - - CPPUNIT_ASSERT( connectPorts(tp, tp2 ) ); - - testPortStats(); - testPortDisconnect(); - -} - -void CorbaTest::testConnectPortsLRC() -{ - ts = Corba::ControlTaskServer::Create( tc, false ); //no-naming - tp = Corba::ControlTaskProxy::Create( ts->server(), true ); - ts2 = Corba::ControlTaskServer::Create( t2, false ); //no-naming - tp2 = Corba::ControlTaskProxy::Create( ts2->server(), true ); - - // test connecting to existing connection: - ConnectionInterface::shared_ptr ci = md1->createConnection(ConnectionTypes::lockfree); - CPPUNIT_ASSERT( md1->connectTo(ci) ); - CPPUNIT_ASSERT( ci->connect() ); - - CPPUNIT_ASSERT( connectPorts(tc, tp2 ) ); - - testPortStats(); - testPortDisconnect(); - -} -void CorbaTest::testConnectPortsRLC() -{ - ts = Corba::ControlTaskServer::Create( tc, false ); //no-naming - tp = Corba::ControlTaskProxy::Create( ts->server(), true ); - ts2 = Corba::ControlTaskServer::Create( t2, false ); //no-naming - tp2 = Corba::ControlTaskProxy::Create( ts2->server(), true ); - - // test connecting to existing connection: - ConnectionInterface::shared_ptr ci = md1->createConnection(ConnectionTypes::lockfree); - CPPUNIT_ASSERT( md1->connectTo(ci) ); - CPPUNIT_ASSERT( ci->connect() ); - - CPPUNIT_ASSERT( connectPorts(tp, t2 ) ); - - testPortStats(); - testPortDisconnect(); - -} - -void CorbaTest::testConnectPortsRRC() -{ - ts = Corba::ControlTaskServer::Create( tc, false ); //no-naming - tp = Corba::ControlTaskProxy::Create( ts->server(), true ); - ts2 = Corba::ControlTaskServer::Create( t2, false ); //no-naming - tp2 = Corba::ControlTaskProxy::Create( ts2->server(), true ); - - // test connecting to existing connection: - ConnectionInterface::shared_ptr ci = md1->createConnection(ConnectionTypes::lockfree); - CPPUNIT_ASSERT( md1->connectTo(ci) ); - CPPUNIT_ASSERT( ci->connect() ); - - CPPUNIT_ASSERT( connectPorts(tp, tp2 ) ); - - testPortStats(); - testPortDisconnect(); - -} - - -void CorbaTest::testPortStats() -{ - // ALWAYS connect from tc/tp TO t2/tp2 - // The test assumes the connection direction is tc->t2. - // Tests if ports are correctly working, this test is called by the other test functions. - // DATA PORTS - // Check if connection succeeded both ways: - CPPUNIT_ASSERT( md1->connected() ); - CPPUNIT_ASSERT( md2->connected() ); - // Check if both ports return same initial value: - CPPUNIT_ASSERT_EQUAL( 1.0, md1->Get() ); - CPPUNIT_ASSERT_EQUAL( 1.0, md2->Get() ); - - // Check writing from both ways: - md1->Set( 3.0 ); - CPPUNIT_ASSERT_EQUAL( 3.0, md1->Get() ); - CPPUNIT_ASSERT_EQUAL( 3.0, md2->Get() ); - md2->Set( -3.0 ); - CPPUNIT_ASSERT_EQUAL( -3.0, md1->Get() ); - CPPUNIT_ASSERT_EQUAL( -3.0, md2->Get() ); - - // READ/WRITE DATA PORTS - // Check if connection succeeded both ways: - CPPUNIT_ASSERT( mdr1->connected() ); - CPPUNIT_ASSERT( mdr2->connected() ); - CPPUNIT_ASSERT( mdw1->connected() ); - CPPUNIT_ASSERT( mdw2->connected() ); - // Check if both ports return same initial value: - CPPUNIT_ASSERT_EQUAL( -1.0, mdr1->Get() ); - //CPPUNIT_ASSERT_EQUAL( 1.0, mdw1->Get() ); - CPPUNIT_ASSERT_EQUAL( 1.0, mdr2->Get() ); - //CPPUNIT_ASSERT_EQUAL( -1.0, mdw2->Get() ); - - // Check writing from both ways: - mdw1->Set( 3.0 ); - //CPPUNIT_ASSERT_EQUAL( 3.0, mdw1->Get() ); - CPPUNIT_ASSERT_EQUAL( 3.0, mdr2->Get() ); - mdw2->Set( -3.0 ); - //CPPUNIT_ASSERT_EQUAL( -3.0, mdw2->Get() ); - CPPUNIT_ASSERT_EQUAL( -3.0, mdr1->Get() ); - - // - // BUFFER PORTS - // Check if connection succeeded both ways: - double val = 0.0; - CPPUNIT_ASSERT( mb1->connected() ); - CPPUNIT_ASSERT( mb2->connected() ); - CPPUNIT_ASSERT_EQUAL( 10, mb2->capacity() ); - CPPUNIT_ASSERT_EQUAL( 0, mb1->size() ); - CPPUNIT_ASSERT_EQUAL( 0, mb2->size() ); - - // Check writing from both ways: - CPPUNIT_ASSERT( mb1->Push( 3.0 ) ); - CPPUNIT_ASSERT( mb1->front() == 3.0 ); - CPPUNIT_ASSERT( mb2->front() == 3.0 ); - CPPUNIT_ASSERT_EQUAL( 1, mb1->size() ); - CPPUNIT_ASSERT_EQUAL( 1, mb2->size() ); - CPPUNIT_ASSERT( mb2->Pop( val )); - CPPUNIT_ASSERT( val == 3.0 ); - CPPUNIT_ASSERT_EQUAL( 0, mb1->size() ); - CPPUNIT_ASSERT_EQUAL( 0, mb2->size() ); - - CPPUNIT_ASSERT( mb2->Push( -3.0 ) ); - CPPUNIT_ASSERT( mb1->front() == -3.0 ); - CPPUNIT_ASSERT( mb2->front() == -3.0 ); - CPPUNIT_ASSERT_EQUAL( 1, mb1->size() ); - CPPUNIT_ASSERT_EQUAL( 1, mb2->size() ); - CPPUNIT_ASSERT( mb2->Pop( val )); - CPPUNIT_ASSERT( val == -3.0 ); - CPPUNIT_ASSERT_EQUAL( 0, mb1->size() ); - CPPUNIT_ASSERT_EQUAL( 0, mb2->size() ); -} - -void CorbaTest::testPortDisconnect() -{ - // Connection management. - // DATA PORTS - CPPUNIT_ASSERT( md1->connected() ); - CPPUNIT_ASSERT( md2->connected() ); - - // store -3.0 in connection. - md1->Set( -3.0 ); - - md1->disconnect(); - md2->disconnect(); - - CPPUNIT_ASSERT( !md1->connected() ); - CPPUNIT_ASSERT( !md2->connected() ); - - // Check no writing from both ways: - md1->Set( 3.0 ); - CPPUNIT_ASSERT_EQUAL( 3.0, md1->Get() ); - CPPUNIT_ASSERT( 3.0 != md2->Get() ); - md2->Set( 6.0 ); - CPPUNIT_ASSERT_EQUAL( 3.0, md1->Get() ); - CPPUNIT_ASSERT_EQUAL( 6.0, md2->Get() ); - - // - // BUFFER PORTS - // Check if connection succeeded both ways: - double val = 0.0; - CPPUNIT_ASSERT( mb1->connected() ); - CPPUNIT_ASSERT( mb2->connected() ); - - // Store a value. - CPPUNIT_ASSERT( mb1->Push( 3.0 ) ); - - // Disconnect - mb1->disconnect(); - mb2->disconnect(); - - // should fail - CPPUNIT_ASSERT( !mb1->Push( 3.0 ) ); - CPPUNIT_ASSERT( !mb2->Pop( val )); - - CPPUNIT_ASSERT( !mb2->Push( -3.0 ) ); - CPPUNIT_ASSERT( !mb2->Pop( val )); -} - -void CorbaTest::testConnections() -{ - // This test tests the differen port-to-port connections. - ts = Corba::ControlTaskServer::Create( tc, false ); //no-naming - tp = Corba::ControlTaskProxy::Create( ts->server(), true ); - ts2 = Corba::ControlTaskServer::Create( t2, false ); //no-naming - tp2 = Corba::ControlTaskProxy::Create( ts2->server(), true ); - - // incompatible type should fail - CPPUNIT_ASSERT( !ts->server()->ports()->connectPorts("md", ts2->server()->ports(), "mb") ); - - CPPUNIT_ASSERT( ts->server()->ports()->connectPorts("md", ts2->server()->ports(), "md") ); - CPPUNIT_ASSERT( ts->server()->ports()->connectPorts("mb", ts2->server()->ports(), "mb") ); - CPPUNIT_ASSERT( ts->server()->ports()->connectPorts("mdrwA", ts2->server()->ports(), "mdrwA") ); - CPPUNIT_ASSERT( ts->server()->ports()->connectPorts("mdrwB", ts2->server()->ports(), "mdrwB") ); - - testPortStats(); - testPortDisconnect(); - - -} - diff --git a/tests/corba_test.hpp b/tests/corba_test.hpp deleted file mode 100644 index 120d4c013..000000000 --- a/tests/corba_test.hpp +++ /dev/null @@ -1,104 +0,0 @@ -#ifndef CORBA_TEST_H -#define CORBA_TEST_H - -#include - -#include -#include -#include -#include -#include -#include - -using namespace RTT; - -class CorbaTest : public CppUnit::TestFixture -{ - CPPUNIT_TEST_SUITE( CorbaTest ); - - CPPUNIT_TEST( setupCorba ); - CPPUNIT_TEST( testRemoteMethodC ); - CPPUNIT_TEST( testRemoteMethod ); - CPPUNIT_TEST( testAnyMethod ); - CPPUNIT_TEST( testPorts ); - CPPUNIT_TEST( testConnectPortsIDL ); - CPPUNIT_TEST( testConnectPortsRL ); - CPPUNIT_TEST( testConnectPortsLR ); - CPPUNIT_TEST( testConnectPortsRR ); - CPPUNIT_TEST( testConnectPortsLRC ); - CPPUNIT_TEST( testConnectPortsRLC ); - CPPUNIT_TEST( testConnectPortsRRC ); - CPPUNIT_TEST( testConnections ); - CPPUNIT_TEST( cleanupCorba ); - - CPPUNIT_TEST_SUITE_END(); - - TaskContext* tc; - TaskContext* t2; - TaskContext* tp; - Corba::ControlTaskServer* ts; - TaskContext* tp2; - Corba::ControlTaskServer* ts2; - TaskObject* createMethodFactory(); - - // Ports - DataPort* md1; - DataPort* md1bis; - DataPort* md2; - ReadDataPort* mdr1; - ReadDataPort* mdr2; - WriteDataPort* mdw1; - WriteDataPort* mdw2; - BufferPort* mb1; - BufferPort* mb2; - - // ref/const-ref tests: - double ret; - double& m0r() { return ret; } - const double& m0cr() { return ret; } - - // test const std::string& argument for command_ds - bool comstr(const std::string& cs) { return !cs.empty(); } - - double m1r(double& a) { a = 2*a; return a; } - double m1cr(const double& a) { return a; } - - // plain argument tests: - double m0() { return -1.0; } - double m1(int i) { return -2.0; } - double m2(int i, double d) { return -3.0; } - double m3(int i, double d, bool c) { return -4.0; } - double m4(int i, double d, bool c, std::string s) { return -5.0; } - - // void(void) function test: - void vm0(void) { ; } - - bool assertBool( bool ); -public: - - void setupCorba(); - void cleanupCorba(); - - void setUp(); - void tearDown(); - - void testRemoteMethodC(); - void testRemoteMethod(); - void testAnyMethod(); - - void testPorts(); - void testConnectPortsIDL(); - void testConnectPortsRL(); - void testConnectPortsLR(); - void testConnectPortsRR(); - void testConnectPortsRLC(); - void testConnectPortsLRC(); - void testConnectPortsRRC(); - void testConnections(); - - // helper test functions - void testPortStats(); - void testPortDisconnect(); -}; - -#endif diff --git a/tests/dev_test.cpp b/tests/dev_test.cpp deleted file mode 100644 index 5ae05bdf0..000000000 --- a/tests/dev_test.cpp +++ /dev/null @@ -1,85 +0,0 @@ -/*************************************************************************** - tag: Peter Soetens Mon Jan 10 15:59:51 CET 2005 dev_test.cpp - - dev_test.cpp - description - ------------------- - begin : Mon January 10 2005 - copyright : (C) 2005 Peter Soetens - email : peter.soetens@mech.kuleuven.ac.be - - *************************************************************************** - * * - * This program is free software; you can redistribute it and/or modify * - * it under the terms of the GNU General Public License as published by * - * the Free Software Foundation; either version 2 of the License, or * - * (at your option) any later version. * - * * - ***************************************************************************/ - - - -#include "dev_test.hpp" -#include "FakeAnalogDevice.hpp" -#include "FakeDigitalDevice.hpp" -#include "dev/AnalogInput.hpp" -#include "dev/AnalogOutput.hpp" -#include "dev/DigitalInput.hpp" -#include "dev/DigitalOutput.hpp" - -#include -#include - -using namespace std; - -// Registers the fixture into the 'registry' -CPPUNIT_TEST_SUITE_REGISTRATION( DevTest ); - -using namespace RTT; - -void -DevTest::setUp() -{ -} - - -void -DevTest::tearDown() -{ -} - -void DevTest::testClasses() -{ - DigitalInput din(true, false); // init, invert - DigitalOutput dout(false); // init. - AnalogInput ain(0,0); - AnalogOutput aout(0,0); - - - CPPUNIT_ASSERT( din.isOn() ); - - CPPUNIT_ASSERT( dout.isOn() == false); - dout.setBit(true); - CPPUNIT_ASSERT( dout.isOn() == true); - dout.setBit(false); - CPPUNIT_ASSERT( dout.isOn() == false); -} - -void DevTest::testNaming() -{ - - FakeAnalogDevice fad; - FakeDigitalDevice fdd; - - AnalogInInterface* aii = AnalogInInterface::nameserver.getObject("FakeAnalogDevice"); - AnalogOutInterface* aoi = AnalogOutInterface::nameserver.getObject("FakeAnalogDevice"); - - DigitalInInterface* dii = DigitalInInterface::nameserver.getObject("FakeDigitalDevice"); - DigitalOutInterface* doi = DigitalOutInterface::nameserver.getObject("FakeDigitalDevice"); - - CPPUNIT_ASSERT( aii ); - CPPUNIT_ASSERT( aoi ); - CPPUNIT_ASSERT( dii ); - CPPUNIT_ASSERT( doi ); - -} - diff --git a/tests/dev_test.hpp b/tests/dev_test.hpp deleted file mode 100644 index ced224907..000000000 --- a/tests/dev_test.hpp +++ /dev/null @@ -1,41 +0,0 @@ -/*************************************************************************** - tag: Peter Soetens Mon Jan 10 15:59:18 CET 2005 logger_test.hpp - - dev_test.hpp - description - ------------------- - begin : Mon January 10 2005 - copyright : (C) 2005 Peter Soetens - email : peter.soetens@mech.kuleuven.ac.be - - *************************************************************************** - * * - * This program is free software; you can redistribute it and/or modify * - * it under the terms of the GNU General Public License as published by * - * the Free Software Foundation; either version 2 of the License, or * - * (at your option) any later version. * - * * - ***************************************************************************/ - - -#ifndef DEVTEST_H -#define DEVTEST_H - -#include - -class DevTest : public CppUnit::TestFixture -{ - CPPUNIT_TEST_SUITE( DevTest ); - CPPUNIT_TEST( testClasses ); - CPPUNIT_TEST( testNaming ); - CPPUNIT_TEST_SUITE_END(); - -public: - - void setUp(); - void tearDown(); - - void testClasses(); - void testNaming(); -}; - -#endif diff --git a/tests/dispatch_test.cpp b/tests/dispatch_test.cpp deleted file mode 100644 index 711ff0c40..000000000 --- a/tests/dispatch_test.cpp +++ /dev/null @@ -1,299 +0,0 @@ -/*************************************************************************** - tag: Peter Soetens Mon Jan 10 15:59:51 CET 2005 dispatch_test.cpp - - dispatch_test.cpp - description - ------------------- - begin : Mon January 10 2005 - copyright : (C) 2005 Peter Soetens - email : peter.soetens@mech.kuleuven.ac.be - - *************************************************************************** - * * - * This program is free software; you can redistribute it and/or modify * - * it under the terms of the GNU General Public License as published by * - * the Free Software Foundation; either version 2 of the License, or * - * (at your option) any later version. * - * * - ***************************************************************************/ - - - -#include "dispatch_test.hpp" -#include -#include -#include -#include -#include -#include -#include - -using namespace std; - -// Registers the fixture into the 'registry' -CPPUNIT_TEST_SUITE_REGISTRATION( DispatchTest ); - -DispatchTest::DispatchTest() - : gtc("root"), - mtc("space"), - ltc("subspace"), - gtask(0.1, gtc.engine() ), - mtask(0.05, mtc.engine()), - ltask(0.01, ltc.engine()) -{} - - -void -DispatchTest::setUp() -{ - ltc.clear(); - mtc.clear(); - gtc.clear(); - // ltc has a test object - ltc.addObject( this->createObject("test", ltc.engine()->commands()) ); - // mtc has two methods. - mtc.addObject( this->createObject("test", mtc.engine()->commands()) ); - - gtc.addPeer( &mtc ); - mtc.connectPeers( <c ); - -} - - -void -DispatchTest::tearDown() -{ - gtc.removePeer( "space" ); - ltc.disconnectPeers( "subspace" ); -} - - -bool DispatchTest::assertBool( bool b) { - return b; -} -bool DispatchTest::assertMsg( bool b, const std::string& msg) { - if ( b == false ) - cout << "Asserted :" << b << " with :" << msg << endl; - return b; -} - - -TaskObject* DispatchTest::createObject(string a, CommandProcessor* cp) -{ - TaskObject* dat = new TaskObject(a); - dat->methods()->addMethod( method( "assert", &DispatchTest::assertBool, this), "Assert", "bool", "" ); - dat->methods()->addMethod( method( "assertMsg", &DispatchTest::assertMsg, this), "Assert message", "bool", "", "text", "text" ); - dat->methods()->addMethod( method( "isTrue", &DispatchTest::assertBool, this), "Identity function", "bool", "" ); - dat->commands()->addCommand( command( "instantDone", &DispatchTest::true_genCom, - &DispatchTest::true_gen, this, cp), - "returns immediately" ); - dat->commands()->addCommand( command( "neverDone", &DispatchTest::true_genCom, - &DispatchTest::false_gen, this, cp), - "returns never" ); - dat->commands()->addCommand( command( "instantNotDone", &DispatchTest::true_genCom, - &DispatchTest::true_gen, this, cp, false), - "returns never"); - dat->commands()->addCommand( command( "instantFail", &DispatchTest::false_genCom, - &DispatchTest::true_gen, this, cp), - "fails immediately" ); - dat->commands()->addCommand( command( "totalFail", &DispatchTest::false_genCom, - &DispatchTest::false_gen, this, cp), - "fails in command and condition" ); - return dat; -} - - -void DispatchTest::testParseDispatch() -{ - // this is a global program requesting a method on a local - // task/processor (ie assert) and a command (instantDone) - string prog = string("program x { do space.subspace.test.assertMsg(true,\"tpdtrue\") \n") - + " if space.subspace.test.assert(true) then \n" - + " do nothing\n" - + " do space.subspace.test.instantDone() \n" -// + " do space.assertMsg(true,\"tpdfail\")\n" -// + " do this.space.assertMsg(true,\"donotreach\")\n" - + "}"; - - this->doDispatch( prog, >c ); - - CPPUNIT_ASSERT( gtc.engine()->programs()->getProgramStatus("x") != ProgramInterface::Status::error ); - CPPUNIT_ASSERT( gtc.engine()->programs()->getProgramStatus("x") != ProgramInterface::Status::running ); - CPPUNIT_ASSERT( gtc.engine()->programs()->getProgramStatus("x") == ProgramInterface::Status::stopped ); - - this->finishDispatch( >c, "x"); -} - -void DispatchTest::testDispatchFailure() -{ - // this is a global program requesting a command on a local - // task/processor (ie instantFail). - string prog = string("program x { do space.subspace.test.instantFail() \n") - + "}"; - - this->doDispatch( prog, >c ); - - CPPUNIT_ASSERT( gtc.engine()->programs()->getProgramStatus("x") == ProgramInterface::Status::error ); - - this->finishDispatch( >c, "x"); -} -void DispatchTest::testDispatchCondition() -{ - // see if checking a remote condition works - // also tests peerparser in expressions - string prog = string("program x { if ( space.subspace.test.assert(true) ) then \n") - + "do space.subspace.test.instantDone() \n" - + "else \n" - + "do space.subspace.test.instantFail() \n" - + "if ( space.subspace.test.assert(false) ) then \n" - + "do space.subspace.test.instantFail() \n" - + "else \n" - + "do space.subspace.test.instantDone() \n" - + " }"; - this->doDispatch( prog, >c ); - - stringstream msg; - msg << "Status was not 'stopped', but "+gtc.engine()->programs()->getProgramStatusStr("x"); - msg << " on line " << gtc.engine()->programs()->getProgram("x")->getLineNumber(); - CPPUNIT_ASSERT_MESSAGE(msg.str(), - gtc.engine()->programs()->getProgramStatus("x") == ProgramInterface::Status::stopped); - - this->finishDispatch( >c, "x"); -} - -void DispatchTest::testDispatchAnd() -{ - // see if checking a remote condition works - string prog = string("program x { do space.subspace.test.assert(true)\n") - + "and space.subspace.test.assert(true) \n" - + "and space.subspace.test.assert(true) \n" - + "do space.subspace.test.instantDone() \n" - + "and space.subspace.test.instantDone() \n" - + "and space.subspace.test.instantDone() \n" - + " }"; - this->doDispatch( prog, >c ); - - stringstream msg; - msg << "Status was not 'stopped', but "+gtc.engine()->programs()->getProgramStatusStr("x"); - msg << " on line " << gtc.engine()->programs()->getProgram("x")->getLineNumber(); - CPPUNIT_ASSERT_MESSAGE(msg.str(), - gtc.engine()->programs()->getProgramStatus("x") == ProgramInterface::Status::stopped); - - this->finishDispatch( >c, "x"); -} - -void DispatchTest::testDispatchTry() -{ - // see if checking a remote condition works - string prog = string("program x { try space.subspace.test.assert(false)\n") - + "try space.subspace.test.assert(true) \n" - + "and space.subspace.test.assert(false) \n" - + "and space.subspace.test.assert(true) \n" - + "try space.subspace.test.instantFail()\n" - + "try space.subspace.test.instantDone() \n" - + "and space.subspace.test.instantFail() \n" - + "and space.subspace.test.instantDone() \n" - + " }"; - this->doDispatch( prog, >c ); - - CPPUNIT_ASSERT( gtc.engine()->programs()->getProgramStatus("x") != ProgramInterface::Status::error ); - stringstream msg; - msg << "Status was not 'stopped', but "+gtc.engine()->programs()->getProgramStatusStr("x"); - msg << " on line " << gtc.engine()->programs()->getProgram("x")->getLineNumber(); - CPPUNIT_ASSERT_MESSAGE(msg.str(), - gtc.engine()->programs()->getProgramStatus("x") == ProgramInterface::Status::stopped); - - this->finishDispatch( >c, "x"); -} - -void DispatchTest::testDispatchUntil() -{ - // see if checking a remote condition works - string prog = string("program x { do space.subspace.test.instantDone()\n") - + "until { \n" - + " if time > 10 ms then continue \n" // test in simulation takes far less than 1 second - + "} \n" - + "do space.subspace.test.instantDone()\n" - + "until { \n" - + " if done then continue \n" - + "} \n" - + " }"; - this->doDispatch( prog, >c ); - - stringstream msg; - msg << "Status was not 'stopped', but "+gtc.engine()->programs()->getProgramStatusStr("x"); - msg << " on line " << gtc.engine()->programs()->getProgram("x")->getLineNumber(); - CPPUNIT_ASSERT_MESSAGE(msg.str(), - gtc.engine()->programs()->getProgramStatus("x") == ProgramInterface::Status::stopped); - - this->finishDispatch( >c, "x"); -} - -void DispatchTest::testDispatchUntilFail() -{ - // see if checking a remote condition works - string prog = string("program x { do space.subspace.test.instantFail()\n") - + "until { \n" - + " if done then continue \n" // program should go into error - + "} \n" - + " }"; - this->doDispatch( prog, >c ); - - CPPUNIT_ASSERT( gtc.engine()->programs()->getProgramStatus("x") == ProgramInterface::Status::error ); - - this->finishDispatch( >c, "x"); -} - -void DispatchTest::testDispatchMany() -{ - // XXX not a valid test. send not present in Orocos, this looks like 'try' - // a program which must not fail, even if the command failes. - string prog = string("program x { ") - +" do space.subspace.test.instantDone()\n" - +" do space.subspace.test.instantDone()\n" - +" do space.subspace.test.instantDone()\n" - +" do space.subspace.test.instantDone()\n" - +" }"; - this->doDispatch( prog, >c ); - - CPPUNIT_ASSERT( gtc.engine()->programs()->getProgramStatus("x") != ProgramInterface::Status::error ); - CPPUNIT_ASSERT( gtc.engine()->programs()->getProgramStatus("x") == ProgramInterface::Status::stopped ); - - this->finishDispatch( >c, "x" ); -} - - -void DispatchTest::doDispatch( const std::string& prog, TaskContext* tc ) -{ - Parser::ParsedPrograms pg_list; - try { - pg_list = parser.parseProgram( prog, tc ); - } - catch( const file_parse_exception& exc ) - { - CPPUNIT_ASSERT_MESSAGE( exc.what(), false ); - } - if ( pg_list.empty() ) - { - CPPUNIT_ASSERT( false ); - } - CPPUNIT_ASSERT( tc->engine()->programs()->loadProgram( *pg_list.begin() ) ); - CPPUNIT_ASSERT(ltask.start()); - CPPUNIT_ASSERT(mtask.start()); - CPPUNIT_ASSERT(gtask.start()); - CPPUNIT_ASSERT( tc->engine()->programs()->getProgram( (*pg_list.begin())->getName() )->start() ); - - SimulationThread::Instance()->run(1000); -} - -void DispatchTest::finishDispatch(TaskContext* tc, std::string prog_name) -{ - CPPUNIT_ASSERT(gtask.stop()); - CPPUNIT_ASSERT(mtask.stop()); - CPPUNIT_ASSERT(ltask.stop()); - tc->engine()->programs()->getProgram( prog_name )->stop(); - CPPUNIT_ASSERT( tc->engine()->programs()->unloadProgram( prog_name ) ); - -} - - - diff --git a/tests/dispatch_test.hpp b/tests/dispatch_test.hpp deleted file mode 100644 index cc9d652e6..000000000 --- a/tests/dispatch_test.hpp +++ /dev/null @@ -1,86 +0,0 @@ -/*************************************************************************** - tag: Peter Soetens Mon Jan 10 15:59:18 CET 2005 dispatch_test.hpp - - dispatch_test.hpp - description - ------------------- - begin : Mon January 10 2005 - copyright : (C) 2005 Peter Soetens - email : peter.soetens@mech.kuleuven.ac.be - - *************************************************************************** - * * - * This program is free software; you can redistribute it and/or modify * - * it under the terms of the GNU General Public License as published by * - * the Free Software Foundation; either version 2 of the License, or * - * (at your option) any later version. * - * * - ***************************************************************************/ - - -#ifndef DISPATCHTEST_H -#define DISPATCHTEST_H - -#include - -#include -#include -#include -#include -#include - -using namespace RTT; -using namespace RTT; - -class DispatchTest : public CppUnit::TestFixture -{ - CPPUNIT_TEST_SUITE( DispatchTest ); - CPPUNIT_TEST( testParseDispatch ); - CPPUNIT_TEST( testDispatchFailure ); - CPPUNIT_TEST( testDispatchCondition ); - CPPUNIT_TEST( testDispatchAnd ); - CPPUNIT_TEST( testDispatchTry ); - CPPUNIT_TEST( testDispatchUntil ); - CPPUNIT_TEST( testDispatchUntilFail ); - CPPUNIT_TEST( testDispatchMany ); - CPPUNIT_TEST_SUITE_END(); - - //CPPUNIT_TEST( testSendDispatch ); - - Parser parser; - TaskContext gtc; - TaskContext mtc; - TaskContext ltc; - SimulationActivity gtask; - SimulationActivity mtask; - SimulationActivity ltask; - TaskObject* createObject(std::string a, CommandProcessor* cp); - - bool true_genCom() { return true; } - bool false_genCom() { return false; } - bool true_gen() const { return true; } - bool false_gen() const { return false; } - - bool bool_gen( bool b ) const { return b; } - - bool assertBool( bool ); - bool assertMsg( bool, const std::string& msg); - void doDispatch( const std::string& prog, TaskContext* ); - void finishDispatch( TaskContext* , std::string ); -public: - DispatchTest(); - - void setUp(); - void tearDown(); - - void testParseDispatch(); - void testDispatchCondition(); - void testDispatchMany(); - void testDispatchFailure(); - void testDispatchAnd(); - void testDispatchTry(); - void testDispatchUntil(); - void testDispatchUntilFail(); - -}; - -#endif diff --git a/tests/event_test.cpp b/tests/event_test.cpp deleted file mode 100644 index 7be4866ce..000000000 --- a/tests/event_test.cpp +++ /dev/null @@ -1,558 +0,0 @@ -/*************************************************************************** - tag: Peter Soetens Mon Jan 10 15:59:51 CET 2005 event_test.cpp - - event_test.cpp - description - ------------------- - begin : Mon January 10 2005 - copyright : (C) 2005 Peter Soetens - email : peter.soetens@mech.kuleuven.ac.be - - *************************************************************************** - * * - * This program is free software; you can redistribute it and/or modify * - * it under the terms of the GNU General Public License as published by * - * the Free Software Foundation; either version 2 of the License, or * - * (at your option) any later version. * - * * - ***************************************************************************/ - - - -#include -#include -#include -#include -#include -#include -#include -#include - -#include "event_test.hpp" -#include -#include - -// Registers the fixture into the 'registry' -CPPUNIT_TEST_SUITE_REGISTRATION( EventTest ); - -using namespace RTT; -using namespace boost; - -void -EventTest::setUp() -{ - t_event = Event("t_event"); - t_event_string = Event("t_event_string"); - t_event_float = Event("t_event_float"); - event_proc = new EventProcessor(); - act.run( event_proc ); - reset(); - // to be sure - CompletionProcessor::Instance()->start(); -} - - -void -EventTest::tearDown() -{ - act.stop(); - delete event_proc; -} - -void EventTest::listener(void) -{ - t_listener_value = true; -} - -void EventTest::listenerString(const std::string& what) -{ - t_listener_what = what; -} - -void EventTest::completer(void) -{ - t_completer_value = true; -} - -int EventTest::float_listener(float a, float b) -{ - Logger::log() << Logger::Debug << "float_listener "<< a<<", "<& e; - Handle h1; - Handle h2; - Runner( Event& e_ ) : e(e_) { - act.run(&ep); - } - - SlaveActivity act; - BlockingEventProcessor ep; - - bool initialize() { - act.start(); - result = false; - // connect sync and async handler with event - // and run async handler in thread of this task. - h1 = e.connect( bind(&Runner::handle,this, _1) ); - h2 = e.connect( bind(&Runner::complete,this,_1), &ep ); - return true; - } - void step() { - e( 123456 ); - ep.loop(); - } - - // blocking implementation - void loop() { - e( 123456 ); - ep.loop(); // wait for our own event. - } - - bool breakLoop() { - return ep.breakLoop(); - } - - void finalize() { - act.stop(); - h1.disconnect(); - h2.disconnect(); - } - - void handle(int i) { - data = i; - } - void complete(int i) { - result = (i == data); - } -}; - -struct SelfRemover : public RunnableInterface -{ - Event& e; - Handle h1, h2; - SelfRemover( Event& e_ ) : e(e_) { - act.run(&ep); - } - - SlaveActivity act; - EventProcessor ep; - - bool initialize() { - act.start(); - // connect sync and async handler with event - // and run async handler in thread of this task. - h1 = e.setup( bind(&SelfRemover::handle,this)); - h2 = e.setup( bind(&SelfRemover::complete,this), &ep ); - return true; - } - void step() { - h1.connect(); - h2.connect(); - e(); - // repeat for complete : - h1.connect(); - h2.connect(); - - ep.step(); - } - - void finalize() { - act.stop(); - } - - void handle(void) { - // do not emit within handle! - // first disconnect self, then reconnect - h1.disconnect(); - h2.disconnect(); - h1.connect(); - h2.connect(); - h1.disconnect(); - h2.disconnect(); - } - void complete(void) { - h1.disconnect(); - h2.disconnect(); - } -}; - -struct CrossRemover : public RunnableInterface -{ - Event& e; - Handle h1,h2; - CrossRemover( Event& e_ ) : e(e_), count(0) { - act.run(&ep); - } - int count; - - SlaveActivity act; - EventProcessor ep; - - bool initialize() { - act.start(); - // connect sync and async handler with event - // and run async handler in thread of this task. - e.connect( bind(&CrossRemover::handle,this)); - e.connect( bind(&CrossRemover::complete,this), &ep ); - h1 = e.connect( bind(&CrossRemover::handle,this)); - h2 = e.connect( bind(&CrossRemover::complete,this), &ep ); - e.connect( bind(&CrossRemover::handle,this)); - e.connect( bind(&CrossRemover::complete,this), &ep ); - return true; - } - void step() { - // for syn : - count = 0; - e(); - h1.disconnect(); // disconnect ! - h2.disconnect(); // disconnect ! - // for asyn : - count = 0; - ep.step(); - } - - void finalize() { - act.stop(); - } - - void handle(void) { - if ( count == 0 ) { - h1.disconnect(); // remove next handler - h2.disconnect(); // remove next handler - } - if ( count == 1 ){ - h1.connect(); // insert again - h2.connect(); // insert again - } - } - void complete(void) { - // these connect/disconnect have no effect on times the complete - // function is called, since it is already queued in the CP. - if ( count == 0 ) { - h1.connect(); // insert a handler - h2.connect(); // insert a handler - } - if ( count == 1 ) {// remove it again - h1.disconnect(); - h2.disconnect(); - } - if ( count == 2 ) { // add it again - h1.connect(); - h2.connect(); - } - } -}; - - -void EventTest::testTask() -{ - Event event("Event"); - Runner runobj(event); - SimulationActivity task(0.01, &runobj); - CPPUNIT_ASSERT( SimulationThread::Instance()->stop() ); - CPPUNIT_ASSERT(task.start()); - CPPUNIT_ASSERT( SimulationThread::Instance()->run(100) ); - CPPUNIT_ASSERT( runobj.result ); -} - -void EventTest::testSelfRemoval() -{ - SelfRemover runobj(t_event); - SimulationActivity task(0.01, &runobj); - CPPUNIT_ASSERT( SimulationThread::Instance()->stop() ); - CPPUNIT_ASSERT( task.start() ); - CPPUNIT_ASSERT( SimulationThread::Instance()->run(100) ); - CPPUNIT_ASSERT( task.stop() ); -} - -void EventTest::testCrossRemoval() -{ - CrossRemover runobj(t_event); - SimulationActivity task(0.01, &runobj); - CPPUNIT_ASSERT( SimulationThread::Instance()->stop() ); - CPPUNIT_ASSERT( task.start() ); - CPPUNIT_ASSERT( SimulationThread::Instance()->run(100) ); - CPPUNIT_ASSERT( task.stop() ); -} - -static OS::AtomicInt testConcurrentEmitHandlerCount; - -void testConcurrentEmitHandler(void) -{ - testConcurrentEmitHandlerCount.inc(); -} - -class EmitAndcount - :public RunnableInterface -{ -public: - EmitAndcount(Event &ev) - : mev(ev), count(0) {} - Event &mev; - int count; - bool initialize() { return true;} - void step() {} - void finalize() {} - bool breakLoop() { return true; } - void loop() - { - mev(); - ++count; - this->getActivity()->trigger(); - } - -}; - -void EventTest::testConcurrentEmit() -{ - testConcurrentEmitHandlerCount.set(0); - Event event("Event"); - CPPUNIT_ASSERT( event.ready() ); - EmitAndcount arunobj(event); - EmitAndcount brunobj(event); - EmitAndcount crunobj(event); - EmitAndcount drunobj(event); - NonPeriodicActivity atask(0, &arunobj); - NonPeriodicActivity btask(0, &brunobj); - NonPeriodicActivity ctask(0, &crunobj); - NonPeriodicActivity dtask(0, &drunobj); - Handle h = event.connect( &testConcurrentEmitHandler ); - CPPUNIT_ASSERT( h.connected() ); - CPPUNIT_ASSERT( atask.start() ); - CPPUNIT_ASSERT( btask.start() ); - CPPUNIT_ASSERT( ctask.start() ); - CPPUNIT_ASSERT( dtask.start() ); - sleep(1); - CPPUNIT_ASSERT( atask.stop() ); - CPPUNIT_ASSERT( btask.stop() ); - CPPUNIT_ASSERT( ctask.stop() ); - CPPUNIT_ASSERT( dtask.stop() ); - // Verify that all emits also caused the handler to be called. - CPPUNIT_ASSERT_EQUAL( arunobj.count + brunobj.count + crunobj.count + drunobj.count, testConcurrentEmitHandlerCount.read() ); -} - -void EventTest::testBlockingTask() -{ - Event event("Event"); - Runner runobj(event); - NonPeriodicActivity task(15, &runobj); - CPPUNIT_ASSERT(task.start()); - sleep(1); - CPPUNIT_ASSERT(task.stop()); - - CPPUNIT_ASSERT( runobj.result ); -} - -void EventTest::testEventArgs() -{ - float_sum = 0; - float_sub = 0; - // use CompletionProcessor for completer - CPPUNIT_ASSERT(CompletionProcessor::Instance()->stop()); - Handle h1 = t_event_float.connect( boost::bind(&EventTest::float_listener, this,_1,_2) ); - - Handle h2 = t_event_float.connect(boost::bind(&EventTest::float_completer, this, _1, _2), - CompletionProcessor::Instance() ); - - t_event_float(1.0, 4.0); - CPPUNIT_ASSERT_EQUAL( float(5.0), float_sum ); - - float a = 10.0, b = 5.0; - t_event_float(a, b); - CPPUNIT_ASSERT_EQUAL( float(20.0), float_sum ); - CPPUNIT_ASSERT_EQUAL( float(0.0), float_sub ); - - CPPUNIT_ASSERT(CompletionProcessor::Instance()->start()); - - h1.disconnect(); - h2.disconnect(); - float_sum = 0; - float_sub = 0; - - // use event processor - CPPUNIT_ASSERT(act.start()); - - h1 = t_event_float.connect(boost::bind(&EventTest::float_listener, this,_1,_2)); - h2 = t_event_float.connect(boost::bind(&EventTest::float_completer, this, _1, _2), - event_proc, EventProcessor::OnlyLast); - - // simulate overrun : - t_event_float(1.0, 4.0); - CPPUNIT_ASSERT_EQUAL( float(5.0), float_sum ); - - t_event_float(a, b); - CPPUNIT_ASSERT_EQUAL( float(20.0), float_sum ); - - event_proc->step(); - act.stop(); - // asyn handlers should reach only last total. - CPPUNIT_ASSERT_EQUAL( float(-15.0), float_sub ); - h1.disconnect(); - h2.disconnect(); -} - -void EventTest::testSyncListener() -{ - // No completer: - reset(); - Handle h = t_event.connect( boost::bind(&EventTest::listener, this) ); - CPPUNIT_ASSERT( h.connected() ); - t_event(); - h.disconnect(); - CPPUNIT_ASSERT( !h.connected() ); - - CPPUNIT_ASSERT( t_listener_value ); - CPPUNIT_ASSERT( !t_completer_value ); -} - -void EventTest::testSyncListenerThreadCompleter() -{ - // in thread completer: - reset(); - CPPUNIT_ASSERT(act.start()); - // Manually call step - event_proc->step(); - Handle h1 = t_event.connect( boost::bind(&EventTest::listener,this)); - Handle h2 = t_event.connect( boost::bind(&EventTest::completer,this), - event_proc ); - CPPUNIT_ASSERT( h1.connected() ); - CPPUNIT_ASSERT( h2.connected() ); - - // Manually call step - event_proc->step(); - - t_event(); - - // Manually call step - event_proc->step(); - - // This will block until all completers are processed. - h1.disconnect(); - h2.disconnect(); - CPPUNIT_ASSERT( !h1.connected() ); - CPPUNIT_ASSERT( !h2.connected() ); - - // Manually call step - event_proc->step(); - event_proc->finalize(); - - // now, both must be called. - CPPUNIT_ASSERT( t_listener_value ); - CPPUNIT_ASSERT( t_completer_value ); -} - -void EventTest::testSyncListenerString() -{ - // No completer: - reset(); - Handle h = t_event_string.connect( boost::bind(&EventTest::listenerString,this,_1) ); - CPPUNIT_ASSERT( h.connected() ); - t_event_string( std::string("What") ); - h.disconnect(); - CPPUNIT_ASSERT( !h.connected() ); - - CPPUNIT_ASSERT_EQUAL( t_listener_what, std::string("What") ); - CPPUNIT_ASSERT( !t_listener_value ); - CPPUNIT_ASSERT( !t_completer_value ); -} - -void EventTest::testCompletionProcessor() -{ - // in thread completer: - reset(); - - CPPUNIT_ASSERT( CompletionProcessor::Instance()->isActive() ); - - Handle h2 = t_event.connect(boost::bind(&EventTest::completer,this), - CompletionProcessor::Instance() - ); - CPPUNIT_ASSERT( h2.connected() ); - - t_event(); - - // This will block until all completers are processed. - sleep(1); - h2.disconnect(); - CPPUNIT_ASSERT( !h2.connected() ); - // CP must be called. - CPPUNIT_ASSERT( t_completer_value ); -} - -void EventTest::testRTEvent() -{ - reset(); - - CPPUNIT_ASSERT(act.start()); - - Handle hl( t_event.setup( boost::bind(&EventTest::listener,this) ) ); - Handle hc( t_event.setup( boost::bind(&EventTest::completer,this), event_proc ) ); - - CPPUNIT_ASSERT( !hl.connected() ); - CPPUNIT_ASSERT( !hc.connected() ); - - hl.connect(); - hc.connect(); - CPPUNIT_ASSERT( hl.connected() ); - CPPUNIT_ASSERT( hc.connected() ); - - t_event(); - - - hl.disconnect(); - CPPUNIT_ASSERT( !hl.connected() ); - CPPUNIT_ASSERT( t_listener_value ); - CPPUNIT_ASSERT( !t_completer_value ); - - event_proc->step(); - CPPUNIT_ASSERT( t_completer_value ); - hc.disconnect(); - CPPUNIT_ASSERT( !hc.connected() ); - - reset(); - t_event(); - event_proc->step(); - - CPPUNIT_ASSERT( t_completer_value == false ); - CPPUNIT_ASSERT( t_listener_value == false ); - - hl.connect(); - hc.connect(); - t_event(); - - hl.disconnect(); - CPPUNIT_ASSERT( !hl.connected() ); - CPPUNIT_ASSERT( t_listener_value == true ); - CPPUNIT_ASSERT( t_completer_value == false ); - - event_proc->step(); - hc.disconnect(); - CPPUNIT_ASSERT( !hc.connected() ); - CPPUNIT_ASSERT( t_completer_value == true ); - -} diff --git a/tests/event_test.hpp b/tests/event_test.hpp deleted file mode 100644 index 6d65c86f2..000000000 --- a/tests/event_test.hpp +++ /dev/null @@ -1,85 +0,0 @@ -/*************************************************************************** - tag: Peter Soetens Mon Jan 10 15:59:18 CET 2005 event_test.hpp - - event_test.hpp - description - ------------------- - begin : Mon January 10 2005 - copyright : (C) 2005 Peter Soetens - email : peter.soetens@mech.kuleuven.ac.be - - *************************************************************************** - * * - * This program is free software; you can redistribute it and/or modify * - * it under the terms of the GNU General Public License as published by * - * the Free Software Foundation; either version 2 of the License, or * - * (at your option) any later version. * - * * - ***************************************************************************/ - - -#ifndef EVENTTEST_H -#define EVENTTEST_H - -#include -#include -#include -#include - -class EventTest : public CppUnit::TestFixture -{ - CPPUNIT_TEST_SUITE( EventTest ); - CPPUNIT_TEST( testEmpty ); - CPPUNIT_TEST( testSyncListener ); - CPPUNIT_TEST( testSyncListenerString ); - CPPUNIT_TEST( testSyncListenerThreadCompleter ); - CPPUNIT_TEST( testCompletionProcessor ); - CPPUNIT_TEST( testTask ); - CPPUNIT_TEST( testBlockingTask ); - CPPUNIT_TEST( testEventArgs ); - CPPUNIT_TEST( testRTEvent ); - CPPUNIT_TEST( testSelfRemoval ); - CPPUNIT_TEST( testCrossRemoval ); -#ifdef OROCOS_TARGET_GNULINUX - CPPUNIT_TEST( testConcurrentEmit ); -#endif - CPPUNIT_TEST_SUITE_END(); - - RTT::Event t_event; - RTT::Event t_event_string; - RTT::Event t_event_float; - bool t_listener_value; - bool t_completer_value; - std::string t_listener_what; - RTT::EventProcessor* event_proc; - RTT::SlaveActivity act; - float float_sum, float_sub; -public: - void setUp(); - void tearDown(); - - void reset(); - - void listener(); - void listenerString(const std::string&); - void completer(); - - int float_listener(float a, float b); - int float_completer(float a, float b); - - void testEmpty(); - void testSyncListener(); - void testSyncListenerString(); - void testSyncListenerSyncCompleter(); - void testSyncListenerThreadCompleter(); - void testCompletionProcessor(); - void testTask(); - void testBlockingTask(); - void testEventArgs(); - void testRTEvent(); - void testSelfRemoval(); - void testCrossRemoval(); - void testConcurrentEmit(); -}; - - -#endif // EVENTTEST_H diff --git a/tests/eventservice_test.cpp b/tests/eventservice_test.cpp deleted file mode 100644 index a0c731c80..000000000 --- a/tests/eventservice_test.cpp +++ /dev/null @@ -1,395 +0,0 @@ -/*************************************************************************** - tag: Peter Soetens Wed Jan 18 14:11:41 CET 2006 eventservice_test.cpp - - eventservice_test.cpp - description - ------------------- - begin : Wed January 18 2006 - copyright : (C) 2006 Peter Soetens - email : peter.soetens@mech.kuleuven.be - - *************************************************************************** - * * - * This program is free software; you can redistribute it and/or modify * - * it under the terms of the GNU General Public License as published by * - * the Free Software Foundation; either version 2 of the License, or * - * (at your option) any later version. * - * * - ***************************************************************************/ - - -#include -#include -#include - -#include -#include - -#include "eventservice_test.hpp" -#include -#include - -// Registers the fixture into the 'registry' -CPPUNIT_TEST_SUITE_REGISTRATION( EventServiceTest ); - -using namespace RTT; -using namespace RTT; -using namespace boost; -using namespace std; - -void -EventServiceTest::setUp() -{ - t_event0 = Event("t_event0"); - t_event1 = RTT::Event("t_event1"); - t_event2 = RTT::Event("t_event2"); - t_event3 = RTT::Event("t_event3"); - - - event_proc = new EventProcessor(); - act.run(event_proc); - act.start(); - es = new EventService(event_proc); - reset(); -} - - -void -EventServiceTest::tearDown() -{ - act.stop(); - delete es; - delete event_proc; -} - -void EventServiceTest::listener0(void) -{ - t_listener_done = true; -} - -void EventServiceTest::completer0(void) -{ - t_completer_done = true; -} - -void EventServiceTest::listener1(const std::string& s) -{ - t_listener_done = true; - t_listener_string=s; -} -void EventServiceTest::completer1(const std::string&s) -{ - t_completer_done = true; - t_completer_string=s; -} -void EventServiceTest::listener2(const std::string& s, double f ) -{ - t_listener_done = true; - t_listener_string=s; - t_listener_double=f; -} -void EventServiceTest::completer2(const std::string& s, double f) -{ - t_completer_done = true; - t_completer_string=s; - t_completer_double=f; -} - -void EventServiceTest::listener3(std::string s, double f, bool b) -{ - t_listener_done = true; - t_listener_string=s; - t_listener_double=f; - t_listener_bool=b; -} -void EventServiceTest::completer3(std::string s, double f, bool b ) -{ - t_completer_done = true; - t_completer_string=s; - t_completer_double=f; - t_completer_bool=b; -} - -void EventServiceTest::reset() -{ - t_listener_done = false; - t_completer_done = false; - t_listener_string = ""; - t_listener_double = 0.0; - t_listener_bool = false; - t_completer_string = ""; - t_completer_double = 0.0; - t_completer_bool = false; -} - -void EventServiceTest::setup() -{ - es->addEvent( &t_event0, ""); - es->addEvent( &t_event1, "", "", "" ); - es->addEvent( &t_event2, "", "", "", "", "" ); - es->addEvent( &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; - result = es->addEvent( &t_event0 ); - CPPUNIT_ASSERT( result ); - result = es->addEvent( &t_event1 ); - CPPUNIT_ASSERT( result ); - result = es->addEvent( &t_event2 ); - CPPUNIT_ASSERT( result ); - result = es->addEvent( &t_event3 ); - CPPUNIT_ASSERT( result ); - - result = es->addEvent( &t_event0 ); - CPPUNIT_ASSERT( result == false ); - - result = es->removeEvent( "t_event0" ); - CPPUNIT_ASSERT( result ); - result = es->removeEvent( "t_event1" ); - CPPUNIT_ASSERT( result ); - result = es->removeEvent( "t_event2" ); - CPPUNIT_ASSERT( result ); - result = es->removeEvent( "t_event3" ); - CPPUNIT_ASSERT( result ); - - result = es->removeEvent( "t_event0" ); - CPPUNIT_ASSERT( result == false ); -} - -void EventServiceTest::testSetupSyn() -{ - this->setup(); - Handle h; - h = es->setupSyn("t_event0", bind(&EventServiceTest::listener0,this), vector() ); - CPPUNIT_ASSERT( h ); - h = es->setupSyn("t_event1", bind(&EventServiceTest::listener0,this), GenerateDataSource()(ref(t_listener_string))); - CPPUNIT_ASSERT( h ); - h = es->setupSyn("t_event2", bind(&EventServiceTest::listener0,this), GenerateDataSource()(ref(t_listener_string), ref(t_listener_double))); - CPPUNIT_ASSERT( h ); - h = es->setupSyn("t_event3", bind(&EventServiceTest::listener0,this), GenerateDataSource()(ref(t_listener_string), ref(t_listener_double),ref(t_listener_bool))); - CPPUNIT_ASSERT( h ); - - this->cleanup(); -} - -void EventServiceTest::testSetupAsyn() -{ - this->setup(); - Handle h; - h = es->setupAsyn("t_event0", bind(&EventServiceTest::completer0,this), vector(),event_proc ); - CPPUNIT_ASSERT( h ); - h = es->setupAsyn("t_event1", bind(&EventServiceTest::completer0,this), GenerateDataSource()(ref(t_completer_string)),event_proc); - CPPUNIT_ASSERT( h ); - h = es->setupAsyn("t_event2", bind(&EventServiceTest::completer0,this), GenerateDataSource()(ref(t_completer_string), ref(t_completer_double)),event_proc); - CPPUNIT_ASSERT( h ); - h = es->setupAsyn("t_event3", bind(&EventServiceTest::completer0,this), GenerateDataSource()(ref(t_completer_string), ref(t_completer_double), ref(t_completer_bool) ),event_proc); - CPPUNIT_ASSERT( h ); - - this->cleanup(); -} - -void EventServiceTest::testSetupEmit() -{ - this->setup(); - - ActionInterface::shared_ptr r; - r.reset( es->getEvent("t_event0", std::vector() ) ); - CPPUNIT_ASSERT( r ); - r.reset( es->getEvent("t_event1", GenerateDataSource()(std::string("hello")) ) ); - CPPUNIT_ASSERT( r ); - r.reset( es->getEvent("t_event2", GenerateDataSource()(std::string("hello"),0.1234) ) ); - CPPUNIT_ASSERT( r ); - r.reset( es->getEvent("t_event3", GenerateDataSource()(std::string("hello"),0.1234, true) ) ); - CPPUNIT_ASSERT( r ); - - this->cleanup(); -} - -void EventServiceTest::testEmit0() -{ - this->setup(); - - Handle h1, h2; - h1 = es->setupSyn("t_event0", bind(&EventServiceTest::listener0,this), vector() ); - h2 = es->setupAsyn("t_event0", bind(&EventServiceTest::completer0,this), vector(),event_proc ); - ActionInterface::shared_ptr r; - r.reset( es->getEvent("t_event0", std::vector() ) ); - - CPPUNIT_ASSERT( h1.connect() ); - r->execute(); - CPPUNIT_ASSERT( t_listener_done ); - this->reset(); - CPPUNIT_ASSERT( h1.disconnect() ); - - CPPUNIT_ASSERT( h2.connect() ); - r->execute(); - CPPUNIT_ASSERT( !t_completer_done ); - event_proc->step(); - CPPUNIT_ASSERT( t_completer_done ); - this->reset(); - CPPUNIT_ASSERT( h2.disconnect() ); - - this->cleanup(); -} - -void EventServiceTest::testEmit1() -{ - this->setup(); - - Handle h1, h2; - ActionInterface::shared_ptr r; - - h1 = es->setupSyn("t_event1", bind(&EventServiceTest::listener0,this), GenerateDataSource()(ref(t_listener_string))); - h2 = es->setupAsyn("t_event1", bind(&EventServiceTest::completer0,this), GenerateDataSource()(ref(t_completer_string)),event_proc); - r.reset( es->getEvent("t_event1", GenerateDataSource()(std::string("hello")) ) ); - - CPPUNIT_ASSERT( h1.connect() ); - r->execute(); - CPPUNIT_ASSERT( t_listener_done ); - CPPUNIT_ASSERT( t_listener_string == std::string("hello") ); - this->reset(); - CPPUNIT_ASSERT( h1.disconnect() ); - - CPPUNIT_ASSERT( h2.connect() ); - r->execute(); - CPPUNIT_ASSERT( !t_completer_done ); - event_proc->step(); - CPPUNIT_ASSERT( t_completer_done ); - CPPUNIT_ASSERT( t_completer_string == std::string("hello") ); - this->reset(); - CPPUNIT_ASSERT( h2.disconnect() ); - - this->cleanup(); -} -void EventServiceTest::testEmit2() -{ - this->setup(); - Handle h1, h2; - ActionInterface::shared_ptr r; - - h1 = es->setupSyn("t_event2", bind(&EventServiceTest::listener0,this), GenerateDataSource()(ref(t_listener_string), ref(t_listener_double))); - h2 = es->setupAsyn("t_event2", bind(&EventServiceTest::completer0,this), GenerateDataSource()(ref(t_completer_string), ref(t_completer_double)),event_proc); - - r.reset( es->getEvent("t_event2", GenerateDataSource()(std::string("hello"),0.1234) ) ); - - - CPPUNIT_ASSERT( h1.connect() ); - r->execute(); - CPPUNIT_ASSERT( t_listener_done ); - CPPUNIT_ASSERT( t_listener_string == std::string("hello") ); - CPPUNIT_ASSERT( t_listener_double == 0.1234 ); - this->reset(); - CPPUNIT_ASSERT( h1.disconnect() ); - - CPPUNIT_ASSERT( h2.connect() ); - r->execute(); - 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 ); - this->reset(); - CPPUNIT_ASSERT( h2.disconnect() ); - - this->cleanup(); -} - -void EventServiceTest::testEmit3() -{ - this->setup(); - Handle h1, h2; - ActionInterface::shared_ptr r; - - h1 = es->setupSyn("t_event3", bind(&EventServiceTest::listener0,this), GenerateDataSource()(ref(t_listener_string), ref(t_listener_double),ref(t_listener_bool))); - h2 = es->setupAsyn("t_event3", bind(&EventServiceTest::completer0,this), GenerateDataSource()(ref(t_completer_string), ref(t_completer_double), ref(t_completer_bool) ),event_proc); - r.reset( es->getEvent("t_event3", GenerateDataSource()(std::string("hello"),0.1234, true) ) ); - - - CPPUNIT_ASSERT( h1.connect() ); - r->execute(); - 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 == true ); - this->reset(); - CPPUNIT_ASSERT( h1.disconnect() ); - - CPPUNIT_ASSERT( h2.connect() ); - r->execute(); - 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 == true ); - this->reset(); - CPPUNIT_ASSERT( h2.disconnect() ); - - this->cleanup(); -} - -void Foo3(string, double, bool) -{ -} - -void EventServiceTest::testEventC() -{ - // Test EventC and ConnectionC... - Handle h1, h2, h3; - - this->setup(); - - try { - //h1 = es->setupConnection("t_event3").callback( Foo3 ).handle(); - h1 = es->setupConnection("t_event3").callback( this, &EventServiceTest::listener3 ).handle(); - } catch ( std::exception& e ) { - CPPUNIT_ASSERT_MESSAGE( e.what(), false ); - } - - try { - h2 = es->setupConnection("t_event3").callback( this, &EventServiceTest::completer3 ,event_proc).handle(); - } catch ( std::exception& e ) { - CPPUNIT_ASSERT_MESSAGE( e.what(), false ); - } - - EventC evc; - bool evcarg = true; - try { - evc = es->setupEmit("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 deleted file mode 100644 index eebef7461..000000000 --- a/tests/eventservice_test.hpp +++ /dev/null @@ -1,86 +0,0 @@ -/*************************************************************************** - tag: Peter Soetens Mon Jan 10 15:59:18 CET 2005 event_test.hpp - - event_test.hpp - description - ------------------- - begin : Mon January 10 2005 - copyright : (C) 2005 Peter Soetens - email : peter.soetens@mech.kuleuven.ac.be - - *************************************************************************** - * * - * This program is free software; you can redistribute it and/or modify * - * it under the terms of the GNU General Public License as published by * - * the Free Software Foundation; either version 2 of the License, or * - * (at your option) any later version. * - * * - ***************************************************************************/ - - -#ifndef EVENT_SERVICE_TEST_H -#define EVENT_SERVICE_TEST_H - -#include -#include -#include -#include -#include - -class EventServiceTest : public CppUnit::TestFixture -{ - CPPUNIT_TEST_SUITE( EventServiceTest ); - CPPUNIT_TEST( testAddRemove ); - CPPUNIT_TEST( testSetupSyn ); - CPPUNIT_TEST( testSetupAsyn ); - CPPUNIT_TEST( testSetupEmit ); - CPPUNIT_TEST( testEmit0 ); - CPPUNIT_TEST( testEmit1 ); - CPPUNIT_TEST( testEmit2 ); - CPPUNIT_TEST( testEmit3 ); - CPPUNIT_TEST( testEventC ); - CPPUNIT_TEST_SUITE_END(); - - RTT::Event t_event0; - RTT::Event t_event1; - RTT::Event t_event2; - RTT::Event t_event3; - bool t_listener_done; - bool t_completer_done; - std::string t_listener_string; - double t_listener_double; - bool t_listener_bool; - std::string t_completer_string; - double t_completer_double; - bool t_completer_bool; - RTT::EventProcessor* event_proc; - RTT::EventService* es; - RTT::SlaveActivity act; -public: - void setUp(); - void tearDown(); - - void setup(); - void reset(); - void cleanup(); - - void listener0(); - void completer0(); - void listener1(const std::string&); - void completer1(const std::string&); - void listener2(const std::string&, double); - void completer2(const std::string&, double); - void listener3(std::string, double, bool); - void completer3(std::string, double, bool); - - void testAddRemove(); - void testSetupSyn(); - void testSetupAsyn(); - void testSetupEmit(); - void testEmit0(); - void testEmit1(); - void testEmit2(); - void testEmit3(); - void testEventC(); -}; - -#endif // EVENTTEST_H diff --git a/tests/function_test.cpp b/tests/function_test.cpp deleted file mode 100644 index 6795b2395..000000000 --- a/tests/function_test.cpp +++ /dev/null @@ -1,338 +0,0 @@ -/*************************************************************************** - tag: Peter Soetens Mon Jan 10 15:59:51 CET 2005 function_test.cpp - - function_test.cpp - description - ------------------- - begin : Mon January 10 2005 - copyright : (C) 2005 Peter Soetens - email : peter.soetens@mech.kuleuven.ac.be - - *************************************************************************** - * * - * This program is free software; you can redistribute it and/or modify * - * it under the terms of the GNU General Public License as published by * - * the Free Software Foundation; either version 2 of the License, or * - * (at your option) any later version. * - * * - ***************************************************************************/ - - - -#include "function_test.hpp" -#include -#include -#include -#include -#include -#include -#include - -using namespace std; - -// Registers the fixture into the 'registry' -CPPUNIT_TEST_SUITE_REGISTRATION( FunctionTest ); - - - FunctionTest::FunctionTest() - : gtc("root" ), - gtask( 0.01, gtc.engine() ) - {} - - -void -FunctionTest::setUp() -{ - // ltc has a test object - gtc.addObject(this->createObject("test", gtc.engine()->commands() ) ); - - i = 0; -} - - -void -FunctionTest::tearDown() -{ -} - - -bool FunctionTest::assertBool( bool b) { - return b; -} -bool FunctionTest::assertMsg( bool b, const std::string& msg) { - if ( b == false ) - cout << "Asserted :" << b << " with :" << msg << endl; - return b; -} - -int FunctionTest::increase() { - return ++i; -} - -void FunctionTest::reset() { - i = 0; -} - - -OperationInterface* FunctionTest::createObject(string a, CommandProcessor* cp) -{ - TaskObject* dat = new TaskObject(a); - dat->methods()->addMethod( method( "assert", &FunctionTest::assertBool, this), - "Assert", "bool", "" ); - dat->methods()->addMethod( method( "increase", &FunctionTest::increase, this), - "Return increasing i" ); - dat->methods()->addMethod( method( "reset", &FunctionTest::reset, this), - "Reset i" ); - dat->methods()->addMethod( method( "assertMsg", &FunctionTest::assertMsg, this), - "Assert message", "bool", "", "text", "text" ); - - dat->methods()->addMethod( method( "isTrue", &FunctionTest::assertBool, this), - "Identity function", "bool", "" ); - dat->methods()->addMethod( method( "i", &FunctionTest::getI, this), - "Return the current number" ); - - dat->commands()->addCommand( command( "instantDone", &FunctionTest::true_genCom, - &FunctionTest::true_gen, this, cp), - "returns immediately" ); - dat->commands()->addCommand( command( "neverDone", &FunctionTest::true_genCom, - &FunctionTest::false_gen, this, cp), - "returns never" ); - dat->commands()->addCommand( command( "instantNotDone", &FunctionTest::true_genCom, - &FunctionTest::true_gen, this, cp, false), - "returns never"); - dat->commands()->addCommand( command( "instantFail", &FunctionTest::false_genCom, - &FunctionTest::true_gen, this, cp), - "fails immediately" ); - dat->commands()->addCommand( command( "totalFail", &FunctionTest::false_genCom, - &FunctionTest::false_gen, this, cp), - "fails in command and condition" ); - return dat; -} - -void FunctionTest::testSimpleFunction() -{ - string prog = string("function foo { \n") - + " do test.assert( test.isTrue( true ) )\n" - + "}\n" - + "program x { \n" - // + " do test.assert( true )\n" - + " call foo\n" - //+ " do test.assert( true )\n" - + "}"; - - this->doFunction( prog, >c ); - this->finishFunction( >c, "x"); -} - -void FunctionTest::testExportFunction() -{ - string prog = string("export function foo { \n") - + " do test.assert( test.isTrue( true ) )\n" - + "}\n" - + "program x { \n" - + " do this.foo()\n" - + "}"; - - this->doFunction( prog, >c ); - this->finishFunction( >c, "x"); -} - -void FunctionTest::testRecFunction() -{ - string prog = string("export function foo { \n") - + " do this.foo()\n" // recursive is forbidden. - + "}\n" - + "program x { \n" - + " do foo\n" - + "}"; - - try { - parser.parseProgram( prog, >c ); - } - catch( ... ) - { - prog = string("function foo { \n") - + " call foo\n" // recursive is forbidden. - + "}\n" - + "program x { \n" - + " call foo\n" - + "}"; - //progs = prog; - try { - parser.parseProgram( prog, >c ); - } - catch( ... ) - { - return; - } - CPPUNIT_ASSERT_MESSAGE( "Recursive 'call' function was accepted, while it is illegal.", false ); - } - CPPUNIT_ASSERT_MESSAGE( "Recursive 'do' function was accepted, while it is illegal.", false ); -} - -void FunctionTest::testCallFunction() -{ - string prog = string("function foo(int a, string b, bool c) { \n") - + " do test.assert( test.isTrue( true ) )\n" - + " if true then\n" - + " return\n" - + " do test.assert(false)\n" // do not reach - + "}\n" - + "program x { \n" - + " call foo( 1, \"hello\", true)\n" - + "}"; - - this->doFunction( prog, >c ); - this->finishFunction( >c, "x"); -} - -void FunctionTest::testFunctionStack() -{ - string prog = string("export function foo { \n") - +" var double a = 1.234\n" - +" var double b = 4.321\n" - +" do test.assert( a == 1.234 )\n" - +" do test.assert( b == 4.321 )\n" - +" set a = 2.134\n" - +" set b = 3.421\n" - +" do test.assert( a == 2.134 )\n" - +" do test.assert( b == 3.421 )\n" - + "}\n" - + "program x { \n" - +" var double b = 1.234\n" // we switch val's of a and b here - +" var double a = 4.321\n" - + " do foo()\n" - +" do test.assert( b == 1.234 )\n" - +" do test.assert( a == 4.321 )\n" - + " do foo()\n" - + " set a = 0.0\n" - + " set b = 1.0\n" - +" do test.assert( b == 1.0 )\n" - +" do test.assert( a == 0.0 )\n" - + "}"; - - this->doFunction( prog, >c ); - this->finishFunction( >c, "x"); -} - - -void FunctionTest::testFunctionExportArgs() -{ - // Test if the foo args are init'ed correctly. - string prog = - string("export function fooA(int a, string b, bool c) { \n") - + " do test.assert( c )\n" - + " do test.assert( a == 1 )\n" - + " do test.assert( b == \"A\" )\n" - + "}\n" - + "export function fooB(int a, string b, bool c) { \n" - + " do test.assert( !c )\n" - + " do test.assert( a == -1 )\n" - + " do test.assert( b == \"B\" )\n" - + " do fooA(1, \"A\", true)\n" - + "}\n" - + "program x { \n" - + " do fooA(1, \"A\", true)\n" - + " do fooB(-1, \"B\", false)\n" -// + " call fooA(1.0, \"A\", true)\n" -// + " call fooB(-1, \"B\", false)\n" - + "}"; - - this->doFunction( prog, >c ); - this->finishFunction( >c, "x"); -} - -void FunctionTest::testFunctionCallArgs() -{ - // Test if the foo args are init'ed correctly. - string prog = - string("function fooA(int a, string b, bool c) { \n") - + " do test.assert( c )\n" - + " do test.assert( a == 1 )\n" - + " do test.assert( b == \"A\" )\n" - + "}\n" - + "function fooB(int a, string b, bool c) { \n" - + " do test.assert( !c )\n" - + " var int i = 1\n" - + " var string s = \"A\"\n" - + " var bool tf = true\n" - + " call fooA(i, s, tf)\n" - + " do test.assert( a == -1 )\n" - + " do test.assert( b == \"B\" )\n" - + "}\n" - + "program x { \n" - + " call fooA(1, \"A\", true)\n" - + " call fooB(-1, \"B\", false)\n" -// + " call fooA(1.0, \"A\", true)\n" -// + " call fooB(-1, \"B\", false)\n" - + "}"; - - this->doFunction( prog, >c ); - this->finishFunction( >c, "x"); -} - -void FunctionTest::testFunctionFail() -{ - // Test if obj-function error is propagated correctly to - // calling program or function - string prog = - string("export function fooA { \n") - + " do test.assert( false )\n" // throws error - + "}\n" - + "export function fooB { \n" - + " do fooA()\n" - + "}\n" - + "program x { \n" - + " var bool success = false\n" - + " try fooA()\n" - + " catch \n" - + " set success = true\n" // error caught. - + " do test.assert(success)\n" - + " set success = false\n" - + " try fooB()\n" - + " catch\n" - + " set success = true\n" // error caught. - + " do test.assert(success)\n" - + "}"; - - this->doFunction( prog, >c ); - this->finishFunction( >c, "x"); -} - -void FunctionTest::doFunction( const std::string& prog, TaskContext* tc, bool test ) -{ - CPPUNIT_ASSERT( tc->engine() ); - CPPUNIT_ASSERT( tc->engine()->programs()); - Parser::ParsedPrograms pg_list; - try { - pg_list = parser.parseProgram( prog, tc ); - } - catch( const file_parse_exception& exc ) - { - CPPUNIT_ASSERT_MESSAGE( exc.what(), false ); - } - if ( pg_list.empty() ) - { - CPPUNIT_ASSERT_MESSAGE("No program parsed in test.", false ); - } - ProgramProcessor* pp = tc->engine()->programs(); - pp->loadProgram( *pg_list.begin() ); - pp->getProgram( (*pg_list.begin())->getName() )->start(); - CPPUNIT_ASSERT( SimulationThread::Instance()->run(1000) ); - gtask.stop(); - - if (test ) { - stringstream errormsg; - errormsg << " on line " << pp->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->engine()->programs()->getProgram( prog_name )->stop(); - tc->engine()->programs()->unloadProgram( prog_name ); -} - - - diff --git a/tests/function_test.hpp b/tests/function_test.hpp deleted file mode 100644 index 3c25c3b25..000000000 --- a/tests/function_test.hpp +++ /dev/null @@ -1,83 +0,0 @@ -/*************************************************************************** - tag: Peter Soetens Mon Jan 10 15:59:18 CET 2005 function_test.hpp - - function_test.hpp - description - ------------------- - begin : Mon January 10 2005 - copyright : (C) 2005 Peter Soetens - email : peter.soetens@mech.kuleuven.ac.be - - *************************************************************************** - * * - * This program is free software; you can redistribute it and/or modify * - * it under the terms of the GNU General Public License as published by * - * the Free Software Foundation; either version 2 of the License, or * - * (at your option) any later version. * - * * - ***************************************************************************/ - - -#ifndef FUNCTIONTEST_H -#define FUNCTIONTEST_H - -#include - -#include -#include -#include -#include -#include - -using namespace RTT; -using namespace RTT; - -class FunctionTest : public CppUnit::TestFixture -{ - CPPUNIT_TEST_SUITE( FunctionTest ); - CPPUNIT_TEST( testSimpleFunction ); - CPPUNIT_TEST( testRecFunction ); - CPPUNIT_TEST( testCallFunction ); - CPPUNIT_TEST( testExportFunction ); - CPPUNIT_TEST( testFunctionStack ); - CPPUNIT_TEST( testFunctionCallArgs ); - CPPUNIT_TEST( testFunctionExportArgs ); - CPPUNIT_TEST( testFunctionFail ); - CPPUNIT_TEST_SUITE_END(); - - Parser parser; - TaskContext gtc; - SimulationActivity gtask; - OperationInterface* createObject(std::string name, CommandProcessor* cp); - bool assertBool( bool ); - bool assertMsg( bool, const std::string& msg); - int increase(); - void reset(); - void doFunction( const std::string& prog, TaskContext*, bool test=true ); - void finishFunction( TaskContext* , std::string ); - - bool true_genCom() { return true; } - bool false_genCom() { return false; } - bool true_gen() const { return true; } - bool false_gen() const { return false; } - - bool bool_gen( bool b ) const { return b; } - int getI() const { return i; } - int i; -public: - FunctionTest(); - - void setUp(); - void tearDown(); - - void testSimpleFunction(); - void testRecFunction(); - void testCallFunction(); - void testExportFunction(); - void testFunctionStack(); - void testFunctionCallArgs(); - void testFunctionExportArgs(); - void testFunctionFail(); - -}; - -#endif diff --git a/tests/generictask_test.cpp b/tests/generictask_test.cpp deleted file mode 100644 index 2f79de104..000000000 --- a/tests/generictask_test.cpp +++ /dev/null @@ -1,322 +0,0 @@ -/*************************************************************************** - tag: Peter Soetens Mon Jun 26 13:26:02 CEST 2006 generictask_test.cpp - - generictask_test.cpp - description - ------------------- - begin : Mon June 26 2006 - copyright : (C) 2006 Peter Soetens - email : peter.soetens@fmtc.be - - *************************************************************************** - * * - * This program is free software; you can redistribute it and/or modify * - * it under the terms of the GNU General Public License as published by * - * the Free Software Foundation; either version 2 of the License, or * - * (at your option) any later version. * - * * - ***************************************************************************/ - - - -#include "generictask_test.hpp" -#include -#include -#include -#include -#include -#include -#include - -#include -#include - -#include - -#include - -using namespace std; - -// Registers the fixture into the 'registry' -CPPUNIT_TEST_SUITE_REGISTRATION( Generic_TaskTest ); - - -void -Generic_TaskTest::setUp() -{ - tc = new TaskContext( "root" ); - tc->addObject( this->createMethodFactory() ); - tsim = new SimulationActivity(0.001, tc->engine() ); -} - - -void -Generic_TaskTest::tearDown() -{ -// if ( tc->getPeer("programs") ) -// delete tc->getPeer("programs"); - tsim->stop(); - SimulationThread::Instance()->stop(); - delete tc; - delete tsim; -} - -bool Generic_TaskTest::assertBool( bool b) { - return b; -} - -TaskObject* Generic_TaskTest::createMethodFactory() -{ - TaskObject* to = new TaskObject("methods"); - - to->methods()->addMethod( method("assert", &Generic_TaskTest::assertBool, this), "assert","b","bd"); - - to->methods()->addMethod( method("m0", &Generic_TaskTest::m0, this), "M0"); - to->methods()->addMethod( method("m1", &Generic_TaskTest::m1, this), "M1","a","ad"); - to->methods()->addMethod( method("m2", &Generic_TaskTest::m2, this), "M2","a","ad","a","ad"); - to->methods()->addMethod( method("m3", &Generic_TaskTest::m3, this), "M3","a","ad","a","ad","a","ad"); - to->methods()->addMethod( method("m4", &Generic_TaskTest::m4, this), "M4","a","ad","a","ad","a","ad","a","ad"); - return to; -} - -void Generic_TaskTest::testRemoteMethod() -{ - Method m0; - boost::shared_ptr implementation( new detail::RemoteMethod(tc->getObject("methods")->methods(),"m0") ); - m0 = implementation; - CPPUNIT_ASSERT( m0.ready() ); - - Method m1; - implementation.reset( new detail::RemoteMethod(tc->getObject("methods")->methods(),"m1") ); - m1 = implementation; - CPPUNIT_ASSERT( m1.ready() ); - - CPPUNIT_ASSERT_EQUAL( -2.0, m1(1) ); - CPPUNIT_ASSERT_EQUAL( -1.0, m0() ); -} - -void Generic_TaskTest::testMethodsC() -{ - MethodC mc; - double r = 0.0; - mc = tc->getObject("methods")->methods()->create("m0").ret( r ); - CPPUNIT_ASSERT( mc.execute() ); - CPPUNIT_ASSERT( r == -1.0 ); - - mc = tc->getObject("methods")->methods()->create("m2").argC(1).argC(1.0).ret( r ); - CPPUNIT_ASSERT( mc.execute() ); - CPPUNIT_ASSERT( r == -3.0 ); - - mc = tc->getObject("methods")->methods()->create("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 Generic_TaskTest::testMethod() -{ - Method m0("m0", &Generic_TaskTest::m0, this); - Method m1("m1", &Generic_TaskTest::m1, this); - Method m2("m2", &Generic_TaskTest::m2, this); - Method m3("m3", &Generic_TaskTest::m3, this); - Method m4("m4", &Generic_TaskTest::m4, this); - - CPPUNIT_ASSERT_EQUAL( -1.0, m0() ); - CPPUNIT_ASSERT_EQUAL( -2.0, m1(1) ); - CPPUNIT_ASSERT_EQUAL( -3.0, m2(1, 2.0) ); - CPPUNIT_ASSERT_EQUAL( -4.0, m3(1, 2.0, false) ); - CPPUNIT_ASSERT_EQUAL( -5.0, m4(1, 2.0, false,"hello") ); -} - -void Generic_TaskTest::testMethodFactory() -{ - // Test the addition of 'simple' methods to the operation interface, - // and retrieving it back in a new Method object. - - Method m0("m0", &Generic_TaskTest::m0, this); - Method m1("m1", &Generic_TaskTest::m1, this); - Method m2("m2", &Generic_TaskTest::m2, this); - - TaskObject to("task"); - - CPPUNIT_ASSERT( to.methods()->addMethod(&m0) ); - CPPUNIT_ASSERT( ! to.methods()->addMethod(&m0) ); - CPPUNIT_ASSERT( to.methods()->addMethod(&m1) ); - CPPUNIT_ASSERT( to.methods()->addMethod(&m2) ); - - // test constructor - Method mm0 = to.methods()->getMethod("m0"); - CPPUNIT_ASSERT( mm0.getMethodImpl() ); - CPPUNIT_ASSERT( mm0.ready() ); - - // test operator=() - Method mm1; - mm1 = to.methods()->getMethod("m1"); - CPPUNIT_ASSERT( mm1.getMethodImpl() ); - CPPUNIT_ASSERT( mm1.ready() ); - - Method mm2 = to.methods()->getMethod("m2"); - CPPUNIT_ASSERT( mm2.getMethodImpl() ); - CPPUNIT_ASSERT( mm2.ready() ); - - // start the activity, such that methods are accepted. - CPPUNIT_ASSERT( tsim->start()) ; - // execute methods and check status: - CPPUNIT_ASSERT_EQUAL( -1.0, mm0() ); - - CPPUNIT_ASSERT_EQUAL( -2.0, mm1(1) ); - CPPUNIT_ASSERT_EQUAL( -3.0, mm2(1, 2.0) ); - - // test error cases: - // Add uninitialised method: - Method mvoid; - CPPUNIT_ASSERT(to.methods()->addMethod( &mvoid ) == false); - mvoid = Method("voidm"); - CPPUNIT_ASSERT(to.methods()->addMethod( &mvoid ) == false); - - // wrong type 1: - mvoid = to.methods()->getMethod("m1"); - CPPUNIT_ASSERT( mvoid.ready() == false ); - // wrong type 2: - mvoid = to.methods()->getMethod("m1"); - // wrong type 3: - mvoid = to.methods()->getMethod("m0"); - CPPUNIT_ASSERT( mvoid.ready() == false ); - // non existing - mvoid = to.methods()->getMethod("voidm"); - CPPUNIT_ASSERT( mvoid.ready() == false ); - - // this line may not crash: - mvoid(); - -} - -void Generic_TaskTest::testCRMethod() -{ - this->ret = -3.3; - - Method m0r("m0r", &Generic_TaskTest::m0r, this); - Method m0cr("m0cr", &Generic_TaskTest::m0cr, this); - - Method m1r("m1r", &Generic_TaskTest::m1r, this); - Method m1cr("m1cr", &Generic_TaskTest::m1cr, this); - - CPPUNIT_ASSERT_EQUAL( -3.3, m0r() ); - CPPUNIT_ASSERT_EQUAL( -3.3, m0cr() ); - - double value = 5.3; - CPPUNIT_ASSERT_EQUAL( 5.3*2, m1r(value) ); - CPPUNIT_ASSERT_EQUAL( 5.3*2, value ); - CPPUNIT_ASSERT_EQUAL( 5.3, m1cr(5.3) ); -} - - -void Generic_TaskTest::testMethodFromDS() -{ - TaskObject to("task"); - - Method m0("m0", &Generic_TaskTest::m0, this); - Method m1("m1", &Generic_TaskTest::m1, this); - Method m2("m2", &Generic_TaskTest::m2, this); - Method m3("m3", &Generic_TaskTest::m3, this); - Method m4("m4", &Generic_TaskTest::m4, this); - - to.methods()->addMethod( &m0, "desc"); - to.methods()->addMethod( &m1, "desc", "a1", "d1"); - to.methods()->addMethod( &m2, "desc", "a1", "d1", "a2","d2"); - to.methods()->addMethod( &m3, "desc", "a1", "d1", "a2","d2","a3","d3"); - to.methods()->addMethod( &m4, "desc", "a1", "d1", "a2","d2","a3","d3", "a4","d4"); - - double ret; - MethodC mc0( to.methods(), "m0"); - mc0.ret(ret); - MethodC mc1( to.methods(), "m1"); - mc1.argC(1).ret(ret); - MethodC mc2( to.methods(), "m2"); - mc2.argC(1).argC(2.0).ret(ret); - MethodC mc3( to.methods(), "m3"); - mc3.argC(1).argC(2.0).argC(false).ret(ret); - MethodC mc4( to.methods(), "m4"); - mc4.argC(1).argC(2.0).argC(false).argC(std::string("hello")).ret(ret); - - CPPUNIT_ASSERT( mc0.execute() ); - CPPUNIT_ASSERT_EQUAL(-1.0, ret); - CPPUNIT_ASSERT( mc1.execute() ); - CPPUNIT_ASSERT_EQUAL(-2.0, ret); - CPPUNIT_ASSERT( mc2.execute() ); - CPPUNIT_ASSERT_EQUAL(-3.0, ret); - CPPUNIT_ASSERT( mc3.execute() ); - CPPUNIT_ASSERT_EQUAL(-4.0, ret); - CPPUNIT_ASSERT( mc4.execute() ); - CPPUNIT_ASSERT_EQUAL(-5.0, ret); -} - -void Generic_TaskTest::testDSMethod() -{ - TaskObject to("task"); - - // A method of which the first argument type is a pointer to the object - // on which it must be invoked. The pointer is internally stored as a weak_ptr, - // thus the object must be stored in a shared_ptr, in a DataSource. Scripting - // requires this for copying state machines. - - Method meth0("m0", - &Generic_TaskTest::m0); - - method_ds("m0", &Generic_TaskTest::m0); - - Method meth1("m1", - &Generic_TaskTest::m1); - - method_ds("m1", &Generic_TaskTest::m1); - method_ds("ms",&Generic_TaskTest::comstr ); - - boost::shared_ptr ptr( new Generic_TaskTest() ); - ValueDataSource >::shared_ptr wp = new ValueDataSource >( ptr ); - CPPUNIT_ASSERT( to.methods()->addMethodDS( wp.get(), meth0, "desc" ) ); - CPPUNIT_ASSERT( to.methods()->addMethodDS( wp.get(), meth1, "desc", "a1", "d1" ) ); - - // this actually works ! the method will detect the deleted pointer. - //ptr.reset(); - - CPPUNIT_ASSERT( tsim->start()) ; - - double ret; - MethodC c0 = to.methods()->create("m0").ret(ret); - CPPUNIT_ASSERT( c0.execute() ); - CPPUNIT_ASSERT_EQUAL( -1.0, ret ); - MethodC c1 = to.methods()->create("m1").argC(1).ret(ret); - CPPUNIT_ASSERT( c1.execute() ); - CPPUNIT_ASSERT_EQUAL( -2.0, ret ); - - CPPUNIT_ASSERT( tsim->stop()) ; - -} - -void Generic_TaskTest::testAddMethod() -{ - Method m0 = method("m0", &Generic_TaskTest::m0, this); - - Method m1 = method("m1", &Generic_TaskTest::m1, this); - Method m2 = method("m2", &Generic_TaskTest::m2, this); - Method m3 = method("m3", &Generic_TaskTest::m3, this); - Method m4 = method("m4", &Generic_TaskTest::m4, this); - - CPPUNIT_ASSERT_EQUAL( -1.0, m0() ); - CPPUNIT_ASSERT_EQUAL( -2.0, m1(1) ); - CPPUNIT_ASSERT_EQUAL( -3.0, m2(1, 2.0) ); - CPPUNIT_ASSERT_EQUAL( -4.0, m3(1, 2.0, false) ); - CPPUNIT_ASSERT_EQUAL( -5.0, m4(1, 2.0, false,"hello") ); -} - diff --git a/tests/generictask_test.hpp b/tests/generictask_test.hpp deleted file mode 100644 index 89061f137..000000000 --- a/tests/generictask_test.hpp +++ /dev/null @@ -1,90 +0,0 @@ -/*************************************************************************** - tag: Peter Soetens Mon Jun 26 13:26:02 CEST 2006 generictask_test.hpp - - generictask_test.hpp - description - ------------------- - begin : Mon June 26 2006 - copyright : (C) 2006 Peter Soetens - email : peter.soetens@fmtc.be - - *************************************************************************** - * * - * This program is free software; you can redistribute it and/or modify * - * it under the terms of the GNU General Public License as published by * - * the Free Software Foundation; either version 2 of the License, or * - * (at your option) any later version. * - * * - ***************************************************************************/ - - -#ifndef GENERIC_TASK_H -#define GENERIC_TASK_H - -#include - -#include -#include - -using namespace RTT; -using namespace RTT; - -class Generic_TaskTest : public CppUnit::TestFixture -{ - CPPUNIT_TEST_SUITE( Generic_TaskTest ); - - CPPUNIT_TEST( testMethod ); - CPPUNIT_TEST( testMethodFromDS ); - CPPUNIT_TEST( testMethodFactory ); - CPPUNIT_TEST( testRemoteMethod ); - CPPUNIT_TEST( testDSMethod ); - CPPUNIT_TEST( testCRMethod ); - CPPUNIT_TEST( testMethodsC ); - CPPUNIT_TEST( testAddMethod ); - - CPPUNIT_TEST_SUITE_END(); - - TaskContext* tc; - ActivityInterface* tsim; - TaskObject* createMethodFactory(); - - // ref/const-ref tests: - double ret; - double& m0r() { return ret; } - const double& m0cr() { return ret; } - - // test const std::string& argument for command_ds - bool comstr(const std::string& cs) { return !cs.empty(); } - - double m1r(double& a) { a = 2*a; return a; } - double m1cr(const double& a) { return a; } - - // plain argument tests: - double m0() { return -d0(); } - double m1(int i) { return -d1(i); } - double m2(int i, double d) { return -d2(i,d); } - double m3(int i, double d, bool c) { return -d3(i,d,c); } - double m4(int i, double d, bool c, std::string s) { return -d4(i,d,c,s); } - - double d0() const { return 1.0; } - double d1(int i) const { return 2.0; } - double d2(int i, double d) const { return 3.0; } - double d3(int i, double d, bool c) const { return 4.0; } - double d4(int i, double d, bool c, std::string s) const { return 5.0; } - - bool assertBool( bool ); -public: - - void setUp(); - void tearDown(); - - void testMethodsC(); - void testRemoteMethod(); - void testAddMethod(); - void testCRMethod(); - void testMethod(); - void testMethodFromDS(); - void testMethodFactory(); - void testDSMethod(); -}; - -#endif diff --git a/tests/generictask_test_2.cpp b/tests/generictask_test_2.cpp deleted file mode 100644 index 6aac1c293..000000000 --- a/tests/generictask_test_2.cpp +++ /dev/null @@ -1,773 +0,0 @@ -/*************************************************************************** - tag: Peter Soetens Mon Jun 26 13:26:02 CEST 2006 generictask_test.cpp - - generictask_test_2.cpp - description - ------------------- - begin : Mon June 26 2006 - copyright : (C) 2006 Peter Soetens - email : peter.soetens@fmtc.be - - *************************************************************************** - * * - * This program is free software; you can redistribute it and/or modify * - * it under the terms of the GNU General Public License as published by * - * the Free Software Foundation; either version 2 of the License, or * - * (at your option) any later version. * - * * - ***************************************************************************/ - - - -#include "generictask_test_2.hpp" -#include -#include -#include -#include -#include -#include - -#include -#include - -#include - -using namespace std; - -// Registers the fixture into the 'registry' -CPPUNIT_TEST_SUITE_REGISTRATION( Generic_TaskTest_2 ); - - -void -Generic_TaskTest_2::setUp() -{ - tc = new TaskContext( "root" ); - tc->addObject( this->createCommandFactory() ); - tsim = new SimulationActivity(0.001, tc->engine() ); - SimulationThread::Instance()->stop(); - cd0count = 0; - cd1count = 0; - cd2count = 0; - cd3count = 0; - cd4count = 0; -} - - -void -Generic_TaskTest_2::tearDown() -{ -// if ( tc->getPeer("programs") ) -// delete tc->getPeer("programs"); - tsim->stop(); - SimulationThread::Instance()->stop(); - delete tc; - delete tsim; -} - -bool Generic_TaskTest_2::assertBool( bool b) { - return b; -} - - -TaskObject* Generic_TaskTest_2::createCommandFactory() -{ - TaskObject* to = new TaskObject("commands"); - - to->commands()->addCommand( command("c00", &Generic_TaskTest_2::cd0, &Generic_TaskTest_2::cn0, this, tc->engine()->commands()), "c0d"); - to->commands()->addCommand( command("c10", &Generic_TaskTest_2::cd1, &Generic_TaskTest_2::cn0, this, tc->engine()->commands()), "c1d","a","ad"); - to->commands()->addCommand( command("c11", &Generic_TaskTest_2::cd1, &Generic_TaskTest_2::cn1, this, tc->engine()->commands()), "c1d","a","ad"); - to->commands()->addCommand( command("c20", &Generic_TaskTest_2::cd2, &Generic_TaskTest_2::cn0, this, tc->engine()->commands()), "c2d","a","ad","a","ad"); - to->commands()->addCommand( command("c21", &Generic_TaskTest_2::cd2, &Generic_TaskTest_2::cn1, this, tc->engine()->commands()), "c2d","a","ad","a","ad"); - to->commands()->addCommand( command("c22", &Generic_TaskTest_2::cd2, &Generic_TaskTest_2::cn2, this, tc->engine()->commands()), "c2d","a","ad","a","ad"); - to->commands()->addCommand( command("c30", &Generic_TaskTest_2::cd3, &Generic_TaskTest_2::cn0, this, tc->engine()->commands()), "c3d","a","ad","a","ad","a","ad"); - to->commands()->addCommand( command("c31", &Generic_TaskTest_2::cd3, &Generic_TaskTest_2::cn1, this, tc->engine()->commands()), "c3d","a","ad","a","ad","a","ad"); - to->commands()->addCommand( command("c33", &Generic_TaskTest_2::cd3, &Generic_TaskTest_2::cn3, this, tc->engine()->commands()), "c3d","a","ad","a","ad","a","ad"); - to->commands()->addCommand( command("c40", &Generic_TaskTest_2::cd4, &Generic_TaskTest_2::cn0, this, tc->engine()->commands()), "c4d","a","ad","a","ad","a","ad","a","ad"); - to->commands()->addCommand( command("c41", &Generic_TaskTest_2::cd4, &Generic_TaskTest_2::cn1, this, tc->engine()->commands()), "c4d","a","ad","a","ad","a","ad","a","ad"); - to->commands()->addCommand( command("c44", &Generic_TaskTest_2::cd4, &Generic_TaskTest_2::cn4, this, tc->engine()->commands()), "c4d","a","ad","a","ad","a","ad","a","ad"); - return to; -} - -struct Sender: public TaskContext -{ - Command com0; - Command com1; - int com0count,com1count; - TaskContext* mrecv; - - Sender(TaskContext* receiver) - : TaskContext("Sender"), - com0count(0), - com1count(0) - { - mrecv = receiver; - com0 = mrecv->getObject("commands")->commands()->getCommand("c00"); - com1 = mrecv->getObject("commands")->commands()->getCommand("c11"); - CPPUNIT_ASSERT(com0.ready()); - CPPUNIT_ASSERT(com1.ready()); - } - - void updateHook() { - //CPPUNIT_ASSERT(com0.ready()); - //CPPUNIT_ASSERT( com0() ); - if (com0()) - com0count++; - //this->stop(); - } -}; - -void Generic_TaskTest_2::testCommandThreading() -{ - tsim->run(0); - Sender scomp ( tc ); // tc is receiver. - - new NonPeriodicActivity(ORO_SCHED_RT, 1, tc->engine() ); - new PeriodicActivity(ORO_SCHED_OTHER, 0, 0.1, scomp.engine()); - CPPUNIT_ASSERT( tc->start() ); - CPPUNIT_ASSERT( scomp.start() ); - //while(1) - sleep(1); - CPPUNIT_ASSERT( scomp.stop() ); - CPPUNIT_ASSERT( tc->stop() ); - CPPUNIT_ASSERT_EQUAL(scomp.com0count, cd0count); - CPPUNIT_ASSERT_EQUAL(scomp.com1count, cd1count); - delete tc->engine()->getActivity(); - delete scomp.engine()->getActivity(); -} - -void Generic_TaskTest_2::testCommandsC() -{ - CommandC cc = tc->getObject("commands")->commands()->create("c00"); - CommandC c20 = tc->getObject("commands")->commands()->create("c20").argC(1).argC(1.0); - CommandC c32 = tc->getObject("commands")->commands()->create("c31").argC(1).argC(1.0).argC('a'); - CommandC c33 = tc->getObject("commands")->commands()->create("c33").argC(1).argC(1.0).argC('a'); - CommandC c44 = tc->getObject("commands")->commands()->create("c44").argC(1).argC(1.0).argC('a').argC(true); - - // CASE 1 : Send command to not running task. - CPPUNIT_ASSERT( cc.ready() ); - CPPUNIT_ASSERT( c20.ready() ); - CPPUNIT_ASSERT( c32.ready() ); - CPPUNIT_ASSERT( c33.ready() ); - CPPUNIT_ASSERT( c44.ready() ); - CPPUNIT_ASSERT( !cc.sent() ); - CPPUNIT_ASSERT( !c20.sent() ); - CPPUNIT_ASSERT( !c32.sent() ); - CPPUNIT_ASSERT( !c33.sent() ); - CPPUNIT_ASSERT( !c44.sent() ); - CPPUNIT_ASSERT( !cc.executed() ); - CPPUNIT_ASSERT( !c20.executed() ); - CPPUNIT_ASSERT( !c32.executed() ); - CPPUNIT_ASSERT( !c33.executed() ); - CPPUNIT_ASSERT( !c44.executed() ); - CPPUNIT_ASSERT( !cc.accepted() ); - CPPUNIT_ASSERT( !c20.accepted() ); - CPPUNIT_ASSERT( !c32.accepted() ); - CPPUNIT_ASSERT( !c33.accepted() ); - CPPUNIT_ASSERT( !c44.accepted() ); - CPPUNIT_ASSERT( !cc.valid() ); - CPPUNIT_ASSERT( !c20.valid() ); - CPPUNIT_ASSERT( !c32.valid() ); - CPPUNIT_ASSERT( !c33.valid() ); - CPPUNIT_ASSERT( !c44.valid() ); - CPPUNIT_ASSERT( !cc.done() ); - CPPUNIT_ASSERT( !c20.done() ); - CPPUNIT_ASSERT( !c32.done() ); - CPPUNIT_ASSERT( !c33.done() ); - CPPUNIT_ASSERT( !c44.done() ); - CPPUNIT_ASSERT( !cc.execute() ); - CPPUNIT_ASSERT( !c20.execute() ); - CPPUNIT_ASSERT( !c32.execute() ); - CPPUNIT_ASSERT( !c33.execute() ); - CPPUNIT_ASSERT( !c44.execute() ); - CPPUNIT_ASSERT( cc.sent() ); - CPPUNIT_ASSERT( c20.sent() ); - CPPUNIT_ASSERT( c32.sent() ); - CPPUNIT_ASSERT( c33.sent() ); - CPPUNIT_ASSERT( c44.sent() ); - CPPUNIT_ASSERT( !cc.accepted() ); - CPPUNIT_ASSERT( !c20.accepted() ); - CPPUNIT_ASSERT( !c32.accepted() ); - CPPUNIT_ASSERT( !c33.accepted() ); - CPPUNIT_ASSERT( !c44.accepted() ); - CPPUNIT_ASSERT( !cc.executed() ); - CPPUNIT_ASSERT( !c20.executed() ); - CPPUNIT_ASSERT( !c32.executed() ); - CPPUNIT_ASSERT( !c33.executed() ); - CPPUNIT_ASSERT( !c44.executed() ); - CPPUNIT_ASSERT( !cc.valid() ); - CPPUNIT_ASSERT( !c20.valid() ); - CPPUNIT_ASSERT( !c32.valid() ); - CPPUNIT_ASSERT( !c33.valid() ); - CPPUNIT_ASSERT( !c44.valid() ); - CPPUNIT_ASSERT( !cc.done() ); - CPPUNIT_ASSERT( !c20.done() ); - CPPUNIT_ASSERT( !c32.done() ); - CPPUNIT_ASSERT( !c33.done() ); - CPPUNIT_ASSERT( !c44.done() ); - - // Test Reset: - cc.reset(); - c20.reset(); - c32.reset(); - c33.reset(); - c44.reset(); - CPPUNIT_ASSERT( cc.ready() ); - CPPUNIT_ASSERT( c20.ready() ); - CPPUNIT_ASSERT( c32.ready() ); - CPPUNIT_ASSERT( c33.ready() ); - CPPUNIT_ASSERT( c44.ready() ); - CPPUNIT_ASSERT( !cc.sent() ); - CPPUNIT_ASSERT( !c20.sent() ); - CPPUNIT_ASSERT( !c32.sent() ); - CPPUNIT_ASSERT( !c33.sent() ); - CPPUNIT_ASSERT( !c44.sent() ); - CPPUNIT_ASSERT( !cc.accepted() ); - CPPUNIT_ASSERT( !c20.accepted() ); - CPPUNIT_ASSERT( !c32.accepted() ); - CPPUNIT_ASSERT( !c33.accepted() ); - CPPUNIT_ASSERT( !c44.accepted() ); - CPPUNIT_ASSERT( !cc.executed() ); - CPPUNIT_ASSERT( !c20.executed() ); - CPPUNIT_ASSERT( !c32.executed() ); - CPPUNIT_ASSERT( !c33.executed() ); - CPPUNIT_ASSERT( !c44.executed() ); - CPPUNIT_ASSERT( !cc.valid() ); - CPPUNIT_ASSERT( !c20.valid() ); - CPPUNIT_ASSERT( !c32.valid() ); - CPPUNIT_ASSERT( !c33.valid() ); - CPPUNIT_ASSERT( !c44.valid() ); - CPPUNIT_ASSERT( !cc.done() ); - CPPUNIT_ASSERT( !c20.done() ); - CPPUNIT_ASSERT( !c32.done() ); - CPPUNIT_ASSERT( !c33.done() ); - CPPUNIT_ASSERT( !c44.done() ); - - // CASE 2 send command to running task - CPPUNIT_ASSERT( tsim->start() ); - - // freezed sim thread - CPPUNIT_ASSERT( cc.execute() ); - CPPUNIT_ASSERT( c20.execute() ); - CPPUNIT_ASSERT( c32.execute() ); - CPPUNIT_ASSERT( c33.execute() ); - CPPUNIT_ASSERT( c44.execute() ); - CPPUNIT_ASSERT( cc.sent() ); - CPPUNIT_ASSERT( c20.sent() ); - CPPUNIT_ASSERT( c32.sent() ); - CPPUNIT_ASSERT( c33.sent() ); - CPPUNIT_ASSERT( c44.sent() ); - CPPUNIT_ASSERT( cc.accepted() ); - CPPUNIT_ASSERT( c20.accepted() ); - CPPUNIT_ASSERT( c32.accepted() ); - CPPUNIT_ASSERT( c33.accepted() ); - CPPUNIT_ASSERT( c44.accepted() ); - CPPUNIT_ASSERT( !cc.executed() ); - CPPUNIT_ASSERT( !c20.executed() ); - CPPUNIT_ASSERT( !c32.executed() ); - CPPUNIT_ASSERT( !c33.executed() ); - CPPUNIT_ASSERT( !c44.executed() ); - CPPUNIT_ASSERT( !cc.valid() ); - CPPUNIT_ASSERT( !c20.valid() ); - CPPUNIT_ASSERT( !c32.valid() ); - CPPUNIT_ASSERT( !c33.valid() ); - CPPUNIT_ASSERT( !c44.valid() ); - CPPUNIT_ASSERT( !cc.done() ); - CPPUNIT_ASSERT( !c20.done() ); - CPPUNIT_ASSERT( !c32.done() ); - CPPUNIT_ASSERT( !c33.done() ); - CPPUNIT_ASSERT( !c44.done() ); - tc->engine()->step(); - tc->engine()->step(); - tc->engine()->step(); - tc->engine()->step(); - tc->engine()->step(); - CPPUNIT_ASSERT( cc.executed() ); - CPPUNIT_ASSERT( c20.executed() ); - CPPUNIT_ASSERT( c32.executed() ); - CPPUNIT_ASSERT( c33.executed() ); - CPPUNIT_ASSERT( c44.executed() ); - CPPUNIT_ASSERT( cc.valid() ); - CPPUNIT_ASSERT( c20.valid() ); - CPPUNIT_ASSERT( c32.valid() ); - CPPUNIT_ASSERT( c33.valid() ); - CPPUNIT_ASSERT( c44.valid() ); - CPPUNIT_ASSERT( cc.done() ); - CPPUNIT_ASSERT( c20.done() ); - CPPUNIT_ASSERT( c32.done() ); - CPPUNIT_ASSERT( c33.done() ); - CPPUNIT_ASSERT( c44.done() ); - tsim->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" - +" do commands.c44(1, 1.0, 'a', true)\n" - +"}"; -#endif -} - -void Generic_TaskTest_2::verifydispatch(DispatchInterface& com) -{ - CPPUNIT_ASSERT( com.sent() ); - CPPUNIT_ASSERT( com.accepted() ); - CPPUNIT_ASSERT( !com.executed() ); - CPPUNIT_ASSERT( !com.valid() ); - CPPUNIT_ASSERT( !com.done() ); - CPPUNIT_ASSERT( SimulationThread::Instance()->run(1) ); - CPPUNIT_ASSERT( com.executed() ); - CPPUNIT_ASSERT( com.valid() ); - CPPUNIT_ASSERT( com.done() ); - com.reset(); - CPPUNIT_ASSERT( !com.sent() ); - CPPUNIT_ASSERT( !com.accepted() ); - CPPUNIT_ASSERT( !com.executed() ); - CPPUNIT_ASSERT( !com.valid() ); - CPPUNIT_ASSERT( !com.done() ); -} - -void Generic_TaskTest_2::verifycommand(CommandC& com) -{ - CPPUNIT_ASSERT( com.execute() ); - CPPUNIT_ASSERT( com.sent() ); - CPPUNIT_ASSERT( com.accepted() ); - CPPUNIT_ASSERT( !com.executed() ); - CPPUNIT_ASSERT( !com.valid() ); - CPPUNIT_ASSERT( !com.done() ); - CPPUNIT_ASSERT( SimulationThread::Instance()->run(1) ); - CPPUNIT_ASSERT( com.executed() ); - CPPUNIT_ASSERT( com.valid() ); - CPPUNIT_ASSERT( com.done() ); - com.reset(); - CPPUNIT_ASSERT( !com.sent() ); - CPPUNIT_ASSERT( !com.accepted() ); - CPPUNIT_ASSERT( !com.executed() ); - CPPUNIT_ASSERT( !com.valid() ); - CPPUNIT_ASSERT( !com.done() ); -} - -void Generic_TaskTest_2::testRemoteCommand() -{ - Command com0; - Command com11; - - com0 = new detail::RemoteCommand(tc->getObject("commands")->commands(), "c00"); - com11 = new detail::RemoteCommand(tc->getObject("commands")->commands(), "c11"); - - CPPUNIT_ASSERT( com0.ready() ); - com0(); // execute - - CPPUNIT_ASSERT( com0.ready() ); - com11(1); // execute - -} - -void Generic_TaskTest_2::testCommand() -{ - Command com0("command", &Generic_TaskTest_2::cd0, &Generic_TaskTest_2::cn0, this, tc->engine()->commands() ); - Command com11("command", &Generic_TaskTest_2::cd1, &Generic_TaskTest_2::cn1, this, tc->engine()->commands() ); - Command com10("command", &Generic_TaskTest_2::cd1, &Generic_TaskTest_2::cn0, this, tc->engine()->commands() ); - - Command com22("command", &Generic_TaskTest_2::cd2, &Generic_TaskTest_2::cn2, this, tc->engine()->commands() ); - Command com20("command", &Generic_TaskTest_2::cd2, &Generic_TaskTest_2::cn0, this, tc->engine()->commands() ); - Command com21("command", &Generic_TaskTest_2::cd2, &Generic_TaskTest_2::cn1, this, tc->engine()->commands() ); - - Command com33("command", &Generic_TaskTest_2::cd3, &Generic_TaskTest_2::cn3, this, tc->engine()->commands() ); - Command com30("command", &Generic_TaskTest_2::cd3, &Generic_TaskTest_2::cn0, this, tc->engine()->commands() ); - Command com31("command", &Generic_TaskTest_2::cd3, &Generic_TaskTest_2::cn1, this, tc->engine()->commands() ); - - Command com44("command", &Generic_TaskTest_2::cd4, &Generic_TaskTest_2::cn4, this, tc->engine()->commands() ); - Command com40("command", &Generic_TaskTest_2::cd4, &Generic_TaskTest_2::cn0, this, tc->engine()->commands() ); - Command com41("command", &Generic_TaskTest_2::cd4, &Generic_TaskTest_2::cn1, this, tc->engine()->commands() ); - - // start the activity, such that commands are accepted. - CPPUNIT_ASSERT( tsim->start()) ; - // execute commands and check status: - CPPUNIT_ASSERT( com0() ); - verifydispatch(*com0.getCommandImpl()); - - CPPUNIT_ASSERT( com11(1) ); - verifydispatch(*com11.getCommandImpl()); - CPPUNIT_ASSERT( com10(1) ); - verifydispatch(*com10.getCommandImpl()); - - CPPUNIT_ASSERT( com22(1, 1.0) ); - verifydispatch(*com22.getCommandImpl()); - CPPUNIT_ASSERT( com20(1, 1.0) ); - verifydispatch(*com20.getCommandImpl()); - CPPUNIT_ASSERT( com21(1, 1.0) ); - verifydispatch(*com21.getCommandImpl()); - - CPPUNIT_ASSERT( com33(1, 1.0, char('a') ) ); - verifydispatch(*com33.getCommandImpl()); - CPPUNIT_ASSERT( com30(1, 1.0, char('a') ) ); - verifydispatch(*com30.getCommandImpl()); - CPPUNIT_ASSERT( com31(1, 1.0, char('a') ) ); - verifydispatch(*com31.getCommandImpl()); - - CPPUNIT_ASSERT( com44(1, 1.0, char('a'),true) ); - verifydispatch(*com44.getCommandImpl()); - CPPUNIT_ASSERT( com40(1, 1.0, char('a'),true) ); - verifydispatch(*com40.getCommandImpl()); - CPPUNIT_ASSERT( com41(1, 1.0, char('a'),true) ); - verifydispatch(*com41.getCommandImpl()); - - CPPUNIT_ASSERT( tsim->stop() ); -} - -void Generic_TaskTest_2::testCommandProcessor() -{ - Command com0("command", &Generic_TaskTest_2::cd0, &Generic_TaskTest_2::cn0, this, tc->engine()->commands() ); - Command com11("command", &Generic_TaskTest_2::cd1, &Generic_TaskTest_2::cn1, this, tc->engine()->commands() ); - Command com10("command", &Generic_TaskTest_2::cd1, &Generic_TaskTest_2::cn0, this, tc->engine()->commands() ); - - // start the activity, such that commands are accepted. - CPPUNIT_ASSERT( tsim->start()) ; - // execute commands and check status: - CPPUNIT_ASSERT( com0() ); - CPPUNIT_ASSERT( com11(1) ); - CPPUNIT_ASSERT( com10(1) ); - - CPPUNIT_ASSERT( com0.sent() ); - CPPUNIT_ASSERT( com0.accepted() ); - CPPUNIT_ASSERT( com11.sent() ); - CPPUNIT_ASSERT( com11.accepted() ); - CPPUNIT_ASSERT( com10.sent() ); - CPPUNIT_ASSERT( com10.accepted() ); - - CPPUNIT_ASSERT( !com0.executed() ); - CPPUNIT_ASSERT( !com0.valid() ); - CPPUNIT_ASSERT( !com0.done() ); - CPPUNIT_ASSERT( !com11.executed() ); - CPPUNIT_ASSERT( !com11.valid() ); - CPPUNIT_ASSERT( !com11.done() ); - CPPUNIT_ASSERT( !com10.executed() ); - CPPUNIT_ASSERT( !com10.valid() ); - CPPUNIT_ASSERT( !com10.done() ); - - // This executes all queued commands. - CPPUNIT_ASSERT( SimulationThread::Instance()->run(1) ); - - CPPUNIT_ASSERT( com0.executed() ); - CPPUNIT_ASSERT( com0.valid() ); - CPPUNIT_ASSERT( com0.done() ); - CPPUNIT_ASSERT( com11.executed() ); - CPPUNIT_ASSERT( com11.valid() ); - CPPUNIT_ASSERT( com11.done() ); - CPPUNIT_ASSERT( com10.executed() ); - CPPUNIT_ASSERT( com10.valid() ); - CPPUNIT_ASSERT( com10.done() ); - - CPPUNIT_ASSERT( tsim->stop() ); -} - -void Generic_TaskTest_2::testCommandFactory() -{ - // Test the addition of 'simple' commands to the operation interface, - // and retrieving it back in a new Command object. - - Command com0("c0", &Generic_TaskTest_2::cd0, &Generic_TaskTest_2::cn0, this, tc->engine()->commands() ); - Command com11("c11", &Generic_TaskTest_2::cd1, &Generic_TaskTest_2::cn1, this, tc->engine()->commands() ); - Command com10("c10", &Generic_TaskTest_2::cd1, &Generic_TaskTest_2::cn0, this, tc->engine()->commands() ); - - TaskObject to("task"); - - CPPUNIT_ASSERT( to.commands()->addCommand(&com0) ); - CPPUNIT_ASSERT( ! to.commands()->addCommand(&com0) ); - CPPUNIT_ASSERT( to.commands()->addCommand(&com11) ); - CPPUNIT_ASSERT( to.commands()->addCommand(&com10) ); - - // test constructor - Command rc0 = to.commands()->getCommand("c0"); - CPPUNIT_ASSERT( rc0.getCommandImpl() ); - CPPUNIT_ASSERT( rc0.ready() ); - - // test operator=() - Command rc11; - rc11 = to.commands()->getCommand("c11"); - CPPUNIT_ASSERT( rc11.getCommandImpl() ); - CPPUNIT_ASSERT( rc11.ready() ); - - Command rc10 = to.commands()->getCommand("c10"); - CPPUNIT_ASSERT( rc10.getCommandImpl() ); - CPPUNIT_ASSERT( rc10.ready() ); - - // start the activity, such that commands are accepted. - CPPUNIT_ASSERT( tsim->start()) ; - // execute commands and check status: - CPPUNIT_ASSERT( com0() ); - verifydispatch(*com0.getCommandImpl()); - - CPPUNIT_ASSERT( com11(1) ); - verifydispatch(*com11.getCommandImpl()); - - CPPUNIT_ASSERT( com10(1) ); - verifydispatch(*com10.getCommandImpl()); - - // test error cases: - // Add uninitialised command: - Command cvoid; - CPPUNIT_ASSERT(to.commands()->addCommand( &cvoid ) == false); - cvoid = Command("voidc"); - CPPUNIT_ASSERT(to.commands()->addCommand( &cvoid ) == false); - - // wrong type: - cvoid = to.commands()->getCommand("c0"); - CPPUNIT_ASSERT( cvoid.ready() == false ); - // wrong type 2: - cvoid = to.commands()->getCommand("c11"); - CPPUNIT_ASSERT( cvoid.ready() == false ); - // wrong type 3: - cvoid = to.commands()->getCommand("c11"); - CPPUNIT_ASSERT( cvoid.ready() == false ); - // not existing: - cvoid = to.commands()->getCommand("voidm"); - CPPUNIT_ASSERT( cvoid.ready() == false ); - - cvoid.reset(); - CPPUNIT_ASSERT( cvoid() == false); - CPPUNIT_ASSERT( cvoid.accepted() == false); - CPPUNIT_ASSERT( cvoid.executed() == false); - CPPUNIT_ASSERT( cvoid.sent() == false); - CPPUNIT_ASSERT( cvoid.valid() == false); - CPPUNIT_ASSERT( cvoid.done() == false); - -} - -void Generic_TaskTest_2::testCommandFromDS() -{ - Command com0("c0", &Generic_TaskTest_2::cd0, &Generic_TaskTest_2::cn0, this, tc->engine()->commands() ); - Command com11("c11", &Generic_TaskTest_2::cd1, &Generic_TaskTest_2::cn1, this, tc->engine()->commands() ); - Command com10("c10", &Generic_TaskTest_2::cd1, &Generic_TaskTest_2::cn0, this, tc->engine()->commands() ); - Command com22("c22", &Generic_TaskTest_2::cd2, &Generic_TaskTest_2::cn2, this, tc->engine()->commands() ); - Command com20("c20", &Generic_TaskTest_2::cd2, &Generic_TaskTest_2::cn0, this, tc->engine()->commands() ); - Command com21("c21", &Generic_TaskTest_2::cd2, &Generic_TaskTest_2::cn1, this, tc->engine()->commands() ); - - Command com33("c33", &Generic_TaskTest_2::cd3, &Generic_TaskTest_2::cn3, this, tc->engine()->commands() ); - Command com30("c30", &Generic_TaskTest_2::cd3, &Generic_TaskTest_2::cn0, this, tc->engine()->commands() ); - Command com31("c31", &Generic_TaskTest_2::cd3, &Generic_TaskTest_2::cn1, this, tc->engine()->commands() ); - - Command com44("c44", &Generic_TaskTest_2::cd4, &Generic_TaskTest_2::cn4, this, tc->engine()->commands() ); - Command com40("c40", &Generic_TaskTest_2::cd4, &Generic_TaskTest_2::cn0, this, tc->engine()->commands() ); - Command com41("c41", &Generic_TaskTest_2::cd4, &Generic_TaskTest_2::cn1, this, tc->engine()->commands() ); - - TaskObject to("task"); - - CPPUNIT_ASSERT( to.commands()->addCommand( &com0, "desc" ) ); - CPPUNIT_ASSERT( ! to.commands()->addCommand( &com0, "desc" ) ); - - CPPUNIT_ASSERT( to.commands()->addCommand( &com11, "desc","a1", "d1" ) ); - CPPUNIT_ASSERT( ! to.commands()->addCommand( &com11, "desc","a1", "d1" ) ); - CPPUNIT_ASSERT( to.commands()->addCommand( &com10, "desc","a1", "d1" ) ); - - CPPUNIT_ASSERT( to.commands()->addCommand( &com22, "desc","a1", "d1","a2","d2" ) ); - CPPUNIT_ASSERT( ! to.commands()->addCommand( &com22, "desc","a1", "d1","a2","d2" ) ); - CPPUNIT_ASSERT( to.commands()->addCommand( &com20, "desc","a1", "d1","a2","d2" ) ); - CPPUNIT_ASSERT( to.commands()->addCommand( &com21, "desc","a1", "d1","a2","d2" ) ); - - CPPUNIT_ASSERT( to.commands()->addCommand( &com33, "desc","a1", "d1","a2","d2","a3","d3" ) ); - CPPUNIT_ASSERT( ! to.commands()->addCommand( &com33, "desc","a1", "d1","a2","d2","a3","d3" ) ); - CPPUNIT_ASSERT( to.commands()->addCommand( &com30, "desc","a1", "d1","a2","d2","a3","d3" ) ); - CPPUNIT_ASSERT( to.commands()->addCommand( &com31, "desc","a1", "d1","a2","d2","a3","d3" ) ); - - CPPUNIT_ASSERT( to.commands()->addCommand( &com44, "desc","a1", "d1","a2","d2","a3","d3","a4","d4" ) ); - CPPUNIT_ASSERT( ! to.commands()->addCommand( &com44, "desc","a1", "d1","a2","d2","a3","d3","a4","d4" ) ); - CPPUNIT_ASSERT( to.commands()->addCommand( &com40, "desc","a1", "d1","a2","d2","a3","d3","a4","d4" ) ); - CPPUNIT_ASSERT( to.commands()->addCommand( &com41, "desc","a1", "d1","a2","d2","a3","d3","a4","d4" ) ); - - - std::vector args; - CommandC c0 = to.commands()->create("c0"); - CommandC c10 = to.commands()->create("c10").argC(1); - CommandC c11 = to.commands()->create("c11").argC(1); - CommandC c20 = to.commands()->create("c20").argC(1).argC(1.0); - CommandC c21 = to.commands()->create("c21").argC(1).argC(1.0); - CommandC c22 = to.commands()->create("c22").argC(1).argC(1.0); - CommandC c30 = to.commands()->create("c30").argC(1).argC(1.0).argC('a'); - CommandC c31 = to.commands()->create("c31").argC(1).argC(1.0).argC('a'); - CommandC c33 = to.commands()->create("c33").argC(1).argC(1.0).argC('a'); - CommandC c40 = to.commands()->create("c40").argC(1).argC(1.0).argC('a').argC(true); - CommandC c41 = to.commands()->create("c41").argC(1).argC(1.0).argC('a').argC(true); - CommandC c44 = to.commands()->create("c44").argC(1).argC(1.0).argC('a').argC(true); - - CPPUNIT_ASSERT( tsim->start()) ; - verifycommand(c0); - verifycommand(c11); - verifycommand(c10); - verifycommand(c22); - verifycommand(c20); - verifycommand(c21); - verifycommand(c33); - verifycommand(c30); - verifycommand(c31); - verifycommand(c44); - verifycommand(c40); - verifycommand(c41); - CPPUNIT_ASSERT( tsim->stop()) ; -} - -void Generic_TaskTest_2::testDSCommand() -{ - TaskObject to("task"); - - // A command of which the first argument type is a pointer to the object - // on which it must be invoked. The pointer is internally stored as a weak_ptr, - // thus the object must be stored in a shared_ptr, in a DataSource. Scripting - // requires this for copying state machines. - - CommandDS com0("c0", - &Generic_TaskTest_2::cd0, &Generic_TaskTest_2::cn0, - tc->engine()->commands() ); - - command_ds("c0", &Generic_TaskTest_2::cd0, &Generic_TaskTest_2::cn0, tc->engine()->commands() ); - - CommandDS com1("c1", - &Generic_TaskTest_2::cd1, &Generic_TaskTest_2::cn1, - tc->engine()->commands() ); - - command_ds("c1",&Generic_TaskTest_2::cd1, &Generic_TaskTest_2::cn1, tc->engine()->commands() ); - - command_ds("cs",&Generic_TaskTest_2::comstr, &Generic_TaskTest_2::comstr, tc->engine()->commands() ); - - boost::shared_ptr ptr( new Generic_TaskTest_2() ); - ValueDataSource >::shared_ptr wp = new ValueDataSource >( ptr ); - CPPUNIT_ASSERT( to.commands()->addCommandDS( wp.get(), com0, "desc" ) ); - CPPUNIT_ASSERT( to.commands()->addCommandDS( wp.get(), com1, "desc", "a1", "d1" ) ); - - // this actually works ! the command will detect the deleted pointer. - //ptr.reset(); - - CPPUNIT_ASSERT( tsim->start()) ; - - CommandC c0 = to.commands()->create("c0"); - verifycommand(c0); - CommandC c1 = to.commands()->create("c1").argC(1); - verifycommand(c1); - - CPPUNIT_ASSERT( tsim->stop()) ; - -} - -void Generic_TaskTest_2::testCRCommand() -{ - this->ret = -3.3; - - Command ic1r("c1r", &Generic_TaskTest_2::cn1r, &Generic_TaskTest_2::cd1r, this, tc->engine()->commands() ); - Command ic1cr("c1cr", &Generic_TaskTest_2::cn1cr, &Generic_TaskTest_2::cd1cr, this, tc->engine()->commands() ); - - Command c1r = ic1r.getCommandImpl()->clone(); - Command c1cr = ic1cr.getCommandImpl()->clone(); - - CPPUNIT_ASSERT( c1r.ready() ); - CPPUNIT_ASSERT( c1cr.ready() ); - - CPPUNIT_ASSERT( tsim->start()) ; - // execute commands and check status: - CPPUNIT_ASSERT( c1cr(1.0) ); - verifydispatch(*c1cr.getCommandImpl()); - CPPUNIT_ASSERT_EQUAL( 1.0, ret ); - - this->ret = -3.3; - double result = 0.0; - CPPUNIT_ASSERT( c1r(result) ); - verifydispatch(*c1r.getCommandImpl()); - // ret == -3.3, result == -6.6 - CPPUNIT_ASSERT_EQUAL( -3.3, ret ); - CPPUNIT_ASSERT_EQUAL( ret * 2, result ); - - CPPUNIT_ASSERT( tsim->stop() ) ; -} - -void Generic_TaskTest_2::testCSCRCommand() -{ - // using a struct: - CS cs; - cs.y = 1.234; - cs.z = 0.123; - cs.x = cs.y + cs.z; - - CS cs2 = cs; - - Command ic1r("c1r", &Generic_TaskTest_2::CScn1r, &Generic_TaskTest_2::CScd1r, this, tc->engine()->commands() ); - Command ic1cr("c1cr", &Generic_TaskTest_2::CScn1cr, &Generic_TaskTest_2::CScd1cr, this, tc->engine()->commands() ); - - Command c1r = ic1r.getCommandImpl()->clone(); - Command c1cr = ic1cr.getCommandImpl()->clone(); - CPPUNIT_ASSERT( c1r.ready() ); - CPPUNIT_ASSERT( c1cr.ready() ); - - CPPUNIT_ASSERT( tsim->start()) ; - // execute commands and check status: - CPPUNIT_ASSERT( c1cr(cs) ); - verifydispatch(*c1cr.getCommandImpl()); - - CPPUNIT_ASSERT( c1r(cs2) ); - verifydispatch(*c1r.getCommandImpl()); - CPPUNIT_ASSERT_EQUAL( 2*cs2.y+2*cs2.z, cs2.x ); - - CPPUNIT_ASSERT( tsim->stop() ) ; -} - -void Generic_TaskTest_2::testAddCommand() -{ - - Command com0("c0"); - com0 = command("command", &Generic_TaskTest_2::cd0, &Generic_TaskTest_2::cn0, this, tc->engine()->commands() ); - - Command com11("c11"); - com11= command("command", &Generic_TaskTest_2::cd1, &Generic_TaskTest_2::cn1, this, tc->engine()->commands() ); - - Command com10= command("command", &Generic_TaskTest_2::cd1, &Generic_TaskTest_2::cn0, this, tc->engine()->commands() ); - - Command com22= command("command", &Generic_TaskTest_2::cd2, &Generic_TaskTest_2::cn2, this, tc->engine()->commands() ); - Command com20= command("command", &Generic_TaskTest_2::cd2, &Generic_TaskTest_2::cn0, this, tc->engine()->commands() ); - Command com21= command("command", &Generic_TaskTest_2::cd2, &Generic_TaskTest_2::cn1, this, tc->engine()->commands() ); - - Command com33= command("command", &Generic_TaskTest_2::cd3, &Generic_TaskTest_2::cn3, this, tc->engine()->commands() ); - Command com30= command("command", &Generic_TaskTest_2::cd3, &Generic_TaskTest_2::cn0, this, tc->engine()->commands() ); - Command com31= command("command", &Generic_TaskTest_2::cd3, &Generic_TaskTest_2::cn1, this, tc->engine()->commands() ); - - Command com44= command("command", &Generic_TaskTest_2::cd4, &Generic_TaskTest_2::cn4, this, tc->engine()->commands() ); - Command com40= command("command", &Generic_TaskTest_2::cd4, &Generic_TaskTest_2::cn0, this, tc->engine()->commands() ); - Command com41= command("command", &Generic_TaskTest_2::cd4, &Generic_TaskTest_2::cn1, this, tc->engine()->commands() ); - - // start the activity, such that commands are accepted. - CPPUNIT_ASSERT( tsim->start()) ; - - // execute commands and check status: - CPPUNIT_ASSERT( com0() ); - verifydispatch(*com0.getCommandImpl()); - - CPPUNIT_ASSERT( com11(1) ); - verifydispatch(*com11.getCommandImpl()); - CPPUNIT_ASSERT( com10(1) ); - verifydispatch(*com10.getCommandImpl()); - - CPPUNIT_ASSERT( com22(1, 1.0) ); - verifydispatch(*com22.getCommandImpl()); - CPPUNIT_ASSERT( com20(1, 1.0) ); - verifydispatch(*com20.getCommandImpl()); - CPPUNIT_ASSERT( com21(1, 1.0) ); - verifydispatch(*com21.getCommandImpl()); - - CPPUNIT_ASSERT( com33(1, 1.0, char('a') ) ); - verifydispatch(*com33.getCommandImpl()); - CPPUNIT_ASSERT( com30(1, 1.0, char('a') ) ); - verifydispatch(*com30.getCommandImpl()); - CPPUNIT_ASSERT( com31(1, 1.0, char('a') ) ); - verifydispatch(*com31.getCommandImpl()); - - CPPUNIT_ASSERT( com44(1, 1.0, char('a'),true) ); - verifydispatch(*com44.getCommandImpl()); - CPPUNIT_ASSERT( com40(1, 1.0, char('a'),true) ); - verifydispatch(*com40.getCommandImpl()); - CPPUNIT_ASSERT( com41(1, 1.0, char('a'),true) ); - verifydispatch(*com41.getCommandImpl()); - - CPPUNIT_ASSERT( tsim->stop() ); -} diff --git a/tests/generictask_test_2.hpp b/tests/generictask_test_2.hpp deleted file mode 100644 index 624b06bc8..000000000 --- a/tests/generictask_test_2.hpp +++ /dev/null @@ -1,113 +0,0 @@ -/*************************************************************************** - tag: Peter Soetens Mon Jun 26 13:26:02 CEST 2006 generictask_test.hpp - - generictask_test_2.hpp - description - ------------------- - begin : Mon June 26 2006 - copyright : (C) 2006 Peter Soetens - email : peter.soetens@fmtc.be - - *************************************************************************** - * * - * This program is free software; you can redistribute it and/or modify * - * it under the terms of the GNU General Public License as published by * - * the Free Software Foundation; either version 2 of the License, or * - * (at your option) any later version. * - * * - ***************************************************************************/ - - -#ifndef GENERIC_TASK_2_H -#define GENERIC_TASK_2_H - -#include - -#include -#include - -using namespace RTT; -using namespace RTT; - -class Generic_TaskTest_2 : public CppUnit::TestFixture -{ - CPPUNIT_TEST_SUITE( Generic_TaskTest_2 ); - - CPPUNIT_TEST( testCommandThreading ); - CPPUNIT_TEST( testCommand ); - CPPUNIT_TEST( testCommandProcessor ); - CPPUNIT_TEST( testRemoteCommand ); - CPPUNIT_TEST( testCommandsC ); - CPPUNIT_TEST( testCommandFromDS ); - CPPUNIT_TEST( testCommandFactory ); - CPPUNIT_TEST( testDSCommand ); - CPPUNIT_TEST( testCRCommand ); - CPPUNIT_TEST( testCSCRCommand ); - CPPUNIT_TEST( testAddCommand ); - - CPPUNIT_TEST_SUITE_END(); - - TaskContext* tc; - ActivityInterface* tsim; - TaskObject* createCommandFactory(); - - // ref/const-ref tests: - double ret; - bool cn1r(double& a) { a = ret; return true; } - bool cd1r(double& a) { a = ret * 2; return true; } - bool cn1cr(const double& a) { ret = a; return true; } - bool cd1cr(const double& a) { ret = a; return true; } - - // ref/const-ref of structs: - struct CS - { - double x,y,z; - }; - bool CScn1r(CS& a) { - CPPUNIT_ASSERT(a.x == a.y + a.z ); - a.x = 2* a.y + 2* a.z; - return true; - } - bool CScd1r(CS& a) { CPPUNIT_ASSERT(a.x == 2*a.y + 2*a.z ); return true; } - bool CScn1cr(const CS& a) { CPPUNIT_ASSERT(a.x == a.y + a.z ); return true; } - bool CScd1cr(const CS& a) { CPPUNIT_ASSERT(a.x == a.y + a.z ); return true; } - - // test const std::string& argument for command_ds - bool comstr(const std::string& cs) { return !cs.empty(); } - - int cd0count,cd1count,cd2count,cd3count,cd4count; - bool cd0() { cd0count++; return true; } - bool cd1(int i) { cd1count++; return true; } - bool cd2(int i, double d) { cd2count++; return true; } - bool cd3(int i, double d, char c) { cd3count++; return true; } - bool cd4(int i, double d, char c, bool b) { cd4count++; return true; } - bool cn0() const { return true; } - bool cn1(int i) const { CPPUNIT_ASSERT_EQUAL(1, i); return true; } - bool cn2(int i, double d) const { CPPUNIT_ASSERT_EQUAL(1, i); CPPUNIT_ASSERT_EQUAL(1.0,d); return true; } - bool cn3(int i, double d, char c) const { CPPUNIT_ASSERT_EQUAL(1, i); CPPUNIT_ASSERT_EQUAL(1.0,d); CPPUNIT_ASSERT_EQUAL('a',c); return true; } - bool cn4(int i, double d, char c, bool b) const { CPPUNIT_ASSERT_EQUAL(1, i); CPPUNIT_ASSERT_EQUAL(1.0,d); CPPUNIT_ASSERT_EQUAL('a',c); CPPUNIT_ASSERT_EQUAL(true,b);return true; } - - bool assertBool( bool ); - - void verifydispatch(DispatchInterface& com); - void verifycommand(CommandC& com); - -public: - - void setUp(); - void tearDown(); - - void testCommandThreading(); - void testAddCommand(); - void testCRCommand(); - void testCSCRCommand(); - void testCommandsC(); - void testCommand(); - void testCommandProcessor(); - void testRemoteCommand(); - void testCommandFactory(); - void testCommandFromDS(); - void testDSCommand(); - -}; - -#endif diff --git a/tests/generictask_test_3.cpp b/tests/generictask_test_3.cpp deleted file mode 100644 index 7bfdec82f..000000000 --- a/tests/generictask_test_3.cpp +++ /dev/null @@ -1,997 +0,0 @@ -/*************************************************************************** - tag: Peter Soetens Mon Jun 26 13:26:02 CEST 2006 generictask_test.cpp - - generictask_test_3.cpp - description - ------------------- - begin : Mon June 26 2006 - copyright : (C) 2006 Peter Soetens - email : peter.soetens@fmtc.be - - *************************************************************************** - * * - * This program is free software; you can redistribute it and/or modify * - * it under the terms of the GNU General Public License as published by * - * the Free Software Foundation; either version 2 of the License, or * - * (at your option) any later version. * - * * - ***************************************************************************/ - - - -#include "generictask_test_3.hpp" -#include -#include -#include "Ports.hpp" -#include "DataObjectInterfaces.hpp" -#include "BufferLocked.hpp" - -#include "SlaveActivity.hpp" -#include "SimulationActivity.hpp" -#include "SimulationThread.hpp" - -#include - -using namespace std; - -// Registers the fixture into the 'registry' -CPPUNIT_TEST_SUITE_REGISTRATION( Generic_TaskTest_3 ); - -// Test TaskContext states. -class StatesTC - : public RTT::TaskContext -{ -public: - StatesTC() - : TaskContext("TC", PreOperational) - { - this->resetFlags(); - validconfig = true; - validstart = true; - validreset = true; - validactivate = true; - do_error = false; - } - - void resetFlags() - { - didconfig = false; - didstart = false; - didstop = false; - didcleanup = false; - didupdate = false; - didreset = false; - didactivate = false; - } - - bool configureHook() { - CPPUNIT_ASSERT( mTaskState <= Stopped ); - didconfig = true; - return validconfig; - } - - bool startHook() { - CPPUNIT_ASSERT( mTaskState == Stopped || mTaskState == Active); - didstart = true; - return validstart; - } - - void stopHook() { - CPPUNIT_ASSERT( mTaskState >= Running || mTaskState == Active || mTaskState == FatalError); - didstop = true; - } - - void cleanupHook() { - CPPUNIT_ASSERT( mTaskState == Stopped ); - didcleanup = true; - } - - void updateHook() { - CPPUNIT_ASSERT( mTaskState == Running ); - didupdate = true; - if (do_error) - this->fatal(); - } - - bool resetHook() { - didreset = true; - return validreset; - } - - bool activateHook() { - didactivate = true; - return validactivate; - } - - bool validconfig, didconfig; - bool validstart, didstart; - bool didstop; - bool didcleanup; - bool didupdate; - bool validreset, didreset, didactivate, validactivate; - bool do_error; -}; - -class EventPortsTC : public TaskContext -{ -public: - bool had_event; - int nb_events; - EventPortsTC(): TaskContext("eptc") { resetStats(); } - void updateHook(std::vector const& updated_ports) - { - nb_events += updated_ports.size(); - had_event = true; - } - void resetStats() { - nb_events = 0; - had_event = false; - } -}; - -void -Generic_TaskTest_3::setUp() -{ - tc = new TaskContext( "root", TaskContext::Stopped ); - tce = new EventPortsTC(); - tc2 = new EventPortsTC(); - stc = new StatesTC(); - tsim = new SimulationActivity(0.001, tc->engine() ); - stsim = new SimulationActivity(0.001, stc->engine() ); - SimulationThread::Instance()->stop(); -} - - -void -Generic_TaskTest_3::tearDown() -{ -// if ( tc->getPeer("programs") ) -// delete tc->getPeer("programs"); - tsim->stop(); - stsim->stop(); - delete tc; - delete tsim; - delete stc; - delete stsim; -} - -void Generic_TaskTest_3::testPeriod() -{ - // check unconfigured TC - TaskContext pertc("PerTC"); - CPPUNIT_ASSERT( pertc.getPeriod() == 0.0 ); - - // check periodic TC - SlaveActivity sa(1.0, pertc.engine()); - CPPUNIT_ASSERT( sa.getPeriod() == 1.0 ); - CPPUNIT_ASSERT( pertc.getPeriod() == 1.0 ); - - // check non periodic TC - SlaveActivity sb(0.0, pertc.engine()); - CPPUNIT_ASSERT( sb.getPeriod() == 0.0 ); - CPPUNIT_ASSERT( pertc.getPeriod() == 0.0 ); - -} -void Generic_TaskTest_3::testTCStates() -{ - // Test the states of a Default TC, no user methods. - CPPUNIT_ASSERT( tc->getTaskState() == TaskContext::Stopped ); - - // Configure in Stop - CPPUNIT_ASSERT( tc->isConfigured() == true ); - CPPUNIT_ASSERT( tc->isRunning() == false ); - CPPUNIT_ASSERT( tc->isActive() == false ); - CPPUNIT_ASSERT( tc->configure() == true ); - CPPUNIT_ASSERT( tc->resetError() == false ); - - // Stop to Running - CPPUNIT_ASSERT( tc->start() == true ); - CPPUNIT_ASSERT( tc->isRunning() == true ); - CPPUNIT_ASSERT( tc->isActive() == true ); - CPPUNIT_ASSERT( tc->configure() == false ); - CPPUNIT_ASSERT( tc->start() == false ); - CPPUNIT_ASSERT( tc->cleanup() == false ); - CPPUNIT_ASSERT( tc->resetError() == false ); - - // Running to Stop - CPPUNIT_ASSERT( tc->stop() == true ); - CPPUNIT_ASSERT( tc->isRunning() == false); - CPPUNIT_ASSERT( tc->isActive() == false ); - CPPUNIT_ASSERT( tc->stop() == false ); - CPPUNIT_ASSERT( tc->configure() == true ); - CPPUNIT_ASSERT( tc->isConfigured() == true ); - - // Stop to Active to Stop - CPPUNIT_ASSERT( tc->activate() == true ); - CPPUNIT_ASSERT( tc->isActive() == true); - CPPUNIT_ASSERT( tc->isRunning() == false ); - CPPUNIT_ASSERT( tc->configure() == false ); - CPPUNIT_ASSERT( tc->resetError() == false ); - CPPUNIT_ASSERT( tc->stop() == true ); - CPPUNIT_ASSERT( tc->isConfigured() == true ); - - // Stop to Active to Running to Stop - CPPUNIT_ASSERT( tc->activate() == true ); - CPPUNIT_ASSERT( tc->start() == true ); - CPPUNIT_ASSERT( tc->isRunning() == true ); - CPPUNIT_ASSERT( tc->isActive() == true ); - CPPUNIT_ASSERT( tc->configure() == false ); - CPPUNIT_ASSERT( tc->start() == false ); - CPPUNIT_ASSERT( tc->cleanup() == false ); - CPPUNIT_ASSERT( tc->resetError() == false ); - CPPUNIT_ASSERT( tc->stop() == true ); - CPPUNIT_ASSERT( tc->isConfigured() == true ); - - // Stop to PreOp - CPPUNIT_ASSERT( tc->cleanup() == true ); - CPPUNIT_ASSERT( tc->isConfigured() == false); - CPPUNIT_ASSERT( tc->isRunning() == false); - - // PreOp to stop - CPPUNIT_ASSERT( tc->configure() == true ); - CPPUNIT_ASSERT( tc->isConfigured() == true); - CPPUNIT_ASSERT( tc->isRunning() == false); - CPPUNIT_ASSERT( tc->isActive() == false ); - -} - -void Generic_TaskTest_3::testSpecialTCStates() -{ - // Test the states of a Specially crafted TC, requiring configure etc. - CPPUNIT_ASSERT( stc->getTaskState() == TaskContext::PreOperational ); - - // PreOperational state: - CPPUNIT_ASSERT( stc->isConfigured() == false ); - CPPUNIT_ASSERT( stc->isRunning() == false ); - CPPUNIT_ASSERT( stc->configure() == true ); - CPPUNIT_ASSERT( stc->didconfig == true ); - CPPUNIT_ASSERT( stc->isConfigured() == true ); - // test flags - CPPUNIT_ASSERT( stc->didstart == false ); - CPPUNIT_ASSERT( stc->didupdate == false ); - CPPUNIT_ASSERT( stc->didstop == false ); - CPPUNIT_ASSERT( stc->didcleanup == false ); - CPPUNIT_ASSERT( stc->didactivate == false ); - stc->resetFlags(); - - // Stopped state: - CPPUNIT_ASSERT( stc->start() == true ); - CPPUNIT_ASSERT( stc->didstart == true ); - stc->resetFlags(); - CPPUNIT_ASSERT( stc->isRunning() == true ); - CPPUNIT_ASSERT( stc->configure() == false ); - CPPUNIT_ASSERT( stc->start() == false ); - CPPUNIT_ASSERT( stc->cleanup() == false ); - // test flags - CPPUNIT_ASSERT( stc->didconfig == false ); - CPPUNIT_ASSERT( stc->didstart == false ); - CPPUNIT_ASSERT( stc->didupdate == false ); - CPPUNIT_ASSERT( stc->didstop == false ); - CPPUNIT_ASSERT( stc->didcleanup == false ); - CPPUNIT_ASSERT( stc->didactivate == false ); - stc->resetFlags(); - - - // Running state / updateHook : - SimulationThread::Instance()->run(1); - // test flags - CPPUNIT_ASSERT( stc->didconfig == false ); - CPPUNIT_ASSERT( stc->didstart == false ); - CPPUNIT_ASSERT( stc->didupdate == true ); - CPPUNIT_ASSERT( stc->didstop == false ); - CPPUNIT_ASSERT( stc->didcleanup == false ); - CPPUNIT_ASSERT( stc->didactivate == false ); - stc->resetFlags(); - - // Back to stopped - CPPUNIT_ASSERT( stc->stop() == true ); - CPPUNIT_ASSERT( stc->didstop == true ); - // test flags - CPPUNIT_ASSERT( stc->didconfig == false ); - CPPUNIT_ASSERT( stc->didstart == false ); - CPPUNIT_ASSERT( stc->didupdate == false ); - CPPUNIT_ASSERT( stc->didstop == true ); - CPPUNIT_ASSERT( stc->didcleanup == false ); - CPPUNIT_ASSERT( stc->didactivate == false ); - stc->resetFlags(); - - CPPUNIT_ASSERT( stc->isRunning() == false); - CPPUNIT_ASSERT( stc->stop() == false ); - CPPUNIT_ASSERT( stc->configure() == true ); - CPPUNIT_ASSERT( stc->isConfigured() == true ); - // test flags - CPPUNIT_ASSERT( stc->didconfig == true ); - CPPUNIT_ASSERT( stc->didstart == false ); - CPPUNIT_ASSERT( stc->didupdate == false ); - CPPUNIT_ASSERT( stc->didstop == false ); - CPPUNIT_ASSERT( stc->didcleanup == false ); - CPPUNIT_ASSERT( stc->didactivate == false ); - stc->resetFlags(); - - - // Active state: - CPPUNIT_ASSERT( stc->activate() == true ); - CPPUNIT_ASSERT( stc->didactivate == true ); - stc->resetFlags(); - CPPUNIT_ASSERT( stc->isActive() == true ); - CPPUNIT_ASSERT( stc->configure() == false ); - CPPUNIT_ASSERT( stc->activate() == false ); - CPPUNIT_ASSERT( stc->cleanup() == false ); - // test flags - CPPUNIT_ASSERT( stc->didconfig == false ); - CPPUNIT_ASSERT( stc->didstart == false ); - CPPUNIT_ASSERT( stc->didupdate == false ); - CPPUNIT_ASSERT( stc->didstop == false ); - CPPUNIT_ASSERT( stc->didcleanup == false ); - CPPUNIT_ASSERT( stc->didactivate == false ); - stc->resetFlags(); - // continue to start - CPPUNIT_ASSERT( stc->start() == true ); - CPPUNIT_ASSERT( stc->didstart == true ); - stc->resetFlags(); - CPPUNIT_ASSERT( stc->isActive() == true ); - CPPUNIT_ASSERT( stc->isRunning() == true ); - CPPUNIT_ASSERT( stc->configure() == false ); - CPPUNIT_ASSERT( stc->activate() == false ); - CPPUNIT_ASSERT( stc->cleanup() == false ); - CPPUNIT_ASSERT( stc->start() == false ); - // running to stop to active to stop - CPPUNIT_ASSERT( stc->stop() == true ); - CPPUNIT_ASSERT( stc->activate() == true ); - stc->resetFlags(); - CPPUNIT_ASSERT( stc->stop() == true ); - CPPUNIT_ASSERT( stc->didstop == true ); - // test flags - CPPUNIT_ASSERT( stc->didconfig == false ); - CPPUNIT_ASSERT( stc->didstart == false ); - CPPUNIT_ASSERT( stc->didupdate == false ); - CPPUNIT_ASSERT( stc->didcleanup == false ); - CPPUNIT_ASSERT( stc->didactivate == false ); - stc->resetFlags(); - - // Stopped to PreOp state: - CPPUNIT_ASSERT( stc->cleanup() == true ); - CPPUNIT_ASSERT( stc->isConfigured() == false); - CPPUNIT_ASSERT( stc->isRunning() == false); - // test flags - CPPUNIT_ASSERT( stc->didconfig == false ); - CPPUNIT_ASSERT( stc->didstart == false ); - CPPUNIT_ASSERT( stc->didupdate == false ); - CPPUNIT_ASSERT( stc->didstop == false ); - CPPUNIT_ASSERT( stc->didcleanup == true ); - CPPUNIT_ASSERT( stc->didactivate == false ); - stc->resetFlags(); - CPPUNIT_ASSERT( stc->start() == false ); - CPPUNIT_ASSERT( stc->cleanup() == false ); - // test flags - CPPUNIT_ASSERT( stc->didconfig == false ); - CPPUNIT_ASSERT( stc->didstart == false ); - CPPUNIT_ASSERT( stc->didupdate == false ); - CPPUNIT_ASSERT( stc->didstop == false ); - CPPUNIT_ASSERT( stc->didcleanup == false ); - CPPUNIT_ASSERT( stc->didactivate == false ); - stc->resetFlags(); - - - // PreOperational to Stopped state: - CPPUNIT_ASSERT( stc->configure() == true ); - CPPUNIT_ASSERT( stc->isConfigured() == true); - CPPUNIT_ASSERT( stc->isRunning() == false); - // test flags - CPPUNIT_ASSERT( stc->didconfig == true ); - CPPUNIT_ASSERT( stc->didstart == false ); - CPPUNIT_ASSERT( stc->didupdate == false ); - CPPUNIT_ASSERT( stc->didstop == false ); - CPPUNIT_ASSERT( stc->didcleanup == false ); - CPPUNIT_ASSERT( stc->didactivate == false ); - stc->resetFlags(); - -} - -void Generic_TaskTest_3::testFailingTCStates() -{ - // Test the states of a TC failing in transitions - stc->validconfig = false; - stc->validstart = false; - stc->validactivate = false; - stc->validreset = false; - - // PreOperational state: - CPPUNIT_ASSERT( stc->isConfigured() == false ); - CPPUNIT_ASSERT( stc->isRunning() == false ); - CPPUNIT_ASSERT( stc->configure() == false ); - CPPUNIT_ASSERT( stc->didconfig == true ); - CPPUNIT_ASSERT( stc->isConfigured() == false ); - CPPUNIT_ASSERT( stc->isRunning() == false ); - CPPUNIT_ASSERT( stc->isActive() == false ); - stc->resetFlags(); - - // Retry: - stc->validconfig = true; - CPPUNIT_ASSERT( stc->configure() == true ); - CPPUNIT_ASSERT( stc->didconfig == true ); - CPPUNIT_ASSERT( stc->isConfigured() == true ); - CPPUNIT_ASSERT( stc->isRunning() == false ); - CPPUNIT_ASSERT( stc->isActive() == false ); - stc->resetFlags(); - - // Stopped state: - CPPUNIT_ASSERT( stc->start() == false ); - CPPUNIT_ASSERT( stc->didstart == true ); - CPPUNIT_ASSERT( stc->isRunning() == false ); - CPPUNIT_ASSERT( stc->isActive() == false ); - CPPUNIT_ASSERT( stc->isConfigured() == true ); - stc->resetFlags(); - - // Retry: - stc->validstart = true; - CPPUNIT_ASSERT( stc->start() == true ); - CPPUNIT_ASSERT( stc->didstart == true ); - CPPUNIT_ASSERT( stc->isConfigured() == true ); - CPPUNIT_ASSERT( stc->isRunning() == true ); - CPPUNIT_ASSERT( stc->isActive() == true ); - stc->resetFlags(); - - // Stopped to Active - CPPUNIT_ASSERT( stc->stop() == true ); - CPPUNIT_ASSERT( stc->activate() == false ); - CPPUNIT_ASSERT( stc->didactivate == true ); - CPPUNIT_ASSERT( stc->isRunning() == false ); - CPPUNIT_ASSERT( stc->isActive() == false ); - CPPUNIT_ASSERT( stc->isConfigured() == true ); - stc->resetFlags(); - // Retry: - stc->validactivate = true; - CPPUNIT_ASSERT( stc->activate() == true ); - CPPUNIT_ASSERT( stc->didactivate == true ); - CPPUNIT_ASSERT( stc->isConfigured() == true ); - CPPUNIT_ASSERT( stc->isActive() == true ); - CPPUNIT_ASSERT( stc->isRunning() == false ); - stc->resetFlags(); - - // Active to Running - stc->validstart = false; - CPPUNIT_ASSERT( stc->start() == false ); - CPPUNIT_ASSERT( stc->didstart == true ); - CPPUNIT_ASSERT( stc->isRunning() == false ); - CPPUNIT_ASSERT( stc->isActive() == true ); - CPPUNIT_ASSERT( stc->isConfigured() == true ); - stc->resetFlags(); - - // Retry: - stc->validstart = true; - CPPUNIT_ASSERT( stc->start() == true ); - CPPUNIT_ASSERT( stc->didstart == true ); - CPPUNIT_ASSERT( stc->isConfigured() == true ); - CPPUNIT_ASSERT( stc->isRunning() == true ); - CPPUNIT_ASSERT( stc->isActive() == true ); - stc->resetFlags(); - - // Error state. - stc->do_error = true; - // Running state / updateHook : - SimulationThread::Instance()->run(1); - CPPUNIT_ASSERT( stc->inFatalError() == true ); - CPPUNIT_ASSERT( stc->resetError() == true ); // brings us to PreOp. - CPPUNIT_ASSERT( stc->didreset == true ); - CPPUNIT_ASSERT( stc->isConfigured() == false); - // Retry: - CPPUNIT_ASSERT( stc->configure() == true); - CPPUNIT_ASSERT( stc->start() == true ); - stc->validreset = true; - // Running state / updateHook : - SimulationThread::Instance()->run(1); - CPPUNIT_ASSERT( stc->inFatalError() == true ); - CPPUNIT_ASSERT( stc->resetError() == true ); // brings us to Stopped. - CPPUNIT_ASSERT( stc->didreset == true ); - CPPUNIT_ASSERT( stc->isConfigured() == true); - -} - -void Generic_TaskTest_3::testExecutionEngine() -{ - // no owner: - ExecutionEngine ee1(0); - ExecutionEngine ee2(0); - - // test setActivity: - CPPUNIT_ASSERT( tsim->run(&ee1) ); - CPPUNIT_ASSERT( SimulationThread::Instance()->run(5) ); - - // this also tests setActivity: - CPPUNIT_ASSERT( tsim->run(&ee2) ); - CPPUNIT_ASSERT( SimulationThread::Instance()->run(5) ); - - { - TaskCore tc1("tc1", &ee2); - TaskCore tc2("tc2", &ee2); - - // run with two children. - CPPUNIT_ASSERT( SimulationThread::Instance()->run(5) ); - } - // children removed again: - CPPUNIT_ASSERT( SimulationThread::Instance()->run(5) ); - tsim->run(0); -} - -void Generic_TaskTest_3::testProperties() -{ - Property d1("d1", "desc1", 1.234); - tc->properties()->addProperty( &d1); - - CPPUNIT_ASSERT_EQUAL( double(1.234), d1.get() ); - CPPUNIT_ASSERT_EQUAL( double(1.234), tc->properties()->getProperty("d1")->get() ); - - // test setup of mirror: - Property s1; - CPPUNIT_ASSERT( !s1.ready() ); - Property s2("hello","description", "world"); - CPPUNIT_ASSERT( s2.ready() ); - - CPPUNIT_ASSERT(tc->properties()->addProperty( &s1 ) == false); - CPPUNIT_ASSERT(tc->properties()->addProperty( &s2 ) ); - s1 = tc->properties()->getProperty("hello"); - CPPUNIT_ASSERT( s1.ready() ); - - CPPUNIT_ASSERT_EQUAL(std::string("hello"), s1.getName() ); - CPPUNIT_ASSERT_EQUAL(std::string("description"), s1.getDescription() ); - CPPUNIT_ASSERT_EQUAL(std::string("world"), s1.get() ); - - // Test mirroring of 'set' and 'get': - s1.set("universe"); - CPPUNIT_ASSERT_EQUAL(std::string("universe"), s2.get() ); - -#if 0 - CPPUNIT_ASSERT(tc->writeProperties("Generic_TaskTest_3_Properties.cpf")); - CPPUNIT_ASSERT( tc->readProperties("Generic_TaskTest_3_Properties.cpf")); -#endif -} - -void Generic_TaskTest_3::testAttributes() -{ - // test attribute repository: - Attribute i1("i1"); - Attribute d1("d1", 1.234); - CPPUNIT_ASSERT( i1.ready() ); - CPPUNIT_ASSERT( d1.ready() ); - CPPUNIT_ASSERT(tc->attributes()->addAttribute( &d1 )); - CPPUNIT_ASSERT(tc->attributes()->addAttribute( &i1 )); - - i1.set( 3 ); - CPPUNIT_ASSERT_EQUAL( double(1.234), d1.get() ); - CPPUNIT_ASSERT_EQUAL( int(3), i1.get() ); - - CPPUNIT_ASSERT_EQUAL( double(1.234), tc->attributes()->getAttribute("d1")->get() ); - CPPUNIT_ASSERT_EQUAL( int(3), tc->attributes()->getAttribute("i1")->get() ); - - // test setup of mirror: - Attribute s1; - CPPUNIT_ASSERT( !s1.ready() ); - Attribute s2("hello","world"); - CPPUNIT_ASSERT( s2.ready() ); - - CPPUNIT_ASSERT(tc->attributes()->addAttribute( &s1 ) == false); - CPPUNIT_ASSERT(tc->attributes()->addAttribute( &s2 ) ); - s1 = tc->attributes()->getAttribute("hello"); - CPPUNIT_ASSERT( s1.ready() ); - - CPPUNIT_ASSERT_EQUAL(std::string("hello"), s1.getName() ); - CPPUNIT_ASSERT_EQUAL(std::string("world"), s1.get() ); - - // Test mirroring of 'set' and 'get': - s1.set("universe"); - CPPUNIT_ASSERT_EQUAL(std::string("universe"), s2.get() ); - -} - -void Generic_TaskTest_3::testPorts() -{ - WriteDataPort wdp("WDName"); - ReadDataPort rdp("RDName"); - DataPort dp("DName"); - DataPort dp2("D2Name"); - - CPPUNIT_ASSERT( wdp.getPortType() == PortInterface::WritePort ); - CPPUNIT_ASSERT( rdp.getPortType() == PortInterface::ReadPort ); - CPPUNIT_ASSERT( dp.getPortType() == PortInterface::ReadWritePort ); - - // Test initial value - wdp.Set( 1.0 ); - dp.Set( 2.0 ); - - WriteBufferPort wbp("WBName", 10); - ReadBufferPort rbp("RBName"); - BufferPort bp("BName", 10); - BufferPort bp2("B2Name", 10); - - CPPUNIT_ASSERT( wbp.getPortType() == PortInterface::WritePort ); - CPPUNIT_ASSERT( rbp.getPortType() == PortInterface::ReadPort ); - CPPUNIT_ASSERT( bp.getPortType() == PortInterface::ReadWritePort ); - - CPPUNIT_ASSERT( tc->ports()->addPort( &wdp )); - CPPUNIT_ASSERT( tc->ports()->addPort( &rdp )); - CPPUNIT_ASSERT( tc->ports()->addPort( &dp )); - CPPUNIT_ASSERT( tc->ports()->addPort( &dp2 )); - - // check adding same port twice. - CPPUNIT_ASSERT( tc->ports()->addPort( &wdp ) == false); - { - // also check adding different port with same name. - DataPort tdp("WDName"); - CPPUNIT_ASSERT( tc->ports()->addPort( &tdp ) == false); - } - - CPPUNIT_ASSERT( tc->ports()->addPort( &wbp )); - CPPUNIT_ASSERT( tc->ports()->addPort( &rbp )); - CPPUNIT_ASSERT( tc->ports()->addPort( &bp )); - CPPUNIT_ASSERT( tc->ports()->addPort( &bp2 )); - - // Test connection creation. - CPPUNIT_ASSERT(wdp.connectTo( &rdp ) ); - CPPUNIT_ASSERT(dp.connectTo( rdp.connection() )); - - CPPUNIT_ASSERT(wbp.connectTo( &rbp ) ); - CPPUNIT_ASSERT(bp.connectTo( rbp.connection() )); - - CPPUNIT_ASSERT( wdp.connected() ); - CPPUNIT_ASSERT( rdp.connected() ); - CPPUNIT_ASSERT( dp.connected() ); - - CPPUNIT_ASSERT( wbp.connected() ); - CPPUNIT_ASSERT( rbp.connected() ); - CPPUNIT_ASSERT( bp.connected() ); - - // Test data transfer - CPPUNIT_ASSERT( rdp.Get() == 1.0 ); - wdp.Set( 3.0 ); - CPPUNIT_ASSERT( rdp.Get() == 3.0 ); - CPPUNIT_ASSERT( dp.Get() == 3.0 ); - double dat = 0.0; - dp.Get( dat ); - CPPUNIT_ASSERT( dat == 3.0 ); - dat = 0.0; - rdp.Get( dat ); - CPPUNIT_ASSERT( dat == 3.0 ); - - // Test Data-to-Data: - dp.disconnect(); - CPPUNIT_ASSERT( dp.connectTo( &dp2 ) ); - CPPUNIT_ASSERT( dp.connected() ); - CPPUNIT_ASSERT( dp2.connected() ); - - dp.Set( 5.0 ); - dp2.Get( dat ); - CPPUNIT_ASSERT( dat == 5.0 ); - - dp2.Set( 6.0 ); - CPPUNIT_ASSERT( dp.Get() == 6.0 ); - - dp.disconnect(); - dp2.disconnect(); -#ifndef OROPKG_OS_MACOSX - dp = new DataObject("Data",10.0); - CPPUNIT_ASSERT( dp.connected() ); - CPPUNIT_ASSERT( dp.Get() == 10.0 ); -#endif - // Test buffer transfer - double val; - CPPUNIT_ASSERT( wbp.Push( 5.0 ) ); - CPPUNIT_ASSERT( rbp.Pop( val ) ); - CPPUNIT_ASSERT( val == 5.0 ); - - CPPUNIT_ASSERT( wbp.Push( 6.0 ) ); - CPPUNIT_ASSERT( bp.Pop( val ) ); - CPPUNIT_ASSERT( val == 6.0 ); - - CPPUNIT_ASSERT( bp.Push( 5.0 ) ); - CPPUNIT_ASSERT( bp.Pop( val ) ); - CPPUNIT_ASSERT( val == 5.0 ); - CPPUNIT_ASSERT( bp.Pop( val ) == false ); - - // Test Buffer-to-Buffer: - bp.disconnect(); - CPPUNIT_ASSERT( bp.connectTo( &bp2 ) ); - CPPUNIT_ASSERT( bp.connected() ); - CPPUNIT_ASSERT( bp2.connected() ); - - CPPUNIT_ASSERT( bp.Push( 5.0 ) ); - CPPUNIT_ASSERT( bp2.Pop( val ) ); - CPPUNIT_ASSERT( val == 5.0 ); - CPPUNIT_ASSERT( bp2.Pop( val ) == false ); - - CPPUNIT_ASSERT( bp2.Push( 5.0 ) ); - CPPUNIT_ASSERT( bp.Pop( val ) ); - CPPUNIT_ASSERT( val == 5.0 ); - CPPUNIT_ASSERT( bp2.Pop( val ) == false ); - - bp.disconnect(); - bp2.disconnect(); -#ifndef OROPKG_OS_MACOSX - bp = new BufferLockFree(10); - CPPUNIT_ASSERT( bp.connected() ); - CPPUNIT_ASSERT( bp.buffer()->capacity() == 10 ); -#endif - -} - -void Generic_TaskTest_3::testEventPorts() -{ - // Data ports - WriteDataPort wdp("WDName"); - ReadDataPort rdp("RDName"); - DataPort dp("DName"); - DataPort dp2("D2Name"); - - CPPUNIT_ASSERT( tce->ports()->addEventPort( &wdp )); - CPPUNIT_ASSERT( tc2->ports()->addEventPort( &rdp )); - CPPUNIT_ASSERT( tce->ports()->addEventPort( &dp )); - CPPUNIT_ASSERT( tc2->ports()->addEventPort( &dp2 )); - - // Buffer ports - WriteBufferPort wbp("WBName", 10); - ReadBufferPort rbp("RBName"); - BufferPort bp("BName", 10); - BufferPort bp2("B2Name", 10); - - CPPUNIT_ASSERT( tce->ports()->addEventPort( &wbp )); - CPPUNIT_ASSERT( tc2->ports()->addEventPort( &rbp )); - CPPUNIT_ASSERT( tce->ports()->addEventPort( &bp )); - CPPUNIT_ASSERT( tc2->ports()->addEventPort( &bp2 )); - - // Connect 3 data ports - CPPUNIT_ASSERT(wdp.connectTo( &rdp ) ); - CPPUNIT_ASSERT(dp.connectTo( rdp.connection() )); - - // Connect 3 buffer ports - CPPUNIT_ASSERT(wbp.connectTo( &rbp ) ); - CPPUNIT_ASSERT(bp.connectTo( rbp.connection() )); - - wdp.Set(1.0); - CPPUNIT_ASSERT( tc2->had_event == false ); - CPPUNIT_ASSERT_EQUAL( tc2->nb_events, 0 ); // not running. - CPPUNIT_ASSERT( tce->had_event == false ); - CPPUNIT_ASSERT_EQUAL( tce->nb_events, 0 ); // not running. - - // After addEventPort, do the start (SequentialActivity) - tce->start(); - tc2->start(); - - // Test data transfer - CPPUNIT_ASSERT( rdp.Get() == 1.0 ); - wdp.Set( 3.0 ); - CPPUNIT_ASSERT( rdp.Get() == 3.0 ); - CPPUNIT_ASSERT( dp.Get() == 3.0 ); - CPPUNIT_ASSERT( tce->had_event ); - CPPUNIT_ASSERT_EQUAL( 1, tce->nb_events ); // 1 event port (dp) fired. - CPPUNIT_ASSERT( tc2->had_event ); - CPPUNIT_ASSERT_EQUAL( 1, tc2->nb_events ); // 1 event port (rdp) connected - tce->resetStats(); - tc2->resetStats(); - - // Test Reconnection after tasks are running: - dp.disconnect(); - CPPUNIT_ASSERT( dp.connectTo( &dp2 ) ); - CPPUNIT_ASSERT( dp.connected() ); - CPPUNIT_ASSERT( dp2.connected() ); - - double dat; - dp.Set( 5.0 ); - dp2.Get( dat ); - CPPUNIT_ASSERT( dat == 5.0 ); - CPPUNIT_ASSERT( tce->had_event ); - CPPUNIT_ASSERT_EQUAL( 1, tce->nb_events ); // 1 event port (dp) fired. - CPPUNIT_ASSERT( tc2->had_event ); - CPPUNIT_ASSERT_EQUAL( 1, tc2->nb_events ); // 1 event port (dp2). - tce->resetStats(); - tc2->resetStats(); - - dp2.Set( 6.0 ); - CPPUNIT_ASSERT( dp.Get() == 6.0 ); - CPPUNIT_ASSERT( tce->had_event ); - CPPUNIT_ASSERT_EQUAL( 1, tce->nb_events ); // 1 event port fired. - CPPUNIT_ASSERT( tc2->had_event ); - CPPUNIT_ASSERT_EQUAL( 1, tc2->nb_events ); // 1 event port fired. - tce->resetStats(); - tc2->resetStats(); - - dp.disconnect(); - dp2.disconnect(); -#ifndef OROPKG_OS_MACOSX - dp = new DataObject("Data",10.0); - CPPUNIT_ASSERT( dp.connected() ); - CPPUNIT_ASSERT( dp.Get() == 10.0 ); -#endif - // Each time, each TC must receive one event. - double val; - CPPUNIT_ASSERT( wbp.Push( 5.0 ) ); - CPPUNIT_ASSERT( rbp.Pop( val ) ); - CPPUNIT_ASSERT( tce->had_event ); - CPPUNIT_ASSERT_EQUAL( 1, tce->nb_events ); // 1 event port (bp) fired. - CPPUNIT_ASSERT( tc2->had_event ); - CPPUNIT_ASSERT_EQUAL( 1, tc2->nb_events ); // 1 event ports (rbp) fired. - tce->resetStats(); - tc2->resetStats(); - - CPPUNIT_ASSERT( bp.Push( 5.0 ) ); - CPPUNIT_ASSERT( bp.Pop( val ) ); - CPPUNIT_ASSERT( tce->had_event ); - CPPUNIT_ASSERT_EQUAL( 1, tce->nb_events ); // 1 event port (bp) fired. - CPPUNIT_ASSERT( tc2->had_event ); - CPPUNIT_ASSERT_EQUAL( 1, tc2->nb_events ); // 1 event port (rbp) fired. - tce->resetStats(); - tc2->resetStats(); -} - - -void Generic_TaskTest_3::testConnections() -{ - WriteDataPort wdp("WDName"); - ReadDataPort rdp("RDName"); - DataPort dp("DName"); - DataPort dp2("D2Name"); - - CPPUNIT_ASSERT( wdp.getPortType() == PortInterface::WritePort ); - CPPUNIT_ASSERT( rdp.getPortType() == PortInterface::ReadPort ); - CPPUNIT_ASSERT( dp.getPortType() == PortInterface::ReadWritePort ); - - // Test initial value - wdp.Set( 1.0 ); - dp.Set( 2.0 ); - - WriteBufferPort wbp("WBName", 10); - ReadBufferPort rbp("RBName"); - BufferPort bp("BName", 10); - BufferPort bp2("B2Name", 10); - - CPPUNIT_ASSERT( wbp.getPortType() == PortInterface::WritePort ); - CPPUNIT_ASSERT( rbp.getPortType() == PortInterface::ReadPort ); - CPPUNIT_ASSERT( bp.getPortType() == PortInterface::ReadWritePort ); - - CPPUNIT_ASSERT( tc->ports()->addPort( &wdp )); - CPPUNIT_ASSERT( tc->ports()->addPort( &rdp )); - CPPUNIT_ASSERT( tc->ports()->addPort( &dp )); - CPPUNIT_ASSERT( tc->ports()->addPort( &dp2 )); - - // test setting the connection object - wdp = new DataObject(""); - rdp = new DataObject(""); - dp = new DataObject(""); - dp2 = new DataObject(""); - - CPPUNIT_ASSERT( wdp.connected() ); - CPPUNIT_ASSERT( rdp.connected() ); - CPPUNIT_ASSERT( dp.connected() ); - CPPUNIT_ASSERT( dp2.connected() ); - - CPPUNIT_ASSERT( dynamic_cast* >( wdp.connection()->getDataSource().get() ) ); - CPPUNIT_ASSERT( dynamic_cast* >( rdp.connection()->getDataSource().get() ) ); - CPPUNIT_ASSERT( dynamic_cast* >( dp.connection()->getDataSource().get() ) ); - CPPUNIT_ASSERT( dynamic_cast* >( dp2.connection()->getDataSource().get() ) ); - - // test setting the connection object - wbp = new BufferLocked(10); - rbp = new BufferLocked(11); - bp = new BufferLocked(12); - bp2 = new BufferLocked(13); - - CPPUNIT_ASSERT( wbp.connected() ); - CPPUNIT_ASSERT( rbp.connected() ); - CPPUNIT_ASSERT( bp.connected() ); - CPPUNIT_ASSERT( bp2.connected() ); - - CPPUNIT_ASSERT( dynamic_cast* >( wbp.connection()->getBuffer().get() ) ); - CPPUNIT_ASSERT( dynamic_cast* >( rbp.connection()->getBuffer().get() ) ); - CPPUNIT_ASSERT( dynamic_cast* >( bp.connection()->getBuffer().get() ) ); - CPPUNIT_ASSERT( dynamic_cast* >( bp2.connection()->getBuffer().get() ) ); - -} - -void Generic_TaskTest_3::testPortObjects() -{ - WriteDataPort wdp("WDName"); - ReadDataPort rdp("RDName"); - DataPort dp("DName"); - DataPort dp2("D2Name"); - - tc->ports()->addPort( &wdp ); - tc->ports()->addPort( &rdp ); - tc->ports()->addPort( &dp ); - tc->ports()->addPort( &dp2 ); - - // Check if ports were added as objects as well - CPPUNIT_ASSERT( tc->getObject("WDName") != 0 ); - CPPUNIT_ASSERT( tc->getObject("RDName") != 0 ); - CPPUNIT_ASSERT( tc->getObject("DName") != 0 ); - CPPUNIT_ASSERT( tc->getObject("D2Name") != 0 ); - - // Set initial value - wdp.Set( 1.0 ); - dp.Set( 2.0 ); - - // Connect ports. - wdp.connectTo( &rdp ); - dp.connectTo( &dp2 ); - - WriteBufferPort wbp("WBName", 10); - ReadBufferPort rbp("RBName"); - BufferPort bp("BName", 10); - BufferPort bp2("B2Name", 10); - - tc->ports()->addPort( &wbp ); - tc->ports()->addPort( &rbp ); - tc->ports()->addPort( &bp ); - tc->ports()->addPort( &bp2 ); - - // Check if ports were added as objects as well - CPPUNIT_ASSERT( tc->getObject("WBName") != 0 ); - CPPUNIT_ASSERT( tc->getObject("RBName") != 0 ); - CPPUNIT_ASSERT( tc->getObject("BName") != 0 ); - CPPUNIT_ASSERT( tc->getObject("B2Name") != 0 ); - - // Connect ports. - wbp.connectTo( &rbp ); - bp.connectTo( &bp2 ); - - // Test Methods set/get - Method mset; - Method mget; - - mset = tc->getObject("WDName")->methods()->getMethod("Set"); - CPPUNIT_ASSERT( mset.ready() ); - - mget = tc->getObject("RDName")->methods()->getMethod("Get"); - CPPUNIT_ASSERT( mget.ready() ); - - mset( 3.991 ); - - CPPUNIT_ASSERT( mget() == 3.991 ); - - // Test Methods for DataPort - mset = tc->getObject("DName")->methods()->getMethod("Set"); - CPPUNIT_ASSERT( mset.ready() ); - - mget = tc->getObject("D2Name")->methods()->getMethod("Get"); - CPPUNIT_ASSERT( mget.ready() ); - - mset( 3.992 ); - - CPPUNIT_ASSERT( mget() == 3.992 ); - - // Test Methods push/pull - Method mpush; - Method mpop; - - mpush = tc->getObject("WBName")->methods()->getMethod("Push"); - CPPUNIT_ASSERT( mpush.ready() ); - - mpop = tc->getObject("RBName")->methods()->getMethod("Pop"); - CPPUNIT_ASSERT( mpop.ready() ); - - CPPUNIT_ASSERT( mpush( 3.991 ) ); - - double ret; - CPPUNIT_ASSERT( mpop(ret) ); - - CPPUNIT_ASSERT( ret == 3.991 ); - - // Test Methods push/pop for DataPort - mpush = tc->getObject("BName")->methods()->getMethod("Push"); - CPPUNIT_ASSERT( mpush.ready() ); - - mpop = tc->getObject("B2Name")->methods()->getMethod("Pop"); - CPPUNIT_ASSERT( mpop.ready() ); - - CPPUNIT_ASSERT( mpush( 3.993 ) ); - - CPPUNIT_ASSERT( mpop(ret) ); - - CPPUNIT_ASSERT( ret == 3.993 ); - - // Finally, check cleanup. Ports and port objects must be gone: - tc->ports()->removePort("RDName"); - CPPUNIT_ASSERT( tc->getObject("RDName") == 0 ); - CPPUNIT_ASSERT( tc->ports()->getPort("RDName") == 0 ); - - tc->ports()->removePort("BName"); - CPPUNIT_ASSERT( tc->getObject("BName") == 0 ); - CPPUNIT_ASSERT( tc->ports()->getPort("BName") == 0 ); -} diff --git a/tests/generictask_test_3.hpp b/tests/generictask_test_3.hpp deleted file mode 100644 index c921edcf9..000000000 --- a/tests/generictask_test_3.hpp +++ /dev/null @@ -1,75 +0,0 @@ -/*************************************************************************** - tag: Peter Soetens Mon Jun 26 13:26:02 CEST 2006 generictask_test.hpp - - generictask_test.hpp - description - ------------------- - begin : Mon June 26 2006 - copyright : (C) 2006 Peter Soetens - email : peter.soetens@fmtc.be - - *************************************************************************** - * * - * This program is free software; you can redistribute it and/or modify * - * it under the terms of the GNU General Public License as published by * - * the Free Software Foundation; either version 2 of the License, or * - * (at your option) any later version. * - * * - ***************************************************************************/ - - -#ifndef GENERIC_TASK_3_H -#define GENERIC_TASK_3_H - -#include - -#include "TaskContext.hpp" -#include - -using namespace RTT; - -class StatesTC; -class EventPortsTC; - -class Generic_TaskTest_3 : public CppUnit::TestFixture -{ - CPPUNIT_TEST_SUITE( Generic_TaskTest_3 ); - CPPUNIT_TEST( testPeriod ); - CPPUNIT_TEST( testExecutionEngine ); - CPPUNIT_TEST( testPorts ); - CPPUNIT_TEST( testEventPorts ); - CPPUNIT_TEST( testConnections ); - CPPUNIT_TEST( testPortObjects ); - CPPUNIT_TEST( testProperties ); - CPPUNIT_TEST( testAttributes ); - CPPUNIT_TEST( testTCStates ); - CPPUNIT_TEST( testSpecialTCStates ); - CPPUNIT_TEST( testFailingTCStates ); - CPPUNIT_TEST_SUITE_END(); - - TaskContext* tc; - EventPortsTC* tce; - EventPortsTC* tc2; - StatesTC* stc; - ActivityInterface* tsim; - ActivityInterface* stsim; - -public: - - void setUp(); - void tearDown(); - - void testPeriod(); - void testExecutionEngine(); - void testProperties(); - void testAttributes(); - void testPorts(); - void testEventPorts(); - void testConnections(); - void testPortObjects(); - void testTCStates(); - void testSpecialTCStates(); - void testFailingTCStates(); - -}; - -#endif diff --git a/tests/logger_test.cpp b/tests/logger_test.cpp deleted file mode 100644 index 845ca2bc8..000000000 --- a/tests/logger_test.cpp +++ /dev/null @@ -1,116 +0,0 @@ -/*************************************************************************** - tag: Peter Soetens Mon Jan 10 15:59:51 CET 2005 logger_test.cpp - - logger_test.cpp - description - ------------------- - begin : Mon January 10 2005 - copyright : (C) 2005 Peter Soetens - email : peter.soetens@mech.kuleuven.ac.be - - *************************************************************************** - * * - * This program is free software; you can redistribute it and/or modify * - * it under the terms of the GNU General Public License as published by * - * the Free Software Foundation; either version 2 of the License, or * - * (at your option) any later version. * - * * - ***************************************************************************/ - - - -#include "logger_test.hpp" -#include -#include -#include -#include "os/PeriodicThread.hpp" - -using namespace boost; -using namespace std; - -// Registers the fixture into the 'registry' -CPPUNIT_TEST_SUITE_REGISTRATION( LoggerTest ); - -using namespace RTT; - -class Dummy {}; - -#define QS 10 - -void -LoggerTest::setUp() -{ - logger = Logger::Instance(); -} - - -void -LoggerTest::tearDown() -{ -} - -void LoggerTest::testStartStop() -{ - CPPUNIT_ASSERT( logger != 0 ); - CPPUNIT_ASSERT( &Logger::log() != 0 ); -} -void LoggerTest::testLogEnv() -{ - Logger::log() << Logger::Debug << "Debug Level set + text"<< Logger::nl; - Logger::log() << "Test Log Environment variable : Single line" << Logger::endl; - Logger::log() << "Test Log Environment variable : Two "; - Logger::log() << "lines on one line." << Logger::endl; - Logger::log() << "Test Log Environment variable : Two" << Logger::nl; - Logger::log() << "lines on two lines." << Logger::endl; - - Logger::log() << "Test Log Environment variable : nl" << Logger::nl; - Logger::log() << "Test Log Environment variable : flush" << flush; - Logger::log() << " and std::endl." << std::endl; -} - -void LoggerTest::testNewLog() -{ - log( Debug ) << "Debug Level set + text"<< endlog(); - log() << "Test Log Environment variable : Single line" << endlog(Debug); - log() << "Test Log Environment variable : Two "; - log() << "lines on one line." << endlog(); - log() << "Test Log Environment variable : Two" << nlog(); - log() << "lines on two lines." << endlog(); - - log() << "Test Log Environment variable : nl" << nlog(); - log() << "Test Log Environment variable : flush" << flushlog(); - log() << " and std::endl." << std::endl; -} - -struct TestLog - : public RTT::OS::RunnableInterface -{ - bool fini; - bool initialize() { fini = false; return true; } - - void step() { - Logger::In in("TLOG"); - log(Info) << "Hello this is the world speaking elaborately and lengthy...!" < run( new TestLog() ); - boost::scoped_ptr t( new RTT::OS::PeriodicThread(25,"ORThread", 0.001) ); - boost::scoped_ptr run2( new TestLog() ); - boost::scoped_ptr t2( new RTT::OS::PeriodicThread(25,"ORThread", 0.001) ); - - t->run( run.get() ); - t2->run( run2.get() ); - - t->start(); - t2->start(); - sleep(1); - t->stop(); - t2->stop(); - -} diff --git a/tests/logger_test.hpp b/tests/logger_test.hpp deleted file mode 100644 index ab5506358..000000000 --- a/tests/logger_test.hpp +++ /dev/null @@ -1,50 +0,0 @@ -/*************************************************************************** - tag: Peter Soetens Mon Jan 10 15:59:18 CET 2005 logger_test.hpp - - logger_test.hpp - description - ------------------- - begin : Mon January 10 2005 - copyright : (C) 2005 Peter Soetens - email : peter.soetens@mech.kuleuven.ac.be - - *************************************************************************** - * * - * This program is free software; you can redistribute it and/or modify * - * it under the terms of the GNU General Public License as published by * - * the Free Software Foundation; either version 2 of the License, or * - * (at your option) any later version. * - * * - ***************************************************************************/ - - -#ifndef LOGGERTEST_H -#define LOGGERTEST_H - -#include - -#include - -using namespace RTT; - -class LoggerTest : public CppUnit::TestFixture -{ - Logger* logger; - CPPUNIT_TEST_SUITE( LoggerTest ); - CPPUNIT_TEST( testStartStop ); - CPPUNIT_TEST( testLogEnv ); - CPPUNIT_TEST( testNewLog ); - CPPUNIT_TEST( testThreadLog ); - CPPUNIT_TEST_SUITE_END(); - -public: - - void setUp(); - void tearDown(); - - void testStartStop(); - void testLogEnv(); - void testNewLog(); - void testThreadLog(); -}; - -#endif diff --git a/tests/program_test.cpp b/tests/program_test.cpp deleted file mode 100644 index 1dd758e49..000000000 --- a/tests/program_test.cpp +++ /dev/null @@ -1,441 +0,0 @@ -/*************************************************************************** - tag: Peter Soetens Mon Jan 10 15:59:51 CET 2005 program_test.cpp - - program_test.cpp - description - ------------------- - begin : Mon January 10 2005 - copyright : (C) 2005 Peter Soetens - email : peter.soetens@mech.kuleuven.ac.be - - *************************************************************************** - * * - * This program is free software; you can redistribute it and/or modify * - * it under the terms of the GNU General Public License as published by * - * the Free Software Foundation; either version 2 of the License, or * - * (at your option) any later version. * - * * - ***************************************************************************/ - - - -#include "program_test.hpp" -#include -#include -#include -#include -#include -#include -#include - - -using namespace std; - -// Registers the fixture into the 'registry' -CPPUNIT_TEST_SUITE_REGISTRATION( ProgramTest ); - - - ProgramTest::ProgramTest() - : gtc("root"), - gtask( 0.01, gtc.engine() ) - {} - - -void -ProgramTest::setUp() -{ - Attribute init_var("tvar_i"); - var_i = &init_var; - const_i = new Constant("tconst_i",-1); - // ltc has a test object - gtc.addObject( this->createObject(new TaskObject("test"), gtc.engine()->commands()) ); - - // also this functions - this->createObject( >c, gtc.engine()->commands()); - - gtc.attributes()->addAttribute( &var_i ); - gtc.attributes()->addConstant( const_i ); - var_i.set(-1); - i = 0; - SimulationThread::Instance()->stop(); -} - - -void -ProgramTest::tearDown() -{ - delete const_i; - gtask.stop(); -} - - -bool ProgramTest::assertBool( bool b) { - return b; -} -bool ProgramTest::assertMsg( bool b, const std::string& msg) { - if ( b == false ) - cout << "Asserted :" << b << " with :" << msg << endl; - return b; -} - -int ProgramTest::increase() { - return ++i; -} - -void ProgramTest::resetI() { - i = 0; -} - - -OperationInterface* ProgramTest::createObject(OperationInterface* dat, CommandProcessor* cp) -{ - // Add the data of the EE: - dat->methods()->addMethod( method( "assert", &ProgramTest::assertBool, this), - "Assert", "bool", "" ); - dat->methods()->addMethod( method( "increase", &ProgramTest::increase, this), - "Return increasing i" ); - dat->methods()->addMethod( method( "resetI", &ProgramTest::resetI, this), - "ResetI i" ); - dat->methods()->addMethod( method( "assertMsg", &ProgramTest::assertMsg, this), - "Assert message", "bool", "", "text", "text" ); - dat->methods()->addMethod( method( "isTrue", &ProgramTest::assertBool, this), - "Identity function", "bool", "" ); - dat->methods()->addMethod( method( "i", &ProgramTest::getI, this), - "Return the current number" ); - dat->commands()->addCommand( command( "instantDone", &ProgramTest::true_genCom, - &ProgramTest::true_gen, this, cp), - "returns immediately" ); - dat->commands()->addCommand( command( "neverDone", &ProgramTest::true_genCom, - &ProgramTest::false_gen, this, cp), - "returns never" ); - dat->commands()->addCommand( command( "instantNotDone", &ProgramTest::true_genCom, - &ProgramTest::true_gen, this, cp, false), - "returns never" ); - dat->commands()->addCommand( command( "instantFail", &ProgramTest::false_genCom, - &ProgramTest::true_gen, this, cp), - "fails immediately" ); - dat->commands()->addCommand( command( "totalFail", &ProgramTest::false_genCom, - &ProgramTest::false_gen, this, cp), - "fails in command and condition" ); - return dat; -} - -void ProgramTest::testEmptyProgram() -{ - string prog = ""; - Parser::ParsedPrograms pg_list; - try { - pg_list = parser.parseProgram( prog, >c ); - } - catch( const file_parse_exception& exc ) - { - CPPUNIT_ASSERT( false ); - } - if ( !pg_list.empty() ) - { - CPPUNIT_ASSERT( false ); - } -} - -void ProgramTest::testReturnProgram() -{ - string prog = "program x { return \n }"; - this->doProgram( prog, >c ); - this->finishProgram( >c, "x"); -} - -void ProgramTest::testParseProgram() -{ - // a program which should never fail - // test this methods, commands etc. - string prog = string("program x { do test.instantDone() \n") - + " \n " + "and\n" + " test.instantDone() and test.instantDone()\n" - + " do test.assert( test.isTrue( true ) )\n" - + " do test.assert( test.i == 0 )\n" - + " do test.increase()\n" - + " do test.assert( test.i == 1 )\n" - + " do test.resetI()\n" - + " do test.assert( test.i == 0 )\n" - + " if test.increase() + test.increase() + test.increase() != 6 then \n " - + " do test.assert( false )\n" - + " do assert( isTrue( true ) )\n" - + " do instantDone() \n" - + " and instantDone() and instantDone()\n" - + " do resetI()\n" - + " do assert( i == 0 )\n" - + " if increase() + increase() + increase() != 6 then \n " - + " do assert( false )\n" - + " if true then\n" - + " return\n" - + " do test.assert(false)" // do not reach - + "}"; - - this->doProgram( prog, >c ); - this->finishProgram( >c, "x"); -} - -void ProgramTest::testProgramFailure() -{ - //also small test for program without newlines - string prog = string("program x { do test.instantFail() until { ") - + " if true then continue }" - + "}"; - - this->doProgram( prog, >c, false ); - - CPPUNIT_ASSERT( gtc.engine()->programs()->getProgramStatus("x") == ProgramInterface::Status::error ); - - this->finishProgram( >c, "x"); -} -void ProgramTest::testProgramCondition() -{ - // see if checking a remote condition works - string prog = string("program x { \n") - + "if test.isTrue(true) then \n" - + " do test.instantDone() \n" - + "else \n" - + " do test.instantFail() \n" - + "if test.isTrue(false) then \n" - + " do test.instantFail() \n" - + "else \n" - + " do test.instantDone() \n" - + "if test.isTrue(true) then \n" - + " if test.isTrue(true) then \n" - + " if test.isTrue(false) then \n" - + " do test.instantFail() \n" - + " else \n" - + " if test.isTrue(false) then \n" - + " do test.instantFail() \n" - + " else \n" - + " do test.instantDone() \n" - + " else \n" - + " do test.instantFail() \n" - + "else \n" - + " do test.instantFail() \n" - + "var bool trig = false \n" - + "do test.resetI()\n" - + "while test.increase() != 100 && !trig \n" - + " if test.i == 50 then \n" - + " set trig = true \n" - + "if test.i != 51 then \n" // the test.increase() will first increment i to 51, and then we detect trig. - + " do test.instantFail() \n" - + "do test.resetI()\n" - + "set trig = false\n" - + "for (var int i = 0; i != 100 && !trig ; set i = test.increase() )\n" - + " if test.i == 50 then \n" - + " set trig = true \n" -// + "if test.i != 51 then \n" // require same result as with ISO C -// + " do test.instantFail() \n" - + "return " - + "}"; - this->doProgram( prog, >c ); - this->finishProgram( >c, "x"); -} - -void ProgramTest::testProgramBreak() -{ - // see if break statement works - string prog = string("program x { \n") - + "do test.resetI()\n" - + "while (test.increase() != 100)\n" - + " if test.i == 50 then {\n" - + " break\n" - + " do test.instantFail() \n" // do not reach. - + " }\n" - + "if test.i != 50 then \n" // break on 50 - + " do test.instantFail() \n" - + "do test.resetI()\n" - + "for (var int i = 0; i != 100 ; set i = test.increase() )\n" - + " if test.i != 50 then \n" - + " do nothing \n" - + " else {\n" - + " break \n" - + " do test.instantFail() \n" // do not reach. - + " }\n" - + "if test.i != 50 then \n" // break on 50 - + " do test.instantFail() \n" - + "do test.resetI()\n" - + "while test.increase() != 100 {\n" - + " while test.increase() != 100 \n" - + " if test.i == 50 then {\n" - + " break \n" - + " do test.instantFail() \n" // do not reach. - + " }\n" - + " if test.i != 50 then \n" // break on 50 - + " do test.instantFail() \n" - + " if test.i == 50 then \n" - + " break \n" - + " do test.instantFail() \n" // do not reach. - + " }\n" - + "if test.i != 50 then \n" // break on 50 - + " do test.instantFail() \n" - + "return \n" - + "}"; - this->doProgram( prog, >c ); - this->finishProgram( >c, "x"); -} - -void ProgramTest::testProgramAnd() -{ - // see if checking a remote condition works - string prog = string("program x { do test.instantDone()\n") - + "and test.instantDone() \n" - + "and test.instantDone() \n" - + " }"; - this->doProgram( prog, >c ); - this->finishProgram( >c, "x"); -} - -void ProgramTest::testProgramTry() -{ - // see if checking a remote condition works - string prog = string("program progtry { try test.instantFail()\n") - + "try instantDone() \n" - + "and test.instantFail() \n" - + "and test.instantDone() \n" - + "try test.instantDone() \n" - + "and test.instantFail() \n" - + "and totalFail() until { \n" - + " if true then continue }\n" - + "try test.instantDone() \n" - + "and test.instantFail() \n" - + "and test.instantFail() catch { \n" - + " try test.instantDone() \n" - + " and test.instantDone() \n" - + " and test.instantDone() catch {\n" - + " do instantFail()\n" - + " }\n" - + "}\n" - + "do test.resetI() \n" - + "try test.instantDone() \n" - + "and test.instantFail() \n" - + "and test.instantDone() until {\n" - + " if done then continue\n" - + " } catch { \n" - + " do test.increase()\n" - + "}\n" - + "if test.i == 0 then\n" // check if catch was reached - + " do test.totalFail()\n" - + "}"; - this->doProgram( prog, >c ); - this->finishProgram( >c, "progtry"); -} - -void ProgramTest::testProgramTask() -{ - // see if checking a remote condition works - string prog = string("export function foo {\n") - + " do assert( tvar_i == +2 ) \n" - + " do assert( tvar_i != tconst_i ) \n" - + " set tvar_i = +4\n" - + " do assert( tvar_i == +4 ) \n" - + "}\n" - + "program x { \n" - + "do assert( tvar_i == -1 ) \n" - + "do assert( tvar_i == tconst_i ) \n" - + "set tvar_i = +2\n" - + "do assert( tvar_i == +2 )\n" - + "do foo()\n" - + "}"; - this->doProgram( prog, >c ); - CPPUNIT_ASSERT_EQUAL( 4, gtc.attributes()->getAttribute("tvar_i")->get() ); - this->finishProgram( >c, "x"); -} - -void ProgramTest::testProgramUntil() -{ - // see if checking a remote condition works - string prog = string("program proguntil {\n") - +" do test.resetI()\n" - +" do test.neverDone()\n" - + "until { \n" - + " if time > 10 ms then continue \n" // test in simulation takes far less than 1 second - + "} \n" - + "do neverDone()\n" - + "until { \n" - + " if done then continue \n" - + " if test.increase() == 10 then continue \n" // we continue after 10 checks - + "} \n" - + " }"; - this->doProgram( prog, >c ); - this->finishProgram( >c, "proguntil"); -} - -void ProgramTest::testProgramUntilFail() -{ - // see if checking a remote condition works - string prog = string("program x { do test.instantFail()\n") - + "until { \n" - + " if done then continue \n" // program should go into error - + "} \n" - + " }"; - this->doProgram( prog, >c, false ); - - CPPUNIT_ASSERT( gtc.engine()->programs()->getProgramStatus("x") == ProgramInterface::Status::error ); - - this->finishProgram( >c, "x"); -} - -void ProgramTest::doProgram( const std::string& prog, TaskContext* tc, bool test ) -{ - CPPUNIT_ASSERT( tc->engine() ); - CPPUNIT_ASSERT( tc->engine()->programs()); - - Parser::ParsedPrograms pg_list; - try { - pg_list = parser.parseProgram( prog, tc ); - } - catch( const file_parse_exception& exc ) - { - CPPUNIT_ASSERT_MESSAGE( exc.what(), false ); - } - if ( pg_list.empty() ) - { - CPPUNIT_ASSERT( false ); - } - ProgramInterfacePtr pi = *pg_list.begin(); - - tc->engine()->programs()->loadProgram( pi ); - CPPUNIT_ASSERT( gtc.start() ); - CPPUNIT_ASSERT( gtc.isActive() ); - CPPUNIT_ASSERT( gtc.isRunning() ); - CPPUNIT_ASSERT( pi->start() ); - CPPUNIT_ASSERT( SimulationThread::Instance()->run(1000) ); - - if (test ) { - stringstream errormsg; - errormsg << " on line " << pi->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( pi ); - } -} - -void ProgramTest::loopProgram( ProgramInterfacePtr f) -{ - //std::cerr <getName(); - // especially handy for performance testing : - // This bypasses the processor however, does not - // measure its performance. - int loops = 100; - f->reset(); - while ( loops-- != 0 ) { - while ( !f->isStopped() && !f->inError() ) - f->execute(); - f->reset(); - //std::cerr << "."; - } -} - - -void ProgramTest::finishProgram(TaskContext* tc, std::string prog_name) -{ - CPPUNIT_ASSERT( gtask.stop() ); - CPPUNIT_ASSERT( tc->engine()->programs()->getProgram( prog_name )->stop() ); - tc->engine()->programs()->unloadProgram( prog_name ); - -} - - - diff --git a/tests/program_test.hpp b/tests/program_test.hpp deleted file mode 100644 index 5113ed66c..000000000 --- a/tests/program_test.hpp +++ /dev/null @@ -1,91 +0,0 @@ -/*************************************************************************** - tag: Peter Soetens Mon Jan 10 15:59:18 CET 2005 program_test.hpp - - program_test.hpp - description - ------------------- - begin : Mon January 10 2005 - copyright : (C) 2005 Peter Soetens - email : peter.soetens@mech.kuleuven.ac.be - - *************************************************************************** - * * - * This program is free software; you can redistribute it and/or modify * - * it under the terms of the GNU General Public License as published by * - * the Free Software Foundation; either version 2 of the License, or * - * (at your option) any later version. * - * * - ***************************************************************************/ - - -#ifndef PROGRAMTEST_H -#define PROGRAMTEST_H - -#include - -#include -#include -#include -#include - -using namespace RTT; - -class ProgramTest : public CppUnit::TestFixture -{ - CPPUNIT_TEST_SUITE( ProgramTest ); - CPPUNIT_TEST( testEmptyProgram ); - CPPUNIT_TEST( testReturnProgram ); - CPPUNIT_TEST( testParseProgram ); - CPPUNIT_TEST( testProgramFailure ); - CPPUNIT_TEST( testProgramCondition ); - CPPUNIT_TEST( testProgramAnd ); - CPPUNIT_TEST( testProgramTry ); - CPPUNIT_TEST( testProgramUntil ); - CPPUNIT_TEST( testProgramBreak ); - CPPUNIT_TEST( testProgramUntilFail ); - CPPUNIT_TEST( testProgramTask); - CPPUNIT_TEST_SUITE_END(); - - Parser parser; - TaskContext gtc; - SimulationActivity gtask; - OperationInterface* createObject( OperationInterface*, CommandProcessor* cp ); - Attribute var_i; - Constant* const_i; - bool assertBool( bool ); - bool assertMsg( bool, const std::string& msg); - int increase(); - void resetI(); - void doProgram( const std::string& prog, TaskContext*, bool test=true ); - void finishProgram( TaskContext* , std::string ); - void loopProgram( ProgramInterfacePtr ); - - bool true_genCom() { return true; } - bool false_genCom() { return false; } - bool true_gen() const { return true; } - bool false_gen() const { return false; } - - bool bool_gen( bool b ) const { return b; } - int getI() const { return i; } - - int i; -public: - ProgramTest(); - - void setUp(); - void tearDown(); - - void testEmptyProgram(); - void testReturnProgram(); - void testParseProgram(); - void testProgramTask(); - void testProgramCondition(); - void testProgramFailure(); - void testProgramAnd(); - void testProgramTry(); - void testProgramBreak(); - void testProgramUntil(); - void testProgramUntilFail(); - -}; - -#endif diff --git a/tests/property_test.cpp b/tests/property_test.cpp deleted file mode 100644 index 3f3f5f47f..000000000 --- a/tests/property_test.cpp +++ /dev/null @@ -1,404 +0,0 @@ -/*************************************************************************** - tag: Peter Soetens Tue Apr 5 16:53:26 CEST 2005 property_test.cpp - - property_test.cpp - description - ------------------- - begin : Tue April 05 2005 - copyright : (C) 2005 Peter Soetens - email : peter.soetens@mech.kuleuven.ac.be - - *************************************************************************** - * * - * This program is free software; you can redistribute it and/or modify * - * it under the terms of the GNU General Public License as published by * - * the Free Software Foundation; either version 2 of the License, or * - * (at your option) any later version. * - * * - ***************************************************************************/ - - - - - - -#include "property_test.hpp" -#include -#include -#include "MultiVector.hpp" -#include "marsh/PropertyMarshaller.hpp" -#include "marsh/PropertyDemarshaller.hpp" -#include -#include - -// Registers the fixture into the 'registry' -CPPUNIT_TEST_SUITE_REGISTRATION( PropertyTest ); - -using namespace RTT; -using namespace boost; -using namespace std; - -void -PropertyTest::setUp() -{ - intref = 99; - pi1 = new Property("pi1","pi1d", 0 ); - pi2 = new Property("pi2","pi2d", 0 ); - pi1ref = dynamic_cast< Property* >( pi1->clone() ); - pi2ref = dynamic_cast< Property* >( pi2->clone() ); -} - - -void -PropertyTest::tearDown() -{ - delete pi1; - delete pi2; - delete pi1ref; - delete pi2ref; -} - -void PropertyTest::testPrimitives() -{ - *pi1 = intref; - *pi2 = 0; - - // update semantics - pi1->update( *pi2 ); - CPPUNIT_ASSERT_EQUAL( pi2->get(), pi1->get() ); - CPPUNIT_ASSERT_EQUAL( pi1ref->getName(), pi1->getName() ); - CPPUNIT_ASSERT_EQUAL( pi1ref->getDescription(), pi1->getDescription() ); - *pi2 = 0; - - // update with PropertyBase. - CPPUNIT_ASSERT( pi1->update( pi2 ) ); - CPPUNIT_ASSERT_EQUAL( pi2->get(), pi1->get() ); - CPPUNIT_ASSERT_EQUAL( pi1ref->getName(), pi1->getName() ); - CPPUNIT_ASSERT_EQUAL( pi1ref->getDescription(), pi1->getDescription() ); - *pi2 = 0; - - // copy semantics - pi1->copy( *pi2 ); - CPPUNIT_ASSERT_EQUAL( pi2->get(), pi1->get() ); - CPPUNIT_ASSERT_EQUAL( pi2ref->getName(), pi1->getName() ); - CPPUNIT_ASSERT_EQUAL( pi2ref->getDescription(), pi1->getDescription() ); - pi1->copy( *pi1ref ); - - // copy with PropertyBase. - CPPUNIT_ASSERT( pi1->copy( pi2 ) ); - CPPUNIT_ASSERT_EQUAL( pi2->get(), pi1->get() ); - CPPUNIT_ASSERT_EQUAL( pi2ref->getName(), pi1->getName() ); - CPPUNIT_ASSERT_EQUAL( pi2ref->getDescription(), pi1->getDescription() ); - pi1->copy( pi1ref ); -} -void PropertyTest::testBags() -{ - PropertyBag bag; - - Property pf("pf","pfd", -1.0); - Property pd("pd","pdd", +1.0); - Property ps("ps","psd", "std::string"); - Property pc("pc","pcd", 'c'); - - Property subbag1("s1", "s1d"); - Property subbag2("s2", "s2d"); - - bag.add( pi1 ); - bag.add( pi2 ); - bag.add( &subbag1 ); - subbag1.set().add( &subbag2 ); - subbag1.set().add( &pf ); - subbag1.set().add( &pd ); - - subbag2.set().add( &ps ); - subbag2.set().add( &pc ); - - // non recursive search : - CPPUNIT_ASSERT( bag.find( "pf" ) == 0 ); - CPPUNIT_ASSERT( bag.find( "s1" ) == &subbag1 ); - CPPUNIT_ASSERT( bag.find( "pi1" ) == pi1 ); - - // recursive search : - CPPUNIT_ASSERT( findProperty( bag, "/pf", "/" ) == 0 ); - CPPUNIT_ASSERT( findProperty( bag, ".pi1" ) == pi1 ); // default is "." - CPPUNIT_ASSERT( findProperty( bag, "s1" ) == &subbag1 ); - CPPUNIT_ASSERT( findProperty( bag, "pi1" ) == pi1 ); - CPPUNIT_ASSERT( findProperty( bag, "/s1/s2", "/" ) == &subbag2 ); - CPPUNIT_ASSERT( findProperty( bag, "/s1/s2/ps", "/" ) == &ps ); - CPPUNIT_ASSERT( findProperty( bag, "s1.s2.pc" ) == &pc ); - -} -void PropertyTest::testBagOperations() -{ -} - -bool operator==(const std::vector& a, const std::vector& b) -{ - if ( a.size() != b.size() ) { - log(Error) << "Wrong vector sizes : " << a.size() <<" "<< b.size()< names = TypeInfoRepository::Instance()->getTypes(); - for (std::vector::iterator it = names.begin(); it != names.end(); ++it) { - PropertyBase* target; - Property bag("Result","D"); - CPPUNIT_ASSERT( TypeInfoRepository::Instance()->type( *it ) ); - target = TypeInfoRepository::Instance()->type( *it )->buildProperty("Result", "D"); - CPPUNIT_ASSERT( target ); - if ( target->getTypeInfo()->decomposeType( target->getDataSource(), bag.value() ) ) - CPPUNIT_ASSERT( target->getTypeInfo()->composeType( bag.getDataSource() , target->getDataSource() ) ); - deletePropertyBag( bag.value() ); - delete target; - } - -} - -void PropertyTest::testComposition() -{ - /** - * test vector - */ - std::vector init(33, 1.0); - Property > pvd("pvd","pvd desc", init); - Property& > pvd_cr("pvd_cr","pvd_cr desc", init); - - Property > pvd2("pvd 2","pvd desc 2"); - Property& > pvd_cr2("pvd_cr 2","pvd desc 2"); - - CPPUNIT_ASSERT( pvd.get() == init ); - CPPUNIT_ASSERT( pvd_cr.get() == init ); - CPPUNIT_ASSERT( pvd.set() == init ); - CPPUNIT_ASSERT( pvd_cr.set() == init ); - - CPPUNIT_ASSERT( pvd.getTypeInfo() ); - CPPUNIT_ASSERT( pvd.getTypeInfo() == pvd_cr.getTypeInfo() ); - // Compatible-type -assignment: - CPPUNIT_ASSERT( pvd.getTypeInfo()->composeType( pvd.getDataSource(), pvd2.getDataSource() ) ); - CPPUNIT_ASSERT( pvd.getTypeInfo()->composeType( pvd_cr.getDataSource(), pvd.getDataSource() ) ); - CPPUNIT_ASSERT( pvd.getTypeInfo()->composeType( pvd.getDataSource(), pvd_cr.getDataSource() ) ); - CPPUNIT_ASSERT( pvd.getTypeInfo()->composeType( pvd_cr.getDataSource(), pvd_cr2.getDataSource() ) ); - - Property bag("Result","Rd"); - // Decompose to property bag and back: - CPPUNIT_ASSERT( pvd.getTypeInfo()->decomposeType( pvd.getDataSource(), bag.value() ) ); - CPPUNIT_ASSERT( pvd.getTypeInfo()->composeType( bag.getDataSource(), pvd2.getDataSource() ) ); - CPPUNIT_ASSERT( pvd == pvd2 ); - pvd2.value().clear(); - deletePropertyBag( bag.value() ); - - CPPUNIT_ASSERT( pvd.getTypeInfo()->decomposeType( pvd_cr.getDataSource(), bag.value() ) ); - CPPUNIT_ASSERT( pvd.getTypeInfo()->composeType( bag.getDataSource(), pvd_cr2.getDataSource() ) ); - CPPUNIT_ASSERT( pvd_cr == pvd_cr2); - pvd_cr2.value().clear(); - deletePropertyBag( bag.value() ); - - // Cross composition. (const ref to value and vice versa) - CPPUNIT_ASSERT( pvd.getTypeInfo()->decomposeType( pvd.getDataSource(), bag.value() ) ); - CPPUNIT_ASSERT( pvd.getTypeInfo()->composeType( bag.getDataSource(), pvd_cr2.getDataSource() ) ); - CPPUNIT_ASSERT( pvd == pvd_cr2); - pvd_cr2.value().clear(); - deletePropertyBag( bag.value() ); - - CPPUNIT_ASSERT( pvd.getTypeInfo()->decomposeType( pvd_cr.getDataSource(), bag.value() ) ); - CPPUNIT_ASSERT( pvd.getTypeInfo()->composeType( bag.getDataSource(), pvd2.getDataSource() ) ); - CPPUNIT_ASSERT( pvd_cr == pvd2); - pvd2.value().clear(); - deletePropertyBag( bag.value() ); -} - - -void PropertyTest::testInit() -{ - // See if this compiles fine: - // detects collisions with other constructors... - Property pui("PUI","", 0 ); - Property pi("PI","", 0 ); - Property pb("PB","", false ); - - // Test null assignment - PropertyBase* pbase = 0; - Property p2 = pbase; - CPPUNIT_ASSERT( !p2.ready() ); - Property p3; - CPPUNIT_ASSERT( !p3.ready() ); - - p3 = pbase; - CPPUNIT_ASSERT( !p3.ready() ); - - p2 = p3; - CPPUNIT_ASSERT( !p2.ready() ); - - p2 = pi; - CPPUNIT_ASSERT( p2.ready() ); - - CPPUNIT_ASSERT(true); -} - -void PropertyTest::testUpdate() -{ - PropertyBag source; - PropertyBag target; - - Property b1("b1",""); - Property b2("b2",""); - Property p1("p1","",-1); - - Property b1c("b1",""); - Property b2c("b2",""); - Property p1c("p1","",0); - - // setup source tree - source.addProperty( &b1 ); - b1.value().addProperty( &b2 ); - b2.value().addProperty( &p1 ); - - // update case: - // setup target tree - target.addProperty( &b1c ); - b1c.value().addProperty( &b2c ); - b2c.value().addProperty( &p1c ); - - CPPUNIT_ASSERT( p1.get() != p1c.get() ); - - CPPUNIT_ASSERT( updateProperty(target, source, "b1/b2/p1", "/") ); - - CPPUNIT_ASSERT( p1.get() == -1 ); - CPPUNIT_ASSERT( p1c.get() == -1 ); - - // creation case: - target.removeProperty(&b1); - CPPUNIT_ASSERT( updateProperty(target, source, "b1/b2/p1", "/") ); - - Property* bag = target.getProperty("b1"); - CPPUNIT_ASSERT( bag ); - CPPUNIT_ASSERT( bag->getName() == "b1" ); - bag = bag->get().getProperty("b2"); - CPPUNIT_ASSERT( bag ); - CPPUNIT_ASSERT( bag->getName() == "b2" ); - - Property* res = bag->get().getProperty("p1"); - CPPUNIT_ASSERT( res ); - CPPUNIT_ASSERT( res->getName() == "p1" ); - CPPUNIT_ASSERT( res->get() == -1 ); - -} - -// This test does not yet test all types ! -void PropertyTest::testPropMarsh() -{ - std::string filename = ".property_test.cpf"; - - PropertyBag source; // to file - PropertyBag target; // from file - - Property b1("b1","b1d"); - Property b2("b2","b2d"); - Property p1("p1","p1d",-1); - - // setup source tree - source.addProperty( &b1 ); - b1.value().addProperty( &b2 ); - b2.value().addProperty( &p1 ); - - { - // scope required such that file is closed - PropertyMarshaller pm( filename ); - pm.serialize( source ); - } - - { - // scope required such that file is closed - PropertyDemarshaller pd( filename ); - CPPUNIT_ASSERT( pd.deserialize( target ) ); - } - - Property bag = target.getProperty("b1"); - CPPUNIT_ASSERT( bag.ready() ); - CPPUNIT_ASSERT( bag.getDescription() == "b1d" ); - - bag = bag.rvalue().getProperty("b2"); - CPPUNIT_ASSERT( bag.ready() ); - CPPUNIT_ASSERT( bag.getDescription() == "b2d" ); - - Property pi = bag.rvalue().getProperty("p1"); - CPPUNIT_ASSERT( pi.ready() ); - CPPUNIT_ASSERT( pi.get() == -1 ); - CPPUNIT_ASSERT( pi.getDescription() == "p1d" ); - -} - -void PropertyTest::testPropMarshVect() -{ - std::string filename = ".property_test_vect.cpf"; - - PropertyBag source; // to file - PropertyBag target; // from file - - Property > p1("p1","p1d", std::vector(7, 1.234) ); - - // setup source tree - source.addProperty( &p1 ); - - { - // scope required such that file is closed - PropertyMarshaller pm( filename ); - pm.serialize( source ); - } - - p1.set() = std::vector(3, 0.234); - { - // scope required such that file is closed - PropertyDemarshaller pd( filename ); - CPPUNIT_ASSERT( pd.deserialize( target ) ); - } - - // check bag: - Property bag = target.getProperty("p1"); - CPPUNIT_ASSERT( bag.ready() ); - CPPUNIT_ASSERT( bag.getDescription() == "p1d" ); - CPPUNIT_ASSERT( bag.rvalue().size() == 7 ); - - // update bag -> array. - CPPUNIT_ASSERT( updateProperties( source, target) ); - - //p1 = source.getProperty< std::vector >("p1"); - CPPUNIT_ASSERT( p1.ready() ); - CPPUNIT_ASSERT( p1.rvalue().size() == 7 ); - CPPUNIT_ASSERT( p1.rvalue()[0] == 1.234 ); - - // Test legacy: - deleteProperties( target ); - p1.setName("driveLimits"); - { - // scope required such that file is closed - PropertyDemarshaller pd( "property_test_vect.cpf" ); - CPPUNIT_ASSERT( pd.deserialize( target ) ); - } - bag = target.getProperty("driveLimits"); - CPPUNIT_ASSERT( bag.ready() ); - CPPUNIT_ASSERT( bag.rvalue().size() == 7 ); - - // update bag -> array. - CPPUNIT_ASSERT( updateProperties( source, target) ); - - //p1 = source.getProperty< std::vector >("p1"); - CPPUNIT_ASSERT( p1.ready() ); - //cout << p1 << endl; - CPPUNIT_ASSERT( p1.rvalue().size() == 6 ); - CPPUNIT_ASSERT( p1.rvalue()[0] == 1 ); - -} diff --git a/tests/property_test.hpp b/tests/property_test.hpp deleted file mode 100644 index 0ad99655d..000000000 --- a/tests/property_test.hpp +++ /dev/null @@ -1,76 +0,0 @@ -/*************************************************************************** - tag: Peter Soetens Tue Apr 5 16:53:26 CEST 2005 property_test.hpp - - property_test.hpp - description - ------------------- - begin : Tue April 05 2005 - copyright : (C) 2005 Peter Soetens - email : peter.soetens@mech.kuleuven.ac.be - - *************************************************************************** - * * - * This program is free software; you can redistribute it and/or modify * - * it under the terms of the GNU General Public License as published by * - * the Free Software Foundation; either version 2 of the License, or * - * (at your option) any later version. * - * * - ***************************************************************************/ - - -#ifndef PROPERTYTEST_H -#define PROPERTYTEST_H - -#include -#include -#include - -using namespace RTT; - -struct Composite { - Composite() : a(0), b(-1), c(+1) {} - void reset() { a = 0; b = -1; c = +1; } - void change() { a = -1; b=+1; c=0; } - bool isReset() { return a == 0 && b == -1 && c == +1;} - bool isChanged() { return a == -1 && b == +1 && c == 0;} - int a,b,c; -}; - -class PropertyTest : public CppUnit::TestFixture -{ - CPPUNIT_TEST_SUITE( PropertyTest ); - CPPUNIT_TEST( testPrimitives ); - CPPUNIT_TEST( testBags ); - CPPUNIT_TEST( testComposition ); - CPPUNIT_TEST( testRepository ); - CPPUNIT_TEST( testBagOperations ); - CPPUNIT_TEST( testInit ); - CPPUNIT_TEST( testUpdate ); - CPPUNIT_TEST( testPropMarsh ); - CPPUNIT_TEST( testPropMarshVect ); - CPPUNIT_TEST_SUITE_END(); - - PropertyBag bag1; - PropertyBag bag2; - PropertyBase* pb; - Property* pi1; - Property* pi2; - Property* pi1ref; - Property* pi2ref; - int intref; - Composite compref; -public: - void setUp(); - void tearDown(); - - void testPrimitives(); - void testBags(); - void testBagOperations(); - void testComposition(); - void testRepository(); - void testInit(); - void testUpdate(); - void testPropMarsh(); - void testPropMarshVect(); -}; - -#endif // PROPERTYTEST_H diff --git a/tests/property_test_vect.cpf b/tests/property_test_vect.cpf deleted file mode 100644 index 2d9582464..000000000 --- a/tests/property_test_vect.cpf +++ /dev/null @@ -1,14 +0,0 @@ - - - - - velocity limits of the axes, (rad/s) - Dimension of the Vector6 - 1 - 1 - 1 - 1 - 1 - 1 - - diff --git a/tests/state_test.cpp b/tests/state_test.cpp deleted file mode 100644 index 155d9f6d2..000000000 --- a/tests/state_test.cpp +++ /dev/null @@ -1,972 +0,0 @@ -/*************************************************************************** - tag: Peter Soetens Mon Jan 10 15:59:51 CET 2005 state_test.cpp - - state_test.cpp - description - ------------------- - begin : Mon January 10 2005 - copyright : (C) 2005 Peter Soetens - email : peter.soetens@mech.kuleuven.ac.be - - *************************************************************************** - * * - * This program is free software; you can redistribute it and/or modify * - * it under the terms of the GNU General Public License as published by * - * the Free Software Foundation; either version 2 of the License, or * - * (at your option) any later version. * - * * - ***************************************************************************/ - - - -#include -#include "state_test.hpp" -#include -#include -#include -#ifndef NOPARSER -#include -#include -#endif -#include -#include -#include -#include -#include - -using namespace std; - -// Registers the fixture into the 'registry' -CPPUNIT_TEST_SUITE_REGISTRATION( StateTest ); - - -StateTest::StateTest() - :gtc("root"), - gtask( 0.01, gtc.engine() ) -{} - - -void -StateTest::setUp() -{ - d_event = Event("d_event"); - b_event = Event("b_event"); - t_event = Event("t_event"); - - - // ltc has a test object - gtc.addObject(this->createObject("test") ); - - gtc.events()->addEvent( &d_event, "D", "a1", "arg1 D" ); - gtc.events()->addEvent( &b_event, "B", "a1", "arg1 B" ); - gtc.events()->addEvent( &t_event, "T" ); - i = 0; - SimulationThread::Instance()->stop(); -} - - -void -StateTest::tearDown() -{ - // if a test failed, we must still stop : - gtask.stop(); -} - - -bool StateTest::assertBool( bool b) { - return b; -} -bool StateTest::assertMsg( bool b, const std::string& msg) { - if ( b == false ) - cout << "Asserted :" << msg << endl; - return true; // allow to continue to check other commands. -} - -int StateTest::increase() { - return ++i; -} - -void StateTest::resetI() { - i = 0; -} - - -TaskObject* StateTest::createObject(string a) -{ - TaskObject* dat = new TaskObject(a); - - dat->methods()->addMethod( method( "assert", &StateTest::assertBool, this), - "Assert", "bool", "" ); - dat->methods()->addMethod( method( "increase", &StateTest::increase, this), - "Return increasing i" ); - dat->methods()->addMethod( method( "resetI", &StateTest::resetI, this), - "ResetI i" ); - dat->methods()->addMethod( method( "assertMsg", &StateTest::assertMsg, this), - "Assert message", "bool", "", "text", "text" ); - dat->methods()->addMethod( method( "isTrue", &StateTest::assertBool, this), - "Identity function", "bool", "" ); - dat->methods()->addMethod( method( "i", &StateTest::getI, this), - "Return the current number" ); - dat->commands()->addCommand( command( "instantDone", &StateTest::true_genCom, - &StateTest::true_gen, this, gtc.engine()->commands()), - "returns immediately" ); - dat->commands()->addCommand( command( "neverDone", &StateTest::true_genCom, - &StateTest::false_gen, this, gtc.engine()->commands()), - "returns never" ); - dat->commands()->addCommand( command( "instantNotDone", &StateTest::true_genCom, - &StateTest::true_gen, this, gtc.engine()->commands(), false), - "returns never"); - dat->commands()->addCommand( command( "instantFail", &StateTest::false_genCom, - &StateTest::true_gen, this, gtc.engine()->commands()), - "fails immediately" ); - dat->commands()->addCommand( command( "totalFail", &StateTest::false_genCom, - &StateTest::false_gen, this, gtc.engine()->commands()), - "fails in command and condition" ); - return dat; -} - - -void StateTest::testParseState() -{ - // a state which should never fail - string prog = string("StateMachine X {\n") - + " param int isten\n" - + " param bool isflse\n" - + " param bool isok\n" - + " param double isnegative\n" - + " var bool istrrue = true\n" - + " var double d_dummy = -1.0\n" - + " var int i_dummy = -1\n" - + " var bool varinit = false\n" - + " var bool b_dummy = true\n" // 10 - + " initial state INIT {\n" - // XXX bug : preconditions are not checked in the initial state. -// + " preconditions {\n" -// + " if (istrrue == false) || (isflse == true) || (isten != 10) ||( isnegative >= 0. ) then select PRE_PARAMFAIL\n" -// + " if false then select PRE_ERROR\n" -// + " if (isnegative != -1.) then select PRE_PARAMFAIL\n" -// + " if (istrrue != true) then select PRE_PARAMFAIL\n" -// + " if (isflse != false) then select PRE_PARAMFAIL\n" -// + " if (isten != 10 ) then select PRE_PARAMFAIL\n" -// + " if (d_dummy != -1.) || (i_dummy != -1) then select PRE_VARFAIL\n" -// + " }\n" - + " entry {\n" - + " set varinit = (d_dummy != -1.) || (i_dummy != -1) \n" - + " do test.instantDone()\n" - + " set d_dummy = 1.234\n" - + " set i_dummy = -2\n" - + " do test.instantDone()\n" - + " }\n" - + " handle {\n" - + " do test.instantDone()\n" // 20 - + " }\n" - + " exit {\n" - + " do test.instantDone()\n" - + " set d_dummy = 0.0\n" - + " set i_dummy = 0\n" - + " }\n" - + " transitions {\n" - + " if false then select ERROR\n" - + " if varinit == true then select PRE_VARFAIL\n" - + " if (d_dummy != 1.234) || (i_dummy != -2) then select ENTRYFAIL\n" // 30 - + " }\n" - + " transition if (istrrue == false) || (isflse == true) || (isten != 10) ||( isnegative >= 0. ) then select PARAMFAIL\n" - + " transition if isok == false then select PARAMFAIL\n" - + " transition select FINI\n" - + " transition select ERROR\n" // do not reach - + " }\n" - + " state PRE_ERROR { entry { do test.assert(false) }\n" - + " }\n" - + " state PRE_PARAMFAIL { entry { do test.assert(false) }\n" - + " }\n" - + " state PRE_VARFAIL { entry { do test.assert(false) }\n" - + " }\n" - + " state ERROR { entry { do test.assert(false) }\n" - + " }\n" - + " state PARAMFAIL {\n" - + " entry { \n" - + " do test.assertMsg( isten == 10, \"isten parameter not correctly initialised\")\n" - + " do test.assertMsg( istrrue == true, \"istrrue parameter not correctly initialised\")\n" - + " do test.assertMsg( isok == true, \"isok parameter not correctly initialised\")\n" - + " do test.assertMsg( isflse == false, \"isflse parameter not correctly initialised\")\n" - + " do test.assertMsg( true == true, \"true ident not correctly done\")\n" - + " do test.assertMsg( false == false, \"false ident not correctly done\")\n" - + " do test.assertMsg( isnegative == -1.0, \"isnegative parameter not correctly initialised\")\n" - + " }\n" - + " }\n" - + " state VARFAIL { entry { do test.assert(false) }\n" - + " }\n" - + " state EXITFAIL { entry { do test.assert(false) }\n" - + " }\n" - + " state ENTRYFAIL { entry { do test.assert(false) }\n" - + " }\n" - + " final state FINI {\n" - + " preconditions {\n" - + " if (d_dummy != 0.) || (i_dummy != 0) then select EXITFAIL\n" - + " if false then select ERROR\n" - + " }\n" - + " entry {\n" - + " do test.instantDone()\n" - + " set d_dummy = -1.\n" - + " set i_dummy = -1\n" - + " }\n" - + " handle {\n" - + " do test.instantDone()\n" - + " }\n" - + " exit {\n" - + " do test.instantDone()\n" - + " }\n" - + " transitions {\n" - + " if false then select ERROR\n" - + " select INIT\n" - + " select ERROR\n" // do not reach - + " }\n" - + " }\n" - + " }\n" - // + " RootMachine X x( isten = 10, isflse = false, isnegative = -1.0) \n" // instantiate a non hierarchical SC - + " RootMachine X x( isten = 10, isok = true, isflse=false, isnegative = -1.0) \n" // instantiate a non hierarchical SC - ; - - this->doState( prog, >c ); - this->finishState( >c, "x"); -} - -void StateTest::testStateFailure() -{ - // test _command_ (through methods though) failure detection on several places. - // it is an incomplete test, even more that parsing should fail on the second - // run since the type 'X' is defined twice. - string prog = string("StateMachine X {\n") - + " initial state INIT {\n" - + " entry {\n" - + " do test.increase()\n" // set i to i+1 - + " do test.assert( test.i() != 1)\n" // fail if i == 1 - + " }\n" - + " handle {\n" - + " do test.assert( test.i != 2)\n" - + " }\n" - + " exit {\n" - + " do test.assert( test.i != 3)\n" - + " }\n" - + " transitions {\n" - + " select FINI\n" - + " }\n" - + " }\n" - + " state ERROR { entry { do test.assert(false) }\n" - + " }\n" - + " final state FINI {\n" - + " entry {\n" - + " do test.assert( test.i != 4)\n" - + " }\n" - + " handle {\n" - + " do test.assert( test.i != 5)\n" - + " }\n" - + " exit {\n" - + " do test.assert( test.i != 6)\n" - + " }\n" - + " transitions {\n" - + " select INIT\n" - + " }\n" - + " }\n" - + " }\n" - + " RootMachine X x\n" // instantiate a non hierarchical SC - ; - - // should fail each time - while ( i < 6 ) { - this->doState( prog, >c, false ); - - // assert that an error happened : - CPPUNIT_ASSERT( gtc.engine()->states()->getStateMachineStatus("x") == StateMachine::Status::error ); - - this->finishState( >c, "x"); - } -} -void StateTest::testStateChildren() -{ - // instantiate two children and check init of vars and params - string prog = string("StateMachine Y {\n") - + " param double isnegative\n" - + " var double t = 1.0\n" - + " initial state INIT {\n" - + " entry {\n" - + " do test.instantDone()\n" - + " }\n" - + " transitions {\n" - + " if isnegative >= 0. then select PARAMFAIL\n" - + " select FINI\n" - + " }\n" - + " }\n" - + " state ERROR { entry { do test.assert(false) }\n" - + " }\n" - + " state PARAMFAIL { entry { do test.assert(false) }\n" - + " }\n" - + " state VARFAIL { entry { do test.assert(false) }\n" - + " }\n" - + " state EXITFAIL { entry { do test.assert(false) }\n" - + " }\n" - + " state ENTRYFAIL { entry { do test.assert(false) }\n" - + " }\n" - + " final state FINI {\n" - + " entry {\n" - + " do test.instantDone()\n" - + " }\n" - + " transitions {\n" - + " select INIT\n" - + " }\n" - + " }\n" - + " }\n" - + string("StateMachine Z {\n") - + " param double neg\n" - + " initial state INIT {\n" - + " transitions {\n" - + " if neg >= 0. then select PARAMFAIL\n" - + " select FINI\n" - + " }\n" - + " }\n" - + " state PARAMFAIL { entry { do test.assert(false) }\n" - + " }\n" - + " final state FINI {\n" - + " transitions {\n" - + " select INIT\n" - + " }\n" - + " }\n" - + " }\n" - + string("StateMachine X {\n") - + " param double isnegative\n" - + " var double d_dummy = -2.0\n" - + " var int i_dummy = -1\n" - + " SubMachine Y y1(isnegative = d_dummy)\n" - + " SubMachine Y y2(isnegative = -3.0)\n" - + " SubMachine Y y3(isnegative = isnegative)\n" - + " SubMachine Z z1( neg = d_dummy)\n" - + " initial state INIT {\n" - + " entry {\n" - + " do test.instantDone()\n" - + " do y1.activate()\n" - + " do y2.activate()\n" - + " do y3.activate()\n" - + " do z1.activate()\n" - + " }\n" - + " exit {\n" - + " do y1.start()\n" - + " do y2.start()\n" - + " do y3.start()\n" - + " do z1.start()\n" - + " }\n" - + " transitions {\n" - + " select FINI\n" - + " }\n" - + " }\n" - + " state ERROR { entry { do test.assert(false) }\n" - + " }\n" - + " state PARAMFAIL {\n" - + " entry { \n" - + " do test.assertMsg( y3.isnegative == isnegative, \"y3 parameter not correctly initialised\")\n" - + " do test.assertMsg( y2.isnegative == -3.0, \"y2 parameter not correctly initialised\")\n" - + " do test.assertMsg( y1.isnegative == d_dummy, \"y1 parameter not correctly initialised\")\n" - + " do test.assertMsg( z1.neg == d_dummy, \"z1 parameter not correctly initialised\")\n" - + " }\n" - + " }\n" - + " state VARFAIL { entry { do test.assert(false) }\n" - + " }\n" - + " state EXITFAIL { entry { do test.assert(false) }\n" - + " }\n" - + " state ENTRYFAIL { entry { do test.assert(false) }\n" - + " }\n" - + " final state FINI {\n" - + " entry {\n" - + " do test.instantDone()\n" - + " do y1.stop()\n" - + " do y2.stop()\n" - + " do y3.stop()\n" - + " do z1.stop()\n" - + " }\n" - + " exit {\n" - + " do test.instantDone()\n" - + " do y1.deactivate()\n" - + " do y2.deactivate()\n" - + " do y3.deactivate()\n" - + " do z1.deactivate()\n" - + " }\n" - + " transitions {\n" - + " if z1.neg != d_dummy then select PARAMFAIL\n" - + " if y1.isnegative != d_dummy then select PARAMFAIL\n" - + " if y2.isnegative != -3.0 then select PARAMFAIL\n" - + " if y3.isnegative != isnegative then select PARAMFAIL\n" - + " select INIT\n" - + " }\n" - + " }\n" - + " }\n" - + " RootMachine X x( isnegative = -1.0) \n" // instantiate a hierarchical SC - ; - this->doState( prog, >c ); - this->finishState( >c, "x"); -} - -void StateTest::testStateEmpty() -{ - // test processing of completely empty states - string prog = string("StateMachine X {\n") - + " initial state INIT {\n" - + " transitions {\n" - + " select TEST;\n" // only a transition - + " }\n" - + " }\n" - + " state TEST {\n" // not even used - + " }\n" - + " final state FINI {\n" // completely empty - + " }\n" - + " }\n" - + " RootMachine X x\n" // instantiate a non hierarchical SC - ; - this->doState( prog, >c ); - this->finishState( >c, "x"); -} - -void StateTest::testStateTransitions() -{ - // test processing of transition statements. - string prog = string("StateMachine X {\n") - + " initial state INIT {\n" - + " var int i = 0;\n" // transition counter - + " var int j = 0;\n" // entry counter - + " var int k = 0;\n" // run counter - + " entry {\n" - + " set j = j + 1\n" - + " }\n" - + " run {\n" - + " set k = k + 1\n" - + " }\n" - + " transitions {\n" - + " if i < 5 then {\n" - + " set i = i + 1;\n" // execute this program - + " } select INIT\n" // test EXPLICIT transition to self: no entry/exit. - + " if i < 10 then {\n" - + " set i = i + 1;\n" // execute this program - + " }\n" // test IMPLICIT transition to self: no entry/exit. - + " if i < 10 then {\n" - + " } select TRANS_SHOULD_NOT_CHECK\n" // should never be reached. - + " if i == 10 then {\n" - + " set i = i + 1;\n" // execute this program - + " } select TEST_ENTRY\n" - + " }\n" - + " }\n" - + " state TEST_ENTRY {\n" // test if entry was executed one time - + " transitions {\n" - + " if k != i then {\n" - + " } select RUN_FAILED\n" - + " if j != 1 then {\n" - + " } select ENTRY_FAILED\n" - + " else select FINI\n" - + " }\n" - + " }\n" - + " state TRANS_SHOULD_NOT_CHECK {\n" // failure state - + " entry { do test.assert(false); }\n" - + " }\n" - + " state ENTRY_FAILED {\n" // failure state - + " entry { do test.assert(false); }\n" - + " }\n" - + " state RUN_FAILED {\n" // failure state - + " entry { do test.assert(false); }\n" - + " }\n" - + " final state FINI {\n" // Success state. - + " }\n" - + " }\n" - + " RootMachine X x\n" // instantiate a non hierarchical SC - ; - this->doState( prog, >c ); - CPPUNIT_ASSERT( gtc.engine()->states()->getStateMachine( "x" )->inState("FINI") ); - this->finishState( >c, "x"); -} - -void StateTest::testStateGlobalTransitions() -{ - // test processing of transition statements. - string prog = string("StateMachine X {\n") - + " var int gi = 0;\n" // transition counter - + " transitions {\n" - - + " if gi < 5 then {\n" - + " set gi = gi + 1;\n" // execute this program - + " } select INIT\n" // test EXPLICIT transition to self: no entry/exit. - - + " if gi < 10 then {\n" - + " if gi < 5 then do test.assert(false);\n" - + " set gi = gi + 1;\n" // execute this program - + " }\n" // test IMPLICIT transition to self: no entry/exit. - + " if gi < 10 then {\n" - + " do test.assert(false);\n" - + " } select TRANS_SHOULD_NOT_CHECK\n" // should never be reached. - + " if gi >= 10 then {\n" - + " } select FINI\n" // we must be checked before - + " }\n" - + " initial state INIT {\n" - + " var int i = 0;\n" // transition counter - + " var int j = 0;\n" // entry counter - + " var int k = 0;\n" // run counter - + " entry {\n" - + " set j = j + 1\n" - + " }\n" - + " run {\n" - + " set k = k + 1\n" - + " }\n" - + " transitions {\n" - + " if i < 5 then {\n" - + " set i = i + 1;\n" // execute this program - + " } select INIT\n" // test EXPLICIT transition to self: no entry/exit. - + " if i < 10 then {\n" - + " set i = i + 1;\n" // execute this program - + " }\n" // test IMPLICIT transition to self: no entry/exit. - + " if i < 10 then {\n" - + " } select TRANS_SHOULD_NOT_CHECK\n" // should never be reached. - + " }\n" - + " }\n" - + " state TRANS_SHOULD_NOT_CHECK {\n" // failure state - + " entry { do test.assert(false); }\n" - + " }\n" - + " state ENTRY_FAILED {\n" // failure state - + " entry { do test.assert(false); }\n" - + " }\n" - + " state RUN_FAILED {\n" // failure state - + " entry { do test.assert(false); }\n" - + " }\n" - + " final state FINI {\n" // Success state. - + " }\n" - + " }\n" - + " RootMachine X x\n" // instantiate a non hierarchical SC - ; - this->doState( prog, >c ); - CPPUNIT_ASSERT( gtc.engine()->states()->getStateMachine( "x" )->inState("FINI") ); - this->finishState( >c, "x"); -} - - -void StateTest::testStateSubStateVars() -{ - // test get/set access of substate variables and parameters - string prog = string("StateMachine Y {\n") - + " param double isnegative\n" - + " var double t = 1.0\n" - + " initial state INIT {\n" - + " transitions {\n" - + " if isnegative >= 0. then select PARAMFAIL\n" - + " if t >= 0. then select VARFAIL\n" - + " select FINI\n" - + " }\n" - + " exit { set isnegative = +1.0 }\n" - + " }\n" // 11 - + " state ERROR { entry { do test.assert(false) }\n" - + " }\n" - + " state PARAMFAIL { entry { do test.assert(false) }\n" - + " }\n" - + " state VARFAIL { entry { do test.assert(false) }\n" - + " }\n" - + " state EXITFAIL { entry { do test.assert(false) }\n" - + " }\n" - + " state ENTRYFAIL { entry { do test.assert(false) }\n" - + " }\n" // 21 - + " final state FINI {\n" - + " transitions {\n" - + " if isnegative <= 0. then select PARAMFAIL\n" - + " }\n" - + " }\n" - + " }\n" - + string("StateMachine X {\n") - + " param double isnegative\n" - + " var double d_dummy = -2.0\n" - + " var int i_dummy = -1\n" //31 - + " SubMachine Y y1(isnegative = d_dummy)\n" - + " initial state INIT {\n" - + " entry {\n" - + " do y1.activate()\n" - + " set y1.t = -1.0 \n" - + " }\n" - + " exit {\n" - + " do y1.start()\n" - + " }\n" - + " transitions {\n" - + " select FINI\n" - + " }\n" - + " }\n" - + " final state FINI {\n" - + " entry {\n" - + " do y1.stop()\n" - + " }\n" - + " exit {\n" - + " set y1.isnegative = -1.0 \n" - + " do y1.deactivate()\n" - + " }\n" - + " transitions {\n" - + " select INIT\n" - + " }\n" - + " }\n" - + " }\n" - + " RootMachine X x( isnegative = -1.0) \n" // instantiate a hierarchical SC - ; - - this->doState( prog, >c ); - CPPUNIT_ASSERT( gtc.engine()->states()->getStateMachine( "x" )->inState("FINI") ); - this->finishState( >c, "x"); -} - -void StateTest::testStateSubStateCommands() -{ - // test get/set access of substate variables and parameters - string prog = string("StateMachine Y {\n") - + " param double isnegative\n" - + " var double t = 1.0\n" - + " initial state INIT {\n" - + " transitions {\n" - + " if isnegative < 0. then select ISNEGATIVE\n" - + " if t >= 0. then select ISPOSITIVE\n" - + " select DEFAULT\n" - + " }\n" - + " }\n" - + " state ISNEGATIVE {\n" - + " transitions {\n" - + " select INIT\n" - + " }\n" - + " }\n" - + " state ISPOSITIVE {\n" - + " transitions {\n" - + " select INIT\n" - + " }\n" - // 20 : - + " }\n" - + " state DEFAULT {\n" - + " transitions {\n" - + " select FINI\n" - + " }\n" - + " }\n" - + " final state FINI {\n" - + " }\n" - + " }\n" - + string("StateMachine X {\n") // 1 - + " SubMachine Y y1(isnegative = -1.0)\n" - + " initial state INIT {\n" - + " entry {\n" - + " set y1.t = -1.0 \n" - + " do y1.activate()\n" - + " do y1.requestState(\"ISNEGATIVE\")\n" - + " do test.assert( y1.inState(\"ISNEGATIVE\") )\n" - + " do y1.requestState(\"INIT\")\n" - + " do test.assert( y1.inState(\"INIT\") )\n" - + " set y1.isnegative = +1.0 \n" - + " try y1.requestState(\"ISNEGATIVE\") \n " - + " catch \n{\n" - + " do test.assert( y1.inState(\"INIT\") )\n" // do not leave INIT - + " }\n" - + " do test.assert( y1.inState(\"INIT\") )\n" // do not leave INIT - + " do y1.requestState(\"FINI\")\n" // request final state - + " do test.assert( y1.inState(\"FINI\") )\n" - + " }\n" - + " exit {\n" - + " do y1.requestState(\"INIT\")\n" // request initial state - + " do test.assert( y1.inState(\"INIT\") )\n" - + " set y1.isnegative = +1.0 \n" - + " set y1.t = -1.0 \n" - + " do y1.start()\n" // must reach FINI after a while. - + " while ! y1.inState(\"FINI\") \n" - + " do nothing\n" - + " }\n" - + " transitions {\n" - + " select FINI\n" - + " }\n" - + " }\n" - + " final state FINI {\n" - + " entry {\n" - + " do y1.stop()\n" - + " }\n" - + " exit {\n" - + " do y1.deactivate()\n" - + " }\n" - + " transitions {\n" - + " select INIT\n" - + " }\n" - + " }\n" - + " }\n" - + " RootMachine X x() \n" // instantiate a hierarchical SC - ; - - this->doState( prog, >c ); - this->finishState( >c, "x"); -} - -void StateTest::testStateEvents() -{ - // test event reception in sub states. - string prog = string("StateMachine Y {\n") - + " var double t = 0.0\n" - + " var double et = 0.0\n" - + " var bool eb = false\n" - + " transition t_event() select TESTSELF\n" // test self transition - + " transition d_event(et)\n" - + " if et < 0. then select ISNEGATIVE\n" - + " else select ISPOSITIVE\n" - + " initial state INIT {\n" - + " transition b_event(eb)\n" - + " if eb == false then select ISFALSE\n" - + " else select ISTRUE\n" - + " }\n" - + " state ISNEGATIVE {\n" - + " transitions {\n" - + " select INIT\n" - + " }\n" - + " }\n" - + " state ISPOSITIVE {\n" - + " transitions {\n" - + " select INIT\n" // 20 - + " }\n" - + " }\n" - + " state ISTRUE {\n" - + " transitions {\n" - + " select INIT\n" - + " }\n" - + " }\n" - + " state ISFALSE {\n" - + " transitions {\n" - + " select INIT\n" - + " }\n" - + " }\n" - + " state TESTSELF {\n" - + " entry {\n" - + " set eb = !eb\n" - + " }\n" - + " transition t_event() select TESTSELF\n" // does not execute entry {} - + " transition b_event(eb) { set eb = true; }\n" - + " transition select INIT\n" - + " }\n" - + " final state FINI {\n" - + " }\n" - + " }\n" // 40 - + string("StateMachine X {\n") // 1 - + " SubMachine Y y1()\n" - + " initial state INIT {\n" - + " run {\n" - // + " do test.assert(false)\n" - + " do y1.activate()\n" - + " do d_event(-1.0)\n" - + " do nothing\n" - + " do test.assert( !y1.inState(\"INIT\") )\n" - + " do test.assert( !y1.inState(\"ISPOSITIVE\") )\n" - + " do test.assert( y1.inState(\"ISNEGATIVE\") )\n" - + " do y1.requestState(\"INIT\")\n" - + " do test.assert( y1.inState(\"INIT\") )\n" - + " do d_event(+1.0)\n" - + " do nothing\n" - + " if ( !y1.inState(\"ISPOSITIVE\") ) then\n" - + " do test.assertMsg( false, y1.getState() )\n" // 15 - + " do test.assert( y1.inState(\"ISPOSITIVE\") )\n" - + " do y1.requestState(\"INIT\")\n" - + " do test.assert( y1.inState(\"INIT\") )\n" - + " do b_event(true)\n" - + " do nothing\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" - + " do 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" - // test self transitions - + " set y1.eb = true;\n" - + " do t_event()\n" - + " do nothing\n" - + " do test.assert( !y1.inState(\"INIT\") )\n" - + " do test.assert( !y1.inState(\"ISPOSITIVE\") )\n" - + " do test.assert( !y1.inState(\"ISNEGATIVE\") )\n" - + " do test.assert( y1.inState(\"TESTSELF\") )\n" - + " do test.assert( y1.eb == false )\n" - + " do t_event()\n" - + " do nothing\n" - + " do test.assert( y1.inState(\"TESTSELF\") )\n" - + " do test.assert( y1.eb == false )\n" // no entry - + " do b_event(true)\n" - + " do nothing\n" - + " do test.assert( y1.inState(\"TESTSELF\") )\n" - + " do test.assert( y1.eb == true )\n" - + " do y1.requestState(\"INIT\")\n" - + " do test.assert( y1.inState(\"INIT\") )\n" - //+ " do y1.deactivate()\n" - + " }\n" - + " transitions {\n" - + " select FINI\n" - + " }\n" - + " }\n" - + " final state FINI {\n" - + " entry {\n" - + " do y1.deactivate()\n" - //+ " do test.assert(false)\n" - + " }\n" - + " transitions {\n" - + " select INIT\n" - + " }\n" - + " }\n" - + " }\n" - + " RootMachine X x() \n" // instantiate a hierarchical SC - ; - - this->doState( prog, >c ); - //CPPUNIT_ASSERT( gtc.engine()->states()->getStateMachine( "x" )->inState("FINI") ); - this->finishState( >c, "x"); -} - -void StateTest::testStateUntil() -{ -// this->doState( prog, >c ); -// this->finishState( >c, "x"); -} - -void StateTest::testStateUntilFail() -{ -// this->doState( prog, >c, false ); - -// CPPUNIT_ASSERT( gprocessor.getStateMachineStatus("x") == Processor::StateMachineStatus::error ); - -// this->finishState( >c, "x"); -} - -void StateTest::doState( const std::string& prog, TaskContext* tc, bool test ) -{ - CPPUNIT_ASSERT( tc->engine() ); - CPPUNIT_ASSERT( tc->engine()->states()); - -#if 0 - // Classical way: use parser directly. - Parser::ParsedStateMachines pg_list; - try { - pg_list = parser.parseStateMachine( prog, tc ); - } - catch( const file_parse_exception& exc ) - { - CPPUNIT_ASSERT_MESSAGE( exc.what(), false ); - } - catch( const parse_exception& exc ) - { - CPPUNIT_ASSERT_MESSAGE( exc.what(), false ); - } - catch( ... ) { - CPPUNIT_ASSERT_MESSAGE( "Uncaught Parse Exception", false ); - } - if ( pg_list.empty() ) - { - CPPUNIT_ASSERT( false ); - } -#endif - // Alternative way: test ScriptingAccess as well. - try { - tc->scripting()->loadStateMachines( prog, std::string("state_test.cpp"), true ); - } - catch( const file_parse_exception& exc ) - { - CPPUNIT_ASSERT_MESSAGE( exc.what(), false ); - } - catch( const parse_exception& exc ) - { - CPPUNIT_ASSERT_MESSAGE( exc.what(), false ); - } - catch( const program_load_exception& e) - { - CPPUNIT_ASSERT_MESSAGE( e.what(), false ); - } - catch( const std::exception& e ) { - CPPUNIT_ASSERT_MESSAGE( e.what(), false ); - CPPUNIT_ASSERT_MESSAGE( "Uncaught Processor load exception", false ); - } - CPPUNIT_ASSERT( gtask.start() ); - StateMachinePtr sm = tc->engine()->states()->getStateMachine("x"); - CPPUNIT_ASSERT( sm ); - 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 '"+sm->getName()+"' did not have effect.", sm->isActive() ); -// cerr << "After activate :"<getPeer("states")->getPeer("x")->debug(true); - CPPUNIT_ASSERT( gtc.engine()->commands()->process( cs ) != 0 ); -// while (1) - CPPUNIT_ASSERT( SimulationThread::Instance()->run(1000) ); - delete ca; - delete cs; -// cerr << "After run :"<getPeer("states")->getPeer("x")->debug(true); -// // tc->getPeer("__states")->getPeer("X")->debug(false); -// if( tc->getPeer("__states")->getPeer("Y")) -// 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; - - if (test ) { - // check error status of parent : - CPPUNIT_ASSERT_MESSAGE( "Error : State Context '"+sm->getName()+"' did not get activated.", sm->isActive() ); - stringstream errormsg; - int line = sm->getLineNumber(); - errormsg <<" in StateMachine "+sm->getName() - <<" in state "<< sm->currentState()->getName() - <<" on line " << line <<" of that StateMachine:"<getText() ); - int cnt = 1; - while ( cnt++ " << sline << endl; - if ( sm->inError() ) { - RTT::detail::DumpObject( tc ); - } - CPPUNIT_ASSERT_MESSAGE( "Runtime error (inError() == true) encountered" + errormsg.str(), sm->inError() == false ); - // check error status of all children: - 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 StateMachine."< " << sline << endl; - else - cerrormsg <<" (deactivated) on line " << (*clit)->getLineNumber() <<" of that StateMachine."< " << sline << endl; - CPPUNIT_ASSERT_MESSAGE( "Runtime error (inError() == true) encountered in child "+(*clit)->getName() + cerrormsg.str(), (*clit)->inError() == false ); - ++clit; - } - } -} - -void StateTest::finishState(TaskContext* tc, std::string prog_name) -{ - StateMachinePtr sm = tc->engine()->states()->getStateMachine(prog_name); - CPPUNIT_ASSERT( sm ); - tc->engine()->states()->getStateMachine( prog_name )->stop(); - CPPUNIT_ASSERT( SimulationThread::Instance()->run(500) ); - stringstream errormsg; - errormsg << " on line " << sm->getLineNumber() <<", status is "<< tc->engine()->states()->getStateMachineStatusStr(prog_name) < " << sline << endl;; - CPPUNIT_ASSERT_MESSAGE( "StateMachine stalled " + errormsg.str(), sm->isStopped() ); - // 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->engine()->states()->getStateMachine( prog_name )->deactivate() ); - CPPUNIT_ASSERT( SimulationThread::Instance()->run(200) ); - 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->engine()->states()->unloadStateMachine( prog_name ); - } - catch( const program_unload_exception& e) - { - CPPUNIT_ASSERT_MESSAGE( e.what(), false ); - } - catch( ... ) { - CPPUNIT_ASSERT_MESSAGE( "Uncaught Processor unload exception", false ); - } - -} - - - diff --git a/tests/state_test.hpp b/tests/state_test.hpp deleted file mode 100644 index 3b8752f0a..000000000 --- a/tests/state_test.hpp +++ /dev/null @@ -1,97 +0,0 @@ -/*************************************************************************** - tag: Peter Soetens Mon Jan 10 15:59:18 CET 2005 state_test.hpp - - state_test.hpp - description - ------------------- - begin : Mon January 10 2005 - copyright : (C) 2005 Peter Soetens - email : peter.soetens@mech.kuleuven.ac.be - - *************************************************************************** - * * - * This program is free software; you can redistribute it and/or modify * - * it under the terms of the GNU General Public License as published by * - * the Free Software Foundation; either version 2 of the License, or * - * (at your option) any later version. * - * * - ***************************************************************************/ - - -#ifndef STATETEST_H -#define STATETEST_H - -#include - -//#define NOPARSER -#ifndef NOPARSER -#include -#endif - -#include -#include -#include - -using namespace RTT; -using namespace RTT; - -class StateTest : public CppUnit::TestFixture -{ - CPPUNIT_TEST_SUITE( StateTest ); - CPPUNIT_TEST( testParseState ); - //CPPUNIT_TEST( testStateFailure ); - CPPUNIT_TEST( testStateChildren ); - CPPUNIT_TEST( testStateEmpty ); - CPPUNIT_TEST( testStateSubStateVars ); - CPPUNIT_TEST( testStateSubStateCommands ); - CPPUNIT_TEST( testStateEvents ); - CPPUNIT_TEST( testStateTransitions ); - CPPUNIT_TEST( testStateGlobalTransitions ); -// CPPUNIT_TEST( testStateUntilFail ); - CPPUNIT_TEST_SUITE_END(); - -#ifndef NOPARSER - Parser parser; -#endif - TaskContext gtc; - SimulationActivity gtask; - Event d_event; - Event b_event; - Event t_event; - TaskObject* createObject(std::string); - bool assertBool( bool ); - bool assertMsg( bool, const std::string& msg); - int increase(); - void resetI(); - void doState( const std::string& prog, TaskContext*, bool test=true ); - void finishState( TaskContext* , std::string ); - - bool true_genCom() { return true; } - bool false_genCom() { return false; } - bool true_gen() const { return true; } - bool false_gen() const { return false; } - - bool bool_gen( bool b ) const { return b; } - int getI() const {return i;} - int i; - std::string sline; -public: - StateTest(); - - void setUp(); - void tearDown(); - - void testParseState(); - void testStateFailure(); - void testStateChildren(); - void testStateEmpty(); - void testStateSubStateVars(); - void testStateSubStateCommands(); - void testStateEvents(); - void testStateUntil(); - void testStateUntilFail(); - void testStateTransitions(); - void testStateGlobalTransitions(); - -}; - -#endif diff --git a/tests/tasks_multiple_test.cpp b/tests/tasks_multiple_test.cpp deleted file mode 100644 index 28dcd65fc..000000000 --- a/tests/tasks_multiple_test.cpp +++ /dev/null @@ -1,168 +0,0 @@ -/*************************************************************************** - tag: Peter Soetens Mon Jan 10 15:59:50 CET 2005 tasks_multiple_test.cpp - - tasks_multiple_test.cpp - description - ------------------- - begin : Mon January 10 2005 - copyright : (C) 2005 Peter Soetens - email : peter.soetens@mech.kuleuven.ac.be - - *************************************************************************** - * * - * This program is free software; you can redistribute it and/or modify * - * it under the terms of the GNU General Public License as published by * - * the Free Software Foundation; either version 2 of the License, or * - * (at your option) any later version. * - * * - ***************************************************************************/ - - - -#include "tasks_multiple_test.hpp" -#include -#include "Logger.hpp" - -#include -using namespace std; -using namespace RTT; - -// Registers the fixture into the 'registry' -CPPUNIT_TEST_SUITE_REGISTRATION( ActivitiesMultipleTest ); - - void ActivitiesMultipleTest::setUp() - { - nr_of_p = TimerThread::MAX_ACTIVITIES/2; - nr_of_np = TimerThread::MAX_ACTIVITIES/2; - runningP = 1; - runningNp = 1; // see step() why it's 1 and not 0 - errInitNP = "Not all NonPreemptibleActivity::init() or finalize() functions were called\n"; - errStepNP = "Not all NonPreemptibleActivity::step() functions were called\n"; - errFinNP = "Not all NonPreemptibleActivity::finalize() or finalize() functions were called\n"; - errInitP ="Not all PreemptibleActivity::init() functions were called\n"; - errStepP ="Not all PreemptibleActivity::step() functions were called\n"; - errFinP ="Not all PreemptibleActivity::finalize() functions were called\n"; - - log(Info) << "Creating "<< nr_of_np << " High priority and "<< nr_of_p << " Low priority activities."<start() ); - } - for (PI i=p_tasks.begin(); i != p_tasks.end(); ++i) - { - CPPUNIT_ASSERT( (*i)->start() ); - } - - int runs = 0; - - // we lower the 'load' if the period is too short. - // this is a bit arbitrary. - int correction = 1; - - while ( runs++ != 100/correction ) { - if ( np_tasks[runningNp]->isRunning() ) - CPPUNIT_ASSERT( np_tasks[runningNp]->stop() ); - if ( !np_tasks[runningNp - 1]->isRunning() ) - CPPUNIT_ASSERT( np_tasks[runningNp - 1]->start() ); - - if ( p_tasks[runningP]->isRunning() ) - CPPUNIT_ASSERT( p_tasks[runningP]->stop() ); - if ( !p_tasks[runningP - 1]->isRunning() ) - CPPUNIT_ASSERT( p_tasks[runningP - 1]->start() ); - - if ( ++runningP == nr_of_p) runningP = 1; - if ( ++runningNp == nr_of_np) runningNp = 1; - if ( runs % (20/correction) == 0 ) - sleep(1); - } - - for (NPI i=np_tasks.begin(); i != np_tasks.end(); ++i) - { - if ( (*i)->isRunning() ) - CPPUNIT_ASSERT( (*i)->stop() ); - } - for (PI i=p_tasks.begin(); i != p_tasks.end(); ++i) - { - if ( (*i)->isRunning() ) - CPPUNIT_ASSERT( (*i)->stop() ); - } - - for (unsigned int i=0; i < nr_of_np; ++i) - { - CPPUNIT_ASSERT_EQUAL( np_tasks[i]->nrOfOKStarts(), np_tasks[i]->nrOfInits() ); - //CPPUNIT_ASSERT_EQUAL( np_tasks[i]->nrOfOKStarts() , np_tasks[i]->nrOfStarts() ); - - CPPUNIT_ASSERT_EQUAL( np_tasks[i]->nrOfOKStops(), np_tasks[i]->nrOfFinals() ); - //CPPUNIT_ASSERT_EQUAL( np_tasks[i]->nrOfOKStops() , np_tasks[i]->nrOfStops() ); - } - for (unsigned int i=0; i < nr_of_p; ++i) - { - CPPUNIT_ASSERT_EQUAL( p_tasks[i]->nrOfOKStarts(), p_tasks[i]->nrOfInits() ); - //CPPUNIT_ASSERT_EQUAL( p_tasks[i]->nrOfOKStarts(), p_tasks[i]->nrOfStarts() ); - CPPUNIT_ASSERT_EQUAL( p_tasks[i]->nrOfOKStops(), p_tasks[i]->nrOfFinals() ); - //CPPUNIT_ASSERT_EQUAL( p_tasks[i]->nrOfOKStops(), p_tasks[i]->nrOfStops() ); - } - - int totInit=0, totSteps=0, totFins=0; - - // exclude first and last one from checking - for (unsigned int i=1; i < nr_of_np-1; ++i) - { - totInit += np_tasks[i]->nrOfInits(); - totSteps += np_tasks[i]->nrOfSteps(); - totFins += np_tasks[i]->nrOfFinals(); - } - CPPUNIT_ASSERT_MESSAGE( errInitNP, totInit == totFins); - CPPUNIT_ASSERT_MESSAGE( errStepNP, totSteps >= totInit ); - //CPPUNIT_ASSERT_MESSAGE(errFinNP, totFins == (nr_of_np-2) * 10 ); - - totInit = totSteps = totFins = 0; - - for (unsigned int i=1; i < nr_of_p-1; ++i) - { - totInit += p_tasks[i]->nrOfInits(); - totSteps += p_tasks[i]->nrOfSteps(); - totFins += p_tasks[i]->nrOfFinals(); - } - CPPUNIT_ASSERT_MESSAGE(errInitP,totInit == totFins ); - CPPUNIT_ASSERT_MESSAGE(errStepP,totSteps >= totInit ); - //CPPUNIT_ASSERT_MESSAGE(errFinP, totFins == (nr_of_p-2) * 10 ); - } - - void ActivitiesMultipleTest::tearDown() - { - // stop to be sure that task does not access memory during destruction. - for (NPI i=np_tasks.begin(); i != np_tasks.end(); ++i) - { - (*i)->stop(); - delete *i; - } - for (PI i=p_tasks.begin(); i != p_tasks.end(); ++i) - { - (*i)->stop(); - delete *i; - } - } - - diff --git a/tests/tasks_multiple_test.hpp b/tests/tasks_multiple_test.hpp deleted file mode 100644 index f5aa31357..000000000 --- a/tests/tasks_multiple_test.hpp +++ /dev/null @@ -1,120 +0,0 @@ -/*************************************************************************** - tag: Peter Soetens Mon Jan 10 15:59:18 CET 2005 tasks_multiple_test.hpp - - tasks_multiple_test.hpp - description - ------------------- - begin : Mon January 10 2005 - copyright : (C) 2005 Peter Soetens - email : peter.soetens@mech.kuleuven.ac.be - - *************************************************************************** - * * - * This program is free software; you can redistribute it and/or modify * - * it under the terms of the GNU General Public License as published by * - * the Free Software Foundation; either version 2 of the License, or * - * (at your option) any later version. * - * * - ***************************************************************************/ - - - -#ifndef TASKS_MULTIPLE_TEST_HPP -#define TASKS_MULTIPLE_TEST_HPP - -#include - -#include - -using namespace RTT; - - -template -class DummyTask : public T -{ - unsigned int inits; - unsigned int steps; - unsigned int fins; - - unsigned int starts; - unsigned int stops; - unsigned int okstarts; - unsigned int okstops; -public: - DummyTask(int prio, double period) - : T(prio, period), - inits(0), steps(0), fins(0), - starts(0), stops(0), - okstarts(0), okstops(0) {} - - bool start() { - ++starts; - if ( T::start() ) { - ++okstarts; - return true; - } - return false; - } - bool stop() { - ++stops; - if ( T::stop() ) { - ++okstops; - return true; - } - return false; - } - bool initialize() { ++inits; return true;} - void step() { ++steps; } - void finalize() { ++fins; } - unsigned int nrOfStarts() { return starts;} - unsigned int nrOfOKStarts() { return okstarts;} - unsigned int nrOfInits() { return inits;} - unsigned int nrOfSteps() { return steps;} - unsigned int nrOfFinals() { return fins;} - unsigned int nrOfStops() { return stops;} - unsigned int nrOfOKStops() { return okstops;} -}; - -typedef DummyTask DummyPTask; -typedef DummyTask DummyNPTask; - -/** - * Test for starting and stopping tasks - */ -class ActivitiesMultipleTest - : public CppUnit::TestFixture -{ -public: - CPPUNIT_TEST_SUITE( ActivitiesMultipleTest ); - // Test Many Activities : - CPPUNIT_TEST( testMultiple ); - CPPUNIT_TEST_SUITE_END(); - -public: - void setUp(); - - void testMultiple(); - - void tearDown(); - - std::vector np_tasks; - - typedef std::vector::iterator NPI; - typedef std::vector::iterator PI; - - std::vector p_tasks; - - unsigned int nr_of_p; - unsigned int nr_of_np; - - unsigned int runningP; - unsigned int runningNp; - - std::string errInitNP; - std::string errStepNP; - std::string errFinNP; - std::string errInitP; - std::string errStepP; - std::string errFinP; -}; - -#endif diff --git a/tests/tasks_test.cpp b/tests/tasks_test.cpp deleted file mode 100644 index c13d1534f..000000000 --- a/tests/tasks_test.cpp +++ /dev/null @@ -1,391 +0,0 @@ -/*************************************************************************** - tag: Peter Soetens Mon Jan 10 15:59:49 CET 2005 tasks_test.cpp - - tasks_test.cpp - description - ------------------- - begin : Mon January 10 2005 - copyright : (C) 2005 Peter Soetens - email : peter.soetens@mech.kuleuven.ac.be - - *************************************************************************** - * * - * This program is free software; you can redistribute it and/or modify * - * it under the terms of the GNU General Public License as published by * - * the Free Software Foundation; either version 2 of the License, or * - * (at your option) any later version. * - * * - ***************************************************************************/ - - - -#include "tasks_test.hpp" -#include -#include - -#include -#include - -#include - -using namespace std; -using namespace boost; - -// Registers the fixture into the 'registry' -CPPUNIT_TEST_SUITE_REGISTRATION( ActivitiesTest ); - -using namespace RTT; -using namespace RTT::detail; - -struct TestOverrun - : public RTT::OS::RunnableInterface -{ - bool fini; - bool initialize() { fini = false; return true; } - - void step() { - sleep(1); - } - - void finalize() { - fini = true; - } -}; - -struct TestPeriodic - : public RTT::OS::RunnableInterface -{ - int overfail, underfail, succ; - bool stepped; - - TimeService::ticks ts; - - TestPeriodic() - : overfail(0), underfail(0), succ(0), stepped(false) - { - } - - bool initialize() { - this->reset(); - return true; - } - void step() { - if (stepped == false ) { - ts = TimeService::Instance()->getTicks(); - stepped = true; - } else { - TimeService::Seconds s = TimeService::Instance()->secondsSince( ts ); - if ( s < this->getThread()->getPeriod() *0.9 ) { // if elapsed time is smaller than 10% of period, something went wrong - ++underfail; - //rtos_printf("UnderFailPeriod: %f \n", s); - } - else if ( s > this->getThread()->getPeriod() *1.1 ) { // if elapsed time is smaller than 10% of period, something went wrong - ++overfail; - //rtos_printf("OverFailPeriod: %f \n", s); - } - else { - ++succ; - //rtos_printf("SuccPeriod: %f \n", s); - } - ts = TimeService::Instance()->getTicks(); - } - } - void finalize() { - if (overfail || underfail) - cerr <<"overfail is:"<reset(res); - } - - bool initialize() { - init = true; - return result; - } - void step() { - stepped = true; - } - void finalize() { - fini = true; - } - - void reset(bool res) { - result = res; - init = false; - stepped = false; - fini = false; - } -}; - -struct TestAllocate - : public RunnableInterface -{ - std::vector v; - char* c; - std::string s; - - bool initialize() { - c = 0; - return true; - } - void step() { - v.resize( 0 ); - v.resize( 1025, std::string("Goodbye Memory") ); - delete[] c; - c = new char[1025]; - s = "Hello World "; - s += s; - s += s; - } - void finalize() { - delete[] c; - v.resize(0); - } -}; - -struct TestSelfRemove - : public RunnableInterface -{ - int c; - bool fini; - bool initialize() { - c = 0; - fini = false; - return true; - } - bool breakLoop() { - return true; - } - void loop() { - this->getActivity()->stop(); - } - void step() { - ++c; - if (c == 5) - this->getActivity()->stop(); - } - void finalize() { - fini = true; - } -}; - -void -ActivitiesTest::setUp() -{ - t_task_prio = new PeriodicActivity( 15, 0.01 ); - - t_run_int_prio = new TestRunnableInterface(true); - t_run_int_fail = new TestRunnableInterface(false); - - t_run_allocate = new TestAllocate(); - t_self_remove = new TestSelfRemove(); - -} - - -void -ActivitiesTest::tearDown() -{ - delete t_task_prio; - - delete t_run_int_prio; - delete t_run_int_fail; - - delete t_run_allocate; - delete t_self_remove; -} - -void ActivitiesTest::testFailInit() -{ - t_task_prio->run( t_run_int_fail ); - - CPPUNIT_ASSERT( !t_task_prio->start() ); - CPPUNIT_ASSERT( !t_task_prio->stop() ); - -} - -void ActivitiesTest::testOverrun() -{ - bool r = false; - // create - boost::scoped_ptr run( new TestOverrun() ); - boost::scoped_ptr t( new RTT::OS::PeriodicThread(25,"ORThread", 0.1) ); - CPPUNIT_ASSERT_EQUAL(25,t->getPriority() ); - CPPUNIT_ASSERT_EQUAL(0.1,t->getPeriod() ); - - t->run( run.get() ); - - t->start(); - sleep(2); - - r = !t->isRunning(); - - t->run(0); - - CPPUNIT_ASSERT_MESSAGE( "Failed to detect step overrun in Thread", r); - - CPPUNIT_ASSERT_MESSAGE( "Failed to execute finalize in emergencyStop", run->fini ); - -} - - -void ActivitiesTest::testThreads() -{ - bool r = false; - // create - boost::scoped_ptr run( new TestPeriodic() ); - - boost::scoped_ptr t( new RTT::OS::PeriodicThread(RTT::OS::HighestPriority,"PThread", 0.1) ); - t->run( run.get() ); - - r = t->start(); - CPPUNIT_ASSERT_MESSAGE( "Failed to start Thread", r); - r = t->stop(); - CPPUNIT_ASSERT_MESSAGE( "Failed to stop Thread", r); - CPPUNIT_ASSERT_EQUAL_MESSAGE("Periodic Failure: period of step() to long !", run->overfail, 0); - CPPUNIT_ASSERT_EQUAL_MESSAGE("Periodic Failure: period of step() to short!", run->underfail, 0); - r = t->start(); - CPPUNIT_ASSERT_MESSAGE( "Failed to start Thread", r); - sleep(1); - r = t->stop(); - CPPUNIT_ASSERT_MESSAGE( "Failed to stop Thread", r); - CPPUNIT_ASSERT_EQUAL_MESSAGE("Periodic Failure: period of step() to long !", run->overfail, 0); - CPPUNIT_ASSERT_EQUAL_MESSAGE("Periodic Failure: period of step() to short!", run->underfail, 0); - t->run(0); -} - -void ActivitiesTest::testNonPeriodic() -{ - scoped_ptr t_run_int_nonper - ( new TestRunnableInterface(true) ); - // force ordering of scoped_ptr destruction. - { - scoped_ptr t_task_nonper - ( new NonPeriodicActivity( 14 ) ); - - CPPUNIT_ASSERT( t_task_nonper->run( t_run_int_nonper.get() ) ); - CPPUNIT_ASSERT( t_task_nonper->start() ); - sleep(1); - CPPUNIT_ASSERT( t_run_int_nonper->stepped ); - CPPUNIT_ASSERT( t_run_int_nonper->init ); - CPPUNIT_ASSERT( t_task_nonper->stop() ); - CPPUNIT_ASSERT( t_run_int_nonper->fini ); - CPPUNIT_ASSERT( !t_task_nonper->isRunning() ); - CPPUNIT_ASSERT( t_task_nonper->run( 0 ) ); - CPPUNIT_ASSERT( t_task_nonper->start() ); - CPPUNIT_ASSERT( t_task_nonper->stop() ); - // stop() should be fully synchronising... - CPPUNIT_ASSERT( !t_task_nonper->isRunning() ); - } -} - -void ActivitiesTest::testSelfRemove() -{ - scoped_ptr t_run_int_nonper - ( new TestSelfRemove() ); - scoped_ptr t_task_nonper - ( new NonPeriodicActivity( 14 ) ); - CPPUNIT_ASSERT( t_task_nonper->run( t_run_int_nonper.get() ) ); - CPPUNIT_ASSERT( t_task_nonper->start() ); - CPPUNIT_ASSERT( t_task_prio->run(t_self_remove) ); - CPPUNIT_ASSERT( t_task_prio->start() ); - sleep(1); - CPPUNIT_ASSERT( !t_task_prio->isRunning() ); - CPPUNIT_ASSERT( t_self_remove->fini ); - CPPUNIT_ASSERT( !t_task_nonper->isRunning() ); - CPPUNIT_ASSERT( t_run_int_nonper->fini ); -} - -void ActivitiesTest::testStartStop() -{ - testStart(); - testPause(); - testStop(); -} - -void ActivitiesTest::testRunnableInterface() -{ - testAddRunnableInterface(); - testStart(); - testRunnableInterfaceInit(); - testPause(); - testRunnableInterfaceExecution(); - testStop(); - testRemoveRunnableInterface(); -} - -void ActivitiesTest::testAllocation() -{ - testAddAllocate(); - testStart(); - testPause(); - testStop(); - testRemoveAllocate(); -} - -void ActivitiesTest::testAddRunnableInterface() -{ - bool adding_prio = t_task_prio->run( t_run_int_prio ); - CPPUNIT_ASSERT( adding_prio ); -} - -void ActivitiesTest::testRemoveRunnableInterface() -{ - CPPUNIT_ASSERT( t_run_int_prio->fini ); - CPPUNIT_ASSERT( t_task_prio->run( 0 ) ); -} - -void ActivitiesTest::testStart() -{ - CPPUNIT_ASSERT( t_task_prio->start()); - - CPPUNIT_ASSERT( t_task_prio->isRunning() ); -} - -void ActivitiesTest::testPause() -{ - sleep(1); -} - -void ActivitiesTest::testRunnableInterfaceInit() { - CPPUNIT_ASSERT( t_run_int_prio->init ); -} - -void ActivitiesTest::testRunnableInterfaceExecution() { - - CPPUNIT_ASSERT( t_run_int_prio->stepped ); -} - -void ActivitiesTest::testStop() -{ - CPPUNIT_ASSERT( t_task_prio->stop()); - - CPPUNIT_ASSERT( !t_task_prio->isRunning() ); -} - -void ActivitiesTest::testAddAllocate() -{ - CPPUNIT_ASSERT( t_task_prio->run( t_run_allocate ) ); -} - -void ActivitiesTest::testRemoveAllocate() -{ - CPPUNIT_ASSERT( t_task_prio->run( 0 ) ); -} - - diff --git a/tests/tasks_test.hpp b/tests/tasks_test.hpp deleted file mode 100644 index 5e7a1d1ee..000000000 --- a/tests/tasks_test.hpp +++ /dev/null @@ -1,102 +0,0 @@ -/*************************************************************************** - tag: Peter Soetens Mon Jan 10 15:59:18 CET 2005 tasks_test.hpp - - tasks_test.hpp - description - ------------------- - begin : Mon January 10 2005 - copyright : (C) 2005 Peter Soetens - email : peter.soetens@mech.kuleuven.ac.be - - *************************************************************************** - * * - * This program is free software; you can redistribute it and/or modify * - * it under the terms of the GNU General Public License as published by * - * the Free Software Foundation; either version 2 of the License, or * - * (at your option) any later version. * - * * - ***************************************************************************/ - - -#ifndef TASKSTEST_H -#define TASKSTEST_H - -#include - -#include -#include -#include -#include - -using namespace RTT; -using namespace RTT::detail; - -struct TestRunnableInterface; -struct TestSelfRemove; - -class ActivitiesTest : public CppUnit::TestFixture -{ - CPPUNIT_TEST_SUITE( ActivitiesTest ); - // Periodic Thread Test : - CPPUNIT_TEST( testThreads ); - - // Periodic Overrun Thread Test : - // Does not work in GNU/Linux nor RAI - //CPPUNIT_TEST( testOverrun ); - - // Start - Stop Test : - CPPUNIT_TEST( testStartStop ); - - // Runnable Interface Test : - CPPUNIT_TEST( testRunnableInterface ); - CPPUNIT_TEST( testFailInit ); - - // Allocation Test : [disabled, kills RTAI/LXRT] - CPPUNIT_TEST( testAddAllocate ); - - // Self Removal Test : - CPPUNIT_TEST( testSelfRemove ); - - // non periodic Test : - CPPUNIT_TEST( testNonPeriodic ); - - CPPUNIT_TEST_SUITE_END(); - - PeriodicActivity* t_task_prio; - - TestRunnableInterface* t_run_int_prio; - TestRunnableInterface* t_run_int_fail; - - RunnableInterface* t_run_allocate; - TestSelfRemove* t_self_remove; - -public: - - void setUp(); - void tearDown(); - - void testThreads(); - void testOverrun(); - - void testStartStop(); - void testStart(); - void testPause(); - void testStop(); - - void testSelfRemove(); - - void testNonPeriodic(); - - void testAllocation(); - void testRemoveAllocate(); - void testAddAllocate(); - - void testFailInit(); - void testRunnableInterface(); - void testAddRunnableInterface(); - void testRunnableInterfaceInit(); - void testRunnableInterfaceExecution(); - void testRemoveRunnableInterface(); - -}; - -#endif diff --git a/tests/taskthread_test.cpp b/tests/taskthread_test.cpp deleted file mode 100644 index d41544e72..000000000 --- a/tests/taskthread_test.cpp +++ /dev/null @@ -1,580 +0,0 @@ -/*************************************************************************** - tag: Peter Soetens Tue Apr 5 16:53:26 CEST 2005 taskthread_test.cpp - - taskthread_test.cpp - description - ------------------- - begin : Tue April 05 2005 - copyright : (C) 2005 Peter Soetens - email : peter.soetens@mech.kuleuven.ac.be - - *************************************************************************** - * * - * This program is free software; you can redistribute it and/or modify * - * it under the terms of the GNU General Public License as published by * - * the Free Software Foundation; either version 2 of the License, or * - * (at your option) any later version. * - * * - ***************************************************************************/ - - - - -#include "taskthread_test.hpp" -#include -#include - -#include -#include -#include -#include -#include -#include - -using namespace std; - -// Registers the fixture into the 'registry' -CPPUNIT_TEST_SUITE_REGISTRATION( ActivitiesThreadTest ); - -using namespace RTT; - -struct A {}; - -template -struct TestActivity - : public T -{ - bool result, _dothrow; - bool init, stepped, fini; - - ActivityInterface* owner; - - TestActivity(int prio, double per, bool fail, bool dothrow = false) - :T(prio,per), _dothrow(dothrow) - { - this->reset(fail); - } - - bool initialize() { - init = true; - return result; - } - void step() { - stepped = true; - CPPUNIT_ASSERT(this->isRunning()); -#ifndef ORO_EMBEDDED - if ( _dothrow ) - throw A(); -#endif - } - void finalize() { - fini = true; - } - - void reset(bool fail) { - result = fail; - init = false; - stepped = false; - fini = false; - } -}; - -struct TestRunner - : public RunnableInterface -{ - bool result; - bool init, stepped, fini; - bool looped, broke; - - TestRunner(bool fail) - { - this->reset(fail); - } - - bool initialize() { - init = true; - CPPUNIT_ASSERT(getActivity()->isActive()); - CPPUNIT_ASSERT(!getActivity()->isRunning()); - return result; - } - void step() { - stepped = true; - CPPUNIT_ASSERT(getActivity()->isActive()); - CPPUNIT_ASSERT(getActivity()->isRunning()); - } - - void loop() { - looped = true; - CPPUNIT_ASSERT(getActivity()->isActive()); - CPPUNIT_ASSERT(getActivity()->isRunning()); - } - - bool breakLoop() { - broke = true; - return true; - } - - void finalize() { - fini = true; - CPPUNIT_ASSERT(getActivity()->isActive()); - CPPUNIT_ASSERT(!getActivity()->isRunning()); - } - - void reset(bool fail) { - result = fail; - init = false; - stepped = false; - fini = false; - looped = false; - broke = false; - } -}; - - -struct TestAllocate - : public RunnableInterface -{ - std::vector v; - char* c; - std::string s; - - bool initialize() { - c = 0; - return true; - } - void step() { - v.resize( 0 ); - v.resize( 1025, std::string("Goodbye Memory") ); - delete[] c; - c = new char[1025]; - s = "Hello World "; - s += s; - s += s; - } - void finalize() { - delete[] c; - v.resize(0); - } -}; - -void -ActivitiesThreadTest::setUp() -{ - t_task_np = new TestActivity(3, 0.01, true ); - t_task_np_bad = new TestActivity(3, 0.01, true, true ); - t_task_p = new TestActivity(3, 0.032, true ); -} - - -void -ActivitiesThreadTest::tearDown() -{ - delete t_task_np; - delete t_task_np_bad; - delete t_task_p; -} - -void ActivitiesThreadTest::testPeriodic() -{ - // Test periodic task sequencing... - - PeriodicActivity mtask( 15, 0.01 ); - CPPUNIT_ASSERT( mtask.isActive() == false ); - CPPUNIT_ASSERT( mtask.isRunning() == false ); - CPPUNIT_ASSERT( mtask.thread()->isRunning() ); - CPPUNIT_ASSERT_EQUAL( 0.01, mtask.thread()->getPeriod() ); - - // Adapt priority levels to OS. - int bprio = 15, rtsched = ORO_SCHED_RT; - OS::CheckPriority( rtsched, bprio ); - - CPPUNIT_ASSERT_EQUAL( bprio, mtask.thread()->getPriority() ); - CPPUNIT_ASSERT_EQUAL( rtsched, mtask.thread()->getScheduler() ); - - PeriodicActivity m2task( 15, 0.01 ); - CPPUNIT_ASSERT( mtask.thread() == m2task.thread() ); - - // starting... - CPPUNIT_ASSERT( mtask.start() == true ); - CPPUNIT_ASSERT( mtask.isRunning() == true ); - CPPUNIT_ASSERT( m2task.isRunning() == false ); - CPPUNIT_ASSERT( m2task.start() == true ); - CPPUNIT_ASSERT( m2task.isRunning() == true ); - - sleep(1); - - // stopping... - CPPUNIT_ASSERT( mtask.stop() == true ); - CPPUNIT_ASSERT( mtask.isRunning() == false ); - CPPUNIT_ASSERT( m2task.isRunning() == true ); - CPPUNIT_ASSERT( m2task.stop() == true ); - CPPUNIT_ASSERT( m2task.isRunning() == false ); - - // Different Scheduler (don't test if invalid priorities) - bprio = 15; - rtsched = ORO_SCHED_RT; - if ( OS::CheckPriority( rtsched, bprio ) ) { - PeriodicActivity m3task(ORO_SCHED_OTHER, 15, 0.01); - bprio = 15; - rtsched = ORO_SCHED_OTHER; - if ( OS::CheckPriority( rtsched, bprio ) ) { - CPPUNIT_ASSERT( mtask.thread() != m3task.thread() ); - CPPUNIT_ASSERT_EQUAL( ORO_SCHED_OTHER, m3task.thread()->getScheduler() ); - } - } - - // Starting thread if thread not running - CPPUNIT_ASSERT( mtask.thread()->stop() ); - CPPUNIT_ASSERT( mtask.thread()->isRunning() == false ); - CPPUNIT_ASSERT( mtask.start() ); - CPPUNIT_ASSERT( mtask.isRunning() == true ); - CPPUNIT_ASSERT( mtask.thread()->isRunning() == true); -} - -void ActivitiesThreadTest::testNonPeriodic() -{ - // Test periodic task sequencing... - - NonPeriodicActivity mtask( 15 ); - - // Adapt priority levels to OS. - int bprio = 15, rtsched = ORO_SCHED_RT; - OS::CheckPriority( rtsched, bprio ); - - CPPUNIT_ASSERT( mtask.isActive() == false ); - CPPUNIT_ASSERT( mtask.isRunning() == false ); - CPPUNIT_ASSERT( mtask.thread()->isRunning() == false ); - CPPUNIT_ASSERT_EQUAL( bprio, mtask.thread()->getPriority() ); - CPPUNIT_ASSERT_EQUAL( rtsched, mtask.thread()->getScheduler() ); - - NonPeriodicActivity m2task( 15 ); - CPPUNIT_ASSERT( mtask.thread() != m2task.thread() ); - - // starting... - CPPUNIT_ASSERT( mtask.start() == true ); - CPPUNIT_ASSERT( mtask.isActive() == true ); - CPPUNIT_ASSERT( m2task.isActive() == false ); - CPPUNIT_ASSERT( m2task.start() == true ); - CPPUNIT_ASSERT( m2task.isActive() == true ); - - sleep(1); - - // stopping... - CPPUNIT_ASSERT( mtask.stop() == true ); - CPPUNIT_ASSERT( mtask.isActive() == false ); - CPPUNIT_ASSERT( m2task.isActive() == true ); - CPPUNIT_ASSERT( m2task.stop() == true ); - CPPUNIT_ASSERT( m2task.isActive() == false ); - - // Different Scheduler - bprio = 15; - rtsched = ORO_SCHED_OTHER; - if ( OS::CheckPriority( rtsched, bprio ) ) { - NonPeriodicActivity m3task(ORO_SCHED_OTHER, 15); - CPPUNIT_ASSERT( mtask.thread() != m3task.thread() ); - CPPUNIT_ASSERT_EQUAL( ORO_SCHED_OTHER, m3task.thread()->getScheduler() ); - } -} - -void ActivitiesThreadTest::testSlave() -{ - // Test slave activities - TestRunner r(true); - - // without master, NP. - SlaveActivity mtask(&r); - CPPUNIT_ASSERT( mtask.isActive() == false ); - CPPUNIT_ASSERT( mtask.isRunning() == false ); - CPPUNIT_ASSERT( mtask.isPeriodic() == false ); - CPPUNIT_ASSERT( mtask.getPeriod() == 0.0 ); - CPPUNIT_ASSERT( mtask.execute() == false ); - CPPUNIT_ASSERT( mtask.thread() == OS::MainThread::Instance() ); - - // starting... - CPPUNIT_ASSERT( mtask.start() == true ); - CPPUNIT_ASSERT( r.init == true ); - - CPPUNIT_ASSERT( mtask.isActive() == true ); - CPPUNIT_ASSERT( mtask.isRunning() == false ); - CPPUNIT_ASSERT( mtask.start() == false ); - - // calls loop() - CPPUNIT_ASSERT( mtask.execute() ); - CPPUNIT_ASSERT( r.looped == true ); - CPPUNIT_ASSERT( mtask.execute() ); - - // stopping... - CPPUNIT_ASSERT( mtask.stop() == true ); - CPPUNIT_ASSERT( r.fini == true ); - CPPUNIT_ASSERT( mtask.isRunning() == false ); - CPPUNIT_ASSERT( mtask.isActive() == false ); - CPPUNIT_ASSERT( mtask.stop() == false ); - - CPPUNIT_ASSERT( mtask.execute() == false ); - - r.reset(true); - - // with periodic master: - SlaveActivity mslave( t_task_np, &r ); - CPPUNIT_ASSERT( mslave.isActive() == false ); - CPPUNIT_ASSERT( mslave.isRunning() == false ); - CPPUNIT_ASSERT( mslave.isPeriodic() == true ); - CPPUNIT_ASSERT_EQUAL( mslave.getPeriod(), t_task_np->getPeriod() ); - CPPUNIT_ASSERT( mslave.execute() == false ); - CPPUNIT_ASSERT( mslave.thread() == t_task_np->thread() ); - - CPPUNIT_ASSERT( !mslave.start() ); - CPPUNIT_ASSERT( t_task_np->start() ); - CPPUNIT_ASSERT( mslave.start() ); - CPPUNIT_ASSERT( r.init == true ); - CPPUNIT_ASSERT( mslave.isActive() ); - CPPUNIT_ASSERT( mslave.isRunning() ); - - // calls step() - CPPUNIT_ASSERT( mslave.execute() ); - CPPUNIT_ASSERT( r.stepped == true ); - CPPUNIT_ASSERT( mslave.execute() ); - CPPUNIT_ASSERT( !mslave.start() ); - - // stopping... - CPPUNIT_ASSERT( mslave.stop() ); - CPPUNIT_ASSERT( r.fini == true ); - CPPUNIT_ASSERT( !mslave.isActive() ); - CPPUNIT_ASSERT( !mslave.isRunning() ); - - r.reset(true); - - // periodic: - SlaveActivity mslave_p(0.001, &r); - CPPUNIT_ASSERT( mslave_p.isActive() == false ); - CPPUNIT_ASSERT( mslave_p.isRunning() == false ); - CPPUNIT_ASSERT( mslave_p.isPeriodic() == true ); - CPPUNIT_ASSERT( mslave_p.getPeriod() == 0.001 ); - CPPUNIT_ASSERT( mslave_p.execute() == false ); - CPPUNIT_ASSERT( mslave_p.thread() == OS::MainThread::Instance() ); - - CPPUNIT_ASSERT( mslave_p.start() ); - CPPUNIT_ASSERT( r.init == true ); - CPPUNIT_ASSERT( mslave_p.isActive() ); - CPPUNIT_ASSERT( mslave_p.isRunning() ); - CPPUNIT_ASSERT( mslave_p.execute() ); - CPPUNIT_ASSERT( r.stepped == true ); - CPPUNIT_ASSERT( !mslave_p.start() ); - - // stopping... - CPPUNIT_ASSERT( mslave_p.stop() ); - CPPUNIT_ASSERT( r.fini == true ); - CPPUNIT_ASSERT( !mslave_p.isActive() ); - CPPUNIT_ASSERT( !mslave_p.isRunning() ); - CPPUNIT_ASSERT( !mslave_p.execute() ); - -} - -void ActivitiesThreadTest::testSequential() -{ - // Test sequential activities - TestRunner r(true); - - SequentialActivity mtask(&r); - CPPUNIT_ASSERT( mtask.isActive() == false ); - CPPUNIT_ASSERT( mtask.isRunning() == false ); - CPPUNIT_ASSERT( mtask.isPeriodic() == false ); - CPPUNIT_ASSERT( mtask.getPeriod() == 0.0 ); - CPPUNIT_ASSERT( mtask.execute() == false ); - CPPUNIT_ASSERT( mtask.trigger() == false ); - CPPUNIT_ASSERT( mtask.thread() == OS::MainThread::Instance() ); - - // starting... - CPPUNIT_ASSERT( mtask.start() == true ); - CPPUNIT_ASSERT( r.init == true ); - - CPPUNIT_ASSERT( mtask.isActive() == true ); - CPPUNIT_ASSERT( mtask.isRunning() == false ); - CPPUNIT_ASSERT( mtask.start() == false ); - - // calls step() - CPPUNIT_ASSERT( mtask.trigger() ); - CPPUNIT_ASSERT( r.stepped == true ); - CPPUNIT_ASSERT( mtask.execute() == false ); - - // stopping... - CPPUNIT_ASSERT( mtask.stop() == true ); - CPPUNIT_ASSERT( r.fini == true ); - CPPUNIT_ASSERT( mtask.isRunning() == false ); - CPPUNIT_ASSERT( mtask.isActive() == false ); - CPPUNIT_ASSERT( mtask.stop() == false ); - - CPPUNIT_ASSERT( mtask.execute() == false ); - CPPUNIT_ASSERT( mtask.trigger() == false ); - - r.reset(false); - CPPUNIT_ASSERT( mtask.start() == false ); - CPPUNIT_ASSERT( r.init == true ); - - CPPUNIT_ASSERT( mtask.isActive() == false ); - CPPUNIT_ASSERT( mtask.isRunning() == false ); - CPPUNIT_ASSERT( mtask.start() == false ); -} - -void ActivitiesThreadTest::testScheduler() -{ - int rtsched = ORO_SCHED_OTHER; - int bprio = 15; - - OS::CheckPriority( rtsched, bprio ); - TimerThreadPtr tt = TimerThread::Instance(rtsched, bprio, 0.0123); - CPPUNIT_ASSERT( tt != 0 ); - - CPPUNIT_ASSERT( tt->isRunning() == false ); - - CPPUNIT_ASSERT_EQUAL( 0.0123, tt->getPeriod()); - - CPPUNIT_ASSERT_EQUAL( bprio, tt->getPriority()); - CPPUNIT_ASSERT_EQUAL( rtsched, tt->getScheduler()); - - // different scheduler, different thread. - rtsched = ORO_SCHED_RT; - bprio = 15; - if ( OS::CheckPriority( rtsched, bprio ) ) { - TimerThreadPtr tt2 = TimerThread::Instance(rtsched, bprio, 0.0123); - CPPUNIT_ASSERT( tt2 != 0 ); - CPPUNIT_ASSERT( tt2 != tt ); - CPPUNIT_ASSERT_EQUAL( rtsched, tt2->getScheduler()); - - tt = TimerThread::Instance(bprio, 0.0123); // ORO_SCHED_RT is the default. - CPPUNIT_ASSERT( tt == tt2 ); - } -} - - -void ActivitiesThreadTest::testThreadConfig() -{ - int rtsched = ORO_SCHED_RT; - int bprio = 15; - TimerThreadPtr tt = TimerThread::Instance(bprio, 0.0123); - - CPPUNIT_ASSERT( tt->isRunning() == false ); - - CPPUNIT_ASSERT_EQUAL( 0.0123, tt->getPeriod()); - - // only do this if valid priority/scheduler range: - if ( OS::CheckPriority( rtsched, bprio ) == true) - { - CPPUNIT_ASSERT_EQUAL( bprio, tt->getPriority()); - - // different priority, different thread. - TimerThreadPtr tt2 = TimerThread::Instance(bprio - 1, 0.0123); - CPPUNIT_ASSERT( tt2 != 0 ); - CPPUNIT_ASSERT( tt2 != tt ); - - // different period, different thread. - TimerThreadPtr tt3 = TimerThread::Instance(bprio, 0.123); - CPPUNIT_ASSERT( tt3 != 0 ); - CPPUNIT_ASSERT( tt3 != tt ); - CPPUNIT_ASSERT( tt3 != tt2 ); - } - - tt = TimerThread::Instance(bprio, 0.0123); - CPPUNIT_ASSERT( tt != 0 ); - CPPUNIT_ASSERT( tt == TimerThread::Instance(bprio,0.0123) ); - - // switching hard/soft - // do not ASSERT since the ret-value may be false... - if ( tt->setScheduler(ORO_SCHED_OTHER) ) - CPPUNIT_ASSERT( tt->getScheduler() == ORO_SCHED_OTHER ); - if ( tt->setScheduler(ORO_SCHED_RT) ) - CPPUNIT_ASSERT( tt->getScheduler() == ORO_SCHED_RT ); - tt->setScheduler(ORO_SCHED_OTHER); - tt->setScheduler(ORO_SCHED_RT); - tt->setScheduler(ORO_SCHED_OTHER); - tt->setScheduler(ORO_SCHED_RT); - if ( tt->setPriority( 4 ) ) { - CPPUNIT_ASSERT_EQUAL( tt->getPriority(), 4 ); - - // even if the priority was changed after construction, - // the thread can be found: - CPPUNIT_ASSERT( tt == TimerThread::Instance(4,0.0123) ); - } - - CPPUNIT_ASSERT( tt->start() ); - - sleep(1); - - // prints annoying warning messages... - Logger::LogLevel ll = Logger::log().getLogLevel(); - Logger::log().setLogLevel(Logger::Critical); - CPPUNIT_ASSERT( tt->setScheduler(ORO_SCHED_RT) == false ); - CPPUNIT_ASSERT( tt->setScheduler(ORO_SCHED_OTHER) == false ); - Logger::log().setLogLevel( ll ); - CPPUNIT_ASSERT( tt->setPeriod(0.3) == false ); - - // reconfigure periodicity - CPPUNIT_ASSERT( tt->stop() ); - CPPUNIT_ASSERT( tt->setPeriod(0.3) ); - CPPUNIT_ASSERT_EQUAL( Seconds_to_nsecs(0.3), tt->getPeriodNS() ); - - // some quick start/stops. - CPPUNIT_ASSERT( tt->start() ); - CPPUNIT_ASSERT( tt->stop() ); - CPPUNIT_ASSERT( tt->start() ); - -} - -#ifndef ORO_EMBEDDED -void ActivitiesThreadTest::testExceptionRecovery() -{ - Logger::LogLevel ll = Logger::log().getLogLevel(); - Logger::log().setLogLevel( Logger::Never ); - CPPUNIT_ASSERT(t_task_np->start()); - CPPUNIT_ASSERT(t_task_np_bad->start()); - CPPUNIT_ASSERT(t_task_p->start()); - - sleep(1); - // thread should stop : - Logger::log().setLogLevel( ll ); - CPPUNIT_ASSERT( !t_task_np_bad->thread()->isRunning() ); - - CPPUNIT_ASSERT( !t_task_np->isRunning() ); - CPPUNIT_ASSERT( !t_task_np_bad->isRunning() ); - CPPUNIT_ASSERT( t_task_p->isRunning() ); - - CPPUNIT_ASSERT( t_task_np->init ); - CPPUNIT_ASSERT( t_task_np_bad->init ); - CPPUNIT_ASSERT( t_task_p->init ); - - CPPUNIT_ASSERT( t_task_np->stepped ); - CPPUNIT_ASSERT( t_task_np_bad->stepped ); - CPPUNIT_ASSERT( t_task_p->stepped ); - - // must be stopped since bad throwed an exception - CPPUNIT_ASSERT( t_task_np->fini ); - CPPUNIT_ASSERT( t_task_np_bad->fini ); - - t_task_p->stop(); - - // see if we recovered ok : - CPPUNIT_ASSERT( t_task_np_bad->thread()->start() ); - - CPPUNIT_ASSERT(t_task_np->start()); - - sleep(1); - t_task_p->reset(true); - CPPUNIT_ASSERT( t_task_np->isRunning() ); - CPPUNIT_ASSERT( t_task_np->init ); - CPPUNIT_ASSERT( t_task_np->stepped ); - - CPPUNIT_ASSERT(t_task_np->stop()); - CPPUNIT_ASSERT( t_task_np->fini ); -} -#endif - -void ActivitiesThreadTest::testAddAllocate() -{ - CPPUNIT_ASSERT( t_task_np->run( t_run_allocate ) ); -} - -void ActivitiesThreadTest::testRemoveAllocate() -{ - CPPUNIT_ASSERT( t_task_np->run( 0 ) ); -} - - diff --git a/tests/taskthread_test.hpp b/tests/taskthread_test.hpp deleted file mode 100644 index 719fbd1f8..000000000 --- a/tests/taskthread_test.hpp +++ /dev/null @@ -1,86 +0,0 @@ -/*************************************************************************** - tag: Peter Soetens Tue Apr 5 16:53:26 CEST 2005 taskthread_test.hpp - - taskthread_test.hpp - description - ------------------- - begin : Tue April 05 2005 - copyright : (C) 2005 Peter Soetens - email : peter.soetens@mech.kuleuven.ac.be - - *************************************************************************** - * * - * This program is free software; you can redistribute it and/or modify * - * it under the terms of the GNU General Public License as published by * - * the Free Software Foundation; either version 2 of the License, or * - * (at your option) any later version. * - * * - ***************************************************************************/ - - - -#ifndef TASKSTHREADTEST_H -#define TASKSTHREADTEST_H - -#include - -#include -#include -#include - -using namespace RTT; - -template -struct TestActivity; - - -/** - * Tests task-thread relationships. - */ -class ActivitiesThreadTest : public CppUnit::TestFixture -{ - CPPUNIT_TEST_SUITE( ActivitiesThreadTest ); - // Configuration Test : - CPPUNIT_TEST( testThreadConfig ); - CPPUNIT_TEST( testPeriodic ); - CPPUNIT_TEST( testNonPeriodic ); - CPPUNIT_TEST( testSlave ); - CPPUNIT_TEST( testSequential ); - CPPUNIT_TEST( testScheduler ); - -#ifndef ORO_EMBEDDED - CPPUNIT_TEST( testExceptionRecovery ); -#endif - - // Allocation Test : [disabled, kills RTAI/LXRT] - //CPPUNIT_TEST( testAddAllocate ); - - CPPUNIT_TEST_SUITE_END(); - - TestActivity* t_task_np; - TestActivity* t_task_np_bad; - TestActivity* t_task_p; - TestActivity* t_task_slave; - - RunnableInterface* t_run_allocate; -public: - - void setUp(); - void tearDown(); - -#ifndef ORO_EMBEDDED - void testExceptionRecovery(); -#endif - void testThreadConfig(); - void testPeriodic(); - void testNonPeriodic(); - void testSlave(); - void testSequential(); - - void testScheduler(); - - void testAllocation(); - void testRemoveAllocate(); - void testAddAllocate(); -}; - -#endif diff --git a/tests/template_factory_test.cpp b/tests/template_factory_test.cpp deleted file mode 100644 index c43f17010..000000000 --- a/tests/template_factory_test.cpp +++ /dev/null @@ -1,343 +0,0 @@ -/*************************************************************************** - tag: Peter Soetens Wed Jan 18 14:11:41 CET 2006 template_factory_test.cpp - - template_factory_test.cpp - description - ------------------- - begin : Wed January 18 2006 - copyright : (C) 2006 Peter Soetens - email : peter.soetens@mech.kuleuven.be - - *************************************************************************** - * * - * This program is free software; you can redistribute it and/or modify * - * it under the terms of the GNU General Public License as published by * - * the Free Software Foundation; either version 2 of the License, or * - * (at your option) any later version. * - * * - ***************************************************************************/ - - - -#include "template_factory_test.hpp" -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include - -#include - -using namespace std; - -// Registers the fixture into the 'registry' -CPPUNIT_TEST_SUITE_REGISTRATION( Template_FactoryTest ); - - -void -Template_FactoryTest::setUp() -{ - tc = new TaskContext( "root" ); - tc->addObject( this->createMethodFactory() ); - tc->addObject( this->createUserMethodFactory() ); - tc->addObject( this->createCommandFactory() ); - t_event_float = RTT::Event("FloatEvent"); - CPPUNIT_ASSERT( tc->events()->addEvent( &t_event_float, "Description","a1","d1", "a2", "d2" ) ); - tsim = new SimulationActivity(0.001, tc->engine() ); - event_proc = new EventProcessor(); - act.run(event_proc); - SimulationThread::Instance()->stop(); -} - - -void -Template_FactoryTest::tearDown() -{ -// if ( tc->getPeer("programs") ) -// delete tc->getPeer("programs"); - tsim->stop(); - act.stop(); - delete tc; - delete tsim; - delete event_proc; -} - -bool Template_FactoryTest::assertBool( bool b) { - return b; -} - -TaskObject* Template_FactoryTest::createMethodFactory() -{ - TaskObject* dat = new TaskObject("methods"); - - dat->methods()->addMethod( method("assert", &Template_FactoryTest::assertBool, this), "assert","b","bd"); - dat->methods()->addMethod( method("m0", &Template_FactoryTest::m0, this), "M0"); - dat->methods()->addMethod( method("m1", &Template_FactoryTest::m1, this), "M1","a","ad"); - dat->methods()->addMethod( method("m2", &Template_FactoryTest::m2, this), "M2","a","ad","a","ad"); - dat->methods()->addMethod( method("m3", &Template_FactoryTest::m3, this), "M3","a","ad","a","ad","a","ad"); - dat->methods()->addMethod( method("m4", &Template_FactoryTest::m4, this), "M4","a","ad","a","ad","a","ad","a","ad"); - return dat; -} - -TaskObject* Template_FactoryTest::createUserMethodFactory() -{ - TaskObject* dat = new TaskObject("umethods"); - - dat->methods()->addMethod( method("umd", &Template_FactoryTest::umd, this), "umd", "D0", "D0"); - dat->methods()->addMethod( method("umv", &Template_FactoryTest::umv, this), "umv", "V0", "V0"); - dat->methods()->addMethod( method("umcv", &Template_FactoryTest::umcv, this), "umv", "V0", "V0"); - dat->methods()->addMethod( method("umcrv", &Template_FactoryTest::umcrv, this), "umv", "V0", "V0"); - dat->methods()->addMethod( method("umrv", &Template_FactoryTest::umrv, this), "umv", "V0", "V0"); - return dat; -} - -TaskObject* Template_FactoryTest::createCommandFactory() -{ - TaskObject* dat = new TaskObject("commands"); - - dat->commands()->addCommand( command("c00", &Template_FactoryTest::cd0, &Template_FactoryTest::cn0, this, tc->engine()->commands() ), "c0d"); - dat->commands()->addCommand( command("c10", &Template_FactoryTest::cd1, &Template_FactoryTest::cn0, this, tc->engine()->commands() ), "c1d","a","ad"); - dat->commands()->addCommand( command("c11", &Template_FactoryTest::cd1, &Template_FactoryTest::cn1, this, tc->engine()->commands() ), "c1d","a","ad"); - dat->commands()->addCommand( command("c20", &Template_FactoryTest::cd2, &Template_FactoryTest::cn0, this, tc->engine()->commands() ), "c2d","a","ad","a","ad"); - dat->commands()->addCommand( command("c21", &Template_FactoryTest::cd2, &Template_FactoryTest::cn1, this, tc->engine()->commands() ), "c2d","a","ad","a","ad"); - dat->commands()->addCommand( command("c22", &Template_FactoryTest::cd2, &Template_FactoryTest::cn2, this, tc->engine()->commands() ), "c2d","a","ad","a","ad"); - dat->commands()->addCommand( command("c30", &Template_FactoryTest::cd3, &Template_FactoryTest::cn0, this, tc->engine()->commands() ), "c3d","a","ad","a","ad","a","ad"); - dat->commands()->addCommand( command("c31", &Template_FactoryTest::cd3, &Template_FactoryTest::cn1, this, tc->engine()->commands() ), "c3d","a","ad","a","ad","a","ad"); - dat->commands()->addCommand( command("c33", &Template_FactoryTest::cd3, &Template_FactoryTest::cn3, this, tc->engine()->commands() ), "c3d","a","ad","a","ad","a","ad"); - return dat; -} - -void Template_FactoryTest::executePrograms(const Parser::ParsedPrograms& pg_list ) -{ - tc->engine()->programs()->loadProgram( *pg_list.begin() ); - CPPUNIT_ASSERT( tsim->start() ); - CPPUNIT_ASSERT( (*pg_list.begin())->start() ); - CPPUNIT_ASSERT( SimulationThread::Instance()->run(1000) ); - CPPUNIT_ASSERT( (*pg_list.begin())->stop() ); - tsim->stop(); - if ( (*pg_list.begin())->inError() ) { - stringstream errormsg; - errormsg << " Program error on line " << (*pg_list.begin())->getLineNumber() <<"."< res; - res = GenerateDataSource()( 1 ); - CPPUNIT_ASSERT( res.size() == 1 ); - res = GenerateDataSource()(1, 1.0 ); - CPPUNIT_ASSERT( res.size() == 2 ); - res = GenerateDataSource()(1, 1.0, true ); - CPPUNIT_ASSERT( res.size() == 3 ); - res = GenerateDataSource()(1, 1.0, true, "c" ); - CPPUNIT_ASSERT( res.size() == 4 ); - - // C++ DataSources : - DataSourceBase::shared_ptr empty1; - DataSource::shared_ptr empty2; - AssignableDataSource::shared_ptr empty3; - ValueDataSource::shared_ptr empty4; - - res = GenerateDataSource()( empty1.get() ); - CPPUNIT_ASSERT( res.size() == 1 ); - res = GenerateDataSource()( empty1.get(), empty2.get() ); - CPPUNIT_ASSERT( res.size() == 2 ); - res = GenerateDataSource()( empty1.get(), empty2.get(), empty3.get() ); - CPPUNIT_ASSERT( res.size() == 3 ); - res = GenerateDataSource()( empty1.get(), empty2.get(), empty3.get(), empty4.get() ); - CPPUNIT_ASSERT( res.size() == 4 ); -} - - -int Template_FactoryTest::float_listener(float a, float b) -{ - Logger::log() << Logger::Debug << "float_listener "<< a<<", "<stop(); - ConnectionC cc = tc->events()->setupConnection("FloatEvent"); - cc.callback( this, &Template_FactoryTest::float_listener ); - Handle h1 = cc.handle(); - cc.callback( this, &Template_FactoryTest::float_completer, CompletionProcessor::Instance() ); - Handle h2 = cc.handle(); - - CPPUNIT_ASSERT( h1.connect() ); - CPPUNIT_ASSERT( h2.connect() ); - - // first test ConnectionC callbacks. - t_event_float(1.0, 4.0); - CPPUNIT_ASSERT_EQUAL( float(5.0), float_sum ); - CPPUNIT_ASSERT_EQUAL( float(0.0), float_sub ); - float_sum = float_sub = 0.0; - - // OK, now test if the EventC emission works. - EventC mevent; - CPPUNIT_ASSERT_NO_THROW( mevent = tc->events()->setupEmit("FloatEvent").argC(float(1.0)).argC(float(4.0)) ); - CPPUNIT_ASSERT( mevent.ready() ); - mevent.emit(); - CPPUNIT_ASSERT_EQUAL( float(5.0), float_sum ); - CPPUNIT_ASSERT_EQUAL( float(0.0), float_sub ); - - float a = 10.0, b = 5.0; - CPPUNIT_ASSERT_NO_THROW( mevent = tc->events()->setupEmit("FloatEvent").arg(a).arg(b) ); - mevent.emit(); - CPPUNIT_ASSERT_EQUAL( float(20.0), float_sum ); - CPPUNIT_ASSERT_EQUAL( float(0.0), float_sub ); - - CompletionProcessor::Instance()->start(); - - h1.disconnect(); - h2.disconnect(); - float_sum = 0; - float_sub = 0; - - // use event processor - CPPUNIT_ASSERT(act.start()); - - cc = tc->events()->setupConnection("FloatEvent").callback( this, &Template_FactoryTest::float_listener); - h1 = cc.handle(); - cc.callback( this, &Template_FactoryTest::float_completer, event_proc, RTT::EventProcessor::OnlyLast ); - h2 = cc.handle(); - - h1.connect(); - h2.connect(); - - // simulate overrun : - mevent = tc->events()->setupEmit("FloatEvent").argC(float(1.0)).argC(float(4.0)); - mevent.emit(); - CPPUNIT_ASSERT_EQUAL( float(5.0), float_sum ); - - mevent = tc->events()->setupEmit("FloatEvent").arg(a).arg(b); - mevent.emit(); - CPPUNIT_ASSERT_EQUAL( float(20.0), float_sum ); - - event_proc->step(); - event_proc->finalize(); - // asyn handlers should reach only last total. - CPPUNIT_ASSERT_EQUAL( float(-15.0), float_sub ); - h1.disconnect(); - h2.disconnect(); -} - diff --git a/tests/template_factory_test.hpp b/tests/template_factory_test.hpp deleted file mode 100644 index aca171a83..000000000 --- a/tests/template_factory_test.hpp +++ /dev/null @@ -1,103 +0,0 @@ -/*************************************************************************** - tag: Peter Soetens Wed Jan 18 14:11:41 CET 2006 template_factory_test.hpp - - template_factory_test.hpp - description - ------------------- - begin : Wed January 18 2006 - copyright : (C) 2006 Peter Soetens - email : peter.soetens@mech.kuleuven.be - - *************************************************************************** - * * - * This program is free software; you can redistribute it and/or modify * - * it under the terms of the GNU General Public License as published by * - * the Free Software Foundation; either version 2 of the License, or * - * (at your option) any later version. * - * * - ***************************************************************************/ - - -#ifndef TEMPLATE_FACTORYTEST_H -#define TEMPLATE_FACTORYTEST_H - -#include - -#include -#include -#include -#include -#include -#include - -using namespace RTT; -using namespace RTT; - -class Template_FactoryTest : public CppUnit::TestFixture -{ - CPPUNIT_TEST_SUITE( Template_FactoryTest ); - CPPUNIT_TEST( testMethods ); - CPPUNIT_TEST( testUserMethods ); - CPPUNIT_TEST( testCommands ); - CPPUNIT_TEST( testManual ); - CPPUNIT_TEST( testEventC ); - CPPUNIT_TEST_SUITE_END(); - - Parser parser; - TaskContext* tc; - ActivityInterface* tsim; - SlaveActivity act; - CommandProcessor processor; - TaskObject* createMethodFactory(); - TaskObject* createUserMethodFactory(); - TaskObject* createCommandFactory(); - - RTT::Event t_event_float; - int float_listener(float a, float b); - int float_completer(float a, float b); - RTT::EventProcessor* event_proc; - float float_sum, float_sub; - - 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); } - double m3(int i, double d, bool c) { return -d3(i,d,c); } - double m4(int i, double d, bool c, std::string s) { return -d4(i,d,c,s); } - - Double6D umd(Double6D d) { return d; } - const std::vector& umcrv(const std::vector& d) { return d; } - std::vector umv( std::vector d) { return d; } - const std::vector umcv(const std::vector d) { return d; } - std::vector& umrv( std::vector& d) { return d; } - - double d0() const { return 1.0; } - double d1(int i) const { return 2.0; } - double d2(int i, double d) const { return 3.0; } - double d3(int i, double d, bool c) const { return 4.0; } - double d4(int i, double d, bool c, std::string s) const { return 5.0; } - - bool cd0() { return true; } - bool cd1(int i) { return true; } - bool cd2(int i, double d) { return true; } - bool cd3(int i, double d, char c) { return true; } - bool cn0() const { return true; } - bool cn1(int i) const { return true; } - bool cn2(int i, double d) const { return true; } - bool cn3(int i, double d, char c) const { return true; } - - bool assertBool( bool ); -public: - - void setUp(); - void tearDown(); - - void testMethods(); - void testUserMethods(); - void testData(); - void testCommands(); - void testEventC(); - - void testManual(); -}; - -#endif diff --git a/tests/test-runner.cpp b/tests/test-runner.cpp deleted file mode 100644 index 6ac52eff7..000000000 --- a/tests/test-runner.cpp +++ /dev/null @@ -1,56 +0,0 @@ -/*************************************************************************** - tag: Peter Soetens Mon Jan 10 15:59:50 CET 2005 test-runner.cpp - - test-runner.cpp - description - ------------------- - begin : Mon January 10 2005 - copyright : (C) 2005 Peter Soetens - email : peter.soetens@mech.kuleuven.ac.be - - *************************************************************************** - * * - * This program is free software; you can redistribute it and/or modify * - * it under the terms of the GNU General Public License as published by * - * the Free Software Foundation; either version 2 of the License, or * - * (at your option) any later version. * - * * - ***************************************************************************/ - - - -#include -#include -#include -#include -#include - -using namespace RTT; - -int ORO_main(int argc, char** argv) -{ - // disable logging of errors or warnings if no ORO_LOGLEVEL was set. - if ( log().getLogLevel() == Logger::Warning ) { - log(Info) << "Lowering LogLevel to Critical." << endlog(); - log().setLogLevel(Logger::Critical); - } else { - log(Info) << "LogLevel unaltered by test-runner." << endlog(); - } - - // Get the top level suite from the registry - CppUnit::Test *suite = CppUnit::TestFactoryRegistry::getRegistry().makeTest(); - - // Adds the test to the list of test to run - CppUnit::TextUi::TestRunner runner; - runner.addTest( suite ); - - // Change the default outputter to a compiler error format outputter - runner.setOutputter( new CppUnit::CompilerOutputter( &runner.result(), - std::cerr ) ); - - // Run the tests. - bool wasSucessful = runner.run(); - - // Return error code 1 if the one of test failed. - return wasSucessful ? 0 : 1; -} - diff --git a/tests/time_test.cpp b/tests/time_test.cpp deleted file mode 100644 index 80bd1a6fd..000000000 --- a/tests/time_test.cpp +++ /dev/null @@ -1,286 +0,0 @@ -/*************************************************************************** - tag: Peter Soetens Fri Feb 11 15:59:13 CET 2005 time_test.cpp - - time_test.cpp - description - ------------------- - begin : Fri February 11 2005 - copyright : (C) 2005 Peter Soetens - email : peter.soetens@mech.kuleuven.ac.be - - *************************************************************************** - * * - * This program is free software; you can redistribute it and/or modify * - * it under the terms of the GNU General Public License as published by * - * the Free Software Foundation; either version 2 of the License, or * - * (at your option) any later version. * - * * - ***************************************************************************/ - - -#include "time_test.hpp" -#include -#include -#include - -#define EPSILON 0.000000002 - -// Registers the fixture into the 'registry' -CPPUNIT_TEST_SUITE_REGISTRATION( TimeTest ); - -using namespace std; -using namespace RTT; -using namespace boost; - -void -TimeTest::setUp() -{ - hbg = TimeService::Instance(); - long_ns = 9007199254740992LL; // == 2^53 - //long_ns = 4503599627370496LL; // == 2^52 - //long_ns = 123456789123456789LL; // 1.234...e17 ns == approx 4 years, but double can not represent this. - long_S = 9007199.254740992; - //long_S = 4.503599627370496e14; - normal_ns = 1000000000; // 1s - normal_S = 1.0; // 1s - small_ns = 1; // 1ns - small_S = 1e-9; // 1ns - small_t = 1; - normal_t = 1000000000; // 1e9 ticks - long_t = long_ns; // == 2^53 -} - - -void -TimeTest::tearDown() -{ - hbg->enableSystemClock( true ); -} - -#define CPPUNIT_ASSERT_EQUAL_EPS(a, b, eps) if ( !( -(eps) < ((a)-(b)) && (eps) > ((a)-(b)) ) ) { CPPUNIT_ASSERT_EQUAL( a,b); } - -void -TimeTest::testSecondsConversion() -{ - // Test one way - CPPUNIT_ASSERT_EQUAL( long_ns , Seconds_to_nsecs(long_S) ); - CPPUNIT_ASSERT_EQUAL( normal_ns, Seconds_to_nsecs(normal_S)); - CPPUNIT_ASSERT_EQUAL( small_ns , Seconds_to_nsecs(small_S) ); - - // Test other way - CPPUNIT_ASSERT_EQUAL( long_S , nsecs_to_Seconds(long_ns)); - CPPUNIT_ASSERT_EQUAL( normal_S, nsecs_to_Seconds(normal_ns)); - CPPUNIT_ASSERT_EQUAL( small_S , nsecs_to_Seconds(small_ns)); - - // Test invariance of conversions : - CPPUNIT_ASSERT_EQUAL( long_ns , Seconds_to_nsecs( nsecs_to_Seconds(long_ns) )); - CPPUNIT_ASSERT_EQUAL( normal_ns, Seconds_to_nsecs( nsecs_to_Seconds(normal_ns) )); - CPPUNIT_ASSERT_EQUAL( small_ns , Seconds_to_nsecs( nsecs_to_Seconds(small_ns) )); - CPPUNIT_ASSERT_EQUAL( long_S , nsecs_to_Seconds( Seconds_to_nsecs(long_S) )); - CPPUNIT_ASSERT_EQUAL( normal_S, nsecs_to_Seconds( Seconds_to_nsecs(normal_S) )); - CPPUNIT_ASSERT_EQUAL( small_S , nsecs_to_Seconds( Seconds_to_nsecs(small_S) )); -} - -void -TimeTest::testTicksConversion() -{ - // Test ticks conversion invariance : - // Allow rounding error of '2'. ( < 3 ) - int margin = 3; - CPPUNIT_ASSERT_EQUAL_EPS( long_ns , TimeService::ticks2nsecs( TimeService::nsecs2ticks( long_ns )), margin ); - CPPUNIT_ASSERT_EQUAL_EPS( normal_ns, TimeService::ticks2nsecs( TimeService::nsecs2ticks( normal_ns )), margin ); - CPPUNIT_ASSERT_EQUAL_EPS( small_ns , TimeService::ticks2nsecs( TimeService::nsecs2ticks( small_ns )), margin ); - CPPUNIT_ASSERT_EQUAL_EPS( long_t , TimeService::nsecs2ticks( TimeService::ticks2nsecs( long_t )), margin * 2); - CPPUNIT_ASSERT_EQUAL_EPS( normal_t, TimeService::nsecs2ticks( TimeService::ticks2nsecs( normal_t )), margin * 2); - CPPUNIT_ASSERT_EQUAL_EPS( small_t , TimeService::nsecs2ticks( TimeService::ticks2nsecs( small_t )), margin * 2); -} - -void -TimeTest::testTimeProgress() -{ - // A time measurement takes time : - TimeService::ticks t = hbg->getTicks(); - CPPUNIT_ASSERT( t != hbg->getTicks() ); - CPPUNIT_ASSERT( 0 != hbg->ticksSince(t) ); - CPPUNIT_ASSERT( 0 != hbg->secondsSince(t) ); - - // With Re-init of t : - t = 0; - CPPUNIT_ASSERT_EQUAL( TimeService::ticks(0) , hbg->getTicks( t ) ); - t = 0; - // CPPUNIT_ASSERT_EQUAL( Seconds(0.0) , hbg->getSeconds( t ) ); - - // Stop Time Progress: - hbg->enableSystemClock( false ); - t = hbg->getTicks(); - CPPUNIT_ASSERT_EQUAL( t , hbg->getTicks() ); - CPPUNIT_ASSERT_EQUAL( TimeService::ticks(0) , hbg->ticksSince(t) ); - // CPPUNIT_ASSERT_EQUAL( Seconds(0.0) , hbg->secondsSince(t) ); - - Seconds change_S = 0.123456789; - - hbg->secondsChange( change_S ); - CPPUNIT_ASSERT( t != hbg->getTicks() ); // ticks must have changed - CPPUNIT_ASSERT( -EPSILON < (change_S - hbg->secondsSince(t)) && - EPSILON > (change_S - hbg->secondsSince(t)) ); - - // Restart Time Progress - hbg->enableSystemClock( true ); - CPPUNIT_ASSERT( t != hbg->getTicks() ); - CPPUNIT_ASSERT( TimeService::ticks(0) != hbg->ticksSince(t) ); - CPPUNIT_ASSERT( Seconds(0.0) != hbg->secondsSince(t) ); - -} - -struct TestTimer - : public Timer -{ - std::vector< std::pair > occured; - TimeService::Seconds mstart; - TestTimer() - :Timer(32, ORO_SCHED_RT, OS::HighestPriority) - { - occured.reserve(100); - mstart = TimeService::Instance()->secondsSince(0); - } - void timeout(Timer::TimerId id) - { - Seconds now = TimeService::Instance()->secondsSince( 0 ); - occured.push_back( std::make_pair(id, now) ); - //cout << "Occured: "<< id <<" on " << now - mstart <<"\n"; - } - - ~TestTimer() - { - cout.flush(); - } -}; - -void TimeTest::testTimers() -{ - TestTimer timer; - Seconds now = hbg->secondsSince( 0 ); - // Test arming - CPPUNIT_ASSERT( timer.arm(0, 0.5) ); - CPPUNIT_ASSERT( timer.arm(1, 0.6) ); - CPPUNIT_ASSERT( timer.arm(2, 0.5) ); - - CPPUNIT_ASSERT( timer.arm(3, 0.8) ); - CPPUNIT_ASSERT( timer.arm(3, 0.9) ); - - CPPUNIT_ASSERT( timer.isArmed( 0 ) ); - CPPUNIT_ASSERT( timer.isArmed( 1 ) ); - CPPUNIT_ASSERT( timer.isArmed( 2 ) ); - CPPUNIT_ASSERT( timer.isArmed( 3 ) ); - - sleep(1); - - // Test clearing - CPPUNIT_ASSERT( !timer.isArmed( 0 ) ); - CPPUNIT_ASSERT( !timer.isArmed( 1 ) ); - CPPUNIT_ASSERT( !timer.isArmed( 2 ) ); - CPPUNIT_ASSERT( !timer.isArmed( 3 ) ); - - // Test sequence - CPPUNIT_ASSERT( timer.occured.size() == 4 ); - CPPUNIT_ASSERT( timer.occured[0].first == 0 ); - CPPUNIT_ASSERT( timer.occured[1].first == 2 ); - CPPUNIT_ASSERT( timer.occured[2].first == 1 ); - CPPUNIT_ASSERT( timer.occured[3].first == 3 ); - - // Test timeliness - CPPUNIT_ASSERT_EQUAL_EPS( timer.occured[0].second, now+0.5, 0.1 ); - CPPUNIT_ASSERT_EQUAL_EPS( timer.occured[1].second, now+0.5, 0.1 ); - CPPUNIT_ASSERT_EQUAL_EPS( timer.occured[2].second, now+0.6, 0.1 ); - CPPUNIT_ASSERT_EQUAL_EPS( timer.occured[3].second, now+0.9, 0.1 ); - - // Test wrong parameters. - CPPUNIT_ASSERT( timer.arm(4, -0.1) == false); - CPPUNIT_ASSERT( timer.arm(500, 0.1) == false); - - timer.occured.clear(); - - // Test resize. - CPPUNIT_ASSERT( timer.arm(10, 0.5) ); - timer.setMaxTimers( 5 ); // clears the timer - sleep(1); - CPPUNIT_ASSERT( timer.occured.size() == 0 ); -} - -void TimeTest::testTimerPeriod() -{ - TestTimer timer; - Seconds now = hbg->secondsSince( 0 ); - // Test starting periodics - CPPUNIT_ASSERT( timer.startTimer(0, 0.1) ); - CPPUNIT_ASSERT( timer.startTimer(1, 0.6) ); - CPPUNIT_ASSERT( timer.startTimer(2, 0.5) ); - - CPPUNIT_ASSERT( timer.startTimer(3, 0.5) ); - CPPUNIT_ASSERT( timer.startTimer(3, 0.2) ); - - CPPUNIT_ASSERT( timer.isArmed( 0 ) ); - CPPUNIT_ASSERT( timer.isArmed( 1 ) ); - CPPUNIT_ASSERT( timer.isArmed( 2 ) ); - CPPUNIT_ASSERT( timer.isArmed( 3 ) ); - - sleep(1); - - // Test clearing - CPPUNIT_ASSERT( timer.killTimer( 0 ) ); - CPPUNIT_ASSERT( timer.killTimer( 1 ) ); - CPPUNIT_ASSERT( timer.killTimer( 2 ) ); - CPPUNIT_ASSERT( timer.killTimer( 3 ) ); - CPPUNIT_ASSERT( !timer.isArmed( 0 ) ); - CPPUNIT_ASSERT( !timer.isArmed( 1 ) ); - CPPUNIT_ASSERT( !timer.isArmed( 2 ) ); - CPPUNIT_ASSERT( !timer.isArmed( 3 ) ); - - // Test sequence - //CPPUNIT_ASSERT( timer.occured.size() == 4 ); hard to estimate - CPPUNIT_ASSERT( timer.occured[0].first == 0 ); - CPPUNIT_ASSERT( timer.occured[1].first == 0 ); - CPPUNIT_ASSERT( timer.occured[2].first == 3 ); - CPPUNIT_ASSERT( timer.occured[3].first == 0 ); - CPPUNIT_ASSERT( timer.occured[4].first == 0 ); - CPPUNIT_ASSERT( timer.occured[5].first == 3 ); - - CPPUNIT_ASSERT( timer.occured[6].first == 0 ); - CPPUNIT_ASSERT( timer.occured[7].first == 2 ); - - CPPUNIT_ASSERT( timer.occured[8].first == 0 ); - CPPUNIT_ASSERT( timer.occured[9].first == 1 ); - CPPUNIT_ASSERT( timer.occured[10].first == 3 ); - CPPUNIT_ASSERT( timer.occured[11].first == 0 ); - CPPUNIT_ASSERT( timer.occured[12].first == 0 ); - CPPUNIT_ASSERT( timer.occured[13].first == 3 ); - CPPUNIT_ASSERT( timer.occured[14].first == 0 ); - - // Test timeliness - CPPUNIT_ASSERT_EQUAL_EPS( timer.occured[0].second, now+0.1, 0.1 ); - CPPUNIT_ASSERT_EQUAL_EPS( timer.occured[1].second, now+0.2, 0.1 ); - CPPUNIT_ASSERT_EQUAL_EPS( timer.occured[2].second, now+0.2, 0.1 ); - CPPUNIT_ASSERT_EQUAL_EPS( timer.occured[3].second, now+0.3, 0.1 ); - CPPUNIT_ASSERT_EQUAL_EPS( timer.occured[4].second, now+0.4, 0.1 ); - CPPUNIT_ASSERT_EQUAL_EPS( timer.occured[5].second, now+0.4, 0.1 ); - CPPUNIT_ASSERT_EQUAL_EPS( timer.occured[6].second, now+0.5, 0.1 ); - CPPUNIT_ASSERT_EQUAL_EPS( timer.occured[7].second, now+0.5, 0.1 ); - CPPUNIT_ASSERT_EQUAL_EPS( timer.occured[8].second, now+0.6, 0.1 ); - CPPUNIT_ASSERT_EQUAL_EPS( timer.occured[9].second, now+0.6, 0.1 ); - CPPUNIT_ASSERT_EQUAL_EPS( timer.occured[10].second, now+0.6, 0.1 ); - CPPUNIT_ASSERT_EQUAL_EPS( timer.occured[11].second, now+0.7, 0.1 ); - CPPUNIT_ASSERT_EQUAL_EPS( timer.occured[12].second, now+0.8, 0.1 ); - CPPUNIT_ASSERT_EQUAL_EPS( timer.occured[13].second, now+0.8, 0.1 ); - CPPUNIT_ASSERT_EQUAL_EPS( timer.occured[14].second, now+0.9, 0.1 ); - - // Test wrong parameters. - CPPUNIT_ASSERT( timer.startTimer(4, -0.1) == false); - CPPUNIT_ASSERT( timer.startTimer(500, 0.1) == false); - - timer.occured.clear(); - - // Test resize. - CPPUNIT_ASSERT( timer.startTimer(10, 0.5) ); - timer.setMaxTimers( 5 ); // clears the timer - sleep(1); - CPPUNIT_ASSERT( timer.occured.size() == 0 ); -} diff --git a/tests/time_test.hpp b/tests/time_test.hpp deleted file mode 100644 index b4c18b6c3..000000000 --- a/tests/time_test.hpp +++ /dev/null @@ -1,56 +0,0 @@ -/*************************************************************************** - tag: Peter Soetens Fri Feb 11 15:59:13 CET 2005 time_test.hpp - - time_test.hpp - description - ------------------- - begin : Fri February 11 2005 - copyright : (C) 2005 Peter Soetens - email : peter.soetens@mech.kuleuven.ac.be - - *************************************************************************** - * * - * This program is free software; you can redistribute it and/or modify * - * it under the terms of the GNU General Public License as published by * - * the Free Software Foundation; either version 2 of the License, or * - * (at your option) any later version. * - * * - ***************************************************************************/ - - - -#ifndef TIMETEST_H -#define TIMETEST_H - -#include -#include -#include -#include -#include -#include - -class TimeTest : public CppUnit::TestFixture -{ - CPPUNIT_TEST_SUITE( TimeTest ); - CPPUNIT_TEST( testSecondsConversion ); - CPPUNIT_TEST( testTicksConversion ); - CPPUNIT_TEST( testTimeProgress ); - CPPUNIT_TEST( testTimers ); - CPPUNIT_TEST( testTimerPeriod ); - CPPUNIT_TEST_SUITE_END(); - - RTT::TimeService* hbg; - double small_S, normal_S, long_S; - RTT::TimeService::ticks small_t, normal_t, long_t; - RTT::nsecs small_ns, normal_ns, long_ns; -public: - void setUp(); - void tearDown(); - - void testSecondsConversion(); - void testTicksConversion(); - void testTimeProgress(); - void testTimers(); - void testTimerPeriod(); -}; - -#endif // TIMETEST_H diff --git a/tests/types_test.cpp b/tests/types_test.cpp deleted file mode 100644 index b730c9315..000000000 --- a/tests/types_test.cpp +++ /dev/null @@ -1,370 +0,0 @@ -/*************************************************************************** - tag: Peter Soetens Mon Jan 10 15:59:50 CET 2005 types_test.cpp - - types_test.cpp - description - ------------------- - begin : Mon January 10 2005 - copyright : (C) 2005 Peter Soetens - email : peter.soetens@mech.kuleuven.ac.be - - *************************************************************************** - * * - * This program is free software; you can redistribute it and/or modify * - * it under the terms of the GNU General Public License as published by * - * the Free Software Foundation; either version 2 of the License, or * - * (at your option) any later version. * - * * - ***************************************************************************/ - - - -#include "types_test.hpp" -#include -#include -#include -#include -#include -#include -#include -#include -#include - -using namespace std; - -// Registers the fixture into the 'registry' -CPPUNIT_TEST_SUITE_REGISTRATION( TypesTest ); - - -void -TypesTest::setUp() -{ - tc = new TaskContext( "root" ); - tc->addObject( this->createMethodFactory() ); - tsim = new SimulationActivity( 0.001, tc->engine() ); - SimulationThread::Instance()->stop(); -} - - -void -TypesTest::tearDown() -{ - tsim->stop(); - delete tc; - delete tsim; -} - - -bool TypesTest::assertBool( bool b) { - return b; -} -bool TypesTest::assertMsg( bool b, const std::string& msg) { - return b; -} - - - TaskObject* TypesTest::createMethodFactory() - { - TaskObject* to = new TaskObject("test"); - to->methods()->addMethod( method("assert", &TypesTest::assertBool, this), - "Assert", "bool", ""); - to->methods()->addMethod( method("assertMsg", &TypesTest::assertMsg, this), - "Assert message", "bool", "", "text", "text" ); - return to; - } - - -void TypesTest::testTypes() -{ - // XXX - // for some reason, we can not compare the double6D's one fails - // to parse, the others assert false, thus inequality. - string test = - // Line 2: - string("var int i2 = -1, j = 10, k; set k = 20\n") + - "do test.assert( i2 == -1 ) ; do test.assert( j == 10 ); do test.assert(k == 20)\n" + - "var double d = 10.0\n"+ - "do test.assert( d == 10.0 )\n" + - "var bool b = false\n"+ - "do test.assert( b == false )\n" + - "var string s=\"string\"\n"+ - "do test.assert( s == \"string\" )\n" + - "const int ic = i2\n" + - "do test.assert( ic == 0 )\n" + // i was null at parse time ! - "const double dc = 10.0\n"+ // evaluate 10.0 at parse time - "do test.assert( dc == 10.0 )\n" + - "const bool bc = true && false\n"+ - "do test.assert( bc == false )\n" + - "const string sc= \"hello\"\n"+ - "do test.assert( sc == \"hello\" )\n" + - "var array ar(10)\n"+ // size hint syntax != constructor syntax - "do test.assert( ar.size == 10)\n"+ - // 20: - "do test.assert( ar.capacity == 10)\n"+ - "set ar[0] = 0.0\n"+ - "set ar[1] = 1.0\n"+ - "set ar[2] = 0.2\n"+ - "set ar[8] = 0.8\n"+ - "set ar[9] = 9.0\n"+ - "do test.assert( ar[0] == 0.0 )\n"+ - "do test.assert( ar[1] == 1.0 )\n"+ - "do test.assert( ar[2] == 0.2 )\n"+ - "do test.assert( ar[8] == 0.8 )\n"+ - // 30: - "do test.assert( ar[9] == 9.0 )\n"+ - "do test.assert( ar[10] == 0.0 )\n"+ - "var array ar1(12,2.0)\n"+ - "do test.assert(ar1.size == 12)\n"+ - "do test.assert(ar1[0] == 2.0)\n"+ - "var array ar2 = array(5,3.0)\n"+ - "do test.assert(ar2.size == 5)\n"+ - "do test.assert(ar2[0] == 3.0)\n"+ - "var array ar3(2.0,3.0,4.0)\n"+ - "do test.assert(ar3.size == 3)\n"+ - //40: - "do test.assert(ar3[0]==2.0)\n"+ - "do test.assert(ar3[1]==3.0)\n"+ - "do test.assert(ar3[2]==4.0)\n"+ - "var array ar4 = array(2.0,3.0,4.0,5.0)\n"+ - "do test.assert(ar4.size == 4)\n"+ - "do test.assert(ar4[0]==2.0)\n"+ - "do test.assert(ar4[1]==3.0)\n"+ - "do test.assert(ar4[2]==4.0)\n"+ - "do test.assert(ar4[3]==5.0)\n"+ - "var string str(10) = \"hello\"\n"+ - // 50: - "do test.assert( str.size == 10)\n"+ - "do test.assert( str.capacity == 10)\n"+ - "set str[0] = 'a'\n"+ - "set str[1] = 'b'\n"+ - "set str[2] = 'c'\n"+ - "do test.assert( str[0] == 'a' )\n"+ - "do test.assert( str[1] == 'b' )\n"+ - "do test.assert( str[2] == 'c' )\n"+ - "do test.assert( str == \"abclo\" )\n"+ - "do test.assert( str[20] == '\\0' )\n"+ - // 60: - "do test.assert( str[8] == '\\0' )\n"+ - "do test.assert( str[9] == '\\0' )\n"+ - "do test.assert( str[10] == '\\0' )\n"+ - // various array constructors - "var array ar2 = array(10.,5.)\n"+ - "do test.assert( ar2.size == 2)\n"+ - "do test.assert( ar2.capacity == 2)\n"+ - "do test.assert( ar2[0] == 10.0 )\n"+ - "do test.assert( ar2[1] == 5.0 )\n"+ - "var array ar3 = array(10.)\n"+ - "do test.assert( ar3.size == 1)\n"+ - "do test.assert( ar3.capacity == 1)\n"+ - "do test.assert( ar3[0] == 10.0 )\n"+ - "var array ar4 = array(2, 7.)\n"+ - "do test.assert( ar4.size == 2)\n"+ - "do test.assert( ar4.capacity == 2)\n"+ - "do test.assert( ar4[0] == 7.0 )\n"+ - "do test.assert( ar4[1] == 7.0 )\n"+ - // various array assignments - "set ar2 = ar4\n"+ - "do test.assert( ar2.size == 2)\n"+ - "do test.assert( ar2.capacity == 2)\n"+ - "do test.assert( ar2[0] == 7.0 )\n"+ - "do test.assert( ar2[1] == 7.0 )\n"+ - "set ar = ar2\n"+ - "do test.assert( ar.size == 2)\n"+ - "do test.assert( ar.capacity == 10)\n"+ - "do test.assert( ar2[0] == 7.0 )\n"+ - "do test.assert( ar2[1] == 7.0 )\n"; - - string state = string("StateMachine X { initial state Init { run {\n") - +test - +"} }\n" - +"final state Fini {} }\n" - +"RootMachine X x\n"; - - string prog = string("program x {\n") + test + "}\n"; - executeStates(state); - - // execute - executePrograms(prog); - -} - -void TypesTest::testOperators() -{ - string prog = string("program x {\n") + - "var int i = 3\n" + - "var char c = 'c'\n" + - "var double d = 10.0*i\n"+ - "do test.assert( d == 30.0 )\n" + - "var bool b = false\n"+ - "var string s=\"string\"\n"+ -// "do test.assert( d == 10.0 )\n" + - "set b = b\n or\n b\n and\n true\n && false\n || true\n"+ - "do test.assert( b == false )\n" + - "var array a1 = array(2, 7.)\n"+ - "do test.assert( a1.size == 2 )\n" + - "do test.assert( a1.capacity == 2 )\n" + -// "set s = s+\"abc\"\n"+ - "}"; - // execute - executePrograms(prog); -} - -void TypesTest::testConversions() -{ - string prog = string("program x {\n") + - "var int i = 3.0\n" + - "var double d = float(10.0*i)\n"+ - "do test.assert( float(d) == float(30.0) )\n" + - "var float f = 5\n" + - "set f = double(5) * double(-1) + i\n" + - "set i = f\n" + - "set f = i\n" + - "set i = double(float(int(f)))\n" + - "set f = int(float(double(int(3.333))))\n" + - "do test.assert( f == 3 )\n" + - "}"; - // execute - executePrograms(prog); -} -void TypesTest::testProperties() -{ - string prog = string("program x {\n") + - "do test.assert( Double1 == 1.234 )\n" + - "do test.assert( Double2 == 2.234 )\n" + - "do test.assert( Double3 == 3.234 )\n" + - "do test.assert( Collection.Double1 == 1.234 )\n" + - "do test.assert( Collection.Double3 == 3.234 )\n" + - "do test.assert( Collection.Collection.Double1 == 1.234 )\n" + - "do test.assert( Collection.Collection.Collection.Double3 == 3.234 )\n" + - "do test.assert( V[0] == 4.0 )\n" + - "do test.assert( V[1] == 4.0 )\n" + - "do test.assert( V[2] == 4.0 )\n" + - "do test.assert( V[3] == 4.0 )\n" + - //"do test.assert( V.size() == 4 )\n" + - "set Double1 = 4.321\n" + - "set Double2 = Double1\n" + - // -> = 10 - "set Collection.Double3 = 0.3\n" + - "set V[0] = 0.321\n" + - "set V[1] = 1.321\n" + - "set V[2] = 2.321\n" + - "set V[3] = 3.321\n" + - "do test.assert( Double1 == 4.321 )\n" + - "do test.assert( Double2 == 4.321 )\n" + - "do test.assert( Double3 == 0.3 )\n" + - "set Collection.Collection.Collection.Double3 = 3.0\n" + - "do test.assert( Double3 == 3.0 )\n" + - "}"; - - Property pb("Collection",""); - Property pd1("Double1","",1.234); - Property pd2("Double2","",2.234); - Property pd3("Double3","",3.234); - - Property< std::vector > pv("V","",std::vector(4, 4.0) ); - - pb.value().add( &pd1 ); - pb.value().add( &pd3 ); - pb.value().add( &pb ); // yep, recursive ! - - tc->properties()->addProperty( &pd1 ); - tc->properties()->addProperty( &pd2 ); - tc->properties()->addProperty( &pd3 ); - tc->properties()->addProperty( &pb ); - tc->properties()->addProperty( &pv ); - - // execute - executePrograms(prog); - - CPPUNIT_ASSERT_EQUAL( 4.321, pd1.get() ); - CPPUNIT_ASSERT_EQUAL( 3.0, pd3.get() ); - CPPUNIT_ASSERT_EQUAL( 0.321, pv.value()[0] ); - CPPUNIT_ASSERT_EQUAL( 1.321, pv.value()[1] ); - CPPUNIT_ASSERT_EQUAL( 2.321, pv.value()[2] ); - CPPUNIT_ASSERT_EQUAL( 3.321, pv.value()[3] ); -} - -void TypesTest::executePrograms(const std::string& prog ) -{ - CPPUNIT_ASSERT( tc->engine() ); - CPPUNIT_ASSERT( tc->engine()->programs()); - - Parser::ParsedPrograms pg_list; - try { - pg_list = parser.parseProgram( prog, tc ); - } - catch( const file_parse_exception& exc ) - { - CPPUNIT_ASSERT_MESSAGE(exc.what(), false ); - } - if ( pg_list.empty() ) - { - CPPUNIT_ASSERT( false ); - } - - CPPUNIT_ASSERT( tc->engine()->programs()->loadProgram( *pg_list.begin() ) ); - CPPUNIT_ASSERT( tsim->start() ); - CPPUNIT_ASSERT( (*pg_list.begin())->start() ); - - CPPUNIT_ASSERT( SimulationThread::Instance()->run(1000) ); - - if ( (*pg_list.begin())->inError() ) { - stringstream errormsg; - errormsg << " Program error on line " << (*pg_list.begin())->getLineNumber() <<"."<isRunning() ) { - stringstream errormsg; - errormsg << " Program still running on line " << (*pg_list.begin())->getLineNumber() <<"."<isStopped() == false ) { - stringstream errormsg; - errormsg << " Program not stopped on line " << (*pg_list.begin())->getLineNumber() <<"."<stop() ); - tsim->stop(); - tc->engine()->programs()->unloadProgram( (*pg_list.begin())->getName() ); -} - -void TypesTest::executeStates(const std::string& state ) -{ - CPPUNIT_ASSERT( tc->engine() ); - CPPUNIT_ASSERT( tc->engine()->states()); - Parser::ParsedStateMachines pg_list; - try { - pg_list = parser.parseStateMachine( state, tc ); - } - catch( const file_parse_exception& exc ) - { - CPPUNIT_ASSERT_MESSAGE(exc.what(), false ); - } - if ( pg_list.empty() ) - { - CPPUNIT_ASSERT( false ); - } - - CPPUNIT_ASSERT( tc->engine()->states()->loadStateMachine( *pg_list.begin() ) ); - CPPUNIT_ASSERT( tsim->start() ); - CPPUNIT_ASSERT( (*pg_list.begin())->activate() ); - CPPUNIT_ASSERT( (*pg_list.begin())->start() ); - - CPPUNIT_ASSERT( SimulationThread::Instance()->run(1000) ); - if ( (*pg_list.begin())->inError() ) { - stringstream errormsg; - errormsg << " State error on line " << (*pg_list.begin())->getLineNumber() <<"."<stop() ); - CPPUNIT_ASSERT( SimulationThread::Instance()->run(100) ); - CPPUNIT_ASSERT( (*pg_list.begin())->deactivate() ); - - tsim->stop(); - tc->engine()->states()->unloadStateMachine( (*pg_list.begin())->getName() ); -} - - - diff --git a/tests/types_test.hpp b/tests/types_test.hpp deleted file mode 100644 index baf52a950..000000000 --- a/tests/types_test.hpp +++ /dev/null @@ -1,60 +0,0 @@ -/*************************************************************************** - tag: Peter Soetens Mon Jan 10 15:59:18 CET 2005 types_test.hpp - - types_test.hpp - description - ------------------- - begin : Mon January 10 2005 - copyright : (C) 2005 Peter Soetens - email : peter.soetens@mech.kuleuven.ac.be - - *************************************************************************** - * * - * This program is free software; you can redistribute it and/or modify * - * it under the terms of the GNU General Public License as published by * - * the Free Software Foundation; either version 2 of the License, or * - * (at your option) any later version. * - * * - ***************************************************************************/ - - -#ifndef TYPESTEST_H -#define TYPESTEST_H - -#include - -#include -#include -#include -#include - -using namespace RTT; - -class TypesTest : public CppUnit::TestFixture -{ - CPPUNIT_TEST_SUITE( TypesTest ); - //CPPUNIT_TEST( testTypes ); - CPPUNIT_TEST( testOperators ); -// CPPUNIT_TEST( testProperties ); -// CPPUNIT_TEST( testConversions ); - CPPUNIT_TEST_SUITE_END(); - - Parser parser; - TaskContext* tc; - ActivityInterface* tsim; - TaskObject* createMethodFactory(); - bool assertBool( bool ); - bool assertMsg( bool, const std::string& msg); - void executePrograms(const std::string& prog); - void executeStates(const std::string& state); -public: - - void setUp(); - void tearDown(); - - void testTypes(); - void testOperators(); - void testProperties(); - void testConversions(); -}; - -#endif