From decabcc15cf2c8aff9f9a064d019698e048c9408 Mon Sep 17 00:00:00 2001 From: xuezhongzhu Date: Tue, 20 Sep 2022 14:21:55 +0800 Subject: [PATCH] =?UTF-8?q?ssueNo:https:https://gitee.com/openharmony/noti?= =?UTF-8?q?fication=5Fdistributed=5Fnotification=5Fservice/issues/I5S0ZS?= =?UTF-8?q?=20Description:TDD=E7=94=A8=E4=BE=8B=E5=88=86=E6=94=AF=E8=A6=86?= =?UTF-8?q?=E7=9B=96=E7=8E=87=20Sig:SIG=5FApplicationFramework=20Feature?= =?UTF-8?q?=20or=20Bugfix:Bugfix=20Binary=20Source:=20No=20Signed-off-by:?= =?UTF-8?q?=20xuezhongzhu=20?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Change-Id: I9a58fa6d6d02c6a54f970bb59a00235536230c7c --- frameworks/ans/test/unittest/BUILD.gn | 1 + .../unittest/notification_content_test.cpp | 127 ++++++++++++++++++ 2 files changed, 128 insertions(+) create mode 100644 frameworks/ans/test/unittest/notification_content_test.cpp diff --git a/frameworks/ans/test/unittest/BUILD.gn b/frameworks/ans/test/unittest/BUILD.gn index 9a116044d..e6b398f46 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_content_test.cpp", "${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", diff --git a/frameworks/ans/test/unittest/notification_content_test.cpp b/frameworks/ans/test/unittest/notification_content_test.cpp new file mode 100644 index 000000000..ce0b1afb1 --- /dev/null +++ b/frameworks/ans/test/unittest/notification_content_test.cpp @@ -0,0 +1,127 @@ +/* + * 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_basic_content.h" +#include "notification_content.h" +#undef private +#undef protected + +using namespace testing::ext; +namespace OHOS { +namespace Notification { +class NotificationContentTest : public testing::Test { +public: + static void SetUpTestCase() {}; + static void TearDownTestCase() {}; + void SetUp() {}; + void TearDown() {}; +}; + +/** + * @tc.name: NotificationContentMarshalling_0100 + * @tc.desc: Marshalling + * @tc.type: FUNC + * @tc.require: issueI5S0ZS + */ +HWTEST_F(NotificationContentTest, NotificationContentMarshalling_0100, Level1) +{ + Parcel parcel; + std::shared_ptr normalContent = std::make_shared(); + EXPECT_NE(normalContent, nullptr); + NotificationContent notificationContent(normalContent); + auto result = notificationContent.Marshalling(parcel); + EXPECT_EQ(result, true); +} + +/** + * @tc.name: NotificationContentReadFromParcel_0100 + * @tc.desc: ReadFromParcel + * @tc.type: FUNC + * @tc.require: issueI5S0ZS + */ +HWTEST_F(NotificationContentTest, NotificationContentReadFromParcel_0100, Level1) +{ + Parcel parcel; + std::shared_ptr normalContent = std::make_shared(); + EXPECT_NE(normalContent, nullptr); + NotificationContent notificationContent(normalContent); + auto result = notificationContent.ReadFromParcel(parcel); + EXPECT_EQ(result, true); +} + +/** + * @tc.name: NotificationBasicContentGetAdditionalText_0100 + * @tc.desc: GetAdditionalText + * @tc.type: FUNC + * @tc.require: issueI5S0ZS + */ +HWTEST_F(NotificationContentTest, NotificationBasicContentGetAdditionalText_0100, Level1) +{ + std::string additionalText = "test"; + NotificationBasicContent notificationBasicContent; + notificationBasicContent.SetAdditionalText(additionalText); + auto result = notificationBasicContent.GetAdditionalText(); + EXPECT_EQ(result, additionalText); +} + +/** + * @tc.name: NotificationBasicContentGetText_0100 + * @tc.desc: GetText + * @tc.type: FUNC + * @tc.require: issueI5S0ZS + */ +HWTEST_F(NotificationContentTest, NotificationBasicContentGetText_0100, Level1) +{ + std::string Text = "test"; + NotificationBasicContent notificationBasicContent; + notificationBasicContent.SetText(Text); + auto result = notificationBasicContent.GetText(); + EXPECT_EQ(result, Text); +} + +/** + * @tc.name: NotificationBasicContentGetTitle_0100 + * @tc.desc: GetTitle + * @tc.type: FUNC + * @tc.require: issueI5S0ZS + */ +HWTEST_F(NotificationContentTest, NotificationBasicContentGetTitle_0100, Level1) +{ + std::string title = "titleTest"; + NotificationBasicContent notificationBasicContent; + notificationBasicContent.SetTitle(title); + auto result = notificationBasicContent.GetTitle(); + EXPECT_EQ(result, title); +} + +/** + * @tc.name: NotificationBasicContentMarshalling_0100 + * @tc.desc: Marshalling + * @tc.type: FUNC + * @tc.require: issueI5S0ZS + */ +HWTEST_F(NotificationContentTest, NotificationBasicContentMarshalling_0100, Level1) +{ + Parcel parcel; + NotificationBasicContent notificationBasicContent; + auto result = notificationBasicContent.Marshalling(parcel); + EXPECT_EQ(result, true); +} +} +} -- Gitee