Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSergey Prigogin2011-05-23 19:55:41 -0400
committerSergey Prigogin2011-05-23 19:55:41 -0400
commitc3b54355959971e7f975cefafd3be6b73f4c8664 (patch)
treed0d3d532713af75a9be0b8f901810247e8097583 /codan/org.eclipse.cdt.codan.core.test
parent8fc40a28842f8018c25e67aad3b4568f2496b1db (diff)
downloadorg.eclipse.cdt-c3b54355959971e7f975cefafd3be6b73f4c8664.tar.gz
org.eclipse.cdt-c3b54355959971e7f975cefafd3be6b73f4c8664.tar.xz
org.eclipse.cdt-c3b54355959971e7f975cefafd3be6b73f4c8664.zip
Bug 315528 - Non-virtual destructor diagnostics doesn't take superclass into account. Tests by Patrick Hofer.
Diffstat (limited to 'codan/org.eclipse.cdt.codan.core.test')
-rw-r--r--codan/org.eclipse.cdt.codan.core.test/src/org/eclipse/cdt/codan/core/internal/checkers/NonVirtualDestructorCheckerTest.java128
-rw-r--r--codan/org.eclipse.cdt.codan.core.test/src/org/eclipse/cdt/codan/core/test/AutomatedIntegrationSuite.java2
2 files changed, 130 insertions, 0 deletions
diff --git a/codan/org.eclipse.cdt.codan.core.test/src/org/eclipse/cdt/codan/core/internal/checkers/NonVirtualDestructorCheckerTest.java b/codan/org.eclipse.cdt.codan.core.test/src/org/eclipse/cdt/codan/core/internal/checkers/NonVirtualDestructorCheckerTest.java
new file mode 100644
index 0000000000..5bdd871dea
--- /dev/null
+++ b/codan/org.eclipse.cdt.codan.core.test/src/org/eclipse/cdt/codan/core/internal/checkers/NonVirtualDestructorCheckerTest.java
@@ -0,0 +1,128 @@
+/*******************************************************************************
+ * Copyright (c) 2011 Patrick Hofer and others.
+ * 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:
+ * Patrick Hofer - Initial API and implementation
+ *******************************************************************************/
+package org.eclipse.cdt.codan.core.internal.checkers;
+
+import org.eclipse.cdt.codan.core.test.CheckerTestCase;
+import org.eclipse.cdt.codan.internal.checkers.NonVirtualDestructor;
+
+/**
+ * Test for {@see NonVirtualDestructor} class.
+ */
+public class NonVirtualDestructorCheckerTest extends CheckerTestCase {
+ @Override
+ public boolean isCpp() {
+ return true;
+ }
+
+ @Override
+ public void setUp() throws Exception {
+ super.setUp();
+ enableProblems(NonVirtualDestructor.ER_ID);
+ }
+
+ // struct A {
+ // virtual void f() = 0;
+ // virtual ~A(); // ok.
+ // };
+ public void testVirtualDtorInClass() {
+ loadCodeAndRun(getAboveComment());
+ checkNoErrors();
+ }
+
+ // struct A {
+ // virtual void f() = 0;
+ // protected:
+ // ~A(); // ok.
+ // };
+ public void testNonPublicVirtualDtorInClass() {
+ loadCodeAndRun(getAboveComment());
+ checkNoErrors();
+ }
+
+ // struct A {
+ // virtual void f() = 0;
+ // ~A(); // warn! public non-virtual dtor.
+ // };
+ public void _testPublicVirtualDtorInClass() {
+ loadCodeAndRun(getAboveComment());
+ checkErrorLines(3);
+ }
+
+ // struct A {
+ // virtual void f() = 0;
+ // // warn! implicit public non-virtual dtor.
+ // };
+ public void _testImplicitPublicNonVirtualDtorInClass() {
+ loadCodeAndRun(getAboveComment());
+ checkErrorLines(1);
+ }
+
+ // struct F { };
+ //
+ // struct A {
+ // virtual void f() = 0;
+ // private:
+ // friend class F;
+ // ~A(); // warn! can be called from class F.
+ // };
+ public void _testPublicNonVirtualDtorCanBeCalledFromFriendClass() {
+ loadCodeAndRun(getAboveComment());
+ checkErrorLines(7);
+ }
+
+ // struct A {
+ // virtual void f() = 0;
+ // virtual ~A();
+ // };
+ //
+ // struct B {
+ // ~B(); // ok.
+ // };
+ public void testVirtualDtorInBaseClass() {
+ loadCodeAndRun(getAboveComment());
+ checkNoErrors();
+ }
+
+ // struct A {
+ // virtual void f() = 0;
+ // virtual ~A(); // ok.
+ // };
+ //
+ // struct B : public A { };
+ //
+ // struct C { };
+ //
+ // struct D : public B, C { };
+ //
+ // struct E : public D { };
+ public void testVirtualDtorInBaseClass2() {
+ loadCodeAndRun(getAboveComment());
+ checkNoErrors();
+ }
+
+ // struct A {
+ // virtual void f() = 0;
+ // ~A(); // warn! public non-virtual dtor.
+ // // this affects B, D and E further down in the hierarchy as well
+ // };
+ //
+ // struct B : public A { };
+ //
+ // struct C { };
+ //
+ // struct D : public B, C { };
+ //
+ // struct E : public D {
+ // };
+ public void _testNonVirtualDtorInBaseClass2() {
+ checkErrorLines(3, 7, 11, 13);
+ }
+}
diff --git a/codan/org.eclipse.cdt.codan.core.test/src/org/eclipse/cdt/codan/core/test/AutomatedIntegrationSuite.java b/codan/org.eclipse.cdt.codan.core.test/src/org/eclipse/cdt/codan/core/test/AutomatedIntegrationSuite.java
index ed5ae7a2c5..7958a4b8d1 100644
--- a/codan/org.eclipse.cdt.codan.core.test/src/org/eclipse/cdt/codan/core/test/AutomatedIntegrationSuite.java
+++ b/codan/org.eclipse.cdt.codan.core.test/src/org/eclipse/cdt/codan/core/test/AutomatedIntegrationSuite.java
@@ -21,6 +21,7 @@ import org.eclipse.cdt.codan.core.internal.checkers.AssignmentToItselfCheckerTes
import org.eclipse.cdt.codan.core.internal.checkers.CaseBreakCheckerTest;
import org.eclipse.cdt.codan.core.internal.checkers.CatchByReferenceTest;
import org.eclipse.cdt.codan.core.internal.checkers.FormatStringCheckerTest;
+import org.eclipse.cdt.codan.core.internal.checkers.NonVirtualDestructorCheckerTest;
import org.eclipse.cdt.codan.core.internal.checkers.ProblemBindingCheckerTest;
import org.eclipse.cdt.codan.core.internal.checkers.ReturnCheckerTest;
import org.eclipse.cdt.codan.core.internal.checkers.ReturnStyleCheckerTest;
@@ -56,6 +57,7 @@ public class AutomatedIntegrationSuite extends TestSuite {
suite.addTestSuite(CaseBreakCheckerTest.class);
suite.addTestSuite(CatchByReferenceTest.class);
suite.addTestSuite(FormatStringCheckerTest.class);
+ suite.addTestSuite(NonVirtualDestructorCheckerTest.class);
suite.addTestSuite(ProblemBindingCheckerTest.class);
suite.addTestSuite(ReturnCheckerTest.class);
suite.addTestSuite(ReturnStyleCheckerTest.class);

Back to the top