Esempio n. 1
0
void tst_QUrlQuery::constructing()
{
    QUrlQuery empty;
    QVERIFY(empty.isEmpty());
    QCOMPARE(empty.queryPairDelimiter(), QUrlQuery::defaultQueryPairDelimiter());
    QCOMPARE(empty.queryValueDelimiter(), QUrlQuery::defaultQueryValueDelimiter());
    // undefined whether it is detached, but don't crash
    QVERIFY(empty.isDetached() || !empty.isDetached());

    empty.clear();
    QVERIFY(empty.isEmpty());

    {
        QUrlQuery copy(empty);
        QVERIFY(copy.isEmpty());
        QVERIFY(!copy.isDetached());
        QVERIFY(copy == empty);
        QVERIFY(!(copy != empty));

        copy = empty;
        QVERIFY(copy == empty);

        copy = QUrlQuery();
        QVERIFY(copy == empty);
    }
    {
        QUrlQuery copy(emptyQuery());
        QVERIFY(copy == empty);
    }

    QVERIFY(!empty.hasQueryItem("a"));
    QVERIFY(empty.queryItemValue("a").isEmpty());
    QVERIFY(empty.allQueryItemValues("a").isEmpty());

    QVERIFY(!empty.hasQueryItem(""));
    QVERIFY(empty.queryItemValue("").isEmpty());
    QVERIFY(empty.allQueryItemValues("").isEmpty());

    QVERIFY(!empty.hasQueryItem(QString()));
    QVERIFY(empty.queryItemValue(QString()).isEmpty());
    QVERIFY(empty.allQueryItemValues(QString()).isEmpty());

    QVERIFY(empty.queryItems().isEmpty());

    QUrlQuery other;
    other.addQueryItem("a", "b");
    QVERIFY(!other.isEmpty());
    QVERIFY(other.isDetached());
    QVERIFY(other != empty);
    QVERIFY(!(other == empty));

    QUrlQuery copy(other);
    QVERIFY(copy == other);

    copy.clear();
    QVERIFY(copy.isEmpty());
    QVERIFY(copy != other);

    copy = other;
    QVERIFY(!copy.isEmpty());
    QVERIFY(copy == other);

    copy = QUrlQuery();
    QVERIFY(copy.isEmpty());

    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());
}