Qt 6.x
The Qt SDK
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/qtest.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
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
48{
49 const QMetaObject *mo = &QNetworkReply::staticMetaObject;
50 int index = mo->indexOfEnumerator("NetworkError");
51 if (index == -1)
52 return qstrdup("");
53
54 QMetaEnum qme = mo->enumerator(index);
55 return qstrdup(qme.valueToKey(code));
56}
57
58inline char *toString(const QNetworkCookie &cookie)
59{
60 return toString(cookie.toRawForm());
61}
62
64{
65 QByteArray result = "QList(";
66 if (!list.isEmpty()) {
67 for (const QNetworkCookie &cookie : list)
68 result += "QNetworkCookie(" + cookie.toRawForm() + "), ";
69 result.chop(2); // remove trailing ", "
70 }
71 result.append(')');
72 return toString(result);
73}
74
75} // namespace QTest
76
78
79#endif
static constexpr auto IPv4Protocol
static constexpr auto UnknownNetworkLayerProtocol
static constexpr auto AnyIPProtocol
static constexpr auto IPv6Protocol
\inmodule QtCore
Definition qbytearray.h:57
void chop(qsizetype n)
Removes n bytes from the end of the byte array.
The QHostAddress class provides an IP address.
Definition qlist.h:74
bool isEmpty() const noexcept
Definition qlist.h:390
\inmodule QtCore
const char * valueToKey(int value) const
Returns the string that is used as the name of the given enumeration value, or \nullptr if value is n...
The QNetworkCookie class holds one network cookie.
QByteArray toRawForm(RawForm form=Full) const
Returns the raw form of this QNetworkCookie.
NetworkError
Indicates all possible error conditions found during the processing of the request.
auto mo
[7]
Combined button and popup list for selecting options.
char * toString(const MyPoint &point)
char * toString< QHostAddress >(const QHostAddress &addr)
Q_CORE_EXPORT char * qstrdup(const char *)
GLuint index
[2]
GLenum const void * addr
GLuint64EXT * result
[6]
QList< int > list
[14]
\inmodule QtCore