1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-07-31 21:05:37 +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

@ -6,46 +6,36 @@
* http://www.eclipse.org/legal/epl-v10.html * http://www.eclipse.org/legal/epl-v10.html
* *
* Contributors: * Contributors:
* IBM - Initial API and implementation * IBM - Initial API and implementation
*******************************************************************************/ *******************************************************************************/
package org.eclipse.cdt.core.testplugin.util; 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

@ -6,109 +6,107 @@
* http://www.eclipse.org/legal/epl-v10.html * http://www.eclipse.org/legal/epl-v10.html
* *
* Contributors: * Contributors:
* IBM - Initial API and implementation * IBM - Initial API and implementation
*******************************************************************************/ *******************************************************************************/
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.
*/ */
protected String application; protected String application;
/** /**
* The path for finding find plugins. * The path for finding find plugins.
*/ */
protected URL pluginPathLocation; protected URL pluginPathLocation;
/** /**
* The boot path location. * The boot path location.
*/ */
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;
/** /**
* The item to be uninstalled. * The item to be uninstalled.
*/ */
protected String uninstallCookie; protected String uninstallCookie;
/** /**
* 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$
private static final String BOOT = "-boot"; //$NON-NLS-1$ private static final String BOOT = "-boot"; //$NON-NLS-1$
@ -120,7 +118,7 @@ public class Main {
private static final String BOOTLOADER = "org.eclipse.core.boot.BootLoader"; //$NON-NLS-1$ private static final String BOOTLOADER = "org.eclipse.core.boot.BootLoader"; //$NON-NLS-1$
private static final String UPDATELOADER = "org.eclipse.core.internal.boot.LaunchInfo"; //$NON-NLS-1$ private static final String UPDATELOADER = "org.eclipse.core.internal.boot.LaunchInfo"; //$NON-NLS-1$
// The project containing the boot loader code. This is used to construct // The project containing the boot loader code. This is used to construct
// the correct class path for running in VAJ and VAME. // the correct class path for running in VAJ and VAME.
private static final String PROJECT_NAME = "Eclipse Core Boot"; //$NON-NLS-1$ private static final String PROJECT_NAME = "Eclipse Core Boot"; //$NON-NLS-1$
@ -143,387 +141,411 @@ 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$
try { new Class[] { String.class, URL.class, String.class, String[].class });
return method.invoke(clazz, new Object[] { application, pluginPathLocation, location, args }); try {
} catch (InvocationTargetException e) { return method.invoke(clazz, new Object[] { application, pluginPathLocation, location, args });
if (e.getTargetException() instanceof Error) } catch (InvocationTargetException e) {
throw (Error) e.getTargetException(); if (e.getTargetException() instanceof Error)
throw e; throw (Error) e.getTargetException();
throw e;
}
} }
}
/** /**
* 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.toArray(new String[0]);
} }
return list.isEmpty() ? new String[0] : (String[]) list.toArray(new String[0]);
} /**
/** * Creates and returns a platform <code>BootLoader</code> which can be used
* Creates and returns a platform <code>BootLoader</code> which can be used to start * to start up and run the platform. The given base, if not
* up and run the platform. The given base, if not <code>null</code>, * <code>null</code>, is the location of the boot loader code. If the value
* is the location of the boot loader code. If the value is <code>null</code> * is <code>null</code> then the boot loader is located relative to this
* then the boot loader is located relative to this class. * 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
* are located when running in development mode. /**
* * Returns the <code>URL</code>-based class path describing where the boot
* @return the url-based class path * classes are located when running in development mode.
* @param base the base location *
* @exception MalformedURLException if a problem occurs computing the class path * @param base the base location
*/ * @return the url-based class path
protected URL[] getDevPath(URL base) throws MalformedURLException { * @exception MalformedURLException if a problem occurs computing the class path
URL url; */
String devBase = base.toExternalForm(); protected URL[] getDevPath(URL base) throws MalformedURLException {
if (!inDevelopmentMode) { URL url;
String devBase = base.toExternalForm();
if (!inDevelopmentMode) {
url = new URL(devBase + "boot.jar"); //$NON-NLS-1$
return new URL[] { url };
}
String[] locations = getArrayFromList(devClassPath);
ArrayList<URL> result = new ArrayList<>(locations.length);
for (int i = 0; i < locations.length; i++) {
String spec = devBase + locations[i];
char lastChar = spec.charAt(spec.length() - 1);
if ((spec.endsWith(".jar") || (lastChar == '/' || lastChar == '\\'))) { //$NON-NLS-1$
url = new URL(spec);
} else {
url = new URL(spec + "/"); //$NON-NLS-1$
}
// make sure URL exists before adding to path
if (new java.io.File(url.getFile()).exists())
result.add(url);
}
url = new URL(devBase + "boot.jar"); //$NON-NLS-1$ url = new URL(devBase + "boot.jar"); //$NON-NLS-1$
return new URL[] {url};
}
String[] locations = getArrayFromList(devClassPath);
ArrayList result = new ArrayList(locations.length);
for (int i = 0; i < locations.length; i++) {
String spec = devBase + locations[i];
char lastChar = spec.charAt(spec.length() - 1);
if ((spec.endsWith(".jar") || (lastChar == '/' || lastChar == '\\'))) //$NON-NLS-1$
url = new URL (spec);
else
url = new URL(spec + "/"); //$NON-NLS-1$
//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);
return result.toArray(new URL[result.size()]);
} }
url = new URL(devBase + "boot.jar"); //$NON-NLS-1$
if (new java.io.File(url.getFile()).exists())
result.add(url);
return (URL[])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
* @exception MalformedURLException if a problem occurs computing the class path * @return the url-based class path
*/ * @exception MalformedURLException if a problem occurs computing the class path
protected URL[] getBootPath(String base) throws MalformedURLException { */
URL url = null; protected URL[] getBootPath(String base) throws MalformedURLException {
// if the given location is not null, assume it is correct and use it. URL url = null;
if (base != null) { // if the given location is not null, assume it is correct and use it.
url = new URL(base); if (base != null) {
if (debug) url = new URL(base);
System.out.println("Boot URL: " + url.toExternalForm()); //$NON-NLS-1$ if (debug)
return new URL[] {url}; System.out.println("Boot URL: " + url.toExternalForm()); //$NON-NLS-1$
} return new URL[] { url };
// Create a URL based on the location of this class' code.
// strip off jar file and/or last directory to get
// to the directory containing projects.
URL[] result = null;
url = getClass().getProtectionDomain().getCodeSource().getLocation();
String path = url.getFile();
if (path.endsWith(".jar")) //$NON-NLS-1$
path = path.substring(0, path.lastIndexOf("/")); //$NON-NLS-1$
else
if (path.endsWith("/")) //$NON-NLS-1$
path = path.substring(0, path.length() - 1);
if (inVAJ || inVAME) {
int ix = path.lastIndexOf("/"); //$NON-NLS-1$
path = path.substring(0, ix + 1);
path = path + PROJECT_NAME + "/"; //$NON-NLS-1$
url = new URL(url.getProtocol(), url.getHost(), url.getPort(), path);
result = new URL[] {url};
} else {
path = searchForPlugins(path);
path = searchForBoot(path);
// add on any dev path elements
url = new URL(url.getProtocol(), url.getHost(), url.getPort(), path);
result = getDevPath(url);
}
if (debug) {
System.out.println("Boot URL:"); //$NON-NLS-1$
for (int i = 0; i < result.length; i++)
System.out.println(" " + result[i].toExternalForm()); //$NON-NLS-1$
}
return result;
}
/**
* Searches for a plugins root starting at a given location. If one is
* found then this location is returned; otherwise an empty string is
* returned.
*
* @return the location where plugins were found, or an empty string
* @param start the location to begin searching at
*/
protected String searchForPlugins(String start) {
File path = new File(start);
while (path != null) {
File test = new File(path, "plugins"); //$NON-NLS-1$
if (test.exists())
return test.toString();
path = path.getParentFile();
path = (path == null || path.length() == 1) ? null : path;
}
return ""; //$NON-NLS-1$
}
/**
* Searches for a boot directory starting at a given location. If one
* is found then this location is returned; otherwise an empty string
* is returned.
*
* @return the location where plugins were found, or an empty string
* @param start the location to begin searching at
*/
protected String searchForBoot(String start) {
FileFilter filter = new FileFilter() {
@Override
public boolean accept(File candidate) {
return candidate.getName().startsWith(PI_BOOT);
} }
}; // Create a URL based on the location of this class' code.
File[] boots = new File(start).listFiles(filter); // strip off jar file and/or last directory to get
String result = null; // to the directory containing projects.
String maxVersion = null; URL[] result = null;
for (int i = 0; i < boots.length; i++) { url = getClass().getProtectionDomain().getCodeSource().getLocation();
String name = boots[i].getName(); String path = url.getFile();
int index = name.lastIndexOf('_'); if (path.endsWith(".jar")) //$NON-NLS-1$
if (index == -1) { path = path.substring(0, path.lastIndexOf("/")); //$NON-NLS-1$
result = boots[i].getAbsolutePath(); else if (path.endsWith("/")) //$NON-NLS-1$
i = boots.length; path = path.substring(0, path.length() - 1);
if (inVAJ || inVAME) {
int ix = path.lastIndexOf("/"); //$NON-NLS-1$
path = path.substring(0, ix + 1);
path = path + PROJECT_NAME + "/"; //$NON-NLS-1$
url = new URL(url.getProtocol(), url.getHost(), url.getPort(), path);
result = new URL[] { url };
} else { } else {
if (index > 0) { path = searchForPlugins(path);
String version = name.substring(index + 1); path = searchForBoot(path);
if (maxVersion == null) { // add on any dev path elements
result = boots[i].getAbsolutePath(); url = new URL(url.getProtocol(), url.getHost(), url.getPort(), path);
maxVersion = version; result = getDevPath(url);
} else }
if (maxVersion.compareTo(version) == -1) { if (debug) {
System.out.println("Boot URL:"); //$NON-NLS-1$
for (int i = 0; i < result.length; i++)
System.out.println(" " + result[i].toExternalForm()); //$NON-NLS-1$
}
return result;
}
/**
* Searches for a plugins root starting at a given location. If one is found
* then this location is returned; otherwise an empty string is returned.
*
* @param start the location to begin searching at
* @return the location where plugins were found, or an empty string
*/
protected String searchForPlugins(String start) {
File path = new File(start);
while (path != null) {
File test = new File(path, "plugins"); //$NON-NLS-1$
if (test.exists())
return test.toString();
path = path.getParentFile();
path = (path == null || path.length() == 1) ? null : path;
}
return ""; //$NON-NLS-1$
}
/**
* Searches for a boot directory starting at a given location. If one is
* found then this location is returned; otherwise an empty string is
* returned.
*
* @param start the location to begin searching at
* @return the location where plugins were found, or an empty string
*/
protected String searchForBoot(String start) {
FileFilter filter = new FileFilter() {
@Override
public boolean accept(File candidate) {
return candidate.getName().startsWith(PI_BOOT);
}
};
File[] boots = new File(start).listFiles(filter);
String result = null;
String maxVersion = null;
for (int i = 0; i < boots.length; i++) {
String name = boots[i].getName();
int index = name.lastIndexOf('_');
if (index == -1) {
result = boots[i].getAbsolutePath();
i = boots.length;
} else {
if (index > 0) {
String version = name.substring(index + 1);
if (maxVersion == null) {
result = boots[i].getAbsolutePath(); result = boots[i].getAbsolutePath();
maxVersion = version; maxVersion = version;
} } else if (maxVersion.compareTo(version) == -1) {
result = boots[i].getAbsolutePath();
maxVersion = version;
}
}
} }
} }
if (result == null)
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$
} }
if (result == null)
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$
}
/**
* Returns the update loader for the given boot path.
*
* @return the update loader
* @param base the boot path base
* @exception Exception thrown is a problem occurs determining this loader
*/
public Class getUpdateLoader(String base) throws Exception {
URLClassLoader loader = new URLClassLoader(getBootPath(base), null);
return loader.loadClass(UPDATELOADER);
}
/**
* Runs the platform with the given arguments. The arguments must identify
* an application to run (e.g., <code>-application com.example.application</code>).
* After running the application <code>System.exit(N)</code> is executed.
* The value of N is derived from the value returned from running the application.
* If the application's return value is an <code>Integer</code>, N is this value.
* In all other cases, N = 0.
* <p>
* Clients wishing to run the platform without a following <code>System.exit</code>
* call should use <code>run()</code>.
*
* @see #run
*
* @param args the command line arguments
*/
public static void main(String[] args) {
Object result = null;
try {
result = new Main().run(args);
} catch (Throwable e) {
// try and take down the splash screen.
endSplash();
System.out.println("Exception launching the Eclipse Platform:"); //$NON-NLS-1$
e.printStackTrace();
}
int exitCode = result instanceof Integer ? ((Integer) result).intValue() : 0;
System.exit(exitCode);
}
/**
* Tears down the currently-displayed splash screen.
*/
public static void endSplash() {
if (endSplash == null)
return;
try {
Runtime.getRuntime().exec(endSplash);
} catch (Exception e) {
}
}
/** /**
* Runs this launcher with the arguments specified in the given string. * Returns the update loader for the given boot path.
* *
* @param argString the arguments string * @param base the boot path base
* @exception Exception thrown if a problem occurs during launching * @return the update loader
*/ * @exception Exception thrown is a problem occurs determining this loader
public static void main(String argString) throws Exception { */
Vector list = new Vector(5); public Class<?> getUpdateLoader(String base) throws MalformedURLException, IOException, ClassNotFoundException {
for (StringTokenizer tokens = new StringTokenizer(argString, " "); tokens.hasMoreElements();) //$NON-NLS-1$ try (URLClassLoader loader = new URLClassLoader(getBootPath(base), null)) {
list.addElement(tokens.nextElement()); return loader.loadClass(UPDATELOADER);
main((String[]) list.toArray(new String[list.size()]));
}
/**
* Processes the command line arguments
*
* @return the arguments to pass through to the launched application
* @param args the command line arguments
*/
protected String[] processCommandLine(String[] args) throws Exception {
int[] configArgs = new int[100];
configArgs[0] = -1; // need to initialize the first element to something that could not be an index.
int configArgIndex = 0;
for (int i = 0; i < args.length; i++) {
boolean found = false;
// check for args without parameters (i.e., a flag arg)
// check if debug should be enabled for the entire platform
if (args[i].equalsIgnoreCase(DEBUG)) {
debug = true;
// passed thru this arg (i.e., do not set found = true
continue;
}
// 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 -),
// simply enable development mode. Otherwise, assume that that the 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;
// do not mark the arg as found so it will be passed through
continue;
}
// done checking for args. Remember where an arg was found
if (found) {
configArgs[configArgIndex++] = i;
continue;
}
// check for args with parameters. If we are at the last argument or 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$
continue;
String arg = args[++i];
// look for the laucher to run
if (args[i - 1].equalsIgnoreCase(BOOT)) {
bootLocation = arg;
found = true;
}
// look for the development mode and class path entries.
if (args[i - 1].equalsIgnoreCase(DEV)) {
inDevelopmentMode = true;
devClassPath = arg;
continue;
}
// look for the application to run
if (args[i - 1].equalsIgnoreCase(APPLICATION)) {
application = arg;
found = true;
}
// look for token to use to end the splash screen
if (args[i - 1].equalsIgnoreCase(ENDSPLASH)) {
endSplash = arg;
continue;
}
// look for items to uninstall
if (args[i - 1].equalsIgnoreCase(UNINSTALL)) {
uninstall = true;
uninstallCookie = arg;
found = true;
}
// done checking for args. Remember where an arg was found
if (found) {
configArgs[configArgIndex++] = i - 1;
configArgs[configArgIndex++] = i;
} }
} }
// remove all the arguments consumed by this argument parsing
if (configArgIndex == 0) /**
return args; * Runs the platform with the given arguments. The arguments must identify
String[] passThruArgs = new String[args.length - configArgIndex]; * an application to run (e.g., <code>-application com.example.application</code>).
configArgIndex = 0; * After running the application <code>System.exit(N)</code> is executed.
int j = 0; * The value of N is derived from the value returned from running the application.
for (int i = 0; i < args.length; i++) { * If the application's return value is an <code>Integer</code>, N is this value.
if (i == configArgs[configArgIndex]) * In all other cases, N = 0.
configArgIndex++; * <p>
else * Clients wishing to run the platform without a following
passThruArgs[j++] = args[i]; * <code>System.exit</code> call should use <code>run()</code>.
*
* @param args the command line arguments
*
* @see #run
*/
public static void main(String[] args) {
Object result = null;
try {
result = new Main().run(args);
} catch (Throwable e) {
// try and take down the splash screen.
endSplash();
System.out.println("Exception launching the Eclipse Platform:"); //$NON-NLS-1$
e.printStackTrace();
}
int exitCode = result instanceof Integer ? ((Integer) result).intValue() : 0;
System.exit(exitCode);
} }
return passThruArgs;
} /**
/** * Tears down the currently-displayed splash screen.
* Runs the application to be launched. */
* public static void endSplash() {
* @return the return value from the launched application if (endSplash == null)
* @param args the arguments to pass to the application return;
* @exception thrown if a problem occurs during launching try {
*/ Runtime.getRuntime().exec(endSplash);
public Object run(String[] args) throws Exception { } catch (Exception e) {
String[] passThruArgs = processCommandLine(args); }
if (uninstall) }
return updateRun(UNINSTALL, uninstallCookie, passThruArgs);
return basicRun(passThruArgs); /**
} * Runs this launcher with the arguments specified in the given string.
/** *
* Performs an update run. * @param argString the arguments string
* * @exception Exception thrown if a problem occurs during launching
* @return the return value from the update loader */
* @param flag flag to give to the update loader public static void main(String argString) throws Exception {
* @param value value to give to the update loader Vector<Object> list = new Vector<Object>(5);
* @param args arguments to give to the update loader. for (StringTokenizer tokens = new StringTokenizer(argString, " "); tokens.hasMoreElements();) //$NON-NLS-1$
* @exception Exception thrown if a problem occurs during execution list.addElement(tokens.nextElement());
*/ main(list.toArray(new String[list.size()]));
protected Object updateRun(String flag, String value, String[] args) throws Exception { }
Class clazz = getUpdateLoader(bootLocation);
Method method = clazz.getDeclaredMethod("run", new Class[] { String.class, String.class, String.class, String[].class }); //$NON-NLS-1$ /**
try { * Processes the command line arguments
return method.invoke(clazz, new Object[] { flag, value, location, args }); *
} catch (InvocationTargetException e) { * @param args the command line arguments
if (e.getTargetException() instanceof Error) * @return the arguments to pass through to the launched application
throw (Error) e.getTargetException(); */
throw e; protected String[] processCommandLine(String[] args) throws Exception {
int[] configArgs = new int[100];
configArgs[0] = -1; // need to initialize the first element to something
// that could not be an index.
int configArgIndex = 0;
for (int i = 0; i < args.length; i++) {
boolean found = false;
// check for args without parameters (i.e., a flag arg)
// check if debug should be enabled for the entire platform
if (args[i].equalsIgnoreCase(DEBUG)) {
debug = true;
// passed thru this arg (i.e., do not set found = true
continue;
}
// 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 -),
// simply enable development mode. Otherwise, assume that that the
// 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;
// do not mark the arg as found so it will be passed through
continue;
}
// done checking for args. Remember where an arg was found
if (found) {
configArgs[configArgIndex++] = i;
continue;
}
// check for args with parameters. If we are at the last argument or
// 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$
continue;
String arg = args[++i];
// look for the laucher to run
if (args[i - 1].equalsIgnoreCase(BOOT)) {
bootLocation = arg;
found = true;
}
// look for the development mode and class path entries.
if (args[i - 1].equalsIgnoreCase(DEV)) {
inDevelopmentMode = true;
devClassPath = arg;
continue;
}
// look for the application to run
if (args[i - 1].equalsIgnoreCase(APPLICATION)) {
application = arg;
found = true;
}
// look for token to use to end the splash screen
if (args[i - 1].equalsIgnoreCase(ENDSPLASH)) {
endSplash = arg;
continue;
}
// look for items to uninstall
if (args[i - 1].equalsIgnoreCase(UNINSTALL)) {
uninstall = true;
uninstallCookie = arg;
found = true;
}
// done checking for args. Remember where an arg was found
if (found) {
configArgs[configArgIndex++] = i - 1;
configArgs[configArgIndex++] = i;
}
}
// remove all the arguments consumed by this argument parsing
if (configArgIndex == 0)
return args;
String[] passThruArgs = new String[args.length - configArgIndex];
configArgIndex = 0;
int j = 0;
for (int i = 0; i < args.length; i++) {
if (i == configArgs[configArgIndex])
configArgIndex++;
else
passThruArgs[j++] = args[i];
}
return passThruArgs;
}
/**
* Runs the application to be launched.
*
* @return the return value from the launched application
* @param args the arguments to pass to the application
* @exception Exception thrown if a problem occurs during launching
*/
public Object run(String[] args) throws Exception {
String[] passThruArgs = processCommandLine(args);
if (uninstall)
return updateRun(UNINSTALL, uninstallCookie, passThruArgs);
return basicRun(passThruArgs);
}
/**
* Performs an update run.
*
* @return the return value from the update loader
* @param flag
* flag to give to the update loader
* @param value
* 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 {
Class<?> clazz = getUpdateLoader(bootLocation);
Method method = clazz.getDeclaredMethod("run", //$NON-NLS-1$
new Class[] { String.class, String.class, String.class, String[].class });
try {
return method.invoke(clazz, new Object[] { flag, value, location, args });
} catch (InvocationTargetException e) {
if (e.getTargetException() instanceof Error)
throw (Error) e.getTargetException();
throw e;
}
} }
} }
}

View file

@ -6,7 +6,7 @@
* http://www.eclipse.org/legal/epl-v10.html * http://www.eclipse.org/legal/epl-v10.html
* *
* Contributors: * Contributors:
* IBM - Initial API and implementation * IBM - Initial API and implementation
*******************************************************************************/ *******************************************************************************/
package org.eclipse.cdt.ui.testplugin; package org.eclipse.cdt.ui.testplugin;
@ -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);
extra= true;
return 1;
}
extraStrings.push(current);
extra=true;
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,22 +33,25 @@ 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()
*/ */
@Override @Override
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.
@ -41,7 +38,7 @@ import org.eclipse.swt.widgets.Shell;
public class VerifyDialog extends TitleAreaDialog { public class VerifyDialog extends TitleAreaDialog {
private int SIZING_WIDTH = 400; private int SIZING_WIDTH = 400;
static int TEST_TYPE; static int TEST_TYPE;
public static final int TEST_SIZING = 0; public static final int TEST_SIZING = 0;
public static final int TEST_FOCUS = 1; public static final int TEST_FOCUS = 1;
public static final int TEST_ACCESS = 2; public static final int TEST_ACCESS = 2;
@ -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,16 +191,17 @@ 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() );
_checkList[i].setVisible(true); _checkList[i].setVisible(true);
_checkList[i].update(); _checkList[i].update();
@ -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

@ -4,12 +4,14 @@
* are made available under the terms of the Eclipse Public License v1.0 * are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at * which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html * http://www.eclipse.org/legal/epl-v10.html
* *
* Contributors: * Contributors:
* Intel Corporation - Initial API and implementation * Intel Corporation - Initial API and implementation
**********************************************************************/ **********************************************************************/
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,101 +19,101 @@ 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;
/** /**
* *
*/ */
public class CHelpProviderTester{ public class CHelpProviderTester {
private static final String KEY_PROVIDER_ID = "providerID"; private static final String KEY_PROVIDER_ID = "providerID";
private static final String KEY_REQUESTED_NAME = "requestedName"; private static final String KEY_REQUESTED_NAME = "requestedName";
private static final String KEY_BOOK_TITLE = "bookTitle"; private static final String KEY_BOOK_TITLE = "bookTitle";
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() {
} }
public static CHelpProviderTester getDefault(){ public static CHelpProviderTester getDefault() {
if(fDefaultInstance == null) if (fDefaultInstance == null)
fDefaultInstance = new CHelpProviderTester(); fDefaultInstance = new CHelpProviderTester();
return fDefaultInstance; return fDefaultInstance;
} }
private class CHelpBook implements ICHelpBook{ private class CHelpBook implements ICHelpBook {
private int fCHelpType; private int fCHelpType;
private String fTitle; private String fTitle;
public CHelpBook(String providerID, int type){ public CHelpBook(String providerID, int type) {
fCHelpType = type; fCHelpType = type;
fTitle = generateBookTitle(providerID,type); fTitle = generateBookTitle(providerID, type);
} }
@Override @Override
public String getTitle(){ public String getTitle() {
return fTitle; return fTitle;
} }
@Override @Override
public int getCHelpType(){ public int getCHelpType() {
return fCHelpType; return fCHelpType;
} }
} }
private class CHelpResourceDescriptor implements ICHelpResourceDescriptor{ private class CHelpResourceDescriptor implements ICHelpResourceDescriptor {
ICHelpBook fBook; ICHelpBook fBook;
String fString; String fString;
String fLabel; String fLabel;
String fHref; String fHref;
IHelpResource fResources[]; IHelpResource fResources[];
public CHelpResourceDescriptor(ICHelpBook helpBook, String string, String providerID){ public CHelpResourceDescriptor(ICHelpBook helpBook, String string, String providerID) {
fBook = helpBook; fBook = helpBook;
fString = string; fString = string;
fHref = string + helpBook.getTitle() + ".html"; fHref = string + helpBook.getTitle() + ".html";
fLabel = generateHelpString(helpBook, string, providerID); fLabel = generateHelpString(helpBook, string, providerID);
fResources = new IHelpResource[1]; fResources = new IHelpResource[1];
fResources[0] = new IHelpResource(){ fResources[0] = new IHelpResource() {
@Override @Override
public String getHref(){ public String getHref() {
return fHref; return fHref;
} }
@Override @Override
public String getLabel(){ public String getLabel() {
return fLabel; return fLabel;
} }
}; };
} }
@Override @Override
public ICHelpBook getCHelpBook(){ public ICHelpBook getCHelpBook() {
return fBook; return fBook;
} }
@Override @Override
public IHelpResource[] getHelpResources(){ public IHelpResource[] getHelpResources() {
return fResources; return fResources;
} }
} }
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";
@ -120,231 +122,231 @@ public class CHelpProviderTester{
private IRequiredInclude[] incs = new IRequiredInclude[] { new RequiredInclude("dummy.h")}; private IRequiredInclude[] incs = new IRequiredInclude[] { new RequiredInclude("dummy.h")};
private class RequiredInclude implements IRequiredInclude { private class RequiredInclude implements IRequiredInclude {
private String include; private String include;
public RequiredInclude (String file) { public RequiredInclude (String file) {
include = file; include = file;
} }
@Override @Override
public String getIncludeName() { public String getIncludeName() {
return include; return include;
} }
@Override @Override
public boolean isStandard() { public boolean isStandard() {
return true; return true;
} }
} }
public FunctionSummary(ICHelpBook helpBook, String string, String providerID){ public FunctionSummary(ICHelpBook helpBook, String string, String providerID) {
fName = string; fName = string;
fSummary = generateHelpString(helpBook, string, providerID); fSummary = generateHelpString(helpBook, string, providerID);
} }
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) {
Properties props = new Properties(); Properties props = new Properties();
props.setProperty(KEY_PROVIDER_ID, providerID); props.setProperty(KEY_PROVIDER_ID, providerID);
props.setProperty(KEY_REQUESTED_NAME, name); props.setProperty(KEY_REQUESTED_NAME, name);
props.setProperty(KEY_BOOK_TITLE, helpBook.getTitle()); props.setProperty(KEY_BOOK_TITLE, helpBook.getTitle());
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 static String generateBookTitle(String providerID, int bookType){ private static String generateBookTitle(String providerID, int bookType) {
Properties props = new Properties(); Properties props = new Properties();
props.setProperty(KEY_PROVIDER_ID, providerID); props.setProperty(KEY_PROVIDER_ID, providerID);
props.setProperty(KEY_BOOK_TYPE, String.valueOf(bookType)); props.setProperty(KEY_BOOK_TYPE, String.valueOf(bookType));
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;
} }
} }
private String getValueByKey(String key){ private String getValueByKey(String key) {
String val = fProperties.getProperty(key); String val = fProperties.getProperty(key);
if(val == null) if (val == null)
val = ""; //$NON-NLS-1$ val = ""; //$NON-NLS-1$
return val; return val;
} }
private String getHelpProviderID(){ private String getHelpProviderID() {
return getValueByKey(KEY_PROVIDER_ID); return getValueByKey(KEY_PROVIDER_ID);
} }
private String getRequestedName(){ private String getRequestedName() {
return getValueByKey(KEY_REQUESTED_NAME); return getValueByKey(KEY_REQUESTED_NAME);
} }
private String getBookTitle(){ private String getBookTitle() {
return getValueByKey(KEY_BOOK_TITLE); return getValueByKey(KEY_BOOK_TITLE);
} }
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");
if(!id.startsWith(CHelpTest.TEST_EXTENSION_ID_PREFIX)) if (!id.startsWith(CHelpTest.TEST_EXTENSION_ID_PREFIX))
return false; return false;
} }
return true; return true;
} }
public ICHelpResourceDescriptor[] generateHelpResources(ICHelpBook[] helpBooks, String name, String providerID){ public ICHelpResourceDescriptor[] generateHelpResources(ICHelpBook[] helpBooks, String name, String providerID) {
ICHelpResourceDescriptor des[] = new ICHelpResourceDescriptor[helpBooks.length]; ICHelpResourceDescriptor des[] = new ICHelpResourceDescriptor[helpBooks.length];
for(int i = 0; i < helpBooks.length; i++){ for (int i = 0; i < helpBooks.length; i++) {
des[i] = new CHelpResourceDescriptor(helpBooks[i],name,providerID); des[i] = new CHelpResourceDescriptor(helpBooks[i], name, providerID);
} }
return des; return des;
} }
public IFunctionSummary generateFunctionInfo(ICHelpBook[] helpBooks, String name, String providerID){ public IFunctionSummary generateFunctionInfo(ICHelpBook[] helpBooks, String name, String providerID) {
if(helpBooks.length == 0) if (helpBooks.length == 0)
return null; return null;
return new FunctionSummary(helpBooks[0],name,providerID); return new FunctionSummary(helpBooks[0], name, providerID);
} }
public IFunctionSummary[] generateMatchingFunctions(ICHelpBook[] helpBooks, String prefix, String providerID){ public IFunctionSummary[] generateMatchingFunctions(ICHelpBook[] helpBooks, String prefix, String providerID) {
IFunctionSummary sum[] = new IFunctionSummary[helpBooks.length]; IFunctionSummary sum[] = new IFunctionSummary[helpBooks.length];
for(int i = 0; i < helpBooks.length; i++){ for (int i = 0; i < helpBooks.length; i++) {
sum[i] = new FunctionSummary(helpBooks[i],prefix,providerID); sum[i] = new FunctionSummary(helpBooks[i], prefix, providerID);
} }
return sum; return sum;
} }
public ICHelpBook[] generateCHelpBooks(final String providerID){ public ICHelpBook[] generateCHelpBooks(final String providerID) {
ICHelpBook books[] = new ICHelpBook[3]; ICHelpBook books[] = new ICHelpBook[3];
books[0] = new CHelpBook(providerID,ICHelpBook.HELP_TYPE_C); books[0] = new CHelpBook(providerID, ICHelpBook.HELP_TYPE_C);
books[1] = new CHelpBook(providerID,ICHelpBook.HELP_TYPE_CPP); books[1] = new CHelpBook(providerID, ICHelpBook.HELP_TYPE_CPP);
books[2] = new CHelpBook(providerID,ICHelpBook.HELP_TYPE_ASM); books[2] = new CHelpBook(providerID, ICHelpBook.HELP_TYPE_ASM);
return books; return books;
} }
private void checkResponse(CHelpProviderTester data[], ICHelpInvocationContext context, String name, boolean allBooksResponded){ private void checkResponse(CHelpProviderTester data[], ICHelpInvocationContext context, String name, boolean allBooksResponded) {
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++) {
if(bookTitle.equals(bookDes[j].getCHelpBook().getTitle())){ if (bookTitle.equals(bookDes[j].getCHelpBook().getTitle())) {
Assert.assertTrue("provider was requested for help in disabled book",bookDes[j].isEnabled()); Assert.assertTrue("provider was requested for help in disabled book", bookDes[j].isEnabled());
break; break;
} }
} }
Assert.assertFalse("provider was requested for help in non-existent book",j == bookDes.length); Assert.assertFalse("provider was requested for help in non-existent book", j == bookDes.length);
} }
if(allBooksResponded){ if (allBooksResponded) {
for(int i = 0; i < bookDes.length; i++){ for (int i = 0; i < bookDes.length; i++) {
if(bookDes[i].isEnabled()){ if (bookDes[i].isEnabled()) {
String bookTitle = bookDes[i].getCHelpBook().getTitle(); String bookTitle = bookDes[i].getCHelpBook().getTitle();
int j = 0; int j = 0;
for(; j < data.length; j++){ for (; j < data.length; j++) {
if(bookTitle.equals(data[j].getBookTitle())) if (bookTitle.equals(data[j].getBookTitle()))
break; break;
} }
Assert.assertFalse("provider was not requested for help in enabled book",j == bookDes.length); Assert.assertFalse("provider was not requested for help in enabled book", j == bookDes.length);
} }
} }
} }
} }
public void checkHelpResources(ICHelpResourceDescriptor helpDescriptors[], ICHelpInvocationContext context, String name){ public void checkHelpResources(ICHelpResourceDescriptor helpDescriptors[], ICHelpInvocationContext context,
if(helpDescriptors == null || helpDescriptors.length == 0) String name) {
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.size() > 0) if (!dataList.isEmpty())
checkResponse((CHelpProviderTester[])dataList.toArray(new CHelpProviderTester[dataList.size()]), context, name, true); checkResponse(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.size() > 0) if (!dataList.isEmpty())
checkResponse((CHelpProviderTester[])dataList.toArray(new CHelpProviderTester[dataList.size()]), context, name, true); checkResponse(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
@ -49,15 +53,15 @@ public class CHelpTest extends TestCase {
private ICHelpInvocationContext fDefaultCHelpContext = null; private ICHelpInvocationContext fDefaultCHelpContext = null;
private ICHelpInvocationContext getDefaultCCHelpContext() throws CoreException{ private ICHelpInvocationContext getDefaultCCHelpContext() throws CoreException{
if(fDefaultCCHelpContext == null){ if (fDefaultCCHelpContext == null) {
final IProject project = getCCProject().getProject(); final IProject project = getCCProject().getProject();
fDefaultCCHelpContext = new ICHelpInvocationContext(){ fDefaultCCHelpContext = new ICHelpInvocationContext() {
@Override @Override
public IProject getProject(){ public IProject getProject() {
return project; return project;
} }
@Override @Override
public ITranslationUnit getTranslationUnit(){ public ITranslationUnit getTranslationUnit() {
return null; return null;
} }
}; };
@ -66,15 +70,15 @@ public class CHelpTest extends TestCase {
} }
private ICHelpInvocationContext getDefaultCHelpContext() throws CoreException{ private ICHelpInvocationContext getDefaultCHelpContext() throws CoreException{
if(fDefaultCHelpContext == null){ if (fDefaultCHelpContext == null) {
final IProject project = getCProject().getProject(); final IProject project = getCProject().getProject();
fDefaultCHelpContext = new ICHelpInvocationContext(){ fDefaultCHelpContext = new ICHelpInvocationContext() {
@Override @Override
public IProject getProject(){ public IProject getProject() {
return project; return project;
} }
@Override @Override
public ITranslationUnit getTranslationUnit(){ public ITranslationUnit getTranslationUnit() {
return null; return null;
} }
}; };
@ -83,13 +87,13 @@ public class CHelpTest extends TestCase {
} }
private ICProject getCProject() throws CoreException{ private ICProject getCProject() throws CoreException{
if(fCProject == null) if (fCProject == null)
fCProject = CProjectHelper.createCProject(C_PROJECT_NAME, BIN_DIR_NAME, IPDOMManager.ID_NO_INDEXER); fCProject = CProjectHelper.createCProject(C_PROJECT_NAME, BIN_DIR_NAME, IPDOMManager.ID_NO_INDEXER);
return fCProject; return fCProject;
} }
private ICProject getCCProject() throws CoreException{ private ICProject getCCProject() throws CoreException{
if(fCCProject == null) if (fCCProject == null)
fCCProject = CProjectHelper.createCCProject(CC_PROJECT_NAME, BIN_DIR_NAME, IPDOMManager.ID_NO_INDEXER); fCCProject = CProjectHelper.createCCProject(CC_PROJECT_NAME, BIN_DIR_NAME, IPDOMManager.ID_NO_INDEXER);
return fCCProject; return fCCProject;
} }
@ -110,14 +114,14 @@ public class CHelpTest extends TestCase {
super.tearDown(); super.tearDown();
} }
public void testCHelpProviderManagerGeneral(){ public void testCHelpProviderManagerGeneral() {
CHelpProviderManager mngr = CHelpProviderManager.getDefault(); CHelpProviderManager mngr = CHelpProviderManager.getDefault();
if(mngr == null) if (mngr == null)
fail("manager not created"); //$NON-NLS-1$ fail("manager not created"); //$NON-NLS-1$
if(mngr != CHelpProviderManager.getDefault()) if (mngr != CHelpProviderManager.getDefault())
fail("getDefault returned an other instance of manager"); //$NON-NLS-1$ fail("getDefault returned an other instance of manager"); //$NON-NLS-1$
try{ try {
ICHelpInvocationContext cContext = getDefaultCHelpContext(); ICHelpInvocationContext cContext = getDefaultCHelpContext();
ICHelpInvocationContext ccContext = getDefaultCCHelpContext(); ICHelpInvocationContext ccContext = getDefaultCCHelpContext();
@ -133,116 +137,120 @@ public class CHelpTest extends TestCase {
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"); //$NON-NLS-1$ String id = configElements[i].getAttribute("id"); //$NON-NLS-1$
if(id.startsWith(TEST_EXTENSION_ID_PREFIX)) if(id.startsWith(TEST_EXTENSION_ID_PREFIX))
numExts++; numExts++;
} }
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);
} }
} }
public void testGetMatchingFunctions(){ public void testGetMatchingFunctions() {
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 {
ICHelpInvocationContext cContext = getDefaultCHelpContext(); ICHelpInvocationContext cContext = getDefaultCHelpContext();
ICHelpInvocationContext ccContext = getDefaultCCHelpContext(); ICHelpInvocationContext ccContext = getDefaultCCHelpContext();
String requestedName = "dummyName"; //$NON-NLS-1$ String requestedName = "dummyName"; //$NON-NLS-1$
IFunctionSummary summaries[] = CHelpProviderManager.getDefault().getMatchingFunctions(cContext,requestedName); IFunctionSummary summaries[] = CHelpProviderManager.getDefault().getMatchingFunctions(cContext, requestedName);
CHelpProviderTester.getDefault().checkMatchingFunctions(summaries, cContext, requestedName); CHelpProviderTester.getDefault().checkMatchingFunctions(summaries, cContext, requestedName);
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 {
ICHelpInvocationContext cContext = getDefaultCHelpContext(); ICHelpInvocationContext cContext = getDefaultCHelpContext();
ICHelpInvocationContext ccContext = getDefaultCCHelpContext(); ICHelpInvocationContext ccContext = getDefaultCCHelpContext();
String requestedName = "dummyName"; //$NON-NLS-1$ String requestedName = "dummyName"; //$NON-NLS-1$
IFunctionSummary summary = CHelpProviderManager.getDefault().getFunctionInfo(cContext,requestedName); IFunctionSummary summary = CHelpProviderManager.getDefault().getFunctionInfo(cContext, requestedName);
CHelpProviderTester.getDefault().checkFunctionInfo(summary, cContext, requestedName); CHelpProviderTester.getDefault().checkFunctionInfo(summary, cContext, requestedName);
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$
} }
} }
public void testGetHelpResources(){ public void testGetHelpResources() {
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 {
ICHelpInvocationContext cContext = getDefaultCHelpContext(); ICHelpInvocationContext cContext = getDefaultCHelpContext();
ICHelpInvocationContext ccContext = getDefaultCCHelpContext(); ICHelpInvocationContext ccContext = getDefaultCCHelpContext();
String requestedName = "dummyName"; //$NON-NLS-1$ String requestedName = "dummyName"; //$NON-NLS-1$
ICHelpResourceDescriptor resourceDes[] = CHelpProviderManager.getDefault().getHelpResources(cContext,requestedName); ICHelpResourceDescriptor resourceDes[] = CHelpProviderManager.getDefault().getHelpResources(cContext, requestedName);
CHelpProviderTester.getDefault().checkHelpResources(resourceDes, cContext, requestedName); CHelpProviderTester.getDefault().checkHelpResources(resourceDes, cContext, requestedName);
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$
} }
} }
public void testCHelpBookDescriptors(){ public void testCHelpBookDescriptors() {
CHelpProviderManager mngr = CHelpProviderManager.getDefault(); CHelpProviderManager mngr = CHelpProviderManager.getDefault();
try{ try {
CHelpBookDescriptor ccBookDescriptors[] = mngr.getCHelpBookDescriptors(getDefaultCCHelpContext()); CHelpBookDescriptor ccBookDescriptors[] = mngr.getCHelpBookDescriptors(getDefaultCCHelpContext());
CHelpBookDescriptor cBookDescriptors[] = mngr.getCHelpBookDescriptors(getDefaultCHelpContext()); CHelpBookDescriptor cBookDescriptors[] = mngr.getCHelpBookDescriptors(getDefaultCHelpContext());
assertTrue("CC book descriptors length (" + ccBookDescriptors.length + ") is less than C book descriptors length (" + cBookDescriptors.length + ")", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ assertTrue("CC book descriptors length (" + ccBookDescriptors.length + ") is less than C book descriptors length (" + cBookDescriptors.length + ")", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
ccBookDescriptors.length >= cBookDescriptors.length); ccBookDescriptors.length >= cBookDescriptors.length);
for(int i = 0; i < cBookDescriptors.length; i++){ for (int i = 0; i < cBookDescriptors.length; i++) {
CHelpBookDescriptor curBookDes = cBookDescriptors[i]; CHelpBookDescriptor curBookDes = cBookDescriptors[i];
assertTrue("book \"" + curBookDes.getCHelpBook().getTitle() + "\" of type HELP_TYPE_CPP in book descriptors for C project \"" + getDefaultCHelpContext().getProject().getName() + "\"", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ assertTrue("book \"" + curBookDes.getCHelpBook().getTitle() + "\" of type HELP_TYPE_CPP in book descriptors for C project \"" + getDefaultCHelpContext().getProject().getName() + "\"", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
curBookDes.getCHelpBook().getCHelpType() != ICHelpBook.HELP_TYPE_CPP); curBookDes.getCHelpBook().getCHelpType() != ICHelpBook.HELP_TYPE_CPP);
int j = 0; int j = 0;
for(; j < ccBookDescriptors.length; j++){ for (; j < ccBookDescriptors.length; j++) {
if(ccBookDescriptors[j].getCHelpBook().getTitle().equals(curBookDes.getCHelpBook().getTitle())) if (ccBookDescriptors[j].getCHelpBook().getTitle().equals(curBookDes.getCHelpBook().getTitle()))
break; break;
} }
assertTrue("book \"" + curBookDes.getCHelpBook().getTitle() + "\" was not found in CC books",j < ccBookDescriptors.length); //$NON-NLS-1$ //$NON-NLS-2$ assertTrue("book \"" + curBookDes.getCHelpBook().getTitle() + "\" was not found in CC books", j < ccBookDescriptors.length); //$NON-NLS-1$ //$NON-NLS-2$
} }
for(int i = 0; i < ccBookDescriptors.length; i++){ for (int i = 0; i < ccBookDescriptors.length; i++) {
CHelpBookDescriptor curBookDes = ccBookDescriptors[i]; CHelpBookDescriptor curBookDes = ccBookDescriptors[i];
int j = 0; int j = 0;
for(; j < cBookDescriptors.length; j++){ for (; j < cBookDescriptors.length; j++) {
if(cBookDescriptors[j].getCHelpBook().getTitle().equals(curBookDes.getCHelpBook().getTitle())) if(cBookDescriptors[j].getCHelpBook().getTitle().equals(curBookDes.getCHelpBook().getTitle()))
break; break;
} }
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[];
@ -37,27 +36,21 @@ public class CHelpTestInfoProvider implements ICHelpProvider {
*/ */
static boolean fgEnabled= false; static boolean fgEnabled= false;
public CHelpTestInfoProvider(){ public CHelpTestInfoProvider() {
fProviderID = PROVIDER_ID_PREFIX + fNumProviders++; fProviderID = PROVIDER_ID_PREFIX + fNumProviders++;
fCHelpBooks = CHelpProviderTester.getDefault().generateCHelpBooks(fProviderID); fCHelpBooks = CHelpProviderTester.getDefault().generateCHelpBooks(fProviderID);
} }
public static int getNumProviders(){ public static int getNumProviders() {
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,22 +60,15 @@ 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;
} }
Assert.assertTrue("getFunctionInfo is called before completion contributor gets initialized",fIsInitialized); Assert.assertTrue("getFunctionInfo is called before completion contributor gets initialized",fIsInitialized);
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,
@ -90,21 +76,18 @@ public class CHelpTestInfoProvider implements ICHelpProvider {
if (!fgEnabled) { if (!fgEnabled) {
return new IFunctionSummary[0]; return new IFunctionSummary[0];
} }
Assert.assertTrue("getMatchingFunctions is called before completion contributor gets initialized",fIsInitialized); Assert.assertTrue("getMatchingFunctions is called before completion contributor gets initialized", fIsInitialized);
return null; // TODO returning null until someone puts in a preference to control it. return null; // TODO returning null until someone puts in a preference to control it.
//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];
} }
Assert.assertTrue("getHelpResources is called before completion contributor gets initialized",fIsInitialized); Assert.assertTrue("getHelpResources is called before completion contributor gets initialized", fIsInitialized);
return CHelpProviderTester.getDefault().generateHelpResources(helpBooks,name,fProviderID); return CHelpProviderTester.getDefault().generateHelpResources(helpBooks, name, fProviderID);
} }
} }