• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 bundleState from '@ohos.bundleState'
17
18import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from '@ohos/hypium'
19
20export default function DeviceUsageStatisticsJsTest() {
21    describe("DeviceUsageStatisticsJsTest", function () {
22        beforeAll(function () {
23
24            /*
25             * @tc.setup: setup invoked before all testcases
26             */
27            console.info('beforeAll called')
28        })
29
30        afterAll(function () {
31
32            /*
33             * @tc.teardown: teardown invoked after all testcases
34             */
35            console.info('afterAll called')
36        })
37
38        beforeEach(function () {
39
40            /*
41             * @tc.setup: setup invoked before each testcases
42             */
43            console.info('beforeEach called')
44        })
45
46        afterEach(function () {
47
48            /*
49             * @tc.teardown: teardown invoked after each testcases
50             */
51            console.info('afterEach caled')
52        })
53
54        /*
55         * @tc.number:SUB_RESOURCESCHEDULE_USAGEINFO_QUERY_XTS_001
56         * @tc.name: DeviceUsageStatisticsJsTest001
57         * @tc.desc:  isIdleState promise.
58         */
59        it("DeviceUsageStatisticsJsTest001", 0, async function (done) {
60            console.info('----------------------DeviceUsageStatisticsJsTest001---------------------------');
61            let bundleName = 'ohos.acts.resourceschedule.deviceusagestatisticsjsunit.js.function';
62            bundleState.isIdleState(bundleName).then((res) => {
63                console.info(' DeviceUsageStatisticsJsTest001 isIdleStateone promise success.' + res);
64                expect(res).assertEqual(false);
65                done();
66            }).catch((err) => {
67                console.info(' DeviceUsageStatisticsJsTest001 isIdleState promise failure.' + err.code);
68            });
69        })
70
71        /*
72         * @tc.number:SUB_RESOURCESCHEDULE_USAGEINFO_QUERY_XTS_002
73         * @tc.name: DeviceUsageStatisticsJsTest002
74         * @tc.desc:  isIdleState callback.
75         */
76        it("DeviceUsageStatisticsJsTest002", 0, async function (done) {
77            console.info('----------------------DeviceUsageStatisticsJsTest002---------------------------');
78            let bundleName = 'ohos.acts.resourceschedule.deviceusagestatisticsjsunit.js.function';
79            bundleState.isIdleState(bundleName, (err, res) => {
80                if (err) {
81                    console.info(' DeviceUsageStatisticsJsTest002 isIdleState callback failure.' + err.code);
82                } else {
83                    console.info(' DeviceUsageStatisticsJsTest002 isIdleState callback success.' + res);
84                    expect(res).assertEqual(false);
85                    done();
86                }
87            });
88        })
89
90        /*
91         * @tc.number:SUB_RESOURCESCHEDULE_USAGEINFO_QUERY_XTS_003
92         * @tc.name: DeviceUsageStatisticsJsTest003
93         * @tc.desc:  queryAppUsagePriorityGroup promise.
94         */
95        it("DeviceUsageStatisticsJsTest003", 0, async function (done) {
96            console.info('----------------------DeviceUsageStatisticsJsTest003---------------------------');
97            bundleState.queryAppUsagePriorityGroup().then(res => {
98                console.info(' DeviceUsageStatisticsJsTest003 queryAppUsagePriorityGroup promise success.' + res);
99                expect(res).assertLarger(0);
100                done();
101            }).catch(err => {
102                console.info(' DeviceUsageStatisticsJsTest003 queryAppUsagePriorityGroup promise failure.' + err.code);
103            });
104        })
105
106        /*
107         * @tc.number:SUB_RESOURCESCHEDULE_USAGEINFO_QUERY_XTS_004
108         * @tc.name: DeviceUsageStatisticsJsTest004
109         * @tc.desc:  queryAppUsagePriorityGroup callback.
110         */
111        it("DeviceUsageStatisticsJsTest004", 0, async function (done) {
112            console.info('----------------------DeviceUsageStatisticsJsTest004---------------------------');
113            bundleState.queryAppUsagePriorityGroup((err, res) => {
114                if (err) {
115                    console.info(' DeviceUsageStatisticsJsTest004 queryAppUsagePriorityGroup callback failure.' + err.code);
116                } else {
117                    console.info(' DeviceUsageStatisticsJsTest004 queryAppUsagePriorityGroup callback success.' + res);
118                    expect(res).assertLarger(0);
119                    done();
120                }
121            });
122        })
123
124        /*
125         * @tc.number:SUB_RESOURCESCHEDULE_USAGEINFO_QUERY_XTS_005
126         * @tc.name: DeviceUsageStatisticsJsTest005
127         * @tc.desc:  queryCurrentBundleActiveStates promise.
128         */
129        it("DeviceUsageStatisticsJsTest005", 0, async function (done) {
130            console.info('----------------------DeviceUsageStatisticsJsTest005---------------------------');
131            let beginTime = 0;
132            let endTime = 20000000000000;
133            bundleState.queryCurrentBundleActiveStates(beginTime, endTime).then((res) => {
134                console.info(' DeviceUsageStatisticsJsTest005 queryCurrentBundleActiveStates promise success.' + res);
135                expect(res).assertInstanceOf('Array');
136                done();
137            }).catch((err) => {
138                console.info(' DeviceUsageStatisticsJsTest005 queryCurrentBundleActiveStates promise failure.' + err.code);
139            });
140        })
141
142        /*
143         * @tc.number:SUB_RESOURCESCHEDULE_USAGEINFO_QUERY_XTS_006
144         * @tc.name: DeviceUsageStatisticsJsTest006
145         * @tc.desc:  queryCurrentBundleActiveStates callback.
146         */
147        it("DeviceUsageStatisticsJsTest006", 0, async function (done) {
148            console.info('----------------------DeviceUsageStatisticsJsTest006---------------------------');
149            let beginTime = 0;
150            let endTime = 20000000000000;
151            bundleState.queryCurrentBundleActiveStates(beginTime, endTime, (err, res) => {
152                if (err) {
153                    console.info(' DeviceUsageStatisticsJsTest006 queryCurrentBundleActiveStates callback failure.' + err.code);
154                } else {
155                    console.info(' DeviceUsageStatisticsJsTest006 queryCurrentBundleActiveStates callback success.' + res);
156                    expect(res).assertInstanceOf('Array');
157                    done();
158                }
159            });
160        })
161
162        /*
163         * @tc.number:SUB_RESOURCESCHEDULE_USAGEINFO_QUERY_XTS_007
164         * @tc.name: DeviceUsageStatisticsJsTest007
165         * @tc.desc:  intervalType BY_OPTIMIZED
166         */
167        it("DeviceUsageStatisticsJsTest007", 0, function (done) {
168            console.info('----------------------DeviceUsageStatisticsJsTest007---------------------------');
169            let value1 = bundleState.IntervalType.BY_OPTIMIZED;
170            expect(value1).assertEqual(0)
171            done();
172        })
173
174        /*
175         * @tc.number:SUB_RESOURCESCHEDULE_USAGEINFO_QUERY_XTS_008
176         * @tc.name: DeviceUsageStatisticsJsTest008
177         * @tc.desc:  intervalType BY_DAILY
178         */
179        it("DeviceUsageStatisticsJsTest008", 0, function (done) {
180            console.info('----------------------DeviceUsageStatisticsJsTest008---------------------------');
181            let value1 = bundleState.IntervalType.BY_DAILY;
182            expect(value1).assertEqual(1)
183            done();
184        })
185
186        /*
187         * @tc.number:SUB_RESOURCESCHEDULE_USAGEINFO_QUERY_XTS_009
188         * @tc.name: DeviceUsageStatisticsJsTest009
189         * @tc.desc:  intervalType BY_WEEKLY
190         */
191        it("DeviceUsageStatisticsJsTest009", 0, function (done) {
192            console.info('----------------------DeviceUsageStatisticsJsTest009---------------------------');
193            let value1 = bundleState.IntervalType.BY_WEEKLY;
194            expect(value1).assertEqual(2)
195            done();
196        })
197
198        /*
199         * @tc.number:SUB_RESOURCESCHEDULE_USAGEINFO_QUERY_XTS_0010
200         * @tc.name: DeviceUsageStatisticsJsTest0010
201         * @tc.desc:  intervalType BY_MONTHLY
202         */
203        it("DeviceUsageStatisticsJsTest0010", 0, function (done) {
204            console.info('----------------------DeviceUsageStatisticsJsTest0010---------------------------');
205            let value1 = bundleState.IntervalType.BY_MONTHLY;
206            expect(value1).assertEqual(3)
207            done();
208        })
209
210        /*
211         * @tc.number:SUB_RESOURCESCHEDULE_USAGEINFO_QUERY_XTS_0011
212         * @tc.name: DeviceUsageStatisticsJsTest0011
213         * @tc.desc:  intervalType BY_ANNUALLY
214         */
215        it("DeviceUsageStatisticsJsTest0011", 0, function (done) {
216            console.info('----------------------DeviceUsageStatisticsJsTest0011---------------------------');
217            let value1 = bundleState.IntervalType.BY_ANNUALLY;
218            expect(value1).assertEqual(4)
219            done();
220        })
221
222        /*
223         * @tc.number:SUB_RESOURCESCHEDULE_USAGEINFO_QUERY_XTS_0012
224         * @tc.name: DeviceUsageStatisticsJsTest0012
225         * @tc.desc:  bundleState isIdleState promise.
226         */
227        it("DeviceUsageStatisticsJsTest0012", 0, async function (done) {
228            console.info('----------------------DeviceUsageStatisticsJsTest0012---------------------------');
229            bundleState.isIdleState('').then((res) => {
230                console.info(' bundle DeviceUsageStatisticsJsTest0012 promise success, result= ' + res);
231            }).catch((err) => {
232                console.info(' bundle DeviceUsageStatisticsJsTest0012 promise fail, result= ' + err.code);
233                expect(err.code).assertLarger(0);
234                done();
235            });
236        })
237
238        /*
239         * @tc.number:SUB_RESOURCESCHEDULE_USAGEINFO_QUERY_XTS_0013
240         * @tc.name: DeviceUsageStatisticsJsTest0013
241         * @tc.desc:  bundleState isIdleState promise.
242         */
243        it("DeviceUsageStatisticsJsTest0013", 0, async function (done) {
244            console.info('----------------------DeviceUsageStatisticsJsTest0013---------------------------');
245            bundleState.isIdleState(12345).then((res) => {
246                console.info(' bundle DeviceUsageStatisticsJsTest0013 promise success, result= ' + res);
247            }).catch((err) => {
248                console.info(' bundle DeviceUsageStatisticsJsTest0013 promise fail, result= ' + err.code);
249                expect(err.code).assertLarger(0);
250                done();
251            });
252        })
253
254        /*
255         * @tc.number:SUB_RESOURCESCHEDULE_USAGEINFO_QUERY_XTS_0014
256         * @tc.name: DeviceUsageStatisticsJsTest0014
257         * @tc.desc:  bundleState isIdleState promise.
258         */
259        it("DeviceUsageStatisticsJsTest0014", 0, async function (done) {
260            console.info('----------------------DeviceUsageStatisticsJsTest0014---------------------------');
261            bundleState.isIdleState(true).then((res) => {
262                console.info(' bundle DeviceUsageStatisticsJsTest0014 promise success, result= ' + res);
263            }).catch((err) => {
264                console.info(' bundle DeviceUsageStatisticsJsTest0014 promise fail, result= ' + err.code);
265                expect(err.code).assertLarger(0);
266                done();
267            });
268        })
269
270        /*
271         * @tc.number:SUB_RESOURCESCHEDULE_USAGEINFO_QUERY_XTS_0015
272         * @tc.name: DeviceUsageStatisticsJsTest0015
273         * @tc.desc:  bundleState isIdleState promise.
274         */
275        it("DeviceUsageStatisticsJsTest0015", 0, async function (done) {
276            console.info('----------------------DeviceUsageStatisticsJsTest0015---------------------------');
277            bundleState.isIdleState(null).then((res) => {
278                console.info(' bundle DeviceUsageStatisticsJsTest0015 promise success, result= ' + res);
279            }).catch((err) => {
280                console.info(' bundle DeviceUsageStatisticsJsTest0015 promise fail, result= ' + err.code);
281                expect(err.code).assertLarger(0);
282                done();
283            });
284        })
285
286        /*
287         * @tc.number:SUB_RESOURCESCHEDULE_USAGEINFO_QUERY_XTS_0016
288         * @tc.name: DeviceUsageStatisticsJsTest0016
289         * @tc.desc:  bundleState isIdleState promise.
290         */
291        it("DeviceUsageStatisticsJsTest0016", 0, async function (done) {
292            console.info('----------------------DeviceUsageStatisticsJsTest0016---------------------------');
293            bundleState.isIdleState(undefined).then((res) => {
294                console.info(' bundle DeviceUsageStatisticsJsTest0016 promise success, result= ' + res);
295            }).catch((err) => {
296                console.info(' bundle DeviceUsageStatisticsJsTest0016 promise fail, result= ' + err.code);
297                expect(err.code).assertLarger(0);
298                done();
299            });
300        })
301
302        /*
303         * @tc.number:SUB_RESOURCESCHEDULE_USAGEINFO_QUERY_XTS_0017
304         * @tc.name: DeviceUsageStatisticsJsTest0017
305         * @tc.desc:  bundleState isIdleState callback.
306         */
307        it("DeviceUsageStatisticsJsTest0017", 0, async function (done) {
308            console.info('----------------------DeviceUsageStatisticsJsTest0017---------------------------');
309            bundleState.isIdleState(undefined, (err, res) => {
310                if (err) {
311                    console.info(' bundle DeviceUsageStatisticsJsTest0017 callback fail, result= ' + err.code);
312                    expect(err.code).assertLarger(0);
313                    done();
314                } else {
315                    console.info(' bundle DeviceUsageStatisticsJsTest0017 callback success, result= ' + res);
316                }
317            });
318        })
319
320        /*
321         * @tc.number:SUB_RESOURCESCHEDULE_USAGEINFO_QUERY_XTS_0018
322         * @tc.name: DeviceUsageStatisticsJsTest0018
323         * @tc.desc:  bundleState isIdleState callback.
324         */
325        it("DeviceUsageStatisticsJsTest0018", 0, async function (done) {
326            console.info('----------------------DeviceUsageStatisticsJsTest0018---------------------------');
327            bundleState.isIdleState(null, (err, res) => {
328                if (err) {
329                    console.info(' bundle DeviceUsageStatisticsJsTest0018 callback fail, result= ' + err.code);
330                    expect(err.code).assertLarger(0);
331                    done();
332                } else {
333                    console.info(' bundle DeviceUsageStatisticsJsTest0018 callback success, result= ' + res);
334                }
335            });
336        })
337
338        /*
339         * @tc.number:SUB_RESOURCESCHEDULE_USAGEINFO_QUERY_XTS_0019
340         * @tc.name: DeviceUsageStatisticsJsTest0019
341         * @tc.desc:  queryCurrentBundleActiveStates BundleActiveState bundleName.
342         */
343        it("DeviceUsageStatisticsJsTest0019", 0, async function (done) {
344            console.info('----------------------DeviceUsageStatisticsJsTest0019---------------------------');
345            let beginTime = 10;
346            let endTime = 20000000000000;
347            bundleState.queryCurrentBundleActiveStates(beginTime, endTime, (err, res) => {
348                if (err) {
349                    console.info(' DeviceUsageStatisticsJsTest0019 err.code: ' + err.code);
350                } else {
351                    if (res === undefined) {
352                        res = [{ bundleName: 'www.baidu.com' }];
353                        console.info(' DeviceUsageStatisticsJsTest0019 BundleActiveState bundleName: ' +
354                            res[0].bundleName);
355                    }
356                    console.info(' DeviceUsageStatisticsJsTest0019 res: ' + res, typeof (res));
357                    expect(res).assertInstanceOf('Array');
358                    done();
359                }
360            });
361        })
362
363        /*
364         * @tc.number:SUB_RESOURCESCHEDULE_USAGEINFO_QUERY_XTS_0020
365         * @tc.name: DeviceUsageStatisticsJsTest0020
366         * @tc.desc:  queryCurrentBundleActiveStates BundleActiveState stateType.
367         */
368        it("DeviceUsageStatisticsJsTest0020", 0, async function (done) {
369            console.info('----------------------DeviceUsageStatisticsJsTest0020---------------------------');
370            let beginTime = 10;
371            let endTime = 20000000000000;
372            bundleState.queryCurrentBundleActiveStates(beginTime, endTime, (err, res) => {
373                if (err) {
374                    console.info(' DeviceUsageStatisticsJsTest0020 err.code: ' + err.code);
375                } else {
376                    if (res === undefined) {
377                        res = [{ stateType: 0 }];
378                        console.info(' DeviceUsageStatisticsJsTest0020 BundleActiveState stateType: ' +
379                            res[0].stateType);
380                    }
381                    console.info(' DeviceUsageStatisticsJsTest0020 res: ' + res, typeof (res));
382                    expect(res).assertInstanceOf('Array');
383                    done();
384                }
385            });
386        })
387
388        /*
389         * @tc.number:SUB_RESOURCESCHEDULE_USAGEINFO_QUERY_XTS_0021
390         * @tc.name: DeviceUsageStatisticsJsTest0021
391         * @tc.desc:  queryCurrentBundleActiveStates BundleActiveState stateOccurredTime.
392         */
393        it("DeviceUsageStatisticsJsTest0021", 0, async function (done) {
394            console.info('----------------------DeviceUsageStatisticsJsTest0021---------------------------');
395            let beginTime = 10;
396            let endTime = 20000000000000;
397            bundleState.queryCurrentBundleActiveStates(beginTime, endTime, (err, res) => {
398                if (err) {
399                    console.info(' DeviceUsageStatisticsJsTest0021 err.code: ' + err.code);
400                } else {
401                    if (res === undefined) {
402                        res = [{ stateOccurredTime: 0 }];
403                        console.info(' DeviceUsageStatisticsJsTest0021 BundleActiveState stateOccurredTime: ' +
404                            res[0].stateOccurredTime);
405                    }
406                    console.info(' DeviceUsageStatisticsJsTest0021 res: ' + res, typeof (res));
407                    expect(res).assertInstanceOf('Array');
408                    done();
409                }
410            });
411        })
412
413        /*
414         * @tc.number:SUB_RESOURCESCHEDULE_USAGEINFO_QUERY_XTS_0022
415         * @tc.name: DeviceUsageStatisticsJsTest0022
416         * @tc.desc:  queryCurrentBundleActiveStates BundleActiveState appUsagePriorityGroup.
417         */
418        it("DeviceUsageStatisticsJsTest0022", 0, async function (done) {
419            console.info('----------------------DeviceUsageStatisticsJsTest0022---------------------------');
420            let beginTime = 10;
421            let endTime = 20000000000000;
422            bundleState.queryCurrentBundleActiveStates(beginTime, endTime, (err, res) => {
423                if (err) {
424                    console.info(' DeviceUsageStatisticsJsTest0022 err.code: ' + err.code);
425                } else {
426                    if (res === undefined) {
427                        res = [{ appUsagePriorityGroup: 0 }];
428                        console.info(' DeviceUsageStatisticsJsTest0022 BundleActiveState appUsagePriorityGroup: ' +
429                            res[0].appUsagePriorityGroup);
430                    }
431                    console.info(' DeviceUsageStatisticsJsTest0022 res: ' + res, typeof (res));
432                    expect(res).assertInstanceOf('Array');
433                    done();
434                }
435            });
436        })
437
438        /*
439         * @tc.number:SUB_RESOURCESCHEDULE_USAGEINFO_QUERY_XTS_0023
440         * @tc.name: DeviceUsageStatisticsJsTest0023
441         * @tc.desc:  queryCurrentBundleActiveStates BundleActiveState indexOfLink.
442         */
443        it("DeviceUsageStatisticsJsTest0023", 0, async function (done) {
444            console.info('----------------------DeviceUsageStatisticsJsTest0023---------------------------');
445            let beginTime = 10;
446            let endTime = 20000000000000;
447            bundleState.queryCurrentBundleActiveStates(beginTime, endTime, (err, res) => {
448                if (err) {
449                    console.info(' DeviceUsageStatisticsJsTest0023 err.code: ' + err.code);
450                } else {
451                    if (res === undefined) {
452                        res = [{ indexOfLink: 'id' }];
453                        console.info(' DeviceUsageStatisticsJsTest0023 BundleActiveState indexOfLink: ' +
454                            res[0].indexOfLink);
455                    }
456                    console.info(' DeviceUsageStatisticsJsTest0023 res: ' + res, typeof (res));
457                    expect(res).assertInstanceOf('Array');
458                    done();
459                }
460            });
461        })
462
463        /*
464         * @tc.number:SUB_RESOURCESCHEDULE_USAGEINFO_QUERY_XTS_0024
465         * @tc.name: DeviceUsageStatisticsJsTest0024
466         * @tc.desc:  queryCurrentBundleActiveStates BundleActiveState nameOfClass.
467         */
468        it("DeviceUsageStatisticsJsTest0024", 0, async function (done) {
469            console.info('----------------------DeviceUsageStatisticsJsTest0024---------------------------');
470            let beginTime = 10;
471            let endTime = 20000000000000;
472            bundleState.queryCurrentBundleActiveStates(beginTime, endTime, (err, res) => {
473                if (err) {
474                    console.info(' DeviceUsageStatisticsJsTest0024 err.code: ' + err.code);
475                } else {
476                    if (res === undefined) {
477                        res = [{ nameOfClass: 'BundleStates' }];
478                        console.info(' DeviceUsageStatisticsJsTest0024 BundleActiveState nameOfClass: ' +
479                            res[0].nameOfClass);
480                    }
481                    console.info(' DeviceUsageStatisticsJsTest0024 res: ' + res, typeof (res));
482                    expect(res).assertInstanceOf('Array');
483                    done();
484                }
485            });
486        })
487    })
488}