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