1/* 2 * Copyright (C) 2021 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 16import runningLock from '@ohos.runningLock' 17import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect, TestType, Size, Level } from '@ohos/hypium'; 18 19export default function RunningLockTest() { 20 describe('RunningLockTest', function () { 21 /** 22 * @tc.number SUB_PowerSystem_RunningLock_JSTest_0010 23 * @tc.name testRunning_Lock_Lock_JSTest0010 24 * @tc.desc Prevents the system from hibernating and sets the lock duration (deprecated since 9) 25 * @tc.level: Level 1 26 * @tc.type: Functiontion 27 * @tc.size: MediumTest 28 */ 29 it('Running_Lock_Lock_JSTest0010', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL1, async function (done) { 30 await runningLock.createRunningLock("Running_Lock_Lock_JSTest0010", runningLock.RunningLockType.BACKGROUND) 31 .then(runninglock => { 32 expect(runninglock !== null).assertTrue(); 33 let used = runninglock.isUsed(); 34 console.info('Running_Lock_Lock_JSTest0010 is used: ' + used); 35 expect(used).assertFalse(); 36 runninglock.lock(500); 37 used = runninglock.isUsed(); 38 console.info('after lock Running_Lock_Lock_JSTest0010 is used: ' + used); 39 expect(used).assertTrue(); 40 done(); 41 }) 42 .catch(error => { 43 console.log('Running_Lock_Lock_JSTest0010 error: ' + error); 44 expect().assertFail(); 45 done(); 46 }) 47 }) 48 49 /** 50 * @tc.number SUB_PowerSystem_RunningLock_JSTest_0020 51 * @tc.name testRunning_Lock_used_JSTest0020 52 * @tc.desc Checks whether a lock is held or in use (deprecated since 9) 53 * @tc.level: Level 1 54 * @tc.type: Functiontion 55 * @tc.size: MediumTest 56 */ 57 it('Running_Lock_used_JSTest0020', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL1, async function (done) { 58 await runningLock.createRunningLock("Running_Lock_used_JSTest0020", runningLock.RunningLockType.BACKGROUND) 59 .then(runninglock => { 60 expect(runninglock !== null).assertTrue(); 61 let used = runninglock.isUsed(); 62 console.info('Running_Lock_used_JSTest0020 used: ' + used); 63 expect(used).assertFalse(); 64 console.info('Running_Lock_used_JSTest0020 success'); 65 done(); 66 }) 67 .catch(error => { 68 console.log('Running_Lock_used_JSTest0020 error: ' + error); 69 expect().assertFail(); 70 done(); 71 }) 72 }) 73 74 /** 75 * @tc.number SUB_PowerSystem_RunningLock_JSTest_0030 76 * @tc.name testRunning_Lock_Unlock_JSTest0030 77 * @tc.desc Release running lock (deprecated since 9) 78 * @tc.level: Level 1 79 * @tc.type: Functiontion 80 * @tc.size: MediumTest 81 */ 82 it('Running_Lock_Unlock_JSTest0030', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL1, async function (done) { 83 await runningLock.createRunningLock("Running_Lock_Unlock_JSTest0030", 84 runningLock.RunningLockType.BACKGROUND) 85 .then(runninglock => { 86 expect(runninglock !== null).assertTrue(); 87 let used = runninglock.isUsed(); 88 console.info('Running_Lock_Unlock_JSTest0030 is used: ' + used); 89 expect(used).assertFalse(); 90 runninglock.lock(500); 91 used = runninglock.isUsed(); 92 console.info('after lock Running_Lock_Unlock_JSTest0030 is used: ' + used); 93 expect(used).assertTrue(); 94 runninglock.unlock(); 95 used = runninglock.isUsed(); 96 console.info('after unlock Running_Lock_Unlock_JSTest0030 is used: ' + used); 97 expect(used).assertFalse(); 98 console.info('Running_Lock_Unlock_JSTest0030 success'); 99 done(); 100 }) 101 .catch(error => { 102 console.log('Running_Lock_Unlock_JSTest0030 error: ' + error); 103 expect().assertFail(); 104 done(); 105 }) 106 }) 107 108 /** 109 * @tc.number SUB_PowerSystem_RunningLock_JSTest_0040 110 * @tc.name testRunning_Lock_Hold_IsHolding_UnHold_JSTest0040 111 * @tc.desc hold lock, is holding , unhold 112 * @tc.level: Level 3 113 * @tc.type: Functiontion 114 * @tc.size: MediumTest 115 */ 116 it('Running_Lock_Hold_IsHolding_UnHold_JSTest0040', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL3, async function (done) { 117 try { 118 let isExec = false; 119 await runningLock.create("Running_Lock_Hold_IsHolding_UnHold_JSTest0040", 120 runningLock.RunningLockType.BACKGROUND) 121 .then((runninglock) => { 122 isExec = true; 123 expect(runninglock !== null).assertTrue(); 124 let holding = runninglock.isHolding(); 125 console.info('Running_Lock_Hold_IsHolding_UnHold_JSTest0040 holding false:' + holding); 126 expect(holding).assertFalse(); 127 runninglock.hold(1000); // hold 1000ms 128 holding = runninglock.isHolding(); 129 console.info('Running_Lock_Hold_IsHolding_UnHold_JSTest0040 holding true:' + holding); 130 expect(holding).assertTrue(); 131 runninglock.unhold(); 132 expect(runninglock.isHolding()).assertFalse(); 133 done(); 134 }) 135 .catch((error) => { 136 isExec = true; 137 console.info('Running_Lock_Hold_IsHolding_UnHold_JSTest0040 error:' + (typeof error)); 138 expect(typeof error !== "undefined").assertTrue(); 139 console.info('Running_Lock_Hold_IsHolding_UnHold_JSTest0040 error code:' + error.code + 140 " msg: " + error.message); 141 done(); 142 }) 143 .finally(() => { 144 expect(isExec).assertTrue(); 145 done(); 146 }) 147 } catch (e) { 148 console.info('Running_Lock_Hold_IsHolding_UnHold_JSTest0040 error:' + e); 149 expect().assertFail(); 150 done(); 151 } 152 }) 153 154 /** 155 * @tc.number SUB_PowerSystem_RunningLock_JSTest_0050 156 * @tc.name testRunning_Lock_IsHolding_UnHold_JSTest0050 157 * @tc.desc hold lock, is holding , unhold 158 * @tc.level: Level 3 159 * @tc.type: Functiontion 160 * @tc.size: MediumTest 161 */ 162 it('Running_Lock_IsHolding_UnHold_JSTest0050', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL3, async function (done) { 163 try { 164 let isExec = false; 165 await runningLock.create("Running_Lock_IsHolding_UnHold_JSTest0050", 166 runningLock.RunningLockType.PROXIMITY_SCREEN_CONTROL) 167 .then((runninglock) => { 168 isExec = true; 169 expect(runninglock !== null).assertTrue(); 170 let holding = runninglock.isHolding(); 171 console.info('Running_Lock_IsHolding_UnHold_JSTest0050 holding false:' + holding); 172 expect(holding).assertFalse(); 173 runninglock.unhold(); 174 expect(runninglock.isHolding()).assertFalse(); 175 done(); 176 }) 177 .catch((error) => { 178 isExec = true; 179 console.info('Running_Lock_IsHolding_UnHold_JSTest0050 error:' + (typeof error)); 180 expect(typeof error !== "undefined").assertTrue(); 181 console.info('Running_Lock_IsHolding_UnHold_JSTest0050 error code:' + error.code + " msg: " + 182 error.message); 183 done(); 184 }) 185 .finally(() => { 186 expect(isExec).assertTrue(); 187 done(); 188 }) 189 } catch (e) { 190 console.info('Running_Lock_IsHolding_UnHold_JSTest0050 error:' + e); 191 expect().assertFail(); 192 done(); 193 } 194 }) 195 196 /** 197 * @tc.number SUB_PowerSystem_RunningLock_JSTest_0060 198 * @tc.name testRunning_Lock_Hold_IsHolding_UnHold_JSTest0060 199 * @tc.desc hold lock, is holding , unhold 200 * @tc.level: Level 3 201 * @tc.type: Functiontion 202 * @tc.size: MediumTest 203 */ 204 it('Running_Lock_Hold_IsHolding_UnHold_JSTest0060', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL3, async function (done) { 205 try { 206 let isExec = false; 207 await runningLock.create("Running_Lock_Hold_IsHolding_UnHold_JSTest0060", 208 runningLock.RunningLockType.PROXIMITY_SCREEN_CONTROL) 209 .then((runninglock) => { 210 isExec = true; 211 expect(runninglock !== null).assertTrue(); 212 let holding = runninglock.isHolding(); 213 console.info('Running_Lock_Hold_IsHolding_UnHold_JSTest0060 holding false:' + holding); 214 expect(holding).assertFalse(); 215 runninglock.hold(-1); 216 holding = runninglock.isHolding(); 217 console.info('Running_Lock_Hold_IsHolding_UnHold_JSTest0060 holding true:' + holding); 218 expect(holding).assertTrue(); 219 runninglock.unhold(); 220 expect(runninglock.isHolding()).assertFalse(); 221 done(); 222 }) 223 .catch((error) => { 224 isExec = true; 225 console.info('Running_Lock_Hold_IsHolding_UnHold_JSTest0060 error:' + (typeof error)); 226 expect(typeof error !== "undefined").assertTrue(); 227 console.info('Running_Lock_Hold_IsHolding_UnHold_JSTest0060 error code:' + error.code + 228 " msg: " + error.message); 229 done(); 230 }) 231 .finally(() => { 232 expect(isExec).assertTrue(); 233 done(); 234 }) 235 } catch (e) { 236 console.info('Running_Lock_Hold_IsHolding_UnHold_JSTest0060 error:' + e); 237 expect().assertFail(); 238 done(); 239 } 240 }) 241 242 /** 243 * @tc.number SUB_PowerSystem_RunningLock_JSTest_0061 244 * @tc.name testRunning_Lock_Hold_IsHolding_UnHold_JSTest0061 245 * @tc.desc hold lock, is holding 246 * @tc.level: Level 3 247 * @tc.type: Function 248 * @tc.size: MediumTest 249 */ 250 it('Running_Lock_Hold_IsHolding_UnHold_JSTest0061', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL3, async function (done) { 251 let TAG = 'Running_Lock_Hold_IsHolding_UnHold_JSTest0061'; 252 try { 253 runningLock.create(TAG, runningLock.RunningLockType.PROXIMITY_SCREEN_CONTROL) 254 .then((lock) => { 255 expect(lock).not().assertUndefined(); 256 let holding = lock.isHolding(); 257 console.info(`${TAG} holding: ${holding}`); 258 expect(holding).assertFalse(); 259 lock.hold('hold'); 260 let isHolding = lock.isHolding(); 261 console.info(`${TAG} isHolding: ${isHolding}`); 262 expect(isHolding).assertFalse(); 263 done(); 264 }) 265 .catch((error) => { 266 console.error(`${TAG} error: ${error.code} ${error.message}`); 267 expect(error.code).assertEqual(401); 268 done(); 269 }) 270 .finally(() => { 271 console.info(`${TAG} finally`); 272 done(); 273 }) 274 } catch (e) { 275 console.error(`${TAG} error: ${e.code} ${e.message}`); 276 expect(e.code).assertEqual(401); 277 done(); 278 } 279 }) 280 281 /** 282 * @tc.number SUB_PowerSystem_RunningLock_JSTest_0062 283 * @tc.name testRunning_Lock_Hold_IsHolding_UnHold_JSTest0062 284 * @tc.desc hold lock, is holding 285 * @tc.level: Level 3 286 * @tc.type: Function 287 * @tc.size: MediumTest 288 */ 289 it('Running_Lock_Hold_IsHolding_UnHold_JSTest0062', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL3, async function (done) { 290 let TAG = 'Running_Lock_Hold_IsHolding_UnHold_JSTest0062'; 291 try { 292 runningLock.create(TAG, runningLock.RunningLockType.PROXIMITY_SCREEN_CONTROL) 293 .then((lock) => { 294 expect(lock).not().assertUndefined(); 295 let holding = lock.isHolding(); 296 console.info(`${TAG} holding: ${holding}`); 297 expect(holding).assertFalse(); 298 lock.hold({ 299 timeout: 500 300 }); 301 let isHolding = lock.isHolding(); 302 console.info(`${TAG} isHolding: ${isHolding}`); 303 expect(isHolding).assertFalse(); 304 done(); 305 }) 306 .catch((error) => { 307 console.error(`${TAG} error: ${error.code} ${error.message}`); 308 expect(error.code).assertEqual(401); 309 done(); 310 }) 311 .finally(() => { 312 console.info(`${TAG} finally`); 313 done(); 314 }) 315 } catch (e) { 316 console.error(`${TAG} error: ${e.code} ${e.message}`); 317 expect(e.code).assertEqual(401); 318 done(); 319 } 320 }) 321 322 /** 323 * @tc.number SUB_PowerSystem_RunningLock_JSTest_0063 324 * @tc.name testRunning_Lock_Hold_IsHolding_UnHold_JSTest0063 325 * @tc.desc hold lock, is holding 326 * @tc.level: Level 3 327 * @tc.type: Function 328 * @tc.size: MediumTest 329 */ 330 it('Running_Lock_Hold_IsHolding_UnHold_JSTest0063', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL3, async function (done) { 331 let TAG = 'Running_Lock_Hold_IsHolding_UnHold_JSTest0063'; 332 try { 333 runningLock.create(TAG, runningLock.RunningLockType.PROXIMITY_SCREEN_CONTROL) 334 .then((lock) => { 335 expect(lock).not().assertUndefined(); 336 let holding = lock.isHolding(); 337 console.info(`${TAG} holding: ${holding}`); 338 expect(holding).assertFalse(); 339 lock.hold(true); 340 let isHolding = lock.isHolding(); 341 console.info(`${TAG} isHolding: ${isHolding}`); 342 expect(isHolding).assertFalse(); 343 done(); 344 }) 345 .catch((error) => { 346 console.error(`${TAG} error: ${error.code} ${error.message}`); 347 expect(error.code).assertEqual(401); 348 done(); 349 }) 350 .finally(() => { 351 console.info(`${TAG} finally`); 352 done(); 353 }) 354 } catch (e) { 355 console.error(`${TAG} error: ${e.code} ${e.message}`); 356 expect(e.code).assertEqual(401); 357 done(); 358 } 359 }) 360 361 /** 362 * @tc.number SUB_PowerSystem_RunningLock_JSTest_0070 363 * @tc.name testEnum_RunningLock_Type_Background_JSTest0070 364 * @tc.desc The lock type is BACKGROUND 365 * @tc.level: Level 3 366 * @tc.type: Functiontion 367 * @tc.size: MediumTest 368 */ 369 it('Enum_RunningLock_Type_Background_JSTest0070', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL3, function () { 370 let runningLockType = runningLock.RunningLockType.BACKGROUND; 371 console.info('runningLockType = ' + runningLockType); 372 expect(runningLockType == 1).assertTrue(); 373 console.info('Enum_RunningLock_Type_Background_JSTest0070 success'); 374 }) 375 376 /** 377 * @tc.number SUB_PowerSystem_RunningLock_JSTest_0080 378 * @tc.name testEnum_RunningLock_Type_Proximityscreencontrol_JSTest0080 379 * @tc.desc The lock type is PROXIMITY_SCREEN_CONTROL 380 * @tc.level: Level 3 381 * @tc.type: Functiontion 382 * @tc.size: MediumTest 383 */ 384 it('Enum_RunningLock_Type_Proximityscreencontrol_JSTest0080', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL3, function () { 385 let runningLockType = runningLock.RunningLockType.PROXIMITY_SCREEN_CONTROL; 386 console.info('runningLockType = ' + runningLockType); 387 expect(runningLockType == 2).assertTrue(); 388 console.info('Enum_RunningLock_Type_Proximityscreencontrol_JSTest0080 success'); 389 }) 390 391 /** 392 * @tc.number SUB_PowerSystem_RunningLock_JSTest_0090 393 * @tc.name testIs_Runninglock_Type_Supported_Promise_JSTest0090 394 * @tc.desc Checks whether the specified RunningLockType is supported (deprecated since 9) 395 * @tc.level: Level 3 396 * @tc.type: Functiontion 397 * @tc.size: MediumTest 398 */ 399 it('Is_Runninglock_Type_Supported_Promise_JSTest0090', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL3, async function (done) { 400 await runningLock.isRunningLockTypeSupported(runningLock.RunningLockType.PROXIMITY_SCREEN_CONTROL) 401 .then(supported => { 402 console.info('Is_Runninglock_Type_Supported_Promise_JSTest0090 PROXIMITY_SCREEN_CONTROL supported is ' + 403 supported); 404 expect(supported).assertTrue(); 405 console.info('Is_Runninglock_Type_Supported_Promise_JSTest0090 success'); 406 done(); 407 }) 408 .catch(error => { 409 console.log('Is_Runninglock_Type_Supported_Promise_JSTest0090 error: ' + error); 410 expect().assertFail(); 411 done(); 412 }) 413 }) 414 415 /** 416 * @tc.number SUB_PowerSystem_RunningLock_JSTest_0100 417 * @tc.name testIs_Runninglock_Type_Supported_Promise_JSTest0100 418 * @tc.desc Checks whether the specified RunningLockType is supported (deprecated since 9) 419 * @tc.level: Level 3 420 * @tc.type: Functiontion 421 * @tc.size: MediumTest 422 */ 423 it('Is_Runninglock_Type_Supported_Promise_JSTest0100', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL3, async function (done) { 424 await runningLock.isRunningLockTypeSupported(runningLock.RunningLockType.BACKGROUND) 425 .then(supported => { 426 console.info('Is_Runninglock_Type_Supported_Promise_JSTest0100 BACKGROUND supported is ' + 427 supported); 428 expect(supported).assertTrue(); 429 console.info('Is_Runninglock_Type_Supported_Promise_JSTest0100 success'); 430 done(); 431 }) 432 .catch(error => { 433 console.log('Is_Runninglock_Type_Supported_Promise_JSTest0100 error: ' + error); 434 expect().assertFail(); 435 done(); 436 }) 437 }) 438 439 /** 440 * @tc.number SUB_PowerSystem_RunningLock_JSTest_0110 441 * @tc.name testIs_Runninglock_Type_Supported_Callback_JSTest0110 442 * @tc.desc Checks whether the specified RunningLockType is supported (deprecated since 9) 443 * @tc.level: Level 3 444 * @tc.type: Functiontion 445 * @tc.size: MediumTest 446 */ 447 it('Is_Runninglock_Type_Supported_Callback_JSTest0110', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL3, async function (done) { 448 runningLock.isRunningLockTypeSupported(runningLock.RunningLockType.BACKGROUND, (error, supported) => { 449 if (typeof error === "undefined") { 450 console.info('Is_Runninglock_Type_Supported_Callback_JSTest0110 supported is ' + supported); 451 expect(supported).assertTrue(); 452 console.info('Is_Runninglock_Type_Supported_Callback_JSTest0110 success'); 453 } else { 454 console.log('Is_Runninglock_Type_Supported_Callback_JSTest0110: ' + error); 455 expect().assertFail(); 456 } 457 done(); 458 }) 459 }) 460 461 /** 462 * @tc.number SUB_PowerSystem_RunningLock_JSTest_0120 463 * @tc.name testIs_Runninglock_Type_Supported_Callback_JSTest0120 464 * @tc.desc Checks whether the specified RunningLockType is supported (deprecated since 9) 465 * @tc.level: Level 3 466 * @tc.type: Functiontion 467 * @tc.size: MediumTest 468 */ 469 it('Is_Runninglock_Type_Supported_Callback_JSTest0120', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL3, async function (done) { 470 runningLock.isRunningLockTypeSupported(3, (error, supported) => { 471 if (typeof error === "undefined") { 472 console.info('Is_Runninglock_Type_Supported_Callback_JSTest0120 supported is ' + supported); 473 expect(supported).assertFalse(); 474 console.info('Is_Runninglock_Type_Supported_Callback_JSTest0120 success'); 475 } else { 476 console.log('Is_Runninglock_Type_Supported_Callback_JSTest0120: ' + error); 477 expect().assertFail(); 478 } 479 done(); 480 }) 481 }) 482 483 /** 484 * @tc.number SUB_PowerSystem_RunningLock_JSTest_0130 485 * @tc.name testIs_Supported_JSTest0130 486 * @tc.desc Checks whether the specified RunningLockType is supported. 487 * @tc.level: Level 3 488 * @tc.type: Functiontion 489 * @tc.size: MediumTest 490 */ 491 it('Is_Supported_JSTest0130', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL3, async function (done) { 492 try { 493 let background = runningLock.isSupported(runningLock.RunningLockType.BACKGROUND) 494 expect(background).assertTrue(); 495 done(); 496 } catch (e) { 497 console.info('Is_Supported_JSTest0130 code:' + e); 498 expect().assertFail(); 499 done(); 500 } 501 }) 502 503 /** 504 * @tc.number SUB_PowerSystem_RunningLock_JSTest_0140 505 * @tc.name testIs_Supported_JSTest0140 506 * @tc.desc Checks whether the specified RunningLockType is supported. 507 * @tc.level: Level 3 508 * @tc.type: Functiontion 509 * @tc.size: MediumTest 510 */ 511 it('Is_Supported_JSTest0140', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL3, async function (done) { 512 try { 513 let proximityScreenControl = 514 runningLock.isSupported(runningLock.RunningLockType.PROXIMITY_SCREEN_CONTROL) 515 expect(proximityScreenControl).assertTrue(); 516 done(); 517 } catch (e) { 518 console.info('Is_Supported_JSTest0140 code:' + e); 519 expect().assertFail(); 520 done(); 521 } 522 }) 523 524 /** 525 * @tc.number SUB_PowerSystem_RunningLock_JSTest_0150 526 * @tc.name testIs_Supported_JSTest0150 527 * @tc.desc Checks whether the specified RunningLockType is supported. 528 * @tc.level: Level 3 529 * @tc.type: Functiontion 530 * @tc.size: MediumTest 531 */ 532 it('Is_Supported_JSTest0150', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL3, async function (done) { 533 try { 534 let other = runningLock.isSupported(0) 535 expect(other).assertFalse(); 536 done(); 537 } catch (e) { 538 console.info('Is_Supported_JSTest0150 code:' + e); 539 expect().assertFail(); 540 done(); 541 } 542 }) 543 544 /** 545 * @tc.number SUB_PowerSystem_RunningLock_JSTest_0160 546 * @tc.name testIs_Supported_JSTest0160 547 * @tc.desc Checks whether the specified RunningLockType is supported. 548 * @tc.level: Level 3 549 * @tc.type: Functiontion 550 * @tc.size: MediumTest 551 */ 552 it('Is_Supported_JSTest0160', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL3, async function (done) { 553 try { 554 let other = runningLock.isSupported(3) 555 expect(other).assertFalse(); 556 done(); 557 } catch (e) { 558 console.info('Is_Supported_JSTest0160 code:' + e); 559 expect().assertFail(); 560 done(); 561 } 562 }) 563 564 /** 565 * @tc.number SUB_PowerSystem_RunningLock_JSTest_0161 566 * @tc.name testIs_Supported_JSTest0161 567 * @tc.desc Checks whether the specified RunningLockType is supported. 568 * @tc.level: Level 3 569 * @tc.type: Function 570 * @tc.size: MediumTest 571 */ 572 it('Is_Supported_JSTest0161', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL3, async function (done) { 573 let TAG = 'Is_Supported_JSTest0161'; 574 try { 575 let isSupported = runningLock.isSupported('PROXIMITY_SCREEN_CONTROL'); 576 console.info(`${TAG} isSupported: ${isSupported}`); 577 expect(isSupported).assertUndefined(); 578 done(); 579 } catch (e) { 580 console.error(`${TAG} error: ${e.code} ${e.message}`); 581 expect(e.code).assertEqual(401); 582 done(); 583 } 584 }) 585 586 /** 587 * @tc.number SUB_PowerSystem_RunningLock_JSTest_0162 588 * @tc.name testIs_Supported_JSTest0162 589 * @tc.desc Checks whether the specified RunningLockType is supported. 590 * @tc.level: Level 3 591 * @tc.type: Function 592 * @tc.size: MediumTest 593 */ 594 it('Is_Supported_JSTest0162', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL3, async function (done) { 595 let TAG = 'Is_Supported_JSTest0162'; 596 try { 597 let isSupported = runningLock.isSupported(false); 598 console.info(`${TAG} isSupported: ${isSupported}`); 599 expect(isSupported).assertUndefined(); 600 done(); 601 } catch (e) { 602 console.error(`${TAG} error: ${e.code} ${e.message}`); 603 expect(e.code).assertEqual(401); 604 done(); 605 } 606 }) 607 608 /** 609 * @tc.number SUB_PowerSystem_RunningLock_JSTest_0163 610 * @tc.name testIs_Supported_JSTest0163 611 * @tc.desc Checks whether the specified RunningLockType is supported. 612 * @tc.level: Level 3 613 * @tc.type: Function 614 * @tc.size: MediumTest 615 */ 616 it('Is_Supported_JSTest0163', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL3, async function (done) { 617 let TAG = 'Is_Supported_JSTest0163'; 618 try { 619 let isSupported = runningLock.isSupported({ 620 RunningLockType: runningLock.RunningLockType.PROXIMITY_SCREEN_CONTROL 621 }); 622 console.info(`${TAG} isSupported: ${isSupported}`); 623 expect(isSupported).assertUndefined(); 624 done(); 625 } catch (e) { 626 console.error(`${TAG} error: ${e.code} ${e.message}`); 627 expect(e.code).assertEqual(401); 628 done(); 629 } 630 }) 631 632 /** 633 * @tc.number SUB_PowerSystem_RunningLock_JSTest_0170 634 * @tc.name testCreate_Running_Lock_Promise_JSTest0170 635 * @tc.desc Create running lock promise (deprecated since 9) 636 * @tc.level: Level 3 637 * @tc.type: Functiontion 638 * @tc.size: MediumTest 639 */ 640 it('Create_Running_Lock_Promise_JSTest0170', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL3, async function (done) { 641 await runningLock.createRunningLock("Create_Running_Lock_Promise_JSTest0170", 642 runningLock.RunningLockType.BACKGROUND) 643 .then(runninglock => { 644 expect(runninglock !== null).assertTrue(); 645 console.info('Create_Running_Lock_Promise_JSTest0170 success'); 646 done(); 647 }) 648 .catch(error => { 649 console.log('Create_Running_Lock_Promise_JSTest0170 error: ' + error); 650 expect().assertFail(); 651 done(); 652 }) 653 }) 654 655 /** 656 * @tc.number SUB_PowerSystem_RunningLock_JSTest_0180 657 * @tc.name testCreate_Running_Lock_CallBack_JSTest0180 658 * @tc.desc Create running lock callback (deprecated since 9) 659 * @tc.level: Level 3 660 * @tc.type: Functiontion 661 * @tc.size: MediumTest 662 */ 663 it('Create_Running_Lock_CallBack_JSTest0180', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL3, async function (done) { 664 runningLock.createRunningLock("Create_Running_Lock_CallBack_JSTest0180", 665 runningLock.RunningLockType.PROXIMITY_SCREEN_CONTROL, 666 (error, runninglock) => { 667 if (typeof error === "undefined") { 668 console.info('Create_Running_Lock_CallBack_JSTest0180: runningLock is ' + runninglock); 669 expect(runninglock !== null).assertTrue(); 670 let used = runninglock.isUsed(); 671 console.info('Create_Running_Lock_CallBack_JSTest0180 is used: ' + used); 672 expect(used).assertFalse(); 673 runninglock.lock(500); 674 used = runninglock.isUsed(); 675 console.info('after lock Create_Running_Lock_CallBack_JSTest0180 is used: ' + used); 676 expect(used).assertTrue(); 677 console.info('Create_Running_Lock_CallBack_JSTest0180 success'); 678 } else { 679 console.log('Create_Running_Lock_CallBack_JSTest0180: ' + error); 680 expect().assertFail(); 681 } 682 done(); 683 }) 684 }) 685 686 /** 687 * @tc.number SUB_PowerSystem_RunningLock_JSTest_0190 688 * @tc.name testCreate_Running_Lock_Promise_JSTest0190 689 * @tc.desc Create lock promise 690 * @tc.level: Level 3 691 * @tc.type: Functiontion 692 * @tc.size: MediumTest 693 */ 694 it('Create_Running_Lock_Promise_JSTest0190', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL3, async function (done) { 695 try { 696 let isExec = false; 697 await runningLock.create("Create_Running_Lock_Promise_JSTest0190", 698 runningLock.RunningLockType.BACKGROUND) 699 .then((runninglock) => { 700 isExec = true; 701 expect(runninglock !== null).assertTrue(); 702 console.info('Create_Running_Lock_Promise_JSTest0190 success'); 703 done(); 704 }) 705 .catch((error) => { 706 isExec = true; 707 console.info('Create_Running_Lock_Promise_JSTest0190 error:' + (typeof error)); 708 expect(typeof error !== "undefined").assertTrue(); 709 console.info('Create_Running_Lock_Promise_JSTest0190 error code:' + error.code + " msg: " + 710 error.message); 711 done(); 712 }) 713 .finally(() => { 714 expect(isExec).assertTrue(); 715 done(); 716 }) 717 } catch (e) { 718 console.info('Create_Running_Lock_Promise_JSTest0190 error:' + e); 719 expect().assertFail(); 720 done(); 721 } 722 723 }) 724 725 /** 726 * @tc.number SUB_PowerSystem_RunningLock_JSTest_0200 727 * @tc.name testCreate_Running_Lock_Promise_JSTest0200 728 * @tc.desc Create lock promise 729 * @tc.level: Level 3 730 * @tc.type: Functiontion 731 * @tc.size: MediumTest 732 */ 733 it('Create_Running_Lock_Promise_JSTest0200', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL3, async function (done) { 734 try { 735 let isExec = false; 736 await runningLock.create("Create_Running_Lock_Promise_JSTest0200", 737 runningLock.RunningLockType.PROXIMITY_SCREEN_CONTROL) 738 .then((runninglock) => { 739 isExec = true; 740 expect(runninglock !== null).assertTrue(); 741 console.info('Create_Running_Lock_Promise_JSTest0200 success'); 742 done(); 743 }) 744 .catch((error) => { 745 isExec = true; 746 console.info('Create_Running_Lock_Promise_JSTest0200 error:' + (typeof error)); 747 expect(typeof error !== "undefined").assertTrue(); 748 console.info('Create_Running_Lock_Promise_JSTest0200 error code:' + error.code + " msg: " + 749 error.message); 750 done(); 751 }) 752 .finally(() => { 753 expect(isExec).assertTrue(); 754 done(); 755 }) 756 } catch (e) { 757 console.info('Create_Running_Lock_Promise_JSTest0200 error:' + e); 758 expect().assertFail(); 759 done(); 760 } 761 }) 762 763 /** 764 * @tc.number SUB_PowerSystem_RunningLock_JSTest_0210 765 * @tc.name testCreate_Running_Lock_Promise_Invalid_JSTest0210 766 * @tc.desc Create lock input invalid value 767 * @tc.level: Level 3 768 * @tc.type: Functiontion 769 * @tc.size: MediumTest 770 */ 771 it('Create_Running_Lock_Promise_Invalid_JSTest0210', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL3, async function (done) { 772 try { 773 runningLock.create(TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL3, runningLock.RunningLockType.BACKGROUND) 774 .then((runninglock) => { 775 expect().assertFail(); 776 done(); 777 }) 778 } catch (e) { 779 console.info('Create_Running_Lock_Promise_Invalid_JSTest0210 code: ' + e.code + "msg: " + e.message); 780 // 401: Invalid input parameter 781 expect(e.code === 401).assertTrue(); 782 done(); 783 } 784 }) 785 786 /** 787 * @tc.number SUB_PowerSystem_RunningLock_JSTest_0220 788 * @tc.name testCreate_Running_Lock_Promise_Invalid_JSTest0220 789 * @tc.desc Create lock input invalid value 790 * @tc.level: Level 3 791 * @tc.type: Functiontion 792 * @tc.size: MediumTest 793 */ 794 it('Create_Running_Lock_Promise_Invalid_JSTest0220', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL3, async function (done) { 795 try { 796 runningLock.create("Create_Running_Lock_Promise_Invalid_JSTest0220", 0) 797 .then((runninglock) => { 798 expect(runninglock === null).assertTrue(); 799 done(); 800 }) 801 .catch((error) => { 802 console.info('Create_Running_Lock_Promise_Invalid_JSTest0220 error:' + (typeof error)); 803 expect(typeof error !== "undefined").assertTrue(); 804 console.info('Create_Running_Lock_Promise_Invalid_JSTest0220 error code:' + error.code + 805 " msg: " + error.message); 806 done(); 807 }) 808 } catch (e) { 809 console.info('Create_Running_Lock_Promise_Invalid_JSTest0220 code:' + e.code + "msg:" + e.message); 810 // 401: Invalid input parameter 811 expect(e.code === 401).assertTrue(); 812 done(); 813 } 814 }) 815 816 /** 817 * @tc.number SUB_PowerSystem_RunningLock_JSTest_0230 818 * @tc.name testCreate_Running_Lock_Promise_Invalid_JSTest0230 819 * @tc.desc Create lock input invalid value 820 * @tc.level: Level 3 821 * @tc.type: Functiontion 822 * @tc.size: MediumTest 823 */ 824 it('Create_Running_Lock_Promise_Invalid_JSTest0230', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL3, async function (done) { 825 try { 826 runningLock.create("Create_Running_Lock_Promise_Invalid_JSTest0230", 5) 827 .then((runninglock) => { 828 expect(runninglock === null).assertTrue(); 829 done(); 830 }) 831 .catch((error) => { 832 console.info('Create_Running_Lock_Promise_Invalid_JSTest0230 error: ' + (typeof error)); 833 expect(typeof error !== "undefined").assertTrue(); 834 console.info('Create_Running_Lock_Promise_Invalid_JSTest0230 error code: ' + error.code + 835 " msg: " + error.message); 836 done(); 837 }) 838 } catch (e) { 839 console.info('Create_Running_Lock_Promise_Invalid_JSTest0230 code: ' + e.code + "msg: " + e.message); 840 // 401: Invalid input parameter 841 expect(e.code === 401).assertTrue(); 842 done(); 843 } 844 }) 845 846 /** 847 * @tc.number SUB_PowerSystem_RunningLock_JSTest_0240 848 * @tc.name testCreate_Running_Lock_Callback_JSTest0240 849 * @tc.desc Create lock callback 850 * @tc.level: Level 3 851 * @tc.type: Functiontion 852 * @tc.size: MediumTest 853 */ 854 it('Create_Running_Lock_Callback_JSTest0240', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL3, async function (done) { 855 try { 856 runningLock.create("Create_Running_Lock_Callback_JSTest0240", runningLock.RunningLockType.BACKGROUND, 857 (error, runninglock) => { 858 expect(typeof error === "undefined").assertTrue(); 859 expect(runninglock !== null).assertTrue(); 860 console.info('Create_Running_Lock_Callback_JSTest0240 success'); 861 done(); 862 }); 863 } catch (e) { 864 console.info('Create_Running_Lock_Callback_JSTest0240 error:' + e); 865 expect().assertFail(); 866 done(); 867 } 868 }) 869 870 /** 871 * @tc.number SUB_PowerSystem_RunningLock_JSTest_0250 872 * @tc.name testCreate_Running_Lock_Callback_JSTest0250 873 * @tc.desc Create lock callback 874 * @tc.level: Level 3 875 * @tc.type: Functiontion 876 * @tc.size: MediumTest 877 */ 878 it('Create_Running_Lock_Callback_JSTest0250', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL3, async function (done) { 879 try { 880 runningLock.create("Create_Running_Lock_Callback_JSTest0250", 881 runningLock.RunningLockType.PROXIMITY_SCREEN_CONTROL, 882 (error, runninglock) => { 883 expect(typeof error === "undefined").assertTrue(); 884 expect(runninglock !== null).assertTrue(); 885 console.info('Create_Running_Lock_Callback_JSTest0250 success'); 886 done(); 887 }); 888 } catch (e) { 889 console.info('Create_Running_Lock_Callback_JSTest0250 error:' + e); 890 expect().assertFail(); 891 done(); 892 } 893 }) 894 895 /** 896 * @tc.number SUB_PowerSystem_RunningLock_JSTest_0260 897 * @tc.name testCreate_Running_Lock_Callback_Invalid_JSTest0260 898 * @tc.desc Create lock input invalid value 899 * @tc.level: Level 3 900 * @tc.type: Functiontion 901 * @tc.size: MediumTest 902 */ 903 it('Create_Running_Lock_Callback_Invalid_JSTest0260', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL3, async function (done) { 904 try { 905 runningLock.create("Create_Running_Lock_Callback_Invalid_JSTest0260", "invalid", 906 (error, runninglock) => { 907 expect(typeof error !== "undefined").assertTrue(); 908 expect(runninglock === null).assertTrue(); 909 console.info('Create_Running_Lock_Callback_Invalid_JSTest0260 success'); 910 expect().assertFail(); 911 done(); 912 }); 913 } catch (e) { 914 console.info('Create_Running_Lock_Callback_Invalid_JSTest0260 code:' + e.code + "msg:" + e.message); 915 // 401: Invalid input parameter 916 expect(e.code === 401).assertTrue(); 917 done(); 918 } 919 }) 920 921 /** 922 * @tc.number SUB_PowerSystem_RunningLock_JSTest_0270 923 * @tc.name testCreate_Running_Lock_Callback_Invalid_JSTest0270 924 * @tc.desc Create lock input invalid value 925 * @tc.level: Level 3 926 * @tc.type: Function 927 * @tc.size: MediumTest 928 */ 929 it('Create_Running_Lock_Callback_Invalid_JSTest0270', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL3, async function (done) { 930 let TAG = 'Create_Running_Lock_Callback_Invalid_JSTest0270'; 931 try { 932 runningLock.create(TAG, -1, (error, lock) => { 933 console.error(`${TAG} error: ${error.code} ${error.message}`); 934 expect(error.code).assertEqual(401); 935 console.info(`${TAG} lock: ${JSON.stringify(lock)}`); 936 expect(lock).assertUndefined(); 937 done(); 938 }); 939 } catch (error) { 940 console.error(`${TAG} error: ${error.code} ${error.message}`); 941 // 401: Invalid input parameter 942 expect(error.code).assertEqual(401); 943 done(); 944 } 945 }) 946 947 /** 948 * @tc.number SUB_PowerSystem_RunningLock_JSTest_0280 949 * @tc.name testCreate_Running_Lock_Callback_Invalid_JSTest0280 950 * @tc.desc Create lock input invalid value 951 * @tc.level: Level 3 952 * @tc.type: Function 953 * @tc.size: MediumTest 954 */ 955 it('Create_Running_Lock_Callback_Invalid_JSTest0280', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL3, async function (done) { 956 let TAG = 'Create_Running_Lock_Callback_Invalid_JSTest0280'; 957 try { 958 runningLock.create(TAG, 3, (error, lock) => { 959 console.error(`${TAG} error: ${error.code} ${error.message}`); 960 expect(error.code).assertEqual(401); 961 console.info(`${TAG} lock: ${JSON.stringify(lock)}`); 962 expect(lock).assertUndefined(); 963 done(); 964 }); 965 } catch (error) { 966 console.error(`${TAG} error: ${error.code} ${error.message}`); 967 expect(error.code).assertEqual(401); 968 done(); 969 } 970 }) 971 }) 972} 973