AutoTest: Unify TestTreeItem::modify*() functions

Change-Id: Ia234fb6a8a8466c039060f6f00b1a5e3dea2af9e
Reviewed-by: David Schulz <david.schulz@qt.io>
This commit is contained in:
Christian Stenger
2017-05-10 13:42:44 +02:00
parent 3bd32292b7
commit a9d511ff7d
6 changed files with 23 additions and 27 deletions

View File

@@ -239,7 +239,7 @@ bool GTestTreeItem::modify(const TestParseResult *result)
bool GTestTreeItem::modifyTestSetContent(const GTestParseResult *result) bool GTestTreeItem::modifyTestSetContent(const GTestParseResult *result)
{ {
bool hasBeenModified = modifyLineAndColumn(result->line, result->column); bool hasBeenModified = modifyLineAndColumn(result);
GTestTreeItem::TestStates states = result->disabled ? GTestTreeItem::Disabled GTestTreeItem::TestStates states = result->disabled ? GTestTreeItem::Disabled
: GTestTreeItem::Enabled; : GTestTreeItem::Enabled;
if (m_state != states) { if (m_state != states) {

View File

@@ -62,13 +62,13 @@ 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 GTestParseResult *result);
TestTreeItem *findChildByNameStateAndFile(const QString &name, TestTreeItem *findChildByNameStateAndFile(const QString &name,
GTestTreeItem::TestStates state, GTestTreeItem::TestStates state,
const QString &proFile) const; const QString &proFile) const;
QString nameSuffix() const; QString nameSuffix() const;
private: private:
bool modifyTestSetContent(const GTestParseResult *result);
GTestTreeItem::TestStates m_state; GTestTreeItem::TestStates m_state;
}; };

View File

@@ -243,13 +243,13 @@ bool QtTestTreeItem::modify(const TestParseResult *result)
switch (type()) { switch (type()) {
case TestCase: case TestCase:
return modifyTestCaseContent(result->name, result->line, result->column); return modifyTestCaseContent(result);
case TestFunctionOrSet: case TestFunctionOrSet:
case TestDataFunction: case TestDataFunction:
case TestSpecialFunction: case TestSpecialFunction:
return modifyTestFunctionContent(result); return modifyTestFunctionContent(result);
case TestDataTag: case TestDataTag:
return modifyDataTagContent(result->name, result->fileName, result->line, result->column); return modifyDataTagContent(result);
default: default:
return false; return false;
} }

View File

@@ -285,12 +285,11 @@ bool QuickTestTreeItem::modify(const TestParseResult *result)
switch (type()) { switch (type()) {
case TestCase: case TestCase:
return result->name.isEmpty() ? false : modifyTestCaseContent(result->name, result->line, return result->name.isEmpty() ? false : modifyTestCaseContent(result);
result->column);
case TestFunctionOrSet: case TestFunctionOrSet:
case TestDataFunction: case TestDataFunction:
case TestSpecialFunction: case TestSpecialFunction:
return name().isEmpty() ? modifyLineAndColumn(result->line, result->column) return name().isEmpty() ? modifyLineAndColumn(result)
: modifyTestFunctionContent(result); : modifyTestFunctionContent(result);
default: default:
return false; return false;

View File

@@ -115,39 +115,37 @@ Qt::ItemFlags TestTreeItem::flags(int /*column*/) const
} }
} }
bool TestTreeItem::modifyTestCaseContent(const QString &name, unsigned line, unsigned column) bool TestTreeItem::modifyTestCaseContent(const TestParseResult *result)
{ {
bool hasBeenModified = modifyName(name); bool hasBeenModified = modifyName(result->name);
hasBeenModified |= modifyLineAndColumn(line, column); hasBeenModified |= modifyLineAndColumn(result);
return hasBeenModified; return hasBeenModified;
} }
bool TestTreeItem::modifyTestFunctionContent(const TestParseResult *result) bool TestTreeItem::modifyTestFunctionContent(const TestParseResult *result)
{ {
bool hasBeenModified = modifyFilePath(result->fileName); bool hasBeenModified = modifyFilePath(result->fileName);
hasBeenModified |= modifyLineAndColumn(result->line, result->column); hasBeenModified |= modifyLineAndColumn(result);
return hasBeenModified; return hasBeenModified;
} }
// TODO pass TestParseResult * to all modifyXYZ() OR remove completely if possible bool TestTreeItem::modifyDataTagContent(const TestParseResult *result)
bool TestTreeItem::modifyDataTagContent(const QString &name, const QString &fileName,
unsigned line, unsigned column)
{ {
bool hasBeenModified = modifyFilePath(fileName);
hasBeenModified |= modifyName(name); bool hasBeenModified = modifyTestFunctionContent(result);
hasBeenModified |= modifyLineAndColumn(line, column); hasBeenModified |= modifyName(result->name);
return hasBeenModified; return hasBeenModified;
} }
bool TestTreeItem::modifyLineAndColumn(unsigned line, unsigned column) bool TestTreeItem::modifyLineAndColumn(const TestParseResult *result)
{ {
bool hasBeenModified = false; bool hasBeenModified = false;
if (m_line != line) { if (m_line != result->line) {
m_line = line; m_line = result->line;
hasBeenModified = true; hasBeenModified = true;
} }
if (m_column != column) { if (m_column != result->column) {
m_column = column; m_column = result->column;
hasBeenModified = true; hasBeenModified = true;
} }
return hasBeenModified; return hasBeenModified;

View File

@@ -70,11 +70,10 @@ public:
virtual QVariant data(int column, int role) const override; virtual QVariant data(int column, int role) const override;
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 TestParseResult *result);
bool modifyTestFunctionContent(const TestParseResult *result); bool modifyTestFunctionContent(const TestParseResult *result);
bool modifyDataTagContent(const QString &name, const QString &fileName, unsigned line, bool modifyDataTagContent(const TestParseResult *result);
unsigned column); bool modifyLineAndColumn(const TestParseResult *result);
bool modifyLineAndColumn(unsigned line, unsigned column);
const QString name() const { return m_name; } const QString name() const { return m_name; }
void setName(const QString &name) { m_name = name; } void setName(const QString &name) { m_name = name; }
@@ -112,12 +111,12 @@ public:
virtual bool modify(const TestParseResult *result) = 0; virtual bool modify(const TestParseResult *result) = 0;
protected: protected:
bool modifyFilePath(const QString &filePath);
typedef std::function<bool(const TestTreeItem *)> CompareFunction; typedef std::function<bool(const TestTreeItem *)> CompareFunction;
TestTreeItem *findChildBy(CompareFunction compare) const; TestTreeItem *findChildBy(CompareFunction compare) const;
private: private:
void revalidateCheckState(); void revalidateCheckState();
bool modifyFilePath(const QString &filePath);
bool modifyName(const QString &name); bool modifyName(const QString &name);
enum Status enum Status