From c35eff2ace00a8d4b8cc31ab5b63ec79b96cc07c Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Thu, 25 Aug 2016 09:06:54 +0200 Subject: Add qtest_network.h MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ... and move toString() implementations there which were repeated in network tests, or #ifdef'ed in qtest.h. Since the functions moved from network tests are now in a public header, had to massage them a bit to pass headersclean: - replace Q_FOREACH with C++11 range-for - avoid implicit conversion from QByteArray -> const char* (done by re-using toString(QByteArray) instead of calling strdup() manually) Also made the functions overloads instead of specializations. This allows to pass the enum by value instead of by const-&. Like the existing QHostAddress, the newly-added toString() overloads are marked as \internal. We can decide later whether to turn them into public API. Change-Id: I8c23db7a0a6575273567017d42d7b2a957acece8 Reviewed-by: Jędrzej Nowacki Reviewed-by: Timur Pocheptsov --- src/testlib/qtest.h | 28 ++++------------------------ 1 file changed, 4 insertions(+), 24 deletions(-) (limited to 'src/testlib/qtest.h') 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 #include -#ifdef QT_NETWORK_LIB -# include -#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(""); - 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 +#endif + #if defined(QT_WIDGETS_LIB) #include -- cgit v1.2.3