Commit dd7a080e authored by Christian Stenger's avatar Christian Stenger Committed by Christian Stenger

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's avatarNikolai Kosjar <nikolai.kosjar@qt.io>
parent a14e7db1
......@@ -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;
......
......@@ -95,6 +95,7 @@ public:
QMap<QString, TestCodeLocationList> 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;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment