##// END OF EJS Templates
Unit tests for plugin loading (2)...
Alexandre Leroux -
r71:fa55a3b11979
parent child
Show More
@@ -0,0 +1,81
1 #include <Plugin/PluginManager.h>
2
3 #include <QObject>
4 #include <QtTest>
5
6 #include <QtDebug>
7
8 namespace {
9
10 /// Path for the tests
11 const auto TESTS_RESOURCES_PATH = QFileInfo{
12 QString{SCQCORE_TESTS_RESOURCES_PATH},
13 "Plugin/TestPluginManager"}.absoluteFilePath();
14
15 QString pluginDirPath(const QString &pluginDirName)
16 {
17 return QFileInfo{TESTS_RESOURCES_PATH, pluginDirName}.absoluteFilePath();
18 }
19
20 } // namespace
21
22 class TestPluginManager : public QObject {
23 Q_OBJECT
24 private slots:
25 /// Defines data for plugin loading
26 /// @sa testLoadPlugin()
27 void testLoadPlugin_data();
28
29 /// Tests plugin loading
30 void testLoadPlugin();
31 };
32
33 void TestPluginManager::testLoadPlugin_data()
34 {
35 // ////////////// //
36 // Test structure //
37 // ////////////// //
38
39 // Name of directory containing the plugins
40 QTest::addColumn<QString>("pluginDirName");
41 // Number of loaded plugins expected
42 QTest::addColumn<int>("nbPluginsLoaded");
43
44 // ////////// //
45 // Test cases //
46 // ////////// //
47
48 QTest::newRow("Valid plugin") << QStringLiteral("Test_ValidPlugin") << 1;
49
50 // Two different plugins
51 QTest::newRow("Valid plugins") << QStringLiteral("Test_ValidPlugins") << 2;
52
53 // Two plugins with the same name: we expect that only one is loaded
54 QTest::newRow("Duplicated plugins") << QStringLiteral("Test_DuplicatedPlugins") << 1;
55
56 QTest::newRow("Invalid plugin (not a DLL)") << QStringLiteral("Test_InvalidFileType") << 0;
57 QTest::newRow("Invalid plugin (not a SciQlop DLL)")
58 << QStringLiteral("Test_NotSciqlopDll") << 0;
59 QTest::newRow("Invalid plugin (missing metadata)")
60 << QStringLiteral("Test_MissingPluginMetadata") << 0;
61 }
62
63 void TestPluginManager::testLoadPlugin()
64 {
65 QFETCH(QString, pluginDirName);
66 QFETCH(int, nbPluginsLoaded);
67
68 // Generates plugin dir
69 auto pluginDir = QDir{pluginDirPath(pluginDirName)};
70 QVERIFY(pluginDir.exists());
71
72 // Load plugins
73 PluginManager pluginManager{};
74 pluginManager.loadPlugins(pluginDir);
75
76 // Check the number of plugins loaded
77 QCOMPARE(pluginManager.nbPluginsLoaded(), nbPluginsLoaded);
78 }
79
80 QTEST_MAIN(TestPluginManager)
81 #include "TestPluginManager.moc"
General Comments 0
You need to be logged in to leave comments. Login now