001: /*******************************************************************************
002: * Copyright (c) 2005, 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.jface.tests.performance;
011:
012: import org.eclipse.core.runtime.CoreException;
013: import org.eclipse.swt.SWT;
014: import org.eclipse.swt.layout.FillLayout;
015: import org.eclipse.swt.widgets.Display;
016: import org.eclipse.swt.widgets.Shell;
017: import org.eclipse.swt.widgets.Tree;
018: import org.eclipse.swt.widgets.TreeItem;
019: import org.eclipse.ui.tests.performance.BasicPerformanceTest;
020: import org.eclipse.ui.tests.performance.TestRunnable;
021:
022: public class SWTTreeTest extends BasicPerformanceTest {
023:
024: Shell browserShell;
025:
026: Tree tree;
027:
028: public SWTTreeTest(String testName, int tagging) {
029: super (testName, tagging);
030: }
031:
032: public SWTTreeTest(String testName) {
033: super (testName);
034: }
035:
036: protected void openBrowser() {
037: Display display = Display.getCurrent();
038: if (display == null) {
039: display = new Display();
040: }
041: browserShell = new Shell(display);
042: browserShell.setSize(500, 500);
043: browserShell.setLayout(new FillLayout());
044: tree = new Tree(browserShell, SWT.NONE);
045: createChildren();
046: browserShell.open();
047: // processEvents();
048: }
049:
050: private void createChildren() {
051: for (int i = 0; i < TreeTest.TEST_COUNT; i++) {
052: TreeItem item = new TreeItem(tree, SWT.NONE);
053: item.setText("Element " + String.valueOf(i));
054:
055: }
056:
057: }
058:
059: /**
060: * Test the getItems API.
061: *
062: */
063: public void testGetItems() throws CoreException {
064: openBrowser();
065:
066: exercise(new TestRunnable() {
067: public void run() throws Exception {
068: processEvents();
069: startMeasuring();
070: for (int j = 0; j < TreeTest.TEST_COUNT; j++) {
071: tree.getItems();
072: processEvents();
073: }
074: stopMeasuring();
075: }
076: });
077:
078: commitMeasurements();
079: assertPerformance();
080: browserShell.close();
081: }
082:
083: /**
084: * @throws CoreException
085: * Test the getItem API.
086: *
087: */
088: public void testGetItemAt() throws CoreException {
089: openBrowser();
090:
091: exercise(new TestRunnable() {
092: public void run() throws Exception {
093: processEvents();
094: startMeasuring();
095: for (int j = 0; j < TreeTest.TEST_COUNT; j++) {
096: tree.getItem(j);
097: processEvents();
098: }
099: stopMeasuring();
100: }
101: });
102:
103: commitMeasurements();
104: assertPerformance();
105: browserShell.close();
106: }
107:
108: }
|