summaryrefslogtreecommitdiffstats
path: root/tests/auto
diff options
context:
space:
mode:
authorEdward Welbourne <edward.welbourne@qt.io>2016-07-04 15:58:39 +0200
committerEdward Welbourne <edward.welbourne@qt.io>2016-07-04 15:58:39 +0200
commitb5695bd5be908970244919bcd7c19cbf7ccca2c4 (patch)
tree29f1e2895bef25db5b47e7e2cf01414f6b32ac8d /tests/auto
parent840729a931a7d3fefbc4b4a8e01f8b1bd69a427e (diff)
parentb7744e0b05255fc468db2af215ba94eca4b7757b (diff)
Merge remote-tracking branch 'origin/5.6' into 5.7
Diffstat (limited to 'tests/auto')
-rw-r--r--tests/auto/corelib/io/qdatastream/tst_qdatastream.cpp27
-rw-r--r--tests/auto/corelib/io/qurl/tst_qurl.cpp162
-rw-r--r--tests/auto/network/access/qnetworkreply/tst_qnetworkreply.cpp6
3 files changed, 126 insertions, 69 deletions
diff --git a/tests/auto/corelib/io/qdatastream/tst_qdatastream.cpp b/tests/auto/corelib/io/qdatastream/tst_qdatastream.cpp
index fefe08db30..b7e7344b16 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()
{
@@ -3132,6 +3133,30 @@ void tst_QDataStream::compatibility_Qt3()
QCOMPARE(in_palette.brush(QPalette::Button).style(), Qt::NoBrush);
QCOMPARE(in_palette.color(QPalette::Light), QColor(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()
diff --git a/tests/auto/corelib/io/qurl/tst_qurl.cpp b/tests/auto/corelib/io/qurl/tst_qurl.cpp
index 73672f3572..e982660bef 100644
--- a/tests/auto/corelib/io/qurl/tst_qurl.cpp
+++ b/tests/auto/corelib/io/qurl/tst_qurl.cpp
@@ -120,7 +120,8 @@ private slots:
void isValid();
void schemeValidator_data();
void schemeValidator();
- void invalidSchemeValidator();
+ void setScheme_data();
+ void setScheme();
void strictParser_data();
void strictParser();
void tolerantParser();
@@ -2077,87 +2078,114 @@ void tst_QUrl::isValid()
void tst_QUrl::schemeValidator_data()
{
- QTest::addColumn<QByteArray>("encodedUrl");
+ QTest::addColumn<QString>("input");
QTest::addColumn<bool>("result");
- QTest::addColumn<QString>("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<QString>("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<QString>("input");
diff --git a/tests/auto/network/access/qnetworkreply/tst_qnetworkreply.cpp b/tests/auto/network/access/qnetworkreply/tst_qnetworkreply.cpp
index 21a84dfbb2..93bdbdd6a5 100644
--- a/tests/auto/network/access/qnetworkreply/tst_qnetworkreply.cpp
+++ b/tests/auto/network/access/qnetworkreply/tst_qnetworkreply.cpp
@@ -7310,7 +7310,11 @@ void tst_QNetworkReply::qtbug45581WrongReplyStatusCode()
const QByteArray expectedContent =
"<root attr=\"value\" attr2=\"value2\">"
- "<person /><fruit /></root>\n";
+ "<person /><fruit /></root>"
+#ifdef Q_OS_WIN
+ "\r"
+#endif
+ "\n";
QCOMPARE(reply->readAll(), expectedContent);