diff options
author | Christian Stenger <[email protected]> | 2019-05-21 13:39:00 +0200 |
---|---|---|
committer | Christian Stenger <[email protected]> | 2019-05-24 06:27:22 +0000 |
commit | b86c05b96ac4e4d7b8af54035fb9350b7bd89142 (patch) | |
tree | f6dd7a1bf5b25c9ee428d990ea4fd85b9d7da90c | |
parent | 5c6eb0a2bac1cf644cbccf200fc547668e0079ca (diff) |
AutoTest: Add unit test for parsing boost tests
To execute them you need - beside the former prerequisites -
either have boost installed installed at system level (UNIX)
or you must specify BOOST_INCLUDE_DIR as environment variable
otherwise the respective test will be skipped.
Change-Id: I6bd8472e554132ab05e58b56e3ccbd5e9dffada9
Reviewed-by: David Schulz <[email protected]>
22 files changed, 306 insertions, 9 deletions
diff --git a/src/plugins/autotest/autotestunittests.cpp b/src/plugins/autotest/autotestunittests.cpp index 2b8624a8346..eeeeb599de3 100644 --- a/src/plugins/autotest/autotestunittests.cpp +++ b/src/plugins/autotest/autotestunittests.cpp @@ -39,6 +39,7 @@ #include <projectexplorer/projectexplorer.h> #include <projectexplorer/toolchain.h> +#include <QFileInfo> #include <QSignalSpy> #include <QTest> @@ -53,9 +54,7 @@ namespace Internal { AutoTestUnitTests::AutoTestUnitTests(TestTreeModel *model, QObject *parent) : QObject(parent), - m_model(model), - m_tmpDir(nullptr), - m_isQt4(false) + m_model(model) { } @@ -74,6 +73,16 @@ void AutoTestUnitTests::initTestCase() QSKIP("This test requires that there is a kit with a toolchain."); m_tmpDir = new CppTools::Tests::TemporaryCopiedDir(":/unit_test"); + + if (!qgetenv("BOOST_INCLUDE_DIR").isEmpty()) { + m_checkBoost = true; + } else { + if (QFileInfo::exists("/usr/include/boost/version.hpp") + || QFileInfo::exists("/usr/local/include/boost/version.hpp")) { + qDebug() << "Found boost at system level - will run boost parser test."; + m_checkBoost = true; + } + } } void AutoTestUnitTests::cleanupTestCase() @@ -218,6 +227,7 @@ void AutoTestUnitTests::testCodeParserGTest() QCOMPARE(m_model->namedQuickTestsCount(), 0); QCOMPARE(m_model->unnamedQuickTestsCount(), 0); QCOMPARE(m_model->dataTagsCount(), 0); + QCOMPARE(m_model->boostTestNamesCount(), 0); } void AutoTestUnitTests::testCodeParserGTest_data() @@ -229,5 +239,51 @@ void AutoTestUnitTests::testCodeParserGTest_data() << QString(m_tmpDir->path() + "/simple_gt/simple_gt.qbs"); } +void AutoTestUnitTests::testCodeParserBoostTest() +{ + if (!m_checkBoost) + QSKIP("This test needs boost - set BOOST_INCLUDE_DIR (or have it installed)"); + + QFETCH(QString, projectFilePath); + CppTools::Tests::ProjectOpenerAndCloser projectManager; + CppTools::ProjectInfo projectInfo = projectManager.open(projectFilePath, true); + QVERIFY(projectInfo.isValid()); + + QSignalSpy parserSpy(m_model->parser(), SIGNAL(parsingFinished())); + QSignalSpy modelUpdateSpy(m_model, SIGNAL(sweepingDone())); + QVERIFY(parserSpy.wait(20000)); + QVERIFY(modelUpdateSpy.wait()); + + QCOMPARE(m_model->boostTestNamesCount(), 5); + + QMultiMap<QString, int> expectedSuitesAndTests; + expectedSuitesAndTests.insert(QStringLiteral("Master Test Suite"), 2); // decorators w/o suite + expectedSuitesAndTests.insert(QStringLiteral("Master Test Suite"), 2); // fixtures + expectedSuitesAndTests.insert(QStringLiteral("Master Test Suite"), 3); // functions + expectedSuitesAndTests.insert(QStringLiteral("Suite1"), 4); + expectedSuitesAndTests.insert(QStringLiteral("SuiteOuter"), 5); // 2 sub suites + 3 tests + + QMultiMap<QString, int> foundNamesAndSets = m_model->boostTestSuitesAndTests(); + QCOMPARE(expectedSuitesAndTests.size(), foundNamesAndSets.size()); + for (const QString &name : expectedSuitesAndTests.keys()) + QCOMPARE(expectedSuitesAndTests.values(name), foundNamesAndSets.values(name)); + + // check also that no Qt related tests have been found + QCOMPARE(m_model->autoTestsCount(), 0); + QCOMPARE(m_model->namedQuickTestsCount(), 0); + QCOMPARE(m_model->unnamedQuickTestsCount(), 0); + QCOMPARE(m_model->dataTagsCount(), 0); + QCOMPARE(m_model->gtestNamesCount(), 0); +} + +void AutoTestUnitTests::testCodeParserBoostTest_data() +{ + QTest::addColumn<QString>("projectFilePath"); + QTest::newRow("simpleBoostTest") + << QString(m_tmpDir->path() + "/simple_boost/simple_boost.pro"); + QTest::newRow("simpleBoostTestQbs") + << QString(m_tmpDir->path() + "/simple_boost/simple_boost.qbs"); +} + } // namespace Internal } // namespace Autotest diff --git a/src/plugins/autotest/autotestunittests.h b/src/plugins/autotest/autotestunittests.h index 1d0e0b397b7..3b464fc709e 100644 --- a/src/plugins/autotest/autotestunittests.h +++ b/src/plugins/autotest/autotestunittests.h @@ -51,11 +51,14 @@ private slots: void testCodeParserSwitchStartup_data(); void testCodeParserGTest(); void testCodeParserGTest_data(); + void testCodeParserBoostTest(); + void testCodeParserBoostTest_data(); private: - TestTreeModel *m_model; - CppTools::Tests::TemporaryCopiedDir *m_tmpDir; - bool m_isQt4; + TestTreeModel *m_model = nullptr; + CppTools::Tests::TemporaryCopiedDir *m_tmpDir = nullptr; + bool m_isQt4 = false; + bool m_checkBoost = false; }; } // namespace Internal diff --git a/src/plugins/autotest/autotestunittests.qrc b/src/plugins/autotest/autotestunittests.qrc index 68285166cd4..13db89f567a 100644 --- a/src/plugins/autotest/autotestunittests.qrc +++ b/src/plugins/autotest/autotestunittests.qrc @@ -72,5 +72,22 @@ <file>unit_test/mixed_atp/tests/auto/quickauto3/quickauto3.qbs</file> <file>unit_test/mixed_atp/tests/auto/quickauto3/tst_test1.qml</file> <file>unit_test/mixed_atp/tests/auto/quickauto3/tst_test2.qml</file> + <file>unit_test/simple_boost/simple_boost.pro</file> + <file>unit_test/simple_boost/simple_boost.qbs</file> + <file>unit_test/simple_boost/src/main.cpp</file> + <file>unit_test/simple_boost/src/src.pro</file> + <file>unit_test/simple_boost/src/src.qbs</file> + <file>unit_test/simple_boost/tests/tests.pro</file> + <file>unit_test/simple_boost/tests/tests.qbs</file> + <file>unit_test/simple_boost/tests/deco/deco.pro</file> + <file>unit_test/simple_boost/tests/deco/deco.qbs</file> + <file>unit_test/simple_boost/tests/deco/enab.h</file> + <file>unit_test/simple_boost/tests/deco/main.cpp</file> + <file>unit_test/simple_boost/tests/fix/fix.cpp</file> + <file>unit_test/simple_boost/tests/fix/fix.pro</file> + <file>unit_test/simple_boost/tests/fix/fix.qbs</file> + <file>unit_test/simple_boost/tests/params/main.cpp</file> + <file>unit_test/simple_boost/tests/params/params.pro</file> + <file>unit_test/simple_boost/tests/params/params.qbs</file> </qresource> </RCC> diff --git a/src/plugins/autotest/testtreemodel.cpp b/src/plugins/autotest/testtreemodel.cpp index d0620630d3a..68f9ff47f21 100644 --- a/src/plugins/autotest/testtreemodel.cpp +++ b/src/plugins/autotest/testtreemodel.cpp @@ -481,24 +481,30 @@ void TestTreeModel::removeTestRootNodes() #ifdef WITH_TESTS // we're inside tests - so use some internal knowledge to make testing easier -TestTreeItem *qtRootNode() +static TestTreeItem *qtRootNode() { return TestFrameworkManager::instance()->rootNodeForTestFramework( Core::Id(Constants::FRAMEWORK_PREFIX).withSuffix("QtTest")); } -TestTreeItem *quickRootNode() +static TestTreeItem *quickRootNode() { return TestFrameworkManager::instance()->rootNodeForTestFramework( Core::Id(Constants::FRAMEWORK_PREFIX).withSuffix("QtQuickTest")); } -TestTreeItem *gtestRootNode() +static TestTreeItem *gtestRootNode() { return TestFrameworkManager::instance()->rootNodeForTestFramework( Core::Id(Constants::FRAMEWORK_PREFIX).withSuffix("GTest")); } +static TestTreeItem *boostTestRootNode() +{ + return TestFrameworkManager::instance()->rootNodeForTestFramework( + Core::Id(Constants::FRAMEWORK_PREFIX).withSuffix("Boost")); +} + int TestTreeModel::autoTestsCount() const { TestTreeItem *rootNode = qtRootNode(); @@ -570,6 +576,25 @@ QMultiMap<QString, int> TestTreeModel::gtestNamesAndSets() const } return result; } + +int TestTreeModel::boostTestNamesCount() const +{ + TestTreeItem *rootNode = boostTestRootNode(); + return rootNode ? rootNode->childCount() : 0; +} + +QMultiMap<QString, int> TestTreeModel::boostTestSuitesAndTests() const +{ + QMultiMap<QString, int> result; + + if (TestTreeItem *rootNode = boostTestRootNode()) { + rootNode->forFirstLevelChildren([&result](TestTreeItem *child) { + result.insert(child->name(), child->childCount()); + }); + } + return result; +} + #endif /***************************** Sort/Filter Model **********************************/ diff --git a/src/plugins/autotest/testtreemodel.h b/src/plugins/autotest/testtreemodel.h index 2945765d473..e1f271d5bc3 100644 --- a/src/plugins/autotest/testtreemodel.h +++ b/src/plugins/autotest/testtreemodel.h @@ -70,6 +70,8 @@ public: int dataTagsCount() const; int gtestNamesCount() const; QMultiMap<QString, int> gtestNamesAndSets() const; + int boostTestNamesCount() const; + QMultiMap<QString, int> boostTestSuitesAndTests() const; #endif void markAllForRemoval(); diff --git a/src/plugins/autotest/unit_test/simple_boost/simple_boost.pro b/src/plugins/autotest/unit_test/simple_boost/simple_boost.pro new file mode 100644 index 00000000000..f0f3a156bb3 --- /dev/null +++ b/src/plugins/autotest/unit_test/simple_boost/simple_boost.pro @@ -0,0 +1,2 @@ +TEMPLATE = subdirs +SUBDIRS += src tests diff --git a/src/plugins/autotest/unit_test/simple_boost/simple_boost.qbs b/src/plugins/autotest/unit_test/simple_boost/simple_boost.qbs new file mode 100644 index 00000000000..413f4f4971d --- /dev/null +++ b/src/plugins/autotest/unit_test/simple_boost/simple_boost.qbs @@ -0,0 +1,5 @@ +import qbs +Project { + name: "SimpleBoost" + references: [ "src/src.qbs", "tests/tests.qbs" ] +} diff --git a/src/plugins/autotest/unit_test/simple_boost/src/main.cpp b/src/plugins/autotest/unit_test/simple_boost/src/main.cpp new file mode 100644 index 00000000000..bc90974049c --- /dev/null +++ b/src/plugins/autotest/unit_test/simple_boost/src/main.cpp @@ -0,0 +1,6 @@ +#include <iostream> +int main() +{ + std::cout << "Hello BoostWorld!\n"; + return 0; +} diff --git a/src/plugins/autotest/unit_test/simple_boost/src/src.pro b/src/plugins/autotest/unit_test/simple_boost/src/src.pro new file mode 100644 index 00000000000..0393f7894b4 --- /dev/null +++ b/src/plugins/autotest/unit_test/simple_boost/src/src.pro @@ -0,0 +1,4 @@ +TEMPLATE = app +CONFIG -= qt app_bundle +CONFIG += console +SOURCES += main.cpp diff --git a/src/plugins/autotest/unit_test/simple_boost/src/src.qbs b/src/plugins/autotest/unit_test/simple_boost/src/src.qbs new file mode 100644 index 00000000000..5b24d9d2171 --- /dev/null +++ b/src/plugins/autotest/unit_test/simple_boost/src/src.qbs @@ -0,0 +1,6 @@ +import qbs +CppApplication { + type: "application" + name: "HelloBoost application" + files: [ "main.cpp" ] +} diff --git a/src/plugins/autotest/unit_test/simple_boost/tests/deco/deco.pro b/src/plugins/autotest/unit_test/simple_boost/tests/deco/deco.pro new file mode 100644 index 00000000000..0a69f075c24 --- /dev/null +++ b/src/plugins/autotest/unit_test/simple_boost/tests/deco/deco.pro @@ -0,0 +1,8 @@ +TEMPLATE = app +CONFIG -= qt app_bundle +CONFIG += console +SOURCES += main.cpp +HEADERS += enab.h + +isEmpty(BOOST_INCLUDE_DIR):BOOST_INCLUDE_DIR=$$(BOOST_INCLUDE_DIR) +!isEmpty(BOOST_INCLUDE_DIR): INCLUDEPATH *= $$BOOST_INCLUDE_DIR diff --git a/src/plugins/autotest/unit_test/simple_boost/tests/deco/deco.qbs b/src/plugins/autotest/unit_test/simple_boost/tests/deco/deco.qbs new file mode 100644 index 00000000000..1f53178c057 --- /dev/null +++ b/src/plugins/autotest/unit_test/simple_boost/tests/deco/deco.qbs @@ -0,0 +1,11 @@ +import qbs +import qbs.File +CppApplication { + name: "Decorators Test" + type: "application" + Properties { + condition: project.boostIncDir && File.exists(project.boostIncDir) + cpp.includePaths: [project.boostIncDir]; + } + files: [ "enab.h", "main.cpp" ] +} diff --git a/src/plugins/autotest/unit_test/simple_boost/tests/deco/enab.h b/src/plugins/autotest/unit_test/simple_boost/tests/deco/enab.h new file mode 100644 index 00000000000..2090c539ebf --- /dev/null +++ b/src/plugins/autotest/unit_test/simple_boost/tests/deco/enab.h @@ -0,0 +1,23 @@ +#pragma once +#include <boost/test/included/unit_test.hpp> + +namespace utf = boost::unit_test; + +BOOST_AUTO_TEST_SUITE(Suite1, * utf::disabled()) + BOOST_AUTO_TEST_CASE(test1) + { + BOOST_TEST(1 != 1); + } + BOOST_AUTO_TEST_CASE(Test2, * utf::enabled()) + { + BOOST_TEST(2 != 2); + } + BOOST_AUTO_TEST_CASE(TestIo, * utf::enable_if<true>()) + { + BOOST_TEST(3 != 3); + } + BOOST_AUTO_TEST_CASE(TestDb, * utf::enable_if<false>()) + { + BOOST_TEST(4 != 4); + } +BOOST_AUTO_TEST_SUITE_END() diff --git a/src/plugins/autotest/unit_test/simple_boost/tests/deco/main.cpp b/src/plugins/autotest/unit_test/simple_boost/tests/deco/main.cpp new file mode 100644 index 00000000000..aef3d912f3f --- /dev/null +++ b/src/plugins/autotest/unit_test/simple_boost/tests/deco/main.cpp @@ -0,0 +1,21 @@ +#define BOOST_TEST_MODULE Suites and Decorators +#include <boost/test/included/unit_test.hpp> +#include "enab.h" +using boost::unit_test::label; + +BOOST_AUTO_TEST_CASE(testWithout1, *label("WO")) { BOOST_TEST (true); } +BOOST_AUTO_TEST_CASE(testWithout2, *label("WO")) { BOOST_TEST (false); } +BOOST_AUTO_TEST_SUITE(SuiteOuter) + BOOST_AUTO_TEST_SUITE(SuiteInner1) + BOOST_AUTO_TEST_CASE(Test1) { BOOST_TEST (true); } + BOOST_AUTO_TEST_CASE(Test2) { BOOST_TEST (true); } + BOOST_AUTO_TEST_SUITE_END() + BOOST_AUTO_TEST_SUITE(SuiteInner2, *boost::unit_test::disabled()) + BOOST_AUTO_TEST_CASE(Test1, *label("I2")) { BOOST_TEST (false); } + BOOST_AUTO_TEST_CASE(Test2, *label("I2")) { BOOST_TEST (false); } + BOOST_AUTO_TEST_SUITE_END() + BOOST_AUTO_TEST_CASE(Test1, *label("O1")) { BOOST_TEST (true); } + BOOST_AUTO_TEST_CASE(Test2) { BOOST_TEST (true); } + BOOST_AUTO_TEST_CASE(Test2A) { BOOST_TEST (true); } +BOOST_AUTO_TEST_SUITE_END() + diff --git a/src/plugins/autotest/unit_test/simple_boost/tests/fix/fix.cpp b/src/plugins/autotest/unit_test/simple_boost/tests/fix/fix.cpp new file mode 100644 index 00000000000..54325e5f258 --- /dev/null +++ b/src/plugins/autotest/unit_test/simple_boost/tests/fix/fix.cpp @@ -0,0 +1,18 @@ +#define BOOST_TEST_MODULE fixture example +#include <boost/test/included/unit_test.hpp> + +struct F { + F() : i( 0 ) { BOOST_TEST_MESSAGE( "setup fixture" ); } + ~F() { BOOST_TEST_MESSAGE( "teardown fixture" ); } + int i; +}; + +BOOST_FIXTURE_TEST_CASE( test_case1, F ) +{ + BOOST_TEST( i++ == 1 ); +} + +BOOST_FIXTURE_TEST_CASE( test_case2, F, * boost::unit_test::disabled() ) +{ + BOOST_CHECK_EQUAL( i, 1 ); +} diff --git a/src/plugins/autotest/unit_test/simple_boost/tests/fix/fix.pro b/src/plugins/autotest/unit_test/simple_boost/tests/fix/fix.pro new file mode 100644 index 00000000000..f070f564b04 --- /dev/null +++ b/src/plugins/autotest/unit_test/simple_boost/tests/fix/fix.pro @@ -0,0 +1,7 @@ +TEMPLATE = app +CONFIG -= qt app_bundle +CONFIG += console +SOURCES += fix.cpp + +isEmpty(BOOST_INCLUDE_DIR):BOOST_INCLUDE_DIR=$$(BOOST_INCLUDE_DIR) +!isEmpty(BOOST_INCLUDE_DIR): INCLUDEPATH *= $$BOOST_INCLUDE_DIR diff --git a/src/plugins/autotest/unit_test/simple_boost/tests/fix/fix.qbs b/src/plugins/autotest/unit_test/simple_boost/tests/fix/fix.qbs new file mode 100644 index 00000000000..5aa62d78880 --- /dev/null +++ b/src/plugins/autotest/unit_test/simple_boost/tests/fix/fix.qbs @@ -0,0 +1,11 @@ +import qbs +import qbs.File +CppApplication { + name: "Fixture Test" + type: "application" + Properties { + condition: project.boostIncDir && File.exists(project.boostIncDir) + cpp.includePaths: [project.boostIncDir]; + } + files: [ "fix.cpp" ] +} diff --git a/src/plugins/autotest/unit_test/simple_boost/tests/params/main.cpp b/src/plugins/autotest/unit_test/simple_boost/tests/params/main.cpp new file mode 100644 index 00000000000..b0821844db3 --- /dev/null +++ b/src/plugins/autotest/unit_test/simple_boost/tests/params/main.cpp @@ -0,0 +1,41 @@ +#include <boost/test/included/unit_test.hpp> +#include <boost/test/parameterized_test.hpp> +#include <boost/bind.hpp> + +using namespace boost::unit_test; + +class TestClass +{ +public: + void testMethod() + { + BOOST_TEST( true ); + } +}; + +void freeTestFunction() +{ + BOOST_TEST( true ); +} + +void freeTestFunction2(int i) +{ + BOOST_TEST( i < 4 ); +} + +test_suite* init_unit_test_suite( int /*argc*/, char* /*argv*/[] ) +{ + boost::shared_ptr<TestClass> tester( new TestClass ); + + framework::master_test_suite(). + add( BOOST_TEST_CASE( boost::bind( &TestClass::testMethod, tester ))); + + framework::master_test_suite(). + add( BOOST_TEST_CASE( &freeTestFunction) ); + + int params[] = {1, 2, 3, 4, 5, 6}; + framework::master_test_suite(). + add( BOOST_PARAM_TEST_CASE( &freeTestFunction2, params, params + 6) ); + + return nullptr; +} diff --git a/src/plugins/autotest/unit_test/simple_boost/tests/params/params.pro b/src/plugins/autotest/unit_test/simple_boost/tests/params/params.pro new file mode 100644 index 00000000000..efea50f870b --- /dev/null +++ b/src/plugins/autotest/unit_test/simple_boost/tests/params/params.pro @@ -0,0 +1,7 @@ +TEMPLATE = app +CONFIG -= qt app_bundle +CONFIG += console +SOURCES += main.cpp + +isEmpty(BOOST_INCLUDE_DIR):BOOST_INCLUDE_DIR=$$(BOOST_INCLUDE_DIR) +!isEmpty(BOOST_INCLUDE_DIR): INCLUDEPATH *= $$BOOST_INCLUDE_DIR diff --git a/src/plugins/autotest/unit_test/simple_boost/tests/params/params.qbs b/src/plugins/autotest/unit_test/simple_boost/tests/params/params.qbs new file mode 100644 index 00000000000..5e4633cdb17 --- /dev/null +++ b/src/plugins/autotest/unit_test/simple_boost/tests/params/params.qbs @@ -0,0 +1,11 @@ +import qbs +import qbs.File +CppApplication { + name: "Using Test Functions" + type: "application" + Properties { + condition: project.boostIncDir && File.exists(project.boostIncDir) + cpp.includePaths: [project.boostIncDir]; + } + files: [ "main.cpp" ] +} diff --git a/src/plugins/autotest/unit_test/simple_boost/tests/tests.pro b/src/plugins/autotest/unit_test/simple_boost/tests/tests.pro new file mode 100644 index 00000000000..160045bd752 --- /dev/null +++ b/src/plugins/autotest/unit_test/simple_boost/tests/tests.pro @@ -0,0 +1,2 @@ +TEMPLATE = subdirs +SUBDIRS += fix params deco diff --git a/src/plugins/autotest/unit_test/simple_boost/tests/tests.qbs b/src/plugins/autotest/unit_test/simple_boost/tests/tests.qbs new file mode 100644 index 00000000000..2033b5de2ef --- /dev/null +++ b/src/plugins/autotest/unit_test/simple_boost/tests/tests.qbs @@ -0,0 +1,11 @@ +import qbs +import qbs.Environment +Project { + name: "Tests" + property string boostIncDir: { + if (typeof Environment.getEnv("BOOST_INCLUDE_DIR") !== 'undefined') + return Environment.getEnv("BOOST_INCLUDE_DIR"); + return undefined; + } + references: [ "deco/deco.qbs", "fix/fix.qbs", "params/params.qbs" ] +} |