/*! Check that functions have the correct const qualification. */ void tst_QXmlName::constCorrectness() const { const QXmlName name; /* isNull() */ QVERIFY(name.isNull()); /* operator==() */ QVERIFY(name == name); /* operator!=() */ QVERIFY(!(name != name)); QXmlNamePool namePool; const QXmlName name2(namePool, QLatin1String("localName"), QLatin1String("http://example.com/"), QLatin1String("prefix")); /* namespaceUri(). */ QCOMPARE(name2.namespaceUri(namePool), QLatin1String("http://example.com/")); /* localName(). */ QCOMPARE(name2.localName(namePool), QLatin1String("localName")); /* prefix(). */ QCOMPARE(name2.prefix(namePool), QLatin1String("prefix")); /* toClarkname(). */ QCOMPARE(name2.toClarkName(namePool), QLatin1String("{http://example.com/}prefix:localName")); }
/*! Ensure that the three last arguments have default values, and that they are null strings. */ void tst_QXmlName::argumentConstructorDefaultArguments() const { QXmlNamePool np; const QXmlName n1(np, QLatin1String("localName")); const QXmlName n2(np, QLatin1String("localName"), QString(), QString()); QCOMPARE(n1, n2); QCOMPARE(n1.toClarkName(np), QString::fromLatin1("localName")); }
void tst_QXmlName::toClarkName_data() const { QTest::addColumn<QString>("produced"); QTest::addColumn<QString>("expected"); QXmlNamePool np; /* A null QXmlName. */ { const QXmlName n; QTest::newRow("") << n.toClarkName(np) << QString::fromLatin1("QXmlName(null)"); } { const QXmlName n(np, QLatin1String("localName")); QTest::newRow("") << n.toClarkName(np) << QString::fromLatin1("localName"); } /* Local name with namespace URI, empty prefix. */ { const QXmlName n(np, QLatin1String("localName"), QLatin1String("http://example.com/")); QTest::newRow("") << n.toClarkName(np) << QString::fromLatin1("{http://example.com/}localName"); } /* Local name with namespace URI and prefix. */ { const QXmlName n(np, QLatin1String("localName"), QLatin1String("http://example.com/"), QLatin1String("p")); QTest::newRow("") << n.toClarkName(np) << QString::fromLatin1("{http://example.com/}p:localName"); } }
void tst_QXmlName::operatorEqual_data() const { QTest::addColumn<QXmlName>("op1"); QTest::addColumn<QXmlName>("op2"); QTest::addColumn<bool>("expected"); QXmlNamePool namePool; const QXmlName n1(namePool, QString::fromLatin1("localName1"), QString::fromLatin1("http://example.com/Namespace1"), QString::fromLatin1("prefix1")); const QXmlName n2(namePool, QString::fromLatin1("localName2"), QString::fromLatin1("http://example.com/Namespace1"), QString::fromLatin1("prefix1")); const QXmlName n3(namePool, QString::fromLatin1("localName2"), QString::fromLatin1("http://example.com/Namespace1"), QString::fromLatin1("prefix2")); const QXmlName n4(namePool, QString::fromLatin1("localName3"), QString::fromLatin1("http://example.com/Namespace2")); const QXmlName n5(namePool, QString::fromLatin1("localName4"), QString::fromLatin1("http://example.com/Namespace2")); const QXmlName n6(namePool, QString::fromLatin1("localName4"), QString::fromLatin1("http://example.com/Namespace2"), QString::fromLatin1("prefix3")); const QXmlName n7(namePool, QString::fromLatin1("localName2"), QString::fromLatin1("http://example.com/Namespace2"), QString::fromLatin1("prefix3")); QTest::newRow(qPrintable(n1.toClarkName(namePool))) << n1 << n1 << true; QTest::newRow(qPrintable(n2.toClarkName(namePool))) << n2 << n2 << true; QTest::newRow(qPrintable(n3.toClarkName(namePool))) << n3 << n3 << true; QTest::newRow(qPrintable(n4.toClarkName(namePool))) << n4 << n4 << true; QTest::newRow(qPrintable(n5.toClarkName(namePool))) << n5 << n5 << true; QTest::newRow(qPrintable(n6.toClarkName(namePool))) << n6 << n6 << true; QTest::newRow(qPrintable(n7.toClarkName(namePool))) << n7 << n7 << true; QTest::newRow("Prefix differs") << n2 << n3 << true; QTest::newRow("No prefix vs. prefix") << n5 << n6 << true; QTest::newRow("Local name differs") << n1 << n2 << false; QTest::newRow("Namespace differs") << n2 << n7 << false; }