diff --git a/codan/org.eclipse.cdt.codan.core.test/src/org/eclipse/cdt/codan/internal/checkers/ui/quickfix/CaseBreakQuickFixTest.java b/codan/org.eclipse.cdt.codan.core.test/src/org/eclipse/cdt/codan/internal/checkers/ui/quickfix/CaseBreakQuickFixTest.java index c85f489c7a5..f9a5d2323eb 100644 --- a/codan/org.eclipse.cdt.codan.core.test/src/org/eclipse/cdt/codan/internal/checkers/ui/quickfix/CaseBreakQuickFixTest.java +++ b/codan/org.eclipse.cdt.codan.core.test/src/org/eclipse/cdt/codan/internal/checkers/ui/quickfix/CaseBreakQuickFixTest.java @@ -28,7 +28,7 @@ public class CaseBreakQuickFixTest extends QuickFixTestCase { // case 2: // } // } - public void testMiddleCase() { + public void testMiddleCase() throws Exception { loadcode(getAboveComment()); String result = runQuickFixOneFile(); assertContainedIn("break; case 2:", result); @@ -41,7 +41,7 @@ public class CaseBreakQuickFixTest extends QuickFixTestCase { // hello(); // } // } - public void testLastCase() { + public void testLastCase() throws Exception { loadcode(getAboveComment()); String result = runQuickFixOneFile(); assertContainedIn("break; }", result); @@ -55,9 +55,9 @@ public class CaseBreakQuickFixTest extends QuickFixTestCase { // } // } // } - public void testLastCaseComp() { + public void testLastCaseComp() throws Exception { loadcode(getAboveComment()); String result = runQuickFixOneFile(); - assertContainedIn("hello();\n\nbreak;", result); + assertContainedIn("hello();\t\tbreak;", result); } } diff --git a/codan/org.eclipse.cdt.codan.core.test/src/org/eclipse/cdt/codan/internal/checkers/ui/quickfix/CatchByReferenceQuickFixTest.java b/codan/org.eclipse.cdt.codan.core.test/src/org/eclipse/cdt/codan/internal/checkers/ui/quickfix/CatchByReferenceQuickFixTest.java index 9849aaea806..3d28009ae56 100644 --- a/codan/org.eclipse.cdt.codan.core.test/src/org/eclipse/cdt/codan/internal/checkers/ui/quickfix/CatchByReferenceQuickFixTest.java +++ b/codan/org.eclipse.cdt.codan.core.test/src/org/eclipse/cdt/codan/internal/checkers/ui/quickfix/CatchByReferenceQuickFixTest.java @@ -6,7 +6,7 @@ * http://www.eclipse.org/legal/epl-v10.html * * Contributors: - * Tomasz Wesolowski - initial API and implementation + * Tomasz Wesolowski - initial API and implementation *******************************************************************************/ package org.eclipse.cdt.codan.internal.checkers.ui.quickfix; @@ -93,5 +93,4 @@ public class CatchByReferenceQuickFixTest extends QuickFixTestCase { String result = runQuickFixOneFile(); assertContainedIn("catch (const C &)", result); //$NON-NLS-1$ } - } diff --git a/codan/org.eclipse.cdt.codan.core.test/src/org/eclipse/cdt/codan/internal/checkers/ui/quickfix/CreateLocalVariableQuickFixTest.java b/codan/org.eclipse.cdt.codan.core.test/src/org/eclipse/cdt/codan/internal/checkers/ui/quickfix/CreateLocalVariableQuickFixTest.java index 2cdec1d9e6a..f721c7ade19 100644 --- a/codan/org.eclipse.cdt.codan.core.test/src/org/eclipse/cdt/codan/internal/checkers/ui/quickfix/CreateLocalVariableQuickFixTest.java +++ b/codan/org.eclipse.cdt.codan.core.test/src/org/eclipse/cdt/codan/internal/checkers/ui/quickfix/CreateLocalVariableQuickFixTest.java @@ -43,7 +43,7 @@ public class CreateLocalVariableQuickFixTest extends QuickFixTestCase { // void func() { // aChar = 'a'; // } - public void testChar() { + public void testChar() throws Exception { loadcode(getAboveComment()); String result = runQuickFixOneFile(); assertContainedIn("char aChar;", result); //$NON-NLS-1$ @@ -52,7 +52,7 @@ public class CreateLocalVariableQuickFixTest extends QuickFixTestCase { // void func() { // aDouble = 40.; // } - public void testDouble() { + public void testDouble() throws Exception { loadcode(getAboveComment()); String result = runQuickFixOneFile(); assertContainedIn("double aDouble;", result); //$NON-NLS-1$ @@ -61,7 +61,7 @@ public class CreateLocalVariableQuickFixTest extends QuickFixTestCase { // void func() { // aString = "foo"; // } - public void testString() { + public void testString() throws Exception { loadcode(getAboveComment()); String result = runQuickFixOneFile(); assertContainedIn("const char* aString;", result); //$NON-NLS-1$ @@ -70,7 +70,7 @@ public class CreateLocalVariableQuickFixTest extends QuickFixTestCase { // void func() { // aWString = L"foo"; // } - public void testWString() { + public void testWString() throws Exception { loadcode(getAboveComment()); String result = runQuickFixOneFile(); assertContainedIn("const wchar_t* aWString;", result); //$NON-NLS-1$ @@ -79,7 +79,7 @@ public class CreateLocalVariableQuickFixTest extends QuickFixTestCase { // void func() { // aFuncPtr = func; // } - public void testFuncPtr() { + public void testFuncPtr() throws Exception { loadcode(getAboveComment()); String result = runQuickFixOneFile(); assertContainedIn("void (*aFuncPtr)();", result); //$NON-NLS-1$ diff --git a/codan/org.eclipse.cdt.codan.core.test/src/org/eclipse/cdt/codan/internal/checkers/ui/quickfix/QuickFixTestCase.java b/codan/org.eclipse.cdt.codan.core.test/src/org/eclipse/cdt/codan/internal/checkers/ui/quickfix/QuickFixTestCase.java index ba15bee64cd..d2976091416 100644 --- a/codan/org.eclipse.cdt.codan.core.test/src/org/eclipse/cdt/codan/internal/checkers/ui/quickfix/QuickFixTestCase.java +++ b/codan/org.eclipse.cdt.codan.core.test/src/org/eclipse/cdt/codan/internal/checkers/ui/quickfix/QuickFixTestCase.java @@ -6,7 +6,7 @@ * http://www.eclipse.org/legal/epl-v10.html * * Contributors: - * QNX Software Systems (Alena Laskavaia) - initial API and implementation + * QNX Software Systems (Alena Laskavaia) - initial API and implementation *******************************************************************************/ package org.eclipse.cdt.codan.internal.checkers.ui.quickfix; @@ -17,7 +17,6 @@ import org.eclipse.cdt.codan.core.test.CheckerTestCase; import org.eclipse.cdt.codan.core.test.TestUtils; import org.eclipse.cdt.codan.internal.ui.CodanUIActivator; import org.eclipse.cdt.codan.ui.AbstractCodanCMarkerResolution; -import org.eclipse.cdt.core.model.CModelException; import org.eclipse.core.resources.IMarker; import org.eclipse.core.runtime.CoreException; import org.eclipse.jface.preference.IPreferenceStore; @@ -27,19 +26,19 @@ import org.eclipse.swt.widgets.Display; import org.eclipse.ui.IWorkbenchPage; import org.eclipse.ui.IWorkbenchPart; import org.eclipse.ui.IWorkbenchWindow; -import org.eclipse.ui.PartInitException; import org.eclipse.ui.PlatformUI; /** - * TODO: add description + * Abstract base class for Quck Fix tests. */ +@SuppressWarnings("restriction") public abstract class QuickFixTestCase extends CheckerTestCase { AbstractCodanCMarkerResolution quickFix; Display display; /** * Dispatch ui events for at least msec - milliseconds - * + * * @param msec - * milliseconds delay * @param display - @@ -60,7 +59,7 @@ public abstract class QuickFixTestCase extends CheckerTestCase { IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow(); IWorkbenchPage activePage = window.getActivePage(); IWorkbenchPart activePart = activePage.getActivePart(); - if (activePart.getTitle().equals("Welcome")) { + if (activePart.getTitle().equals("Welcome")) { //$NON-NLS-1$ //activePage.close(); activePart.dispose(); } @@ -69,7 +68,6 @@ public abstract class QuickFixTestCase extends CheckerTestCase { } } - @SuppressWarnings("restriction") @Override public void setUp() throws Exception { super.setUp(); @@ -77,7 +75,7 @@ public abstract class QuickFixTestCase extends CheckerTestCase { display = PlatformUI.getWorkbench().getDisplay(); closeWelcome(); IPreferenceStore store = CodanUIActivator.getDefault().getPreferenceStore(cproject.getProject()); - // turn off editor reconsiler + // turn off editor reconciler store.setValue(PreferenceConstants.P_RUN_IN_EDITOR, false); } @@ -105,31 +103,15 @@ public abstract class QuickFixTestCase extends CheckerTestCase { return new TextSelection(code.indexOf(string), string.length()); } - /** - * @return - * @throws CModelException - * @throws PartInitException - * @throws IOException - * @throws CoreException - */ - public String runQuickFixOneFile() { + public String runQuickFixOneFile() throws IOException, CoreException { // need to load before running codan because otherwise marker is lost when doing quick fix 8[] - try { - runCodan(); - doRunQuickFix(); - dispatch(500); - String result = TestUtils.loadFile(currentIFile.getContents()); - return result; - } catch (Exception e) { - e.printStackTrace(); - fail(e.getMessage()); - return null; - } + runCodan(); + doRunQuickFix(); + dispatch(500); + String result = TestUtils.loadFile(currentIFile.getContents()); + return result; } - /** - * - */ public void doRunQuickFix() { for (int i = 0; i < markers.length; i++) { IMarker marker = markers[i]; diff --git a/codan/org.eclipse.cdt.codan.core.test/src/org/eclipse/cdt/codan/internal/checkers/ui/quickfix/SuggestedParenthesisQuickFixTest.java b/codan/org.eclipse.cdt.codan.core.test/src/org/eclipse/cdt/codan/internal/checkers/ui/quickfix/SuggestedParenthesisQuickFixTest.java index e06baa2f08e..14195e97256 100644 --- a/codan/org.eclipse.cdt.codan.core.test/src/org/eclipse/cdt/codan/internal/checkers/ui/quickfix/SuggestedParenthesisQuickFixTest.java +++ b/codan/org.eclipse.cdt.codan.core.test/src/org/eclipse/cdt/codan/internal/checkers/ui/quickfix/SuggestedParenthesisQuickFixTest.java @@ -6,25 +6,22 @@ * http://www.eclipse.org/legal/epl-v10.html * * Contributors: - * QNX Software Systems (Alena Laskavaia) - initial API and implementation + * QNX Software Systems (Alena Laskavaia) - initial API and implementation *******************************************************************************/ package org.eclipse.cdt.codan.internal.checkers.ui.quickfix; +import java.io.File; +import java.io.FileInputStream; + import org.eclipse.cdt.codan.core.test.TestUtils; import org.eclipse.cdt.codan.ui.AbstractCodanCMarkerResolution; import org.eclipse.cdt.internal.ui.util.EditorUtility; -import org.eclipse.core.runtime.CoreException; - -import java.io.File; -import java.io.FileInputStream; -import java.io.FileNotFoundException; -import java.io.IOException; /** * Test for quick fix for suggested parenthesis */ +@SuppressWarnings("restriction") public class SuggestedParenthesisQuickFixTest extends QuickFixTestCase { - @SuppressWarnings("restriction") @Override public AbstractCodanCMarkerResolution createQuickFix() { return new SuggestedParenthesisQuickFix(); @@ -34,7 +31,7 @@ public class SuggestedParenthesisQuickFixTest extends QuickFixTestCase { // int a=1,b=3; // if (b+a && a>b || b-a) b--; // error here // } - public void testSimple() throws IOException, CoreException { + public void testSimple() throws Exception { loadcode(getAboveComment()); String result = runQuickFixOneFile(); assertContainedIn("(b+a && a>b)", result); //$NON-NLS-1$ @@ -52,23 +49,18 @@ public class SuggestedParenthesisQuickFixTest extends QuickFixTestCase { * this test is using two files, there was not actually bugs here so * quick fix is not called */ - public void test2FilesExample() throws FileNotFoundException, IOException { + public void test2FilesExample() throws Exception { CharSequence[] code = getContents(2); File f1 = loadcode(code[0].toString()); File f2 = loadcode(code[1].toString()); // lets pretend marker is found in main.c but fixes go in both files, // to check do something like this - try { - EditorUtility.openInEditor(f2); - runCodan(); - doRunQuickFix(); - String result_main = TestUtils.loadFile(new FileInputStream(f2)); - String result_header = TestUtils.loadFile(new FileInputStream(f1)); - assertContainedIn("foo", result_main); //$NON-NLS-1$ - assertContainedIn("foo", result_header); //$NON-NLS-1$ - } catch (Exception e) { - e.printStackTrace(); - fail(e.getMessage()); - } + EditorUtility.openInEditor(f2); + runCodan(); + doRunQuickFix(); + String result_main = TestUtils.loadFile(new FileInputStream(f2)); + String result_header = TestUtils.loadFile(new FileInputStream(f1)); + assertContainedIn("foo", result_main); //$NON-NLS-1$ + assertContainedIn("foo", result_header); //$NON-NLS-1$ } }