summaryrefslogtreecommitdiffstats
path: root/src/testlib
diff options
context:
space:
mode:
authorLiang Qi <liang.qi@qt.io>2016-10-13 09:49:38 +0200
committerLiang Qi <liang.qi@qt.io>2016-10-13 09:49:38 +0200
commitdfc177e3a99dd593db4b1e9445d6243ce75ebf07 (patch)
tree4e33c7be90a44642e672fff22ea163b500ff3aef /src/testlib
parent72efb2e6f4af2fd909daaf9104f09fd1425acfb0 (diff)
parent1d6eb70dcec105af28d6a5e9b59d56c895c70389 (diff)
Merge remote-tracking branch 'origin/5.8' into dev
Conflicts: qmake/library/qmakeevaluator.cpp (cherry picked from commit 1af6dc2c8fb4d91400fddc5050166f972ae57c9a in qttools) src/corelib/kernel/qcore_mac_objc.mm src/gui/painting/qcolor.h src/plugins/platforms/cocoa/qcocoawindow.mm Change-Id: I5b3ec468a5a9a73911b528d3d24ff8e19f339f31
Diffstat (limited to 'src/testlib')
-rw-r--r--src/testlib/qtest.h28
-rw-r--r--src/testlib/qtest_network.h126
-rw-r--r--src/testlib/qtestcase.h54
-rw-r--r--src/testlib/testlib.pro1
4 files changed, 158 insertions, 51 deletions
diff --git a/src/testlib/qtest.h b/src/testlib/qtest.h
index 63e79c777f..b9bb10818e 100644
--- a/src/testlib/qtest.h
+++ b/src/testlib/qtest.h
@@ -58,10 +58,6 @@
#include <QtCore/qsize.h>
#include <QtCore/qrect.h>
-#ifdef QT_NETWORK_LIB
-# include <QtNetwork/qhostaddress.h>
-#endif
-
QT_BEGIN_NAMESPACE
@@ -192,26 +188,6 @@ template<> inline char *toString(const QVariant &v)
return qstrdup(vstring.constData());
}
-#ifdef QT_NETWORK_LIB
-/*!
- \internal
- */
-template<> inline char *toString(const QHostAddress &addr)
-{
- switch (addr.protocol()) {
- case QAbstractSocket::UnknownNetworkLayerProtocol:
- return qstrdup("<unknown address (parse error)>");
- case QAbstractSocket::AnyIPProtocol:
- return qstrdup("QHostAddress::Any");
- case QAbstractSocket::IPv4Protocol:
- case QAbstractSocket::IPv6Protocol:
- break;
- }
-
- return qstrdup(addr.toString().toLatin1().constData());
-}
-#endif
-
inline char *toString(std::nullptr_t)
{
return toString(QLatin1String("nullptr"));
@@ -357,6 +333,10 @@ int main(int argc, char *argv[]) \
# define QTEST_ADD_GPU_BLACKLIST_SUPPORT
#endif
+#if defined(QT_NETWORK_LIB)
+# include <QtTest/qtest_network.h>
+#endif
+
#if defined(QT_WIDGETS_LIB)
#include <QtTest/qtest_widgets.h>
diff --git a/src/testlib/qtest_network.h b/src/testlib/qtest_network.h
new file mode 100644
index 0000000000..6f6b4c1b8e
--- /dev/null
+++ b/src/testlib/qtest_network.h
@@ -0,0 +1,126 @@
+/****************************************************************************
+**
+** Copyright (C) 2016 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the QtTest module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** 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 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 3 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL3 included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 3 requirements
+** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 2.0 or (at your option) the GNU General
+** Public license version 3 or any later version approved by the KDE Free
+** Qt Foundation. The licenses are as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
+** 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-2.0.html and
+** https://www.gnu.org/licenses/gpl-3.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef QTEST_NETWORK_H
+#define QTEST_NETWORK_H
+
+#include <QtTest/qtest.h>
+
+// enable NETWORK features
+#ifndef QT_NETWORK_LIB
+#define QT_NETWORK_LIB
+#endif
+
+#if 0
+#pragma qt_class(QtTestNetwork)
+#endif
+
+#include <QtNetwork/QHostAddress>
+#include <QtNetwork/QNetworkCookie>
+#include <QtNetwork/QNetworkReply>
+
+#if 0
+// inform syncqt
+#pragma qt_no_master_include
+#endif
+
+QT_BEGIN_NAMESPACE
+
+namespace QTest
+{
+/*!
+ \internal
+ */
+inline char *toString(const QHostAddress &addr)
+{
+ switch (addr.protocol()) {
+ case QAbstractSocket::UnknownNetworkLayerProtocol:
+ return qstrdup("<unknown address (parse error)>");
+ case QAbstractSocket::AnyIPProtocol:
+ return qstrdup("QHostAddress::Any");
+ case QAbstractSocket::IPv4Protocol:
+ case QAbstractSocket::IPv6Protocol:
+ break;
+ }
+
+ return toString(addr.toString());
+}
+
+/*!
+ \internal
+ */
+inline char *toString(QNetworkReply::NetworkError code)
+{
+ const QMetaObject *mo = &QNetworkReply::staticMetaObject;
+ int index = mo->indexOfEnumerator("NetworkError");
+ if (index == -1)
+ return qstrdup("");
+
+ QMetaEnum qme = mo->enumerator(index);
+ return qstrdup(qme.valueToKey(code));
+}
+
+/*!
+ \internal
+ */
+inline char *toString(const QNetworkCookie &cookie)
+{
+ return toString(cookie.toRawForm());
+}
+
+/*!
+ \internal
+ */
+inline char *toString(const QList<QNetworkCookie> &list)
+{
+ QByteArray result = "QList(";
+ if (!list.isEmpty()) {
+ for (const QNetworkCookie &cookie : list)
+ result += "QNetworkCookie(" + cookie.toRawForm() + "), ";
+ result.chop(2); // remove trailing ", "
+ }
+ result.append(')');
+ return toString(result);
+}
+
+} // namespace QTest
+
+QT_END_NAMESPACE
+
+#endif
diff --git a/src/testlib/qtestcase.h b/src/testlib/qtestcase.h
index 106fa7abd5..045431fcaf 100644
--- a/src/testlib/qtestcase.h
+++ b/src/testlib/qtestcase.h
@@ -130,57 +130,57 @@ do {\
#endif // !QT_NO_EXCEPTIONS
-#define QTRY_LOOP_IMPL(__expr, __timeoutValue, __step) \
- if (!(__expr)) { \
+#define QTRY_LOOP_IMPL(expr, timeoutValue, step) \
+ if (!(expr)) { \
QTest::qWait(0); \
} \
- int __i = 0; \
- for (; __i < __timeoutValue && !(__expr); __i += __step) { \
- QTest::qWait(__step); \
+ int qt_test_i = 0; \
+ for (; qt_test_i < timeoutValue && !(expr); qt_test_i += step) { \
+ QTest::qWait(step); \
}
-#define QTRY_TIMEOUT_DEBUG_IMPL(__expr, __timeoutValue, __step)\
- if (!(__expr)) { \
- QTRY_LOOP_IMPL((__expr), (2 * __timeoutValue), __step);\
- if (__expr) { \
+#define QTRY_TIMEOUT_DEBUG_IMPL(expr, timeoutValue, step)\
+ if (!(expr)) { \
+ QTRY_LOOP_IMPL((expr), (2 * timeoutValue), step);\
+ if (expr) { \
QString msg = QString::fromUtf8("QTestLib: This test case check (\"%1\") failed because the requested timeout (%2 ms) was too short, %3 ms would have been sufficient this time."); \
- msg = msg.arg(QString::fromUtf8(#__expr)).arg(__timeoutValue).arg(__timeoutValue + __i); \
+ msg = msg.arg(QString::fromUtf8(#expr)).arg(timeoutValue).arg(timeoutValue + qt_test_i); \
QFAIL(qPrintable(msg)); \
} \
}
-#define QTRY_IMPL(__expr, __timeout)\
- const int __step = 50; \
- const int __timeoutValue = __timeout; \
- QTRY_LOOP_IMPL((__expr), __timeoutValue, __step); \
- QTRY_TIMEOUT_DEBUG_IMPL((__expr), __timeoutValue, __step)\
+#define QTRY_IMPL(expr, timeout)\
+ const int qt_test_step = 50; \
+ const int qt_test_timeoutValue = timeout; \
+ QTRY_LOOP_IMPL((expr), qt_test_timeoutValue, qt_test_step); \
+ QTRY_TIMEOUT_DEBUG_IMPL((expr), qt_test_timeoutValue, qt_test_step)\
// Will try to wait for the expression to become true while allowing event processing
-#define QTRY_VERIFY_WITH_TIMEOUT(__expr, __timeout) \
+#define QTRY_VERIFY_WITH_TIMEOUT(expr, timeout) \
do { \
- QTRY_IMPL((__expr), __timeout);\
- QVERIFY(__expr); \
+ QTRY_IMPL((expr), timeout);\
+ QVERIFY(expr); \
} while (0)
-#define QTRY_VERIFY(__expr) QTRY_VERIFY_WITH_TIMEOUT((__expr), 5000)
+#define QTRY_VERIFY(expr) QTRY_VERIFY_WITH_TIMEOUT((expr), 5000)
// Will try to wait for the expression to become true while allowing event processing
-#define QTRY_VERIFY2_WITH_TIMEOUT(__expr, __messageExpression, __timeout) \
+#define QTRY_VERIFY2_WITH_TIMEOUT(expr, messageExpression, timeout) \
do { \
- QTRY_IMPL((__expr), __timeout);\
- QVERIFY2(__expr, __messageExpression); \
+ QTRY_IMPL((expr), timeout);\
+ QVERIFY2(expr, messageExpression); \
} while (0)
-#define QTRY_VERIFY2(__expr, __messageExpression) QTRY_VERIFY2_WITH_TIMEOUT((__expr), (__messageExpression), 5000)
+#define QTRY_VERIFY2(expr, messageExpression) QTRY_VERIFY2_WITH_TIMEOUT((expr), (messageExpression), 5000)
// Will try to wait for the comparison to become successful while allowing event processing
-#define QTRY_COMPARE_WITH_TIMEOUT(__expr, __expected, __timeout) \
+#define QTRY_COMPARE_WITH_TIMEOUT(expr, expected, timeout) \
do { \
- QTRY_IMPL(((__expr) == (__expected)), __timeout);\
- QCOMPARE((__expr), __expected); \
+ QTRY_IMPL(((expr) == (expected)), timeout);\
+ QCOMPARE((expr), expected); \
} while (0)
-#define QTRY_COMPARE(__expr, __expected) QTRY_COMPARE_WITH_TIMEOUT((__expr), __expected, 5000)
+#define QTRY_COMPARE(expr, expected) QTRY_COMPARE_WITH_TIMEOUT((expr), expected, 5000)
#define QSKIP_INTERNAL(statement) \
do {\
diff --git a/src/testlib/testlib.pro b/src/testlib/testlib.pro
index 3fe1aeea96..d76dbb8c75 100644
--- a/src/testlib/testlib.pro
+++ b/src/testlib/testlib.pro
@@ -28,6 +28,7 @@ HEADERS = qbenchmark.h \
qtesteventloop.h \
qtest_global.h \
qtest_gui.h \
+ qtest_network.h \
qtest_widgets.h \
qtest.h \
qtestkeyboard.h \