Commit d198c4a2 authored by Christian Stenger's avatar Christian Stenger

AutoTest: Add Id to parsers and remove now useless enum

Preparation for introducing test frameworks.

Change-Id: Iefaa4ca9dd9af665444556afa9c6e326041cfd0f
Reviewed-by: default avatarDavid Schulz <david.schulz@theqtcompany.com>
parent 94fdd4d9
......@@ -67,7 +67,6 @@ AutotestPlugin::AutotestPlugin()
qRegisterMetaType<TestResult>();
qRegisterMetaType<TestTreeItem *>();
qRegisterMetaType<TestCodeLocationAndType>();
qRegisterMetaType<TestTreeModel::Type>();
m_instance = this;
}
......
......@@ -73,7 +73,8 @@ static bool hasGTestNames(const CPlusPlus::Document::Ptr &document)
static bool handleGTest(QFutureInterface<TestParseResultPtr> futureInterface,
const CPlusPlus::Document::Ptr &doc,
const CPlusPlus::Snapshot &snapshot)
const CPlusPlus::Snapshot &snapshot,
const Core::Id &id)
{
const CppTools::CppModelManager *modelManager = CppTools::CppModelManager::instance();
const QString &filePath = doc->fileName();
......@@ -91,7 +92,7 @@ static bool handleGTest(QFutureInterface<TestParseResultPtr> futureInterface,
proFile = ppList.first()->projectFile;
foreach (const GTestCaseSpec &testSpec, result.keys()) {
GTestParseResult *parseResult = new GTestParseResult;
GTestParseResult *parseResult = new GTestParseResult(id);
parseResult->itemType = TestTreeItem::TestCase;
parseResult->fileName = filePath;
parseResult->name = testSpec.testCaseName;
......@@ -101,7 +102,7 @@ static bool handleGTest(QFutureInterface<TestParseResultPtr> futureInterface,
parseResult->proFile = proFile;
foreach (const GTestCodeLocationAndType &location, result.value(testSpec)) {
GTestParseResult *testSet = new GTestParseResult;
GTestParseResult *testSet = new GTestParseResult(id);
testSet->name = location.m_name;
testSet->fileName = filePath;
testSet->line = location.m_line;
......@@ -126,7 +127,7 @@ bool GTestParser::processDocument(QFutureInterface<TestParseResultPtr> futureInt
CPlusPlus::Document::Ptr document = m_cppSnapshot.find(fileName).value();
if (!includesGTest(document, m_cppSnapshot) || !hasGTestNames(document))
return false;
return handleGTest(futureInterface, document, m_cppSnapshot);
return handleGTest(futureInterface, document, m_cppSnapshot, id());
}
} // namespace Internal
......
......@@ -33,7 +33,7 @@ namespace Internal {
class GTestParseResult : public TestParseResult
{
public:
explicit GTestParseResult() : TestParseResult(TestTreeModel::GoogleTest) {}
explicit GTestParseResult(const Core::Id &id) : TestParseResult(id) {}
TestTreeItem *createTestTreeItem() const override;
bool parameterized = false;
bool typed = false;
......
......@@ -28,27 +28,24 @@
#include "testtreeitem.h"
#include "testtreemodel.h"
#include <coreplugin/id.h>
#include <cplusplus/CppDocument.h>
#include <cpptools/cppmodelmanager.h>
#include <qmljs/qmljsdocument.h>
namespace CppTools {
class CppModelManager;
}
namespace Autotest {
namespace Internal {
class TestParseResult
{
public:
explicit TestParseResult(TestTreeModel::Type t = TestTreeModel::Invalid) : type(t) {}
explicit TestParseResult(const Core::Id &id) : frameworkId(id) {}
virtual ~TestParseResult() { qDeleteAll(children); }
virtual TestTreeItem *createTestTreeItem() const = 0;
QVector<TestParseResult *> children;
TestTreeModel::Type type;
Core::Id frameworkId;
TestTreeItem::Type itemType = TestTreeItem::Root;
QString displayName;
QString fileName;
......@@ -67,6 +64,11 @@ public:
virtual void init(const QStringList &filesToParse) = 0;
virtual bool processDocument(QFutureInterface<TestParseResultPtr> futureInterface,
const QString &fileName) = 0;
void setId(const Core::Id &id) { m_id = id; }
Core::Id id() const { return m_id; }
private:
Core::Id m_id;
};
class CppParser : public ITestParser
......
......@@ -162,7 +162,8 @@ static QMap<QString, TestCodeLocationList> checkForDataTags(const QString &fileN
static bool handleQtTest(QFutureInterface<TestParseResultPtr> futureInterface,
CPlusPlus::Document::Ptr document,
const CPlusPlus::Snapshot &snapshot,
const QString &oldTestCaseName)
const QString &oldTestCaseName,
const Core::Id &id)
{
const CppTools::CppModelManager *modelManager = CppTools::CppModelManager::instance();
const QString &fileName = document->fileName();
......@@ -191,7 +192,7 @@ static bool handleQtTest(QFutureInterface<TestParseResultPtr> futureInterface,
foreach (const QString &file, files)
dataTags.unite(checkForDataTags(file, snapshot));
QtTestParseResult *parseResult = new QtTestParseResult;
QtTestParseResult *parseResult = new QtTestParseResult(id);
parseResult->itemType = TestTreeItem::TestCase;
parseResult->fileName = declaringDoc->fileName();
parseResult->name = testCaseName;
......@@ -203,7 +204,7 @@ static bool handleQtTest(QFutureInterface<TestParseResultPtr> futureInterface,
const QMap<QString, TestCodeLocationAndType>::ConstIterator end = testFunctions.end();
for ( ; it != end; ++it) {
const TestCodeLocationAndType &location = it.value();
QtTestParseResult *func = new QtTestParseResult;
QtTestParseResult *func = new QtTestParseResult(id);
func->itemType = location.m_type;
func->name = testCaseName + QLatin1String("::") + it.key();
func->displayName = it.key();
......@@ -212,7 +213,7 @@ static bool handleQtTest(QFutureInterface<TestParseResultPtr> futureInterface,
func->column = location.m_column;
foreach (const TestCodeLocationAndType &tag, dataTags.value(func->name)) {
QtTestParseResult *dataTag = new QtTestParseResult;
QtTestParseResult *dataTag = new QtTestParseResult(id);
dataTag->itemType = tag.m_type;
dataTag->name = tag.m_name;
dataTag->displayName = tag.m_name;
......@@ -247,7 +248,7 @@ bool QtTestParser::processDocument(QFutureInterface<TestParseResultPtr> futureIn
if ((!includesQtTest(doc, m_cppSnapshot) || !qtTestLibDefined(fileName)) && oldName.isEmpty())
return false;
return handleQtTest(futureInterface, doc, m_cppSnapshot, oldName);
return handleQtTest(futureInterface, doc, m_cppSnapshot, oldName, id());
}
} // namespace Internal
......
......@@ -33,7 +33,7 @@ namespace Internal {
class QtTestParseResult : public TestParseResult
{
public:
explicit QtTestParseResult() : TestParseResult(TestTreeModel::AutoTest) {}
explicit QtTestParseResult(const Core::Id &id) : TestParseResult(id) {}
TestTreeItem *createTestTreeItem() const override;
};
......
......@@ -150,6 +150,7 @@ static QList<QmlJS::Document::Ptr> scanDirectoryForQuickTestQmlFiles(const QStri
static bool checkQmlDocumentForQuickTestCode(QFutureInterface<TestParseResultPtr> futureInterface,
const QmlJS::Document::Ptr &qmlJSDoc,
const Core::Id &id,
const QString &proFile = QString())
{
if (qmlJSDoc.isNull())
......@@ -163,14 +164,14 @@ static bool checkQmlDocumentForQuickTestCode(QFutureInterface<TestParseResultPtr
const TestCodeLocationAndType tcLocationAndType = qmlVisitor.testCaseLocation();
const QMap<QString, TestCodeLocationAndType> &testFunctions = qmlVisitor.testFunctions();
QuickTestParseResult *parseResult = new QuickTestParseResult;
QuickTestParseResult *parseResult = new QuickTestParseResult(id);
parseResult->proFile = proFile;
parseResult->itemType = TestTreeItem::TestCase;
QMap<QString, TestCodeLocationAndType>::ConstIterator it = testFunctions.begin();
const QMap<QString, TestCodeLocationAndType>::ConstIterator end = testFunctions.end();
for ( ; it != end; ++it) {
const TestCodeLocationAndType &loc = it.value();
QuickTestParseResult *funcResult = new QuickTestParseResult;
QuickTestParseResult *funcResult = new QuickTestParseResult(id);
funcResult->name = it.key();
funcResult->displayName = it.key();
funcResult->itemType = loc.m_type;
......@@ -192,7 +193,8 @@ static bool checkQmlDocumentForQuickTestCode(QFutureInterface<TestParseResultPtr
}
static bool handleQtQuickTest(QFutureInterface<TestParseResultPtr> futureInterface,
CPlusPlus::Document::Ptr document)
CPlusPlus::Document::Ptr document,
const Core::Id &id)
{
const CppTools::CppModelManager *modelManager = CppTools::CppModelManager::instance();
if (quickTestName(document).isEmpty())
......@@ -210,7 +212,7 @@ static bool handleQtQuickTest(QFutureInterface<TestParseResultPtr> futureInterfa
const QList<QmlJS::Document::Ptr> qmlDocs = scanDirectoryForQuickTestQmlFiles(srcDir);
bool result = false;
foreach (const QmlJS::Document::Ptr &qmlJSDoc, qmlDocs)
result |= checkQmlDocumentForQuickTestCode(futureInterface, qmlJSDoc, proFile);
result |= checkQmlDocumentForQuickTestCode(futureInterface, qmlJSDoc, id, proFile);
return result;
}
......@@ -225,14 +227,14 @@ bool QuickTestParser::processDocument(QFutureInterface<TestParseResultPtr> futur
{
if (fileName.endsWith(".qml")) {
QmlJS::Document::Ptr qmlJSDoc = m_qmlSnapshot.document(fileName);
return checkQmlDocumentForQuickTestCode(futureInterface, qmlJSDoc);
return checkQmlDocumentForQuickTestCode(futureInterface, qmlJSDoc, id());
}
if (!m_cppSnapshot.contains(fileName) || !selectedForBuilding(fileName))
return false;
CPlusPlus::Document::Ptr document = m_cppSnapshot.find(fileName).value();
if (!includesQtQuickTest(document, m_cppSnapshot))
return false;
return handleQtQuickTest(futureInterface, document);
return handleQtQuickTest(futureInterface, document, id());
}
} // namespace Internal
......
......@@ -33,7 +33,7 @@ namespace Internal {
class QuickTestParseResult : public TestParseResult
{
public:
explicit QuickTestParseResult() : TestParseResult(TestTreeModel::QuickTest) {}
explicit QuickTestParseResult(const Core::Id &id) : TestParseResult(id) {}
TestTreeItem *createTestTreeItem() const override;
};
......
......@@ -82,9 +82,14 @@ TestCodeParser::TestCodeParser(TestTreeModel *parent)
emit testParseResultReady(m_futureWatcher.resultAt(index));
});
m_testCodeParsers.append(new QtTestParser);
m_testCodeParsers.append(new QuickTestParser);
m_testCodeParsers.append(new GTestParser);
// REMOVE
auto p1 = new QtTestParser;
p1->setId("QtTest");
auto p2 = new QuickTestParser;
p2->setId("QtQuickTest");
auto p3 = new GTestParser;
p3->setId("GTest");
m_testCodeParsers.append( {p1, p2, p3} );
}
TestCodeParser::~TestCodeParser()
......
......@@ -227,14 +227,10 @@ void TestTreeModel::removeFiles(const QStringList &files)
void TestTreeModel::markAllForRemoval()
{
foreach (Utils::TreeItem *item, m_qtTestRootItem->children())
static_cast<TestTreeItem *>(item)->markForRemovalRecursively(true);
foreach (Utils::TreeItem *item, m_quickTestRootItem->children())
static_cast<TestTreeItem *>(item)->markForRemovalRecursively(true);
foreach (Utils::TreeItem *item, m_googleTestRootItem->children())
static_cast<TestTreeItem *>(item)->markForRemovalRecursively(true);
foreach (Utils::TreeItem *frameworkRoot, rootItem()->children()) {
foreach (Utils::TreeItem *item, frameworkRoot->children())
static_cast<TestTreeItem *>(item)->markForRemovalRecursively(true);
}
}
void TestTreeModel::markForRemoval(const QString &filePath)
......@@ -242,9 +238,8 @@ void TestTreeModel::markForRemoval(const QString &filePath)
if (filePath.isEmpty())
return;
Type types[] = { AutoTest, QuickTest, GoogleTest };
for (Type type : types) {
TestTreeItem *root = rootItemForType(type);
for (Utils::TreeItem *frameworkRoot : rootItem()->children()) {
TestTreeItem *root = static_cast<TestTreeItem *>(frameworkRoot);
for (int childRow = root->childCount() - 1; childRow >= 0; --childRow) {
TestTreeItem *child = root->childItem(childRow);
child->markForRemovalRecursively(filePath);
......@@ -254,9 +249,8 @@ void TestTreeModel::markForRemoval(const QString &filePath)
void TestTreeModel::sweep()
{
Type types[] = { AutoTest, QuickTest, GoogleTest };
for (Type type : types) {
TestTreeItem *root = rootItemForType(type);
for (Utils::TreeItem *frameworkRoot : rootItem()->children()) {
TestTreeItem *root = static_cast<TestTreeItem *>(frameworkRoot);
sweepChildren(root);
}
// even if nothing has changed by the sweeping we might had parse which added or modified items
......@@ -317,7 +311,7 @@ bool TestTreeModel::sweepChildren(TestTreeItem *item)
void TestTreeModel::onParseResultReady(const TestParseResultPtr result)
{
TestTreeItem *rootNode = rootItemForType(result->type);
TestTreeItem *rootNode = rootItemForFramework(result->frameworkId);
QTC_ASSERT(rootNode, return);
handleParseResult(result.data(), rootNode);
}
......@@ -352,19 +346,15 @@ void TestTreeModel::removeAllTestItems()
emit testTreeModelChanged();
}
TestTreeItem *TestTreeModel::rootItemForType(TestTreeModel::Type type)
TestTreeItem *TestTreeModel::rootItemForFramework(const Core::Id &id)
{
switch (type) {
case AutoTest:
if (id == Core::Id("QtTest"))
return m_qtTestRootItem;
case QuickTest:
if (id == Core::Id("QtQuickTest"))
return m_quickTestRootItem;
case GoogleTest:
if (id == Core::Id("GTest"))
return m_googleTestRootItem;
case Invalid:
break;
}
QTC_ASSERT(false, return 0);
return 0;
}
#ifdef WITH_TESTS
......
......@@ -44,13 +44,6 @@ class TestTreeModel : public Utils::TreeModel
{
Q_OBJECT
public:
enum Type { // FIXME remove this enum
Invalid,
AutoTest,
QuickTest,
GoogleTest
};
static TestTreeModel* instance();
~TestTreeModel();
void enableParsing();
......@@ -98,7 +91,7 @@ private:
bool sweepChildren(TestTreeItem *item);
TestTreeItem *unnamedQuickTests() const;
TestTreeItem *rootItemForType(Type type);
TestTreeItem *rootItemForFramework(const Core::Id &id);
explicit TestTreeModel(QObject *parent = 0);
void setupParsingConnections();
......@@ -143,5 +136,3 @@ private:
} // namespace Internal
} // namespace Autotest
Q_DECLARE_METATYPE(Autotest::Internal::TestTreeModel::Type)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment