Skip to main content
summaryrefslogtreecommitdiffstats
path: root/codan
diff options
context:
space:
mode:
authorAlena Laskavaia2010-05-24 17:52:18 -0400
committerAlena Laskavaia2010-05-24 17:52:18 -0400
commitf4f2bfd6eeb9be3d6a0a93e8329f8f3981f574f0 (patch)
tree4408cc3753fe3b2afa2fd01c42bc2f94ad842abd /codan
parentdc1e7535ae9bf445a3f4be182c7ed54639ff11f0 (diff)
downloadorg.eclipse.cdt-f4f2bfd6eeb9be3d6a0a93e8329f8f3981f574f0.tar.gz
org.eclipse.cdt-f4f2bfd6eeb9be3d6a0a93e8329f8f3981f574f0.tar.xz
org.eclipse.cdt-f4f2bfd6eeb9be3d6a0a93e8329f8f3981f574f0.zip
Added test for problem argument
Diffstat (limited to 'codan')
-rw-r--r--codan/org.eclipse.cdt.codan.core.test/src/org/eclipse/cdt/codan/core/internal/checkers/ExpressionRequiredInReturnCheckerTest.java89
-rw-r--r--codan/org.eclipse.cdt.codan.core.test/src/org/eclipse/cdt/codan/core/internal/checkers/StatementHasNoEffectCheckerTest.java22
-rw-r--r--codan/org.eclipse.cdt.codan.core.test/src/org/eclipse/cdt/codan/core/test/CheckerTestCase.java31
3 files changed, 47 insertions, 95 deletions
diff --git a/codan/org.eclipse.cdt.codan.core.test/src/org/eclipse/cdt/codan/core/internal/checkers/ExpressionRequiredInReturnCheckerTest.java b/codan/org.eclipse.cdt.codan.core.test/src/org/eclipse/cdt/codan/core/internal/checkers/ExpressionRequiredInReturnCheckerTest.java
deleted file mode 100644
index b4b875b080..0000000000
--- a/codan/org.eclipse.cdt.codan.core.test/src/org/eclipse/cdt/codan/core/internal/checkers/ExpressionRequiredInReturnCheckerTest.java
+++ /dev/null
@@ -1,89 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2009 Alena Laskavaia
- * 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:
- * Alena Laskavaia - initial API and implementation
- * Felipe Martinez - ExpressionRequiredInReturnCheckerTest implementation
- *******************************************************************************/
-package org.eclipse.cdt.codan.core.internal.checkers;
-
-import org.eclipse.cdt.codan.core.test.CheckerTestCase;
-
-/**
- * Test for {@see ExpressionRequiredInReturnCheckerTest} class
- *
- */
-public class ExpressionRequiredInReturnCheckerTest extends CheckerTestCase {
-
-
-// dummy() {
-// return; // error here on line 2
-// }
- public void testDummyFunction() {
- loadCodeAndRun(getAboveComment());
- checkNoErrors(); // because return type if not defined, usually people don't care
- }
-
-
-// void void_function(void) {
-// return; // no error here
-// }
- public void testVoidFunction() {
- loadCodeAndRun(getAboveComment());
- checkNoErrors();
- }
-
-
-// int integer_return_function(void) {
-// if (global) {
-// if (global == 100) {
-// return; // error here on line 4
-// }
-// }
-// }
- public void testBasicTypeFunction() {
- loadCodeAndRun(getAboveComment());
- checkErrorLine(4);
- }
-
-//
-// struct My_Struct {
-// int a;
-// };
-//
-// struct My_Struct struct_return_function(void) {
-// return; // error here on line 6
-// }
- public void testUserDefinedFunction() {
- loadCodeAndRun(getAboveComment());
- checkErrorLine(6);
- }
-
-
-// typedef unsigned int uint8_t;
-//
-// uint8_t return_typedef(void) {
-// return; // error here on line 4
-// }
- public void testTypedefReturnFunction() {
- loadCodeAndRun(getAboveComment());
- checkErrorLine(4);
- }
-
-
-// typedef unsigned int uint8_t;
-//
-// uint8_t (*return_fp_no_typedef(void))(void)
-// {
-// return; // error here on line 5
-// }
- public void testFunctionPointerReturnFunction() {
- loadCodeAndRun(getAboveComment());
- checkErrorLine(5);
- }
-
-} \ No newline at end of file
diff --git a/codan/org.eclipse.cdt.codan.core.test/src/org/eclipse/cdt/codan/core/internal/checkers/StatementHasNoEffectCheckerTest.java b/codan/org.eclipse.cdt.codan.core.test/src/org/eclipse/cdt/codan/core/internal/checkers/StatementHasNoEffectCheckerTest.java
index 4f063fcc38..eb4a309d7d 100644
--- a/codan/org.eclipse.cdt.codan.core.test/src/org/eclipse/cdt/codan/core/internal/checkers/StatementHasNoEffectCheckerTest.java
+++ b/codan/org.eclipse.cdt.codan.core.test/src/org/eclipse/cdt/codan/core/internal/checkers/StatementHasNoEffectCheckerTest.java
@@ -16,6 +16,7 @@ import java.io.IOException;
import org.eclipse.cdt.codan.core.param.IProblemPreference;
import org.eclipse.cdt.codan.core.test.CheckerTestCase;
import org.eclipse.cdt.codan.internal.checkers.StatementHasNoEffectChecker;
+import org.eclipse.core.resources.IMarker;
/**
* Test for {@see StatementHasNoEffectChecker} class
@@ -154,6 +155,17 @@ public class StatementHasNoEffectCheckerTest extends CheckerTestCase {
//#define FUNC(a) a
// main() {
+ // int x;
+ // FUNC(x); // error
+ // }
+ public void testMessageInMacro() throws IOException {
+ loadCodeAndRun(getAboveComment());
+ IMarker m = checkErrorLine(4);
+ assertMessageMatch("'FUNC(x)'", m); //$NON-NLS-1$
+ }
+
+ //#define FUNC(a) a
+ // main() {
// int a;
// FUNC(a); // no error if macro exp turned off
// }
@@ -166,4 +178,14 @@ public class StatementHasNoEffectCheckerTest extends CheckerTestCase {
loadCodeAndRun(getAboveComment());
checkNoErrors();
}
+
+ // main() {
+ // int a;
+ // +a; // error here on line 3
+ // }
+ public void testMessage() throws IOException {
+ loadCodeAndRun(getAboveComment());
+ IMarker m = checkErrorLine(3);
+ assertMessageMatch("'\\+a'", m); //$NON-NLS-1$
+ }
}
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 6a5d949fd9..3282ea3c39 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
@@ -29,22 +29,24 @@ import org.eclipse.core.runtime.NullProgressMonitor;
public class CheckerTestCase extends CodanTestCase {
private IMarker[] markers;
- public void checkErrorLine(int i) {
- checkErrorLine(currentFile, i);
+ public IMarker checkErrorLine(int i) {
+ return checkErrorLine(currentFile, i);
}
/**
* @param expectedLine
* - line
+ * @return
*/
- public void checkErrorLine(File file, int expectedLine) {
+ public IMarker checkErrorLine(File file, int expectedLine) {
assertTrue(markers != null);
assertTrue("No problems found but should", markers.length > 0); //$NON-NLS-1$
boolean found = false;
Integer line = null;
String mfile = null;
+ IMarker m = null;
for (int j = 0; j < markers.length; j++) {
- IMarker m = markers[j];
+ m = markers[j];
Object pos;
try {
line = (Integer) m.getAttribute(IMarker.LINE_NUMBER);
@@ -70,6 +72,8 @@ public class CheckerTestCase extends CodanTestCase {
if (file != null)
assertEquals(file.getName(), mfile);
assertTrue(found);
+ assertNotNull(m);
+ return m;
}
public void checkNoErrors() {
@@ -123,12 +127,27 @@ public class CheckerTestCase extends CodanTestCase {
* @param paramId
* @return
*/
- protected IProblemPreference getPreference(String problemId,
- String paramId) {
+ protected IProblemPreference getPreference(String problemId, String paramId) {
IProblem problem = CodanRuntime.getInstance().getChechersRegistry()
.getWorkspaceProfile().findProblem(problemId);
IProblemPreference pref = ((MapProblemPreference) problem
.getPreference()).getChildDescriptor(paramId);
return pref;
}
+
+ /**
+ * @param string
+ * @param m
+ */
+ public void assertMessageMatch(String pattern, IMarker m) {
+ try {
+ String attribute = (String) m.getAttribute(IMarker.MESSAGE);
+ if (attribute.matches(pattern)) {
+ fail("Expected " + attribute + " to match with /" + pattern //$NON-NLS-1$ //$NON-NLS-2$
+ + "/"); //$NON-NLS-1$
+ }
+ } catch (CoreException e) {
+ fail(e.getMessage());
+ }
+ }
}

Back to the top