From dd7a080eb1a1045e2b26b853c92e6fc4416243fc Mon Sep 17 00:00:00 2001 From: Christian Stenger Date: Mon, 25 Apr 2016 10:44:30 +0200 Subject: [PATCH] AutoTest: Fix parsing of more complicated newRow() calls If the name for the test row consists of more than a single string literal we only used the first part. In turn this test data could not get executed explicitly. Change-Id: I442c9058e036323cf1a21c21f200fcbfcf916fd8 Reviewed-by: Nikolai Kosjar --- src/plugins/autotest/testvisitor.cpp | 28 ++++++++++++++++++++++++---- src/plugins/autotest/testvisitor.h | 1 + 2 files changed, 25 insertions(+), 4 deletions(-) diff --git a/src/plugins/autotest/testvisitor.cpp b/src/plugins/autotest/testvisitor.cpp index d766cc0fdc5..d9f7b37a820 100644 --- a/src/plugins/autotest/testvisitor.cpp +++ b/src/plugins/autotest/testvisitor.cpp @@ -203,6 +203,26 @@ bool TestDataFunctionVisitor::visit(CPlusPlus::FunctionDefinitionAST *ast) return false; } +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; +} + bool TestDataFunctionVisitor::visit(CPlusPlus::CallAST *ast) { if (m_currentFunction.isEmpty()) @@ -214,15 +234,15 @@ bool TestDataFunctionVisitor::visit(CPlusPlus::CallAST *ast) // first argument is the one we need if (const auto argumentExpressionAST = expressionListAST->value) { if (const auto stringLiteral = argumentExpressionAST->asStringLiteral()) { - auto token = m_currentDoc->translationUnit()->tokenAt( - stringLiteral->literal_token); - if (token.isStringLiteral()) { + bool ok = false; + QString name = extractNameFromAST(stringLiteral, &ok); + if (ok) { unsigned line = 0; unsigned column = 0; m_currentDoc->translationUnit()->getTokenStartPosition( firstToken, &line, &column); TestCodeLocationAndType locationAndType; - locationAndType.m_name = QString::fromUtf8(token.spell()); + locationAndType.m_name = name; locationAndType.m_column = column - 1; locationAndType.m_line = line; locationAndType.m_type = TestTreeItem::TestDataTag; diff --git a/src/plugins/autotest/testvisitor.h b/src/plugins/autotest/testvisitor.h index b849a1d8c5f..2c88ebe9e1c 100644 --- a/src/plugins/autotest/testvisitor.h +++ b/src/plugins/autotest/testvisitor.h @@ -95,6 +95,7 @@ public: QMap dataTags() const { return m_dataTags; } private: + QString extractNameFromAST(CPlusPlus::StringLiteralAST *ast, bool *ok) const; bool newRowCallFound(CPlusPlus::CallAST *ast, unsigned *firstToken) const; CPlusPlus::Document::Ptr m_currentDoc;