AutoTest: Unify test parse result implementations

This is also necessary for a uniform handling while adding or
updating test tree items, which in turn makes it possible to
separate model and items once more.

Change-Id: I84ff558d23490c8734b22062f00e03e8c06d6720
Reviewed-by: David Schulz <david.schulz@theqtcompany.com>
This commit is contained in:
Christian Stenger
2016-05-03 13:03:03 +02:00
parent 1628d052fc
commit 317a1d14d7
5 changed files with 163 additions and 200 deletions

View File

@@ -454,14 +454,29 @@ static bool checkQmlDocumentForTestCode(QFutureInterface<TestParseResultPtr> fut
const QString testCaseName = qmlVisitor.testCaseName(); const QString testCaseName = qmlVisitor.testCaseName();
const TestCodeLocationAndType tcLocationAndType = qmlVisitor.testCaseLocation(); const TestCodeLocationAndType tcLocationAndType = qmlVisitor.testCaseLocation();
const QMap<QString, TestCodeLocationAndType> testFunctions = qmlVisitor.testFunctions(); const QMap<QString, TestCodeLocationAndType> &testFunctions = qmlVisitor.testFunctions();
QuickTestParseResult *parseResult = new QuickTestParseResult(TestTreeModel::QuickTest); QuickTestParseResult *parseResult = new QuickTestParseResult;
parseResult->proFile = proFile; parseResult->proFile = proFile;
parseResult->functions = testFunctions; 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;
funcResult->name = it.key();
funcResult->displayName = it.key();
funcResult->itemType = loc.m_type;
funcResult->fileName = loc.m_name;
funcResult->line = loc.m_line;
funcResult->column = loc.m_column;
funcResult->proFile = proFile;
parseResult->children.append(funcResult);
}
if (!testCaseName.isEmpty()) { if (!testCaseName.isEmpty()) {
parseResult->fileName = tcLocationAndType.m_name; parseResult->fileName = tcLocationAndType.m_name;
parseResult->testCaseName = testCaseName; parseResult->name = testCaseName;
parseResult->line = tcLocationAndType.m_line; parseResult->line = tcLocationAndType.m_line;
parseResult->column = tcLocationAndType.m_column; parseResult->column = tcLocationAndType.m_column;
} }
@@ -491,21 +506,47 @@ static bool handleQtTest(QFutureInterface<TestParseResultPtr> futureInterface,
if (!visitor.resultValid()) if (!visitor.resultValid())
return false; return false;
const QMap<QString, TestCodeLocationAndType> testFunctions = visitor.privateSlots(); const QMap<QString, TestCodeLocationAndType> &testFunctions = visitor.privateSlots();
const QSet<QString> &files = filesWithDataFunctionDefinitions(testFunctions); const QSet<QString> &files = filesWithDataFunctionDefinitions(testFunctions);
// TODO: change to QHash<>
QMap<QString, TestCodeLocationList> dataTags; QMap<QString, TestCodeLocationList> dataTags;
foreach (const QString &file, files) foreach (const QString &file, files)
dataTags.unite(checkForDataTags(file)); dataTags.unite(checkForDataTags(file));
QtTestParseResult *parseResult = new QtTestParseResult(TestTreeModel::AutoTest); QtTestParseResult *parseResult = new QtTestParseResult;
parseResult->itemType = TestTreeItem::TestCase;
parseResult->fileName = declaringDoc->fileName(); parseResult->fileName = declaringDoc->fileName();
parseResult->testCaseName = testCaseName; parseResult->name = testCaseName;
parseResult->displayName = testCaseName;
parseResult->line = line; parseResult->line = line;
parseResult->column = column; parseResult->column = column;
parseResult->functions = testFunctions;
parseResult->dataTags = dataTags;
parseResult->proFile = modelManager->projectPart(fileName).first()->projectFile; parseResult->proFile = modelManager->projectPart(fileName).first()->projectFile;
QMap<QString, TestCodeLocationAndType>::ConstIterator it = testFunctions.begin();
const QMap<QString, TestCodeLocationAndType>::ConstIterator end = testFunctions.end();
for ( ; it != end; ++it) {
const TestCodeLocationAndType &location = it.value();
QtTestParseResult *func = new QtTestParseResult;
func->itemType = location.m_type;
func->name = testCaseName + QLatin1String("::") + it.key();
func->displayName = it.key();
func->fileName = location.m_name;
func->line = location.m_line;
func->column = location.m_column;
foreach (const TestCodeLocationAndType &tag, dataTags.value(func->name)) {
QtTestParseResult *dataTag = new QtTestParseResult;
dataTag->itemType = tag.m_type;
dataTag->name = tag.m_name;
dataTag->displayName = tag.m_name;
dataTag->fileName = testFunctions.value(it.key() + QLatin1String("_data")).m_name;
dataTag->line = tag.m_line;
dataTag->column = tag.m_column;
func->children.append(dataTag);
}
parseResult->children.append(func);
}
futureInterface.reportResult(TestParseResultPtr(parseResult)); futureInterface.reportResult(TestParseResultPtr(parseResult));
return true; return true;
@@ -555,14 +596,28 @@ static bool handleGTest(QFutureInterface<TestParseResultPtr> futureInterface, co
proFile = ppList.first()->projectFile; proFile = ppList.first()->projectFile;
foreach (const GTestCaseSpec &testSpec, result.keys()) { foreach (const GTestCaseSpec &testSpec, result.keys()) {
GoogleTestParseResult *parseResult = new GoogleTestParseResult(TestTreeModel::GoogleTest); GoogleTestParseResult *parseResult = new GoogleTestParseResult;
parseResult->itemType = TestTreeItem::TestCase;
parseResult->fileName = filePath; parseResult->fileName = filePath;
parseResult->testCaseName = testSpec.testCaseName; parseResult->name = testSpec.testCaseName;
parseResult->parameterized = testSpec.parameterized; parseResult->parameterized = testSpec.parameterized;
parseResult->typed = testSpec.typed; parseResult->typed = testSpec.typed;
parseResult->disabled = testSpec.disabled; parseResult->disabled = testSpec.disabled;
parseResult->proFile = proFile; parseResult->proFile = proFile;
parseResult->testSets = result.value(testSpec);
foreach (const TestCodeLocationAndType &location, result.value(testSpec)) {
GoogleTestParseResult *testSet = new GoogleTestParseResult;
testSet->name = location.m_name;
testSet->fileName = filePath;
testSet->line = location.m_line;
testSet->column = location.m_column;
testSet->disabled = location.m_state & GoogleTestTreeItem::Disabled;
testSet->itemType = location.m_type;
testSet->proFile = proFile;
parseResult->children.append(testSet);
}
futureInterface.reportResult(TestParseResultPtr(parseResult)); futureInterface.reportResult(TestParseResultPtr(parseResult));
} }
return !result.keys().isEmpty(); return !result.keys().isEmpty();

View File

@@ -47,12 +47,15 @@ class TestParseResult
{ {
public: public:
explicit TestParseResult(TestTreeModel::Type t = TestTreeModel::Invalid) : type(t) {} explicit TestParseResult(TestTreeModel::Type t = TestTreeModel::Invalid) : type(t) {}
virtual ~TestParseResult() {} virtual ~TestParseResult() { qDeleteAll(children); }
QVector<TestParseResult *> children;
TestTreeModel::Type type; TestTreeModel::Type type;
TestTreeItem::Type itemType = TestTreeItem::Root;
QString displayName;
QString fileName; QString fileName;
QString proFile; QString proFile;
QString testCaseName; QString name;
unsigned line = 0; unsigned line = 0;
unsigned column = 0; unsigned column = 0;
}; };
@@ -60,26 +63,22 @@ public:
class QtTestParseResult : public TestParseResult class QtTestParseResult : public TestParseResult
{ {
public: public:
QtTestParseResult(TestTreeModel::Type t = TestTreeModel::Invalid) : TestParseResult(t) {} explicit QtTestParseResult() : TestParseResult(TestTreeModel::AutoTest) {}
QMap<QString, TestCodeLocationAndType> functions;
QMap<QString, TestCodeLocationList> dataTags;
}; };
class QuickTestParseResult : public TestParseResult class QuickTestParseResult : public TestParseResult
{ {
public: public:
QuickTestParseResult(TestTreeModel::Type t = TestTreeModel::Invalid) : TestParseResult(t) {} explicit QuickTestParseResult() : TestParseResult(TestTreeModel::QuickTest) {}
QMap<QString, TestCodeLocationAndType> functions;
}; };
class GoogleTestParseResult : public TestParseResult class GoogleTestParseResult : public TestParseResult
{ {
public: public:
GoogleTestParseResult(TestTreeModel::Type t = TestTreeModel::Invalid) : TestParseResult(t) {} explicit GoogleTestParseResult() : TestParseResult(TestTreeModel::GoogleTest) {}
bool parameterized = false; bool parameterized = false;
bool typed = false; bool typed = false;
bool disabled = false; bool disabled = false;
TestCodeLocationList testSets;
}; };
using TestParseResultPtr = QSharedPointer<TestParseResult>; using TestParseResultPtr = QSharedPointer<TestParseResult>;

View File

@@ -129,27 +129,23 @@ bool TestTreeItem::modifyTestCaseContent(const QString &name, unsigned line, uns
return hasBeenModified; return hasBeenModified;
} }
bool TestTreeItem::modifyTestFunctionContent(const TestCodeLocationAndType &location) bool TestTreeItem::modifyTestFunctionContent(const TestParseResult *result)
{ {
bool hasBeenModified = modifyFilePath(location.m_name); bool hasBeenModified = modifyFilePath(result->fileName);
hasBeenModified |= modifyLineAndColumn(location); hasBeenModified |= modifyLineAndColumn(result->line, result->column);
return hasBeenModified; return hasBeenModified;
} }
bool TestTreeItem::modifyDataTagContent(const QString &fileName, // TODO pass TestParseResult * to all modifyXYZ() OR remove completely if possible
const TestCodeLocationAndType &location) bool TestTreeItem::modifyDataTagContent(const QString &name, const QString &fileName,
unsigned line, unsigned column)
{ {
bool hasBeenModified = modifyFilePath(fileName); bool hasBeenModified = modifyFilePath(fileName);
hasBeenModified |= modifyName(location.m_name); hasBeenModified |= modifyName(name);
hasBeenModified |= modifyLineAndColumn(location); hasBeenModified |= modifyLineAndColumn(line, column);
return hasBeenModified; return hasBeenModified;
} }
bool TestTreeItem::modifyLineAndColumn(const TestCodeLocationAndType &location)
{
return modifyLineAndColumn(location.m_line, location.m_column);
}
bool TestTreeItem::modifyLineAndColumn(unsigned line, unsigned column) bool TestTreeItem::modifyLineAndColumn(unsigned line, unsigned column)
{ {
bool hasBeenModified = false; bool hasBeenModified = false;
@@ -340,46 +336,19 @@ TestTreeItem *TestTreeItem::findChildBy(CompareFunction compare)
return 0; return 0;
} }
AutoTestTreeItem *AutoTestTreeItem::createTestItem(const TestParseResult &result) AutoTestTreeItem *AutoTestTreeItem::createTestItem(const TestParseResult *result)
{ {
const QtTestParseResult &parseResult = static_cast<const QtTestParseResult &>(result); AutoTestTreeItem *item = new AutoTestTreeItem(result->displayName, result->fileName,
AutoTestTreeItem *item = new AutoTestTreeItem(result.testCaseName, result.fileName, TestCase); result->itemType);
item->setProFile(parseResult.proFile); item->setProFile(result->proFile);
item->setLine(parseResult.line); item->setLine(result->line);
item->setColumn(parseResult.column); item->setColumn(result->column);
foreach (const QString &functionName, parseResult.functions.keys()) { foreach (const TestParseResult *funcParseResult, result->children)
const TestCodeLocationAndType &locationAndType = parseResult.functions.value(functionName); item->appendChild(createTestItem(funcParseResult));
const QString qualifiedName = result.testCaseName + QLatin1String("::") + functionName;
item->appendChild(createFunctionItem(functionName, locationAndType,
parseResult.dataTags.value(qualifiedName)));
}
return item; return item;
} }
AutoTestTreeItem *AutoTestTreeItem::createFunctionItem(const QString &functionName,
const TestCodeLocationAndType &location,
const TestCodeLocationList &dataTags)
{
AutoTestTreeItem *item = new AutoTestTreeItem(functionName, location.m_name, location.m_type);
item->setLine(location.m_line);
item->setColumn(location.m_column);
// if there are any data tags for this function add them
foreach (const TestCodeLocationAndType &tagLocation, dataTags)
item->appendChild(createDataTagItem(location.m_name, tagLocation));
return item;
}
AutoTestTreeItem *AutoTestTreeItem::createDataTagItem(const QString &fileName,
const TestCodeLocationAndType &location)
{
AutoTestTreeItem *tagItem = new AutoTestTreeItem(location.m_name, fileName, location.m_type);
tagItem->setLine(location.m_line);
tagItem->setColumn(location.m_column);
return tagItem;
}
QVariant AutoTestTreeItem::data(int column, int role) const QVariant AutoTestTreeItem::data(int column, int role) const
{ {
switch (role) { switch (role) {
@@ -530,46 +499,15 @@ QList<TestConfiguration *> AutoTestTreeItem::getSelectedTestConfigurations() con
return result; return result;
} }
QuickTestTreeItem *QuickTestTreeItem::createTestItem(const TestParseResult &result) QuickTestTreeItem *QuickTestTreeItem::createTestItem(const TestParseResult *result)
{ {
const QuickTestParseResult &parseResult = static_cast<const QuickTestParseResult &>(result); QuickTestTreeItem *item = new QuickTestTreeItem(result->name, result->fileName,
QuickTestTreeItem *item = new QuickTestTreeItem(parseResult.testCaseName, parseResult.fileName, result->itemType);
TestCase); item->setProFile(result->proFile);
item->setProFile(result.proFile); item->setLine(result->line);
item->setLine(result.line); item->setColumn(result->column);
item->setColumn(result.column); foreach (const TestParseResult *funcResult, result->children)
foreach (const QString &functionName, parseResult.functions.keys()) item->appendChild(createTestItem(funcResult));
item->appendChild(createFunctionItem(functionName, parseResult.functions.value(functionName)));
return item;
}
QuickTestTreeItem *QuickTestTreeItem::createFunctionItem(const QString &functionName,
const TestCodeLocationAndType &location)
{
QuickTestTreeItem *item = new QuickTestTreeItem(functionName, location.m_name, location.m_type);
item->setLine(location.m_line);
item->setColumn(location.m_column);
return item;
}
QuickTestTreeItem *QuickTestTreeItem::createUnnamedQuickTestItem(const TestParseResult &result)
{
const QuickTestParseResult &parseResult = static_cast<const QuickTestParseResult &>(result);
QuickTestTreeItem *item = new QuickTestTreeItem(QString(), QString(), TestCase);
foreach (const QString &functionName, parseResult.functions.keys())
item->appendChild(createUnnamedQuickFunctionItem(functionName, parseResult));
return item;
}
QuickTestTreeItem *QuickTestTreeItem::createUnnamedQuickFunctionItem(const QString &functionName,
const TestParseResult &result)
{
const QuickTestParseResult &parseResult = static_cast<const QuickTestParseResult &>(result);
const TestCodeLocationAndType &location = parseResult.functions.value(functionName);
QuickTestTreeItem *item = new QuickTestTreeItem(functionName, location.m_name, location.m_type);
item->setLine(location.m_line);
item->setColumn(location.m_column);
item->setProFile(parseResult.proFile);
return item; return item;
} }
@@ -836,31 +774,23 @@ static QString gtestFilter(GoogleTestTreeItem::TestStates states)
return QLatin1String("%1.%2"); return QLatin1String("%1.%2");
} }
GoogleTestTreeItem *GoogleTestTreeItem::createTestItem(const TestParseResult &result) GoogleTestTreeItem *GoogleTestTreeItem::createTestItem(const TestParseResult *result)
{ {
const GoogleTestParseResult &parseResult = static_cast<const GoogleTestParseResult &>(result); const GoogleTestParseResult *parseResult = static_cast<const GoogleTestParseResult *>(result);
GoogleTestTreeItem *item = new GoogleTestTreeItem(parseResult.testCaseName, QString(), TestCase); GoogleTestTreeItem *item = new GoogleTestTreeItem(parseResult->name, parseResult->fileName,
item->setProFile(parseResult.proFile); parseResult->itemType);
if (parseResult.parameterized) item->setProFile(parseResult->proFile);
item->setState(Parameterized); item->setLine(parseResult->line);
if (parseResult.typed) item->setColumn(parseResult->column);
item->setState(Typed);
if (parseResult.disabled)
item->setState(Disabled);
foreach (const TestCodeLocationAndType &location, parseResult.testSets)
item->appendChild(createTestSetItem(result, location));
return item;
}
GoogleTestTreeItem *GoogleTestTreeItem::createTestSetItem(const TestParseResult &result, if (parseResult->parameterized)
const TestCodeLocationAndType &location) item->setState(Parameterized);
{ if (parseResult->typed)
GoogleTestTreeItem *item = new GoogleTestTreeItem(location.m_name, result.fileName, item->setState(Typed);
location.m_type); if (parseResult->disabled)
item->setStates(location.m_state); item->setState(Disabled);
item->setLine(location.m_line); foreach (const TestParseResult *testSet, parseResult->children)
item->setColumn(location.m_column); item->appendChild(createTestItem(testSet));
item->setProFile(result.proFile);
return item; return item;
} }
@@ -1042,13 +972,13 @@ QList<TestConfiguration *> GoogleTestTreeItem::getSelectedTestConfigurations() c
return result; return result;
} }
bool GoogleTestTreeItem::modifyTestSetContent(const QString &fileName, bool GoogleTestTreeItem::modifyTestSetContent(const GoogleTestParseResult *result)
const TestCodeLocationAndType &location)
{ {
bool hasBeenModified = modifyFilePath(fileName); bool hasBeenModified = modifyLineAndColumn(result->line, result->column);
hasBeenModified |= modifyLineAndColumn(location); GoogleTestTreeItem::TestStates states = result->disabled ? GoogleTestTreeItem::Disabled
if (m_state != location.m_state) { : GoogleTestTreeItem::Enabled;
m_state = location.m_state; if (m_state != states) {
m_state = states;
hasBeenModified = true; hasBeenModified = true;
} }
return hasBeenModified; return hasBeenModified;

View File

@@ -48,6 +48,7 @@ class AutoTestTreeItem;
class QuickTestTreeItem; class QuickTestTreeItem;
class GoogleTestTreeItem; class GoogleTestTreeItem;
class TestParseResult; class TestParseResult;
class GoogleTestParseResult;
class TestConfiguration; class TestConfiguration;
class TestTreeItem : public Utils::TreeItem class TestTreeItem : public Utils::TreeItem
@@ -75,9 +76,9 @@ public:
virtual bool setData(int column, const QVariant &data, int role) override; virtual bool setData(int column, const QVariant &data, int role) override;
virtual Qt::ItemFlags flags(int column) const override; virtual Qt::ItemFlags flags(int column) const override;
bool modifyTestCaseContent(const QString &name, unsigned line, unsigned column); bool modifyTestCaseContent(const QString &name, unsigned line, unsigned column);
bool modifyTestFunctionContent(const TestCodeLocationAndType &location); bool modifyTestFunctionContent(const TestParseResult *result);
bool modifyDataTagContent(const QString &fileName, const TestCodeLocationAndType &location); bool modifyDataTagContent(const QString &name, const QString &fileName, unsigned line,
bool modifyLineAndColumn(const TestCodeLocationAndType &location); unsigned column);
bool modifyLineAndColumn(unsigned line, unsigned column); bool modifyLineAndColumn(unsigned line, unsigned column);
const QString name() const { return m_name; } const QString name() const { return m_name; }
@@ -145,12 +146,7 @@ public:
AutoTestTreeItem(const QString &name = QString(), const QString &filePath = QString(), AutoTestTreeItem(const QString &name = QString(), const QString &filePath = QString(),
Type type = Root) : TestTreeItem(name, filePath, type) {} Type type = Root) : TestTreeItem(name, filePath, type) {}
static AutoTestTreeItem *createTestItem(const TestParseResult &result); static AutoTestTreeItem *createTestItem(const TestParseResult *result);
static AutoTestTreeItem *createFunctionItem(const QString &functionName,
const TestCodeLocationAndType &location,
const TestCodeLocationList &dataTags);
static AutoTestTreeItem *createDataTagItem(const QString &fileName,
const TestCodeLocationAndType &location);
QVariant data(int column, int role) const override; QVariant data(int column, int role) const override;
bool canProvideTestConfiguration() const override; bool canProvideTestConfiguration() const override;
@@ -165,12 +161,7 @@ public:
QuickTestTreeItem(const QString &name = QString(), const QString &filePath = QString(), QuickTestTreeItem(const QString &name = QString(), const QString &filePath = QString(),
Type type = Root) : TestTreeItem(name, filePath, type) {} Type type = Root) : TestTreeItem(name, filePath, type) {}
static QuickTestTreeItem *createTestItem(const TestParseResult &result); static QuickTestTreeItem *createTestItem(const TestParseResult *result);
static QuickTestTreeItem *createFunctionItem(const QString &functionName,
const TestCodeLocationAndType &location);
static QuickTestTreeItem *createUnnamedQuickTestItem(const TestParseResult &result);
static QuickTestTreeItem *createUnnamedQuickFunctionItem(const QString &functionName,
const TestParseResult &result);
QVariant data(int column, int role) const override; QVariant data(int column, int role) const override;
Qt::ItemFlags flags(int column) const override; Qt::ItemFlags flags(int column) const override;
@@ -201,9 +192,7 @@ public:
GoogleTestTreeItem(const QString &name = QString(), const QString &filePath = QString(), GoogleTestTreeItem(const QString &name = QString(), const QString &filePath = QString(),
Type type = Root) : TestTreeItem(name, filePath, type), m_state(Enabled) {} Type type = Root) : TestTreeItem(name, filePath, type), m_state(Enabled) {}
static GoogleTestTreeItem *createTestItem(const TestParseResult &result); static GoogleTestTreeItem *createTestItem(const TestParseResult *result);
static GoogleTestTreeItem *createTestSetItem(const TestParseResult &result,
const TestCodeLocationAndType &location);
QVariant data(int column, int role) const override; QVariant data(int column, int role) const override;
bool canProvideTestConfiguration() const override { return type() != Root; } bool canProvideTestConfiguration() const override { return type() != Root; }
@@ -214,7 +203,7 @@ public:
void setStates(TestStates states) { m_state = states; } void setStates(TestStates states) { m_state = states; }
void setState(TestState state) { m_state |= state; } void setState(TestState state) { m_state |= state; }
TestStates state() const { return m_state; } TestStates state() const { return m_state; }
bool modifyTestSetContent(const QString &fileName, const TestCodeLocationAndType &location); bool modifyTestSetContent(const GoogleTestParseResult *result);
TestTreeItem *findChildByNameStateAndFile(const QString &name, TestTreeItem *findChildByNameStateAndFile(const QString &name,
GoogleTestTreeItem::TestStates state, GoogleTestTreeItem::TestStates state,
const QString &proFile); const QString &proFile);

View File

@@ -332,42 +332,37 @@ void TestTreeModel::handleQtParseResult(const TestParseResultPtr result)
TestTreeItem *toBeModified = m_autoTestRootItem->findChildByFile(result->fileName); TestTreeItem *toBeModified = m_autoTestRootItem->findChildByFile(result->fileName);
// if there's no matching item, add the new one // if there's no matching item, add the new one
if (!toBeModified) { if (!toBeModified) {
m_autoTestRootItem->appendChild(AutoTestTreeItem::createTestItem(*result)); m_autoTestRootItem->appendChild(AutoTestTreeItem::createTestItem(result.data()));
return; return;
} }
// else we have to check level by level.. first the current level... // else we have to check level by level.. first the current level...
bool changed = toBeModified->modifyTestCaseContent(result->testCaseName, result->line, bool changed = toBeModified->modifyTestCaseContent(result->name, result->line,
result->column); result->column);
toBeModified->markForRemoval(false); toBeModified->markForRemoval(false);
if (changed) if (changed)
emit dataChanged(indexForItem(toBeModified), indexForItem(toBeModified)); emit dataChanged(indexForItem(toBeModified), indexForItem(toBeModified));
// ...now the functions // ...now the functions
const QtTestParseResult &parseResult = static_cast<const QtTestParseResult &>(*result); foreach (const TestParseResult *funcResult, result->children) {
foreach (const QString &func, parseResult.functions.keys()) { TestTreeItem *functionItem = toBeModified->findChildByName(funcResult->displayName);
TestTreeItem *functionItem = toBeModified->findChildByName(func);
if (!functionItem) { if (!functionItem) {
// if there's no function matching, add the new one // if there's no function matching, add the new one
const QString qualifiedName = parseResult.testCaseName + QLatin1String("::") + func; toBeModified->appendChild(AutoTestTreeItem::createTestItem(funcResult));
toBeModified->appendChild(AutoTestTreeItem::createFunctionItem(
func, parseResult.functions.value(func),
parseResult.dataTags.value(qualifiedName)));
continue; continue;
} }
// else we have to check level by level.. first the current level... // else we have to check level by level.. first the current level...
changed = functionItem->modifyTestFunctionContent(parseResult.functions.value(func)); changed = functionItem->modifyTestFunctionContent(funcResult);
functionItem->markForRemoval(false); functionItem->markForRemoval(false);
if (changed) if (changed)
emit dataChanged(indexForItem(functionItem), indexForItem(functionItem)); emit dataChanged(indexForItem(functionItem), indexForItem(functionItem));
// ...now the data tags // ...now the data tags
const QString &funcFileName = parseResult.functions.value(func).m_name; foreach (const TestParseResult *tag, funcResult->children) {
const QString qualifiedFunctionName = parseResult.testCaseName + QLatin1String("::") + func; TestTreeItem *dataTagItem = functionItem->findChildByName(tag->name);
foreach (const TestCodeLocationAndType &location, parseResult.dataTags.value(qualifiedFunctionName)) {
TestTreeItem *dataTagItem = functionItem->findChildByName(location.m_name);
if (!dataTagItem) { if (!dataTagItem) {
functionItem->appendChild(AutoTestTreeItem::createDataTagItem(funcFileName, location)); functionItem->appendChild(AutoTestTreeItem::createTestItem(tag));
continue; continue;
} }
changed = dataTagItem->modifyDataTagContent(funcFileName, location); changed = dataTagItem->modifyDataTagContent(tag->name, tag->fileName, tag->line,
tag->column);
dataTagItem->markForRemoval(false); dataTagItem->markForRemoval(false);
if (changed) if (changed)
emit dataChanged(indexForItem(dataTagItem), indexForItem(dataTagItem)); emit dataChanged(indexForItem(dataTagItem), indexForItem(dataTagItem));
@@ -377,7 +372,7 @@ void TestTreeModel::handleQtParseResult(const TestParseResultPtr result)
void TestTreeModel::handleQuickParseResult(const TestParseResultPtr result) void TestTreeModel::handleQuickParseResult(const TestParseResultPtr result)
{ {
if (result->testCaseName.isEmpty()) { if (result->name.isEmpty()) {
handleUnnamedQuickParseResult(result); handleUnnamedQuickParseResult(result);
return; return;
} }
@@ -385,28 +380,25 @@ void TestTreeModel::handleQuickParseResult(const TestParseResultPtr result)
TestTreeItem *toBeModified = m_quickTestRootItem->findChildByFile(result->fileName); TestTreeItem *toBeModified = m_quickTestRootItem->findChildByFile(result->fileName);
// if there's no matching item, add the new one // if there's no matching item, add the new one
if (!toBeModified) { if (!toBeModified) {
m_quickTestRootItem->appendChild(QuickTestTreeItem::createTestItem(*result)); m_quickTestRootItem->appendChild(QuickTestTreeItem::createTestItem(result.data()));
return; return;
} }
// else we have to check level by level.. first the current level... // else we have to check level by level.. first the current level...
bool changed = toBeModified->modifyTestCaseContent(result->testCaseName, result->line, bool changed = toBeModified->modifyTestCaseContent(result->name, result->line,
result->column); result->column);
toBeModified->markForRemoval(false); toBeModified->markForRemoval(false);
if (changed) if (changed)
emit dataChanged(indexForItem(toBeModified), indexForItem(toBeModified)); emit dataChanged(indexForItem(toBeModified), indexForItem(toBeModified));
// ...now the functions // ...now the functions
foreach (const TestParseResult *funcResult, result->children) {
const QuickTestParseResult &parseResult = static_cast<const QuickTestParseResult &>(*result); TestTreeItem *functionItem = toBeModified->findChildByName(funcResult->name);
foreach (const QString &func, parseResult.functions.keys()) {
TestTreeItem *functionItem = toBeModified->findChildByName(func);
if (!functionItem) { if (!functionItem) {
// if there's no matching, add the new one // if there's no matching, add the new one
toBeModified->appendChild(QuickTestTreeItem::createFunctionItem( toBeModified->appendChild(QuickTestTreeItem::createTestItem(funcResult));
func, parseResult.functions.value(func)));
continue; continue;
} }
// else we have to modify.. // else we have to modify..
changed = functionItem->modifyTestFunctionContent(parseResult.functions.value(func)); changed = functionItem->modifyTestFunctionContent(funcResult);
functionItem->markForRemoval(false); functionItem->markForRemoval(false);
if (changed) if (changed)
emit dataChanged(indexForItem(functionItem), indexForItem(functionItem)); emit dataChanged(indexForItem(functionItem), indexForItem(functionItem));
@@ -415,52 +407,50 @@ void TestTreeModel::handleQuickParseResult(const TestParseResultPtr result)
void TestTreeModel::handleUnnamedQuickParseResult(const TestParseResultPtr result) void TestTreeModel::handleUnnamedQuickParseResult(const TestParseResultPtr result)
{ {
const QuickTestParseResult &parseResult = static_cast<const QuickTestParseResult &>(*result);
TestTreeItem *toBeModified = unnamedQuickTests(); TestTreeItem *toBeModified = unnamedQuickTests();
if (!toBeModified) { if (!toBeModified) {
m_quickTestRootItem->appendChild(QuickTestTreeItem::createUnnamedQuickTestItem(parseResult)); m_quickTestRootItem->appendChild(QuickTestTreeItem::createTestItem(result.data()));
return; return;
} }
// if we have already Unnamed Quick tests we might update them.. // if we have already Unnamed Quick tests we might update them..
foreach (const QString &func, parseResult.functions.keys()) { foreach (const TestParseResult *funcResult, result->children) {
const TestCodeLocationAndType &location = parseResult.functions.value(func); TestTreeItem *functionItem = toBeModified->findChildByNameAndFile(funcResult->name,
TestTreeItem *functionItem = toBeModified->findChildByNameAndFile(func, location.m_name); funcResult->fileName);
if (!functionItem) { if (!functionItem) {
toBeModified->appendChild(QuickTestTreeItem::createUnnamedQuickFunctionItem( toBeModified->appendChild(QuickTestTreeItem::createTestItem(funcResult));
func, parseResult));
continue; continue;
} }
functionItem->modifyLineAndColumn(location); functionItem->modifyLineAndColumn(funcResult->line, funcResult->column);
functionItem->markForRemoval(false); functionItem->markForRemoval(false);
} }
} }
void TestTreeModel::handleGTestParseResult(const TestParseResultPtr result) void TestTreeModel::handleGTestParseResult(const TestParseResultPtr result)
{ {
const GoogleTestParseResult &parseResult = static_cast<const GoogleTestParseResult &>(*result); QTC_ASSERT(!result->children.isEmpty(), return);
QTC_ASSERT(!parseResult.testSets.isEmpty(), return); const GoogleTestParseResult *parseResult = static_cast<const GoogleTestParseResult *>(result.data());
GoogleTestTreeItem::TestStates states = GoogleTestTreeItem::Enabled; GoogleTestTreeItem::TestStates states = GoogleTestTreeItem::Enabled;
if (parseResult.parameterized) if (parseResult->parameterized)
states |= GoogleTestTreeItem::Parameterized; states |= GoogleTestTreeItem::Parameterized;
if (parseResult.typed) if (parseResult->typed)
states |= GoogleTestTreeItem::Typed; states |= GoogleTestTreeItem::Typed;
TestTreeItem *toBeModified = m_googleTestRootItem->findChildByNameStateAndFile( TestTreeItem *toBeModified = m_googleTestRootItem->findChildByNameStateAndFile(
parseResult.testCaseName, states, parseResult.proFile); parseResult->name, states, parseResult->proFile);
if (!toBeModified) { if (!toBeModified) {
m_googleTestRootItem->appendChild(GoogleTestTreeItem::createTestItem(parseResult)); m_googleTestRootItem->appendChild(GoogleTestTreeItem::createTestItem(parseResult));
return; return;
} }
// if found nothing has to be updated as all relevant members are used to find the item // if found nothing has to be updated as all relevant members are used to find the item
foreach (const TestCodeLocationAndType &location , parseResult.testSets) { foreach (const TestParseResult *setResult, parseResult->children) {
TestTreeItem *testSetItem = toBeModified->findChildByNameAndFile(location.m_name, const GoogleTestParseResult *testSet = static_cast<const GoogleTestParseResult *>(setResult);
parseResult.fileName); TestTreeItem *testSetItem = toBeModified->findChildByNameAndFile(testSet->name,
testSet->fileName);
if (!testSetItem) { if (!testSetItem) {
toBeModified->appendChild(GoogleTestTreeItem::createTestSetItem(parseResult, location)); toBeModified->appendChild(GoogleTestTreeItem::createTestItem(testSet));
continue; continue;
} }
bool changed = static_cast<GoogleTestTreeItem *>(testSetItem)->modifyTestSetContent( bool changed = static_cast<GoogleTestTreeItem *>(testSetItem)->modifyTestSetContent(testSet);
parseResult.fileName, location);
testSetItem->markForRemoval(false); testSetItem->markForRemoval(false);
if (changed) if (changed)
emit dataChanged(indexForItem(testSetItem), indexForItem(testSetItem)); emit dataChanged(indexForItem(testSetItem), indexForItem(testSetItem));