Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-12-16 10:27:32

0001 // Copyright (C) 2016 The Qt Company Ltd.
0002 // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
0003 
0004 #ifndef QTEST_NETWORK_H
0005 #define QTEST_NETWORK_H
0006 
0007 #include <QtTest/qtesttostring.h>
0008 
0009 // enable NETWORK features
0010 #ifndef QT_NETWORK_LIB
0011 #define QT_NETWORK_LIB
0012 #endif
0013 
0014 #if 0
0015 #pragma qt_class(QtTestNetwork)
0016 #endif
0017 
0018 #include <QtNetwork/QHostAddress>
0019 #include <QtNetwork/QNetworkCookie>
0020 #include <QtNetwork/QNetworkReply>
0021 
0022 #if 0
0023 // inform syncqt
0024 #pragma qt_no_master_include
0025 #endif
0026 
0027 QT_BEGIN_NAMESPACE
0028 
0029 namespace QTest
0030 {
0031 template<>
0032 inline char *toString<QHostAddress>(const QHostAddress &addr)
0033 {
0034     switch (addr.protocol()) {
0035     case QAbstractSocket::UnknownNetworkLayerProtocol:
0036         return qstrdup("<unknown address (parse error)>");
0037     case QAbstractSocket::AnyIPProtocol:
0038         return qstrdup("QHostAddress::Any");
0039     case QAbstractSocket::IPv4Protocol:
0040     case QAbstractSocket::IPv6Protocol:
0041         break;
0042     }
0043 
0044     return toString(addr.toString());
0045 }
0046 } // namespace QTest
0047 
0048 inline char *toString(QNetworkReply::NetworkError code)
0049 {
0050     const QMetaObject *mo = &QNetworkReply::staticMetaObject;
0051     int index = mo->indexOfEnumerator("NetworkError");
0052     if (index == -1)
0053         return qstrdup("");
0054 
0055     QMetaEnum qme = mo->enumerator(index);
0056     return qstrdup(qme.valueToKey(code));
0057 }
0058 
0059 inline char *toString(const QNetworkCookie &cookie)
0060 {
0061     return QTest::toString(cookie.toRawForm());
0062 }
0063 
0064 inline char *toString(const QList<QNetworkCookie> &list)
0065 {
0066     QByteArray result = "QList(";
0067     if (!list.isEmpty()) {
0068         for (const QNetworkCookie &cookie : list)
0069             result += "QNetworkCookie(" + cookie.toRawForm() + "), ";
0070         result.chop(2); // remove trailing ", "
0071     }
0072     result.append(')');
0073     return QTest::toString(result);
0074 }
0075 
0076 QT_END_NAMESPACE
0077 
0078 #endif