diff options
author | Thiago Macieira <thiago.macieira@intel.com> | 2012-03-28 19:31:45 -0300 |
---|---|---|
committer | Qt by Nokia <qt-info@nokia.com> | 2012-03-30 01:19:59 +0200 |
commit | 66df11f4d109ca3d97fed8985d6bbc6dcf90733d (patch) | |
tree | 0c514e0c7b03beea92403baaa380c6158cead84f /tests | |
parent | 64a10879cb1f3a48b4b44c2e3a46694efb3bec0a (diff) |
Fix QUrl operator== and operator<
Don't crash when either side is null but not both sides.
Also make sure operator< is working properly and satisfies the basic
conditions of a type (such as that if A < B, then !(B < A)).
Change-Id: Idd9e9fc593e1a7781d9f4f2b13a1024b643926fd
Reviewed-by: Giuseppe D'Angelo <dangelog@gmail.com>
Reviewed-by: Lars Knoll <lars.knoll@nokia.com>
Diffstat (limited to 'tests')
-rw-r--r-- | tests/auto/corelib/io/qurl/tst_qurl.cpp | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/tests/auto/corelib/io/qurl/tst_qurl.cpp b/tests/auto/corelib/io/qurl/tst_qurl.cpp index 5c9e20b9b4..f0081df765 100644 --- a/tests/auto/corelib/io/qurl/tst_qurl.cpp +++ b/tests/auto/corelib/io/qurl/tst_qurl.cpp @@ -66,6 +66,8 @@ private slots: void unc(); void assignment(); void comparison(); + void comparison2_data(); + void comparison2(); void copying(); void setUrl(); void i18n_data(); @@ -286,6 +288,55 @@ void tst_QUrl::comparison() QVERIFY(url5 == url6); } +void tst_QUrl::comparison2_data() +{ + QTest::addColumn<QUrl>("url1"); + QTest::addColumn<QUrl>("url2"); + QTest::addColumn<int>("ordering"); // like strcmp + + QTest::newRow("null-null") << QUrl() << QUrl() << 0; + + QUrl empty; + empty.setPath("/hello"); // ensure it has detached + empty.setPath(QString()); + QTest::newRow("null-empty") << QUrl() << empty << 0; + + QTest::newRow("scheme-null") << QUrl("x:") << QUrl() << 1; + QTest::newRow("samescheme") << QUrl("x:") << QUrl("x:") << 0; + + // the following three are by choice + // the order could be the opposite and it would still be correct + QTest::newRow("scheme-path") << QUrl("x:") << QUrl("/tmp") << +1; + QTest::newRow("fragment-path") << QUrl("#foo") << QUrl("/tmp") << -1; + QTest::newRow("fragment-scheme") << QUrl("#foo") << QUrl("x:") << -1; + + QTest::newRow("noport-zeroport") << QUrl("http://example.com") << QUrl("http://example.com:0") << -1; +} + +void tst_QUrl::comparison2() +{ + QFETCH(QUrl, url1); + QFETCH(QUrl, url2); + QFETCH(int, ordering); + + QCOMPARE(url1.toString() == url2.toString(), ordering == 0); + QCOMPARE(url1 == url2, ordering == 0); + QCOMPARE(url1 != url2, ordering != 0); + if (ordering == 0) + QCOMPARE(qHash(url1), qHash(url2)); + + QCOMPARE(url1 < url2, ordering < 0); + QCOMPARE(!(url1 < url2), ordering >= 0); + + QCOMPARE(url2 < url1, ordering > 0); + QCOMPARE(!(url2 < url1), ordering <= 0); + + // redundant checks (the above should catch these) + QCOMPARE(url1 < url2 || url2 < url1, ordering != 0); + QVERIFY(!(url1 < url2 && url2 < url1)); + QVERIFY(url1 < url2 || url1 == url2 || url2 < url1); +} + void tst_QUrl::copying() { QUrl url("http://qt.nokia.com/"); |