Add basic support for gtest

This patch provides the basics for detecting the googletest related
code.

Change-Id: I34da3e02596cdc0805f79633ecf2176807390fc1
Reviewed-by: Nikolai Kosjar <nikolai.kosjar@theqtcompany.com>
This commit is contained in:
Christian Stenger
2015-12-07 10:21:50 +01:00
parent e72cfeefba
commit 42def5bb05
8 changed files with 170 additions and 1 deletions

View File

@@ -17,6 +17,7 @@
**
****************************************************************************/
#include "autotest_utils.h"
#include "testvisitor.h"
#include <cplusplus/FullySpecifiedType.h>
@@ -339,5 +340,51 @@ bool TestQmlVisitor::visit(QmlJS::AST::StringLiteral *ast)
return false;
}
/********************** Google Test Function AST Visitor **********************/
GTestVisitor::GTestVisitor(CPlusPlus::Document::Ptr doc)
: CPlusPlus::ASTVisitor(doc->translationUnit())
, m_document(doc)
{
}
bool GTestVisitor::visit(CPlusPlus::FunctionDefinitionAST *ast)
{
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));
if (!AutoTest::Internal::isGTestMacro(prettyName))
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());
bool disabled = testName.startsWith(QLatin1String("DISABLED_"));
unsigned line = 0;
unsigned column = 0;
unsigned token = id->firstToken();
m_document->translationUnit()->getTokenStartPosition(token, &line, &column);
TestCodeLocationAndType locationAndType;
locationAndType.m_name = disabled ? testName.mid(9) : testName;
locationAndType.m_line = line;
locationAndType.m_column = column - 1;
locationAndType.m_type = disabled ? TestTreeItem::GTestNameDisabled
: TestTreeItem::GTestName;
m_gtestFunctions[testCaseName].append(locationAndType);
}
return false;
}
} // namespace Internal
} // namespace Autotest