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 WPROGRESS_TEST_H 00026 #define WPROGRESS_TEST_H 00027 00028 #include <iostream> 00029 00030 #include <cxxtest/TestSuite.h> 00031 00032 #include "../WProgress.h" 00033 00034 /** 00035 * Test Class for the base progress class. 00036 */ 00037 class WProgressTest : public CxxTest::TestSuite 00038 { 00039 public: 00040 00041 /** 00042 * Test whether WProgress is instantiatable. 00043 */ 00044 void testInstantiation() 00045 { 00046 TS_ASSERT_THROWS_NOTHING( WProgress p( "Test", 1 ) ); 00047 } 00048 00049 /** 00050 * Test whether isDetermined returns the right value, depending on construction parameters of WProgress. 00051 */ 00052 void testDeterminedFlag() 00053 { 00054 WProgress p1( "Test1", 0 ); 00055 WProgress p2( "Test2", 1 ); 00056 00057 TS_ASSERT( !p1.isDetermined() ); 00058 TS_ASSERT( p2.isDetermined() ); 00059 } 00060 00061 /** 00062 * Test whether finish() sets pending to false. 00063 */ 00064 void testFinish() 00065 { 00066 // this instance should be pending 00067 WProgress p1( "Test1", 1 ); 00068 TS_ASSERT( p1.isPending() ); 00069 00070 // finishing it should set isPending to false 00071 p1.finish(); 00072 TS_ASSERT( !p1.isPending() ); 00073 } 00074 00075 /** 00076 * Test whether the state is updated properly. 00077 */ 00078 void testInternalState() 00079 { 00080 WProgress p( "Test", 11 ); 00081 00082 // update 00083 TS_ASSERT_THROWS_NOTHING( p.update() ); 00084 00085 // get progress 00086 TS_ASSERT( p.getProgress() == 0.0 ); 00087 00088 // increment it a bit 00089 ++++++++++p; 00090 TS_ASSERT_THROWS_NOTHING( p.update() ); 00091 TS_ASSERT( p.m_count == 5 ); 00092 TS_ASSERT( p.getProgress() == 50.0 ); 00093 ++++++++++p; 00094 TS_ASSERT_THROWS_NOTHING( p.update() ); 00095 TS_ASSERT( p.m_count == 10 ); 00096 TS_ASSERT( p.getProgress() == 100.0 ); 00097 00098 // does another step increase the count! It shouldn't 00099 ++p; 00100 TS_ASSERT_THROWS_NOTHING( p.update() ); 00101 TS_ASSERT( p.m_count == 10 ); 00102 TS_ASSERT( p.getProgress() == 100.0 ); 00103 00104 // reaching the max counter should not finish the progress. 00105 // update 00106 TS_ASSERT( p.isPending() ); 00107 } 00108 00109 /** 00110 * Test whether the state is updated properly if the instance is a indetermined one. 00111 */ 00112 void testInternalStateOfIndetermined() 00113 { 00114 WProgress p( "Test", 0 ); 00115 00116 // update 00117 TS_ASSERT_THROWS_NOTHING( p.update() ); 00118 00119 // get progress 00120 TS_ASSERT( p.getProgress() == 0.0 ); 00121 // increment it a bit 00122 ++++++++++p; 00123 TS_ASSERT_THROWS_NOTHING( p.update() ); 00124 TS_ASSERT( p.m_count == 0 ); 00125 TS_ASSERT( p.getProgress() == 0.0 ); 00126 } 00127 }; 00128 00129 #endif // WPROGRESS_TEST_H 00130