tests/auto/qhttpnetworkreply/tst_qhttpnetworkreply.cpp
changeset 0 1918ee327afb
child 4 3b1da2848fc7
equal deleted inserted replaced
-1:000000000000 0:1918ee327afb
       
     1 /****************************************************************************
       
     2 **
       
     3 ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
       
     4 ** All rights reserved.
       
     5 ** Contact: Nokia Corporation (qt-info@nokia.com)
       
     6 **
       
     7 ** This file is part of the test suite of the Qt Toolkit.
       
     8 **
       
     9 ** $QT_BEGIN_LICENSE:LGPL$
       
    10 ** No Commercial Usage
       
    11 ** This file contains pre-release code and may not be distributed.
       
    12 ** You may use this file in accordance with the terms and conditions
       
    13 ** contained in the Technology Preview License Agreement accompanying
       
    14 ** this package.
       
    15 **
       
    16 ** GNU Lesser General Public License Usage
       
    17 ** Alternatively, this file may be used under the terms of the GNU Lesser
       
    18 ** General Public License version 2.1 as published by the Free Software
       
    19 ** Foundation and appearing in the file LICENSE.LGPL included in the
       
    20 ** packaging of this file.  Please review the following information to
       
    21 ** ensure the GNU Lesser General Public License version 2.1 requirements
       
    22 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
       
    23 **
       
    24 ** In addition, as a special exception, Nokia gives you certain additional
       
    25 ** rights.  These rights are described in the Nokia Qt LGPL Exception
       
    26 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
       
    27 **
       
    28 ** If you have questions regarding the use of this file, please contact
       
    29 ** Nokia at qt-info@nokia.com.
       
    30 **
       
    31 **
       
    32 **
       
    33 **
       
    34 **
       
    35 **
       
    36 **
       
    37 **
       
    38 ** $QT_END_LICENSE$
       
    39 **
       
    40 ****************************************************************************/
       
    41 
       
    42 
       
    43 #include <QtTest/QtTest>
       
    44 #include "private/qhttpnetworkconnection_p.h"
       
    45 
       
    46 class tst_QHttpNetworkReply: public QObject
       
    47 {
       
    48     Q_OBJECT
       
    49 private Q_SLOTS:
       
    50     void init();
       
    51     void cleanup();
       
    52     void initTestCase();
       
    53     void cleanupTestCase();
       
    54 
       
    55     void parseHeader_data();
       
    56     void parseHeader();
       
    57 };
       
    58 
       
    59 
       
    60 void tst_QHttpNetworkReply::initTestCase()
       
    61 {
       
    62 }
       
    63 
       
    64 void tst_QHttpNetworkReply::cleanupTestCase()
       
    65 {
       
    66 }
       
    67 
       
    68 void tst_QHttpNetworkReply::init()
       
    69 {
       
    70 }
       
    71 
       
    72 void tst_QHttpNetworkReply::cleanup()
       
    73 {
       
    74 }
       
    75 
       
    76 void tst_QHttpNetworkReply::parseHeader_data()
       
    77 {
       
    78     QTest::addColumn<QByteArray>("headers");
       
    79     QTest::addColumn<QStringList>("fields");
       
    80     QTest::addColumn<QStringList>("values");
       
    81 
       
    82     QTest::newRow("empty-field") << QByteArray("Set-Cookie: \r\n")
       
    83                                  << (QStringList() << "Set-Cookie")
       
    84                                  << (QStringList() << "");
       
    85     QTest::newRow("single-field") << QByteArray("Content-Type: text/html; charset=utf-8\r\n")
       
    86                                   << (QStringList() << "Content-Type")
       
    87                                   << (QStringList() << "text/html; charset=utf-8");
       
    88     QTest::newRow("single-field-continued") << QByteArray("Content-Type: text/html;\r\n"
       
    89                                                           " charset=utf-8\r\n")
       
    90                                             << (QStringList() << "Content-Type")
       
    91                                             << (QStringList() << "text/html; charset=utf-8");
       
    92 
       
    93     QTest::newRow("multi-field") << QByteArray("Content-Type: text/html; charset=utf-8\r\n"
       
    94                                                "Content-Length: 1024\r\n"
       
    95                                                "Content-Encoding: gzip\r\n")
       
    96                                  << (QStringList() << "Content-Type" << "Content-Length" << "Content-Encoding")
       
    97                                  << (QStringList() << "text/html; charset=utf-8" << "1024" << "gzip");
       
    98     QTest::newRow("multi-field-with-emtpy") << QByteArray("Content-Type: text/html; charset=utf-8\r\n"
       
    99                                                           "Content-Length: 1024\r\n"
       
   100                                                           "Set-Cookie: \r\n"
       
   101                                                           "Content-Encoding: gzip\r\n")
       
   102                                             << (QStringList() << "Content-Type" << "Content-Length" << "Set-Cookie" << "Content-Encoding")
       
   103                                             << (QStringList() << "text/html; charset=utf-8" << "1024" << "" << "gzip");
       
   104 
       
   105     QTest::newRow("lws-field") << QByteArray("Content-Type: text/html; charset=utf-8\r\n"
       
   106                                              "Content-Length:\r\n 1024\r\n"
       
   107                                              "Content-Encoding: gzip\r\n")
       
   108                                << (QStringList() << "Content-Type" << "Content-Length" << "Content-Encoding")
       
   109                                << (QStringList() << "text/html; charset=utf-8" << "1024" << "gzip");
       
   110 
       
   111     QTest::newRow("duplicated-field") << QByteArray("Vary: Accept-Language\r\n"
       
   112                                                     "Vary: Cookie\r\n"
       
   113                                                     "Vary: User-Agent\r\n")
       
   114                                       << (QStringList() << "Vary")
       
   115                                       << (QStringList() << "Accept-Language, Cookie, User-Agent");
       
   116 }
       
   117 
       
   118 void tst_QHttpNetworkReply::parseHeader()
       
   119 {
       
   120     QFETCH(QByteArray, headers);
       
   121     QFETCH(QStringList, fields);
       
   122     QFETCH(QStringList, values);
       
   123 
       
   124     QHttpNetworkReply reply;
       
   125     reply.parseHeader(headers);
       
   126     for (int i = 0; i < fields.count(); ++i) {
       
   127         //qDebug() << "field" << fields.at(i) << "value" << reply.headerField(fields.at(i)) << "expected" << values.at(i);
       
   128         QString field = reply.headerField(fields.at(i).toLatin1());
       
   129         QCOMPARE(field, values.at(i));
       
   130     }
       
   131 }
       
   132 
       
   133 QTEST_MAIN(tst_QHttpNetworkReply)
       
   134 #include "tst_qhttpnetworkreply.moc"