1/*
2 * Copyright (c) 2023 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 userAuth from '@ohos.userIAM.userAuth';
17import { beforeAll, describe, expect, it } from '@ohos/hypium';
18import AuthUtils from '../../../../main/ets/common/utils/AuthUtils';
19import FuncUtils from '../../../../main/ets/common/utils/FuncUtils';
20import LogUtils from '../../../../main/ets/common/utils/LogUtils';
21import TimeUtils from '../../../../main/ets/common/utils/TimeUtils';
22import WindowPrivacyUtils from '../../../../main/ets/common/utils/WindowPrivacyUtils';
23import common from '@ohos.app.ability.common';
24
25const TAG = 'FuncUtilsTest';
26
27export default function FuncUtilsTest() {
28  describe('FuncUtilsTest', () => {
29    beforeAll(async () => {
30      const authParam : userAuth.AuthParam = {
31        challenge: new Uint8Array([49, 49, 49, 49, 49, 49]),
32        authType: [1],
33        authTrustLevel: 10000,
34      };
35      const widgetParam : userAuth.WidgetParam = {
36        title: '',
37        windowMode: 1,
38        navigationButtonText: '',
39      };
40      let userAuthInstance = await userAuth.getUserAuthInstance(authParam, widgetParam);
41      if (userAuthInstance === null) {
42        LogUtils.error(TAG, 'userAuthInstance is null');
43        return;
44      }
45      userAuthInstance.on('result', {
46        onResult (result) {
47          LogUtils.info(TAG, 'userAuthInstance callback result = ' + JSON.stringify(result));
48        }
49      });
50      userAuthInstance.start();
51    })
52
53    it('getUint8PWFunc_test', 0, (done: Function) => {
54      const data1 = FuncUtils.getUint8PW('111111');
55      const data2 = FuncUtils.getUint8PW('11111111');
56      FuncUtils.getWindowHeight();
57      expect(data1).assertInstanceOf('Uint8Array');
58      expect(data2).assertInstanceOf('Uint8Array');
59      done();
60    })
61
62    it('getDialogTypeFunc_test', 0, (done: Function) => {
63      const data1 = FuncUtils.getDialogType([1]);
64      const data2 = FuncUtils.getDialogType([1, 2, 4]);
65      const data3 = FuncUtils.getDialogType([]);
66      const data6 = FuncUtils.getDialogType([1, 2]);
67      const data7 = FuncUtils.getDialogType([1, 4]);
68      const data8 = FuncUtils.getDialogType([2]);
69      const data9 = FuncUtils.getDialogType([4]);
70      expect(data1).assertEqual(1);
71      expect(data2).assertEqual(10);
72      expect(data3).assertEqual(1);
73      expect(data6).assertEqual(6);
74      expect(data7).assertEqual(7);
75      expect(data8).assertEqual(2);
76      expect(data9).assertEqual(3);
77      done();
78    })
79
80    it('getWindowHeightFunc_test', 0, (done: Function) => {
81      FuncUtils.getWindowHeight();
82      done();
83    })
84
85    it('judgmentOverflowFunc_test', 0, function (done) {
86      FuncUtils.judgmentOverflow(Number.POSITIVE_INFINITY);
87      FuncUtils.judgmentOverflow(Number.NEGATIVE_INFINITY);
88      done();
89    })
90
91    it('sendNoticeFunc_test', 0, async function (done) {
92      AuthUtils.getInstance().sendNotice('EVENT_AUTH_TYPE_READY', ['pin']);
93      AuthUtils.getInstance().sendNotice('EVENT_AUTH_TYPE_START', ['pin']);
94      done();
95    })
96
97    it('logFunc_test', 0, async (done: Function) => {
98      LogUtils.debug(TAG, 'debug log test');
99      LogUtils.info(TAG, 'info log test');
100      LogUtils.warn(TAG, 'warning log test');
101      LogUtils.error(TAG, 'error log test');
102      LogUtils.fatal(TAG, 'fatal log test');
103      done();
104    })
105
106    it('getFreezingTimeNmFunc_test', 0, async function (done) {
107      TimeUtils.getFreezingTimeNm(10000, globalThis.context);
108      TimeUtils.getFreezingTimeNm(100000, globalThis.context);
109      done();
110    })
111
112    it('setWindowPrivacyModeFunc_test', 0, async (done: Function) => {
113      WindowPrivacyUtils.setWindowPrivacyMode(null, false);
114      done();
115    })
116  })
117}