From 1bcecf88bd8b4ca2a58c51ddaae99d4c0f834cbd Mon Sep 17 00:00:00 2001 From: logic42 Date: Wed, 29 Dec 2021 13:40:59 +0000 Subject: [PATCH] add usb testcases Signed-off-by: logic42 --- usb/BUILD.gn | 21 + usb/usb_standard/BUILD.gn | 31 + usb/usb_standard/Test.json | 18 + usb/usb_standard/signature/openharmony_sx.p7b | Bin 0 -> 3437 bytes usb/usb_standard/src/main/config.json | 60 ++ usb/usb_standard/src/main/js/default/app.js | 23 + .../src/main/js/default/i18n/en-US.json | 6 + .../src/main/js/default/i18n/zh-CN.json | 6 + .../src/main/js/default/pages/index/index.css | 9 + .../src/main/js/default/pages/index/index.hml | 5 + .../src/main/js/default/pages/index/index.js | 46 ++ .../main/js/default/test/CheckEmptyUtils.js | 68 ++ .../main/js/default/test/DateAndTimeUtil.js | 120 +++ .../main/js/default/test/EventConstants.js | 67 ++ .../src/main/js/default/test/ListUsb.test.js | 29 + .../js/default/test/UsbCoreJsunit.test.js | 236 ++++++ .../js/default/test/UsbCoreJsunitEx.test.js | 615 ++++++++++++++ .../default/test/UsbDevicePipeJsunit.test.js | 465 +++++++++++ .../test/UsbDevicePipeJsunitEx.test.js | 778 ++++++++++++++++++ .../default/test/UsbFunctionsJsunit.test.js | 203 +++++ .../default/test/UsbFunctionsJsunitEx.test.js | 250 ++++++ .../js/default/test/UsbPortJsunit.test.js | 139 ++++ .../js/default/test/UsbPortJsunitEx.test.js | 387 +++++++++ .../main/resources/base/element/string.json | 12 + .../src/main/resources/base/media/icon.png | Bin 0 -> 6790 bytes 25 files changed, 3594 insertions(+) create mode 100755 usb/BUILD.gn create mode 100755 usb/usb_standard/BUILD.gn create mode 100755 usb/usb_standard/Test.json create mode 100755 usb/usb_standard/signature/openharmony_sx.p7b create mode 100755 usb/usb_standard/src/main/config.json create mode 100755 usb/usb_standard/src/main/js/default/app.js create mode 100755 usb/usb_standard/src/main/js/default/i18n/en-US.json create mode 100755 usb/usb_standard/src/main/js/default/i18n/zh-CN.json create mode 100755 usb/usb_standard/src/main/js/default/pages/index/index.css create mode 100755 usb/usb_standard/src/main/js/default/pages/index/index.hml create mode 100755 usb/usb_standard/src/main/js/default/pages/index/index.js create mode 100755 usb/usb_standard/src/main/js/default/test/CheckEmptyUtils.js create mode 100755 usb/usb_standard/src/main/js/default/test/DateAndTimeUtil.js create mode 100755 usb/usb_standard/src/main/js/default/test/EventConstants.js create mode 100755 usb/usb_standard/src/main/js/default/test/ListUsb.test.js create mode 100755 usb/usb_standard/src/main/js/default/test/UsbCoreJsunit.test.js create mode 100755 usb/usb_standard/src/main/js/default/test/UsbCoreJsunitEx.test.js create mode 100755 usb/usb_standard/src/main/js/default/test/UsbDevicePipeJsunit.test.js create mode 100755 usb/usb_standard/src/main/js/default/test/UsbDevicePipeJsunitEx.test.js create mode 100755 usb/usb_standard/src/main/js/default/test/UsbFunctionsJsunit.test.js create mode 100755 usb/usb_standard/src/main/js/default/test/UsbFunctionsJsunitEx.test.js create mode 100755 usb/usb_standard/src/main/js/default/test/UsbPortJsunit.test.js create mode 100755 usb/usb_standard/src/main/js/default/test/UsbPortJsunitEx.test.js create mode 100755 usb/usb_standard/src/main/resources/base/element/string.json create mode 100755 usb/usb_standard/src/main/resources/base/media/icon.png diff --git a/usb/BUILD.gn b/usb/BUILD.gn new file mode 100755 index 000000000..6e37eabef --- /dev/null +++ b/usb/BUILD.gn @@ -0,0 +1,21 @@ +# 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("//build/ohos_var.gni") + +group("usb") { + testonly = true + if (is_standard_system) { + deps = [ "usb_standard:usb_js_test" ] + } +} diff --git a/usb/usb_standard/BUILD.gn b/usb/usb_standard/BUILD.gn new file mode 100755 index 000000000..ed66ed5e7 --- /dev/null +++ b/usb/usb_standard/BUILD.gn @@ -0,0 +1,31 @@ +# Copyright (C) 2021 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import("//test/xts/tools/build/suite.gni") + +ohos_js_hap_suite("usb_js_test") { + hap_profile = "./src/main/config.json" + deps = [ + ":usb_js_assets", + ":usb_js_resources", + ] + certificate_profile = "./signature/openharmony_sx.p7b" + hap_name = "ActsUsbJSApiTest" +} +ohos_js_assets("usb_js_assets") { + source_dir = "./src/main/js/default" +} +ohos_resources("usb_js_resources") { + sources = [ "./src/main/resources" ] + hap_profile = "./src/main/config.json" +} diff --git a/usb/usb_standard/Test.json b/usb/usb_standard/Test.json new file mode 100755 index 000000000..cd7ef814d --- /dev/null +++ b/usb/usb_standard/Test.json @@ -0,0 +1,18 @@ +{ + "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 + } + ] +} diff --git a/usb/usb_standard/signature/openharmony_sx.p7b b/usb/usb_standard/signature/openharmony_sx.p7b new file mode 100755 index 0000000000000000000000000000000000000000..9be1e98fa4c0c28ca997ed660112fa16b194f0f5 GIT binary patch literal 3437 zcmcgvX>b$g8MY4FF(5FQyMT=#m||qU)nQ9cId-MBB-<-lvSdq&snM}IENNF>t+bK| zgowuF2vC|SxSZxNN5eHhV%(WPpbeB9Fc3;JDMtzMBv1-XAc2N~c2_tCXW&OCGw6qQ z-s9VS-tT?h=bI0tMS+~WDXqHJyCPmLzdbE-fV8Nd&*MRZfG8(#POFZG3xs@Lb{0ry z=R8j3wWo!5g=yjKx#BoZMFS)uA)H}cTp@-^K`9VV?RC3J59@}eik*>n|pRKOLZ zxdn7G!Yv@9O#y<&eUy{)vMXb;fQR)ffVAADQsEMXm;IBMDLfLD0w^U;6%HVo-0Q_5 zCHEa?DBuauNpZzoF+tK27w#n~?u%toS-DhR4k@Q*{7x^8Q=D6&kd^_~J#VVG2LXkL zaAy=}U*?Jto)9hx5MGjdp9hcQAu@tfk_;l!PeyxPY<8b&+&D!CyaBh9=8BSVKLpk4 z4Ml3yY|&Th)vyK4cpC{!uU8v2YBlVV`d~(nz&<@{G1oe*DHub1z7~J5*;s2bX<)_* zV_GbsPQg`(&rpxRb_*Od7}++3+liSw-$!1 zs5*g}EHWhI3i|!-FcfzYL0`SL-rq>LENC;PMl)G(0(1U2%Va|smp0UFx0xd@soZA* zD5LYc4OlbE7@ARt#h}rr3>K@bf%B#^-c+xz8Hr)0D5ExIFltezN@Hn8>o5d~bSfYtkc+_Z&kI#-N5_GhCg*V-^TSO=!G~ z(fXy{n2XV+k}6w_W`dTOP2a4u0ly;ANZ>4OxSKAzFB!yBzdo`gX zO?o|H@WiAw$y6l?=^3jA_Hy0S)nTYs12;4hKE&ekQ|>?|ZLJ}#F`2BczC7kdE4@xV zZBD_)Otwjhz+NSaz?d45!;FsGSu-#qh#hStD%B}f!mCT!KqzSo>I`NGH_9Dea$1Qi zg29Ydt!~lQVR99_T7#Hije~(12drl-P)SV?QR*9sus`8th-8^OQ7@xI$(Yp|^;bL1 zR50O$mDXw6P>i7B(TJ)ciPzTE>XY%X6HAa)b#OBRXv&~%Bw|J#Y><i4=e%95bjtw|cJp=#P#Pf#*luqI_wR;fISDCJhAqSG6R%xItn%~QtZ@m%&u zjGGLX;t6Ls62eQvNmf@v+}J%54^CygxRZ`?8X#r|wkev7(s;Ou4T#y1XNNf)h;o7z z8a^Lfq<1uH`E{G9E z*(=)Css_LSk=>E9jr)s5^2-!+MN=Ds}>1hRma4`uCIz9%p3O77839E{xf z4c_I?**|1`K2tg4!Hvyrou4BsJQuv*UfF)<%CelYIS>D^o?X)3+MK%la6kooW8&G@BU)Y0hT`+mOm$Z_%rB=a%o>I z!2c6lHyKQN)VjiFwa!eE^p8jc$sy$vB+8i25lI~6KPFFh$!o$avA~rj#L6xvR|Z83 z*WD6T9e+5Pyy=F+)pNTf{ny3cy>7Rkd3o*TS?TZJ`NS^NF2%HMkyS{?uJ$`!P4_L^ z1`NFDUbNyg_qREifgktnp1_v{Jbb`7m}2PTyUdOmtJj~m z9bB=ecw4_^rw1IW=of+>nrW5=d3k`3qHCxsIN_F{T1A545};;+fsyC&qChi+YV zr~M63H8ZLCPYmsjY>ls9cL%I)F|JIW-#+48$+lD4k*(P*kDM%zx_fvu4u5ZYUnI}5 zdrycFq>xFU)&X3p@pP2u%$o}}YcRn(MhJ&B2o?KS@cIVz>Ye%o^xV?CB{_Qhu z;}_q1bvO^g{8<3!gYbo4Di{8qzV+(9 zdlmksohQmRTs@qB;(Wo?dER_ux6XQb@q$tQPW?CMu6GVQd;R=iR;-S{Kr%Zks7>b1 zNs{|-+jhObYE}NR&`TGGr^h^4bjh%c>R#@=8nM&Md>_a+zVulsl;){flFekV1t9ob z+SqfV_Pv3$2f)bQ8%Ul2>fdYR^1zs0BQF~olsOj5AodC&Q_7SMFzsz2 z9newxE&jodk~tNHwl%LBMMDbrk=(^b literal 0 HcmV?d00001 diff --git a/usb/usb_standard/src/main/config.json b/usb/usb_standard/src/main/config.json new file mode 100755 index 000000000..4a05ad4d0 --- /dev/null +++ b/usb/usb_standard/src/main/config.json @@ -0,0 +1,60 @@ +{ + "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 + } + } + ] + } +} diff --git a/usb/usb_standard/src/main/js/default/app.js b/usb/usb_standard/src/main/js/default/app.js new file mode 100755 index 000000000..e423f4bce --- /dev/null +++ b/usb/usb_standard/src/main/js/default/app.js @@ -0,0 +1,23 @@ +/* + * Copyright (C) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +export default { + onCreate() { + console.info('AceApplication onCreate'); + }, + onDestroy() { + console.info('AceApplication onDestroy'); + } +}; diff --git a/usb/usb_standard/src/main/js/default/i18n/en-US.json b/usb/usb_standard/src/main/js/default/i18n/en-US.json new file mode 100755 index 000000000..e63c70d97 --- /dev/null +++ b/usb/usb_standard/src/main/js/default/i18n/en-US.json @@ -0,0 +1,6 @@ +{ + "strings": { + "hello": "Hello", + "world": "World" + } +} \ No newline at end of file diff --git a/usb/usb_standard/src/main/js/default/i18n/zh-CN.json b/usb/usb_standard/src/main/js/default/i18n/zh-CN.json new file mode 100755 index 000000000..de6ee5748 --- /dev/null +++ b/usb/usb_standard/src/main/js/default/i18n/zh-CN.json @@ -0,0 +1,6 @@ +{ + "strings": { + "hello": "您好", + "world": "世界" + } +} \ No newline at end of file diff --git a/usb/usb_standard/src/main/js/default/pages/index/index.css b/usb/usb_standard/src/main/js/default/pages/index/index.css new file mode 100755 index 000000000..6fda79275 --- /dev/null +++ b/usb/usb_standard/src/main/js/default/pages/index/index.css @@ -0,0 +1,9 @@ +.container { + flex-direction: column; + justify-content: center; + align-items: center; +} + +.title { + font-size: 100px; +} diff --git a/usb/usb_standard/src/main/js/default/pages/index/index.hml b/usb/usb_standard/src/main/js/default/pages/index/index.hml new file mode 100755 index 000000000..f64b040a5 --- /dev/null +++ b/usb/usb_standard/src/main/js/default/pages/index/index.hml @@ -0,0 +1,5 @@ +
+ + {{ $t('strings.hello') }} {{ title }} + +
diff --git a/usb/usb_standard/src/main/js/default/pages/index/index.js b/usb/usb_standard/src/main/js/default/pages/index/index.js new file mode 100755 index 000000000..3cdd779e2 --- /dev/null +++ b/usb/usb_standard/src/main/js/default/pages/index/index.js @@ -0,0 +1,46 @@ +/* + * 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() { + }, +} diff --git a/usb/usb_standard/src/main/js/default/test/CheckEmptyUtils.js b/usb/usb_standard/src/main/js/default/test/CheckEmptyUtils.js new file mode 100755 index 000000000..a2fa91880 --- /dev/null +++ b/usb/usb_standard/src/main/js/default/test/CheckEmptyUtils.js @@ -0,0 +1,68 @@ +/* + * Copyright (c) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +export default { + + /** + * 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/default/test/DateAndTimeUtil.js new file mode 100755 index 000000000..22ba24b4c --- /dev/null +++ b/usb/usb_standard/src/main/js/default/test/DateAndTimeUtil.js @@ -0,0 +1,120 @@ +/* + * 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 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/default/test/EventConstants.js new file mode 100755 index 000000000..b07e489e6 --- /dev/null +++ b/usb/usb_standard/src/main/js/default/test/EventConstants.js @@ -0,0 +1,67 @@ +/* + * 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. + */ + +/* + * 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/default/test/ListUsb.test.js b/usb/usb_standard/src/main/js/default/test/ListUsb.test.js new file mode 100755 index 000000000..cd298d4f7 --- /dev/null +++ b/usb/usb_standard/src/main/js/default/test/ListUsb.test.js @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + + +/* 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') diff --git a/usb/usb_standard/src/main/js/default/test/UsbCoreJsunit.test.js b/usb/usb_standard/src/main/js/default/test/UsbCoreJsunit.test.js new file mode 100755 index 000000000..39fb1431c --- /dev/null +++ b/usb/usb_standard/src/main/js/default/test/UsbCoreJsunit.test.js @@ -0,0 +1,236 @@ +/* + * 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 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 () { + + beforeAll(function () { + console.log('*************Usb Unit UsbCoreJsFunctionsTest Begin*************'); + var Version = usb.getVersion() + console.info('begin test getversion :' + Version) + // 切换为host + var usbPortList = usb.getPorts() + if (usbPortList.length > 0) { + if (usbPortList[0].status.currentMode == 1) { + usb.setPortRoles(usbPortList[0].id, 1, 1).then(data => { + console.info('usb case setPortRoles return: ' + data); + }).catch(error => { + console.info('usb case setPortRoles error : ' + error); + }); + console.log('*************Usb Unit Begin switch to host*************'); + } + } + }) + 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*************'); + }) + + var gDeviceList + var gPipe; + + /** + * @tc.number : get_devices_test_01 + * @tc.name : getDevices + * @tc.desc : 获取设备列表 + */ + it('SUB_USB_get_devices_test_01', 0, function () { + console.info('usb get_device_01 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 get_devices_test_01: PASS'); + }) + + + /** + * @tc.number : has_right_1 + * @tc.name : hasRigt + * @tc.desc : 权限查询 连接设备 关闭设备 + */ + it('SUB_USB_has_right_01', 0, function () { + console.info('usb has_right_01 begin'); + 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 has_right_01 : PASS'); + expect(true).assertTrue(); + }) + + + /** + * @tc.number : request_right_01 + * @tc.name : requestRight + * @tc.desc : 请求权限 + */ + it('SUB_USB_request_right_01', 0, function () { + console.info('usb request_right_01 begin'); + 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 request_right_01 : PASS'); + }).catch(error => { + console.info('usb case device request right failed : ' + error + ' :' + gDeviceList[i].name); + expect(false).assertTrue(); + }); + } + }) + + /** + * @tc.number : connect_device_01 + * @tc.name : connectDevice + * @tc.desc : 打开设备 + */ + it('SUB_USB_connect_device_01', 0, function () { + console.info('usb connect_device_01 begin'); + 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 connect_device_01 : PASS'); + }) + + /** + * @tc.number : close_pipe_02 + * @tc.name : closePipe + * @tc.desc : 反向测试 关闭设备 错误 busNum + */ + it('SUB_USB_close_pipe_02', 0, function () { + console.info('usb close_pipe_02 begin'); + 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 close_pipe_02 : PASS'); + }) + + /** + * @tc.number : close_pipe_03 + * @tc.name : closePipe + * @tc.desc : 反向测试 关闭设备 错误 devAddress + */ + it('SUB_USB_close_pipe_03', 0, function () { + console.info('usb close_pipe_03 begin'); + 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 close_pipe_03 : PASS'); + }) + + /** + * @tc.number : close_pipe_04 + * @tc.name : closePipe + * @tc.desc : 反向测试 关闭设备 错误 devAddress busNum + */ + it('SUB_USB_close_pipe_04', 0, function () { + console.info('usb close_pipe_04 begin'); + 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 close_pipe_04 : PASS'); + }) + + /** + * @tc.number : close_pipe_01 + * @tc.name : closePipe + * @tc.desc : 关闭设备 + */ + it('SUB_USB_close_pipe_01', 0, function () { + console.info('usb close_pipe_01 begin'); + 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 close_pipe_01 : PASS'); + }) + +}) diff --git a/usb/usb_standard/src/main/js/default/test/UsbCoreJsunitEx.test.js b/usb/usb_standard/src/main/js/default/test/UsbCoreJsunitEx.test.js new file mode 100755 index 000000000..1556c4ac4 --- /dev/null +++ b/usb/usb_standard/src/main/js/default/test/UsbCoreJsunitEx.test.js @@ -0,0 +1,615 @@ +/* + * 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 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 + beforeAll(function () { + console.log('*************Usb Unit UsbCoreJsFunctionsTestEx Begin*************'); + var Version = usb.getVersion() + console.info('begin test getversion :' + Version) + // 切换为host + var usbPortList = usb.getPorts() + if (usbPortList.length > 0) { + if (usbPortList[0].status.currentMode == 1) { + usb.setPortRoles(usbPortList[0].id, 1, 1).then(data => { + console.info('usb case setPortRolesEx return: ' + data); + }).catch(error => { + console.info('usb case setPortRolesEx error : ' + error); + }); + console.log('*************Usb Unit Begin switch to host*************'); + } + } + gDeviceList = usb.getDevices(); + }) + 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 : connect_device_02 + * @tc.name : connectDevice + * @tc.desc : 反向测试 错误参数 devAddress 打开设备 + */ + it('SUB_USB_connect_device_02', 0, function () { + console.info('usb connect_device_02 begin'); + 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 02 requestRight error:' + error); + }); + console.info('usb 02 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 connect_device_02 : PASS'); + }) + + /** + * @tc.number : connect_device_03 + * @tc.name : connectDevice + * @tc.desc : 反向测试 busNum错误参数 打开设备 + */ + it('SUB_USB_connect_device_03', 0, function () { + console.info('usb connect_device_03 begin'); + 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 03 requestRight error:' + error); + }); + console.info('usb 03 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 connect_device_03 : PASS'); + }) + + /** + * @tc.number : connect_device_04 + * @tc.name : connectDevice + * @tc.desc : 反向测试 serial错误参数 打开设备 + */ + it('SUB_USB_connect_device_04', 0, function () { + console.info('usb connect_device_04 begin'); + 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 04 requestRight error:' + error); + }); + console.info('usb 04 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 connect_device_04 : PASS'); + }) + + /** + * @tc.number : connect_device_05 + * @tc.name : connectDevice + * @tc.desc : 反向测试 name错误参数 打开设备 + */ + it('SUB_USB_connect_device_05', 0, function () { + console.info('usb connect_device_05 begin'); + 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 05 requestRight error:' + error); + }); + console.info('usb 05 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 connect_device_05 : PASS'); + }) + + /** + * @tc.number : connect_device_06 + * @tc.name : connectDevice + * @tc.desc : 反向测试 manufacturerName错误参数 打开设备 + */ + it('SUB_USB_connect_device_06', 0, function () { + console.info('usb connect_device_06 begin'); + 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 06 requestRight error:' + error); + }); + console.info('usb 06 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 connect_device_06 : PASS'); + }) + + /** + * @tc.number : connect_device_07 + * @tc.name : connectDevice + * @tc.desc : 反向测试 productName错误参数 打开设备 + */ + it('SUB_USB_connect_device_07', 0, function () { + console.info('usb connect_device_07 begin'); + 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 07 requestRight error:' + error); + }); + console.info('usb 07 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 connect_device_07 : PASS'); + }) + + /** + * @tc.number : connect_device_08 + * @tc.name : connectDevice + * @tc.desc : 反向测试 version错误参数 打开设备 + */ + it('SUB_USB_connect_device_08', 0, function () { + console.info('usb connect_device_08 begin'); + 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 08 requestRight error:' + error); + }); + console.info('usb 08 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 connect_device_08 : PASS'); + }) + + /** + * @tc.number : connect_device_09 + * @tc.name : connectDevice + * @tc.desc : 反向测试 vendorId错误参数 打开设备 + */ + it('SUB_USB_connect_device_09', 0, function () { + console.info('usb connect_device_09 begin'); + 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 09 requestRight error:' + error); + }); + console.info('usb 09 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 connect_device_09 : PASS'); + }) + + /** + * @tc.number : connect_device_10 + * @tc.name : connectDevice + * @tc.desc : 反向测试 productId错误参数 打开设备 + */ + it('SUB_USB_connect_device_10', 0, function () { + console.info('usb connect_device_10 begin'); + 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 10 requestRight error:' + error); + }); + console.info('usb 10 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 connect_device_10 : PASS'); + }) + + /** + * @tc.number : connect_device_11 + * @tc.name : connectDevice + * @tc.desc : 反向测试 clazz错误参数 打开设备 + */ + it('SUB_USB_connect_device_11', 0, function () { + console.info('usb connect_device_11 begin'); + 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 11 requestRight error:' + error); + }); + console.info('usb 11 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 connect_device_11 : PASS'); + }) + + /** + * @tc.number : connect_device_12 + * @tc.name : connectDevice + * @tc.desc : 反向测试 subclass错误参数 打开设备 + */ + it('SUB_USB_connect_device_12', 0, function () { + console.info('usb connect_device_12 begin'); + 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 12 requestRight error:' + error); + }); + console.info('usb 12 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 connect_device_12 : PASS'); + }) + + /** + * @tc.number : connect_device_13 + * @tc.name : connectDevice + * @tc.desc : 反向测试 protocol错误参数 打开设备 + */ + it('SUB_USB_connect_device_13', 0, function () { + console.info('usb connect_device_13 begin'); + 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 13 requestRight error:' + error); + }); + console.info('usb 13 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 connect_device_13 : PASS'); + }) + + /** + * @tc.number : has_right_02 + * @tc.name : hasRight + * @tc.desc : 反向测试 给错误设备名字 + */ + it('SUB_USB_has_right_02', 0, function () { + console.info('usb has_right_02 begin'); + 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 has_right_02 : PASS'); + expect(true).assertTrue(); + }) + + /** + * @tc.number : has_right_03 + * @tc.name : hasRight + * @tc.desc : 反向测试 给设备名字为字母 + */ + it('SUB_USB_has_right_03', 0, function () { + console.info('usb has_right_03 begin'); + 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 has_right_03 : PASS'); + expect(true).assertTrue(); + }) + + /** + * @tc.number : request_right_02 + * @tc.name : requestRight + * @tc.desc : 反向测试 错误设备名字 请求权限 + */ + it('SUB_USB_request_right_02', 0, function () { + console.info('usb request_right_02 begin'); + 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 request_right_02 : PASS'); + }).catch(error => { + expect(error).assertFalse(); + console.info('usb request_right_02 error: ' + error); + }); + } + }) + + /** + * @tc.number : request_right_03 + * @tc.name : requestRight + * @tc.desc : 反向测试 设备名字为数字 请求权限 + */ + it('SUB_USB_request_right_03', 0, function () { + console.info('usb request_right_03 begin'); + 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 request_right_03 : PASS'); + }).catch(error => { + expect(error).assertFalse(); + console.info('usb request_right_03 error: ' + error); + }); + } + }) +}) diff --git a/usb/usb_standard/src/main/js/default/test/UsbDevicePipeJsunit.test.js b/usb/usb_standard/src/main/js/default/test/UsbDevicePipeJsunit.test.js new file mode 100755 index 000000000..a0106077f --- /dev/null +++ b/usb/usb_standard/src/main/js/default/test/UsbDevicePipeJsunit.test.js @@ -0,0 +1,465 @@ +/* + * 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 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 + + beforeAll(function () { + console.log('*************Usb Unit UsbDevicePipeJsFunctionsTest Begin*************'); + var Version = usb.getVersion() + console.info('usb unit begin test getversion :' + Version) + + // 切换为host + var usbPortList = usb.getPorts() + if (usbPortList.length > 0) { + if (usbPortList[0].status.currentMode == 1) { + usb.setPortRoles(usbPortList[0].id, 1, 1).then(data => { + console.info('usb case setPortRoles return: ' + data); + }).catch(error => { + console.info('usb case setPortRoles error : ' + error); + }); + console.log('*************Usb Unit switch to host Begin*************'); + } + } + + gDeviceList = usb.getDevices(); + 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 == EventConstants.USB_ENDPOINT_DIR_OUT) { + testParam.maxOutSize = endpoint.maxPacketSize; + testParam.outEndpoint = endpoint; + } else if (endpoint.direction == EventConstants.USB_ENDPOINT_DIR_IN) { + 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 : bulk_transfer_test_01 + * @tc.name : bulkTransfer + * @tc.desc : 批量传输 收数据 + */ + it('SUB_USB_bulk_transfer_test_01', 0, function () { + console.info('usb bulk_transfer_test_01 begin'); + var testParam = getTransferTestParam() + if (testParam.interface == null || testParam.inEndpoint == null) { + expect(false).assertTrue(); + return + } + + testParam.isClaimed = usb.releaseInterface(testParam.pip, testParam.interface) + expect(testParam.isClaimed).assertEqual(0); + 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 bulk_transfer_test_01 : PASS'); + expect(data >= 0).assertTrue(); + }).catch(error => { + console.info('usb case readData error : ' + JSON.stringify(error)); + expect(false).assertTrue(); + }); + }) + + /** + * @tc.number : bulk_transfer_test_02 + * @tc.name : bulkTransfer + * @tc.desc : 批量传输 发数据 + */ + it('SUB_USB_bulk_transfer_test_02', 0, function () { + console.info('usb bulk_transfer_test_02 begin'); + var testParam = getTransferTestParam() + if (testParam.interface == null || testParam.outEndpoint == null) { + expect(false).assertTrue(); + return + } + + testParam.isClaimed = usb.releaseInterface(testParam.pip, testParam.interface) + expect(testParam.isClaimed).assertEqual(0); + 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 bulk_transfer_test_02 ret: ' + data); + console.info('usb case bulk_transfer_test_02 send data: ' + testParam.sendData); + console.info('usb case bulk_transfer_test_02 : PASS'); + expect(true).assertTrue(); + }).catch(error => { + console.info('usb write error : ' + JSON.stringify(error)); + expect(false).assertTrue(); + }); + + }) + + /** + * @tc.number : claim_interface_test_01 + * @tc.name : claimInterface + * @tc.desc : 获取接口 并释放 + */ + it('SUB_USB_claim_interface_test_01', 0, function () { + console.info('usb claim_interface_test_01 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 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); + } + } + } + + console.info('usb claim_interface_test_01 : 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 : set_configuration_test_01 + * @tc.name : setConfiguration + * @tc.desc : 设置设备接口 + */ + it('SUB_USB_set_configuration_test_01', 0, function () { + console.info('usb set_configuration_test_01 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 ret = usb.setConfiguration(gPipe, gDeviceList[0].configs[j]) + console.info('usb case setConfiguration return : ' + ret); + expect(ret).assertEqual(0); + } + + console.info('usb set_configuration_test_01 : PASS'); + expect(true).assertTrue(); + }) + + /** + * @tc.number : set_configuration_test_02 + * @tc.name : setConfiguration + * @tc.desc : 反向测试 设置设备接口 + */ + it('SUB_USB_set_configuration_test_02', 0, function () { + console.info('usb set_configuration_test_02 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 set_configuration_test_02 : PASS'); + }) + + /** + * @tc.number : set_interface_test_01 + * @tc.name : setInterface + * @tc.desc : 设置设备接口 + */ + it('SUB_USB_set_interface_test_01', 0, function () { + console.info('usb set_interface_test_01 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 set_interface_test_01 : PASS'); + expect(true).assertTrue(); + }) + + /** + * @tc.number : set_interface_test_02 + * @tc.name : setInterface + * @tc.desc : 反向测试 设置设备接口 + */ + it('SUB_USB_set_interface_test_02', 0, function () { + console.info('usb set_interface_test_02 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 set_interface_test_02 : 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 : control_transfer_test_01 + * @tc.name : controlTransfer + * @tc.desc : 控制传输 GetDescriptor: cmd 6 reqType 128 value 512 index 0 + */ + it('SUB_USB_control_transfer_test_01', 0, function () { + console.info('usb control_transfer_test_01 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, ((1 << 7) | (0 << 5) | (0 & 0x1f)), (2 << 8), 0) + callControlTransfer(testParam.pip, controlParam, timeout, 'control_transfer_test_01 GetDescriptor') + }) + + /** + * @tc.number : control_transfer_test_02 + * @tc.name : controlTransfer + * @tc.desc : 控制传输 GetStatus: cmd 0 reqType 128 value 0 index 0 + */ + it('SUB_USB_control_transfer_test_02', 0, function () { + console.info('usb control_transfer_test_02 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, 128, 0, 0) + callControlTransfer(testParam.pip, controlParam, timeout, 'control_transfer_test_02 GetStatus') + }) + + /** + * @tc.number : control_transfer_test_03 + * @tc.name : controlTransfer + * @tc.desc : 控制传输 GetConfiguration: cmd 8 reqType 128 value 0 index 0 + */ + it('SUB_USB_control_transfer_test_03', 0, function () { + console.info('usb control_transfer_test_03 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, 128, 0, 0) + callControlTransfer(testParam.pip, controlParam, timeout, 'control_transfer_test_03 GetConfiguration') + }) + + /** + * @tc.number : control_transfer_test_04 + * @tc.name : controlTransfer + * @tc.desc : 控制传输 GetInterface: cmd 10 reqType 129 value 0 index 1 + */ + it('SUB_USB_control_transfer_test_04', 0, function () { + console.info('usb control_transfer_test_04 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, 129, 0, 1) + callControlTransfer(testParam.pip, controlParam, timeout, 'control_transfer_test_04 GetInterface') + }) + + /** + * @tc.number : control_transfer_test_05 + * @tc.name : controlTransfer + * @tc.desc : 控制传输 ClearFeature: cmd 1 reqType 0 value 0 index 0 + */ + it('SUB_USB_control_transfer_test_05', 0, function () { + console.info('usb control_transfer_test_05 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, 0, 0, 0) + callControlTransfer(testParam.pip, controlParam, timeout, 'control_transfer_test_05 ClearFeature') + }) + +}) diff --git a/usb/usb_standard/src/main/js/default/test/UsbDevicePipeJsunitEx.test.js b/usb/usb_standard/src/main/js/default/test/UsbDevicePipeJsunitEx.test.js new file mode 100755 index 000000000..42f715712 --- /dev/null +++ b/usb/usb_standard/src/main/js/default/test/UsbDevicePipeJsunitEx.test.js @@ -0,0 +1,778 @@ +/* + * 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 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 + + beforeAll(function () { + console.log('*************Usb Unit UsbDevicePipeJsFunctionsTestEx Begin*************'); + var Version = usb.getVersion() + console.info('usb unit begin test getversion :' + Version) + + // 切换为host + var usbPortList = usb.getPorts() + if (usbPortList.length > 0) { + if (usbPortList[0].status.currentMode == 1) { + usb.setPortRoles(usbPortList[0].id, 1, 1).then(data => { + 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) + } + } + + gDeviceList = usb.getDevices(); + 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 == EventConstants.USB_ENDPOINT_DIR_OUT) { + testParam.outEndpoint = endpoint; + testParam.maxOutSize = endpoint.maxPacketSize; + } else if (endpoint.direction == EventConstants.USB_ENDPOINT_DIR_IN) { + 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 : bulk_transfer_test_03 + * @tc.name : bulkTransfer + * @tc.desc : 反向测试 批量传输 发数据 修改 outEndpoint.address = 123 + */ + it('SUB_USB_bulk_transfer_test_03', 0, function () { + console.info('usb bulk_transfer_test_03 begin'); + var testParam = getTransferTestParam() + if (testParam.interface == null || testParam.outEndpoint == null) { + expect(false).assertTrue(); + return + } + + testParam.isClaimed = usb.releaseInterface(testParam.pip, testParam.interface) + expect(testParam.isClaimed).assertEqual(0); + 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 bulk_transfer_test_03 ret: ' + data); + console.info('usb case bulk_transfer_test_03 : PASS'); + expect(data).assertEqual(-1); + }).catch(error => { + console.info('usb 03 write error : ' + JSON.stringify(error)); + console.info('usb case bulk_transfer_test_03 : PASS'); + expect(false).assertFalse(); + }); + }) + + /** + * @tc.number : bulk_transfer_test_04 + * @tc.name : bulkTransfer + * @tc.desc : 反向测试 批量传输 发数据 修改 outEndpoint.number = 123 + */ + it('SUB_USB_bulk_transfer_test_04', 0, function () { + console.info('usb bulk_transfer_test_04 begin'); + var testParam = getTransferTestParam() + if (testParam.interface == null || testParam.outEndpoint == null) { + expect(false).assertTrue(); + return + } + + testParam.isClaimed = usb.releaseInterface(testParam.pip, testParam.interface) + expect(testParam.isClaimed).assertEqual(0); + 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 bulk_transfer_test_04 ret: ' + data); + console.info('usb case bulk_transfer_test_04 : PASS'); + expect(data).assertEqual(-1); + }).catch(error => { + console.info('usb 04 write error : ' + JSON.stringify(error)); + console.info('usb case bulk_transfer_test_04 : PASS'); + expect(false).assertFalse(); + }); + }) + + /** + * @tc.number : bulk_transfer_test_05 + * @tc.name : bulkTransfer + * @tc.desc : 反向测试 批量传输 发数据 修改 outEndpoint.type = 123 + */ + it('SUB_USB_bulk_transfer_test_05', 0, function () { + console.info('usb bulk_transfer_test_05 begin'); + var testParam = getTransferTestParam() + if (testParam.interface == null || testParam.outEndpoint == null) { + expect(false).assertTrue(); + return + } + + testParam.isClaimed = usb.releaseInterface(testParam.pip, testParam.interface) + expect(testParam.isClaimed).assertEqual(0); + 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 bulk_transfer_test_05 ret: ' + data); + console.info('usb case bulk_transfer_test_05 : PASS'); + expect(data).assertEqual(-1); + }).catch(error => { + console.info('usb 05 write error : ' + JSON.stringify(error)); + console.info('usb case bulk_transfer_test_05 : PASS'); + expect(false).assertFalse(); + }); + }) + + /** + * @tc.number : claim_interface_test_02 + * @tc.name : claimInterface + * @tc.desc : 反向测试 USBInterface传入异常id 获取接口 失败 + */ + it('SUB_USB_claim_interface_test_02', 0, function () { + console.info('usb claim_interface_test_02 begin'); + 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 02 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 02 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 claim_interface_test_02 : PASS'); + expect(true).assertTrue(); + }) + + /** + * @tc.number : claim_interface_test_03 + * @tc.name : claimInterface + * @tc.desc : 反向测试 USBInterface传入异常protocol 获取接口 失败 + */ + it('SUB_USB_claim_interface_test_03', 0, function () { + console.info('usb claim_interface_test_03 begin'); + 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 03 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 03 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 claim_interface_test_03 : PASS'); + expect(true).assertTrue(); + }) + + /** + * @tc.number : claim_interface_test_04 + * @tc.name : claimInterface + * @tc.desc : 反向测试 USBInterface传入异常clazz 获取接口 失败 + */ + it('SUB_USB_claim_interface_test_04', 0, function () { + console.info('usb claim_interface_test_04 begin'); + 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 04 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 04 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 claim_interface_test_04 : PASS'); + expect(true).assertTrue(); + }) + + /** + * @tc.number : claim_interface_test_05 + * @tc.name : claimInterface + * @tc.desc : 反向测试 USBInterface传入异常name 获取接口 失败 + */ + it('SUB_USB_claim_interface_test_05', 0, function () { + console.info('usb claim_interface_test_05 begin'); + 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 05 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 05 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 claim_interface_test_05 : PASS'); + expect(true).assertTrue(); + }) + + /** + * @tc.number : claim_interface_test_06 + * @tc.name : claimInterface + * @tc.desc : 反向测试 USBInterface传入异常subClass 获取接口 失败 + */ + it('SUB_USB_claim_interface_test_06', 0, function () { + console.info('usb claim_interface_test_06 begin'); + 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 06 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 06 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 claim_interface_test_06 : PASS'); + expect(true).assertTrue(); + }) + + /** + * @tc.number : release_interface_test_01 + * @tc.name : releaseInterface + * @tc.desc : 反向测试 获取接口 release传入Interface的错误ID 并释放 + */ + it('SUB_USB_release_interface_test_01', 0, function () { + console.info('usb release_interface_test_01 begin'); + 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 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 01 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 release_interface_test_01 : PASS'); + expect(true).assertTrue(); + }) + + /** + * @tc.number : release_interface_test_02 + * @tc.name : releaseInterface + * @tc.desc : 反向测试 获取接口 release传入Interface的错误name 并释放 + */ + it('SUB_USB_release_interface_test_02', 0, function () { + console.info('usb release_interface_test_02 begin'); + 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 02 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 02 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 release_interface_test_02 : PASS'); + expect(true).assertTrue(); + }) + + /** + * @tc.number : release_interface_test_03 + * @tc.name : releaseInterface + * @tc.desc : 反向测试 获取接口 release传入Interface的错误clazz 并释放 + */ + it('SUB_USB_release_interface_test_03', 0, function () { + console.info('usb release_interface_test_03 begin'); + 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 03 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 03 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 release_interface_test_03 : PASS'); + expect(true).assertTrue(); + }) + + /** + * @tc.number : release_interface_test_04 + * @tc.name : releaseInterface + * @tc.desc : 反向测试 获取接口 release传入Interface的错误protocol 并释放 + */ + it('SUB_USB_release_interface_test_04', 0, function () { + console.info('usb release_interface_test_04 begin'); + 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 04 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 04 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 release_interface_test_04 : PASS'); + expect(true).assertTrue(); + }) + + /** + * @tc.number : release_interface_test_05 + * @tc.name : releaseInterface + * @tc.desc : 反向测试 获取接口 release传入Interface的错误subClass 并释放 + */ + it('SUB_USB_release_interface_test_05', 0, function () { + console.info('usb release_interface_test_05 begin'); + 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 05 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 05 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 release_interface_test_05 : PASS'); + expect(true).assertTrue(); + }) + + /** + * @tc.number : set_interface_test_03 + * @tc.name : setInterface + * @tc.desc : 反向测试 Interface的protocol 设置设备接口 + */ + it('SUB_USB_set_interface_test_03', 0, function () { + console.info('usb set_interface_test_03 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 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 set_interface_test_03 : PASS'); + expect(true).assertTrue(); + }) + + /** + * @tc.number : set_interface_test_04 + * @tc.name : setInterface + * @tc.desc : 反向测试 Interface的clazz 设置设备接口 + */ + it('SUB_USB_set_interface_test_04', 0, function () { + console.info('usb set_interface_test_04 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) + + 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 set_interface_test_04 : PASS'); + expect(true).assertTrue(); + }) + + /** + * @tc.number : set_interface_test_05 + * @tc.name : setInterface + * @tc.desc : 反向测试 Interface的subClass 设置设备接口 + */ + it('SUB_USB_set_interface_test_05', 0, function () { + console.info('usb set_interface_test_05 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) + + 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 set_interface_test_05 : PASS'); + expect(true).assertTrue(); + }) + + /** + * @tc.number : set_interface_test_06 + * @tc.name : setInterface + * @tc.desc : 反向测试 Interface的name 设置设备接口 + */ + it('SUB_USB_set_interface_test_06', 0, function () { + console.info('usb set_interface_test_05 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) + + 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 set_interface_test_06 : PASS'); + expect(true).assertTrue(); + }) + + /** + * @tc.number : set_configuration_test_03 + * @tc.name : setConfiguration + * @tc.desc : 反向测试 USBConfig的name 赋值错误 设置设备接口 + */ + it('SUB_USB_set_configuration_test_03', 0, function () { + console.info('usb set_configuration_test_03 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 = 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 set_configuration_test_03 : PASS'); + }) + + /** + * @tc.number : set_configuration_test_04 + * @tc.name : setConfiguration + * @tc.desc : 反向测试 USBConfig的name 赋值错误 设置设备接口 + */ + it('SUB_USB_set_configuration_test_04', 0, function () { + console.info('usb set_configuration_test_04 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 = 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 set_configuration_test_04 : PASS'); + }) + + /** + * @tc.number : set_configuration_test_05 + * @tc.name : setConfiguration + * @tc.desc : 反向测试 USBConfig的attributes 赋值错误 设置设备接口 + */ + it('SUB_USB_set_configuration_test_05', 0, function () { + console.info('usb set_configuration_test_05 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 = 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 set_configuration_test_05 : PASS'); + }) + + +}) diff --git a/usb/usb_standard/src/main/js/default/test/UsbFunctionsJsunit.test.js b/usb/usb_standard/src/main/js/default/test/UsbFunctionsJsunit.test.js new file mode 100755 index 000000000..73320625f --- /dev/null +++ b/usb/usb_standard/src/main/js/default/test/UsbFunctionsJsunit.test.js @@ -0,0 +1,203 @@ +/* + * 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 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) + // 切换到 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); + }); + 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 : get_current_functions_test_01 + * @tc.name : getCurrentFunctions + * @tc.desc : 获取当前设备模式 掩码与描述字符转换 + */ + it('SUB_USB_get_current_functions_test_01', 0, function () { + console.info('usb get_current_functions_test_01 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 get_current_functions_test_01 : PASS'); + expect(true).assertTrue(); + }) + + /** + * @tc.number : get_current_functions_test_02 + * @tc.name : usbFunctionString + * @tc.desc : 反向测试 获取当前设备模式 掩码与描述字符转换 + */ + it('SUB_USB_get_current_functions_test_02', 0, function () { + console.info('usb get_current_functions_test_02 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 get_current_functions_test_02 : PASS'); + }) + + function callSetCurFunction(caseName, iValue) { + CheckEmptyUtils.sleep(3000) + console.info('usb case param case name:' + caseName); + console.info('usb case param iValue:' + iValue); + usb.setCurrentFunctions(iValue).then(data => { + console.info('usb case SetCurFunction ret:' + data); + expect(data).assertTrue(); + console.info('usb case ' + caseName + ': PASS'); + }).catch(error => { + console.info('usb case ' + caseName + ' error : ' + error); + expect(false).assertTrue(); + }); + } + + /** + * @tc.number : set_current_functions_test_02 + * @tc.name : functions_test + * @tc.desc : 在设备模式下设置当前的USB功能列表 Set 1 设置为ACM功能 + */ + it('SUB_USB_set_current_functions_test_02', 0, function () { + CheckEmptyUtils.sleep(3000) + console.info('usb set_current_functions_test_02 set ACM begin'); + var maskCode = usb.getCurrentFunctions(); + console.info('usb case getCurrentFunctions return: ' + maskCode); + var funcString = usb.usbFunctionsToString(maskCode); + console.info('usb case funcString:' + funcString); + callSetCurFunction('set_current_functions_test_02 ACM 1', 1) + }) + + /** + * @tc.number : set_current_functions_test_03 + * @tc.name : functions_test + * @tc.desc : 在设备模式下设置当前的USB功能列表 Set 2 设置为ECM功能 + */ + it('SUB_USB_set_current_functions_test_03', 0, function () { + CheckEmptyUtils.sleep(3000) + console.info('usb set_current_functions_test_03 set ECM begin'); + var maskCode = usb.getCurrentFunctions(); + console.info('usb case getCurrentFunctions return: ' + maskCode); + var funcString = usb.usbFunctionsToString(maskCode); + console.info('usb case funcString:' + funcString); + callSetCurFunction('set_current_functions_test_03 ECM 2', 2) + }) + + /** + * @tc.number : set_current_functions_test_04 + * @tc.name : functions_test + * @tc.desc : 在设备模式下设置当前的USB功能列表 Set 3 设置为ACM、ECM功能 + */ + it('SUB_USB_set_current_functions_test_04', 0, function () { + CheckEmptyUtils.sleep(3000) + console.info('usb set_current_functions_test_04 set ACM ECM begin'); + var maskCode = usb.getCurrentFunctions(); + console.info('usb case getCurrentFunctions return: ' + maskCode); + var funcString = usb.usbFunctionsToString(maskCode); + console.info('usb case funcString:' + funcString); + callSetCurFunction('set_current_functions_test_04 ACM ECM 3', 3) + }) + + /** + * @tc.number : set_current_functions_test_05 + * @tc.name : functions_test + * @tc.desc : 在设备模式下设置当前的USB功能列表 Set 4 设置为HDC功能 + */ + it('SUB_USB_set_current_functions_test_05', 0, function () { + CheckEmptyUtils.sleep(3000) + console.info('usb set_current_functions_test_05 set HDC begin'); + var maskCode = usb.getCurrentFunctions(); + console.info('usb case getCurrentFunctions return: ' + maskCode); + var funcString = usb.usbFunctionsToString(maskCode); + console.info('usb case funcString:' + funcString); + callSetCurFunction('set_current_functions_test_05 HDC 4', 4) + }) + + /** + * @tc.number : set_current_functions_test_06 + * @tc.name : functions_test + * @tc.desc : 在设备模式下设置当前的USB功能列表 Set 5 设置为ACM、HDC功能 + */ + it('SUB_USB_set_current_functions_test_06', 0, function () { + CheckEmptyUtils.sleep(3000) + console.info('usb set_current_functions_test_06 set ACM HDC begin'); + var maskCode = usb.getCurrentFunctions(); + console.info('usb case getCurrentFunctions return: ' + maskCode); + var funcString = usb.usbFunctionsToString(maskCode); + console.info('usb case funcString:' + funcString); + callSetCurFunction('set_current_functions_test_06 ACM HDC 5', 5) + }) + + /** + * @tc.number : set_current_functions_test_07 + * @tc.name : functions_test + * @tc.desc : 在设备模式下设置当前的USB功能列表 Set 6 设置为ECM、HDC功能 + */ + it('SUB_USB_set_current_functions_test_07', 0, function () { + CheckEmptyUtils.sleep(3000) + console.info('usb set_current_functions_test_07 set ECM HDC begin'); + var maskCode = usb.getCurrentFunctions(); + console.info('usb case getCurrentFunctions return: ' + maskCode); + var funcString = usb.usbFunctionsToString(maskCode); + console.info('usb case funcString:' + funcString); + callSetCurFunction('set_current_functions_test_07 ECM HDC 6', 6) + }) + +}) diff --git a/usb/usb_standard/src/main/js/default/test/UsbFunctionsJsunitEx.test.js b/usb/usb_standard/src/main/js/default/test/UsbFunctionsJsunitEx.test.js new file mode 100755 index 000000000..f339e8f63 --- /dev/null +++ b/usb/usb_standard/src/main/js/default/test/UsbFunctionsJsunitEx.test.js @@ -0,0 +1,250 @@ +/* + * 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 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) + + // 切换到 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); + }); + + 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 : usb_function_to_string_test_01 + * @tc.name : usbFunctionsToString + * @tc.desc : 正向测试 0 返回 'none' + */ + it('SUB_USB_usb_function_to_string_test_01', 0, function () { + console.info('usb usb_function_to_string_test_01 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 usb_function_to_string_test_01 : PASS'); + }) + + /** + * @tc.number : usb_function_to_string_test_02 + * @tc.name : usbFunctionsToString + * @tc.desc : 正向测试 1 返回 'acm' + */ + it('SUB_USB_usb_function_to_string_test_02', 0, function () { + console.info('usb usb_function_to_string_test_02 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 usb_function_to_string_test_02 : PASS'); + }) + + /** + * @tc.number : usb_function_to_string_test_03 + * @tc.name : usbFunctionsToString + * @tc.desc : 正向测试 2 返回 'ecm' + */ + it('SUB_USB_usb_function_to_string_test_03', 0, function () { + console.info('usb usb_function_to_string_test_02 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 usb_function_to_string_test_02 : PASS'); + }) + + /** + * @tc.number : usb_function_to_string_test_04 + * @tc.name : usbFunctionsToString + * @tc.desc : 正向测试 3 返回 'acm,ecm' + */ + it('SUB_USB_usb_function_to_string_test_04', 0, function () { + console.info('usb usb_function_to_string_test_02 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 usb_function_to_string_test_02 : PASS'); + }) + + /** + * @tc.number : usb_function_to_string_test_05 + * @tc.name : usbFunctionsToString + * @tc.desc : 正向测试 4 返回 'hdc' + */ + it('SUB_USB_usb_function_to_string_test_05', 0, function () { + console.info('usb usb_function_to_string_test_05 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 usb_function_to_string_test_05 : PASS'); + }) + + /** + * @tc.number : usb_function_to_string_test_06 + * @tc.name : usbFunctionsToString + * @tc.desc : 正向测试 5 返回 'acm,hdc' + */ + it('SUB_USB_usb_function_to_string_test_06', 0, function () { + console.info('usb usb_function_to_string_test_06 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 usb_function_to_string_test_06 : PASS'); + }) + + /** + * @tc.number : usb_function_to_string_test_07 + * @tc.name : usbFunctionsToString + * @tc.desc : 正向测试 6 返回 'ecm,hdc' + */ + it('SUB_USB_usb_function_to_string_test_07', 0, function () { + console.info('usb usb_function_to_string_test_07 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 usb_function_to_string_test_07 : PASS'); + }) + + /** + * @tc.number : usb_function_from_string_test_01 + * @tc.name : usbFunctionsFromString + * @tc.desc : 正向测试 'none' 返回 0 + */ + it('SUB_USB_usb_function_from_string_test_01', 0, function () { + console.info('usb usb_function_from_string_test_01 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 usb_function_to_string_test_01 : PASS'); + }) + + /** + * @tc.number : usb_function_from_string_test_02 + * @tc.name : usbFunctionsFromString + * @tc.desc : 正向测试 'acm' 返回 1 + */ + it('SUB_USB_usb_function_from_string_test_02', 0, function () { + console.info('usb usb_function_from_string_test_02 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 usb_function_from_string_test_02 : PASS'); + }) + + /** + * @tc.number : usb_function_from_string_test_03 + * @tc.name : usbFunctionsFromString + * @tc.desc : 正向测试 'ecm' 返回 2 + */ + it('SUB_USB_usb_function_from_string_test_03', 0, function () { + console.info('usb usb_function_from_string_test_03 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 usb_function_from_string_test_03 : PASS'); + }) + + /** + * @tc.number : usb_function_from_string_test_04 + * @tc.name : usbFunctionsFromString + * @tc.desc : 正向测试 'acm,ecm' 返回 3 + */ + it('SUB_USB_usb_function_from_string_test_04', 0, function () { + console.info('usb usb_function_from_string_test_04 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 usb_function_from_string_test_04 : PASS'); + }) + + /** + * @tc.number : usb_function_from_string_test_05 + * @tc.name : usbFunctionsFromString + * @tc.desc : 正向测试 'hdc' 返回 4 + */ + it('SUB_USB_usb_function_from_string_test_05', 0, function () { + console.info('usb usb_function_from_string_test_05 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 usb_function_from_string_test_04 : PASS'); + }) + + /** + * @tc.number : usb_function_from_string_test_06 + * @tc.name : usbFunctionsFromString + * @tc.desc : 正向测试 'acm,hdc' 返回 5 + */ + it('SUB_USB_usb_function_from_string_test_06', 0, function () { + console.info('usb usb_function_from_string_test_06 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 usb_function_from_string_test_06 : PASS'); + }) + + /** + * @tc.number : usb_function_from_string_test_07 + * @tc.name : usbFunctionsFromString + * @tc.desc : 正向测试 'ecm,hdc' 返回 6 + */ + it('SUB_USB_usb_function_from_string_test_07', 0, function () { + console.info('usb usb_function_from_string_test_07 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 usb_function_from_string_test_07 : PASS'); + }) + +}) diff --git a/usb/usb_standard/src/main/js/default/test/UsbPortJsunit.test.js b/usb/usb_standard/src/main/js/default/test/UsbPortJsunit.test.js new file mode 100755 index 000000000..86be31742 --- /dev/null +++ b/usb/usb_standard/src/main/js/default/test/UsbPortJsunit.test.js @@ -0,0 +1,139 @@ +/* + * 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 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 : get_ports_test_01 + * @tc.name : getPorts + * @tc.desc : 获取USB端口描述信息列表 + */ + it('SUB_USB_get_ports_test_01', 0, function () { + console.info('usb get_ports_test_01 begin'); + var usbPortList = usb.getPorts() + if (usbPortList.length == 0) { + console.info('usb get_ports_test_01 usbPortList is null'); + expect(false).assertTrue(); + return + } + expect(usbPortList.length > 0).assertTrue(); + console.info('usb get_ports_test_01 : PASS'); + expect(true).assertTrue(); + }) + + /** + * @tc.number : get_supported_modes_test_01 + * @tc.name : getSupportedModes + * @tc.desc : 获取指定的端口支持的模式列表的组合掩码 + */ + it('SUB_USB_get_supported_modes_test_01', 0, function () { + console.info('usb get_supported_modes_test_01 begin'); + var usbPortList = usb.getPorts() + if (usbPortList.length == 0) { + console.info('usb get_supported_modes_test_01 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 get_supported_modes_test_01 : PASS'); + expect(true).assertTrue(); + }) + + /** + * @tc.number : set_port_roles_test_01 + * @tc.name : setPortRoles + * @tc.desc : 切换为Device set powerRole 2 DataRole 2 + */ + it('SUB_USB_set_port_roles_test_01', 0, function () { + console.info('usb set_port_roles_test_01 device 2 2 begin'); + var usbPortList = usb.getPorts() + if (usbPortList.length == 0) { + console.info('usb set_port_roles_test_01 device 2 2 usbPortList is null'); + expect(false).assertTrue(); + return + } + + for (var i = 0; i < usbPortList.length; i++) { + console.info('usb case set data role 2, data role 2'); + usb.setPortRoles(usbPortList[i].id, 2, 2).then(data => { + console.info('usb case setPortRoles return: ' + data); + expect(data).assertTrue(); + }).catch(error => { + console.info('usb case setPortRoles error : ' + error); + expect(false).assertTrue(); + }); + } + + console.info('usb set_port_roles_test_01 device 2 2: PASS'); + expect(true).assertTrue(); + }) + + /** + * @tc.number : set_port_roles_test_02 + * @tc.name : setPortRoles + * @tc.desc : 切换为host set powerRole 1 DataRole 1 + */ + it('SUB_USB_set_port_roles_test_02', 0, function () { + console.info('usb set_port_roles_test_02 host 1 1 begin'); + var usbPortList = usb.getPorts() + if (usbPortList.length == 0) { + console.info('usb set_port_roles_test_02 host 1 1 usbPortList is null'); + expect(false).assertTrue(); + return + } + + for (var i = 0; i < usbPortList.length; i++) { + console.info('usb case set data role 1, data role 1'); + CheckEmptyUtils.sleep(5000) + usb.setPortRoles(usbPortList[i].id, 1, 1).then(data => { + expect(data).assertTrue(); + console.info('usb case setPortRoles return: ' + data); + }).catch(error => { + console.info('usb case setPortRoles error : ' + error); + expect(false).assertTrue(); + }); + } + + console.info('usb set_port_roles_test_02 host 1 1: 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/default/test/UsbPortJsunitEx.test.js new file mode 100755 index 000000000..dfb508800 --- /dev/null +++ b/usb/usb_standard/src/main/js/default/test/UsbPortJsunitEx.test.js @@ -0,0 +1,387 @@ +/* + * 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 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 () { + + 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 : get_supported_modes_test_02 + * @tc.name : getSupportedModes + * @tc.desc : 反向测试 改变id 获取指定的端口支持的模式列表的组合掩码 + */ + it('SUB_USB_get_supported_modes_test_02', 0, function () { + console.info('usb get_supported_modes_test_02 begin'); + var usbPortList = usb.getPorts() + if (usbPortList.length == 0) { + console.info('usb get_supported_modes_test_01 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 get_supported_modes_test_02 : PASS'); + expect(true).assertTrue(); + }) + + /** + * @tc.number : set_port_roles_test_03 + * @tc.name : setPortRoles + * @tc.desc : Device模式下,dataRole参数错误 + */ + it('SUB_USB_set_port_roles_test_03', 0, function () { + var portId = 2; + var powerRole = 2; + var dataRole = -1; + CheckEmptyUtils.sleep(2000) + usb.setPortRoles(2, 2, -1).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('set_port_roles_test_03: PASS'); + }) + + console.info('set_port_roles_test_03: PASS'); + expect(true).assertTrue(); + }) + + /** + * @tc.number : set_port_roles_test_04 + * @tc.name : setPortRoles + * @tc.desc : Device模式下,portId,powerRole参数错误 + */ + it('SUB_USB_set_port_roles_test_04', 0, function () { + var portId = -1; + var powerRole = -1; + var dataRole = 2; + CheckEmptyUtils.sleep(2000) + usb.setPortRoles(-1, -1, 2).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('set_port_roles_test_04: PASS'); + }) + + console.info('set_port_roles_test_04: PASS'); + expect(true).assertTrue(); + }) + + /** + * @tc.number : set_port_roles_test_05 + * @tc.name : setPortRoles + * @tc.desc : Device模式下,portId,dataRole参数错误 + */ + it('SUB_USB_set_port_roles_test_05', 0, function () { + var portId = -1; + var powerRole = 2; + var dataRole = -1; + CheckEmptyUtils.sleep(2000) + usb.setPortRoles(-1, 2, -1).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('set_port_roles_test_05: PASS'); + }) + + console.info('set_port_roles_test_05: PASS'); + expect(true).assertTrue(); + }) + + /** + * @tc.number : set_port_roles_test_06 + * @tc.name : setPortRoles + * @tc.desc : Device模式下,powerRole,dataRole参数错误 + */ + it('SUB_USB_set_port_roles_test_06', 0, function () { + var portId = 2; + var powerRole = -1; + var dataRole = -1; + CheckEmptyUtils.sleep(2000) + usb.setPortRoles(2, -1, -1).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('set_port_roles_test_06: PASS'); + }) + + console.info('set_port_roles_test_06: PASS'); + expect(true).assertTrue(); + }) + + /** + * @tc.number : set_port_roles_test_07 + * @tc.name : setPortRoles + * @tc.desc : Device模式下,portId,portId,dataRole参数错误 + */ + it('SUB_USB_set_port_roles_test_07', 0, function () { + var portId = -1; + var dataRole = -1; + var powerRole = -1; + + CheckEmptyUtils.sleep(2000) + usb.setPortRoles(-1, -1, -1).then(data => { + console.info('usb case setPortRoles 07 return: ' + data); + expect(data).assertTrue(); + }).catch(error => { + console.info('usb case setPortRoles 07 error : ' + error); + expect(error).assertFalse(); + console.info('set_port_roles_test_07: PASS'); + }) + + console.info('set_port_roles_test_07: PASS'); + expect(true).assertTrue(); + }) + + /** + * @tc.number : set_port_roles_test_08 + * @tc.name : setPortRoles + * @tc.desc : host模式下,portId参数错误 + */ + it('SUB_USB_set_port_roles_test_08', 0, function () { + var portId = -1; + var powerRole = 1; + var dataRole = 1; + CheckEmptyUtils.sleep(2000) + usb.setPortRoles(-1, 1, 1).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('set_port_roles_test_08: PASS'); + }) + + console.info('set_port_roles_test_08: PASS'); + expect(true).assertTrue(); + }) + + /** + * @tc.number : set_port_roles_test_09 + * @tc.name : setPortRoles + * @tc.desc : host模式下,powerRole参数错误 + */ + it('SUB_USB_set_port_roles_test_09', 0, function () { + var portId = 1; + var powerRole = -1; + var dataRole = 1; + CheckEmptyUtils.sleep(2000) + usb.setPortRoles(1, -1, 1).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('set_port_roles_test_09: PASS'); + }) + + console.info('set_port_roles_test_09: PASS'); + expect(true).assertTrue(); + }) + + /** + * @tc.number : set_port_roles_test_10 + * @tc.name : setPortRoles + * @tc.desc : host模式下,dataRole参数错误 + */ + it('SUB_USB_set_port_roles_test_10', 0, function () { + var portId = 1; + var powerRole = 1; + var dataRole = -1; + CheckEmptyUtils.sleep(2000) + usb.setPortRoles(1, -1, 1).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('set_port_roles_test_10: PASS'); + }) + + console.info('set_port_roles_test_10: PASS'); + expect(true).assertTrue(); + }) + + /** + * @tc.number : set_port_roles_test_11 + * @tc.name : setPortRoles + * @tc.desc : host模式下,portId,powerRole参数错误 + */ + it('SUB_USB_set_port_roles_test_11', 0, function () { + var portId = -1; + var powerRole = -1; + var dataRole = 1; + CheckEmptyUtils.sleep(2000) + usb.setPortRoles(-1, -1, 1).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('set_port_roles_test_11: PASS'); + }) + + console.info('set_port_roles_test_11: PASS'); + expect(true).assertTrue(); + }) + + /** + * @tc.number : set_port_roles_test_12 + * @tc.name : setPortRoles + * @tc.desc : host模式下,portId,dataRole参数错误 + */ + it('SUB_USB_set_port_roles_test_12', 0, function () { + var portId = -1; + var powerRole = 1; + var dataRole = -1; + CheckEmptyUtils.sleep(2000) + usb.setPortRoles(-1, 1, -1).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('set_port_roles_test_12: PASS'); + }) + + console.info('set_port_roles_test_12: PASS'); + expect(true).assertTrue(); + }) + + /** + * @tc.number : set_port_roles_test_13 + * @tc.name : setPortRoles + * @tc.desc : host模式下,powerRole,dataRole参数错误 + */ + it('SUB_USB_set_port_roles_test_13', 0, function () { + var portId = 1; + var powerRole = -1; + var dataRole = -1; + CheckEmptyUtils.sleep(2000) + usb.setPortRoles(1, -1, -1).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('set_port_roles_test_13: PASS'); + }) + + console.info('set_port_roles_test_13: PASS'); + expect(true).assertTrue(); + }) + + /** + * @tc.number : set_port_roles_test_14 + * @tc.name : setPortRoles + * @tc.desc : host模式下,portId,powerRole,dataRole参数错误 + */ + it('SUB_USB_set_port_roles_test_14', 0, function () { + var portId = -1; + var powerRole = -1; + var dataRole = -1; + CheckEmptyUtils.sleep(2000) + + usb.setPortRoles(-1, -1, -1).then(data => { + console.info('usb case setPortRoles 14 return: ' + data); + expect(data).assertTrue(); + }).catch(error => { + console.info('usb case setPortRoles 14 error : ' + error); + expect(error).assertFalse(); + console.info('set_port_roles_test_14: PASS'); + }) + + console.info('set_port_roles_test_14: PASS'); + expect(true).assertTrue(); + }) + + /** + * @tc.number : set_port_roles_test_15 + * @tc.name : setPortRoles + * @tc.desc : Device模式下,portId参数错误 + */ + it('SUB_USB_set_port_roles_test_15', 0, function () { + var portId = -1; + var powerRole = 2; + var dataRole = 2; + CheckEmptyUtils.sleep(2000) + usb.setPortRoles(-1, 2, 2).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('set_port_roles_test_15: PASS'); + }) + + console.info('set_port_roles_test_15: PASS'); + expect(true).assertTrue(); + }) + + /** + * @tc.number : set_port_roles_test_16 + * @tc.name : setPortRoles + * @tc.desc : Device模式下,powerRole参数错误 + */ + it('SUB_USB_set_port_roles_test_16', 0, function () { + var portId = 2; + var powerRole = -1; + var dataRole = 2; + CheckEmptyUtils.sleep(2000) + usb.setPortRoles(2, -1, 2).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('set_port_roles_test_16: PASS'); + }) + + console.info('set_port_roles_test_16: 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 new file mode 100755 index 000000000..9cc0314b6 --- /dev/null +++ b/usb/usb_standard/src/main/resources/base/element/string.json @@ -0,0 +1,12 @@ +{ + "string": [ + { + "name": "app_name", + "value": "UsbJSApiTest" + }, + { + "name": "mainability_description", + "value": "JS_Phone_Empty Feature Ability" + } + ] +} \ 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 new file mode 100755 index 0000000000000000000000000000000000000000..ce307a8827bd75456441ceb57d530e4c8d45d36c GIT binary patch literal 6790 zcmX|G1ymHk)?T_}Vd;>R?p|tHQo6fg38|$UVM!6BLrPFWk?s;$LOP{GmJpBl$qoSA!PUg~PA65-S00{{S`XKG6NkG0RgjEntPrmV+?0|00mu7;+5 zrdpa{2QLqPJ4Y{j7=Mrl{BaxrkdY69+c~(w{Fv-v&aR%aEI&JYSeRTLWm!zbv;?)_ ziZB;fwGbbeL5Q}YLx`J$lp~A09KK8t_z}PZ=4ZzgdeKtgoc+o5EvN9A1K1_<>M?MBqb#!ASf&# zEX?<)!RH(7>1P+j=jqG(58}TVN-$psA6K}atCuI!KTJD&FMmH-78ZejBm)0qc{ESp z|LuG1{QnBUJRg_E=h1#XMWt2%fcoN@l7eAS!Es?Q+;XsRNPhiiE=@AqlLkJzF`O18 zbsbSmKN=aaq8k3NFYZfDWpKmM!coBU0(XnL8R{4=i|wi{!uWYM2je{U{B*K2PVdu&=E zTq*-XsEsJ$u5H4g6DIm2Y!DN`>^v|AqlwuCD;w45K0@eqauiqWf7l&o)+YLHm~|L~ z7$0v5mkobriU!H<@mVJHLlmQqzQ3d6Rh_-|%Yy2li*tHO>_vcnuZ7OR_xkAIuIU&x z-|8Y0wj|6|a6_I(v91y%k_kNw6pnkNdxjqG8!%Vz_d%c_!X+6-;1`GC9_FpjoHev5fEV7RhJ>r=mh-jp$fqbqRJ=obwdgLDVP5+s zy1=_DWG0Y-Jb3t^WXmkr(d9~08k-|#Ly zaNOmT(^9tIb&eb4%CzIT zAm3CUtWSr1t4?h1kk#NBi{U|pJslvME{q|_eS^3En>SOqSxyuN1x;Is@8~m?*>}** znrRFArP!K_52RpX*&JHMR<^lVdm8ypJ}0R(SD(51j;6@ni$6bQ+2XL+R^|NnSp5}(kzvMZ^(@4fD_{QVu$(&K6H|C37TG1Am9Re{<<3gd zh@`>;BqkXMW&p0T6rt|iB$)~CvFe(XC)F9WgAZn*0@t$oZo;!*}r@_`h?KKH&6A@3= zISXoQB+~`op>NP-buiA*^0n{@i{_?MRG)&k)c)k_F+-2Lud!S9pc+i`s74NpBCaGF zXN+pHkubw*msGBTY27BKHv)RRh3;nMg4&$fD_6X9Vt~;_4D+5XPH~#Kn-yjcy!$}1 zigv#FNY>TqMhtIBb@UoF!cE~Q8~;!Pek>SQQwHnHuWKoVBosAiOr}q>!>aE*Krc)V zBUMEcJ5NU0g8}-h6i1zpMY9>m4ne?=U2~`w7K7Q0gB_=p@$5K7p6}thw z-~3dMj?YNX2X$lZ+7ngQ$=s}3mizNN@kE%OtB)?c&i~2L55z8^=yz;xMHLmlY>&Q# zJj?!)M#q_SyfkQh)k?j8IfLtB)ZCp|*vf4_B zos?73yd^h-Ac+;?E4*bpf=o*^3x3-`TVjbY4n6!EN10K6o@fxdyps05Vo3PU)otB} z`3kR+2w7_C#8Z!q`J)p{Vh!+m9-UP!$STp+Hb}}#@#_u^SsUQg<}59< zTvH3%XS4G+6FF^(m6bVF&nSUIXcl;nw{=H$%fgeJ>CgDYiLdpDXr{;-AnG z8dvcrHYVMI&`R6;GWekI@Ir3!uo)oz4^{6q0m^}@f2tM9&=YHNi6-?rh0-{+k@cQm zdp`g#YdQn%MDVg2GR>wZ`n2<0l4)9nx1Wfr&!Dvz=bPwU!h2S?ez6MVc5APE4-xLB zi&W9Q8k2@0w!C53g?iAIQ}~p*3O(@zja6KQ=M3zfW*_6o5SwR-)6VBh~m7{^-=MC-owYH5-u40a}a0liho3QZZ5L{bS_xM1)4}19)zTU$$MY zq3eZML1WC{K%YFd`Be0M-rkO^l?h{kM{$2oK1*A@HVJ57*yhDkUF!2WZ&oA4Y-sK( zCY69%#`mBCi6>6uw(x4gbFaP0+FD*JKJ-q!F1E?vLJ+d35!I5d7@^eU?(CS|C^tmI5?lv@s{{*|1F zFg|OzNpZ0hxljdjaW%45O0MOttRrd(Z?h{HYbB-KFUx&9GfFL3b8NwZ$zNu)WbBD` zYkj$^UB5%3Pj1MDr>S2Ejr9pUcgA!;ZG!@{uAy12)vG=*^9-|dNQBc8&`oxBlU~#y zs!anJX&T?57Jdr^sb>e+V`MVfY>Y0ESg7MG<7W0g&bR-ZYzzZ%2H&Etcp zcd6QeXO1D!5A#zM0lx*GH}`M)2~ZFLE;sP^RSB5wVMNfiZXPd(cmO>j=OSA3`o5r& zna(|^jGXbdN7PK)U8b7^zYtYkkeb%<%F~=OqB~kXMQkq}ii|skh@WSRt>5za;cjP0 zZ~nD%6)wzedqE}BMLt~qKwlvTr33))#uP~xyw#*Eaa|DbMQ_%mG0U8numf8)0DX`r zRoG2bM;#g|p-8gWnwRV5SCW0tLjLO&9Z?K>FImeIxlGUgo0Zk`9Qzhj1eco~7XZy+hXc@YF&ZQ=? zn*^1O56yK^x{y}q`j7}blGCx%dydV!c7)g~tJzmHhV=W~jbWRRR{1<^oDK+1clprm zz$eCy7y9+?{E|YgkW~}}iB#I4XoJ*xr8R?i_Hv$=Cof5bo-Nj~f`-DLebH}&0% zfQj9@WGd4;N~Y?mzQsHJTJq6!Qzl^-vwol(+fMt#Pl=Wh#lI5Vmu@QM0=_r+1wHt` z+8WZ~c2}KQQ+q)~2Ki77QvV&`xb|xVcTms99&cD$Zz4+-^R4kvUBxG8gDk7Y`K*)JZ^2rL(+ZWV~%W(@6 z)0bPArG#BROa_PHs~&WplQ_UIrpd)1N1QGPfv!J(Z9jNT#i%H?CE6|pPZb9hJ1JW4 z^q;ft#!HRNV0YgPojzIYT`8LuET2rUe-J|c!9l4`^*;4WtY@Ew@pL>wkjmMgGfN7 ze}}GtmU0@<_#08~I-Suk=^*9GLW=H4xhsml;vAV{%hy5Eegl@!6qKqbG024%n2HHw zCc@ivW_$@5ZoHP70(7D+(`PvgjW1Pd`wsiuv-aCukMrafwDm)B!xXVy*j2opohhoU zcJz%ADmj>i3`-3-$7nQKBQQuGY;2Qt&+(L~C>vSGFj5{Mlv?T_^dql;{zkpe4R1}R z%XfZyQ}wr*sr>jrKgm*PWLjuVc%6&&`Kbf1SuFpHPN&>W)$GmqC;pIoBC`=4-hPY8 zT*>%I2fP}vGW;R=^!1be?ta2UQd2>alOFFbVl;(SQJ4Jk#)4Z0^wpWEVvY4=vyDk@ zqlModi@iVPMC+{?rm=4(n+<;|lmUO@UKYA>EPTS~AndtK^Wy^%#3<;(dQdk3WaUkRtzSMC9}7x2||CNpF#(3T4C)@ z$~RWs`BNABKX|{cmBt>Q=&gkXl&x!!NK_%5hW0LS)Z4PB>%sV?F-{Wyj#s7W%$F{D zXdK^Fp3wvy+48+GP6F_|^PCRx=ddcTO3sG;B23A49~Qaw31SZ0Rc~`r4qqt%#OGW{ zCA_(LG5^N>yzUn&kAgVmxb=EA8s&tBXC}S1CZ(KoW)(%^JjLTPo^fs`Va;`=YlVPgmB$!yB}<(4ym6OeZ3xAJJ#;)2+B%p3P1Wt+d$eo`vz`T zXfUP2))kBDPoscH;Jc7I3NU<({|@wM$&GaDt`n7WLgIY3IA7A6-_R?z8N3mz|}*i z(zl5ot--Oq@f2-nv{X(ujT2T(k1vY_qh93pK@>H-qc%2Xta)IP0Q%zt%bqYgI`o!wv!0QerB`nCN^1n|@$sVOQ!V0teVG!I z_fD%JvfDeT1cK#-{o6Gv7}& zY0#NWin~kVaf$aufV&;63Hbs|`QVZWpDX6IMk1Hj2G}fiH9e-^6u2zf^FIr^BwD<6zjw63+{yUe8PUFvk8v{sJ=R{d#`O!sz`Q13~< zPT$JS(w=yQfU2`zPCNfSw=&zup@DXc(98afjhv@1w_f!m2Z>rMJ19AB&dB%P#Ls3b z=lK7OILM+SQ&VEd=1GN6o&>YVVtIzoZ%=Z_SdqJN2}E43{bE`>w+A;=y->@^k{oCC z$F*WTY&?34;kfyFV?b*Xb1Pq`Z=%OgwEg)Rz)tx=`f%5#w_INP=x&z5!jI;#;N$ma zhO)+MDm;SxOEVL15; zGq(v2pL3&P1Sl)8P*;G-fd{l1QJsv@e@d8)1PK4w2m*M%V3j-V~L^$i|&C@b?D?9tfwE{B^}Z$k8e5FmQ>v7Xz)sG32g9t}YBt zyR$+*_00RmPx+0mW+vVG4mxd(n$(eQf3-w>JPl2UJpafrPaL5@2j}%{VE-) zBI%6Qpj*dsdH<;g!S!avA~bv^0E+ zfyJbSjPb+j;J52U)<|cIcntQBI2T#>2;tOxu{%D?kML476AErF(qN9hPva5Nkc@BF zC-tLF@3ZFb%Kpj)M<{)x*l|*Ia@ECeXo2E4h2f!aV=cHAhi_E_mfUth(sM4^hJq7B zQsGWqdZUm9S%F`$nQ*_#NcuD`&)Ek%_s{&^78{9Hm ztri&rYLOxgFdG>O@+XHy z9#;|&vBCPXH5Mon^I`jSuR$&~ZWtyB67ujzFSj!51>#C}C17~TffQ{c-!QFQkTQ%! zIR^b1`zHx|*1GU?tbBx23weFLz5H?y_Q%N&t$}k?w+``2A=aotj0;2v$~AL z{scF-cL{wsdrmPvf#a9OHyYLcwQD4Kcm)`LLwMh4WT~p29f7M!iafJSU`IV}QY5Wa z(n44-9oA}?J{a+ah*@31WTs#&J#o1`H98#6IQf;Wv0N_!);f&9g7o-k(lW5rWnDUR zQBFIRG+X=6NnsI@mxnwm;tf5;_Uxg?jZ8m-m0}&6+DA!qam(p$mN5R})yA_7m$q@| zFEd|dpS595rxQr-n#GjI5i-AhnUE>Cr;jpCqSrD~EwK_DqI^7%3#p5)%T_od!t3SOmH9MyXeeGO2(UQL;ax|x?Ncixmeo1=$ z{-);Au{*tfzOG?KQ~K|ak8-HQ?`Pekhe2WM(8s{xv-p>Zmu_6{G!-oE$7$mY`MOJorI=+mMx?H;`pr!;fVYz?5~yXBACruWB`Ph zZM}90_<^OBxIhyZ9BW$`>6JvO;%VFpqVr8|7t3~AmxYak6?`Pp#c;**_SYmi`&z23 z`p6_~ePvH)C6x-G9$hgL=eVALq`-AiamN>!3~Lxw&{H(b{B(7xSRm6<3<{%{yXiH# zos5Rv1L+8fUKJLo%P>4I&$}y