blob: c65141cc5260b377b24081955c8350f44675ac73 [file] [log] [blame]
/*******************************************************************************
* Copyright (c) 2003, 2004 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/cpl-v10.html
*
* Contributors:
* IBM Corporation - initial API and implementation
*******************************************************************************/
package org.eclipse.pde.internal.junit.runtime;
import junit.framework.*;
import org.eclipse.core.runtime.*;
import org.eclipse.ui.*;
import org.eclipse.ui.testing.*;
/**
* A Workbench that runs a test suite specified in the
* command line arguments.
*/
public class UITestApplication implements IPlatformRunnable, ITestHarness {
private static final String DEFAULT_APP_3_0 = "org.eclipse.ui.ide.workbench"; //$NON-NLS-1$
private TestableObject fTestableObject;
/* (non-Javadoc)
* @see org.eclipse.core.runtime.IPlatformRunnable#run(java.lang.Object)
*/
public Object run(final Object args) throws Exception {
IPlatformRunnable application = getApplication((String[]) args);
Assert.assertNotNull(application);
fTestableObject = PlatformUI.getTestableObject();
fTestableObject.setTestHarness(this);
return application.run(args);
}
/*
* return the application to run, or null if not even the default application
* is found.
*/
private IPlatformRunnable getApplication(String[] args) throws CoreException {
// Find the name of the application as specified by the PDE JUnit launcher.
// If no application is specified, the 3.0 default workbench application
// is returned.
IExtension extension =
Platform.getExtensionRegistry().getExtension(
Platform.PI_RUNTIME,
Platform.PT_APPLICATIONS,
getApplicationToRun(args));
Assert.assertNotNull(extension);
// If the extension does not have the correct grammar, return null.
// Otherwise, return the application object.
IConfigurationElement[] elements = extension.getConfigurationElements();
if (elements.length > 0) {
IConfigurationElement[] runs = elements[0].getChildren("run"); //$NON-NLS-1$
if (runs.length > 0) {
Object runnable = runs[0].createExecutableExtension("class"); //$NON-NLS-1$
if (runnable instanceof IPlatformRunnable)
return (IPlatformRunnable) runnable;
}
}
return null;
}
private String getProductApplication(String productID) {
IExtension extension =
Platform.getExtensionRegistry().getExtension(
Platform.PI_RUNTIME,
Platform.PT_PRODUCT,
productID);
Assert.assertNotNull(extension);
IConfigurationElement[] elements = extension.getConfigurationElements();
return elements.length > 0 ? elements[0].getAttribute("application") : null;
}
/*
* The -testApplication argument specifies the application to be run.
* If the PDE JUnit launcher did not set this argument, then return
* the name of the default application.
* In 3.0, the default is the "org.eclipse.ui.ide.worbench" application.
*
*/
private String getApplicationToRun(String[] args) {
for (int i = 0; i < args.length; i++) {
if (args[i].equals("-testProduct")) //$NON-NLS-1$
return getProductApplication(args[i+1]);
if (args[i].equals("-testApplication") && i < args.length -1) //$NON-NLS-1$
return args[i+1];
}
return DEFAULT_APP_3_0;
}
/* (non-Javadoc)
* @see org.eclipse.ui.testing.ITestHarness#runTests()
*/
public void runTests() {
fTestableObject.testingStarting();
fTestableObject.runTest(new Runnable() {
public void run() {
RemotePluginTestRunner.main(Platform.getCommandLineArgs());
}
});
fTestableObject.testingFinished();
}
}