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 WFLAGFORWARDER_TEST_H 00026 #define WFLAGFORWARDER_TEST_H 00027 00028 #include <cxxtest/TestSuite.h> 00029 00030 #include "../WFlagForwarder.h" 00031 #include "../WFlag.h" 00032 #include "../WConditionOneShot.h" 00033 00034 /** 00035 * Test WFlagForwarder. 00036 */ 00037 class WFlagForwarderTest : public CxxTest::TestSuite 00038 { 00039 public: 00040 /** 00041 * Add some flags and test whether the value gets propagated properly. 00042 */ 00043 void testPropagation( void ) 00044 { 00045 // create some flags 00046 boost::shared_ptr< WFlag< int > > flagSource( new WFlag< int >( new WConditionOneShot(), 5 ) ); 00047 boost::shared_ptr< WFlag< int > > flagTarget1( new WFlag< int >( new WConditionOneShot(), 10 ) ); 00048 boost::shared_ptr< WFlag< int > > flagTarget2( new WFlag< int >( new WConditionOneShot(), 15 ) ); 00049 00050 // create the forwarder 00051 WFlagForwarder< int >* f = new WFlagForwarder< int >( flagSource ); 00052 f->forward( flagTarget1 ); 00053 f->forward( flagTarget2 ); 00054 00055 // now all flags should have value 5 00056 TS_ASSERT( flagSource->get() == 5 ); 00057 TS_ASSERT( flagTarget1->get() == 5 ); 00058 TS_ASSERT( flagTarget2->get() == 5 ); 00059 00060 // set some value to the source 00061 flagSource->set( 50 ); 00062 00063 // now all flags should have value 50 00064 TS_ASSERT( flagSource->get() == 50 ); 00065 TS_ASSERT( flagTarget1->get() == 50 ); 00066 TS_ASSERT( flagTarget2->get() == 50 ); 00067 00068 // changing the value of one target flag should not affect the others: 00069 flagTarget2->set( 100 ); 00070 TS_ASSERT( flagSource->get() == 50 ); 00071 TS_ASSERT( flagTarget1->get() == 50 ); 00072 TS_ASSERT( flagTarget2->get() == 100 ); 00073 } 00074 }; 00075 00076 #endif // WFLAGFORWARDER_TEST_H 00077 00078