diff --git a/usb/BUILD.gn b/usb/BUILD.gn old mode 100755 new mode 100644 diff --git a/usb/usb_standard/BUILD.gn b/usb/usb_standard/BUILD.gn old mode 100755 new mode 100644 index ed66ed5e7fbb3b33e9ef074b552fa8eb063e6786..94a648949c4a191e320848b10bd04af5fe4ca637 --- a/usb/usb_standard/BUILD.gn +++ b/usb/usb_standard/BUILD.gn @@ -9,7 +9,7 @@ # 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") @@ -23,7 +23,9 @@ ohos_js_hap_suite("usb_js_test") { hap_name = "ActsUsbJSApiTest" } ohos_js_assets("usb_js_assets") { - source_dir = "./src/main/js/default" + js2abc = true + hap_profile = "./src/main/config.json" + source_dir = "./src/main/js" } ohos_resources("usb_js_resources") { sources = [ "./src/main/resources" ] diff --git a/usb/usb_standard/Test.json b/usb/usb_standard/Test.json old mode 100755 new mode 100644 index cd7ef814da181eed0960f3513e55467031ee16b2..1e7498444500c909b24c103f99a06c9dc90bac7d --- a/usb/usb_standard/Test.json +++ b/usb/usb_standard/Test.json @@ -1,18 +1,19 @@ -{ - "description": "Configuration for usb js api Tests", - "driver": { - "type": "JSUnitTest", - "test-timeout": "160000", - "package": "ohos.acts.usb.usb.function", - "shell-timeout": "60000" - }, - "kits": [ - { - "test-file-name": [ - "ActsUsbJSApiTest.hap" - ], - "type": "AppInstallKit", - "cleanup-apps": true - } - ] -} +{ + "description": "Configuration for usb js api Tests", + "driver": { + "type": "OHJSUnitTest", + "test-timeout": "160000", + "shell-timeout": "160000", + "bundle-name": "ohos.acts.usb.usb.function", + "package-name": "ohos.acts.usb.usb.function" + }, + "kits": [ + { + "test-file-name": [ + "ActsUsbJSApiTest.hap" + ], + "type": "AppInstallKit", + "cleanup-apps": true + } + ] +} \ No newline at end of file diff --git a/usb/usb_standard/signature/openharmony_sx.p7b b/usb/usb_standard/signature/openharmony_sx.p7b old mode 100755 new mode 100644 diff --git a/usb/usb_standard/src/main/config.json b/usb/usb_standard/src/main/config.json old mode 100755 new mode 100644 index 4a05ad4d02dabfd0b326c8c4c82faf7443a03bf1..ff11f31f9f24f42a924472800ea1b9412171f2d3 --- a/usb/usb_standard/src/main/config.json +++ b/usb/usb_standard/src/main/config.json @@ -1,60 +1,93 @@ -{ - "app": { - "bundleName": "ohos.acts.usb.usb.function", - "vendor": "example", - "version": { - "code": 1, - "name": "1.0" - }, - "apiVersion": { - "compatible": 4, - "target": 5 - } - }, - "deviceConfig": {}, - "module": { - "package": "ohos.acts.usb.usb.function", - "name": ".MyApplication", - "deviceType": [ - "phone" - ], - "distro": { - "deliveryWithInstall": true, - "moduleName": "entry", - "moduleType": "entry" - }, - "abilities": [ - { - "visible": true, - "skills": [ - { - "entities": [ - "entity.system.home" - ], - "actions": [ - "action.system.home" - ] - } - ], - "name": "ohos.acts.usb.usb.function.MainAbility", - "icon": "$media:icon", - "description": "$string:mainability_description", - "label": "$string:app_name", - "type": "page", - "launchType": "standard" - } - ], - "js": [ - { - "pages": [ - "pages/index/index" - ], - "name": "default", - "window": { - "designWidth": 720, - "autoDesignWidth": false - } - } - ] - } -} +{ + "app": { + "bundleName": "ohos.acts.usb.usb.function", + "vendor": "example", + "version": { + "code": 1, + "name": "1.0" + }, + "apiVersion": { + "compatible": 4, + "target": 5 + } + }, + "deviceConfig": {}, + "module": { + "package": "ohos.acts.usb.usb.function", + "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/usb/usb_standard/src/main/js/default/app.js b/usb/usb_standard/src/main/js/MainAbility/app.js old mode 100755 new mode 100644 similarity index 100% rename from usb/usb_standard/src/main/js/default/app.js rename to usb/usb_standard/src/main/js/MainAbility/app.js diff --git a/usb/usb_standard/src/main/js/default/i18n/en-US.json b/usb/usb_standard/src/main/js/MainAbility/i18n/en-US.json old mode 100755 new mode 100644 similarity index 100% rename from usb/usb_standard/src/main/js/default/i18n/en-US.json rename to usb/usb_standard/src/main/js/MainAbility/i18n/en-US.json diff --git a/usb/usb_standard/src/main/js/default/i18n/zh-CN.json b/usb/usb_standard/src/main/js/MainAbility/i18n/zh-CN.json old mode 100755 new mode 100644 similarity index 100% rename from usb/usb_standard/src/main/js/default/i18n/zh-CN.json rename to usb/usb_standard/src/main/js/MainAbility/i18n/zh-CN.json diff --git a/usb/usb_standard/src/main/js/default/pages/index/index.css b/usb/usb_standard/src/main/js/MainAbility/pages/index/index.css old mode 100755 new mode 100644 similarity index 100% rename from usb/usb_standard/src/main/js/default/pages/index/index.css rename to usb/usb_standard/src/main/js/MainAbility/pages/index/index.css diff --git a/usb/usb_standard/src/main/js/default/pages/index/index.hml b/usb/usb_standard/src/main/js/MainAbility/pages/index/index.hml old mode 100755 new mode 100644 similarity index 100% rename from usb/usb_standard/src/main/js/default/pages/index/index.hml rename to usb/usb_standard/src/main/js/MainAbility/pages/index/index.hml diff --git a/usb/usb_standard/src/main/js/default/pages/index/index.js b/usb/usb_standard/src/main/js/MainAbility/pages/index/index.js old mode 100755 new mode 100644 similarity index 67% rename from usb/usb_standard/src/main/js/default/pages/index/index.js rename to usb/usb_standard/src/main/js/MainAbility/pages/index/index.js index 3cdd779e2442eb4d78feec5f58ce90bc1f61074d..644429709f93ac436e4ef6f932a610da7a6aa197 --- a/usb/usb_standard/src/main/js/default/pages/index/index.js +++ b/usb/usb_standard/src/main/js/MainAbility/pages/index/index.js @@ -1,46 +1,30 @@ -/* - * 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 {Core, ExpectExtend} from 'deccjsunit/index' - -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') - const core = Core.getInstance() - const expectExtend = new ExpectExtend({ - 'id': 'extend' - }) - core.addService('expect', expectExtend) - core.init() - - const configService = core.getDefaultService('config') - this.timeout = 5000 - configService.setConfig(this) - - require('../../test/ListUsb.test') - core.execute() - }, - onReady() { - }, -} +/* + * 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() { + }, +} diff --git a/usb/usb_standard/src/main/js/TestAbility/app.js b/usb/usb_standard/src/main/js/TestAbility/app.js new file mode 100644 index 0000000000000000000000000000000000000000..cdc31f3dcf031e2f6a7665d9653e53bb649e21c5 --- /dev/null +++ b/usb/usb_standard/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/usb/usb_standard/src/main/js/TestAbility/i18n/en-US.json b/usb/usb_standard/src/main/js/TestAbility/i18n/en-US.json new file mode 100644 index 0000000000000000000000000000000000000000..3cb24b374b1d919ca8eac0638f361692b603a900 --- /dev/null +++ b/usb/usb_standard/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/usb/usb_standard/src/main/js/TestAbility/i18n/zh-CN.json b/usb/usb_standard/src/main/js/TestAbility/i18n/zh-CN.json new file mode 100644 index 0000000000000000000000000000000000000000..c804e32c0c3103929baca5617cdac70be11fdba1 --- /dev/null +++ b/usb/usb_standard/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/usb/usb_standard/src/main/js/TestAbility/pages/index/index.css b/usb/usb_standard/src/main/js/TestAbility/pages/index/index.css new file mode 100644 index 0000000000000000000000000000000000000000..b1bcd43387ba131cc1d30975ff7508a6f8084a4b --- /dev/null +++ b/usb/usb_standard/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/usb/usb_standard/src/main/js/TestAbility/pages/index/index.hml b/usb/usb_standard/src/main/js/TestAbility/pages/index/index.hml new file mode 100644 index 0000000000000000000000000000000000000000..f629c71a9be857db6cdf94149652a191b9b272ea --- /dev/null +++ b/usb/usb_standard/src/main/js/TestAbility/pages/index/index.hml @@ -0,0 +1,5 @@ +
+ + {{ $t('strings.hello') }} {{ title }} + +
diff --git a/usb/usb_standard/src/main/js/default/test/ListUsb.test.js b/usb/usb_standard/src/main/js/TestAbility/pages/index/index.js old mode 100755 new mode 100644 similarity index 52% rename from usb/usb_standard/src/main/js/default/test/ListUsb.test.js rename to usb/usb_standard/src/main/js/TestAbility/pages/index/index.js index e565d2f4679d5aa207b070525cfe62c3c4db82c2..88b083a7f6b979019d6a2c5ad20b19c5fd43286b --- a/usb/usb_standard/src/main/js/default/test/ListUsb.test.js +++ b/usb/usb_standard/src/main/js/TestAbility/pages/index/index.js @@ -1,32 +1,26 @@ -/* - * Copyright (c) 2021-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. - */ - - -/* host test case */ -require('./UsbCoreJsunit.test.js') -require('./UsbCoreJsunitEx.test.js') -require('./UsbDevicePipeJsunit.test.js') -require('./UsbDevicePipeJsunitEx.test.js') - -/* device test case */ -require('./UsbFunctionsJsunit.test.js') -require('./UsbFunctionsJsunitEx.test.js') - -/* device and host test case */ -require('./UsbPortJsunit.test.js') -require('./UsbPortJsunitEx.test.js') -// require('./UsbPortAndFunctionJsunit.test.js') - -require('./UsbAutoJsunit.test.js') +/* + * 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/usb/usb_standard/src/main/js/TestRunner/OpenHarmonyTestRunner.js b/usb/usb_standard/src/main/js/TestRunner/OpenHarmonyTestRunner.js new file mode 100644 index 0000000000000000000000000000000000000000..c5fa8620ca77d381f20b65a903b833e6e3378c97 --- /dev/null +++ b/usb/usb_standard/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/usb/usb_standard/src/main/js/default/test/CheckEmptyUtils.js b/usb/usb_standard/src/main/js/test/CheckEmptyUtils.js old mode 100755 new mode 100644 similarity index 96% rename from usb/usb_standard/src/main/js/default/test/CheckEmptyUtils.js rename to usb/usb_standard/src/main/js/test/CheckEmptyUtils.js index 7fc5780d5dfb7160cd9245702eed76a56a7ee51c..2c2a43ddfeef65726497dd58d7dcf8f6868ee10d --- a/usb/usb_standard/src/main/js/default/test/CheckEmptyUtils.js +++ b/usb/usb_standard/src/main/js/test/CheckEmptyUtils.js @@ -1,68 +1,68 @@ -/* - * Copyright (c) 2021-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 { - - /** - * Check obj is empty. - * - * @param {object} obj - * @return {boolean} true(empty) - */ - isEmpty(obj) { - return (typeof obj == 'undefined' || obj == null || - JSON.stringify(obj) == '{}' || JSON.stringify(obj) == 'undefined'); - }, - - /** - * Check str is empty. - * - * @param {string} str - * @return {boolean} true(empty) - */ - checkStrIsEmpty(str) { - return str.trim().length == 0; - }, - - /** - * Check array is empty. - * - * @param {Array}arr - * @return {boolean} true(empty) - */ - isEmptyArr(arr) { - return arr.length == 0; - }, - - // ArrayBuffer转为字符串,参数为ArrayBuffer对象 - ab2str(buf) { - return String.fromCharCode.apply(null, new Uint8Array(buf)); - }, - - // 字符串转为ArrayBuffer对象,参数为字符串 - str2ab(str) { - var arr = []; - for (var i = 0, j = str.length; i < j; ++i) { - arr.push(str.charCodeAt(i)); - } - var tmpUint8Array = new Uint8Array(arr); - return tmpUint8Array; - }, - - // 简单阻塞的粗暴实现 - sleep(delay) { - for (var t = Date.now(); Date.now() - t <= delay;); - } -} +/* + * Copyright (c) 2021-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 { + + /** + * Check obj is empty. + * + * @param {object} obj + * @return {boolean} true(empty) + */ + isEmpty(obj) { + return (typeof obj == 'undefined' || obj == null || + JSON.stringify(obj) == '{}' || JSON.stringify(obj) == 'undefined'); + }, + + /** + * Check str is empty. + * + * @param {string} str + * @return {boolean} true(empty) + */ + checkStrIsEmpty(str) { + return str.trim().length == 0; + }, + + /** + * Check array is empty. + * + * @param {Array}arr + * @return {boolean} true(empty) + */ + isEmptyArr(arr) { + return arr.length == 0; + }, + + // ArrayBuffer转为字符串,参数为ArrayBuffer对象 + ab2str(buf) { + return String.fromCharCode.apply(null, new Uint8Array(buf)); + }, + + // 字符串转为ArrayBuffer对象,参数为字符串 + str2ab(str) { + var arr = []; + for (var i = 0, j = str.length; i < j; ++i) { + arr.push(str.charCodeAt(i)); + } + var tmpUint8Array = new Uint8Array(arr); + return tmpUint8Array; + }, + + // 简单阻塞的粗暴实现 + sleep(delay) { + for (var t = Date.now(); Date.now() - t <= delay;); + } +} diff --git a/usb/usb_standard/src/main/js/default/test/DateAndTimeUtil.js b/usb/usb_standard/src/main/js/test/DateAndTimeUtil.js old mode 100755 new mode 100644 similarity index 96% rename from usb/usb_standard/src/main/js/default/test/DateAndTimeUtil.js rename to usb/usb_standard/src/main/js/test/DateAndTimeUtil.js index 1247ad0d4d95c2a17b97b3e07f70260d09b82c52..8ebd008cc499ad38782a81f0309191b82a315344 --- a/usb/usb_standard/src/main/js/default/test/DateAndTimeUtil.js +++ b/usb/usb_standard/src/main/js/test/DateAndTimeUtil.js @@ -1,120 +1,120 @@ -/* - * Copyright (c) 2021-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. - */ - -const twelve = 12; - -/* - * date package tool class - */ -export default class DateAndTimeUtil { - constructor() { - } - - /** - * - * Get the current time - */ - now() { - const datetime = new Date(); - const hours = datetime.getHours(); - const minutes = datetime.getMinutes(); - return this.concatTime(hours, minutes); - } - - /** - * - * Get the current time - */ - nowWithSeconds() { - const datetime = new Date(); - const hours = datetime.getHours(); - const minutes = datetime.getMinutes(); - const seconds = datetime.getMilliseconds() - console.info('now: ' + hours + ':' + minutes + ':' + seconds) - var now = this.concatTimeWithSeconds(hours, minutes, seconds); - console.info('now concat: ' + now); - return now; - } - - /** - * format - * @param value - * @return - */ - fill(value) { - return (value > 9 ? '' : '0') + value; - } - - /** - * concat date - * @param year m d - * @return - */ - concatDate(year, month, date) { - return year + this.year + month + this.month + date + this.day; - } - - concatTime(hours, minutes) { - return `${this.fill(hours)}:${this.fill(minutes)}`; - } - - concatTimeWithSeconds(hours, minutes, milliseconds) { - return `${this.fill(hours)}:${this.fill(minutes)}:${this.fill(milliseconds)}`; - } - - /** - * Turn to 24-hour clock - * @param str - * @return - */ - transform24(str) { - const timeFlag = str.substr(0, 2); - if (timeFlag == this.morning) { - const h = str.substr(2).split(':')[0]; - if (h == twelve) { - const time = '0' + ':' + str.substr(2).split(':')[1]; - return time; - } else { - return h + ':' + str.substr(2).split(':')[1]; - } - } else { - const h = str.substr(2).split(':')[0]; - const h1 = parseInt(h) + twelve; - if (h != twelve) { - const time = h1 + ':' + str.substr(2).split(':')[1]; - return time; - } - } - } - - /** - * Turn to 12-hour clock - * @param str - * @return - */ - transform12(str) { - const hours = str.substring(0, str.indexOf(':')); - const minutes = str.split(':')[1]; - if (hours < twelve) { - return this.morning.concat(`${hours}:${minutes}`); - } - if (hours == twelve) { - return this.afternoon.concat(`${hours}:${minutes}`); - } else { - const reduceHours = parseInt(hours) - twelve; - return this.afternoon.concat(`${reduceHours}:${minutes}`); - } - } -} +/* + * Copyright (c) 2021-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. + */ + +const twelve = 12; + +/* + * date package tool class + */ +export default class DateAndTimeUtil { + constructor() { + } + + /** + * + * Get the current time + */ + now() { + const datetime = new Date(); + const hours = datetime.getHours(); + const minutes = datetime.getMinutes(); + return this.concatTime(hours, minutes); + } + + /** + * + * Get the current time + */ + nowWithSeconds() { + const datetime = new Date(); + const hours = datetime.getHours(); + const minutes = datetime.getMinutes(); + const seconds = datetime.getMilliseconds() + console.info('now: ' + hours + ':' + minutes + ':' + seconds) + var now = this.concatTimeWithSeconds(hours, minutes, seconds); + console.info('now concat: ' + now); + return now; + } + + /** + * format + * @param value + * @return + */ + fill(value) { + return (value > 9 ? '' : '0') + value; + } + + /** + * concat date + * @param year m d + * @return + */ + concatDate(year, month, date) { + return year + this.year + month + this.month + date + this.day; + } + + concatTime(hours, minutes) { + return `${this.fill(hours)}:${this.fill(minutes)}`; + } + + concatTimeWithSeconds(hours, minutes, milliseconds) { + return `${this.fill(hours)}:${this.fill(minutes)}:${this.fill(milliseconds)}`; + } + + /** + * Turn to 24-hour clock + * @param str + * @return + */ + transform24(str) { + const timeFlag = str.substr(0, 2); + if (timeFlag == this.morning) { + const h = str.substr(2).split(':')[0]; + if (h == twelve) { + const time = '0' + ':' + str.substr(2).split(':')[1]; + return time; + } else { + return h + ':' + str.substr(2).split(':')[1]; + } + } else { + const h = str.substr(2).split(':')[0]; + const h1 = parseInt(h) + twelve; + if (h != twelve) { + const time = h1 + ':' + str.substr(2).split(':')[1]; + return time; + } + } + } + + /** + * Turn to 12-hour clock + * @param str + * @return + */ + transform12(str) { + const hours = str.substring(0, str.indexOf(':')); + const minutes = str.split(':')[1]; + if (hours < twelve) { + return this.morning.concat(`${hours}:${minutes}`); + } + if (hours == twelve) { + return this.afternoon.concat(`${hours}:${minutes}`); + } else { + const reduceHours = parseInt(hours) - twelve; + return this.afternoon.concat(`${reduceHours}:${minutes}`); + } + } +} diff --git a/usb/usb_standard/src/main/js/default/test/EventConstants.js b/usb/usb_standard/src/main/js/test/EventConstants.js old mode 100755 new mode 100644 similarity index 94% rename from usb/usb_standard/src/main/js/default/test/EventConstants.js rename to usb/usb_standard/src/main/js/test/EventConstants.js index 2b51b538f950634abf602e132e5a849bcdd81b8f..f917b6ee93246fc2047c6fed4453a92df6ae664f --- a/usb/usb_standard/src/main/js/default/test/EventConstants.js +++ b/usb/usb_standard/src/main/js/test/EventConstants.js @@ -1,67 +1,67 @@ -/* - * Copyright (c) 2021-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. - */ - -/* - * Constants of events that will be registered to system. - */ -const EventConstants = { - - /** - * Bitmask used for extracting the USBEndpoint type from it's address - */ - USB_ENDPOINT_XFERTYPE_MASK: 0x03, - - /** - * Control USBEndpoint type - */ - USB_ENDPOINT_XFER_CONTROL: 0, - - /** - * Isochronous USBEndpoint type - */ - USB_ENDPOINT_XFER_ISOC: 1, - - /** - * Bulk USBEndpoint type - */ - USB_ENDPOINT_XFER_BULK: 2, - - /** - * Interrupt USBEndpoint type - */ - USB_ENDPOINT_XFER_INT: 3, - - /** - * Bitmask used for extracting the USBEndpoint number from it's address - */ - USB_ENDPOINT_NUMBER_MASK: 0x0f, - - /** - * Bitmask used for extracting the USBEndpoint direction from it's address - */ - USB_ENDPOINT_DIR_MASK: 0x80, - - /** - * Used to signify direction of data for USBEndpoint is OUT, host to device - */ - USB_ENDPOINT_DIR_OUT: 0, - - /** - * Used to signify direction of data for USBEndpoint is IN, device to host - */ - USB_ENDPOINT_DIR_IN: 0x80 -} - +/* + * Copyright (c) 2021-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. + */ + +/* + * Constants of events that will be registered to system. + */ +const EventConstants = { + + /** + * Bitmask used for extracting the USBEndpoint type from it's address + */ + USB_ENDPOINT_XFERTYPE_MASK: 0x03, + + /** + * Control USBEndpoint type + */ + USB_ENDPOINT_XFER_CONTROL: 0, + + /** + * Isochronous USBEndpoint type + */ + USB_ENDPOINT_XFER_ISOC: 1, + + /** + * Bulk USBEndpoint type + */ + USB_ENDPOINT_XFER_BULK: 2, + + /** + * Interrupt USBEndpoint type + */ + USB_ENDPOINT_XFER_INT: 3, + + /** + * Bitmask used for extracting the USBEndpoint number from it's address + */ + USB_ENDPOINT_NUMBER_MASK: 0x0f, + + /** + * Bitmask used for extracting the USBEndpoint direction from it's address + */ + USB_ENDPOINT_DIR_MASK: 0x80, + + /** + * Used to signify direction of data for USBEndpoint is OUT, host to device + */ + USB_ENDPOINT_DIR_OUT: 0, + + /** + * Used to signify direction of data for USBEndpoint is IN, device to host + */ + USB_ENDPOINT_DIR_IN: 0x80 +} + export default EventConstants; \ No newline at end of file diff --git a/usb/usb_standard/src/main/js/test/List.test.js b/usb/usb_standard/src/main/js/test/List.test.js new file mode 100644 index 0000000000000000000000000000000000000000..06e5026b78304558e84f05d928ce7a89ae37487e --- /dev/null +++ b/usb/usb_standard/src/main/js/test/List.test.js @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2021-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 UsbAutoJsunit from './UsbAutoJsunit.test.js' +import UsbPortAndFunctionsJsFunctionsTest from './UsbPortAndFunctionJsunit.test.js' +import UsbPortJsFunctionsTest from './UsbPortJsunit.test.js' +import UsbPortJsFunctionsTestEx from './UsbPortJsunitEx.test.js' +import UsbFunctionsJsFunctionsTestEx from './UsbFunctionsJsunitEx.test.js' +import UsbFunctionsJsFunctionsTest from './UsbFunctionsJsunit.test.js' +import UsbDevicePipeJsFunctionsTest from './UsbDevicePipeJsunit.test.js' +import UsbDevicePipeJsFunctionsTestEx from './UsbDevicePipeJsunitEx.test.js' +import UsbCoreJsFunctionsTest from './UsbCoreJsunit.test.js' +import UsbCoreJsFunctionsTestEx from './UsbCoreJsunitEx.test.js' +/* host test case */ +export default function testsuite() { +UsbAutoJsunit() +UsbCoreJsFunctionsTest() +UsbCoreJsFunctionsTestEx() +UsbDevicePipeJsFunctionsTest() +UsbDevicePipeJsFunctionsTestEx() +UsbFunctionsJsFunctionsTest() +UsbFunctionsJsFunctionsTestEx() +//UsbPortAndFunctionsJsFunctionsTest() +UsbPortJsFunctionsTest() +UsbPortJsFunctionsTestEx() +} diff --git a/usb/usb_standard/src/main/js/default/test/UsbAutoJsunit.test.js b/usb/usb_standard/src/main/js/test/UsbAutoJsunit.test.js old mode 100755 new mode 100644 similarity index 96% rename from usb/usb_standard/src/main/js/default/test/UsbAutoJsunit.test.js rename to usb/usb_standard/src/main/js/test/UsbAutoJsunit.test.js index a1cd7d3338e8578944c2e520d6faf33df5cd3256..0543745ef38cea295ef5f9a98bc43646166f816f --- a/usb/usb_standard/src/main/js/default/test/UsbAutoJsunit.test.js +++ b/usb/usb_standard/src/main/js/test/UsbAutoJsunit.test.js @@ -1,365 +1,367 @@ -/* - * Copyright (C) 2021-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 usb from '@ohos.usb'; -import CheckEmptyUtils from './CheckEmptyUtils.js'; -import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from 'deccjsunit/index' - -/* usb core functions test */ -describe('UsbAutoJsunit', function () { - - beforeAll(function () { - console.log('*************Usb Unit UsbAutoJsunit Begin*************'); - var Version = usb.getVersion() - console.info('begin test getversion :' + Version) - - // 切换到 device - var usbPortList = usb.getPorts() - if (usbPortList.length > 0) { - if (usbPortList[0].status.currentMode == 2) { - console.info('usb case set data role 1, data role 1'); - usb.setPortRoles(usbPortList[0].id, 2, 2).then(data => { - console.info('usb case setPortRoles return: ' + data); - }).catch(error => { - console.info('usb case setPortRoles error : ' + error); - }); - CheckEmptyUtils.sleep(8000) - console.log('*************Usb Unit switch to device Begin*************'); - } - } - }) - beforeEach(function () { - console.info('beforeEach: *************Usb Unit Test Case*************'); - }) - - afterEach(function () { - console.info('afterEach: *************Usb Unit Test Case*************'); - }) - - afterAll(function () { - console.log('*************Usb Unit UsbAutoJsunit End*************'); - }) - - /** - * @tc.number : SUB_USB_JS_0930 - * @tc.name : usbFunctionsToString - * @tc.desc : 正向测试 0 返回 'none' - */ - it('SUB_USB_JS_0930', 0, function () { - console.info('usb SUB_USB_JS_0930 begin'); - var maskCode = 0 - var strMaskCode = usb.usbFunctionsToString(maskCode) - expect(strMaskCode).assertEqual('none'); - console.info('usb case maskCode ' + maskCode + ' usbFunctionsToString return int: ' + strMaskCode); - console.info('usb SUB_USB_JS_0930 : PASS'); - }) - - /** - * @tc.number : SUB_USB_JS_0940 - * @tc.name : usbFunctionsToString - * @tc.desc : 正向测试 1 返回 'acm' - */ - it('SUB_USB_JS_0940', 0, function () { - console.info('usb SUB_USB_JS_0940 begin'); - var maskCode = 1 - var strMaskCode = usb.usbFunctionsToString(maskCode) - expect(strMaskCode).assertEqual('acm'); - console.info('usb case maskCode ' + maskCode + ' usbFunctionsToString return int: ' + strMaskCode); - console.info('usb SUB_USB_JS_0940 : PASS'); - }) - - /** - * @tc.number : SUB_USB_JS_0950 - * @tc.name : usbFunctionsToString - * @tc.desc : 正向测试 2 返回 'ecm' - */ - it('SUB_USB_JS_0950', 0, function () { - console.info('usb SUB_USB_JS_0950 begin'); - var maskCode = 2 - var strMaskCode = usb.usbFunctionsToString(maskCode) - expect(strMaskCode).assertEqual('ecm'); - console.info('usb case maskCode ' + maskCode + ' usbFunctionsToString return int: ' + strMaskCode); - console.info('usb SUB_USB_JS_0950 : PASS'); - }) - - /** - * @tc.number : SUB_USB_JS_0960 - * @tc.name : usbFunctionsToString - * @tc.desc : 正向测试 3 返回 'acm,ecm' - */ - it('SUB_USB_JS_0960', 0, function () { - console.info('usb SUB_USB_JS_0960 begin'); - var maskCode = 3 - var strMaskCode = usb.usbFunctionsToString(maskCode) - expect(strMaskCode).assertEqual('acm,ecm'); - console.info('usb case maskCode ' + maskCode + ' usbFunctionsToString return int: ' + strMaskCode); - console.info('usb SUB_USB_JS_0960 : PASS'); - }) - - /** - * @tc.number : SUB_USB_JS_0970 - * @tc.name : usbFunctionsToString - * @tc.desc : 正向测试 4 返回 'hdc' - */ - it('SUB_USB_JS_0970', 0, function () { - console.info('usb SUB_USB_JS_0970 begin'); - var maskCode = 4 - var strMaskCode = usb.usbFunctionsToString(maskCode) - expect(strMaskCode).assertEqual('hdc'); - console.info('usb case maskCode ' + maskCode + ' usbFunctionsToString return int: ' + strMaskCode); - console.info('usb SUB_USB_JS_0970 : PASS'); - }) - - /** - * @tc.number : SUB_USB_JS_0980 - * @tc.name : usbFunctionsToString - * @tc.desc : 正向测试 5 返回 'acm,hdc' - */ - it('SUB_USB_JS_0980', 0, function () { - console.info('usb SUB_USB_JS_0980 begin'); - var maskCode = 5 - var strMaskCode = usb.usbFunctionsToString(maskCode) - expect(strMaskCode).assertEqual('hdc,acm'); - console.info('usb case maskCode ' + maskCode + ' usbFunctionsToString return int: ' + strMaskCode); - console.info('usb SUB_USB_JS_0980 : PASS'); - }) - - /** - * @tc.number : SUB_USB_JS_0990 - * @tc.name : usbFunctionsToString - * @tc.desc : 正向测试 6 返回 'ecm,hdc' - */ - it('SUB_USB_JS_0990', 0, function () { - console.info('usb SUB_USB_JS_0990 begin'); - var maskCode = 6 - var strMaskCode = usb.usbFunctionsToString(maskCode) - expect(strMaskCode).assertEqual('hdc,ecm'); - console.info('usb case maskCode ' + maskCode + ' usbFunctionsToString return int: ' + strMaskCode); - console.info('usb SUB_USB_JS_0990 : PASS'); - }) - - /** - * @tc.number : SUB_USB_JS_0860 - * @tc.name : usbFunctionsFromString - * @tc.desc : 正向测试 'none' 返回 0 - */ - it('SUB_USB_JS_0860', 0, function () { - console.info('usb SUB_USB_JS_0860 begin'); - var strMaskCode = 'none' - var nMaskCode = usb.usbFunctionsFromString(strMaskCode) - expect(nMaskCode).assertEqual(0); - console.info('usb case strMaskCode ' + strMaskCode + ' usbFunctionsFromString return int: ' + nMaskCode); - console.info('usb SUB_USB_JS_0860 : PASS'); - }) - - /** - * @tc.number : SUB_USB_JS_0870 - * @tc.name : usbFunctionsFromString - * @tc.desc : 正向测试 'acm' 返回 1 - */ - it('SUB_USB_JS_0870', 0, function () { - console.info('usb SUB_USB_JS_0870 begin'); - var strMaskCode = 'acm' - var nMaskCode = usb.usbFunctionsFromString(strMaskCode) - expect(nMaskCode).assertEqual(1); - console.info('usb case strMaskCode ' + strMaskCode + ' usbFunctionsFromString return int: ' + nMaskCode); - console.info('usb SUB_USB_JS_0870 : PASS'); - }) - - /** - * @tc.number : SUB_USB_JS_0880 - * @tc.name : usbFunctionsFromString - * @tc.desc : 正向测试 'ecm' 返回 2 - */ - it('SUB_USB_JS_0880', 0, function () { - console.info('usb SUB_USB_JS_0880 begin'); - var strMaskCode = 'ecm' - var nMaskCode = usb.usbFunctionsFromString(strMaskCode) - expect(nMaskCode).assertEqual(2); - console.info('usb case strMaskCode ' + strMaskCode + ' usbFunctionsFromString return int: ' + nMaskCode); - console.info('usb SUB_USB_JS_0880 : PASS'); - }) - - /** - * @tc.number : SUB_USB_JS_0890 - * @tc.name : usbFunctionsFromString - * @tc.desc : 正向测试 'acm,ecm' 返回 3 - */ - it('SUB_USB_JS_0890', 0, function () { - console.info('usb SUB_USB_JS_0890 begin'); - var strMaskCode = 'acm,ecm' - var nMaskCode = usb.usbFunctionsFromString(strMaskCode) - expect(nMaskCode).assertEqual(3); - console.info('usb case strMaskCode ' + strMaskCode + ' usbFunctionsFromString return int: ' + nMaskCode); - console.info('usb SUB_USB_JS_0890 : PASS'); - }) - - /** - * @tc.number : SUB_USB_JS_0900 - * @tc.name : usbFunctionsFromString - * @tc.desc : 正向测试 'hdc' 返回 4 - */ - it('SUB_USB_JS_0900', 0, function () { - console.info('usb SUB_USB_JS_0900 begin'); - var strMaskCode = 'hdc' - var nMaskCode = usb.usbFunctionsFromString(strMaskCode) - expect(nMaskCode).assertEqual(4); - console.info('usb case strMaskCode ' + strMaskCode + ' usbFunctionsFromString return int: ' + nMaskCode); - console.info('usb SUB_USB_JS_0900 : PASS'); - }) - - /** - * @tc.number : SUB_USB_JS_0910 - * @tc.name : usbFunctionsFromString - * @tc.desc : 正向测试 'acm,hdc' 返回 5 - */ - it('SUB_USB_JS_0910', 0, function () { - console.info('usb SUB_USB_JS_0910 begin'); - var strMaskCode = 'acm,hdc' - var nMaskCode = usb.usbFunctionsFromString(strMaskCode) - expect(nMaskCode).assertEqual(5); - console.info('usb case strMaskCode ' + strMaskCode + ' usbFunctionsFromString return int: ' + nMaskCode); - console.info('usb SUB_USB_JS_0910 : PASS'); - }) - - /** - * @tc.number : SUB_USB_JS_0920 - * @tc.name : usbFunctionsFromString - * @tc.desc : 正向测试 'ecm,hdc' 返回 6 - */ - it('SUB_USB_JS_0920', 0, function () { - console.info('usb SUB_USB_JS_0920 begin'); - var strMaskCode = 'ecm,hdc' - var nMaskCode = usb.usbFunctionsFromString(strMaskCode) - expect(nMaskCode).assertEqual(6); - console.info('usb case strMaskCode ' + strMaskCode + ' usbFunctionsFromString return int: ' + nMaskCode); - console.info('usb SUB_USB_JS_0920 : PASS'); - }) - - /** - * @tc.number : SUB_USB_JS_0330 - * @tc.name : getCurrentFunctions - * @tc.desc : 获取当前设备模式 掩码与描述字符转换 - */ - it('SUB_USB_JS_0330', 0, function () { - console.info('usb SUB_USB_JS_0330 begin'); - var maskCode = usb.getCurrentFunctions(); - console.info('usb case getCurrentFunctions return: ' + maskCode); - - var strMaskCode = usb.usbFunctionsToString(maskCode) - console.info('usb case usbFunctionsToString return str: ' + strMaskCode); - var nMaskCode = usb.usbFunctionsFromString(strMaskCode) - console.info('usb case strMaskCode usbFunctionsFromString return int: ' + nMaskCode); - expect(nMaskCode).assertEqual(maskCode); - console.info('usb SUB_USB_JS_0330 : PASS'); - expect(true).assertTrue(); - }) - - /** - * @tc.number : SUB_USB_JS_0340 - * @tc.name : usbFunctionString - * @tc.desc : 反向测试 获取当前设备模式 掩码与描述字符转换 - */ - it('SUB_USB_JS_0340', 0, function () { - console.info('usb SUB_USB_JS_0340 begin'); - var maskCode = usb.getCurrentFunctions(); - console.info('usb case getCurrentFunctions return: ' + maskCode); - - var strMaskCode = usb.usbFunctionsToString(maskCode) - console.info('usb case usbFunctionsToString return str: ' + strMaskCode); - var nMaskCode = usb.usbFunctionsFromString(strMaskCode) - console.info('usb case strMaskCode usbFunctionsFromString return int: ' + nMaskCode); - - var errmaskCode = 0 - var strMaskCode = usb.usbFunctionsToString(errmaskCode) - - console.info('usb case ' + errmaskCode + ' usbFunctionsToString return str: ' + strMaskCode); - - var errStrMaskCode = 'none' - var nMaskCode = usb.usbFunctionsFromString(errStrMaskCode) - expect(nMaskCode).assertEqual(0); - console.info('usb case errStrMaskCode ' + errStrMaskCode + - ' usbFunctionsFromString return int: ' + nMaskCode); - - console.info('usb SUB_USB_JS_0340 : PASS'); - }) - - /** - * @tc.number : SUB_USB_JS_0410 - * @tc.name : getPorts - * @tc.desc : 获取USB端口描述信息列表 - */ - it('SUB_USB_JS_0410', 0, function () { - console.info('usb SUB_USB_JS_0410 begin'); - var usbPortList = usb.getPorts() - if (usbPortList.length == 0) { - console.info('usb SUB_USB_JS_0410 usbPortList is null'); - expect(false).assertTrue(); - return - } - expect(usbPortList.length > 0).assertTrue(); - console.info('usb SUB_USB_JS_0410 : PASS'); - expect(true).assertTrue(); - }) - - /** - * @tc.number : SUB_USB_JS_0220 - * @tc.name : getSupportedModes - * @tc.desc : 获取指定的端口支持的模式列表的组合掩码 - */ - it('SUB_USB_JS_0220', 0, function () { - console.info('usb SUB_USB_JS_0220 begin'); - var usbPortList = usb.getPorts() - if (usbPortList.length == 0) { - console.info('usb SUB_USB_JS_0220 usbPortList is null'); - expect(false).assertTrue(); - return - } - - expect(usbPortList.length > 0).assertTrue(); - for (var i = 0; i < usbPortList.length; i++) { - var maskCode = usb.getSupportedModes(usbPortList[i].id) - expect(maskCode).assertEqual(usbPortList[i].supportedModes); - } - - console.info('usb SUB_USB_JS_0220 : PASS'); - expect(true).assertTrue(); - }) - - /** - * @tc.number : SUB_USB_JS_0230 - * @tc.name : getSupportedModes - * @tc.desc : 反向测试 改变id 获取指定的端口支持的模式列表的组合掩码 - */ - it('SUB_USB_JS_0230', 0, function () { - console.info('usb SUB_USB_JS_0230 begin'); - var usbPortList = usb.getPorts() - if (usbPortList.length == 0) { - console.info('usb SUB_USB_JS_0230 usbPortList is null'); - expect(false).assertTrue(); - return - } - - expect(usbPortList.length > 0).assertTrue(); - - var portID = usbPortList[0].id + 10 - var maskCode = usb.getSupportedModes(portID) - expect(maskCode).assertEqual(0); - - console.info('usb SUB_USB_JS_0230 : PASS'); - expect(true).assertTrue(); - }) - -}) +/* + * Copyright (C) 2021-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 usb from '@ohos.usb'; +import CheckEmptyUtils from './CheckEmptyUtils.js'; +import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from '@ohos/hypium' + +/* usb core functions test */ +export default function UsbAutoJsunit() { +describe('UsbAutoJsunit', function () { + + beforeAll(function () { + console.log('*************Usb Unit UsbAutoJsunit Begin*************'); + var Version = usb.getVersion() + console.info('begin test getversion :' + Version) + + // 切换到 device + var usbPortList = usb.getPorts() + if (usbPortList.length > 0) { + if (usbPortList[0].status.currentMode == 2) { + console.info('usb case set data role 1, data role 1'); + usb.setPortRoles(usbPortList[0].id, 2, 2).then(data => { + console.info('usb case setPortRoles return: ' + data); + }).catch(error => { + console.info('usb case setPortRoles error : ' + error); + }); + CheckEmptyUtils.sleep(8000) + console.log('*************Usb Unit switch to device Begin*************'); + } + } + }) + beforeEach(function () { + console.info('beforeEach: *************Usb Unit Test Case*************'); + }) + + afterEach(function () { + console.info('afterEach: *************Usb Unit Test Case*************'); + }) + + afterAll(function () { + console.log('*************Usb Unit UsbAutoJsunit End*************'); + }) + + /** + * @tc.number : SUB_USB_JS_0930 + * @tc.name : usbFunctionsToString + * @tc.desc : 正向测试 0 返回 'none' + */ + it('SUB_USB_JS_0930', 0, function () { + console.info('usb SUB_USB_JS_0930 begin'); + var maskCode = 0 + var strMaskCode = usb.usbFunctionsToString(maskCode) + expect(strMaskCode).assertEqual('none'); + console.info('usb case maskCode ' + maskCode + ' usbFunctionsToString return int: ' + strMaskCode); + console.info('usb SUB_USB_JS_0930 : PASS'); + }) + + /** + * @tc.number : SUB_USB_JS_0940 + * @tc.name : usbFunctionsToString + * @tc.desc : 正向测试 1 返回 'acm' + */ + it('SUB_USB_JS_0940', 0, function () { + console.info('usb SUB_USB_JS_0940 begin'); + var maskCode = 1 + var strMaskCode = usb.usbFunctionsToString(maskCode) + expect(strMaskCode).assertEqual('acm'); + console.info('usb case maskCode ' + maskCode + ' usbFunctionsToString return int: ' + strMaskCode); + console.info('usb SUB_USB_JS_0940 : PASS'); + }) + + /** + * @tc.number : SUB_USB_JS_0950 + * @tc.name : usbFunctionsToString + * @tc.desc : 正向测试 2 返回 'ecm' + */ + it('SUB_USB_JS_0950', 0, function () { + console.info('usb SUB_USB_JS_0950 begin'); + var maskCode = 2 + var strMaskCode = usb.usbFunctionsToString(maskCode) + expect(strMaskCode).assertEqual('ecm'); + console.info('usb case maskCode ' + maskCode + ' usbFunctionsToString return int: ' + strMaskCode); + console.info('usb SUB_USB_JS_0950 : PASS'); + }) + + /** + * @tc.number : SUB_USB_JS_0960 + * @tc.name : usbFunctionsToString + * @tc.desc : 正向测试 3 返回 'acm,ecm' + */ + it('SUB_USB_JS_0960', 0, function () { + console.info('usb SUB_USB_JS_0960 begin'); + var maskCode = 3 + var strMaskCode = usb.usbFunctionsToString(maskCode) + expect(strMaskCode).assertEqual('acm,ecm'); + console.info('usb case maskCode ' + maskCode + ' usbFunctionsToString return int: ' + strMaskCode); + console.info('usb SUB_USB_JS_0960 : PASS'); + }) + + /** + * @tc.number : SUB_USB_JS_0970 + * @tc.name : usbFunctionsToString + * @tc.desc : 正向测试 4 返回 'hdc' + */ + it('SUB_USB_JS_0970', 0, function () { + console.info('usb SUB_USB_JS_0970 begin'); + var maskCode = 4 + var strMaskCode = usb.usbFunctionsToString(maskCode) + expect(strMaskCode).assertEqual('hdc'); + console.info('usb case maskCode ' + maskCode + ' usbFunctionsToString return int: ' + strMaskCode); + console.info('usb SUB_USB_JS_0970 : PASS'); + }) + + /** + * @tc.number : SUB_USB_JS_0980 + * @tc.name : usbFunctionsToString + * @tc.desc : 正向测试 5 返回 'acm,hdc' + */ + it('SUB_USB_JS_0980', 0, function () { + console.info('usb SUB_USB_JS_0980 begin'); + var maskCode = 5 + var strMaskCode = usb.usbFunctionsToString(maskCode) + expect(strMaskCode).assertEqual('hdc,acm'); + console.info('usb case maskCode ' + maskCode + ' usbFunctionsToString return int: ' + strMaskCode); + console.info('usb SUB_USB_JS_0980 : PASS'); + }) + + /** + * @tc.number : SUB_USB_JS_0990 + * @tc.name : usbFunctionsToString + * @tc.desc : 正向测试 6 返回 'ecm,hdc' + */ + it('SUB_USB_JS_0990', 0, function () { + console.info('usb SUB_USB_JS_0990 begin'); + var maskCode = 6 + var strMaskCode = usb.usbFunctionsToString(maskCode) + expect(strMaskCode).assertEqual('hdc,ecm'); + console.info('usb case maskCode ' + maskCode + ' usbFunctionsToString return int: ' + strMaskCode); + console.info('usb SUB_USB_JS_0990 : PASS'); + }) + + /** + * @tc.number : SUB_USB_JS_0860 + * @tc.name : usbFunctionsFromString + * @tc.desc : 正向测试 'none' 返回 0 + */ + it('SUB_USB_JS_0860', 0, function () { + console.info('usb SUB_USB_JS_0860 begin'); + var strMaskCode = 'none' + var nMaskCode = usb.usbFunctionsFromString(strMaskCode) + expect(nMaskCode).assertEqual(0); + console.info('usb case strMaskCode ' + strMaskCode + ' usbFunctionsFromString return int: ' + nMaskCode); + console.info('usb SUB_USB_JS_0860 : PASS'); + }) + + /** + * @tc.number : SUB_USB_JS_0870 + * @tc.name : usbFunctionsFromString + * @tc.desc : 正向测试 'acm' 返回 1 + */ + it('SUB_USB_JS_0870', 0, function () { + console.info('usb SUB_USB_JS_0870 begin'); + var strMaskCode = 'acm' + var nMaskCode = usb.usbFunctionsFromString(strMaskCode) + expect(nMaskCode).assertEqual(1); + console.info('usb case strMaskCode ' + strMaskCode + ' usbFunctionsFromString return int: ' + nMaskCode); + console.info('usb SUB_USB_JS_0870 : PASS'); + }) + + /** + * @tc.number : SUB_USB_JS_0880 + * @tc.name : usbFunctionsFromString + * @tc.desc : 正向测试 'ecm' 返回 2 + */ + it('SUB_USB_JS_0880', 0, function () { + console.info('usb SUB_USB_JS_0880 begin'); + var strMaskCode = 'ecm' + var nMaskCode = usb.usbFunctionsFromString(strMaskCode) + expect(nMaskCode).assertEqual(2); + console.info('usb case strMaskCode ' + strMaskCode + ' usbFunctionsFromString return int: ' + nMaskCode); + console.info('usb SUB_USB_JS_0880 : PASS'); + }) + + /** + * @tc.number : SUB_USB_JS_0890 + * @tc.name : usbFunctionsFromString + * @tc.desc : 正向测试 'acm,ecm' 返回 3 + */ + it('SUB_USB_JS_0890', 0, function () { + console.info('usb SUB_USB_JS_0890 begin'); + var strMaskCode = 'acm,ecm' + var nMaskCode = usb.usbFunctionsFromString(strMaskCode) + expect(nMaskCode).assertEqual(3); + console.info('usb case strMaskCode ' + strMaskCode + ' usbFunctionsFromString return int: ' + nMaskCode); + console.info('usb SUB_USB_JS_0890 : PASS'); + }) + + /** + * @tc.number : SUB_USB_JS_0900 + * @tc.name : usbFunctionsFromString + * @tc.desc : 正向测试 'hdc' 返回 4 + */ + it('SUB_USB_JS_0900', 0, function () { + console.info('usb SUB_USB_JS_0900 begin'); + var strMaskCode = 'hdc' + var nMaskCode = usb.usbFunctionsFromString(strMaskCode) + expect(nMaskCode).assertEqual(4); + console.info('usb case strMaskCode ' + strMaskCode + ' usbFunctionsFromString return int: ' + nMaskCode); + console.info('usb SUB_USB_JS_0900 : PASS'); + }) + + /** + * @tc.number : SUB_USB_JS_0910 + * @tc.name : usbFunctionsFromString + * @tc.desc : 正向测试 'acm,hdc' 返回 5 + */ + it('SUB_USB_JS_0910', 0, function () { + console.info('usb SUB_USB_JS_0910 begin'); + var strMaskCode = 'acm,hdc' + var nMaskCode = usb.usbFunctionsFromString(strMaskCode) + expect(nMaskCode).assertEqual(5); + console.info('usb case strMaskCode ' + strMaskCode + ' usbFunctionsFromString return int: ' + nMaskCode); + console.info('usb SUB_USB_JS_0910 : PASS'); + }) + + /** + * @tc.number : SUB_USB_JS_0920 + * @tc.name : usbFunctionsFromString + * @tc.desc : 正向测试 'ecm,hdc' 返回 6 + */ + it('SUB_USB_JS_0920', 0, function () { + console.info('usb SUB_USB_JS_0920 begin'); + var strMaskCode = 'ecm,hdc' + var nMaskCode = usb.usbFunctionsFromString(strMaskCode) + expect(nMaskCode).assertEqual(6); + console.info('usb case strMaskCode ' + strMaskCode + ' usbFunctionsFromString return int: ' + nMaskCode); + console.info('usb SUB_USB_JS_0920 : PASS'); + }) + + /** + * @tc.number : SUB_USB_JS_0330 + * @tc.name : getCurrentFunctions + * @tc.desc : 获取当前设备模式 掩码与描述字符转换 + */ + it('SUB_USB_JS_0330', 0, function () { + console.info('usb SUB_USB_JS_0330 begin'); + var maskCode = usb.getCurrentFunctions(); + console.info('usb case getCurrentFunctions return: ' + maskCode); + + var strMaskCode = usb.usbFunctionsToString(maskCode) + console.info('usb case usbFunctionsToString return str: ' + strMaskCode); + var nMaskCode = usb.usbFunctionsFromString(strMaskCode) + console.info('usb case strMaskCode usbFunctionsFromString return int: ' + nMaskCode); + expect(nMaskCode).assertEqual(maskCode); + console.info('usb SUB_USB_JS_0330 : PASS'); + expect(true).assertTrue(); + }) + + /** + * @tc.number : SUB_USB_JS_0340 + * @tc.name : usbFunctionString + * @tc.desc : 反向测试 获取当前设备模式 掩码与描述字符转换 + */ + it('SUB_USB_JS_0340', 0, function () { + console.info('usb SUB_USB_JS_0340 begin'); + var maskCode = usb.getCurrentFunctions(); + console.info('usb case getCurrentFunctions return: ' + maskCode); + + var strMaskCode = usb.usbFunctionsToString(maskCode) + console.info('usb case usbFunctionsToString return str: ' + strMaskCode); + var nMaskCode = usb.usbFunctionsFromString(strMaskCode) + console.info('usb case strMaskCode usbFunctionsFromString return int: ' + nMaskCode); + + var errmaskCode = 0 + var strMaskCode = usb.usbFunctionsToString(errmaskCode) + + console.info('usb case ' + errmaskCode + ' usbFunctionsToString return str: ' + strMaskCode); + + var errStrMaskCode = 'none' + var nMaskCode = usb.usbFunctionsFromString(errStrMaskCode) + expect(nMaskCode).assertEqual(0); + console.info('usb case errStrMaskCode ' + errStrMaskCode + + ' usbFunctionsFromString return int: ' + nMaskCode); + + console.info('usb SUB_USB_JS_0340 : PASS'); + }) + + /** + * @tc.number : SUB_USB_JS_0410 + * @tc.name : getPorts + * @tc.desc : 获取USB端口描述信息列表 + */ + it('SUB_USB_JS_0410', 0, function () { + console.info('usb SUB_USB_JS_0410 begin'); + var usbPortList = usb.getPorts() + if (usbPortList.length == 0) { + console.info('usb SUB_USB_JS_0410 usbPortList is null'); + expect(false).assertTrue(); + return + } + expect(usbPortList.length > 0).assertTrue(); + console.info('usb SUB_USB_JS_0410 : PASS'); + expect(true).assertTrue(); + }) + + /** + * @tc.number : SUB_USB_JS_0220 + * @tc.name : getSupportedModes + * @tc.desc : 获取指定的端口支持的模式列表的组合掩码 + */ + it('SUB_USB_JS_0220', 0, function () { + console.info('usb SUB_USB_JS_0220 begin'); + var usbPortList = usb.getPorts() + if (usbPortList.length == 0) { + console.info('usb SUB_USB_JS_0220 usbPortList is null'); + expect(false).assertTrue(); + return + } + + expect(usbPortList.length > 0).assertTrue(); + for (var i = 0; i < usbPortList.length; i++) { + var maskCode = usb.getSupportedModes(usbPortList[i].id) + expect(maskCode).assertEqual(usbPortList[i].supportedModes); + } + + console.info('usb SUB_USB_JS_0220 : PASS'); + expect(true).assertTrue(); + }) + + /** + * @tc.number : SUB_USB_JS_0230 + * @tc.name : getSupportedModes + * @tc.desc : 反向测试 改变id 获取指定的端口支持的模式列表的组合掩码 + */ + it('SUB_USB_JS_0230', 0, function () { + console.info('usb SUB_USB_JS_0230 begin'); + var usbPortList = usb.getPorts() + if (usbPortList.length == 0) { + console.info('usb SUB_USB_JS_0230 usbPortList is null'); + expect(false).assertTrue(); + return + } + + expect(usbPortList.length > 0).assertTrue(); + + var portID = usbPortList[0].id + 10 + var maskCode = usb.getSupportedModes(portID) + expect(maskCode).assertEqual(0); + + console.info('usb SUB_USB_JS_0230 : PASS'); + expect(true).assertTrue(); + }) + +}) +} diff --git a/usb/usb_standard/src/main/js/default/test/UsbCoreJsunit.test.js b/usb/usb_standard/src/main/js/test/UsbCoreJsunit.test.js old mode 100755 new mode 100644 similarity index 96% rename from usb/usb_standard/src/main/js/default/test/UsbCoreJsunit.test.js rename to usb/usb_standard/src/main/js/test/UsbCoreJsunit.test.js index 162dc8087d8d9af00c74e3584f75bdf2dd355e77..708f69cd33b889afcc39e658a8ee0075bb55b40e --- a/usb/usb_standard/src/main/js/default/test/UsbCoreJsunit.test.js +++ b/usb/usb_standard/src/main/js/test/UsbCoreJsunit.test.js @@ -1,427 +1,429 @@ -/* - * Copyright (c) 2021-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 usb from '@ohos.usb'; -import CheckEmptyUtils from './CheckEmptyUtils.js'; -import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from 'deccjsunit/index' - - -/* usb core functions test */ -describe('UsbCoreJsFunctionsTest', function () { - - var gDeviceList; - var gPipe; - var portCurrentMode; - - beforeAll(function () { - console.log('*************Usb Unit UsbCoreJsFunctionsTest Begin*************'); - var Version = usb.getVersion() - console.info('begin test getversion :' + Version) - // version > 17 host currentMode = 2 device currentMode = 1 - var usbPortList = usb.getPorts() - gDeviceList = usb.getDevices(); - if (usbPortList.length > 0) { - console.info('usb case gDeviceList.length return: ' + gDeviceList.length); - if (gDeviceList.length > 0) { - if (usbPortList[0].status.currentMode == 1) { - usb.setPortRoles(usbPortList[0].id, usb.SOURCE, usb.HOST).then(data => { - portCurrentMode = 2 - console.info('usb case setPortRoles return: ' + data); - }).catch(error => { - console.info('usb case setPortRoles error : ' + error); - }); - CheckEmptyUtils.sleep(8000) - console.log('*************Usb Unit Begin switch to host*************'); - } - } else { - portCurrentMode = 1 - } - } - }) - afterEach(function () { - console.info('afterEach: *************Usb Unit Test Case*************'); - }) - beforeEach(function () { - console.info('beforeEach: *************Usb Unit Test Case*************'); - }) - afterAll(function () { - console.log('*************Usb Unit UsbCoreJsFunctionsTest End*************'); - }) - - /** - * @tc.number : SUB_USB_JS_0480 - * @tc.name : getDevices - * @tc.desc : 获取设备列表 - */ - it('SUB_USB_JS_0480', 0, function () { - console.info('*****SUB_USB_JS_0480 portcurrentMode**** ret : ' + portCurrentMode) - if (portCurrentMode == 1) { - console.info('usb case get_device port is device') - expect(false).assertFalse(); - return - } - console.info('usb SUB_USB_JS_0480 begin'); - gDeviceList = usb.getDevices(); - if (gDeviceList.length == 0) { - console.info('usb case get_devices list is null') - expect(false).assertTrue(); - return - } - expect(gDeviceList.length).assertLarger(0); - console.info('usb case getDevices ret length: ' + gDeviceList.length); - console.info('usb SUB_USB_JS_0480: PASS'); - }) - - - /** - * @tc.number : SUB_USB_JS_0710 - * @tc.name : hasRigt - * @tc.desc : 权限查询 连接设备 关闭设备 - */ - it('SUB_USB_JS_0710', 0, function () { - console.info('usb has_right_01 begin'); - if (portCurrentMode == 1) { - console.info('usb case get_device port is device') - expect(false).assertFalse(); - return - } - if (gDeviceList.length == 0) { - console.info('usb case get_device_list is null') - expect(false).assertTrue(); - return - } - - for (var i = 0; i < gDeviceList.length; i++) { - var hasRight = usb.hasRight(gDeviceList[i].name) - console.info('usb has_right ret :' + hasRight); - } - - console.info('usb SUB_USB_JS_0710 : PASS'); - expect(true).assertTrue(); - }) - - - /** - * @tc.number : SUB_USB_JS_0680 - * @tc.name : requestRight - * @tc.desc : 请求权限 - */ - it('SUB_USB_JS_0680', 0, function () { - console.info('usb SUB_USB_JS_0680 begin'); - if (portCurrentMode == 1) { - console.info('usb case get_device port is device') - expect(false).assertFalse(); - return - } - if (gDeviceList.length == 0) { - console.info('usb case get_device_list is null') - expect(false).assertTrue(); - return - } - - for (var i = 0; i < gDeviceList.length; i++) { - usb.requestRight(gDeviceList[i].name).then(hasRight => { - expect(hasRight).assertTrue(); - console.info('usb request_right ret :' + hasRight); - console.info('usb SUB_USB_JS_0680 : PASS'); - }).catch(error => { - console.info('usb case device request right failed : ' + error + ' :' + gDeviceList[i].name); - expect(false).assertTrue(); - }); - } - }) - - /** - * @tc.number : SUB_USB_JS_0090 - * @tc.name : connectDevice - * @tc.desc : 打开设备 - */ - it('SUB_USB_JS_0090', 0, function () { - console.info('usb SUB_USB_JS_0090 begin'); - if (portCurrentMode == 1) { - console.info('usb case get_device port is device') - expect(false).assertFalse(); - return - } - if (gDeviceList.length == 0) { - console.info('usb case get_device_list is null') - expect(false).assertTrue(); - return - } - var isRight = usb.hasRight(gDeviceList[0].name); - if (!isRight) { - usb.requestRight(gDeviceList[0].name).then(hasRight => { - - }).catch(error => { - console.info('usb 01 requestRight error:' + error); - }); - CheckEmptyUtils.sleep(3000) - } - - gPipe = usb.connectDevice(gDeviceList[0]) - console.info('usb case connectDevice ret: ' + JSON.stringify(gPipe)); - expect(CheckEmptyUtils.isEmpty(gPipe)).assertFalse(); - - console.info('usb SUB_USB_JS_0090 : PASS'); - }) - - /** - * @tc.number : SUB_USB_JS_0250 - * @tc.name : closePipe - * @tc.desc : 反向测试 关闭设备 错误 busNum - */ - it('SUB_USB_JS_0250', 0, function () { - console.info('usb SUB_USB_JS_0250 begin'); - if (portCurrentMode == 1) { - console.info('usb case get_device port is device') - expect(false).assertFalse(); - return - } - if (gDeviceList.length == 0) { - console.info('usb case get_device_list is null') - expect(false).assertTrue(); - return - } - - var tmpPipe = JSON.parse(JSON.stringify(gPipe)); - tmpPipe.busNum = -23 - var isPipClose = usb.closePipe(tmpPipe); - console.info('usb case closePipe ret: ' + isPipClose); - expect(isPipClose == 0).assertFalse(); - - console.info('usb SUB_USB_JS_0250 : PASS'); - }) - - /** - * @tc.number : SUB_USB_JS_0260 - * @tc.name : closePipe - * @tc.desc : 反向测试 关闭设备 错误 devAddress - */ - it('SUB_USB_JS_0260', 0, function () { - console.info('usb SUB_USB_JS_0260 begin'); - if (portCurrentMode == 1) { - console.info('usb case get_device port is device') - expect(false).assertFalse(); - return - } - if (gDeviceList.length == 0) { - console.info('usb case get_device_list is null') - expect(false).assertTrue(); - return - } - var tmpPipe = JSON.parse(JSON.stringify(gPipe)); - tmpPipe.devAddress = -23 - var isPipClose = usb.closePipe(tmpPipe); - console.info('usb case closePipe ret: ' + isPipClose); - expect(isPipClose == 0).assertFalse(); - - console.info('usb SUB_USB_JS_0260 : PASS'); - }) - - /** - * @tc.number : SUB_USB_JS_0270 - * @tc.name : closePipe - * @tc.desc : 反向测试 关闭设备 错误 devAddress busNum - */ - it('SUB_USB_JS_0270', 0, function () { - console.info('usb SUB_USB_JS_0270 begin'); - if (portCurrentMode == 1) { - console.info('usb case get_device port is device') - expect(false).assertFalse(); - return - } - if (gDeviceList.length == 0) { - console.info('usb case get_device_list is null') - expect(false).assertTrue(); - return - } - var tmpPipe = JSON.parse(JSON.stringify(gPipe)); - tmpPipe.devAddress = -23 - tmpPipe.busNum = -23 - var isPipClose = usb.closePipe(tmpPipe); - console.info('usb case closePipe ret: ' + isPipClose); - expect(isPipClose == 0).assertFalse(); - - console.info('usb SUB_USB_JS_0270 : PASS'); - }) - - /** - * @tc.number : SUB_USB_JS_0240 - * @tc.name : closePipe - * @tc.desc : 关闭设备 - */ - it('SUB_USB_JS_0240', 0, function () { - console.info('usb SUB_USB_JS_0240 begin'); - if (portCurrentMode == 1) { - console.info('usb case get_device port is device') - expect(false).assertFalse(); - return - } - if (gDeviceList.length == 0) { - console.info('usb case get_device_list is null') - expect(false).assertTrue(); - return - } - - console.info('usb case closePipe param: ' + JSON.stringify(gPipe)); - var isPipClose = usb.closePipe(gPipe); - console.info('usb case closePipe ret: ' + isPipClose); - expect(isPipClose).assertEqual(0); - - console.info('usb SUB_USB_JS_0240 : PASS'); - }) - - /** - * @tc.number : SUB_USB_JS_0530 - * @tc.name : getRawDescriptor - * @tc.desc : 获取原始的USB描述符 - */ - it('SUB_USB_JS_0530', 0, function () { - console.info('usb SUB_USB_JS_0530 begin'); - if (portCurrentMode == 1) { - console.info('usb case get_device port is device') - expect(false).assertFalse(); - return - } - if (gDeviceList.length == 0) { - console.info('usb case get_device_list is null') - expect(false).assertTrue(); - return - } - - gPipe = usb.connectDevice(gDeviceList[0]) - console.info('usb case getRawDescriptor param: ' + JSON.stringify(gPipe)); - var descriptor = usb.getRawDescriptor(gPipe); - console.info('usb case getRawDescriptor ret: ' + descriptor); - expect(true).assertTrue(); - var isPipClose = usb.closePipe(gPipe); - expect(isPipClose).assertEqual(0); - - console.info('usb SUB_USB_JS_0530 : PASS'); - }) - - /** - * @tc.number : SUB_USB_JS_0490 - * @tc.name : getFileDescriptor - * @tc.desc : 获取文件描述符 - */ - it('SUB_USB_JS_0490', 0, function () { - console.info('usb SUB_USB_JS_0490 begin'); - if (portCurrentMode == 1) { - console.info('usb case get_device port is device') - expect(false).assertFalse(); - return - } - if (gDeviceList.length == 0) { - console.info('usb case get_device_list is null') - expect(false).assertTrue(); - return - } - gPipe = usb.connectDevice(gDeviceList[0]) - console.info('usb case getFileDescriptor param: ' + JSON.stringify(gPipe)); - var fileDescriptor = usb.getFileDescriptor(gPipe); - console.info('usb case getFileDescriptor ret: ' + fileDescriptor); - expect(true).assertTrue(); - var isPipClose = usb.closePipe(gPipe); - expect(isPipClose).assertEqual(0); - - console.info('usb SUB_USB_JS_0490 : PASS'); - }) - - /** - * @tc.number : SUB_USB_JS_0500 - * @tc.name : getFileDescriptor - * @tc.desc : 获取文件描述符,反向测试,错误参数busNum=512 - */ - it('SUB_USB_JS_0500', 0, function () { - console.info('usb SUB_USB_JS_0500 begin'); - if (portCurrentMode == 1) { - console.info('usb case get_device port is device') - expect(false).assertFalse(); - return - } - if (gDeviceList.length == 0) { - console.info('usb case get_device_list is null') - expect(false).assertTrue(); - return - } - gPipe = usb.connectDevice(gDeviceList[0]) - var tempPipe = {busNum : 255, devAddress : 255} - console.info('usb case getFileDescriptor param: ' + JSON.stringify(gPipe)); - var fileDescriptor = usb.getFileDescriptor(tempPipe); - expect(fileDescriptor < 0).assertTrue(); - console.info('usb case getFileDescriptor ret: ' + fileDescriptor); - var isPipClose = usb.closePipe(gPipe); - expect(isPipClose).assertEqual(0); - console.info('usb SUB_USB_JS_0500 : PASS'); - }) - - /** - * @tc.number : SUB_USB_JS_0510 - * @tc.name : getFileDescriptor - * @tc.desc : 获取文件描述符,反向测试,错误参数devAddress=512 - */ - it('SUB_USB_JS_0510', 0, function () { - console.info('usb get_file_descriptor_03 begin'); - if (portCurrentMode == 1) { - console.info('usb case get_device port is device') - expect(false).assertFalse(); - return - } - if (gDeviceList.length == 0) { - console.info('usb case get_device_list is null') - expect(false).assertTrue(); - return - } - gPipe = usb.connectDevice(gDeviceList[0]) - var tempPipe = {busNum : 255, devAddress : gPipe.devAddress} - console.info('usb case getFileDescriptor param: ' + JSON.stringify(gPipe)); - var fileDescriptor = usb.getFileDescriptor(tempPipe); - expect(fileDescriptor < 0).assertTrue(); - console.info('usb case getFileDescriptor ret: ' + fileDescriptor); - var isPipClose = usb.closePipe(gPipe); - expect(isPipClose).assertEqual(0); - console.info('usb SUB_USB_JS_0510 : PASS'); - }) - - /** - * @tc.number : SUB_USB_JS_0520 - * @tc.name : getFileDescriptor - * @tc.desc : 获取文件描述符,反向测试,错误参数busNum=512,devAddress=512 - */ - it('SUB_USB_JS_0520', 0, function () { - console.info('usb get_file_descriptor_04 begin'); - if (portCurrentMode == 1) { - console.info('usb case get_device port is device') - expect(false).assertFalse(); - return - } - if (gDeviceList.length == 0) { - console.info('usb case get_device_list is null') - expect(false).assertTrue(); - return - } - gPipe = usb.connectDevice(gDeviceList[0]) - var tempPipe = {busNum : gPipe.busNum, devAddress : 255} - console.info('usb case getFileDescriptor param: ' + JSON.stringify(gPipe)); - var fileDescriptor = usb.getFileDescriptor(tempPipe); - expect(fileDescriptor < 0).assertTrue(); - console.info('usb case getFileDescriptor ret: ' + fileDescriptor); - var isPipClose = usb.closePipe(gPipe); - expect(isPipClose).assertEqual(0); - console.info('usb SUB_USB_JS_0520 : PASS'); - }) - -}) +/* + * Copyright (c) 2021-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 usb from '@ohos.usb'; +import CheckEmptyUtils from './CheckEmptyUtils.js'; +import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from '@ohos/hypium' + + +/* usb core functions test */ +export default function UsbCoreJsFunctionsTest() { +describe('UsbCoreJsFunctionsTest', function () { + + var gDeviceList; + var gPipe; + var portCurrentMode; + + beforeAll(function () { + console.log('*************Usb Unit UsbCoreJsFunctionsTest Begin*************'); + var Version = usb.getVersion() + console.info('begin test getversion :' + Version) + // version > 17 host currentMode = 2 device currentMode = 1 + var usbPortList = usb.getPorts() + gDeviceList = usb.getDevices(); + if (usbPortList.length > 0) { + console.info('usb case gDeviceList.length return: ' + gDeviceList.length); + if (gDeviceList.length > 0) { + if (usbPortList[0].status.currentMode == 1) { + usb.setPortRoles(usbPortList[0].id, usb.SOURCE, usb.HOST).then(data => { + portCurrentMode = 2 + console.info('usb case setPortRoles return: ' + data); + }).catch(error => { + console.info('usb case setPortRoles error : ' + error); + }); + CheckEmptyUtils.sleep(8000) + console.log('*************Usb Unit Begin switch to host*************'); + } + } else { + portCurrentMode = 1 + } + } + }) + afterEach(function () { + console.info('afterEach: *************Usb Unit Test Case*************'); + }) + beforeEach(function () { + console.info('beforeEach: *************Usb Unit Test Case*************'); + }) + afterAll(function () { + console.log('*************Usb Unit UsbCoreJsFunctionsTest End*************'); + }) + + /** + * @tc.number : SUB_USB_JS_0480 + * @tc.name : getDevices + * @tc.desc : 获取设备列表 + */ + it('SUB_USB_JS_0480', 0, function () { + console.info('*****SUB_USB_JS_0480 portcurrentMode**** ret : ' + portCurrentMode) + if (portCurrentMode == 1) { + console.info('usb case get_device port is device') + expect(false).assertFalse(); + return + } + console.info('usb SUB_USB_JS_0480 begin'); + gDeviceList = usb.getDevices(); + if (gDeviceList.length == 0) { + console.info('usb case get_devices list is null') + expect(false).assertTrue(); + return + } + expect(gDeviceList.length).assertLarger(0); + console.info('usb case getDevices ret length: ' + gDeviceList.length); + console.info('usb SUB_USB_JS_0480: PASS'); + }) + + + /** + * @tc.number : SUB_USB_JS_0710 + * @tc.name : hasRigt + * @tc.desc : 权限查询 连接设备 关闭设备 + */ + it('SUB_USB_JS_0710', 0, function () { + console.info('usb has_right_01 begin'); + if (portCurrentMode == 1) { + console.info('usb case get_device port is device') + expect(false).assertFalse(); + return + } + if (gDeviceList.length == 0) { + console.info('usb case get_device_list is null') + expect(false).assertTrue(); + return + } + + for (var i = 0; i < gDeviceList.length; i++) { + var hasRight = usb.hasRight(gDeviceList[i].name) + console.info('usb has_right ret :' + hasRight); + } + + console.info('usb SUB_USB_JS_0710 : PASS'); + expect(true).assertTrue(); + }) + + + /** + * @tc.number : SUB_USB_JS_0680 + * @tc.name : requestRight + * @tc.desc : 请求权限 + */ + it('SUB_USB_JS_0680', 0, function () { + console.info('usb SUB_USB_JS_0680 begin'); + if (portCurrentMode == 1) { + console.info('usb case get_device port is device') + expect(false).assertFalse(); + return + } + if (gDeviceList.length == 0) { + console.info('usb case get_device_list is null') + expect(false).assertTrue(); + return + } + + for (var i = 0; i < gDeviceList.length; i++) { + usb.requestRight(gDeviceList[i].name).then(hasRight => { + expect(hasRight).assertTrue(); + console.info('usb request_right ret :' + hasRight); + console.info('usb SUB_USB_JS_0680 : PASS'); + }).catch(error => { + console.info('usb case device request right failed : ' + error + ' :' + gDeviceList[i].name); + expect(false).assertTrue(); + }); + } + }) + + /** + * @tc.number : SUB_USB_JS_0090 + * @tc.name : connectDevice + * @tc.desc : 打开设备 + */ + it('SUB_USB_JS_0090', 0, function () { + console.info('usb SUB_USB_JS_0090 begin'); + if (portCurrentMode == 1) { + console.info('usb case get_device port is device') + expect(false).assertFalse(); + return + } + if (gDeviceList.length == 0) { + console.info('usb case get_device_list is null') + expect(false).assertTrue(); + return + } + var isRight = usb.hasRight(gDeviceList[0].name); + if (!isRight) { + usb.requestRight(gDeviceList[0].name).then(hasRight => { + + }).catch(error => { + console.info('usb 01 requestRight error:' + error); + }); + CheckEmptyUtils.sleep(3000) + } + + gPipe = usb.connectDevice(gDeviceList[0]) + console.info('usb case connectDevice ret: ' + JSON.stringify(gPipe)); + expect(CheckEmptyUtils.isEmpty(gPipe)).assertFalse(); + + console.info('usb SUB_USB_JS_0090 : PASS'); + }) + + /** + * @tc.number : SUB_USB_JS_0250 + * @tc.name : closePipe + * @tc.desc : 反向测试 关闭设备 错误 busNum + */ + it('SUB_USB_JS_0250', 0, function () { + console.info('usb SUB_USB_JS_0250 begin'); + if (portCurrentMode == 1) { + console.info('usb case get_device port is device') + expect(false).assertFalse(); + return + } + if (gDeviceList.length == 0) { + console.info('usb case get_device_list is null') + expect(false).assertTrue(); + return + } + + var tmpPipe = JSON.parse(JSON.stringify(gPipe)); + tmpPipe.busNum = -23 + var isPipClose = usb.closePipe(tmpPipe); + console.info('usb case closePipe ret: ' + isPipClose); + expect(isPipClose == 0).assertFalse(); + + console.info('usb SUB_USB_JS_0250 : PASS'); + }) + + /** + * @tc.number : SUB_USB_JS_0260 + * @tc.name : closePipe + * @tc.desc : 反向测试 关闭设备 错误 devAddress + */ + it('SUB_USB_JS_0260', 0, function () { + console.info('usb SUB_USB_JS_0260 begin'); + if (portCurrentMode == 1) { + console.info('usb case get_device port is device') + expect(false).assertFalse(); + return + } + if (gDeviceList.length == 0) { + console.info('usb case get_device_list is null') + expect(false).assertTrue(); + return + } + var tmpPipe = JSON.parse(JSON.stringify(gPipe)); + tmpPipe.devAddress = -23 + var isPipClose = usb.closePipe(tmpPipe); + console.info('usb case closePipe ret: ' + isPipClose); + expect(isPipClose == 0).assertFalse(); + + console.info('usb SUB_USB_JS_0260 : PASS'); + }) + + /** + * @tc.number : SUB_USB_JS_0270 + * @tc.name : closePipe + * @tc.desc : 反向测试 关闭设备 错误 devAddress busNum + */ + it('SUB_USB_JS_0270', 0, function () { + console.info('usb SUB_USB_JS_0270 begin'); + if (portCurrentMode == 1) { + console.info('usb case get_device port is device') + expect(false).assertFalse(); + return + } + if (gDeviceList.length == 0) { + console.info('usb case get_device_list is null') + expect(false).assertTrue(); + return + } + var tmpPipe = JSON.parse(JSON.stringify(gPipe)); + tmpPipe.devAddress = -23 + tmpPipe.busNum = -23 + var isPipClose = usb.closePipe(tmpPipe); + console.info('usb case closePipe ret: ' + isPipClose); + expect(isPipClose == 0).assertFalse(); + + console.info('usb SUB_USB_JS_0270 : PASS'); + }) + + /** + * @tc.number : SUB_USB_JS_0240 + * @tc.name : closePipe + * @tc.desc : 关闭设备 + */ + it('SUB_USB_JS_0240', 0, function () { + console.info('usb SUB_USB_JS_0240 begin'); + if (portCurrentMode == 1) { + console.info('usb case get_device port is device') + expect(false).assertFalse(); + return + } + if (gDeviceList.length == 0) { + console.info('usb case get_device_list is null') + expect(false).assertTrue(); + return + } + + console.info('usb case closePipe param: ' + JSON.stringify(gPipe)); + var isPipClose = usb.closePipe(gPipe); + console.info('usb case closePipe ret: ' + isPipClose); + expect(isPipClose).assertEqual(0); + + console.info('usb SUB_USB_JS_0240 : PASS'); + }) + + /** + * @tc.number : SUB_USB_JS_0530 + * @tc.name : getRawDescriptor + * @tc.desc : 获取原始的USB描述符 + */ + it('SUB_USB_JS_0530', 0, function () { + console.info('usb SUB_USB_JS_0530 begin'); + if (portCurrentMode == 1) { + console.info('usb case get_device port is device') + expect(false).assertFalse(); + return + } + if (gDeviceList.length == 0) { + console.info('usb case get_device_list is null') + expect(false).assertTrue(); + return + } + + gPipe = usb.connectDevice(gDeviceList[0]) + console.info('usb case getRawDescriptor param: ' + JSON.stringify(gPipe)); + var descriptor = usb.getRawDescriptor(gPipe); + console.info('usb case getRawDescriptor ret: ' + descriptor); + expect(true).assertTrue(); + var isPipClose = usb.closePipe(gPipe); + expect(isPipClose).assertEqual(0); + + console.info('usb SUB_USB_JS_0530 : PASS'); + }) + + /** + * @tc.number : SUB_USB_JS_0490 + * @tc.name : getFileDescriptor + * @tc.desc : 获取文件描述符 + */ + it('SUB_USB_JS_0490', 0, function () { + console.info('usb SUB_USB_JS_0490 begin'); + if (portCurrentMode == 1) { + console.info('usb case get_device port is device') + expect(false).assertFalse(); + return + } + if (gDeviceList.length == 0) { + console.info('usb case get_device_list is null') + expect(false).assertTrue(); + return + } + gPipe = usb.connectDevice(gDeviceList[0]) + console.info('usb case getFileDescriptor param: ' + JSON.stringify(gPipe)); + var fileDescriptor = usb.getFileDescriptor(gPipe); + console.info('usb case getFileDescriptor ret: ' + fileDescriptor); + expect(true).assertTrue(); + var isPipClose = usb.closePipe(gPipe); + expect(isPipClose).assertEqual(0); + + console.info('usb SUB_USB_JS_0490 : PASS'); + }) + + /** + * @tc.number : SUB_USB_JS_0500 + * @tc.name : getFileDescriptor + * @tc.desc : 获取文件描述符,反向测试,错误参数busNum=512 + */ + it('SUB_USB_JS_0500', 0, function () { + console.info('usb SUB_USB_JS_0500 begin'); + if (portCurrentMode == 1) { + console.info('usb case get_device port is device') + expect(false).assertFalse(); + return + } + if (gDeviceList.length == 0) { + console.info('usb case get_device_list is null') + expect(false).assertTrue(); + return + } + gPipe = usb.connectDevice(gDeviceList[0]) + var tempPipe = {busNum : 255, devAddress : 255} + console.info('usb case getFileDescriptor param: ' + JSON.stringify(gPipe)); + var fileDescriptor = usb.getFileDescriptor(tempPipe); + expect(fileDescriptor < 0).assertTrue(); + console.info('usb case getFileDescriptor ret: ' + fileDescriptor); + var isPipClose = usb.closePipe(gPipe); + expect(isPipClose).assertEqual(0); + console.info('usb SUB_USB_JS_0500 : PASS'); + }) + + /** + * @tc.number : SUB_USB_JS_0510 + * @tc.name : getFileDescriptor + * @tc.desc : 获取文件描述符,反向测试,错误参数devAddress=512 + */ + it('SUB_USB_JS_0510', 0, function () { + console.info('usb get_file_descriptor_03 begin'); + if (portCurrentMode == 1) { + console.info('usb case get_device port is device') + expect(false).assertFalse(); + return + } + if (gDeviceList.length == 0) { + console.info('usb case get_device_list is null') + expect(false).assertTrue(); + return + } + gPipe = usb.connectDevice(gDeviceList[0]) + var tempPipe = {busNum : 255, devAddress : gPipe.devAddress} + console.info('usb case getFileDescriptor param: ' + JSON.stringify(gPipe)); + var fileDescriptor = usb.getFileDescriptor(tempPipe); + expect(fileDescriptor < 0).assertTrue(); + console.info('usb case getFileDescriptor ret: ' + fileDescriptor); + var isPipClose = usb.closePipe(gPipe); + expect(isPipClose).assertEqual(0); + console.info('usb SUB_USB_JS_0510 : PASS'); + }) + + /** + * @tc.number : SUB_USB_JS_0520 + * @tc.name : getFileDescriptor + * @tc.desc : 获取文件描述符,反向测试,错误参数busNum=512,devAddress=512 + */ + it('SUB_USB_JS_0520', 0, function () { + console.info('usb get_file_descriptor_04 begin'); + if (portCurrentMode == 1) { + console.info('usb case get_device port is device') + expect(false).assertFalse(); + return + } + if (gDeviceList.length == 0) { + console.info('usb case get_device_list is null') + expect(false).assertTrue(); + return + } + gPipe = usb.connectDevice(gDeviceList[0]) + var tempPipe = {busNum : gPipe.busNum, devAddress : 255} + console.info('usb case getFileDescriptor param: ' + JSON.stringify(gPipe)); + var fileDescriptor = usb.getFileDescriptor(tempPipe); + expect(fileDescriptor < 0).assertTrue(); + console.info('usb case getFileDescriptor ret: ' + fileDescriptor); + var isPipClose = usb.closePipe(gPipe); + expect(isPipClose).assertEqual(0); + console.info('usb SUB_USB_JS_0520 : PASS'); + }) + +}) +} diff --git a/usb/usb_standard/src/main/js/default/test/UsbCoreJsunitEx.test.js b/usb/usb_standard/src/main/js/test/UsbCoreJsunitEx.test.js old mode 100755 new mode 100644 similarity index 96% rename from usb/usb_standard/src/main/js/default/test/UsbCoreJsunitEx.test.js rename to usb/usb_standard/src/main/js/test/UsbCoreJsunitEx.test.js index 7b13b64299deb337b279f7b7eb9e22bf2b456a9e..1685e45617d21c494314d466d448accdaaf619e1 --- a/usb/usb_standard/src/main/js/default/test/UsbCoreJsunitEx.test.js +++ b/usb/usb_standard/src/main/js/test/UsbCoreJsunitEx.test.js @@ -1,704 +1,706 @@ -/* - * Copyright (c) 2021-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 usb from '@ohos.usb'; -import CheckEmptyUtils from './CheckEmptyUtils.js'; -import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from 'deccjsunit/index' - - -/* usb core functions test */ -describe('UsbCoreJsFunctionsTestEx', function () { - - var gDeviceList - var portCurrentMode - - beforeAll(function () { - console.log('*************Usb Unit UsbCoreJsFunctionsTestEx Begin*************'); - var Version = usb.getVersion() - console.info('begin test getversion :' + Version) - // version > 17 host currentMode = 2 device currentMode = 1 - var usbPortList = usb.getPorts() - gDeviceList = usb.getDevices(); - if (usbPortList.length > 0) { - if (gDeviceList.length > 0) { - if (usbPortList[0].status.currentMode == 1) { - usb.setPortRoles(usbPortList[0].id, usb.SOURCE, usb.HOST).then(data => { - portCurrentMode = 2 - console.info('usb case setPortRolesEx return: ' + data); - }).catch(error => { - console.info('usb case setPortRolesEx error : ' + error); - }); - console.log('*************Usb Unit Begin switch to host*************'); - } - } else { - portCurrentMode = 1 - } - } - }) - beforeEach(function () { - console.info('beforeEach: *************Usb Unit Test CaseEx*************'); - }) - afterEach(function () { - console.info('afterEach: *************Usb Unit Test CaseEx*************'); - }) - afterAll(function () { - console.log('*************Usb Unit UsbCoreJsFunctionsTestEx End*************'); - }) - - - /** - * @tc.number : SUB_USB_JS_0100 - * @tc.name : connectDevice - * @tc.desc : 反向测试 错误参数 devAddress 打开设备 - */ - it('SUB_USB_JS_0100', 0, function () { - console.info('usb SUB_USB_JS_0100 begin'); - console.info('*****SUB_USB_JS_0100 portCurrentMode**** ret : ' + portCurrentMode) - if (portCurrentMode == 1) { - console.info('usb case get_device port is device') - expect(false).assertFalse(); - return - } - if (gDeviceList.length == 0) { - console.info('usb case get_device_list is null') - expect(false).assertTrue(); - return - } - var isRight = usb.hasRight(gDeviceList[0].name); - if (!isRight) { - usb.requestRight(gDeviceList[0].name).then(hasRight => { - }).catch(error => { - console.info('usb JS_0100 requestRight error:' + error); - }); - console.info('usb JS_0100 requestRight end:'); - CheckEmptyUtils.sleep(3000) - } - - var device = JSON.parse(JSON.stringify(gDeviceList[0])); - device.devAddress = 2 + 10000 - try { - var usbDevicePipe = usb.connectDevice(device) - } catch (err) { - expect(true).assertTrue(); - console.info('usb connectDevice fail:' + err); - } - console.info('usb case connectDevice ret: ' + JSON.stringify(usbDevicePipe) + - ' devAddress ' + device.devAddress); - expect(CheckEmptyUtils.isEmpty(usbDevicePipe)).assertTrue(); - - console.info('usb SUB_USB_JS_0100 : PASS'); - }) - - /** - * @tc.number : SUB_USB_JS_0110 - * @tc.name : connectDevice - * @tc.desc : 反向测试 busNum错误参数 打开设备 - */ - it('SUB_USB_JS_0110', 0, function () { - console.info('usb SUB_USB_JS_0110 begin'); - if (portCurrentMode == 1) { - console.info('usb case get_device port is device') - expect(false).assertFalse(); - return - } - if (gDeviceList.length == 0) { - console.info('usb case get_device_list is null') - expect(false).assertTrue(); - return - } - var isRight = usb.hasRight(gDeviceList[0].name); - if (!isRight) { - usb.requestRight(gDeviceList[0].name).then(hasRight => { - }).catch(error => { - console.info('usb JS_0110 requestRight error:' + error); - }); - console.info('usb JS_0110 requestRight end:'); - CheckEmptyUtils.sleep(3000) - } - - var device = JSON.parse(JSON.stringify(gDeviceList[0])); - device.busNum = 2 + 1000 - try { - var usbDevicePipe = usb.connectDevice(device) - } catch (err) { - expect(true).assertTrue(); - console.info('usb connectDevice fail:' + err); - } - console.info('usb case connectDevice ret: ' + JSON.stringify(usbDevicePipe) + - ' busNum ' + device.busNum); - expect(CheckEmptyUtils.isEmpty(usbDevicePipe)).assertTrue(); - console.info('usb SUB_USB_JS_0110 : PASS'); - }) - - /** - * @tc.number : SUB_USB_JS_0120 - * @tc.name : connectDevice - * @tc.desc : 反向测试 serial错误参数 打开设备 - */ - it('SUB_USB_JS_0120', 0, function () { - console.info('usb SUB_USB_JS_0120 begin'); - if (portCurrentMode == 1) { - console.info('usb case get_device port is device') - expect(false).assertFalse(); - return - } - if (gDeviceList.length == 0) { - console.info('usb case get_device_list is null') - expect(false).assertTrue(); - return - } - var isRight = usb.hasRight(gDeviceList[0].name); - if (!isRight) { - usb.requestRight(gDeviceList[0].name).then(hasRight => { - }).catch(error => { - console.info('usb JS_0120 requestRight error:' + error); - }); - console.info('usb JS_0120 requestRight end:'); - CheckEmptyUtils.sleep(3000) - } - - var device = JSON.parse(JSON.stringify(gDeviceList[0])); - device.serial = 'asdfsd' - try { - var usbDevicePipe = usb.connectDevice(device) - } catch (err) { - expect(true).assertTrue(); - console.info('usb connectDevice fail:' + err); - } - console.info('usb case connectDevice ret: ' + JSON.stringify(usbDevicePipe) + - ' serial ' + device.serial); - expect(CheckEmptyUtils.isEmpty(usbDevicePipe)).assertFalse(); - var isPipClose = usb.closePipe(usbDevicePipe); - console.info('usb case closePipe ret: ' + isPipClose); - expect(isPipClose).assertEqual(0); - console.info('usb SUB_USB_JS_0120 : PASS'); - }) - - /** - * @tc.number : SUB_USB_JS_0130 - * @tc.name : connectDevice - * @tc.desc : 反向测试 name错误参数 打开设备 - */ - it('SUB_USB_JS_0130', 0, function () { - console.info('usb SUB_USB_JS_0130 begin'); - if (portCurrentMode == 1) { - console.info('usb case get_device port is device') - expect(false).assertFalse(); - return - } - if (gDeviceList.length == 0) { - console.info('usb case get_device_list is null') - expect(false).assertTrue(); - return - } - var isRight = usb.hasRight(gDeviceList[0].name); - if (!isRight) { - usb.requestRight(gDeviceList[0].name).then(hasRight => { - }).catch(error => { - console.info('usb JS_0130 requestRight error:' + error); - }); - console.info('usb JS_0130 requestRight end:'); - CheckEmptyUtils.sleep(3000) - } - - var device = JSON.parse(JSON.stringify(gDeviceList[0])); - device.name = 2 + 10000 - try { - var usbDevicePipe = usb.connectDevice(device) - } catch (err) { - expect(true).assertTrue(); - console.info('usb connectDevice fail:' + err); - } - console.info('usb case connectDevice ret: ' + JSON.stringify(usbDevicePipe) + ' name ' + device.name); - expect(CheckEmptyUtils.isEmpty(usbDevicePipe)).assertFalse(); - var isPipClose = usb.closePipe(usbDevicePipe); - console.info('usb case closePipe ret: ' + isPipClose); - expect(isPipClose).assertEqual(0); - console.info('usb SUB_USB_JS_0130 : PASS'); - }) - - /** - * @tc.number : SUB_USB_JS_0140 - * @tc.name : connectDevice - * @tc.desc : 反向测试 manufacturerName错误参数 打开设备 - */ - it('SUB_USB_JS_0140', 0, function () { - console.info('usb connect_device_06 begin'); - if (portCurrentMode == 1) { - console.info('usb case get_device port is device') - expect(false).assertFalse(); - return - } - if (gDeviceList.length == 0) { - console.info('usb case get_device_list is null') - expect(false).assertTrue(); - return - } - var isRight = usb.hasRight(gDeviceList[0].name); - if (!isRight) { - usb.requestRight(gDeviceList[0].name).then(hasRight => { - }).catch(error => { - console.info('usb JS_0140 requestRight error:' + error); - }); - console.info('usb JS_0140 requestRight end:'); - CheckEmptyUtils.sleep(3000) - } - - var device = JSON.parse(JSON.stringify(gDeviceList[0])); - device.manufacturerName = 2 + 10000 - try { - var usbDevicePipe = usb.connectDevice(device) - } catch (err) { - expect(true).assertTrue(); - console.info('usb connectDevice fail:' + err); - } - console.info('usb case connectDevice ret: ' + JSON.stringify(usbDevicePipe) + - ' manufacturerName ' + device.manufacturerName); - expect(CheckEmptyUtils.isEmpty(usbDevicePipe)).assertFalse(); - var isPipClose = usb.closePipe(usbDevicePipe); - console.info('usb case closePipe ret: ' + isPipClose); - expect(isPipClose).assertEqual(0); - console.info('usb SUB_USB_JS_0140 : PASS'); - }) - - /** - * @tc.number : SUB_USB_JS_0150 - * @tc.name : connectDevice - * @tc.desc : 反向测试 productName错误参数 打开设备 - */ - it('SUB_USB_JS_0150', 0, function () { - console.info('usb SUB_USB_JS_0150 begin'); - if (portCurrentMode == 1) { - console.info('usb case get_device port is device') - expect(false).assertFalse(); - return - } - if (gDeviceList.length == 0) { - console.info('usb case get_device_list is null') - expect(false).assertTrue(); - return - } - var isRight = usb.hasRight(gDeviceList[0].name); - if (!isRight) { - usb.requestRight(gDeviceList[0].name).then(hasRight => { - }).catch(error => { - console.info('usb SUB_USB_JS_0150 requestRight error:' + error); - }); - console.info('usb SUB_USB_JS_0150 requestRight end:'); - CheckEmptyUtils.sleep(3000) - } - - var device = JSON.parse(JSON.stringify(gDeviceList[0])); - device.productName = 'sdfsdfe' - try { - var usbDevicePipe = usb.connectDevice(device) - } catch (err) { - expect(true).assertTrue(); - console.info('usb connectDevice fail:' + err); - } - console.info('usb case connectDevice ret: ' + JSON.stringify(usbDevicePipe) + - ' productName ' + device.productName); - expect(CheckEmptyUtils.isEmpty(usbDevicePipe)).assertFalse(); - var isPipClose = usb.closePipe(usbDevicePipe); - console.info('usb case closePipe ret: ' + isPipClose); - expect(isPipClose).assertEqual(0); - console.info('usb SUB_USB_JS_0150 : PASS'); - }) - - /** - * @tc.number : SUB_USB_JS_0160 - * @tc.name : connectDevice - * @tc.desc : 反向测试 version错误参数 打开设备 - */ - it('SUB_USB_JS_0160', 0, function () { - console.info('usb connect_device_08 begin'); - if (portCurrentMode == 1) { - console.info('usb case get_device port is device') - expect(false).assertFalse(); - return - } - if (gDeviceList.length == 0) { - console.info('usb case get_device_list is null') - expect(false).assertTrue(); - return - } - var isRight = usb.hasRight(gDeviceList[0].name); - if (!isRight) { - usb.requestRight(gDeviceList[0].name).then(hasRight => { - }).catch(error => { - console.info('usb SUB_USB_JS_0160 requestRight error:' + error); - }); - console.info('usb SUB_USB_JS_0160 requestRight end:'); - CheckEmptyUtils.sleep(3000) - } - - var device = JSON.parse(JSON.stringify(gDeviceList[0])); - device.version = 'gwefsdf' - try { - var usbDevicePipe = usb.connectDevice(device) - } catch (err) { - expect(true).assertTrue(); - console.info('usb connectDevice fail:' + err); - } - console.info('usb case connectDevice ret: ' + JSON.stringify(usbDevicePipe) + - ' version ' + device.version); - expect(CheckEmptyUtils.isEmpty(usbDevicePipe)).assertFalse(); - var isPipClose = usb.closePipe(usbDevicePipe); - console.info('usb case closePipe ret: ' + isPipClose); - expect(isPipClose).assertEqual(0); - console.info('usb SUB_USB_JS_0160 : PASS'); - }) - - /** - * @tc.number : SUB_USB_JS_0170 - * @tc.name : connectDevice - * @tc.desc : 反向测试 vendorId错误参数 打开设备 - */ - it('SUB_USB_JS_0170', 0, function () { - console.info('usb connect_device_09 begin'); - if (portCurrentMode == 1) { - console.info('usb case get_device port is device') - expect(false).assertFalse(); - return - } - if (gDeviceList.length == 0) { - console.info('usb case get_device_list is null') - expect(false).assertTrue(); - return - } - var isRight = usb.hasRight(gDeviceList[0].name); - if (!isRight) { - usb.requestRight(gDeviceList[0].name).then(hasRight => { - }).catch(error => { - console.info('usb SUB_USB_JS_0170 requestRight error:' + error); - }); - console.info('usb SUB_USB_JS_0170 requestRight end:'); - CheckEmptyUtils.sleep(3000) - } - - var device = JSON.parse(JSON.stringify(gDeviceList[0])); - device.vendorId = 2 + 10000 - try { - var usbDevicePipe = usb.connectDevice(device) - } catch (err) { - expect(true).assertTrue(); - console.info('usb connectDevice fail:' + err); - } - console.info('usb case connectDevice ret: ' + JSON.stringify(usbDevicePipe) + - ' vendorId ' + device.vendorId); - expect(CheckEmptyUtils.isEmpty(usbDevicePipe)).assertFalse(); - var isPipClose = usb.closePipe(usbDevicePipe); - console.info('usb case closePipe ret: ' + isPipClose); - expect(isPipClose).assertEqual(0); - console.info('usb SUB_USB_JS_0170 : PASS'); - }) - - /** - * @tc.number : SUB_USB_JS_0180 - * @tc.name : connectDevice - * @tc.desc : 反向测试 productId错误参数 打开设备 - */ - it('SUB_USB_JS_0180', 0, function () { - console.info('usb connect_device_10 begin'); - if (portCurrentMode == 1) { - console.info('usb case get_device port is device') - expect(false).assertFalse(); - return - } - if (gDeviceList.length == 0) { - console.info('usb case get_device_list is null') - expect(false).assertTrue(); - return - } - var isRight = usb.hasRight(gDeviceList[0].name); - if (!isRight) { - usb.requestRight(gDeviceList[0].name).then(hasRight => { - }).catch(error => { - console.info('usb SUB_USB_JS_0180 requestRight error:' + error); - }); - console.info('usb SUB_USB_JS_0180 requestRight end:'); - CheckEmptyUtils.sleep(3000) - } - - var device = JSON.parse(JSON.stringify(gDeviceList[0])); - device.productId = 2 + 10000 - try { - var usbDevicePipe = usb.connectDevice(device) - } catch (err) { - expect(true).assertTrue(); - console.info('usb connectDevice fail:' + err); - } - console.info('usb case connectDevice ret: ' + JSON.stringify(usbDevicePipe) + - ' productId ' + device.productId); - expect(CheckEmptyUtils.isEmpty(usbDevicePipe)).assertFalse(); - var isPipClose = usb.closePipe(usbDevicePipe); - console.info('usb case closePipe ret: ' + isPipClose); - expect(isPipClose).assertEqual(0); - console.info('usb SUB_USB_JS_0180 : PASS'); - }) - - /** - * @tc.number : SUB_USB_JS_0190 - * @tc.name : connectDevice - * @tc.desc : 反向测试 clazz错误参数 打开设备 - */ - it('SUB_USB_JS_0190', 0, function () { - console.info('usb connect_device_11 begin'); - if (portCurrentMode == 1) { - console.info('usb case get_device port is device') - expect(false).assertFalse(); - return - } - if (gDeviceList.length == 0) { - console.info('usb case get_device_list is null') - expect(false).assertTrue(); - return - } - var isRight = usb.hasRight(gDeviceList[0].name); - if (!isRight) { - usb.requestRight(gDeviceList[0].name).then(hasRight => { - }).catch(error => { - console.info('usb SUB_USB_JS_0190 requestRight error:' + error); - }); - console.info('usb SUB_USB_JS_0190 requestRight end:'); - CheckEmptyUtils.sleep(3000) - } - - var device = JSON.parse(JSON.stringify(gDeviceList[0])); - device.clazz = 2 + 10000 - try { - var usbDevicePipe = usb.connectDevice(device) - } catch (err) { - expect(true).assertTrue(); - console.info('usb connectDevice fail:' + err); - } - console.info('usb case connectDevice ret: ' + JSON.stringify(usbDevicePipe) + ' clazz ' + device.clazz); - expect(CheckEmptyUtils.isEmpty(usbDevicePipe)).assertFalse(); - var isPipClose = usb.closePipe(usbDevicePipe); - console.info('usb case closePipe ret: ' + isPipClose); - expect(isPipClose).assertEqual(0); - console.info('usb SUB_USB_JS_0190 : PASS'); - }) - - /** - * @tc.number : SUB_USB_JS_0200 - * @tc.name : connectDevice - * @tc.desc : 反向测试 subclass错误参数 打开设备 - */ - it('SUB_USB_JS_0200', 0, function () { - console.info('usb connect_device_12 begin'); - if (portCurrentMode == 1) { - console.info('usb case get_device port is device') - expect(false).assertFalse(); - return - } - if (gDeviceList.length == 0) { - console.info('usb case get_device_list is null') - expect(false).assertTrue(); - return - } - var isRight = usb.hasRight(gDeviceList[0].name); - if (!isRight) { - usb.requestRight(gDeviceList[0].name).then(hasRight => { - }).catch(error => { - console.info('usb SUB_USB_JS_0200 requestRight error:' + error); - }); - console.info('usb SUB_USB_JS_0200 requestRight end:'); - CheckEmptyUtils.sleep(3000) - } - - var device = JSON.parse(JSON.stringify(gDeviceList[0])); - device.subclass = 2 + 10000 - try { - var usbDevicePipe = usb.connectDevice(device) - } catch (err) { - expect(true).assertTrue(); - console.info('usb connectDevice fail:' + err); - } - console.info('usb case connectDevice ret: ' + JSON.stringify(usbDevicePipe) + ' subclass ' + device.subclass); - expect(CheckEmptyUtils.isEmpty(usbDevicePipe)).assertFalse(); - var isPipClose = usb.closePipe(usbDevicePipe); - console.info('usb case closePipe ret: ' + isPipClose); - expect(isPipClose).assertEqual(0); - console.info('usb SUB_USB_JS_0200 : PASS'); - }) - - /** - * @tc.number : SUB_USB_JS_0210 - * @tc.name : connectDevice - * @tc.desc : 反向测试 protocol错误参数 打开设备 - */ - it('SUB_USB_JS_0210', 0, function () { - console.info('usb connect_device_13 begin'); - if (portCurrentMode == 1) { - console.info('usb case get_device port is device') - expect(false).assertFalse(); - return - } - if (gDeviceList.length == 0) { - console.info('usb case get_device_list is null') - expect(false).assertTrue(); - return - } - var isRight = usb.hasRight(gDeviceList[0].name); - if (!isRight) { - usb.requestRight(gDeviceList[0].name).then(hasRight => { - }).catch(error => { - console.info('usb SUB_USB_JS_0210 requestRight error:' + error); - }); - console.info('usb SUB_USB_JS_0210 requestRight end:'); - CheckEmptyUtils.sleep(3000) - } - - var device = JSON.parse(JSON.stringify(gDeviceList[0])); - device.protocol = 2 + 10000 - try { - var usbDevicePipe = usb.connectDevice(device) - } catch (err) { - expect(true).assertTrue(); - console.info('usb connectDevice fail:' + err); - } - console.info('usb case connectDevice ret: ' + JSON.stringify(usbDevicePipe) + ' protocol ' + device.protocol); - expect(CheckEmptyUtils.isEmpty(usbDevicePipe)).assertFalse(); - var isPipClose = usb.closePipe(usbDevicePipe); - console.info('usb case closePipe ret: ' + isPipClose); - expect(isPipClose).assertEqual(0); - console.info('usb SUB_USB_JS_0210 : PASS'); - }) - - /** - * @tc.number : SUB_USB_JS_0720 - * @tc.name : hasRight - * @tc.desc : 反向测试 给错误设备名字 - */ - it('SUB_USB_JS_0720', 0, function () { - console.info('usb SUB_USB_JS_0720 begin'); - if (portCurrentMode == 1) { - console.info('usb case get_device port is device') - expect(false).assertFalse(); - return - } - if (gDeviceList.length == 0) { - console.info('usb case get_device_list is null') - expect(false).assertTrue(); - return - } - - for (var i = 0; i < gDeviceList.length; i++) { - var deviceName = gDeviceList[i].name - deviceName = deviceName + '$#' - var hasRight = usb.hasRight(deviceName) - console.info('usb has_right ret :' + hasRight); - expect(hasRight == false).assertTrue(); - } - - console.info('usb SUB_USB_JS_0720 : PASS'); - expect(true).assertTrue(); - }) - - /** - * @tc.number : SUB_USB_JS_0730 - * @tc.name : hasRight - * @tc.desc : 反向测试 给设备名字为字母 - */ - it('SUB_USB_JS_0730', 0, function () { - console.info('usb SUB_USB_JS_0730 begin'); - if (portCurrentMode == 1) { - console.info('usb case get_device port is device') - expect(false).assertFalse(); - return - } - if (gDeviceList.length == 0) { - console.info('usb case get_device_list is null') - expect(false).assertTrue(); - return - } - - for (var i = 0; i < gDeviceList.length; i++) { - var deviceName = gDeviceList[i].name - deviceName = deviceName + 'abcdg' - var hasRight = usb.hasRight(deviceName) - console.info('usb hasRight ret :' + hasRight); - expect(hasRight == false).assertTrue(); - } - - console.info('usb SUB_USB_JS_0730 : PASS'); - expect(true).assertTrue(); - }) - - /** - * @tc.number : SUB_USB_JS_0690 - * @tc.name : requestRight - * @tc.desc : 反向测试 错误设备名字 请求权限 - */ - it('SUB_USB_JS_0690', 0, function () { - console.info('usb SUB_USB_JS_0690 begin'); - if (portCurrentMode == 1) { - console.info('usb case get_device port is device') - expect(false).assertFalse(); - return - } - if (gDeviceList.length == 0) { - console.info('usb case get_device_list is null') - expect(false).assertTrue(); - return - } - - for (var i = 0; i < gDeviceList.length; i++) { - var diviceName = gDeviceList[i].name - diviceName = diviceName + '@#' - usb.requestRight(diviceName).then(hasRight => { - console.info('usb request_right ret :' + hasRight); - expect(hasRight).assertFalse(); - console.info('usb SUB_USB_JS_0690 : PASS'); - }).catch(error => { - expect(error).assertFalse(); - console.info('usb SUB_USB_JS_0690 error: ' + error); - }); - } - }) - - /** - * @tc.number : SUB_USB_JS_0700 - * @tc.name : requestRight - * @tc.desc : 反向测试 设备名字为数字 请求权限 - */ - it('SUB_USB_JS_0700', 0, function () { - console.info('usb SUB_USB_JS_0700 begin'); - if (portCurrentMode == 1) { - console.info('usb case get_device port is device') - expect(false).assertFalse(); - return - } - if (gDeviceList.length == 0) { - console.info('usb case get_device_list is null') - expect(false).assertTrue(); - return - } - - for (var i = 0; i < gDeviceList.length; i++) { - var diviceName = gDeviceList[i].name - diviceName = diviceName + '123' - usb.requestRight(diviceName).then(hasRight => { - console.info('usb request_right ret :' + hasRight); - expect(hasRight).assertFalse(); - console.info('usb SUB_USB_JS_0700 : PASS'); - }).catch(error => { - expect(error).assertFalse(); - console.info('usb SUB_USB_JS_0700 error: ' + error); - }); - } - }) -}) +/* + * Copyright (c) 2021-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 usb from '@ohos.usb'; +import CheckEmptyUtils from './CheckEmptyUtils.js'; +import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from '@ohos/hypium' + + +/* usb core functions test */ +export default function UsbCoreJsFunctionsTestEx() { +describe('UsbCoreJsFunctionsTestEx', function () { + + var gDeviceList + var portCurrentMode + + beforeAll(function () { + console.log('*************Usb Unit UsbCoreJsFunctionsTestEx Begin*************'); + var Version = usb.getVersion() + console.info('begin test getversion :' + Version) + // version > 17 host currentMode = 2 device currentMode = 1 + var usbPortList = usb.getPorts() + gDeviceList = usb.getDevices(); + if (usbPortList.length > 0) { + if (gDeviceList.length > 0) { + if (usbPortList[0].status.currentMode == 1) { + usb.setPortRoles(usbPortList[0].id, usb.SOURCE, usb.HOST).then(data => { + portCurrentMode = 2 + console.info('usb case setPortRolesEx return: ' + data); + }).catch(error => { + console.info('usb case setPortRolesEx error : ' + error); + }); + console.log('*************Usb Unit Begin switch to host*************'); + } + } else { + portCurrentMode = 1 + } + } + }) + beforeEach(function () { + console.info('beforeEach: *************Usb Unit Test CaseEx*************'); + }) + afterEach(function () { + console.info('afterEach: *************Usb Unit Test CaseEx*************'); + }) + afterAll(function () { + console.log('*************Usb Unit UsbCoreJsFunctionsTestEx End*************'); + }) + + + /** + * @tc.number : SUB_USB_JS_0100 + * @tc.name : connectDevice + * @tc.desc : 反向测试 错误参数 devAddress 打开设备 + */ + it('SUB_USB_JS_0100', 0, function () { + console.info('usb SUB_USB_JS_0100 begin'); + console.info('*****SUB_USB_JS_0100 portCurrentMode**** ret : ' + portCurrentMode) + if (portCurrentMode == 1) { + console.info('usb case get_device port is device') + expect(false).assertFalse(); + return + } + if (gDeviceList.length == 0) { + console.info('usb case get_device_list is null') + expect(false).assertTrue(); + return + } + var isRight = usb.hasRight(gDeviceList[0].name); + if (!isRight) { + usb.requestRight(gDeviceList[0].name).then(hasRight => { + }).catch(error => { + console.info('usb JS_0100 requestRight error:' + error); + }); + console.info('usb JS_0100 requestRight end:'); + CheckEmptyUtils.sleep(3000) + } + + var device = JSON.parse(JSON.stringify(gDeviceList[0])); + device.devAddress = 2 + 10000 + try { + var usbDevicePipe = usb.connectDevice(device) + } catch (err) { + expect(true).assertTrue(); + console.info('usb connectDevice fail:' + err); + } + console.info('usb case connectDevice ret: ' + JSON.stringify(usbDevicePipe) + + ' devAddress ' + device.devAddress); + expect(CheckEmptyUtils.isEmpty(usbDevicePipe)).assertTrue(); + + console.info('usb SUB_USB_JS_0100 : PASS'); + }) + + /** + * @tc.number : SUB_USB_JS_0110 + * @tc.name : connectDevice + * @tc.desc : 反向测试 busNum错误参数 打开设备 + */ + it('SUB_USB_JS_0110', 0, function () { + console.info('usb SUB_USB_JS_0110 begin'); + if (portCurrentMode == 1) { + console.info('usb case get_device port is device') + expect(false).assertFalse(); + return + } + if (gDeviceList.length == 0) { + console.info('usb case get_device_list is null') + expect(false).assertTrue(); + return + } + var isRight = usb.hasRight(gDeviceList[0].name); + if (!isRight) { + usb.requestRight(gDeviceList[0].name).then(hasRight => { + }).catch(error => { + console.info('usb JS_0110 requestRight error:' + error); + }); + console.info('usb JS_0110 requestRight end:'); + CheckEmptyUtils.sleep(3000) + } + + var device = JSON.parse(JSON.stringify(gDeviceList[0])); + device.busNum = 2 + 1000 + try { + var usbDevicePipe = usb.connectDevice(device) + } catch (err) { + expect(true).assertTrue(); + console.info('usb connectDevice fail:' + err); + } + console.info('usb case connectDevice ret: ' + JSON.stringify(usbDevicePipe) + + ' busNum ' + device.busNum); + expect(CheckEmptyUtils.isEmpty(usbDevicePipe)).assertTrue(); + console.info('usb SUB_USB_JS_0110 : PASS'); + }) + + /** + * @tc.number : SUB_USB_JS_0120 + * @tc.name : connectDevice + * @tc.desc : 反向测试 serial错误参数 打开设备 + */ + it('SUB_USB_JS_0120', 0, function () { + console.info('usb SUB_USB_JS_0120 begin'); + if (portCurrentMode == 1) { + console.info('usb case get_device port is device') + expect(false).assertFalse(); + return + } + if (gDeviceList.length == 0) { + console.info('usb case get_device_list is null') + expect(false).assertTrue(); + return + } + var isRight = usb.hasRight(gDeviceList[0].name); + if (!isRight) { + usb.requestRight(gDeviceList[0].name).then(hasRight => { + }).catch(error => { + console.info('usb JS_0120 requestRight error:' + error); + }); + console.info('usb JS_0120 requestRight end:'); + CheckEmptyUtils.sleep(3000) + } + + var device = JSON.parse(JSON.stringify(gDeviceList[0])); + device.serial = 'asdfsd' + try { + var usbDevicePipe = usb.connectDevice(device) + } catch (err) { + expect(true).assertTrue(); + console.info('usb connectDevice fail:' + err); + } + console.info('usb case connectDevice ret: ' + JSON.stringify(usbDevicePipe) + + ' serial ' + device.serial); + expect(CheckEmptyUtils.isEmpty(usbDevicePipe)).assertFalse(); + var isPipClose = usb.closePipe(usbDevicePipe); + console.info('usb case closePipe ret: ' + isPipClose); + expect(isPipClose).assertEqual(0); + console.info('usb SUB_USB_JS_0120 : PASS'); + }) + + /** + * @tc.number : SUB_USB_JS_0130 + * @tc.name : connectDevice + * @tc.desc : 反向测试 name错误参数 打开设备 + */ + it('SUB_USB_JS_0130', 0, function () { + console.info('usb SUB_USB_JS_0130 begin'); + if (portCurrentMode == 1) { + console.info('usb case get_device port is device') + expect(false).assertFalse(); + return + } + if (gDeviceList.length == 0) { + console.info('usb case get_device_list is null') + expect(false).assertTrue(); + return + } + var isRight = usb.hasRight(gDeviceList[0].name); + if (!isRight) { + usb.requestRight(gDeviceList[0].name).then(hasRight => { + }).catch(error => { + console.info('usb JS_0130 requestRight error:' + error); + }); + console.info('usb JS_0130 requestRight end:'); + CheckEmptyUtils.sleep(3000) + } + + var device = JSON.parse(JSON.stringify(gDeviceList[0])); + device.name = 2 + 10000 + try { + var usbDevicePipe = usb.connectDevice(device) + } catch (err) { + expect(true).assertTrue(); + console.info('usb connectDevice fail:' + err); + } + console.info('usb case connectDevice ret: ' + JSON.stringify(usbDevicePipe) + ' name ' + device.name); + expect(CheckEmptyUtils.isEmpty(usbDevicePipe)).assertFalse(); + var isPipClose = usb.closePipe(usbDevicePipe); + console.info('usb case closePipe ret: ' + isPipClose); + expect(isPipClose).assertEqual(0); + console.info('usb SUB_USB_JS_0130 : PASS'); + }) + + /** + * @tc.number : SUB_USB_JS_0140 + * @tc.name : connectDevice + * @tc.desc : 反向测试 manufacturerName错误参数 打开设备 + */ + it('SUB_USB_JS_0140', 0, function () { + console.info('usb connect_device_06 begin'); + if (portCurrentMode == 1) { + console.info('usb case get_device port is device') + expect(false).assertFalse(); + return + } + if (gDeviceList.length == 0) { + console.info('usb case get_device_list is null') + expect(false).assertTrue(); + return + } + var isRight = usb.hasRight(gDeviceList[0].name); + if (!isRight) { + usb.requestRight(gDeviceList[0].name).then(hasRight => { + }).catch(error => { + console.info('usb JS_0140 requestRight error:' + error); + }); + console.info('usb JS_0140 requestRight end:'); + CheckEmptyUtils.sleep(3000) + } + + var device = JSON.parse(JSON.stringify(gDeviceList[0])); + device.manufacturerName = 2 + 10000 + try { + var usbDevicePipe = usb.connectDevice(device) + } catch (err) { + expect(true).assertTrue(); + console.info('usb connectDevice fail:' + err); + } + console.info('usb case connectDevice ret: ' + JSON.stringify(usbDevicePipe) + + ' manufacturerName ' + device.manufacturerName); + expect(CheckEmptyUtils.isEmpty(usbDevicePipe)).assertFalse(); + var isPipClose = usb.closePipe(usbDevicePipe); + console.info('usb case closePipe ret: ' + isPipClose); + expect(isPipClose).assertEqual(0); + console.info('usb SUB_USB_JS_0140 : PASS'); + }) + + /** + * @tc.number : SUB_USB_JS_0150 + * @tc.name : connectDevice + * @tc.desc : 反向测试 productName错误参数 打开设备 + */ + it('SUB_USB_JS_0150', 0, function () { + console.info('usb SUB_USB_JS_0150 begin'); + if (portCurrentMode == 1) { + console.info('usb case get_device port is device') + expect(false).assertFalse(); + return + } + if (gDeviceList.length == 0) { + console.info('usb case get_device_list is null') + expect(false).assertTrue(); + return + } + var isRight = usb.hasRight(gDeviceList[0].name); + if (!isRight) { + usb.requestRight(gDeviceList[0].name).then(hasRight => { + }).catch(error => { + console.info('usb SUB_USB_JS_0150 requestRight error:' + error); + }); + console.info('usb SUB_USB_JS_0150 requestRight end:'); + CheckEmptyUtils.sleep(3000) + } + + var device = JSON.parse(JSON.stringify(gDeviceList[0])); + device.productName = 'sdfsdfe' + try { + var usbDevicePipe = usb.connectDevice(device) + } catch (err) { + expect(true).assertTrue(); + console.info('usb connectDevice fail:' + err); + } + console.info('usb case connectDevice ret: ' + JSON.stringify(usbDevicePipe) + + ' productName ' + device.productName); + expect(CheckEmptyUtils.isEmpty(usbDevicePipe)).assertFalse(); + var isPipClose = usb.closePipe(usbDevicePipe); + console.info('usb case closePipe ret: ' + isPipClose); + expect(isPipClose).assertEqual(0); + console.info('usb SUB_USB_JS_0150 : PASS'); + }) + + /** + * @tc.number : SUB_USB_JS_0160 + * @tc.name : connectDevice + * @tc.desc : 反向测试 version错误参数 打开设备 + */ + it('SUB_USB_JS_0160', 0, function () { + console.info('usb connect_device_08 begin'); + if (portCurrentMode == 1) { + console.info('usb case get_device port is device') + expect(false).assertFalse(); + return + } + if (gDeviceList.length == 0) { + console.info('usb case get_device_list is null') + expect(false).assertTrue(); + return + } + var isRight = usb.hasRight(gDeviceList[0].name); + if (!isRight) { + usb.requestRight(gDeviceList[0].name).then(hasRight => { + }).catch(error => { + console.info('usb SUB_USB_JS_0160 requestRight error:' + error); + }); + console.info('usb SUB_USB_JS_0160 requestRight end:'); + CheckEmptyUtils.sleep(3000) + } + + var device = JSON.parse(JSON.stringify(gDeviceList[0])); + device.version = 'gwefsdf' + try { + var usbDevicePipe = usb.connectDevice(device) + } catch (err) { + expect(true).assertTrue(); + console.info('usb connectDevice fail:' + err); + } + console.info('usb case connectDevice ret: ' + JSON.stringify(usbDevicePipe) + + ' version ' + device.version); + expect(CheckEmptyUtils.isEmpty(usbDevicePipe)).assertFalse(); + var isPipClose = usb.closePipe(usbDevicePipe); + console.info('usb case closePipe ret: ' + isPipClose); + expect(isPipClose).assertEqual(0); + console.info('usb SUB_USB_JS_0160 : PASS'); + }) + + /** + * @tc.number : SUB_USB_JS_0170 + * @tc.name : connectDevice + * @tc.desc : 反向测试 vendorId错误参数 打开设备 + */ + it('SUB_USB_JS_0170', 0, function () { + console.info('usb connect_device_09 begin'); + if (portCurrentMode == 1) { + console.info('usb case get_device port is device') + expect(false).assertFalse(); + return + } + if (gDeviceList.length == 0) { + console.info('usb case get_device_list is null') + expect(false).assertTrue(); + return + } + var isRight = usb.hasRight(gDeviceList[0].name); + if (!isRight) { + usb.requestRight(gDeviceList[0].name).then(hasRight => { + }).catch(error => { + console.info('usb SUB_USB_JS_0170 requestRight error:' + error); + }); + console.info('usb SUB_USB_JS_0170 requestRight end:'); + CheckEmptyUtils.sleep(3000) + } + + var device = JSON.parse(JSON.stringify(gDeviceList[0])); + device.vendorId = 2 + 10000 + try { + var usbDevicePipe = usb.connectDevice(device) + } catch (err) { + expect(true).assertTrue(); + console.info('usb connectDevice fail:' + err); + } + console.info('usb case connectDevice ret: ' + JSON.stringify(usbDevicePipe) + + ' vendorId ' + device.vendorId); + expect(CheckEmptyUtils.isEmpty(usbDevicePipe)).assertFalse(); + var isPipClose = usb.closePipe(usbDevicePipe); + console.info('usb case closePipe ret: ' + isPipClose); + expect(isPipClose).assertEqual(0); + console.info('usb SUB_USB_JS_0170 : PASS'); + }) + + /** + * @tc.number : SUB_USB_JS_0180 + * @tc.name : connectDevice + * @tc.desc : 反向测试 productId错误参数 打开设备 + */ + it('SUB_USB_JS_0180', 0, function () { + console.info('usb connect_device_10 begin'); + if (portCurrentMode == 1) { + console.info('usb case get_device port is device') + expect(false).assertFalse(); + return + } + if (gDeviceList.length == 0) { + console.info('usb case get_device_list is null') + expect(false).assertTrue(); + return + } + var isRight = usb.hasRight(gDeviceList[0].name); + if (!isRight) { + usb.requestRight(gDeviceList[0].name).then(hasRight => { + }).catch(error => { + console.info('usb SUB_USB_JS_0180 requestRight error:' + error); + }); + console.info('usb SUB_USB_JS_0180 requestRight end:'); + CheckEmptyUtils.sleep(3000) + } + + var device = JSON.parse(JSON.stringify(gDeviceList[0])); + device.productId = 2 + 10000 + try { + var usbDevicePipe = usb.connectDevice(device) + } catch (err) { + expect(true).assertTrue(); + console.info('usb connectDevice fail:' + err); + } + console.info('usb case connectDevice ret: ' + JSON.stringify(usbDevicePipe) + + ' productId ' + device.productId); + expect(CheckEmptyUtils.isEmpty(usbDevicePipe)).assertFalse(); + var isPipClose = usb.closePipe(usbDevicePipe); + console.info('usb case closePipe ret: ' + isPipClose); + expect(isPipClose).assertEqual(0); + console.info('usb SUB_USB_JS_0180 : PASS'); + }) + + /** + * @tc.number : SUB_USB_JS_0190 + * @tc.name : connectDevice + * @tc.desc : 反向测试 clazz错误参数 打开设备 + */ + it('SUB_USB_JS_0190', 0, function () { + console.info('usb connect_device_11 begin'); + if (portCurrentMode == 1) { + console.info('usb case get_device port is device') + expect(false).assertFalse(); + return + } + if (gDeviceList.length == 0) { + console.info('usb case get_device_list is null') + expect(false).assertTrue(); + return + } + var isRight = usb.hasRight(gDeviceList[0].name); + if (!isRight) { + usb.requestRight(gDeviceList[0].name).then(hasRight => { + }).catch(error => { + console.info('usb SUB_USB_JS_0190 requestRight error:' + error); + }); + console.info('usb SUB_USB_JS_0190 requestRight end:'); + CheckEmptyUtils.sleep(3000) + } + + var device = JSON.parse(JSON.stringify(gDeviceList[0])); + device.clazz = 2 + 10000 + try { + var usbDevicePipe = usb.connectDevice(device) + } catch (err) { + expect(true).assertTrue(); + console.info('usb connectDevice fail:' + err); + } + console.info('usb case connectDevice ret: ' + JSON.stringify(usbDevicePipe) + ' clazz ' + device.clazz); + expect(CheckEmptyUtils.isEmpty(usbDevicePipe)).assertFalse(); + var isPipClose = usb.closePipe(usbDevicePipe); + console.info('usb case closePipe ret: ' + isPipClose); + expect(isPipClose).assertEqual(0); + console.info('usb SUB_USB_JS_0190 : PASS'); + }) + + /** + * @tc.number : SUB_USB_JS_0200 + * @tc.name : connectDevice + * @tc.desc : 反向测试 subclass错误参数 打开设备 + */ + it('SUB_USB_JS_0200', 0, function () { + console.info('usb connect_device_12 begin'); + if (portCurrentMode == 1) { + console.info('usb case get_device port is device') + expect(false).assertFalse(); + return + } + if (gDeviceList.length == 0) { + console.info('usb case get_device_list is null') + expect(false).assertTrue(); + return + } + var isRight = usb.hasRight(gDeviceList[0].name); + if (!isRight) { + usb.requestRight(gDeviceList[0].name).then(hasRight => { + }).catch(error => { + console.info('usb SUB_USB_JS_0200 requestRight error:' + error); + }); + console.info('usb SUB_USB_JS_0200 requestRight end:'); + CheckEmptyUtils.sleep(3000) + } + + var device = JSON.parse(JSON.stringify(gDeviceList[0])); + device.subclass = 2 + 10000 + try { + var usbDevicePipe = usb.connectDevice(device) + } catch (err) { + expect(true).assertTrue(); + console.info('usb connectDevice fail:' + err); + } + console.info('usb case connectDevice ret: ' + JSON.stringify(usbDevicePipe) + ' subclass ' + device.subclass); + expect(CheckEmptyUtils.isEmpty(usbDevicePipe)).assertFalse(); + var isPipClose = usb.closePipe(usbDevicePipe); + console.info('usb case closePipe ret: ' + isPipClose); + expect(isPipClose).assertEqual(0); + console.info('usb SUB_USB_JS_0200 : PASS'); + }) + + /** + * @tc.number : SUB_USB_JS_0210 + * @tc.name : connectDevice + * @tc.desc : 反向测试 protocol错误参数 打开设备 + */ + it('SUB_USB_JS_0210', 0, function () { + console.info('usb connect_device_13 begin'); + if (portCurrentMode == 1) { + console.info('usb case get_device port is device') + expect(false).assertFalse(); + return + } + if (gDeviceList.length == 0) { + console.info('usb case get_device_list is null') + expect(false).assertTrue(); + return + } + var isRight = usb.hasRight(gDeviceList[0].name); + if (!isRight) { + usb.requestRight(gDeviceList[0].name).then(hasRight => { + }).catch(error => { + console.info('usb SUB_USB_JS_0210 requestRight error:' + error); + }); + console.info('usb SUB_USB_JS_0210 requestRight end:'); + CheckEmptyUtils.sleep(3000) + } + + var device = JSON.parse(JSON.stringify(gDeviceList[0])); + device.protocol = 2 + 10000 + try { + var usbDevicePipe = usb.connectDevice(device) + } catch (err) { + expect(true).assertTrue(); + console.info('usb connectDevice fail:' + err); + } + console.info('usb case connectDevice ret: ' + JSON.stringify(usbDevicePipe) + ' protocol ' + device.protocol); + expect(CheckEmptyUtils.isEmpty(usbDevicePipe)).assertFalse(); + var isPipClose = usb.closePipe(usbDevicePipe); + console.info('usb case closePipe ret: ' + isPipClose); + expect(isPipClose).assertEqual(0); + console.info('usb SUB_USB_JS_0210 : PASS'); + }) + + /** + * @tc.number : SUB_USB_JS_0720 + * @tc.name : hasRight + * @tc.desc : 反向测试 给错误设备名字 + */ + it('SUB_USB_JS_0720', 0, function () { + console.info('usb SUB_USB_JS_0720 begin'); + if (portCurrentMode == 1) { + console.info('usb case get_device port is device') + expect(false).assertFalse(); + return + } + if (gDeviceList.length == 0) { + console.info('usb case get_device_list is null') + expect(false).assertTrue(); + return + } + + for (var i = 0; i < gDeviceList.length; i++) { + var deviceName = gDeviceList[i].name + deviceName = deviceName + '$#' + var hasRight = usb.hasRight(deviceName) + console.info('usb has_right ret :' + hasRight); + expect(hasRight == false).assertTrue(); + } + + console.info('usb SUB_USB_JS_0720 : PASS'); + expect(true).assertTrue(); + }) + + /** + * @tc.number : SUB_USB_JS_0730 + * @tc.name : hasRight + * @tc.desc : 反向测试 给设备名字为字母 + */ + it('SUB_USB_JS_0730', 0, function () { + console.info('usb SUB_USB_JS_0730 begin'); + if (portCurrentMode == 1) { + console.info('usb case get_device port is device') + expect(false).assertFalse(); + return + } + if (gDeviceList.length == 0) { + console.info('usb case get_device_list is null') + expect(false).assertTrue(); + return + } + + for (var i = 0; i < gDeviceList.length; i++) { + var deviceName = gDeviceList[i].name + deviceName = deviceName + 'abcdg' + var hasRight = usb.hasRight(deviceName) + console.info('usb hasRight ret :' + hasRight); + expect(hasRight == false).assertTrue(); + } + + console.info('usb SUB_USB_JS_0730 : PASS'); + expect(true).assertTrue(); + }) + + /** + * @tc.number : SUB_USB_JS_0690 + * @tc.name : requestRight + * @tc.desc : 反向测试 错误设备名字 请求权限 + */ + it('SUB_USB_JS_0690', 0, function () { + console.info('usb SUB_USB_JS_0690 begin'); + if (portCurrentMode == 1) { + console.info('usb case get_device port is device') + expect(false).assertFalse(); + return + } + if (gDeviceList.length == 0) { + console.info('usb case get_device_list is null') + expect(false).assertTrue(); + return + } + + for (var i = 0; i < gDeviceList.length; i++) { + var diviceName = gDeviceList[i].name + diviceName = diviceName + '@#' + usb.requestRight(diviceName).then(hasRight => { + console.info('usb request_right ret :' + hasRight); + expect(hasRight).assertFalse(); + console.info('usb SUB_USB_JS_0690 : PASS'); + }).catch(error => { + expect(error).assertFalse(); + console.info('usb SUB_USB_JS_0690 error: ' + error); + }); + } + }) + + /** + * @tc.number : SUB_USB_JS_0700 + * @tc.name : requestRight + * @tc.desc : 反向测试 设备名字为数字 请求权限 + */ + it('SUB_USB_JS_0700', 0, function () { + console.info('usb SUB_USB_JS_0700 begin'); + if (portCurrentMode == 1) { + console.info('usb case get_device port is device') + expect(false).assertFalse(); + return + } + if (gDeviceList.length == 0) { + console.info('usb case get_device_list is null') + expect(false).assertTrue(); + return + } + + for (var i = 0; i < gDeviceList.length; i++) { + var diviceName = gDeviceList[i].name + diviceName = diviceName + '123' + usb.requestRight(diviceName).then(hasRight => { + console.info('usb request_right ret :' + hasRight); + expect(hasRight).assertFalse(); + console.info('usb SUB_USB_JS_0700 : PASS'); + }).catch(error => { + expect(error).assertFalse(); + console.info('usb SUB_USB_JS_0700 error: ' + error); + }); + } + }) +}) +} diff --git a/usb/usb_standard/src/main/js/default/test/UsbDevicePipeJsunit.test.js b/usb/usb_standard/src/main/js/test/UsbDevicePipeJsunit.test.js old mode 100755 new mode 100644 similarity index 96% rename from usb/usb_standard/src/main/js/default/test/UsbDevicePipeJsunit.test.js rename to usb/usb_standard/src/main/js/test/UsbDevicePipeJsunit.test.js index baac2b7d5bc396a4be854cfceccd9c0694df9041..a23cbe461a8034e98059c6fabbb8fe370923e54a --- a/usb/usb_standard/src/main/js/default/test/UsbDevicePipeJsunit.test.js +++ b/usb/usb_standard/src/main/js/test/UsbDevicePipeJsunit.test.js @@ -1,631 +1,633 @@ -/* - * Copyright (c) 2021-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 usb from '@ohos.usb'; -import CheckEmptyUtils from './CheckEmptyUtils.js'; -import EventConstants from './EventConstants.js'; -import parameter from '@ohos.systemparameter'; -import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from 'deccjsunit/index' - -/* usb device pipe test */ -describe('UsbDevicePipeJsFunctionsTest', function () { - - var gDeviceList - var gPipe - var portCurrentMode - - beforeAll(function () { - console.log('*************Usb Unit UsbDevicePipeJsFunctionsTest Begin*************'); - var Version = usb.getVersion() - console.info('usb unit begin test getversion :' + Version) - // version > 17 host currentMode = 2 device currentMode = 1 - var usbPortList = usb.getPorts() - gDeviceList = usb.getDevices(); - if (usbPortList.length > 0) { - if (gDeviceList.length > 0) { - if (usbPortList[0].status.currentMode == 1) { - usb.setPortRoles(usbPortList[0].id, usb.SOURCE, usb.HOST).then(data => { - portCurrentMode = 2 - console.info('usb case setPortRoles return: ' + data); - }).catch(error => { - console.info('usb case setPortRoles error : ' + error); - }); - console.log('*************Usb Unit switch to host Begin*************'); - } - } else { - portCurrentMode = 1 - } - } - - gPipe = usb.connectDevice(gDeviceList[0]) - console.info('usb unit connectDevice gPipe ret : ' + JSON.stringify(gPipe)); - }) - - beforeEach(function () { - console.info('beforeEach: *************Usb Unit Test Case*************'); - }) - afterEach(function () { - console.info('afterEach: *************Usb Unit Test Case*************'); - }) - - afterAll(function () { - var isPipClose = usb.closePipe(gPipe) - console.info('usb unit close gPipe ret : ' + isPipClose); - console.log('*************Usb Unit UsbDevicePipeJsFunctionsTest End*************'); - }) - - function findInitPoint(testParam, j) { - var bfind = false - for (var k = 0; k < testParam.config.interfaces[j].endpoints.length; k++) { - var endpoint = testParam.config.interfaces[j].endpoints[k]; - if (endpoint.type == EventConstants.USB_ENDPOINT_XFER_BULK) { - bfind = true - if (endpoint.direction == usb.USB_REQUEST_DIR_TO_DEVICE) { - testParam.maxOutSize = endpoint.maxPacketSize; - testParam.outEndpoint = endpoint; - } else if (endpoint.direction == usb.USB_REQUEST_DIR_FROM_DEVICE) { - testParam.maxInSize = endpoint.maxPacketSize; - testParam.inEndpoint = endpoint - } - } - } - if (bfind) { - testParam.interface = testParam.config.interfaces[j] - return bfind - } - return false - } - - function getFlag(testParam, j) { - if (testParam.config.interfaces[j].endpoints.length == 0) { - return false - } - - if (testParam.config.interfaces[j].clazz != 10 || - testParam.config.interfaces[j].subclass != 0 || - testParam.config.interfaces[j].protocol != 2) { - return false - } - return true - } - - function initPoint(testParam) { - for (var j = 0; j < testParam.config.interfaces.length; j++) { - if (getFlag(testParam, j) == true) { - if (findInitPoint(testParam, j) == true) { - break - } - } - } - } - - // 预制传输相关参数 - function getTransferTestParam() { - var testParam = { - config: null, - device: null, - pip: null, - inEndpoint: null, - interface: null, - outEndpoint: null, - usbRequest: null, - sendData: '', - isClaimed: 0, - maxInSize: 1024, - maxOutSize: 1024 - } - - console.info('usb case gDeviceList.length: ' + gDeviceList.length); - for (var i = 0; i < gDeviceList.length; i++) { - testParam.device = gDeviceList[i] - testParam.config = testParam.device.configs[0] - testParam.pip = gPipe - initPoint(testParam) - } - return testParam - } - - /** - * @tc.number : SUB_USB_JS_0630 - * @tc.name : bulkTransfer - * @tc.desc : 批量传输 收数据 - */ - it('SUB_USB_JS_0630', 0, function () { - console.info('usb SUB_USB_JS_0630 begin'); - console.info('usb SUB_USB_JS_0630 portcurrentMode ret : ' + portCurrentMode) - if (portCurrentMode == 1) { - console.info('usb case get_device port is device') - expect(false).assertFalse(); - return - } - var testParam = getTransferTestParam() - if (testParam.interface == null || testParam.inEndpoint == null) { - expect(false).assertTrue(); - return - } - - testParam.isClaimed = usb.claimInterface(testParam.pip, testParam.interface, true); - expect(testParam.isClaimed).assertEqual(0); - - console.info('usb case readData begin'); - var tmpUint8Array = new Uint8Array(testParam.maxInSize); - usb.bulkTransfer(testParam.pip, testParam.inEndpoint, tmpUint8Array, 5000).then(data => { - console.info('usb case readData tmpUint8Array buffer : ' + CheckEmptyUtils.ab2str(tmpUint8Array)); - console.info('usb case readData ret: ' + data); - console.info('usb case SUB_USB_JS_0630 : PASS'); - expect(data >= 0).assertTrue(); - }).catch(error => { - console.info('usb case readData error : ' + JSON.stringify(error)); - expect(false).assertTrue(); - }); - }) - - /** - * @tc.number : SUB_USB_JS_0640 - * @tc.name : bulkTransfer - * @tc.desc : 批量传输 发数据 - */ - it('SUB_USB_JS_0640', 0, function () { - console.info('usb SUB_USB_JS_0640 begin'); - if (portCurrentMode == 1) { - console.info('usb case get_device port is device') - expect(false).assertFalse(); - return - } - var testParam = getTransferTestParam() - if (testParam.interface == null || testParam.outEndpoint == null) { - expect(false).assertTrue(); - return - } - - testParam.isClaimed = usb.claimInterface(testParam.pip, testParam.interface, true); - expect(testParam.isClaimed).assertEqual(0); - - testParam.sendData = 'send default'; - try { - testParam.sendData = parameter.getSync('test_usb', 'default'); - console.log('usb parameter ' + JSON.stringify(testParam.sendData)); - } catch (e) { - console.log('usb parameter getSync unexpected error: ' + e); - } - - var tmpUint8Array = CheckEmptyUtils.str2ab(testParam.sendData); - usb.bulkTransfer(testParam.pip, testParam.outEndpoint, tmpUint8Array, 5000).then(data => { - console.info('usb case SUB_USB_JS_0640 ret: ' + data); - console.info('usb case SUB_USB_JS_0640 send data: ' + testParam.sendData); - console.info('usb case SUB_USB_JS_0640 : PASS'); - expect(true).assertTrue(); - }).catch(error => { - console.info('usb write error : ' + JSON.stringify(error)); - expect(false).assertTrue(); - }); - - }) - - /** - * @tc.number : SUB_USB_JS_0420 - * @tc.name : claimInterface - * @tc.desc : 获取接口 并释放 - */ - it('SUB_USB_JS_0420', 0, function () { - console.info('usb SUB_USB_JS_0420 begin'); - if (portCurrentMode == 1) { - console.info('usb case get_device port is device') - expect(false).assertFalse(); - return - } - if (gDeviceList.length == 0) { - console.info('usb 01 case get_device_list is null') - expect(gDeviceList.length).assertEqual(-1); - return - } - - if (gDeviceList[0].configs.length == 0) { - console.info('usb 01 case current device.configs.length = 0'); - expect(false).assertTrue(); - return - } - - for (var j = 0; j < gDeviceList[0].configs.length; j++) { - if (gDeviceList[0].configs[j].interfaces.length == 0) { - console.info('usb case current device.configs.interfaces.length = 0'); - } - for (var k = 0; k < gDeviceList[0].configs[j].interfaces.length; k++) { - var isClaim = usb.claimInterface(gPipe, gDeviceList[0].configs[j].interfaces[k], true) - console.info('usb case claimInterface function return: ' + isClaim); - expect(isClaim).assertEqual(0); - if (isClaim == 0) { - isClaim = usb.releaseInterface(gPipe, gDeviceList[0].configs[j].interfaces[k]) - console.info('usb case releaseInterface function return: ' + isClaim); - expect(isClaim).assertEqual(0); - gPipe = usb.connectDevice(gDeviceList[0]) - } - } - } - - console.info('usb SUB_USB_JS_0420 : PASS'); - expect(true).assertTrue(); - }) - - function getTransferParam(iCmd, iReqType, iValue, iIndex) { - var tmpUint8Array = new Uint8Array(512); - var requestCmd = iCmd - var requestType = iReqType - var value = iValue; - var index = iIndex; - var controlParam = { - request: requestCmd, - reqType: requestType, - value: value, - index: index, - data: tmpUint8Array - } - return controlParam - } - - /** - * @tc.number : SUB_USB_JS_0740 - * @tc.name : setConfiguration - * @tc.desc : 设置设备接口 - */ - it('SUB_USB_JS_0740', 0, function () { - console.info('usb SUB_USB_JS_0740 begin'); - if (portCurrentMode == 1) { - console.info('usb case get_device port is device') - expect(false).assertFalse(); - return - } - if (gDeviceList.length == 0) { - console.info('usb case get_device_list is null') - expect(false).assertTrue(); - return - } - - gPipe = usb.connectDevice(gDeviceList[0]) - for (var j = 0; j < gDeviceList[0].configs.length; j++) { - var ret = usb.setConfiguration(gPipe, gDeviceList[0].configs[j]) - console.info('usb case setConfiguration return : ' + ret); - expect(ret).assertEqual(0); - } - - console.info('usb SUB_USB_JS_0740 : PASS'); - expect(true).assertTrue(); - }) - - /** - * @tc.number : SUB_USB_JS_0750 - * @tc.name : setConfiguration - * @tc.desc : 反向测试 设置设备接口 - */ - it('SUB_USB_JS_0750', 0, function () { - console.info('usb SUB_USB_JS_0750 begin'); - if (portCurrentMode == 1) { - console.info('usb case get_device port is device') - expect(false).assertFalse(); - return - } - if (gDeviceList.length == 0) { - console.info('usb case get_device_list is null') - expect(false).assertTrue(); - return - } - - for (var j = 0; j < gDeviceList[0].configs.length; j++) { - var config = JSON.parse(JSON.stringify(gDeviceList[0].configs[j])); - config.id = 255 - var ret = usb.setConfiguration(gPipe, config) - console.info('usb case setConfiguration return : ' + ret); - expect(ret).assertLess(0); - } - - console.info('usb SUB_USB_JS_0750 : PASS'); - }) - - /** - * @tc.number : SUB_USB_JS_0800 - * @tc.name : setInterface - * @tc.desc : 设置设备接口 - */ - it('SUB_USB_JS_0800', 0, function () { - console.info('usb SUB_USB_JS_0800 begin'); - if (portCurrentMode == 1) { - console.info('usb case get_device port is device') - expect(false).assertFalse(); - return - } - if (gDeviceList.length == 0) { - console.info('usb case get_device_list is null') - expect(false).assertTrue(); - return - } - - for (var j = 0; j < gDeviceList[0].configs.length; j++) { - var isClaim = usb.claimInterface(gPipe, gDeviceList[0].configs[j].interfaces[0], true) - expect(isClaim).assertEqual(0) - if (isClaim == 0) { - var ret = usb.setInterface(gPipe, gDeviceList[0].configs[j].interfaces[0]) - expect(ret).assertEqual(0); - console.info('usb case setInterface return : ' + ret); - } - } - - console.info('usb SUB_USB_JS_0800 : PASS'); - expect(true).assertTrue(); - }) - - /** - * @tc.number : SUB_USB_JS_0810 - * @tc.name : setInterface - * @tc.desc : 反向测试 设置设备接口 - */ - it('SUB_USB_JS_0810', 0, function () { - console.info('usb SUB_USB_JS_0810 begin'); - if (portCurrentMode == 1) { - console.info('usb case get_device port is device') - expect(false).assertFalse(); - return - } - if (gDeviceList.length == 0) { - console.info('usb case get_device_list is null') - expect(false).assertTrue() - return - } - - for (var j = 0; j < gDeviceList[0].configs.length; j++) { - var isClaim = usb.claimInterface(gPipe, gDeviceList[0].configs[j].interfaces[0], true) - expect(isClaim).assertEqual(0) - if (isClaim == 0) { - var tmpInterface = JSON.parse(JSON.stringify(gDeviceList[0].configs[j].interfaces[0])); - tmpInterface.id = 234 - var ret = usb.setInterface(gPipe, tmpInterface) - expect(ret).assertLess(0) - console.info('usb case setInterface return : ' + ret) - } - } - - console.info('usb SUB_USB_JS_0810 : PASS'); - expect(true).assertTrue(); - }) - - function callControlTransfer(pip, controlParam, timeout, caseName) { - usb.controlTransfer(pip, controlParam, timeout).then(data => { - console.info('usb controlTransfer ret data : ' + data + ' ' + caseName); - console.info('usb controlTransfer controlParam.data buffer : ' + controlParam.data + ' ' + caseName); - console.info('usb' + caseName + ': PASS'); - expect(true).assertTrue(); - }).catch(error => { - console.info('usb controlTransfer error : ' + JSON.stringify(error)); - console.info('usb' + caseName + ': PASS'); - expect(false).assertTrue(); - }); - } - - /** - * @tc.number : SUB_USB_JS_0540 - * @tc.name : controlTransfer - * @tc.desc : 控制传输 GetDescriptor: cmd 6 reqType 128 value 512 index 0 - */ - it('SUB_USB_JS_0540', 0, function () { - console.info('usb SUB_USB_JS_0540 begin'); - if (portCurrentMode == 1) { - console.info('usb case get_device port is device') - expect(false).assertFalse(); - return - } - var testParam = getTransferTestParam() - if (testParam.inEndpoint == null || testParam.interface == null || testParam.outEndpoint == null) { - expect(false).assertTrue(); - return - } - - var timeout = 5000; - var controlParam = getTransferParam(6, (usb.USB_REQUEST_DIR_FROM_DEVICE << 7) - | (usb.USB_REQUEST_TYPE_STANDARD << 5) | (usb.USB_REQUEST_TARGET_DEVICE & 0x1f), (2 << 8), 0) - callControlTransfer(testParam.pip, controlParam, timeout, 'SUB_USB_JS_0540 GetDescriptor') - }) - - /** - * @tc.number : SUB_USB_JS_0550 - * @tc.name : controlTransfer - * @tc.desc : 控制传输 GetStatus: cmd 0 reqType 128 value 0 index 0 - */ - it('SUB_USB_JS_0550', 0, function () { - console.info('usb SUB_USB_JS_0550 begin'); - if (portCurrentMode == 1) { - console.info('usb case get_device port is device') - expect(false).assertFalse(); - return - } - var testParam = getTransferTestParam() - if (testParam.inEndpoint == null || testParam.interface == null || testParam.outEndpoint == null) { - expect(false).assertTrue(); - return - } - - var timeout = 5000; - var controlParam = getTransferParam(0, (usb.USB_REQUEST_DIR_FROM_DEVICE << 7) - | (usb.USB_REQUEST_TYPE_STANDARD << 5) | (usb.USB_REQUEST_TARGET_DEVICE & 0x1f), 0, 0) - callControlTransfer(testParam.pip, controlParam, timeout, 'SUB_USB_JS_0550 GetStatus') - }) - - /** - * @tc.number : SUB_USB_JS_0560 - * @tc.name : controlTransfer - * @tc.desc : 控制传输 GetConfiguration: cmd 8 reqType 128 value 0 index 0 - */ - it('SUB_USB_JS_0560', 0, function () { - console.info('usb SUB_USB_JS_0560 begin'); - if (portCurrentMode == 1) { - console.info('usb case get_device port is device') - expect(false).assertFalse(); - return - } - var testParam = getTransferTestParam() - if (testParam.inEndpoint == null || testParam.interface == null || testParam.outEndpoint == null) { - expect(false).assertTrue(); - return - } - - var timeout = 5000; - var controlParam = getTransferParam(8, (usb.USB_REQUEST_DIR_FROM_DEVICE << 7) - | (usb.USB_REQUEST_TYPE_STANDARD << 5) | (usb.USB_REQUEST_TARGET_DEVICE & 0x1f), 0, 0) - callControlTransfer(testParam.pip, controlParam, timeout, 'SUB_USB_JS_0560 GetConfiguration') - }) - - /** - * @tc.number : SUB_USB_JS_0570 - * @tc.name : controlTransfer - * @tc.desc : 控制传输 GetInterface: cmd 8 reqType 129 value 0 index 1 - */ - it('SUB_USB_JS_0570', 0, function () { - console.info('usb SUB_USB_JS_0570 begin'); - if (portCurrentMode == 1) { - console.info('usb case get_device port is device') - expect(false).assertFalse(); - return - } - var testParam = getTransferTestParam() - if (testParam.inEndpoint == null || testParam.interface == null || testParam.outEndpoint == null) { - expect(false).assertTrue(); - return - } - - var timeout = 5000; - var controlParam = getTransferParam(10, (usb.USB_REQUEST_DIR_FROM_DEVICE << 7) - | (usb.USB_REQUEST_TYPE_STANDARD << 5) | (usb.USB_REQUEST_TARGET_INTERFACE & 0x1f), 0, 1) - callControlTransfer(testParam.pip, controlParam, timeout, 'SUB_USB_JS_0570 GetInterface') - }) - - /** - * @tc.number : SUB_USB_JS_0580 - * @tc.name : controlTransfer - * @tc.desc : 控制传输 ClearFeature: cmd 1 reqType 0 value 0 index 0 - */ - it('SUB_USB_JS_0580', 0, function () { - console.info('usb SUB_USB_JS_0580 begin'); - if (portCurrentMode == 1) { - console.info('usb case get_device port is device') - expect(false).assertFalse(); - return - } - var testParam = getTransferTestParam() - if (testParam.inEndpoint == null || testParam.interface == null || testParam.outEndpoint == null) { - expect(false).assertTrue(); - return - } - - var timeout = 5000; - var controlParam = getTransferParam(1, (usb.USB_REQUEST_DIR_TO_DEVICE << 7) - | (usb.USB_REQUEST_TYPE_STANDARD << 5) | (usb.USB_REQUEST_TARGET_DEVICE & 0x1f), 0, 0) - callControlTransfer(testParam.pip, controlParam, timeout, 'SUB_USB_JS_0580 ClearFeature') - }) - - /** - * @tc.number : SUB_USB_JS_0590 - * @tc.name : controlTransfer - * @tc.desc : 控制传输 ClearFeature: cmd 255 reqType 129 value 512 index 0 - */ - it('SUB_USB_JS_0590', 0, function () { - console.info('usb SUB_USB_JS_0590 begin'); - if (portCurrentMode == 1) { - console.info('usb case get_device port is device') - expect(false).assertFalse(); - return - } - var testParam = getTransferTestParam() - if (testParam.inEndpoint == null || testParam.interface == null || testParam.outEndpoint == null) { - expect(false).assertTrue(); - return - } - - var timeout = 5000; - var controlParam = getTransferParam(255, (usb.USB_REQUEST_DIR_FROM_DEVICE << 7) - | (usb.USB_REQUEST_TYPE_STANDARD << 5) | (usb.USB_REQUEST_TARGET_INTERFACE & 0x1f), (2 << 8), 0) - callControlTransfer(testParam.pip, controlParam, timeout, 'SUB_USB_JS_0590 ClearFeature') - }) - - /** - * @tc.number : SUB_USB_JS_0600 - * @tc.name : controlTransfer - * @tc.desc : 控制传输 ClearFeature: cmd 255 reqType 3 value 512 index 0 - */ - it('SUB_USB_JS_0600', 0, function () { - console.info('usb SUB_USB_JS_0600 begin'); - if (portCurrentMode == 1) { - console.info('usb case get_device port is device') - expect(false).assertFalse(); - return - } - var testParam = getTransferTestParam() - if (testParam.inEndpoint == null || testParam.interface == null || testParam.outEndpoint == null) { - expect(false).assertTrue(); - return - } - - var timeout = 5000; - var controlParam = getTransferParam(255, (usb.USB_REQUEST_DIR_TO_DEVICE << 7) - | (usb.USB_REQUEST_TYPE_CLASS << 5) | (usb.USB_REQUEST_TARGET_ENDPOINT & 0x1f), (2 << 8), 0) - callControlTransfer(testParam.pip, controlParam, timeout, 'SUB_USB_JS_0600 ClearFeature') - }) - - /** - * @tc.number : SUB_USB_JS_0610 - * @tc.name : controlTransfer - * @tc.desc : 控制传输 ClearFeature: ccmd 255 reqType 5 value 512 index 0 - */ - it('SUB_USB_JS_0610', 0, function () { - console.info('usb SUB_USB_JS_0610 begin'); - if (portCurrentMode == 1) { - console.info('usb case get_device port is device') - expect(false).assertFalse(); - return - } - var testParam = getTransferTestParam() - if (testParam.inEndpoint == null || testParam.interface == null || testParam.outEndpoint == null) { - expect(false).assertTrue(); - return - } - - var timeout = 5000; - var controlParam = getTransferParam(255, (usb.USB_REQUEST_DIR_TO_DEVICE << 7) - | (usb.USB_REQUEST_TYPE_VENDOR << 5) | (usb.USB_REQUEST_TARGET_OTHER & 0x1f), (2 << 8), 0) - callControlTransfer(testParam.pip, controlParam, timeout, 'SUB_USB_JS_0610 ClearFeature') - }) - - /** - * @tc.number : SUB_USB_JS_0620 - * @tc.name : controlTransfer - * @tc.desc : 控制传输 ClearFeature: cmd 255 reqType 4 value 0 index 0 - */ - it('SUB_USB_JS_0620', 0, function () { - console.info('usb SUB_USB_JS_0620 begin'); - if (portCurrentMode == 1) { - console.info('usb case get_device port is device') - expect(false).assertFalse(); - return - } - var testParam = getTransferTestParam() - if (testParam.inEndpoint == null || testParam.interface == null || testParam.outEndpoint == null) { - expect(false).assertTrue(); - return - } - - var timeout = 5000; - var controlParam = getTransferParam(255, (usb.USB_REQUEST_DIR_TO_DEVICE << 7) - | (usb.USB_REQUEST_TYPE_CLASS << 5) | (usb.USB_REQUEST_TARGET_OTHER & 0x1f), 0, 0) - callControlTransfer(testParam.pip, controlParam, timeout, 'SUB_USB_JS_0620 ClearFeature') - }) - -}) +/* + * Copyright (c) 2021-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 usb from '@ohos.usb'; +import CheckEmptyUtils from './CheckEmptyUtils.js'; +import EventConstants from './EventConstants.js'; +import parameter from '@ohos.systemparameter'; +import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from '@ohos/hypium' + +/* usb device pipe test */ +export default function UsbDevicePipeJsFunctionsTest() { +describe('UsbDevicePipeJsFunctionsTest', function () { + + var gDeviceList + var gPipe + var portCurrentMode + + beforeAll(function () { + console.log('*************Usb Unit UsbDevicePipeJsFunctionsTest Begin*************'); + var Version = usb.getVersion() + console.info('usb unit begin test getversion :' + Version) + // version > 17 host currentMode = 2 device currentMode = 1 + var usbPortList = usb.getPorts() + gDeviceList = usb.getDevices(); + if (usbPortList.length > 0) { + if (gDeviceList.length > 0) { + if (usbPortList[0].status.currentMode == 1) { + usb.setPortRoles(usbPortList[0].id, usb.SOURCE, usb.HOST).then(data => { + portCurrentMode = 2 + console.info('usb case setPortRoles return: ' + data); + }).catch(error => { + console.info('usb case setPortRoles error : ' + error); + }); + console.log('*************Usb Unit switch to host Begin*************'); + } + } else { + portCurrentMode = 1 + } + } + + gPipe = usb.connectDevice(gDeviceList[0]) + console.info('usb unit connectDevice gPipe ret : ' + JSON.stringify(gPipe)); + }) + + beforeEach(function () { + console.info('beforeEach: *************Usb Unit Test Case*************'); + }) + afterEach(function () { + console.info('afterEach: *************Usb Unit Test Case*************'); + }) + + afterAll(function () { + var isPipClose = usb.closePipe(gPipe) + console.info('usb unit close gPipe ret : ' + isPipClose); + console.log('*************Usb Unit UsbDevicePipeJsFunctionsTest End*************'); + }) + + function findInitPoint(testParam, j) { + var bfind = false + for (var k = 0; k < testParam.config.interfaces[j].endpoints.length; k++) { + var endpoint = testParam.config.interfaces[j].endpoints[k]; + if (endpoint.type == EventConstants.USB_ENDPOINT_XFER_BULK) { + bfind = true + if (endpoint.direction == usb.USB_REQUEST_DIR_TO_DEVICE) { + testParam.maxOutSize = endpoint.maxPacketSize; + testParam.outEndpoint = endpoint; + } else if (endpoint.direction == usb.USB_REQUEST_DIR_FROM_DEVICE) { + testParam.maxInSize = endpoint.maxPacketSize; + testParam.inEndpoint = endpoint + } + } + } + if (bfind) { + testParam.interface = testParam.config.interfaces[j] + return bfind + } + return false + } + + function getFlag(testParam, j) { + if (testParam.config.interfaces[j].endpoints.length == 0) { + return false + } + + if (testParam.config.interfaces[j].clazz != 10 || + testParam.config.interfaces[j].subclass != 0 || + testParam.config.interfaces[j].protocol != 2) { + return false + } + return true + } + + function initPoint(testParam) { + for (var j = 0; j < testParam.config.interfaces.length; j++) { + if (getFlag(testParam, j) == true) { + if (findInitPoint(testParam, j) == true) { + break + } + } + } + } + + // 预制传输相关参数 + function getTransferTestParam() { + var testParam = { + config: null, + device: null, + pip: null, + inEndpoint: null, + interface: null, + outEndpoint: null, + usbRequest: null, + sendData: '', + isClaimed: 0, + maxInSize: 1024, + maxOutSize: 1024 + } + + console.info('usb case gDeviceList.length: ' + gDeviceList.length); + for (var i = 0; i < gDeviceList.length; i++) { + testParam.device = gDeviceList[i] + testParam.config = testParam.device.configs[0] + testParam.pip = gPipe + initPoint(testParam) + } + return testParam + } + + /** + * @tc.number : SUB_USB_JS_0630 + * @tc.name : bulkTransfer + * @tc.desc : 批量传输 收数据 + */ + it('SUB_USB_JS_0630', 0, function () { + console.info('usb SUB_USB_JS_0630 begin'); + console.info('usb SUB_USB_JS_0630 portcurrentMode ret : ' + portCurrentMode) + if (portCurrentMode == 1) { + console.info('usb case get_device port is device') + expect(false).assertFalse(); + return + } + var testParam = getTransferTestParam() + if (testParam.interface == null || testParam.inEndpoint == null) { + expect(false).assertTrue(); + return + } + + testParam.isClaimed = usb.claimInterface(testParam.pip, testParam.interface, true); + expect(testParam.isClaimed).assertEqual(0); + + console.info('usb case readData begin'); + var tmpUint8Array = new Uint8Array(testParam.maxInSize); + usb.bulkTransfer(testParam.pip, testParam.inEndpoint, tmpUint8Array, 5000).then(data => { + console.info('usb case readData tmpUint8Array buffer : ' + CheckEmptyUtils.ab2str(tmpUint8Array)); + console.info('usb case readData ret: ' + data); + console.info('usb case SUB_USB_JS_0630 : PASS'); + expect(data >= 0).assertTrue(); + }).catch(error => { + console.info('usb case readData error : ' + JSON.stringify(error)); + expect(false).assertTrue(); + }); + }) + + /** + * @tc.number : SUB_USB_JS_0640 + * @tc.name : bulkTransfer + * @tc.desc : 批量传输 发数据 + */ + it('SUB_USB_JS_0640', 0, function () { + console.info('usb SUB_USB_JS_0640 begin'); + if (portCurrentMode == 1) { + console.info('usb case get_device port is device') + expect(false).assertFalse(); + return + } + var testParam = getTransferTestParam() + if (testParam.interface == null || testParam.outEndpoint == null) { + expect(false).assertTrue(); + return + } + + testParam.isClaimed = usb.claimInterface(testParam.pip, testParam.interface, true); + expect(testParam.isClaimed).assertEqual(0); + + testParam.sendData = 'send default'; + try { + testParam.sendData = parameter.getSync('test_usb', 'default'); + console.log('usb parameter ' + JSON.stringify(testParam.sendData)); + } catch (e) { + console.log('usb parameter getSync unexpected error: ' + e); + } + + var tmpUint8Array = CheckEmptyUtils.str2ab(testParam.sendData); + usb.bulkTransfer(testParam.pip, testParam.outEndpoint, tmpUint8Array, 5000).then(data => { + console.info('usb case SUB_USB_JS_0640 ret: ' + data); + console.info('usb case SUB_USB_JS_0640 send data: ' + testParam.sendData); + console.info('usb case SUB_USB_JS_0640 : PASS'); + expect(true).assertTrue(); + }).catch(error => { + console.info('usb write error : ' + JSON.stringify(error)); + expect(false).assertTrue(); + }); + + }) + + /** + * @tc.number : SUB_USB_JS_0420 + * @tc.name : claimInterface + * @tc.desc : 获取接口 并释放 + */ + it('SUB_USB_JS_0420', 0, function () { + console.info('usb SUB_USB_JS_0420 begin'); + if (portCurrentMode == 1) { + console.info('usb case get_device port is device') + expect(false).assertFalse(); + return + } + if (gDeviceList.length == 0) { + console.info('usb 01 case get_device_list is null') + expect(gDeviceList.length).assertEqual(-1); + return + } + + if (gDeviceList[0].configs.length == 0) { + console.info('usb 01 case current device.configs.length = 0'); + expect(false).assertTrue(); + return + } + + for (var j = 0; j < gDeviceList[0].configs.length; j++) { + if (gDeviceList[0].configs[j].interfaces.length == 0) { + console.info('usb case current device.configs.interfaces.length = 0'); + } + for (var k = 0; k < gDeviceList[0].configs[j].interfaces.length; k++) { + var isClaim = usb.claimInterface(gPipe, gDeviceList[0].configs[j].interfaces[k], true) + console.info('usb case claimInterface function return: ' + isClaim); + expect(isClaim).assertEqual(0); + if (isClaim == 0) { + isClaim = usb.releaseInterface(gPipe, gDeviceList[0].configs[j].interfaces[k]) + console.info('usb case releaseInterface function return: ' + isClaim); + expect(isClaim).assertEqual(0); + gPipe = usb.connectDevice(gDeviceList[0]) + } + } + } + + console.info('usb SUB_USB_JS_0420 : PASS'); + expect(true).assertTrue(); + }) + + function getTransferParam(iCmd, iReqType, iValue, iIndex) { + var tmpUint8Array = new Uint8Array(512); + var requestCmd = iCmd + var requestType = iReqType + var value = iValue; + var index = iIndex; + var controlParam = { + request: requestCmd, + reqType: requestType, + value: value, + index: index, + data: tmpUint8Array + } + return controlParam + } + + /** + * @tc.number : SUB_USB_JS_0740 + * @tc.name : setConfiguration + * @tc.desc : 设置设备接口 + */ + it('SUB_USB_JS_0740', 0, function () { + console.info('usb SUB_USB_JS_0740 begin'); + if (portCurrentMode == 1) { + console.info('usb case get_device port is device') + expect(false).assertFalse(); + return + } + if (gDeviceList.length == 0) { + console.info('usb case get_device_list is null') + expect(false).assertTrue(); + return + } + + gPipe = usb.connectDevice(gDeviceList[0]) + for (var j = 0; j < gDeviceList[0].configs.length; j++) { + var ret = usb.setConfiguration(gPipe, gDeviceList[0].configs[j]) + console.info('usb case setConfiguration return : ' + ret); + expect(ret).assertEqual(0); + } + + console.info('usb SUB_USB_JS_0740 : PASS'); + expect(true).assertTrue(); + }) + + /** + * @tc.number : SUB_USB_JS_0750 + * @tc.name : setConfiguration + * @tc.desc : 反向测试 设置设备接口 + */ + it('SUB_USB_JS_0750', 0, function () { + console.info('usb SUB_USB_JS_0750 begin'); + if (portCurrentMode == 1) { + console.info('usb case get_device port is device') + expect(false).assertFalse(); + return + } + if (gDeviceList.length == 0) { + console.info('usb case get_device_list is null') + expect(false).assertTrue(); + return + } + + for (var j = 0; j < gDeviceList[0].configs.length; j++) { + var config = JSON.parse(JSON.stringify(gDeviceList[0].configs[j])); + config.id = 255 + var ret = usb.setConfiguration(gPipe, config) + console.info('usb case setConfiguration return : ' + ret); + expect(ret).assertLess(0); + } + + console.info('usb SUB_USB_JS_0750 : PASS'); + }) + + /** + * @tc.number : SUB_USB_JS_0800 + * @tc.name : setInterface + * @tc.desc : 设置设备接口 + */ + it('SUB_USB_JS_0800', 0, function () { + console.info('usb SUB_USB_JS_0800 begin'); + if (portCurrentMode == 1) { + console.info('usb case get_device port is device') + expect(false).assertFalse(); + return + } + if (gDeviceList.length == 0) { + console.info('usb case get_device_list is null') + expect(false).assertTrue(); + return + } + + for (var j = 0; j < gDeviceList[0].configs.length; j++) { + var isClaim = usb.claimInterface(gPipe, gDeviceList[0].configs[j].interfaces[0], true) + expect(isClaim).assertEqual(0) + if (isClaim == 0) { + var ret = usb.setInterface(gPipe, gDeviceList[0].configs[j].interfaces[0]) + expect(ret).assertEqual(0); + console.info('usb case setInterface return : ' + ret); + } + } + + console.info('usb SUB_USB_JS_0800 : PASS'); + expect(true).assertTrue(); + }) + + /** + * @tc.number : SUB_USB_JS_0810 + * @tc.name : setInterface + * @tc.desc : 反向测试 设置设备接口 + */ + it('SUB_USB_JS_0810', 0, function () { + console.info('usb SUB_USB_JS_0810 begin'); + if (portCurrentMode == 1) { + console.info('usb case get_device port is device') + expect(false).assertFalse(); + return + } + if (gDeviceList.length == 0) { + console.info('usb case get_device_list is null') + expect(false).assertTrue() + return + } + + for (var j = 0; j < gDeviceList[0].configs.length; j++) { + var isClaim = usb.claimInterface(gPipe, gDeviceList[0].configs[j].interfaces[0], true) + expect(isClaim).assertEqual(0) + if (isClaim == 0) { + var tmpInterface = JSON.parse(JSON.stringify(gDeviceList[0].configs[j].interfaces[0])); + tmpInterface.id = 234 + var ret = usb.setInterface(gPipe, tmpInterface) + expect(ret).assertLess(0) + console.info('usb case setInterface return : ' + ret) + } + } + + console.info('usb SUB_USB_JS_0810 : PASS'); + expect(true).assertTrue(); + }) + + function callControlTransfer(pip, controlParam, timeout, caseName) { + usb.controlTransfer(pip, controlParam, timeout).then(data => { + console.info('usb controlTransfer ret data : ' + data + ' ' + caseName); + console.info('usb controlTransfer controlParam.data buffer : ' + controlParam.data + ' ' + caseName); + console.info('usb' + caseName + ': PASS'); + expect(true).assertTrue(); + }).catch(error => { + console.info('usb controlTransfer error : ' + JSON.stringify(error)); + console.info('usb' + caseName + ': PASS'); + expect(false).assertTrue(); + }); + } + + /** + * @tc.number : SUB_USB_JS_0540 + * @tc.name : controlTransfer + * @tc.desc : 控制传输 GetDescriptor: cmd 6 reqType 128 value 512 index 0 + */ + it('SUB_USB_JS_0540', 0, function () { + console.info('usb SUB_USB_JS_0540 begin'); + if (portCurrentMode == 1) { + console.info('usb case get_device port is device') + expect(false).assertFalse(); + return + } + var testParam = getTransferTestParam() + if (testParam.inEndpoint == null || testParam.interface == null || testParam.outEndpoint == null) { + expect(false).assertTrue(); + return + } + + var timeout = 5000; + var controlParam = getTransferParam(6, (usb.USB_REQUEST_DIR_FROM_DEVICE << 7) + | (usb.USB_REQUEST_TYPE_STANDARD << 5) | (usb.USB_REQUEST_TARGET_DEVICE & 0x1f), (2 << 8), 0) + callControlTransfer(testParam.pip, controlParam, timeout, 'SUB_USB_JS_0540 GetDescriptor') + }) + + /** + * @tc.number : SUB_USB_JS_0550 + * @tc.name : controlTransfer + * @tc.desc : 控制传输 GetStatus: cmd 0 reqType 128 value 0 index 0 + */ + it('SUB_USB_JS_0550', 0, function () { + console.info('usb SUB_USB_JS_0550 begin'); + if (portCurrentMode == 1) { + console.info('usb case get_device port is device') + expect(false).assertFalse(); + return + } + var testParam = getTransferTestParam() + if (testParam.inEndpoint == null || testParam.interface == null || testParam.outEndpoint == null) { + expect(false).assertTrue(); + return + } + + var timeout = 5000; + var controlParam = getTransferParam(0, (usb.USB_REQUEST_DIR_FROM_DEVICE << 7) + | (usb.USB_REQUEST_TYPE_STANDARD << 5) | (usb.USB_REQUEST_TARGET_DEVICE & 0x1f), 0, 0) + callControlTransfer(testParam.pip, controlParam, timeout, 'SUB_USB_JS_0550 GetStatus') + }) + + /** + * @tc.number : SUB_USB_JS_0560 + * @tc.name : controlTransfer + * @tc.desc : 控制传输 GetConfiguration: cmd 8 reqType 128 value 0 index 0 + */ + it('SUB_USB_JS_0560', 0, function () { + console.info('usb SUB_USB_JS_0560 begin'); + if (portCurrentMode == 1) { + console.info('usb case get_device port is device') + expect(false).assertFalse(); + return + } + var testParam = getTransferTestParam() + if (testParam.inEndpoint == null || testParam.interface == null || testParam.outEndpoint == null) { + expect(false).assertTrue(); + return + } + + var timeout = 5000; + var controlParam = getTransferParam(8, (usb.USB_REQUEST_DIR_FROM_DEVICE << 7) + | (usb.USB_REQUEST_TYPE_STANDARD << 5) | (usb.USB_REQUEST_TARGET_DEVICE & 0x1f), 0, 0) + callControlTransfer(testParam.pip, controlParam, timeout, 'SUB_USB_JS_0560 GetConfiguration') + }) + + /** + * @tc.number : SUB_USB_JS_0570 + * @tc.name : controlTransfer + * @tc.desc : 控制传输 GetInterface: cmd 8 reqType 129 value 0 index 1 + */ + it('SUB_USB_JS_0570', 0, function () { + console.info('usb SUB_USB_JS_0570 begin'); + if (portCurrentMode == 1) { + console.info('usb case get_device port is device') + expect(false).assertFalse(); + return + } + var testParam = getTransferTestParam() + if (testParam.inEndpoint == null || testParam.interface == null || testParam.outEndpoint == null) { + expect(false).assertTrue(); + return + } + + var timeout = 5000; + var controlParam = getTransferParam(10, (usb.USB_REQUEST_DIR_FROM_DEVICE << 7) + | (usb.USB_REQUEST_TYPE_STANDARD << 5) | (usb.USB_REQUEST_TARGET_INTERFACE & 0x1f), 0, 1) + callControlTransfer(testParam.pip, controlParam, timeout, 'SUB_USB_JS_0570 GetInterface') + }) + + /** + * @tc.number : SUB_USB_JS_0580 + * @tc.name : controlTransfer + * @tc.desc : 控制传输 ClearFeature: cmd 1 reqType 0 value 0 index 0 + */ + it('SUB_USB_JS_0580', 0, function () { + console.info('usb SUB_USB_JS_0580 begin'); + if (portCurrentMode == 1) { + console.info('usb case get_device port is device') + expect(false).assertFalse(); + return + } + var testParam = getTransferTestParam() + if (testParam.inEndpoint == null || testParam.interface == null || testParam.outEndpoint == null) { + expect(false).assertTrue(); + return + } + + var timeout = 5000; + var controlParam = getTransferParam(1, (usb.USB_REQUEST_DIR_TO_DEVICE << 7) + | (usb.USB_REQUEST_TYPE_STANDARD << 5) | (usb.USB_REQUEST_TARGET_DEVICE & 0x1f), 0, 0) + callControlTransfer(testParam.pip, controlParam, timeout, 'SUB_USB_JS_0580 ClearFeature') + }) + + /** + * @tc.number : SUB_USB_JS_0590 + * @tc.name : controlTransfer + * @tc.desc : 控制传输 ClearFeature: cmd 255 reqType 129 value 512 index 0 + */ + it('SUB_USB_JS_0590', 0, function () { + console.info('usb SUB_USB_JS_0590 begin'); + if (portCurrentMode == 1) { + console.info('usb case get_device port is device') + expect(false).assertFalse(); + return + } + var testParam = getTransferTestParam() + if (testParam.inEndpoint == null || testParam.interface == null || testParam.outEndpoint == null) { + expect(false).assertTrue(); + return + } + + var timeout = 5000; + var controlParam = getTransferParam(255, (usb.USB_REQUEST_DIR_FROM_DEVICE << 7) + | (usb.USB_REQUEST_TYPE_STANDARD << 5) | (usb.USB_REQUEST_TARGET_INTERFACE & 0x1f), (2 << 8), 0) + callControlTransfer(testParam.pip, controlParam, timeout, 'SUB_USB_JS_0590 ClearFeature') + }) + + /** + * @tc.number : SUB_USB_JS_0600 + * @tc.name : controlTransfer + * @tc.desc : 控制传输 ClearFeature: cmd 255 reqType 3 value 512 index 0 + */ + it('SUB_USB_JS_0600', 0, function () { + console.info('usb SUB_USB_JS_0600 begin'); + if (portCurrentMode == 1) { + console.info('usb case get_device port is device') + expect(false).assertFalse(); + return + } + var testParam = getTransferTestParam() + if (testParam.inEndpoint == null || testParam.interface == null || testParam.outEndpoint == null) { + expect(false).assertTrue(); + return + } + + var timeout = 5000; + var controlParam = getTransferParam(255, (usb.USB_REQUEST_DIR_TO_DEVICE << 7) + | (usb.USB_REQUEST_TYPE_CLASS << 5) | (usb.USB_REQUEST_TARGET_ENDPOINT & 0x1f), (2 << 8), 0) + callControlTransfer(testParam.pip, controlParam, timeout, 'SUB_USB_JS_0600 ClearFeature') + }) + + /** + * @tc.number : SUB_USB_JS_0610 + * @tc.name : controlTransfer + * @tc.desc : 控制传输 ClearFeature: ccmd 255 reqType 5 value 512 index 0 + */ + it('SUB_USB_JS_0610', 0, function () { + console.info('usb SUB_USB_JS_0610 begin'); + if (portCurrentMode == 1) { + console.info('usb case get_device port is device') + expect(false).assertFalse(); + return + } + var testParam = getTransferTestParam() + if (testParam.inEndpoint == null || testParam.interface == null || testParam.outEndpoint == null) { + expect(false).assertTrue(); + return + } + + var timeout = 5000; + var controlParam = getTransferParam(255, (usb.USB_REQUEST_DIR_TO_DEVICE << 7) + | (usb.USB_REQUEST_TYPE_VENDOR << 5) | (usb.USB_REQUEST_TARGET_OTHER & 0x1f), (2 << 8), 0) + callControlTransfer(testParam.pip, controlParam, timeout, 'SUB_USB_JS_0610 ClearFeature') + }) + + /** + * @tc.number : SUB_USB_JS_0620 + * @tc.name : controlTransfer + * @tc.desc : 控制传输 ClearFeature: cmd 255 reqType 4 value 0 index 0 + */ + it('SUB_USB_JS_0620', 0, function () { + console.info('usb SUB_USB_JS_0620 begin'); + if (portCurrentMode == 1) { + console.info('usb case get_device port is device') + expect(false).assertFalse(); + return + } + var testParam = getTransferTestParam() + if (testParam.inEndpoint == null || testParam.interface == null || testParam.outEndpoint == null) { + expect(false).assertTrue(); + return + } + + var timeout = 5000; + var controlParam = getTransferParam(255, (usb.USB_REQUEST_DIR_TO_DEVICE << 7) + | (usb.USB_REQUEST_TYPE_CLASS << 5) | (usb.USB_REQUEST_TARGET_OTHER & 0x1f), 0, 0) + callControlTransfer(testParam.pip, controlParam, timeout, 'SUB_USB_JS_0620 ClearFeature') + }) + +}) +} diff --git a/usb/usb_standard/src/main/js/default/test/UsbDevicePipeJsunitEx.test.js b/usb/usb_standard/src/main/js/test/UsbDevicePipeJsunitEx.test.js old mode 100755 new mode 100644 similarity index 96% rename from usb/usb_standard/src/main/js/default/test/UsbDevicePipeJsunitEx.test.js rename to usb/usb_standard/src/main/js/test/UsbDevicePipeJsunitEx.test.js index 5ef9295321d75d4735364bd2e0d01e7aea8a68bd..1e963c6d1ca7992977f066862a85d50762a8287b --- a/usb/usb_standard/src/main/js/default/test/UsbDevicePipeJsunitEx.test.js +++ b/usb/usb_standard/src/main/js/test/UsbDevicePipeJsunitEx.test.js @@ -1,908 +1,910 @@ -/* - * Copyright (c) 2021-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 usb from '@ohos.usb'; -import CheckEmptyUtils from './CheckEmptyUtils.js'; -import EventConstants from './EventConstants.js'; -import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from 'deccjsunit/index' - -/* usb device pipe test */ -describe('UsbDevicePipeJsFunctionsTestEx', function () { - - var gDeviceList - var gPipe - var portCurrentMode - - beforeAll(function () { - console.log('*************Usb Unit UsbDevicePipeJsFunctionsTestEx Begin*************'); - var Version = usb.getVersion() - console.info('usb unit begin test getversion :' + Version) - - // version > 17 host currentMode = 2 device currentMode = 1 - var usbPortList = usb.getPorts() - gDeviceList = usb.getDevices(); - if (usbPortList.length > 0) { - if (gDeviceList.length > 0) { - if (usbPortList[0].status.currentMode == 1) { - usb.setPortRoles(usbPortList[0].id, usb.SOURCE, usb.HOST).then(data => { - portCurrentMode = 2 - console.info('usb case setPortRoles return: ' + data); - }).catch(error => { - console.info('usb case setPortRoles error : ' + error); - }); - - console.log('*************Usb Unit switch to host Ex Begin*************'); - CheckEmptyUtils.sleep(3000) - } - } else { - portCurrentMode = 1 - } - } - - gPipe = usb.connectDevice(gDeviceList[0]) - console.info('usb unit connectDevice gPipe ret : ' + JSON.stringify(gPipe)); - }) - beforeEach(function () { - console.info('beforeEach: *************Usb Unit Test Ex Case*************'); - }) - afterEach(function () { - console.info('afterEach: *************Usb Unit Test Ex Case*************'); - }) - afterAll(function () { - var isPipClose = usb.closePipe(gPipe) - console.info('usb unit close gPipe ret : ' + isPipClose); - console.log('*************Usb Unit UsbDevicePipeJsFunctionsTestEx End*************'); - }) - - function findInitPoint(testParam, j) { - var bfind = false - for (var k = 0; k < testParam.config.interfaces[j].endpoints.length; k++) { - var endpoint = testParam.config.interfaces[j].endpoints[k]; - if (endpoint.type == EventConstants.USB_ENDPOINT_XFER_BULK) { - - bfind = true - if (endpoint.direction == usb.USB_REQUEST_DIR_TO_DEVICE) { - testParam.outEndpoint = endpoint; - testParam.maxOutSize = endpoint.maxPacketSize; - } else if (endpoint.direction == usb.USB_REQUEST_DIR_FROM_DEVICE) { - testParam.inEndpoint = endpoint - testParam.maxInSize = endpoint.maxPacketSize; - } - } - } - if (bfind) { - testParam.interface = testParam.config.interfaces[j] - return true - } - return false - } - - function getFlag(testParam, j) { - if (testParam.config.interfaces[j].clazz != 10 || - testParam.config.interfaces[j].subclass != 0 || - testParam.config.interfaces[j].protocol != 2) { - return false - } - - if (testParam.config.interfaces[j].endpoints.length == 0) { - return false - } - - return true - } - - function initPoint(testParam) { - for (var j = 0; j < testParam.config.interfaces.length; j++) { - if (getFlag(testParam, j)) { - if (findInitPoint(testParam, j)) { - break - } - } - } - } - - // 预制传输相关参数 - function getTransferTestParam() { - var testParam = { - device: null, - config: null, - pip: null, - inEndpoint: null, - outEndpoint: null, - interface: null, - usbRequest: null, - sendData: '', - isClaimed: 0, - maxInSize: 1024, - maxOutSize: 1024 - } - - console.info('usb case gDeviceList.length: ' + gDeviceList.length); - for (var i = 0; i < gDeviceList.length; i++) { - testParam.device = gDeviceList[i] - testParam.config = testParam.device.configs[0] - testParam.pip = gPipe - initPoint(testParam) - } - return testParam - } - - /** - * @tc.number : SUB_USB_JS_0650 - * @tc.name : bulkTransfer - * @tc.desc : 反向测试 批量传输 发数据 修改 outEndpoint.address = 123 - */ - it('SUB_USB_JS_0650', 0, function () { - console.info('usb SUB_USB_JS_0650 begin'); - if (portCurrentMode == 1) { - console.info('usb case get_device port is device') - expect(false).assertFalse(); - return - } - var testParam = getTransferTestParam() - if (testParam.interface == null || testParam.outEndpoint == null) { - expect(false).assertTrue(); - return - } - - testParam.isClaimed = usb.claimInterface(testParam.pip, testParam.interface, true); - expect(testParam.isClaimed).assertEqual(0); - - testParam.sendData = 'send time 13213213 wzy 03'; - var tmpUint8Array = CheckEmptyUtils.str2ab(testParam.sendData); - var TmpTestParam = testParam - TmpTestParam.outEndpoint.address = 123 - usb.bulkTransfer(TmpTestParam.pip, TmpTestParam.outEndpoint, tmpUint8Array, 5000).then(data => { - console.info('usb case SUB_USB_JS_0650 ret: ' + data); - console.info('usb case SUB_USB_JS_0650 : PASS'); - expect(data).assertEqual(-1); - }).catch(error => { - console.info('usb 03 write error : ' + JSON.stringify(error)); - expect(false).assertFalse(); - console.info('usb case SUB_USB_JS_0650 : PASS'); - }); - }) - - /** - * @tc.number : SUB_USB_JS_0660 - * @tc.name : bulkTransfer - * @tc.desc : 反向测试 批量传输 发数据 修改 outEndpoint.number = 123 - */ - it('SUB_USB_JS_0660', 0, function () { - console.info('usb SUB_USB_JS_0660 begin'); - if (portCurrentMode == 1) { - console.info('usb case get_device port is device') - expect(false).assertFalse(); - return - } - var testParam = getTransferTestParam() - if (testParam.interface == null || testParam.outEndpoint == null) { - expect(false).assertTrue(); - return - } - - testParam.isClaimed = usb.claimInterface(testParam.pip, testParam.interface, true); - expect(testParam.isClaimed).assertEqual(0); - - testParam.sendData = 'send time 13213213 wzy 04'; - var tmpUint8Array = CheckEmptyUtils.str2ab(testParam.sendData); - var TmpTestParam = testParam - TmpTestParam.outEndpoint.number = 123 - usb.bulkTransfer(TmpTestParam.pip, TmpTestParam.outEndpoint, tmpUint8Array, 5000).then(data => { - console.info('usb case SUB_USB_JS_0660 ret: ' + data); - console.info('usb case SUB_USB_JS_0660 : PASS'); - expect(data).assertEqual(-1); - }).catch(error => { - console.info('usb 04 write error : ' + JSON.stringify(error)); - expect(false).assertFalse(); - console.info('usb case SUB_USB_JS_0660 : PASS'); - }); - }) - - /** - * @tc.number : SUB_USB_JS_0670 - * @tc.name : bulkTransfer - * @tc.desc : 反向测试 批量传输 发数据 修改 outEndpoint.type = 123 - */ - it('SUB_USB_JS_0670', 0, function () { - console.info('usb SUB_USB_JS_0670 begin'); - if (portCurrentMode == 1) { - console.info('usb case get_device port is device') - expect(false).assertFalse(); - return - } - var testParam = getTransferTestParam() - if (testParam.interface == null || testParam.outEndpoint == null) { - expect(false).assertTrue(); - return - } - - testParam.isClaimed = usb.claimInterface(testParam.pip, testParam.interface, true); - expect(testParam.isClaimed).assertEqual(0); - - testParam.sendData = 'send time 13213213 wzy 05'; - var tmpUint8Array = CheckEmptyUtils.str2ab(testParam.sendData); - var TmpTestParam = testParam - TmpTestParam.outEndpoint.type = 123 - usb.bulkTransfer(TmpTestParam.pip, TmpTestParam.outEndpoint, tmpUint8Array, 5000).then(data => { - console.info('usb case SUB_USB_JS_0670 ret: ' + data); - console.info('usb case SUB_USB_JS_0670 : PASS'); - expect(data).assertEqual(-1); - }).catch(error => { - console.info('usb 05 write error : ' + JSON.stringify(error)); - expect(false).assertFalse(); - console.info('usb case SUB_USB_JS_0670 : PASS'); - }); - }) - - /** - * @tc.number : SUB_USB_JS_0430 - * @tc.name : claimInterface - * @tc.desc : 反向测试 USBInterface传入异常id 获取接口 失败 - */ - it('SUB_USB_JS_0430', 0, function () { - console.info('usb SUB_USB_JS_0430 begin'); - if (portCurrentMode == 1) { - console.info('usb case get_device port is device') - expect(false).assertFalse(); - return - } - if (gDeviceList.length == 0) { - console.info('usb case get_device_list is null') - expect(false).assertTrue(); - return - } - - if (gDeviceList[0].configs.length == 0) { - console.info('usb case SUB_USB_JS_0430 current device.configs.length = 0'); - expect(false).assertTrue(); - return - } - - for (var j = 0; j < gDeviceList[0].configs.length; j++) { - if (gDeviceList[0].configs[j].interfaces.length == 0) { - console.info('usb case SUB_USB_JS_0430 current device.configs.interfaces.length = 0'); - } - for (var k = 0; k < gDeviceList[0].configs[j].interfaces.length; k++) { - var TmpInterface = gDeviceList[0].configs[j].interfaces[k] - TmpInterface.id = 123 - var isClaim = usb.claimInterface(gPipe, TmpInterface, true) - console.info('usb case claimInterface function return: ' + isClaim); - expect(isClaim).assertLess(0); - } - } - - console.info('usb SUB_USB_JS_0430 : PASS'); - expect(true).assertTrue(); - }) - - /** - * @tc.number : SUB_USB_JS_0440 - * @tc.name : claimInterface - * @tc.desc : 反向测试 USBInterface传入异常protocol 获取接口 失败 - */ - it('SUB_USB_JS_0440', 0, function () { - console.info('usb SUB_USB_JS_0440 begin'); - if (portCurrentMode == 1) { - console.info('usb case get_device port is device') - expect(false).assertFalse(); - return - } - if (gDeviceList.length == 0) { - console.info('usb case get_device_list is null') - expect(false).assertTrue(); - return - } - - if (gDeviceList[0].configs.length == 0) { - console.info('usb case SUB_USB_JS_0440 current device.configs.length = 0'); - expect(false).assertTrue(); - return - } - - for (var j = 0; j < gDeviceList[0].configs.length; j++) { - if (gDeviceList[0].configs[j].interfaces.length == 0) { - console.info('usb case SUB_USB_JS_0440 current device.configs.interfaces.length = 0'); - } - for (var k = 0; k < gDeviceList[0].configs[j].interfaces.length; k++) { - var TmpInterface = gDeviceList[0].configs[j].interfaces[k] - TmpInterface.protocol = 120 - var isClaim = usb.claimInterface(gPipe, TmpInterface, true) - console.info('usb case claimInterface function return: ' + isClaim); - expect(isClaim).assertLess(0); - } - } - - console.info('usb SUB_USB_JS_0440 : PASS'); - expect(true).assertTrue(); - }) - - /** - * @tc.number : SUB_USB_JS_0450 - * @tc.name : claimInterface - * @tc.desc : 反向测试 USBInterface传入异常clazz 获取接口 失败 - */ - it('SUB_USB_JS_0450', 0, function () { - console.info('usb SUB_USB_JS_0450 begin'); - if (portCurrentMode == 1) { - console.info('usb case get_device port is device') - expect(false).assertFalse(); - return - } - if (gDeviceList.length == 0) { - console.info('usb case get_device_list is null') - expect(false).assertTrue(); - return - } - - if (gDeviceList[0].configs.length == 0) { - console.info('usb case SUB_USB_JS_0450 current device.configs.length = 0'); - expect(false).assertTrue(); - return - } - - for (var j = 0; j < gDeviceList[0].configs.length; j++) { - if (gDeviceList[0].configs[j].interfaces.length == 0) { - console.info('usb case SUB_USB_JS_0450 current device.configs.interfaces.length = 0'); - } - for (var k = 0; k < gDeviceList[0].configs[j].interfaces.length; k++) { - var TmpInterface = gDeviceList[0].configs[j].interfaces[k] - TmpInterface.clazz = 784 - var isClaim = usb.claimInterface(gPipe, TmpInterface, true) - console.info('usb case claimInterface function return: ' + isClaim); - expect(isClaim).assertLess(0); - } - } - - console.info('usb SUB_USB_JS_0450 : PASS'); - expect(true).assertTrue(); - }) - - /** - * @tc.number : SUB_USB_JS_0460 - * @tc.name : claimInterface - * @tc.desc : 反向测试 USBInterface传入异常name 获取接口 失败 - */ - it('SUB_USB_JS_0460', 0, function () { - console.info('usb SUB_USB_JS_0460 begin'); - if (portCurrentMode == 1) { - console.info('usb case get_device port is device') - expect(false).assertFalse(); - return - } - if (gDeviceList.length == 0) { - console.info('usb case get_device_list is null') - expect(false).assertTrue(); - return - } - - if (gDeviceList[0].configs.length == 0) { - console.info('usb case SUB_USB_JS_0460 current device.configs.length = 0'); - expect(false).assertTrue(); - return - } - - for (var j = 0; j < gDeviceList[0].configs.length; j++) { - if (gDeviceList[0].configs[j].interfaces.length == 0) { - console.info('usb case SUB_USB_JS_0460 current device.configs.interfaces.length = 0'); - } - for (var k = 0; k < gDeviceList[0].configs[j].interfaces.length; k++) { - var TmpInterface = gDeviceList[0].configs[j].interfaces[k] - TmpInterface.name = '123sdf' - var isClaim = usb.claimInterface(gPipe, TmpInterface, true) - console.info('usb case claimInterface function return: ' + isClaim); - expect(isClaim).assertLess(0); - } - } - - console.info('usb SUB_USB_JS_0460 : PASS'); - expect(true).assertTrue(); - }) - - /** - * @tc.number : SUB_USB_JS_0470 - * @tc.name : claimInterface - * @tc.desc : 反向测试 USBInterface传入异常subClass 获取接口 失败 - */ - it('SUB_USB_JS_0470', 0, function () { - console.info('usb SUB_USB_JS_0470 begin'); - if (portCurrentMode == 1) { - console.info('usb case get_device port is device') - expect(false).assertFalse(); - return - } - if (gDeviceList.length == 0) { - console.info('usb case get_device_list is null') - expect(false).assertTrue(); - return - } - - if (gDeviceList[0].configs.length == 0) { - console.info('usb case SUB_USB_JS_0470 current device.configs.length = 0'); - expect(false).assertTrue(); - return - } - - for (var j = 0; j < gDeviceList[0].configs.length; j++) { - if (gDeviceList[0].configs[j].interfaces.length == 0) { - console.info('usb case SUB_USB_JS_0470 current device.configs.interfaces.length = 0'); - } - for (var k = 0; k < gDeviceList[0].configs[j].interfaces.length; k++) { - var TmpInterface = gDeviceList[0].configs[j].interfaces[k] - TmpInterface.subClass = 1210 - var isClaim = usb.claimInterface(gPipe, TmpInterface, true) - console.info('usb case claimInterface function return: ' + isClaim); - expect(isClaim).assertLess(0); - } - } - - console.info('usb SUB_USB_JS_0470 : PASS'); - expect(true).assertTrue(); - }) - - /** - * @tc.number : SUB_USB_JS_0280 - * @tc.name : releaseInterface - * @tc.desc : 反向测试 获取接口 release传入Interface的错误ID 并释放 - */ - it('SUB_USB_JS_0280', 0, function () { - console.info('usb SUB_USB_JS_0280 begin'); - if (portCurrentMode == 1) { - console.info('usb case get_device port is device') - expect(false).assertFalse(); - return - } - if (gDeviceList.length == 0) { - console.info('usb case get_device_list is null') - expect(false).assertTrue(); - return - } - - if (gDeviceList[0].configs.length == 0) { - console.info('usb SUB_USB_JS_0280 case current device.configs.length = 0'); - expect(false).assertTrue(); - return - } - gPipe = usb.connectDevice(gDeviceList[0]) - for (var j = 0; j < gDeviceList[0].configs.length; j++) { - if (gDeviceList[0].configs[j].interfaces.length == 0) { - console.info('usb SUB_USB_JS_0280 case current device.configs.interfaces.length = 0'); - } - for (var k = 0; k < gDeviceList[0].configs[j].interfaces.length; k++) { - var tmpInterface = gDeviceList[0].configs[j].interfaces[k] - tmpInterface.id = 134 - var isClaim = usb.releaseInterface(gPipe, tmpInterface) - console.info('usb case releaseInterface function return: ' + isClaim); - expect(isClaim).assertLess(0); - } - } - - console.info('usb SUB_USB_JS_0280 : PASS'); - expect(true).assertTrue(); - }) - - /** - * @tc.number : SUB_USB_JS_0290 - * @tc.name : releaseInterface - * @tc.desc : 反向测试 获取接口 release传入Interface的错误name 并释放 - */ - it('SUB_USB_JS_0290', 0, function () { - console.info('usb SUB_USB_JS_0290 begin'); - if (portCurrentMode == 1) { - console.info('usb case get_device port is device') - expect(false).assertFalse(); - return - } - if (gDeviceList.length == 0) { - console.info('usb case get_device_list is null') - expect(false).assertTrue(); - return - } - - if (gDeviceList[0].configs.length == 0) { - console.info('usb SUB_USB_JS_0290 case current device.configs.length = 0'); - expect(false).assertTrue(); - return - } - gPipe = usb.connectDevice(gDeviceList[0]) - for (var j = 0; j < gDeviceList[0].configs.length; j++) { - if (gDeviceList[0].configs[j].interfaces.length == 0) { - console.info('usb SUB_USB_JS_0290 case current device.configs.interfaces.length = 0'); - } - for (var k = 0; k < gDeviceList[0].configs[j].interfaces.length; k++) { - var tmpInterface = gDeviceList[0].configs[j].interfaces[k] - tmpInterface.name = '134wer' - var isClaim = usb.releaseInterface(gPipe, tmpInterface) - console.info('usb case releaseInterface function return: ' + isClaim); - expect(isClaim).assertLess(0); - } - } - - console.info('usb SUB_USB_JS_0290 : PASS'); - expect(true).assertTrue(); - }) - - /** - * @tc.number : SUB_USB_JS_0300 - * @tc.name : releaseInterface - * @tc.desc : 反向测试 获取接口 release传入Interface的错误clazz 并释放 - */ - it('SUB_USB_JS_0300', 0, function () { - console.info('usb SUB_USB_JS_0300 begin'); - if (portCurrentMode == 1) { - console.info('usb case get_device port is device') - expect(false).assertFalse(); - return - } - if (gDeviceList.length == 0) { - console.info('usb case get_device_list is null') - expect(false).assertTrue(); - return - } - - if (gDeviceList[0].configs.length == 0) { - console.info('usb SUB_USB_JS_0300 case current device.configs.length = 0'); - expect(false).assertTrue(); - return - } - gPipe = usb.connectDevice(gDeviceList[0]) - for (var j = 0; j < gDeviceList[0].configs.length; j++) { - if (gDeviceList[0].configs[j].interfaces.length == 0) { - console.info('usb SUB_USB_JS_0300 case current device.configs.interfaces.length = 0'); - } - for (var k = 0; k < gDeviceList[0].configs[j].interfaces.length; k++) { - var tmpInterface = gDeviceList[0].configs[j].interfaces[k] - tmpInterface.clazz = 78 - var isClaim = usb.releaseInterface(gPipe, tmpInterface) - console.info('usb case releaseInterface function return: ' + isClaim); - expect(isClaim).assertLess(0); - } - } - - console.info('usb SUB_USB_JS_0300 : PASS'); - expect(true).assertTrue(); - }) - - /** - * @tc.number : SUB_USB_JS_0310 - * @tc.name : releaseInterface - * @tc.desc : 反向测试 获取接口 release传入Interface的错误protocol 并释放 - */ - it('SUB_USB_JS_0310', 0, function () { - console.info('usb SUB_USB_JS_0310 begin'); - if (portCurrentMode == 1) { - console.info('usb case get_device port is device') - expect(false).assertFalse(); - return - } - if (gDeviceList.length == 0) { - console.info('usb case get_device_list is null') - expect(false).assertTrue(); - return - } - - if (gDeviceList[0].configs.length == 0) { - console.info('usb SUB_USB_JS_0310 case current device.configs.length = 0'); - expect(false).assertTrue(); - return - } - gPipe = usb.connectDevice(gDeviceList[0]) - for (var j = 0; j < gDeviceList[0].configs.length; j++) { - if (gDeviceList[0].configs[j].interfaces.length == 0) { - console.info('usb SUB_USB_JS_0310 case current device.configs.interfaces.length = 0'); - } - for (var k = 0; k < gDeviceList[0].configs[j].interfaces.length; k++) { - var tmpInterface = gDeviceList[0].configs[j].interfaces[k] - tmpInterface.protocol = 124 - var isClaim = usb.releaseInterface(gPipe, tmpInterface) - console.info('usb case releaseInterface function return: ' + isClaim); - expect(isClaim).assertLess(0); - } - } - - console.info('usb SUB_USB_JS_0310 : PASS'); - expect(true).assertTrue(); - }) - - /** - * @tc.number : SUB_USB_JS_0320 - * @tc.name : releaseInterface - * @tc.desc : 反向测试 获取接口 release传入Interface的错误subClass 并释放 - */ - it('SUB_USB_JS_0320', 0, function () { - console.info('usb SUB_USB_JS_0320 begin'); - if (portCurrentMode == 1) { - console.info('usb case get_device port is device') - expect(false).assertFalse(); - return - } - if (gDeviceList.length == 0) { - console.info('usb case get_device_list is null') - expect(false).assertTrue(); - return - } - - if (gDeviceList[0].configs.length == 0) { - console.info('usb SUB_USB_JS_0320 case current device.configs.length = 0'); - expect(false).assertTrue(); - return - } - gPipe = usb.connectDevice(gDeviceList[0]) - for (var j = 0; j < gDeviceList[0].configs.length; j++) { - if (gDeviceList[0].configs[j].interfaces.length == 0) { - console.info('usb SUB_USB_JS_0320 case current device.configs.interfaces.length = 0'); - } - for (var k = 0; k < gDeviceList[0].configs[j].interfaces.length; k++) { - var tmpInterface = gDeviceList[0].configs[j].interfaces[k] - tmpInterface.subClass = 784 - var isClaim = usb.releaseInterface(gPipe, tmpInterface) - console.info('usb case releaseInterface function return: ' + isClaim); - expect(isClaim).assertLess(0); - } - } - - console.info('usb SUB_USB_JS_0320 : PASS'); - expect(true).assertTrue(); - }) - - /** - * @tc.number : SUB_USB_JS_0820 - * @tc.name : setInterface - * @tc.desc : 反向测试 Interface的protocol 设置设备接口 - */ - it('SUB_USB_JS_0820', 0, function () { - console.info('usb SUB_USB_JS_0820 begin'); - if (portCurrentMode == 1) { - console.info('usb case get_device port is device') - expect(false).assertFalse(); - return - } - if (gDeviceList.length == 0) { - console.info('usb case get_device_list is null') - expect(false).assertTrue() - return - } - gPipe = usb.connectDevice(gDeviceList[0]) - for (var j = 0; j < gDeviceList[0].configs.length; j++) { - var isClaimed = usb.claimInterface(gPipe, gDeviceList[0].configs[j].interfaces[0], true); - - var tmpInterface = gDeviceList[0].configs[j].interfaces[0] - tmpInterface.protocol = 482 - var ret = usb.setInterface(gPipe, tmpInterface) - expect(ret).assertLess(0) - console.info('usb case setInterface return : ' + ret) - } - - console.info('usb SUB_USB_JS_0820 : PASS'); - expect(true).assertTrue(); - }) - - /** - * @tc.number : SUB_USB_JS_0830 - * @tc.name : setInterface - * @tc.desc : 反向测试 Interface的clazz 设置设备接口 - */ - it('SUB_USB_JS_0830', 0, function () { - console.info('usb SUB_USB_JS_0830 begin'); - if (portCurrentMode == 1) { - console.info('usb case get_device port is device') - expect(false).assertFalse(); - return - } - if (gDeviceList.length == 0) { - console.info('usb case get_device_list is null') - expect(false).assertTrue() - return - } - gPipe = usb.connectDevice(gDeviceList[0]) - for (var j = 0; j < gDeviceList[0].configs.length; j++) { - var isClaim = usb.claimInterface(gPipe, gDeviceList[0].configs[j].interfaces[0], true) - - var tmpInterface = gDeviceList[0].configs[j].interfaces[0] - tmpInterface.clazz = 482 - var ret = usb.setInterface(gPipe, tmpInterface) - expect(ret).assertLess(0) - console.info('usb case setInterface return : ' + ret) - - } - - console.info('usb SUB_USB_JS_0830 : PASS'); - expect(true).assertTrue(); - }) - - /** - * @tc.number : SUB_USB_JS_0840 - * @tc.name : setInterface - * @tc.desc : 反向测试 Interface的subClass 设置设备接口 - */ - it('SUB_USB_JS_0840', 0, function () { - console.info('usb SUB_USB_JS_0840 begin'); - if (portCurrentMode == 1) { - console.info('usb case get_device port is device') - expect(false).assertFalse(); - return - } - if (gDeviceList.length == 0) { - console.info('usb case get_device_list is null') - expect(false).assertTrue() - return - } - gPipe = usb.connectDevice(gDeviceList[0]) - for (var j = 0; j < gDeviceList[0].configs.length; j++) { - var isClaim = usb.claimInterface(gPipe, gDeviceList[0].configs[j].interfaces[0], true) - - var tmpInterface = gDeviceList[0].configs[j].interfaces[0] - tmpInterface.subClass = 482 - var ret = usb.setInterface(gPipe, tmpInterface) - expect(ret).assertLess(0) - console.info('usb case setInterface return : ' + ret) - - } - - console.info('usb SUB_USB_JS_0840 : PASS'); - expect(true).assertTrue(); - }) - - /** - * @tc.number : SUB_USB_JS_0850 - * @tc.name : setInterface - * @tc.desc : 反向测试 Interface的name 设置设备接口 - */ - it('SUB_USB_JS_0850', 0, function () { - console.info('usb SUB_USB_JS_0840 begin'); - if (portCurrentMode == 1) { - console.info('usb case get_device port is device') - expect(false).assertFalse(); - return - } - if (gDeviceList.length == 0) { - console.info('usb case get_device_list is null') - expect(false).assertTrue() - return - } - gPipe = usb.connectDevice(gDeviceList[0]) - for (var j = 0; j < gDeviceList[0].configs.length; j++) { - var isClaim = usb.claimInterface(gPipe, gDeviceList[0].configs[j].interfaces[0], true) - - var tmpInterface = gDeviceList[0].configs[j].interfaces[0] - tmpInterface.name = 'wer32' - var ret = usb.setInterface(gPipe, tmpInterface) - expect(ret).assertLess(0) - console.info('usb case setInterface return : ' + ret) - } - - console.info('usb SUB_USB_JS_0850 : PASS'); - expect(true).assertTrue(); - }) - - /** - * @tc.number : SUB_USB_JS_0760 - * @tc.name : setConfiguration - * @tc.desc : 反向测试 USBConfig的name 赋值错误 设置设备接口 - */ - it('SUB_USB_JS_0760', 0, function () { - console.info('usb SUB_USB_JS_0760 begin'); - if (portCurrentMode == 1) { - console.info('usb case get_device port is device') - expect(false).assertFalse(); - return - } - if (gDeviceList.length == 0) { - console.info('usb case get_device_list is null') - expect(false).assertTrue(); - return - } - gPipe = usb.connectDevice(gDeviceList[0]) - for (var j = 0; j < gDeviceList[0].configs.length; j++) { - var config = gDeviceList[0].configs[j] - config.name = 'asdfsd' - var ret = usb.setConfiguration(gPipe, config) - console.info('usb case setConfiguration return : ' + ret); - expect(ret).assertEqual(0); - } - - console.info('usb SUB_USB_JS_0760 : PASS'); - }) - - /** - * @tc.number : SUB_USB_JS_0770 - * @tc.name : setConfiguration - * @tc.desc : 反向测试 USBConfig的name 赋值错误 设置设备接口 - */ - it('SUB_USB_JS_0770', 0, function () { - console.info('usb SUB_USB_JS_0770 begin'); - if (portCurrentMode == 1) { - console.info('usb case get_device port is device') - expect(false).assertFalse(); - return - } - if (gDeviceList.length == 0) { - console.info('usb case get_device_list is null') - expect(false).assertTrue(); - return - } - - for (var j = 0; j < gDeviceList[0].configs.length; j++) { - var config = gDeviceList[0].configs[j] - config.name = 'asdfsd' - config.id = 154 - var ret = usb.setConfiguration(gPipe, config) - console.info('usb case setConfiguration return : ' + ret); - expect(ret).assertLess(0); - } - - console.info('usb SUB_USB_JS_0770 : PASS'); - }) - - /** - * @tc.number : SUB_USB_JS_0780 - * @tc.name : setConfiguration - * @tc.desc : 反向测试 USBConfig的attributes 赋值错误 设置设备接口 - */ - it('SUB_USB_JS_0780', 0, function () { - console.info('usb SUB_USB_JS_0780 begin'); - if (portCurrentMode == 1) { - console.info('usb case get_device port is device') - expect(false).assertFalse(); - return - } - if (gDeviceList.length == 0) { - console.info('usb case get_device_list is null') - expect(false).assertTrue(); - return - } - - for (var j = 0; j < gDeviceList[0].configs.length; j++) { - var config = gDeviceList[0].configs[j] - config.attributes = 154 - var ret = usb.setConfiguration(gPipe, config) - console.info('usb case setConfiguration return : ' + ret); - expect(ret).assertLess(0); - } - - console.info('usb SUB_USB_JS_0780 : PASS'); - }) - -/** - * @tc.number : SUB_USB_JS_0790 - * @tc.name : setConfiguration - * @tc.desc : 反向测试 USBConfig的name interval(1-16) 赋值错误 设置设备接口 - */ - it('SUB_USB_JS_0790', 0, function () { - console.info('usb SUB_USB_JS_0790 begin'); - if (portCurrentMode == 1) { - console.info('usb case get_device port is device') - expect(false).assertFalse(); - return - } - if (gDeviceList.length == 0) { - console.info('usb case get_device_list is null') - expect(false).assertTrue(); - return - } - - for (var j = 0; j < gDeviceList[0].configs.length; j++) { - var config = gDeviceList[0].configs[j] - config.name = 'asdfsd' - config.interfaces[0].endpoints[0].interval = 0 - var ret = usb.setConfiguration(gPipe, config) - console.info('usb case setConfiguration return : ' + ret); - expect(ret).assertLess(0); - } - - console.info('usb SUB_USB_JS_0790 : PASS'); - }) - -}) +/* + * Copyright (c) 2021-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 usb from '@ohos.usb'; +import CheckEmptyUtils from './CheckEmptyUtils.js'; +import EventConstants from './EventConstants.js'; +import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from '@ohos/hypium' + +/* usb device pipe test */ +export default function UsbDevicePipeJsFunctionsTestEx() { +describe('UsbDevicePipeJsFunctionsTestEx', function () { + + var gDeviceList + var gPipe + var portCurrentMode + + beforeAll(function () { + console.log('*************Usb Unit UsbDevicePipeJsFunctionsTestEx Begin*************'); + var Version = usb.getVersion() + console.info('usb unit begin test getversion :' + Version) + + // version > 17 host currentMode = 2 device currentMode = 1 + var usbPortList = usb.getPorts() + gDeviceList = usb.getDevices(); + if (usbPortList.length > 0) { + if (gDeviceList.length > 0) { + if (usbPortList[0].status.currentMode == 1) { + usb.setPortRoles(usbPortList[0].id, usb.SOURCE, usb.HOST).then(data => { + portCurrentMode = 2 + console.info('usb case setPortRoles return: ' + data); + }).catch(error => { + console.info('usb case setPortRoles error : ' + error); + }); + + console.log('*************Usb Unit switch to host Ex Begin*************'); + CheckEmptyUtils.sleep(3000) + } + } else { + portCurrentMode = 1 + } + } + + gPipe = usb.connectDevice(gDeviceList[0]) + console.info('usb unit connectDevice gPipe ret : ' + JSON.stringify(gPipe)); + }) + beforeEach(function () { + console.info('beforeEach: *************Usb Unit Test Ex Case*************'); + }) + afterEach(function () { + console.info('afterEach: *************Usb Unit Test Ex Case*************'); + }) + afterAll(function () { + var isPipClose = usb.closePipe(gPipe) + console.info('usb unit close gPipe ret : ' + isPipClose); + console.log('*************Usb Unit UsbDevicePipeJsFunctionsTestEx End*************'); + }) + + function findInitPoint(testParam, j) { + var bfind = false + for (var k = 0; k < testParam.config.interfaces[j].endpoints.length; k++) { + var endpoint = testParam.config.interfaces[j].endpoints[k]; + if (endpoint.type == EventConstants.USB_ENDPOINT_XFER_BULK) { + + bfind = true + if (endpoint.direction == usb.USB_REQUEST_DIR_TO_DEVICE) { + testParam.outEndpoint = endpoint; + testParam.maxOutSize = endpoint.maxPacketSize; + } else if (endpoint.direction == usb.USB_REQUEST_DIR_FROM_DEVICE) { + testParam.inEndpoint = endpoint + testParam.maxInSize = endpoint.maxPacketSize; + } + } + } + if (bfind) { + testParam.interface = testParam.config.interfaces[j] + return true + } + return false + } + + function getFlag(testParam, j) { + if (testParam.config.interfaces[j].clazz != 10 || + testParam.config.interfaces[j].subclass != 0 || + testParam.config.interfaces[j].protocol != 2) { + return false + } + + if (testParam.config.interfaces[j].endpoints.length == 0) { + return false + } + + return true + } + + function initPoint(testParam) { + for (var j = 0; j < testParam.config.interfaces.length; j++) { + if (getFlag(testParam, j)) { + if (findInitPoint(testParam, j)) { + break + } + } + } + } + + // 预制传输相关参数 + function getTransferTestParam() { + var testParam = { + device: null, + config: null, + pip: null, + inEndpoint: null, + outEndpoint: null, + interface: null, + usbRequest: null, + sendData: '', + isClaimed: 0, + maxInSize: 1024, + maxOutSize: 1024 + } + + console.info('usb case gDeviceList.length: ' + gDeviceList.length); + for (var i = 0; i < gDeviceList.length; i++) { + testParam.device = gDeviceList[i] + testParam.config = testParam.device.configs[0] + testParam.pip = gPipe + initPoint(testParam) + } + return testParam + } + + /** + * @tc.number : SUB_USB_JS_0650 + * @tc.name : bulkTransfer + * @tc.desc : 反向测试 批量传输 发数据 修改 outEndpoint.address = 123 + */ + it('SUB_USB_JS_0650', 0, function () { + console.info('usb SUB_USB_JS_0650 begin'); + if (portCurrentMode == 1) { + console.info('usb case get_device port is device') + expect(false).assertFalse(); + return + } + var testParam = getTransferTestParam() + if (testParam.interface == null || testParam.outEndpoint == null) { + expect(false).assertTrue(); + return + } + + testParam.isClaimed = usb.claimInterface(testParam.pip, testParam.interface, true); + expect(testParam.isClaimed).assertEqual(0); + + testParam.sendData = 'send time 13213213 wzy 03'; + var tmpUint8Array = CheckEmptyUtils.str2ab(testParam.sendData); + var TmpTestParam = testParam + TmpTestParam.outEndpoint.address = 123 + usb.bulkTransfer(TmpTestParam.pip, TmpTestParam.outEndpoint, tmpUint8Array, 5000).then(data => { + console.info('usb case SUB_USB_JS_0650 ret: ' + data); + console.info('usb case SUB_USB_JS_0650 : PASS'); + expect(data).assertEqual(-1); + }).catch(error => { + console.info('usb 03 write error : ' + JSON.stringify(error)); + expect(false).assertFalse(); + console.info('usb case SUB_USB_JS_0650 : PASS'); + }); + }) + + /** + * @tc.number : SUB_USB_JS_0660 + * @tc.name : bulkTransfer + * @tc.desc : 反向测试 批量传输 发数据 修改 outEndpoint.number = 123 + */ + it('SUB_USB_JS_0660', 0, function () { + console.info('usb SUB_USB_JS_0660 begin'); + if (portCurrentMode == 1) { + console.info('usb case get_device port is device') + expect(false).assertFalse(); + return + } + var testParam = getTransferTestParam() + if (testParam.interface == null || testParam.outEndpoint == null) { + expect(false).assertTrue(); + return + } + + testParam.isClaimed = usb.claimInterface(testParam.pip, testParam.interface, true); + expect(testParam.isClaimed).assertEqual(0); + + testParam.sendData = 'send time 13213213 wzy 04'; + var tmpUint8Array = CheckEmptyUtils.str2ab(testParam.sendData); + var TmpTestParam = testParam + TmpTestParam.outEndpoint.number = 123 + usb.bulkTransfer(TmpTestParam.pip, TmpTestParam.outEndpoint, tmpUint8Array, 5000).then(data => { + console.info('usb case SUB_USB_JS_0660 ret: ' + data); + console.info('usb case SUB_USB_JS_0660 : PASS'); + expect(data).assertEqual(-1); + }).catch(error => { + console.info('usb 04 write error : ' + JSON.stringify(error)); + expect(false).assertFalse(); + console.info('usb case SUB_USB_JS_0660 : PASS'); + }); + }) + + /** + * @tc.number : SUB_USB_JS_0670 + * @tc.name : bulkTransfer + * @tc.desc : 反向测试 批量传输 发数据 修改 outEndpoint.type = 123 + */ + it('SUB_USB_JS_0670', 0, function () { + console.info('usb SUB_USB_JS_0670 begin'); + if (portCurrentMode == 1) { + console.info('usb case get_device port is device') + expect(false).assertFalse(); + return + } + var testParam = getTransferTestParam() + if (testParam.interface == null || testParam.outEndpoint == null) { + expect(false).assertTrue(); + return + } + + testParam.isClaimed = usb.claimInterface(testParam.pip, testParam.interface, true); + expect(testParam.isClaimed).assertEqual(0); + + testParam.sendData = 'send time 13213213 wzy 05'; + var tmpUint8Array = CheckEmptyUtils.str2ab(testParam.sendData); + var TmpTestParam = testParam + TmpTestParam.outEndpoint.type = 123 + usb.bulkTransfer(TmpTestParam.pip, TmpTestParam.outEndpoint, tmpUint8Array, 5000).then(data => { + console.info('usb case SUB_USB_JS_0670 ret: ' + data); + console.info('usb case SUB_USB_JS_0670 : PASS'); + expect(data).assertEqual(-1); + }).catch(error => { + console.info('usb 05 write error : ' + JSON.stringify(error)); + expect(false).assertFalse(); + console.info('usb case SUB_USB_JS_0670 : PASS'); + }); + }) + + /** + * @tc.number : SUB_USB_JS_0430 + * @tc.name : claimInterface + * @tc.desc : 反向测试 USBInterface传入异常id 获取接口 失败 + */ + it('SUB_USB_JS_0430', 0, function () { + console.info('usb SUB_USB_JS_0430 begin'); + if (portCurrentMode == 1) { + console.info('usb case get_device port is device') + expect(false).assertFalse(); + return + } + if (gDeviceList.length == 0) { + console.info('usb case get_device_list is null') + expect(false).assertTrue(); + return + } + + if (gDeviceList[0].configs.length == 0) { + console.info('usb case SUB_USB_JS_0430 current device.configs.length = 0'); + expect(false).assertTrue(); + return + } + + for (var j = 0; j < gDeviceList[0].configs.length; j++) { + if (gDeviceList[0].configs[j].interfaces.length == 0) { + console.info('usb case SUB_USB_JS_0430 current device.configs.interfaces.length = 0'); + } + for (var k = 0; k < gDeviceList[0].configs[j].interfaces.length; k++) { + var TmpInterface = gDeviceList[0].configs[j].interfaces[k] + TmpInterface.id = 123 + var isClaim = usb.claimInterface(gPipe, TmpInterface, true) + console.info('usb case claimInterface function return: ' + isClaim); + expect(isClaim).assertLess(0); + } + } + + console.info('usb SUB_USB_JS_0430 : PASS'); + expect(true).assertTrue(); + }) + + /** + * @tc.number : SUB_USB_JS_0440 + * @tc.name : claimInterface + * @tc.desc : 反向测试 USBInterface传入异常protocol 获取接口 失败 + */ + it('SUB_USB_JS_0440', 0, function () { + console.info('usb SUB_USB_JS_0440 begin'); + if (portCurrentMode == 1) { + console.info('usb case get_device port is device') + expect(false).assertFalse(); + return + } + if (gDeviceList.length == 0) { + console.info('usb case get_device_list is null') + expect(false).assertTrue(); + return + } + + if (gDeviceList[0].configs.length == 0) { + console.info('usb case SUB_USB_JS_0440 current device.configs.length = 0'); + expect(false).assertTrue(); + return + } + + for (var j = 0; j < gDeviceList[0].configs.length; j++) { + if (gDeviceList[0].configs[j].interfaces.length == 0) { + console.info('usb case SUB_USB_JS_0440 current device.configs.interfaces.length = 0'); + } + for (var k = 0; k < gDeviceList[0].configs[j].interfaces.length; k++) { + var TmpInterface = gDeviceList[0].configs[j].interfaces[k] + TmpInterface.protocol = 120 + var isClaim = usb.claimInterface(gPipe, TmpInterface, true) + console.info('usb case claimInterface function return: ' + isClaim); + expect(isClaim).assertLess(0); + } + } + + console.info('usb SUB_USB_JS_0440 : PASS'); + expect(true).assertTrue(); + }) + + /** + * @tc.number : SUB_USB_JS_0450 + * @tc.name : claimInterface + * @tc.desc : 反向测试 USBInterface传入异常clazz 获取接口 失败 + */ + it('SUB_USB_JS_0450', 0, function () { + console.info('usb SUB_USB_JS_0450 begin'); + if (portCurrentMode == 1) { + console.info('usb case get_device port is device') + expect(false).assertFalse(); + return + } + if (gDeviceList.length == 0) { + console.info('usb case get_device_list is null') + expect(false).assertTrue(); + return + } + + if (gDeviceList[0].configs.length == 0) { + console.info('usb case SUB_USB_JS_0450 current device.configs.length = 0'); + expect(false).assertTrue(); + return + } + + for (var j = 0; j < gDeviceList[0].configs.length; j++) { + if (gDeviceList[0].configs[j].interfaces.length == 0) { + console.info('usb case SUB_USB_JS_0450 current device.configs.interfaces.length = 0'); + } + for (var k = 0; k < gDeviceList[0].configs[j].interfaces.length; k++) { + var TmpInterface = gDeviceList[0].configs[j].interfaces[k] + TmpInterface.clazz = 784 + var isClaim = usb.claimInterface(gPipe, TmpInterface, true) + console.info('usb case claimInterface function return: ' + isClaim); + expect(isClaim).assertLess(0); + } + } + + console.info('usb SUB_USB_JS_0450 : PASS'); + expect(true).assertTrue(); + }) + + /** + * @tc.number : SUB_USB_JS_0460 + * @tc.name : claimInterface + * @tc.desc : 反向测试 USBInterface传入异常name 获取接口 失败 + */ + it('SUB_USB_JS_0460', 0, function () { + console.info('usb SUB_USB_JS_0460 begin'); + if (portCurrentMode == 1) { + console.info('usb case get_device port is device') + expect(false).assertFalse(); + return + } + if (gDeviceList.length == 0) { + console.info('usb case get_device_list is null') + expect(false).assertTrue(); + return + } + + if (gDeviceList[0].configs.length == 0) { + console.info('usb case SUB_USB_JS_0460 current device.configs.length = 0'); + expect(false).assertTrue(); + return + } + + for (var j = 0; j < gDeviceList[0].configs.length; j++) { + if (gDeviceList[0].configs[j].interfaces.length == 0) { + console.info('usb case SUB_USB_JS_0460 current device.configs.interfaces.length = 0'); + } + for (var k = 0; k < gDeviceList[0].configs[j].interfaces.length; k++) { + var TmpInterface = gDeviceList[0].configs[j].interfaces[k] + TmpInterface.name = '123sdf' + var isClaim = usb.claimInterface(gPipe, TmpInterface, true) + console.info('usb case claimInterface function return: ' + isClaim); + expect(isClaim).assertLess(0); + } + } + + console.info('usb SUB_USB_JS_0460 : PASS'); + expect(true).assertTrue(); + }) + + /** + * @tc.number : SUB_USB_JS_0470 + * @tc.name : claimInterface + * @tc.desc : 反向测试 USBInterface传入异常subClass 获取接口 失败 + */ + it('SUB_USB_JS_0470', 0, function () { + console.info('usb SUB_USB_JS_0470 begin'); + if (portCurrentMode == 1) { + console.info('usb case get_device port is device') + expect(false).assertFalse(); + return + } + if (gDeviceList.length == 0) { + console.info('usb case get_device_list is null') + expect(false).assertTrue(); + return + } + + if (gDeviceList[0].configs.length == 0) { + console.info('usb case SUB_USB_JS_0470 current device.configs.length = 0'); + expect(false).assertTrue(); + return + } + + for (var j = 0; j < gDeviceList[0].configs.length; j++) { + if (gDeviceList[0].configs[j].interfaces.length == 0) { + console.info('usb case SUB_USB_JS_0470 current device.configs.interfaces.length = 0'); + } + for (var k = 0; k < gDeviceList[0].configs[j].interfaces.length; k++) { + var TmpInterface = gDeviceList[0].configs[j].interfaces[k] + TmpInterface.subClass = 1210 + var isClaim = usb.claimInterface(gPipe, TmpInterface, true) + console.info('usb case claimInterface function return: ' + isClaim); + expect(isClaim).assertLess(0); + } + } + + console.info('usb SUB_USB_JS_0470 : PASS'); + expect(true).assertTrue(); + }) + + /** + * @tc.number : SUB_USB_JS_0280 + * @tc.name : releaseInterface + * @tc.desc : 反向测试 获取接口 release传入Interface的错误ID 并释放 + */ + it('SUB_USB_JS_0280', 0, function () { + console.info('usb SUB_USB_JS_0280 begin'); + if (portCurrentMode == 1) { + console.info('usb case get_device port is device') + expect(false).assertFalse(); + return + } + if (gDeviceList.length == 0) { + console.info('usb case get_device_list is null') + expect(false).assertTrue(); + return + } + + if (gDeviceList[0].configs.length == 0) { + console.info('usb SUB_USB_JS_0280 case current device.configs.length = 0'); + expect(false).assertTrue(); + return + } + gPipe = usb.connectDevice(gDeviceList[0]) + for (var j = 0; j < gDeviceList[0].configs.length; j++) { + if (gDeviceList[0].configs[j].interfaces.length == 0) { + console.info('usb SUB_USB_JS_0280 case current device.configs.interfaces.length = 0'); + } + for (var k = 0; k < gDeviceList[0].configs[j].interfaces.length; k++) { + var tmpInterface = gDeviceList[0].configs[j].interfaces[k] + tmpInterface.id = 134 + var isClaim = usb.releaseInterface(gPipe, tmpInterface) + console.info('usb case releaseInterface function return: ' + isClaim); + expect(isClaim).assertLess(0); + } + } + + console.info('usb SUB_USB_JS_0280 : PASS'); + expect(true).assertTrue(); + }) + + /** + * @tc.number : SUB_USB_JS_0290 + * @tc.name : releaseInterface + * @tc.desc : 反向测试 获取接口 release传入Interface的错误name 并释放 + */ + it('SUB_USB_JS_0290', 0, function () { + console.info('usb SUB_USB_JS_0290 begin'); + if (portCurrentMode == 1) { + console.info('usb case get_device port is device') + expect(false).assertFalse(); + return + } + if (gDeviceList.length == 0) { + console.info('usb case get_device_list is null') + expect(false).assertTrue(); + return + } + + if (gDeviceList[0].configs.length == 0) { + console.info('usb SUB_USB_JS_0290 case current device.configs.length = 0'); + expect(false).assertTrue(); + return + } + gPipe = usb.connectDevice(gDeviceList[0]) + for (var j = 0; j < gDeviceList[0].configs.length; j++) { + if (gDeviceList[0].configs[j].interfaces.length == 0) { + console.info('usb SUB_USB_JS_0290 case current device.configs.interfaces.length = 0'); + } + for (var k = 0; k < gDeviceList[0].configs[j].interfaces.length; k++) { + var tmpInterface = gDeviceList[0].configs[j].interfaces[k] + tmpInterface.name = '134wer' + var isClaim = usb.releaseInterface(gPipe, tmpInterface) + console.info('usb case releaseInterface function return: ' + isClaim); + expect(isClaim).assertLess(0); + } + } + + console.info('usb SUB_USB_JS_0290 : PASS'); + expect(true).assertTrue(); + }) + + /** + * @tc.number : SUB_USB_JS_0300 + * @tc.name : releaseInterface + * @tc.desc : 反向测试 获取接口 release传入Interface的错误clazz 并释放 + */ + it('SUB_USB_JS_0300', 0, function () { + console.info('usb SUB_USB_JS_0300 begin'); + if (portCurrentMode == 1) { + console.info('usb case get_device port is device') + expect(false).assertFalse(); + return + } + if (gDeviceList.length == 0) { + console.info('usb case get_device_list is null') + expect(false).assertTrue(); + return + } + + if (gDeviceList[0].configs.length == 0) { + console.info('usb SUB_USB_JS_0300 case current device.configs.length = 0'); + expect(false).assertTrue(); + return + } + gPipe = usb.connectDevice(gDeviceList[0]) + for (var j = 0; j < gDeviceList[0].configs.length; j++) { + if (gDeviceList[0].configs[j].interfaces.length == 0) { + console.info('usb SUB_USB_JS_0300 case current device.configs.interfaces.length = 0'); + } + for (var k = 0; k < gDeviceList[0].configs[j].interfaces.length; k++) { + var tmpInterface = gDeviceList[0].configs[j].interfaces[k] + tmpInterface.clazz = 78 + var isClaim = usb.releaseInterface(gPipe, tmpInterface) + console.info('usb case releaseInterface function return: ' + isClaim); + expect(isClaim).assertLess(0); + } + } + + console.info('usb SUB_USB_JS_0300 : PASS'); + expect(true).assertTrue(); + }) + + /** + * @tc.number : SUB_USB_JS_0310 + * @tc.name : releaseInterface + * @tc.desc : 反向测试 获取接口 release传入Interface的错误protocol 并释放 + */ + it('SUB_USB_JS_0310', 0, function () { + console.info('usb SUB_USB_JS_0310 begin'); + if (portCurrentMode == 1) { + console.info('usb case get_device port is device') + expect(false).assertFalse(); + return + } + if (gDeviceList.length == 0) { + console.info('usb case get_device_list is null') + expect(false).assertTrue(); + return + } + + if (gDeviceList[0].configs.length == 0) { + console.info('usb SUB_USB_JS_0310 case current device.configs.length = 0'); + expect(false).assertTrue(); + return + } + gPipe = usb.connectDevice(gDeviceList[0]) + for (var j = 0; j < gDeviceList[0].configs.length; j++) { + if (gDeviceList[0].configs[j].interfaces.length == 0) { + console.info('usb SUB_USB_JS_0310 case current device.configs.interfaces.length = 0'); + } + for (var k = 0; k < gDeviceList[0].configs[j].interfaces.length; k++) { + var tmpInterface = gDeviceList[0].configs[j].interfaces[k] + tmpInterface.protocol = 124 + var isClaim = usb.releaseInterface(gPipe, tmpInterface) + console.info('usb case releaseInterface function return: ' + isClaim); + expect(isClaim).assertLess(0); + } + } + + console.info('usb SUB_USB_JS_0310 : PASS'); + expect(true).assertTrue(); + }) + + /** + * @tc.number : SUB_USB_JS_0320 + * @tc.name : releaseInterface + * @tc.desc : 反向测试 获取接口 release传入Interface的错误subClass 并释放 + */ + it('SUB_USB_JS_0320', 0, function () { + console.info('usb SUB_USB_JS_0320 begin'); + if (portCurrentMode == 1) { + console.info('usb case get_device port is device') + expect(false).assertFalse(); + return + } + if (gDeviceList.length == 0) { + console.info('usb case get_device_list is null') + expect(false).assertTrue(); + return + } + + if (gDeviceList[0].configs.length == 0) { + console.info('usb SUB_USB_JS_0320 case current device.configs.length = 0'); + expect(false).assertTrue(); + return + } + gPipe = usb.connectDevice(gDeviceList[0]) + for (var j = 0; j < gDeviceList[0].configs.length; j++) { + if (gDeviceList[0].configs[j].interfaces.length == 0) { + console.info('usb SUB_USB_JS_0320 case current device.configs.interfaces.length = 0'); + } + for (var k = 0; k < gDeviceList[0].configs[j].interfaces.length; k++) { + var tmpInterface = gDeviceList[0].configs[j].interfaces[k] + tmpInterface.subClass = 784 + var isClaim = usb.releaseInterface(gPipe, tmpInterface) + console.info('usb case releaseInterface function return: ' + isClaim); + expect(isClaim).assertLess(0); + } + } + + console.info('usb SUB_USB_JS_0320 : PASS'); + expect(true).assertTrue(); + }) + + /** + * @tc.number : SUB_USB_JS_0820 + * @tc.name : setInterface + * @tc.desc : 反向测试 Interface的protocol 设置设备接口 + */ + it('SUB_USB_JS_0820', 0, function () { + console.info('usb SUB_USB_JS_0820 begin'); + if (portCurrentMode == 1) { + console.info('usb case get_device port is device') + expect(false).assertFalse(); + return + } + if (gDeviceList.length == 0) { + console.info('usb case get_device_list is null') + expect(false).assertTrue() + return + } + gPipe = usb.connectDevice(gDeviceList[0]) + for (var j = 0; j < gDeviceList[0].configs.length; j++) { + var isClaimed = usb.claimInterface(gPipe, gDeviceList[0].configs[j].interfaces[0], true); + + var tmpInterface = gDeviceList[0].configs[j].interfaces[0] + tmpInterface.protocol = 482 + var ret = usb.setInterface(gPipe, tmpInterface) + expect(ret).assertLess(0) + console.info('usb case setInterface return : ' + ret) + } + + console.info('usb SUB_USB_JS_0820 : PASS'); + expect(true).assertTrue(); + }) + + /** + * @tc.number : SUB_USB_JS_0830 + * @tc.name : setInterface + * @tc.desc : 反向测试 Interface的clazz 设置设备接口 + */ + it('SUB_USB_JS_0830', 0, function () { + console.info('usb SUB_USB_JS_0830 begin'); + if (portCurrentMode == 1) { + console.info('usb case get_device port is device') + expect(false).assertFalse(); + return + } + if (gDeviceList.length == 0) { + console.info('usb case get_device_list is null') + expect(false).assertTrue() + return + } + gPipe = usb.connectDevice(gDeviceList[0]) + for (var j = 0; j < gDeviceList[0].configs.length; j++) { + var isClaim = usb.claimInterface(gPipe, gDeviceList[0].configs[j].interfaces[0], true) + + var tmpInterface = gDeviceList[0].configs[j].interfaces[0] + tmpInterface.clazz = 482 + var ret = usb.setInterface(gPipe, tmpInterface) + expect(ret).assertLess(0) + console.info('usb case setInterface return : ' + ret) + + } + + console.info('usb SUB_USB_JS_0830 : PASS'); + expect(true).assertTrue(); + }) + + /** + * @tc.number : SUB_USB_JS_0840 + * @tc.name : setInterface + * @tc.desc : 反向测试 Interface的subClass 设置设备接口 + */ + it('SUB_USB_JS_0840', 0, function () { + console.info('usb SUB_USB_JS_0840 begin'); + if (portCurrentMode == 1) { + console.info('usb case get_device port is device') + expect(false).assertFalse(); + return + } + if (gDeviceList.length == 0) { + console.info('usb case get_device_list is null') + expect(false).assertTrue() + return + } + gPipe = usb.connectDevice(gDeviceList[0]) + for (var j = 0; j < gDeviceList[0].configs.length; j++) { + var isClaim = usb.claimInterface(gPipe, gDeviceList[0].configs[j].interfaces[0], true) + + var tmpInterface = gDeviceList[0].configs[j].interfaces[0] + tmpInterface.subClass = 482 + var ret = usb.setInterface(gPipe, tmpInterface) + expect(ret).assertLess(0) + console.info('usb case setInterface return : ' + ret) + + } + + console.info('usb SUB_USB_JS_0840 : PASS'); + expect(true).assertTrue(); + }) + + /** + * @tc.number : SUB_USB_JS_0850 + * @tc.name : setInterface + * @tc.desc : 反向测试 Interface的name 设置设备接口 + */ + it('SUB_USB_JS_0850', 0, function () { + console.info('usb SUB_USB_JS_0840 begin'); + if (portCurrentMode == 1) { + console.info('usb case get_device port is device') + expect(false).assertFalse(); + return + } + if (gDeviceList.length == 0) { + console.info('usb case get_device_list is null') + expect(false).assertTrue() + return + } + gPipe = usb.connectDevice(gDeviceList[0]) + for (var j = 0; j < gDeviceList[0].configs.length; j++) { + var isClaim = usb.claimInterface(gPipe, gDeviceList[0].configs[j].interfaces[0], true) + + var tmpInterface = gDeviceList[0].configs[j].interfaces[0] + tmpInterface.name = 'wer32' + var ret = usb.setInterface(gPipe, tmpInterface) + expect(ret).assertLess(0) + console.info('usb case setInterface return : ' + ret) + } + + console.info('usb SUB_USB_JS_0850 : PASS'); + expect(true).assertTrue(); + }) + + /** + * @tc.number : SUB_USB_JS_0760 + * @tc.name : setConfiguration + * @tc.desc : 反向测试 USBConfig的name 赋值错误 设置设备接口 + */ + it('SUB_USB_JS_0760', 0, function () { + console.info('usb SUB_USB_JS_0760 begin'); + if (portCurrentMode == 1) { + console.info('usb case get_device port is device') + expect(false).assertFalse(); + return + } + if (gDeviceList.length == 0) { + console.info('usb case get_device_list is null') + expect(false).assertTrue(); + return + } + gPipe = usb.connectDevice(gDeviceList[0]) + for (var j = 0; j < gDeviceList[0].configs.length; j++) { + var config = gDeviceList[0].configs[j] + config.name = 'asdfsd' + var ret = usb.setConfiguration(gPipe, config) + console.info('usb case setConfiguration return : ' + ret); + expect(ret).assertEqual(0); + } + + console.info('usb SUB_USB_JS_0760 : PASS'); + }) + + /** + * @tc.number : SUB_USB_JS_0770 + * @tc.name : setConfiguration + * @tc.desc : 反向测试 USBConfig的name 赋值错误 设置设备接口 + */ + it('SUB_USB_JS_0770', 0, function () { + console.info('usb SUB_USB_JS_0770 begin'); + if (portCurrentMode == 1) { + console.info('usb case get_device port is device') + expect(false).assertFalse(); + return + } + if (gDeviceList.length == 0) { + console.info('usb case get_device_list is null') + expect(false).assertTrue(); + return + } + + for (var j = 0; j < gDeviceList[0].configs.length; j++) { + var config = gDeviceList[0].configs[j] + config.name = 'asdfsd' + config.id = 154 + var ret = usb.setConfiguration(gPipe, config) + console.info('usb case setConfiguration return : ' + ret); + expect(ret).assertLess(0); + } + + console.info('usb SUB_USB_JS_0770 : PASS'); + }) + + /** + * @tc.number : SUB_USB_JS_0780 + * @tc.name : setConfiguration + * @tc.desc : 反向测试 USBConfig的attributes 赋值错误 设置设备接口 + */ + it('SUB_USB_JS_0780', 0, function () { + console.info('usb SUB_USB_JS_0780 begin'); + if (portCurrentMode == 1) { + console.info('usb case get_device port is device') + expect(false).assertFalse(); + return + } + if (gDeviceList.length == 0) { + console.info('usb case get_device_list is null') + expect(false).assertTrue(); + return + } + + for (var j = 0; j < gDeviceList[0].configs.length; j++) { + var config = gDeviceList[0].configs[j] + config.attributes = 154 + var ret = usb.setConfiguration(gPipe, config) + console.info('usb case setConfiguration return : ' + ret); + expect(ret).assertLess(0); + } + + console.info('usb SUB_USB_JS_0780 : PASS'); + }) + +/** + * @tc.number : SUB_USB_JS_0790 + * @tc.name : setConfiguration + * @tc.desc : 反向测试 USBConfig的name interval(1-16) 赋值错误 设置设备接口 + */ + it('SUB_USB_JS_0790', 0, function () { + console.info('usb SUB_USB_JS_0790 begin'); + if (portCurrentMode == 1) { + console.info('usb case get_device port is device') + expect(false).assertFalse(); + return + } + if (gDeviceList.length == 0) { + console.info('usb case get_device_list is null') + expect(false).assertTrue(); + return + } + + for (var j = 0; j < gDeviceList[0].configs.length; j++) { + var config = gDeviceList[0].configs[j] + config.name = 'asdfsd' + config.interfaces[0].endpoints[0].interval = 0 + var ret = usb.setConfiguration(gPipe, config) + console.info('usb case setConfiguration return : ' + ret); + expect(ret).assertLess(0); + } + + console.info('usb SUB_USB_JS_0790 : PASS'); + }) + +}) +} diff --git a/usb/usb_standard/src/main/js/default/test/UsbDevicePipeJsunit_A.test.js b/usb/usb_standard/src/main/js/test/UsbDevicePipeJsunit_A.test.js old mode 100755 new mode 100644 similarity index 96% rename from usb/usb_standard/src/main/js/default/test/UsbDevicePipeJsunit_A.test.js rename to usb/usb_standard/src/main/js/test/UsbDevicePipeJsunit_A.test.js index a5bb21b03c5e4294d8213b3da30fed7a4561bd74..eac2f59f5cc9cd50e94a7841432fa43e59ba4fb6 --- a/usb/usb_standard/src/main/js/default/test/UsbDevicePipeJsunit_A.test.js +++ b/usb/usb_standard/src/main/js/test/UsbDevicePipeJsunit_A.test.js @@ -1,567 +1,569 @@ -/* - * Copyright (c) 2021-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 usb from '@ohos.usb'; -import CheckEmptyUtils from './CheckEmptyUtils.js'; -import EventConstants from './EventConstants.js'; -import parameter from '@ohos.systemparameter'; -import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from 'deccjsunit/index' - -/* usb device pipe test */ -describe('UsbDevicePipeJsFunctionsTest', function () { - var gDeviceList - var gPipe - var portCurrentMode - - beforeAll(function () { - console.log('*************Usb Unit UsbDevicePipeJsFunctionsTest Begin*************'); - var Version = usb.getVersion() - console.info('usb unit begin test getversion :' + Version) - // version > 17 host currentMode = 2 device currentMode = 1 - var usbPortList = usb.getPorts() - gDeviceList = usb.getDevices(); - if (usbPortList.length > 0) { - if (gDeviceList.length > 0) { - if (usbPortList[0].status.currentMode == 1) { - usb.setPortRoles(usbPortList[0].id, usb.SOURCE, usb.HOST).then(data => { - portCurrentMode = 2 - console.info('usb case setPortRoles return: ' + data); - }).catch(error => { - console.info('usb case setPortRoles error : ' + error); - }); - console.log('*************Usb Unit switch to host Begin*************'); - } - } else { - portCurrentMode = 1 - } - - } - - gDeviceList = usb.getDevices(); - gDeviceList[0].name; - gDeviceList[0].version; - gDeviceList[0].configs; - gPipe = usb.connectDevice(gDeviceList[0]) - console.info('usb unit connectDevice gPipe ret : ' + JSON.stringify(gPipe)); - }) - - beforeEach(function () { - console.info('beforeEach: *************Usb Unit Test Case*************'); - }) - afterEach(function () { - console.info('afterEach: *************Usb Unit Test Case*************'); - }) - - afterAll(function () { - var isPipClose = usb.closePipe(gPipe) - console.info('usb unit close gPipe ret : ' + isPipClose); - console.log('*************Usb Unit UsbDevicePipeJsFunctionsTest End*************'); - }) - - function findInitPoint(testParam, j) { - var bfind = false - for (var k = 0; k < testParam.config.interfaces[j].endpoints.length; k++) { - var endpoint = testParam.config.interfaces[j].endpoints[k]; - endpoint.number = 1; - endpoint.type = 1; - endpoint.interfaceid = 1; - if (endpoint.type == EventConstants.USB_ENDPOINT_XFER_BULK) { - bfind = true - if (endpoint.direction == usb.USB_REQUEST_DIR_TO_DEVICE) { - testParam.maxOutSize = endpoint.maxPacketSize; - testParam.outEndpoint = endpoint; - } else if (endpoint.direction == usb.USB_REQUEST_DIR_FROM_DEVICE) { - testParam.maxInSize = endpoint.maxPacketSize; - testParam.inEndpoint = endpoint - } - } - } - if (bfind) { - testParam.interface = testParam.config.interfaces[j] - return bfind - } - return false - } - - function getFlag(testParam, j) { - if (testParam.config.interfaces[j].endpoints.length == 0) { - return false - } - - if (testParam.config.interfaces[j].clazz != 10 || - testParam.config.interfaces[j].subclass != 0 || - testParam.config.interfaces[j].protocol != 2) { - return false - } - return true - } - - function initPoint(testParam) { - for (var j = 0; j < testParam.config.interfaces.length; j++) { - if (getFlag(testParam, j) == true) { - if (findInitPoint(testParam, j) == true) { - break - } - } - } - } - - function getTransferTestParam() { - var testParam = { - config: null, - device: null, - pip: null, - inEndpoint: null, - interface: null, - outEndpoint: null, - usbRequest: null, - sendData: '', - isClaimed: 0, - maxInSize: 1024, - maxOutSize: 1024 - } - - console.info('usb case gDeviceList.length: ' + gDeviceList.length); - for (var i = 0; i < gDeviceList.length; i++) { - testParam.device = gDeviceList[i] - testParam.config = testParam.device.configs[0] - testParam.pip = gPipe - initPoint(testParam) - } - return testParam - } - - /** - * @tc.number : SUB_USB_JS_0630 - * @tc.name : bulkTransfer - * @tc.desc : 批量传输 收数据 - */ - it('SUB_USB_JS_0630', 0, function () { - console.info('usb SUB_USB_JS_0630 begin'); - var testParam = getTransferTestParam() - if (testParam.interface == null || testParam.inEndpoint == null) { - expect(false).assertTrue(); - return - } - - testParam.isClaimed = usb.claimInterface(testParam.pip, testParam.interface, true); - expect(testParam.isClaimed).assertEqual(0); - - console.info('usb case readData begin'); - var tmpUint8Array = new Uint8Array(testParam.maxInSize); - usb.bulkTransfer(testParam.pip, testParam.inEndpoint, tmpUint8Array, 5000).then(data => { - console.info('usb case readData tmpUint8Array buffer : ' + CheckEmptyUtils.ab2str(tmpUint8Array)); - console.info('usb case readData ret: ' + data); - console.info('usb case SUB_USB_JS_0630 : PASS'); - expect(data >= 0).assertTrue(); - }).catch(error => { - console.info('usb case readData error : ' + JSON.stringify(error)); - expect(false).assertTrue(); - }); - }) - - /** - * @tc.number : SUB_USB_JS_0640 - * @tc.name : bulkTransfer - * @tc.desc : 批量传输 发数据 - */ - it('SUB_USB_JS_0640', 0, function () { - console.info('usb SUB_USB_JS_0640 begin'); - var testParam = getTransferTestParam() - if (testParam.interface == null || testParam.outEndpoint == null) { - expect(false).assertTrue(); - return - } - - testParam.isClaimed = usb.claimInterface(testParam.pip, testParam.interface, true); - expect(testParam.isClaimed).assertEqual(0); - - testParam.sendData = 'send default'; - try { - testParam.sendData = parameter.getSync('test_usb', 'default'); - console.log('usb parameter ' + JSON.stringify(testParam.sendData)); - } catch (e) { - console.log('usb parameter getSync unexpected error: ' + e); - } - - var tmpUint8Array = CheckEmptyUtils.str2ab(testParam.sendData); - usb.bulkTransfer(testParam.pip, testParam.outEndpoint, tmpUint8Array, 5000).then(data => { - console.info('usb case SUB_USB_JS_0640 ret: ' + data); - console.info('usb case SUB_USB_JS_0640 send data: ' + testParam.sendData); - console.info('usb case SUB_USB_JS_0640 : PASS'); - expect(true).assertTrue(); - }).catch(error => { - console.info('usb write error : ' + JSON.stringify(error)); - expect(false).assertTrue(); - }); - - }) - - /** - * @tc.number : SUB_USB_JS_0420 - * @tc.name : claimInterface - * @tc.desc : 获取接口 并释放 - */ - it('SUB_USB_JS_0420', 0, function () { - console.info('usb SUB_USB_JS_0420 begin'); - if (gDeviceList.length == 0) { - console.info('usb 01 case get_device_list is null') - expect(gDeviceList.length).assertEqual(-1); - return - } - - if (gDeviceList[0].configs.length == 0) { - console.info('usb 01 case current device.configs.length = 0'); - expect(false).assertTrue(); - return - } - - for (var j = 0; j < gDeviceList[0].configs.length; j++) { - if (gDeviceList[0].configs[j].interfaces.length == 0) { - console.info('usb case current device.configs.interfaces.length = 0'); - } - for (var k = 0; k < gDeviceList[0].configs[j].interfaces.length; k++) { - //属性预制 - var interfaces = gDeviceList[0].configs[j].interfaces[k]; - interfaces.id = 1; - interfaces.name = ''; - interfaces.alternateSetting = 1; - var isClaim = usb.claimInterface(gPipe, gDeviceList[0].configs[j].interfaces[k], true) - console.info('usb case claimInterface function return: ' + isClaim); - expect(isClaim).assertEqual(0); - if (isClaim == 0) { - isClaim = usb.releaseInterface(gPipe, gDeviceList[0].configs[j].interfaces[k]) - console.info('usb case releaseInterface function return: ' + isClaim); - expect(isClaim).assertEqual(0); - gPipe = usb.connectDevice(gDeviceList[0]) - } - } - } - - console.info('usb SUB_USB_JS_0420 : PASS'); - expect(true).assertTrue(); - }) - - function getTransferParam(iCmd, iReqType, iValue, iIndex) { - var tmpUint8Array = new Uint8Array(512); - var requestCmd = iCmd - var requestType = iReqType - var value = iValue; - var index = iIndex; - var controlParam = { - request: requestCmd, - reqType: requestType, - value: value, - index: index, - data: tmpUint8Array - } - return controlParam - } - - /** - * @tc.number : SUB_USB_JS_0740 - * @tc.name : setConfiguration - * @tc.desc : 设置设备接口 - */ - it('SUB_USB_JS_0740', 0, function () { - console.info('usb SUB_USB_JS_0740 begin'); - if (gDeviceList.length == 0) { - console.info('usb case get_device_list is null') - expect(false).assertTrue(); - return - } - - gPipe = usb.connectDevice(gDeviceList[0]) - for (var j = 0; j < gDeviceList[0].configs.length; j++) { - var configs = gDeviceList[0].configs[j]; - configs.id = 1; - configs.name = ''; - configs.maxPower = 1; - configs.isRemoteWakeup = true; - configs.isSelfPowered = true; - var ret = usb.setConfiguration(gPipe, gDeviceList[0].configs[j]) - console.info('usb case setConfiguration return : ' + ret); - expect(ret).assertEqual(0); - } - - console.info('usb SUB_USB_JS_0740 : PASS'); - expect(true).assertTrue(); - }) - - /** - * @tc.number : SUB_USB_JS_0750 - * @tc.name : setConfiguration - * @tc.desc : 反向测试 设置设备接口 - */ - it('SUB_USB_JS_0750', 0, function () { - console.info('usb SUB_USB_JS_0750 begin'); - if (gDeviceList.length == 0) { - console.info('usb case get_device_list is null') - expect(false).assertTrue(); - return - } - - for (var j = 0; j < gDeviceList[0].configs.length; j++) { - var config = JSON.parse(JSON.stringify(gDeviceList[0].configs[j])); - config.id = 255 - var ret = usb.setConfiguration(gPipe, config) - console.info('usb case setConfiguration return : ' + ret); - expect(ret).assertLess(0); - } - - console.info('usb SUB_USB_JS_0750 : PASS'); - }) - - /** - * @tc.number : SUB_USB_JS_0800 - * @tc.name : setInterface - * @tc.desc : 设置设备接口 - */ - it('SUB_USB_JS_0800', 0, function () { - console.info('usb SUB_USB_JS_0800 begin'); - if (gDeviceList.length == 0) { - console.info('usb case get_device_list is null') - expect(false).assertTrue(); - return - } - - for (var j = 0; j < gDeviceList[0].configs.length; j++) { - var isClaim = usb.claimInterface(gPipe, gDeviceList[0].configs[j].interfaces[0], true) - expect(isClaim).assertEqual(0) - if (isClaim == 0) { - var ret = usb.setInterface(gPipe, gDeviceList[0].configs[j].interfaces[0]) - expect(ret).assertEqual(0); - console.info('usb case setInterface return : ' + ret); - } - } - - console.info('usb SUB_USB_JS_0800 : PASS'); - expect(true).assertTrue(); - }) - - /** - * @tc.number : SUB_USB_JS_0810 - * @tc.name : setInterface - * @tc.desc : 反向测试 设置设备接口 - */ - it('SUB_USB_JS_0810', 0, function () { - console.info('usb SUB_USB_JS_0810 begin'); - if (gDeviceList.length == 0) { - console.info('usb case get_device_list is null') - expect(false).assertTrue() - return - } - - for (var j = 0; j < gDeviceList[0].configs.length; j++) { - var isClaim = usb.claimInterface(gPipe, gDeviceList[0].configs[j].interfaces[0], true) - expect(isClaim).assertEqual(0) - if (isClaim == 0) { - var tmpInterface = JSON.parse(JSON.stringify(gDeviceList[0].configs[j].interfaces[0])); - tmpInterface.id = 234 - var ret = usb.setInterface(gPipe, tmpInterface) - expect(ret).assertLess(0) - console.info('usb case setInterface return : ' + ret) - } - } - - console.info('usb SUB_USB_JS_0810 : PASS'); - expect(true).assertTrue(); - }) - - function callControlTransfer(pip, controlParam, timeout, caseName) { - usb.controlTransfer(pip, controlParam, timeout).then(data => { - console.info('usb controlTransfer ret data : ' + data + ' ' + caseName); - console.info('usb controlTransfer controlParam.data buffer : ' + controlParam.data + ' ' + caseName); - console.info('usb' + caseName + ': PASS'); - expect(true).assertTrue(); - }).catch(error => { - console.info('usb controlTransfer error : ' + JSON.stringify(error)); - console.info('usb' + caseName + ': PASS'); - expect(false).assertTrue(); - }); - } - - /** - * @tc.number : SUB_USB_JS_0540 - * @tc.name : controlTransfer - * @tc.desc : 控制传输 GetDescriptor: cmd 6 reqType 128 value 512 index 0 - */ - it('SUB_USB_JS_0540', 0, function () { - console.info('usb SUB_USB_JS_0540 begin'); - var testParam = getTransferTestParam() - if (testParam.inEndpoint == null || testParam.interface == null || testParam.outEndpoint == null) { - expect(false).assertTrue(); - return - } - - var timeout = 5000; - var controlParam = getTransferParam(6, (usb.USB_REQUEST_DIR_FROM_DEVICE << 7) - | (usb.USB_REQUEST_TYPE_STANDARD << 5) | (usb.USB_REQUEST_TARGET_DEVICE & 0x1f), (2 << 8), 0) - callControlTransfer(testParam.pip, controlParam, timeout, 'SUB_USB_JS_0540 GetDescriptor') - }) - - /** - * @tc.number : SUB_USB_JS_0550 - * @tc.name : controlTransfer - * @tc.desc : 控制传输 GetStatus: cmd 0 reqType 128 value 0 index 0 - */ - it('SUB_USB_JS_0550', 0, function () { - console.info('usb SUB_USB_JS_0550 begin'); - var testParam = getTransferTestParam() - if (testParam.inEndpoint == null || testParam.interface == null || testParam.outEndpoint == null) { - expect(false).assertTrue(); - return - } - - var timeout = 5000; - var controlParam = getTransferParam(0, (usb.USB_REQUEST_DIR_FROM_DEVICE << 7) - | (usb.USB_REQUEST_TYPE_STANDARD << 5) | (usb.USB_REQUEST_TARGET_DEVICE & 0x1f), 0, 0) - callControlTransfer(testParam.pip, controlParam, timeout, 'SUB_USB_JS_0550 GetStatus') - }) - - /** - * @tc.number : SUB_USB_JS_0560 - * @tc.name : controlTransfer - * @tc.desc : 控制传输 GetConfiguration: cmd 8 reqType 128 value 0 index 0 - */ - it('SUB_USB_JS_0560', 0, function () { - console.info('usb SUB_USB_JS_0560 begin'); - var testParam = getTransferTestParam() - if (testParam.inEndpoint == null || testParam.interface == null || testParam.outEndpoint == null) { - expect(false).assertTrue(); - return - } - - var timeout = 5000; - var controlParam = getTransferParam(8, (usb.USB_REQUEST_DIR_FROM_DEVICE << 7) - | (usb.USB_REQUEST_TYPE_STANDARD << 5) | (usb.USB_REQUEST_TARGET_DEVICE & 0x1f), 0, 0) - callControlTransfer(testParam.pip, controlParam, timeout, 'SUB_USB_JS_0560 GetConfiguration') - }) - - /** - * @tc.number : SUB_USB_JS_0570 - * @tc.name : controlTransfer - * @tc.desc : 控制传输 GetInterface: cmd 8 reqType 129 value 0 index 1 - */ - it('SUB_USB_JS_0570', 0, function () { - console.info('usb SUB_USB_JS_0570 begin'); - var testParam = getTransferTestParam() - if (testParam.inEndpoint == null || testParam.interface == null || testParam.outEndpoint == null) { - expect(false).assertTrue(); - return - } - - var timeout = 5000; - var controlParam = getTransferParam(10, (usb.USB_REQUEST_DIR_FROM_DEVICE << 7) - | (usb.USB_REQUEST_TYPE_STANDARD << 5) | (usb.USB_REQUEST_TARGET_INTERFACE & 0x1f), 0, 1) - callControlTransfer(testParam.pip, controlParam, timeout, 'SUB_USB_JS_0570 GetInterface') - }) - - /** - * @tc.number : SUB_USB_JS_0580 - * @tc.name : controlTransfer - * @tc.desc : 控制传输 ClearFeature: cmd 1 reqType 0 value 0 index 0 - */ - it('SUB_USB_JS_0580', 0, function () { - console.info('usb SUB_USB_JS_0580 begin'); - var testParam = getTransferTestParam() - if (testParam.inEndpoint == null || testParam.interface == null || testParam.outEndpoint == null) { - expect(false).assertTrue(); - return - } - - var timeout = 5000; - var controlParam = getTransferParam(1, (usb.USB_REQUEST_DIR_TO_DEVICE << 7) - | (usb.USB_REQUEST_TYPE_STANDARD << 5) | (usb.USB_REQUEST_TARGET_DEVICE & 0x1f), 0, 0) - callControlTransfer(testParam.pip, controlParam, timeout, 'SUB_USB_JS_0580 ClearFeature') - }) - - /** - * @tc.number : SUB_USB_JS_0590 - * @tc.name : controlTransfer - * @tc.desc : 控制传输 ClearFeature: cmd 255 reqType 129 value 512 index 0 - */ - it('SUB_USB_JS_0590', 0, function () { - console.info('usb SUB_USB_JS_0590 begin'); - var testParam = getTransferTestParam() - if (testParam.inEndpoint == null || testParam.interface == null || testParam.outEndpoint == null) { - expect(false).assertTrue(); - return - } - - var timeout = 5000; - var controlParam = getTransferParam(255, (usb.USB_REQUEST_DIR_FROM_DEVICE << 7) - | (usb.USB_REQUEST_TYPE_STANDARD << 5) | (usb.USB_REQUEST_TARGET_INTERFACE & 0x1f), (2 << 8), 0) - callControlTransfer(testParam.pip, controlParam, timeout, 'SUB_USB_JS_0590 ClearFeature') - }) - - /** - * @tc.number : SUB_USB_JS_0600 - * @tc.name : controlTransfer - * @tc.desc : 控制传输 ClearFeature: cmd 255 reqType 3 value 512 index 0 - */ - it('SUB_USB_JS_0600', 0, function () { - console.info('usb SUB_USB_JS_0600 begin'); - var testParam = getTransferTestParam() - if (testParam.inEndpoint == null || testParam.interface == null || testParam.outEndpoint == null) { - expect(false).assertTrue(); - return - } - - var timeout = 5000; - var controlParam = getTransferParam(255, (usb.USB_REQUEST_DIR_TO_DEVICE << 7) - | (usb.USB_REQUEST_TYPE_CLASS << 5) | (usb.USB_REQUEST_TARGET_ENDPOINT & 0x1f), (2 << 8), 0) - callControlTransfer(testParam.pip, controlParam, timeout, 'SUB_USB_JS_0600 ClearFeature') - }) - - /** - * @tc.number : SUB_USB_JS_0610 - * @tc.name : controlTransfer - * @tc.desc : 控制传输 ClearFeature: cmd 255 reqType 5 value 512 index 0 - */ - it('SUB_USB_JS_0610', 0, function () { - console.info('usb SUB_USB_JS_0610 begin'); - var testParam = getTransferTestParam() - if (testParam.inEndpoint == null || testParam.interface == null || testParam.outEndpoint == null) { - expect(false).assertTrue(); - return - } - - var timeout = 5000; - var controlParam = getTransferParam(255, (usb.USB_REQUEST_DIR_TO_DEVICE << 7) - | (usb.USB_REQUEST_TYPE_VENDOR << 5) | (usb.USB_REQUEST_TARGET_OTHER & 0x1f), (2 << 8), 0) - callControlTransfer(testParam.pip, controlParam, timeout, 'SUB_USB_JS_0610 ClearFeature') - }) - - /** - * @tc.number : SUB_USB_JS_0620 - * @tc.name : controlTransfer - * @tc.desc : 控制传输 ClearFeature: cmd 255 reqType 4 value 0 index 0 - */ - it('SUB_USB_JS_0620', 0, function () { - console.info('usb SUB_USB_JS_0620 begin'); - var testParam = getTransferTestParam() - if (testParam.inEndpoint == null || testParam.interface == null || testParam.outEndpoint == null) { - expect(false).assertTrue(); - return - } - - var timeout = 5000; - var controlParam = getTransferParam(255, (usb.USB_REQUEST_DIR_TO_DEVICE << 7) - | (usb.USB_REQUEST_TYPE_CLASS << 5) | (usb.USB_REQUEST_TARGET_OTHER & 0x1f), 0, 0) - callControlTransfer(testParam.pip, controlParam, timeout, 'SUB_USB_JS_0620 ClearFeature') - }) - -}) +/* + * Copyright (c) 2021-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 usb from '@ohos.usb'; +import CheckEmptyUtils from './CheckEmptyUtils.js'; +import EventConstants from './EventConstants.js'; +import parameter from '@ohos.systemparameter'; +import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from '@ohos/hypium' + +/* usb device pipe test */ +export default function UsbDevicePipeJsFunctionsTest() { +describe('UsbDevicePipeJsFunctionsTest', function () { + var gDeviceList + var gPipe + var portCurrentMode + + beforeAll(function () { + console.log('*************Usb Unit UsbDevicePipeJsFunctionsTest Begin*************'); + var Version = usb.getVersion() + console.info('usb unit begin test getversion :' + Version) + // version > 17 host currentMode = 2 device currentMode = 1 + var usbPortList = usb.getPorts() + gDeviceList = usb.getDevices(); + if (usbPortList.length > 0) { + if (gDeviceList.length > 0) { + if (usbPortList[0].status.currentMode == 1) { + usb.setPortRoles(usbPortList[0].id, usb.SOURCE, usb.HOST).then(data => { + portCurrentMode = 2 + console.info('usb case setPortRoles return: ' + data); + }).catch(error => { + console.info('usb case setPortRoles error : ' + error); + }); + console.log('*************Usb Unit switch to host Begin*************'); + } + } else { + portCurrentMode = 1 + } + + } + + gDeviceList = usb.getDevices(); + gDeviceList[0].name; + gDeviceList[0].version; + gDeviceList[0].configs; + gPipe = usb.connectDevice(gDeviceList[0]) + console.info('usb unit connectDevice gPipe ret : ' + JSON.stringify(gPipe)); + }) + + beforeEach(function () { + console.info('beforeEach: *************Usb Unit Test Case*************'); + }) + afterEach(function () { + console.info('afterEach: *************Usb Unit Test Case*************'); + }) + + afterAll(function () { + var isPipClose = usb.closePipe(gPipe) + console.info('usb unit close gPipe ret : ' + isPipClose); + console.log('*************Usb Unit UsbDevicePipeJsFunctionsTest End*************'); + }) + + function findInitPoint(testParam, j) { + var bfind = false + for (var k = 0; k < testParam.config.interfaces[j].endpoints.length; k++) { + var endpoint = testParam.config.interfaces[j].endpoints[k]; + endpoint.number = 1; + endpoint.type = 1; + endpoint.interfaceid = 1; + if (endpoint.type == EventConstants.USB_ENDPOINT_XFER_BULK) { + bfind = true + if (endpoint.direction == usb.USB_REQUEST_DIR_TO_DEVICE) { + testParam.maxOutSize = endpoint.maxPacketSize; + testParam.outEndpoint = endpoint; + } else if (endpoint.direction == usb.USB_REQUEST_DIR_FROM_DEVICE) { + testParam.maxInSize = endpoint.maxPacketSize; + testParam.inEndpoint = endpoint + } + } + } + if (bfind) { + testParam.interface = testParam.config.interfaces[j] + return bfind + } + return false + } + + function getFlag(testParam, j) { + if (testParam.config.interfaces[j].endpoints.length == 0) { + return false + } + + if (testParam.config.interfaces[j].clazz != 10 || + testParam.config.interfaces[j].subclass != 0 || + testParam.config.interfaces[j].protocol != 2) { + return false + } + return true + } + + function initPoint(testParam) { + for (var j = 0; j < testParam.config.interfaces.length; j++) { + if (getFlag(testParam, j) == true) { + if (findInitPoint(testParam, j) == true) { + break + } + } + } + } + + function getTransferTestParam() { + var testParam = { + config: null, + device: null, + pip: null, + inEndpoint: null, + interface: null, + outEndpoint: null, + usbRequest: null, + sendData: '', + isClaimed: 0, + maxInSize: 1024, + maxOutSize: 1024 + } + + console.info('usb case gDeviceList.length: ' + gDeviceList.length); + for (var i = 0; i < gDeviceList.length; i++) { + testParam.device = gDeviceList[i] + testParam.config = testParam.device.configs[0] + testParam.pip = gPipe + initPoint(testParam) + } + return testParam + } + + /** + * @tc.number : SUB_USB_JS_0630 + * @tc.name : bulkTransfer + * @tc.desc : 批量传输 收数据 + */ + it('SUB_USB_JS_0630', 0, function () { + console.info('usb SUB_USB_JS_0630 begin'); + var testParam = getTransferTestParam() + if (testParam.interface == null || testParam.inEndpoint == null) { + expect(false).assertTrue(); + return + } + + testParam.isClaimed = usb.claimInterface(testParam.pip, testParam.interface, true); + expect(testParam.isClaimed).assertEqual(0); + + console.info('usb case readData begin'); + var tmpUint8Array = new Uint8Array(testParam.maxInSize); + usb.bulkTransfer(testParam.pip, testParam.inEndpoint, tmpUint8Array, 5000).then(data => { + console.info('usb case readData tmpUint8Array buffer : ' + CheckEmptyUtils.ab2str(tmpUint8Array)); + console.info('usb case readData ret: ' + data); + console.info('usb case SUB_USB_JS_0630 : PASS'); + expect(data >= 0).assertTrue(); + }).catch(error => { + console.info('usb case readData error : ' + JSON.stringify(error)); + expect(false).assertTrue(); + }); + }) + + /** + * @tc.number : SUB_USB_JS_0640 + * @tc.name : bulkTransfer + * @tc.desc : 批量传输 发数据 + */ + it('SUB_USB_JS_0640', 0, function () { + console.info('usb SUB_USB_JS_0640 begin'); + var testParam = getTransferTestParam() + if (testParam.interface == null || testParam.outEndpoint == null) { + expect(false).assertTrue(); + return + } + + testParam.isClaimed = usb.claimInterface(testParam.pip, testParam.interface, true); + expect(testParam.isClaimed).assertEqual(0); + + testParam.sendData = 'send default'; + try { + testParam.sendData = parameter.getSync('test_usb', 'default'); + console.log('usb parameter ' + JSON.stringify(testParam.sendData)); + } catch (e) { + console.log('usb parameter getSync unexpected error: ' + e); + } + + var tmpUint8Array = CheckEmptyUtils.str2ab(testParam.sendData); + usb.bulkTransfer(testParam.pip, testParam.outEndpoint, tmpUint8Array, 5000).then(data => { + console.info('usb case SUB_USB_JS_0640 ret: ' + data); + console.info('usb case SUB_USB_JS_0640 send data: ' + testParam.sendData); + console.info('usb case SUB_USB_JS_0640 : PASS'); + expect(true).assertTrue(); + }).catch(error => { + console.info('usb write error : ' + JSON.stringify(error)); + expect(false).assertTrue(); + }); + + }) + + /** + * @tc.number : SUB_USB_JS_0420 + * @tc.name : claimInterface + * @tc.desc : 获取接口 并释放 + */ + it('SUB_USB_JS_0420', 0, function () { + console.info('usb SUB_USB_JS_0420 begin'); + if (gDeviceList.length == 0) { + console.info('usb 01 case get_device_list is null') + expect(gDeviceList.length).assertEqual(-1); + return + } + + if (gDeviceList[0].configs.length == 0) { + console.info('usb 01 case current device.configs.length = 0'); + expect(false).assertTrue(); + return + } + + for (var j = 0; j < gDeviceList[0].configs.length; j++) { + if (gDeviceList[0].configs[j].interfaces.length == 0) { + console.info('usb case current device.configs.interfaces.length = 0'); + } + for (var k = 0; k < gDeviceList[0].configs[j].interfaces.length; k++) { + //属性预制 + var interfaces = gDeviceList[0].configs[j].interfaces[k]; + interfaces.id = 1; + interfaces.name = ''; + interfaces.alternateSetting = 1; + var isClaim = usb.claimInterface(gPipe, gDeviceList[0].configs[j].interfaces[k], true) + console.info('usb case claimInterface function return: ' + isClaim); + expect(isClaim).assertEqual(0); + if (isClaim == 0) { + isClaim = usb.releaseInterface(gPipe, gDeviceList[0].configs[j].interfaces[k]) + console.info('usb case releaseInterface function return: ' + isClaim); + expect(isClaim).assertEqual(0); + gPipe = usb.connectDevice(gDeviceList[0]) + } + } + } + + console.info('usb SUB_USB_JS_0420 : PASS'); + expect(true).assertTrue(); + }) + + function getTransferParam(iCmd, iReqType, iValue, iIndex) { + var tmpUint8Array = new Uint8Array(512); + var requestCmd = iCmd + var requestType = iReqType + var value = iValue; + var index = iIndex; + var controlParam = { + request: requestCmd, + reqType: requestType, + value: value, + index: index, + data: tmpUint8Array + } + return controlParam + } + + /** + * @tc.number : SUB_USB_JS_0740 + * @tc.name : setConfiguration + * @tc.desc : 设置设备接口 + */ + it('SUB_USB_JS_0740', 0, function () { + console.info('usb SUB_USB_JS_0740 begin'); + if (gDeviceList.length == 0) { + console.info('usb case get_device_list is null') + expect(false).assertTrue(); + return + } + + gPipe = usb.connectDevice(gDeviceList[0]) + for (var j = 0; j < gDeviceList[0].configs.length; j++) { + var configs = gDeviceList[0].configs[j]; + configs.id = 1; + configs.name = ''; + configs.maxPower = 1; + configs.isRemoteWakeup = true; + configs.isSelfPowered = true; + var ret = usb.setConfiguration(gPipe, gDeviceList[0].configs[j]) + console.info('usb case setConfiguration return : ' + ret); + expect(ret).assertEqual(0); + } + + console.info('usb SUB_USB_JS_0740 : PASS'); + expect(true).assertTrue(); + }) + + /** + * @tc.number : SUB_USB_JS_0750 + * @tc.name : setConfiguration + * @tc.desc : 反向测试 设置设备接口 + */ + it('SUB_USB_JS_0750', 0, function () { + console.info('usb SUB_USB_JS_0750 begin'); + if (gDeviceList.length == 0) { + console.info('usb case get_device_list is null') + expect(false).assertTrue(); + return + } + + for (var j = 0; j < gDeviceList[0].configs.length; j++) { + var config = JSON.parse(JSON.stringify(gDeviceList[0].configs[j])); + config.id = 255 + var ret = usb.setConfiguration(gPipe, config) + console.info('usb case setConfiguration return : ' + ret); + expect(ret).assertLess(0); + } + + console.info('usb SUB_USB_JS_0750 : PASS'); + }) + + /** + * @tc.number : SUB_USB_JS_0800 + * @tc.name : setInterface + * @tc.desc : 设置设备接口 + */ + it('SUB_USB_JS_0800', 0, function () { + console.info('usb SUB_USB_JS_0800 begin'); + if (gDeviceList.length == 0) { + console.info('usb case get_device_list is null') + expect(false).assertTrue(); + return + } + + for (var j = 0; j < gDeviceList[0].configs.length; j++) { + var isClaim = usb.claimInterface(gPipe, gDeviceList[0].configs[j].interfaces[0], true) + expect(isClaim).assertEqual(0) + if (isClaim == 0) { + var ret = usb.setInterface(gPipe, gDeviceList[0].configs[j].interfaces[0]) + expect(ret).assertEqual(0); + console.info('usb case setInterface return : ' + ret); + } + } + + console.info('usb SUB_USB_JS_0800 : PASS'); + expect(true).assertTrue(); + }) + + /** + * @tc.number : SUB_USB_JS_0810 + * @tc.name : setInterface + * @tc.desc : 反向测试 设置设备接口 + */ + it('SUB_USB_JS_0810', 0, function () { + console.info('usb SUB_USB_JS_0810 begin'); + if (gDeviceList.length == 0) { + console.info('usb case get_device_list is null') + expect(false).assertTrue() + return + } + + for (var j = 0; j < gDeviceList[0].configs.length; j++) { + var isClaim = usb.claimInterface(gPipe, gDeviceList[0].configs[j].interfaces[0], true) + expect(isClaim).assertEqual(0) + if (isClaim == 0) { + var tmpInterface = JSON.parse(JSON.stringify(gDeviceList[0].configs[j].interfaces[0])); + tmpInterface.id = 234 + var ret = usb.setInterface(gPipe, tmpInterface) + expect(ret).assertLess(0) + console.info('usb case setInterface return : ' + ret) + } + } + + console.info('usb SUB_USB_JS_0810 : PASS'); + expect(true).assertTrue(); + }) + + function callControlTransfer(pip, controlParam, timeout, caseName) { + usb.controlTransfer(pip, controlParam, timeout).then(data => { + console.info('usb controlTransfer ret data : ' + data + ' ' + caseName); + console.info('usb controlTransfer controlParam.data buffer : ' + controlParam.data + ' ' + caseName); + console.info('usb' + caseName + ': PASS'); + expect(true).assertTrue(); + }).catch(error => { + console.info('usb controlTransfer error : ' + JSON.stringify(error)); + console.info('usb' + caseName + ': PASS'); + expect(false).assertTrue(); + }); + } + + /** + * @tc.number : SUB_USB_JS_0540 + * @tc.name : controlTransfer + * @tc.desc : 控制传输 GetDescriptor: cmd 6 reqType 128 value 512 index 0 + */ + it('SUB_USB_JS_0540', 0, function () { + console.info('usb SUB_USB_JS_0540 begin'); + var testParam = getTransferTestParam() + if (testParam.inEndpoint == null || testParam.interface == null || testParam.outEndpoint == null) { + expect(false).assertTrue(); + return + } + + var timeout = 5000; + var controlParam = getTransferParam(6, (usb.USB_REQUEST_DIR_FROM_DEVICE << 7) + | (usb.USB_REQUEST_TYPE_STANDARD << 5) | (usb.USB_REQUEST_TARGET_DEVICE & 0x1f), (2 << 8), 0) + callControlTransfer(testParam.pip, controlParam, timeout, 'SUB_USB_JS_0540 GetDescriptor') + }) + + /** + * @tc.number : SUB_USB_JS_0550 + * @tc.name : controlTransfer + * @tc.desc : 控制传输 GetStatus: cmd 0 reqType 128 value 0 index 0 + */ + it('SUB_USB_JS_0550', 0, function () { + console.info('usb SUB_USB_JS_0550 begin'); + var testParam = getTransferTestParam() + if (testParam.inEndpoint == null || testParam.interface == null || testParam.outEndpoint == null) { + expect(false).assertTrue(); + return + } + + var timeout = 5000; + var controlParam = getTransferParam(0, (usb.USB_REQUEST_DIR_FROM_DEVICE << 7) + | (usb.USB_REQUEST_TYPE_STANDARD << 5) | (usb.USB_REQUEST_TARGET_DEVICE & 0x1f), 0, 0) + callControlTransfer(testParam.pip, controlParam, timeout, 'SUB_USB_JS_0550 GetStatus') + }) + + /** + * @tc.number : SUB_USB_JS_0560 + * @tc.name : controlTransfer + * @tc.desc : 控制传输 GetConfiguration: cmd 8 reqType 128 value 0 index 0 + */ + it('SUB_USB_JS_0560', 0, function () { + console.info('usb SUB_USB_JS_0560 begin'); + var testParam = getTransferTestParam() + if (testParam.inEndpoint == null || testParam.interface == null || testParam.outEndpoint == null) { + expect(false).assertTrue(); + return + } + + var timeout = 5000; + var controlParam = getTransferParam(8, (usb.USB_REQUEST_DIR_FROM_DEVICE << 7) + | (usb.USB_REQUEST_TYPE_STANDARD << 5) | (usb.USB_REQUEST_TARGET_DEVICE & 0x1f), 0, 0) + callControlTransfer(testParam.pip, controlParam, timeout, 'SUB_USB_JS_0560 GetConfiguration') + }) + + /** + * @tc.number : SUB_USB_JS_0570 + * @tc.name : controlTransfer + * @tc.desc : 控制传输 GetInterface: cmd 8 reqType 129 value 0 index 1 + */ + it('SUB_USB_JS_0570', 0, function () { + console.info('usb SUB_USB_JS_0570 begin'); + var testParam = getTransferTestParam() + if (testParam.inEndpoint == null || testParam.interface == null || testParam.outEndpoint == null) { + expect(false).assertTrue(); + return + } + + var timeout = 5000; + var controlParam = getTransferParam(10, (usb.USB_REQUEST_DIR_FROM_DEVICE << 7) + | (usb.USB_REQUEST_TYPE_STANDARD << 5) | (usb.USB_REQUEST_TARGET_INTERFACE & 0x1f), 0, 1) + callControlTransfer(testParam.pip, controlParam, timeout, 'SUB_USB_JS_0570 GetInterface') + }) + + /** + * @tc.number : SUB_USB_JS_0580 + * @tc.name : controlTransfer + * @tc.desc : 控制传输 ClearFeature: cmd 1 reqType 0 value 0 index 0 + */ + it('SUB_USB_JS_0580', 0, function () { + console.info('usb SUB_USB_JS_0580 begin'); + var testParam = getTransferTestParam() + if (testParam.inEndpoint == null || testParam.interface == null || testParam.outEndpoint == null) { + expect(false).assertTrue(); + return + } + + var timeout = 5000; + var controlParam = getTransferParam(1, (usb.USB_REQUEST_DIR_TO_DEVICE << 7) + | (usb.USB_REQUEST_TYPE_STANDARD << 5) | (usb.USB_REQUEST_TARGET_DEVICE & 0x1f), 0, 0) + callControlTransfer(testParam.pip, controlParam, timeout, 'SUB_USB_JS_0580 ClearFeature') + }) + + /** + * @tc.number : SUB_USB_JS_0590 + * @tc.name : controlTransfer + * @tc.desc : 控制传输 ClearFeature: cmd 255 reqType 129 value 512 index 0 + */ + it('SUB_USB_JS_0590', 0, function () { + console.info('usb SUB_USB_JS_0590 begin'); + var testParam = getTransferTestParam() + if (testParam.inEndpoint == null || testParam.interface == null || testParam.outEndpoint == null) { + expect(false).assertTrue(); + return + } + + var timeout = 5000; + var controlParam = getTransferParam(255, (usb.USB_REQUEST_DIR_FROM_DEVICE << 7) + | (usb.USB_REQUEST_TYPE_STANDARD << 5) | (usb.USB_REQUEST_TARGET_INTERFACE & 0x1f), (2 << 8), 0) + callControlTransfer(testParam.pip, controlParam, timeout, 'SUB_USB_JS_0590 ClearFeature') + }) + + /** + * @tc.number : SUB_USB_JS_0600 + * @tc.name : controlTransfer + * @tc.desc : 控制传输 ClearFeature: cmd 255 reqType 3 value 512 index 0 + */ + it('SUB_USB_JS_0600', 0, function () { + console.info('usb SUB_USB_JS_0600 begin'); + var testParam = getTransferTestParam() + if (testParam.inEndpoint == null || testParam.interface == null || testParam.outEndpoint == null) { + expect(false).assertTrue(); + return + } + + var timeout = 5000; + var controlParam = getTransferParam(255, (usb.USB_REQUEST_DIR_TO_DEVICE << 7) + | (usb.USB_REQUEST_TYPE_CLASS << 5) | (usb.USB_REQUEST_TARGET_ENDPOINT & 0x1f), (2 << 8), 0) + callControlTransfer(testParam.pip, controlParam, timeout, 'SUB_USB_JS_0600 ClearFeature') + }) + + /** + * @tc.number : SUB_USB_JS_0610 + * @tc.name : controlTransfer + * @tc.desc : 控制传输 ClearFeature: cmd 255 reqType 5 value 512 index 0 + */ + it('SUB_USB_JS_0610', 0, function () { + console.info('usb SUB_USB_JS_0610 begin'); + var testParam = getTransferTestParam() + if (testParam.inEndpoint == null || testParam.interface == null || testParam.outEndpoint == null) { + expect(false).assertTrue(); + return + } + + var timeout = 5000; + var controlParam = getTransferParam(255, (usb.USB_REQUEST_DIR_TO_DEVICE << 7) + | (usb.USB_REQUEST_TYPE_VENDOR << 5) | (usb.USB_REQUEST_TARGET_OTHER & 0x1f), (2 << 8), 0) + callControlTransfer(testParam.pip, controlParam, timeout, 'SUB_USB_JS_0610 ClearFeature') + }) + + /** + * @tc.number : SUB_USB_JS_0620 + * @tc.name : controlTransfer + * @tc.desc : 控制传输 ClearFeature: cmd 255 reqType 4 value 0 index 0 + */ + it('SUB_USB_JS_0620', 0, function () { + console.info('usb SUB_USB_JS_0620 begin'); + var testParam = getTransferTestParam() + if (testParam.inEndpoint == null || testParam.interface == null || testParam.outEndpoint == null) { + expect(false).assertTrue(); + return + } + + var timeout = 5000; + var controlParam = getTransferParam(255, (usb.USB_REQUEST_DIR_TO_DEVICE << 7) + | (usb.USB_REQUEST_TYPE_CLASS << 5) | (usb.USB_REQUEST_TARGET_OTHER & 0x1f), 0, 0) + callControlTransfer(testParam.pip, controlParam, timeout, 'SUB_USB_JS_0620 ClearFeature') + }) + +}) +} diff --git a/usb/usb_standard/src/main/js/default/test/UsbFunctionsJsunit.test.js b/usb/usb_standard/src/main/js/test/UsbFunctionsJsunit.test.js old mode 100755 new mode 100644 similarity index 95% rename from usb/usb_standard/src/main/js/default/test/UsbFunctionsJsunit.test.js rename to usb/usb_standard/src/main/js/test/UsbFunctionsJsunit.test.js index 2a4f0e33082dcfd672a33ad88517b679b471bbd8..a436e212c0c5f5f73be77f1d4309af3a222ea923 --- a/usb/usb_standard/src/main/js/default/test/UsbFunctionsJsunit.test.js +++ b/usb/usb_standard/src/main/js/test/UsbFunctionsJsunit.test.js @@ -1,98 +1,100 @@ -/* - * Copyright (c) 2021-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 usb from '@ohos.usb'; -import CheckEmptyUtils from './CheckEmptyUtils.js'; -import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from 'deccjsunit/index' - -/* usb core functions test */ -describe('UsbFunctionsJsFunctionsTest', function () { - - beforeAll(function () { - console.log('*************Usb Unit UsbFunctionsJsFunctionsTest Begin*************'); - var Version = usb.getVersion() - console.info('begin test getversion :' + Version) - // version > 17 host currentMode = 2 device currentMode = 1 - var usbPortList = usb.getPorts() - if (usbPortList.length > 0) { - if (usbPortList[0].status.currentMode == 2) { - usb.setPortRoles(usbPortList[0].id, usb.SINK, usb.DEVICE).then(data => { - console.info('usb case setPortRoles return: ' + data); - }).catch(error => { - console.info('usb case setPortRoles error : ' + error); - }); - console.log('*************Usb Unit switch to device Begin*************'); - } - } - }) - beforeEach(function () { - console.info('beforeEach: *************Usb Unit Test Case*************'); - }) - afterEach(function () { - console.info('afterEach: *************Usb Unit Test Case*************'); - }) - afterAll(function () { - console.log('*************Usb Unit UsbFunctionsJsFunctionsTest End*************'); - }) - - /** - * @tc.number : SUB_USB_JS_0330 - * @tc.name : getCurrentFunctions - * @tc.desc : 获取当前设备模式 掩码与描述字符转换 - */ - it('SUB_USB_JS_0330', 0, function () { - console.info('usb SUB_USB_JS_0330 begin'); - var maskCode = usb.getCurrentFunctions(); - console.info('usb case getCurrentFunctions return: ' + maskCode); - - var strMaskCode = usb.usbFunctionsToString(maskCode) - console.info('usb case usbFunctionsToString return str: ' + strMaskCode); - var nMaskCode = usb.usbFunctionsFromString(strMaskCode) - console.info('usb case strMaskCode usbFunctionsFromString return int: ' + nMaskCode); - expect(nMaskCode).assertEqual(maskCode); - console.info('usb SUB_USB_JS_0330 : PASS'); - expect(true).assertTrue(); - }) - - /** - * @tc.number : SUB_USB_JS_0340 - * @tc.name : usbFunctionString - * @tc.desc : 反向测试 获取当前设备模式 掩码与描述字符转换 - */ - it('SUB_USB_JS_0340', 0, function () { - console.info('usb SUB_USB_JS_0340 begin'); - var maskCode = usb.getCurrentFunctions(); - console.info('usb case getCurrentFunctions return: ' + maskCode); - - var strMaskCode = usb.usbFunctionsToString(maskCode) - console.info('usb case usbFunctionsToString return str: ' + strMaskCode); - var nMaskCode = usb.usbFunctionsFromString(strMaskCode) - console.info('usb case strMaskCode usbFunctionsFromString return int: ' + nMaskCode); - - var errmaskCode = 0 - var strMaskCode = usb.usbFunctionsToString(errmaskCode) - - console.info('usb case ' + errmaskCode + ' usbFunctionsToString return str: ' + strMaskCode); - - var errStrMaskCode = 'none' - var nMaskCode = usb.usbFunctionsFromString(errStrMaskCode) - expect(nMaskCode).assertEqual(usb.NONE); - console.info('usb case errStrMaskCode ' + errStrMaskCode + - ' usbFunctionsFromString return int: ' + nMaskCode); - - console.info('usb SUB_USB_JS_0340 : PASS'); - }) - -}) +/* + * Copyright (c) 2021-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 usb from '@ohos.usb'; +import CheckEmptyUtils from './CheckEmptyUtils.js'; +import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from '@ohos/hypium' + +/* usb core functions test */ +export default function UsbFunctionsJsFunctionsTest() { +describe('UsbFunctionsJsFunctionsTest', function () { + + beforeAll(function () { + console.log('*************Usb Unit UsbFunctionsJsFunctionsTest Begin*************'); + var Version = usb.getVersion() + console.info('begin test getversion :' + Version) + // version > 17 host currentMode = 2 device currentMode = 1 + var usbPortList = usb.getPorts() + if (usbPortList.length > 0) { + if (usbPortList[0].status.currentMode == 2) { + usb.setPortRoles(usbPortList[0].id, usb.SINK, usb.DEVICE).then(data => { + console.info('usb case setPortRoles return: ' + data); + }).catch(error => { + console.info('usb case setPortRoles error : ' + error); + }); + console.log('*************Usb Unit switch to device Begin*************'); + } + } + }) + beforeEach(function () { + console.info('beforeEach: *************Usb Unit Test Case*************'); + }) + afterEach(function () { + console.info('afterEach: *************Usb Unit Test Case*************'); + }) + afterAll(function () { + console.log('*************Usb Unit UsbFunctionsJsFunctionsTest End*************'); + }) + + /** + * @tc.number : SUB_USB_JS_0330 + * @tc.name : getCurrentFunctions + * @tc.desc : 获取当前设备模式 掩码与描述字符转换 + */ + it('SUB_USB_JS_0330', 0, function () { + console.info('usb SUB_USB_JS_0330 begin'); + var maskCode = usb.getCurrentFunctions(); + console.info('usb case getCurrentFunctions return: ' + maskCode); + + var strMaskCode = usb.usbFunctionsToString(maskCode) + console.info('usb case usbFunctionsToString return str: ' + strMaskCode); + var nMaskCode = usb.usbFunctionsFromString(strMaskCode) + console.info('usb case strMaskCode usbFunctionsFromString return int: ' + nMaskCode); + expect(nMaskCode).assertEqual(maskCode); + console.info('usb SUB_USB_JS_0330 : PASS'); + expect(true).assertTrue(); + }) + + /** + * @tc.number : SUB_USB_JS_0340 + * @tc.name : usbFunctionString + * @tc.desc : 反向测试 获取当前设备模式 掩码与描述字符转换 + */ + it('SUB_USB_JS_0340', 0, function () { + console.info('usb SUB_USB_JS_0340 begin'); + var maskCode = usb.getCurrentFunctions(); + console.info('usb case getCurrentFunctions return: ' + maskCode); + + var strMaskCode = usb.usbFunctionsToString(maskCode) + console.info('usb case usbFunctionsToString return str: ' + strMaskCode); + var nMaskCode = usb.usbFunctionsFromString(strMaskCode) + console.info('usb case strMaskCode usbFunctionsFromString return int: ' + nMaskCode); + + var errmaskCode = 0 + var strMaskCode = usb.usbFunctionsToString(errmaskCode) + + console.info('usb case ' + errmaskCode + ' usbFunctionsToString return str: ' + strMaskCode); + + var errStrMaskCode = 'none' + var nMaskCode = usb.usbFunctionsFromString(errStrMaskCode) + expect(nMaskCode).assertEqual(usb.NONE); + console.info('usb case errStrMaskCode ' + errStrMaskCode + + ' usbFunctionsFromString return int: ' + nMaskCode); + + console.info('usb SUB_USB_JS_0340 : PASS'); + }) + +}) +} diff --git a/usb/usb_standard/src/main/js/default/test/UsbFunctionsJsunitEx.test.js b/usb/usb_standard/src/main/js/test/UsbFunctionsJsunitEx.test.js old mode 100755 new mode 100644 similarity index 96% rename from usb/usb_standard/src/main/js/default/test/UsbFunctionsJsunitEx.test.js rename to usb/usb_standard/src/main/js/test/UsbFunctionsJsunitEx.test.js index 3e416ca5395a9e6cbf777ababb6d6b09efee1b7a..ab794fe7108aa8f54fd739662c6367b22dd3114e --- a/usb/usb_standard/src/main/js/default/test/UsbFunctionsJsunitEx.test.js +++ b/usb/usb_standard/src/main/js/test/UsbFunctionsJsunitEx.test.js @@ -1,255 +1,257 @@ -/* - * Copyright (C) 2021-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 usb from '@ohos.usb'; -import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from 'deccjsunit/index' - -/* usb core functions test */ -describe('UsbFunctionsJsFunctionsTestEx', function () { - - beforeAll(function () { - console.log('*************Usb Unit UsbFunctionsJsFunctionsTestEx Begin*************'); - var Version = usb.getVersion() - console.info('begin test getversion :' + Version) - // 17 version host currentMode = 2 device currentMode = 1 - var usbPortList = usb.getPorts() - if (usbPortList.length > 0) { - if (usbPortList[0].status.currentMode == 2) { - usb.setPortRoles(usbPortList[0].id, usb.SINK, usb.DEVICE).then(data => { - console.info('usb case setPortRoles return: ' + data); - }).catch(error => { - console.info('usb case setPortRoles error : ' + error); - }); - - console.log('*************Usb Unit switch to device Begin*************'); - } - } - }) - beforeEach(function () { - console.info('beforeEach: *************Usb Unit Test Case*************'); - }) - - afterEach(function () { - console.info('afterEach: *************Usb Unit Test Case*************'); - }) - - afterAll(function () { - console.log('*************Usb Unit UsbFunctionsJsFunctionsTest End*************'); - }) - - /** - * @tc.number : SUB_USB_JS_0930 - * @tc.name : usbFunctionsToString - * @tc.desc : 正向测试 0 返回 'none' - */ - it('SUB_USB_JS_0930', 0, function () { - console.info('usb SUB_USB_JS_0930 begin'); - var maskCode = usb.NONE - console.info('usb case maskCode : ' + usb.NONE); - var strMaskCode = usb.usbFunctionsToString(maskCode) - expect(strMaskCode).assertEqual('none'); - console.info('usb case maskCode ' + maskCode + ' usbFunctionsToString return int: ' + strMaskCode); - console.info('usb SUB_USB_JS_0930 : PASS'); - }) - - /** - * @tc.number : SUB_USB_JS_0940 - * @tc.name : usbFunctionsToString - * @tc.desc : 正向测试 1 返回 'acm' - */ - it('SUB_USB_JS_0940', 0, function () { - console.info('usb SUB_USB_JS_0940 begin'); - var maskCode = usb.ACM - console.info('usb case maskCode : ' + usb.ACM); - var strMaskCode = usb.usbFunctionsToString(maskCode) - expect(strMaskCode).assertEqual('acm'); - console.info('usb case maskCode ' + maskCode + ' usbFunctionsToString return int: ' + strMaskCode); - console.info('usb SUB_USB_JS_0940 : PASS'); - }) - - /** - * @tc.number : SUB_USB_JS_0950 - * @tc.name : usbFunctionsToString - * @tc.desc : 正向测试 2 返回 'ecm' - */ - it('SUB_USB_JS_0950', 0, function () { - console.info('usb SUB_USB_JS_0950 begin'); - var maskCode = usb.ECM - console.info('usb case maskCode : ' + maskCode); - var strMaskCode = usb.usbFunctionsToString(maskCode) - expect(strMaskCode).assertEqual('ecm'); - console.info('usb case maskCode ' + maskCode + ' usbFunctionsToString return int: ' + strMaskCode); - console.info('usb SUB_USB_JS_0950 : PASS'); - }) - - /** - * @tc.number : SUB_USB_JS_0960 - * @tc.name : usbFunctionsToString - * @tc.desc : 正向测试 3 返回 'acm,ecm' - */ - it('SUB_USB_JS_0960', 0, function () { - console.info('usb SUB_USB_JS_0960 begin'); - var maskCode = usb.ACM | usb.ECM - console.info('usb case maskCode : ' + maskCode); - var strMaskCode = usb.usbFunctionsToString(maskCode) - expect(strMaskCode).assertEqual('acm,ecm'); - console.info('usb case maskCode ' + maskCode + ' usbFunctionsToString return int: ' + strMaskCode); - console.info('usb SUB_USB_JS_0960 : PASS'); - }) - - /** - * @tc.number : SUB_USB_JS_0970 - * @tc.name : usbFunctionsToString - * @tc.desc : 正向测试 4 返回 'hdc' - */ - it('SUB_USB_JS_0970', 0, function () { - console.info('usb SUB_USB_JS_0970 begin'); - var maskCode = usb.HDC - console.info('usb case maskCode : ' + maskCode); - var strMaskCode = usb.usbFunctionsToString(maskCode) - expect(strMaskCode).assertEqual('hdc'); - console.info('usb case maskCode ' + maskCode + ' usbFunctionsToString return int: ' + strMaskCode); - console.info('usb SUB_USB_JS_0970 : PASS'); - }) - - /** - * @tc.number : SUB_USB_JS_0980 - * @tc.name : usbFunctionsToString - * @tc.desc : 正向测试 5 返回 'acm,hdc' - */ - it('SUB_USB_JS_0980', 0, function () { - console.info('usb SUB_USB_JS_0980 begin'); - var maskCode = usb.ACM | usb.HDC - console.info('usb case maskCode : ' + maskCode); - var strMaskCode = usb.usbFunctionsToString(maskCode) - expect(strMaskCode).assertEqual('hdc,acm'); - console.info('usb case maskCode ' + maskCode + ' usbFunctionsToString return int: ' + strMaskCode); - console.info('usb SUB_USB_JS_0980 : PASS'); - }) - - /** - * @tc.number : SUB_USB_JS_0990 - * @tc.name : usbFunctionsToString - * @tc.desc : 正向测试 6 返回 'ecm,hdc' - */ - it('SUB_USB_JS_0990', 0, function () { - console.info('usb SUB_USB_JS_0990 begin'); - var maskCode = usb.ECM | usb.HDC - console.info('usb case maskCode : ' + maskCode); - var strMaskCode = usb.usbFunctionsToString(maskCode) - expect(strMaskCode).assertEqual('hdc,ecm'); - console.info('usb case maskCode ' + maskCode + ' usbFunctionsToString return int: ' + strMaskCode); - console.info('usb SUB_USB_JS_0990 : PASS'); - }) - - /** - * @tc.number : SUB_USB_JS_0860 - * @tc.name : usbFunctionsFromString - * @tc.desc : 正向测试 'none' 返回 0 - */ - it('SUB_USB_JS_0860', 0, function () { - console.info('usb SUB_USB_JS_0860 begin'); - var strMaskCode = 'none' - var nMaskCode = usb.usbFunctionsFromString(strMaskCode) - expect(nMaskCode).assertEqual(usb.NONE); - console.info('usb case strMaskCode ' + strMaskCode + ' usbFunctionsFromString return int: ' + nMaskCode); - console.info('usb SUB_USB_JS_0860 : PASS'); - }) - - /** - * @tc.number : SUB_USB_JS_0870 - * @tc.name : usbFunctionsFromString - * @tc.desc : 正向测试 'acm' 返回 1 - */ - it('SUB_USB_JS_0870', 0, function () { - console.info('usb SUB_USB_JS_0870 begin'); - var strMaskCode = 'acm' - var nMaskCode = usb.usbFunctionsFromString(strMaskCode) - expect(nMaskCode).assertEqual(usb.ACM); - console.info('usb case strMaskCode ' + strMaskCode + ' usbFunctionsFromString return int: ' + nMaskCode); - console.info('usb SUB_USB_JS_0870 : PASS'); - }) - - /** - * @tc.number : SUB_USB_JS_0880 - * @tc.name : usbFunctionsFromString - * @tc.desc : 正向测试 'ecm' 返回 2 - */ - it('SUB_USB_JS_0880', 0, function () { - console.info('usb SUB_USB_JS_0880 begin'); - var strMaskCode = 'ecm' - var nMaskCode = usb.usbFunctionsFromString(strMaskCode) - expect(nMaskCode).assertEqual(usb.ECM); - console.info('usb case strMaskCode ' + strMaskCode + ' usbFunctionsFromString return int: ' + nMaskCode); - console.info('usb SUB_USB_JS_0880 : PASS'); - }) - - /** - * @tc.number : SUB_USB_JS_0890 - * @tc.name : usbFunctionsFromString - * @tc.desc : 正向测试 'acm,ecm' 返回 3 - */ - it('SUB_USB_JS_0890', 0, function () { - console.info('usb SUB_USB_JS_0890 begin'); - var strMaskCode = 'acm,ecm' - var nMaskCode = usb.usbFunctionsFromString(strMaskCode) - expect(nMaskCode).assertEqual(usb.ACM | usb.ECM); - console.info('usb case strMaskCode ' + strMaskCode + ' usbFunctionsFromString return int: ' + nMaskCode); - console.info('usb SUB_USB_JS_0890 : PASS'); - }) - - /** - * @tc.number : SUB_USB_JS_0900 - * @tc.name : usbFunctionsFromString - * @tc.desc : 正向测试 'hdc' 返回 4 - */ - it('SUB_USB_JS_0900', 0, function () { - console.info('usb SUB_USB_JS_0900 begin'); - var strMaskCode = 'hdc' - var nMaskCode = usb.usbFunctionsFromString(strMaskCode) - expect(nMaskCode).assertEqual(usb.HDC); - console.info('usb case strMaskCode ' + strMaskCode + ' usbFunctionsFromString return int: ' + nMaskCode); - console.info('usb SUB_USB_JS_0900 : PASS'); - }) - - /** - * @tc.number : SUB_USB_JS_0910 - * @tc.name : usbFunctionsFromString - * @tc.desc : 正向测试 'acm,hdc' 返回 5 - */ - it('SUB_USB_JS_0910', 0, function () { - console.info('usb SUB_USB_JS_0910 begin'); - var strMaskCode = 'acm,hdc' - var nMaskCode = usb.usbFunctionsFromString(strMaskCode) - expect(nMaskCode).assertEqual(usb.HDC | usb.ACM); - console.info('usb case strMaskCode ' + strMaskCode + ' usbFunctionsFromString return int: ' + nMaskCode); - console.info('usb SUB_USB_JS_0910 : PASS'); - }) - - /** - * @tc.number : SUB_USB_JS_0920 - * @tc.name : usbFunctionsFromString - * @tc.desc : 正向测试 'ecm,hdc' 返回 6 - */ - it('SUB_USB_JS_0920', 0, function () { - console.info('usb SUB_USB_JS_0920 begin'); - var strMaskCode = 'ecm,hdc' - var nMaskCode = usb.usbFunctionsFromString(strMaskCode) - expect(nMaskCode).assertEqual(usb.HDC | usb.ECM); - console.info('usb case strMaskCode ' + strMaskCode + ' usbFunctionsFromString return int: ' + nMaskCode); - console.info('usb SUB_USB_JS_0920 : PASS'); - }) - -}) +/* + * Copyright (C) 2021-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 usb from '@ohos.usb'; +import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from '@ohos/hypium' + +/* usb core functions test */ +export default function UsbFunctionsJsFunctionsTestEx() { +describe('UsbFunctionsJsFunctionsTestEx', function () { + + beforeAll(function () { + console.log('*************Usb Unit UsbFunctionsJsFunctionsTestEx Begin*************'); + var Version = usb.getVersion() + console.info('begin test getversion :' + Version) + // 17 version host currentMode = 2 device currentMode = 1 + var usbPortList = usb.getPorts() + if (usbPortList.length > 0) { + if (usbPortList[0].status.currentMode == 2) { + usb.setPortRoles(usbPortList[0].id, usb.SINK, usb.DEVICE).then(data => { + console.info('usb case setPortRoles return: ' + data); + }).catch(error => { + console.info('usb case setPortRoles error : ' + error); + }); + + console.log('*************Usb Unit switch to device Begin*************'); + } + } + }) + beforeEach(function () { + console.info('beforeEach: *************Usb Unit Test Case*************'); + }) + + afterEach(function () { + console.info('afterEach: *************Usb Unit Test Case*************'); + }) + + afterAll(function () { + console.log('*************Usb Unit UsbFunctionsJsFunctionsTest End*************'); + }) + + /** + * @tc.number : SUB_USB_JS_0930 + * @tc.name : usbFunctionsToString + * @tc.desc : 正向测试 0 返回 'none' + */ + it('SUB_USB_JS_0930', 0, function () { + console.info('usb SUB_USB_JS_0930 begin'); + var maskCode = usb.NONE + console.info('usb case maskCode : ' + usb.NONE); + var strMaskCode = usb.usbFunctionsToString(maskCode) + expect(strMaskCode).assertEqual('none'); + console.info('usb case maskCode ' + maskCode + ' usbFunctionsToString return int: ' + strMaskCode); + console.info('usb SUB_USB_JS_0930 : PASS'); + }) + + /** + * @tc.number : SUB_USB_JS_0940 + * @tc.name : usbFunctionsToString + * @tc.desc : 正向测试 1 返回 'acm' + */ + it('SUB_USB_JS_0940', 0, function () { + console.info('usb SUB_USB_JS_0940 begin'); + var maskCode = usb.ACM + console.info('usb case maskCode : ' + usb.ACM); + var strMaskCode = usb.usbFunctionsToString(maskCode) + expect(strMaskCode).assertEqual('acm'); + console.info('usb case maskCode ' + maskCode + ' usbFunctionsToString return int: ' + strMaskCode); + console.info('usb SUB_USB_JS_0940 : PASS'); + }) + + /** + * @tc.number : SUB_USB_JS_0950 + * @tc.name : usbFunctionsToString + * @tc.desc : 正向测试 2 返回 'ecm' + */ + it('SUB_USB_JS_0950', 0, function () { + console.info('usb SUB_USB_JS_0950 begin'); + var maskCode = usb.ECM + console.info('usb case maskCode : ' + maskCode); + var strMaskCode = usb.usbFunctionsToString(maskCode) + expect(strMaskCode).assertEqual('ecm'); + console.info('usb case maskCode ' + maskCode + ' usbFunctionsToString return int: ' + strMaskCode); + console.info('usb SUB_USB_JS_0950 : PASS'); + }) + + /** + * @tc.number : SUB_USB_JS_0960 + * @tc.name : usbFunctionsToString + * @tc.desc : 正向测试 3 返回 'acm,ecm' + */ + it('SUB_USB_JS_0960', 0, function () { + console.info('usb SUB_USB_JS_0960 begin'); + var maskCode = usb.ACM | usb.ECM + console.info('usb case maskCode : ' + maskCode); + var strMaskCode = usb.usbFunctionsToString(maskCode) + expect(strMaskCode).assertEqual('acm,ecm'); + console.info('usb case maskCode ' + maskCode + ' usbFunctionsToString return int: ' + strMaskCode); + console.info('usb SUB_USB_JS_0960 : PASS'); + }) + + /** + * @tc.number : SUB_USB_JS_0970 + * @tc.name : usbFunctionsToString + * @tc.desc : 正向测试 4 返回 'hdc' + */ + it('SUB_USB_JS_0970', 0, function () { + console.info('usb SUB_USB_JS_0970 begin'); + var maskCode = usb.HDC + console.info('usb case maskCode : ' + maskCode); + var strMaskCode = usb.usbFunctionsToString(maskCode) + expect(strMaskCode).assertEqual('hdc'); + console.info('usb case maskCode ' + maskCode + ' usbFunctionsToString return int: ' + strMaskCode); + console.info('usb SUB_USB_JS_0970 : PASS'); + }) + + /** + * @tc.number : SUB_USB_JS_0980 + * @tc.name : usbFunctionsToString + * @tc.desc : 正向测试 5 返回 'acm,hdc' + */ + it('SUB_USB_JS_0980', 0, function () { + console.info('usb SUB_USB_JS_0980 begin'); + var maskCode = usb.ACM | usb.HDC + console.info('usb case maskCode : ' + maskCode); + var strMaskCode = usb.usbFunctionsToString(maskCode) + expect(strMaskCode).assertEqual('hdc,acm'); + console.info('usb case maskCode ' + maskCode + ' usbFunctionsToString return int: ' + strMaskCode); + console.info('usb SUB_USB_JS_0980 : PASS'); + }) + + /** + * @tc.number : SUB_USB_JS_0990 + * @tc.name : usbFunctionsToString + * @tc.desc : 正向测试 6 返回 'ecm,hdc' + */ + it('SUB_USB_JS_0990', 0, function () { + console.info('usb SUB_USB_JS_0990 begin'); + var maskCode = usb.ECM | usb.HDC + console.info('usb case maskCode : ' + maskCode); + var strMaskCode = usb.usbFunctionsToString(maskCode) + expect(strMaskCode).assertEqual('hdc,ecm'); + console.info('usb case maskCode ' + maskCode + ' usbFunctionsToString return int: ' + strMaskCode); + console.info('usb SUB_USB_JS_0990 : PASS'); + }) + + /** + * @tc.number : SUB_USB_JS_0860 + * @tc.name : usbFunctionsFromString + * @tc.desc : 正向测试 'none' 返回 0 + */ + it('SUB_USB_JS_0860', 0, function () { + console.info('usb SUB_USB_JS_0860 begin'); + var strMaskCode = 'none' + var nMaskCode = usb.usbFunctionsFromString(strMaskCode) + expect(nMaskCode).assertEqual(usb.NONE); + console.info('usb case strMaskCode ' + strMaskCode + ' usbFunctionsFromString return int: ' + nMaskCode); + console.info('usb SUB_USB_JS_0860 : PASS'); + }) + + /** + * @tc.number : SUB_USB_JS_0870 + * @tc.name : usbFunctionsFromString + * @tc.desc : 正向测试 'acm' 返回 1 + */ + it('SUB_USB_JS_0870', 0, function () { + console.info('usb SUB_USB_JS_0870 begin'); + var strMaskCode = 'acm' + var nMaskCode = usb.usbFunctionsFromString(strMaskCode) + expect(nMaskCode).assertEqual(usb.ACM); + console.info('usb case strMaskCode ' + strMaskCode + ' usbFunctionsFromString return int: ' + nMaskCode); + console.info('usb SUB_USB_JS_0870 : PASS'); + }) + + /** + * @tc.number : SUB_USB_JS_0880 + * @tc.name : usbFunctionsFromString + * @tc.desc : 正向测试 'ecm' 返回 2 + */ + it('SUB_USB_JS_0880', 0, function () { + console.info('usb SUB_USB_JS_0880 begin'); + var strMaskCode = 'ecm' + var nMaskCode = usb.usbFunctionsFromString(strMaskCode) + expect(nMaskCode).assertEqual(usb.ECM); + console.info('usb case strMaskCode ' + strMaskCode + ' usbFunctionsFromString return int: ' + nMaskCode); + console.info('usb SUB_USB_JS_0880 : PASS'); + }) + + /** + * @tc.number : SUB_USB_JS_0890 + * @tc.name : usbFunctionsFromString + * @tc.desc : 正向测试 'acm,ecm' 返回 3 + */ + it('SUB_USB_JS_0890', 0, function () { + console.info('usb SUB_USB_JS_0890 begin'); + var strMaskCode = 'acm,ecm' + var nMaskCode = usb.usbFunctionsFromString(strMaskCode) + expect(nMaskCode).assertEqual(usb.ACM | usb.ECM); + console.info('usb case strMaskCode ' + strMaskCode + ' usbFunctionsFromString return int: ' + nMaskCode); + console.info('usb SUB_USB_JS_0890 : PASS'); + }) + + /** + * @tc.number : SUB_USB_JS_0900 + * @tc.name : usbFunctionsFromString + * @tc.desc : 正向测试 'hdc' 返回 4 + */ + it('SUB_USB_JS_0900', 0, function () { + console.info('usb SUB_USB_JS_0900 begin'); + var strMaskCode = 'hdc' + var nMaskCode = usb.usbFunctionsFromString(strMaskCode) + expect(nMaskCode).assertEqual(usb.HDC); + console.info('usb case strMaskCode ' + strMaskCode + ' usbFunctionsFromString return int: ' + nMaskCode); + console.info('usb SUB_USB_JS_0900 : PASS'); + }) + + /** + * @tc.number : SUB_USB_JS_0910 + * @tc.name : usbFunctionsFromString + * @tc.desc : 正向测试 'acm,hdc' 返回 5 + */ + it('SUB_USB_JS_0910', 0, function () { + console.info('usb SUB_USB_JS_0910 begin'); + var strMaskCode = 'acm,hdc' + var nMaskCode = usb.usbFunctionsFromString(strMaskCode) + expect(nMaskCode).assertEqual(usb.HDC | usb.ACM); + console.info('usb case strMaskCode ' + strMaskCode + ' usbFunctionsFromString return int: ' + nMaskCode); + console.info('usb SUB_USB_JS_0910 : PASS'); + }) + + /** + * @tc.number : SUB_USB_JS_0920 + * @tc.name : usbFunctionsFromString + * @tc.desc : 正向测试 'ecm,hdc' 返回 6 + */ + it('SUB_USB_JS_0920', 0, function () { + console.info('usb SUB_USB_JS_0920 begin'); + var strMaskCode = 'ecm,hdc' + var nMaskCode = usb.usbFunctionsFromString(strMaskCode) + expect(nMaskCode).assertEqual(usb.HDC | usb.ECM); + console.info('usb case strMaskCode ' + strMaskCode + ' usbFunctionsFromString return int: ' + nMaskCode); + console.info('usb SUB_USB_JS_0920 : PASS'); + }) + +}) +} diff --git a/usb/usb_standard/src/main/js/default/test/UsbPortAndFunctionJsunit.test.js b/usb/usb_standard/src/main/js/test/UsbPortAndFunctionJsunit.test.js similarity index 96% rename from usb/usb_standard/src/main/js/default/test/UsbPortAndFunctionJsunit.test.js rename to usb/usb_standard/src/main/js/test/UsbPortAndFunctionJsunit.test.js index 564c31b119be27efc66b882261cb099f1bcacf4b..bf9aec12484f511cebbc3cffc86a9e37962ffe44 100644 --- a/usb/usb_standard/src/main/js/default/test/UsbPortAndFunctionJsunit.test.js +++ b/usb/usb_standard/src/main/js/test/UsbPortAndFunctionJsunit.test.js @@ -15,9 +15,10 @@ import usb from '@ohos.usb'; import CheckEmptyUtils from './CheckEmptyUtils.js'; -import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from 'deccjsunit/index' +import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from '@ohos/hypium' /* usb core functions test */ +export default function UsbPortAndFunctionsJsFunctionsTest() { describe('UsbPortAndFunctionsJsFunctionsTest', function () { beforeAll(function () { @@ -211,3 +212,4 @@ describe('UsbPortAndFunctionsJsFunctionsTest', function () { }) }) +} diff --git a/usb/usb_standard/src/main/js/default/test/UsbPortJsunit.test.js b/usb/usb_standard/src/main/js/test/UsbPortJsunit.test.js old mode 100755 new mode 100644 similarity index 94% rename from usb/usb_standard/src/main/js/default/test/UsbPortJsunit.test.js rename to usb/usb_standard/src/main/js/test/UsbPortJsunit.test.js index 2a03aca2b2cfbacb208ffa93610a2263ceb2c892..e47a20f8510b1fa9f1c68db050fd18602db66642 --- a/usb/usb_standard/src/main/js/default/test/UsbPortJsunit.test.js +++ b/usb/usb_standard/src/main/js/test/UsbPortJsunit.test.js @@ -1,80 +1,82 @@ -/* - * Copyright (c) 2021-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 usb from '@ohos.usb'; -import CheckEmptyUtils from './CheckEmptyUtils.js'; -import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from 'deccjsunit/index' - -/* usb core functions test */ -describe('UsbPortJsFunctionsTest', function () { - - beforeAll(function () { - console.log('*************Usb Unit UsbPortJsFunctionsTest Begin*************'); - var Version = usb.getVersion() - console.info('begin test getversion :' + Version) - }) - beforeEach(function () { - console.info('beforeEach: *************Usb Unit Test Case*************'); - }) - afterEach(function () { - console.info('afterEach: *************Usb Unit Test Case*************'); - }) - afterAll(function () { - console.log('*************Usb Unit UsbPortJsFunctionsTest End*************'); - }) - - /** - * @tc.number : SUB_USB_JS_0410 - * @tc.name : getPorts - * @tc.desc : 获取USB端口描述信息列表 - */ - it('SUB_USB_JS_0410', 0, function () { - console.info('usb SUB_USB_JS_0410 begin'); - var usbPortList = usb.getPorts() - if (usbPortList.length == 0) { - console.info('usb SUB_USB_JS_0410 usbPortList is null'); - expect(false).assertTrue(); - return - } - expect(usbPortList.length > 0).assertTrue(); - console.info('usb SUB_USB_JS_0410 : PASS'); - expect(true).assertTrue(); - }) - - /** - * @tc.number : SUB_USB_JS_0220 - * @tc.name : getSupportedModes - * @tc.desc : 获取指定的端口支持的模式列表的组合掩码 - */ - it('SUB_USB_JS_0220', 0, function () { - console.info('usb SUB_USB_JS_0220 begin'); - var usbPortList = usb.getPorts() - if (usbPortList.length == 0) { - console.info('usb SUB_USB_JS_0220 usbPortList is null'); - expect(false).assertTrue(); - return - } - - expect(usbPortList.length > 0).assertTrue(); - for (var i = 0; i < usbPortList.length; i++) { - var maskCode = usb.getSupportedModes(usbPortList[i].id) - expect(maskCode).assertEqual(usbPortList[i].supportedModes); - } - - console.info('usb SUB_USB_JS_0220 : PASS'); - expect(true).assertTrue(); - }) - -}) +/* + * Copyright (c) 2021-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 usb from '@ohos.usb'; +import CheckEmptyUtils from './CheckEmptyUtils.js'; +import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from '@ohos/hypium' + +/* usb core functions test */ +export default function UsbPortJsFunctionsTest() { +describe('UsbPortJsFunctionsTest', function () { + + beforeAll(function () { + console.log('*************Usb Unit UsbPortJsFunctionsTest Begin*************'); + var Version = usb.getVersion() + console.info('begin test getversion :' + Version) + }) + beforeEach(function () { + console.info('beforeEach: *************Usb Unit Test Case*************'); + }) + afterEach(function () { + console.info('afterEach: *************Usb Unit Test Case*************'); + }) + afterAll(function () { + console.log('*************Usb Unit UsbPortJsFunctionsTest End*************'); + }) + + /** + * @tc.number : SUB_USB_JS_0410 + * @tc.name : getPorts + * @tc.desc : 获取USB端口描述信息列表 + */ + it('SUB_USB_JS_0410', 0, function () { + console.info('usb SUB_USB_JS_0410 begin'); + var usbPortList = usb.getPorts() + if (usbPortList.length == 0) { + console.info('usb SUB_USB_JS_0410 usbPortList is null'); + expect(false).assertTrue(); + return + } + expect(usbPortList.length > 0).assertTrue(); + console.info('usb SUB_USB_JS_0410 : PASS'); + expect(true).assertTrue(); + }) + + /** + * @tc.number : SUB_USB_JS_0220 + * @tc.name : getSupportedModes + * @tc.desc : 获取指定的端口支持的模式列表的组合掩码 + */ + it('SUB_USB_JS_0220', 0, function () { + console.info('usb SUB_USB_JS_0220 begin'); + var usbPortList = usb.getPorts() + if (usbPortList.length == 0) { + console.info('usb SUB_USB_JS_0220 usbPortList is null'); + expect(false).assertTrue(); + return + } + + expect(usbPortList.length > 0).assertTrue(); + for (var i = 0; i < usbPortList.length; i++) { + var maskCode = usb.getSupportedModes(usbPortList[i].id) + expect(maskCode).assertEqual(usbPortList[i].supportedModes); + } + + console.info('usb SUB_USB_JS_0220 : PASS'); + expect(true).assertTrue(); + }) + +}) +} diff --git a/usb/usb_standard/src/main/js/default/test/UsbPortJsunitEx.test.js b/usb/usb_standard/src/main/js/test/UsbPortJsunitEx.test.js old mode 100755 new mode 100644 similarity index 95% rename from usb/usb_standard/src/main/js/default/test/UsbPortJsunitEx.test.js rename to usb/usb_standard/src/main/js/test/UsbPortJsunitEx.test.js index d37d45e80f7d7c29e5b76b887c5a9ef265b85377..7afbf9d16cd57454f19b9c6a75c616f9c7d01868 --- a/usb/usb_standard/src/main/js/default/test/UsbPortJsunitEx.test.js +++ b/usb/usb_standard/src/main/js/test/UsbPortJsunitEx.test.js @@ -1,204 +1,206 @@ -/* - * Copyright (c) 2021-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 usb from '@ohos.usb'; -import CheckEmptyUtils from './CheckEmptyUtils.js'; -import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from 'deccjsunit/index' - -/* usb core functions test */ -describe('UsbPortJsFunctionsTestEx', function () { - - var gPort; - beforeAll(function () { - console.log('*************Usb Unit UsbPortJsFunctionsTestEx Begin*************'); - var Version = usb.getVersion() - console.info('begin test getversion :' + Version) - }) - beforeEach(function () { - console.info('beforeEach: *************Usb Unit Test Case*************'); - }) - - afterEach(function () { - console.info('afterEach: *************Usb Unit Test Case*************'); - }) - - afterAll(function () { - console.log('*************Usb Unit UsbPortJsFunctionsTest End*************'); - }) - - /** - * @tc.number : SUB_USB_JS_0230 - * @tc.name : getSupportedModes - * @tc.desc : 反向测试 改变id 获取指定的端口支持的模式列表的组合掩码 - */ - it('SUB_USB_JS_0230', 0, function () { - console.info('usb SUB_USB_JS_0230 begin'); - var usbPortList = usb.getPorts() - if (usbPortList.length == 0) { - console.info('usb SUB_USB_JS_0230 usbPortList is null'); - expect(false).assertTrue(); - return - } - - expect(usbPortList.length > 0).assertTrue(); - gPort = usbPortList[0] - var portID = usbPortList[0].id + 10 - var maskCode = usb.getSupportedModes(portID) - expect(maskCode).assertEqual(usb.NONE); - - console.info('usb SUB_USB_JS_0230 : PASS'); - expect(true).assertTrue(); - }) - - /** - * @tc.number : SUB_USB_JS_0030 - * @tc.name : setPortRoles - * @tc.desc : dataRole参数错误 - */ - it('SUB_USB_JS_0030', 0, function () { - var portId = gPort.id; - var powerRole = usb.SINK; - var dataRole = usb.NONE - 1; - CheckEmptyUtils.sleep(2000) - usb.setPortRoles(portId, powerRole, dataRole).then(data => { - console.info('usb case setPortRoles return: ' + data); - expect(data).assertTrue(); - }).catch(error => { - console.info('usb case setPortRoles error : ' + error); - expect(error).assertFalse(); - console.info('usb SUB_USB_JS_0030: PASS'); - }) - - console.info('usb SUB_USB_JS_0030: PASS'); - expect(true).assertTrue(); - }) - - /** - * @tc.number : SUB_USB_JS_0040 - * @tc.name : setPortRoles - * @tc.desc : portId,powerRole参数错误 - */ - it('SUB_USB_JS_0040', 0, function () { - var portId = gPort.id; - var powerRole = usb.NONE - 1; - var dataRole = usb.DEVICE; - CheckEmptyUtils.sleep(2000) - usb.setPortRoles(portId, powerRole, dataRole).then(data => { - console.info('usb case setPortRoles return: ' + data); - expect(data).assertTrue(); - }).catch(error => { - console.info('usb case setPortRoles error : ' + error); - expect(error).assertFalse(); - console.info('usb SUB_USB_JS_0040: PASS'); - }) - - console.info('usb SUB_USB_JS_0040: PASS'); - expect(true).assertTrue(); - }) - - /** - * @tc.number : SUB_USB_JS_0050 - * @tc.name : setPortRoles - * @tc.desc : portId,dataRole参数错误 - */ - it('SUB_USB_JS_0050', 0, function () { - var portId = gPort.id - 3; - var powerRole = usb.SINK; - var dataRole = usb.NONE - 1; - CheckEmptyUtils.sleep(2000) - usb.setPortRoles(portId, powerRole, dataRole).then(data => { - console.info('usb case setPortRoles return: ' + data); - expect(data).assertTrue(); - }).catch(error => { - console.info('usb case setPortRoles error : ' + error); - expect(error).assertFalse(); - console.info('usb SUB_USB_JS_0050: PASS'); - }) - - console.info('usb SUB_USB_JS_0050: PASS'); - expect(true).assertTrue(); - }) - - /** - * @tc.number : SUB_USB_JS_0060 - * @tc.name : setPortRoles - * @tc.desc : powerRole,dataRole参数错误 - */ - it('SUB_USB_JS_0060', 0, function () { - var portId = gPort.id; - var powerRole = usb.NONE - 1; - var dataRole = usb.NONE - 1; - CheckEmptyUtils.sleep(2000) - usb.setPortRoles(portId, powerRole, dataRole).then(data => { - console.info('usb case setPortRoles return: ' + data); - expect(data).assertTrue(); - }).catch(error => { - console.info('usb case setPortRoles error : ' + error); - expect(error).assertFalse(); - console.info('usb SUB_USB_JS_0060: PASS'); - }) - - console.info('usb SUB_USB_JS_0060: PASS'); - expect(true).assertTrue(); - }) - - /** - * @tc.number : SUB_USB_JS_0070 - * @tc.name : setPortRoles - * @tc.desc : portId,portId,dataRole参数错误 - */ - it('SUB_USB_JS_0070', 0, function () { - var portId = gPort.id - 1; - var dataRole = usb.NONE - 1; - var powerRole = usb.NONE - 1; - - CheckEmptyUtils.sleep(2000) - usb.setPortRoles(portId, powerRole, dataRole).then(data => { - console.info('usb case setPortRoles return: ' + data); - expect(data).assertTrue(); - }).catch(error => { - console.info('usb case setPortRoles error : ' + error); - expect(error).assertFalse(); - console.info('usb SUB_USB_JS_0070: PASS'); - }) - - console.info('usb SUB_USB_JS_0070: PASS'); - expect(true).assertTrue(); - }) - - /** - * @tc.number : SUB_USB_JS_0080 - * @tc.name : setPortRoles - * @tc.desc : portId参数错误 - */ - it('SUB_USB_JS_0080', 0, function () { - var portId = gPort.id - 1; - var powerRole = 1; - var dataRole = 1; - CheckEmptyUtils.sleep(2000) - usb.setPortRoles(portId, powerRole, dataRole).then(data => { - console.info('usb case setPortRoles return: ' + data); - expect(data).assertTrue(); - }).catch(error => { - console.info('usb case setPortRoles error : ' + error); - expect(error).assertFalse(); - console.info('usb SUB_USB_JS_0080: PASS'); - }) - - console.info('usb SUB_USB_JS_0080: PASS'); - expect(true).assertTrue(); - }) - -}) +/* + * Copyright (c) 2021-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 usb from '@ohos.usb'; +import CheckEmptyUtils from './CheckEmptyUtils.js'; +import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from '@ohos/hypium' + +/* usb core functions test */ +export default function UsbPortJsFunctionsTestEx() { +describe('UsbPortJsFunctionsTestEx', function () { + + var gPort; + beforeAll(function () { + console.log('*************Usb Unit UsbPortJsFunctionsTestEx Begin*************'); + var Version = usb.getVersion() + console.info('begin test getversion :' + Version) + }) + beforeEach(function () { + console.info('beforeEach: *************Usb Unit Test Case*************'); + }) + + afterEach(function () { + console.info('afterEach: *************Usb Unit Test Case*************'); + }) + + afterAll(function () { + console.log('*************Usb Unit UsbPortJsFunctionsTest End*************'); + }) + + /** + * @tc.number : SUB_USB_JS_0230 + * @tc.name : getSupportedModes + * @tc.desc : 反向测试 改变id 获取指定的端口支持的模式列表的组合掩码 + */ + it('SUB_USB_JS_0230', 0, function () { + console.info('usb SUB_USB_JS_0230 begin'); + var usbPortList = usb.getPorts() + if (usbPortList.length == 0) { + console.info('usb SUB_USB_JS_0230 usbPortList is null'); + expect(false).assertTrue(); + return + } + + expect(usbPortList.length > 0).assertTrue(); + gPort = usbPortList[0] + var portID = usbPortList[0].id + 10 + var maskCode = usb.getSupportedModes(portID) + expect(maskCode).assertEqual(usb.NONE); + + console.info('usb SUB_USB_JS_0230 : PASS'); + expect(true).assertTrue(); + }) + + /** + * @tc.number : SUB_USB_JS_0030 + * @tc.name : setPortRoles + * @tc.desc : dataRole参数错误 + */ + it('SUB_USB_JS_0030', 0, function () { + var portId = gPort.id; + var powerRole = usb.SINK; + var dataRole = usb.NONE - 1; + CheckEmptyUtils.sleep(2000) + usb.setPortRoles(portId, powerRole, dataRole).then(data => { + console.info('usb case setPortRoles return: ' + data); + expect(data).assertTrue(); + }).catch(error => { + console.info('usb case setPortRoles error : ' + error); + expect(error).assertFalse(); + console.info('usb SUB_USB_JS_0030: PASS'); + }) + + console.info('usb SUB_USB_JS_0030: PASS'); + expect(true).assertTrue(); + }) + + /** + * @tc.number : SUB_USB_JS_0040 + * @tc.name : setPortRoles + * @tc.desc : portId,powerRole参数错误 + */ + it('SUB_USB_JS_0040', 0, function () { + var portId = gPort.id; + var powerRole = usb.NONE - 1; + var dataRole = usb.DEVICE; + CheckEmptyUtils.sleep(2000) + usb.setPortRoles(portId, powerRole, dataRole).then(data => { + console.info('usb case setPortRoles return: ' + data); + expect(data).assertTrue(); + }).catch(error => { + console.info('usb case setPortRoles error : ' + error); + expect(error).assertFalse(); + console.info('usb SUB_USB_JS_0040: PASS'); + }) + + console.info('usb SUB_USB_JS_0040: PASS'); + expect(true).assertTrue(); + }) + + /** + * @tc.number : SUB_USB_JS_0050 + * @tc.name : setPortRoles + * @tc.desc : portId,dataRole参数错误 + */ + it('SUB_USB_JS_0050', 0, function () { + var portId = gPort.id - 3; + var powerRole = usb.SINK; + var dataRole = usb.NONE - 1; + CheckEmptyUtils.sleep(2000) + usb.setPortRoles(portId, powerRole, dataRole).then(data => { + console.info('usb case setPortRoles return: ' + data); + expect(data).assertTrue(); + }).catch(error => { + console.info('usb case setPortRoles error : ' + error); + expect(error).assertFalse(); + console.info('usb SUB_USB_JS_0050: PASS'); + }) + + console.info('usb SUB_USB_JS_0050: PASS'); + expect(true).assertTrue(); + }) + + /** + * @tc.number : SUB_USB_JS_0060 + * @tc.name : setPortRoles + * @tc.desc : powerRole,dataRole参数错误 + */ + it('SUB_USB_JS_0060', 0, function () { + var portId = gPort.id; + var powerRole = usb.NONE - 1; + var dataRole = usb.NONE - 1; + CheckEmptyUtils.sleep(2000) + usb.setPortRoles(portId, powerRole, dataRole).then(data => { + console.info('usb case setPortRoles return: ' + data); + expect(data).assertTrue(); + }).catch(error => { + console.info('usb case setPortRoles error : ' + error); + expect(error).assertFalse(); + console.info('usb SUB_USB_JS_0060: PASS'); + }) + + console.info('usb SUB_USB_JS_0060: PASS'); + expect(true).assertTrue(); + }) + + /** + * @tc.number : SUB_USB_JS_0070 + * @tc.name : setPortRoles + * @tc.desc : portId,portId,dataRole参数错误 + */ + it('SUB_USB_JS_0070', 0, function () { + var portId = gPort.id - 1; + var dataRole = usb.NONE - 1; + var powerRole = usb.NONE - 1; + + CheckEmptyUtils.sleep(2000) + usb.setPortRoles(portId, powerRole, dataRole).then(data => { + console.info('usb case setPortRoles return: ' + data); + expect(data).assertTrue(); + }).catch(error => { + console.info('usb case setPortRoles error : ' + error); + expect(error).assertFalse(); + console.info('usb SUB_USB_JS_0070: PASS'); + }) + + console.info('usb SUB_USB_JS_0070: PASS'); + expect(true).assertTrue(); + }) + + /** + * @tc.number : SUB_USB_JS_0080 + * @tc.name : setPortRoles + * @tc.desc : portId参数错误 + */ + it('SUB_USB_JS_0080', 0, function () { + var portId = gPort.id - 1; + var powerRole = 1; + var dataRole = 1; + CheckEmptyUtils.sleep(2000) + usb.setPortRoles(portId, powerRole, dataRole).then(data => { + console.info('usb case setPortRoles return: ' + data); + expect(data).assertTrue(); + }).catch(error => { + console.info('usb case setPortRoles error : ' + error); + expect(error).assertFalse(); + console.info('usb SUB_USB_JS_0080: PASS'); + }) + + console.info('usb SUB_USB_JS_0080: PASS'); + expect(true).assertTrue(); + }) + +}) +} diff --git a/usb/usb_standard/src/main/resources/base/element/string.json b/usb/usb_standard/src/main/resources/base/element/string.json old mode 100755 new mode 100644 index 9cc0314b698d82fe05d06e24bf9f020bbaba05bb..6d13d3ff5977d95c34e6ec935032a6b7580e14ef --- a/usb/usb_standard/src/main/resources/base/element/string.json +++ b/usb/usb_standard/src/main/resources/base/element/string.json @@ -1,12 +1,28 @@ -{ - "string": [ - { - "name": "app_name", - "value": "UsbJSApiTest" - }, - { - "name": "mainability_description", - "value": "JS_Phone_Empty Feature Ability" - } - ] +{ + "string": [ + { + "name": "app_name", + "value": "UsbJSApiTest" + }, + { + "name": "mainability_description", + "value": "JS_Phone_Empty Feature Ability" + }, + { + "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/usb/usb_standard/src/main/resources/base/media/icon.png b/usb/usb_standard/src/main/resources/base/media/icon.png old mode 100755 new mode 100644