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