OpenWalnut  1.4.0
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  * Test whether WProgress is instantiatable.
42  */
44  {
45  TS_ASSERT_THROWS_NOTHING( WProgress p( "Test", 1 ) );
46  }
47 
48  /**
49  * Test whether isDetermined returns the right value, depending on construction parameters of WProgress.
50  */
52  {
53  WProgress p1( "Test1", 0 );
54  WProgress p2( "Test2", 1 );
55 
56  TS_ASSERT( !p1.isDetermined() );
57  TS_ASSERT( p2.isDetermined() );
58  }
59 
60  /**
61  * Test whether finish() sets pending to false.
62  */
63  void testFinish()
64  {
65  // this instance should be pending
66  WProgress p1( "Test1", 1 );
67  TS_ASSERT( p1.isPending() );
68 
69  // finishing it should set isPending to false
70  p1.finish();
71  TS_ASSERT( !p1.isPending() );
72  }
73 
74  /**
75  * Test whether the state is updated properly.
76  */
78  {
79  WProgress p( "Test", 11 );
80 
81  // update
82  TS_ASSERT_THROWS_NOTHING( p.update() );
83 
84  // get progress
85  TS_ASSERT( p.getProgress() == 0.0 );
86 
87  // increment it a bit
88  ++++++++++p;
89  TS_ASSERT_THROWS_NOTHING( p.update() );
90  TS_ASSERT( p.m_count == 5 );
91  TS_ASSERT( p.getProgress() == 50.0 );
92  ++++++++++p;
93  TS_ASSERT_THROWS_NOTHING( p.update() );
94  TS_ASSERT( p.m_count == 10 );
95  TS_ASSERT( p.getProgress() == 100.0 );
96 
97  // does another step increase the count! It shouldn't
98  ++p;
99  TS_ASSERT_THROWS_NOTHING( p.update() );
100  TS_ASSERT( p.m_count == 10 );
101  TS_ASSERT( p.getProgress() == 100.0 );
102 
103  // reaching the max counter should not finish the progress.
104  // update
105  TS_ASSERT( p.isPending() );
106  }
107 
108  /**
109  * Test whether the state is updated properly if the instance is a indetermined one.
110  */
112  {
113  WProgress p( "Test", 0 );
114 
115  // update
116  TS_ASSERT_THROWS_NOTHING( p.update() );
117 
118  // get progress
119  TS_ASSERT( p.getProgress() == 0.0 );
120  // increment it a bit
121  ++++++++++p;
122  TS_ASSERT_THROWS_NOTHING( p.update() );
123  TS_ASSERT( p.m_count == 0 );
124  TS_ASSERT( p.getProgress() == 0.0 );
125  }
126 };
127 
128 #endif // WPROGRESS_TEST_H
129 
Class managing progress inside of modules.
Definition: WProgress.h:41
virtual float getProgress()
Returns the overall progress of this progress instance, including the child progress'.
Definition: WProgress.cpp:68
void testFinish()
Test whether finish() sets pending to false.
void testInternalStateOfIndetermined()
Test whether the state is updated properly if the instance is a indetermined one. ...
void testInternalState()
Test whether the state is updated properly.
Test Class for the base progress class.
virtual void update()
Function updating the internal state.
Definition: WProgress.cpp:52
void testDeterminedFlag()
Test whether isDetermined returns the right value, depending on construction parameters of WProgress...
virtual bool isDetermined()
Returns true whenever the progress has a known end.
Definition: WProgress.cpp:83
virtual void finish()
Stops the progress.
Definition: WProgress.cpp:57
virtual bool isPending()
Returns true when the operation is pending.
Definition: WProgress.cpp:73
void testInstantiation()
Test whether WProgress is instantiatable.