From f375f197d1bba919cd4d7efb7f15d99683361863 Mon Sep 17 00:00:00 2001 From: Christian Stenger Date: Thu, 5 Jan 2017 11:48:55 +0100 Subject: [PATCH] AutoTest: Add test for derived Qt tests Change-Id: I8c61c08ff9b0653c02d262fb9010940e41e178af Reviewed-by: David Schulz --- src/plugins/autotest/autotestunittests.cpp | 8 ++-- src/plugins/autotest/autotestunittests.qrc | 5 +++ .../unit_test/mixed_atp/tests/auto/auto.pro | 1 + .../unit_test/mixed_atp/tests/auto/auto.qbs | 1 + .../mixed_atp/tests/auto/derived/derived.pro | 34 +++++++++++++++ .../mixed_atp/tests/auto/derived/derived.qbs | 14 ++++++ .../mixed_atp/tests/auto/derived/origin.cpp | 43 +++++++++++++++++++ .../mixed_atp/tests/auto/derived/origin.h | 18 ++++++++ .../tests/auto/derived/tst_derivedtest.cpp | 37 ++++++++++++++++ 9 files changed, 157 insertions(+), 4 deletions(-) create mode 100644 src/plugins/autotest/unit_test/mixed_atp/tests/auto/derived/derived.pro create mode 100644 src/plugins/autotest/unit_test/mixed_atp/tests/auto/derived/derived.qbs create mode 100644 src/plugins/autotest/unit_test/mixed_atp/tests/auto/derived/origin.cpp create mode 100644 src/plugins/autotest/unit_test/mixed_atp/tests/auto/derived/origin.h create mode 100644 src/plugins/autotest/unit_test/mixed_atp/tests/auto/derived/tst_derivedtest.cpp diff --git a/src/plugins/autotest/autotestunittests.cpp b/src/plugins/autotest/autotestunittests.cpp index 369df6b7145..fc917ffdf44 100644 --- a/src/plugins/autotest/autotestunittests.cpp +++ b/src/plugins/autotest/autotestunittests.cpp @@ -121,13 +121,13 @@ void AutoTestUnitTests::testCodeParser_data() << 1 << 0 << 0 << 0; QTest::newRow("mixedAutoTestAndQuickTests") << QString(m_tmpDir->path() + QLatin1String("/mixed_atp/mixed_atp.pro")) - << 3 << 5 << 3 << 8; + << 4 << 5 << 3 << 10; QTest::newRow("plainAutoTestQbs") << QString(m_tmpDir->path() + QLatin1String("/plain/plain.qbs")) << 1 << 0 << 0 << 0; QTest::newRow("mixedAutoTestAndQuickTestsQbs") << QString(m_tmpDir->path() + QLatin1String("/mixed_atp/mixed_atp.qbs")) - << 3 << 5 << 3 << 8; + << 4 << 5 << 3 << 10; } void AutoTestUnitTests::testCodeParserSwitchStartup() @@ -173,10 +173,10 @@ void AutoTestUnitTests::testCodeParserSwitchStartup_data() << QString(m_tmpDir->path() + QLatin1String("/plain/plain.qbs")) << QString(m_tmpDir->path() + QLatin1String("/mixed_atp/mixed_atp.qbs")); - QList expectedAutoTests = QList() << 1 << 3 << 1 << 3; + QList expectedAutoTests = QList() << 1 << 4 << 1 << 4; QList expectedNamedQuickTests = QList() << 0 << 5 << 0 << 5; QList expectedUnnamedQuickTests = QList() << 0 << 3 << 0 << 3; - QList expectedDataTagsCount = QList() << 0 << 8 << 0 << 8; + QList expectedDataTagsCount = QList() << 0 << 10 << 0 << 10; QTest::newRow("loadMultipleProjects") << projects << expectedAutoTests << expectedNamedQuickTests diff --git a/src/plugins/autotest/autotestunittests.qrc b/src/plugins/autotest/autotestunittests.qrc index 0bc8017cc32..2b96248246d 100644 --- a/src/plugins/autotest/autotestunittests.qrc +++ b/src/plugins/autotest/autotestunittests.qrc @@ -39,6 +39,11 @@ unit_test/mixed_atp/tests/auto/gui/gui.qbs unit_test/mixed_atp/tests/auto/quickauto/quickauto.qbs unit_test/mixed_atp/tests/auto/quickauto2/quickauto2.qbs + unit_test/mixed_atp/tests/auto/derived/derived.pro + unit_test/mixed_atp/tests/auto/derived/derived.qbs + unit_test/mixed_atp/tests/auto/derived/origin.h + unit_test/mixed_atp/tests/auto/derived/origin.cpp + unit_test/mixed_atp/tests/auto/derived/tst_derivedtest.cpp unit_test/simple_gt/src/main.cpp unit_test/simple_gt/src/src.pro unit_test/simple_gt/src/src.qbs diff --git a/src/plugins/autotest/unit_test/mixed_atp/tests/auto/auto.pro b/src/plugins/autotest/unit_test/mixed_atp/tests/auto/auto.pro index cb4dc9ec327..72e2d6f4e16 100644 --- a/src/plugins/autotest/unit_test/mixed_atp/tests/auto/auto.pro +++ b/src/plugins/autotest/unit_test/mixed_atp/tests/auto/auto.pro @@ -2,6 +2,7 @@ TEMPLATE = subdirs SUBDIRS = \ bench \ + derived \ dummy \ gui diff --git a/src/plugins/autotest/unit_test/mixed_atp/tests/auto/auto.qbs b/src/plugins/autotest/unit_test/mixed_atp/tests/auto/auto.qbs index a27b3922443..011987acfa1 100644 --- a/src/plugins/autotest/unit_test/mixed_atp/tests/auto/auto.qbs +++ b/src/plugins/autotest/unit_test/mixed_atp/tests/auto/auto.qbs @@ -5,6 +5,7 @@ Project { references: [ "bench/bench.qbs", + "derived/derived.qbs", "dummy/dummy.qbs", "gui/gui.qbs", "quickauto/quickauto.qbs", diff --git a/src/plugins/autotest/unit_test/mixed_atp/tests/auto/derived/derived.pro b/src/plugins/autotest/unit_test/mixed_atp/tests/auto/derived/derived.pro new file mode 100644 index 00000000000..4178799aae2 --- /dev/null +++ b/src/plugins/autotest/unit_test/mixed_atp/tests/auto/derived/derived.pro @@ -0,0 +1,34 @@ +#------------------------------------------------- +# +# Project created by QtCreator 2017-01-03T08:16:50 +# +#------------------------------------------------- + +QT += testlib + +QT -= gui + +TARGET = tst_derivedtest +CONFIG += console +CONFIG -= app_bundle + +TEMPLATE = app + +# The following define makes your compiler emit warnings if you use +# any feature of Qt which as been marked as deprecated (the exact warnings +# depend on your compiler). Please consult the documentation of the +# deprecated API in order to know how to port your code away from it. +DEFINES += QT_DEPRECATED_WARNINGS + +# You can also make your code fail to compile if you use deprecated APIs. +# In order to do so, uncomment the following line. +# You can also select to disable deprecated APIs only up to a certain version of Qt. +#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0 + + +SOURCES += tst_derivedtest.cpp \ + origin.cpp +DEFINES += SRCDIR=\\\"$$PWD/\\\" + +HEADERS += \ + origin.h diff --git a/src/plugins/autotest/unit_test/mixed_atp/tests/auto/derived/derived.qbs b/src/plugins/autotest/unit_test/mixed_atp/tests/auto/derived/derived.qbs new file mode 100644 index 00000000000..27b02c128d7 --- /dev/null +++ b/src/plugins/autotest/unit_test/mixed_atp/tests/auto/derived/derived.qbs @@ -0,0 +1,14 @@ +import qbs + +CppApplication { + type: "application" + name: "Derived Auto Test" + targetName: "tst_derivedtest" + + Depends { name: "cpp" } + Depends { name: "Qt.testlib" } + + files: [ "origin.cpp", "origin.h", "tst_derivedtest.cpp" ] + + cpp.defines: base.concat("SRCDIR=" + path) +} diff --git a/src/plugins/autotest/unit_test/mixed_atp/tests/auto/derived/origin.cpp b/src/plugins/autotest/unit_test/mixed_atp/tests/auto/derived/origin.cpp new file mode 100644 index 00000000000..5e9014cf626 --- /dev/null +++ b/src/plugins/autotest/unit_test/mixed_atp/tests/auto/derived/origin.cpp @@ -0,0 +1,43 @@ +#include "origin.h" + +#include + +Origin::Origin() +{ +} + +void Origin::testSchmu() +{ + QCOMPARE(1, 1); +} + +void Origin::testStr() +{ + QFETCH(bool, localAware); + + QString str1 = QLatin1String("Hello World"); + QString str2 = QLatin1String("Hallo Welt"); + if (!localAware) { + QBENCHMARK { + str1 == str2; + } + } else { + QBENCHMARK { + str1.localeAwareCompare(str2) == 0; + } + } +} + +void Origin::testStr_data() +{ + QTest::addColumn("localAware"); + QTest::newRow("simple") << false; + QTest::newRow("localAware") << true; +} + +void Origin::testBase1_data() +{ + QTest::addColumn("bogus"); + QTest::newRow("foo") << false; // we don't expect 'foo' and 'bar' to be displayed + QTest::newRow("bar") << true; +} diff --git a/src/plugins/autotest/unit_test/mixed_atp/tests/auto/derived/origin.h b/src/plugins/autotest/unit_test/mixed_atp/tests/auto/derived/origin.h new file mode 100644 index 00000000000..57a62d4d5b7 --- /dev/null +++ b/src/plugins/autotest/unit_test/mixed_atp/tests/auto/derived/origin.h @@ -0,0 +1,18 @@ +#ifndef ORIGIN_H +#define ORIGIN_H + +#include + +class Origin : public QObject +{ + Q_OBJECT +public: + Origin(); +private slots: + void testSchmu(); + void testStr(); + void testStr_data(); + void testBase1_data(); // makes no sense - but should be handled correctly +}; + +#endif // ORIGIN_H diff --git a/src/plugins/autotest/unit_test/mixed_atp/tests/auto/derived/tst_derivedtest.cpp b/src/plugins/autotest/unit_test/mixed_atp/tests/auto/derived/tst_derivedtest.cpp new file mode 100644 index 00000000000..6ca6c23fc1d --- /dev/null +++ b/src/plugins/autotest/unit_test/mixed_atp/tests/auto/derived/tst_derivedtest.cpp @@ -0,0 +1,37 @@ +#include "origin.h" + +#include + +class BaseTest : public Origin +{ + Q_OBJECT +private slots: + void testBase1(); +}; + +void BaseTest::testBase1() +{ + QVERIFY(true); +} + +class DerivedTest : public BaseTest +{ + Q_OBJECT +private Q_SLOTS: + void testCase1(); + void testBase1(); +}; + +void DerivedTest::testCase1() +{ + QVERIFY2(true, "Failure"); +} + +void DerivedTest::testBase1() +{ + QVERIFY(true); +} + +QTEST_APPLESS_MAIN(DerivedTest) + +#include "tst_derivedtest.moc"