2022-08-19 15:59:36 +02:00
|
|
|
// Copyright (C) 2016 The Qt Company Ltd.
|
2022-12-21 10:12:09 +01:00
|
|
|
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
|
2014-12-04 14:05:19 +01:00
|
|
|
|
2020-10-09 13:07:55 +02:00
|
|
|
#include "testsettingspage.h"
|
|
|
|
|
|
2014-12-04 14:05:19 +01:00
|
|
|
#include "autotestconstants.h"
|
2020-10-09 13:07:55 +02:00
|
|
|
#include "autotestplugin.h"
|
2022-07-13 18:31:56 +02:00
|
|
|
#include "autotesttr.h"
|
2016-06-06 15:35:00 +02:00
|
|
|
#include "testframeworkmanager.h"
|
2014-12-04 14:05:19 +01:00
|
|
|
#include "testsettings.h"
|
2016-02-01 15:12:10 +01:00
|
|
|
#include "testtreemodel.h"
|
2014-12-04 14:05:19 +01:00
|
|
|
|
2020-10-09 13:07:55 +02:00
|
|
|
#include <utils/algorithm.h>
|
|
|
|
|
#include <utils/id.h>
|
2022-07-13 18:15:55 +02:00
|
|
|
#include <utils/infolabel.h>
|
|
|
|
|
#include <utils/layoutbuilder.h>
|
2017-01-06 07:20:25 +01:00
|
|
|
#include <utils/qtcassert.h>
|
2016-08-03 17:55:54 +02:00
|
|
|
#include <utils/utilsicons.h>
|
2014-12-04 14:05:19 +01:00
|
|
|
|
2022-07-13 18:15:55 +02:00
|
|
|
#include <QCheckBox>
|
|
|
|
|
#include <QComboBox>
|
|
|
|
|
#include <QGroupBox>
|
|
|
|
|
#include <QHeaderView>
|
|
|
|
|
#include <QLabel>
|
|
|
|
|
#include <QPushButton>
|
|
|
|
|
#include <QSpacerItem>
|
|
|
|
|
#include <QTreeWidget>
|
|
|
|
|
|
2023-01-16 15:00:15 +01:00
|
|
|
using namespace Utils;
|
|
|
|
|
|
2023-04-20 09:55:15 +02:00
|
|
|
namespace Autotest::Internal {
|
2014-12-04 14:05:19 +01:00
|
|
|
|
2023-04-20 09:55:15 +02:00
|
|
|
class TestSettingsWidget : public Core::IOptionsPageWidget
|
2022-07-13 18:15:55 +02:00
|
|
|
{
|
|
|
|
|
public:
|
2023-05-12 11:00:00 +02:00
|
|
|
TestSettingsWidget();
|
2023-04-20 09:55:15 +02:00
|
|
|
|
2022-07-13 18:15:55 +02:00
|
|
|
private:
|
2023-01-16 15:00:15 +01:00
|
|
|
void populateFrameworksListWidget(const QHash<Id, bool> &frameworks,
|
|
|
|
|
const QHash<Id, bool> &testTools);
|
2023-05-12 11:00:00 +02:00
|
|
|
void testSettings(NonAspectSettings &settings) const;
|
|
|
|
|
void testToolsSettings(NonAspectSettings &settings) const;
|
2022-07-13 18:15:55 +02:00
|
|
|
void onFrameworkItemChanged();
|
|
|
|
|
|
|
|
|
|
QTreeWidget *m_frameworkTreeWidget;
|
2023-01-16 15:00:15 +01:00
|
|
|
InfoLabel *m_frameworksWarn;
|
2022-07-13 18:15:55 +02:00
|
|
|
};
|
|
|
|
|
|
2023-05-12 11:00:00 +02:00
|
|
|
TestSettingsWidget::TestSettingsWidget()
|
2014-12-04 14:05:19 +01:00
|
|
|
{
|
2022-07-13 18:31:56 +02:00
|
|
|
auto timeoutLabel = new QLabel(Tr::tr("Timeout:"));
|
|
|
|
|
timeoutLabel->setToolTip(Tr::tr("Timeout used when executing each test case."));
|
2023-06-30 10:53:08 +02:00
|
|
|
auto scanThreadLabel = new QLabel(Tr::tr("Scan threads:"));
|
|
|
|
|
scanThreadLabel->setToolTip("Number of worker threads used when scanning for tests.");
|
2022-07-13 18:15:55 +02:00
|
|
|
|
|
|
|
|
m_frameworkTreeWidget = new QTreeWidget;
|
|
|
|
|
m_frameworkTreeWidget->setRootIsDecorated(false);
|
|
|
|
|
m_frameworkTreeWidget->setHeaderHidden(false);
|
|
|
|
|
m_frameworkTreeWidget->setColumnCount(2);
|
|
|
|
|
m_frameworkTreeWidget->header()->setDefaultSectionSize(150);
|
2022-07-13 18:31:56 +02:00
|
|
|
m_frameworkTreeWidget->setToolTip(Tr::tr("Selects the test frameworks to be handled by the AutoTest plugin."));
|
2022-07-13 18:15:55 +02:00
|
|
|
|
|
|
|
|
QTreeWidgetItem *item = m_frameworkTreeWidget->headerItem();
|
2022-07-13 18:31:56 +02:00
|
|
|
item->setText(0, Tr::tr("Framework"));
|
|
|
|
|
item->setToolTip(0, Tr::tr("Selects the test frameworks to be handled by the AutoTest plugin."));
|
|
|
|
|
item->setText(1, Tr::tr("Group"));
|
|
|
|
|
item->setToolTip(1, Tr::tr("Enables grouping of test cases."));
|
2022-07-13 18:15:55 +02:00
|
|
|
|
2023-01-16 15:00:15 +01:00
|
|
|
m_frameworksWarn = new InfoLabel;
|
2022-07-13 18:15:55 +02:00
|
|
|
m_frameworksWarn->setVisible(false);
|
|
|
|
|
m_frameworksWarn->setElideMode(Qt::ElideNone);
|
2023-01-16 15:00:15 +01:00
|
|
|
m_frameworksWarn->setType(InfoLabel::Warning);
|
2022-07-13 18:15:55 +02:00
|
|
|
|
2023-01-16 15:00:15 +01:00
|
|
|
using namespace Layouting;
|
2022-07-13 18:15:55 +02:00
|
|
|
|
2022-08-01 18:18:02 +02:00
|
|
|
PushButton resetChoicesButton {
|
|
|
|
|
text(Tr::tr("Reset Cached Choices")),
|
|
|
|
|
tooltip(Tr::tr("Clear all cached choices of run configurations for "
|
|
|
|
|
"tests where the executable could not be deduced.")),
|
|
|
|
|
onClicked([] { AutotestPlugin::clearChoiceCache(); }, this)
|
|
|
|
|
};
|
|
|
|
|
|
2023-05-12 11:00:00 +02:00
|
|
|
TestSettings &s = *TestSettings::instance();
|
2022-07-13 18:15:55 +02:00
|
|
|
Group generalGroup {
|
2022-07-13 18:31:56 +02:00
|
|
|
title(Tr::tr("General")),
|
2022-07-13 18:15:55 +02:00
|
|
|
Column {
|
2023-06-30 10:53:08 +02:00
|
|
|
Row { scanThreadLabel, s.scanThreadLimit, st },
|
2023-05-12 11:00:00 +02:00
|
|
|
s.omitInternalMsg,
|
|
|
|
|
s.omitRunConfigWarn,
|
|
|
|
|
s.limitResultOutput,
|
|
|
|
|
Row { s.limitResultDescription, s.resultDescriptionMaxSize, st },
|
|
|
|
|
s.popupOnStart,
|
|
|
|
|
s.popupOnFinish,
|
|
|
|
|
Row { Space(20), s.popupOnFail },
|
|
|
|
|
s.autoScroll,
|
|
|
|
|
s.displayApplication,
|
|
|
|
|
s.processArgs,
|
|
|
|
|
Row { Tr::tr("Automatically run"), s.runAfterBuild, st },
|
|
|
|
|
Row { timeoutLabel, s.timeout, st },
|
2022-07-22 18:54:04 +02:00
|
|
|
Row { resetChoicesButton, st }
|
2022-07-13 18:15:55 +02:00
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
Group activeFrameworks {
|
2022-07-13 18:31:56 +02:00
|
|
|
title(Tr::tr("Active Test Frameworks")),
|
2022-07-13 18:15:55 +02:00
|
|
|
Column {
|
|
|
|
|
m_frameworkTreeWidget,
|
|
|
|
|
m_frameworksWarn,
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
Column {
|
|
|
|
|
Row {
|
2022-07-22 18:54:04 +02:00
|
|
|
Column { generalGroup, st },
|
|
|
|
|
Column { activeFrameworks, st }
|
2022-07-13 18:15:55 +02:00
|
|
|
},
|
2022-07-22 18:54:04 +02:00
|
|
|
st
|
2022-07-13 18:15:55 +02:00
|
|
|
}.attachTo(this);
|
|
|
|
|
|
|
|
|
|
connect(m_frameworkTreeWidget, &QTreeWidget::itemChanged,
|
2016-06-08 12:56:25 +02:00
|
|
|
this, &TestSettingsWidget::onFrameworkItemChanged);
|
2023-05-12 11:00:00 +02:00
|
|
|
|
|
|
|
|
populateFrameworksListWidget(s.frameworks, s.tools);
|
2014-12-04 14:05:19 +01:00
|
|
|
|
2023-05-08 17:36:03 +02:00
|
|
|
setOnApply([this] {
|
2023-05-12 11:00:00 +02:00
|
|
|
TestSettings &s = *TestSettings::instance();
|
|
|
|
|
|
|
|
|
|
NonAspectSettings tmp;
|
|
|
|
|
testSettings(tmp);
|
|
|
|
|
testToolsSettings(tmp);
|
|
|
|
|
|
|
|
|
|
const QList<Utils::Id> changedIds = Utils::filtered(tmp.frameworksGrouping.keys(),
|
|
|
|
|
[&tmp, &s](Utils::Id id) {
|
|
|
|
|
return tmp.frameworksGrouping[id] != s.frameworksGrouping[id];
|
2023-05-08 17:36:03 +02:00
|
|
|
});
|
|
|
|
|
|
2023-05-12 11:00:00 +02:00
|
|
|
testSettings(s);
|
|
|
|
|
testToolsSettings(s);
|
2023-07-06 09:57:16 +02:00
|
|
|
s.toSettings();
|
2023-05-08 17:36:03 +02:00
|
|
|
|
|
|
|
|
for (ITestFramework *framework : TestFrameworkManager::registeredFrameworks()) {
|
2023-05-12 11:00:00 +02:00
|
|
|
framework->setActive(s.frameworks.value(framework->id(), false));
|
|
|
|
|
framework->setGrouping(s.frameworksGrouping.value(framework->id(), false));
|
2023-05-08 17:36:03 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for (ITestTool *testTool : TestFrameworkManager::registeredTestTools())
|
2023-05-12 11:00:00 +02:00
|
|
|
testTool->setActive(s.tools.value(testTool->id(), false));
|
2023-05-08 17:36:03 +02:00
|
|
|
|
|
|
|
|
TestTreeModel::instance()->synchronizeTestFrameworks();
|
|
|
|
|
TestTreeModel::instance()->synchronizeTestTools();
|
|
|
|
|
if (!changedIds.isEmpty())
|
|
|
|
|
TestTreeModel::instance()->rebuild(changedIds);
|
|
|
|
|
});
|
2014-12-04 14:05:19 +01:00
|
|
|
}
|
|
|
|
|
|
2020-10-19 14:46:21 +02:00
|
|
|
enum TestBaseInfo
|
|
|
|
|
{
|
|
|
|
|
BaseId = Qt::UserRole,
|
|
|
|
|
BaseType
|
|
|
|
|
};
|
|
|
|
|
|
2023-01-16 15:00:15 +01:00
|
|
|
void TestSettingsWidget::populateFrameworksListWidget(const QHash<Id, bool> &frameworks,
|
|
|
|
|
const QHash<Id, bool> &testTools)
|
2016-06-06 15:35:00 +02:00
|
|
|
{
|
2020-03-26 12:01:59 +01:00
|
|
|
const TestFrameworks ®istered = TestFrameworkManager::registeredFrameworks();
|
2022-07-13 18:15:55 +02:00
|
|
|
m_frameworkTreeWidget->clear();
|
2020-03-13 13:54:33 +01:00
|
|
|
for (const ITestFramework *framework : registered) {
|
2023-01-16 15:00:15 +01:00
|
|
|
const Id id = framework->id();
|
2022-07-13 18:15:55 +02:00
|
|
|
auto item = new QTreeWidgetItem(m_frameworkTreeWidget, {framework->displayName()});
|
2016-06-06 15:35:00 +02:00
|
|
|
item->setFlags(Qt::ItemIsEnabled | Qt::ItemIsSelectable | Qt::ItemIsUserCheckable);
|
2018-01-09 13:15:11 +01:00
|
|
|
item->setCheckState(0, frameworks.value(id) ? Qt::Checked : Qt::Unchecked);
|
2020-10-19 14:46:21 +02:00
|
|
|
item->setData(0, BaseId, id.toSetting());
|
|
|
|
|
item->setData(0, BaseType, ITestBase::Framework);
|
2020-03-13 13:54:33 +01:00
|
|
|
item->setData(1, Qt::CheckStateRole, framework->grouping() ? Qt::Checked : Qt::Unchecked);
|
2022-07-13 18:31:56 +02:00
|
|
|
item->setToolTip(0, Tr::tr("Enable or disable test frameworks to be handled by the "
|
|
|
|
|
"AutoTest plugin."));
|
2020-03-13 13:54:33 +01:00
|
|
|
QString toolTip = framework->groupingToolTip();
|
2018-03-13 10:04:46 +01:00
|
|
|
if (toolTip.isEmpty())
|
2022-07-13 18:31:56 +02:00
|
|
|
toolTip = Tr::tr("Enable or disable grouping of test cases by folder.");
|
2018-03-13 10:04:46 +01:00
|
|
|
item->setToolTip(1, toolTip);
|
2016-06-06 15:35:00 +02:00
|
|
|
}
|
2020-10-19 14:46:21 +02:00
|
|
|
// ...and now the test tools
|
|
|
|
|
const TestTools ®isteredTools = TestFrameworkManager::registeredTestTools();
|
|
|
|
|
for (const ITestTool *testTool : registeredTools) {
|
2023-01-16 15:00:15 +01:00
|
|
|
const Id id = testTool->id();
|
2022-07-13 18:15:55 +02:00
|
|
|
auto item = new QTreeWidgetItem(m_frameworkTreeWidget, {testTool->displayName()});
|
2020-10-19 14:46:21 +02:00
|
|
|
item->setFlags(Qt::ItemIsEnabled | Qt::ItemIsSelectable | Qt::ItemIsUserCheckable);
|
|
|
|
|
item->setCheckState(0, testTools.value(id) ? Qt::Checked : Qt::Unchecked);
|
|
|
|
|
item->setData(0, BaseId, id.toSetting());
|
|
|
|
|
item->setData(0, BaseType, ITestBase::Tool);
|
|
|
|
|
}
|
2016-06-06 15:35:00 +02:00
|
|
|
}
|
|
|
|
|
|
2023-05-12 11:00:00 +02:00
|
|
|
void TestSettingsWidget::testSettings(NonAspectSettings &settings) const
|
2016-06-06 15:35:00 +02:00
|
|
|
{
|
2022-07-13 18:15:55 +02:00
|
|
|
const QAbstractItemModel *model = m_frameworkTreeWidget->model();
|
2017-12-06 08:45:36 +01:00
|
|
|
QTC_ASSERT(model, return);
|
2020-10-19 14:46:21 +02:00
|
|
|
const int itemCount = TestFrameworkManager::registeredFrameworks().size();
|
|
|
|
|
QTC_ASSERT(itemCount <= model->rowCount(), return);
|
2016-06-06 15:35:00 +02:00
|
|
|
for (int row = 0; row < itemCount; ++row) {
|
2017-12-06 08:45:36 +01:00
|
|
|
QModelIndex idx = model->index(row, 0);
|
2023-01-16 15:00:15 +01:00
|
|
|
const Id id = Id::fromSetting(idx.data(BaseId));
|
2017-12-06 08:45:36 +01:00
|
|
|
settings.frameworks.insert(id, idx.data(Qt::CheckStateRole) == Qt::Checked);
|
|
|
|
|
idx = model->index(row, 1);
|
|
|
|
|
settings.frameworksGrouping.insert(id, idx.data(Qt::CheckStateRole) == Qt::Checked);
|
2016-06-06 15:35:00 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-05-12 11:00:00 +02:00
|
|
|
void TestSettingsWidget::testToolsSettings(NonAspectSettings &settings) const
|
2020-10-19 14:46:21 +02:00
|
|
|
{
|
2022-07-13 18:15:55 +02:00
|
|
|
const QAbstractItemModel *model = m_frameworkTreeWidget->model();
|
2020-10-19 14:46:21 +02:00
|
|
|
QTC_ASSERT(model, return);
|
|
|
|
|
// frameworks are listed before tools
|
|
|
|
|
int row = TestFrameworkManager::registeredFrameworks().size();
|
|
|
|
|
const int end = model->rowCount();
|
|
|
|
|
QTC_ASSERT(row <= end, return);
|
|
|
|
|
for ( ; row < end; ++row) {
|
|
|
|
|
const QModelIndex idx = model->index(row, 0);
|
2023-01-16 15:00:15 +01:00
|
|
|
const Id id = Id::fromSetting(idx.data(BaseId));
|
2020-10-19 14:46:21 +02:00
|
|
|
settings.tools.insert(id, idx.data(Qt::CheckStateRole) == Qt::Checked);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-06-08 12:56:25 +02:00
|
|
|
void TestSettingsWidget::onFrameworkItemChanged()
|
|
|
|
|
{
|
2020-10-19 14:46:21 +02:00
|
|
|
bool atLeastOneEnabled = false;
|
|
|
|
|
int mixed = ITestBase::None;
|
2022-07-13 18:15:55 +02:00
|
|
|
if (QAbstractItemModel *model = m_frameworkTreeWidget->model()) {
|
2018-01-09 13:15:11 +01:00
|
|
|
for (int row = 0, count = model->rowCount(); row < count; ++row) {
|
2020-10-19 14:46:21 +02:00
|
|
|
const QModelIndex idx = model->index(row, 0);
|
|
|
|
|
if (idx.data(Qt::CheckStateRole) == Qt::Checked) {
|
|
|
|
|
atLeastOneEnabled = true;
|
|
|
|
|
mixed |= idx.data(BaseType).toInt();
|
2018-01-09 13:15:11 +01:00
|
|
|
}
|
2016-06-08 12:56:25 +02:00
|
|
|
}
|
|
|
|
|
}
|
2020-10-19 14:46:21 +02:00
|
|
|
|
|
|
|
|
if (!atLeastOneEnabled || (mixed == (ITestBase::Framework | ITestBase::Tool))) {
|
|
|
|
|
if (!atLeastOneEnabled) {
|
2022-07-13 18:31:56 +02:00
|
|
|
m_frameworksWarn->setText(Tr::tr("No active test frameworks or tools."));
|
|
|
|
|
m_frameworksWarn->setToolTip(Tr::tr("You will not be able to use the AutoTest plugin "
|
|
|
|
|
"without having at least one active test framework."));
|
2020-10-19 14:46:21 +02:00
|
|
|
} else {
|
2022-07-13 18:31:56 +02:00
|
|
|
m_frameworksWarn->setText(Tr::tr("Mixing test frameworks and test tools."));
|
|
|
|
|
m_frameworksWarn->setToolTip(Tr::tr("Mixing test frameworks and test tools can lead "
|
|
|
|
|
"to duplicating run information when using "
|
2021-03-18 11:02:24 +01:00
|
|
|
"\"Run All Tests\", for example."));
|
2020-10-19 14:46:21 +02:00
|
|
|
}
|
|
|
|
|
}
|
2022-07-13 18:15:55 +02:00
|
|
|
m_frameworksWarn->setVisible(!atLeastOneEnabled
|
2020-10-19 14:46:21 +02:00
|
|
|
|| (mixed == (ITestBase::Framework | ITestBase::Tool)));
|
2016-06-08 12:56:25 +02:00
|
|
|
}
|
|
|
|
|
|
2023-04-20 09:55:15 +02:00
|
|
|
// TestSettingsPage
|
|
|
|
|
|
2023-05-12 11:00:00 +02:00
|
|
|
TestSettingsPage::TestSettingsPage()
|
2023-04-20 09:55:15 +02:00
|
|
|
{
|
|
|
|
|
setId(Constants::AUTOTEST_SETTINGS_ID);
|
|
|
|
|
setDisplayName(Tr::tr("General"));
|
|
|
|
|
setCategory(Constants::AUTOTEST_SETTINGS_CATEGORY);
|
|
|
|
|
setDisplayCategory(Tr::tr("Testing"));
|
|
|
|
|
setCategoryIconPath(":/autotest/images/settingscategory_autotest.png");
|
2023-05-12 11:00:00 +02:00
|
|
|
setWidgetCreator([] { return new TestSettingsWidget; });
|
2023-04-20 09:55:15 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} // Autotest::Internal
|