Members of the KDE Community are recommended to subscribe to the kde-community mailing list at https://mail.kde.org/mailman/listinfo/kde-community to allow them to participate in important discussions and receive other important announcements

Commit fe677a7b authored by Manuel Breugelmans's avatar Manuel Breugelmans

Add testcase, testcommand and register from veritas. Adapt includes, namespace usage and tests.

parent 8b2d269a
......@@ -26,6 +26,8 @@ include_directories(
${KDEVPLATFORM_INCLUDE_DIR}/veritas/interfaces)
set(kdevcheck_SRCS
../cppunit/testcase.cpp
../cppunit/testcommand.cpp
outputparser.cpp
testsuite.cpp
testroot.cpp)
......
......@@ -31,7 +31,7 @@
#include <projectmodel.h>
#include <core.h>
#include <test.h>
#include <register.h>
#include "plugins/xtest/cppunit/register.h"
#include <QFile>
#include <KDebug>
#include <KConfigGroup>
......@@ -44,7 +44,6 @@ using KDevelop::IProject;
using KDevelop::IProjectController;
using Veritas::Test;
using Veritas::Register;
using Veritas::TestRunnerToolView;
using Check::TestRoot;
......
......@@ -21,7 +21,7 @@
#include "outputparser.h"
#include "testsuite.h"
#include "testroot.h"
#include <testcase.h>
#include "plugins/xtest/cppunit/testcase.h"
#include <QStringRef>
#include <KDebug>
......
......@@ -25,7 +25,7 @@
#include <ui_statuswidget.h>
#include <runnerwindow.h>
#include <runnermodel.h>
#include <register.h>
#include "plugins/xtest/cppunit/register.h"
#include <KDebug>
#include <QBuffer>
......@@ -39,7 +39,6 @@
using Veritas::RunnerWindow;
using Veritas::RunnerModel;
using Veritas::Register;
using Check::TestSuite;
using Check::TestRoot;
using Check::it::CheckRunnerTest;
......
......@@ -25,7 +25,6 @@
using Check::TestSuite;
using Check::OutputParser;
using Veritas::TestCase;
using Veritas::Test;
TestSuite::TestSuite(const QString& name, const QFileInfo& exe, Test* parent)
......
......@@ -26,7 +26,8 @@
#include <KProcess>
#include <test.h>
#include <testcase.h>
#include "plugins/xtest/cppunit/testcase.h"
namespace Check
{
......@@ -40,7 +41,7 @@ public:
*/
TestSuite(const QString&, const QFileInfo&, Veritas::Test*);
virtual ~TestSuite();
Veritas::TestCase* child(int i) const;
TestCase* child(int i) const;
private:
QFileInfo m_exe;
......
......@@ -26,6 +26,8 @@ include_directories(
${KDEVPLATFORM_INCLUDE_DIR}/veritas/interfaces)
set(kdevcppunit_SRCS
testcommand.cpp
testcase.cpp
testsuite.cpp
testroot.cpp
outputparser.cpp)
......
......@@ -31,7 +31,7 @@
#include <projectmodel.h>
#include <core.h>
#include <test.h>
#include <register.h>
#include "register.h"
#include <QFile>
#include <KConfigGroup>
......@@ -45,7 +45,6 @@ using KDevelop::IProject;
using KDevelop::IProjectController;
using Veritas::Test;
using Veritas::TestRunnerToolView;
using Veritas::Register;
using CppUnit::TestRoot;
using CppUnit::TestSuite;
......
......@@ -21,13 +21,12 @@
#include "outputparser.h"
#include "testroot.h"
#include <test.h>
#include <testcase.h>
#include "testcase.h"
#include <QStringRef>
#include <KDebug>
using Veritas::Test;
using Veritas::TestResult;
using Veritas::TestCase;
using CppUnit::TestRoot;
using CppUnit::OutputParser;
......
/*
* This file is part of KDevelop
* Copyright 2008 Manuel Breugelmans <mbr.nxi@gmail.com>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
* 02110-1301, USA.
*/
#ifndef CPPUNIT_TESTREGISTER_H
#define CPPUNIT_TESTREGISTER_H
#include <QtCore/QString>
#include <QtCore/QFileInfo>
#include <QtXml/QXmlStreamReader>
#include <test.h>
#include "testcase.h"
class KProcess;
class QIODevice;
/*!
* This class removes bad duplication between the Check
* & CppUnit plugins. It might be completely irrelevant for
* other frameworks.
*/
template<typename R, typename S>
class Register : public QXmlStreamReader
{
public:
typedef R TestRoot;
typedef S TestSuite;
Register();
virtual ~Register();
void addFromXml(QIODevice*);
void addFromExe(const QFileInfo& exe);
TestRoot* rootItem();
void setRootDir(const QString& root);
void setExecutable(const QFileInfo& exe);
private: // helpers
void execute(KProcess*);
bool isStartElement_(const QString& elem);
bool isEndElement_(const QString& elem);
void processSuite();
void processCase(TestSuite* suite);
void processCmd(TestCase* caze);
QString fetchName();
QFileInfo fetchDir();
QFileInfo fetchExe();
private: // state
TestRoot* m_rootItem;
QString m_root;
QFileInfo m_exe;
private: // some xml constants
const QString c_suite;
const QString c_case;
const QString c_cmd;
const QString c_name;
};
///// template implementation
#include <KDebug>
#include <KProcess>
#include <KLocalizedString>
template<typename R, typename S>
Register<R,S>::Register()
: m_root(""),
c_suite("suite"),
c_case("case"),
c_cmd("command"),
c_name("name")
{}
template<typename R, typename S>
Register<R,S>::~Register()
{}
template<typename R, typename S>
R* Register<R,S>::rootItem()
{
return m_rootItem;
}
template<typename R, typename S>
bool Register<R,S>::isStartElement_(const QString& elem)
{
return isStartElement() && (name() == elem);
}
template<typename R, typename S>
bool Register<R,S>::isEndElement_(const QString& elem)
{
return isEndElement() && (name() == elem);
}
template<typename R, typename S>
void Register<R,S>::addFromExe(const QFileInfo& exe)
{
KProcess* proc = new KProcess;
setExecutable(exe);
execute(proc);
addFromXml(proc);
}
template<typename R, typename S>
void Register<R,S>::execute(KProcess* proc)
{
QStringList argv;
argv << "-proto";
proc->setProgram(m_exe.filePath(), argv);
kDebug() << "executing " << proc->program();
proc->setOutputChannelMode(KProcess::SeparateChannels);
proc->start();
proc->waitForFinished(-1);
}
template<typename R, typename S>
void Register<R,S>::addFromXml(QIODevice* dev)
{
// Data for column headers is stored in the root item.
QList<QVariant> rootData;
rootData << i18n("Test Name") << i18n("Result") << i18n("Message")
<< i18n("File Name") << i18n("Line Number");
m_rootItem = new TestRoot(rootData);
Q_ASSERT(dev != 0);
setDevice(dev);
if (!device()->isOpen())
device()->open(QIODevice::ReadOnly);
while (!atEnd()) {
readNext();
if (isStartElement_(c_suite))
processSuite();
}
kError(hasError()) << errorString() << " @ " << lineNumber() << ":" << columnNumber();
}
template<typename R, typename S>
void Register<R,S>::processSuite()
{
TestSuite* suite = new TestSuite(fetchName(), m_exe, m_rootItem);
m_rootItem->addChild(suite);
kDebug() << suite->name();
while (!atEnd() && !isEndElement_(c_suite)) {
readNext();
if (isStartElement_(c_case))
processCase(suite);
}
}
template<typename R, typename S>
void Register<R,S>::processCase(TestSuite* suite)
{
TestCase* caze = new TestCase(fetchName(), suite);
suite->addChild(caze);
kDebug() << caze->name();
while (!atEnd() && !isEndElement_(c_case)) {
readNext();
if (isStartElement_(c_cmd))
processCmd(caze);
}
}
template<typename R, typename S>
void Register<R,S>::setExecutable(const QFileInfo& exe)
{
m_exe = exe;
}
template<typename R, typename S>
void Register<R,S>::processCmd(TestCase* caze)
{
TestCommand* cmd = new TestCommand(fetchName(), caze);
caze->addChild(cmd);
kDebug() << cmd->name();
}
template<typename R, typename S>
QString Register<R,S>::fetchName()
{
return attributes().value(c_name).toString();
}
#endif // CPPUNIT_REGISTER_H
/*
* This file is part of KDevelop
* Copyright 2008 Manuel Breugelmans <mbr.nxi@gmail.com>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
* 02110-1301, USA.
*/
#include "testcase.h"
using Veritas::Test;
TestCase::TestCase(const QString& name, Test* parent)
: Test(name, parent)
{}
TestCase::~TestCase()
{}
TestCommand* TestCase::child(int i) const
{
return static_cast<TestCommand*>(Test::child(i));
}
#include "testcase.moc"
/*
* This file is part of KDevelop
* Copyright 2008 Manuel Breugelmans <mbr.nxi@gmail.com>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
* 02110-1301, USA.
*/
#ifndef TESTCASE_H
#define TESTCASE_H
#include <test.h>
#include "testcommand.h"
#include <QtCore/QString>
/*!
* This class removes bad duplication between the Check
* & CppUnit plugins. It might be completely irrelevant for
* other frameworks.
*/
class TestCase : public Veritas::Test
{
Q_OBJECT
public:
TestCase(const QString& name, Veritas::Test* parent);
virtual ~TestCase();
TestCommand* child(int i) const;
};
#endif // TESTCASE_H
/*
* This file is part of KDevelop
* Copyright 2008 Manuel Breugelmans <mbr.nxi@gmail.com>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
* 02110-1301, USA.
*/
#include "testcommand.h"
using Veritas::Test;
TestCommand::TestCommand(const QString& name, Test* parent)
: Test(name, parent)
{}
TestCommand::~TestCommand()
{}
#include "testcommand.moc"
/*
* This file is part of KDevelop
* Copyright 2008 Manuel Breugelmans <mbr.nxi@gmail.com>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
* 02110-1301, USA.
*/
#ifndef TESTCOMMAND_H
#define TESTCOMMAND_H
#include <test.h>
#include <QtCore/QString>
/*!
* This class removes bad duplication between the Check
* & CppUnit plugins. It might be completely irrelevant for
* other frameworks.
*/
class VERITAS_EXPORT TestCommand : public Veritas::Test
{
Q_OBJECT
public:
TestCommand(const QString& name, Veritas::Test* parent);
virtual ~TestCommand();
};
#endif // TESTCOMMAND_H
......@@ -26,7 +26,7 @@
#include <runnerwindow.h>
#include <runnermodel.h>
#include <testresult.h>
#include <register.h>
#include "register.h"
#include <KDebug>
#include <QBuffer>
......@@ -40,7 +40,6 @@
using Veritas::RunnerWindow;
using Veritas::RunnerModel;
using Veritas::Register;
using Veritas::Test;
using CppUnit::TestSuite;
using CppUnit::TestRoot;
......
......@@ -24,7 +24,6 @@
using CppUnit::TestSuite;
using CppUnit::OutputParser;
using Veritas::TestCase;
using Veritas::Test;
TestSuite::TestSuite()
......@@ -43,23 +42,4 @@ TestCase* TestSuite::child(int i) const
return static_cast<TestCase*>(Test::child(i));
}
// bool TestSuite::shouldRun() const
// {
// return true;
// }
//
// int TestSuite::run()
// {
// KProcess proc;
// QStringList argv;
// proc.setProgram(m_exe.filePath(), argv);
// kDebug() << "executing " << proc.program();
// proc.setOutputChannelMode(KProcess::SeparateChannels);
// proc.start();
// proc.waitForFinished(-1);
// OutputParser parser(&proc);
// parser.go(this);
// return 0;
// }
#include "testsuite.moc"
......@@ -25,7 +25,8 @@
#include <QFileInfo>
#include <KProcess>
#include <test.h>
#include <testcase.h>
#include "testcase.h"
namespace CppUnit
{
......@@ -37,9 +38,7 @@ public:
TestSuite();
TestSuite(const QString&, const QFileInfo& executable, Veritas::Test* parent);
virtual ~TestSuite();
Veritas::TestCase* child(int i) const;
// int run();
// bool shouldRun() const;
TestCase* child(int i) const;
private:
QFileInfo m_exe;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment