From 938396d671c2869eb2236e0dc8a0925d97baa80f Mon Sep 17 00:00:00 2001 From: xuezhongzhu Date: Fri, 16 Sep 2022 16:10:29 +0800 Subject: [PATCH] =?UTF-8?q?ssueNo:https://gitee.com/openharmony/notificati?= =?UTF-8?q?on=5Fdistributed=5Fnotification=5Fservice/issues/I5RH5J=20Descr?= =?UTF-8?q?iption:=E9=80=9A=E7=9F=A5=E5=AD=90=E7=B3=BB=E7=BB=9FTDD?= =?UTF-8?q?=E7=94=A8=E4=BE=8B=E8=A6=86=E7=9B=96=20Sig:SIG=5FApplicationFra?= =?UTF-8?q?mework=20Feature=20or=20Bugfix:Bugfix=20Binary=20Source:=20No?= =?UTF-8?q?=20Signed-off-by:=20xuezhongzhu=20?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Change-Id: I823719706a34a46e8db7709ae859d36f566d9797 --- .../unittest/notification_hisysevent_test.cpp | 77 +++++++++++++++++++ .../notification_slot_filter_test.cpp | 28 ++++++- 2 files changed, 104 insertions(+), 1 deletion(-) diff --git a/services/ans/test/unittest/notification_hisysevent_test.cpp b/services/ans/test/unittest/notification_hisysevent_test.cpp index 829e0e6a4..aea905907 100644 --- a/services/ans/test/unittest/notification_hisysevent_test.cpp +++ b/services/ans/test/unittest/notification_hisysevent_test.cpp @@ -18,6 +18,11 @@ #include "event_report.h" #include "notification_constant.h" #include "notification_content.h" +#define private public +#define protected public +#include "notification.h" +#undef private +#undef protected namespace OHOS { namespace Notification { @@ -81,6 +86,11 @@ HWTEST_F(NotificationHisyseventTest, SendSubscriberErrorSysEvent_0100, Level1) return (str == appNames.front()) ? (bundleName + str) : (bundleName + "," + str); }); EventReport::SendHiSysEvent(SUBSCRIBE_ERROR, eventInfo); + std::string deviceId = "123"; + sptr request = nullptr; + Notification notificationTest(deviceId, request); + auto result = notificationTest.GetDeviceId(); + EXPECT_EQ(result, deviceId); GTEST_LOG_(INFO) << "SendSubscriberErrorSysEvent_0100 end"; } @@ -101,6 +111,15 @@ HWTEST_F(NotificationHisyseventTest, SendEnableNotificationErrorSysEvent_0100, L eventInfo.enable = true; eventInfo.errCode = TEST_ERROR_CODE; EventReport::SendHiSysEvent(ENABLE_NOTIFICATION_ERROR, eventInfo); + std::string deviceId = "123"; + sptr request = nullptr; + int32_t notificationId =5; + Notification notificationTest(deviceId, request); + NotificationRequest notificationRequest(notificationId); + pid_t myPid = notificationRequest.GetCreatorPid(); + notificationRequest.SetCreatorPid(myPid); + auto result = notificationTest.GetPid(); + EXPECT_EQ(result, myPid); GTEST_LOG_(INFO) << "SendEnableNotificationErrorSysEvent_0100 end"; } @@ -122,6 +141,11 @@ HWTEST_F(NotificationHisyseventTest, SendEnableNotificationSlotErrorSysEvent_010 eventInfo.slotType = NotificationConstant::SERVICE_REMINDER; eventInfo.errCode = TEST_ERROR_CODE; EventReport::SendHiSysEvent(ENABLE_NOTIFICATION_SLOT_ERROR, eventInfo); + std::string deviceId = "123"; + sptr request = nullptr; + Notification notificationTest(deviceId, request); + auto result = notificationTest.IsUnremovable(); + EXPECT_EQ(result, false); GTEST_LOG_(INFO) << "SendEnableNotificationSlotErrorSysEvent_0100 end"; } @@ -143,6 +167,11 @@ HWTEST_F(NotificationHisyseventTest, SendPublishErrorSysEvent_0100, Level1) eventInfo.userId = TEST_USER_ID; eventInfo.errCode = TEST_ERROR_CODE; EventReport::SendHiSysEvent(PUBLISH_ERROR, eventInfo); + std::string deviceId = "123"; + sptr request = nullptr; + Notification notificationTest(deviceId, request); + auto result = notificationTest.IsGroup(); + EXPECT_EQ(result, false); GTEST_LOG_(INFO) << "SendPublishErrorSysEvent_0100 end"; } @@ -162,6 +191,11 @@ HWTEST_F(NotificationHisyseventTest, SendFlowControlOccurSysEvent_0100, Level1) eventInfo.bundleName = TEST_BUNDLE_OPTION_BUNDLE_NAME; eventInfo.uid = TEST_BUNDLE_OPTION_UID; EventReport::SendHiSysEvent(FLOW_CONTROL_OCCUR, eventInfo); + std::string deviceId = "123"; + sptr request = nullptr; + Notification notificationTest(deviceId, request); + auto result = notificationTest.IsFloatingIcon(); + EXPECT_EQ(result, false); GTEST_LOG_(INFO) << "SendFlowControlOccurSysEvent_0100 end"; } @@ -195,6 +229,12 @@ HWTEST_F(NotificationHisyseventTest, SendSubscribeSysEvent_0100, Level1) return (str == anotherBundle.front()) ? (bundleName + str) : (bundleName + "," + str); }); EventReport::SendHiSysEvent(SUBSCRIBE, eventInfo); + std::string deviceId = "123"; + sptr request = nullptr; + Parcel p; + Notification notificationTest(deviceId, request); + auto result = notificationTest.MarshallingBool(p); + EXPECT_EQ(result, true); GTEST_LOG_(INFO) << "SendSubscribeSysEvent_0100 end"; } @@ -219,6 +259,12 @@ HWTEST_F(NotificationHisyseventTest, SendUnSubscribeSysEvent_0100, Level1) return (str == appNames.front()) ? (bundleName + str) : (bundleName + "," + str); }); EventReport::SendHiSysEvent(UNSUBSCRIBE, eventInfo); + std::string deviceId = "123"; + sptr request = nullptr; + Parcel p; + Notification notificationTest(deviceId, request); + auto result = notificationTest.MarshallingInt32(p); + EXPECT_EQ(result, true); GTEST_LOG_(INFO) << "SendUnSubscribeSysEvent_0100 end"; } @@ -238,6 +284,12 @@ HWTEST_F(NotificationHisyseventTest, SendEnableNotificationSysEvent_0100, Level1 eventInfo.uid = getuid(); eventInfo.enable = true; EventReport::SendHiSysEvent(ENABLE_NOTIFICATION, eventInfo); + std::string deviceId = "123"; + sptr request = nullptr; + Parcel p; + Notification notificationTest(deviceId, request); + auto result = notificationTest.MarshallingInt64(p); + EXPECT_EQ(result, true); GTEST_LOG_(INFO) << "SendEnableNotificationSysEvent_0100 end"; } @@ -258,6 +310,12 @@ HWTEST_F(NotificationHisyseventTest, SendEnableNotificationSlotSysEvent_0100, Le eventInfo.enable = true; eventInfo.slotType = NotificationConstant::CONTENT_INFORMATION; EventReport::SendHiSysEvent(ENABLE_NOTIFICATION_SLOT, eventInfo); + std::string deviceId = "123"; + sptr request = nullptr; + Parcel p; + Notification notificationTest(deviceId, request); + auto result = notificationTest.MarshallingParcelable(p); + EXPECT_EQ(result, true); GTEST_LOG_(INFO) << "SendEnableNotificationSlotSysEvent_0100 end"; } @@ -278,6 +336,12 @@ HWTEST_F(NotificationHisyseventTest, SendPublishSysEvent_0100, Level1) eventInfo.bundleName = TEST_CREATER_BUNDLE_NAME; eventInfo.userId = TEST_USER_ID; EventReport::SendHiSysEvent(PUBLISH, eventInfo); + std::string deviceId = "123"; + sptr request = nullptr; + Parcel p; + Notification notificationTest(deviceId, request); + auto result = notificationTest.Marshalling(p); + EXPECT_EQ(result, true); GTEST_LOG_(INFO) << "SendPublishSysEvent_0100 end"; } @@ -298,6 +362,12 @@ HWTEST_F(NotificationHisyseventTest, SendCancelSysEvent_0100, Level1) eventInfo.bundleName = TEST_BUNDLE_OPTION_BUNDLE_NAME; eventInfo.uid = TEST_BUNDLE_OPTION_UID; EventReport::SendHiSysEvent(CANCEL, eventInfo); + std::string deviceId = "123"; + sptr request = nullptr; + Parcel p; + Notification notificationTest(deviceId, request); + auto result = notificationTest.ReadFromParcel(p); + EXPECT_EQ(result, true); GTEST_LOG_(INFO) << "SendCancelSysEvent_0100 end"; } @@ -318,6 +388,13 @@ HWTEST_F(NotificationHisyseventTest, SendRemoveSysEvent_0100, Level1) eventInfo.bundleName = TEST_BUNDLE_OPTION_BUNDLE_NAME; eventInfo.uid = TEST_BUNDLE_OPTION_UID; EventReport::SendHiSysEvent(REMOVE, eventInfo); + std::string deviceId = "123"; + sptr request = nullptr; + std::vector style = {1}; + Notification notificationTest(deviceId, request); + notificationTest.SetVibrationStyle(style); + auto result = notificationTest.GetVibrationStyle(); + EXPECT_EQ(result, style); GTEST_LOG_(INFO) << "SendRemoveSysEvent_0100 end"; } diff --git a/services/ans/test/unittest/notification_slot_filter_test.cpp b/services/ans/test/unittest/notification_slot_filter_test.cpp index 7cc73fa00..90e5730dc 100644 --- a/services/ans/test/unittest/notification_slot_filter_test.cpp +++ b/services/ans/test/unittest/notification_slot_filter_test.cpp @@ -16,7 +16,13 @@ #include #include +#define private public +#define protected public +#include "notification_slot.h" +#undef private +#undef protected #include "notification_slot_filter.h" +#include "notification_subscribe_info.h" using namespace testing::ext; namespace OHOS { @@ -38,6 +44,13 @@ HWTEST_F(NotificationSlotFilterTest, NotificationSlotFilterTest_00100, Function { NotificationSlotFilter notificationSlotFilter; notificationSlotFilter.OnStart(); + + // NotificationSlot Marshalling TDD test + Parcel p; + NotificationConstant::SlotType type = NotificationConstant::SlotType::CUSTOM; + NotificationSlot notificationSlot(type); + auto result = notificationSlot.Marshalling(p); + EXPECT_EQ(result, true); } /** @@ -49,6 +62,13 @@ HWTEST_F(NotificationSlotFilterTest, NotificationSlotFilterTest_00200, Function { NotificationSlotFilter notificationSlotFilter; notificationSlotFilter.OnStop(); + + // NotificationSlot ReadFromParcel TDD test + Parcel p; + NotificationConstant::SlotType type = NotificationConstant::SlotType::CUSTOM; + NotificationSlot notificationSlot(type); + auto result = notificationSlot.ReadFromParcel(p); + EXPECT_EQ(result, false); } /** @@ -64,6 +84,12 @@ HWTEST_F(NotificationSlotFilterTest, NotificationSlotFilterTest_00300, Function record->notification = new Notification(record->request); record->slot = new NotificationSlot(NotificationConstant::SlotType::SOCIAL_COMMUNICATION); notificationSlotFilter.OnPublish(record); + + // NotificationSubscribeInfo Marshalling TDD test + Parcel p; + NotificationSubscribeInfo notificationSubscribeInfo; + auto result = notificationSubscribeInfo.Marshalling(p); + EXPECT_EQ(result, true); } } // namespace Notification -} // namespace OHOS \ No newline at end of file +} // namespace OHOS -- Gitee