2014-10-07 12:30:54 +02:00
|
|
|
/****************************************************************************
|
|
|
|
|
**
|
2015-02-19 08:09:02 +01:00
|
|
|
** Copyright (C) 2015 The Qt Company Ltd
|
2014-10-07 12:30:54 +02:00
|
|
|
** All rights reserved.
|
2015-02-19 08:09:02 +01:00
|
|
|
** For any questions to The Qt Company, please use contact form at
|
|
|
|
|
** http://www.qt.io/contact-us
|
2014-10-07 12:30:54 +02:00
|
|
|
**
|
|
|
|
|
** This file is part of the Qt Creator Enterprise Auto Test Add-on.
|
|
|
|
|
**
|
|
|
|
|
** Licensees holding valid Qt Enterprise licenses may use this file in
|
|
|
|
|
** accordance with the Qt Enterprise License Agreement provided with the
|
|
|
|
|
** Software or, alternatively, in accordance with the terms contained in
|
2015-02-19 08:09:02 +01:00
|
|
|
** a written agreement between you and The Qt Company.
|
2014-10-07 12:30:54 +02:00
|
|
|
**
|
|
|
|
|
** If you have questions regarding the use of this file, please use
|
2015-02-19 08:09:02 +01:00
|
|
|
** contact form at http://www.qt.io/contact-us
|
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"
|
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
|
|
|
|
|
|
|
|
#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>
|
|
|
|
|
|
|
|
|
|
#include <licensechecker/licensecheckerplugin.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-02-13 15:44:18 +01:00
|
|
|
qRegisterMetaType<TestTreeItem>();
|
|
|
|
|
qRegisterMetaType<TestCodeLocationAndType>();
|
|
|
|
|
qRegisterMetaType<TestTreeModel::Type>();
|
|
|
|
|
|
2014-12-04 14:05:19 +01:00
|
|
|
m_instance = this;
|
2014-10-07 12:30:54 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
AutotestPlugin::~AutotestPlugin()
|
|
|
|
|
{
|
|
|
|
|
// Delete members
|
|
|
|
|
TestTreeModel *model = TestTreeModel::instance();
|
|
|
|
|
delete model;
|
2014-10-07 15:51:02 +02:00
|
|
|
TestRunner *runner = TestRunner::instance();
|
|
|
|
|
delete runner;
|
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-18 17:35:25 +01:00
|
|
|
bool AutotestPlugin::checkLicense()
|
|
|
|
|
{
|
|
|
|
|
LicenseChecker::LicenseCheckerPlugin *licenseChecker
|
|
|
|
|
= ExtensionSystem::PluginManager::getObject<LicenseChecker::LicenseCheckerPlugin>();
|
|
|
|
|
|
|
|
|
|
if (!licenseChecker || !licenseChecker->hasValidLicense()) {
|
|
|
|
|
qWarning() << "Invalid license, disabling Qt Creator Enterprise Auto Test Add-on.";
|
|
|
|
|
return false;
|
|
|
|
|
} else if (!licenseChecker->enterpriseFeatures())
|
|
|
|
|
return false;
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
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);
|
|
|
|
|
menu->menu()->setTitle(tr("Tests"));
|
|
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
|
ActionManager::actionContainer(Core::Constants::M_TOOLS)->addMenu(menu);
|
|
|
|
|
connect(menu->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-18 17:35:25 +01:00
|
|
|
if (!checkLicense())
|
2014-10-28 13:02:34 +01:00
|
|
|
return true;
|
|
|
|
|
|
2014-12-19 11:25:05 +01:00
|
|
|
initializeMenuEntries();
|
2014-10-07 12:30:54 +02:00
|
|
|
|
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
|
|
|
|
|
|
|
|
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());
|
|
|
|
|
runner->runTests();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void AutotestPlugin::onRunSelectedTriggered()
|
|
|
|
|
{
|
|
|
|
|
TestRunner *runner = TestRunner::instance();
|
|
|
|
|
TestTreeModel *model = TestTreeModel::instance();
|
|
|
|
|
runner->setSelectedTests(model->getSelectedTests());
|
|
|
|
|
runner->runTests();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void AutotestPlugin::updateMenuItemsEnabledState()
|
|
|
|
|
{
|
|
|
|
|
const bool enabled = !TestRunner::instance()->isTestRunning();
|
|
|
|
|
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;
|
|
|
|
|
}
|