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 bundlestate from '@ohos.bundleState'; 17import {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect, Level } from '@ohos/hypium' 18 19function onInit() { 20 let obj = {startTime: 0,endTime: 0}; 21 const myTime = new Date().getTime(); 22 obj.startTime = myTime - 86400000; 23 obj.endTime = myTime 24 return obj; 25} 26let bundleName = 'com.example.backgroundTaskManager'; 27let bundleNames = 'com.example.backgroundTaskManagers'; 28const byInterval = bundlestate.IntervalType.BY_DAILY; 29const toMerge = { 30 "abilityInFgTotalTime": 0, 31 "abilityPrevAccessTime": 1629907200000, 32 "abilityPrevSeenTime": 0, 33 "abilitySeenTotalTime": 0, 34 "bundleName": "com.example.backgroundTaskManager", 35 "fgAbilityAccessTotalTime": 0, 36 "fgAbilityPrevAccessTime": 0, 37 "id": 0, 38 "infosBeginTime": 1629907200000, 39 "infosEndTime": 1629993599999 40} 41export default function bundlestate_test() { 42describe('bundlestate_test', function() { 43 console.info('Start test tvmw bundlestate######################'); 44 beforeAll(function() { 45 console.info('beforeAll') 46 }) 47 48 afterAll(function() { 49 console.info('afterAll begin') 50 }) 51 52 beforeEach(function() { 53 console.info('beforeEach caled') 54 }) 55 56 afterEach(function() { 57 console.info('afterEach caled') 58 }) 59 60 /* 61 * @tc.number: SUB_INTELLITV_JS_BUNDLE_0024 62 * @tc.name: merge_024. 63 * @tc.desc: Execute merge with callback. 64 * @tc.size: MEDIUM 65 * @tc.type: Function 66 * @tc.level: level 0 67 */ 68 it('merge_024', Level.LEVEL0, function(done) { 69 console.info('bundle merge_024 start'); 70 let toMerge02 = { 71 "abilityInFgTotalTime": 0, 72 "abilityPrevAccessTime": 1629907200000, 73 "abilityPrevSeenTime": 0, 74 "abilitySeenTotalTime": 0, 75 "bundleName": "com.example.backgroundTaskManager", 76 "fgAbilityAccessTotalTime": 0, 77 "fgAbilityPrevAccessTime": 0, 78 "id": 0, 79 "infosBeginTime": 1629907200000, 80 "infosEndTime": 1629993599999, 81 }; 82 try { 83 let ret = bundlestate.BundleStateInfo.merge(toMerge02); 84 expect(ret).assertUndefined() 85 } catch(e) { 86 console.info('bundle merge_024 failed'); 87 let err = 0; 88 expect(err).assertEqual(0); 89 } 90 done(); 91 console.info('merge_024 end'); 92 }) 93 94 /* 95 * @tc.number: SUB_INTELLITV_JS_BUNDLE_0025 96 * @tc.name: merge_025. 97 * @tc.desc: Execute merge with callback. 98 * @tc.size: MEDIUM 99 * @tc.type: Function 100 * @tc.level: level 0 101 */ 102 it('merge_025', Level.LEVEL0, function(done) { 103 console.info('bundle merge_025 start'); 104 let toMerge03 = { 105 "abilityInFgTotalTime": 'text', 106 "abilityPrevAccessTime": 'text', 107 "abilityPrevSeenTime": 'text', 108 "abilitySeenTotalTime": 'text', 109 "bundleName": "com.example.backgroundTaskManager", 110 "fgAbilityAccessTotalTime": 'text', 111 "fgAbilityPrevAccessTime": 'text', 112 "id": 'text', 113 "infosBeginTime": 'text', 114 "infosEndTime": 'text', 115 }; 116 try { 117 let ret = bundlestate.BundleStateInfo.merge(toMerge03); 118 expect(ret).assertUndefined() 119 } catch(e) { 120 console.info('bundle merge_025 failed'); 121 let err = 0; 122 expect(err).assertEqual(0); 123 } 124 done(); 125 console.info('merge_025 end'); 126 }) 127 128 /* 129 * @tc.number: SUB_INTELLITV_JS_0026 130 * @tc.name: merge_026. 131 * @tc.desc: Execute merge with callback. 132 * @tc.size: MEDIUM 133 * @tc.type: Function 134 * @tc.level: level 0 135 */ 136 it('merge_026', Level.LEVEL0, function(done) { 137 console.info('bundle merge_026 start'); 138 try { 139 let ret = bundlestate.BundleStateInfo.merge(null); 140 expect(ret).assertUndefined() 141 } catch(e) { 142 console.info('bundle merge_026 failed'); 143 let err = 0; 144 expect(err).assertEqual(0); 145 } 146 done(); 147 console.info('merge_026 end'); 148 }) 149 150 /* 151 * @tc.number: SUB_INTELLITV_JS_0027 152 * @tc.name: merge_027. 153 * @tc.desc: Execute merge with callback. 154 * @tc.size: MEDIUM 155 * @tc.type: Function 156 * @tc.level: level 0 157 */ 158 it('merge_027', Level.LEVEL0, function(done) { 159 console.info('bundle merge_027 start'); 160 try { 161 let ret = bundlestate.BundleStateInfo.merge(true); 162 expect(ret).assertUndefined() 163 } catch(e) { 164 console.info('bundle merge_027 failed'); 165 let err = 0; 166 expect(err).assertEqual(0); 167 } 168 done(); 169 console.info('merge_027 end'); 170 }) 171 172 /* 173 * @tc.number: SUB_INTELLITV_JS_0028 174 * @tc.name: merge_028. 175 * @tc.desc: Execute merge with callback. 176 * @tc.size: MEDIUM 177 * @tc.type: Function 178 * @tc.level: level 0 179 */ 180 it('merge_028', Level.LEVEL0, function(done) { 181 console.info('bundle merge_028 start'); 182 try { 183 let ret = bundlestate.BundleStateInfo.merge(123); 184 expect(ret).assertUndefined() 185 } catch(e) { 186 console.info('bundle merge_028 failed'); 187 let err = 0; 188 expect(err).assertEqual(0); 189 } 190 done(); 191 console.info('merge_028 end'); 192 }) 193 194 /* 195 * @tc.number: SUB_INTELLITV_JS_BUNDLE_0052 196 * @tc.name: isIdleState_052. 197 * @tc.desc: Execute isIdleState with callback. 198 * @tc.size: MEDIUM 199 * @tc.type: Function 200 * @tc.level: level 0 201 */ 202 it('isIdleState_052', Level.LEVEL0, async function(done) { 203 console.info('isIdleState_052 start'); 204 bundlestate.isIdleState(bundleName, (err, res) => { 205 if(err) { 206 console.info('isIdleState_052 callback fail result = ' + JSON.stringify(err.code)); 207 expect(err.code).assertLarger(0); 208 } else { 209 console.info('isIdleState_052 callback success result = ' + JSON.stringify(res)); 210 if(res) { 211 expect(res).assertTrue(); 212 } else { 213 expect(res).assertFalse(); 214 } 215 } 216 done(); 217 }); 218 console.info('isIdleState_052 end'); 219 }) 220 221 /* 222 * @tc.number: SUB_INTELLITV_JS_BUNDLE_0053 223 * @tc.name: isIdleState_053. 224 * @tc.desc: Execute isIdleState with callback. 225 * @tc.size: MEDIUM 226 * @tc.type: Function 227 * @tc.level: level 0 228 */ 229 it('isIdleState_053', Level.LEVEL0, async function(done) { 230 console.info('isIdleState_053 start'); 231 let bundleName02 = 'ohos.plrdtest.resourceschedule' 232 bundlestate.isIdleState(bundleName02, (err, res) => { 233 if(err) { 234 console.info('isIdleState_053 callback fail result = ' + err); 235 } else { 236 console.info('isIdleState_053 callback success result = ' + JSON.stringify(res)); 237 expect(res).assertInstanceOf('Boolean'); 238 }; 239 done(); 240 }); 241 console.info('isIdleState_053 end'); 242 }) 243 244 /* 245 * @tc.number: SUB_INTELLITV_JS_BUNDLE_0054 246 * @tc.name: isIdleState_054. 247 * @tc.desc: Execute isIdleState with promise. 248 * @tc.size: MEDIUM 249 * @tc.type: Function 250 * @tc.level: level 0 251 */ 252 it('isIdleState_054', Level.LEVEL0, async function(done) { 253 console.info('isIdleState_054 start'); 254 bundlestate.isIdleState(bundleNames).then((data) => { 255 console.info('isIdleState_054 promise success result = ' + JSON.stringify(data)); 256 if(res) { 257 expect(res).assertTrue(); 258 } else { 259 expect(res).assertFalse(); 260 }; 261 done(); 262 }).catch((err) => { 263 console.info('isIdleState_054 promise fail result = ' + JSON.stringify(err.code)); 264 expect(err.code).assertUndefined(); 265 done(); 266 }) 267 console.info('isIdleState_054 end'); 268 }) 269 270 /* 271 * @tc.number: SUB_INTELLITV_JS_BUNDLE_0055 272 * @tc.name: isIdleState_055. 273 * @tc.desc: Execute isIdleState with promise. 274 * @tc.size: MEDIUM 275 * @tc.type: Function 276 * @tc.level: level 0 277 */ 278 it('isIdleState_055', Level.LEVEL0, async function(done) { 279 console.info('isIdleState_055 start'); 280 let bundleName31 = 'ohos.plrdtest.resourceschedule' 281 bundlestate.isIdleState(bundleName31).then((res) => { 282 console.info('isIdleState_055 promise success result = ' + res); 283 expect(res).assertFalse(); 284 }).catch((err) => { 285 console.info('isIdleState_055 promise fail result = ' + JSON.stringify(err)); 286 expect(err.code).assertLarger(0); 287 }) 288 done(); 289 console.info('isIdleState_055 end'); 290 }) 291 292 /* 293 * @tc.number: SUB_INTELLITV_JS_BUNDLE_0056 294 * @tc.name: isIdleState_056. 295 * @tc.desc: Execute isIdleState with callback. 296 * @tc.size: MEDIUM 297 * @tc.type: Function 298 * @tc.level: level 0 299 */ 300 it('isIdleState_056', Level.LEVEL0, async function(done) { 301 console.info('isIdleState_056 start'); 302 bundlestate.isIdleState(123, (err, data) => { 303 if(err) { 304 console.info('isIdleState_056 callback fail result = ' + JSON.stringify(err.code)); 305 expect(err.code).assertLarger(0); 306 } else { 307 console.info('isIdleState_056 callback success result = ' + JSON.stringify(data)); 308 expect(data).assertFail(); 309 } 310 done(); 311 }); 312 console.info('isIdleState_056 end'); 313 }) 314 315 /* 316 * @tc.number: SUB_INTELLITV_JS_BUNDLE_0062 317 * @tc.name: isIdleState_062. 318 * @tc.desc: Execute isIdleState with Promise. 319 * @tc.size: MEDIUM 320 * @tc.type: Function 321 * @tc.level: level 0 322 */ 323 it('isIdleState_062', Level.LEVEL0, async function(done) { 324 console.info('isIdleState_062 start'); 325 bundlestate.isIdleState(123).then((res) => { 326 console.info('isIdleState_062 promise success result = ' + JSON.stringify(res)); 327 expect(res).assertFail(); 328 }).catch((err) => { 329 console.info('isIdleState_062 promise fail result = ' + JSON.stringify(err)); 330 expect(err.code).assertLarger(0); 331 }) 332 done(); 333 console.info('isIdleState_062 end'); 334 }) 335 336 /* 337 * @tc.number: SUB_INTELLITV_JS_BUNDLE_0057 338 * @tc.name: isIdleState_057. 339 * @tc.desc: Execute isIdleState with callback. 340 * @tc.size: MEDIUM 341 * @tc.type: Function 342 * @tc.level: level 0 343 */ 344 it('isIdleState_057', Level.LEVEL0, async function(done) { 345 console.info('isIdleState_057 start'); 346 bundlestate.isIdleState(null, (err, data) => { 347 if(err) { 348 console.info('isIdleState_057 callback fail result = ' + JSON.stringify(err.code)); 349 expect(err.code).assertLarger(0); 350 } else { 351 console.info('isIdleState_057 callback success result = ' + JSON.stringify(data)); 352 expect(data).assertFail(); 353 } 354 done(); 355 }); 356 console.info('isIdleState_057 end'); 357 }) 358 359 /* 360 * @tc.number: SUB_INTELLITV_JS_BUNDLE_0063 361 * @tc.name: isIdleState_063. 362 * @tc.desc: Execute isIdleState with Promise. 363 * @tc.size: MEDIUM 364 * @tc.type: Function 365 * @tc.level: level 0 366 */ 367 it('isIdleState_063', Level.LEVEL0, async function(done) { 368 console.info('isIdleState_063 start'); 369 bundlestate.isIdleState(null).then((res) => { 370 console.info('isIdleState_063 promise success result = ' + JSON.stringify(res)); 371 expect(res).assertFail(); 372 }).catch((err) => { 373 console.info('isIdleState_063 promise fail result = ' + JSON.stringify(err)); 374 expect(err.code).assertLarger(0); 375 }) 376 done(); 377 console.info('isIdleState_063 end'); 378 }) 379 380 /* 381 * @tc.number: SUB_INTELLITV_JS_BUNDLE_0058 382 * @tc.name: isIdleState_058. 383 * @tc.desc: Execute isIdleState with callback. 384 * @tc.size: MEDIUM 385 * @tc.type: Function 386 * @tc.level: level 0 387 */ 388 it('isIdleState_058', Level.LEVEL0, async function(done) { 389 console.info('isIdleState_058 start'); 390 bundlestate.isIdleState(true, (err, data) => { 391 if(err) { 392 console.info('isIdleState_058 callback fail result = ' + JSON.stringify(err.code)); 393 expect(err.code).assertLarger(0); 394 } else { 395 console.info('isIdleState_058 callback success result = ' + JSON.stringify(data)); 396 expect(data).assertFail(); 397 } 398 done(); 399 }); 400 console.info('isIdleState_058 end'); 401 }) 402 403 /* 404 * @tc.number: SUB_INTELLITV_JS_BUNDLE_0059 405 * @tc.name: isIdleState_059. 406 * @tc.desc: Execute isIdleState with callback. 407 * @tc.size: MEDIUM 408 * @tc.type: Function 409 * @tc.level: level 0 410 */ 411 it('isIdleState_059', Level.LEVEL0, async function(done) { 412 console.info('isIdleState_059 start'); 413 bundlestate.isIdleState(false, (err, data) => { 414 if(err) { 415 console.info('isIdleState_059 callback fail result = ' + JSON.stringify(err)); 416 expect(err.code).assertLarger(0); 417 } else { 418 console.info('isIdleState_059 callback success result = ' + JSON.stringify(data)); 419 expect(data).assertFail(); 420 } 421 done(); 422 }); 423 console.info('isIdleState_059 end'); 424 }) 425 426 /* 427 * @tc.number: SUB_INTELLITV_JS_BUNDLE_0064 428 * @tc.name: isIdleState_064. 429 * @tc.desc: Execute isIdleState with Promise. 430 * @tc.size: MEDIUM 431 * @tc.type: Function 432 * @tc.level: level 0 433 */ 434 it('isIdleState_064', Level.LEVEL0, async function(done) { 435 console.info('isIdleState_064 start'); 436 bundlestate.isIdleState(false).then((res) => { 437 console.info('isIdleState_064 promise success result = ' + JSON.stringify(res)); 438 expect(res).assertFail(); 439 }).catch((err) => { 440 console.info('isIdleState_064 promise fail result = ' + JSON.stringify(err)); 441 expect(err.code).assertLarger(0); 442 }) 443 done(); 444 console.info('isIdleState_064 end'); 445 }) 446 447 /* 448 * @tc.number: SUB_INTELLITV_JS_BUNDLE_0060 449 * @tc.name: isIdleState_060. 450 * @tc.desc: Execute isIdleState with callback. 451 * @tc.size: MEDIUM 452 * @tc.type: Function 453 * @tc.level: level 0 454 */ 455 it('isIdleState_060', Level.LEVEL0, async function(done) { 456 console.info('isIdleState_060 start'); 457 bundlestate.isIdleState('', (err, data) => { 458 if(err) { 459 console.info('isIdleState_060 callback fail result = ' + JSON.stringify(err.code)); 460 expect(err.code).assertLarger(0); 461 } else { 462 console.info('isIdleState_060 callback success result = ' + JSON.stringify(data)); 463 expect(data).assertFail(); 464 } 465 done(); 466 }); 467 console.info('isIdleState_060 end'); 468 }) 469 470 /* 471 * @tc.number: SUB_INTELLITV_JS_BUNDLE_0061 472 * @tc.name: isIdleState_061. 473 * @tc.desc: Execute isIdleState with Promise. 474 * @tc.size: MEDIUM 475 * @tc.type: Function 476 * @tc.level: level 0 477 */ 478 it('isIdleState_061', Level.LEVEL0, async function(done) { 479 console.info('isIdleState_061 start'); 480 bundlestate.isIdleState('').then((res) => { 481 console.info('isIdleState_061 promise success result = ' + JSON.stringify(res)); 482 expect(res).assertFail(); 483 }).catch((err) => { 484 console.info('isIdleState_061 promise fail result = ' + JSON.stringify(err)); 485 expect(err.code).assertLarger(0); 486 }) 487 done(); 488 console.info('isIdleState_061 end'); 489 }) 490 491 /* 492 * @tc.number: SUB_INTELLITV_JS_BUNDLE_065 493 * @tc.name: isIdleState_065. 494 * @tc.desc: Execute isIdleState with Promise. 495 * @tc.size: MEDIUM 496 * @tc.type: Function 497 * @tc.level: level 0 498 */ 499 it('isIdleState_065', Level.LEVEL0, async function(done) { 500 console.info('isIdleState_065 start'); 501 bundlestate.isIdleState(true).then((res) => { 502 console.info('isIdleState_065 promise success result = ' + JSON.stringify(res)); 503 expect(res).assertFail(); 504 }).catch((err) => { 505 console.info('isIdleState_065 promise fail result = ' + JSON.stringify(err)); 506 expect(err.code).assertLarger(0); 507 }) 508 done(); 509 console.info('isIdleState_065 end'); 510 }) 511 512})} 513