diff --git a/distributeddatamgr/BUILD.gn b/distributeddatamgr/BUILD.gn index 7d5950cf18d29afbc58b584b1104fd3cbbf1da94..3f1d2c265a7d9250e08c487d5b610bf7c3238659 100644 --- a/distributeddatamgr/BUILD.gn +++ b/distributeddatamgr/BUILD.gn @@ -1,4 +1,4 @@ -# Copyright (C) 2022 Huawei Device Co., Ltd. +# Copyright (C) 2023 Huawei Device Co., Ltd. # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at @@ -16,6 +16,7 @@ group("distributeddatamgr") { testonly = true if (is_standard_system) { deps = [ + "UDMFtest:UDMFtest", "dataObjectjstest/hap:dataObject_js_test", "dataSharejstest/hap:dataShare_js_test", "distributedKVStoretest:distributedKVStoretest", diff --git a/distributeddatamgr/UDMFtest/BUILD.gn b/distributeddatamgr/UDMFtest/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..1c5c9b71427ad8989eef256683c5787cba1eb5b4 --- /dev/null +++ b/distributeddatamgr/UDMFtest/BUILD.gn @@ -0,0 +1,21 @@ +# Copyright (c) 2023 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import("//test/xts/tools/build/suite.gni") + +group("UDMFtest") { + testonly = true + if (is_standard_system) { + deps = [ "UDMFtest:UDMF_ets_test" ] + } +} diff --git a/distributeddatamgr/UDMFtest/UDMFtest/AppScope/app.json b/distributeddatamgr/UDMFtest/UDMFtest/AppScope/app.json new file mode 100644 index 0000000000000000000000000000000000000000..cb4bf6e2a483f3b89c1e0a85c3b12b8370407ea1 --- /dev/null +++ b/distributeddatamgr/UDMFtest/UDMFtest/AppScope/app.json @@ -0,0 +1,20 @@ +{ + "app": { + "bundleName": "ohos.acts.UDMF", + "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/UDMFtest/UDMFtest/AppScope/resources/base/element/string.json b/distributeddatamgr/UDMFtest/UDMFtest/AppScope/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..743eebb13dba6bf565857756006a7c13bd8e7299 --- /dev/null +++ b/distributeddatamgr/UDMFtest/UDMFtest/AppScope/resources/base/element/string.json @@ -0,0 +1,8 @@ +{ + "string": [ + { + "name": "app_name", + "value": "MyApplication2" + } + ] +} diff --git a/distributeddatamgr/UDMFtest/UDMFtest/AppScope/resources/base/media/app_icon.png b/distributeddatamgr/UDMFtest/UDMFtest/AppScope/resources/base/media/app_icon.png new file mode 100644 index 0000000000000000000000000000000000000000..ce307a8827bd75456441ceb57d530e4c8d45d36c Binary files /dev/null and b/distributeddatamgr/UDMFtest/UDMFtest/AppScope/resources/base/media/app_icon.png differ diff --git a/distributeddatamgr/UDMFtest/UDMFtest/BUILD.gn b/distributeddatamgr/UDMFtest/UDMFtest/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..efe49f9db4e15b596070b411f475c3de7accc0a0 --- /dev/null +++ b/distributeddatamgr/UDMFtest/UDMFtest/BUILD.gn @@ -0,0 +1,43 @@ +# Copyright (c) 2023 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import("//test/xts/tools/build/suite.gni") + +ohos_js_hap_suite("UDMF_ets_test") { + hap_profile = "entry/src/main/module.json" + js_build_mode = "debug" + deps = [ + ":relationalStoreStage_js_assets", + ":relationalStoreStage_resources", + ] + ets2abc = true + certificate_profile = "signature/openharmony_sx.p7b" + hap_name = "ActsUDMFTest" + subsystem_name = "distributeddatamgr" + part_name = "relational_store" +} + +ohos_app_scope("relationalStoreStage_app_profile") { + app_profile = "AppScope/app.json" + sources = [ "AppScope/resources" ] +} + +ohos_js_assets("relationalStoreStage_js_assets") { + source_dir = "entry/src/main/ets" +} + +ohos_resources("relationalStoreStage_resources") { + sources = [ "entry/src/main/resources" ] + deps = [ ":relationalStoreStage_app_profile" ] + hap_profile = "entry/src/main/module.json" +} diff --git a/distributeddatamgr/UDMFtest/UDMFtest/Test.json b/distributeddatamgr/UDMFtest/UDMFtest/Test.json new file mode 100644 index 0000000000000000000000000000000000000000..043f75be779263ce83a32a6b3d38b7f7118f4663 --- /dev/null +++ b/distributeddatamgr/UDMFtest/UDMFtest/Test.json @@ -0,0 +1,18 @@ +{ + "description": "Configuration for hjunit demo Tests", + "driver": { + "type": "OHJSUnitTest", + "test-timeout": "180000", + "bundle-name": "ohos.acts.UDMF", + "module-name": "entry", + "shell-timeout": "600000", + "testcase-timeout": 70000 + }, + "kits": [{ + "test-file-name": [ + "ActsUDMFTest.hap" + ], + "type": "AppInstallKit", + "cleanup-apps": true + }] +} \ No newline at end of file diff --git a/distributeddatamgr/UDMFtest/UDMFtest/entry/src/main/ets/Application/AbilityStage.ts b/distributeddatamgr/UDMFtest/UDMFtest/entry/src/main/ets/Application/AbilityStage.ts new file mode 100644 index 0000000000000000000000000000000000000000..f570795b56803731be68e9496e52d12eaf10ea35 --- /dev/null +++ b/distributeddatamgr/UDMFtest/UDMFtest/entry/src/main/ets/Application/AbilityStage.ts @@ -0,0 +1,22 @@ +/* +* Copyright (c) 2023 Huawei Device Co., Ltd. +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +import AbilityStage from "@ohos.app.ability.AbilityStage" + +export default class MyAbilityStage extends AbilityStage { + onCreate() { + console.log("[Demo] MyAbilityStage onCreate") + } +} \ No newline at end of file diff --git a/distributeddatamgr/UDMFtest/UDMFtest/entry/src/main/ets/MainAbility/MainAbility.ts b/distributeddatamgr/UDMFtest/UDMFtest/entry/src/main/ets/MainAbility/MainAbility.ts new file mode 100644 index 0000000000000000000000000000000000000000..26985371581a769c35fca8298f2f0537d2f83afc --- /dev/null +++ b/distributeddatamgr/UDMFtest/UDMFtest/entry/src/main/ets/MainAbility/MainAbility.ts @@ -0,0 +1,141 @@ +/* +* Copyright (c) 2023 Huawei Device Co., Ltd. +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +import Ability from '@ohos.app.ability.UIAbility' +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 = 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."); + 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.connectServiceExtensionAbility(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.connectServiceExtensionAbility(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/UDMFtest/UDMFtest/entry/src/main/ets/MainAbility/pages/index.ets b/distributeddatamgr/UDMFtest/UDMFtest/entry/src/main/ets/MainAbility/pages/index.ets new file mode 100644 index 0000000000000000000000000000000000000000..596ee12ca2a7c096c811c62cabc73318f8d3f977 --- /dev/null +++ b/distributeddatamgr/UDMFtest/UDMFtest/entry/src/main/ets/MainAbility/pages/index.ets @@ -0,0 +1,58 @@ +/* +* Copyright (c) 2023 Huawei Device Co., Ltd. +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ +import 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/UDMFtest/UDMFtest/entry/src/main/ets/TestAbility/TestAbility.ts b/distributeddatamgr/UDMFtest/UDMFtest/entry/src/main/ets/TestAbility/TestAbility.ts new file mode 100644 index 0000000000000000000000000000000000000000..871dc89b25426b48a4575c64948ef5d916477140 --- /dev/null +++ b/distributeddatamgr/UDMFtest/UDMFtest/entry/src/main/ets/TestAbility/TestAbility.ts @@ -0,0 +1,50 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +import Ability from '@ohos.app.ability.UIAbility' + +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/UDMFtest/UDMFtest/entry/src/main/ets/TestAbility/pages/index.ets b/distributeddatamgr/UDMFtest/UDMFtest/entry/src/main/ets/TestAbility/pages/index.ets new file mode 100644 index 0000000000000000000000000000000000000000..1cf6eda5d963e40bc2e277218b30397f3ad43b09 --- /dev/null +++ b/distributeddatamgr/UDMFtest/UDMFtest/entry/src/main/ets/TestAbility/pages/index.ets @@ -0,0 +1,48 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +import 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/UDMFtest/UDMFtest/entry/src/main/ets/TestRunner/OpenHarmonyTestRunner.ts b/distributeddatamgr/UDMFtest/UDMFtest/entry/src/main/ets/TestRunner/OpenHarmonyTestRunner.ts new file mode 100644 index 0000000000000000000000000000000000000000..97f884cc114757e4026c523187d874e6a15f6db9 --- /dev/null +++ b/distributeddatamgr/UDMFtest/UDMFtest/entry/src/main/ets/TestRunner/OpenHarmonyTestRunner.ts @@ -0,0 +1,78 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +import 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 ohos.acts.UDMF.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/UDMFtest/UDMFtest/entry/src/main/ets/test/List.test.ets b/distributeddatamgr/UDMFtest/UDMFtest/entry/src/main/ets/test/List.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..fed9393e6356238814a9774040940d7599e395f7 --- /dev/null +++ b/distributeddatamgr/UDMFtest/UDMFtest/entry/src/main/ets/test/List.test.ets @@ -0,0 +1,20 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + + +import UDMFApiTest from './UDMF.test.ets' +export default function testsuite() { + UDMFApiTest() +} diff --git a/distributeddatamgr/UDMFtest/UDMFtest/entry/src/main/ets/test/UDMF.test.ets b/distributeddatamgr/UDMFtest/UDMFtest/entry/src/main/ets/test/UDMF.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..59b3b818d70da0d065eb585c4f41d5e194e76c4b --- /dev/null +++ b/distributeddatamgr/UDMFtest/UDMFtest/entry/src/main/ets/test/UDMF.test.ets @@ -0,0 +1,477 @@ +/* + * Copyright (C) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the 'License'); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an 'AS IS' BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from '@ohos/hypium' +import UDMF from '@ohos.data.UDMF'; + +export default function UDMFApiTest() { + describe('UDMFApiTest', function () { + console.info('start################################start'); + + let text = new UDMF.Text(); + text.details = { + title:"标题", + content:"内容" + }; + + let plainText = new UDMF.PlainText(); + plainText.details = { + title:"标题", + content:"内容" + }; + plainText.textContent = "textContent"; + plainText.abstract = "abstract"; + + let link = new UDMF.Hyperlink(); + link.details = { + title:"标题", + content:"内容" + }; + link.url = "url"; + link.description = "description"; + + let html = new UDMF.HTML(); + html.details = { + title:"标题", + content:"内容" + }; + html.htmlContent = "htmlContent"; + html.plainContent = "plainContent"; + + let file = new UDMF.File(); + file.details = { + title:"标题", + content:"内容" + }; + file.uri = "uri"; + + let folder = new UDMF.Folder(); + folder.details = { + title:"标题", + content:"内容" + }; + folder.folderUri = "folderUri"; + + let image = new UDMF.Image(); + image.details = { + title:"标题", + content:"内容" + }; + image.imageUri = "imageUri"; + + let video = new UDMF.Video(); + video.details = { + title:"标题", + content:"内容" + }; + video.videoUri = "videoUri"; + + let arrayBuf = new ArrayBuffer(2 * 3 * 4); + let u8Array = new Uint8Array(arrayBuf); + + let systemDefinedRecord = new UDMF.SystemDefinedRecord(); + systemDefinedRecord.details = { + title:"标题", + version:1, + content:u8Array + }; + + let systemDefinedForm = new UDMF.SystemDefinedForm(); + systemDefinedForm.details = { + title:"标题", + version:1, + content:u8Array + }; + systemDefinedForm.formId = 123456; + systemDefinedForm.formName = 'formName'; + systemDefinedForm.bundleName = 'bundleName'; + systemDefinedForm.abilityName = 'abilityName'; + systemDefinedForm.module = 'module'; + + let systemDefinedAppItem = new UDMF.SystemDefinedAppItem(); + systemDefinedAppItem.details = { + title:"标题", + version:1, + content:u8Array + }; + systemDefinedAppItem.appId = 'appId'; + systemDefinedAppItem.appName = 'appName'; + systemDefinedAppItem.appIconId = 'appIconId'; + systemDefinedAppItem.appLabelId = 'appLabelId'; + systemDefinedAppItem.bundleName = 'bundleName'; + systemDefinedAppItem.abilityName = 'abilityName'; + + let systemDefinedPixelMap = new UDMF.SystemDefinedPixelMap(); + systemDefinedPixelMap.details = { + title:"标题", + version:1, + content:u8Array + }; + systemDefinedPixelMap.rawData = u8Array; + + let applicationDefinedRecord = new UDMF.ApplicationDefinedRecord(); + applicationDefinedRecord.applicationDefinedType = 'applicationDefinedType'; + applicationDefinedRecord.rawData = u8Array; + + /** + * @tc.number SUB_DistributedData_Udmf_API001 + * @tc.name CreateData + * @tc.desc Test UDMF creating a unifieddata with a text record. + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 1 + */ + it('SUB_DistributedData_Udmf_API001',0, async function (done) { + console.info('SUB_DistributedData_Udmf_API001 start'); + let unifiedData = new UDMF.UnifiedData(text); + let records = unifiedData.getRecords(); + let record = (records[0]); + expect(records.length).assertEqual(1); + expect(record.details.title).assertEqual('标题'); + expect(record.details.content).assertEqual('内容'); + console.info("SUB_DistributedData_Udmf_API001 end"); + done(); + }) + + /** + * @tc.number SUB_DistributedData_Udmf_API002 + * @tc.name CreateData + * @tc.desc Test UDMF creating a unifieddata with a plaintext record. + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 1 + */ + it('SUB_DistributedData_Udmf_API002',0, async function (done) { + console.info('SUB_DistributedData_Udmf_API002 start'); + let unifiedData = new UDMF.UnifiedData(plainText); + let records = unifiedData.getRecords(); + let record = (records[0]); + expect(records.length).assertEqual(1); + expect(record.details.title).assertEqual('标题'); + expect(record.details.content).assertEqual('内容'); + expect(record.textContent).assertEqual('textContent'); + expect(record.abstract).assertEqual('abstract'); + console.info("SUB_DistributedData_Udmf_API002 end"); + done(); + }) + + /** + * @tc.number SUB_DistributedData_Udmf_API003 + * @tc.name CreateData + * @tc.desc Test UDMF creating a unifieddata with a hyperlink record. + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 1 + */ + it('SUB_DistributedData_Udmf_API003',0, async function (done) { + console.info('SUB_DistributedData_Udmf_API003 start'); + let unifiedData = new UDMF.UnifiedData(link); + let records = unifiedData.getRecords(); + let record = (records[0]); + expect(records.length).assertEqual(1); + expect(record.details.title).assertEqual('标题'); + expect(record.details.content).assertEqual('内容'); + expect(record.url).assertEqual('url'); + expect(record.description).assertEqual('description'); + console.info("SUB_DistributedData_Udmf_API003 end"); + done(); + }) + + /** + * @tc.number SUB_DistributedData_Udmf_API004 + * @tc.name CreateData + * @tc.desc Test UDMF creating a unifieddata with a html record. + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 1 + */ + it('SUB_DistributedData_Udmf_API004',0, async function (done) { + console.info('SUB_DistributedData_Udmf_API004 start'); + let unifiedData = new UDMF.UnifiedData(html); + let records = unifiedData.getRecords(); + let record = (records[0]); + expect(records.length).assertEqual(1); + expect(record.details.title).assertEqual('标题'); + expect(record.details.content).assertEqual('内容'); + expect(record.htmlContent).assertEqual('htmlContent'); + expect(record.plainContent).assertEqual('plainContent'); + console.info("SUB_DistributedData_Udmf_API004 end"); + done(); + }) + + /** + * @tc.number SUB_DistributedData_Udmf_API005 + * @tc.name CreateData + * @tc.desc Test UDMF creating a unifieddata with a file record. + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 1 + */ + it('SUB_DistributedData_Udmf_API005',0, async function (done) { + console.info('SUB_DistributedData_Udmf_API005 start'); + let unifiedData = new UDMF.UnifiedData(file); + let records = unifiedData.getRecords(); + let record = (records[0]); + expect(records.length).assertEqual(1); + expect(record.details.title).assertEqual('标题'); + expect(record.details.content).assertEqual('内容'); + console.info("SUB_DistributedData_Udmf_API005 end"); + done(); + }) + + /** + * @tc.number SUB_DistributedData_Udmf_API006 + * @tc.name CreateData + * @tc.desc Test UDMF creating a unifieddata with a folder record. + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 1 + */ + it('SUB_DistributedData_Udmf_API006',0, async function (done) { + console.info('SUB_DistributedData_Udmf_API006 start'); + let unifiedData = new UDMF.UnifiedData(folder); + let records = unifiedData.getRecords(); + let record = (records[0]); + expect(records.length).assertEqual(1); + expect(record.details.title).assertEqual('标题'); + expect(record.details.content).assertEqual('内容'); + console.info("SUB_DistributedData_Udmf_API006 end"); + done(); + }) + + /** + * @tc.number SUB_DistributedData_Udmf_API007 + * @tc.name CreateData + * @tc.desc Test UDMF creating a unifieddata with a image record. + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 1 + */ + it('SUB_DistributedData_Udmf_API007',0, async function (done) { + console.info('SUB_DistributedData_Udmf_API007 start'); + let unifiedData = new UDMF.UnifiedData(image); + let records = unifiedData.getRecords(); + let record = (records[0]); + expect(records.length).assertEqual(1); + expect(record.details.title).assertEqual('标题'); + expect(record.details.content).assertEqual('内容'); + console.info("SUB_DistributedData_Udmf_API007 end"); + done(); + }) + + /** + * @tc.number SUB_DistributedData_Udmf_API008 + * @tc.name CreateData + * @tc.desc Test UDMF creating a unifieddata with a video record. + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 1 + */ + it('SUB_DistributedData_Udmf_API008',0, async function (done) { + console.info('SUB_DistributedData_Udmf_API008 start'); + let unifiedData = new UDMF.UnifiedData(video); + let records = unifiedData.getRecords(); + let record = (records[0]); + expect(records.length).assertEqual(1); + expect(record.details.title).assertEqual('标题'); + expect(record.details.content).assertEqual('内容'); + console.info("SUB_DistributedData_Udmf_API008 end"); + done(); + }) + + /** + * @tc.number SUB_DistributedData_Udmf_API009 + * @tc.name CreateData + * @tc.desc Test UDMF creating a unifieddata with a systemdefinedrecord record. + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 1 + */ + it('SUB_DistributedData_Udmf_API009',0, async function (done) { + console.info('SUB_DistributedData_Udmf_API009 start'); + let unifiedData = new UDMF.UnifiedData(systemDefinedRecord); + let records = unifiedData.getRecords(); + let record = (records[0]); + expect(records.length).assertEqual(1); + expect(record.details.title).assertEqual('标题'); + expect(record.details.version).assertEqual(1); + for(var i = 0; i(records[0]); + expect(records.length).assertEqual(1); + expect(record.details.title).assertEqual('标题'); + expect(record.details.version).assertEqual(1); + for(var i = 0; i(records[0]); + expect(records.length).assertEqual(1); + expect(record.details.title).assertEqual('标题'); + expect(record.details.version).assertEqual(1); + for(var i = 0; i(records[0]); + expect(records.length).assertEqual(1); + expect(record.details.title).assertEqual('标题'); + expect(record.details.version).assertEqual(1); + for(var i = 0; i(records[0]); + expect(records.length).assertEqual(1); + expect(record.applicationDefinedType).assertEqual('applicationDefinedType'); + for(var i = 0; i(records[0]); + let record2 = (records[1]); + let record3 = (records[2]); + let record4 = (records[3]); + let record5 = (records[4]); + let record6 = (records[5]); + let record7 = (records[6]); + let record8 = (records[7]); + let record9 = (records[8]); + let record10 = (records[9]); + let record11 = (records[10]); + let record12 = (records[11]); + let record13 = (records[12]); + expect(records.length).assertEqual(13); + expect(record1.getType()).assertEqual(UDMF.UnifiedDataType.TEXT); + expect(record2.getType()).assertEqual(UDMF.UnifiedDataType.PLAIN_TEXT); + expect(record3.getType()).assertEqual(UDMF.UnifiedDataType.HYPERLINK); + expect(record4.getType()).assertEqual(UDMF.UnifiedDataType.HTML); + expect(record5.getType()).assertEqual(UDMF.UnifiedDataType.FILE); + expect(record6.getType()).assertEqual(UDMF.UnifiedDataType.FOLDER); + expect(record7.getType()).assertEqual(UDMF.UnifiedDataType.IMAGE); + expect(record8.getType()).assertEqual(UDMF.UnifiedDataType.VIDEO); + expect(record9.getType()).assertEqual(UDMF.UnifiedDataType.SYSTEM_DEFINED_RECORD); + expect(record10.getType()).assertEqual(UDMF.UnifiedDataType.SYSTEM_DEFINED_FORM); + expect(record11.getType()).assertEqual(UDMF.UnifiedDataType.SYSTEM_DEFINED_APP_ITEM); + expect(record12.getType()).assertEqual(UDMF.UnifiedDataType.SYSTEM_DEFINED_PIXEL_MAP); + expect(record13.getType()).assertEqual(UDMF.UnifiedDataType.APPLICATION_DEFINED_RECORD); + console.info("SUB_DistributedData_Udmf_API014 end"); + done(); + }) + }) +} \ No newline at end of file diff --git a/distributeddatamgr/UDMFtest/UDMFtest/entry/src/main/module.json b/distributeddatamgr/UDMFtest/UDMFtest/entry/src/main/module.json new file mode 100644 index 0000000000000000000000000000000000000000..979a3b9b4bb9199c79481a19a6b7c938e4fc44b4 --- /dev/null +++ b/distributeddatamgr/UDMFtest/UDMFtest/entry/src/main/module.json @@ -0,0 +1,40 @@ +{ + "module": { + "package": "ohos.acts.UDMF", + "name": "entry", + "mainAbility": "ohos.acts.UDMF.MainAbility", + "type": "entry", + "srcEntrance": "./ets/Application/AbilityStage.ts", + "description": "$string:entry_desc", + "mainElement": "MainAbility", + "deviceTypes": [ + "default", + "tablet", + "phone" + ], + "deliveryWithInstall": true, + "installationFree": false, + "pages": "$profile:main_pages", + "uiSyntax": "ets", + "abilities": [ + { + "name": "ohos.acts.UDMF.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/UDMFtest/UDMFtest/entry/src/main/resources/base/element/string.json b/distributeddatamgr/UDMFtest/UDMFtest/entry/src/main/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..3db4141e4690bb0999a2ad900c2e30f3d4c310d9 --- /dev/null +++ b/distributeddatamgr/UDMFtest/UDMFtest/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": "ActsUDMFTest" + } + ] +} \ No newline at end of file diff --git a/distributeddatamgr/UDMFtest/UDMFtest/entry/src/main/resources/base/media/icon.png b/distributeddatamgr/UDMFtest/UDMFtest/entry/src/main/resources/base/media/icon.png new file mode 100644 index 0000000000000000000000000000000000000000..ce307a8827bd75456441ceb57d530e4c8d45d36c Binary files /dev/null and b/distributeddatamgr/UDMFtest/UDMFtest/entry/src/main/resources/base/media/icon.png differ diff --git a/distributeddatamgr/UDMFtest/UDMFtest/entry/src/main/resources/base/profile/main_pages.json b/distributeddatamgr/UDMFtest/UDMFtest/entry/src/main/resources/base/profile/main_pages.json new file mode 100644 index 0000000000000000000000000000000000000000..c1858c216308ad312862a877139a8ba6908ec3c6 --- /dev/null +++ b/distributeddatamgr/UDMFtest/UDMFtest/entry/src/main/resources/base/profile/main_pages.json @@ -0,0 +1,5 @@ +{ + "src": [ + "MainAbility/pages/index" + ] +} diff --git a/distributeddatamgr/UDMFtest/UDMFtest/signature/openharmony_sx.p7b b/distributeddatamgr/UDMFtest/UDMFtest/signature/openharmony_sx.p7b new file mode 100644 index 0000000000000000000000000000000000000000..23468c8824de9f98ae59b1d3910cc78abb896c72 Binary files /dev/null and b/distributeddatamgr/UDMFtest/UDMFtest/signature/openharmony_sx.p7b differ