2014-10-07 15:51:02 +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 15:51:02 +02:00
|
|
|
**
|
2016-01-22 10:37:55 +01:00
|
|
|
** This file is part of Qt Creator.
|
2014-10-07 15:51:02 +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 15:51:02 +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 15:51:02 +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 15:51:02 +02:00
|
|
|
**
|
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
|
|
#include "testconfiguration.h"
|
|
|
|
|
|
2015-04-27 16:11:28 +02:00
|
|
|
#include <cpptools/cppmodelmanager.h>
|
2016-01-13 12:14:43 +01:00
|
|
|
#include <cpptools/projectinfo.h>
|
2015-04-27 16:11:28 +02:00
|
|
|
|
|
|
|
|
#include <projectexplorer/buildtargetinfo.h>
|
|
|
|
|
#include <projectexplorer/environmentaspect.h>
|
2016-01-25 15:00:20 +01:00
|
|
|
#include <projectexplorer/kitinformation.h>
|
2014-10-07 15:51:02 +02:00
|
|
|
#include <projectexplorer/project.h>
|
2016-01-25 15:00:20 +01:00
|
|
|
#include <projectexplorer/runnables.h>
|
2015-04-27 16:11:28 +02:00
|
|
|
#include <projectexplorer/runconfiguration.h>
|
|
|
|
|
#include <projectexplorer/session.h>
|
|
|
|
|
#include <projectexplorer/target.h>
|
|
|
|
|
|
|
|
|
|
using namespace ProjectExplorer;
|
2014-10-07 15:51:02 +02:00
|
|
|
|
|
|
|
|
namespace Autotest {
|
|
|
|
|
namespace Internal {
|
|
|
|
|
|
|
|
|
|
TestConfiguration::TestConfiguration(const QString &testClass, const QStringList &testCases,
|
2014-11-03 08:30:22 +01:00
|
|
|
int testCaseCount, QObject *parent)
|
2014-10-07 15:51:02 +02:00
|
|
|
: QObject(parent),
|
|
|
|
|
m_testClass(testClass),
|
|
|
|
|
m_testCases(testCases),
|
2014-11-03 08:30:22 +01:00
|
|
|
m_testCaseCount(testCaseCount),
|
2015-01-07 09:33:57 +01:00
|
|
|
m_unnamedOnly(false),
|
2015-02-17 10:33:35 +01:00
|
|
|
m_project(0),
|
2015-12-09 09:46:33 +01:00
|
|
|
m_guessedConfiguration(false),
|
2016-01-12 13:52:21 +01:00
|
|
|
m_type(TestTypeQt)
|
2014-10-07 15:51:02 +02:00
|
|
|
{
|
2015-04-27 16:11:28 +02:00
|
|
|
if (testCases.size() != 0)
|
2014-11-03 08:30:22 +01:00
|
|
|
m_testCaseCount = testCases.size();
|
2014-10-07 15:51:02 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TestConfiguration::~TestConfiguration()
|
|
|
|
|
{
|
|
|
|
|
m_testCases.clear();
|
|
|
|
|
}
|
|
|
|
|
|
2015-04-27 16:11:28 +02:00
|
|
|
void basicProjectInformation(Project *project, const QString &mainFilePath, QString *proFile,
|
|
|
|
|
QString *displayName, Project **targetProject)
|
|
|
|
|
{
|
|
|
|
|
CppTools::CppModelManager *cppMM = CppTools::CppModelManager::instance();
|
|
|
|
|
QList<CppTools::ProjectPart::Ptr> projParts = cppMM->projectInfo(project).projectParts();
|
|
|
|
|
|
|
|
|
|
foreach (const CppTools::ProjectPart::Ptr &part, projParts) {
|
|
|
|
|
foreach (const CppTools::ProjectFile currentFile, part->files) {
|
|
|
|
|
if (currentFile.path == mainFilePath) {
|
|
|
|
|
*proFile = part->projectFile;
|
|
|
|
|
*displayName = part->displayName;
|
|
|
|
|
*targetProject = part->project;
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2015-12-09 09:46:33 +01:00
|
|
|
void basicProjectInformation(Project *project, const QString &proFile, QString *displayName,
|
|
|
|
|
Project **targetProject)
|
|
|
|
|
{
|
|
|
|
|
CppTools::CppModelManager *cppMM = CppTools::CppModelManager::instance();
|
|
|
|
|
QList<CppTools::ProjectPart::Ptr> projParts = cppMM->projectInfo(project).projectParts();
|
|
|
|
|
|
|
|
|
|
foreach (const CppTools::ProjectPart::Ptr &part, projParts) {
|
|
|
|
|
if (part->projectFile == proFile) {
|
|
|
|
|
*displayName = part->displayName;
|
|
|
|
|
*targetProject = part->project;
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-01-25 15:00:20 +01:00
|
|
|
static bool isLocal(RunConfiguration *runConfiguration)
|
2015-04-27 16:11:28 +02:00
|
|
|
{
|
2016-01-25 15:00:20 +01:00
|
|
|
Target *target = runConfiguration ? runConfiguration->target() : 0;
|
|
|
|
|
Kit *kit = target ? target->kit() : 0;
|
|
|
|
|
return DeviceTypeKitInformation::deviceTypeId(kit) == ProjectExplorer::Constants::DESKTOP_DEVICE_TYPE;
|
2015-04-27 16:11:28 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void TestConfiguration::completeTestInformation()
|
|
|
|
|
{
|
2015-12-09 09:46:33 +01:00
|
|
|
QTC_ASSERT(!m_mainFilePath.isEmpty() || !m_proFile.isEmpty(), return);
|
2015-04-27 16:11:28 +02:00
|
|
|
|
|
|
|
|
Project *project = SessionManager::startupProject();
|
|
|
|
|
if (!project)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
QString targetFile;
|
|
|
|
|
QString targetName;
|
|
|
|
|
QString workDir;
|
2015-12-09 09:46:33 +01:00
|
|
|
QString proFile = m_proFile;
|
2015-04-27 16:11:28 +02:00
|
|
|
QString displayName;
|
|
|
|
|
Project *targetProject = 0;
|
|
|
|
|
Utils::Environment env;
|
|
|
|
|
bool hasDesktopTarget = false;
|
|
|
|
|
bool guessedRunConfiguration = false;
|
|
|
|
|
setProject(0);
|
|
|
|
|
|
2015-12-09 09:46:33 +01:00
|
|
|
if (m_proFile.isEmpty())
|
|
|
|
|
basicProjectInformation(project, m_mainFilePath, &proFile, &displayName, &targetProject);
|
|
|
|
|
else
|
|
|
|
|
basicProjectInformation(project, proFile, &displayName, &targetProject);
|
2015-04-27 16:11:28 +02:00
|
|
|
|
|
|
|
|
Target *target = project->activeTarget();
|
|
|
|
|
if (!target)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
BuildTargetInfoList appTargets = target->applicationTargets();
|
|
|
|
|
foreach (const BuildTargetInfo &bti, appTargets.list) {
|
|
|
|
|
// some project manager store line/column information as well inside ProjectPart
|
|
|
|
|
if (bti.isValid() && proFile.startsWith(bti.projectFilePath.toString())) {
|
|
|
|
|
targetFile = Utils::HostOsInfo::withExecutableSuffix(bti.targetFilePath.toString());
|
|
|
|
|
targetName = bti.targetName;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QList<RunConfiguration *> rcs = target->runConfigurations();
|
|
|
|
|
foreach (RunConfiguration *rc, rcs) {
|
2016-01-25 15:00:20 +01:00
|
|
|
Runnable runnable = rc->runnable();
|
|
|
|
|
if (isLocal(rc) && runnable.is<StandardRunnable>()) {
|
|
|
|
|
StandardRunnable stdRunnable = runnable.as<StandardRunnable>();
|
|
|
|
|
if (stdRunnable.executable == targetFile) {
|
|
|
|
|
workDir = Utils::FileUtils::normalizePathName(stdRunnable.workingDirectory);
|
|
|
|
|
env = stdRunnable.environment;
|
|
|
|
|
hasDesktopTarget = true;
|
|
|
|
|
break;
|
|
|
|
|
}
|
2015-04-27 16:11:28 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// if we could not figure out the run configuration
|
|
|
|
|
// try to use the run configuration of the parent project
|
|
|
|
|
if (!hasDesktopTarget && targetProject && !targetFile.isEmpty()) {
|
2016-01-25 15:00:20 +01:00
|
|
|
if (auto rc = target->activeRunConfiguration()) {
|
|
|
|
|
Runnable runnable = rc->runnable();
|
|
|
|
|
if (isLocal(rc) && runnable.is<StandardRunnable>()) {
|
|
|
|
|
StandardRunnable stdRunnable = runnable.as<StandardRunnable>();
|
|
|
|
|
workDir = Utils::FileUtils::normalizePathName(stdRunnable.workingDirectory);
|
|
|
|
|
env = stdRunnable.environment;
|
|
|
|
|
hasDesktopTarget = true;
|
|
|
|
|
guessedRunConfiguration = true;
|
|
|
|
|
}
|
2015-04-27 16:11:28 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
setProFile(proFile);
|
|
|
|
|
setDisplayName(displayName);
|
|
|
|
|
|
|
|
|
|
if (hasDesktopTarget) {
|
|
|
|
|
setTargetFile(targetFile);
|
|
|
|
|
setTargetName(targetName);
|
|
|
|
|
setWorkingDirectory(workDir);
|
|
|
|
|
setEnvironment(env);
|
|
|
|
|
setProject(project);
|
|
|
|
|
setGuessedConfiguration(guessedRunConfiguration);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2014-11-06 16:01:06 +01:00
|
|
|
/**
|
|
|
|
|
* @brief sets the test cases for this test configuration.
|
|
|
|
|
*
|
|
|
|
|
* Watch out for special handling of test configurations, because this method also
|
|
|
|
|
* updates the test case count to the current size of \a testCases.
|
|
|
|
|
*
|
|
|
|
|
* @param testCases list of names of the test functions / test cases
|
|
|
|
|
*/
|
|
|
|
|
void TestConfiguration::setTestCases(const QStringList &testCases)
|
|
|
|
|
{
|
|
|
|
|
m_testCases.clear();
|
|
|
|
|
m_testCases << testCases;
|
|
|
|
|
m_testCaseCount = m_testCases.size();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void TestConfiguration::setTestCaseCount(int count)
|
|
|
|
|
{
|
|
|
|
|
m_testCaseCount = count;
|
|
|
|
|
}
|
|
|
|
|
|
2015-04-27 16:11:28 +02:00
|
|
|
void TestConfiguration::setMainFilePath(const QString &mainFile)
|
|
|
|
|
{
|
|
|
|
|
m_mainFilePath = mainFile;
|
|
|
|
|
}
|
|
|
|
|
|
2014-10-07 15:51:02 +02:00
|
|
|
void TestConfiguration::setTargetFile(const QString &targetFile)
|
|
|
|
|
{
|
|
|
|
|
m_targetFile = targetFile;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void TestConfiguration::setTargetName(const QString &targetName)
|
|
|
|
|
{
|
|
|
|
|
m_targetName = targetName;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void TestConfiguration::setProFile(const QString &proFile)
|
|
|
|
|
{
|
|
|
|
|
m_proFile = proFile;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void TestConfiguration::setWorkingDirectory(const QString &workingDirectory)
|
|
|
|
|
{
|
|
|
|
|
m_workingDir = workingDirectory;
|
|
|
|
|
}
|
|
|
|
|
|
2014-11-13 12:31:58 +01:00
|
|
|
void TestConfiguration::setDisplayName(const QString &displayName)
|
|
|
|
|
{
|
|
|
|
|
m_displayName = displayName;
|
|
|
|
|
}
|
|
|
|
|
|
2014-10-07 15:51:02 +02:00
|
|
|
void TestConfiguration::setEnvironment(const Utils::Environment &env)
|
|
|
|
|
{
|
|
|
|
|
m_environment = env;
|
|
|
|
|
}
|
|
|
|
|
|
2015-04-27 16:11:28 +02:00
|
|
|
void TestConfiguration::setProject(Project *project)
|
2014-10-07 15:51:02 +02:00
|
|
|
{
|
|
|
|
|
m_project = project;
|
|
|
|
|
}
|
|
|
|
|
|
2015-01-07 09:33:57 +01:00
|
|
|
void TestConfiguration::setUnnamedOnly(bool unnamedOnly)
|
|
|
|
|
{
|
|
|
|
|
m_unnamedOnly = unnamedOnly;
|
|
|
|
|
}
|
|
|
|
|
|
2015-02-17 10:33:35 +01:00
|
|
|
void TestConfiguration::setGuessedConfiguration(bool guessed)
|
|
|
|
|
{
|
|
|
|
|
m_guessedConfiguration = guessed;
|
|
|
|
|
}
|
|
|
|
|
|
2015-12-09 09:46:33 +01:00
|
|
|
void TestConfiguration::setTestType(TestType type)
|
|
|
|
|
{
|
|
|
|
|
m_type = type;
|
|
|
|
|
}
|
|
|
|
|
|
2014-10-07 15:51:02 +02:00
|
|
|
} // namespace Internal
|
|
|
|
|
} // namespace Autotest
|