summaryrefslogtreecommitdiffstats
path: root/tests/auto/corelib/io
diff options
context:
space:
mode:
authorThiago Macieira <thiago.macieira@intel.com>2011-09-08 22:05:42 +0200
committerQt by Nokia <qt-info@nokia.com>2012-03-30 01:19:59 +0200
commit1c2144c39fa0069bf496e8f77389a9c2f8a31acf (patch)
treefb3709b67e9d2f5f76cb9a45c6113b67d686d765 /tests/auto/corelib/io
parent1aeb18038661d8da6d37fa278e37e315e35c5c42 (diff)
Forward the methods dealing with the break down of query to QUrlQuery
Now that QUrlQuery exists, these methods are no longer necessary in QUrl itself. Manipulation of the items should be done using the new class. They are now implemented using a temporary QUrlQuery. This is hardly efficient but it works. Change-Id: I34820b3101424593d0715841a2057ac3f74d74f0 Reviewed-by: Lars Knoll <lars.knoll@nokia.com>
Diffstat (limited to 'tests/auto/corelib/io')
-rw-r--r--tests/auto/corelib/io/qurl/tst_qurl.cpp101
-rw-r--r--tests/auto/corelib/io/qurlquery/tst_qurlquery.cpp120
2 files changed, 120 insertions, 101 deletions
diff --git a/tests/auto/corelib/io/qurl/tst_qurl.cpp b/tests/auto/corelib/io/qurl/tst_qurl.cpp
index 7ca7fbb81d..900d0b7644 100644
--- a/tests/auto/corelib/io/qurl/tst_qurl.cpp
+++ b/tests/auto/corelib/io/qurl/tst_qurl.cpp
@@ -114,11 +114,8 @@ private slots:
void isRelative_data();
void isRelative();
void setQueryItems();
- void queryItems();
void hasQuery_data();
void hasQuery();
- void hasQueryItem_data();
- void hasQueryItem();
void nameprep();
void isValid();
void schemeValidator_data();
@@ -157,8 +154,6 @@ private slots:
void toEncodedNotUsingUninitializedPath();
void emptyAuthorityRemovesExistingAuthority();
void acceptEmptyAuthoritySegments();
- void removeAllEncodedQueryItems_data();
- void removeAllEncodedQueryItems();
};
// Testing get/set functions
@@ -1416,8 +1411,6 @@ void tst_QUrl::symmetry()
QCOMPARE(url.path(), QString::fromLatin1("/pub"));
// this will be encoded ...
QCOMPARE(url.encodedQuery().constData(), QString::fromLatin1("a=b&a=d%C3%B8&a=f").toLatin1().constData());
- // unencoded
- QCOMPARE(url.allQueryItemValues("a").join(""), QString::fromUtf8("bdøf"));
QCOMPARE(url.fragment(), QString::fromUtf8("vræl"));
QUrl onlyHost("//qt.nokia.com");
@@ -1577,56 +1570,6 @@ void tst_QUrl::setQueryItems()
"/ole&du>anne+jørgen=sant/prosent>%25#top"));
}
-void tst_QUrl::queryItems()
-{
- QUrl url;
- QVERIFY(!url.hasQuery());
-
- QList<QPair<QString, QString> > newItems;
- newItems += qMakePair(QString("2"), QString("b"));
- newItems += qMakePair(QString("1"), QString("a"));
- newItems += qMakePair(QString("3"), QString("c"));
- newItems += qMakePair(QString("4"), QString("a b"));
- newItems += qMakePair(QString("5"), QString("&"));
- newItems += qMakePair(QString("foo bar"), QString("hello world"));
- newItems += qMakePair(QString("foo+bar"), QString("hello+world"));
- newItems += qMakePair(QString("tex"), QString("a + b = c"));
- url.setQueryItems(newItems);
- QVERIFY(url.hasQuery());
-
- QList<QPair<QString, QString> > setItems = url.queryItems();
- QVERIFY(newItems == setItems);
-
- url.addQueryItem("1", "z");
-
- QVERIFY(url.hasQueryItem("1"));
- QCOMPARE(url.queryItemValue("1").toLatin1().constData(), "a");
-
- url.addQueryItem("1", "zz");
-
- QStringList expected;
- expected += "a";
- expected += "z";
- expected += "zz";
- QCOMPARE(expected, url.allQueryItemValues("1"));
-
- url.removeQueryItem("1");
- QCOMPARE(url.allQueryItemValues("1").size(), 2);
- QCOMPARE(url.queryItemValue("1").toLatin1().constData(), "z");
-
- url.removeAllQueryItems("1");
- QVERIFY(!url.hasQueryItem("1"));
-
- QCOMPARE(url.queryItemValue("4").toLatin1().constData(), "a b");
- QCOMPARE(url.queryItemValue("5").toLatin1().constData(), "&");
- QCOMPARE(url.queryItemValue("tex").toLatin1().constData(), "a + b = c");
- QCOMPARE(url.queryItemValue("foo bar").toLatin1().constData(), "hello world");
- url.setUrl("http://www.google.com/search?q=a+b");
- QCOMPARE(url.queryItemValue("q"), QString("a+b"));
- url.setUrl("http://www.google.com/search?q=a=b"); // invalid, but should be tolerated
- QCOMPARE(url.queryItemValue("q"), QString("a=b"));
-}
-
void tst_QUrl::hasQuery_data()
{
QTest::addColumn<QString>("url");
@@ -1656,27 +1599,6 @@ void tst_QUrl::hasQuery()
QCOMPARE(qurl.encodedQuery().isNull(), !trueFalse);
}
-void tst_QUrl::hasQueryItem_data()
-{
- QTest::addColumn<QString>("url");
- QTest::addColumn<QString>("item");
- QTest::addColumn<bool>("trueFalse");
-
- QTest::newRow("no query items") << "http://www.foo.bar" << "baz" << false;
- QTest::newRow("query item: hello") << "http://www.foo.bar?hello=world" << "hello" << true;
- QTest::newRow("no query item: world") << "http://www.foo.bar?hello=world" << "world" << false;
- QTest::newRow("query item: qt") << "http://www.foo.bar?hello=world&qt=rocks" << "qt" << true;
-}
-
-void tst_QUrl::hasQueryItem()
-{
- QFETCH(QString, url);
- QFETCH(QString, item);
- QFETCH(bool, trueFalse);
-
- QCOMPARE(QUrl(url).hasQueryItem(item), trueFalse);
-}
-
void tst_QUrl::nameprep()
{
QUrl url(QString::fromUtf8("http://www.fu""\xc3""\x9f""ball.de/"));
@@ -2568,28 +2490,5 @@ void tst_QUrl::effectiveTLDs()
QCOMPARE(domain.topLevelDomain(), TLD);
}
-void tst_QUrl::removeAllEncodedQueryItems_data()
-{
- QTest::addColumn<QUrl>("url");
- QTest::addColumn<QByteArray>("key");
- QTest::addColumn<QUrl>("result");
-
- QTest::newRow("test1") << QUrl::fromEncoded("http://qt.nokia.com/foo?aaa=a&bbb=b&ccc=c") << QByteArray("bbb") << QUrl::fromEncoded("http://qt.nokia.com/foo?aaa=a&ccc=c");
- QTest::newRow("test2") << QUrl::fromEncoded("http://qt.nokia.com/foo?aaa=a&bbb=b&ccc=c") << QByteArray("aaa") << QUrl::fromEncoded("http://qt.nokia.com/foo?bbb=b&ccc=c");
-// QTest::newRow("test3") << QUrl::fromEncoded("http://qt.nokia.com/foo?aaa=a&bbb=b&ccc=c") << QByteArray("ccc") << QUrl::fromEncoded("http://qt.nokia.com/foo?aaa=a&bbb=b");
- QTest::newRow("test4") << QUrl::fromEncoded("http://qt.nokia.com/foo?aaa=a&bbb=b&ccc=c") << QByteArray("b%62b") << QUrl::fromEncoded("http://qt.nokia.com/foo?aaa=a&bbb=b&ccc=c");
- QTest::newRow("test5") << QUrl::fromEncoded("http://qt.nokia.com/foo?aaa=a&b%62b=b&ccc=c") << QByteArray("b%62b") << QUrl::fromEncoded("http://qt.nokia.com/foo?aaa=a&ccc=c");
- QTest::newRow("test6") << QUrl::fromEncoded("http://qt.nokia.com/foo?aaa=a&b%62b=b&ccc=c") << QByteArray("bbb") << QUrl::fromEncoded("http://qt.nokia.com/foo?aaa=a&b%62b=b&ccc=c");
-}
-
-void tst_QUrl::removeAllEncodedQueryItems()
-{
- QFETCH(QUrl, url);
- QFETCH(QByteArray, key);
- QFETCH(QUrl, result);
- url.removeAllEncodedQueryItems(key);
- QCOMPARE(url, result);
-}
-
QTEST_MAIN(tst_QUrl)
#include "tst_qurl.moc"
diff --git a/tests/auto/corelib/io/qurlquery/tst_qurlquery.cpp b/tests/auto/corelib/io/qurlquery/tst_qurlquery.cpp
index 4ce621c4ba..ec9170bd7d 100644
--- a/tests/auto/corelib/io/qurlquery/tst_qurlquery.cpp
+++ b/tests/auto/corelib/io/qurlquery/tst_qurlquery.cpp
@@ -72,6 +72,12 @@ private Q_SLOTS:
void encodedParsing_data();
void encodedParsing();
void differentDelimiters();
+
+ // old tests from tst_qurl.cpp
+ // add new tests above
+ void old_queryItems();
+ void old_hasQueryItem_data();
+ void old_hasQueryItem();
};
static QString prettyElement(const QString &key, const QString &value)
@@ -230,6 +236,14 @@ void tst_QUrlQuery::constructing()
empty.setQueryDelimiters('(', ')');
QCOMPARE(empty.queryValueDelimiter(), QChar(QLatin1Char('(')));
QCOMPARE(empty.queryPairDelimiter(), QChar(QLatin1Char(')')));
+
+ QList<QPair<QString, QString> > query;
+ query += qMakePair(QString("type"), QString("login"));
+ query += qMakePair(QString("name"), QString::fromUtf8("åge nissemannsen"));
+ query += qMakePair(QString("ole&du"), QString::fromUtf8("anne+jørgen=sant"));
+ query += qMakePair(QString("prosent"), QString("%"));
+ copy.setQueryItems(query);
+ QVERIFY(!copy.isEmpty());
}
void tst_QUrlQuery::addRemove()
@@ -690,6 +704,112 @@ void tst_QUrlQuery::differentDelimiters()
}
}
+void tst_QUrlQuery::old_queryItems()
+{
+ // test imported from old tst_qurl.cpp
+ QUrlQuery url;
+
+ QList<QPair<QString, QString> > newItems;
+ newItems += qMakePair(QString("1"), QString("a"));
+ newItems += qMakePair(QString("2"), QString("b"));
+ newItems += qMakePair(QString("3"), QString("c"));
+ newItems += qMakePair(QString("4"), QString("a b"));
+ newItems += qMakePair(QString("5"), QString("&"));
+ newItems += qMakePair(QString("foo bar"), QString("hello world"));
+ newItems += qMakePair(QString("foo+bar"), QString("hello+world"));
+ newItems += qMakePair(QString("tex"), QString("a + b = c"));
+ url.setQueryItems(newItems);
+ QVERIFY(!url.isEmpty());
+
+ QList<QPair<QString, QString> > setItems = url.queryItems();
+ QVERIFY(newItems == setItems);
+
+ url.addQueryItem("1", "z");
+
+#if 0
+ // undefined behaviour in the new QUrlQuery
+
+ QVERIFY(url.hasQueryItem("1"));
+ QCOMPARE(url.queryItemValue("1").toLatin1().constData(), "a");
+
+ url.addQueryItem("1", "zz");
+
+ QStringList expected;
+ expected += "a";
+ expected += "z";
+ expected += "zz";
+ QCOMPARE(url.allQueryItemValues("1"), expected);
+
+ url.removeQueryItem("1");
+ QCOMPARE(url.allQueryItemValues("1").size(), 2);
+ QCOMPARE(url.queryItemValue("1").toLatin1().constData(), "z");
+#endif
+
+ url.removeAllQueryItems("1");
+ QVERIFY(!url.hasQueryItem("1"));
+
+ QCOMPARE(url.queryItemValue("4").toLatin1().constData(), "a b");
+ QCOMPARE(url.queryItemValue("5").toLatin1().constData(), "&");
+ QCOMPARE(url.queryItemValue("tex").toLatin1().constData(), "a + b = c");
+ QCOMPARE(url.queryItemValue("foo bar").toLatin1().constData(), "hello world");
+
+ //url.setUrl("http://www.google.com/search?q=a+b");
+ url.setQuery("q=a+b");
+ QCOMPARE(url.queryItemValue("q"), QString("a+b"));
+
+ //url.setUrl("http://www.google.com/search?q=a=b"); // invalid, but should be tolerated
+ url.setQuery("q=a=b");
+ QCOMPARE(url.queryItemValue("q"), QString("a=b"));
+}
+
+void tst_QUrlQuery::old_hasQueryItem_data()
+{
+ QTest::addColumn<QString>("url");
+ QTest::addColumn<QString>("item");
+ QTest::addColumn<bool>("trueFalse");
+
+ // the old tests started with "http://www.foo.bar"
+ QTest::newRow("no query items") << "" << "baz" << false;
+ QTest::newRow("query item: hello") << "hello=world" << "hello" << true;
+ QTest::newRow("no query item: world") << "hello=world" << "world" << false;
+ QTest::newRow("query item: qt") << "hello=world&qt=rocks" << "qt" << true;
+}
+
+void tst_QUrlQuery::old_hasQueryItem()
+{
+ QFETCH(QString, url);
+ QFETCH(QString, item);
+ QFETCH(bool, trueFalse);
+
+ QCOMPARE(QUrlQuery(url).hasQueryItem(item), trueFalse);
+}
+
+#if 0
+// this test doesn't make sense anymore
+void tst_QUrl::removeAllEncodedQueryItems_data()
+{
+ QTest::addColumn<QUrl>("url");
+ QTest::addColumn<QByteArray>("key");
+ QTest::addColumn<QUrl>("result");
+
+ QTest::newRow("test1") << QUrl::fromEncoded("http://qt.nokia.com/foo?aaa=a&bbb=b&ccc=c") << QByteArray("bbb") << QUrl::fromEncoded("http://qt.nokia.com/foo?aaa=a&ccc=c");
+ QTest::newRow("test2") << QUrl::fromEncoded("http://qt.nokia.com/foo?aaa=a&bbb=b&ccc=c") << QByteArray("aaa") << QUrl::fromEncoded("http://qt.nokia.com/foo?bbb=b&ccc=c");
+// QTest::newRow("test3") << QUrl::fromEncoded("http://qt.nokia.com/foo?aaa=a&bbb=b&ccc=c") << QByteArray("ccc") << QUrl::fromEncoded("http://qt.nokia.com/foo?aaa=a&bbb=b");
+ QTest::newRow("test4") << QUrl::fromEncoded("http://qt.nokia.com/foo?aaa=a&bbb=b&ccc=c") << QByteArray("b%62b") << QUrl::fromEncoded("http://qt.nokia.com/foo?aaa=a&bbb=b&ccc=c");
+ QTest::newRow("test5") << QUrl::fromEncoded("http://qt.nokia.com/foo?aaa=a&b%62b=b&ccc=c") << QByteArray("b%62b") << QUrl::fromEncoded("http://qt.nokia.com/foo?aaa=a&ccc=c");
+ QTest::newRow("test6") << QUrl::fromEncoded("http://qt.nokia.com/foo?aaa=a&b%62b=b&ccc=c") << QByteArray("bbb") << QUrl::fromEncoded("http://qt.nokia.com/foo?aaa=a&b%62b=b&ccc=c");
+}
+
+void tst_QUrl::removeAllEncodedQueryItems()
+{
+ QFETCH(QUrl, url);
+ QFETCH(QByteArray, key);
+ QFETCH(QUrl, result);
+ url.removeAllEncodedQueryItems(key);
+ QCOMPARE(url, result);
+}
+#endif
+
QTEST_APPLESS_MAIN(tst_QUrlQuery)
#include "tst_qurlquery.moc"