Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
View | Details | Raw Unified | Return to bug 252446
Collapse All | Expand All

(-)src/org/eclipse/core/tests/runtime/TestProgressMonitor.java (-1 / +5 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2006 IBM Corporation and others.
2
 * Copyright (c) 2006, 2008 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
Lines 254-259 Link Here
254
		totalWork += work;
254
		totalWork += work;
255
	}
255
	}
256
256
257
	public int getExpectedWork() {
258
		return expectedWork;
259
	}
260
257
	/**
261
	/**
258
	 * <p>Asserts that the progress reported on this monitor was optimal. That is,
262
	 * <p>Asserts that the progress reported on this monitor was optimal. That is,
259
	 * there were no redundant method calls, and progress was reported in between
263
	 * there were no redundant method calls, and progress was reported in between
(-)src/org/eclipse/core/tests/runtime/SubMonitorTest.java (-1 / +31 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2006, 2007 IBM Corporation and others.
2
 * Copyright (c) 2006, 2008 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
Lines 10-15 Link Here
10
 *     Stefan Xenos - bug 174539 - add a 1-argument convert(...) method     
10
 *     Stefan Xenos - bug 174539 - add a 1-argument convert(...) method     
11
 *     Stefan Xenos - bug 174040 - SubMonitor#convert doesn't always set task name
11
 *     Stefan Xenos - bug 174040 - SubMonitor#convert doesn't always set task name
12
 *     Stefan Xenos - bug 206942 - Regression test for infinite progress reporting rate
12
 *     Stefan Xenos - bug 206942 - Regression test for infinite progress reporting rate
13
 *     IBM Corporation - bug 252446 - SubMonitor.newChild passes zero ticks to child
13
 *******************************************************************************/
14
 *******************************************************************************/
14
package org.eclipse.core.tests.runtime;
15
package org.eclipse.core.tests.runtime;
15
16
Lines 793-798 Link Here
793
	}
794
	}
794
795
795
	/**
796
	/**
797
	 * Tests reporting of progress by sub-monitors created via newChild() 
798
	 */
799
	public void testBug252446() {
800
		int children = 12;
801
		int cyclesPerChild = 17;
802
803
		TestProgressMonitor monitor = new TestProgressMonitor();
804
		SubMonitor progress = SubMonitor.convert(monitor, children * cyclesPerChild);
805
806
		// At this time monitor.getExpectedWork() == SubMonitor.MINIMUM_RESOLUTION == 1000
807
		double expectedTicksPerIteration = (double) monitor.getExpectedWork() / children / cyclesPerChild;
808
809
		for (int i = 0; i < children; i++) {
810
			IProgressMonitor mon = progress.newChild(cyclesPerChild);
811
			for (int j = 1; j <= cyclesPerChild; j++) {
812
				mon.worked(1);
813
				double expectedTopMonitorWork = expectedTicksPerIteration * (i * cyclesPerChild + j);
814
				// Progress is passed to the parent monitor as integer leading to rounding 
815
				// errors. The parent's progress has to follow child's progress "close enough"
816
				// and then it will catch up when next child is created. Hence, a relatively large delta 
817
				// value in this check:
818
				assertEquals(expectedTopMonitorWork, monitor.getTotalWork(), 2.0d);
819
			}
820
		}
821
		monitor.done();
822
		monitor.assertOptimal();
823
	}
824
825
	/**
796
	 * Creates and destroys the given number of child progress monitors under the given parent.
826
	 * Creates and destroys the given number of child progress monitors under the given parent.
797
	 * 
827
	 * 
798
	 * @param monitor monitor to create children under. The caller must call done on this monitor
828
	 * @param monitor monitor to create children under. The caller must call done on this monitor
(-)src/org/eclipse/core/runtime/SubMonitor.java (-2 / +3 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2006, 2007 IBM Corporation and others.
2
 * Copyright (c) 2006, 2008 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
Lines 10-15 Link Here
10
 *     Stefan Xenos - bug 174539 - add a 1-argument convert(...) method     
10
 *     Stefan Xenos - bug 174539 - add a 1-argument convert(...) method     
11
 *     Stefan Xenos - bug 174040 - SubMonitor#convert doesn't always set task name
11
 *     Stefan Xenos - bug 174040 - SubMonitor#convert doesn't always set task name
12
 *     Stefan Xenos - bug 206942 - updated javadoc to recommend better constants for infinite progress
12
 *     Stefan Xenos - bug 206942 - updated javadoc to recommend better constants for infinite progress
13
 *     IBM Corporation - bug 252446 - SubMonitor.newChild passes zero ticks to child
13
 *******************************************************************************/
14
 *******************************************************************************/
14
package org.eclipse.core.runtime;
15
package org.eclipse.core.runtime;
15
16
Lines 743-749 Link Here
743
		// is no method on the child that would delegate to beginTask on the parent.
744
		// is no method on the child that would delegate to beginTask on the parent.
744
		childFlags |= suppressFlags;
745
		childFlags |= suppressFlags;
745
746
746
		SubMonitor result = new SubMonitor(root, consume(totalWorkDouble), 0, childFlags);
747
		SubMonitor result = new SubMonitor(root, consume(totalWorkDouble), (int) totalWorkDouble, childFlags);
747
		lastSubMonitor = result;
748
		lastSubMonitor = result;
748
		return result;
749
		return result;
749
	}
750
	}

Return to bug 252446