OpenWalnut
1.4.0
|
00001 //--------------------------------------------------------------------------- 00002 // 00003 // Project: OpenWalnut ( http://www.openwalnut.org ) 00004 // 00005 // Copyright 2009 OpenWalnut Community, BSV@Uni-Leipzig and CNCF@MPI-CBS 00006 // For more information see http://www.openwalnut.org/copying 00007 // 00008 // This file is part of OpenWalnut. 00009 // 00010 // OpenWalnut is free software: you can redistribute it and/or modify 00011 // it under the terms of the GNU Lesser General Public License as published by 00012 // the Free Software Foundation, either version 3 of the License, or 00013 // (at your option) any later version. 00014 // 00015 // OpenWalnut is distributed in the hope that it will be useful, 00016 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00017 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00018 // GNU Lesser General Public License for more details. 00019 // 00020 // You should have received a copy of the GNU Lesser General Public License 00021 // along with OpenWalnut. If not, see <http://www.gnu.org/licenses/>. 00022 // 00023 //--------------------------------------------------------------------------- 00024 00025 #ifndef WTHREADEDRUNNER_TEST_H 00026 #define WTHREADEDRUNNER_TEST_H 00027 00028 #include <iostream> 00029 00030 #include <cxxtest/TestSuite.h> 00031 00032 #include "../WThreadedRunner.h" 00033 00034 /** 00035 * Class implementing a simple worker thread, since proper testing of WThreadedRunner itself is not usable. 00036 */ 00037 class WThreadedRunnerImpl: public WThreadedRunner 00038 { 00039 friend class WThreadedRunnerTest; 00040 protected: 00041 /** 00042 * Function that has to be overwritten for execution. It gets executed in a separate thread after run() 00043 * has been called. 00044 */ 00045 virtual void threadMain() 00046 { 00047 // Since the modules run in a separate thread: such loops are possible 00048 while( !m_shutdownFlag() ) 00049 { 00050 // do fancy stuff 00051 sleep( 1 ); 00052 } 00053 } 00054 }; 00055 00056 /** 00057 * Tests the WThreadedRunner class. 00058 */ 00059 class WThreadedRunnerTest : public CxxTest::TestSuite 00060 { 00061 public: 00062 /** 00063 * Ensure that nothing is thrown when an instance is created. 00064 */ 00065 void testInstantiation( void ) 00066 { 00067 TS_ASSERT_THROWS_NOTHING( WThreadedRunnerImpl() ); 00068 } 00069 00070 /** 00071 * Ensure that nothing is thrown when going to sleep. 00072 */ 00073 void testSleep( void ) 00074 { 00075 WThreadedRunnerImpl t; 00076 00077 TS_ASSERT_THROWS_NOTHING( t.sleep( 1 ) ); 00078 } 00079 00080 /** 00081 * Ensure that nothing is thrown when running thread. 00082 */ 00083 void testRun( void ) 00084 { 00085 WThreadedRunnerImpl t; 00086 00087 TS_ASSERT_THROWS_NOTHING( t.run() ); 00088 TS_ASSERT_THROWS_NOTHING( t.wait( true ) ); 00089 } 00090 }; 00091 00092 #endif // WTHREADEDRUNNER_TEST_H 00093