提交 df7e79f3 编写于 作者: G greada

power test code optimization

Signed-off-by: Ngreada <kangqiao1@huawei.com>
上级 7b8657cf
...@@ -93,22 +93,19 @@ export default async function SystemDisplayTest() { ...@@ -93,22 +93,19 @@ export default async function SystemDisplayTest() {
brightness.setKeepScreenOn({ brightness.setKeepScreenOn({
keepScreenOn: true, keepScreenOn: true,
success: function () { success: function () {
console.log('handling set keep screen on success0.'); console.log('handling set keep screen on success.');
brightness.setValue({ brightness.setValue({
value: 50, value: 50,
success: function () { success: function () {
console.log('set keep screen on success1.'); console.log('set_value_success_value success.');
setTimeout(() => { expect(true).assertTrue();
console.log('set keep screen on success2.'); done();
brightness.getValue({
success: (data) => {
console.log("set_value_success_value, brightness: " + data.value);
expect(data.value === 50).assertTrue();
done();
}
});
}, 1000);
}, },
fail: function () {
console.log('set_value_success_value fail.');
expect().assertFail();
done();
}
}); });
}, },
fail: function (data, code) { fail: function (data, code) {
...@@ -188,13 +185,12 @@ export default async function SystemDisplayTest() { ...@@ -188,13 +185,12 @@ export default async function SystemDisplayTest() {
mode: 0, mode: 0,
success: () => { success: () => {
console.log("set_mode_success success"); console.log("set_mode_success success");
brightness.getMode({ expect(true).assertTrue();
success: (data) => { },
console.log("set_mode_success, data: " + data.mode); fail: (data, code) => {
expect(data.mode === 0).assertTrue(); console.log("set_mode_success, data: " + data + ", code: " + code);
done(); expect(code == 200).assertTrue();
} done();
});
}, },
complete: () => { complete: () => {
console.log("The device information is obtained successfully. Procedure"); console.log("The device information is obtained successfully. Procedure");
...@@ -273,4 +269,4 @@ export default async function SystemDisplayTest() { ...@@ -273,4 +269,4 @@ export default async function SystemDisplayTest() {
}); });
}); });
}) })
} }
\ No newline at end of file
...@@ -67,8 +67,8 @@ describe('PowerManagerPowerTest', function () { ...@@ -67,8 +67,8 @@ describe('PowerManagerPowerTest', function () {
console.log('Power_Is_Screnn_On_Callback_JSTest0030: ' + error); console.log('Power_Is_Screnn_On_Callback_JSTest0030: ' + error);
expect().assertFail(); expect().assertFail();
} }
}) done();
done(); })
}) })
/** /**
......
...@@ -26,7 +26,7 @@ describe('PowerManagerRunningLockTest', function () { ...@@ -26,7 +26,7 @@ describe('PowerManagerRunningLockTest', function () {
* @tc.name Running_Lock_Lock_JSTest0010 * @tc.name Running_Lock_Lock_JSTest0010
* @tc.desc Prevents the system from hibernating and sets the lock duration (deprecated since 9) * @tc.desc Prevents the system from hibernating and sets the lock duration (deprecated since 9)
*/ */
it('Running_Lock_Lock_JSTest0010', 0, async function (done) { it('Running_Lock_Lock_JSTest0010', 0, async function (done) {
await runningLock.createRunningLock("Running_Lock_Lock_JSTest0010", 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();
......
...@@ -16,59 +16,67 @@ import commonEvent from '@ohos.commonEvent'; ...@@ -16,59 +16,67 @@ import commonEvent from '@ohos.commonEvent';
import thermal from "@ohos.thermal" import thermal from "@ohos.thermal"
export default function ThermalCommonEvent() { export default function ThermalCommonEvent() {
describe('ThermalCommonEvent', function () { describe('ThermalCommonEvent', function () {
console.log("*************Thermal commonEvent Test Begin*************"); console.log("*************Thermal commonEvent Test Begin*************");
/** /**
* @tc.number ThermalCommonEventTest_001 * @tc.number ThermalCommonEventTest_001
* @tc.name subscribe thermal level changed common event * @tc.name subscribe thermal level changed common event
* @tc.desc Thermal acquisition kit * @tc.desc Thermal acquisition kit
*/ */
it('ThermalCommonEventTest_001', 0, function (done) { it('ThermalCommonEventTest_001', 0, function (done) {
createSubscriber(); createSubscriber();
done(); done();
})
console.log("*************Thermal commonEvent Test End*************");
}) })
console.log("*************Thermal commonEvent Test End*************");
})
function createSubscriber() { function createSubscriber() {
let commonEventSubscribeInfo = { let commonEventSubscribeInfo = {
events: [commonEvent.Support.COMMON_EVENT_THERMAL_LEVEL_CHANGED], events: [commonEvent.Support.COMMON_EVENT_THERMAL_LEVEL_CHANGED],
}; };
commonEvent.createSubscriber(commonEventSubscribeInfo) commonEvent.createSubscriber(commonEventSubscribeInfo)
.then(subscriber => { .then(subscriber => {
console.info('createSubscriber success'); console.info('createSubscriber success');
let mySubscriber = subscriber; let mySubscriber = subscriber;
console.log(subscriber); console.log(subscriber);
if (subscriber == "" || subscriber == undefined || subscriber == null) { if (subscriber == "" || subscriber == undefined || subscriber == null) {
console.info("createSubscriber failed"); console.info("createSubscriber failed");
} }
mySubscriber.getCode() mySubscriber.getCode()
.then((data) => { .then((data) => {
console.info('Subscriber getCode success : ' + JSON.stringify(data)); console.info('Subscriber getCode success : ' + JSON.stringify(data));
}).catch((error) => { }).catch((error) => {
console.error('Subscriber getCode error because: ' + JSON.stringify(error)); console.error('Subscriber getCode error because: ' + JSON.stringify(error));
}) })
mySubscriber.getData() mySubscriber.getData()
.then((data) => { .then((data) => {
console.info('Subscriber getData success : ' + JSON.stringify(data)); console.info('Subscriber getData success : ' + JSON.stringify(data));
}).catch((error) => { }).catch((error) => {
console.error('Subscriber getData error because: ' + JSON.stringify(error)); console.error('Subscriber getData error because: ' + JSON.stringify(error));
}) })
console.info('subscribe begin '); console.info('subscribe begin ');
commonEvent.subscribe(mySubscriber, (error, commonEventData) => { commonEvent.subscribe(mySubscriber, (error, commonEventData) => {
console.error('err code: ' + JSON.stringify(error)); console.error('err code: ' + JSON.stringify(error));
console.info('subscribe callback: ' + JSON.stringify(commonEventData)); console.info('subscribe callback: ' + JSON.stringify(commonEventData));
console.info("commonEventData event: " + commonEventData.event); console.info("commonEventData event: " + commonEventData.event);
console.info("commonEventData bundleName: " + commonEventData.bundleName); console.info("commonEventData bundleName: " + commonEventData.bundleName);
console.info("commonEventData data: " + commonEventData.data); console.info("commonEventData data: " + commonEventData.data);
console.info("commonEventData parameter: " + commonEventData.parameters[0]); console.info("commonEventData parameter: " + commonEventData.parameters[0]);
let level = -1; let level = -1;
expect(level >= thermal.ThermalLevel.COOL && warm <= level.ThermalLevel.EMERGENCY).assertTrue(); expect(level >= thermal.ThermalLevel.COOL && warm <= level.ThermalLevel.EMERGENCY).assertTrue();
});
commonEvent.unsubscribe(mySubscriber, (error) => {
if (error.code) {
console.error(`unsubscribe failed, code is ${err.code}`);
} else {
console.info("unsubscribe");
}
})
}).catch((error) => {
console.error('Operation failed. Cause: ' + JSON.stringify(error));
}); });
}).catch((error) => { }
console.error('Operation failed. Cause: ' + JSON.stringify(error)); }
});
}}
// @ts-nocheck
/* /*
* Copyright (C) 2022 Huawei Device Co., Ltd. * Copyright (C) 2022 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册