summaryrefslogtreecommitdiffstats
path: root/tests/auto/corelib/global/qglobal/tst_qglobal.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'tests/auto/corelib/global/qglobal/tst_qglobal.cpp')
-rw-r--r--tests/auto/corelib/global/qglobal/tst_qglobal.cpp151
1 files changed, 134 insertions, 17 deletions
diff --git a/tests/auto/corelib/global/qglobal/tst_qglobal.cpp b/tests/auto/corelib/global/qglobal/tst_qglobal.cpp
index 00f70f5380..bb4d1f4bf2 100644
--- a/tests/auto/corelib/global/qglobal/tst_qglobal.cpp
+++ b/tests/auto/corelib/global/qglobal/tst_qglobal.cpp
@@ -1,31 +1,26 @@
/****************************************************************************
**
-** Copyright (C) 2015 The Qt Company Ltd.
-** Contact: http://www.qt.io/licensing/
+** Copyright (C) 2016 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
**
** This file is part of the test suite of the Qt Toolkit.
**
-** $QT_BEGIN_LICENSE:LGPL21$
+** $QT_BEGIN_LICENSE:GPL-EXCEPT$
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see http://www.qt.io/terms-conditions. For further
-** information use the contact form at http://www.qt.io/contact-us.
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 2.1 or version 3 as published by the Free
-** Software Foundation and appearing in the file LICENSE.LGPLv21 and
-** LICENSE.LGPLv3 included in the packaging of this file. Please review the
-** following information to ensure the GNU Lesser General Public License
-** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
-** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
-**
-** As a special exception, The Qt Company gives you certain additional
-** rights. These rights are described in The Qt Company 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 as published by the Free Software
+** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-3.0.html.
**
** $QT_END_LICENSE$
**
@@ -60,6 +55,7 @@ private slots:
void qprintable();
void qprintable_data();
void buildAbiEndianness();
+ void testqOverload();
};
void tst_QGlobal::qIsNull()
@@ -657,5 +653,126 @@ void tst_QGlobal::buildAbiEndianness()
QVERIFY(QSysInfo::buildAbi().contains(endian));
}
+struct Overloaded
+{
+ void foo() {}
+ void foo(QByteArray) {}
+ void foo(QByteArray, const QString &) {}
+
+ void constFoo() const {}
+ void constFoo(QByteArray) const {}
+ void constFoo(QByteArray, const QString &) const {}
+
+ void mixedFoo() {}
+ void mixedFoo(QByteArray) const {}
+};
+
+void freeOverloaded() {}
+void freeOverloaded(QByteArray) {}
+void freeOverloaded(QByteArray, const QString &) {}
+
+void freeOverloadedGet(QByteArray) {}
+QByteArray freeOverloadedGet() { return QByteArray(); }
+
+
+void tst_QGlobal::testqOverload()
+{
+#ifdef Q_COMPILER_VARIADIC_TEMPLATES
+
+ // void returning free overloaded functions
+ QVERIFY(QOverload<>::of(&freeOverloaded) ==
+ static_cast<void (*)()>(&freeOverloaded));
+
+ QVERIFY(QOverload<QByteArray>::of(&freeOverloaded) ==
+ static_cast<void (*)(QByteArray)>(&freeOverloaded));
+
+ QVERIFY((QOverload<QByteArray, const QString &>::of(&freeOverloaded)) ==
+ static_cast<void (*)(QByteArray, const QString &)>(&freeOverloaded));
+
+ // value returning free overloaded functions
+ QVERIFY(QOverload<>::of(&freeOverloadedGet) ==
+ static_cast<QByteArray (*)()>(&freeOverloadedGet));
+
+ QVERIFY(QOverload<QByteArray>::of(&freeOverloadedGet) ==
+ static_cast<void (*)(QByteArray)>(&freeOverloadedGet));
+
+ // void returning overloaded member functions
+ QVERIFY(QOverload<>::of(&Overloaded::foo) ==
+ static_cast<void (Overloaded::*)()>(&Overloaded::foo));
+
+ QVERIFY(QOverload<QByteArray>::of(&Overloaded::foo) ==
+ static_cast<void (Overloaded::*)(QByteArray)>(&Overloaded::foo));
+
+ QVERIFY((QOverload<QByteArray, const QString &>::of(&Overloaded::foo)) ==
+ static_cast<void (Overloaded::*)(QByteArray, const QString &)>(&Overloaded::foo));
+
+ // void returning overloaded const member functions
+ QVERIFY(QOverload<>::of(&Overloaded::constFoo) ==
+ static_cast<void (Overloaded::*)() const>(&Overloaded::constFoo));
+
+ QVERIFY(QOverload<QByteArray>::of(&Overloaded::constFoo) ==
+ static_cast<void (Overloaded::*)(QByteArray) const>(&Overloaded::constFoo));
+
+ QVERIFY((QOverload<QByteArray, const QString &>::of(&Overloaded::constFoo)) ==
+ static_cast<void (Overloaded::*)(QByteArray, const QString &) const>(&Overloaded::constFoo));
+
+ // void returning overloaded const AND non-const member functions
+ QVERIFY(QNonConstOverload<>::of(&Overloaded::mixedFoo) ==
+ static_cast<void (Overloaded::*)()>(&Overloaded::mixedFoo));
+
+ QVERIFY(QConstOverload<QByteArray>::of(&Overloaded::mixedFoo) ==
+ static_cast<void (Overloaded::*)(QByteArray) const>(&Overloaded::mixedFoo));
+
+#if defined(__cpp_variable_templates) && __cpp_variable_templates >= 201304 // C++14
+
+ // void returning free overloaded functions
+ QVERIFY(qOverload<>(&freeOverloaded) ==
+ static_cast<void (*)()>(&freeOverloaded));
+
+ QVERIFY(qOverload<QByteArray>(&freeOverloaded) ==
+ static_cast<void (*)(QByteArray)>(&freeOverloaded));
+
+ QVERIFY((qOverload<QByteArray, const QString &>(&freeOverloaded) ==
+ static_cast<void (*)(QByteArray, const QString &)>(&freeOverloaded)));
+
+ // value returning free overloaded functions
+ QVERIFY(qOverload<>(&freeOverloadedGet) ==
+ static_cast<QByteArray (*)()>(&freeOverloadedGet));
+
+ QVERIFY(qOverload<QByteArray>(&freeOverloadedGet) ==
+ static_cast<void (*)(QByteArray)>(&freeOverloadedGet));
+
+ // void returning overloaded member functions
+ QVERIFY(qOverload<>(&Overloaded::foo) ==
+ static_cast<void (Overloaded::*)()>(&Overloaded::foo));
+
+ QVERIFY(qOverload<QByteArray>(&Overloaded::foo) ==
+ static_cast<void (Overloaded::*)(QByteArray)>(&Overloaded::foo));
+
+ QVERIFY((qOverload<QByteArray, const QString &>(&Overloaded::foo)) ==
+ static_cast<void (Overloaded::*)(QByteArray, const QString &)>(&Overloaded::foo));
+
+ // void returning overloaded const member functions
+ QVERIFY(qOverload<>(&Overloaded::constFoo) ==
+ static_cast<void (Overloaded::*)() const>(&Overloaded::constFoo));
+
+ QVERIFY(qOverload<QByteArray>(&Overloaded::constFoo) ==
+ static_cast<void (Overloaded::*)(QByteArray) const>(&Overloaded::constFoo));
+
+ QVERIFY((qOverload<QByteArray, const QString &>(&Overloaded::constFoo)) ==
+ static_cast<void (Overloaded::*)(QByteArray, const QString &) const>(&Overloaded::constFoo));
+
+ // void returning overloaded const AND non-const member functions
+ QVERIFY(qNonConstOverload<>(&Overloaded::mixedFoo) ==
+ static_cast<void (Overloaded::*)()>(&Overloaded::mixedFoo));
+
+ QVERIFY(qConstOverload<QByteArray>(&Overloaded::mixedFoo) ==
+ static_cast<void (Overloaded::*)(QByteArray) const>(&Overloaded::mixedFoo));
+#endif
+
+#endif
+}
+
+
QTEST_APPLESS_MAIN(tst_QGlobal)
#include "tst_qglobal.moc"