From 352cb21edfa9527e60921d7dd33f9e6f081ab0c2 Mon Sep 17 00:00:00 2001 From: baozeyu Date: Thu, 30 Nov 2023 16:12:25 +0800 Subject: [PATCH 1/3] =?UTF-8?q?=E6=B7=BB=E5=8A=A0UT=E7=94=A8=E4=BE=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: baozeyu Change-Id: I7b4042b23b895fbc8aa44f5234f15868af6f77f8 --- frameworks/ans/test/unittest/BUILD.gn | 3 + .../notification_button_option_test.cpp | 109 ++++++++++++ .../unittest/notification_capsule_test.cpp | 126 ++++++++++++++ .../test/unittest/notification_time_test.cpp | 161 ++++++++++++++++++ services/ans/test/unittest/BUILD.gn | 1 + ...ocal_live_view_subscriber_manager_test.cpp | 147 ++++++++++++++++ 6 files changed, 547 insertions(+) create mode 100644 frameworks/ans/test/unittest/notification_button_option_test.cpp create mode 100644 frameworks/ans/test/unittest/notification_capsule_test.cpp create mode 100644 frameworks/ans/test/unittest/notification_time_test.cpp create mode 100644 services/ans/test/unittest/notification_local_live_view_subscriber_manager_test.cpp diff --git a/frameworks/ans/test/unittest/BUILD.gn b/frameworks/ans/test/unittest/BUILD.gn index 9b225a102..bbcbd73df 100644 --- a/frameworks/ans/test/unittest/BUILD.gn +++ b/frameworks/ans/test/unittest/BUILD.gn @@ -33,6 +33,8 @@ ohos_unittest("ans_reminder_unit_test") { "${frameworks_module_ans_path}/test/unittest/message_user_test.cpp", "${frameworks_module_ans_path}/test/unittest/notification_action_button_test.cpp", "${frameworks_module_ans_path}/test/unittest/notification_bundle_option_test.cpp", + "${frameworks_module_ans_path}/test/unittest/notification_button_option_test.cpp", + "${frameworks_module_ans_path}/test/unittest/notification_capsule_test.cpp", "${frameworks_module_ans_path}/test/unittest/notification_content_test.cpp", "${frameworks_module_ans_path}/test/unittest/notification_conversational_content_test.cpp", "${frameworks_module_ans_path}/test/unittest/notification_conversational_message_test.cpp", @@ -52,6 +54,7 @@ ohos_unittest("ans_reminder_unit_test") { "${frameworks_module_ans_path}/test/unittest/notification_subscribe_info_test.cpp", "${frameworks_module_ans_path}/test/unittest/notification_template_test.cpp", "${frameworks_module_ans_path}/test/unittest/notification_test.cpp", + "${frameworks_module_ans_path}/test/unittest/notification_time_test.cpp", "${frameworks_module_ans_path}/test/unittest/notification_user_input_test.cpp", "${frameworks_module_ans_path}/test/unittest/reminder_helper_test.cpp", "${frameworks_module_ans_path}/test/unittest/reminder_request_alarm_test.cpp", diff --git a/frameworks/ans/test/unittest/notification_button_option_test.cpp b/frameworks/ans/test/unittest/notification_button_option_test.cpp new file mode 100644 index 000000000..a8ce4e5ae --- /dev/null +++ b/frameworks/ans/test/unittest/notification_button_option_test.cpp @@ -0,0 +1,109 @@ +/* + * Copyright (c) 2022 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 +#include +#include "notification_button_option.h" + +using namespace testing::ext; +namespace OHOS { +namespace Notification { +class NotificationButtonOptionTest : public testing::Test { +public: + static void SetUpTestCase() {} + static void TearDownTestCase() {} + void SetUp() {} + void TearDown() {} +}; + +/** + * @tc.name: SetButtonName_00001 + * @tc.desc: Test buttonName_ parameters. + * @tc.type: FUNC + * @tc.require: issue + */ +HWTEST_F(NotificationButtonOptionTest, SetButtonName_00001, Function | SmallTest | Level1) +{ + auto rrc = std::make_shared(); + std::string buttonName = "testbuttonName"; + rrc->SetButtonName(buttonName); + EXPECT_EQ(rrc->GetButtonName(), buttonName); +} + +/** + * @tc.name: Dump_00001 + * @tc.desc: Test buttonNames_ dump. + * @tc.type: FUNC + * @tc.require: issue + */ +HWTEST_F(NotificationButtonOptionTest, Dump_00001, Function | SmallTest | Level1) +{ + auto rrc = std::make_shared(); + std::string buttonName = "testbuttonName"; + rrc->SetButtonName(buttonName); + EXPECT_EQ(rrc->Dump(), "NotificationButtonOption{ " + "buttonName = " + buttonName +" }"); +} + +/** + * @tc.name: FromJson_00001 + * @tc.desc: Test FromJson parameters. + * @tc.type: FUNC + * @tc.require: issue + */ +HWTEST_F(NotificationButtonOptionTest, FromJson_00001, Function | SmallTest | Level1) +{ + auto rrc = std::make_shared(); + nlohmann::json jsonObject = nlohmann::json{"buttonName"}; + EXPECT_EQ(jsonObject.is_object(), false); + EXPECT_EQ(rrc->FromJson(jsonObject), nullptr); +} + +/** + * @tc.name: Marshalling_00001 + * @tc.desc: Test Marshalling parameters. + * @tc.type: FUNC + * @tc.require: issueI5WBBH + */ +HWTEST_F(NotificationButtonOptionTest, Marshalling_00001, Function | SmallTest | Level1) +{ + Parcel parcel; + auto rrc = std::make_shared(); + EXPECT_EQ(rrc->Marshalling(parcel), true); +} + +/** + * @tc.name: Unmarshalling_00001 + * @tc.desc: Test Unmarshalling parameters. + * @tc.type: FUNC + * @tc.require: issueI5WBBH + */ +HWTEST_F(NotificationButtonOptionTest, Unmarshalling_00001, Function | SmallTest | Level1) +{ + bool unmarshalling = true; + Parcel parcel; + std::shared_ptr result = + std::make_shared(); + + if (nullptr != result) { + if (nullptr == result->Unmarshalling(parcel)) { + unmarshalling = false; + } + } + EXPECT_EQ(unmarshalling, true); +} +} +} diff --git a/frameworks/ans/test/unittest/notification_capsule_test.cpp b/frameworks/ans/test/unittest/notification_capsule_test.cpp new file mode 100644 index 000000000..a3c598c16 --- /dev/null +++ b/frameworks/ans/test/unittest/notification_capsule_test.cpp @@ -0,0 +1,126 @@ +/* + * Copyright (c) 2022 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 +#include +#include "notification_capsule.h" +#include "pixel_map.h" + +using namespace testing::ext; +namespace OHOS { +namespace Notification { +class NotificationCapsuleTest : public testing::Test { +public: + static void SetUpTestCase() {} + static void TearDownTestCase() {} + void SetUp() {} + void TearDown() {} +}; + +/** + * @tc.name: SetTitle_00001 + * @tc.desc: Test title_ parameters. + * @tc.type: FUNC + * @tc.require: issue + */ +HWTEST_F(NotificationCapsuleTest, SetTitle_00001, Function | SmallTest | Level1) +{ + auto rrc = std::make_shared(); + std::string title = "testTitle"; + rrc->SetTitle(title); + EXPECT_EQ(rrc->GetTitle(), title); +} + +/** + * @tc.name: SetBackgroundColor_00001 + * @tc.desc: Test buttonNames_ parameters. + * @tc.type: FUNC + * @tc.require: issue + */ +HWTEST_F(NotificationCapsuleTest, SetBackgroundColor_00001, Function | SmallTest | Level1) +{ + auto rrc = std::make_shared(); + std::string backgroundColor = "testBackgroundColor"; + rrc->SetBackgroundColor(backgroundColor); + EXPECT_EQ(rrc->GetBackgroundColor(), backgroundColor); +} + +/** + * @tc.name: Dump_00001 + * @tc.desc: Test buttonNames_ dump. + * @tc.type: FUNC + * @tc.require: issue + */ +HWTEST_F(NotificationCapsuleTest, Dump_00001, Function | SmallTest | Level1) +{ + auto rrc = std::make_shared(); + std::string title = "testTitle"; + rrc->SetTitle(title); + std::string backgroundColor = "testBackgroundColor"; + rrc->SetBackgroundColor(backgroundColor); + EXPECT_EQ(rrc->Dump(), "Capsule{ title = " + title + ", backgroundColor = " + backgroundColor + + ", icon = null }"); +} + +/** + * @tc.name: FromJson_00001 + * @tc.desc: Test FromJson parameters. + * @tc.type: FUNC + * @tc.require: issue + */ +HWTEST_F(NotificationCapsuleTest, FromJson_00001, Function | SmallTest | Level1) +{ + auto rrc = std::make_shared(); + nlohmann::json jsonObject = nlohmann::json{"title", "backgroundColor", "icon"}; + EXPECT_EQ(jsonObject.is_object(), false); + EXPECT_EQ(rrc->FromJson(jsonObject), nullptr); +} + +/** + * @tc.name: Marshalling_00001 + * @tc.desc: Test Marshalling parameters. + * @tc.type: FUNC + * @tc.require: issueI5WBBH + */ +HWTEST_F(NotificationCapsuleTest, Marshalling_00001, Function | SmallTest | Level1) +{ + Parcel parcel; + auto rrc = std::make_shared(); + EXPECT_EQ(rrc->Marshalling(parcel), true); +} + +/** + * @tc.name: Unmarshalling_00001 + * @tc.desc: Test Unmarshalling parameters. + * @tc.type: FUNC + * @tc.require: issueI5WBBH + */ +HWTEST_F(NotificationCapsuleTest, Unmarshalling_00001, Function | SmallTest | Level1) +{ + bool unmarshalling = true; + Parcel parcel; + std::shared_ptr result = + std::make_shared(); + + if (nullptr != result) { + if (nullptr == result->Unmarshalling(parcel)) { + unmarshalling = false; + } + } + EXPECT_EQ(unmarshalling, true); +} +} +} diff --git a/frameworks/ans/test/unittest/notification_time_test.cpp b/frameworks/ans/test/unittest/notification_time_test.cpp new file mode 100644 index 000000000..5d0b42b2c --- /dev/null +++ b/frameworks/ans/test/unittest/notification_time_test.cpp @@ -0,0 +1,161 @@ +/* + * Copyright (c) 2022 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 +#include +#include "notification_time.h" + +using namespace testing::ext; +namespace OHOS { +namespace Notification { +class NotificationTimeTest : public testing::Test { +public: + static void SetUpTestCase() {} + static void TearDownTestCase() {} + void SetUp() {} + void TearDown() {} +}; + +/** + * @tc.name: SetInitialTime_00001 + * @tc.desc: Test initialTime_ parameters. + * @tc.type: FUNC + * @tc.require: issue + */ +HWTEST_F(NotificationTimeTest, SetInitialTime_00001, Function | SmallTest | Level1) +{ + auto rrc = std::make_shared(); + int32_t initialTime = 1; + rrc->SetInitialTime(initialTime); + EXPECT_EQ(rrc->GetInitialTime(), initialTime); +} + +/** + * @tc.name: SetIsCountDown_00001 + * @tc.desc: Test isCountDown_ parameters. + * @tc.type: FUNC + * @tc.require: issue + */ +HWTEST_F(NotificationTimeTest, SetIsCountDown_00001, Function | SmallTest | Level1) +{ + auto rrc = std::make_shared(); + bool isCountDown = true; + rrc->SetIsCountDown(isCountDown); + EXPECT_EQ(rrc->GetIsCountDown(), isCountDown); +} + +/** + * @tc.name: SetIsPaused_0001 + * @tc.desc: Test isPaused_ parameters. + * @tc.type: FUNC + * @tc.require: issue + */ +HWTEST_F(NotificationTimeTest, SetIsPaused_0001, Function | SmallTest | Level1) +{ + auto rrc = std::make_shared(); + bool isPaused = true; + rrc->SetIsPaused(isPaused); + EXPECT_EQ(rrc->GetIsPaused(), isPaused); +} + +/** + * @tc.name: SetIsInTitle_0001 + * @tc.desc: Test isInTitle_ parameters. + * @tc.type: FUNC + * @tc.require: issue + */ +HWTEST_F(NotificationTimeTest, SetIsInTitle_0001, Function | SmallTest | Level1) +{ + auto rrc = std::make_shared(); + bool isInTitle = true; + rrc->SetIsInTitle(isInTitle); + EXPECT_EQ(rrc->GetIsInTitle(), isInTitle); +} + +/** + * @tc.name: Dump_00001 + * @tc.desc: Test buttonNames_ dump. + * @tc.type: FUNC + * @tc.require: issue + */ +HWTEST_F(NotificationTimeTest, Dump_00001, Function | SmallTest | Level1) +{ + auto rrc = std::make_shared(); + int32_t initialTime = 1; + rrc->SetInitialTime(initialTime); + bool isCountDown = true; + rrc->SetIsCountDown(isCountDown); + bool isPaused = true; + rrc->SetIsPaused(isPaused); + bool isInTitle = true; + rrc->SetIsInTitle(isInTitle); + EXPECT_EQ(rrc->Dump(), "Time{ " + "initialTime = " + std::to_string(initialTime) + + ", isCountDown = " + std::to_string(isCountDown) + + ", isPaused = " + std::to_string(isPaused) + + ", isInTitle = " + std::to_string(isInTitle) + + " }"); +} + +/** + * @tc.name: FromJson_00001 + * @tc.desc: Test FromJson parameters. + * @tc.type: FUNC + * @tc.require: issue + */ +HWTEST_F(NotificationTimeTest, FromJson_00001, Function | SmallTest | Level1) +{ + auto rrc = std::make_shared(); + nlohmann::json jsonObject = nlohmann::json{"initialTime", "isCountDown", "isPaused", "isInTitle"}; + EXPECT_EQ(jsonObject.is_object(), false); + EXPECT_EQ(rrc->FromJson(jsonObject), nullptr); +} + +/** + * @tc.name: Marshalling_00001 + * @tc.desc: Test Marshalling parameters. + * @tc.type: FUNC + * @tc.require: issueI5WBBH + */ +HWTEST_F(NotificationTimeTest, Marshalling_00001, Function | SmallTest | Level1) +{ + Parcel parcel; + auto rrc = std::make_shared(); + EXPECT_EQ(rrc->Marshalling(parcel), true); +} + +/** + * @tc.name: Unmarshalling_00001 + * @tc.desc: Test Unmarshalling parameters. + * @tc.type: FUNC + * @tc.require: issueI5WBBH + */ +HWTEST_F(NotificationTimeTest, Unmarshalling_00001, Function | SmallTest | Level1) +{ + bool unmarshalling = true; + Parcel parcel; + std::shared_ptr result = + std::make_shared(); + + if (nullptr != result) { + if (nullptr == result->Unmarshalling(parcel)) { + unmarshalling = false; + } + } + EXPECT_EQ(unmarshalling, true); +} +} +} diff --git a/services/ans/test/unittest/BUILD.gn b/services/ans/test/unittest/BUILD.gn index 6358ed02a..cb302adb2 100644 --- a/services/ans/test/unittest/BUILD.gn +++ b/services/ans/test/unittest/BUILD.gn @@ -122,6 +122,7 @@ ohos_unittest("ans_unit_test") { "mock/mock_push_callback_stub.cpp", "mock/mock_single_kv_store.cpp", "notification_hisysevent_test.cpp", + "notification_local_live_view_subscriber_manager_test.cpp", "notification_preferences_database_test.cpp", "notification_slot_filter_test.cpp", "notification_subscriber_manager_test.cpp", diff --git a/services/ans/test/unittest/notification_local_live_view_subscriber_manager_test.cpp b/services/ans/test/unittest/notification_local_live_view_subscriber_manager_test.cpp new file mode 100644 index 000000000..b57e2b4de --- /dev/null +++ b/services/ans/test/unittest/notification_local_live_view_subscriber_manager_test.cpp @@ -0,0 +1,147 @@ +/* + * Copyright (c) 2021-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. + */ + +#include +#include + +#define private public +#include "notification_local_live_view_subscriber.h" +#include "notification_local_live_view_subscriber_manager.h" + +#include "ans_inner_errors.h" + +using namespace testing::ext; +using namespace testing; + +namespace OHOS { +namespace Notification { +class NotificationLocalLiveViewSubscriberManagerTest : public testing::Test { +public: + static void SetUpTestCase(); + static void TearDownTestCase(); + void SetUp(); + void TearDown(); + +private: + class TestAnsSubscriber : public NotificationLocalLiveViewSubscriber { + public: + void OnConnected() override + {} + void OnDisconnected() override + {} + void OnDied() override + {} + void OnResponse(int32_t notificationId, sptr buttonOption) override + {} + }; + + static std::shared_ptr notificationLocalLiveViewSubscriberManager_; + static TestAnsSubscriber testAnsSubscriber_; + static sptr subscriber_; +}; + +std::shared_ptr NotificationLocalLiveViewSubscriberManagerTest::notificationLocalLiveViewSubscriberManager_ = + nullptr; +NotificationLocalLiveViewSubscriberManagerTest::TestAnsSubscriber NotificationLocalLiveViewSubscriberManagerTest::testAnsSubscriber_; +sptr NotificationLocalLiveViewSubscriberManagerTest::subscriber_ = nullptr; + +void NotificationLocalLiveViewSubscriberManagerTest::SetUpTestCase() +{ + notificationLocalLiveViewSubscriberManager_ = NotificationLocalLiveViewSubscriberManager::GetInstance(); + subscriber_ = testAnsSubscriber_.GetImpl(); +} + +void NotificationLocalLiveViewSubscriberManagerTest::TearDownTestCase() +{ + subscriber_ = nullptr; + if (notificationLocalLiveViewSubscriberManager_ != nullptr) { + notificationLocalLiveViewSubscriberManager_->ResetFfrtQueue(); + notificationLocalLiveViewSubscriberManager_ = nullptr; + } +} + +void NotificationLocalLiveViewSubscriberManagerTest::SetUp() +{ + sptr bundleOption = new NotificationBundleOption(); + bundleOption->SetBundleName("test_bundle"); + notificationLocalLiveViewSubscriberManager_->AddSubscriberInner(subscriber_, bundleOption); +} + +void NotificationLocalLiveViewSubscriberManagerTest::TearDown() +{ + notificationLocalLiveViewSubscriberManager_->RemoveLocalLiveViewSubscriber(subscriber_, nullptr); +} + +/** + * @tc.number : NotificationLocalLiveViewSubscriberManagerTest_001 + * @tc.name : ANS_AddSubscriber_001 + * @tc.desc : Test AddSubscriber function, return is ERR_OK. + */ +HWTEST_F(NotificationLocalLiveViewSubscriberManagerTest, NotificationLocalLiveViewSubscriberManagerTest_001, Function | SmallTest | Level1) +{ + sptr bundleOption = new NotificationBundleOption(); + bundleOption->SetBundleName("test_bundle"); + EXPECT_EQ(notificationLocalLiveViewSubscriberManager_->AddSubscriberInner(subscriber_, bundleOption), (int)ERR_OK); +} + +/** + * @tc.number : NotificationLocalLiveViewSubscriberManagerTest_002 + * @tc.name : ANS_AddSubscriber_002 + * @tc.desc : Test AddSubscriber function AND RemoveSubscriberInner, return is ERR_OK. + */ +HWTEST_F(NotificationLocalLiveViewSubscriberManagerTest, NotificationLocalLiveViewSubscriberManagerTest_002, Function | SmallTest | Level1) +{ + sptr bundleOption = new NotificationBundleOption(); + bundleOption->SetBundleName("test_bundle"); + EXPECT_EQ(notificationLocalLiveViewSubscriberManager_->AddSubscriberInner(subscriber_, bundleOption), (int)ERR_OK); + sptr info = new NotificationSubscribeInfo(); + EXPECT_EQ(notificationLocalLiveViewSubscriberManager_->RemoveSubscriberInner(subscriber_, info), (int)ERR_OK); +} + +/** + * @tc.number : NotificationLocalLiveViewSubscriberManagerTest_003 + * @tc.name : ANS_AddSubscriber_003 + * @tc.desc : Test AddSubscriber function AND FindSubscriberRecord, return is not nullptr. + */ +HWTEST_F(NotificationLocalLiveViewSubscriberManagerTest, NotificationLocalLiveViewSubscriberManagerTest_003, Function | SmallTest | Level1) +{ + sptr bundleOption = new NotificationBundleOption(); + bundleOption->SetBundleName("test_bundle"); + EXPECT_EQ(notificationLocalLiveViewSubscriberManager_->AddSubscriberInner(subscriber_, bundleOption), (int)ERR_OK); + sptr info = new NotificationSubscribeInfo(); + EXPECT_NE(notificationLocalLiveViewSubscriberManager_->FindSubscriberRecord(subscriber_), nullptr); +} + +/** + * @tc.number : NotificationLocalLiveViewSubscriberManagerTest_004 + * @tc.name : ANS_IsSystemUser_001 + * @tc.desc : Test IsSystemUser function, return is true. + */ +HWTEST_F(NotificationLocalLiveViewSubscriberManagerTest, NotificationLocalLiveViewSubscriberManagerTest_004, Function | SmallTest | Level1) +{ + EXPECT_EQ(notificationLocalLiveViewSubscriberManager_->IsSystemUser(0), true); +} + +/** + * @tc.number : NotificationLocalLiveViewSubscriberManagerTest_005 + * @tc.name : ANS_IsSystemUser_002 + * @tc.desc : Test IsSystemUser function, return is true. + */ +HWTEST_F(NotificationLocalLiveViewSubscriberManagerTest, NotificationLocalLiveViewSubscriberManagerTest_005, Function | SmallTest | Level1) +{ + EXPECT_EQ(notificationLocalLiveViewSubscriberManager_->IsSystemUser(200), false); +} +} // namespace Notification +} // namespace OHOS -- Gitee From 0367ac9c2d1885ce8ec2d64e1701e6ffb0bdcd8b Mon Sep 17 00:00:00 2001 From: baozeyu Date: Thu, 30 Nov 2023 20:57:38 +0800 Subject: [PATCH 2/3] ent Change-Id: Ic70e9745fccb73b585e3ee3d4a1a200766ffa4c2 --- ...ocal_live_view_subscriber_manager_test.cpp | 42 +++++-------------- 1 file changed, 10 insertions(+), 32 deletions(-) diff --git a/services/ans/test/unittest/notification_local_live_view_subscriber_manager_test.cpp b/services/ans/test/unittest/notification_local_live_view_subscriber_manager_test.cpp index b57e2b4de..d5b99ca50 100644 --- a/services/ans/test/unittest/notification_local_live_view_subscriber_manager_test.cpp +++ b/services/ans/test/unittest/notification_local_live_view_subscriber_manager_test.cpp @@ -13,6 +13,7 @@ * limitations under the License. */ +#include "notification_button_option.h" #include #include @@ -91,9 +92,8 @@ void NotificationLocalLiveViewSubscriberManagerTest::TearDown() */ HWTEST_F(NotificationLocalLiveViewSubscriberManagerTest, NotificationLocalLiveViewSubscriberManagerTest_001, Function | SmallTest | Level1) { - sptr bundleOption = new NotificationBundleOption(); - bundleOption->SetBundleName("test_bundle"); - EXPECT_EQ(notificationLocalLiveViewSubscriberManager_->AddSubscriberInner(subscriber_, bundleOption), (int)ERR_OK); + sptr info = new NotificationSubscribeInfo(); + EXPECT_EQ(notificationLocalLiveViewSubscriberManager_->AddLocalLiveViewSubscriber(subscriber_, info), (int)ERR_OK); } /** @@ -103,45 +103,23 @@ HWTEST_F(NotificationLocalLiveViewSubscriberManagerTest, NotificationLocalLiveVi */ HWTEST_F(NotificationLocalLiveViewSubscriberManagerTest, NotificationLocalLiveViewSubscriberManagerTest_002, Function | SmallTest | Level1) { - sptr bundleOption = new NotificationBundleOption(); - bundleOption->SetBundleName("test_bundle"); - EXPECT_EQ(notificationLocalLiveViewSubscriberManager_->AddSubscriberInner(subscriber_, bundleOption), (int)ERR_OK); sptr info = new NotificationSubscribeInfo(); - EXPECT_EQ(notificationLocalLiveViewSubscriberManager_->RemoveSubscriberInner(subscriber_, info), (int)ERR_OK); + EXPECT_EQ(notificationLocalLiveViewSubscriberManager_->AddLocalLiveViewSubscriber(subscriber_, info), (int)ERR_OK); + EXPECT_EQ(notificationLocalLiveViewSubscriberManager_->RemoveLocalLiveViewSubscriber(subscriber_, info), (int)ERR_OK); } /** * @tc.number : NotificationLocalLiveViewSubscriberManagerTest_003 * @tc.name : ANS_AddSubscriber_003 - * @tc.desc : Test AddSubscriber function AND FindSubscriberRecord, return is not nullptr. + * @tc.desc : Test NotifyTriggerResponse, return is not nullptr. */ HWTEST_F(NotificationLocalLiveViewSubscriberManagerTest, NotificationLocalLiveViewSubscriberManagerTest_003, Function | SmallTest | Level1) { - sptr bundleOption = new NotificationBundleOption(); - bundleOption->SetBundleName("test_bundle"); - EXPECT_EQ(notificationLocalLiveViewSubscriberManager_->AddSubscriberInner(subscriber_, bundleOption), (int)ERR_OK); sptr info = new NotificationSubscribeInfo(); - EXPECT_NE(notificationLocalLiveViewSubscriberManager_->FindSubscriberRecord(subscriber_), nullptr); -} - -/** - * @tc.number : NotificationLocalLiveViewSubscriberManagerTest_004 - * @tc.name : ANS_IsSystemUser_001 - * @tc.desc : Test IsSystemUser function, return is true. - */ -HWTEST_F(NotificationLocalLiveViewSubscriberManagerTest, NotificationLocalLiveViewSubscriberManagerTest_004, Function | SmallTest | Level1) -{ - EXPECT_EQ(notificationLocalLiveViewSubscriberManager_->IsSystemUser(0), true); -} - -/** - * @tc.number : NotificationLocalLiveViewSubscriberManagerTest_005 - * @tc.name : ANS_IsSystemUser_002 - * @tc.desc : Test IsSystemUser function, return is true. - */ -HWTEST_F(NotificationLocalLiveViewSubscriberManagerTest, NotificationLocalLiveViewSubscriberManagerTest_005, Function | SmallTest | Level1) -{ - EXPECT_EQ(notificationLocalLiveViewSubscriberManager_->IsSystemUser(200), false); + EXPECT_EQ(notificationLocalLiveViewSubscriberManager_->AddLocalLiveViewSubscriber(subscriber_, info), (int)ERR_OK); + sptr buttonOption = new NotificationButtonOption(); + sptr notification = new Notification(); + notificationLocalLiveViewSubscriberManager_->NotifyTriggerResponse(notification, buttonOption); } } // namespace Notification } // namespace OHOS -- Gitee From 1a15be8cd01425c697662bad9bad9ad2174b480c Mon Sep 17 00:00:00 2001 From: baozeyu Date: Thu, 30 Nov 2023 21:11:49 +0800 Subject: [PATCH 3/3] ent Change-Id: I088dc2a5f6a6098c946525bacbaf193167fc2843 --- .../unittest/notification_capsule_test.cpp | 1 - ...ocal_live_view_subscriber_manager_test.cpp | 23 +++++++++++-------- 2 files changed, 14 insertions(+), 10 deletions(-) diff --git a/frameworks/ans/test/unittest/notification_capsule_test.cpp b/frameworks/ans/test/unittest/notification_capsule_test.cpp index a3c598c16..b31258917 100644 --- a/frameworks/ans/test/unittest/notification_capsule_test.cpp +++ b/frameworks/ans/test/unittest/notification_capsule_test.cpp @@ -17,7 +17,6 @@ #include #include #include "notification_capsule.h" -#include "pixel_map.h" using namespace testing::ext; namespace OHOS { diff --git a/services/ans/test/unittest/notification_local_live_view_subscriber_manager_test.cpp b/services/ans/test/unittest/notification_local_live_view_subscriber_manager_test.cpp index d5b99ca50..c71c21ec1 100644 --- a/services/ans/test/unittest/notification_local_live_view_subscriber_manager_test.cpp +++ b/services/ans/test/unittest/notification_local_live_view_subscriber_manager_test.cpp @@ -17,7 +17,6 @@ #include #include -#define private public #include "notification_local_live_view_subscriber.h" #include "notification_local_live_view_subscriber_manager.h" @@ -53,10 +52,12 @@ private: static sptr subscriber_; }; -std::shared_ptr NotificationLocalLiveViewSubscriberManagerTest::notificationLocalLiveViewSubscriberManager_ = - nullptr; -NotificationLocalLiveViewSubscriberManagerTest::TestAnsSubscriber NotificationLocalLiveViewSubscriberManagerTest::testAnsSubscriber_; -sptr NotificationLocalLiveViewSubscriberManagerTest::subscriber_ = nullptr; +std::shared_ptr + NotificationLocalLiveViewSubscriberManagerTest::notificationLocalLiveViewSubscriberManager_ = nullptr; +NotificationLocalLiveViewSubscriberManagerTest::TestAnsSubscriber + NotificationLocalLiveViewSubscriberManagerTest::testAnsSubscriber_; +sptr + NotificationLocalLiveViewSubscriberManagerTest::subscriber_ = nullptr; void NotificationLocalLiveViewSubscriberManagerTest::SetUpTestCase() { @@ -90,7 +91,8 @@ void NotificationLocalLiveViewSubscriberManagerTest::TearDown() * @tc.name : ANS_AddSubscriber_001 * @tc.desc : Test AddSubscriber function, return is ERR_OK. */ -HWTEST_F(NotificationLocalLiveViewSubscriberManagerTest, NotificationLocalLiveViewSubscriberManagerTest_001, Function | SmallTest | Level1) +HWTEST_F(NotificationLocalLiveViewSubscriberManagerTest, + NotificationLocalLiveViewSubscriberManagerTest_001, Function | SmallTest | Level1) { sptr info = new NotificationSubscribeInfo(); EXPECT_EQ(notificationLocalLiveViewSubscriberManager_->AddLocalLiveViewSubscriber(subscriber_, info), (int)ERR_OK); @@ -101,11 +103,13 @@ HWTEST_F(NotificationLocalLiveViewSubscriberManagerTest, NotificationLocalLiveVi * @tc.name : ANS_AddSubscriber_002 * @tc.desc : Test AddSubscriber function AND RemoveSubscriberInner, return is ERR_OK. */ -HWTEST_F(NotificationLocalLiveViewSubscriberManagerTest, NotificationLocalLiveViewSubscriberManagerTest_002, Function | SmallTest | Level1) +HWTEST_F(NotificationLocalLiveViewSubscriberManagerTest, + NotificationLocalLiveViewSubscriberManagerTest_002, Function | SmallTest | Level1) { sptr info = new NotificationSubscribeInfo(); EXPECT_EQ(notificationLocalLiveViewSubscriberManager_->AddLocalLiveViewSubscriber(subscriber_, info), (int)ERR_OK); - EXPECT_EQ(notificationLocalLiveViewSubscriberManager_->RemoveLocalLiveViewSubscriber(subscriber_, info), (int)ERR_OK); + EXPECT_EQ(notificationLocalLiveViewSubscriberManager_-> + RemoveLocalLiveViewSubscriber(subscriber_, info), (int)ERR_OK); } /** @@ -113,7 +117,8 @@ HWTEST_F(NotificationLocalLiveViewSubscriberManagerTest, NotificationLocalLiveVi * @tc.name : ANS_AddSubscriber_003 * @tc.desc : Test NotifyTriggerResponse, return is not nullptr. */ -HWTEST_F(NotificationLocalLiveViewSubscriberManagerTest, NotificationLocalLiveViewSubscriberManagerTest_003, Function | SmallTest | Level1) +HWTEST_F(NotificationLocalLiveViewSubscriberManagerTest, + NotificationLocalLiveViewSubscriberManagerTest_003, Function | SmallTest | Level1) { sptr info = new NotificationSubscribeInfo(); EXPECT_EQ(notificationLocalLiveViewSubscriberManager_->AddLocalLiveViewSubscriber(subscriber_, info), (int)ERR_OK); -- Gitee