Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
qtest_network.h
Go to the documentation of this file.
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<>
33{
34 switch (addr.protocol()) {
36 return qstrdup("<unknown address (parse error)>");
38 return qstrdup("QHostAddress::Any");
41 break;
42 }
43
44 return toString(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("NetworkError");
52 if (index == -1)
53 return qstrdup("");
54
55 QMetaEnum qme = mo->enumerator(index);
56 return qstrdup(qme.valueToKey(code));
57}
58
59inline char *toString(const QNetworkCookie &cookie)
60{
61 return QTest::toString(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(2); // remove trailing ", "
71 }
72 result.append(')');
73 return QTest::toString(result);
74}
75
76QT_END_NAMESPACE
77
78#endif
char * toString(QNetworkReply::NetworkError code)
char * toString(const MyType &t)
[31]