tests/auto/qxmlquery/tst_qxmlquery.cpp
changeset 3 41300fa6a67c
parent 0 1918ee327afb
child 4 3b1da2848fc7
equal deleted inserted replaced
2:56cd8111b7f7 3:41300fa6a67c
   343                                  QLatin1String("http://example.com/"),
   343                                  QLatin1String("http://example.com/"),
   344                                  QLatin1String("prefix"));
   344                                  QLatin1String("prefix"));
   345         query1.setInitialTemplateName(name);
   345         query1.setInitialTemplateName(name);
   346 
   346 
   347         const QXmlQuery query2(query1);
   347         const QXmlQuery query2(query1);
   348         QCOMPARE(query2.messageHandler(), &silencer);
   348         QCOMPARE(query2.messageHandler(), static_cast<QAbstractMessageHandler *>(&silencer));
   349         QCOMPARE(query2.uriResolver(), &resolver);
   349         QCOMPARE(query2.uriResolver(), static_cast<const QAbstractUriResolver *>(&resolver));
   350         QCOMPARE(query2.queryLanguage(), QXmlQuery::XSLT20);
   350         QCOMPARE(query2.queryLanguage(), QXmlQuery::XSLT20);
   351         QCOMPARE(query2.initialTemplateName(), name);
   351         QCOMPARE(query2.initialTemplateName(), name);
   352         QCOMPARE(query2.networkAccessManager(), &networkManager);
   352         QCOMPARE(query2.networkAccessManager(), &networkManager);
   353 
   353 
   354         QXmlNamePool np2(query2.namePool());
   354         QXmlNamePool np2(query2.namePool());
   520             /* We use assignment operator, not copy constructor. */
   520             /* We use assignment operator, not copy constructor. */
   521             copy = original;
   521             copy = original;
   522 
   522 
   523             QVERIFY(copy.isValid());
   523             QVERIFY(copy.isValid());
   524             QCOMPARE(copy.uriResolver(), static_cast<const QAbstractUriResolver *>(&returnURI));
   524             QCOMPARE(copy.uriResolver(), static_cast<const QAbstractUriResolver *>(&returnURI));
   525             QCOMPARE(copy.messageHandler(), &silencer);
   525             QCOMPARE(copy.messageHandler(), static_cast<QAbstractMessageHandler *>(&silencer));
   526             QCOMPARE(testName.localName(copy.namePool()), QString::fromLatin1("somethingToCheck"));
   526             QCOMPARE(testName.localName(copy.namePool()), QString::fromLatin1("somethingToCheck"));
   527 
   527 
   528             QXmlResultItems result;
   528             QXmlResultItems result;
   529             copy.evaluateTo(&result);
   529             copy.evaluateTo(&result);
   530             QCOMPARE(result.next().toAtomicValue(), QVariant(1));
   530             QCOMPARE(result.next().toAtomicValue(), QVariant(1));
   557                 copy.setQuery(QLatin1String("$var, 1 + 1, ., string(doc($device))"));
   557                 copy.setQuery(QLatin1String("$var, 1 + 1, ., string(doc($device))"));
   558 
   558 
   559                 /* Check that the copy picked up the new things. */
   559                 /* Check that the copy picked up the new things. */
   560                 QVERIFY(copy.isValid());
   560                 QVERIFY(copy.isValid());
   561                 QCOMPARE(copy.uriResolver(), static_cast<const QAbstractUriResolver *>(&secondUriResolver));
   561                 QCOMPARE(copy.uriResolver(), static_cast<const QAbstractUriResolver *>(&secondUriResolver));
   562                 QCOMPARE(copy.messageHandler(), &secondSilencer);
   562                 QCOMPARE(copy.messageHandler(), static_cast<QAbstractMessageHandler *>(&secondSilencer));
   563 
   563 
   564                 QXmlResultItems resultCopy;
   564                 QXmlResultItems resultCopy;
   565                 copy.evaluateTo(&resultCopy);
   565                 copy.evaluateTo(&resultCopy);
   566                 QCOMPARE(resultCopy.next().toAtomicValue(), QVariant(4));
   566                 QCOMPARE(resultCopy.next().toAtomicValue(), QVariant(4));
   567                 QCOMPARE(resultCopy.next().toAtomicValue(), QVariant(2));
   567                 QCOMPARE(resultCopy.next().toAtomicValue(), QVariant(2));
   575             /* Evaluate the original. */
   575             /* Evaluate the original. */
   576             {
   576             {
   577                 /* Check that the original is unchanged. */
   577                 /* Check that the original is unchanged. */
   578                 QVERIFY(original.isValid());
   578                 QVERIFY(original.isValid());
   579                 QCOMPARE(original.uriResolver(), static_cast<const QAbstractUriResolver *>(&returnURI));
   579                 QCOMPARE(original.uriResolver(), static_cast<const QAbstractUriResolver *>(&returnURI));
   580                 QCOMPARE(original.messageHandler(), &silencer);
   580                 QCOMPARE(original.messageHandler(), static_cast<QAbstractMessageHandler *>(&silencer));
   581 
   581 
   582                 QXmlResultItems resultOriginal;
   582                 QXmlResultItems resultOriginal;
   583                 original.evaluateTo(&resultOriginal);
   583                 original.evaluateTo(&resultOriginal);
   584                 QCOMPARE(resultOriginal.next().toAtomicValue(), QVariant(1));
   584                 QCOMPARE(resultOriginal.next().toAtomicValue(), QVariant(1));
   585                 QCOMPARE(resultOriginal.next().toAtomicValue(), QVariant(2));
   585                 QCOMPARE(resultOriginal.next().toAtomicValue(), QVariant(2));
   929 void tst_QXmlQuery::setMessageHandler() const
   929 void tst_QXmlQuery::setMessageHandler() const
   930 {
   930 {
   931     QXmlQuery query;
   931     QXmlQuery query;
   932     MessageSilencer silencer;
   932     MessageSilencer silencer;
   933     query.setMessageHandler(&silencer);
   933     query.setMessageHandler(&silencer);
   934     QCOMPARE(&silencer, query.messageHandler());
   934     QCOMPARE(static_cast<QAbstractMessageHandler *>(&silencer), query.messageHandler());
   935 }
   935 }
   936 
   936 
   937 void tst_QXmlQuery::evaluateToReceiver()
   937 void tst_QXmlQuery::evaluateToReceiver()
   938 {
   938 {
   939     QFETCH(QString, inputQuery);
   939     QFETCH(QString, inputQuery);
  1689 
  1689 
  1690     {
  1690     {
  1691         TestURIResolver resolver;
  1691         TestURIResolver resolver;
  1692         QXmlQuery query;
  1692         QXmlQuery query;
  1693         query.setUriResolver(&resolver);
  1693         query.setUriResolver(&resolver);
  1694         QCOMPARE(query.uriResolver(), &resolver);
  1694         QCOMPARE(query.uriResolver(), static_cast<const QAbstractUriResolver *>(&resolver));
  1695     }
  1695     }
  1696 }
  1696 }
  1697 
  1697 
  1698 void tst_QXmlQuery::uriResolver() const
  1698 void tst_QXmlQuery::uriResolver() const
  1699 {
  1699 {