diff --git a/core/org.eclipse.cdt.ui.tests/.classpath b/core/org.eclipse.cdt.ui.tests/.classpath
new file mode 100644
index 00000000000..9fb20c1d6fd
--- /dev/null
+++ b/core/org.eclipse.cdt.ui.tests/.classpath
@@ -0,0 +1,17 @@
+
+
20th June, 2002
+Eclipse.org makes available all content in this plug-in ("Content"). Unless otherwise indicated below, the Content is provided to you under the terms and conditions of the +Common Public License Version 1.0 ("CPL"). A copy of the CPL is available at http://www.eclipse.org/legal/cpl-v10.html. +For purposes of the CPL, "Program" will mean the Content.
+ +The Content includes items that may be have been sourced from third parties as follows:
+ +JUnit 3.7
+The plug-in is based on software developed by JUnit.org. Your use of JUnit 3.7 in both source and binary code +form contained in the plug-in is subject to the terms and conditions of the IBM Public License 1.0 which is available at +http://oss.software.ibm.com/developerworks/opensource/license10.html. +The source code is located in testresources/junit37-noUI-src.zip.
+ +i) IBM effectively disclaims on behalf of all Contributors all warranties and conditions, express and implied, including warranties or conditions of title and non-infringement, and implied warranties or conditions of merchantability and fitness for a particular purpose;
+ii) IBM effectively excludes on behalf of all Contributors all liability for damages, including direct, indirect, special, incidental and consequential damages, such as lost profits;
+iii) IBM states that any provisions which differ from this Agreement are offered by that Contributor alone and not by any other party.
+ +If this Content is licensed to you under the terms and conditions of the CPL, any Contributions, as defined in the CPL, uploaded, submitted, or otherwise +made available to Eclipse.org, members of Eclipse.org and/or the host of Eclipse.org web site, by you that relate to such +Content are provided under the terms and conditions of the CPL and can be made available to others under the terms of the CPL.
+ +If this Content is licensed to you under license terms and conditions other than the CPL ("Other License"), any modifications, enhancements and/or +other code and/or documentation ("Modifications") uploaded, submitted, or otherwise made available to Eclipse.org, members of Eclipse.org and/or the +host of Eclipse.org, by you that relate to such Content are provided under terms and conditions of the Other License and can be made available +to others under the terms of the Other License. In addition, with regard to Modifications for which you are the copyright holder, you are also +providing the Modifications under the terms and conditions of the CPL and such Modifications can be made available to others under the terms of +the CPL.
+ + + \ No newline at end of file diff --git a/core/org.eclipse.cdt.ui.tests/build.properties b/core/org.eclipse.cdt.ui.tests/build.properties new file mode 100644 index 00000000000..1eab93ac3d4 --- /dev/null +++ b/core/org.eclipse.cdt.ui.tests/build.properties @@ -0,0 +1 @@ +source.cdttests.jar = src/ diff --git a/core/org.eclipse.cdt.ui.tests/core/org/eclipse/cdt/ui/tests/textmanipulation/TextBufferTest.java b/core/org.eclipse.cdt.ui.tests/core/org/eclipse/cdt/ui/tests/textmanipulation/TextBufferTest.java new file mode 100644 index 00000000000..e3f84ab1a55 --- /dev/null +++ b/core/org.eclipse.cdt.ui.tests/core/org/eclipse/cdt/ui/tests/textmanipulation/TextBufferTest.java @@ -0,0 +1,472 @@ +/* + * Copyright (c) 2002 IBM Corp. All rights reserved. + * This file is made available under the terms of the Common Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v10.html + */ + +package org.eclipse.cdt.ui.tests.textmanipulation; + +import junit.framework.Test; +import junit.framework.TestCase; +import junit.framework.TestSuite; + +import org.eclipse.cdt.internal.corext.textmanipulation.MoveTextEdit; +import org.eclipse.cdt.internal.corext.textmanipulation.SimpleTextEdit; +import org.eclipse.cdt.internal.corext.textmanipulation.SwapTextEdit; +import org.eclipse.cdt.internal.corext.textmanipulation.TextBuffer; +import org.eclipse.cdt.internal.corext.textmanipulation.TextBufferEditor; +import org.eclipse.cdt.internal.corext.textmanipulation.TextRange; +import org.eclipse.cdt.internal.corext.textmanipulation.UndoMemento; +import org.eclipse.cdt.testplugin.TestPluginLauncher; + + + +public class TextBufferTest extends TestCase { + + private static final Class THIS= TextBufferTest.class; + + private TextBuffer fBuffer; + private TextBufferEditor fEditor; + + public TextBufferTest(String name) { + super(name); + } + + public static void main(String[] args) { + TestPluginLauncher.run(TestPluginLauncher.getLocationFromProperties(), THIS, args); + } + + public static Test suite() { + TestSuite result= new TestSuite(THIS); + if (false) { // For hot code replace when debugging test cases + result.addTestSuite(THIS); + result.addTestSuite(THIS); + result.addTestSuite(THIS); + result.addTestSuite(THIS); + result.addTestSuite(THIS); + result.addTestSuite(THIS); + } + return result; + } + + protected void setUp() throws Exception { + fBuffer= TextBuffer.create("0123456789"); + fEditor= new TextBufferEditor(fBuffer); + } + + protected void tearDown() throws Exception { + fEditor= null; + } + + public void testOverlap1() throws Exception { + // [ [ ] ] + fEditor.add(SimpleTextEdit.createReplace(0, 2, "01")); + fEditor.add(SimpleTextEdit.createReplace(1, 2, "12")); + assertTrue(!fEditor.canPerformEdits()); + } + + public void testOverlap2() throws Exception { + // [[ ] ] + fEditor.add(SimpleTextEdit.createReplace(0, 2, "01")); + fEditor.add(SimpleTextEdit.createReplace(0, 1, "0")); + assertTrue(!fEditor.canPerformEdits()); + } + + public void testOverlap3() throws Exception { + // [ [ ]] + fEditor.add(SimpleTextEdit.createReplace(0, 2, "01")); + fEditor.add(SimpleTextEdit.createReplace(1, 1, "1")); + assertTrue(!fEditor.canPerformEdits()); + } + + public void testOverlap4() throws Exception { + // [ [ ] ] + fEditor.add(SimpleTextEdit.createReplace(0, 3, "012")); + fEditor.add(SimpleTextEdit.createReplace(1, 1, "1")); + assertTrue(!fEditor.canPerformEdits()); + } + + public void testOverlap5() throws Exception { + // [ [] ] + fEditor.add(SimpleTextEdit.createReplace(0, 3, "012")); + fEditor.add(SimpleTextEdit.createInsert(1, "xx")); + assertTrue(!fEditor.canPerformEdits()); + } + + public void testOverlap6() throws Exception { + // [ [] ] + fEditor.add(SimpleTextEdit.createReplace(0, 3, "012")); + fEditor.add(SimpleTextEdit.createInsert(2, "xx")); + assertTrue(!fEditor.canPerformEdits()); + } + + public void testOverlap7() throws Exception { + boolean catched= false; + try { + new MoveTextEdit(2,5,3); + } catch (Exception e) { + catched= true; + } + assertTrue(catched); + } + + public void testOverlap8() throws Exception { + boolean catched= false; + try { + new MoveTextEdit(2,5,6); + } catch (Exception e) { + catched= true; + } + assertTrue(catched); + } + + public void testOverlap9() throws Exception { + MoveTextEdit e1= new MoveTextEdit(3, 1, 7); + MoveTextEdit e2= new MoveTextEdit(2, 3, 8); + fEditor.add(e1); + fEditor.add(e2); + assertTrue(!fEditor.canPerformEdits()); + } + + public void testInsert1() throws Exception { + // [][ ] + SimpleTextEdit e1= SimpleTextEdit.createInsert(2, "yy"); + SimpleTextEdit e2= SimpleTextEdit.createReplace(2, 3, "3456"); + fEditor.add(e1); + fEditor.add(e2); + assertTrue(fEditor.canPerformEdits()); + UndoMemento undo= fEditor.performEdits(null); + assert(e1.getTextRange(), 2, 2); + assert(e2.getTextRange(), 4, 4); + assertEquals("Buffer content", "01yy345656789", fBuffer.getContent()); + doUndo(undo); + assert(e1.getTextRange(), 2, 0); + assert(e2.getTextRange(), 2, 3); + } + + public void testInsert2() throws Exception { + // [][] + SimpleTextEdit e1= SimpleTextEdit.createInsert(2, "yy"); + SimpleTextEdit e2= SimpleTextEdit.createInsert(2, "xx"); + fEditor.add(e1); + fEditor.add(e2); + assertTrue(fEditor.canPerformEdits()); + UndoMemento undo= fEditor.performEdits(null); + assert(e1.getTextRange(), 2, 2); + assert(e2.getTextRange(), 4, 2); + assertEquals("Buffer content", "01yyxx23456789", fBuffer.getContent()); + doUndo(undo); + assert(e1.getTextRange(), 2, 0); + assert(e2.getTextRange(), 2, 0); + } + + public void testInsert3() throws Exception { + // [ ][][ ] + SimpleTextEdit e1= SimpleTextEdit.createReplace(0, 2, "011"); + SimpleTextEdit e2= SimpleTextEdit.createInsert(2, "xx"); + SimpleTextEdit e3= SimpleTextEdit.createReplace(2, 2, "2"); + fEditor.add(e1); + fEditor.add(e2); + fEditor.add(e3); + assertTrue(fEditor.canPerformEdits()); + UndoMemento undo= fEditor.performEdits(null); + assert(e1.getTextRange(), 0, 3); + assert(e2.getTextRange(), 3, 2); + assert(e3.getTextRange(), 5, 1); + assertEquals("Buffer content", "011xx2456789", fBuffer.getContent()); + doUndo(undo); + assert(e1.getTextRange(), 0, 2); + assert(e2.getTextRange(), 2, 0); + assert(e3.getTextRange(), 2, 2); + } + + public void testInsert4() throws Exception { + SimpleTextEdit e1= SimpleTextEdit.createInsert(0, "xx"); + fEditor.add(e1); + assertTrue(fEditor.canPerformEdits()); + UndoMemento undo= fEditor.performEdits(null); + assertEquals("Buffer length", 12, fBuffer.getLength()); + assert(e1.getTextRange(), 0, 2); + assertEquals("Buffer content", "xx0123456789", fBuffer.getContent()); + doUndo(undo); + assert(e1.getTextRange(), 0, 0); + } + + public void testInsert5() throws Exception { + SimpleTextEdit e1= SimpleTextEdit.createInsert(10, "xx"); + fEditor.add(e1); + assertTrue(fEditor.canPerformEdits()); + UndoMemento undo= fEditor.performEdits(null); + assertEquals("Buffer length", 12, fBuffer.getLength()); + assert(e1.getTextRange(), 10, 2); + assertEquals("Buffer content", "0123456789xx", fBuffer.getContent()); + doUndo(undo); + assert(e1.getTextRange(), 10, 0); + } + + public void testDelete1() throws Exception { + SimpleTextEdit e1= SimpleTextEdit.createDelete(3, 1); + fEditor.add(e1); + assertTrue("Can perform edits", fEditor.canPerformEdits()); + UndoMemento undo= fEditor.performEdits(null); + assert(e1.getTextRange(), 3, 0); + assertEquals("Buffer content", "012456789", fBuffer.getContent()); + doUndo(undo); + assert(e1.getTextRange(), 3, 1); + } + + public void testDelete2() throws Exception { + SimpleTextEdit e1= SimpleTextEdit.createDelete(4, 1); + SimpleTextEdit e2= SimpleTextEdit.createDelete(3, 1); + SimpleTextEdit e3= SimpleTextEdit.createDelete(5, 1); + fEditor.add(e1); + fEditor.add(e2); + fEditor.add(e3); + assertTrue("Can perform edits", fEditor.canPerformEdits()); + UndoMemento undo= fEditor.performEdits(null); + assert(e1.getTextRange(), 3, 0); + assert(e2.getTextRange(), 3, 0); + assert(e3.getTextRange(), 3, 0); + assertEquals("Buffer content", "0126789", fBuffer.getContent()); + doUndo(undo); + assert(e1.getTextRange(), 4, 1); + assert(e2.getTextRange(), 3, 1); + assert(e3.getTextRange(), 5, 1); + } + + public void testDelete3() throws Exception { + SimpleTextEdit e1= SimpleTextEdit.createInsert(3, "x"); + SimpleTextEdit e2= SimpleTextEdit.createDelete(3, 1); + fEditor.add(e1); + fEditor.add(e2); + assertTrue("Can perform edits", fEditor.canPerformEdits()); + UndoMemento undo= fEditor.performEdits(null); + assert(e1.getTextRange(), 3, 1); + assert(e2.getTextRange(), 4, 0); + assertEquals("Buffer content", "012x456789", fBuffer.getContent()); + doUndo(undo); + assert(e1.getTextRange(), 3, 0); + assert(e2.getTextRange(), 3, 1); + } + + public void testMove1() throws Exception { + MoveTextEdit e1= new MoveTextEdit(2, 2, 5); + fEditor.add(e1); + assertTrue(fEditor.canPerformEdits()); + UndoMemento undo= fEditor.performEdits(null); + assertEquals("Buffer content", "0142356789", fBuffer.getContent()); + assert(e1.getTargetRange(), 3, 2); + assert(e1.getSourceRange(), 2, 0); + doUndo(undo); + assert(e1.getSourceRange(), 2, 2); + assert(e1.getTargetRange(), 5, 0); + } + + public void testMove2() throws Exception { + MoveTextEdit e1= new MoveTextEdit(5, 2, 2); + fEditor.add(e1); + assertTrue(fEditor.canPerformEdits()); + UndoMemento undo= fEditor.performEdits(null); + assertEquals("Buffer content", "0156234789", fBuffer.getContent()); + assert(e1.getTargetRange(), 2, 2); + assert(e1.getSourceRange(), 7, 0); + doUndo(undo); + assert(e1.getSourceRange(), 5, 2); + assert(e1.getTargetRange(), 2, 0); + } + + public void testMove3() throws Exception { + MoveTextEdit e1= new MoveTextEdit(2, 2, 7); + SimpleTextEdit e2= SimpleTextEdit.createReplace(4, 1, "x"); + fEditor.add(e1); + fEditor.add(e2); + assertTrue(fEditor.canPerformEdits()); + UndoMemento undo= fEditor.performEdits(null); + assertEquals("Buffer content", "01x5623789", fBuffer.getContent()); + assert(e1.getTargetRange(), 5, 2); + assert(e1.getSourceRange(), 2, 0); + assert(e2.getTextRange(), 2, 1); + doUndo(undo); + assert(e1.getSourceRange(), 2, 2); + assert(e1.getTargetRange(), 7, 0); + assert(e2.getTextRange(), 4, 1); + } + + public void testMove4() throws Exception { + MoveTextEdit e1= new MoveTextEdit(7, 2, 2); + SimpleTextEdit e2= SimpleTextEdit.createReplace(5, 1, "x"); + fEditor.add(e2); + fEditor.add(e1); + assertTrue(fEditor.canPerformEdits()); + UndoMemento undo= fEditor.performEdits(null); + assertEquals("Buffer content", "0178234x69", fBuffer.getContent()); + assert(e1.getTargetRange(), 2, 2); + assert(e1.getSourceRange(), 9, 0); + assert(e2.getTextRange(), 7, 1); + doUndo(undo); + assert(e1.getSourceRange(), 7, 2); + assert(e1.getTargetRange(), 2, 0); + assert(e2.getTextRange(), 5, 1); + } + + public void testMove5() throws Exception { + // Move onto itself + MoveTextEdit e1= new MoveTextEdit(2, 1, 3); + SimpleTextEdit e2= SimpleTextEdit.createReplace(2,1,"x"); + fEditor.add(e1); + fEditor.add(e2); + assertTrue(fEditor.canPerformEdits()); + UndoMemento undo= fEditor.performEdits(null); + assert(e1.getTargetRange(), 2, 1); + assert(e1.getSourceRange(), 3, 0); + assert(e2.getTextRange(), 2, 1); + assertEquals("Buffer content", "01x3456789", fBuffer.getContent()); + doUndo(undo); + assert(e1.getSourceRange(), 2, 1); + assert(e1.getTargetRange(), 3, 0); + assert(e2.getTextRange(), 2, 1); + } + + public void testMove6() throws Exception { + // Move onto itself + MoveTextEdit e1= new MoveTextEdit(2, 1, 2); + SimpleTextEdit e2= SimpleTextEdit.createReplace(2,1,"x"); + fEditor.add(e1); + fEditor.add(e2); + assertTrue(fEditor.canPerformEdits()); + UndoMemento undo= fEditor.performEdits(null); + assert(e1.getTargetRange(), 2, 1); + assert(e1.getSourceRange(), 3, 0); // This gets normalized since a move from [2,1] -> 2 == [2,1] -> 3 + assert(e2.getTextRange(), 2, 1); + assertEquals("Buffer content", "01x3456789", fBuffer.getContent()); + doUndo(undo); + assert(e1.getSourceRange(), 2, 1); + assert(e1.getTargetRange(), 3, 0); + assert(e2.getTextRange(), 2, 1); + } + + public void testMove7() throws Exception { + MoveTextEdit e1= new MoveTextEdit(2, 3, 7); + SimpleTextEdit e2= SimpleTextEdit.createReplace(3, 1, "x"); + fEditor.add(e1); + fEditor.add(e2); + assertTrue(fEditor.canPerformEdits()); + UndoMemento undo= fEditor.performEdits(null); + assertEquals("Buffer content", "01562x4789", fBuffer.getContent()); + assert(e1.getTargetRange(), 4, 3); + assert(e1.getSourceRange(), 2, 0); + assert(e2.getTextRange(), 5, 1); + doUndo(undo); + assert(e1.getSourceRange(), 2, 3); + assert(e1.getTargetRange(), 7, 0); + assert(e2.getTextRange(), 3, 1); + } + + public void testMove8() throws Exception { + MoveTextEdit e1= new MoveTextEdit(5, 3, 1); + SimpleTextEdit e2= SimpleTextEdit.createReplace(6, 1, "x"); + fEditor.add(e2); + fEditor.add(e1); + assertTrue(fEditor.canPerformEdits()); + UndoMemento undo= fEditor.performEdits(null); + assertEquals("Buffer content", "05x7123489", fBuffer.getContent()); + assert(e1.getTargetRange(), 1, 3); + assert(e1.getSourceRange(), 8, 0); + assert(e2.getTextRange(), 2, 1); + doUndo(undo); + assert(e1.getSourceRange(), 5, 3); + assert(e1.getTargetRange(), 1, 0); + assert(e2.getTextRange(), 6, 1); + } + + public void testMove9() throws Exception { + MoveTextEdit e1= new MoveTextEdit(1, 1, 3); + MoveTextEdit e2= new MoveTextEdit(1, 3, 5); + fEditor.add(e1); + fEditor.add(e2); + assertTrue("Can perform edits", fEditor.canPerformEdits()); + UndoMemento undo= fEditor.performEdits(null); + assert(e1.getTargetRange(), 3, 1); + assert(e1.getSourceRange(), 2, 0); + assert(e2.getTargetRange(), 2, 3); + assert(e2.getSourceRange(), 1, 0); + assertEquals("Buffer content", "0421356789", fBuffer.getContent()); + doUndo(undo); + assert(e1.getSourceRange(), 1, 1); + assert(e1.getTargetRange(), 3, 0); + assert(e2.getSourceRange(), 1, 3); + assert(e2.getTargetRange(), 5, 0); + } + + public void testMove10() throws Exception { + MoveTextEdit e1= new MoveTextEdit(2, 2, 8); + MoveTextEdit e2= new MoveTextEdit(5, 2, 1); + fEditor.add(e1); + fEditor.add(e2); + assertTrue("Can perform edits", fEditor.canPerformEdits()); + UndoMemento undo= fEditor.performEdits(null); + assertEquals("Buffer content", "0561472389", fBuffer.getContent()); + doUndo(undo); + } + + public void testSwap1() throws Exception { + SwapTextEdit e1= new SwapTextEdit(1, 1, 3, 1); + fEditor.add(e1); + assertTrue("Can perform edits", fEditor.canPerformEdits()); + UndoMemento undo= fEditor.performEdits(null); + assertEquals("Buffer content", "0321456789", fBuffer.getContent()); + doUndo(undo); + } + + public void testSwap2() throws Exception { + SwapTextEdit e1= new SwapTextEdit(1, 1, 3, 1); + SwapTextEdit e2= new SwapTextEdit(5, 1, 7, 1); + fEditor.add(e1); + fEditor.add(e2); + assertTrue("Can perform edits", fEditor.canPerformEdits()); + UndoMemento undo= fEditor.performEdits(null); + assertEquals("Buffer content", "0321476589", fBuffer.getContent()); + doUndo(undo); + } + + public void testSwap3() throws Exception { + SwapTextEdit e1= new SwapTextEdit(1, 1, 3, 1); + SwapTextEdit e2= new SwapTextEdit(5, 1, 7, 1); + SwapTextEdit e3= new SwapTextEdit(1, 3, 5, 3); + fEditor.add(e1); + fEditor.add(e2); + fEditor.add(e3); + assertTrue("Can perform edits", fEditor.canPerformEdits()); + UndoMemento undo= fEditor.performEdits(null); + assertEquals("Buffer content", "0765432189", fBuffer.getContent()); + doUndo(undo); + } + + public void testSwapAndReplace() throws Exception { + SwapTextEdit e1= new SwapTextEdit(1, 3, 5, 3); + SimpleTextEdit e2= SimpleTextEdit.createReplace(6, 1, "ab"); + fEditor.add(e1); + fEditor.add(e2); + assertTrue("Can perform edits", fEditor.canPerformEdits()); + UndoMemento undo= fEditor.performEdits(null); + assertEquals("Buffer content", "05ab7412389", fBuffer.getContent()); + doUndo(undo); + } + + private void doUndo(UndoMemento undo) throws Exception { + fEditor.add(undo); + fEditor.performEdits(null); + assertBufferContent(); + } + + private void assert(TextRange r, int offset, int length) { + assertEquals("Offset", offset, r.getOffset()); + assertEquals("Length", length, r.getLength()); + } + + private void assertBufferContent() { + assertEquals("Buffer content restored", "0123456789", fBuffer.getContent()); + } +} + diff --git a/core/org.eclipse.cdt.ui.tests/plugin.xml b/core/org.eclipse.cdt.ui.tests/plugin.xml new file mode 100644 index 00000000000..46d78414370 --- /dev/null +++ b/core/org.eclipse.cdt.ui.tests/plugin.xml @@ -0,0 +1,23 @@ + +BootLoader
which can be used to start
+ * up and run the platform. The given base, if not null
,
+ * is the location of the boot loader code. If the value is null
+ * then the boot loader is located relative to this class.
+ *
+ * @return the new boot loader
+ * @param base the location of the boot loader
+ */
+public Class getBootLoader(String base) throws Exception {
+ URLClassLoader loader = new URLClassLoader(getBootPath(base), null);
+ return loader.loadClass(BOOTLOADER);
+}
+/**
+ * Returns the URL
-based class path describing where the boot classes
+ * are located when running in development mode.
+ *
+ * @return the url-based class path
+ * @param base the base location
+ * @exception MalformedURLException if a problem occurs computing the class path
+ */
+protected URL[] getDevPath(URL base) throws MalformedURLException {
+ URL url;
+ String devBase = base.toExternalForm();
+ if (!inDevelopmentMode) {
+ url = new URL(devBase + "boot.jar");
+ 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 == '\\')))
+ url = new URL (spec);
+ else
+ url = new URL(spec + "/");
+ //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");
+ if (new java.io.File(url.getFile()).exists())
+ result.add(url);
+ return (URL[])result.toArray(new URL[result.size()]);
+}
+
+/**
+ * Returns the URL
-based class path describing where the boot classes are located.
+ *
+ * @return the url-based class path
+ * @param base the base location
+ * @exception MalformedURLException if a problem occurs computing the class path
+ */
+protected URL[] getBootPath(String base) throws MalformedURLException {
+ URL url = null;
+ // if the given location is not null, assume it is correct and use it.
+ if (base != null) {
+ url = new URL(base);
+ if (debug)
+ System.out.println("Boot URL: " + url.toExternalForm());
+ 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"))
+ path = path.substring(0, path.lastIndexOf("/"));
+ else
+ if (path.endsWith("/"))
+ path = path.substring(0, path.length() - 1);
+ if (inVAJ || inVAME) {
+ int ix = path.lastIndexOf("/");
+ path = path.substring(0, ix + 1);
+ path = path + PROJECT_NAME + "/";
+ 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:");
+ for (int i = 0; i < result.length; i++)
+ System.out.println(" " + result[i].toExternalForm());
+ }
+ 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");
+ if (test.exists())
+ return test.toString();
+ path = path.getParentFile();
+ path = (path == null || path.length() == 1) ? null : path;
+ }
+ return "";
+}
+/**
+ * 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() {
+ 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();
+ 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.");
+ return result.replace(File.separatorChar, '/') + "/";
+}
+/**
+ * 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., -application com.example.application
).
+ * After running the application System.exit(N)
is executed.
+ * The value of N is derived from the value returned from running the application.
+ * If the application's return value is an Integer
, N is this value.
+ * In all other cases, N = 0.
+ *
+ * Clients wishing to run the platform without a following System.exit
+ * call should use run()
.
+ *
+ * @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:");
+ 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.
+ *
+ * @param argString the arguments string
+ * @exception Exception thrown if a problem occurs during launching
+ */
+public static void main(String argString) throws Exception {
+ Vector list = new Vector(5);
+ for (StringTokenizer tokens = new StringTokenizer(argString, " "); tokens.hasMoreElements();)
+ list.addElement((String) tokens.nextElement());
+ 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("-"))))) {
+ 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("-"))
+ 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 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);
+ else
+ 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", 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();
+ else
+ throw e;
+ }
+}
+}
diff --git a/core/org.eclipse.cdt.ui.tests/src/org/eclipse/cdt/testplugin/NewMain.java b/core/org.eclipse.cdt.ui.tests/src/org/eclipse/cdt/testplugin/NewMain.java
new file mode 100644
index 00000000000..41a42bc7f30
--- /dev/null
+++ b/core/org.eclipse.cdt.ui.tests/src/org/eclipse/cdt/testplugin/NewMain.java
@@ -0,0 +1,74 @@
+/*
+ * (c) Copyright IBM Corp. 2000, 2001.
+ * All Rights Reserved.
+ */
+package org.eclipse.cdt.testplugin;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.net.URL;
+import java.util.Properties;
+import java.util.StringTokenizer;
+import java.util.Vector;
+
+/**
+ * Application is responsible for calling core launch api
+ */
+
+public class NewMain extends Main {
+ private static final String DEFAULT_APPLICATION= "org.eclipse.ui.workbench";
+
+
+ public NewMain(String application, String location, URL pluginPathLocation, String bootLocation, boolean debug) throws IOException {
+ this.application= application;
+ this.location= location;
+ this.pluginPathLocation= pluginPathLocation;
+ this.bootLocation= bootLocation;
+ }
+
+ public static void main(String[] args) {
+ try {
+ String location= getLocationFromProperties("platform");
+ new NewMain(DEFAULT_APPLICATION, location, null, null, true).run(args);
+ } catch (Throwable e) {
+ System.out.println("Exception launching the Eclipse Platform UI:");
+ e.printStackTrace();
+ }
+ System.exit(0);
+ }
+
+
+ /**
+ * Run this launcher with the arguments specified in the given string.
+ * This is a short cut method for people running the launcher from
+ * a scrapbook (i.e., swip-and-doit facility).
+ */
+ public static void main(String argString) throws Exception {
+ Vector list= new Vector(5);
+ for (StringTokenizer tokens= new StringTokenizer(argString, " "); tokens.hasMoreElements();)
+ list.addElement((String) tokens.nextElement());
+ main((String[]) list.toArray(new String[list.size()]));
+ }
+
+ public static String getLocationFromProperties(String key) {
+ Properties properties= new Properties();
+ try {
+ FileInputStream fis= new FileInputStream(getSettingsFile());
+ properties.load(fis);
+ return properties.getProperty(key);
+ } catch (IOException e) {
+ }
+ return null;
+ }
+
+ private static File getSettingsFile() {
+ String home= System.getProperty("user.home");
+ if (home == null) {
+ System.out.println("Home dir not defined");
+ return null;
+ }
+ return new File(home, "eclipse-workspaces.properties");
+ }
+}
\ No newline at end of file
diff --git a/core/org.eclipse.cdt.ui.tests/src/org/eclipse/cdt/testplugin/TestPluginLauncher.java b/core/org.eclipse.cdt.ui.tests/src/org/eclipse/cdt/testplugin/TestPluginLauncher.java
new file mode 100644
index 00000000000..4ee939df6b5
--- /dev/null
+++ b/core/org.eclipse.cdt.ui.tests/src/org/eclipse/cdt/testplugin/TestPluginLauncher.java
@@ -0,0 +1,57 @@
+/*
+ * (c) Copyright IBM Corp. 2000, 2001.
+ * All Rights Reserved.
+ */
+package org.eclipse.cdt.testplugin;
+
+import java.net.URL;
+
+/**
+ * Helper class to launch a test
+ */
+public class TestPluginLauncher {
+
+ public static final String APP_NAME= "org.eclipse.jdt.ui.tests.app";
+
+ public static void run(String location, Class testCase, String[] args) {
+ run(APP_NAME, location, testCase, args);
+ }
+
+ public static void run(String application, String location, Class testCase, String[] args) {
+ try {
+ String bootLocation= getBootLocation();
+ int nArgs= args.length;
+ String[] newArgs= new String[4 + nArgs];
+ newArgs[0]= testCase.getName();
+ for (int i= 0; i < nArgs; i++) {
+ newArgs[1 + i]= args[i];
+ }
+ newArgs[1 + nArgs]= "-dev";
+ newArgs[1 + nArgs + 1]= "bin";
+ newArgs[1 + nArgs + 2]= "-debug";
+ NewMain newMain= new NewMain(application, location, null, bootLocation, false);
+ newMain.run(newArgs);
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+
+ public static String getLocationFromProperties(String key) {
+ return NewMain.getLocationFromProperties(key);
+ }
+
+ public static String getLocationFromProperties() {
+ return NewMain.getLocationFromProperties("tests");
+ }
+
+ public static String getBootLocation() {
+ URL url= TestPluginLauncher.class.getResource("TestPluginLauncher.class");
+ String s= url.toString();
+ int index= s.indexOf("/org.eclipse.jdt.ui.tests");
+ if (index == -1)
+ throw new IllegalArgumentException();
+ s= s.substring(0, index);
+ s= s + "/org.eclipse.core.boot/boot.jar";
+ return s;
+ }
+}
\ No newline at end of file
diff --git a/core/org.eclipse.cdt.ui.tests/src/org/eclipse/cdt/testplugin/TestWorkbench.java b/core/org.eclipse.cdt.ui.tests/src/org/eclipse/cdt/testplugin/TestWorkbench.java
new file mode 100644
index 00000000000..45bc1e8de3f
--- /dev/null
+++ b/core/org.eclipse.cdt.ui.tests/src/org/eclipse/cdt/testplugin/TestWorkbench.java
@@ -0,0 +1,79 @@
+/*
+ * (c) Copyright IBM Corp. 2000, 2001.
+ * All Rights Reserved.
+ */
+package org.eclipse.cdt.testplugin;
+
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+import junit.textui.TestRunner;
+
+import org.eclipse.core.runtime.IPath;
+
+import org.eclipse.swt.widgets.Display;
+
+import org.eclipse.ui.internal.Workbench;
+
+public class TestWorkbench extends Workbench {
+
+ /**
+ * Run an event loop for the workbench.
+ */
+ protected void runEventLoop() {
+ // Dispatch all events.
+ Display display = Display.getCurrent();
+ while (true) {
+ try {
+ if (!display.readAndDispatch())
+ break;
+ } catch (Throwable e) {
+ break;
+ }
+ }
+ IPath location= CTestPlugin.getDefault().getWorkspace().getRoot().getLocation();
+ System.out.println("Workspace-location: " + location.toString());
+
+
+ try {
+ String[] args= getCommandLineArgs();
+ if (args.length > 0) {
+ Test test= getTest(args[0]);
+ TestRunner.run(test);
+ } else {
+ System.out.println("TestWorkbench: Argument must be class name");
+ }
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+
+
+ // Close the workbench.
+ close();
+ }
+
+ public Test getTest(String className) throws Exception {
+ Class testClass= getClass().getClassLoader().loadClass(className);
+
+ Method suiteMethod= null;
+ try {
+ suiteMethod= testClass.getMethod(TestRunner.SUITE_METHODNAME, new Class[0]);
+ } catch (Exception e) {
+ // try to extract a test suite automatically
+ return new TestSuite(testClass);
+ }
+ try {
+ return (Test) suiteMethod.invoke(null, new Class[0]); // static method
+ } catch (InvocationTargetException e) {
+ System.out.println("Failed to invoke suite():" + e.getTargetException().toString());
+ } catch (IllegalAccessException e) {
+ System.out.println("Failed to invoke suite():" + e.toString());
+ }
+ return null;
+
+ }
+
+
+}
\ No newline at end of file
diff --git a/core/org.eclipse.cdt.ui.tests/src/org/eclipse/cdt/testplugin/test/HelloWorld.java b/core/org.eclipse.cdt.ui.tests/src/org/eclipse/cdt/testplugin/test/HelloWorld.java
new file mode 100644
index 00000000000..4e41ef027f1
--- /dev/null
+++ b/core/org.eclipse.cdt.ui.tests/src/org/eclipse/cdt/testplugin/test/HelloWorld.java
@@ -0,0 +1,50 @@
+/*
+ * (c) Copyright IBM Corp. 2000, 2001.
+ * All Rights Reserved.
+ */
+package org.eclipse.cdt.testplugin.test;
+
+import junit.framework.Test;
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+
+import org.eclipse.cdt.core.model.ICProject;
+import org.eclipse.cdt.testplugin.CProjectHelper;
+import org.eclipse.cdt.testplugin.TestPluginLauncher;
+import org.eclipse.core.runtime.Path;
+
+
+public class HelloWorld extends TestCase {
+
+ private ICProject fCProject;
+
+ public static void main(String[] args) {
+ TestPluginLauncher.run(TestPluginLauncher.getLocationFromProperties(), HelloWorld.class, args);
+ }
+
+ public static Test suite() {
+ TestSuite suite= new TestSuite();
+ suite.addTest(new HelloWorld("test1"));
+ return suite;
+ }
+
+ public HelloWorld(String name) {
+ super(name);
+ }
+
+ protected void setUp() throws Exception {
+ fCProject= CProjectHelper.createCProject("TestProject1", "bin");
+ }
+
+
+ protected void tearDown() throws Exception {
+ CProjectHelper.delete(fCProject);
+ }
+
+ public void test1() throws Exception {
+
+ assertTrue("Exception to test", 0 != 0);
+
+ }
+
+}
\ No newline at end of file
diff --git a/core/org.eclipse.cdt.ui.tests/src/org/eclipse/cdt/testplugin/util/AccessibilityTestPass.java b/core/org.eclipse.cdt.ui.tests/src/org/eclipse/cdt/testplugin/util/AccessibilityTestPass.java
new file mode 100644
index 00000000000..2a6e8fe44bd
--- /dev/null
+++ b/core/org.eclipse.cdt.ui.tests/src/org/eclipse/cdt/testplugin/util/AccessibilityTestPass.java
@@ -0,0 +1,66 @@
+package org.eclipse.cdt.testplugin.util;
+
+
+import java.util.ArrayList;
+
+
+public class AccessibilityTestPass implements IDialogTestPass {
+ private static final int CHECKLIST_SIZE = 5;
+
+ /**
+ * @see IDialogTestPass#title()
+ */
+ public String title() {
+ return "Test Pass: Accessibility";
+ }
+ /**
+ * @see IDialogTestPass#description()
+ */
+ public String description() {
+ return "Verify the accessibility of the dialogs.";
+ }
+ /**
+ * @see IDialogTestPass#label()
+ */
+ public String label() {
+ return "&Accessibility";
+ }
+ /**
+ * @see IDialogTestPass#checkListTexts()
+ */
+ public ArrayList checkListTexts() {
+ ArrayList list = new ArrayList(CHECKLIST_SIZE);
+ list.add("&1) all widgets are accessible by tabbing.");
+ 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("&4) there are no duplicate mnemonics.");
+ list.add("&5) selectable widgets can be selected using the spacebar.");
+ return list;
+ }
+ /**
+ * @see IDialogTestPass#failureTexts()
+ * Size of the return array must be the same size as the checkListTexts'
+ * ArrayList.
+ */
+ public String[] failureTexts() {
+ String[] failureText = new String[CHECKLIST_SIZE];
+ failureText[0] = "Some widgets aren't accessible by tabbing.";
+ failureText[1] = "Tabbing order is illogical.";
+ failureText[2] = "Missing or inappropriate mnemonics.";
+ failureText[3] = "Duplicate mnemonics.";
+ failureText[4] = "Some widgets cannot be selected using the spacebar.";
+ return failureText;
+ }
+ /**
+ * @see IDialogTestPass#queryText()
+ */
+ public String queryText() {
+ return "Is the accessibility of the dialog acceptable?";
+ }
+ /**
+ * @see IDialogTestPass#getID()
+ */
+ public int getID() {
+ return VerifyDialog.TEST_ACCESS;
+ }
+}
\ No newline at end of file
diff --git a/core/org.eclipse.cdt.ui.tests/src/org/eclipse/cdt/testplugin/util/DialogCheck.java b/core/org.eclipse.cdt.ui.tests/src/org/eclipse/cdt/testplugin/util/DialogCheck.java
new file mode 100644
index 00000000000..8ef16ebce24
--- /dev/null
+++ b/core/org.eclipse.cdt.ui.tests/src/org/eclipse/cdt/testplugin/util/DialogCheck.java
@@ -0,0 +1,225 @@
+package org.eclipse.cdt.testplugin.util;
+
+
+/*
+ * (c) Copyright IBM Corp. 2000, 2001.
+ * All Rights Reserved.
+ */
+
+
+import junit.framework.Assert;
+
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.graphics.Point;
+import org.eclipse.swt.widgets.Button;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.Label;
+import org.eclipse.swt.widgets.Shell;
+
+import org.eclipse.jface.dialogs.Dialog;
+import org.eclipse.jface.dialogs.IDialogConstants;
+
+import org.eclipse.ui.internal.WorkbenchPlugin;
+
+
+/**
+ * A DialogCheck
is used test a dialog in
+ * various ways.
+ *
+ * For interactive tests use assertDialog
.
+ * For automated tests use assert DialogTexts
.
+ *
Dialog dialog = new AboutDialog( DialogCheck.getShell() );
+ * DialogCheck.assertDialog(dialog, this);
+ *
+ * @param dialog the test dialog to be verified.
+ * @param assert this is the test case object, assertions will be
+ * executed on this object.
+ */
+ public static void assertDialog(Dialog dialog, Assert assert) {
+ assert.assertNotNull(dialog);
+ if (_verifyDialog.getShell() == null) {
+ //force the creation of the verify dialog
+ getShell();
+ }
+ if (_verifyDialog.open(dialog) == IDialogConstants.NO_ID) {
+ assert.assertTrue(_verifyDialog.getFailureText(), false);
+ }
+ }
+
+
+ /**
+ * Automated test that checks all the labels and buttons of a dialog
+ * to make sure there is enough room to display all the text. Any
+ * text that wraps is only approximated and is currently not accurate.
+ *
+ * @param dialog the test dialog to be verified.
+ * @param assert this is the test case object, assertions will be
+ * executed on this object.
+ */
+ public static void assertDialogTexts(Dialog dialog, Assert assert) {
+ assert.assertNotNull(dialog);
+ dialog.setBlockOnOpen(false);
+ dialog.open();
+ Shell shell = dialog.getShell();
+ verifyCompositeText(shell, assert);
+ dialog.close();
+ }
+
+
+ /**
+ * This method should be called when creating dialogs to test. This
+ * ensures that the dialog's parent shell will be that of the
+ * verification dialog.
+ *
+ * @return Shell The shell of the verification dialog to be used as
+ * the parent shell of the test dialog.
+ */
+ public static Shell getShell() {
+ Shell shell =
+ WorkbenchPlugin
+ .getDefault()
+ .getWorkbench()
+ .getActiveWorkbenchWindow()
+ .getShell();
+ _verifyDialog = new VerifyDialog(shell);
+ _verifyDialog.create();
+ return _verifyDialog.getShell();
+ }
+
+
+ /*
+ * Looks at all the child widgets of a given composite and
+ * verifies the text on all labels and widgets.
+ * @param composite The composite to look through
+ * @param assert The object to invoke assertions on.
+ */
+ private static void verifyCompositeText(Composite composite, Assert assert) {
+ Control children[] = composite.getChildren();
+ for (int i = 0; i < children.length; i++) {
+ try {
+ //verify the text if the child is a button
+ verifyButtonText((Button) children[i], assert);
+ } catch (ClassCastException exNotButton) {
+ try {
+ //child is not a button, maybe a label
+ verifyLabelText((Label) children[i], assert);
+ } catch (ClassCastException exNotLabel) {
+ try {
+ //child is not a label, make a recursive call if it is a composite
+ verifyCompositeText((Composite) children[i], assert);
+ } catch (ClassCastException exNotComposite) {
+ //the child is not a button, label, or composite - ignore it.
+ }
+ }
+ }
+ }
+ }
+
+ /*
+ * Verifies that a given button is large enough to display its text.
+ * @param button The button to verify,
+ * @param assert The object to invoke assertions on.
+ */
+ private static void verifyButtonText(Button button, Assert assert) {
+ String widget = button.toString();
+ Point size = button.getSize();
+
+
+ //compute the size with no line wrapping
+ Point preferred = button.computeSize(SWT.DEFAULT, SWT.DEFAULT);
+ //if (size.y/preferred.y) == X, then label spans X lines, so divide
+ //the calculated value of preferred.x by X
+ if (preferred.y * size.y > 0) {
+ preferred.y /= countLines(button.getText()); //check for '\n\'
+ if (size.y / preferred.y > 1) {
+ preferred.x /= (size.y / preferred.y);
+ }
+ }
+
+
+ String message =
+ new StringBuffer("Warning: ")
+ .append(widget)
+ .append("\n\tActual Width -> ")
+ .append(size.x)
+ .append("\n\tRecommended Width -> ")
+ .append(preferred.x)
+ .toString();
+ if (preferred.x > size.x) {
+ //close the dialog
+ button.getShell().dispose();
+ assert.assertTrue(message.toString(), false);
+ }
+ }
+
+ /*
+ * Verifies that a given label is large enough to display its text.
+ * @param label The label to verify,
+ * @param assert The object to invoke assertions on.
+ */
+ private static void verifyLabelText(Label label, Assert assert) {
+ String widget = label.toString();
+ Point size = label.getSize();
+
+
+ //compute the size with no line wrapping
+ Point preferred = label.computeSize(SWT.DEFAULT, SWT.DEFAULT);
+ //if (size.y/preferred.y) == X, then label spans X lines, so divide
+ //the calculated value of preferred.x by X
+ if (preferred.y * size.y > 0) {
+ preferred.y /= countLines(label.getText());
+ if (size.y / preferred.y > 1) {
+ preferred.x /= (size.y / preferred.y);
+ }
+ }
+ String message =
+ new StringBuffer("Warning: ")
+ .append(widget)
+ .append("\n\tActual Width -> ")
+ .append(size.x)
+ .append("\n\tRecommended Width -> ")
+ .append(preferred.x)
+ .toString();
+ if (preferred.x > size.x) {
+ //close the dialog
+ label.getShell().dispose();
+ assert.assertTrue(message.toString(), false);
+ }
+ }
+
+ /*
+ * Counts the number of lines in a given String.
+ * For example, if a string contains one (1) newline character,
+ * a value of two (2) would be returned.
+ * @param text The string to look through.
+ * @return int the number of lines in text.
+ */
+ private static int countLines(String text) {
+ int newLines = 1;
+ for (int i = 0; i < text.length(); i++) {
+ if (text.charAt(i) == '\n') {
+ newLines++;
+ }
+ }
+ return newLines;
+ }
+}
\ No newline at end of file
diff --git a/core/org.eclipse.cdt.ui.tests/src/org/eclipse/cdt/testplugin/util/FailureDialog.java b/core/org.eclipse.cdt.ui.tests/src/org/eclipse/cdt/testplugin/util/FailureDialog.java
new file mode 100644
index 00000000000..dbe98db5652
--- /dev/null
+++ b/core/org.eclipse.cdt.ui.tests/src/org/eclipse/cdt/testplugin/util/FailureDialog.java
@@ -0,0 +1,107 @@
+package org.eclipse.cdt.testplugin.util;
+
+
+/*
+ * (c) Copyright IBM Corp. 2000, 2001.
+ * All Rights Reserved.
+ */
+
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.Label;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.swt.widgets.Text;
+
+import org.eclipse.jface.dialogs.Dialog;
+import org.eclipse.jface.dialogs.IDialogConstants;
+import org.eclipse.jface.resource.JFaceResources;
+
+
+/*
+ * A dialog for collecting notes from the tester regarding
+ * the failure of a test.
+ */
+public class FailureDialog extends Dialog {
+ private Text _text;
+ private String _log;
+ private int SIZING_TEXT_WIDTH = 400;
+ private int SIZING_TEXT_HEIGHT = 200;
+
+ /**
+ * Constructor for FailureDialog
+ */
+ public FailureDialog(Shell parentShell) {
+ super(parentShell);
+ }
+ /* (non-Javadoc)
+ * Method declared on Window.
+ */
+ protected void configureShell(Shell newShell) {
+ super.configureShell(newShell);
+ newShell.setText("Dialog Test Failed");
+ }
+ /* (non-Javadoc)
+ * Method declared on Dialog.
+ */
+ protected void createButtonsForButtonBar(Composite parent) {
+ createButton(parent, IDialogConstants.OK_ID, "&OK", true);
+ createButton(parent, IDialogConstants.CANCEL_ID, IDialogConstants.CANCEL_LABEL, false);
+ }
+ /* (non-Javadoc)
+ * Method declared on Dialog.
+ */
+ protected Control createDialogArea(Composite parent) {
+ // page group
+ Composite composite = (Composite)super.createDialogArea(parent);
+ composite.setSize( composite.computeSize(SWT.DEFAULT, SWT.DEFAULT) );
+
+ Label label = new Label(composite, SWT.WRAP);
+ label.setText("&Enter a note regarding the failure:");
+
+ _text = new Text(composite, SWT.MULTI | SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL);
+ _text.setFont( JFaceResources.getFontRegistry().get(JFaceResources.TEXT_FONT) );
+ GridData data = new GridData(GridData.FILL_BOTH);
+ data.widthHint = SIZING_TEXT_WIDTH;
+ data.heightHint = SIZING_TEXT_HEIGHT;
+ _text.setLayoutData(data);
+
+ return composite;
+ }
+ /* (non-Javadoc)
+ * Method declared on Dialog.
+ */
+ protected void okPressed() {
+ _log = _text.getText();
+ super.okPressed();
+ }
+ /*
+ * @return String the text contained in the input area of
+ * the dialog.
+ */
+ String getText() {
+ if (_log == null) {
+ return "Empty entry.";
+ } else {
+ return _log;
+ }
+ }
+ /*
+ * Sets the text of the input area. This should only be
+ * called to set the initial text so only call before invoking
+ * open().
+ */
+ void setText(String text) {
+ _text.setText(text);
+ }
+ /*
+ * Returns a string representation of this class which
+ * the text contained in the input area of the dialog.
+ */
+ public String toString() {
+ return getText();
+ }
+}
+
+
diff --git a/core/org.eclipse.cdt.ui.tests/src/org/eclipse/cdt/testplugin/util/FocusTestPass.java b/core/org.eclipse.cdt.ui.tests/src/org/eclipse/cdt/testplugin/util/FocusTestPass.java
new file mode 100644
index 00000000000..0f83e03c1c2
--- /dev/null
+++ b/core/org.eclipse.cdt.ui.tests/src/org/eclipse/cdt/testplugin/util/FocusTestPass.java
@@ -0,0 +1,68 @@
+package org.eclipse.cdt.testplugin.util;
+
+
+/*
+ * (c) Copyright IBM Corp. 2000, 2001.
+ * All Rights Reserved.
+ */
+
+import java.util.ArrayList;
+
+
+/*
+ * This test pass verifies the initial focus of a dialog
+ * when it is given focus.
+ */
+public class FocusTestPass implements IDialogTestPass {
+ private static final int CHECKLIST_SIZE = 1;
+
+
+ /**
+ * @see IDialogTestPass#title()
+ */
+ public String title() {
+ return "Test Pass: Initial Focus";
+ }
+ /**
+ * @see IDialogTestPass#description()
+ */
+ public String description() {
+ return "Verify the initial focus of the dialogs.";
+ }
+ /**
+ * @see IDialogTestPass#label()
+ */
+ public String label() {
+ return "&Initial Focus";
+ }
+ /**
+ * @see IDialogTestPass#checkListTexts()
+ */
+ public ArrayList checkListTexts() {
+ ArrayList list = new ArrayList(CHECKLIST_SIZE);
+ list.add("&1) the initial focus is appropriate.");
+ return list;
+ }
+ /**
+ * @see IDialogTestPass#failureTexts()
+ * Size of the return array must be the same size as the checkListTexts'
+ * ArrayList.
+ */
+ public String[] failureTexts() {
+ String[] failureText = new String[CHECKLIST_SIZE];
+ failureText[0] = "The initial focus is inappropriate.";
+ return failureText;
+ }
+ /**
+ * @see IDialogTestPass#queryText()
+ */
+ public String queryText() {
+ return "Is the initial focus of the dialog correct?";
+ }
+ /**
+ * @see IDialogTestPass#getID()
+ */
+ public int getID() {
+ return VerifyDialog.TEST_FOCUS;
+ }
+}
\ No newline at end of file
diff --git a/core/org.eclipse.cdt.ui.tests/src/org/eclipse/cdt/testplugin/util/IDialogTestPass.java b/core/org.eclipse.cdt.ui.tests/src/org/eclipse/cdt/testplugin/util/IDialogTestPass.java
new file mode 100644
index 00000000000..be34fbadf8c
--- /dev/null
+++ b/core/org.eclipse.cdt.ui.tests/src/org/eclipse/cdt/testplugin/util/IDialogTestPass.java
@@ -0,0 +1,48 @@
+package org.eclipse.cdt.testplugin.util;
+
+
+import java.util.ArrayList;
+
+
+/*
+ * Interface to describe a visual test pass for a dialog test.
+ */
+public interface IDialogTestPass {
+ /*
+ * @return String The title of the test pass.
+ */
+ public String title();
+ /*
+ * @return String The description of the test pass.
+ */
+ public String description();
+ /*
+ * @return String The label of the test pass to be used
+ * in a selection list. The return includes an '&'
+ * if a mnemonic is desired.
+ */
+ public String label();
+ /*
+ * @return ArrayList A list of items to appear in a checklist.
+ * The items in the list must be Strings and should include an
+ * '&' if a mnemonic is desired.
+ */
+ public ArrayList checkListTexts();
+ /*
+ * @return String[] Associated failure messages that correspond
+ * to the checklist items. The size of this array should be the
+ * same size as the checklist.
+ */
+ public String[] failureTexts();
+ /*
+ * @return String The test that corresponds to the test pass to
+ * which the tester will respond with a 'yes' or 'no'.
+ */
+ public String queryText();
+ /*
+ * @return int A unique number that identifies the test pass.
+ */
+ public int getID();
+}
+
+
diff --git a/core/org.eclipse.cdt.ui.tests/src/org/eclipse/cdt/testplugin/util/SizingTestPass.java b/core/org.eclipse.cdt.ui.tests/src/org/eclipse/cdt/testplugin/util/SizingTestPass.java
new file mode 100644
index 00000000000..dc471637e66
--- /dev/null
+++ b/core/org.eclipse.cdt.ui.tests/src/org/eclipse/cdt/testplugin/util/SizingTestPass.java
@@ -0,0 +1,76 @@
+package org.eclipse.cdt.testplugin.util;
+
+
+/*
+ * (c) Copyright IBM Corp. 2000, 2001.
+ * All Rights Reserved.
+ */
+
+import java.util.ArrayList;
+
+
+/*
+ * This test pass verifies visually the sizing of the dialog and its
+ * widgets.
+ */
+class SizingTestPass implements IDialogTestPass {
+ private static final int CHECKLIST_SIZE = 5;
+
+
+ /**
+ * @see IDialogTestPass#title()
+ */
+ public String title() {
+ return "Test Pass: Sizing and Display";
+ }
+ /**
+ * @see IDialogTestPass#description()
+ */
+ public String description() {
+ return "Verify the sizing and display of the dialogs and widgets.";
+ }
+ /**
+ * @see IDialogTestPass#label()
+ */
+ public String label() {
+ return "&Sizing and Display";
+ }
+ /**
+ * @see IDialogTestPass#checkListTexts()
+ */
+ public ArrayList checkListTexts() {
+ ArrayList list = new ArrayList(CHECKLIST_SIZE);
+ list.add("&1) the correct dialog displays.");
+ 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("&4) all strings have been externalized properly.");
+ list.add("&5) all the widgets are viewable and not cut off.");
+ return list;
+ }
+ /**
+ * @see IDialogTestPass#failureTexts()
+ * Size of the return array must be the same size as the checkListTexts'
+ * ArrayList.
+ */
+ public String[] failureTexts() {
+ String[] failureText = new String[CHECKLIST_SIZE];
+ failureText[0] = "The wrong dialog displayed.";
+ failureText[1] = "The dialog is too large for the required resolution.";
+ failureText[2] = "Text labels are wrong or cut off.";
+ failureText[3] = "Some strings have not been externalized properly.";
+ failureText[4] = "Some widgets are cut off.";
+ return failureText;
+ }
+ /**
+ * @see IDialogTestPass#queryText()
+ */
+ public String queryText() {
+ return "Is the sizing and display of the dialog correct?";
+ }
+ /**
+ * @see IDialogTestPass#getID()
+ */
+ public int getID() {
+ return VerifyDialog.TEST_SIZING;
+ }
+}
\ No newline at end of file
diff --git a/core/org.eclipse.cdt.ui.tests/src/org/eclipse/cdt/testplugin/util/VerifyDialog.java b/core/org.eclipse.cdt.ui.tests/src/org/eclipse/cdt/testplugin/util/VerifyDialog.java
new file mode 100644
index 00000000000..a28a1e43524
--- /dev/null
+++ b/core/org.eclipse.cdt.ui.tests/src/org/eclipse/cdt/testplugin/util/VerifyDialog.java
@@ -0,0 +1,305 @@
+package org.eclipse.cdt.testplugin.util;
+
+
+import java.util.Iterator;
+
+
+import org.eclipse.jface.dialogs.Dialog;
+import org.eclipse.jface.dialogs.IDialogConstants;
+import org.eclipse.jface.dialogs.TitleAreaDialog;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.SelectionAdapter;
+import org.eclipse.swt.events.SelectionEvent;
+import org.eclipse.swt.events.ShellAdapter;
+import org.eclipse.swt.events.ShellEvent;
+import org.eclipse.swt.graphics.Point;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Button;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.Group;
+import org.eclipse.swt.widgets.Label;
+import org.eclipse.swt.widgets.Shell;
+
+
+/*
+ * This dialog is intended to verify a dialogs in a testing
+ * environment. The tester can test for sizing, initial focus,
+ * or accessibility.
+ */
+public class VerifyDialog extends TitleAreaDialog {
+ private int SIZING_WIDTH = 400;
+
+ private static int TEST_TYPE;
+ public static final int TEST_SIZING = 0;
+ public static final int TEST_FOCUS = 1;
+ public static final int TEST_ACCESS = 2;
+ private IDialogTestPass _dialogTests[] = new IDialogTestPass[3];
+
+
+ private Dialog _testDialog; //the dialog to test
+ private Point _testDialogSize;
+
+ private Label _queryLabel;
+ private Button _yesButton;
+ private Button _noButton;
+ private Button _checkList[];
+ private String _failureText;
+
+ /*
+ * Create an instance of the verification dialog.
+ */
+ public VerifyDialog(Shell parent) {
+ super(parent);
+ if ( !(TEST_TYPE <= 2) && !(TEST_TYPE >= 0) ) {
+ TEST_TYPE = TEST_SIZING;
+ }
+ _failureText = "";
+ _dialogTests[0] = new SizingTestPass();
+ _dialogTests[1] = new FocusTestPass();
+ _dialogTests[2] = new AccessibilityTestPass();
+ }
+
+ /* (non-Javadoc)
+ * Method declared on Window.
+ */
+ protected void configureShell(Shell newShell) {
+ super.configureShell(newShell);
+ newShell.setText("Dialog Verification");
+ setShellStyle(SWT.NONE);
+ }
+ /* (non-Javadoc)
+ * Method declared on Dialog.
+ */
+ protected void createButtonsForButtonBar(Composite parent) {
+ _yesButton = createButton(parent, IDialogConstants.YES_ID, IDialogConstants.YES_LABEL, true);
+ _noButton = createButton(parent, IDialogConstants.NO_ID, IDialogConstants.NO_LABEL, false);
+ }
+ /* (non-Javadoc)
+ * Method declared on Dialog.
+ */
+ protected void buttonPressed(int buttonId) {
+ if (IDialogConstants.YES_ID == buttonId) {
+ setReturnCode(IDialogConstants.YES_ID);
+ if (_testDialog.getShell() != null) {
+ _testDialog.close();
+ }
+ close();
+ } else if (IDialogConstants.NO_ID == buttonId) {
+ handleFailure();
+ }
+ }
+ /* (non-Javadoc)
+ * Method declared on Dialog.
+ */
+ protected Control createDialogArea(Composite parent) {
+ // top level composite
+ Composite parentComposite = (Composite)super.createDialogArea(parent);
+
+
+ // create a composite with standard margins and spacing
+ Composite composite = new Composite(parentComposite, SWT.NONE);
+ composite.setSize(SIZING_WIDTH, SWT.DEFAULT);
+ GridLayout layout = new GridLayout();
+ layout.marginHeight = convertVerticalDLUsToPixels(IDialogConstants.VERTICAL_MARGIN);
+ layout.marginWidth = convertHorizontalDLUsToPixels(IDialogConstants.HORIZONTAL_MARGIN);
+ layout.verticalSpacing = convertVerticalDLUsToPixels(IDialogConstants.VERTICAL_SPACING);
+ layout.horizontalSpacing = convertHorizontalDLUsToPixels(IDialogConstants.HORIZONTAL_SPACING);
+ composite.setLayout(layout);
+ composite.setLayoutData(new GridData(GridData.FILL_BOTH));
+
+
+ createTestSelectionGroup(composite);
+ createCheckListGroup(composite);
+
+
+ _queryLabel = new Label(composite, SWT.NONE);
+ _queryLabel.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
+
+ initializeTest();
+ return composite;
+ }
+ /*
+ * Group for selecting type of test.
+ */
+ private void createTestSelectionGroup(Composite parent) {
+ Group group = new Group(parent, SWT.SHADOW_NONE);
+ group.setText("Testing:");
+ group.setLayout( new GridLayout() );
+ GridData data = new GridData(GridData.FILL_HORIZONTAL);
+ group.setLayoutData(data);
+
+ for (int i = 0; i < _dialogTests.length; i++) {
+ Button radio = new Button(group, SWT.RADIO);
+ radio.setText( _dialogTests[i].label() );
+ final int testID = _dialogTests[i].getID();
+ radio.addSelectionListener(new SelectionAdapter() {
+ public void widgetSelected(SelectionEvent e) {
+ TEST_TYPE = testID;
+ initializeTest();
+ _yesButton.setEnabled(true);
+ }
+ });
+ if ( TEST_TYPE == _dialogTests[i].getID() ) {
+ radio.setSelection(true);
+ }
+ }
+ }
+ /*
+ * Initializes the checklist with empty checks.
+ */
+ private void createCheckListGroup(Composite parent) {
+ Group group = new Group(parent, SWT.SHADOW_NONE);
+ group.setText("Verify that:");
+ group.setLayout( new GridLayout() );
+ GridData data = new GridData(GridData.FILL_HORIZONTAL);
+ group.setLayoutData(data);
+
+ int checkListSize = 0;
+ for (int i = 0; i < _dialogTests.length; i++) {
+ int size = _dialogTests[i].checkListTexts().size();
+ if (size > checkListSize) {
+ checkListSize = size;
+ }
+ }
+ _checkList = new Button[checkListSize];
+ SelectionAdapter selectionAdapter = new SelectionAdapter() {
+ public void widgetSelected(SelectionEvent e) {
+ checkYesEnable();
+ }
+ };
+ for (int i = 0; i < checkListSize; i++) {
+ _checkList[i] = new Button(group, SWT.CHECK);
+ _checkList[i].addSelectionListener(selectionAdapter);
+ data = new GridData(GridData.HORIZONTAL_ALIGN_FILL);
+ data.grabExcessHorizontalSpace = true;
+ _checkList[i].setLayoutData(data);
+ }
+ }
+ /*
+ * Disables the yes button if any of the items in the checklist
+ * are unchecked. Enables the yes button otherwise.
+ */
+ private void checkYesEnable() {
+ boolean enable = true;
+ for (int i = 0; i < _checkList.length; i++) {
+ if ( !_checkList[i].getSelection() ) {
+ enable = false;
+ }
+ }
+ _yesButton.setEnabled(enable);
+ }
+ /*
+ * Initializes the checklist, banner texts, and query label
+ */
+ private void initializeTest() {
+ IDialogTestPass test = _dialogTests[TEST_TYPE];
+ setTitle( test.title() );
+ setMessage( test.description() );
+ Iterator iterator = test.checkListTexts().iterator();
+ for (int i = 0; i < _checkList.length; i++) {
+ if ( iterator.hasNext() ) {
+ _checkList[i].setText( iterator.next().toString() );
+ _checkList[i].setVisible(true);
+ _checkList[i].update();
+ } else {
+ _checkList[i].setVisible(false);
+ _checkList[i].update();
+ }
+ _checkList[i].setSelection(true);
+ }
+ _queryLabel.setText( test.queryText() );
+ }
+ public String getFailureText() {
+ return _failureText;
+ }
+ /*
+ * Can't open the verification dialog without a specified
+ * test dialog, this simply returns a failure and prevents
+ * opening. Should use open(Dialog) instead.
+ *
+ */
+ public int open() {
+ _failureText = "Testing dialog is required, use VerifyDialog::open(Dialog)";
+ return IDialogConstants.NO_ID;
+ }
+ /*
+ * Opens the verification dialog to test the specified dialog.
+ */
+ public int open(Dialog testDialog) {
+ if (getShell() == null) {
+ create();
+ }
+ getShell().setLocation(0, 0);
+ getShell().setSize(Math.max(SIZING_WIDTH, getShell().getSize().x), getShell().getSize().y);
+ _testDialog = testDialog;
+ if (_testDialog.getShell() == null) {
+ _testDialog.create();
+ }
+ _testDialogSize = _testDialog.getShell().getSize();
+ openNewTestDialog();
+
+ return super.open();
+ }
+ /*
+ * Opens the dialog to be verified.
+ */
+ private void openNewTestDialog() {
+ if (_testDialog.getShell() == null) {
+ _testDialog.create();
+ }
+ _testDialog.setBlockOnOpen(false);
+ _testDialog.getShell().setLocation(getShell().getSize().x + 1, 0);
+ _testDialog.getShell().setSize(_testDialogSize);
+ _testDialog.getShell().addShellListener(new ShellAdapter() {
+ public void shellClosed(ShellEvent e) {
+ e.doit = false;
+ }
+
+ });
+ _testDialog.open();
+ }
+ /*
+ * The test dialog failed, open the failure dialog.
+ */
+ private void handleFailure() {
+ IDialogTestPass test = _dialogTests[TEST_TYPE];
+ StringBuffer text = new StringBuffer();
+ String label = test.label();
+ label = label.substring(0, label.indexOf("&")) +
+ label.substring(label.indexOf("&") + 1);
+ text.append(label).
+ append(" failed on the ").
+ append(SWT.getPlatform()).
+ append(" platform:\n");
+
+ String failureMessages[] = test.failureTexts();
+ for (int i = 0; i < test.checkListTexts().size(); i++) {
+ if ( !_checkList[i].getSelection() ) {
+ text.append("- ").append(failureMessages[i]).append("\n");
+ }
+ }
+ FailureDialog dialog = new FailureDialog( getShell() );
+ dialog.create();
+ String temp = text.toString();
+ dialog.setText( text.toString() );
+ if (dialog.open() == IDialogConstants.OK_ID) {
+ _failureText = dialog.toString();
+ setReturnCode(IDialogConstants.NO_ID);
+ if (_testDialog.getShell() != null) {
+ _testDialog.close();
+ }
+ close();
+ }
+ }
+ /*
+ * In case the shell was closed by a means other than
+ * the NO button.
+ */
+ protected void handleShellCloseEvent() {
+ handleFailure();
+ }
+}
+
+
diff --git a/core/org.eclipse.cdt.ui.tests/test.xml b/core/org.eclipse.cdt.ui.tests/test.xml
new file mode 100644
index 00000000000..45036dab5c6
--- /dev/null
+++ b/core/org.eclipse.cdt.ui.tests/test.xml
@@ -0,0 +1,51 @@
+
+
+IParitionTokenScanner
s for conformance and performance.
+ */
+public class PartitionTokenScannerTest extends TestCase {
+
+ private IPartitionTokenScanner fReference;
+ private IPartitionTokenScanner fTestee;
+
+ public PartitionTokenScannerTest(String name) {
+ super(name);
+ }
+
+ protected void setUp() {
+ fReference= new CPartitionScanner();
+ fTestee= new FastCPartitionScanner();
+ }
+
+ // read sample java file
+ private IDocument getDocument(String name, String lineDelimiter) {
+ try {
+ InputStream stream= getClass().getResourceAsStream(name);
+ BufferedReader reader= new BufferedReader(new InputStreamReader(stream));
+
+ StringBuffer buffer= new StringBuffer();
+ String line= reader.readLine();
+ while (line != null) {
+ buffer.append(line);
+ buffer.append(lineDelimiter);
+ line= reader.readLine();
+ }
+
+ return new Document(buffer.toString());
+
+ } catch (IOException e) {
+ }
+
+ return null;
+ }
+
+ private static IDocument getRandomDocument(int size) {
+ final char[] characters= {'/', '*', '\'', '"', '\r', '\n', '\\'};
+ final StringBuffer buffer= new StringBuffer();
+
+ for (int i= 0; i < size; i++) {
+ final int randomIndex= (int) (Math.random() * characters.length);
+ buffer.append(characters[randomIndex]);
+ }
+
+ return new Document(buffer.toString());
+ }
+
+ public static Test suite() {
+ return new TestSuite(PartitionTokenScannerTest.class);
+ }
+
+ public void testTestCaseLF() {
+ testConformance(getDocument("TestCase.txt", "\n"));
+ }
+
+ public void testTestCaseCRLF() {
+ testConformance(getDocument("TestCase.txt", "\r\n"));
+ }
+
+ public void testTestCaseCR() {
+ testConformance(getDocument("TestCase.txt", "\r"));
+ }
+
+ public void testTestCase2LF() {
+ testConformance(getDocument("TestCase2.txt", "\n"));
+ }
+
+ public void testTestCase2CRLF() {
+ testConformance(getDocument("TestCase2.txt", "\r\n"));
+ }
+
+ public void testTestCase2CR() {
+ testConformance(getDocument("TestCase2.txt", "\r"));
+ }
+
+// XXX not fully passing because of "\setUp
tearDown
.+ * public class MathTest extends TestCase { + * protected double fValue1; + * protected double fValue2; + * + * public MathTest(String name) { + * super(name); + * } + * + * protected void setUp() { + * fValue1= 2.0; + * fValue2= 3.0; + * } + * } + *+ * + * For each test implement a method which interacts + * with the fixture. Verify the expected results with assertions specified + * by calling
assert
with a boolean.
+ * + * protected void testAdd() { + * double result= fValue1 + fValue2; + * assert(result == 5.0); + * } + *+ * Once the methods are defined you can run them. The framework supports + * both a static type safe and more dynamic way to run a test. + * In the static way you override the runTest method and define the method to + * be invoked. A convenient way to do so is with an anonymous inner class. + *
+ * Test test= new MathTest("add") { + * public void runTest() { + * testAdd(); + * } + * }; + * test.run(); + *+ * The dynamic way uses reflection to implement
runTest
. It dynamically finds
+ * and invokes a method.
+ * In this case the name of the test case has to correspond to the test method
+ * to be run.
+ * + * Test= new MathTest("testAdd"); + * test.run(); + *+ * The tests to be run can be collected into a TestSuite. JUnit provides + * different test runners which can run a test suite and collect the results. + * A test runner either expects a static method
suite
as the entry
+ * point to get a test to run or it will extract the suite automatically.
+ * + * public static Test suite() { + * suite.addTest(new MathTest("testAdd")); + * suite.addTest(new MathTest("testDivideByZero")); + * return suite; + * } + *+ * @see TestResult + * @see TestSuite + */ + +public abstract class TestCase extends Assert implements Test { + /** + * the name of the test case + */ + private String fName; + + /** + * No-arg constructor to enable serialization. This method + * is not intended to be used by mere mortals. + */ + TestCase() { + fName= null; + } + + /** + * Constructs a test case with the given name. + */ + public TestCase(String name) { + fName= name; + } + + /** + * Counts the number of test cases executed by run(TestResult result). + */ + public int countTestCases() { + return 1; + } + /** + * Creates a default TestResult object + * + * @see TestResult + */ + protected TestResult createResult() { + return new TestResult(); + } + /** + * Gets the name of the test case. + * @deprecated use getName() + */ + public String name() { + return fName; + } + /** + * A convenience method to run this test, collecting the results with a + * default TestResult object. + * + * @see TestResult + */ + public TestResult run() { + TestResult result= createResult(); + run(result); + return result; + } + /** + * Runs the test case and collects the results in TestResult. + */ + public void run(TestResult result) { + result.run(this); + } + /** + * Runs the bare test sequence. + * @exception Throwable if any exception is thrown + */ + public void runBare() throws Throwable { + setUp(); + try { + runTest(); + } + finally { + tearDown(); + } + } + /** + * Override to run the test and assert its state. + * @exception Throwable if any exception is thrown + */ + protected void runTest() throws Throwable { + Method runMethod= null; + try { + // use getMethod to get all public inherited + // methods. getDeclaredMethods returns all + // methods of this class but excludes the + // inherited ones. + runMethod= getClass().getMethod(fName, null); + } catch (NoSuchMethodException e) { + fail("Method \""+fName+"\" not found"); + } + if (!Modifier.isPublic(runMethod.getModifiers())) { + fail("Method \""+fName+"\" should be public"); + } + + try { + runMethod.invoke(this, new Class[0]); + } + catch (InvocationTargetException e) { + e.fillInStackTrace(); + throw e.getTargetException(); + } + catch (IllegalAccessException e) { + e.fillInStackTrace(); + throw e; + } + } + /** + * Sets up the fixture, for example, open a network connection. + * This method is called before a test is executed. + */ + protected void setUp() throws Exception { + } + /** + * Tears down the fixture, for example, close a network connection. + * This method is called after a test is executed. + */ + protected void tearDown() throws Exception { + } + /** + * Returns a string representation of the test case + */ + public String toString() { + return name()+"("+getClass().getName()+")"; + } + /** + * Gets the name of a TestCase + * @return returns a String + */ + public String getName() { + return fName; + } + + /** + * Sets the name of a TestCase + * @param name The name to set + */ + public void setName(String name) { + fName= name; + } + +} \ No newline at end of file diff --git a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/TestCase2.txt b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/TestCase2.txt new file mode 100644 index 00000000000..f9a86b87366 --- /dev/null +++ b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/TestCase2.txt @@ -0,0 +1,66 @@ +package org.eclipse.jdt.ui.tests.text; + +/** + * javadoc + */ +public class TestCase2 { + /* + * multi line comment + */ + private void foo() { + // single line comment + int value= 42; + + /**/ + + String s= "string"; + char c= 'c'; + + String s2= "string2"/* ads*/; + + Nastyness: ""/**/''""; + + // open strings and characters + 'open characters + "open strings + + // all state transitions + /* multi line comment */// single line comment + /* multi line comment *//* multi line comment */ + /* multi line comment *//** java doc */ + /* multi line comment */'character' + /* multi line comment */"string" + /* java doc */// single line comment + /* java doc *//* multi line comment */ + /* java doc *//** java doc */ + /* java doc */'character' + /* java doc */"string" + "string"// single line comment + "string"//* multi line comment */ + "string"/** java doc */ + "string"'character' + "string""string" + 'character'// single line comment + 'character'"//* multi line comment */ + 'character'/** java doc */ + 'character''character' + 'character'"string" + + // more nasty cases + /'asdf + /"asdf + + /** + * // single line comment inside javadoc + */ + + /* + * // single line comment inside multi-line comment + */ + + // would fail conformance, but it's ok + "