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.StructuredViewer;
013: import org.eclipse.jface.viewers.TableViewer;
014: import org.eclipse.jface.viewers.ViewerSorter;
015: import org.eclipse.swt.widgets.Composite;
016: import org.eclipse.swt.widgets.Shell;
017: import org.eclipse.swt.widgets.Table;
018: import org.eclipse.swt.widgets.TableItem;
019: import org.eclipse.swt.widgets.Widget;
020: import org.eclipse.ui.tests.performance.TestRunnable;
021:
022: /**
023: * The TableViewerRefreshTest is a test for refreshing the TableViewer.
024: */
025: public class TableViewerRefreshTest extends ViewerTest {
026:
027: class TestTableViewer extends TableViewer {
028:
029: public TestTableViewer(Composite parent, int style) {
030: super (parent, style);
031: }
032:
033: public TestTableViewer(Composite parent) {
034: super (parent);
035: }
036:
037: public TestTableViewer(Table table) {
038: super (table);
039: }
040:
041: public void testUpdateItem(Widget widget, Object element) {
042: updateItem(widget, element);
043: }
044: }
045:
046: TestTableViewer viewer;
047:
048: private RefreshTestContentProvider contentProvider;
049:
050: public TableViewerRefreshTest(String testName, int tagging) {
051: super (testName, tagging);
052: }
053:
054: public TableViewerRefreshTest(String testName) {
055: super (testName);
056: }
057:
058: /*
059: * (non-Javadoc)
060: *
061: * @see org.eclipse.jface.tests.performance.ViewerTest#createViewer(org.eclipse.swt.widgets.Shell)
062: */
063: protected StructuredViewer createViewer(Shell shell) {
064: viewer = new TestTableViewer(shell);
065: contentProvider = new RefreshTestContentProvider(
066: RefreshTestContentProvider.ELEMENT_COUNT);
067: viewer.setContentProvider(contentProvider);
068: viewer.setLabelProvider(getLabelProvider());
069: return viewer;
070: }
071:
072: /**
073: * Test the time for doing a refresh.
074: *
075: * @throws Throwable
076: */
077: public void testRefresh() throws Throwable {
078: openBrowser();
079:
080: exercise(new TestRunnable() {
081: public void run() {
082: startMeasuring();
083: viewer.refresh();
084: processEvents();
085: stopMeasuring();
086: }
087: }, MIN_ITERATIONS, slowGTKIterations(),
088: JFacePerformanceSuite.MAX_TIME);
089:
090: commitMeasurements();
091: assertPerformance();
092: }
093:
094: /**
095: * Test the time for doing a refresh.
096: *
097: * @throws Throwable
098: */
099: public void testRefreshSorted() throws Throwable {
100: openBrowser();
101: viewer.setSorter(new ViewerSorter());
102:
103: exercise(new TestRunnable() {
104: public void run() {
105: startMeasuring();
106: viewer.refresh();
107: processEvents();
108: stopMeasuring();
109: }
110: }, MIN_ITERATIONS, slowGTKIterations(),
111: JFacePerformanceSuite.MAX_TIME);
112:
113: commitMeasurements();
114: assertPerformance();
115: }
116:
117: /**
118: * Test the time for doing a refresh.
119: *
120: * @throws Throwable
121: */
122: public void testRefreshPreSorted() throws Throwable {
123: openBrowser();
124: final ViewerSorter sorter = new ViewerSorter();
125: viewer.setSorter(sorter);
126:
127: exercise(new TestRunnable() {
128: public void run() {
129: contentProvider.refreshElements();
130: startMeasuring();
131: contentProvider.cloneElements();
132: contentProvider.preSortElements(viewer, sorter);
133: viewer.refresh();
134: processEvents();
135: stopMeasuring();
136: }
137: }, MIN_ITERATIONS, ITERATIONS, JFacePerformanceSuite.MAX_TIME);
138:
139: commitMeasurements();
140: assertPerformance();
141: }
142:
143: /**
144: * Test the time for doing a refresh.
145: *
146: * @throws Throwable
147: */
148: public void testUpdate() throws Throwable {
149: openBrowser();
150:
151: exercise(
152: new TestRunnable() {
153: public void run() {
154:
155: TableItem[] items = viewer.getTable()
156: .getItems();
157: startMeasuring();
158: for (int j = 0; j < items.length; j++) {
159: TableItem item = items[j];
160: Object element = RefreshTestContentProvider.allElements[j];
161:
162: viewer.testUpdateItem(item, element);
163:
164: }
165: processEvents();
166: stopMeasuring();
167:
168: }
169: }, MIN_ITERATIONS, slowGTKIterations(),
170: JFacePerformanceSuite.MAX_TIME);
171:
172: commitMeasurements();
173: assertPerformance();
174: }
175:
176: }
|