• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/**
2 * Copyright (c) 2024-2024 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 { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect, MockKit } from '@ohos/hypium'
17import abilityDelegatorRegistry from '@ohos.app.ability.abilityDelegatorRegistry';
18import HiSysEventConstant from '../../../../main/ets/common/constants/HiSysEventConstant';
19import getSelfBundleInfoUtils from '../../../../main/ets/common/utils/GetSelfBundleInfoUtils';
20import HiSysEventUtil from '../../../../main/ets/common/utils/HiSysEventUtil';
21import { RawFileUtil } from '../../../../main/ets/common/utils/RawFileUtil';
22import ResourceUtil from '../../../../main/ets/common/utils/ResourceUtil';
23import { StringUtil } from '../../../../main/ets/common/utils/StringUtil';
24import Logger from '../../../../main/ets/common/utils/Logger';
25
26export default function BundleInfoBeanTest() {
27  describe('CommonTest', () => {
28    // Defines a test suite. Two parameters are supported: test suite name and test suite function.
29    beforeAll(() => {
30      // Presets an action, which is performed only once before all test cases of the test suite start.
31      // This API supports only one parameter: preset action function.
32    })
33    beforeEach(() => {
34      // Presets an action, which is performed before each unit test case starts.
35      // The number of execution times is the same as the number of test cases defined by **it**.
36      // This API supports only one parameter: preset action function.
37    })
38    afterEach(() => {
39      // Presets a clear action, which is performed after each unit test case ends.
40      // The number of execution times is the same as the number of test cases defined by **it**.
41      // This API supports only one parameter: clear action function.
42    })
43    afterAll(() => {
44      // Presets a clear action, which is performed after all test cases of the test suite end.
45      // This API supports only one parameter: clear action function.
46    })
47    it('getSelfBundleInfoUtilsTest', 0, () => {
48      getSelfBundleInfoUtils.getVersionName()
49    })
50    it('HiSysEventUtilTest', 0, async () => {
51      await HiSysEventUtil.reportAccessClick('com.example.test');
52      await HiSysEventUtil.reportLocationClick('LOCATION');
53      await HiSysEventUtil.reportLocationFlagClick(1);
54      await HiSysEventUtil.reportLocationFlagClick(0);
55      let eventParams: Record<string, string> = {
56        "PERMISSION_GROUP": 'ohos.permission.Location'
57      };
58      expect(eventParams).not().assertNull();
59      await HiSysEventUtil.reportClick(HiSysEventConstant.PERMISSION_PAGE_LOCATION_EVENT_NAME, eventParams);
60    })
61    it('RawfileUtilTest', 0, async () => {
62      let fileStr: string = await RawFileUtil.getStringByFile(abilityDelegatorRegistry.getAbilityDelegator()
63        .getAppContext().resourceManager, 'emptyTestFileName');
64      expect(fileStr).assertEqual('');
65      let rawFile = await RawFileUtil.getRawFileByContext(getContext(), 'emptyTestFileName');
66      expect(rawFile).assertEqual('');
67    })
68    it('ResourceUtilTest', 0, () => {
69      ResourceUtil.getResourceString(abilityDelegatorRegistry.getAbilityDelegator()
70        .getAppContext(), $r('app.media.ic_back'));
71      ResourceUtil.getBundleResourceManager('', abilityDelegatorRegistry.getAbilityDelegator().getAppContext());
72      expect(ResourceUtil.getBundleResourceManager('', null)).assertNull();
73      ResourceUtil.getBundleResourceManager('com.ohos.security.privacycenter',
74        abilityDelegatorRegistry.getAbilityDelegator().getAppContext());
75    })
76    it('StringUtilTest', 0, () => {
77      let flag: boolean = StringUtil.isEmpty('');
78      expect(flag).assertEqual(true);
79      flag = StringUtil.isEmpty('111');
80      expect(flag).assertEqual(false);
81      flag = StringUtil.isNotEmpty('');
82      expect(flag).assertEqual(false);
83      flag = StringUtil.isNotEmpty('111');
84      expect(flag).assertEqual(true);
85    })
86    it('LoggerTest', 0, () => {
87      Logger.info('LOGGER_TEST', 'logger test begin');
88      let mocker: MockKit = new MockKit();
89      mocker.mockFunc(Logger, Logger.info);
90      Logger.info('LOGGER_TEST', 'logger info test');
91      mocker.verify('info', ['LOGGER_TEST', 'logger info test']).once();
92      mocker.mockFunc(Logger, Logger.debug);
93      Logger.debug('LOGGER_TEST', 'logger debug test');
94      mocker.verify('debug', ['LOGGER_TEST', 'logger debug test']).once();
95      mocker.mockFunc(Logger, Logger.warn);
96      Logger.warn('LOGGER_TEST', 'logger warn test');
97      mocker.verify('warn', ['LOGGER_TEST', 'logger warn test']).once();
98      mocker.mockFunc(Logger, Logger.error);
99      Logger.error('LOGGER_TEST', 'logger error test');
100      mocker.verify('error', ['LOGGER_TEST', 'logger error test']).once();
101    })
102
103  })
104}