From bef331e1d3097bb28fda5c52445b16f2bcd2b5a9 Mon Sep 17 00:00:00 2001 From: logic42 Date: Fri, 4 Nov 2022 15:39:49 +0000 Subject: [PATCH] change power testcase Signed-off-by: logic42 --- .../src/main/js/test/system_display.test.js | 579 +++++++++--------- 1 file changed, 276 insertions(+), 303 deletions(-) diff --git a/powermgr/display_manager/src/main/js/test/system_display.test.js b/powermgr/display_manager/src/main/js/test/system_display.test.js index 09f1e49ad..43ff8825f 100644 --- a/powermgr/display_manager/src/main/js/test/system_display.test.js +++ b/powermgr/display_manager/src/main/js/test/system_display.test.js @@ -3,16 +3,15 @@ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * + * + * http://www.apache.org/licenses/LICENSE-2.0 + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. - */ - +*/ import brightness from '@system.brightness'; import { describe, it, expect } from '@ohos/hypium'; @@ -20,327 +19,301 @@ const INPUT_ERROR_CODE_CODE = 202; const SET_VALUE_MSG = "value is not an available number"; const SET_MODE_MSG = "value is not an available number"; -export default function SystemDisplayTest() { -describe('SystemDisplayTest', function () { - console.log("*************System SystemDisplay Unit Test Begin*************"); +export default async function SystemDisplayTest() { + describe('SystemDisplayTest', async function () { + console.log("System SystemDisplay Unit Test Begin"); - /** - * @tc.number system_display_js_0100 - * @tc.name get_value_success - * @tc.desc Get brightness success - */ - it('get_value_success', 0, function () { - let currValue = 100; - let setValue = 120; - brightness.getValue({ - success: (data) => { - currValue = data.value; - let value = (data.value > 0) && (data.value <= 255); - expect(value).assertTrue(); - } - }); - brightness.setValue({ - value: setValue - }); - brightness.getValue({ - success: (data) => { - expect(setValue === data.value).assertTrue(); - }, - fail: (data, code) => { - console.log("get_value_success, data: " + data + ", code: " + code); - expect().assertFail(); - }, - complete: () => { - console.log("The device information is obtained successfully. Procedure"); - } + /** + * @tc.number system_display_js_0100 + * @tc.name get_value_success + * @tc.desc Get brightness success + */ + it('get_value_success', 0, async function (done) { + let currValue = 100; + brightness.getValue({ + success: (data) => { + currValue = data.value; + let value = (data.value > 0) && (data.value <= 255); + expect(value).assertTrue(); + done(); + } + }); }); - brightness.setValue({ - value: currValue - }); - }); + /** + * @tc.number system_display_js_0101 + * @tc.name get_value_success_not_must_test + * @tc.desc Get brightness + */ + it('get_status_test_success_not_must', 0, async function (done) { + brightness.getValue({ + fail: (data, code) => { + console.log("get_status_test_success_not_must, data: " + data + ", code: " + code); + expect().assertFail(); + done(); + }, + complete: () => { + console.log("The device information is obtained successfully. Procedure"); + done(); + } + }); + }) - /** - * @tc.number system_display_js_0101 - * @tc.name get_value_success_not_must_test - * @tc.desc Get brightness - */ - it('get_status_test_success_not_must', 0, function () { - brightness.getValue({ - fail: (data, code) => { - console.log("get_status_test_success_not_must, data: " + data + ", code: " + code); - expect().assertFail(); - }, - complete: () => { - console.log("The device information is obtained successfully. Procedure"); - } + /** + * @tc.number system_display_js_0102 + * @tc.name get_value_fail_not_must_test + * @tc.desc Get brightness + */ + it('get_value_fail_not_must_test', 0, async function (done) { + brightness.getValue({ + complete: () => { + console.log("The device information is obtained successfully. Procedure"); + done(); + } + }); }); - }) - /** - * @tc.number system_display_js_0102 - * @tc.name get_value_fail_not_must_test - * @tc.desc Get brightness - */ - it('get_value_fail_not_must_test', 0, function () { - brightness.getValue({ - complete: () => { - console.log("The device information is obtained successfully. Procedure"); - } - }); - }); + /** + * @tc.number system_display_js_0103 + * @tc.name get_value_null_test + * @tc.desc Get brightness + */ + it('get_status_test_fail_not_must', 0, async function (done) { + brightness.getValue(); + expect(true).assertTrue(); + done(); + }) - /** - * @tc.number system_display_js_0103 - * @tc.name get_value_null_test - * @tc.desc Get brightness - */ - it('get_status_test_fail_not_must', 0, function () { - brightness.getValue(); - expect(true).assertTrue(); - }) + /** + * @tc.number system_display_js_0200 + * @tc.name set_value_success_all + * @tc.desc Set brightness success + */ + it('set_value_success_all', 0, async function (done) { + let setValue = 200; + let currValue = 100; + brightness.getValue({ + success: (data) => { + currValue = data.value; + } + }); - /** - * @tc.number system_display_js_0200 - * @tc.name set_value_success_all - * @tc.desc Set brightness success - */ - it('set_value_success_all', 0, function () { - let setValue = 200; - let currValue = 100; - brightness.getValue({ - success: (data) => { - currValue = data.value; - } + brightness.setValue({ + value: setValue, + success: () => { + brightness.getValue({ + success: (data) => { + expect(data.value === setValue).assertTrue(); + brightness.setValue({ + value: currValue, + success: function () { + done(); + }, + }); + } + }); + }, + fail: (data, code) => { + console.log("set_value_success_all, data: " + data + ", code: " + code); + expect().assertFail(); + done(); + }, + complete: () => { + console.log("The device information is obtained successfully. Procedure"); + done(); + } + }); }); - brightness.setValue({ - value: setValue, - success: () => { - brightness.getValue({ - success: (data) => { - expect(data.value === setValue).assertTrue(); - } - }); - }, - fail: (data, code) => { - console.log("set_value_success_all, data: " + data + ", code: " + code); - expect().assertFail(); - }, - complete: () => { - console.log("The device information is obtained successfully. Procedure"); - } + /** + * @tc.number system_display_js_0201 + * @tc.name set_value_success_value + * @tc.desc Set brightness success + */ + it('set_value_success_value', 0, async function (done) { + brightness.setKeepScreenOn({ + keepScreenOn: true, + success: function () { + console.log('handling set keep screen on success.'); + brightness.setValue({ + value: 50, + success: function () { + setTimeout(() => { + brightness.getValue({ + success: (data) => { + console.log("set_value_success_value, brightness: " + data.value); + expect(data.value === 50).assertTrue(); + done(); + } + }); + }, 1000); + }, + }); + }, + fail: function (data, code) { + console.error('handling set keep screen on fail, code:' + code + ', data: ' + data); + done(); + }, + complete: function () { + console.error('handling set keep screen on complete.'); + done(); + }, + }); }); - brightness.setValue({ - value: currValue + /** + * @tc.number system_display_js_0202 + * @tc.name set_value_fail + * @tc.desc Set brightness fail + */ + it('set_value_fail', 0, async function (done) { + let setValue = "50"; + brightness.setValue({ + value: setValue, + success: () => { + console.log("set_value_fail success"); + expect().assertFail(); + done(); + }, + fail: (data, code) => { + console.log("set_value_fail, data: " + data + ", code: " + code); + expect(code === INPUT_ERROR_CODE_CODE).assertTrue(); + expect(data === SET_VALUE_MSG).assertTrue(); + done(); + } + }); }); - }); - /** - * @tc.number system_display_js_0201 - * @tc.name set_value_success_value - * @tc.desc Set brightness success - */ - it('set_value_success_value', 0, function () { - let setValue = 50; - let currValue = 100; - brightness.getValue({ - success: (data) => { - currValue = data.value; - } - }); - brightness.setKeepScreenOn({ - keepScreenOn: true, - success: function () { - console.log('handling set keep screen on success.'); - brightness.setValue({ value: setValue }); - }, - fail: function (data, code) { - console.error('handling set keep screen on fail, code:' + code + ', data: ' + data); - } - }); - brightness.getValue({ - success: (data) => { - console.log("set_value_success_value, brightness: " + data.value); - expect(data.value === setValue).assertTrue(); - } - }); - brightness.setValue({ value: currValue }); - }); - - /** - * @tc.number system_display_js_0202 - * @tc.name set_value_fail - * @tc.desc Set brightness fail - */ - it('set_value_fail', 0, function () { - let setValue = "50"; - brightness.setValue({ - value: setValue, - success: () => { - console.log("set_value_fail success"); - expect().assertFail(); - }, - fail: (data, code) => { - console.log("set_value_fail, data: " + data + ", code: " + code); - expect(code === NPUT_ERROR_CODE).assertTrue(); - expect(data === SET_VALUE_MSG).assertTrue(); - } - }); - }); - - /** - * @tc.number system_display_js_0300 - * @tc.name get_mode_success - * @tc.desc Get mode success - */ - it('get_mode_success', 0, function () { - let modeVal = 0; - let exec = true; - brightness.getMode({ - success: (data) => { - console.log("get_mode_success: get mode: " + data.mode); - modeVal = data.mode; - } - }); - brightness.setMode({ - mode: modeVal ? 0 : 1, - fail: (data, code) => { - console.log("get_mode_success, data: " + data + ", code: " + code); - exec = false; - } + /** + * @tc.number system_display_js_0300 + * @tc.name get_mode_success + * @tc.desc Get mode success + */ + it('get_mode_success', 0, async function (done) { + brightness.getMode({ + success: (data) => { + console.log("get_mode_success: get mode: " + data.mode); + expect(data.mode === 0 || data.mode === 1).assertTrue(); + done(); + } + }); }) - if (!exec) { - return; - } - brightness.getMode({ - success: (data) => { - expect(data.mode === (modeVal ? 0 : 1)).assertTrue(); - }, - fail: (data, code) => { - console.log("get_mode_success, data: " + data + ", code: " + code); - expect().assertFail(); - }, - complete: () => { - console.log("The device information is obtained successfully. Procedure"); - } - }); - brightness.setMode({ mode: modeVal }); - }) - - /** - * @tc.number system_display_js_0301 - * @tc.name get_mode_success_null - * @tc.desc Get mode success is null - */ - it('get_mode_success_null', 0, function () { - brightness.getMode({ - fail: (data, code) => { - console.log("get_mode_success_null, data: " + data + ", code: " + code); - expect().assertFail(); - }, - complete: () => { - console.log("The device information is obtained successfully. Procedure"); - } + /** + * @tc.number system_display_js_0301 + * @tc.name get_mode_success_null + * @tc.desc Get mode success is null + */ + it('get_mode_success_null', 0, async function (done) { + brightness.getMode({ + fail: (data, code) => { + console.log("get_mode_success_null, data: " + data + ", code: " + code); + expect().assertFail(); + done(); + }, + complete: () => { + console.log("The device information is obtained successfully. Procedure"); + done(); + } + }); }); - }); - /** - * @tc.number system_display_js_0400 - * @tc.name set_mode_success - * @tc.desc set mode success - */ - it('set_mode_success', 0, function () { - let modeVal = 0; - brightness.getMode({ - success: (data) => { - modeVal = data.mode; - } + /** + * @tc.number system_display_js_0400 + * @tc.name set_mode_success + * @tc.desc set mode success + */ + it('set_mode_success', 0, async function (done) { + brightness.setMode({ + mode: 0, + success: () => { + console.log("set_mode_success success"); + brightness.getMode({ + success: (data) => { + console.log("set_mode_success, data: " + data.mode); + expect(data.mode === 0).assertTrue(); + done(); + } + }); + }, + complete: () => { + console.log("The device information is obtained successfully. Procedure"); + done(); + } + }); }); - brightness.setMode({ - mode: modeVal ? 0 : 1, - success: () => { - console.log("set_mode_success success"); - brightness.getMode({ - success: (data) => { - console.log("set_mode_success, data: " + data.mode); - expect(data.mode === (modeVal ? 0 : 1)).assertTrue(); - } - }); - }, - complete: () => { - console.log("The device information is obtained successfully. Procedure"); - } + /** + * @tc.number system_display_js_0401 + * @tc.name set_mode_fail + * @tc.desc set mode fail + */ + it('set_mode_fail', 0, async function (done) { + brightness.setMode({ + mode: "0", + success: () => { + expect().assertFail(); + done(); + }, + fail: (data, code) => { + console.log("set_mode_fail, data: " + data + ", code: " + code); + expect(code === INPUT_ERROR_CODE_CODE).assertTrue(); + expect(data === SET_MODE_MSG).assertTrue(); + done(); + }, + complete: () => { + console.log("The device information is obtained successfully. Procedure"); + done(); + } + }); }); - brightness.setMode({ mode: modeVal }); - }); - - /** - * @tc.number system_display_js_0401 - * @tc.name set_mode_fail - * @tc.desc set mode fail - */ - it('set_mode_fail', 0, function () { - brightness.setMode({ - mode: "0", - success: () => { - expect().assertFail(); - }, - fail: (data, code) => { - console.log("set_mode_fail, data: " + data + ", code: " + code); - expect(code === INPUT_ERROR_CODE_CODE).assertTrue(); - expect(data === SET_MODE_MSG).assertTrue(); - }, - complete: () => { - console.log("The device information is obtained successfully. Procedure"); - } + /** + * @tc.number system_display_js_0500 + * @tc.name set_keep_screen_on_true + * @tc.desc set keep screen on true + */ + it('set_keep_screen_on_true', 0, async function (done) { + brightness.setKeepScreenOn({ + keepScreenOn: true, + success: () => { + expect(true).assertTrue(); + done(); + }, + fail: (data, code) => { + console.log("set_keep_screen_on, data: " + data + ", code: " + code); + expect().assertFail(); + done(); + }, + complete: () => { + console.log("The device information is obtained successfully. Procedure"); + done(); + } + }); }); - }); - /** - * @tc.number system_display_js_0500 - * @tc.name set_keep_screen_on_true - * @tc.desc set keep screen on true - */ - it('set_keep_screen_on_true', 0, async function () { - brightness.setKeepScreenOn({ - keepScreenOn: true, - success: () => { - expect().assertTrue(); - }, - fail: (data, code) => { - console.log("set_keep_screen_on, data: " + data + ", code: " + code); - expect().assertFail(); - }, - complete: () => { - console.log("The device information is obtained successfully. Procedure"); - } + /** + * @tc.number system_display_js_0501 + * @tc.name set_keep_screen_on_false + * @tc.desc set keep screen on false + */ + it('set_keep_screen_on_false', 0, async function (done) { + brightness.setKeepScreenOn({ + keepScreenOn: false, + success: () => { + expect(true).assertTrue(); + done(); + }, + fail: (data, code) => { + console.log("set_keep_screen_on_false, data: " + data + ", code: " + code); + expect().assertFail(); + done(); + }, + complete: () => { + console.log("The device information is obtained successfully. Procedure"); + done(); + } + }); }); - }); - - /** - * @tc.number system_display_js_0501 - * @tc.name set_keep_screen_on_false - * @tc.desc set keep screen on false - */ - it('set_keep_screen_on_false', 0, async function () { - brightness.setKeepScreenOn({ - keepScreenOn: false, - success: () => { - expect().assertTrue(); - }, - fail: (data, code) => { - console.log("set_keep_screen_on_false, data: " + data + ", code: " + code); - expect().assertFail(); - }, - complete: () => { - console.log("The device information is obtained successfully. Procedure"); - } - }); - }); -}) + }) } \ No newline at end of file -- GitLab