1/* 2 * Copyright (c) 2022 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16import runningLock from '@ohos.runningLock'; 17import power from '@ohos.power'; 18 19import {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from 'deccjsunit/index' 20 21describe('appInfoTest', function () { 22 console.log("*************Power Unit Test Begin*************"); 23 it('create_running_lock_promise_test', 0, async function (done) { 24 runningLock.createRunningLock("running_lock_test_1", runningLock.RunningLockType.BACKGROUND) 25 .then(runninglock => { 26 expect(runninglock !== null).assertTrue(); 27 console.info('create_running_lock_promise_test success'); 28 done(); 29 }) 30 .catch(error => { 31 console.log('create_running_lock_promise_test error: ' + error); 32 expect().assertFail(); 33 done(); 34 }) 35 }) 36 it('create_running_lock_callback_test', 0, async function (done) { 37 runningLock.createRunningLock("running_lock_test_2", runningLock.RunningLockType.BACKGROUND, (error, runninglock) => { 38 if (typeof error === "undefined") { 39 console.info('create_running_lock_callback_test: runningLock is ' + runninglock); 40 expect(runninglock !== null).assertTrue(); 41 var used = runninglock.isUsed(); 42 console.info('create_running_lock_callback_test is used: ' + used); 43 expect(used).assertFalse(); 44 runninglock.lock(500); 45 used = runninglock.isUsed(); 46 console.info('after lock create_running_lock_callback_test is used: ' + used); 47 expect(used).assertTrue(); 48 console.info('create_running_lock_callback_test success'); 49 done(); 50 } else { 51 console.log('create_running_lock_callback_test: ' + error); 52 expect().assertFail(); 53 done(); 54 } 55 }) 56 }) 57 it('running_lock_lock_test', 0, async function (done) { 58 runningLock.createRunningLock("running_lock_test_3", runningLock.RunningLockType.BACKGROUND) 59 .then(runninglock => { 60 expect(runninglock !== null).assertTrue(); 61 var used = runninglock.isUsed(); 62 console.info('running_lock_lock_test is used: ' + used); 63 expect(used).assertFalse(); 64 runninglock.lock(500); 65 used = runninglock.isUsed(); 66 console.info('after lock running_lock_lock_test is used: ' + used); 67 expect(used).assertTrue(); 68 console.info('running_lock_lock_test success'); 69 done(); 70 }) 71 .catch(error => { 72 console.log('running_lock_lock_test error: ' + error); 73 expect().assertFail(); 74 done(); 75 }) 76 }) 77 it('running_lock_isused_test', 0, async function (done) { 78 runningLock.createRunningLock("running_lock_test_4", runningLock.RunningLockType.BACKGROUND) 79 .then(runninglock => { 80 expect(runninglock !== null).assertTrue(); 81 var used = runninglock.isUsed(); 82 console.info('running_lock_isused_test used: ' + used); 83 expect(used).assertFalse(); 84 console.info('running_lock_isused_test success'); 85 done(); 86 }) 87 .catch(error => { 88 console.log('running_lock_isused_test error: ' + error); 89 expect().assertFail(); 90 done(); 91 }) 92 }) 93 it('running_lock_unlock_test', 0, async function (done) { 94 runningLock.createRunningLock("running_lock_test_5", runningLock.RunningLockType.BACKGROUND) 95 .then(runninglock => { 96 expect(runninglock !== null).assertTrue(); 97 var used = runninglock.isUsed(); 98 console.info('running_lock_unlock_test is used: ' + used); 99 expect(used).assertFalse(); 100 runninglock.lock(500); 101 used = runninglock.isUsed(); 102 console.info('after lock running_lock_unlock_test is used: ' + used); 103 expect(used).assertTrue(); 104 runninglock.unlock(); 105 used = runninglock.isUsed(); 106 console.info('after unlock running_lock_unlock_test is used: ' + used); 107 expect(used).assertFalse(); 108 console.info('running_lock_unlock_test success'); 109 done(); 110 }) 111 .catch(error => { 112 console.log('running_lock_unlock_test error: ' + error); 113 expect().assertFail(); 114 done(); 115 }) 116 }) 117 it('enum_runningLock_type_background_test', 0, function () { 118 var runningLockType = runningLock.RunningLockType.BACKGROUND; 119 console.info('runningLockType = ' + runningLockType); 120 expect(runningLockType == 1).assertTrue(); 121 console.info('enum_runningLock_type_background_test success'); 122 }) 123 it('enum_runningLock_type_proximityscreencontrol_test', 0, function () { 124 var runningLockType = runningLock.RunningLockType.PROXIMITY_SCREEN_CONTROL; 125 console.info('runningLockType = ' + runningLockType); 126 expect(runningLockType == 2).assertTrue(); 127 console.info('enum_runningLock_type_proximityscreencontrol_test success'); 128 }) 129 it('is_runninglock_type_supported_test_1', 0, async function (done) { 130 runningLock.isRunningLockTypeSupported(runningLock.RunningLockType.PROXIMITY_SCREEN_CONTROL) 131 .then(supported => { 132 console.info('is_runninglock_type_supported_test_1 PROXIMITY_SCREEN_CONTROL supported is ' + supported); 133 expect(supported).assertTrue(); 134 console.info('is_runninglock_type_supported_test_1 success'); 135 done(); 136 }) 137 .catch(error => { 138 console.log('is_runninglock_type_supported_test_1 error: ' + error); 139 expect().assertFail(); 140 done(); 141 }) 142 }) 143 it('is_runninglock_type_supported_promise_test_2', 0, async function (done) { 144 runningLock.isRunningLockTypeSupported(runningLock.RunningLockType.BACKGROUND) 145 .then(supported => { 146 console.info('is_runninglock_type_supported_promise_test_2 BACKGROUND supported is ' + supported); 147 expect(supported).assertTrue(); 148 console.info('is_runninglock_type_supported_promise_test_2 success'); 149 done(); 150 }) 151 .catch(error => { 152 console.log('is_runninglock_type_supported_promise_test_2 error: ' + error); 153 expect().assertFail(); 154 done(); 155 }) 156 }) 157 it('is_runninglock_type_supported_callback_test_3', 0, async function (done) { 158 runningLock.isRunningLockTypeSupported(runningLock.RunningLockType.BACKGROUND, (error, supported) => { 159 if (typeof error === "undefined") { 160 console.info('is_runninglock_type_supported_callback_test_3 BACKGROUND supported is ' + supported); 161 expect(supported).assertTrue(); 162 console.info('is_runninglock_type_supported_callback_test_3 success'); 163 done(); 164 } else { 165 console.log('is_runninglock_type_supported_callback_test_3: ' + error); 166 expect().assertFail(); 167 done(); 168 } 169 }) 170 }) 171 it('power_is_screen_on_promise_test', 0, async function (done) { 172 power.isScreenOn() 173 .then(screenOn => { 174 console.info('power_is_screen_on_promise_test screenOn is ' + screenOn); 175 expect(screenOn).assertTrue(); 176 console.info('power_is_screen_on_promise_test success'); 177 done(); 178 }) 179 .catch(error => { 180 console.log('power_is_screen_on_promise_test error: ' + error); 181 expect().assertFail(); 182 done(); 183 }) 184 }) 185 it('power_is_screen_on_callback_test', 0, async function (done) { 186 power.isScreenOn((error, screenOn) => { 187 if (typeof error === "undefined") { 188 console.info('power_is_screen_on_callback_test screenOn is ' + screenOn); 189 expect(screenOn).assertTrue(); 190 console.info('power_is_screen_on_callback_test success'); 191 done(); 192 } else { 193 console.log('power_is_screen_on_callback_test: ' + error); 194 expect().assertFail(); 195 done(); 196 } 197 }) 198 }) 199 it('power_reboot_device_test', 0, function () { 200 if (false) { 201 power.rebootDevice("power_js_test_reboot"); 202 } 203 console.info('power_reboot_device_test success'); 204 }) 205 it('power_shutdown_device_test', 0, function () { 206 if (false) { 207 power.shutdownDevice("power_js_test_shutdown"); 208 } 209 console.info('power_shutdown_device_test success'); 210 }) 211})