tests/auto/qurl/tst_qurl.cpp
branchGCC_SURGE
changeset 31 5daf16870df6
parent 30 5dc02b23752f
child 37 758a864f9613
equal deleted inserted replaced
27:93b982ccede2 31:5daf16870df6
   191     void binaryData();
   191     void binaryData();
   192     void fromUserInput_data();
   192     void fromUserInput_data();
   193     void fromUserInput();
   193     void fromUserInput();
   194     void task_199967();
   194     void task_199967();
   195     void task_240612();
   195     void task_240612();
       
   196     void taskQTBUG_6962();
   196 
   197 
   197 #ifdef QT3_SUPPORT
   198 #ifdef QT3_SUPPORT
   198     void dirPath();
   199     void dirPath();
   199 #endif
   200 #endif
   200 };
   201 };
  1407         }
  1408         }
  1408 
  1409 
  1409 void tst_QUrl::i18n_data()
  1410 void tst_QUrl::i18n_data()
  1410 {
  1411 {
  1411     QTest::addColumn<QString>("input");
  1412     QTest::addColumn<QString>("input");
  1412     QTest::addColumn<QByteArray>("punyOutput"); 
  1413     QTest::addColumn<QByteArray>("punyOutput");
  1413 
  1414 
  1414     QTest::newRow("øl") << QString::fromLatin1("http://ole:passord@www.øl.no/index.html?ole=æsemann&ilder gud=hei#top")
  1415     QTest::newRow("øl") << QString::fromLatin1("http://ole:passord@www.øl.no/index.html?ole=æsemann&ilder gud=hei#top")
  1415                      <<          QByteArray("http://ole:passord@www.xn--l-4ga.no/index.html?ole=%C3%A6semann&ilder%20gud=hei#top");
  1416                      <<          QByteArray("http://ole:passord@www.xn--l-4ga.no/index.html?ole=%C3%A6semann&ilder%20gud=hei#top");
  1416     QTest::newRow("räksmörgås") << QString::fromLatin1("http://www.räksmörgås.no/")
  1417     QTest::newRow("räksmörgås") << QString::fromLatin1("http://www.räksmörgås.no/")
  1417                              << QByteArray("http://www.xn--rksmrgs-5wao1o.no/");
  1418                              << QByteArray("http://www.xn--rksmrgs-5wao1o.no/");
  1629     */
  1630     */
  1630 
  1631 
  1631     QTest::newRow("nopath_task31320") << QString::fromLatin1("host://protocol")
  1632     QTest::newRow("nopath_task31320") << QString::fromLatin1("host://protocol")
  1632                                    << uint(QUrl::None)
  1633                                    << uint(QUrl::None)
  1633                                    << QString::fromLatin1("host://protocol");
  1634                                    << QString::fromLatin1("host://protocol");
       
  1635 
       
  1636     QTest::newRow("underscore_QTBUG-7434") << QString::fromLatin1("http://foo_bar.host.com/rss.php")
       
  1637                                    << uint(QUrl::None)
       
  1638                                    << QString::fromLatin1("http://foo_bar.host.com/rss.php");
  1634 }
  1639 }
  1635 
  1640 
  1636 void tst_QUrl::toString()
  1641 void tst_QUrl::toString()
  1637 {
  1642 {
  1638     QFETCH(QString, urlString);
  1643     QFETCH(QString, urlString);
  2158     QTest::addColumn<QByteArray>("encoded");
  2163     QTest::addColumn<QByteArray>("encoded");
  2159     QTest::addColumn<QByteArray>("excludeInEncoding");
  2164     QTest::addColumn<QByteArray>("excludeInEncoding");
  2160     QTest::addColumn<QByteArray>("includeInEncoding");
  2165     QTest::addColumn<QByteArray>("includeInEncoding");
  2161 
  2166 
  2162     QTest::newRow("test_01") << QString::fromLatin1("abcdevghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ012345678-._~")
  2167     QTest::newRow("test_01") << QString::fromLatin1("abcdevghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ012345678-._~")
  2163                           << QByteArray("abcdevghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ012345678-._~") 
  2168                           << QByteArray("abcdevghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ012345678-._~")
  2164                           << QByteArray("")
  2169                           << QByteArray("")
  2165                           << QByteArray("");
  2170                           << QByteArray("");
  2166     QTest::newRow("test_02") << QString::fromLatin1("{\t\n\r^\"abc}")
  2171     QTest::newRow("test_02") << QString::fromLatin1("{\t\n\r^\"abc}")
  2167                           << QByteArray("%7B%09%0A%0D%5E%22abc%7D") 
  2172                           << QByteArray("%7B%09%0A%0D%5E%22abc%7D")
  2168                           << QByteArray("")
  2173                           << QByteArray("")
  2169                           << QByteArray("");
  2174                           << QByteArray("");
  2170     QTest::newRow("test_03") << QString::fromLatin1("://?#[]@!$&'()*+,;=")
  2175     QTest::newRow("test_03") << QString::fromLatin1("://?#[]@!$&'()*+,;=")
  2171                           << QByteArray("%3A%2F%2F%3F%23%5B%5D%40%21%24%26%27%28%29%2A%2B%2C%3B%3D") 
  2176                           << QByteArray("%3A%2F%2F%3F%23%5B%5D%40%21%24%26%27%28%29%2A%2B%2C%3B%3D")
  2172                           << QByteArray("")
  2177                           << QByteArray("")
  2173                           << QByteArray("");
  2178                           << QByteArray("");
  2174     QTest::newRow("test_04") << QString::fromLatin1("://?#[]@!$&'()*+,;=")
  2179     QTest::newRow("test_04") << QString::fromLatin1("://?#[]@!$&'()*+,;=")
  2175                           << QByteArray("%3A%2F%2F%3F%23%5B%5D%40!$&'()*+,;=") 
  2180                           << QByteArray("%3A%2F%2F%3F%23%5B%5D%40!$&'()*+,;=")
  2176                           << QByteArray("!$&'()*+,;=")
  2181                           << QByteArray("!$&'()*+,;=")
  2177                           << QByteArray("");
  2182                           << QByteArray("");
  2178     QTest::newRow("test_05") << QString::fromLatin1("abcd")
  2183     QTest::newRow("test_05") << QString::fromLatin1("abcd")
  2179                           << QByteArray("a%62%63d")
  2184                           << QByteArray("a%62%63d")
  2180                           << QByteArray("")
  2185                           << QByteArray("")
  2181                           << QByteArray("bc");                          
  2186                           << QByteArray("bc");
  2182 }
  2187 }
  2183 
  2188 
  2184 void tst_QUrl::toPercentEncoding()
  2189 void tst_QUrl::toPercentEncoding()
  2185 {
  2190 {
  2186     QFETCH(QString, original);
  2191     QFETCH(QString, original);
  2187     QFETCH(QByteArray, encoded);
  2192     QFETCH(QByteArray, encoded);
  2188     QFETCH(QByteArray, excludeInEncoding);
  2193     QFETCH(QByteArray, excludeInEncoding);
  2189     QFETCH(QByteArray, includeInEncoding);
  2194     QFETCH(QByteArray, includeInEncoding);
  2190 
  2195 
  2191     QByteArray encodedUrl = QUrl::toPercentEncoding(original, excludeInEncoding, includeInEncoding); 
  2196     QByteArray encodedUrl = QUrl::toPercentEncoding(original, excludeInEncoding, includeInEncoding);
  2192     QCOMPARE(encodedUrl.constData(), encoded.constData());
  2197     QCOMPARE(encodedUrl.constData(), encoded.constData());
  2193     QCOMPARE(original, QUrl::fromPercentEncoding(encodedUrl));
  2198     QCOMPARE(original, QUrl::fromPercentEncoding(encodedUrl));
  2194 }
  2199 }
  2195 
  2200 
  2196 void tst_QUrl::symmetry()
  2201 void tst_QUrl::symmetry()
  2454     }
  2459     }
  2455     {
  2460     {
  2456         QUrl url = QUrl::fromEncoded("http://strange<username>@ok-hostname/", QUrl::StrictMode);
  2461         QUrl url = QUrl::fromEncoded("http://strange<username>@ok-hostname/", QUrl::StrictMode);
  2457         QVERIFY(!url.isValid());
  2462         QVERIFY(!url.isValid());
  2458         // < and > are not allowed in userinfo in strict mode
  2463         // < and > are not allowed in userinfo in strict mode
       
  2464         url.setUserName("normal_username");
       
  2465         QVERIFY(url.isValid());
  2459     }
  2466     }
  2460     {
  2467     {
  2461         QUrl url = QUrl::fromEncoded("http://strange<username>@ok-hostname/");
  2468         QUrl url = QUrl::fromEncoded("http://strange<username>@ok-hostname/");
  2462         QVERIFY(url.isValid());
  2469         QVERIFY(url.isValid());
  2463         // < and > are allowed in tolerant mode
  2470         // < and > are allowed in tolerant mode
  2464     }
  2471     }
  2465     {
  2472     {
  2466         QUrl url = QUrl::fromEncoded("http://strange;hostname/here");
  2473         QUrl url = QUrl::fromEncoded("http://strange;hostname/here");
  2467         QVERIFY(!url.isValid());
  2474         QVERIFY(!url.isValid());
  2468         QCOMPARE(url.path(), QString("/here"));
  2475         QCOMPARE(url.path(), QString("/here"));
  2469     }
  2476         url.setAuthority("foobar@bar");
       
  2477         QVERIFY(url.isValid());
       
  2478     }
       
  2479 
       
  2480     {
       
  2481         QUrl url = QUrl::fromEncoded("foo://stuff;1/g");
       
  2482         QVERIFY(!url.isValid());
       
  2483         QCOMPARE(url.path(), QString("/g"));
       
  2484         url.setHost("stuff-1");
       
  2485         QVERIFY(url.isValid());
       
  2486     }
       
  2487 
  2470 }
  2488 }
  2471 
  2489 
  2472 void tst_QUrl::schemeValidator_data()
  2490 void tst_QUrl::schemeValidator_data()
  2473 {
  2491 {
  2474     QTest::addColumn<QByteArray>("encodedUrl");
  2492     QTest::addColumn<QByteArray>("encodedUrl");
  3187                                << QString::fromLatin1("alqualond\353")
  3205                                << QString::fromLatin1("alqualond\353")
  3188                                << QString::fromLatin1("alqualond\353");
  3206                                << QString::fromLatin1("alqualond\353");
  3189 
  3207 
  3190     QTest::newRow("separator-3002") << QString::fromUtf8("example\343\200\202com")
  3208     QTest::newRow("separator-3002") << QString::fromUtf8("example\343\200\202com")
  3191                                     << "example.com" << "." << "example.com";
  3209                                     << "example.com" << "." << "example.com";
       
  3210 
       
  3211     QString egyptianIDN =
       
  3212         QString::fromUtf8("\331\210\330\262\330\247\330\261\330\251\055\330\247\331\204\330"
       
  3213                           "\243\330\252\330\265\330\247\331\204\330\247\330\252.\331\205"
       
  3214                           "\330\265\330\261");
       
  3215     QTest::newRow("egyptian-tld-ace")
       
  3216         << "xn----rmckbbajlc6dj7bxne2c.xn--wgbh1c"
       
  3217         << "xn----rmckbbajlc6dj7bxne2c.xn--wgbh1c"
       
  3218         << "."
       
  3219         << egyptianIDN;
       
  3220     QTest::newRow("egyptian-tld-unicode")
       
  3221         << egyptianIDN
       
  3222         << "xn----rmckbbajlc6dj7bxne2c.xn--wgbh1c"
       
  3223         << "."
       
  3224         << egyptianIDN;
       
  3225     QTest::newRow("egyptian-tld-mix1")
       
  3226         << QString::fromUtf8("\331\210\330\262\330\247\330\261\330\251\055\330\247\331\204\330"
       
  3227                              "\243\330\252\330\265\330\247\331\204\330\247\330\252.xn--wgbh1c")
       
  3228         << "xn----rmckbbajlc6dj7bxne2c.xn--wgbh1c"
       
  3229         << "."
       
  3230         << egyptianIDN;
       
  3231     QTest::newRow("egyptian-tld-mix2")
       
  3232         << QString::fromUtf8("xn----rmckbbajlc6dj7bxne2c.\331\205\330\265\330\261")
       
  3233         << "xn----rmckbbajlc6dj7bxne2c.xn--wgbh1c"
       
  3234         << "."
       
  3235         << egyptianIDN;
  3192 }
  3236 }
  3193 
  3237 
  3194 void tst_QUrl::ace_testsuite()
  3238 void tst_QUrl::ace_testsuite()
  3195 {
  3239 {
  3196     static const char canonsuffix[] = ".troll.no";
  3240     static const char canonsuffix[] = ".troll.no";
  3241     QTest::newRow("slash") << "foo/bar" << true;
  3285     QTest::newRow("slash") << "foo/bar" << true;
  3242     QTest::newRow("colon") << "foo:80" << true;
  3286     QTest::newRow("colon") << "foo:80" << true;
  3243     QTest::newRow("question") << "foo?bar" << true;
  3287     QTest::newRow("question") << "foo?bar" << true;
  3244     QTest::newRow("at") << "foo@bar" << true;
  3288     QTest::newRow("at") << "foo@bar" << true;
  3245     QTest::newRow("backslash") << "foo\\bar" << false;
  3289     QTest::newRow("backslash") << "foo\\bar" << false;
  3246     QTest::newRow("underline") << "foo_bar" << false;
       
  3247 
  3290 
  3248     // these characters are transformed by NFKC to non-LDH characters
  3291     // these characters are transformed by NFKC to non-LDH characters
  3249     QTest::newRow("dot-like") << QString::fromUtf8("foo\342\200\244bar") << false;  // U+2024 ONE DOT LEADER
  3292     QTest::newRow("dot-like") << QString::fromUtf8("foo\342\200\244bar") << false;  // U+2024 ONE DOT LEADER
  3250     QTest::newRow("slash-like") << QString::fromUtf8("foo\357\274\217bar") << false;    // U+FF0F FULLWIDTH SOLIDUS
  3293     QTest::newRow("slash-like") << QString::fromUtf8("foo\357\274\217bar") << false;    // U+FF0F FULLWIDTH SOLIDUS
  3251 
  3294 
  3286 {
  3329 {
  3287     QTest::addColumn<QString>("source");
  3330     QTest::addColumn<QString>("source");
  3288 
  3331 
  3289     QTest::newRow("ending-dot") << "example.com.";
  3332     QTest::newRow("ending-dot") << "example.com.";
  3290     QTest::newRow("ending-dot3002") << QString("example.com") + QChar(0x3002);
  3333     QTest::newRow("ending-dot3002") << QString("example.com") + QChar(0x3002);
       
  3334     QTest::newRow("underline") << "foo_bar";  //QTBUG-7434
  3291 }
  3335 }
  3292 
  3336 
  3293 void tst_QUrl::std3deviations()
  3337 void tst_QUrl::std3deviations()
  3294 {
  3338 {
  3295     QFETCH(QString, source);
  3339     QFETCH(QString, source);
  3858         << QUrl::fromEncoded("http://www.foo.com:8080/")
  3902         << QUrl::fromEncoded("http://www.foo.com:8080/")
  3859         << QUrl::fromEncoded("newfile.html")
  3903         << QUrl::fromEncoded("newfile.html")
  3860         << QUrl::fromEncoded("http://www.foo.com:8080/newfile.html");
  3904         << QUrl::fromEncoded("http://www.foo.com:8080/newfile.html");
  3861 }
  3905 }
  3862 
  3906 
       
  3907 void tst_QUrl::taskQTBUG_6962()
       
  3908 {
       
  3909     //bug 6962: empty authority ignored by setAuthority
       
  3910     QUrl url("http://example.com/something");
       
  3911     url.setAuthority(QString());
       
  3912     QCOMPARE(url.authority(), QString());
       
  3913 }
       
  3914 
  3863 QTEST_MAIN(tst_QUrl)
  3915 QTEST_MAIN(tst_QUrl)
  3864 #include "tst_qurl.moc"
  3916 #include "tst_qurl.moc"