tests/auto/xmlpatternssdk/XQTSTestCase.cpp
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 #include <QColor>
       
    43 #include <QFile>
       
    44 #include <QFileInfo>
       
    45 #include <QVariant>
       
    46 #include <QtDebug>
       
    47 
       
    48 #include "XQTSTestCase.h"
       
    49 
       
    50 using namespace QPatternistSDK;
       
    51 using namespace QPatternist;
       
    52 
       
    53 XQTSTestCase::XQTSTestCase(const Scenario scen,
       
    54                            TreeItem *p,
       
    55                            const QXmlQuery::QueryLanguage lang) : m_isXPath(false)
       
    56                                                                 , m_scenario(scen)
       
    57                                                                 , m_parent(p)
       
    58                                                                 , m_lang(lang)
       
    59 {
       
    60 }
       
    61 
       
    62 XQTSTestCase::~XQTSTestCase()
       
    63 {
       
    64     qDeleteAll(m_baseLines);
       
    65 }
       
    66 
       
    67 QVariant XQTSTestCase::data(const Qt::ItemDataRole role, int column) const
       
    68 {
       
    69     if(role == Qt::DisplayRole)
       
    70     {
       
    71         if(column == 0)
       
    72             return title();
       
    73 
       
    74         const TestResult *const tr = testResult();
       
    75         if(!tr)
       
    76         {
       
    77             if(column == 1)
       
    78                 return TestResult::displayName(TestResult::NotTested);
       
    79             else
       
    80                 return QString();
       
    81         }
       
    82         const TestResult::Status status = tr->status();
       
    83 
       
    84         switch(column)
       
    85         {
       
    86             case 1:
       
    87                 return status == TestResult::Pass ? QString(QChar::fromLatin1('1'))
       
    88                                                   : QString(QChar::fromLatin1('0'));
       
    89             case 2:
       
    90                 return status == TestResult::Fail ? QString(QChar::fromLatin1('1'))
       
    91                                                   : QString(QChar::fromLatin1('0'));
       
    92             default:
       
    93                 return QString();
       
    94         }
       
    95     }
       
    96 
       
    97     if(role != Qt::BackgroundRole)
       
    98         return QVariant();
       
    99 
       
   100     const TestResult *const tr = testResult();
       
   101 
       
   102     if(!tr)
       
   103     {
       
   104         if(column == 0)
       
   105             return Qt::yellow;
       
   106         else
       
   107             return QVariant();
       
   108     }
       
   109 
       
   110     const TestResult::Status status = tr->status();
       
   111 
       
   112     if(status == TestResult::NotTested || status == TestResult::Unknown)
       
   113         return Qt::yellow;
       
   114 
       
   115     switch(column)
       
   116     {
       
   117         case 1:
       
   118             return status == TestResult::Pass ? Qt::green : QVariant();
       
   119         case 2:
       
   120             return status == TestResult::Fail ? Qt::red : QVariant();
       
   121         default:
       
   122             return QVariant();
       
   123     }
       
   124 }
       
   125 
       
   126 QString XQTSTestCase::sourceCode(bool &ok) const
       
   127 {
       
   128     QFile file(m_queryPath.toLocalFile());
       
   129 
       
   130     QString err;
       
   131 
       
   132     if(!file.exists())
       
   133         err = QString::fromLatin1("Error: %1 does not exist.").arg(file.fileName());
       
   134     else if(!QFileInfo(file.fileName()).isFile())
       
   135         err = QString::fromLatin1("Error: %1 is not a file, cannot display it.").arg(file.fileName());
       
   136     else if(!file.open(QIODevice::ReadOnly))
       
   137         err = QString::fromLatin1("Error: Could not open %1. Likely a permission error.")
       
   138                                   .arg(file.fileName());
       
   139 
       
   140     if(err.isNull()) /* No errors. */
       
   141     {
       
   142         ok = true;
       
   143         /* Scary, we assume the query is stored in UTF-8. */
       
   144         return QString::fromUtf8(file.readAll());
       
   145     }
       
   146     else
       
   147     {
       
   148         ok = false;
       
   149         return err;
       
   150     }
       
   151 }
       
   152 
       
   153 int XQTSTestCase::columnCount() const
       
   154 {
       
   155     return 2;
       
   156 }
       
   157 
       
   158 void XQTSTestCase::addBaseLine(TestBaseLine *line)
       
   159 {
       
   160     m_baseLines.append(line);
       
   161 }
       
   162 
       
   163 QString XQTSTestCase::name() const
       
   164 {
       
   165     return m_name;
       
   166 }
       
   167 
       
   168 QString XQTSTestCase::creator() const
       
   169 {
       
   170     return m_creator;
       
   171 }
       
   172 
       
   173 QString XQTSTestCase::description() const
       
   174 {
       
   175     return m_description;
       
   176 }
       
   177 
       
   178 QDate XQTSTestCase::lastModified() const
       
   179 {
       
   180     return m_lastModified;
       
   181 }
       
   182 
       
   183 bool XQTSTestCase::isXPath() const
       
   184 {
       
   185     return m_isXPath;
       
   186 }
       
   187 
       
   188 TestCase::Scenario XQTSTestCase::scenario() const
       
   189 {
       
   190     return m_scenario;
       
   191 }
       
   192 
       
   193 void XQTSTestCase::setName(const QString &n)
       
   194 {
       
   195     m_name = n;
       
   196 }
       
   197 
       
   198 void XQTSTestCase::setCreator(const QString &ctor)
       
   199 {
       
   200     m_creator = ctor;
       
   201 }
       
   202 
       
   203 void XQTSTestCase::setDescription(const QString &descriptionP)
       
   204 {
       
   205     m_description = descriptionP;
       
   206 }
       
   207 
       
   208 void XQTSTestCase::setLastModified(const QDate &date)
       
   209 {
       
   210     m_lastModified = date;
       
   211 }
       
   212 
       
   213 void XQTSTestCase::setIsXPath(const bool isXPathP)
       
   214 {
       
   215     m_isXPath = isXPathP;
       
   216 }
       
   217 
       
   218 void XQTSTestCase::setQueryPath(const QUrl &uri)
       
   219 {
       
   220     m_queryPath = uri;
       
   221 }
       
   222 
       
   223 TreeItem *XQTSTestCase::parent() const
       
   224 {
       
   225     return m_parent;
       
   226 }
       
   227 
       
   228 QString XQTSTestCase::title() const
       
   229 {
       
   230     return m_name;
       
   231 }
       
   232 
       
   233 TestBaseLine::List XQTSTestCase::baseLines() const
       
   234 {
       
   235     Q_ASSERT_X(!m_baseLines.isEmpty(), Q_FUNC_INFO,
       
   236                qPrintable(QString::fromLatin1("The test %1 has no base lines, it should have at least one.").arg(name())));
       
   237     return m_baseLines;
       
   238 }
       
   239 
       
   240 QUrl XQTSTestCase::testCasePath() const
       
   241 {
       
   242     return m_queryPath;
       
   243 }
       
   244 
       
   245 void XQTSTestCase::setExternalVariableLoader(const QPatternist::ExternalVariableLoader::Ptr &loader)
       
   246 {
       
   247     m_externalVariableLoader = loader;
       
   248 }
       
   249 
       
   250 QPatternist::ExternalVariableLoader::Ptr XQTSTestCase::externalVariableLoader() const
       
   251 {
       
   252     return m_externalVariableLoader;
       
   253 }
       
   254 
       
   255 void XQTSTestCase::setContextItemSource(const QUrl &uri)
       
   256 {
       
   257     m_contextItemSource = uri;
       
   258 }
       
   259 
       
   260 QUrl XQTSTestCase::contextItemSource() const
       
   261 {
       
   262     return m_contextItemSource;
       
   263 }
       
   264 
       
   265 QXmlQuery::QueryLanguage XQTSTestCase::language() const
       
   266 {
       
   267     return m_lang;
       
   268 }
       
   269 
       
   270 void XQTSTestCase::setParent(TreeItem *const p)
       
   271 {
       
   272     m_parent = p;
       
   273 }
       
   274 
       
   275 void XQTSTestCase::setInitialTemplateName(const QXmlName &name)
       
   276 {
       
   277     m_initialTemplateName = name;
       
   278 }
       
   279 
       
   280 QXmlName XQTSTestCase::initialTemplateName() const
       
   281 {
       
   282     return m_initialTemplateName;
       
   283 }
       
   284 
       
   285 // vim: et:ts=4:sw=4:sts=4
       
   286