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.jface.viewers.ILabelProvider;
013: import org.eclipse.jface.viewers.LabelProvider;
014: import org.eclipse.jface.viewers.StructuredViewer;
015: import org.eclipse.swt.SWT;
016: import org.eclipse.swt.layout.FillLayout;
017: import org.eclipse.swt.widgets.Display;
018: import org.eclipse.swt.widgets.Shell;
019: import org.eclipse.ui.tests.performance.BasicPerformanceTest;
020:
021: /**
022: * The LinearViewerTest is a test that tests viewers.
023: *
024: */
025: public abstract class ViewerTest extends BasicPerformanceTest {
026:
027: Shell browserShell;
028:
029: public static int ITERATIONS = 100;
030: public static int MIN_ITERATIONS = 20;
031:
032: public ViewerTest(String testName, int tagging) {
033: super (testName, tagging);
034: }
035:
036: public ViewerTest(String testName) {
037: super (testName);
038: }
039:
040: protected void openBrowser() {
041: Display display = Display.getCurrent();
042: if (display == null) {
043: display = new Display();
044: }
045: browserShell = new Shell(display);
046: browserShell.setSize(500, 500);
047: browserShell.setLayout(new FillLayout());
048: StructuredViewer viewer = createViewer(browserShell);
049: viewer.setUseHashlookup(true);
050: viewer.setInput(getInitialInput());
051: browserShell.open();
052: // processEvents();
053: }
054:
055: /**
056: * Get the initial input for the receiver.
057: * @return
058: */
059: protected Object getInitialInput() {
060: return this ;
061: }
062:
063: /**
064: * Create the viewer we are testing.
065: * @param aShell
066: * @return
067: */
068: protected abstract StructuredViewer createViewer(Shell shell);
069:
070: public ILabelProvider getLabelProvider() {
071: return new LabelProvider() {
072: /*
073: * (non-Javadoc)
074: *
075: * @see org.eclipse.jface.viewers.ILabelProvider#getText(java.lang.Object)
076: */
077: public String getText(Object element) {
078: return ((TestElement) element).getText();
079: }
080:
081: };
082: }
083:
084: /* (non-Javadoc)
085: * @see org.eclipse.ui.tests.util.UITestCase#doTearDown()
086: */
087: protected void doTearDown() throws Exception {
088: super .doTearDown();
089: if (browserShell != null) {
090: browserShell.close();
091: browserShell = null;
092: }
093: }
094:
095: /**
096: * Return the number of iterations for tests that are slow on Linux
097: * @return int
098: */
099: public int slowGTKIterations() {
100: if (SWT.getPlatform().equals("gtk"))
101: return ITERATIONS / 5;
102: return ITERATIONS;
103: }
104:
105: /**
106: * Return the number of iterations for tests that are slow on Linux
107: * @return int
108: */
109: public int slowWindowsIterations() {
110: if (SWT.getPlatform().equals("win32"))
111: return ITERATIONS / 5;
112: return ITERATIONS;
113: }
114:
115: }
|