1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163
|
/**
* This file is part of OpenOrienteering.
*
* This is a modified version of tst_qglobal.cpp from the Qt Toolkit 5.7.
* You can redistribute it and/or modify it under the terms of
* the GNU General Public License, version 3, as published by
* the Free Software Foundation.
*
* OpenOrienteering 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 OpenOrienteering. If not, see <http://www.gnu.org/licenses/>
*
* Changes:
* 2016-03-25 Kai Pastor <dg0yt@darc.de>
* - Adjustment of legal information
* - Reduction to qOverload related tests
* - Adaption to our testing framework
*/
/****************************************************************************
**
** Copyright (C) 2016 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
****************************************************************************/
#include "tst_qglobal.h"
#include <QtGlobal>
#include <QtTest>
#include <QByteArray>
#include <QString>
#include "util/backports.h" // IWYU pragma: keep
// clazy:excludeall=function-args-by-ref
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)
|