001: /*******************************************************************************
002: * Copyright (c) 2000, 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.io.ByteArrayInputStream;
013:
014: import junit.extensions.TestSetup;
015: import junit.framework.Test;
016:
017: import org.eclipse.core.resources.IFile;
018: import org.eclipse.core.resources.IProject;
019: import org.eclipse.core.resources.IWorkspace;
020: import org.eclipse.core.resources.ResourcesPlugin;
021: import org.eclipse.core.runtime.CoreException;
022: import org.eclipse.ui.IWorkbench;
023: import org.eclipse.ui.IWorkbenchPage;
024: import org.eclipse.ui.IWorkbenchWindow;
025: import org.eclipse.ui.PlatformUI;
026:
027: public class UIPerformanceTestSetup extends TestSetup {
028:
029: public static final String PERSPECTIVE1 = "org.eclipse.ui.tests.performancePerspective1";
030: public static final String PERSPECTIVE2 = "org.eclipse.ui.tests.performancePerspective2";
031:
032: public static final String PROJECT_NAME = "Performance Project";
033:
034: private static final String INTRO_VIEW = "org.eclipse.ui.internal.introview";
035:
036: private IProject testProject;
037:
038: public UIPerformanceTestSetup(Test test) {
039: super (test);
040: }
041:
042: /*
043: * @see junit.extensions.TestSetup#setUp()
044: */
045: protected void setUp() throws Exception {
046: IWorkbench workbench = PlatformUI.getWorkbench();
047: IWorkbenchWindow activeWindow = workbench
048: .getActiveWorkbenchWindow();
049: IWorkbenchPage activePage = activeWindow.getActivePage();
050:
051: activePage.hideView(activePage.findViewReference(INTRO_VIEW));
052:
053: workbench.showPerspective(PERSPECTIVE1, activeWindow);
054:
055: boolean wasAutobuilding = ResourceTestHelper
056: .disableAutoBuilding();
057: setUpProject();
058: ResourceTestHelper.fullBuild();
059: if (wasAutobuilding) {
060: ResourceTestHelper.enableAutoBuilding();
061: EditorTestHelper.calmDown(2000, 30000, 1000);
062: }
063: }
064:
065: /*
066: * @see junit.extensions.TestSetup#tearDown()
067: */
068: protected void tearDown() throws Exception {
069: // do nothing, the set up workspace will be used by the open editor tests
070:
071: /*
072: * ensure the workbench state gets saved when running with the Automated Testing Framework
073: * TODO: remove when https://bugs.eclipse.org/bugs/show_bug.cgi?id=71362 is fixed
074: */
075: StackTraceElement[] elements = new Throwable().getStackTrace();
076: for (int i = 0; i < elements.length; i++) {
077: StackTraceElement element = elements[i];
078: if (element.getClassName().equals(
079: "org.eclipse.test.EclipseTestRunner")) {
080: PlatformUI.getWorkbench().close();
081: break;
082: }
083: }
084: }
085:
086: private void setUpProject() throws CoreException {
087:
088: // Create a java project.
089: IWorkspace workspace = ResourcesPlugin.getWorkspace();
090: testProject = workspace.getRoot().getProject(PROJECT_NAME);
091: testProject.create(null);
092: testProject.open(null);
093: /*IProjectDescription projectDescription = testProject.getDescription();
094: String[] natureIds = { "org.eclipse.jdt.core.javanature" };
095: projectDescription.setNatureIds(natureIds);*/
096: /*ICommand buildCommand = new BuildCommand();
097: buildCommand.setBuilderName("org.eclipse.jdt.core.javabuilder");
098: projectDescription.setBuildSpec(new ICommand[] { buildCommand });
099: testProject.setDescription(projectDescription, null);*/
100:
101: for (int i = 0; i < EditorPerformanceSuite.EDITOR_FILE_EXTENSIONS.length; i++) {
102: createFiles(EditorPerformanceSuite.EDITOR_FILE_EXTENSIONS[i]);
103: }
104: }
105:
106: /**
107: * @param ext
108: * @throws CoreException
109: */
110: private void createFiles(String ext) throws CoreException {
111: for (int i = 0; i < 100; i++) {
112: String fileName = i + "." + ext;
113: IFile iFile = testProject.getFile(fileName);
114: iFile.create(new ByteArrayInputStream(new byte[] { '\n' }),
115: true, null);
116: }
117: }
118: }
|