OpenWalnut  1.4.0
WThreadedRunner_test.h
1 //---------------------------------------------------------------------------
2 //
3 // Project: OpenWalnut ( http://www.openwalnut.org )
4 //
5 // Copyright 2009 OpenWalnut Community, BSV@Uni-Leipzig and CNCF@MPI-CBS
6 // For more information see http://www.openwalnut.org/copying
7 //
8 // This file is part of OpenWalnut.
9 //
10 // OpenWalnut is free software: you can redistribute it and/or modify
11 // it under the terms of the GNU Lesser General Public License as published by
12 // the Free Software Foundation, either version 3 of the License, or
13 // (at your option) any later version.
14 //
15 // OpenWalnut is distributed in the hope that it will be useful,
16 // but WITHOUT ANY WARRANTY; without even the implied warranty of
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 // GNU Lesser General Public License for more details.
19 //
20 // You should have received a copy of the GNU Lesser General Public License
21 // along with OpenWalnut. If not, see <http://www.gnu.org/licenses/>.
22 //
23 //---------------------------------------------------------------------------
24 
25 #ifndef WTHREADEDRUNNER_TEST_H
26 #define WTHREADEDRUNNER_TEST_H
27 
28 #include <iostream>
29 
30 #include <cxxtest/TestSuite.h>
31 
32 #include "../WThreadedRunner.h"
33 
34 /**
35  * Class implementing a simple worker thread, since proper testing of WThreadedRunner itself is not usable.
36  */
38 {
39  friend class WThreadedRunnerTest;
40 protected:
41  /**
42  * Function that has to be overwritten for execution. It gets executed in a separate thread after run()
43  * has been called.
44  */
45  virtual void threadMain()
46  {
47  // Since the modules run in a separate thread: such loops are possible
48  while( !m_shutdownFlag() )
49  {
50  // do fancy stuff
51  sleep( 1 );
52  }
53  }
54 };
55 
56 /**
57  * Tests the WThreadedRunner class.
58  */
59 class WThreadedRunnerTest : public CxxTest::TestSuite
60 {
61 public:
62  /**
63  * Ensure that nothing is thrown when an instance is created.
64  */
65  void testInstantiation( void )
66  {
67  TS_ASSERT_THROWS_NOTHING( WThreadedRunnerImpl() );
68  }
69 
70  /**
71  * Ensure that nothing is thrown when going to sleep.
72  */
73  void testSleep( void )
74  {
76 
77  TS_ASSERT_THROWS_NOTHING( t.sleep( 1 ) );
78  }
79 
80  /**
81  * Ensure that nothing is thrown when running thread.
82  */
83  void testRun( void )
84  {
86 
87  TS_ASSERT_THROWS_NOTHING( t.run() );
88  TS_ASSERT_THROWS_NOTHING( t.wait( true ) );
89  }
90 };
91 
92 #endif // WTHREADEDRUNNER_TEST_H
93 
void testInstantiation(void)
Ensure that nothing is thrown when an instance is created.
virtual void run()
Run thread.
Base class for all classes needing to be executed in a separate thread.
void testRun(void)
Ensure that nothing is thrown when running thread.
virtual void threadMain()
Function that has to be overwritten for execution.
void sleep(const int32_t t) const
Sets thread asleep.
Class implementing a simple worker thread, since proper testing of WThreadedRunner itself is not usab...
Tests the WThreadedRunner class.
WBoolFlag m_shutdownFlag
Condition getting fired whenever the thread should quit.
void testSleep(void)
Ensure that nothing is thrown when going to sleep.
void wait(bool requestFinish=false)
Wait for the thread to be finished.