01: /*******************************************************************************
02: * Copyright (c) 2000, 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;
11:
12: import java.util.ArrayList;
13: import java.util.List;
14: import java.util.Random;
15:
16: import junit.framework.Test;
17: import junit.framework.TestSuite;
18:
19: import org.eclipse.jface.viewers.IStructuredSelection;
20: import org.eclipse.jface.viewers.StructuredSelection;
21: import org.eclipse.test.performance.Dimension;
22:
23: public class ObjectContributionsPerformance extends
24: BasicPerformanceTest {
25:
26: public static final int SEED = 1001001;
27: private IStructuredSelection selection;
28:
29: public static Test suite() {
30: TestSuite suite = new TestSuite(
31: "Object contribution performance");
32: suite.addTest(new ObjectContributionsPerformance(
33: "large selection, limited contributors",
34: generateAdaptableSelection(SEED, 5000),
35: BasicPerformanceTest.NONE));
36: suite.addTest(new ObjectContributionsPerformance(
37: "limited selection, limited contributors",
38: generateAdaptableSelection(SEED, 50),
39: BasicPerformanceTest.NONE));
40: return suite;
41: }
42:
43: public ObjectContributionsPerformance(String label,
44: IStructuredSelection selection, int tagging) {
45: super ("testObjectContributions:" + label, tagging);
46: this .selection = selection;
47: }
48:
49: protected void runTest() {
50: ObjectContributionTest tests = new ObjectContributionTest(
51: "testObjectContributions");
52: tagIfNecessary("UI - " + selection.size() + " contribution(s)",
53: Dimension.ELAPSED_PROCESS);
54: setDegradationComment("<a href=https://bugs.eclipse.org/bugs/show_bug.cgi?id=88274>See Bug 88274</a> ");
55: startMeasuring();
56: for (int i = 0; i < 5000; i++) {
57: tests.assertPopupMenus("1", new String[] { "bogus" },
58: selection, null, false);
59: }
60: stopMeasuring();
61: commitMeasurements();
62: assertPerformance();
63: }
64:
65: protected static IStructuredSelection generateAdaptableSelection(
66: int seed, int size) {
67: Random rand = new Random(seed);
68: List selection = new ArrayList();
69: for (int i = 0; i < size; i++) {
70: switch ((int) Math.round(rand.nextDouble() * 5)) {
71: case 0:
72: selection.add(new ObjectContributionClasses.A());
73: break;
74: case 1:
75: selection.add(new ObjectContributionClasses.B());
76: break;
77: case 2:
78: selection.add(new ObjectContributionClasses.C());
79: break;
80: case 3:
81: selection.add(new ObjectContributionClasses.Common());
82: break;
83: case 4:
84: selection.add(new ObjectContributionClasses.D());
85: break;
86: case 5:
87: selection.add(new ObjectContributionClasses.A1());
88: break;
89: default:
90: selection.add(new Object());
91: }
92: }
93: return new StructuredSelection(selection);
94: }
95: }
|