diff options
-rw-r--r-- | abstractmetabuilder.cpp | 6 | ||||
-rw-r--r-- | abstractmetalang.h | 24 | ||||
-rw-r--r-- | tests/CMakeLists.txt | 1 | ||||
-rw-r--r-- | tests/testdtorinformation.cpp | 76 | ||||
-rw-r--r-- | tests/testdtorinformation.h | 41 |
5 files changed, 146 insertions, 2 deletions
diff --git a/abstractmetabuilder.cpp b/abstractmetabuilder.cpp index c754d1367..d40efd667 100644 --- a/abstractmetabuilder.cpp +++ b/abstractmetabuilder.cpp @@ -1209,8 +1209,10 @@ void AbstractMetaBuilder::traverseFunctions(ScopeModelItem scopeItem, AbstractMe } metaClass->addFunction(metaFunction); - } else if (metaFunction->isDestructor() && metaFunction->isPrivate()) { - metaClass->setHasPrivateDestructor(true); + } else if (metaFunction->isDestructor()) { + metaClass->setHasPrivateDestructor(metaFunction->isPrivate()); + metaClass->setHasProtectedDestructor(metaFunction->isProtected()); + metaClass->setHasVirtualDestructor(metaFunction->isVirtual()); } applyFunctionModifications(metaFunction); } diff --git a/abstractmetalang.h b/abstractmetalang.h index 76d9d652b..7915ea21b 100644 --- a/abstractmetalang.h +++ b/abstractmetalang.h @@ -1308,6 +1308,8 @@ public: m_hasNonPrivateConstructor(false), m_functionsFixed(false), m_hasPrivateDestructor(false), + m_hasProtectedDestructor(false), + m_hasVirtualDestructor(false), m_forceShellClass(false), m_hasHashFunction(false), m_hasEqualsOperator(false), @@ -1364,6 +1366,26 @@ public: m_hasPrivateDestructor = value; } + bool hasProtectedDestructor() const + { + return m_hasProtectedDestructor; + } + + void setHasProtectedDestructor(bool value) + { + m_hasProtectedDestructor = value; + } + + bool hasVirtualDestructor() const + { + return m_hasVirtualDestructor; + } + + void setHasVirtualDestructor(bool value) + { + m_hasVirtualDestructor = value; + } + AbstractMetaFunctionList queryFunctionsByName(const QString &name) const; AbstractMetaFunctionList queryFunctions(uint query) const; inline AbstractMetaFunctionList allVirtualFunctions() const; @@ -1757,6 +1779,8 @@ private: uint m_hasNonPrivateConstructor : 1; uint m_functionsFixed : 1; uint m_hasPrivateDestructor : 1; + uint m_hasProtectedDestructor : 1; + uint m_hasVirtualDestructor : 1; uint m_forceShellClass : 1; uint m_hasHashFunction : 1; uint m_hasEqualsOperator : 1; diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 5a104907d..78966362c 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -14,3 +14,4 @@ declare_test(testmodifydocumentation) declare_test(testaddfunction) declare_test(testconversionruletag) declare_test(testreverseoperators) +declare_test(testdtorinformation) diff --git a/tests/testdtorinformation.cpp b/tests/testdtorinformation.cpp new file mode 100644 index 000000000..1aaeb91dc --- /dev/null +++ b/tests/testdtorinformation.cpp @@ -0,0 +1,76 @@ +/* +* This file is part of the API Extractor project. +* +* Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +* +* Contact: PySide team <contact@pyside.org> +* +* This program is free software; you can redistribute it and/or +* modify it under the terms of the GNU General Public License +* version 2 as published by the Free Software Foundation. +* +* This program is distributed in the hope that it will be useful, but +* WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +* General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program; if not, write to the Free Software +* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA +* 02110-1301 USA +* +*/ + +#include "testdtorinformation.h" +#include "abstractmetabuilder.h" +#include <QtTest/QTest> +#include "testutil.h" + +void TestDtorInformation::testDtorIsPrivate() +{ + const char* cppCode ="class Control { public: ~Control() {} }; class Subject { private: ~Subject() {} };"; + const char* xmlCode = "<typesystem package=\"Foo\"><value-type name=\"Control\"/><value-type name=\"Subject\"/></typesystem>"; + TestUtil t(cppCode, xmlCode); + AbstractMetaClassList classes = t.builder()->classes(); + QCOMPARE(classes.count(), 2); + QCOMPARE(classes.findClass("Control")->hasPrivateDestructor(), false); + QCOMPARE(classes.findClass("Subject")->hasPrivateDestructor(), true); +} + +void TestDtorInformation::testDtorIsProtected() +{ + const char* cppCode ="class Control { public: ~Control() {} }; class Subject { protected: ~Subject() {} };"; + const char* xmlCode = "<typesystem package=\"Foo\"><value-type name=\"Control\"/><value-type name=\"Subject\"/></typesystem>"; + TestUtil t(cppCode, xmlCode); + AbstractMetaClassList classes = t.builder()->classes(); + QCOMPARE(classes.count(), 2); + QCOMPARE(classes.findClass("Control")->hasProtectedDestructor(), false); + QCOMPARE(classes.findClass("Subject")->hasProtectedDestructor(), true); +} + +void TestDtorInformation::testDtorIsVirtual() +{ + const char* cppCode ="class Control { public: ~Control() {} }; class Subject { protected: virtual ~Subject() {} };"; + const char* xmlCode = "<typesystem package=\"Foo\"><value-type name=\"Control\"/><value-type name=\"Subject\"/></typesystem>"; + TestUtil t(cppCode, xmlCode); + AbstractMetaClassList classes = t.builder()->classes(); + QCOMPARE(classes.count(), 2); + QCOMPARE(classes.findClass("Control")->hasVirtualDestructor(), false); + QCOMPARE(classes.findClass("Subject")->hasVirtualDestructor(), true); +} + +void TestDtorInformation::testClassWithVirtualDtorIsPolymorphic() +{ + const char* cppCode ="class Control { public: virtual ~Control() {} }; class Subject { protected: virtual ~Subject() {} };"; + const char* xmlCode = "<typesystem package=\"Foo\"><value-type name=\"Control\"/><value-type name=\"Subject\"/></typesystem>"; + TestUtil t(cppCode, xmlCode); + AbstractMetaClassList classes = t.builder()->classes(); + QCOMPARE(classes.count(), 2); + QCOMPARE(classes.findClass("Control")->isPolymorphic(), true); + QCOMPARE(classes.findClass("Subject")->isPolymorphic(), true); +} + +QTEST_APPLESS_MAIN(TestDtorInformation) + +#include "testdtorinformation.moc" + diff --git a/tests/testdtorinformation.h b/tests/testdtorinformation.h new file mode 100644 index 000000000..2e378001b --- /dev/null +++ b/tests/testdtorinformation.h @@ -0,0 +1,41 @@ +/* +* This file is part of the API Extractor project. +* +* Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +* +* Contact: PySide team <contact@pyside.org> +* +* This program is free software; you can redistribute it and/or +* modify it under the terms of the GNU General Public License +* version 2 as published by the Free Software Foundation. +* +* This program is distributed in the hope that it will be useful, but +* WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +* General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program; if not, write to the Free Software +* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA +* 02110-1301 USA +* +*/ + +#ifndef TESTDTORINFORMATION_H +#define TESTDTORINFORMATION_H + +#include <QObject> + +class AbstractMetaBuilder; + +class TestDtorInformation: public QObject +{ + Q_OBJECT +private slots: + void testDtorIsPrivate(); + void testDtorIsProtected(); + void testDtorIsVirtual(); + void testClassWithVirtualDtorIsPolymorphic(); +}; + +#endif // TESTDTORINFORMATION_H |