OpenWalnut  1.4.0
WFlagForwarder_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 WFLAGFORWARDER_TEST_H
26 #define WFLAGFORWARDER_TEST_H
27 
28 #include <cxxtest/TestSuite.h>
29 
30 #include "../WFlagForwarder.h"
31 #include "../WFlag.h"
32 #include "../WConditionOneShot.h"
33 
34 /**
35  * Test WFlagForwarder.
36  */
37 class WFlagForwarderTest : public CxxTest::TestSuite
38 {
39 public:
40  /**
41  * Add some flags and test whether the value gets propagated properly.
42  */
43  void testPropagation( void )
44  {
45  // create some flags
46  boost::shared_ptr< WFlag< int > > flagSource( new WFlag< int >( new WConditionOneShot(), 5 ) );
47  boost::shared_ptr< WFlag< int > > flagTarget1( new WFlag< int >( new WConditionOneShot(), 10 ) );
48  boost::shared_ptr< WFlag< int > > flagTarget2( new WFlag< int >( new WConditionOneShot(), 15 ) );
49 
50  // create the forwarder
51  WFlagForwarder< int >* f = new WFlagForwarder< int >( flagSource );
52  f->forward( flagTarget1 );
53  f->forward( flagTarget2 );
54 
55  // now all flags should have value 5
56  TS_ASSERT( flagSource->get() == 5 );
57  TS_ASSERT( flagTarget1->get() == 5 );
58  TS_ASSERT( flagTarget2->get() == 5 );
59 
60  // set some value to the source
61  flagSource->set( 50 );
62 
63  // now all flags should have value 50
64  TS_ASSERT( flagSource->get() == 50 );
65  TS_ASSERT( flagTarget1->get() == 50 );
66  TS_ASSERT( flagTarget2->get() == 50 );
67 
68  // changing the value of one target flag should not affect the others:
69  flagTarget2->set( 100 );
70  TS_ASSERT( flagSource->get() == 50 );
71  TS_ASSERT( flagTarget1->get() == 50 );
72  TS_ASSERT( flagTarget2->get() == 100 );
73  }
74 };
75 
76 #endif // WFLAGFORWARDER_TEST_H
77 
78