1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-08-01 13:25:45 +02:00

Code cleanup

Change-Id: If94553894586f8745fff9952f3648160110ba609
This commit is contained in:
Sergey Prigogin 2016-11-29 10:24:42 -08:00 committed by Gerrit Code Review @ Eclipse.org
parent 83bd6f7ed4
commit dccd99c843
13 changed files with 809 additions and 838 deletions

View file

@ -16,14 +16,13 @@ import java.net.URL;
* Helper class to launch a test * Helper class to launch a test
*/ */
public class TestPluginLauncher { public class TestPluginLauncher {
public static final String APP_NAME= "org.eclipse.jdt.ui.tests.app"; public static final String APP_NAME= "org.eclipse.jdt.ui.tests.app";
public static void run(String location, Class testCase, String[] args) { public static void run(String location, Class<?> testCase, String[] args) {
run(APP_NAME, location, testCase, args); run(APP_NAME, location, testCase, args);
} }
public static void run(String application, String location, Class testCase, String[] args) { public static void run(String application, String location, Class<?> testCase, String[] args) {
try { try {
String bootLocation= getBootLocation(); String bootLocation= getBootLocation();
int nArgs= args.length; int nArgs= args.length;

View file

@ -10,46 +10,50 @@
*******************************************************************************/ *******************************************************************************/
package org.eclipse.cdt.core.testplugin.util; package org.eclipse.cdt.core.testplugin.util;
import java.util.ArrayList; import java.util.ArrayList;
/* /*
* Interface to describe a visual test pass for a dialog test. * Interface to describe a visual test pass for a dialog test.
*/ */
public interface IDialogTestPass { public interface IDialogTestPass {
/* /**
* @return String The title of the test pass. * @return String The title of the test pass.
*/ */
public String title(); public String title();
/*
/**
* @return String The description of the test pass. * @return String The description of the test pass.
*/ */
public String description(); public String description();
/*
/**
* @return String The label of the test pass to be used * @return String The label of the test pass to be used
* in a selection list. The return includes an '&' * in a selection list. The return includes an '&'
* if a mnemonic is desired. * if a mnemonic is desired.
*/ */
public String label(); public String label();
/*
/**
* @return ArrayList A list of items to appear in a checklist. * @return ArrayList A list of items to appear in a checklist.
* The items in the list must be Strings and should include an * The items in the list must be Strings and should include an
* '&' if a mnemonic is desired. * '&' if a mnemonic is desired.
*/ */
public ArrayList checkListTexts(); public ArrayList<String> checkListTexts();
/*
/**
* @return String[] Associated failure messages that correspond * @return String[] Associated failure messages that correspond
* to the checklist items. The size of this array should be the * to the checklist items. The size of this array should be the
* same size as the checklist. * same size as the checklist.
*/ */
public String[] failureTexts(); public String[] failureTexts();
/*
/**
* @return String The test that corresponds to the test pass to * @return String The test that corresponds to the test pass to
* which the tester will respond with a 'yes' or 'no'. * which the tester will respond with a 'yes' or 'no'.
*/ */
public String queryText(); public String queryText();
/*
/**
* @return int A unique number that identifies the test pass. * @return int A unique number that identifies the test pass.
*/ */
public int getID(); public int getID();

View file

@ -13,39 +13,29 @@ package org.eclipse.cdt.core.testplugin.util;
import java.util.ArrayList; import java.util.ArrayList;
/* /*
* This test pass verifies visually the sizing of the dialog and its * This test pass verifies visually the sizing of the dialog and its widgets.
* widgets.
*/ */
class SizingTestPass implements IDialogTestPass { class SizingTestPass implements IDialogTestPass {
private static final int CHECKLIST_SIZE = 5; private static final int CHECKLIST_SIZE = 5;
/**
* @see IDialogTestPass#title()
*/
@Override @Override
public String title() { public String title() {
return "Test Pass: Sizing and Display"; return "Test Pass: Sizing and Display";
} }
/**
* @see IDialogTestPass#description()
*/
@Override @Override
public String description() { public String description() {
return "Verify the sizing and display of the dialogs and widgets."; return "Verify the sizing and display of the dialogs and widgets.";
} }
/**
* @see IDialogTestPass#label()
*/
@Override @Override
public String label() { public String label() {
return "&Sizing and Display"; return "&Sizing and Display";
} }
/**
* @see IDialogTestPass#checkListTexts()
*/
@Override @Override
public ArrayList checkListTexts() { public ArrayList<String> checkListTexts() {
ArrayList list = new ArrayList(CHECKLIST_SIZE); ArrayList<String> list = new ArrayList<>(CHECKLIST_SIZE);
list.add("&1) the correct dialog displays."); list.add("&1) the correct dialog displays.");
list.add("&2) the dialog is an appropriate size for the required resolution (1024x768)."); list.add("&2) the dialog is an appropriate size for the required resolution (1024x768).");
list.add("&3) the texts are correct and not cut off."); list.add("&3) the texts are correct and not cut off.");
@ -53,11 +43,7 @@ class SizingTestPass implements IDialogTestPass {
list.add("&5) all the widgets are viewable and not cut off."); list.add("&5) all the widgets are viewable and not cut off.");
return list; return list;
} }
/**
* @see IDialogTestPass#failureTexts()
* Size of the return array must be the same size as the checkListTexts'
* ArrayList.
*/
@Override @Override
public String[] failureTexts() { public String[] failureTexts() {
String[] failureText = new String[CHECKLIST_SIZE]; String[] failureText = new String[CHECKLIST_SIZE];
@ -68,16 +54,12 @@ class SizingTestPass implements IDialogTestPass {
failureText[4] = "Some widgets are cut off."; failureText[4] = "Some widgets are cut off.";
return failureText; return failureText;
} }
/**
* @see IDialogTestPass#queryText()
*/
@Override @Override
public String queryText() { public String queryText() {
return "Is the sizing and display of the dialog correct?"; return "Is the sizing and display of the dialog correct?";
} }
/**
* @see IDialogTestPass#getID()
*/
@Override @Override
public int getID() { public int getID() {
return VerifyDialog.TEST_SIZING; return VerifyDialog.TEST_SIZING;

View file

@ -10,66 +10,64 @@
*******************************************************************************/ *******************************************************************************/
package org.eclipse.cdt.ui.testplugin; package org.eclipse.cdt.ui.testplugin;
// copied from startup.jar. planned to be removed soon import java.io.File;
import java.net.*; import java.io.FileFilter;
import java.lang.reflect.*; import java.io.IOException;
import java.io.*; import java.lang.reflect.InvocationTargetException;
import java.util.*; import java.lang.reflect.Method;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLClassLoader;
import java.util.ArrayList;
import java.util.List;
import java.util.StringTokenizer;
import java.util.Vector;
// Copied from startup.jar. planned to be removed soon
/** /**
* Startup class for Eclipse. Creates a class loader using * Startup class for Eclipse. Creates a class loader using supplied URL of
* supplied URL of platform installation, loads and calls * platform installation, loads and calls the Eclipse Boot Loader. The startup
* the Eclipse Boot Loader. The startup arguments are as follows: * arguments are as follows:
* <dl> * <dl>
* <dd> * <dd>-application &lt;id&gt;: the identifier of the application to run</dd>
* -application &lt;id&gt;: the identifier of the application to run * <dd>-boot &lt;location&gt;: the location, expressed as a URL, of the
* platform's boot.jar</dd>
* <dd>-consolelog : enables log to the console. Handy when combined with -debug
* </dd> * </dd>
* <dd> * <dd>-data &lt;location&gt;: sets the workspace location and the default
* -boot &lt;location&gt;: the location, expressed as a URL, of the platform's boot.jar * location for projects</dd>
* </dd> * <dd>-debug [options file]: turns on debug mode for the platform and
* <dd> * optionally specifies a location for the .options file. This file indicates
* -consolelog : enables log to the console. Handy when combined with -debug * what debug points are available for a plug-in and whether or not they are
* </dd> * enabled. If a location is not specified, the platform searches for the
* <dd> * .options file under the install directory</dd>
* -data &lt;location&gt;: sets the workspace location and the default location for projects * <dd>-dev [entries]: turns on dev mode and optionally specifies
* </dd> * comma-separated class path entries which are added to the class path of each
* <dd> * plug-in</dd>
* -debug [options file]: turns on debug mode for the platform and optionally specifies a location * <dd>-keyring &lt;location&gt;: the location of the authorization database on
* for the .options file. This file indicates what debug points are available for a * disk. This argument has to be used together with the -password argument</dd>
* plug-in and whether or not they are enabled. If a location is not specified, the platform searches * <dd>-password &lt;passwd&gt;: the password for the authorization database
* for the .options file under the install directory
* </dd>
* <dd>
* -dev [entries]: turns on dev mode and optionally specifies comma-separated class path entries
* which are added to the class path of each plug-in
* </dd>
* <dd>
* -keyring &lt;location&gt;: the location of the authorization database on disk. This argument
* has to be used together with the -password argument
* </dd>
* <dd>
* -password &lt;passwd&gt;: the password for the authorization database
* </dd>
* <dd>
* -plugins &lt;location&gt;: The arg is a URL pointing to a file which specs the plugin
* path for the platform. The file is in property file format where the keys are user-defined
* names and the values are comma separated lists of either explicit paths to plugin.xml
* files or directories containing plugins. (e.g., .../eclipse/plugins).
* </dd>
* <dd>
* -ws &lt;window system&gt;: sets the window system value
* </dd> * </dd>
* <dd>-plugins &lt;location&gt;: The arg is a URL pointing to a file which
* specs the plugin path for the platform. The file is in property file format
* where the keys are user-defined names and the values are comma separated
* lists of either explicit paths to plugin.xml files or directories containing
* plugins. (e.g., .../eclipse/plugins).</dd>
* <dd>-ws &lt;window system&gt;: sets the window system value</dd>
* </dl> * </dl>
*/ */
public class Main { public class Main {
/** /**
* Indicates whether this instance is running in debug mode. * Indicates whether this instance is running in debug mode.
*/ */
protected boolean debug = false; protected boolean debug;
/** /**
* The location of the launcher to run. * The location of the launcher to run.
*/ */
protected String bootLocation = null; protected String bootLocation;
/** /**
* The identifier of the application to run. * The identifier of the application to run.
@ -87,7 +85,7 @@ public class Main {
protected String location; protected String location;
/** /**
* Indicates whether items for UNinstallation should be looked for. * Indicates whether items for uninstallation should be looked for.
*/ */
protected boolean uninstall = false; protected boolean uninstall = false;
@ -99,15 +97,15 @@ public class Main {
/** /**
* The class path entries. * The class path entries.
*/ */
protected String devClassPath = null; protected String devClassPath;
/** /**
* Indicates whether this instance is running in development mode. * Indicates whether this instance is running in development mode.
*/ */
protected boolean inDevelopmentMode = false; protected boolean inDevelopmentMode;
// static token describing how to take down the splash screen // static token describing how to take down the splash screen
private static String endSplash = null; private static String endSplash;
// constants // constants
private static final String APPLICATION = "-application"; //$NON-NLS-1$ private static final String APPLICATION = "-application"; //$NON-NLS-1$
@ -146,13 +144,14 @@ public class Main {
/** /**
* Executes the launch. * Executes the launch.
* *
* @return the result of performing the launch
* @param args command-line arguments * @param args command-line arguments
* @return the result of performing the launch
* @exception Exception thrown if a problem occurs during the launch * @exception Exception thrown if a problem occurs during the launch
*/ */
protected Object basicRun(String[] args) throws Exception { protected Object basicRun(String[] args) throws Exception {
Class clazz = getBootLoader(bootLocation); Class<?> clazz = getBootLoader(bootLocation);
Method method = clazz.getDeclaredMethod("run", new Class[] { String.class, URL.class, String.class, String[].class }); //$NON-NLS-1$ Method method = clazz.getDeclaredMethod("run", //$NON-NLS-1$
new Class[] { String.class, URL.class, String.class, String[].class });
try { try {
return method.invoke(clazz, new Object[] { application, pluginPathLocation, location, args }); return method.invoke(clazz, new Object[] { application, pluginPathLocation, location, args });
} catch (InvocationTargetException e) { } catch (InvocationTargetException e) {
@ -163,42 +162,46 @@ protected Object basicRun(String[] args) throws Exception {
} }
/** /**
* Returns the result of converting a list of comma-separated tokens into an array * Returns the result of converting a list of comma-separated tokens into an array.
* *
* @return the array of string tokens
* @param prop the initial comma-separated string * @param prop the initial comma-separated string
* @return the array of string tokens
*/ */
private String[] getArrayFromList(String prop) { private String[] getArrayFromList(String prop) {
if (prop == null || prop.trim().isEmpty()) if (prop == null || prop.trim().isEmpty())
return new String[0]; return new String[0];
Vector list = new Vector(); List<String> list = new ArrayList<>();
StringTokenizer tokens = new StringTokenizer(prop, ","); //$NON-NLS-1$ StringTokenizer tokens = new StringTokenizer(prop, ","); //$NON-NLS-1$
while (tokens.hasMoreTokens()) { while (tokens.hasMoreTokens()) {
String token = tokens.nextToken().trim(); String token = tokens.nextToken().trim();
if (!token.isEmpty()) if (!token.isEmpty())
list.addElement(token); list.add(token);
} }
return list.isEmpty() ? new String[0] : (String[]) list.toArray(new String[0]); return list.toArray(new String[0]);
} }
/** /**
* Creates and returns a platform <code>BootLoader</code> which can be used to start * Creates and returns a platform <code>BootLoader</code> which can be used
* up and run the platform. The given base, if not <code>null</code>, * to start up and run the platform. The given base, if not
* is the location of the boot loader code. If the value is <code>null</code> * <code>null</code>, is the location of the boot loader code. If the value
* then the boot loader is located relative to this class. * is <code>null</code> then the boot loader is located relative to this
* class.
* *
* @return the new boot loader
* @param base the location of the boot loader * @param base the location of the boot loader
* @return the new boot loader
*/ */
public Class getBootLoader(String base) throws Exception { public Class<?> getBootLoader(String base) throws Exception {
URLClassLoader loader = new URLClassLoader(getBootPath(base), null); try (URLClassLoader loader = new URLClassLoader(getBootPath(base), null)) {
return loader.loadClass(BOOTLOADER); return loader.loadClass(BOOTLOADER);
} }
}
/** /**
* Returns the <code>URL</code>-based class path describing where the boot classes * Returns the <code>URL</code>-based class path describing where the boot
* are located when running in development mode. * classes are located when running in development mode.
* *
* @return the url-based class path
* @param base the base location * @param base the base location
* @return the url-based class path
* @exception MalformedURLException if a problem occurs computing the class path * @exception MalformedURLException if a problem occurs computing the class path
*/ */
protected URL[] getDevPath(URL base) throws MalformedURLException { protected URL[] getDevPath(URL base) throws MalformedURLException {
@ -209,14 +212,15 @@ protected URL[] getDevPath(URL base) throws MalformedURLException {
return new URL[] { url }; return new URL[] { url };
} }
String[] locations = getArrayFromList(devClassPath); String[] locations = getArrayFromList(devClassPath);
ArrayList result = new ArrayList(locations.length); ArrayList<URL> result = new ArrayList<>(locations.length);
for (int i = 0; i < locations.length; i++) { for (int i = 0; i < locations.length; i++) {
String spec = devBase + locations[i]; String spec = devBase + locations[i];
char lastChar = spec.charAt(spec.length() - 1); char lastChar = spec.charAt(spec.length() - 1);
if ((spec.endsWith(".jar") || (lastChar == '/' || lastChar == '\\'))) //$NON-NLS-1$ if ((spec.endsWith(".jar") || (lastChar == '/' || lastChar == '\\'))) { //$NON-NLS-1$
url = new URL(spec); url = new URL(spec);
else } else {
url = new URL(spec + "/"); //$NON-NLS-1$ url = new URL(spec + "/"); //$NON-NLS-1$
}
// make sure URL exists before adding to path // make sure URL exists before adding to path
if (new java.io.File(url.getFile()).exists()) if (new java.io.File(url.getFile()).exists())
result.add(url); result.add(url);
@ -224,14 +228,15 @@ protected URL[] getDevPath(URL base) throws MalformedURLException {
url = new URL(devBase + "boot.jar"); //$NON-NLS-1$ url = new URL(devBase + "boot.jar"); //$NON-NLS-1$
if (new java.io.File(url.getFile()).exists()) if (new java.io.File(url.getFile()).exists())
result.add(url); result.add(url);
return (URL[])result.toArray(new URL[result.size()]); return result.toArray(new URL[result.size()]);
} }
/** /**
* Returns the <code>URL</code>-based class path describing where the boot classes are located. * Returns the <code>URL</code>-based class path describing where the boot
* classes are located.
* *
* @return the url-based class path
* @param base the base location * @param base the base location
* @return the url-based class path
* @exception MalformedURLException if a problem occurs computing the class path * @exception MalformedURLException if a problem occurs computing the class path
*/ */
protected URL[] getBootPath(String base) throws MalformedURLException { protected URL[] getBootPath(String base) throws MalformedURLException {
@ -251,8 +256,7 @@ protected URL[] getBootPath(String base) throws MalformedURLException {
String path = url.getFile(); String path = url.getFile();
if (path.endsWith(".jar")) //$NON-NLS-1$ if (path.endsWith(".jar")) //$NON-NLS-1$
path = path.substring(0, path.lastIndexOf("/")); //$NON-NLS-1$ path = path.substring(0, path.lastIndexOf("/")); //$NON-NLS-1$
else else if (path.endsWith("/")) //$NON-NLS-1$
if (path.endsWith("/")) //$NON-NLS-1$
path = path.substring(0, path.length() - 1); path = path.substring(0, path.length() - 1);
if (inVAJ || inVAME) { if (inVAJ || inVAME) {
int ix = path.lastIndexOf("/"); //$NON-NLS-1$ int ix = path.lastIndexOf("/"); //$NON-NLS-1$
@ -276,12 +280,11 @@ protected URL[] getBootPath(String base) throws MalformedURLException {
} }
/** /**
* Searches for a plugins root starting at a given location. If one is * Searches for a plugins root starting at a given location. If one is found
* found then this location is returned; otherwise an empty string is * then this location is returned; otherwise an empty string is returned.
* returned.
* *
* @return the location where plugins were found, or an empty string
* @param start the location to begin searching at * @param start the location to begin searching at
* @return the location where plugins were found, or an empty string
*/ */
protected String searchForPlugins(String start) { protected String searchForPlugins(String start) {
File path = new File(start); File path = new File(start);
@ -294,13 +297,14 @@ protected String searchForPlugins(String start) {
} }
return ""; //$NON-NLS-1$ return ""; //$NON-NLS-1$
} }
/** /**
* Searches for a boot directory starting at a given location. If one * Searches for a boot directory starting at a given location. If one is
* is found then this location is returned; otherwise an empty string * found then this location is returned; otherwise an empty string is
* is returned. * returned.
* *
* @return the location where plugins were found, or an empty string
* @param start the location to begin searching at * @param start the location to begin searching at
* @return the location where plugins were found, or an empty string
*/ */
protected String searchForBoot(String start) { protected String searchForBoot(String start) {
FileFilter filter = new FileFilter() { FileFilter filter = new FileFilter() {
@ -324,8 +328,7 @@ protected String searchForBoot(String start) {
if (maxVersion == null) { if (maxVersion == null) {
result = boots[i].getAbsolutePath(); result = boots[i].getAbsolutePath();
maxVersion = version; maxVersion = version;
} else } else if (maxVersion.compareTo(version) == -1) {
if (maxVersion.compareTo(version) == -1) {
result = boots[i].getAbsolutePath(); result = boots[i].getAbsolutePath();
maxVersion = version; maxVersion = version;
} }
@ -333,20 +336,24 @@ protected String searchForBoot(String start) {
} }
} }
if (result == null) if (result == null)
throw new RuntimeException("Could not find bootstrap code. Check location of boot plug-in or specify -boot."); //$NON-NLS-1$ throw new RuntimeException(
"Could not find bootstrap code. Check location of boot plug-in or specify -boot."); //$NON-NLS-1$
return result.replace(File.separatorChar, '/') + "/"; //$NON-NLS-1$ return result.replace(File.separatorChar, '/') + "/"; //$NON-NLS-1$
} }
/** /**
* Returns the update loader for the given boot path. * Returns the update loader for the given boot path.
* *
* @return the update loader
* @param base the boot path base * @param base the boot path base
* @return the update loader
* @exception Exception thrown is a problem occurs determining this loader * @exception Exception thrown is a problem occurs determining this loader
*/ */
public Class getUpdateLoader(String base) throws Exception { public Class<?> getUpdateLoader(String base) throws MalformedURLException, IOException, ClassNotFoundException {
URLClassLoader loader = new URLClassLoader(getBootPath(base), null); try (URLClassLoader loader = new URLClassLoader(getBootPath(base), null)) {
return loader.loadClass(UPDATELOADER); return loader.loadClass(UPDATELOADER);
} }
}
/** /**
* Runs the platform with the given arguments. The arguments must identify * Runs the platform with the given arguments. The arguments must identify
* an application to run (e.g., <code>-application com.example.application</code>). * an application to run (e.g., <code>-application com.example.application</code>).
@ -355,12 +362,12 @@ public Class getUpdateLoader(String base) throws Exception {
* If the application's return value is an <code>Integer</code>, N is this value. * If the application's return value is an <code>Integer</code>, N is this value.
* In all other cases, N = 0. * In all other cases, N = 0.
* <p> * <p>
* Clients wishing to run the platform without a following <code>System.exit</code> * Clients wishing to run the platform without a following
* call should use <code>run()</code>. * <code>System.exit</code> call should use <code>run()</code>.
*
* @see #run
* *
* @param args the command line arguments * @param args the command line arguments
*
* @see #run
*/ */
public static void main(String[] args) { public static void main(String[] args) {
Object result = null; Object result = null;
@ -375,6 +382,7 @@ public static void main(String[] args) {
int exitCode = result instanceof Integer ? ((Integer) result).intValue() : 0; int exitCode = result instanceof Integer ? ((Integer) result).intValue() : 0;
System.exit(exitCode); System.exit(exitCode);
} }
/** /**
* Tears down the currently-displayed splash screen. * Tears down the currently-displayed splash screen.
*/ */
@ -394,21 +402,22 @@ public static void endSplash() {
* @exception Exception thrown if a problem occurs during launching * @exception Exception thrown if a problem occurs during launching
*/ */
public static void main(String argString) throws Exception { public static void main(String argString) throws Exception {
Vector list = new Vector(5); Vector<Object> list = new Vector<Object>(5);
for (StringTokenizer tokens = new StringTokenizer(argString, " "); tokens.hasMoreElements();) //$NON-NLS-1$ for (StringTokenizer tokens = new StringTokenizer(argString, " "); tokens.hasMoreElements();) //$NON-NLS-1$
list.addElement(tokens.nextElement()); list.addElement(tokens.nextElement());
main((String[]) list.toArray(new String[list.size()])); main(list.toArray(new String[list.size()]));
} }
/** /**
* Processes the command line arguments * Processes the command line arguments
* *
* @return the arguments to pass through to the launched application
* @param args the command line arguments * @param args the command line arguments
* @return the arguments to pass through to the launched application
*/ */
protected String[] processCommandLine(String[] args) throws Exception { protected String[] processCommandLine(String[] args) throws Exception {
int[] configArgs = new int[100]; int[] configArgs = new int[100];
configArgs[0] = -1; // need to initialize the first element to something that could not be an index. configArgs[0] = -1; // need to initialize the first element to something
// that could not be an index.
int configArgIndex = 0; int configArgIndex = 0;
for (int i = 0; i < args.length; i++) { for (int i = 0; i < args.length; i++) {
boolean found = false; boolean found = false;
@ -420,11 +429,15 @@ protected String[] processCommandLine(String[] args) throws Exception {
continue; continue;
} }
// check if development mode should be enabled for the entire platform // Check if development mode should be enabled for the entire platform.
// If this is the last arg or there is a following arg (i.e., arg+1 has a leading -), // If this is the last arg or there is a following arg (i.e., arg+1
// simply enable development mode. Otherwise, assume that that the following arg is // has a leading -),
// actually some additional development time class path entries. This will be processed below. // simply enable development mode. Otherwise, assume that that the
if (args[i].equalsIgnoreCase(DEV) && ((i + 1 == args.length) || ((i + 1 < args.length) && (args[i + 1].startsWith("-"))))) { //$NON-NLS-1$ // following arg is
// actually some additional development time class path entries.
// This will be processed below.
if (args[i].equalsIgnoreCase(DEV)
&& ((i + 1 == args.length) || ((i + 1 < args.length) && (args[i + 1].startsWith("-"))))) { //$NON-NLS-1$
inDevelopmentMode = true; inDevelopmentMode = true;
// do not mark the arg as found so it will be passed through // do not mark the arg as found so it will be passed through
continue; continue;
@ -435,8 +448,10 @@ protected String[] processCommandLine(String[] args) throws Exception {
configArgs[configArgIndex++] = i; configArgs[configArgIndex++] = i;
continue; continue;
} }
// check for args with parameters. If we are at the last argument or if the next one // check for args with parameters. If we are at the last argument or
// has a '-' as the first character, then we can't have an arg with a parm so continue. // if the next one
// has a '-' as the first character, then we can't have an arg with
// a parm so continue.
if (i == args.length - 1 || args[i + 1].startsWith("-")) //$NON-NLS-1$ if (i == args.length - 1 || args[i + 1].startsWith("-")) //$NON-NLS-1$
continue; continue;
String arg = args[++i]; String arg = args[++i];
@ -493,12 +508,13 @@ protected String[] processCommandLine(String[] args) throws Exception {
} }
return passThruArgs; return passThruArgs;
} }
/** /**
* Runs the application to be launched. * Runs the application to be launched.
* *
* @return the return value from the launched application * @return the return value from the launched application
* @param args the arguments to pass to the application * @param args the arguments to pass to the application
* @exception thrown if a problem occurs during launching * @exception Exception thrown if a problem occurs during launching
*/ */
public Object run(String[] args) throws Exception { public Object run(String[] args) throws Exception {
String[] passThruArgs = processCommandLine(args); String[] passThruArgs = processCommandLine(args);
@ -506,18 +522,24 @@ public Object run(String[] args) throws Exception {
return updateRun(UNINSTALL, uninstallCookie, passThruArgs); return updateRun(UNINSTALL, uninstallCookie, passThruArgs);
return basicRun(passThruArgs); return basicRun(passThruArgs);
} }
/** /**
* Performs an update run. * Performs an update run.
* *
* @return the return value from the update loader * @return the return value from the update loader
* @param flag flag to give to the update loader * @param flag
* @param value value to give to the update loader * flag to give to the update loader
* @param args arguments to give to the update loader. * @param value
* @exception Exception thrown if a problem occurs during execution * value to give to the update loader
* @param args
* arguments to give to the update loader.
* @exception Exception
* thrown if a problem occurs during execution
*/ */
protected Object updateRun(String flag, String value, String[] args) throws Exception { protected Object updateRun(String flag, String value, String[] args) throws Exception {
Class clazz = getUpdateLoader(bootLocation); Class<?> clazz = getUpdateLoader(bootLocation);
Method method = clazz.getDeclaredMethod("run", new Class[] { String.class, String.class, String.class, String[].class }); //$NON-NLS-1$ Method method = clazz.getDeclaredMethod("run", //$NON-NLS-1$
new Class[] { String.class, String.class, String.class, String[].class });
try { try {
return method.invoke(clazz, new Object[] { flag, value, location, args }); return method.invoke(clazz, new Object[] { flag, value, location, args });
} catch (InvocationTargetException e) { } catch (InvocationTargetException e) {

View file

@ -14,19 +14,19 @@ import java.io.File;
import java.io.FileInputStream; import java.io.FileInputStream;
import java.io.IOException; import java.io.IOException;
import java.net.URL; import java.net.URL;
import java.util.ArrayList;
import java.util.List;
import java.util.Properties; import java.util.Properties;
import java.util.StringTokenizer; import java.util.StringTokenizer;
import java.util.Vector;
/** /**
* Application is responsible for calling core launch api * Application is responsible for calling core launch api
*/ */
public class NewMain extends Main { public class NewMain extends Main {
private static final String DEFAULT_APPLICATION= "org.eclipse.ui.workbench"; //$NON-NLS-1$ private static final String DEFAULT_APPLICATION= "org.eclipse.ui.workbench"; //$NON-NLS-1$
public NewMain(String application, String location, URL pluginPathLocation, String bootLocation, boolean debug)
public NewMain(String application, String location, URL pluginPathLocation, String bootLocation, boolean debug) throws IOException { throws IOException {
this.application= application; this.application= application;
this.location= location; this.location= location;
this.pluginPathLocation= pluginPathLocation; this.pluginPathLocation= pluginPathLocation;
@ -44,17 +44,17 @@ public class NewMain extends Main {
System.exit(0); System.exit(0);
} }
/** /**
* Run this launcher with the arguments specified in the given string. * Runs this launcher with the arguments specified in the given string.
* This is a short cut method for people running the launcher from * This is a short cut method for people running the launcher from
* a scrapbook (i.e., swip-and-doit facility). * a scrapbook (i.e., swip-and-doit facility).
*/ */
public static void main(String argString) throws Exception { public static void main(String argString) throws Exception {
Vector list= new Vector(5); List<String> list= new ArrayList<>(5);
for (StringTokenizer tokens= new StringTokenizer(argString, " "); tokens.hasMoreElements();) //$NON-NLS-1$ for (StringTokenizer tokens= new StringTokenizer(argString, " "); tokens.hasMoreElements();) { //$NON-NLS-1$
list.addElement(tokens.nextElement()); list.add((String) tokens.nextElement());
main((String[]) list.toArray(new String[list.size()])); }
main(list.toArray(new String[list.size()]));
} }
public static String getLocationFromProperties(String key) { public static String getLocationFromProperties(String key) {

View file

@ -10,40 +10,29 @@
*******************************************************************************/ *******************************************************************************/
package org.eclipse.cdt.ui.testplugin.util; package org.eclipse.cdt.ui.testplugin.util;
import java.util.ArrayList; import java.util.ArrayList;
public class AccessibilityTestPass implements IDialogTestPass { public class AccessibilityTestPass implements IDialogTestPass {
private static final int CHECKLIST_SIZE = 5; private static final int CHECKLIST_SIZE = 5;
/**
* @see IDialogTestPass#title()
*/
@Override @Override
public String title() { public String title() {
return "Test Pass: Accessibility"; return "Test Pass: Accessibility";
} }
/**
* @see IDialogTestPass#description()
*/
@Override @Override
public String description() { public String description() {
return "Verify the accessibility of the dialogs."; return "Verify the accessibility of the dialogs.";
} }
/**
* @see IDialogTestPass#label()
*/
@Override @Override
public String label() { public String label() {
return "&Accessibility"; return "&Accessibility";
} }
/**
* @see IDialogTestPass#checkListTexts()
*/
@Override @Override
public ArrayList checkListTexts() { public ArrayList<String> checkListTexts() {
ArrayList list = new ArrayList(CHECKLIST_SIZE); ArrayList<String> list = new ArrayList<>(CHECKLIST_SIZE);
list.add("&1) all widgets are accessible by tabbing."); list.add("&1) all widgets are accessible by tabbing.");
list.add("&2) forwards and backwards tabbing is in a logical order"); list.add("&2) forwards and backwards tabbing is in a logical order");
list.add("&3) all the widgets with labels have an appropriate mnemonic."); list.add("&3) all the widgets with labels have an appropriate mnemonic.");
@ -51,11 +40,7 @@ public class AccessibilityTestPass implements IDialogTestPass {
list.add("&5) selectable widgets can be selected using the spacebar."); list.add("&5) selectable widgets can be selected using the spacebar.");
return list; return list;
} }
/**
* @see IDialogTestPass#failureTexts()
* Size of the return array must be the same size as the checkListTexts'
* ArrayList.
*/
@Override @Override
public String[] failureTexts() { public String[] failureTexts() {
String[] failureText = new String[CHECKLIST_SIZE]; String[] failureText = new String[CHECKLIST_SIZE];
@ -66,16 +51,12 @@ public class AccessibilityTestPass implements IDialogTestPass {
failureText[4] = "Some widgets cannot be selected using the spacebar."; failureText[4] = "Some widgets cannot be selected using the spacebar.";
return failureText; return failureText;
} }
/**
* @see IDialogTestPass#queryText()
*/
@Override @Override
public String queryText() { public String queryText() {
return "Is the accessibility of the dialog acceptable?"; return "Is the accessibility of the dialog acceptable?";
} }
/**
* @see IDialogTestPass#getID()
*/
@Override @Override
public int getID() { public int getID() {
return VerifyDialog.TEST_ACCESS; return VerifyDialog.TEST_ACCESS;

View file

@ -19,12 +19,9 @@ import java.util.Stack;
* in a structure/list, it will maintain a list of unfound/extra strings. * in a structure/list, it will maintain a list of unfound/extra strings.
*/ */
public class ExpectedStrings { public class ExpectedStrings {
public String [] expStrings; public String [] expStrings;
private boolean[] foundStrings; private boolean[] foundStrings;
private Stack extraStrings; /* A stack of the unecpected strings we private Stack<String> extraStrings; // A stack of the unexpected strings we received
* recieved
*/
private boolean extra; private boolean extra;
/** /**
@ -32,75 +29,71 @@ public class ExpectedStrings {
*/ */
public ExpectedStrings() { public ExpectedStrings() {
} }
/** /**
* Constructor for ExpectedStrings that accepts a list of strings that * Constructor for ExpectedStrings that accepts a list of strings that we expect to get.
* we expect to get.
*/ */
public ExpectedStrings(String[] values) { public ExpectedStrings(String[] values) {
int x;
expStrings=new String[values.length]; expStrings=new String[values.length];
for (x=0;x<values.length;x++) { for (int x = 0; x < values.length; x++) {
expStrings[x] = values[x]; expStrings[x] = values[x];
} }
foundStrings=new boolean[values.length]; foundStrings=new boolean[values.length];
for (x=0;x<values.length;x++) { for (int x = 0; x < values.length; x++) {
foundStrings[x] = false; foundStrings[x] = false;
} }
extraStrings=new Stack(); extraStrings = new Stack<>();
extra = false; extra = false;
} }
public int foundString(String current) { public int foundString(String current) {
int x; for (int x = 0; x < expStrings.length; x++) {
for (x=0;x<expStrings.length;x++) {
if (current.equals(expStrings[x])) { if (current.equals(expStrings[x])) {
foundStrings[x] = true; foundStrings[x] = true;
return(0); return 0;
} }
} }
/* If we arrive here, the strings was not found, so this is
* and extra string
*/
// If we arrive here, the strings was not found, so this is and extra string.
extraStrings.push(current); extraStrings.push(current);
extra= true; extra= true;
return(1); return 1;
} }
public int getNum(String name) { public int getNum(String name) {
int x; for (int x = 0; x < expStrings.length; x++) {
for (x=0;x<expStrings.length;x++) {
if (name.equals(expStrings[x])) if (name.equals(expStrings[x]))
return(x); return x;
} }
return(-1); return -1;
} }
public boolean gotAll() { public boolean gotAll() {
int x; for (int x = 0; x < expStrings.length; x++) {
for (x=0;x<expStrings.length;x++) { if (!foundStrings[x])
if (foundStrings[x]==false) return false;
return(false);
} }
return(true); return true;
} }
public boolean gotExtra() { public boolean gotExtra() {
return(extra); return extra;
} }
public String getMissingString() { public String getMissingString() {
int x; StringBuilder missing = new StringBuilder("Missing elements: ");
String missing = "Missing elements: "; for (int x = 0; x < expStrings.length; x++) {
for (x=0;x<expStrings.length;x++) { if (!foundStrings[x])
if (foundStrings[x]==false) missing.append(expStrings[x]).append(" ");
missing+=expStrings[x];
missing+=" ";
} }
return(missing); return missing.toString();
} }
public String getExtraString() { public String getExtraString() {
String extra= "Extra elements: "; StringBuilder extra = new StringBuilder("Extra elements: ");
while (!extraStrings.empty()) { while (!extraStrings.empty()) {
extra+=extraStrings.pop(); extra.append(extraStrings.pop()).append(" ");
extra+=" ";
} }
return(extra); return extra.toString();
} }
} }

View file

@ -13,13 +13,11 @@ package org.eclipse.cdt.ui.testplugin.util;
import java.util.ArrayList; import java.util.ArrayList;
/* /*
* This test pass verifies the initial focus of a dialog * This test pass verifies the initial focus of a dialog when it is given focus.
* when it is given focus.
*/ */
public class FocusTestPass implements IDialogTestPass { public class FocusTestPass implements IDialogTestPass {
private static final int CHECKLIST_SIZE = 1; private static final int CHECKLIST_SIZE = 1;
/** /**
* @see IDialogTestPass#title() * @see IDialogTestPass#title()
*/ */
@ -27,6 +25,7 @@ public class FocusTestPass implements IDialogTestPass {
public String title() { public String title() {
return "Test Pass: Initial Focus"; return "Test Pass: Initial Focus";
} }
/** /**
* @see IDialogTestPass#description() * @see IDialogTestPass#description()
*/ */
@ -34,6 +33,7 @@ public class FocusTestPass implements IDialogTestPass {
public String description() { public String description() {
return "Verify the initial focus of the dialogs."; return "Verify the initial focus of the dialogs.";
} }
/** /**
* @see IDialogTestPass#label() * @see IDialogTestPass#label()
*/ */
@ -41,15 +41,17 @@ public class FocusTestPass implements IDialogTestPass {
public String label() { public String label() {
return "&Initial Focus"; return "&Initial Focus";
} }
/** /**
* @see IDialogTestPass#checkListTexts() * @see IDialogTestPass#checkListTexts()
*/ */
@Override @Override
public ArrayList checkListTexts() { public ArrayList<String> checkListTexts() {
ArrayList list = new ArrayList(CHECKLIST_SIZE); ArrayList<String> list = new ArrayList<>(CHECKLIST_SIZE);
list.add("&1) the initial focus is appropriate."); list.add("&1) the initial focus is appropriate.");
return list; return list;
} }
/** /**
* @see IDialogTestPass#failureTexts() * @see IDialogTestPass#failureTexts()
* Size of the return array must be the same size as the checkListTexts' * Size of the return array must be the same size as the checkListTexts'
@ -61,6 +63,7 @@ public class FocusTestPass implements IDialogTestPass {
failureText[0] = "The initial focus is inappropriate."; failureText[0] = "The initial focus is inappropriate.";
return failureText; return failureText;
} }
/** /**
* @see IDialogTestPass#queryText() * @see IDialogTestPass#queryText()
*/ */
@ -68,6 +71,7 @@ public class FocusTestPass implements IDialogTestPass {
public String queryText() { public String queryText() {
return "Is the initial focus of the dialog correct?"; return "Is the initial focus of the dialog correct?";
} }
/** /**
* @see IDialogTestPass#getID() * @see IDialogTestPass#getID()
*/ */

View file

@ -10,46 +10,50 @@
*******************************************************************************/ *******************************************************************************/
package org.eclipse.cdt.ui.testplugin.util; package org.eclipse.cdt.ui.testplugin.util;
import java.util.ArrayList; import java.util.ArrayList;
/* /*
* Interface to describe a visual test pass for a dialog test. * Interface to describe a visual test pass for a dialog test.
*/ */
public interface IDialogTestPass { public interface IDialogTestPass {
/* /**
* @return String The title of the test pass. * @return String The title of the test pass.
*/ */
public String title(); public String title();
/*
/**
* @return String The description of the test pass. * @return String The description of the test pass.
*/ */
public String description(); public String description();
/*
/**
* @return String The label of the test pass to be used * @return String The label of the test pass to be used
* in a selection list. The return includes an '&' * in a selection list. The return includes an '&'
* if a mnemonic is desired. * if a mnemonic is desired.
*/ */
public String label(); public String label();
/*
/**
* @return ArrayList A list of items to appear in a checklist. * @return ArrayList A list of items to appear in a checklist.
* The items in the list must be Strings and should include an * The items in the list must be Strings and should include an
* '&' if a mnemonic is desired. * '&' if a mnemonic is desired.
*/ */
public ArrayList checkListTexts(); public ArrayList<String> checkListTexts();
/*
/**
* @return String[] Associated failure messages that correspond * @return String[] Associated failure messages that correspond
* to the checklist items. The size of this array should be the * to the checklist items. The size of this array should be the
* same size as the checklist. * same size as the checklist.
*/ */
public String[] failureTexts(); public String[] failureTexts();
/*
/**
* @return String The test that corresponds to the test pass to * @return String The test that corresponds to the test pass to
* which the tester will respond with a 'yes' or 'no'. * which the tester will respond with a 'yes' or 'no'.
*/ */
public String queryText(); public String queryText();
/*
/**
* @return int A unique number that identifies the test pass. * @return int A unique number that identifies the test pass.
*/ */
public int getID(); public int getID();

View file

@ -10,10 +10,8 @@
*******************************************************************************/ *******************************************************************************/
package org.eclipse.cdt.ui.testplugin.util; package org.eclipse.cdt.ui.testplugin.util;
import java.util.Iterator; import java.util.Iterator;
import org.eclipse.jface.dialogs.Dialog; import org.eclipse.jface.dialogs.Dialog;
import org.eclipse.jface.dialogs.IDialogConstants; import org.eclipse.jface.dialogs.IDialogConstants;
import org.eclipse.jface.dialogs.TitleAreaDialog; import org.eclipse.jface.dialogs.TitleAreaDialog;
@ -32,8 +30,7 @@ import org.eclipse.swt.widgets.Group;
import org.eclipse.swt.widgets.Label; import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Shell; import org.eclipse.swt.widgets.Shell;
/**
/*
* This dialog is intended to verify a dialogs in a testing * This dialog is intended to verify a dialogs in a testing
* environment. The tester can test for sizing, initial focus, * environment. The tester can test for sizing, initial focus,
* or accessibility. * or accessibility.
@ -57,8 +54,8 @@ public class VerifyDialog extends TitleAreaDialog {
private Button _checkList[]; private Button _checkList[];
private String _failureText; private String _failureText;
/* /**
* Create an instance of the verification dialog. * Creates an instance of the verification dialog.
*/ */
public VerifyDialog(Shell parent) { public VerifyDialog(Shell parent) {
super(parent); super(parent);
@ -71,26 +68,19 @@ public class VerifyDialog extends TitleAreaDialog {
_dialogTests[2] = new AccessibilityTestPass(); _dialogTests[2] = new AccessibilityTestPass();
} }
/* (non-Javadoc)
* Method declared on Window.
*/
@Override @Override
protected void configureShell(Shell newShell) { protected void configureShell(Shell newShell) {
super.configureShell(newShell); super.configureShell(newShell);
newShell.setText("Dialog Verification"); newShell.setText("Dialog Verification");
setShellStyle(SWT.NONE); setShellStyle(SWT.NONE);
} }
/* (non-Javadoc)
* Method declared on Dialog.
*/
@Override @Override
protected void createButtonsForButtonBar(Composite parent) { protected void createButtonsForButtonBar(Composite parent) {
_yesButton = createButton(parent, IDialogConstants.YES_ID, IDialogConstants.YES_LABEL, true); _yesButton = createButton(parent, IDialogConstants.YES_ID, IDialogConstants.YES_LABEL, true);
_noButton = createButton(parent, IDialogConstants.NO_ID, IDialogConstants.NO_LABEL, false); _noButton = createButton(parent, IDialogConstants.NO_ID, IDialogConstants.NO_LABEL, false);
} }
/* (non-Javadoc)
* Method declared on Dialog.
*/
@Override @Override
protected void buttonPressed(int buttonId) { protected void buttonPressed(int buttonId) {
if (IDialogConstants.YES_ID == buttonId) { if (IDialogConstants.YES_ID == buttonId) {
@ -103,15 +93,12 @@ public class VerifyDialog extends TitleAreaDialog {
handleFailure(); handleFailure();
} }
} }
/* (non-Javadoc)
* Method declared on Dialog.
*/
@Override @Override
protected Control createDialogArea(Composite parent) { protected Control createDialogArea(Composite parent) {
// top level composite // top level composite
Composite parentComposite = (Composite)super.createDialogArea(parent); Composite parentComposite = (Composite)super.createDialogArea(parent);
// create a composite with standard margins and spacing // create a composite with standard margins and spacing
Composite composite = new Composite(parentComposite, SWT.NONE); Composite composite = new Composite(parentComposite, SWT.NONE);
composite.setSize(SIZING_WIDTH, SWT.DEFAULT); composite.setSize(SIZING_WIDTH, SWT.DEFAULT);
@ -123,11 +110,9 @@ public class VerifyDialog extends TitleAreaDialog {
composite.setLayout(layout); composite.setLayout(layout);
composite.setLayoutData(new GridData(GridData.FILL_BOTH)); composite.setLayoutData(new GridData(GridData.FILL_BOTH));
createTestSelectionGroup(composite); createTestSelectionGroup(composite);
createCheckListGroup(composite); createCheckListGroup(composite);
_queryLabel = new Label(composite, SWT.NONE); _queryLabel = new Label(composite, SWT.NONE);
_queryLabel.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); _queryLabel.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
@ -206,14 +191,15 @@ public class VerifyDialog extends TitleAreaDialog {
} }
_yesButton.setEnabled(enable); _yesButton.setEnabled(enable);
} }
/*
/**
* Initializes the checklist, banner texts, and query label * Initializes the checklist, banner texts, and query label
*/ */
void initializeTest() { void initializeTest() {
IDialogTestPass test = _dialogTests[TEST_TYPE]; IDialogTestPass test = _dialogTests[TEST_TYPE];
setTitle( test.title() ); setTitle( test.title() );
setMessage( test.description() ); setMessage( test.description() );
Iterator iterator = test.checkListTexts().iterator(); Iterator<String> iterator = test.checkListTexts().iterator();
for (int i = 0; i < _checkList.length; i++) { for (int i = 0; i < _checkList.length; i++) {
if (iterator.hasNext()) { if (iterator.hasNext()) {
_checkList[i].setText( iterator.next().toString() ); _checkList[i].setText( iterator.next().toString() );
@ -227,21 +213,23 @@ public class VerifyDialog extends TitleAreaDialog {
} }
_queryLabel.setText( test.queryText() ); _queryLabel.setText( test.queryText() );
} }
public String getFailureText() { public String getFailureText() {
return _failureText; return _failureText;
} }
/*
/**
* Can't open the verification dialog without a specified * Can't open the verification dialog without a specified
* test dialog, this simply returns a failure and prevents * test dialog, this simply returns a failure and prevents
* opening. Should use open(Dialog) instead. * opening. Should use open(Dialog) instead.
*
*/ */
@Override @Override
public int open() { public int open() {
_failureText = "Testing dialog is required, use VerifyDialog::open(Dialog)"; _failureText = "Testing dialog is required, use VerifyDialog::open(Dialog)";
return IDialogConstants.NO_ID; return IDialogConstants.NO_ID;
} }
/*
/**
* Opens the verification dialog to test the specified dialog. * Opens the verification dialog to test the specified dialog.
*/ */
public int open(Dialog testDialog) { public int open(Dialog testDialog) {
@ -259,7 +247,8 @@ public class VerifyDialog extends TitleAreaDialog {
return super.open(); return super.open();
} }
/*
/**
* Opens the dialog to be verified. * Opens the dialog to be verified.
*/ */
private void openNewTestDialog() { private void openNewTestDialog() {
@ -278,7 +267,8 @@ public class VerifyDialog extends TitleAreaDialog {
}); });
_testDialog.open(); _testDialog.open();
} }
/*
/**
* The test dialog failed, open the failure dialog. * The test dialog failed, open the failure dialog.
*/ */
private void handleFailure() { private void handleFailure() {
@ -287,10 +277,10 @@ public class VerifyDialog extends TitleAreaDialog {
String label = test.label(); String label = test.label();
label = label.substring(0, label.indexOf("&")) + label = label.substring(0, label.indexOf("&")) +
label.substring(label.indexOf("&") + 1); label.substring(label.indexOf("&") + 1);
text.append(label). text.append(label)
append(" failed on the "). .append(" failed on the ")
append(SWT.getPlatform()). .append(SWT.getPlatform())
append(" platform:\n"); .append(" platform:\n");
String failureMessages[] = test.failureTexts(); String failureMessages[] = test.failureTexts();
for (int i = 0; i < test.checkListTexts().size(); i++) { for (int i = 0; i < test.checkListTexts().size(); i++) {
@ -300,7 +290,6 @@ public class VerifyDialog extends TitleAreaDialog {
} }
FailureDialog dialog = new FailureDialog( getShell() ); FailureDialog dialog = new FailureDialog( getShell() );
dialog.create(); dialog.create();
//String temp = text.toString();
dialog.setText( text.toString() ); dialog.setText( text.toString() );
if (dialog.open() == IDialogConstants.OK_ID) { if (dialog.open() == IDialogConstants.OK_ID) {
_failureText = dialog.toString(); _failureText = dialog.toString();
@ -311,9 +300,9 @@ public class VerifyDialog extends TitleAreaDialog {
close(); close();
} }
} }
/*
* In case the shell was closed by a means other than /**
* the NO button. * In case the shell was closed by a means other than the NO button.
*/ */
@Override @Override
protected void handleShellCloseEvent() { protected void handleShellCloseEvent() {

View file

@ -10,6 +10,8 @@
**********************************************************************/ **********************************************************************/
package org.eclipse.cdt.ui.tests.chelp; package org.eclipse.cdt.ui.tests.chelp;
import static org.eclipse.cdt.ui.tests.chelp.CHelpTest.fail;
import java.io.ByteArrayInputStream; import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream; import java.io.ByteArrayOutputStream;
import java.io.IOException; import java.io.IOException;
@ -17,20 +19,21 @@ import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Properties; import java.util.Properties;
import junit.framework.Assert; import org.eclipse.core.runtime.IConfigurationElement;
import org.eclipse.core.runtime.Platform;
import org.eclipse.help.IHelpResource;
import org.junit.Assert;
import org.eclipse.cdt.internal.ui.CHelpProviderManager;
import org.eclipse.cdt.internal.ui.text.CHelpBookDescriptor;
import org.eclipse.cdt.internal.ui.text.CHelpSettings;
import org.eclipse.cdt.ui.CUIPlugin; import org.eclipse.cdt.ui.CUIPlugin;
import org.eclipse.cdt.ui.ICHelpBook; import org.eclipse.cdt.ui.ICHelpBook;
import org.eclipse.cdt.ui.ICHelpResourceDescriptor; import org.eclipse.cdt.ui.ICHelpResourceDescriptor;
import org.eclipse.cdt.ui.IFunctionSummary; import org.eclipse.cdt.ui.IFunctionSummary;
import org.eclipse.cdt.ui.IRequiredInclude; import org.eclipse.cdt.ui.IRequiredInclude;
import org.eclipse.cdt.ui.text.ICHelpInvocationContext; import org.eclipse.cdt.ui.text.ICHelpInvocationContext;
import org.eclipse.core.runtime.IConfigurationElement;
import org.eclipse.core.runtime.Platform; import org.eclipse.cdt.internal.ui.CHelpProviderManager;
import org.eclipse.help.IHelpResource; import org.eclipse.cdt.internal.ui.text.CHelpBookDescriptor;
import org.eclipse.cdt.internal.ui.text.CHelpSettings;
/** /**
* *
@ -42,7 +45,7 @@ public class CHelpProviderTester{
private static final String KEY_BOOK_TYPE = "bookType"; private static final String KEY_BOOK_TYPE = "bookType";
private Properties fProperties; private Properties fProperties;
private static CHelpProviderTester fDefaultInstance = null; private static CHelpProviderTester fDefaultInstance;
private CHelpProviderTester() { private CHelpProviderTester() {
} }
@ -111,7 +114,6 @@ public class CHelpProviderTester{
} }
private class FunctionSummary implements IFunctionSummary { private class FunctionSummary implements IFunctionSummary {
private String fName = "Name"; private String fName = "Name";
private String fReturnType = "ReturnType"; private String fReturnType = "ReturnType";
private String fPrototype = "Prototype"; private String fPrototype = "Prototype";
@ -143,36 +145,48 @@ public class CHelpProviderTester{
public class FunctionPrototypeSummary implements IFunctionPrototypeSummary { public class FunctionPrototypeSummary implements IFunctionPrototypeSummary {
@Override @Override
public String getName() { return fName; } public String getName() {
return fName;
}
@Override @Override
public String getReturnType() { return fReturnType; } public String getReturnType() {
return fReturnType;
}
@Override @Override
public String getArguments() { return fPrototype; } public String getArguments() {
return fPrototype;
}
@Override @Override
public String getPrototypeString(boolean namefirst) { public String getPrototypeString(boolean namefirst) {
if (true == namefirst) { if (true == namefirst) {
return fName + " (" + fPrototype + ") " + fReturnType; return fName + " (" + fPrototype + ") " + fReturnType;
} } else {
else {
return fReturnType + " " + fName + " (" + fPrototype + ")"; return fReturnType + " " + fName + " (" + fPrototype + ")";
} }
} }
} }
@Override @Override
public String getName() { return fName; } public String getName() {
return fName;
}
@Override @Override
public String getNamespace() { return "dummy namespace"; } public String getNamespace() {
return "dummy namespace";
}
@Override @Override
public String getDescription() { return fSummary; } public String getDescription() {
return fSummary;
}
@Override @Override
public IFunctionPrototypeSummary getPrototype() { return new FunctionPrototypeSummary(); } public IFunctionPrototypeSummary getPrototype() {
return new FunctionPrototypeSummary();
}
@Override @Override
public IRequiredInclude[] getIncludes() { public IRequiredInclude[] getIncludes() {
return incs; return incs;
} }
} }
private static String generateHelpString(ICHelpBook helpBook, String name, String providerID) { private static String generateHelpString(ICHelpBook helpBook, String name, String providerID) {
@ -183,8 +197,8 @@ public class CHelpProviderTester{
ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
try { try {
props.store(outputStream, null); props.store(outputStream, null);
} } catch (IOException e) {
catch(Exception e){ fail(e);
} }
return outputStream.toString(); return outputStream.toString();
} }
@ -196,21 +210,19 @@ public class CHelpProviderTester{
ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
try { try {
props.store(outputStream, null); props.store(outputStream, null);
} } catch (IOException e) {
catch(Exception e){ fail(e);
} }
return outputStream.toString(); return outputStream.toString();
} }
private CHelpProviderTester(String string) throws IOException{ private CHelpProviderTester(String string) {
fProperties = new Properties(); fProperties = new Properties();
ByteArrayInputStream stream = new ByteArrayInputStream(string.getBytes()); ByteArrayInputStream stream = new ByteArrayInputStream(string.getBytes());
try { try {
fProperties.load(stream); fProperties.load(stream);
} catch (IOException e) { } catch (IOException e) {
//TODO: handle fail(e);
throw e;
} }
} }
@ -234,7 +246,8 @@ public class CHelpProviderTester{
} }
public boolean onlyTestInfoProvidersAvailable() { public boolean onlyTestInfoProvidersAvailable() {
IConfigurationElement configElements[] = Platform.getExtensionRegistry().getConfigurationElementsFor(CUIPlugin.PLUGIN_ID, CHelpSettings.CONTRIBUTION_EXTENSION); IConfigurationElement configElements[] = Platform.getExtensionRegistry().getConfigurationElementsFor(
CUIPlugin.PLUGIN_ID, CHelpSettings.CONTRIBUTION_EXTENSION);
int numExts = 0; int numExts = 0;
for (int i = 0; i < configElements.length; i++) { for (int i = 0; i < configElements.length; i++) {
String id = configElements[i].getAttribute("id"); String id = configElements[i].getAttribute("id");
@ -278,7 +291,8 @@ public class CHelpProviderTester{
CHelpBookDescriptor bookDes[] = CHelpProviderManager.getDefault().getCHelpBookDescriptors(context); CHelpBookDescriptor bookDes[] = CHelpProviderManager.getDefault().getCHelpBookDescriptors(context);
for (int i = 0; i < data.length; i++) { for (int i = 0; i < data.length; i++) {
CHelpProviderTester tester = data[i]; CHelpProviderTester tester = data[i];
Assert.assertTrue("the name passed to CHelpProvider (" + tester.getRequestedName() + ") differs prom tha name passed to manager (" + name + ")",name.equals(tester.getRequestedName())); Assert.assertTrue("the name passed to CHelpProvider (" + tester.getRequestedName()
+ ") differs prom tha name passed to manager (" + name + ")", name.equals(tester.getRequestedName()));
String bookTitle = tester.getBookTitle(); String bookTitle = tester.getBookTitle();
int j = 0; int j = 0;
for (; j < bookDes.length; j++) { for (; j < bookDes.length; j++) {
@ -305,46 +319,34 @@ public class CHelpProviderTester{
} }
} }
public void checkHelpResources(ICHelpResourceDescriptor helpDescriptors[], ICHelpInvocationContext context, String name){ public void checkHelpResources(ICHelpResourceDescriptor helpDescriptors[], ICHelpInvocationContext context,
String name) {
if (helpDescriptors == null || helpDescriptors.length == 0) if (helpDescriptors == null || helpDescriptors.length == 0)
return; return;
List dataList = new ArrayList(helpDescriptors.length); List<CHelpProviderTester> dataList = new ArrayList<>(helpDescriptors.length);
for (int i = 0; i < helpDescriptors.length; i++) { for (int i = 0; i < helpDescriptors.length; i++) {
try{
dataList.add(new CHelpProviderTester(helpDescriptors[i].getHelpResources()[0].getLabel())); dataList.add(new CHelpProviderTester(helpDescriptors[i].getHelpResources()[0].getLabel()));
}catch(IOException e){
Assert.fail("checkHelpResources failed to instantiate CHelpProviderTester, IOException occured: " + e.getMessage());
} }
} if (!dataList.isEmpty())
if(dataList.size() > 0) checkResponse(dataList.toArray(new CHelpProviderTester[dataList.size()]), context, name, true);
checkResponse((CHelpProviderTester[])dataList.toArray(new CHelpProviderTester[dataList.size()]), context, name, true);
} }
public void checkMatchingFunctions(IFunctionSummary summaries[], ICHelpInvocationContext context, String name) { public void checkMatchingFunctions(IFunctionSummary summaries[], ICHelpInvocationContext context, String name) {
if (summaries == null || summaries.length == 0) if (summaries == null || summaries.length == 0)
return; return;
List dataList = new ArrayList(summaries.length); List<CHelpProviderTester> dataList = new ArrayList<>(summaries.length);
for (int i = 0; i < summaries.length; i++) { for (int i = 0; i < summaries.length; i++) {
try{
dataList.add(new CHelpProviderTester(summaries[i].getDescription())); dataList.add(new CHelpProviderTester(summaries[i].getDescription()));
}catch(IOException e){
Assert.fail("checkMatchingFunctions failed to instantiate CHelpProviderTester, IOException occured: " + e.getMessage());
} }
} if (!dataList.isEmpty())
if(dataList.size() > 0) checkResponse(dataList.toArray(new CHelpProviderTester[dataList.size()]), context, name, true);
checkResponse((CHelpProviderTester[])dataList.toArray(new CHelpProviderTester[dataList.size()]), context, name, true);
} }
public void checkFunctionInfo(IFunctionSummary summary, ICHelpInvocationContext context, String name) { public void checkFunctionInfo(IFunctionSummary summary, ICHelpInvocationContext context, String name) {
if (summary == null) if (summary == null)
return; return;
CHelpProviderTester data[] = new CHelpProviderTester[1]; CHelpProviderTester data[] = new CHelpProviderTester[1];
try{
data[0] = new CHelpProviderTester(summary.getDescription()); data[0] = new CHelpProviderTester(summary.getDescription());
checkResponse(data, context, name, false); checkResponse(data, context, name, false);
}catch(IOException e){
Assert.fail("checkFunctionInfo failed to instantiate CHelpProviderTester, IOException occured: " + e.getMessage());
}
} }
} }

View file

@ -10,14 +10,14 @@
*******************************************************************************/ *******************************************************************************/
package org.eclipse.cdt.ui.tests.chelp; package org.eclipse.cdt.ui.tests.chelp;
import junit.framework.Test; import java.io.PrintWriter;
import junit.framework.TestCase; import java.io.StringWriter;
import junit.framework.TestSuite;
import org.eclipse.core.resources.IProject; import org.eclipse.core.resources.IProject;
import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IConfigurationElement; import org.eclipse.core.runtime.IConfigurationElement;
import org.eclipse.core.runtime.Platform; import org.eclipse.core.runtime.Platform;
import org.junit.Assert;
import org.eclipse.cdt.core.dom.IPDOMManager; import org.eclipse.cdt.core.dom.IPDOMManager;
import org.eclipse.cdt.core.model.ICProject; import org.eclipse.cdt.core.model.ICProject;
@ -33,6 +33,10 @@ import org.eclipse.cdt.internal.ui.CHelpProviderManager;
import org.eclipse.cdt.internal.ui.text.CHelpBookDescriptor; import org.eclipse.cdt.internal.ui.text.CHelpBookDescriptor;
import org.eclipse.cdt.internal.ui.text.CHelpSettings; import org.eclipse.cdt.internal.ui.text.CHelpSettings;
import junit.framework.Test;
import junit.framework.TestCase;
import junit.framework.TestSuite;
/** /**
* *
* CHelpProvider tests * CHelpProvider tests
@ -141,7 +145,7 @@ public class CHelpTest extends TestCase {
assertTrue("number of provider instances created (" + CHelpTestInfoProvider.getNumProviders() + ") is not equal to number of extensions (" + numExts + ")",numExts == CHelpTestInfoProvider.getNumProviders()); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ assertTrue("number of provider instances created (" + CHelpTestInfoProvider.getNumProviders() + ") is not equal to number of extensions (" + numExts + ")",numExts == CHelpTestInfoProvider.getNumProviders()); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
} catch (CoreException e) { } catch (CoreException e) {
fail("CoreException occured: " + e.getMessage()); //$NON-NLS-1$ fail(e);
} }
} }
@ -160,15 +164,14 @@ public class CHelpTest extends TestCase {
summaries = CHelpProviderManager.getDefault().getMatchingFunctions(ccContext, requestedName); summaries = CHelpProviderManager.getDefault().getMatchingFunctions(ccContext, requestedName);
CHelpProviderTester.getDefault().checkMatchingFunctions(summaries, ccContext, requestedName); CHelpProviderTester.getDefault().checkMatchingFunctions(summaries, ccContext, requestedName);
} } catch (CoreException e) {
catch(CoreException e){ fail(e);
fail("CoreException occured: " + e.getMessage()); //$NON-NLS-1$
} }
} }
public void testGetFunctionInfo() { public void testGetFunctionInfo() {
if (!CHelpProviderTester.getDefault().onlyTestInfoProvidersAvailable()) { if (!CHelpProviderTester.getDefault().onlyTestInfoProvidersAvailable()) {
//this test assumes that only CHelpTestInfoProviders are available // This test assumes that only CHelpTestInfoProviders are available.
return; return;
} }
try { try {
@ -181,8 +184,7 @@ public class CHelpTest extends TestCase {
summary = CHelpProviderManager.getDefault().getFunctionInfo(ccContext, requestedName); summary = CHelpProviderManager.getDefault().getFunctionInfo(ccContext, requestedName);
CHelpProviderTester.getDefault().checkFunctionInfo(summary, ccContext, requestedName); CHelpProviderTester.getDefault().checkFunctionInfo(summary, ccContext, requestedName);
} } catch (CoreException e) {
catch(CoreException e){
fail("CoreException occured: " + e.getMessage()); //$NON-NLS-1$ fail("CoreException occured: " + e.getMessage()); //$NON-NLS-1$
} }
} }
@ -202,8 +204,7 @@ public class CHelpTest extends TestCase {
resourceDes = CHelpProviderManager.getDefault().getHelpResources(ccContext, requestedName); resourceDes = CHelpProviderManager.getDefault().getHelpResources(ccContext, requestedName);
CHelpProviderTester.getDefault().checkHelpResources(resourceDes, ccContext, requestedName); CHelpProviderTester.getDefault().checkHelpResources(resourceDes, ccContext, requestedName);
} } catch (CoreException e) {
catch(CoreException e){
fail("CoreException occured: " + e.getMessage()); //$NON-NLS-1$ fail("CoreException occured: " + e.getMessage()); //$NON-NLS-1$
} }
} }
@ -240,9 +241,16 @@ public class CHelpTest extends TestCase {
assertTrue("book \"" + curBookDes.getCHelpBook().getTitle() + "\" of type HELP_TYPE_C was not found in C books", //$NON-NLS-1$ //$NON-NLS-2$ assertTrue("book \"" + curBookDes.getCHelpBook().getTitle() + "\" of type HELP_TYPE_C was not found in C books", //$NON-NLS-1$ //$NON-NLS-2$
j < cBookDescriptors.length || curBookDes.getCHelpBook().getCHelpType() == ICHelpBook.HELP_TYPE_CPP); j < cBookDescriptors.length || curBookDes.getCHelpBook().getCHelpType() == ICHelpBook.HELP_TYPE_CPP);
} }
} } catch (CoreException e) {
catch(CoreException e){
fail("CoreException occured: " + e.getMessage()); //$NON-NLS-1$ fail("CoreException occured: " + e.getMessage()); //$NON-NLS-1$
} }
} }
static void fail(Throwable t) {
StringWriter stringWriter = new StringWriter();
PrintWriter printWriter = new PrintWriter(stringWriter);
printWriter.println(t);
t.printStackTrace(printWriter);
Assert.fail(stringWriter.toString());
}
} }

View file

@ -10,7 +10,7 @@
**********************************************************************/ **********************************************************************/
package org.eclipse.cdt.ui.tests.chelp; package org.eclipse.cdt.ui.tests.chelp;
import junit.framework.Assert; import org.junit.Assert;
import org.eclipse.cdt.ui.ICHelpBook; import org.eclipse.cdt.ui.ICHelpBook;
import org.eclipse.cdt.ui.ICHelpProvider; import org.eclipse.cdt.ui.ICHelpProvider;
@ -19,15 +19,14 @@ import org.eclipse.cdt.ui.IFunctionSummary;
import org.eclipse.cdt.ui.text.ICHelpInvocationContext; import org.eclipse.cdt.ui.text.ICHelpInvocationContext;
/** /**
* * This class implements ICHelpProvider and provides test information
* this class implements ICHelpProvider and provides test information
*/ */
public class CHelpTestInfoProvider implements ICHelpProvider { public class CHelpTestInfoProvider implements ICHelpProvider {
private static int fNumProviders = 0; private static int fNumProviders = 0;
private static final String PROVIDER_ID_PREFIX = "TestInfoProvider_"; private static final String PROVIDER_ID_PREFIX = "TestInfoProvider_";
final private String fProviderID; final private String fProviderID;
private boolean fIsInitialized = false; private boolean fIsInitialized;
private ICHelpBook fCHelpBooks[]; private ICHelpBook fCHelpBooks[];
@ -46,18 +45,12 @@ public class CHelpTestInfoProvider implements ICHelpProvider {
return fNumProviders; return fNumProviders;
} }
/* (non-Javadoc)
* @see org.eclipse.cdt.ui.ICHelpProvider#initialize()
*/
@Override @Override
public void initialize() { public void initialize() {
Assert.assertFalse("initialize is called several times", fIsInitialized); Assert.assertFalse("initialize is called several times", fIsInitialized);
fIsInitialized = true; fIsInitialized = true;
} }
/* (non-Javadoc)
* @see org.eclipse.cdt.ui.ICHelpProvider#getCHelpBooks()
*/
@Override @Override
public ICHelpBook[] getCHelpBooks() { public ICHelpBook[] getCHelpBooks() {
if (!fgEnabled) { if (!fgEnabled) {
@ -67,12 +60,8 @@ public class CHelpTestInfoProvider implements ICHelpProvider {
return fCHelpBooks; return fCHelpBooks;
} }
/* (non-Javadoc)
* @see org.eclipse.cdt.ui.ICHelpProvider#getFunctionInfo(org.eclipse.cdt.ui.text.ICHelpInvocationContext, org.eclipse.cdt.ui.ICHelpBook[], java.lang.String)
*/
@Override @Override
public IFunctionSummary getFunctionInfo(ICHelpInvocationContext context, public IFunctionSummary getFunctionInfo(ICHelpInvocationContext context, ICHelpBook[] helpBooks, String name) {
ICHelpBook[] helpBooks, String name) {
if (!fgEnabled) { if (!fgEnabled) {
return null; return null;
} }
@ -80,9 +69,6 @@ public class CHelpTestInfoProvider implements ICHelpProvider {
return CHelpProviderTester.getDefault().generateFunctionInfo(helpBooks, name, fProviderID); return CHelpProviderTester.getDefault().generateFunctionInfo(helpBooks, name, fProviderID);
} }
/* (non-Javadoc)
* @see org.eclipse.cdt.ui.ICHelpProvider#getMatchingFunctions(org.eclipse.cdt.ui.text.ICHelpInvocationContext, org.eclipse.cdt.ui.ICHelpBook[], java.lang.String)
*/
@Override @Override
public IFunctionSummary[] getMatchingFunctions( public IFunctionSummary[] getMatchingFunctions(
ICHelpInvocationContext context, ICHelpBook[] helpBooks, ICHelpInvocationContext context, ICHelpBook[] helpBooks,
@ -95,12 +81,9 @@ public class CHelpTestInfoProvider implements ICHelpProvider {
//return CHelpProviderTester.getDefault().generateMatchingFunctions(helpBooks, prefix, fProviderID); //return CHelpProviderTester.getDefault().generateMatchingFunctions(helpBooks, prefix, fProviderID);
} }
/* (non-Javadoc)
* @see org.eclipse.cdt.ui.ICHelpProvider#getHelpResources(org.eclipse.cdt.ui.text.ICHelpInvocationContext, org.eclipse.cdt.ui.ICHelpBook[], java.lang.String)
*/
@Override @Override
public ICHelpResourceDescriptor[] getHelpResources( public ICHelpResourceDescriptor[] getHelpResources(ICHelpInvocationContext context, ICHelpBook[] helpBooks,
ICHelpInvocationContext context, ICHelpBook[] helpBooks, String name) { String name) {
if (!fgEnabled) { if (!fgEnabled) {
return new ICHelpResourceDescriptor[0]; return new ICHelpResourceDescriptor[0];
} }