OpenWalnut  1.2.5
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
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  /**
42  * Add some flags and test whether the value gets propagated properly.
43  */
44  void testPropagation( void )
45  {
46  // create some flags
47  boost::shared_ptr< WFlag< int > > flagSource = boost::shared_ptr< WFlag< int > >( new WFlag< int >( new WConditionOneShot(), 5 ) );
48  boost::shared_ptr< WFlag< int > > flagTarget1 = boost::shared_ptr< WFlag< int > >( new WFlag< int >( new WConditionOneShot(), 10 ) );
49  boost::shared_ptr< WFlag< int > > flagTarget2 = boost::shared_ptr< WFlag< int > >( new WFlag< int >( new WConditionOneShot(), 15 ) );
50 
51  // create the forwarder
52  WFlagForwarder< int >* f = new WFlagForwarder< int >( flagSource );
53  f->forward( flagTarget1 );
54  f->forward( flagTarget2 );
55 
56  // now all flags should have value 5
57  TS_ASSERT( flagSource->get() == 5 );
58  TS_ASSERT( flagTarget1->get() == 5 );
59  TS_ASSERT( flagTarget2->get() == 5 );
60 
61  // set some value to the source
62  flagSource->set( 50 );
63 
64  // now all flags should have value 50
65  TS_ASSERT( flagSource->get() == 50 );
66  TS_ASSERT( flagTarget1->get() == 50 );
67  TS_ASSERT( flagTarget2->get() == 50 );
68 
69  // changing the value of one target flag should not affect the others:
70  flagTarget2->set( 100 );
71  TS_ASSERT( flagSource->get() == 50 );
72  TS_ASSERT( flagTarget1->get() == 50 );
73  TS_ASSERT( flagTarget2->get() == 100 );
74  }
75 };
76 
77 #endif // WFLAGFORWARDER_TEST_H
78 
79