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;
011:
012: import java.util.ArrayList;
013:
014: import junit.framework.Test;
015: import junit.framework.TestSuite;
016:
017: import org.eclipse.ui.IPerspectiveDescriptor;
018: import org.eclipse.ui.internal.Workbench;
019: import org.eclipse.ui.tests.harness.util.EmptyPerspective;
020: import org.eclipse.ui.tests.performance.layout.ComputeSizeTest;
021: import org.eclipse.ui.tests.performance.layout.LayoutTest;
022: import org.eclipse.ui.tests.performance.layout.PerspectiveWidgetFactory;
023: import org.eclipse.ui.tests.performance.layout.RecursiveTrimLayoutWidgetFactory;
024: import org.eclipse.ui.tests.performance.layout.ResizeTest;
025: import org.eclipse.ui.tests.performance.layout.TestWidgetFactory;
026:
027: /**
028: * @since 3.1
029: */
030: class WorkbenchPerformanceSuite extends TestSuite {
031:
032: private static String RESOURCE_PERSPID = "org.eclipse.ui.resourcePerspective";
033: // Note: to test perspective switching properly, we need perspectives with lots of
034: // associated actions.
035: // NOTE - do not change the order of the IDs below. the PerspectiveSwitchTest has a
036: // fingerprint test for performance that releys on this not changing.
037: public static final String[] PERSPECTIVE_IDS = {
038: EmptyPerspective.PERSP_ID2,
039: UIPerformanceTestSetup.PERSPECTIVE1, RESOURCE_PERSPID,
040: "org.eclipse.jdt.ui.JavaPerspective",
041: "org.eclipse.debug.ui.DebugPerspective" };
042:
043: // Perspective ID to use for the resize window fingerprint test
044: public static String resizeFingerprintTest = RESOURCE_PERSPID;
045:
046: public static final String[][] PERSPECTIVE_SWITCH_PAIRS = {
047: // Test switching between the two most commonly used perspectives in the SDK (this is the most important
048: // perspective switch test, but it is easily affected by changes in JDT, etc.)
049: { "org.eclipse.jdt.ui.JavaPerspective",
050: "org.eclipse.debug.ui.DebugPerspective", "1.java" },
051:
052: { UIPerformanceTestSetup.PERSPECTIVE1,
053: UIPerformanceTestSetup.PERSPECTIVE2, "1.perf_basic" },
054:
055: { "org.eclipse.ui.tests.dnd.dragdrop",
056: "org.eclipse.ui.tests.fastview_perspective",
057: "1.perf_basic" },
058:
059: // Test switching between a perspective with lots of actions and a perspective with none
060: { "org.eclipse.jdt.ui.JavaPerspective",
061: "org.eclipse.ui.tests.util.EmptyPerspective",
062: "1.perf_basic" },
063:
064: { RESOURCE_PERSPID, "org.eclipse.jdt.ui.JavaPerspective",
065: "1.java" } };
066:
067: public static final String[] VIEW_IDS = {
068: "org.eclipse.ui.views.ProblemView",
069: "org.eclipse.ui.views.ResourceNavigator" };
070: public static final int ITERATIONS = 25;
071:
072: /**
073: * Returns the suite. This is required to use the JUnit Launcher.
074: */
075: public static Test suite() {
076: return new WorkbenchPerformanceSuite();
077: }
078:
079: /**
080: *
081: */
082: public WorkbenchPerformanceSuite() {
083: addLayoutScenarios();
084: addResizeScenarios();
085: addPerspectiveSwitchScenarios();
086: addPerspectiveOpenCloseScenarios();
087: addWindowOpenCloseScenarios();
088: addContributionScenarios();
089: }
090:
091: /**
092: *
093: */
094: private void addContributionScenarios() {
095: addTest(new ObjectContributionsPerformance(
096: "large selection, limited contributors",
097: ObjectContributionsPerformance
098: .generateAdaptableSelection(
099: ObjectContributionsPerformance.SEED,
100: 5000), BasicPerformanceTest.NONE));
101: addTest(new ObjectContributionsPerformance(
102: "limited selection, limited contributors",
103: ObjectContributionsPerformance
104: .generateAdaptableSelection(
105: ObjectContributionsPerformance.SEED, 50),
106: BasicPerformanceTest.NONE));
107: }
108:
109: /**
110: *
111: */
112: private void addWindowOpenCloseScenarios() {
113: for (int i = 0; i < PERSPECTIVE_IDS.length; i++) {
114: addTest(new OpenCloseWindowTest(PERSPECTIVE_IDS[i],
115: BasicPerformanceTest.NONE));
116: }
117: }
118:
119: /**
120: *
121: *
122: */
123: private void addPerspectiveOpenCloseScenarios() {
124: for (int i = 0; i < PERSPECTIVE_IDS.length; i++) {
125: addTest(new OpenClosePerspectiveTest(PERSPECTIVE_IDS[i],
126: i == 1 ? BasicPerformanceTest.LOCAL
127: : BasicPerformanceTest.NONE));
128: }
129: }
130:
131: /**
132: *
133: */
134: private void addPerspectiveSwitchScenarios() {
135: for (int i = 0; i < PERSPECTIVE_SWITCH_PAIRS.length; i++) {
136: addTest(new PerspectiveSwitchTest(
137: PERSPECTIVE_SWITCH_PAIRS[i],
138: BasicPerformanceTest.NONE));
139: }
140: }
141:
142: /**
143: * Add performance tests for the layout of the given widget
144: *
145: * @param factory
146: * @since 3.1
147: */
148: private void addLayoutScenarios(TestWidgetFactory factory) {
149:
150: // Determine the effect of flushing the cache
151: addTest(new ComputeSizeTest(factory));
152:
153: // Test layout(false)
154: addTest(new LayoutTest(factory, false));
155:
156: // Test layout(true)
157: addTest(new LayoutTest(factory, true));
158:
159: // Test resizing
160: addTest(new ResizeTest(factory));
161: }
162:
163: private void addLayoutScenarios() {
164: addLayoutScenarios(new RecursiveTrimLayoutWidgetFactory());
165: }
166:
167: public static String[] getAllPerspectiveIds() {
168: ArrayList result = new ArrayList();
169: IPerspectiveDescriptor[] perspectives = Workbench.getInstance()
170: .getPerspectiveRegistry().getPerspectives();
171:
172: for (int i = 0; i < perspectives.length; i++) {
173: IPerspectiveDescriptor descriptor = perspectives[i];
174: String id = descriptor.getId();
175: result.add(id);
176: }
177:
178: return (String[]) result.toArray(new String[result.size()]);
179: }
180:
181: /**
182: *
183: */
184: private void addResizeScenarios() {
185: String[] perspectiveIds = getAllPerspectiveIds();
186: for (int i = 0; i < perspectiveIds.length; i++) {
187: String id = perspectiveIds[i];
188: addTest(new ResizeTest(
189: new PerspectiveWidgetFactory(id),
190: id.equals(resizeFingerprintTest) ? BasicPerformanceTest.LOCAL
191: : BasicPerformanceTest.NONE,
192: "UI - Workbench Window Resize"));
193: }
194: }
195: }
|