2016-06-01 16:22:50 +02:00
|
|
|
/****************************************************************************
|
|
|
|
|
**
|
|
|
|
|
** Copyright (C) 2016 The Qt Company Ltd.
|
|
|
|
|
** Contact: https://www.qt.io/licensing/
|
|
|
|
|
**
|
|
|
|
|
** This file is part of Qt Creator.
|
|
|
|
|
**
|
|
|
|
|
** Commercial License Usage
|
|
|
|
|
** Licensees holding valid commercial Qt licenses may use this file in
|
|
|
|
|
** accordance with the commercial license agreement provided with the
|
|
|
|
|
** Software or, alternatively, in accordance with the terms contained in
|
|
|
|
|
** a written agreement between you and The Qt Company. For licensing terms
|
|
|
|
|
** and conditions see https://www.qt.io/terms-conditions. For further
|
|
|
|
|
** information use the contact form at https://www.qt.io/contact-us.
|
|
|
|
|
**
|
|
|
|
|
** GNU General Public License Usage
|
|
|
|
|
** Alternatively, this file may be used under the terms of the GNU
|
|
|
|
|
** General Public License version 3 as published by the Free Software
|
|
|
|
|
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
|
|
|
|
|
** included in the packaging of this file. Please review the following
|
|
|
|
|
** information to ensure the GNU General Public License requirements will
|
|
|
|
|
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
|
|
|
|
|
**
|
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
|
|
#include "testframeworkmanager.h"
|
|
|
|
|
#include "autotestconstants.h"
|
2016-10-05 12:39:23 +02:00
|
|
|
#include "autotestplugin.h"
|
|
|
|
|
#include "iframeworksettings.h"
|
2016-06-01 16:22:50 +02:00
|
|
|
#include "itestparser.h"
|
2016-06-06 15:35:00 +02:00
|
|
|
#include "testsettings.h"
|
2016-06-01 16:22:50 +02:00
|
|
|
#include "testtreeitem.h"
|
|
|
|
|
#include "testtreemodel.h"
|
|
|
|
|
|
2020-01-10 12:00:37 +01:00
|
|
|
#include <coreplugin/dialogs/ioptionspage.h>
|
|
|
|
|
|
2016-06-01 16:22:50 +02:00
|
|
|
#include <utils/algorithm.h>
|
|
|
|
|
#include <utils/qtcassert.h>
|
|
|
|
|
|
|
|
|
|
#include <QLoggingCategory>
|
2016-10-05 13:34:57 +02:00
|
|
|
#include <QSettings>
|
2016-06-01 16:22:50 +02:00
|
|
|
|
2018-10-12 09:33:30 +03:00
|
|
|
static Q_LOGGING_CATEGORY(LOG, "qtc.autotest.frameworkmanager", QtWarningMsg)
|
2016-06-01 16:22:50 +02:00
|
|
|
|
2019-08-19 14:46:20 +02:00
|
|
|
using namespace Core;
|
|
|
|
|
|
2016-06-01 16:22:50 +02:00
|
|
|
namespace Autotest {
|
|
|
|
|
|
2017-09-27 15:00:11 +02:00
|
|
|
static TestFrameworkManager *s_instance = nullptr;
|
2016-06-01 16:22:50 +02:00
|
|
|
|
|
|
|
|
TestFrameworkManager::TestFrameworkManager()
|
|
|
|
|
{
|
|
|
|
|
s_instance = this;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TestFrameworkManager *TestFrameworkManager::instance()
|
|
|
|
|
{
|
|
|
|
|
return s_instance;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TestFrameworkManager::~TestFrameworkManager()
|
|
|
|
|
{
|
2020-03-19 16:59:59 +01:00
|
|
|
qDeleteAll(m_registeredFrameworks);
|
2020-03-26 09:21:25 +01:00
|
|
|
s_instance = nullptr;
|
2016-06-01 16:22:50 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool TestFrameworkManager::registerTestFramework(ITestFramework *framework)
|
|
|
|
|
{
|
|
|
|
|
QTC_ASSERT(framework, return false);
|
2020-03-19 16:59:59 +01:00
|
|
|
QTC_ASSERT(!m_registeredFrameworks.contains(framework), return false);
|
2016-06-06 15:35:00 +02:00
|
|
|
// TODO check for unique priority before registering
|
2020-03-19 16:59:59 +01:00
|
|
|
m_registeredFrameworks.append(framework);
|
2016-06-01 16:22:50 +02:00
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2020-02-28 12:27:13 +01:00
|
|
|
void TestFrameworkManager::activateFrameworksFromSettings(const Internal::TestSettings *settings)
|
2016-06-06 15:35:00 +02:00
|
|
|
{
|
2020-03-19 16:59:59 +01:00
|
|
|
for (ITestFramework *framework : qAsConst(m_registeredFrameworks)) {
|
|
|
|
|
framework->setActive(settings->frameworks.value(framework->id(), false));
|
|
|
|
|
framework->setGrouping(settings->frameworksGrouping.value(framework->id(), false));
|
2017-12-06 08:45:36 +01:00
|
|
|
}
|
2016-06-06 15:35:00 +02:00
|
|
|
}
|
|
|
|
|
|
2020-03-13 13:54:33 +01:00
|
|
|
TestFrameworks TestFrameworkManager::registeredFrameworks() const
|
2016-06-06 15:35:00 +02:00
|
|
|
{
|
2020-03-19 16:59:59 +01:00
|
|
|
return m_registeredFrameworks;
|
2016-06-06 15:35:00 +02:00
|
|
|
}
|
|
|
|
|
|
2020-03-13 13:54:33 +01:00
|
|
|
TestFrameworks TestFrameworkManager::sortedRegisteredFrameworks() const
|
2016-06-01 16:22:50 +02:00
|
|
|
{
|
2020-03-19 16:59:59 +01:00
|
|
|
TestFrameworks registered = m_registeredFrameworks;
|
2020-03-13 13:54:33 +01:00
|
|
|
Utils::sort(registered, &ITestFramework::priority);
|
2016-06-06 15:35:00 +02:00
|
|
|
qCDebug(LOG) << "Registered frameworks sorted by priority" << registered;
|
|
|
|
|
return registered;
|
|
|
|
|
}
|
|
|
|
|
|
2020-03-13 13:54:33 +01:00
|
|
|
TestFrameworks TestFrameworkManager::activeFrameworks() const
|
2016-06-01 16:22:50 +02:00
|
|
|
{
|
2020-03-13 13:54:33 +01:00
|
|
|
TestFrameworks active;
|
2020-03-19 16:59:59 +01:00
|
|
|
for (ITestFramework *framework : qAsConst(m_registeredFrameworks)) {
|
2020-03-13 13:54:33 +01:00
|
|
|
if (framework->active())
|
|
|
|
|
active.append(framework);
|
2016-06-06 15:35:00 +02:00
|
|
|
}
|
|
|
|
|
return active;
|
|
|
|
|
}
|
2016-06-01 16:22:50 +02:00
|
|
|
|
2020-03-13 13:54:33 +01:00
|
|
|
TestFrameworks TestFrameworkManager::sortedActiveFrameworks() const
|
2016-06-06 15:35:00 +02:00
|
|
|
{
|
2020-03-13 13:54:33 +01:00
|
|
|
TestFrameworks active = activeFrameworks();
|
|
|
|
|
Utils::sort(active, &ITestFramework::priority);
|
2016-06-06 15:35:00 +02:00
|
|
|
qCDebug(LOG) << "Active frameworks sorted by priority" << active;
|
|
|
|
|
return active;
|
2016-06-01 16:22:50 +02:00
|
|
|
}
|
|
|
|
|
|
2020-03-13 12:16:26 +01:00
|
|
|
ITestFramework *TestFrameworkManager::frameworkForId(Id frameworkId)
|
|
|
|
|
{
|
2020-03-19 16:59:59 +01:00
|
|
|
return Utils::findOrDefault(s_instance->m_registeredFrameworks,
|
|
|
|
|
[frameworkId](ITestFramework *framework) {
|
|
|
|
|
return framework->id() == frameworkId;
|
|
|
|
|
});
|
2020-03-13 12:16:26 +01:00
|
|
|
}
|
|
|
|
|
|
2016-10-05 12:39:23 +02:00
|
|
|
void TestFrameworkManager::synchronizeSettings(QSettings *s)
|
|
|
|
|
{
|
2019-08-19 10:55:32 +02:00
|
|
|
Internal::AutotestPlugin::settings()->fromSettings(s);
|
2020-03-19 16:59:59 +01:00
|
|
|
for (ITestFramework *framework : qAsConst(m_registeredFrameworks)) {
|
|
|
|
|
if (IFrameworkSettings *fSettings = framework->frameworkSettings())
|
2016-10-05 12:39:23 +02:00
|
|
|
fSettings->fromSettings(s);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-06-08 12:56:25 +02:00
|
|
|
bool TestFrameworkManager::hasActiveFrameworks() const
|
|
|
|
|
{
|
2020-03-19 16:59:59 +01:00
|
|
|
return Utils::anyOf(m_registeredFrameworks, &ITestFramework::active);
|
2016-06-08 12:56:25 +02:00
|
|
|
}
|
|
|
|
|
|
2020-01-10 12:00:37 +01:00
|
|
|
Id ITestFramework::settingsId() const
|
|
|
|
|
{
|
|
|
|
|
return Core::Id(Constants::SETTINGSPAGE_PREFIX)
|
|
|
|
|
.withSuffix(QString("%1.%2").arg(priority()).arg(QLatin1String(name())));
|
|
|
|
|
}
|
|
|
|
|
|
2016-06-01 16:22:50 +02:00
|
|
|
} // namespace Autotest
|