1/* 2 * Copyright (C) 2021 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 app from '@system.app' 17import Context from '@ohos.napi_context' 18import thermal from "@ohos.thermal" 19import ThermalLevel from "@ohos.thermal" 20import {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from 'deccjsunit/index' 21 22describe('appInfoTest', function () { 23 console.log("*************Thermal API Test Begin*************"); 24 const MSEC_1000 = 1000; 25 const MSEC_10000 = 10000; 26 /** 27 * @tc.number thermal_manager_js_000 28 * @tc.name Thermal_000 29 * @tc.desc Thermal acquisition kit 30 */ 31 it('Thermal_000', 0, async function (done) { 32 console.info("enter"); 33 await new Promise((resolve, reject) => { 34 setTimeout(() => { 35 var cold = thermal.getThermalLevel(); 36 console.info("cold level is: " + cold); 37 expect(cold >= 0 && cold <= 5).assertEqual('1'); 38 resolve(); 39 }, MSEC_10000); 40 }) 41 done(); 42 }) 43 44 /** 45 * @tc.number thermal_manager_js_001 46 * @tc.name Thermal_001 47 * @tc.desc Thermal acquisition kit 48 */ 49 it('Thermal_001', 0, async function (done) { 50 console.info("enter"); 51 await new Promise((resolve, reject) => { 52 setTimeout(() => { 53 var normal = thermal.getThermalLevel(); 54 console.info("normal level is: " + normal); 55 expect(normal >= 0 && normal <= 5).assertEqual('1'); 56 resolve(); 57 }, MSEC_10000); 58 }) 59 done(); 60 }) 61 62 /** 63 * @tc.number thermal_manager_js_002 64 * @tc.name Thermal_002 65 * @tc.desc Thermal acquisition kit 66 */ 67 it('Thermal_002', 0, async function (done) { 68 await new Promise((resolve, reject) => { 69 setTimeout(() => { 70 var warm = thermal.getThermalLevel(); 71 console.info("warm level is: " + warm); 72 expect(warm >= 0 && warm <= 5).assertEqual('1'); 73 resolve(); 74 }, MSEC_10000); 75 }) 76 done(); 77 }) 78 79 /** 80 * @tc.number thermal_manager_js_003 81 * @tc.name Thermal_003 82 * @tc.desc Thermal acquisition kit 83 */ 84 it('Thermal_003', 0, async function (done) { 85 await new Promise((resolve, reject) => { 86 setTimeout(() => { 87 var hot = thermal.getThermalLevel(); 88 console.info("hot level is: " + hot); 89 expect(hot >= 0 && hot <= 5).assertEqual('1'); 90 resolve(); 91 }, MSEC_10000); 92 }) 93 done(); 94 }) 95 96 /** 97 * @tc.number thermal_manager_js_004 98 * @tc.name Thermal_004 99 * @tc.desc Thermal acquisition kit 100 */ 101 it('Thermal_004', 0, async function (done) { 102 await new Promise((resolve, reject) => { 103 setTimeout(() => { 104 var overheated = thermal.getThermalLevel(); 105 console.info("overheated level is: " + overheated); 106 expect(overheated >= 0 && overheated <= 5).assertEqual('1'); 107 resolve(); 108 }, MSEC_10000); 109 }) 110 done(); 111 }) 112 113 /** 114 * @tc.number thermal_manager_js_005 115 * @tc.name Thermal_005 116 * @tc.desc Thermal acquisition kit 117 */ 118 it('Thermal_005', 0, async function (done) { 119 await new Promise((resolve, reject) => { 120 setTimeout(() => { 121 var warning = thermal.getThermalLevel(); 122 console.info("warning level is: " + warning); 123 expect(warning >= 0 && warning <= 5).assertEqual('1'); 124 resolve(); 125 }, MSEC_10000); 126 }) 127 done(); 128 }) 129 130 /** 131 * @tc.number thermal_manager_js_006 132 * @tc.name Thermal_006 133 * @tc.desc Thermal acquisition kit 134 */ 135 it('Thermal_006', 0, async function (done) { 136 await new Promise((resolve, reject) => { 137 setTimeout(() => { 138 var emergency = thermal.getThermalLevel(); 139 console.info("emergency level is: " + emergency); 140 expect(emergency >= 0 && emergency <= 5).assertEqual('1'); 141 resolve(); 142 }, MSEC_10000); 143 }) 144 done(); 145 }) 146 147 /** 148 * @tc.number thermal_manager_js_007 149 * @tc.name Thermal_007 150 * @tc.desc Thermal acquisition kit 151 */ 152 it('Thermal_007', 0, async function (done) { 153 var count = 0; 154 thermal.subscribeThermalLevel((cool) => { 155 console.info("cool level is: " + cool); 156 count++; 157 expect(cool >= 0 && cool <= 5).assertEqual('1'); 158 }) 159 await new Promise((resolve, reject) => { 160 setTimeout(() => { 161 thermal.unsubscribeThermalLevel(); 162 resolve(); 163 }, MSEC_10000); 164 }) 165 expect(count >= 1).assertEqual('1'); 166 done(); 167 }) 168 169 /** 170 * @tc.number thermal_manager_js_008 171 * @tc.name Thermal_008 172 * @tc.desc Thermal acquisition kit 173 */ 174 it('Thermal_008', 0, async function (done) { 175 var count = 0; 176 thermal.subscribeThermalLevel((warm) => { 177 console.info("cool level is: " + warm); 178 count++; 179 expect(warm >= 0 && warm <= 5).assertEqual('1'); 180 }) 181 await new Promise((resolve, reject) => { 182 setTimeout(() => { 183 thermal.unsubscribeThermalLevel(); 184 resolve(); 185 }, MSEC_10000); 186 }) 187 expect(count >= 1).assertEqual('1'); 188 done(); 189 }) 190 191 /** 192 * @tc.number thermal_manager_js_009 193 * @tc.name Thermal_009 194 * @tc.desc Thermal acquisition kit 195 */ 196 it('Thermal_009', 0, async function (done) { 197 var count = 0; 198 thermal.subscribeThermalLevel((hot) => { 199 console.info("hot level is: " + hot); 200 count++; 201 expect(hot >= 0 && hot <= 5).assertEqual('1'); 202 }) 203 await new Promise((resolve, reject) => { 204 setTimeout(() => { 205 thermal.unsubscribeThermalLevel(); 206 resolve(); 207 }, MSEC_10000); 208 }) 209 expect(count >= 1).assertEqual('1'); 210 done(); 211 }) 212 213 /** 214 * @tc.number thermal_manager_js_010 215 * @tc.name Thermal_010 216 * @tc.desc Thermal acquisition kit 217 */ 218 it('Thermal_010', 0, async function (done) { 219 var count = 0; 220 thermal.subscribeThermalLevel((overheated) => { 221 console.info("overheated level is: " + overheated); 222 count++; 223 expect(overheated >= 0 && overheated <= 5).assertEqual('1'); 224 }) 225 await new Promise((resolve, reject) => { 226 setTimeout(() => { 227 thermal.unsubscribeThermalLevel(); 228 resolve(); 229 }, MSEC_10000); 230 }) 231 expect(count >= 1).assertEqual('1'); 232 done(); 233 }) 234 235 /** 236 * @tc.number thermal_manager_js_011 237 * @tc.name Thermal_011 238 * @tc.desc Thermal acquisition kit 239 */ 240 it('Thermal_011', 0, async function (done) { 241 var count = 0; 242 thermal.subscribeThermalLevel((warning) => { 243 console.info("warning level is: " + warning); 244 count++; 245 expect(warning >= 0 && warning <= 5).assertEqual('1'); 246 }) 247 await new Promise((resolve, reject) => { 248 setTimeout(() => { 249 thermal.unsubscribeThermalLevel(); 250 resolve(); 251 }, MSEC_10000); 252 }) 253 expect(count >= 1).assertEqual('1'); 254 done(); 255 }) 256 257 /** 258 * @tc.number thermal_manager_js_012 259 * @tc.name Thermal_012 260 * @tc.desc Thermal acquisition kit 261 */ 262 it('Thermal_012', 0, async function (done) { 263 var count = 0; 264 thermal.subscribeThermalLevel((emergency) => { 265 console.info("emergency level is: " + emergency); 266 count++; 267 expect(emergency >= 0 && emergency <= 5).assertEqual('1'); 268 }) 269 await new Promise((resolve, reject) => { 270 setTimeout(() => { 271 thermal.unsubscribeThermalLevel(); 272 resolve(); 273 }, MSEC_10000); 274 }) 275 expect(count >= 1).assertEqual('1'); 276 done(); 277 }) 278 279 /** 280 * @tc.number thermal_manager_js_013 281 * @tc.name Thermal_013 282 * @tc.desc Thermal acquisition kit 283 */ 284 it('Thermal_013', 0, async function (done) { 285 var count = 0; 286 thermal.subscribeThermalLevel((normal) => { 287 console.info("normal level is: " + normal); 288 count++; 289 expect(normal >= 0 && normal <= 5).assertEqual('1'); 290 }) 291 await new Promise((resolve, reject) => { 292 setTimeout(() => { 293 thermal.unsubscribeThermalLevel(); 294 resolve(); 295 }, MSEC_10000); 296 }) 297 expect(count >= 1).assertEqual('1'); 298 done(); 299 }) 300 301 /** 302 * @tc.number thermal_manager_js_014 303 * @tc.name Thermal_014 304 * @tc.desc Thermal acquisition kit 305 */ 306 it('Thermal_014', 0, async function (done) { 307 var count = 0; 308 thermal.subscribeThermalLevel((cool) => { 309 console.info("cool level is: " + cool); 310 count++; 311 expect(cool >= 0 && cool <= 5).assertEqual('1'); 312 }) 313 await new Promise((resolve, reject) => { 314 setTimeout(() => { 315 thermal.unsubscribeThermalLevel(); 316 resolve(); 317 }, MSEC_10000 * 2); 318 }) 319 expect(count >= 2).assertEqual('1'); 320 done(); 321 }) 322}) 323