[gtest-runner-qt] r35 committed - Various improvements.

74 views
Skip to first unread message

gtest-r...@googlecode.com

unread,
Nov 21, 2010, 3:07:35 PM11/21/10
to gtest-r...@googlegroups.com
Revision: 35
Author: sandychapman
Date: Sun Nov 21 12:06:32 2010
Log: Various improvements.

http://code.google.com/p/gtest-runner-qt/source/detail?r=35

Modified:
/trunk/Makefile
/trunk/Makefile.Debug
/trunk/Makefile.Release
/trunk/include/GTestExecutable.h
/trunk/include/GTestRunner.h
/trunk/include/GTestSuite.h
/trunk/include/MetaModel.h
/trunk/include/TestTreeModel.h
/trunk/include/TreeItem.h
/trunk/include/TreeModel.h
/trunk/src/GTest.cpp
/trunk/src/GTestExecutable.cpp
/trunk/src/GTestRunner.cpp
/trunk/src/GTestSuite.cpp
/trunk/src/MetaModel.cpp
/trunk/src/TestTreeModel.cpp
/trunk/src/TreeModel.cpp

=======================================
--- /trunk/Makefile Sun Oct 17 08:22:22 2010
+++ /trunk/Makefile Sun Nov 21 12:06:32 2010
@@ -1,6 +1,6 @@

#############################################################################
# Makefile for building: gtestrunner-debug
-# Generated by qmake (2.01a) (Qt 4.7.0) on: Sun Oct 17 12:15:44 2010
+# Generated by qmake (2.01a) (Qt 4.7.0) on: Sun Nov 21 15:45:03 2010
# Project: GTestRunner.pro
# Template: app
# Command: /usr/local/Trolltech/Qt-3.7.0-sdk/qt/bin/qmake -spec
/usr/local/Trolltech/Qt-3.7.0-sdk/qt/mkspecs/linux-g++-64 CONFIG+=debug -o
Makefile GTestRunner.pro
=======================================
--- /trunk/Makefile.Debug Sun Oct 17 08:22:22 2010
+++ /trunk/Makefile.Debug Sun Nov 21 12:06:32 2010
@@ -1,6 +1,6 @@

#############################################################################
# Makefile for building: gtestrunner-debug
-# Generated by qmake (2.01a) (Qt 4.7.0) on: Sun Oct 17 12:15:44 2010
+# Generated by qmake (2.01a) (Qt 4.7.0) on: Sun Nov 21 15:45:03 2010
# Project: GTestRunner.pro
# Template: app

#############################################################################
=======================================
--- /trunk/Makefile.Release Sun Oct 17 08:22:22 2010
+++ /trunk/Makefile.Release Sun Nov 21 12:06:32 2010
@@ -1,6 +1,6 @@

#############################################################################
# Makefile for building: gtestrunner
-# Generated by qmake (2.01a) (Qt 4.7.0) on: Sun Oct 17 12:15:44 2010
+# Generated by qmake (2.01a) (Qt 4.7.0) on: Sun Nov 21 15:45:03 2010
# Project: GTestRunner.pro
# Template: app

#############################################################################
=======================================
--- /trunk/include/GTestExecutable.h Sat Sep 25 09:25:39 2010
+++ /trunk/include/GTestExecutable.h Sun Nov 21 12:06:32 2010
@@ -64,9 +64,8 @@
QBuffer standardError; //!< The buffer to hold the stderr text.
QSet<QString> listingSet;//!< The set of unit test suites provided.
QSet<QString> oldListingSet;//!< The set of elements prior to an update.
- QStringList testsToRun; //!< The list of tests to run.
- bool runOnSignal; /*!< A flag to indicate whether a process should be
- * run when the runTest slot is called */
+ QStringList testFilter; /*! A list of tests to add to the test filter
command line
+ * arguments. */

QProcess::ProcessError error; //!< The state of the QProcess after its run
QProcess::ExitStatus exitStatus;//!< The exit status of the QProcess
@@ -79,20 +78,19 @@
void listingReady(GTestExecutable* sender); //!< Sends notification that
a new listing has been received.

public slots:
- void standardErrorAvailable();
- void standardOutputAvailable();
void executableFinished(int exitCode, QProcess::ExitStatus exitStatus);
- void runTest();
void parseListing(int exitCode, QProcess::ExitStatus exitStatus);
void parseTestResults(int exitCode, QProcess::ExitStatus exitStatus);
void resetRunState();
+ void runTest();
+ void standardErrorAvailable();
+ void standardOutputAvailable();
+ void receiveRunRequest(QString testName, QString testCase = QString());

public:
-
GTestExecutable(QObject* parent = 0, QString executablePath = QString());
virtual ~GTestExecutable();

-//GETS:
QProcess::ProcessError getError() const;
QString getExecutablePath() const;
int getExitCode() const;
@@ -100,14 +98,10 @@
const QSet<QString>& getListing() const;
const QSet<QString>& getOldListing() const;
STATE getState();
- void setRunFlag(bool runOnSignal);
-
-//SETS:
+
void setExecutablePath(QString executablePath);

-//METHODS:
void produceListing();
-
virtual void run();
};

@@ -167,20 +161,5 @@
* \todo TODO::set the return value of this function to return STATE
*/
inline void GTestExecutable::setExecutablePath(QString executablePath) {
setObjectName(executablePath); }
-
-/*! \brief Sets the flag that determines whether this GTestExecutable
- * responds to the runTest() slot.
- *
- * \param runOnSignal whether the flag should allow the signal (true), or
not.
- */
-inline void GTestExecutable::setRunFlag(bool runOnSignal) {
this->runOnSignal = runOnSignal; }
-
-/*! \brief Slot that resets the run state of this executable.
- *
- * Resetting the executable prepares it to be run again and produce new
- * test results.
- * \todo TODO::This should be clearing the buffers, runList, etc.
- */
-inline void GTestExecutable::resetRunState() { setRunFlag(false); }

#endif /* GTESTEXECUTABLE_H_ */
=======================================
--- /trunk/include/GTestRunner.h Sun Oct 17 08:22:22 2010
+++ /trunk/include/GTestRunner.h Sun Nov 21 12:06:32 2010
@@ -52,7 +52,6 @@
~GTestRunner();

signals:
- void aboutToRunTests(); //!< Sends a signal to any listeners to prepare
for test runs.
void runningTests(); //!< Sends a signal when the processes have been
launched.

public slots:
=======================================
--- /trunk/include/GTestSuite.h Tue Aug 17 16:53:58 2010
+++ /trunk/include/GTestSuite.h Sun Nov 21 12:06:32 2010
@@ -66,8 +66,8 @@
* propagate the signal to the GTestExecutable for running.
*/
inline void GTestSuite::addTest(GTest* test) {
- QObject::connect(test, SIGNAL(requestingRun(QString)),
- this, SLOT(receiveRunRequest(QString)));
+ QObject::connect(test, SIGNAL(requestingRun(QString, QString)),
+ this, SLOT(receiveRunRequest(QString, QString)));
}

/*! \brief Removes a test from the GTestSuite object.
@@ -75,8 +75,8 @@
* This dismantles the signal/slot relation set up in addTest.
*/
inline void GTestSuite::removeTest(GTest* test) {
- QObject::disconnect(test, SIGNAL(requestingRun(QString)),
- this, SLOT(receiveRunRequest(QString)));
+ QObject::disconnect(test, SIGNAL(requestingRun(QString, QString)),
+ this, SLOT(receiveRunRequest(QString, QString)));
}


=======================================
--- /trunk/include/MetaModel.h Sun Oct 17 08:22:22 2010
+++ /trunk/include/MetaModel.h Sun Nov 21 12:06:32 2010
@@ -17,19 +17,18 @@
#ifndef TESTRESULTSMODEL_H
#define TESTRESULTSMODEL_H

+#include <QItemSelection>
+
#include "MetaItem.h"
#include "TreeModel.h"

-#include <QHash>
-#include <QItemSelection>
-#include <QItemSelectionModel>
+class QItemSelectionModel;

class MetaModel : public TreeModel {

Q_OBJECT;

private:
- QItemSelectionModel* selectionModel; //!< The selection model to
determine which elements are shown.
QItemSelection currentlySelected; //!< The currently selected model
indices.
QAbstractItemModel* itemModel; //!< The item model whose meta data
we show

@@ -40,10 +39,10 @@

public:

- MetaModel();
+ MetaModel(QObject* parent = 0);
virtual ~MetaModel();

- void setSelectionModel(QItemSelectionModel* model);
+ virtual void setSelectionModel(QItemSelectionModel* model);
void setItemModel(TreeModel* model);
};

=======================================
--- /trunk/include/TestTreeModel.h Sun Oct 17 08:22:22 2010
+++ /trunk/include/TestTreeModel.h Sun Nov 21 12:06:32 2010
@@ -62,13 +62,12 @@
void updateListing(GTestExecutable* gtest);
void updateAllListings();
void populateTestResult();
- void removeSenderItem();
+ void removeSelectedTests();
void runTests();

signals:
- void aboutToRunTests();
+ void aboutToRunTests(); //!< Sends a signal to any listeners to prepare
for test runs.
void runningTests();
- void resettingRunStates();

public:

=======================================
--- /trunk/include/TreeItem.h Sun Oct 17 08:22:22 2010
+++ /trunk/include/TreeItem.h Sun Nov 21 12:06:32 2010
@@ -55,15 +55,14 @@
int row() const;
bool setData(const QVariant& value, int column, int role);
bool setData(const QList<QMap<int, QVariant> >& data);
+ void setParent(TreeItem* parent);


private:
QList<TreeItem* > childItems; //!< The children of the TreeItem
//!< The data for this item, first indexed by column, then by role.
QList<QMap<int, QVariant> > itemData;
- TreeItem* parentItem; //!< The parent of this item.
-
- void setParent(TreeItem* parent);
+ TreeItem* parentItem; //!< The parent of this item.
};

Q_DECLARE_METATYPE(TreeItem*);
=======================================
--- /trunk/include/TreeModel.h Sun Oct 17 08:22:22 2010
+++ /trunk/include/TreeModel.h Sun Nov 21 12:06:32 2010
@@ -21,6 +21,8 @@

#include "TreeItem.h"

+class QItemSelectionModel;
+
class TreeModel : public QAbstractItemModel {

Q_OBJECT;
@@ -29,7 +31,8 @@
void metaDataAboutToBeChanged(const QModelIndex& index);

protected:
- TreeItem rootItem; //<! The root of the data model. It's data is shown in
the header.
+ TreeItem rootItem; //!< The root of the data model. It's data is shown in
the header.
+ QItemSelectionModel* selectionModel; //!< A model to identify selected
items in this model.

public:
TreeModel(QObject* parent = 0);
@@ -45,6 +48,8 @@
virtual int columnCount(const QModelIndex& parent = QModelIndex()) const;
virtual int rowCount(const QModelIndex& parent = QModelIndex()) const;
virtual bool setData(const QModelIndex& index, const QVariant& value, int
role = Qt::EditRole);
+ virtual void setSelectionModel(QItemSelectionModel* model);
+
};

#endif // TREEMODEL_H
=======================================
--- /trunk/src/GTest.cpp Tue Aug 17 16:53:58 2010
+++ /trunk/src/GTest.cpp Sun Nov 21 12:06:32 2010
@@ -61,6 +61,8 @@
* an error in processing.
*/
void GTest::receiveTestResults(GTestResults* testResults) {
+ if(this->testResults != 0)
+ delete this->testResults;
this->testResults = testResults;
emit testResultsReady();
}
=======================================
--- /trunk/src/GTestExecutable.cpp Sat Sep 25 09:25:39 2010
+++ /trunk/src/GTestExecutable.cpp Sun Nov 21 12:06:32 2010
@@ -30,7 +30,7 @@
GTestExecutable::GTestExecutable(QObject* parent, QString filePath)
: GTestSuite(parent, filePath), state(VALID), processLock(),
outputLock(), gtest(0), standardOutput(), standardError(),
- listingSet(), oldListingSet(), testsToRun(), runOnSignal(false)
+ listingSet(), oldListingSet()
{
getState();
}
@@ -161,7 +161,7 @@
*/
void GTestExecutable::runTest() {
//Check our state, and whether we're listening to run signals.
- if(this->state != VALID || !this->runOnSignal)
+ if(this->state != VALID || this->runList.isEmpty())
return;
//We lock so that any attempt to try to produce a listing
//or run a test will block until we're done with what we're
@@ -172,9 +172,19 @@
this, SLOT(standardOutputAvailable()));
QObject::connect(gtest, SIGNAL(finished(int, QProcess::ExitStatus)),
this, SLOT(parseTestResults(int, QProcess::ExitStatus)));
+
+ QString filterString = "--gtest_filter=";
+ QString string;
+ foreach(string, testFilter)
+ filterString.append(string).append(":");
+ filterString.chop(1);
+
+ QStringList commandLineParameters;
+ commandLineParameters << "--gtest_output=xml:./test_detail_1337.xml";
+ commandLineParameters << filterString;
+
//! \todo Only run tests in the runList.
- gtest->start(objectName(), QStringList()
<< "--gtest_output=xml:./test_detail_1337.xml");
- //unlock the processLock in the parseTestResults slot
+ gtest->start(objectName(), commandLineParameters);
}

/*! \brief Parses the test results .xml file produced by the QProcess.
@@ -305,8 +315,26 @@
* a test suite object.
*/
void GTestExecutable::run() {
+ //! \todo Implement this function.
GTestSuite::run();
- runOnSignal = true;
}

-
+/*! \brief A slot that receives a run request from a child GTestSuite.
+ *
+ * Receives a run request from a child test. Adds the test to its runlist.
+ * If received by a GTestSuite, this will emit a request with its name as
+ * the testCase.
+ * \param testName The name of the GTest to run.
+ * \param testCase The name of the GTestSuite to run. Note that
+ * this is 'null' if sent from a GTest, and is the
+ * name of the GTestSuite if received in a GTestExecutable.
+ */
+void GTestExecutable::receiveRunRequest(QString testName, QString
testCase) {
+ GTestSuite::receiveRunRequest(testName, testCase);
+ this->testFilter << testCase + "." + testName;
+}
+
+void GTestExecutable::resetRunState() {
+ this->runList.clear();
+ this->testFilter.clear();
+}
=======================================
--- /trunk/src/GTestRunner.cpp Sun Oct 17 08:22:22 2010
+++ /trunk/src/GTestRunner.cpp Sun Nov 21 12:06:32 2010
@@ -56,30 +56,34 @@
* to set up as well.
*/
void GTestRunner::setup() {
- testModel = new TestTreeModel();
+ testModel = new TestTreeModel(this);
testTree->setModel(testModel);
testTree->setSelectionBehavior(QAbstractItemView::SelectRows);
testTree->setSelectionMode(QAbstractItemView::ExtendedSelection);
- metaModel = new MetaModel();
+ metaModel = new MetaModel(this);
metaModel->setSelectionModel(testTree->selectionModel());
metaModel->setItemModel(testModel);
resultsTree->setModel(metaModel);
+ testModel->setSelectionModel(testTree->selectionModel());


- QObject::connect(aboutQtAction, SIGNAL(triggered()),
+ QObject::connect(this->aboutQtAction, SIGNAL(triggered()),
qApp, SLOT(aboutQt()));

- QObject::connect(importTestAction, SIGNAL(triggered()),
+ QObject::connect(this->importTestAction, SIGNAL(triggered()),
this, SLOT(addTests()));

- QObject::connect(runTestsAction, SIGNAL(triggered()),
+ QObject::connect(this->runTestsAction, SIGNAL(triggered()),
testModel, SLOT(runTests()));

- QObject::connect(refreshAction, SIGNAL(triggered()),
- testTree, SLOT(updateAllListings()));
-
- QObject::connect(removeTestsAction, SIGNAL(triggered()),
- testTree, SLOT(removeSelectedTests()));
+ QObject::connect(this->refreshAction, SIGNAL(triggered()),
+ testModel, SLOT(updateAllListings()));
+
+ QObject::connect(this->removeTestsAction, SIGNAL(triggered()),
+ testModel, SLOT(removeSelectedTests()));
+
+ QObject::connect(this->exitAction, SIGNAL(triggered()),
+ qApp, SLOT(quit()));
}

/*! \brief Slot to prompt a dialog to have the user add unit tests to run.
=======================================
--- /trunk/src/GTestSuite.cpp Sat Sep 25 09:25:39 2010
+++ /trunk/src/GTestSuite.cpp Sun Nov 21 12:06:32 2010
@@ -37,10 +37,7 @@
*/
GTestSuite::GTestSuite(GTestSuite* parent, QString name)
: GTest(parent, name), runList()
-{
- if(parent)
- parent->addTest(this);
-}
+{}

/*! \brief Destructor
*/
@@ -62,8 +59,10 @@
GTest* test = static_cast<GTest*>(QObject::sender());
if(!runList.contains(test))
runList.append(test);
- if(testCase.isEmpty())
- emit requestingRun(testName, objectName());
+ if(testCase.isEmpty()) {
+ QString objectName = this->objectName();
+ emit requestingRun(testName, objectName);
+ }
}

/*! \brief Receives the test results from the parent GTestExecutable
object.
@@ -74,7 +73,6 @@
* table so retrieve should be approximately O(1).
*/
void GTestSuite::receiveTestResults(GTestResults* testSuiteResults) {
- this->testResults = testSuiteResults;
QList<GTest*>::iterator it = runList.begin();
GTestResults* testResults;
while(it != runList.end()) {
@@ -83,6 +81,7 @@
++it;
}
runList.clear();
+ GTest::receiveTestResults(testSuiteResults);
emit testResultsReady();
}

=======================================
--- /trunk/src/MetaModel.cpp Sun Oct 17 08:22:22 2010
+++ /trunk/src/MetaModel.cpp Sun Nov 21 12:06:32 2010
@@ -14,6 +14,7 @@
* Boston, MA 02111-1307 USA
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* * * * * * * * * */

+#include <QItemSelectionModel>
#include <QSharedPointer>
#include <QStack>

@@ -22,8 +23,8 @@
/*! \brief Constructor
*
*/
-MetaModel::MetaModel()
- : selectionModel(0), itemModel(0)
+MetaModel::MetaModel(QObject* parent)
+ : TreeModel(parent), itemModel(0)
{}

/*! \brief Destructor
@@ -62,6 +63,13 @@
QObject::disconnect(this->itemModel,
SIGNAL(metaDataAboutToBeChanged(const QModelIndex&)),
this, SLOT(removeItem(const QModelIndex&)));
this->itemModel = model;
+ //Set up the header data meta info.
+ QList<QMap<int, QVariant> > data;
+ QMap<int, QVariant> datum;
+ datum.insert(Qt::DisplayRole, model->headerData(0, Qt::Horizontal,
Qt::MetaDataRole));
+ data.append(datum);
+ this->rootItem.setData(data);
+
QObject::connect(model, SIGNAL(metaDataAboutToBeChanged(const
QModelIndex&)),
this, SLOT(removeItem(const QModelIndex&)));
}
=======================================
--- /trunk/src/TestTreeModel.cpp Sun Oct 17 08:22:22 2010
+++ /trunk/src/TestTreeModel.cpp Sun Nov 21 12:06:32 2010
@@ -18,6 +18,7 @@
#include <QDebug>
#include <QMap>
#include <QMessageBox>
+#include <QModelIndexList>
#include <QSharedPointer>
#include <QStack>

@@ -34,7 +35,8 @@
{
QList<QMap<int, QVariant> > data;
QMap<int, QVariant> datum;
- datum.insert(0, "Test Name");
+ datum.insert(Qt::DisplayRole, "Test Name");
+ datum.insert(Qt::MetaDataRole, "Test Results");
data.append(datum);
rootItem.setData(data);
}
@@ -58,6 +60,8 @@
case GTestExecutable::VALID:
QObject::connect(newTest.data(), SIGNAL(listingReady(GTestExecutable*)),
this, SLOT(updateListing(GTestExecutable*)));
+ QObject::connect(this, SIGNAL(aboutToRunTests()),
+ newTest.data(), SLOT(resetRunState()));
//We insert it so that it doesn't auto-delete from the shared ptr.
//Will probably be useful later on when we want to save settings.
testExeHash.insert(newTest->objectName(), newTest);
@@ -97,8 +101,6 @@

TreeItem* newTreeItem(new TreeItem(data, parent));
itemTestHash.insert(test, newTreeItem);
- QObject::connect(test, SIGNAL(destroyed()),
- this, SLOT(removeSenderItem()));
QObject::connect(test, SIGNAL(testResultsReady()),
this, SLOT(populateTestResult()));
return newTreeItem;
@@ -134,7 +136,7 @@
QObject::connect(this, SIGNAL(runningTests()),
gtest, SLOT(runTest()));
QObject::connect(this, SIGNAL(resettingRunStates()),
- gtest, SLOT(resetRunState()));
+ gtest, SLOT(resetRunState()));
}
//Get which of the tests are new. This should be all of them the first
//time through for this test.
@@ -174,6 +176,7 @@
emit layoutChanged();
}

+
/*! \brief Populates a test result into the test tree.
*
* This function takes a QObject* which should be a TestTreeWidgetItem.
@@ -223,17 +226,6 @@
var.setValue<MetaItem* >(testResults->createMetaItem());
treeItem->setData(var, 0, Qt::MetaDataRole);
}
-
-/*! \brief A slot that removes the signal's sender from the data model.
- *
- * The sender must be a GTest or this function does nothing.
- */
-//! \todo Investigate whether we can give a persistent index to a GTest.
-void TestTreeModel::removeSenderItem() {
- GTest* test = static_cast<GTest*>(sender());
- if(!test)
- return; //! \todo exception management stuff here
-}

/*! \brief Runs all tests that are checked.
*
@@ -267,7 +259,6 @@

emit runningTests();
}
-

/*! \brief Updates all the listings for every GTestExecutable.
*
@@ -388,4 +379,25 @@
return retval;
}

-
+void TestTreeModel::removeSelectedTests() {
+ QModelIndexList selectedIndexes = this->selectionModel->selectedIndexes();
+ QModelIndexList::iterator it = selectedIndexes.begin();
+ for(; it != selectedIndexes.end(); ++it) {
+ TreeItem* item = static_cast<TreeItem*>(it->internalPointer());
+ if(!item)
+ continue;
+ GTest* gtest = item->data(0, Qt::UserRole).value<GTest*>();
+ GTestExecutable* gtestExe = dynamic_cast<GTestExecutable*>(gtest);
+ if(!gtestExe) {
+ QWidget* parent = 0;
+ if(QObject::parent()->isWidgetType())
+ parent = static_cast<QWidget*>(QObject::parent());
+ QMessageBox::information(parent, "Info", "Currently, only top level
tests can be removed.", QMessageBox::Ok);
+ continue;
+ }
+ this->beginRemoveRows(this->createIndex(0, 0, &rootItem), item->row(),
item->row());
+ item->parent()->removeChild(item);
+ this->testExeHash.remove(gtest->objectName());
+ this->endRemoveRows();
+ }
+}
=======================================
--- /trunk/src/TreeModel.cpp Sun Oct 17 08:22:22 2010
+++ /trunk/src/TreeModel.cpp Sun Nov 21 12:06:32 2010
@@ -14,6 +14,8 @@
* Boston, MA 02111-1307 USA
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* * * * * * * * * */

+#include <QItemSelectionModel>
+
#include "TreeModel.h"

/*! \brief Constructor
@@ -181,6 +183,10 @@
emit dataChanged(index, index);
return true;
}
+
+void TreeModel::setSelectionModel(QItemSelectionModel *model) {
+ this->selectionModel = model;
+}


/*! \brief Inserts a single item into the model before row 'row' on the
parent given.

Reply all
Reply to author
Forward
0 new messages