/** Test SubProgressMonitor's created with negative a work value. */ public void testNegativeWorkValues() { TestProgressMonitor top = new TestProgressMonitor(); top.beginTask("", 10); SubProgressMonitor childMonitor = new SubProgressMonitor(top, IProgressMonitor.UNKNOWN); // -1 childMonitor.beginTask("", 10); childMonitor.worked(5); Assert.assertEquals(0.0, top.getTotalWork(), 0.01d); childMonitor.done(); Assert.assertEquals(0.0, top.getTotalWork(), 0.01d); top.done(); }
/** * Tests the automatic cleanup when progress monitors are created via their constructor * * @deprecated to suppress deprecation warnings */ public void testParallelChildren() { TestProgressMonitor top = new TestProgressMonitor(); top.beginTask("", 1000); SubProgressMonitor mon = new SubProgressMonitor(top, 1000); mon.beginTask("", 1000); SubProgressMonitor monitor1 = new SubProgressMonitor(mon, 200); SubProgressMonitor monitor2 = new SubProgressMonitor(mon, 200); Assert.assertEquals("Ensure no work has been reported yet", 0.0, top.getTotalWork(), 0.01d); monitor1.beginTask("", 1000); Assert.assertEquals("Ensure no work has been reported yet", 0.0, top.getTotalWork(), 0.01d); monitor2.beginTask("", 1000); Assert.assertEquals("Should not have cleaned up monitor 1", 0.0, top.getTotalWork(), 0.01d); monitor1.done(); Assert.assertEquals("Should have cleaned up monitor 1", 200.0, top.getTotalWork(), 0.01d); monitor1.worked(1000); Assert.assertEquals( "Monitor1 shouldn't report work once it's complete", 200.0, top.getTotalWork(), 0.01d); monitor2.worked(500); Assert.assertEquals(300.0, top.getTotalWork(), 0.01d); // Create a monitor that will leak - monitors won't be auto-completed until their done methods // are // called SubProgressMonitor monitor3 = new SubProgressMonitor(mon, 300); Assert.assertEquals( "Monitor2 should not have been cleaned up yet", 300.0, top.getTotalWork(), 0.01d); SubProgressMonitor monitor4 = new SubProgressMonitor(mon, 300); monitor4.beginTask("", 100); mon.done(); Assert.assertNotNull(monitor3); Assert.assertEquals( "All leaked work should have been collected", 1000.0, top.getTotalWork(), 0.01d); }
/** * Tests SubProgressMonitor nesting when using the default constructor. (Tests parents in floating * point mode) * * @deprecated to suppress deprecation warnings */ public void testConstructorNestingFP() { TestProgressMonitor top = new TestProgressMonitor(); top.beginTask("", 2000); // Create an SPM, put it in floating-point mode, and consume half its work SubProgressMonitor fpMonitor = new SubProgressMonitor(top, 1000); fpMonitor.beginTask("", 100); fpMonitor.internalWorked(50.0); fpMonitor.internalWorked(-10.0); // should have no effect Assert.assertEquals(500.0, top.getTotalWork(), 0.01d); // Create a child monitor, and ensure that it grabs the correct amount of work // from the parent. SubProgressMonitor childMonitor = new SubProgressMonitor(fpMonitor, 20); childMonitor.beginTask("", 100); childMonitor.worked(100); childMonitor.done(); Assert.assertEquals(700.0, top.getTotalWork(), 0.01d); // Create a child monitor, and ensure that it grabs the correct amount of work // from the parent. SubProgressMonitor childMonitor2 = new SubProgressMonitor(fpMonitor, 30); childMonitor2.beginTask("", 100); childMonitor2.worked(100); childMonitor2.done(); Assert.assertEquals(1000.0, top.getTotalWork(), 0.01d); // Ensure that creating another child will have no effect SubProgressMonitor childMonitor3 = new SubProgressMonitor(fpMonitor, 10); childMonitor3.beginTask("", 100); childMonitor3.worked(100); childMonitor3.done(); Assert.assertEquals(1000.0, top.getTotalWork(), 0.01d); fpMonitor.worked(100); Assert.assertEquals(1000.0, top.getTotalWork(), 0.01d); fpMonitor.done(); Assert.assertEquals(1000.0, top.getTotalWork(), 0.01d); }