001: /*******************************************************************************
002: * Copyright (c) 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.ui.tests.performance;
011:
012: import java.util.HashMap;
013: import java.util.Map;
014:
015: import org.eclipse.core.resources.IMarker;
016: import org.eclipse.core.resources.IResource;
017: import org.eclipse.core.resources.IWorkspaceRoot;
018: import org.eclipse.core.resources.ResourcesPlugin;
019: import org.eclipse.core.runtime.CoreException;
020: import org.eclipse.test.performance.Dimension;
021: import org.eclipse.ui.IWorkbenchPage;
022: import org.eclipse.ui.IWorkbenchWindow;
023: import org.eclipse.ui.PartInitException;
024: import org.eclipse.ui.tests.performance.parts.PerformanceProblemsView;
025: import org.eclipse.ui.texteditor.MarkerUtilities;
026:
027: /**
028: * The ProblemsViewPerformanceTest is a test of population of the problems view.
029: *
030: * @since 3.2
031: *
032: */
033: public class ProblemsViewPerformanceTest extends BasicPerformanceTest {
034:
035: private String EMPTY_PERSPECTIVE_ID = "org.eclipse.ui.tests.harness.util.EmptyPerspective";
036:
037: private String PROBLEMS_VIEW_ID = "org.eclipse.ui.tests.performance.problemsView";
038:
039: /**
040: * Create a new instance of the receiver.
041: *
042: * @param testName
043: */
044: public ProblemsViewPerformanceTest(String testName) {
045: super (testName);
046: }
047:
048: /**
049: * Test the population of the problems view.
050: */
051: public void testPopulation() {
052: IWorkbenchWindow window = openTestWindow(EMPTY_PERSPECTIVE_ID);
053: final IWorkbenchPage page = window.getActivePage();
054:
055: PerformanceProblemsView view;
056:
057: try {
058: view = (PerformanceProblemsView) page
059: .showView(PROBLEMS_VIEW_ID);
060: } catch (PartInitException e) {
061: e.printStackTrace();
062: fail();
063: return;
064: }
065:
066: tagIfNecessary("UI - Problems View population",
067: Dimension.ELAPSED_PROCESS);
068:
069: for (int i = 0; i < 100; i++) {
070: createMarkers();
071: processEvents();
072: startMeasuring();
073: while (view.getTreeWidget().getItemCount() == 0)
074: processEvents();
075: stopMeasuring();
076: removeMarkers();
077: while (view.getTreeWidget().getItemCount() > 0)
078: processEvents();
079: }
080: commitMeasurements();
081: assertPerformance();
082:
083: }
084:
085: /**
086: * Remove the created markers
087: */
088: private void removeMarkers() {
089:
090: try {
091: IWorkspaceRoot root = ResourcesPlugin.getWorkspace()
092: .getRoot();
093:
094: IMarker[] markers = root.findMarkers(IMarker.PROBLEM,
095: false, IResource.DEPTH_ZERO);
096:
097: for (int i = 0; i < markers.length; i++) {
098: String message = (String) markers[i]
099: .getAttribute(IMarker.MESSAGE);
100:
101: if (message != null
102: && message.startsWith("this is a test")) {
103: markers[i].delete();
104: }
105: }
106: } catch (CoreException e) {
107: e.printStackTrace();
108: }
109:
110: }
111:
112: /**
113: * Create the markers for the receiver.
114: */
115: private void createMarkers() {
116: try {
117: IWorkspaceRoot root = ResourcesPlugin.getWorkspace()
118: .getRoot();
119: Map attribs = new HashMap();
120: for (int i = 0; i < 1000; i++) {
121: attribs.put(IMarker.SEVERITY, new Integer(
122: IMarker.SEVERITY_ERROR));
123: attribs.put(IMarker.MESSAGE, "this is a test " + i);
124: MarkerUtilities.createMarker(root, attribs,
125: IMarker.PROBLEM);
126: }
127: } catch (CoreException e) {
128: e.printStackTrace();
129: }
130:
131: }
132:
133: }
|