summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorThiago Macieira <thiago.macieira@intel.com>2012-09-20 17:22:01 +0200
committerThe Qt Project <gerrit-noreply@qt-project.org>2012-10-02 22:34:42 +0200
commitf89fd779fc4431f667d937ea502fd930e6425079 (patch)
tree2668e07f1471c9c03b6e9f4348767003ed1cffaf /tests
parent4f52a9509995b1f5c834354ff6d02fa9b4f4396d (diff)
Overhaul a little the QUrl error reporting.
Keep the original QString that triggered the parsing error, instead of just one QChar. This provides more powerful error messages, like: Invalid IPv6 address; source was "http://[:::]"; scheme = "http", host = "" (QUrl cannot keep invalid hostnames) Invalid port or port number out of range; source was "http://example.com:abc"; scheme = "http", host = "example.com" (QUrl cannot keep a non-numeric port number) Invalid path (character '%' not permitted); source was "foo:/path%?"; scheme = "foo", path = "/path%25%1F" (the tolerant parser runs first, so the faulty component is fixed) This stores the error state in a special structure which is not allocated under normal conditions, keeping the memory consumption down. On 32-bit systems, QUrlPrivate does not increase in size; on 64-bit systems, it grows by 8 bytes. Change-Id: I93d798d43401dfeb9fca7b6eed7ea758da10136b Reviewed-by: David Faure <faure@kde.org>
Diffstat (limited to 'tests')
-rw-r--r--tests/auto/corelib/io/qurl/tst_qurl.cpp27
1 files changed, 16 insertions, 11 deletions
diff --git a/tests/auto/corelib/io/qurl/tst_qurl.cpp b/tests/auto/corelib/io/qurl/tst_qurl.cpp
index 25ff3155bc..361713bbc7 100644
--- a/tests/auto/corelib/io/qurl/tst_qurl.cpp
+++ b/tests/auto/corelib/io/qurl/tst_qurl.cpp
@@ -1894,32 +1894,32 @@ void tst_QUrl::strictParser_data()
QTest::newRow("invalid-scheme") << "ht%://example.com" << "character '%' not permitted";
QTest::newRow("empty-scheme") << ":/" << "':' before any '/'";
- QTest::newRow("invalid-user1") << "http://bad<user_name>@ok-hostname" << "Invalid user name";
- QTest::newRow("invalid-user2") << "http://bad%@ok-hostname" << "Invalid user name";
+ QTest::newRow("invalid-user1") << "http://bad<user_name>@ok-hostname" << "Invalid user name (character '<' not permitted)";
+ QTest::newRow("invalid-user2") << "http://bad%@ok-hostname" << "Invalid user name (character '%' not permitted)";
- QTest::newRow("invalid-password") << "http://user:pass\x7F@ok-hostname" << "Invalid password";
+ QTest::newRow("invalid-password") << "http://user:pass\x7F@ok-hostname" << "Invalid password (character '\x7F' not permitted)";
- QTest::newRow("invalid-regname") << "http://bad<hostname>" << "Invalid hostname";
- QTest::newRow("invalid-regname-2") << "http://b%61d" << "Invalid hostname";
+ QTest::newRow("invalid-regname") << "http://bad<hostname>" << "Invalid hostname (contains invalid characters)";
+ QTest::newRow("invalid-regname-2") << "http://b%61d" << "Invalid hostname (contains invalid characters)";
QTest::newRow("invalid-ipv6") << "http://[:::]" << "Invalid IPv6 address";
QTest::newRow("invalid-ipvfuture-1") << "http://[v7]" << "Invalid IPvFuture address";
QTest::newRow("invalid-ipvfuture-2") << "http://[v7.]" << "Invalid IPvFuture address";
QTest::newRow("invalid-ipvfuture-3") << "http://[v789]" << "Invalid IPvFuture address";
- QTest::newRow("unbalanced-brackets") << "http://[ff02::1" << "Expected ']'";
+ QTest::newRow("unbalanced-brackets") << "http://[ff02::1" << "Expected ']' to match '[' in hostname";
// port errors happen in TolerantMode too
- QTest::newRow("empty-port-1") << "http://example.com:" << "empty";
- QTest::newRow("empty-port-2") << "http://example.com:/" << "empty";
+ QTest::newRow("empty-port-1") << "http://example.com:" << "Port field was empty";
+ QTest::newRow("empty-port-2") << "http://example.com:/" << "Port field was empty";
QTest::newRow("invalid-port-1") << "http://example.com:-1" << "Invalid port";
QTest::newRow("invalid-port-2") << "http://example.com:abc" << "Invalid port";
QTest::newRow("invalid-port-3") << "http://example.com:9a" << "Invalid port";
QTest::newRow("port-range") << "http://example.com:65536" << "out of range";
- QTest::newRow("invalid-path") << "foo:/path%\x1F" << "Invalid path";
+ QTest::newRow("invalid-path") << "foo:/path%\x1F" << "Invalid path (character '%' not permitted)";
- QTest::newRow("invalid-query") << "foo:?\\#" << "Invalid query";
+ QTest::newRow("invalid-query") << "foo:?\\#" << "Invalid query (character '\\' not permitted)";
- QTest::newRow("invalid-fragment") << "#{}" << "Invalid fragment";
+ QTest::newRow("invalid-fragment") << "#{}" << "Invalid fragment (character '{' not permitted)";
}
void tst_QUrl::strictParser()
@@ -1931,6 +1931,11 @@ void tst_QUrl::strictParser()
QVERIFY(!url.isValid());
QVERIFY(url.toString().isEmpty());
QVERIFY(!url.errorString().isEmpty());
+ QVERIFY2(url.errorString().contains(input),
+ "Error string does not contain the original input (\"" +
+ input.toLatin1() + "\"): " + url.errorString().toLatin1());
+
+ // Note: if the following fails due to changes in the parser, simply update the test data
QVERIFY2(url.errorString().contains(needle),
"Error string changed and does not contain \"" +
needle.toLatin1() + "\" anymore: " + url.errorString().toLatin1());