summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDawid Śliwa <dawid.sliwa@qt.io>2026-08-14 11:26:00 +0200
committerDawid Śliwa <dawid.sliwa@qt.io>2026-08-15 19:09:04 +0000
commit59c85b2ecd3c0c25d242a7d7ab6c8fc477f882cf (patch)
tree91629e5376bb607ca9384df4a3f54744a5e4b04e
parent10bf69ad412badb5558e5c2ed299ec4975f698d4 (diff)
tst_QPluginLoader: make the plugin tests work on HarmonyOSHEADdev
The test resolved its helper plugins through QFINDTESTDATA("bin/..."), a build-tree layout that does not exist inside a HAP, so every row that opens or loads theplugin failed: 83 of 89 functions. Resolve them from the library paths instead, where HarmonyOS keeps the flat libs dir of the package, and declare the runtime-loaded plugins as extra libs so they are packaged in the first place - they are dlopen'ed by name, not linked, so nothing else pulls them in. relativePath() and absolutePath() need no library-path setup, like on Android, but the plugin file name carries no architecture suffix and the absolute path has to be resolved before the paths are cleared, so both get their own branch. Result on device: 89 passed, 1 skipped (was 6 passed, 83 failed), identical on a tablet and a 2in1. Task-number: QTBUG-149202 Pick-to: 6.12 Change-Id: Ic1304c11c63283f4236671eaf3103634aec5a177 Reviewed-by: SanthoshKumar Selvaraj <santhosh.kumar.selvaraj@qt.io>
-rw-r--r--tests/auto/corelib/plugin/qpluginloader/tst/CMakeLists.txt11
-rw-r--r--tests/auto/corelib/plugin/qpluginloader/tst_qpluginloader.cpp24
2 files changed, 34 insertions, 1 deletions
diff --git a/tests/auto/corelib/plugin/qpluginloader/tst/CMakeLists.txt b/tests/auto/corelib/plugin/qpluginloader/tst/CMakeLists.txt
index 9235f3e6a91..8f9fc9a797c 100644
--- a/tests/auto/corelib/plugin/qpluginloader/tst/CMakeLists.txt
+++ b/tests/auto/corelib/plugin/qpluginloader/tst/CMakeLists.txt
@@ -47,3 +47,14 @@ if(ANDROID)
QT_ANDROID_EXTRA_LIBS "${extra_libs}"
)
endif()
+
+if(OHOS)
+ set(extra_libs
+ theplugin
+ theoldplugin
+ tst_qpluginloaderlib
+ )
+ set_target_properties(tst_qpluginloader PROPERTIES
+ QT_HARMONYOS_EXTRA_LIBS "${extra_libs}"
+ )
+endif()
diff --git a/tests/auto/corelib/plugin/qpluginloader/tst_qpluginloader.cpp b/tests/auto/corelib/plugin/qpluginloader/tst_qpluginloader.cpp
index da2f00917bc..9230cc4bc04 100644
--- a/tests/auto/corelib/plugin/qpluginloader/tst_qpluginloader.cpp
+++ b/tests/auto/corelib/plugin/qpluginloader/tst_qpluginloader.cpp
@@ -181,6 +181,17 @@ static QString sys_qualifiedLibraryName(const QString &fileName)
ANDROID_ARCH, SUFFIX);
}
return fileName;
+#elif defined(Q_OS_HARMONY)
+ // On HarmonyOS all the libraries are bundled flat into the HAP's libs subdir,
+ // which is one of the library paths
+ const QString name = QLatin1String(PREFIX) + fileName + QLatin1String(SUFFIX);
+ const QStringList paths = QCoreApplication::libraryPaths();
+ for (const QString &path : paths) {
+ const QFileInfo fi(path + u'/' + name);
+ if (fi.exists())
+ return fi.canonicalFilePath();
+ }
+ return fileName;
#else
QString name = QLatin1String("bin/") + QLatin1String(PREFIX) + fileName + QLatin1String(SUFFIX);
const QString libname = QFINDTESTDATA(name);
@@ -963,6 +974,10 @@ void tst_QPluginLoader::relativePath()
// already set.
// But we need to use ARCH suffix in pulgin name
const QString pluginName("theplugin_" ANDROID_ARCH SUFFIX);
+#elif defined(Q_OS_HARMONY)
+ // On HarmonyOS we do not need to explicitly set library paths either, as the
+ // plugins are bundled flat into a directory that is already one of them.
+ const QString pluginName("theplugin" SUFFIX);
#else
// Windows binaries run from release and debug subdirs, so we can't rely on the current dir.
const QString binDir = QFINDTESTDATA("bin");
@@ -990,6 +1005,13 @@ void tst_QPluginLoader::absolutePath()
QVERIFY(!libraryPaths.isEmpty());
QCoreApplication::setLibraryPaths(QStringList());
const QString pluginPath(libraryPaths.first() + "/" PREFIX "theplugin_" ANDROID_ARCH SUFFIX);
+#elif defined(Q_OS_HARMONY)
+ // On HarmonyOS we need to clear library paths too, but the plugin has to be
+ // located before that, as it lives in one of them
+ const QStringList libraryPaths = QCoreApplication::libraryPaths();
+ QVERIFY(!libraryPaths.isEmpty());
+ const QString pluginPath = sys_qualifiedLibraryName("theplugin");
+ QCoreApplication::setLibraryPaths(QStringList());
#else
// Windows binaries run from release and debug subdirs, so we can't rely on the current dir.
const QString binDir = QFINDTESTDATA("bin");
@@ -1000,7 +1022,7 @@ void tst_QPluginLoader::absolutePath()
QPluginLoader loader(pluginPath);
loader.load(); // not recommended, instance() should do the job.
PluginInterface *instance = qobject_cast<PluginInterface*>(loader.instance());
-#ifdef Q_OS_ANDROID
+#if defined(Q_OS_ANDROID) || defined(Q_OS_HARMONY)
// Restore library paths
QCoreApplication::setLibraryPaths(libraryPaths);
#endif