OpenWalnut  1.2.5
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
WProgress_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 WPROGRESS_TEST_H
26 #define WPROGRESS_TEST_H
27 
28 #include <iostream>
29 
30 #include <cxxtest/TestSuite.h>
31 
32 #include "../WProgress.h"
33 
34 /**
35  * Test Class for the base progress class.
36  */
37 class WProgressTest : public CxxTest::TestSuite
38 {
39 public:
40 
41  /**
42  * Test whether WProgress is instantiatable.
43  */
45  {
46  TS_ASSERT_THROWS_NOTHING( WProgress p( "Test", 1 ) );
47  }
48 
49  /**
50  * Test whether isDetermined returns the right value, depending on construction parameters of WProgress.
51  */
53  {
54  WProgress p1( "Test1", 0 );
55  WProgress p2( "Test2", 1 );
56 
57  TS_ASSERT( !p1.isDetermined() );
58  TS_ASSERT( p2.isDetermined() );
59  }
60 
61  /**
62  * Test whether finish() sets pending to false.
63  */
64  void testFinish()
65  {
66  // this instance should be pending
67  WProgress p1( "Test1", 1 );
68  TS_ASSERT( p1.isPending() );
69 
70  // finishing it should set isPending to false
71  p1.finish();
72  TS_ASSERT( !p1.isPending() );
73  }
74 
75  /**
76  * Test whether the state is updated properly.
77  */
79  {
80  WProgress p( "Test", 11 );
81 
82  // update
83  TS_ASSERT_THROWS_NOTHING( p.update() );
84 
85  // get progress
86  TS_ASSERT( p.getProgress() == 0.0 );
87 
88  // increment it a bit
89  ++++++++++p;
90  TS_ASSERT_THROWS_NOTHING( p.update() );
91  TS_ASSERT( p.m_count == 5 );
92  TS_ASSERT( p.getProgress() == 50.0 );
93  ++++++++++p;
94  TS_ASSERT_THROWS_NOTHING( p.update() );
95  TS_ASSERT( p.m_count == 10 );
96  TS_ASSERT( p.getProgress() == 100.0 );
97 
98  // does another step increase the count! It shouldn't
99  ++p;
100  TS_ASSERT_THROWS_NOTHING( p.update() );
101  TS_ASSERT( p.m_count == 10 );
102  TS_ASSERT( p.getProgress() == 100.0 );
103 
104  // reaching the max counter should not finish the progress.
105  // update
106  TS_ASSERT( p.isPending() );
107  }
108 
109  /**
110  * Test whether the state is updated properly if the instance is a indetermined one.
111  */
113  {
114  WProgress p( "Test", 0 );
115 
116  // update
117  TS_ASSERT_THROWS_NOTHING( p.update() );
118 
119  // get progress
120  TS_ASSERT( p.getProgress() == 0.0 );
121  // increment it a bit
122  ++++++++++p;
123  TS_ASSERT_THROWS_NOTHING( p.update() );
124  TS_ASSERT( p.m_count == 0 );
125  TS_ASSERT( p.getProgress() == 0.0 );
126  }
127 };
128 
129 #endif // WPROGRESS_TEST_H
130