From 2714d94ff4652e863f2e6005a138a2563d836f07 Mon Sep 17 00:00:00 2001 From: Friedemann Kleint Date: Wed, 8 Jun 2016 16:19:04 +0200 Subject: Fix tst_QNetworkReply::qtbug45581WrongReplyStatusCode() on Windows The file is read using CRLF line convention on Windows. Task-number: QTBUG-24226 Change-Id: Ie08fa603e29c80a42de4bfbfd1f4237f53c22b98 Reviewed-by: Timur Pocheptsov --- tests/auto/network/access/qnetworkreply/tst_qnetworkreply.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'tests') diff --git a/tests/auto/network/access/qnetworkreply/tst_qnetworkreply.cpp b/tests/auto/network/access/qnetworkreply/tst_qnetworkreply.cpp index 02aca3d6c1..0f2d0873a7 100644 --- a/tests/auto/network/access/qnetworkreply/tst_qnetworkreply.cpp +++ b/tests/auto/network/access/qnetworkreply/tst_qnetworkreply.cpp @@ -7295,7 +7295,11 @@ void tst_QNetworkReply::qtbug45581WrongReplyStatusCode() const QByteArray expectedContent = "" - "\n"; + "" +#ifdef Q_OS_WIN + "\r" +#endif + "\n"; QCOMPARE(reply->readAll(), expectedContent); -- cgit v1.2.3 From 1af4916e11c1251b2957a909f819678e9fd32feb Mon Sep 17 00:00:00 2001 From: David Faure Date: Fri, 1 Jul 2016 13:49:46 +0200 Subject: QTime: restore Qt3 compatibility in the QDataStream operators A Qt5 program writing a null QTime() using setVersion(QDataStream::Qt_3_3), and then a Qt3 program reading that, would lead to a weird QTime, with isNull=false, isValid=false, hour=1193, minute=2, second=47, ms=295. This commit restores interoperability, by writing out the expected value (0) for a null QTime rather than the -1 value used by Qt4 and Qt5. Change-Id: Icde468a8f6fc9434ef7018296725819b44d672af Reviewed-by: Thiago Macieira --- .../corelib/io/qdatastream/tst_qdatastream.cpp | 27 +++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) (limited to 'tests') diff --git a/tests/auto/corelib/io/qdatastream/tst_qdatastream.cpp b/tests/auto/corelib/io/qdatastream/tst_qdatastream.cpp index 86fd142036..76650ea9a4 100644 --- a/tests/auto/corelib/io/qdatastream/tst_qdatastream.cpp +++ b/tests/auto/corelib/io/qdatastream/tst_qdatastream.cpp @@ -1203,10 +1203,11 @@ static QTime qTimeData(int index) case 57: return QTime(23, 59, 59, 99); case 58: return QTime(23, 59, 59, 100); case 59: return QTime(23, 59, 59, 999); + case 60: return QTime(); } return QTime(0, 0, 0); } -#define MAX_QTIME_DATA 60 +#define MAX_QTIME_DATA 61 void tst_QDataStream::stream_QTime_data() { @@ -3081,6 +3082,30 @@ void tst_QDataStream::compatibility_Qt3() QVERIFY(in_palette.brush(QPalette::Button).style() == Qt::NoBrush); QVERIFY(in_palette.color(QPalette::Light) == Qt::green); } + // QTime() was serialized to (0, 0, 0, 0) in Qt3, not (0xFF, 0xFF, 0xFF, 0xFF) + // This is because in Qt3 a null time was valid, and there was no support for deserializing a value of -1. + { + QByteArray stream; + { + QDataStream out(&stream, QIODevice::WriteOnly); + out.setVersion(QDataStream::Qt_3_3); + out << QTime(); + } + QTime in_time; + { + QDataStream in(stream); + in.setVersion(QDataStream::Qt_3_3); + in >> in_time; + } + QVERIFY(in_time.isNull()); + + quint32 rawValue; + QDataStream in(stream); + in.setVersion(QDataStream::Qt_3_3); + in >> rawValue; + QCOMPARE(rawValue, quint32(0)); + } + } void tst_QDataStream::compatibility_Qt2() -- cgit v1.2.3 From 4f3eb6617331ba2634206064512ae68a4fbd793e Mon Sep 17 00:00:00 2001 From: Thiago Macieira Date: Thu, 30 Jun 2016 15:48:52 -0700 Subject: QUrl: Test that we do correctly accept valid schemes ... and reject invalid ones. There was one error: we accepted schemes starting with pluses, dashes and dots. Change-Id: Ie585843cfb684bc3b6e3fffd145cfe12227ec4ad Reviewed-by: David Faure --- tests/auto/corelib/io/qurl/tst_qurl.cpp | 162 +++++++++++++++++++------------- 1 file changed, 95 insertions(+), 67 deletions(-) (limited to 'tests') diff --git a/tests/auto/corelib/io/qurl/tst_qurl.cpp b/tests/auto/corelib/io/qurl/tst_qurl.cpp index ef210d4a64..eb29646053 100644 --- a/tests/auto/corelib/io/qurl/tst_qurl.cpp +++ b/tests/auto/corelib/io/qurl/tst_qurl.cpp @@ -125,7 +125,8 @@ private slots: void isValid(); void schemeValidator_data(); void schemeValidator(); - void invalidSchemeValidator(); + void setScheme_data(); + void setScheme(); void strictParser_data(); void strictParser(); void tolerantParser(); @@ -2082,87 +2083,114 @@ void tst_QUrl::isValid() void tst_QUrl::schemeValidator_data() { - QTest::addColumn("encodedUrl"); + QTest::addColumn("input"); QTest::addColumn("result"); - QTest::addColumn("toString"); - - QTest::newRow("empty") << QByteArray() << false << QString(); - - // ftp - QTest::newRow("ftp:") << QByteArray("ftp:") << true << QString("ftp:"); - QTest::newRow("ftp://ftp.qt-project.org") - << QByteArray("ftp://ftp.qt-project.org") - << true << QString("ftp://ftp.qt-project.org"); - QTest::newRow("ftp://ftp.qt-project.org/") - << QByteArray("ftp://ftp.qt-project.org/") - << true << QString("ftp://ftp.qt-project.org/"); - QTest::newRow("ftp:/index.html") - << QByteArray("ftp:/index.html") - << false << QString(); - - // mailto - QTest::newRow("mailto:") << QByteArray("mailto:") << true << QString("mailto:"); - QTest::newRow("mailto://smtp.trolltech.com/ole@bull.name") - << QByteArray("mailto://smtp.trolltech.com/ole@bull.name") << false << QString(); - QTest::newRow("mailto:") << QByteArray("mailto:") << true << QString("mailto:"); - QTest::newRow("mailto:ole@bull.name") - << QByteArray("mailto:ole@bull.name") << true << QString("mailto:ole@bull.name"); + QTest::addColumn("scheme"); - // file - QTest::newRow("file:") << QByteArray("file:/etc/passwd") << true << QString("file:///etc/passwd"); + // scheme = ALPHA *( ALPHA / DIGIT / "+" / "-" / "." ) + + QTest::newRow("empty") << QString() << false << QString(); + + // uncontroversial ones + QTest::newRow("ftp") << "ftp://ftp.example.com/" << true << "ftp"; + QTest::newRow("http") << "http://www.example.com/" << true << "http"; + QTest::newRow("mailto") << "mailto:smith@example.com" << true << "mailto"; + QTest::newRow("file-1slash") << "file:/etc/passwd" << true << "file"; + QTest::newRow("file-2slashes") << "file://server/etc/passwd" << true << "file"; + QTest::newRow("file-3slashes") << "file:///etc/passwd" << true << "file"; + + QTest::newRow("mailto+subject") << "mailto:smith@example.com?subject=Hello%20World" << true << "mailto"; + QTest::newRow("mailto+host") << "mailto://smtp.example.com/smith@example.com" << true << "mailto"; + + // valid, but unexpected + QTest::newRow("ftp-nohost") << "ftp:/etc/passwd" << true << "ftp"; + QTest::newRow("http-nohost") << "http:/etc/passwd" << true << "http"; + QTest::newRow("mailto-nomail") << "mailto://smtp.example.com" << true << "mailto"; + + // schemes with numbers + QTest::newRow("digits") << "proto2://" << true << "proto2"; + + // schemes with dots, dashes, and pluses + QTest::newRow("svn+ssh") << "svn+ssh://svn.example.com" << true << "svn+ssh"; + QTest::newRow("withdash") << "svn-ssh://svn.example.com" << true << "svn-ssh"; + QTest::newRow("withdots") << "org.qt-project://qt-project.org" << true << "org.qt-project"; + + // lowercasing + QTest::newRow("FTP") << "FTP://ftp.example.com/" << true << "ftp"; + QTest::newRow("HTTP") << "HTTP://www.example.com/" << true << "http"; + QTest::newRow("MAILTO") << "MAILTO:smith@example.com" << true << "mailto"; + QTest::newRow("FILE") << "FILE:/etc/passwd" << true << "file"; + QTest::newRow("SVN+SSH") << "SVN+SSH://svn.example.com" << true << "svn+ssh"; + QTest::newRow("WITHDASH") << "SVN-SSH://svn.example.com" << true << "svn-ssh"; + QTest::newRow("WITHDOTS") << "ORG.QT-PROJECT://qt-project.org" << true << "org.qt-project"; + + // invalid entries + QTest::newRow("start-digit") << "1http://example.com" << false << "1http"; + QTest::newRow("start-plus") << "+ssh://user@example.com" << false << "+ssh"; + QTest::newRow("start-dot") << ".org.example:///" << false << ".org.example"; + QTest::newRow("with-space") << "a b://" << false << "a b"; + QTest::newRow("with-non-ascii") << "\304\245\305\243\305\245\321\200://example.com" << false << "\304\245\305\243\305\245\321\200"; + QTest::newRow("with-control1") << "http\1://example.com" << false << "http\1"; + QTest::newRow("with-control127") << "http\177://example.com" << false << "http\177"; + QTest::newRow("with-null") << QString::fromLatin1("http\0://example.com", 19) << false << QString::fromLatin1("http\0", 5); + + QTest::newRow("percent-encoded") << "%68%74%%74%70://example.com" << false << "%68%74%%74%70"; + + static const char controls[] = "!\"$&'()*,;<=>[\\]^_`{|}~"; + for (size_t i = 0; i < sizeof(controls) - 1; ++i) + QTest::newRow(("with-" + QByteArray(1, controls[i])).constData()) + << QString("pre%1post://example.com/").arg(QLatin1Char(controls[i])) + << false << QString("pre%1post").arg(QLatin1Char(controls[i])); } void tst_QUrl::schemeValidator() { - QFETCH(QByteArray, encodedUrl); + QFETCH(QString, input); QFETCH(bool, result); - QFETCH(QString, toString); - QUrl url = QUrl::fromEncoded(encodedUrl); - QEXPECT_FAIL("ftp:/index.html", "high-level URL validation not reimplemented yet", Abort); - QEXPECT_FAIL("mailto://smtp.trolltech.com/ole@bull.name", "high-level URL validation not reimplemented yet", Abort); + QUrl url(input); QCOMPARE(url.isValid(), result); - if (!result) - QVERIFY(url.toString().isEmpty()); -} + if (result) { + QFETCH(QString, scheme); + QCOMPARE(url.scheme(), scheme); -void tst_QUrl::invalidSchemeValidator() -{ - // test that if scheme does not start with an ALPHA, QUrl::isValid() returns false - { - QUrl url("1http://qt-project.org"); - QVERIFY(url.scheme().isEmpty()); - QVERIFY(url.path().startsWith("1http")); - } - { - QUrl url("http://qt-project.org"); - url.setScheme("111http://qt-project.org"); - QCOMPARE(url.isValid(), false); - QVERIFY(url.toString().isEmpty()); - } - // non-ALPHA character at other positions in the scheme are ok - { - QUrl url("ht111tp://qt-project.org", QUrl::StrictMode); + // reconstruct with just the scheme: + url.setUrl(scheme + ':'); QVERIFY(url.isValid()); - QCOMPARE(url.scheme(), QString("ht111tp")); - QVERIFY(!url.toString().isEmpty()); - } - { - QUrl url("http://qt-project.org"); - url.setScheme("ht123tp://qt-project.org"); - QVERIFY(!url.isValid()); + QCOMPARE(url.scheme(), scheme); + } else { QVERIFY(url.toString().isEmpty()); - url.setScheme("http"); - QVERIFY(url.isValid()); - QVERIFY(!url.toString().isEmpty()); - } - { - QUrl url = QUrl::fromEncoded("ht321tp://qt-project.org", QUrl::StrictMode); - QVERIFY(url.isValid()); - QVERIFY(!url.toString().isEmpty()); } } +void tst_QUrl::setScheme_data() +{ + schemeValidator_data(); + + // a couple more which wouldn't work in parsing a full URL + QTest::newRow("with-slash") << QString() << false << "http/"; + QTest::newRow("with-question") << QString() << false << "http?"; + QTest::newRow("with-hash") << QString() << false << "http#"; +} + +void tst_QUrl::setScheme() +{ + QFETCH(QString, scheme); + QFETCH(bool, result); + QString expectedScheme; + if (result) + expectedScheme = scheme; + + QUrl url; + url.setScheme(scheme); + QCOMPARE(url.isValid(), result); + QCOMPARE(url.scheme(), expectedScheme); + + url.setScheme(scheme.toUpper()); + QCOMPARE(url.isValid(), result); + QCOMPARE(url.scheme(), expectedScheme); +} + void tst_QUrl::strictParser_data() { QTest::addColumn("input"); -- cgit v1.2.3