2016-05-11 13:02:42 +02:00
|
|
|
/****************************************************************************
|
|
|
|
|
**
|
|
|
|
|
** Copyright (C) 2016 The Qt Company Ltd.
|
|
|
|
|
** Contact: https://www.qt.io/licensing/
|
|
|
|
|
**
|
|
|
|
|
** This file is part of Qt Creator.
|
|
|
|
|
**
|
|
|
|
|
** Commercial License Usage
|
|
|
|
|
** Licensees holding valid commercial Qt licenses may use this file in
|
|
|
|
|
** accordance with the commercial license agreement provided with the
|
|
|
|
|
** Software or, alternatively, in accordance with the terms contained in
|
|
|
|
|
** 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.
|
|
|
|
|
**
|
|
|
|
|
** 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.
|
|
|
|
|
**
|
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
|
|
#include "gtestresult.h"
|
2017-10-25 13:08:16 +02:00
|
|
|
#include "gtestconstants.h"
|
|
|
|
|
#include "../testframeworkmanager.h"
|
2017-09-09 16:46:43 +02:00
|
|
|
#include "../testtreeitem.h"
|
2016-05-11 13:02:42 +02:00
|
|
|
|
2017-10-25 13:08:16 +02:00
|
|
|
#include <coreplugin/id.h>
|
|
|
|
|
|
2016-05-11 13:02:42 +02:00
|
|
|
namespace Autotest {
|
|
|
|
|
namespace Internal {
|
|
|
|
|
|
2017-09-09 16:46:43 +02:00
|
|
|
GTestResult::GTestResult(const QString &projectFile, const QString &name)
|
|
|
|
|
: TestResult(name), m_projectFile(projectFile)
|
2016-05-11 13:02:42 +02:00
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2018-05-09 10:48:23 +02:00
|
|
|
GTestResult::GTestResult(const QString &id, const QString &projectFile,
|
2017-09-09 16:46:43 +02:00
|
|
|
const QString &name)
|
2018-05-09 10:48:23 +02:00
|
|
|
: TestResult(id, name), m_projectFile(projectFile)
|
2017-06-27 15:15:43 +02:00
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2016-05-11 13:02:42 +02:00
|
|
|
const QString GTestResult::outputString(bool selected) const
|
|
|
|
|
{
|
|
|
|
|
const QString &desc = description();
|
|
|
|
|
QString output;
|
|
|
|
|
switch (result()) {
|
|
|
|
|
case Result::Pass:
|
|
|
|
|
case Result::Fail:
|
|
|
|
|
output = m_testSetName;
|
|
|
|
|
if (selected && !desc.isEmpty())
|
2016-09-29 12:15:43 +02:00
|
|
|
output.append('\n').append(desc);
|
2016-05-11 13:02:42 +02:00
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
output = desc;
|
|
|
|
|
if (!selected)
|
2016-09-29 12:15:43 +02:00
|
|
|
output = output.split('\n').first();
|
2016-05-11 13:02:42 +02:00
|
|
|
}
|
|
|
|
|
return output;
|
|
|
|
|
}
|
|
|
|
|
|
2016-10-31 13:11:52 +01:00
|
|
|
bool GTestResult::isDirectParentOf(const TestResult *other, bool *needsIntermediate) const
|
|
|
|
|
{
|
|
|
|
|
if (!TestResult::isDirectParentOf(other, needsIntermediate))
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
const GTestResult *gtOther = static_cast<const GTestResult *>(other);
|
2018-08-18 21:48:34 +03:00
|
|
|
if (m_testSetName == gtOther->m_testSetName) {
|
|
|
|
|
const Result::Type otherResult = other->result();
|
|
|
|
|
if (otherResult == Result::MessageInternal || otherResult == Result::MessageLocation)
|
2019-04-04 13:31:06 +02:00
|
|
|
return result() != Result::MessageInternal && result() != Result::MessageLocation;
|
2018-08-18 21:48:34 +03:00
|
|
|
}
|
2016-12-14 13:30:33 +01:00
|
|
|
if (m_iteration != gtOther->m_iteration)
|
|
|
|
|
return false;
|
2016-10-31 13:11:52 +01:00
|
|
|
return isTest() && gtOther->isTestSet();
|
|
|
|
|
}
|
|
|
|
|
|
2017-09-09 16:46:43 +02:00
|
|
|
static QString normalizeName(const QString &name)
|
|
|
|
|
{
|
|
|
|
|
static QRegExp parameterIndex("/\\d+");
|
|
|
|
|
|
|
|
|
|
QString nameWithoutParameterIndices = name;
|
|
|
|
|
nameWithoutParameterIndices.remove(parameterIndex);
|
|
|
|
|
|
|
|
|
|
return nameWithoutParameterIndices.split('/').last();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static QString normalizeTestName(const QString &testname)
|
|
|
|
|
{
|
|
|
|
|
QString nameWithoutTypeParam = testname.split(',').first();
|
|
|
|
|
|
|
|
|
|
return normalizeName(nameWithoutTypeParam);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const TestTreeItem *GTestResult::findTestTreeItem() const
|
|
|
|
|
{
|
2017-10-25 13:08:16 +02:00
|
|
|
auto id = Core::Id(Constants::FRAMEWORK_PREFIX).withSuffix(GTest::Constants::FRAMEWORK_NAME);
|
|
|
|
|
const TestTreeItem *rootNode = TestFrameworkManager::instance()->rootNodeForTestFramework(id);
|
|
|
|
|
if (!rootNode)
|
|
|
|
|
return nullptr;
|
|
|
|
|
|
|
|
|
|
const auto item = rootNode->findAnyChild([this](const Utils::TreeItem *item) {
|
|
|
|
|
const auto treeItem = static_cast<const TestTreeItem *>(item);
|
|
|
|
|
return treeItem && matches(treeItem);
|
2017-09-09 16:46:43 +02:00
|
|
|
});
|
|
|
|
|
return static_cast<const TestTreeItem *>(item);
|
|
|
|
|
}
|
|
|
|
|
|
2017-10-25 13:08:16 +02:00
|
|
|
bool GTestResult::matches(const TestTreeItem *treeItem) const
|
2017-09-09 16:46:43 +02:00
|
|
|
{
|
2017-10-25 13:08:16 +02:00
|
|
|
if (treeItem->proFile() != m_projectFile)
|
2017-09-09 16:46:43 +02:00
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
if (isTest())
|
|
|
|
|
return matchesTestCase(treeItem);
|
|
|
|
|
|
|
|
|
|
return matchesTestFunctionOrSet(treeItem);
|
|
|
|
|
}
|
|
|
|
|
|
2017-10-25 13:08:16 +02:00
|
|
|
bool GTestResult::matchesTestFunctionOrSet(const TestTreeItem *treeItem) const
|
2017-09-09 16:46:43 +02:00
|
|
|
{
|
2017-10-25 13:08:16 +02:00
|
|
|
if (treeItem->type() != TestTreeItem::TestFunctionOrSet)
|
2017-09-09 16:46:43 +02:00
|
|
|
return false;
|
|
|
|
|
|
2017-10-25 13:08:16 +02:00
|
|
|
const QString testItemTestSet = treeItem->parentItem()->name() + '.' + treeItem->name();
|
2017-09-09 16:46:43 +02:00
|
|
|
return testItemTestSet == normalizeName(m_testSetName);
|
|
|
|
|
}
|
|
|
|
|
|
2017-10-25 13:08:16 +02:00
|
|
|
bool GTestResult::matchesTestCase(const TestTreeItem *treeItem) const
|
2017-09-09 16:46:43 +02:00
|
|
|
{
|
2017-10-25 13:08:16 +02:00
|
|
|
if (treeItem->type() != TestTreeItem::TestCase)
|
2017-09-09 16:46:43 +02:00
|
|
|
return false;
|
|
|
|
|
|
2017-10-25 13:08:16 +02:00
|
|
|
return treeItem->name() == normalizeTestName(name());
|
2017-09-09 16:46:43 +02:00
|
|
|
}
|
|
|
|
|
|
2016-05-11 13:02:42 +02:00
|
|
|
} // namespace Internal
|
|
|
|
|
} // namespace Autotest
|