001: /*******************************************************************************
002: * Copyright (c) 2004, 2006 IBM Corporation and others.
003: * All rights reserved. This program and the accompanying materials
004: * are made available under the terms of the Eclipse Public License v1.0
005: * which accompanies this distribution, and is available at
006: * http://www.eclipse.org/legal/epl-v10.html
007: *
008: * Contributors:
009: * IBM Corporation - initial API and implementation
010: *******************************************************************************/package org.eclipse.ui.tests.performance.layout;
011:
012: import org.eclipse.core.runtime.CoreException;
013: import org.eclipse.swt.graphics.Point;
014: import org.eclipse.swt.graphics.Rectangle;
015: import org.eclipse.swt.widgets.Composite;
016: import org.eclipse.test.performance.Dimension;
017: import org.eclipse.ui.WorkbenchException;
018: import org.eclipse.ui.tests.performance.BasicPerformanceTest;
019:
020: /**
021: * Measures the time to resize the widget 10 times, including the time required
022: * to redraw.
023: *
024: * @since 3.1
025: */
026: public class ResizeTest extends BasicPerformanceTest {
027:
028: private TestWidgetFactory widgetFactory;
029:
030: private int xIterations = 5;
031:
032: private int yIterations = 5;
033:
034: private String tagString;
035:
036: /**
037: * Create a new instance of the receiver.
038: * @param factory
039: */
040: public ResizeTest(TestWidgetFactory factory) {
041: this (factory, NONE, factory.getName() + " setSize");
042: }
043:
044: /**
045: * Create a new instance of the receiver.
046: * @param factory
047: * @param tagging
048: * @param tag
049: */
050: public ResizeTest(TestWidgetFactory factory, int tagging, String tag) {
051: super (factory.getName() + " setSize", tagging);
052: this .tagString = tag;
053: this .widgetFactory = factory;
054: }
055:
056: /**
057: * Run the test
058: */
059: protected void runTest() throws CoreException, WorkbenchException {
060:
061: tagIfNecessary(tagString, Dimension.ELAPSED_PROCESS);
062:
063: widgetFactory.init();
064: final Composite widget = widgetFactory.getControl();
065: Rectangle initialBounds = widget.getBounds();
066: final Point maxSize = widgetFactory.getMaxSize();
067:
068: waitForBackgroundJobs();
069: processEvents();
070: for (int j = 0; j < 50; j++) {
071:
072: startMeasuring();
073: for (int i = 0; i < 2; i++) {
074:
075: for (int xIteration = 0; xIteration < xIterations; xIteration += 5) {
076:
077: for (int yIteration = 0; yIteration < yIterations; yIteration++) {
078: // Avoid giving the same x value twice in a row in order
079: // to make it hard to cache
080: int xSize = maxSize.x
081: * ((xIteration + yIteration) % xIterations)
082: / xIterations;
083: int ySize = maxSize.y * yIteration
084: / yIterations;
085:
086: widget.setSize(xSize, ySize);
087:
088: processEvents();
089: }
090:
091: }
092:
093: }
094: stopMeasuring();
095: }
096: commitMeasurements();
097: assertPerformance();
098:
099: widget.setBounds(initialBounds);
100: widgetFactory.done();
101: }
102:
103: }
|