diff options
author | Rolf Bislin | 2017-05-02 07:49:27 +0000 |
---|---|---|
committer | Thomas Corbat | 2017-05-08 17:25:15 +0000 |
commit | a583190f52c69400dc25d455b170dc23d8314105 (patch) | |
tree | f40f7258e77bb0af59921d5d4704df3d4eeb1920 /codan/org.eclipse.cdt.codan.core.tests | |
parent | 0f27b20848e526bfddea0de20693696885cb214d (diff) | |
download | org.eclipse.cdt-a583190f52c69400dc25d455b170dc23d8314105.tar.gz org.eclipse.cdt-a583190f52c69400dc25d455b170dc23d8314105.tar.xz org.eclipse.cdt-a583190f52c69400dc25d455b170dc23d8314105.zip |
Bug 514685 - codan: handle fallthrough attribute
and provide quickfix for adding fallthrough attribute
and add JUnit Tests
and add StandardAttributes class
Change-Id: I8cf0238771dc92bd1784b9dfb35a680d078b1db6
Depends-On: Ic09aa96f896b0a5dd998156e05930704775f695b
Signed-off-by: Rolf Bislin <romibi@bluewin.ch>
Signed-off-by: Thomas Corbat <tcorbat@hsr.ch>
Diffstat (limited to 'codan/org.eclipse.cdt.codan.core.tests')
-rw-r--r-- | codan/org.eclipse.cdt.codan.core.tests/src/org/eclipse/cdt/codan/core/internal/checkers/CaseBreakCheckerTest.java | 198 | ||||
-rw-r--r-- | codan/org.eclipse.cdt.codan.core.tests/src/org/eclipse/cdt/codan/core/tests/AutomatedIntegrationSuite.java | 14 | ||||
-rw-r--r-- | codan/org.eclipse.cdt.codan.core.tests/src/org/eclipse/cdt/codan/internal/checkers/ui/quickfix/CaseBreakQuickFixBreakTest.java (renamed from codan/org.eclipse.cdt.codan.core.tests/src/org/eclipse/cdt/codan/internal/checkers/ui/quickfix/CaseBreakQuickFixTest.java) | 2 | ||||
-rw-r--r-- | codan/org.eclipse.cdt.codan.core.tests/src/org/eclipse/cdt/codan/internal/checkers/ui/quickfix/CaseBreakQuickFixFallthroughAttributeTest.java | 90 |
4 files changed, 292 insertions, 12 deletions
diff --git a/codan/org.eclipse.cdt.codan.core.tests/src/org/eclipse/cdt/codan/core/internal/checkers/CaseBreakCheckerTest.java b/codan/org.eclipse.cdt.codan.core.tests/src/org/eclipse/cdt/codan/core/internal/checkers/CaseBreakCheckerTest.java index 3f5f808b8fa..b8c5e878d62 100644 --- a/codan/org.eclipse.cdt.codan.core.tests/src/org/eclipse/cdt/codan/core/internal/checkers/CaseBreakCheckerTest.java +++ b/codan/org.eclipse.cdt.codan.core.tests/src/org/eclipse/cdt/codan/core/internal/checkers/CaseBreakCheckerTest.java @@ -166,6 +166,18 @@ public class CaseBreakCheckerTest extends CheckerTestCase { checkNoErrorsOfKind(ER_ID); } + // void foo(void) { + // int a; + // switch (a) { + // case 1: + // [[fallthrough]]; // invalid in last case + // } + // } + public void testEmptyLastCaseBadFallthrough_514685() throws Exception { + loadCodeAndRunCpp(getAboveComment()); + checkErrorLine(5); + } + // void foo(int a, int b) { // switch (a) { // case 1: @@ -199,11 +211,25 @@ public class CaseBreakCheckerTest extends CheckerTestCase { // int a, b; // switch (a) { // case 1: + // b = 2; + // [[fallthrough]]; + // } + // } + public void testLastCaseBadFallthrough_514685() throws Exception { + loadCodeAndRunCpp(getAboveComment()); + checkErrorLine(5); + } + + // void foo(void) { + // int a, b; + // switch (a) { + // case 1: // /* no break */ // case 2: // b = 2; // break; // } + // } public void testEmptyCaseOKcomment() throws Exception { loadCodeAndRun(getAboveComment()); checkNoErrorsOfKind(ER_ID); @@ -213,6 +239,21 @@ public class CaseBreakCheckerTest extends CheckerTestCase { // int a, b; // switch (a) { // case 1: + // [[fallthrough]]; + // case 2: + // b = 2; + // break; + // } + // } + public void testEmptyCaseOKFallthrough_514685() throws Exception { + loadCodeAndRunCpp(getAboveComment()); + checkNoErrorsOfKind(ER_ID); + } + + // void foo(void) { + // int a, b; + // switch (a) { + // case 1: // b = 2; // /* no break */ // bye(); @@ -223,6 +264,21 @@ public class CaseBreakCheckerTest extends CheckerTestCase { checkErrorLines(7); } + // void bye() {} + // void foo(void) { + // int a, b; + // switch (a) { + // case 1: + // b = 2; + // [[fallthrough]]; + // bye(); + // } + // } + public void testLastCaseBadFallthroughNotLast_514685() throws Exception { + loadCodeAndRunCpp(getAboveComment()); + checkErrorLines(8); + } + // void foo(void) { // int a, b; // switch (a) { @@ -257,6 +313,36 @@ public class CaseBreakCheckerTest extends CheckerTestCase { // void foo(void) { // int a, b; // switch (a) { + // case 1: + // b = 2; + // [[fallthrough]]; + // case 2: + // b = 2; + // [[ fallthrough ]]; + // case 3: + // b = 2; + // [ [ fallthrough ] ] ; + // case 4: + // b = 2;[[fallthrough]]; + // case 5: + // b = 2; + // [[fall]]; + // case 6: + // b = 2; + // [[FALLTHROUGH]]; + // case 7: + // b = 2; + // [[fallthrough]] + // } + // } + public void testDifferentFallthroughs_514685() throws Exception { + loadCodeAndRunCpp(getAboveComment()); + checkErrorLines(16, 19, 24); + } + + // void foo(void) { + // int a, b; + // switch (a) { // case 1: //err // // lolo // case 2: //err @@ -286,15 +372,22 @@ public class CaseBreakCheckerTest extends CheckerTestCase { // b = 2; // /* no break */ // case 4: - // b = 2; // err + // b = 2; + // [[fallthrough]]; // case 5: + // b = 2; // err + // case 6: // b = 2; // break; - // case 6: + // case 7: // b = 2; // /* no break */ // b = 2; //err - // case 7: + // case 8: + // b = 2; + // [[fallthrough]]; + // b = 2; //err + // case 9: // b = 2;//err // } // @@ -310,7 +403,7 @@ public class CaseBreakCheckerTest extends CheckerTestCase { public void testGeneral1() throws Exception { setEmpty(true); setLast(true); - loadCodeAndRun(getAboveComment()); + loadCodeAndRunCpp(getAboveComment()); checkErrorComments(); } @@ -347,6 +440,36 @@ public class CaseBreakCheckerTest extends CheckerTestCase { // void foo(void) { // int a, b; // switch (a) { + // case 1: + // b = 2; + // // lolo + // [[fallthrough]]; + // case 2: + // b = 2; + // [[fallthrough]]; + // // lolo + // case 3: + // [[fallthrough]]; // not valid, not last statement + // b = 2; + // // loo + // case 4: + // b = 2; + // // lolo + // [[fallthrough]]; + // case 5: + // // lolo + // b = 2; + // [[fallthrough]]; // not valid in last case + // } + // } + public void testGeneralFallthroughs1_514685() throws Exception { + loadCodeAndRunCpp(getAboveComment()); + checkErrorLines(14, 22); + } + + // void foo(void) { + // int a, b; + // switch (a) { // case 0: // switch( b ) { // case 2: // err @@ -370,13 +493,23 @@ public class CaseBreakCheckerTest extends CheckerTestCase { // } // err // case 5: // switch( b ) { + // case 2: + // [[fallthrough]]; // err + // } // err + // case 6: + // switch( b ) { // case 2: // err // } // /* no break */ + // case 7: + // switch( b ) { + // case 2: // err + // } // err + // [[fallthrough]]; // } // } public void testNestedSwitches() throws Exception { - loadCodeAndRun(getAboveComment()); + loadCodeAndRunCpp(getAboveComment()); checkErrorComments(); } @@ -429,6 +562,61 @@ public class CaseBreakCheckerTest extends CheckerTestCase { checkErrorLine(4, ER_ID); } + // void foo() { + // int a, b; + // switch (a) { + // case 1: { + // b = 2; + // [[fallthrough]]; + // } + // case 2: { + // b = 2; + // } + // [[fallthrough]]; + // case 3: { + // { + // b = 2; + // [[fallthrough]]; + // } + // } + // case 4: { + // b = 2; + // break; + // } + // } + //} + public void testFallthroughAndCompoundStatementCombinations_514685() throws Exception { + String code = getAboveComment(); + loadCodeAndRunCpp(code); + checkNoErrorsOfKind(ER_ID); + } + + // void foo() { + // int a, b; + // switch (a) { + // case 1: + // b = 2; // err + // [[fallthrough]]; + // } + // switch (a) { + // case 1: { + // b = 2; + // [[fallthrough]]; + // } // err + // } + // switch (a) { + // case 1: { + // b = 2; + // } // err + // [[fallthrough]]; + // } + // } + public void testBadFallthroughInLastStatement_514685() throws Exception { + String code = getAboveComment(); + loadCodeAndRunCpp(code); + checkErrorComments(); + } + private void setLast(boolean val) { IProblemPreference pref = getPreference(CaseBreakChecker.ER_ID, CaseBreakChecker.PARAM_LAST_CASE); pref.setValue(val); diff --git a/codan/org.eclipse.cdt.codan.core.tests/src/org/eclipse/cdt/codan/core/tests/AutomatedIntegrationSuite.java b/codan/org.eclipse.cdt.codan.core.tests/src/org/eclipse/cdt/codan/core/tests/AutomatedIntegrationSuite.java index 7233b65c959..70089d5a627 100644 --- a/codan/org.eclipse.cdt.codan.core.tests/src/org/eclipse/cdt/codan/core/tests/AutomatedIntegrationSuite.java +++ b/codan/org.eclipse.cdt.codan.core.tests/src/org/eclipse/cdt/codan/core/tests/AutomatedIntegrationSuite.java @@ -11,10 +11,6 @@ *******************************************************************************/ package org.eclipse.cdt.codan.core.tests; -import junit.framework.Test; -import junit.framework.TestCase; -import junit.framework.TestSuite; - import org.eclipse.cdt.codan.core.internal.checkers.AbstractClassInstantiationCheckerTest; import org.eclipse.cdt.codan.core.internal.checkers.AssignmentInConditionCheckerTest; import org.eclipse.cdt.codan.core.internal.checkers.AssignmentToItselfCheckerTest; @@ -33,12 +29,17 @@ import org.eclipse.cdt.codan.core.internal.checkers.SuggestedParenthesisCheckerT 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.AssignmentInConditionQuickFixTest; -import org.eclipse.cdt.codan.internal.checkers.ui.quickfix.CaseBreakQuickFixTest; +import org.eclipse.cdt.codan.internal.checkers.ui.quickfix.CaseBreakQuickFixBreakTest; import org.eclipse.cdt.codan.internal.checkers.ui.quickfix.CaseBreakQuickFixCommentTest; +import org.eclipse.cdt.codan.internal.checkers.ui.quickfix.CaseBreakQuickFixFallthroughAttributeTest; 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; +import junit.framework.Test; +import junit.framework.TestCase; +import junit.framework.TestSuite; + public class AutomatedIntegrationSuite extends TestSuite { public AutomatedIntegrationSuite() { } @@ -81,8 +82,9 @@ public class AutomatedIntegrationSuite extends TestSuite { suite.addTestSuite(CreateLocalVariableQuickFixTest.class); suite.addTestSuite(SuggestedParenthesisQuickFixTest.class); suite.addTestSuite(CatchByReferenceQuickFixTest.class); - suite.addTestSuite(CaseBreakQuickFixTest.class); + suite.addTestSuite(CaseBreakQuickFixBreakTest.class); suite.addTestSuite(CaseBreakQuickFixCommentTest.class); + suite.addTestSuite(CaseBreakQuickFixFallthroughAttributeTest.class); suite.addTestSuite(AssignmentInConditionQuickFixTest.class); return suite; } diff --git a/codan/org.eclipse.cdt.codan.core.tests/src/org/eclipse/cdt/codan/internal/checkers/ui/quickfix/CaseBreakQuickFixTest.java b/codan/org.eclipse.cdt.codan.core.tests/src/org/eclipse/cdt/codan/internal/checkers/ui/quickfix/CaseBreakQuickFixBreakTest.java index bafe92bc2ae..b14884a6e0a 100644 --- a/codan/org.eclipse.cdt.codan.core.tests/src/org/eclipse/cdt/codan/internal/checkers/ui/quickfix/CaseBreakQuickFixTest.java +++ b/codan/org.eclipse.cdt.codan.core.tests/src/org/eclipse/cdt/codan/internal/checkers/ui/quickfix/CaseBreakQuickFixBreakTest.java @@ -12,7 +12,7 @@ package org.eclipse.cdt.codan.internal.checkers.ui.quickfix; import org.eclipse.cdt.codan.ui.AbstractCodanCMarkerResolution;
-public class CaseBreakQuickFixTest extends QuickFixTestCase {
+public class CaseBreakQuickFixBreakTest extends QuickFixTestCase {
@SuppressWarnings("restriction")
@Override
protected AbstractCodanCMarkerResolution createQuickFix() {
diff --git a/codan/org.eclipse.cdt.codan.core.tests/src/org/eclipse/cdt/codan/internal/checkers/ui/quickfix/CaseBreakQuickFixFallthroughAttributeTest.java b/codan/org.eclipse.cdt.codan.core.tests/src/org/eclipse/cdt/codan/internal/checkers/ui/quickfix/CaseBreakQuickFixFallthroughAttributeTest.java new file mode 100644 index 00000000000..23b63dd7551 --- /dev/null +++ b/codan/org.eclipse.cdt.codan.core.tests/src/org/eclipse/cdt/codan/internal/checkers/ui/quickfix/CaseBreakQuickFixFallthroughAttributeTest.java @@ -0,0 +1,90 @@ +/******************************************************************************* + * Copyright (c) 2017 Institute for Software, HSR Hochschule fuer Technik + * 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 + *******************************************************************************/ +package org.eclipse.cdt.codan.internal.checkers.ui.quickfix; + +import org.eclipse.cdt.codan.ui.AbstractCodanCMarkerResolution; + +public class CaseBreakQuickFixFallthroughAttributeTest extends QuickFixTestCase { + @SuppressWarnings("restriction") + @Override + protected AbstractCodanCMarkerResolution createQuickFix() { + return new CaseBreakQuickFixFallthroughAttribute(); + } + + //void hello() {} + //void func() { + // int a; + // switch(a) { + // case 1: + // hello(); + // case 2: + // break; + // } + //} + public void testSimpleCase_514685() throws Exception { + loadcode(getAboveComment(), true); + String result = runQuickFixOneFile(); + assertContainedIn("[[fallthrough]];\tcase 2:", result); + } + + //void hello() {} + //void func() { + // int a; + // switch(a) { + // case 1: + // hello(); + // hello(); + // case 2: + // break; + // } + //} + public void testMultipleStatementsCase_514685() throws Exception { + loadcode(getAboveComment(), true); + String result = runQuickFixOneFile(); + assertContainedIn("[[fallthrough]];\tcase 2:", result); + } + + //void hello() {} + //void func() { + // int a; + // switch(a) { + // case 1: { + // hello(); + // } + // case 2: + // break; + // } + //} + public void testCompositeCase_514685() throws Exception { + loadcode(getAboveComment(), true); + String result = runQuickFixOneFile(); + assertContainedIn("[[fallthrough]];\t}\tcase 2:", result); + } + + //void hello() {} + //void func() { + // int a; + // switch(a) { + // case 1: { + // { + // hello(); + // { + // hello(); + // } + // } + // } + // case 2: + // break; + // } + //} + public void testNestedCompositeCase_514685() throws Exception { + loadcode(getAboveComment(), true); + String result = runQuickFixOneFile(); + assertContainedIn("[[fallthrough]];\t}\tcase 2:", result); + } +} |