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