未验证 提交 02204690 编写于 作者: O openharmony_ci 提交者: Gitee

!6095 test: power用例整改

Merge pull request !6095 from qiuxiangdong/I5WVHE
...@@ -23,340 +23,265 @@ describe('PowerManagerPowerTest', function () { ...@@ -23,340 +23,265 @@ describe('PowerManagerPowerTest', function () {
/** /**
* @tc.number SUB_PowerSystem_PowerManager_JSTest_0010 * @tc.number SUB_PowerSystem_PowerManager_JSTest_0010
* @tc.name Power_Is_Screnn_On_Promise_JSTest0010 * @tc.name Power_Reboot_Device_JSTest0010
* @tc.desc Checks whether the screen of a device is on or off * @tc.desc reboot device (deprecated since 9)
*/ */
it('Power_Is_Screnn_On_Promise_JSTest0010', 0, async function (done) { it('Power_Reboot_Device_JSTest0010', 0, function () {
power.wakeupDevice("Power_Is_Screnn_On_Promise_JSTest0010"); // Reboot tests are not performed by default
power.isScreenOn() 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 => { .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(); expect(screenOn).assertTrue();
console.info('Power_Is_Screnn_On_Promise_JSTest0010 success'); console.info('Power_Is_Screnn_On_Promise_JSTest0020 success');
done();
}) })
.catch(error => { .catch(error => {
console.log('Power_Is_Screnn_On_Promise_JSTest0010 error: ' + error); console.log('Power_Is_Screnn_On_Promise_JSTest0020 error: ' + error);
expect().assertFail(); expect().assertFail();
done();
}) })
done();
}) })
/** /**
* @tc.number SUB_PowerSystem_PowerManager_JSTest_0020 * @tc.number SUB_PowerSystem_PowerManager_JSTest_0030
* @tc.name Power_Is_Screnn_On_Callback_JSTest0020 * @tc.name Power_Is_Screnn_On_Callback_JSTest0030
* @tc.desc Checks whether the screen of a device is on or off * @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) { it('Power_Is_Screnn_On_Callback_JSTest0030', 0, async function (done) {
power.wakeupDevice("Power_Is_Screnn_On_Callback_JSTest0020"); power.wakeupDevice("Power_Is_Screnn_On_Callback_JSTest0030");
power.isScreenOn((error, screenOn) => { power.isScreenOn((error, screenOn) => {
if (typeof error === "undefined") { 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(); expect(screenOn).assertTrue();
console.info('Power_Is_Screnn_On_Callback_JSTest0020 success'); console.info('Power_Is_Screnn_On_Callback_JSTest0030 success');
done();
} else { } else {
console.log('Power_Is_Screnn_On_Callback_JSTest0020: ' + error); console.log('Power_Is_Screnn_On_Callback_JSTest0030: ' + error);
expect().assertFail(); expect().assertFail();
done();
} }
}) })
done();
}) })
/** /**
* @tc.number SUB_PowerSystem_PowerManager_JSTest_0030 * @tc.number SUB_PowerSystem_PowerManager_JSTest_0040
* @tc.name Power_WakeupDevices_String_JSTest0030 * @tc.name Power_Is_Active_JSTest0040
* @tc.desc Try to wakeup the device and let screen on * @tc.desc On and Off Screen and get the current screen on and off
*/ */
it('Power_WakeupDevices_String_JSTest0030', 0, async function (done) { it('Power_Is_Active_JSTest0040', 0, function () {
power.isScreenOn() try {
.then(screenOn => { power.suspend();
console.info('Power_WakeupDevices_String_JSTest0030: The current screenOn is ' + screenOn); power.wakeup('Power_Is_Active_JSTest0040');
if (screenOn) { let on = power.isActive();
power.suspendDevice(); console.info('Power_Is_Active_JSTest0040 on:' + on);
} expect(on).assertTrue();
}) power.suspend();
.catch(error => { let off = power.isActive();
console.log('Power_WakeupDevices_String_JSTest0030 error: ' + error); console.info('Power_Is_Active_JSTest0040 off:' + off);
expect().assertFail(); expect(off).assertFalse();
done(); } catch (e) {
}) console.info('Power_Is_Active_JSTest0040:' + e);
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(); expect().assertFail();
done(); }
})
}, 2000);
}) })
/** /**
* @tc.number SUB_PowerSystem_PowerManager_JSTest_0040 * @tc.number SUB_PowerSystem_PowerManager_JSTest_0050
* @tc.name Power_SuspendDevices_JSTest0040 * @tc.name Power_Get_Power_Mode_JSTest0050
* @tc.desc Try to suspend the device and let screen off * @tc.desc Gets and sets the power mode
*/ */
it('Power_SuspendDevices_JSTest0040', 0, async function (done) { it('Power_Get_Power_Mode_JSTest0050', 0, async function () {
power.isScreenOn() let currentMode = power.getPowerMode();
.then(screenOn => { console.info('Power_Get_Power_Mode_JSTest0050 currentMode:' + currentMode);
console.info('Power_SuspendDevices_JSTest0040: The current screenOn is ' + screenOn); expect(currentMode >= power.DevicePowerMode.MODE_NORMAL &&
if (!screenOn) { currentMode <= power.DevicePowerMode.MODE_EXTREME_POWER_SAVE).assertTrue();
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);
}) })
/** /**
* @tc.number SUB_PowerSystem_PowerManager_JSTest_0070 * @tc.number SUB_PowerSystem_PowerManager_JSTest_0060
* @tc.name Power_Device_Power_Mode_MODENORMAL_JSTest0070 * @tc.name Power_Device_Power_Mode_MODENORMAL_JSTest0060
* @tc.desc Get device power mode MODE_NORMAL * @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; let devicePowerMode = power.DevicePowerMode.MODE_NORMAL;
console.info('MODE_NORMAL = ' + devicePowerMode); console.info('MODE_NORMAL = ' + devicePowerMode);
expect(devicePowerMode === 600).assertTrue(); 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.name Power_Device_Power_Mode_MODEPOWERSAVE_JSTest0080
* @tc.desc Get device power mode MODE_POWER_SAVE * @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; let devicePowerMode = power.DevicePowerMode.MODE_POWER_SAVE;
console.info('MODE_POWER_SAVE = ' + devicePowerMode); console.info('MODE_POWER_SAVE = ' + devicePowerMode);
expect(devicePowerMode === 601).assertTrue(); 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.name Power_Device_pPower_Mode_MODEPERFORMANCE_JSTest0090
* @tc.desc Get device power mode MODE_PERFORMANCE * @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; let devicePowerMode = power.DevicePowerMode.MODE_PERFORMANCE;
console.info('MODE_PERFORMANCE = ' + devicePowerMode); console.info('MODE_PERFORMANCE = ' + devicePowerMode);
expect(devicePowerMode === 602).assertTrue(); expect(devicePowerMode === 602).assertTrue();
}) })
/** /**
* @tc.number SUB_PowerSystem_PowerManager_JSTest_0100 * @tc.number SUB_PowerSystem_PowerManager_JSTest_0090
* @tc.name Power_Device_Power_Mode_MODE_EXTREME_POWER_SAVE_JSTest0100 * @tc.name Power_Device_Power_Mode_MODE_EXTREME_POWER_SAVE_JSTest0090
* @tc.desc Get device power mode MODE_EXTREME_POWER_SAVE * @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; let devicePowerMode = power.DevicePowerMode.MODE_EXTREME_POWER_SAVE;
console.info('MODE_EXTREME_POWER_SAVE = ' + devicePowerMode); console.info('MODE_EXTREME_POWER_SAVE = ' + devicePowerMode);
expect(devicePowerMode === 603).assertTrue(); expect(devicePowerMode === 603).assertTrue();
}) })
// New interface
/** /**
* @tc.number SUB_PowerSystem_PowerManager_JSTest_0110 * @tc.number SUB_PowerSystem_PowerManager_JSTest_0150
* @tc.name Power_Get_Set_Mode_Promise_JSTest0110 * @tc.name Power_WakeupDevices_String_JSTest0150
* @tc.desc Gets and sets the power mode * @tc.desc Try to wakeup the device and let screen on (SystemApi)
*/ */
it('Power_Get_Set_Mode_Promise_JSTest0110', 0, async function (done) { it('Power_WakeupDevices_String_JSTest0150', 0, async function (done) {
let currentMode = power.getPowerMode(); await power.isScreenOn()
console.info('Power_Get_Set_Mode_Promise_JSTest0110 currentMode:' + currentMode); .then(screenOn => {
expect(currentMode >= power.DevicePowerMode.MODE_NORMAL && console.info('Power_WakeupDevices_String_JSTest0150: The current screenOn is ' + screenOn);
currentMode <= power.DevicePowerMode.MODE_EXTREME_POWER_SAVE).assertTrue(); if (screenOn) {
try { power.suspendDevice();
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) { .catch(error => {
console.info('Power_Get_Set_Mode_Promise_JSTest0110 error:' + e); console.log('Power_WakeupDevices_String_JSTest0150 error: ' + error);
expect().assertFail(); expect().assertFail();
} })
power.setPowerMode(currentMode); 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();
})
}, 2000);
done(); done();
}) })
/** /**
* @tc.number SUB_PowerSystem_PowerManager_JSTest_0120 * @tc.number SUB_PowerSystem_PowerManager_JSTest_0160
* @tc.name Power_Get_Set_Mode_Promise_Invalid_JSTest0120 * @tc.name Power_SuspendDevices_JSTest0160
* @tc.desc Set the wrong power mode * @tc.desc Try to suspend the device and let screen off (SystemApi)
*/ */
it('Power_Get_Set_Mode_Promise_Invalid_JSTest0120', 0, async function (done) { it('Power_SuspendDevices_JSTest0160', 0, async function (done) {
try { await power.isScreenOn()
// invalid mode .then(screenOn => {
power.setPowerMode('').then(() => { console.info('Power_SuspendDevices_JSTest0160: The current screenOn is ' + screenOn);
console.info('Power_Get_Set_Mode_Promise_Invalid_JSTest0120 string failed'); if (!screenOn) {
power.wakeupDevice("Power_SuspendDevices_JSTest0160");
}
})
.catch(error => {
console.log('Power_SuspendDevices_JSTest0160 error: ' + error);
expect().assertFail(); expect().assertFail();
}) })
} catch (e) { setTimeout(function(){
console.info('Power_Get_Set_Mode_Promise_Invalid_JSTest0120 code:' + e.code + 'msg:' + e.message); power.suspendDevice();
// 401: Invalid input parameter console.info('Power_SuspendDevices_JSTest0160: SuspendDevice end');
expect(e.code === 401).assertTrue(); power.isScreenOn()
} .then(screenOn => {
console.info('Power_SuspendDevices_JSTest0160: The current screenOn is ' + screenOn);
try { expect(screenOn).assertFalse();
// Number of invalid parameters console.info('Power_SuspendDevices_JSTest0160 success');
power.setPowerMode('', '', 0).then(() => { })
console.info('Power_Get_Set_Mode_Promise_Invalid_JSTest0120 number failed'); .catch(error => {
console.log('Power_SuspendDevices_JSTest0160 error: ' + error);
expect().assertFail(); expect().assertFail();
}) })
} catch (e) { }, 2000);
console.info('Power_Get_Set_Mode_Promise_Invalid_JSTest0120 code:' + e.code + 'msg:' + e.message);
// 401: Invalid input parameter
expect(e.code === 401).assertTrue();
}
done(); done();
}) })
/** /**
* @tc.number SUB_PowerSystem_PowerManager_JSTest_0130 * @tc.number SUB_PowerSystem_PowerManager_JSTest_0170
* @tc.name Power_Get_Set_Mode_Callback_JSTest0130 * @tc.name Power_Set_Mode_Promise_JSTest0110
* @tc.desc Gets and sets the power mode * @tc.desc Gets and sets the power mode (SystemApi)
*/ */
it('Power_Get_Set_Mode_Callback_JSTest0130', 0, async function (done) { it('Power_Set_Mode_Promise_JSTest0110', 0, async function (done) {
if (false) {
let currentMode = power.getPowerMode(); let currentMode = power.getPowerMode();
console.info('Power_Get_Set_Mode_Callback_JSTest0130 currentMode:' + currentMode); console.info('Power_Set_Mode_Promise_JSTest0110 currentMode:' + currentMode);
expect(currentMode >= power.DevicePowerMode.MODE_NORMAL && expect(currentMode >= power.DevicePowerMode.MODE_NORMAL &&
currentMode <= power.DevicePowerMode.MODE_EXTREME_POWER_SAVE).assertTrue(); currentMode <= power.DevicePowerMode.MODE_EXTREME_POWER_SAVE).assertTrue();
try { try {
power.setPowerMode(power.DevicePowerMode.MODE_PERFORMANCE, (error) => { let isExec = false;
console.info('Power_Get_Set_Mode_Callback_JSTest0130 error:' + (typeof error)); 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(); expect(typeof error === "undefined").assertTrue();
let mode = power.getPowerMode(); let mode = power.getPowerMode();
console.info('Power_Get_Set_Mode_Callback_JSTest0130 mode:' + mode); console.info('Power_Set_Mode_Promise_JSTest0110 mode:' + mode);
expect(mode === power.DevicePowerMode.MODE_PERFORMANCE).assertTrue(); expect(mode === power.DevicePowerMode.MODE_POWER_SAVE).assertTrue();
}).finally(() => {
expect(isExec).assertTrue();
}) })
} catch (e) { } catch (e) {
console.info('Power_Get_Set_Mode_Callback_JSTest0130 error:' + e); console.info('Power_Set_Mode_Promise_JSTest0110 error:' + e);
expect().assertFail(); expect().assertFail();
} }
power.setPowerMode(currentMode); 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) => {
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();
} }
done(); done();
}) })
/** /**
* @tc.number SUB_PowerSystem_PowerManager_JSTest_0150 * @tc.number SUB_PowerSystem_PowerManager_JSTest_0180
* @tc.name Power_Reboot_JSTest0150 * @tc.name Power_Set_Mode_Callback_JSTest0180
* @tc.desc reboot * @tc.desc Gets and sets the power mode (SystemApi)
*/ */
it('Power_Reboot_JSTest0150', 0, function () { it('Power_Set_Mode_Callback_JSTest0180', 0, async function (done) {
// Reboot tests are not performed by default
if (false) { 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 { try {
power.reboot('Power_Reboot_JSTest0150'); power.setPowerMode(power.DevicePowerMode.MODE_PERFORMANCE, (error) => {
} catch (e) { console.info('Power_Set_Mode_Callback_JSTest0180 error:' + (typeof error));
console.info('Power_Reboot_JSTest0150 error:' + e); expect(typeof error === "undefined").assertTrue();
expect().assertFail(); let mode = power.getPowerMode();
} console.info('Power_Set_Mode_Callback_JSTest0180 mode:' + mode);
} expect(mode === power.DevicePowerMode.MODE_PERFORMANCE).assertTrue();
}) })
/**
* @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) { } catch (e) {
console.info('Power_Wakeup_Suspend_IsActive_JSTest0160:' + e); console.info('Power_Set_Mode_Callback_JSTest0180 error:' + e);
expect().assertFail(); expect().assertFail();
} }
}) power.setPowerMode(currentMode);
/**
* @tc.number SUB_PowerSystem_PowerManager_JSTest_0170
* @tc.name Power_Wakeup_Invalid_JSTest0170
* @tc.desc wakeup Input invalid parameter
*/
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();
} }
done();
}) })
}) })
} }
...@@ -22,323 +22,304 @@ describe('PowerManagerRunningLockTest', function () { ...@@ -22,323 +22,304 @@ describe('PowerManagerRunningLockTest', function () {
console.log("*************RunningLock Unit Test Begin*************"); console.log("*************RunningLock Unit Test Begin*************");
/** /**
* @tc.number SUB_PowerSystem_PowerManager_JSTest_0110 * @tc.number SUB_PowerSystem_PowerManager_JSTest_0010
* @tc.name Create_Running_Lock_Promise_JSTest0010 * @tc.name Running_Lock_Lock_JSTest0010
* @tc.desc Create running lock * @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) { it('Running_Lock_Lock_JSTest0010', 0, async function (done) {
runningLock.createRunningLock("running_lock_test_3", runningLock.RunningLockType.BACKGROUND) await runningLock.createRunningLock("Running_Lock_Lock_JSTest0010", runningLock.RunningLockType.BACKGROUND)
.then(runninglock => { .then(runninglock => {
expect(runninglock !== null).assertTrue(); expect(runninglock !== null).assertTrue();
let used = runninglock.isUsed(); 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(); expect(used).assertFalse();
runninglock.lock(500); runninglock.lock(500);
used = runninglock.isUsed(); 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(); expect(used).assertTrue();
console.info('Running_Lock_Lock_JSTest0030 success');
done();
}) })
.catch(error => { .catch(error => {
console.log('Running_Lock_Lock_JSTest0030 error: ' + error); console.log('Running_Lock_Lock_JSTest0010 error: ' + error);
expect().assertFail(); expect().assertFail();
done();
}) })
done();
}) })
/** /**
* @tc.number SUB_PowerSystem_PowerManager_JSTest_0140 * @tc.number SUB_PowerSystem_PowerManager_JSTest_0020
* @tc.name Running_Lock_used_JSTest0040 * @tc.name Running_Lock_used_JSTest0020
* @tc.desc Checks whether a lock is held or in use * @tc.desc Checks whether a lock is held or in use (deprecated since 9)
*/ */
it('Running_Lock_used_JSTest0040', 0, async function (done) { it('Running_Lock_used_JSTest0020', 0, async function (done) {
runningLock.createRunningLock("running_lock_test_4", runningLock.RunningLockType.BACKGROUND) runningLock.createRunningLock("Running_Lock_used_JSTest0020", runningLock.RunningLockType.BACKGROUND)
.then(runninglock => { .then(runninglock => {
expect(runninglock !== null).assertTrue(); expect(runninglock !== null).assertTrue();
let used = runninglock.isUsed(); let used = runninglock.isUsed();
console.info('Running_Lock_used_JSTest0040 used: ' + used); console.info('Running_Lock_used_JSTest0020 used: ' + used);
expect(used).assertFalse(); expect(used).assertFalse();
console.info('Running_Lock_used_JSTest0040 success'); console.info('Running_Lock_used_JSTest0020 success');
done();
}) })
.catch(error => { .catch(error => {
console.log('Running_Lock_used_JSTest0040 error: ' + error); console.log('Running_Lock_used_JSTest0020 error: ' + error);
expect().assertFail(); expect().assertFail();
done();
}) })
done();
}) })
/** /**
* @tc.number SUB_PowerSystem_PowerManager_JSTest_0150 * @tc.number SUB_PowerSystem_PowerManager_JSTest_0030
* @tc.name Running_Lock_Unlock_JSTest0050 * @tc.name Running_Lock_Unlock_JSTest0030
* @tc.desc Release running lock * @tc.desc Release running lock (deprecated since 9)
*/ */
it('Running_Lock_Unlock_JSTest0050', 0, async function (done) { it('Running_Lock_Unlock_JSTest0030', 0, async function (done) {
runningLock.createRunningLock("running_lock_test_5", runningLock.RunningLockType.BACKGROUND) await runningLock.createRunningLock("Running_Lock_Unlock_JSTest0030", runningLock.RunningLockType.BACKGROUND)
.then(runninglock => { .then(runninglock => {
expect(runninglock !== null).assertTrue(); expect(runninglock !== null).assertTrue();
let used = runninglock.isUsed(); 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(); expect(used).assertFalse();
runninglock.lock(500); runninglock.lock(500);
used = runninglock.isUsed(); 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(); expect(used).assertTrue();
runninglock.unlock(); runninglock.unlock();
used = runninglock.isUsed(); 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(); expect(used).assertFalse();
console.info('Running_Lock_Unlock_JSTest0050 success'); console.info('Running_Lock_Unlock_JSTest0030 success');
done();
}) })
.catch(error => { .catch(error => {
console.log('Running_Lock_Unlock_JSTest0050 error: ' + error); console.log('Running_Lock_Unlock_JSTest0030 error: ' + error);
expect().assertFail(); 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.number SUB_PowerSystem_PowerManager_JSTest_0050
* @tc.name Enum_RunningLock_Type_Background_JSTest0060 * @tc.name Enum_RunningLock_Type_Background_JSTest0050
* @tc.desc The lock type is BACKGROUND * @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; let runningLockType = runningLock.RunningLockType.BACKGROUND;
console.info('runningLockType = ' + runningLockType); console.info('runningLockType = ' + runningLockType);
expect(runningLockType == 1).assertTrue(); 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.number SUB_PowerSystem_PowerManager_JSTest_0060
* @tc.name Enum_RunningLock_Type_Proximityscreencontrol_JSTest0070 * @tc.name Enum_RunningLock_Type_Proximityscreencontrol_JSTest0060
* @tc.desc The lock type is PROXIMITY_SCREEN_CONTROL * @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; let runningLockType = runningLock.RunningLockType.PROXIMITY_SCREEN_CONTROL;
console.info('runningLockType = ' + runningLockType); console.info('runningLockType = ' + runningLockType);
expect(runningLockType == 2).assertTrue(); 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.number SUB_PowerSystem_PowerManager_JSTest_0070
* @tc.name Is_Runninglock_Type_Supported_Promise_Test1_JSTest0080 * @tc.name Is_Runninglock_Type_Supported_Promise_JSTest0070
* @tc.desc Checks whether the specified RunningLockType is supported. * @tc.desc Checks whether the specified RunningLockType is supported (deprecated since 9)
*/ */
it('Is_Runninglock_Type_Supported_Promise_Test1_JSTest0080', 0, async function (done) { it('Is_Runninglock_Type_Supported_Promise_JSTest0070', 0, async function (done) {
runningLock.isRunningLockTypeSupported(runningLock.RunningLockType.PROXIMITY_SCREEN_CONTROL) await runningLock.isRunningLockTypeSupported(runningLock.RunningLockType.PROXIMITY_SCREEN_CONTROL)
.then(supported => { .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(); expect(supported).assertTrue();
console.info('is_runninglock_type_supported_test_1 success'); console.info('Is_Runninglock_Type_Supported_Promise_JSTest0070 success');
done();
}) })
.catch(error => { .catch(error => {
console.log('is_runninglock_type_supported_test_1 error: ' + error); console.log('Is_Runninglock_Type_Supported_Promise_JSTest0070 error: ' + error);
expect().assertFail(); expect().assertFail();
done();
}) })
done();
}) })
/** /**
* @tc.number SUB_PowerSystem_PowerManager_JSTest_0190 * @tc.number SUB_PowerSystem_PowerManager_JSTest_0080
* @tc.name Is_Runninglock_Type_Supported_Promise_Test2_JSTest0090 * @tc.name Is_Runninglock_Type_Supported_Promise_JSTest0080
* @tc.desc Checks whether the specified RunningLockType is supported. * @tc.desc Checks whether the specified RunningLockType is supported (deprecated since 9)
*/ */
it('Is_Runninglock_Type_Supported_Promise_Test2_JSTest0090', 0, async function (done) { it('Is_Runninglock_Type_Supported_Promise_JSTest0080', 0, async function (done) {
runningLock.isRunningLockTypeSupported(runningLock.RunningLockType.BACKGROUND) await runningLock.isRunningLockTypeSupported(runningLock.RunningLockType.BACKGROUND)
.then(supported => { .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(); expect(supported).assertTrue();
console.info('Is_Runninglock_Type_Supported_Promise_Test2 success'); console.info('Is_Runninglock_Type_Supported_Promise_JSTest0080 success');
done();
}) })
.catch(error => { .catch(error => {
console.log('Is_Runninglock_Type_Supported_Promise_Test2 error: ' + error); console.log('Is_Runninglock_Type_Supported_Promise_JSTest0080 error: ' + error);
expect().assertFail(); expect().assertFail();
done();
}) })
done();
}) })
/** /**
* @tc.number SUB_PowerSystem_PowerManager_JSTest_0200 * @tc.number SUB_PowerSystem_PowerManager_JSTest_0090
* @tc.name Is_Runninglock_Type_Supported_Callback_test3_JSTest0100 * @tc.name Is_Runninglock_Type_Supported_Callback_JSTest0090
* @tc.desc Checks whether the specified RunningLockType is supported. * @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) => { runningLock.isRunningLockTypeSupported(runningLock.RunningLockType.BACKGROUND, (error, supported) => {
if (typeof error === "undefined") { 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(); expect(supported).assertTrue();
console.info('Is_Runninglock_Type_Supported_Callback_test3_JSTest success'); console.info('Is_Runninglock_Type_Supported_Callback_JSTest0090 success');
done();
} else { } else {
console.log('Is_Runninglock_Type_Supported_Callback_test3_JSTest: ' + error); console.log('Is_Runninglock_Type_Supported_Callback_JSTest0090: ' + error);
expect().assertFail(); expect().assertFail();
done();
} }
}) })
done();
}) })
/** /**
* @tc.number SUB_PowerSystem_PowerManager_JSTest_0210 * @tc.number SUB_PowerSystem_PowerManager_JSTest_0100
* @tc.name Create_Running_Lock_Promise_JSTest0210 * @tc.name Is_Supported_JSTest0100
* @tc.desc Create lock, hold lock, unlock * @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 { try {
let isExec = false; let background = runningLock.isSupported(runningLock.RunningLockType.BACKGROUND)
runningLock.create("Create_Running_Lock_Promise_JSTest0210", runningLock.RunningLockType.BACKGROUND) expect(background).assertTrue();
.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();
})
} catch (e) { } catch (e) {
console.info('Create_Running_Lock_Promise_JSTest0210 error:' + e); console.info('Is_Supported_JSTest0100 code:' + e);
expect().assertFail(); expect().assertFail();
} }
done(); done();
}) })
// New interface
/** /**
* @tc.number SUB_PowerSystem_PowerManager_JSTest_0220 * @tc.number SUB_PowerSystem_PowerManager_JSTest_0110
* @tc.name Create_Running_Lock_Promise_Invalid_JSTest0220 * @tc.name Create_Running_Lock_Promise_JSTest0110
* @tc.desc Create lock input invalid value * @tc.desc Create running lock promise (deprecated since 9)
*/ */
it('Create_Running_Lock_Promise_Invalid_JSTest0220', 0, async function (done) { it('Create_Running_Lock_Promise_JSTest0110', 0, async function (done) {
try { await runningLock.createRunningLock("running_lock_test_1", runningLock.RunningLockType.BACKGROUND)
runningLock.create(0, runningLock.RunningLockType.BACKGROUND) .then(runninglock => {
.then((error, 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(); 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();
}
done(); done();
}) })
/** /**
* @tc.number SUB_PowerSystem_PowerManager_JSTest_0230 * @tc.number SUB_PowerSystem_PowerManager_JSTest_0120
* @tc.name Create_Running_Lock_Callback_JSTest0230 * @tc.name Create_Running_Lock_CallBack_JSTest0120
* @tc.desc Create lock, hold lock, unlock * @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) {
try { runningLock.createRunningLock("Create_Running_Lock_CallBack_JSTest0120", runningLock.RunningLockType.BACKGROUND,
runningLock.create("Create_Running_Lock_Callback_JSTest0230", runningLock.RunningLockType.BACKGROUND,
(error, runninglock) => { (error, runninglock) => {
expect(typeof error === "undefined").assertTrue(); if (typeof error === "undefined") {
console.info('Create_Running_Lock_CallBack_JSTest0120: runningLock is ' + runninglock);
expect(runninglock !== null).assertTrue(); expect(runninglock !== null).assertTrue();
runninglock.hold(1000); // hold 1000ms let used = runninglock.isUsed();
let holding = runninglock.isHolding(); console.info('Create_Running_Lock_CallBack_JSTest0120 is used: ' + used);
console.info('Create_Running_Lock_Callback_JSTest0230 holding true:' + holding); expect(used).assertFalse();
expect(holding).assertTrue(); runninglock.lock(500);
runninglock.unhold(); used = runninglock.isUsed();
holding = runninglock.isHolding(); console.info('after lock Create_Running_Lock_CallBack_JSTest0120 is used: ' + used);
expect(holding).assertFalse(); expect(used).assertTrue();
console.info('Create_Running_Lock_Callback_JSTest0230 holding false:' + holding); console.info('Create_Running_Lock_CallBack_JSTest0120 success');
}); } else {
} catch (e) { console.log('Create_Running_Lock_CallBack_JSTest0120: ' + error);
console.info('Create_Running_Lock_Callback_JSTest0230 error:' + e);
expect().assertFail(); expect().assertFail();
} }
})
done(); done();
}) })
/** /**
* @tc.number SUB_PowerSystem_PowerManager_JSTest_0240 * @tc.number SUB_PowerSystem_PowerManager_JSTest_0130
* @tc.name Create_Running_Lock_Callback_Invalid_JSTest0240 * @tc.name Create_Running_Lock_Promise_JSTest0130
* @tc.desc Create lock input invalid value * @tc.desc Create lock promise
*/ */
it('Create_Running_Lock_Callback_Invalid_JSTest0240', 0, async function (done) { it('Create_Running_Lock_Promise_JSTest0130', 0, async function (done) {
try { try {
runningLock.create("Create_Running_Lock_Callback_Invalid_JSTest0240", "invalid", let isExec = false;
(error, runninglock) => { await runningLock.create("Create_Running_Lock_Promise_JSTest0130", runningLock.RunningLockType.BACKGROUND)
expect().assertFail(); .then((runninglock) => {
}); isExec = true;
expect(runninglock !== null).assertTrue();
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) { } catch (e) {
console.info('Create_Running_Lock_Callback_Invalid_JSTest0240 code:' + e.code + "msg:" + e.message); console.info('Create_Running_Lock_Promise_JSTest0130 error:' + e);
// 401: Invalid input parameter expect().assertFail();
expect(e.code === 401).assertTrue();
} }
done(); done();
}) })
/** /**
* @tc.number SUB_PowerSystem_PowerManager_JSTest_0250 * @tc.number SUB_PowerSystem_PowerManager_JSTest_0140
* @tc.name Is_Supported_JSTest0250 * @tc.name Create_Running_Lock_Callback_JSTest0140
* @tc.desc Checks whether the specified RunningLockType is supported. * @tc.desc Create lock callback
*/ */
it('Is_Supported_JSTest0250', 0, async function (done) { it('Create_Running_Lock_Callback_JSTest0140', 0, async function (done) {
try { try {
let background = runningLock.isSupported(runningLock.RunningLockType.BACKGROUND) runningLock.create("Create_Running_Lock_Callback_JSTest0140", runningLock.RunningLockType.BACKGROUND,
expect(background).assertTrue(); (error, runninglock) => {
expect(typeof error === "undefined").assertTrue();
expect(runninglock !== null).assertTrue();
console.info('Create_Running_Lock_Callback_JSTest0140 success');
});
} catch (e) { } catch (e) {
console.info('Is_Supported_JSTest0250 code:' + e); console.info('Create_Running_Lock_Callback_JSTest0230 error:' + e);
expect().assertFail(); expect().assertFail();
} }
done(); done();
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册