diff --git a/distributeddatamgr/BUILD.gn b/distributeddatamgr/BUILD.gn index 44251c1c06241033f80bd6c56094ec816ce6a654..48e438d3d1ff1bd04f2710e3778782e4697ebb3b 100644 --- a/distributeddatamgr/BUILD.gn +++ b/distributeddatamgr/BUILD.gn @@ -16,15 +16,16 @@ group("distributeddatamgr") { testonly = true if (is_standard_system) { deps = [ - "appdatamgrjstest/hap:appdatamgr_js_test", - "distributeddataObjectjstest/hap:distributeddataObject_js_test", - "distributeddatamgrjstest/hap:distributeddatamgr_js_test", - "windowStage:windowStage", + "dataObjectjstest/hap:dataObject_js_test", + "dataShare:dataShare", + "kvStorejstest/hap:kvStore_js_test", + "preferencesjstest/hap:preferences_js_test", + "relationalStorejstest/hap:relationalstore_js_test", ] } else { deps = [ - "appdatamgrtest/hap:appdatamgrfunctest_hap", - "distributeddatamgrtest/hap:distributeddatamgrfunctest_hap", + "kvStorejstest/hap:distributeddatamgrfunctest_hap", + "relationalStorejstest/hap:appdatamgrfunctest_hap", "searchtest/hap:searchfunctest_hap", ] } diff --git a/distributeddatamgr/distributeddataObjectjstest/hap/BUILD.gn b/distributeddatamgr/dataObjectjstest/hap/BUILD.gn similarity index 76% rename from distributeddatamgr/distributeddataObjectjstest/hap/BUILD.gn rename to distributeddatamgr/dataObjectjstest/hap/BUILD.gn index da89b5297b4530a498bf0210f3c337807f2806df..552ba8f4336319db08a3b0de8b6db9054079936f 100644 --- a/distributeddatamgr/distributeddataObjectjstest/hap/BUILD.gn +++ b/distributeddatamgr/dataObjectjstest/hap/BUILD.gn @@ -9,25 +9,27 @@ # 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. +# limitations under the License. import("//test/xts/tools/build/suite.gni") -ohos_js_hap_suite("distributeddataObject_js_test") { +ohos_js_hap_suite("dataObject_js_test") { hap_profile = "./src/main/config.json" deps = [ - ":distributeddataObject_js_assets", - ":distributeddataObject_resources", + ":dataObject_js_assets", + ":dataObject_resources", ] certificate_profile = "./signature/openharmony_sx.p7b" - hap_name = "ActsDistributedDataObjectJsTest" + hap_name = "ActsDataObjectJsTest" + subsystem_name = "distributeddatamgr" + part_name = "data_object" } -ohos_js_assets("distributeddataObject_js_assets") { +ohos_js_assets("dataObject_js_assets") { js2abc = true hap_profile = "./src/main/config.json" source_dir = "./src/main/js" } -ohos_resources("distributeddataObject_resources") { +ohos_resources("dataObject_resources") { sources = [ "./src/main/resources" ] hap_profile = "./src/main/config.json" } diff --git a/distributeddatamgr/distributeddataObjectjstest/hap/Test.json b/distributeddatamgr/dataObjectjstest/hap/Test.json similarity index 64% rename from distributeddatamgr/distributeddataObjectjstest/hap/Test.json rename to distributeddatamgr/dataObjectjstest/hap/Test.json index a117e896caea634540facc9ec052cbf2d06276e4..c686f26988adb335e6f3ccefceba784d46840a78 100644 --- a/distributeddatamgr/distributeddataObjectjstest/hap/Test.json +++ b/distributeddatamgr/dataObjectjstest/hap/Test.json @@ -4,13 +4,13 @@ "type": "OHJSUnitTest", "test-timeout": "1200000", "shell-timeout": "1200000", - "bundle-name": "ohos.acts.distributeddataObject", - "package-name": "ohos.acts.distributeddataObject" + "bundle-name": "ohos.acts.dataObject", + "package-name": "ohos.acts.dataObject" }, "kits": [ { "test-file-name": [ - "ActsDistributedDataObjectJsTest.hap" + "ActsDataObjectJsTest.hap" ], "type": "AppInstallKit", "cleanup-apps": true diff --git a/distributeddatamgr/appdatamgrjstest/hap/signature/openharmony_sx.p7b b/distributeddatamgr/dataObjectjstest/hap/signature/openharmony_sx.p7b similarity index 100% rename from distributeddatamgr/appdatamgrjstest/hap/signature/openharmony_sx.p7b rename to distributeddatamgr/dataObjectjstest/hap/signature/openharmony_sx.p7b diff --git a/distributeddatamgr/distributeddataObjectjstest/hap/src/main/config.json b/distributeddatamgr/dataObjectjstest/hap/src/main/config.json similarity index 92% rename from distributeddatamgr/distributeddataObjectjstest/hap/src/main/config.json rename to distributeddatamgr/dataObjectjstest/hap/src/main/config.json index 40d806d7012428520ffd0a78fd2e40584477b454..6d81160593f04a9230751298d772c31cb7a3b686 100644 --- a/distributeddatamgr/distributeddataObjectjstest/hap/src/main/config.json +++ b/distributeddatamgr/dataObjectjstest/hap/src/main/config.json @@ -1,6 +1,6 @@ { "app": { - "bundleName": "ohos.acts.distributeddataObject", + "bundleName": "ohos.acts.dataObject", "vendor": "example", "version": { "code": 1000000, @@ -13,7 +13,7 @@ }, "deviceConfig": {}, "module": { - "package": "ohos.acts.distributeddataObject", + "package": "ohos.acts.dataObject", "name": ".entry", "mainAbility": ".MainAbility", "deviceType": [ diff --git a/distributeddatamgr/distributeddataObjectjstest/hap/src/main/js/MainAbility/app.js b/distributeddatamgr/dataObjectjstest/hap/src/main/js/MainAbility/app.js similarity index 100% rename from distributeddatamgr/distributeddataObjectjstest/hap/src/main/js/MainAbility/app.js rename to distributeddatamgr/dataObjectjstest/hap/src/main/js/MainAbility/app.js diff --git a/distributeddatamgr/distributeddataObjectjstest/hap/src/main/js/MainAbility/i18n/en-US.json b/distributeddatamgr/dataObjectjstest/hap/src/main/js/MainAbility/i18n/en-US.json similarity index 100% rename from distributeddatamgr/distributeddataObjectjstest/hap/src/main/js/MainAbility/i18n/en-US.json rename to distributeddatamgr/dataObjectjstest/hap/src/main/js/MainAbility/i18n/en-US.json diff --git a/distributeddatamgr/distributeddataObjectjstest/hap/src/main/js/MainAbility/i18n/zh-CN.json b/distributeddatamgr/dataObjectjstest/hap/src/main/js/MainAbility/i18n/zh-CN.json similarity index 100% rename from distributeddatamgr/distributeddataObjectjstest/hap/src/main/js/MainAbility/i18n/zh-CN.json rename to distributeddatamgr/dataObjectjstest/hap/src/main/js/MainAbility/i18n/zh-CN.json diff --git a/distributeddatamgr/distributeddataObjectjstest/hap/src/main/js/MainAbility/pages/index/index.css b/distributeddatamgr/dataObjectjstest/hap/src/main/js/MainAbility/pages/index/index.css similarity index 100% rename from distributeddatamgr/distributeddataObjectjstest/hap/src/main/js/MainAbility/pages/index/index.css rename to distributeddatamgr/dataObjectjstest/hap/src/main/js/MainAbility/pages/index/index.css diff --git a/distributeddatamgr/distributeddataObjectjstest/hap/src/main/js/MainAbility/pages/index/index.hml b/distributeddatamgr/dataObjectjstest/hap/src/main/js/MainAbility/pages/index/index.hml similarity index 100% rename from distributeddatamgr/distributeddataObjectjstest/hap/src/main/js/MainAbility/pages/index/index.hml rename to distributeddatamgr/dataObjectjstest/hap/src/main/js/MainAbility/pages/index/index.hml diff --git a/distributeddatamgr/distributeddataObjectjstest/hap/src/main/js/MainAbility/pages/index/index.js b/distributeddatamgr/dataObjectjstest/hap/src/main/js/MainAbility/pages/index/index.js similarity index 100% rename from distributeddatamgr/distributeddataObjectjstest/hap/src/main/js/MainAbility/pages/index/index.js rename to distributeddatamgr/dataObjectjstest/hap/src/main/js/MainAbility/pages/index/index.js diff --git a/distributeddatamgr/appdatamgrjstest/hap/src/main/js/TestAbility/app.js b/distributeddatamgr/dataObjectjstest/hap/src/main/js/TestAbility/app.js similarity index 100% rename from distributeddatamgr/appdatamgrjstest/hap/src/main/js/TestAbility/app.js rename to distributeddatamgr/dataObjectjstest/hap/src/main/js/TestAbility/app.js diff --git a/distributeddatamgr/appdatamgrjstest/hap/src/main/js/MainAbility/i18n/en-US.json b/distributeddatamgr/dataObjectjstest/hap/src/main/js/TestAbility/i18n/en-US.json similarity index 100% rename from distributeddatamgr/appdatamgrjstest/hap/src/main/js/MainAbility/i18n/en-US.json rename to distributeddatamgr/dataObjectjstest/hap/src/main/js/TestAbility/i18n/en-US.json diff --git a/distributeddatamgr/appdatamgrjstest/hap/src/main/js/MainAbility/i18n/zh-CN.json b/distributeddatamgr/dataObjectjstest/hap/src/main/js/TestAbility/i18n/zh-CN.json similarity index 100% rename from distributeddatamgr/appdatamgrjstest/hap/src/main/js/MainAbility/i18n/zh-CN.json rename to distributeddatamgr/dataObjectjstest/hap/src/main/js/TestAbility/i18n/zh-CN.json diff --git a/distributeddatamgr/appdatamgrjstest/hap/src/main/js/TestAbility/pages/index/index.css b/distributeddatamgr/dataObjectjstest/hap/src/main/js/TestAbility/pages/index/index.css similarity index 100% rename from distributeddatamgr/appdatamgrjstest/hap/src/main/js/TestAbility/pages/index/index.css rename to distributeddatamgr/dataObjectjstest/hap/src/main/js/TestAbility/pages/index/index.css diff --git a/distributeddatamgr/appdatamgrjstest/hap/src/main/js/TestAbility/pages/index/index.hml b/distributeddatamgr/dataObjectjstest/hap/src/main/js/TestAbility/pages/index/index.hml similarity index 100% rename from distributeddatamgr/appdatamgrjstest/hap/src/main/js/TestAbility/pages/index/index.hml rename to distributeddatamgr/dataObjectjstest/hap/src/main/js/TestAbility/pages/index/index.hml diff --git a/distributeddatamgr/appdatamgrjstest/hap/src/main/js/TestAbility/pages/index/index.js b/distributeddatamgr/dataObjectjstest/hap/src/main/js/TestAbility/pages/index/index.js similarity index 100% rename from distributeddatamgr/appdatamgrjstest/hap/src/main/js/TestAbility/pages/index/index.js rename to distributeddatamgr/dataObjectjstest/hap/src/main/js/TestAbility/pages/index/index.js diff --git a/distributeddatamgr/appdatamgrjstest/hap/src/main/js/TestRunner/OpenHarmonyTestRunner.js b/distributeddatamgr/dataObjectjstest/hap/src/main/js/TestRunner/OpenHarmonyTestRunner.js similarity index 100% rename from distributeddatamgr/appdatamgrjstest/hap/src/main/js/TestRunner/OpenHarmonyTestRunner.js rename to distributeddatamgr/dataObjectjstest/hap/src/main/js/TestRunner/OpenHarmonyTestRunner.js diff --git a/distributeddatamgr/distributeddataObjectjstest/hap/src/main/js/test/List.test.js b/distributeddatamgr/dataObjectjstest/hap/src/main/js/test/List.test.js similarity index 100% rename from distributeddatamgr/distributeddataObjectjstest/hap/src/main/js/test/List.test.js rename to distributeddatamgr/dataObjectjstest/hap/src/main/js/test/List.test.js diff --git a/distributeddatamgr/distributeddataObjectjstest/hap/src/main/js/test/ObjectStoreJsunit.test.js b/distributeddatamgr/dataObjectjstest/hap/src/main/js/test/ObjectStoreJsunit.test.js similarity index 100% rename from distributeddatamgr/distributeddataObjectjstest/hap/src/main/js/test/ObjectStoreJsunit.test.js rename to distributeddatamgr/dataObjectjstest/hap/src/main/js/test/ObjectStoreJsunit.test.js diff --git a/distributeddatamgr/distributeddataObjectjstest/hap/src/main/resources/base/element/string.json b/distributeddatamgr/dataObjectjstest/hap/src/main/resources/base/element/string.json similarity index 100% rename from distributeddatamgr/distributeddataObjectjstest/hap/src/main/resources/base/element/string.json rename to distributeddatamgr/dataObjectjstest/hap/src/main/resources/base/element/string.json diff --git a/distributeddatamgr/appdatamgrjstest/hap/src/main/resources/base/media/icon.png b/distributeddatamgr/dataObjectjstest/hap/src/main/resources/base/media/icon.png similarity index 100% rename from distributeddatamgr/appdatamgrjstest/hap/src/main/resources/base/media/icon.png rename to distributeddatamgr/dataObjectjstest/hap/src/main/resources/base/media/icon.png diff --git a/distributeddatamgr/windowStage/BUILD.gn b/distributeddatamgr/dataShare/BUILD.gn similarity index 83% rename from distributeddatamgr/windowStage/BUILD.gn rename to distributeddatamgr/dataShare/BUILD.gn index 2f42d4434f17ebdd6608095cd7bbdff37aeccaa9..bbf5e1aff7a9ee9f4de1624572d8a4e04cc1a149 100644 --- a/distributeddatamgr/windowStage/BUILD.gn +++ b/distributeddatamgr/dataShare/BUILD.gn @@ -13,11 +13,14 @@ import("//test/xts/tools/build/suite.gni") -group("windowStage") { +group("dataShare") { testonly = true if (is_standard_system) { deps = [ + "dataShareKvtest:ActsDataShareKvTest", "dataShareRdbtest:ActsDataShareRdbTest", + "dataSharejstest/hap:dataShare_js_test", + "server/kvService:ActsKvServiceHap", "server/rdbService:ActsRdbServiceHap", ] } diff --git a/distributeddatamgr/dataShare/dataShareKvtest/AppScope/app.json b/distributeddatamgr/dataShare/dataShareKvtest/AppScope/app.json new file mode 100644 index 0000000000000000000000000000000000000000..c83a65e9a6b4dc9722ae20089e1151fec2a72628 --- /dev/null +++ b/distributeddatamgr/dataShare/dataShareKvtest/AppScope/app.json @@ -0,0 +1,20 @@ +{ + "app": { + "bundleName": "com.example.myapplication2", + "vendor": "example", + "versionCode": 1000000, + "versionName": "1.0.0", + "icon": "$media:app_icon", + "label": "$string:app_name", + "debug": false, + "distributedNotificationEnabled": true, + "keepAlive": true, + "singleUser": true, + "minAPIVersion": 9, + "targetAPIVersion": 9, + "car": { + "apiCompatibleVersion": 9, + "singleUser": false + } + } +} diff --git a/distributeddatamgr/dataShare/dataShareKvtest/AppScope/resources/base/element/string.json b/distributeddatamgr/dataShare/dataShareKvtest/AppScope/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..743eebb13dba6bf565857756006a7c13bd8e7299 --- /dev/null +++ b/distributeddatamgr/dataShare/dataShareKvtest/AppScope/resources/base/element/string.json @@ -0,0 +1,8 @@ +{ + "string": [ + { + "name": "app_name", + "value": "MyApplication2" + } + ] +} diff --git a/distributeddatamgr/windowStage/dataShareRdbtest/AppScope/resources/base/media/app_icon.png b/distributeddatamgr/dataShare/dataShareKvtest/AppScope/resources/base/media/app_icon.png similarity index 100% rename from distributeddatamgr/windowStage/dataShareRdbtest/AppScope/resources/base/media/app_icon.png rename to distributeddatamgr/dataShare/dataShareKvtest/AppScope/resources/base/media/app_icon.png diff --git a/distributeddatamgr/dataShare/dataShareKvtest/BUILD.gn b/distributeddatamgr/dataShare/dataShareKvtest/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..7123a280880837a1f27f6f8a2e7c045c5af21183 --- /dev/null +++ b/distributeddatamgr/dataShare/dataShareKvtest/BUILD.gn @@ -0,0 +1,43 @@ +# 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("//test/xts/tools/build/suite.gni") + +ohos_js_hap_suite("ActsDataShareKvTest") { + hap_profile = "entry/src/main/module.json" + js_build_mode = "debug" + deps = [ + ":dataShareKv_js_assets", + ":dataShareKv_resources", + ] + ets2abc = true + certificate_profile = "signature/openharmony_sx.p7b" + hap_name = "ActsDataShareKvTest" + subsystem_name = "distributeddatamgr" + part_name = "data_share" +} + +ohos_app_scope("dataShareKv_app_profile") { + app_profile = "AppScope/app.json" + sources = [ "AppScope/resources" ] +} + +ohos_js_assets("dataShareKv_js_assets") { + source_dir = "entry/src/main/ets" +} + +ohos_resources("dataShareKv_resources") { + sources = [ "entry/src/main/resources" ] + deps = [ ":dataShareKv_app_profile" ] + hap_profile = "entry/src/main/module.json" +} diff --git a/distributeddatamgr/dataShare/dataShareKvtest/Test.json b/distributeddatamgr/dataShare/dataShareKvtest/Test.json new file mode 100644 index 0000000000000000000000000000000000000000..3db4301be42ad609c1701bafe28561bab892dcdf --- /dev/null +++ b/distributeddatamgr/dataShare/dataShareKvtest/Test.json @@ -0,0 +1,19 @@ +{ + "description": "Configuration for hjunit demo Tests", + "driver": { + "type": "OHJSUnitTest", + "test-timeout": "180000", + "bundle-name": "com.example.myapplication2", + "module-name": "entry", + "shell-timeout": "600000", + "testcase-timeout": 70000 + }, + "kits": [{ + "test-file-name": [ + "ActsDataShareKvTest.hap", + "ActsKvServiceHap.hap" + ], + "type": "AppInstallKit", + "cleanup-apps": true + }] +} \ No newline at end of file diff --git a/distributeddatamgr/dataShare/dataShareKvtest/entry/src/main/ets/Application/AbilityStage.ts b/distributeddatamgr/dataShare/dataShareKvtest/entry/src/main/ets/Application/AbilityStage.ts new file mode 100644 index 0000000000000000000000000000000000000000..02ecba3c3e620207210edec3de91aa7191f6e8c7 --- /dev/null +++ b/distributeddatamgr/dataShare/dataShareKvtest/entry/src/main/ets/Application/AbilityStage.ts @@ -0,0 +1,22 @@ +/* +* 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 AbilityStage from "@ohos.application.AbilityStage" + +export default class MyAbilityStage extends AbilityStage { + onCreate() { + console.log("[Demo] MyAbilityStage onCreate") + } +} \ No newline at end of file diff --git a/distributeddatamgr/dataShare/dataShareKvtest/entry/src/main/ets/MainAbility/MainAbility.ts b/distributeddatamgr/dataShare/dataShareKvtest/entry/src/main/ets/MainAbility/MainAbility.ts new file mode 100644 index 0000000000000000000000000000000000000000..cc6fdc5ef88488efe7bb9715a0c385c4bc32ffd0 --- /dev/null +++ b/distributeddatamgr/dataShare/dataShareKvtest/entry/src/main/ets/MainAbility/MainAbility.ts @@ -0,0 +1,144 @@ +/* +* 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 Ability from '@ohos.application.Ability' +import dataShare from '@ohos.data.dataShare' +import rpc from "@ohos.rpc"; + +var seConnect = { + onConnect:function (elementName, proxy) { + console.log("[ttt] [DataShareTest] <> seConnect onConnect called."); + console.log("[ttt] [DataShareTest] <> seConnect onConnect elementName = " + elementName); + console.log("[ttt] [DataShareTest] <> seConnect onConnect proxy = " + proxy); + let data = rpc.MessageParcel.create(); + let reply = rpc.MessageParcel.create(); + let option = new rpc.MessageOption(); + data.writeInterfaceToken("connect-test"); + data.writeInt(111); + + console.log("[ttt] [DataShareTest] <> seConnect onConnect sendRequest."); + proxy.sendRequest(1, data, reply, option) + .then(function (result) { + if (result.errCode === 0) { + // let msg = reply.readString(); + let msg = result.reply.readInt(); + console.log("[ttt] [DataShareTest] <> seConnect reply msg: " + msg); + } else { + console.log("[ttt] [DataShareTest] <> seConnect sendRequest failed, errCode: " + result.errCode); + } + // callback没有返回值,默认返回undefined + }).catch(function (e) { + console.log("[ttt] [DataShareTest] <> seConnect sendRequest got exception: " + e); + }).finally (async () => { + console.log("[ttt] [DataShareTest] <> seConnect sendRequest ends, reclaim parcel"); + data.reclaim(); + reply.reclaim(); + }) + }, + onDisconnect:function (elementName) { + console.log("[ttt] [DataShareTest] <> seConnect onDisconnect"); + }, + onFailed:function (code) { + console.log("[ttt] [DataShareTest] <> seConnect onFailed"); + } +}; + +let dseProxy = 0; +let dseUri = ("datashare:///com.samples.datasharekvtest.DataShare"); + +var dseConnect = { + onConnect:function (elementName, proxy) { + console.log("[ttt] [DataShareTest] <> dseConnect onConnect called."); + // console.log("[ttt] [DataShareTest] <> dseConnect onConnect elementName = " + elementName); + // console.log("[ttt] [DataShareTest] <> dseConnect onConnect proxy = " + proxy); + dseProxy = proxy; + }, + onDisconnect:function (elementName) { + console.log("[ttt] [DataShareTest] <> dseConnect onDisconnect, elementName:" + elementName); + }, + onFailed:function (code) { + console.log("[ttt] [DataShareTest] <> dseConnect onFailed, code:" + code); + } +}; + +let seConnectionId = -1; +let dseConnectionId = -1; + +let seWant = { + "bundleName": "com.samples.datasharetest", + "abilityName": "ServiceExtAbility", +} + +let dseWant = { + "bundleName": "com.samples.datasharetest", + "abilityName": "DataShareExtAbility", +} + +export function onCallback() { + console.info("[ttt] [DataShareTest] <> **** Observer on callback ****"); +} + +export function offCallback() { + console.info("[ttt] [DataShareTest] <> **** Observer off callback ****"); +} + +export default class MainAbility extends Ability { + onCreate(want, launchParam) { + // Ability is creating, initialize resources for this ability + console.log("[ttt] [DataShareTest] <> MainAbility onCreate") + globalThis.abilityWant = want; + } + + onDestroy() { + // Ability is destroying, release resources for this ability + console.log("[ttt] [DataShareTest] <> MainAbility onDestroy") + } + + onWindowStageCreate(windowStage) { + // Main window is created, set main page for this ability + console.log("[ttt] [DataShareTest] <> MainAbility onWindowStageCreate") + globalThis.abilityContext = this.context; + let context = this.context; + dseConnectionId = context.connectAbility(dseWant, dseConnect); + globalThis.connectDataShareExtAbility = (async () => { + console.log("[ttt] [DataShareTest] <> connectDataShareExtAbility begin"); + await dataShare.createDataShareHelper(globalThis.abilityContext, dseUri, (err,data)=>{ + globalThis.helper = data; + globalThis.testhelper = data; + console.info("[ttt] [DataShareTest] <> ----- 1 -----, globalThis.helper = " + globalThis.helper); + console.info("[ttt] [DataShareTest] <> ----- 2 -----, data = " + data); + console.info("[ttt] [DataShareTest] <> ----- 3 -----, err = " + err); + console.info("[ttt] [DataShareTest] <> ----- 4 -----, JSON.stringify(err) = " + JSON.stringify(err)); + }); + dseConnectionId = await context.connectAbility(dseWant, dseConnect); + }) + windowStage.setUIContent(this.context, "MainAbility/pages/index", null) + } + + onWindowStageDestroy() { + // Main window is destroyed, release UI related resources + console.log("[ttt] [DataShareTest] <> MainAbility onWindowStageDestroy") + } + + onForeground() { + // Ability has brought to foreground + console.log("[ttt] [DataShareTest] <> MainAbility onForeground") + } + + onBackground() { + // Ability has back to background + console.log("[ttt] [DataShareTest] <> MainAbility onBackground") + } +}; diff --git a/distributeddatamgr/dataShare/dataShareKvtest/entry/src/main/ets/MainAbility/pages/index.ets b/distributeddatamgr/dataShare/dataShareKvtest/entry/src/main/ets/MainAbility/pages/index.ets new file mode 100644 index 0000000000000000000000000000000000000000..3ee1f46bd035e2a8b9f73a81190bbd1985284185 --- /dev/null +++ b/distributeddatamgr/dataShare/dataShareKvtest/entry/src/main/ets/MainAbility/pages/index.ets @@ -0,0 +1,58 @@ +/* +* 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 file from '@system.file'; +import router from '@ohos.router'; +import AbilityDelegatorRegistry from '@ohos.application.abilityDelegatorRegistry' +import { Hypium } from '@ohos/hypium' +import testsuite from '../../test/List.test' + +//InstrumentLog, ReportExtend + +@Entry +@Component +struct Index { + + aboutToAppear(){ + console.info("start run testcase!!!!") + var abilityDelegator: any + abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator() + var abilityDelegatorArguments: any + abilityDelegatorArguments = AbilityDelegatorRegistry.getArguments() + console.info('start run testcase!!!') + Hypium.hypiumTest(abilityDelegator, abilityDelegatorArguments, testsuite) + } + + build() { + Flex({ direction:FlexDirection.Column, alignItems:ItemAlign.Center, justifyContent: FlexAlign.Center }) { + Text('Hello World') + .fontSize(50) + .fontWeight(FontWeight.Bold) + Button() { + Text('next page') + .fontSize(25) + .fontWeight(FontWeight.Bold) + }.type(ButtonType.Capsule) + .margin({ + top: 20 + }) + .backgroundColor('#0D9FFB') + .onClick(() => { + + }) + } + .width('100%') + .height('100%') + } +} \ No newline at end of file diff --git a/distributeddatamgr/windowStage/dataShareRdbtest/entry/src/main/ets/TestAbility/TestAbility.ts b/distributeddatamgr/dataShare/dataShareKvtest/entry/src/main/ets/TestAbility/TestAbility.ts similarity index 100% rename from distributeddatamgr/windowStage/dataShareRdbtest/entry/src/main/ets/TestAbility/TestAbility.ts rename to distributeddatamgr/dataShare/dataShareKvtest/entry/src/main/ets/TestAbility/TestAbility.ts diff --git a/distributeddatamgr/windowStage/dataShareRdbtest/entry/src/main/ets/TestAbility/pages/index.ets b/distributeddatamgr/dataShare/dataShareKvtest/entry/src/main/ets/TestAbility/pages/index.ets similarity index 100% rename from distributeddatamgr/windowStage/dataShareRdbtest/entry/src/main/ets/TestAbility/pages/index.ets rename to distributeddatamgr/dataShare/dataShareKvtest/entry/src/main/ets/TestAbility/pages/index.ets diff --git a/distributeddatamgr/dataShare/dataShareKvtest/entry/src/main/ets/TestRunner/OpenHarmonyTestRunner.ts b/distributeddatamgr/dataShare/dataShareKvtest/entry/src/main/ets/TestRunner/OpenHarmonyTestRunner.ts new file mode 100644 index 0000000000000000000000000000000000000000..f98317aaa139b06cead9061b97117ec3c4c32384 --- /dev/null +++ b/distributeddatamgr/dataShare/dataShareKvtest/entry/src/main/ets/TestRunner/OpenHarmonyTestRunner.ts @@ -0,0 +1,78 @@ +/* + * 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 TestRunner from '@ohos.application.testRunner' +import AbilityDelegatorRegistry from '@ohos.application.abilityDelegatorRegistry' + +var abilityDelegator = undefined +var abilityDelegatorArguments = undefined + +function translateParamsToString(parameters) { + const keySet = new Set([ + '-s class', '-s notClass', '-s suite', '-s it', + '-s level', '-s testType', '-s size', '-s timeout', + '-s dryRun' + ]) + let targetParams = ''; + for (const key in parameters) { + if (keySet.has(key)) { + targetParams = `${targetParams} ${key} ${parameters[key]}` + } + } + return targetParams.trim() +} + +async function onAbilityCreateCallback() { + console.log("onAbilityCreateCallback"); +} + +async function addAbilityMonitorCallback(err: any) { + console.info("addAbilityMonitorCallback : " + JSON.stringify(err)) +} + +export default class OpenHarmonyTestRunner implements TestRunner { + constructor() { + } + + onPrepare() { + console.info("OpenHarmonyTestRunner OnPrepare ") + } + + async onRun() { + console.log('OpenHarmonyTestRunner onRun run') + abilityDelegatorArguments = AbilityDelegatorRegistry.getArguments() + abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator() + var testAbilityName = abilityDelegatorArguments.bundleName + '.MainAbility' + let lMonitor = { + abilityName: testAbilityName, + onAbilityCreate: onAbilityCreateCallback, + }; + abilityDelegator.addAbilityMonitor(lMonitor, addAbilityMonitorCallback) + var cmd = 'aa start -d 0 -a com.example.myapplication2.MainAbility' + ' -b ' + abilityDelegatorArguments.bundleName + cmd += ' '+translateParamsToString(abilityDelegatorArguments.parameters) + var debug = abilityDelegatorArguments.parameters["-D"] + if (debug == 'true') + { + cmd += ' -D' + } + console.info('cmd : '+cmd) + abilityDelegator.executeShellCommand(cmd, + (err: any, d: any) => { + console.info('executeShellCommand : err : ' + JSON.stringify(err)); + console.info('executeShellCommand : data : ' + d.stdResult); + console.info('executeShellCommand : data : ' + d.exitCode); + }) + console.info('OpenHarmonyTestRunner onRun end') + } +}; \ No newline at end of file diff --git a/distributeddatamgr/dataShare/dataShareKvtest/entry/src/main/ets/test/DataShareCombinationKvdb.ets b/distributeddatamgr/dataShare/dataShareKvtest/entry/src/main/ets/test/DataShareCombinationKvdb.ets new file mode 100644 index 0000000000000000000000000000000000000000..14ae14fa4dc80dce3531a939cf54dea35258f372 --- /dev/null +++ b/distributeddatamgr/dataShare/dataShareKvtest/entry/src/main/ets/test/DataShareCombinationKvdb.ets @@ -0,0 +1,504 @@ +/* +* 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 dataShare from '@ohos.data.dataShare' +import * as pubfun from './DataSharePublicfunction_Promise' +import dataSharePredicates from '@ohos.data.dataSharePredicates' + +//CreateDataShareHelper +let uri = "datashare:///com.samples.datasharekvtest.DataShare"; + +//InsertValuesBucket +let Insert = { "name": "sun", "age": 1, "isStudent": true }; + +let BatchInsert = new Array( + { "name": "sun", "age": 1, "isStudent": true }, + { "name": "sun", "age": 10, "isStudent": false }); + +let Insert100 = new Array(); +for (let i = 0; i < 100; i++) { + Insert100.push({ "name": "sun", "age": i + 1, "isStudent": true }); +} + +//UpdateValuesBucket +let Update = { "name": "suns", "age": 1, "isStudent": false }; + +//Predicates +let EqualTo = new dataSharePredicates.DataSharePredicates(); +EqualTo.equalTo("$.age", 1); +let ResultSetEqualTo = new dataSharePredicates.DataSharePredicates(); +ResultSetEqualTo.equalTo("$.name", "sun"); +let PredicatesDelete0 = new dataSharePredicates.DataSharePredicates(); +PredicatesDelete0.inKeys(["testkey0"]); +let PredicatesDelete1 = new dataSharePredicates.DataSharePredicates(); +PredicatesDelete1.inKeys(["testkey1"]); + +//getColumnIndex +const IndexValue = "value"; + +//Return Expect + +const ResultSetInsert = { "name": "sun", "age": 1, "isStudent": "true" }; +const ResultSetUpdate = { "name": "suns", "age": 1, "isStudent": "false" }; +const DataProcessResultOne = 1; +const DataProcessResultThree = 3; +const column = 1; +let Delete = 0; + +function onChangeNotify() { + console.info("===>onChangeNotify===>"); +}; + +function notifyChangeCallback() { + console.info("===>notifyChangeCallback===>"); +}; + +export default function DataShareCombinationKvdb() { + describe('DataShareCombinationKvdb', function () { + function sleep(time) { + return new Promise(resolve => { + setTimeout(() => { + resolve('sleep finished'); + }, time); + }) + } + + beforeAll(async () => { + await globalThis.connectDataShareExtAbility(); + await sleep(2000); + console.info("[ttt] helper = " + globalThis.helper + "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!") + }) + + /* + * @tc.number : SUB_DDM_DataShare_ETS_DataShareCombinationKvdb0101 + * @tc.name : Use getEntries get the value by mixing the string key + * @tc.desc : Insert Update Query Delete in Kvdb + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 1 +*/ + it('DataShareCombinationKvdb0101', 1, async function (done) { + try { + await pubfun.publicinsert(globalThis.helper, uri, Insert).then((data) => { + console.info("TestDataShare going insert = " + data); + }).catch((err) => { + console.info("DataShareCombinationKvdb0101 insert err" + JSON.stringify(err)); + expect(err).assertFail(); + }) + await pubfun.publicupdate(globalThis.helper, uri, EqualTo, Update).then((data) => { + console.info("TestDataShare going update = " + data); + expect(DataProcessResultOne).assertEqual(data); + }).catch((err) => { + console.info("DataShareCombinationKvdb0101 update err" + JSON.stringify(err)); + expect(err).assertFail(); + }) + await pubfun.publicquery(globalThis.helper, uri, EqualTo, ["*"]).then((data) => { + console.info("TestDataShare going query = " + data); + globalThis.ResultSet.goToFirstRow(); + expect(JSON.stringify(ResultSetUpdate)).assertEqual(globalThis.ResultSet.getString(1)); + }).catch((err) => { + console.info("DataShareCombinationKvdb0101 query err" + JSON.stringify(err)); + expect(err).assertFail(); + }) + await pubfun.publicdelete(globalThis.helper, uri, PredicatesDelete0).then((data) => { + console.info("TestDataShare going delete = " + data); + expect(DataProcessResultOne).assertEqual(data); + done(); + }).catch((err) => { + console.info("DataShareCombinationKvdb0101 delete err" + JSON.stringify(err)); + expect(err).assertFail(); + done(); + }) + } catch (err) { + console.info("DataShareCombinationKvdb0101 fail" + JSON.stringify(err)); + expect(err).assertFail(); + done(); + } + }) + + /* + * @tc.number : SUB_DDM_DataShare_ETS_DataShareCombinationKvdb0102 + * @tc.name : Use getEntries get the value by mixing the string key + * @tc.desc : BatchInsert Update Query Delete in Kvdb + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 1 +*/ + it('DataShareCombinationKvdb0102', 1, async function (done) { + try { + await pubfun.publicbatchInsert(globalThis.helper, uri, BatchInsert).then((data) => { + console.info("TestDataShare going batchInsert = " + data); + expect(DataProcessResultOne).assertEqual(data); + }).catch((err) => { + console.info("DataShareCombinationKvdb0102 batchInsert err" + JSON.stringify(err)); + expect(err).assertFail(); + }) + await pubfun.publicupdate(globalThis.helper, uri, EqualTo, Update).then((data) => { + console.info("TestDataShare going update = " + data); + expect(DataProcessResultOne).assertEqual(data); + }).catch((err) => { + console.info("DataShareCombinationKvdb0102 update err" + JSON.stringify(err)); + expect(err).assertFail(); + }) + await pubfun.publicquery(globalThis.helper, uri, EqualTo, ["*"]).then((data) => { + console.info("TestDataShare going query = " + data); + globalThis.ResultSet.goToFirstRow(); + expect(JSON.stringify(ResultSetUpdate)).assertEqual(globalThis.ResultSet.getString(1)); + }).catch((err) => { + console.info("DataShareCombinationKvdb0102 query err" + JSON.stringify(err)); + expect(err).assertFail(); + }) + await pubfun.publicdelete(globalThis.helper, uri, PredicatesDelete0).then((data) => { + console.info("TestDataShare going delete = " + data); + expect(DataProcessResultOne).assertEqual(data); + }).catch((err) => { + console.info("DataShareCombinationKvdb0102 delete err" + JSON.stringify(err)); + expect(err).assertFail(); + }) + await pubfun.publicdelete(globalThis.helper, uri, PredicatesDelete1).then((data) => { + console.info("TestDataShare going delete = " + data); + expect(DataProcessResultOne).assertEqual(data); + done(); + }).catch((err) => { + console.info("DataShareCombinationKvdb0102 delete err" + JSON.stringify(err)); + expect(err).assertFail(); + done(); + }) + } catch (err) { + console.info("DataShareCombinationKvdb0102 fail" + JSON.stringify(err)); + expect(err).assertFail(); + done(); + } + }) + + /* + * @tc.number : SUB_DDM_DataShare_ETS_DataShareCombinationKvdb0104 + * @tc.name : Use getEntries get the value by mixing the string key + * @tc.desc : On on + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 1 +*/ + it('DataShareCombinationKvdb0104', 1, function () { + try { + globalThis.helper.on("dataChange", uri, onChangeNotify); + console.info("TestDataShare going On 1"); + globalThis.helper.on("dataChange", uri, onChangeNotify); + console.info("TestDataShare going On 2"); + } catch (err) { + console.info("DataShareCombinationKvdb0104 fail" + JSON.stringify(err)); + expect(err).assertFail(); + } + }) + + /* + * @tc.number : SUB_DDM_DataShare_ETS_DataShareCombinationKvdb005 + * @tc.name : Use getEntries get the value by mixing the string key + * @tc.desc : Off off + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 1 +*/ + it('DataShareCombinationKvdb0105', 1, function () { + try { + globalThis.helper.on("dataChange", uri, onChangeNotify); + console.info("TestDataShare going On 1"); + globalThis.helper.off("dataChange", uri); + console.info("TestDataShare going Off 1"); + globalThis.helper.off("dataChange", uri); + console.info("TestDataShare going Off 2"); + } catch (err) { + console.info("DataShareCombinationKvdb0105 fail" + JSON.stringify(err)); + expect(err).assertFail(); + } + }) + + /* + * @tc.number : SUB_DDM_DataShare_ETS_DataShareCombinationKvdb0106 + * @tc.name : Use getEntries get the value by mixing the string key + * @tc.desc : BatchInsert Update Query Delete in Kvdb + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 2 +*/ + it('DataShareCombinationKvdb0106', 2, async function (done) { + try { + await pubfun.publicbatchInsert(globalThis.helper, uri, Insert100).then((data) => { + console.info("TestDataShare going batchInsert = " + data); + expect(DataProcessResultOne).assertEqual(data); + }).catch((err) => { + console.info("DataShareCombinationKvdb0106 batchInsert err" + JSON.stringify(err)); + expect(err).assertFail(); + }) + await pubfun.publicupdate(globalThis.helper, uri, EqualTo, Update).then((data) => { + console.info("TestDataShare going update = " + data); + expect(DataProcessResultOne).assertEqual(data); + }).catch((err) => { + console.info("DataShareCombinationKvdb0106 update err" + JSON.stringify(err)); + expect(err).assertFail(); + }) + await pubfun.publicquery(globalThis.helper, uri, EqualTo, ["*"]).then((data) => { + console.info("TestDataShare going query = " + data); + globalThis.ResultSet.goToFirstRow(); + expect(JSON.stringify(ResultSetUpdate)).assertEqual(globalThis.ResultSet.getString(1)); + }).catch((err) => { + console.info("DataShareCombinationKvdb0106 query err" + JSON.stringify(err)); + expect(err).assertFail(); + }) + for (let i = 0; i < 100; i++) { + let PredicatesDelete = new dataSharePredicates.DataSharePredicates(); + PredicatesDelete.inKeys(["testkey" + Delete]); + await pubfun.publicdelete(globalThis.helper, uri, PredicatesDelete).then((data) => { + console.info("TestDataShare going delete " + Delete + "=" + data); + expect(DataProcessResultOne).assertEqual(data); + }) + Delete++; + } + done(); + } catch (err) { + console.info("DataShareCombinationKvdb0106 fail" + JSON.stringify(err)); + expect(err).assertFail(); + done(); + } + }) + + /* + * @tc.number : SUB_DDM_DataShare_ETS_DataShareNotifyChangeKvdb0101 + * @tc.name : Use getEntries get the value by mixing the string key + * @tc.desc : NotifyChange + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 1 +*/ + it('DataShareNotifyChangeKvdb0101', 1, async function (done) { + try { + let Count = 1; + globalThis.helper.on("dataChange", uri, function (err,data) { + if (Count < 4) { + console.info("TestDataShare notifyChange err = " + err); + console.info("TestDataShare notifyChange data = " + data); + expect(true).assertEqual(err == null); + expect(true).assertEqual(data == null); + Count = Count + 1; + } else { + console.info("TestDataShare notifyChange err = " + err); + console.info("TestDataShare notifyChange data = " + data); + expect(true).assertEqual(err == null); + expect(true).assertEqual(data == null); + globalThis.helper.off("dataChange", uri); + console.info("TestDataShare off"); + done(); + } + }) + await pubfun.publicinsert(globalThis.helper, uri, Insert).then((data) => { + console.info("TestDataShare going insert = " + data); + globalThis.helper.notifyChange(uri, notifyChangeCallback); + }).catch((err) => { + console.info("DataShareNotifyChangeKvdb0101 insert err" + JSON.stringify(err)); + expect(err).assertFail(); + }) + await pubfun.publicupdate(globalThis.helper, uri, EqualTo, Update).then((data) => { + console.info("TestDataShare going update = " + data); + globalThis.helper.notifyChange(uri, notifyChangeCallback); + }).catch((err) => { + console.info("DataShareNotifyChangeKvdb0101 update err" + JSON.stringify(err)); + expect(err).assertFail(); + }) + await pubfun.publicquery(globalThis.helper, uri, EqualTo, ["*"]).then((data) => { + console.info("TestDataShare going query = " + data); + globalThis.helper.notifyChange(uri, notifyChangeCallback); + }).catch((err) => { + console.info("DataShareNotifyChangeKvdb0101 query err" + JSON.stringify(err)); + expect(err).assertFail(); + }) + await pubfun.publicdelete(globalThis.helper, uri, PredicatesDelete0).then((data) => { + console.info("TestDataShare going delete = " + data); + globalThis.helper.notifyChange(uri, notifyChangeCallback); + }).catch((err) => { + console.info("DataShareNotifyChangeKvdb0101 delete err" + JSON.stringify(err)); + expect(err).assertFail(); + }) + } catch (err) { + console.info("DataShareNotifyChangeKvdb0101 fail" + JSON.stringify(err)); + expect(err).assertFail(); + done(); + } + }) + + /* + * @tc.number : SUB_DDM_DataShare_ETS_DataShareResultSetKvdb0101 + * @tc.name : Use getEntries get the value by mixing the string key + * @tc.desc : DataShare Supports ResultSet + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 1 +*/ + it('DataShareResultSetKvdb0101', 1, async function (done) { + try { + await pubfun.publicbatchInsert(globalThis.helper, uri, BatchInsert).then((data) => { + console.info("TestDataShare going batchInsert = " + data); + }).catch((err) => { + console.info("DataShareResultSetKvdb0101 batchInsert err" + JSON.stringify(err)); + expect(err).assertFail(); + }) + await pubfun.publicquery(globalThis.helper, uri, ResultSetEqualTo, ["*"]).then((data) => { + console.info("TestDataShare going query = " + data); + expect(true).assertEqual(globalThis.ResultSet.goToFirstRow()); + expect(true).assertEqual(globalThis.ResultSet.goToNextRow()); + expect(true).assertEqual(globalThis.ResultSet.goToLastRow()); + expect(true).assertEqual(globalThis.ResultSet.goToPreviousRow()); + expect(true).assertEqual(globalThis.ResultSet.goTo(column)); + expect(true).assertEqual(globalThis.ResultSet.goToRow(column)); + globalThis.ResultSet.close() + }).catch((err) => { + console.info("DataShareResultSetKvdb0101 query err" + JSON.stringify(err)); + expect(err).assertFail(); + }) + await pubfun.publicdelete(globalThis.helper, uri, PredicatesDelete0).then((data) => { + console.info("TestDataShare going delete0 = " + data); + }).catch((err) => { + console.info("DataShareResultSetKvdb0101 delete0 err" + JSON.stringify(err)); + expect(err).assertFail(); + }) + await pubfun.publicdelete(globalThis.helper, uri, PredicatesDelete1).then((data) => { + console.info("TestDataShare going delete1 = " + data); + done(); + }).catch((err) => { + console.info("DataShareResultSetKvdb0101 delete1 err" + JSON.stringify(err)); + expect(err).assertFail(); + done(); + }) + } catch (err) { + console.info("DataShareResultSetKvdb001 fail" + JSON.stringify(err)); + expect(err).assertFail(); + done(); + } + }) + + /* + * @tc.number : SUB_DDM_DataShare_ETS_DataShareResultSetKvdb0102 + * @tc.name : Use getEntries get the value by mixing the string key + * @tc.desc : DataShare Supports ResultSet + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 1 +*/ + it('DataShareResultSetKvdb0102', 1, async function (done) { + try { + await pubfun.publicquery(globalThis.helper, uri, EqualTo, ["*"]).then((data) => { + console.info("TestDataShare going query = " + data); + expect(false).assertEqual(globalThis.ResultSet.goToFirstRow()); + expect(false).assertEqual(globalThis.ResultSet.goToNextRow()); + expect(false).assertEqual(globalThis.ResultSet.goToLastRow()); + expect(false).assertEqual(globalThis.ResultSet.goToPreviousRow()); + expect(false).assertEqual(globalThis.ResultSet.goTo(column)); + expect(false).assertEqual(globalThis.ResultSet.goToRow(column)); + done(); + }).catch((err) => { + console.info("DataShareResultSetKvdb0102 query err" + JSON.stringify(err)); + expect(err).assertFail(); + done(); + }) + } catch (err) { + console.info("DataShareResultSetKvdb0102 fail" + JSON.stringify(err)); + expect(err).assertFail(); + done(); + } + }) + + /* + * @tc.number : SUB_DDM_DataShare_ETS_DataShareResultSetKvdb0103 + * @tc.name : Use getEntries get the value by mixing the string key + * @tc.desc : DataShare Supports ResultSet + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 1 +*/ + it('DataShareResultSetKvdb0103', 1, async function (done) { + try { + await pubfun.publicinsert(globalThis.helper, uri, Insert).then((data) => { + console.info("TestDataShare going insert = " + data); + }).catch((err) => { + console.info("DataShareResultSetKvdb0103 insert err" + JSON.stringify(err)); + expect(err).assertFail(); + }) + await pubfun.publicquery(globalThis.helper, uri, EqualTo, ["*"]).then((data) => { + console.info("TestDataShare going query = " + data); + globalThis.ResultSet.goToFirstRow(); + expect(JSON.stringify(ResultSetInsert)).assertEqual(globalThis.ResultSet.getString(1)); + expect(DataProcessResultThree).assertEqual(globalThis.ResultSet.getDataType(1)); + }).catch((err) => { + console.info("DataShareResultSetKvdb0103 query err" + JSON.stringify(err)); + expect(err).assertFail(); + }) + await pubfun.publicdelete(globalThis.helper, uri, PredicatesDelete0).then((data) => { + console.info("TestDataShare going deleteall = " + data); + expect(DataProcessResultOne).assertEqual(data); + done(); + }).catch((err) => { + console.info("DataShareResultSetKvdb0103 deleteall err" + JSON.stringify(err)); + expect(err).assertFail(); + done(); + }) + } catch (err) { + console.info("DataShareResultSetKvdb0103 fail" + JSON.stringify(err)); + expect(err).assertFail(); + done(); + } + }) + + /* + * @tc.number : SUB_DDM_DataShare_ETS_DataShareResultSetKvdb0108 + * @tc.name : Use getEntries get the value by mixing the string key + * @tc.desc : DataShare Supports ResultSet + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 1 +*/ + it('DataShareResultSetKvdb0108', 1, async function (done) { + try { + await pubfun.publicinsert(globalThis.helper, uri, Insert).then((data) => { + console.info("TestDataShare going insert = " + data); + }).catch((err) => { + console.info("DataShareResultSetKvdb0108 insert err" + JSON.stringify(err)); + expect(err).assertFail(); + }) + await pubfun.publicquery(globalThis.helper, uri, EqualTo, ["*"]).then((data) => { + console.info("TestDataShare going query = " + data); + globalThis.ResultSet.goToFirstRow(); + expect(DataProcessResultOne).assertEqual(globalThis.ResultSet.getColumnIndex(IndexValue)); + expect(IndexValue).assertEqual(globalThis.ResultSet.getColumnName(DataProcessResultOne)); + }).catch((err) => { + console.info("DataShareResultSetKvdb0108 query err" + JSON.stringify(err)); + expect(err).assertFail(); + }) + await pubfun.publicdelete(globalThis.helper, uri, PredicatesDelete0).then((data) => { + console.info("TestDataShare going deleteall = " + data); + expect(DataProcessResultOne).assertEqual(data); + done(); + }).catch((err) => { + console.info("DataShareResultSetKvdb0108 deleteall err" + JSON.stringify(err)); + expect(err).assertFail(); + done(); + }) + } catch (err) { + console.info("DataShareResultSetKvdb0108 fail" + JSON.stringify(err)); + expect(err).assertFail(); + done(); + } + }) + }) +} \ No newline at end of file diff --git a/distributeddatamgr/dataShare/dataShareKvtest/entry/src/main/ets/test/DataSharePredicatesKvdb.ets b/distributeddatamgr/dataShare/dataShareKvtest/entry/src/main/ets/test/DataSharePredicatesKvdb.ets new file mode 100644 index 0000000000000000000000000000000000000000..63f7e3c675e52adcd7ed3d0721906b163d9b6f32 --- /dev/null +++ b/distributeddatamgr/dataShare/dataShareKvtest/entry/src/main/ets/test/DataSharePredicatesKvdb.ets @@ -0,0 +1,694 @@ +/* +* 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 dataShare from '@ohos.data.dataShare' +import dataSharePredicates from '@ohos.data.dataSharePredicates' +import * as pubfun from './DataSharePublicfunction_Promise' + +//CreateDataShareHelper +let uri = "datashare:///com.samples.datasharekvtest.DataShare"; + +//InsertValuesBucket +let Insert = { "name": "sun", "age": 1, "isStudent": true }; + +//UpdateValuesBucket +let Update = { "name": "sun", "age": 1, "isStudent": false }; + +//Predicates +let EqualTo = new dataSharePredicates.DataSharePredicates(); +EqualTo.equalTo("$.age", 1); +let NotEqualTo = new dataSharePredicates.DataSharePredicates(); +NotEqualTo.notEqualTo("$.age", 2); +let GreaterThan = new dataSharePredicates.DataSharePredicates(); +GreaterThan.greaterThan("$.age", 0); +let LessThan = new dataSharePredicates.DataSharePredicates(); +LessThan.lessThan("$.age", 3); +let GreaterThanOrEqualTo = new dataSharePredicates.DataSharePredicates(); +GreaterThanOrEqualTo.greaterThanOrEqualTo("$.age", 1); +let LessThanOrEqualTo = new dataSharePredicates.DataSharePredicates(); +LessThanOrEqualTo.lessThanOrEqualTo("$.age", 1); +let IsNull = new dataSharePredicates.DataSharePredicates(); +IsNull.isNull("$.age"); +let IsNotNull = new dataSharePredicates.DataSharePredicates(); +IsNotNull.isNotNull("$.age"); +let In = new dataSharePredicates.DataSharePredicates(); +In.in("$.age", [1]); +let NotIn = new dataSharePredicates.DataSharePredicates(); +NotIn.notIn("$.age", [2]); +let Like = new dataSharePredicates.DataSharePredicates(); +Like.like("$.name", "%u%"); +let UnLike = new dataSharePredicates.DataSharePredicates(); +UnLike.unlike("$.name", "%i%"); +let And = new dataSharePredicates.DataSharePredicates(); +And.notEqualTo("$.age", 2).and().equalTo("$.age", 1); +let Or = new dataSharePredicates.DataSharePredicates(); +Or.equalTo("$.isStudent", true).or().equalTo("$.age", 1); +let OrderByAsc = new dataSharePredicates.DataSharePredicates(); +OrderByAsc.orderByAsc("$.age"); +let OrderByDesc = new dataSharePredicates.DataSharePredicates(); +OrderByDesc.orderByDesc("$.age"); +let Limit = new dataSharePredicates.DataSharePredicates(); +Limit.equalTo("$.age", 1).limit(1,0); +let InKeys = new dataSharePredicates.DataSharePredicates(); +InKeys.inKeys(["testkey0"]); +let PrefixKey = new dataSharePredicates.DataSharePredicates(); +PrefixKey.prefixKey("testkey"); +let PredicatesDelete = new dataSharePredicates.DataSharePredicates(); +PredicatesDelete.inKeys(["testkey0"]); + +//Return Expect +const DataProcessResultOne = 1; +const ResultSetUpdate = { "name": "sun", "age": 1, "isStudent": "false" }; +const ResultSetInsert = { "name": "sun", "age": 1, "isStudent": "true" }; + +export default function DataSharePredicatesKvdb() { + describe('DataSharePredicatesKvdb', function () { + function sleep(time) { + return new Promise(resolve => { + setTimeout(() => { + resolve('sleep finished'); + }, time); + }) + } + + beforeAll(async () => { + await globalThis.connectDataShareExtAbility(); + await sleep(2000); + console.info("[ttt] helper = " + globalThis.helper + "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!") + }) + + beforeEach(async function () { + await pubfun.publicinsert(globalThis.helper, uri, Insert).then((data) => { + console.info("TestDataShare going Insert = " + data); + }) + }) + afterEach(async function () { + await pubfun.publicdelete(globalThis.helper, uri, PredicatesDelete).then((data) => { + console.info("TestDataShare going deleteall = " + data); + }) + }) + + /* + * @tc.number : SUB_DDM_DataShare_ETS_DataSharePredicatesKvdb0101 + * @tc.name : Use getEntries get the value by mixing the string key + * @tc.desc : DataShare Supports Predicates + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 1 + */ + it('DataSharePredicatesKvdb0101', 1, async function (done) { + try { + await pubfun.publicupdate(globalThis.helper, uri, EqualTo, Update).then((data) => { + console.info("TestDataShare going update = " + data); + expect(DataProcessResultOne).assertEqual(data); + }).catch((err) => { + console.info("DataSharePredicatesKvdb0101 Update err" + JSON.stringify(err)); + expect(err).assertFail(); + }) + await pubfun.publicquery(globalThis.helper, uri, EqualTo, ["*"]).then((data) => { + console.info("TestDataShare going query = " + data); + globalThis.ResultSet.goToFirstRow(); + expect(JSON.stringify(ResultSetUpdate)).assertEqual(globalThis.ResultSet.getString(1)); + done(); + }).catch((err) => { + console.info("DataSharePredicatesKvdb0101 query err" + JSON.stringify(err)); + expect(err).assertFail(); + done(); + }) + } catch (err) { + console.info("DataSharePredicatesKvdb0101 fail" + JSON.stringify(err)); + expect(err).assertFail(); + done(); + } + }) + + /* + * @tc.number : SUB_DDM_DataShare_ETS_DataSharePredicatesKvdb0102 + * @tc.name : Use getEntries get the value by mixing the string key + * @tc.desc : DataShare Supports Predicates + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 1 + */ + it('DataSharePredicatesKvdb0102', 1, async function (done) { + try { + await pubfun.publicupdate(globalThis.helper, uri, NotEqualTo, Update).then((data) => { + console.info("TestDataShare going update = " + data); + expect(DataProcessResultOne).assertEqual(data); + }).catch((err) => { + console.info("DataSharePredicatesKvdb0102 Update err" + JSON.stringify(err)); + expect(err).assertFail(); + }) + await pubfun.publicquery(globalThis.helper, uri, NotEqualTo, ["*"]).then((data) => { + console.info("TestDataShare going query = " + data); + globalThis.ResultSet.goToFirstRow(); + expect(JSON.stringify(ResultSetUpdate)).assertEqual(globalThis.ResultSet.getString(1)); + done(); + }).catch((err) => { + console.info("DataSharePredicatesKvdb0102 query err" + JSON.stringify(err)); + expect(err).assertFail(); + done(); + }) + } catch (err) { + console.info("DataSharePredicatesKvdb0102 fail" + JSON.stringify(err)); + expect(err).assertFail(); + done(); + } + }) + + /* + * @tc.number : SUB_DDM_DataShare_ETS_DataSharePredicatesKvdb0103 + * @tc.name : Use getEntries get the value by mixing the string key + * @tc.desc : DataShare Supports Predicates + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 1 + */ + it('DataSharePredicatesKvdb0103', 1, async function (done) { + try { + await pubfun.publicupdate(globalThis.helper, uri, GreaterThan, Update).then((data) => { + console.info("TestDataShare going update = " + data); + expect(DataProcessResultOne).assertEqual(data); + }).catch((err) => { + console.info("DataSharePredicatesKvdb0103 Update err" + JSON.stringify(err)); + expect(err).assertFail(); + }) + await pubfun.publicquery(globalThis.helper, uri, GreaterThan, ["*"]).then((data) => { + console.info("TestDataShare going query = " + data); + globalThis.ResultSet.goToFirstRow(); + expect(JSON.stringify(ResultSetUpdate)).assertEqual(globalThis.ResultSet.getString(1)); + done(); + }).catch((err) => { + console.info("DataSharePredicatesKvdb0103 query err" + JSON.stringify(err)); + expect(err).assertFail(); + done(); + }) + } catch (err) { + console.info("DataSharePredicatesKvdb0103 fail" + JSON.stringify(err)); + expect(err).assertFail(); + done(); + } + }) + + /* + * @tc.number : SUB_DDM_DataShare_ETS_DataSharePredicatesKvdb0104 + * @tc.name : Use getEntries get the value by mixing the string key + * @tc.desc : DataShare Supports Predicates + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 1 + */ + it('DataSharePredicatesKvdb0104', 1, async function (done) { + try { + await pubfun.publicupdate(globalThis.helper, uri, LessThan, Update).then((data) => { + console.info("TestDataShare going update = " + data); + expect(DataProcessResultOne).assertEqual(data); + }).catch((err) => { + console.info("DataSharePredicatesKvdb0104 Update err" + JSON.stringify(err)); + expect(err).assertFail(); + }) + await pubfun.publicquery(globalThis.helper, uri, LessThan, ["*"]).then((data) => { + console.info("TestDataShare going query = " + data); + globalThis.ResultSet.goToFirstRow(); + expect(JSON.stringify(ResultSetUpdate)).assertEqual(globalThis.ResultSet.getString(1)); + done(); + }).catch((err) => { + console.info("DataSharePredicatesKvdb0104 query err" + JSON.stringify(err)); + expect(err).assertFail(); + done(); + }) + } catch (err) { + console.info("DataSharePredicatesKvdb0104 fail" + JSON.stringify(err)); + expect(err).assertFail(); + done(); + } + }) + + /* + * @tc.number : SUB_DDM_DataShare_ETS_DataSharePredicatesKvdb0105 + * @tc.name : Use getEntries get the value by mixing the string key + * @tc.desc : DataShare Supports Predicates + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 1 + */ + it('DataSharePredicatesKvdb0105', 1, async function (done) { + try { + await pubfun.publicupdate(globalThis.helper, uri, GreaterThanOrEqualTo, Update).then((data) => { + console.info("TestDataShare going update = " + data); + expect(DataProcessResultOne).assertEqual(data); + }).catch((err) => { + console.info("DataSharePredicatesKvdb0105 Update err" + JSON.stringify(err)); + expect(err).assertFail(); + }) + await pubfun.publicquery(globalThis.helper, uri, GreaterThanOrEqualTo, ["*"]).then((data) => { + console.info("TestDataShare going query = " + data); + globalThis.ResultSet.goToFirstRow(); + expect(JSON.stringify(ResultSetUpdate)).assertEqual(globalThis.ResultSet.getString(1)); + done(); + }).catch((err) => { + console.info("DataSharePredicatesKvdb0105 query err" + JSON.stringify(err)); + expect(err).assertFail(); + done(); + }) + } catch (err) { + console.info("DataSharePredicatesKvdb0105 fail" + JSON.stringify(err)); + expect(err).assertFail(); + done(); + } + }) + + /* + * @tc.number : SUB_DDM_DataShare_ETS_DataSharePredicatesKvdb0106 + * @tc.name : Use getEntries get the value by mixing the string key + * @tc.desc : DataShare Supports Predicates + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 1 + */ + it('DataSharePredicatesKvdb0106', 1, async function (done) { + try { + await pubfun.publicupdate(globalThis.helper, uri, LessThanOrEqualTo, Update).then((data) => { + console.info("TestDataShare going update = " + data); + expect(DataProcessResultOne).assertEqual(data); + }).catch((err) => { + console.info("DataSharePredicatesKvdb0106 Update err" + JSON.stringify(err)); + expect(err).assertFail(); + }) + await pubfun.publicquery(globalThis.helper, uri, LessThanOrEqualTo, ["*"]).then((data) => { + console.info("TestDataShare going query = " + data); + globalThis.ResultSet.goToFirstRow(); + expect(JSON.stringify(ResultSetUpdate)).assertEqual(globalThis.ResultSet.getString(1)); + done(); + }).catch((err) => { + console.info("DataSharePredicatesKvdb0106 query err" + JSON.stringify(err)); + expect(err).assertFail(); + done(); + }) + } catch (err) { + console.info("DataSharePredicatesKvdb006 fail" + JSON.stringify(err)); + expect(err).assertFail(); + done(); + } + }) + + /* + * @tc.number : SUB_DDM_DataShare_ETS_DataSharePredicatesKvdb0107 + * @tc.name : Use getEntries get the value by mixing the string key + * @tc.desc : DataShare Supports Predicates + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 1 + */ + it('DataSharePredicatesKvdb0107', 1, async function (done) { + try { + await pubfun.publicquery(globalThis.helper, uri, IsNull, ["*"]).then((data) => { + console.info("TestDataShare going query = " + data); + expect(false).assertEqual(globalThis.ResultSet.goToLastRow()); + done(); + }).catch((err) => { + console.info("DataSharePredicatesKvdb0107 query err" + JSON.stringify(err)); + expect(err).assertFail(); + done(); + }) + } catch (err) { + console.info("DataSharePredicatesKvdb0107 fail" + JSON.stringify(err)); + expect(err).assertFail(); + done(); + } + }) + + /* + * @tc.number : SUB_DDM_DataShare_ETS_DataSharePredicatesKvdb0108 + * @tc.name : Use getEntries get the value by mixing the string key + * @tc.desc : DataShare Supports Predicates + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 1 + */ + it('DataSharePredicatesKvdb0108', 1, async function (done) { + try { + await pubfun.publicupdate(globalThis.helper, uri, IsNotNull, Update).then((data) => { + console.info("TestDataShare going update = " + data); + expect(DataProcessResultOne).assertEqual(data); + }).catch((err) => { + console.info("DataSharePredicatesKvdb0108 Update err" + JSON.stringify(err)); + expect(err).assertFail(); + }) + await pubfun.publicquery(globalThis.helper, uri, IsNotNull, ["*"]).then((data) => { + console.info("TestDataShare going query = " + data); + globalThis.ResultSet.goToFirstRow(); + expect(JSON.stringify(ResultSetUpdate)).assertEqual(globalThis.ResultSet.getString(1)); + done(); + }).catch((err) => { + console.info("DataSharePredicatesKvdb0108 query err" + JSON.stringify(err)); + expect(err).assertFail(); + done(); + }) + } catch (err) { + console.info("DataSharePredicatesKvdb0108 fail" + JSON.stringify(err)); + expect(err).assertFail(); + done(); + } + }) + + /* + * @tc.number : SUB_DDM_DataShare_ETS_DataSharePredicatesKvdb0109 + * @tc.name : Use getEntries get the value by mixing the string key + * @tc.desc : DataShare Supports Predicates + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 1 + */ + it('DataSharePredicatesKvdb0109', 1, async function (done) { + try { + await pubfun.publicupdate(globalThis.helper, uri, In, Update).then((data) => { + console.info("TestDataShare going update = " + data); + expect(DataProcessResultOne).assertEqual(data); + }).catch((err) => { + console.info("DataSharePredicatesKvdb0109 Update err" + JSON.stringify(err)); + expect(err).assertFail(); + }) + await pubfun.publicquery(globalThis.helper, uri, In, ["*"]).then((data) => { + console.info("TestDataShare going query = " + data); + globalThis.ResultSet.goToFirstRow(); + expect(JSON.stringify(ResultSetUpdate)).assertEqual(globalThis.ResultSet.getString(1)); + done(); + }).catch((err) => { + console.info("DataSharePredicatesKvdb0109 query err" + JSON.stringify(err)); + expect(err).assertFail(); + done(); + }) + } catch (err) { + console.info("DataSharePredicatesKvdb0109 fail" + JSON.stringify(err)); + expect(err).assertFail(); + done(); + } + }) + + /* + * @tc.number : SUB_DDM_DataShare_ETS_DataSharePredicatesKvdb0110 + * @tc.name : Use getEntries get the value by mixing the string key + * @tc.desc : DataShare Supports Predicates + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 1 + */ + it('DataSharePredicatesKvdb0110', 1, async function (done) { + try { + await pubfun.publicupdate(globalThis.helper, uri, NotIn, Update).then((data) => { + console.info("TestDataShare going update = " + data); + expect(DataProcessResultOne).assertEqual(data); + }).catch((err) => { + console.info("DataSharePredicatesKvdb0110 Update err" + JSON.stringify(err)); + expect(err).assertFail(); + }) + await pubfun.publicquery(globalThis.helper, uri, NotIn, ["*"]).then((data) => { + console.info("TestDataShare going query = " + data); + globalThis.ResultSet.goToFirstRow(); + expect(JSON.stringify(ResultSetUpdate)).assertEqual(globalThis.ResultSet.getString(1)); + done(); + }).catch((err) => { + console.info("DataSharePredicatesKvdb0110 query err" + JSON.stringify(err)); + expect(err).assertFail(); + done(); + }) + } catch (err) { + console.info("DataSharePredicatesKvdb0110 fail" + JSON.stringify(err)); + expect(err).assertFail(); + done(); + } + }) + + /* + * @tc.number : SUB_DDM_DataShare_ETS_DataSharePredicatesKvdb0111 + * @tc.name : Use getEntries get the value by mixing the string key + * @tc.desc : DataShare Supports Predicates + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 1 + */ + it('DataSharePredicatesKvdb0111', 1, async function (done) { + try { + await pubfun.publicupdate(globalThis.helper, uri, Like, Update).then((data) => { + console.info("TestDataShare going update = " + data); + expect(DataProcessResultOne).assertEqual(data); + }).catch((err) => { + console.info("DataSharePredicatesKvdb0111 Update err" + JSON.stringify(err)); + expect(err).assertFail(); + }) + await pubfun.publicquery(globalThis.helper, uri, Like, ["*"]).then((data) => { + console.info("TestDataShare going query = " + data); + globalThis.ResultSet.goToFirstRow(); + expect(JSON.stringify(ResultSetUpdate)).assertEqual(globalThis.ResultSet.getString(1)); + done(); + }).catch((err) => { + console.info("DataSharePredicatesKvdb0111 query err" + JSON.stringify(err)); + expect(err).assertFail(); + done(); + }) + } catch (err) { + console.info("DataSharePredicatesKvdb0111 fail" + JSON.stringify(err)); + expect(err).assertFail(); + done(); + } + }) + + /* + * @tc.number : SUB_DDM_DataShare_ETS_DataSharePredicatesKvdb0112 + * @tc.name : Use getEntries get the value by mixing the string key + * @tc.desc : DataShare Supports Predicates + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 1 + */ + it('DataSharePredicatesKvdb0112', 1, async function (done) { + try { + await pubfun.publicupdate(globalThis.helper, uri, UnLike, Update).then((data) => { + console.info("TestDataShare going update = " + data); + expect(DataProcessResultOne).assertEqual(data); + }).catch((err) => { + console.info("DataSharePredicatesKvdb0112 Update err" + JSON.stringify(err)); + expect(err).assertFail(); + }) + await pubfun.publicquery(globalThis.helper, uri, Like, ["*"]).then((data) => { + console.info("TestDataShare going query = " + data); + globalThis.ResultSet.goToFirstRow(); + expect(JSON.stringify(ResultSetUpdate)).assertEqual(globalThis.ResultSet.getString(1)); + done(); + }).catch((err) => { + console.info("DataSharePredicatesKvdb0112 query err" + JSON.stringify(err)); + expect(err).assertFail(); + done(); + }) + } catch (err) { + console.info("DataSharePredicatesKvdb0112 fail" + JSON.stringify(err)); + expect(err).assertFail(); + done(); + } + }) + + /* + * @tc.number : SUB_DDM_DataShare_ETS_DataSharePredicatesKvdb0113 + * @tc.name : Use getEntries get the value by mixing the string key + * @tc.desc : DataShare Supports Predicates + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 1 + */ + it('DataSharePredicatesKvdb0113', 1, async function (done) { + try { + await pubfun.publicupdate(globalThis.helper, uri, And, Update).then((data) => { + console.info("TestDataShare going update = " + data); + expect(DataProcessResultOne).assertEqual(data); + }).catch((err) => { + console.info("DataSharePredicatesKvdb0113 Update err" + JSON.stringify(err)); + expect(err).assertFail(); + }) + await pubfun.publicquery(globalThis.helper, uri, And, ["*"]).then((data) => { + console.info("TestDataShare going query = " + data); + globalThis.ResultSet.goToFirstRow(); + expect(JSON.stringify(ResultSetUpdate)).assertEqual(globalThis.ResultSet.getString(1)); + done(); + }).catch((err) => { + console.info("DataSharePredicatesKvdb0113 query err" + JSON.stringify(err)); + expect(err).assertFail(); + done(); + }) + } catch (err) { + console.info("DataSharePredicatesKvdb0113 fail" + JSON.stringify(err)); + expect(err).assertFail(); + done(); + } + }) + + /* + * @tc.number : SUB_DDM_DataShare_ETS_DataSharePredicatesKvdb0114 + * @tc.name : Use getEntries get the value by mixing the string key + * @tc.desc : DataShare Supports Predicates + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 1 + */ + it('DataSharePredicatesKvdb0114', 0, async function (done) { + try { + await pubfun.publicupdate(globalThis.helper, uri, Or, Update).then((data) => { + console.info("TestDataShare going update = " + data); + expect(DataProcessResultOne).assertEqual(data); + }).catch((err) => { + console.info("DataSharePredicatesKvdb0114 Update err" + JSON.stringify(err)); + expect(err).assertFail(); + }) + await pubfun.publicquery(globalThis.helper, uri, Or, ["*"]).then((data) => { + console.info("TestDataShare going query = " + data); + globalThis.ResultSet.goToFirstRow(); + expect(JSON.stringify(ResultSetUpdate)).assertEqual(globalThis.ResultSet.getString(1)); + done(); + }).catch((err) => { + console.info("DataSharePredicatesKvdb0114 query err" + JSON.stringify(err)); + expect(err).assertFail(); + done(); + }) + } catch (err) { + console.info("DataSharePredicatesKvdb0114 fail" + JSON.stringify(err)); + expect(err).assertFail(); + done(); + } + }) + + /* + * @tc.number : SUB_DDM_DataShare_ETS_DataSharePredicatesKvdb0115 + * @tc.name : Use getEntries get the value by mixing the string key + * @tc.desc : DataShare Supports Predicates + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 1 + */ + it('DataSharePredicatesKvdb0115', 1, async function (done) { + try { + await pubfun.publicquery(globalThis.helper, uri, OrderByAsc, ["*"]).then((data) => { + console.info("TestDataShare going query = " + data); + globalThis.ResultSet.goToFirstRow(); + expect(JSON.stringify(ResultSetInsert)).assertEqual(globalThis.ResultSet.getString(1)); + done(); + }).catch((err) => { + console.info("DataSharePredicatesKvdb0115 query err" + JSON.stringify(err)); + expect(err).assertFail(); + done(); + }) + } catch (err) { + console.info("DataSharePredicatesKvdb0115 fail" + JSON.stringify(err)); + expect(err).assertFail(); + done(); + } + }) + + /* + * @tc.number : SUB_DDM_DataShare_ETS_DataSharePredicatesKvdb0116 + * @tc.name : Use getEntries get the value by mixing the string key + * @tc.desc : DataShare Supports Predicates + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 1 + */ + it('DataSharePredicatesKvdb0116', 1, async function (done) { + try { + await pubfun.publicquery(globalThis.helper, uri, OrderByAsc, ["*"]).then((data) => { + console.info("TestDataShare going query = " + data); + globalThis.ResultSet.goToFirstRow(); + expect(JSON.stringify(ResultSetInsert)).assertEqual(globalThis.ResultSet.getString(1)); + done(); + }).catch((err) => { + console.info("DataSharePredicatesKvdb0116 query err" + JSON.stringify(err)); + expect(err).assertFail(); + done(); + }) + } catch (err) { + console.info("DataSharePredicatesKvdb0116 fail" + JSON.stringify(err)); + expect(err).assertFail(); + done(); + } + }) + + /* + * @tc.number : SUB_DDM_DataShare_ETS_DataSharePredicatesKvdb0118 + * @tc.name : Use getEntries get the value by mixing the string key + * @tc.desc : DataShare Supports Predicates + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 1 + */ + it('DataSharePredicatesKvdb0118', 0, async function (done) { + try { + await pubfun.publicupdate(globalThis.helper, uri, InKeys, Update).then((data) => { + console.info("TestDataShare going update = " + data); + expect(DataProcessResultOne).assertEqual(data); + }).catch((err) => { + console.info("DataSharePredicatesKvdb0118 Update err" + JSON.stringify(err)); + expect(err).assertFail(); + }) + await pubfun.publicquery(globalThis.helper, uri, InKeys, ["*"]).then((data) => { + console.info("TestDataShare going query = " + data); + globalThis.ResultSet.goToFirstRow(); + expect(JSON.stringify(ResultSetUpdate)).assertEqual(globalThis.ResultSet.getString(1)); + done(); + }).catch((err) => { + console.info("DataSharePredicatesKvdb0118 query err" + JSON.stringify(err)); + expect(err).assertFail(); + done(); + }) + } catch (err) { + console.info("DataSharePredicatesKvdb0118 fail" + JSON.stringify(err)); + expect(err).assertFail(); + done(); + } + }) + + /* + * @tc.number : SUB_DDM_DataShare_ETS_DataSharePredicatesKvdb0119 + * @tc.name : Use getEntries get the value by mixing the string key + * @tc.desc : DataShare Supports Predicates + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 1 + */ + it('DataSharePredicatesKvdb0119', 0, async function (done) { + try { + await pubfun.publicupdate(globalThis.helper, uri, PrefixKey, Update).then((data) => { + console.info("TestDataShare going update = " + data); + expect(DataProcessResultOne).assertEqual(data); + }).catch((err) => { + console.info("DataSharePredicatesKvdb0118 Update err" + JSON.stringify(err)); + expect(err).assertFail(); + }) + await pubfun.publicquery(globalThis.helper, uri, PrefixKey, ["*"]).then((data) => { + console.info("TestDataShare going query = " + data); + globalThis.ResultSet.goToFirstRow(); + expect(JSON.stringify(ResultSetUpdate)).assertEqual(globalThis.ResultSet.getString(1)); + done(); + }).catch((err) => { + console.info("DataSharePredicatesKvdb0119 query err" + JSON.stringify(err)); + expect(err).assertFail(); + done(); + }) + } catch (err) { + console.info("DataSharePredicatesKvdb0119 fail" + JSON.stringify(err)); + expect(err).assertFail(); + done(); + } + }) + }) +} \ No newline at end of file diff --git a/distributeddatamgr/windowStage/dataShareRdbtest/entry/src/main/ets/test/DataSharePublicfunction_Callback.ets b/distributeddatamgr/dataShare/dataShareKvtest/entry/src/main/ets/test/DataSharePublicfunction_Callback.ets similarity index 100% rename from distributeddatamgr/windowStage/dataShareRdbtest/entry/src/main/ets/test/DataSharePublicfunction_Callback.ets rename to distributeddatamgr/dataShare/dataShareKvtest/entry/src/main/ets/test/DataSharePublicfunction_Callback.ets diff --git a/distributeddatamgr/windowStage/dataShareRdbtest/entry/src/main/ets/test/DataSharePublicfunction_Promise.ets b/distributeddatamgr/dataShare/dataShareKvtest/entry/src/main/ets/test/DataSharePublicfunction_Promise.ets similarity index 100% rename from distributeddatamgr/windowStage/dataShareRdbtest/entry/src/main/ets/test/DataSharePublicfunction_Promise.ets rename to distributeddatamgr/dataShare/dataShareKvtest/entry/src/main/ets/test/DataSharePublicfunction_Promise.ets diff --git a/distributeddatamgr/dataShare/dataShareKvtest/entry/src/main/ets/test/DataShareSingleKvdb_Callback.ets b/distributeddatamgr/dataShare/dataShareKvtest/entry/src/main/ets/test/DataShareSingleKvdb_Callback.ets new file mode 100644 index 0000000000000000000000000000000000000000..40c14342360d5cf7020d076655267ebf2e916943 --- /dev/null +++ b/distributeddatamgr/dataShare/dataShareKvtest/entry/src/main/ets/test/DataShareSingleKvdb_Callback.ets @@ -0,0 +1,557 @@ +/* +* 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 dataShare from '@ohos.data.dataShare' +import dataSharePredicates from '@ohos.data.dataSharePredicates' +import * as pubfun from './DataSharePublicfunction_Callback' + +//CreateDataShareHelper +let uri = ("datashare:///com.samples.datasharekvtest.DataShare"); + +//InsertValuesBucket +let Insert = { "name": "sun", "age": 1, "isStudent": true }; +let BatchInsert = new Array( + { "name": "sun", "age": 1, "isStudent": true }, + { "name": "sunn", "age": 10, "isStudent": false }); + +//UpdateValuesBucket +let Update = { "name": "suns", "age": 2, "isStudent": false }; + +//Predicates +let EqualTo = new dataSharePredicates.DataSharePredicates(); +EqualTo.equalTo("$.age", 1); +let PredicatesDelete0 = new dataSharePredicates.DataSharePredicates(); +PredicatesDelete0.inKeys(["testkey0"]); +let PredicatesDelete1 = new dataSharePredicates.DataSharePredicates(); +PredicatesDelete1.inKeys(["testkey1"]); + +//Return Expect +const DataProcessResultOne = 1; +const GetType = "image"; +const GetFileTypes = new Array("type01", "type02", "type03"); +const Normalize = "normalize+" + uri; +const Denormalize = "denormalize+" + uri; +const ResultSetInsert = { "name": "sun", "age": 1, "isStudent": "true" }; +const Mode = "rwt"; + +function onChangeNotify() { + console.info("===>onChangeNotify===>"); +}; + +export default function DataShareSingleKvdb_Callback() { + describe('DataShareSingleKvdb_Callback', function () { + function sleep(time) { + return new Promise(resolve => { + setTimeout(() => { + resolve('sleep finished'); + }, time); + }) + } + + beforeAll(async () => { + await globalThis.connectDataShareExtAbility(); + await sleep(2000); + console.info("[ttt] helper = " + globalThis.helper + "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!") + }) + + /* + * @tc.number : SUB_DDM_DataShare_ETS_DataShareInsertKvdb0101 + * @tc.name : Use getEntries get the value by mixing the string key + * @tc.desc : Insert All type data in Kvdb + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 0 + */ + it('DataShareInsertKvdb0101', 0, async function (done) { + try { + await pubfun.publicinsert(globalThis.helper, uri, Insert).then((data) => { + console.info("TestDataShare going insert = " + data); + expect(DataProcessResultOne).assertEqual(data); + }).catch((err) => { + console.info("DataShareInsertKvdb0101 fail err " + JSON.stringify(err)); + expect(err).assertFail(); + }) + await pubfun.publicdelete(globalThis.helper, uri, PredicatesDelete0).then((data) => { + console.info("TestDataShare going delete = " + data); + expect(DataProcessResultOne).assertEqual(data); + done(); + }) + } catch (err) { + console.info("DataShareInsertKvdb0101 fail " + JSON.stringify(err)); + expect(err).assertFail(); + done(); + } + }) + + /* + * @tc.number : SUB_DDM_DataShare_ETS_DataShareUpdateKvdb0101 + * @tc.name : Use getEntries get the value by mixing the string key + * @tc.desc : Update All type data in Kvdb + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 0 + */ + it('DataShareUpdateKvdb0101', 0, async function (done) { + try { + await pubfun.publicinsert(globalThis.helper, uri, Insert).then((data) => { + console.info("TestDataShare going insert = " + data); + expect(DataProcessResultOne).assertEqual(data); + }) + await pubfun.publicupdate(globalThis.helper, uri, EqualTo, Update).then((data) => { + console.info("TestDataShare going update = " + data); + expect(DataProcessResultOne).assertEqual(data); + }).catch((err) => { + console.info("DataShareUpdateKvdb0101 err " + JSON.stringify(err)); + expect(err).assertFail(); + }) + await pubfun.publicdelete(globalThis.helper, uri, PredicatesDelete0).then((data) => { + console.info("TestDataShare going delete = " + data); + expect(DataProcessResultOne).assertEqual(data); + done(); + }) + } catch (err) { + console.info("DataShareUpdateKvdb0101 fail " + JSON.stringify(err)); + expect(err).assertFail(); + done(); + } + }) + + /* + * @tc.number : SUB_DDM_DataShare_ETS_DataShareQueryKvdb0101 + * @tc.name : Use getEntries get the value by mixing the string key + * @tc.desc : Query All type data in Kvdb + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 0 + */ + it('DataShareQueryKvdb0101', 0, async function (done) { + try { + await pubfun.publicinsert(globalThis.helper, uri, Insert).then((data) => { + console.info("TestDataShare going insert = " + data); + expect(DataProcessResultOne).assertEqual(data); + }) + await pubfun.publicquery(globalThis.helper, uri, EqualTo, ["*"]).then((data) => { + console.info("TestDataShare going query = " + data); + globalThis.ResultSet.goToFirstRow(); + expect(JSON.stringify(ResultSetInsert)).assertEqual(globalThis.ResultSet.getString(1)); + }).catch((err) => { + console.info("DataShareQueryKvdb0101 err " + JSON.stringify(err)); + expect(err).assertFail(); + }) + await pubfun.publicdelete(globalThis.helper, uri, PredicatesDelete0).then((data) => { + console.info("TestDataShare going delete = " + data); + expect(DataProcessResultOne).assertEqual(data); + done(); + }) + } catch (err) { + console.info("DataShareQueryKvdb0101 fail " + JSON.stringify(err)); + expect(err).assertFail(); + done(); + } + }) + + /* + * @tc.number : SUB_DDM_DataShare_ETS_DataShareDeleteKvdb0101 + * @tc.name : Use getEntries get the value by mixing the string key + * @tc.desc : Delete number type data in Kvdb + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 0 + */ + it('DataShareDeleteKvdb0101', 0, async function (done) { + try { + await pubfun.publicinsert(globalThis.helper, uri, Insert).then((data) => { + console.info("TestDataShare going insert = " + data); + expect(DataProcessResultOne).assertEqual(data); + }) + await pubfun.publicdelete(globalThis.helper, uri, PredicatesDelete0).then((data) => { + console.info("TestDataShare going delete = " + data); + expect(DataProcessResultOne).assertEqual(data); + done(); + }).catch((err) => { + console.info("DataShareDeleteKvdb0101 err " + JSON.stringify(err)); + expect(err).assertFail(); + done(); + }) + } catch (err) { + console.info("DataShareDeleteKvdb0101 fail " + JSON.stringify(err)); + expect(err).assertFail(); + done(); + } + }) + + /* + * @tc.number : SUB_DDM_DataShare_ETS_DataShareBatchKvdb0101 + * @tc.name : Use getEntries get the value by mixing the string key + * @tc.desc : BatchInsert data in Kvdb + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 0 + */ + it('DataShareBatchKvdb0101', 0, async function (done) { + try { + await pubfun.publicbatchInsert(globalThis.helper, uri, BatchInsert).then((data) => { + console.info("TestDataShare going batchInsert = " + data); + expect(DataProcessResultOne).assertEqual(data); + }).catch((err) => { + console.info("DataSharebatchKvdb001 err " + JSON.stringify(err)); + expect(err).assertFail(); + }) + await pubfun.publicdelete(globalThis.helper, uri, PredicatesDelete0).then((data) => { + console.info("TestDataShare going delete 0 = " + data); + expect(DataProcessResultOne).assertEqual(data); + }) + await pubfun.publicdelete(globalThis.helper, uri, PredicatesDelete1).then((data) => { + console.info("TestDataShare going delete 1 = " + data); + expect(DataProcessResultOne).assertEqual(data); + done(); + }) + } catch (err) { + console.info("DataSharebatchKvdb001 fail " + JSON.stringify(err)); + expect(err).assertFail(); + done(); + } + }) + + /* + * @tc.number : SUB_DDM_DataShare_ETS_DataShareBatchKvdb0102 + * @tc.name : Use getEntries get the value by mixing the string key + * @tc.desc : Update data in Kvdb + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 0 + */ + it('DataShareBatchKvdb0102', 0, async function (done) { + try { + await pubfun.publicbatchInsert(globalThis.helper, uri, BatchInsert).then((data) => { + console.info("TestDataShare going batchInsert = " + data); + expect(DataProcessResultOne).assertEqual(data); + }) + await pubfun.publicupdate(globalThis.helper, uri, EqualTo, Update).then((data) => { + console.info("TestDataShare going update = " + data); + expect(DataProcessResultOne).assertEqual(data); + }).catch((err) => { + console.info("DataShareBatchKvdb0102 err " + JSON.stringify(err)); + expect(err).assertFail(); + }) + await pubfun.publicdelete(globalThis.helper, uri, PredicatesDelete0).then((data) => { + console.info("TestDataShare going delete 0 = " + data); + expect(DataProcessResultOne).assertEqual(data); + }) + await pubfun.publicdelete(globalThis.helper, uri, PredicatesDelete1).then((data) => { + console.info("TestDataShare going delete 1 = " + data); + expect(DataProcessResultOne).assertEqual(data); + done(); + }) + } catch (err) { + console.info("DataShareBatchKvdb0102 fail " + JSON.stringify(err)); + expect(err).assertFail(); + done(); + } + }) + + /* + * @tc.number : SUB_DDM_DataShare_ETS_DataShareBatchKvdb0103 + * @tc.name : Use getEntries get the value by mixing the string key + * @tc.desc : Query data in Kvdb + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 0 + */ + it('DataShareBatchKvdb0103', 0, async function (done) { + try { + await pubfun.publicbatchInsert(globalThis.helper, uri, BatchInsert).then((data) => { + console.info("TestDataShare going batchInsert = " + data); + expect(DataProcessResultOne).assertEqual(data); + }) + await pubfun.publicquery(globalThis.helper, uri, EqualTo, ["*"]).then((data) => { + console.info("TestDataShare going query = " + data); + globalThis.ResultSet.goToFirstRow(); + expect(JSON.stringify(ResultSetInsert)).assertEqual(globalThis.ResultSet.getString(1)); + }).catch((err) => { + console.info("DataShareBatchKvdb003 err " + JSON.stringify(err)); + expect(err).assertFail(); + }) + await pubfun.publicdelete(globalThis.helper, uri, PredicatesDelete0).then((data) => { + console.info("TestDataShare going delete 0 = " + data); + expect(DataProcessResultOne).assertEqual(data); + }) + await pubfun.publicdelete(globalThis.helper, uri, PredicatesDelete1).then((data) => { + console.info("TestDataShare going delete 1 = " + data); + expect(DataProcessResultOne).assertEqual(data); + done(); + }) + } catch (err) { + console.info("DataShareBatchKvdb003 fail " + JSON.stringify(err)); + expect(err).assertFail(); + done(); + } + }) + + /* + * @tc.number : SUB_DDM_DataShare_ETS_DataShareBatchKvdb0104 + * @tc.name : Use getEntries get the value by mixing the string key + * @tc.desc : Delete data in Kvdb + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 0 + */ + it('DataShareBatchKvdb0104', 0, async function (done) { + try { + await pubfun.publicbatchInsert(globalThis.helper, uri, BatchInsert).then((data) => { + console.info("TestDataShare going batchInsert = " + data); + expect(DataProcessResultOne).assertEqual(data); + }) + await pubfun.publicdelete(globalThis.helper, uri, PredicatesDelete0).then((data) => { + console.info("TestDataShare going delete 0 = " + data); + expect(DataProcessResultOne).assertEqual(data); + }).catch((err) => { + console.info("DataShareBatchKvdb0104 delete 0 err " + JSON.stringify(err)); + expect(err).assertFail(); + }) + await pubfun.publicdelete(globalThis.helper, uri, PredicatesDelete1).then((data) => { + console.info("TestDataShare going delete 1 = " + data); + expect(DataProcessResultOne).assertEqual(data); + done(); + }).catch((err) => { + console.info("DataShareBatchKvdb0104 delete 1 err " + JSON.stringify(err)); + expect(err).assertFail(); + done(); + }) + } catch (err) { + console.info("DataShareBatchKvdb0104 fail " + JSON.stringify(err)); + expect(err).assertFail(); + done(); + } + }) + + /* + * @tc.number : SUB_DDM_DataShare_ETS_DataShareGetType0101 + * @tc.name : Use getEntries get the value by mixing the string key + * @tc.desc : Support GetType function + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 0 + */ + it('DataShareGetType0101', 0, async function (done) { + try { + await pubfun.publicgetType(globalThis.helper, uri).then((data) => { + console.info("TestDataShare going getType = " + data); + expect(GetType).assertEqual(data); + done(); + }).catch((err) => { + console.info("DataShareGetType0101 err " + JSON.stringify(err)); + expect(err).assertFail(); + done(); + }) + } catch (err) { + console.info("DataShareGetType0101 fail " + JSON.stringify(err)); + expect(err).assertFail(); + done(); + } + }) + + /* + * @tc.number : SUB_DDM_DataShare_ETS_DataShareGetFileTypes0101 + * @tc.name : Use getEntries get the value by mixing the string key + * @tc.desc : Support GetFileTypes function + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 0 + */ + it('DataShareGetFileTypes0101', 0, async function (done) { + try { + await pubfun.publicgetFileTypes(globalThis.helper, uri, "image/*").then((data) => { + console.info("TestDataShare going getFileTypes = " + data); + expect(JSON.stringify(GetFileTypes)).assertEqual(JSON.stringify(data)); + done(); + }).catch((err) => { + console.info("DataShareGetFileTypes0101 err " + JSON.stringify(err)); + expect(err).assertFail(); + done(); + }) + } catch (err) { + console.info("DataShareGetFileTypes0101 fail " + JSON.stringify(err)); + expect(err).assertFail(); + done(); + } + }) + + /* + * @tc.number : SUB_DDM_DataShare_ETS_DataShareNormalizeUri0101 + * @tc.name : Use getEntries get the value by mixing the string key + * @tc.desc : Support NormalizeUri function + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 0 + */ + it('DataShareNormalizeUri0101', 0, async function (done) { + try { + await pubfun.publicnormalizeUri(globalThis.helper, uri).then((data) => { + console.info("TestDataShare going NormalizeUri = " + data); + expect(Normalize).assertEqual(data); + done(); + }).catch((err) => { + console.info("DataShareNormalizeUri0101 err " + JSON.stringify(err)); + expect(err).assertFail(); + done(); + }) + } catch (err) { + console.info("DataShareNormalizeUri0101 fail " + JSON.stringify(err)); + expect(err).assertFail(); + done(); + } + }) + + /* + * @tc.number : SUB_DDM_DataShare_ETS_DataShareDenormalizeUri0101 + * @tc.name : Use getEntries get the value by mixing the string key + * @tc.desc : Support DenormalizeUri function + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 0 + */ + it('DataShareDenormalizeUri0101', 0, async function (done) { + try { + await pubfun.publicdenormalizeUri(globalThis.helper, uri).then((data) => { + console.info("TestDataShare going denormalizeUri = " + data); + expect(Denormalize).assertEqual(data); + done(); + }).catch((err) => { + console.info("DataShareDenormalizeUri0101 err " + JSON.stringify(err)); + expect(err).assertFail(); + done(); + }) + } catch (err) { + console.info("DataShareDenormalizeUri0101 fail " + JSON.stringify(err)); + expect(err).assertFail(); + done(); + } + }) + + /* + * @tc.number : SUB_DDM_DataShare_ETS_DataShareOnKvdb0101 + * @tc.name : Use getEntries get the value by mixing the string key + * @tc.desc : Support On function + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 0 + */ + it('DataShareOnKvdb0101', 0, function () { + try { + globalThis.helper.on("dataChange", uri, onChangeNotify); + console.info("TestDataShare going on"); + globalThis.helper.off("dataChange", uri); + console.info("TestDataShare going off"); + } catch (err) { + console.info("DataShareOnKvdb0101 fail " + JSON.stringify(err)); + expect(err).assertFail(); + } + }) + + /* + * @tc.number : SUB_DDM_DataShare_ETS_DataShareOffKvdb0101 + * @tc.name : Use getEntries get the value by mixing the string key + * @tc.desc : Support Off function + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 0 + */ + it('DataShareOffKvdb0101', 0, function () { + try { + globalThis.helper.off("dataChange", uri, onChangeNotify); + console.info("TestDataShare going off"); + globalThis.helper.off("dataChange", uri); + console.info("TestDataShare going off"); + } catch (err) { + console.info("DataShareOffKvdb0101 fail " + JSON.stringify(err)); + expect(err).assertFail(); + } + }) + + /* + * @tc.number : SUB_DDM_DataShare_ETS_DataShareTypeErr0101 + * @tc.name : Use getEntries get the value by mixing the string key + * @tc.desc : Cannot on off operate + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 2 + */ + it('DataShareTypeErr0101', 2, function () { + try { + globalThis.helper.on(null, uri, onChangeNotify); + console.info("TestDataShare going on"); + globalThis.helper.off(null, uri); + console.info("TestDataShare going off"); + } catch (err) { + console.info("DataShareTypeErr0101 fail" + JSON.stringify(err)); + expect(err).assertFail(); + } + }) + + /* + * @tc.number : SUB_DDM_DataShare_ETS_CreateDataSharePromise0101 + * @tc.name : Use getEntries get the value by mixing the string key + * @tc.desc : CreateDataShareHelperPromise + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 0 + */ + it('CreateDataSharePromise0101', 0, async function (done) { + try { + await dataShare.createDataShareHelper(globalThis.abilityContext, uri).then((data) => { + console.info("TestDataShare CreateDataShareHelper = " + data); + expect(true).assertEqual(data != undefined); + done(); + }).catch((err) => { + console.info("CreateDataSharePromise0101 err " + JSON.stringify(err)); + expect(err).assertFail(); + done(); + }) + } catch (err) { + console.info("CreateDataSharePromise0101 fail " + JSON.stringify(err)); + expect(err).assertFail(); + done(); + } + }) + + /* + * @tc.number : SUB_DDM_DataShare_ETS_DataShareOpenFile0101 + * @tc.name : Use getEntries get the value by mixing the string key + * @tc.desc : Support OpenFile function + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 0 + */ + it('DataShareOpenFile0101', 0, async function (done) { + try { + await pubfun.publicopenFile(globalThis.helper, uri, Mode).then((data) => { + console.info("TestDataShare going openFile = " + data); + expect(true).assertEqual(data != null); + done(); + }).catch((err) => { + console.info("DataShareOpenFile0101 err " + JSON.stringify(err)); + expect(err).assertFail(); + done(); + }) + } catch (err) { + console.info("DataShareOpenFile0101 fail " + JSON.stringify(err)); + expect(err).assertFail(); + done(); + } + }) + }) +} \ No newline at end of file diff --git a/distributeddatamgr/dataShare/dataShareKvtest/entry/src/main/ets/test/DataShareSingleKvdb_Promise.ets b/distributeddatamgr/dataShare/dataShareKvtest/entry/src/main/ets/test/DataShareSingleKvdb_Promise.ets new file mode 100644 index 0000000000000000000000000000000000000000..1d9adbff0c684e8304cdd492d82d459e6d92039b --- /dev/null +++ b/distributeddatamgr/dataShare/dataShareKvtest/entry/src/main/ets/test/DataShareSingleKvdb_Promise.ets @@ -0,0 +1,558 @@ +/* +* 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 dataShare from '@ohos.data.dataShare' +import dataSharePredicates from '@ohos.data.dataSharePredicates' +import * as pubfun from './DataSharePublicfunction_Promise' + +//CreateDataShareHelper +let uri = ("datashare:///com.samples.datasharekvtest.DataShare"); + +//InsertValuesBucket +let Insert = { "name": "sun", "age": 1, "isStudent": true }; +let BatchInsert = new Array( + { "name": "sun", "age": 1, "isStudent": true }, + { "name": "sunn", "age": 10, "isStudent": false }); + +//UpdateValuesBucket +let Update = { "name": "suns", "age": 2, "isStudent": false }; + +//Predicates +let EqualTo = new dataSharePredicates.DataSharePredicates(); +EqualTo.equalTo("$.age", 1); +let PredicatesDelete0 = new dataSharePredicates.DataSharePredicates(); +PredicatesDelete0.inKeys(["testkey0"]); +let PredicatesDelete1 = new dataSharePredicates.DataSharePredicates(); +PredicatesDelete1.inKeys(["testkey1"]); + + +//Return Expect +const DataProcessResultOne = 1; +const GetType = "image"; +const GetFileTypes = new Array("type01", "type02", "type03"); +const Normalize = "normalize+" + uri; +const Denormalize = "denormalize+" + uri; +const ResultSetInsert = { "name": "sun", "age": 1, "isStudent": "true" }; +const Mode = "rwt"; + +function onChangeNotify() { + console.info("===>onChangeNotify===>"); +}; + +export default function DataShareSingleKvdb_Promise() { + describe('DataShareSingleKvdb_Promise', function () { + function sleep(time) { + return new Promise(resolve => { + setTimeout(() => { + resolve('sleep finished'); + }, time); + }) + } + + beforeAll(async () => { + await globalThis.connectDataShareExtAbility(); + await sleep(2000); + console.info("[ttt] helper = " + globalThis.helper + "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!") + }) + + /* + * @tc.number : SUB_DDM_DataShare_ETS_DataShareInsertKvdb0101 + * @tc.name : Use getEntries get the value by mixing the string key + * @tc.desc : Insert All type data in Kvdb + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 0 + */ + it('DataShareInsertKvdb0101', 0, async function (done) { + try { + await pubfun.publicinsert(globalThis.helper, uri, Insert).then((data) => { + console.info("TestDataShare going insert = " + data); + expect(DataProcessResultOne).assertEqual(data); + }).catch((err) => { + console.info("DataShareInsertKvdb0101 fail err " + JSON.stringify(err)); + expect(err).assertFail(); + }) + await pubfun.publicdelete(globalThis.helper, uri, PredicatesDelete0).then((data) => { + console.info("TestDataShare going delete = " + data); + expect(DataProcessResultOne).assertEqual(data); + done(); + }) + } catch (err) { + console.info("DataShareInsertKvdb0101 fail " + JSON.stringify(err)); + expect(err).assertFail(); + done(); + } + }) + + /* + * @tc.number : SUB_DDM_DataShare_ETS_DataShareUpdateKvdb0101 + * @tc.name : Use getEntries get the value by mixing the string key + * @tc.desc : Update All type data in Kvdb + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 0 + */ + it('DataShareUpdateKvdb0101', 0, async function (done) { + try { + await pubfun.publicinsert(globalThis.helper, uri, Insert).then((data) => { + console.info("TestDataShare going insert = " + data); + expect(DataProcessResultOne).assertEqual(data); + }) + await pubfun.publicupdate(globalThis.helper, uri, EqualTo, Update).then((data) => { + console.info("TestDataShare going update = " + data); + expect(DataProcessResultOne).assertEqual(data); + }).catch((err) => { + console.info("DataShareUpdateKvdb0101 err " + JSON.stringify(err)); + expect(err).assertFail(); + }) + await pubfun.publicdelete(globalThis.helper, uri, PredicatesDelete0).then((data) => { + console.info("TestDataShare going delete = " + data); + expect(DataProcessResultOne).assertEqual(data); + done(); + }) + } catch (err) { + console.info("DataShareUpdateKvdb0101 fail " + JSON.stringify(err)); + expect(err).assertFail(); + done(); + } + }) + + /* + * @tc.number : SUB_DDM_DataShare_ETS_DataShareQueryKvdb0101 + * @tc.name : Use getEntries get the value by mixing the string key + * @tc.desc : Query All type data in Kvdb + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 0 + */ + it('DataShareQueryKvdb0101', 0, async function (done) { + try { + await pubfun.publicinsert(globalThis.helper, uri, Insert).then((data) => { + console.info("TestDataShare going insert = " + data); + expect(DataProcessResultOne).assertEqual(data); + }) + await pubfun.publicquery(globalThis.helper, uri, EqualTo, ["*"]).then((data) => { + console.info("TestDataShare going query = " + data); + globalThis.ResultSet.goToFirstRow(); + expect(JSON.stringify(ResultSetInsert)).assertEqual(globalThis.ResultSet.getString(1)); + }).catch((err) => { + console.info("DataShareQueryKvdb0101 err " + JSON.stringify(err)); + expect(err).assertFail(); + }) + await pubfun.publicdelete(globalThis.helper, uri, PredicatesDelete0).then((data) => { + console.info("TestDataShare going delete = " + data); + expect(DataProcessResultOne).assertEqual(data); + done(); + }) + } catch (err) { + console.info("DataShareQueryKvdb0101 fail " + JSON.stringify(err)); + expect(err).assertFail(); + done(); + } + }) + + /* + * @tc.number : SUB_DDM_DataShare_ETS_DataShareDeleteKvdb0101 + * @tc.name : Use getEntries get the value by mixing the string key + * @tc.desc : Delete number type data in Kvdb + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 0 + */ + it('DataShareDeleteKvdb0101', 0, async function (done) { + try { + await pubfun.publicinsert(globalThis.helper, uri, Insert).then((data) => { + console.info("TestDataShare going insert = " + data); + expect(DataProcessResultOne).assertEqual(data); + }) + await pubfun.publicdelete(globalThis.helper, uri, PredicatesDelete0).then((data) => { + console.info("TestDataShare going delete = " + data); + expect(DataProcessResultOne).assertEqual(data); + done(); + }).catch((err) => { + console.info("DataShareDeleteKvdb0101 err " + JSON.stringify(err)); + expect(err).assertFail(); + done(); + }) + } catch (err) { + console.info("DataShareDeleteKvdb0101 fail " + JSON.stringify(err)); + expect(err).assertFail(); + done(); + } + }) + + /* + * @tc.number : SUB_DDM_DataShare_ETS_DataShareBatchKvdb0101 + * @tc.name : Use getEntries get the value by mixing the string key + * @tc.desc : BatchInsert data in Kvdb + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 0 + */ + it('DataShareBatchKvdb0101', 0, async function (done) { + try { + await pubfun.publicbatchInsert(globalThis.helper, uri, BatchInsert).then((data) => { + console.info("TestDataShare going batchInsert = " + data); + expect(DataProcessResultOne).assertEqual(data); + }).catch((err) => { + console.info("DataSharebatchKvdb001 err " + JSON.stringify(err)); + expect(err).assertFail(); + }) + await pubfun.publicdelete(globalThis.helper, uri, PredicatesDelete0).then((data) => { + console.info("TestDataShare going delete 0 = " + data); + expect(DataProcessResultOne).assertEqual(data); + }) + await pubfun.publicdelete(globalThis.helper, uri, PredicatesDelete1).then((data) => { + console.info("TestDataShare going delete 1 = " + data); + expect(DataProcessResultOne).assertEqual(data); + done(); + }) + } catch (err) { + console.info("DataSharebatchKvdb001 fail " + JSON.stringify(err)); + expect(err).assertFail(); + done(); + } + }) + + /* + * @tc.number : SUB_DDM_DataShare_ETS_DataShareBatchKvdb0102 + * @tc.name : Use getEntries get the value by mixing the string key + * @tc.desc : Update data in Kvdb + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 0 + */ + it('DataShareBatchKvdb0102', 0, async function (done) { + try { + await pubfun.publicbatchInsert(globalThis.helper, uri, BatchInsert).then((data) => { + console.info("TestDataShare going batchInsert = " + data); + expect(DataProcessResultOne).assertEqual(data); + }) + await pubfun.publicupdate(globalThis.helper, uri, EqualTo, Update).then((data) => { + console.info("TestDataShare going update = " + data); + expect(DataProcessResultOne).assertEqual(data); + }).catch((err) => { + console.info("DataShareBatchKvdb0102 err " + JSON.stringify(err)); + expect(err).assertFail(); + }) + await pubfun.publicdelete(globalThis.helper, uri, PredicatesDelete0).then((data) => { + console.info("TestDataShare going delete 0 = " + data); + expect(DataProcessResultOne).assertEqual(data); + }) + await pubfun.publicdelete(globalThis.helper, uri, PredicatesDelete1).then((data) => { + console.info("TestDataShare going delete 1 = " + data); + expect(DataProcessResultOne).assertEqual(data); + done(); + }) + } catch (err) { + console.info("DataShareBatchKvdb0102 fail " + JSON.stringify(err)); + expect(err).assertFail(); + done(); + } + }) + + /* + * @tc.number : SUB_DDM_DataShare_ETS_DataShareBatchKvdb0103 + * @tc.name : Use getEntries get the value by mixing the string key + * @tc.desc : Query data in Kvdb + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 0 + */ + it('DataShareBatchKvdb0103', 0, async function (done) { + try { + await pubfun.publicbatchInsert(globalThis.helper, uri, BatchInsert).then((data) => { + console.info("TestDataShare going batchInsert = " + data); + expect(DataProcessResultOne).assertEqual(data); + }) + await pubfun.publicquery(globalThis.helper, uri, EqualTo, ["*"]).then((data) => { + console.info("TestDataShare going query = " + data); + globalThis.ResultSet.goToFirstRow(); + expect(JSON.stringify(ResultSetInsert)).assertEqual(globalThis.ResultSet.getString(1)); + }).catch((err) => { + console.info("DataShareBatchKvdb003 err " + JSON.stringify(err)); + expect(err).assertFail(); + }) + await pubfun.publicdelete(globalThis.helper, uri, PredicatesDelete0).then((data) => { + console.info("TestDataShare going delete 0 = " + data); + expect(DataProcessResultOne).assertEqual(data); + }) + await pubfun.publicdelete(globalThis.helper, uri, PredicatesDelete1).then((data) => { + console.info("TestDataShare going delete 1 = " + data); + expect(DataProcessResultOne).assertEqual(data); + done(); + }) + } catch (err) { + console.info("DataShareBatchKvdb003 fail " + JSON.stringify(err)); + expect(err).assertFail(); + done(); + } + }) + + /* + * @tc.number : SUB_DDM_DataShare_ETS_DataShareBatchKvdb0104 + * @tc.name : Use getEntries get the value by mixing the string key + * @tc.desc : Delete data in Kvdb + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 0 + */ + it('DataShareBatchKvdb0104', 0, async function (done) { + try { + await pubfun.publicbatchInsert(globalThis.helper, uri, BatchInsert).then((data) => { + console.info("TestDataShare going batchInsert = " + data); + expect(DataProcessResultOne).assertEqual(data); + }) + await pubfun.publicdelete(globalThis.helper, uri, PredicatesDelete0).then((data) => { + console.info("TestDataShare going delete 0 = " + data); + expect(DataProcessResultOne).assertEqual(data); + }).catch((err) => { + console.info("DataShareBatchKvdb0104 delete 0 err " + JSON.stringify(err)); + expect(err).assertFail(); + }) + await pubfun.publicdelete(globalThis.helper, uri, PredicatesDelete1).then((data) => { + console.info("TestDataShare going delete 1 = " + data); + expect(DataProcessResultOne).assertEqual(data); + done(); + }).catch((err) => { + console.info("DataShareBatchKvdb0104 delete 1 err " + JSON.stringify(err)); + expect(err).assertFail(); + done(); + }) + } catch (err) { + console.info("DataShareBatchKvdb0104 fail " + JSON.stringify(err)); + expect(err).assertFail(); + done(); + } + }) + + /* + * @tc.number : SUB_DDM_DataShare_ETS_DataShareGetType0101 + * @tc.name : Use getEntries get the value by mixing the string key + * @tc.desc : Support GetType function + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 0 + */ + it('DataShareGetType0101', 0, async function (done) { + try { + await pubfun.publicgetType(globalThis.helper, uri).then((data) => { + console.info("TestDataShare going getType = " + data); + expect(GetType).assertEqual(data); + done(); + }).catch((err) => { + console.info("DataShareGetType0101 err " + JSON.stringify(err)); + expect(err).assertFail(); + done(); + }) + } catch (err) { + console.info("DataShareGetType0101 fail " + JSON.stringify(err)); + expect(err).assertFail(); + done(); + } + }) + + /* + * @tc.number : SUB_DDM_DataShare_ETS_DataShareGetFileTypes0101 + * @tc.name : Use getEntries get the value by mixing the string key + * @tc.desc : Support GetFileTypes function + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 0 + */ + it('DataShareGetFileTypes0101', 0, async function (done) { + try { + await pubfun.publicgetFileTypes(globalThis.helper, uri, "image/*").then((data) => { + console.info("TestDataShare going getFileTypes = " + data); + expect(JSON.stringify(GetFileTypes)).assertEqual(JSON.stringify(data)); + done(); + }).catch((err) => { + console.info("DataShareGetFileTypes0101 err " + JSON.stringify(err)); + expect(err).assertFail(); + done(); + }) + } catch (err) { + console.info("DataShareGetFileTypes0101 fail " + JSON.stringify(err)); + expect(err).assertFail(); + done(); + } + }) + + /* + * @tc.number : SUB_DDM_DataShare_ETS_DataShareNormalizeUri0101 + * @tc.name : Use getEntries get the value by mixing the string key + * @tc.desc : Support NormalizeUri function + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 0 + */ + it('DataShareNormalizeUri0101', 0, async function (done) { + try { + await pubfun.publicnormalizeUri(globalThis.helper, uri).then((data) => { + console.info("TestDataShare going NormalizeUri = " + data); + expect(Normalize).assertEqual(data); + done(); + }).catch((err) => { + console.info("DataShareNormalizeUri0101 err " + JSON.stringify(err)); + expect(err).assertFail(); + done(); + }) + } catch (err) { + console.info("DataShareNormalizeUri0101 fail " + JSON.stringify(err)); + expect(err).assertFail(); + done(); + } + }) + + /* + * @tc.number : SUB_DDM_DataShare_ETS_DataShareDenormalizeUri0101 + * @tc.name : Use getEntries get the value by mixing the string key + * @tc.desc : Support DenormalizeUri function + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 0 + */ + it('DataShareDenormalizeUri0101', 0, async function (done) { + try { + await pubfun.publicdenormalizeUri(globalThis.helper, uri).then((data) => { + console.info("TestDataShare going denormalizeUri = " + data); + expect(Denormalize).assertEqual(data); + done(); + }).catch((err) => { + console.info("DataShareDenormalizeUri0101 err " + JSON.stringify(err)); + expect(err).assertFail(); + done(); + }) + } catch (err) { + console.info("DataShareDenormalizeUri0101 fail " + JSON.stringify(err)); + expect(err).assertFail(); + done(); + } + }) + + /* + * @tc.number : SUB_DDM_DataShare_ETS_DataShareOnKvdb0101 + * @tc.name : Use getEntries get the value by mixing the string key + * @tc.desc : Support On function + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 0 + */ + it('DataShareOnKvdb0101', 0, function () { + try { + globalThis.helper.on("dataChange", uri, onChangeNotify); + console.info("TestDataShare going on"); + globalThis.helper.off("dataChange", uri); + console.info("TestDataShare going off"); + } catch (err) { + console.info("DataShareOnKvdb0101 fail " + JSON.stringify(err)); + expect(err).assertFail(); + } + }) + + /* + * @tc.number : SUB_DDM_DataShare_ETS_DataShareOffKvdb0101 + * @tc.name : Use getEntries get the value by mixing the string key + * @tc.desc : Support Off function + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 0 + */ + it('DataShareOffKvdb0101', 0, function () { + try { + globalThis.helper.off("dataChange", uri, onChangeNotify); + console.info("TestDataShare going off"); + globalThis.helper.off("dataChange", uri); + console.info("TestDataShare going off"); + } catch (err) { + console.info("DataShareOffKvdb0101 fail " + JSON.stringify(err)); + expect(err).assertFail(); + } + }) + + /* + * @tc.number : SUB_DDM_DataShare_ETS_DataShareTypeErr0101 + * @tc.name : Use getEntries get the value by mixing the string key + * @tc.desc : Cannot on off operate + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 2 + */ + it('DataShareTypeErr0101', 2, function () { + try { + globalThis.helper.on(null, uri, onChangeNotify); + console.info("TestDataShare going on"); + globalThis.helper.off(null, uri); + console.info("TestDataShare going off"); + } catch (err) { + console.info("DataShareTypeErr0101 fail" + JSON.stringify(err)); + expect(err).assertFail(); + } + }) + + /* + * @tc.number : SUB_DDM_DataShare_ETS_CreateDataSharePromise0101 + * @tc.name : Use getEntries get the value by mixing the string key + * @tc.desc : CreateDataShareHelperPromise + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 0 + */ + it('CreateDataSharePromise0101', 0, async function (done) { + try { + await dataShare.createDataShareHelper(globalThis.abilityContext, uri).then((data) => { + console.info("TestDataShare CreateDataShareHelper = " + data); + expect(true).assertEqual(data != undefined); + done(); + }).catch((err) => { + console.info("CreateDataSharePromise0101 err " + JSON.stringify(err)); + expect(err).assertFail(); + done(); + }) + } catch (err) { + console.info("CreateDataSharePromise0101 fail " + JSON.stringify(err)); + expect(err).assertFail(); + done(); + } + }) + + /* + * @tc.number : SUB_DDM_DataShare_ETS_DataShareOpenFile0101 + * @tc.name : Use getEntries get the value by mixing the string key + * @tc.desc : Support OpenFile function + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 0 + */ + it('DataShareOpenFile0101', 0, async function (done) { + try { + await pubfun.publicopenFile(globalThis.helper, uri, Mode).then((data) => { + console.info("TestDataShare going openFile = " + data); + expect(true).assertEqual(data != null); + done(); + }).catch((err) => { + console.info("DataShareOpenFile0101 err " + JSON.stringify(err)); + expect(err).assertFail(); + done(); + }) + } catch (err) { + console.info("DataShareOpenFile0101 fail " + JSON.stringify(err)); + expect(err).assertFail(); + done(); + } + }) + }) +} \ No newline at end of file diff --git a/distributeddatamgr/dataShare/dataShareKvtest/entry/src/main/ets/test/List.test.ets b/distributeddatamgr/dataShare/dataShareKvtest/entry/src/main/ets/test/List.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..2de2a1b319387ffe2b20c9baf55d81e862f82254 --- /dev/null +++ b/distributeddatamgr/dataShare/dataShareKvtest/entry/src/main/ets/test/List.test.ets @@ -0,0 +1,27 @@ +/* +* 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 DataShareSingleKvdb_Callback from "./DataShareSingleKvdb_Callback" +import DataShareSingleKvdb_Promise from "./DataShareSingleKvdb_Promise" +import DataSharePredicatesKvdb from "./DataSharePredicatesKvdb" +import DataShareCombinationKvdb from "./DataShareCombinationKvdb" + +export default function testsuite() { + + DataShareSingleKvdb_Callback() + DataShareSingleKvdb_Promise() + DataSharePredicatesKvdb() + DataShareCombinationKvdb() +} \ No newline at end of file diff --git a/distributeddatamgr/dataShare/dataShareKvtest/entry/src/main/module.json b/distributeddatamgr/dataShare/dataShareKvtest/entry/src/main/module.json new file mode 100644 index 0000000000000000000000000000000000000000..e67f9c2565c2bf14a4a5ad2670571f4ed91788e3 --- /dev/null +++ b/distributeddatamgr/dataShare/dataShareKvtest/entry/src/main/module.json @@ -0,0 +1,38 @@ +{ + "module": { + "package": "com.example.myapplication2", + "name": "entry", + "mainAbility": "com.example.myapplication2.MainAbility", + "type": "entry", + "srcEntrance": "./ets/Application/AbilityStage.ts", + "description": "$string:entry_desc", + "mainElement": "MainAbility", + "deviceTypes": [ + "phone" + ], + "deliveryWithInstall": true, + "installationFree": false, + "pages": "$profile:main_pages", + "uiSyntax": "ets", + "abilities": [ + { + "name": "com.example.myapplication2.MainAbility", + "srcEntrance": "./ets/MainAbility/MainAbility.ts", + "description": "$string:MainAbility_desc", + "icon": "$media:icon", + "label": "$string:MainAbility_label", + "visible": true, + "skills": [ + { + "entities": [ + "entity.system.home" + ], + "actions": [ + "action.system.home" + ] + } + ] + } + ] + } +} diff --git a/distributeddatamgr/dataShare/dataShareKvtest/entry/src/main/resources/base/element/string.json b/distributeddatamgr/dataShare/dataShareKvtest/entry/src/main/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..cac443cf6cb6e440dbfd9e26c90008cbebf71c69 --- /dev/null +++ b/distributeddatamgr/dataShare/dataShareKvtest/entry/src/main/resources/base/element/string.json @@ -0,0 +1,16 @@ +{ + "string": [ + { + "name": "entry_desc", + "value": "description" + }, + { + "name": "MainAbility_desc", + "value": "description" + }, + { + "name": "MainAbility_label", + "value": "ActsDataShareKvTest" + } + ] +} \ No newline at end of file diff --git a/distributeddatamgr/distributeddataObjectjstest/hap/src/main/resources/base/media/icon.png b/distributeddatamgr/dataShare/dataShareKvtest/entry/src/main/resources/base/media/icon.png similarity index 100% rename from distributeddatamgr/distributeddataObjectjstest/hap/src/main/resources/base/media/icon.png rename to distributeddatamgr/dataShare/dataShareKvtest/entry/src/main/resources/base/media/icon.png diff --git a/distributeddatamgr/windowStage/dataShareRdbtest/entry/src/main/resources/base/profile/main_pages.json b/distributeddatamgr/dataShare/dataShareKvtest/entry/src/main/resources/base/profile/main_pages.json similarity index 100% rename from distributeddatamgr/windowStage/dataShareRdbtest/entry/src/main/resources/base/profile/main_pages.json rename to distributeddatamgr/dataShare/dataShareKvtest/entry/src/main/resources/base/profile/main_pages.json diff --git a/distributeddatamgr/windowStage/dataShareRdbtest/signature/openharmony_sx.p7b b/distributeddatamgr/dataShare/dataShareKvtest/signature/openharmony_sx.p7b similarity index 100% rename from distributeddatamgr/windowStage/dataShareRdbtest/signature/openharmony_sx.p7b rename to distributeddatamgr/dataShare/dataShareKvtest/signature/openharmony_sx.p7b diff --git a/distributeddatamgr/windowStage/dataShareRdbtest/AppScope/app.json b/distributeddatamgr/dataShare/dataShareRdbtest/AppScope/app.json similarity index 100% rename from distributeddatamgr/windowStage/dataShareRdbtest/AppScope/app.json rename to distributeddatamgr/dataShare/dataShareRdbtest/AppScope/app.json diff --git a/distributeddatamgr/windowStage/dataShareRdbtest/AppScope/resources/base/element/string.json b/distributeddatamgr/dataShare/dataShareRdbtest/AppScope/resources/base/element/string.json similarity index 100% rename from distributeddatamgr/windowStage/dataShareRdbtest/AppScope/resources/base/element/string.json rename to distributeddatamgr/dataShare/dataShareRdbtest/AppScope/resources/base/element/string.json diff --git a/distributeddatamgr/windowStage/server/rdbService/AppScope/resources/base/media/app_icon.png b/distributeddatamgr/dataShare/dataShareRdbtest/AppScope/resources/base/media/app_icon.png similarity index 100% rename from distributeddatamgr/windowStage/server/rdbService/AppScope/resources/base/media/app_icon.png rename to distributeddatamgr/dataShare/dataShareRdbtest/AppScope/resources/base/media/app_icon.png diff --git a/distributeddatamgr/windowStage/dataShareRdbtest/BUILD.gn b/distributeddatamgr/dataShare/dataShareRdbtest/BUILD.gn similarity index 95% rename from distributeddatamgr/windowStage/dataShareRdbtest/BUILD.gn rename to distributeddatamgr/dataShare/dataShareRdbtest/BUILD.gn index 271042a33ebe477b6f4907e1c65f70b1ca350fdf..71e01ed65ccbbcb8aa4bfc9546e962f2280ca3dc 100644 --- a/distributeddatamgr/windowStage/dataShareRdbtest/BUILD.gn +++ b/distributeddatamgr/dataShare/dataShareRdbtest/BUILD.gn @@ -23,6 +23,8 @@ ohos_js_hap_suite("ActsDataShareRdbTest") { ets2abc = true certificate_profile = "signature/openharmony_sx.p7b" hap_name = "ActsDataShareRdbTest" + subsystem_name = "distributeddatamgr" + part_name = "data_share" } ohos_app_scope("dataShareRdb_app_profile") { diff --git a/distributeddatamgr/windowStage/dataShareRdbtest/Test.json b/distributeddatamgr/dataShare/dataShareRdbtest/Test.json similarity index 100% rename from distributeddatamgr/windowStage/dataShareRdbtest/Test.json rename to distributeddatamgr/dataShare/dataShareRdbtest/Test.json diff --git a/distributeddatamgr/windowStage/dataShareRdbtest/entry/src/main/ets/Application/AbilityStage.ts b/distributeddatamgr/dataShare/dataShareRdbtest/entry/src/main/ets/Application/AbilityStage.ts similarity index 100% rename from distributeddatamgr/windowStage/dataShareRdbtest/entry/src/main/ets/Application/AbilityStage.ts rename to distributeddatamgr/dataShare/dataShareRdbtest/entry/src/main/ets/Application/AbilityStage.ts diff --git a/distributeddatamgr/windowStage/dataShareRdbtest/entry/src/main/ets/MainAbility/MainAbility.ts b/distributeddatamgr/dataShare/dataShareRdbtest/entry/src/main/ets/MainAbility/MainAbility.ts similarity index 100% rename from distributeddatamgr/windowStage/dataShareRdbtest/entry/src/main/ets/MainAbility/MainAbility.ts rename to distributeddatamgr/dataShare/dataShareRdbtest/entry/src/main/ets/MainAbility/MainAbility.ts diff --git a/distributeddatamgr/windowStage/dataShareRdbtest/entry/src/main/ets/MainAbility/pages/index.ets b/distributeddatamgr/dataShare/dataShareRdbtest/entry/src/main/ets/MainAbility/pages/index.ets similarity index 100% rename from distributeddatamgr/windowStage/dataShareRdbtest/entry/src/main/ets/MainAbility/pages/index.ets rename to distributeddatamgr/dataShare/dataShareRdbtest/entry/src/main/ets/MainAbility/pages/index.ets diff --git a/distributeddatamgr/dataShare/dataShareRdbtest/entry/src/main/ets/TestAbility/TestAbility.ts b/distributeddatamgr/dataShare/dataShareRdbtest/entry/src/main/ets/TestAbility/TestAbility.ts new file mode 100644 index 0000000000000000000000000000000000000000..89a84730505783ba229175ab4b55d37f91a16266 --- /dev/null +++ b/distributeddatamgr/dataShare/dataShareRdbtest/entry/src/main/ets/TestAbility/TestAbility.ts @@ -0,0 +1,50 @@ +/* + * 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 Ability from '@ohos.application.Ability' + +export default class TestAbility extends Ability { + onCreate(want, launchParam) { + console.log('TestAbility onCreate') + } + + onDestroy() { + console.log('TestAbility onDestroy') + } + + onWindowStageCreate(windowStage) { + console.log('TestAbility onWindowStageCreate') + windowStage.loadContent("TestAbility/pages/index", (err, data) => { + if (err.code) { + console.error('Failed to load the content. Cause:' + JSON.stringify(err)); + return; + } + console.info('Succeeded in loading the content. Data: ' + JSON.stringify(data)) + }); + + globalThis.abilityContext = this.context; + } + + onWindowStageDestroy() { + console.log('TestAbility onWindowStageDestroy') + } + + onForeground() { + console.log('TestAbility onForeground') + } + + onBackground() { + console.log('TestAbility onBackground') + } +}; \ No newline at end of file diff --git a/distributeddatamgr/dataShare/dataShareRdbtest/entry/src/main/ets/TestAbility/pages/index.ets b/distributeddatamgr/dataShare/dataShareRdbtest/entry/src/main/ets/TestAbility/pages/index.ets new file mode 100644 index 0000000000000000000000000000000000000000..b93567f962921124b282f78c8ef123965d1460c9 --- /dev/null +++ b/distributeddatamgr/dataShare/dataShareRdbtest/entry/src/main/ets/TestAbility/pages/index.ets @@ -0,0 +1,48 @@ +/* + * 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 router from '@ohos.router'; + +@Entry +@Component +struct Index { + aboutToAppear() { + console.info('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/windowStage/dataShareRdbtest/entry/src/main/ets/TestRunner/OpenHarmonyTestRunner.ts b/distributeddatamgr/dataShare/dataShareRdbtest/entry/src/main/ets/TestRunner/OpenHarmonyTestRunner.ts similarity index 100% rename from distributeddatamgr/windowStage/dataShareRdbtest/entry/src/main/ets/TestRunner/OpenHarmonyTestRunner.ts rename to distributeddatamgr/dataShare/dataShareRdbtest/entry/src/main/ets/TestRunner/OpenHarmonyTestRunner.ts diff --git a/distributeddatamgr/windowStage/dataShareRdbtest/entry/src/main/ets/test/DataShareCombinationRdb.ets b/distributeddatamgr/dataShare/dataShareRdbtest/entry/src/main/ets/test/DataShareCombinationRdb.ets similarity index 97% rename from distributeddatamgr/windowStage/dataShareRdbtest/entry/src/main/ets/test/DataShareCombinationRdb.ets rename to distributeddatamgr/dataShare/dataShareRdbtest/entry/src/main/ets/test/DataShareCombinationRdb.ets index a1b8be329655d63f97843316982cc371cddbc75d..7b351dff481a52edd71f71bfd14dcd7b822c13e5 100644 --- a/distributeddatamgr/windowStage/dataShareRdbtest/entry/src/main/ets/test/DataShareCombinationRdb.ets +++ b/distributeddatamgr/dataShare/dataShareRdbtest/entry/src/main/ets/test/DataShareCombinationRdb.ets @@ -293,7 +293,7 @@ export default function DataShareCombinationRdb() { * @tc.size : MediumTest * @tc.type : Function * @tc.level : Level 1 - */ +*/ it('DataShareNotifyChangeRdb0101', 1, async function (done) { try { let Count = 1; diff --git a/distributeddatamgr/windowStage/dataShareRdbtest/entry/src/main/ets/test/DataSharePredicatesRdb.ets b/distributeddatamgr/dataShare/dataShareRdbtest/entry/src/main/ets/test/DataSharePredicatesRdb.ets similarity index 100% rename from distributeddatamgr/windowStage/dataShareRdbtest/entry/src/main/ets/test/DataSharePredicatesRdb.ets rename to distributeddatamgr/dataShare/dataShareRdbtest/entry/src/main/ets/test/DataSharePredicatesRdb.ets diff --git a/distributeddatamgr/dataShare/dataShareRdbtest/entry/src/main/ets/test/DataSharePublicfunction_Callback.ets b/distributeddatamgr/dataShare/dataShareRdbtest/entry/src/main/ets/test/DataSharePublicfunction_Callback.ets new file mode 100644 index 0000000000000000000000000000000000000000..1e80d7a5081174eafcb98e329a0ee5b1ac147da7 --- /dev/null +++ b/distributeddatamgr/dataShare/dataShareRdbtest/entry/src/main/ets/test/DataSharePublicfunction_Callback.ets @@ -0,0 +1,177 @@ +/* +* 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 file from '@system.file'; +import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from "@ohos/hypium" +import dataShare from '@ohos.data.dataShare' +import dataSharePredicates from '@ohos.data.dataSharePredicates' +import DataShareResultSet from '@ohos.data.DataShareResultSet' + +//insert公共方法 +function publicinsert(helper, uri, DataShareValuesBucket) { + return new Promise(function (resolve, reject) { + helper.insert(uri, DataShareValuesBucket, (err, data) => { + console.info("[ttt] [TestDataShare] publicinsert Callback=" + JSON.stringify(data)); + globalThis.insertdata = data; + if (err) { + console.info("test insert err information: " + JSON.stringify(err)); + reject(err); + } else { + resolve(data); + } + }) + }) +} + +//delete公共方法 +async function publicdelete(helper, uri, DataSharePredicates) { + return new Promise(function (resolve, reject) { + console.info("[ttt] [DataShareTest] <> 12345648564185645314"); + helper.delete(uri, DataSharePredicates, (err, data) => { + console.info("[ttt] [TestDataShare] publicdelete Callback=" + JSON.stringify(data)); + if (err) { + console.info("test delete err information: " + JSON.stringify(err)); + reject(err); + } else { + resolve(data); + } + }) + }) +} + +//query公共方法 +function publicquery(helper, uri, DataSharePredicates, columns) { + return new Promise(function (resolve, reject) { + helper.query(uri, DataSharePredicates, columns, (err, data) => { + console.info("[ttt] [TestDataShare] publicquery Callback=" + JSON.stringify(data)); + globalThis.ResultSet = data; + if (err) { + console.info("test query err information: " + JSON.stringify(err)); + reject(err); + } else { + resolve(data); + } + }) + }) +} + +//update公共方法 +function publicupdate(helper, uri, DataSharePredicates, DataShareValuesBucket) { + return new Promise(function (resolve, reject) { + helper.update(uri, DataSharePredicates, DataShareValuesBucket, (err, data) => { + console.info("[ttt] [TestDataShare] publicupdate Callback=" + JSON.stringify(data)); + if (err) { + console.info("test update err information: " + JSON.stringify(err)); + reject(err); + } else { + resolve(data); + } + }) + }) +} + +//batchInsert公共方法 +function publicbatchInsert(helper, uri, DataShareValuesBucket) { + return new Promise(function (resolve, reject) { + helper.batchInsert(uri, DataShareValuesBucket, (err, data) => { + console.info("[ttt] [TestDataShare] publicbatchInsert Callback=" + JSON.stringify(data)); + if (err) { + console.info("test batchInsert err information: " + JSON.stringify(err)); + reject(err); + } else { + resolve(data); + } + }) + }) +} + +//getType公共方法 +function publicgetType(helper, uri) { + return new Promise(function (resolve, reject) { + helper.getType(uri, (err, data) => { + console.info("[ttt] [TestDataShare] publicgetType Callback=" + JSON.stringify(data)); + if (err) { + console.info("test getType err information: " + JSON.stringify(err)); + reject(err); + } else { + resolve(data); + } + }) + }) +} + +//getFileTypes公共方法 +function publicgetFileTypes(helper, uri, mimeTypeFilter) { + return new Promise(function (resolve, reject) { + helper.getFileTypes(uri, mimeTypeFilter, (err, data) => { + console.info("[ttt] [TestDataShare] publicgetFileTypes Callback=" + JSON.stringify(data)); + if (err) { + console.info("test getFileTypes err information: " + JSON.stringify(err)); + reject(err); + } else { + resolve(data); + } + }) + }) +} + +//normalizeUri公共方法 +function publicnormalizeUri(helper, uri) { + return new Promise(function (resolve, reject) { + helper.normalizeUri(uri, (err, data) => { + console.info("[ttt] [TestDataShare] publicnormalizeUri Callback=" + JSON.stringify(data)); + if (err) { + console.info("test normalizeUri err information: " + JSON.stringify(err)); + reject(err); + } else { + resolve(data); + } + }) + }) +} + +//denormalizeUri公共方法 +function publicdenormalizeUri(helper, uri) { + return new Promise(function (resolve, reject) { + helper.denormalizeUri(uri, (err, data) => { + console.info("[ttt] [TestDataShare] publicdenormalizeUri Callback=" + JSON.stringify(data)); + if (err) { + console.info("test denormalizeUri err information: " + JSON.stringify(err)); + reject(err); + } else { + resolve(data); + } + }) + }) +} + +//denormalizeUri公共方法 +function publicopenFile(helper, uri, mode) { + return new Promise(function (resolve, reject) { + helper.denormalizeUri(uri, mode, (err, data) => { + console.info("[ttt] [TestDataShare] publicopenFile Callback=" + JSON.stringify(data)); + if (err) { + console.info("test openFile err information: " + JSON.stringify(err)); + reject(err); + } else { + resolve(data); + } + }) + }) +} + +export { publicinsert, publicdelete, publicquery, publicupdate, publicbatchInsert, publicgetType, publicgetFileTypes, + publicnormalizeUri, publicdenormalizeUri, publicopenFile +} \ No newline at end of file diff --git a/distributeddatamgr/dataShare/dataShareRdbtest/entry/src/main/ets/test/DataSharePublicfunction_Promise.ets b/distributeddatamgr/dataShare/dataShareRdbtest/entry/src/main/ets/test/DataSharePublicfunction_Promise.ets new file mode 100644 index 0000000000000000000000000000000000000000..5fcd72c0609194fd1d88071fd168a682f19c7452 --- /dev/null +++ b/distributeddatamgr/dataShare/dataShareRdbtest/entry/src/main/ets/test/DataSharePublicfunction_Promise.ets @@ -0,0 +1,156 @@ +/* +* 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 file from '@system.file'; +import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from "@ohos/hypium" +import dataShare from '@ohos.data.dataShare' +import dataSharePredicates from '@ohos.data.dataSharePredicates' +import DataShareResultSet from '@ohos.data.DataShareResultSet' + +//insert公共方法 +function publicinsert(helper, uri, DataShareValuesBucket) { + return new Promise(function (resolve, reject) { + helper.insert(uri, DataShareValuesBucket).then((data) => { + console.info("[ttt] [TestDataShare] publicinsert Callback=" + JSON.stringify(data)); + globalThis.insertdata = data; + resolve(data); + }).catch((err) => { + console.info("test insert err information: " + JSON.stringify(err)); + reject(err); + }) + }) +} + +//delete公共方法 +function publicdelete(helper, uri, DataSharePredicates) { + return new Promise(function (resolve, reject) { + helper.delete(uri, DataSharePredicates).then((data) => { + console.info("[ttt] [TestDataShare] publicdelete Callback=" + JSON.stringify(data)); + resolve(data); + }).catch((err) => { + console.info("test delete err information: " + JSON.stringify(err)); + reject(err); + }) + }) +} + +//query公共方法 +function publicquery(helper, uri, columns, DataSharePredicates) { + return new Promise(function (resolve, reject) { + helper.query(uri, columns, DataSharePredicates).then((data) => { + console.info("[ttt] [TestDataShare] publicquery Callback=" + JSON.stringify(data)); + globalThis.ResultSet = data; + resolve(data); + }).catch((err) => { + console.info("test query err information: " + JSON.stringify(err)); + reject(err); + }) + }) +} + +//update公共方法 +function publicupdate(helper, uri, DataShareValuesBucket, DataSharePredicates) { + return new Promise(function (resolve, reject) { + helper.update(uri, DataShareValuesBucket, DataSharePredicates).then((data) => { + console.info("[ttt] [TestDataShare] publicupdate Callback=" + JSON.stringify(data)); + resolve(data); + }).catch((err) => { + console.info("test update err information: " + JSON.stringify(err)); + reject(err); + }) + }) +} + +//batchInsert公共方法 +function publicbatchInsert(helper, uri, DataShareValuesBucket) { + return new Promise(function (resolve, reject) { + helper.batchInsert(uri, DataShareValuesBucket).then((data) => { + console.info("[ttt] [TestDataShare] publicbatchInsert Callback=" + JSON.stringify(data)); + resolve(data); + }).catch((err) => { + console.info("test batchInsert err information: " + JSON.stringify(err)); + reject(err); + }) + }) +} + +//getType公共方法 +function publicgetType(helper, uri) { + return new Promise(function (resolve, reject) { + helper.getType(uri).then((data) => { + console.info("[ttt] [TestDataShare] publicgetType Callback=" + JSON.stringify(data)); + resolve(data); + }).catch((err) => { + console.info("test getType err information: " + JSON.stringify(err)); + reject(err); + }) + }) +} + +//getFileTypes公共方法 +function publicgetFileTypes(helper, uri, mimeTypeFilter) { + return new Promise(function (resolve, reject) { + helper.getFileTypes(uri, mimeTypeFilter).then((data) => { + console.info("[ttt] [TestDataShare] publicgetFileTypes Callback=" + JSON.stringify(data)); + resolve(data); + }).catch((err) => { + console.info("test getFileTypes err information: " + JSON.stringify(err)); + reject(err); + }) + }) +} + +//normalizeUri公共方法 +function publicnormalizeUri(helper, uri) { + return new Promise(function (resolve, reject) { + helper.normalizeUri(uri).then((data) => { + console.info("[ttt] [TestDataShare] publicnormalizeUri Callback=" + JSON.stringify(data)); + resolve(data); + }).catch((err) => { + console.info("test normalizeUri err information: " + JSON.stringify(err)); + reject(err); + }) + }) +} + +//denormalizeUri公共方法 +function publicdenormalizeUri(helper, uri) { + return new Promise(function (resolve, reject) { + helper.denormalizeUri(uri).then((data) => { + console.info("[ttt] [TestDataShare] publicdenormalizeUri Callback=" + JSON.stringify(data)); + resolve(data); + }).catch((err) => { + console.info("test denormalizeUri err information: " + JSON.stringify(err)); + reject(err); + }) + }) +} + +//denormalizeUri公共方法 +function publicopenFile(helper, uri, mode) { + return new Promise(function (resolve, reject) { + helper.openFile(uri, mode).then((data) => { + console.info("[ttt] [TestDataShare] publicopenFile Callback=" + JSON.stringify(data)); + resolve(data); + }).catch((err) => { + console.info("test openFile err information: " + JSON.stringify(err)); + reject(err); + }) + }) +} + +export { publicinsert, publicdelete, publicquery, publicupdate, publicbatchInsert, publicgetType, publicgetFileTypes, + publicnormalizeUri, publicdenormalizeUri, publicopenFile +} \ No newline at end of file diff --git a/distributeddatamgr/windowStage/dataShareRdbtest/entry/src/main/ets/test/DataShareSingleRdb_Callback.ets b/distributeddatamgr/dataShare/dataShareRdbtest/entry/src/main/ets/test/DataShareSingleRdb_Callback.ets similarity index 100% rename from distributeddatamgr/windowStage/dataShareRdbtest/entry/src/main/ets/test/DataShareSingleRdb_Callback.ets rename to distributeddatamgr/dataShare/dataShareRdbtest/entry/src/main/ets/test/DataShareSingleRdb_Callback.ets diff --git a/distributeddatamgr/windowStage/dataShareRdbtest/entry/src/main/ets/test/DataShareSingleRdb_Promise.ets b/distributeddatamgr/dataShare/dataShareRdbtest/entry/src/main/ets/test/DataShareSingleRdb_Promise.ets similarity index 100% rename from distributeddatamgr/windowStage/dataShareRdbtest/entry/src/main/ets/test/DataShareSingleRdb_Promise.ets rename to distributeddatamgr/dataShare/dataShareRdbtest/entry/src/main/ets/test/DataShareSingleRdb_Promise.ets diff --git a/distributeddatamgr/windowStage/dataShareRdbtest/entry/src/main/ets/test/List.test.ets b/distributeddatamgr/dataShare/dataShareRdbtest/entry/src/main/ets/test/List.test.ets similarity index 100% rename from distributeddatamgr/windowStage/dataShareRdbtest/entry/src/main/ets/test/List.test.ets rename to distributeddatamgr/dataShare/dataShareRdbtest/entry/src/main/ets/test/List.test.ets diff --git a/distributeddatamgr/windowStage/dataShareRdbtest/entry/src/main/module.json b/distributeddatamgr/dataShare/dataShareRdbtest/entry/src/main/module.json similarity index 100% rename from distributeddatamgr/windowStage/dataShareRdbtest/entry/src/main/module.json rename to distributeddatamgr/dataShare/dataShareRdbtest/entry/src/main/module.json diff --git a/distributeddatamgr/windowStage/dataShareRdbtest/entry/src/main/resources/base/element/string.json b/distributeddatamgr/dataShare/dataShareRdbtest/entry/src/main/resources/base/element/string.json similarity index 100% rename from distributeddatamgr/windowStage/dataShareRdbtest/entry/src/main/resources/base/element/string.json rename to distributeddatamgr/dataShare/dataShareRdbtest/entry/src/main/resources/base/element/string.json diff --git a/distributeddatamgr/distributeddatamgrjstest/hap/src/main/resources/base/media/icon.png b/distributeddatamgr/dataShare/dataShareRdbtest/entry/src/main/resources/base/media/icon.png old mode 100755 new mode 100644 similarity index 100% rename from distributeddatamgr/distributeddatamgrjstest/hap/src/main/resources/base/media/icon.png rename to distributeddatamgr/dataShare/dataShareRdbtest/entry/src/main/resources/base/media/icon.png diff --git a/distributeddatamgr/dataShare/dataShareRdbtest/entry/src/main/resources/base/profile/main_pages.json b/distributeddatamgr/dataShare/dataShareRdbtest/entry/src/main/resources/base/profile/main_pages.json new file mode 100644 index 0000000000000000000000000000000000000000..c1858c216308ad312862a877139a8ba6908ec3c6 --- /dev/null +++ b/distributeddatamgr/dataShare/dataShareRdbtest/entry/src/main/resources/base/profile/main_pages.json @@ -0,0 +1,5 @@ +{ + "src": [ + "MainAbility/pages/index" + ] +} diff --git a/distributeddatamgr/dataShare/dataShareRdbtest/signature/openharmony_sx.p7b b/distributeddatamgr/dataShare/dataShareRdbtest/signature/openharmony_sx.p7b new file mode 100644 index 0000000000000000000000000000000000000000..66b4457a8a81fb8d3356cf46d67226c850944858 Binary files /dev/null and b/distributeddatamgr/dataShare/dataShareRdbtest/signature/openharmony_sx.p7b differ diff --git a/distributeddatamgr/appdatamgrjstest/hap/BUILD.gn b/distributeddatamgr/dataShare/dataSharejstest/hap/BUILD.gn similarity index 76% rename from distributeddatamgr/appdatamgrjstest/hap/BUILD.gn rename to distributeddatamgr/dataShare/dataSharejstest/hap/BUILD.gn index e97cff2668aaa3dd45d74bc0f18da34cc968c81e..9627b715c7f50612dd68a962f53b315ae9f75dbf 100644 --- a/distributeddatamgr/appdatamgrjstest/hap/BUILD.gn +++ b/distributeddatamgr/dataShare/dataSharejstest/hap/BUILD.gn @@ -9,25 +9,27 @@ # 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. +# limitations under the License. import("//test/xts/tools/build/suite.gni") -ohos_js_hap_suite("appdatamgr_js_test") { +ohos_js_hap_suite("dataShare_js_test") { hap_profile = "./src/main/config.json" deps = [ - ":appdatamgr_js_assets", - ":appdatamgr_resources", + ":dataShare_js_assets", + ":dataShare_resources", ] certificate_profile = "./signature/openharmony_sx.p7b" - hap_name = "ActsAppdatamagrJsTest" + hap_name = "ActsDataShareJsTest" + subsystem_name = "distributeddatamgr" + part_name = "data_share" } -ohos_js_assets("appdatamgr_js_assets") { +ohos_js_assets("dataShare_js_assets") { js2abc = true hap_profile = "./src/main/config.json" source_dir = "./src/main/js" } -ohos_resources("appdatamgr_resources") { +ohos_resources("dataShare_resources") { sources = [ "./src/main/resources" ] hap_profile = "./src/main/config.json" } diff --git a/distributeddatamgr/appdatamgrjstest/hap/Test.json b/distributeddatamgr/dataShare/dataSharejstest/hap/Test.json similarity index 66% rename from distributeddatamgr/appdatamgrjstest/hap/Test.json rename to distributeddatamgr/dataShare/dataSharejstest/hap/Test.json index f080e5f76e4c767b2212435dcd1d6281788498bb..e885fe4348eb6ca9fbe254b9c7e8a4f9a873ccad 100644 --- a/distributeddatamgr/appdatamgrjstest/hap/Test.json +++ b/distributeddatamgr/dataShare/dataSharejstest/hap/Test.json @@ -4,13 +4,13 @@ "type": "OHJSUnitTest", "test-timeout": "1000000", "shell-timeout": "1000000", - "bundle-name": "ohos.acts.appdatamgrjstest", - "package-name": "ohos.acts.appdatamgrjstest" + "bundle-name": "ohos.acts.dataSharejstest", + "package-name": "ohos.acts.dataSharejstest" }, "kits": [ { "test-file-name": [ - "ActsAppdatamagrJsTest.hap" + "ActsDataShareJsTest.hap" ], "type": "AppInstallKit", "cleanup-apps": true diff --git a/distributeddatamgr/distributeddataObjectjstest/hap/signature/openharmony_sx.p7b b/distributeddatamgr/dataShare/dataSharejstest/hap/signature/openharmony_sx.p7b similarity index 100% rename from distributeddatamgr/distributeddataObjectjstest/hap/signature/openharmony_sx.p7b rename to distributeddatamgr/dataShare/dataSharejstest/hap/signature/openharmony_sx.p7b diff --git a/distributeddatamgr/appdatamgrjstest/hap/src/main/config.json b/distributeddatamgr/dataShare/dataSharejstest/hap/src/main/config.json similarity index 93% rename from distributeddatamgr/appdatamgrjstest/hap/src/main/config.json rename to distributeddatamgr/dataShare/dataSharejstest/hap/src/main/config.json index 32ad9b41d6f77f8532ba1099b0d0e7070071c8e5..c8e4ccb52ca65152056d27f168f7f76301196895 100644 --- a/distributeddatamgr/appdatamgrjstest/hap/src/main/config.json +++ b/distributeddatamgr/dataShare/dataSharejstest/hap/src/main/config.json @@ -1,6 +1,6 @@ { "app": { - "bundleName": "ohos.acts.appdatamgrjstest", + "bundleName": "ohos.acts.dataSharejstest", "vendor": "example", "version": { "code": 1, @@ -13,7 +13,7 @@ }, "deviceConfig": {}, "module": { - "package": "ohos.acts.appdatamgrjstest", + "package": "ohos.acts.dataSharejstest", "name": ".entry", "deviceType": [ "phone" diff --git a/distributeddatamgr/appdatamgrjstest/hap/src/main/js/MainAbility/app.js b/distributeddatamgr/dataShare/dataSharejstest/hap/src/main/js/MainAbility/app.js similarity index 100% rename from distributeddatamgr/appdatamgrjstest/hap/src/main/js/MainAbility/app.js rename to distributeddatamgr/dataShare/dataSharejstest/hap/src/main/js/MainAbility/app.js diff --git a/distributeddatamgr/appdatamgrjstest/hap/src/main/js/TestAbility/i18n/en-US.json b/distributeddatamgr/dataShare/dataSharejstest/hap/src/main/js/MainAbility/i18n/en-US.json similarity index 100% rename from distributeddatamgr/appdatamgrjstest/hap/src/main/js/TestAbility/i18n/en-US.json rename to distributeddatamgr/dataShare/dataSharejstest/hap/src/main/js/MainAbility/i18n/en-US.json diff --git a/distributeddatamgr/appdatamgrjstest/hap/src/main/js/TestAbility/i18n/zh-CN.json b/distributeddatamgr/dataShare/dataSharejstest/hap/src/main/js/MainAbility/i18n/zh-CN.json similarity index 100% rename from distributeddatamgr/appdatamgrjstest/hap/src/main/js/TestAbility/i18n/zh-CN.json rename to distributeddatamgr/dataShare/dataSharejstest/hap/src/main/js/MainAbility/i18n/zh-CN.json diff --git a/distributeddatamgr/appdatamgrjstest/hap/src/main/js/MainAbility/pages/index/index.css b/distributeddatamgr/dataShare/dataSharejstest/hap/src/main/js/MainAbility/pages/index/index.css similarity index 100% rename from distributeddatamgr/appdatamgrjstest/hap/src/main/js/MainAbility/pages/index/index.css rename to distributeddatamgr/dataShare/dataSharejstest/hap/src/main/js/MainAbility/pages/index/index.css diff --git a/distributeddatamgr/appdatamgrjstest/hap/src/main/js/MainAbility/pages/index/index.hml b/distributeddatamgr/dataShare/dataSharejstest/hap/src/main/js/MainAbility/pages/index/index.hml similarity index 100% rename from distributeddatamgr/appdatamgrjstest/hap/src/main/js/MainAbility/pages/index/index.hml rename to distributeddatamgr/dataShare/dataSharejstest/hap/src/main/js/MainAbility/pages/index/index.hml diff --git a/distributeddatamgr/appdatamgrjstest/hap/src/main/js/MainAbility/pages/index/index.js b/distributeddatamgr/dataShare/dataSharejstest/hap/src/main/js/MainAbility/pages/index/index.js similarity index 100% rename from distributeddatamgr/appdatamgrjstest/hap/src/main/js/MainAbility/pages/index/index.js rename to distributeddatamgr/dataShare/dataSharejstest/hap/src/main/js/MainAbility/pages/index/index.js diff --git a/distributeddatamgr/distributeddataObjectjstest/hap/src/main/js/TestAbility/app.js b/distributeddatamgr/dataShare/dataSharejstest/hap/src/main/js/TestAbility/app.js similarity index 100% rename from distributeddatamgr/distributeddataObjectjstest/hap/src/main/js/TestAbility/app.js rename to distributeddatamgr/dataShare/dataSharejstest/hap/src/main/js/TestAbility/app.js diff --git a/distributeddatamgr/distributeddataObjectjstest/hap/src/main/js/TestAbility/i18n/en-US.json b/distributeddatamgr/dataShare/dataSharejstest/hap/src/main/js/TestAbility/i18n/en-US.json similarity index 100% rename from distributeddatamgr/distributeddataObjectjstest/hap/src/main/js/TestAbility/i18n/en-US.json rename to distributeddatamgr/dataShare/dataSharejstest/hap/src/main/js/TestAbility/i18n/en-US.json diff --git a/distributeddatamgr/distributeddataObjectjstest/hap/src/main/js/TestAbility/i18n/zh-CN.json b/distributeddatamgr/dataShare/dataSharejstest/hap/src/main/js/TestAbility/i18n/zh-CN.json similarity index 100% rename from distributeddatamgr/distributeddataObjectjstest/hap/src/main/js/TestAbility/i18n/zh-CN.json rename to distributeddatamgr/dataShare/dataSharejstest/hap/src/main/js/TestAbility/i18n/zh-CN.json diff --git a/distributeddatamgr/distributeddataObjectjstest/hap/src/main/js/TestAbility/pages/index/index.css b/distributeddatamgr/dataShare/dataSharejstest/hap/src/main/js/TestAbility/pages/index/index.css similarity index 100% rename from distributeddatamgr/distributeddataObjectjstest/hap/src/main/js/TestAbility/pages/index/index.css rename to distributeddatamgr/dataShare/dataSharejstest/hap/src/main/js/TestAbility/pages/index/index.css diff --git a/distributeddatamgr/distributeddataObjectjstest/hap/src/main/js/TestAbility/pages/index/index.hml b/distributeddatamgr/dataShare/dataSharejstest/hap/src/main/js/TestAbility/pages/index/index.hml similarity index 100% rename from distributeddatamgr/distributeddataObjectjstest/hap/src/main/js/TestAbility/pages/index/index.hml rename to distributeddatamgr/dataShare/dataSharejstest/hap/src/main/js/TestAbility/pages/index/index.hml diff --git a/distributeddatamgr/distributeddataObjectjstest/hap/src/main/js/TestAbility/pages/index/index.js b/distributeddatamgr/dataShare/dataSharejstest/hap/src/main/js/TestAbility/pages/index/index.js similarity index 100% rename from distributeddatamgr/distributeddataObjectjstest/hap/src/main/js/TestAbility/pages/index/index.js rename to distributeddatamgr/dataShare/dataSharejstest/hap/src/main/js/TestAbility/pages/index/index.js diff --git a/distributeddatamgr/distributeddataObjectjstest/hap/src/main/js/TestRunner/OpenHarmonyTestRunner.js b/distributeddatamgr/dataShare/dataSharejstest/hap/src/main/js/TestRunner/OpenHarmonyTestRunner.js similarity index 100% rename from distributeddatamgr/distributeddataObjectjstest/hap/src/main/js/TestRunner/OpenHarmonyTestRunner.js rename to distributeddatamgr/dataShare/dataSharejstest/hap/src/main/js/TestRunner/OpenHarmonyTestRunner.js diff --git a/distributeddatamgr/appdatamgrjstest/hap/src/main/js/test/DataAbilityPredicatesJsunit.test.js b/distributeddatamgr/dataShare/dataSharejstest/hap/src/main/js/test/DataAbilityPredicatesJsunit.test.js similarity index 100% rename from distributeddatamgr/appdatamgrjstest/hap/src/main/js/test/DataAbilityPredicatesJsunit.test.js rename to distributeddatamgr/dataShare/dataSharejstest/hap/src/main/js/test/DataAbilityPredicatesJsunit.test.js diff --git a/distributeddatamgr/dataShare/dataSharejstest/hap/src/main/js/test/List.test.js b/distributeddatamgr/dataShare/dataSharejstest/hap/src/main/js/test/List.test.js new file mode 100644 index 0000000000000000000000000000000000000000..de04f5f832a73ea005f146d83a0979896b15f877 --- /dev/null +++ b/distributeddatamgr/dataShare/dataSharejstest/hap/src/main/js/test/List.test.js @@ -0,0 +1,20 @@ +/* +* Copyright (c) 2021 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 dataAbilityPredicatesTest from './DataAbilityPredicatesJsunit.test.js' +import rdbStoreDataSharePredicatesTest from './RdbStoreDataShareJsunit.test.js' +export default function testsuite() { +dataAbilityPredicatesTest() +rdbStoreDataSharePredicatesTest() +} diff --git a/distributeddatamgr/appdatamgrjstest/hap/src/main/js/test/RdbStoreDataShareJsunit.test.js b/distributeddatamgr/dataShare/dataSharejstest/hap/src/main/js/test/RdbStoreDataShareJsunit.test.js similarity index 100% rename from distributeddatamgr/appdatamgrjstest/hap/src/main/js/test/RdbStoreDataShareJsunit.test.js rename to distributeddatamgr/dataShare/dataSharejstest/hap/src/main/js/test/RdbStoreDataShareJsunit.test.js diff --git a/distributeddatamgr/appdatamgrjstest/hap/src/main/resources/base/element/string.json b/distributeddatamgr/dataShare/dataSharejstest/hap/src/main/resources/base/element/string.json similarity index 100% rename from distributeddatamgr/appdatamgrjstest/hap/src/main/resources/base/element/string.json rename to distributeddatamgr/dataShare/dataSharejstest/hap/src/main/resources/base/element/string.json diff --git a/distributeddatamgr/windowStage/dataShareRdbtest/entry/src/main/resources/base/media/icon.png b/distributeddatamgr/dataShare/dataSharejstest/hap/src/main/resources/base/media/icon.png similarity index 100% rename from distributeddatamgr/windowStage/dataShareRdbtest/entry/src/main/resources/base/media/icon.png rename to distributeddatamgr/dataShare/dataSharejstest/hap/src/main/resources/base/media/icon.png diff --git a/distributeddatamgr/dataShare/server/kvService/AppScope/app.json b/distributeddatamgr/dataShare/server/kvService/AppScope/app.json new file mode 100644 index 0000000000000000000000000000000000000000..741b21663370e8e1638275da29fef6eaaa2069cd --- /dev/null +++ b/distributeddatamgr/dataShare/server/kvService/AppScope/app.json @@ -0,0 +1,20 @@ +{ + "app": { + "bundleName": "com.samples.datasharekvtest", + "vendor": "example", + "versionCode": 1000000, + "versionName": "1.0.0", + "icon": "$media:app_icon", + "label": "$string:app_name", + "debug": false, + "distributedNotificationEnabled": true, + "keepAlive": true, + "singleUser": true, + "minAPIVersion": 9, + "targetAPIVersion": 9, + "car": { + "apiCompatibleVersion": 9, + "singleUser": false + } + } +} diff --git a/distributeddatamgr/dataShare/server/kvService/AppScope/resources/base/element/string.json b/distributeddatamgr/dataShare/server/kvService/AppScope/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..c1640a8a5aad1d4fa54058ebd92f25f88c362560 --- /dev/null +++ b/distributeddatamgr/dataShare/server/kvService/AppScope/resources/base/element/string.json @@ -0,0 +1,8 @@ +{ + "string": [ + { + "name": "app_name", + "value": "ActsKvServiceHap" + } + ] +} diff --git a/distributeddatamgr/windowStage/server/rdbService/entry/src/main/resources/base/media/icon.png b/distributeddatamgr/dataShare/server/kvService/AppScope/resources/base/media/app_icon.png similarity index 100% rename from distributeddatamgr/windowStage/server/rdbService/entry/src/main/resources/base/media/icon.png rename to distributeddatamgr/dataShare/server/kvService/AppScope/resources/base/media/app_icon.png diff --git a/distributeddatamgr/dataShare/server/kvService/BUILD.gn b/distributeddatamgr/dataShare/server/kvService/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..98fe5d946c10fd01f34c8c7ae8e3754b67934e4b --- /dev/null +++ b/distributeddatamgr/dataShare/server/kvService/BUILD.gn @@ -0,0 +1,42 @@ +# 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("//test/xts/tools/build/suite.gni") + +ohos_hap_assist_suite("ActsKvServiceHap") { + hap_profile = "./entry/src/main/module.json" + hap_name = "ActsKvServiceHap" + subsystem_name = "distributeddatamgr" + part_name = "data_share" + js_build_mode = "debug" + deps = [ + ":kvService_js_assets", + ":kvService_resources", + ] + ets2abc = true + certificate_profile = "./signature/openharmony_sx.p7b" +} +ohos_app_scope("dataShareKv_app_profile") { + app_profile = "AppScope/app.json" + sources = [ "AppScope/resources" ] +} + +ohos_js_assets("kvService_js_assets") { + source_dir = "./entry/src/main/ets" +} + +ohos_resources("kvService_resources") { + sources = [ "./entry/src/main/resources" ] + deps = [ ":dataShareKv_app_profile" ] + hap_profile = "./entry/src/main/module.json" +} diff --git a/distributeddatamgr/dataShare/server/kvService/entry/src/main/ets/Application/AbilityStage.ts b/distributeddatamgr/dataShare/server/kvService/entry/src/main/ets/Application/AbilityStage.ts new file mode 100644 index 0000000000000000000000000000000000000000..057140a9ef4ede2b1caa27691d773cba2c294c93 --- /dev/null +++ b/distributeddatamgr/dataShare/server/kvService/entry/src/main/ets/Application/AbilityStage.ts @@ -0,0 +1,22 @@ +/* +* 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 AbilityStage from "@ohos.application.AbilityStage" + +export default class MyAbilityStage extends AbilityStage { + onCreate() { + console.log("[ttt] [DataShareTest] MyAbilityStage onCreate"); + } +} \ No newline at end of file diff --git a/distributeddatamgr/dataShare/server/kvService/entry/src/main/ets/DataShareExtAbility/DataShareExtAbility.ts b/distributeddatamgr/dataShare/server/kvService/entry/src/main/ets/DataShareExtAbility/DataShareExtAbility.ts new file mode 100644 index 0000000000000000000000000000000000000000..251ae4b7b1057c83dcbefa8468ba28b1401ae6fb --- /dev/null +++ b/distributeddatamgr/dataShare/server/kvService/entry/src/main/ets/DataShareExtAbility/DataShareExtAbility.ts @@ -0,0 +1,338 @@ +/* +* 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 Extension from '@ohos.application.DataShareExtensionAbility' +import dataSharePredicates from '@ohos.data.dataSharePredicates' +import distributedData from '@ohos.data.distributedData'; +import fileIo from '@ohos.fileio' + + +let kvManager; +let kvdbStore; +let kvResultSet; +let result; + +const BUNDLE_NAME = 'com.samples.datasharetest'; +const STORE_ID = 'storeId'; + + +export default class DataShareExtAbility extends Extension { + private rdbStore_; + private kvdbStore_; + + + onCreate(want,callback) { + console.info('[ttt] [DataShareTest] <> DataShareExtAbility onCreate, want:' + want.abilityName); + let mKVMgrConfig = { + userInfo : { + userId : '0', + userType : distributedData.UserType.SAME_USER_ID + }, + bundleName: BUNDLE_NAME, + context : this.context + } + var options = { + createIfMissing : true, + encrypt : false, + backup : false, + autoSync : true, + kvStoreType : distributedData.KVStoreType.SINGLE_VERSION, + schema : {}, + securityLevel : distributedData.SecurityLevel.NO_LEVEL, + } + let name = new distributedData.FieldNode('name'); + name.type = distributedData.ValueType.STRING; + name.nullable = false; + name.default = 'name'; + + let age = new distributedData.FieldNode('age'); + age.type = distributedData.ValueType.INTEGER; + age.nullable = false; + age.default = '0'; + + let isStudent = new distributedData.FieldNode('isStudent'); + isStudent.type = distributedData.ValueType.STRING; + isStudent.nullable = false; + isStudent.default = 'false'; + + + let schema1 = new distributedData.Schema(); + schema1.root.appendChild(name); + schema1.root.appendChild(age); + schema1.root.appendChild(isStudent); + schema1.indexes = ['$.name', "$.age", "$.isStudent"]; + // options.kvStoreType = distributedData.KVStoreType.DEVICE_COLLABORATION; + options.schema = schema1; + distributedData.createKVManager(mKVMgrConfig, function (err, manager) { + if (err) { + console.info("[ttt] [DataShareTest] <> createKVManager err: " + err); + return; + } + console.info("[ttt] [DataShareTest] <> createKVManager success"); + kvManager = manager; + console.info('[ttt] [DataShareTest] <> createKVManager kvManager = ' + kvManager); + kvManager.getKVStore(STORE_ID, options, function (err, store) { + if (err) { + console.info("[ttt] [DataShareTest] <> getKVStore err: " + err); + return; + } + console.info("[ttt] [DataShareTest] <> getKVStore success"); + kvdbStore = store; + console.info('[ttt] [DataShareTest] <> createKVManager kvdbStore = ' + kvdbStore); + }); + callback(); + }); + result = this.context.cacheDir + '/datashare.txt' + console.info('[ttt] [DataAbilityTest] <> resultpath = ' + result); + } + + getFileTypes(uri: string, mimeTypeFilter: string, callback) { + console.info('[ttt] [DataShareTest] <> [getFileTypes] enter'); + let ret = new Array("type01", "type02", "type03"); + console.info('[ttt] [DataShareTest] <> [getFileTypes] leave, ret:' + ret); + let err = {"code":2}; + callback(err,ret); + return ret; + } + + async insert(uri, value, callback) { + console.info('[ttt] [DataShareTest] <> [insert] enterkvdb'); + if (value == null) { + console.info('[ttt] [DataShareTest] <> [insert] invalid valueBuckets'); + return; + } + console.info('[ttt] [DataShareTest] <> [insert] kvdb value = ' + JSON.stringify(value)); + let vbArr = new Array(); + let insertBucket = {"name":value.name, "age":value.age, "isStudent":String(value.isStudent)} + console.info('[ttt] [DataShareTest] <> [insert] kvdb insertBucket = ' + JSON.stringify(insertBucket)); + vbArr.push({ + "key":"testkey0", + "value": JSON.stringify(insertBucket) + }); + + console.info('[ttt] [DataShareTest] <> [insert] kvdb vbArr = ' + JSON.stringify(vbArr) + "?????????????"); + kvdbStore.putBatch(vbArr, function (err,data) { + if (err != undefined) { + console.info("[ttt] [DataShareTest] <> [insert kvdb put] callback err: " + err); + if (callback != undefined) { + callback(-1,-1); + } + }else{ + if (callback != undefined) { + callback(0,1); + } + } + console.info("[ttt] [DataShareTest] <> [insert kvdb put] callback data:" + JSON.stringify(data)); + }); + console.info('[ttt] [DataShareTest] <> [insert] leave'); + } + + update(uri, predicates, value, callback) { + console.info('[ttt] [DataShareTest] <> [update] enter'); + console.info('[ttt] [DataShareTest] <> [update] value = ' + JSON.stringify(value)); + console.info('[ttt] [DataShareTest] <> [update] predicates = ' + predicates); + + if (predicates == null || predicates == undefined) { + console.info('[ttt] [DataShareTest] <> [update] invalid predicates'); + return; + } + let vbArr = new Array(); + let keyName = "testkey0"; + let updateBucket = {"name":value.name, "age":value.age, "isStudent":String(value.isStudent)} +// let da = new dataShare.DataSharePredicates(); +// da.notEqualTo("$.name", "789"); +// kvdbStore.getResultSet(da, function (err, data) { +// if (err != undefined) { +// console.info("[ttt] [DataShareTest] <> [query kvdb get] callback err: " + err); +// return; +// } +// console.info("[ttt] [DataShareTest] <> [query kvdb get] callback data:" + JSON.stringify(data)); +// if (callback != undefined) { +// callback(err, data); +// } +// }) + + console.info('[ttt] [DataShareTest] <> [update] updateBucket = ' + JSON.stringify(updateBucket)); + console.info('[ttt] [DataShareTest] <> [update] keyName = ' + keyName); + vbArr.push({ + "key": keyName, + "value": JSON.stringify(updateBucket) + }); + console.info('[ttt] [DataShareTest] <> [update] vbArr = ' + JSON.stringify(vbArr)); + + + + kvdbStore.putBatch(vbArr, function (err,data) { + if (err != undefined) { + console.info("[ttt] [DataShareTest] <> [update kvdb put] callback err: " + JSON.stringify(err)); + if (callback != undefined) { + callback(-1,-1); + } + }else{ + if (callback != undefined) { + callback(0,1); + } + } + console.info("[ttt] [DataShareTest] <> [update kvdb put] callback data:" + JSON.stringify(data)); + }); + console.info('[ttt] [DataShareTest] <> [update] leave'); + } + + delete(uri, predicates, callback) { + console.info('[ttt] [DataShareTest] <> [delete] enter'); + if (predicates == null || predicates == undefined) { + console.info('[ttt] [DataShareTest] <> [delete] invalid predicates'); + return; + } + kvdbStore.delete(predicates, function(err, data) { + if (err != undefined) { + console.info("[ttt] [DataShareTest] <> [delete kvdb] callback err: " + err); + if (callback != undefined) { + callback(-1, -1); + } + }else { + console.info("[ttt] [DataShareTest] <> [delete kvdb] callback data:" + JSON.stringify(data)); + if (callback != undefined) { + callback(0, 1); + } + } + }); + console.info('[ttt] [DataShareTest] <> [delete] leave'); + } + + query(uri, predicates, columns, callback) { + console.info('[ttt] [DataShareTest] <> [query] enter'); + if (predicates == null || predicates == undefined) { + console.info('[ttt] [DataShareTest] <> [query] invalid predicates'); + } + console.info("[ttt] [DataShareTest] <> [query] getDADADADADADADA!!!") + if(kvResultSet != null || kvResultSet != undefined){ + kvdbStore.closeResultSet(kvResultSet,function (err, data) { + if (err != undefined) { + console.info("[ttt] [DataShareTest] <> [query kvdb closeResultSet] callback err: " + err); + return; + } + console.info("[ttt] [DataShareTest] <> [query kvdb closeResultSet] callback data:" + JSON.stringify(data)); + }) + } + console.info("[ttt] [DataShareTest] <> [RPF66666] " ); +// let da = new dataSharePredicates.DataSharePredicates(); +// da.notEqualTo("$.name", "789"); +// da.limit(1, 0); +// var query = new distributedData.Query(); +// query.notEqualTo("$.name", 3); +// query.limit(1, 0); + kvdbStore.getResultSet(predicates, function (err, data) { + if (err != undefined) { + console.info("[ttt] [DataShareTest] <> [query kvdb get] callback err: " + err); + return; + } + kvResultSet = data; + console.info("[ttt] [DataShareTest] <> [query kvdb get] getCount = " + kvResultSet.getCount()) + console.info("[ttt] [DataShareTest] <> [query kvdb get] callback data:" + JSON.stringify(data)); + if (callback != undefined) { + callback(err, data); + } + }) + console.info('[ttt] [DataShareTest] <> [query] leave'); + } + + getType(uri: string,callback) { + console.info('[ttt] [DataShareTest] <> [getType] enter'); + let ret = "image"; + console.info('[ttt] [DataShareTest] <> [getType] leave, ret:' + ret); + let err = {"code":2}; + callback(err,ret); + return ret; + } + + batchInsert(uri, valueBuckets, callback) { + console.info('[ttt] [DataShareTest] <> [batchInsert] enter'); + if (valueBuckets == null || valueBuckets.length == undefined) { + console.info('[ttt] [DataShareTest] <> [batchInsert] invalid valueBuckets'); + return; + } + console.info('[ttt] [DataShareTest] <> [batchInsert] valueBuckets.length:' + valueBuckets.length); + + console.info('[ttt] [DataShareTest] <> [batchInsert] valueBuckets.isStudent :' + JSON.stringify(valueBuckets[0].isStudent)); + + let vbArr = new Array(); + let batchInsertBucket = new Array(); + let num = 0; + for(let i = 0; i < valueBuckets.length; i++) { + console.info('[ttt] [DataShareTest] <> [batchInsert] valueBuckets.boolean :' + JSON.stringify(valueBuckets[i].isStudent)); + batchInsertBucket[i] = {"name":valueBuckets[i].name, "age":valueBuckets[i].age, "isStudent":String(valueBuckets[i].isStudent)} + vbArr.push({ + "key":"testkey"+num, + "value": JSON.stringify(batchInsertBucket[i]) + }); + num++; + } + + + console.info('[ttt] [DataShareTest] <> [batchInsert] valueBuckets :' + JSON.stringify(batchInsertBucket)); + kvdbStore.putBatch(vbArr, function(err, data) { + if (err != undefined) { + console.info("[ttt] [DataShareTest] <> [batchInsert kvdb] callback err: " + err); + if (callback != undefined) { + callback(-1, -1); + } + return; + }else{ + if (callback != undefined) { + callback(0,1); + } + } + console.info("[ttt] [DataShareTest] <> [batchInsert kvdb] callback data:" + JSON.stringify(data)); + + }); + console.info('[ttt] [DataShareTest] <> [batchInsert] leave'); + } + + + openFile(uri: string, mode: string, callback) { + console.info('[ttt] [DataAbilityTest] <> DataAbility openFile in'); + fileIo.open(result, 0o2 | 0o100, 0o666, function(err, fd) { + if(err) { + console.info('[ttt] [DataAbilityTest] <> OpenFile err = ' + err); + console.info('[ttt] [DataAbilityTest] <> OpenFile err = ' + JSON.stringify(err)); + } + console.log('[ttt] [DataAbilityTest] <> EtsFileIo fd =' + fd); + let num = fileIo.writeSync(fd, "this is a boring test of DataShare"); + console.info("[ttt] [DataAbillityTest] <> WriteSync length = " + num); + console.info("[ttt] [DataAbillityTest] <> WriteSync fd = " + fd); + callback(err,fd); + }) + } + + normalizeUri(uri: string,callback) { + console.info('[ttt] [DataShareTest] <> [normalizeUri] enter'); + let ret = "normalize+" + uri; + console.info('[ttt] [DataShareTest] <> [normalizeUri] leave, ret:' + ret); + let err = {"code":2}; + console.info('[ttt] [DataShareTest] <> [normalizeUri] enter!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!'); + callback(err,ret); + console.info('[ttt] [DataShareTest] <> [normalizeUri] leave!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!'); + } + + denormalizeUri(uri: string,callback) { + console.info('[ttt] [DataShareTest] <> [denormalizeUri] enter'); + let ret = "denormalize+" + uri; + console.info('[ttt] [DataShareTest] <> [denormalizeUri] leave, ret:' + ret); + let err = {"code":2}; + callback(err,ret); + return ret; + } +}; \ No newline at end of file diff --git a/distributeddatamgr/dataShare/server/kvService/entry/src/main/ets/MainAbility/MainAbility.ts b/distributeddatamgr/dataShare/server/kvService/entry/src/main/ets/MainAbility/MainAbility.ts new file mode 100644 index 0000000000000000000000000000000000000000..a8b406d0c22e1693aa87dcc99ac1485fb7616d84 --- /dev/null +++ b/distributeddatamgr/dataShare/server/kvService/entry/src/main/ets/MainAbility/MainAbility.ts @@ -0,0 +1,458 @@ +/* +* 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 Ability from '@ohos.application.Ability' +import ability_particleAbility from '@ohos.ability.particleAbility' +import dataSharePredicates from '@ohos.data.dataSharePredicates' +import dataShare from '@ohos.data.dataShare' + +import dataAbility from '@ohos.data.dataAbility' +import rdb from '@ohos.data.rdb'; + +import rpc from "@ohos.rpc"; + +import distributedData from '@ohos.data.distributedData'; +let kvManager; +let kvdbStore; + + +var seConnect = { + onConnect:function (elementName, proxy) { + console.info("[ttt] [DataShareTest] <> seConnect onConnect called."); + console.info("[ttt] [DataShareTest] <> seConnect onConnect elementName = " + elementName); + console.info("[ttt] [DataShareTest] <> seConnect onConnect proxy = " + proxy); + let data = rpc.MessageParcel.create(); + let reply = rpc.MessageParcel.create(); + let option = new rpc.MessageOption(); + data.writeInterfaceToken("connect-test"); + data.writeInt(111); + + console.info("[ttt] [DataShareTest] <> seConnect onConnect sendRequest."); + proxy.sendRequest(1, data, reply, option) + .then(function (result) { + if (result.errCode === 0) { + // let msg = reply.readString(); + let msg = result.reply.readInt(); + console.info("[ttt] [DataShareTest] <> seConnect reply msg: " + msg); + } else { + console.info("[ttt] [DataShareTest] <> seConnect sendRequest failed, errCode: " + result.errCode); + } + // callback没有返回值,默认返回undefined + }).catch(function (e) { + console.info("[ttt] [DataShareTest] <> seConnect sendRequest got exception: " + e); + }).finally (async () => { + console.info("[ttt] [DataShareTest] <> seConnect sendRequest ends, reclaim parcel"); + data.reclaim(); + reply.reclaim(); + }) + }, + onDisconnect:function (elementName) { + console.info("[ttt] [DataShareTest] <> seConnect onDisconnect"); + }, + onFailed:function (code) { + console.info("[ttt] [DataShareTest] <> seConnect onFailed"); + } +}; + +let dseProxy = 0; +let dseUri = ("datashare:///com.samples.datasharetest.DataShare"); + +var dseConnect = { + onConnect:function (elementName, proxy) { + console.info("[ttt] [DataShareTest] <> dseConnect onConnect called."); + // console.info("[ttt] [DataShareTest] <> dseConnect onConnect elementName = " + elementName); + // console.info("[ttt] [DataShareTest] <> dseConnect onConnect proxy = " + proxy); + dseProxy = proxy; + }, + onDisconnect:function (elementName) { + console.info("[ttt] [DataShareTest] <> dseConnect onDisconnect, elementName:" + elementName); + }, + onFailed:function (code) { + console.info("[ttt] [DataShareTest] <> dseConnect onFailed, code:" + code); + } +}; + +let seConnectionId = -1; +let dseConnectionId = -1; + +let seWant = { + "bundleName": "com.samples.datasharetest", + "abilityName": "ServiceExtAbility", +} + +let dseWant = { + "bundleName": "com.samples.datasharetest", + "abilityName": "DataShareExtAbility", +} + +export function onCallback() { + console.info("[ttt] [DataShareTest] <> **** Observer on callback ****"); +} + +export function offCallback() { + console.info("[ttt] [DataShareTest] <> **** Observer off callback ****"); +} + +export default class MainAbility extends Ability { + onCreate(want, launchParam) { + // Ability is creating, initialize resources for this ability + console.info("[ttt] [DataShareTest] <> MainAbility onCreate") + globalThis.abilityWant = want; + } + + onDestroy() { + // Ability is destroying, release resources for this ability + console.info("[ttt] [DataShareTest] <> MainAbility onDestroy") + } + + onWindowStageCreate(windowStage) { + // Main window is created, set main page for this ability + console.info("[ttt] [DataShareTest] <> MainAbility onWindowStageCreate") + globalThis.abilityContext = this.context; + + let context = this.context; +// console.info('[ttt] [DataShareTest] <> MainAbility onWindowStageCreate this.context.stageMode:' + context.stageMode); +// console.info('[ttt] [DataShareTest] <> MainAbility onWindowStageCreate this.context.bundleName:' + context.bundleName); +// console.info('[ttt] [DataShareTest] <> MainAbility onWindowStageCreate this.context.name:' + context.name); + globalThis.connectServiceExtAbility = (async () => { + console.info("[ttt] [DataShareTest] <> connectServiceExtAbility begin"); + seConnectionId = await context.connectAbility(seWant, seConnect); + console.info("[ttt] [DataShareTest] <> connectServiceExtAbility end, seConnectionId:" + seConnectionId); + }) + + globalThis.disconnectServiceExtAbility = (async () => { + console.info("[ttt] [DataShareTest] <> disconnectServiceExtAbility begin"); + await context.disconnectAbility(seConnectionId).then((data) => { + console.info("[ttt] [DataShareTest] <> startAbility success:" + JSON.stringify(data)); + }).catch((error) => { + console.error("[ttt] [DataShareTest] <> startAbility failed:" + JSON.stringify(error)); + }); + console.info("[ttt] [DataShareTest] <> disconnectServiceExtAbility end, seConnectionId:" + seConnectionId); + }) + + + + globalThis.connectDataShareExtAbility = (async () => { + console.info("[ttt] [DataShareTest] <> connectDataShareExtAbility begin"); +// globalThis.dsHelper = await dataShare.createDataShareHelper(this.context,dseUri); + + await dataShare.createDataShareHelper(globalThis.abilityContext, dseUri, (err,data)=>{ + globalThis.dsHelper = data; + console.info("[ttt] [DataShareTest] <> ----- 1 -----, globalThis.dsHelper = " + globalThis.dsHelper); + console.info("[ttt] [DataShareTest] <> ----- 2 -----, data = " + data); + console.info("[ttt] [DataShareTest] <> ----- 3 -----, err = " + err); + console.info("[ttt] [DataShareTest] <> ----- 4 -----, JSON.stringify(err) = " + JSON.stringify(err)); + }); + +// await dataShare.createDataShareHelper(this.context,dseUri).then((data)=>{ +// globalThis.dsHelper = data; +// console.info("[ttt] [DataShareTest] <> ----- 1 -----, globalThis.dsHelper = " + globalThis.dsHelper); +// console.info("[ttt] [DataShareTest] <> ----- 2 -----, data = " + data); +// }).catch((err)=>{ +// console.info("[ttt] [DataShareTest] <> ----- 3 -----, err = " + err); +// console.info("[ttt] [DataShareTest] <> ----- 4 -----, JSON.stringify(err) = " + JSON.stringify(err)); +// }) + dseConnectionId = await context.connectAbility(dseWant, dseConnect); +// console.info("[ttt] [DataShareTest] <> ----- 5 -----, globalThis.dsHelper = " + globalThis.dsHelper); +// console.info("[ttt] [DataShareTest] <> connectDataShareExtAbility end, dseConnectionId:" + dseConnectionId); + }) + + globalThis.disconnectDataShareExtAbility = (async () => { + console.info("[ttt] [DataShareTest] <> disconnectDataShareExtAbility begin"); + await context.disconnectAbility(dseConnectionId).then((data) => { + console.info("[ttt] [DataShareTest] <> disconnectDataShareExtAbility success:" + JSON.stringify(data)); + }).catch((error) => { + console.error("[ttt] [DataShareTest] <> disconnectDataShareExtAbility failed:" + JSON.stringify(error)); + }); + globalThis.dsHelper = null; + console.info("[ttt] [DataShareTest] <> disconnectDataShareExtAbility end, dseConnectionId:" + dseConnectionId); + }) + + globalThis.on = (async () => { + console.info("[ttt] [DataShareTest] <> on begin"); + if (globalThis.dsHelper == null) { + console.info("[ttt] [DataShareTest] <> on end, DSHelper is null"); + return; + } + await globalThis.dsHelper.on("dataChange", dseUri, onCallback); + console.info("[ttt] [DataShareTest] <> on end"); + }) + + globalThis.off = (async () => { + console.info("[ttt] [DataShareTest] <> off begin"); + if (globalThis.dsHelper == null) { + console.info("[ttt] [DataShareTest] <> off end, DSHelper is null"); + return; + } + await globalThis.dsHelper.off("dataChange", dseUri); + await globalThis.dsHelper.off("dataChange", dseUri, offCallback); + console.info("[ttt] [DataShareTest] <> off end"); + }) + + // globalThis.openFile = (async () => { + // console.info("[ttt] [DataShareTest] <> openFile begin"); + // if (globalThis.dsHelper == null) { + // console.info("[ttt] [DataShareTest] <> openFile end, DSHelper is null"); + // return; + // } + // let result = await globalThis.dsHelper.openFile(dseUri, "rwt"); + // console.info("[ttt] [DataShareTest] <> openFile end, result:" + result); + // return result; + // }) + + globalThis.query = (async () => { + console.info("[ttt] [DataShareTest] <> query begin"); + let da = new dataSharePredicates.DataSharePredicates(); + if (da == null || da == undefined) { + console.info("[ttt] [DataShareTest] <> da is null or undefined"); + return; + } + let count = 0; + if (globalThis.dsHelper == null) { + console.info("[ttt] [DataShareTest] <> query end, DSHelper is null"); + return; + } + da.equalTo("name", "ZhangSan"); + let result = await globalThis.dsHelper.query(dseUri, da, ["*"], (err,resultSet)=> { + if (err) { + console.error("[ttt] [DataShareTest] <> query err:" + JSON.stringify(err)); + console.info("[ttt] [DataShareTest] <> query data:" + resultSet); + console.info("[ttt] [DataShareTest] <> query data.rowCount:" + resultSet.rowCount); + console.info("[ttt] [DataShareTest] <> query data.columnCount:" + resultSet.columnCount); + } else { + console.info("[ttt] [DataShareTest] <> query data:" + resultSet); + console.info("[ttt] [DataShareTest] <> query data.rowCount:" + resultSet.rowCount); + console.info("[ttt] [DataShareTest] <> query data.columnCount:" + resultSet.columnCount); + } + }); + if (result != undefined) { + count = result.rowCount; + } + console.info("[ttt] [DataShareTest] <> query end, count:" + count); + return count; + }) + + globalThis.insert = (async () => { + + console.info("[ttt] [DataShareTest] <> insert begin"); + if (globalThis.dsHelper == null) { + console.info("[ttt] [DataShareTest] <> insert end, DSHelper is null"); + return; + } + let vb = {"age": 21} + + let v8Arr = []; + let ar = new Uint8Array([1,2,3,4,5,6]); + let arr = new Uint8Array([4,5,6,7]); + let vb1 = {"key":ar,"value":arr} + v8Arr.push(vb1); + + console.info("[ttt] [DataShareTest] <> insert vb:" + JSON.stringify(vb)); + console.info("[ttt] [DataShareTest] <> insert vb:" + JSON.stringify(vb)); + let ret = await globalThis.dsHelper.insert(dseUri, vb, (err,ret)=>{ + if(err){ + console.error("[ttt] [DataShareTest] <> insert err:" + JSON.stringify(err)); + console.info("[ttt] [DataShareTest] <> insert data:" + ret); + }else { + console.info("[ttt] [DataShareTest] <> insert data:" + ret); + } + }); + await globalThis.notifyChange(); + console.info("[ttt] [DataShareTest] <> insert end, ret:" + ret); + return ret; + }) + + globalThis.update = (async () => { + console.info("[ttt] [DataShareTest] <> update begin"); + if (globalThis.dsHelper == null) { + console.info("[ttt] [DataShareTest] <> update end, DSHelper is null"); + return; + } + console.info("[ttt] [DataShareTest] <> update begin RPF666"); + let da = new dataSharePredicates.DataSharePredicates(); + console.info("[ttt] [DataShareTest] <> update begin RPF777"); + if (da == null || da == undefined) { + console.info("[ttt] [DataShareTest] <> da is null or u" + + "ndefined"); + return; + } +// da.equalTo("name", "ZhangSan"); + let ret = await globalThis.dsHelper.update(dseUri, da, {"age": 31}, (err,ret)=>{ + if(err){ + console.error("[ttt] [DataShareTest] <> update err:" + JSON.stringify(err)); + console.info("[ttt] [DataShareTest] <> update data:" + ret); + }else { + console.info("[ttt] [DataShareTest] <> update data:" + ret); + } + }); + await globalThis.notifyChange(); + console.info("[ttt] [DataShareTest] <> update end, result:" + ret); + return ret; + }) + + globalThis.delete = (async () => { + console.info("[ttt] [DataShareTest] <> delete begin"); + if (globalThis.dsHelper == null) { + console.info("[ttt] [DataShareTest] <> delete end, DSHelper is null"); + return; + } + let da = new dataSharePredicates.DataSharePredicates(); + if (da == null || da == undefined) { + console.info("[ttt] [DataShareTest] <> da is null or undefined"); + return; + } +// da.equalTo("name", "ZhangSan"); + let ret = globalThis.dsHelper.delete(dseUri, da, (err,ret)=>{ + if(err){ + console.error("[ttt] [DataShareTest] <> delete err:" + JSON.stringify(err)); + console.info("[ttt] [DataShareTest] <> delete data:" + ret); + }else { + console.info("[ttt] [DataShareTest] <> delete data:" + ret); + } + }); + await globalThis.notifyChange(); + console.info("[ttt] [DataShareTest] <> delete end, result:" + ret); + return ret; + }) + + globalThis.batchInsert = (async () => { + console.info("[ttt] [DataShareTest] <> batchInsert begin"); + if (globalThis.dsHelper == null) { + console.info("[ttt] [DataShareTest] <> batchInsert end, DSHelper is null"); + return; + } + let ar = new Uint8Array([1,2,3,4,5,6]); + let arr = new Uint8Array([4,5,6,7]); + let people = new Array( + {"name": "LiSi", "age": 41, "Binary": ar}, + {"name": "WangWu", "age": 21, "Binary": arr}, + {"name": "ZhaoLiu", "age": 61, "Binary": arr}); +// let ar = new Uint8Array([1,2,3,4,5,6]); +// let arr = new Uint8Array([4,5,6,7]); +// let v8Arr = []; +// let vb = {"key":ar,"jii":arr,"value":arr,"njj":arr}; +// v8Arr.push(vb) + let ret = await globalThis.dsHelper.batchInsert(dseUri, people); + await globalThis.notifyChange(); + console.info("[ttt] [DataShareTest] <> batchInsert end, result:" + ret); + return ret; + }) + + globalThis.notifyChange = (async () => { + console.info("[ttt] [DataShareTest] <> notifyChange begin"); + if (globalThis.dsHelper == null) { + console.info("[ttt] [DataShareTest] <> notifyChange end, DSHelper is null"); + return; + } + await globalThis.dsHelper.notifyChange(dseUri); + console.info("[ttt] [DataShareTest] <> notifyChange end"); + }) + + globalThis.getType = (async () => { + console.info("[ttt] [DataShareTest] <> getType begin"); + if (globalThis.dsHelper == null) { + console.info("[ttt] [DataShareTest] <> getType end, DSHelper is null"); + return; + } + let result; + globalThis.dsHelper.getType(dseUri,(err,data)=>{ + if(err){ + console.info("[ttt] [DataShareTest] <> getType err, err:" + JSON.stringify(err)); + console.info("[ttt] [DataShareTest] <> getType end, err:" + JSON.stringify(data)); + result = data; + }else{ + console.info("[ttt] [DataShareTest] <> getType end, err:" + JSON.stringify(data)); + result = data; + } + }); + console.info("[ttt] [DataShareTest] <> getType end, result:" + result); + return result; + }) + + globalThis.getFileTypes = (async () => { + console.info("[ttt] [DataShareTest] <> getFileTypes begin"); + if (globalThis.dsHelper == null) { + console.info("[ttt] [DataShareTest] <> getFileTypes end, DSHelper is null"); + return; + } + let result = await globalThis.dsHelper.getFileTypes(dseUri, "image/*",(err,data)=>{ + if(err){ + console.info("[ttt] [DataShareTest] <> getType err, err:" + JSON.stringify(err)); + console.info("[ttt] [DataShareTest] <> getType end, err:" + JSON.stringify(data)); + result = data; + }else{ + console.info("[ttt] [DataShareTest] <> getType end, err:" + JSON.stringify(data)); + result = data; + } + }); + return result; + }) + + globalThis.normalizeUri = (async () => { + console.info("[ttt] [DataShareTest] <> normalizeUri begin"); + if (globalThis.dsHelper == null) { + console.info("[ttt] [DataShareTest] <> normalizeUri end, DSHelper is null"); + return; + } + let result = await globalThis.dsHelper.normalizeUri(dseUri,(err,data)=>{ + if(err){ + console.info("[ttt] [DataShareTest] <> normalizeUri err, err:" + JSON.stringify(err)); +// console.info("[ttt] [DataShareTest] <> getType end, data:" + JSON.stringify(data)); +// result = data; + }else{ + console.info("[ttt] [DataShareTest] <> normalizeUri end, data:" + JSON.stringify(data)); + result = data; + } + }); + return result; + }) + + globalThis.denormalizeUri = (async () => { + console.info("[ttt] [DataShareTest] <> denormalizeUri begin"); + if (globalThis.dsHelper == null) { + console.info("[ttt] [DataShareTest] <> denormalizeUri end, DSHelper is null"); + return; + } + let result = await globalThis.dsHelper.denormalizeUri(dseUri,(err,data)=>{ + if(err){ + console.info("[ttt] [DataShareTest] <> denormalizeUri err, err:" + JSON.stringify(err)); +// console.info("[ttt] [DataShareTest] <> getType end, err:" + JSON.stringify(data)); +// result = data; + }else{ + console.info("[ttt] [DataShareTest] <> denormalizeUri end, err:" + JSON.stringify(data)); + result = data; + } + }); + return result; + }) + + windowStage.setUIContent(this.context, "pages/index", null) + } + + onWindowStageDestroy() { + // Main window is destroyed, release UI related resources + console.info("[ttt] [DataShareTest] <> MainAbility onWindowStageDestroy") + } + + onForeground() { + // Ability has brought to foreground + console.info("[ttt] [DataShareTest] <> MainAbility onForeground") + } + + onBackground() { + // Ability has back to background + console.info("[ttt] [DataShareTest] <> MainAbility onBackground") + } +}; diff --git a/distributeddatamgr/dataShare/server/kvService/entry/src/main/ets/pages/index.ets b/distributeddatamgr/dataShare/server/kvService/entry/src/main/ets/pages/index.ets new file mode 100644 index 0000000000000000000000000000000000000000..826b42a8f8e46781aa47c56cfa75ec981dc2aaa2 --- /dev/null +++ b/distributeddatamgr/dataShare/server/kvService/entry/src/main/ets/pages/index.ets @@ -0,0 +1,413 @@ +/* +* 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 dataShare from '@ohos.data.dataShare' + +@Entry +@Component +struct Index { + @State message: string = "Main thread message filed" + + build() { + Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) { + Text('DataShare Extension Ability Test') + .fontSize(40) + .fontWeight(FontWeight.Bold) + .onClick(async () => { +// console.info('[ttt] [DataShareTest] <> dataSharePredicates build begin'); +// let da = new dataShare.DataSharePredicates(); +// da.equalTo("name", "zhangsan"); +// da.notEqualTo("name", "lisi"); +// da.beginWrap(); +// da.endWrap(); +// da.or(); +// da.and(); +// da.contains("name", "zhang"); +// da.beginsWith("name", "z"); +// da.endsWith("name", "n"); +// da.isNull("name"); +// da.isNotNull("name"); +// da.like("name", "zhang"); +// da.unlike("name", "li"); +// da.glob("name", "???"); +// da.between("age", 18, 22); +// da.notBetween("age", 18, 22); +// da.greaterThan("age", 18); +// da.lessThan("age", 22); +// da.greaterThanOrEqualTo("age", 18); +// da.lessThanOrEqualTo("age", 22); +// da.orderByAsc("age"); +// da.orderByDesc("age"); +// da.distinct(); +// da.limit(10, 5); +// da.groupBy(["name", "age"]); +// da.indexedBy("name"); +// da.in("name", []); +// da.notIn("name", []); +// da.prefixKey("name"); +// console.info('[ttt] [DataShareTest] <> dataSharePredicates = ' + JSON.stringify(da)); +// console.info('[ttt] [DataShareTest] <> dataSharePredicates build end'); + }) + + Text(`${this.message}`) + .fontSize(30) + .height('15%') + .width('100%') + .textAlign(TextAlign.Center) + +// Row() { +// Button() { +// Text('ConnectServiceExtension') +// .fontSize(25) +// .fontWeight(FontWeight.Bold) +// }.type(ButtonType.Capsule) +// .margin({ +// top: 20 +// }) +// .width('45%') +// .height('8%') +// .backgroundColor('#0ddffb') +// .onClick(async () => { +// console.info('[ttt] [DataShareTest] <> ConnectServiceExtension onclick enter') +// this.message = 'ConnectServiceExtension onclick' +// globalThis.connectServiceExtAbility() +// console.info('[ttt] [DataShareTest] <> ConnectServiceExtension onclick leave') +// }) +// +// Button() { +// Text('DisconnectServiceExtension') +// .fontSize(25) +// .fontWeight(FontWeight.Bold) +// }.type(ButtonType.Capsule) +// .margin({ +// top: 20 +// }) +// .width('45%') +// .height('8%') +// .backgroundColor('#0ddffb') +// .onClick(async () => { +// console.info('[ttt] [DataShareTest] <> DisconnectServiceExtension onclick enter') +// this.message = 'DisconnectServiceExtension onclick' +// globalThis.disconnectServiceExtAbility() +// console.info('[ttt] [DataShareTest] <> DisconnectServiceExtension onclick leave') +// }) +// } + + Row() { + Button() { + Text('Connect') + .fontSize(25) + .fontWeight(FontWeight.Bold) + }.type(ButtonType.Capsule) + .margin({ + top: 20 + }) + .width('45%') + .height('8%') + .backgroundColor('#0ddffb') + .onClick(async () => { + console.info('[ttt] [DataShareTest] <> Connect onclick enter') + this.message = 'Connect onclick' + await globalThis.connectDataShareExtAbility() + console.info('[ttt] [DataShareTest] <> Connect onclick leave') + }) + + Button() { + Text('Disconnect') + .fontSize(25) + .fontWeight(FontWeight.Bold) + }.type(ButtonType.Capsule) + .margin({ + top: 20 + }) + .width('45%') + .height('8%') + .backgroundColor('#0ddffb') + .onClick(async () => { + console.info('[ttt] [DataShareTest] <> Disconnect onclick enter') + this.message = 'Disconnect onclick' + await globalThis.disconnectDataShareExtAbility() + console.info('[ttt] [DataShareTest] <> Disconnect onclick leave') + }) + } + + Row() { + Button() { + Text('On') + .fontSize(25) + .fontWeight(FontWeight.Bold) + }.type(ButtonType.Capsule) + .margin({ + top: 20 + }) + .width('45%') + .height('8%') + .backgroundColor('#0ddffb') + .onClick(async () => { + console.info('[ttt] [DataShareTest] <> On onclick enter') + this.message = '~ On onclick' + try { + await globalThis.on(); + } catch (err) { + console.error('[ttt] [DataAbilityTest] Observer on catch(err)====>:' + err); + } + console.info('[ttt] [DataShareTest] <> On onclick leave') + }) + + Button() { + Text('Off') + .fontSize(25) + .fontWeight(FontWeight.Bold) + }.type(ButtonType.Capsule) + .margin({ + top: 20 + }) + .width('45%') + .height('8%') + .backgroundColor('#0ddffb') + .onClick(async () => { + console.info('[ttt] [DataShareTest] <> Off onclick enter') + this.message = '~ Off onclick' + try { + await globalThis.off(); + } catch (err) { + console.error('[ttt] [DataAbilityTest] Observer Off catch(err)====>:' + err); + } + console.info('[ttt] [DataShareTest] <> Off onclick leave') + }) + +// Button() { +// Text('OpenFile') +// .fontSize(25) +// .fontWeight(FontWeight.Bold) +// }.type(ButtonType.Capsule) +// .margin({ +// top: 20 +// }) +// .width('30%') +// .height('8%') +// .backgroundColor('#0ddffb') +// .onClick(async () => { +// console.info('[ttt] [DataShareTest] <> OpenFile onclick enter') +// this.message = 'OpenFile onclick' +// let ret = await globalThis.openFile() +// this.message += "\n\n Test Result: " + ret; +// console.info('[ttt] [DataShareTest] <> OpenFile onclick leave') +// }) + } + + Row() { + Button() { + Text('Query') + .fontSize(25) + .fontWeight(FontWeight.Bold) + }.type(ButtonType.Capsule) + .margin({ + top: 20 + }) + .width('45%') + .height('8%') + .backgroundColor('#0ddffb') + .onClick(async () => { + console.info('[ttt] [DataShareTest] <> Query onclick enter') + this.message = 'Query onclick' + let ret = await globalThis.query() + this.message += "\n\n Test Result: " + ret; + console.info('[ttt] [DataShareTest] <> Query onclick leave') + }) + + Button() { + Text('Insert') + .fontSize(25) + .fontWeight(FontWeight.Bold) + }.type(ButtonType.Capsule) + .margin({ + top: 20 + }) + .width('45%') + .height('8%') + .backgroundColor('#0ddffb') + .onClick(async () => { + console.info('[ttt] [DataShareTest] <> Insert onclick enter') + this.message = 'Insert onclick' + let ret = await globalThis.insert() + this.message += "\n\n Test Result: " + ret; + console.info('[ttt] [DataShareTest] <> Insert onclick leave') + }) + } + + Row() { + Button() { + Text('Update') + .fontSize(25) + .fontWeight(FontWeight.Bold) + }.type(ButtonType.Capsule) + .margin({ + top: 20 + }) + .width('45%') + .height('8%') + .backgroundColor('#0ddffb') + .onClick(async () => { + console.info('[ttt] [DataShareTest] <> Update onclick enter') + this.message = 'Update onclick' + let ret = await globalThis.update() + this.message += "\n\n Test Result: " + ret; + console.info('[ttt] [DataShareTest] <> Update onclick leave') + }) + + Button() { + Text('Delete') + .fontSize(25) + .fontWeight(FontWeight.Bold) + }.type(ButtonType.Capsule) + .margin({ + top: 20 + }) + .width('45%') + .height('8%') + .backgroundColor('#0ddffb') + .onClick(async () => { + console.info('[ttt] [DataShareTest] <> Delete onclick enter') + this.message = 'Delete onclick' + let ret = await globalThis.delete() + this.message += "\n\n Test Result: " + ret; + console.info('[ttt] [DataShareTest] <> Delete onclick leave') + }) + } + + Row() { + Button() { + Text('BatchInsert') + .fontSize(25) + .fontWeight(FontWeight.Bold) + }.type(ButtonType.Capsule) + .margin({ + top: 20 + }) + .width('45%') + .height('8%') + .backgroundColor('#0ddffb') + .onClick(async () => { + console.info('[ttt] [DataShareTest] <> BatchInsert onclick enter') + this.message = 'BatchInsert onclick' + let ret = await globalThis.batchInsert() + this.message += "\n\n Test Result: " + ret; + console.info('[ttt] [DataShareTest] <> BatchInsert onclick leave') + }) + + Button() { + Text('NotifyChange') + .fontSize(25) + .fontWeight(FontWeight.Bold) + }.type(ButtonType.Capsule) + .margin({ + top: 20 + }) + .width('45%') + .height('8%') + .backgroundColor('#0ddffb') + .onClick(async () => { + console.info('[ttt] [DataShareTest] <> NotifyChange onclick enter') + this.message = 'NotifyChange onclick' + await globalThis.notifyChange() + console.info('[ttt] [DataShareTest] <> NotifyChange onclick leave') + }) + } + + Row() { + Button() { + Text('GetType') + .fontSize(25) + .fontWeight(FontWeight.Bold) + }.type(ButtonType.Capsule) + .margin({ + top: 20 + }) + .width('45%') + .height('8%') + .backgroundColor('#0ddffb') + .onClick(async () => { + console.info('[ttt] [DataShareTest] <> GetType onclick enter') + this.message = 'GetType onclick' + let ret = await globalThis.getType() + this.message += "\n\n Test Result: " + ret; + console.info('[ttt] [DataShareTest] <> GetType onclick leave') + }) + + Button() { + Text('GetFileTypes') + .fontSize(25) + .fontWeight(FontWeight.Bold) + }.type(ButtonType.Capsule) + .margin({ + top: 20 + }) + .width('45%') + .height('8%') + .backgroundColor('#0ddffb') + .onClick(async () => { + console.info('[ttt] [DataShareTest] <> GetFileTypes onclick enter') + this.message = 'GetFileTypes onclick' + let ret = await globalThis.getFileTypes() + this.message += "\n\n Test Result: " + ret; + console.info('[ttt] [DataShareTest] <> GetFileTypes onclick leave') + }) + } + + Row() { + Button() { + Text('NormalizeUri') + .fontSize(25) + .fontWeight(FontWeight.Bold) + }.type(ButtonType.Capsule) + .margin({ + top: 20 + }) + .width('45%') + .height('8%') + .backgroundColor('#0ddffb') + .onClick(async () => { + console.info('[ttt] [DataShareTest] <> NormalizeUri onclick enter') + this.message = 'NormalizeUri onclick' + let ret = await globalThis.normalizeUri() + this.message += "\n\n Test Result: " + ret; + console.info('[ttt] [DataShareTest] <> NormalizeUri onclick leave') + }) + + Button() { + Text('DenormalizeUri') + .fontSize(25) + .fontWeight(FontWeight.Bold) + }.type(ButtonType.Capsule) + .margin({ + top: 20 + }) + .width('45%') + .height('8%') + .backgroundColor('#0ddffb') + .onClick(async () => { + console.info('[ttt] [DataShareTest] <> DenormalizeUri onclick enter') + this.message = 'DenormalizeUri onclick' + let ret = await globalThis.denormalizeUri() + this.message += "\n\n Test Result: " + ret; + console.info('[ttt] [DataShareTest] <> DenormalizeUri onclick leave') + }) + } + } + .width('100%') + .height('100%') + } +} \ No newline at end of file diff --git a/distributeddatamgr/dataShare/server/kvService/entry/src/main/module.json b/distributeddatamgr/dataShare/server/kvService/entry/src/main/module.json new file mode 100644 index 0000000000000000000000000000000000000000..fbf4887a657fc3f56abfa64db45154fecb32916c --- /dev/null +++ b/distributeddatamgr/dataShare/server/kvService/entry/src/main/module.json @@ -0,0 +1,49 @@ +{ + "module": { + "name": "entry", + "type": "entry", + "srcEntrance": "./ets/Application/AbilityStage.ts", + "description": "$string:phone_entry_dsc", + "mainElement": "MainAbility", + "deviceTypes": [ + "default" + ], + "deliveryWithInstall": true, + "installationFree": false, + "pages": "$profile:main_pages", + "uiSyntax": "ets", + "abilities": [ + { + "name": "MainAbility", + "srcEntrance": "./ets/MainAbility/MainAbility.ts", + "description": "$string:phone_entry_main", + "icon": "$media:icon", + "label": "$string:entry_label", + "visible": true, + "skills": [ + { + "entities": [ + "entity.system.home" + ], + "actions": [ + "action.system.home" + ] + } + ], + "startWindowIcon": "$media:icon", + "startWindowBackground": "$color:color_1" + } + ], + "extensionAbilities": [ + { + "srcEntrance": "./ets/DataShareExtAbility/DataShareExtAbility.ts", + "name": "DataShareExtAbility", + "icon": "$media:icon", + "description": "$string:description_datashareextability", + "type": "dataShare", + "uri": "datashare://com.samples.datasharekvtest.DataShare", + "visible": true + } + ] + } +} \ No newline at end of file diff --git a/distributeddatamgr/windowStage/server/rdbService/entry/src/main/resources/base/element/datashare.json b/distributeddatamgr/dataShare/server/kvService/entry/src/main/resources/base/element/datashare.json similarity index 100% rename from distributeddatamgr/windowStage/server/rdbService/entry/src/main/resources/base/element/datashare.json rename to distributeddatamgr/dataShare/server/kvService/entry/src/main/resources/base/element/datashare.json diff --git a/distributeddatamgr/dataShare/server/kvService/entry/src/main/resources/base/element/string.json b/distributeddatamgr/dataShare/server/kvService/entry/src/main/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..4323c3d122e2d06897be45ec200cd0284258415d --- /dev/null +++ b/distributeddatamgr/dataShare/server/kvService/entry/src/main/resources/base/element/string.json @@ -0,0 +1,40 @@ +{ + "string": [ + { + "name": "phone_entry_dsc", + "value": "i am an entry for phone" + }, + { + "name": "phone_entry_main", + "value": "the phone entry ability" + }, + { + "name": "entry_label", + "value": "ActsKvServiceHap" + }, + { + "name": "form_description", + "value": "my form" + }, + { + "name": "serviceability_description", + "value": "my whether" + }, + { + "name": "description_application", + "value": "ActsKvServiceHap" + }, + { + "name": "app_name", + "value": "ActsKvServiceHap" + }, + { + "name": "description_datashareextability", + "value": "description_datashareextability" + }, + { + "name": "description_serviceability", + "value": "description_serviceability" + } + ] +} diff --git a/distributeddatamgr/dataShare/server/kvService/entry/src/main/resources/base/media/icon.png b/distributeddatamgr/dataShare/server/kvService/entry/src/main/resources/base/media/icon.png new file mode 100644 index 0000000000000000000000000000000000000000..ce307a8827bd75456441ceb57d530e4c8d45d36c Binary files /dev/null and b/distributeddatamgr/dataShare/server/kvService/entry/src/main/resources/base/media/icon.png differ diff --git a/distributeddatamgr/windowStage/server/rdbService/entry/src/main/resources/base/profile/form_config.json b/distributeddatamgr/dataShare/server/kvService/entry/src/main/resources/base/profile/form_config.json similarity index 100% rename from distributeddatamgr/windowStage/server/rdbService/entry/src/main/resources/base/profile/form_config.json rename to distributeddatamgr/dataShare/server/kvService/entry/src/main/resources/base/profile/form_config.json diff --git a/distributeddatamgr/windowStage/server/rdbService/entry/src/main/resources/base/profile/main_pages.json b/distributeddatamgr/dataShare/server/kvService/entry/src/main/resources/base/profile/main_pages.json similarity index 100% rename from distributeddatamgr/windowStage/server/rdbService/entry/src/main/resources/base/profile/main_pages.json rename to distributeddatamgr/dataShare/server/kvService/entry/src/main/resources/base/profile/main_pages.json diff --git a/distributeddatamgr/windowStage/server/rdbService/signature/openharmony_sx.p7b b/distributeddatamgr/dataShare/server/kvService/signature/openharmony_sx.p7b similarity index 100% rename from distributeddatamgr/windowStage/server/rdbService/signature/openharmony_sx.p7b rename to distributeddatamgr/dataShare/server/kvService/signature/openharmony_sx.p7b diff --git a/distributeddatamgr/windowStage/server/rdbService/AppScope/app.json b/distributeddatamgr/dataShare/server/rdbService/AppScope/app.json similarity index 100% rename from distributeddatamgr/windowStage/server/rdbService/AppScope/app.json rename to distributeddatamgr/dataShare/server/rdbService/AppScope/app.json diff --git a/distributeddatamgr/windowStage/server/rdbService/AppScope/resources/base/element/string.json b/distributeddatamgr/dataShare/server/rdbService/AppScope/resources/base/element/string.json similarity index 100% rename from distributeddatamgr/windowStage/server/rdbService/AppScope/resources/base/element/string.json rename to distributeddatamgr/dataShare/server/rdbService/AppScope/resources/base/element/string.json diff --git a/distributeddatamgr/dataShare/server/rdbService/AppScope/resources/base/media/app_icon.png b/distributeddatamgr/dataShare/server/rdbService/AppScope/resources/base/media/app_icon.png new file mode 100644 index 0000000000000000000000000000000000000000..ce307a8827bd75456441ceb57d530e4c8d45d36c Binary files /dev/null and b/distributeddatamgr/dataShare/server/rdbService/AppScope/resources/base/media/app_icon.png differ diff --git a/distributeddatamgr/windowStage/server/rdbService/BUILD.gn b/distributeddatamgr/dataShare/server/rdbService/BUILD.gn similarity index 88% rename from distributeddatamgr/windowStage/server/rdbService/BUILD.gn rename to distributeddatamgr/dataShare/server/rdbService/BUILD.gn index 7dcd432675f739bf1d2a5de30be44f6b6bede343..e5ecd070a7ae8d259b210e132740090aa2e0353e 100644 --- a/distributeddatamgr/windowStage/server/rdbService/BUILD.gn +++ b/distributeddatamgr/dataShare/server/rdbService/BUILD.gn @@ -13,13 +13,11 @@ import("//test/xts/tools/build/suite.gni") -ohos_hap("ActsRdbServiceHap") { +ohos_hap_assist_suite("ActsRdbServiceHap") { hap_profile = "./entry/src/main/module.json" - hap_name = "ActsRdbServiceHap" - subsystem_name = XTS_SUITENAME - final_hap_path = - "${SUITES_OUTPUT_ROOT}/${XTS_SUITENAME}/testcases/${hap_name}.hap" + subsystem_name = "distributeddatamgr" + part_name = "data_share" js_build_mode = "debug" deps = [ ":rdbService_js_assets", diff --git a/distributeddatamgr/windowStage/server/rdbService/entry/src/main/ets/Application/AbilityStage.ts b/distributeddatamgr/dataShare/server/rdbService/entry/src/main/ets/Application/AbilityStage.ts similarity index 100% rename from distributeddatamgr/windowStage/server/rdbService/entry/src/main/ets/Application/AbilityStage.ts rename to distributeddatamgr/dataShare/server/rdbService/entry/src/main/ets/Application/AbilityStage.ts diff --git a/distributeddatamgr/windowStage/server/rdbService/entry/src/main/ets/DataShareExtAbility/DataShareExtAbility.ts b/distributeddatamgr/dataShare/server/rdbService/entry/src/main/ets/DataShareExtAbility/DataShareExtAbility.ts similarity index 100% rename from distributeddatamgr/windowStage/server/rdbService/entry/src/main/ets/DataShareExtAbility/DataShareExtAbility.ts rename to distributeddatamgr/dataShare/server/rdbService/entry/src/main/ets/DataShareExtAbility/DataShareExtAbility.ts diff --git a/distributeddatamgr/windowStage/server/rdbService/entry/src/main/ets/MainAbility/MainAbility.ts b/distributeddatamgr/dataShare/server/rdbService/entry/src/main/ets/MainAbility/MainAbility.ts similarity index 100% rename from distributeddatamgr/windowStage/server/rdbService/entry/src/main/ets/MainAbility/MainAbility.ts rename to distributeddatamgr/dataShare/server/rdbService/entry/src/main/ets/MainAbility/MainAbility.ts diff --git a/distributeddatamgr/windowStage/server/rdbService/entry/src/main/ets/pages/index.ets b/distributeddatamgr/dataShare/server/rdbService/entry/src/main/ets/pages/index.ets similarity index 100% rename from distributeddatamgr/windowStage/server/rdbService/entry/src/main/ets/pages/index.ets rename to distributeddatamgr/dataShare/server/rdbService/entry/src/main/ets/pages/index.ets diff --git a/distributeddatamgr/windowStage/server/rdbService/entry/src/main/module.json b/distributeddatamgr/dataShare/server/rdbService/entry/src/main/module.json similarity index 100% rename from distributeddatamgr/windowStage/server/rdbService/entry/src/main/module.json rename to distributeddatamgr/dataShare/server/rdbService/entry/src/main/module.json diff --git a/distributeddatamgr/dataShare/server/rdbService/entry/src/main/resources/base/element/datashare.json b/distributeddatamgr/dataShare/server/rdbService/entry/src/main/resources/base/element/datashare.json new file mode 100644 index 0000000000000000000000000000000000000000..c946d63748451e44cc2861cf10f392df713f8224 --- /dev/null +++ b/distributeddatamgr/dataShare/server/rdbService/entry/src/main/resources/base/element/datashare.json @@ -0,0 +1,8 @@ +{ + "color": [ + { + "name": "color_1", + "value": "#ff0000" + } + ] +} \ No newline at end of file diff --git a/distributeddatamgr/windowStage/server/rdbService/entry/src/main/resources/base/element/string.json b/distributeddatamgr/dataShare/server/rdbService/entry/src/main/resources/base/element/string.json similarity index 100% rename from distributeddatamgr/windowStage/server/rdbService/entry/src/main/resources/base/element/string.json rename to distributeddatamgr/dataShare/server/rdbService/entry/src/main/resources/base/element/string.json diff --git a/distributeddatamgr/dataShare/server/rdbService/entry/src/main/resources/base/media/icon.png b/distributeddatamgr/dataShare/server/rdbService/entry/src/main/resources/base/media/icon.png new file mode 100644 index 0000000000000000000000000000000000000000..ce307a8827bd75456441ceb57d530e4c8d45d36c Binary files /dev/null and b/distributeddatamgr/dataShare/server/rdbService/entry/src/main/resources/base/media/icon.png differ diff --git a/distributeddatamgr/dataShare/server/rdbService/entry/src/main/resources/base/profile/form_config.json b/distributeddatamgr/dataShare/server/rdbService/entry/src/main/resources/base/profile/form_config.json new file mode 100644 index 0000000000000000000000000000000000000000..ba3489dd5c6ee9435d07201193fcb137e3ad083e --- /dev/null +++ b/distributeddatamgr/dataShare/server/rdbService/entry/src/main/resources/base/profile/form_config.json @@ -0,0 +1,24 @@ +{ + "forms": [ + { + "name": "Form_Js", + "description": "$string:form_description", + "src": "pages/card/index", + "window": { + "designWidth": 720, + "autoDesignWidth": true + }, + "colorMode": "auto", + "formConfigAbility": "ability://xxxxx", + "formVisibleNotify": false, + "isDefault": true, + "updateEnabled": true, + "scheduledUpdateTime": "10:30", + "updateDuration": 1, + "defaultDimension": "2*2", + "supportDimensions": [ + "2*2" + ] + } + ] +} diff --git a/distributeddatamgr/dataShare/server/rdbService/entry/src/main/resources/base/profile/main_pages.json b/distributeddatamgr/dataShare/server/rdbService/entry/src/main/resources/base/profile/main_pages.json new file mode 100644 index 0000000000000000000000000000000000000000..50b961efe7eba3554818d73178d6c4aa735bcd16 --- /dev/null +++ b/distributeddatamgr/dataShare/server/rdbService/entry/src/main/resources/base/profile/main_pages.json @@ -0,0 +1,5 @@ +{ + "src": [ + "pages/index" + ] +} diff --git a/distributeddatamgr/dataShare/server/rdbService/signature/openharmony_sx.p7b b/distributeddatamgr/dataShare/server/rdbService/signature/openharmony_sx.p7b new file mode 100644 index 0000000000000000000000000000000000000000..7ffcdc78527c5c1aa24520ab7e913c5f47c703f0 Binary files /dev/null and b/distributeddatamgr/dataShare/server/rdbService/signature/openharmony_sx.p7b differ diff --git a/distributeddatamgr/distributeddatamgrjstest/hap/BUILD.gn b/distributeddatamgr/kvStorejstest/hap/BUILD.gn old mode 100755 new mode 100644 similarity index 76% rename from distributeddatamgr/distributeddatamgrjstest/hap/BUILD.gn rename to distributeddatamgr/kvStorejstest/hap/BUILD.gn index bd60cb0b67a38c8a09d561049f3d1636013e64b4..c3ee3a6262a2df1c08a3a5c4b11314ac742d70aa --- a/distributeddatamgr/distributeddatamgrjstest/hap/BUILD.gn +++ b/distributeddatamgr/kvStorejstest/hap/BUILD.gn @@ -13,19 +13,21 @@ import("//test/xts/tools/build/suite.gni") -ohos_js_hap_suite("distributeddatamgr_js_test") { +ohos_js_hap_suite("kvStore_js_test") { hap_profile = "./src/main/config.json" deps = [ - ":distributeddatamgr_js_assets", - ":distributeddatamgr_resources", + ":kvStore_js_assets", + ":kvStore_resources", ] certificate_profile = "./signature/openharmony_sx.p7b" - hap_name = "ActsDistributedDatamgrJsTest" + hap_name = "ActKvStoreJsTest" + subsystem_name = "distributeddatamgr" + part_name = "distributeddatamgr" } -ohos_js_assets("distributeddatamgr_js_assets") { +ohos_js_assets("kvStore_js_assets") { source_dir = "./src/main/js/default" } -ohos_resources("distributeddatamgr_resources") { +ohos_resources("kvStore_resources") { sources = [ "./src/main/resources" ] hap_profile = "./src/main/config.json" } diff --git a/distributeddatamgr/distributeddatamgrjstest/hap/Test.json b/distributeddatamgr/kvStorejstest/hap/Test.json old mode 100755 new mode 100644 similarity index 76% rename from distributeddatamgr/distributeddatamgrjstest/hap/Test.json rename to distributeddatamgr/kvStorejstest/hap/Test.json index 08d2c51c235221653f08bbfc780fb5b3fd3a419b..fcbcdbc84ac715aacd31212a61dfd31e0c5c3288 --- a/distributeddatamgr/distributeddatamgrjstest/hap/Test.json +++ b/distributeddatamgr/kvStorejstest/hap/Test.json @@ -3,13 +3,13 @@ "driver": { "type": "JSUnitTest", "test-timeout": "1200000", - "package": "ohos.acts.distributeddatamgr", + "package": "ohos.acts.kvStore", "shell-timeout": "60000" }, "kits": [ { "test-file-name": [ - "ActsDistributedDatamgrJsTest.hap" + "ActKvStoreJsTest.hap" ], "type": "AppInstallKit", "cleanup-apps": true diff --git a/distributeddatamgr/distributeddatamgrjstest/hap/signature/openharmony_sx.p7b b/distributeddatamgr/kvStorejstest/hap/signature/openharmony_sx.p7b old mode 100755 new mode 100644 similarity index 100% rename from distributeddatamgr/distributeddatamgrjstest/hap/signature/openharmony_sx.p7b rename to distributeddatamgr/kvStorejstest/hap/signature/openharmony_sx.p7b diff --git a/distributeddatamgr/distributeddatamgrjstest/hap/src/main/config.json b/distributeddatamgr/kvStorejstest/hap/src/main/config.json old mode 100755 new mode 100644 similarity index 83% rename from distributeddatamgr/distributeddatamgrjstest/hap/src/main/config.json rename to distributeddatamgr/kvStorejstest/hap/src/main/config.json index 60cdf297456db462262599d55628d62c23e64181..6687d43405e956667c8cf5eb4020f42772a41a79 --- a/distributeddatamgr/distributeddatamgrjstest/hap/src/main/config.json +++ b/distributeddatamgr/kvStorejstest/hap/src/main/config.json @@ -1,6 +1,6 @@ { "app": { - "bundleName": "ohos.acts.distributeddatamgr", + "bundleName": "ohos.acts.kvStore", "vendor": "example", "version": { "code": 1000000, @@ -13,9 +13,9 @@ }, "deviceConfig": {}, "module": { - "package": "ohos.acts.distributeddatamgr", + "package": "ohos.acts.kvStore", "name": ".MyApplication", - "mainAbility": "ohos.acts.distributeddatamgr.MainAbility", + "mainAbility": "ohos.acts.kvStore.MainAbility", "deviceType": [ "phone" ], @@ -38,7 +38,7 @@ ] } ], - "name": "ohos.acts.distributeddatamgr.MainAbility", + "name": "ohos.acts.kvStore.MainAbility", "icon": "$media:icon", "description": "$string:mainability_description", "label": "$string:app_name", diff --git a/distributeddatamgr/distributeddatamgrjstest/hap/src/main/js/default/app.js b/distributeddatamgr/kvStorejstest/hap/src/main/js/default/app.js old mode 100755 new mode 100644 similarity index 100% rename from distributeddatamgr/distributeddatamgrjstest/hap/src/main/js/default/app.js rename to distributeddatamgr/kvStorejstest/hap/src/main/js/default/app.js diff --git a/distributeddatamgr/distributeddatamgrjstest/hap/src/main/js/default/i18n/en-US.json b/distributeddatamgr/kvStorejstest/hap/src/main/js/default/i18n/en-US.json old mode 100755 new mode 100644 similarity index 100% rename from distributeddatamgr/distributeddatamgrjstest/hap/src/main/js/default/i18n/en-US.json rename to distributeddatamgr/kvStorejstest/hap/src/main/js/default/i18n/en-US.json diff --git a/distributeddatamgr/distributeddatamgrjstest/hap/src/main/js/default/i18n/zh-CN.json b/distributeddatamgr/kvStorejstest/hap/src/main/js/default/i18n/zh-CN.json old mode 100755 new mode 100644 similarity index 100% rename from distributeddatamgr/distributeddatamgrjstest/hap/src/main/js/default/i18n/zh-CN.json rename to distributeddatamgr/kvStorejstest/hap/src/main/js/default/i18n/zh-CN.json diff --git a/distributeddatamgr/distributeddatamgrjstest/hap/src/main/js/default/pages/index/index.css b/distributeddatamgr/kvStorejstest/hap/src/main/js/default/pages/index/index.css old mode 100755 new mode 100644 similarity index 100% rename from distributeddatamgr/distributeddatamgrjstest/hap/src/main/js/default/pages/index/index.css rename to distributeddatamgr/kvStorejstest/hap/src/main/js/default/pages/index/index.css diff --git a/distributeddatamgr/distributeddatamgrjstest/hap/src/main/js/default/pages/index/index.hml b/distributeddatamgr/kvStorejstest/hap/src/main/js/default/pages/index/index.hml old mode 100755 new mode 100644 similarity index 100% rename from distributeddatamgr/distributeddatamgrjstest/hap/src/main/js/default/pages/index/index.hml rename to distributeddatamgr/kvStorejstest/hap/src/main/js/default/pages/index/index.hml diff --git a/distributeddatamgr/distributeddatamgrjstest/hap/src/main/js/default/pages/index/index.js b/distributeddatamgr/kvStorejstest/hap/src/main/js/default/pages/index/index.js old mode 100755 new mode 100644 similarity index 100% rename from distributeddatamgr/distributeddatamgrjstest/hap/src/main/js/default/pages/index/index.js rename to distributeddatamgr/kvStorejstest/hap/src/main/js/default/pages/index/index.js diff --git a/distributeddatamgr/distributeddatamgrjstest/hap/src/main/js/default/test/DeviceKvStoreCallbackJsunit.test.js b/distributeddatamgr/kvStorejstest/hap/src/main/js/default/test/DeviceKvStoreCallbackJsunit.test.js similarity index 99% rename from distributeddatamgr/distributeddatamgrjstest/hap/src/main/js/default/test/DeviceKvStoreCallbackJsunit.test.js rename to distributeddatamgr/kvStorejstest/hap/src/main/js/default/test/DeviceKvStoreCallbackJsunit.test.js index 0d7256630db68d495b717336577f67b4b1c791b0..e27eadf466657f17011e1791732f68995fcd41df 100644 --- a/distributeddatamgr/distributeddatamgrjstest/hap/src/main/js/default/test/DeviceKvStoreCallbackJsunit.test.js +++ b/distributeddatamgr/kvStorejstest/hap/src/main/js/default/test/DeviceKvStoreCallbackJsunit.test.js @@ -27,7 +27,7 @@ const VALUE_TEST_BOOLEAN_ELEMENT = true; const VALUE_TEST_STRING_ELEMENT = 'value-string-002'; const VALUE_TEST_SYNC_ELEMENT = 'value-string-001'; -const TEST_BUNDLE_NAME = 'ohos.acts.distributeddatamgr'; +const TEST_BUNDLE_NAME = 'ohos.acts.kvStore'; const TEST_STORE_ID = 'storeId'; var kvManager = null; var kvStore = null; diff --git a/distributeddatamgr/distributeddatamgrjstest/hap/src/main/js/default/test/DeviceKvStorePromiseJsunit.test.js b/distributeddatamgr/kvStorejstest/hap/src/main/js/default/test/DeviceKvStorePromiseJsunit.test.js similarity index 99% rename from distributeddatamgr/distributeddatamgrjstest/hap/src/main/js/default/test/DeviceKvStorePromiseJsunit.test.js rename to distributeddatamgr/kvStorejstest/hap/src/main/js/default/test/DeviceKvStorePromiseJsunit.test.js index 654d6301ba085e0a8d63c0ddbd9533ef08181dbe..b6bbf43345a4340ee1a0a27ca9ecbda81a2f1e79 100644 --- a/distributeddatamgr/distributeddatamgrjstest/hap/src/main/js/default/test/DeviceKvStorePromiseJsunit.test.js +++ b/distributeddatamgr/kvStorejstest/hap/src/main/js/default/test/DeviceKvStorePromiseJsunit.test.js @@ -27,7 +27,7 @@ const VALUE_TEST_BOOLEAN_ELEMENT = true; const VALUE_TEST_STRING_ELEMENT = 'value-string-001'; const VALUE_TEST_SYNC_ELEMENT = 'value-string-001'; -const TEST_BUNDLE_NAME = 'ohos.acts.distributeddatamgr'; +const TEST_BUNDLE_NAME = 'ohos.acts.kvStore'; const TEST_STORE_ID = 'storeId'; var kvManager = null; var kvStore = null; diff --git a/distributeddatamgr/distributeddatamgrjstest/hap/src/main/js/default/test/FieldNodeJsunit.test.js b/distributeddatamgr/kvStorejstest/hap/src/main/js/default/test/FieldNodeJsunit.test.js similarity index 100% rename from distributeddatamgr/distributeddatamgrjstest/hap/src/main/js/default/test/FieldNodeJsunit.test.js rename to distributeddatamgr/kvStorejstest/hap/src/main/js/default/test/FieldNodeJsunit.test.js diff --git a/distributeddatamgr/distributeddatamgrjstest/hap/src/main/js/default/test/KvManagerCallbackJsunit.test.js b/distributeddatamgr/kvStorejstest/hap/src/main/js/default/test/KvManagerCallbackJsunit.test.js similarity index 99% rename from distributeddatamgr/distributeddatamgrjstest/hap/src/main/js/default/test/KvManagerCallbackJsunit.test.js rename to distributeddatamgr/kvStorejstest/hap/src/main/js/default/test/KvManagerCallbackJsunit.test.js index c72c5c2b8560d6a7043945ed9f423a3afe3e5574..0077582e6bd06d5e44a97f78a2fe81525825a464 100644 --- a/distributeddatamgr/distributeddatamgrjstest/hap/src/main/js/default/test/KvManagerCallbackJsunit.test.js +++ b/distributeddatamgr/kvStorejstest/hap/src/main/js/default/test/KvManagerCallbackJsunit.test.js @@ -15,7 +15,7 @@ import {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from 'deccjsunit/index' import factory from '@ohos.data.distributedData'; -const TEST_BUNDLE_NAME = 'ohos.acts.distributeddatamgr'; +const TEST_BUNDLE_NAME = 'ohos.acts.kvStore'; const TEST_STORE_ID = 'storeId'; const STORE_KEY = 'key_test_string'; const STORE_VALUE = 'value-test-string'; diff --git a/distributeddatamgr/distributeddatamgrjstest/hap/src/main/js/default/test/KvManagerPromiseJsunit.test.js b/distributeddatamgr/kvStorejstest/hap/src/main/js/default/test/KvManagerPromiseJsunit.test.js similarity index 99% rename from distributeddatamgr/distributeddatamgrjstest/hap/src/main/js/default/test/KvManagerPromiseJsunit.test.js rename to distributeddatamgr/kvStorejstest/hap/src/main/js/default/test/KvManagerPromiseJsunit.test.js index 18cf25dd88d9eb1d420943d1dc0552ec7e02678f..891a189d88fe28e3de87c02920536d60637b959b 100644 --- a/distributeddatamgr/distributeddatamgrjstest/hap/src/main/js/default/test/KvManagerPromiseJsunit.test.js +++ b/distributeddatamgr/kvStorejstest/hap/src/main/js/default/test/KvManagerPromiseJsunit.test.js @@ -15,7 +15,7 @@ import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from 'deccjsunit/index' import factory from '@ohos.data.distributedData'; -const TEST_BUNDLE_NAME = 'ohos.acts.distributeddatamgr'; +const TEST_BUNDLE_NAME = 'ohos.acts.kvStore'; const TEST_STORE_ID = 'storeId'; var kvManager = null; var kvStore = null; diff --git a/distributeddatamgr/distributeddatamgrjstest/hap/src/main/js/default/test/KvStoreResultSetJsunit.test.js b/distributeddatamgr/kvStorejstest/hap/src/main/js/default/test/KvStoreResultSetJsunit.test.js similarity index 99% rename from distributeddatamgr/distributeddatamgrjstest/hap/src/main/js/default/test/KvStoreResultSetJsunit.test.js rename to distributeddatamgr/kvStorejstest/hap/src/main/js/default/test/KvStoreResultSetJsunit.test.js index 44efca2a2cbe0a9efd0cd39a29bb60c6b6a1ab79..7aa5590f180a818da4abb6988d517cdb84e28537 100644 --- a/distributeddatamgr/distributeddatamgrjstest/hap/src/main/js/default/test/KvStoreResultSetJsunit.test.js +++ b/distributeddatamgr/kvStorejstest/hap/src/main/js/default/test/KvStoreResultSetJsunit.test.js @@ -15,7 +15,7 @@ import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from 'deccjsunit/index' import factory from '@ohos.data.distributedData'; -const TEST_BUNDLE_NAME = 'ohos.acts.distributeddatamgr'; +const TEST_BUNDLE_NAME = 'ohos.acts.kvStore'; const TEST_STORE_ID = 'storeId'; var kvManager = null; var kvStore = null; diff --git a/distributeddatamgr/distributeddatamgrjstest/hap/src/main/js/default/test/List.test.js b/distributeddatamgr/kvStorejstest/hap/src/main/js/default/test/List.test.js old mode 100755 new mode 100644 similarity index 100% rename from distributeddatamgr/distributeddatamgrjstest/hap/src/main/js/default/test/List.test.js rename to distributeddatamgr/kvStorejstest/hap/src/main/js/default/test/List.test.js diff --git a/distributeddatamgr/distributeddatamgrjstest/hap/src/main/js/default/test/QueryJsunit.test.js b/distributeddatamgr/kvStorejstest/hap/src/main/js/default/test/QueryJsunit.test.js similarity index 100% rename from distributeddatamgr/distributeddatamgrjstest/hap/src/main/js/default/test/QueryJsunit.test.js rename to distributeddatamgr/kvStorejstest/hap/src/main/js/default/test/QueryJsunit.test.js diff --git a/distributeddatamgr/distributeddatamgrjstest/hap/src/main/js/default/test/SchemaJsunit.test.js b/distributeddatamgr/kvStorejstest/hap/src/main/js/default/test/SchemaJsunit.test.js similarity index 99% rename from distributeddatamgr/distributeddatamgrjstest/hap/src/main/js/default/test/SchemaJsunit.test.js rename to distributeddatamgr/kvStorejstest/hap/src/main/js/default/test/SchemaJsunit.test.js index 489de4df5119076f48688303fe5b0678db298c2f..17ff7c837aaa2d851553ece65903789e63d6e756 100644 --- a/distributeddatamgr/distributeddatamgrjstest/hap/src/main/js/default/test/SchemaJsunit.test.js +++ b/distributeddatamgr/kvStorejstest/hap/src/main/js/default/test/SchemaJsunit.test.js @@ -15,7 +15,7 @@ import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from 'deccjsunit/index' import ddm from '@ohos.data.distributedData'; -const TEST_BUNDLE_NAME = 'ohos.acts.distributeddatamgr'; +const TEST_BUNDLE_NAME = 'ohos.acts.kvStore'; const TEST_STORE_ID = 'storeId'; var kvManager = null; diff --git a/distributeddatamgr/distributeddatamgrjstest/hap/src/main/js/default/test/SingleKvStoreCallbackJsunit.test.js b/distributeddatamgr/kvStorejstest/hap/src/main/js/default/test/SingleKvStoreCallbackJsunit.test.js old mode 100755 new mode 100644 similarity index 99% rename from distributeddatamgr/distributeddatamgrjstest/hap/src/main/js/default/test/SingleKvStoreCallbackJsunit.test.js rename to distributeddatamgr/kvStorejstest/hap/src/main/js/default/test/SingleKvStoreCallbackJsunit.test.js index dc6c3ebc846eb7734f93a33867d702beccbc6033..724077dee25657520b296d58e13169d47ab751d8 --- a/distributeddatamgr/distributeddatamgrjstest/hap/src/main/js/default/test/SingleKvStoreCallbackJsunit.test.js +++ b/distributeddatamgr/kvStorejstest/hap/src/main/js/default/test/SingleKvStoreCallbackJsunit.test.js @@ -27,7 +27,7 @@ const VALUE_TEST_BOOLEAN_ELEMENT = true; const VALUE_TEST_STRING_ELEMENT = 'value-string-002'; const VALUE_TEST_SYNC_ELEMENT = 'value-string-001'; -const TEST_BUNDLE_NAME = 'ohos.acts.distributeddatamgr'; +const TEST_BUNDLE_NAME = 'ohos.acts.kvStore'; const TEST_STORE_ID = 'storeId'; var kvManager = null; var kvStore = null; diff --git a/distributeddatamgr/distributeddatamgrjstest/hap/src/main/js/default/test/SingleKvStoreEnumJsunit.test.js b/distributeddatamgr/kvStorejstest/hap/src/main/js/default/test/SingleKvStoreEnumJsunit.test.js similarity index 100% rename from distributeddatamgr/distributeddatamgrjstest/hap/src/main/js/default/test/SingleKvStoreEnumJsunit.test.js rename to distributeddatamgr/kvStorejstest/hap/src/main/js/default/test/SingleKvStoreEnumJsunit.test.js diff --git a/distributeddatamgr/distributeddatamgrjstest/hap/src/main/js/default/test/SingleKvStorePromiseJsunit.test.js b/distributeddatamgr/kvStorejstest/hap/src/main/js/default/test/SingleKvStorePromiseJsunit.test.js old mode 100755 new mode 100644 similarity index 96% rename from distributeddatamgr/distributeddatamgrjstest/hap/src/main/js/default/test/SingleKvStorePromiseJsunit.test.js rename to distributeddatamgr/kvStorejstest/hap/src/main/js/default/test/SingleKvStorePromiseJsunit.test.js index a315f93542182321459a5f8711d3930386dd7466..8e56a4d48a05e74a5de2ebe90307fdc34049a7d5 --- a/distributeddatamgr/distributeddatamgrjstest/hap/src/main/js/default/test/SingleKvStorePromiseJsunit.test.js +++ b/distributeddatamgr/kvStorejstest/hap/src/main/js/default/test/SingleKvStorePromiseJsunit.test.js @@ -27,7 +27,7 @@ const VALUE_TEST_BOOLEAN_ELEMENT = true; const VALUE_TEST_STRING_ELEMENT = 'value-string-001'; const VALUE_TEST_SYNC_ELEMENT = 'value-string-001'; -const TEST_BUNDLE_NAME = 'ohos.acts.distributeddatamgr'; +const TEST_BUNDLE_NAME = 'ohos.acts.kvStore'; const TEST_STORE_ID = 'storeId'; var kvManager = null; var kvStore = null; @@ -2657,4 +2657,79 @@ describe('SingleKvStorePromiseTest', function () { } done(); }) + + /** + * @tc.number SUB_DISTRIBUTEDDATAMGR_SINGLEKVSTORE_CHANGENOTIFICATION_0100 + * @tc.name [JS-API8]SingleKvStoreChangeNotification. + * @tc.desc Test Js Api SingleKvStoreChangeNotification testcase 001 + */ + it('testSingleKvStoreChangeNotification101', 0, async function (done) { + var getInsertEntries = new Promise((resolve, reject) => { + kvStore.on('dataChange', 0, function(ChangeNotification){ + resolve(ChangeNotification.insertEntries); + }); + kvStore.put("getInsertEntries", "byPut").then(() => { + console.info('testSingleKvStoreChangeNotification101 put success'); + }); + }); + await getInsertEntries.then(function(insertEntries){ + console.info('testSingleKvStoreChangeNotification101 getInsertEntries' + JSON.stringify(insertEntries)); + expect(insertEntries).assertNotNull(); + }).catch((error) => { + console.info('testSingleKvStoreChangeNotification101 can NOT getInsertEntries, fail:' + error); + }); + done(); + }) + + /** + * @tc.number SUB_DISTRIBUTEDDATAMGR_SINGLEKVSTORE_CHANGENOTIFICATION_0200 + * @tc.name [JS-API8]SingleKvStoreChangeNotification. + * @tc.desc Test Js Api SingleKvStoreChangeNotification testcase 002 + */ + it('testSingleKvStoreChangeNotification102', 0, async function (done) { + await kvStore.put('getUpdateEntries', 'byPut').then(() => { + console.info('testSingleKvStoreChangeNotification102 put success'); + }); + var getUpdateEntries = new Promise((resolve, reject) => { + kvStore.on('dataChange', 0, function(ChangeNotification){ + resolve(ChangeNotification.updateEntries); + }); + kvStore.put("getUpdateEntries", "byPut").then(() => { + console.info('testSingleKvStoreChangeNotification102 update success'); + }); + }); + await getUpdateEntries.then(function(updateEntries){ + console.info('testSingleKvStoreChangeNotification102 getUpdateEntries' + JSON.stringify(updateEntries)); + expect(updateEntries).assertNotNull(); + }).catch((error) => { + console.info('testSingleKvStoreChangeNotification102 can NOT getUpdateEntries, fail:' + error); + }); + done(); + }) + + /** + * @tc.number SUB_DISTRIBUTEDDATAMGR_SINGLEKVSTORE_CHANGENOTIFICATION_0300 + * @tc.name [JS-API8]SingleKvStoreChangeNotification. + * @tc.desc Test Js Api SingleKvStoreChangeNotification testcase 003 + */ + it('testSingleKvStoreChangeNotification103', 0, async function (done) { + await kvStore.put('deleteEntries', 'byPut').then(() => { + console.info('testSingleKvStoreChangeNotification103 put success'); + }); + var getdeleteEntries = new Promise((resolve, reject) => { + kvStore.on('dataChange', 0, function(ChangeNotification){ + resolve(ChangeNotification.deleteEntries); + }); + kvStore.delete("deleteEntries").then(() => { + console.info('testSingleKvStoreChangeNotification103 delete success'); + }); + }); + await getdeleteEntries.then(function(deleteEntries){ + console.info('testSingleKvStoreChangeNotification103 deleteEntries' + JSON.stringify(getdeleteEntries)); + expect(deleteEntries != null).assertNotNull(); + }).catch((error) => { + console.info('testSingleKvStoreChangeNotification103 can NOT getdeleteEntries, fail:' + error); + }); + done(); + }) }) \ No newline at end of file diff --git a/distributeddatamgr/distributeddatamgrjstest/hap/src/main/resources/base/element/string.json b/distributeddatamgr/kvStorejstest/hap/src/main/resources/base/element/string.json old mode 100755 new mode 100644 similarity index 100% rename from distributeddatamgr/distributeddatamgrjstest/hap/src/main/resources/base/element/string.json rename to distributeddatamgr/kvStorejstest/hap/src/main/resources/base/element/string.json diff --git a/distributeddatamgr/kvStorejstest/hap/src/main/resources/base/media/icon.png b/distributeddatamgr/kvStorejstest/hap/src/main/resources/base/media/icon.png new file mode 100644 index 0000000000000000000000000000000000000000..ce307a8827bd75456441ceb57d530e4c8d45d36c Binary files /dev/null and b/distributeddatamgr/kvStorejstest/hap/src/main/resources/base/media/icon.png differ diff --git a/distributeddatamgr/preferencesjstest/hap/BUILD.gn b/distributeddatamgr/preferencesjstest/hap/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..183f1fb69ff719accff029fcea8df110e5b99143 --- /dev/null +++ b/distributeddatamgr/preferencesjstest/hap/BUILD.gn @@ -0,0 +1,35 @@ +# Copyright (C) 2021 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("preferences_js_test") { + hap_profile = "./src/main/config.json" + deps = [ + ":preferences_js_assets", + ":preferences_resources", + ] + certificate_profile = "./signature/openharmony_sx.p7b" + hap_name = "ActsPreferencesJsTest" + subsystem_name = "distributeddatamgr" + part_name = "preferences" +} +ohos_js_assets("preferences_js_assets") { + js2abc = true + hap_profile = "./src/main/config.json" + source_dir = "./src/main/js" +} +ohos_resources("preferences_resources") { + sources = [ "./src/main/resources" ] + hap_profile = "./src/main/config.json" +} diff --git a/distributeddatamgr/preferencesjstest/hap/Test.json b/distributeddatamgr/preferencesjstest/hap/Test.json new file mode 100644 index 0000000000000000000000000000000000000000..9acab397be87243eb5fce0300196ce263e930808 --- /dev/null +++ b/distributeddatamgr/preferencesjstest/hap/Test.json @@ -0,0 +1,19 @@ +{ + "description": "Configuration for hjunit demo Tests", + "driver": { + "type": "OHJSUnitTest", + "test-timeout": "1000000", + "shell-timeout": "1000000", + "bundle-name": "ohos.acts.preferencesjstest", + "package-name": "ohos.acts.preferencesjstest" + }, + "kits": [ + { + "test-file-name": [ + "ActsPreferencesJsTest.hap" + ], + "type": "AppInstallKit", + "cleanup-apps": true + } + ] +} \ No newline at end of file diff --git a/distributeddatamgr/preferencesjstest/hap/signature/openharmony_sx.p7b b/distributeddatamgr/preferencesjstest/hap/signature/openharmony_sx.p7b new file mode 100644 index 0000000000000000000000000000000000000000..9be1e98fa4c0c28ca997ed660112fa16b194f0f5 Binary files /dev/null and b/distributeddatamgr/preferencesjstest/hap/signature/openharmony_sx.p7b differ diff --git a/distributeddatamgr/preferencesjstest/hap/src/main/config.json b/distributeddatamgr/preferencesjstest/hap/src/main/config.json new file mode 100644 index 0000000000000000000000000000000000000000..7e2209339231c13c6c1c316e2186166d4082f6f1 --- /dev/null +++ b/distributeddatamgr/preferencesjstest/hap/src/main/config.json @@ -0,0 +1,93 @@ +{ + "app": { + "bundleName": "ohos.acts.preferencesjstest", + "vendor": "example", + "version": { + "code": 1, + "name": "1.0" + }, + "apiVersion": { + "compatible": 4, + "target": 5 + } + }, + "deviceConfig": {}, + "module": { + "package": "ohos.acts.preferencesjstest", + "name": ".entry", + "deviceType": [ + "phone" + ], + "distro": { + "deliveryWithInstall": true, + "moduleName": "entry", + "moduleType": "entry" + }, + "abilities": [ + { + "skills": [ + { + "entities": [ + "entity.system.home" + ], + "actions": [ + "action.system.home" + ] + } + ], + "orientation": "unspecified", + "formsEnabled": false, + "name": ".MainAbility", + "srcLanguage": "js", + "srcPath": "MainAbility", + "icon": "$media:icon", + "description": "$string:MainAbility_desc", + "label": "$string:MainAbility_label", + "type": "page", + "visible": true, + "launchType": "standard" + }, + { + "orientation": "unspecified", + "formsEnabled": false, + "name": ".TestAbility", + "srcLanguage": "js", + "srcPath": "TestAbility", + "icon": "$media:icon", + "description": "$string:TestAbility_desc", + "label": "$string:TestAbility_label", + "type": "page", + "visible": true, + "launchType": "standard" + } + ], + "js": [ + { + "pages": [ + "pages/index/index" + ], + "name": "default", + "window": { + "designWidth": 720, + "autoDesignWidth": false + } + }, + { + "pages": [ + "pages/index/index" + ], + "name": ".TestAbility", + "window": { + "designWidth": 720, + "autoDesignWidth": false + } + } + ], + "testRunner": { + "name": "OpenHarmonyTestRunner", + "srcPath": "TestRunner" + }, + "mainAbility": ".MainAbility", + "srcPath": "" + } +} \ No newline at end of file diff --git a/distributeddatamgr/preferencesjstest/hap/src/main/js/MainAbility/app.js b/distributeddatamgr/preferencesjstest/hap/src/main/js/MainAbility/app.js new file mode 100644 index 0000000000000000000000000000000000000000..9b225d0cce79fd927c66e75cd35a88267a92431d --- /dev/null +++ b/distributeddatamgr/preferencesjstest/hap/src/main/js/MainAbility/app.js @@ -0,0 +1,22 @@ +/* +* Copyright (c) 2021 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. +*/ +export default { + onCreate() { + console.info('TestApplication onCreate'); + }, + onDestroy() { + console.info('TestApplication onDestroy'); + } +}; diff --git a/distributeddatamgr/preferencesjstest/hap/src/main/js/MainAbility/i18n/en-US.json b/distributeddatamgr/preferencesjstest/hap/src/main/js/MainAbility/i18n/en-US.json new file mode 100644 index 0000000000000000000000000000000000000000..3cb24b374b1d919ca8eac0638f361692b603a900 --- /dev/null +++ b/distributeddatamgr/preferencesjstest/hap/src/main/js/MainAbility/i18n/en-US.json @@ -0,0 +1,8 @@ +{ + "strings": { + "hello": "Hello", + "world": "World" + }, + "Files": { + } +} \ No newline at end of file diff --git a/distributeddatamgr/preferencesjstest/hap/src/main/js/MainAbility/i18n/zh-CN.json b/distributeddatamgr/preferencesjstest/hap/src/main/js/MainAbility/i18n/zh-CN.json new file mode 100644 index 0000000000000000000000000000000000000000..c804e32c0c3103929baca5617cdac70be11fdba1 --- /dev/null +++ b/distributeddatamgr/preferencesjstest/hap/src/main/js/MainAbility/i18n/zh-CN.json @@ -0,0 +1,8 @@ +{ + "strings": { + "hello": "您好", + "world": "世界" + }, + "Files": { + } +} \ No newline at end of file diff --git a/distributeddatamgr/preferencesjstest/hap/src/main/js/MainAbility/pages/index/index.css b/distributeddatamgr/preferencesjstest/hap/src/main/js/MainAbility/pages/index/index.css new file mode 100644 index 0000000000000000000000000000000000000000..59e50f0bfb9ab1919501533a2b8b87771a4162e9 --- /dev/null +++ b/distributeddatamgr/preferencesjstest/hap/src/main/js/MainAbility/pages/index/index.css @@ -0,0 +1,23 @@ +/* +* Copyright (c) 2021 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. +*/ +.container { + flex-direction: column; + justify-content: center; + align-items: center; +} + +.title { + font-size: 100px; +} diff --git a/distributeddatamgr/preferencesjstest/hap/src/main/js/MainAbility/pages/index/index.hml b/distributeddatamgr/preferencesjstest/hap/src/main/js/MainAbility/pages/index/index.hml new file mode 100644 index 0000000000000000000000000000000000000000..99a01341103ff63765e8163279d1e50a00e039d4 --- /dev/null +++ b/distributeddatamgr/preferencesjstest/hap/src/main/js/MainAbility/pages/index/index.hml @@ -0,0 +1,5 @@ +
+ + {{ $t('strings.hello') }} {{title}} + +
diff --git a/distributeddatamgr/preferencesjstest/hap/src/main/js/MainAbility/pages/index/index.js b/distributeddatamgr/preferencesjstest/hap/src/main/js/MainAbility/pages/index/index.js new file mode 100644 index 0000000000000000000000000000000000000000..aabb387ce9cfbc983eb0c62756fdd4c6607e778b --- /dev/null +++ b/distributeddatamgr/preferencesjstest/hap/src/main/js/MainAbility/pages/index/index.js @@ -0,0 +1,32 @@ +/* +* Copyright (c) 2021 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. +*/ + + +const injectRef = Object.getPrototypeOf(global) || global +injectRef.regeneratorRuntime = require('@babel/runtime/regenerator') + +export default { + data: { + title: '' + }, + onInit() { + this.title = this.$t('strings.world'); + }, + onShow() { + console.info('onShow finish') + }, + onReady() { + }, +} \ No newline at end of file diff --git a/distributeddatamgr/preferencesjstest/hap/src/main/js/TestAbility/app.js b/distributeddatamgr/preferencesjstest/hap/src/main/js/TestAbility/app.js new file mode 100644 index 0000000000000000000000000000000000000000..cdc31f3dcf031e2f6a7665d9653e53bb649e21c5 --- /dev/null +++ b/distributeddatamgr/preferencesjstest/hap/src/main/js/TestAbility/app.js @@ -0,0 +1,31 @@ +/* + * 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 AbilityDelegatorRegistry from '@ohos.application.abilityDelegatorRegistry' +import { Hypium } from '@ohos/hypium' +import testsuite from '../test/List.test' + +export default { + onCreate() { + console.info('TestApplication onCreate') + var abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator() + var abilityDelegatorArguments = AbilityDelegatorRegistry.getArguments() + console.info('start run testcase!!!') + Hypium.hypiumTest(abilityDelegator, abilityDelegatorArguments, testsuite) + }, + onDestroy() { + console.info("TestApplication onDestroy"); + } +}; diff --git a/distributeddatamgr/preferencesjstest/hap/src/main/js/TestAbility/i18n/en-US.json b/distributeddatamgr/preferencesjstest/hap/src/main/js/TestAbility/i18n/en-US.json new file mode 100644 index 0000000000000000000000000000000000000000..3cb24b374b1d919ca8eac0638f361692b603a900 --- /dev/null +++ b/distributeddatamgr/preferencesjstest/hap/src/main/js/TestAbility/i18n/en-US.json @@ -0,0 +1,8 @@ +{ + "strings": { + "hello": "Hello", + "world": "World" + }, + "Files": { + } +} \ No newline at end of file diff --git a/distributeddatamgr/preferencesjstest/hap/src/main/js/TestAbility/i18n/zh-CN.json b/distributeddatamgr/preferencesjstest/hap/src/main/js/TestAbility/i18n/zh-CN.json new file mode 100644 index 0000000000000000000000000000000000000000..c804e32c0c3103929baca5617cdac70be11fdba1 --- /dev/null +++ b/distributeddatamgr/preferencesjstest/hap/src/main/js/TestAbility/i18n/zh-CN.json @@ -0,0 +1,8 @@ +{ + "strings": { + "hello": "您好", + "world": "世界" + }, + "Files": { + } +} \ No newline at end of file diff --git a/distributeddatamgr/preferencesjstest/hap/src/main/js/TestAbility/pages/index/index.css b/distributeddatamgr/preferencesjstest/hap/src/main/js/TestAbility/pages/index/index.css new file mode 100644 index 0000000000000000000000000000000000000000..b1bcd43387ba131cc1d30975ff7508a6f8084a4b --- /dev/null +++ b/distributeddatamgr/preferencesjstest/hap/src/main/js/TestAbility/pages/index/index.css @@ -0,0 +1,30 @@ +.container { + display: flex; + flex-direction: column; + justify-content: center; + align-items: center; + left: 0px; + top: 0px; + width: 100%; + height: 100%; +} + +.title { + font-size: 60px; + text-align: center; + width: 100%; + height: 40%; + margin: 10px; +} + +@media screen and (device-type: phone) and (orientation: landscape) { + .title { + font-size: 60px; + } +} + +@media screen and (device-type: tablet) and (orientation: landscape) { + .title { + font-size: 100px; + } +} \ No newline at end of file diff --git a/distributeddatamgr/preferencesjstest/hap/src/main/js/TestAbility/pages/index/index.hml b/distributeddatamgr/preferencesjstest/hap/src/main/js/TestAbility/pages/index/index.hml new file mode 100644 index 0000000000000000000000000000000000000000..f629c71a9be857db6cdf94149652a191b9b272ea --- /dev/null +++ b/distributeddatamgr/preferencesjstest/hap/src/main/js/TestAbility/pages/index/index.hml @@ -0,0 +1,5 @@ +
+ + {{ $t('strings.hello') }} {{ title }} + +
diff --git a/distributeddatamgr/preferencesjstest/hap/src/main/js/TestAbility/pages/index/index.js b/distributeddatamgr/preferencesjstest/hap/src/main/js/TestAbility/pages/index/index.js new file mode 100644 index 0000000000000000000000000000000000000000..88b083a7f6b979019d6a2c5ad20b19c5fd43286b --- /dev/null +++ b/distributeddatamgr/preferencesjstest/hap/src/main/js/TestAbility/pages/index/index.js @@ -0,0 +1,26 @@ +/* + * 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. + */ + +export default { + data: { + title: "" + }, + onInit() { + this.title = this.$t('strings.world'); + } +} + + + diff --git a/distributeddatamgr/preferencesjstest/hap/src/main/js/TestRunner/OpenHarmonyTestRunner.js b/distributeddatamgr/preferencesjstest/hap/src/main/js/TestRunner/OpenHarmonyTestRunner.js new file mode 100644 index 0000000000000000000000000000000000000000..c5fa8620ca77d381f20b65a903b833e6e3378c97 --- /dev/null +++ b/distributeddatamgr/preferencesjstest/hap/src/main/js/TestRunner/OpenHarmonyTestRunner.js @@ -0,0 +1,59 @@ +/* + * 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 AbilityDelegatorRegistry from '@ohos.application.abilityDelegatorRegistry' + +function translateParamsToString(parameters) { + const keySet = new Set([ + '-s class', '-s notClass', '-s suite', '-s itName', + '-s level', '-s testType', '-s size', '-s timeout', + '-s package', '-s dryRun' + ]) + let targetParams = ''; + for (const key in parameters) { + if (keySet.has(key)) { + targetParams += ' ' + key + ' ' + parameters[key] + } + } + return targetParams.trim() +} + + export default { + onPrepare() { + console.info('OpenHarmonyTestRunner OnPrepare') + }, + onRun() { + console.log('OpenHarmonyTestRunner onRun run') + var abilityDelegatorArguments = AbilityDelegatorRegistry.getArguments() + var abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator() + + var testAbilityName = abilityDelegatorArguments.parameters['-p'] + '.TestAbility' + + var cmd = 'aa start -d 0 -a ' + testAbilityName + ' -b ' + abilityDelegatorArguments.bundleName + cmd += ' ' + translateParamsToString(abilityDelegatorArguments.parameters) + var debug = abilityDelegatorArguments.parameters["-D"] + console.info('debug value : '+debug) + if (debug == 'true') + { + cmd += ' -D' + } + console.info('cmd : '+cmd) + abilityDelegator.executeShellCommand(cmd, (err, data) => { + console.info('executeShellCommand : err : ' + JSON.stringify(err)); + console.info('executeShellCommand : data : ' + data.stdResult); + console.info('executeShellCommand : data : ' + data.exitCode); + }) + } +}; diff --git a/distributeddatamgr/preferencesjstest/hap/src/main/js/test/List.test.js b/distributeddatamgr/preferencesjstest/hap/src/main/js/test/List.test.js new file mode 100644 index 0000000000000000000000000000000000000000..a9e2480db9a153a5f566556b4d8a03463f1cc09e --- /dev/null +++ b/distributeddatamgr/preferencesjstest/hap/src/main/js/test/List.test.js @@ -0,0 +1,27 @@ +/* +* Copyright (c) 2021 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 storageCallBackTest from './StorageCallBackJsunit.test.js' +import storageHelperTest from './StorageHelperJsunit.test.js' +import storagePromiseTest from './StoragePromiseJsunit.test.js' +import storageSyncTest from './StorageSyncJsunit.test.js' +import systemStorageTest from './SystemStorageJsunit.test.js' +export default function testsuite() { +storageCallBackTest() +storageHelperTest() +storagePromiseTest() +storageSyncTest() +systemStorageTest() +} diff --git a/distributeddatamgr/appdatamgrjstest/hap/src/main/js/test/StorageCallBackJsunit.test.js b/distributeddatamgr/preferencesjstest/hap/src/main/js/test/StorageCallBackJsunit.test.js similarity index 100% rename from distributeddatamgr/appdatamgrjstest/hap/src/main/js/test/StorageCallBackJsunit.test.js rename to distributeddatamgr/preferencesjstest/hap/src/main/js/test/StorageCallBackJsunit.test.js diff --git a/distributeddatamgr/appdatamgrjstest/hap/src/main/js/test/StorageHelperJsunit.test.js b/distributeddatamgr/preferencesjstest/hap/src/main/js/test/StorageHelperJsunit.test.js similarity index 100% rename from distributeddatamgr/appdatamgrjstest/hap/src/main/js/test/StorageHelperJsunit.test.js rename to distributeddatamgr/preferencesjstest/hap/src/main/js/test/StorageHelperJsunit.test.js diff --git a/distributeddatamgr/appdatamgrjstest/hap/src/main/js/test/StoragePromiseJsunit.test.js b/distributeddatamgr/preferencesjstest/hap/src/main/js/test/StoragePromiseJsunit.test.js similarity index 100% rename from distributeddatamgr/appdatamgrjstest/hap/src/main/js/test/StoragePromiseJsunit.test.js rename to distributeddatamgr/preferencesjstest/hap/src/main/js/test/StoragePromiseJsunit.test.js diff --git a/distributeddatamgr/appdatamgrjstest/hap/src/main/js/test/StorageSyncJsunit.test.js b/distributeddatamgr/preferencesjstest/hap/src/main/js/test/StorageSyncJsunit.test.js similarity index 100% rename from distributeddatamgr/appdatamgrjstest/hap/src/main/js/test/StorageSyncJsunit.test.js rename to distributeddatamgr/preferencesjstest/hap/src/main/js/test/StorageSyncJsunit.test.js diff --git a/distributeddatamgr/appdatamgrjstest/hap/src/main/js/test/SystemStorageJsunit.test.js b/distributeddatamgr/preferencesjstest/hap/src/main/js/test/SystemStorageJsunit.test.js similarity index 100% rename from distributeddatamgr/appdatamgrjstest/hap/src/main/js/test/SystemStorageJsunit.test.js rename to distributeddatamgr/preferencesjstest/hap/src/main/js/test/SystemStorageJsunit.test.js diff --git a/distributeddatamgr/preferencesjstest/hap/src/main/resources/base/element/string.json b/distributeddatamgr/preferencesjstest/hap/src/main/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..f5ccd87bb736f8b939f2a77131835e4da903dfed --- /dev/null +++ b/distributeddatamgr/preferencesjstest/hap/src/main/resources/base/element/string.json @@ -0,0 +1,28 @@ +{ + "string": [ + { + "name": "app_name", + "value": "MyApplication" + }, + { + "name": "mainability_description", + "value": "hap sample empty page" + }, + { + "name": "MainAbility_desc", + "value": "description" + }, + { + "name": "MainAbility_label", + "value": "label" + }, + { + "name": "TestAbility_desc", + "value": "description" + }, + { + "name": "TestAbility_label", + "value": "label" + } + ] +} diff --git a/distributeddatamgr/preferencesjstest/hap/src/main/resources/base/media/icon.png b/distributeddatamgr/preferencesjstest/hap/src/main/resources/base/media/icon.png new file mode 100644 index 0000000000000000000000000000000000000000..ce307a8827bd75456441ceb57d530e4c8d45d36c Binary files /dev/null and b/distributeddatamgr/preferencesjstest/hap/src/main/resources/base/media/icon.png differ diff --git a/distributeddatamgr/relationalStorejstest/hap/BUILD.gn b/distributeddatamgr/relationalStorejstest/hap/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..16c322171a6df1328eedab1eb6f01eaf9619fa93 --- /dev/null +++ b/distributeddatamgr/relationalStorejstest/hap/BUILD.gn @@ -0,0 +1,35 @@ +# Copyright (C) 2021 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("relationalstore_js_test") { + hap_profile = "./src/main/config.json" + deps = [ + ":relationalstore_js_assets", + ":relationalstore_resources", + ] + certificate_profile = "./signature/openharmony_sx.p7b" + hap_name = "ActsRelationalStoreJsTest" + subsystem_name = "distributeddatamgr" + part_name = "relational_store" +} +ohos_js_assets("relationalstore_js_assets") { + js2abc = true + hap_profile = "./src/main/config.json" + source_dir = "./src/main/js" +} +ohos_resources("relationalstore_resources") { + sources = [ "./src/main/resources" ] + hap_profile = "./src/main/config.json" +} diff --git a/distributeddatamgr/relationalStorejstest/hap/Test.json b/distributeddatamgr/relationalStorejstest/hap/Test.json new file mode 100644 index 0000000000000000000000000000000000000000..d4a01d80ac72f28e31b30bdca0c53beeb3a69d34 --- /dev/null +++ b/distributeddatamgr/relationalStorejstest/hap/Test.json @@ -0,0 +1,19 @@ +{ + "description": "Configuration for hjunit demo Tests", + "driver": { + "type": "OHJSUnitTest", + "test-timeout": "1000000", + "shell-timeout": "1000000", + "bundle-name": "ohos.acts.relationalStorejstest", + "package-name": "ohos.acts.relationalStorejstest" + }, + "kits": [ + { + "test-file-name": [ + "ActsRelationalStoreJsTest.hap" + ], + "type": "AppInstallKit", + "cleanup-apps": true + } + ] +} \ No newline at end of file diff --git a/distributeddatamgr/relationalStorejstest/hap/signature/openharmony_sx.p7b b/distributeddatamgr/relationalStorejstest/hap/signature/openharmony_sx.p7b new file mode 100644 index 0000000000000000000000000000000000000000..9be1e98fa4c0c28ca997ed660112fa16b194f0f5 Binary files /dev/null and b/distributeddatamgr/relationalStorejstest/hap/signature/openharmony_sx.p7b differ diff --git a/distributeddatamgr/relationalStorejstest/hap/src/main/config.json b/distributeddatamgr/relationalStorejstest/hap/src/main/config.json new file mode 100644 index 0000000000000000000000000000000000000000..7fa74de9bde02c613d920422c1618de81889edfb --- /dev/null +++ b/distributeddatamgr/relationalStorejstest/hap/src/main/config.json @@ -0,0 +1,93 @@ +{ + "app": { + "bundleName": "ohos.acts.relationalStorejstest", + "vendor": "example", + "version": { + "code": 1, + "name": "1.0" + }, + "apiVersion": { + "compatible": 4, + "target": 5 + } + }, + "deviceConfig": {}, + "module": { + "package": "ohos.acts.relationalStorejstest", + "name": ".entry", + "deviceType": [ + "phone" + ], + "distro": { + "deliveryWithInstall": true, + "moduleName": "entry", + "moduleType": "entry" + }, + "abilities": [ + { + "skills": [ + { + "entities": [ + "entity.system.home" + ], + "actions": [ + "action.system.home" + ] + } + ], + "orientation": "unspecified", + "formsEnabled": false, + "name": ".MainAbility", + "srcLanguage": "js", + "srcPath": "MainAbility", + "icon": "$media:icon", + "description": "$string:MainAbility_desc", + "label": "$string:MainAbility_label", + "type": "page", + "visible": true, + "launchType": "standard" + }, + { + "orientation": "unspecified", + "formsEnabled": false, + "name": ".TestAbility", + "srcLanguage": "js", + "srcPath": "TestAbility", + "icon": "$media:icon", + "description": "$string:TestAbility_desc", + "label": "$string:TestAbility_label", + "type": "page", + "visible": true, + "launchType": "standard" + } + ], + "js": [ + { + "pages": [ + "pages/index/index" + ], + "name": "default", + "window": { + "designWidth": 720, + "autoDesignWidth": false + } + }, + { + "pages": [ + "pages/index/index" + ], + "name": ".TestAbility", + "window": { + "designWidth": 720, + "autoDesignWidth": false + } + } + ], + "testRunner": { + "name": "OpenHarmonyTestRunner", + "srcPath": "TestRunner" + }, + "mainAbility": ".MainAbility", + "srcPath": "" + } +} \ No newline at end of file diff --git a/distributeddatamgr/relationalStorejstest/hap/src/main/js/MainAbility/app.js b/distributeddatamgr/relationalStorejstest/hap/src/main/js/MainAbility/app.js new file mode 100644 index 0000000000000000000000000000000000000000..9b225d0cce79fd927c66e75cd35a88267a92431d --- /dev/null +++ b/distributeddatamgr/relationalStorejstest/hap/src/main/js/MainAbility/app.js @@ -0,0 +1,22 @@ +/* +* Copyright (c) 2021 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. +*/ +export default { + onCreate() { + console.info('TestApplication onCreate'); + }, + onDestroy() { + console.info('TestApplication onDestroy'); + } +}; diff --git a/distributeddatamgr/relationalStorejstest/hap/src/main/js/MainAbility/i18n/en-US.json b/distributeddatamgr/relationalStorejstest/hap/src/main/js/MainAbility/i18n/en-US.json new file mode 100644 index 0000000000000000000000000000000000000000..3cb24b374b1d919ca8eac0638f361692b603a900 --- /dev/null +++ b/distributeddatamgr/relationalStorejstest/hap/src/main/js/MainAbility/i18n/en-US.json @@ -0,0 +1,8 @@ +{ + "strings": { + "hello": "Hello", + "world": "World" + }, + "Files": { + } +} \ No newline at end of file diff --git a/distributeddatamgr/relationalStorejstest/hap/src/main/js/MainAbility/i18n/zh-CN.json b/distributeddatamgr/relationalStorejstest/hap/src/main/js/MainAbility/i18n/zh-CN.json new file mode 100644 index 0000000000000000000000000000000000000000..c804e32c0c3103929baca5617cdac70be11fdba1 --- /dev/null +++ b/distributeddatamgr/relationalStorejstest/hap/src/main/js/MainAbility/i18n/zh-CN.json @@ -0,0 +1,8 @@ +{ + "strings": { + "hello": "您好", + "world": "世界" + }, + "Files": { + } +} \ No newline at end of file diff --git a/distributeddatamgr/relationalStorejstest/hap/src/main/js/MainAbility/pages/index/index.css b/distributeddatamgr/relationalStorejstest/hap/src/main/js/MainAbility/pages/index/index.css new file mode 100644 index 0000000000000000000000000000000000000000..59e50f0bfb9ab1919501533a2b8b87771a4162e9 --- /dev/null +++ b/distributeddatamgr/relationalStorejstest/hap/src/main/js/MainAbility/pages/index/index.css @@ -0,0 +1,23 @@ +/* +* Copyright (c) 2021 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. +*/ +.container { + flex-direction: column; + justify-content: center; + align-items: center; +} + +.title { + font-size: 100px; +} diff --git a/distributeddatamgr/relationalStorejstest/hap/src/main/js/MainAbility/pages/index/index.hml b/distributeddatamgr/relationalStorejstest/hap/src/main/js/MainAbility/pages/index/index.hml new file mode 100644 index 0000000000000000000000000000000000000000..99a01341103ff63765e8163279d1e50a00e039d4 --- /dev/null +++ b/distributeddatamgr/relationalStorejstest/hap/src/main/js/MainAbility/pages/index/index.hml @@ -0,0 +1,5 @@ +
+ + {{ $t('strings.hello') }} {{title}} + +
diff --git a/distributeddatamgr/relationalStorejstest/hap/src/main/js/MainAbility/pages/index/index.js b/distributeddatamgr/relationalStorejstest/hap/src/main/js/MainAbility/pages/index/index.js new file mode 100644 index 0000000000000000000000000000000000000000..aabb387ce9cfbc983eb0c62756fdd4c6607e778b --- /dev/null +++ b/distributeddatamgr/relationalStorejstest/hap/src/main/js/MainAbility/pages/index/index.js @@ -0,0 +1,32 @@ +/* +* Copyright (c) 2021 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. +*/ + + +const injectRef = Object.getPrototypeOf(global) || global +injectRef.regeneratorRuntime = require('@babel/runtime/regenerator') + +export default { + data: { + title: '' + }, + onInit() { + this.title = this.$t('strings.world'); + }, + onShow() { + console.info('onShow finish') + }, + onReady() { + }, +} \ No newline at end of file diff --git a/distributeddatamgr/relationalStorejstest/hap/src/main/js/TestAbility/app.js b/distributeddatamgr/relationalStorejstest/hap/src/main/js/TestAbility/app.js new file mode 100644 index 0000000000000000000000000000000000000000..cdc31f3dcf031e2f6a7665d9653e53bb649e21c5 --- /dev/null +++ b/distributeddatamgr/relationalStorejstest/hap/src/main/js/TestAbility/app.js @@ -0,0 +1,31 @@ +/* + * 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 AbilityDelegatorRegistry from '@ohos.application.abilityDelegatorRegistry' +import { Hypium } from '@ohos/hypium' +import testsuite from '../test/List.test' + +export default { + onCreate() { + console.info('TestApplication onCreate') + var abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator() + var abilityDelegatorArguments = AbilityDelegatorRegistry.getArguments() + console.info('start run testcase!!!') + Hypium.hypiumTest(abilityDelegator, abilityDelegatorArguments, testsuite) + }, + onDestroy() { + console.info("TestApplication onDestroy"); + } +}; diff --git a/distributeddatamgr/relationalStorejstest/hap/src/main/js/TestAbility/i18n/en-US.json b/distributeddatamgr/relationalStorejstest/hap/src/main/js/TestAbility/i18n/en-US.json new file mode 100644 index 0000000000000000000000000000000000000000..3cb24b374b1d919ca8eac0638f361692b603a900 --- /dev/null +++ b/distributeddatamgr/relationalStorejstest/hap/src/main/js/TestAbility/i18n/en-US.json @@ -0,0 +1,8 @@ +{ + "strings": { + "hello": "Hello", + "world": "World" + }, + "Files": { + } +} \ No newline at end of file diff --git a/distributeddatamgr/relationalStorejstest/hap/src/main/js/TestAbility/i18n/zh-CN.json b/distributeddatamgr/relationalStorejstest/hap/src/main/js/TestAbility/i18n/zh-CN.json new file mode 100644 index 0000000000000000000000000000000000000000..c804e32c0c3103929baca5617cdac70be11fdba1 --- /dev/null +++ b/distributeddatamgr/relationalStorejstest/hap/src/main/js/TestAbility/i18n/zh-CN.json @@ -0,0 +1,8 @@ +{ + "strings": { + "hello": "您好", + "world": "世界" + }, + "Files": { + } +} \ No newline at end of file diff --git a/distributeddatamgr/relationalStorejstest/hap/src/main/js/TestAbility/pages/index/index.css b/distributeddatamgr/relationalStorejstest/hap/src/main/js/TestAbility/pages/index/index.css new file mode 100644 index 0000000000000000000000000000000000000000..b1bcd43387ba131cc1d30975ff7508a6f8084a4b --- /dev/null +++ b/distributeddatamgr/relationalStorejstest/hap/src/main/js/TestAbility/pages/index/index.css @@ -0,0 +1,30 @@ +.container { + display: flex; + flex-direction: column; + justify-content: center; + align-items: center; + left: 0px; + top: 0px; + width: 100%; + height: 100%; +} + +.title { + font-size: 60px; + text-align: center; + width: 100%; + height: 40%; + margin: 10px; +} + +@media screen and (device-type: phone) and (orientation: landscape) { + .title { + font-size: 60px; + } +} + +@media screen and (device-type: tablet) and (orientation: landscape) { + .title { + font-size: 100px; + } +} \ No newline at end of file diff --git a/distributeddatamgr/relationalStorejstest/hap/src/main/js/TestAbility/pages/index/index.hml b/distributeddatamgr/relationalStorejstest/hap/src/main/js/TestAbility/pages/index/index.hml new file mode 100644 index 0000000000000000000000000000000000000000..f629c71a9be857db6cdf94149652a191b9b272ea --- /dev/null +++ b/distributeddatamgr/relationalStorejstest/hap/src/main/js/TestAbility/pages/index/index.hml @@ -0,0 +1,5 @@ +
+ + {{ $t('strings.hello') }} {{ title }} + +
diff --git a/distributeddatamgr/relationalStorejstest/hap/src/main/js/TestAbility/pages/index/index.js b/distributeddatamgr/relationalStorejstest/hap/src/main/js/TestAbility/pages/index/index.js new file mode 100644 index 0000000000000000000000000000000000000000..88b083a7f6b979019d6a2c5ad20b19c5fd43286b --- /dev/null +++ b/distributeddatamgr/relationalStorejstest/hap/src/main/js/TestAbility/pages/index/index.js @@ -0,0 +1,26 @@ +/* + * 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. + */ + +export default { + data: { + title: "" + }, + onInit() { + this.title = this.$t('strings.world'); + } +} + + + diff --git a/distributeddatamgr/relationalStorejstest/hap/src/main/js/TestRunner/OpenHarmonyTestRunner.js b/distributeddatamgr/relationalStorejstest/hap/src/main/js/TestRunner/OpenHarmonyTestRunner.js new file mode 100644 index 0000000000000000000000000000000000000000..c5fa8620ca77d381f20b65a903b833e6e3378c97 --- /dev/null +++ b/distributeddatamgr/relationalStorejstest/hap/src/main/js/TestRunner/OpenHarmonyTestRunner.js @@ -0,0 +1,59 @@ +/* + * 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 AbilityDelegatorRegistry from '@ohos.application.abilityDelegatorRegistry' + +function translateParamsToString(parameters) { + const keySet = new Set([ + '-s class', '-s notClass', '-s suite', '-s itName', + '-s level', '-s testType', '-s size', '-s timeout', + '-s package', '-s dryRun' + ]) + let targetParams = ''; + for (const key in parameters) { + if (keySet.has(key)) { + targetParams += ' ' + key + ' ' + parameters[key] + } + } + return targetParams.trim() +} + + export default { + onPrepare() { + console.info('OpenHarmonyTestRunner OnPrepare') + }, + onRun() { + console.log('OpenHarmonyTestRunner onRun run') + var abilityDelegatorArguments = AbilityDelegatorRegistry.getArguments() + var abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator() + + var testAbilityName = abilityDelegatorArguments.parameters['-p'] + '.TestAbility' + + var cmd = 'aa start -d 0 -a ' + testAbilityName + ' -b ' + abilityDelegatorArguments.bundleName + cmd += ' ' + translateParamsToString(abilityDelegatorArguments.parameters) + var debug = abilityDelegatorArguments.parameters["-D"] + console.info('debug value : '+debug) + if (debug == 'true') + { + cmd += ' -D' + } + console.info('cmd : '+cmd) + abilityDelegator.executeShellCommand(cmd, (err, data) => { + console.info('executeShellCommand : err : ' + JSON.stringify(err)); + console.info('executeShellCommand : data : ' + data.stdResult); + console.info('executeShellCommand : data : ' + data.exitCode); + }) + } +}; diff --git a/distributeddatamgr/appdatamgrjstest/hap/src/main/js/test/List.test.js b/distributeddatamgr/relationalStorejstest/hap/src/main/js/test/List.test.js similarity index 72% rename from distributeddatamgr/appdatamgrjstest/hap/src/main/js/test/List.test.js rename to distributeddatamgr/relationalStorejstest/hap/src/main/js/test/List.test.js index 35782cc0d022aac00edd2787fed674faac0267f4..2108d9c2ec073830a2cae472287f34d60da85eff 100644 --- a/distributeddatamgr/appdatamgrjstest/hap/src/main/js/test/List.test.js +++ b/distributeddatamgr/relationalStorejstest/hap/src/main/js/test/List.test.js @@ -12,10 +12,8 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -import dataAbilityPredicatesTest from './DataAbilityPredicatesJsunit.test.js' import rdbStoreBackupRestoreWithFAContextTest from './RdbstoreBackupRestoreWithFAContextJsunit.test.js' import rdbstoreChangeEncryptKeyTest from './RdbstoreChangeEncryptKeyJsunit.test.js' -import rdbStoreDataSharePredicatesTest from './RdbStoreDataShareJsunit.test.js' import rdbStoreDeleteTest from './RdbstoreDeleteJsunit.test.js' import rdbStoreDistributedTest from './RdbStoreDistributedJsunit.test.js' import rdbstoreInsertTest from './RdbstoreInsertJsunit.test.js' @@ -26,16 +24,9 @@ import rdbResultSetTest from './RdbStoreResultSetJsunit.test.js' import rdbstoreStoreExcuteSqlTest from './RdbstoreStoreExcuteSqlJsunit.test.js' import rdbstoreTransactionTest from './RdbstoreTransactionJsunit.test.js' import rdbStoreUpdateTest from './RdbstoreUpdateJsunit.test.js' -import storageCallBackTest from './StorageCallBackJsunit.test.js' -import storageHelperTest from './StorageHelperJsunit.test.js' -import storagePromiseTest from './StoragePromiseJsunit.test.js' -import storageSyncTest from './StorageSyncJsunit.test.js' -import systemStorageTest from './SystemStorageJsunit.test.js' export default function testsuite() { -dataAbilityPredicatesTest() rdbStoreBackupRestoreWithFAContextTest() rdbstoreChangeEncryptKeyTest() -rdbStoreDataSharePredicatesTest() rdbStoreDeleteTest() rdbStoreDistributedTest() rdbstoreInsertTest() @@ -46,9 +37,4 @@ rdbResultSetTest() rdbstoreStoreExcuteSqlTest() rdbstoreTransactionTest() rdbStoreUpdateTest() -storageCallBackTest() -storageHelperTest() -storagePromiseTest() -storageSyncTest() -systemStorageTest() } diff --git a/distributeddatamgr/appdatamgrjstest/hap/src/main/js/test/RdbStoreDistributedJsunit.test.js b/distributeddatamgr/relationalStorejstest/hap/src/main/js/test/RdbStoreDistributedJsunit.test.js similarity index 100% rename from distributeddatamgr/appdatamgrjstest/hap/src/main/js/test/RdbStoreDistributedJsunit.test.js rename to distributeddatamgr/relationalStorejstest/hap/src/main/js/test/RdbStoreDistributedJsunit.test.js diff --git a/distributeddatamgr/appdatamgrjstest/hap/src/main/js/test/RdbStoreResultSetJsunit.test.js b/distributeddatamgr/relationalStorejstest/hap/src/main/js/test/RdbStoreResultSetJsunit.test.js similarity index 100% rename from distributeddatamgr/appdatamgrjstest/hap/src/main/js/test/RdbStoreResultSetJsunit.test.js rename to distributeddatamgr/relationalStorejstest/hap/src/main/js/test/RdbStoreResultSetJsunit.test.js diff --git a/distributeddatamgr/appdatamgrjstest/hap/src/main/js/test/RdbstoreBackupRestoreWithFAContextJsunit.test.js b/distributeddatamgr/relationalStorejstest/hap/src/main/js/test/RdbstoreBackupRestoreWithFAContextJsunit.test.js similarity index 66% rename from distributeddatamgr/appdatamgrjstest/hap/src/main/js/test/RdbstoreBackupRestoreWithFAContextJsunit.test.js rename to distributeddatamgr/relationalStorejstest/hap/src/main/js/test/RdbstoreBackupRestoreWithFAContextJsunit.test.js index d9368a00221296486aa92df19b87477005a3a4bc..1a4c90017613fa6f96b19660cafd7cb33f2fdb79 100644 --- a/distributeddatamgr/appdatamgrjstest/hap/src/main/js/test/RdbstoreBackupRestoreWithFAContextJsunit.test.js +++ b/distributeddatamgr/relationalStorejstest/hap/src/main/js/test/RdbstoreBackupRestoreWithFAContextJsunit.test.js @@ -119,70 +119,70 @@ describe('rdbStoreBackupRestoreWithFAContextTest', function () { console.info(TAG + "*************Unit Test Begin*************") - /** - * @tc.name RDB Backup Restore test - * @tc.number SUB_DDM_RDB_JS_RdbBackupRestoreTest_0010 - * @tc.desc RDB backup and restore function test - */ - it('RdbBackupRestoreTest_0010', 0, async function (done) { - await console.info(TAG + "************* RdbBackupRestoreTest_0010 start *************") - - // RDB backup function test - let promiseBackup = RdbStore.backup(DATABASE_BACKUP_NAME) - promiseBackup.then(() => { - try { - fileio.accessSync(DATABASE_DIR + DATABASE_BACKUP_NAME) - fileio.accessSync(DATABASE_DIR + STORE_CONFIG.name) - } catch (err) { - expect(false).assertTrue() - } - }).catch((err) => { - expect(false).assertTrue() - }) - await promiseBackup - - // RDB restore function test - let promiseRestore = RdbStore.restore(DATABASE_BACKUP_NAME) - promiseRestore.then(() => { - try { - fileio.accessSync(DATABASE_DIR + DATABASE_BACKUP_NAME) - expect(false).assertTrue() - } catch (err) { - expect(true).assertTrue() - } - - try { - fileio.accessSync(DATABASE_DIR + STORE_CONFIG.name) - expect(true).assertTrue() - } catch (err) { - expect(false).assertTrue() - } - }).catch((err) => { - expect(false).assertTrue() - }) - await promiseRestore - - // RDB after restored, data query test - let predicates = new dataRdb.RdbPredicates("test") - predicates.equalTo("name", "zhangsan") - let resultSet = await RdbStore.query(predicates) - try { - console.info(TAG + "After restore resultSet query done") - expect(true).assertEqual(resultSet.goToFirstRow()) - const id = resultSet.getLong(resultSet.getColumnIndex("id")) - const name = resultSet.getString(resultSet.getColumnIndex("name")) - const blobType = resultSet.getBlob(resultSet.getColumnIndex("blobType")) - expect(1).assertEqual(id) - expect("zhangsan").assertEqual(name) - expect(1).assertEqual(blobType[0]) - } catch (err) { - expect(false).assertTrue() - } - resultSet = null - RdbStore = null - done() - await console.info(TAG + "************* RdbBackupRestoreTest_0010 end *************") - }) + // /** + // * @tc.name RDB Backup Restore test + // * @tc.number SUB_DDM_RDB_JS_RdbBackupRestoreTest_0010 + // * @tc.desc RDB backup and restore function test + // */ + // it('RdbBackupRestoreTest_0010', 0, async function (done) { + // await console.info(TAG + "************* RdbBackupRestoreTest_0010 start *************") + + // // RDB backup function test + // let promiseBackup = RdbStore.backup(DATABASE_BACKUP_NAME) + // promiseBackup.then(() => { + // try { + // fileio.accessSync(DATABASE_DIR + DATABASE_BACKUP_NAME) + // fileio.accessSync(DATABASE_DIR + STORE_CONFIG.name) + // } catch (err) { + // expect(false).assertTrue() + // } + // }).catch((err) => { + // expect(false).assertTrue() + // }) + // await promiseBackup + + // // RDB restore function test + // let promiseRestore = RdbStore.restore(DATABASE_BACKUP_NAME) + // promiseRestore.then(() => { + // try { + // fileio.accessSync(DATABASE_DIR + DATABASE_BACKUP_NAME) + // expect(false).assertTrue() + // } catch (err) { + // expect(true).assertTrue() + // } + + // try { + // fileio.accessSync(DATABASE_DIR + STORE_CONFIG.name) + // expect(true).assertTrue() + // } catch (err) { + // expect(false).assertTrue() + // } + // }).catch((err) => { + // expect(false).assertTrue() + // }) + // await promiseRestore + + // // RDB after restored, data query test + // let predicates = new dataRdb.RdbPredicates("test") + // predicates.equalTo("name", "zhangsan") + // let resultSet = await RdbStore.query(predicates) + // try { + // console.info(TAG + "After restore resultSet query done") + // expect(true).assertEqual(resultSet.goToFirstRow()) + // const id = resultSet.getLong(resultSet.getColumnIndex("id")) + // const name = resultSet.getString(resultSet.getColumnIndex("name")) + // const blobType = resultSet.getBlob(resultSet.getColumnIndex("blobType")) + // expect(1).assertEqual(id) + // expect("zhangsan").assertEqual(name) + // expect(1).assertEqual(blobType[0]) + // } catch (err) { + // expect(false).assertTrue() + // } + // resultSet = null + // RdbStore = null + // done() + // await console.info(TAG + "************* RdbBackupRestoreTest_0010 end *************") + // }) /** * @tc.name RDB Backup test diff --git a/distributeddatamgr/appdatamgrjstest/hap/src/main/js/test/RdbstoreChangeEncryptKeyJsunit.test.js b/distributeddatamgr/relationalStorejstest/hap/src/main/js/test/RdbstoreChangeEncryptKeyJsunit.test.js similarity index 100% rename from distributeddatamgr/appdatamgrjstest/hap/src/main/js/test/RdbstoreChangeEncryptKeyJsunit.test.js rename to distributeddatamgr/relationalStorejstest/hap/src/main/js/test/RdbstoreChangeEncryptKeyJsunit.test.js diff --git a/distributeddatamgr/appdatamgrjstest/hap/src/main/js/test/RdbstoreDeleteJsunit.test.js b/distributeddatamgr/relationalStorejstest/hap/src/main/js/test/RdbstoreDeleteJsunit.test.js similarity index 97% rename from distributeddatamgr/appdatamgrjstest/hap/src/main/js/test/RdbstoreDeleteJsunit.test.js rename to distributeddatamgr/relationalStorejstest/hap/src/main/js/test/RdbstoreDeleteJsunit.test.js index f4eded7d5b6d7eb32840943ec383cd9c7d0a7721..b0fb0b1445b0606da2ebbe7e9f2870fb096c8801 100644 --- a/distributeddatamgr/appdatamgrjstest/hap/src/main/js/test/RdbstoreDeleteJsunit.test.js +++ b/distributeddatamgr/relationalStorejstest/hap/src/main/js/test/RdbstoreDeleteJsunit.test.js @@ -47,6 +47,7 @@ describe('rdbStoreDeleteTest', function () { }) console.info(TAG + '*************Unit Test Begin*************'); + /** * @tc.name rdb delete test * @tc.number SUB_DDM_AppDataFWK_JSRDB_Delete_0010 diff --git a/distributeddatamgr/appdatamgrjstest/hap/src/main/js/test/RdbstoreInsertJsunit.test.js b/distributeddatamgr/relationalStorejstest/hap/src/main/js/test/RdbstoreInsertJsunit.test.js similarity index 100% rename from distributeddatamgr/appdatamgrjstest/hap/src/main/js/test/RdbstoreInsertJsunit.test.js rename to distributeddatamgr/relationalStorejstest/hap/src/main/js/test/RdbstoreInsertJsunit.test.js diff --git a/distributeddatamgr/appdatamgrjstest/hap/src/main/js/test/RdbstorePredicatesJoinJsunit.test.js b/distributeddatamgr/relationalStorejstest/hap/src/main/js/test/RdbstorePredicatesJoinJsunit.test.js similarity index 100% rename from distributeddatamgr/appdatamgrjstest/hap/src/main/js/test/RdbstorePredicatesJoinJsunit.test.js rename to distributeddatamgr/relationalStorejstest/hap/src/main/js/test/RdbstorePredicatesJoinJsunit.test.js diff --git a/distributeddatamgr/appdatamgrjstest/hap/src/main/js/test/RdbstorePredicatesJsunit.test.js b/distributeddatamgr/relationalStorejstest/hap/src/main/js/test/RdbstorePredicatesJsunit.test.js similarity index 100% rename from distributeddatamgr/appdatamgrjstest/hap/src/main/js/test/RdbstorePredicatesJsunit.test.js rename to distributeddatamgr/relationalStorejstest/hap/src/main/js/test/RdbstorePredicatesJsunit.test.js diff --git a/distributeddatamgr/appdatamgrjstest/hap/src/main/js/test/RdbstoreRdbstoreJsunit.test.js b/distributeddatamgr/relationalStorejstest/hap/src/main/js/test/RdbstoreRdbstoreJsunit.test.js similarity index 100% rename from distributeddatamgr/appdatamgrjstest/hap/src/main/js/test/RdbstoreRdbstoreJsunit.test.js rename to distributeddatamgr/relationalStorejstest/hap/src/main/js/test/RdbstoreRdbstoreJsunit.test.js diff --git a/distributeddatamgr/appdatamgrjstest/hap/src/main/js/test/RdbstoreStoreExcuteSqlJsunit.test.js b/distributeddatamgr/relationalStorejstest/hap/src/main/js/test/RdbstoreStoreExcuteSqlJsunit.test.js similarity index 100% rename from distributeddatamgr/appdatamgrjstest/hap/src/main/js/test/RdbstoreStoreExcuteSqlJsunit.test.js rename to distributeddatamgr/relationalStorejstest/hap/src/main/js/test/RdbstoreStoreExcuteSqlJsunit.test.js diff --git a/distributeddatamgr/appdatamgrjstest/hap/src/main/js/test/RdbstoreTransactionJsunit.test.js b/distributeddatamgr/relationalStorejstest/hap/src/main/js/test/RdbstoreTransactionJsunit.test.js similarity index 100% rename from distributeddatamgr/appdatamgrjstest/hap/src/main/js/test/RdbstoreTransactionJsunit.test.js rename to distributeddatamgr/relationalStorejstest/hap/src/main/js/test/RdbstoreTransactionJsunit.test.js diff --git a/distributeddatamgr/appdatamgrjstest/hap/src/main/js/test/RdbstoreUpdateJsunit.test.js b/distributeddatamgr/relationalStorejstest/hap/src/main/js/test/RdbstoreUpdateJsunit.test.js similarity index 100% rename from distributeddatamgr/appdatamgrjstest/hap/src/main/js/test/RdbstoreUpdateJsunit.test.js rename to distributeddatamgr/relationalStorejstest/hap/src/main/js/test/RdbstoreUpdateJsunit.test.js diff --git a/distributeddatamgr/relationalStorejstest/hap/src/main/resources/base/element/string.json b/distributeddatamgr/relationalStorejstest/hap/src/main/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..f5ccd87bb736f8b939f2a77131835e4da903dfed --- /dev/null +++ b/distributeddatamgr/relationalStorejstest/hap/src/main/resources/base/element/string.json @@ -0,0 +1,28 @@ +{ + "string": [ + { + "name": "app_name", + "value": "MyApplication" + }, + { + "name": "mainability_description", + "value": "hap sample empty page" + }, + { + "name": "MainAbility_desc", + "value": "description" + }, + { + "name": "MainAbility_label", + "value": "label" + }, + { + "name": "TestAbility_desc", + "value": "description" + }, + { + "name": "TestAbility_label", + "value": "label" + } + ] +} diff --git a/distributeddatamgr/relationalStorejstest/hap/src/main/resources/base/media/icon.png b/distributeddatamgr/relationalStorejstest/hap/src/main/resources/base/media/icon.png new file mode 100644 index 0000000000000000000000000000000000000000..ce307a8827bd75456441ceb57d530e4c8d45d36c Binary files /dev/null and b/distributeddatamgr/relationalStorejstest/hap/src/main/resources/base/media/icon.png differ