Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMarc-Andre Laperle2011-07-21 12:57:53 -0400
committerMarc-Andre Laperle2011-07-21 12:57:53 -0400
commitdb669ba9633e67facd61a36cc34361d8363e1e56 (patch)
tree938ae317a532ccdd1068e9d302d7f79578280586 /codan/org.eclipse.cdt.codan.core.test
parent62c3d22313b44edf792f16ee24aec47d7e447ed4 (diff)
downloadorg.eclipse.cdt-db669ba9633e67facd61a36cc34361d8363e1e56.tar.gz
org.eclipse.cdt-db669ba9633e67facd61a36cc34361d8363e1e56.tar.xz
org.eclipse.cdt-db669ba9633e67facd61a36cc34361d8363e1e56.zip
Bug 348191 - Quick fix for catch by value should propose to replace by a
const reference Bug 352263 - [qf] Catch by reference quick fix places & at a wrong place when no space after the type
Diffstat (limited to 'codan/org.eclipse.cdt.codan.core.test')
-rw-r--r--codan/org.eclipse.cdt.codan.core.test/src/org/eclipse/cdt/codan/core/test/AutomatedIntegrationSuite.java2
-rw-r--r--codan/org.eclipse.cdt.codan.core.test/src/org/eclipse/cdt/codan/internal/checkers/ui/quickfix/CatchByReferenceQuickFixTest.java97
-rw-r--r--codan/org.eclipse.cdt.codan.core.test/src/org/eclipse/cdt/codan/internal/checkers/ui/quickfix/QuickFixTestCase.java8
3 files changed, 107 insertions, 0 deletions
diff --git a/codan/org.eclipse.cdt.codan.core.test/src/org/eclipse/cdt/codan/core/test/AutomatedIntegrationSuite.java b/codan/org.eclipse.cdt.codan.core.test/src/org/eclipse/cdt/codan/core/test/AutomatedIntegrationSuite.java
index b70376f252..b832bcd40f 100644
--- a/codan/org.eclipse.cdt.codan.core.test/src/org/eclipse/cdt/codan/core/test/AutomatedIntegrationSuite.java
+++ b/codan/org.eclipse.cdt.codan.core.test/src/org/eclipse/cdt/codan/core/test/AutomatedIntegrationSuite.java
@@ -30,6 +30,7 @@ import org.eclipse.cdt.codan.core.internal.checkers.StatementHasNoEffectCheckerT
import org.eclipse.cdt.codan.core.internal.checkers.SuggestedParenthesisCheckerTest;
import org.eclipse.cdt.codan.core.internal.checkers.SuspiciousSemicolonCheckerTest;
import org.eclipse.cdt.codan.core.internal.checkers.UnusedSymbolInFileScopeCheckerTest;
+import org.eclipse.cdt.codan.internal.checkers.ui.quickfix.CatchByReferenceQuickFixTest;
import org.eclipse.cdt.codan.internal.checkers.ui.quickfix.CreateLocalVariableQuickFixTest;
import org.eclipse.cdt.codan.internal.checkers.ui.quickfix.SuggestedParenthesisQuickFixTest;
@@ -72,6 +73,7 @@ public class AutomatedIntegrationSuite extends TestSuite {
// quick fixes
suite.addTestSuite(CreateLocalVariableQuickFixTest.class);
suite.addTestSuite(SuggestedParenthesisQuickFixTest.class);
+ suite.addTestSuite(CatchByReferenceQuickFixTest.class);
return suite;
}
}
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
new file mode 100644
index 0000000000..9849aaea80
--- /dev/null
+++ b/codan/org.eclipse.cdt.codan.core.test/src/org/eclipse/cdt/codan/internal/checkers/ui/quickfix/CatchByReferenceQuickFixTest.java
@@ -0,0 +1,97 @@
+/*******************************************************************************
+ * Copyright (c) 2011 Tomasz Wesolowski and others
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Tomasz Wesolowski - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.cdt.codan.internal.checkers.ui.quickfix;
+
+import org.eclipse.cdt.codan.internal.checkers.CatchByReference;
+import org.eclipse.cdt.codan.ui.AbstractCodanCMarkerResolution;
+
+/**
+ * @author Tomasz Wesolowski
+ */
+public class CatchByReferenceQuickFixTest extends QuickFixTestCase {
+
+ @Override
+ public void setUp() throws Exception {
+ super.setUp();
+ enableProblems(CatchByReference.ER_ID);
+ }
+
+ @Override
+ public boolean isCpp() {
+ return true;
+ }
+
+ @Override
+ protected AbstractCodanCMarkerResolution createQuickFix() {
+ return null; // quick fix to be chosen per test
+ }
+
+ // struct C {
+ // };
+ // void foo() {
+ // try {
+ // } catch (C exception) {
+ // }
+ // }
+ @SuppressWarnings("restriction")
+ public void testCatchByReference() throws Exception {
+ setQuickFix(new CatchByReferenceQuickFix());
+ loadcode(getAboveComment());
+ String result = runQuickFixOneFile();
+ assertContainedIn("catch (C & exception)", result); //$NON-NLS-1$
+ }
+
+ // struct C {
+ // };
+ // void foo() {
+ // try {
+ // } catch (C) {
+ // }
+ // }
+ @SuppressWarnings("restriction")
+ public void testCatchByReferenceNoDeclName() throws Exception {
+ setQuickFix(new CatchByReferenceQuickFix());
+ loadcode(getAboveComment());
+ String result = runQuickFixOneFile();
+ assertContainedIn("catch (C &)", result); //$NON-NLS-1$
+ }
+
+ // struct C {
+ // };
+ // void foo() {
+ // try {
+ // } catch (C exception) {
+ // }
+ // }
+ @SuppressWarnings("restriction")
+ public void testCatchByConstReference() throws Exception {
+ setQuickFix(new CatchByConstReferenceQuickFix());
+ loadcode(getAboveComment());
+ String result = runQuickFixOneFile();
+ assertContainedIn("catch (const C & exception)", result); //$NON-NLS-1$
+ }
+
+ // struct C {
+ // };
+ // void foo() {
+ // try {
+ // } catch (C) {
+ // }
+ // }
+ @SuppressWarnings("restriction")
+ public void testCatchByConstReferenceNoDeclName() throws Exception {
+ setQuickFix(new CatchByConstReferenceQuickFix());
+ loadcode(getAboveComment());
+ 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/QuickFixTestCase.java b/codan/org.eclipse.cdt.codan.core.test/src/org/eclipse/cdt/codan/internal/checkers/ui/quickfix/QuickFixTestCase.java
index 0782edc547..ba15bee64c 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
@@ -146,4 +146,12 @@ public abstract class QuickFixTestCase extends CheckerTestCase {
public void assertContainedIn(String expected, String result) {
assertTrue("Text <" + expected + "> not found in <" + result + ">", result.contains(expected)); //$NON-NLS-1$//$NON-NLS-2$ //$NON-NLS-3$
}
+
+ /**
+ * Changes the quick fix to be used
+ * @param quickFix
+ */
+ public void setQuickFix(AbstractCodanCMarkerResolution quickFix) {
+ this.quickFix = quickFix;
+ }
}

Back to the top