tests/auto/xmlpatternssdk/TestCase.h
branchRCL_3
changeset 8 3f74d0d4af4c
equal deleted inserted replaced
6:dee5afe5301f 8:3f74d0d4af4c
       
     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 #ifndef PatternistSDK_TestCase_H
       
    43 #define PatternistSDK_TestCase_H
       
    44 
       
    45 #include <QtXmlPatterns/QXmlQuery>
       
    46 
       
    47 #include "qexternalvariableloader_p.h"
       
    48 
       
    49 #include "ErrorHandler.h"
       
    50 #include "TestBaseLine.h"
       
    51 #include "Global.h"
       
    52 
       
    53 #include "TestItem.h"
       
    54 
       
    55 QT_BEGIN_HEADER
       
    56 
       
    57 QT_BEGIN_NAMESPACE
       
    58 
       
    59 class QDate;
       
    60 class QString;
       
    61 class QUrl;
       
    62 
       
    63 namespace QPatternistSDK
       
    64 {
       
    65     class XMLWriter;
       
    66 
       
    67     /**
       
    68      * @short A generic abstract base class for test cases.
       
    69      *
       
    70      * @ingroup PatternistSDK
       
    71      * @author Frans Englich <frans.englich@nokia.com>
       
    72      */
       
    73     class Q_PATTERNISTSDK_EXPORT TestCase : public TestItem
       
    74     {
       
    75     public:
       
    76         /**
       
    77          * Corresponds to the simpleType test:scenarios-enum
       
    78          */
       
    79         enum Scenario
       
    80         {
       
    81             /**
       
    82              * The test case should evaluate normally and that the output
       
    83              * should match the supplied base line.
       
    84              */
       
    85             Standard        = 1,
       
    86 
       
    87             /**
       
    88              * The test case should result in a static error, a parser error.
       
    89              */
       
    90             ParseError      = 2,
       
    91 
       
    92             /**
       
    93              * The test case should result in a dynamic error, a runtime error.
       
    94              */
       
    95             RuntimeError    = 4,
       
    96 
       
    97             Trivial         = 8,
       
    98 
       
    99             /**
       
   100              * ParseError and RuntimeError OR'd.
       
   101              */
       
   102             AnyError        = RuntimeError | ParseError
       
   103 
       
   104         };
       
   105 
       
   106         TestCase();
       
   107         virtual ~TestCase();
       
   108 
       
   109         /**
       
   110          * Executes the test, and returns the result. The returned list
       
   111          * will always contain exactly one TestResult.
       
   112          *
       
   113          * @p stage is ignored when running out-of-process.
       
   114          */
       
   115         virtual TestResult::List execute(const ExecutionStage stage,
       
   116                                          TestSuite *ts);
       
   117 
       
   118         /**
       
   119          * Determines the corresponding Scenario enumerator from the string
       
   120          * representation @p string.
       
   121          *
       
   122          * The following mappings are in effect:
       
   123          * @arg @c Standard "standard"
       
   124          * @arg @c ParseError "parse-error"
       
   125          * @arg @c RuntimeError "runtime-error"
       
   126          */
       
   127         static Scenario scenarioFromString(const QString &string);
       
   128 
       
   129         /**
       
   130          * @return always @c true
       
   131          */
       
   132         virtual bool isFinalNode() const;
       
   133 
       
   134         /**
       
   135          * Calling this function makes no sense, so it always
       
   136          * performs an Q_ASSERT check.
       
   137          */
       
   138         virtual void appendChild(TreeItem *);
       
   139 
       
   140         /**
       
   141          * Calling this function makes no sense, so it always
       
   142          * performs an Q_ASSERT check.
       
   143          */
       
   144         virtual TreeItem *child(const unsigned int) const;
       
   145 
       
   146         /**
       
   147          * @return always zero
       
   148          */
       
   149         virtual unsigned int childCount() const;
       
   150 
       
   151         /**
       
   152          * @return always an empty list.
       
   153          */
       
   154         virtual TreeItem::List children() const;
       
   155 
       
   156         /**
       
   157          * A description of the test case for human consumption.
       
   158          */
       
   159         virtual QString description() const = 0;
       
   160 
       
   161         /**
       
   162          * The title of the test. This can be the identifier of the test, for example.
       
   163          */
       
   164         virtual QString title() const = 0;
       
   165 
       
   166         /**
       
   167          * Whether this test case only make use of XPath features.
       
   168          *
       
   169          * @returns @c false if the test case exercises any XQuery feature
       
   170          * which is not available in XPath 2.0.
       
   171          */
       
   172         virtual bool isXPath() const = 0;
       
   173 
       
   174         /**
       
   175          * The full name of the creator of the test case. For example, "Frans Englich".
       
   176          */
       
   177         virtual QString creator() const = 0;
       
   178 
       
   179         /**
       
   180          * The date of when the test case was created or last modified.
       
   181          */
       
   182         virtual QDate lastModified() const = 0;
       
   183 
       
   184         /**
       
   185          * The test's source code. That is, the XPath/XQuery code for the test.
       
   186          *
       
   187          * @param ok the function sets this value to @c false if loading the query
       
   188          * failed, and returns a description of the error for human consumption. If
       
   189          * everything went ok, @p ok is set to @c true, and the query is returned.
       
   190          */
       
   191         virtual QString sourceCode(bool &ok) const = 0;
       
   192 
       
   193         /**
       
   194          * The path to the file containing the code of the test case.
       
   195          */
       
   196         virtual QUrl testCasePath() const = 0;
       
   197 
       
   198         /**
       
   199          * The test case's identifier. For example, "Literals001".
       
   200          */
       
   201         virtual QString name() const = 0;
       
   202 
       
   203         /**
       
   204          * What kind of test this is. For example, whether the test case
       
   205          * should result in a parser error or should evaluate without errors.
       
   206          *
       
   207          * The vast common case is that one Scenario is returned; the bit signifiance
       
   208          * is for the TestCase sub-class UserTestCase.
       
   209          */
       
   210         virtual Scenario scenario() const = 0;
       
   211 
       
   212         static QString displayName(const Scenario scen);
       
   213 
       
   214         /**
       
   215          * @returns the valid test baselines for this test case. If only
       
   216          * one outcome is valid, the returned list only contains
       
   217          * that baseline.
       
   218          */
       
   219         virtual TestBaseLine::List baseLines() const = 0;
       
   220 
       
   221         virtual TestResult *testResult() const;
       
   222 
       
   223         virtual ResultSummary resultSummary() const;
       
   224 
       
   225         void toXML(XMLWriter &receiver) const;
       
   226 
       
   227         virtual QPatternist::ExternalVariableLoader::Ptr externalVariableLoader() const = 0;
       
   228 
       
   229         /**
       
   230          * @short The XML document that should be used as focus. If none should
       
   231          * be used, and hence the focus be undefined, a default constructed
       
   232          * QUrl is returned.
       
   233          */
       
   234         virtual QUrl contextItemSource() const = 0;
       
   235 
       
   236         /**
       
   237          * Returns by default QXmlQuery::XQuery10.
       
   238          */
       
   239         virtual QXmlQuery::QueryLanguage language() const;
       
   240 
       
   241         virtual QXmlName initialTemplateName() const;
       
   242     private:
       
   243         TestResult::List execute(const ExecutionStage stage);
       
   244         TestResult *createTestResult(const TestResult::Status status,
       
   245                                            const QString &comment) const;
       
   246 
       
   247         QPointer<TestResult>    m_result;
       
   248     };
       
   249 }
       
   250 
       
   251 QT_END_NAMESPACE
       
   252 
       
   253 QT_END_HEADER
       
   254 
       
   255 #endif
       
   256 // vim: et:ts=4:sw=4:sts=4