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
|
|
|
|
2020-06-26 13:59:38 +02:00
|
|
|
#include <utils/id.h>
|
2017-10-25 13:08:16 +02:00
|
|
|
|
2019-05-24 10:12:43 +02:00
|
|
|
#include <QRegularExpression>
|
|
|
|
|
|
2016-05-11 13:02:42 +02:00
|
|
|
namespace Autotest {
|
|
|
|
|
namespace Internal {
|
|
|
|
|
|
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()) {
|
2019-02-06 14:11:19 +01:00
|
|
|
case ResultType::Pass:
|
|
|
|
|
case ResultType::Fail:
|
2019-05-24 07:17:50 +02:00
|
|
|
output = m_testCaseName;
|
2016-05-11 13:02:42 +02:00
|
|
|
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);
|
2019-05-24 07:17:50 +02:00
|
|
|
if (m_testCaseName == gtOther->m_testCaseName) {
|
2019-02-06 14:11:19 +01:00
|
|
|
const ResultType otherResult = other->result();
|
|
|
|
|
if (otherResult == ResultType::MessageInternal || otherResult == ResultType::MessageLocation)
|
|
|
|
|
return result() != ResultType::MessageInternal && result() != ResultType::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;
|
2019-05-24 07:17:50 +02:00
|
|
|
return isTestSuite() && gtOther->isTestCase();
|
2016-10-31 13:11:52 +01:00
|
|
|
}
|
|
|
|
|
|
2017-09-09 16:46:43 +02:00
|
|
|
static QString normalizeName(const QString &name)
|
|
|
|
|
{
|
2019-05-24 10:12:43 +02:00
|
|
|
static QRegularExpression parameterIndex("/\\d+");
|
2017-09-09 16:46:43 +02:00
|
|
|
|
|
|
|
|
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
|
|
|
|
|
{
|
2020-06-26 13:59:38 +02:00
|
|
|
auto id = Utils::Id(Constants::FRAMEWORK_PREFIX).withSuffix(GTest::Constants::FRAMEWORK_NAME);
|
2020-03-13 13:54:33 +01:00
|
|
|
ITestFramework *framework = TestFrameworkManager::frameworkForId(id);
|
|
|
|
|
QTC_ASSERT(framework, return nullptr);
|
|
|
|
|
const TestTreeItem *rootNode = framework->rootNode();
|
2017-10-25 13:08:16 +02:00
|
|
|
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;
|
|
|
|
|
|
2019-05-24 07:17:50 +02:00
|
|
|
if (isTestSuite())
|
|
|
|
|
return matchesTestSuite(treeItem);
|
2017-09-09 16:46:43 +02:00
|
|
|
|
2019-05-24 07:17:50 +02:00
|
|
|
return matchesTestCase(treeItem);
|
2017-09-09 16:46:43 +02:00
|
|
|
}
|
|
|
|
|
|
2019-05-24 07:17:50 +02:00
|
|
|
bool GTestResult::matchesTestCase(const TestTreeItem *treeItem) const
|
2017-09-09 16:46:43 +02:00
|
|
|
{
|
2019-05-21 07:50:34 +02:00
|
|
|
if (treeItem->type() != TestTreeItem::TestCase)
|
2017-09-09 16:46:43 +02:00
|
|
|
return false;
|
|
|
|
|
|
2019-05-24 07:17:50 +02:00
|
|
|
const QString testItemTestCase = treeItem->parentItem()->name() + '.' + treeItem->name();
|
|
|
|
|
return testItemTestCase == normalizeName(m_testCaseName);
|
2017-09-09 16:46:43 +02:00
|
|
|
}
|
|
|
|
|
|
2019-05-24 07:17:50 +02:00
|
|
|
bool GTestResult::matchesTestSuite(const TestTreeItem *treeItem) const
|
2017-09-09 16:46:43 +02:00
|
|
|
{
|
2019-05-21 07:50:34 +02:00
|
|
|
if (treeItem->type() != TestTreeItem::TestSuite)
|
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
|