Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMarco Stornelli2019-03-30 11:25:33 +0000
committerMarco Stornelli2019-05-26 18:26:16 +0000
commit1204bf21b161bbc93d7342f3e51d8d4b8b0d4d31 (patch)
tree20df6b79ca4811efcb2ea916ca46ec587a7b4ab8 /codan/org.eclipse.cdt.codan.core.tests
parent1065ee7688e641d2d9ad80f88bf1c6377b1fbd92 (diff)
downloadorg.eclipse.cdt-1204bf21b161bbc93d7342f3e51d8d4b8b0d4d31.tar.gz
org.eclipse.cdt-1204bf21b161bbc93d7342f3e51d8d4b8b0d4d31.tar.xz
org.eclipse.cdt-1204bf21b161bbc93d7342f3e51d8d4b8b0d4d31.zip
Bug 545956 - Added checker for virtual methods in ctor/dtor
Change-Id: I63b8a40447e9a5b6080e046030677a13607c4ea3 Signed-off-by: Marco Stornelli <marco.stornelli@gmail.com>
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/VirtualMethodCallCheckerTest.java248
-rw-r--r--codan/org.eclipse.cdt.codan.core.tests/src/org/eclipse/cdt/codan/core/tests/AutomatedIntegrationSuite.java2
2 files changed, 250 insertions, 0 deletions
diff --git a/codan/org.eclipse.cdt.codan.core.tests/src/org/eclipse/cdt/codan/core/internal/checkers/VirtualMethodCallCheckerTest.java b/codan/org.eclipse.cdt.codan.core.tests/src/org/eclipse/cdt/codan/core/internal/checkers/VirtualMethodCallCheckerTest.java
new file mode 100644
index 00000000000..fa054060294
--- /dev/null
+++ b/codan/org.eclipse.cdt.codan.core.tests/src/org/eclipse/cdt/codan/core/internal/checkers/VirtualMethodCallCheckerTest.java
@@ -0,0 +1,248 @@
+/*******************************************************************************
+ * Copyright (c) 2019 Marco Stornelli
+ *
+ * This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License 2.0
+ * which accompanies this distribution, and is available at
+ * https://www.eclipse.org/legal/epl-2.0/
+ *
+ * SPDX-License-Identifier: EPL-2.0
+ *******************************************************************************/
+package org.eclipse.cdt.codan.core.internal.checkers;
+
+import org.eclipse.cdt.codan.core.tests.CheckerTestCase;
+import org.eclipse.cdt.codan.internal.checkers.VirtualMethodCallChecker;
+
+/**
+ * Test for {@link VirtualMethodCallChecker} class
+ */
+public class VirtualMethodCallCheckerTest extends CheckerTestCase {
+
+ private static final String ERR_VIRTUAL_ID = VirtualMethodCallChecker.VIRTUAL_CALL_ID;
+
+ @Override
+ public void setUp() throws Exception {
+ super.setUp();
+ enableProblems(ERR_VIRTUAL_ID);
+ }
+
+ @Override
+ public boolean isCpp() {
+ return true;
+ }
+
+ //class Foo {
+ //public:
+ //Foo();
+ //~Foo();
+ //virtual void bar();
+ //virtual void pure() = 0;
+ //virtual void notpure();
+ //};
+ //Foo::Foo() {
+ // pure();
+ //}
+ //Foo::~Foo() {
+ //}
+ //Foo::bar() {
+ //}
+ public void testWithPureInCtor() throws Exception {
+ loadCodeAndRun(getAboveComment());
+ checkErrorLine(10, ERR_VIRTUAL_ID);
+ }
+
+ //class Foo {
+ //public:
+ //Foo();
+ //~Foo();
+ //virtual void bar();
+ //virtual void pure() = 0;
+ //virtual void notpure();
+ //};
+ //Foo::Foo() {
+ // notpure();
+ //}
+ //Foo::~Foo() {
+ //}
+ //Foo::bar() {
+ //}
+ public void testWithNotPureInCtor() throws Exception {
+ loadCodeAndRun(getAboveComment());
+ checkErrorLine(10, ERR_VIRTUAL_ID);
+ }
+
+ //class Foo {
+ //public:
+ //Foo();
+ //~Foo();
+ //virtual void bar();
+ //virtual void pure() = 0;
+ //virtual void notpure();
+ //};
+ //Foo::Foo() {
+ //}
+ //Foo::~Foo() {
+ // pure();
+ //}
+ //Foo::bar() {
+ //}
+ public void testWithPureInDtor() throws Exception {
+ loadCodeAndRun(getAboveComment());
+ checkErrorLine(12, ERR_VIRTUAL_ID);
+ }
+
+ //class Foo {
+ //public:
+ //Foo();
+ //~Foo();
+ //virtual void bar();
+ //virtual void pure() = 0;
+ //virtual void notpure();
+ //};
+ //Foo::Foo() {
+ //}
+ //Foo::~Foo() {
+ // notpure();
+ //}
+ //Foo::bar() {
+ //}
+ public void testWithNotPureInDtor() throws Exception {
+ loadCodeAndRun(getAboveComment());
+ checkErrorLine(12, ERR_VIRTUAL_ID);
+ }
+
+ //class Foo {
+ //public:
+ //Foo();
+ //~Foo();
+ //virtual void bar();
+ //virtual void pure() = 0;
+ //virtual void notpure();
+ //};
+ //Foo::Foo() {
+ //}
+ //Foo::~Foo() {
+ //}
+ //Foo::bar() {
+ // pure();
+ // notpure();
+ //}
+ public void testWithVirtualInMethod() throws Exception {
+ loadCodeAndRun(getAboveComment());
+ checkNoErrorsOfKind(ERR_VIRTUAL_ID);
+ }
+
+ //class A {
+ //public:
+ // virtual void v() {}
+ //};
+ //class B {
+ //private:
+ //A a;
+ //public:
+ // B() { a.v(); }
+ //};
+ public void testVirtualMethodOtherClass() throws Exception {
+ loadCodeAndRun(getAboveComment());
+ checkNoErrorsOfKind(ERR_VIRTUAL_ID);
+ }
+
+ //class B {
+ //private:
+ //A a;
+ //public:
+ // B() { this->v(); }
+ // virtual void v() {}
+ //};
+ public void testVirtualMethodWithThis() throws Exception {
+ loadCodeAndRun(getAboveComment());
+ checkErrorLine(5, ERR_VIRTUAL_ID);
+ }
+
+ //class B {
+ //private:
+ //A a;
+ //public:
+ // B() { (*this).v(); }
+ // virtual void v() {}
+ //};
+ public void testVirtualMethodWithDerThis() throws Exception {
+ loadCodeAndRun(getAboveComment());
+ checkErrorLine(5, ERR_VIRTUAL_ID);
+ }
+
+ //class A {
+ //public:
+ // virtual void v() {}
+ //};
+ //class B: public A {
+ //public:
+ // B() { A::v(); }
+ //};
+ public void testVirtualMethodChildClass() throws Exception {
+ loadCodeAndRun(getAboveComment());
+ checkErrorLine(7, ERR_VIRTUAL_ID);
+ }
+
+ //class Foo {
+ //public:
+ // Foo() {
+ // class LocalClass {
+ // LocalClass() {}
+ // virtual void foo() {
+ // }
+ // void func() {
+ // foo();
+ // }
+ // virtual ~LocalClass() {}
+ // };
+ // }
+ //};
+ public void testVirtualMethodLocalClass() throws Exception {
+ loadCodeAndRun(getAboveComment());
+ checkNoErrorsOfKind(ERR_VIRTUAL_ID);
+ }
+
+ //class A {
+ //public:
+ // A() : A(5) { foo(); }
+ // A(int a) : a(a) { }
+ // virtual void foo();
+ //private:
+ // int a;
+ //};
+ public void testVirtualMethodDelCtor() throws Exception {
+ loadCodeAndRun(getAboveComment());
+ checkNoErrorsOfKind(ERR_VIRTUAL_ID);
+ }
+
+ //class A {
+ //public:
+ // A() {
+ // A a;
+ // a.foo();
+ // }
+ // virtual void foo();
+ //};
+ public void testVirtualMethodOtherInstance() throws Exception {
+ loadCodeAndRun(getAboveComment());
+ checkNoErrorsOfKind(ERR_VIRTUAL_ID);
+ }
+
+ //class A {
+ //public:
+ // A() {
+ // foo();
+ // }
+ // virtual void foo();
+ // class Nested {
+ // public:
+ // Nested() { bar(); };
+ // virtual void bar();
+ // }
+ //};
+ public void testVirtualMethodNested() throws Exception {
+ loadCodeAndRun(getAboveComment());
+ checkErrorLines(4, 9);
+ }
+}
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 51ec39307eb..9a0cb3e2399 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
@@ -36,6 +36,7 @@ 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.SwitchCaseCheckerTest;
import org.eclipse.cdt.codan.core.internal.checkers.UnusedSymbolInFileScopeCheckerTest;
+import org.eclipse.cdt.codan.core.internal.checkers.VirtualMethodCallCheckerTest;
import org.eclipse.cdt.codan.internal.checkers.ui.quickfix.AssignmentInConditionQuickFixTest;
import org.eclipse.cdt.codan.internal.checkers.ui.quickfix.CaseBreakQuickFixBreakTest;
import org.eclipse.cdt.codan.internal.checkers.ui.quickfix.CaseBreakQuickFixCommentTest;
@@ -90,6 +91,7 @@ public class AutomatedIntegrationSuite extends TestSuite {
suite.addTestSuite(GotoStatementCheckerTest.class);
suite.addTestSuite(CopyrightCheckerTest.class);
suite.addTestSuite(SwitchCaseCheckerTest.class);
+ suite.addTestSuite(VirtualMethodCallCheckerTest.class);
// framework
suite.addTest(CodanFastTestSuite.suite());
// quick fixes

Back to the top