diff --git a/distributeddatamgr/BUILD.gn b/distributeddatamgr/BUILD.gn index d21bd66eaa67f263b6d620e59a6d0af4ecf38153..5fd17ee49bfcb755ad70a606eb12d05a36516d89 100644 --- a/distributeddatamgr/BUILD.gn +++ b/distributeddatamgr/BUILD.gn @@ -25,6 +25,8 @@ group("distributeddatamgr") { "kvStoretest:kvStoretest", "preferencesjstest/hap:preferences_js_test", "relationalStoretest:relationalStoretest", + "relationalstoredatagroupidtest:ActsRelationalstoreDataGroupIdTest", + "preferencesdatagroupidtest:ActsPreferencesDataGroupIdTest", ] } else { deps = [ diff --git a/distributeddatamgr/preferencesdatagroupidtest/AppScope/app.json b/distributeddatamgr/preferencesdatagroupidtest/AppScope/app.json new file mode 100644 index 0000000000000000000000000000000000000000..74ce7515f453ee62a927c4a7f7cc17968099d580 --- /dev/null +++ b/distributeddatamgr/preferencesdatagroupidtest/AppScope/app.json @@ -0,0 +1,16 @@ +{ + "app": { + "bundleName": "ohos.acts.preferencesdatagroupidtest", + "vendor": "example", + "versionCode": 1000000, + "versionName": "1.0.0", + "icon": "$media:app_icon", + "label": "$string:app_name", + "minAPIVersion": 10, + "targetAPIVersion": 10, + "car": { + "apiCompatibleVersion": 10, + "singleUser": false + } + } +} diff --git a/distributeddatamgr/preferencesdatagroupidtest/AppScope/resources/base/element/string.json b/distributeddatamgr/preferencesdatagroupidtest/AppScope/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..3811bc441fc0f128eb4d14c53ed463ffb8dc3811 --- /dev/null +++ b/distributeddatamgr/preferencesdatagroupidtest/AppScope/resources/base/element/string.json @@ -0,0 +1,8 @@ +{ + "string": [ + { + "name": "app_name", + "value": "xtsDemo1" + } + ] +} diff --git a/distributeddatamgr/preferencesdatagroupidtest/AppScope/resources/base/media/app_icon.png b/distributeddatamgr/preferencesdatagroupidtest/AppScope/resources/base/media/app_icon.png new file mode 100644 index 0000000000000000000000000000000000000000..ce307a8827bd75456441ceb57d530e4c8d45d36c Binary files /dev/null and b/distributeddatamgr/preferencesdatagroupidtest/AppScope/resources/base/media/app_icon.png differ diff --git a/distributeddatamgr/preferencesdatagroupidtest/BUILD.gn b/distributeddatamgr/preferencesdatagroupidtest/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..29190526f4c432c8c57717ce30c74f42372e5bec --- /dev/null +++ b/distributeddatamgr/preferencesdatagroupidtest/BUILD.gn @@ -0,0 +1,43 @@ +# Copyright (C) 2023 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("//test/xts/tools/build/suite.gni") + +ohos_js_hap_suite("ActsPreferencesDataGroupIdTest") { + hap_profile = "src/main/module.json" + deps = [ + ":preferencesDataGroupId_js_assets", + ":preferencesDataGroupId_resources", + ] + ets2abc = true + certificate_profile = "./signature/openharmony_sx.p7b" + + hap_name = "ActsPreferencesDataGroupIdTest" + subsystem_name = "distributeddatamgr" + part_name = "preferences" +} +ohos_app_scope("preferencesDataGroupId_app_profile") { + app_profile = "AppScope/app.json" + + sources = [ "AppScope/resources" ] +} +ohos_js_assets("preferencesDataGroupId_js_assets") { + source_dir = "src/main/ets" +} +ohos_resources("preferencesDataGroupId_resources") { + sources = [ "src/main/resources" ] + + deps = [ ":preferencesDataGroupId_app_profile" ] + + hap_profile = "src/main/module.json" +} diff --git a/distributeddatamgr/preferencesdatagroupidtest/Test.json b/distributeddatamgr/preferencesdatagroupidtest/Test.json new file mode 100644 index 0000000000000000000000000000000000000000..72b929eda6da78ffd3a6e6ef8231bc1c20f6ea80 --- /dev/null +++ b/distributeddatamgr/preferencesdatagroupidtest/Test.json @@ -0,0 +1,19 @@ +{ + "description": "Configuration for hjunit demo Tests", + "driver": { + "type": "OHJSUnitTest", + "test-timeout": "60000", + "shell-timeout": "60000", + "bundle-name": "ohos.acts.preferencesdatagroupidtest", + "module-name": "preferencesDataGroupId" + }, + "kits": [ + { + "test-file-name": [ + "ActsPreferencesDataGroupIdTest.hap" + ], + "type": "AppInstallKit", + "cleanup-apps": true + } + ] +} \ No newline at end of file diff --git a/distributeddatamgr/preferencesdatagroupidtest/signature/openharmony_sx.p7b b/distributeddatamgr/preferencesdatagroupidtest/signature/openharmony_sx.p7b new file mode 100644 index 0000000000000000000000000000000000000000..539c7fac576cff33b82f0735c3675464a1229ad4 Binary files /dev/null and b/distributeddatamgr/preferencesdatagroupidtest/signature/openharmony_sx.p7b differ diff --git a/distributeddatamgr/preferencesdatagroupidtest/src/main/ets/TestAbility/TestAbility.ets b/distributeddatamgr/preferencesdatagroupidtest/src/main/ets/TestAbility/TestAbility.ets new file mode 100644 index 0000000000000000000000000000000000000000..dac63ae78615c5762d40e44e94c5be2d33a1b546 --- /dev/null +++ b/distributeddatamgr/preferencesdatagroupidtest/src/main/ets/TestAbility/TestAbility.ets @@ -0,0 +1,63 @@ +/* + * Copyright (C) 2023 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 UIAbility from "@ohos.app.ability.UIAbility"; +import AbilityDelegatorRegistry from "@ohos.app.ability.abilityDelegatorRegistry"; +import hilog from "@ohos.hilog"; +import { Hypium } from "@ohos/hypium"; +import testsuite from "../test/List.test"; +import window from "@ohos.window"; + +export default class TestAbility extends UIAbility { + onCreate(want, launchParam) { + hilog.info(0x0000, "testTag", "%{public}s", "TestAbility onCreate"); + hilog.info(0x0000, "testTag", "%{public}s", "want param:" + JSON.stringify(want) ?? ""); + hilog.info(0x0000, "testTag", "%{public}s", "launchParam:" + JSON.stringify(launchParam) ?? ""); + var abilityDelegator: any; + abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator(); + var abilityDelegatorArguments: any; + abilityDelegatorArguments = AbilityDelegatorRegistry.getArguments(); + hilog.info(0x0000, "testTag", "%{public}s", "start run testcase!!!"); + Hypium.hypiumTest(abilityDelegator, abilityDelegatorArguments, testsuite); + } + + onDestroy() { + hilog.info(0x0000, "testTag", "%{public}s", "TestAbility onDestroy"); + } + + onWindowStageCreate(windowStage: window.WindowStage) { + hilog.info(0x0000, "testTag", "%{public}s", "TestAbility onWindowStageCreate"); + globalThis.abilityContext = this.context; + windowStage.loadContent("TestAbility/pages/Index", (err, data) => { + if (err.code) { + hilog.error(0x0000, "testTag", "Failed to load the content. Cause: %{public}s", JSON.stringify(err) ?? ""); + return; + } + hilog.info(0x0000, "testTag", "Succeeded in loading the content. Data: %{public}s", JSON.stringify(data) ?? ""); + }); + } + + onWindowStageDestroy() { + hilog.info(0x0000, "testTag", "%{public}s", "TestAbility onWindowStageDestroy"); + } + + onForeground() { + hilog.info(0x0000, "testTag", "%{public}s", "TestAbility onForeground"); + } + + onBackground() { + hilog.info(0x0000, "testTag", "%{public}s", "TestAbility onBackground"); + } +} diff --git a/distributeddatamgr/preferencesdatagroupidtest/src/main/ets/TestAbility/pages/Index.ets b/distributeddatamgr/preferencesdatagroupidtest/src/main/ets/TestAbility/pages/Index.ets new file mode 100644 index 0000000000000000000000000000000000000000..7063c2427f471eb22dc9ea361188d2bbd6c24c57 --- /dev/null +++ b/distributeddatamgr/preferencesdatagroupidtest/src/main/ets/TestAbility/pages/Index.ets @@ -0,0 +1,49 @@ +/* + * Copyright (C) 2023 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 '@ohos.hilog'; + +@Entry +@Component +struct Index { + aboutToAppear() { + hilog.info(0x0000, 'testTag', '%{public}s', 'TestAbility index aboutToAppear'); + } + @State message: string = 'Hello World' + build() { + Row() { + Column() { + Text(this.message) + .fontSize(50) + .fontWeight(FontWeight.Bold) + Button() { + Text('next page') + .fontSize(20) + .fontWeight(FontWeight.Bold) + }.type(ButtonType.Capsule) + .margin({ + top: 20 + }) + .backgroundColor('#0D9FFB') + .width('35%') + .height('5%') + .onClick(()=>{ + }) + } + .width('100%') + } + .height('100%') + } + } \ No newline at end of file diff --git a/distributeddatamgr/preferencesdatagroupidtest/src/main/ets/TestRunner/OpenHarmonyTestRunner.ts b/distributeddatamgr/preferencesdatagroupidtest/src/main/ets/TestRunner/OpenHarmonyTestRunner.ts new file mode 100644 index 0000000000000000000000000000000000000000..92a16d84e8870da219c51d9f1342c79203c1f42d --- /dev/null +++ b/distributeddatamgr/preferencesdatagroupidtest/src/main/ets/TestRunner/OpenHarmonyTestRunner.ts @@ -0,0 +1,49 @@ +import hilog from '@ohos.hilog'; +import TestRunner from '@ohos.application.testRunner'; +import AbilityDelegatorRegistry from '@ohos.app.ability.abilityDelegatorRegistry'; + +var abilityDelegator = undefined +var abilityDelegatorArguments = undefined + +async function onAbilityCreateCallback() { + hilog.info(0x0000, 'testTag', '%{public}s', 'onAbilityCreateCallback'); +} + +async function addAbilityMonitorCallback(err: any) { + hilog.info(0x0000, 'testTag', 'addAbilityMonitorCallback : %{public}s', JSON.stringify(err) ?? ''); +} + +export default class OpenHarmonyTestRunner implements TestRunner { + constructor() { + } + + onPrepare() { + hilog.info(0x0000, 'testTag', '%{public}s', 'OpenHarmonyTestRunner OnPrepare '); + } + + async onRun() { + hilog.info(0x0000, 'testTag', '%{public}s', 'OpenHarmonyTestRunner onRun run'); + abilityDelegatorArguments = AbilityDelegatorRegistry.getArguments() + abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator() + var testAbilityName = abilityDelegatorArguments.bundleName + '.TestAbility' + let lMonitor = { + abilityName: testAbilityName, + onAbilityCreate: onAbilityCreateCallback, + }; + abilityDelegator.addAbilityMonitor(lMonitor, addAbilityMonitorCallback) + var cmd = 'aa start -d 0 -a TestAbility' + ' -b ' + abilityDelegatorArguments.bundleName + var debug = abilityDelegatorArguments.parameters['-D'] + if (debug == 'true') + { + cmd += ' -D' + } + hilog.info(0x0000, 'testTag', 'cmd : %{public}s', cmd); + abilityDelegator.executeShellCommand(cmd, + (err: any, d: any) => { + hilog.info(0x0000, 'testTag', 'executeShellCommand : err : %{public}s', JSON.stringify(err) ?? ''); + hilog.info(0x0000, 'testTag', 'executeShellCommand : data : %{public}s', d.stdResult ?? ''); + hilog.info(0x0000, 'testTag', 'executeShellCommand : data : %{public}s', d.exitCode ?? ''); + }) + hilog.info(0x0000, 'testTag', '%{public}s', 'OpenHarmonyTestRunner onRun end'); + } +} \ No newline at end of file diff --git a/distributeddatamgr/preferencesdatagroupidtest/src/main/ets/test/List.test.ets b/distributeddatamgr/preferencesdatagroupidtest/src/main/ets/test/List.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..3ef220f15be70c25ea2e7b6d7ad4166e76737d6b --- /dev/null +++ b/distributeddatamgr/preferencesdatagroupidtest/src/main/ets/test/List.test.ets @@ -0,0 +1,22 @@ +/* + * Copyright (c) 2023 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 preferencesDataGroupIdCallback from './preferencesDataGroupIdCallback.test' +import preferencesDataGroupIdPromise from './preferencesDataGroupIdPromise.test' + +export default function testsuite() { + preferencesDataGroupIdCallback() + preferencesDataGroupIdPromise() +} \ No newline at end of file diff --git a/distributeddatamgr/preferencesdatagroupidtest/src/main/ets/test/preferencesDataGroupIdCallback.test.ets b/distributeddatamgr/preferencesdatagroupidtest/src/main/ets/test/preferencesDataGroupIdCallback.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..0d508dadd46ba8546c1697f02bb090aaabb22876 --- /dev/null +++ b/distributeddatamgr/preferencesdatagroupidtest/src/main/ets/test/preferencesDataGroupIdCallback.test.ets @@ -0,0 +1,112 @@ +/* + * Copyright (c) 2023 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 } from '@ohos/hypium' +import dataPreferences from '@ohos.data.preferences'; + +const TAG = "[ttt]" + + +export default function preferencesDataGroupIdCallback() { + describe('preferencesDataGroupIdCallback', function () { + + console.log(TAG + "*************Unit Test Begin*************"); + + /** + * @tc.number SUB_DDM_Preferences_DataGroupId_Callback_0100 + * @tc.name preferences dataGroupId null callback test + * @tc.desc preferences dataGroupId null callback test + */ + it('SUB_DDM_Preferences_DataGroupId_Callback_0100', 0, async function (done) { + const Options = { + name: "test_preferences_callback", + dataGroupId: null, + }; + try { + dataPreferences.getPreferences(globalThis.abilityContext, Options, async function (err) { + console.info(TAG, `getPreferences successfully.`); + expect().assertFail(); + done(); + dataPreferences.deletePreferences(globalThis.abilityContext, Options, function (error) { + console.info(TAG, `deletePreferences successfully.`); + expect().assertFail(); + done(); + }) + }) + } catch (errInfo) { + console.error(TAG, `failed, code is ${errInfo.code},message is ${errInfo.message}`); + expect(errInfo.code).assertEqual('401'); + done(); + } + }) + + /** + * @tc.number SUB_DDM_Preferences_DataGroupId_Callback_0200 + * @tc.name preferences dataGroupId undefined callback test + * @tc.desc preferences dataGroupId undefined callback test + */ + it('SUB_DDM_Preferences_DataGroupId_Callback_0200', 0, async function (done) { + const Options = { + name: "test_preferences_callback", + dataGroupId: undefined, + }; + try { + dataPreferences.getPreferences(globalThis.abilityContext, Options, async function (err) { + console.info(TAG, `getPreferences successfully.`); + expect().assertFail(); + done(); + dataPreferences.deletePreferences(globalThis.abilityContext, Options, function (error) { + console.info(TAG, `deletePreferences successfully.`); + expect().assertFail(); + done(); + }) + }) + } catch (errInfo) { + console.error(TAG, `failed, code is ${errInfo.code},message is ${errInfo.message}`); + expect(errInfo.code).assertEqual('401'); + done(); + } + }) + /** + * @tc.number SUB_DDM_Preferences_DataGroupId_Callback_0300 + * @tc.name preferences dataGroupId callback test + * @tc.desc preferences dataGroupId callback test + */ + it('SUB_DDM_Preferences_DataGroupId_Callback_0300', 0, async function (done) { + const Options = { + name: "test_preferences_callback", + dataGroupId: '112233', + }; + try { + dataPreferences.getPreferences(globalThis.abilityContext, Options, async function (err) { + console.info(TAG, `getPreferences successfully.`); + expect().assertFail(); + done(); + dataPreferences.deletePreferences(globalThis.abilityContext, Options, function (error) { + console.info(TAG, `deletePreferences successfully.`); + expect().assertFail(); + done(); + }) + }) + } catch (errInfo) { + console.error(TAG, `failed, code is ${errInfo.code},message is ${errInfo.message}`); + expect(errInfo.code).assertEqual('14801002'); + done(); + } + }) + + console.log(TAG + "*************Unit Test End*************"); + }) +} \ No newline at end of file diff --git a/distributeddatamgr/preferencesdatagroupidtest/src/main/ets/test/preferencesDataGroupIdPromise.test.ets b/distributeddatamgr/preferencesdatagroupidtest/src/main/ets/test/preferencesDataGroupIdPromise.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..b24afbfa9ded9a2bc30774e8d3d13ae109d092f9 --- /dev/null +++ b/distributeddatamgr/preferencesdatagroupidtest/src/main/ets/test/preferencesDataGroupIdPromise.test.ets @@ -0,0 +1,137 @@ +/* + * Copyright (C) 2022 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 } from '@ohos/hypium' +import dataPreferences from '@ohos.data.preferences'; + +const TAG = "[ttt]" + +export default function preferencesDataGroupIdPromise() { + describe('preferencesDataGroupIdPromise', function () { + + console.log(TAG + "*************Unit Test Begin*************"); + + + /** + * @tc.number SUB_DDM_Preferences_DataGroupId_Promise_0100 + * @tc.name preferences dataGroupId null promise test + * @tc.desc preferences dataGroupId null promise test + */ + it('SUB_DDM_Preferences_DataGroupId_Promise_0100', 0, async function (done) { + const Options = { + name: "test_preferences_callback", + dataGroupId: null, + }; + try{ + dataPreferences.getPreferences(globalThis.abilityContext, Options).then(async (data) => { + console.info(TAG, `getPreferences successfully.`); + expect().assertFail(); + done(); + dataPreferences.deletePreferences(globalThis.abilityContext, Options).then(async (val) => { + console.info(TAG, `deletePreferences successfully.`); + expect().assertFail(); + done(); + }).catch((error) => { + console.error(TAG, `deletePreferences failed, code is ${error.code},message is ${error.message}`); + expect(error !== null).assertFail(); + done(); + }) + }).catch((err) => { + console.error(TAG, `getPreferences failed, code is ${err.code},message is ${err.message}`); + expect(err !== null).assertFail(); + done(); + }) + }catch(errInfo){ + console.error(TAG, `failed, code is ${errInfo.code},message is ${errInfo.message}`); + expect(errInfo.code).assertEqual('401'); + done(); + } + }) + + /** + * @tc.number SUB_DDM_Preferences_DataGroupId_Promise_0200 + * @tc.name preferences dataGroupId undefined promise test + * @tc.desc preferences dataGroupId undefined promise test + */ + it('SUB_DDM_Preferences_DataGroupId_Promise_0200', 0, async function (done) { + const Options = { + name: "test_preferences_callback", + dataGroupId: undefined, + }; + try{ + dataPreferences.getPreferences(globalThis.abilityContext, Options).then(async (data) => { + console.info(TAG, `getPreferences successfully.`); + expect().assertFail(); + done(); + dataPreferences.deletePreferences(globalThis.abilityContext, Options).then(async (val) => { + console.info(TAG, `deletePreferences successfully.`); + expect().assertFail(); + done(); + }).catch((error) => { + console.error(TAG, `deletePreferences failed, code is ${error.code},message is ${error.message}`); + expect(error !== null).assertFail(); + done(); + }) + }).catch((err) => { + console.error(TAG, `getPreferences failed, code is ${err.code},message is ${err.message}`); + expect(err !== null).assertFail(); + done(); + }) + }catch(errInfo){ + console.error(TAG, `failed, code is ${errInfo.code},message is ${errInfo.message}`); + expect(errInfo.code).assertEqual('401'); + done(); + } + }) + + /** + * @tc.number SUB_DDM_Preferences_DataGroupId_Promise_0300 + * @tc.name preferences dataGroupId promise test + * @tc.desc preferences dataGroupId promise test + */ + it('SUB_DDM_Preferences_DataGroupId_Promise_0300', 0, async function (done) { + const Options = { + name: "test_preferences_callback", + dataGroupId: '112233', + }; + try{ + dataPreferences.getPreferences(globalThis.abilityContext, Options).then(async (data) => { + console.info(TAG, `getPreferences successfully.`); + expect().assertFail(); + done(); + dataPreferences.deletePreferences(globalThis.abilityContext, Options).then(async (val) => { + console.info(TAG, `deletePreferences successfully.`); + expect().assertFail(); + done(); + }).catch((error) => { + console.error(TAG, `deletePreferences failed, code is ${error.code},message is ${error.message}`); + expect(error !== null).assertFail(); + done(); + }) + }).catch((err) => { + console.error(TAG, `getPreferences failed, code is ${err.code},message is ${err.message}`); + expect(err !== null).assertFail(); + done(); + }) + }catch(errInfo){ + console.error(TAG, `failed, code is ${errInfo.code},message is ${errInfo.message}`); + expect(errInfo.code).assertEqual('14801002'); + done(); + } + }) + + console.log(TAG + "*************Unit Test End*************"); + }) +} \ No newline at end of file diff --git a/distributeddatamgr/preferencesdatagroupidtest/src/main/module.json b/distributeddatamgr/preferencesdatagroupidtest/src/main/module.json new file mode 100644 index 0000000000000000000000000000000000000000..9781a30a69aa969c19010da8fa32ff68e3d26d37 --- /dev/null +++ b/distributeddatamgr/preferencesdatagroupidtest/src/main/module.json @@ -0,0 +1,39 @@ +{ + "module": { + "name": "preferencesDataGroupId", + "type": "feature", + "description": "$string:module_test_desc", + "mainElement": "TestAbility", + "deviceTypes": [ + "default", + "tablet", + "phone", + "2in1" + ], + "deliveryWithInstall": true, + "installationFree": false, + "pages": "$profile:test_pages", + "abilities": [ + { + "name": "TestAbility", + "srcEntry": "./ets/TestAbility/TestAbility.ets", + "description": "$string:TestAbility_desc", + "icon": "$media:icon", + "label": "$string:TestAbility_label", + "exported": true, + "startWindowIcon": "$media:icon", + "startWindowBackground": "$color:start_window_background", + "skills": [ + { + "actions": [ + "action.system.home" + ], + "entities": [ + "entity.system.home" + ] + } + ] + } + ] + } +} diff --git a/distributeddatamgr/preferencesdatagroupidtest/src/main/resources/base/element/color.json b/distributeddatamgr/preferencesdatagroupidtest/src/main/resources/base/element/color.json new file mode 100644 index 0000000000000000000000000000000000000000..3c712962da3c2751c2b9ddb53559afcbd2b54a02 --- /dev/null +++ b/distributeddatamgr/preferencesdatagroupidtest/src/main/resources/base/element/color.json @@ -0,0 +1,8 @@ +{ + "color": [ + { + "name": "start_window_background", + "value": "#FFFFFF" + } + ] +} \ No newline at end of file diff --git a/distributeddatamgr/preferencesdatagroupidtest/src/main/resources/base/element/string.json b/distributeddatamgr/preferencesdatagroupidtest/src/main/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..65d8fa5a7cf54aa3943dcd0214f58d1771bc1f6c --- /dev/null +++ b/distributeddatamgr/preferencesdatagroupidtest/src/main/resources/base/element/string.json @@ -0,0 +1,16 @@ +{ + "string": [ + { + "name": "module_test_desc", + "value": "test ability description" + }, + { + "name": "TestAbility_desc", + "value": "the test ability" + }, + { + "name": "TestAbility_label", + "value": "test label" + } + ] +} \ No newline at end of file diff --git a/distributeddatamgr/preferencesdatagroupidtest/src/main/resources/base/media/icon.png b/distributeddatamgr/preferencesdatagroupidtest/src/main/resources/base/media/icon.png new file mode 100644 index 0000000000000000000000000000000000000000..ce307a8827bd75456441ceb57d530e4c8d45d36c Binary files /dev/null and b/distributeddatamgr/preferencesdatagroupidtest/src/main/resources/base/media/icon.png differ diff --git a/distributeddatamgr/preferencesdatagroupidtest/src/main/resources/base/profile/test_pages.json b/distributeddatamgr/preferencesdatagroupidtest/src/main/resources/base/profile/test_pages.json new file mode 100644 index 0000000000000000000000000000000000000000..77e90731b5a38d861663029b483df3d3ac9ec74b --- /dev/null +++ b/distributeddatamgr/preferencesdatagroupidtest/src/main/resources/base/profile/test_pages.json @@ -0,0 +1,5 @@ +{ + "src": [ + "TestAbility/pages/Index" + ] +} diff --git a/distributeddatamgr/relationalstoredatagroupidtest/AppScope/app.json b/distributeddatamgr/relationalstoredatagroupidtest/AppScope/app.json new file mode 100644 index 0000000000000000000000000000000000000000..4b321db661f16f9aa49a5d8d08d8c8858a0659cb --- /dev/null +++ b/distributeddatamgr/relationalstoredatagroupidtest/AppScope/app.json @@ -0,0 +1,16 @@ +{ + "app": { + "bundleName": "ohos.acts.relationalstoredatagroupidtest", + "vendor": "example", + "versionCode": 1000000, + "versionName": "1.0.0", + "icon": "$media:app_icon", + "label": "$string:app_name", + "minAPIVersion": 10, + "targetAPIVersion": 10, + "car": { + "apiCompatibleVersion": 10, + "singleUser": false + } + } +} diff --git a/distributeddatamgr/relationalstoredatagroupidtest/AppScope/resources/base/element/string.json b/distributeddatamgr/relationalstoredatagroupidtest/AppScope/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..3811bc441fc0f128eb4d14c53ed463ffb8dc3811 --- /dev/null +++ b/distributeddatamgr/relationalstoredatagroupidtest/AppScope/resources/base/element/string.json @@ -0,0 +1,8 @@ +{ + "string": [ + { + "name": "app_name", + "value": "xtsDemo1" + } + ] +} diff --git a/distributeddatamgr/relationalstoredatagroupidtest/AppScope/resources/base/media/app_icon.png b/distributeddatamgr/relationalstoredatagroupidtest/AppScope/resources/base/media/app_icon.png new file mode 100644 index 0000000000000000000000000000000000000000..ce307a8827bd75456441ceb57d530e4c8d45d36c Binary files /dev/null and b/distributeddatamgr/relationalstoredatagroupidtest/AppScope/resources/base/media/app_icon.png differ diff --git a/distributeddatamgr/relationalstoredatagroupidtest/BUILD.gn b/distributeddatamgr/relationalstoredatagroupidtest/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..1b83088d8aedb5260edf64a15ba92afeeedc3ab0 --- /dev/null +++ b/distributeddatamgr/relationalstoredatagroupidtest/BUILD.gn @@ -0,0 +1,43 @@ +# Copyright (C) 2023 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("//test/xts/tools/build/suite.gni") + +ohos_js_hap_suite("ActsRelationalstoreDataGroupIdTest") { + hap_profile = "src/main/module.json" + deps = [ + ":relationalstoreDataGroupId_js_assets", + ":relationalstoreDataGroupId_resources", + ] + ets2abc = true + certificate_profile = "./signature/openharmony_sx.p7b" + + hap_name = "ActsRelationalstoreDataGroupIdTest" + subsystem_name = "distributeddatamgr" + part_name = "relational_store" +} +ohos_app_scope("relationalstoreDataGroupId_app_profile") { + app_profile = "AppScope/app.json" + + sources = [ "AppScope/resources" ] +} +ohos_js_assets("relationalstoreDataGroupId_js_assets") { + source_dir = "src/main/ets" +} +ohos_resources("relationalstoreDataGroupId_resources") { + sources = [ "src/main/resources" ] + + deps = [ ":relationalstoreDataGroupId_app_profile" ] + + hap_profile = "src/main/module.json" +} diff --git a/distributeddatamgr/relationalstoredatagroupidtest/Test.json b/distributeddatamgr/relationalstoredatagroupidtest/Test.json new file mode 100644 index 0000000000000000000000000000000000000000..14457e96de5c75eb4b42ca11a5981e61b9bdf714 --- /dev/null +++ b/distributeddatamgr/relationalstoredatagroupidtest/Test.json @@ -0,0 +1,19 @@ +{ + "description": "Configuration for hjunit demo Tests", + "driver": { + "type": "OHJSUnitTest", + "test-timeout": "60000", + "shell-timeout": "60000", + "bundle-name": "ohos.acts.relationalstoredatagroupidtest", + "module-name": "relationalstoreDataGroupId" + }, + "kits": [ + { + "test-file-name": [ + "ActsRelationalstoreDataGroupIdTest.hap" + ], + "type": "AppInstallKit", + "cleanup-apps": true + } + ] +} \ No newline at end of file diff --git a/distributeddatamgr/relationalstoredatagroupidtest/signature/openharmony_sx.p7b b/distributeddatamgr/relationalstoredatagroupidtest/signature/openharmony_sx.p7b new file mode 100644 index 0000000000000000000000000000000000000000..d98a1473b50b4080dba358fd3603984ca47a66ba Binary files /dev/null and b/distributeddatamgr/relationalstoredatagroupidtest/signature/openharmony_sx.p7b differ diff --git a/distributeddatamgr/relationalstoredatagroupidtest/src/main/ets/TestAbility/TestAbility.ets b/distributeddatamgr/relationalstoredatagroupidtest/src/main/ets/TestAbility/TestAbility.ets new file mode 100644 index 0000000000000000000000000000000000000000..dac63ae78615c5762d40e44e94c5be2d33a1b546 --- /dev/null +++ b/distributeddatamgr/relationalstoredatagroupidtest/src/main/ets/TestAbility/TestAbility.ets @@ -0,0 +1,63 @@ +/* + * Copyright (C) 2023 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 UIAbility from "@ohos.app.ability.UIAbility"; +import AbilityDelegatorRegistry from "@ohos.app.ability.abilityDelegatorRegistry"; +import hilog from "@ohos.hilog"; +import { Hypium } from "@ohos/hypium"; +import testsuite from "../test/List.test"; +import window from "@ohos.window"; + +export default class TestAbility extends UIAbility { + onCreate(want, launchParam) { + hilog.info(0x0000, "testTag", "%{public}s", "TestAbility onCreate"); + hilog.info(0x0000, "testTag", "%{public}s", "want param:" + JSON.stringify(want) ?? ""); + hilog.info(0x0000, "testTag", "%{public}s", "launchParam:" + JSON.stringify(launchParam) ?? ""); + var abilityDelegator: any; + abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator(); + var abilityDelegatorArguments: any; + abilityDelegatorArguments = AbilityDelegatorRegistry.getArguments(); + hilog.info(0x0000, "testTag", "%{public}s", "start run testcase!!!"); + Hypium.hypiumTest(abilityDelegator, abilityDelegatorArguments, testsuite); + } + + onDestroy() { + hilog.info(0x0000, "testTag", "%{public}s", "TestAbility onDestroy"); + } + + onWindowStageCreate(windowStage: window.WindowStage) { + hilog.info(0x0000, "testTag", "%{public}s", "TestAbility onWindowStageCreate"); + globalThis.abilityContext = this.context; + windowStage.loadContent("TestAbility/pages/Index", (err, data) => { + if (err.code) { + hilog.error(0x0000, "testTag", "Failed to load the content. Cause: %{public}s", JSON.stringify(err) ?? ""); + return; + } + hilog.info(0x0000, "testTag", "Succeeded in loading the content. Data: %{public}s", JSON.stringify(data) ?? ""); + }); + } + + onWindowStageDestroy() { + hilog.info(0x0000, "testTag", "%{public}s", "TestAbility onWindowStageDestroy"); + } + + onForeground() { + hilog.info(0x0000, "testTag", "%{public}s", "TestAbility onForeground"); + } + + onBackground() { + hilog.info(0x0000, "testTag", "%{public}s", "TestAbility onBackground"); + } +} diff --git a/distributeddatamgr/relationalstoredatagroupidtest/src/main/ets/TestAbility/pages/Index.ets b/distributeddatamgr/relationalstoredatagroupidtest/src/main/ets/TestAbility/pages/Index.ets new file mode 100644 index 0000000000000000000000000000000000000000..7063c2427f471eb22dc9ea361188d2bbd6c24c57 --- /dev/null +++ b/distributeddatamgr/relationalstoredatagroupidtest/src/main/ets/TestAbility/pages/Index.ets @@ -0,0 +1,49 @@ +/* + * Copyright (C) 2023 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 '@ohos.hilog'; + +@Entry +@Component +struct Index { + aboutToAppear() { + hilog.info(0x0000, 'testTag', '%{public}s', 'TestAbility index aboutToAppear'); + } + @State message: string = 'Hello World' + build() { + Row() { + Column() { + Text(this.message) + .fontSize(50) + .fontWeight(FontWeight.Bold) + Button() { + Text('next page') + .fontSize(20) + .fontWeight(FontWeight.Bold) + }.type(ButtonType.Capsule) + .margin({ + top: 20 + }) + .backgroundColor('#0D9FFB') + .width('35%') + .height('5%') + .onClick(()=>{ + }) + } + .width('100%') + } + .height('100%') + } + } \ No newline at end of file diff --git a/distributeddatamgr/relationalstoredatagroupidtest/src/main/ets/TestRunner/OpenHarmonyTestRunner.ts b/distributeddatamgr/relationalstoredatagroupidtest/src/main/ets/TestRunner/OpenHarmonyTestRunner.ts new file mode 100644 index 0000000000000000000000000000000000000000..92a16d84e8870da219c51d9f1342c79203c1f42d --- /dev/null +++ b/distributeddatamgr/relationalstoredatagroupidtest/src/main/ets/TestRunner/OpenHarmonyTestRunner.ts @@ -0,0 +1,49 @@ +import hilog from '@ohos.hilog'; +import TestRunner from '@ohos.application.testRunner'; +import AbilityDelegatorRegistry from '@ohos.app.ability.abilityDelegatorRegistry'; + +var abilityDelegator = undefined +var abilityDelegatorArguments = undefined + +async function onAbilityCreateCallback() { + hilog.info(0x0000, 'testTag', '%{public}s', 'onAbilityCreateCallback'); +} + +async function addAbilityMonitorCallback(err: any) { + hilog.info(0x0000, 'testTag', 'addAbilityMonitorCallback : %{public}s', JSON.stringify(err) ?? ''); +} + +export default class OpenHarmonyTestRunner implements TestRunner { + constructor() { + } + + onPrepare() { + hilog.info(0x0000, 'testTag', '%{public}s', 'OpenHarmonyTestRunner OnPrepare '); + } + + async onRun() { + hilog.info(0x0000, 'testTag', '%{public}s', 'OpenHarmonyTestRunner onRun run'); + abilityDelegatorArguments = AbilityDelegatorRegistry.getArguments() + abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator() + var testAbilityName = abilityDelegatorArguments.bundleName + '.TestAbility' + let lMonitor = { + abilityName: testAbilityName, + onAbilityCreate: onAbilityCreateCallback, + }; + abilityDelegator.addAbilityMonitor(lMonitor, addAbilityMonitorCallback) + var cmd = 'aa start -d 0 -a TestAbility' + ' -b ' + abilityDelegatorArguments.bundleName + var debug = abilityDelegatorArguments.parameters['-D'] + if (debug == 'true') + { + cmd += ' -D' + } + hilog.info(0x0000, 'testTag', 'cmd : %{public}s', cmd); + abilityDelegator.executeShellCommand(cmd, + (err: any, d: any) => { + hilog.info(0x0000, 'testTag', 'executeShellCommand : err : %{public}s', JSON.stringify(err) ?? ''); + hilog.info(0x0000, 'testTag', 'executeShellCommand : data : %{public}s', d.stdResult ?? ''); + hilog.info(0x0000, 'testTag', 'executeShellCommand : data : %{public}s', d.exitCode ?? ''); + }) + hilog.info(0x0000, 'testTag', '%{public}s', 'OpenHarmonyTestRunner onRun end'); + } +} \ No newline at end of file diff --git a/distributeddatamgr/relationalstoredatagroupidtest/src/main/ets/test/List.test.ets b/distributeddatamgr/relationalstoredatagroupidtest/src/main/ets/test/List.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..514733983ad93c3c3dfb14895b6b4926775d5b57 --- /dev/null +++ b/distributeddatamgr/relationalstoredatagroupidtest/src/main/ets/test/List.test.ets @@ -0,0 +1,23 @@ +/* + * Copyright (c) 2023 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 relationalStoreDataGroupIdCallback from './relationalStoreDataGroupIdCallback.test' +import relationalStoreDataGroupIdPromise from './relationalStoreDataGroupIdPromise.test' + +export default function testsuite() { + relationalStoreDataGroupIdCallback() + relationalStoreDataGroupIdPromise() +} \ No newline at end of file diff --git a/distributeddatamgr/relationalstoredatagroupidtest/src/main/ets/test/relationalStoreDataGroupIdCallback.test.ets b/distributeddatamgr/relationalstoredatagroupidtest/src/main/ets/test/relationalStoreDataGroupIdCallback.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..95efef0ab7aea55608941e59b6cda8cb48b1412f --- /dev/null +++ b/distributeddatamgr/relationalstoredatagroupidtest/src/main/ets/test/relationalStoreDataGroupIdCallback.test.ets @@ -0,0 +1,186 @@ + /* + * Copyright (c) 2023 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 } from '@ohos/hypium' +import relationalStore from '@ohos.data.relationalStore'; + +const TAG = "[ttt]" +const CREATE_TABLE_TEST = "CREATE TABLE IF NOT EXISTS test (" ++ "id INTEGER PRIMARY KEY AUTOINCREMENT, " ++ "name TEXT NOT NULL, " ++ "age INTEGER, " ++ "salary REAL, " ++ "blobType BLOB)"; + +let context = globalThis.abilityContext; + +//let rdbStore; + + +export default function relationalStoreDataGroupIdCallback() { + describe('relationalStoreDataGroupIdCallback', function () { + beforeAll(function () { + console.info(TAG + 'beforeAll') + }) + + beforeEach(function () { + console.info(TAG + 'beforeEach') + }) + + afterEach(function () { + console.info(TAG + 'afterEach') + }) + + afterAll(async function () { + console.info(TAG + 'afterAll') + }) + + console.log(TAG + "*************Unit Test Begin*************"); + + + /** + * @tc.number SUB_DDM_RelationalStore_DataGroupId_Callback_0100 + * @tc.name relationalStore dataGroupId null callback test + * @tc.desc relationalStore dataGroupId null callback test + */ + it('SUB_DDM_RelationalStore_DataGroupId_Callback_0100', 0, async function (done) { + const STORE_CONFIG = { + name: "RdbTest.db", + securityLevel: relationalStore.SecurityLevel.S1, + dataGroupId: null, + }; + try { + relationalStore.getRdbStore(globalThis.abilityContext, STORE_CONFIG, async function (err, rdbStore) { + console.info(TAG, `Get RdbStore successfully.`); + expect(err !== null && rdbStore !== null).assertFail(); + done(); + await rdbStore.executeSql(CREATE_TABLE_TEST); + relationalStore.deleteRdbStore(globalThis.abilityContext, STORE_CONFIG, function (error) { + expect(error).assertFail(); + console.info(TAG, `Delete RdbStore successfully.`); + done(); + }) + }) + } catch (errInfo) { + console.error(TAG, `failed, code is ${errInfo.code},message is ${errInfo.message}`); + expect(errInfo.code).assertEqual('401'); + done(); + } + }) + + /** + * @tc.number SUB_DDM_RelationalStore_DataGroupId_Callback_0200 + * @tc.name relationalStore dataGroupId undefined callback test + * @tc.desc relationalStore dataGroupId undefined callback test + */ + it('SUB_DDM_RelationalStore_DataGroupId_Callback_0200', 0, async function (done) { + const STORE_CONFIG = { + name: "RdbTest.db", + securityLevel: relationalStore.SecurityLevel.S1, + dataGroupId: undefined, + }; + try { + relationalStore.getRdbStore(globalThis.abilityContext, STORE_CONFIG, async function (err, rdbStore) { + console.info(TAG, `Get RdbStore successfully.`); + expect(err !== null && rdbStore !== null).assertFail(); + done(); + await rdbStore.executeSql(CREATE_TABLE_TEST); + relationalStore.deleteRdbStore(globalThis.abilityContext, STORE_CONFIG, function (error) { + expect(error).assertFail(); + console.info(TAG, `Delete RdbStore successfully.`); + done(); + }) + }) + } catch (errInfo) { + console.error(TAG, `failed, code is ${errInfo.code},message is ${errInfo.message}`); + expect(errInfo.code).assertEqual('401'); + done(); + } + }) + + + /** + * @tc.number SUB_DDM_RelationalStore_DataGroupId_Callback_0300 + * @tc.name relationalStore dataGroupId callback test + * @tc.desc relationalStore dataGroupId callback test + */ + it('SUB_DDM_RelationalStore_DataGroupId_Callback_0300', 0, async function (done) { + const STORE_CONFIG = { + name: "RdbTest.db", + securityLevel: relationalStore.SecurityLevel.S1, + dataGroupId: '112233', + }; + try { + relationalStore.getRdbStore(globalThis.abilityContext, STORE_CONFIG, async function (err, rdbStore) { + console.info(TAG, `Get RdbStore successfully.`); + expect(err !== null && rdbStore !== null).assertFail(); + done(); + await rdbStore.executeSql(CREATE_TABLE_TEST); + relationalStore.deleteRdbStore(globalThis.abilityContext, STORE_CONFIG, function (error) { + expect(error).assertFail(); + console.info(TAG, `Delete RdbStore successfully.`); + done(); + }) + }) + } catch (errInfo) { + console.error(TAG, `failed, code is ${errInfo.code},message is ${errInfo.message}`); + expect(errInfo.code).assertEqual('14801002') + done(); + } + }) + + /** + * @tc.number SUB_DDM_RelationalStore_DataGroupId_Callback_0100 + * @tc.name relationalStore dataGroupId callback test + * @tc.desc relationalStore dataGroupId callback test + */ + // it('SUB_DDM_RelationalStore_DataGroupId_Callback_0100', 0, async function (done) { + // const STORE_CONFIG = { + // name: "RdbTest.db", + // securityLevel: relationalStore.SecurityLevel.S1, + // dataGroupId: '123456' + // }; + // try { + // relationalStore.getRdbStore(globalThis.abilityContext, STORE_CONFIG, async function (err, store) { + // rdbStore = store; + // if (err) { + // console.error(TAG, `Get RdbStore failed, code is ${err.code},message is ${err.message}`); + // return false; + // } + // console.info(TAG, `Get RdbStore successfully.`); + // await rdbStore.executeSql(CREATE_TABLE_TEST); + // relationalStore.deleteRdbStore(globalThis.abilityContext, STORE_CONFIG, function (err) { + // if (err) { + // console.error(TAG, `Delete RdbStore failed, code is ${err.code},message is ${err.message}`); + // return false; + // } + // console.info(TAG, `Delete RdbStore successfully.`); + // expect(err === null).assertTrue() + // done(); + // }) + // }) + // } catch (errInfo) { + // console.error(TAG, `failed, code is ${errInfo.code},message is ${errInfo.message}`); + // expect(errInfo !== null).assertFail() + // done(); + // } + // + // }) + + + console.log(TAG + "*************Unit Test End*************"); + }) +} \ No newline at end of file diff --git a/distributeddatamgr/relationalstoredatagroupidtest/src/main/ets/test/relationalStoreDataGroupIdPromise.test.ets b/distributeddatamgr/relationalstoredatagroupidtest/src/main/ets/test/relationalStoreDataGroupIdPromise.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..4f6246500ab698e9183b5592103e764771bb8894 --- /dev/null +++ b/distributeddatamgr/relationalstoredatagroupidtest/src/main/ets/test/relationalStoreDataGroupIdPromise.test.ets @@ -0,0 +1,154 @@ +/* + * Copyright (c) 2023 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 } from '@ohos/hypium' +import relationalStore from '@ohos.data.relationalStore'; + +const TAG = "[ttt]" +const CREATE_TABLE_TEST = "CREATE TABLE IF NOT EXISTS test (" ++ "id INTEGER PRIMARY KEY AUTOINCREMENT, " ++ "name TEXT NOT NULL, " ++ "age INTEGER, " ++ "salary REAL, " ++ "blobType BLOB)"; + +let rdbStore; + + +export default function relationalStoreDataGroupIdPromise() { + describe('relationalStoreDataGroupIdPromise', function () { + + + console.log(TAG + "*************Unit Test Begin*************"); + + /** + * @tc.number SUB_DDM_RelationalStore_DataGroupId_Promise_0100 + * @tc.name relationalStore dataGroupId null promise test + * @tc.desc relationalStore dataGroupId null promise test + */ + it('SUB_DDM_RelationalStore_DataGroupId_Promise_0100', 0, async function (done) { + const STORE_CONFIG = { + name: "RdbTest.db", + securityLevel: relationalStore.SecurityLevel.S1, + dataGroupId: null, + }; + try { + relationalStore.getRdbStore(globalThis.abilityContext, STORE_CONFIG).then(async (rdbStore) => { + console.info(TAG, `Get RdbStore successfully.`); + expect().assertFail(); + done(); + await rdbStore.executeSql(CREATE_TABLE_TEST); + relationalStore.deleteRdbStore(globalThis.abilityContext, STORE_CONFIG).then(async () => { + expect().assertFail(); + console.info(TAG, `Delete RdbStore successfully.`); + done(); + }).catch((error) => { + console.info(TAG, `Delete RdbStore fail, code is ${error.code},message is ${error.message}.`); + expect(error !== null).assertFail(); + done(); + }) + }).catch((err) => { + console.info(TAG, `Get RdbStore fail, code is ${err.code},message is ${err.message}.`); + expect(err !== null).assertFail(); + done(); + }) + } catch (errInfo) { + console.error(TAG, `failed, code is ${errInfo.code},message is ${errInfo.message}`); + expect(errInfo.code).assertEqual('401'); + done(); + } + }) + + /** + * @tc.number SUB_DDM_RelationalStore_DataGroupId_Promise_0200 + * @tc.name relationalStore dataGroupId undefined callback test + * @tc.desc relationalStore dataGroupId undefined callback test + */ + it('SUB_DDM_RelationalStore_DataGroupId_Promise_0200', 0, async function (done) { + const STORE_CONFIG = { + name: "RdbTest.db", + securityLevel: relationalStore.SecurityLevel.S1, + dataGroupId: undefined, + }; + try { + relationalStore.getRdbStore(globalThis.abilityContext, STORE_CONFIG).then(async (rdbStore) => { + console.info(TAG, `Get RdbStore successfully.`); + expect().assertFail(); + done(); + await rdbStore.executeSql(CREATE_TABLE_TEST); + relationalStore.deleteRdbStore(globalThis.abilityContext, STORE_CONFIG).then(async () => { + expect().assertFail(); + console.info(TAG, `Delete RdbStore successfully.`); + done(); + }).catch((error) => { + console.info(TAG, `Delete RdbStore fail, code is ${error.code},message is ${error.message}.`); + expect(error !== null).assertFail(); + done(); + }) + }).catch((err) => { + console.info(TAG, `Get RdbStore fail, code is ${err.code},message is ${err.message}.`); + expect(err !== null).assertFail(); + done(); + }) + } catch (errInfo) { + console.error(TAG, `failed, code is ${errInfo.code},message is ${errInfo.message}`); + expect(errInfo.code).assertEqual('401'); + done(); + } + }) + + + /** + * @tc.number SUB_DDM_RelationalStore_DataGroupId_Promise_0300 + * @tc.name relationalStore dataGroupId callback test + * @tc.desc relationalStore dataGroupId callback test + */ + it('SUB_DDM_RelationalStore_DataGroupId_Promise_0300', 0, async function (done) { + const STORE_CONFIG = { + name: "RdbTest.db", + securityLevel: relationalStore.SecurityLevel.S1, + dataGroupId: '112233', + }; + try { + relationalStore.getRdbStore(globalThis.abilityContext, STORE_CONFIG).then(async (rdbStore) => { + console.info(TAG, `Get RdbStore successfully.`); + expect().assertFail(); + done(); + await rdbStore.executeSql(CREATE_TABLE_TEST); + relationalStore.deleteRdbStore(globalThis.abilityContext, STORE_CONFIG).then(async () => { + expect().assertFail(); + console.info(TAG, `Delete RdbStore successfully.`); + done(); + }).catch((error) => { + console.info(TAG, `Delete RdbStore fail, code is ${error.code},message is ${error.message}.`); + expect(error !== null).assertFail(); + done(); + }) + }).catch((err) => { + console.info(TAG, `Get RdbStore fail, code is ${err.code},message is ${err.message}.`); + expect(err !== null).assertFail(); + done(); + }) + } catch (errInfo) { + console.error(TAG, `failed, code is ${errInfo.code},message is ${errInfo.message}`); + expect(errInfo.code).assertEqual('14801002'); + done(); + } + }) + + console.info(TAG + "*************Unit Test End*************"); + }) +} \ No newline at end of file diff --git a/distributeddatamgr/relationalstoredatagroupidtest/src/main/module.json b/distributeddatamgr/relationalstoredatagroupidtest/src/main/module.json new file mode 100644 index 0000000000000000000000000000000000000000..766cc11af93df1b5fad8748ad7d7ab28f8c0b8b2 --- /dev/null +++ b/distributeddatamgr/relationalstoredatagroupidtest/src/main/module.json @@ -0,0 +1,39 @@ +{ + "module": { + "name": "relationalstoreDataGroupId", + "type": "feature", + "description": "$string:module_test_desc", + "mainElement": "TestAbility", + "deviceTypes": [ + "default", + "tablet", + "phone", + "2in1" + ], + "deliveryWithInstall": true, + "installationFree": false, + "pages": "$profile:test_pages", + "abilities": [ + { + "name": "TestAbility", + "srcEntry": "./ets/TestAbility/TestAbility.ets", + "description": "$string:TestAbility_desc", + "icon": "$media:icon", + "label": "$string:TestAbility_label", + "exported": true, + "startWindowIcon": "$media:icon", + "startWindowBackground": "$color:start_window_background", + "skills": [ + { + "actions": [ + "action.system.home" + ], + "entities": [ + "entity.system.home" + ] + } + ] + } + ] + } +} diff --git a/distributeddatamgr/relationalstoredatagroupidtest/src/main/resources/base/element/color.json b/distributeddatamgr/relationalstoredatagroupidtest/src/main/resources/base/element/color.json new file mode 100644 index 0000000000000000000000000000000000000000..3c712962da3c2751c2b9ddb53559afcbd2b54a02 --- /dev/null +++ b/distributeddatamgr/relationalstoredatagroupidtest/src/main/resources/base/element/color.json @@ -0,0 +1,8 @@ +{ + "color": [ + { + "name": "start_window_background", + "value": "#FFFFFF" + } + ] +} \ No newline at end of file diff --git a/distributeddatamgr/relationalstoredatagroupidtest/src/main/resources/base/element/string.json b/distributeddatamgr/relationalstoredatagroupidtest/src/main/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..65d8fa5a7cf54aa3943dcd0214f58d1771bc1f6c --- /dev/null +++ b/distributeddatamgr/relationalstoredatagroupidtest/src/main/resources/base/element/string.json @@ -0,0 +1,16 @@ +{ + "string": [ + { + "name": "module_test_desc", + "value": "test ability description" + }, + { + "name": "TestAbility_desc", + "value": "the test ability" + }, + { + "name": "TestAbility_label", + "value": "test label" + } + ] +} \ No newline at end of file diff --git a/distributeddatamgr/relationalstoredatagroupidtest/src/main/resources/base/media/icon.png b/distributeddatamgr/relationalstoredatagroupidtest/src/main/resources/base/media/icon.png new file mode 100644 index 0000000000000000000000000000000000000000..ce307a8827bd75456441ceb57d530e4c8d45d36c Binary files /dev/null and b/distributeddatamgr/relationalstoredatagroupidtest/src/main/resources/base/media/icon.png differ diff --git a/distributeddatamgr/relationalstoredatagroupidtest/src/main/resources/base/profile/test_pages.json b/distributeddatamgr/relationalstoredatagroupidtest/src/main/resources/base/profile/test_pages.json new file mode 100644 index 0000000000000000000000000000000000000000..77e90731b5a38d861663029b483df3d3ac9ec74b --- /dev/null +++ b/distributeddatamgr/relationalstoredatagroupidtest/src/main/resources/base/profile/test_pages.json @@ -0,0 +1,5 @@ +{ + "src": [ + "TestAbility/pages/Index" + ] +}