1 /* 2 * Copyright (c) 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 <gtest/gtest.h> 17 18 #include "key_command_handler_util.h" 19 #include "mmi_log.h" 20 21 #undef MMI_LOG_TAG 22 #define MMI_LOG_TAG "KeyCommandHandlerUtilTest" 23 24 namespace OHOS { 25 namespace MMI { 26 namespace { 27 using namespace testing::ext; 28 } // namespace 29 30 class KeyCommandHandlerUtilTest : public testing::Test { 31 public: SetUpTestCase(void)32 static void SetUpTestCase(void) {} TearDownTestCase(void)33 static void TearDownTestCase(void) {} 34 }; 35 36 /** 37 * @tc.name: KeyCommandHandlerUtilTest_IsSpecialType_001 38 * @tc.desc: Test the function IsSpecialType 39 * @tc.type: FUNC 40 * @tc.require: 41 */ 42 HWTEST_F(KeyCommandHandlerUtilTest, KeyCommandHandlerUtilTest_IsSpecialType_001, TestSize.Level1) 43 { 44 CALL_TEST_DEBUG; 45 SpecialType type = SPECIAL_ALL; 46 int32_t keyCode = 1; 47 bool result = OHOS::MMI::IsSpecialType(keyCode, type); 48 EXPECT_FALSE(result); 49 type = SUBSCRIBER_BEFORE_DELAY; 50 keyCode = 2; 51 result = OHOS::MMI::IsSpecialType(keyCode, type); 52 EXPECT_FALSE(result); 53 type = KEY_DOWN_ACTION; 54 keyCode = 3; 55 result = OHOS::MMI::IsSpecialType(keyCode, type); 56 EXPECT_FALSE(result); 57 type = KEY_DOWN_ACTION; 58 keyCode = -1; 59 result = OHOS::MMI::IsSpecialType(keyCode, type); 60 EXPECT_FALSE(result); 61 } 62 63 /** 64 * @tc.name: KeyCommandHandlerUtilTest_GetBusinessId_001 65 * @tc.desc: Test the function GetBusinessId 66 * @tc.type: FUNC 67 * @tc.require: 68 */ 69 HWTEST_F(KeyCommandHandlerUtilTest, KeyCommandHandlerUtilTest_GetBusinessId_001, TestSize.Level1) 70 { 71 CALL_TEST_DEBUG; 72 cJSON *jsonData = cJSON_CreateString("not an object"); 73 std::string businessIdValue; 74 std::vector<std::string> businessIds; 75 bool result = OHOS::MMI::GetBusinessId(jsonData, businessIdValue, businessIds); 76 EXPECT_FALSE(result); 77 cJSON_Delete(jsonData); 78 } 79 80 /** 81 * @tc.name: KeyCommandHandlerUtilTest_GetBusinessId_002 82 * @tc.desc: Test the function GetBusinessId 83 * @tc.type: FUNC 84 * @tc.require: 85 */ 86 HWTEST_F(KeyCommandHandlerUtilTest, KeyCommandHandlerUtilTest_GetBusinessId_002, TestSize.Level1) 87 { 88 CALL_TEST_DEBUG; 89 cJSON *jsonData = cJSON_CreateObject(); 90 cJSON_AddItemToObject(jsonData, "businessId", cJSON_CreateNumber(123)); 91 std::string businessIdValue; 92 std::vector<std::string> businessIds; 93 bool result = OHOS::MMI::GetBusinessId(jsonData, businessIdValue, businessIds); 94 EXPECT_FALSE(result); 95 cJSON_Delete(jsonData); 96 } 97 98 /** 99 * @tc.name: KeyCommandHandlerUtilTest_GetPreKeys_001 100 * @tc.desc: Test the function GetPreKeys 101 * @tc.type: FUNC 102 * @tc.require: 103 */ 104 HWTEST_F(KeyCommandHandlerUtilTest, KeyCommandHandlerUtilTest_GetPreKeys_001, TestSize.Level1) 105 { 106 CALL_TEST_DEBUG; 107 cJSON* jsonData = cJSON_CreateObject(); 108 ShortcutKey shortcutKey; 109 bool result = OHOS::MMI::GetPreKeys(jsonData, shortcutKey); 110 EXPECT_FALSE(result); 111 cJSON_Delete(jsonData); 112 } 113 114 /** 115 * @tc.name: KeyCommandHandlerUtilTest_GetPreKeys_002 116 * @tc.desc: Test the function GetPreKeys 117 * @tc.type: FUNC 118 * @tc.require: 119 */ 120 HWTEST_F(KeyCommandHandlerUtilTest, KeyCommandHandlerUtilTest_GetPreKeys_002, TestSize.Level1) 121 { 122 CALL_TEST_DEBUG; 123 cJSON* jsonData = cJSON_CreateObject(); 124 cJSON* preKey = cJSON_CreateArray(); 125 for (int i = 0; i < MAX_PREKEYS_NUM + 1; ++i) { 126 cJSON_AddItemToArray(preKey, cJSON_CreateNumber(i)); 127 } 128 cJSON_AddItemToObject(jsonData, "preKey", preKey); 129 ShortcutKey shortcutKey; 130 bool result = OHOS::MMI::GetPreKeys(jsonData, shortcutKey); 131 EXPECT_FALSE(result); 132 cJSON_Delete(jsonData); 133 } 134 135 /** 136 * @tc.name: KeyCommandHandlerUtilTest_GetPreKeys_003 137 * @tc.desc: Test the function GetPreKeys 138 * @tc.type: FUNC 139 * @tc.require: 140 */ 141 HWTEST_F(KeyCommandHandlerUtilTest, KeyCommandHandlerUtilTest_GetPreKeys_003, TestSize.Level1) 142 { 143 CALL_TEST_DEBUG; 144 cJSON* jsonData = cJSON_CreateObject(); 145 cJSON_AddItemToObject(jsonData, "preKey", cJSON_CreateString("invalid")); 146 ShortcutKey shortcutKey; 147 bool result = OHOS::MMI::GetPreKeys(jsonData, shortcutKey); 148 EXPECT_FALSE(result); 149 cJSON_Delete(jsonData); 150 } 151 152 /** 153 * @tc.name: KeyCommandHandlerUtilTest_GetPreKeys_004 154 * @tc.desc: Test the function GetPreKeys 155 * @tc.type: FUNC 156 * @tc.require: 157 */ 158 HWTEST_F(KeyCommandHandlerUtilTest, KeyCommandHandlerUtilTest_GetPreKeys_004, TestSize.Level1) 159 { 160 CALL_TEST_DEBUG; 161 cJSON* jsonData = cJSON_CreateObject(); 162 cJSON* preKey = cJSON_CreateArray(); 163 cJSON_AddItemToArray(preKey, cJSON_CreateNumber(-1)); 164 cJSON_AddItemToObject(jsonData, "preKey", preKey); 165 ShortcutKey shortcutKey; 166 bool result = OHOS::MMI::GetPreKeys(jsonData, shortcutKey); 167 EXPECT_FALSE(result); 168 cJSON_Delete(jsonData); 169 } 170 171 /** 172 * @tc.name: KeyCommandHandlerUtilTest_GetPreKeys_005 173 * @tc.desc: Test the function GetPreKeys 174 * @tc.type: FUNC 175 * @tc.require: 176 */ 177 HWTEST_F(KeyCommandHandlerUtilTest, KeyCommandHandlerUtilTest_GetPreKeys_005, TestSize.Level1) 178 { 179 CALL_TEST_DEBUG; 180 cJSON* jsonData = cJSON_CreateObject(); 181 cJSON* preKey = cJSON_CreateArray(); 182 cJSON_AddItemToArray(preKey, cJSON_CreateNumber(1)); 183 cJSON_AddItemToArray(preKey, cJSON_CreateNumber(1)); 184 cJSON_AddItemToObject(jsonData, "preKey", preKey); 185 ShortcutKey shortcutKey; 186 bool result = OHOS::MMI::GetPreKeys(jsonData, shortcutKey); 187 EXPECT_FALSE(result); 188 cJSON_Delete(jsonData); 189 } 190 191 /** 192 * @tc.name: KeyCommandHandlerUtilTest_IsSpecialType_002 193 * @tc.desc: Test keyCode is not in SPECIAL_KEYS 194 * @tc.type: FUNC 195 * @tc.require: 196 */ 197 HWTEST_F(KeyCommandHandlerUtilTest, KeyCommandHandlerUtilTest_IsSpecialType_002, TestSize.Level1) 198 { 199 CALL_TEST_DEBUG; 200 int32_t keyCode = 999; 201 SpecialType type = SpecialType::SPECIAL_ALL; 202 EXPECT_FALSE(OHOS::MMI::IsSpecialType(keyCode, type)); 203 } 204 205 /** 206 * @tc.name: KeyCommandHandlerUtilTest_IsSpecialType_003 207 * @tc.desc: The corresponding value is not equal to SpecialType.: SPECIAL_ALL and input type 208 * @tc.type: FUNC 209 * @tc.require: 210 */ 211 HWTEST_F(KeyCommandHandlerUtilTest, KeyCommandHandlerUtilTest_IsSpecialType_003, TestSize.Level1) 212 { 213 CALL_TEST_DEBUG; 214 int32_t keyCode = 16; 215 SpecialType type = SpecialType::SPECIAL_ALL; 216 EXPECT_FALSE(OHOS::MMI::IsSpecialType(keyCode, type)); 217 } 218 219 /** 220 * @tc.name: KeyCommandHandlerUtilTest_IsSpecialType_004 221 * @tc.desc: The test keyCode is in SPECIAL_KEYS and the value is equal to SpecialType.: SPECIAL_ALL 222 * @tc.type: FUNC 223 * @tc.require: 224 */ 225 HWTEST_F(KeyCommandHandlerUtilTest, KeyCommandHandlerUtilTest_IsSpecialType_004, TestSize.Level1) 226 { 227 CALL_TEST_DEBUG; 228 int32_t keyCode = 0; 229 SpecialType type = SpecialType::SPECIAL_ALL; 230 EXPECT_FALSE(OHOS::MMI::IsSpecialType(keyCode, type)); 231 } 232 233 /** 234 * @tc.name: KeyCommandHandlerUtilTest_GetBusinessId_003 235 * @tc.desc: Test the scenario where the JSON object is not a valid object 236 * @tc.type: FUNC 237 * @tc.require: 238 */ 239 HWTEST_F(KeyCommandHandlerUtilTest, KeyCommandHandlerUtilTest_GetBusinessId_003, TestSize.Level1) 240 { 241 CALL_TEST_DEBUG; 242 cJSON *jsonData = nullptr; 243 std::string businessIdValue; 244 std::vector<std::string> businessIds; 245 bool result = OHOS::MMI::GetBusinessId(jsonData, businessIdValue, businessIds); 246 EXPECT_FALSE(result); 247 cJSON_Delete(jsonData); 248 } 249 250 /** 251 * @tc.name: KeyCommandHandlerUtilTest_GetBusinessId_004 252 * @tc.desc: Test the scenario where businessId is not a string 253 * @tc.type: FUNC 254 * @tc.require: 255 */ 256 HWTEST_F(KeyCommandHandlerUtilTest, KeyCommandHandlerUtilTest_GetBusinessId_004, TestSize.Level1) 257 { 258 CALL_TEST_DEBUG; 259 cJSON *jsonData = cJSON_CreateObject(); 260 std::vector<std::string> businessIds; 261 cJSON_AddItemToObject(jsonData, "businessIds", cJSON_CreateNumber(123)); 262 std::string businessIdValue; 263 bool result = OHOS::MMI::GetBusinessId(jsonData, businessIdValue, businessIds); 264 EXPECT_FALSE(result); 265 cJSON_Delete(jsonData); 266 } 267 268 /** 269 * @tc.name: KeyCommandHandlerUtilTest_GetBusinessId_005 270 * @tc.desc: Test the normal running condition 271 * @tc.type: FUNC 272 * @tc.require: 273 */ 274 HWTEST_F(KeyCommandHandlerUtilTest, KeyCommandHandlerUtilTest_GetBusinessId_005, TestSize.Level1) 275 { 276 CALL_TEST_DEBUG; 277 cJSON *jsonData = cJSON_CreateObject(); 278 std::vector<std::string> businessIds; 279 cJSON_AddStringToObject(jsonData, "businessId", "testBusinessId"); 280 std::string businessIdValue; 281 bool result = OHOS::MMI::GetBusinessId(jsonData, businessIdValue, businessIds); 282 EXPECT_TRUE(result); 283 cJSON_Delete(jsonData); 284 } 285 286 /** 287 * @tc.name: KeyCommandHandlerUtilTest_GetPreKeys_006 288 * @tc.desc: Test the case that the input jsonData is not an object 289 * @tc.type: FUNC 290 * @tc.require: 291 */ 292 HWTEST_F(KeyCommandHandlerUtilTest, KeyCommandHandlerUtilTest_GetPreKeys_006, TestSize.Level1) 293 { 294 CALL_TEST_DEBUG; 295 cJSON* jsonData = nullptr; 296 ShortcutKey shortcutKey; 297 EXPECT_FALSE(OHOS::MMI::GetPreKeys(jsonData, shortcutKey)); 298 cJSON_Delete(jsonData); 299 } 300 301 /** 302 * @tc.name: KeyCommandHandlerUtilTest_GetPreKeys_007 303 * @tc.desc: Test the case that preKey is not an array 304 * @tc.type: FUNC 305 * @tc.require: 306 */ 307 HWTEST_F(KeyCommandHandlerUtilTest, KeyCommandHandlerUtilTest_GetPreKeys_007, TestSize.Level1) 308 { 309 CALL_TEST_DEBUG; 310 cJSON* jsonData = cJSON_CreateObject(); 311 cJSON_AddItemToObject(jsonData, "preKey", cJSON_CreateString("test")); 312 ShortcutKey shortcutKey; 313 EXPECT_FALSE(OHOS::MMI::GetPreKeys(jsonData, shortcutKey)); 314 cJSON_Delete(jsonData); 315 } 316 317 /** 318 * @tc.name: KeyCommandHandlerUtilTest_GetPreKeys_008 319 * @tc.desc: Test the case that the size of preKey exceeds MAX_PREKEYS_NUM 320 * @tc.type: FUNC 321 * @tc.require: 322 */ 323 HWTEST_F(KeyCommandHandlerUtilTest, KeyCommandHandlerUtilTest_GetPreKeys_008, TestSize.Level1) 324 { 325 CALL_TEST_DEBUG; 326 cJSON* jsonData = cJSON_CreateObject(); 327 cJSON* preKey = cJSON_CreateArray(); 328 for (int i = 0; i < 10; ++i) { 329 cJSON_AddItemToArray(preKey, cJSON_CreateNumber(i)); 330 } 331 cJSON_AddItemToObject(jsonData, "preKey", preKey); 332 ShortcutKey shortcutKey; 333 EXPECT_FALSE(OHOS::MMI::GetPreKeys(jsonData, shortcutKey)); 334 cJSON_Delete(jsonData); 335 } 336 337 /** 338 * @tc.name: KeyCommandHandlerUtilTest_GetPreKeys_009 339 * @tc.desc: Test if the element in preKey is not a number 340 * @tc.type: FUNC 341 * @tc.require: 342 */ 343 HWTEST_F(KeyCommandHandlerUtilTest, KeyCommandHandlerUtilTest_GetPreKeys_009, TestSize.Level1) 344 { 345 CALL_TEST_DEBUG; 346 cJSON* jsonData = cJSON_CreateObject(); 347 cJSON* preKey = cJSON_CreateArray(); 348 cJSON_AddItemToArray(preKey, cJSON_CreateString("not a number")); 349 cJSON_AddItemToObject(jsonData, "preKey", preKey); 350 ShortcutKey shortcutKey; 351 EXPECT_FALSE(OHOS::MMI::GetPreKeys(jsonData, shortcutKey)); 352 cJSON_Delete(jsonData); 353 } 354 355 /** 356 * @tc.name: KeyCommandHandlerUtilTest_GetPreKeys_010 357 * @tc.desc: Tests if the number in preKey is less than 0 358 * @tc.type: FUNC 359 * @tc.require: 360 */ 361 HWTEST_F(KeyCommandHandlerUtilTest, KeyCommandHandlerUtilTest_GetPreKeys_010, TestSize.Level1) 362 { 363 CALL_TEST_DEBUG; 364 cJSON* jsonData = cJSON_CreateObject(); 365 cJSON* preKey = cJSON_CreateArray(); 366 cJSON_AddItemToArray(preKey, cJSON_CreateNumber(-1)); 367 cJSON_AddItemToObject(jsonData, "preKey", preKey); 368 ShortcutKey shortcutKey; 369 EXPECT_FALSE(OHOS::MMI::GetPreKeys(jsonData, shortcutKey)); 370 cJSON_Delete(jsonData); 371 } 372 373 /** 374 * @tc.name: KeyCommandHandlerUtilTest_GetPreKeys_011 375 * @tc.desc: Test the duplicated number in preKey 376 * @tc.type: FUNC 377 * @tc.require: 378 */ 379 HWTEST_F(KeyCommandHandlerUtilTest, KeyCommandHandlerUtilTest_GetPreKeys_011, TestSize.Level1) 380 { 381 CALL_TEST_DEBUG; 382 cJSON* jsonData = cJSON_CreateObject(); 383 cJSON* preKey = cJSON_CreateArray(); 384 cJSON_AddItemToArray(preKey, cJSON_CreateNumber(1)); 385 cJSON_AddItemToArray(preKey, cJSON_CreateNumber(1)); 386 cJSON_AddItemToObject(jsonData, "preKey", preKey); 387 ShortcutKey shortcutKey; 388 EXPECT_FALSE(OHOS::MMI::GetPreKeys(jsonData, shortcutKey)); 389 cJSON_Delete(jsonData); 390 } 391 392 /** 393 * @tc.name: KeyCommandHandlerUtilTest_GetPreKeys_012 394 * @tc.desc: Test the normal running condition 395 * @tc.type: FUNC 396 * @tc.require: 397 */ 398 HWTEST_F(KeyCommandHandlerUtilTest, KeyCommandHandlerUtilTest_GetPreKeys_012, TestSize.Level1) 399 { 400 CALL_TEST_DEBUG; 401 cJSON* jsonData = cJSON_CreateObject(); 402 cJSON* preKey = cJSON_CreateArray(); 403 cJSON_AddItemToObject(jsonData, "preKey", preKey); 404 cJSON_AddItemToArray(preKey, cJSON_CreateNumber(1)); 405 cJSON_AddItemToArray(preKey, cJSON_CreateNumber(2)); 406 cJSON_AddItemToArray(preKey, cJSON_CreateNumber(3)); 407 cJSON_AddItemToArray(preKey, cJSON_CreateNumber(4)); 408 ShortcutKey shortcutKey; 409 EXPECT_TRUE(OHOS::MMI::GetPreKeys(jsonData, shortcutKey)); 410 cJSON_Delete(jsonData); 411 } 412 413 /** 414 * @tc.name: KeyCommandHandlerUtilTest_GetTrigger_001 415 * @tc.desc: Test jsonData is not an object 416 * @tc.type: FUNC 417 * @tc.require: 418 */ 419 HWTEST_F(KeyCommandHandlerUtilTest, KeyCommandHandlerUtilTest_GetTrigger_001, TestSize.Level1) 420 { 421 CALL_TEST_DEBUG; 422 int32_t triggerType = 1; 423 const char* nonObjectInput = nullptr; 424 EXPECT_FALSE(OHOS::MMI::GetTrigger((const cJSON*)nonObjectInput, triggerType)); 425 } 426 427 /** 428 * @tc.name: KeyCommandHandlerUtilTest_GetTrigger_002 429 * @tc.desc: The value of the trigger field is not a string 430 * @tc.type: FUNC 431 * @tc.require: 432 */ 433 HWTEST_F(KeyCommandHandlerUtilTest, KeyCommandHandlerUtilTest_GetTrigger_002, TestSize.Level1) 434 { 435 CALL_TEST_DEBUG; 436 int32_t triggerType = 1; 437 cJSON *jsonData = cJSON_CreateObject(); 438 cJSON_AddItemToObject(jsonData, "trigger", cJSON_CreateNumber(123)); 439 EXPECT_FALSE(OHOS::MMI::GetTrigger(jsonData, triggerType)); 440 cJSON_Delete(jsonData); 441 } 442 443 /** 444 * @tc.name: KeyCommandHandlerUtilTest_GetTrigger_003 445 * @tc.desc: The value of the test trigger field is neither key_up nor key_down 446 * @tc.type: FUNC 447 * @tc.require: 448 */ 449 HWTEST_F(KeyCommandHandlerUtilTest, KeyCommandHandlerUtilTest_GetTrigger_003, TestSize.Level1) 450 { 451 CALL_TEST_DEBUG; 452 int32_t triggerType = 1; 453 cJSON *jsonData = cJSON_CreateObject(); 454 cJSON_AddStringToObject(jsonData, "trigger", "invalid_value"); 455 EXPECT_FALSE(OHOS::MMI::GetTrigger(jsonData, triggerType)); 456 cJSON_Delete(jsonData); 457 } 458 459 /** 460 * @tc.name: KeyCommandHandlerUtilTest_GetTrigger_004 461 * @tc.desc: The value of the test trigger field is key_up 462 * @tc.type: FUNC 463 * @tc.require: 464 */ 465 HWTEST_F(KeyCommandHandlerUtilTest, KeyCommandHandlerUtilTest_GetTrigger_004, TestSize.Level1) 466 { 467 CALL_TEST_DEBUG; 468 int32_t triggerType = 1; 469 cJSON *jsonData = cJSON_CreateObject(); 470 cJSON_AddStringToObject(jsonData, "trigger", "key_up"); 471 EXPECT_TRUE(OHOS::MMI::GetTrigger(jsonData, triggerType)); 472 EXPECT_EQ(triggerType, KeyEvent::KEY_ACTION_UP); 473 cJSON_Delete(jsonData); 474 } 475 476 /** 477 * @tc.name: KeyCommandHandlerUtilTest_GetTrigger_005 478 * @tc.desc: The value of the test trigger field is key_down 479 * @tc.type: FUNC 480 * @tc.require: 481 */ 482 HWTEST_F(KeyCommandHandlerUtilTest, KeyCommandHandlerUtilTest_GetTrigger_005, TestSize.Level1) 483 { 484 CALL_TEST_DEBUG; 485 int32_t triggerType = 1; 486 cJSON *jsonData = cJSON_CreateObject(); 487 cJSON_AddStringToObject(jsonData, "trigger", "key_down"); 488 EXPECT_TRUE(OHOS::MMI::GetTrigger(jsonData, triggerType)); 489 EXPECT_EQ(triggerType, KeyEvent::KEY_ACTION_DOWN); 490 cJSON_Delete(jsonData); 491 } 492 493 /** 494 * @tc.name: KeyCommandHandlerUtilTest_GetKeyDownDuration_001 495 * @tc.desc: Test jsonData is not an object 496 * @tc.type: FUNC 497 * @tc.require: 498 */ 499 HWTEST_F(KeyCommandHandlerUtilTest, KeyCommandHandlerUtilTest_GetKeyDownDuration_001, TestSize.Level1) 500 { 501 CALL_TEST_DEBUG; 502 int32_t keyDownDurationInt = 1; 503 EXPECT_FALSE(OHOS::MMI::GetKeyDownDuration(nullptr, keyDownDurationInt)); 504 } 505 506 /** 507 * @tc.name: KeyCommandHandlerUtilTest_GetKeyDownDuration_002 508 * @tc.desc: Test that the value of the keyDownDuration field is not a number 509 * @tc.type: FUNC 510 * @tc.require: 511 */ 512 HWTEST_F(KeyCommandHandlerUtilTest, KeyCommandHandlerUtilTest_GetKeyDownDuration_002, TestSize.Level1) 513 { 514 CALL_TEST_DEBUG; 515 cJSON *jsonData = cJSON_CreateObject(); 516 cJSON_AddItemToObject(jsonData, "keyDownDuration", cJSON_CreateString("not a number")); 517 int32_t keyDownDurationInt = 1; 518 EXPECT_FALSE(OHOS::MMI::GetKeyDownDuration(jsonData, keyDownDurationInt)); 519 cJSON_Delete(jsonData); 520 } 521 522 /** 523 * @tc.name: KeyCommandHandlerUtilTest_GetKeyDownDuration_003 524 * @tc.desc: Test the value of the keyDownDuration field is negative 525 * @tc.type: FUNC 526 * @tc.require: 527 */ 528 HWTEST_F(KeyCommandHandlerUtilTest, KeyCommandHandlerUtilTest_GetKeyDownDuration_003, TestSize.Level1) 529 { 530 CALL_TEST_DEBUG; 531 cJSON *jsonData = cJSON_CreateObject(); 532 cJSON_AddNumberToObject(jsonData, "keyDownDuration", -1); 533 int32_t keyDownDurationInt = 1; 534 EXPECT_FALSE(OHOS::MMI::GetKeyDownDuration(jsonData, keyDownDurationInt)); 535 cJSON_Delete(jsonData); 536 } 537 538 /** 539 * @tc.name: KeyCommandHandlerUtilTest_GetKeyDownDuration_004 540 * @tc.desc: Test normal branch condition 541 * @tc.type: FUNC 542 * @tc.require: 543 */ 544 HWTEST_F(KeyCommandHandlerUtilTest, KeyCommandHandlerUtilTest_GetKeyDownDuration_004, TestSize.Level1) 545 { 546 CALL_TEST_DEBUG; 547 cJSON *jsonData = cJSON_CreateObject(); 548 cJSON_AddNumberToObject(jsonData, "keyDownDuration", 1); 549 int32_t keyDownDurationInt = 1; 550 EXPECT_TRUE(OHOS::MMI::GetKeyDownDuration(jsonData, keyDownDurationInt)); 551 EXPECT_EQ(keyDownDurationInt, 1); 552 cJSON_Delete(jsonData); 553 } 554 555 /** 556 * @tc.name: KeyCommandHandlerUtilTest_GetKeyFinalKey_001 557 * @tc.desc: Test jsonData is not an object 558 * @tc.type: FUNC 559 * @tc.require: 560 */ 561 HWTEST_F(KeyCommandHandlerUtilTest, KeyCommandHandlerUtilTest_GetKeyFinalKey_001, TestSize.Level1) 562 { 563 CALL_TEST_DEBUG; 564 int32_t finalKeyInt = 1; 565 EXPECT_FALSE(OHOS::MMI::GetKeyFinalKey(nullptr, finalKeyInt)); 566 } 567 568 /** 569 * @tc.name: KeyCommandHandlerUtilTest_GetKeyFinalKey_002 570 * @tc.desc: Test finalKey value is not a number 571 * @tc.type: FUNC 572 * @tc.require: 573 */ 574 HWTEST_F(KeyCommandHandlerUtilTest, KeyCommandHandlerUtilTest_GetKeyFinalKey_002, TestSize.Level1) 575 { 576 CALL_TEST_DEBUG; 577 int32_t finalKeyInt = 1; 578 cJSON *jsonData = cJSON_CreateObject(); 579 cJSON_AddStringToObject(jsonData, "finalKey", "not a number"); 580 EXPECT_FALSE(OHOS::MMI::GetKeyFinalKey(jsonData, finalKeyInt)); 581 cJSON_Delete(jsonData); 582 } 583 584 /** 585 * @tc.name: KeyCommandHandlerUtilTest_GetKeyFinalKey_003 586 * @tc.desc: Test that jsonData is an object and that the value of finalKey is a number 587 * @tc.type: FUNC 588 * @tc.require: 589 */ 590 HWTEST_F(KeyCommandHandlerUtilTest, KeyCommandHandlerUtilTest_GetKeyFinalKey_003, TestSize.Level1) 591 { 592 CALL_TEST_DEBUG; 593 int32_t finalKeyInt = 1; 594 cJSON *jsonData = cJSON_CreateObject(); 595 cJSON_AddNumberToObject(jsonData, "finalKey", 123); 596 EXPECT_TRUE(OHOS::MMI::GetKeyFinalKey(jsonData, finalKeyInt)); 597 EXPECT_EQ(finalKeyInt, 123); 598 cJSON_Delete(jsonData); 599 } 600 601 /** 602 * @tc.name: KeyCommandHandlerUtilTest_GetKeyVal_001 603 * @tc.desc: Test key does not exist in JSON object 604 * @tc.type: FUNC 605 * @tc.require: 606 */ 607 HWTEST_F(KeyCommandHandlerUtilTest, KeyCommandHandlerUtilTest_GetKeyVal_001, TestSize.Level1) 608 { 609 CALL_TEST_DEBUG; 610 cJSON *json = nullptr; 611 std::string value; 612 OHOS::MMI::GetKeyVal(json, "key", value); 613 EXPECT_TRUE(value.empty()); 614 cJSON_Delete(json); 615 } 616 617 /** 618 * @tc.name: KeyCommandHandlerUtilTest_GetKeyVal_002 619 * @tc.desc: The value corresponding to the test key is a string type 620 * @tc.type: FUNC 621 * @tc.require: 622 */ 623 HWTEST_F(KeyCommandHandlerUtilTest, KeyCommandHandlerUtilTest_GetKeyVal_002, TestSize.Level1) 624 { 625 CALL_TEST_DEBUG; 626 cJSON *json = cJSON_CreateObject(); 627 cJSON_AddStringToObject(json, "key", "value"); 628 std::string value; 629 OHOS::MMI::GetKeyVal(json, "key", value); 630 EXPECT_EQ(value, "value"); 631 cJSON_Delete(json); 632 } 633 634 /** 635 * @tc.name: KeyCommandHandlerUtilTest_GetEntities_001 636 * @tc.desc: Testing jsonAbility is not an object 637 * @tc.type: FUNC 638 * @tc.require: 639 */ 640 HWTEST_F(KeyCommandHandlerUtilTest, KeyCommandHandlerUtilTest_GetEntities_001, TestSize.Level1) 641 { 642 CALL_TEST_DEBUG; 643 Ability ability; 644 cJSON* jsonAbility = nullptr; 645 ASSERT_FALSE(OHOS::MMI::GetEntities(jsonAbility, ability)); 646 cJSON_Delete(jsonAbility); 647 } 648 649 /** 650 * @tc.name: KeyCommandHandlerUtilTest_GetEntities_002 651 * @tc.desc: Test has no entities field 652 * @tc.type: FUNC 653 * @tc.require: 654 */ 655 HWTEST_F(KeyCommandHandlerUtilTest, KeyCommandHandlerUtilTest_GetEntities_002, TestSize.Level1) 656 { 657 CALL_TEST_DEBUG; 658 Ability ability; 659 cJSON* jsonAbility = cJSON_CreateObject(); 660 ASSERT_TRUE(OHOS::MMI::GetEntities(jsonAbility, ability)); 661 cJSON_Delete(jsonAbility); 662 } 663 664 /** 665 * @tc.name: KeyCommandHandlerUtilTest_GetEntities_003 666 * @tc.desc: The test entities field exists but is not an array 667 * @tc.type: FUNC 668 * @tc.require: 669 */ 670 HWTEST_F(KeyCommandHandlerUtilTest, KeyCommandHandlerUtilTest_GetEntities_003, TestSize.Level1) 671 { 672 CALL_TEST_DEBUG; 673 Ability ability; 674 cJSON* jsonAbility = cJSON_CreateObject(); 675 cJSON_AddItemToObject(jsonAbility, "entities", cJSON_CreateNumber(123)); 676 ASSERT_FALSE(OHOS::MMI::GetEntities(jsonAbility, ability)); 677 cJSON_Delete(jsonAbility); 678 } 679 680 /** 681 * @tc.name: KeyCommandHandlerUtilTest_GetEntities_004 682 * @tc.desc: Test array contains non-string elements 683 * @tc.type: FUNC 684 * @tc.require: 685 */ 686 HWTEST_F(KeyCommandHandlerUtilTest, KeyCommandHandlerUtilTest_GetEntities_004, TestSize.Level1) 687 { 688 CALL_TEST_DEBUG; 689 Ability ability; 690 cJSON* jsonAbility = cJSON_CreateObject(); 691 cJSON* entities = cJSON_CreateArray(); 692 cJSON_AddItemToArray(entities, cJSON_CreateNumber(123)); 693 cJSON_AddItemToObject(jsonAbility, "entities", entities); 694 ASSERT_FALSE(OHOS::MMI::GetEntities(jsonAbility, ability)); 695 cJSON_Delete(jsonAbility); 696 } 697 698 /** 699 * @tc.name: KeyCommandHandlerUtilTest_GetEntities_005 700 * @tc.desc: Test normal conditions 701 * @tc.type: FUNC 702 * @tc.require: 703 */ 704 HWTEST_F(KeyCommandHandlerUtilTest, KeyCommandHandlerUtilTest_GetEntities_005, TestSize.Level1) 705 { 706 CALL_TEST_DEBUG; 707 Ability ability; 708 cJSON* jsonAbility = cJSON_CreateObject(); 709 cJSON* entities = cJSON_CreateArray(); 710 cJSON_AddItemToArray(entities, cJSON_CreateString("entity1")); 711 cJSON_AddItemToArray(entities, cJSON_CreateString("entity2")); 712 cJSON_AddItemToObject(jsonAbility, "entities", entities); 713 ASSERT_TRUE(OHOS::MMI::GetEntities(jsonAbility, ability)); 714 EXPECT_EQ(ability.entities.size(), 2); 715 EXPECT_EQ(ability.entities[0], "entity1"); 716 EXPECT_EQ(ability.entities[1], "entity2"); 717 cJSON_Delete(jsonAbility); 718 } 719 720 /** 721 * @tc.name: KeyCommandHandlerUtilTest_GetParams_001 722 * @tc.desc: Test jsonAbility is not an object 723 * @tc.type: FUNC 724 * @tc.require: 725 */ 726 HWTEST_F(KeyCommandHandlerUtilTest, KeyCommandHandlerUtilTest_GetParams_001, TestSize.Level1) 727 { 728 CALL_TEST_DEBUG; 729 Ability ability; 730 cJSON* jsonAbility = nullptr; 731 ASSERT_FALSE(OHOS::MMI::GetParams(jsonAbility, ability)); 732 cJSON_Delete(jsonAbility); 733 } 734 735 /** 736 * @tc.name: KeyCommandHandlerUtilTest_GetParams_002 737 * @tc.desc: Test params are not an array 738 * @tc.type: FUNC 739 * @tc.require: 740 */ 741 HWTEST_F(KeyCommandHandlerUtilTest, KeyCommandHandlerUtilTest_GetParams_002, TestSize.Level1) 742 { 743 CALL_TEST_DEBUG; 744 Ability ability; 745 cJSON* jsonAbility = cJSON_CreateObject(); 746 cJSON* params = cJSON_CreateString("not an array"); 747 cJSON_AddItemToObject(jsonAbility, "params", params); 748 bool result = OHOS::MMI::GetParams(jsonAbility, ability); 749 ASSERT_FALSE(result); 750 ASSERT_TRUE(ability.params.empty()); 751 cJSON_Delete(jsonAbility); 752 } 753 754 /** 755 * @tc.name: KeyCommandHandlerUtilTest_GetParams_003 756 * @tc.desc: Test Params for nullptr 757 * @tc.type: FUNC 758 * @tc.require: 759 */ 760 HWTEST_F(KeyCommandHandlerUtilTest, KeyCommandHandlerUtilTest_GetParams_003, TestSize.Level1) 761 { 762 CALL_TEST_DEBUG; 763 Ability ability; 764 cJSON* jsonAbility = cJSON_CreateObject(); 765 cJSON* params = cJSON_CreateArray(); 766 cJSON_AddItemToObject(jsonAbility, "params", params); 767 cJSON_AddItemToArray(params, nullptr); 768 bool result = OHOS::MMI::GetParams(jsonAbility, ability); 769 EXPECT_TRUE(result); 770 cJSON_Delete(jsonAbility); 771 } 772 773 /** 774 * @tc.name: KeyCommandHandlerUtilTest_GetParams_004 775 * @tc.desc: Test param is not an object 776 * @tc.type: FUNC 777 * @tc.require: 778 */ 779 HWTEST_F(KeyCommandHandlerUtilTest, KeyCommandHandlerUtilTest_GetParams_004, TestSize.Level1) 780 { 781 CALL_TEST_DEBUG; 782 Ability ability; 783 cJSON* jsonAbility = cJSON_CreateObject(); 784 cJSON* params = cJSON_CreateObject(); 785 cJSON_AddItemToObject(jsonAbility, "params", params); 786 bool result = OHOS::MMI::GetParams(jsonAbility, ability); 787 EXPECT_FALSE(result); 788 cJSON_Delete(jsonAbility); 789 } 790 791 /** 792 * @tc.name: KeyCommandHandlerUtilTest_GetParams_005 793 * @tc.desc: The test key is not a string 794 * @tc.type: FUNC 795 * @tc.require: 796 */ 797 HWTEST_F(KeyCommandHandlerUtilTest, KeyCommandHandlerUtilTest_GetParams_005, TestSize.Level1) 798 { 799 CALL_TEST_DEBUG; 800 Ability ability; 801 const char* jsonStr = R"({"params":[{"key":123,"value":"value"}]})"; 802 cJSON* jsonAbility = cJSON_Parse(jsonStr); 803 bool result = OHOS::MMI::GetParams(jsonAbility, ability); 804 ASSERT_FALSE(result); 805 cJSON_Delete(jsonAbility); 806 } 807 808 /** 809 * @tc.name: KeyCommandHandlerUtilTest_GetParams_006 810 * @tc.desc: The test value is not a string 811 * @tc.type: FUNC 812 * @tc.require: 813 */ 814 HWTEST_F(KeyCommandHandlerUtilTest, KeyCommandHandlerUtilTest_GetParams_006, TestSize.Level1) 815 { 816 CALL_TEST_DEBUG; 817 Ability ability; 818 const char* jsonStr = R"({"params":[{"key":"key","value":123}]})"; 819 cJSON* jsonAbility = cJSON_Parse(jsonStr); 820 bool result = OHOS::MMI::GetParams(jsonAbility, ability); 821 ASSERT_FALSE(result); 822 cJSON_Delete(jsonAbility); 823 } 824 825 /** 826 * @tc.name: KeyCommandHandlerUtilTest_GetParams_007 827 * @tc.desc: Test for normal conditions 828 * @tc.type: FUNC 829 * @tc.require: 830 */ 831 HWTEST_F(KeyCommandHandlerUtilTest, KeyCommandHandlerUtilTest_GetParams_007, TestSize.Level1) 832 { 833 CALL_TEST_DEBUG; 834 Ability ability; 835 cJSON* jsonAbility = cJSON_CreateObject(); 836 cJSON* params = cJSON_CreateArray(); 837 cJSON* param1 = cJSON_CreateObject(); 838 cJSON* key1 = cJSON_CreateString("key"); 839 cJSON* value1 = cJSON_CreateString("value1"); 840 cJSON* param2 = cJSON_CreateObject(); 841 cJSON* key2 = cJSON_CreateString("key"); 842 cJSON* value2 = cJSON_CreateString("value2"); 843 cJSON_AddItemToObject(param1, "key", key1); 844 cJSON_AddItemToObject(param1, "value", value1); 845 cJSON_AddItemToObject(param2, "key", key2); 846 cJSON_AddItemToObject(param2, "value", value2); 847 cJSON_AddItemToArray(params, param1); 848 cJSON_AddItemToArray(params, param2); 849 cJSON_AddItemToObject(jsonAbility, "params", params); 850 bool result = OHOS::MMI::GetParams(jsonAbility, ability); 851 ASSERT_TRUE(result); 852 ASSERT_EQ(ability.params.size(), 1); 853 ASSERT_EQ(ability.params["key"], "value1"); 854 cJSON_Delete(jsonAbility); 855 } 856 857 /** 858 * @tc.name: KeyCommandHandlerUtilTest_ackageAbility_001 859 * @tc.desc: Test jsonAbility is not an object 860 * @tc.type: FUNC 861 * @tc.require: 862 */ 863 HWTEST_F(KeyCommandHandlerUtilTest, KeyCommandHandlerUtilTest_ackageAbility_001, TestSize.Level1) 864 { 865 CALL_TEST_DEBUG; 866 Ability ability; 867 cJSON* jsonAbility = nullptr; 868 ASSERT_FALSE(OHOS::MMI::PackageAbility(jsonAbility, ability)); 869 cJSON_Delete(jsonAbility); 870 } 871 872 /** 873 * @tc.name: KeyCommandHandlerUtilTest_ConvertToShortcutKey_001 874 * @tc.desc: The test case jsonData is not an object 875 * @tc.type: FUNC 876 * @tc.require: 877 */ 878 HWTEST_F(KeyCommandHandlerUtilTest, KeyCommandHandlerUtilTest_ConvertToShortcutKey_001, TestSize.Level1) 879 { 880 CALL_TEST_DEBUG; 881 cJSON *jsonData = nullptr; 882 ShortcutKey shortcutKey; 883 std::vector<std::string> businessIds; 884 bool result = OHOS::MMI::ConvertToShortcutKey(jsonData, shortcutKey, businessIds); 885 ASSERT_FALSE(result); 886 cJSON_Delete(jsonData); 887 } 888 889 /** 890 * @tc.name: KeyCommandHandlerUtilTest_ConvertToShortcutKey_002 891 * @tc.desc: Test case 2 GetBusinessId failed 892 * @tc.type: FUNC 893 * @tc.require: 894 */ 895 HWTEST_F(KeyCommandHandlerUtilTest, KeyCommandHandlerUtilTest_ConvertToShortcutKey_002, TestSize.Level1) 896 { 897 CALL_TEST_DEBUG; 898 cJSON *jsonData = cJSON_CreateObject(); 899 ShortcutKey shortcutKey; 900 std::vector<std::string> businessIds; 901 bool result = OHOS::MMI::ConvertToShortcutKey(jsonData, shortcutKey, businessIds); 902 ASSERT_FALSE(result); 903 cJSON_Delete(jsonData); 904 } 905 906 /** 907 * @tc.name: KeyCommandHandlerUtilTest_ConvertToShortcutKey_003 908 * @tc.desc: Test case 3 GetPreKeys failed 909 * @tc.type: FUNC 910 * @tc.require: 911 */ 912 HWTEST_F(KeyCommandHandlerUtilTest, KeyCommandHandlerUtilTest_ConvertToShortcutKey_003, TestSize.Level1) 913 { 914 CALL_TEST_DEBUG; 915 cJSON *jsonData = cJSON_CreateObject(); 916 cJSON_AddStringToObject(jsonData, "businessId", "test"); 917 ShortcutKey shortcutKey; 918 std::vector<std::string> businessIds; 919 bool result = OHOS::MMI::ConvertToShortcutKey(jsonData, shortcutKey, businessIds); 920 ASSERT_FALSE(result); 921 cJSON_Delete(jsonData); 922 } 923 924 /** 925 * @tc.name: KeyCommandHandlerUtilTest_ConvertToShortcutKey_004 926 * @tc.desc: Test case 4 GetKeyFinalKey failed 927 * @tc.type: FUNC 928 * @tc.require: 929 */ 930 HWTEST_F(KeyCommandHandlerUtilTest, KeyCommandHandlerUtilTest_ConvertToShortcutKey_004, TestSize.Level1) 931 { 932 CALL_TEST_DEBUG; 933 cJSON *jsonData = cJSON_CreateObject(); 934 cJSON_AddStringToObject(jsonData, "businessId", "test"); 935 cJSON* preKey = cJSON_CreateArray(); 936 cJSON_AddItemToObject(jsonData, "preKey", preKey); 937 cJSON_AddItemToArray(preKey, cJSON_CreateNumber(1)); 938 cJSON_AddItemToArray(preKey, cJSON_CreateNumber(2)); 939 cJSON_AddItemToArray(preKey, cJSON_CreateNumber(3)); 940 cJSON_AddItemToArray(preKey, cJSON_CreateNumber(4)); 941 cJSON_AddItemToObject(jsonData, "preKeys", cJSON_CreateArray()); 942 ShortcutKey shortcutKey; 943 std::vector<std::string> businessIds; 944 bool result = OHOS::MMI::ConvertToShortcutKey(jsonData, shortcutKey, businessIds); 945 ASSERT_FALSE(result); 946 cJSON_Delete(jsonData); 947 } 948 949 /** 950 * @tc.name: KeyCommandHandlerUtilTest_ConvertToShortcutKey_005 951 * @tc.desc: Test case 5 GetTrigger failed 952 * @tc.type: FUNC 953 * @tc.require: 954 */ 955 HWTEST_F(KeyCommandHandlerUtilTest, KeyCommandHandlerUtilTest_ConvertToShortcutKey_005, TestSize.Level1) 956 { 957 CALL_TEST_DEBUG; 958 cJSON *jsonData = cJSON_CreateObject(); 959 cJSON_AddStringToObject(jsonData, "businessId", "test"); 960 cJSON* preKey = cJSON_CreateArray(); 961 cJSON_AddItemToObject(jsonData, "preKey", preKey); 962 cJSON_AddItemToArray(preKey, cJSON_CreateNumber(1)); 963 cJSON_AddItemToArray(preKey, cJSON_CreateNumber(2)); 964 cJSON_AddItemToArray(preKey, cJSON_CreateNumber(3)); 965 cJSON_AddItemToArray(preKey, cJSON_CreateNumber(4)); 966 cJSON_AddItemToObject(jsonData, "preKeys", cJSON_CreateArray()); 967 cJSON_AddNumberToObject(jsonData, "finalKey", 123); 968 ShortcutKey shortcutKey; 969 std::vector<std::string> businessIds; 970 bool result = OHOS::MMI::ConvertToShortcutKey(jsonData, shortcutKey, businessIds); 971 ASSERT_FALSE(result); 972 cJSON_Delete(jsonData); 973 } 974 975 /** 976 * @tc.name: KeyCommandHandlerUtilTest_ConvertToShortcutKey_006 977 * @tc.desc: Test case 6 GetKeyDownDuration failed 978 * @tc.type: FUNC 979 * @tc.require: 980 */ 981 HWTEST_F(KeyCommandHandlerUtilTest, KeyCommandHandlerUtilTest_ConvertToShortcutKey_006, TestSize.Level1) 982 { 983 CALL_TEST_DEBUG; 984 cJSON *jsonData = cJSON_CreateObject(); 985 cJSON_AddStringToObject(jsonData, "businessId", "test"); 986 cJSON* preKey = cJSON_CreateArray(); 987 cJSON_AddItemToObject(jsonData, "preKey", preKey); 988 cJSON_AddItemToArray(preKey, cJSON_CreateNumber(1)); 989 cJSON_AddItemToArray(preKey, cJSON_CreateNumber(2)); 990 cJSON_AddItemToArray(preKey, cJSON_CreateNumber(3)); 991 cJSON_AddItemToArray(preKey, cJSON_CreateNumber(4)); 992 cJSON_AddItemToObject(jsonData, "preKeys", cJSON_CreateArray()); 993 cJSON_AddNumberToObject(jsonData, "finalKey", 123); 994 cJSON_AddStringToObject(jsonData, "trigger", "key_down"); 995 ShortcutKey shortcutKey; 996 std::vector<std::string> businessIds; 997 bool result = OHOS::MMI::ConvertToShortcutKey(jsonData, shortcutKey, businessIds); 998 ASSERT_FALSE(result); 999 cJSON_Delete(jsonData); 1000 } 1001 1002 /** 1003 * @tc.name: KeyCommandHandlerUtilTest_ConvertToShortcutKey_007 1004 * @tc.desc: Test case 7 Ability is not an object 1005 * @tc.type: FUNC 1006 * @tc.require: 1007 */ 1008 HWTEST_F(KeyCommandHandlerUtilTest, KeyCommandHandlerUtilTest_ConvertToShortcutKey_007, TestSize.Level1) 1009 { 1010 CALL_TEST_DEBUG; 1011 cJSON *jsonData = cJSON_CreateObject(); 1012 cJSON_AddStringToObject(jsonData, "businessId", "test"); 1013 cJSON* preKey = cJSON_CreateArray(); 1014 cJSON_AddItemToObject(jsonData, "preKey", preKey); 1015 cJSON_AddItemToArray(preKey, cJSON_CreateNumber(1)); 1016 cJSON_AddItemToArray(preKey, cJSON_CreateNumber(2)); 1017 cJSON_AddItemToArray(preKey, cJSON_CreateNumber(3)); 1018 cJSON_AddItemToArray(preKey, cJSON_CreateNumber(4)); 1019 cJSON_AddItemToObject(jsonData, "preKeys", cJSON_CreateArray()); 1020 cJSON_AddNumberToObject(jsonData, "finalKey", 123); 1021 cJSON_AddStringToObject(jsonData, "trigger", "key_down"); 1022 cJSON_AddNumberToObject(jsonData, "keyDownDuration", 1); 1023 cJSON_AddItemToObject(jsonData, "statusConfig", cJSON_CreateString("test")); 1024 cJSON_AddItemToObject(jsonData, "ability", cJSON_CreateString("test")); 1025 ShortcutKey shortcutKey; 1026 std::vector<std::string> businessIds; 1027 bool result = OHOS::MMI::ConvertToShortcutKey(jsonData, shortcutKey, businessIds); 1028 ASSERT_FALSE(result); 1029 cJSON_Delete(jsonData); 1030 } 1031 1032 /** 1033 * @tc.name: KeyCommandHandlerUtilTest_ConvertToShortcutKey_008 1034 * @tc.desc: Test for normal conditions 1035 * @tc.type: FUNC 1036 * @tc.require: 1037 */ 1038 HWTEST_F(KeyCommandHandlerUtilTest, KeyCommandHandlerUtilTest_ConvertToShortcutKey_008, TestSize.Level1) 1039 { 1040 CALL_TEST_DEBUG; 1041 cJSON *jsonData = cJSON_CreateObject(); 1042 cJSON_AddStringToObject(jsonData, "businessId", "test"); 1043 cJSON* preKey = cJSON_CreateArray(); 1044 cJSON_AddItemToObject(jsonData, "preKey", preKey); 1045 cJSON_AddItemToArray(preKey, cJSON_CreateNumber(1)); 1046 cJSON_AddItemToArray(preKey, cJSON_CreateNumber(2)); 1047 cJSON_AddItemToArray(preKey, cJSON_CreateNumber(3)); 1048 cJSON_AddItemToArray(preKey, cJSON_CreateNumber(4)); 1049 cJSON_AddItemToObject(jsonData, "preKeys", cJSON_CreateArray()); 1050 cJSON_AddNumberToObject(jsonData, "finalKey", 123); 1051 cJSON_AddStringToObject(jsonData, "trigger", "key_down"); 1052 cJSON_AddNumberToObject(jsonData, "keyDownDuration", 1); 1053 cJSON_AddItemToObject(jsonData, "statusConfig", cJSON_CreateString("test")); 1054 cJSON *ability = cJSON_CreateObject(); 1055 cJSON_AddItemToObject(jsonData, "ability", ability); 1056 ShortcutKey shortcutKey; 1057 std::vector<std::string> businessIds; 1058 bool result = OHOS::MMI::ConvertToShortcutKey(jsonData, shortcutKey, businessIds); 1059 ASSERT_TRUE(result); 1060 cJSON_Delete(jsonData); 1061 } 1062 1063 /** 1064 * @tc.name: KeyCommandHandlerUtilTest_GetKeyCode_001 1065 * @tc.desc: The test case jsonData is not an object 1066 * @tc.type: FUNC 1067 * @tc.require: 1068 */ 1069 HWTEST_F(KeyCommandHandlerUtilTest, KeyCommandHandlerUtilTest_GetKeyCode_001, TestSize.Level1) 1070 { 1071 CALL_TEST_DEBUG; 1072 cJSON *jsonData = nullptr; 1073 int32_t keyCodeInt; 1074 bool result = OHOS::MMI::GetKeyCode(jsonData, keyCodeInt); 1075 EXPECT_FALSE(result); 1076 cJSON_Delete(jsonData); 1077 } 1078 1079 /** 1080 * @tc.name: KeyCommandHandlerUtilTest_GetKeyCode_002 1081 * @tc.desc: Test that the value of the keyCode field is not a number 1082 * @tc.type: FUNC 1083 * @tc.require: 1084 */ 1085 HWTEST_F(KeyCommandHandlerUtilTest, KeyCommandHandlerUtilTest_GetKeyCode_002, TestSize.Level1) 1086 { 1087 CALL_TEST_DEBUG; 1088 const char* jsonStr = "{\"otherKey\": \"value\"}"; 1089 cJSON *jsonData = cJSON_Parse(jsonStr); 1090 int32_t keyCodeInt; 1091 bool result = OHOS::MMI::GetKeyCode(jsonData, keyCodeInt); 1092 EXPECT_FALSE(result); 1093 cJSON_Delete(jsonData); 1094 } 1095 1096 /** 1097 * @tc.name: KeyCommandHandlerUtilTest_GetKeyCode_003 1098 * @tc.desc: The value of the test keyCode field is negative 1099 * @tc.type: FUNC 1100 * @tc.require: 1101 */ 1102 HWTEST_F(KeyCommandHandlerUtilTest, KeyCommandHandlerUtilTest_GetKeyCode_003, TestSize.Level1) 1103 { 1104 CALL_TEST_DEBUG; 1105 const char* jsonStr = "{\"keyCode\": -123}"; 1106 cJSON *jsonData = cJSON_Parse(jsonStr); 1107 int32_t keyCodeInt; 1108 bool result = OHOS::MMI::GetKeyCode(jsonData, keyCodeInt); 1109 EXPECT_FALSE(result); 1110 cJSON_Delete(jsonData); 1111 } 1112 1113 /** 1114 * @tc.name: KeyCommandHandlerUtilTest_GetKeyCode_004 1115 * @tc.desc: Test for normal conditions 1116 * @tc.type: FUNC 1117 * @tc.require: 1118 */ 1119 HWTEST_F(KeyCommandHandlerUtilTest, KeyCommandHandlerUtilTest_GetKeyCode_004, TestSize.Level1) 1120 { 1121 CALL_TEST_DEBUG; 1122 const char* jsonStr = "{\"keyCode\": 123}"; 1123 cJSON *jsonData = cJSON_Parse(jsonStr); 1124 int32_t keyCodeInt; 1125 bool result = OHOS::MMI::GetKeyCode(jsonData, keyCodeInt); 1126 EXPECT_TRUE(result); 1127 EXPECT_EQ(keyCodeInt, 123); 1128 cJSON_Delete(jsonData); 1129 } 1130 1131 /** 1132 * @tc.name: KeyCommandHandlerUtilTest_GetKeyAction_001 1133 * @tc.desc: The test case jsonData is not an object 1134 * @tc.type: FUNC 1135 * @tc.require: 1136 */ 1137 HWTEST_F(KeyCommandHandlerUtilTest, KeyCommandHandlerUtilTest_GetKeyAction_001, TestSize.Level1) 1138 { 1139 CALL_TEST_DEBUG; 1140 const cJSON* jsonData = nullptr; 1141 int32_t keyActionInt; 1142 EXPECT_FALSE(OHOS::MMI::GetKeyAction(jsonData, keyActionInt)); 1143 } 1144 1145 /** 1146 * @tc.name: KeyCommandHandlerUtilTest_GetKeyAction_002 1147 * @tc.desc: The value of the test keyAction field is not a number 1148 * @tc.type: FUNC 1149 * @tc.require: 1150 */ 1151 HWTEST_F(KeyCommandHandlerUtilTest, KeyCommandHandlerUtilTest_GetKeyAction_002, TestSize.Level1) 1152 { 1153 CALL_TEST_DEBUG; 1154 cJSON* jsonData = cJSON_CreateObject(); 1155 cJSON_AddItemToObject(jsonData, "keyAction", cJSON_CreateString("down")); 1156 int32_t keyActionInt; 1157 EXPECT_FALSE(OHOS::MMI::GetKeyAction(jsonData, keyActionInt)); 1158 cJSON_Delete(jsonData); 1159 } 1160 1161 /** 1162 * @tc.name: KeyCommandHandlerUtilTest_GetKeyAction_003 1163 * @tc.desc: The value of the Test Caiaction field is 999 1164 * @tc.type: FUNC 1165 * @tc.require: 1166 */ 1167 HWTEST_F(KeyCommandHandlerUtilTest, KeyCommandHandlerUtilTest_GetKeyAction_003, TestSize.Level1) 1168 { 1169 CALL_TEST_DEBUG; 1170 cJSON* jsonData = cJSON_CreateObject(); 1171 cJSON_AddNumberToObject(jsonData, "keyAction", 999); 1172 int32_t keyActionInt; 1173 EXPECT_FALSE(OHOS::MMI::GetKeyAction(jsonData, keyActionInt)); 1174 cJSON_Delete(jsonData); 1175 } 1176 1177 /** 1178 * @tc.name: KeyCommandHandlerUtilTest_GetKeyAction_004 1179 * @tc.desc: Test for normal conditions 1180 * @tc.type: FUNC 1181 * @tc.require: 1182 */ 1183 HWTEST_F(KeyCommandHandlerUtilTest, KeyCommandHandlerUtilTest_GetKeyAction_004, TestSize.Level1) 1184 { 1185 CALL_TEST_DEBUG; 1186 cJSON* jsonData = cJSON_CreateObject(); 1187 cJSON_AddNumberToObject(jsonData, "keyAction", KeyEvent::KEY_ACTION_DOWN); 1188 int32_t keyActionInt; 1189 EXPECT_TRUE(OHOS::MMI::GetKeyAction(jsonData, keyActionInt)); 1190 EXPECT_EQ(keyActionInt, KeyEvent::KEY_ACTION_DOWN); 1191 cJSON_Delete(jsonData); 1192 } 1193 1194 /** 1195 * @tc.name: KeyCommandHandlerUtilTest_GetDelay_001 1196 * @tc.desc: Tests when jsonData is not an object 1197 * @tc.type: FUNC 1198 * @tc.require: 1199 */ 1200 HWTEST_F(KeyCommandHandlerUtilTest, KeyCommandHandlerUtilTest_GetDelay_001, TestSize.Level1) 1201 { 1202 CALL_TEST_DEBUG; 1203 cJSON* jsonData = nullptr; 1204 int64_t delayInt = 1; 1205 EXPECT_FALSE(OHOS::MMI::GetDelay(jsonData, delayInt)); 1206 } 1207 1208 /** 1209 * @tc.name: KeyCommandHandlerUtilTest_GetDelay_002 1210 * @tc.desc: Tests the condition when the delay entry is present but not numeric 1211 * @tc.type: FUNC 1212 * @tc.require: 1213 */ 1214 HWTEST_F(KeyCommandHandlerUtilTest, KeyCommandHandlerUtilTest_GetDelay_002, TestSize.Level1) 1215 { 1216 CALL_TEST_DEBUG; 1217 cJSON* jsonData = cJSON_CreateObject(); 1218 cJSON_AddItemToObject(jsonData, "delay", cJSON_CreateString("not a number")); 1219 int64_t delayInt = 1; 1220 EXPECT_FALSE(OHOS::MMI::GetDelay(jsonData, delayInt)); 1221 cJSON_Delete(jsonData); 1222 } 1223 1224 /** 1225 * @tc.name: KeyCommandHandlerUtilTest_GetDelay_003 1226 * @tc.desc: Tests the case when the delay term is a negative number 1227 * @tc.type: FUNC 1228 * @tc.require: 1229 */ 1230 HWTEST_F(KeyCommandHandlerUtilTest, KeyCommandHandlerUtilTest_GetDelay_003, TestSize.Level1) 1231 { 1232 CALL_TEST_DEBUG; 1233 cJSON* jsonData = cJSON_CreateObject(); 1234 cJSON_AddNumberToObject(jsonData, "delay", -1); 1235 int64_t delayInt = 1; 1236 EXPECT_FALSE(OHOS::MMI::GetDelay(jsonData, delayInt)); 1237 cJSON_Delete(jsonData); 1238 } 1239 1240 /** 1241 * @tc.name: KeyCommandHandlerUtilTest_GetDelay_004 1242 * @tc.desc: Test the condition when all conditions are met 1243 * @tc.type: FUNC 1244 * @tc.require: 1245 */ 1246 HWTEST_F(KeyCommandHandlerUtilTest, KeyCommandHandlerUtilTest_GetDelay_004, TestSize.Level1) 1247 { 1248 CALL_TEST_DEBUG; 1249 cJSON* jsonData = cJSON_CreateObject(); 1250 cJSON_AddNumberToObject(jsonData, "delay", 10); 1251 int64_t delayInt = 1; 1252 EXPECT_TRUE(OHOS::MMI::GetDelay(jsonData, delayInt)); 1253 EXPECT_EQ(delayInt, 10 * SECONDS_SYSTEM); 1254 cJSON_Delete(jsonData); 1255 } 1256 1257 /** 1258 * @tc.name: KeyCommandHandlerUtilTest_GetRepeatTimes_001 1259 * @tc.desc: Tests when jsonData is not an object 1260 * @tc.type: FUNC 1261 * @tc.require: 1262 */ 1263 HWTEST_F(KeyCommandHandlerUtilTest, KeyCommandHandlerUtilTest_GetRepeatTimes_001, TestSize.Level1) 1264 { 1265 CALL_TEST_DEBUG; 1266 int32_t repeatTimesInt = 1; 1267 EXPECT_FALSE(OHOS::MMI::GetRepeatTimes(nullptr, repeatTimesInt)); 1268 } 1269 1270 /** 1271 * @tc.name: KeyCommandHandlerUtilTest_GetRepeatTimes_002 1272 * @tc.desc: Tests the case when the delay term is a negative number 1273 * @tc.type: FUNC 1274 * @tc.require: 1275 */ 1276 HWTEST_F(KeyCommandHandlerUtilTest, KeyCommandHandlerUtilTest_GetRepeatTimes_002, TestSize.Level1) 1277 { 1278 CALL_TEST_DEBUG; 1279 cJSON *jsonData = cJSON_CreateObject(); 1280 cJSON_AddItemToObject(jsonData, "times", cJSON_CreateString("not a number")); 1281 int32_t repeatTimesInt = 1; 1282 EXPECT_FALSE(OHOS::MMI::GetRepeatTimes(jsonData, repeatTimesInt)); 1283 cJSON_Delete(jsonData); 1284 } 1285 1286 /** 1287 * @tc.name: KeyCommandHandlerUtilTest_GetRepeatTimes_003 1288 * @tc.desc: Test the case when the timers entry is a negative number 1289 * @tc.type: FUNC 1290 * @tc.require: 1291 */ 1292 HWTEST_F(KeyCommandHandlerUtilTest, KeyCommandHandlerUtilTest_GetRepeatTimes_003, TestSize.Level1) 1293 { 1294 CALL_TEST_DEBUG; 1295 cJSON *jsonData = cJSON_CreateObject(); 1296 cJSON_AddItemToObject(jsonData, "times", cJSON_CreateNumber(-1)); 1297 int32_t repeatTimesInt = 1; 1298 EXPECT_FALSE(OHOS::MMI::GetRepeatTimes(jsonData, repeatTimesInt)); 1299 cJSON_Delete(jsonData); 1300 } 1301 1302 /** 1303 * @tc.name: KeyCommandHandlerUtilTest_GetRepeatTimes_004 1304 * @tc.desc: Test the condition when all conditions are met 1305 * @tc.type: FUNC 1306 * @tc.require: 1307 */ 1308 HWTEST_F(KeyCommandHandlerUtilTest, KeyCommandHandlerUtilTest_GetRepeatTimes_004, TestSize.Level1) 1309 { 1310 CALL_TEST_DEBUG; 1311 cJSON *jsonData = cJSON_CreateObject(); 1312 cJSON_AddItemToObject(jsonData, "times", cJSON_CreateNumber(1)); 1313 int32_t repeatTimesInt = 1; 1314 EXPECT_TRUE(OHOS::MMI::GetRepeatTimes(jsonData, repeatTimesInt)); 1315 EXPECT_EQ(repeatTimesInt, 1); 1316 cJSON_Delete(jsonData); 1317 } 1318 1319 /** 1320 * @tc.name: KeyCommandHandlerUtilTest_GetAbilityStartDelay_001 1321 * @tc.desc: Tests when jsonData is not an object 1322 * @tc.type: FUNC 1323 * @tc.require: 1324 */ 1325 HWTEST_F(KeyCommandHandlerUtilTest, KeyCommandHandlerUtilTest_GetAbilityStartDelay_001, TestSize.Level1) 1326 { 1327 CALL_TEST_DEBUG; 1328 int64_t delay = 1; 1329 EXPECT_FALSE(OHOS::MMI::GetAbilityStartDelay(nullptr, delay)); 1330 } 1331 1332 /** 1333 * @tc.name: KeyCommandHandlerUtilTest_GetAbilityStartDelay_002 1334 * @tc.desc: Tests the value of the abilityStartDela field is not a number 1335 * @tc.type: FUNC 1336 * @tc.require: 1337 */ 1338 HWTEST_F(KeyCommandHandlerUtilTest, KeyCommandHandlerUtilTest_GetAbilityStartDelay_002, TestSize.Level1) 1339 { 1340 CALL_TEST_DEBUG; 1341 cJSON *jsonData = cJSON_CreateObject(); 1342 cJSON_AddItemToObject(jsonData, "abilityStartDelay", cJSON_CreateString("not a number")); 1343 int64_t delay = 1; 1344 EXPECT_FALSE(OHOS::MMI::GetAbilityStartDelay(jsonData, delay)); 1345 cJSON_Delete(jsonData); 1346 } 1347 1348 /** 1349 * @tc.name: KeyCommandHandlerUtilTest_GetAbilityStartDelay_003 1350 * @tc.desc: Test the case when the abilityStartDelay entry is a negative number 1351 * @tc.type: FUNC 1352 * @tc.require: 1353 */ 1354 HWTEST_F(KeyCommandHandlerUtilTest, KeyCommandHandlerUtilTest_GetAbilityStartDelay_003, TestSize.Level1) 1355 { 1356 CALL_TEST_DEBUG; 1357 cJSON *jsonData = cJSON_CreateObject(); 1358 cJSON_AddItemToObject(jsonData, "abilityStartDelay", cJSON_CreateNumber(-1)); 1359 int64_t delay = 1; 1360 EXPECT_FALSE(OHOS::MMI::GetAbilityStartDelay(jsonData, delay)); 1361 cJSON_Delete(jsonData); 1362 } 1363 1364 /** 1365 * @tc.name: KeyCommandHandlerUtilTest_GetAbilityStartDelay_004 1366 * @tc.desc: Test the condition when all conditions are met 1367 * @tc.type: FUNC 1368 * @tc.require: 1369 */ 1370 HWTEST_F(KeyCommandHandlerUtilTest, KeyCommandHandlerUtilTest_GetAbilityStartDelay_004, TestSize.Level1) 1371 { 1372 CALL_TEST_DEBUG; 1373 cJSON *jsonData = cJSON_CreateObject(); 1374 cJSON_AddItemToObject(jsonData, "abilityStartDelay", cJSON_CreateNumber(10)); 1375 int64_t delay = 1; 1376 EXPECT_TRUE(OHOS::MMI::GetAbilityStartDelay(jsonData, delay)); 1377 EXPECT_EQ(delay, 10); 1378 cJSON_Delete(jsonData); 1379 } 1380 1381 /** 1382 * @tc.name: KeyCommandHandlerUtilTest_PackageSequenceKey_001 1383 * @tc.desc: Tests when jsonData is not an object 1384 * @tc.type: FUNC 1385 * @tc.require: 1386 */ 1387 HWTEST_F(KeyCommandHandlerUtilTest, KeyCommandHandlerUtilTest_PackageSequenceKey_001, TestSize.Level1) 1388 { 1389 CALL_TEST_DEBUG; 1390 cJSON* json = nullptr; 1391 SequenceKey sequenceKey; 1392 bool result = OHOS::MMI::PackageSequenceKey(json, sequenceKey); 1393 EXPECT_FALSE(result); 1394 cJSON_Delete(json); 1395 } 1396 1397 /** 1398 * @tc.name: KeyCommandHandlerUtilTest_PackageSequenceKey_002 1399 * @tc.desc: Tests get keyCode failed 1400 * @tc.type: FUNC 1401 * @tc.require: 1402 */ 1403 HWTEST_F(KeyCommandHandlerUtilTest, KeyCommandHandlerUtilTest_PackageSequenceKey_002, TestSize.Level1) 1404 { 1405 CALL_TEST_DEBUG; 1406 const char* jsonStr = "{\"otherKey\": \"value\"}"; 1407 cJSON *json = cJSON_Parse(jsonStr); 1408 SequenceKey sequenceKey; 1409 bool result = OHOS::MMI::PackageSequenceKey(json, sequenceKey); 1410 EXPECT_FALSE(result); 1411 cJSON_Delete(json); 1412 } 1413 1414 /** 1415 * @tc.name: KeyCommandHandlerUtilTest_PackageSequenceKey_003 1416 * @tc.desc: Tests get keyAction failed 1417 * @tc.type: FUNC 1418 * @tc.require: 1419 */ 1420 HWTEST_F(KeyCommandHandlerUtilTest, KeyCommandHandlerUtilTest_PackageSequenceKey_003, TestSize.Level1) 1421 { 1422 CALL_TEST_DEBUG; 1423 const char* jsonStr = "{\"keyCode\": 123}"; 1424 cJSON *jsonData = cJSON_Parse(jsonStr); 1425 SequenceKey sequenceKey; 1426 bool result = OHOS::MMI::PackageSequenceKey(jsonData, sequenceKey); 1427 EXPECT_FALSE(result); 1428 cJSON_Delete(jsonData); 1429 } 1430 1431 /** 1432 * @tc.name: KeyCommandHandlerUtilTest_GetSequenceKeys_001 1433 * @tc.desc: Tests when jsonData is not an object 1434 * @tc.type: FUNC 1435 * @tc.require: 1436 */ 1437 HWTEST_F(KeyCommandHandlerUtilTest, KeyCommandHandlerUtilTest_GetSequenceKeys_001, TestSize.Level1) 1438 { 1439 CALL_TEST_DEBUG; 1440 cJSON* jsonData = nullptr; 1441 Sequence sequence; 1442 bool result = OHOS::MMI::GetSequenceKeys(jsonData, sequence); 1443 EXPECT_FALSE(result); 1444 cJSON_Delete(jsonData); 1445 } 1446 1447 /** 1448 * @tc.name: KeyCommandHandlerUtilTest_GetSequenceKeys_002 1449 * @tc.desc: Tests sequenceKeys number must be array 1450 * @tc.type: FUNC 1451 * @tc.require: 1452 */ 1453 HWTEST_F(KeyCommandHandlerUtilTest, KeyCommandHandlerUtilTest_GetSequenceKeys_002, TestSize.Level1) 1454 { 1455 CALL_TEST_DEBUG; 1456 cJSON* jsonData = cJSON_CreateObject(); 1457 cJSON_AddItemToObject(jsonData, "sequenceKeys", cJSON_CreateString("invalid")); 1458 Sequence sequence; 1459 bool result = OHOS::MMI::GetSequenceKeys(jsonData, sequence); 1460 EXPECT_FALSE(result); 1461 cJSON_Delete(jsonData); 1462 } 1463 1464 /** 1465 * @tc.name: KeyCommandHandlerUtilTest_GetSequenceKeys_003 1466 * @tc.desc: Tests sequenceKeysSize number must less 1467 * @tc.type: FUNC 1468 * @tc.require: 1469 */ 1470 HWTEST_F(KeyCommandHandlerUtilTest, KeyCommandHandlerUtilTest_GetSequenceKeys_003, TestSize.Level1) 1471 { 1472 CALL_TEST_DEBUG; 1473 cJSON* jsonData = cJSON_CreateObject(); 1474 cJSON* sequenceKeys = cJSON_CreateArray(); 1475 for (int i = 0; i <= MAX_SEQUENCEKEYS_NUM; ++i) { 1476 cJSON* sequenceKeyJson = cJSON_CreateObject(); 1477 cJSON_AddItemToObject(sequenceKeyJson, "key", cJSON_CreateString("key")); 1478 cJSON_AddItemToArray(sequenceKeys, sequenceKeyJson); 1479 } 1480 cJSON_AddItemToObject(jsonData, "sequenceKeys", sequenceKeys); 1481 Sequence sequence; 1482 bool result = OHOS::MMI::GetSequenceKeys(jsonData, sequence); 1483 EXPECT_FALSE(result); 1484 cJSON_Delete(jsonData); 1485 } 1486 1487 /** 1488 * @tc.name: KeyCommandHandlerUtilTest_GetSequenceKeys_004 1489 * @tc.desc: Tests packege sequenceKey failed 1490 * @tc.type: FUNC 1491 * @tc.require: 1492 */ 1493 HWTEST_F(KeyCommandHandlerUtilTest, KeyCommandHandlerUtilTest_GetSequenceKeys_004, TestSize.Level1) 1494 { 1495 CALL_TEST_DEBUG; 1496 cJSON* jsonData = cJSON_CreateObject(); 1497 cJSON* sequenceKeys = cJSON_CreateArray(); 1498 for (int i = 0; i < MAX_SEQUENCEKEYS_NUM; ++i) { 1499 cJSON* sequenceKeyJson = cJSON_CreateObject(); 1500 cJSON_AddItemToObject(sequenceKeyJson, "key", cJSON_CreateString("key")); 1501 cJSON_AddItemToArray(sequenceKeys, sequenceKeyJson); 1502 } 1503 cJSON_AddItemToObject(jsonData, "sequenceKeys", sequenceKeys); 1504 Sequence sequence; 1505 bool result = OHOS::MMI::GetSequenceKeys(jsonData, sequence); 1506 EXPECT_FALSE(result); 1507 cJSON_Delete(jsonData); 1508 } 1509 1510 /** 1511 * @tc.name: KeyCommandHandlerUtilTest_IsSequenceKeysValid_001 1512 * @tc.desc: Test case check when sequenceKeys is empty 1513 * @tc.type: FUNC 1514 * @tc.require: 1515 */ 1516 HWTEST_F(KeyCommandHandlerUtilTest, KeyCommandHandlerUtilTest_IsSequenceKeysValid_001, TestSize.Level1) 1517 { 1518 CALL_TEST_DEBUG; 1519 Sequence sequence; 1520 sequence.sequenceKeys = {}; 1521 EXPECT_FALSE(OHOS::MMI::IsSequenceKeysValid(sequence)); 1522 } 1523 1524 /** 1525 * @tc.name: KeyCommandHandlerUtilTest_IsSequenceKeysValid_002 1526 * @tc.desc: Test cases check when the size of sequenceKeys exceeds the maximum limit 1527 * @tc.type: FUNC 1528 * @tc.require: 1529 */ 1530 HWTEST_F(KeyCommandHandlerUtilTest, KeyCommandHandlerUtilTest_IsSequenceKeysValid_002, TestSize.Level1) 1531 { 1532 CALL_TEST_DEBUG; 1533 Sequence sequence; 1534 sequence.sequenceKeys.resize(MAX_SEQUENCEKEYS_NUM + 1); 1535 EXPECT_FALSE(OHOS::MMI::IsSequenceKeysValid(sequence)); 1536 } 1537 1538 /** 1539 * @tc.name: KeyCommandHandlerUtilTest_IsSequenceKeysValid_003 1540 * @tc.desc: Test cases check when there are duplicate keys in sequenceKeys 1541 * @tc.type: FUNC 1542 * @tc.require: 1543 */ 1544 HWTEST_F(KeyCommandHandlerUtilTest, KeyCommandHandlerUtilTest_IsSequenceKeysValid_003, TestSize.Level1) 1545 { 1546 CALL_TEST_DEBUG; 1547 Sequence sequence; 1548 SequenceKey key1; 1549 key1.keyCode = 1; 1550 key1.delay = 0; 1551 sequence.sequenceKeys.push_back(key1); 1552 SequenceKey key2; 1553 key2.keyCode = 1; 1554 key2.delay = 0; 1555 sequence.sequenceKeys.push_back(key2); 1556 EXPECT_FALSE(IsSequenceKeysValid(sequence)); 1557 } 1558 1559 /** 1560 * @tc.name: KeyCommandHandlerUtilTest_IsSequenceKeysValid_004 1561 * @tc.desc: Test cases check when sequenceKeys are valid 1562 * @tc.type: FUNC 1563 * @tc.require: 1564 */ 1565 HWTEST_F(KeyCommandHandlerUtilTest, KeyCommandHandlerUtilTest_IsSequenceKeysValid_004, TestSize.Level1) 1566 { 1567 CALL_TEST_DEBUG; 1568 Sequence sequence; 1569 SequenceKey key1; 1570 key1.keyCode = 1; 1571 key1.delay = 0; 1572 sequence.sequenceKeys.push_back(key1); 1573 SequenceKey key2; 1574 key2.keyCode = 2; 1575 key2.delay = 0; 1576 sequence.sequenceKeys.push_back(key2); 1577 EXPECT_TRUE(OHOS::MMI::IsSequenceKeysValid(sequence)); 1578 } 1579 1580 /** 1581 * @tc.name: KeyCommandHandlerUtilTest_ConvertToKeySequence_001 1582 * @tc.desc: Tests when jsonData is not an object 1583 * @tc.type: FUNC 1584 * @tc.require: 1585 */ 1586 HWTEST_F(KeyCommandHandlerUtilTest, KeyCommandHandlerUtilTest_ConvertToKeySequence_001, TestSize.Level1) 1587 { 1588 CALL_TEST_DEBUG; 1589 cJSON* jsonData = nullptr; 1590 Sequence sequence; 1591 EXPECT_FALSE(OHOS::MMI::ConvertToKeySequence(jsonData, sequence)); 1592 cJSON_Delete(jsonData); 1593 } 1594 1595 /** 1596 * @tc.name: KeyCommandHandlerUtilTest_ConvertToKeySequence_002 1597 * @tc.desc: Tests Get sequenceKeys failed 1598 * @tc.type: FUNC 1599 * @tc.require: 1600 */ 1601 HWTEST_F(KeyCommandHandlerUtilTest, KeyCommandHandlerUtilTest_ConvertToKeySequence_002, TestSize.Level1) 1602 { 1603 CALL_TEST_DEBUG; 1604 cJSON* jsonData = cJSON_CreateObject(); 1605 Sequence sequence; 1606 cJSON_AddItemToObject(jsonData, "sequenceKeys", cJSON_CreateString("invalid")); 1607 EXPECT_FALSE(OHOS::MMI::ConvertToKeySequence(jsonData, sequence)); 1608 cJSON_Delete(jsonData); 1609 } 1610 } // namespace MMI 1611 } // namespace OHOS