From bd1a7ed26bf845dea56d6e3afb63665630d0b76f Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Tue, 10 Jul 2012 18:08:18 +0200 Subject: moc: test slots marked final/override in various ways While writing the test, I found that moc doesn't yet support volatile slots. I left the tests in, commented, for a time when it does. Change-Id: Ib5fa00b25600618aedcc66739630054f3c879b99 Reviewed-by: Olivier Goffart --- .../tools/moc/cxx11-explicit-override-control.h | 256 +++++++++++++++++++++ tests/auto/tools/moc/moc.pro | 1 + tests/auto/tools/moc/tst_moc.cpp | 40 ++++ 3 files changed, 297 insertions(+) create mode 100644 tests/auto/tools/moc/cxx11-explicit-override-control.h diff --git a/tests/auto/tools/moc/cxx11-explicit-override-control.h b/tests/auto/tools/moc/cxx11-explicit-override-control.h new file mode 100644 index 0000000000..622046b033 --- /dev/null +++ b/tests/auto/tools/moc/cxx11-explicit-override-control.h @@ -0,0 +1,256 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com, author Marc Mutz +** Contact: http://www.qt-project.org/ +** +** This file is part of the test suite of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** GNU Lesser General Public License Usage +** This file may be used under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation and +** appearing in the file LICENSE.LGPL included in the packaging of this +** file. Please review the following information to ensure the GNU Lesser +** General Public License version 2.1 requirements will be met: +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU General +** Public License version 3.0 as published by the Free Software Foundation +** and appearing in the file LICENSE.GPL included in the packaging of this +** file. Please review the following information to ensure the GNU General +** Public License version 3.0 requirements will be met: +** http://www.gnu.org/copyleft/gpl.html. +** +** Other Usage +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ +#ifndef TESTS_AUTO_CORELIB_TOOLS_MOC_CXX11_EXPLICIT_OVERRIDE_CONTROL_H +#define TESTS_AUTO_CORELIB_TOOLS_MOC_CXX11_EXPLICIT_OVERRIDE_CONTROL_H + +#include + +#ifndef Q_MOC_RUN // hide from moc +# define override +# define final +# define sealed +#endif + +class ExplicitOverrideControlBase : public QObject +{ + Q_OBJECT +public: + explicit ExplicitOverrideControlBase(QObject *parent = 0) + : QObject(parent) {} + +private Q_SLOTS: + virtual void pureSlot0() = 0; + virtual void pureSlot1() = 0; + virtual void pureSlot2() const = 0; + virtual void pureSlot3() const = 0; +#if 0 // moc doesn't support volatile slots + virtual void pureSlot4() volatile = 0; + virtual void pureSlot5() volatile = 0; + virtual void pureSlot6() const volatile = 0; + virtual void pureSlot7() volatile const = 0; + virtual void pureSlot8() const volatile = 0; + virtual void pureSlot9() volatile const = 0; +#endif +}; + +class ExplicitOverrideControlFinalQt : public ExplicitOverrideControlBase +{ + Q_OBJECT +public: + explicit ExplicitOverrideControlFinalQt(QObject *parent = 0) + : ExplicitOverrideControlBase(parent) {} + +private Q_SLOTS: + void pureSlot0() Q_DECL_FINAL {} + void pureSlot1() Q_DECL_FINAL {} + void pureSlot2() const Q_DECL_FINAL {} + void pureSlot3() Q_DECL_FINAL const {} +#if 0 // moc doesn't support volatile slots + void pureSlot4() volatile Q_DECL_FINAL {} + void pureSlot5() Q_DECL_FINAL volatile {} + void pureSlot6() const volatile Q_DECL_FINAL {} + void pureSlot7() volatile Q_DECL_FINAL const {} + void pureSlot8() const Q_DECL_FINAL volatile {} + void pureSlot9() Q_DECL_FINAL volatile const {} +#endif +}; + +class ExplicitOverrideControlFinalCxx11 : public ExplicitOverrideControlBase +{ + Q_OBJECT +public: + explicit ExplicitOverrideControlFinalCxx11(QObject *parent = 0) + : ExplicitOverrideControlBase(parent) {} + +private Q_SLOTS: + void pureSlot0() final {} + void pureSlot1() final {} + void pureSlot2() const final {} + void pureSlot3() final const {} +#if 0 // moc doesn't support volatile slots + void pureSlot4() volatile final {} + void pureSlot5() final volatile {} + void pureSlot6() const volatile final {} + void pureSlot7() volatile final const {} + void pureSlot8() const final volatile {} + void pureSlot9() final volatile const {} +#endif +}; + +class ExplicitOverrideControlSealed : public ExplicitOverrideControlBase +{ + Q_OBJECT +public: + explicit ExplicitOverrideControlSealed(QObject *parent = 0) + : ExplicitOverrideControlBase(parent) {} + +private Q_SLOTS: + void pureSlot0() sealed {} + void pureSlot1() sealed {} + void pureSlot2() const sealed {} + void pureSlot3() sealed const {} +#if 0 // moc doesn't support volatile slots + void pureSlot4() volatile sealed {} + void pureSlot5() sealed volatile {} + void pureSlot6() const volatile sealed {} + void pureSlot7() volatile sealed const {} + void pureSlot8() const sealed volatile {} + void pureSlot9() sealed volatile const {} +#endif +}; + +class ExplicitOverrideControlOverrideQt : public ExplicitOverrideControlBase +{ + Q_OBJECT +public: + explicit ExplicitOverrideControlOverrideQt(QObject *parent = 0) + : ExplicitOverrideControlBase(parent) {} + +private Q_SLOTS: + void pureSlot0() Q_DECL_OVERRIDE {} + void pureSlot1() Q_DECL_OVERRIDE {} + void pureSlot2() const Q_DECL_OVERRIDE {} + void pureSlot3() Q_DECL_OVERRIDE const {} +#if 0 // moc doesn't support volatile slots + void pureSlot4() volatile Q_DECL_OVERRIDE {} + void pureSlot5() Q_DECL_OVERRIDE volatile {} + void pureSlot6() const volatile Q_DECL_OVERRIDE {} + void pureSlot7() volatile Q_DECL_OVERRIDE const {} + void pureSlot8() const Q_DECL_OVERRIDE volatile {} + void pureSlot9() Q_DECL_OVERRIDE volatile const {} +#endif +}; + +class ExplicitOverrideControlOverrideCxx11 : public ExplicitOverrideControlBase +{ + Q_OBJECT +public: + explicit ExplicitOverrideControlOverrideCxx11(QObject *parent = 0) + : ExplicitOverrideControlBase(parent) {} + +private Q_SLOTS: + void pureSlot0() override {} + void pureSlot1() override {} + void pureSlot2() const override {} + void pureSlot3() override const {} +#if 0 // moc doesn't support volatile slots + void pureSlot4() volatile override {} + void pureSlot5() override volatile {} + void pureSlot6() const volatile override {} + void pureSlot7() volatile override const {} + void pureSlot8() const override volatile {} + void pureSlot9() override volatile const {} +#endif +}; + +class ExplicitOverrideControlFinalQtOverrideQt : public ExplicitOverrideControlBase +{ + Q_OBJECT +public: + explicit ExplicitOverrideControlFinalQtOverrideQt(QObject *parent = 0) + : ExplicitOverrideControlBase(parent) {} + +private Q_SLOTS: + void pureSlot0() Q_DECL_FINAL Q_DECL_OVERRIDE {} + void pureSlot1() Q_DECL_OVERRIDE Q_DECL_FINAL {} + void pureSlot2() Q_DECL_OVERRIDE const Q_DECL_FINAL {} + void pureSlot3() Q_DECL_FINAL const Q_DECL_OVERRIDE {} +#if 0 // moc doesn't support volatile slots + void pureSlot4() volatile Q_DECL_FINAL Q_DECL_OVERRIDE {} + void pureSlot5() Q_DECL_OVERRIDE Q_DECL_FINAL volatile {} + void pureSlot6() Q_DECL_OVERRIDE const volatile Q_DECL_FINAL {} + void pureSlot7() volatile Q_DECL_OVERRIDE Q_DECL_FINAL const {} + void pureSlot8() const Q_DECL_FINAL Q_DECL_OVERRIDE volatile {} + void pureSlot9() Q_DECL_FINAL volatile const Q_DECL_OVERRIDE {} +#endif +}; + +class ExplicitOverrideControlFinalCxx11OverrideCxx11 : public ExplicitOverrideControlBase +{ + Q_OBJECT +public: + explicit ExplicitOverrideControlFinalCxx11OverrideCxx11(QObject *parent = 0) + : ExplicitOverrideControlBase(parent) {} + +private Q_SLOTS: + void pureSlot0() final override {} + void pureSlot1() override final {} + void pureSlot2() override const final {} + void pureSlot3() final const override {} +#if 0 // moc doesn't support volatile slots + void pureSlot4() volatile final override {} + void pureSlot5() override final volatile {} + void pureSlot6() const volatile final override {} + void pureSlot7() volatile final override const {} + void pureSlot8() const override final volatile {} + void pureSlot9() override final volatile const {} +#endif +}; + +class ExplicitOverrideControlSealedOverride : public ExplicitOverrideControlBase +{ + Q_OBJECT +public: + explicit ExplicitOverrideControlSealedOverride(QObject *parent = 0) + : ExplicitOverrideControlBase(parent) {} + +private Q_SLOTS: + void pureSlot0() sealed override {} + void pureSlot1() override sealed {} + void pureSlot2() override const sealed {} + void pureSlot3() sealed const override {} +#if 0 // moc doesn't support volatile slots + void pureSlot4() volatile sealed override {} + void pureSlot5() sealed override volatile {} + void pureSlot6() const override volatile sealed {} + void pureSlot7() volatile sealed override const {} + void pureSlot8() const sealed volatile override {} + void pureSlot9() override sealed volatile const {} +#endif +}; + +#ifndef Q_MOC_RUN +# undef final +# undef sealed +# undef override +#endif + +#endif // TESTS_AUTO_CORELIB_TOOLS_MOC_CXX11_EXPLICIT_OVERRIDE_CONTROL_H diff --git a/tests/auto/tools/moc/moc.pro b/tests/auto/tools/moc/moc.pro index 3987309637..b3ed5df469 100644 --- a/tests/auto/tools/moc/moc.pro +++ b/tests/auto/tools/moc/moc.pro @@ -20,6 +20,7 @@ HEADERS += using-namespaces.h no-keywords.h task87883.h c-comments.h backslash-n dir-in-include-path.h single_function_keyword.h task192552.h task189996.h \ task234909.h task240368.h pure-virtual-signals.h cxx11-enums.h \ cxx11-final-classes.h \ + cxx11-explicit-override-control.h \ if(*-g++*|*-icc*|*-clang*|*-llvm):!irix-*:!win32-*: HEADERS += os9-newlines.h win-newlines.h diff --git a/tests/auto/tools/moc/tst_moc.cpp b/tests/auto/tools/moc/tst_moc.cpp index 622255a640..f60ab112ed 100644 --- a/tests/auto/tools/moc/tst_moc.cpp +++ b/tests/auto/tools/moc/tst_moc.cpp @@ -72,6 +72,7 @@ #endif #include "cxx11-enums.h" #include "cxx11-final-classes.h" +#include "cxx11-explicit-override-control.h" QT_USE_NAMESPACE @@ -546,6 +547,8 @@ private slots: void privateSignalConnection(); void finalClasses_data(); void finalClasses(); + void explicitOverrideControl_data(); + void explicitOverrideControl(); signals: void sigWithUnsignedArg(unsigned foo); @@ -2253,6 +2256,43 @@ void tst_Moc::finalClasses() QCOMPARE(className, expected); } +Q_DECLARE_METATYPE(const QMetaObject*); + +void tst_Moc::explicitOverrideControl_data() +{ + QTest::addColumn("mo"); + +#define ADD(x) QTest::newRow(#x) << &x::staticMetaObject + ADD(ExplicitOverrideControlFinalQt); + ADD(ExplicitOverrideControlFinalCxx11); + ADD(ExplicitOverrideControlSealed); + ADD(ExplicitOverrideControlOverrideQt); + ADD(ExplicitOverrideControlOverrideCxx11); + ADD(ExplicitOverrideControlFinalQtOverrideQt); + ADD(ExplicitOverrideControlFinalCxx11OverrideCxx11); + ADD(ExplicitOverrideControlSealedOverride); +#undef ADD +} + +void tst_Moc::explicitOverrideControl() +{ + QFETCH(const QMetaObject*, mo); + + QVERIFY(mo); + QCOMPARE(mo->indexOfMethod("pureSlot0()"), mo->methodOffset() + 0); + QCOMPARE(mo->indexOfMethod("pureSlot1()"), mo->methodOffset() + 1); + QCOMPARE(mo->indexOfMethod("pureSlot2()"), mo->methodOffset() + 2); + QCOMPARE(mo->indexOfMethod("pureSlot3()"), mo->methodOffset() + 3); +#if 0 // moc doesn't support volatile slots + QCOMPARE(mo->indexOfMethod("pureSlot4()"), mo->methodOffset() + 4); + QCOMPARE(mo->indexOfMethod("pureSlot5()"), mo->methodOffset() + 5); + QCOMPARE(mo->indexOfMethod("pureSlot6()"), mo->methodOffset() + 6); + QCOMPARE(mo->indexOfMethod("pureSlot7()"), mo->methodOffset() + 7); + QCOMPARE(mo->indexOfMethod("pureSlot8()"), mo->methodOffset() + 8); + QCOMPARE(mo->indexOfMethod("pureSlot9()"), mo->methodOffset() + 9); +#endif +} + QTEST_MAIN(tst_Moc) #include "tst_moc.moc" -- cgit v1.2.3