forked from qt-creator/qt-creator
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:
@@ -454,14 +454,29 @@ static bool checkQmlDocumentForTestCode(QFutureInterface<TestParseResultPtr> fut
|
||||
|
||||
const QString testCaseName = qmlVisitor.testCaseName();
|
||||
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->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()) {
|
||||
parseResult->fileName = tcLocationAndType.m_name;
|
||||
parseResult->testCaseName = testCaseName;
|
||||
parseResult->name = testCaseName;
|
||||
parseResult->line = tcLocationAndType.m_line;
|
||||
parseResult->column = tcLocationAndType.m_column;
|
||||
}
|
||||
@@ -491,21 +506,47 @@ static bool handleQtTest(QFutureInterface<TestParseResultPtr> futureInterface,
|
||||
if (!visitor.resultValid())
|
||||
return false;
|
||||
|
||||
const QMap<QString, TestCodeLocationAndType> testFunctions = visitor.privateSlots();
|
||||
const QMap<QString, TestCodeLocationAndType> &testFunctions = visitor.privateSlots();
|
||||
const QSet<QString> &files = filesWithDataFunctionDefinitions(testFunctions);
|
||||
|
||||
// TODO: change to QHash<>
|
||||
QMap<QString, TestCodeLocationList> dataTags;
|
||||
foreach (const QString &file, files)
|
||||
dataTags.unite(checkForDataTags(file));
|
||||
|
||||
QtTestParseResult *parseResult = new QtTestParseResult(TestTreeModel::AutoTest);
|
||||
QtTestParseResult *parseResult = new QtTestParseResult;
|
||||
parseResult->itemType = TestTreeItem::TestCase;
|
||||
parseResult->fileName = declaringDoc->fileName();
|
||||
parseResult->testCaseName = testCaseName;
|
||||
parseResult->name = testCaseName;
|
||||
parseResult->displayName = testCaseName;
|
||||
parseResult->line = line;
|
||||
parseResult->column = column;
|
||||
parseResult->functions = testFunctions;
|
||||
parseResult->dataTags = dataTags;
|
||||
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));
|
||||
return true;
|
||||
@@ -555,14 +596,28 @@ static bool handleGTest(QFutureInterface<TestParseResultPtr> futureInterface, co
|
||||
proFile = ppList.first()->projectFile;
|
||||
|
||||
foreach (const GTestCaseSpec &testSpec, result.keys()) {
|
||||
GoogleTestParseResult *parseResult = new GoogleTestParseResult(TestTreeModel::GoogleTest);
|
||||
GoogleTestParseResult *parseResult = new GoogleTestParseResult;
|
||||
parseResult->itemType = TestTreeItem::TestCase;
|
||||
parseResult->fileName = filePath;
|
||||
parseResult->testCaseName = testSpec.testCaseName;
|
||||
parseResult->name = testSpec.testCaseName;
|
||||
parseResult->parameterized = testSpec.parameterized;
|
||||
parseResult->typed = testSpec.typed;
|
||||
parseResult->disabled = testSpec.disabled;
|
||||
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));
|
||||
}
|
||||
return !result.keys().isEmpty();
|
||||
|
||||
@@ -47,12 +47,15 @@ class TestParseResult
|
||||
{
|
||||
public:
|
||||
explicit TestParseResult(TestTreeModel::Type t = TestTreeModel::Invalid) : type(t) {}
|
||||
virtual ~TestParseResult() {}
|
||||
virtual ~TestParseResult() { qDeleteAll(children); }
|
||||
|
||||
QVector<TestParseResult *> children;
|
||||
TestTreeModel::Type type;
|
||||
TestTreeItem::Type itemType = TestTreeItem::Root;
|
||||
QString displayName;
|
||||
QString fileName;
|
||||
QString proFile;
|
||||
QString testCaseName;
|
||||
QString name;
|
||||
unsigned line = 0;
|
||||
unsigned column = 0;
|
||||
};
|
||||
@@ -60,26 +63,22 @@ public:
|
||||
class QtTestParseResult : public TestParseResult
|
||||
{
|
||||
public:
|
||||
QtTestParseResult(TestTreeModel::Type t = TestTreeModel::Invalid) : TestParseResult(t) {}
|
||||
QMap<QString, TestCodeLocationAndType> functions;
|
||||
QMap<QString, TestCodeLocationList> dataTags;
|
||||
explicit QtTestParseResult() : TestParseResult(TestTreeModel::AutoTest) {}
|
||||
};
|
||||
|
||||
class QuickTestParseResult : public TestParseResult
|
||||
{
|
||||
public:
|
||||
QuickTestParseResult(TestTreeModel::Type t = TestTreeModel::Invalid) : TestParseResult(t) {}
|
||||
QMap<QString, TestCodeLocationAndType> functions;
|
||||
explicit QuickTestParseResult() : TestParseResult(TestTreeModel::QuickTest) {}
|
||||
};
|
||||
|
||||
class GoogleTestParseResult : public TestParseResult
|
||||
{
|
||||
public:
|
||||
GoogleTestParseResult(TestTreeModel::Type t = TestTreeModel::Invalid) : TestParseResult(t) {}
|
||||
explicit GoogleTestParseResult() : TestParseResult(TestTreeModel::GoogleTest) {}
|
||||
bool parameterized = false;
|
||||
bool typed = false;
|
||||
bool disabled = false;
|
||||
TestCodeLocationList testSets;
|
||||
};
|
||||
|
||||
using TestParseResultPtr = QSharedPointer<TestParseResult>;
|
||||
|
||||
@@ -129,27 +129,23 @@ bool TestTreeItem::modifyTestCaseContent(const QString &name, unsigned line, uns
|
||||
return hasBeenModified;
|
||||
}
|
||||
|
||||
bool TestTreeItem::modifyTestFunctionContent(const TestCodeLocationAndType &location)
|
||||
bool TestTreeItem::modifyTestFunctionContent(const TestParseResult *result)
|
||||
{
|
||||
bool hasBeenModified = modifyFilePath(location.m_name);
|
||||
hasBeenModified |= modifyLineAndColumn(location);
|
||||
bool hasBeenModified = modifyFilePath(result->fileName);
|
||||
hasBeenModified |= modifyLineAndColumn(result->line, result->column);
|
||||
return hasBeenModified;
|
||||
}
|
||||
|
||||
bool TestTreeItem::modifyDataTagContent(const QString &fileName,
|
||||
const TestCodeLocationAndType &location)
|
||||
// TODO pass TestParseResult * to all modifyXYZ() OR remove completely if possible
|
||||
bool TestTreeItem::modifyDataTagContent(const QString &name, const QString &fileName,
|
||||
unsigned line, unsigned column)
|
||||
{
|
||||
bool hasBeenModified = modifyFilePath(fileName);
|
||||
hasBeenModified |= modifyName(location.m_name);
|
||||
hasBeenModified |= modifyLineAndColumn(location);
|
||||
hasBeenModified |= modifyName(name);
|
||||
hasBeenModified |= modifyLineAndColumn(line, column);
|
||||
return hasBeenModified;
|
||||
}
|
||||
|
||||
bool TestTreeItem::modifyLineAndColumn(const TestCodeLocationAndType &location)
|
||||
{
|
||||
return modifyLineAndColumn(location.m_line, location.m_column);
|
||||
}
|
||||
|
||||
bool TestTreeItem::modifyLineAndColumn(unsigned line, unsigned column)
|
||||
{
|
||||
bool hasBeenModified = false;
|
||||
@@ -340,46 +336,19 @@ TestTreeItem *TestTreeItem::findChildBy(CompareFunction compare)
|
||||
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.testCaseName, result.fileName, TestCase);
|
||||
item->setProFile(parseResult.proFile);
|
||||
item->setLine(parseResult.line);
|
||||
item->setColumn(parseResult.column);
|
||||
AutoTestTreeItem *item = new AutoTestTreeItem(result->displayName, result->fileName,
|
||||
result->itemType);
|
||||
item->setProFile(result->proFile);
|
||||
item->setLine(result->line);
|
||||
item->setColumn(result->column);
|
||||
|
||||
foreach (const QString &functionName, parseResult.functions.keys()) {
|
||||
const TestCodeLocationAndType &locationAndType = parseResult.functions.value(functionName);
|
||||
const QString qualifiedName = result.testCaseName + QLatin1String("::") + functionName;
|
||||
item->appendChild(createFunctionItem(functionName, locationAndType,
|
||||
parseResult.dataTags.value(qualifiedName)));
|
||||
}
|
||||
foreach (const TestParseResult *funcParseResult, result->children)
|
||||
item->appendChild(createTestItem(funcParseResult));
|
||||
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
|
||||
{
|
||||
switch (role) {
|
||||
@@ -530,46 +499,15 @@ QList<TestConfiguration *> AutoTestTreeItem::getSelectedTestConfigurations() con
|
||||
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(parseResult.testCaseName, parseResult.fileName,
|
||||
TestCase);
|
||||
item->setProFile(result.proFile);
|
||||
item->setLine(result.line);
|
||||
item->setColumn(result.column);
|
||||
foreach (const QString &functionName, parseResult.functions.keys())
|
||||
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);
|
||||
QuickTestTreeItem *item = new QuickTestTreeItem(result->name, result->fileName,
|
||||
result->itemType);
|
||||
item->setProFile(result->proFile);
|
||||
item->setLine(result->line);
|
||||
item->setColumn(result->column);
|
||||
foreach (const TestParseResult *funcResult, result->children)
|
||||
item->appendChild(createTestItem(funcResult));
|
||||
return item;
|
||||
}
|
||||
|
||||
@@ -836,31 +774,23 @@ static QString gtestFilter(GoogleTestTreeItem::TestStates states)
|
||||
return QLatin1String("%1.%2");
|
||||
}
|
||||
|
||||
GoogleTestTreeItem *GoogleTestTreeItem::createTestItem(const TestParseResult &result)
|
||||
GoogleTestTreeItem *GoogleTestTreeItem::createTestItem(const TestParseResult *result)
|
||||
{
|
||||
const GoogleTestParseResult &parseResult = static_cast<const GoogleTestParseResult &>(result);
|
||||
GoogleTestTreeItem *item = new GoogleTestTreeItem(parseResult.testCaseName, QString(), TestCase);
|
||||
item->setProFile(parseResult.proFile);
|
||||
if (parseResult.parameterized)
|
||||
item->setState(Parameterized);
|
||||
if (parseResult.typed)
|
||||
item->setState(Typed);
|
||||
if (parseResult.disabled)
|
||||
item->setState(Disabled);
|
||||
foreach (const TestCodeLocationAndType &location, parseResult.testSets)
|
||||
item->appendChild(createTestSetItem(result, location));
|
||||
return item;
|
||||
}
|
||||
const GoogleTestParseResult *parseResult = static_cast<const GoogleTestParseResult *>(result);
|
||||
GoogleTestTreeItem *item = new GoogleTestTreeItem(parseResult->name, parseResult->fileName,
|
||||
parseResult->itemType);
|
||||
item->setProFile(parseResult->proFile);
|
||||
item->setLine(parseResult->line);
|
||||
item->setColumn(parseResult->column);
|
||||
|
||||
GoogleTestTreeItem *GoogleTestTreeItem::createTestSetItem(const TestParseResult &result,
|
||||
const TestCodeLocationAndType &location)
|
||||
{
|
||||
GoogleTestTreeItem *item = new GoogleTestTreeItem(location.m_name, result.fileName,
|
||||
location.m_type);
|
||||
item->setStates(location.m_state);
|
||||
item->setLine(location.m_line);
|
||||
item->setColumn(location.m_column);
|
||||
item->setProFile(result.proFile);
|
||||
if (parseResult->parameterized)
|
||||
item->setState(Parameterized);
|
||||
if (parseResult->typed)
|
||||
item->setState(Typed);
|
||||
if (parseResult->disabled)
|
||||
item->setState(Disabled);
|
||||
foreach (const TestParseResult *testSet, parseResult->children)
|
||||
item->appendChild(createTestItem(testSet));
|
||||
return item;
|
||||
}
|
||||
|
||||
@@ -1042,13 +972,13 @@ QList<TestConfiguration *> GoogleTestTreeItem::getSelectedTestConfigurations() c
|
||||
return result;
|
||||
}
|
||||
|
||||
bool GoogleTestTreeItem::modifyTestSetContent(const QString &fileName,
|
||||
const TestCodeLocationAndType &location)
|
||||
bool GoogleTestTreeItem::modifyTestSetContent(const GoogleTestParseResult *result)
|
||||
{
|
||||
bool hasBeenModified = modifyFilePath(fileName);
|
||||
hasBeenModified |= modifyLineAndColumn(location);
|
||||
if (m_state != location.m_state) {
|
||||
m_state = location.m_state;
|
||||
bool hasBeenModified = modifyLineAndColumn(result->line, result->column);
|
||||
GoogleTestTreeItem::TestStates states = result->disabled ? GoogleTestTreeItem::Disabled
|
||||
: GoogleTestTreeItem::Enabled;
|
||||
if (m_state != states) {
|
||||
m_state = states;
|
||||
hasBeenModified = true;
|
||||
}
|
||||
return hasBeenModified;
|
||||
|
||||
@@ -48,6 +48,7 @@ class AutoTestTreeItem;
|
||||
class QuickTestTreeItem;
|
||||
class GoogleTestTreeItem;
|
||||
class TestParseResult;
|
||||
class GoogleTestParseResult;
|
||||
class TestConfiguration;
|
||||
|
||||
class TestTreeItem : public Utils::TreeItem
|
||||
@@ -75,9 +76,9 @@ public:
|
||||
virtual bool setData(int column, const QVariant &data, int role) override;
|
||||
virtual Qt::ItemFlags flags(int column) const override;
|
||||
bool modifyTestCaseContent(const QString &name, unsigned line, unsigned column);
|
||||
bool modifyTestFunctionContent(const TestCodeLocationAndType &location);
|
||||
bool modifyDataTagContent(const QString &fileName, const TestCodeLocationAndType &location);
|
||||
bool modifyLineAndColumn(const TestCodeLocationAndType &location);
|
||||
bool modifyTestFunctionContent(const TestParseResult *result);
|
||||
bool modifyDataTagContent(const QString &name, const QString &fileName, unsigned line,
|
||||
unsigned column);
|
||||
bool modifyLineAndColumn(unsigned line, unsigned column);
|
||||
|
||||
const QString name() const { return m_name; }
|
||||
@@ -145,12 +146,7 @@ public:
|
||||
AutoTestTreeItem(const QString &name = QString(), const QString &filePath = QString(),
|
||||
Type type = Root) : TestTreeItem(name, filePath, type) {}
|
||||
|
||||
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);
|
||||
static AutoTestTreeItem *createTestItem(const TestParseResult *result);
|
||||
|
||||
QVariant data(int column, int role) const override;
|
||||
bool canProvideTestConfiguration() const override;
|
||||
@@ -165,12 +161,7 @@ public:
|
||||
QuickTestTreeItem(const QString &name = QString(), const QString &filePath = QString(),
|
||||
Type type = Root) : TestTreeItem(name, filePath, type) {}
|
||||
|
||||
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);
|
||||
static QuickTestTreeItem *createTestItem(const TestParseResult *result);
|
||||
|
||||
QVariant data(int column, int role) const override;
|
||||
Qt::ItemFlags flags(int column) const override;
|
||||
@@ -201,9 +192,7 @@ public:
|
||||
GoogleTestTreeItem(const QString &name = QString(), const QString &filePath = QString(),
|
||||
Type type = Root) : TestTreeItem(name, filePath, type), m_state(Enabled) {}
|
||||
|
||||
static GoogleTestTreeItem *createTestItem(const TestParseResult &result);
|
||||
static GoogleTestTreeItem *createTestSetItem(const TestParseResult &result,
|
||||
const TestCodeLocationAndType &location);
|
||||
static GoogleTestTreeItem *createTestItem(const TestParseResult *result);
|
||||
|
||||
QVariant data(int column, int role) const override;
|
||||
bool canProvideTestConfiguration() const override { return type() != Root; }
|
||||
@@ -214,7 +203,7 @@ public:
|
||||
void setStates(TestStates states) { m_state = states; }
|
||||
void setState(TestState state) { m_state |= 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,
|
||||
GoogleTestTreeItem::TestStates state,
|
||||
const QString &proFile);
|
||||
|
||||
@@ -332,42 +332,37 @@ void TestTreeModel::handleQtParseResult(const TestParseResultPtr result)
|
||||
TestTreeItem *toBeModified = m_autoTestRootItem->findChildByFile(result->fileName);
|
||||
// if there's no matching item, add the new one
|
||||
if (!toBeModified) {
|
||||
m_autoTestRootItem->appendChild(AutoTestTreeItem::createTestItem(*result));
|
||||
m_autoTestRootItem->appendChild(AutoTestTreeItem::createTestItem(result.data()));
|
||||
return;
|
||||
}
|
||||
// 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);
|
||||
toBeModified->markForRemoval(false);
|
||||
if (changed)
|
||||
emit dataChanged(indexForItem(toBeModified), indexForItem(toBeModified));
|
||||
// ...now the functions
|
||||
const QtTestParseResult &parseResult = static_cast<const QtTestParseResult &>(*result);
|
||||
foreach (const QString &func, parseResult.functions.keys()) {
|
||||
TestTreeItem *functionItem = toBeModified->findChildByName(func);
|
||||
foreach (const TestParseResult *funcResult, result->children) {
|
||||
TestTreeItem *functionItem = toBeModified->findChildByName(funcResult->displayName);
|
||||
if (!functionItem) {
|
||||
// if there's no function matching, add the new one
|
||||
const QString qualifiedName = parseResult.testCaseName + QLatin1String("::") + func;
|
||||
toBeModified->appendChild(AutoTestTreeItem::createFunctionItem(
|
||||
func, parseResult.functions.value(func),
|
||||
parseResult.dataTags.value(qualifiedName)));
|
||||
toBeModified->appendChild(AutoTestTreeItem::createTestItem(funcResult));
|
||||
continue;
|
||||
}
|
||||
// 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);
|
||||
if (changed)
|
||||
emit dataChanged(indexForItem(functionItem), indexForItem(functionItem));
|
||||
// ...now the data tags
|
||||
const QString &funcFileName = parseResult.functions.value(func).m_name;
|
||||
const QString qualifiedFunctionName = parseResult.testCaseName + QLatin1String("::") + func;
|
||||
foreach (const TestCodeLocationAndType &location, parseResult.dataTags.value(qualifiedFunctionName)) {
|
||||
TestTreeItem *dataTagItem = functionItem->findChildByName(location.m_name);
|
||||
foreach (const TestParseResult *tag, funcResult->children) {
|
||||
TestTreeItem *dataTagItem = functionItem->findChildByName(tag->name);
|
||||
if (!dataTagItem) {
|
||||
functionItem->appendChild(AutoTestTreeItem::createDataTagItem(funcFileName, location));
|
||||
functionItem->appendChild(AutoTestTreeItem::createTestItem(tag));
|
||||
continue;
|
||||
}
|
||||
changed = dataTagItem->modifyDataTagContent(funcFileName, location);
|
||||
changed = dataTagItem->modifyDataTagContent(tag->name, tag->fileName, tag->line,
|
||||
tag->column);
|
||||
dataTagItem->markForRemoval(false);
|
||||
if (changed)
|
||||
emit dataChanged(indexForItem(dataTagItem), indexForItem(dataTagItem));
|
||||
@@ -377,7 +372,7 @@ void TestTreeModel::handleQtParseResult(const TestParseResultPtr result)
|
||||
|
||||
void TestTreeModel::handleQuickParseResult(const TestParseResultPtr result)
|
||||
{
|
||||
if (result->testCaseName.isEmpty()) {
|
||||
if (result->name.isEmpty()) {
|
||||
handleUnnamedQuickParseResult(result);
|
||||
return;
|
||||
}
|
||||
@@ -385,28 +380,25 @@ void TestTreeModel::handleQuickParseResult(const TestParseResultPtr result)
|
||||
TestTreeItem *toBeModified = m_quickTestRootItem->findChildByFile(result->fileName);
|
||||
// if there's no matching item, add the new one
|
||||
if (!toBeModified) {
|
||||
m_quickTestRootItem->appendChild(QuickTestTreeItem::createTestItem(*result));
|
||||
m_quickTestRootItem->appendChild(QuickTestTreeItem::createTestItem(result.data()));
|
||||
return;
|
||||
}
|
||||
// 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);
|
||||
toBeModified->markForRemoval(false);
|
||||
if (changed)
|
||||
emit dataChanged(indexForItem(toBeModified), indexForItem(toBeModified));
|
||||
// ...now the functions
|
||||
|
||||
const QuickTestParseResult &parseResult = static_cast<const QuickTestParseResult &>(*result);
|
||||
foreach (const QString &func, parseResult.functions.keys()) {
|
||||
TestTreeItem *functionItem = toBeModified->findChildByName(func);
|
||||
foreach (const TestParseResult *funcResult, result->children) {
|
||||
TestTreeItem *functionItem = toBeModified->findChildByName(funcResult->name);
|
||||
if (!functionItem) {
|
||||
// if there's no matching, add the new one
|
||||
toBeModified->appendChild(QuickTestTreeItem::createFunctionItem(
|
||||
func, parseResult.functions.value(func)));
|
||||
toBeModified->appendChild(QuickTestTreeItem::createTestItem(funcResult));
|
||||
continue;
|
||||
}
|
||||
// else we have to modify..
|
||||
changed = functionItem->modifyTestFunctionContent(parseResult.functions.value(func));
|
||||
changed = functionItem->modifyTestFunctionContent(funcResult);
|
||||
functionItem->markForRemoval(false);
|
||||
if (changed)
|
||||
emit dataChanged(indexForItem(functionItem), indexForItem(functionItem));
|
||||
@@ -415,52 +407,50 @@ void TestTreeModel::handleQuickParseResult(const TestParseResultPtr result)
|
||||
|
||||
void TestTreeModel::handleUnnamedQuickParseResult(const TestParseResultPtr result)
|
||||
{
|
||||
const QuickTestParseResult &parseResult = static_cast<const QuickTestParseResult &>(*result);
|
||||
TestTreeItem *toBeModified = unnamedQuickTests();
|
||||
if (!toBeModified) {
|
||||
m_quickTestRootItem->appendChild(QuickTestTreeItem::createUnnamedQuickTestItem(parseResult));
|
||||
m_quickTestRootItem->appendChild(QuickTestTreeItem::createTestItem(result.data()));
|
||||
return;
|
||||
}
|
||||
// if we have already Unnamed Quick tests we might update them..
|
||||
foreach (const QString &func, parseResult.functions.keys()) {
|
||||
const TestCodeLocationAndType &location = parseResult.functions.value(func);
|
||||
TestTreeItem *functionItem = toBeModified->findChildByNameAndFile(func, location.m_name);
|
||||
foreach (const TestParseResult *funcResult, result->children) {
|
||||
TestTreeItem *functionItem = toBeModified->findChildByNameAndFile(funcResult->name,
|
||||
funcResult->fileName);
|
||||
if (!functionItem) {
|
||||
toBeModified->appendChild(QuickTestTreeItem::createUnnamedQuickFunctionItem(
|
||||
func, parseResult));
|
||||
toBeModified->appendChild(QuickTestTreeItem::createTestItem(funcResult));
|
||||
continue;
|
||||
}
|
||||
functionItem->modifyLineAndColumn(location);
|
||||
functionItem->modifyLineAndColumn(funcResult->line, funcResult->column);
|
||||
functionItem->markForRemoval(false);
|
||||
}
|
||||
}
|
||||
|
||||
void TestTreeModel::handleGTestParseResult(const TestParseResultPtr result)
|
||||
{
|
||||
const GoogleTestParseResult &parseResult = static_cast<const GoogleTestParseResult &>(*result);
|
||||
QTC_ASSERT(!parseResult.testSets.isEmpty(), return);
|
||||
QTC_ASSERT(!result->children.isEmpty(), return);
|
||||
const GoogleTestParseResult *parseResult = static_cast<const GoogleTestParseResult *>(result.data());
|
||||
|
||||
GoogleTestTreeItem::TestStates states = GoogleTestTreeItem::Enabled;
|
||||
if (parseResult.parameterized)
|
||||
if (parseResult->parameterized)
|
||||
states |= GoogleTestTreeItem::Parameterized;
|
||||
if (parseResult.typed)
|
||||
if (parseResult->typed)
|
||||
states |= GoogleTestTreeItem::Typed;
|
||||
TestTreeItem *toBeModified = m_googleTestRootItem->findChildByNameStateAndFile(
|
||||
parseResult.testCaseName, states, parseResult.proFile);
|
||||
parseResult->name, states, parseResult->proFile);
|
||||
if (!toBeModified) {
|
||||
m_googleTestRootItem->appendChild(GoogleTestTreeItem::createTestItem(parseResult));
|
||||
return;
|
||||
}
|
||||
// if found nothing has to be updated as all relevant members are used to find the item
|
||||
foreach (const TestCodeLocationAndType &location , parseResult.testSets) {
|
||||
TestTreeItem *testSetItem = toBeModified->findChildByNameAndFile(location.m_name,
|
||||
parseResult.fileName);
|
||||
foreach (const TestParseResult *setResult, parseResult->children) {
|
||||
const GoogleTestParseResult *testSet = static_cast<const GoogleTestParseResult *>(setResult);
|
||||
TestTreeItem *testSetItem = toBeModified->findChildByNameAndFile(testSet->name,
|
||||
testSet->fileName);
|
||||
if (!testSetItem) {
|
||||
toBeModified->appendChild(GoogleTestTreeItem::createTestSetItem(parseResult, location));
|
||||
toBeModified->appendChild(GoogleTestTreeItem::createTestItem(testSet));
|
||||
continue;
|
||||
}
|
||||
bool changed = static_cast<GoogleTestTreeItem *>(testSetItem)->modifyTestSetContent(
|
||||
parseResult.fileName, location);
|
||||
bool changed = static_cast<GoogleTestTreeItem *>(testSetItem)->modifyTestSetContent(testSet);
|
||||
testSetItem->markForRemoval(false);
|
||||
if (changed)
|
||||
emit dataChanged(indexForItem(testSetItem), indexForItem(testSetItem));
|
||||
|
||||
Reference in New Issue
Block a user