From d7871680a16e62b9b23bf853802aa11da562eebd Mon Sep 17 00:00:00 2001 From: guxiang Date: Sun, 15 Jun 2025 19:14:11 +0800 Subject: [PATCH] tdd_ans_notification Signed-off-by: guxiang --- .../src/listener/ans_subscriber_listener.cpp | 7 +- frameworks/core/test/unittest/BUILD.gn | 3 + .../ans_manager_death_recipient_test/BUILD.gn | 55 ++ .../ans_manager_death_recipient_unit_test.cpp | 95 +++ .../ans_notification_unit_test.cpp | 123 ++++ .../ans_subscriber_listener_test/BUILD.gn | 51 ++ .../ans_subscriber_listener_unit_test.cpp | 638 ++++++++++++++++++ .../unittest/dialog_status_data_test/BUILD.gn | 51 ++ .../dialog_status_data_unit_test.cpp | 54 ++ .../unittest/mock/mock_service_registry.h | 71 ++ 10 files changed, 1147 insertions(+), 1 deletion(-) create mode 100644 frameworks/core/test/unittest/ans_manager_death_recipient_test/BUILD.gn create mode 100644 frameworks/core/test/unittest/ans_manager_death_recipient_test/ans_manager_death_recipient_unit_test.cpp create mode 100644 frameworks/core/test/unittest/ans_subscriber_listener_test/BUILD.gn create mode 100644 frameworks/core/test/unittest/ans_subscriber_listener_test/ans_subscriber_listener_unit_test.cpp create mode 100644 frameworks/core/test/unittest/dialog_status_data_test/BUILD.gn create mode 100644 frameworks/core/test/unittest/dialog_status_data_test/dialog_status_data_unit_test.cpp create mode 100644 frameworks/core/test/unittest/mock/mock_service_registry.h diff --git a/frameworks/core/src/listener/ans_subscriber_listener.cpp b/frameworks/core/src/listener/ans_subscriber_listener.cpp index 2ee4e4e36..846b76f85 100644 --- a/frameworks/core/src/listener/ans_subscriber_listener.cpp +++ b/frameworks/core/src/listener/ans_subscriber_listener.cpp @@ -14,6 +14,8 @@ */ #include "ans_subscriber_listener.h" + +#include "ans_log_wrapper.h" #include "notification_constant.h" #include "hitrace_meter_adapter.h" #include "iservice_registry.h" @@ -61,7 +63,10 @@ ErrCode SubscriberListener::OnConsumed( ANS_LOGE("Subscriber is nullptr"); return ERR_INVALID_DATA; } - + if (notificationMap == nullptr) { + ANS_LOGE("OnConsumed fail cause notificationMap is null."); + return ERR_INVALID_DATA; + } std::shared_ptr sharedNotification = std::make_shared(*notification); #ifdef NOTIFICATION_SMART_REMINDER_SUPPORTED if (!subscriber->ProcessSyncDecision(subscriber->GetDeviceType(), sharedNotification)) { diff --git a/frameworks/core/test/unittest/BUILD.gn b/frameworks/core/test/unittest/BUILD.gn index ad69cf1a1..e5cc7121f 100644 --- a/frameworks/core/test/unittest/BUILD.gn +++ b/frameworks/core/test/unittest/BUILD.gn @@ -25,5 +25,8 @@ group("unittest") { "ans_subscriber_proxy_branch_test:unittest", "ans_subscriber_proxy_test:unittest", "swing_callback_test:unittest", + "ans_subscriber_listener_test:unittest", + "dialog_status_data_test:unittest", + "ans_manager_death_recipient_test:unittest", ] } diff --git a/frameworks/core/test/unittest/ans_manager_death_recipient_test/BUILD.gn b/frameworks/core/test/unittest/ans_manager_death_recipient_test/BUILD.gn new file mode 100644 index 000000000..9fdc08af0 --- /dev/null +++ b/frameworks/core/test/unittest/ans_manager_death_recipient_test/BUILD.gn @@ -0,0 +1,55 @@ +# Copyright (c) 2022-2023 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import("//base/notification/distributed_notification_service/notification.gni") +import("//build/ohos.gni") +import("//build/test.gni") + +module_output_path = + "${component_name}/distributed_notification_service/unittest" + +ohos_unittest("ans_manager_death_recipient_test") { + module_out_path = module_output_path + include_dirs = [ + "${core_path}/common/include", + "${core_path}/include", + "../mock/", + ] + + sources = [ + "${core_path}/src/manager/ans_manager_death_recipient.cpp", + "ans_manager_death_recipient_unit_test.cpp", + ] + + deps = [ + "${frameworks_module_ans_path}:ans_innerkits", + ] + + external_deps = [ + "ability_base:zuri", + "hilog:libhilog", + "os_account:os_account_innerkits", + "samgr:samgr_proxy", + "googletest:gmock_main", + ] + + subsystem_name = "${subsystem_name}" + part_name = "${component_name}" +} + +group("unittest") { + testonly = true + deps = [] + + deps += [ ":ans_manager_death_recipient_test" ] +} \ No newline at end of file diff --git a/frameworks/core/test/unittest/ans_manager_death_recipient_test/ans_manager_death_recipient_unit_test.cpp b/frameworks/core/test/unittest/ans_manager_death_recipient_test/ans_manager_death_recipient_unit_test.cpp new file mode 100644 index 000000000..ae6876194 --- /dev/null +++ b/frameworks/core/test/unittest/ans_manager_death_recipient_test/ans_manager_death_recipient_unit_test.cpp @@ -0,0 +1,95 @@ +/* + * Copyright (c) 2024-2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#include +#include "gtest/gtest.h" +#define private public +#include "ans_inner_errors.h" +#include "ans_manager_death_recipient.h" +#include "iservice_registry.h" +#include "notification_helper.h" +#undef private +#include "mock_service_registry.h" + +using namespace testing::ext; + +extern void MockGetSystemAbilityManager(bool mockRet); + +namespace OHOS { +namespace Notification { +class AnsManagerDeathRecipientTest : public ::testing::Test { +protected: + void SetUp(); + void TearDown() override {} + sptr systemAbilityManager_ = nullptr; + sptr mockSAMgr_ = nullptr; +}; + +void AnsManagerDeathRecipientTest::SetUp() +{ + std::cout << "AnsManagerDeathRecipientTest SetUp" << std::endl; + mockSAMgr_ = new (std::nothrow) MockSystemAbilityManager(); + systemAbilityManager_ = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager(); + SystemAbilityManagerClient::GetInstance().systemAbilityManager_ = mockSAMgr_; +} + +/** + * @tc.name : SubscribeSAManagerTest_0100 + * @tc.desc : Test Marshalling when SubscribeSystemAbility fail + */ +HWTEST_F(AnsManagerDeathRecipientTest, SubscribeSAManagerTest_0100, Function | MediumTest | Level1) +{ + auto ansManagerDeathRecipient = OHOS::DelayedSingleton::GetInstance(); + ansManagerDeathRecipient->SubscribeSAManager(); + EXPECT_EQ(ansManagerDeathRecipient->statusChangeListener_, nullptr); +} + +/** + * @tc.name : SubscribeSAManagerTest_0200 + * @tc.desc : Test Marshalling with none null statusChangeListener + */ +HWTEST_F(AnsManagerDeathRecipientTest, SubscribeSAManagerTest_0200, Function | MediumTest | Level1) +{ + auto ansManagerDeathRecipient = OHOS::DelayedSingleton::GetInstance(); + ansManagerDeathRecipient->statusChangeListener_ = + new (std::nothrow) AnsManagerDeathRecipient::SystemAbilityStatusChangeListener(); + ansManagerDeathRecipient->SubscribeSAManager(); + EXPECT_NE(ansManagerDeathRecipient->statusChangeListener_, nullptr); +} + +/** + * @tc.name : SubscribeSAManagerTest_0300 + * @tc.desc : Test Marshalling with null systemAbilityManager + */ +HWTEST_F(AnsManagerDeathRecipientTest, SubscribeSAManagerTest_0300, Function | MediumTest | Level1) +{ + auto ansManagerDeathRecipient = OHOS::DelayedSingleton::GetInstance(); + ansManagerDeathRecipient->SubscribeSAManager(); + EXPECT_NE(ansManagerDeathRecipient->statusChangeListener_, nullptr); +} + +/** + * @tc.name : OnRemoveSystemAbility_0100 + * @tc.desc : Test SystemAbility remove success + */ +HWTEST_F(AnsManagerDeathRecipientTest, OnRemoveSystemAbility_0100, Function | MediumTest | Level1) +{ + auto ansManagerDeathRecipient = OHOS::DelayedSingleton::GetInstance(); + ansManagerDeathRecipient->SubscribeSAManager(); + ansManagerDeathRecipient->statusChangeListener_->OnAddSystemAbility(0, ""); + ansManagerDeathRecipient->statusChangeListener_->OnRemoveSystemAbility(0, ""); + EXPECT_NE(ansManagerDeathRecipient->statusChangeListener_, nullptr); +} +} // namespace Notification +} // namespace OHOS \ No newline at end of file diff --git a/frameworks/core/test/unittest/ans_notification_test/ans_notification_unit_test.cpp b/frameworks/core/test/unittest/ans_notification_test/ans_notification_unit_test.cpp index 1b9b7958c..dfbc7ab6f 100644 --- a/frameworks/core/test/unittest/ans_notification_test/ans_notification_unit_test.cpp +++ b/frameworks/core/test/unittest/ans_notification_test/ans_notification_unit_test.cpp @@ -128,6 +128,22 @@ HWTEST_F(AnsNotificationUnitTest, GetAnsManagerProxy_0100, Function | MediumTest EXPECT_EQ(res, false); } +/* + * @tc.name: SetNotificationSlotFlagsAsBundle_0100 + * @tc.desc: test GetNotificationSlotFlagsAsBundle. + * @tc.type: FUNC + * @tc.require: #I62SME + */ +HWTEST_F(AnsNotificationUnitTest, SetNotificationSlotFlagsAsBundle_0100, Function | MediumTest | Level1) +{ + MockWriteInterfaceToken(false); + NotificationBundleOption bundleOptions; + bundleOptions.SetBundleName("bundleName"); + uint64_t num = 1; + ErrCode ret1 = ans_->SetNotificationSlotFlagsAsBundle(bundleOptions, num); + EXPECT_EQ(ret1, ERR_ANS_SERVICE_NOT_CONNECTED); +} + /* * @tc.name: AddSlotByType_0100 * @tc.desc: test AddSlotByType ErrCode ERR_ANS_SERVICE_NOT_CONNECTED. @@ -218,6 +234,28 @@ HWTEST_F(AnsNotificationUnitTest, GetNotificationSlotNumAsBundle_0100, Function EXPECT_EQ(ret1, ERR_ANS_SERVICE_NOT_CONNECTED); } +/* + * @tc.name: GetNotificationSlotNumAsBundle_0200 + * @tc.desc: test GetNotificationSlotNumAsBundle ErrCode ERR_OK. + * @tc.type: FUNC + * @tc.require: #I62SME + */ +HWTEST_F(AnsNotificationUnitTest, GetNotificationSlotNumAsBundle_0200, Function | MediumTest | Level1) +{ + MockWriteInterfaceToken(false); + sptr iremoteObjects = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObjects); + std::shared_ptr proxy = std::make_shared(iremoteObjects); + ASSERT_NE(nullptr, proxy); + ans_->GetAnsManagerProxy(); + NotificationBundleOption bundleOptions; + std::string bundleName = "bundleName"; + bundleOptions.SetBundleName(bundleName); + uint64_t num; + ErrCode ret = ans_->GetNotificationSlotNumAsBundle(bundleOptions, num); + EXPECT_EQ(ret, ERR_ANS_SERVICE_NOT_CONNECTED); +} + /* * @tc.name: GetNotificationSlotFlagsAsBundle_0100 * @tc.desc: test GetNotificationSlotFlagsAsBundle. @@ -261,6 +299,52 @@ HWTEST_F(AnsNotificationUnitTest, GetNotificationSlotFlagsAsBundle_0200, Functio EXPECT_EQ(ret1, ERR_ANS_INVALID_PARAM); } +/* + * @tc.name: GetNotificationSlotFlagsAsBundle_0300 + * @tc.desc: test GetNotificationSlotFlagsAsBundle errCode ERR_OK. + * @tc.type: FUNC + * @tc.require: #I62SME + */ +HWTEST_F(AnsNotificationUnitTest, GetNotificationSlotFlagsAsBundle_0300, Function | MediumTest | Level1) +{ + MockWriteInterfaceToken(false); + sptr iremoteObjects = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObjects); + std::shared_ptr proxy = std::make_shared(iremoteObjects); + ASSERT_NE(nullptr, proxy); + ans_->GetAnsManagerProxy(); + NotificationBundleOption bundleOptions; + std::string bundleName = "bundleName"; + bundleOptions.SetBundleName(bundleName); + uint32_t num = 10; + ErrCode ret1 = ans_->GetNotificationSlotFlagsAsBundle(bundleOptions, num); + EXPECT_EQ(ret1, ERR_ANS_SERVICE_NOT_CONNECTED); +} + +/* + * @tc.name: AddNotificationSlots_0100 + * @tc.desc: test AddNotificationSlots exceed MAX_SLOT_NUM. + * @tc.type: FUNC + * @tc.require: #I62SME + */ +HWTEST_F(AnsNotificationUnitTest, AddNotificationSlots_0100, Function | MediumTest | Level1) +{ + MockWriteInterfaceToken(false); + sptr iremoteObjects = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObjects); + std::shared_ptr proxy = std::make_shared(iremoteObjects); + ASSERT_NE(nullptr, proxy); + ans_->GetAnsManagerProxy(); + std::vector slots; + for (int i = 0; i < MAX_SLOT_NUM + 1; i++) { + NotificationConstant::SlotType slotType = NotificationConstant::SlotType::CUSTOM; + sptr notificationSlot = new (std::nothrow) NotificationSlot(slotType); + slots.push_back(*notificationSlot); + } + ErrCode ret = ans_->AddNotificationSlots(slots); + EXPECT_EQ(ret, ERR_ANS_SERVICE_NOT_CONNECTED); +} + /* * @tc.name: SetNotificationSlotFlagsAsBundle_0200 * @tc.desc: test GetNotificationSlotFlagsAsBundle. @@ -282,6 +366,27 @@ HWTEST_F(AnsNotificationUnitTest, SetNotificationSlotFlagsAsBundle_0200, Functio EXPECT_EQ(ret1, ERR_ANS_INVALID_PARAM); } +/* + * @tc.name: SetNotificationSlotFlagsAsBundle_0300 + * @tc.desc: test GetNotificationSlotFlagsAsBundle. + * @tc.type: FUNC + * @tc.require: #I62SME + */ +HWTEST_F(AnsNotificationUnitTest, SetNotificationSlotFlagsAsBundle_0300, Function | MediumTest | Level1) +{ + MockWriteInterfaceToken(false); + sptr iremoteObjects = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObjects); + std::shared_ptr proxy = std::make_shared(iremoteObjects); + ASSERT_NE(nullptr, proxy); + ans_->GetAnsManagerProxy(); + NotificationBundleOption bundleOptions; + bundleOptions.SetBundleName("bundleName"); + uint64_t num = 1; + ErrCode ret1 = ans_->SetNotificationSlotFlagsAsBundle(bundleOptions, num); + EXPECT_EQ(ret1, ERR_ANS_SERVICE_NOT_CONNECTED); +} + /* * @tc.name: CanPopEnableNotificationDialog_0100 * @tc.desc: test CanPopEnableNotificationDialog. @@ -1638,5 +1743,23 @@ HWTEST_F(AnsNotificationUnitTest, GetNotificationSettings_0100, Function | Mediu ErrCode result = ans_->GetNotificationSettings(slotFlags); EXPECT_EQ(result, ERR_ANS_SERVICE_NOT_CONNECTED); } + +/* + * @tc.name: GetNotificationSettings_0200 + * @tc.desc: test GetNotificationSetting. + * @tc.type: FUNC + */ +HWTEST_F(AnsNotificationUnitTest, GetNotificationSettings_0200, Function | MediumTest | Level1) +{ + MockWriteInterfaceToken(false); + sptr iremoteObjects = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObjects); + std::shared_ptr proxy = std::make_shared(iremoteObjects); + ASSERT_NE(nullptr, proxy); + ans_->GetAnsManagerProxy(); + uint32_t slotFlags = 0; + ErrCode result = ans_->GetNotificationSettings(slotFlags); + EXPECT_EQ(result, ERR_ANS_SERVICE_NOT_CONNECTED); +} } // namespace Notification } // namespace OHOS diff --git a/frameworks/core/test/unittest/ans_subscriber_listener_test/BUILD.gn b/frameworks/core/test/unittest/ans_subscriber_listener_test/BUILD.gn new file mode 100644 index 000000000..44590125c --- /dev/null +++ b/frameworks/core/test/unittest/ans_subscriber_listener_test/BUILD.gn @@ -0,0 +1,51 @@ +# Copyright (c) 2022-2023 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import("//base/notification/distributed_notification_service/notification.gni") +import("//build/ohos.gni") +import("//build/test.gni") + +module_output_path = + "${component_name}/distributed_notification_service/unittest" + +ohos_unittest("ans_subscriber_listener_test") { + module_out_path = module_output_path + include_dirs = [ + "${core_path}/include", + "../mock/", + ] + + sources = [ + "${core_path}/src/listener/ans_subscriber_listener.cpp", + "ans_subscriber_listener_unit_test.cpp", + ] + + deps = [ "${frameworks_module_ans_path}:ans_innerkits" ] + + external_deps = [ + "ability_base:zuri", + "c_utils:utils", + "ipc:ipc_single", + "hilog:libhilog", + ] + + subsystem_name = "${subsystem_name}" + part_name = "${component_name}" +} + +group("unittest") { + testonly = true + deps = [] + + deps += [ ":ans_subscriber_listener_test" ] +} \ No newline at end of file diff --git a/frameworks/core/test/unittest/ans_subscriber_listener_test/ans_subscriber_listener_unit_test.cpp b/frameworks/core/test/unittest/ans_subscriber_listener_test/ans_subscriber_listener_unit_test.cpp new file mode 100644 index 000000000..a3611dc3c --- /dev/null +++ b/frameworks/core/test/unittest/ans_subscriber_listener_test/ans_subscriber_listener_unit_test.cpp @@ -0,0 +1,638 @@ +/* + * Copyright (c) 2024-2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#include +#include "gtest/gtest.h" +#define private public +#include "ans_subscriber_listener.h" +#undef private + +using namespace testing::ext; +namespace OHOS { +namespace Notification { +class SubscriberListenerTest : public ::testing::Test { +public: + static void SetUpTestCase(){}; + static void TearDownTestCase(){}; + void SetUp(){}; + void TearDown(){}; +}; + +class TestSubscriber : public NotificationSubscriber { +public: + void OnDisconnected() override + {} + void OnDied() override + {} + void OnUpdate(const std::shared_ptr &sortingMap) override + {} + void OnDoNotDisturbDateChange(const std::shared_ptr &date) override + {} + void OnConnected() override + {} + void OnEnabledNotificationChanged(const std::shared_ptr &callbackData) override + {} + void OnCanceled(const std::shared_ptr &request, + const std::shared_ptr &sortingMap, int deleteReason) override + {} + void OnBadgeChanged(const std::shared_ptr &badgeData) override + {} + void OnBadgeEnabledChanged(const sptr &callbackData) override + {} + void OnConsumed(const std::shared_ptr &request, + const std::shared_ptr &sortingMap) override + {} + + void OnBatchCanceled(const std::vector> &requestList, + const std::shared_ptr &sortingMap, int32_t deleteReason) override + {} + +#ifdef NOTIFICATION_SMART_REMINDER_SUPPORTED + bool NotificationSubscriber::ProcessSyncDecision( + const std::string &deviceType, std::shared_ptr ¬ification) override + { + return notification->GetNotificationRequestPoint() != nullptr; + } +#endif + + bool HasOnBatchCancelCallback() override + { + return true; + } +}; + +class TestNoBatchSubscriber : public NotificationSubscriber { +public: + void OnDisconnected() override + {} + void OnDied() override + {} + void OnUpdate(const std::shared_ptr &sortingMap) override + {} + void OnDoNotDisturbDateChange(const std::shared_ptr &date) override + {} + void OnConnected() override + {} + void OnEnabledNotificationChanged(const std::shared_ptr &callbackData) override + {} + void OnCanceled(const std::shared_ptr &request, + const std::shared_ptr &sortingMap, int deleteReason) override + {} + void OnBadgeChanged(const std::shared_ptr &badgeData) override + {} + void OnBadgeEnabledChanged(const sptr &callbackData) override + {} + void OnConsumed(const std::shared_ptr &request, + const std::shared_ptr &sortingMap) override + {} + + void OnBatchCanceled(const std::vector> &requestList, + const std::shared_ptr &sortingMap, int32_t deleteReason) override + {} + + bool HasOnBatchCancelCallback() override + { + return false; + } +}; + +/** + * @tc.name : OnConnected_0100 + * @tc.desc : Test OnConnected success + */ +HWTEST_F(SubscriberListenerTest, OnConnected_0100, Function | MediumTest | Level1) +{ + std::shared_ptr subscriber = std::make_shared(); + sptr listener = new (std::nothrow) SubscriberListener(subscriber); + ErrCode result = listener->OnConnected(); + EXPECT_EQ(result, ERR_OK); +} + +/** + * @tc.name : OnConnected_0200 + * @tc.desc : Test OnConnected invalid data + */ +HWTEST_F(SubscriberListenerTest, OnConnected_0200, Function | MediumTest | Level1) +{ + sptr listener = new (std::nothrow) SubscriberListener(nullptr); + ErrCode result = listener->OnConnected(); + EXPECT_EQ(result, ERR_INVALID_DATA); +} + +/** + * @tc.name : OnDisconnected_0100 + * @tc.desc : Test OnConnected success + */ +HWTEST_F(SubscriberListenerTest, OnDisconnected_0100, Function | MediumTest | Level1) +{ + std::shared_ptr subscriber = std::make_shared(); + sptr listener = new (std::nothrow) SubscriberListener(subscriber); + ErrCode result = listener->OnDisconnected(); + EXPECT_EQ(result, ERR_OK); +} + +/** + * @tc.name : OnDisconnected_0200 + * @tc.desc : Test OnConnected invalid data + */ +HWTEST_F(SubscriberListenerTest, OnDisconnected_0200, Function | MediumTest | Level1) +{ + sptr listener = new (std::nothrow) SubscriberListener(nullptr); + ErrCode result = listener->OnDisconnected(); + EXPECT_EQ(result, ERR_INVALID_DATA); +} + +/** + * @tc.name : OnConsumed_0100 + * @tc.desc : Test OnConsumed invalid data + */ +HWTEST_F(SubscriberListenerTest, OnConsumed_0100, Function | MediumTest | Level1) +{ + sptr listener = new (std::nothrow) SubscriberListener(nullptr); + ErrCode result = listener->OnConsumed(nullptr, nullptr); + EXPECT_EQ(result, ERR_INVALID_DATA); +} + +#ifdef NOTIFICATION_SMART_REMINDER_SUPPORTED +/** + * @tc.name : OnConsumed_0200 + * @tc.desc : Test OnConsumed invalid operation + */ +HWTEST_F(SubscriberListenerTest, OnConsumed_0200, Function | MediumTest | Level1) +{ + sptr notification = new (std::nothrow) Notification("001", nullptr); + sptr notificationMap = new (std::nothrow) NotificationSortingMap(); + std::shared_ptr subscriber = std::make_shared(); + sptr listener = new (std::nothrow) SubscriberListener(subscriber); + ErrCode result = listener->OnConsumed(notification, notificationMap); + EXPECT_EQ(result, ERR_INVALID_OPERATION); +} +#endif + +/** + * @tc.name : OnConsumed_0300 + * @tc.desc : Test OnConsumed success + */ +HWTEST_F(SubscriberListenerTest, OnConsumed_0300, Function | MediumTest | Level1) +{ + sptr request = new (std::nothrow) NotificationRequest(1); + sptr notification = new (std::nothrow) Notification("001", request); + sptr notificationMap = new (std::nothrow) NotificationSortingMap(); + std::shared_ptr subscriber = std::make_shared(); + sptr listener = new (std::nothrow) SubscriberListener(subscriber); + ErrCode result = listener->OnConsumed(notification, notificationMap); + EXPECT_EQ(result, ERR_OK); +} + +/** + * @tc.name : OnConsumed_0400 + * @tc.desc : Test one param OnConsumed success + */ +HWTEST_F(SubscriberListenerTest, OnConsumed_0400, Function | MediumTest | Level1) +{ + sptr request = new (std::nothrow) NotificationRequest(1); + sptr notification = new (std::nothrow) Notification("001", request); + std::shared_ptr subscriber = std::make_shared(); + sptr listener = new (std::nothrow) SubscriberListener(subscriber); + ErrCode result = listener->OnConsumed(notification); + EXPECT_EQ(result, ERR_INVALID_DATA); +} + +/** + * @tc.name : OnConsumedWithMaxCapacity_0100 + * @tc.desc : Test OnConsumedWithMaxCapacity success + */ +HWTEST_F(SubscriberListenerTest, OnConsumedWithMaxCapacity_0100, Function | MediumTest | Level1) +{ + sptr request = new (std::nothrow) NotificationRequest(1); + sptr notification = new (std::nothrow) Notification("001", request); + sptr notificationMap = new (std::nothrow) NotificationSortingMap(); + std::shared_ptr subscriber = std::make_shared(); + sptr listener = new (std::nothrow) SubscriberListener(subscriber); + ErrCode result = listener->OnConsumedWithMaxCapacity(notification, notificationMap); + EXPECT_EQ(result, ERR_OK); +} + +/** + * @tc.name : OnConsumedWithMaxCapacity_0200 + * @tc.desc : Test one param OnConsumedWithMaxCapacity success + */ +HWTEST_F(SubscriberListenerTest, OnConsumedWithMaxCapacity_0200, Function | MediumTest | Level1) +{ + sptr request = new (std::nothrow) NotificationRequest(1); + sptr notification = new (std::nothrow) Notification("001", request); + std::shared_ptr subscriber = std::make_shared(); + sptr listener = new (std::nothrow) SubscriberListener(subscriber); + ErrCode result = listener->OnConsumedWithMaxCapacity(notification); + EXPECT_EQ(result, ERR_INVALID_DATA); +} + +/** + * @tc.name : OnConsumedList_0100 + * @tc.desc : Test OnConsumedList success + */ +HWTEST_F(SubscriberListenerTest, OnConsumedList_0100, Function | MediumTest | Level1) +{ + sptr request = new (std::nothrow) NotificationRequest(1); + sptr notification = new (std::nothrow) Notification("001", request); + std::vector> notifications; + notifications.push_back(notification); + sptr notificationMap = new (std::nothrow) NotificationSortingMap(); + std::shared_ptr subscriber = std::make_shared(); + sptr listener = new (std::nothrow) SubscriberListener(subscriber); + ErrCode result = listener->OnConsumedList(notifications, notificationMap); + EXPECT_EQ(result, ERR_OK); +} + +/** + * @tc.name : OnConsumedList_0200 + * @tc.desc : Test one param OnConsumedList success + */ +HWTEST_F(SubscriberListenerTest, OnConsumedList_0200, Function | MediumTest | Level1) +{ + sptr request = new (std::nothrow) NotificationRequest(1); + sptr notification = new (std::nothrow) Notification("001", request); + std::vector> notifications; + notifications.push_back(notification); + std::shared_ptr subscriber = std::make_shared(); + sptr listener = new (std::nothrow) SubscriberListener(subscriber); + ErrCode result = listener->OnConsumedList(notifications); + EXPECT_EQ(result, ERR_OK); +} + +/** + * @tc.name : OnCanceled_0100 + * @tc.desc : Test OnCanceled invalid data + */ +HWTEST_F(SubscriberListenerTest, OnCanceled_0100, Function | MediumTest | Level1) +{ + sptr notification = new (std::nothrow) Notification("001", nullptr); + sptr listener = new (std::nothrow) SubscriberListener(nullptr); + ErrCode result = listener->OnCanceled(notification, nullptr, 0); + EXPECT_EQ(result, ERR_INVALID_DATA); +} + +/** + * @tc.name : OnCanceled_0200 + * @tc.desc : Test OnCanceled notificationMap nullptr + */ +HWTEST_F(SubscriberListenerTest, OnCanceled_0200, Function | MediumTest | Level1) +{ + sptr notification = new (std::nothrow) Notification("001", nullptr); + std::shared_ptr subscriber = std::make_shared(); + sptr listener = new (std::nothrow) SubscriberListener(subscriber); + ErrCode result = listener->OnCanceled(notification, nullptr, 0); + EXPECT_EQ(result, ERR_OK); +} + +/** + * @tc.name : OnCanceled_0300 + * @tc.desc : Test OnCanceled notificationMap not nullptr + */ +HWTEST_F(SubscriberListenerTest, OnCanceled_0300, Function | MediumTest | Level1) +{ + sptr notification = new (std::nothrow) Notification("001", nullptr); + std::shared_ptr subscriber = std::make_shared(); + sptr notificationMap = new (std::nothrow) NotificationSortingMap(); + sptr listener = new (std::nothrow) SubscriberListener(subscriber); + ErrCode result = listener->OnCanceled(notification, notificationMap, 0); + EXPECT_EQ(result, ERR_OK); +} + +/** + * @tc.name : OnCanceled_0400 + * @tc.desc : Test two params OnCanceled + */ +HWTEST_F(SubscriberListenerTest, OnCanceled_0400, Function | MediumTest | Level1) +{ + sptr notification = new (std::nothrow) Notification("001", nullptr); + std::shared_ptr subscriber = std::make_shared(); + sptr listener = new (std::nothrow) SubscriberListener(subscriber); + ErrCode result = listener->OnCanceled(notification, 0); + EXPECT_EQ(result, ERR_OK); +} + +/** + * @tc.name : OnCanceledWithMaxCapacity_0100 + * @tc.desc : Test OnCanceledWithMaxCapacity success + */ +HWTEST_F(SubscriberListenerTest, OnCanceledWithMaxCapacity_0100, Function | MediumTest | Level1) +{ + sptr notification = new (std::nothrow) Notification("001", nullptr); + std::shared_ptr subscriber = std::make_shared(); + sptr notificationMap = new (std::nothrow) NotificationSortingMap(); + sptr listener = new (std::nothrow) SubscriberListener(subscriber); + ErrCode result = listener->OnCanceledWithMaxCapacity(notification, notificationMap, 0); + EXPECT_EQ(result, ERR_OK); +} + +/** + * @tc.name : OnCanceledWithMaxCapacity_0200 + * @tc.desc : Test two params OnCanceledWithMaxCapacity + */ +HWTEST_F(SubscriberListenerTest, OnCanceledWithMaxCapacity_0200, Function | MediumTest | Level1) +{ + sptr notification = new (std::nothrow) Notification("001", nullptr); + std::shared_ptr subscriber = std::make_shared(); + sptr listener = new (std::nothrow) SubscriberListener(subscriber); + ErrCode result = listener->OnCanceledWithMaxCapacity(notification, 0); + EXPECT_EQ(result, ERR_OK); +} + +/** + * @tc.name : OnBatchCanceled_0100 + * @tc.desc : Test OnBatchCanceled invalid data + */ +HWTEST_F(SubscriberListenerTest, OnBatchCanceled_0100, Function | MediumTest | Level1) +{ + sptr notification = new (std::nothrow) Notification("001", nullptr); + std::vector> notifications; + notifications.push_back(notification); + sptr listener = new (std::nothrow) SubscriberListener(nullptr); + listener->OnBatchCanceled(notifications, nullptr, 0); + EXPECT_EQ(notifications.size(), 1); +} + +/** + * @tc.name : OnBatchCanceled_0200 + * @tc.desc : Test OnBatchCanceled notificationMap nullptr + */ +HWTEST_F(SubscriberListenerTest, OnBatchCanceled_0200, Function | MediumTest | Level1) +{ + sptr notification = new (std::nothrow) Notification("001", nullptr); + std::vector> notifications; + notifications.push_back(notification); + std::shared_ptr subscriber = std::make_shared(); + sptr listener = new (std::nothrow) SubscriberListener(subscriber); + listener->OnBatchCanceled(notifications, nullptr, 0); + EXPECT_EQ(notifications.size(), 1); +} + +/** + * @tc.name : OnBatchCanceled_0300 + * @tc.desc : Test OnBatchCanceled notificationMap not nullptr + */ +HWTEST_F(SubscriberListenerTest, OnBatchCanceled_0300, Function | MediumTest | Level1) +{ + sptr notification = new (std::nothrow) Notification("001", nullptr); + std::vector> notifications; + notifications.push_back(notification); + sptr notificationMap = new (std::nothrow) NotificationSortingMap(); + std::shared_ptr subscriber = std::make_shared(); + sptr listener = new (std::nothrow) SubscriberListener(subscriber); + listener->OnBatchCanceled(notifications, notificationMap, 0); + EXPECT_EQ(notifications.size(), 1); +} + +/** + * @tc.name : OnCanceledList_0100 + * @tc.desc : Test OnCanceledList invalid data + */ +HWTEST_F(SubscriberListenerTest, OnCanceledList_0100, Function | MediumTest | Level1) +{ + sptr notification = new (std::nothrow) Notification("001", nullptr); + std::vector> notifications; + notifications.push_back(notification); + sptr listener = new (std::nothrow) SubscriberListener(nullptr); + ErrCode result = listener->OnCanceledList(notifications, nullptr, 0); + EXPECT_EQ(result, ERR_INVALID_DATA); +} + +/** + * @tc.name : OnCanceledList_0200 + * @tc.desc : Test OnCanceledList called OnBatchCanceled + */ +HWTEST_F(SubscriberListenerTest, OnCanceledList_0200, Function | MediumTest | Level1) +{ + sptr notification = new (std::nothrow) Notification("001", nullptr); + std::vector> notifications; + notifications.push_back(notification); + std::shared_ptr subscriber = std::make_shared(); + sptr listener = new (std::nothrow) SubscriberListener(subscriber); + ErrCode result = listener->OnCanceledList(notifications, nullptr, 0); + EXPECT_EQ(result, ERR_INVALID_DATA); +} + +/** + * @tc.name : OnCanceledList_0300 + * @tc.desc : Test OnCanceledList called OnCanceled + */ +HWTEST_F(SubscriberListenerTest, OnCanceledList_0300, Function | MediumTest | Level1) +{ + sptr notification = new (std::nothrow) Notification("001", nullptr); + std::vector> notifications; + notifications.push_back(notification); + std::shared_ptr subscriber = std::make_shared(); + sptr listener = new (std::nothrow) SubscriberListener(subscriber); + ErrCode result = listener->OnCanceledList(notifications, nullptr, 0); + EXPECT_EQ(result, ERR_OK); +} + +/** + * @tc.name : OnCanceledList_0400 + * @tc.desc : Test two params OnCanceledList + */ +HWTEST_F(SubscriberListenerTest, OnCanceledList_0400, Function | MediumTest | Level1) +{ + sptr notification = new (std::nothrow) Notification("001", nullptr); + std::vector> notifications; + notifications.push_back(notification); + std::shared_ptr subscriber = std::make_shared(); + sptr listener = new (std::nothrow) SubscriberListener(subscriber); + ErrCode result = listener->OnCanceledList(notifications, 0); + EXPECT_EQ(result, ERR_OK); +} + +/** + * @tc.name : OnUpdated_0100 + * @tc.desc : Test OnUpdated invalid data + */ +HWTEST_F(SubscriberListenerTest, OnUpdated_0100, Function | MediumTest | Level1) +{ + sptr listener = new (std::nothrow) SubscriberListener(nullptr); + sptr notificationMap = new (std::nothrow) NotificationSortingMap(); + ErrCode result = listener->OnUpdated(notificationMap); + EXPECT_EQ(result, ERR_INVALID_DATA); +} + +/** + * @tc.name : OnUpdated_0200 + * @tc.desc : Test OnUpdated success + */ +HWTEST_F(SubscriberListenerTest, OnUpdated_0200, Function | MediumTest | Level1) +{ + std::shared_ptr subscriber = std::make_shared(); + sptr listener = new (std::nothrow) SubscriberListener(subscriber); + sptr notificationMap = new (std::nothrow) NotificationSortingMap(); + ErrCode result = listener->OnUpdated(notificationMap); + EXPECT_EQ(result, ERR_OK); +} + +/** + * @tc.name : OnDoNotDisturbDateChange_0100 + * @tc.desc : Test OnDoNotDisturbDateChange invalid data + */ +HWTEST_F(SubscriberListenerTest, OnDoNotDisturbDateChange_0100, Function | MediumTest | Level1) +{ + sptr listener = new (std::nothrow) SubscriberListener(nullptr); + sptr date = + new (std::nothrow) NotificationDoNotDisturbDate(NotificationConstant::DoNotDisturbType::ONCE, 0, 1); + ErrCode result = listener->OnDoNotDisturbDateChange(date); + EXPECT_EQ(result, ERR_INVALID_DATA); +} + +/** + * @tc.name : OnDoNotDisturbDateChange_0200 + * @tc.desc : Test OnDoNotDisturbDateChange success + */ +HWTEST_F(SubscriberListenerTest, OnDoNotDisturbDateChange_0200, Function | MediumTest | Level1) +{ + std::shared_ptr subscriber = std::make_shared(); + sptr listener = new (std::nothrow) SubscriberListener(subscriber); + sptr date = + new (std::nothrow) NotificationDoNotDisturbDate(NotificationConstant::DoNotDisturbType::ONCE, 0, 1); + ErrCode result = listener->OnDoNotDisturbDateChange(date); + EXPECT_EQ(result, ERR_OK); +} + +/** + * @tc.name : OnEnabledNotificationChanged_0100 + * @tc.desc : Test OnEnabledNotificationChanged invalid data + */ +HWTEST_F(SubscriberListenerTest, OnEnabledNotificationChanged_0100, Function | MediumTest | Level1) +{ + sptr listener = new (std::nothrow) SubscriberListener(nullptr); + sptr callbackData = + new (std::nothrow) EnabledNotificationCallbackData("", 100, true); + ErrCode result = listener->OnEnabledNotificationChanged(callbackData); + EXPECT_EQ(result, ERR_INVALID_DATA); +} + +/** + * @tc.name : OnEnabledNotificationChanged_0200 + * @tc.desc : Test OnEnabledNotificationChanged success + */ +HWTEST_F(SubscriberListenerTest, OnEnabledNotificationChanged_0200, Function | MediumTest | Level1) +{ + std::shared_ptr subscriber = std::make_shared(); + sptr listener = new (std::nothrow) SubscriberListener(subscriber); + sptr callbackData = + new (std::nothrow) EnabledNotificationCallbackData("", 100, true); + ErrCode result = listener->OnEnabledNotificationChanged(callbackData); + EXPECT_EQ(result, ERR_OK); +} + +/** + * @tc.name : OnBadgeChanged_0100 + * @tc.desc : Test OnBadgeChanged invalid data + */ +HWTEST_F(SubscriberListenerTest, OnBadgeChanged_0100, Function | MediumTest | Level1) +{ + sptr listener = new (std::nothrow) SubscriberListener(nullptr); + sptr callbackData = new (std::nothrow) BadgeNumberCallbackData("", 100, 1); + ErrCode result = listener->OnBadgeChanged(callbackData); + EXPECT_EQ(result, ERR_INVALID_DATA); +} + +/** + * @tc.name : OnBadgeChanged_0200 + * @tc.desc : Test OnBadgeChanged success + */ +HWTEST_F(SubscriberListenerTest, OnBadgeChanged_0200, Function | MediumTest | Level1) +{ + std::shared_ptr subscriber = std::make_shared(); + sptr listener = new (std::nothrow) SubscriberListener(subscriber); + sptr callbackData = new (std::nothrow) BadgeNumberCallbackData("", 100, 1); + ErrCode result = listener->OnBadgeChanged(callbackData); + EXPECT_EQ(result, ERR_OK); +} + +/** + * @tc.name : OnBadgeEnabledChanged_0100 + * @tc.desc : Test OnBadgeEnabledChanged invalid data + */ +HWTEST_F(SubscriberListenerTest, OnBadgeEnabledChanged_0100, Function | MediumTest | Level1) +{ + sptr listener = new (std::nothrow) SubscriberListener(nullptr); + sptr callbackData = + new (std::nothrow) EnabledNotificationCallbackData("", 100, true); + ErrCode result = listener->OnBadgeEnabledChanged(callbackData); + EXPECT_EQ(result, ERR_INVALID_DATA); +} + +/** + * @tc.name : OnBadgeEnabledChanged_0200 + * @tc.desc : Test OnBadgeEnabledChanged success + */ +HWTEST_F(SubscriberListenerTest, OnBadgeEnabledChanged_0200, Function | MediumTest | Level1) +{ + std::shared_ptr subscriber = std::make_shared(); + sptr listener = new (std::nothrow) SubscriberListener(subscriber); + sptr callbackData = + new (std::nothrow) EnabledNotificationCallbackData("", 100, true); + ErrCode result = listener->OnBadgeEnabledChanged(callbackData); + EXPECT_EQ(result, ERR_OK); +} + +/** + * @tc.name : OnApplicationInfoNeedChanged_0100 + * @tc.desc : Test OnApplicationInfoNeedChanged invalid data + */ +HWTEST_F(SubscriberListenerTest, OnApplicationInfoNeedChanged_0100, Function | MediumTest | Level1) +{ + sptr listener = new (std::nothrow) SubscriberListener(nullptr); + ErrCode result = listener->OnApplicationInfoNeedChanged(""); + EXPECT_EQ(result, ERR_INVALID_DATA); +} + +/** + * @tc.name : OnApplicationInfoNeedChanged_0200 + * @tc.desc : Test OnApplicationInfoNeedChanged success + */ +HWTEST_F(SubscriberListenerTest, OnApplicationInfoNeedChanged_0200, Function | MediumTest | Level1) +{ + std::shared_ptr subscriber = std::make_shared(); + sptr listener = new (std::nothrow) SubscriberListener(subscriber); + ErrCode result = listener->OnApplicationInfoNeedChanged(""); + EXPECT_EQ(result, ERR_OK); +} + +/** + * @tc.name : OnOperationResponse_0100 + * @tc.desc : Test OnOperationResponse invalid data + */ +HWTEST_F(SubscriberListenerTest, OnOperationResponse_0100, Function | MediumTest | Level1) +{ + sptr listener = new (std::nothrow) SubscriberListener(nullptr); + sptr operationInfo = new (std::nothrow) NotificationOperationInfo(); + int32_t funcResult; + ErrCode result = listener->OnOperationResponse(operationInfo, funcResult); + EXPECT_EQ(result, ERR_OK); +} + +/** + * @tc.name : OnOperationResponse_0200 + * @tc.desc : Test OnOperationResponse success + */ +HWTEST_F(SubscriberListenerTest, OnOperationResponse_0200, Function | MediumTest | Level1) +{ + std::shared_ptr subscriber = std::make_shared(); + sptr listener = new (std::nothrow) SubscriberListener(subscriber); + sptr operationInfo = new (std::nothrow) NotificationOperationInfo(); + int32_t funcResult; + ErrCode result = listener->OnOperationResponse(operationInfo, funcResult); + EXPECT_EQ(result, ERR_OK); +} +} // namespace Notification +} // namespace OHOS \ No newline at end of file diff --git a/frameworks/core/test/unittest/dialog_status_data_test/BUILD.gn b/frameworks/core/test/unittest/dialog_status_data_test/BUILD.gn new file mode 100644 index 000000000..5cf338fa3 --- /dev/null +++ b/frameworks/core/test/unittest/dialog_status_data_test/BUILD.gn @@ -0,0 +1,51 @@ +# Copyright (c) 2022-2023 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import("//base/notification/distributed_notification_service/notification.gni") +import("//build/ohos.gni") +import("//build/test.gni") + +module_output_path = + "${component_name}/distributed_notification_service/unittest" + +ohos_unittest("dialog_status_data_test") { + module_out_path = module_output_path + include_dirs = [ + "${core_path}/include", + "${core_path}/common/include", + "../mock/", + ] + + sources = [ + "${core_path}/src/dialog_status_data.cpp", + "dialog_status_data_unit_test.cpp", + ] + + external_deps = [ + "ipc:ipc_single", + "hilog:libhilog", + "os_account:os_account_innerkits", + "relational_store:native_rdb", + ] + + + subsystem_name = "${subsystem_name}" + part_name = "${component_name}" +} + +group("unittest") { + testonly = true + deps = [] + + deps += [ ":dialog_status_data_test" ] +} \ No newline at end of file diff --git a/frameworks/core/test/unittest/dialog_status_data_test/dialog_status_data_unit_test.cpp b/frameworks/core/test/unittest/dialog_status_data_test/dialog_status_data_unit_test.cpp new file mode 100644 index 000000000..6f3f40678 --- /dev/null +++ b/frameworks/core/test/unittest/dialog_status_data_test/dialog_status_data_unit_test.cpp @@ -0,0 +1,54 @@ +/* + * Copyright (c) 2024-2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#include +#include "gtest/gtest.h" +#define private public +#include "dialog_status_data.h" +#undef private + +using namespace testing::ext; +namespace OHOS { +namespace Notification { +class DialogStatusDataTest : public ::testing::Test { +protected: + void SetUp() override {} + void TearDown() override {} +}; + +/** + * @tc.name : Marshalling_0100 + * @tc.desc : Test Marshalling with valid parcel + */ +HWTEST_F(DialogStatusDataTest, Marshalling_0100, Function | MediumTest | Level1) +{ + DialogStatusData dialogStatusData(EnabledDialogStatus::ALLOW_CLICKED); + Parcel parcel; + bool result = dialogStatusData.Marshalling(parcel); + EXPECT_TRUE(result); +} + +/** + * @tc.name : Unmarshalling_0100 + * @tc.desc : Test Unmarshalling + */ +HWTEST_F(DialogStatusDataTest, Unmarshalling_0100, Function | MediumTest | Level1) +{ + DialogStatusData dialogStatusData(EnabledDialogStatus::ALLOW_CLICKED); + Parcel parcel; + DialogStatusData* dialogStatusDataPtr = dialogStatusData.Unmarshalling(parcel); + EXPECT_NE(dialogStatusDataPtr, nullptr); +} +} // namespace Notification +} // namespace OHOS \ No newline at end of file diff --git a/frameworks/core/test/unittest/mock/mock_service_registry.h b/frameworks/core/test/unittest/mock/mock_service_registry.h new file mode 100644 index 000000000..9992ebafd --- /dev/null +++ b/frameworks/core/test/unittest/mock/mock_service_registry.h @@ -0,0 +1,71 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef OHOS_NOTIFICATION_MOCK_SYSTEM_ABILITY_MANAGER_H +#define OHOS_NOTIFICATION_MOCK_SYSTEM_ABILITY_MANAGER_H + +#include "gmock/gmock.h" + +#include "iremote_object.h" +#include "iremote_stub.h" + +namespace OHOS { +namespace Notification { +class MockSystemAbilityManager : public IRemoteStub { +public: + MockSystemAbilityManager() {}; + virtual ~MockSystemAbilityManager() {}; + + MOCK_METHOD1(ListSystemAbilities, std::vector(unsigned int)); + MOCK_METHOD1(GetSystemAbility, sptr(int32_t)); + MOCK_METHOD2(GetSystemAbility, sptr(int32_t, const std::string &)); + MOCK_METHOD1(CheckSystemAbility, sptr(int32_t)); + MOCK_METHOD2(CheckSystemAbility, sptr(int32_t, const std::string &)); + MOCK_METHOD2(CheckSystemAbility, sptr(int32_t, bool &)); + MOCK_METHOD1(RemoveSystemAbility, int32_t(int32_t)); + MOCK_METHOD2(UnSubscribeSystemAbility, int32_t(int32_t, const sptr &)); + MOCK_METHOD2(AddOnDemandSystemAbilityInfo, int32_t(int32_t, const std::u16string &)); + MOCK_METHOD3(AddSystemAbility, int32_t(int32_t, const sptr &, const SAExtraProp &)); + MOCK_METHOD2(AddSystemProcess, int32_t(const std::u16string &, const sptr &)); + MOCK_METHOD2(LoadSystemAbility, sptr(int32_t, int32_t)); + MOCK_METHOD2(LoadSystemAbility, int32_t(int32_t, const sptr &)); + MOCK_METHOD3(LoadSystemAbility, int32_t(int32_t, const std::string &, const sptr &)); + MOCK_METHOD1(UnloadSystemAbility, int32_t(int32_t)); + MOCK_METHOD1(CancelUnloadSystemAbility, int32_t(int32_t)); + MOCK_METHOD1(GetRunningSystemProcess, int32_t(std::list &)); + MOCK_METHOD1(SubscribeSystemProcess, int32_t(const sptr &)); + MOCK_METHOD4(SendStrategy, int32_t(int32_t, std::vector &, int32_t, std::string &)); + MOCK_METHOD1(UnSubscribeSystemProcess, int32_t(const sptr &)); + MOCK_METHOD2(GetOnDemandReasonExtraData, int32_t(int64_t, MessageParcel &)); + MOCK_METHOD2(GetSystemProcessInfo, int32_t(int32_t, SystemProcessInfo &)); + MOCK_METHOD3(GetOnDemandPolicy, int32_t(int32_t, OnDemandPolicyType, std::vector &)); + MOCK_METHOD3( + UpdateOnDemandPolicy, int32_t(int32_t, OnDemandPolicyType, const std::vector &)); + MOCK_METHOD1(GetOnDemandSystemAbilityIds, int32_t(std::vector &)); + MOCK_METHOD0(UnloadAllIdleSystemAbility, int32_t()); + MOCK_METHOD2(GetExtensionSaIds, int32_t(const std::string&, std::vector &)); + MOCK_METHOD2(GetExtensionRunningSaList, int32_t(const std::string&, std::vector>&)); + MOCK_METHOD2(GetRunningSaExtensionInfoList, int32_t(const std::string&, std::vector&)); + MOCK_METHOD3(GetCommonEventExtraDataIdlist, int32_t(int32_t, std::vector&, const std::string&)); + + int32_t SubscribeSystemAbility(int32_t systemAbilityId, const sptr& listener) override + { + std::cout << "SubscribeSystemAbility" << std::endl; + return ERR_ANS_SERVICE_NOT_CONNECTED; + } +}; +} // namespace Notification +} // namespace OHOS +#endif // OHOS_NOTIFICATION_MOCK_SYSTEM_ABILITY_MANAGER_H \ No newline at end of file -- Gitee