From fc70a0f70db7dff1e8bb335052e3bf0501cbfcd5 Mon Sep 17 00:00:00 2001 From: Alena Laskavaia Date: Mon, 24 May 2010 14:16:39 +0000 Subject: [PATCH] Bug 313622 Tests for "Make checking for !a && b optional and off by default" --- .../SuggestedParenthesisCheckerTest.java | 58 +++++++++---------- .../cdt/codan/core/test/CheckerTestCase.java | 17 ++++++ 2 files changed, 44 insertions(+), 31 deletions(-) diff --git a/codan/org.eclipse.cdt.codan.core.test/src/org/eclipse/cdt/codan/core/internal/checkers/SuggestedParenthesisCheckerTest.java b/codan/org.eclipse.cdt.codan.core.test/src/org/eclipse/cdt/codan/core/internal/checkers/SuggestedParenthesisCheckerTest.java index 2c87699c7a5..d28260b4a04 100644 --- a/codan/org.eclipse.cdt.codan.core.test/src/org/eclipse/cdt/codan/core/internal/checkers/SuggestedParenthesisCheckerTest.java +++ b/codan/org.eclipse.cdt.codan.core.test/src/org/eclipse/cdt/codan/core/internal/checkers/SuggestedParenthesisCheckerTest.java @@ -10,41 +10,42 @@ *******************************************************************************/ package org.eclipse.cdt.codan.core.internal.checkers; +import org.eclipse.cdt.codan.core.param.IProblemPreference; import org.eclipse.cdt.codan.core.test.CheckerTestCase; +import org.eclipse.cdt.codan.internal.checkers.SuggestedParenthesisChecker; /** * Test for {@see SuggestedParenthesisChecker} class * */ public class SuggestedParenthesisCheckerTest extends CheckerTestCase { - -// main() { -// int a=1,b=3; -// if (!a<10) b=4; // error here on line 3 -// } + // main() { + // int a=1,b=3; + // if (!a<10) b=4; // error here on line 3 + // } public void test1() { + IProblemPreference macro = getPreference( + SuggestedParenthesisChecker.ER_ID, + SuggestedParenthesisChecker.PARAM_NOT); + macro.setValue(Boolean.TRUE); loadCodeAndRun(getAboveComment()); checkErrorLine(3); } - - -// main() { -// int a=1,b=3; -// -// if (b+a && a>b || b-a) b--; // error here on line 4 -// } + // main() { + // int a=1,b=3; + // + // if (b+a && a>b || b-a) b--; // error here on line 4 + // } public void test2() { loadCodeAndRun(getAboveComment()); checkErrorLine(4); } - - -// main() { -// int a=1,b=3; -// if (!(a<10)) b=4; // no error here on line 3 -// } + // main() { + // int a=1,b=3; + // if (!(a<10)) b=4; // no error here on line 3 + // } public void test3() { loadCodeAndRun(getAboveComment()); checkNoErrors(); @@ -54,29 +55,24 @@ public class SuggestedParenthesisCheckerTest extends CheckerTestCase { // int a=1,b=3; // if (a && !b) b=4; // no error here on line 3 // } - public void test_lastnot() { loadCodeAndRun(getAboveComment()); checkNoErrors(); } - - -// main() { -// int a=1,b=3; -// if ((!a) && 10) b=4; // no error here on line 3 -// } + // main() { + // int a=1,b=3; + // if ((!a) && 10) b=4; // no error here on line 3 + // } public void test_fixed() { loadCodeAndRun(getAboveComment()); checkNoErrors(); } - - -// main() { -// int a=1,b=3; -// if (a && b & a) b=4; // error here on line 3 -// } + // main() { + // int a=1,b=3; + // if (a && b & a) b=4; // error here on line 3 + // } public void test_mixedbin() { loadCodeAndRun(getAboveComment()); checkErrorLine(3); diff --git a/codan/org.eclipse.cdt.codan.core.test/src/org/eclipse/cdt/codan/core/test/CheckerTestCase.java b/codan/org.eclipse.cdt.codan.core.test/src/org/eclipse/cdt/codan/core/test/CheckerTestCase.java index cc2f973d34f..6a5d949fd98 100644 --- a/codan/org.eclipse.cdt.codan.core.test/src/org/eclipse/cdt/codan/core/test/CheckerTestCase.java +++ b/codan/org.eclipse.cdt.codan.core.test/src/org/eclipse/cdt/codan/core/test/CheckerTestCase.java @@ -14,7 +14,10 @@ import java.io.File; import java.io.IOException; import org.eclipse.cdt.codan.core.CodanRuntime; +import org.eclipse.cdt.codan.core.model.IProblem; import org.eclipse.cdt.codan.core.model.IProblemReporter; +import org.eclipse.cdt.codan.core.param.IProblemPreference; +import org.eclipse.cdt.codan.core.param.MapProblemPreference; import org.eclipse.core.resources.IMarker; import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.NullProgressMonitor; @@ -114,4 +117,18 @@ public class CheckerTestCase extends CodanTestCase { fail(e.getMessage()); } } + + /** + * @param problemId + * @param paramId + * @return + */ + protected IProblemPreference getPreference(String problemId, + String paramId) { + IProblem problem = CodanRuntime.getInstance().getChechersRegistry() + .getWorkspaceProfile().findProblem(problemId); + IProblemPreference pref = ((MapProblemPreference) problem + .getPreference()).getChildDescriptor(paramId); + return pref; + } }