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
|
|
|
**
|
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
2015-12-07 10:21:50 +01:00
|
|
|
#include "autotest_utils.h"
|
2014-10-07 12:30:54 +02:00
|
|
|
#include "testvisitor.h"
|
|
|
|
|
|
2014-10-28 15:57:13 +01:00
|
|
|
#include <cplusplus/FullySpecifiedType.h>
|
2014-10-07 12:30:54 +02:00
|
|
|
#include <cplusplus/LookupContext.h>
|
|
|
|
|
#include <cplusplus/Symbols.h>
|
2014-10-28 15:57:13 +01:00
|
|
|
#include <cplusplus/TypeOfExpression.h>
|
|
|
|
|
|
|
|
|
|
#include <cpptools/cppmodelmanager.h>
|
2014-10-07 12:30:54 +02:00
|
|
|
|
2014-11-06 16:01:06 +01:00
|
|
|
#include <qmljs/parser/qmljsast_p.h>
|
|
|
|
|
|
2015-08-04 15:53:09 +02:00
|
|
|
#include <utils/qtcassert.h>
|
|
|
|
|
|
2014-10-07 12:30:54 +02:00
|
|
|
#include <QList>
|
|
|
|
|
|
|
|
|
|
namespace Autotest {
|
|
|
|
|
namespace Internal {
|
|
|
|
|
|
2015-05-19 07:41:39 +02:00
|
|
|
// names of special functions (applies for QTest as well as Quick Tests)
|
|
|
|
|
static QList<QString> specialFunctions = QList<QString>() << QLatin1String("initTestCase")
|
|
|
|
|
<< QLatin1String("cleanupTestCase")
|
|
|
|
|
<< QLatin1String("init")
|
|
|
|
|
<< QLatin1String("cleanup");
|
|
|
|
|
|
2014-11-06 16:01:06 +01:00
|
|
|
/************************** Cpp Test Symbol Visitor ***************************/
|
|
|
|
|
|
2014-10-07 12:30:54 +02:00
|
|
|
TestVisitor::TestVisitor(const QString &fullQualifiedClassName)
|
|
|
|
|
: m_className(fullQualifiedClassName)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TestVisitor::~TestVisitor()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool TestVisitor::visit(CPlusPlus::Class *symbol)
|
|
|
|
|
{
|
|
|
|
|
const CPlusPlus::Overview o;
|
|
|
|
|
CPlusPlus::LookupContext lc;
|
2016-04-27 16:24:45 +02:00
|
|
|
const CPlusPlus::Snapshot snapshot = CppTools::CppModelManager::instance()->snapshot();
|
2014-10-07 12:30:54 +02:00
|
|
|
|
|
|
|
|
unsigned count = symbol->memberCount();
|
|
|
|
|
for (unsigned i = 0; i < count; ++i) {
|
|
|
|
|
CPlusPlus::Symbol *member = symbol->memberAt(i);
|
|
|
|
|
CPlusPlus::Type *type = member->type().type();
|
|
|
|
|
|
|
|
|
|
const QString className = o.prettyName(lc.fullyQualifiedName(member->enclosingClass()));
|
|
|
|
|
if (className != m_className)
|
|
|
|
|
continue;
|
|
|
|
|
|
2016-03-31 14:31:53 +02:00
|
|
|
m_valid = true;
|
|
|
|
|
|
2014-11-06 16:01:06 +01:00
|
|
|
if (const auto func = type->asFunctionType()) {
|
2014-10-07 12:30:54 +02:00
|
|
|
if (func->isSlot() && member->isPrivate()) {
|
2014-10-28 15:57:13 +01:00
|
|
|
const QString name = o.prettyName(func->name());
|
2014-11-13 12:31:58 +01:00
|
|
|
TestCodeLocationAndType locationAndType;
|
2015-08-03 14:56:18 +02:00
|
|
|
|
|
|
|
|
CPlusPlus::Function *functionDefinition = m_symbolFinder.findMatchingDefinition(
|
2016-04-27 16:24:45 +02:00
|
|
|
func, snapshot, true);
|
2016-04-15 07:11:06 +02:00
|
|
|
if (functionDefinition && functionDefinition->fileId()) {
|
2015-08-04 15:53:09 +02:00
|
|
|
locationAndType.m_name = QString::fromUtf8(functionDefinition->fileName());
|
2015-08-03 14:56:18 +02:00
|
|
|
locationAndType.m_line = functionDefinition->line();
|
|
|
|
|
locationAndType.m_column = functionDefinition->column() - 1;
|
|
|
|
|
} else { // if we cannot find the definition use declaration as fallback
|
2015-08-04 15:53:09 +02:00
|
|
|
locationAndType.m_name = QString::fromUtf8(member->fileName());
|
2015-08-03 14:56:18 +02:00
|
|
|
locationAndType.m_line = member->line();
|
|
|
|
|
locationAndType.m_column = member->column() - 1;
|
|
|
|
|
}
|
2014-11-13 12:31:58 +01:00
|
|
|
if (specialFunctions.contains(name))
|
2015-12-07 08:26:54 +01:00
|
|
|
locationAndType.m_type = TestTreeItem::TestSpecialFunction;
|
2014-11-13 12:31:58 +01:00
|
|
|
else if (name.endsWith(QLatin1String("_data")))
|
2015-12-07 08:26:54 +01:00
|
|
|
locationAndType.m_type = TestTreeItem::TestDataFunction;
|
2014-11-13 12:31:58 +01:00
|
|
|
else
|
2016-02-23 15:56:52 +01:00
|
|
|
locationAndType.m_type = TestTreeItem::TestFunctionOrSet;
|
2014-11-13 12:31:58 +01:00
|
|
|
m_privSlots.insert(name, locationAndType);
|
2014-10-07 12:30:54 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2014-11-06 16:01:06 +01:00
|
|
|
/**************************** Cpp Test AST Visitor ****************************/
|
|
|
|
|
|
2014-10-28 15:57:13 +01:00
|
|
|
TestAstVisitor::TestAstVisitor(CPlusPlus::Document::Ptr doc)
|
|
|
|
|
: ASTVisitor(doc->translationUnit()),
|
|
|
|
|
m_currentDoc(doc)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TestAstVisitor::~TestAstVisitor()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool TestAstVisitor::visit(CPlusPlus::CallAST *ast)
|
|
|
|
|
{
|
|
|
|
|
if (!m_currentScope || m_currentDoc.isNull())
|
|
|
|
|
return false;
|
|
|
|
|
|
2014-11-06 16:01:06 +01:00
|
|
|
if (const auto expressionAST = ast->base_expression) {
|
|
|
|
|
if (const auto idExpressionAST = expressionAST->asIdExpression()) {
|
|
|
|
|
if (const auto qualifiedNameAST = idExpressionAST->name->asQualifiedName()) {
|
2014-10-28 15:57:13 +01:00
|
|
|
const CPlusPlus::Overview o;
|
|
|
|
|
const QString prettyName = o.prettyName(qualifiedNameAST->name);
|
|
|
|
|
if (prettyName == QLatin1String("QTest::qExec")) {
|
2014-11-06 16:01:06 +01:00
|
|
|
if (const auto expressionListAST = ast->expression_list) {
|
2014-10-28 15:57:13 +01:00
|
|
|
// first argument is the one we need
|
2014-11-06 16:01:06 +01:00
|
|
|
if (const auto argumentExpressionAST = expressionListAST->value) {
|
2014-10-28 15:57:13 +01:00
|
|
|
CPlusPlus::TypeOfExpression toe;
|
|
|
|
|
CppTools::CppModelManager *cppMM = CppTools::CppModelManager::instance();
|
|
|
|
|
toe.init(m_currentDoc, cppMM->snapshot());
|
|
|
|
|
QList<CPlusPlus::LookupItem> toeItems
|
|
|
|
|
= toe(argumentExpressionAST, m_currentDoc, m_currentScope);
|
|
|
|
|
|
|
|
|
|
if (toeItems.size()) {
|
2014-11-06 16:01:06 +01:00
|
|
|
if (const auto pointerType = toeItems.first().type()->asPointerType())
|
2014-10-28 15:57:13 +01:00
|
|
|
m_className = o.prettyType(pointerType->elementType());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool TestAstVisitor::visit(CPlusPlus::CompoundStatementAST *ast)
|
|
|
|
|
{
|
2016-05-24 13:02:04 +02:00
|
|
|
if (!ast || !ast->symbol) {
|
|
|
|
|
m_currentScope = 0;
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2014-10-28 15:57:13 +01:00
|
|
|
m_currentScope = ast->symbol->asScope();
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2015-08-04 15:53:09 +02:00
|
|
|
/********************** Test Data Function AST Visitor ************************/
|
|
|
|
|
|
|
|
|
|
TestDataFunctionVisitor::TestDataFunctionVisitor(CPlusPlus::Document::Ptr doc)
|
|
|
|
|
: CPlusPlus::ASTVisitor(doc->translationUnit()),
|
|
|
|
|
m_currentDoc(doc),
|
|
|
|
|
m_currentAstDepth(0),
|
|
|
|
|
m_insideUsingQTestDepth(0),
|
|
|
|
|
m_insideUsingQTest(false)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TestDataFunctionVisitor::~TestDataFunctionVisitor()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool TestDataFunctionVisitor::visit(CPlusPlus::UsingDirectiveAST *ast)
|
|
|
|
|
{
|
|
|
|
|
if (auto nameAST = ast->name) {
|
|
|
|
|
if (m_overview.prettyName(nameAST->name) == QLatin1String("QTest")) {
|
|
|
|
|
m_insideUsingQTest = true;
|
|
|
|
|
// we need the surrounding AST depth as using directive is an AST itself
|
|
|
|
|
m_insideUsingQTestDepth = m_currentAstDepth - 1;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool TestDataFunctionVisitor::visit(CPlusPlus::FunctionDefinitionAST *ast)
|
|
|
|
|
{
|
|
|
|
|
if (ast->declarator) {
|
|
|
|
|
CPlusPlus::DeclaratorIdAST *id = ast->declarator->core_declarator->asDeclaratorId();
|
2015-10-29 10:20:53 +01:00
|
|
|
if (!id || !ast->symbol || ast->symbol->argumentCount() != 0)
|
2015-08-04 15:53:09 +02:00
|
|
|
return false;
|
|
|
|
|
|
2015-10-29 10:20:53 +01:00
|
|
|
CPlusPlus::LookupContext lc;
|
|
|
|
|
const QString prettyName = m_overview.prettyName(lc.fullyQualifiedName(ast->symbol));
|
2015-08-04 15:53:09 +02:00
|
|
|
// do not handle functions that aren't real test data functions
|
2015-10-29 10:20:53 +01:00
|
|
|
if (!prettyName.endsWith(QLatin1String("_data")))
|
2015-08-04 15:53:09 +02:00
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
m_currentFunction = prettyName.left(prettyName.size() - 5);
|
|
|
|
|
m_currentTags.clear();
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2016-04-25 10:44:30 +02:00
|
|
|
QString TestDataFunctionVisitor::extractNameFromAST(CPlusPlus::StringLiteralAST *ast, bool *ok) const
|
|
|
|
|
{
|
|
|
|
|
auto token = m_currentDoc->translationUnit()->tokenAt(ast->literal_token);
|
|
|
|
|
if (!token.isStringLiteral()) {
|
|
|
|
|
*ok = false;
|
|
|
|
|
return QString();
|
|
|
|
|
}
|
|
|
|
|
*ok = true;
|
|
|
|
|
QString name = QString::fromUtf8(token.spell());
|
|
|
|
|
if (ast->next) {
|
|
|
|
|
CPlusPlus::StringLiteralAST *current = ast;
|
|
|
|
|
do {
|
|
|
|
|
auto nextToken = m_currentDoc->translationUnit()->tokenAt(current->next->literal_token);
|
|
|
|
|
name.append(QString::fromUtf8(nextToken.spell()));
|
|
|
|
|
current = current->next;
|
|
|
|
|
} while (current->next);
|
|
|
|
|
}
|
|
|
|
|
return name;
|
|
|
|
|
}
|
|
|
|
|
|
2015-08-04 15:53:09 +02:00
|
|
|
bool TestDataFunctionVisitor::visit(CPlusPlus::CallAST *ast)
|
|
|
|
|
{
|
|
|
|
|
if (m_currentFunction.isEmpty())
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
|
|
unsigned firstToken;
|
|
|
|
|
if (newRowCallFound(ast, &firstToken)) {
|
|
|
|
|
if (const auto expressionListAST = ast->expression_list) {
|
|
|
|
|
// first argument is the one we need
|
|
|
|
|
if (const auto argumentExpressionAST = expressionListAST->value) {
|
|
|
|
|
if (const auto stringLiteral = argumentExpressionAST->asStringLiteral()) {
|
2016-04-25 10:44:30 +02:00
|
|
|
bool ok = false;
|
|
|
|
|
QString name = extractNameFromAST(stringLiteral, &ok);
|
|
|
|
|
if (ok) {
|
2015-08-04 15:53:09 +02:00
|
|
|
unsigned line = 0;
|
|
|
|
|
unsigned column = 0;
|
|
|
|
|
m_currentDoc->translationUnit()->getTokenStartPosition(
|
|
|
|
|
firstToken, &line, &column);
|
|
|
|
|
TestCodeLocationAndType locationAndType;
|
2016-04-25 10:44:30 +02:00
|
|
|
locationAndType.m_name = name;
|
2015-08-04 15:53:09 +02:00
|
|
|
locationAndType.m_column = column - 1;
|
|
|
|
|
locationAndType.m_line = line;
|
2015-12-07 08:26:54 +01:00
|
|
|
locationAndType.m_type = TestTreeItem::TestDataTag;
|
2015-08-04 15:53:09 +02:00
|
|
|
m_currentTags.append(locationAndType);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool TestDataFunctionVisitor::preVisit(CPlusPlus::AST *)
|
|
|
|
|
{
|
|
|
|
|
++m_currentAstDepth;
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void TestDataFunctionVisitor::postVisit(CPlusPlus::AST *ast)
|
|
|
|
|
{
|
|
|
|
|
--m_currentAstDepth;
|
|
|
|
|
m_insideUsingQTest &= m_currentAstDepth >= m_insideUsingQTestDepth;
|
|
|
|
|
|
|
|
|
|
if (!ast->asFunctionDefinition())
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
if (!m_currentFunction.isEmpty() && !m_currentTags.isEmpty())
|
|
|
|
|
m_dataTags.insert(m_currentFunction, m_currentTags);
|
|
|
|
|
|
|
|
|
|
m_currentFunction.clear();
|
|
|
|
|
m_currentTags.clear();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool TestDataFunctionVisitor::newRowCallFound(CPlusPlus::CallAST *ast, unsigned *firstToken) const
|
|
|
|
|
{
|
|
|
|
|
QTC_ASSERT(firstToken, return false);
|
|
|
|
|
|
|
|
|
|
if (!ast->base_expression)
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
bool found = false;
|
|
|
|
|
|
|
|
|
|
if (const CPlusPlus::IdExpressionAST *exp = ast->base_expression->asIdExpression()) {
|
|
|
|
|
if (!exp->name)
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
if (const auto qualifiedNameAST = exp->name->asQualifiedName()) {
|
|
|
|
|
found = m_overview.prettyName(qualifiedNameAST->name) == QLatin1String("QTest::newRow");
|
|
|
|
|
*firstToken = qualifiedNameAST->firstToken();
|
|
|
|
|
} else if (m_insideUsingQTest) {
|
|
|
|
|
found = m_overview.prettyName(exp->name->name) == QLatin1String("newRow");
|
|
|
|
|
*firstToken = exp->name->firstToken();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return found;
|
|
|
|
|
}
|
|
|
|
|
|
2014-11-06 16:01:06 +01:00
|
|
|
/*************************** Quick Test AST Visitor ***************************/
|
|
|
|
|
|
|
|
|
|
TestQmlVisitor::TestQmlVisitor(QmlJS::Document::Ptr doc)
|
|
|
|
|
: m_currentDoc(doc)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TestQmlVisitor::~TestQmlVisitor()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool TestQmlVisitor::visit(QmlJS::AST::UiObjectDefinition *ast)
|
|
|
|
|
{
|
|
|
|
|
const QStringRef name = ast->qualifiedTypeNameId->name;
|
|
|
|
|
if (name != QLatin1String("TestCase"))
|
2014-11-13 12:31:58 +01:00
|
|
|
return true; // find nested TestCase items as well
|
2014-11-06 16:01:06 +01:00
|
|
|
|
|
|
|
|
m_currentTestCaseName.clear();
|
|
|
|
|
const auto sourceLocation = ast->firstSourceLocation();
|
2015-08-04 15:53:09 +02:00
|
|
|
m_testCaseLocation.m_name = m_currentDoc->fileName();
|
2014-11-06 16:01:06 +01:00
|
|
|
m_testCaseLocation.m_line = sourceLocation.startLine;
|
|
|
|
|
m_testCaseLocation.m_column = sourceLocation.startColumn - 1;
|
2016-02-23 15:56:52 +01:00
|
|
|
m_testCaseLocation.m_type = TestTreeItem::TestCase;
|
2014-11-06 16:01:06 +01:00
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool TestQmlVisitor::visit(QmlJS::AST::ExpressionStatement *ast)
|
|
|
|
|
{
|
|
|
|
|
const QmlJS::AST::ExpressionNode *expr = ast->expression;
|
|
|
|
|
return expr->kind == QmlJS::AST::Node::Kind_StringLiteral;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool TestQmlVisitor::visit(QmlJS::AST::UiScriptBinding *ast)
|
|
|
|
|
{
|
|
|
|
|
const QStringRef name = ast->qualifiedId->name;
|
|
|
|
|
return name == QLatin1String("name");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool TestQmlVisitor::visit(QmlJS::AST::FunctionDeclaration *ast)
|
|
|
|
|
{
|
|
|
|
|
const QStringRef name = ast->name;
|
2015-05-19 07:41:39 +02:00
|
|
|
if (name.startsWith(QLatin1String("test_"))
|
|
|
|
|
|| name.startsWith(QLatin1String("benchmark_"))
|
|
|
|
|
|| name.endsWith(QLatin1String("_data"))
|
|
|
|
|
|| specialFunctions.contains(name.toString())) {
|
2014-11-06 16:01:06 +01:00
|
|
|
const auto sourceLocation = ast->firstSourceLocation();
|
2014-11-13 12:31:58 +01:00
|
|
|
TestCodeLocationAndType locationAndType;
|
2015-08-04 15:53:09 +02:00
|
|
|
locationAndType.m_name = m_currentDoc->fileName();
|
2014-11-13 12:31:58 +01:00
|
|
|
locationAndType.m_line = sourceLocation.startLine;
|
|
|
|
|
locationAndType.m_column = sourceLocation.startColumn - 1;
|
2015-05-19 07:41:39 +02:00
|
|
|
if (specialFunctions.contains(name.toString()))
|
2015-12-07 08:26:54 +01:00
|
|
|
locationAndType.m_type = TestTreeItem::TestSpecialFunction;
|
2015-05-19 07:41:39 +02:00
|
|
|
else if (name.endsWith(QLatin1String("_data")))
|
2015-12-07 08:26:54 +01:00
|
|
|
locationAndType.m_type = TestTreeItem::TestDataFunction;
|
2015-05-19 07:41:39 +02:00
|
|
|
else
|
2016-02-23 15:56:52 +01:00
|
|
|
locationAndType.m_type = TestTreeItem::TestFunctionOrSet;
|
2014-11-06 16:01:06 +01:00
|
|
|
|
2014-11-13 12:31:58 +01:00
|
|
|
m_testFunctions.insert(name.toString(), locationAndType);
|
2014-11-06 16:01:06 +01:00
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool TestQmlVisitor::visit(QmlJS::AST::StringLiteral *ast)
|
|
|
|
|
{
|
|
|
|
|
m_currentTestCaseName = ast->value.toString();
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2015-12-07 10:21:50 +01:00
|
|
|
/********************** Google Test Function AST Visitor **********************/
|
|
|
|
|
|
|
|
|
|
GTestVisitor::GTestVisitor(CPlusPlus::Document::Ptr doc)
|
|
|
|
|
: CPlusPlus::ASTVisitor(doc->translationUnit())
|
|
|
|
|
, m_document(doc)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool GTestVisitor::visit(CPlusPlus::FunctionDefinitionAST *ast)
|
|
|
|
|
{
|
2016-01-19 10:50:10 +01:00
|
|
|
static QString disabledPrefix = QString::fromLatin1("DISABLED_");
|
2015-12-07 10:21:50 +01:00
|
|
|
if (!ast || !ast->declarator || !ast->declarator->core_declarator)
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
CPlusPlus::DeclaratorIdAST *id = ast->declarator->core_declarator->asDeclaratorId();
|
|
|
|
|
if (!id || !ast->symbol || ast->symbol->argumentCount() != 2)
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
CPlusPlus::LookupContext lc;
|
|
|
|
|
const QString prettyName = m_overview.prettyName(lc.fullyQualifiedName(ast->symbol));
|
2016-01-05 14:05:23 +01:00
|
|
|
if (!TestUtils::isGTestMacro(prettyName))
|
2015-12-07 10:21:50 +01:00
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
CPlusPlus::Argument *testCaseNameArg = ast->symbol->argumentAt(0)->asArgument();
|
|
|
|
|
CPlusPlus::Argument *testNameArg = ast->symbol->argumentAt(1)->asArgument();
|
|
|
|
|
if (testCaseNameArg && testNameArg) {
|
|
|
|
|
const QString &testCaseName = m_overview.prettyType(testCaseNameArg->type());
|
|
|
|
|
const QString &testName = m_overview.prettyType(testNameArg->type());
|
|
|
|
|
|
2016-01-19 10:50:10 +01:00
|
|
|
const bool disabled = testName.startsWith(disabledPrefix);
|
|
|
|
|
const bool disabledCase = testCaseName.startsWith(disabledPrefix);
|
2015-12-07 10:21:50 +01:00
|
|
|
unsigned line = 0;
|
|
|
|
|
unsigned column = 0;
|
|
|
|
|
unsigned token = id->firstToken();
|
|
|
|
|
m_document->translationUnit()->getTokenStartPosition(token, &line, &column);
|
|
|
|
|
|
2016-05-03 17:05:11 +02:00
|
|
|
GTestCodeLocationAndType locationAndType;
|
2016-02-23 17:40:10 +01:00
|
|
|
locationAndType.m_name = testName;
|
2015-12-07 10:21:50 +01:00
|
|
|
locationAndType.m_line = line;
|
|
|
|
|
locationAndType.m_column = column - 1;
|
2016-02-23 15:56:52 +01:00
|
|
|
locationAndType.m_type = TestTreeItem::TestFunctionOrSet;
|
2016-02-23 17:40:10 +01:00
|
|
|
locationAndType.m_state = disabled ? GoogleTestTreeItem::Disabled
|
|
|
|
|
: GoogleTestTreeItem::Enabled;
|
2016-01-12 16:45:20 +01:00
|
|
|
GTestCaseSpec spec;
|
2016-02-23 17:40:10 +01:00
|
|
|
spec.testCaseName = testCaseName;
|
2016-01-12 16:45:20 +01:00
|
|
|
spec.parameterized = TestUtils::isGTestParameterized(prettyName);
|
2016-02-22 11:23:53 +01:00
|
|
|
spec.typed = TestUtils::isGTestTyped(prettyName);
|
2016-02-23 17:40:10 +01:00
|
|
|
spec.disabled = disabledCase;
|
2016-01-12 16:45:20 +01:00
|
|
|
m_gtestFunctions[spec].append(locationAndType);
|
2015-12-07 10:21:50 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2014-10-07 12:30:54 +02:00
|
|
|
} // namespace Internal
|
|
|
|
|
} // namespace Autotest
|