diff --git a/module_manager/native_module_manager.cpp b/module_manager/native_module_manager.cpp index 78c61488a71a66f2669e9dc5edc1233fef2a6086..9ac776142e3e772dda28a40a6ac9420cf0d44c3e 100644 --- a/module_manager/native_module_manager.cpp +++ b/module_manager/native_module_manager.cpp @@ -502,6 +502,21 @@ void NativeModuleManager::CreateLdNamespace(const std::string moduleName, const #endif } +bool NativeModuleManager::GetLdNamespaceName(const std::string &moduleName, std::string &nsName) +{ +#if !defined(WINDOWS_PLATFORM) && !defined(MAC_PLATFORM) && !defined(__BIONIC__) && !defined(IOS_PLATFORM) && \ + !defined(LINUX_PLATFORM) + if (nsMap_.find(moduleName) == nsMap_.end()) { + HILOG_ERROR("not found ns: %{public}s", moduleName.c_str()); + return false; + } + nsName = "moduleNs_" + moduleName; + return true; +#else + return false; +#endif +} + void NativeModuleManager::SetAppLibPath(const std::string& moduleName, const std::vector& appLibPath, const bool& isSystemApp) { diff --git a/module_manager/native_module_manager.h b/module_manager/native_module_manager.h index 1a45d5db0b09496f28f89592d9ab1f259a2bc28e..be8ce6bb09bfaf89c440f4f252ac6243d42f06f7 100644 --- a/module_manager/native_module_manager.h +++ b/module_manager/native_module_manager.h @@ -84,6 +84,7 @@ public: void Register(NativeModule* nativeModule); void SetAppLibPath(const std::string& moduleName, const std::vector& appLibPath, const bool& isSystemApp = false); + bool GetLdNamespaceName(const std::string &moduleName, std::string &nsName); NativeModule* LoadNativeModule(const char* moduleName, const char* path, bool isAppModule, std::string& errInfo, bool internal = false, const char* relativePath = ""); void SetNativeEngine(std::string moduleName, NativeEngine* nativeEngine); diff --git a/module_manager/test/unittest/module_manager_test/module_manager_test.cpp b/module_manager/test/unittest/module_manager_test/module_manager_test.cpp index 9722ade09b9cf5c9c4a2e55aadf16a4659e58e0c..6298d806aecc253a751e93ffc237088f4027a28f 100644 --- a/module_manager/test/unittest/module_manager_test/module_manager_test.cpp +++ b/module_manager/test/unittest/module_manager_test/module_manager_test.cpp @@ -227,7 +227,13 @@ HWTEST_F(ModuleManagerTest, LoadNativeModuleTest_008, TestSize.Level1) moduleManager->Register(nullptr); moduleManager->CreateSharedLibsSonames(); + std::string nsName; + bool res = moduleManager->GetLdNamespaceName(moduleName, nsName); + EXPECT_EQ(res, false); moduleManager->CreateLdNamespace(moduleName, libPath, true); + res = moduleManager->GetLdNamespaceName(moduleName, nsName); + EXPECT_EQ(res, true); + EXPECT_STREQ(nsName.c_str(), ("moduleNs_" + moduleName).c_str()); GTEST_LOG_(INFO) << "ModuleManagerTest, LoadNativeModuleTest_008 end"; } @@ -245,7 +251,13 @@ HWTEST_F(ModuleManagerTest, LoadNativeModuleTest_009, TestSize.Level1) std::shared_ptr moduleManager = std::make_shared(); ASSERT_NE(nullptr, moduleManager); + std::string nsName; + bool res = moduleManager->GetLdNamespaceName(moduleName, nsName); + EXPECT_EQ(res, false); moduleManager->CreateLdNamespace(moduleName, libPath, false); + res = moduleManager->GetLdNamespaceName(moduleName, nsName); + EXPECT_EQ(res, true); + EXPECT_STREQ(nsName.c_str(), ("moduleNs_" + moduleName).c_str()); std::vector appLibPath; moduleManager->SetAppLibPath(moduleName, appLibPath, false); GTEST_LOG_(INFO) << "ModuleManagerTest, LoadNativeModuleTest_009 end";