Commit 8288eada authored by Christian Stenger's avatar Christian Stenger

AutoTest: Unify handling of run modes

Move used enums more central to avoid duplicating
information and unify their usages.

Change-Id: I33e9bdc11f7da16ecabf03991b5a5f550a53bdad
Reviewed-by: Oliver Wolff's avatarOliver Wolff <oliver.wolff@qt.io>
parent f8857855
......@@ -45,4 +45,14 @@ const char FRAMEWORK_PREFIX[] = "AutoTest.Framework.";
const char SETTINGSPAGE_PREFIX[] = "A.AutoTest.";
const char SETTINGSGROUP[] = "Autotest";
} // namespace Constants
namespace Internal {
enum class TestRunMode
{
Run,
RunWithoutDeploy,
Debug,
DebugWithoutDeploy
};
} // namespace Internal
} // namespace Autotest
......@@ -170,7 +170,7 @@ void AutotestPlugin::onRunAllTriggered()
TestRunner *runner = TestRunner::instance();
TestTreeModel *model = TestTreeModel::instance();
runner->setSelectedTests(model->getAllTestCases());
runner->prepareToRunTests(TestRunner::Run);
runner->prepareToRunTests(TestRunMode::Run);
}
void AutotestPlugin::onRunSelectedTriggered()
......@@ -178,7 +178,7 @@ void AutotestPlugin::onRunSelectedTriggered()
TestRunner *runner = TestRunner::instance();
TestTreeModel *model = TestTreeModel::instance();
runner->setSelectedTests(model->getSelectedTests());
runner->prepareToRunTests(TestRunner::Run);
runner->prepareToRunTests(TestRunMode::Run);
}
void AutotestPlugin::updateMenuItemsEnabledState()
......
......@@ -62,7 +62,7 @@ QStringList GTestConfiguration::argumentsForTestRunner() const
if (gSettings->throwOnFailure)
arguments << "--gtest_throw_on_failure";
if (runMode() == DebuggableTestConfiguration::Debug) {
if (isDebugRunMode()) {
if (gSettings->breakOnFailure)
arguments << "--gtest_break_on_failure";
}
......
......@@ -115,7 +115,7 @@ TestConfiguration *GTestTreeItem::debugConfiguration() const
{
GTestConfiguration *config = static_cast<GTestConfiguration *>(testConfiguration());
if (config)
config->setRunMode(DebuggableTestConfiguration::Debug);
config->setRunMode(TestRunMode::Debug);
return config;
}
......
......@@ -73,7 +73,7 @@ QStringList QtTestConfiguration::argumentsForTestRunner() const
if (qtSettings->logSignalsSlots)
arguments << "-vs";
if (runMode() == DebuggableTestConfiguration::Debug) {
if (isDebugRunMode()) {
if (qtSettings->noCrashHandler)
arguments << "-nocrashhandler";
}
......
......@@ -142,7 +142,7 @@ TestConfiguration *QtTestTreeItem::debugConfiguration() const
{
QtTestConfiguration *config = static_cast<QtTestConfiguration *>(testConfiguration());
if (config)
config->setRunMode(DebuggableTestConfiguration::Debug);
config->setRunMode(TestRunMode::Debug);
return config;
}
......
......@@ -26,7 +26,6 @@
#include "testconfiguration.h"
#include "testoutputreader.h"
#include "testrunconfiguration.h"
#include "testrunner.h"
#include <cpptools/cppmodelmanager.h>
#include <cpptools/projectinfo.h>
......@@ -73,7 +72,7 @@ static QString ensureExeEnding(const QString& file)
return Utils::HostOsInfo::withExecutableSuffix(file);
}
void TestConfiguration::completeTestInformation(int runMode)
void TestConfiguration::completeTestInformation(TestRunMode runMode)
{
QTC_ASSERT(!m_projectFile.isEmpty(), return);
QTC_ASSERT(!m_buildTargets.isEmpty(), return);
......@@ -158,7 +157,7 @@ void TestConfiguration::completeTestInformation(int runMode)
m_runnable.executable = currentExecutable;
m_displayName = runConfig->displayName();
m_project = project;
if (runMode == TestRunner::Debug)
if (runMode == TestRunMode::Debug || runMode == TestRunMode::DebugWithoutDeploy)
m_runConfig = new TestRunConfiguration(runConfig->target(), this);
break;
}
......@@ -182,7 +181,7 @@ void TestConfiguration::completeTestInformation(int runMode)
m_project = project;
m_guessedConfiguration = true;
m_guessedFrom = rc->displayName();
if (runMode == TestRunner::Debug)
if (runMode == TestRunMode::Debug)
m_runConfig = new TestRunConfiguration(rc->target(), this);
}
} else {
......@@ -291,5 +290,10 @@ QString TestConfiguration::workingDirectory() const
return executable.isEmpty() ? executable : QFileInfo(executable).absolutePath();
}
bool DebuggableTestConfiguration::isDebugRunMode() const
{
return m_runMode == TestRunMode::Debug || m_runMode == TestRunMode::DebugWithoutDeploy;
}
} // namespace Internal
} // namespace Autotest
......@@ -50,13 +50,12 @@ class TestRunConfiguration;
using TestResultPtr = QSharedPointer<TestResult>;
class TestConfiguration
{
public:
explicit TestConfiguration();
virtual ~TestConfiguration();
void completeTestInformation(int runMode);
void completeTestInformation(TestRunMode runMode);
void setTestCases(const QStringList &testCases);
void setTestCaseCount(int count);
......@@ -104,21 +103,15 @@ private:
class DebuggableTestConfiguration : public TestConfiguration
{
public:
enum RunMode
{
Run,
Debug
};
explicit DebuggableTestConfiguration(RunMode runMode = Run) : m_runMode(runMode) {}
explicit DebuggableTestConfiguration(TestRunMode runMode = TestRunMode::Run)
: m_runMode(runMode) {}
~DebuggableTestConfiguration() {}
void setRunMode(RunMode mode) { m_runMode = mode; }
RunMode runMode() const { return m_runMode; }
void setRunMode(TestRunMode mode) { m_runMode = mode; }
TestRunMode runMode() const { return m_runMode; }
bool isDebugRunMode() const;
private:
RunMode m_runMode;
TestRunMode m_runMode;
};
} // namespace Internal
......
......@@ -136,13 +136,13 @@ void TestNavigationWidget::contextMenuEvent(QContextMenuEvent *event)
runThisTest->setEnabled(enabled);
connect(runThisTest, &QAction::triggered,
this, [this] () {
onRunThisTestTriggered(TestRunner::Run);
onRunThisTestTriggered(TestRunMode::Run);
});
runWithoutDeploy = new QAction(tr("Run Without Deployment"), &menu);
runWithoutDeploy->setEnabled(enabled);
connect(runWithoutDeploy, &QAction::triggered,
this, [this] () {
onRunThisTestTriggered(TestRunner::RunWithoutDeploy);
onRunThisTestTriggered(TestRunMode::RunWithoutDeploy);
});
}
if (item->canProvideDebugConfiguration()) {
......@@ -150,13 +150,13 @@ void TestNavigationWidget::contextMenuEvent(QContextMenuEvent *event)
debugThisTest->setEnabled(enabled);
connect(debugThisTest, &QAction::triggered,
this, [this] () {
onRunThisTestTriggered(TestRunner::Debug);
onRunThisTestTriggered(TestRunMode::Debug);
});
debugWithoutDeploy = new QAction(tr("Debug Without Deployment"), &menu);
debugWithoutDeploy->setEnabled(enabled);
connect(debugWithoutDeploy, &QAction::triggered,
this, [this] () {
onRunThisTestTriggered(TestRunner::DebugWithoutDeploy);
onRunThisTestTriggered(TestRunMode::DebugWithoutDeploy);
});
}
}
......@@ -291,7 +291,7 @@ void TestNavigationWidget::initializeFilterMenu()
m_filterMenu->addAction(action);
}
void TestNavigationWidget::onRunThisTestTriggered(TestRunner::Mode runMode)
void TestNavigationWidget::onRunThisTestTriggered(TestRunMode runMode)
{
const QModelIndexList selected = m_view->selectionModel()->selectedIndexes();
if (selected.isEmpty())
......@@ -303,12 +303,12 @@ void TestNavigationWidget::onRunThisTestTriggered(TestRunner::Mode runMode)
TestTreeItem *item = static_cast<TestTreeItem *>(sourceIndex.internalPointer());
TestConfiguration *configuration;
switch (runMode) {
case TestRunner::Run:
case TestRunner::RunWithoutDeploy:
case TestRunMode::Run:
case TestRunMode::RunWithoutDeploy:
configuration = item->testConfiguration();
break;
case TestRunner::Debug:
case TestRunner::DebugWithoutDeploy:
case TestRunMode::Debug:
case TestRunMode::DebugWithoutDeploy:
configuration = item->debugConfiguration();
break;
default:
......
......@@ -72,7 +72,7 @@ private:
void onParsingStarted();
void onParsingFinished();
void initializeFilterMenu();
void onRunThisTestTriggered(TestRunner::Mode runMode);
void onRunThisTestTriggered(TestRunMode runMode);
TestTreeModel *m_model;
TestTreeSortFilterModel *m_sortFilterModel;
......
......@@ -423,14 +423,14 @@ void TestResultsPane::onRunAllTriggered()
{
TestRunner *runner = TestRunner::instance();
runner->setSelectedTests(TestTreeModel::instance()->getAllTestCases());
runner->prepareToRunTests(TestRunner::Run);
runner->prepareToRunTests(TestRunMode::Run);
}
void TestResultsPane::onRunSelectedTriggered()
{
TestRunner *runner = TestRunner::instance();
runner->setSelectedTests(TestTreeModel::instance()->getSelectedTests());
runner->prepareToRunTests(TestRunner::Run);
runner->prepareToRunTests(TestRunMode::Run);
}
void TestResultsPane::initializeFilterMenu()
......
......@@ -127,7 +127,7 @@ static void performTestRun(QFutureInterface<TestResultPtr> &futureInterface,
QEventLoop eventLoop;
int testCaseCount = 0;
for (TestConfiguration *config : selectedTests) {
config->completeTestInformation(TestRunner::Run);
config->completeTestInformation(TestRunMode::Run);
if (config->project()) {
testCaseCount += config->testCaseCount();
if (!omitRunConfigWarnings && config->isGuessed()) {
......@@ -224,7 +224,7 @@ static void performTestRun(QFutureInterface<TestResultPtr> &futureInterface,
futureInterface.setProgressValue(testCaseCount);
}
void TestRunner::prepareToRunTests(Mode mode)
void TestRunner::prepareToRunTests(TestRunMode mode)
{
m_runMode = mode;
ProjectExplorer::Internal::ProjectExplorerSettings projectExplorerSettings =
......@@ -257,8 +257,8 @@ void TestRunner::prepareToRunTests(Mode mode)
return;
}
if (!projectExplorerSettings.buildBeforeDeploy || mode == TestRunner::DebugWithoutDeploy
|| mode == TestRunner::RunWithoutDeploy) {
if (!projectExplorerSettings.buildBeforeDeploy || mode == TestRunMode::DebugWithoutDeploy
|| mode == TestRunMode::RunWithoutDeploy) {
runOrDebugTests();
} else if (project->hasActiveBuildSettings()) {
buildProject(project);
......@@ -311,7 +311,7 @@ void TestRunner::debugTests()
QTC_ASSERT(m_selectedTests.size() == 1, onFinished();return);
TestConfiguration *config = m_selectedTests.first();
config->completeTestInformation(Debug);
config->completeTestInformation(TestRunMode::Debug);
if (!config->runConfiguration()) {
emit testResultReady(TestResultPtr(new FaultyTestResult(Result::MessageFatal,
TestRunner::tr("Failed to get run configuration."))));
......@@ -387,12 +387,12 @@ void TestRunner::debugTests()
void TestRunner::runOrDebugTests()
{
switch (m_runMode) {
case Run:
case RunWithoutDeploy:
case TestRunMode::Run:
case TestRunMode::RunWithoutDeploy:
runTests();
break;
case Debug:
case DebugWithoutDeploy:
case TestRunMode::Debug:
case TestRunMode::DebugWithoutDeploy:
debugTests();
break;
default:
......
......@@ -44,21 +44,13 @@ class TestRunner : public QObject
Q_OBJECT
public:
enum Mode
{
Run,
RunWithoutDeploy,
Debug,
DebugWithoutDeploy
};
static TestRunner* instance();
~TestRunner();
void setSelectedTests(const QList<TestConfiguration *> &selected);
bool isTestRunning() const { return m_executingTests; }
void prepareToRunTests(Mode mode);
void prepareToRunTests(TestRunMode mode);
signals:
void testRunStarted();
......@@ -79,7 +71,7 @@ private:
QFutureWatcher<TestResultPtr> m_futureWatcher;
QList<TestConfiguration *> m_selectedTests;
bool m_executingTests;
Mode m_runMode = Run;
TestRunMode m_runMode = TestRunMode::Run;
// temporarily used if building before running is necessary
QMetaObject::Connection m_buildConnect;
......
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