1 /* 2 * Copyright (c) 2023-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 #include "codec_callback_if.h" 16 #include "codec_component_manager.h" 17 #include <gtest/gtest.h> 18 #include <osal_mem.h> 19 using namespace std; 20 using namespace testing::ext; 21 namespace { 22 class CodecHdiManagerTestAdditional : public testing::Test { 23 public: SetUpTestCase()24 static void SetUpTestCase() {} TearDownTestCase()25 static void TearDownTestCase() {} SetUp()26 void SetUp() { manager_ = GetCodecComponentManager(); } TearDown()27 void TearDown() 28 { 29 CodecComponentManagerRelease(); 30 manager_ = nullptr; 31 } 32 33 public: 34 struct CodecComponentManager *manager_ = nullptr; 35 }; 36 37 /** 38 * @tc.number SUB_Driver_Codec_CodecHdi_0600 39 * @tc.name testCodecGetComponentNum001 40 * @tc.desc Determines whether the function gets the param correctly 41 */ 42 HWTEST_F(CodecHdiManagerTestAdditional, testCodecGetComponentNum001, Function | MediumTest | Level1) 43 { 44 ASSERT_TRUE(manager_ != nullptr); 45 auto count = -1; 46 count = manager_->GetComponentNum(); 47 EXPECT_TRUE(count >= 0); 48 } 49 50 /** 51 * @tc.number SUB_Driver_Codec_CodecHdi_0700 52 * @tc.name testCodecGetComponentCapabilityList001 53 * @tc.desc Determine whether the function can obtain the correct value if there are existing values in the structure 54 */ 55 HWTEST_F(CodecHdiManagerTestAdditional, testCodecGetComponentCapabilityList001, Function | MediumTest | Level1) 56 { 57 ASSERT_TRUE(manager_ != nullptr); 58 auto count = manager_->GetComponentNum(); 59 CodecCompCapability *capList = (CodecCompCapability *)OsalMemAlloc(sizeof(CodecCompCapability) * count); 60 ASSERT_TRUE(capList != nullptr); 61 capList->role = MEDIA_ROLETYPE_INVALID; 62 auto err = manager_->GetComponentCapabilityList(capList, count); 63 EXPECT_EQ(err, HDF_SUCCESS); 64 } 65 66 /** 67 * @tc.number SUB_Driver_Codec_CodecHdi_0800 68 * @tc.name testCodecGetComponentCapabilityList002 69 * @tc.desc Determine whether the function can obtain the correct value if there are existing values in the structure 70 */ 71 HWTEST_F(CodecHdiManagerTestAdditional, testCodecGetComponentCapabilityList002, Function | MediumTest | Level1) 72 { 73 ASSERT_TRUE(manager_ != nullptr); 74 auto count = manager_->GetComponentNum(); 75 ASSERT_TRUE(count > 0); 76 CodecCompCapability *capList = (CodecCompCapability *)OsalMemAlloc(sizeof(CodecCompCapability) * count); 77 ASSERT_TRUE(capList != nullptr); 78 capList->role = MEDIA_ROLETYPE_IMAGE_JPEG; 79 auto err = manager_->GetComponentCapabilityList(capList, count); 80 EXPECT_EQ(err, HDF_SUCCESS); 81 } 82 83 /** 84 * @tc.number SUB_Driver_Codec_CodecHdi_0900 85 * @tc.name testCodecGetComponentCapabilityList003 86 * @tc.desc Determine whether the function can obtain the correct value if there are existing values in the structure 87 */ 88 HWTEST_F(CodecHdiManagerTestAdditional, testCodecGetComponentCapabilityList003, Function | MediumTest | Level1) 89 { 90 ASSERT_TRUE(manager_ != nullptr); 91 auto count = manager_->GetComponentNum(); 92 CodecCompCapability *capList = (CodecCompCapability *)OsalMemAlloc(sizeof(CodecCompCapability) * count); 93 ASSERT_TRUE(capList != nullptr); 94 capList->type = INVALID_TYPE; 95 auto err = manager_->GetComponentCapabilityList(capList, count); 96 EXPECT_EQ(err, HDF_SUCCESS); 97 } 98 99 /** 100 * @tc.number SUB_Driver_Codec_CodecHdi_1000 101 * @tc.name testCodecGetComponentCapabilityList004 102 * @tc.desc Determine whether the function can obtain the correct value if there are existing values in the structure 103 */ 104 HWTEST_F(CodecHdiManagerTestAdditional, testCodecGetComponentCapabilityList004, Function | MediumTest | Level1) 105 { 106 ASSERT_TRUE(manager_ != nullptr); 107 auto count = manager_->GetComponentNum(); 108 CodecCompCapability *capList = (CodecCompCapability *)OsalMemAlloc(sizeof(CodecCompCapability) * count); 109 ASSERT_TRUE(capList != nullptr); 110 capList->maxInst = -1; 111 auto err = manager_->GetComponentCapabilityList(capList, count); 112 EXPECT_EQ(err, HDF_SUCCESS); 113 } 114 115 /** 116 * @tc.number SUB_Driver_Codec_CodecHdi_1100 117 * @tc.name testCodecGetComponentCapabilityList005 118 * @tc.desc Determine whether the function can obtain the correct value if there are existing values in the structure 119 */ 120 HWTEST_F(CodecHdiManagerTestAdditional, testCodecGetComponentCapabilityList005, Function | MediumTest | Level1) 121 { 122 ASSERT_TRUE(manager_ != nullptr); 123 auto count = manager_->GetComponentNum(); 124 CodecCompCapability *capList = (CodecCompCapability *)OsalMemAlloc(sizeof(CodecCompCapability) * count); 125 ASSERT_TRUE(capList != nullptr); 126 capList->capsMask = -1; 127 auto err = manager_->GetComponentCapabilityList(capList, count); 128 EXPECT_EQ(err, HDF_SUCCESS); 129 } 130 131 /** 132 * @tc.number SUB_Driver_Codec_CodecHdi_1200 133 * @tc.name testCodecGetComponentCapabilityList006 134 * @tc.desc When the number of codec components is negative, the validity of the function is judged 135 */ 136 HWTEST_F(CodecHdiManagerTestAdditional, testCodecGetComponentCapabilityList006, Function | MediumTest | Level2) 137 { 138 ASSERT_TRUE(manager_ != nullptr); 139 int count = -1; 140 CodecCompCapability *capList = 141 (CodecCompCapability *)OsalMemAlloc(sizeof(CodecCompCapability) * (manager_->GetComponentNum())); 142 ASSERT_TRUE(capList != nullptr); 143 auto err = manager_->GetComponentCapabilityList(capList, count); 144 EXPECT_NE(err, HDF_SUCCESS); 145 } 146 147 /** 148 * @tc.number SUB_Driver_Codec_CodecHdi_1300 149 * @tc.name testCodecCreateComponent001 150 * @tc.desc When the parameter passed by the function already has a value, determine whether it will have an effect 151 */ 152 HWTEST_F(CodecHdiManagerTestAdditional, testCodecCreateComponent001, Function | MediumTest | Level1) 153 { 154 ASSERT_TRUE(manager_ != nullptr); 155 std::string compName(""); 156 auto count = manager_->GetComponentNum(); 157 ASSERT_TRUE(count > 0); 158 CodecCompCapability *capList = (CodecCompCapability *)OsalMemAlloc(sizeof(CodecCompCapability) * count); 159 ASSERT_TRUE(capList != nullptr); 160 auto err = manager_->GetComponentCapabilityList(capList, count); 161 ASSERT_TRUE(err == HDF_SUCCESS); 162 compName = capList[0].compName; 163 OsalMemFree(capList); 164 capList = nullptr; 165 166 ASSERT_FALSE(compName.empty()); 167 struct CodecCallbackType *callback = CodecCallbackTypeGet(nullptr); 168 struct CodecComponentType *component = nullptr; 169 uint32_t componentId = -1; 170 ASSERT_TRUE(callback != nullptr); 171 172 int32_t ret = manager_->CreateComponent(&component, &componentId, compName.data(), (int64_t)this, callback); 173 EXPECT_EQ(ret, HDF_SUCCESS); 174 CodecCallbackTypeRelease(callback); 175 } 176 177 /** 178 * @tc.number SUB_Driver_Codec_CodecHdi_1400 179 * @tc.name testCodecCreateComponent002 180 * @tc.desc Open the OpenMax component based on a non-existent compName 181 */ 182 HWTEST_F(CodecHdiManagerTestAdditional, testCodecCreateComponent002, Function | MediumTest | Level2) 183 { 184 struct CodecCallbackType *callback = CodecCallbackTypeGet(nullptr); 185 ASSERT_TRUE(callback != nullptr); 186 ASSERT_TRUE(manager_ != nullptr); 187 std::string compName(" "); 188 struct CodecComponentType *component = nullptr; 189 uint32_t componentId = 0; 190 int32_t ret = manager_->CreateComponent(&component, &componentId, compName.data(), (int64_t)this, callback); 191 EXPECT_NE(ret, HDF_SUCCESS); 192 EXPECT_EQ(component, nullptr); 193 CodecCallbackTypeRelease(callback); 194 } 195 196 /** 197 * @tc.number SUB_Driver_Codec_CodecHdi_1500 198 * @tc.name testCodecCreateComponent003 199 * @tc.desc Open the OpenMax component based on a non-existent compName 200 */ 201 HWTEST_F(CodecHdiManagerTestAdditional, testCodecCreateComponent003, Function | MediumTest | Level2) 202 { 203 struct CodecCallbackType *callback = CodecCallbackTypeGet(nullptr); 204 ASSERT_TRUE(callback != nullptr); 205 ASSERT_TRUE(manager_ != nullptr); 206 std::string compName("//\a"); 207 struct CodecComponentType *component = nullptr; 208 uint32_t componentId = 0; 209 int32_t ret = manager_->CreateComponent(&component, &componentId, compName.data(), (int64_t)this, callback); 210 EXPECT_NE(ret, HDF_SUCCESS); 211 EXPECT_EQ(component, nullptr); 212 CodecCallbackTypeRelease(callback); 213 } 214 215 /** 216 * @tc.number SUB_Driver_Codec_CodecHdi_1600 217 * @tc.name testCodecCreateComponent004 218 * @tc.desc Open the OpenMax component based on a non-existent compName 219 */ 220 HWTEST_F(CodecHdiManagerTestAdditional, testCodecCreateComponent004, Function | MediumTest | Level2) 221 { 222 struct CodecCallbackType *callback = CodecCallbackTypeGet(nullptr); 223 ASSERT_TRUE(callback != nullptr); 224 ASSERT_TRUE(manager_ != nullptr); 225 std::string compName("a,,"); 226 struct CodecComponentType *component = nullptr; 227 uint32_t componentId = 0; 228 int32_t ret = manager_->CreateComponent(&component, &componentId, compName.data(), (int64_t)this, callback); 229 EXPECT_NE(ret, HDF_SUCCESS); 230 EXPECT_EQ(component, nullptr); 231 CodecCallbackTypeRelease(callback); 232 } 233 234 /** 235 * @tc.number SUB_Driver_Codec_CodecHdi_1700 236 * @tc.name testCodecCreateComponent005 237 * @tc.desc Open the OpenMax component based on a non-existent compName 238 */ 239 HWTEST_F(CodecHdiManagerTestAdditional, testCodecCreateComponent005, Function | MediumTest | Level2) 240 { 241 struct CodecCallbackType *callback = CodecCallbackTypeGet(nullptr); 242 ASSERT_TRUE(callback != nullptr); 243 ASSERT_TRUE(manager_ != nullptr); 244 std::string compName("12344"); 245 struct CodecComponentType *component = nullptr; 246 uint32_t componentId = 0; 247 int32_t ret = manager_->CreateComponent(&component, &componentId, compName.data(), (int64_t)this, callback); 248 EXPECT_NE(ret, HDF_SUCCESS); 249 EXPECT_EQ(component, nullptr); 250 CodecCallbackTypeRelease(callback); 251 } 252 253 /** 254 * @tc.number SUB_Driver_Codec_CodecHdi_1800 255 * @tc.name testCodecCreateComponent006 256 * @tc.desc Open the OpenMax component based on a non-existent compName 257 */ 258 HWTEST_F(CodecHdiManagerTestAdditional, testCodecCreateComponent006, Function | MediumTest | Level1) 259 { 260 struct CodecCallbackType *callback = CodecCallbackTypeGet(nullptr); 261 ASSERT_TRUE(callback != nullptr); 262 ASSERT_TRUE(manager_ != nullptr); 263 std::string compName("a@%"); 264 struct CodecComponentType *component = nullptr; 265 uint32_t componentId = 0; 266 int32_t ret = manager_->CreateComponent(&component, &componentId, compName.data(), (int64_t)this, callback); 267 EXPECT_NE(ret, HDF_SUCCESS); 268 EXPECT_EQ(component, nullptr); 269 CodecCallbackTypeRelease(callback); 270 } 271 272 /** 273 * @tc.number SUB_Driver_Codec_CodecHdi_1900 274 * @tc.name testCodecCreateComponent007 275 * @tc.desc Open the OpenMax component based on a non-existent compName 276 */ 277 HWTEST_F(CodecHdiManagerTestAdditional, testCodecCreateComponent007, Function | MediumTest | Level2) 278 { 279 struct CodecCallbackType *callback = CodecCallbackTypeGet(nullptr); 280 ASSERT_TRUE(callback != nullptr); 281 ASSERT_TRUE(manager_ != nullptr); 282 std::string compName("a~~~"); 283 struct CodecComponentType *component = nullptr; 284 uint32_t componentId = 0; 285 int32_t ret = manager_->CreateComponent(&component, &componentId, compName.data(), (int64_t)this, callback); 286 EXPECT_NE(ret, HDF_SUCCESS); 287 EXPECT_EQ(component, nullptr); 288 CodecCallbackTypeRelease(callback); 289 } 290 291 /** 292 * @tc.number SUB_Driver_Codec_CodecHdi_2000 293 * @tc.name testCodecCreateComponent008 294 * @tc.desc Open the OpenMax component based on a non-existent compName 295 */ 296 HWTEST_F(CodecHdiManagerTestAdditional, testCodecCreateComponent008, Function | MediumTest | Level2) 297 { 298 struct CodecCallbackType *callback = CodecCallbackTypeGet(nullptr); 299 ASSERT_TRUE(callback != nullptr); 300 ASSERT_TRUE(manager_ != nullptr); 301 std::string compName("a~~~"); 302 struct CodecComponentType *component = nullptr; 303 uint32_t componentId = 0; 304 int32_t ret = manager_->CreateComponent(&component, &componentId, compName.data(), (int64_t)this, callback); 305 EXPECT_NE(ret, HDF_SUCCESS); 306 EXPECT_EQ(component, nullptr); 307 CodecCallbackTypeRelease(callback); 308 } 309 310 /** 311 * @tc.number SUB_Driver_Codec_CodecHdi_2100 312 * @tc.name testCodecDestroyComponent001 313 * @tc.desc Test its stability by iterating through the DestroyComponent function 314 */ 315 HWTEST_F(CodecHdiManagerTestAdditional, testCodecDestroyComponent001, Function | MediumTest | Level1) 316 { 317 ASSERT_TRUE(manager_ != nullptr); 318 uint32_t componentId = 0; 319 int32_t ret; 320 int i = 0; 321 while (i < 50) { 322 ret = manager_->DestroyComponent(componentId); 323 ASSERT_EQ(ret, HDF_SUCCESS); 324 i++; 325 } 326 } 327 328 /** 329 * @tc.number SUB_Driver_Codec_CodecHdi_2200 330 * @tc.name testCodecDestroyComponent002 331 * @tc.desc Open the OpenMax component based on a non-existent compName 332 */ 333 HWTEST_F(CodecHdiManagerTestAdditional, testCodecDestroyComponent002, Function | MediumTest | Level1) 334 { 335 ASSERT_TRUE(manager_ != nullptr); 336 uint32_t componentId = -1; 337 int32_t ret = manager_->DestroyComponent(componentId); 338 ASSERT_EQ(ret, HDF_SUCCESS); 339 } 340 341 /** 342 * @tc.number SUB_Driver_Codec_CodecHdi_2300 343 * @tc.name testCodecGetComponentCapabilityList007 344 * @tc.desc Verify when GetComponentCapabilityList function into the parameter to 0, 345 * the second result returned failure 346 */ 347 HWTEST_F(CodecHdiManagerTestAdditional, testCodecGetComponentCapabilityList007, Function | MediumTest | Level2) 348 { 349 ASSERT_TRUE(manager_ != nullptr); 350 CodecCompCapability *capList = (CodecCompCapability *)OsalMemAlloc(sizeof(CodecCompCapability) * 0); 351 auto err = manager_->GetComponentCapabilityList(capList, 0); 352 EXPECT_NE(err, HDF_SUCCESS); 353 } 354 355 /** 356 * @tc.number SUB_Driver_Codec_CodecHdi_2400 357 * @tc.name testCodecGetComponentCapabilityList008 358 * @tc.desc Verify when GetComponentCapabilityList function into the parameter to 100000, 359 * the second result returned failure 360 */ 361 HWTEST_F(CodecHdiManagerTestAdditional, testCodecGetComponentCapabilityList008, Function | MediumTest | Level2) 362 { 363 ASSERT_TRUE(manager_ != nullptr); 364 CodecCompCapability *capList = (CodecCompCapability *)OsalMemAlloc(sizeof(CodecCompCapability) * 100000); 365 auto err = manager_->GetComponentCapabilityList(capList, 100000); 366 EXPECT_NE(err, HDF_SUCCESS); 367 } 368 369 /** 370 * @tc.number SUB_Driver_Codec_CodecHdi_2500 371 * @tc.name testCodecDestroyComponent003 372 * @tc.desc Verify that the DestroyComponent function returns success when the CreateComponent 373 * function returns success 374 */ 375 HWTEST_F(CodecHdiManagerTestAdditional, testCodecDestroyComponent003, Function | MediumTest | Level1) 376 { 377 ASSERT_TRUE(manager_ != nullptr); 378 std::string compName(""); 379 auto count = manager_->GetComponentNum(); 380 ASSERT_TRUE(count > 0); 381 CodecCompCapability *capList = (CodecCompCapability *)OsalMemAlloc(sizeof(CodecCompCapability) * count); 382 ASSERT_TRUE(capList != nullptr); 383 auto err = manager_->GetComponentCapabilityList(capList, count); 384 ASSERT_TRUE(err == HDF_SUCCESS); 385 compName = capList[0].compName; 386 OsalMemFree(capList); 387 capList = nullptr; 388 389 ASSERT_FALSE(compName.empty()); 390 struct CodecCallbackType *callback = CodecCallbackTypeGet(nullptr); 391 struct CodecComponentType *component = nullptr; 392 uint32_t componentId = 1; 393 ASSERT_TRUE(callback != nullptr); 394 395 int32_t ret = manager_->CreateComponent(&component, &componentId, compName.data(), (int64_t)this, callback); 396 EXPECT_EQ(ret, HDF_SUCCESS); 397 EXPECT_EQ(manager_->DestroyComponent(componentId), 0); 398 399 CodecCallbackTypeRelease(callback); 400 } 401 402 /** 403 * @tc.number SUB_Driver_Codec_CodecHdi_2600 404 * @tc.name testCodecDestroyComponent004 405 * @tc.desc Verify that a failure is returned when the CreateComponent function returns success and the entry of the 406 * DestroyComponent function is 1000, the second entry of the CreateComponent function 407 */ 408 HWTEST_F(CodecHdiManagerTestAdditional, testCodecDestroyComponent004, Function | MediumTest | Level1) 409 { 410 ASSERT_TRUE(manager_ != nullptr); 411 std::string compName(""); 412 auto count = manager_->GetComponentNum(); 413 ASSERT_TRUE(count > 0); 414 CodecCompCapability *capList = (CodecCompCapability *)OsalMemAlloc(sizeof(CodecCompCapability) * count); 415 ASSERT_TRUE(capList != nullptr); 416 auto err = manager_->GetComponentCapabilityList(capList, count); 417 ASSERT_TRUE(err == HDF_SUCCESS); 418 compName = capList[0].compName; 419 OsalMemFree(capList); 420 capList = nullptr; 421 422 ASSERT_FALSE(compName.empty()); 423 struct CodecCallbackType *callback = CodecCallbackTypeGet(nullptr); 424 struct CodecComponentType *component = nullptr; 425 uint32_t componentId = 1; 426 ASSERT_TRUE(callback != nullptr); 427 428 int32_t ret = manager_->CreateComponent(&component, &componentId, compName.data(), (int64_t)this, callback); 429 EXPECT_EQ(ret, HDF_SUCCESS); 430 componentId = 1000; 431 EXPECT_EQ(manager_->DestroyComponent(componentId), 0); 432 433 CodecCallbackTypeRelease(callback); 434 } 435 436 /** 437 * @tc.number SUB_Driver_Codec_CodecHdi_2700 438 * @tc.name testCodecDestroyComponent005 439 * @tc.desc Verify that the DestroyComponent result returns a failure when the CreateComponent 440 * function returns a failure 441 */ 442 HWTEST_F(CodecHdiManagerTestAdditional, testCodecDestroyComponent005, Function | MediumTest | Level1) 443 { 444 struct CodecCallbackType *callback = CodecCallbackTypeGet(nullptr); 445 ASSERT_TRUE(callback != nullptr); 446 ASSERT_TRUE(manager_ != nullptr); 447 std::string compName(" "); 448 struct CodecComponentType *component = nullptr; 449 uint32_t componentId = 1000; 450 int32_t ret = manager_->CreateComponent(&component, &componentId, compName.data(), (int64_t)this, callback); 451 EXPECT_NE(ret, HDF_SUCCESS); 452 453 EXPECT_EQ(manager_->DestroyComponent(componentId), 0); 454 CodecCallbackTypeRelease(callback); 455 } 456 } // namespace 457