summaryrefslogtreecommitdiffstats
path: root/tests/auto/network/access
diff options
context:
space:
mode:
authorMarc Mutz <marc.mutz@kdab.com>2016-08-25 09:06:54 +0200
committerMarc Mutz <marc.mutz@kdab.com>2016-09-29 21:46:19 +0000
commitc35eff2ace00a8d4b8cc31ab5b63ec79b96cc07c (patch)
tree2326731d86ff01ad89c8915bf207a71d3132a961 /tests/auto/network/access
parent157ee01a8d0be9a4dbac03883c9eaf3609fc1172 (diff)
Add qtest_network.h
... 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 <jedrzej.nowacki@theqtcompany.com> Reviewed-by: Timur Pocheptsov <timur.pocheptsov@theqtcompany.com>
Diffstat (limited to 'tests/auto/network/access')
-rw-r--r--tests/auto/network/access/qnetworkcookie/tst_qnetworkcookie.cpp27
-rw-r--r--tests/auto/network/access/qnetworkcookiejar/tst_qnetworkcookiejar.cpp28
-rw-r--r--tests/auto/network/access/qnetworkreply/tst_qnetworkreply.cpp39
-rw-r--r--tests/auto/network/access/qnetworkrequest/tst_qnetworkrequest.cpp27
4 files changed, 0 insertions, 121 deletions
diff --git a/tests/auto/network/access/qnetworkcookie/tst_qnetworkcookie.cpp b/tests/auto/network/access/qnetworkcookie/tst_qnetworkcookie.cpp
index 0424fc47ed..96c4917473 100644
--- a/tests/auto/network/access/qnetworkcookie/tst_qnetworkcookie.cpp
+++ b/tests/auto/network/access/qnetworkcookie/tst_qnetworkcookie.cpp
@@ -46,33 +46,6 @@ private slots:
void parseMultipleCookies();
};
-QT_BEGIN_NAMESPACE
-
-namespace QTest {
- template<>
- char *toString(const QNetworkCookie &cookie)
- {
- return qstrdup(cookie.toRawForm());
- }
-
- template<>
- char *toString(const QList<QNetworkCookie> &list)
- {
- QByteArray result = "QList(";
- bool first = true;
- foreach (QNetworkCookie cookie, list) {
- if (!first)
- result += ", ";
- first = false;
- result += "QNetworkCookie(" + cookie.toRawForm() + ')';
- }
- result.append(')');
- return qstrdup(result.constData());
- }
-}
-
-QT_END_NAMESPACE
-
void tst_QNetworkCookie::getterSetter()
{
QNetworkCookie cookie;
diff --git a/tests/auto/network/access/qnetworkcookiejar/tst_qnetworkcookiejar.cpp b/tests/auto/network/access/qnetworkcookiejar/tst_qnetworkcookiejar.cpp
index 8a1a5b8369..f9cc33fb26 100644
--- a/tests/auto/network/access/qnetworkcookiejar/tst_qnetworkcookiejar.cpp
+++ b/tests/auto/network/access/qnetworkcookiejar/tst_qnetworkcookiejar.cpp
@@ -55,34 +55,6 @@ private slots:
void rfc6265();
};
-QT_BEGIN_NAMESPACE
-
-namespace QTest {
- template<>
- char *toString(const QNetworkCookie &cookie)
- {
- return qstrdup(cookie.toRawForm());
- }
-
- template<>
- char *toString(const QList<QNetworkCookie> &list)
- {
- QByteArray result = "QList(";
- bool first = true;
- foreach (QNetworkCookie cookie, list) {
- if (!first)
- result += ", ";
- first = false;
- result += "QNetworkCookie(" + cookie.toRawForm() + ')';
- }
-
- result.append(')');
- return qstrdup(result.constData());
- }
-}
-
-QT_END_NAMESPACE
-
class MyCookieJar: public QNetworkCookieJar
{
public:
diff --git a/tests/auto/network/access/qnetworkreply/tst_qnetworkreply.cpp b/tests/auto/network/access/qnetworkreply/tst_qnetworkreply.cpp
index 43e05c95f9..38c3b47aae 100644
--- a/tests/auto/network/access/qnetworkreply/tst_qnetworkreply.cpp
+++ b/tests/auto/network/access/qnetworkreply/tst_qnetworkreply.cpp
@@ -490,45 +490,6 @@ private:
bool tst_QNetworkReply::seedCreated = false;
-QT_BEGIN_NAMESPACE
-
-namespace QTest {
- template<>
- char *toString(const 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));
- }
-
- template<>
- char *toString(const QNetworkCookie &cookie)
- {
- return qstrdup(cookie.toRawForm());
- }
-
- template<>
- char *toString(const QList<QNetworkCookie> &list)
- {
- QByteArray result = "QList(";
- bool first = true;
- foreach (QNetworkCookie cookie, list) {
- if (!first)
- result += ", ";
- first = false;
- result += "QNetworkCookie(" + cookie.toRawForm() + ')';
- }
- result.append(')');
- return qstrdup(result.constData());
- }
-}
-
-QT_END_NAMESPACE
-
#define RUN_REQUEST(call) \
do { \
QString errorMsg = call; \
diff --git a/tests/auto/network/access/qnetworkrequest/tst_qnetworkrequest.cpp b/tests/auto/network/access/qnetworkrequest/tst_qnetworkrequest.cpp
index a14aaf3cb1..bc9144e40e 100644
--- a/tests/auto/network/access/qnetworkrequest/tst_qnetworkrequest.cpp
+++ b/tests/auto/network/access/qnetworkrequest/tst_qnetworkrequest.cpp
@@ -56,33 +56,6 @@ private slots:
void removeHeader();
};
-QT_BEGIN_NAMESPACE
-
-namespace QTest {
- template<>
- char *toString(const QNetworkCookie &cookie)
- {
- return qstrdup(cookie.toRawForm());
- }
-
- template<>
- char *toString(const QList<QNetworkCookie> &list)
- {
- QByteArray result = "QList(";
- bool first = true;
- foreach (QNetworkCookie cookie, list) {
- if (!first)
- result += ", ";
- first = false;
- result += "QNetworkCookie(" + cookie.toRawForm() + ')';
- }
- result.append(')');
- return qstrdup(result.constData());
- }
-}
-
-QT_END_NAMESPACE
-
void tst_QNetworkRequest::ctor_data()
{
QTest::addColumn<QUrl>("url");