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;