From d9df74b57fb130a95c21b9b97fc73b66bc172b19 Mon Sep 17 00:00:00 2001 From: fanchenxuan Date: Wed, 23 Oct 2024 16:22:13 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9EDT=E7=94=A8=E4=BE=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: fanchenxuan --- .gitignore | 3 +- entry/src/ohosTest/ets/test/Ability.test.ets | 50 +++++++++++++++++++ entry/src/ohosTest/ets/test/List.test.ets | 22 ++++++++ entry/src/ohosTest/ets/test/index.test.ets | 31 ++++++++++++ entry/src/ohosTest/module.json5 | 26 ++++++++++ hvigor/hvigor-config.json5 | 2 + oh-package-lock.json5 | 11 +++- oh-package.json5 | 1 + permissionmanager/.gitignore | 3 +- permissionmanager/src/main/module.json | 4 +- permissionmanager/src/main/module.json5 | 4 +- .../src/ohosTest/ets/test/Ability.test.ets | 50 +++++++++++++++++++ .../src/ohosTest/ets/test/List.test.ets | 22 ++++++++ .../src/ohosTest/ets/test/utils.test.ets | 47 +++++++++++++++++ permissionmanager/src/ohosTest/module.json5 | 26 ++++++++++ 15 files changed, 296 insertions(+), 6 deletions(-) create mode 100644 entry/src/ohosTest/ets/test/Ability.test.ets create mode 100644 entry/src/ohosTest/ets/test/List.test.ets create mode 100644 entry/src/ohosTest/ets/test/index.test.ets create mode 100644 entry/src/ohosTest/module.json5 create mode 100644 permissionmanager/src/ohosTest/ets/test/Ability.test.ets create mode 100644 permissionmanager/src/ohosTest/ets/test/List.test.ets create mode 100644 permissionmanager/src/ohosTest/ets/test/utils.test.ets create mode 100644 permissionmanager/src/ohosTest/module.json5 diff --git a/.gitignore b/.gitignore index 8ebb4d4..eba8eeb 100644 --- a/.gitignore +++ b/.gitignore @@ -4,4 +4,5 @@ **/build /.hvigor /oh_modules -/dependencies \ No newline at end of file +/dependencies +.clang-format \ No newline at end of file diff --git a/entry/src/ohosTest/ets/test/Ability.test.ets b/entry/src/ohosTest/ets/test/Ability.test.ets new file mode 100644 index 0000000..a8ff110 --- /dev/null +++ b/entry/src/ohosTest/ets/test/Ability.test.ets @@ -0,0 +1,50 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import { hilog } from '@kit.PerformanceAnalysisKit'; +import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from '@ohos/hypium'; + +export default function abilityTest() { + describe('ActsAbilityTest', () => { + // Defines a test suite. Two parameters are supported: test suite name and test suite function. + beforeAll(() => { + // Presets an action, which is performed only once before all test cases of the test suite start. + // This API supports only one parameter: preset action function. + }) + beforeEach(() => { + // Presets an action, which is performed before each unit test case starts. + // The number of execution times is the same as the number of test cases defined by **it**. + // This API supports only one parameter: preset action function. + }) + afterEach(() => { + // Presets a clear action, which is performed after each unit test case ends. + // The number of execution times is the same as the number of test cases defined by **it**. + // This API supports only one parameter: clear action function. + }) + afterAll(() => { + // Presets a clear action, which is performed after all test cases of the test suite end. + // This API supports only one parameter: clear action function. + }) + it('assertContain', 0, () => { + // Defines a test case. This API supports three parameters: test case name, filter parameter, and test case function. + hilog.info(0x0000, 'testTag', '%{public}s', 'it begin'); + let a = 'abc'; + let b = 'b'; + // Defines a variety of assertion methods, which are used to declare expected boolean conditions. + expect(a).assertContain(b); + expect(a).assertEqual(a); + }) + }) +} \ No newline at end of file diff --git a/entry/src/ohosTest/ets/test/List.test.ets b/entry/src/ohosTest/ets/test/List.test.ets new file mode 100644 index 0000000..8a041d1 --- /dev/null +++ b/entry/src/ohosTest/ets/test/List.test.ets @@ -0,0 +1,22 @@ +import indexTest from './index.test' +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import abilityTest from './Ability.test'; + +export default function testsuite() { + abilityTest(); + indexTest() +} \ No newline at end of file diff --git a/entry/src/ohosTest/ets/test/index.test.ets b/entry/src/ohosTest/ets/test/index.test.ets new file mode 100644 index 0000000..024f225 --- /dev/null +++ b/entry/src/ohosTest/ets/test/index.test.ets @@ -0,0 +1,31 @@ +import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from '@ohos/hypium' + +export default function indexTest() { + describe('indexTest', () => { + // Defines a test suite. Two parameters are supported: test suite name and test suite function. + beforeAll(() => { + // Presets an action, which is performed only once before all test cases of the test suite start. + // This API supports only one parameter: preset action function. + }) + beforeEach(() => { + // Presets an action, which is performed before each unit test case starts. + // The number of execution times is the same as the number of test cases defined by **it**. + // This API supports only one parameter: preset action function. + }) + afterEach(() => { + // Presets a clear action, which is performed after each unit test case ends. + // The number of execution times is the same as the number of test cases defined by **it**. + // This API supports only one parameter: clear action function. + }) + afterAll(() => { + // Presets a clear action, which is performed after all test cases of the test suite end. + // This API supports only one parameter: clear action function. + }) + it('assertEqual', 0, () => { + // Defines a test case. This API supports three parameters: test case name, filter parameter, and test case function. + let a = 'test' + // Defines a variety of assertion methods, which are used to declare expected boolean conditions. + expect(a).assertEqual('test') + }) + }) +} \ No newline at end of file diff --git a/entry/src/ohosTest/module.json5 b/entry/src/ohosTest/module.json5 new file mode 100644 index 0000000..944ed99 --- /dev/null +++ b/entry/src/ohosTest/module.json5 @@ -0,0 +1,26 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +{ + "module": { + "name": "entry_test", + "type": "feature", + "deviceTypes": [ + "default", + "tablet" + ], + "deliveryWithInstall": true, + "installationFree": false + } +} diff --git a/hvigor/hvigor-config.json5 b/hvigor/hvigor-config.json5 index 4cbdf16..8610f2b 100644 --- a/hvigor/hvigor-config.json5 +++ b/hvigor/hvigor-config.json5 @@ -15,7 +15,9 @@ { "hvigorVersion": "3.0.2", +// "modelVersion": "5.0.0", //本地IDE配置 "dependencies": { "@ohos/hvigor-ohos-plugin": "3.0.2" +// "@ohos/hvigor-ohos-plugin": "5.8.5" //本地IDE配置 } } diff --git a/oh-package-lock.json5 b/oh-package-lock.json5 index 17c8ea4..04107a1 100644 --- a/oh-package-lock.json5 +++ b/oh-package-lock.json5 @@ -14,15 +14,22 @@ */ { - "lockfileVersion": 1, + "meta": { + "stableOrder": true + }, + "lockfileVersion": 3, "ATTENTION": "THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.", "specifiers": { "@ohos/hypium@1.0.6": "@ohos/hypium@1.0.6" }, "packages": { "@ohos/hypium@1.0.6": { + "name": "@ohos/hypium", + "version": "1.0.6", + "integrity": "sha512-bb3DWeWhYrFqj9mPFV3yZQpkm36kbcK+YYaeY9g292QKSjOdmhEIQR2ULPvyMsgSR4usOBf5nnYrDmaCCXirgQ==", "resolved": "https://repo.harmonyos.com/ohpm/@ohos/hypium/-/hypium-1.0.6.tgz", - "integrity": "sha512-bb3DWeWhYrFqj9mPFV3yZQpkm36kbcK+YYaeY9g292QKSjOdmhEIQR2ULPvyMsgSR4usOBf5nnYrDmaCCXirgQ==" + "shasum": "3f5fed65372633233264b3447705b0831dfe7ea1", + "registryType": "ohpm" } } } \ No newline at end of file diff --git a/oh-package.json5 b/oh-package.json5 index 756269c..a7fa446 100644 --- a/oh-package.json5 +++ b/oh-package.json5 @@ -14,6 +14,7 @@ */ { + "modelVersion": "5.0.0", "license": "ISC", "devDependencies": { "@ohos/hypium": "1.0.6" diff --git a/permissionmanager/.gitignore b/permissionmanager/.gitignore index 4f9a973..23f4a26 100644 --- a/permissionmanager/.gitignore +++ b/permissionmanager/.gitignore @@ -1,3 +1,4 @@ /node_modules /.preview -/build \ No newline at end of file +/build +/.test \ No newline at end of file diff --git a/permissionmanager/src/main/module.json b/permissionmanager/src/main/module.json index c89e9e7..b7dc81a 100644 --- a/permissionmanager/src/main/module.json +++ b/permissionmanager/src/main/module.json @@ -103,7 +103,9 @@ "name": "ohos.permission.PERMISSION_USED_STATS" }, { - "name": "ohos.permission.GET_INSTALLED_BUNDLE_LIST" + "name": "ohos.permission.GET_INSTALLED_BUNDLE_LIST", + "reason": "$string:allow", + "usedScene": {} }, { "name": "ohos.permission.LISTEN_BUNDLE_CHANGE" diff --git a/permissionmanager/src/main/module.json5 b/permissionmanager/src/main/module.json5 index 6c52a16..7665e0f 100644 --- a/permissionmanager/src/main/module.json5 +++ b/permissionmanager/src/main/module.json5 @@ -115,7 +115,9 @@ "name": "ohos.permission.PERMISSION_USED_STATS" }, { - "name": "ohos.permission.GET_INSTALLED_BUNDLE_LIST" + "name": "ohos.permission.GET_INSTALLED_BUNDLE_LIST", + "reason": "$string:allow", + "usedScene": {} }, { "name": "ohos.permission.LISTEN_BUNDLE_CHANGE" diff --git a/permissionmanager/src/ohosTest/ets/test/Ability.test.ets b/permissionmanager/src/ohosTest/ets/test/Ability.test.ets new file mode 100644 index 0000000..a8ff110 --- /dev/null +++ b/permissionmanager/src/ohosTest/ets/test/Ability.test.ets @@ -0,0 +1,50 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import { hilog } from '@kit.PerformanceAnalysisKit'; +import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from '@ohos/hypium'; + +export default function abilityTest() { + describe('ActsAbilityTest', () => { + // Defines a test suite. Two parameters are supported: test suite name and test suite function. + beforeAll(() => { + // Presets an action, which is performed only once before all test cases of the test suite start. + // This API supports only one parameter: preset action function. + }) + beforeEach(() => { + // Presets an action, which is performed before each unit test case starts. + // The number of execution times is the same as the number of test cases defined by **it**. + // This API supports only one parameter: preset action function. + }) + afterEach(() => { + // Presets a clear action, which is performed after each unit test case ends. + // The number of execution times is the same as the number of test cases defined by **it**. + // This API supports only one parameter: clear action function. + }) + afterAll(() => { + // Presets a clear action, which is performed after all test cases of the test suite end. + // This API supports only one parameter: clear action function. + }) + it('assertContain', 0, () => { + // Defines a test case. This API supports three parameters: test case name, filter parameter, and test case function. + hilog.info(0x0000, 'testTag', '%{public}s', 'it begin'); + let a = 'abc'; + let b = 'b'; + // Defines a variety of assertion methods, which are used to declare expected boolean conditions. + expect(a).assertContain(b); + expect(a).assertEqual(a); + }) + }) +} \ No newline at end of file diff --git a/permissionmanager/src/ohosTest/ets/test/List.test.ets b/permissionmanager/src/ohosTest/ets/test/List.test.ets new file mode 100644 index 0000000..a98c00c --- /dev/null +++ b/permissionmanager/src/ohosTest/ets/test/List.test.ets @@ -0,0 +1,22 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import utilsTest from './utils.test'; +import abilityTest from './Ability.test'; + +export default function testsuite() { + abilityTest(); + utilsTest(); +} \ No newline at end of file diff --git a/permissionmanager/src/ohosTest/ets/test/utils.test.ets b/permissionmanager/src/ohosTest/ets/test/utils.test.ets new file mode 100644 index 0000000..4efc9ac --- /dev/null +++ b/permissionmanager/src/ohosTest/ets/test/utils.test.ets @@ -0,0 +1,47 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect, TestType } from '@ohos/hypium'; +import { Log, getGroupIdByPermission } from '../../../main/ets/common/utils/utils'; + +export default function utilsTest() { + describe('utilsTest', () => { + // Defines a test suite. Two parameters are supported: test suite name and test suite function. + beforeAll(() => { + // Presets an action, which is performed only once before all test cases of the test suite start. + // This API supports only one parameter: preset action function. + }) + beforeEach(() => { + // Presets an action, which is performed before each unit test case starts. + // The number of execution times is the same as the number of test cases defined by **it**. + // This API supports only one parameter: preset action function. + }) + afterEach(() => { + // Presets a clear action, which is performed after each unit test case ends. + // The number of execution times is the same as the number of test cases defined by **it**. + // This API supports only one parameter: clear action function. + }) + afterAll(() => { + // Presets a clear action, which is performed after all test cases of the test suite end. + // This API supports only one parameter: clear action function. + }) + it('UtilsTest_000', TestType.FUNCTION, () => { + Log.info(`UtilsTest_000 begin`); + let testUri = 'ohos.permission.MICROPHONE'; + let groupId = getGroupIdByPermission(testUri); + expect(groupId).assertEqual(2); + }) + }) +} \ No newline at end of file diff --git a/permissionmanager/src/ohosTest/module.json5 b/permissionmanager/src/ohosTest/module.json5 new file mode 100644 index 0000000..2c2b488 --- /dev/null +++ b/permissionmanager/src/ohosTest/module.json5 @@ -0,0 +1,26 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +{ + "module": { + "name": "permissionmanager_test", + "type": "feature", + "deviceTypes": [ + "default", + "tablet" + ], + "deliveryWithInstall": true, + "installationFree": false + } +} -- Gitee