• 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 #include <gtest/gtest.h>
17 
18 #include "cm_param.h"
19 #include "cm_type.h"
20 
21 using namespace testing::ext;
22 namespace {
23 class CmParamTest : public testing::Test {
24 public:
25     static void SetUpTestCase(void);
26 
27     static void TearDownTestCase(void);
28 
29     void SetUp();
30 
31     void TearDown();
32 };
33 
SetUpTestCase(void)34 void CmParamTest::SetUpTestCase(void)
35 {
36 }
37 
TearDownTestCase(void)38 void CmParamTest::TearDownTestCase(void)
39 {
40 }
41 
SetUp()42 void CmParamTest::SetUp()
43 {
44 }
45 
TearDown()46 void CmParamTest::TearDown()
47 {
48 }
49 
50 /**
51 * @tc.name: CmParamTest001
52 * @tc.desc: test CmInitParamSet nullptr
53 * @tc.type: FUNC
54 * @tc.require: AR000H0MIA /SR000H09NA
55 */
56 HWTEST_F(CmParamTest, CmParamTest001, TestSize.Level0)
57 {
58     int32_t ret = CmInitParamSet(nullptr);
59     EXPECT_EQ(ret, CMR_ERROR_INVALID_ARGUMENT);
60 }
61 
62 /**
63 * @tc.name: CmParamTest002
64 * @tc.desc: test CmAddParams paramSet is nullptr
65 * @tc.type: FUNC
66 * @tc.require: AR000H0MIA /SR000H09NA
67 */
68 HWTEST_F(CmParamTest, CmParamTest002, TestSize.Level0)
69 {
70     struct CmParam param[] = {
71         { .tag = CM_TAG_PARAM0_BOOL, .boolParam = false },
72     };
73     int32_t ret = CmAddParams(nullptr, param, sizeof(param) / sizeof(struct CmParam));
74     EXPECT_EQ(ret, CMR_ERROR_INVALID_ARGUMENT);
75 }
76 
77 /**
78 * @tc.name: CmParamTest003
79 * @tc.desc: test CmAddParams param is nullptr
80 * @tc.type: FUNC
81 * @tc.require: AR000H0MIA /SR000H09NA
82 */
83 HWTEST_F(CmParamTest, CmParamTest003, TestSize.Level0)
84 {
85     struct CmParamSet *paramSet = nullptr;
86     int32_t ret = CmInitParamSet(&paramSet);
87     EXPECT_EQ(ret, CM_SUCCESS);
88 
89     ret = CmAddParams(paramSet, nullptr, 0);
90     EXPECT_EQ(ret, CMR_ERROR_INVALID_ARGUMENT);
91 
92     CmFreeParamSet(&paramSet);
93 }
94 
95 /**
96 * @tc.name: CmParamTest004
97 * @tc.desc: test CmAddParams paramSet size is invalid
98 * @tc.type: FUNC
99 * @tc.require: AR000H0MIA /SR000H09NA
100 */
101 HWTEST_F(CmParamTest, CmParamTest004, TestSize.Level0)
102 {
103     struct CmParamSet paramSet = { CM_PARAM_SET_MAX_SIZE + 1, 0 };
104     struct CmParam param[] = {
105         { .tag = CM_TAG_PARAM0_BOOL, .boolParam = false },
106     };
107     int32_t ret = CmAddParams(&paramSet, param, sizeof(param) / sizeof(struct CmParam));
108     EXPECT_EQ(ret, CMR_ERROR_INVALID_ARGUMENT);
109 }
110 
111 /**
112 * @tc.name: CmParamTest005
113 * @tc.desc: test CmAddParams param cnt is invalid
114 * @tc.type: FUNC
115 * @tc.require: AR000H0MIA /SR000H09NA
116 */
117 HWTEST_F(CmParamTest, CmParamTest005, TestSize.Level0)
118 {
119     struct CmParamSet *paramSet = nullptr;
120     int32_t ret = CmInitParamSet(&paramSet);
121     EXPECT_EQ(ret, CM_SUCCESS);
122 
123     struct CmParam param[] = {
124         { .tag = CM_TAG_PARAM0_BOOL, .boolParam = false },
125     };
126     ret = CmAddParams(paramSet, param, CM_DEFAULT_PARAM_CNT + 1);
127     EXPECT_EQ(ret, CMR_ERROR_INVALID_ARGUMENT);
128 
129     CmFreeParamSet(&paramSet);
130 }
131 
132 /**
133 * @tc.name: CmParamTest006
134 * @tc.desc: test CmAddParams paramSet cnt is invalid
135 * @tc.type: FUNC
136 * @tc.require: AR000H0MIA /SR000H09NA
137 */
138 HWTEST_F(CmParamTest, CmParamTest006, TestSize.Level0)
139 {
140     struct CmParamSet *paramSet = nullptr;
141     int32_t ret = CmInitParamSet(&paramSet);
142     EXPECT_EQ(ret, CM_SUCCESS);
143     paramSet->paramsCnt = CM_DEFAULT_PARAM_CNT;
144 
145     struct CmParam param[] = {
146         { .tag = CM_TAG_PARAM0_BOOL, .boolParam = false },
147     };
148     ret = CmAddParams(paramSet, param, sizeof(param) / sizeof(struct CmParam));
149     EXPECT_EQ(ret, CMR_ERROR_INVALID_ARGUMENT);
150 
151     CmFreeParamSet(&paramSet);
152 }
153 
154 /**
155 * @tc.name: CmParamTest007
156 * @tc.desc: test CmAddParams param tag blob.data is invalid
157 * @tc.type: FUNC
158 * @tc.require: AR000H0MIA /SR000H09NA
159 */
160 HWTEST_F(CmParamTest, CmParamTest007, TestSize.Level0)
161 {
162     struct CmParamSet *paramSet = nullptr;
163     int32_t ret = CmInitParamSet(&paramSet);
164     EXPECT_EQ(ret, CM_SUCCESS);
165 
166     struct CmBlob tempBlob = { 0, nullptr };
167     struct CmParam param[] = {
168         { .tag = CM_TAG_PARAM0_BUFFER, .blob = tempBlob },
169     };
170     ret = CmAddParams(paramSet, param, sizeof(param) / sizeof(struct CmParam));
171     EXPECT_EQ(ret, CMR_ERROR_INVALID_ARGUMENT);
172 
173     CmFreeParamSet(&paramSet);
174 }
175 
176 /**
177 * @tc.name: CmParamTest008
178 * @tc.desc: test CmAddParams param tag blob.size is invalid
179 * @tc.type: FUNC
180 * @tc.require: AR000H0MIA /SR000H09NA
181 */
182 HWTEST_F(CmParamTest, CmParamTest008, TestSize.Level0)
183 {
184     struct CmParamSet *paramSet = nullptr;
185     int32_t ret = CmInitParamSet(&paramSet);
186     EXPECT_EQ(ret, CM_SUCCESS);
187 
188     uint8_t tempBuf[] = "this is for test";
189     struct CmBlob tempBlob = { UINT32_MAX, tempBuf };
190     struct CmParam param[] = {
191         { .tag = CM_TAG_PARAM0_BUFFER, .blob = tempBlob },
192     };
193     ret = CmAddParams(paramSet, param, sizeof(param) / sizeof(struct CmParam));
194     EXPECT_EQ(ret, CMR_ERROR_INVALID_ARGUMENT);
195 
196     CmFreeParamSet(&paramSet);
197 }
198 
199 /**
200 * @tc.name: CmParamTest009
201 * @tc.desc: test CmGetParam paramSet is nullptr
202 * @tc.type: FUNC
203 * @tc.require: AR000H0MIA /SR000H09NA
204 */
205 HWTEST_F(CmParamTest, CmParamTest009, TestSize.Level0)
206 {
207     struct CmParam *param = nullptr;
208     int32_t ret = CmGetParam(nullptr, CM_TAG_PARAM0_BUFFER, &param);
209     EXPECT_EQ(ret, CMR_ERROR_INVALID_ARGUMENT);
210 }
211 
212 /**
213 * @tc.name: CmParamTest010
214 * @tc.desc: test CmGetParam out param is nullptr
215 * @tc.type: FUNC
216 * @tc.require: AR000H0MIA /SR000H09NA
217 */
218 HWTEST_F(CmParamTest, CmParamTest010, TestSize.Level0)
219 {
220     struct CmParamSet *paramSet = nullptr;
221     int32_t ret = CmInitParamSet(&paramSet);
222     EXPECT_EQ(ret, CM_SUCCESS);
223 
224     ret = CmGetParam(paramSet, CM_TAG_PARAM0_BUFFER, nullptr);
225     EXPECT_EQ(ret, CMR_ERROR_INVALID_ARGUMENT);
226 
227     CmFreeParamSet(&paramSet);
228 }
229 
230 /**
231 * @tc.name: CmParamTest011
232 * @tc.desc: test CmGetParam paramSet size is invalid
233 * @tc.type: FUNC
234 * @tc.require: AR000H0MIA /SR000H09NA
235 */
236 HWTEST_F(CmParamTest, CmParamTest011, TestSize.Level0)
237 {
238     struct CmParamSet paramSet = {CM_PARAM_SET_MAX_SIZE + 1, 1 };
239     struct CmParam *param = nullptr;
240     int32_t ret = CmGetParam(&paramSet, CM_TAG_PARAM0_BUFFER, &param);
241     EXPECT_EQ(ret, CMR_ERROR_INVALID_ARGUMENT);
242 }
243 
244 /**
245 * @tc.name: CmParamTest012
246 * @tc.desc: test CmGetParam paramSet size is invalid (smaller than struct size)
247 * @tc.type: FUNC
248 * @tc.require: AR000H0MIA /SR000H09NA
249 */
250 HWTEST_F(CmParamTest, CmParamTest012, TestSize.Level0)
251 {
252     struct CmParamSet paramSet = { sizeof(struct CmParamSet) - 1, 1 };
253     struct CmParam *param = nullptr;
254     int32_t ret = CmGetParam(&paramSet, CM_TAG_PARAM0_BUFFER, &param);
255     EXPECT_EQ(ret, CMR_ERROR_INVALID_ARGUMENT);
256 }
257 
258 /**
259 * @tc.name: CmParamTest013
260 * @tc.desc: test CmGetParam paramSet cnt is invalid
261 * @tc.type: FUNC
262 * @tc.require: AR000H0MIA /SR000H09NA
263 */
264 HWTEST_F(CmParamTest, CmParamTest013, TestSize.Level0)
265 {
266     struct CmParamSet paramSet = { sizeof(struct CmParamSet), 1 };
267     struct CmParam *param = nullptr;
268     int32_t ret = CmGetParam(&paramSet, CM_TAG_PARAM0_BUFFER, &param);
269     EXPECT_EQ(ret, CMR_ERROR_INVALID_ARGUMENT);
270 }
271 
ConstrutParamSet(struct CmParamSet ** paramSet)272 static void ConstrutParamSet(struct CmParamSet **paramSet)
273 {
274     int32_t ret = CmInitParamSet(paramSet);
275     EXPECT_EQ(ret, CM_SUCCESS);
276 
277     struct CmParam param[] = {
278         { .tag = CM_TAG_PARAM0_BOOL, .boolParam = false },
279     };
280     ret = CmAddParams(*paramSet, param, sizeof(param) / sizeof(struct CmParam));
281     EXPECT_EQ(ret, CM_SUCCESS);
282 
283     ret = CmBuildParamSet(paramSet);
284     EXPECT_EQ(ret, CM_SUCCESS);
285 }
286 
287 /**
288 * @tc.name: CmParamTest014
289 * @tc.desc: test CmGetParam normal testcase
290 * @tc.type: FUNC
291 * @tc.require: AR000H0MIA /SR000H09NA
292 */
293 HWTEST_F(CmParamTest, CmParamTest014, TestSize.Level0)
294 {
295     struct CmParamSet *paramSet = nullptr;
296     ConstrutParamSet(&paramSet);
297 
298     struct CmParam *param = nullptr;
299     int32_t ret = CmGetParam(paramSet, CM_TAG_PARAM0_BOOL, &param);
300     EXPECT_EQ(ret, CM_SUCCESS);
301 
302     CmFreeParamSet(&paramSet);
303 }
304 
305 /**
306 * @tc.name: CmParamTest015
307 * @tc.desc: test CmGetParam param not exist
308 * @tc.type: FUNC
309 * @tc.require: AR000H0MIA /SR000H09NA
310 */
311 HWTEST_F(CmParamTest, CmParamTest015, TestSize.Level0)
312 {
313     struct CmParamSet *paramSet = nullptr;
314     ConstrutParamSet(&paramSet);
315 
316     struct CmParam *param = nullptr;
317     int32_t ret = CmGetParam(paramSet, CM_TAG_PARAM0_BUFFER, &param);
318     EXPECT_EQ(ret, CMR_ERROR_PARAM_NOT_EXIST);
319 
320     CmFreeParamSet(&paramSet);
321 }
322 
323 /**
324 * @tc.name: CmParamTest016
325 * @tc.desc: test CmFreeParamSet paramSet is nullptr
326 * @tc.type: FUNC
327 * @tc.require: AR000H0MIA /SR000H09NA
328 */
329 HWTEST_F(CmParamTest, CmParamTest016, TestSize.Level0)
330 {
331     CmFreeParamSet(nullptr);
332 }
333 
334 /**
335 * @tc.name: CmParamTest017
336 * @tc.desc: test CmBuildParamSet paramSet is nullptr
337 * @tc.type: FUNC
338 * @tc.require: AR000H0MIA /SR000H09NA
339 */
340 HWTEST_F(CmParamTest, CmParamTest017, TestSize.Level0)
341 {
342     int32_t ret = CmBuildParamSet(nullptr);
343     EXPECT_EQ(ret, CMR_ERROR_NULL_POINTER);
344 }
345 
346 /**
347 * @tc.name: CmParamTest018
348 * @tc.desc: test CmBuildParamSet *paramSet is nullptr
349 * @tc.type: FUNC
350 * @tc.require: AR000H0MIA /SR000H09NA
351 */
352 HWTEST_F(CmParamTest, CmParamTest018, TestSize.Level0)
353 {
354     struct CmParamSet *paramSet = nullptr;
355     int32_t ret = CmBuildParamSet(&paramSet);
356     EXPECT_EQ(ret, CMR_ERROR_NULL_POINTER);
357 }
358 
359 /**
360 * @tc.name: CmParamTest019
361 * @tc.desc: test CmBuildParamSet paramSet size is invalid
362 * @tc.type: FUNC
363 * @tc.require: AR000H0MIA /SR000H09NA
364 */
365 HWTEST_F(CmParamTest, CmParamTest019, TestSize.Level0)
366 {
367     struct CmParamSet *paramSet = nullptr;
368     int32_t ret = CmInitParamSet(&paramSet);
369     EXPECT_EQ(ret, CM_SUCCESS);
370     if (ret != CM_SUCCESS) {
371         return;
372     }
373     paramSet->paramSetSize = sizeof(struct CmParamSet) - 1;
374 
375     ret = CmBuildParamSet(&paramSet);
376     EXPECT_EQ(ret, CMR_ERROR_INVALID_ARGUMENT);
377 
378     CmFreeParamSet(&paramSet);
379 }
380 
381 /**
382 * @tc.name: CmParamTest020
383 * @tc.desc: test CmBuildParamSet param tag blob size is invalid
384 * @tc.type: FUNC
385 * @tc.require: AR000H0MIA /SR000H09NA
386 */
387 HWTEST_F(CmParamTest, CmParamTest020, TestSize.Level0)
388 {
389     struct CmParamSet *paramSet = nullptr;
390     int32_t ret = CmInitParamSet(&paramSet);
391     EXPECT_EQ(ret, CM_SUCCESS);
392     if (ret != CM_SUCCESS) {
393         return;
394     }
395 
396     uint8_t tempBuf[] = "this is for test020";
397     paramSet->paramsCnt = 1;
398     paramSet->paramSetSize += sizeof(struct CmParam);
399     paramSet->params[0].tag = CM_TAG_PARAM1_BUFFER;
400     paramSet->params[0].blob.size = UINT32_MAX;
401     paramSet->params[0].blob.data = tempBuf;
402 
403     ret = CmBuildParamSet(&paramSet);
404     EXPECT_EQ(ret, CMR_ERROR_INVALID_ARGUMENT);
405 
406     CmFreeParamSet(&paramSet);
407 }
408 
409 /**
410 * @tc.name: CmParamTest021
411 * @tc.desc: test CmBuildParamSet param tag blob data is invalid
412 * @tc.type: FUNC
413 * @tc.require: AR000H0MIA /SR000H09NA
414 */
415 HWTEST_F(CmParamTest, CmParamTest021, TestSize.Level0)
416 {
417     struct CmParamSet *paramSet = nullptr;
418     int32_t ret = CmInitParamSet(&paramSet);
419     EXPECT_EQ(ret, CM_SUCCESS);
420     if (ret != CM_SUCCESS) {
421         return;
422     }
423 
424     uint8_t tempBuf[] = "this is for test021";
425     paramSet->paramsCnt = 1;
426     paramSet->paramSetSize += sizeof(struct CmParam) + sizeof(tempBuf);
427     paramSet->params[0].tag = CM_TAG_PARAM0_BUFFER;
428     paramSet->params[0].blob.size = sizeof(tempBuf);
429     paramSet->params[0].blob.data = nullptr;
430 
431     ret = CmBuildParamSet(&paramSet);
432     EXPECT_EQ(ret, CMR_ERROR_INVALID_OPERATION);
433 
434     CmFreeParamSet(&paramSet);
435 }
436 
437 /**
438 * @tc.name: CmParamTest022
439 * @tc.desc: test CmBuildParamSet paramSet size is invalid
440 * @tc.type: FUNC
441 * @tc.require: AR000H0MIA /SR000H09NA
442 */
443 HWTEST_F(CmParamTest, CmParamTest022, TestSize.Level0)
444 {
445     struct CmParamSet *paramSet = nullptr;
446     int32_t ret = CmInitParamSet(&paramSet);
447     EXPECT_EQ(ret, CM_SUCCESS);
448     if (ret != CM_SUCCESS) {
449         return;
450     }
451 
452     uint8_t tempBuf[] = "this is for test022";
453     paramSet->paramsCnt = 1;
454     paramSet->paramSetSize += sizeof(struct CmParam) + sizeof(tempBuf) + 1; /* invalid size */
455     paramSet->params[0].tag = CM_TAG_PARAM0_BUFFER;
456     paramSet->params[0].blob.size = sizeof(tempBuf);
457     paramSet->params[0].blob.data = tempBuf;
458 
459     ret = CmBuildParamSet(&paramSet);
460     EXPECT_EQ(ret, CMR_ERROR_INVALID_ARGUMENT);
461 
462     CmFreeParamSet(&paramSet);
463 }
464 
465 /**
466 * @tc.name: CmParamTest023
467 * @tc.desc: test CmGetParamSet paramSet is nullptr
468 * @tc.type: FUNC
469 * @tc.require: AR000H0MIA /SR000H09NA
470 */
471 HWTEST_F(CmParamTest, CmParamTest023, TestSize.Level0)
472 {
473     struct CmParamSet *outParamSet = nullptr;
474     int32_t ret = CmGetParamSet(nullptr, 0, &outParamSet);
475     EXPECT_EQ(ret, CMR_ERROR_NULL_POINTER);
476 }
477 
478 /**
479 * @tc.name: CmParamTest024
480 * @tc.desc: test CmGetParamSet normal testcase
481 * @tc.type: FUNC
482 * @tc.require: AR000H0MIA /SR000H09NA
483 */
484 HWTEST_F(CmParamTest, CmParamTest024, TestSize.Level0)
485 {
486     struct CmParamSet *paramSet = nullptr;
487     ConstrutParamSet(&paramSet);
488     if (paramSet == nullptr) {
489         return;
490     }
491 
492     struct CmParamSet *outParamSet = nullptr;
493     int32_t ret = CmGetParamSet(paramSet, paramSet->paramSetSize, &outParamSet);
494     EXPECT_EQ(ret, CM_SUCCESS);
495 
496     CmFreeParamSet(&paramSet);
497     CmFreeParamSet(&outParamSet);
498 }
499 
500 /**
501 * @tc.name: CmParamTest025
502 * @tc.desc: test CmGetParamSet param tag blob size is invalid
503 * @tc.type: FUNC
504 * @tc.require: AR000H0MIA /SR000H09NA
505 */
506 HWTEST_F(CmParamTest, CmParamTest025, TestSize.Level0)
507 {
508     struct CmParamSet *paramSet = nullptr;
509     int32_t ret = CmInitParamSet(&paramSet);
510     EXPECT_EQ(ret, CM_SUCCESS);
511     if (ret != CM_SUCCESS) {
512         return;
513     }
514 
515     uint8_t tempBuf[] = "this is for test025";
516     paramSet->paramsCnt = 1;
517     paramSet->paramSetSize += sizeof(struct CmParam);
518     paramSet->params[0].tag = CM_TAG_PARAM1_BUFFER;
519     paramSet->params[0].blob.size = UINT32_MAX;
520     paramSet->params[0].blob.data = tempBuf;
521 
522     struct CmParamSet *outParamSet = nullptr;
523     ret = CmGetParamSet(paramSet, paramSet->paramSetSize, &outParamSet);
524     EXPECT_EQ(ret, CMR_ERROR_INVALID_ARGUMENT);
525 
526     CmFreeParamSet(&paramSet);
527     CmFreeParamSet(&outParamSet);
528 }
529 
530 /**
531 * @tc.name: CmParamTest026
532 * @tc.desc: test CmGetParamSet paramSet size is invalid
533 * @tc.type: FUNC
534 * @tc.require: AR000H0MIA /SR000H09NA
535 */
536 HWTEST_F(CmParamTest, CmParamTest026, TestSize.Level0)
537 {
538     struct CmParamSet *paramSet = nullptr;
539     int32_t ret = CmInitParamSet(&paramSet);
540     EXPECT_EQ(ret, CM_SUCCESS);
541     if (ret != CM_SUCCESS) {
542         return;
543     }
544 
545     uint8_t tempBuf[] = "this is for test026";
546     paramSet->paramsCnt = 1;
547     paramSet->paramSetSize += sizeof(struct CmParam) + sizeof(tempBuf) + 1; /* invalid size */
548     paramSet->params[0].tag = CM_TAG_PARAM0_BUFFER;
549     paramSet->params[0].blob.size = sizeof(tempBuf);
550     paramSet->params[0].blob.data = tempBuf;
551 
552     struct CmParamSet *outParamSet = nullptr;
553     ret = CmGetParamSet(paramSet, paramSet->paramSetSize, &outParamSet);
554     EXPECT_EQ(ret, CMR_ERROR_INVALID_ARGUMENT);
555 
556     CmFreeParamSet(&paramSet);
557     CmFreeParamSet(&outParamSet);
558 }
559 
560 /**
561 * @tc.name: CmParamTest027
562 * @tc.desc: test CmGetParamSet normal testcase tag include blob
563 * @tc.type: FUNC
564 * @tc.require: AR000H0MIA /SR000H09NA
565 */
566 HWTEST_F(CmParamTest, CmParamTest027, TestSize.Level0)
567 {
568     struct CmParamSet *paramSet = nullptr;
569     int32_t ret = CmInitParamSet(&paramSet);
570     EXPECT_EQ(ret, CM_SUCCESS);
571     if (ret != CM_SUCCESS) {
572         return;
573     }
574 
575     uint8_t tempBuf[] = "this is for test027";
576     paramSet->paramsCnt = 1;
577     paramSet->paramSetSize += sizeof(struct CmParam) + sizeof(tempBuf);
578     paramSet->params[0].tag = CM_TAG_PARAM0_BUFFER;
579     paramSet->params[0].blob.size = sizeof(tempBuf);
580     paramSet->params[0].blob.data = tempBuf;
581 
582     struct CmParamSet *outParamSet = nullptr;
583     ret = CmGetParamSet(paramSet, paramSet->paramSetSize, &outParamSet);
584     EXPECT_EQ(ret, CM_SUCCESS);
585 
586     CmFreeParamSet(&paramSet);
587     CmFreeParamSet(&outParamSet);
588 }
589 } // end of namespace
590