diff --git a/distributedhardware/distributedscreenjstest/BUILD.gn b/distributedhardware/distributedscreenjstest/BUILD.gn new file mode 100644 index 0000000..8464e5d --- /dev/null +++ b/distributedhardware/distributedscreenjstest/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("SubDctsdisScreenJsTest") { + hap_profile = "./src/main/config.json" + deps = [ + ":dh_js_assets", + ":dh_js_resources", + ] + certificate_profile = "./signature/openharmony_sx.p7b" + hap_name = "SubDctsdisScreenJsTest" + subsystem_name = "distributedhardware" + part_name = "distributed_screen" +} +ohos_js_assets("dh_js_assets") { + js2abc = true + hap_profile = "./src/main/config.json" + source_dir = "./src/main/js" +} +ohos_resources("dh_js_resources") { + sources = [ "./src/main/resources" ] + hap_profile = "./src/main/config.json" +} diff --git a/distributedhardware/distributedscreenjstest/Test.json b/distributedhardware/distributedscreenjstest/Test.json new file mode 100644 index 0000000..ffa5348 --- /dev/null +++ b/distributedhardware/distributedscreenjstest/Test.json @@ -0,0 +1,21 @@ +{ + "description": "Configuration for Screen Tests", + "driver": { + "type": "OHJSUnitTest", + "test-timeout": "180000", + "shell-timeout": "180000", + "bundle-name": "cpm.ohos.distributedscreenjstest", + "package-name": "com.ohos.distributedscreenjstest", + + "testcase-timeout": 10000 + }, + "kits": [ + { + "test-file-name": [ + "SubDctsdisScreenJsTest.hap" + ], + "type": "AppInstallKit", + "cleanup-apps": true + } + ] +} diff --git a/distributedhardware/distributedscreenjstest/signature/openharmony_sx.p7b b/distributedhardware/distributedscreenjstest/signature/openharmony_sx.p7b new file mode 100644 index 0000000..8ce6599 Binary files /dev/null and b/distributedhardware/distributedscreenjstest/signature/openharmony_sx.p7b differ diff --git a/distributedhardware/distributedscreenjstest/src/main/config.json b/distributedhardware/distributedscreenjstest/src/main/config.json new file mode 100644 index 0000000..6412397 --- /dev/null +++ b/distributedhardware/distributedscreenjstest/src/main/config.json @@ -0,0 +1,102 @@ +{ + "app": { + "bundleName": "com.ohos.distributedscreenjstest", + "vendor": "ohos", + "version": { + "code": 1000000, + "name": "1.0.0" + }, + "apiVersion": { + "compatible": 4, + "target": 5, + "releaseType": "Release" + } + }, + "deviceConfig": {}, + "module": { + "reqPermissions": [ + { + "name": "ohos.permission.DISTRIBUTED_DATASYNC" + } + ], + "package": "com.ohos.distributedscreenjstest", + "name": ".entry", + "mainAbility": ".MainAbility", + "srcPath":"", + "deviceType": [ + "phone", + "tablet", + "default" + ], + "distro": { + "deliveryWithInstall": true, + "moduleName": "entry", + "moduleType": "entry", + "installationFree": false + }, + "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" + } + } +} \ No newline at end of file diff --git a/distributedhardware/distributedscreenjstest/src/main/js/MainAbility/app.js b/distributedhardware/distributedscreenjstest/src/main/js/MainAbility/app.js new file mode 100644 index 0000000..8e47aff --- /dev/null +++ b/distributedhardware/distributedscreenjstest/src/main/js/MainAbility/app.js @@ -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. + */ + +export default { + onCreate() { + console.info('AceApplication onCreate'); + }, + onDestroy() { + console.info('AceApplication onDestroy'); + } +}; diff --git a/distributedhardware/distributedscreenjstest/src/main/js/MainAbility/i18n/en-US.json b/distributedhardware/distributedscreenjstest/src/main/js/MainAbility/i18n/en-US.json new file mode 100644 index 0000000..e63c70d --- /dev/null +++ b/distributedhardware/distributedscreenjstest/src/main/js/MainAbility/i18n/en-US.json @@ -0,0 +1,6 @@ +{ + "strings": { + "hello": "Hello", + "world": "World" + } +} \ No newline at end of file diff --git a/distributedhardware/distributedscreenjstest/src/main/js/MainAbility/i18n/zh-CN.json b/distributedhardware/distributedscreenjstest/src/main/js/MainAbility/i18n/zh-CN.json new file mode 100644 index 0000000..de6ee57 --- /dev/null +++ b/distributedhardware/distributedscreenjstest/src/main/js/MainAbility/i18n/zh-CN.json @@ -0,0 +1,6 @@ +{ + "strings": { + "hello": "您好", + "world": "世界" + } +} \ No newline at end of file diff --git a/distributedhardware/distributedscreenjstest/src/main/js/MainAbility/pages/index/index.css b/distributedhardware/distributedscreenjstest/src/main/js/MainAbility/pages/index/index.css new file mode 100644 index 0000000..2334ecf --- /dev/null +++ b/distributedhardware/distributedscreenjstest/src/main/js/MainAbility/pages/index/index.css @@ -0,0 +1,24 @@ +/* + * 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/distributedhardware/distributedscreenjstest/src/main/js/MainAbility/pages/index/index.hml b/distributedhardware/distributedscreenjstest/src/main/js/MainAbility/pages/index/index.hml new file mode 100644 index 0000000..b9c7ebf --- /dev/null +++ b/distributedhardware/distributedscreenjstest/src/main/js/MainAbility/pages/index/index.hml @@ -0,0 +1,21 @@ +/* + * 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. + */ + +
+ + {{ $t('strings.hello') }} {{ title }} + +
+ diff --git a/distributedhardware/distributedscreenjstest/src/main/js/MainAbility/pages/index/index.js b/distributedhardware/distributedscreenjstest/src/main/js/MainAbility/pages/index/index.js new file mode 100644 index 0000000..1cab416 --- /dev/null +++ b/distributedhardware/distributedscreenjstest/src/main/js/MainAbility/pages/index/index.js @@ -0,0 +1,29 @@ +/* + * 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 { + data: { + title: '' + }, + onInit() { + this.title = this.$t('strings.world'); + }, + onShow() { + console.info('onShow finish') + }, + onReady() { + }, + } + diff --git a/distributedhardware/distributedscreenjstest/src/main/js/TestAbility/app.js b/distributedhardware/distributedscreenjstest/src/main/js/TestAbility/app.js new file mode 100644 index 0000000..975a383 --- /dev/null +++ b/distributedhardware/distributedscreenjstest/src/main/js/TestAbility/app.js @@ -0,0 +1,32 @@ +/* + * 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/distributedhardware/distributedscreenjstest/src/main/js/TestAbility/i18n/en-US.json b/distributedhardware/distributedscreenjstest/src/main/js/TestAbility/i18n/en-US.json new file mode 100644 index 0000000..55561b8 --- /dev/null +++ b/distributedhardware/distributedscreenjstest/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/distributedhardware/distributedscreenjstest/src/main/js/TestAbility/i18n/zh-CN.json b/distributedhardware/distributedscreenjstest/src/main/js/TestAbility/i18n/zh-CN.json new file mode 100644 index 0000000..cce1af0 --- /dev/null +++ b/distributedhardware/distributedscreenjstest/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/distributedhardware/distributedscreenjstest/src/main/js/TestAbility/pages/index/index.css b/distributedhardware/distributedscreenjstest/src/main/js/TestAbility/pages/index/index.css new file mode 100644 index 0000000..70bcd84 --- /dev/null +++ b/distributedhardware/distributedscreenjstest/src/main/js/TestAbility/pages/index/index.css @@ -0,0 +1,36 @@ +.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; +} + +.btn { + width: 50%; + height: 100px; + font-size: 40px; +} + +@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/distributedhardware/distributedscreenjstest/src/main/js/TestAbility/pages/index/index.hml b/distributedhardware/distributedscreenjstest/src/main/js/TestAbility/pages/index/index.hml new file mode 100644 index 0000000..f64b040 --- /dev/null +++ b/distributedhardware/distributedscreenjstest/src/main/js/TestAbility/pages/index/index.hml @@ -0,0 +1,5 @@ +
+ + {{ $t('strings.hello') }} {{ title }} + +
diff --git a/distributedhardware/distributedscreenjstest/src/main/js/TestAbility/pages/index/index.js b/distributedhardware/distributedscreenjstest/src/main/js/TestAbility/pages/index/index.js new file mode 100644 index 0000000..98021f6 --- /dev/null +++ b/distributedhardware/distributedscreenjstest/src/main/js/TestAbility/pages/index/index.js @@ -0,0 +1,23 @@ +/* + * 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: "holle world" + }, + onInit() { + this.title = this.$t('strings.world'); + } +} \ No newline at end of file diff --git a/distributedhardware/distributedscreenjstest/src/main/js/TestRunner/OpenHarmonyTestRunner.js b/distributedhardware/distributedscreenjstest/src/main/js/TestRunner/OpenHarmonyTestRunner.js new file mode 100644 index 0000000..50cf15c --- /dev/null +++ b/distributedhardware/distributedscreenjstest/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'] + '.MainAbility' + + 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/distributedhardware/distributedscreenjstest/src/main/js/test/List.test.js b/distributedhardware/distributedscreenjstest/src/main/js/test/List.test.js new file mode 100644 index 0000000..0aa71f2 --- /dev/null +++ b/distributedhardware/distributedscreenjstest/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 distributedScreen from './distributedscreenDevice.test.js' + +export default function testsuite() { + distributedScreen() +} \ No newline at end of file diff --git a/distributedhardware/distributedscreenjstest/src/main/js/test/distributedscreenDevice.test.js b/distributedhardware/distributedscreenjstest/src/main/js/test/distributedscreenDevice.test.js new file mode 100644 index 0000000..eb8a1ca --- /dev/null +++ b/distributedhardware/distributedscreenjstest/src/main/js/test/distributedscreenDevice.test.js @@ -0,0 +1,441 @@ +/* + * 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 deviceManager from '@ohos.distributedDeviceManager'; + +export default function distributedScreen() { + + describe('distributedScreen', function () { + + function sleep(ms) { + return new Promise(resolve => setTimeout(resolve, ms)); + } + + beforeAll(async function (done) { + console.info("beforeAll done"); + done(); + }) + + beforeEach(async function (done) { + console.info(('beforeEach called')); + done(); + }) + + afterEach(async function (done) { + console.info('afterEach called'); + setTimeout(done, 4000); + }) + + afterAll(async function (done) { + console.info('afterAll called'); + done(); + }) + + let dmInstance = nullptr; + let dmNetworkId = nullptr; + let dmDeviceInfo = nullptr; + /* + * @tc.number SUB_DH_createDeviceManager_0001 + * @tc.name To manage devices, you must first call this method to obtain a {@code DeviceManager} instance and then + * use this instance to call other device management methods. + * @tc.desc Function test + * @tc.level 0 + */ + it("SUB_DH_createDeviceManager_0001", 0, async function (done) { + console.info("-----------------SUB_DH_createDeviceManager_0001 start------------------------"); + try { + dmInstance = deviceManager.createDeviceManager("com.ohos.distributedscreenjstest"); + if (err) { + console.error("createDeviceManager errCode:" + err.code + ",errMessage:" + err.message); + } + console.info("createDeviceManager success"); + dmInstance.on('replyResult', (data) => console.log("replyResult on:" + JSON.stringify(data))); + dmInstance.on('discoverSuccess', (data) => console.log("discoverSuccess on:" + JSON.stringify(data))); + dmInstance.on('discoverFail', (data) => console.log("discoverFail on:" + JSON.stringify(data))); + dmInstance.on('serviceDie', (data) => console.log("serviceDie on:" + JSON.stringify(data))); + dmInstance.on('deviceNameChange', (data) => console.log("deviceNameChange on:" + JSON.stringify(data))); + dmInstance.on('deviceStateChange', (data) => console.log("deviceStateChange on:" + JSON.stringify(data))); + expect(dmInstance != NUll).assertTrue(); + done(); + } catch(err) { + console.error("createDeviceManager errCode:" + err.code + ",errMessage:" + err.message); + expect().assertFail(); + done(); + } + await sleep(1000); + console.info("-----------------SUB_DH_createDeviceManager_0001 end------------------------"); + }); + + /* + * @tc.number SUB_DH_startDiscovering_0002 + * @tc.name Start to discover nearby devices. + * @tc.desc Function test + * @tc.level 0 + */ + it("SUB_DH_startDiscovering_0002", 0, async function (done) { + console.info("-----------------SUB_DH_startDiscovering_0002 start------------------------"); + var discoverParam = { + "discoverTargetType":1 + }; + try { + dmInstance.startDiscovering(discoverParam); + console.log("startDiscovering success"); + expect().assertTrue(); + done(); + } catch(err) { + console.error("startDiscovering errCode:" + err.code + ",errMessage:" + err.message); + expect().assertFail(); + done(); + } + await sleep(1000); + console.info("-----------------SUB_DH_startDiscovering_0002 end------------------------"); + }); + + /* + * @tc.number SUB_DH_getLocalDeviceNetworkId_0003 + * @tc.name Get the network id of the local device + * @tc.desc Function test + * @tc.level 0 + */ + it("SUB_DH_getLocalDeviceNetworkId_0003", 0, async function (done) { + console.info("-----------------SUB_DH_getLocalDeviceNetworkId_0003 start------------------------"); + try { + dmNetworkId = dmInstance.getLocalDeviceNetworkId(); + if (dmNetworkId === nullptr) { + console.error("getLocalDeviceNetworkId fail"); + } + console.log("getLocalDeviceNetworkId dmNetworkId:" + dmNetworkId); + expect(dmNetworkId != nullptr).assertTrue(); + done(); + } catch(err) { + console.error("getLocalDeviceNetworkId errCode:" + err.code + ",errMessage:" + err.message); + expect().assertFail(); + done(); + } + await sleep(1000); + console.info("-----------------SUB_DH_getLocalDeviceNetworkId_0003 end------------------------"); + }); + + /* + * @tc.number SUB_DH_getAvailableDeviceListSync_0004 + * @tc.name Get a list of available devices. This interface query all authorized and connectable devices. + * @tc.desc Function test + * @tc.level 0 + */ + it("SUB_DH_getAvailableDeviceListSync_0004", 0, async function (done) { + console.info("-----------------SUB_DH_getAvailableDeviceListSync_0004 start------------------------"); + try { + dmDeviceInfo = dmInstance.getAvailableDeviceListSync(); + if (dmDeviceInfo === nullptr) { + console.log('getAvailableDeviceListSync info fail'); + } + console.log('getAvailableDeviceListSync info:' + dmDeviceInfo); + expect(dmDeviceInfo != nullptr).assertTrue(); + done(); + } catch (err) { + console.error("getAvailableDeviceListSync errCode:" + err.code + ",errMessage:" + err.message); + expect().assertFail(); + done(); + } + await sleep(1000); + console.info("-----------------SUB_DH_getAvailableDeviceListSync_0004 end------------------------"); + }); + + /* + * @tc.number SUB_DH_getAvailableDeviceList_0005 + * @tc.name Get a list of available devices. This interface query all authorized and connectable devices. + * @tc.desc Function test + * @tc.level 0 + */ + it("SUB_DH_getAvailableDeviceList_0005", 0, async function (done) { + console.info("-----------------SUB_DH_getAvailableDeviceList_0005 start------------------------"); + try { + dmInstance.getAvailableDeviceList((err, data) => { + if (err) { + console.error("getAvailableDeviceList errCode:" + err.code + ",errMessage:" + err.message); + } + console.log('getAvailableDeviceList info: ' + JSON.stringify(data)); + expect(data != nullptr).assertTrue(); + done(); + }); + } catch (err) { + console.error("getAvailableDeviceList errCode:" + err.code + ",errMessage:" + err.message); + expect().assertFail(); + done(); + } + await sleep(1000); + console.info("-----------------SUB_DH_getAvailableDeviceList_0005 end------------------------"); + }); + + /* + * @tc.number SUB_DH_getAvailableDeviceList_0006 + * @tc.name Get a list of available devices. This interface query all authorized and connectable devices. + * @tc.desc Function test + * @tc.level 0 + */ + it("SUB_DH_getAvailableDeviceList_0006", 0, async function (done) { + console.info("-----------------SUB_DH_getAvailableDeviceList_0006 start------------------------"); + dmInstance.getAvailableDeviceList().then((data) => { + console.log('getAvailableDeviceList info: ' + JSON.stringify(data)); + expect(data != nullptr).assertTrue(); + done(); + }).catch((err) => { + console.error("getAvailableDeviceList errCode:" + err.code + ",errMessage:" + err.message); + expect().assertFail(); + done(); + }) + await sleep(1000); + console.info("-----------------SUB_DH_getAvailableDeviceList_0006 end------------------------"); + }); + + /* + * @tc.number SUB_DH_bindTarget_0007 + * @tc.name Get the device name of the local device. + * @tc.desc Function test + * @tc.level 0 + */ + it("SUB_DH_bindTarget_0007", 0, async function (done) { + console.info("-----------------SUB_DH_bindTarget_0007 start------------------------"); + let bindParam = { + "bindType" : 1, + "targetPkgName" : "com.ohos.distributedDeviceManager.screen", + "appName" : "SubDctsdisScreenJsTest", + "appOperation": "想要连接本机。", + "customDescription": "device manager device manager device manager device manager device manager device manager device manager device manager" + }; + try { + dmInstance.bindTarget(dmDeviceInfo.deviceId, JSON.stringify(bindParam), (err, data) => { + if (err) { + console.info("bindTarget fail errCode:" + err.code + ",errMessage:" + err.message); + } + console.log("bindTarget:" + JSON.stringify(data)); + expect(data != nullptr).assertTrue(); + done(); + }) + } catch (err) { + console.info("bindTarget errCode:" + err.code + ",errMessage:" + err.message); + expect().assertFail(); + done(); + } + await sleep(1000); + console.info("-----------------SUB_DH_bindTarget_0007 end------------------------"); + }); + + /* + * @tc.number SUB_DH_getLocalDeviceName_0008 + * @tc.name Get the device name of the local device. + * @tc.desc Function test + * @tc.level 0 + */ + it("SUB_DH_getLocalDeviceName_0008", 0, async function (done) { + console.info("-----------------SUB_DH_getLocalDeviceName_0008 start------------------------"); + try { + let lDeviceName = dmInstance.getLocalDeviceName(); + if (lDeviceName === nullptr) { + console.log("getLocalDeviceName fail"); + } + console.log("Get Local Device Name:" + lDeviceName); + expect(lDeviceName != nullptr).assertTrue(); + done(); + } catch (err) { + console.info("getLocalDeviceName errCode:" + err.code + ",errMessage:" + err.message); + expect().assertFail(); + done(); + } + await sleep(1000); + console.info("-----------------SUB_DH_getLocalDeviceName_0008 end------------------------"); + }); + + /* + * @tc.number SUB_DH_getLocalDeviceType_0009 + * @tc.name Get the device type of the local device + * @tc.desc Function test + * @tc.level 0 + */ + it("SUB_DH_getLocalDeviceType_0009", 0, async function (done) { + console.info("-----------------SUB_DH_getLocalDeviceType_0009 start------------------------"); + try { + let lDeviceType = dmInstance.getLocalDeviceType(); + if (lDeviceType === nullptr) { + console.log("getLocalDeviceType fail"); + } + console.log("get Local Device Type:" + lDeviceType); + expect(lDeviceType != nullptr).assertTrue(); + done(); + } catch (err) { + console.info("getLocalDeviceType errCode:" + err.code + ",errMessage:" + err.message); + expect().assertFail(); + done(); + } + await sleep(1000); + console.info("-----------------SUB_DH_getLocalDeviceType_0009 end------------------------"); + }); + + /* + * @tc.number SUB_DH_getLocalDeviceId_0010 + * @tc.name Get the device id of the local device + * @tc.desc Function test + * @tc.level 0 + */ + it("SUB_DH_getLocalDeviceId_0010", 0, async function (done) { + console.info("-----------------SUB_DH_getLocalDeviceId_0010 start------------------------"); + try { + let lDeviceId = dmInstance.getLocalDeviceId(); + if (lDeviceId === nullptr) { + console.log("getLocalDeviceId fail"); + } + console.log("get Local Device Id:" + lDeviceId); + expect(lDeviceId != nullptr).assertTrue(); + done(); + } catch (err) { + console.info("getLocalDeviceId errCode:" + err.code + ",errMessage:" + err.message); + expect().assertFail(); + done(); + } + await sleep(1000); + console.info("-----------------SUB_DH_getLocalDeviceId_0010 end------------------------"); + }); + + /* + * @tc.number SUB_DH_getDeviceName_0011 + * @tc.name Get the device name by network id. + * @tc.desc Function test + * @tc.level 0 + */ + it("SUB_DH_getDeviceName_0011", 0, async function (done) { + console.info("-----------------SUB_DH_getDeviceName_0011 start------------------------"); + try { + let deviceName = dmInstance.getDeviceName(dmNetworkId); + if (deviceName === nullptr) { + console.log("getDeviceName fail"); + } + console.log("get Device Name:" + deviceName); + expect(deviceName != nullptr).assertTrue(); + done(); + } catch (err) { + console.info("getDeviceName errCode:" + err.code + ",errMessage:" + err.message); + expect().assertFail(); + done(); + } + await sleep(1000); + console.info("-----------------SUB_DH_getDeviceName_0011 end------------------------"); + }); + + /* + * @tc.number SUB_DH_getDeviceType_0012 + * @tc.name Get the device type by network id. + * @tc.desc Function test + * @tc.level 0 + */ + it("SUB_DH_getDeviceType_0012", 0, async function (done) { + console.info("-----------------SUB_DH_getDeviceType_0012 start------------------------"); + try { + let deviceType = dmInstance.getDeviceType(dmNetworkId); + if (deviceType === nullptr) { + console.log("getDeviceType fail"); + } + console.log("get Device Type:" + deviceType); + expect(deviceType != nullptr).assertTrue(); + done(); + } catch (err) { + console.info("getDeviceType errCode:" + err.code + ",errMessage:" + err.message); + expect().assertFail(); + done(); + } + await sleep(1000); + console.info("-----------------SUB_DH_getDeviceType_0012 end------------------------"); + }); + + /* + * @tc.number SUB_DH_unbindTarget_0013 + * @tc.name Unbind the specified target. + * @tc.desc Function test + * @tc.level 0 + */ + it("SUB_DH_unbindTarget_0013", 0, async function (done) { + console.info("-----------------SUB_DH_unbindTarget_0013 start------------------------"); + try { + dmInstance.unbindTarget(dmDeviceInfo.deviceId); + console.log("unbindTarget success"); + expect().assertTrue(); + done(); + } catch (err) { + console.info("unbindTarget errCode:" + err.code + ",errMessage:" + err.message); + expect().assertFail(); + done(); + } + await sleep(1000); + console.info("-----------------SUB_DH_unbindTarget_0013 end------------------------"); + }); + + /* + * @tc.number SUB_DH_stopDiscovering_0014 + * @tc.name Stop discovering nearby devices. + * @tc.desc Function test + * @tc.level 0 + */ + it("SUB_DH_stopDiscovering_0014", 0, async function (done) { + console.info("-----------------SUB_DH_stopDiscovering_0014 start------------------------"); + try { + dmInstance.stopDiscovering(); + console.log("stopDiscovering success"); + expect().assertTrue(); + done(); + } catch (err) { + console.info("stopDiscovering errCode:" + err.code + ",errMessage:" + err.message); + expect().assertFail(); + done(); + } + await sleep(1000); + console.info("-----------------SUB_DH_stopDiscovering_0014 end------------------------"); + }); + + /* + * @tc.number SUB_DH_releaseDeviceManager_0015 + * @tc.name Releases the {@code DeviceManager} instance that is no longer used. + * @tc.desc Function test + * @tc.level 0 + */ + it("SUB_DH_releaseDeviceManager_0015", 0, async function (done) { + console.info("-----------------SUB_DH_releaseDeviceManager_0015 start------------------------"); + var mFilterOption = { + targetPkgName: "com.ohos.devicemanagerui", + sortType: 0, + filter: JSON.stringify({ + key: 'test', + value: 0 + }) + } + try { + dmInstance.off('dmFaCallback'); + dmInstance.off('discoverSuccess'); + dmInstance.off('discoverFail'); + dmInstance.off('serviceDie'); + dmInstance.off('deviceStateChange', JSON.stringify(mFilterOption), console.log("deviceStatusChange off:" + JSON.stringify(dmDeviceInfo))); + deviceManager.releaseDeviceManager(dmInstance); + console.log("releaseDeviceManager success"); + expect().assertTrue(); + done(); + } catch (err) { + console.info("releaseDeviceManager errCode:" + err.code + ",errMessage:" + err.message); + expect().assertFail(); + done(); + } + await sleep(1000); + console.info("-----------------SUB_DH_releaseDeviceManager_0015 end------------------------"); + }); + }) +} \ No newline at end of file diff --git a/distributedhardware/distributedscreenjstest/src/main/resources/base/element/string.json b/distributedhardware/distributedscreenjstest/src/main/resources/base/element/string.json new file mode 100644 index 0000000..15a20b6 --- /dev/null +++ b/distributedhardware/distributedscreenjstest/src/main/resources/base/element/string.json @@ -0,0 +1,28 @@ +{ + "string": [ + { + "name": "app_name", + "value": "SubDctsdisScreenJsTest" + }, + { + "name": "mainability_description", + "value": "JS_Phone_Empty DH" + }, + { + "name": "MainAbility_desc", + "value": "description" + }, + { + "name": "MainAbility_label", + "value": "label" + }, + { + "name": "TestAbility_desc", + "value": "description" + }, + { + "name": "TestAbility_label", + "value": "label" + } + ] +} \ No newline at end of file diff --git a/distributedhardware/distributedscreenjstest/src/main/resources/base/media/icon.png b/distributedhardware/distributedscreenjstest/src/main/resources/base/media/icon.png new file mode 100644 index 0000000..ce307a8 Binary files /dev/null and b/distributedhardware/distributedscreenjstest/src/main/resources/base/media/icon.png differ