diff --git a/frameworks/ans/test/unittest/BUILD.gn b/frameworks/ans/test/unittest/BUILD.gn index 9e93dde4af23a56bea6372500d954bd6538d9457..1f7946df6d8b6915ea4ed4ecc305a293cab9aa37 100644 --- a/frameworks/ans/test/unittest/BUILD.gn +++ b/frameworks/ans/test/unittest/BUILD.gn @@ -40,6 +40,7 @@ ohos_unittest("ans_reminder_unit_test") { "${frameworks_module_ans_path}/test/unittest/notification_flags_test.cpp", "${frameworks_module_ans_path}/test/unittest/notification_helper_test.cpp", "${frameworks_module_ans_path}/test/unittest/notification_local_live_view_content_test.cpp", + "${frameworks_module_ans_path}/test/unittest/notification_local_live_view_button_test.cpp", "${frameworks_module_ans_path}/test/unittest/notification_long_text_content_test.cpp", "${frameworks_module_ans_path}/test/unittest/notification_media_content_test.cpp", "${frameworks_module_ans_path}/test/unittest/notification_multiline_content_test.cpp", diff --git a/frameworks/ans/test/unittest/notification_local_live_view_button_test.cpp b/frameworks/ans/test/unittest/notification_local_live_view_button_test.cpp new file mode 100644 index 0000000000000000000000000000000000000000..588e842622d4e3fa3a4420366734b8c44d8c89af --- /dev/null +++ b/frameworks/ans/test/unittest/notification_local_live_view_button_test.cpp @@ -0,0 +1,142 @@ +/* + * Copyright (c) 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 +#include +#include +#include "notification_local_live_view_button.h" + +using namespace testing::ext; +namespace OHOS { +namespace Notification { +class NotificationLocalLiveViewButtonTest : public testing::Test { +public: + static void SetUpTestCase() {} + static void TearDownTestCase() {} + void SetUp() {} + void TearDown() {} +}; + +/** + * @tc.name: AddSingleButtonName__00001 + * @tc.desc: Test buttonNames_ parameters. + * @tc.type: FUNC + * @tc.require: issue + */ +HWTEST_F(NotificationLocalLiveViewButtonTest, AddSingleButtonName__00001, Function | SmallTest | Level1) +{ + std::string buttonName = "testOneButton"; + auto rrc = std::make_shared(); + rrc->addSingleButtonName(buttonName); + EXPECT_EQ(rrc->GetAllButtonNames()[0], buttonName); +} + +/** + * @tc.name: AddSingleButtonName__00002 + * @tc.desc: Test buttonNames_ parameters. + * @tc.type: FUNC + * @tc.require: issue + */ +HWTEST_F(NotificationLocalLiveViewButtonTest, AddSingleButtonName__00002, Function | SmallTest | Level1) +{ + std::string buttonName = "testOneButton"; + auto rrc = std::make_shared(); + rrc->addSingleButtonName(buttonName); + EXPECT_EQ(rrc->GetAllButtonNames().size(), 1); +} + +/** + * @tc.name: AddSingleButtonName__00003 + * @tc.desc: Test buttonNames_ parameters. + * @tc.type: FUNC + * @tc.require: issue + */ +HWTEST_F(NotificationLocalLiveViewButtonTest, AddSingleButtonName__00003, Function | SmallTest | Level1) +{ + std::string buttonNameOne = "testOneButton"; + std::string buttonNameTwo = "testTwoButton"; + std::string buttonNameThree = "testThreeButton"; + std::string buttonNameFour = "testFourButton"; + auto rrc = std::make_shared(); + rrc->addSingleButtonName(buttonNameOne); + rrc->addSingleButtonName(buttonNameTwo); + rrc->addSingleButtonName(buttonNameThree); + rrc->addSingleButtonName(buttonNameFour); + EXPECT_EQ(rrc->GetAllButtonNames().size(), 3); +} + +/** + * @tc.name: ToJson_00001 + * @tc.desc: Test ToJson parameters. + * @tc.type: FUNC + * @tc.require: issueI5WBBH + */ +HWTEST_F(NotificationLocalLiveViewButtonTest, ToJson_00001, Function | SmallTest | Level1) +{ + nlohmann::json jsonObject; + auto rrc = std::make_shared(); + rrc->FromJson(jsonObject); + EXPECT_EQ(rrc->ToJson(jsonObject), true); +} + +/** + * @tc.name: FromJson_00001 + * @tc.desc: Test FromJson parameters. + * @tc.type: FUNC + * @tc.require: issue + */ +HWTEST_F(NotificationLocalLiveViewButtonTest, FromJson_00001, Function | SmallTest | Level1) +{ + auto rrc = std::make_shared(); + nlohmann::json jsonObject = nlohmann::json{"test"}; + EXPECT_EQ(jsonObject.is_object(), false); + EXPECT_EQ(rrc->FromJson(jsonObject), nullptr); +} + +/** + * @tc.name: Marshalling_00001 + * @tc.desc: Test Marshalling parameters. + * @tc.type: FUNC + * @tc.require: issueI5WBBH + */ +HWTEST_F(NotificationLocalLiveViewButtonTest, Marshalling_00001, Function | SmallTest | Level1) +{ + Parcel parcel; + auto rrc = std::make_shared(); + EXPECT_EQ(rrc->Marshalling(parcel), true); +} + +/** + * @tc.name: Unmarshalling_00001 + * @tc.desc: Test Unmarshalling parameters. + * @tc.type: FUNC + * @tc.require: issueI5WBBH + */ +HWTEST_F(NotificationLocalLiveViewButtonTest, Unmarshalling_001, Function | SmallTest | Level1) +{ + bool unmarshalling = true; + Parcel parcel; + std::shared_ptr result = + std::make_shared(); + + if (nullptr != result) { + if (nullptr == result->Unmarshalling(parcel)) { + unmarshalling = false; + } + } + EXPECT_EQ(unmarshalling, true); +} +} +} 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 bd0219e39f1884590735768ad973fbe46dc31ffa..664de0dc0c4ec1b8d65468f99cfa9c3741671d3d 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 @@ -40,5 +40,85 @@ HWTEST_F(NotificationLocalLiveViewContentTest, SetTypeCode_00001, Function | Sma rrc->SetType(typeCode); EXPECT_EQ(rrc->GetType(), typeCode); } + + +/** + * @tc.name: ToJson_00001 + * @tc.desc: Test ToJson parameters. + * @tc.type: FUNC + * @tc.require: issueI5WBBH + */ +HWTEST_F(NotificationLocalLiveViewContentTest, ToJson_00001, Function | SmallTest | Level1) +{ + nlohmann::json jsonObject; + auto rrc = std::make_shared(); + rrc->FromJson(jsonObject); + EXPECT_EQ(rrc->ToJson(jsonObject), true); +} + +/** + * @tc.name: FromJson_00002 + * @tc.desc: Test FromJson parameters. + * @tc.type: FUNC + * @tc.require: issue + */ +HWTEST_F(NotificationLocalLiveViewContentTest, FromJson_00002, Function | SmallTest | Level1) +{ + auto rrc = std::make_shared(); + nlohmann::json jsonObject = nlohmann::json{"typeCode", "capsule", "button", "progress", "time"}; + rrc->FromJson(jsonObject); + EXPECT_EQ(jsonObject.is_object(), false); + EXPECT_EQ(rrc->FromJson(jsonObject), NULL); +} + +/** + * @tc.name: Marshalling_00001 + * @tc.desc: Test Marshalling parameters. + * @tc.type: FUNC + * @tc.require: issueI5WBBH + */ +HWTEST_F(NotificationLocalLiveViewContentTest, Marshalling_00001, Function | SmallTest | Level1) +{ + Parcel parcel; + auto rrc = std::make_shared(); + EXPECT_EQ(rrc->Marshalling(parcel), true); +} + +/** + * @tc.name: Unmarshalling_00001 + * @tc.desc: Test Unmarshalling parameters. + * @tc.type: FUNC + * @tc.require: issueI5WBBH + */ +HWTEST_F(NotificationLocalLiveViewContentTest, Unmarshalling_001, Function | SmallTest | Level1) +{ + bool unmarshalling = true; + Parcel parcel; + std::shared_ptr result = + std::make_shared(); + + if (nullptr != result) { + if (nullptr == result->Unmarshalling(parcel)) { + unmarshalling = false; + } + } + EXPECT_EQ(unmarshalling, false); +} + +/** + * @tc.name: FromJson_00004 + * @tc.desc: Test FromJson parameters. + * @tc.type: FUNC + * @tc.require: issue + */ +HWTEST_F(NotificationLocalLiveViewContentTest, FromJson_00004, Function | SmallTest | Level1) +{ + auto rrc = std::make_shared(); + nlohmann::json jsonObject = nlohmann::json{ + {"longText", "test"}, + {"expandedTitle", "test"}, + {"briefText", "test"}}; + EXPECT_NE(rrc->FromJson(jsonObject), nullptr); +} } }