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.rcp.performance;
11:
12: import org.eclipse.swt.widgets.Display;
13: import org.eclipse.test.performance.Dimension;
14: import org.eclipse.test.performance.Performance;
15: import org.eclipse.test.performance.PerformanceTestCase;
16: import org.eclipse.ui.PlatformUI;
17: import org.eclipse.ui.application.WorkbenchAdvisor;
18: import org.eclipse.ui.tests.rcp.util.IPerformanceMeterArray;
19: import org.eclipse.ui.tests.rcp.util.IntervalMeters;
20: import org.eclipse.ui.tests.rcp.util.RestoreWorkbenchIntervalMonitor;
21: import org.eclipse.ui.tests.rcp.util.OpenWorkbenchIntervalMonitor;
22:
23: /**
24: * @since 3.1
25: */
26: public class EmptyWorkbenchPerfTest extends PerformanceTestCase {
27:
28: private static final int REPEAT_COUNT = 10;
29:
30: public void testOpen() {
31: Display display = PlatformUI.createDisplay();
32:
33: Performance perf = Performance.getDefault();
34:
35: String baseScenarioId = perf.getDefaultScenarioId(this );
36: IPerformanceMeterArray meters = new IntervalMeters(perf,
37: baseScenarioId,
38: OpenWorkbenchIntervalMonitor.intervalNames);
39: tagAsSummary("Open RCP App", Dimension.CPU_TIME);
40: for (int i = 0; i < REPEAT_COUNT; ++i) {
41: meters.start(OpenWorkbenchIntervalMonitor.firstInterval);
42: int code = PlatformUI.createAndRunWorkbench(display,
43: new OpenWorkbenchIntervalMonitor(meters));
44: meters.stop(OpenWorkbenchIntervalMonitor.finalInterval);
45:
46: assertEquals(PlatformUI.RETURN_OK, code);
47: }
48:
49: display.dispose();
50: assertTrue(display.isDisposed());
51:
52: meters.commit();
53: meters.assertPerformance();
54: meters.dispose();
55: }
56:
57: public void testRestore() {
58: Display display = PlatformUI.createDisplay();
59:
60: // create an advisor that will just start the workbench long enough to create
61: // something to be restored later
62: WorkbenchAdvisor wa = new RestoreWorkbenchIntervalMonitor();
63:
64: int code = PlatformUI.createAndRunWorkbench(display, wa);
65: assertEquals(PlatformUI.RETURN_RESTART, code);
66: assertFalse(display.isDisposed());
67:
68: // the rest is a bunch of code to restore the workbench and monitor performance
69: // while doing so
70:
71: Performance perf = Performance.getDefault();
72:
73: String baseScenarioId = perf.getDefaultScenarioId(this );
74: IPerformanceMeterArray meters = new IntervalMeters(perf,
75: baseScenarioId,
76: RestoreWorkbenchIntervalMonitor.intervalNames);
77:
78: tagAsSummary("Restore RCP App", Dimension.CPU_TIME);
79:
80: for (int i = 0; i < REPEAT_COUNT; ++i) {
81: meters.start(RestoreWorkbenchIntervalMonitor.firstInterval);
82: code = PlatformUI.createAndRunWorkbench(display,
83: new RestoreWorkbenchIntervalMonitor(meters));
84: meters.stop(RestoreWorkbenchIntervalMonitor.finalInterval);
85:
86: assertEquals(PlatformUI.RETURN_OK, code);
87: }
88:
89: meters.commit();
90: meters.assertPerformance();
91: meters.dispose();
92:
93: display.dispose();
94: assertTrue(display.isDisposed());
95: }
96: }
|