From ead60a0d5e1fd21c3796df482fd435e3c201f40a Mon Sep 17 00:00:00 2001 From: qiuxiangdong Date: Tue, 25 Oct 2022 14:17:14 +0800 Subject: [PATCH] test: Power rectification Signed-off-by: qiuxiangdong Change-Id: I88b74b914752d80a03cb25212ee31c8353116bab --- .../main/js/test/power_manager_power.test.js | 413 +++++++----------- .../test/power_manager_running_lock.test.js | 377 ++++++++-------- 2 files changed, 348 insertions(+), 442 deletions(-) diff --git a/powermgr/power_manager/src/main/js/test/power_manager_power.test.js b/powermgr/power_manager/src/main/js/test/power_manager_power.test.js index c07130d9e..2a1f91c94 100644 --- a/powermgr/power_manager/src/main/js/test/power_manager_power.test.js +++ b/powermgr/power_manager/src/main/js/test/power_manager_power.test.js @@ -21,342 +21,267 @@ export default function PowerManagerPowerTest() { describe('PowerManagerPowerTest', function () { console.log("*************Power Unit Test Begin*************"); - /** + /** * @tc.number SUB_PowerSystem_PowerManager_JSTest_0010 - * @tc.name Power_Is_Screnn_On_Promise_JSTest0010 - * @tc.desc Checks whether the screen of a device is on or off + * @tc.name Power_Reboot_Device_JSTest0010 + * @tc.desc reboot device (deprecated since 9) */ - it('Power_Is_Screnn_On_Promise_JSTest0010', 0, async function (done) { - power.wakeupDevice("Power_Is_Screnn_On_Promise_JSTest0010"); - power.isScreenOn() + it('Power_Reboot_Device_JSTest0010', 0, function () { + // Reboot tests are not performed by default + if (false) { + try { + power.rebootDevice('Power_Reboot_Device_JSTest0010'); + } catch (e) { + console.info('Power_Reboot_Device_JSTest0010 error:' + e); + expect().assertFail(); + } + } + }) + + /** + * @tc.number SUB_PowerSystem_PowerManager_JSTest_0020 + * @tc.name Power_Is_Screnn_On_Promise_JSTest0020 + * @tc.desc Checks whether the screen of a device is on or off (deprecated since 9) + */ + it('Power_Is_Screnn_On_Promise_JSTest0020', 0, async function (done) { + power.wakeupDevice("Power_Is_Screnn_On_Promise_JSTest0020"); + await power.isScreenOn() .then(screenOn => { - console.info('Power_Is_Screnn_On_Promise_JSTest0010 screenOn is ' + screenOn); + console.info('Power_Is_Screnn_On_Promise_JSTest0020 screenOn is ' + screenOn); expect(screenOn).assertTrue(); - console.info('Power_Is_Screnn_On_Promise_JSTest0010 success'); - done(); + console.info('Power_Is_Screnn_On_Promise_JSTest0020 success'); }) .catch(error => { - console.log('Power_Is_Screnn_On_Promise_JSTest0010 error: ' + error); + console.log('Power_Is_Screnn_On_Promise_JSTest0020 error: ' + error); expect().assertFail(); - done(); }) + done(); }) /** - * @tc.number SUB_PowerSystem_PowerManager_JSTest_0020 - * @tc.name Power_Is_Screnn_On_Callback_JSTest0020 - * @tc.desc Checks whether the screen of a device is on or off + * @tc.number SUB_PowerSystem_PowerManager_JSTest_0030 + * @tc.name Power_Is_Screnn_On_Callback_JSTest0030 + * @tc.desc Checks whether the screen of a device is on or off (deprecated since 9) */ - it('Power_Is_Screnn_On_Callback_JSTest0020', 0, async function (done) { - power.wakeupDevice("Power_Is_Screnn_On_Callback_JSTest0020"); + it('Power_Is_Screnn_On_Callback_JSTest0030', 0, async function (done) { + power.wakeupDevice("Power_Is_Screnn_On_Callback_JSTest0030"); power.isScreenOn((error, screenOn) => { if (typeof error === "undefined") { - console.info('Power_Is_Screnn_On_Callback_JSTest0020 screenOn is ' + screenOn); + console.info('Power_Is_Screnn_On_Callback_JSTest0030 screenOn is ' + screenOn); expect(screenOn).assertTrue(); - console.info('Power_Is_Screnn_On_Callback_JSTest0020 success'); - done(); + console.info('Power_Is_Screnn_On_Callback_JSTest0030 success'); } else { - console.log('Power_Is_Screnn_On_Callback_JSTest0020: ' + error); + console.log('Power_Is_Screnn_On_Callback_JSTest0030: ' + error); expect().assertFail(); - done(); } }) + done(); }) /** - * @tc.number SUB_PowerSystem_PowerManager_JSTest_0030 - * @tc.name Power_WakeupDevices_String_JSTest0030 - * @tc.desc Try to wakeup the device and let screen on + * @tc.number SUB_PowerSystem_PowerManager_JSTest_0040 + * @tc.name Power_Is_Active_JSTest0040 + * @tc.desc On and Off Screen and get the current screen on and off */ - it('Power_WakeupDevices_String_JSTest0030', 0, async function (done) { - power.isScreenOn() - .then(screenOn => { - console.info('Power_WakeupDevices_String_JSTest0030: The current screenOn is ' + screenOn); - if (screenOn) { - power.suspendDevice(); - } - }) - .catch(error => { - console.log('Power_WakeupDevices_String_JSTest0030 error: ' + error); - expect().assertFail(); - done(); - }) - setTimeout(function(){ - power.wakeupDevice("Power_WakeupDevices_String_JSTest0030"); - power.isScreenOn() - .then(screenOn => { - console.info('Power_WakeupDevices_String_JSTest0030: The current screenOn is ' + screenOn); - expect(screenOn).assertTrue(); - console.info('Power_WakeupDevices_String_JSTest0030 success'); - done(); - }) - .catch(error => { - console.log('Power_WakeupDevices_String_JSTest0030 error: ' + error); - expect().assertFail(); - done(); - }) - }, 2000); + it('Power_Is_Active_JSTest0040', 0, function () { + try { + power.suspend(); + power.wakeup('Power_Is_Active_JSTest0040'); + let on = power.isActive(); + console.info('Power_Is_Active_JSTest0040 on:' + on); + expect(on).assertTrue(); + power.suspend(); + let off = power.isActive(); + console.info('Power_Is_Active_JSTest0040 off:' + off); + expect(off).assertFalse(); + } catch (e) { + console.info('Power_Is_Active_JSTest0040:' + e); + expect().assertFail(); + } }) /** - * @tc.number SUB_PowerSystem_PowerManager_JSTest_0040 - * @tc.name Power_SuspendDevices_JSTest0040 - * @tc.desc Try to suspend the device and let screen off + * @tc.number SUB_PowerSystem_PowerManager_JSTest_0050 + * @tc.name Power_Get_Power_Mode_JSTest0050 + * @tc.desc Gets and sets the power mode */ - it('Power_SuspendDevices_JSTest0040', 0, async function (done) { - power.isScreenOn() - .then(screenOn => { - console.info('Power_SuspendDevices_JSTest0040: The current screenOn is ' + screenOn); - if (!screenOn) { - power.wakeupDevice("Power_SuspendDevices_JSTest0040"); - } - }) - .catch(error => { - console.log('Power_SuspendDevices_JSTest0040 error: ' + error); - expect().assertFail(); - done(); - }) - setTimeout(function(){ - power.suspendDevice(); - console.info('Power_SuspendDevices_JSTest0040: SuspendDevice end'); - power.isScreenOn() - .then(screenOn => { - console.info('Power_SuspendDevices_JSTest0040: The current screenOn is ' + screenOn); - expect(screenOn).assertFalse(); - console.info('Power_SuspendDevices_JSTest0040 success'); - done(); - }) - .catch(error => { - console.log('Power_SuspendDevices_JSTest0040 error: ' + error); - expect().assertFail(); - done(); - }) - }, 2000); + it('Power_Get_Power_Mode_JSTest0050', 0, async function () { + let currentMode = power.getPowerMode(); + console.info('Power_Get_Power_Mode_JSTest0050 currentMode:' + currentMode); + expect(currentMode >= power.DevicePowerMode.MODE_NORMAL && + currentMode <= power.DevicePowerMode.MODE_EXTREME_POWER_SAVE).assertTrue(); }) /** - * @tc.number SUB_PowerSystem_PowerManager_JSTest_0070 - * @tc.name Power_Device_Power_Mode_MODENORMAL_JSTest0070 + * @tc.number SUB_PowerSystem_PowerManager_JSTest_0060 + * @tc.name Power_Device_Power_Mode_MODENORMAL_JSTest0060 * @tc.desc Get device power mode MODE_NORMAL */ - it('Power_Device_Power_Mode_MODENORMAL_JSTest0070', 0, function () { + it('Power_Device_Power_Mode_MODENORMAL_JSTest0060', 0, function () { let devicePowerMode = power.DevicePowerMode.MODE_NORMAL; console.info('MODE_NORMAL = ' + devicePowerMode); expect(devicePowerMode === 600).assertTrue(); }) /** - * @tc.number SUB_PowerSystem_PowerManager_JSTest_0080 + * @tc.number SUB_PowerSystem_PowerManager_JSTest_0070 * @tc.name Power_Device_Power_Mode_MODEPOWERSAVE_JSTest0080 * @tc.desc Get device power mode MODE_POWER_SAVE */ - it('Power_Device_Power_Mode_MODEPOWERSAVE_JSTest0080', 0, function () { + it('Power_Device_Power_Mode_MODEPOWERSAVE_JSTest0070', 0, function () { let devicePowerMode = power.DevicePowerMode.MODE_POWER_SAVE; console.info('MODE_POWER_SAVE = ' + devicePowerMode); expect(devicePowerMode === 601).assertTrue(); }) /** - * @tc.number SUB_PowerSystem_PowerManager_JSTest_0090 + * @tc.number SUB_PowerSystem_PowerManager_JSTest_0080 * @tc.name Power_Device_pPower_Mode_MODEPERFORMANCE_JSTest0090 * @tc.desc Get device power mode MODE_PERFORMANCE */ - it('Power_Device_pPower_Mode_MODEPERFORMANCE_JSTest0090', 0, function () { + it('Power_Device_pPower_Mode_MODEPERFORMANCE_JSTest0080', 0, function () { let devicePowerMode = power.DevicePowerMode.MODE_PERFORMANCE; console.info('MODE_PERFORMANCE = ' + devicePowerMode); expect(devicePowerMode === 602).assertTrue(); }) /** - * @tc.number SUB_PowerSystem_PowerManager_JSTest_0100 - * @tc.name Power_Device_Power_Mode_MODE_EXTREME_POWER_SAVE_JSTest0100 + * @tc.number SUB_PowerSystem_PowerManager_JSTest_0090 + * @tc.name Power_Device_Power_Mode_MODE_EXTREME_POWER_SAVE_JSTest0090 * @tc.desc Get device power mode MODE_EXTREME_POWER_SAVE */ - it('Power_Device_Power_Mode_MODE_EXTREME_POWER_SAVE_JSTest0100', 0, function () { + it('Power_Device_Power_Mode_MODE_EXTREME_POWER_SAVE_JSTest0090', 0, function () { let devicePowerMode = power.DevicePowerMode.MODE_EXTREME_POWER_SAVE; console.info('MODE_EXTREME_POWER_SAVE = ' + devicePowerMode); expect(devicePowerMode === 603).assertTrue(); }) - - // New interface - /** - * @tc.number SUB_PowerSystem_PowerManager_JSTest_0110 - * @tc.name Power_Get_Set_Mode_Promise_JSTest0110 - * @tc.desc Gets and sets the power mode - */ - it('Power_Get_Set_Mode_Promise_JSTest0110', 0, async function (done) { - let currentMode = power.getPowerMode(); - console.info('Power_Get_Set_Mode_Promise_JSTest0110 currentMode:' + currentMode); - expect(currentMode >= power.DevicePowerMode.MODE_NORMAL && - currentMode <= power.DevicePowerMode.MODE_EXTREME_POWER_SAVE).assertTrue(); - try { - let isExec = false; - power.setPowerMode(power.DevicePowerMode.MODE_POWER_SAVE) - .then((error) => { - isExec = true; - console.info('Power_Get_Set_Mode_Promise_JSTest0110 error:' + (typeof error)); - expect(typeof error === "undefined").assertTrue(); - let mode = power.getPowerMode(); - console.info('Power_Get_Set_Mode_Promise_JSTest0110 mode:' + mode); - expect(mode === power.DevicePowerMode.MODE_POWER_SAVE).assertTrue(); - }).finally(() => { - expect(isExec).assertTrue(); - }) - } catch (e) { - console.info('Power_Get_Set_Mode_Promise_JSTest0110 error:' + e); - expect().assertFail(); - } - power.setPowerMode(currentMode); - done(); - }) /** - * @tc.number SUB_PowerSystem_PowerManager_JSTest_0120 - * @tc.name Power_Get_Set_Mode_Promise_Invalid_JSTest0120 - * @tc.desc Set the wrong power mode + * @tc.number SUB_PowerSystem_PowerManager_JSTest_0150 + * @tc.name Power_WakeupDevices_String_JSTest0150 + * @tc.desc Try to wakeup the device and let screen on (SystemApi) */ - it('Power_Get_Set_Mode_Promise_Invalid_JSTest0120', 0, async function (done) { - try { - // invalid mode - power.setPowerMode('').then(() => { - console.info('Power_Get_Set_Mode_Promise_Invalid_JSTest0120 string failed'); + it('Power_WakeupDevices_String_JSTest0150', 0, async function (done) { + await power.isScreenOn() + .then(screenOn => { + console.info('Power_WakeupDevices_String_JSTest0150: The current screenOn is ' + screenOn); + if (screenOn) { + power.suspendDevice(); + } + }) + .catch(error => { + console.log('Power_WakeupDevices_String_JSTest0150 error: ' + error); expect().assertFail(); }) - } catch (e) { - console.info('Power_Get_Set_Mode_Promise_Invalid_JSTest0120 code:' + e.code + 'msg:' + e.message); - // 401: Invalid input parameter - expect(e.code === 401).assertTrue(); - } - - try { - // Number of invalid parameters - power.setPowerMode('', '', 0).then(() => { - console.info('Power_Get_Set_Mode_Promise_Invalid_JSTest0120 number failed'); + setTimeout(function(){ + power.wakeupDevice("Power_WakeupDevices_String_JSTest0150"); + power.isScreenOn() + .then(screenOn => { + console.info('Power_WakeupDevices_String_JSTest0150: The current screenOn is ' + screenOn); + expect(screenOn).assertTrue(); + console.info('Power_WakeupDevices_String_JSTest0150 success'); + }) + .catch(error => { + console.log('Power_WakeupDevices_String_JSTest0150 error: ' + error); expect().assertFail(); }) - } catch (e) { - console.info('Power_Get_Set_Mode_Promise_Invalid_JSTest0120 code:' + e.code + 'msg:' + e.message); - // 401: Invalid input parameter - expect(e.code === 401).assertTrue(); - } + }, 2000); done(); }) /** - * @tc.number SUB_PowerSystem_PowerManager_JSTest_0130 - * @tc.name Power_Get_Set_Mode_Callback_JSTest0130 - * @tc.desc Gets and sets the power mode + * @tc.number SUB_PowerSystem_PowerManager_JSTest_0160 + * @tc.name Power_SuspendDevices_JSTest0160 + * @tc.desc Try to suspend the device and let screen off (SystemApi) */ - it('Power_Get_Set_Mode_Callback_JSTest0130', 0, async function (done) { - let currentMode = power.getPowerMode(); - console.info('Power_Get_Set_Mode_Callback_JSTest0130 currentMode:' + currentMode); - expect(currentMode >= power.DevicePowerMode.MODE_NORMAL && - currentMode <= power.DevicePowerMode.MODE_EXTREME_POWER_SAVE).assertTrue(); - try { - power.setPowerMode(power.DevicePowerMode.MODE_PERFORMANCE, (error) => { - console.info('Power_Get_Set_Mode_Callback_JSTest0130 error:' + (typeof error)); - expect(typeof error === "undefined").assertTrue(); - let mode = power.getPowerMode(); - console.info('Power_Get_Set_Mode_Callback_JSTest0130 mode:' + mode); - expect(mode === power.DevicePowerMode.MODE_PERFORMANCE).assertTrue(); + it('Power_SuspendDevices_JSTest0160', 0, async function (done) { + await power.isScreenOn() + .then(screenOn => { + console.info('Power_SuspendDevices_JSTest0160: The current screenOn is ' + screenOn); + if (!screenOn) { + power.wakeupDevice("Power_SuspendDevices_JSTest0160"); + } }) - } catch (e) { - console.info('Power_Get_Set_Mode_Callback_JSTest0130 error:' + e); - expect().assertFail(); - } - power.setPowerMode(currentMode); - done(); - }) - - /** - * @tc.number SUB_PowerSystem_PowerManager_JSTest_0140 - * @tc.name Power_Get_Set_Mode_Callback_Invalid_JSTest0140 - * @tc.desc Set the wrong power mode - */ - it('Power_Get_Set_Mode_Callback_Invalid_JSTest0140', 0, async function (done) { - try { - // invalid mode - power.setPowerMode('', (error) => { + .catch(error => { + console.log('Power_SuspendDevices_JSTest0160 error: ' + error); expect().assertFail(); }) - } catch (e) { - console.info('Power_Get_Set_Mode_Callback_Invalid_JSTest0140 code:' + e.code + 'msg:' + e.message); - // 401: Invalid input parameter - expect(e.code === 401).assertTrue(); - } - - try { - // invalid callback - power.setPowerMode(power.DevicePowerMode.MODE_PERFORMANCE, '') - } catch (e) { - console.info('Power_Get_Set_Mode_Callback_Invalid_JSTest0140 code:' + e.code + 'msg:' + e.message); - // 401: Invalid input parameter - expect(e.code === 401).assertTrue(); - } + setTimeout(function(){ + power.suspendDevice(); + console.info('Power_SuspendDevices_JSTest0160: SuspendDevice end'); + power.isScreenOn() + .then(screenOn => { + console.info('Power_SuspendDevices_JSTest0160: The current screenOn is ' + screenOn); + expect(screenOn).assertFalse(); + console.info('Power_SuspendDevices_JSTest0160 success'); + }) + .catch(error => { + console.log('Power_SuspendDevices_JSTest0160 error: ' + error); + expect().assertFail(); + }) + }, 2000); done(); }) - /** - * @tc.number SUB_PowerSystem_PowerManager_JSTest_0150 - * @tc.name Power_Reboot_JSTest0150 - * @tc.desc reboot + /** + * @tc.number SUB_PowerSystem_PowerManager_JSTest_0170 + * @tc.name Power_Set_Mode_Promise_JSTest0110 + * @tc.desc Gets and sets the power mode (SystemApi) */ - it('Power_Reboot_JSTest0150', 0, function () { - // Reboot tests are not performed by default + it('Power_Set_Mode_Promise_JSTest0110', 0, async function (done) { if (false) { + let currentMode = power.getPowerMode(); + console.info('Power_Set_Mode_Promise_JSTest0110 currentMode:' + currentMode); + expect(currentMode >= power.DevicePowerMode.MODE_NORMAL && + currentMode <= power.DevicePowerMode.MODE_EXTREME_POWER_SAVE).assertTrue(); try { - power.reboot('Power_Reboot_JSTest0150'); + let isExec = false; + await power.setPowerMode(power.DevicePowerMode.MODE_POWER_SAVE) + .then((error) => { + isExec = true; + console.info('Power_Set_Mode_Promise_JSTest0110 error:' + (typeof error)); + expect(typeof error === "undefined").assertTrue(); + let mode = power.getPowerMode(); + console.info('Power_Set_Mode_Promise_JSTest0110 mode:' + mode); + expect(mode === power.DevicePowerMode.MODE_POWER_SAVE).assertTrue(); + }).finally(() => { + expect(isExec).assertTrue(); + }) } catch (e) { - console.info('Power_Reboot_JSTest0150 error:' + e); + console.info('Power_Set_Mode_Promise_JSTest0110 error:' + e); expect().assertFail(); } + power.setPowerMode(currentMode); } + done(); }) /** - * @tc.number SUB_PowerSystem_PowerManager_JSTest_0160 - * @tc.name Power_Wakeup_Suspend_IsActive_JSTest0160 - * @tc.desc On and Off Screen and get the current screen on and off - */ - it('Power_Wakeup_Suspend_IsActive_JSTest0160', 0, function () { - try { - power.suspend(); - power.wakeup('wakeup_suspend_isPower_Wakeup_Suspend_IsActive_JSTest0160_active'); - let on = power.isActive(); - console.info('Power_Wakeup_Suspend_IsActive_JSTest0160 on:' + on); - expect(on).assertTrue(); - power.suspend(); - let off = power.isActive(); - console.info('Power_Wakeup_Suspend_IsActive_JSTest0160 off:' + off); - expect(off).assertFalse(); - } catch (e) { - console.info('Power_Wakeup_Suspend_IsActive_JSTest0160:' + e); - expect().assertFail(); - } - }) - - /** - * @tc.number SUB_PowerSystem_PowerManager_JSTest_0170 - * @tc.name Power_Wakeup_Invalid_JSTest0170 - * @tc.desc wakeup Input invalid parameter + * @tc.number SUB_PowerSystem_PowerManager_JSTest_0180 + * @tc.name Power_Set_Mode_Callback_JSTest0180 + * @tc.desc Gets and sets the power mode (SystemApi) */ - it('Power_Wakeup_Invalid_JSTest0170', 0, function () { - try { - power.wakeup(0) - } catch (e) { - console.info('Power_Wakeup_Invalid_JSTest0170 code:' + e.code + "msg:" + e.message); - // 401: Invalid input parameter - expect(e.code === 401).assertTrue(); - } - - try { - // The number of parameters does not match - power.wakeup('', 0) - } catch (e) { - console.info('Power_Wakeup_Invalid_JSTest0170 code:' + e.code + "msg:" + e.message); - // 401: Invalid input parameter - expect(e.code === 401).assertTrue(); + it('Power_Set_Mode_Callback_JSTest0180', 0, async function (done) { + if (false) { + let currentMode = power.getPowerMode(); + console.info('Power_Set_Mode_Callback_JSTest0180 currentMode:' + currentMode); + expect(currentMode >= power.DevicePowerMode.MODE_NORMAL && + currentMode <= power.DevicePowerMode.MODE_EXTREME_POWER_SAVE).assertTrue(); + try { + power.setPowerMode(power.DevicePowerMode.MODE_PERFORMANCE, (error) => { + console.info('Power_Set_Mode_Callback_JSTest0180 error:' + (typeof error)); + expect(typeof error === "undefined").assertTrue(); + let mode = power.getPowerMode(); + console.info('Power_Set_Mode_Callback_JSTest0180 mode:' + mode); + expect(mode === power.DevicePowerMode.MODE_PERFORMANCE).assertTrue(); + }) + } catch (e) { + console.info('Power_Set_Mode_Callback_JSTest0180 error:' + e); + expect().assertFail(); + } + power.setPowerMode(currentMode); } + done(); }) }) } diff --git a/powermgr/power_manager/src/main/js/test/power_manager_running_lock.test.js b/powermgr/power_manager/src/main/js/test/power_manager_running_lock.test.js index 4d1e2bcc9..585108fa3 100644 --- a/powermgr/power_manager/src/main/js/test/power_manager_running_lock.test.js +++ b/powermgr/power_manager/src/main/js/test/power_manager_running_lock.test.js @@ -22,326 +22,307 @@ describe('PowerManagerRunningLockTest', function () { console.log("*************RunningLock Unit Test Begin*************"); /** - * @tc.number SUB_PowerSystem_PowerManager_JSTest_0110 - * @tc.name Create_Running_Lock_Promise_JSTest0010 - * @tc.desc Create running lock + * @tc.number SUB_PowerSystem_PowerManager_JSTest_0010 + * @tc.name Running_Lock_Lock_JSTest0010 + * @tc.desc Prevents the system from hibernating and sets the lock duration (deprecated since 9) */ - it('Create_Running_Lock_Promise_JSTest0010', 0, async function (done) { - runningLock.createRunningLock("running_lock_test_1", runningLock.RunningLockType.BACKGROUND) - .then(runninglock => { - expect(runninglock !== null).assertTrue(); - console.info('Create_Running_Lock_Promise_JSTest0010 success'); - done(); - }) - .catch(error => { - console.log('Create_Running_Lock_Promise_JSTest0010 error: ' + error); - expect().assertFail(); - done(); - }) - }) - - /** - * @tc.number SUB_PowerSystem_PowerManager_JSTest_0120 - * @tc.name Create_Running_Lock_CallBack_JSTest0020 - * @tc.desc Create running lock - */ - it('Create_Running_Lock_CallBack_JSTest0020', 0, async function (done) { - runningLock.createRunningLock("running_lock_test_2", runningLock.RunningLockType.BACKGROUND, - (error, runninglock) => { - if (typeof error === "undefined") { - console.info('Create_Running_Lock_CallBack_JSTest0020: runningLock is ' + runninglock); - expect(runninglock !== null).assertTrue(); - let used = runninglock.isUsed(); - console.info('Create_Running_Lock_CallBack_JSTest0020 is used: ' + used); - expect(used).assertFalse(); - runninglock.lock(500); - used = runninglock.isUsed(); - console.info('after lock Create_Running_Lock_CallBack_JSTest0020 is used: ' + used); - expect(used).assertTrue(); - console.info('Create_Running_Lock_CallBack_JSTest0020 success'); - done(); - } else { - console.log('Create_Running_Lock_CallBack_JSTest0020: ' + error); - expect().assertFail(); - done(); - } - }) - }) - - /** - * @tc.number SUB_PowerSystem_PowerManager_JSTest_0130 - * @tc.name Running_Lock_Lock_JSTest0030 - * @tc.desc Prevents the system from hibernating and sets the lock duration - */ - it('Running_Lock_Lock_JSTest0030', 0, async function (done) { - runningLock.createRunningLock("running_lock_test_3", runningLock.RunningLockType.BACKGROUND) + it('Running_Lock_Lock_JSTest0010', 0, async function (done) { + await runningLock.createRunningLock("Running_Lock_Lock_JSTest0010", runningLock.RunningLockType.BACKGROUND) .then(runninglock => { expect(runninglock !== null).assertTrue(); let used = runninglock.isUsed(); - console.info('Running_Lock_Lock_JSTest0030 is used: ' + used); + console.info('Running_Lock_Lock_JSTest0010 is used: ' + used); expect(used).assertFalse(); runninglock.lock(500); used = runninglock.isUsed(); - console.info('after lock Running_Lock_Lock_JSTest0030 is used: ' + used); + console.info('after lock Running_Lock_Lock_JSTest0010 is used: ' + used); expect(used).assertTrue(); - console.info('Running_Lock_Lock_JSTest0030 success'); - done(); }) .catch(error => { - console.log('Running_Lock_Lock_JSTest0030 error: ' + error); + console.log('Running_Lock_Lock_JSTest0010 error: ' + error); expect().assertFail(); - done(); }) + done(); }) /** - * @tc.number SUB_PowerSystem_PowerManager_JSTest_0140 - * @tc.name Running_Lock_used_JSTest0040 - * @tc.desc Checks whether a lock is held or in use + * @tc.number SUB_PowerSystem_PowerManager_JSTest_0020 + * @tc.name Running_Lock_used_JSTest0020 + * @tc.desc Checks whether a lock is held or in use (deprecated since 9) */ - it('Running_Lock_used_JSTest0040', 0, async function (done) { - runningLock.createRunningLock("running_lock_test_4", runningLock.RunningLockType.BACKGROUND) + it('Running_Lock_used_JSTest0020', 0, async function (done) { + runningLock.createRunningLock("Running_Lock_used_JSTest0020", runningLock.RunningLockType.BACKGROUND) .then(runninglock => { expect(runninglock !== null).assertTrue(); let used = runninglock.isUsed(); - console.info('Running_Lock_used_JSTest0040 used: ' + used); + console.info('Running_Lock_used_JSTest0020 used: ' + used); expect(used).assertFalse(); - console.info('Running_Lock_used_JSTest0040 success'); - done(); + console.info('Running_Lock_used_JSTest0020 success'); }) .catch(error => { - console.log('Running_Lock_used_JSTest0040 error: ' + error); + console.log('Running_Lock_used_JSTest0020 error: ' + error); expect().assertFail(); - done(); }) + done(); }) /** - * @tc.number SUB_PowerSystem_PowerManager_JSTest_0150 - * @tc.name Running_Lock_Unlock_JSTest0050 - * @tc.desc Release running lock + * @tc.number SUB_PowerSystem_PowerManager_JSTest_0030 + * @tc.name Running_Lock_Unlock_JSTest0030 + * @tc.desc Release running lock (deprecated since 9) */ - it('Running_Lock_Unlock_JSTest0050', 0, async function (done) { - runningLock.createRunningLock("running_lock_test_5", runningLock.RunningLockType.BACKGROUND) + it('Running_Lock_Unlock_JSTest0030', 0, async function (done) { + await runningLock.createRunningLock("Running_Lock_Unlock_JSTest0030", runningLock.RunningLockType.BACKGROUND) .then(runninglock => { expect(runninglock !== null).assertTrue(); let used = runninglock.isUsed(); - console.info('Running_Lock_Unlock_JSTest0050 is used: ' + used); + console.info('Running_Lock_Unlock_JSTest0030 is used: ' + used); expect(used).assertFalse(); runninglock.lock(500); used = runninglock.isUsed(); - console.info('after lock Running_Lock_Unlock_JSTest0050 is used: ' + used); + console.info('after lock Running_Lock_Unlock_JSTest0030 is used: ' + used); expect(used).assertTrue(); runninglock.unlock(); used = runninglock.isUsed(); - console.info('after unlock Running_Lock_Unlock_JSTest0050 is used: ' + used); + console.info('after unlock Running_Lock_Unlock_JSTest0030 is used: ' + used); expect(used).assertFalse(); - console.info('Running_Lock_Unlock_JSTest0050 success'); - done(); + console.info('Running_Lock_Unlock_JSTest0030 success'); }) .catch(error => { - console.log('Running_Lock_Unlock_JSTest0050 error: ' + error); + console.log('Running_Lock_Unlock_JSTest0030 error: ' + error); expect().assertFail(); - done(); }) + done(); }) + /** + * @tc.number SUB_PowerSystem_PowerManager_JSTest_0040 + * @tc.name Running_Lock_Hold_IsHolding_UnHold_JSTest0040 + * @tc.desc hold lock, is holding , unhold + */ + it('Running_Lock_Hold_IsHolding_UnHold_JSTest0040', 0, async function (done) { + try { + let isExec = false; + await runningLock.create("Running_Lock_Hold_IsHolding_UnHold_JSTest0040", runningLock.RunningLockType.BACKGROUND) + .then((runninglock) => { + isExec = true; + expect(runninglock !== null).assertTrue(); + let holding = runninglock.isHolding(); + console.info('Running_Lock_Hold_IsHolding_UnHold_JSTest0040 holding false:' + holding); + expect(holding).assertFalse(); + runninglock.hold(1000); // hold 1000ms + holding = runninglock.isHolding(); + console.info('Running_Lock_Hold_IsHolding_UnHold_JSTest0040 holding true:' + holding); + expect(holding).assertTrue(); + runninglock.unhold(); + expect(runninglock.isHolding()).assertFalse(); + }) + .catch((error) => { + isExec = true; + console.info('Running_Lock_Hold_IsHolding_UnHold_JSTest0040 error:' + (typeof error)); + expect(typeof error !== "undefined").assertTrue(); + console.info('Running_Lock_Hold_IsHolding_UnHold_JSTest0040 error code:' + error.code + " msg: " + error.message); + }) + .finally(() => { + expect(isExec).assertTrue(); + }) + } catch (e) { + console.info('Running_Lock_Hold_IsHolding_UnHold_JSTest0040 error:' + e); + expect().assertFail(); + } + done(); + }) + /** - * @tc.number SUB_PowerSystem_PowerManager_JSTest_0160 - * @tc.name Enum_RunningLock_Type_Background_JSTest0060 + * @tc.number SUB_PowerSystem_PowerManager_JSTest_0050 + * @tc.name Enum_RunningLock_Type_Background_JSTest0050 * @tc.desc The lock type is BACKGROUND */ - it('Enum_RunningLock_Type_Background_JSTest0060', 0, function () { + it('Enum_RunningLock_Type_Background_JSTest0050', 0, function () { let runningLockType = runningLock.RunningLockType.BACKGROUND; console.info('runningLockType = ' + runningLockType); expect(runningLockType == 1).assertTrue(); - console.info('Enum_RunningLock_Type_Background_JSTest0060 success'); + console.info('Enum_RunningLock_Type_Background_JSTest0050 success'); }) /** - * @tc.number SUB_PowerSystem_PowerManager_JSTest_0170 - * @tc.name Enum_RunningLock_Type_Proximityscreencontrol_JSTest0070 + * @tc.number SUB_PowerSystem_PowerManager_JSTest_0060 + * @tc.name Enum_RunningLock_Type_Proximityscreencontrol_JSTest0060 * @tc.desc The lock type is PROXIMITY_SCREEN_CONTROL */ - it('Enum_RunningLock_Type_Proximityscreencontrol_JSTest0070', 0, function () { + it('Enum_RunningLock_Type_Proximityscreencontrol_JSTest0060', 0, function () { let runningLockType = runningLock.RunningLockType.PROXIMITY_SCREEN_CONTROL; console.info('runningLockType = ' + runningLockType); expect(runningLockType == 2).assertTrue(); - console.info('Enum_RunningLock_Type_Proximityscreencontrol_JSTest0070 success'); + console.info('Enum_RunningLock_Type_Proximityscreencontrol_JSTest0060 success'); }) /** - * @tc.number SUB_PowerSystem_PowerManager_JSTest_0180 - * @tc.name Is_Runninglock_Type_Supported_Promise_Test1_JSTest0080 - * @tc.desc Checks whether the specified RunningLockType is supported. + * @tc.number SUB_PowerSystem_PowerManager_JSTest_0070 + * @tc.name Is_Runninglock_Type_Supported_Promise_JSTest0070 + * @tc.desc Checks whether the specified RunningLockType is supported (deprecated since 9) */ - it('Is_Runninglock_Type_Supported_Promise_Test1_JSTest0080', 0, async function (done) { - runningLock.isRunningLockTypeSupported(runningLock.RunningLockType.PROXIMITY_SCREEN_CONTROL) + it('Is_Runninglock_Type_Supported_Promise_JSTest0070', 0, async function (done) { + await runningLock.isRunningLockTypeSupported(runningLock.RunningLockType.PROXIMITY_SCREEN_CONTROL) .then(supported => { - console.info('is_runninglock_type_supported_test_1 PROXIMITY_SCREEN_CONTROL supported is ' + supported); + console.info('Is_Runninglock_Type_Supported_Promise_JSTest0070 PROXIMITY_SCREEN_CONTROL supported is ' + supported); expect(supported).assertTrue(); - console.info('is_runninglock_type_supported_test_1 success'); - done(); + console.info('Is_Runninglock_Type_Supported_Promise_JSTest0070 success'); }) .catch(error => { - console.log('is_runninglock_type_supported_test_1 error: ' + error); + console.log('Is_Runninglock_Type_Supported_Promise_JSTest0070 error: ' + error); expect().assertFail(); - done(); }) + done(); }) /** - * @tc.number SUB_PowerSystem_PowerManager_JSTest_0190 - * @tc.name Is_Runninglock_Type_Supported_Promise_Test2_JSTest0090 - * @tc.desc Checks whether the specified RunningLockType is supported. + * @tc.number SUB_PowerSystem_PowerManager_JSTest_0080 + * @tc.name Is_Runninglock_Type_Supported_Promise_JSTest0080 + * @tc.desc Checks whether the specified RunningLockType is supported (deprecated since 9) */ - it('Is_Runninglock_Type_Supported_Promise_Test2_JSTest0090', 0, async function (done) { - runningLock.isRunningLockTypeSupported(runningLock.RunningLockType.BACKGROUND) + it('Is_Runninglock_Type_Supported_Promise_JSTest0080', 0, async function (done) { + await runningLock.isRunningLockTypeSupported(runningLock.RunningLockType.BACKGROUND) .then(supported => { - console.info('Is_Runninglock_Type_Supported_Promise_Test2 BACKGROUND supported is ' + supported); + console.info('Is_Runninglock_Type_Supported_Promise_JSTest0080 BACKGROUND supported is ' + supported); expect(supported).assertTrue(); - console.info('Is_Runninglock_Type_Supported_Promise_Test2 success'); - done(); + console.info('Is_Runninglock_Type_Supported_Promise_JSTest0080 success'); }) .catch(error => { - console.log('Is_Runninglock_Type_Supported_Promise_Test2 error: ' + error); + console.log('Is_Runninglock_Type_Supported_Promise_JSTest0080 error: ' + error); expect().assertFail(); - done(); }) + done(); }) /** - * @tc.number SUB_PowerSystem_PowerManager_JSTest_0200 - * @tc.name Is_Runninglock_Type_Supported_Callback_test3_JSTest0100 - * @tc.desc Checks whether the specified RunningLockType is supported. + * @tc.number SUB_PowerSystem_PowerManager_JSTest_0090 + * @tc.name Is_Runninglock_Type_Supported_Callback_JSTest0090 + * @tc.desc Checks whether the specified RunningLockType is supported (deprecated since 9) */ - it('Is_Runninglock_Type_Supported_Callback_test3_JSTest0100', 0, async function (done) { + it('Is_Runninglock_Type_Supported_Callback_JSTest0090', 0, async function (done) { runningLock.isRunningLockTypeSupported(runningLock.RunningLockType.BACKGROUND, (error, supported) => { if (typeof error === "undefined") { - console.info('Is_Runninglock_Type_Supported_Callback_test3_JSTest supported is ' + supported); + console.info('Is_Runninglock_Type_Supported_Callback_JSTest0090 supported is ' + supported); expect(supported).assertTrue(); - console.info('Is_Runninglock_Type_Supported_Callback_test3_JSTest success'); - done(); + console.info('Is_Runninglock_Type_Supported_Callback_JSTest0090 success'); } else { - console.log('Is_Runninglock_Type_Supported_Callback_test3_JSTest: ' + error); + console.log('Is_Runninglock_Type_Supported_Callback_JSTest0090: ' + error); expect().assertFail(); - done(); } }) + done(); }) - /** - * @tc.number SUB_PowerSystem_PowerManager_JSTest_0210 - * @tc.name Create_Running_Lock_Promise_JSTest0210 - * @tc.desc Create lock, hold lock, unlock + /** + * @tc.number SUB_PowerSystem_PowerManager_JSTest_0100 + * @tc.name Is_Supported_JSTest0100 + * @tc.desc Checks whether the specified RunningLockType is supported. */ - it('Create_Running_Lock_Promise_JSTest0210', 0, async function (done) { + it('Is_Supported_JSTest0100', 0, async function (done) { try { - let isExec = false; - runningLock.create("Create_Running_Lock_Promise_JSTest0210", runningLock.RunningLockType.BACKGROUND) - .then((error, runninglock) => { - isExec = true; - expect(typeof error === "undefined").assertTrue(); - expect(runninglock !== null).assertTrue(); - let holding = runninglock.isHolding(); - console.info('Create_Running_Lock_Promise_JSTest0210 holding false:' + holding); - expect(holding).assertFalse(); - runninglock.hold(1000); // hold 1000ms - holding = runninglock.isHolding(); - console.info('Create_Running_Lock_Promise_JSTest0210 holding true:' + holding); - expect(holding).assertTrue(); - runninglock.unhold(); - expect(runninglock.isHolding()).assertFalse(); - }).finally(() => { - expect(isExec).assertTrue(); - }) + let background = runningLock.isSupported(runningLock.RunningLockType.BACKGROUND) + expect(background).assertTrue(); } catch (e) { - console.info('Create_Running_Lock_Promise_JSTest0210 error:' + e); + console.info('Is_Supported_JSTest0100 code:' + e); expect().assertFail(); } done(); }) - // New interface /** - * @tc.number SUB_PowerSystem_PowerManager_JSTest_0220 - * @tc.name Create_Running_Lock_Promise_Invalid_JSTest0220 - * @tc.desc Create lock input invalid value + * @tc.number SUB_PowerSystem_PowerManager_JSTest_0110 + * @tc.name Create_Running_Lock_Promise_JSTest0110 + * @tc.desc Create running lock promise (deprecated since 9) */ - it('Create_Running_Lock_Promise_Invalid_JSTest0220', 0, async function (done) { - try { - runningLock.create(0, runningLock.RunningLockType.BACKGROUND) - .then((error, runninglock) => { - expect().assertFail(); - }) - } catch (e) { - console.info('Create_Running_Lock_Promise_Invalid_JSTest0220 code:' + e.code + "msg:" + e.message); - // 401: Invalid input parameter - expect(e.code === 401).assertTrue(); - } + it('Create_Running_Lock_Promise_JSTest0110', 0, async function (done) { + await runningLock.createRunningLock("running_lock_test_1", runningLock.RunningLockType.BACKGROUND) + .then(runninglock => { + expect(runninglock !== null).assertTrue(); + console.info('Create_Running_Lock_Promise_JSTest0110 success'); + }) + .catch(error => { + console.log('Create_Running_Lock_Promise_JSTest0110 error: ' + error); + expect().assertFail(); + }) done(); }) /** - * @tc.number SUB_PowerSystem_PowerManager_JSTest_0230 - * @tc.name Create_Running_Lock_Callback_JSTest0230 - * @tc.desc Create lock, hold lock, unlock + * @tc.number SUB_PowerSystem_PowerManager_JSTest_0120 + * @tc.name Create_Running_Lock_CallBack_JSTest0120 + * @tc.desc Create running lock callback (deprecated since 9) */ - it('Create_Running_Lock_Callback_JSTest0230', 0, async function (done) { + it('Create_Running_Lock_CallBack_JSTest0120', 0, async function (done) { + runningLock.createRunningLock("Create_Running_Lock_CallBack_JSTest0120", runningLock.RunningLockType.BACKGROUND, + (error, runninglock) => { + if (typeof error === "undefined") { + console.info('Create_Running_Lock_CallBack_JSTest0120: runningLock is ' + runninglock); + expect(runninglock !== null).assertTrue(); + let used = runninglock.isUsed(); + console.info('Create_Running_Lock_CallBack_JSTest0120 is used: ' + used); + expect(used).assertFalse(); + runninglock.lock(500); + used = runninglock.isUsed(); + console.info('after lock Create_Running_Lock_CallBack_JSTest0120 is used: ' + used); + expect(used).assertTrue(); + console.info('Create_Running_Lock_CallBack_JSTest0120 success'); + } else { + console.log('Create_Running_Lock_CallBack_JSTest0120: ' + error); + expect().assertFail(); + } + }) + done(); + }) + + /** + * @tc.number SUB_PowerSystem_PowerManager_JSTest_0130 + * @tc.name Create_Running_Lock_Promise_JSTest0130 + * @tc.desc Create lock promise + */ + it('Create_Running_Lock_Promise_JSTest0130', 0, async function (done) { try { - runningLock.create("Create_Running_Lock_Callback_JSTest0230", runningLock.RunningLockType.BACKGROUND, - (error, runninglock) => { - expect(typeof error === "undefined").assertTrue(); + let isExec = false; + await runningLock.create("Create_Running_Lock_Promise_JSTest0130", runningLock.RunningLockType.BACKGROUND) + .then((runninglock) => { + isExec = true; expect(runninglock !== null).assertTrue(); - runninglock.hold(1000); // hold 1000ms - let holding = runninglock.isHolding(); - console.info('Create_Running_Lock_Callback_JSTest0230 holding true:' + holding); - expect(holding).assertTrue(); - runninglock.unhold(); - holding = runninglock.isHolding(); - expect(holding).assertFalse(); - console.info('Create_Running_Lock_Callback_JSTest0230 holding false:' + holding); - }); + console.info('Create_Running_Lock_Promise_JSTest0130 success'); + }) + .catch((error) => { + isExec = true; + console.info('Create_Running_Lock_Promise_JSTest0130 error:' + (typeof error)); + expect(typeof error !== "undefined").assertTrue(); + console.info('Create_Running_Lock_Promise_JSTest0130 error code:' + error.code + " msg: " + error.message); + }) + .finally(() => { + expect(isExec).assertTrue(); + }) } catch (e) { - console.info('Create_Running_Lock_Callback_JSTest0230 error:' + e); + console.info('Create_Running_Lock_Promise_JSTest0130 error:' + e); expect().assertFail(); } done(); }) /** - * @tc.number SUB_PowerSystem_PowerManager_JSTest_0240 - * @tc.name Create_Running_Lock_Callback_Invalid_JSTest0240 - * @tc.desc Create lock input invalid value + * @tc.number SUB_PowerSystem_PowerManager_JSTest_0140 + * @tc.name Create_Running_Lock_Callback_JSTest0140 + * @tc.desc Create lock callback */ - it('Create_Running_Lock_Callback_Invalid_JSTest0240', 0, async function (done) { + it('Create_Running_Lock_Callback_JSTest0140', 0, async function (done) { try { - runningLock.create("Create_Running_Lock_Callback_Invalid_JSTest0240", "invalid", + runningLock.create("Create_Running_Lock_Callback_JSTest0140", runningLock.RunningLockType.BACKGROUND, (error, runninglock) => { - expect().assertFail(); + expect(typeof error === "undefined").assertTrue(); + expect(runninglock !== null).assertTrue(); + console.info('Create_Running_Lock_Callback_JSTest0140 success'); }); } catch (e) { - console.info('Create_Running_Lock_Callback_Invalid_JSTest0240 code:' + e.code + "msg:" + e.message); - // 401: Invalid input parameter - expect(e.code === 401).assertTrue(); + console.info('Create_Running_Lock_Callback_JSTest0230 error:' + e); + expect().assertFail(); } done(); }) - - /** - * @tc.number SUB_PowerSystem_PowerManager_JSTest_0250 - * @tc.name Is_Supported_JSTest0250 - * @tc.desc Checks whether the specified RunningLockType is supported. - */ - it('Is_Supported_JSTest0250', 0, async function (done) { - try { - let background = runningLock.isSupported(runningLock.RunningLockType.BACKGROUND) - expect(background).assertTrue(); - } catch (e) { - console.info('Is_Supported_JSTest0250 code:' + e); - expect().assertFail(); - } - done(); - }) }) } -- GitLab