tests/auto/xmlpatternssdk/XSLTTestSuiteHandler.cpp
changeset 18 2f34d5167611
equal deleted inserted replaced
3:41300fa6a67c 18:2f34d5167611
       
     1 /****************************************************************************
       
     2 **
       
     3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
       
     4 ** All rights reserved.
       
     5 ** Contact: Nokia Corporation (qt-info@nokia.com)
       
     6 **
       
     7 ** This file is part of the test suite of the Qt Toolkit.
       
     8 **
       
     9 ** $QT_BEGIN_LICENSE:LGPL$
       
    10 ** No Commercial Usage
       
    11 ** This file contains pre-release code and may not be distributed.
       
    12 ** You may use this file in accordance with the terms and conditions
       
    13 ** contained in the Technology Preview License Agreement accompanying
       
    14 ** this package.
       
    15 **
       
    16 ** GNU Lesser General Public License Usage
       
    17 ** Alternatively, this file may be used under the terms of the GNU Lesser
       
    18 ** General Public License version 2.1 as published by the Free Software
       
    19 ** Foundation and appearing in the file LICENSE.LGPL included in the
       
    20 ** packaging of this file.  Please review the following information to
       
    21 ** ensure the GNU Lesser General Public License version 2.1 requirements
       
    22 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
       
    23 **
       
    24 ** In addition, as a special exception, Nokia gives you certain additional
       
    25 ** rights.  These rights are described in the Nokia Qt LGPL Exception
       
    26 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
       
    27 **
       
    28 ** If you have questions regarding the use of this file, please contact
       
    29 ** Nokia at qt-info@nokia.com.
       
    30 **
       
    31 **
       
    32 **
       
    33 **
       
    34 **
       
    35 **
       
    36 **
       
    37 **
       
    38 ** $QT_END_LICENSE$
       
    39 **
       
    40 ****************************************************************************/
       
    41 
       
    42 #include <QtDebug>
       
    43 
       
    44 #include "qacceltreeresourceloader_p.h"
       
    45 #include "qnetworkaccessdelegator_p.h"
       
    46 
       
    47 #include "Global.h"
       
    48 #include "TestBaseLine.h"
       
    49 #include "TestGroup.h"
       
    50 
       
    51 #include "XSLTTestSuiteHandler.h"
       
    52 
       
    53 using namespace QPatternistSDK;
       
    54 
       
    55 extern QNetworkAccessManager s_networkManager;
       
    56 
       
    57 XSLTTestSuiteHandler::XSLTTestSuiteHandler(const QUrl &catalogFile) : m_ts(0)
       
    58                                                                     , m_tc(0)
       
    59                                                                     , m_baseLine(0)
       
    60                                                                     , m_catalogFile(catalogFile)
       
    61                                                                     , m_removeTestcase(false)
       
    62 {
       
    63     const QPatternist::NetworkAccessDelegator::Ptr networkDelegator(new QPatternist::NetworkAccessDelegator(&s_networkManager, &s_networkManager));
       
    64 
       
    65     m_resourceLoader = QPatternist::ResourceLoader::Ptr(new QPatternist::AccelTreeResourceLoader(Global::namePool(),
       
    66                                                                                                  networkDelegator));
       
    67     Q_ASSERT(!m_catalogFile.isRelative());
       
    68 }
       
    69 
       
    70 bool XSLTTestSuiteHandler::startElement(const QString &namespaceURI,
       
    71                                         const QString &localName,
       
    72                                         const QString &/*qName*/,
       
    73                                         const QXmlAttributes &atts)
       
    74     {
       
    75     if(namespaceURI != Global::xsltsCatalogNS)
       
    76         return true;
       
    77 
       
    78     /* The elements are handled roughly in the order of highest occurrence in the catalog file. */
       
    79     if(localName == QLatin1String("testcase"))
       
    80     {
       
    81         /* We pass m_ts temporarily, and change it later. */
       
    82         m_tc = new XQTSTestCase(TestCase::Standard, 0, QXmlQuery::XSLT20);
       
    83 
       
    84         m_currentQueryPath = m_queryOffset.resolved(QUrl(atts.value(QLatin1String("FilePath"))));
       
    85         m_currentBaselinePath = m_baselineOffset.resolved(QUrl(atts.value(QLatin1String("FilePath"))));
       
    86     }
       
    87     else if(localName == QLatin1String("stylesheet"))
       
    88         m_tc->setQueryPath(m_currentQueryPath.resolved(atts.value(QLatin1String("file"))));
       
    89     else if(localName == QLatin1String("error"))
       
    90     {
       
    91         m_baseLine = new TestBaseLine(TestBaseLine::ExpectedError);
       
    92         m_baseLine->setDetails(atts.value(QLatin1String("error-id")));
       
    93         m_tc->addBaseLine(m_baseLine);
       
    94     }
       
    95     else if(localName == QLatin1String("testcases"))
       
    96     {
       
    97         m_ts = new TestSuite();
       
    98         m_ts->setVersion(atts.value(QLatin1String("testSuiteVersion")));
       
    99 
       
   100         m_queryOffset           = m_catalogFile.resolved(atts.value(QLatin1String("InputOffsetPath")));
       
   101         m_baselineOffset        = m_catalogFile.resolved(atts.value(QLatin1String("ResultOffsetPath")));
       
   102         m_sourceOffset          = m_catalogFile.resolved(atts.value(QLatin1String("InputOffsetPath")));
       
   103     }
       
   104     else if(localName == QLatin1String("source-document"))
       
   105     {
       
   106         if(atts.value(QLatin1String("role")) == QLatin1String("principal"))
       
   107             m_tc->setContextItemSource(m_sourceOffset.resolved(QUrl(atts.value(QLatin1String("file")))));
       
   108     }
       
   109     else if(localName == QLatin1String("result-document"))
       
   110     {
       
   111         m_baseLine = new TestBaseLine(TestBaseLine::identifierFromString(atts.value(QLatin1String("type"))));
       
   112         m_baseLine->setDetails(m_currentBaselinePath.resolved(atts.value(QLatin1String("file"))).toString());
       
   113         m_tc->addBaseLine(m_baseLine);
       
   114     }
       
   115     else if(localName == QLatin1String("discretionary-feature"))
       
   116     {
       
   117         const QString feature(atts.value(QLatin1String("name")));
       
   118 
       
   119         m_removeTestcase = feature == QLatin1String("schema_aware") ||
       
   120                            feature == QLatin1String("namespace_axis") ||
       
   121                            feature == QLatin1String("disabling_output_escaping") ||
       
   122                            feature == QLatin1String("XML_1.1");
       
   123     }
       
   124     else if(localName == QLatin1String("discretionary-choice"))
       
   125     {
       
   126         m_baseLine = new TestBaseLine(TestBaseLine::ExpectedError);
       
   127         m_baseLine->setDetails(atts.value(QLatin1String("name")));
       
   128         m_tc->addBaseLine(m_baseLine);
       
   129         const QString feature(atts.value(QLatin1String("name")));
       
   130 
       
   131         m_removeTestcase = feature == QLatin1String("schema_aware") ||
       
   132                            feature == QLatin1String("namespace_axis") ||
       
   133                            feature == QLatin1String("disabling_output_escaping") ||
       
   134                            feature == QLatin1String("XML_1.1");
       
   135     }
       
   136     else if(localName == QLatin1String("entry-named-template"))
       
   137     {
       
   138         const QString name(atts.value(QLatin1String("qname")));
       
   139 
       
   140         if(!name.contains(QLatin1Char(':')))
       
   141         {
       
   142             // TODO do namespace processing
       
   143             const QXmlName complete(Global::namePool()->allocateQName(QString(), name));
       
   144 
       
   145             m_tc->setInitialTemplateName(complete);
       
   146         }
       
   147     }
       
   148 
       
   149     return true;
       
   150 }
       
   151 
       
   152 TestGroup *XSLTTestSuiteHandler::containerFor(const QString &name)
       
   153 {
       
   154     TestGroup *& c = m_containers[name];
       
   155 
       
   156     if(!c)
       
   157     {
       
   158         c = new TestGroup(m_ts);
       
   159         c->setTitle(name);
       
   160         Q_ASSERT(c);
       
   161         m_ts->appendChild(c);
       
   162     }
       
   163 
       
   164     return c;
       
   165 }
       
   166 
       
   167 bool XSLTTestSuiteHandler::endElement(const QString &namespaceURI,
       
   168                                       const QString &localName,
       
   169                                       const QString &/*qName*/)
       
   170 {
       
   171     if(namespaceURI != Global::xsltsCatalogNS)
       
   172         return true;
       
   173 
       
   174     /* The elements are handled roughly in the order of highest occurrence in the catalog file. */
       
   175     if(localName == QLatin1String("description"))
       
   176     {
       
   177         if(m_tc)
       
   178         {
       
   179             /* We're inside a <testcase>, so the <description> belongs
       
   180              * to the testcase. */
       
   181             m_tc->setDescription(m_ch.simplified());
       
   182         }
       
   183     }
       
   184     else if(localName == QLatin1String("testcase"))
       
   185     {
       
   186         Q_ASSERT(m_tc->baseLines().count() >= 1);
       
   187         Q_ASSERT(m_resourceLoader);
       
   188         // TODO can this be removed?
       
   189         m_tc->setExternalVariableLoader(QPatternist::ExternalVariableLoader::Ptr
       
   190                                                 (new ExternalSourceLoader(m_tcSourceInputs,
       
   191                                                                           m_resourceLoader)));
       
   192         m_tcSourceInputs.clear();
       
   193 
       
   194         if(!m_removeTestcase)
       
   195         {
       
   196             /*
       
   197             TestContainer *const container = containerFor(m_currentCategory);
       
   198             delete m_tc;
       
   199             container->removeLast();
       
   200             */
       
   201             TestContainer *const container = containerFor(m_currentCategory);
       
   202             m_tc->setParent(container);
       
   203             Q_ASSERT(m_tc);
       
   204             container->appendChild(m_tc);
       
   205         }
       
   206 
       
   207         m_tc = 0;
       
   208         m_removeTestcase = false;
       
   209     }
       
   210     else if(localName == QLatin1String("name"))
       
   211         m_tc->setName(m_ch);
       
   212     else if(localName == QLatin1String("creator"))
       
   213         m_tc->setCreator(m_ch);
       
   214     else if(localName == QLatin1String("contextItem"))
       
   215         m_contextItemSource = m_ch;
       
   216     else if(localName == QLatin1String("category"))
       
   217         m_currentCategory = m_ch;
       
   218 
       
   219     return true;
       
   220 }
       
   221 
       
   222 bool XSLTTestSuiteHandler::characters(const QString &ch)
       
   223 {
       
   224     m_ch = ch;
       
   225     return true;
       
   226 }
       
   227 
       
   228 TestSuite *XSLTTestSuiteHandler::testSuite() const
       
   229 {
       
   230     return m_ts;
       
   231 }
       
   232 
       
   233 // vim: et:ts=4:sw=4:sts=4
       
   234