OpenWalnut  1.5.0dev
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 <memory>
29 
30 #include <cxxtest/TestSuite.h>
31 
32 #include "../WConditionOneShot.h"
33 #include "../WFlag.h"
34 #include "../WFlagForwarder.h"
35 
36 /**
37  * Test WFlagForwarder.
38  */
39 class WFlagForwarderTest : public CxxTest::TestSuite
40 {
41 public:
42  /**
43  * Add some flags and test whether the value gets propagated properly.
44  */
45  void testPropagation( void )
46  {
47  // create some flags
48  std::shared_ptr< WFlag< int > > flagSource( new WFlag< int >( new WConditionOneShot(), 5 ) );
49  std::shared_ptr< WFlag< int > > flagTarget1( new WFlag< int >( new WConditionOneShot(), 10 ) );
50  std::shared_ptr< WFlag< int > > flagTarget2( new WFlag< int >( new WConditionOneShot(), 15 ) );
51 
52  // create the forwarder
53  WFlagForwarder< int >* f = new WFlagForwarder< int >( flagSource );
54  f->forward( flagTarget1 );
55  f->forward( flagTarget2 );
56 
57  // now all flags should have value 5
58  TS_ASSERT( flagSource->get() == 5 );
59  TS_ASSERT( flagTarget1->get() == 5 );
60  TS_ASSERT( flagTarget2->get() == 5 );
61 
62  // set some value to the source
63  flagSource->set( 50 );
64 
65  // now all flags should have value 50
66  TS_ASSERT( flagSource->get() == 50 );
67  TS_ASSERT( flagTarget1->get() == 50 );
68  TS_ASSERT( flagTarget2->get() == 50 );
69 
70  // changing the value of one target flag should not affect the others:
71  flagTarget2->set( 100 );
72  TS_ASSERT( flagSource->get() == 50 );
73  TS_ASSERT( flagTarget1->get() == 50 );
74  TS_ASSERT( flagTarget2->get() == 100 );
75  }
76 };
77 
78 #endif // WFLAGFORWARDER_TEST_H
79 
80 
Implements a WCondition, but can be fired only ONCE.
Test WFlagForwarder.
void testPropagation(void)
Add some flags and test whether the value gets propagated properly.
This class helps especially container module programmers to easily synchronize the value of one flag ...
void forward(std::shared_ptr< WFlag< T > > to)
Forward the source property to the specified one.
Class to have a simple notification/condition system for simple flags.
Definition: WFlag.h:39