diff options
author | Eike Ziller <eike.ziller@theqtcompany.com> | 2015-07-01 14:13:22 +0200 |
---|---|---|
committer | Eike Ziller <eike.ziller@theqtcompany.com> | 2015-07-01 14:14:15 +0200 |
commit | 47fb89e41484b89697473ff444d0f48e307fe205 (patch) | |
tree | 96073b21b92f778939fd277a92660692cbf6b1c7 | |
parent | 0afd504748f49ae6c6d77403fd1d6f6604b6eaa8 (diff) | |
parent | c7a8a941618a5eb1bfc99c416c5adaa181b472f6 (diff) |
Merge remote-tracking branch 'origin/3.5'
Change-Id: If5eacbdd8f9cd07b7be028c3b04256e9d5368b83
-rw-r--r-- | plugins/autotest/autotest.pro | 1 | ||||
-rw-r--r-- | plugins/autotest/autotest.qbs | 3 | ||||
-rw-r--r-- | plugins/autotest/autotest_dependencies.pri | 5 | ||||
-rw-r--r-- | plugins/autotest/autotestplugin.cpp | 6 | ||||
-rw-r--r-- | plugins/autotest/testconfiguration.cpp | 117 | ||||
-rw-r--r-- | plugins/autotest/testconfiguration.h | 8 | ||||
-rw-r--r-- | plugins/autotest/testnavigationwidget.cpp | 44 | ||||
-rw-r--r-- | plugins/autotest/testnavigationwidget.h | 1 | ||||
-rw-r--r-- | plugins/autotest/testresultdelegate.cpp | 2 | ||||
-rw-r--r-- | plugins/autotest/testrunner.cpp | 32 | ||||
-rw-r--r-- | plugins/autotest/testtreemodel.cpp | 182 | ||||
-rw-r--r-- | plugins/autotest/testtreemodel.h | 4 |
12 files changed, 265 insertions, 140 deletions
diff --git a/plugins/autotest/autotest.pro b/plugins/autotest/autotest.pro index 4d3c6643f2..4022cb4399 100644 --- a/plugins/autotest/autotest.pro +++ b/plugins/autotest/autotest.pro @@ -7,6 +7,7 @@ include(../../qtcreatorplugin.pri) include(autotest_dependencies.pri) DEFINES += AUTOTEST_LIBRARY +CONFIG(licensechecker): DEFINES += LICENSECHECKER SOURCES += \ testtreeview.cpp \ diff --git a/plugins/autotest/autotest.qbs b/plugins/autotest/autotest.qbs index 93505bce3b..4a9ec9e4c8 100644 --- a/plugins/autotest/autotest.qbs +++ b/plugins/autotest/autotest.qbs @@ -1,12 +1,11 @@ import qbs -QtcPlugin { +QtcCommercialPlugin { name: "AutoTest" Depends { name: "Core" } Depends { name: "CppTools" } Depends { name: "CPlusPlus" } - Depends { name: "LicenseChecker" } Depends { name: "ProjectExplorer" } Depends { name: "QmakeProjectManager" } Depends { name: "QmlJS" } diff --git a/plugins/autotest/autotest_dependencies.pri b/plugins/autotest/autotest_dependencies.pri index a21b5fce96..74dc51e15b 100644 --- a/plugins/autotest/autotest_dependencies.pri +++ b/plugins/autotest/autotest_dependencies.pri @@ -5,8 +5,9 @@ QTC_PLUGIN_DEPENDS += \ projectexplorer \ cpptools \ qmljstools \ - qmakeprojectmanager \ - licensechecker + qmakeprojectmanager + +CONFIG(licensechecker): QTC_PLUGIN_DEPENDS += licensechecker QTC_LIB_DEPENDS += \ cplusplus \ diff --git a/plugins/autotest/autotestplugin.cpp b/plugins/autotest/autotestplugin.cpp index a2ab783418..525f21ae3e 100644 --- a/plugins/autotest/autotestplugin.cpp +++ b/plugins/autotest/autotestplugin.cpp @@ -38,7 +38,9 @@ #include <extensionsystem/pluginmanager.h> -#include <licensechecker/licensecheckerplugin.h> +#ifdef LICENSECHECKER +# include <licensechecker/licensecheckerplugin.h> +#endif #include <QAction> #include <QMessageBox> @@ -89,6 +91,7 @@ QSharedPointer<TestSettings> AutotestPlugin::settings() const bool AutotestPlugin::checkLicense() { +#ifdef LICENSECHECKER LicenseChecker::LicenseCheckerPlugin *licenseChecker = ExtensionSystem::PluginManager::getObject<LicenseChecker::LicenseCheckerPlugin>(); @@ -97,6 +100,7 @@ bool AutotestPlugin::checkLicense() return false; } else if (!licenseChecker->enterpriseFeatures()) return false; +#endif // LICENSECHECKER return true; } diff --git a/plugins/autotest/testconfiguration.cpp b/plugins/autotest/testconfiguration.cpp index 7c161289ef..4b294f4782 100644 --- a/plugins/autotest/testconfiguration.cpp +++ b/plugins/autotest/testconfiguration.cpp @@ -19,7 +19,17 @@ #include "testconfiguration.h" +#include <cpptools/cppmodelmanager.h> + +#include <projectexplorer/buildtargetinfo.h> +#include <projectexplorer/environmentaspect.h> +#include <projectexplorer/localapplicationrunconfiguration.h> #include <projectexplorer/project.h> +#include <projectexplorer/runconfiguration.h> +#include <projectexplorer/session.h> +#include <projectexplorer/target.h> + +using namespace ProjectExplorer; namespace Autotest { namespace Internal { @@ -34,9 +44,8 @@ TestConfiguration::TestConfiguration(const QString &testClass, const QStringList m_project(0), m_guessedConfiguration(false) { - if (testCases.size() != 0) { + if (testCases.size() != 0) m_testCaseCount = testCases.size(); - } } TestConfiguration::~TestConfiguration() @@ -44,6 +53,103 @@ TestConfiguration::~TestConfiguration() m_testCases.clear(); } +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; + } + } + } +} + +void extractEnvironmentInformation(LocalApplicationRunConfiguration *localRunConfiguration, + QString *workDir, Utils::Environment *env) +{ + *workDir = Utils::FileUtils::normalizePathName(localRunConfiguration->workingDirectory()); + if (auto environmentAspect = localRunConfiguration->extraAspect<EnvironmentAspect>()) + *env = environmentAspect->environment(); +} + +void TestConfiguration::completeTestInformation() +{ + QTC_ASSERT(!m_mainFilePath.isEmpty(), return); + + typedef LocalApplicationRunConfiguration LocalRunConfig; + + Project *project = SessionManager::startupProject(); + if (!project) + return; + + QString targetFile; + QString targetName; + QString workDir; + QString proFile; + QString displayName; + Project *targetProject = 0; + Utils::Environment env; + bool hasDesktopTarget = false; + bool guessedRunConfiguration = false; + setProject(0); + + basicProjectInformation(project, m_mainFilePath, &proFile, &displayName, &targetProject); + + 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) { + auto config = qobject_cast<LocalRunConfig *>(rc); + if (config && config->executable() == targetFile) { + extractEnvironmentInformation(config, &workDir, &env); + hasDesktopTarget = true; + break; + } + } + + // if we could not figure out the run configuration + // try to use the run configuration of the parent project + if (!hasDesktopTarget && targetProject && !targetFile.isEmpty()) { + if (auto config = qobject_cast<LocalRunConfig *>(target->activeRunConfiguration())) { + extractEnvironmentInformation(config, &workDir, &env); + hasDesktopTarget = true; + guessedRunConfiguration = true; + } + } + + setProFile(proFile); + setDisplayName(displayName); + + if (hasDesktopTarget) { + setTargetFile(targetFile); + setTargetName(targetName); + setWorkingDirectory(workDir); + setEnvironment(env); + setProject(project); + setGuessedConfiguration(guessedRunConfiguration); + } +} + + /** * @brief sets the test cases for this test configuration. * @@ -64,6 +170,11 @@ void TestConfiguration::setTestCaseCount(int count) m_testCaseCount = count; } +void TestConfiguration::setMainFilePath(const QString &mainFile) +{ + m_mainFilePath = mainFile; +} + void TestConfiguration::setTargetFile(const QString &targetFile) { m_targetFile = targetFile; @@ -94,7 +205,7 @@ void TestConfiguration::setEnvironment(const Utils::Environment &env) m_environment = env; } -void TestConfiguration::setProject(ProjectExplorer::Project *project) +void TestConfiguration::setProject(Project *project) { m_project = project; } diff --git a/plugins/autotest/testconfiguration.h b/plugins/autotest/testconfiguration.h index aff75d6405..e1d3bc000e 100644 --- a/plugins/autotest/testconfiguration.h +++ b/plugins/autotest/testconfiguration.h @@ -41,8 +41,11 @@ public: int testCaseCount = 0, QObject *parent = 0); ~TestConfiguration(); + void completeTestInformation(); + void setTestCases(const QStringList &testCases); void setTestCaseCount(int count); + void setMainFilePath(const QString &mainFile); void setTargetFile(const QString &targetFile); void setTargetName(const QString &targetName); void setProFile(const QString &proFile); @@ -66,14 +69,11 @@ public: bool unnamedOnly() const { return m_unnamedOnly; } bool guessedConfiguration() const { return m_guessedConfiguration; } -signals: - -public slots: - private: QString m_testClass; QStringList m_testCases; int m_testCaseCount; + QString m_mainFilePath; bool m_unnamedOnly; QString m_proFile; QString m_targetFile; diff --git a/plugins/autotest/testnavigationwidget.cpp b/plugins/autotest/testnavigationwidget.cpp index f9847a5782..da0de8a761 100644 --- a/plugins/autotest/testnavigationwidget.cpp +++ b/plugins/autotest/testnavigationwidget.cpp @@ -89,7 +89,27 @@ void TestNavigationWidget::contextMenuEvent(QContextMenuEvent *event) const bool enabled = !TestRunner::instance()->isTestRunning() && m_model->parser()->state() == TestCodeParser::Idle; const bool hasTests = m_model->hasTests(); + QMenu menu; + QAction *runThisTest = 0; + const QModelIndexList list = m_view->selectionModel()->selectedIndexes(); + if (list.size() == 1) { + const QModelIndex index = list.first(); + QRect rect(m_view->visualRect(index)); + if (rect.contains(event->pos())) { + // do not provide this menu entry for unnamed Quick Tests as it makes no sense + int type = index.data(TypeRole).toInt(); + const QString &unnamed = tr(Constants::UNNAMED_QUICKTESTS); + if ((type == TestTreeItem::TEST_FUNCTION && index.parent().data().toString() != unnamed) + || (type == TestTreeItem::TEST_CLASS && index.data().toString() != unnamed)) { + runThisTest = new QAction(tr("Run This Test"), &menu); + runThisTest->setEnabled(enabled); + connect(runThisTest, &QAction::triggered, + this, &TestNavigationWidget::onRunThisTestTriggered); + } + } + } + QAction *runAll = Core::ActionManager::command(Constants::ACTION_RUN_ALL_ID)->action(); QAction *runSelected = Core::ActionManager::command(Constants::ACTION_RUN_SELECTED_ID)->action(); QAction *selectAll = new QAction(tr("Select All"), &menu); @@ -106,6 +126,10 @@ void TestNavigationWidget::contextMenuEvent(QContextMenuEvent *event) deselectAll->setEnabled(enabled && hasTests); rescan->setEnabled(enabled); + if (runThisTest) { + menu.addAction(runThisTest); + menu.addSeparator(); + } menu.addAction(runAll); menu.addAction(runSelected); menu.addSeparator(); @@ -210,6 +234,26 @@ void TestNavigationWidget::initializeFilterMenu() m_filterMenu->addAction(action); } +void TestNavigationWidget::onRunThisTestTriggered() +{ + const QModelIndexList selected = m_view->selectionModel()->selectedIndexes(); + // paranoia + if (selected.isEmpty()) + return; + const QModelIndex sourceIndex = m_sortFilterModel->mapToSource(selected.first()); + if (!sourceIndex.isValid()) + return; + + TestTreeItem *item = static_cast<TestTreeItem *>(sourceIndex.internalPointer()); + if (item->type() == TestTreeItem::TEST_CLASS || item->type() == TestTreeItem::TEST_FUNCTION) { + if (TestConfiguration *configuration = m_model->getTestConfiguration(item)) { + TestRunner *runner = TestRunner::instance(); + runner->setSelectedTests( {configuration} ); + runner->runTests(); + } + } +} + TestNavigationWidgetFactory::TestNavigationWidgetFactory() { setDisplayName(tr("Tests")); diff --git a/plugins/autotest/testnavigationwidget.h b/plugins/autotest/testnavigationwidget.h index a4b4c6f061..ef28130817 100644 --- a/plugins/autotest/testnavigationwidget.h +++ b/plugins/autotest/testnavigationwidget.h @@ -69,6 +69,7 @@ private slots: private: void initializeFilterMenu(); + void onRunThisTestTriggered(); TestTreeModel *m_model; TestTreeSortFilterModel *m_sortFilterModel; diff --git a/plugins/autotest/testresultdelegate.cpp b/plugins/autotest/testresultdelegate.cpp index c20ce11200..5e37c64955 100644 --- a/plugins/autotest/testresultdelegate.cpp +++ b/plugins/autotest/testresultdelegate.cpp @@ -114,7 +114,7 @@ void TestResultDelegate::paint(QPainter *painter, const QStyleOptionViewItem &op output.append(QString::fromLatin1(" (%1)").arg(testResult.dataTag())); if (!desc.isEmpty()) { int breakPos = desc.indexOf(QLatin1Char('(')); - output.append(QLatin1String(" - ")).append(desc.left(breakPos)); + output.append(QLatin1String(": ")).append(desc.left(breakPos)); if (selected) output.append(QLatin1Char('\n')).append(desc.mid(breakPos)); } diff --git a/plugins/autotest/testrunner.cpp b/plugins/autotest/testrunner.cpp index 07f90a56ad..bc246ed6aa 100644 --- a/plugins/autotest/testrunner.cpp +++ b/plugins/autotest/testrunner.cpp @@ -110,8 +110,16 @@ void performTestRun(QFutureInterface<void> &futureInterface, const QString metricsOption, TestRunner* testRunner) { int testCaseCount = 0; - foreach (const TestConfiguration *config, selectedTests) - testCaseCount += config->testCaseCount(); + foreach (TestConfiguration *config, selectedTests) { + config->completeTestInformation(); + if (config->project()) { + testCaseCount += config->testCaseCount(); + } else { + emitTestResultCreated(FaultyTestResult(Result::MESSAGE_WARN, + QObject::tr("Project is null for \"%1\". Removing from test run.\n" + "Check the test environment.").arg(config->displayName()))); + } + } QProcess testProcess; testProcess.setReadChannelMode(QProcess::MergedChannels); @@ -135,11 +143,16 @@ void performTestRun(QFutureInterface<void> &futureInterface, if (futureInterface.isCanceled()) break; + if (!testConfiguration->project()) + continue; + QProcessEnvironment environment = testConfiguration->environment().toProcessEnvironment(); QString commandFilePath = executableFilePath(testConfiguration->targetFile(), environment); if (commandFilePath.isEmpty()) { emitTestResultCreated(FaultyTestResult(Result::MESSAGE_FATAL, - QObject::tr("Could not find command \"%1\".").arg(testConfiguration->targetFile()))); + QObject::tr("Could not find command \"%1\". (%2)") + .arg(testConfiguration->targetFile()) + .arg(testConfiguration->displayName()))); continue; } @@ -197,26 +210,13 @@ void TestRunner::runTests() // clear old log and output pane TestResultsPane::instance()->clearContents(); - // handle faulty test configurations - QList<TestConfiguration *> toBeRemoved; foreach (TestConfiguration *config, m_selectedTests) { - if (!config->project()) { - toBeRemoved.append(config); - TestResultsPane::instance()->addTestResult(FaultyTestResult(Result::MESSAGE_WARN, - tr("Project is null for \"%1\". Removing from test run.\n" - "Check the test environment." - ).arg(config->displayName()))); - } if (displayRunConfigWarnings && config->guessedConfiguration()) { TestResultsPane::instance()->addTestResult(FaultyTestResult(Result::MESSAGE_WARN, tr("Project's run configuration was guessed for \"%1\".\n" "This might cause trouble during execution.").arg(config->displayName()))); } } - foreach (TestConfiguration *config, toBeRemoved) { - m_selectedTests.removeOne(config); - delete config; - } if (m_selectedTests.empty()) { TestResultsPane::instance()->addTestResult(FaultyTestResult(Result::MESSAGE_WARN, diff --git a/plugins/autotest/testtreemodel.cpp b/plugins/autotest/testtreemodel.cpp index 134a9dc214..4639cbd1e9 100644 --- a/plugins/autotest/testtreemodel.cpp +++ b/plugins/autotest/testtreemodel.cpp @@ -24,21 +24,14 @@ #include <cpptools/cppmodelmanager.h> -#include <projectexplorer/buildtargetinfo.h> -#include <projectexplorer/environmentaspect.h> -#include <projectexplorer/localapplicationrunconfiguration.h> #include <projectexplorer/project.h> -#include <projectexplorer/projectnodes.h> -#include <projectexplorer/runconfiguration.h> #include <projectexplorer/session.h> -#include <projectexplorer/target.h> #include <qmljs/qmljsmodelmanagerinterface.h> #include <texteditor/texteditor.h> -#include <utils/fileutils.h> -#include <utils/hostosinfo.h> +#include <utils/qtcassert.h> #include <QIcon> @@ -262,6 +255,8 @@ QVariant TestTreeModel::data(const QModelIndex &index, int role) const default: return false; } + case TypeRole: + return item->type(); } // TODO ? @@ -347,113 +342,22 @@ bool TestTreeModel::hasTests() const return m_autoTestRootItem->childCount() > 0 || m_quickTestRootItem->childCount() > 0; } -static void addProjectInformation(TestConfiguration *config, const QString &filePath) -{ - const ProjectExplorer::SessionManager *session = ProjectExplorer::SessionManager::instance(); - if (!session || !session->hasProjects()) - return; - - ProjectExplorer::Project *project = session->startupProject(); - if (!project) - return; - - QString targetFile; - QString targetName; - QString workDir; - QString proFile; - QString displayName; - ProjectExplorer::Project *targetProject = 0; - Utils::Environment env; - bool hasDesktopTarget = false; - bool guessedRunConfiguration = false; - CppTools::CppModelManager *cppMM = CppTools::CppModelManager::instance(); - QList<CppTools::ProjectPart::Ptr> projParts = cppMM->projectInfo(project).projectParts(); - - if (!projParts.empty()) { - foreach (const CppTools::ProjectPart::Ptr &part, projParts) { - foreach (const CppTools::ProjectFile currentFile, part->files) { - if (currentFile.path == filePath) { - proFile = part->projectFile; - displayName = part->displayName; - targetProject = part->project; - break; - } - } - if (!proFile.isEmpty()) // maybe better use a goto instead of the break above?? - break; - } - } - - if (project) { - if (auto target = project->activeTarget()) { - ProjectExplorer::BuildTargetInfoList appTargets = target->applicationTargets(); - foreach (const ProjectExplorer::BuildTargetInfo &bti, appTargets.list) { - if (bti.isValid() && bti.projectFilePath.toString() == proFile) { - targetFile = Utils::HostOsInfo::withExecutableSuffix(bti.targetFilePath.toString()); - targetName = bti.targetName; - break; - } - } - - QList<ProjectExplorer::RunConfiguration *> rcs = target->runConfigurations(); - foreach (ProjectExplorer::RunConfiguration *rc, rcs) { - ProjectExplorer::LocalApplicationRunConfiguration *localRunConfiguration - = qobject_cast<ProjectExplorer::LocalApplicationRunConfiguration *>(rc); - if (localRunConfiguration && localRunConfiguration->executable() == targetFile) { - hasDesktopTarget = true; - workDir = Utils::FileUtils::normalizePathName( - localRunConfiguration->workingDirectory()); - ProjectExplorer::EnvironmentAspect *envAsp - = localRunConfiguration->extraAspect<ProjectExplorer::EnvironmentAspect>(); - env = envAsp->environment(); - break; - } - } - - // if we could not figure out the run configuration - // try to use the run configuration of the parent project - if (!hasDesktopTarget && targetProject && !targetFile.isEmpty()) { - auto localRunConfiguration - = qobject_cast<ProjectExplorer::LocalApplicationRunConfiguration *>(target->activeRunConfiguration()); - if (localRunConfiguration) { - hasDesktopTarget = true; - workDir = Utils::FileUtils::normalizePathName( - localRunConfiguration->workingDirectory()); - ProjectExplorer::EnvironmentAspect *environmentAspect - = localRunConfiguration->extraAspect<ProjectExplorer::EnvironmentAspect>(); - env = environmentAspect->environment(); - guessedRunConfiguration = true; - } - } - } - } - - if (hasDesktopTarget) { - config->setTargetFile(targetFile); - config->setTargetName(targetName); - config->setWorkingDirectory(workDir); - config->setProFile(proFile); - config->setEnvironment(env); - config->setProject(project); - config->setDisplayName(displayName); - config->setGuessedConfiguration(guessedRunConfiguration); - } else { - config->setProFile(proFile); - config->setDisplayName(displayName); - } -} - QList<TestConfiguration *> TestTreeModel::getAllTestCases() const { QList<TestConfiguration *> result; + ProjectExplorer::Project *project = ProjectExplorer::SessionManager::startupProject(); + if (!project) + return result; + // get all Auto Tests for (int row = 0, count = m_autoTestRootItem->childCount(); row < count; ++row) { const TestTreeItem *child = m_autoTestRootItem->child(row); TestConfiguration *tc = new TestConfiguration(child->name(), QStringList(), child->childCount()); - addProjectInformation(tc, child->filePath()); + tc->setMainFilePath(child->filePath()); + tc->setProject(project); result << tc; } @@ -481,7 +385,8 @@ QList<TestConfiguration *> TestTreeModel::getAllTestCases() const foreach (const QString &mainFile, foundMains.keys()) { TestConfiguration *tc = new TestConfiguration(QString(), QStringList(), foundMains.value(mainFile)); - addProjectInformation(tc, mainFile); + tc->setMainFilePath(mainFile); + tc->setProject(project); result << tc; } @@ -491,6 +396,10 @@ QList<TestConfiguration *> TestTreeModel::getAllTestCases() const QList<TestConfiguration *> TestTreeModel::getSelectedTests() const { QList<TestConfiguration *> result; + ProjectExplorer::Project *project = ProjectExplorer::SessionManager::startupProject(); + if (!project) + return result; + TestConfiguration *testConfiguration = 0; for (int row = 0, count = m_autoTestRootItem->childCount(); row < count; ++row) { @@ -501,7 +410,8 @@ QList<TestConfiguration *> TestTreeModel::getSelectedTests() const continue; case Qt::Checked: testConfiguration = new TestConfiguration(child->name(), QStringList(), child->childCount()); - addProjectInformation(testConfiguration, child->filePath()); + testConfiguration->setMainFilePath(child->filePath()); + testConfiguration->setProject(project); result << testConfiguration; continue; case Qt::PartiallyChecked: @@ -516,7 +426,8 @@ QList<TestConfiguration *> TestTreeModel::getSelectedTests() const } testConfiguration = new TestConfiguration(childName, testCases); - addProjectInformation(testConfiguration, child->filePath()); + testConfiguration->setMainFilePath(child->filePath()); + testConfiguration->setProject(project); result << testConfiguration; } } @@ -540,7 +451,8 @@ QList<TestConfiguration *> TestTreeModel::getSelectedTests() const testConfiguration = new TestConfiguration(QString(), QStringList()); testConfiguration->setTestCaseCount(1); testConfiguration->setUnnamedOnly(true); - addProjectInformation(testConfiguration, mainFile); + testConfiguration->setMainFilePath(mainFile); + testConfiguration->setProject(project); foundMains.insert(mainFile, testConfiguration); } } @@ -581,7 +493,8 @@ QList<TestConfiguration *> TestTreeModel::getSelectedTests() const } } else { tc = new TestConfiguration(QString(), testFunctions); - addProjectInformation(tc, child->mainFile()); + tc->setMainFilePath(child->mainFile()); + tc->setProject(project); foundMains.insert(child->mainFile(), tc); } break; @@ -595,6 +508,55 @@ QList<TestConfiguration *> TestTreeModel::getSelectedTests() const return result; } +TestConfiguration *TestTreeModel::getTestConfiguration(const TestTreeItem *item) const +{ + QTC_ASSERT(item != 0, return 0); + ProjectExplorer::Project *project = ProjectExplorer::SessionManager::startupProject(); + QTC_ASSERT(project, return 0); + + TestConfiguration *config = 0; + switch (item->type()) { + case TestTreeItem::TEST_CLASS: { + if (item->parent() == m_quickTestRootItem) { + // Quick Test TestCase + QStringList testFunctions; + for (int row = 0, count = item->childCount(); row < count; ++row) { + testFunctions << item->name() + QLatin1String("::") + item->child(row)->name(); + } + config = new TestConfiguration(QString(), testFunctions); + config->setMainFilePath(item->mainFile()); + config->setProject(project); + } else { + // normal auto test + config = new TestConfiguration(item->name(), QStringList(), item->childCount()); + config->setMainFilePath(item->filePath()); + config->setProject(project); + } + break; + } + case TestTreeItem::TEST_FUNCTION: { + const TestTreeItem *parent = item->parent(); + if (parent->parent() == m_quickTestRootItem) { + // it's a Quick Test function of a named TestCase + QStringList testFunction(parent->name() + QLatin1String("::") + item->name()); + config = new TestConfiguration(QString(), testFunction); + config->setMainFilePath(parent->mainFile()); + config->setProject(project); + } else { + // normal auto test + config = new TestConfiguration(parent->name(), QStringList() << item->name()); + config->setMainFilePath(parent->filePath()); + config->setProject(project); + } + break; + } + // not supported items + default: + return 0; + } + return config; +} + QString TestTreeModel::getMainFileForUnnamedQuickTest(const QString &qmlFile) const { const TestTreeItem *unnamed = unnamedQuickTests(); diff --git a/plugins/autotest/testtreemodel.h b/plugins/autotest/testtreemodel.h index 15a00ecb38..785606c36a 100644 --- a/plugins/autotest/testtreemodel.h +++ b/plugins/autotest/testtreemodel.h @@ -31,7 +31,8 @@ namespace { enum ItemRole { // AnnotationRole = Qt::UserRole + 1, LinkRole = Qt::UserRole + 2, // can be removed if AnnotationRole comes back - ItalicRole // used only inside the delegate + ItalicRole, // used only inside the delegate + TypeRole }; } @@ -71,6 +72,7 @@ public: bool hasTests() const; QList<TestConfiguration *> getAllTestCases() const; QList<TestConfiguration *> getSelectedTests() const; + TestConfiguration *getTestConfiguration(const TestTreeItem *item) const; QString getMainFileForUnnamedQuickTest(const QString &qmlFile) const; void qmlFilesForMainFile(const QString &mainFile, QSet<QString> *filePaths) const; QList<QString> getUnnamedQuickTestFunctions() const; |