1 /*
2  * Copyright (c) 2022 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 
18 #define private public
19 #define protected public
20 #include "notification_media_content.h"
21 #undef private
22 #undef protected
23 
24 using namespace testing::ext;
25 namespace OHOS {
26 namespace Notification {
27 class NotificationMediaContentTest : public testing::Test {
28 public:
SetUpTestCase()29     static void SetUpTestCase() {}
TearDownTestCase()30     static void TearDownTestCase() {}
SetUp()31     void SetUp() {}
TearDown()32     void TearDown() {}
33 };
34 
35 /**
36  * @tc.name: SetAVToken_00001
37  * @tc.desc: Test SetAVToken parameters.
38  * @tc.type: FUNC
39  * @tc.require: issueI5WBBH
40  */
41 HWTEST_F(NotificationMediaContentTest, SetAVToken_00001, Function | SmallTest | Level1)
42 {
43     std::shared_ptr<AVToken> avToken = nullptr;
44     auto rrc = std::make_shared<NotificationMediaContent>();
45     rrc->SetAVToken(avToken);
46     EXPECT_EQ(rrc->GetAVToken(), avToken);
47 }
48 
49 /**
50  * @tc.name: SetShownActions_00001
51  * @tc.desc: Test SetShownActions parameters.
52  * @tc.type: FUNC
53  * @tc.require: issueI5WBBH
54  */
55 HWTEST_F(NotificationMediaContentTest, SetShownActions_00001, Function | SmallTest | Level1)
56 {
57     std::vector<uint32_t> actions;
58     auto rrc = std::make_shared<NotificationMediaContent>();
59     rrc->SetShownActions(actions);
60     EXPECT_EQ(rrc->GetShownActions(), actions);
61 }
62 
63 /**
64  * @tc.name: Dump_00001
65  * @tc.desc: Test Dump parameters.
66  * @tc.type: FUNC
67  * @tc.require: issueI5WBBH
68  */
69 HWTEST_F(NotificationMediaContentTest, Dump_00001, Function | SmallTest | Level1)
70 {
71     auto rrc = std::make_shared<NotificationMediaContent>();
72     std::string ret = "NotificationMediaContent{ title = , text = , "
73     "additionalText = , lockScreenPicture = null, avToken = null, sequenceNumbers =  }";
74 
75     EXPECT_EQ(rrc->Dump(), ret);
76 }
77 
78 /**
79  * @tc.name: ToJson_00001
80  * @tc.desc: Test ToJson parameters.
81  * @tc.type: FUNC
82  * @tc.require: issueI5WBBH
83  */
84 HWTEST_F(NotificationMediaContentTest, ToJson_00001, Function | SmallTest | Level1)
85 {
86     nlohmann::json jsonObject;
87     auto rrc = std::make_shared<NotificationMediaContent>();
88     rrc->FromJson(jsonObject);
89     EXPECT_EQ(rrc->ToJson(jsonObject), true);
90 }
91 
92 /**
93  * @tc.name: Marshalling_00001
94  * @tc.desc: Test Marshalling parameters.
95  * @tc.type: FUNC
96  * @tc.require: issueI5WBBH
97  */
98 HWTEST_F(NotificationMediaContentTest, Marshalling_00001, Function | SmallTest | Level1)
99 {
100     Parcel parcel;
101     auto rrc = std::make_shared<NotificationMediaContent>();
102     EXPECT_EQ(rrc->Marshalling(parcel), true);
103 }
104 
105 /**
106  * @tc.name: Unmarshalling_00001
107  * @tc.desc: Test Unmarshalling parameters.
108  * @tc.type: FUNC
109  * @tc.require: issueI5WBBH
110  */
111 HWTEST_F(NotificationMediaContentTest, Unmarshalling_001, Function | SmallTest | Level1)
112 {
113     bool unmarshalling = true;
114     Parcel parcel;
115     std::shared_ptr<NotificationMediaContent> result =
116     std::make_shared<NotificationMediaContent>();
117 
118     if (nullptr != result) {
119         if (nullptr == result->Unmarshalling(parcel)) {
120             unmarshalling = false;
121         }
122     }
123     EXPECT_EQ(unmarshalling, false);
124 }
125 
126 /**
127  * @tc.name: Unmarshalling_00002
128  * @tc.desc: Test Unmarshalling parameters.
129  * @tc.type: FUNC
130  * @tc.require: issueI5WBBH
131  */
132 HWTEST_F(NotificationMediaContentTest, Unmarshalling_00002, Function | SmallTest | Level1)
133 {
134     Parcel parcel;
135     auto mediaContent = std::make_shared<NotificationMediaContent>();
136     std::vector<uint32_t> actions = {1, 2};
137     mediaContent->SetShownActions(actions);
138     mediaContent->Marshalling(parcel);
139     EXPECT_NE(mediaContent->Unmarshalling(parcel), nullptr);
140 }
141 
142 /**
143  * @tc.name: ReadFromParcel_00001
144  * @tc.desc: Test ReadFromParcel parameters.
145  * @tc.type: FUNC
146  * @tc.require: issueI5WBBH
147  */
148 HWTEST_F(NotificationMediaContentTest, ReadFromParcel_00001, Function | SmallTest | Level1)
149 {
150     Parcel parcel;
151     auto rrc = std::make_shared<NotificationMediaContent>();
152     EXPECT_EQ(rrc->ReadFromParcel(parcel), false);
153 }
154 
155 /**
156  * @tc.name: ToJson_00002
157  * @tc.desc: Test ToJson parameters.
158  * @tc.type: FUNC
159  * @tc.require: issueI5WBBH
160  */
161 HWTEST_F(NotificationMediaContentTest, ToJson_00002, Function | SmallTest | Level1)
162 {
163     nlohmann::json jsonObject = nlohmann::json{
164         {"teset", "test"}};
165     auto rrc = std::make_shared<NotificationMediaContent>();
166     auto res = rrc->FromJson(jsonObject);
167     EXPECT_NE(res, nullptr);
168 }
169 
170 /**
171  * @tc.name: FromJson_00001
172  * @tc.desc: Test ToJson parameters.
173  * @tc.type: FUNC
174  * @tc.require: issueI5WBBH
175  */
176 HWTEST_F(NotificationMediaContentTest, FromJson_00001, Function | SmallTest | Level1)
177 {
178     nlohmann::json jsonObject = nlohmann::json{
179         {"sequenceNumbers", {1, 2}}};
180     auto mediaContent = std::make_shared<NotificationMediaContent>();
181     auto res = mediaContent->FromJson(jsonObject);
182     EXPECT_NE(res, nullptr);
183     EXPECT_EQ(res->GetShownActions().size(), 2);
184 }
185 }
186 }
187