1 /*
2  * Copyright (c) 2022-2024 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 "video_param_test.h"
17 
18 using json = nlohmann::json;
19 
20 using namespace testing::ext;
21 
22 namespace OHOS {
23 namespace DistributedHardware {
24 constexpr static uint32_t VIDEO_DATA_NUM = 480;
SetUpTestCase(void)25 void VideoParamTest::SetUpTestCase(void) {}
26 
TearDownTestCase(void)27 void VideoParamTest::TearDownTestCase(void) {}
28 
SetUp()29 void VideoParamTest::SetUp()
30 {
31     videoParam_ = std::make_shared<VideoParam>();
32 }
33 
TearDown()34 void VideoParamTest::TearDown() {}
35 
36 /**
37  * @tc.name: GetScreenWidth_001
38  * @tc.desc: Verify the GetScreenWidth function.
39  * @tc.type: FUNC
40  * @tc.require: Issue Number
41  */
42 HWTEST_F(VideoParamTest, GetScreenWidth_001, TestSize.Level1)
43 {
44     uint32_t screenWidth = 1;
45     videoParam_->SetScreenWidth(screenWidth);
46     uint32_t actual = videoParam_->GetScreenWidth();
47     EXPECT_EQ(screenWidth, actual);
48 }
49 
50 /**
51  * @tc.name: GetScreenHeight_001
52  * @tc.desc: Verify the GetScreenHeight function.
53  * @tc.type: FUNC
54  * @tc.require: Issue Number
55  */
56 HWTEST_F(VideoParamTest, GetScreenHeight_001, TestSize.Level1)
57 {
58     uint32_t screenHeight = 1;
59     videoParam_->SetScreenHeight(screenHeight);
60     uint32_t actual = videoParam_->GetScreenHeight();
61     EXPECT_EQ(screenHeight, actual);
62 }
63 
64 /**
65  * @tc.name: GetVideoWidth_001
66  * @tc.desc: Verify the GetVideoWidth function.
67  * @tc.type: FUNC
68  * @tc.require: Issue Number
69  */
70 HWTEST_F(VideoParamTest, GetVideoWidth_001, TestSize.Level1)
71 {
72     uint32_t videoWidth = 1;
73     videoParam_->SetVideoWidth(videoWidth);
74     uint32_t actual = videoParam_->GetVideoWidth();
75     EXPECT_EQ(videoWidth, actual);
76 }
77 
78 /**
79  * @tc.name: SetPartialRefreshFlag_001
80  * @tc.desc: Verify the SetPartialRefreshFlag function.
81  * @tc.type: FUNC
82  * @tc.require: Issue Number
83  */
84 HWTEST_F(VideoParamTest, SetPartialRefreshFlag_001, TestSize.Level1)
85 {
86     std::shared_ptr<VideoParam> videoParam = std::make_shared<VideoParam>();
87     videoParam->isPartialRefresh_ = false;
88     videoParam->SetPartialRefreshFlag(true);
89     EXPECT_TRUE(videoParam->isPartialRefresh_);
90 }
91 
92 /**
93  * @tc.name: GetVideoHeight_001
94  * @tc.desc: Verify the GetVideoHeight function.
95  * @tc.type: FUNC
96  * @tc.require: Issue Number
97  */
98 HWTEST_F(VideoParamTest, GetVideoHeight_001, TestSize.Level1)
99 {
100     uint32_t videoHeight = 1;
101     videoParam_->SetVideoHeight(videoHeight);
102     uint32_t actual = videoParam_->GetVideoHeight();
103     EXPECT_EQ(videoHeight, actual);
104 }
105 
106 /**
107  * @tc.name: GetFps_001
108  * @tc.desc: Verify the GetFps function.
109  * @tc.type: FUNC
110  * @tc.require: Issue Number
111  */
112 HWTEST_F(VideoParamTest, GetFps_001, TestSize.Level1)
113 {
114     double fps = 1.0;
115     videoParam_->SetFps(fps);
116     double actual = videoParam_->GetFps();
117     EXPECT_EQ(fps, actual);
118 }
119 
120 /**
121  * @tc.name: GetCodecType_001
122  * @tc.desc: Verify the GetCodecType function.
123  * @tc.type: FUNC
124  * @tc.require: Issue Number
125  */
126 HWTEST_F(VideoParamTest, GetCodecType_001, TestSize.Level1)
127 {
128     uint8_t codecType = 1;
129     videoParam_->SetCodecType(codecType);
130     uint8_t actual = videoParam_->GetCodecType();
131     EXPECT_EQ(codecType, actual);
132 }
133 
134 /**
135  * @tc.name: GetVideoFormat_001
136  * @tc.desc: Verify the GetVideoFormat function.
137  * @tc.type: FUNC
138  * @tc.require: Issue Number
139  */
140 HWTEST_F(VideoParamTest, GetVideoFormat_001, TestSize.Level1)
141 {
142     uint8_t videoFormat = 1;
143     videoParam_->SetVideoFormat(videoFormat);
144     uint8_t actual = videoParam_->GetVideoFormat();
145     EXPECT_EQ(videoFormat, actual);
146 }
147 
148 /**
149  * @tc.name: to_json_001
150  * @tc.desc: Verify the to_json function.
151  * @tc.type: FUNC
152  * @tc.require: Issue Number
153  */
154 HWTEST_F(VideoParamTest, to_json_001, TestSize.Level1)
155 {
156     json j;
157     double fps = 30.0;
158     uint8_t videoFormat = DEFAULT_VIDEO_FORMAT;
159     uint8_t codecType = DEFAULT_CODECTYPE;
160 
161     VideoParam videoParam;
162     videoParam.SetScreenWidth(VIDEO_DATA_NUM);
163     videoParam.SetScreenHeight(VIDEO_DATA_NUM);
164     videoParam.SetVideoWidth(VIDEO_DATA_NUM);
165     videoParam.SetVideoHeight(VIDEO_DATA_NUM);
166     videoParam.SetFps(fps);
167     videoParam.SetVideoFormat(videoFormat);
168     videoParam.SetCodecType(codecType);
169     to_json(j, videoParam);
170 
171     uint32_t jsonVideoWidth = 0;
172     j.at(KEY_VIDEO_WIDTH).get_to(jsonVideoWidth);
173     EXPECT_EQ(VIDEO_DATA_NUM, jsonVideoWidth);
174 }
175 
176 /**
177  * @tc.name: from_json_001
178  * @tc.desc: Verify the from_json function.
179  * @tc.type: FUNC
180  * @tc.require: Issue Number
181  */
182 HWTEST_F(VideoParamTest, from_json_001, TestSize.Level1)
183 {
184     json j;
185     uint32_t screenWidth = 100;
186     uint32_t screenHeight = 100;
187     uint32_t videoWidth = 100;
188     uint32_t videoHeight = 100;
189     double fps = 30.0;
190     uint8_t codecType = DEFAULT_CODECTYPE;
191     uint8_t videoFormat = DEFAULT_VIDEO_FORMAT;
192 
193     VideoParam videoParam;
194     videoParam.SetScreenWidth(screenWidth);
195     videoParam.SetScreenHeight(screenHeight);
196     videoParam.SetVideoWidth(videoWidth);
197     videoParam.SetVideoHeight(videoHeight);
198     videoParam.SetFps(fps);
199     videoParam.SetCodecType(codecType);
200     videoParam.SetVideoFormat(videoFormat);
201     to_json(j, videoParam);
202     VideoParam jsonVideoParam;
203     from_json(j, jsonVideoParam);
204     EXPECT_EQ(videoWidth, jsonVideoParam.GetVideoWidth());
205 }
206 
207 /**
208  * @tc.name: from_json_002
209  * @tc.desc: Verify the from_json function.
210  * @tc.type: FUNC
211  * @tc.require: Issue Number
212  */
213 HWTEST_F(VideoParamTest, from_json_002, TestSize.Level1)
214 {
215     json j;
216     uint32_t screenWidth = 200;
217     uint32_t screenHeight = 200;
218     uint32_t videoWidth = 200;
219     uint32_t videoHeight = 200;
220     double fps = 30.0;
221     uint8_t codecType = DEFAULT_CODECTYPE;
222     uint8_t videoFormat = DEFAULT_VIDEO_FORMAT;
223     VideoParam jsonVideoParam;
224     jsonVideoParam.isPartialRefresh_ = true;
225     from_json(j, jsonVideoParam);
226     j[KEY_SCREEN_WIDTH] = screenWidth;
227     from_json(j, jsonVideoParam);
228     j[KEY_SCREEN_HEIGHT] = screenHeight;
229     from_json(j, jsonVideoParam);
230     j[KEY_VIDEO_WIDTH] = videoWidth;
231     from_json(j, jsonVideoParam);
232     j[KEY_VIDEO_HEIGHT] = videoHeight;
233     from_json(j, jsonVideoParam);
234     j[KEY_FPS] = fps;
235     from_json(j, jsonVideoParam);
236     j[KEY_CODECTYPE] = codecType;
237     from_json(j, jsonVideoParam);
238     j[KEY_COLOR_FORMAT] = videoFormat;
239     from_json(j, jsonVideoParam);
240     EXPECT_EQ(false, jsonVideoParam.isPartialRefresh_);
241 }
242 } // namespace DistributedHardware
243 } // namespace OHOS