00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 #ifndef WPROGRESSCOMBINER_TEST_H
00026 #define WPROGRESSCOMBINER_TEST_H
00027
00028 #include <iostream>
00029
00030 #include <boost/shared_ptr.hpp>
00031
00032 #include <cxxtest/TestSuite.h>
00033
00034 #include "../WProgress.h"
00035 #include "../WProgressCombiner.h"
00036
00037
00038
00039
00040 class WProgressCombinerTest : public CxxTest::TestSuite
00041 {
00042 public:
00043
00044
00045
00046
00047 void testInstantiation()
00048 {
00049 TS_ASSERT_THROWS_NOTHING( WProgressCombiner p( "Test" ) );
00050 }
00051
00052
00053
00054
00055 void testInternalStateIgnoresIncrementAndFinish()
00056 {
00057 WProgressCombiner p( "Test" );
00058
00059
00060 ++++++p;
00061 TS_ASSERT_THROWS_NOTHING( p.update() );
00062 TS_ASSERT( p.getProgress() == 0.0 );
00063
00064
00065 p.finish();
00066 TS_ASSERT_THROWS_NOTHING( p.update() );
00067 TS_ASSERT( !p.isPending() );
00068 }
00069
00070
00071
00072
00073 void testWithChilds()
00074 {
00075 WProgressCombiner p( "Test" );
00076
00077
00078 boost::shared_ptr< WProgress> p1 = boost::shared_ptr< WProgress>( new WProgress( "TestP1", 11 ) );
00079 boost::shared_ptr< WProgress> p2 = boost::shared_ptr< WProgress>( new WProgress( "TestP2", 11 ) );
00080 boost::shared_ptr< WProgress> p3 = boost::shared_ptr< WProgress>( new WProgress( "TestP3" ) );
00081
00082
00083 TS_ASSERT_THROWS_NOTHING( p.addSubProgress( p1 ) );
00084 p.update();
00085 TS_ASSERT( p.isDetermined() );
00086
00087
00088 ++++++++++( *p1 );
00089 p.update();
00090
00091 TS_ASSERT( p1->getProgress() == 50.0 );
00092 TS_ASSERT( p.getProgress() == 50.0 );
00093
00094
00095 TS_ASSERT_THROWS_NOTHING( p.addSubProgress( p2 ) );
00096 p.update();
00097 TS_ASSERT( p.isDetermined() );
00098 TS_ASSERT( p.getProgress() == 25.0 );
00099
00100
00101 TS_ASSERT_THROWS_NOTHING( p.addSubProgress( p3 ) );
00102 p.update();
00103 TS_ASSERT( !p3->isDetermined() );
00104 TS_ASSERT( !p.isDetermined() );
00105
00106
00107
00108
00109 p3->finish();
00110 p.update();
00111 TS_ASSERT( p.isDetermined() );
00112 TS_ASSERT( p.isPending() );
00113
00114
00115 p1->finish();
00116 p2->finish();
00117 p.update();
00118 TS_ASSERT( !p.isPending() );
00119
00120
00121 p.finish();
00122 TS_ASSERT( p.m_children.empty() );
00123 }
00124 };
00125
00126 #endif // WPROGRESSCOMBINER_TEST_H
00127