Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'codan/org.eclipse.cdt.codan.core.tests/src/org/eclipse/cdt/codan/core/internal/checkers/AssignmentToItselfCheckerTest.java')
-rw-r--r--codan/org.eclipse.cdt.codan.core.tests/src/org/eclipse/cdt/codan/core/internal/checkers/AssignmentToItselfCheckerTest.java81
1 files changed, 81 insertions, 0 deletions
diff --git a/codan/org.eclipse.cdt.codan.core.tests/src/org/eclipse/cdt/codan/core/internal/checkers/AssignmentToItselfCheckerTest.java b/codan/org.eclipse.cdt.codan.core.tests/src/org/eclipse/cdt/codan/core/internal/checkers/AssignmentToItselfCheckerTest.java
new file mode 100644
index 00000000000..869969c319c
--- /dev/null
+++ b/codan/org.eclipse.cdt.codan.core.tests/src/org/eclipse/cdt/codan/core/internal/checkers/AssignmentToItselfCheckerTest.java
@@ -0,0 +1,81 @@
+/*******************************************************************************
+ * Copyright (c) 2010 Severin Gehwolf
+ * 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:
+ * Severin Gehwolf - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.cdt.codan.core.internal.checkers;
+
+import org.eclipse.cdt.codan.core.tests.CheckerTestCase;
+import org.eclipse.core.resources.IMarker;
+
+/**
+ * Test for {@see AssignmentToItselfChecker} class
+ */
+public class AssignmentToItselfCheckerTest extends CheckerTestCase {
+ // void main() {
+ // int x = 0;
+ // x = 10;
+ // }
+ public void testNoErrorConstants() throws Exception {
+ loadCodeAndRun(getAboveComment());
+ checkNoErrors();
+ }
+
+ // void main() {
+ // int x = 10;
+ // int s = 10;
+ // x = s;
+ // }
+ public void testNoErrorVariables() throws Exception {
+ loadCodeAndRun(getAboveComment());
+ checkNoErrors();
+ }
+
+ // void main() {
+ // int x = 0;
+ // x = x;
+ // }
+ public void testSimpleVariableSelfAssignmentError() throws Exception {
+ loadCodeAndRun(getAboveComment());
+ checkErrorLine(3);
+ }
+
+ // void main() {
+ // char str[] = "hello testing world";
+ // int x = 10;
+ // str[i] = str[i];
+ // }
+ public void testArraySelfAssignmentError() throws Exception {
+ loadCodeAndRun(getAboveComment());
+ checkErrorLine(4);
+ }
+
+ // #define X a = 1
+ // void main() {
+ // int a;
+ // X;
+ // }
+ public void testNoError_Bug321933() throws Exception {
+ loadCodeAndRun(getAboveComment());
+ checkNoErrors();
+ }
+
+ // void foo() {
+ // int x = 0; x
+ // = x;
+ // }
+ public void testMarkerOffset_Bug486610() throws Exception {
+ String code = getAboveComment();
+ loadCodeAndRun(code);
+ IMarker marker = checkErrorLine(2);
+ int start = marker.getAttribute(IMarker.CHAR_START, -1);
+ int end = marker.getAttribute(IMarker.CHAR_END, -1);
+ // The offset should start at the beginning of the expression "x = x"
+ assertEquals("x\n = x", code.substring(start, end));
+ }
+}

Back to the top