From d16134c864dff61e2cf24f4051f25b788856564b Mon Sep 17 00:00:00 2001 From: "baozeyu1@huawei.com" Date: Sat, 14 Jun 2025 14:55:03 +0800 Subject: [PATCH] tdd cov add Signed-off-by: baozeyu1@huawei.com --- frameworks/ans/src/notification_progress.cpp | 2 +- .../notification_action_button_test.cpp | 116 +++++++++++ .../unittest/notification_capsule_test.cpp | 130 ++++++++++++ .../unittest/notification_content_test.cpp | 49 +++++ .../unittest/notification_disable_test.cpp | 35 ++++ ...tification_do_not_disturb_profile_test.cpp | 41 ++++ .../test/unittest/notification_flags_test.cpp | 54 +++++ .../notification_live_view_content_test.cpp | 19 ++ ...ification_local_live_view_content_test.cpp | 193 ++++++++++++++++++ .../test/unittest/notification_slot_test.cpp | 57 ++++++ .../ans/test/unittest/notification_test.cpp | 31 +++ .../notification_analytics_util_test.cpp | 61 ++++++ 12 files changed, 787 insertions(+), 1 deletion(-) diff --git a/frameworks/ans/src/notification_progress.cpp b/frameworks/ans/src/notification_progress.cpp index 4568b3b9e..068053b2d 100644 --- a/frameworks/ans/src/notification_progress.cpp +++ b/frameworks/ans/src/notification_progress.cpp @@ -99,7 +99,7 @@ NotificationProgress *NotificationProgress::FromJson(const nlohmann::json &jsonO } if (jsonObject.find("isPercentage") != jsonEnd && jsonObject.at("isPercentage").is_boolean()) { - progress->isPercentage_ = jsonObject.at("isPercentage_").get(); + progress->isPercentage_ = jsonObject.at("isPercentage").get(); } return progress; diff --git a/frameworks/ans/test/unittest/notification_action_button_test.cpp b/frameworks/ans/test/unittest/notification_action_button_test.cpp index 79bc07023..7b742c1c7 100644 --- a/frameworks/ans/test/unittest/notification_action_button_test.cpp +++ b/frameworks/ans/test/unittest/notification_action_button_test.cpp @@ -181,6 +181,77 @@ HWTEST_F(NotificationActionButtontTest, Create_00002, Function | SmallTest | Lev autoCreatedReplies, mimeTypeOnlyInputs, userInput, isContextual); } +/** + * @tc.name: Create_00003 + * @tc.desc: Test Create parameters. + * @tc.type: FUNC + * @tc.require: issue + */ +HWTEST_F(NotificationActionButtontTest, Create_00003, Function | SmallTest | Level1) +{ + std::shared_ptr icon = std::make_shared(); + std::string title = "thios is title"; + AbilityRuntime::WantAgent::WantAgentInfo paramsInfo; + std::shared_ptr wantAgent = + std::make_shared(); + std::shared_ptr extras; + NotificationConstant::SemanticActionButton semanticActionButton = + NotificationConstant::SemanticActionButton(2); + bool autoCreatedReplies = true; + std::vector> mimeTypeOnlyInputs; + ASSERT_EQ(mimeTypeOnlyInputs.size(), 0); + std::shared_ptr userInput = std::make_shared(); + userInput->SetPermitFreeFormInput(false); + userInput->SetPermitMimeTypes("test", true); + bool isContextual = true; + + std::shared_ptr notificationActionButton = std::make_shared(); + + std::shared_ptr result = notificationActionButton->Create + (icon, title, wantAgent, extras, semanticActionButton, + autoCreatedReplies, mimeTypeOnlyInputs, userInput, isContextual); + ASSERT_NE(result, nullptr); + ASSERT_EQ(result->GetMimeTypeOnlyUserInputs().size(), 1); +} + +/** + * @tc.name: Dump_00002 + * @tc.desc: Test Dump parameters. + * @tc.type: FUNC + * @tc.require: issue + */ +HWTEST_F(NotificationActionButtontTest, Dump_00002, Function | SmallTest | Level1) +{ + std::shared_ptr icon = std::make_shared(); + std::string title = "thios is title"; + AbilityRuntime::WantAgent::WantAgentInfo paramsInfo; + std::shared_ptr wantAgent = + std::make_shared(); + std::shared_ptr extras; + NotificationConstant::SemanticActionButton semanticActionButton = + NotificationConstant::SemanticActionButton(2); + bool autoCreatedReplies = true; + std::vector> mimeTypeOnlyInputs; + ASSERT_EQ(mimeTypeOnlyInputs.size(), 0); + std::shared_ptr userInput = std::make_shared(); + userInput->SetPermitFreeFormInput(false); + userInput->SetPermitMimeTypes("test", true); + bool isContextual = true; + + std::shared_ptr notificationActionButton = std::make_shared(); + + std::shared_ptr result = notificationActionButton->Create + (icon, title, wantAgent, extras, semanticActionButton, + autoCreatedReplies, mimeTypeOnlyInputs, userInput, isContextual); + ASSERT_NE(result, nullptr); + ASSERT_EQ(result->GetMimeTypeOnlyUserInputs().size(), 1); + std::string temp = result->Dump(); + + auto it = temp.find("mimeTypeOnlyUserInputs"); + ASSERT_NE(it, std::string::npos); +} + + /** * @tc.name: FromJson_00002 * @tc.desc: Test FromJson parameters. @@ -214,6 +285,51 @@ HWTEST_F(NotificationActionButtontTest, FromJson_00003, Function | SmallTest | L EXPECT_EQ(jsonObject.is_object(), true); } +/** + * @tc.name: FromJson_00004 + * @tc.desc: Test FromJson parameters. + * @tc.type: FUNC + * @tc.require: issue + */ +HWTEST_F(NotificationActionButtontTest, FromJson_00004, Function | SmallTest | Level1) +{ + std::shared_ptr icon = std::make_shared(); + std::string title = "test"; + std::shared_ptr wantAgent = + std::make_shared(); + std::shared_ptr extras = std::make_shared(); + NotificationConstant::SemanticActionButton semanticActionButton = + NotificationConstant::SemanticActionButton(2); + bool autoCreatedReplies = true; + std::vector> mimeTypeOnlyInputs; + ASSERT_EQ(mimeTypeOnlyInputs.size(), 0); + std::shared_ptr userInput = std::make_shared(); + userInput->SetPermitFreeFormInput(false); + userInput->SetPermitMimeTypes("test", true); + bool isContextual = true; + + std::shared_ptr notificationActionButton = std::make_shared(); + std::shared_ptr rrc = notificationActionButton->Create + (icon, title, wantAgent, extras, semanticActionButton, + autoCreatedReplies, mimeTypeOnlyInputs, userInput, isContextual); + + nlohmann::json jsonObject; + auto res = rrc->ToJson(jsonObject); + ASSERT_EQ(res, true); + + std::string jsonString = jsonObject.dump(); + auto it = jsonString.find("icon"); + ASSERT_NE(it, std::string::npos); + it = jsonString.find("extras"); + ASSERT_NE(it, std::string::npos); + it = jsonString.find("wantAgent"); + ASSERT_NE(it, std::string::npos); + + auto temp = rrc->FromJson(jsonObject); + ASSERT_NE(temp, nullptr); + ASSERT_EQ(temp->GetTitle(), "test"); +} + /** * @tc.name: Dump_00001 * @tc.desc: Test Dump parameters. diff --git a/frameworks/ans/test/unittest/notification_capsule_test.cpp b/frameworks/ans/test/unittest/notification_capsule_test.cpp index a21e8cdcf..376170bce 100644 --- a/frameworks/ans/test/unittest/notification_capsule_test.cpp +++ b/frameworks/ans/test/unittest/notification_capsule_test.cpp @@ -152,5 +152,135 @@ HWTEST_F(NotificationCapsuleTest, SetIcon_00001, Function | SmallTest | Level1) capsule->SetIcon(pixmap); EXPECT_NE(capsule->GetIcon(), nullptr); } + +/** + * @tc.name: SetContent_00001 + * @tc.desc: Test SetContent. + * @tc.type: FUNC + * @tc.require: issueI5WBBH + */ +HWTEST_F(NotificationCapsuleTest, SetContent_00001, Function | SmallTest | Level1) +{ + NotificationCapsule capsule; + capsule.SetContent("test"); + ASSERT_EQ(capsule.GetContent(), "test"); +} + +/** + * @tc.name: SetTime_00001 + * @tc.desc: Test SetTime. + * @tc.type: FUNC + * @tc.require: issueI5WBBH + */ +HWTEST_F(NotificationCapsuleTest, SetTime_00001, Function | SmallTest | Level1) +{ + NotificationCapsule capsule; + capsule.SetTime(1); + ASSERT_EQ(capsule.GetTime(), 1); +} + +/** + * @tc.name: GetCapsuleButton_00001 + * @tc.desc: Test GetCapsuleButton. + * @tc.type: FUNC + * @tc.require: issueI5WBBH + */ +HWTEST_F(NotificationCapsuleTest, GetCapsuleButton_00001, Function | SmallTest | Level1) +{ + NotificationCapsule capsule; + + std::vector buttons; + NotificationIconButton button; + buttons.push_back(button); + + capsule.SetCapsuleButton(buttons); + ASSERT_EQ(capsule.GetCapsuleButton().size(), 1); +} + +/** + * @tc.name: GetCapsuleButton_00002 + * @tc.desc: Test GetCapsuleButton. + * @tc.type: FUNC + * @tc.require: issueI5WBBH + */ +HWTEST_F(NotificationCapsuleTest, GetCapsuleButton_00002, Function | SmallTest | Level1) +{ + NotificationCapsule capsule; + capsule.SetContent("test"); + + nlohmann::json jsonObject; + auto res = capsule.ToJson(jsonObject); + ASSERT_TRUE(res); + + auto jsonString = jsonObject.dump(); + + auto it = jsonString.find("content"); + ASSERT_NE(it, std::string::npos); + + sptr capsuleSptr = capsule.FromJson(jsonObject); + ASSERT_NE(capsuleSptr, nullptr); + ASSERT_EQ(capsuleSptr->GetContent(), "test"); +} + +/** + * @tc.name: FromJson_00003 + * @tc.desc: Test FromJson_00003. + * @tc.type: FUNC + * @tc.require: issueI5WBBH + */ +HWTEST_F(NotificationCapsuleTest, FromJson_00003, Function | SmallTest | Level1) +{ + NotificationCapsule capsule; + capsule.SetContent("test"); + + nlohmann::json jsonObject; + auto res = capsule.ToJson(jsonObject); + ASSERT_TRUE(res); + + auto jsonString = jsonObject.dump(); + + auto it = jsonString.find("content"); + ASSERT_NE(it, std::string::npos); + + sptr capsuleSptr = capsule.FromJson(jsonObject); + ASSERT_NE(capsuleSptr, nullptr); + ASSERT_EQ(capsuleSptr->GetContent(), "test"); +} + +/** + * @tc.name: Unmarshalling_00002 + * @tc.desc: Test Unmarshalling_00002. + * @tc.type: FUNC + * @tc.require: issueI5WBBH + */ +HWTEST_F(NotificationCapsuleTest, Unmarshalling_00002, Function | SmallTest | Level1) +{ + NotificationCapsule capsule; + capsule.SetContent("test"); + + Parcel parcel; + auto res = capsule.Marshalling(parcel); + ASSERT_TRUE(res); + + sptr capsuleSptr = capsule.Unmarshalling(parcel); + ASSERT_NE(capsuleSptr, nullptr); + ASSERT_EQ(capsuleSptr->GetContent(), "test"); +} + +/** + * @tc.name: ResetIcon_00001 + * @tc.desc: Test ResetIcon. + * @tc.type: FUNC + * @tc.require: issueI5WBBH + */ +HWTEST_F(NotificationCapsuleTest, ResetIcon_00001, Function | SmallTest | Level1) +{ + NotificationCapsule capsule; + auto pixmap = std::make_shared(); + capsule.SetIcon(pixmap); + ASSERT_NE(capsule.GetIcon(), nullptr); + capsule.ResetIcon(); + ASSERT_EQ(capsule.GetIcon(), nullptr); +} } } diff --git a/frameworks/ans/test/unittest/notification_content_test.cpp b/frameworks/ans/test/unittest/notification_content_test.cpp index 86008494c..ae90e3d96 100644 --- a/frameworks/ans/test/unittest/notification_content_test.cpp +++ b/frameworks/ans/test/unittest/notification_content_test.cpp @@ -471,5 +471,54 @@ HWTEST_F(NotificationContentTest, Unmarshalling_00002, Level1) EXPECT_EQ(content1.Marshalling(parcel), true); EXPECT_NE(content1.Unmarshalling(parcel), nullptr); } + +/** + * @tc.name: ReadFromParcel_00700 + * @tc.desc: Test ReadFromParcel + * @tc.type: FUNC + * @tc.require: issueI5S0ZS + */ +HWTEST_F(NotificationContentTest, ReadFromParcel_00700, Level1) +{ + Parcel parcel; + parcel.WriteBool(100); + parcel.WriteBool(true); + NotificationContent notificationContent; + bool res = notificationContent.ReadFromParcel(parcel); + ASSERT_FALSE(res); +} + +/** + * @tc.name: ConvertJsonToContent_00200 + * @tc.desc: Test ConvertJsonToContent + * @tc.type: FUNC + * @tc.require: issueI5S0ZS + */ +HWTEST_F(NotificationContentTest, ConvertJsonToContent_00200, Level1) +{ + NotificationContent notificationContent; + nlohmann::json jsonObject = nlohmann::json{{"contentType", "test"}}; + sptr contentSptr(new NotificationContent()); + bool res = notificationContent.ConvertJsonToContent(contentSptr, jsonObject); + ASSERT_FALSE(res); + + jsonObject = nlohmann::json{{"contentType", 999}, {"content", "test"}}; + res = notificationContent.ConvertJsonToContent(contentSptr, jsonObject); + ASSERT_FALSE(res); +} + +/** + * @tc.name: GetContentTypeByString_00100 + * @tc.desc: Test GetContentTypeByString_00100 + * @tc.type: FUNC + * @tc.require: issueI5S0ZS + */ +HWTEST_F(NotificationContentTest, GetContentTypeByString_00100, Level1) +{ + NotificationContent notificationContent; + NotificationContent::Type contentType; + bool res = notificationContent.GetContentTypeByString("1111", contentType); + ASSERT_FALSE(res); +} } } diff --git a/frameworks/ans/test/unittest/notification_disable_test.cpp b/frameworks/ans/test/unittest/notification_disable_test.cpp index e8b00fad7..481e434f8 100644 --- a/frameworks/ans/test/unittest/notification_disable_test.cpp +++ b/frameworks/ans/test/unittest/notification_disable_test.cpp @@ -106,5 +106,40 @@ HWTEST_F(NotificationDisableTest, Unmarshalling_0100, Function | SmallTest | Lev } EXPECT_TRUE(unmarshalling); } + +/** + * @tc.name: Marshalling_0200 + * @tc.desc: Test Marshalling_0200. + * @tc.type: FUNC + */ +HWTEST_F(NotificationDisableTest, Marshalling_0200, Function | SmallTest | Level1) +{ + NotificationDisable notificationDisable; + std::vector bundleList; + + for (auto i = 0; i <= 1000; ++i) { + bundleList.push_back("123"); + } + notificationDisable.SetBundleList(bundleList); + + Parcel parcel; + auto res = notificationDisable.Marshalling(parcel); + ASSERT_FALSE(res); +} + +/** + * @tc.name: Marshalling_0100 + * @tc.desc: Test Marshalling_0100. + * @tc.type: FUNC + */ +HWTEST_F(NotificationDisableTest, FromJson_0100, Function | SmallTest | Level1) +{ + NotificationDisable notificationDisable; + std::vector bundleList; + + std::string jsonObjString = ""; + notificationDisable.FromJson(jsonObjString); + ASSERT_FALSE(notificationDisable.GetDisabled()); +} } } diff --git a/frameworks/ans/test/unittest/notification_do_not_disturb_profile_test.cpp b/frameworks/ans/test/unittest/notification_do_not_disturb_profile_test.cpp index 27a748516..d498bae42 100644 --- a/frameworks/ans/test/unittest/notification_do_not_disturb_profile_test.cpp +++ b/frameworks/ans/test/unittest/notification_do_not_disturb_profile_test.cpp @@ -154,5 +154,46 @@ HWTEST_F(NotificationDoNotDisturbProfileTest, Unmarshalling_0100, TestSize.Level } EXPECT_EQ(unmarshalling, true); } + +/** + * @tc.name: ReadFromParcel_0300 + * @tc.desc: test it when Unmarshalling success. + * @tc.type: FUNC + */ +HWTEST_F(NotificationDoNotDisturbProfileTest, ReadFromParcel_0300, TestSize.Level1) +{ + NotificationDoNotDisturbProfile notificationDoNotDisturbProfile; + Parcel parcel; + parcel.WriteInt64(1); + parcel.WriteString("1"); + parcel.WriteUint32(1); + + sptr bundleOption(new NotificationBundleOption()); + parcel.WriteParcelable(bundleOption); + auto res = notificationDoNotDisturbProfile.ReadFromParcel(parcel); + ASSERT_TRUE(res); + ASSERT_EQ(notificationDoNotDisturbProfile.GetProfileTrustList().size(), 1); +} + +/** + * @tc.name: FromJson_0100 + * @tc.desc: test it when Unmarshalling success. + * @tc.type: FUNC + */ +HWTEST_F(NotificationDoNotDisturbProfileTest, FromJson_0100, TestSize.Level1) +{ + NotificationDoNotDisturbProfile notificationDoNotDisturbProfile; + std::vector trustList; + NotificationBundleOption notificationBundleOption; + trustList.push_back(notificationBundleOption); + notificationDoNotDisturbProfile.SetProfileTrustList(trustList); + + auto jsonString = notificationDoNotDisturbProfile.ToJson(); + + NotificationDoNotDisturbProfile temp; + temp.FromJson(jsonString); + + ASSERT_EQ(temp.GetProfileTrustList().size(), 1); +} } // namespace Notification } // namespace OHOS diff --git a/frameworks/ans/test/unittest/notification_flags_test.cpp b/frameworks/ans/test/unittest/notification_flags_test.cpp index ebcb1cc18..eace184c6 100644 --- a/frameworks/ans/test/unittest/notification_flags_test.cpp +++ b/frameworks/ans/test/unittest/notification_flags_test.cpp @@ -166,5 +166,59 @@ HWTEST_F(NotificationFlagsTest, ReadFromParcel_00001, Function | SmallTest | Lev auto rrc = std::make_shared(); EXPECT_EQ(rrc->ReadFromParcel(parcel), true); } + +/** + * @tc.name: IsLightScreenEnabled_00001 + * @tc.desc: Test IsLightScreenEnabled parameters. + * @tc.type: FUNC + * @tc.require: issueI5WBBH + */ +HWTEST_F(NotificationFlagsTest, IsLightScreenEnabled_00001, Function | SmallTest | Level1) +{ + NotificationFlags flag; + flag.SetReminderFlags(0); + auto res = flag.IsLightScreenEnabled(); + ASSERT_FALSE(res); +} + +/** + * @tc.name: GetReminderFlagsByString_00001 + * @tc.desc: Test GetReminderFlagsByString parameters. + * @tc.type: FUNC + * @tc.require: issueI5WBBH + */ +HWTEST_F(NotificationFlagsTest, GetReminderFlagsByString_00001, Function | SmallTest | Level1) +{ + NotificationFlags flag; + flag.SetReminderFlags(0); + + std::shared_ptr flagSptr = std::make_shared(); + auto res = flag.GetReminderFlagsByString("333", flagSptr); + ASSERT_FALSE(res); + + res = flag.GetReminderFlagsByString("111111", flagSptr); + ASSERT_TRUE(res); + + res = flag.GetReminderFlagsByString("444444", flagSptr); + ASSERT_FALSE(res); +} + +/** + * @tc.name: ValidCharReminderFlag_00001 + * @tc.desc: Test ValidCharReminderFlag parameters. + * @tc.type: FUNC + * @tc.require: issueI5WBBH + */ +HWTEST_F(NotificationFlagsTest, ValidCharReminderFlag_00001, Function | SmallTest | Level1) +{ + NotificationFlags flag; + flag.SetReminderFlags(0); + + auto res = flag.ValidCharReminderFlag('3', 6); + ASSERT_FALSE(res); + + res = flag.ValidCharReminderFlag('2', 5); + ASSERT_TRUE(res); +} } } \ No newline at end of file diff --git a/frameworks/ans/test/unittest/notification_live_view_content_test.cpp b/frameworks/ans/test/unittest/notification_live_view_content_test.cpp index 23a187992..913e03589 100644 --- a/frameworks/ans/test/unittest/notification_live_view_content_test.cpp +++ b/frameworks/ans/test/unittest/notification_live_view_content_test.cpp @@ -206,6 +206,25 @@ HWTEST_F(NotificationLiveViewContentTest, FromJson_00001, Function | SmallTest | EXPECT_EQ(ptr, nullptr); } +/** + * @tc.name: FromJson_00002 + * @tc.desc: Test FromJson parameters when jsonObject is invalid. + * @tc.type: FUNC + * @tc.require: issue + */ +HWTEST_F(NotificationLiveViewContentTest, FromJson_00002, Function | SmallTest | Level1) +{ + auto rrc = std::make_shared(); + nlohmann::json jsonObject; + auto res = rrc->ToJson(jsonObject); + rrc->SetIsOnlyLocalUpdate(true); + ASSERT_TRUE(res); + + auto ptr = rrc->FromJson(jsonObject); + ASSERT_NE(ptr, nullptr); + ASSERT_TRUE(rrc->GetIsOnlyLocalUpdate()); +} + /** * @tc.name: MarshallConvert_00001 * @tc.desc: Test MarshallConvert parameters. diff --git a/frameworks/ans/test/unittest/notification_local_live_view_content_test.cpp b/frameworks/ans/test/unittest/notification_local_live_view_content_test.cpp index c87d5c862..e9d1e9f83 100644 --- a/frameworks/ans/test/unittest/notification_local_live_view_content_test.cpp +++ b/frameworks/ans/test/unittest/notification_local_live_view_content_test.cpp @@ -267,5 +267,198 @@ HWTEST_F(NotificationLocalLiveViewContentTest, Dump_00001, Function | SmallTest "time = Time{ initialTime = 1, isCountDown = 0, isPaused = 0, isInTitle = 0 }, liveviewType = 0 }"; EXPECT_EQ(liveViewContent->Dump(), dumpStr); } + +/** + * @tc.name: SetCardButton_00001 + * @tc.desc: Test SetCardButton. + * @tc.type: FUNC + * @tc.require: issue + */ +HWTEST_F(NotificationLocalLiveViewContentTest, SetCardButton_00001, Function | SmallTest | Level1) +{ + auto liveViewContent = std::make_shared(); + auto buttons = liveViewContent->GetCardButton(); + EXPECT_EQ(buttons.size(), 0); + + NotificationIconButton button; + buttons.push_back(button); + + liveViewContent->SetCardButton(buttons); + buttons = liveViewContent->GetCardButton(); + EXPECT_EQ(buttons.size(), 1); +} + +/** + * @tc.name: SetLiveViewType_00001 + * @tc.desc: Test SetLiveViewType. + * @tc.type: FUNC + * @tc.require: issue + */ +HWTEST_F(NotificationLocalLiveViewContentTest, SetLiveViewType_00001, Function | SmallTest | Level1) +{ + auto liveViewContent = std::make_shared(); + liveViewContent->SetLiveViewType(NotificationLocalLiveViewContent::LiveViewTypes::LIVE_VIEW_ACTIVITY); + + auto type = liveViewContent->GetLiveViewType(); + EXPECT_EQ(type, NotificationLocalLiveViewContent::LiveViewTypes::LIVE_VIEW_ACTIVITY); +} + +/** + * @tc.name: FromJson_00004 + * @tc.desc: Test FromJson_00004. + * @tc.type: FUNC + * @tc.require: issue + */ +HWTEST_F(NotificationLocalLiveViewContentTest, FromJson_00004, Function | SmallTest | Level1) +{ + auto rrc = std::make_shared(); + + NotificationCapsule capsule; + capsule.SetTitle("testTitle"); + rrc->SetCapsule(capsule); + + nlohmann::json json; + rrc->ToJson(json); + + sptr temp = rrc->FromJson(json); + EXPECT_NE(temp, nullptr); + EXPECT_EQ(temp->GetCapsule().GetTitle(), "testTitle"); +} + +/** + * @tc.name: FromJson_00005 + * @tc.desc: Test FromJson_00005. + * @tc.type: FUNC + * @tc.require: issue + */ +HWTEST_F(NotificationLocalLiveViewContentTest, FromJson_00005, Function | SmallTest | Level1) +{ + auto rrc = std::make_shared(); + + NotificationLocalLiveViewButton button; + button.addSingleButtonName("test"); + rrc->SetButton(button); + + nlohmann::json json; + rrc->ToJson(json); + + sptr temp = rrc->FromJson(json); + EXPECT_NE(temp, nullptr); + EXPECT_EQ(temp->GetButton().GetAllButtonNames().size(), 1); +} + +/** + * @tc.name: FromJson_00007 + * @tc.desc: Test FromJson_00007. + * @tc.type: FUNC + * @tc.require: issue + */ +HWTEST_F(NotificationLocalLiveViewContentTest, FromJson_00007, Function | SmallTest | Level1) +{ + auto rrc = std::make_shared(); + + NotificationProgress progress; + progress.SetMaxValue(1); + rrc->SetProgress(progress); + EXPECT_EQ(rrc->GetProgress().GetMaxValue(), 1); + + nlohmann::json json; + rrc->ToJson(json); + + sptr temp = rrc->FromJson(json); + EXPECT_NE(temp, nullptr); + EXPECT_EQ(temp->GetProgress().GetMaxValue(), 1); +} + +/** + * @tc.name: FromJson_00008 + * @tc.desc: Test FromJson_00008. + * @tc.type: FUNC + * @tc.require: issue + */ +HWTEST_F(NotificationLocalLiveViewContentTest, FromJson_00008, Function | SmallTest | Level1) +{ + auto rrc = std::make_shared(); + + NotificationTime time; + time.SetInitialTime(1); + rrc->SetTime(time); + EXPECT_EQ(rrc->GetTime().GetInitialTime(), 1); + + nlohmann::json json; + rrc->ToJson(json); + + sptr temp = rrc->FromJson(json); + EXPECT_NE(temp, nullptr); + EXPECT_EQ(temp->GetTime().GetInitialTime(), 1); +} + +/** + * @tc.name: FromJson_00009 + * @tc.desc: Test FromJson_00009. + * @tc.type: FUNC + * @tc.require: issue + */ +HWTEST_F(NotificationLocalLiveViewContentTest, FromJson_00009, Function | SmallTest | Level1) +{ + auto rrc = std::make_shared(); + rrc->addFlag(1); + EXPECT_TRUE(rrc->isFlagExist(1)); + + nlohmann::json json; + rrc->ToJson(json); + + sptr temp = rrc->FromJson(json); + EXPECT_NE(temp, nullptr); + EXPECT_TRUE(temp->isFlagExist(1)); +} + +/** + * @tc.name: FromJson_00010 + * @tc.desc: Test FromJson_00010. + * @tc.type: FUNC + * @tc.require: issue + */ +HWTEST_F(NotificationLocalLiveViewContentTest, FromJson_00010, Function | SmallTest | Level1) +{ + auto rrc = std::make_shared(); + rrc->SetLiveViewType(NotificationLocalLiveViewContent::LiveViewTypes::LIVE_VIEW_ACTIVITY); + + auto type = rrc->GetLiveViewType(); + EXPECT_EQ(type, NotificationLocalLiveViewContent::LiveViewTypes::LIVE_VIEW_ACTIVITY); + + nlohmann::json json; + rrc->ToJson(json); + + sptr temp = rrc->FromJson(json); + EXPECT_NE(temp, nullptr); + EXPECT_EQ(temp->GetLiveViewType(), + NotificationLocalLiveViewContent::LiveViewTypes::LIVE_VIEW_ACTIVITY); +} + +/** + * @tc.name: ReadFromParcel_00001 + * @tc.desc: Test ReadFromParcel_00001. + * @tc.type: FUNC + * @tc.require: issue + */ +HWTEST_F(NotificationLocalLiveViewContentTest, ReadFromParcel_00001, Function | SmallTest | Level1) +{ + auto liveViewContent = std::make_shared(); + auto buttons = liveViewContent->GetCardButton(); + EXPECT_EQ(buttons.size(), 0); + + NotificationIconButton button; + buttons.push_back(button); + + liveViewContent->SetCardButton(buttons); + + Parcel parcel; + liveViewContent->Marshalling(parcel); + sptr temp = liveViewContent->Unmarshalling(parcel); + + EXPECT_NE(temp, nullptr); + EXPECT_EQ(temp->GetCardButton().size(), 1); +} } } diff --git a/frameworks/ans/test/unittest/notification_slot_test.cpp b/frameworks/ans/test/unittest/notification_slot_test.cpp index d7fb0565b..3fe020f31 100644 --- a/frameworks/ans/test/unittest/notification_slot_test.cpp +++ b/frameworks/ans/test/unittest/notification_slot_test.cpp @@ -15,6 +15,8 @@ #include +#define private public + #include "notification_slot.h" using namespace testing::ext; @@ -53,5 +55,60 @@ HWTEST_F(NotificationSlotTest, GetSlotTypeByString_00002, Function | SmallTest | const std::string inputStr = "others"; EXPECT_EQ(NotificationSlot::GetSlotTypeByString(inputStr, type), false); } + +/** + * @tc.name: GetSlotFlags_00001 + * @tc.desc: Test GetSlotTypeByString method is false. + * @tc.type: FUNC + * @tc.require: issue + */ +HWTEST_F(NotificationSlotTest, GetSlotFlags_00001, Function | SmallTest | Level1) +{ + NotificationSlot notificationSlot; + notificationSlot.SetType(NotificationConstant::SlotType::EMERGENCY_INFORMATION); + ASSERT_EQ(notificationSlot.GetId(), "EMERGENCY_INFORMATION"); + + notificationSlot.SetSlotFlags(1); + ASSERT_EQ(notificationSlot.GetSlotFlags(), 1); +} + +/** + * @tc.name: Unmarshalling_00001 + * @tc.desc: Test GetSlotTypeByString method is false. + * @tc.type: FUNC + * @tc.require: issue + */ +HWTEST_F(NotificationSlotTest, Unmarshalling_00001, Function | SmallTest | Level1) +{ + NotificationSlot notificationSlot; + notificationSlot.SetType(NotificationConstant::SlotType::EMERGENCY_INFORMATION); + Parcel parcel; + auto res = notificationSlot.Marshalling(parcel); + ASSERT_TRUE(res); + Uri uri("123"); + notificationSlot.SetSound(uri); + + sptr notificationSlotSptr = notificationSlot.Unmarshalling(parcel); + ASSERT_NE(notificationSlotSptr, nullptr); + ASSERT_NE(notificationSlotSptr->GetSound().ToString(), "123"); +} + +/** + * @tc.name: MergeVectorToString_00001 + * @tc.desc: Test GetSlotTypeByString method is false. + * @tc.type: FUNC + * @tc.require: issue + */ +HWTEST_F(NotificationSlotTest, MergeVectorToString_00001, Function | SmallTest | Level1) +{ + NotificationSlot notificationSlot; + notificationSlot.SetType(NotificationConstant::SlotType::EMERGENCY_INFORMATION); + std::vector mergeVector; + mergeVector.push_back(100); + + auto res = notificationSlot.MergeVectorToString(mergeVector); + auto it = res.find("100"); + ASSERT_NE(it, std::string::npos); +} } } \ No newline at end of file diff --git a/frameworks/ans/test/unittest/notification_test.cpp b/frameworks/ans/test/unittest/notification_test.cpp index b870f4cff..356e8a61a 100644 --- a/frameworks/ans/test/unittest/notification_test.cpp +++ b/frameworks/ans/test/unittest/notification_test.cpp @@ -597,5 +597,36 @@ HWTEST_F(NotificationTest, GetFinishTimer_00001, Function | SmallTest | Level1) rrc->SetFinishTimer(1); EXPECT_EQ(rrc->GetFinishTimer(), 1); } + +/** + * @tc.name: GetInstanceKey_00001 + * @tc.desc: Test get finish timer. + * @tc.type: FUNC + * @tc.require: issue + */ +HWTEST_F(NotificationTest, GetInstanceKeyr_00001, Function | SmallTest | Level1) +{ + sptr notification(new Notification(nullptr)); + + ASSERT_EQ(notification->GetInstanceKey(), ""); +} + +/** + * @tc.name: Dump_00002 + * @tc.desc: Test Dump_00002 + * @tc.type: FUNC + * @tc.require: issue + */ +HWTEST_F(NotificationTest, Dump_00002, Function | SmallTest | Level1) +{ + sptr notification(new Notification(nullptr)); + std::vector style; + style.push_back(999); + notification->SetVibrationStyle(style); + + auto dump = notification->Dump(); + auto it = dump.find("999"); + ASSERT_NE(it, std::string::npos); +} } // namespace Notification } // namespace OHOS diff --git a/services/ans/test/unittest/common_utils/notification_analytics_util_test.cpp b/services/ans/test/unittest/common_utils/notification_analytics_util_test.cpp index 98b353368..619742b44 100644 --- a/services/ans/test/unittest/common_utils/notification_analytics_util_test.cpp +++ b/services/ans/test/unittest/common_utils/notification_analytics_util_test.cpp @@ -520,5 +520,66 @@ HWTEST_F(NotificationAnalyticsUtilTest, AggregateLiveView_001, Function | SmallT EXPECT_TRUE(jsonData["startTime"].is_number_integer()); EXPECT_TRUE(jsonData["endTime"].is_number_integer()); } + +/** + * @tc.name: ReportFlowControl_001 + * @tc.desc: Test ReportFlowControl_001 + * @tc.type: FUNC + */ +HWTEST_F(NotificationAnalyticsUtilTest, ReportFlowControl_001, Function | SmallTest | Level1) +{ + auto res = NotificationAnalyticsUtil::ReportFlowControl(0); + EXPECT_TRUE(res); +} + +/** + * @tc.name: RemoveExpired_001 + * @tc.desc: Test RemoveExpired_001 + * @tc.type: FUNC + */ +HWTEST_F(NotificationAnalyticsUtilTest, RemoveExpired_001, Function | SmallTest | Level1) +{ + std::list list; + auto now = std::chrono::system_clock::now(); + list.push_back(now); + EXPECT_EQ(list.size(), 1); + + NotificationAnalyticsUtil::RemoveExpired(list, now, 100); + EXPECT_EQ(list.size(), 1); + + NotificationAnalyticsUtil::RemoveExpired(list, now, -1); + EXPECT_EQ(list.size(), 0); +} + +/** + * @tc.name: ReportSlotEnable_001 + * @tc.desc: Test ReportSlotEnable_001 + * @tc.type: FUNC + */ +HWTEST_F(NotificationAnalyticsUtilTest, ReportSlotEnable_001, Function | SmallTest | Level1) +{ + NotificationAnalyticsUtil::GetAllSlotMessageCache(100); + for (auto i = 0; i <= 20; ++i) { + NotificationAnalyticsUtil::ReportSlotEnable(); + } + auto res = NotificationAnalyticsUtil::ReportSlotEnable(); + EXPECT_FALSE(res); +} + +/** + * @tc.name: GetReportSlotMessage_001 + * @tc.desc: Test GetReportSlotMessage_001 + * @tc.type: FUNC + */ +HWTEST_F(NotificationAnalyticsUtilTest, GetReportSlotMessage_001, Function | SmallTest | Level1) +{ + std::string budleEntryKey = "1_1_1_1_1_1_1"; + std::string budleEntryValue = "1"; + ReportSlotMessage reportSlotMessage; + int32_t userId = 1; + auto res = NotificationAnalyticsUtil::GetReportSlotMessage( + budleEntryKey, budleEntryValue, reportSlotMessage, userId); + EXPECT_FALSE(res); +} } } \ No newline at end of file -- Gitee