Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
OpenHarmony
Xts Acts
提交
1df14524
X
Xts Acts
项目概览
OpenHarmony
/
Xts Acts
大约 1 年 前同步成功
通知
9
Star
22
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
X
Xts Acts
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
未验证
提交
1df14524
编写于
4月 17, 2023
作者:
O
openharmony_ci
提交者:
Gitee
4月 17, 2023
浏览文件
操作
浏览文件
下载
差异文件
!8419 【xts_acts】【master】修改用例中引用的d.ts文件
Merge pull request !8419 from 李晓枫/usbSdk_0411
上级
40bc55fb
f6034516
变更
9
展开全部
隐藏空白更改
内联
并排
Showing
9 changed file
with
424 addition
and
413 deletion
+424
-413
usb/usb_standard/src/main/js/test/UsbCoreJsunit.test.js
usb/usb_standard/src/main/js/test/UsbCoreJsunit.test.js
+37
-37
usb/usb_standard/src/main/js/test/UsbCoreJsunitEx.test.js
usb/usb_standard/src/main/js/test/UsbCoreJsunitEx.test.js
+70
-70
usb/usb_standard/src/main/js/test/UsbDevicePipeJsunit.test.js
...usb_standard/src/main/js/test/UsbDevicePipeJsunit.test.js
+61
-50
usb/usb_standard/src/main/js/test/UsbDevicePipeJsunitEx.test.js
...b_standard/src/main/js/test/UsbDevicePipeJsunitEx.test.js
+78
-78
usb/usb_standard/src/main/js/test/UsbFunctionsJsunit.test.js
usb/usb_standard/src/main/js/test/UsbFunctionsJsunit.test.js
+14
-14
usb/usb_standard/src/main/js/test/UsbFunctionsJsunitEx.test.js
...sb_standard/src/main/js/test/UsbFunctionsJsunitEx.test.js
+70
-70
usb/usb_standard/src/main/js/test/UsbPortAndFunctionJsunit.test.js
...tandard/src/main/js/test/UsbPortAndFunctionJsunit.test.js
+51
-51
usb/usb_standard/src/main/js/test/UsbPortJsunit.test.js
usb/usb_standard/src/main/js/test/UsbPortJsunit.test.js
+6
-6
usb/usb_standard/src/main/js/test/UsbPortJsunitEx.test.js
usb/usb_standard/src/main/js/test/UsbPortJsunitEx.test.js
+37
-37
未找到文件。
usb/usb_standard/src/main/js/test/UsbCoreJsunit.test.js
浏览文件 @
1df14524
...
...
@@ -13,7 +13,7 @@
* limitations under the License.
*/
import
usb
from
'
@ohos.usb
'
;
import
usb
Manager
from
'
@ohos.usbManager
'
;
import
CheckEmptyUtils
from
'
./CheckEmptyUtils.js
'
;
import
{
describe
,
beforeAll
,
beforeEach
,
afterEach
,
afterAll
,
it
,
expect
}
from
'
@ohos/hypium
'
...
...
@@ -28,20 +28,20 @@ describe('UsbCoreJsFunctionsTest', function () {
beforeAll
(
function
()
{
console
.
log
(
'
*************Usb Unit UsbCoreJsFunctionsTest Begin*************
'
);
var
Version
=
usb
.
getVersion
()
var
Version
=
usb
Manager
.
getVersion
()
console
.
info
(
'
begin test getversion :
'
+
Version
)
// version > 17 host currentMode = 2 device currentMode = 1
var
usbPortList
=
usb
.
getPorts
()
var
usbPortList
=
usb
Manager
.
getPorts
()
if
(
usbPortList
==
undefined
)
{
portCurrentMode
=
1
;
return
}
gDeviceList
=
usb
.
getDevices
();
gDeviceList
=
usb
Manager
.
getDevices
();
if
(
usbPortList
.
length
>
0
)
{
console
.
info
(
'
usb case gDeviceList.length return:
'
+
gDeviceList
.
length
);
if
(
gDeviceList
.
length
>
0
)
{
if
(
usbPortList
[
0
].
status
.
currentMode
==
1
)
{
usb
.
setPortRoles
(
usbPortList
[
0
].
id
,
usb
.
SOURCE
,
usb
.
HOST
).
then
(
data
=>
{
usb
Manager
.
setPortRoles
(
usbPortList
[
0
].
id
,
usbManager
.
SOURCE
,
usbManager
.
HOST
).
then
(
data
=>
{
portCurrentMode
=
2
console
.
info
(
'
usb case setPortRoles return:
'
+
data
);
}).
catch
(
error
=>
{
...
...
@@ -79,7 +79,7 @@ describe('UsbCoreJsFunctionsTest', function () {
expect
(
false
).
assertFalse
();
return
}
gDeviceList
=
usb
.
getDevices
();
gDeviceList
=
usb
Manager
.
getDevices
();
if
(
gDeviceList
.
length
==
0
)
{
console
.
info
(
'
usb case get_devices list is null
'
)
expect
(
false
).
assertTrue
();
...
...
@@ -109,7 +109,7 @@ describe('UsbCoreJsFunctionsTest', function () {
}
for
(
var
i
=
0
;
i
<
gDeviceList
.
length
;
i
++
)
{
var
hasRight
=
usb
.
hasRight
(
gDeviceList
[
i
].
name
)
var
hasRight
=
usb
Manager
.
hasRight
(
gDeviceList
[
i
].
name
)
console
.
info
(
'
usb has_right ret :
'
+
hasRight
);
}
...
...
@@ -136,7 +136,7 @@ describe('UsbCoreJsFunctionsTest', function () {
}
for
(
var
i
=
0
;
i
<
gDeviceList
.
length
;
i
++
)
{
usb
.
requestRight
(
gDeviceList
[
i
].
name
).
then
(
hasRight
=>
{
usb
Manager
.
requestRight
(
gDeviceList
[
i
].
name
).
then
(
hasRight
=>
{
console
.
info
(
'
usb request_right ret :
'
+
hasRight
);
expect
(
hasRight
).
assertTrue
();
console
.
info
(
'
usb SUB_USB_JS_0680 : PASS
'
);
...
...
@@ -165,16 +165,16 @@ describe('UsbCoreJsFunctionsTest', function () {
expect
(
false
).
assertTrue
();
return
}
var
isRight
=
usb
.
hasRight
(
gDeviceList
[
0
].
name
);
var
isRight
=
usb
Manager
.
hasRight
(
gDeviceList
[
0
].
name
);
if
(
!
isRight
)
{
usb
.
requestRight
(
gDeviceList
[
0
].
name
).
then
(
hasRight
=>
{
usb
Manager
.
requestRight
(
gDeviceList
[
0
].
name
).
then
(
hasRight
=>
{
console
.
info
(
'
usb 1080 requestRight hasRight:
'
+
hasRight
);
}).
catch
(
error
=>
{
console
.
info
(
'
usb 1080 requestRight error:
'
+
error
);
});
CheckEmptyUtils
.
sleep
(
5000
);
}
var
remRight
=
usb
.
removeRight
(
gDeviceList
[
0
].
name
);
var
remRight
=
usb
Manager
.
removeRight
(
gDeviceList
[
0
].
name
);
console
.
info
(
'
usb remove_right ret :
'
+
remRight
);
expect
(
remRight
).
assertTrue
();
console
.
info
(
'
usb SUB_USB_JS_1080 : PASS
'
);
...
...
@@ -197,9 +197,9 @@ describe('UsbCoreJsFunctionsTest', function () {
expect
(
false
).
assertTrue
();
return
}
var
isRight
=
usb
.
hasRight
(
gDeviceList
[
0
].
name
);
var
isRight
=
usb
Manager
.
hasRight
(
gDeviceList
[
0
].
name
);
if
(
!
isRight
)
{
usb
.
requestRight
(
gDeviceList
[
0
].
name
).
then
(
hasRight
=>
{
usb
Manager
.
requestRight
(
gDeviceList
[
0
].
name
).
then
(
hasRight
=>
{
console
.
info
(
'
usb 0090 requestRight hasRight:
'
+
hasRight
);
}).
catch
(
error
=>
{
console
.
info
(
'
usb 0090 requestRight error:
'
+
error
);
...
...
@@ -207,7 +207,7 @@ describe('UsbCoreJsFunctionsTest', function () {
CheckEmptyUtils
.
sleep
(
5000
)
}
gPipe
=
usb
.
connectDevice
(
gDeviceList
[
0
])
gPipe
=
usb
Manager
.
connectDevice
(
gDeviceList
[
0
])
console
.
info
(
'
usb case connectDevice ret:
'
+
JSON
.
stringify
(
gPipe
));
expect
(
CheckEmptyUtils
.
isEmpty
(
gPipe
)).
assertFalse
();
...
...
@@ -234,7 +234,7 @@ describe('UsbCoreJsFunctionsTest', function () {
var
tmpPipe
=
JSON
.
parse
(
JSON
.
stringify
(
gPipe
));
tmpPipe
.
busNum
=
-
23
var
isPipClose
=
usb
.
closePipe
(
tmpPipe
);
var
isPipClose
=
usb
Manager
.
closePipe
(
tmpPipe
);
console
.
info
(
'
usb case closePipe ret:
'
+
isPipClose
);
expect
(
isPipClose
==
0
).
assertFalse
();
...
...
@@ -260,7 +260,7 @@ describe('UsbCoreJsFunctionsTest', function () {
}
var
tmpPipe
=
JSON
.
parse
(
JSON
.
stringify
(
gPipe
));
tmpPipe
.
devAddress
=
-
23
var
isPipClose
=
usb
.
closePipe
(
tmpPipe
);
var
isPipClose
=
usb
Manager
.
closePipe
(
tmpPipe
);
console
.
info
(
'
usb case closePipe ret:
'
+
isPipClose
);
expect
(
isPipClose
==
0
).
assertFalse
();
...
...
@@ -287,7 +287,7 @@ describe('UsbCoreJsFunctionsTest', function () {
var
tmpPipe
=
JSON
.
parse
(
JSON
.
stringify
(
gPipe
));
tmpPipe
.
devAddress
=
-
23
tmpPipe
.
busNum
=
-
23
var
isPipClose
=
usb
.
closePipe
(
tmpPipe
);
var
isPipClose
=
usb
Manager
.
closePipe
(
tmpPipe
);
console
.
info
(
'
usb case closePipe ret:
'
+
isPipClose
);
expect
(
isPipClose
==
0
).
assertFalse
();
...
...
@@ -313,7 +313,7 @@ describe('UsbCoreJsFunctionsTest', function () {
}
console
.
info
(
'
usb case closePipe param:
'
+
JSON
.
stringify
(
gPipe
));
var
isPipClose
=
usb
.
closePipe
(
gPipe
);
var
isPipClose
=
usb
Manager
.
closePipe
(
gPipe
);
console
.
info
(
'
usb case closePipe ret:
'
+
isPipClose
);
expect
(
isPipClose
).
assertEqual
(
0
);
...
...
@@ -338,12 +338,12 @@ describe('UsbCoreJsFunctionsTest', function () {
return
}
gPipe
=
usb
.
connectDevice
(
gDeviceList
[
0
])
gPipe
=
usb
Manager
.
connectDevice
(
gDeviceList
[
0
])
console
.
info
(
'
usb case getRawDescriptor param:
'
+
JSON
.
stringify
(
gPipe
));
var
descriptor
=
usb
.
getRawDescriptor
(
gPipe
);
var
descriptor
=
usb
Manager
.
getRawDescriptor
(
gPipe
);
console
.
info
(
'
usb case getRawDescriptor ret:
'
+
descriptor
);
expect
(
descriptor
.
length
).
assertLarger
(
0
);
var
isPipClose
=
usb
.
closePipe
(
gPipe
);
var
isPipClose
=
usb
Manager
.
closePipe
(
gPipe
);
expect
(
isPipClose
).
assertEqual
(
0
);
console
.
info
(
'
usb SUB_USB_JS_0530 : PASS
'
);
...
...
@@ -366,12 +366,12 @@ describe('UsbCoreJsFunctionsTest', function () {
expect
(
false
).
assertTrue
();
return
}
gPipe
=
usb
.
connectDevice
(
gDeviceList
[
0
])
gPipe
=
usb
Manager
.
connectDevice
(
gDeviceList
[
0
])
console
.
info
(
'
usb case getFileDescriptor param:
'
+
JSON
.
stringify
(
gPipe
));
var
fileDescriptor
=
usb
.
getFileDescriptor
(
gPipe
);
var
fileDescriptor
=
usb
Manager
.
getFileDescriptor
(
gPipe
);
console
.
info
(
'
usb case getFileDescriptor ret:
'
+
fileDescriptor
);
expect
(
fileDescriptor
>=
0
).
assertTrue
();
var
isPipClose
=
usb
.
closePipe
(
gPipe
);
var
isPipClose
=
usb
Manager
.
closePipe
(
gPipe
);
expect
(
isPipClose
).
assertEqual
(
0
);
console
.
info
(
'
usb SUB_USB_JS_0490 : PASS
'
);
...
...
@@ -394,13 +394,13 @@ describe('UsbCoreJsFunctionsTest', function () {
expect
(
false
).
assertTrue
();
return
}
gPipe
=
usb
.
connectDevice
(
gDeviceList
[
0
])
gPipe
=
usb
Manager
.
connectDevice
(
gDeviceList
[
0
])
var
tempPipe
=
{
busNum
:
255
,
devAddress
:
255
}
console
.
info
(
'
usb case getFileDescriptor param:
'
+
JSON
.
stringify
(
gPipe
));
var
fileDescriptor
=
usb
.
getFileDescriptor
(
tempPipe
);
var
fileDescriptor
=
usb
Manager
.
getFileDescriptor
(
tempPipe
);
expect
(
fileDescriptor
<
0
).
assertTrue
();
console
.
info
(
'
usb case getFileDescriptor ret:
'
+
fileDescriptor
);
var
isPipClose
=
usb
.
closePipe
(
gPipe
);
var
isPipClose
=
usb
Manager
.
closePipe
(
gPipe
);
expect
(
isPipClose
).
assertEqual
(
0
);
console
.
info
(
'
usb SUB_USB_JS_0500 : PASS
'
);
})
...
...
@@ -422,13 +422,13 @@ describe('UsbCoreJsFunctionsTest', function () {
expect
(
false
).
assertTrue
();
return
}
gPipe
=
usb
.
connectDevice
(
gDeviceList
[
0
])
gPipe
=
usb
Manager
.
connectDevice
(
gDeviceList
[
0
])
var
tempPipe
=
{
busNum
:
255
,
devAddress
:
gPipe
.
devAddress
}
console
.
info
(
'
usb case getFileDescriptor param:
'
+
JSON
.
stringify
(
gPipe
));
var
fileDescriptor
=
usb
.
getFileDescriptor
(
tempPipe
);
var
fileDescriptor
=
usb
Manager
.
getFileDescriptor
(
tempPipe
);
expect
(
fileDescriptor
<
0
).
assertTrue
();
console
.
info
(
'
usb case getFileDescriptor ret:
'
+
fileDescriptor
);
var
isPipClose
=
usb
.
closePipe
(
gPipe
);
var
isPipClose
=
usb
Manager
.
closePipe
(
gPipe
);
expect
(
isPipClose
).
assertEqual
(
0
);
console
.
info
(
'
usb SUB_USB_JS_0510 : PASS
'
);
})
...
...
@@ -450,13 +450,13 @@ describe('UsbCoreJsFunctionsTest', function () {
expect
(
false
).
assertTrue
();
return
}
gPipe
=
usb
.
connectDevice
(
gDeviceList
[
0
])
gPipe
=
usb
Manager
.
connectDevice
(
gDeviceList
[
0
])
var
tempPipe
=
{
busNum
:
gPipe
.
busNum
,
devAddress
:
255
}
console
.
info
(
'
usb case getFileDescriptor param:
'
+
JSON
.
stringify
(
gPipe
));
var
fileDescriptor
=
usb
.
getFileDescriptor
(
tempPipe
);
var
fileDescriptor
=
usb
Manager
.
getFileDescriptor
(
tempPipe
);
expect
(
fileDescriptor
<
0
).
assertTrue
();
console
.
info
(
'
usb case getFileDescriptor ret:
'
+
fileDescriptor
);
var
isPipClose
=
usb
.
closePipe
(
gPipe
);
var
isPipClose
=
usb
Manager
.
closePipe
(
gPipe
);
expect
(
isPipClose
).
assertEqual
(
0
);
console
.
info
(
'
usb SUB_USB_JS_0520 : PASS
'
);
})
...
...
@@ -478,9 +478,9 @@ describe('UsbCoreJsFunctionsTest', function () {
expect
(
false
).
assertTrue
();
return
}
gPipe
=
usb
.
connectDevice
(
gDeviceList
[
0
])
gPipe
=
usb
Manager
.
connectDevice
(
gDeviceList
[
0
])
try
{
var
maskCode
=
usb
.
getFileDescriptor
(
"
invalid
"
);
var
maskCode
=
usb
Manager
.
getFileDescriptor
(
"
invalid
"
);
console
.
info
(
'
usb 1070 case getFileDescriptor return:
'
+
maskCode
);
expect
(
false
).
assertTrue
();
}
catch
(
err
)
{
...
...
@@ -507,9 +507,9 @@ describe('UsbCoreJsFunctionsTest', function () {
expect
(
false
).
assertTrue
();
return
}
gPipe
=
usb
.
connectDevice
(
gDeviceList
[
0
])
gPipe
=
usb
Manager
.
connectDevice
(
gDeviceList
[
0
])
try
{
var
maskCode
=
usb
.
getFileDescriptor
();
var
maskCode
=
usb
Manager
.
getFileDescriptor
();
console
.
info
(
'
usb 1230 case getFileDescriptor return:
'
+
maskCode
);
expect
(
false
).
assertTrue
();
}
catch
(
err
)
{
...
...
usb/usb_standard/src/main/js/test/UsbCoreJsunitEx.test.js
浏览文件 @
1df14524
此差异已折叠。
点击以展开。
usb/usb_standard/src/main/js/test/UsbDevicePipeJsunit.test.js
浏览文件 @
1df14524
...
...
@@ -13,7 +13,7 @@
* limitations under the License.
*/
import
usb
from
'
@ohos.usb
'
;
import
usb
Manager
from
'
@ohos.usbManager
'
;
import
CheckEmptyUtils
from
'
./CheckEmptyUtils.js
'
;
import
EventConstants
from
'
./EventConstants.js
'
;
import
parameter
from
'
@ohos.systemparameter
'
;
...
...
@@ -29,19 +29,19 @@ describe('UsbDevicePipeJsFunctionsTest', function () {
beforeAll
(
function
()
{
console
.
log
(
'
*************Usb Unit UsbDevicePipeJsFunctionsTest Begin*************
'
);
var
Version
=
usb
.
getVersion
()
var
Version
=
usb
Manager
.
getVersion
()
console
.
info
(
'
usb unit begin test getversion :
'
+
Version
)
// version > 17 host currentMode = 2 device currentMode = 1
var
usbPortList
=
usb
.
getPorts
()
var
usbPortList
=
usb
Manager
.
getPorts
()
if
(
usbPortList
==
undefined
)
{
portCurrentMode
=
1
;
return
}
gDeviceList
=
usb
.
getDevices
();
gDeviceList
=
usb
Manager
.
getDevices
();
if
(
usbPortList
.
length
>
0
)
{
if
(
gDeviceList
.
length
>
0
)
{
if
(
usbPortList
[
0
].
status
.
currentMode
==
1
)
{
usb
.
setPortRoles
(
usbPortList
[
0
].
id
,
usb
.
SOURCE
,
usb
.
HOST
).
then
(
data
=>
{
usb
Manager
.
setPortRoles
(
usbPortList
[
0
].
id
,
usbManager
.
SOURCE
,
usbManager
.
HOST
).
then
(
data
=>
{
portCurrentMode
=
2
console
.
info
(
'
usb case setPortRoles return:
'
+
data
);
}).
catch
(
error
=>
{
...
...
@@ -55,11 +55,11 @@ describe('UsbDevicePipeJsFunctionsTest', function () {
}
}
gDeviceList
=
usb
.
getDevices
();
gDeviceList
=
usb
Manager
.
getDevices
();
gDeviceList
[
0
].
name
;
gDeviceList
[
0
].
version
;
gDeviceList
[
0
].
configs
;
gPipe
=
usb
.
connectDevice
(
gDeviceList
[
0
])
gPipe
=
usb
Manager
.
connectDevice
(
gDeviceList
[
0
])
console
.
info
(
'
usb unit connectDevice gPipe ret :
'
+
JSON
.
stringify
(
gPipe
));
})
...
...
@@ -71,7 +71,7 @@ describe('UsbDevicePipeJsFunctionsTest', function () {
})
afterAll
(
function
()
{
var
isPipClose
=
usb
.
closePipe
(
gPipe
)
var
isPipClose
=
usb
Manager
.
closePipe
(
gPipe
)
console
.
info
(
'
usb unit close gPipe ret :
'
+
isPipClose
);
console
.
log
(
'
*************Usb Unit UsbDevicePipeJsFunctionsTest End*************
'
);
})
...
...
@@ -85,10 +85,10 @@ describe('UsbDevicePipeJsFunctionsTest', function () {
endpoint
.
interfaceid
=
1
;
if
(
endpoint
.
type
==
EventConstants
.
USB_ENDPOINT_XFER_BULK
)
{
bfind
=
true
if
(
endpoint
.
direction
==
usb
.
USB_REQUEST_DIR_TO_DEVICE
)
{
if
(
endpoint
.
direction
==
usb
Manager
.
USB_REQUEST_DIR_TO_DEVICE
)
{
testParam
.
maxOutSize
=
endpoint
.
maxPacketSize
;
testParam
.
outEndpoint
=
endpoint
;
}
else
if
(
endpoint
.
direction
==
usb
.
USB_REQUEST_DIR_FROM_DEVICE
)
{
}
else
if
(
endpoint
.
direction
==
usb
Manager
.
USB_REQUEST_DIR_FROM_DEVICE
)
{
testParam
.
maxInSize
=
endpoint
.
maxPacketSize
;
testParam
.
inEndpoint
=
endpoint
}
...
...
@@ -169,12 +169,12 @@ describe('UsbDevicePipeJsFunctionsTest', function () {
return
}
testParam
.
isClaimed
=
usb
.
claimInterface
(
testParam
.
pip
,
testParam
.
interface
,
true
);
testParam
.
isClaimed
=
usb
Manager
.
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
=>
{
usb
Manager
.
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
);
expect
(
data
>=
0
).
assertTrue
();
...
...
@@ -204,7 +204,7 @@ describe('UsbDevicePipeJsFunctionsTest', function () {
return
}
testParam
.
isClaimed
=
usb
.
claimInterface
(
testParam
.
pip
,
testParam
.
interface
,
true
);
testParam
.
isClaimed
=
usb
Manager
.
claimInterface
(
testParam
.
pip
,
testParam
.
interface
,
true
);
expect
(
testParam
.
isClaimed
).
assertEqual
(
0
);
testParam
.
sendData
=
'
send default
'
;
...
...
@@ -216,7 +216,7 @@ describe('UsbDevicePipeJsFunctionsTest', function () {
}
var
tmpUint8Array
=
CheckEmptyUtils
.
str2ab
(
testParam
.
sendData
);
usb
.
bulkTransfer
(
testParam
.
pip
,
testParam
.
outEndpoint
,
tmpUint8Array
,
5000
).
then
(
data
=>
{
usb
Manager
.
bulkTransfer
(
testParam
.
pip
,
testParam
.
outEndpoint
,
tmpUint8Array
,
5000
).
then
(
data
=>
{
console
.
info
(
'
usb case SUB_USB_JS_0640 ret:
'
+
data
);
console
.
info
(
'
usb case SUB_USB_JS_0640 send data:
'
+
testParam
.
sendData
);
expect
(
data
>
0
).
assertTrue
();
...
...
@@ -262,14 +262,14 @@ describe('UsbDevicePipeJsFunctionsTest', function () {
interfaces
.
id
=
1
;
interfaces
.
name
=
''
;
interfaces
.
alternateSetting
=
0
;
var
isClaim
=
usb
.
claimInterface
(
gPipe
,
gDeviceList
[
0
].
configs
[
j
].
interfaces
[
k
],
true
)
var
isClaim
=
usb
Manager
.
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
])
isClaim
=
usb
Manager
.
releaseInterface
(
gPipe
,
gDeviceList
[
0
].
configs
[
j
].
interfaces
[
k
])
console
.
info
(
'
usb case releaseInterface function return:
'
+
isClaim
);
expect
(
isClaim
).
assertEqual
(
0
);
gPipe
=
usb
.
connectDevice
(
gDeviceList
[
0
])
gPipe
=
usb
Manager
.
connectDevice
(
gDeviceList
[
0
])
}
}
}
...
...
@@ -313,7 +313,7 @@ describe('UsbDevicePipeJsFunctionsTest', function () {
return
}
gPipe
=
usb
.
connectDevice
(
gDeviceList
[
0
])
gPipe
=
usb
Manager
.
connectDevice
(
gDeviceList
[
0
])
for
(
var
j
=
0
;
j
<
gDeviceList
[
0
].
configs
.
length
;
j
++
)
{
var
configs
=
gDeviceList
[
0
].
configs
[
j
];
configs
.
id
=
1
;
...
...
@@ -321,7 +321,7 @@ describe('UsbDevicePipeJsFunctionsTest', function () {
configs
.
maxPower
=
1
;
configs
.
isRemoteWakeup
=
true
;
configs
.
isSelfPowered
=
true
;
var
ret
=
usb
.
setConfiguration
(
gPipe
,
gDeviceList
[
0
].
configs
[
j
])
var
ret
=
usb
Manager
.
setConfiguration
(
gPipe
,
gDeviceList
[
0
].
configs
[
j
])
console
.
info
(
'
usb case setConfiguration return :
'
+
ret
);
expect
(
ret
).
assertEqual
(
0
);
}
...
...
@@ -350,7 +350,7 @@ describe('UsbDevicePipeJsFunctionsTest', function () {
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
)
var
ret
=
usb
Manager
.
setConfiguration
(
gPipe
,
config
)
console
.
info
(
'
usb case setConfiguration return :
'
+
ret
);
expect
(
ret
).
assertLess
(
0
);
}
...
...
@@ -377,10 +377,10 @@ describe('UsbDevicePipeJsFunctionsTest', function () {
}
for
(
var
j
=
0
;
j
<
gDeviceList
[
0
].
configs
.
length
;
j
++
)
{
var
isClaim
=
usb
.
claimInterface
(
gPipe
,
gDeviceList
[
0
].
configs
[
j
].
interfaces
[
0
],
true
)
var
isClaim
=
usb
Manager
.
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
])
var
ret
=
usb
Manager
.
setInterface
(
gPipe
,
gDeviceList
[
0
].
configs
[
j
].
interfaces
[
0
])
console
.
info
(
'
usb case setInterface return :
'
+
ret
);
expect
(
ret
).
assertEqual
(
0
);
}
...
...
@@ -408,12 +408,12 @@ describe('UsbDevicePipeJsFunctionsTest', function () {
}
for
(
var
j
=
0
;
j
<
gDeviceList
[
0
].
configs
.
length
;
j
++
)
{
var
isClaim
=
usb
.
claimInterface
(
gPipe
,
gDeviceList
[
0
].
configs
[
j
].
interfaces
[
0
],
true
)
var
isClaim
=
usb
Manager
.
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
)
var
ret
=
usb
Manager
.
setInterface
(
gPipe
,
tmpInterface
)
console
.
info
(
'
usb case setInterface return :
'
+
ret
)
expect
(
ret
).
assertLess
(
0
)
}
...
...
@@ -423,7 +423,7 @@ describe('UsbDevicePipeJsFunctionsTest', function () {
})
function
callControlTransfer
(
pip
,
controlParam
,
timeout
,
caseName
)
{
usb
.
controlTransfer
(
pip
,
controlParam
,
timeout
).
then
(
data
=>
{
usb
Manager
.
controlTransfer
(
pip
,
controlParam
,
timeout
).
then
(
data
=>
{
console
.
info
(
'
usb controlTransfer ret data :
'
+
data
+
'
'
+
caseName
);
console
.
info
(
'
usb controlTransfer controlParam.data buffer :
'
+
controlParam
.
data
+
'
'
+
caseName
);
expect
(
data
>=
0
).
assertTrue
();
...
...
@@ -455,8 +455,9 @@ describe('UsbDevicePipeJsFunctionsTest', function () {
}
var
timeout
=
5000
;
var
controlParam
=
getTransferParam
(
6
,
usb
.
USB_REQUEST_TARGET_DEVICE
,
(
usb
.
USB_REQUEST_DIR_FROM_DEVICE
)
|
(
usb
.
USB_REQUEST_TYPE_STANDARD
<<
5
)
|
(
usb
.
USB_REQUEST_TARGET_DEVICE
&
0x1f
),
(
2
<<
8
),
0
)
var
controlParam
=
getTransferParam
(
6
,
usbManager
.
USB_REQUEST_TARGET_DEVICE
,
(
usbManager
.
USB_REQUEST_DIR_FROM_DEVICE
)
|
(
usbManager
.
USB_REQUEST_TYPE_STANDARD
<<
5
)
|
(
usbManager
.
USB_REQUEST_TARGET_DEVICE
&
0x1f
),
(
2
<<
8
),
0
);
callControlTransfer
(
testParam
.
pip
,
controlParam
,
timeout
,
'
SUB_USB_JS_0540 GetDescriptor
'
)
})
...
...
@@ -479,8 +480,9 @@ describe('UsbDevicePipeJsFunctionsTest', function () {
}
var
timeout
=
5000
;
var
controlParam
=
getTransferParam
(
0
,
usb
.
USB_REQUEST_TARGET_DEVICE
,
(
usb
.
USB_REQUEST_DIR_FROM_DEVICE
)
|
(
usb
.
USB_REQUEST_TYPE_STANDARD
<<
5
)
|
(
usb
.
USB_REQUEST_TARGET_DEVICE
&
0x1f
),
0
,
0
)
var
controlParam
=
getTransferParam
(
0
,
usbManager
.
USB_REQUEST_TARGET_DEVICE
,
(
usbManager
.
USB_REQUEST_DIR_FROM_DEVICE
)
|
(
usbManager
.
USB_REQUEST_TYPE_STANDARD
<<
5
)
|
(
usbManager
.
USB_REQUEST_TARGET_DEVICE
&
0x1f
),
0
,
0
);
callControlTransfer
(
testParam
.
pip
,
controlParam
,
timeout
,
'
SUB_USB_JS_0550 GetStatus
'
)
})
...
...
@@ -503,8 +505,9 @@ describe('UsbDevicePipeJsFunctionsTest', function () {
}
var
timeout
=
5000
;
var
controlParam
=
getTransferParam
(
8
,
usb
.
USB_REQUEST_TARGET_DEVICE
,
(
usb
.
USB_REQUEST_DIR_FROM_DEVICE
)
|
(
usb
.
USB_REQUEST_TYPE_STANDARD
<<
5
)
|
(
usb
.
USB_REQUEST_TARGET_DEVICE
&
0x1f
),
0
,
0
)
var
controlParam
=
getTransferParam
(
8
,
usbManager
.
USB_REQUEST_TARGET_DEVICE
,
(
usbManager
.
USB_REQUEST_DIR_FROM_DEVICE
)
|
(
usbManager
.
USB_REQUEST_TYPE_STANDARD
<<
5
)
|
(
usbManager
.
USB_REQUEST_TARGET_DEVICE
&
0x1f
),
0
,
0
);
callControlTransfer
(
testParam
.
pip
,
controlParam
,
timeout
,
'
SUB_USB_JS_0560 GetConfiguration
'
)
})
...
...
@@ -527,8 +530,9 @@ describe('UsbDevicePipeJsFunctionsTest', function () {
}
var
timeout
=
5000
;
var
controlParam
=
getTransferParam
(
10
,
usb
.
USB_REQUEST_TARGET_INTERFACE
,
(
usb
.
USB_REQUEST_DIR_FROM_DEVICE
)
|
(
usb
.
USB_REQUEST_TYPE_STANDARD
<<
5
)
|
(
usb
.
USB_REQUEST_TARGET_INTERFACE
&
0x1f
),
0
,
1
)
var
controlParam
=
getTransferParam
(
10
,
usbManager
.
USB_REQUEST_TARGET_INTERFACE
,
(
usbManager
.
USB_REQUEST_DIR_FROM_DEVICE
)
|
(
usbManager
.
USB_REQUEST_TYPE_STANDARD
<<
5
)
|
(
usbManager
.
USB_REQUEST_TARGET_INTERFACE
&
0x1f
),
0
,
1
);
callControlTransfer
(
testParam
.
pip
,
controlParam
,
timeout
,
'
SUB_USB_JS_0570 GetInterface
'
)
})
...
...
@@ -551,8 +555,9 @@ describe('UsbDevicePipeJsFunctionsTest', function () {
}
var
timeout
=
5000
;
var
controlParam
=
getTransferParam
(
1
,
usb
.
USB_REQUEST_TARGET_DEVICE
,
(
usb
.
USB_REQUEST_DIR_TO_DEVICE
)
|
(
usb
.
USB_REQUEST_TYPE_STANDARD
<<
5
)
|
(
usb
.
USB_REQUEST_TARGET_DEVICE
&
0x1f
),
0
,
0
)
var
controlParam
=
getTransferParam
(
1
,
usbManager
.
USB_REQUEST_TARGET_DEVICE
,
(
usbManager
.
USB_REQUEST_DIR_TO_DEVICE
)
|
(
usbManager
.
USB_REQUEST_TYPE_STANDARD
<<
5
)
|
(
usbManager
.
USB_REQUEST_TARGET_DEVICE
&
0x1f
),
0
,
0
);
callControlTransfer
(
testParam
.
pip
,
controlParam
,
timeout
,
'
SUB_USB_JS_0580 ClearFeature
'
)
})
...
...
@@ -575,8 +580,9 @@ describe('UsbDevicePipeJsFunctionsTest', function () {
}
var
timeout
=
5000
;
var
controlParam
=
getTransferParam
(
255
,
usb
.
USB_REQUEST_TARGET_INTERFACE
,
(
usb
.
USB_REQUEST_DIR_FROM_DEVICE
)
|
(
usb
.
USB_REQUEST_TYPE_STANDARD
<<
5
)
|
(
usb
.
USB_REQUEST_TARGET_INTERFACE
&
0x1f
),
(
2
<<
8
),
0
)
var
controlParam
=
getTransferParam
(
255
,
usbManager
.
USB_REQUEST_TARGET_INTERFACE
,
(
usbManager
.
USB_REQUEST_DIR_FROM_DEVICE
)
|
(
usbManager
.
USB_REQUEST_TYPE_STANDARD
<<
5
)
|
(
usbManager
.
USB_REQUEST_TARGET_INTERFACE
&
0x1f
),
(
2
<<
8
),
0
);
callControlTransfer
(
testParam
.
pip
,
controlParam
,
timeout
,
'
SUB_USB_JS_0590 ClearFeature
'
)
})
...
...
@@ -599,8 +605,9 @@ describe('UsbDevicePipeJsFunctionsTest', function () {
}
var
timeout
=
5000
;
var
controlParam
=
getTransferParam
(
255
,
usb
.
USB_REQUEST_TARGET_ENDPOINT
,
(
usb
.
USB_REQUEST_DIR_TO_DEVICE
)
|
(
usb
.
USB_REQUEST_TYPE_CLASS
<<
5
)
|
(
usb
.
USB_REQUEST_TARGET_ENDPOINT
&
0x1f
),
(
2
<<
8
),
0
)
var
controlParam
=
getTransferParam
(
255
,
usbManager
.
USB_REQUEST_TARGET_ENDPOINT
,
(
usbManager
.
USB_REQUEST_DIR_TO_DEVICE
)
|
(
usbManager
.
USB_REQUEST_TYPE_CLASS
<<
5
)
|
(
usbManager
.
USB_REQUEST_TARGET_ENDPOINT
&
0x1f
),
(
2
<<
8
),
0
);
callControlTransfer
(
testParam
.
pip
,
controlParam
,
timeout
,
'
SUB_USB_JS_0600 ClearFeature
'
)
})
...
...
@@ -623,8 +630,9 @@ describe('UsbDevicePipeJsFunctionsTest', function () {
}
var
timeout
=
5000
;
var
controlParam
=
getTransferParam
(
255
,
usb
.
USB_REQUEST_TARGET_OTHER
,
(
usb
.
USB_REQUEST_DIR_TO_DEVICE
)
|
(
usb
.
USB_REQUEST_TYPE_VENDOR
<<
5
)
|
(
usb
.
USB_REQUEST_TARGET_OTHER
&
0x1f
),
(
2
<<
8
),
0
)
var
controlParam
=
getTransferParam
(
255
,
usbManager
.
USB_REQUEST_TARGET_OTHER
,
(
usbManager
.
USB_REQUEST_DIR_TO_DEVICE
)
|
(
usbManager
.
USB_REQUEST_TYPE_VENDOR
<<
5
)
|
(
usbManager
.
USB_REQUEST_TARGET_OTHER
&
0x1f
),
(
2
<<
8
),
0
);
callControlTransfer
(
testParam
.
pip
,
controlParam
,
timeout
,
'
SUB_USB_JS_0610 ClearFeature
'
)
})
...
...
@@ -647,13 +655,14 @@ describe('UsbDevicePipeJsFunctionsTest', function () {
}
var
timeout
=
5000
;
var
controlParam
=
getTransferParam
(
255
,
usb
.
USB_REQUEST_TARGET_OTHER
,
(
usb
.
USB_REQUEST_DIR_TO_DEVICE
)
|
(
usb
.
USB_REQUEST_TYPE_CLASS
<<
5
)
|
(
usb
.
USB_REQUEST_TARGET_OTHER
&
0x1f
),
0
,
0
)
var
controlParam
=
getTransferParam
(
255
,
usbManager
.
USB_REQUEST_TARGET_OTHER
,
(
usbManager
.
USB_REQUEST_DIR_TO_DEVICE
)
|
(
usbManager
.
USB_REQUEST_TYPE_CLASS
<<
5
)
|
(
usbManager
.
USB_REQUEST_TARGET_OTHER
&
0x1f
),
0
,
0
);
callControlTransfer
(
testParam
.
pip
,
controlParam
,
timeout
,
'
SUB_USB_JS_0620 ClearFeature
'
)
})
function
callControlTransferEx
(
pip
,
controlParam
,
timeout
,
caseName
)
{
usb
.
controlTransfer
(
pip
,
controlParam
,
timeout
).
then
(
data
=>
{
usb
Manager
.
controlTransfer
(
pip
,
controlParam
,
timeout
).
then
(
data
=>
{
console
.
info
(
'
usb controlTransfer ret data :
'
+
data
+
'
'
+
caseName
);
expect
(
false
).
assertTrue
();
console
.
info
(
'
usb
'
+
caseName
+
'
: FAILED
'
);
...
...
@@ -683,7 +692,7 @@ describe('UsbDevicePipeJsFunctionsTest', function () {
return
}
try
{
usb
.
controlTransfer
(
"
invalid
"
).
then
(
data
=>
{
usb
Manager
.
controlTransfer
(
"
invalid
"
).
then
(
data
=>
{
console
.
info
(
'
usb 1140 case controlTransfer ret data :
'
+
data
);
expect
(
false
).
assertTrue
();
}).
catch
(
error
=>
{
...
...
@@ -715,7 +724,7 @@ describe('UsbDevicePipeJsFunctionsTest', function () {
return
}
try
{
usb
.
controlTransfer
().
then
(
data
=>
{
usb
Manager
.
controlTransfer
().
then
(
data
=>
{
console
.
info
(
'
usb 1300 case controlTransfer ret data :
'
+
data
);
expect
(
false
).
assertTrue
();
}).
catch
(
error
=>
{
...
...
@@ -748,8 +757,9 @@ describe('UsbDevicePipeJsFunctionsTest', function () {
}
var
testParamPip
=
"
invalid
"
;
var
timeout
=
5000
;
var
controlParam
=
getTransferParam
(
255
,
usb
.
USB_REQUEST_TARGET_OTHER
,
(
usb
.
USB_REQUEST_DIR_TO_DEVICE
)
|
(
usb
.
USB_REQUEST_TYPE_CLASS
<<
5
)
|
(
usb
.
USB_REQUEST_TARGET_OTHER
&
0x1f
),
0
,
0
);
var
controlParam
=
getTransferParam
(
255
,
usbManager
.
USB_REQUEST_TARGET_OTHER
,
(
usbManager
.
USB_REQUEST_DIR_TO_DEVICE
)
|
(
usbManager
.
USB_REQUEST_TYPE_CLASS
<<
5
)
|
(
usbManager
.
USB_REQUEST_TARGET_OTHER
&
0x1f
),
0
,
0
);
try
{
callControlTransferEx
(
testParamPip
,
controlParam
,
timeout
,
'
SUB_USB_JS_1440 ClearFeature
'
);
}
catch
(
err
)
{
...
...
@@ -806,8 +816,9 @@ describe('UsbDevicePipeJsFunctionsTest', function () {
return
}
var
timeout
=
"
invalid
"
;
var
controlParam
=
getTransferParam
(
255
,
usb
.
USB_REQUEST_TARGET_OTHER
,
(
usb
.
USB_REQUEST_DIR_TO_DEVICE
)
|
(
usb
.
USB_REQUEST_TYPE_CLASS
<<
5
)
|
(
usb
.
USB_REQUEST_TARGET_OTHER
&
0x1f
),
0
,
0
);
var
controlParam
=
getTransferParam
(
255
,
usbManager
.
USB_REQUEST_TARGET_OTHER
,
(
usbManager
.
USB_REQUEST_DIR_TO_DEVICE
)
|
(
usbManager
.
USB_REQUEST_TYPE_CLASS
<<
5
)
|
(
usbManager
.
USB_REQUEST_TARGET_OTHER
&
0x1f
),
0
,
0
);
try
{
callControlTransferEx
(
testParam
.
pip
,
controlParam
,
timeout
,
'
SUB_USB_JS_1570 ClearFeature
'
);
}
catch
(
err
)
{
...
...
usb/usb_standard/src/main/js/test/UsbDevicePipeJsunitEx.test.js
浏览文件 @
1df14524
此差异已折叠。
点击以展开。
usb/usb_standard/src/main/js/test/UsbFunctionsJsunit.test.js
浏览文件 @
1df14524
...
...
@@ -13,7 +13,7 @@
* limitations under the License.
*/
import
usb
from
'
@ohos.usb
'
;
import
usb
Manager
from
'
@ohos.usbManager
'
;
import
CheckEmptyUtils
from
'
./CheckEmptyUtils.js
'
;
import
{
describe
,
beforeAll
,
beforeEach
,
afterEach
,
afterAll
,
it
,
expect
}
from
'
@ohos/hypium
'
...
...
@@ -23,13 +23,13 @@ describe('UsbFunctionsJsFunctionsTest', function () {
beforeAll
(
function
()
{
console
.
log
(
'
*************Usb Unit UsbFunctionsJsFunctionsTest Begin*************
'
);
var
Version
=
usb
.
getVersion
()
var
Version
=
usb
Manager
.
getVersion
()
console
.
info
(
'
begin test getversion :
'
+
Version
)
// version > 17 host currentMode = 2 device currentMode = 1
var
usbPortList
=
usb
.
getPorts
()
var
usbPortList
=
usb
Manager
.
getPorts
()
if
(
usbPortList
.
length
>
0
)
{
if
(
usbPortList
[
0
].
status
.
currentMode
==
2
)
{
usb
.
setPortRoles
(
usbPortList
[
0
].
id
,
usb
.
SINK
,
usb
.
DEVICE
).
then
(
data
=>
{
usb
Manager
.
setPortRoles
(
usbPortList
[
0
].
id
,
usbManager
.
SINK
,
usbManager
.
DEVICE
).
then
(
data
=>
{
console
.
info
(
'
usb case setPortRoles return:
'
+
data
);
}).
catch
(
error
=>
{
console
.
info
(
'
usb case setPortRoles error :
'
+
error
);
...
...
@@ -57,12 +57,12 @@ describe('UsbFunctionsJsFunctionsTest', function () {
*/
it
(
'
SUB_USB_JS_0330
'
,
0
,
function
()
{
console
.
info
(
'
usb SUB_USB_JS_0330 begin
'
);
var
maskCode
=
usb
.
getCurrentFunctions
();
var
maskCode
=
usb
Manager
.
getCurrentFunctions
();
console
.
info
(
'
usb case getCurrentFunctions return:
'
+
maskCode
);
var
strMaskCode
=
usb
.
usbFunctionsToString
(
maskCode
)
var
strMaskCode
=
usb
Manager
.
usbFunctionsToString
(
maskCode
)
console
.
info
(
'
usb case usbFunctionsToString return str:
'
+
strMaskCode
);
var
nMaskCode
=
usb
.
usbFunctionsFromString
(
strMaskCode
)
var
nMaskCode
=
usb
Manager
.
usbFunctionsFromString
(
strMaskCode
)
console
.
info
(
'
usb case strMaskCode usbFunctionsFromString return int:
'
+
nMaskCode
);
expect
(
nMaskCode
).
assertEqual
(
maskCode
);
console
.
info
(
'
usb SUB_USB_JS_0330 : PASS
'
);
...
...
@@ -75,24 +75,24 @@ describe('UsbFunctionsJsFunctionsTest', function () {
*/
it
(
'
SUB_USB_JS_0340
'
,
0
,
function
()
{
console
.
info
(
'
usb SUB_USB_JS_0340 begin
'
);
var
maskCode
=
usb
.
getCurrentFunctions
();
var
maskCode
=
usb
Manager
.
getCurrentFunctions
();
console
.
info
(
'
usb case getCurrentFunctions return:
'
+
maskCode
);
var
strMaskCode
=
usb
.
usbFunctionsToString
(
maskCode
)
var
strMaskCode
=
usb
Manager
.
usbFunctionsToString
(
maskCode
)
console
.
info
(
'
usb case usbFunctionsToString return str:
'
+
strMaskCode
);
var
nMaskCode
=
usb
.
usbFunctionsFromString
(
strMaskCode
)
var
nMaskCode
=
usb
Manager
.
usbFunctionsFromString
(
strMaskCode
)
console
.
info
(
'
usb case strMaskCode usbFunctionsFromString return int:
'
+
nMaskCode
);
var
errmaskCode
=
0
var
strMaskCode
=
usb
.
usbFunctionsToString
(
errmaskCode
)
var
strMaskCode
=
usb
Manager
.
usbFunctionsToString
(
errmaskCode
)
console
.
info
(
'
usb case
'
+
errmaskCode
+
'
usbFunctionsToString return str:
'
+
strMaskCode
);
var
errStrMaskCode
=
'
none
'
var
nMaskCode
=
usb
.
usbFunctionsFromString
(
errStrMaskCode
)
var
nMaskCode
=
usb
Manager
.
usbFunctionsFromString
(
errStrMaskCode
)
console
.
info
(
'
usb case errStrMaskCode
'
+
errStrMaskCode
+
'
usbFunctionsFromString return int:
'
+
nMaskCode
);
expect
(
nMaskCode
).
assertEqual
(
usb
.
NONE
);
expect
(
nMaskCode
).
assertEqual
(
usb
Manager
.
NONE
);
console
.
info
(
'
usb SUB_USB_JS_0340 : PASS
'
);
})
...
...
@@ -105,7 +105,7 @@ describe('UsbFunctionsJsFunctionsTest', function () {
it
(
'
SUB_USB_JS_1000
'
,
0
,
function
()
{
console
.
info
(
'
usb SUB_USB_JS_1000 begin
'
);
try
{
var
maskCode
=
usb
.
getCurrentFunctions
(
"
invalid
"
);
var
maskCode
=
usb
Manager
.
getCurrentFunctions
(
"
invalid
"
);
console
.
info
(
'
usb 1000 case getCurrentFunctions return:
'
+
maskCode
);
expect
(
false
).
assertTrue
();
}
catch
(
err
)
{
...
...
usb/usb_standard/src/main/js/test/UsbFunctionsJsunitEx.test.js
浏览文件 @
1df14524
此差异已折叠。
点击以展开。
usb/usb_standard/src/main/js/test/UsbPortAndFunctionJsunit.test.js
浏览文件 @
1df14524
...
...
@@ -13,7 +13,7 @@
* limitations under the License.
*/
import
usb
from
'
@ohos.usb
'
;
import
usb
Manager
from
'
@ohos.usbManager
'
;
import
CheckEmptyUtils
from
'
./CheckEmptyUtils.js
'
;
import
{
describe
,
beforeAll
,
beforeEach
,
afterEach
,
afterAll
,
it
,
expect
}
from
'
@ohos/hypium
'
...
...
@@ -23,13 +23,13 @@ describe('UsbPortAndFunctionsJsFunctionsTest', function () {
beforeAll
(
function
()
{
console
.
log
(
'
*************Usb Unit UsbPortAndFunctionsJsFunctionsTest Begin*************
'
);
var
Version
=
usb
.
getVersion
()
var
Version
=
usb
Manager
.
getVersion
()
console
.
info
(
'
begin test getversion :
'
+
Version
)
// version > 17 host currentMode = 2 device currentMode = 1
var
usbPortList
=
usb
.
getPorts
()
var
usbPortList
=
usb
Manager
.
getPorts
()
if
(
usbPortList
.
length
>
0
)
{
if
(
usbPortList
[
0
].
status
.
currentMode
==
2
)
{
usb
.
setPortRoles
(
usbPortList
[
0
].
id
,
usb
.
SINK
,
usb
.
DEVICE
).
then
(
data
=>
{
usb
Manager
.
setPortRoles
(
usbPortList
[
0
].
id
,
usbManager
.
SINK
,
usbManager
.
DEVICE
).
then
(
data
=>
{
console
.
info
(
'
usb case setPortRoles return:
'
+
data
);
}).
catch
(
error
=>
{
console
.
info
(
'
usb case setPortRoles error :
'
+
error
);
...
...
@@ -52,7 +52,7 @@ describe('UsbPortAndFunctionsJsFunctionsTest', function () {
function
callSetCurFunction
(
caseName
,
iValue
)
{
console
.
info
(
'
usb case param case name:
'
+
caseName
);
console
.
info
(
'
usb case param iValue:
'
+
iValue
);
usb
.
setCurrentFunctions
(
iValue
).
then
(
data
=>
{
usb
Manager
.
setCurrentFunctions
(
iValue
).
then
(
data
=>
{
console
.
info
(
'
usb case SetCurFunction ret:
'
+
data
);
expect
(
data
).
assertTrue
();
console
.
info
(
'
usb case
'
+
caseName
+
'
: PASS
'
);
...
...
@@ -71,11 +71,11 @@ describe('UsbPortAndFunctionsJsFunctionsTest', function () {
it
(
'
SUB_USB_JS_0350
'
,
0
,
function
()
{
CheckEmptyUtils
.
sleep
(
3000
);
console
.
info
(
'
usb SUB_USB_JS_0350 set ACM begin
'
);
var
maskCode
=
usb
.
getCurrentFunctions
();
var
maskCode
=
usb
Manager
.
getCurrentFunctions
();
console
.
info
(
'
usb case getCurrentFunctions return:
'
+
maskCode
);
var
funcString
=
usb
.
usbFunctionsToString
(
maskCode
);
var
funcString
=
usb
Manager
.
usbFunctionsToString
(
maskCode
);
console
.
info
(
'
usb case funcString:
'
+
funcString
);
callSetCurFunction
(
'
SUB_USB_JS_0350 ACM 1
'
,
usb
.
ACM
);
callSetCurFunction
(
'
SUB_USB_JS_0350 ACM 1
'
,
usb
Manager
.
ACM
);
})
/**
...
...
@@ -86,11 +86,11 @@ describe('UsbPortAndFunctionsJsFunctionsTest', function () {
it
(
'
SUB_USB_JS_0360
'
,
0
,
function
()
{
CheckEmptyUtils
.
sleep
(
3000
);
console
.
info
(
'
usb SUB_USB_JS_0360 set ECM begin
'
);
var
maskCode
=
usb
.
getCurrentFunctions
();
var
maskCode
=
usb
Manager
.
getCurrentFunctions
();
console
.
info
(
'
usb case getCurrentFunctions return:
'
+
maskCode
);
var
funcString
=
usb
.
usbFunctionsToString
(
maskCode
);
var
funcString
=
usb
Manager
.
usbFunctionsToString
(
maskCode
);
console
.
info
(
'
usb case funcString:
'
+
funcString
);
callSetCurFunction
(
'
SUB_USB_JS_0360 ECM 2
'
,
usb
.
ECM
);
callSetCurFunction
(
'
SUB_USB_JS_0360 ECM 2
'
,
usb
Manager
.
ECM
);
})
/**
...
...
@@ -101,11 +101,11 @@ describe('UsbPortAndFunctionsJsFunctionsTest', function () {
it
(
'
SUB_USB_JS_0370
'
,
0
,
function
()
{
CheckEmptyUtils
.
sleep
(
3000
);
console
.
info
(
'
usb SUB_USB_JS_0370 set ACM ECM begin
'
);
var
maskCode
=
usb
.
getCurrentFunctions
();
var
maskCode
=
usb
Manager
.
getCurrentFunctions
();
console
.
info
(
'
usb case getCurrentFunctions return:
'
+
maskCode
);
var
funcString
=
usb
.
usbFunctionsToString
(
maskCode
);
var
funcString
=
usb
Manager
.
usbFunctionsToString
(
maskCode
);
console
.
info
(
'
usb case funcString:
'
+
funcString
);
callSetCurFunction
(
'
SUB_USB_JS_0370 ACM ECM 3
'
,
(
usb
.
ACM
|
usb
.
ECM
));
callSetCurFunction
(
'
SUB_USB_JS_0370 ACM ECM 3
'
,
(
usb
Manager
.
ACM
|
usbManager
.
ECM
));
})
/**
...
...
@@ -116,11 +116,11 @@ describe('UsbPortAndFunctionsJsFunctionsTest', function () {
it
(
'
SUB_USB_JS_0380
'
,
0
,
function
()
{
CheckEmptyUtils
.
sleep
(
3000
);
console
.
info
(
'
usb SUB_USB_JS_0380 set HDC begin
'
);
var
maskCode
=
usb
.
getCurrentFunctions
();
var
maskCode
=
usb
Manager
.
getCurrentFunctions
();
console
.
info
(
'
usb case getCurrentFunctions return:
'
+
maskCode
);
var
funcString
=
usb
.
usbFunctionsToString
(
maskCode
);
var
funcString
=
usb
Manager
.
usbFunctionsToString
(
maskCode
);
console
.
info
(
'
usb case funcString:
'
+
funcString
);
callSetCurFunction
(
'
SUB_USB_JS_0380 HDC 4
'
,
usb
.
HDC
);
callSetCurFunction
(
'
SUB_USB_JS_0380 HDC 4
'
,
usb
Manager
.
HDC
);
})
/**
...
...
@@ -131,11 +131,11 @@ describe('UsbPortAndFunctionsJsFunctionsTest', function () {
it
(
'
SUB_USB_JS_0390
'
,
0
,
function
()
{
CheckEmptyUtils
.
sleep
(
3000
);
console
.
info
(
'
usb SUB_USB_JS_0390 set ACM HDC begin
'
);
var
maskCode
=
usb
.
getCurrentFunctions
();
var
maskCode
=
usb
Manager
.
getCurrentFunctions
();
console
.
info
(
'
usb case getCurrentFunctions return:
'
+
maskCode
);
var
funcString
=
usb
.
usbFunctionsToString
(
maskCode
);
var
funcString
=
usb
Manager
.
usbFunctionsToString
(
maskCode
);
console
.
info
(
'
usb case funcString:
'
+
funcString
);
callSetCurFunction
(
'
SUB_USB_JS_0390 ACM HDC 5
'
,
(
usb
.
HDC
|
usb
.
ACM
));
callSetCurFunction
(
'
SUB_USB_JS_0390 ACM HDC 5
'
,
(
usb
Manager
.
HDC
|
usbManager
.
ACM
));
})
/**
...
...
@@ -146,11 +146,11 @@ describe('UsbPortAndFunctionsJsFunctionsTest', function () {
it
(
'
SUB_USB_JS_0400
'
,
0
,
function
()
{
CheckEmptyUtils
.
sleep
(
3000
);
console
.
info
(
'
usb SUB_USB_JS_0400 set ECM HDC begin
'
);
var
maskCode
=
usb
.
getCurrentFunctions
();
var
maskCode
=
usb
Manager
.
getCurrentFunctions
();
console
.
info
(
'
usb case getCurrentFunctions return:
'
+
maskCode
);
var
funcString
=
usb
.
usbFunctionsToString
(
maskCode
);
var
funcString
=
usb
Manager
.
usbFunctionsToString
(
maskCode
);
console
.
info
(
'
usb case funcString:
'
+
funcString
);
callSetCurFunction
(
'
SUB_USB_JS_0400 ECM HDC 6
'
,
(
usb
.
HDC
|
usb
.
ECM
));
callSetCurFunction
(
'
SUB_USB_JS_0400 ECM HDC 6
'
,
(
usb
Manager
.
HDC
|
usbManager
.
ECM
));
})
/**
...
...
@@ -161,11 +161,11 @@ describe('UsbPortAndFunctionsJsFunctionsTest', function () {
it
(
'
SUB_USB_JS_1620
'
,
0
,
function
()
{
CheckEmptyUtils
.
sleep
(
3000
);
console
.
info
(
'
usb SUB_USB_JS_1620 set MTP begin
'
);
var
maskCode
=
usb
.
getCurrentFunctions
();
var
maskCode
=
usb
Manager
.
getCurrentFunctions
();
console
.
info
(
'
usb case getCurrentFunctions return:
'
+
maskCode
);
var
funcString
=
usb
.
usbFunctionsToString
(
maskCode
);
var
funcString
=
usb
Manager
.
usbFunctionsToString
(
maskCode
);
console
.
info
(
'
usb case funcString:
'
+
funcString
);
callSetCurFunction
(
'
SUB_USB_JS_1620 MTP 8
'
,
(
usb
.
MTP
));
callSetCurFunction
(
'
SUB_USB_JS_1620 MTP 8
'
,
(
usb
Manager
.
MTP
));
})
/**
...
...
@@ -176,11 +176,11 @@ describe('UsbPortAndFunctionsJsFunctionsTest', function () {
it
(
'
SUB_USB_JS_1630
'
,
0
,
function
()
{
CheckEmptyUtils
.
sleep
(
3000
);
console
.
info
(
'
usb SUB_USB_JS_1630 set MTP HDC begin
'
);
var
maskCode
=
usb
.
getCurrentFunctions
();
var
maskCode
=
usb
Manager
.
getCurrentFunctions
();
console
.
info
(
'
usb case getCurrentFunctions return:
'
+
maskCode
);
var
funcString
=
usb
.
usbFunctionsToString
(
maskCode
);
var
funcString
=
usb
Manager
.
usbFunctionsToString
(
maskCode
);
console
.
info
(
'
usb case funcString:
'
+
funcString
);
callSetCurFunction
(
'
SUB_USB_JS_1630 MTP HDC 12
'
,
(
usb
.
MTP
|
usb
.
HDC
));
callSetCurFunction
(
'
SUB_USB_JS_1630 MTP HDC 12
'
,
(
usb
Manager
.
MTP
|
usbManager
.
HDC
));
})
/**
...
...
@@ -191,11 +191,11 @@ describe('UsbPortAndFunctionsJsFunctionsTest', function () {
it
(
'
SUB_USB_JS_1640
'
,
0
,
function
()
{
CheckEmptyUtils
.
sleep
(
3000
);
console
.
info
(
'
usb SUB_USB_JS_1640 set PTP begin
'
);
var
maskCode
=
usb
.
getCurrentFunctions
();
var
maskCode
=
usb
Manager
.
getCurrentFunctions
();
console
.
info
(
'
usb case getCurrentFunctions return:
'
+
maskCode
);
var
funcString
=
usb
.
usbFunctionsToString
(
maskCode
);
var
funcString
=
usb
Manager
.
usbFunctionsToString
(
maskCode
);
console
.
info
(
'
usb case funcString:
'
+
funcString
);
callSetCurFunction
(
'
SUB_USB_JS_1640 PTP 16
'
,
(
usb
.
PTP
));
callSetCurFunction
(
'
SUB_USB_JS_1640 PTP 16
'
,
(
usb
Manager
.
PTP
));
})
/**
...
...
@@ -206,11 +206,11 @@ describe('UsbPortAndFunctionsJsFunctionsTest', function () {
it
(
'
SUB_USB_JS_1650
'
,
0
,
function
()
{
CheckEmptyUtils
.
sleep
(
3000
);
console
.
info
(
'
usb SUB_USB_JS_1650 set PTP HDC begin
'
);
var
maskCode
=
usb
.
getCurrentFunctions
();
var
maskCode
=
usb
Manager
.
getCurrentFunctions
();
console
.
info
(
'
usb case getCurrentFunctions return:
'
+
maskCode
);
var
funcString
=
usb
.
usbFunctionsToString
(
maskCode
);
var
funcString
=
usb
Manager
.
usbFunctionsToString
(
maskCode
);
console
.
info
(
'
usb case funcString:
'
+
funcString
);
callSetCurFunction
(
'
SUB_USB_JS_1650 PTP HDC 20
'
,
(
usb
.
PTP
|
usb
.
HDC
));
callSetCurFunction
(
'
SUB_USB_JS_1650 PTP HDC 20
'
,
(
usb
Manager
.
PTP
|
usbManager
.
HDC
));
})
/**
...
...
@@ -221,11 +221,11 @@ describe('UsbPortAndFunctionsJsFunctionsTest', function () {
it
(
'
SUB_USB_JS_1660
'
,
0
,
function
()
{
CheckEmptyUtils
.
sleep
(
3000
);
console
.
info
(
'
usb SUB_USB_JS_1660 set RNDIS begin
'
);
var
maskCode
=
usb
.
getCurrentFunctions
();
var
maskCode
=
usb
Manager
.
getCurrentFunctions
();
console
.
info
(
'
usb case getCurrentFunctions return:
'
+
maskCode
);
var
funcString
=
usb
.
usbFunctionsToString
(
maskCode
);
var
funcString
=
usb
Manager
.
usbFunctionsToString
(
maskCode
);
console
.
info
(
'
usb case funcString:
'
+
funcString
);
callSetCurFunction
(
'
SUB_USB_JS_1660 RNDIS 32
'
,
(
usb
.
RNDIS
));
callSetCurFunction
(
'
SUB_USB_JS_1660 RNDIS 32
'
,
(
usb
Manager
.
RNDIS
));
})
/**
...
...
@@ -236,11 +236,11 @@ describe('UsbPortAndFunctionsJsFunctionsTest', function () {
it
(
'
SUB_USB_JS_1670
'
,
0
,
function
()
{
CheckEmptyUtils
.
sleep
(
3000
);
console
.
info
(
'
usb SUB_USB_JS_1670 set RNDIS HDC begin
'
);
var
maskCode
=
usb
.
getCurrentFunctions
();
var
maskCode
=
usb
Manager
.
getCurrentFunctions
();
console
.
info
(
'
usb case getCurrentFunctions return:
'
+
maskCode
);
var
funcString
=
usb
.
usbFunctionsToString
(
maskCode
);
var
funcString
=
usb
Manager
.
usbFunctionsToString
(
maskCode
);
console
.
info
(
'
usb case funcString:
'
+
funcString
);
callSetCurFunction
(
'
SUB_USB_JS_1670 RNDIS HDC 36
'
,
(
usb
.
RNDIS
|
usb
.
HDC
));
callSetCurFunction
(
'
SUB_USB_JS_1670 RNDIS HDC 36
'
,
(
usb
Manager
.
RNDIS
|
usbManager
.
HDC
));
})
/**
...
...
@@ -251,11 +251,11 @@ describe('UsbPortAndFunctionsJsFunctionsTest', function () {
it
(
'
SUB_USB_JS_1680
'
,
0
,
function
()
{
CheckEmptyUtils
.
sleep
(
3000
);
console
.
info
(
'
usb SUB_USB_JS_1680 set STORAGE begin
'
);
var
maskCode
=
usb
.
getCurrentFunctions
();
var
maskCode
=
usb
Manager
.
getCurrentFunctions
();
console
.
info
(
'
usb case getCurrentFunctions return:
'
+
maskCode
);
var
funcString
=
usb
.
usbFunctionsToString
(
maskCode
);
var
funcString
=
usb
Manager
.
usbFunctionsToString
(
maskCode
);
console
.
info
(
'
usb case funcString:
'
+
funcString
);
callSetCurFunction
(
'
SUB_USB_JS_1680 STORAGE 512
'
,
(
usb
.
STORAGE
));
callSetCurFunction
(
'
SUB_USB_JS_1680 STORAGE 512
'
,
(
usb
Manager
.
STORAGE
));
})
/**
...
...
@@ -266,11 +266,11 @@ describe('UsbPortAndFunctionsJsFunctionsTest', function () {
it
(
'
SUB_USB_JS_1690
'
,
0
,
function
()
{
CheckEmptyUtils
.
sleep
(
3000
);
console
.
info
(
'
usb SUB_USB_JS_1690 set STORAGE HDC begin
'
);
var
maskCode
=
usb
.
getCurrentFunctions
();
var
maskCode
=
usb
Manager
.
getCurrentFunctions
();
console
.
info
(
'
usb case getCurrentFunctions return:
'
+
maskCode
);
var
funcString
=
usb
.
usbFunctionsToString
(
maskCode
);
var
funcString
=
usb
Manager
.
usbFunctionsToString
(
maskCode
);
console
.
info
(
'
usb case funcString:
'
+
funcString
);
callSetCurFunction
(
'
SUB_USB_JS_1690 STORAGE HDC 516
'
,
(
usb
.
STORAGE
|
usb
.
HDC
));
callSetCurFunction
(
'
SUB_USB_JS_1690 STORAGE HDC 516
'
,
(
usb
Manager
.
STORAGE
|
usbManager
.
HDC
));
})
/**
...
...
@@ -280,7 +280,7 @@ describe('UsbPortAndFunctionsJsFunctionsTest', function () {
*/
it
(
'
SUB_USB_JS_0010
'
,
0
,
function
()
{
console
.
info
(
'
usb SUB_USB_JS_0010 device 2 2 begin
'
);
var
usbPortList
=
usb
.
getPorts
()
var
usbPortList
=
usb
Manager
.
getPorts
()
if
(
usbPortList
.
length
==
0
)
{
console
.
info
(
'
usb SUB_USB_JS_0010 device 2 2 usbPortList is null
'
);
expect
(
false
).
assertTrue
();
...
...
@@ -289,7 +289,7 @@ describe('UsbPortAndFunctionsJsFunctionsTest', function () {
for
(
var
i
=
0
;
i
<
usbPortList
.
length
;
i
++
)
{
console
.
info
(
'
usb 0010 case set data role 2, data role 2
'
);
usb
.
setPortRoles
(
usbPortList
[
i
].
id
,
usb
.
SINK
,
usb
.
DEVICE
).
then
(
data
=>
{
usb
Manager
.
setPortRoles
(
usbPortList
[
i
].
id
,
usbManager
.
SINK
,
usbManager
.
DEVICE
).
then
(
data
=>
{
console
.
info
(
'
usb 0010 case setPortRoles return:
'
+
data
);
expect
(
data
).
assertTrue
();
}).
catch
(
error
=>
{
...
...
@@ -309,7 +309,7 @@ describe('UsbPortAndFunctionsJsFunctionsTest', function () {
*/
it
(
'
SUB_USB_JS_0020
'
,
0
,
function
()
{
console
.
info
(
'
usb SUB_USB_JS_0020 host 1 1 begin
'
);
var
usbPortList
=
usb
.
getPorts
()
var
usbPortList
=
usb
Manager
.
getPorts
()
if
(
usbPortList
.
length
==
0
)
{
console
.
info
(
'
usb SUB_USB_JS_0020 host 1 1 usbPortList is null
'
);
expect
(
false
).
assertTrue
();
...
...
@@ -318,7 +318,7 @@ describe('UsbPortAndFunctionsJsFunctionsTest', function () {
for
(
var
i
=
0
;
i
<
usbPortList
.
length
;
i
++
)
{
console
.
info
(
'
usb 0020 case set data role 1, data role 1
'
);
usb
.
setPortRoles
(
usbPortList
[
i
].
id
,
usb
.
SOURCE
,
usb
.
HOST
).
then
(
data
=>
{
usb
Manager
.
setPortRoles
(
usbPortList
[
i
].
id
,
usbManager
.
SOURCE
,
usbManager
.
HOST
).
then
(
data
=>
{
console
.
info
(
'
usb 0020 case setPortRoles return:
'
+
data
);
expect
(
data
).
assertTrue
();
}).
catch
(
error
=>
{
...
...
usb/usb_standard/src/main/js/test/UsbPortJsunit.test.js
浏览文件 @
1df14524
/*
* Copyright (c) 2021-202
2
Huawei Device Co., Ltd.
* Copyright (c) 2021-202
3
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
...
...
@@ -13,7 +13,7 @@
* limitations under the License.
*/
import
usb
from
'
@ohos.usb
'
;
import
usb
Manager
from
'
@ohos.usbManager
'
;
import
CheckEmptyUtils
from
'
./CheckEmptyUtils.js
'
;
import
{
describe
,
beforeAll
,
beforeEach
,
afterEach
,
afterAll
,
it
,
expect
}
from
'
@ohos/hypium
'
...
...
@@ -23,7 +23,7 @@ describe('UsbPortJsFunctionsTest', function () {
beforeAll
(
function
()
{
console
.
log
(
'
*************Usb Unit UsbPortJsFunctionsTest Begin*************
'
);
var
Version
=
usb
.
getVersion
()
var
Version
=
usb
Manager
.
getVersion
()
console
.
info
(
'
begin test getversion :
'
+
Version
)
})
beforeEach
(
function
()
{
...
...
@@ -43,7 +43,7 @@ describe('UsbPortJsFunctionsTest', function () {
*/
it
(
'
SUB_USB_JS_0410
'
,
0
,
function
()
{
console
.
info
(
'
usb SUB_USB_JS_0410 begin
'
);
var
usbPortList
=
usb
.
getPorts
()
var
usbPortList
=
usb
Manager
.
getPorts
()
if
(
usbPortList
.
length
==
0
)
{
console
.
info
(
'
usb SUB_USB_JS_0410 usbPortList is null
'
);
expect
(
false
).
assertTrue
();
...
...
@@ -60,7 +60,7 @@ describe('UsbPortJsFunctionsTest', function () {
*/
it
(
'
SUB_USB_JS_0220
'
,
0
,
function
()
{
console
.
info
(
'
usb SUB_USB_JS_0220 begin
'
);
var
usbPortList
=
usb
.
getPorts
()
var
usbPortList
=
usb
Manager
.
getPorts
()
if
(
usbPortList
.
length
==
0
)
{
console
.
info
(
'
usb SUB_USB_JS_0220 usbPortList is null
'
);
expect
(
false
).
assertTrue
();
...
...
@@ -69,7 +69,7 @@ describe('UsbPortJsFunctionsTest', function () {
expect
(
usbPortList
.
length
>
0
).
assertTrue
();
for
(
var
i
=
0
;
i
<
usbPortList
.
length
;
i
++
)
{
var
maskCode
=
usb
.
getSupportedModes
(
usbPortList
[
i
].
id
)
var
maskCode
=
usb
Manager
.
getSupportedModes
(
usbPortList
[
i
].
id
)
expect
(
maskCode
).
assertEqual
(
usbPortList
[
i
].
supportedModes
);
}
...
...
usb/usb_standard/src/main/js/test/UsbPortJsunitEx.test.js
浏览文件 @
1df14524
...
...
@@ -13,7 +13,7 @@
* limitations under the License.
*/
import
usb
from
'
@ohos.usb
'
;
import
usb
Manager
from
'
@ohos.usbManager
'
;
import
CheckEmptyUtils
from
'
./CheckEmptyUtils.js
'
;
import
{
describe
,
beforeAll
,
beforeEach
,
afterEach
,
afterAll
,
it
,
expect
}
from
'
@ohos/hypium
'
...
...
@@ -24,7 +24,7 @@ describe('UsbPortJsFunctionsTestEx', function () {
var
gPort
;
beforeAll
(
function
()
{
console
.
log
(
'
*************Usb Unit UsbPortJsFunctionsTestEx Begin*************
'
);
var
Version
=
usb
.
getVersion
()
var
Version
=
usb
Manager
.
getVersion
()
console
.
info
(
'
begin test getversion :
'
+
Version
)
})
beforeEach
(
function
()
{
...
...
@@ -46,7 +46,7 @@ describe('UsbPortJsFunctionsTestEx', function () {
*/
it
(
'
SUB_USB_JS_0230
'
,
0
,
function
()
{
console
.
info
(
'
usb SUB_USB_JS_0230 begin
'
);
var
usbPortList
=
usb
.
getPorts
()
var
usbPortList
=
usb
Manager
.
getPorts
()
if
(
usbPortList
.
length
==
0
)
{
console
.
info
(
'
usb SUB_USB_JS_0230 usbPortList is null
'
);
expect
(
false
).
assertTrue
();
...
...
@@ -56,8 +56,8 @@ describe('UsbPortJsFunctionsTestEx', function () {
expect
(
usbPortList
.
length
>
0
).
assertTrue
();
gPort
=
usbPortList
[
0
]
var
portID
=
usbPortList
[
0
].
id
+
10
var
maskCode
=
usb
.
getSupportedModes
(
portID
)
expect
(
maskCode
).
assertEqual
(
usb
.
NONE
);
var
maskCode
=
usb
Manager
.
getSupportedModes
(
portID
)
expect
(
maskCode
).
assertEqual
(
usb
Manager
.
NONE
);
console
.
info
(
'
usb SUB_USB_JS_0230 : PASS
'
);
})
...
...
@@ -71,7 +71,7 @@ describe('UsbPortJsFunctionsTestEx', function () {
it
(
'
SUB_USB_JS_1210
'
,
0
,
function
()
{
console
.
info
(
'
usb SUB_USB_JS_1210 begin
'
);
try
{
var
maskCode
=
usb
.
getSupportedModes
(
"
invalid
"
);
var
maskCode
=
usb
Manager
.
getSupportedModes
(
"
invalid
"
);
console
.
info
(
'
usb 1210 case getSupportedModes return:
'
+
maskCode
);
expect
(
false
).
assertTrue
();
}
catch
(
err
)
{
...
...
@@ -90,7 +90,7 @@ describe('UsbPortJsFunctionsTestEx', function () {
it
(
'
SUB_USB_JS_1380
'
,
0
,
function
()
{
console
.
info
(
'
usb SUB_USB_JS_1380 begin
'
);
try
{
var
maskCode
=
usb
.
getSupportedModes
();
var
maskCode
=
usb
Manager
.
getSupportedModes
();
console
.
info
(
'
usb 1380 case getSupportedModes return:
'
+
maskCode
);
expect
(
false
).
assertTrue
();
}
catch
(
err
)
{
...
...
@@ -107,9 +107,9 @@ describe('UsbPortJsFunctionsTestEx', function () {
*/
it
(
'
SUB_USB_JS_0030
'
,
0
,
function
()
{
var
portId
=
gPort
.
id
;
var
powerRole
=
usb
.
SINK
;
var
dataRole
=
usb
.
NONE
-
1
;
usb
.
setPortRoles
(
portId
,
powerRole
,
dataRole
).
then
(
data
=>
{
var
powerRole
=
usb
Manager
.
SINK
;
var
dataRole
=
usb
Manager
.
NONE
-
1
;
usb
Manager
.
setPortRoles
(
portId
,
powerRole
,
dataRole
).
then
(
data
=>
{
console
.
info
(
'
usb 0030 case setPortRoles return:
'
+
data
);
expect
(
data
).
assertFalse
();
}).
catch
(
error
=>
{
...
...
@@ -127,9 +127,9 @@ describe('UsbPortJsFunctionsTestEx', function () {
*/
it
(
'
SUB_USB_JS_0040
'
,
0
,
function
()
{
var
portId
=
gPort
.
id
;
var
powerRole
=
usb
.
NONE
-
1
;
var
dataRole
=
usb
.
DEVICE
;
usb
.
setPortRoles
(
portId
,
powerRole
,
dataRole
).
then
(
data
=>
{
var
powerRole
=
usb
Manager
.
NONE
-
1
;
var
dataRole
=
usb
Manager
.
DEVICE
;
usb
Manager
.
setPortRoles
(
portId
,
powerRole
,
dataRole
).
then
(
data
=>
{
console
.
info
(
'
usb 0040 case setPortRoles return:
'
+
data
);
expect
(
data
).
assertFalse
();
}).
catch
(
error
=>
{
...
...
@@ -147,9 +147,9 @@ describe('UsbPortJsFunctionsTestEx', function () {
*/
it
(
'
SUB_USB_JS_0050
'
,
0
,
function
()
{
var
portId
=
gPort
.
id
-
3
;
var
powerRole
=
usb
.
SINK
;
var
dataRole
=
usb
.
NONE
-
1
;
usb
.
setPortRoles
(
portId
,
powerRole
,
dataRole
).
then
(
data
=>
{
var
powerRole
=
usb
Manager
.
SINK
;
var
dataRole
=
usb
Manager
.
NONE
-
1
;
usb
Manager
.
setPortRoles
(
portId
,
powerRole
,
dataRole
).
then
(
data
=>
{
console
.
info
(
'
usb 0050 case setPortRoles return:
'
+
data
);
expect
(
data
).
assertFalse
();
}).
catch
(
error
=>
{
...
...
@@ -167,9 +167,9 @@ describe('UsbPortJsFunctionsTestEx', function () {
*/
it
(
'
SUB_USB_JS_0060
'
,
0
,
function
()
{
var
portId
=
gPort
.
id
;
var
powerRole
=
usb
.
NONE
-
1
;
var
dataRole
=
usb
.
NONE
-
1
;
usb
.
setPortRoles
(
portId
,
powerRole
,
dataRole
).
then
(
data
=>
{
var
powerRole
=
usb
Manager
.
NONE
-
1
;
var
dataRole
=
usb
Manager
.
NONE
-
1
;
usb
Manager
.
setPortRoles
(
portId
,
powerRole
,
dataRole
).
then
(
data
=>
{
console
.
info
(
'
usb 0060 case setPortRoles return:
'
+
data
);
expect
(
data
).
assertFalse
();
}).
catch
(
error
=>
{
...
...
@@ -187,9 +187,9 @@ describe('UsbPortJsFunctionsTestEx', function () {
*/
it
(
'
SUB_USB_JS_0070
'
,
0
,
function
()
{
var
portId
=
gPort
.
id
-
1
;
var
dataRole
=
usb
.
NONE
-
1
;
var
powerRole
=
usb
.
NONE
-
1
;
usb
.
setPortRoles
(
portId
,
powerRole
,
dataRole
).
then
(
data
=>
{
var
dataRole
=
usb
Manager
.
NONE
-
1
;
var
powerRole
=
usb
Manager
.
NONE
-
1
;
usb
Manager
.
setPortRoles
(
portId
,
powerRole
,
dataRole
).
then
(
data
=>
{
console
.
info
(
'
usb 0070 case setPortRoles return:
'
+
data
);
expect
(
data
).
assertFalse
();
}).
catch
(
error
=>
{
...
...
@@ -209,7 +209,7 @@ describe('UsbPortJsFunctionsTestEx', function () {
var
portId
=
gPort
.
id
-
1
;
var
powerRole
=
1
;
var
dataRole
=
1
;
usb
.
setPortRoles
(
portId
,
powerRole
,
dataRole
).
then
(
data
=>
{
usb
Manager
.
setPortRoles
(
portId
,
powerRole
,
dataRole
).
then
(
data
=>
{
console
.
info
(
'
usb 0080 case setPortRoles return:
'
+
data
);
expect
(
data
).
assertFalse
();
}).
catch
(
error
=>
{
...
...
@@ -228,10 +228,10 @@ describe('UsbPortJsFunctionsTestEx', function () {
it
(
'
SUB_USB_JS_1410
'
,
0
,
function
()
{
console
.
info
(
'
usb SUB_USB_JS_1410 begin
'
);
var
portId
=
"
invalid
"
;
var
powerRole
=
usb
.
SINK
;
var
dataRole
=
usb
.
DEVICE
;
var
powerRole
=
usb
Manager
.
SINK
;
var
dataRole
=
usb
Manager
.
DEVICE
;
try
{
var
maskCode
=
usb
.
setPortRoles
(
portId
,
powerRole
,
dataRole
);
var
maskCode
=
usb
Manager
.
setPortRoles
(
portId
,
powerRole
,
dataRole
);
console
.
info
(
'
usb 1410 case setPortRoles return:
'
+
maskCode
);
expect
(
false
).
assertTrue
();
}
catch
(
err
)
{
...
...
@@ -249,7 +249,7 @@ describe('UsbPortJsFunctionsTestEx', function () {
it
(
'
SUB_USB_JS_1190
'
,
0
,
function
()
{
console
.
info
(
'
usb SUB_USB_JS_1190 begin
'
);
try
{
var
maskCode
=
usb
.
setPortRoles
(
"
invalid
"
);
var
maskCode
=
usb
Manager
.
setPortRoles
(
"
invalid
"
);
console
.
info
(
'
usb 1190 case setPortRoles return:
'
+
maskCode
);
expect
(
false
).
assertTrue
();
}
catch
(
err
)
{
...
...
@@ -267,7 +267,7 @@ describe('UsbPortJsFunctionsTestEx', function () {
it
(
'
SUB_USB_JS_1390
'
,
0
,
function
()
{
console
.
info
(
'
usb SUB_USB_JS_1390 begin
'
);
try
{
var
maskCode
=
usb
.
setPortRoles
();
var
maskCode
=
usb
Manager
.
setPortRoles
();
console
.
info
(
'
usb 1390 case setPortRoles return:
'
+
maskCode
);
expect
(
false
).
assertTrue
();
}
catch
(
err
)
{
...
...
@@ -286,9 +286,9 @@ describe('UsbPortJsFunctionsTestEx', function () {
console
.
info
(
'
usb SUB_USB_JS_1590 begin
'
);
var
portId
=
gPort
.
id
;
var
powerRole
=
"
invalid
"
;
var
dataRole
=
usb
.
DEVICE
;
var
dataRole
=
usb
Manager
.
DEVICE
;
try
{
var
maskCode
=
usb
.
setPortRoles
(
portId
,
powerRole
,
dataRole
);
var
maskCode
=
usb
Manager
.
setPortRoles
(
portId
,
powerRole
,
dataRole
);
console
.
info
(
'
usb 1590 case setPortRoles return:
'
+
maskCode
);
expect
(
false
).
assertTrue
();
}
catch
(
err
)
{
...
...
@@ -306,10 +306,10 @@ describe('UsbPortJsFunctionsTestEx', function () {
it
(
'
SUB_USB_JS_1600
'
,
0
,
function
()
{
console
.
info
(
'
usb SUB_USB_JS_1600 begin
'
);
var
portId
=
gPort
.
id
;
var
powerRole
=
usb
.
SINK
;
var
powerRole
=
usb
Manager
.
SINK
;
var
dataRole
=
"
invalid
"
;
try
{
var
maskCode
=
usb
.
setPortRoles
(
portId
,
powerRole
,
dataRole
);
var
maskCode
=
usb
Manager
.
setPortRoles
(
portId
,
powerRole
,
dataRole
);
console
.
info
(
'
usb 1600 case setPortRoles return:
'
+
maskCode
);
expect
(
false
).
assertTrue
();
}
catch
(
err
)
{
...
...
@@ -327,9 +327,9 @@ describe('UsbPortJsFunctionsTestEx', function () {
it
(
'
SUB_USB_JS_1610
'
,
0
,
function
()
{
console
.
info
(
'
usb SUB_USB_JS_1610 begin
'
);
var
portId
=
gPort
.
id
;
var
powerRole
=
usb
.
SINK
;
var
powerRole
=
usb
Manager
.
SINK
;
try
{
var
maskCode
=
usb
.
setPortRoles
(
portId
,
powerRole
);
var
maskCode
=
usb
Manager
.
setPortRoles
(
portId
,
powerRole
);
console
.
info
(
'
usb 1610 case setPortRoles return:
'
+
maskCode
);
expect
(
false
).
assertTrue
();
}
catch
(
err
)
{
...
...
@@ -347,7 +347,7 @@ describe('UsbPortJsFunctionsTestEx', function () {
it
(
'
SUB_USB_JS_1200
'
,
0
,
function
()
{
console
.
info
(
'
usb SUB_USB_JS_1200 begin
'
);
try
{
var
maskCode
=
usb
.
getPorts
(
"
invalid
"
);
var
maskCode
=
usb
Manager
.
getPorts
(
"
invalid
"
);
console
.
info
(
'
usb 1200 case getPorts return:
'
+
maskCode
);
expect
(
false
).
assertTrue
();
}
catch
(
err
)
{
...
...
@@ -365,7 +365,7 @@ describe('UsbPortJsFunctionsTestEx', function () {
it
(
'
SUB_USB_JS_1180
'
,
0
,
function
()
{
console
.
info
(
'
usb SUB_USB_JS_1180 begin
'
);
try
{
var
maskCode
=
usb
.
setCurrentFunctions
(
"
invalid
"
);
var
maskCode
=
usb
Manager
.
setCurrentFunctions
(
"
invalid
"
);
console
.
info
(
'
usb 1180 case setCurrentFunctions return:
'
+
maskCode
);
expect
(
false
).
assertTrue
();
}
catch
(
err
)
{
...
...
@@ -383,7 +383,7 @@ describe('UsbPortJsFunctionsTestEx', function () {
it
(
'
SUB_USB_JS_1400
'
,
0
,
function
()
{
console
.
info
(
'
usb SUB_USB_JS_1400 begin
'
);
try
{
var
maskCode
=
usb
.
setCurrentFunctions
();
var
maskCode
=
usb
Manager
.
setCurrentFunctions
();
console
.
info
(
'
usb 1400 case setCurrentFunctions return:
'
+
maskCode
);
expect
(
false
).
assertTrue
();
}
catch
(
err
)
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录