forked from qt-creator/qt-creator
Provide parameterized gtest for plugin unit tests
Change-Id: I17a42a9070546a5b461fcb27643bd6db7b5d7b4f Reviewed-by: Niels Weber <niels.weber@theqtcompany.com>
This commit is contained in:
committed by
Niels Weber
parent
02281ad429
commit
9055ac5f50
@@ -205,19 +205,22 @@ void AutoTestUnitTests::testCodeParserGTest()
|
||||
QSignalSpy parserSpy(m_model->parser(), SIGNAL(parsingFinished()));
|
||||
QVERIFY(parserSpy.wait(20000));
|
||||
|
||||
QCOMPARE(m_model->gtestNamesCount(), 4);
|
||||
QCOMPARE(m_model->parser()->gtestNamesAndSetsCount(), 9); // 9 == 3 + 2 + 2 + 2, see below
|
||||
QCOMPARE(m_model->gtestNamesCount(), 6);
|
||||
// 11 == 3 + 2 + 2 + 2 + 1 + 1, see below
|
||||
QCOMPARE(m_model->parser()->gtestNamesAndSetsCount(), 11);
|
||||
|
||||
QMap<QString, int> expectedNamesAndSets;
|
||||
QMultiMap<QString, int> expectedNamesAndSets;
|
||||
expectedNamesAndSets.insert(QStringLiteral("FactorialTest"), 3);
|
||||
expectedNamesAndSets.insert(QStringLiteral("FactorialTest_Iterative"), 2);
|
||||
expectedNamesAndSets.insert(QStringLiteral("Sum"), 2);
|
||||
expectedNamesAndSets.insert(QStringLiteral("QueueTest"), 2);
|
||||
expectedNamesAndSets.insert(QStringLiteral("DummyTest"), 1); // used as parameterized test
|
||||
expectedNamesAndSets.insert(QStringLiteral("DummyTest"), 1); // used as 'normal' test
|
||||
|
||||
QMap<QString, int> foundNamesAndSets = m_model->gtestNamesAndSets();
|
||||
QMultiMap<QString, int> foundNamesAndSets = m_model->gtestNamesAndSets();
|
||||
QCOMPARE(expectedNamesAndSets.size(), foundNamesAndSets.size());
|
||||
foreach (const QString &name, expectedNamesAndSets.keys())
|
||||
QCOMPARE(expectedNamesAndSets.value(name), foundNamesAndSets.value(name));
|
||||
QCOMPARE(expectedNamesAndSets.values(name), foundNamesAndSets.values(name));
|
||||
|
||||
// check also that no Qt related tests have been found
|
||||
QCOMPARE(m_model->autoTestsCount(), 0);
|
||||
|
@@ -50,5 +50,8 @@
|
||||
<file>unit_test/simple_gt/tests/tests.pro</file>
|
||||
<file>unit_test/simple_gt/simple_gt.pro</file>
|
||||
<file>unit_test/simple_gt/tests/gtest_dependency.pri</file>
|
||||
<file>unit_test/simple_gt/tests/gt3/dummytest.h</file>
|
||||
<file>unit_test/simple_gt/tests/gt3/gt3.pro</file>
|
||||
<file>unit_test/simple_gt/tests/gt3/main.cpp</file>
|
||||
</qresource>
|
||||
</RCC>
|
||||
|
@@ -824,9 +824,9 @@ int TestTreeModel::gtestNamesCount() const
|
||||
return m_googleTestRootItem ? m_googleTestRootItem->childCount() : 0;
|
||||
}
|
||||
|
||||
QMap<QString, int> TestTreeModel::gtestNamesAndSets() const
|
||||
QMultiMap<QString, int> TestTreeModel::gtestNamesAndSets() const
|
||||
{
|
||||
QMap<QString, int> result;
|
||||
QMultiMap<QString, int> result;
|
||||
|
||||
if (m_googleTestRootItem) {
|
||||
for (int row = 0, count = m_googleTestRootItem->childCount(); row < count; ++row) {
|
||||
|
@@ -70,7 +70,7 @@ public:
|
||||
int unnamedQuickTestsCount() const;
|
||||
int dataTagsCount() const;
|
||||
int gtestNamesCount() const;
|
||||
QMap<QString, int> gtestNamesAndSets() const;
|
||||
QMultiMap<QString, int> gtestNamesAndSets() const;
|
||||
#endif
|
||||
|
||||
signals:
|
||||
|
37
plugins/autotest/unit_test/simple_gt/tests/gt3/dummytest.h
Normal file
37
plugins/autotest/unit_test/simple_gt/tests/gt3/dummytest.h
Normal file
@@ -0,0 +1,37 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** Copyright (C) 2015 The Qt Company Ltd
|
||||
** All rights reserved.
|
||||
** For any questions to The Qt Company, please use contact form at
|
||||
** http://www.qt.io/contact-us
|
||||
**
|
||||
** This file is part of the Qt Creator Enterprise Auto Test Add-on.
|
||||
**
|
||||
** Licensees holding valid Qt Enterprise licenses may use this file in
|
||||
** accordance with the Qt Enterprise License Agreement provided with the
|
||||
** Software or, alternatively, in accordance with the terms contained in
|
||||
** a written agreement between you and The Qt Company.
|
||||
**
|
||||
** If you have questions regarding the use of this file, please use
|
||||
** contact form at http://www.qt.io/contact-us
|
||||
**
|
||||
****************************************************************************/
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
#include <QString>
|
||||
|
||||
class DummyTest : public ::testing::TestWithParam<const char *>
|
||||
{
|
||||
protected:
|
||||
virtual void SetUp() {
|
||||
m_str1 = QString::fromLatin1(GetParam()).toLower();
|
||||
|
||||
m_str2 = QString::fromLatin1(GetParam()).toUpper();
|
||||
|
||||
m_str3 = QString::fromLatin1(GetParam()).toHtmlEscaped();
|
||||
}
|
||||
|
||||
QString m_str1;
|
||||
QString m_str2;
|
||||
QString m_str3;
|
||||
};
|
12
plugins/autotest/unit_test/simple_gt/tests/gt3/gt3.pro
Normal file
12
plugins/autotest/unit_test/simple_gt/tests/gt3/gt3.pro
Normal file
@@ -0,0 +1,12 @@
|
||||
include(../gtest_dependency.pri)
|
||||
|
||||
TEMPLATE = app
|
||||
CONFIG += qt console c++11
|
||||
CONFIG -= app_bundle
|
||||
|
||||
HEADERS += \
|
||||
dummytest.h
|
||||
|
||||
SOURCES += \
|
||||
main.cpp
|
||||
|
85
plugins/autotest/unit_test/simple_gt/tests/gt3/main.cpp
Normal file
85
plugins/autotest/unit_test/simple_gt/tests/gt3/main.cpp
Normal file
@@ -0,0 +1,85 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** Copyright (C) 2015 The Qt Company Ltd
|
||||
** All rights reserved.
|
||||
** For any questions to The Qt Company, please use contact form at
|
||||
** http://www.qt.io/contact-us
|
||||
**
|
||||
** This file is part of the Qt Creator Enterprise Auto Test Add-on.
|
||||
**
|
||||
** Licensees holding valid Qt Enterprise licenses may use this file in
|
||||
** accordance with the Qt Enterprise License Agreement provided with the
|
||||
** Software or, alternatively, in accordance with the terms contained in
|
||||
** a written agreement between you and The Qt Company.
|
||||
**
|
||||
** If you have questions regarding the use of this file, please use
|
||||
** contact form at http://www.qt.io/contact-us
|
||||
**
|
||||
****************************************************************************/
|
||||
#include <gtest/gtest.h>
|
||||
#include <gmock/gmock-matchers.h>
|
||||
|
||||
#include "dummytest.h"
|
||||
|
||||
using namespace testing;
|
||||
|
||||
#include <QMap>
|
||||
#include <QStringList>
|
||||
|
||||
static QMap<const char *, QStringList> testValues = {
|
||||
{ "DummyTest",
|
||||
{QStringLiteral("dummytest"), QStringLiteral("DUMMYTEST"), QStringLiteral("DummyTest")}
|
||||
},
|
||||
{ "Hello World",
|
||||
{QStringLiteral("hello world"), QStringLiteral("HELLO WORLD"), QStringLiteral("Hello World")}
|
||||
},
|
||||
{ "#include <QString>\n#include \"test.h\"",
|
||||
{QStringLiteral("#include <qstring>\n#include \"test.h\""),
|
||||
QStringLiteral("#INCLUDE <QSTRING>\n#INCLUDE \"TEST.H\""),
|
||||
QStringLiteral("#include <QString>\n#include "test.h"")
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
static QMap<const char *, QStringList> testValuesSec = {
|
||||
{ "BlAh",
|
||||
{QStringLiteral("blah"), QStringLiteral("BLAH"), QStringLiteral("BlAh")}
|
||||
},
|
||||
{ "<html>",
|
||||
{QStringLiteral("<html>"), QStringLiteral("<HTML>"), QStringLiteral("<html>")}
|
||||
},
|
||||
};
|
||||
|
||||
INSTANTIATE_TEST_CASE_P(First, DummyTest, ::testing::ValuesIn(testValues.keys()));
|
||||
INSTANTIATE_TEST_CASE_P(Second, DummyTest, ::testing::ValuesIn(testValuesSec.keys()));
|
||||
|
||||
TEST_P(DummyTest, Easy)
|
||||
{
|
||||
// total wrong usage, but this is for testing purpose
|
||||
bool first = testValues.contains(GetParam());
|
||||
bool second = testValuesSec.contains(GetParam());
|
||||
QStringList expected;
|
||||
if (first)
|
||||
expected = testValues.value(GetParam());
|
||||
else if (second)
|
||||
expected = testValuesSec.value(GetParam());
|
||||
else
|
||||
FAIL();
|
||||
|
||||
ASSERT_EQ(3, expected.size());
|
||||
|
||||
EXPECT_EQ(m_str1, expected.at(0));
|
||||
EXPECT_EQ(m_str2, expected.at(1));
|
||||
EXPECT_EQ(m_str3, expected.at(2));
|
||||
}
|
||||
|
||||
TEST(DummyTest, BlaBlubb)
|
||||
{
|
||||
ASSERT_EQ(3, testValues.size());
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
InitGoogleTest(&argc, argv);
|
||||
return RUN_ALL_TESTS();
|
||||
}
|
@@ -1,4 +1,5 @@
|
||||
TEMPLATE = subdirs
|
||||
|
||||
SUBDIRS += gt1 \
|
||||
gt2
|
||||
gt2 \
|
||||
gt3
|
||||
|
Reference in New Issue
Block a user