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