From 060b7ffe5bb5641fac103358f628fe38daf460d1 Mon Sep 17 00:00:00 2001 From: Thiago Macieira Date: Wed, 18 Mar 2015 08:42:51 +0900 Subject: [PATCH] QtTest: Add QHostAddress support for QCOMPARE failures Change-Id: Iee8cbc07c4434ce9b560ffff13cc6dad04a5a554 Reviewed-by: Richard J. Moore --- src/testlib/qtest.h | 20 +++++++++++++++++++ .../kernel/qhostaddress/tst_qhostaddress.cpp | 12 ----------- 2 files changed, 20 insertions(+), 12 deletions(-) diff --git a/src/testlib/qtest.h b/src/testlib/qtest.h index 1d8b195907..8da16af91e 100644 --- a/src/testlib/qtest.h +++ b/src/testlib/qtest.h @@ -51,6 +51,9 @@ #include #include +#ifdef QT_NETWORK_LIB +# include +#endif QT_BEGIN_NAMESPACE @@ -162,6 +165,23 @@ template<> inline char *toString(const QVariant &v) return qstrdup(vstring.constData()); } +#ifdef QT_NETWORK_LIB +template<> inline char *toString(const QHostAddress &addr) +{ + switch (addr.protocol()) { + case QAbstractSocket::UnknownNetworkLayerProtocol: + return qstrdup(""); + case QAbstractSocket::AnyIPProtocol: + return qstrdup("QHostAddress::Any"); + case QAbstractSocket::IPv4Protocol: + case QAbstractSocket::IPv6Protocol: + break; + } + + return qstrdup(addr.toString().toLatin1().constData()); +} +#endif + template<> inline bool qCompare(QString const &t1, QLatin1String const &t2, const char *actual, const char *expected, const char *file, int line) diff --git a/tests/auto/network/kernel/qhostaddress/tst_qhostaddress.cpp b/tests/auto/network/kernel/qhostaddress/tst_qhostaddress.cpp index e074ecae1d..dbb27b955a 100644 --- a/tests/auto/network/kernel/qhostaddress/tst_qhostaddress.cpp +++ b/tests/auto/network/kernel/qhostaddress/tst_qhostaddress.cpp @@ -87,18 +87,6 @@ private slots: void convertv4v6(); }; -QT_BEGIN_NAMESPACE -namespace QTest { - template<> - char *toString(const QHostAddress &addr) - { - if (addr.protocol() == QAbstractSocket::UnknownNetworkLayerProtocol) - return qstrdup(""); - return qstrdup(addr.toString().toLatin1()); - } -} -QT_END_NAMESPACE - tst_QHostAddress::tst_QHostAddress() { }