3677 QCOMPARE(url2, url); |
3677 QCOMPARE(url2, url); |
3678 } |
3678 } |
3679 |
3679 |
3680 void tst_QUrl::fromUserInput_data() |
3680 void tst_QUrl::fromUserInput_data() |
3681 { |
3681 { |
|
3682 // |
|
3683 // most of this test is: |
|
3684 // Copyright (C) Research In Motion Limited 2009. All rights reserved. |
|
3685 // Distributed under the BSD license. |
|
3686 // See qurl.cpp |
|
3687 // |
|
3688 |
3682 QTest::addColumn<QString>("string"); |
3689 QTest::addColumn<QString>("string"); |
3683 QTest::addColumn<QUrl>("url"); |
3690 QTest::addColumn<QUrl>("guessUrlFromString"); |
3684 |
3691 |
3685 // Null |
3692 // Null |
3686 QTest::newRow("null") << QString() << QUrl(); |
3693 QTest::newRow("null") << QString() << QUrl(); |
3687 |
3694 |
3688 // File |
3695 // File |
3689 QDirIterator it(QDir::homePath()); |
3696 QDirIterator it(QDir::homePath()); |
3690 QString fileString; |
|
3691 int c = 0; |
3697 int c = 0; |
3692 while (it.hasNext()) { |
3698 while (it.hasNext()) { |
3693 it.next(); |
3699 it.next(); |
3694 QTest::newRow(QString("file-%1").arg(c++).toLatin1()) << it.filePath() << QUrl::fromLocalFile(it.filePath()); |
3700 QTest::newRow(QString("file-%1").arg(c++).toLatin1()) << it.filePath() << QUrl::fromLocalFile(it.filePath()); |
3695 } |
3701 } |
3696 |
3702 |
3697 // basic latin1 |
3703 // basic latin1 |
3698 QTest::newRow("unicode-0") << QString::fromUtf8("\xC3\xA5.com/") << QUrl::fromEncoded(QString::fromUtf8("http://\xC3\xA5.com/").toUtf8(), QUrl::TolerantMode); |
3704 QTest::newRow("unicode-0") << QString::fromUtf8("\xc3\xa5.com/") << QUrl::fromEncoded(QString::fromUtf8("http://\xc3\xa5.com/").toUtf8(), QUrl::TolerantMode); |
|
3705 QTest::newRow("unicode-0b") << QString::fromUtf8("\xc3\xa5.com/") << QUrl::fromEncoded("http://%C3%A5.com/", QUrl::TolerantMode); |
|
3706 QTest::newRow("unicode-0c") << QString::fromUtf8("\xc3\xa5.com/") << QUrl::fromEncoded("http://xn--5ca.com/", QUrl::TolerantMode); |
3699 // unicode |
3707 // unicode |
3700 QTest::newRow("unicode-1") << QString::fromUtf8("\xCE\xBB.com/") << QUrl::fromEncoded(QString::fromUtf8("http://\xCE\xBB.com/").toUtf8(), QUrl::TolerantMode); |
3708 QTest::newRow("unicode-1") << QString::fromUtf8("\xce\xbb.com/") << QUrl::fromEncoded(QString::fromUtf8("http://\xce\xbb.com/").toUtf8(), QUrl::TolerantMode); |
|
3709 QTest::newRow("unicode-1b") << QString::fromUtf8("\xce\xbb.com/") << QUrl::fromEncoded("http://%CE%BB.com/", QUrl::TolerantMode); |
|
3710 QTest::newRow("unicode-1c") << QString::fromUtf8("\xce\xbb.com/") << QUrl::fromEncoded("http://xn--wxa.com/", QUrl::TolerantMode); |
3701 |
3711 |
3702 // no scheme |
3712 // no scheme |
3703 QTest::newRow("add scheme-0") << "webkit.org" << QUrl("http://webkit.org"); |
3713 QTest::newRow("add scheme-0") << "example.org" << QUrl("http://example.org"); |
3704 QTest::newRow("add scheme-1") << "www.webkit.org" << QUrl("http://www.webkit.org"); |
3714 QTest::newRow("add scheme-1") << "www.example.org" << QUrl("http://www.example.org"); |
3705 QTest::newRow("add scheme-2") << "ftp.webkit.org" << QUrl("ftp://ftp.webkit.org"); |
3715 QTest::newRow("add scheme-2") << "ftp.example.org" << QUrl("ftp://ftp.example.org"); |
3706 QTest::newRow("add scheme-3") << "webkit" << QUrl("webkit"); |
3716 QTest::newRow("add scheme-3") << "hostname" << QUrl("http://hostname"); |
3707 |
3717 |
3708 // QUrl's tolerant parser should already handle this |
3718 // QUrl's tolerant parser should already handle this |
3709 QTest::newRow("not-encoded-0") << "http://webkit.org/test page.html" << QUrl("http://webkit.org/test%20page.html"); |
3719 QTest::newRow("not-encoded-0") << "http://example.org/test page.html" << QUrl::fromEncoded("http://example.org/test%20page.html"); |
3710 |
3720 |
3711 // Make sure the :80, i.e. port doesn't screw anything up |
3721 // Make sure the :80, i.e. port doesn't screw anything up |
3712 QUrl portUrl("http://webkit.org"); |
3722 QUrl portUrl("http://example.org"); |
3713 portUrl.setPort(80); |
3723 portUrl.setPort(80); |
3714 QTest::newRow("port-0") << "webkit.org:80" << portUrl; |
3724 QTest::newRow("port-0") << "example.org:80" << portUrl; |
3715 QTest::newRow("port-1") << "http://webkit.org:80" << portUrl; |
3725 QTest::newRow("port-1") << "http://example.org:80" << portUrl; |
|
3726 portUrl.setPath("path"); |
|
3727 QTest::newRow("port-1") << "example.org:80/path" << portUrl; |
|
3728 QTest::newRow("port-1") << "http://example.org:80/path" << portUrl; |
3716 |
3729 |
3717 // mailto doesn't have a ://, but is valid |
3730 // mailto doesn't have a ://, but is valid |
3718 QUrl mailto("somebody@somewhere.net"); |
3731 QUrl mailto("ben@example.net"); |
3719 mailto.setScheme("mailto"); |
3732 mailto.setScheme("mailto"); |
3720 QTest::newRow("mailto") << "mailto:somebody@somewhere.net" << mailto; |
3733 QTest::newRow("mailto") << "mailto:ben@example.net" << mailto; |
3721 |
3734 |
3722 // misc |
3735 // misc |
3723 QTest::newRow("localhost-0") << "localhost" << QUrl("http://localhost"); |
|
3724 QTest::newRow("localhost-1") << "localhost:80" << QUrl("http://localhost:80"); |
3736 QTest::newRow("localhost-1") << "localhost:80" << QUrl("http://localhost:80"); |
3725 QTest::newRow("spaces-0") << " http://webkit.org/test page.html " << QUrl("http://webkit.org/test%20page.html"); |
3737 QTest::newRow("spaces-0") << " http://example.org/test page.html " << QUrl("http://example.org/test%20page.html"); |
3726 QTest::newRow("trash-0") << "webkit.org/test?someData=42%&someOtherData=abcde#anchor" << QUrl::fromEncoded("http://webkit.org/test?someData=42%25&someOtherData=abcde#anchor"); |
3738 QTest::newRow("trash-0") << "example.org/test?someData=42%&someOtherData=abcde#anchor" << QUrl::fromEncoded("http://example.org/test?someData=42%25&someOtherData=abcde#anchor"); |
|
3739 QTest::newRow("other-scheme-0") << "spotify:track:0hO542doVbfGDAGQULMORT" << QUrl("spotify:track:0hO542doVbfGDAGQULMORT"); |
|
3740 QTest::newRow("other-scheme-1") << "weirdscheme:80:otherstuff" << QUrl("weirdscheme:80:otherstuff"); |
3727 |
3741 |
3728 // FYI: The scheme in the resulting url user |
3742 // FYI: The scheme in the resulting url user |
3729 QUrl authUrl("user:pass@domain.com"); |
3743 QUrl authUrl("user:pass@domain.com"); |
3730 QTest::newRow("misc-1") << "user:pass@domain.com" << authUrl; |
3744 QTest::newRow("misc-1") << "user:pass@domain.com" << authUrl; |
3731 } |
3745 } |
3732 |
3746 |
3733 // public static QUrl guessUrlFromString(QString const& string) |
|
3734 void tst_QUrl::fromUserInput() |
3747 void tst_QUrl::fromUserInput() |
3735 { |
3748 { |
3736 QFETCH(QString, string); |
3749 QFETCH(QString, string); |
3737 QFETCH(QUrl, url); |
3750 QFETCH(QUrl, guessUrlFromString); |
3738 |
3751 |
3739 QUrl guessedUrl = QUrl::fromUserInput(string); |
3752 QUrl url = QUrl::fromUserInput(string); |
3740 QCOMPARE(guessedUrl, url); |
3753 QCOMPARE(url, guessUrlFromString); |
3741 } |
3754 } |
3742 |
3755 |
3743 void tst_QUrl::task_199967() |
3756 void tst_QUrl::task_199967() |
3744 { |
3757 { |
3745 { |
3758 { |