From 3115d41c52a1370349a9124c74110dd182eb79e6 Mon Sep 17 00:00:00 2001 From: xuezhongzhu Date: Mon, 19 Sep 2022 18:54:17 +0800 Subject: [PATCH] =?UTF-8?q?ssueNo:https://gitee.com/openharmony/notificati?= =?UTF-8?q?on=5Fdistributed=5Fnotification=5Fservice/issues/I5RW70=20Descr?= =?UTF-8?q?iption:TDD=E5=88=86=E6=94=AF=E8=A6=86=E7=9B=96=E7=8E=87=20Sig:S?= =?UTF-8?q?IG=5FApplicationFramework=20Feature=20or=20Bugfix:Bugfix=20Bina?= =?UTF-8?q?ry=20Source:=20No=20Signed-off-by:=20xuezhongzhu=20?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Change-Id: Iee94104a94e58aa9a9bcb5c815364337e3a14039 --- frameworks/ans/test/unittest/BUILD.gn | 1 + .../unittest/notification_request_test.cpp | 180 ++++++++++++++++++ 2 files changed, 181 insertions(+) create mode 100644 frameworks/ans/test/unittest/notification_request_test.cpp diff --git a/frameworks/ans/test/unittest/BUILD.gn b/frameworks/ans/test/unittest/BUILD.gn index bfc7c602a..9a116044d 100644 --- a/frameworks/ans/test/unittest/BUILD.gn +++ b/frameworks/ans/test/unittest/BUILD.gn @@ -30,6 +30,7 @@ ohos_unittest("ans_reminder_unit_test") { ] sources = [ + "${frameworks_module_ans_path}/test/unittest/notification_request_test.cpp", "${frameworks_module_ans_path}/test/unittest/reminder_request_alarm_test.cpp", "${frameworks_module_ans_path}/test/unittest/reminder_request_calendar_test.cpp", "${frameworks_module_ans_path}/test/unittest/reminder_request_test.cpp", diff --git a/frameworks/ans/test/unittest/notification_request_test.cpp b/frameworks/ans/test/unittest/notification_request_test.cpp new file mode 100644 index 000000000..6f11e5b3c --- /dev/null +++ b/frameworks/ans/test/unittest/notification_request_test.cpp @@ -0,0 +1,180 @@ +/* + * Copyright (c) 2021-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 + +#define private public +#define protected public +#include "notification_request.h" +#undef private +#undef protected +#include "want_agent_helper.h" + +using namespace testing::ext; +namespace OHOS { +namespace Notification { +class NotificationRequestTest : public testing::Test { +public: + static void SetUpTestCase() {}; + static void TearDownTestCase() {}; + void SetUp() {}; + void TearDown() {}; +}; + +/** + * @tc.name: NotificationGetWantAgent_0100 + * @tc.desc: GetWantAgent + * @tc.type: FUNC + * @tc.require: issueI5RW70 + */ +HWTEST_F(NotificationRequestTest, NotificationGetWantAgent_0100, Level1) +{ + int32_t myNotificationId = 10; + NotificationRequest notificationRequest(myNotificationId); + std::shared_ptr wantAgent = notificationRequest.GetWantAgent(); + EXPECT_EQ(wantAgent, nullptr); +} + +/** + * @tc.name: NotificationSetMaxScreenWantAgent_0100 + * @tc.desc: SetMaxScreenWantAgent + * @tc.type: FUNC + * @tc.require: issueI5RW70 + */ +HWTEST_F(NotificationRequestTest, NotificationSetMaxScreenWantAgent_0100, Level1) +{ + int32_t myNotificationId = 10; + NotificationRequest notificationRequest(myNotificationId); + std::shared_ptr wantAgent = notificationRequest.GetWantAgent(); + notificationRequest.SetMaxScreenWantAgent(wantAgent); + auto result = notificationRequest.GetMaxScreenWantAgent(); + EXPECT_EQ(result, nullptr); +} + +/** + * @tc.name: NotificationGetAdditionalData_0100 + * @tc.desc: GetAdditionalData + * @tc.type: FUNC + * @tc.require: issueI5RW70 + */ +HWTEST_F(NotificationRequestTest, NotificationGetAdditionalData_0100, Level1) +{ + int32_t myNotificationId = 10; + std::shared_ptr additionalPtr; + NotificationRequest notificationRequest(myNotificationId); + notificationRequest.SetAdditionalData(additionalPtr); + auto result = notificationRequest.GetAdditionalData(); + EXPECT_EQ(result, nullptr); +} + +/** + * @tc.name: NotificationSetIsAgentNotification_0100 + * @tc.desc: SetIsAgentNotification + * @tc.type: FUNC + * @tc.require: issueI5RW70 + */ +HWTEST_F(NotificationRequestTest, NotificationSetIsAgentNotification_0100, Level1) +{ + int32_t myNotificationId = 10; + bool isAgentTrue = true; + NotificationRequest notificationRequest(myNotificationId); + notificationRequest.SetIsAgentNotification(isAgentTrue); + auto result = notificationRequest.IsAgentNotification(); + EXPECT_EQ(result, true); + bool isAgentFalse = false; + notificationRequest.SetIsAgentNotification(isAgentFalse); + result = notificationRequest.IsAgentNotification(); + EXPECT_EQ(result, false); +} + +/** + * @tc.name: NotificationOwnerUid_0100 + * @tc.desc: SetOwnerUid and GetOwnerUid + * @tc.type: FUNC + * @tc.require: issueI5RW70 + */ +HWTEST_F(NotificationRequestTest, NotificationOwnerUid_0100, Level1) +{ + int32_t myNotificationId = 10; + int32_t uid = 5; + NotificationRequest notificationRequest(myNotificationId); + notificationRequest.SetOwnerUid(uid); + auto result = notificationRequest.GetOwnerUid(); + EXPECT_EQ(result, uid); +} + +/** + * @tc.name: NotificationOwnerUserId_0100 + * @tc.desc: SetOwnerUserId and GetOwnerUserId + * @tc.type: FUNC + * @tc.require: issueI5RW70 + */ +HWTEST_F(NotificationRequestTest, NotificationOwnerUserId_0100, Level1) +{ + int32_t myNotificationId = 10; + int32_t userid = 5; + NotificationRequest notificationRequest(myNotificationId); + notificationRequest.SetOwnerUserId(userid); + auto result = notificationRequest.GetOwnerUserId(); + EXPECT_EQ(result, userid); +} + +/** + * @tc.name: NotificationMarshalling_0100 + * @tc.desc: Marshalling + * @tc.type: FUNC + * @tc.require: issueI5RW70 + */ +HWTEST_F(NotificationRequestTest, NotificationMarshalling_0100, Level1) +{ + int32_t myNotificationId = 10; + Parcel parcel; + NotificationRequest notificationRequest(myNotificationId); + auto result = notificationRequest.Marshalling(parcel); + EXPECT_EQ(result, true); +} + +/** + * @tc.name: NotificationReadFromParcel_0100 + * @tc.desc: ReadFromParcel + * @tc.type: FUNC + * @tc.require: issueI5RW70 + */ +HWTEST_F(NotificationRequestTest, NotificationReadFromParcel_0100, Level1) +{ + int32_t myNotificationId = 10; + Parcel parcel; + NotificationRequest notificationRequest(myNotificationId); + auto result = notificationRequest.ReadFromParcel(parcel); + EXPECT_EQ(result, false); +} + +/** + * @tc.name: NotificationSetReceiverUserId_0100 + * @tc.desc: SetReceiverUserId + * @tc.type: FUNC + * @tc.require: issueI5RW70 + */ +HWTEST_F(NotificationRequestTest, NotificationSetReceiverUserId_0100, Level1) +{ + int32_t myNotificationId = 10; + int32_t userid = 5; + NotificationRequest notificationRequest(myNotificationId); + notificationRequest.SetReceiverUserId(userid); + auto result = notificationRequest.GetReceiverUserId(); + EXPECT_EQ(result, userid); +} +} +} -- Gitee