summaryrefslogtreecommitdiffstats
path: root/tests/auto/corelib
diff options
context:
space:
mode:
authorThiago Macieira <thiago.macieira@intel.com>2022-10-11 10:16:27 -0700
committerMarc Mutz <marc.mutz@qt.io>2022-10-19 00:10:42 +0000
commit636dbe604596b2860e4f6d9b159fc017dcd2f66b (patch)
treecf8f87d7e8d740b0aa8e578129c78404c3ecc089 /tests/auto/corelib
parent9c6b8ea2907ac97392b521a1c68e4dd03c2028e1 (diff)
tst_QLibrary: add a cleanup() method to unload left-overs
QLibrary intentionally does not unload on destruction, so failing tests may leave libraries already loaded and cause further tests to fail because of that. So add a cleanup() method to unload everything we may have loaded. Note that QLibrary::unload() sets its state to NotLoaded after one successful call, so we must recreate the object in case it had been load()ed multiple times. Pick-to: 6.2 6.4 Change-Id: I12a088d1ae424825abd3fffd171d133c678f910a Reviewed-by: Marc Mutz <marc.mutz@qt.io>
Diffstat (limited to 'tests/auto/corelib')
-rw-r--r--tests/auto/corelib/plugin/qlibrary/tst_qlibrary.cpp33
1 files changed, 33 insertions, 0 deletions
diff --git a/tests/auto/corelib/plugin/qlibrary/tst_qlibrary.cpp b/tests/auto/corelib/plugin/qlibrary/tst_qlibrary.cpp
index 620c1e0960..a64f7785b0 100644
--- a/tests/auto/corelib/plugin/qlibrary/tst_qlibrary.cpp
+++ b/tests/auto/corelib/plugin/qlibrary/tst_qlibrary.cpp
@@ -81,6 +81,7 @@ enum QLibraryOperation {
QString directory;
private slots:
void initTestCase();
+ void cleanup();
void load_data();
void load();
@@ -123,6 +124,38 @@ void tst_QLibrary::initTestCase()
#endif
}
+void tst_QLibrary::cleanup()
+{
+ // unload the libraries, if they are still loaded after the test ended
+ // (probably in a failure)
+
+ static struct {
+ QString name;
+ int version = -1;
+ } libs[] = {
+ { directory + "/mylib" },
+ { directory + "/mylib", 1 },
+ { directory + "/mylib", 2 },
+ { sys_qualifiedLibraryName("mylib") },
+
+ // stuff that load_data() succeeds with
+ { directory + "/" PREFIX "mylib" },
+ { directory + "/" PREFIX "mylib" SUFFIX },
+#if defined(Q_OS_WIN32)
+ { directory + "/mylib.dl2" },
+ { directory + "/system.qt.test.mylib.dll" },
+#elif !defined(Q_OS_ANDROID)
+ // .so even on macOS
+ { directory + "/libmylib.so2" },
+ { directory + "/system.qt.test.mylib.so" },
+#endif
+
+ };
+ for (const auto &entry : libs) {
+ do {} while (QLibrary(entry.name, entry.version).unload());
+ }
+}
+
void tst_QLibrary::version_data()
{
#ifdef Q_OS_ANDROID