diff --git a/services/test/moduletest/BUILD.gn b/services/test/moduletest/BUILD.gn index 0739ebc7e796c618dd4efb2082f11048b093f5ea..170f6b5962e35d5aa78265c798379cbd240091c7 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 11e84186c1438a4ff04cdcddfede6ea2425ab005..96c8c219edcc4ad4ec91641900e8701d9987d09f 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 56e5a7207145bb5ecf6cf7be49708a5b5baa9a84..2c833c5313fc222f52ce933d9fe9ec003d95302e 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 16bd484d3d77dc39222139291b40db7e8950cda0..6ea234292efd5d083ed67429144d867da240b65b 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