001: /*******************************************************************************
002: * Copyright (c) 2004, 2007 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.HashSet;
013:
014: import junit.framework.Test;
015: import junit.framework.TestSuite;
016:
017: import org.eclipse.ui.internal.Workbench;
018: import org.eclipse.ui.tests.performance.layout.ResizeTest;
019: import org.eclipse.ui.tests.performance.layout.ViewWidgetFactory;
020: import org.eclipse.ui.views.IViewDescriptor;
021:
022: /**
023: * @since 3.1
024: */
025: public class ViewPerformanceSuite extends TestSuite {
026:
027: public static final String PROJECT_EXPLORER = "org.eclipse.ui.navigator.ProjectExplorer";
028:
029: public static final String BASIC_PATH = "org.eclipse.ui";
030:
031: public static final String VIEWS_PATTERN = "org.eclipse.ui.views";
032:
033: /**
034: * Returns the suite. This is required to use the JUnit Launcher.
035: */
036: public static Test suite() {
037: return new ViewPerformanceSuite();
038: }
039:
040: /**
041: *
042: */
043: public ViewPerformanceSuite() {
044: addOpenCloseTests();
045: addResizeTests();
046: addTestSuite(OpenNavigatorFolderTest.class);
047: }
048:
049: /**
050: *
051: */
052: private void addOpenCloseTests() {
053: String[] ids = getAllTestableViewIds();
054:
055: for (int i = 0; i < ids.length; i++) {
056: String id = ids[i];
057:
058: addTest(new OpenCloseViewTest(
059: id,
060: id.equals(PROJECT_EXPLORER) ? BasicPerformanceTest.GLOBAL
061: : BasicPerformanceTest.NONE));
062: }
063: }
064:
065: private void addResizeTests() {
066: String[] ids = getAllTestableViewIds();
067:
068: for (int i = 0; i < ids.length; i++) {
069: String id = ids[i];
070:
071: addTest(new ResizeTest(new ViewWidgetFactory(id)));
072: }
073:
074: }
075:
076: public static String[] getAllTestableViewIds() {
077: HashSet result = new HashSet();
078:
079: IViewDescriptor[] descriptors = Workbench.getInstance()
080: .getViewRegistry().getViews();
081: for (int i = 0; i < descriptors.length; i++) {
082: IViewDescriptor descriptor = descriptors[i];
083:
084: String[] categoryPath = descriptor.getCategoryPath();
085:
086: if (categoryPath == null)
087: continue;
088:
089: for (int j = 0; j < categoryPath.length; j++) {
090: // Only test basic views
091: if (categoryPath[j].equals(BASIC_PATH)) {
092: if (descriptor.getId().indexOf(VIEWS_PATTERN) >= 0
093: || descriptor.getId().equals(
094: PROJECT_EXPLORER)) {
095: result.add(descriptor.getId());
096: }
097: }
098: }
099:
100: }
101:
102: return (String[]) result.toArray(new String[result.size()]);
103: }
104: }
|