OpenWalnut
1.2.5
|
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 WPROGRESSCOMBINER_TEST_H 00026 #define WPROGRESSCOMBINER_TEST_H 00027 00028 #include <iostream> 00029 00030 #include <boost/shared_ptr.hpp> 00031 00032 #include <cxxtest/TestSuite.h> 00033 00034 #include "../WProgress.h" 00035 #include "../WProgressCombiner.h" 00036 00037 /** 00038 * Class testing the functionality of progress combiners. 00039 */ 00040 class WProgressCombinerTest : public CxxTest::TestSuite 00041 { 00042 public: 00043 00044 /** 00045 * Test whether WProgress is instantiatable. 00046 */ 00047 void testInstantiation() 00048 { 00049 TS_ASSERT_THROWS_NOTHING( WProgressCombiner p( "Test" ) ); 00050 } 00051 00052 /** 00053 * Test whether the combiner ignores manual increments. 00054 */ 00055 void testInternalStateIgnoresIncrementAndFinish() 00056 { 00057 WProgressCombiner p( "Test" ); 00058 00059 // try increment 00060 ++++++p; 00061 TS_ASSERT_THROWS_NOTHING( p.update() ); 00062 TS_ASSERT( p.getProgress() == 0.0 ); 00063 00064 // should ignore finish() 00065 p.finish(); 00066 TS_ASSERT_THROWS_NOTHING( p.update() ); 00067 TS_ASSERT( !p.isPending() ); 00068 } 00069 00070 /** 00071 * Test the combiner when some childs got added to it. 00072 */ 00073 void testWithChilds() 00074 { 00075 WProgressCombiner p( "Test" ); 00076 00077 // create some children 00078 boost::shared_ptr< WProgress> p1 = boost::shared_ptr< WProgress>( new WProgress( "TestP1", 11 ) ); 00079 boost::shared_ptr< WProgress> p2 = boost::shared_ptr< WProgress>( new WProgress( "TestP2", 11 ) ); 00080 boost::shared_ptr< WProgress> p3 = boost::shared_ptr< WProgress>( new WProgress( "TestP3" ) ); 00081 00082 // as the first and only child is determined (has a known end point) -> the combiner is determined 00083 TS_ASSERT_THROWS_NOTHING( p.addSubProgress( p1 ) ); 00084 p.update(); 00085 TS_ASSERT( p.isDetermined() ); 00086 00087 // increment a bit 00088 ++++++++++( *p1 ); 00089 p.update(); // updating is needed in every case, as this is used to propagate changes. 00090 // p1 is now at 50% -> the combiner should also be at 50% 00091 TS_ASSERT( p1->getProgress() == 50.0 ); 00092 TS_ASSERT( p.getProgress() == 50.0 ); 00093 00094 // add another determined progress 00095 TS_ASSERT_THROWS_NOTHING( p.addSubProgress( p2 ) ); 00096 p.update(); 00097 TS_ASSERT( p.isDetermined() ); 00098 TS_ASSERT( p.getProgress() == 25.0 ); // as p2 is at 0% currently 00099 00100 // now add an indetermined progress 00101 TS_ASSERT_THROWS_NOTHING( p.addSubProgress( p3 ) ); 00102 p.update(); 00103 TS_ASSERT( !p3->isDetermined() ); 00104 TS_ASSERT( !p.isDetermined() ); 00105 00106 // now finish the progress and test whether to combiner reacts on it. 00107 00108 // when finishing the indetermined progress the combiner is determined again. 00109 p3->finish(); 00110 p.update(); 00111 TS_ASSERT( p.isDetermined() ); 00112 TS_ASSERT( p.isPending() ); 00113 00114 // finish the other progress 00115 p1->finish(); 00116 p2->finish(); 00117 p.update(); 00118 TS_ASSERT( !p.isPending() ); 00119 00120 // finish the combiner 00121 p.finish(); 00122 TS_ASSERT( p.m_children.empty() ); 00123 } 00124 }; 00125 00126 #endif // WPROGRESSCOMBINER_TEST_H 00127