aboutsummaryrefslogtreecommitdiffstats
path: root/src/plugins/autotest
diff options
context:
space:
mode:
authorhjk <hjk@qt.io>2024-01-19 12:25:23 +0100
committerhjk <hjk@qt.io>2024-01-19 12:33:33 +0000
commit45bb4a5f760600ed04dfc7e113b65721cdf10b46 (patch)
tree60ab1bac46f94fb4a7fc4b9e803ce59fa0818169 /src/plugins/autotest
parentf9f43f749253a527e4d73bcdf2585e5531eb9521 (diff)
Autotest: Move unit plugin test creation closer to the tested code
The current pattern. Change-Id: I52354584734755b3b0f3d2c9596801dc050300fc Reviewed-by: Jarek Kobus <jaroslaw.kobus@qt.io>
Diffstat (limited to 'src/plugins/autotest')
-rw-r--r--src/plugins/autotest/autotestplugin.cpp2
-rw-r--r--src/plugins/autotest/autotestunittests.cpp70
-rw-r--r--src/plugins/autotest/autotestunittests.h39
3 files changed, 53 insertions, 58 deletions
diff --git a/src/plugins/autotest/autotestplugin.cpp b/src/plugins/autotest/autotestplugin.cpp
index 0b870f0bc0..9e0defa04c 100644
--- a/src/plugins/autotest/autotestplugin.cpp
+++ b/src/plugins/autotest/autotestplugin.cpp
@@ -511,7 +511,7 @@ public:
ExtensionSystem::PluginManager::registerScenario("TestModelManagerInterface",
[] { return dd->m_loadProjectScenario(); });
- addTest<AutoTestUnitTests>(&dd->m_testTreeModel);
+ addTestCreator(createAutotestUnitTests);
#endif
}
diff --git a/src/plugins/autotest/autotestunittests.cpp b/src/plugins/autotest/autotestunittests.cpp
index 7ef019dac1..d1fd8880ab 100644
--- a/src/plugins/autotest/autotestunittests.cpp
+++ b/src/plugins/autotest/autotestunittests.cpp
@@ -34,16 +34,40 @@ using namespace ExtensionSystem;
using namespace ProjectExplorer;
using namespace Utils;
-namespace Autotest {
-namespace Internal {
+namespace Autotest::Internal {
-AutoTestUnitTests::AutoTestUnitTests(TestTreeModel *model, QObject *parent)
- : QObject(parent),
- m_model(model)
+class AutotestUnitTests : public QObject
{
-}
-
-void AutoTestUnitTests::initTestCase()
+ Q_OBJECT
+
+public:
+ AutotestUnitTests()
+ : m_model(TestTreeModel::instance())
+ {}
+
+private slots:
+ void initTestCase();
+ void cleanupTestCase();
+ void testCodeParser();
+ void testCodeParser_data();
+ void testCodeParserSwitchStartup();
+ void testCodeParserSwitchStartup_data();
+ void testCodeParserGTest();
+ void testCodeParserGTest_data();
+ void testCodeParserBoostTest();
+ void testCodeParserBoostTest_data();
+ void testModelManagerInterface();
+
+private:
+ TestTreeModel *m_model = nullptr;
+ CppEditor::Tests::TemporaryCopiedDir *m_tmpDir = nullptr;
+ bool m_isQt4 = false;
+ bool m_checkBoost = false;
+ ProjectExplorer::Kit *m_kit = nullptr;
+};
+
+
+void AutotestUnitTests::initTestCase()
{
const QList<Kit *> allKits = KitManager::kits();
if (allKits.count() == 0)
@@ -80,12 +104,12 @@ void AutoTestUnitTests::initTestCase()
theQtTestFramework().quickCheckForDerivedTests.setValue(true);
}
-void AutoTestUnitTests::cleanupTestCase()
+void AutotestUnitTests::cleanupTestCase()
{
delete m_tmpDir;
}
-void AutoTestUnitTests::testCodeParser()
+void AutotestUnitTests::testCodeParser()
{
QFETCH(FilePath, projectFilePath);
QFETCH(int, expectedAutoTestsCount);
@@ -110,7 +134,7 @@ void AutoTestUnitTests::testCodeParser()
QCOMPARE(m_model->dataTagsCount(), expectedDataTagsCount);
}
-void AutoTestUnitTests::testCodeParser_data()
+void AutotestUnitTests::testCodeParser_data()
{
QTest::addColumn<FilePath>("projectFilePath");
QTest::addColumn<int>("expectedAutoTestsCount");
@@ -133,7 +157,7 @@ void AutoTestUnitTests::testCodeParser_data()
<< 4 << 10 << 5 << 10;
}
-void AutoTestUnitTests::testCodeParserSwitchStartup()
+void AutotestUnitTests::testCodeParserSwitchStartup()
{
QFETCH(FilePaths, projectFilePaths);
QFETCH(QList<int>, expectedAutoTestsCount);
@@ -161,7 +185,7 @@ void AutoTestUnitTests::testCodeParserSwitchStartup()
}
}
-void AutoTestUnitTests::testCodeParserSwitchStartup_data()
+void AutotestUnitTests::testCodeParserSwitchStartup_data()
{
QTest::addColumn<FilePaths>("projectFilePaths");
QTest::addColumn<QList<int> >("expectedAutoTestsCount");
@@ -187,7 +211,7 @@ void AutoTestUnitTests::testCodeParserSwitchStartup_data()
<< expectedUnnamedQuickTests << expectedDataTagsCount;
}
-void AutoTestUnitTests::testCodeParserGTest()
+void AutotestUnitTests::testCodeParserGTest()
{
if (qtcEnvironmentVariableIsEmpty("GOOGLETEST_DIR"))
QSKIP("This test needs googletest - set GOOGLETEST_DIR (point to googletest repository)");
@@ -226,7 +250,7 @@ void AutoTestUnitTests::testCodeParserGTest()
QCOMPARE(m_model->boostTestNamesCount(), 0);
}
-void AutoTestUnitTests::testCodeParserGTest_data()
+void AutotestUnitTests::testCodeParserGTest_data()
{
QTest::addColumn<FilePath>("projectFilePath");
QTest::newRow("simpleGoogletest")
@@ -235,7 +259,7 @@ void AutoTestUnitTests::testCodeParserGTest_data()
<< m_tmpDir->filePath() / "simple_gt/simple_gt.qbs";
}
-void AutoTestUnitTests::testCodeParserBoostTest()
+void AutotestUnitTests::testCodeParserBoostTest()
{
if (!m_checkBoost)
QSKIP("This test needs boost - set BOOST_INCLUDE_DIR (or have it installed)");
@@ -281,7 +305,7 @@ void AutoTestUnitTests::testCodeParserBoostTest()
QCOMPARE(m_model->gtestNamesCount(), 0);
}
-void AutoTestUnitTests::testCodeParserBoostTest_data()
+void AutotestUnitTests::testCodeParserBoostTest_data()
{
QTest::addColumn<FilePath>("projectFilePath");
QTest::addColumn<QString>("extension");
@@ -300,10 +324,16 @@ static int executeScenario(const QString &scenario)
return QProcess::execute(data.m_executable, data.m_args + additionalArgs);
}
-void AutoTestUnitTests::testModelManagerInterface()
+void AutotestUnitTests::testModelManagerInterface()
{
QCOMPARE(executeScenario("TestModelManagerInterface"), 0);
}
-} // namespace Internal
-} // namespace Autotest
+QObject *createAutotestUnitTests()
+{
+ return new AutotestUnitTests;
+}
+
+} // namespace Autotest::Internal
+
+#include "autotestunittests.moc"
diff --git a/src/plugins/autotest/autotestunittests.h b/src/plugins/autotest/autotestunittests.h
index 752599cb45..ff5930e418 100644
--- a/src/plugins/autotest/autotestunittests.h
+++ b/src/plugins/autotest/autotestunittests.h
@@ -5,43 +5,8 @@
#include <QObject>
-namespace CppEditor { namespace Tests { class TemporaryCopiedDir; } }
-namespace ProjectExplorer { class Kit; }
+namespace Autotest::Internal {
-namespace Autotest {
+QObject *createAutotestUnitTests();
-class TestTreeModel;
-
-namespace Internal {
-
-class AutoTestUnitTests : public QObject
-{
- Q_OBJECT
-public:
- explicit AutoTestUnitTests(TestTreeModel *model, QObject *parent = nullptr);
-
-signals:
-
-private slots:
- void initTestCase();
- void cleanupTestCase();
- void testCodeParser();
- void testCodeParser_data();
- void testCodeParserSwitchStartup();
- void testCodeParserSwitchStartup_data();
- void testCodeParserGTest();
- void testCodeParserGTest_data();
- void testCodeParserBoostTest();
- void testCodeParserBoostTest_data();
- void testModelManagerInterface();
-
-private:
- TestTreeModel *m_model = nullptr;
- CppEditor::Tests::TemporaryCopiedDir *m_tmpDir = nullptr;
- bool m_isQt4 = false;
- bool m_checkBoost = false;
- ProjectExplorer::Kit *m_kit = nullptr;
-};
-
-} // namespace Internal
} // namespace Autotest