2014-10-07 12:30:54 +02:00
|
|
|
/****************************************************************************
|
|
|
|
|
**
|
2016-01-22 10:37:55 +01:00
|
|
|
** Copyright (C) 2016 The Qt Company Ltd.
|
|
|
|
|
** Contact: https://www.qt.io/licensing/
|
2014-10-07 12:30:54 +02:00
|
|
|
**
|
2016-01-22 10:37:55 +01:00
|
|
|
** This file is part of Qt Creator.
|
2014-10-07 12:30:54 +02:00
|
|
|
**
|
2016-01-22 10:37:55 +01:00
|
|
|
** Commercial License Usage
|
|
|
|
|
** Licensees holding valid commercial Qt licenses may use this file in
|
|
|
|
|
** accordance with the commercial license agreement provided with the
|
2014-10-07 12:30:54 +02:00
|
|
|
** Software or, alternatively, in accordance with the terms contained in
|
2016-01-22 10:37:55 +01:00
|
|
|
** 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.
|
2014-10-07 12:30:54 +02:00
|
|
|
**
|
2016-01-22 10:37:55 +01:00
|
|
|
** 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.
|
2014-10-07 12:30:54 +02:00
|
|
|
**
|
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
|
|
#include "autotestplugin.h"
|
|
|
|
|
#include "autotestconstants.h"
|
2015-02-16 13:17:53 +01:00
|
|
|
#include "testcodeparser.h"
|
2016-06-01 16:22:50 +02:00
|
|
|
#include "testframeworkmanager.h"
|
2014-10-07 15:51:02 +02:00
|
|
|
#include "testrunner.h"
|
2014-12-04 14:05:19 +01:00
|
|
|
#include "testsettings.h"
|
|
|
|
|
#include "testsettingspage.h"
|
2015-02-13 15:44:18 +01:00
|
|
|
#include "testtreeitem.h"
|
2014-10-07 12:30:54 +02:00
|
|
|
#include "testtreeview.h"
|
|
|
|
|
#include "testtreemodel.h"
|
2014-10-07 15:51:02 +02:00
|
|
|
#include "testresultspane.h"
|
2014-12-18 15:02:07 +01:00
|
|
|
#include "testnavigationwidget.h"
|
2014-10-07 12:30:54 +02:00
|
|
|
|
2016-06-01 16:22:50 +02:00
|
|
|
#include "qtest/qttestframework.h"
|
|
|
|
|
#include "quick/quicktestframework.h"
|
|
|
|
|
#include "gtest/gtestframework.h"
|
|
|
|
|
|
2014-10-07 12:30:54 +02:00
|
|
|
#include <coreplugin/icore.h>
|
|
|
|
|
#include <coreplugin/icontext.h>
|
|
|
|
|
#include <coreplugin/actionmanager/actionmanager.h>
|
|
|
|
|
#include <coreplugin/actionmanager/command.h>
|
|
|
|
|
#include <coreplugin/actionmanager/actioncontainer.h>
|
|
|
|
|
#include <coreplugin/coreconstants.h>
|
|
|
|
|
|
2014-10-28 13:02:34 +01:00
|
|
|
#include <extensionsystem/pluginmanager.h>
|
|
|
|
|
|
2014-10-07 12:30:54 +02:00
|
|
|
#include <QAction>
|
|
|
|
|
#include <QMessageBox>
|
|
|
|
|
#include <QMainWindow>
|
|
|
|
|
#include <QMenu>
|
|
|
|
|
|
|
|
|
|
#include <QtPlugin>
|
|
|
|
|
|
2015-02-10 14:20:43 +01:00
|
|
|
#ifdef WITH_TESTS
|
|
|
|
|
#include "autotestunittests.h"
|
|
|
|
|
#endif
|
|
|
|
|
|
2014-10-07 12:30:54 +02:00
|
|
|
using namespace Autotest::Internal;
|
2015-03-30 07:47:07 +02:00
|
|
|
using namespace Core;
|
2014-10-07 12:30:54 +02:00
|
|
|
|
2014-12-04 14:05:19 +01:00
|
|
|
static AutotestPlugin *m_instance = 0;
|
|
|
|
|
|
2014-10-07 12:30:54 +02:00
|
|
|
AutotestPlugin::AutotestPlugin()
|
2014-12-04 14:05:19 +01:00
|
|
|
: m_settings(new TestSettings)
|
2014-10-07 12:30:54 +02:00
|
|
|
{
|
2015-01-08 12:51:01 +01:00
|
|
|
// needed to be used in QueuedConnection connects
|
|
|
|
|
qRegisterMetaType<TestResult>();
|
2015-09-07 14:44:45 +02:00
|
|
|
qRegisterMetaType<TestTreeItem *>();
|
2015-02-13 15:44:18 +01:00
|
|
|
qRegisterMetaType<TestCodeLocationAndType>();
|
|
|
|
|
|
2014-12-04 14:05:19 +01:00
|
|
|
m_instance = this;
|
2014-10-07 12:30:54 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
AutotestPlugin::~AutotestPlugin()
|
|
|
|
|
{
|
2016-06-01 16:22:50 +02:00
|
|
|
delete m_frameworkManager;
|
2014-10-07 12:30:54 +02:00
|
|
|
}
|
|
|
|
|
|
2014-12-04 14:05:19 +01:00
|
|
|
AutotestPlugin *AutotestPlugin::instance()
|
|
|
|
|
{
|
|
|
|
|
return m_instance;
|
|
|
|
|
}
|
|
|
|
|
|
2015-01-06 15:24:31 +01:00
|
|
|
QSharedPointer<TestSettings> AutotestPlugin::settings() const
|
|
|
|
|
{
|
|
|
|
|
return m_settings;
|
|
|
|
|
}
|
|
|
|
|
|
2014-12-19 11:25:05 +01:00
|
|
|
void AutotestPlugin::initializeMenuEntries()
|
|
|
|
|
{
|
2015-03-30 07:47:07 +02:00
|
|
|
ActionContainer *menu = ActionManager::createMenu(Constants::MENU_ID);
|
2016-01-24 09:03:45 +02:00
|
|
|
menu->menu()->setTitle(tr("&Tests"));
|
2015-03-30 07:47:07 +02:00
|
|
|
|
|
|
|
|
QAction *action = new QAction(tr("Run &All Tests"), this);
|
|
|
|
|
Command *command = ActionManager::registerAction(action, Constants::ACTION_RUN_ALL_ID);
|
|
|
|
|
command->setDefaultKeySequence(QKeySequence(tr("Alt+Shift+T,Alt+A")));
|
|
|
|
|
connect(action, &QAction::triggered,
|
|
|
|
|
this, &AutotestPlugin::onRunAllTriggered);
|
|
|
|
|
menu->addAction(command);
|
|
|
|
|
|
|
|
|
|
action = new QAction(tr("&Run Selected Tests"), this);
|
|
|
|
|
command = ActionManager::registerAction(action, Constants::ACTION_RUN_SELECTED_ID);
|
|
|
|
|
command->setDefaultKeySequence(QKeySequence(tr("Alt+Shift+T,Alt+R")));
|
|
|
|
|
connect(action, &QAction::triggered,
|
|
|
|
|
this, &AutotestPlugin::onRunSelectedTriggered);
|
|
|
|
|
menu->addAction(command);
|
|
|
|
|
|
|
|
|
|
action = new QAction(tr("Re&scan Tests"), this);
|
|
|
|
|
command = ActionManager::registerAction(action, Constants::ACTION_SCAN_ID);
|
2015-02-16 13:17:53 +01:00
|
|
|
command->setDefaultKeySequence(QKeySequence(tr("Alt+Shift+T,Alt+S")));
|
|
|
|
|
connect(action, &QAction::triggered,
|
|
|
|
|
TestTreeModel::instance()->parser(), &TestCodeParser::updateTestTree);
|
2014-12-19 11:25:05 +01:00
|
|
|
menu->addAction(command);
|
2015-03-30 07:47:07 +02:00
|
|
|
|
2015-04-14 15:24:31 +02:00
|
|
|
ActionContainer *toolsMenu = ActionManager::actionContainer(Core::Constants::M_TOOLS);
|
|
|
|
|
toolsMenu->addMenu(menu);
|
|
|
|
|
connect(toolsMenu->menu(), &QMenu::aboutToShow,
|
|
|
|
|
this, &AutotestPlugin::updateMenuItemsEnabledState);
|
2014-12-19 11:25:05 +01:00
|
|
|
}
|
|
|
|
|
|
2014-10-07 12:30:54 +02:00
|
|
|
bool AutotestPlugin::initialize(const QStringList &arguments, QString *errorString)
|
|
|
|
|
{
|
|
|
|
|
Q_UNUSED(arguments)
|
|
|
|
|
Q_UNUSED(errorString)
|
|
|
|
|
|
2014-12-19 11:25:05 +01:00
|
|
|
initializeMenuEntries();
|
2014-10-07 12:30:54 +02:00
|
|
|
|
2016-06-01 16:22:50 +02:00
|
|
|
m_frameworkManager = TestFrameworkManager::instance();
|
|
|
|
|
m_frameworkManager->registerTestFramework(new QtTestFramework);
|
|
|
|
|
m_frameworkManager->registerTestFramework(new QuickTestFramework);
|
|
|
|
|
m_frameworkManager->registerTestFramework(new GTestFramework);
|
|
|
|
|
|
2015-03-30 07:47:07 +02:00
|
|
|
m_settings->fromSettings(ICore::settings());
|
2014-12-18 17:39:27 +01:00
|
|
|
addAutoReleasedObject(new TestSettingsPage(m_settings));
|
2014-12-18 15:02:07 +01:00
|
|
|
addAutoReleasedObject(new TestNavigationWidgetFactory);
|
2014-10-07 15:51:02 +02:00
|
|
|
addAutoReleasedObject(TestResultsPane::instance());
|
2014-10-07 12:30:54 +02:00
|
|
|
|
2016-02-01 15:12:10 +01:00
|
|
|
if (m_settings->alwaysParse)
|
|
|
|
|
TestTreeModel::instance()->enableParsingFromSettings();
|
2016-06-06 15:35:00 +02:00
|
|
|
m_frameworkManager->activateFrameworksFromSettings(m_settings);
|
|
|
|
|
TestTreeModel::instance()->syncTestFrameworks();
|
2016-02-01 15:12:10 +01:00
|
|
|
|
2014-10-07 12:30:54 +02:00
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void AutotestPlugin::extensionsInitialized()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ExtensionSystem::IPlugin::ShutdownFlag AutotestPlugin::aboutToShutdown()
|
|
|
|
|
{
|
|
|
|
|
return SynchronousShutdown;
|
|
|
|
|
}
|
|
|
|
|
|
2015-03-30 07:47:07 +02:00
|
|
|
void AutotestPlugin::onRunAllTriggered()
|
|
|
|
|
{
|
|
|
|
|
TestRunner *runner = TestRunner::instance();
|
|
|
|
|
TestTreeModel *model = TestTreeModel::instance();
|
|
|
|
|
runner->setSelectedTests(model->getAllTestCases());
|
2016-06-15 12:29:24 +02:00
|
|
|
runner->prepareToRunTests(TestRunner::Run);
|
2015-03-30 07:47:07 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void AutotestPlugin::onRunSelectedTriggered()
|
|
|
|
|
{
|
|
|
|
|
TestRunner *runner = TestRunner::instance();
|
|
|
|
|
TestTreeModel *model = TestTreeModel::instance();
|
|
|
|
|
runner->setSelectedTests(model->getSelectedTests());
|
2016-06-15 12:29:24 +02:00
|
|
|
runner->prepareToRunTests(TestRunner::Run);
|
2015-03-30 07:47:07 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void AutotestPlugin::updateMenuItemsEnabledState()
|
|
|
|
|
{
|
2015-04-14 15:24:31 +02:00
|
|
|
const bool enabled = !TestRunner::instance()->isTestRunning()
|
|
|
|
|
&& TestTreeModel::instance()->parser()->state() == TestCodeParser::Idle;
|
2015-03-30 07:47:07 +02:00
|
|
|
const bool hasTests = TestTreeModel::instance()->hasTests();
|
|
|
|
|
|
|
|
|
|
ActionManager::command(Constants::ACTION_RUN_ALL_ID)->action()->setEnabled(enabled && hasTests);
|
|
|
|
|
ActionManager::command(Constants::ACTION_RUN_SELECTED_ID)->action()->setEnabled(enabled && hasTests);
|
|
|
|
|
ActionManager::command(Constants::ACTION_SCAN_ID)->action()->setEnabled(enabled);
|
|
|
|
|
}
|
|
|
|
|
|
2015-02-10 14:20:43 +01:00
|
|
|
QList<QObject *> AutotestPlugin::createTestObjects() const
|
|
|
|
|
{
|
|
|
|
|
QList<QObject *> tests;
|
|
|
|
|
#ifdef WITH_TESTS
|
|
|
|
|
tests << new AutoTestUnitTests(TestTreeModel::instance());
|
|
|
|
|
#endif
|
|
|
|
|
return tests;
|
|
|
|
|
}
|