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