1// Copyright (C) 2016 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
4#ifndef QTEST_NETWORK_H
5#define QTEST_NETWORK_H
6
7#include <QtTest/qtesttostring.h>
8
9// enable NETWORK features
10#ifndef QT_NETWORK_LIB
11#define QT_NETWORK_LIB
12#endif
13
14#if 0
15#pragma qt_class(QtTestNetwork)
16#endif
17
18#include <QtNetwork/QHostAddress>
19#include <QtNetwork/QNetworkCookie>
20#include <QtNetwork/QNetworkReply>
21
22#if 0
23// inform syncqt
24#pragma qt_no_master_include
25#endif
26
27QT_BEGIN_NAMESPACE
28
29namespace QTest
30{
31template<>
32inline char *toString<QHostAddress>(const QHostAddress &addr)
33{
34 switch (addr.protocol()) {
35 case QAbstractSocket::UnknownNetworkLayerProtocol:
36 return qstrdup("<unknown address (parse error)>");
37 case QAbstractSocket::AnyIPProtocol:
38 return qstrdup("QHostAddress::Any");
39 case QAbstractSocket::IPv4Protocol:
40 case QAbstractSocket::IPv6Protocol:
41 break;
42 }
43
44 return toString(str: addr.toString());
45}
46} // namespace QTest
47
48inline char *toString(QNetworkReply::NetworkError code)
49{
50 const QMetaObject *mo = &QNetworkReply::staticMetaObject;
51 int index = mo->indexOfEnumerator(name: "NetworkError");
52 if (index == -1)
53 return qstrdup("");
54
55 QMetaEnum qme = mo->enumerator(index);
56 return qstrdup(qme.valueToKey(value: code));
57}
58
59inline char *toString(const QNetworkCookie &cookie)
60{
61 return QTest::toString(ba: cookie.toRawForm());
62}
63
64inline char *toString(const QList<QNetworkCookie> &list)
65{
66 QByteArray result = "QList(";
67 if (!list.isEmpty()) {
68 for (const QNetworkCookie &cookie : list)
69 result += "QNetworkCookie(" + cookie.toRawForm() + "), ";
70 result.chop(n: 2); // remove trailing ", "
71 }
72 result.append(c: ')');
73 return QTest::toString(ba: result);
74}
75
76QT_END_NAMESPACE
77
78#endif
79

Provided by KDAB

Privacy Policy
Learn Advanced QML with KDAB
Find out more

source code of qtbase/src/testlib/qtest_network.h