diff options
author | Bernhard Sessler <bernhard@burnsen.de> | 2013-12-22 15:00:25 +0100 |
---|---|---|
committer | Markus Mohrhard <markus.mohrhard@googlemail.com> | 2014-01-06 16:36:20 +0000 |
commit | 3383bdf9639914bf85dfac4af9a32b18d62abbbc (patch) | |
tree | f4867d38a6980d6311bfbe7548bd4e4b7595565c | |
parent | f8cd3430163bde5e8ade2a2245437710b2ec048d (diff) | |
download | cppunit-3383bdf9639914bf85dfac4af9a32b18d62abbbc.tar.gz |
src/qttestrunner: Port Qt test runner to Qt4 / Qt5
The codebase was (almost) completely recreated from scratch. The test
runner now builds and runs with both Qt5 and Qt4 (>= 4.7.x).
The qmake project file shipped with the old qt test runner was
updated and can be used to build the library.
Change-Id: Iaf8e773566189113fd45029240d3e3ebeaa60e50
Signed-off-by: Bernhard Sessler <bernhard@burnsen.de>
Reviewed-on: https://gerrit.libreoffice.org/7182
Reviewed-by: Markus Mohrhard <markus.mohrhard@googlemail.com>
Tested-by: Markus Mohrhard <markus.mohrhard@googlemail.com>
45 files changed, 1541 insertions, 2594 deletions
diff --git a/include/cppunit/ui/qt/QtTestRunner.h b/include/cppunit/ui/qt/QtTestRunner.h index 4b6ab4e..169b91e 100644 --- a/include/cppunit/ui/qt/QtTestRunner.h +++ b/include/cppunit/ui/qt/QtTestRunner.h @@ -1,85 +1,69 @@ -// ////////////////////////////////////////////////////////////////////////// -// Header file TestRunner.h for class TestRunner -// (c)Copyright 2000, Baptiste Lepilleur. -// Created: 2001/09/19 -// ////////////////////////////////////////////////////////////////////////// -#ifndef CPPUNIT_QTUI_QTTESTRUNNER_H -#define CPPUNIT_QTUI_QTTESTRUNNER_H +#ifndef CPPUNIT_QTTESTRUNNER_H +#define CPPUNIT_QTTESTRUNNER_H -#include <cppunit/portability/CppUnitVector.h> -#include "Config.h" - -CPPUNIT_NS_BEGIN +#include <QScopedPointer> +#include <cppunit/Portability.h> +#include <cppunit/ui/qt/Config.h> - class Test; - class TestSuite; +CPPUNIT_NS_BEGIN +class Test; -/*! - * \brief QT test runner. +/*! + * \brief Qt test runner. * \ingroup ExecutingTest * + * This test runner uses the Qt GUI framework for running and displaying registered tests. + * * Here is an example of usage: * \code * #include <cppunit/extensions/TestFactoryRegistry.h> * #include <cppunit/ui/qt/TestRunner.h> * - * [...] - * - * void - * QDepWindow::runTests() + * void main(int argc, char*argv[]) * { - * CppUnit::QtUi::TestRunner runner; - * runner.addTest( CppUnit::TestFactoryRegistry::getRegistry().makeTest() ); - * runner.run( true ); + * QApplication app(argc, argv); + * + * CppUnit::QtTestRunner runner; + * runner.addTest(CppUnit::TestFactoryRegistry::getRegistry().makeTest()); + * runner.run(true); + * + * return app.exec(); * } * \endcode - * */ class QTTESTRUNNER_API QtTestRunner { -public: - /*! Constructs a TestRunner object. - */ - QtTestRunner(); - - /*! Destructor. - */ - virtual ~QtTestRunner(); - - void run( bool autoRun =false ); + Q_DISABLE_COPY(QtTestRunner) - void addTest( Test *test ); +public: + /*! + * \brief Constructs a TestRunner object. + */ + QtTestRunner(); -private: - /// Prevents the use of the copy constructor. - QtTestRunner( const QtTestRunner © ); + /*! + * \brief Destructor. + */ + ~QtTestRunner(); - /// Prevents the use of the copy operator. - void operator =( const QtTestRunner © ); + /*! + * \brief Runs the specified test (and all of its child tests) + * \param autorun When set to \c true the tests are automatically run the first time + */ + void run(bool autorun = false); - Test *getRootTest(); + /*! + * \brief Adds a (top-level) test to the list of tests to run + * \param test A test that shall be executed + */ + void addTest(Test *test); private: - typedef CppUnitVector<Test *> Tests; - Tests *_tests; - - TestSuite *_suite; + QScopedPointer<class QtTestRunnerPrivate> _d; }; - -#if CPPUNIT_HAVE_NAMESPACES - namespace QtUi - { - /*! Qt TestRunner (DEPRECATED). - * \deprecated Use CppUnit::QtTestRunner instead. - */ - typedef CPPUNIT_NS::QtTestRunner TestRunner; - } -#endif - - CPPUNIT_NS_END -#endif // CPPUNIT_QTUI_QTTESTRUNNER_H +#endif // CPPUNIT_QTTESTRUNNER_H diff --git a/src/qttestrunner/MostRecentTests.cpp b/src/qttestrunner/MostRecentTests.cpp deleted file mode 100644 index e286ed1..0000000 --- a/src/qttestrunner/MostRecentTests.cpp +++ /dev/null @@ -1,68 +0,0 @@ -// ////////////////////////////////////////////////////////////////////////// -// Implementation file MostRecentTests.cpp for class MostRecentTests -// (c)Copyright 2000, Baptiste Lepilleur. -// Created: 2001/09/20 -// ////////////////////////////////////////////////////////////////////////// - -#include "MostRecentTests.h" - - -MostRecentTests::MostRecentTests() -{ -} - - -MostRecentTests::~MostRecentTests() -{ -} - - -void -MostRecentTests::setTestToRun( CPPUNIT_NS::Test *test ) -{ - m_tests.removeRef( test ); - m_tests.prepend( test ); - - const int maxRecentTest = 20; - if ( m_tests.count() > maxRecentTest ) - m_tests.remove( maxRecentTest ); - - emit listChanged(); - emit testToRunChanged( testToRun() ); -} - - -CPPUNIT_NS::Test * -MostRecentTests::testToRun() -{ - return testAt( 0 ); -} - - -void -MostRecentTests::selectTestToRun( int index ) -{ - if ( index < testCount() ) - setTestToRun( testAt( index ) ); -} - - -int -MostRecentTests::testCount() -{ - return m_tests.count(); -} - - -QString -MostRecentTests::testNameAt( int index ) -{ - return QString::fromLatin1( testAt( index )->getName().c_str() ); -} - - -CPPUNIT_NS::Test * -MostRecentTests::testAt( int index ) -{ - return m_tests.at( index ); -} diff --git a/src/qttestrunner/MostRecentTests.h b/src/qttestrunner/MostRecentTests.h deleted file mode 100644 index ebd95fc..0000000 --- a/src/qttestrunner/MostRecentTests.h +++ /dev/null @@ -1,62 +0,0 @@ -// ////////////////////////////////////////////////////////////////////////// -// Header file MostRecentTests.h for class MostRecentTests -// (c)Copyright 2000, Baptiste Lepilleur. -// Created: 2001/09/20 -// ////////////////////////////////////////////////////////////////////////// -#ifndef MOSTRECENTTESTS_H -#define MOSTRECENTTESTS_H - -#include <cppunit/Test.h> -#include <qstring.h> -#include <qptrlist.h> -#include <qobject.h> - - -/*! \class MostRecentTests - * \brief This class represents the list of the recent tests. - */ -class MostRecentTests : public QObject -{ - Q_OBJECT -public: - /*! Constructs a MostRecentTests object. - */ - MostRecentTests(); - - /*! Destructor. - */ - virtual ~MostRecentTests(); - - void setTestToRun( CPPUNIT_NS::Test *test ); - CPPUNIT_NS::Test *testToRun(); - - int testCount(); - QString testNameAt( int index ); - CPPUNIT_NS::Test *testAt( int index ); - -signals: - void listChanged(); - void testToRunChanged( CPPUNIT_NS::Test *testToRun ); - -public slots: - void selectTestToRun( int index ); - -private: - /// Prevents the use of the copy constructor. - MostRecentTests( const MostRecentTests © ); - - /// Prevents the use of the copy operator. - void operator =( const MostRecentTests © ); - -private: - QList<CPPUNIT_NS::Test> m_tests; -}; - - - -// Inlines methods for MostRecentTests: -// ------------------------------------ - - - -#endif // MOSTRECENTTESTS_H diff --git a/src/qttestrunner/QtTestFailure.cpp b/src/qttestrunner/QtTestFailure.cpp new file mode 100644 index 0000000..6ab1bbb --- /dev/null +++ b/src/qttestrunner/QtTestFailure.cpp @@ -0,0 +1,93 @@ +#include <cppunit/Exception.h> + +#include "QtTestFailure.h" + +class QtTestFailurePrivate +{ + typedef CPPUNIT_NS::Test Test; + typedef CPPUNIT_NS::SourceLine SourceLine; + +public: + QtTestFailurePrivate() + : _isError(true) + , _test(NULL) + , _srcline() + , _message() + {} + + QtTestFailurePrivate(Test *failed, + const QString &message, + const SourceLine &srcline, + bool isError) + : _isError(isError) + , _test(failed) + , _srcline(srcline) + , _message(message) + {} + + ~QtTestFailurePrivate() + {} + +public: + bool _isError; + Test *_test; + SourceLine _srcline; + QString _message; +}; + +QtTestFailure::QtTestFailure() + : _d(new QtTestFailurePrivate) +{} + +QtTestFailure::QtTestFailure(Test *failed, + const QString &message, + const CppUnit::SourceLine &srcline, + bool isError) + : _d(new QtTestFailurePrivate(failed, message, srcline, isError)) +{} + +QtTestFailure::QtTestFailure(const QtTestFailure &other) + : _d(new QtTestFailurePrivate(*other._d.data())) +{} + +QtTestFailure::~QtTestFailure() +{} + +QtTestFailure &QtTestFailure::operator =(const QtTestFailure &other) +{ + if (this != &other) + { + _d.reset(new QtTestFailurePrivate(*other._d.data())); + } + + return *this; +} + +QtTestFailure::SourceLine QtTestFailure::sourceLine() const +{ + return _d->_srcline; +} + +QString QtTestFailure::message() const +{ + return _d->_message; +} + +QString QtTestFailure::failedTestName() const +{ + if (_d->_test == NULL) + return QString(); + + return QString::fromStdString(_d->_test->getName()); +} + +bool QtTestFailure::isError() const +{ + return _d->_isError; +} + +bool QtTestFailure::isValid() const +{ + return _d->_test != NULL; +} + diff --git a/src/qttestrunner/QtTestFailure.h b/src/qttestrunner/QtTestFailure.h new file mode 100644 index 0000000..ba8f1ff --- /dev/null +++ b/src/qttestrunner/QtTestFailure.h @@ -0,0 +1,88 @@ +#ifndef QTTESTFAILURE_H +#define QTTESTFAILURE_H + +#include <QMetaType> +#include <QScopedPointer> +#include <QString> + +#include <cppunit/Test.h> +#include <cppunit/SourceLine.h> + +/*! + * \class QtTestFailure + * \brief This class represents a test failure. + */ +class QtTestFailure +{ + typedef CPPUNIT_NS::Test Test; + typedef CPPUNIT_NS::SourceLine SourceLine; + +public: + /*! + * \brief Constructs an invalid QtTestFailure object + */ + QtTestFailure(); + + /*! + * \brief Constructs a QtTestFailure object from the given parameters + * \param failed A pointer to the failed test + * \param message The failure message + * \param srcline Information about the location of the failure + * \param isError \c true: the failure was actually an error, \c false: a standard test failure + */ + QtTestFailure(Test *failed, const QString &message, const SourceLine &srcline, bool isError); + + /*! + * \brief Copy c'tor + * \param other The object to copy + */ + QtTestFailure(const QtTestFailure &other); + + /*! + * \brief Destructor. + */ + ~QtTestFailure(); + + /*! + * \brief Returns information about the location of the failure + * \return Information about the failure location + */ + SourceLine sourceLine() const; + + /*! + * \brief Returns the detailed message of the failure + * \return The detailed failure message + */ + QString message() const; + + /*! + * \brief Returns the name of the failed test + * \return The name of the failed test + */ + QString failedTestName() const; + + /*! + * \brief Returns whether the failure actually was an error + * \return \c true: the failure was an error, \c false: a standard test failure + */ + bool isError() const; + + /*! + * \brief Returns whether this failure object is valid + * \return \c true: The object is valid, \c false: the object is _not_ valid + */ + bool isValid() const; + + /*! + * \brief Copy assignment operator + * \param other The object to copy + */ + QtTestFailure &operator =(const QtTestFailure &other); + +private: + QScopedPointer<class QtTestFailurePrivate> _d; +}; + +Q_DECLARE_METATYPE(QtTestFailure) + +#endif // QTTESTFAILURE_H diff --git a/src/qttestrunner/QtTestListener.cpp b/src/qttestrunner/QtTestListener.cpp new file mode 100644 index 0000000..2135330 --- /dev/null +++ b/src/qttestrunner/QtTestListener.cpp @@ -0,0 +1,29 @@ +#include <cppunit/Exception.h> + +#include "QtTestListener.h" + +QtTestListener::QtTestListener(QObject *parent) + : QObject(parent) + , CPPUNIT_NS::TestListener() +{} + +QtTestListener::~QtTestListener() +{} + +void QtTestListener::startTest(Test * /*test*/) +{ + emit testCaseStarted(); +} + +void QtTestListener::addFailure(const TestFailure &failure) +{ + emit testFailed(QtTestFailure(failure.failedTest(), + failure.thrownException()->what(), + failure.sourceLine(), + failure.isError())); +} + +void QtTestListener::endTest(Test * /*test*/) +{ + emit testCaseFinished(); +} diff --git a/src/qttestrunner/QtTestListener.h b/src/qttestrunner/QtTestListener.h new file mode 100644 index 0000000..1b53f04 --- /dev/null +++ b/src/qttestrunner/QtTestListener.h @@ -0,0 +1,61 @@ +#ifndef QTTESTLISTENER_H +#define QTTESTLISTENER_H + +#include <QObject> + +#include <cppunit/Test.h> +#include <cppunit/TestListener.h> +#include <cppunit/TestFailure.h> + +#include "QtTestFailure.h" + +/*! + * \class QtTestListener + * \brief A specialized Qt based test listener + * + * This listener uses the Qt meta object system for propagation of testing states. + */ +class QtTestListener : public QObject, public CPPUNIT_NS::TestListener +{ + Q_OBJECT + Q_DISABLE_COPY(QtTestListener) + + typedef CPPUNIT_NS::Test Test; + typedef CPPUNIT_NS::TestFailure TestFailure; + +public: + /*! + * \brief Constructs a QtTestListener object. + * \param parent A parent QObject + */ + QtTestListener(QObject *parent = 0); + + /*! + * \brief Destructor. + */ + ~QtTestListener(); + +signals: + /*! + * \brief Signals that a test case is being executed + */ + void testCaseStarted(); + + /*! + * \brief Signals that a test failed + * \param failure Contains information about the failed test + */ + void testFailed(const QtTestFailure &failure); + + /*! + * \brief Signals that a test case has finished + */ + void testCaseFinished(); + +private: + void startTest(Test *test); + void addFailure(const TestFailure &failure); + void endTest(Test *test); +}; + +#endif // QTTESTLISTENER_H diff --git a/src/qttestrunner/QtTestRunner.cpp b/src/qttestrunner/QtTestRunner.cpp index 9f203cd..2f5d90f 100644 --- a/src/qttestrunner/QtTestRunner.cpp +++ b/src/qttestrunner/QtTestRunner.cpp @@ -1,70 +1,86 @@ -// ////////////////////////////////////////////////////////////////////////// -// Implementation file QtTestRunner.cpp for class QtTestRunner -// (c)Copyright 2000, Baptiste Lepilleur. -// Created: 2001/09/19 -// ////////////////////////////////////////////////////////////////////////// +#include <QApplication> -#include <qapplication.h> #include <cppunit/TestSuite.h> #include <cppunit/ui/qt/QtTestRunner.h> -#include "TestRunnerDlgImpl.h" -#include "TestRunnerModel.h" +#include "TestRunnerWindow.h" CPPUNIT_NS_BEGIN -QtTestRunner::QtTestRunner() : - _suite( new CPPUNIT_NS::TestSuite( "All Tests" ) ), - _tests( new Tests() ) -{ -} +// +// QtTestRunnerPrivate +// +// Define a few types for better readability (and usability) later on +typedef Test* TestPtr; +typedef QVector< TestPtr > TestPtrList; +typedef QVectorIterator< TestPtr > TestPtrListIterator; -QtTestRunner::~QtTestRunner() +class QtTestRunnerPrivate { - delete _suite; + typedef QScopedPointer< TestSuite > TestSuitePtr; + +public: + QtTestRunnerPrivate() + : _suite(new TestSuite("All Tests")) + , _tests() + , _dialog() + {} + + ~QtTestRunnerPrivate() + {} + + Test *rootTest() + { + if (_tests.size() != 1) + { + TestPtrListIterator it(_tests); + while (it.hasNext()) + { + _suite->addTest(it.next()); + } + + _tests.clear(); + return _suite.data(); + } + + return _tests.at(0); + } + +public: + TestSuitePtr _suite; + TestPtrList _tests; + QScopedPointer<TestRunnerWindow> _dialog; +}; + +// +// QtTestRunner +// + +QtTestRunner::QtTestRunner() + : _d(new QtTestRunnerPrivate) +{} - Tests::iterator it = _tests->begin(); - while ( it != _tests->end() ) - delete *it++; - - delete _tests; +QtTestRunner::~QtTestRunner() +{ + TestPtrListIterator it(_d->_tests); + while (it.hasNext()) + delete it.next(); } - -Test * -QtTestRunner::getRootTest() +void QtTestRunner::run(bool autorun) { - if ( _tests->size() != 1 ) - { - Tests::iterator it = _tests->begin(); - while ( it != _tests->end() ) - _suite->addTest( *it++ ); - _tests->clear(); - return _suite; - } - return (*_tests)[0]; -} + _d->_dialog.reset(new TestRunnerWindow(_d->rootTest())); + if (autorun) + _d->_dialog->startTesting(); -void -QtTestRunner::run( bool autoRun ) -{ - TestRunnerDlg *dlg = new TestRunnerDlg( qApp->mainWidget(), - "QtTestRunner", - TRUE ); - dlg->setModel( new TestRunnerModel( getRootTest() ), - autoRun ); - dlg->exec(); - delete dlg; + _d->_dialog->show(); } - -void -QtTestRunner::addTest( CPPUNIT_NS::Test *test ) +void QtTestRunner::addTest(Test *test) { - _tests->push_back( test ); + _d->_tests.append(test); } - CPPUNIT_NS_END diff --git a/src/qttestrunner/TestBrowser.cpp b/src/qttestrunner/TestBrowser.cpp new file mode 100644 index 0000000..64fda53 --- /dev/null +++ b/src/qttestrunner/TestBrowser.cpp @@ -0,0 +1,55 @@ +#include <QTreeWidgetItem> +#include <QVariant> + +#include <cppunit/Test.h> + +#include "TestBrowser.h" +#include "ui_TestBrowser.h" + +TestBrowser::TestBrowser(Test *rootTest, QWidget *parent, Qt::WindowFlags flags) + : QDialog(parent, flags), + _ui(new Ui::TestBrowser) +{ + _ui->setupUi(this); + buildTree(rootTest, NULL); + + _ui->treeWidget->expandAll(); +} + +TestBrowser::~TestBrowser() +{ + // no need to delete child widgets, Qt does it all for us +} + +void TestBrowser::buildTree(Test *test, QTreeWidgetItem *parentItem) +{ + QTreeWidgetItem *item = (parentItem != NULL) + ? new QTreeWidgetItem(parentItem) + : new QTreeWidgetItem(_ui->treeWidget); + + QVariant data; + data.setValue(test); + item->setData(0, Qt::UserRole, data); + item->setText(0, QString::fromStdString(test->getName())); + + if (test->getChildTestCount() > 0 || // suite with test + test->countTestCases() == 0) // empty suite + { + for (int index = 0; index < test->getChildTestCount(); ++index) + buildTree(test->getChildTestAt(index), item); + } +} + +void TestBrowser::accept() +{ + QList<QTreeWidgetItem*> selectedItems = _ui->treeWidget->selectedItems(); + + if(!selectedItems.isEmpty()) + { + QTreeWidgetItem *selected = selectedItems.first(); + QVariant data = selected->data(0, Qt::UserRole); + emit testSelected(data.value<Test*>()); + } + + QDialog::accept(); +} diff --git a/src/qttestrunner/TestBrowser.h b/src/qttestrunner/TestBrowser.h new file mode 100644 index 0000000..9f0efb1 --- /dev/null +++ b/src/qttestrunner/TestBrowser.h @@ -0,0 +1,61 @@ +#ifndef TESTBROWSER_H +#define TESTBROWSER_H + +#include <QDialog> +#include <QScopedPointer> + +#include <cppunit/Test.h> + +namespace Ui { +class TestBrowser; +} + +class QTreeWidgetItem; + +/*! + * \class TestBrowser + * \brief A small dialog that displays all registered tests in a hierarchical tree structure + * + * When a test is selected from this tree and the selection is confirmed, a pointer to the selected + * test is signalled to the outside world. + */ +class TestBrowser : public QDialog +{ + Q_OBJECT + + typedef CPPUNIT_NS::Test Test; + +public: + /*! + * \brief Constructs the test browser dialog + * \param rootTest The top level test to use for determining all child tests + * \param parent A pointer to a parent QWidget + * \param flags Optional window flags controlling the dialog's appearance + * (see the QDialog documentation at http://qt-project.org/doc for further details) + */ + TestBrowser(Test *rootTest, QWidget *parent = 0, Qt::WindowFlags flags = 0); + + /*! + * \brief Releases all allocated resources + */ + ~TestBrowser(); + +signals: + /*! + * \brief Signals that a test was selected on the test tree + */ + void testSelected(Test *); + +private: + void buildTree(Test *test, QTreeWidgetItem *parentItem); + +private slots: + void accept(); + +private: + QScopedPointer<class Ui::TestBrowser> _ui; +}; + +Q_DECLARE_METATYPE(CPPUNIT_NS::Test *) + +#endif // TESTBROWSER_H diff --git a/src/qttestrunner/TestBrowser.ui b/src/qttestrunner/TestBrowser.ui new file mode 100644 index 0000000..8d5f718 --- /dev/null +++ b/src/qttestrunner/TestBrowser.ui @@ -0,0 +1,88 @@ +<?xml version="1.0" encoding="UTF-8"?> +<ui version="4.0"> + <class>TestBrowser</class> + <widget class="QDialog" name="TestBrowser"> + <property name="geometry"> + <rect> + <x>0</x> + <y>0</y> + <width>647</width> + <height>416</height> + </rect> + </property> + <property name="windowTitle"> + <string>Select Test</string> + </property> + <property name="modal"> + <bool>true</bool> + </property> + <layout class="QHBoxLayout" name="horizontalLayout"> + <item> + <widget class="QTreeWidget" name="treeWidget"> + <property name="editTriggers"> + <set>QAbstractItemView::NoEditTriggers</set> + </property> + <property name="headerHidden"> + <bool>true</bool> + </property> + <column> + <property name="text"> + <string notr="true">1</string> + </property> + </column> + </widget> + </item> + <item> + <widget class="QDialogButtonBox" name="buttonBox"> + <property name="sizePolicy"> + <sizepolicy hsizetype="Fixed" vsizetype="Expanding"> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="orientation"> + <enum>Qt::Vertical</enum> + </property> + <property name="standardButtons"> + <set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set> + </property> + </widget> + </item> + </layout> + </widget> + <resources/> + <connections> + <connection> + <sender>buttonBox</sender> + <signal>accepted()</signal> + <receiver>TestBrowser</receiver> + <slot>accept()</slot> + <hints> + <hint type="sourcelabel"> + <x>248</x> + <y>254</y> + </hint> + <hint type="destinationlabel"> + <x>157</x> + <y>274</y> + </hint> + </hints> + </connection> + <connection> + <sender>buttonBox</sender> + <signal>rejected()</signal> + <receiver>TestBrowser</receiver> + <slot>reject()</slot> + <hints> + <hint type="sourcelabel"> + <x>316</x> + <y>260</y> + </hint> + <hint type="destinationlabel"> + <x>286</x> + <y>274</y> + </hint> + </hints> + </connection> + </connections> +</ui> diff --git a/src/qttestrunner/TestBrowserDlgImpl.cpp b/src/qttestrunner/TestBrowserDlgImpl.cpp deleted file mode 100644 index cef7c52..0000000 --- a/src/qttestrunner/TestBrowserDlgImpl.cpp +++ /dev/null @@ -1,83 +0,0 @@ -#include <cppunit/Test.h> -#include <qlistview.h> -#include <qmessagebox.h> -#include "TestBrowserDlgImpl.h" -#include "TestListViewItem.h" - - -/* - * Constructs a TestBrowser which is a child of 'parent', with the - * name 'name' and widget flags set to 'f' - * - * The dialog will by default be modeless, unless you set 'modal' to - * TRUE to construct a modal dialog. - */ -TestBrowser::TestBrowser( QWidget* parent, const char* name, bool modal, WFlags fl ) - : TestBrowserBase( parent, name, modal, fl ), - _selectedTest( NULL ) -{ - _listTests->setRootIsDecorated( TRUE ); -} - -/* - * Destroys the object and frees any allocated resources - */ -TestBrowser::~TestBrowser() -{ - // no need to delete child widgets, Qt does it all for us -} - - -void -TestBrowser::setRootTest( CPPUNIT_NS::Test *rootTest ) -{ - QListViewItem *dummyRoot = new QListViewItem( _listTests ); - - insertItemFor( rootTest, dummyRoot ); - - dummyRoot->firstChild()->moveItem( dummyRoot ); - delete dummyRoot; - - _listTests->firstChild()->setOpen( TRUE ); - _listTests->triggerUpdate(); -} - - -void -TestBrowser::insertItemFor( CPPUNIT_NS::Test *test, - QListViewItem *parentItem ) -{ - QListViewItem *item = new TestListViewItem( test, parentItem ); - QString testName = QString::fromLatin1( test->getName().c_str() ); - item->setText( 0, testName ); - if ( test->getChildTestCount() > 0 || // suite with test - test->countTestCases() == 0 ) // empty suite - { - for ( int index =0; index < test->getChildTestCount(); ++index ) - insertItemFor( test->getChildTestAt( index ), item ); - } -} - - -CPPUNIT_NS::Test * -TestBrowser::selectedTest() -{ - return _selectedTest; -} - - -void -TestBrowser::accept() -{ - TestListViewItem *item = (TestListViewItem *)_listTests->selectedItem(); - if ( item == NULL ) - { - QMessageBox::information( this, tr("Selected test"), - tr( "You must select a test." ) ); - return; - } - - _selectedTest = item->test(); - - TestBrowserBase::accept(); -} diff --git a/src/qttestrunner/TestBrowserDlgImpl.h b/src/qttestrunner/TestBrowserDlgImpl.h deleted file mode 100644 index d4c113a..0000000 --- a/src/qttestrunner/TestBrowserDlgImpl.h +++ /dev/null @@ -1,32 +0,0 @@ -#ifndef TESTBROWSER_H -#define TESTBROWSER_H - -#include <cppunit/Test.h> -#include "testbrowserdlg.h" - -class QListViewItem; - -class TestBrowser : public TestBrowserBase -{ - Q_OBJECT - -public: - TestBrowser( QWidget* parent = 0, const char* name = 0, bool modal = FALSE, WFlags fl = 0 ); - ~TestBrowser(); - - void setRootTest( CPPUNIT_NS::Test *rootTest ); - - CPPUNIT_NS::Test *selectedTest(); - -protected slots: - void accept(); - -private: - void insertItemFor( CPPUNIT_NS::Test *test, - QListViewItem *parentItem ); - -private: - CPPUNIT_NS::Test *_selectedTest; -}; - -#endif // TESTBROWSER_H diff --git a/src/qttestrunner/TestFailureInfo.cpp b/src/qttestrunner/TestFailureInfo.cpp deleted file mode 100644 index 54c5b1d..0000000 --- a/src/qttestrunner/TestFailureInfo.cpp +++ /dev/null @@ -1,21 +0,0 @@ -// ////////////////////////////////////////////////////////////////////////// -// Implementation file TestFailureInfo.cpp for class TestFailureInfo -// (c)Copyright 2000, Baptiste Lepilleur. -// Created: 2001/09/20 -// ////////////////////////////////////////////////////////////////////////// - -#include "TestFailureInfo.h" -#include <cppunit/Exception.h> - - -TestFailureInfo::TestFailureInfo( CPPUNIT_NS::Test *failedTest, - CPPUNIT_NS::Exception *thrownException, - bool isError ) : - CPPUNIT_NS::TestFailure( failedTest, thrownException->clone(), isError ) -{ -} - - -TestFailureInfo::~TestFailureInfo() -{ -} diff --git a/src/qttestrunner/TestFailureInfo.h b/src/qttestrunner/TestFailureInfo.h deleted file mode 100644 index 64a2ceb..0000000 --- a/src/qttestrunner/TestFailureInfo.h +++ /dev/null @@ -1,43 +0,0 @@ -// ////////////////////////////////////////////////////////////////////////// -// Header file TestFailureInfo.h for class TestFailureInfo -// (c)Copyright 2000, Baptiste Lepilleur. -// Created: 2001/09/20 -// ////////////////////////////////////////////////////////////////////////// -#ifndef TESTFAILUREINFO_H -#define TESTFAILUREINFO_H - -#include <cppunit/TestFailure.h> - - -/*! \class TestFailureInfo - * \brief This class represents a test failure. - */ -class TestFailureInfo : public CPPUNIT_NS::TestFailure -{ -public: - /*! Constructs a TestFailureInfo object. - */ - TestFailureInfo( CPPUNIT_NS::Test *failedTest, - CPPUNIT_NS::Exception *thrownException, - bool isError ); - - /*! Destructor. - */ - virtual ~TestFailureInfo(); - -private: - /// Prevents the use of the copy constructor. - TestFailureInfo( const TestFailureInfo © ); - - /// Prevents the use of the copy operator. - void operator =( const TestFailureInfo © ); -}; - - - -// Inlines methods for TestFailureInfo: -// ------------------------------------ - - - -#endif // TESTFAILUREINFO_H diff --git a/src/qttestrunner/TestFailureListViewItem.cpp b/src/qttestrunner/TestFailureListViewItem.cpp deleted file mode 100644 index 387818f..0000000 --- a/src/qttestrunner/TestFailureListViewItem.cpp +++ /dev/null @@ -1,29 +0,0 @@ -// ////////////////////////////////////////////////////////////////////////// -// Implementation file TestFailureListViewItem.cpp for class TestFailureListViewItem -// (c)Copyright 2000, Baptiste Lepilleur. -// Created: 2001/09/20 -// ////////////////////////////////////////////////////////////////////////// - -#include "TestFailureListViewItem.h" - - -TestFailureListViewItem::TestFailureListViewItem( - TestFailureInfo *failure, - QListView *parent ) : - QListViewItem( parent ), - _failure( failure ) -{ - setMultiLinesEnabled (true); -} - - -TestFailureListViewItem::~TestFailureListViewItem() -{ -} - - -TestFailureInfo * -TestFailureListViewItem::failure() -{ - return _failure; -} diff --git a/src/qttestrunner/TestFailureListViewItem.h b/src/qttestrunner/TestFailureListViewItem.h deleted file mode 100644 index 97d3716..0000000 --- a/src/qttestrunner/TestFailureListViewItem.h +++ /dev/null @@ -1,48 +0,0 @@ -// ////////////////////////////////////////////////////////////////////////// -// Header file TestFailureListViewItem.h for class TestFailureListViewItem -// (c)Copyright 2000, Baptiste Lepilleur. -// Created: 2001/09/20 -// ////////////////////////////////////////////////////////////////////////// -#ifndef TESTFAILURELISTVIEWITEM_H -#define TESTFAILURELISTVIEWITEM_H - -#include <qlistview.h> -class TestFailureInfo; - - -/*! \class TestFailureListViewItem - * \brief This class represents a test failure item. - */ -class TestFailureListViewItem : public QListViewItem -{ -public: - /*! Constructs a TestFailureListViewItem object. - */ - TestFailureListViewItem( TestFailureInfo *failure, - QListView *parent ); - - /*! Destructor. - */ - virtual ~TestFailureListViewItem(); - - TestFailureInfo *failure(); - -private: - /// Prevents the use of the copy constructor. - TestFailureListViewItem( const TestFailureListViewItem © ); - - /// Prevents the use of the copy operator. - void operator =( const TestFailureListViewItem © ); - -private: - TestFailureInfo *_failure; -}; - - - -// Inlines methods for TestFailureListViewItem: -// -------------------------------------------- - - - -#endif // TESTFAILURELISTVIEWITEM_H diff --git a/src/qttestrunner/TestFailureTableModel.cpp b/src/qttestrunner/TestFailureTableModel.cpp new file mode 100644 index 0000000..d96ccec --- /dev/null +++ b/src/qttestrunner/TestFailureTableModel.cpp @@ -0,0 +1,146 @@ +#include <QObject> +#include <QMap> + +#include <cppunit/Exception.h> + +#include "TestFailureTableModel.h" + +// +// TestFailureTableModelPrivate +// + +class TestFailureTableModelPrivate +{ +public: + // Column header enumeration + enum Column + { + ColumnType = 0, + ColumnName = 1, + ColumnMessage = 2 + }; + + // Convenience type definition + typedef QMap<Column, QString> ColumnStringMap; + + // C'tor + TestFailureTableModelPrivate() + : columnCount(3) + , failureString(QObject::tr("Failure")) + , errorString(QObject::tr("Error")) + , columnStrings() + , failures() + { + // This would be so much easier using C++11... *sigh* + ColumnStringMap &map = const_cast<ColumnStringMap&>(columnStrings); + map.insert(ColumnType, QObject::tr("Type")); + map.insert(ColumnName, QObject::tr("Test name")); + map.insert(ColumnMessage, QObject::tr("Message")); + } + +public: + const int columnCount; + const QString failureString; + const QString errorString; + const ColumnStringMap columnStrings; + + QList<QtTestFailure> failures; +}; + +// +// TestFailureTableModel +// + +TestFailureTableModel::TestFailureTableModel(QObject *parent) + : QAbstractTableModel(parent) + , _d(new TestFailureTableModelPrivate) +{} + +TestFailureTableModel::~TestFailureTableModel() +{} + +int TestFailureTableModel::rowCount(const QModelIndex &) const +{ + return _d->failures.size(); +} + +int TestFailureTableModel::columnCount(const QModelIndex &) const +{ + return _d->columnCount; +} + +QVariant TestFailureTableModel::data(const QModelIndex &index, int role) const +{ + if (index.isValid()) + { + if (role == Qt::DisplayRole) + { + QtTestFailure failure = _d->failures.at(index.row()); + switch (index.column()) + { + case TestFailureTableModelPrivate::ColumnType: + return failure.isError() + ? QVariant(_d->errorString) + : QVariant(_d->failureString); + case TestFailureTableModelPrivate::ColumnName: + return QVariant(failure.failedTestName()); + case TestFailureTableModelPrivate::ColumnMessage: + return QVariant(failure.message()); + default: + break; + } + } + else if (role == Qt::UserRole) + { + QVariant data; + data.setValue(_d->failures.at(index.row())); + return data; + } + } + + return QVariant(); +} + +QVariant TestFailureTableModel::headerData(int section, Qt::Orientation orientation, int role) const +{ + if (orientation == Qt::Horizontal && role == Qt::DisplayRole) + { + switch (section) + { + case TestFailureTableModelPrivate::ColumnType: + return QVariant(_d->columnStrings.value(TestFailureTableModelPrivate::ColumnType)); + case TestFailureTableModelPrivate::ColumnName: + return QVariant(_d->columnStrings.value(TestFailureTableModelPrivate::ColumnName)); + case TestFailureTableModelPrivate::ColumnMessage: + return QVariant(_d->columnStrings.value(TestFailureTableModelPrivate::ColumnMessage)); + default: + break; + } + } + + return QVariant(); +} + +bool TestFailureTableModel::setHeaderData(int, Qt::Orientation, const QVariant &, int) +{ + // Header is fix, nothing to do here + return false; +} + +void TestFailureTableModel::clear() +{ + beginResetModel(); + _d->failures.clear(); + endResetModel(); +} + +void TestFailureTableModel::addFailure(const QtTestFailure &failure) +{ + if (!failure.isValid()) + return; + + beginInsertRows(QModelIndex(), _d->failures.size(), _d->failures.size()); + insertRow(_d->failures.size(), QModelIndex()); + _d->failures.append(failure); + endInsertRows(); +} diff --git a/src/qttestrunner/TestFailureTableModel.h b/src/qttestrunner/TestFailureTableModel.h new file mode 100644 index 0000000..1f65b27 --- /dev/null +++ b/src/qttestrunner/TestFailureTableModel.h @@ -0,0 +1,88 @@ +#ifndef TESTRUNNERMODEL_H +#define TESTRUNNERMODEL_H + +#include <QAbstractTableModel> +#include <QScopedPointer> + +#include "QtTestFailure.h" + +/*! + * \class TestFailureTableModel + * \brief This class represents the data model for the failure list on the TestRunnerWindow + */ +class TestFailureTableModel : public QAbstractTableModel +{ + Q_OBJECT + Q_DISABLE_COPY(TestFailureTableModel) + +public: + /*! + * \brief Constructs a TestRunnerModel object. + * \param parent A parent QObject + */ + TestFailureTableModel(QObject *parent = 0); + + /*! + * \brief Destructor. + */ + ~TestFailureTableModel(); + + /*! + * \brief Implements QAbstractItemModel::rowCount() + * \return The number of rows stored in this model + */ + int rowCount(const QModelIndex &) const; + + /*! + * \brief Implements QAbstractItemModel::columnCount() + * \return The number of columns this model provides. + */ + int columnCount(const QModelIndex &) const; + + /*! + * \brief Implements QAbstractItemModel::data() + * \param index The index of the data to retrieve + * \param role Specifies the role for which to retrieve data + * \return The data for the given index and role + */ + QVariant data(const QModelIndex &index, int role) const; + + /*! + * \brief Reimplemented from QAbstractTableModel::headerData() + * \param section The index of the section to retrieve information for + * \param orientation Either Qt::Horizontal or Qt::Vertical + * \param role The role to retrieve the header data for + * \return The header data of the given section for the given orientation and role + * + * This method actually returns the column names used in the view on the TestRunnerWindow + */ + QVariant headerData(int section, Qt::Orientation orientation, int role) const; + + /*! + * \brief Reimplemented from QAbstractTableModel::headerData() + * \return Always false + * + * As for this model setting the header data is not required, this method does nothing + * except always returning \c false. + */ + bool setHeaderData(int, Qt::Orientation, const QVariant&, int); + +public slots: + /*! + * \brief Clears all data in the underlying data store + * + * Calling this slot causes all views using this model to be reset. + */ + void clear(); + + /*! + * \brief Adds a new failure record to the underlying data store + * \param failure The failure information to add + */ + void addFailure(const QtTestFailure &failure); + +private: + QScopedPointer<class TestFailureTableModelPrivate> _d; +}; + +#endif // TESTRUNNERMODEL_H diff --git a/src/qttestrunner/TestListViewItem.cpp b/src/qttestrunner/TestListViewItem.cpp deleted file mode 100644 index b4032dc..0000000 --- a/src/qttestrunner/TestListViewItem.cpp +++ /dev/null @@ -1,27 +0,0 @@ -// ////////////////////////////////////////////////////////////////////////// -// Implementation file TestListViewItem.cpp for class TestListViewItem -// (c)Copyright 2000, Baptiste Lepilleur. -// Created: 2001/09/19 -// ////////////////////////////////////////////////////////////////////////// - -#include "TestListViewItem.h" - - -TestListViewItem::TestListViewItem( CPPUNIT_NS::Test *test, - QListViewItem *parent ) : - QListViewItem( parent ), - _test( test ) -{ -} - - -TestListViewItem::~TestListViewItem() -{ -} - - -CPPUNIT_NS::Test * -TestListViewItem::test() const -{ - return _test; -} diff --git a/src/qttestrunner/TestListViewItem.h b/src/qttestrunner/TestListViewItem.h deleted file mode 100644 index 4032f68..0000000 --- a/src/qttestrunner/TestListViewItem.h +++ /dev/null @@ -1,43 +0,0 @@ -// ////////////////////////////////////////////////////////////////////////// -// Header file TestListViewItem.h for class TestListViewItem -// (c)Copyright 2000, Baptiste Lepilleur. -// Created: 2001/09/19 -// ////////////////////////////////////////////////////////////////////////// -#ifndef TESTLISTVIEWITEM_H -#define TESTLISTVIEWITEM_H - -#include <qlistview.h> -#include <cppunit/Test.h> - - -/*! \class TestListViewItem - * \brief This class represents an list item pointing to a Test. - */ -class TestListViewItem : public QListViewItem -{ -public: - /*! Constructs a TestListViewItem object. - */ - TestListViewItem( CPPUNIT_NS::Test *test, - QListViewItem *parent ); - - /*! Destructor. - */ - virtual ~TestListViewItem(); - - CPPUNIT_NS::Test *test() const; - -private: - /// Prevents the use of the copy constructor. - TestListViewItem( const TestListViewItem © ); - - /// Prevents the use of the copy operator. - void operator =( const TestListViewItem © ); - -private: - CPPUNIT_NS::Test *_test; -}; - - - -#endif // TESTLISTVIEWITEM_H diff --git a/src/qttestrunner/TestRunnerDlgImpl.cpp b/src/qttestrunner/TestRunnerDlgImpl.cpp deleted file mode 100644 index c1c8534..0000000 --- a/src/qttestrunner/TestRunnerDlgImpl.cpp +++ /dev/null @@ -1,260 +0,0 @@ -#include <qcombobox.h> -#include <qgroupbox.h> -#include <qlabel.h> -#include <qlistview.h> -#include <qmultilineedit.h> -#include <qprogressbar.h> -#include <qpushbutton.h> -#include <cppunit/Exception.h> -#include "TestRunnerDlgImpl.h" -#include "TestBrowserDlgImpl.h" -#include "MostRecentTests.h" -#include "TestRunnerModel.h" -#include "TestFailureListViewItem.h" - - -/* - * Constructs a TestRunnerDlg which is a child of 'parent', with the - * name 'name' and widget flags set to 'f' - * - * The dialog will by default be modeless, unless you set 'modal' to - * TRUE to construct a modal dialog. - */ -TestRunnerDlg::TestRunnerDlg( QWidget* parent, const char* name, bool modal, WFlags fl ) - : TestRunnerDlgBase( parent, name, modal, fl ), - _model( NULL ), - _recentTests( new MostRecentTests() ) -{ -} - - -/* - * Destroys the object and frees any allocated resources - */ -TestRunnerDlg::~TestRunnerDlg() -{ - delete _model; - delete _recentTests; -} - - -void -TestRunnerDlg::setModel( TestRunnerModel *model, - bool autorunTest ) -{ - delete _model; - - _model = model; - - // update combo when recent list change - connect( _recentTests, SIGNAL( listChanged() ), - SLOT( refreshRecentTests() ) ); - - // make selected test in combo the "most recent" - connect( _comboTest, SIGNAL( activated(int) ), - _recentTests, SLOT( selectTestToRun(int) ) ); - - // refresh the test report counters when a test is selected - connect( _recentTests, SIGNAL( testToRunChanged(CPPUNIT_NS::Test *) ), - _model, SLOT( resetTestReportCounterFor(CPPUNIT_NS::Test *) ) ); - - // refresh progress bar - connect( _model, SIGNAL( numberOfTestCaseChanged(int) ), - _progressRun, SLOT( setTotalSteps(int) ) ); - connect( _model, SIGNAL( numberOfTestCaseRunChanged(int) ), - _progressRun, SLOT( setProgress(int) ) ); - - // refresh test report counters - connect( _model, SIGNAL( numberOfTestCaseChanged( int ) ), - SLOT( setNumberOfTestCase( int ) ) ); - connect( _model, SIGNAL( numberOfTestCaseRunChanged( int ) ), - SLOT( setNumberOfTestCaseRun( int ) ) ); - connect( _model, SIGNAL( numberOfTestCaseFailureChanged( int ) ), - SLOT( setNumberOfTestCaseFailure( int ) ) ); - - // clear failure list - connect( _model, SIGNAL( failuresCleared() ), - SLOT( clearTestFailureList() ) ); - - // clear failure detail list - connect( _model, SIGNAL( failuresCleared() ), - SLOT( clearFailureDetail() ) ); - - // add failure to failure list - connect( _model, SIGNAL( failureAdded(TestFailureInfo *) ), - SLOT( reportFailure(TestFailureInfo*) ) ); - - // show detail on failure selection - connect( _listFailures, SIGNAL( selectionChanged(QListViewItem*) ), - SLOT( showFailureDetailAt(QListViewItem*) ) ); - - // disable button when running test - connect( _model, SIGNAL( testRunStarted( CPPUNIT_NS::Test *, CPPUNIT_NS::TestResult *) ), - SLOT( beRunningTest() ) ); - - // enable button when finished running test - connect( _model, SIGNAL( testRunFinished() ), - SLOT( beCanRunTest() ) ); - - _recentTests->setTestToRun( model->rootTest() ); - beCanRunTest(); - - if ( autorunTest ) - runTest(); -} - - -void -TestRunnerDlg::browseForTest() -{ - TestBrowser *dlg = new TestBrowser( this, - "Test Browser", - TRUE ); - dlg->setRootTest( _model->rootTest() ); - - if ( dlg->exec() ) - _recentTests->setTestToRun( dlg->selectedTest() ); - - delete dlg; -} - - -void -TestRunnerDlg::runTest() -{ - CPPUNIT_NS::Test *testToRun = _recentTests->testToRun(); - if ( testToRun == NULL ) - return; - _model->runTest( testToRun ); -} - - -void -TestRunnerDlg::stopTest() -{ - _model->stopRunningTest(); - if ( _model->isTestRunning() ) - beStoppingTest(); -} - - -void -TestRunnerDlg::clearTestFailureList() -{ - _listFailures->clear(); -} - - -void -TestRunnerDlg::refreshRecentTests() -{ - _comboTest->clear(); - for ( int index =0; index < _recentTests->testCount(); ++index ) - _comboTest->insertItem( _recentTests->testNameAt( index ) ); -} - - -void -TestRunnerDlg::setNumberOfTestCase( int numberOfTestCase ) -{ - _labelTestCaseCount->setText( QString::number( numberOfTestCase ) ); -} - - -void -TestRunnerDlg::setNumberOfTestCaseRun( int numberOfRun ) -{ - _labelTestRunCount->setText( QString::number( numberOfRun ) ); -} - - -void -TestRunnerDlg::setNumberOfTestCaseFailure( int numberOfFailure ) -{ - _labelFailureCount->setText( QString::number( numberOfFailure ) ); -} - - -void -TestRunnerDlg::reportFailure( TestFailureInfo *failure ) -{ - QListViewItem *item = new TestFailureListViewItem( failure, - _listFailures ); - item->setText( indexType, - failure->isError() ? tr("Error") : tr("Failure") ); - std::string failedtestName = failure->failedTestName().c_str(); - item->setText( indexTestName, QString::fromLatin1( failedtestName.c_str() ) ); - - CPPUNIT_NS::Exception *thrownException = failure->thrownException(); -//2.0 item->setText( indexMessage, thrownException->what() ); - item->setText( indexMessage, QString(thrownException->what()).stripWhiteSpace() ); - item->setText( indexFilename, failure->sourceLine().fileName().c_str() ); - item->setText( indexLineNumber, - QString::number( failure->sourceLine().lineNumber() ) ); - - _listFailures->insertItem( item ); - _listFailures->triggerUpdate(); - - if ( _listFailures->childCount() == 1 ) - _listFailures->setSelected( item, TRUE ); -} - - -void -TestRunnerDlg::showFailureDetailAt( QListViewItem *selection ) -{ - TestFailureInfo *failure = ((TestFailureListViewItem*)selection)->failure(); - - QString title = tr("Failure detail for: "); - title += QString::fromLatin1( failure->failedTestName().c_str() ); - _groupFailureDetail->setTitle( title ); - - QString location( failure->sourceLine().fileName().c_str() ); - location += " (" + - QString::number( failure->sourceLine().lineNumber() ) + - ")"; - _labelFailureLocation->setText( location ); - - _editFailureMessage->setText( failure->thrownException()->what() ); -} - - -void -TestRunnerDlg::clearFailureDetail() -{ - _groupFailureDetail->setTitle( tr("Failure detail for:...") ); - _labelFailureLocation->setText( QString::null ); - _editFailureMessage->setText( QString::null ); -} - - -void -TestRunnerDlg::beCanRunTest() -{ - _buttonRunTest->setEnabled( true ); - _buttonBrowse->setEnabled( true ); - _comboTest->setEnabled( true ); - _buttonStop->setDisabled( true ); - _buttonStop->setText( tr("Stop") ); - _buttonClose->setEnabled( true ); -} - - -void -TestRunnerDlg::beRunningTest() -{ - _buttonRunTest->setDisabled( true ); - _buttonBrowse->setDisabled( true ); - _comboTest->setDisabled( true ); - _buttonStop->setEnabled( true ); - _buttonStop->setText( tr("Stop") ); - _buttonClose->setDisabled( true ); -} - - -void -TestRunnerDlg::beStoppingTest() -{ - _buttonStop->setDisabled( true ); - _buttonStop->setText( tr("Stopping") ); -} diff --git a/src/qttestrunner/TestRunnerDlgImpl.h b/src/qttestrunner/TestRunnerDlgImpl.h deleted file mode 100644 index a3befc6..0000000 --- a/src/qttestrunner/TestRunnerDlgImpl.h +++ /dev/null @@ -1,58 +0,0 @@ -#ifndef TESTRUNNERDLG_H -#define TESTRUNNERDLG_H - -#include "testrunnerdlg.h" -#include <cppunit/Test.h> -class TestRunnerModel; -class MostRecentTests; -class TestFailureInfo; -class QListViewItem; - -class TestRunnerDlg : public TestRunnerDlgBase -{ - Q_OBJECT - -public: - TestRunnerDlg( QWidget* parent = 0, - const char* name = 0, - bool modal = FALSE, - WFlags fl = 0 ); - ~TestRunnerDlg(); - - void setModel( TestRunnerModel *model, - bool autorunTest ); - -public slots: - void refreshRecentTests(); - -protected slots: - void browseForTest(); - void runTest(); - void stopTest(); - void setNumberOfTestCase( int numberOfTestCase ); - void setNumberOfTestCaseRun( int numberOfRun ); - void setNumberOfTestCaseFailure( int numberOfFailure ); - void clearTestFailureList(); - void clearFailureDetail(); - void reportFailure( TestFailureInfo *failure ); - void showFailureDetailAt( QListViewItem *selection ); - void beCanRunTest(); - void beRunningTest(); - void beStoppingTest(); - -private: - - enum Columns - { - indexType =0, - indexTestName, - indexMessage, - indexFilename, - indexLineNumber - }; - - TestRunnerModel *_model; - MostRecentTests *_recentTests; -}; - -#endif // TESTRUNNERDLG_H diff --git a/src/qttestrunner/TestRunnerFailureEvent.cpp b/src/qttestrunner/TestRunnerFailureEvent.cpp deleted file mode 100644 index bceb2f6..0000000 --- a/src/qttestrunner/TestRunnerFailureEvent.cpp +++ /dev/null @@ -1,28 +0,0 @@ -// ////////////////////////////////////////////////////////////////////////// -// Implementation file TestRunnerFailureEvent.cpp for class TestRunnerFailureEvent -// (c)Copyright 2000, Baptiste Lepilleur. -// Created: 2001/09/22 -// ////////////////////////////////////////////////////////////////////////// - -#include "TestRunnerFailureEvent.h" -#include "TestRunnerModelThreadInterface.h" - - -TestRunnerFailureEvent::TestRunnerFailureEvent( TestFailureInfo *failure, - int numberOfFailure ) : - _failure( failure ), - _numberOfFailure( numberOfFailure ) -{ -} - - -TestRunnerFailureEvent::~TestRunnerFailureEvent() -{ -} - - -void -TestRunnerFailureEvent::process( TestRunnerModelThreadInterface *target ) -{ - target->eventNewFailure( _failure, _numberOfFailure ); -} diff --git a/src/qttestrunner/TestRunnerFailureEvent.h b/src/qttestrunner/TestRunnerFailureEvent.h deleted file mode 100644 index fa6fef0..0000000 --- a/src/qttestrunner/TestRunnerFailureEvent.h +++ /dev/null @@ -1,48 +0,0 @@ -// ////////////////////////////////////////////////////////////////////////// -// Header file TestRunnerFailureEvent.h for class TestRunnerFailureEvent -// (c)Copyright 2000, Baptiste Lepilleur. -// Created: 2001/09/22 -// ////////////////////////////////////////////////////////////////////////// -#ifndef TESTRUNNERFAILUREEVENT_H -#define TESTRUNNERFAILUREEVENT_H - -#include "TestRunnerThreadEvent.h" -class TestFailureInfo; - - -/*! \class TestRunnerFailureEvent - * \brief This class represents a new TestCase failure event. - */ -class TestRunnerFailureEvent : public TestRunnerThreadEvent -{ -public: - /*! Constructs a TestRunnerFailureEvent object. - */ - TestRunnerFailureEvent( TestFailureInfo *failure, - int numberOfFailure ); - - /// Destructor. - virtual ~TestRunnerFailureEvent(); - -private: - /// Prevents the use of the copy constructor. - TestRunnerFailureEvent( const TestRunnerFailureEvent © ); - - /// Prevents the use of the copy operator. - void operator =( const TestRunnerFailureEvent © ); - - void process( TestRunnerModelThreadInterface *target ); - -private: - TestFailureInfo *_failure; - int _numberOfFailure; -}; - - - -// Inlines methods for TestRunnerFailureEvent: -// ------------------------------------------- - - - -#endif // TESTRUNNERFAILUREEVENT_H diff --git a/src/qttestrunner/TestRunnerModel.cpp b/src/qttestrunner/TestRunnerModel.cpp deleted file mode 100644 index b224a34..0000000 --- a/src/qttestrunner/TestRunnerModel.cpp +++ /dev/null @@ -1,221 +0,0 @@ -// ////////////////////////////////////////////////////////////////////////// -// Implementation file TestRunnerModel.cpp for class TestRunnerModel -// (c)Copyright 2000, Baptiste Lepilleur. -// Created: 2001/09/20 -// ////////////////////////////////////////////////////////////////////////// - -#include <cppunit/TestResult.h> -#include "TestRunnerFailureEvent.h" -#include "TestRunnerModel.h" -#include "TestRunnerTestCaseRunEvent.h" -#include "TestRunnerThread.h" -#include "TestRunnerThreadFinishedEvent.h" - - -TestRunnerModel::TestRunnerModel( CPPUNIT_NS::Test *rootTest ) : - _rootTest( rootTest ), - _runnerThread( NULL ), - _result( NULL ) -{ -} - - -TestRunnerModel::~TestRunnerModel() -{ - delete _runnerThread; -} - - -CPPUNIT_NS::Test * -TestRunnerModel::rootTest() -{ - return _rootTest; -} - - -void -TestRunnerModel::resetTestReportCounterFor( CPPUNIT_NS::Test *testToRun ) -{ - if ( isTestRunning() ) - return; - - { - LockGuard guard( _lock ); - _numberOfTestCase = testToRun->countTestCases(); - _numberOfTestCaseRun =0; - _numberOfTestCaseFailure =0; - _failures.clear(); - } - emit failuresCleared(); - - emit numberOfTestCaseChanged( _numberOfTestCase ); - emit numberOfTestCaseRunChanged( _numberOfTestCaseRun ); - emit numberOfTestCaseFailureChanged( _numberOfTestCaseFailure ); -} - - -int -TestRunnerModel::numberOfTestCase() -{ - LockGuard guard( _lock ); - return _numberOfTestCase; -} - - -int -TestRunnerModel::numberOfTestCaseFailure() -{ - LockGuard guard( _lock ); - return _numberOfTestCaseFailure; -} - - -int -TestRunnerModel::numberOfTestCaseRun() -{ - LockGuard guard( _lock ); - return _numberOfTestCaseRun; -} - - -TestFailureInfo * -TestRunnerModel::failureAt( int index ) -{ - LockGuard guard( _lock ); - return _failures.at( index ); -} - - -void -TestRunnerModel::runTest( CPPUNIT_NS::Test *testToRun ) -{ - if ( isTestRunning() ) - return; - - resetTestReportCounterFor( testToRun ); - - { - LockGuard guard( _lock ); - delete _result; - _result = new CPPUNIT_NS::TestResult(); - _result->addListener( this ); - } - - emit testRunStarted( testToRun, _result ); - - LockGuard guard( _lock ); - _runnerThread = new TestRunnerThread( testToRun, - _result, - this, - new TestRunnerThreadFinishedEvent() ); -} - - -bool -TestRunnerModel::isTestRunning() -{ - LockGuard guard( _lock ); - return _runnerThread != NULL && _runnerThread->running(); -} - - -void -TestRunnerModel::stopRunningTest() -{ - { - LockGuard guard( _lock ); - if ( _result == NULL ) - return; - } - if ( isTestRunning() ) - { - LockGuard guard( _lock ); - _result->stop(); - } -} - - -// Called from the TestRunnerThread. -void -TestRunnerModel::startTest( CPPUNIT_NS::Test * /*test*/ ) -{ -} - - -// Called from the TestRunnerThread. -void -TestRunnerModel::addFailure( const CPPUNIT_NS::TestFailure &failure ) -{ - addFailureInfo( new TestFailureInfo( failure.failedTest(), - failure.thrownException(), - failure.isError() ) ); -} - - -// Called from the TestRunnerThread. -void -TestRunnerModel::endTest( CPPUNIT_NS::Test * /*test*/ ) -{ - int numberOfTestCaseRun; - { - LockGuard guard( _lock ); - numberOfTestCaseRun = ++_numberOfTestCaseRun; - } - - // emit signal asynchronously - QThread::postEvent( this, - new TestRunnerTestCaseRunEvent( numberOfTestCaseRun ) ); -} - - -// Called from the TestRunnerThread. -void -TestRunnerModel::addFailureInfo( TestFailureInfo *failure ) -{ - int numberOfTestCaseFailure; - { - LockGuard guard( _lock ); - _failures.append( failure ); - numberOfTestCaseFailure = ++_numberOfTestCaseFailure; - } - - // emit signals asynchronously - QThread::postEvent( this, - new TestRunnerFailureEvent( failure, - numberOfTestCaseFailure ) ); -} - - -bool -TestRunnerModel::event( QEvent *event ) -{ - if ( event->type() != QEvent::User ) - return false; - - TestRunnerThreadEvent *threadEvent = (TestRunnerThreadEvent *)event; - threadEvent->process( this ); - return true; -} - - -void -TestRunnerModel::eventNewFailure( TestFailureInfo *failure, - int numberOfFailure ) -{ - emit numberOfTestCaseFailureChanged( numberOfFailure ); - emit failureAdded( failure ); -} - - -void -TestRunnerModel::eventNumberOfTestRunChanged( int numberOfRun ) -{ - emit numberOfTestCaseRunChanged( numberOfRun ); -} - - -void -TestRunnerModel::eventTestRunnerThreadFinished() -{ - emit testRunFinished(); -} diff --git a/src/qttestrunner/TestRunnerModel.h b/src/qttestrunner/TestRunnerModel.h deleted file mode 100644 index ebd3a57..0000000 --- a/src/qttestrunner/TestRunnerModel.h +++ /dev/null @@ -1,154 +0,0 @@ -// ////////////////////////////////////////////////////////////////////////// -// Header file TestRunnerModel.h for class TestRunnerModel -// (c)Copyright 2000, Baptiste Lepilleur. -// Created: 2001/09/20 -// ////////////////////////////////////////////////////////////////////////// -#ifndef TESTRUNNERMODEL_H -#define TESTRUNNERMODEL_H - -#include <cppunit/Test.h> -#include <cppunit/TestListener.h> -#include <qptrlist.h> -#include <qobject.h> -#include <qthread.h> -#include "TestFailureInfo.h" -#include "TestRunnerModelThreadInterface.h" -class TestRunnerThread; - -/*! \class TestRunnerModel - * \brief This class represents the model for the TestRunner. - * - * Warning: methods that override CppUnit::TestListener are called - * from the TestRunner thread ! - * - * Warning: _lock is not recursive. Might want to introduce Doug Lea - * Thread Interface pattern for methods used while locked (isTestRunning()). - * - * Refactoring note: a large part of this object actually duplicate - * TestResult. - */ -class TestRunnerModel : public QObject, - private CPPUNIT_NS::TestListener, - private TestRunnerModelThreadInterface -{ - Q_OBJECT -public: - /*! Constructs a TestRunnerModel object. - */ - TestRunnerModel( CPPUNIT_NS::Test *rootTest ); - - /*! Destructor. - */ - virtual ~TestRunnerModel(); - - CPPUNIT_NS::Test *rootTest(); - - int numberOfTestCase(); - int numberOfTestCaseFailure(); - int numberOfTestCaseRun(); - - TestFailureInfo *failureAt( int index ); - - - bool isTestRunning(); - -signals: - void numberOfTestCaseChanged( int numberOfTestCase ); - void numberOfTestCaseRunChanged( int numberOfRun ); - void numberOfTestCaseFailureChanged( int numberOfFailure ); - void failureAdded( TestFailureInfo *failure ); - void failuresCleared(); - void testRunStarted( CPPUNIT_NS::Test *runningTest, - CPPUNIT_NS::TestResult *result ); - void testRunFinished(); - -public slots: - void resetTestReportCounterFor( CPPUNIT_NS::Test *testToRun ); - - /*! Request to run the specified test. - * Returns immedialty. If a test is already running, then - * the run request is ignored. - */ - void runTest( CPPUNIT_NS::Test *testToRun ); - - /*! Request to stop running test. - * This methods returns immediately. testRunFinished() signal - * should be used to now when the test actually stopped running. - */ - void stopRunningTest(); - -private: - /// Prevents the use of the copy constructor. - TestRunnerModel( const TestRunnerModel © ); - - /// Prevents the use of the copy operator. - void operator =( const TestRunnerModel © ); - - /// Called from the TestRunnerThread. - void startTest( CPPUNIT_NS::Test *test ); - - /// Called from the TestRunnerThread. - void addFailure( const CPPUNIT_NS::TestFailure &failure ); - - /// Called from the TestRunnerThread. - void endTest( CPPUNIT_NS::Test *test ); - - /// Called from the TestRunnerThread. - void addFailureInfo( TestFailureInfo *failure ); - - bool event( QEvent *event ); - - /*! Emits new failure signals. - * Called by the TestRunnerThreadEvent from the GUI thread to - * emit the following signals: - * - numberOfTestCaseFailureChanged() - * - failureAdded() - */ - void eventNewFailure( TestFailureInfo *failure, - int numberOfFailure ); - - /*! Emits numberOfTestCaseRunChanged() signal. - * Called by the TestRunnerThreadEvent from the GUI thread to - * emit the numberOfTestCaseRunChanged() signal. - */ - void eventNumberOfTestRunChanged( int numberOfRun ); - - void eventTestRunnerThreadFinished(); - -private: - class LockGuard - { - public: - LockGuard( QMutex &mutex ) : _mutex( mutex ) - { - _mutex.lock(); - } - - ~LockGuard() - { - _mutex.unlock(); - } - - private: - QMutex &_mutex; - }; - - - QMutex _lock; - CPPUNIT_NS::Test *_rootTest; - int _numberOfTestCase; - int _numberOfTestCaseRun; - int _numberOfTestCaseFailure; - QList<TestFailureInfo> _failures; - TestRunnerThread *_runnerThread; - CPPUNIT_NS::TestResult *_result; -}; - - - -// Inlines methods for TestRunnerModel: -// ------------------------------------ - - - -#endif // TESTRUNNERMODEL_H diff --git a/src/qttestrunner/TestRunnerModelThreadInterface.cpp b/src/qttestrunner/TestRunnerModelThreadInterface.cpp deleted file mode 100644 index 3196054..0000000 --- a/src/qttestrunner/TestRunnerModelThreadInterface.cpp +++ /dev/null @@ -1,8 +0,0 @@ -// ////////////////////////////////////////////////////////////////////////// -// Implementation file TestRunnerModelThreadInterface.cpp for class TestRunnerModelThreadInterface -// (c)Copyright 2000, Baptiste Lepilleur. -// Created: 2001/09/21 -// ////////////////////////////////////////////////////////////////////////// - -#include "TestRunnerModelThreadInterface.h" - diff --git a/src/qttestrunner/TestRunnerModelThreadInterface.h b/src/qttestrunner/TestRunnerModelThreadInterface.h deleted file mode 100644 index 6a663a5..0000000 --- a/src/qttestrunner/TestRunnerModelThreadInterface.h +++ /dev/null @@ -1,35 +0,0 @@ -// ////////////////////////////////////////////////////////////////////////// -// Header file TestRunnerModelThreadInterface.h for class TestRunnerModelThreadInterface -// (c)Copyright 2000, Baptiste Lepilleur. -// Created: 2001/09/21 -// ////////////////////////////////////////////////////////////////////////// -#ifndef TESTRUNNERMODELTHREADINTERFACE_H -#define TESTRUNNERMODELTHREADINTERFACE_H - -class TestFailureInfo; - -/*! \class TestRunnerModelThreadInterface - * \brief This class represents the interface used to process gui thread event. - */ -class TestRunnerModelThreadInterface -{ -public: - /// Destructor. - virtual ~TestRunnerModelThreadInterface() {} - - virtual void eventNewFailure( TestFailureInfo *failure, - int numberOfFailure ) =0; - - virtual void eventNumberOfTestRunChanged( int numberOfRun ) =0; - - virtual void eventTestRunnerThreadFinished() =0; -}; - - - -// Inlines methods for TestRunnerModelThreadInterface: -// --------------------------------------------------- - - - -#endif // TESTRUNNERMODELTHREADINTERFACE_H diff --git a/src/qttestrunner/TestRunnerTestCaseRunEvent.cpp b/src/qttestrunner/TestRunnerTestCaseRunEvent.cpp deleted file mode 100644 index 177b358..0000000 --- a/src/qttestrunner/TestRunnerTestCaseRunEvent.cpp +++ /dev/null @@ -1,26 +0,0 @@ -// ////////////////////////////////////////////////////////////////////////// -// Implementation file TestRunnerTestCaseRunEvent.cpp for class TestRunnerTestCaseRunEvent -// (c)Copyright 2000, Baptiste Lepilleur. -// Created: 2001/09/22 -// ////////////////////////////////////////////////////////////////////////// - -#include "TestRunnerModelThreadInterface.h" -#include "TestRunnerTestCaseRunEvent.h" - - -TestRunnerTestCaseRunEvent::TestRunnerTestCaseRunEvent( int numberOfRun ) : - _numberOfRun( numberOfRun ) -{ -} - - -TestRunnerTestCaseRunEvent::~TestRunnerTestCaseRunEvent() -{ -} - - -void -TestRunnerTestCaseRunEvent::process( TestRunnerModelThreadInterface *target ) -{ - target->eventNumberOfTestRunChanged( _numberOfRun ); -} diff --git a/src/qttestrunner/TestRunnerTestCaseRunEvent.h b/src/qttestrunner/TestRunnerTestCaseRunEvent.h deleted file mode 100644 index bd2c635..0000000 --- a/src/qttestrunner/TestRunnerTestCaseRunEvent.h +++ /dev/null @@ -1,45 +0,0 @@ -// ////////////////////////////////////////////////////////////////////////// -// Header file TestRunnerTestCaseRunEvent.h for class TestRunnerTestCaseRunEvent -// (c)Copyright 2000, Baptiste Lepilleur. -// Created: 2001/09/22 -// ////////////////////////////////////////////////////////////////////////// -#ifndef TESTRUNNERTESTCASERUNEVENT_H -#define TESTRUNNERTESTCASERUNEVENT_H - -#include "TestRunnerThreadEvent.h" - - -/*! \class TestRunnerTestCaseRunEvent - * \brief This class represents a new TestCase run event. - */ -class TestRunnerTestCaseRunEvent : public TestRunnerThreadEvent -{ -public: - /*! Constructs a TestRunnerTestCaseRunEvent object. - */ - TestRunnerTestCaseRunEvent( int numberOfRun ); - - /// Destructor. - virtual ~TestRunnerTestCaseRunEvent(); - -private: - /// Prevents the use of the copy constructor. - TestRunnerTestCaseRunEvent( const TestRunnerTestCaseRunEvent © ); - - /// Prevents the use of the copy operator. - void operator =( const TestRunnerTestCaseRunEvent © ); - - void process( TestRunnerModelThreadInterface *target ); - -private: - int _numberOfRun; -}; - - - -// Inlines methods for TestRunnerTestCaseRunEvent: -// ----------------------------------------------- - - - -#endif // TESTRUNNERTESTCASERUNEVENT_H diff --git a/src/qttestrunner/TestRunnerThread.cpp b/src/qttestrunner/TestRunnerThread.cpp index cc45526..dfc5cfe 100644 --- a/src/qttestrunner/TestRunnerThread.cpp +++ b/src/qttestrunner/TestRunnerThread.cpp @@ -1,38 +1,61 @@ -// ////////////////////////////////////////////////////////////////////////// -// Implementation file TestRunnerThread.cpp for class TestRunnerThread -// (c)Copyright 2000, Baptiste Lepilleur. -// Created: 2001/09/22 -// ////////////////////////////////////////////////////////////////////////// +#include <QMutex> +#include <QMutexLocker> #include "TestRunnerThread.h" -#include "TestRunnerThreadFinishedEvent.h" +// +// TestRunnerThreadPrivate +// -TestRunnerThread::TestRunnerThread( CPPUNIT_NS::Test *testToRun, - CPPUNIT_NS::TestResult *result, - QObject *eventTarget, - TestRunnerThreadFinishedEvent *finishedEvent ) : - _testToRun( testToRun ), - _result( result ), - _eventTarget( eventTarget ), - _finishedEvent( finishedEvent ) +class TestRunnerThreadPrivate { - start(); -} - + typedef CPPUNIT_NS::Test Test; + typedef CPPUNIT_NS::TestResult TestResult; + +public: + TestRunnerThreadPrivate() + : _test(NULL) + , _result(NULL) + , _mutex() + {} + +public: + Test *_test; + TestResult *_result; + QMutex _mutex; +}; + +// +// TestRunnerThread +// + +TestRunnerThread::TestRunnerThread(QObject *parent) + : QThread(parent) + , _d(new TestRunnerThreadPrivate) +{} TestRunnerThread::~TestRunnerThread() +{} + +void TestRunnerThread::adviseToStop() { + if (_d->_result) + _d->_result->stop(); } +void TestRunnerThread::setTestInformation(Test *testToRun, TestResult *result) +{ + QMutexLocker lock(&_d->_mutex); + _d->_test = testToRun; + _d->_result = result; +} -void -TestRunnerThread::run() +void TestRunnerThread::run() { - _testToRun->run( _result ); + QMutexLocker lock(&_d->_mutex); + if (_d->_test != NULL && _d->_result != NULL) + _d->_test->run(_d->_result); - // Signal TestRunnerModel GUI thread - QThread::postEvent( _eventTarget, _finishedEvent ); - _eventTarget = NULL; - _finishedEvent = NULL; + _d->_test = NULL; + _d->_result = NULL; } diff --git a/src/qttestrunner/TestRunnerThread.h b/src/qttestrunner/TestRunnerThread.h index 54cb4f1..68d1529 100644 --- a/src/qttestrunner/TestRunnerThread.h +++ b/src/qttestrunner/TestRunnerThread.h @@ -1,55 +1,54 @@ -// ////////////////////////////////////////////////////////////////////////// -// Header file TestRunnerThread.h for class TestRunnerThread -// (c)Copyright 2000, Baptiste Lepilleur. -// Created: 2001/09/22 -// ////////////////////////////////////////////////////////////////////////// #ifndef TESTRUNNERTHREAD_H #define TESTRUNNERTHREAD_H -#include <qthread.h> +#include <QScopedPointer> +#include <QThread> + #include <cppunit/Test.h> #include <cppunit/TestResult.h> -class QObject; -class TestRunnerThreadFinishedEvent; - -/*! \class TestRunnerThread - * \brief This class represents the thread used to run TestCase. +/** + * \class TestRunnerThread + * \brief This class represents the thread used to run the test cases asynchronously. */ class TestRunnerThread : public QThread { -public: - /*! Constructs a TestRunnerThread object. - */ - TestRunnerThread( CPPUNIT_NS::Test *testToRun, - CPPUNIT_NS::TestResult *result, - QObject *eventTarget, - TestRunnerThreadFinishedEvent *finishedEvent ); + Q_OBJECT + Q_DISABLE_COPY(TestRunnerThread) - /// Destructor. - virtual ~TestRunnerThread(); + typedef CPPUNIT_NS::Test Test; + typedef CPPUNIT_NS::TestResult TestResult; -private: - /// Prevents the use of the copy constructor. - TestRunnerThread( const TestRunnerThread © ); - - /// Prevents the use of the copy operator. - void operator =( const TestRunnerThread © ); +public: + /*! + * \brief Constructs a TestRunner thread object. + * \param parent A pointer to a parent QObject + */ + TestRunnerThread(QObject *parent = 0); + + /*! + * \brief Destructor + */ + ~TestRunnerThread(); + +public slots: + /*! + * \brief Stops a running test + */ + void adviseToStop(); + + /*! + * \brief Sets information for the test to run and the output result + * \param testToRun A pointer to a Test which should be run + * \param result A pointer to a TestResult object. + */ + void setTestInformation(Test *testToRun, TestResult *result); - void run(); +private: + void run(); private: - CPPUNIT_NS::Test *_testToRun; - CPPUNIT_NS::TestResult *_result; - QObject *_eventTarget; - TestRunnerThreadFinishedEvent *_finishedEvent; + QScopedPointer<class TestRunnerThreadPrivate> _d; }; - - -// Inlines methods for TestRunnerThread: -// ------------------------------------- - - - -#endif // TESTRUNNERTHREAD_H +#endif // TESTRUNNERTHREAD_H diff --git a/src/qttestrunner/TestRunnerThreadEvent.cpp b/src/qttestrunner/TestRunnerThreadEvent.cpp deleted file mode 100644 index 17be770..0000000 --- a/src/qttestrunner/TestRunnerThreadEvent.cpp +++ /dev/null @@ -1,19 +0,0 @@ -// ////////////////////////////////////////////////////////////////////////// -// Implementation file TestRunnerThreadEvent.cpp for class TestRunnerThreadEvent -// (c)Copyright 2000, Baptiste Lepilleur. -// Created: 2001/09/21 -// ////////////////////////////////////////////////////////////////////////// - -#include "TestRunnerThreadEvent.h" - - -TestRunnerThreadEvent::TestRunnerThreadEvent() : - QCustomEvent( User ) -{ -} - - -TestRunnerThreadEvent::~TestRunnerThreadEvent() -{ -} - diff --git a/src/qttestrunner/TestRunnerThreadEvent.h b/src/qttestrunner/TestRunnerThreadEvent.h deleted file mode 100644 index 32389bd..0000000 --- a/src/qttestrunner/TestRunnerThreadEvent.h +++ /dev/null @@ -1,37 +0,0 @@ -// ////////////////////////////////////////////////////////////////////////// -// Header file TestRunnerThreadEvent.h for class TestRunnerThreadEvent -// (c)Copyright 2000, Baptiste Lepilleur. -// Created: 2001/09/21 -// ////////////////////////////////////////////////////////////////////////// -#ifndef TESTRUNNERTHREADEVENT_H -#define TESTRUNNERTHREADEVENT_H - -#include <qevent.h> -class TestRunnerModelThreadInterface; - -/*! \class TestRunnerThreadEvent - * \brief This class represents an event send by the test runner thread. - */ -class TestRunnerThreadEvent : public QCustomEvent -{ -public: - /*! Constructs a TestRunnerThreadEvent object. - */ - TestRunnerThreadEvent(); - - /// Destructor. - virtual ~TestRunnerThreadEvent(); - - virtual void process( TestRunnerModelThreadInterface *target ) =0; - -private: - /// Prevents the use of the copy constructor. - TestRunnerThreadEvent( const TestRunnerThreadEvent © ); - - /// Prevents the use of the copy operator. - void operator =( const TestRunnerThreadEvent © ); -}; - - - -#endif // TESTRUNNERTHREADEVENT_H diff --git a/src/qttestrunner/TestRunnerThreadFinishedEvent.cpp b/src/qttestrunner/TestRunnerThreadFinishedEvent.cpp deleted file mode 100644 index 5c2f2ba..0000000 --- a/src/qttestrunner/TestRunnerThreadFinishedEvent.cpp +++ /dev/null @@ -1,25 +0,0 @@ -// ////////////////////////////////////////////////////////////////////////// -// Implementation file TestRunnerThreadFinishedEvent.cpp for class TestRunnerThreadFinishedEvent -// (c)Copyright 2000, Baptiste Lepilleur. -// Created: 2001/09/22 -// ////////////////////////////////////////////////////////////////////////// - -#include "TestRunnerThreadFinishedEvent.h" -#include "TestRunnerModelThreadInterface.h" - - -TestRunnerThreadFinishedEvent::TestRunnerThreadFinishedEvent() -{ -} - - -TestRunnerThreadFinishedEvent::~TestRunnerThreadFinishedEvent() -{ -} - - -void -TestRunnerThreadFinishedEvent::process( TestRunnerModelThreadInterface *target ) -{ - target->eventTestRunnerThreadFinished(); -} diff --git a/src/qttestrunner/TestRunnerThreadFinishedEvent.h b/src/qttestrunner/TestRunnerThreadFinishedEvent.h deleted file mode 100644 index b390e7a..0000000 --- a/src/qttestrunner/TestRunnerThreadFinishedEvent.h +++ /dev/null @@ -1,42 +0,0 @@ -// ////////////////////////////////////////////////////////////////////////// -// Header file TestRunnerThreadFinishedEvent.h for class TestRunnerThreadFinishedEvent -// (c)Copyright 2000, Baptiste Lepilleur. -// Created: 2001/09/22 -// ////////////////////////////////////////////////////////////////////////// -#ifndef TESTRUNNERTHREADFINISHEDEVENT_H -#define TESTRUNNERTHREADFINISHEDEVENT_H - -#include "TestRunnerThreadEvent.h" - - -/*! \class TestRunnerThreadFinishedEvent - * \brief This class represents an event indicating that the TestRunnerThread finished. - */ -class TestRunnerThreadFinishedEvent : public TestRunnerThreadEvent -{ -public: - /*! Constructs a TestRunnerThreadFinishedEvent object. - */ - TestRunnerThreadFinishedEvent(); - - /// Destructor. - virtual ~TestRunnerThreadFinishedEvent(); - - void process( TestRunnerModelThreadInterface *target ); - -private: - /// Prevents the use of the copy constructor. - TestRunnerThreadFinishedEvent( const TestRunnerThreadFinishedEvent © ); - - /// Prevents the use of the copy operator. - void operator =( const TestRunnerThreadFinishedEvent © ); -}; - - - -// Inlines methods for TestRunnerThreadFinishedEvent: -// -------------------------------------------------- - - - -#endif // TESTRUNNERTHREADFINISHEDEVENT_H diff --git a/src/qttestrunner/TestRunnerWindow.cpp b/src/qttestrunner/TestRunnerWindow.cpp new file mode 100644 index 0000000..b187fea --- /dev/null +++ b/src/qttestrunner/TestRunnerWindow.cpp @@ -0,0 +1,17 @@ +#include <cppunit/Exception.h> + +#include "TestRunnerWindow.h" +#include "TestRunnerWindowPrivate.h" + +TestRunnerWindow::TestRunnerWindow(Test *rootTest, QWidget* parent, Qt::WindowFlags flags) + : QWidget(parent, flags) + , _d(new TestRunnerWindowPrivate(rootTest, this)) +{} + +TestRunnerWindow::~TestRunnerWindow() +{} + +void TestRunnerWindow::startTesting() +{ + _d->startTesting(); +} diff --git a/src/qttestrunner/TestRunnerWindow.h b/src/qttestrunner/TestRunnerWindow.h new file mode 100644 index 0000000..9133bf8 --- /dev/null +++ b/src/qttestrunner/TestRunnerWindow.h @@ -0,0 +1,46 @@ +#ifndef TESTRUNNERWINDOW_H +#define TESTRUNNERWINDOW_H + +#include <QScopedPointer> +#include <QWidget> + +#include <cppunit/Test.h> + +/*! + * \class TestRunnerWindow + * \brief This class represents the external interface to the test runner dialog + */ +class TestRunnerWindow : public QWidget +{ + Q_OBJECT + + typedef CPPUNIT_NS::Test Test; + +public: + /*! + * \brief Constructs a new test runner dialog + * \param rootTest The root test to use + * \param parent A pointer to a parent QWidget + * \param flags Window flags controlling the appearance of the dialog + */ + TestRunnerWindow(Test* rootTest, QWidget* parent = 0, Qt::WindowFlags flags = 0); + + /*! + * \brief Destructor + */ + ~TestRunnerWindow(); + +public slots: + /*! + * \brief Runs the registered root test (and all of its child tests) + * + * This slot is used by the test runner to _automatically_ start testing once the dialog + * is displayed. + */ + void startTesting(); + +private: + QScopedPointer<class TestRunnerWindowPrivate> _d; +}; + +#endif // TESTRUNNERWINDOW_H diff --git a/src/qttestrunner/TestRunnerWindow.ui b/src/qttestrunner/TestRunnerWindow.ui new file mode 100644 index 0000000..4980f26 --- /dev/null +++ b/src/qttestrunner/TestRunnerWindow.ui @@ -0,0 +1,228 @@ +<?xml version="1.0" encoding="UTF-8"?> +<ui version="4.0"> + <class>TestRunnerWindow</class> + <widget class="QWidget" name="TestRunnerWindow"> + <property name="geometry"> + <rect> + <x>0</x> + <y>0</y> + <width>605</width> + <height>595</height> + </rect> + </property> + <property name="windowTitle"> + <string>Qt Test Runner</string> + </property> + <layout class="QGridLayout" name="gridLayout"> + <item row="0" column="0" colspan="6"> + <widget class="QComboBox" name="comboTest"> + <property name="maxVisibleItems"> + <number>20</number> + </property> + <property name="maxCount"> + <number>20</number> + </property> + <property name="insertPolicy"> + <enum>QComboBox::InsertAtTop</enum> + </property> + <property name="sizeAdjustPolicy"> + <enum>QComboBox::AdjustToContents</enum> + </property> + <property name="duplicatesEnabled"> + <bool>false</bool> + </property> + </widget> + </item> + <item row="1" column="6"> + <widget class="QPushButton" name="pushButton_Run"> + <property name="text"> + <string>Run</string> + </property> + </widget> + </item> + <item row="2" column="6"> + <widget class="QPushButton" name="pushButton_Stop"> + <property name="text"> + <string>Stop Test</string> + </property> + </widget> + </item> + <item row="3" column="6"> + <widget class="QPushButton" name="pushButton_Close"> + <property name="text"> + <string>Close</string> + </property> + </widget> + </item> + <item row="0" column="6"> + <widget class="QPushButton" name="pushButton_Browse"> + <property name="text"> + <string>Browse...</string> + </property> + </widget> + </item> + <item row="3" column="0"> + <widget class="QLabel" name="label_2"> + <property name="sizePolicy"> + <sizepolicy hsizetype="Fixed" vsizetype="Preferred"> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="text"> + <string>Test Cases:</string> + </property> + </widget> + </item> + <item row="3" column="1"> + <widget class="QLabel" name="label_TestCaseCount"> + <property name="text"> + <string>0</string> + </property> + </widget> + </item> + <item row="3" column="2"> + <widget class="QLabel" name="label_3"> + <property name="sizePolicy"> + <sizepolicy hsizetype="Fixed" vsizetype="Preferred"> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="text"> + <string>Run:</string> + </property> + </widget> + </item> + <item row="3" column="3"> + <widget class="QLabel" name="label_TestRunCount"> + <property name="text"> + <string>0</string> + </property> + </widget> + </item> + <item row="3" column="4"> + <widget class="QLabel" name="label_4"> + <property name="sizePolicy"> + <sizepolicy hsizetype="Fixed" vsizetype="Preferred"> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="text"> + <string>Failure:</string> + </property> + </widget> + </item> + <item row="3" column="5"> + <widget class="QLabel" name="label_FailureCount"> + <property name="text"> + <string>0</string> + </property> + </widget> + </item> + <item row="4" column="0" colspan="7"> + <widget class="QProgressBar" name="progressBar_Run"> + <property name="value"> + <number>0</number> + </property> + </widget> + </item> + <item row="6" column="0" colspan="7"> + <widget class="QGroupBox" name="groupBox_Details"> + <property name="sizePolicy"> + <sizepolicy hsizetype="Preferred" vsizetype="Expanding"> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="title"> + <string>Failure Details for: ...</string> + </property> + <layout class="QGridLayout" name="gridLayout_2"> + <item row="0" column="0"> + <widget class="QLabel" name="label"> + <property name="text"> + <string>Location:</string> + </property> + </widget> + </item> + <item row="2" column="0"> + <widget class="QLabel" name="label_5"> + <property name="text"> + <string>Message:</string> + </property> + </widget> + </item> + <item row="0" column="1"> + <widget class="QLineEdit" name="lineEdit_Location"> + <property name="minimumSize"> + <size> + <width>0</width> + <height>24</height> + </size> + </property> + <property name="readOnly"> + <bool>true</bool> + </property> + </widget> + </item> + <item row="2" column="1" colspan="2"> + <widget class="QPlainTextEdit" name="plainTextEdit_Message"> + <property name="sizePolicy"> + <sizepolicy hsizetype="Expanding" vsizetype="Preferred"> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="readOnly"> + <bool>true</bool> + </property> + </widget> + </item> + <item row="0" column="2"> + <widget class="QToolButton" name="toolButton_View"> + <property name="enabled"> + <bool>false</bool> + </property> + <property name="text"> + <string>View</string> + </property> + </widget> + </item> + </layout> + </widget> + </item> + <item row="5" column="0" colspan="7"> + <widget class="QTableView" name="failureView"> + <property name="editTriggers"> + <set>QAbstractItemView::NoEditTriggers</set> + </property> + <property name="alternatingRowColors"> + <bool>true</bool> + </property> + <property name="selectionMode"> + <enum>QAbstractItemView::SingleSelection</enum> + </property> + <property name="selectionBehavior"> + <enum>QAbstractItemView::SelectRows</enum> + </property> + <property name="gridStyle"> + <enum>Qt::NoPen</enum> + </property> + <attribute name="horizontalHeaderCascadingSectionResizes"> + <bool>true</bool> + </attribute> + <attribute name="horizontalHeaderStretchLastSection"> + <bool>true</bool> + </attribute> + <attribute name="verticalHeaderVisible"> + <bool>false</bool> + </attribute> + </widget> + </item> + </layout> + </widget> + <resources/> + <connections/> +</ui> diff --git a/src/qttestrunner/TestRunnerWindowPrivate.cpp b/src/qttestrunner/TestRunnerWindowPrivate.cpp new file mode 100644 index 0000000..abdfc92 --- /dev/null +++ b/src/qttestrunner/TestRunnerWindowPrivate.cpp @@ -0,0 +1,231 @@ +#include <QDesktopServices> +#include <QFile> +#include <QMutex> +#include <QUrl> +#include <cppunit/Exception.h> + +#include "TestRunnerWindowPrivate.h" +#include "ui_TestRunnerWindow.h" + +namespace { + +class QtSynchronizationObject : public CPPUNIT_NS::SynchronizedObject::SynchronizationObject +{ +public: + QtSynchronizationObject() + : CPPUNIT_NS::SynchronizedObject::SynchronizationObject() + {} + + ~QtSynchronizationObject() + {} + + void lock() + { + _mutex.lock(); + } + + void unlock() + { + _mutex.unlock(); + } + +private: + QMutex _mutex; +}; + +} // unnamed namespace + +// +// TestRunnerWindowPrivate +// + +TestRunnerWindowPrivate::TestRunnerWindowPrivate(Test *root, QWidget *parent) + : QObject(parent) + , _model(new TestFailureTableModel(parent)) + , _thread(new TestRunnerThread(parent)) + , _browser(new TestBrowser(root, parent)) + , _listener(new QtTestListener(parent)) + , _rootTest(root) + , _srcfile() + , _result() + , _ui(new Ui::TestRunnerWindow) +{ + _ui->setupUi(parent); + setup(); + updateTestList(_rootTest); +} + +TestRunnerWindowPrivate::~TestRunnerWindowPrivate() +{} + +void TestRunnerWindowPrivate::setup() +{ + qRegisterMetaType<QtTestFailure>("QtTestFailure"); + + connect(_thread, SIGNAL(started()), SLOT(testingStarted())); + connect(_thread, SIGNAL(finished()), SLOT(testingFinished())); + + connect(_ui->pushButton_Browse, SIGNAL(clicked()), _browser, SLOT(exec())); + connect(_ui->pushButton_Stop, SIGNAL(clicked()), SLOT(stopTesting())); + connect(_ui->pushButton_Run, SIGNAL(clicked()), SLOT(startTesting())); + connect(_ui->pushButton_Close, SIGNAL(clicked()), parent(), SLOT(close())); + connect(_ui->toolButton_View, SIGNAL(clicked()), SLOT(viewSourceFile())); + connect(_ui->comboTest, SIGNAL(currentIndexChanged(int)), SLOT(testIndexChanged(int))); + + connect(_ui->failureView, SIGNAL(activated(QModelIndex)), + SLOT(displayFailureDetail(QModelIndex))); + connect(_ui->failureView, SIGNAL(clicked(QModelIndex)), + SLOT(displayFailureDetail(QModelIndex))); + connect(_browser, SIGNAL(testSelected(Test*)), + SLOT(updateTestList(Test*))); + connect(_listener, SIGNAL(testFailed(QtTestFailure)), + _model, SLOT(addFailure(QtTestFailure))); + + connect(_listener, SIGNAL(testCaseFinished()), SLOT(testCaseFinished())); + connect(_listener, SIGNAL(testFailed(QtTestFailure)), SLOT(testCaseFailed())); + + _ui->failureView->setModel(_model); +} + +void TestRunnerWindowPrivate::startTesting() +{ + int currentIndex = _ui->comboTest->currentIndex(); + Test *testToRun = _ui->comboTest->itemData(currentIndex).value<Test*>(); + + if (testToRun == NULL) + return; + + clearPreviousRun(); + _result.reset(new TestResult(new QtSynchronizationObject)); + _result->addListener(_listener); + + connect(_listener, SIGNAL(testCaseStarted()), SLOT(testingStarted())); + connect(_listener, SIGNAL(testCaseFinished()), SLOT(testingFinished())); + + _thread->setTestInformation(testToRun, _result.data()); + _thread->start(); +} + +void TestRunnerWindowPrivate::stopTesting() +{ + if (_thread->isRunning()) + { + _ui->pushButton_Stop->setText(tr("Stopping")); + _thread->adviseToStop(); + } +} + +void TestRunnerWindowPrivate::testingStarted() +{ + _ui->comboTest->setEnabled(false); + _ui->pushButton_Browse->setEnabled(false); + _ui->pushButton_Close->setEnabled(false); + _ui->pushButton_Run->setEnabled(false); + _ui->pushButton_Stop->setEnabled(true); +} + +void TestRunnerWindowPrivate::testingFinished() +{ + _ui->comboTest->setEnabled(true); + _ui->pushButton_Browse->setEnabled(true); + _ui->pushButton_Close->setEnabled(true); + _ui->pushButton_Run->setEnabled(true); + _ui->pushButton_Stop->setEnabled(false); + + if (_ui->pushButton_Stop->text() != tr("Stop Test")) + _ui->pushButton_Stop->setText(tr("Stop Test")); +} + +void TestRunnerWindowPrivate::testIndexChanged(int index) +{ + Test *testToRun = _ui->comboTest->itemData(index).value<Test*>(); + + setTestCaseCount(testToRun->countTestCases()); + clearPreviousRun(); +} + +void TestRunnerWindowPrivate::clearPreviousRun() +{ + _model->clear(); + _ui->label_FailureCount->setText("0"); + _ui->label_TestRunCount->setText("0"); + _ui->progressBar_Run->setValue(0); + _ui->toolButton_View->setEnabled(false); + clearFailureDetail(); +} + +void TestRunnerWindowPrivate::setTestCaseCount(int count) +{ + _ui->label_TestCaseCount->setText(QString::number(count)); + _ui->progressBar_Run->setMaximum(count); +} + +void TestRunnerWindowPrivate::testCaseFinished() +{ + int val = _ui->progressBar_Run->value() + 1; + _ui->label_TestRunCount->setText(QString::number(val)); + _ui->progressBar_Run->setValue(val); +} + +void TestRunnerWindowPrivate::testCaseFailed() +{ + int val = _ui->label_FailureCount->text().toInt() + 1; + _ui->label_FailureCount->setText(QString::number(val)); +} + +void TestRunnerWindowPrivate::clearFailureDetail() +{ + _ui->groupBox_Details->setTitle(tr("Failure detail for: ...")); + _ui->lineEdit_Location->clear(); + _ui->plainTextEdit_Message->clear(); +} + +void TestRunnerWindowPrivate::displayFailureDetail(const QModelIndex &index) +{ + QVariant data = _model->data(index, Qt::UserRole); + QtTestFailure failure = data.value<QtTestFailure>(); + + QString title = tr("Failure detail for: ") + failure.failedTestName(); + _ui->groupBox_Details->setTitle(title); + + QString location = QString::fromStdString(failure.sourceLine().fileName()); + bool fileExists = QFile::exists(location); + + if (fileExists && !_ui->toolButton_View->isEnabled()) + { + _srcfile = location; + _ui->toolButton_View->setEnabled(true); + } + else if(!fileExists && _ui->toolButton_View->isEnabled()) + { + _ui->toolButton_View->setEnabled(false); + } + + location += " (" + QString::number(failure.sourceLine().lineNumber()) + ")"; + _ui->lineEdit_Location->setText(location); + + _ui->plainTextEdit_Message->setPlainText(failure.message()); +} + +void TestRunnerWindowPrivate::updateTestList(Test *test) +{ + QVariant data; + QString testName = QString::fromStdString(test->getName()); + + int duplicateIndex = _ui->comboTest->findText(testName); + if (duplicateIndex > -1) + _ui->comboTest->removeItem(duplicateIndex); + + data.setValue(test); + _ui->comboTest->insertItem(0, testName , data); + _ui->comboTest->setCurrentIndex(0); +} + +void TestRunnerWindowPrivate::viewSourceFile() +{ + if (_srcfile.isEmpty()) + return; + + QUrl location("file:///" + _srcfile); + QDesktopServices::openUrl(location); +} diff --git a/src/qttestrunner/TestRunnerWindowPrivate.h b/src/qttestrunner/TestRunnerWindowPrivate.h new file mode 100644 index 0000000..f52fac9 --- /dev/null +++ b/src/qttestrunner/TestRunnerWindowPrivate.h @@ -0,0 +1,64 @@ +#ifndef TESTRUNNERWINDOWPRIVATE_H +#define TESTRUNNERWINDOWPRIVATE_H + +#include <QScopedPointer> +#include <QWidget> + +#include "QtTestFailure.h" +#include "QtTestListener.h" +#include "TestFailureTableModel.h" +#include "TestRunnerThread.h" +#include "TestBrowser.h" + +#include <cppunit/Test.h> + +namespace Ui { +class TestRunnerWindow; +} + +class TestRunnerWindowPrivate : public QObject +{ + Q_OBJECT + Q_DISABLE_COPY(TestRunnerWindowPrivate) + + typedef CPPUNIT_NS::Test Test; + typedef CPPUNIT_NS::TestResult TestResult; + +public: + TestRunnerWindowPrivate(Test *root, QWidget *parent); + ~TestRunnerWindowPrivate(); + +public slots: + void startTesting(); + +private: + void setup(); + +private slots: + void stopTesting(); + void testingStarted(); + void testingFinished(); + void testIndexChanged(int index); + void clearPreviousRun(); + void setTestCaseCount(int count); + void testCaseFinished(); + void testCaseFailed(); + void clearFailureDetail(); + void displayFailureDetail(const QModelIndex &index); + void updateTestList(Test *test); + void viewSourceFile(); + +private: + TestFailureTableModel *_model; + TestRunnerThread *_thread; + TestBrowser *_browser; + QtTestListener *_listener; + Test *_rootTest; + + QString _srcfile; + + QScopedPointer<TestResult> _result; + QScopedPointer<Ui::TestRunnerWindow> _ui; +}; + +#endif // TESTRUNNERWINDOWPRIVATE_H diff --git a/src/qttestrunner/qttestrunnerlib.pro b/src/qttestrunner/qttestrunnerlib.pro index 18870ee..ac366ad 100644 --- a/src/qttestrunner/qttestrunnerlib.pro +++ b/src/qttestrunner/qttestrunnerlib.pro @@ -1,149 +1,76 @@ #---------------------------------------------------------------------- # File: qttestrunnerlib.pro # Purpose: qmake config file for the QtTestRunner library. -# The library is built as debug staticlib. Set the CONFIG -# variable accordingly to build it differently. +# The library is built in both debug and release configs as +# shared library. Set the CONFIG variable accordingly to build +# it differently. #---------------------------------------------------------------------- -TEMPLATE = lib -LANGUAGE = C++ - -# Get rid of possibly predefined options - -CONFIG -= debug -CONFIG -= release -CONFIG -= dll -CONFIG -= staticlib - -CONFIG += qt warn_on debug staticlib +QT += core gui -#CONFIG += qt warn_on release staticlib -#CONFIG += qt warn_on debug dll -#CONFIG += qt warn_on release dll +greaterThan(QT_MAJOR_VERSION, 4): QT += widgets +TEMPLATE = lib +TARGET = cppunit-qttestrunner +CONFIG += debug_and_release warn_on +CONFIG += dll # Set this to 'static' when building a static library -QTRUNNER_LIB = qttestrunner # Name of the library - +CPPUNIT_LIB = cppunit # cppunit library base name -#---------------------------------------------------------------------- -# MS Windows -#---------------------------------------------------------------------- +CONFIG(debug, debug|release) { + mac { + TARGET = $$join(TARGET,,,_debug) + CPPUNIT_LIB = $$join(CPPUNIT_LIB,,,_debug) + } + win32 { + TARGET = $$join(TARGET,,,d) + CPPUNIT_LIB = $$join(CPPUNIT_LIB,,,d) + } +} -win32 { - # Suppress program database creation (should better be done - # in the qmake spec file) - QMAKE_CXXFLAGS_DEBUG += /Z7 - QMAKE_CXXFLAGS_DEBUG -= -Gm - QMAKE_CXXFLAGS_DEBUG -= -Zi +static { # everything below takes effect with CONFIG += static + CONFIG += staticlib + mac: TARGET = $$join(TARGET,,,_static) + win32: TARGET = $$join(TARGET,,,s) } -win32 { - MOC_DIR = tmp\moc - UI_DIR = tmp\moc - dll { +dll { # everything below takes effect with CONFIG += dll + win32 { DEFINES += QTTESTRUNNER_DLL_BUILD - DLLDESTDIR = ..\..\lib - debug { - TARGET = $${QTRUNNER_LIB}d_dll - QTRUNNER_IMPORTLIB = $${QTRUNNER_LIB}d_dll.lib - OBJECTS_DIR = DebugDLL - LIBS += ..\..\lib\cppunitd_dll.lib - } - release { - TARGET = $${QTRUNNER_LIB}_dll - QTRUNNER_IMPORTLIB = $${QTRUNNER_LIB}_dll.lib - OBJECTS_DIR = ReleaseDLL - LIBS += ..\..\lib\cppunit_dll.lib - } - DESTDIR = $${OBJECTS_DIR} - QMAKE_CLEAN += $${QTRUNNER_IMPORTLIB} - - # Also copy the import library after build of the DLL - QTRUNNER_IMPORTLIB = $${DESTDIR}-SEP-$${QTRUNNER_IMPORTLIB} - QTRUNNER_IMPORTLIB ~= s/-SEP-/\/ - QMAKE_POST_LINK = copy $${QTRUNNER_IMPORTLIB} $${DLLDESTDIR} - } - staticlib { - DESTDIR = ..\..\lib - debug { - TARGET = $${QTRUNNER_LIB}d - OBJECTS_DIR = Debug - } - release { - TARGET = $${QTRUNNER_LIB} - OBJECTS_DIR = Release - } + TARGET = $$join(TARGET,,,_dll) + CPPUNIT_LIB = $$join(CPPUNIT_LIB,,,_dll) } } -#---------------------------------------------------------------------- -# Linux/Unix -#---------------------------------------------------------------------- +# Link paths for the correct cppunit library +win32 { + LIBS += $${CPPUNIT_LIB}.lib +} unix { - MOC_DIR = .moc - UI_DIR = .moc - DESTDIR = ../../lib - dll { - debug { - TARGET = $${QTRUNNER_LIB}d_shared - OBJECTS_DIR = .obj_debug_shared - LIBS += -L../../lib -lcppunit - } - release { - TARGET = $${QTRUNNER_LIB}_shared - OBJECTS_DIR = .obj_release_shared - LIBS += -L../../lib -lcppunit - } - } - staticlib { - debug { - TARGET = $${QTRUNNER_LIB}d - OBJECTS_DIR = .obj_debug - } - release { - TARGET = $${QTRUNNER_LIB} - OBJECTS_DIR = .obj_release - } - } + LIBS += -l$${CPPUNIT_LIB} + target.path = /lib + INSTALLS += target } -#---------------------------------------------------------------------- - -HEADERS = \ - MostRecentTests.h \ - TestBrowserDlgImpl.h \ - TestFailureInfo.h \ - TestFailureListViewItem.h \ - TestListViewItem.h \ - TestRunnerDlgImpl.h \ - TestRunnerFailureEvent.h \ - TestRunnerModel.h \ - TestRunnerModelThreadInterface.h \ - TestRunnerTestCaseRunEvent.h \ - TestRunnerThread.h \ - TestRunnerThreadEvent.h \ - TestRunnerThreadFinishedEvent.h \ - ../../include/cppunit/ui/qt/TestRunner.h - -SOURCES = \ - MostRecentTests.cpp \ - TestBrowserDlgImpl.cpp \ - TestFailureInfo.cpp \ - TestFailureListViewItem.cpp \ - TestListViewItem.cpp \ - QtTestRunner.cpp \ - TestRunnerDlgImpl.cpp \ - TestRunnerFailureEvent.cpp \ - TestRunnerModel.cpp \ - TestRunnerModelThreadInterface.cpp \ - TestRunnerTestCaseRunEvent.cpp \ - TestRunnerThread.cpp \ - TestRunnerThreadEvent.cpp \ - TestRunnerThreadFinishedEvent.cpp - -INTERFACES = \ - testbrowserdlg.ui \ - testrunnerdlg.ui - -INCLUDEPATH += . ../../include +INCLUDEPATH += ../../include + +SOURCES += QtTestFailure.cpp \ + QtTestListener.cpp \ + QtTestRunner.cpp \ + TestBrowser.cpp \ + TestFailureTableModel.cpp \ + TestRunnerThread.cpp \ + TestRunnerWindow.cpp \ + TestRunnerWindowPrivate.cpp + +HEADERS += QtTestFailure.h \ + QtTestListener.h \ + TestBrowser.h \ + TestFailureTableModel.h \ + TestRunnerThread.h \ + TestRunnerWindow.h \ + TestRunnerWindowPrivate.h + +FORMS += TestBrowser.ui \ + TestRunnerWindow.ui diff --git a/src/qttestrunner/testbrowserdlg.ui b/src/qttestrunner/testbrowserdlg.ui deleted file mode 100644 index 4daedf8..0000000 --- a/src/qttestrunner/testbrowserdlg.ui +++ /dev/null @@ -1,148 +0,0 @@ -<!DOCTYPE UI><UI> -<class>TestBrowserBase</class> -<widget> - <class>QDialog</class> - <property stdset="1"> - <name>name</name> - <cstring>TestBrowserBase</cstring> - </property> - <property> - <name>geometry</name> - <rect> - <x>0</x> - <y>0</y> - <width>352</width> - <height>292</height> - </rect> - </property> - <property> - <name>caption</name> - <string>TestBrowser</string> - </property> - <property> - <name>sizeGripEnabled</name> - <bool>true</bool> - </property> - <hbox> - <property> - <name>margin</name> - <number>11</number> - </property> - <property> - <name>spacing</name> - <number>6</number> - </property> - <widget> - <class>QListView</class> - <column> - <property> - <name>text</name> - <string>Test Name</string> - </property> - <property> - <name>clickable</name> - <bool>true</bool> - </property> - <property> - <name>resizeable</name> - <bool>true</bool> - </property> - </column> - <property stdset="1"> - <name>name</name> - <cstring>_listTests</cstring> - </property> - </widget> - <widget> - <class>QLayoutWidget</class> - <property stdset="1"> - <name>name</name> - <cstring>Layout6</cstring> - </property> - <vbox> - <property> - <name>margin</name> - <number>0</number> - </property> - <property> - <name>spacing</name> - <number>6</number> - </property> - <widget> - <class>QPushButton</class> - <property stdset="1"> - <name>name</name> - <cstring>buttonOk</cstring> - </property> - <property> - <name>caption</name> - <string></string> - </property> - <property> - <name>text</name> - <string>&Select</string> - </property> - <property> - <name>autoDefault</name> - <bool>true</bool> - </property> - <property> - <name>default</name> - <bool>true</bool> - </property> - </widget> - <widget> - <class>QPushButton</class> - <property stdset="1"> - <name>name</name> - <cstring>buttonCancel</cstring> - </property> - <property> - <name>text</name> - <string>&Cancel</string> - </property> - <property> - <name>autoDefault</name> - <bool>true</bool> - </property> - </widget> - <spacer> - <property> - <name>name</name> - <cstring>Spacer2</cstring> - </property> - <property> - <name>orientation</name> - <enum>Vertical</enum> - </property> - <property> - <name>sizeType</name> - <enum>Expanding</enum> - </property> - <property> - <name>sizeHint</name> - <size> - <width>20</width> - <height>20</height> - </size> - </property> - </spacer> - </vbox> - </widget> - </hbox> -</widget> -<connections> - <connection> - <sender>buttonOk</sender> - <signal>clicked()</signal> - <receiver>TestBrowserBase</receiver> - <slot>accept()</slot> - </connection> - <connection> - <sender>buttonCancel</sender> - <signal>clicked()</signal> - <receiver>TestBrowserBase</receiver> - <slot>reject()</slot> - </connection> -</connections> -</UI> diff --git a/src/qttestrunner/testrunnerdlg.ui b/src/qttestrunner/testrunnerdlg.ui deleted file mode 100644 index 9727fb1..0000000 --- a/src/qttestrunner/testrunnerdlg.ui +++ /dev/null @@ -1,687 +0,0 @@ -<!DOCTYPE UI><UI> -<class>TestRunnerDlgBase</class> -<widget> - <class>QDialog</class> - <property stdset="1"> - <name>name</name> - <cstring>TestRunnerDlgBase</cstring> - </property> - <property> - <name>geometry</name> - <rect> - <x>0</x> - <y>0</y> - <width>429</width> - <height>370</height> - </rect> - </property> - <property> - <name>caption</name> - <string>Qt Test Runner</string> - </property> - <property> - <name>sizeGripEnabled</name> - <bool>true</bool> - </property> - <vbox> - <property> - <name>margin</name> - <number>11</number> - </property> - <property> - <name>spacing</name> - <number>6</number> - </property> - <widget> - <class>QLayoutWidget</class> - <property stdset="1"> - <name>name</name> - <cstring>Layout25</cstring> - </property> - <hbox> - <property> - <name>margin</name> - <number>0</number> - </property> - <property> - <name>spacing</name> - <number>6</number> - </property> - <widget> - <class>QLayoutWidget</class> - <property stdset="1"> - <name>name</name> - <cstring>Layout24</cstring> - </property> - <vbox> - <property> - <name>margin</name> - <number>0</number> - </property> - <property> - <name>spacing</name> - <number>6</number> - </property> - <widget> - <class>QComboBox</class> - <property stdset="1"> - <name>name</name> - <cstring>_comboTest</cstring> - </property> - <property> - <name>enabled</name> - <bool>true</bool> - </property> - <property> - <name>sizePolicy</name> - <sizepolicy> - <hsizetype>3</hsizetype> - <vsizetype>0</vsizetype> - </sizepolicy> - </property> - <property> - <name>autoResize</name> - <bool>false</bool> - </property> - </widget> - <spacer> - <property> - <name>name</name> - <cstring>Spacer27</cstring> - </property> - <property> - <name>orientation</name> - <enum>Vertical</enum> - </property> - <property> - <name>sizeType</name> - <enum>Expanding</enum> - </property> - <property> - <name>sizeHint</name> - <size> - <width>20</width> - <height>20</height> - </size> - </property> - </spacer> - <widget> - <class>QLayoutWidget</class> - <property stdset="1"> - <name>name</name> - <cstring>Layout9</cstring> - </property> - <hbox> - <property> - <name>margin</name> - <number>0</number> - </property> - <property> - <name>spacing</name> - <number>6</number> - </property> - <widget> - <class>QLayoutWidget</class> - <property stdset="1"> - <name>name</name> - <cstring>Layout8</cstring> - </property> - <hbox> - <property> - <name>margin</name> - <number>0</number> - </property> - <property> - <name>spacing</name> - <number>6</number> - </property> - <widget> - <class>QLabel</class> - <property stdset="1"> - <name>name</name> - <cstring>TextLabel2</cstring> - </property> - <property> - <name>text</name> - <string>TestCases:</string> - </property> - </widget> - <widget> - <class>QLabel</class> - <property stdset="1"> - <name>name</name> - <cstring>_labelTestCaseCount</cstring> - </property> - <property> - <name>text</name> - <string>999999</string> - </property> - </widget> - </hbox> - </widget> - <spacer> - <property> - <name>name</name> - <cstring>Spacer3</cstring> - </property> - <property> - <name>orientation</name> - <enum>Horizontal</enum> - </property> - <property> - <name>sizeType</name> - <enum>Fixed</enum> - </property> - <property> - <name>sizeHint</name> - <size> - <width>20</width> - <height>20</height> - </size> - </property> - </spacer> - <widget> - <class>QLayoutWidget</class> - <property stdset="1"> - <name>name</name> - <cstring>Layout7</cstring> - </property> - <hbox> - <property> - <name>margin</name> - <number>0</number> - </property> - <property> - <name>spacing</name> - <number>6</number> - </property> - <widget> - <class>QLabel</class> - <property stdset="1"> - <name>name</name> - <cstring>TextLabel2_2</cstring> - </property> - <property> - <name>text</name> - <string>Run:</string> - </property> - </widget> - <widget> - <class>QLabel</class> - <property stdset="1"> - <name>name</name> - <cstring>_labelTestRunCount</cstring> - </property> - <property> - <name>text</name> - <string>999999</string> - </property> - </widget> - </hbox> - </widget> - <spacer> - <property> - <name>name</name> - <cstring>Spacer4</cstring> - </property> - <property> - <name>orientation</name> - <enum>Horizontal</enum> - </property> - <property> - <name>sizeType</name> - <enum>Fixed</enum> - </property> - <property> - <name>sizeHint</name> - <size> - <width>20</width> - <height>20</height> - </size> - </property> - </spacer> - <widget> - <class>QLayoutWidget</class> - <property stdset="1"> - <name>name</name> - <cstring>Layout6</cstring> - </property> - <hbox> - <property> - <name>margin</name> - <number>0</number> - </property> - <property> - <name>spacing</name> - <number>6</number> - </property> - <widget> - <class>QLabel</class> - <property stdset="1"> - <name>name</name> - <cstring>TextLabel1</cstring> - </property> - <property> - <name>text</name> - <string>Failure:</string> - </property> - </widget> - <widget> - <class>QLabel</class> - <property stdset="1"> - <name>name</name> - <cstring>_labelFailureCount</cstring> - </property> - <property> - <name>text</name> - <string>999999</string> - </property> - </widget> - </hbox> - </widget> - <spacer> - <property> - <name>name</name> - <cstring>Spacer5</cstring> - </property> - <property> - <name>orientation</name> - <enum>Horizontal</enum> - </property> - <property> - <name>sizeType</name> - <enum>Expanding</enum> - </property> - <property> - <name>sizeHint</name> - <size> - <width>20</width> - <height>20</height> - </size> - </property> - </spacer> - </hbox> - </widget> - <widget> - <class>QProgressBar</class> - <property stdset="1"> - <name>name</name> - <cstring>_progressRun</cstring> - </property> - </widget> - </vbox> - </widget> - <widget> - <class>QLayoutWidget</class> - <property stdset="1"> - <name>name</name> - <cstring>Layout18</cstring> - </property> - <vbox> - <property> - <name>margin</name> - <number>0</number> - </property> - <property> - <name>spacing</name> - <number>6</number> - </property> - <widget> - <class>QPushButton</class> - <property stdset="1"> - <name>name</name> - <cstring>_buttonBrowse</cstring> - </property> - <property> - <name>text</name> - <string>&Browse...</string> - </property> - </widget> - <widget> - <class>QPushButton</class> - <property stdset="1"> - <name>name</name> - <cstring>_buttonRunTest</cstring> - </property> - <property> - <name>text</name> - <string>Run &Test</string> - </property> - <property> - <name>accel</name> - <number>276824148</number> - </property> - </widget> - <widget> - <class>QPushButton</class> - <property stdset="1"> - <name>name</name> - <cstring>_buttonStop</cstring> - </property> - <property> - <name>text</name> - <string>&Stop</string> - </property> - </widget> - <widget> - <class>QPushButton</class> - <property stdset="1"> - <name>name</name> - <cstring>_buttonClose</cstring> - </property> - <property> - <name>caption</name> - <string></string> - </property> - <property> - <name>text</name> - <string>&Close</string> - </property> - <property> - <name>accel</name> - <number>276824131</number> - </property> - <property> - <name>autoDefault</name> - <bool>true</bool> - </property> - <property> - <name>default</name> - <bool>true</bool> - </property> - </widget> - </vbox> - </widget> - </hbox> - </widget> - <widget> - <class>QListView</class> - <column> - <property> - <name>text</name> - <string>Type</string> - </property> - <property> - <name>clickable</name> - <bool>true</bool> - </property> - <property> - <name>resizeable</name> - <bool>true</bool> - </property> - </column> - <column> - <property> - <name>text</name> - <string>Test Name</string> - </property> - <property> - <name>clickable</name> - <bool>true</bool> - </property> - <property> - <name>resizeable</name> - <bool>true</bool> - </property> - </column> - <column> - <property> - <name>text</name> - <string>Message</string> - </property> - <property> - <name>clickable</name> - <bool>true</bool> - </property> - <property> - <name>resizeable</name> - <bool>true</bool> - </property> - </column> - <column> - <property> - <name>text</name> - <string>Filename</string> - </property> - <property> - <name>clickable</name> - <bool>true</bool> - </property> - <property> - <name>resizeable</name> - <bool>true</bool> - </property> - </column> - <column> - <property> - <name>text</name> - <string>Line Number</string> - </property> - <property> - <name>clickable</name> - <bool>true</bool> - </property> - <property> - <name>resizeable</name> - <bool>true</bool> - </property> - </column> - <property stdset="1"> - <name>name</name> - <cstring>_listFailures</cstring> - </property> - <property> - <name>resizePolicy</name> - <enum>AutoOneFit</enum> - </property> - <property> - <name>allColumnsShowFocus</name> - <bool>true</bool> - </property> - <property> - <name>showSortIndicator</name> - <bool>true</bool> - </property> - </widget> - <widget> - <class>QGroupBox</class> - <property stdset="1"> - <name>name</name> - <cstring>_groupFailureDetail</cstring> - </property> - <property> - <name>title</name> - <string>Failure detail...</string> - </property> - <vbox> - <property> - <name>margin</name> - <number>11</number> - </property> - <property> - <name>spacing</name> - <number>6</number> - </property> - <widget> - <class>QLayoutWidget</class> - <property stdset="1"> - <name>name</name> - <cstring>Layout17</cstring> - </property> - <hbox> - <property> - <name>margin</name> - <number>0</number> - </property> - <property> - <name>spacing</name> - <number>6</number> - </property> - <widget> - <class>QLabel</class> - <property stdset="1"> - <name>name</name> - <cstring>TextLabel3</cstring> - </property> - <property> - <name>text</name> - <string>Location:</string> - </property> - </widget> - <widget> - <class>QLabel</class> - <property stdset="1"> - <name>name</name> - <cstring>_labelFailureLocation</cstring> - </property> - <property> - <name>text</name> - <string>...</string> - </property> - </widget> - <spacer> - <property> - <name>name</name> - <cstring>Spacer18</cstring> - </property> - <property> - <name>orientation</name> - <enum>Horizontal</enum> - </property> - <property> - <name>sizeType</name> - <enum>Expanding</enum> - </property> - <property> - <name>sizeHint</name> - <size> - <width>20</width> - <height>20</height> - </size> - </property> - </spacer> - </hbox> - </widget> - <widget> - <class>QLayoutWidget</class> - <property stdset="1"> - <name>name</name> - <cstring>Layout15</cstring> - </property> - <hbox> - <property> - <name>margin</name> - <number>0</number> - </property> - <property> - <name>spacing</name> - <number>6</number> - </property> - <widget> - <class>QLayoutWidget</class> - <property stdset="1"> - <name>name</name> - <cstring>Layout14</cstring> - </property> - <vbox> - <property> - <name>margin</name> - <number>0</number> - </property> - <property> - <name>spacing</name> - <number>6</number> - </property> - <widget> - <class>QLabel</class> - <property stdset="1"> - <name>name</name> - <cstring>TextLabel5</cstring> - </property> - <property> - <name>text</name> - <string>Message:</string> - </property> - </widget> - <spacer> - <property> - <name>name</name> - <cstring>Spacer11</cstring> - </property> - <property> - <name>orientation</name> - <enum>Vertical</enum> - </property> - <property> - <name>sizeType</name> - <enum>Expanding</enum> - </property> - <property> - <name>sizeHint</name> - <size> - <width>20</width> - <height>20</height> - </size> - </property> - </spacer> - </vbox> - </widget> - <widget> - <class>QMultiLineEdit</class> - <property stdset="1"> - <name>name</name> - <cstring>_editFailureMessage</cstring> - </property> - <property> - <name>wordWrap</name> - <enum>WidgetWidth</enum> - </property> - <property> - <name>readOnly</name> - <bool>true</bool> - </property> - </widget> - </hbox> - </widget> - </vbox> - </widget> - </vbox> -</widget> -<connections> - <connection> - <sender>_buttonClose</sender> - <signal>clicked()</signal> - <receiver>TestRunnerDlgBase</receiver> - <slot>accept()</slot> - </connection> - <connection> - <sender>_buttonBrowse</sender> - <signal>clicked()</signal> - <receiver>TestRunnerDlgBase</receiver> - <slot>browseForTest()</slot> - </connection> - <connection> - <sender>_buttonRunTest</sender> - <signal>clicked()</signal> - <receiver>TestRunnerDlgBase</receiver> - <slot>runTest()</slot> - </connection> - <connection> - <sender>_buttonStop</sender> - <signal>clicked()</signal> - <receiver>TestRunnerDlgBase</receiver> - <slot>stopTest()</slot> - </connection> - <slot access="protected">browseForTest()</slot> - <slot access="protected">stopTest()</slot> - <slot access="protected">runTest()</slot> -</connections> -<tabstops> - <tabstop>_comboTest</tabstop> - <tabstop>_buttonBrowse</tabstop> - <tabstop>_buttonRunTest</tabstop> - <tabstop>_listFailures</tabstop> - <tabstop>_editFailureMessage</tabstop> - <tabstop>_buttonClose</tabstop> -</tabstops> -</UI> |