2016-05-11 13:02:42 +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 "qttestparser.h"
|
2016-05-31 14:24:42 +02:00
|
|
|
#include "qttesttreeitem.h"
|
2016-05-11 13:02:42 +02:00
|
|
|
#include "qttestvisitors.h"
|
|
|
|
|
#include "qttest_utils.h"
|
|
|
|
|
|
2017-05-08 12:09:11 +02:00
|
|
|
#include <cpptools/cppmodelmanager.h>
|
|
|
|
|
#include <cpptools/projectpart.h>
|
2016-05-11 13:02:42 +02:00
|
|
|
#include <cplusplus/TypeOfExpression.h>
|
2017-01-05 10:34:03 +01:00
|
|
|
#include <utils/algorithm.h>
|
2016-05-11 13:02:42 +02:00
|
|
|
|
|
|
|
|
namespace Autotest {
|
|
|
|
|
namespace Internal {
|
|
|
|
|
|
|
|
|
|
TestTreeItem *QtTestParseResult::createTestTreeItem() const
|
|
|
|
|
{
|
2017-01-05 12:03:42 +01:00
|
|
|
if (itemType == TestTreeItem::Root)
|
|
|
|
|
return nullptr;
|
|
|
|
|
|
|
|
|
|
QtTestTreeItem *item = new QtTestTreeItem(displayName, fileName, itemType);
|
|
|
|
|
item->setProFile(proFile);
|
|
|
|
|
item->setLine(line);
|
|
|
|
|
item->setColumn(column);
|
|
|
|
|
item->setInherited(m_inherited);
|
|
|
|
|
|
2017-02-13 10:05:06 +01:00
|
|
|
for (const TestParseResult *funcParseResult : children)
|
2017-01-05 12:03:42 +01:00
|
|
|
item->appendChild(funcParseResult->createTestTreeItem());
|
|
|
|
|
return item;
|
2016-05-11 13:02:42 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static bool includesQtTest(const CPlusPlus::Document::Ptr &doc, const CPlusPlus::Snapshot &snapshot)
|
|
|
|
|
{
|
|
|
|
|
static QStringList expectedHeaderPrefixes
|
|
|
|
|
= Utils::HostOsInfo::isMacHost()
|
2017-02-22 15:09:35 +01:00
|
|
|
? QStringList({"QtTest.framework/Headers", "QtTest"}) : QStringList({"QtTest"});
|
2016-05-11 13:02:42 +02:00
|
|
|
|
|
|
|
|
const QList<CPlusPlus::Document::Include> includes = doc->resolvedIncludes();
|
|
|
|
|
|
2017-02-13 10:05:06 +01:00
|
|
|
for (const CPlusPlus::Document::Include &inc : includes) {
|
2016-05-11 13:02:42 +02:00
|
|
|
// TODO this short cut works only for #include <QtTest>
|
|
|
|
|
// bad, as there could be much more different approaches
|
2017-02-13 10:05:06 +01:00
|
|
|
if (inc.unresolvedFileName() == QString("QtTest")) {
|
|
|
|
|
for (const QString &prefix : expectedHeaderPrefixes) {
|
2016-09-29 12:15:43 +02:00
|
|
|
if (inc.resolvedFileName().endsWith(QString("%1/QtTest").arg(prefix)))
|
2016-05-11 13:02:42 +02:00
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const QSet<QString> allIncludes = snapshot.allIncludesForDocument(doc->fileName());
|
2017-02-13 10:05:06 +01:00
|
|
|
for (const QString &include : allIncludes) {
|
|
|
|
|
for (const QString &prefix : expectedHeaderPrefixes) {
|
2016-09-29 12:15:43 +02:00
|
|
|
if (include.endsWith(QString("%1/qtest.h").arg(prefix)))
|
2016-05-11 13:02:42 +02:00
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static bool qtTestLibDefined(const QString &fileName)
|
|
|
|
|
{
|
|
|
|
|
const QList<CppTools::ProjectPart::Ptr> parts =
|
|
|
|
|
CppTools::CppModelManager::instance()->projectPart(fileName);
|
2017-09-18 12:14:37 +02:00
|
|
|
if (parts.size() > 0) {
|
|
|
|
|
return Utils::anyOf(parts.at(0)->projectMacros, [] (const ProjectExplorer::Macro ¯o) {
|
|
|
|
|
return macro.key == "QT_TESTLIB_LIB";
|
|
|
|
|
});
|
|
|
|
|
}
|
2016-05-11 13:02:42 +02:00
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static QString testClass(const CppTools::CppModelManager *modelManager,
|
|
|
|
|
const CPlusPlus::Snapshot &snapshot, const QString &fileName)
|
|
|
|
|
{
|
2016-06-20 07:03:55 +02:00
|
|
|
const QByteArray &fileContent = CppParser::getFileContent(fileName);
|
2016-05-11 13:02:42 +02:00
|
|
|
CPlusPlus::Document::Ptr document = modelManager->document(fileName);
|
|
|
|
|
if (document.isNull())
|
|
|
|
|
return QString();
|
|
|
|
|
|
|
|
|
|
const QList<CPlusPlus::Document::MacroUse> macros = document->macroUses();
|
|
|
|
|
|
2017-02-13 10:05:06 +01:00
|
|
|
for (const CPlusPlus::Document::MacroUse ¯o : macros) {
|
2016-05-11 13:02:42 +02:00
|
|
|
if (!macro.isFunctionLike())
|
|
|
|
|
continue;
|
|
|
|
|
const QByteArray name = macro.macro().name();
|
|
|
|
|
if (QTestUtils::isQTestMacro(name)) {
|
|
|
|
|
const CPlusPlus::Document::Block arg = macro.arguments().at(0);
|
2018-07-11 15:44:51 +02:00
|
|
|
return QLatin1String(fileContent.mid(int(arg.bytesBegin()),
|
|
|
|
|
int(arg.bytesEnd() - arg.bytesBegin())));
|
2016-05-11 13:02:42 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
// check if one has used a self-defined macro or QTest::qExec() directly
|
|
|
|
|
document = snapshot.preprocessedDocument(fileContent, fileName);
|
|
|
|
|
document->check();
|
|
|
|
|
CPlusPlus::AST *ast = document->translationUnit()->ast();
|
2016-09-29 13:58:43 +02:00
|
|
|
TestAstVisitor astVisitor(document, snapshot);
|
2016-05-11 13:02:42 +02:00
|
|
|
astVisitor.accept(ast);
|
|
|
|
|
return astVisitor.className();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static CPlusPlus::Document::Ptr declaringDocument(CPlusPlus::Document::Ptr doc,
|
|
|
|
|
const CPlusPlus::Snapshot &snapshot,
|
|
|
|
|
const QString &testCaseName,
|
2017-01-04 13:56:20 +01:00
|
|
|
const QStringList &alternativeFiles = {},
|
2018-07-11 15:44:51 +02:00
|
|
|
unsigned *line = nullptr,
|
|
|
|
|
unsigned *column = nullptr)
|
2016-05-11 13:02:42 +02:00
|
|
|
{
|
2017-01-04 13:56:20 +01:00
|
|
|
CPlusPlus::Document::Ptr declaringDoc;
|
2016-05-11 13:02:42 +02:00
|
|
|
CPlusPlus::TypeOfExpression typeOfExpr;
|
|
|
|
|
typeOfExpr.init(doc, snapshot);
|
|
|
|
|
|
|
|
|
|
QList<CPlusPlus::LookupItem> lookupItems = typeOfExpr(testCaseName.toUtf8(),
|
|
|
|
|
doc->globalNamespace());
|
2017-01-04 13:56:20 +01:00
|
|
|
// fallback for inherited functions
|
|
|
|
|
if (lookupItems.size() == 0 && !alternativeFiles.isEmpty()) {
|
|
|
|
|
for (const QString &alternativeFile : alternativeFiles) {
|
|
|
|
|
if (snapshot.contains(alternativeFile)) {
|
|
|
|
|
CPlusPlus::Document::Ptr document = snapshot.document(alternativeFile);
|
|
|
|
|
CPlusPlus::TypeOfExpression typeOfExpr; // we need a new one with no bindings
|
|
|
|
|
typeOfExpr.init(document, snapshot);
|
|
|
|
|
lookupItems = typeOfExpr(testCaseName.toUtf8(), document->globalNamespace());
|
|
|
|
|
if (lookupItems.size() != 0)
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-11-20 14:02:09 +01:00
|
|
|
for (const CPlusPlus::LookupItem &item : lookupItems) {
|
|
|
|
|
if (CPlusPlus::Symbol *symbol = item.declaration()) {
|
2016-05-11 13:02:42 +02:00
|
|
|
if (CPlusPlus::Class *toeClass = symbol->asClass()) {
|
|
|
|
|
const QString declFileName = QLatin1String(toeClass->fileId()->chars(),
|
2018-07-11 15:44:51 +02:00
|
|
|
int(toeClass->fileId()->size()));
|
2016-05-11 13:02:42 +02:00
|
|
|
declaringDoc = snapshot.document(declFileName);
|
2017-01-04 12:15:39 +01:00
|
|
|
if (line)
|
|
|
|
|
*line = toeClass->line();
|
|
|
|
|
if (column)
|
|
|
|
|
*column = toeClass->column() - 1;
|
2016-05-11 13:02:42 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return declaringDoc;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static QSet<QString> filesWithDataFunctionDefinitions(
|
2017-01-04 12:06:46 +01:00
|
|
|
const QMap<QString, QtTestCodeLocationAndType> &testFunctions)
|
2016-05-11 13:02:42 +02:00
|
|
|
{
|
|
|
|
|
QSet<QString> result;
|
2017-01-04 12:06:46 +01:00
|
|
|
QMap<QString, QtTestCodeLocationAndType>::ConstIterator it = testFunctions.begin();
|
|
|
|
|
const QMap<QString, QtTestCodeLocationAndType>::ConstIterator end = testFunctions.end();
|
2016-05-11 13:02:42 +02:00
|
|
|
|
|
|
|
|
for ( ; it != end; ++it) {
|
|
|
|
|
const QString &key = it.key();
|
2016-09-29 12:15:43 +02:00
|
|
|
if (key.endsWith("_data") && testFunctions.contains(key.left(key.size() - 5)))
|
2016-05-11 13:02:42 +02:00
|
|
|
result.insert(it.value().m_name);
|
|
|
|
|
}
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
2017-01-04 12:06:46 +01:00
|
|
|
static QMap<QString, QtTestCodeLocationList> checkForDataTags(const QString &fileName,
|
2016-05-11 13:02:42 +02:00
|
|
|
const CPlusPlus::Snapshot &snapshot)
|
|
|
|
|
{
|
2016-06-20 07:03:55 +02:00
|
|
|
const QByteArray fileContent = CppParser::getFileContent(fileName);
|
2016-05-11 13:02:42 +02:00
|
|
|
CPlusPlus::Document::Ptr document = snapshot.preprocessedDocument(fileContent, fileName);
|
|
|
|
|
document->check();
|
|
|
|
|
CPlusPlus::AST *ast = document->translationUnit()->ast();
|
|
|
|
|
TestDataFunctionVisitor visitor(document);
|
|
|
|
|
visitor.accept(ast);
|
|
|
|
|
return visitor.dataTags();
|
|
|
|
|
}
|
|
|
|
|
|
2017-01-05 10:34:03 +01:00
|
|
|
/*!
|
|
|
|
|
* \brief Checks whether \a testFunctions (keys are full qualified names) contains already the
|
|
|
|
|
* given \a function (unqualified name).
|
|
|
|
|
*
|
|
|
|
|
* \return true if this function is already contained, false otherwise
|
|
|
|
|
*/
|
|
|
|
|
static bool containsFunction(const QMap<QString, QtTestCodeLocationAndType> &testFunctions,
|
|
|
|
|
const QString &function)
|
2017-01-04 12:15:39 +01:00
|
|
|
{
|
2017-01-05 10:34:03 +01:00
|
|
|
const QString search = "::" + function;
|
|
|
|
|
return Utils::anyOf(testFunctions.keys(), [&search] (const QString &key) {
|
|
|
|
|
return key.endsWith(search);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void mergeTestFunctions(QMap<QString, QtTestCodeLocationAndType> &testFunctions,
|
|
|
|
|
const QMap<QString, QtTestCodeLocationAndType> &inheritedFunctions)
|
|
|
|
|
{
|
|
|
|
|
static const QString dataSuffix("_data");
|
|
|
|
|
// take over only inherited test functions that have not been re-implemented
|
|
|
|
|
QMap<QString, QtTestCodeLocationAndType>::ConstIterator it = inheritedFunctions.begin();
|
|
|
|
|
QMap<QString, QtTestCodeLocationAndType>::ConstIterator end = inheritedFunctions.end();
|
|
|
|
|
for ( ; it != end; ++it) {
|
|
|
|
|
const QString functionName = it.key();
|
|
|
|
|
const QString &shortName = functionName.mid(functionName.lastIndexOf(':') + 1);
|
|
|
|
|
if (shortName.endsWith(dataSuffix)) {
|
|
|
|
|
const QString &correspondingFunc = functionName.left(functionName.size()
|
|
|
|
|
- dataSuffix.size());
|
|
|
|
|
// inherited test data functions only if we're inheriting the corresponding test
|
|
|
|
|
// function as well (and the inherited test function is not omitted)
|
|
|
|
|
if (inheritedFunctions.contains(correspondingFunc)) {
|
|
|
|
|
if (!testFunctions.contains(correspondingFunc))
|
|
|
|
|
continue;
|
|
|
|
|
testFunctions.insert(functionName, it.value());
|
|
|
|
|
}
|
|
|
|
|
} else if (!containsFunction(testFunctions, shortName)) {
|
|
|
|
|
// normal test functions only if not re-implemented
|
|
|
|
|
testFunctions.insert(functionName, it.value());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void fetchAndMergeBaseTestFunctions(const QSet<QString> &baseClasses,
|
|
|
|
|
QMap<QString, QtTestCodeLocationAndType> &testFunctions,
|
|
|
|
|
const CPlusPlus::Document::Ptr &doc,
|
|
|
|
|
const CPlusPlus::Snapshot &snapshot)
|
|
|
|
|
{
|
|
|
|
|
QList<QString> bases = baseClasses.toList();
|
|
|
|
|
while (!bases.empty()) {
|
|
|
|
|
const QString base = bases.takeFirst();
|
|
|
|
|
TestVisitor baseVisitor(base, snapshot);
|
2017-01-04 12:15:39 +01:00
|
|
|
baseVisitor.setInheritedMode(true);
|
2017-01-05 10:34:03 +01:00
|
|
|
CPlusPlus::Document::Ptr declaringDoc = declaringDocument(doc, snapshot, base);
|
2017-01-04 12:15:39 +01:00
|
|
|
if (declaringDoc.isNull())
|
|
|
|
|
continue;
|
|
|
|
|
baseVisitor.accept(declaringDoc->globalNamespace());
|
2017-01-05 10:34:03 +01:00
|
|
|
if (!baseVisitor.resultValid())
|
|
|
|
|
continue;
|
|
|
|
|
bases.append(baseVisitor.baseClasses().toList());
|
|
|
|
|
mergeTestFunctions(testFunctions, baseVisitor.privateSlots());
|
2017-01-04 12:15:39 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-01-04 15:47:46 +01:00
|
|
|
static QtTestCodeLocationList tagLocationsFor(const QtTestParseResult *func,
|
|
|
|
|
const QMap<QString, QtTestCodeLocationList> &dataTags)
|
|
|
|
|
{
|
|
|
|
|
if (!func->inherited())
|
|
|
|
|
return dataTags.value(func->name);
|
|
|
|
|
|
|
|
|
|
QMap<QString, QtTestCodeLocationList>::ConstIterator it = dataTags.begin();
|
|
|
|
|
QMap<QString, QtTestCodeLocationList>::ConstIterator end = dataTags.end();
|
|
|
|
|
const int lastColon = func->name.lastIndexOf(':');
|
|
|
|
|
QString funcName = lastColon == -1 ? func->name : func->name.mid(lastColon - 1);
|
|
|
|
|
for ( ; it != end; ++it) {
|
|
|
|
|
if (it.key().endsWith(funcName))
|
|
|
|
|
return it.value();
|
|
|
|
|
}
|
|
|
|
|
return QtTestCodeLocationList();
|
|
|
|
|
}
|
|
|
|
|
|
2018-01-15 10:38:27 +01:00
|
|
|
static bool isQObject(const CPlusPlus::Document::Ptr &declaringDoc)
|
|
|
|
|
{
|
|
|
|
|
const QString file = declaringDoc->fileName();
|
|
|
|
|
return (Utils::HostOsInfo::isMacHost() && file.endsWith("QtCore.framework/Headers/qobject.h"))
|
|
|
|
|
|| file.endsWith("QtCore/qobject.h") || file.endsWith("kernel/qobject.h");
|
|
|
|
|
}
|
|
|
|
|
|
2016-05-11 13:02:42 +02:00
|
|
|
static bool handleQtTest(QFutureInterface<TestParseResultPtr> futureInterface,
|
|
|
|
|
CPlusPlus::Document::Ptr document,
|
|
|
|
|
const CPlusPlus::Snapshot &snapshot,
|
2016-06-06 14:18:38 +02:00
|
|
|
const QString &oldTestCaseName,
|
2017-01-04 13:56:20 +01:00
|
|
|
const QStringList &alternativeFiles,
|
2016-06-06 14:18:38 +02:00
|
|
|
const Core::Id &id)
|
2016-05-11 13:02:42 +02:00
|
|
|
{
|
|
|
|
|
const CppTools::CppModelManager *modelManager = CppTools::CppModelManager::instance();
|
|
|
|
|
const QString &fileName = document->fileName();
|
|
|
|
|
QString testCaseName(testClass(modelManager, snapshot, fileName));
|
|
|
|
|
// we might be in a reparse without the original entry point with the QTest::qExec()
|
|
|
|
|
if (testCaseName.isEmpty())
|
|
|
|
|
testCaseName = oldTestCaseName;
|
|
|
|
|
if (!testCaseName.isEmpty()) {
|
|
|
|
|
unsigned line = 0;
|
|
|
|
|
unsigned column = 0;
|
|
|
|
|
CPlusPlus::Document::Ptr declaringDoc = declaringDocument(document, snapshot, testCaseName,
|
2017-01-04 13:56:20 +01:00
|
|
|
alternativeFiles, &line, &column);
|
2016-05-11 13:02:42 +02:00
|
|
|
if (declaringDoc.isNull())
|
|
|
|
|
return false;
|
|
|
|
|
|
2016-09-29 13:58:43 +02:00
|
|
|
TestVisitor visitor(testCaseName, snapshot);
|
2016-05-11 13:02:42 +02:00
|
|
|
visitor.accept(declaringDoc->globalNamespace());
|
|
|
|
|
if (!visitor.resultValid())
|
|
|
|
|
return false;
|
|
|
|
|
|
2017-01-04 12:15:39 +01:00
|
|
|
QMap<QString, QtTestCodeLocationAndType> testFunctions = visitor.privateSlots();
|
2017-01-05 10:34:03 +01:00
|
|
|
// gather appropriate information of base classes as well and merge into already found
|
|
|
|
|
// functions - but only as far as QtTest can handle this appropriate
|
|
|
|
|
fetchAndMergeBaseTestFunctions(
|
|
|
|
|
visitor.baseClasses(), testFunctions, declaringDoc, snapshot);
|
|
|
|
|
|
2018-01-15 10:38:27 +01:00
|
|
|
// handle tests that are not runnable without more information (plugin unit test of QC)
|
|
|
|
|
if (testFunctions.isEmpty() && testCaseName == "QObject" && isQObject(declaringDoc))
|
|
|
|
|
return true; // we did not handle it, but we do not expect any test defined there either
|
|
|
|
|
|
2016-05-11 13:02:42 +02:00
|
|
|
const QSet<QString> &files = filesWithDataFunctionDefinitions(testFunctions);
|
|
|
|
|
|
|
|
|
|
// TODO: change to QHash<>
|
2017-01-04 12:06:46 +01:00
|
|
|
QMap<QString, QtTestCodeLocationList> dataTags;
|
2017-02-13 10:05:06 +01:00
|
|
|
for (const QString &file : files)
|
2016-05-11 13:02:42 +02:00
|
|
|
dataTags.unite(checkForDataTags(file, snapshot));
|
|
|
|
|
|
2016-06-06 14:18:38 +02:00
|
|
|
QtTestParseResult *parseResult = new QtTestParseResult(id);
|
2016-05-11 13:02:42 +02:00
|
|
|
parseResult->itemType = TestTreeItem::TestCase;
|
|
|
|
|
parseResult->fileName = declaringDoc->fileName();
|
|
|
|
|
parseResult->name = testCaseName;
|
|
|
|
|
parseResult->displayName = testCaseName;
|
|
|
|
|
parseResult->line = line;
|
|
|
|
|
parseResult->column = column;
|
2016-07-08 12:53:57 +02:00
|
|
|
QList<CppTools::ProjectPart::Ptr> projectParts = modelManager->projectPart(fileName);
|
|
|
|
|
if (projectParts.isEmpty()) // happens if shutting down while parsing
|
|
|
|
|
return false;
|
|
|
|
|
parseResult->proFile = projectParts.first()->projectFile;
|
2017-01-04 12:06:46 +01:00
|
|
|
QMap<QString, QtTestCodeLocationAndType>::ConstIterator it = testFunctions.begin();
|
|
|
|
|
const QMap<QString, QtTestCodeLocationAndType>::ConstIterator end = testFunctions.end();
|
2016-05-11 13:02:42 +02:00
|
|
|
for ( ; it != end; ++it) {
|
2017-01-04 12:06:46 +01:00
|
|
|
const QtTestCodeLocationAndType &location = it.value();
|
2017-01-05 10:34:03 +01:00
|
|
|
QString functionName = it.key();
|
|
|
|
|
functionName = functionName.mid(functionName.lastIndexOf(':') + 1);
|
2016-06-06 14:18:38 +02:00
|
|
|
QtTestParseResult *func = new QtTestParseResult(id);
|
2016-05-11 13:02:42 +02:00
|
|
|
func->itemType = location.m_type;
|
2017-01-05 10:34:03 +01:00
|
|
|
func->name = testCaseName + "::" + functionName;
|
|
|
|
|
func->displayName = functionName;
|
2016-05-11 13:02:42 +02:00
|
|
|
func->fileName = location.m_name;
|
|
|
|
|
func->line = location.m_line;
|
|
|
|
|
func->column = location.m_column;
|
2017-01-04 12:06:46 +01:00
|
|
|
func->setInherited(location.m_inherited);
|
2016-05-11 13:02:42 +02:00
|
|
|
|
2017-01-04 15:47:46 +01:00
|
|
|
const QtTestCodeLocationList &tagLocations = tagLocationsFor(func, dataTags);
|
2017-02-13 10:05:06 +01:00
|
|
|
for (const QtTestCodeLocationAndType &tag : tagLocations) {
|
2016-06-06 14:18:38 +02:00
|
|
|
QtTestParseResult *dataTag = new QtTestParseResult(id);
|
2016-05-11 13:02:42 +02:00
|
|
|
dataTag->itemType = tag.m_type;
|
|
|
|
|
dataTag->name = tag.m_name;
|
|
|
|
|
dataTag->displayName = tag.m_name;
|
2016-09-29 12:15:43 +02:00
|
|
|
dataTag->fileName = testFunctions.value(it.key() + "_data").m_name;
|
2016-05-11 13:02:42 +02:00
|
|
|
dataTag->line = tag.m_line;
|
|
|
|
|
dataTag->column = tag.m_column;
|
2017-01-04 12:06:46 +01:00
|
|
|
dataTag->setInherited(tag.m_inherited);
|
2016-05-11 13:02:42 +02:00
|
|
|
|
|
|
|
|
func->children.append(dataTag);
|
|
|
|
|
}
|
|
|
|
|
parseResult->children.append(func);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
futureInterface.reportResult(TestParseResultPtr(parseResult));
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2018-01-08 15:14:33 +01:00
|
|
|
void QtTestParser::init(const QStringList &filesToParse, bool fullParse)
|
2016-05-11 13:02:42 +02:00
|
|
|
{
|
2018-01-08 15:14:33 +01:00
|
|
|
if (!fullParse) { // in a full parse cached information might lead to wrong results
|
|
|
|
|
m_testCaseNames = QTestUtils::testCaseNamesForFiles(id(), filesToParse);
|
|
|
|
|
m_alternativeFiles = QTestUtils::alternativeFiles(id(), filesToParse);
|
|
|
|
|
}
|
|
|
|
|
CppParser::init(filesToParse, fullParse);
|
2016-05-11 13:02:42 +02:00
|
|
|
}
|
|
|
|
|
|
2016-07-12 10:35:43 +02:00
|
|
|
void QtTestParser::release()
|
|
|
|
|
{
|
|
|
|
|
m_testCaseNames.clear();
|
2017-01-04 13:56:20 +01:00
|
|
|
m_alternativeFiles.clear();
|
2016-07-12 10:35:43 +02:00
|
|
|
CppParser::release();
|
|
|
|
|
}
|
|
|
|
|
|
2016-05-11 13:02:42 +02:00
|
|
|
bool QtTestParser::processDocument(QFutureInterface<TestParseResultPtr> futureInterface,
|
|
|
|
|
const QString &fileName)
|
|
|
|
|
{
|
|
|
|
|
if (!m_cppSnapshot.contains(fileName) || !selectedForBuilding(fileName))
|
|
|
|
|
return false;
|
|
|
|
|
CPlusPlus::Document::Ptr doc = m_cppSnapshot.find(fileName).value();
|
|
|
|
|
const QString &oldName = m_testCaseNames.value(fileName);
|
2017-01-04 13:56:20 +01:00
|
|
|
const QStringList &alternativeFiles = m_alternativeFiles.values(fileName);
|
2016-05-11 13:02:42 +02:00
|
|
|
if ((!includesQtTest(doc, m_cppSnapshot) || !qtTestLibDefined(fileName)) && oldName.isEmpty())
|
|
|
|
|
return false;
|
|
|
|
|
|
2017-01-04 13:56:20 +01:00
|
|
|
return handleQtTest(futureInterface, doc, m_cppSnapshot, oldName, alternativeFiles, id());
|
2016-05-11 13:02:42 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} // namespace Internal
|
|
|
|
|
} // namespace Autotest
|