/tests/auto/qhttpnetworkreply/tst_qhttpnetworkreply.cpp

https://bitbucket.org/ultra_iter/qt-vtl · C++ · 134 lines · 76 code · 17 blank · 41 comment · 1 complexity · 4d0d0c5561ffea81ec42dda383b61c62 MD5 · raw file

  1. /****************************************************************************
  2. **
  3. ** Copyright (C) 2012 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. ** GNU Lesser General Public License Usage
  11. ** This file may be used under the terms of the GNU Lesser General Public
  12. ** License version 2.1 as published by the Free Software Foundation and
  13. ** appearing in the file LICENSE.LGPL included in the packaging of this
  14. ** file. Please review the following information to ensure the GNU Lesser
  15. ** General Public License version 2.1 requirements will be met:
  16. ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
  17. **
  18. ** In addition, as a special exception, Nokia gives you certain additional
  19. ** rights. These rights are described in the Nokia Qt LGPL Exception
  20. ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
  21. **
  22. ** GNU General Public License Usage
  23. ** Alternatively, this file may be used under the terms of the GNU General
  24. ** Public License version 3.0 as published by the Free Software Foundation
  25. ** and appearing in the file LICENSE.GPL included in the packaging of this
  26. ** file. Please review the following information to ensure the GNU General
  27. ** Public License version 3.0 requirements will be met:
  28. ** http://www.gnu.org/copyleft/gpl.html.
  29. **
  30. ** Other Usage
  31. ** Alternatively, this file may be used in accordance with the terms and
  32. ** conditions contained in a signed written agreement between you and Nokia.
  33. **
  34. **
  35. **
  36. **
  37. **
  38. ** $QT_END_LICENSE$
  39. **
  40. ****************************************************************************/
  41. #include <QtTest/QtTest>
  42. #include "private/qhttpnetworkconnection_p.h"
  43. class tst_QHttpNetworkReply: public QObject
  44. {
  45. Q_OBJECT
  46. private Q_SLOTS:
  47. void init();
  48. void cleanup();
  49. void initTestCase();
  50. void cleanupTestCase();
  51. void parseHeader_data();
  52. void parseHeader();
  53. };
  54. void tst_QHttpNetworkReply::initTestCase()
  55. {
  56. }
  57. void tst_QHttpNetworkReply::cleanupTestCase()
  58. {
  59. }
  60. void tst_QHttpNetworkReply::init()
  61. {
  62. }
  63. void tst_QHttpNetworkReply::cleanup()
  64. {
  65. }
  66. void tst_QHttpNetworkReply::parseHeader_data()
  67. {
  68. QTest::addColumn<QByteArray>("headers");
  69. QTest::addColumn<QStringList>("fields");
  70. QTest::addColumn<QStringList>("values");
  71. QTest::newRow("empty-field") << QByteArray("Set-Cookie: \r\n")
  72. << (QStringList() << "Set-Cookie")
  73. << (QStringList() << "");
  74. QTest::newRow("single-field") << QByteArray("Content-Type: text/html; charset=utf-8\r\n")
  75. << (QStringList() << "Content-Type")
  76. << (QStringList() << "text/html; charset=utf-8");
  77. QTest::newRow("single-field-continued") << QByteArray("Content-Type: text/html;\r\n"
  78. " charset=utf-8\r\n")
  79. << (QStringList() << "Content-Type")
  80. << (QStringList() << "text/html; charset=utf-8");
  81. QTest::newRow("multi-field") << QByteArray("Content-Type: text/html; charset=utf-8\r\n"
  82. "Content-Length: 1024\r\n"
  83. "Content-Encoding: gzip\r\n")
  84. << (QStringList() << "Content-Type" << "Content-Length" << "Content-Encoding")
  85. << (QStringList() << "text/html; charset=utf-8" << "1024" << "gzip");
  86. QTest::newRow("multi-field-with-emtpy") << QByteArray("Content-Type: text/html; charset=utf-8\r\n"
  87. "Content-Length: 1024\r\n"
  88. "Set-Cookie: \r\n"
  89. "Content-Encoding: gzip\r\n")
  90. << (QStringList() << "Content-Type" << "Content-Length" << "Set-Cookie" << "Content-Encoding")
  91. << (QStringList() << "text/html; charset=utf-8" << "1024" << "" << "gzip");
  92. QTest::newRow("lws-field") << QByteArray("Content-Type: text/html; charset=utf-8\r\n"
  93. "Content-Length:\r\n 1024\r\n"
  94. "Content-Encoding: gzip\r\n")
  95. << (QStringList() << "Content-Type" << "Content-Length" << "Content-Encoding")
  96. << (QStringList() << "text/html; charset=utf-8" << "1024" << "gzip");
  97. QTest::newRow("duplicated-field") << QByteArray("Vary: Accept-Language\r\n"
  98. "Vary: Cookie\r\n"
  99. "Vary: User-Agent\r\n")
  100. << (QStringList() << "Vary")
  101. << (QStringList() << "Accept-Language, Cookie, User-Agent");
  102. }
  103. void tst_QHttpNetworkReply::parseHeader()
  104. {
  105. QFETCH(QByteArray, headers);
  106. QFETCH(QStringList, fields);
  107. QFETCH(QStringList, values);
  108. QHttpNetworkReply reply;
  109. reply.parseHeader(headers);
  110. for (int i = 0; i < fields.count(); ++i) {
  111. //qDebug() << "field" << fields.at(i) << "value" << reply.headerField(fields.at(i)) << "expected" << values.at(i);
  112. QString field = reply.headerField(fields.at(i).toLatin1());
  113. QCOMPARE(field, values.at(i));
  114. }
  115. }
  116. QTEST_MAIN(tst_QHttpNetworkReply)
  117. #include "tst_qhttpnetworkreply.moc"