OpenWalnut  1.4.0
WProgressCombiner_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 WPROGRESSCOMBINER_TEST_H
26 #define WPROGRESSCOMBINER_TEST_H
27 
28 #include <iostream>
29 
30 #ifndef Q_MOC_RUN
31 #include <boost/shared_ptr.hpp>
32 #endif
33 
34 #include <cxxtest/TestSuite.h>
35 
36 #include "../WProgress.h"
37 #include "../WProgressCombiner.h"
38 
39 /**
40  * Class testing the functionality of progress combiners.
41  */
42 class WProgressCombinerTest : public CxxTest::TestSuite
43 {
44 public:
45  /**
46  * Test whether WProgress is instantiatable.
47  */
49  {
50  TS_ASSERT_THROWS_NOTHING( WProgressCombiner p( "Test" ) );
51  }
52 
53  /**
54  * Test whether the combiner ignores manual increments.
55  */
57  {
58  WProgressCombiner p( "Test" );
59 
60  // try increment
61  ++++++p;
62  TS_ASSERT_THROWS_NOTHING( p.update() );
63  TS_ASSERT( p.getProgress() == 0.0 );
64 
65  // should ignore finish()
66  p.finish();
67  TS_ASSERT_THROWS_NOTHING( p.update() );
68  TS_ASSERT( !p.isPending() );
69  }
70 
71  /**
72  * Test the combiner when some childs got added to it.
73  */
75  {
76  WProgressCombiner p( "Test" );
77 
78  // create some children
79  boost::shared_ptr< WProgress> p1( new WProgress( "TestP1", 11 ) );
80  boost::shared_ptr< WProgress> p2( new WProgress( "TestP2", 11 ) );
81  boost::shared_ptr< WProgress> p3( new WProgress( "TestP3" ) );
82 
83  // as the first and only child is determined (has a known end point) -> the combiner is determined
84  TS_ASSERT_THROWS_NOTHING( p.addSubProgress( p1 ) );
85  p.update();
86  TS_ASSERT( p.isDetermined() );
87 
88  // increment a bit
89  ++++++++++( *p1 );
90  p.update(); // updating is needed in every case, as this is used to propagate changes.
91  // p1 is now at 50% -> the combiner should also be at 50%
92  TS_ASSERT( p1->getProgress() == 50.0 );
93  TS_ASSERT( p.getProgress() == 50.0 );
94 
95  // add another determined progress
96  TS_ASSERT_THROWS_NOTHING( p.addSubProgress( p2 ) );
97  p.update();
98  TS_ASSERT( p.isDetermined() );
99  TS_ASSERT( p.getProgress() == 25.0 ); // as p2 is at 0% currently
100 
101  // now add an indetermined progress
102  TS_ASSERT_THROWS_NOTHING( p.addSubProgress( p3 ) );
103  p.update();
104  TS_ASSERT( !p3->isDetermined() );
105  TS_ASSERT( !p.isDetermined() );
106 
107  // now finish the progress and test whether to combiner reacts on it.
108 
109  // when finishing the indetermined progress the combiner is determined again.
110  p3->finish();
111  p.update();
112  TS_ASSERT( p.isDetermined() );
113  TS_ASSERT( p.isPending() );
114 
115  // finish the other progress
116  p1->finish();
117  p2->finish();
118  p.update();
119  TS_ASSERT( !p.isPending() );
120 
121  // finish the combiner
122  p.finish();
123  TS_ASSERT( p.m_children.empty() );
124  }
125 };
126 
127 #endif // WPROGRESSCOMBINER_TEST_H
128 
virtual float getProgress()
Returns the overall progress of this progress instance, including the child progress'.
Class managing progress inside of modules.
Definition: WProgress.h:43
virtual void addSubProgress(boost::shared_ptr< WProgress > progress)
Adds a new progress to this combiner.
Base class for all kinds of progress combinations.
std::set< boost::shared_ptr< WProgress > > m_children
Set of all child progress.
virtual void finish()
Stops the progress.
virtual bool isDetermined()
Returns true whenever the progress has a known end.
Definition: WProgress.cpp:83
void testWithChilds()
Test the combiner when some childs got added to it.
virtual bool isPending()
Returns true when the operation is pending.
Definition: WProgress.cpp:73
void testInstantiation()
Test whether WProgress is instantiatable.
void testInternalStateIgnoresIncrementAndFinish()
Test whether the combiner ignores manual increments.
virtual void update()
Function updating the internal state.
Class testing the functionality of progress combiners.