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

!7681 【代码上库】【xts_acts】【powermgr】【master】 power test code optimization

Merge pull request !7681 from kangqiao/master
...@@ -18,203 +18,203 @@ import { describe, it, expect } from '@ohos/hypium' ...@@ -18,203 +18,203 @@ import { describe, it, expect } from '@ohos/hypium'
const MSEC_1000 = 1000; const MSEC_1000 = 1000;
export default function ThermalUnitTest() { export default function ThermalUnitTest() {
describe('ThermalUnitTest', function () { describe('ThermalUnitTest', function () {
console.log("*************Thermal API Test Begin*************"); console.log("*************Thermal API Test Begin*************");
/* @tc.number SUB_PowerSystem_ThermalManager_JSTest_0010 /* @tc.number SUB_PowerSystem_ThermalManager_JSTest_0010
* @tc.name Get_Thermal_Level_JSTest0010 * @tc.name Get_Thermal_Level_JSTest0010
* @tc.desc Thermal acquisition kit * @tc.desc Thermal acquisition kit
*/ */
it('Get_Thermal_Level_JSTest0010', 0, async function (done) { it('Get_Thermal_Level_JSTest0010', 0, async function (done) {
console.info("enter"); console.info("enter");
await new Promise((resolve, reject) => { await new Promise((resolve, reject) => {
setTimeout(() => { setTimeout(() => {
let level = thermal.getThermalLevel(); let level = thermal.getThermalLevel();
console.info("level is: " + level);
expect(level >= 0 && level <= 6).assertTrue();
resolve();
done();
}, MSEC_1000 * 4);
})
})
/* @tc.number SUB_PowerSystem_ThermalManager_JSTest_0020
* @tc.name SubscribeAndUnsubscribe_Thermal_Level_JSTest0020
* @tc.desc Thermal acquisition kit
*/
it('SubscribeAndUnsubscribe_Thermal_Level_JSTest0020', 0, async function (done) {
thermal.subscribeThermalLevel((level) => {
console.info("level is: " + level); console.info("level is: " + level);
expect(level >= 0 && level <= 6).assertTrue(); expect(level >= 0 && level <= 6).assertTrue();
resolve();
done(); done();
}, MSEC_1000 * 4); })
await new Promise((resolve, reject) => {
setTimeout(() => {
thermal.unsubscribeThermalLevel(() => {
console.info("unsubscribe successfully!");
});
resolve();
}, MSEC_1000 * 4);
})
}) })
})
/* @tc.number SUB_PowerSystem_ThermalManager_JSTest_0020 /**
* @tc.name SubscribeAndUnsubscribe_Thermal_Level_JSTest0020 * @tc.number SUB_PowerSystem_ThermalManager_JSTest_0030
* @tc.desc Thermal acquisition kit * @tc.name Get_Thermal_Level_Cool_JSTest0030
*/ * @tc.desc Get device thermalLevel COOL
it('SubscribeAndUnsubscribe_Thermal_Level_JSTest0020', 0, async function (done) { */
thermal.subscribeThermalLevel((level) => { it('Get_Thermal_Level_Cool_JSTest0030', 0, function () {
console.info("level is: " + level); let thermalLevel = thermal.ThermalLevel.COOL;
expect(level >= 0 && level <= 6).assertTrue(); console.info('ThermalLevel.COOL = ' + thermalLevel);
done(); expect(thermalLevel === 0).assertTrue();
})
await new Promise((resolve, reject) => {
setTimeout(() => {
thermal.unsubscribeThermalLevel(() => {
console.info("unsubscribe successfully!");
});
resolve();
}, MSEC_1000 * 4);
}) })
})
/**
* @tc.number SUB_PowerSystem_ThermalManager_JSTest_0030
* @tc.name Get_Thermal_Level_Cool_JSTest0030
* @tc.desc Get device thermalLevel COOL
*/
it('Get_Thermal_Level_Cool_JSTest0030', 0, function () {
let thermalLevel = thermal.ThermalLevel.COOL;
console.info('ThermalLevel.COOL = ' + thermalLevel);
expect(thermalLevel === 0).assertTrue();
})
/** /**
* @tc.number SUB_PowerSystem_ThermalManager_JSTest_0040 * @tc.number SUB_PowerSystem_ThermalManager_JSTest_0040
* @tc.name Get_Thermal_Level_Normal_JSTest0040 * @tc.name Get_Thermal_Level_Normal_JSTest0040
* @tc.desc Get device thermalLevel NORMAL * @tc.desc Get device thermalLevel NORMAL
*/ */
it('Get_Thermal_Level_Normal_JSTest0040', 0, function () { it('Get_Thermal_Level_Normal_JSTest0040', 0, function () {
let thermalLevel = thermal.ThermalLevel.NORMAL; let thermalLevel = thermal.ThermalLevel.NORMAL;
console.info('ThermalLevel.NORMAL = ' + thermalLevel); console.info('ThermalLevel.NORMAL = ' + thermalLevel);
expect(thermalLevel === 1).assertTrue(); expect(thermalLevel === 1).assertTrue();
}) })
/** /**
* @tc.number SUB_PowerSystem_ThermalManager_JSTest_0050 * @tc.number SUB_PowerSystem_ThermalManager_JSTest_0050
* @tc.name Get_Thermal_Level_Warm_JSTest0050 * @tc.name Get_Thermal_Level_Warm_JSTest0050
* @tc.desc Get device thermalLevel WARM * @tc.desc Get device thermalLevel WARM
*/ */
it('Get_Thermal_Level_Warm_JSTest0050', 0, function () { it('Get_Thermal_Level_Warm_JSTest0050', 0, function () {
let thermalLevel = thermal.ThermalLevel.WARM; let thermalLevel = thermal.ThermalLevel.WARM;
console.info('ThermalLevel.WARM = ' + thermalLevel); console.info('ThermalLevel.WARM = ' + thermalLevel);
expect(thermalLevel === 2).assertTrue(); expect(thermalLevel === 2).assertTrue();
}) })
/** /**
* @tc.number SUB_PowerSystem_ThermalManager_JSTest_0060 * @tc.number SUB_PowerSystem_ThermalManager_JSTest_0060
* @tc.name Get_Thermal_Level_Hot_JSTest0060 * @tc.name Get_Thermal_Level_Hot_JSTest0060
* @tc.desc Get device thermalLevel HOT * @tc.desc Get device thermalLevel HOT
*/ */
it('Get_Thermal_Level_Hot_JSTest0060', 0, function () { it('Get_Thermal_Level_Hot_JSTest0060', 0, function () {
let thermalLevel = thermal.ThermalLevel.HOT; let thermalLevel = thermal.ThermalLevel.HOT;
console.info('ThermalLevel.HOT = ' + thermalLevel); console.info('ThermalLevel.HOT = ' + thermalLevel);
expect(thermalLevel === 3).assertTrue(); expect(thermalLevel === 3).assertTrue();
}) })
/** /**
* @tc.number SUB_PowerSystem_ThermalManager_JSTest_0070 * @tc.number SUB_PowerSystem_ThermalManager_JSTest_0070
* @tc.name Get_Thermal_Level_OverHeated_JSTest0070 * @tc.name Get_Thermal_Level_OverHeated_JSTest0070
* @tc.desc Get device thermalLevel OVERHEATED * @tc.desc Get device thermalLevel OVERHEATED
*/ */
it('Get_Thermal_Level_OverHeated_JSTest0070', 0, function () { it('Get_Thermal_Level_OverHeated_JSTest0070', 0, function () {
let thermalLevel = thermal.ThermalLevel.OVERHEATED; let thermalLevel = thermal.ThermalLevel.OVERHEATED;
console.info('ThermalLevel.OVERHEATED = ' + thermalLevel); console.info('ThermalLevel.OVERHEATED = ' + thermalLevel);
expect(thermalLevel === 4).assertTrue(); expect(thermalLevel === 4).assertTrue();
}) })
/** /**
* @tc.number SUB_PowerSystem_ThermalManager_JSTest_0080 * @tc.number SUB_PowerSystem_ThermalManager_JSTest_0080
* @tc.name Get_Thermal_Level_Warning_JSTest0080 * @tc.name Get_Thermal_Level_Warning_JSTest0080
* @tc.desc Get device thermalLevel WARNING * @tc.desc Get device thermalLevel WARNING
*/ */
it('Get_Thermal_Level_Warning_JSTest0080', 0, function () { it('Get_Thermal_Level_Warning_JSTest0080', 0, function () {
let thermalLevel = thermal.ThermalLevel.WARNING; let thermalLevel = thermal.ThermalLevel.WARNING;
console.info('ThermalLevel.WARNING = ' + thermalLevel); console.info('ThermalLevel.WARNING = ' + thermalLevel);
expect(thermalLevel === 5).assertTrue(); expect(thermalLevel === 5).assertTrue();
}) })
/** /**
* @tc.number SUB_PowerSystem_ThermalManager_JSTest_0090 * @tc.number SUB_PowerSystem_ThermalManager_JSTest_0090
* @tc.name Get_Thermal_Level_Emergency_JSTest0090 * @tc.name Get_Thermal_Level_Emergency_JSTest0090
* @tc.desc Get device thermalLevel EMERGENCY * @tc.desc Get device thermalLevel EMERGENCY
*/ */
it('Get_Thermal_Level_Emergency_JSTest0090', 0, function () { it('Get_Thermal_Level_Emergency_JSTest0090', 0, function () {
let thermalLevel = thermal.ThermalLevel.EMERGENCY; let thermalLevel = thermal.ThermalLevel.EMERGENCY;
console.info('ThermalLevel.EMERGENCY = ' + thermalLevel); console.info('ThermalLevel.EMERGENCY = ' + thermalLevel);
expect(thermalLevel === 6).assertTrue(); expect(thermalLevel === 6).assertTrue();
}) })
/* @tc.number SUB_PowerSystem_ThermalManager_JSTest_0100 /* @tc.number SUB_PowerSystem_ThermalManager_JSTest_0100
* @tc.name Get_Level_JSTest0100 * @tc.name Get_Level_JSTest0100
* @tc.desc Thermal acquisition kit * @tc.desc Thermal acquisition kit
*/ */
it('Get_Level_JSTest0100', 0, async function (done) { it('Get_Level_JSTest0100', 0, async function (done) {
let level = thermal.getLevel(); let level = thermal.getLevel();
console.info("Get_Level_JSTest0100 level is: " + level); console.info("Get_Level_JSTest0100 level is: " + level);
expect(level >= thermal.ThermalLevel.COOL && level <= thermal.ThermalLevel.EMERGENCY).assertTrue(); expect(level >= thermal.ThermalLevel.COOL && level <= thermal.ThermalLevel.EMERGENCY).assertTrue();
done(); done();
}) })
/* @tc.number SUB_PowerSystem_ThermalManager_JSTest_0110 /* @tc.number SUB_PowerSystem_ThermalManager_JSTest_0110
* @tc.name Register_Thermal_Level_Callback_JSTest0110 * @tc.name Register_Thermal_Level_Callback_JSTest0110
* @tc.desc Thermal acquisition kit * @tc.desc Thermal acquisition kit
*/ */
it('Register_Thermal_Level_Callback_JSTest0110', 0, async function (done) { it('Register_Thermal_Level_Callback_JSTest0110', 0, async function (done) {
try { try {
thermal.registerThermalLevelCallback((value) => { thermal.registerThermalLevelCallback((value) => {
console.info("Register_Thermal_Level_Callback_JSTest0110 level is: " + value); console.info("Register_Thermal_Level_Callback_JSTest0110 level is: " + value);
let level = thermal.getLevel(); let level = thermal.getLevel();
expect(level === value).assertTrue(); expect(level === value).assertTrue();
}) })
} catch (error) { } catch (error) {
console.info('Register_Thermal_Level_Callback_JSTest0110:' + error); console.info('Register_Thermal_Level_Callback_JSTest0110:' + error);
expect().assertFail(); expect().assertFail();
} }
done(); done();
}) })
/* @tc.number SUB_PowerSystem_ThermalManager_JSTest_0120 /* @tc.number SUB_PowerSystem_ThermalManager_JSTest_0120
* @tc.name Register_Thermal_Level_Callback_JSTest0120 * @tc.name Register_Thermal_Level_Callback_JSTest0120
* @tc.desc Thermal acquisition kit * @tc.desc Thermal acquisition kit
*/ */
it('Register_Thermal_Level_Callback_JSTest0120', 0, async function (done) { it('Register_Thermal_Level_Callback_JSTest0120', 0, async function (done) {
try { try {
thermal.registerThermalLevelCallback('') thermal.registerThermalLevelCallback('')
} catch (error) { } catch (error) {
console.info('Register_Thermal_Level_Callback_JSTest0120 error:' + error); console.info('Register_Thermal_Level_Callback_JSTest0120 error:' + error);
// 401: Invalid input parameter // 401: Invalid input parameter
expect(error.code === 401).assertTrue(); expect(error.code === 401).assertTrue();
} }
done(); done();
}) })
/* @tc.number SUB_PowerSystem_ThermalManager_JSTest_0130 /* @tc.number SUB_PowerSystem_ThermalManager_JSTest_0130
* @tc.name UnRegister_Thermal_Level_Callback_JSTest0130 * @tc.name UnRegister_Thermal_Level_Callback_JSTest0130
* @tc.desc Thermal acquisition kit * @tc.desc Thermal acquisition kit
*/ */
it('UnRegister_Thermal_Level_Callback_JSTest0130', 0, async function (done) { it('UnRegister_Thermal_Level_Callback_JSTest0130', 0, async function (done) {
try { try {
thermal.unregisterThermalLevelCallback('') thermal.unregisterThermalLevelCallback('')
} catch (error) { } catch (error) {
console.info('UnRegister_Thermal_Level_Callback_JSTest0130 error:' + error); console.info('UnRegister_Thermal_Level_Callback_JSTest0130 error:' + error);
// 401: Invalid input parameter // 401: Invalid input parameter
expect(error.code === 401).assertTrue(); expect(error.code === 401).assertTrue();
} }
done(); done();
}) })
/* @tc.number SUB_PowerSystem_ThermalManager_JSTest_0140 /* @tc.number SUB_PowerSystem_ThermalManager_JSTest_0140
* @tc.name UnRegister_Thermal_Level_Callback_JSTest0140 * @tc.name UnRegister_Thermal_Level_Callback_JSTest0140
* @tc.desc Thermal acquisition kit * @tc.desc Thermal acquisition kit
*/ */
it('UnRegister_Thermal_Level_Callback_JSTest0140', 0, async function (done) { it('UnRegister_Thermal_Level_Callback_JSTest0140', 0, async function (done) {
try { try {
thermal.unregisterThermalLevelCallback() thermal.unregisterThermalLevelCallback()
} catch (error) { } catch (error) {
console.info('Thermal_020:' + error); console.info('UnRegister_Thermal_Level_Callback_JSTest0140:' + error);
expect().assertFail(); expect().assertFail();
} }
try { try {
thermal.unregisterThermalLevelCallback(() => { thermal.unregisterThermalLevelCallback(() => {
expect(ture).assertTrue(); expect(true).assertTrue();
}) })
} catch (error) { } catch (error) {
console.info('Thermal_020:' + error); console.info('UnRegister_Thermal_Level_Callback_JSTest0140:' + error);
expect().assertFail(); expect().assertFail();
} }
done(); done();
})
}) })
})
} }
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册