QtTest: Add QHostAddress support for QCOMPARE failures

Change-Id: Iee8cbc07c4434ce9b560ffff13cc6dad04a5a554
Reviewed-by: Richard J. Moore <rich@kde.org>
This commit is contained in:
Thiago Macieira 2015-03-18 08:42:51 +09:00
parent 45e59556ed
commit 060b7ffe5b
2 changed files with 20 additions and 12 deletions

View File

@ -51,6 +51,9 @@
#include <QtCore/qsize.h>
#include <QtCore/qrect.h>
#ifdef QT_NETWORK_LIB
# include <QtNetwork/qhostaddress.h>
#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("<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
template<>
inline bool qCompare(QString const &t1, QLatin1String const &t2, const char *actual,
const char *expected, const char *file, int line)

View File

@ -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("<invalid>");
return qstrdup(addr.toString().toLatin1());
}
}
QT_END_NAMESPACE
tst_QHostAddress::tst_QHostAddress()
{
}