diff --git a/frameworks/ans/test/unittest/BUILD.gn b/frameworks/ans/test/unittest/BUILD.gn index 9a116044dfedceef1d728b4a5d7d52153fd1d7a6..e6b398f4675090a3ce79e4bb885bdce6f8049d55 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 0000000000000000000000000000000000000000..ce0b1afb1ce6a797d7a4077fa717e624a51c0806 --- /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); +} +} +}