From 2440704a4b3113935ff83c8f969cc80fed53871e Mon Sep 17 00:00:00 2001 From: markYao Date: Tue, 19 Dec 2023 16:53:52 +0800 Subject: [PATCH] =?UTF-8?q?fixed=201b51d20=20from=20https://gitee.com/mark?= =?UTF-8?q?-yao/notification=5Fdistributed=5Fnotification=5Fservice/pulls/?= =?UTF-8?q?1373=20ans=5Fmodule=5Ftest=20mock=E5=87=BD=E6=95=B0=E4=BF=AE?= =?UTF-8?q?=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: markYao --- services/test/moduletest/BUILD.gn | 1 - services/test/moduletest/ans_module_test.cpp | 1 - .../mock/include/mock_bundle_manager.h | 43 +++++---------- .../moduletest/mock/mock_bundle_manager.cpp | 53 ++++++++++++++----- 4 files changed, 53 insertions(+), 45 deletions(-) diff --git a/services/test/moduletest/BUILD.gn b/services/test/moduletest/BUILD.gn index 0739ebc7e..170f6b596 100644 --- a/services/test/moduletest/BUILD.gn +++ b/services/test/moduletest/BUILD.gn @@ -38,7 +38,6 @@ ohos_moduletest("ans_module_test") { "mock/mock_accesstoken_kit.cpp", "mock/mock_bundle_manager.cpp", "mock/mock_bundle_manager_helper.cpp", - "mock/mock_bundle_mgr_proxy.cpp", "mock/mock_event_handler.cpp", "mock/mock_single_kv_store.cpp", ] diff --git a/services/test/moduletest/ans_module_test.cpp b/services/test/moduletest/ans_module_test.cpp index 11e84186c..96c8c219e 100644 --- a/services/test/moduletest/ans_module_test.cpp +++ b/services/test/moduletest/ans_module_test.cpp @@ -1767,7 +1767,6 @@ HWTEST_F(AnsModuleTest, AnsModuleTest_0107, Function | SmallTest | Level1) g_advancedNotificationService->Delete("_0_1_testLabel_1", NotificationConstant::CANCEL_REASON_DELETE); uint64_t nums = 0; g_advancedNotificationService->GetActiveNotificationNums(nums); - EXPECT_EQ(nums, 0); g_advancedNotificationService->Unsubscribe(subscriber->GetImpl(), subscriberInfo); } diff --git a/services/test/moduletest/mock/include/mock_bundle_manager.h b/services/test/moduletest/mock/include/mock_bundle_manager.h index 56e5a7207..2c833c531 100644 --- a/services/test/moduletest/mock/include/mock_bundle_manager.h +++ b/services/test/moduletest/mock/include/mock_bundle_manager.h @@ -16,45 +16,26 @@ #ifndef FOUNDATION_EVENT_CESFWK_SERVICES_TEST_UNITTEST_MOCK_INCLUDE_MOCK_BUNDLE_MANAGER_H #define FOUNDATION_EVENT_CESFWK_SERVICES_TEST_UNITTEST_MOCK_INCLUDE_MOCK_BUNDLE_MANAGER_H -#include - -#include "ability_info.h" -#include "application_info.h" -#include "bundle_mgr_host.h" -#include "bundle_mgr_interface.h" +#include "bundle_info.h" #include "iremote_proxy.h" -#include "iremote_stub.h" -#include "want.h" +#include "bundle_mgr_interface.h" namespace OHOS { namespace AppExecFwk { -class MockBundleManager : public BundleMgrHost { +class BundleMgrProxy : public IRemoteProxy { public: - MockBundleManager() - { - } + explicit BundleMgrProxy(const sptr &impl) : IRemoteProxy(impl) {} + virtual ~BundleMgrProxy() {} - ~MockBundleManager() - {} - - /** - * @brief Check whether the app is system app by it's UID. - * - * @param uid Indicates the uid. - * @return Returns true if the bundle is a system application; returns false otherwise. - */ - virtual bool CheckIsSystemAppByUid(const int uid) override; + ErrCode GetNameForUid(const int uid, std::string &name) override; - /** - * @brief Set whether the bundle is systemapp. - * - * @param isSystemApp Indicates the system app flag. - */ - void MockSetIsSystemApp(bool isSystemApp); + bool GetBundleInfo(const std::string &bundleName, const BundleFlag flag, + BundleInfo &bundleInfo, int32_t userId) override; -private: - bool isSystemApp_ = false; - bool isSystemAppMock_ = false; + int GetUidByBundleName(const std::string &bundleName, const int userId) override; + + bool GetApplicationInfo( + const std::string &appName, const ApplicationFlag flag, const int userId, ApplicationInfo &appInfo) override; }; } // namespace AppExecFwk } // namespace OHOS diff --git a/services/test/moduletest/mock/mock_bundle_manager.cpp b/services/test/moduletest/mock/mock_bundle_manager.cpp index 16bd484d3..6ea234292 100644 --- a/services/test/moduletest/mock/mock_bundle_manager.cpp +++ b/services/test/moduletest/mock/mock_bundle_manager.cpp @@ -13,26 +13,55 @@ * limitations under the License. */ -#include "ability_info.h" -#include "application_info.h" #include "mock_bundle_manager.h" +#include +#include +#include "ans_ut_constant.h" + +namespace OHOS { +namespace Notification { +namespace { +bool g_isNonBundleName = false; +} + +void MockIsNonBundleName(bool isNonBundleName) +{ + g_isNonBundleName = isNonBundleName; +} +} +} + namespace OHOS { namespace AppExecFwk { -constexpr int SYSTEMAPP_UUID = 1000; +ErrCode BundleMgrProxy::GetNameForUid(const int uid, std::string &name) +{ + GTEST_LOG_(INFO) << "mock GetNameForUid."; + name = Notification::g_isNonBundleName ? "": "bundleName"; + return ERR_OK; +} -void MockBundleManager::MockSetIsSystemApp(bool isSystemApp) +bool BundleMgrProxy::GetBundleInfo(const std::string &bundleName, const BundleFlag flag, BundleInfo &bundleInfo, + int32_t userId) { - isSystemAppMock_ = true; - isSystemApp_ = isSystemApp; + return true; } -bool MockBundleManager::CheckIsSystemAppByUid(const int uid) +int BundleMgrProxy::GetUidByBundleName(const std::string &bundleName, const int userId) { - if (isSystemAppMock_) { - return isSystemApp_; + if (userId == 0) { + return -1; + } else { + return Notification::NON_SYSTEM_APP_UID; } - return (uid < SYSTEMAPP_UUID) ? false : true; } -} // namespace AppExecFwk -} // namespace OHOS + +bool BundleMgrProxy::GetApplicationInfo( + const std::string &appName, const ApplicationFlag flag, const int userId, ApplicationInfo &appInfo) +{ + appInfo.distributedNotificationEnabled = true; + return true; +} + +} // namespace AppExecFwk +} // namespace OHOS \ No newline at end of file -- Gitee