From 636dbe604596b2860e4f6d9b159fc017dcd2f66b Mon Sep 17 00:00:00 2001 From: Thiago Macieira Date: Tue, 11 Oct 2022 10:16:27 -0700 Subject: 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 --- .../auto/corelib/plugin/qlibrary/tst_qlibrary.cpp | 33 ++++++++++++++++++++++ 1 file changed, 33 insertions(+) (limited to 'tests/auto/corelib') 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 -- cgit v1.2.3