1 /****************************************************************************
3 ** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
4 ** All rights reserved.
5 ** Contact: Nokia Corporation (qt-info@nokia.com)
7 ** This file is part of the test suite of the Qt Toolkit.
9 ** $QT_BEGIN_LICENSE:LGPL$
10 ** GNU Lesser General Public License Usage
11 ** This file may be used under the terms of the GNU Lesser General Public
12 ** License version 2.1 as published by the Free Software Foundation and
13 ** appearing in the file LICENSE.LGPL included in the packaging of this
14 ** file. Please review the following information to ensure the GNU Lesser
15 ** General Public License version 2.1 requirements will be met:
16 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
18 ** In addition, as a special exception, Nokia gives you certain additional
19 ** rights. These rights are described in the Nokia Qt LGPL Exception
20 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
22 ** GNU General Public License Usage
23 ** Alternatively, this file may be used under the terms of the GNU General
24 ** Public License version 3.0 as published by the Free Software Foundation
25 ** and appearing in the file LICENSE.GPL included in the packaging of this
26 ** file. Please review the following information to ensure the GNU General
27 ** Public License version 3.0 requirements will be met:
28 ** http://www.gnu.org/copyleft/gpl.html.
31 ** Alternatively, this file may be used in accordance with the terms and
32 ** conditions contained in a signed written agreement between you and Nokia.
40 ****************************************************************************/
48 #include "XQTSTestCase.h"
50 using namespace QPatternistSDK;
51 using namespace QPatternist;
53 XQTSTestCase::XQTSTestCase(const Scenario scen,
55 const QXmlQuery::QueryLanguage lang) : m_isXPath(false)
62 XQTSTestCase::~XQTSTestCase()
64 qDeleteAll(m_baseLines);
67 QVariant XQTSTestCase::data(const Qt::ItemDataRole role, int column) const
69 if(role == Qt::DisplayRole)
74 const TestResult *const tr = testResult();
78 return TestResult::displayName(TestResult::NotTested);
82 const TestResult::Status status = tr->status();
87 return status == TestResult::Pass ? QString(QChar::fromLatin1('1'))
88 : QString(QChar::fromLatin1('0'));
90 return status == TestResult::Fail ? QString(QChar::fromLatin1('1'))
91 : QString(QChar::fromLatin1('0'));
97 if(role != Qt::BackgroundRole)
100 const TestResult *const tr = testResult();
110 const TestResult::Status status = tr->status();
112 if(status == TestResult::NotTested || status == TestResult::Unknown)
118 return status == TestResult::Pass ? Qt::green : QVariant();
120 return status == TestResult::Fail ? Qt::red : QVariant();
126 QString XQTSTestCase::sourceCode(bool &ok) const
128 QFile file(m_queryPath.toLocalFile());
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());
140 if(err.isNull()) /* No errors. */
143 /* Scary, we assume the query is stored in UTF-8. */
144 return QString::fromUtf8(file.readAll());
153 int XQTSTestCase::columnCount() const
158 void XQTSTestCase::addBaseLine(TestBaseLine *line)
160 m_baseLines.append(line);
163 QString XQTSTestCase::name() const
168 QString XQTSTestCase::creator() const
173 QString XQTSTestCase::description() const
175 return m_description;
178 QDate XQTSTestCase::lastModified() const
180 return m_lastModified;
183 bool XQTSTestCase::isXPath() const
188 TestCase::Scenario XQTSTestCase::scenario() const
193 void XQTSTestCase::setName(const QString &n)
198 void XQTSTestCase::setCreator(const QString &ctor)
203 void XQTSTestCase::setDescription(const QString &descriptionP)
205 m_description = descriptionP;
208 void XQTSTestCase::setLastModified(const QDate &date)
210 m_lastModified = date;
213 void XQTSTestCase::setIsXPath(const bool isXPathP)
215 m_isXPath = isXPathP;
218 void XQTSTestCase::setQueryPath(const QUrl &uri)
223 TreeItem *XQTSTestCase::parent() const
228 QString XQTSTestCase::title() const
233 TestBaseLine::List XQTSTestCase::baseLines() const
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())));
240 QUrl XQTSTestCase::testCasePath() const
245 void XQTSTestCase::setExternalVariableLoader(const QPatternist::ExternalVariableLoader::Ptr &loader)
247 m_externalVariableLoader = loader;
250 QPatternist::ExternalVariableLoader::Ptr XQTSTestCase::externalVariableLoader() const
252 return m_externalVariableLoader;
255 void XQTSTestCase::setContextItemSource(const QUrl &uri)
257 m_contextItemSource = uri;
260 QUrl XQTSTestCase::contextItemSource() const
262 return m_contextItemSource;
265 QXmlQuery::QueryLanguage XQTSTestCase::language() const
270 void XQTSTestCase::setParent(TreeItem *const p)
275 void XQTSTestCase::setInitialTemplateName(const QXmlName &name)
277 m_initialTemplateName = name;
280 QXmlName XQTSTestCase::initialTemplateName() const
282 return m_initialTemplateName;
285 // vim: et:ts=4:sw=4:sts=4