Commit 7a331b8c authored by Christian Stenger's avatar Christian Stenger
Browse files

AutoTest: Provide mark and sweep functions



Actually they are not used, this is a preparation for later patches.

Change-Id: I25f43dd7dba06068ca9e39ccd4153361a7746304
Reviewed-by: default avatarDavid Schulz <david.schulz@theqtcompany.com>
parent 1caeb9bb
......@@ -41,7 +41,8 @@ TestTreeItem::TestTreeItem(const QString &name, const QString &filePath, Type ty
m_filePath(filePath),
m_type(type),
m_line(0),
m_state(Enabled)
m_state(Enabled),
m_markedForRemoval(false)
{
switch (m_type) {
case TestClass:
......@@ -71,7 +72,8 @@ TestTreeItem::TestTreeItem(const TestTreeItem &other)
m_column(other.m_column),
m_mainFile(other.m_mainFile),
m_referencingFile(other.m_referencingFile),
m_state(other.m_state)
m_state(other.m_state),
m_markedForRemoval(other.m_markedForRemoval)
{
for (int row = 0, count = other.childCount(); row < count; ++row)
appendChild(new TestTreeItem(*childItem(row)));
......@@ -198,6 +200,8 @@ bool TestTreeItem::modifyContent(const TestTreeItem *modified)
m_state = modified->m_state;
hasBeenModified = true;
}
if (m_markedForRemoval != modified->m_markedForRemoval)
m_markedForRemoval = modified->m_markedForRemoval;
return hasBeenModified;
}
......@@ -242,6 +246,18 @@ Qt::CheckState TestTreeItem::checked() const
return Qt::Unchecked;
}
void TestTreeItem::markForRemoval(bool mark)
{
m_markedForRemoval = mark;
}
void TestTreeItem::markForRemovalRecursively(bool mark)
{
m_markedForRemoval = mark;
for (int row = 0, count = childCount(); row < count; ++row)
childItem(row)->markForRemovalRecursively(mark);
}
QList<QString> TestTreeItem::getChildNames() const
{
QList<QString> names;
......
......@@ -94,6 +94,9 @@ public:
Type type() const { return m_type; }
void setState(TestStates states) { m_state = states; }
TestStates state() const { return m_state; }
void markForRemoval(bool mark);
void markForRemovalRecursively(bool mark);
bool markedForRemoval() const { return m_markedForRemoval; }
QList<QString> getChildNames() const;
TestTreeItem *parentItem() const;
TestTreeItem *childItem(int row) const;
......@@ -110,6 +113,7 @@ private:
QString m_mainFile; // main for Quick tests, project file for gtest
QString m_referencingFile;
TestStates m_state;
bool m_markedForRemoval;
};
struct TestCodeLocationAndType {
......
......@@ -623,6 +623,87 @@ void TestTreeModel::removeGTests(const QString &filePath)
emit testTreeModelChanged();
}
void TestTreeModel::markAllForRemoval()
{
foreach (Utils::TreeItem *item, m_autoTestRootItem->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);
}
void TestTreeModel::markForRemoval(const QString &filePath)
{
if (filePath.isEmpty())
return;
Type types[] = { AutoTest, QuickTest, GoogleTest };
for (Type type : types) {
TestTreeItem *root = rootItemForType(type);
for (int childRow = root->childCount() - 1; childRow >= 0; --childRow) {
TestTreeItem *child = root->childItem(childRow);
if (child->markedForRemoval())
continue;
// Qt + named Quick Tests
if (child->filePath() == filePath || child->referencingFile() == filePath) {
child->markForRemovalRecursively(true);
} else {
// unnamed Quick Tests and GTest and Qt Tests with separated source/header
int grandChildRow = child->childCount() - 1;
for ( ; grandChildRow >= 0; --grandChildRow) {
TestTreeItem *grandChild = child->childItem(grandChildRow);
if (grandChild->filePath() == filePath
|| grandChild->referencingFile() == filePath) {
grandChild->markForRemovalRecursively(true);
}
}
}
}
}
}
void TestTreeModel::sweep()
{
bool hasChanged = false;
Type types[] = { AutoTest, QuickTest, GoogleTest };
for (Type type : types) {
TestTreeItem *root = rootItemForType(type);
hasChanged |= sweepChildren(root);
}
if (hasChanged)
emit testTreeModelChanged();
}
/**
* @note after calling this function emit testTreeModelChanged() if it returns true
*/
bool TestTreeModel::sweepChildren(TestTreeItem *item)
{
bool hasChanged = false;
for (int row = item->childCount() - 1; row >= 0; --row) {
TestTreeItem *child = item->childItem(row);
if (child->parentItem()->type() != TestTreeItem::Root && child->markedForRemoval()) {
delete takeItem(child);
hasChanged = true;
continue;
}
if (bool noEndNode = child->hasChildren()) {
hasChanged |= sweepChildren(child);
if (noEndNode && child->childCount() == 0) {
delete takeItem(child);
hasChanged = true;
continue;
}
}
child->markForRemoval(false);
}
return hasChanged;
}
QMap<QString, QString> TestTreeModel::referencingFiles() const
{
ReferencingFilesFinder finder;
......
......@@ -78,6 +78,9 @@ public:
QMultiMap<QString, int> gtestNamesAndSets() const;
#endif
void markAllForRemoval();
void markForRemoval(const QString &filePath);
void sweep();
QMap<QString, QString> referencingFiles() const;
signals:
......@@ -94,6 +97,7 @@ private:
void removeTestTreeItems(const QString &filePath, Type type);
void removeUnnamedQuickTests(const QString &filePath);
void removeGTests(const QString &filePath);
bool sweepChildren(TestTreeItem *item);
TestTreeItem *unnamedQuickTests() const;
TestTreeItem *rootItemForType(Type 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