1 /*
2  * Copyright (c) 2023 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #include <gtest/gtest.h>
17 #include <string>
18 #include <unistd.h>
19 #include "notification_button_option.h"
20 
21 using namespace testing::ext;
22 namespace OHOS {
23 namespace Notification {
24 class NotificationButtonOptionTest : public testing::Test {
25 public:
SetUpTestCase()26     static void SetUpTestCase() {}
TearDownTestCase()27     static void TearDownTestCase() {}
SetUp()28     void SetUp() {}
TearDown()29     void TearDown() {}
30 };
31 
32 /**
33  * @tc.name: SetButtonName_00001
34  * @tc.desc: Test buttonName_ parameters.
35  * @tc.type: FUNC
36  * @tc.require: issue
37  */
38 HWTEST_F(NotificationButtonOptionTest, SetButtonName_00001, Function | SmallTest | Level1)
39 {
40     auto rrc = std::make_shared<NotificationButtonOption>();
41     std::string buttonName = "testbuttonName";
42     rrc->SetButtonName(buttonName);
43     EXPECT_EQ(rrc->GetButtonName(), buttonName);
44 }
45 
46 /**
47  * @tc.name: Dump_00001
48  * @tc.desc: Test buttonNames_ dump.
49  * @tc.type: FUNC
50  * @tc.require: issue
51  */
52 HWTEST_F(NotificationButtonOptionTest, Dump_00001, Function | SmallTest | Level1)
53 {
54     auto rrc = std::make_shared<NotificationButtonOption>();
55     std::string buttonName = "testbuttonName";
56     rrc->SetButtonName(buttonName);
57     EXPECT_EQ(rrc->Dump(), "NotificationButtonOption{ "
58         "buttonName = " + buttonName +" }");
59 }
60 
61 /**
62  * @tc.name: FromJson_00001
63  * @tc.desc: Test FromJson parameters.
64  * @tc.type: FUNC
65  * @tc.require: issue
66  */
67 HWTEST_F(NotificationButtonOptionTest, FromJson_00001, Function | SmallTest | Level1)
68 {
69     auto rrc = std::make_shared<NotificationButtonOption>();
70     nlohmann::json jsonObject = nlohmann::json{"buttonName"};
71     EXPECT_EQ(jsonObject.is_object(), false);
72     EXPECT_EQ(rrc->FromJson(jsonObject), nullptr);
73 }
74 
75 /**
76  * @tc.name: Marshalling_00001
77  * @tc.desc: Test Marshalling parameters.
78  * @tc.type: FUNC
79  * @tc.require: issueI5WBBH
80  */
81 HWTEST_F(NotificationButtonOptionTest, Marshalling_00001, Function | SmallTest | Level1)
82 {
83     Parcel parcel;
84     auto rrc = std::make_shared<NotificationButtonOption>();
85     EXPECT_EQ(rrc->Marshalling(parcel), true);
86 }
87 
88 /**
89  * @tc.name: Unmarshalling_00001
90  * @tc.desc: Test Unmarshalling parameters.
91  * @tc.type: FUNC
92  * @tc.require: issueI5WBBH
93  */
94 HWTEST_F(NotificationButtonOptionTest, Unmarshalling_00001, Function | SmallTest | Level1)
95 {
96     bool unmarshalling = true;
97     Parcel parcel;
98     std::shared_ptr<NotificationButtonOption> result =
99         std::make_shared<NotificationButtonOption>();
100 
101     if (nullptr != result) {
102         if (nullptr == result->Unmarshalling(parcel)) {
103             unmarshalling = false;
104         }
105     }
106     EXPECT_EQ(unmarshalling, true);
107 }
108 
109 /**
110  * @tc.name: ToJson_00001
111  * @tc.desc: Test ToJson.
112  * @tc.type: FUNC
113  * @tc.require: issueI5WBBH
114  */
115 HWTEST_F(NotificationButtonOptionTest, ToJson_00001, Function | SmallTest | Level1)
116 {
117     auto rrc = std::make_shared<NotificationButtonOption>();
118     nlohmann::json jsonObject;
119     jsonObject["buttonName"] = "testButtonName";
120     EXPECT_EQ(jsonObject.is_object(), true);
121     EXPECT_EQ(rrc->ToJson(jsonObject), true);
122 }
123 
124 /**
125  * @tc.name: FromJson_00002
126  * @tc.desc: Test FromJson.
127  * @tc.type: FUNC
128  * @tc.require: issueI5WBBH
129  */
130 HWTEST_F(NotificationButtonOptionTest, FromJson_00002, Function | SmallTest | Level1)
131 {
132     auto rrc = std::make_shared<NotificationButtonOption>();
133     nlohmann::json jsonObject;
134     jsonObject["buttonName"] = "testButtonName";
135     EXPECT_EQ(jsonObject.is_object(), true);
136     EXPECT_NE(rrc->FromJson(jsonObject), nullptr);
137 }
138 }
139 }
140