01: /*******************************************************************************
02: * Copyright (c) 2004, 2006 IBM Corporation and others.
03: * All rights reserved. This program and the accompanying materials
04: * are made available under the terms of the Eclipse Public License v1.0
05: * which accompanies this distribution, and is available at
06: * http://www.eclipse.org/legal/epl-v10.html
07: *
08: * Contributors:
09: * IBM Corporation - initial API and implementation
10: *******************************************************************************/package org.eclipse.ui.tests.performance.layout;
11:
12: import org.eclipse.core.runtime.CoreException;
13: import org.eclipse.jface.util.Geometry;
14: import org.eclipse.swt.graphics.Point;
15: import org.eclipse.swt.graphics.Rectangle;
16: import org.eclipse.swt.widgets.Composite;
17: import org.eclipse.ui.WorkbenchException;
18: import org.eclipse.ui.tests.performance.BasicPerformanceTest;
19:
20: /**
21: * Measures the time required to layout the widget 10 times. Does not include
22: * the time required for any deferred repaints.
23: *
24: * @since 3.1
25: */
26: public class LayoutTest extends BasicPerformanceTest {
27:
28: private TestWidgetFactory widgetFactory;
29:
30: private int xIterations = 100;
31:
32: private int yIterations = 10;
33:
34: private boolean flushState;
35:
36: /**
37: * @param testName
38: */
39: public LayoutTest(TestWidgetFactory widgetFactory,
40: boolean flushState) {
41: super (widgetFactory.getName() + " layout("
42: + (flushState ? "true" : "false") + ")");
43:
44: this .widgetFactory = widgetFactory;
45: this .flushState = flushState;
46: }
47:
48: /**
49: * Run the test
50: */
51: protected void runTest() throws CoreException, WorkbenchException {
52:
53: widgetFactory.init();
54: final Composite widget = widgetFactory.getControl();
55: final Point maxSize = widgetFactory.getMaxSize();
56: Rectangle initialBounds = widget.getBounds();
57: final Rectangle newBounds = Geometry.copy(initialBounds);
58:
59: // This test is different now duw to trim API changes so 'gray' it...
60: setDegradationComment("<a href=https://bugs.eclipse.org/bugs/show_bug.cgi?id=129001>See Bug 129001</a> ");
61:
62: for (int xIteration = 0; xIteration < xIterations; xIteration++) {
63:
64: processEvents();
65:
66: startMeasuring();
67:
68: for (int yIteration = 0; yIteration < yIterations; yIteration++) {
69: // Avoid giving the same x value twice in a row in order to make
70: // it hard to cache
71: int xSize = maxSize.x
72: * ((xIteration + yIteration) % xIterations)
73: / xIterations;
74: int ySize = maxSize.y * yIteration / yIterations;
75:
76: newBounds.width = xSize;
77: newBounds.height = ySize;
78:
79: widget.setBounds(newBounds);
80: widget.layout(flushState);
81: }
82:
83: stopMeasuring();
84: }
85:
86: commitMeasurements();
87: assertPerformance();
88:
89: widget.setBounds(initialBounds);
90: widgetFactory.done();
91: }
92: }
|