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 "itestframework.h"
|
|
|
|
|
#include "itestparser.h"
|
2016-10-24 09:00:20 +02:00
|
|
|
#include "itestsettingspage.h"
|
2016-06-01 16:22:50 +02:00
|
|
|
#include "testrunner.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"
|
|
|
|
|
|
|
|
|
|
#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
|
|
|
|
|
|
|
|
static Q_LOGGING_CATEGORY(LOG, "qtc.autotest.frameworkmanager")
|
|
|
|
|
|
|
|
|
|
namespace Autotest {
|
|
|
|
|
namespace Internal {
|
|
|
|
|
|
2017-09-27 15:00:11 +02:00
|
|
|
static TestFrameworkManager *s_instance = nullptr;
|
2016-06-01 16:22:50 +02:00
|
|
|
|
|
|
|
|
TestFrameworkManager::TestFrameworkManager()
|
|
|
|
|
{
|
|
|
|
|
m_testTreeModel = TestTreeModel::instance();
|
|
|
|
|
m_testRunner = TestRunner::instance();
|
|
|
|
|
s_instance = this;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TestFrameworkManager *TestFrameworkManager::instance()
|
|
|
|
|
{
|
|
|
|
|
if (!s_instance)
|
|
|
|
|
return new TestFrameworkManager;
|
|
|
|
|
return s_instance;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TestFrameworkManager::~TestFrameworkManager()
|
|
|
|
|
{
|
|
|
|
|
delete m_testRunner;
|
|
|
|
|
delete m_testTreeModel;
|
2016-06-06 15:35:00 +02:00
|
|
|
for (ITestFramework *framework : m_registeredFrameworks.values())
|
|
|
|
|
delete framework;
|
2016-06-01 16:22:50 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool TestFrameworkManager::registerTestFramework(ITestFramework *framework)
|
|
|
|
|
{
|
|
|
|
|
QTC_ASSERT(framework, return false);
|
|
|
|
|
Core::Id id = Core::Id(Constants::FRAMEWORK_PREFIX).withSuffix(framework->name());
|
2016-06-14 12:24:01 +02:00
|
|
|
QTC_ASSERT(!m_registeredFrameworks.contains(id), delete framework; return false);
|
2016-06-06 15:35:00 +02:00
|
|
|
// TODO check for unique priority before registering
|
|
|
|
|
qCDebug(LOG) << "Registering" << id;
|
2016-06-01 16:22:50 +02:00
|
|
|
m_registeredFrameworks.insert(id, framework);
|
2016-10-05 12:39:23 +02:00
|
|
|
|
2016-10-05 13:34:57 +02:00
|
|
|
AutotestPlugin *plugin = AutotestPlugin::instance();
|
|
|
|
|
|
2016-10-05 12:39:23 +02:00
|
|
|
if (framework->hasFrameworkSettings()) {
|
|
|
|
|
QSharedPointer<IFrameworkSettings> frameworkSettings(framework->createFrameworkSettings());
|
|
|
|
|
m_frameworkSettings.insert(id, frameworkSettings);
|
2016-10-05 13:34:57 +02:00
|
|
|
if (auto page = framework->createSettingsPage(frameworkSettings))
|
|
|
|
|
plugin->addAutoReleasedObject(page);
|
2016-10-05 12:39:23 +02:00
|
|
|
}
|
2016-06-01 16:22:50 +02:00
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2016-06-06 15:35:00 +02:00
|
|
|
void TestFrameworkManager::activateFrameworksFromSettings(QSharedPointer<TestSettings> settings)
|
|
|
|
|
{
|
|
|
|
|
FrameworkIterator it = m_registeredFrameworks.begin();
|
|
|
|
|
FrameworkIterator end = m_registeredFrameworks.end();
|
|
|
|
|
for ( ; it != end; ++it)
|
|
|
|
|
it.value()->setActive(settings->frameworks.value(it.key(), false));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QString TestFrameworkManager::frameworkNameForId(const Core::Id &id) const
|
|
|
|
|
{
|
2017-02-13 10:05:06 +01:00
|
|
|
ITestFramework *framework = m_registeredFrameworks.value(id, nullptr);
|
2016-06-06 15:35:00 +02:00
|
|
|
return framework ? QString::fromLatin1(framework->name()) : QString();
|
|
|
|
|
}
|
|
|
|
|
|
2016-06-01 16:22:50 +02:00
|
|
|
QList<Core::Id> TestFrameworkManager::registeredFrameworkIds() const
|
|
|
|
|
{
|
|
|
|
|
return m_registeredFrameworks.keys();
|
|
|
|
|
}
|
|
|
|
|
|
2016-06-06 15:35:00 +02:00
|
|
|
QList<Core::Id> TestFrameworkManager::sortedRegisteredFrameworkIds() const
|
|
|
|
|
{
|
|
|
|
|
QList<Core::Id> registered = m_registeredFrameworks.keys();
|
|
|
|
|
Utils::sort(registered, [this] (const Core::Id &lhs, const Core::Id &rhs) {
|
|
|
|
|
return m_registeredFrameworks[lhs]->priority() < m_registeredFrameworks[rhs]->priority();
|
|
|
|
|
});
|
|
|
|
|
qCDebug(LOG) << "Registered frameworks sorted by priority" << registered;
|
|
|
|
|
return registered;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QVector<Core::Id> TestFrameworkManager::activeFrameworkIds() const
|
2016-06-01 16:22:50 +02:00
|
|
|
{
|
2016-06-06 15:35:00 +02:00
|
|
|
QVector<Core::Id> active;
|
|
|
|
|
FrameworkIterator it = m_registeredFrameworks.begin();
|
|
|
|
|
FrameworkIterator end = m_registeredFrameworks.end();
|
|
|
|
|
for ( ; it != end; ++it) {
|
|
|
|
|
if (it.value()->active())
|
|
|
|
|
active.append(it.key());
|
|
|
|
|
}
|
|
|
|
|
return active;
|
|
|
|
|
}
|
2016-06-01 16:22:50 +02:00
|
|
|
|
2016-06-06 15:35:00 +02:00
|
|
|
QVector<Core::Id> TestFrameworkManager::sortedActiveFrameworkIds() const
|
|
|
|
|
{
|
|
|
|
|
QVector<Core::Id> active = activeFrameworkIds();
|
|
|
|
|
Utils::sort(active, [this] (const Core::Id &lhs, const Core::Id &rhs) {
|
2016-06-01 16:22:50 +02:00
|
|
|
return m_registeredFrameworks[lhs]->priority() < m_registeredFrameworks[rhs]->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
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TestTreeItem *TestFrameworkManager::rootNodeForTestFramework(const Core::Id &frameworkId) const
|
|
|
|
|
{
|
2017-02-13 10:05:06 +01:00
|
|
|
ITestFramework *framework = m_registeredFrameworks.value(frameworkId, nullptr);
|
|
|
|
|
return framework ? framework->rootNode() : nullptr;
|
2016-06-01 16:22:50 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ITestParser *TestFrameworkManager::testParserForTestFramework(const Core::Id &frameworkId) const
|
|
|
|
|
{
|
2017-02-13 10:05:06 +01:00
|
|
|
ITestFramework *framework = m_registeredFrameworks.value(frameworkId, nullptr);
|
2016-06-01 16:22:50 +02:00
|
|
|
if (!framework)
|
2017-02-13 10:05:06 +01:00
|
|
|
return nullptr;
|
2016-06-01 16:22:50 +02:00
|
|
|
ITestParser *testParser = framework->testParser();
|
|
|
|
|
qCDebug(LOG) << "Setting" << frameworkId << "as Id for test parser";
|
|
|
|
|
testParser->setId(frameworkId);
|
|
|
|
|
return testParser;
|
|
|
|
|
}
|
|
|
|
|
|
2016-10-05 12:39:23 +02:00
|
|
|
QSharedPointer<IFrameworkSettings> TestFrameworkManager::settingsForTestFramework(
|
|
|
|
|
const Core::Id &frameworkId) const
|
|
|
|
|
{
|
|
|
|
|
return m_frameworkSettings.contains(frameworkId) ? m_frameworkSettings.value(frameworkId)
|
|
|
|
|
: QSharedPointer<IFrameworkSettings>();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void TestFrameworkManager::synchronizeSettings(QSettings *s)
|
|
|
|
|
{
|
|
|
|
|
AutotestPlugin::instance()->settings()->fromSettings(s);
|
|
|
|
|
for (const Core::Id &id : m_frameworkSettings.keys()) {
|
|
|
|
|
QSharedPointer<IFrameworkSettings> fSettings = settingsForTestFramework(id);
|
|
|
|
|
if (!fSettings.isNull())
|
|
|
|
|
fSettings->fromSettings(s);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-06-06 15:35:00 +02:00
|
|
|
bool TestFrameworkManager::isActive(const Core::Id &frameworkId) const
|
|
|
|
|
{
|
|
|
|
|
ITestFramework *framework = m_registeredFrameworks.value(frameworkId);
|
|
|
|
|
return framework ? framework->active() : false;
|
|
|
|
|
}
|
|
|
|
|
|
2016-06-08 12:56:25 +02:00
|
|
|
bool TestFrameworkManager::hasActiveFrameworks() const
|
|
|
|
|
{
|
|
|
|
|
for (ITestFramework *framework : m_registeredFrameworks.values()) {
|
|
|
|
|
if (framework->active())
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2016-06-01 16:22:50 +02:00
|
|
|
} // namespace Internal
|
|
|
|
|
} // namespace Autotest
|