Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
OpenHarmony
Xts Acts
提交
ff96c6dc
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看板
提交
ff96c6dc
编写于
8月 02, 2023
作者:
Q
quanli
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
quanli1@huawei.com
Signed-off-by:
N
quanli
<
quanli1@huawei.com
>
上级
17032ba6
变更
57
隐藏空白更改
内联
并排
Showing
57 changed file
with
5565 addition
and
238 deletion
+5565
-238
communication/BUILD.gn
communication/BUILD.gn
+1
-0
communication/bluetooth_gatt/signature/openharmony_sx.p7b
communication/bluetooth_gatt/signature/openharmony_sx.p7b
+0
-0
communication/bluetooth_gatt/src/main/config.json
communication/bluetooth_gatt/src/main/config.json
+11
-31
communication/bluetooth_gatt/src/main/js/test/BtBleManager.test.js
...tion/bluetooth_gatt/src/main/js/test/BtBleManager.test.js
+1032
-0
communication/bluetooth_gatt/src/main/js/test/BtBleService.test.js
...tion/bluetooth_gatt/src/main/js/test/BtBleService.test.js
+372
-0
communication/bluetooth_gatt/src/main/js/test/BtGattManager.test.js
...ion/bluetooth_gatt/src/main/js/test/BtGattManager.test.js
+95
-87
communication/bluetooth_gatt/src/main/js/test/BtGattService.test.js
...ion/bluetooth_gatt/src/main/js/test/BtGattService.test.js
+8
-7
communication/bluetooth_gatt/src/main/js/test/BtManagerGattManager.test.js
...etooth_gatt/src/main/js/test/BtManagerGattManager.test.js
+34
-44
communication/bluetooth_gatt/src/main/js/test/List.test.js
communication/bluetooth_gatt/src/main/js/test/List.test.js
+7
-4
communication/bluetooth_profile/signature/openharmony_sx.p7b
communication/bluetooth_profile/signature/openharmony_sx.p7b
+0
-0
communication/bluetooth_profile/src/main/config.json
communication/bluetooth_profile/src/main/config.json
+10
-4
communication/bluetooth_profile/src/main/js/test/BtA2dp.test.js
...ication/bluetooth_profile/src/main/js/test/BtA2dp.test.js
+104
-0
communication/bluetooth_profile/src/main/js/test/BtBaseProfile.test.js
.../bluetooth_profile/src/main/js/test/BtBaseProfile.test.js
+425
-0
communication/bluetooth_profile/src/main/js/test/List.test.js
...unication/bluetooth_profile/src/main/js/test/List.test.js
+4
-0
communication/bluetooth_scanpairing/signature/openharmony_sx.p7b
...cation/bluetooth_scanpairing/signature/openharmony_sx.p7b
+0
-0
communication/bluetooth_scanpairing/src/main/config.json
communication/bluetooth_scanpairing/src/main/config.json
+18
-4
communication/bluetooth_scanpairing/src/main/js/test/BluetoothBle.test.js
...uetooth_scanpairing/src/main/js/test/BluetoothBle.test.js
+160
-0
communication/bluetooth_scanpairing/src/main/js/test/BtConnection.test.js
...uetooth_scanpairing/src/main/js/test/BtConnection.test.js
+443
-0
communication/bluetooth_scanpairing/src/main/js/test/BtPair.test.js
...ion/bluetooth_scanpairing/src/main/js/test/BtPair.test.js
+10
-11
communication/bluetooth_scanpairing/src/main/js/test/List.test.js
...ation/bluetooth_scanpairing/src/main/js/test/List.test.js
+7
-2
communication/bluetooth_standard/signature/openharmony_sx.p7b
...unication/bluetooth_standard/signature/openharmony_sx.p7b
+0
-0
communication/bluetooth_standard/src/main/config.json
communication/bluetooth_standard/src/main/config.json
+16
-32
communication/bluetooth_standard/src/main/js/test/BluetoothAccess.test.js
...uetooth_standard/src/main/js/test/BluetoothAccess.test.js
+216
-0
communication/bluetooth_standard/src/main/js/test/BluetoothConstant.test.js
...tooth_standard/src/main/js/test/BluetoothConstant.test.js
+436
-0
communication/bluetooth_standard/src/main/js/test/BtSocket.test.js
...tion/bluetooth_standard/src/main/js/test/BtSocket.test.js
+385
-0
communication/bluetooth_standard/src/main/js/test/BtSpp.test.js
...ication/bluetooth_standard/src/main/js/test/BtSpp.test.js
+8
-8
communication/bluetooth_standard/src/main/js/test/List.test.js
...nication/bluetooth_standard/src/main/js/test/List.test.js
+7
-1
communication/nfc_Controller/signature/openharmony_sx.p7b
communication/nfc_Controller/signature/openharmony_sx.p7b
+0
-0
communication/nfc_Controller/src/main/js/test/TagABFV.test.js
...unication/nfc_Controller/src/main/js/test/TagABFV.test.js
+30
-0
communication/nfc_ErrorCode/signature/openharmony_sx.p7b
communication/nfc_ErrorCode/signature/openharmony_sx.p7b
+0
-0
communication/nfc_SecureElement/BUILD.gn
communication/nfc_SecureElement/BUILD.gn
+35
-0
communication/nfc_SecureElement/Test.json
communication/nfc_SecureElement/Test.json
+28
-0
communication/nfc_SecureElement/signature/openharmony_sx.p7b
communication/nfc_SecureElement/signature/openharmony_sx.p7b
+0
-0
communication/nfc_SecureElement/src/main/config.json
communication/nfc_SecureElement/src/main/config.json
+105
-0
communication/nfc_SecureElement/src/main/js/MainAbility/app.js
...nication/nfc_SecureElement/src/main/js/MainAbility/app.js
+23
-0
communication/nfc_SecureElement/src/main/js/MainAbility/i18n/en-US.json
...nfc_SecureElement/src/main/js/MainAbility/i18n/en-US.json
+6
-0
communication/nfc_SecureElement/src/main/js/MainAbility/i18n/zh-CN.json
...nfc_SecureElement/src/main/js/MainAbility/i18n/zh-CN.json
+6
-0
communication/nfc_SecureElement/src/main/js/MainAbility/pages/index/index.css
...cureElement/src/main/js/MainAbility/pages/index/index.css
+25
-0
communication/nfc_SecureElement/src/main/js/MainAbility/pages/index/index.hml
...cureElement/src/main/js/MainAbility/pages/index/index.hml
+21
-0
communication/nfc_SecureElement/src/main/js/MainAbility/pages/index/index.js
...ecureElement/src/main/js/MainAbility/pages/index/index.js
+34
-0
communication/nfc_SecureElement/src/main/js/TestAbility/app.js
...nication/nfc_SecureElement/src/main/js/TestAbility/app.js
+31
-0
communication/nfc_SecureElement/src/main/js/TestAbility/i18n/en-US.json
...nfc_SecureElement/src/main/js/TestAbility/i18n/en-US.json
+8
-0
communication/nfc_SecureElement/src/main/js/TestAbility/i18n/zh-CN.json
...nfc_SecureElement/src/main/js/TestAbility/i18n/zh-CN.json
+8
-0
communication/nfc_SecureElement/src/main/js/TestAbility/pages/index/index.css
...cureElement/src/main/js/TestAbility/pages/index/index.css
+30
-0
communication/nfc_SecureElement/src/main/js/TestAbility/pages/index/index.hml
...cureElement/src/main/js/TestAbility/pages/index/index.hml
+5
-0
communication/nfc_SecureElement/src/main/js/TestAbility/pages/index/index.js
...ecureElement/src/main/js/TestAbility/pages/index/index.js
+26
-0
communication/nfc_SecureElement/src/main/js/TestRunner/OpenHarmonyTestRunner.js
...reElement/src/main/js/TestRunner/OpenHarmonyTestRunner.js
+59
-0
communication/nfc_SecureElement/src/main/js/test/List.test.js
...unication/nfc_SecureElement/src/main/js/test/List.test.js
+32
-0
communication/nfc_SecureElement/src/main/js/test/channelCallback.test.js
...fc_SecureElement/src/main/js/test/channelCallback.test.js
+327
-0
communication/nfc_SecureElement/src/main/js/test/newSEService.test.js
...n/nfc_SecureElement/src/main/js/test/newSEService.test.js
+208
-0
communication/nfc_SecureElement/src/main/js/test/openBasicChannel.test.js
...c_SecureElement/src/main/js/test/openBasicChannel.test.js
+263
-0
communication/nfc_SecureElement/src/main/js/test/openLogicalChannel.test.js
...SecureElement/src/main/js/test/openLogicalChannel.test.js
+267
-0
communication/nfc_SecureElement/src/main/js/test/openSession.test.js
...on/nfc_SecureElement/src/main/js/test/openSession.test.js
+148
-0
communication/nfc_SecureElement/src/main/resources/base/element/string.json
...SecureElement/src/main/resources/base/element/string.json
+28
-0
communication/nfc_SecureElement/src/main/resources/base/media/icon.png
.../nfc_SecureElement/src/main/resources/base/media/icon.png
+0
-0
communication/wifi_standard/src/main/js/test/WifiManagerCandidateNetWork.test.js
...dard/src/main/js/test/WifiManagerCandidateNetWork.test.js
+2
-2
location/geolocation_standard/src/main/js/test/LocationMTest.test.js
...olocation_standard/src/main/js/test/LocationMTest.test.js
+1
-1
未找到文件。
communication/BUILD.gn
浏览文件 @
ff96c6dc
...
@@ -27,6 +27,7 @@ group("communication") {
...
@@ -27,6 +27,7 @@ group("communication") {
"dsoftbus/rpc_request:ActsRpcRequestJsTest",
"dsoftbus/rpc_request:ActsRpcRequestJsTest",
"nfc_Controller:ActsNFCJSTest",
"nfc_Controller:ActsNFCJSTest",
"nfc_ErrorCode:ActsNFCErrorJSTest",
"nfc_ErrorCode:ActsNFCErrorJSTest",
"nfc_SecureElement:ActsnfcSEServiceTest",
"wifi_ErrorCode201:ActsErrorcode201Test",
"wifi_ErrorCode201:ActsErrorcode201Test",
"wifi_ErrorCode202:ActsErrorcode202Test",
"wifi_ErrorCode202:ActsErrorcode202Test",
"wifi_ErrorCode401:ActsErrorcode401Test",
"wifi_ErrorCode401:ActsErrorcode401Test",
...
...
communication/bluetooth_gatt/signature/openharmony_sx.p7b
浏览文件 @
ff96c6dc
无法预览此类型文件
communication/bluetooth_gatt/src/main/config.json
浏览文件 @
ff96c6dc
...
@@ -88,47 +88,27 @@
...
@@ -88,47 +88,27 @@
"reqPermissions"
:
[
"reqPermissions"
:
[
{
{
"name"
:
"ohos.permission.USE_BLUETOOTH"
,
"name"
:
"ohos.permission.USE_BLUETOOTH"
,
"reason"
:
""
,
"reason"
:
""
"usedScene"
:
{
"ability"
:
[
"ohos.acts.communication.bluetooth.bluetoothhost.MainAbility"
],
"when"
:
"inuse"
}
},
},
{
{
"name"
:
"ohos.permission.MANAGE_BLUETOOTH"
,
"name"
:
"ohos.permission.MANAGE_BLUETOOTH"
,
"reason"
:
""
,
"reason"
:
""
"usedScene"
:
{
"ability"
:
[
"ohos.acts.communication.bluetooth.bluetoothhost.MainAbility"
],
"when"
:
"inuse"
}
},
},
{
{
"name"
:
"ohos.permission.DISCOVER_BLUETOOTH"
,
"name"
:
"ohos.permission.DISCOVER_BLUETOOTH"
,
"reason"
:
""
,
"reason"
:
""
"usedScene"
:
{
"ability"
:
[
"ohos.acts.communication.bluetooth.bluetoothhost.MainAbility"
],
"when"
:
"inuse"
}
},
},
{
{
"name"
:
"ohos.permission.
GRANT_SENSITIVE_PERMISSIONS
"
,
"name"
:
"ohos.permission.
LOCATION
"
,
"reason"
:
"
use ohos.permission.GRANT_SENSITIVE_PERMISSIONS
"
"reason"
:
""
},
},
{
{
"name"
:
"ohos.permission.LOCATION"
,
"name"
:
"ohos.permission.ACCESS_BLUETOOTH"
,
"reason"
:
""
,
"reason"
:
""
"usedScene"
:
{
},
"ability"
:
[
{
"ohos.acts.communication.bluetooth.bluetoothhost.MainAbility"
"name"
:
"ohos.permission.GRANT_SENSITIVE_PERMISSIONS"
,
],
"reason"
:
""
"when"
:
"inuse"
}
},
},
{
{
"name"
:
"ohos.permission.REVOKE_SENSITIVE_PERMISSIONS"
,
"name"
:
"ohos.permission.REVOKE_SENSITIVE_PERMISSIONS"
,
...
...
communication/bluetooth_gatt/src/main/js/test/BtBleManager.test.js
0 → 100644
浏览文件 @
ff96c6dc
/*
* Copyright (C) 2022 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import
bluetooth
from
'
@ohos.bluetooth.ble
'
;
import
btAccess
from
'
@ohos.bluetooth.access
'
;
import
{
describe
,
beforeAll
,
beforeEach
,
afterEach
,
afterAll
,
it
,
expect
}
from
'
@ohos/hypium
'
export
default
function
btBleManagerTest
()
{
describe
(
'
btBleManagerTest
'
,
function
()
{
let
gattServer
=
null
;
let
gattClient
=
null
;
function
sleep
(
delay
)
{
return
new
Promise
(
resovle
=>
setTimeout
(
resovle
,
delay
))
}
async
function
tryToEnableBt
()
{
let
sta
=
btAccess
.
getState
();
switch
(
sta
){
case
0
:
console
.
info
(
'
[bluetooth_js] bt turn off:
'
+
JSON
.
stringify
(
sta
));
btAccess
.
enableBluetooth
();
await
sleep
(
10000
);
break
;
case
1
:
console
.
info
(
'
[bluetooth_js] bt turning on:
'
+
JSON
.
stringify
(
sta
));
await
sleep
(
3000
);
break
;
case
2
:
console
.
info
(
'
[bluetooth_js] bt turn on:
'
+
JSON
.
stringify
(
sta
));
break
;
case
3
:
console
.
info
(
'
[bluetooth_js] bt turning off:
'
+
JSON
.
stringify
(
sta
));
btAccess
.
enableBluetooth
();
await
sleep
(
10000
);
break
;
default
:
console
.
info
(
'
[bluetooth_js] enable success
'
);
}
}
beforeAll
(
async
function
(
done
)
{
console
.
info
(
'
beforeAll called
'
)
gattServer
=
bluetooth
.
createGattServer
();
console
.
info
(
'
bluetooth ble create gattserver result:
'
+
gattServer
);
gattClient
=
bluetooth
.
createGattClientDevice
(
'
04:30:02:01:00:07
'
);
console
.
info
(
'
bluetooth ble create gattclientdevice result:
'
+
gattClient
);
done
();
})
beforeEach
(
async
function
(
done
)
{
console
.
info
(
'
beforeEach called
'
)
await
tryToEnableBt
()
done
();
})
afterEach
(
function
()
{
console
.
info
(
'
afterEach called
'
)
})
afterAll
(
async
function
(
done
)
{
console
.
info
(
'
afterAll called
'
)
gattClient
.
close
();
done
();
})
/**
* @tc.number SUB_COMMUNICATION_BLUETOOTHBLE_GATTADVERT_0100
* @tc.name testStartAdvertising
* @tc.desc Test StartAdvertising api10.
* @tc.type Function
* @tc.level Level 0
*/
it
(
'
SUB_COMMUNICATION_BLUETOOTHBLE_GATTADVERT_0100
'
,
0
,
async
function
(
done
)
{
let
manufactureValueBuffer
=
new
Uint8Array
(
4
);
manufactureValueBuffer
[
0
]
=
1
;
manufactureValueBuffer
[
1
]
=
2
;
manufactureValueBuffer
[
2
]
=
3
;
manufactureValueBuffer
[
3
]
=
4
;
let
serviceValueBuffer
=
new
Uint8Array
(
4
);
serviceValueBuffer
[
0
]
=
4
;
serviceValueBuffer
[
1
]
=
6
;
serviceValueBuffer
[
2
]
=
7
;
serviceValueBuffer
[
3
]
=
8
;
let
setting
=
{
interval
:
32
,
txPower
:
1
,
connectable
:
true
,
}
let
advData
=
{
serviceUuids
:[
"
00001888-0000-1000-8000-00805f9b34fb
"
],
manufactureData
:[{
manufactureId
:
4567
,
manufactureValue
:
manufactureValueBuffer
.
buffer
}],
serviceData
:[{
serviceUuid
:
"
00001888-0000-1000-8000-00805f9b34fb
"
,
serviceValue
:
serviceValueBuffer
.
buffer
}],
includeDeviceName
:
false
}
let
advResponse
=
{
serviceUuids
:[
"
00001889-0000-1000-8000-00805f9b34fb
"
],
manufactureData
:[{
manufactureId
:
1789
,
manufactureValue
:
manufactureValueBuffer
.
buffer
}],
serviceData
:[{
serviceUuid
:
"
00001889-0000-1000-8000-00805f9b34fb
"
,
serviceValue
:
serviceValueBuffer
.
buffer
}],
}
try
{
bluetooth
.
startAdvertising
(
setting
,
advData
,
advResponse
);
console
.
info
(
'
[bluetooth_js]startAdvertising1 success
'
);
bluetooth
.
stopAdvertising
();
}
catch
(
error
)
{
console
.
error
(
`[bluetooth_js]startAdvertising1 failed, code is
${
error
.
code
}
,message is
${
error
.
message
}
`
);
expect
(
error
.
code
).
assertEqual
(
'
2900099
'
);
}
done
();
})
/**
* @tc.number SUB_COMMUNICATION_BLUETOOTHBLE_GATTCONNECT_0100
* @tc.name test gatt connect and disconnect
* @tc.desc Test api10.
* @tc.type Function
* @tc.level Level 2
*/
it
(
'
SUB_COMMUNICATION_BLUETOOTHBLE_GATTCONNECT_0100
'
,
0
,
async
function
(
done
)
{
try
{
gattClient
.
connect
();
await
sleep
(
2000
);
gattClient
.
disconnect
();
}
catch
(
error
)
{
console
.
error
(
`[bluetooth_js]disconnect failed, code is
${
error
.
code
}
,message is
${
error
.
message
}
`
);
expect
(
error
.
code
).
assertEqual
(
'
2900099
'
);
}
done
();
})
/**
* @tc.number SUB_COMMUNICATION_BLUETOOTHBLE_GATTCONNECT_0200
* @tc.name testGetConnectedBLEDevices
* @tc.desc Test api10.
* @tc.type Function
* @tc.level Level 2
*/
it
(
'
SUB_COMMUNICATION_BLUETOOTHBLE_GATTCONNECT_0200
'
,
0
,
function
()
{
try
{
let
result
=
bluetooth
.
getConnectedBLEDevices
();
console
.
info
(
"
[bluetooth_js] getConnDev:
"
+
JSON
.
stringify
(
result
)
+
"
length:
"
+
result
.
length
);
expect
(
true
).
assertTrue
(
result
.
length
>
0
);
}
catch
(
error
)
{
console
.
error
(
`[bluetooth_js]getConnDev failed, code is
${
error
.
code
}
,message is
${
error
.
message
}
`
);
expect
(
error
.
code
).
assertEqual
(
'
2900099
'
);
}
})
/**
* @tc.number SUB_COMMUNICATION_BLUETOOTHBLE_GATTCONNECT_0300
* test Client BLEconnectStateChange
* @tc.desc Test on and off api10
* @tc.type Function
* @tc.level Level 2
*/
it
(
'
SUB_COMMUNICATION_BLUETOOTHBLE_GATTCONNECT_0300
'
,
0
,
async
function
(
done
)
{
try
{
function
ConnectStateChanged
(
state
)
{
console
.
log
(
'
bluetooth connect state changed
'
);
let
connectState
=
state
.
state
;
console
.
info
(
'
[bluetooth_js] state changed
'
+
connectState
)
expect
(
true
).
assertEqual
(
connectState
!=
null
);
}
gattClient
.
on
(
'
BLEConnectionStateChange
'
,
ConnectStateChanged
);
gattClient
.
off
(
"
BLEConnectionStateChange
"
);
done
();
}
catch
(
error
)
{
console
.
error
(
`[bluetooth_js]GattConnect failed, code is
${
error
.
code
}
,message is
${
error
.
message
}
`
);
expect
(
error
.
code
).
assertEqual
(
'
2900099
'
);
}
})
/**
* @tc.number SUB_COMMUNICATION_BLUETOOTHBLE_GETRSSIVALUE_0100
* @tc.name testgetRssiValue
* @tc.desc Test getRssiValue api10 by promise.
* @tc.type Function
* @tc.level Level 2
*/
it
(
'
SUB_COMMUNICATION_BLUETOOTHBLE_GETRSSIVALUE_0100
'
,
0
,
async
function
(
done
)
{
try
{
await
gattClient
.
getRssiValue
().
then
((
data
)
=>
{
console
.
info
(
'
[bluetooth_js] BLE read rssi:
'
+
JSON
.
stringify
(
data
));
expect
(
true
).
assertEqual
(
data
!=
null
);
done
();
}).
catch
(
err
=>
{
console
.
info
(
'
bluetooth getRssiValue has error:
'
+
JSON
.
stringify
(
err
));
// expect(true).assertEqual(error.code==2900099||error.code==-1);
let
b
=
false
;
if
(
err
.
code
==
2900099
||
err
.
code
==-
1
)
{
b
=
true
}
expect
(
true
).
assertEqual
(
b
);
done
();
});
}
catch
(
error
)
{
console
.
error
(
`[bluetooth_js]GetRssiValue error, code is
${
error
.
code
}
,message is
${
error
.
message
}
`
);
expect
(
error
.
code
).
assertEqual
(
'
2900099
'
);
}
done
();
})
/**
* @tc.number SUB_COMMUNICATION_BLUETOOTHBLE_GETRSSIVALUE_0200
* @tc.name testgetRssiValue
* @tc.desc Test testGetDeviceName api10 by callback.
* @tc.type Function
* @tc.level Level 2
*/
it
(
'
SUB_COMMUNICATION_BLUETOOTHBLE_GETRSSIVALUE_0200
'
,
0
,
async
function
(
done
)
{
try
{
function
getRssi
()
{
return
new
Promise
((
resolve
,
reject
)
=>
{
gattClient
.
getRssiValue
((
err
,
data
)
=>
{
if
(
err
)
{
console
.
error
(
'
getRssi failed
'
);
let
b
=
false
;
if
(
err
.
code
==
2900099
||
err
.
code
==-
1
)
{
b
=
true
}
expect
(
true
).
assertEqual
(
b
);
}
else
{
console
.
info
(
'
[bluetooth_js]getRssi value:
'
+
JSON
.
stringify
(
data
));
expect
(
true
).
assertEqual
(
data
!=
null
);
}
resolve
();
});
});
}
await
getRssi
();
}
catch
(
error
)
{
console
.
error
(
`[bluetooth_js]GetRssiValue error, code is
${
error
.
code
}
,message is
${
error
.
message
}
`
);
expect
(
error
.
code
).
assertEqual
(
'
2900099
'
);
}
await
sleep
(
2000
);
done
();
})
/**
* @tc.number SUB_COMMUNICATION_BLUETOOTHBLE_GETDEVICENAME_0100
* @tc.name testGetDeviceName
* @tc.desc Test GetDeviceName api10 by promise.
* @tc.type Function
* @tc.level Level 2
*/
it
(
'
SUB_COMMUNICATION_BLUETOOTHBLE_GETDEVICENAME_0100
'
,
0
,
async
function
(
done
)
{
try
{
await
gattClient
.
getDeviceName
().
then
((
data
)
=>
{
console
.
info
(
'
[bluetooth_js] device name:
'
+
JSON
.
stringify
(
data
))
expect
(
true
).
assertEqual
(
data
!=
null
);
done
();
}).
catch
(
err
=>
{
console
.
error
(
'
[bluetooth_js] bluetooth getDeviceName has error:
'
+
JSON
.
stringify
(
err
));
expect
(
err
.
code
).
assertEqual
(
2900099
);
});
}
catch
(
error
)
{
console
.
error
(
`[bluetooth_js]GetDeviceName failed, code is
${
error
.
code
}
,message is
${
error
.
message
}
`
);
expect
(
error
.
code
).
assertEqual
(
'
2900099
'
);
}
done
();
})
/**
* @tc.number SUB_COMMUNICATION_BLUETOOTHBLE_GETDEVICENAME_0200
* @tc.name testGetDeviceName
* @tc.desc Test testGetDeviceName api10 by callback.
* @tc.type Function
* @tc.level Level 2
*/
it
(
'
SUB_COMMUNICATION_BLUETOOTHBLE_GETDEVICENAME_0200
'
,
0
,
async
function
(
done
)
{
try
{
gattClient
.
getDeviceName
((
err
,
data
)
=>
{
if
(
err
)
{
console
.
error
(
'
getname1 failed
'
);
}
console
.
info
(
'
[bluetooth_js]getname value:
'
+
JSON
.
stringify
(
data
));
expect
(
true
).
assertEqual
(
data
!=
null
);
});
await
sleep
(
2000
);
done
();
}
catch
(
error
)
{
console
.
error
(
`[bluetooth_js]GetDeviceName failed, code is
${
error
.
code
}
,message is
${
error
.
message
}
`
);
expect
(
error
.
code
).
assertEqual
(
'
2900099
'
);
}
done
();
})
/**
* @tc.number SUB_COMMUNICATION_BLUETOOTHBLE_GETSERVICE_0100
* @tc.name testGetServices
* @tc.desc Test GetServices api10 by promise.
* @tc.type Function
* @tc.level Level 3
*/
it
(
'
SUB_COMMUNICATION_BLUETOOTHBLE_GETSERVICE_0100
'
,
0
,
async
function
(
done
)
{
try
{
await
gattClient
.
getServices
().
then
((
GattService
)
=>
{
console
.
info
(
'
[bluetooth_js] getServices successfully:
'
+
JSON
.
stringify
(
GattService
));
expect
(
GattService
).
assertNull
();
done
();
}).
catch
(
err
=>
{
console
.
error
(
'
[bluetooth_js] getServices has error:
'
+
JSON
.
stringify
(
err
));
expect
(
true
).
assertEqual
(
true
);
done
();
});
}
catch
(
error
)
{
console
.
error
(
`[bluetooth_js]GetService_0100 failed, code is
${
error
.
code
}
,message is
${
error
.
message
}
`
);
expect
(
error
.
code
).
assertEqual
(
'
2900099
'
);
}
done
();
})
/**
* @tc.number SUB_COMMUNICATION_BLUETOOTHBLE_GETSERVICE_0200
* @tc.name testGetServices
* @tc.desc Test GetServices api10 by callback.
* @tc.type Function
* @tc.level Level 3
*/
it
(
'
SUB_COMMUNICATION_BLUETOOTHBLE_GETSERVICE_0200
'
,
0
,
async
function
(
done
)
{
try
{
gattClient
.
getServices
((
code
,
data
)
=>
{
if
(
code
.
code
==
0
){
console
.
info
(
"
bluetooth services size is
"
,
data
.
length
)
expect
(
true
).
assertEqual
(
data
.
length
>=
0
);
}
else
{
console
.
info
(
'
[bluetooth_js] get services code
'
+
JSON
.
stringify
(
code
));
expect
(
true
).
assertEqual
(
code
.
code
==
-
1
);
}
});
done
();
}
catch
(
error
)
{
console
.
error
(
`[bluetooth_js]GetService_0200 failed, code is
${
error
.
code
}
,message is
${
error
.
message
}
`
);
expect
(
error
.
code
).
assertEqual
(
'
2900099
'
);
}
done
();
})
/**
* @tc.number SUB_COMMUNICATION_BLUETOOTHBLE_MTUSIZE_0100
* @tc.name testSetBLEMtuSize
* @tc.desc Test SetBLEMtuSize api10.
* @tc.type Function
* @tc.level Level 1
*/
it
(
'
SUB_COMMUNICATION_BLUETOOTHBLE_MTUSIZE_0100
'
,
0
,
function
(
done
)
{
try
{
gattClient
.
setBLEMtuSize
(
500
);
console
.
info
(
"
[bluetooth_js]setBLEMtuSize success
"
);
}
catch
(
error
)
{
console
.
error
(
`[bluetooth_js]MtuSize failed, code is
${
error
.
code
}
,message is
${
error
.
message
}
`
);
expect
(
error
.
code
).
assertEqual
(
'
2900099
'
);
}
done
();
})
/**
* @tc.number SUB_COMMUNICATION_BLUETOOTHBLE_READCHARACTERISTIC_1900
* @tc.name testReadDescriptorValue
* @tc.desc Test ReadDescriptorValue api10 by promise.
* @tc.type Function
* @tc.level Level 2
*/
it
(
'
SUB_COMMUNICATION_BLUETOOTHBLE_READCHARACTERISTIC_1900
'
,
0
,
async
function
(
done
)
{
let
descriptors
=
[];
let
bufferDesc
=
new
ArrayBuffer
(
8
);
let
descV
=
new
Uint8Array
(
bufferDesc
);
descV
[
0
]
=
11
;
let
descriptor
=
{
serviceUuid
:
'
00001810-0000-1000-8000-00805F9B34FB
'
,
characteristicUuid
:
'
00001820-0000-1000-8000-00805F9B34FB
'
,
descriptorUuid
:
'
00002903-0000-1000-8000-00805F9B34FB
'
,
descriptorValue
:
bufferDesc
};
descriptors
[
0
]
=
descriptor
;
let
bufferCCC
=
new
ArrayBuffer
(
8
);
let
cccV
=
new
Uint8Array
(
bufferCCC
);
cccV
[
0
]
=
1
;
let
characteristic
=
{
serviceUuid
:
'
00001810-0000-1000-8000-00805F9B34FB
'
,
characteristicUuid
:
'
00001820-0000-1000-8000-00805F9B34FB
'
,
characteristicValue
:
bufferCCC
,
descriptors
:
descriptors
};
try
{
gattClient
.
readCharacteristicValue
(
characteristic
);
done
();
}
catch
(
error
)
{
console
.
error
(
`[bluetooth_js]readDescrValue failed, code is
${
error
.
code
}
,message is
${
error
.
message
}
`
);
expect
(
error
.
code
).
assertEqual
(
'
401
'
);
}
done
();
})
/**
* @tc.number SUB_COMMUNICATION_BLUETOOTHBLE_READCHARACTERISTIC_2000
* @tc.name testReadDescriptorValue
* @tc.desc Test ReadDescriptorValue api10 by callback.
* @tc.type Function
* @tc.level Level 2
*/
it
(
'
SUB_COMMUNICATION_BLUETOOTHBLE_READCHARACTERISTIC_2000
'
,
0
,
async
function
(
done
)
{
function
readCcc
(
code
,
BLECharacteristic
)
{
if
(
code
.
code
!=
0
)
{
return
;
}
console
.
log
(
'
bluetooth characteristic uuid:
'
+
BLECharacteristic
.
characteristicUuid
);
let
value
=
new
Uint8Array
(
BLECharacteristic
.
characteristicValue
);
console
.
log
(
'
bluetooth characteristic value:
'
+
value
[
0
]
+
'
,
'
+
value
[
1
]
+
'
,
'
+
value
[
2
]
+
'
,
'
+
value
[
3
]);
}
let
descriptors
=
[];
let
bufferDesc
=
new
ArrayBuffer
(
8
);
let
descV
=
new
Uint8Array
(
bufferDesc
);
descV
[
0
]
=
11
;
let
descriptor
=
{
serviceUuid
:
'
00001810-0000-1000-8000-00805F9B34FB
'
,
characteristicUuid
:
'
00001820-0000-1000-8000-00805F9B34FB
'
,
descriptorUuid
:
'
00002903-0000-1000-8000-00805F9B34FB
'
,
descriptorValue
:
bufferDesc
};
descriptors
[
0
]
=
descriptor
;
let
bufferCCC
=
new
ArrayBuffer
(
8
);
let
cccV
=
new
Uint8Array
(
bufferCCC
);
cccV
[
0
]
=
1
;
let
characteristic
=
{
serviceUuid
:
'
00001810-0000-1000-8000-00805F9B34FB
'
,
characteristicUuid
:
'
00001820-0000-1000-8000-00805F9B34FB
'
,
characteristicValue
:
bufferCCC
,
descriptors
:
descriptors
};
try
{
gattClient
.
readCharacteristicValue
(
characteristic
,
readCcc
);
done
();
}
catch
(
error
)
{
console
.
error
(
`[bluetooth_js]readCharacteristicValue failed, code is
${
error
.
code
}
,message is
${
error
.
message
}
`
);
expect
(
error
.
code
).
assertEqual
(
'
401
'
);
}
done
();
})
/**
* @tc.number SUB_COMMUNICATION_BLUETOOTHBLE_READCHARACTERISTIC_2100
* @tc.name test characteristicReadOn
* @tc.desc Test On and off api10.
* @tc.type Function
* @tc.level Level 3
*/
it
(
'
SUB_COMMUNICATION_BLUETOOTHBLE_READCHARACTERISTIC_2100
'
,
0
,
async
function
(
done
)
{
let
arrayBufferCCC
=
new
ArrayBuffer
(
8
);
let
cccValue
=
new
Uint8Array
(
arrayBufferCCC
);
cccValue
[
0
]
=
1123
;
function
ReadCharacteristicReq
(
CharacteristicReadRequest
)
{
let
deviceId
=
CharacteristicReadRequest
.
deviceId
;
let
transId
=
CharacteristicReadRequest
.
transId
;
let
offset
=
CharacteristicReadRequest
.
offset
;
let
characteristicUuid
=
CharacteristicReadRequest
.
characteristicUuid
;
let
serverResponse
=
{
deviceId
:
deviceId
,
transId
:
transId
,
status
:
0
,
offset
:
offset
,
value
:
arrayBufferCCC
};
try
{
gattServer
.
sendResponse
(
serverResponse
);
}
catch
(
err
)
{
console
.
error
(
"
sendResponese errCode:
"
+
err
.
code
+
"
,errMessage:
"
+
err
.
message
);
}
}
try
{
await
gattServer
.
on
(
"
characteristicRead
"
,
ReadCharacteristicReq
);
done
();
}
catch
(
err
)
{
console
.
error
(
"
characteristicReadOn errCode:
"
+
err
.
code
+
"
,errMessage:
"
+
err
.
message
);
expect
(
error
.
code
).
assertEqual
(
'
2900099
'
);
}
gattServer
.
off
(
"
characteristicRead
"
);
done
();
})
/**
* @tc.number SUB_COMMUNICATION_BLUETOOTHBLE_READDESCRIPTOR_1300
* @tc.name testReadDescriptorValue
* @tc.desc Test ReadDescriptorValue api10 by promise.
* @tc.type Function
* @tc.level Level 2
*/
it
(
'
SUB_COMMUNICATION_BLUETOOTHBLE_READDESCRIPTOR_1300
'
,
0
,
async
function
(
done
)
{
let
bufferDesc
=
new
ArrayBuffer
(
8
);
let
descV
=
new
Uint8Array
(
bufferDesc
);
descV
[
0
]
=
11
;
let
descriptor
=
{
serviceUuid
:
'
00001810-0000-1000-8000-00805F9B34FB
'
,
characteristicUuid
:
'
00001820-0000-1000-8000-00805F9B34FB
'
,
descriptorUuid
:
'
00002903-0000-1000-8000-00805F9B34FB
'
,
descriptorValue
:
bufferDesc
};
try
{
gattClient
.
readDescriptorValue
(
descriptor
);
expect
(
true
).
assertFalse
();
done
();
}
catch
(
err
)
{
console
.
error
(
"
errCode:
"
+
err
.
code
+
"
,errMessage:
"
+
err
.
message
);
expect
(
err
.
code
).
assertEqual
(
'
401
'
);
done
();
}
})
/**
* @tc.number SUB_COMMUNICATION_BLUETOOTHBLE_READDESCRIPTOR_1400
* @tc.name testReadDescriptorValue
* @tc.desc Test ReadDescriptorValue api10 by callback.
* @tc.type Function
* @tc.level Level 2
*/
it
(
'
SUB_COMMUNICATION_BLUETOOTHBLE_READDESCRIPTOR_1400
'
,
0
,
async
function
(
done
)
{
function
readDesc
(
code
,
BLEDescriptor
)
{
if
(
code
.
code
!=
0
)
{
return
;
}
console
.
log
(
'
bluetooth descriptor uuid:
'
+
BLEDescriptor
.
descriptorUuid
);
let
value
=
new
Uint8Array
(
BLEDescriptor
.
descriptorValue
);
console
.
log
(
'
bluetooth descriptor value:
'
+
value
[
0
]
+
'
,
'
+
value
[
1
]
+
'
,
'
+
value
[
2
]
+
'
,
'
+
value
[
3
]);
}
let
bufferDesc
=
new
ArrayBuffer
(
8
);
let
descV
=
new
Uint8Array
(
bufferDesc
);
descV
[
0
]
=
11
;
let
descriptor
=
{
serviceUuid
:
'
00001810-0000-1000-8000-00805F9B34FB
'
,
characteristicUuid
:
'
00001820-0000-1000-8000-00805F9B34FB
'
,
descriptorUuid
:
'
00002903-0000-1000-8000-00805F9B34FB
'
,
descriptorValue
:
bufferDesc
};
try
{
gattClient
.
readDescriptorValue
(
descriptor
,
readDesc
);
expect
(
true
).
assertFalse
();
done
();
}
catch
(
err
)
{
console
.
error
(
"
errCode:
"
+
err
.
code
+
"
,errMessage:
"
+
err
.
message
);
expect
(
err
.
code
).
assertEqual
(
'
401
'
);
done
();
}
})
/**
* @tc.number SUB_COMMUNICATION_BLUETOOTHBLE_READDESCRIPTOR_1500
* @tc.name test ReadDescriptorOn
* @tc.desc Test On and Off api10.
* @tc.type Function
* @tc.level Level 3
*/
it
(
'
SUB_COMMUNICATION_BLUETOOTHBLE_READDESCRIPTOR_1500
'
,
0
,
async
function
(
done
)
{
try
{
let
arrayBufferCCC
=
new
ArrayBuffer
(
8
);
let
cccValue
=
new
Uint8Array
(
arrayBufferCCC
);
cccValue
[
0
]
=
1011
;
function
ReadDescriptorReq
(
DescriptorReadReq
)
{
let
deviceId
=
DescriptorReadReq
.
deviceId
;
let
transId
=
DescriptorReadReq
.
transId
;
let
offset
=
DescriptorReadReq
.
offset
;
let
characteristicUuid
=
DescriptorReadReq
.
characteristicUuid
;
let
serverResponse
=
{
deviceId
:
deviceId
,
transId
:
transId
,
status
:
0
,
offset
:
offset
,
value
:
arrayBufferCCC
};
gattServer
.
sendResponse
(
serverResponse
);
console
.
info
(
"
[bluetooth_js] DesRedon jsondata:
"
+
'
deviceId:
'
+
deviceId
+
'
transId:
'
+
transId
+
'
offset:
'
+
offset
+
'
descriptorUuid:
'
+
DescriptorReadReq
.
descriptorUuid
+
'
characteristicUuid:
'
+
characteristicUuid
+
'
serviceUuid:
'
+
DescriptorReadReq
.
serviceUuid
);
expect
(
true
).
assertEqual
(
DescriptorReadReq
!=
null
);
}
await
gattServer
.
on
(
"
descriptorRead
"
,
ReadDescriptorReq
);
await
gattServer
.
off
(
"
descriptorRead
"
);
}
catch
(
error
)
{
console
.
error
(
`[bluetooth_js]readDescrValue failed, code is
${
error
.
code
}
,message is
${
error
.
message
}
`
);
expect
(
error
.
code
).
assertEqual
(
'
2900099
'
);
}
done
();
})
/**
* @tc.number SUB_COMMUNICATION_BLUETOOTHBLE_WRITECHARACTERISTIC_1800
* @tc.name testWriteCharacteristicValue callback
* @tc.desc Test Client WriteCharacteristicValue api10.
* @tc.type Function
* @tc.level Level 2
*/
it
(
'
SUB_COMMUNICATION_BLUETOOTHBLE_WRITECHARACTERISTIC_1800
'
,
0
,
function
()
{
try
{
let
descriptors
=
[];
let
arrayBuffer
=
new
ArrayBuffer
(
8
);
let
desValue
=
new
Uint8Array
(
arrayBuffer
);
desValue
[
0
]
=
11
;
let
descriptor
=
{
serviceUuid
:
'
00001810-0000-1000-8000-00805F9B34FB
'
,
characteristicUuid
:
'
00001820-0000-1000-8000-00805F9B34FB
'
,
descriptorUuid
:
'
00001830-0000-1000-8000-00805F9B34FB
'
,
descriptorValue
:
arrayBuffer
};
descriptors
[
0
]
=
descriptor
;
let
arrayBufferCCC
=
new
ArrayBuffer
(
8
);
let
cccValue
=
new
Uint8Array
(
arrayBufferCCC
);
cccValue
[
0
]
=
32
;
let
characteristic
=
{
serviceUuid
:
'
00001810-0000-1000-8000-00805F9B34FB
'
,
characteristicUuid
:
'
00001820-0000-1000-8000-00805F9B34FB
'
,
characteristicValue
:
arrayBufferCCC
,
descriptors
:
descriptors
};
gattClient
.
writeCharacteristicValue
(
characteristic
,
bluetooth
.
GattWriteType
.
WRITE
,
(
err
,
data
)
=>
{
console
.
info
(
'
writeCharacteristicValue err:
'
+
JSON
.
stringify
(
err
)
+
'
,writeCharacteristicValue data:
'
+
JSON
.
stringify
(
data
));
});
}
catch
(
error
)
{
console
.
error
(
`[bluetooth_js]writeCharacteristicValue failed, code is
${
error
.
code
}
,message is
${
error
.
message
}
`
);
expect
(
error
.
code
).
assertEqual
(
'
401
'
);
}
})
/**
* @tc.number SUB_COMMUNICATION_BLUETOOTHBLE_WRITECHARACTERISTIC_1900
* @tc.name testWriteCharacteristicValue promise
* @tc.desc Test Client WriteCharacteristicValue api10.
* @tc.type Function
* @tc.level Level 2
*/
it
(
'
SUB_COMMUNICATION_BLUETOOTHBLE_WRITECHARACTERISTIC_1900
'
,
0
,
function
()
{
try
{
let
descriptors
=
[];
let
arrayBuffer
=
new
ArrayBuffer
(
8
);
let
desValue
=
new
Uint8Array
(
arrayBuffer
);
desValue
[
0
]
=
11
;
let
descriptor
=
{
serviceUuid
:
'
00001810-0000-1000-8000-00805F9B34FB
'
,
characteristicUuid
:
'
00001820-0000-1000-8000-00805F9B34FB
'
,
descriptorUuid
:
'
00001830-0000-1000-8000-00805F9B34FB
'
,
descriptorValue
:
arrayBuffer
};
descriptors
[
0
]
=
descriptor
;
let
arrayBufferCCC
=
new
ArrayBuffer
(
8
);
let
cccValue
=
new
Uint8Array
(
arrayBufferCCC
);
cccValue
[
0
]
=
32
;
let
characteristic
=
{
serviceUuid
:
'
00001810-0000-1000-8000-00805F9B34FB
'
,
characteristicUuid
:
'
00001820-0000-1000-8000-00805F9B34FB
'
,
characteristicValue
:
arrayBufferCCC
,
descriptors
:
descriptors
};
gattClient
.
writeCharacteristicValue
(
characteristic
,
bluetooth
.
GattWriteType
.
WRITE_NO_RESPONSE
).
then
(()
=>
{
console
.
info
(
"
writeCharacteristicValue
"
);
},
err
=>
{
console
.
error
(
"
writeCharacteristicValue:errCode
"
+
err
.
code
+
"
,errMessage:
"
+
err
.
message
);
});
}
catch
(
error
)
{
console
.
error
(
`[bluetooth_js]writeCharacteristicValue failed, code is
${
error
.
code
}
,message is
${
error
.
message
}
`
);
expect
(
error
.
code
).
assertEqual
(
'
401
'
);
}
})
/**
* @tc.number SUB_COMMUNICATION_BLUETOOTHBLE_WRITECHARACTERISTIC_2000
* @tc.name test characteristicWriteOn
* @tc.desc Test on and off api10.
* @tc.type Function
* @tc.level Level 3
*/
it
(
'
SUB_COMMUNICATION_BLUETOOTHBLE_WRITECHARACTERISTIC_2000
'
,
0
,
async
function
(
done
)
{
try
{
let
arrayBufferCCC
=
new
ArrayBuffer
(
8
);
let
cccValue
=
new
Uint8Array
(
arrayBufferCCC
);
function
WriteCharacteristicReq
(
CharacteristicWriteRequest
)
{
let
deviceId
=
CharacteristicWriteRequest
.
deviceId
;
let
transId
=
CharacteristicWriteRequest
.
transId
;
let
offset
=
CharacteristicWriteRequest
.
offset
;
let
isPrepared
=
CharacteristicWriteRequest
.
isPrepared
;
let
needRsp
=
CharacteristicWriteRequest
.
needRsp
;
let
value
=
new
Uint8Array
(
CharacteristicWriteRequest
.
value
);
let
characteristicUuid
=
CharacteristicWriteRequest
.
characteristicUuid
;
let
serviceUuid
=
CharacteristicWriteRequest
.
serviceUuid
;
console
.
info
(
'
CharacteristicWriteRequest deviceId:
'
+
deviceId
);
console
.
info
(
'
CharacteristicWriteRequest transId:
'
+
transId
);
console
.
info
(
'
CharacteristicWriteRequest offset:
'
+
offset
);
console
.
info
(
'
CharacteristicWriteRequest isPrepared:
'
+
isPrepared
);
console
.
info
(
'
CharacteristicWriteRequest needRsp:
'
+
needRsp
);
console
.
info
(
'
CharacteristicWriteRequest value:
'
+
value
);
console
.
info
(
'
CharacteristicWriteRequest characteristicUuid:
'
+
characteristicUuid
);
console
.
info
(
'
CharacteristicWriteRequest serviceUuid:
'
+
serviceUuid
);
cccValue
[
0
]
=
value
[
0
];
let
serverResponse
=
{
deviceId
:
deviceId
,
transId
:
transId
,
status
:
0
,
offset
:
offset
,
value
:
arrayBufferCCC
};
gattServer
.
sendResponse
(
serverResponse
);
}
gattServer
.
on
(
"
characteristicWrite
"
,
WriteCharacteristicReq
);
gattServer
.
off
(
"
characteristicWrite
"
);
}
catch
(
error
)
{
console
.
error
(
`[bluetooth_js]writeCharacteristicValue failed, code is
${
error
.
code
}
,message is
${
error
.
message
}
`
);
expect
(
error
.
code
).
assertEqual
(
'
2900099
'
);
}
done
();
})
/**
* @tc.number SUB_COMMUNICATION_BLUETOOTHBLE_WRITEDESCRIPTOR_1000
* @tc.name testWriteDescriptorValue
* @tc.desc Test Client WriteDescriptorValue promsie api10.
* @tc.type Function
* @tc.level Level 2
*/
it
(
'
SUB_COMMUNICATION_BLUETOOTHBLE_WRITEDESCRIPTOR_1000
'
,
0
,
function
()
{
let
bufferDesc
=
new
ArrayBuffer
(
8
);
let
descV
=
new
Uint8Array
(
bufferDesc
);
descV
[
0
]
=
22
;
let
descriptor
=
{
serviceUuid
:
'
00001810-0000-1000-8000-00805F9B34FB
'
,
characteristicUuid
:
'
00001820-0000-1000-8000-00805F9B34FB
'
,
descriptorUuid
:
'
00002903-0000-1000-8000-00805F9B34FB
'
,
descriptorValue
:
bufferDesc
};
try
{
gattClient
.
writeDescriptorValue
(
descriptor
).
then
(()
=>
{
console
.
info
(
"
writeDescriptorValue
"
);
},
err
=>
{
console
.
error
(
"
writeDescriptorValue:errCode
"
+
err
.
code
+
"
,errMessage:
"
+
err
.
message
);
});
}
catch
(
error
)
{
console
.
error
(
`[bluetooth_js]writeDescriptorValue failed, code is
${
error
.
code
}
,
message is
${
error
.
message
}
`
);
expect
(
error
.
code
).
assertEqual
(
'
401
'
);
}
})
/**
* @tc.number SUB_COMMUNICATION_BLUETOOTHBLE_WRITEDESCRIPTOR_1100
* @tc.name testWriteDescriptorValue
* @tc.desc Test Client WriteDescriptorValue callback api10.
* @tc.type Function
* @tc.level Level 2
*/
it
(
'
SUB_COMMUNICATION_BLUETOOTHBLE_WRITEDESCRIPTOR_1100
'
,
0
,
function
()
{
let
bufferDesc
=
new
ArrayBuffer
(
8
);
let
descV
=
new
Uint8Array
(
bufferDesc
);
descV
[
0
]
=
22
;
let
descriptor
=
{
serviceUuid
:
'
00001810-0000-1000-8000-00805F9B34FB
'
,
characteristicUuid
:
'
00001820-0000-1000-8000-00805F9B34FB
'
,
descriptorUuid
:
'
00002903-0000-1000-8000-00805F9B34FB
'
,
descriptorValue
:
bufferDesc
};
try
{
gattClient
.
writeDescriptorValue
(
descriptor
,
(
err
,
data
)
=>
{
console
.
info
(
'
writeDescriptorValue err:
'
+
JSON
.
stringify
(
err
)
+
'
,writeDescriptorValue data:
'
+
JSON
.
stringify
(
data
));
});
}
catch
(
error
)
{
console
.
error
(
`[bluetooth_js]writeDescriptorValue failed, code is
${
error
.
code
}
,
message is
${
error
.
message
}
`
);
expect
(
error
.
code
).
assertEqual
(
'
401
'
);
}
})
/**
* @tc.number SUB_COMMUNICATION_BLUETOOTHBLE_WRITEDESCRIPTOR_1200
* @tc.name test WriteDescriptorOn
* @tc.desc Test on and off api10.
* @tc.type Function
* @tc.level Level 3
*/
it
(
'
SUB_COMMUNICATION_BLUETOOTHBLE_WRITEDESCRIPTOR_1200
'
,
0
,
async
function
(
done
)
{
try
{
let
arrayBufferDesc
=
new
ArrayBuffer
(
8
);
let
descValue
=
new
Uint8Array
(
arrayBufferDesc
);
function
WriteDescriptorReq
(
DescriptorWriteRequest
)
{
let
deviceId
=
DescriptorWriteRequest
.
deviceId
;
let
transId
=
DescriptorWriteRequest
.
transId
;
let
offset
=
DescriptorWriteRequest
.
offset
;
let
isPrepared
=
DescriptorWriteRequest
.
isPrepared
;
let
needRsp
=
DescriptorWriteRequest
.
needRsp
;
let
value
=
new
Uint8Array
(
DescriptorWriteRequest
.
value
);
let
descriptorUuid
=
DescriptorWriteRequest
.
descriptorUuid
;
descValue
[
0
]
=
value
[
0
];
let
serverResponse
=
{
deviceId
:
deviceId
,
transId
:
transId
,
status
:
0
,
offset
:
offset
,
value
:
arrayBufferDesc
};
gattServer
.
sendResponse
(
serverResponse
);
console
.
info
(
"
[bluetooth_js] desWriOn jsondata:
"
+
'
deviceId:
'
+
deviceId
+
'
transId:
'
+
transId
+
'
offset:
'
+
offset
+
'
descriptorUuid:
'
+
descriptorUuid
+
'
charUuid:
'
+
DescriptorWriteRequest
.
characteristicUuid
+
'
serviceUuid:
'
+
DescriptorWriteRequest
.
serviceUuid
+
'
value:
'
+
DescriptorWriteRequest
.
value
+
'
needRsp
'
+
needRsp
+
'
isPrepared:
'
+
isPrepared
);
expect
(
true
).
assertEqual
(
DescriptorWriteRequest
!=
null
);
}
gattServer
.
on
(
"
descriptorWrite
"
,
WriteDescriptorReq
);
gattServer
.
off
(
"
descriptorWrite
"
);
}
catch
(
error
)
{
console
.
error
(
`[bluetooth_js]writeDescriptorValue failed, code is
${
error
.
code
}
,
message is
${
error
.
message
}
`
);
expect
(
error
.
code
).
assertEqual
(
'
2900099
'
);
}
done
();
})
/**
* @tc.number SUB_COMMUNICATION_BLUETOOTHBLE_SETNOTIFYCHARACTERISTIC_1400
* @tc.name test BLECharacteristicChangeON
* @tc.desc Test On and off api10.
* @tc.type Function
* @tc.level Level 3
*/
it
(
'
SUB_COMMUNICATION_BLUETOOTHBLE_SETNOTIFYCHARACTERISTIC_1400
'
,
0
,
async
function
(
done
)
{
try
{
function
CharacteristicChange
(
CharacteristicChangeReq
)
{
let
serviceUuid
=
CharacteristicChangeReq
.
serviceUuid
;
let
characteristicUuid
=
CharacteristicChangeReq
.
characteristicUuid
;
let
value
=
new
Uint8Array
(
CharacteristicChangeReq
.
characteristicValue
);
expect
(
true
).
assertEqual
(
CharacteristicChangeReq
!=
null
);
}
gattClient
.
on
(
'
BLECharacteristicChange
'
,
CharacteristicChange
);
let
descriptors
=
[];
let
arrayBuffer
=
new
ArrayBuffer
(
8
);
let
desValue
=
new
Uint8Array
(
arrayBuffer
);
desValue
[
0
]
=
11
;
let
descriptor
=
{
serviceUuid
:
'
00001810-0000-1000-8000-00805F9B34FB
'
,
characteristicUuid
:
'
00001820-0000-1000-8000-00805F9B34FB
'
,
descriptorUuid
:
'
00001830-0000-1000-8000-00805F9B34FB
'
,
descriptorValue
:
arrayBuffer
};
descriptors
[
0
]
=
descriptor
;;
let
arrayBufferCCC
=
new
ArrayBuffer
(
8
);
let
cccValue
=
new
Uint8Array
(
arrayBufferCCC
);
cccValue
[
0
]
=
1
;
gattClient
.
off
(
'
BLECharacteristicChange
'
);
}
catch
(
error
)
{
console
.
error
(
`[bluetooth_js]BLECharacteristicChangeON failed, code is
${
error
.
code
}
,
message is
${
error
.
message
}
`
);
expect
(
error
.
code
).
assertEqual
(
'
2900099
'
);
}
done
();
})
/**
* @tc.number SUB_COMMUNICATION_BLUETOOTHACCESS_BLECHARACTERISTIC_0100
* @tc.name test setCharacteristicChangeNotification callback
* @tc.desc Test setCharacteristicChangeNotification api10
* @tc.type Function
* @tc.level Level 0
*/
it
(
'
SUB_COMMUNICATION_BLUETOOTHACCESS_BLECHARACTERISTIC_0100
'
,
0
,
async
function
(
done
)
{
let
descriptors
=
[];
let
arrayBuffer
=
new
ArrayBuffer
(
8
);
let
descV
=
new
Uint8Array
(
arrayBuffer
);
descV
[
0
]
=
11
;
let
descriptor
=
{
serviceUuid
:
'
00001810-0000-1000-8000-00805F9B34FB
'
,
characteristicUuid
:
'
00001820-0000-1000-8000-00805F9B34FB
'
,
descriptorUuid
:
'
00002902-0000-1000-8000-00805F9B34FB
'
,
descriptorValue
:
arrayBuffer
};
descriptors
[
0
]
=
descriptor
;
let
arrayBufferC
=
new
ArrayBuffer
(
8
);
let
characteristic
=
{
serviceUuid
:
'
00001810-0000-1000-8000-00805F9B34FB
'
,
characteristicUuid
:
'
00001820-0000-1000-8000-00805F9B34FB
'
,
characteristicValue
:
arrayBufferC
,
descriptors
:
descriptors
};
try
{
gattClient
.
connect
();
gattClient
.
setCharacteristicChangeNotification
(
characteristic
,
true
,
(
err
)
=>
{
console
.
info
(
'
setCharacteristicChangeNotification err:
'
+
JSON
.
stringify
(
err
));
});
done
();
}
catch
(
err
)
{
console
.
error
(
'
setCharacteristicChangeNotification failed errCode:
'
+
err
.
code
+
'
, errMessage:
'
+
err
.
message
);
expect
(
true
).
assertEqual
(
err
.
code
==
'
401
'
||
err
.
code
==
'
2900099
'
);
done
();
}
done
();
})
/**
* @tc.number SUB_COMMUNICATION_BLUETOOTHACCESS_BLECHARACTERISTIC_0200
* @tc.name test setCharacteristicChangeNotification promise
* @tc.desc Test setCharacteristicChangeNotification api10
* @tc.type Function
* @tc.level Level 0
*/
it
(
'
SUB_COMMUNICATION_BLUETOOTHACCESS_BLECHARACTERISTIC_0200
'
,
0
,
async
function
(
done
)
{
let
descriptors
=
[];
let
arrayBuffer
=
new
ArrayBuffer
(
8
);
let
descV
=
new
Uint8Array
(
arrayBuffer
);
descV
[
0
]
=
11
;
let
descriptor
=
{
serviceUuid
:
'
00001810-0000-1000-8000-00805F9B34FB
'
,
characteristicUuid
:
'
00001820-0000-1000-8000-00805F9B34FB
'
,
descriptorUuid
:
'
00002902-0000-1000-8000-00805F9B34FB
'
,
descriptorValue
:
arrayBuffer
};
descriptors
[
0
]
=
descriptor
;
let
arrayBufferC
=
new
ArrayBuffer
(
8
);
let
characteristic
=
{
serviceUuid
:
'
00001810-0000-1000-8000-00805F9B34FB
'
,
characteristicUuid
:
'
00001820-0000-1000-8000-00805F9B34FB
'
,
characteristicValue
:
arrayBufferC
,
descriptors
:
descriptors
};
try
{
gattClient
.
setCharacteristicChangeNotification
(
characteristic
,
true
).
then
(()
=>
{
console
.
info
(
"
setCharacteristicChangeNotification
"
);
});
done
();
}
catch
(
err
)
{
console
.
error
(
'
setCharacteristicChangeNotification failed errCode:
'
+
err
.
code
+
'
, errMessage:
'
+
err
.
message
);
expect
(
err
.
code
).
assertEqual
(
'
401
'
);
done
();
}
done
();
})
/**
* @tc.number SUB_COMMUNICATION_BLUETOOTHACCESS_BLECHARACTERISTIC_0300
* @tc.name test setCharacteristicChangeIndication callback
* @tc.desc Test setCharacteristicChangeIndication api10
* @tc.type Function
* @tc.level Level 0
*/
it
(
'
SUB_COMMUNICATION_BLUETOOTHACCESS_BLECHARACTERISTIC_0300
'
,
0
,
async
function
(
done
)
{
let
descriptors
=
[];
let
arrayBuffer
=
new
ArrayBuffer
(
8
);
let
descV
=
new
Uint8Array
(
arrayBuffer
);
descV
[
0
]
=
11
;
let
descriptor
=
{
serviceUuid
:
'
00001810-0000-1000-8000-00805F9B34FB
'
,
characteristicUuid
:
'
00001820-0000-1000-8000-00805F9B34FB
'
,
descriptorUuid
:
'
00002902-0000-1000-8000-00805F9B34FB
'
,
descriptorValue
:
arrayBuffer
};
descriptors
[
0
]
=
descriptor
;
let
arrayBufferC
=
new
ArrayBuffer
(
8
);
let
characteristic
=
{
serviceUuid
:
'
00001810-0000-1000-8000-00805F9B34FB
'
,
characteristicUuid
:
'
00001820-0000-1000-8000-00805F9B34FB
'
,
characteristicValue
:
arrayBufferC
,
descriptors
:
descriptors
};
try
{
gattClient
.
setCharacteristicChangeIndication
(
characteristic
,
true
,
(
err
)
=>
{
console
.
info
(
'
setCharacteristicChangeIndication err:
'
+
JSON
.
stringify
(
err
));
});
done
();
}
catch
(
err
)
{
console
.
error
(
'
setCharacteristicChangeIndication failed errCode:
'
+
err
.
code
+
'
, errMessage:
'
+
err
.
message
);
expect
(
err
.
code
).
assertEqual
(
'
401
'
);
done
();
}
done
();
})
/**
* @tc.number SUB_COMMUNICATION_BLUETOOTHACCESS_BLECHARACTERISTIC_0400
* @tc.name test setCharacteristicChangeIndication promise
* @tc.desc Test setCharacteristicChangeIndication api10
* @tc.type Function
* @tc.level Level 0
*/
it
(
'
SUB_COMMUNICATION_BLUETOOTHACCESS_BLECHARACTERISTIC_0400
'
,
0
,
async
function
(
done
)
{
let
descriptors
=
[];
let
arrayBuffer
=
new
ArrayBuffer
(
8
);
let
descV
=
new
Uint8Array
(
arrayBuffer
);
descV
[
0
]
=
11
;
let
descriptor
=
{
serviceUuid
:
'
00001810-0000-1000-8000-00805F9B34FB
'
,
characteristicUuid
:
'
00001820-0000-1000-8000-00805F9B34FB
'
,
descriptorUuid
:
'
00002902-0000-1000-8000-00805F9B34FB
'
,
descriptorValue
:
arrayBuffer
};
descriptors
[
0
]
=
descriptor
;
let
arrayBufferC
=
new
ArrayBuffer
(
8
);
let
characteristic
=
{
serviceUuid
:
'
00001810-0000-1000-8000-00805F9B34FB
'
,
characteristicUuid
:
'
00001820-0000-1000-8000-00805F9B34FB
'
,
characteristicValue
:
arrayBufferC
,
descriptors
:
descriptors
};
try
{
gattClient
.
setCharacteristicChangeIndication
(
characteristic
,
true
).
then
(()
=>
{
console
.
info
(
"
setCharacteristicChangeIndication
"
);
});
done
();
}
catch
(
err
)
{
console
.
error
(
'
setCharacteristicChangeIndication failed errCode:
'
+
err
.
code
+
'
, errMessage:
'
+
err
.
message
);
expect
(
err
.
code
).
assertEqual
(
'
401
'
);
done
();
}
done
();
})
/**
* @tc.number SUB_COMMUNICATION_BLUETOOTHBLE_MTUCHANGE_0100
* @tc.name test GattClientDevice on blemtuchange
* @tc.desc test GattClientDevice on blemtuchange api10.
* @tc.type Function
* @tc.level Level 1
*/
it
(
'
SUB_COMMUNICATION_BLUETOOTHBLE_MTUCHANGE_0100
'
,
0
,
async
function
(
done
)
{
let
serverNumber
=
-
1
;
function
onReceiveEvent
(
code
,
number
)
{
console
.
log
(
'
bluetooth error code:
'
+
code
.
code
);
if
(
code
.
code
==
0
)
{
console
.
log
(
'
bluetooth onReceiveEvent Number:
'
+
number
);
serverNumber
=
number
;
}
}
try
{
gattClient
.
on
(
'
BLEMtuChange
'
,
onReceiveEvent
);
}
catch
(
err
)
{
console
.
error
(
"
bluetooth mtu changed errCode:
"
+
err
.
code
+
"
,bluetooth mtu changed errMessage:
"
+
err
.
message
);
expect
(
error
.
code
).
assertEqual
(
'
2900099
'
);
}
gattClient
.
off
(
'
BLEMtuChange
'
,
onReceiveEvent
);
done
();
})
/**
* @tc.number SUB_COMMUNICATION_BLUETOOTHBLE_MTUCHANGE_0200
* @tc.name test GattClientDevice off blemtuchange
* @tc.desc test GattClientDevice off blemtuchange api10
* @tc.type Function
* @tc.level Level 1
*/
it
(
'
SUB_COMMUNICATION_BLUETOOTHBLE_MTUCHANGE_0200
'
,
0
,
async
function
(
done
)
{
let
serverNumber
=
-
1
;
function
onReceiveEvent
(
code
,
number
)
{
console
.
log
(
'
bluetooth error code:
'
+
code
.
code
);
if
(
code
.
code
==
0
)
{
console
.
log
(
'
bluetooth onReceiveEvent Number:
'
+
number
);
serverNumber
=
number
;
}
}
gattClient
.
on
(
'
BLEMtuChange
'
,
onReceiveEvent
);
try
{
gattClient
.
off
(
'
BLEMtuChange
'
,
onReceiveEvent
);
}
catch
(
err
)
{
console
.
error
(
"
bluetooth mtu changed off errCode:
"
+
err
.
code
+
"
,bluetooth mtu changed off errMessage:
"
+
err
.
message
);
expect
(
error
.
code
).
assertEqual
(
'
2900099
'
);
}
done
();
})
})
}
communication/bluetooth_gatt/src/main/js/test/BtBleService.test.js
0 → 100644
浏览文件 @
ff96c6dc
/*
* Copyright (C) 2022 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import
bluetooth
from
'
@ohos.bluetooth.ble
'
;
import
btAccess
from
'
@ohos.bluetooth.access
'
;
import
{
describe
,
beforeAll
,
beforeEach
,
afterEach
,
afterAll
,
it
,
expect
}
from
'
@ohos/hypium
'
export
default
function
btBleServiceTest
()
{
describe
(
'
btBleServiceTest
'
,
function
()
{
let
gattServer
=
null
;
let
gattClient
=
null
;
function
sleep
(
delay
)
{
return
new
Promise
(
resovle
=>
setTimeout
(
resovle
,
delay
))
}
async
function
tryToEnableBt
()
{
let
sta
=
btAccess
.
getState
();
switch
(
sta
){
case
0
:
console
.
info
(
'
[bluetooth_js] bt turn off:
'
+
JSON
.
stringify
(
sta
));
btAccess
.
enableBluetooth
();
await
sleep
(
10000
);
break
;
case
1
:
console
.
info
(
'
[bluetooth_js] bt turning on:
'
+
JSON
.
stringify
(
sta
));
await
sleep
(
3000
);
break
;
case
2
:
console
.
info
(
'
[bluetooth_js] bt turn on:
'
+
JSON
.
stringify
(
sta
));
break
;
case
3
:
console
.
info
(
'
[bluetooth_js] bt turning off:
'
+
JSON
.
stringify
(
sta
));
btAccess
.
enableBluetooth
();
await
sleep
(
10000
);
break
;
default
:
console
.
info
(
'
[bluetooth_js] enable success
'
);
}
}
beforeAll
(
async
function
(
done
)
{
console
.
info
(
'
beforeAll called
'
)
await
tryToEnableBt
()
gattServer
=
bluetooth
.
createGattServer
();
console
.
info
(
'
bluetooth ble create gattserver result:
'
+
gattServer
);
gattClient
=
bluetooth
.
createGattClientDevice
(
'
04:30:02:01:00:00
'
);
console
.
info
(
'
bluetooth ble create gattclientdevice result:
'
+
gattClient
);
done
()
})
beforeEach
(
async
function
(
done
)
{
console
.
info
(
'
beforeEach called
'
)
await
tryToEnableBt
()
done
();
})
afterEach
(
function
()
{
console
.
info
(
'
afterEach called
'
)
})
afterAll
(
function
()
{
console
.
info
(
'
afterAll called
'
)
gattServer
.
close
();
})
/**
* @tc.number SUB_COMMUNICATION_BLUETOOTHBLE_GATTSERCONNECT_0100
* @tc.name test Server connectStateChange
* @tc.desc Test on and off api10 .
* @tc.type Function
* @tc.level Level 2
*/
it
(
'
SUB_COMMUNICATION_BLUETOOTHBLE_GATTSERCONNECT_0100
'
,
0
,
async
function
(
done
)
{
try
{
function
Connected
(
BLEConnectChangedState
)
{
let
deviceId
=
BLEConnectChangedState
.
deviceId
;
let
status
=
BLEConnectChangedState
.
state
;
console
.
info
(
"
[bluetooth_js] connectStateChange jsondata:
"
+
'
deviceId:
'
+
deviceId
+
'
status:
'
+
status
);
expect
(
true
).
assertEqual
(
BLEConnectChangedState
!=
null
);
}
gattServer
.
on
(
"
connectStateChange
"
,
Connected
);
gattServer
.
off
(
"
connectStateChange
"
);
}
catch
(
error
)
{
console
.
error
(
`[bluetooth_js]Connect_0100 failed, code is
${
error
.
code
}
,message is
${
error
.
message
}
`
);
expect
(
error
.
code
).
assertEqual
(
'
2900099
'
);
}
done
();
})
/**
* @tc.number SUB_COMMUNICATION_BLUETOOTHBLE_ADDSERVICE_0100
* @tc.name testAddService
* @tc.desc Test AddService api10.
* @tc.type Function
* @tc.level Level 1
*/
it
(
'
SUB_COMMUNICATION_BLUETOOTHBLE_ADDSERVICE_0100
'
,
0
,
async
function
(
done
)
{
let
descriptors
=
[];
let
arrayBuffer
=
new
ArrayBuffer
(
8
);
let
descV
=
new
Uint8Array
(
arrayBuffer
);
descV
[
0
]
=
11
;
let
descriptor
=
{
serviceUuid
:
'
00001810-0000-1000-8000-00805F9B34FB
'
,
characteristicUuid
:
'
00001820-0000-1000-8000-00805F9B34FB
'
,
descriptorUuid
:
'
00002902-0000-1000-8000-00805F9B34FB
'
,
descriptorValue
:
arrayBuffer
};
descriptors
[
0
]
=
descriptor
;
let
characteristics
=
[];
let
arrayBufferC
=
new
ArrayBuffer
(
8
);
let
cccV
=
new
Uint8Array
(
arrayBufferC
);
cccV
[
0
]
=
1
;
let
characteristic
=
{
serviceUuid
:
'
00001810-0000-1000-8000-00805F9B34FB
'
,
characteristicUuid
:
'
00001820-0000-1000-8000-00805F9B34FB
'
,
characteristicValue
:
arrayBufferC
,
descriptors
:
descriptors
};
characteristics
[
0
]
=
characteristic
;
let
gattService
=
{
serviceUuid
:
'
00001810-0000-1000-8000-00805F9B34FB
'
,
isPrimary
:
false
,
characteristics
:
characteristics
,
includeServices
:[]};
try
{
gattServer
.
addService
(
gattService
);
}
catch
(
error
)
{
console
.
error
(
`[bluetooth_js]AddService2 failed, code is
${
error
.
code
}
,message is
${
error
.
message
}
`
);
expect
(
error
.
code
).
assertEqual
(
'
2900099
'
);
}
done
();
})
/**
* @tc.number SUB_COMMUNICATION_BLUETOOTHBLE_ADDSERVICE_0200
* @tc.name testAddService
* @tc.desc Test api10 401 - characteristics of service is null.
* @tc.type Function
* @tc.level Level 2
*/
it
(
'
SUB_COMMUNICATION_BLUETOOTHBLE_ADDSERVICE_0200
'
,
0
,
async
function
(
done
)
{
try
{
gattServer
.
removeService
(
'
00001810-0000-1000-8000-00805F9B34FB
'
);
}
catch
(
error
)
{
console
.
error
(
`[bluetooth_js]AddService2 failed, code is
${
error
.
code
}
,message is
${
error
.
message
}
`
);
expect
(
true
).
assertEqual
(
error
.
code
==
'
2900099
'
||
error
.
code
==
'
401
'
);
}
done
();
})
/**
* @tc.number SUB_COMMUNICATION_BLUETOOTHBLE_NOTIFYCHARACTERISTIC_0100
* @tc.name testNotifyCharacteristicChanged callback
* @tc.desc Test NotifyCharacteristicChanged api10.
* @tc.type Function
* @tc.level Level 2
*/
it
(
'
SUB_COMMUNICATION_BLUETOOTHBLE_NOTIFYCHARACTERISTIC_0100
'
,
0
,
async
function
(
done
)
{
let
descriptors
=
[];
let
arrayBuffer
=
new
ArrayBuffer
(
8
);
let
descV
=
new
Uint8Array
(
arrayBuffer
);
descV
[
0
]
=
11
;
let
descriptor
=
{
serviceUuid
:
'
00001810-0000-1000-8000-00805F9B34FB
'
,
characteristicUuid
:
'
00001820-0000-1000-8000-00805F9B34FB
'
,
descriptorUuid
:
'
00002902-0000-1000-8000-00805F9B34FB
'
,
descriptorValue
:
arrayBuffer
};
descriptors
[
0
]
=
descriptor
;
let
arrayBufferC
=
new
ArrayBuffer
(
8
);
let
characteristic
=
{
serviceUuid
:
'
00001810-0000-1000-8000-00805F9B34FB
'
,
characteristicUuid
:
'
00001820-0000-1000-8000-00805F9B34FB
'
,
characteristicValue
:
arrayBufferC
,
descriptors
:
descriptors
};
let
notifyCharacteristic
=
{
serviceUuid
:
'
00001810-0000-1000-8000-00805F9B34FB
'
,
characteristicUuid
:
'
00001821-0000-1000-8000-00805F9B34FB
'
,
characteristicValue
:
characteristic
.
characteristicValue
,
confirm
:
false
};
try
{
gattServer
.
notifyCharacteristicChanged
(
'
00:11:22:33:44:55
'
,
notifyCharacteristic
,
(
err
,
data
)
=>
{
console
.
info
(
'
notifyCharacteristicChanged err:
'
+
JSON
.
stringify
(
err
)
+
'
,notifyCharacteristicChanged data:
'
+
JSON
.
stringify
(
data
));
});
}
catch
(
error
)
{
console
.
error
(
'
[bluetooth_js]notifyCharacteristicChanged1 failed, code:
'
+
JSON
.
stringify
(
error
.
code
)
+
'
error.message:
'
+
JSON
.
stringify
(
error
.
message
));
expect
(
error
.
code
).
assertEqual
(
'
2900099
'
);
}
done
();
})
/**
* @tc.number SUB_COMMUNICATION_BLUETOOTHBLE_NOTIFYCHARACTERISTIC_0200
* @tc.name testNotifyCharacteristicChanged promise
* @tc.desc Test NotifyCharacteristicChanged api10.
* @tc.type Function
* @tc.level Level 2
*/
it
(
'
SUB_COMMUNICATION_BLUETOOTHBLE_NOTIFYCHARACTERISTIC_0200
'
,
0
,
async
function
(
done
)
{
let
descriptors
=
[];
let
arrayBuffer
=
new
ArrayBuffer
(
8
);
let
descV
=
new
Uint8Array
(
arrayBuffer
);
descV
[
0
]
=
11
;
let
descriptor
=
{
serviceUuid
:
'
00001810-0000-1000-8000-00805F9B34FB
'
,
characteristicUuid
:
'
00001820-0000-1000-8000-00805F9B34FB
'
,
descriptorUuid
:
'
00002902-0000-1000-8000-00805F9B34FB
'
,
descriptorValue
:
arrayBuffer
};
descriptors
[
0
]
=
descriptor
;
let
arrayBufferC
=
new
ArrayBuffer
(
8
);
let
characteristic
=
{
serviceUuid
:
'
00001810-0000-1000-8000-00805F9B34FB
'
,
characteristicUuid
:
'
00001820-0000-1000-8000-00805F9B34FB
'
,
characteristicValue
:
arrayBufferC
,
descriptors
:
descriptors
};
let
notifyCharacteristic
=
{
serviceUuid
:
'
00001810-0000-1000-8000-00805F9B34FB
'
,
characteristicUuid
:
'
00001821-0000-1000-8000-00805F9B34FB
'
,
characteristicValue
:
characteristic
.
characteristicValue
,
confirm
:
false
};
try
{
gattServer
.
notifyCharacteristicChanged
(
'
00:11:22:33:44:55
'
,
notifyCharacteristic
).
then
(()
=>
{
console
.
info
(
"
notifyCharacteristicChanged
"
);
},
err
=>
{
console
.
error
(
"
notifyCharacteristicChanged:errCode
"
+
err
.
code
+
"
,errMessage:
"
+
err
.
message
);
});
}
catch
(
error
)
{
console
.
error
(
'
[bluetooth_js]notifyCharacteristicChanged2 failed, code:
'
+
JSON
.
stringify
(
error
.
code
)
+
'
error.message:
'
+
JSON
.
stringify
(
error
.
message
));
expect
(
error
.
code
).
assertEqual
(
'
2900099
'
);
}
done
();
})
/**
* @tc.number SUB_COMMUNICATION_BLUETOOTHBLE_SENDRESPONSE_0100
* @tc.name testSendResponse success
* @tc.desc Test SendResponse api10.
* @tc.type Function
* @tc.level Level 1
*/
it
(
'
SUB_COMMUNICATION_BLUETOOTHBLE_SENDRESPONSE_0100
'
,
0
,
async
function
(
done
)
{
try
{
let
arrayBuffer
=
new
ArrayBuffer
(
8
);
let
value
=
new
Uint8Array
(
arrayBuffer
);
value
[
0
]
=
1
;
let
ServerResponse
=
{
deviceId
:
'
00:11:22:33:44:55
'
,
transId
:
1
,
status
:
0
,
offset
:
0
,
value
:
arrayBuffer
};
gattServer
.
sendResponse
(
ServerResponse
);
expect
(
true
).
assertFalse
();
done
();
}
catch
(
error
)
{
console
.
error
(
`[bluetooth_js]sendResponse1 failed, code is
${
error
.
code
}
,
message is
${
error
.
message
}
`
);
expect
(
error
.
code
).
assertEqual
(
'
2900099
'
);
done
()
}
})
/**
* @tc.number SUB_COMMUNICATION_BLUETOOTHBLE_SENDRESPONSE_0200
* @tc.name testSendResponse success
* @tc.desc Test SendResponse api10.
* @tc.type Function
* @tc.level Level 1
*/
it
(
'
SUB_COMMUNICATION_BLUETOOTHBLE_SENDRESPONSE_0200
'
,
0
,
async
function
(
done
)
{
try
{
let
arrayBuffer
=
new
ArrayBuffer
(
8
);
let
value
=
new
Uint8Array
(
arrayBuffer
);
value
[
0
]
=
1
;
let
ServerResponse
=
{
deviceId
:
'
00:11:22:33:44:55
'
,
transId
:
1
,
status
:
-
1
,
offset
:
0
,
value
:
arrayBuffer
};
gattServer
.
sendResponse
(
ServerResponse
);
expect
(
true
).
assertFalse
();
done
();
}
catch
(
error
)
{
console
.
error
(
`[bluetooth_js]sendResponse2 failed, code is
${
error
.
code
}
,
message is
${
error
.
message
}
`
);
expect
(
error
.
code
).
assertEqual
(
'
2900099
'
);
done
()
}
})
/**
* @tc.number SUB_COMMUNICATION_BLUETOOTHBLE_SENDRESPONSE_0300
* @tc.name testSendResponse success
* @tc.desc Test SendResponse 401 -null parameter.
* @tc.type Function
* @tc.level Level 1
*/
it
(
'
SUB_COMMUNICATION_BLUETOOTHBLE_SENDRESPONSE_0300
'
,
0
,
async
function
(
done
)
{
try
{
gattServer
.
sendResponse
();
expect
(
true
).
assertFalse
();
done
();
}
catch
(
error
)
{
console
.
error
(
'
[bluetooth_js]sendResponse3 error.code:
'
+
JSON
.
stringify
(
error
.
code
)
+
'
error.message:
'
+
JSON
.
stringify
(
error
.
message
));
expect
(
error
.
code
).
assertEqual
(
'
401
'
);
done
()
}
})
/**
* @tc.number SUB_COMMUNICATION_BLUETOOTHBLE_SENDRESPONSE_0400
* @tc.name testSendResponse success
* @tc.desc Test SendResponse 401 -error parameter.
* @tc.type Function
* @tc.level Level 1
*/
it
(
'
SUB_COMMUNICATION_BLUETOOTHBLE_SENDRESPONSE_0400
'
,
0
,
async
function
(
done
)
{
try
{
let
arrayBuffer
=
new
ArrayBuffer
(
8
);
let
value
=
new
Uint8Array
(
arrayBuffer
);
value
[
0
]
=
1
;
let
ServerResponse
=
{
transId
:
1
,
status
:
-
1
,
offset
:
0
,
value
:
arrayBuffer
};
gattServer
.
sendResponse
(
ServerResponse
);
expect
(
true
).
assertFalse
();
done
();
}
catch
(
error
)
{
console
.
error
(
`[bluetooth_js]sendResponse4 failed, code is
${
error
.
code
}
,
message is
${
error
.
message
}
`
);
expect
(
error
.
code
).
assertEqual
(
'
401
'
);
done
()
}
})
/**
* @tc.number SUB_COMMUNICATION_BLUETOOTHBLE_MTUCHANGE_0100
* @tc.name test gattserver on blemtuchange
* @tc.desc test gattserver on blemtuchange api10.
* @tc.type Function
* @tc.level Level 1
*/
it
(
'
SUB_COMMUNICATION_BLUETOOTHBLE_MTUCHANGE_0100
'
,
0
,
async
function
(
done
)
{
try
{
gattServer
.
on
(
'
BLEMtuChange
'
,
(
err
,
data
)
=>
{
console
.
info
(
'
BLEMtuChange on err
'
+
JSON
.
stringify
(
err
));
console
.
info
(
'
BLEMtuChange on value
'
+
JSON
.
stringify
(
data
));
})
}
catch
(
err
)
{
console
.
error
(
"
bluetooth mtu changed on errCode:
"
+
err
.
code
+
"
,bluetooth mtu changed on errMessage:
"
+
err
.
message
);
expect
(
err
.
code
).
assertEqual
(
'
2900099
'
);
}
gattServer
.
off
(
'
BLEMtuChange
'
,
(
err
,
data
)
=>
{
console
.
info
(
'
BLEMtuChange off err
'
+
JSON
.
stringify
(
err
));
console
.
info
(
'
BLEMtuChange off value
'
+
JSON
.
stringify
(
data
));
})
done
();
})
/**
* @tc.number SUB_COMMUNICATION_BLUETOOTHBLE_MTUCHANGE_0200
* @tc.name test gattserver off blemtuchange
* @tc.desc test gattserver off blemtuchange api10
* @tc.type Function
* @tc.level Level 1
*/
it
(
'
SUB_COMMUNICATION_BLUETOOTHBLE_MTUCHANGE_0200
'
,
0
,
async
function
(
done
)
{
gattServer
.
on
(
'
BLEMtuChange
'
,
(
err
,
data
)
=>
{
console
.
info
(
'
BLEMtuChange on err
'
+
JSON
.
stringify
(
err
));
console
.
info
(
'
BLEMtuChange on value
'
+
JSON
.
stringify
(
data
));
})
try
{
gattServer
.
off
(
'
BLEMtuChange
'
,
(
err
,
data
)
=>
{
console
.
info
(
'
BLEMtuChange off err
'
+
JSON
.
stringify
(
err
));
console
.
info
(
'
BLEMtuChange off value
'
+
JSON
.
stringify
(
data
));
})
}
catch
(
err
)
{
console
.
error
(
"
bluetooth mtu changed off errCode:
"
+
err
.
code
+
"
,bluetooth mtu changed off errMessage:
"
+
err
.
message
);
expect
(
err
.
code
).
assertEqual
(
'
2900099
'
);
}
done
();
})
})
}
communication/bluetooth_gatt/src/main/js/test/BtGattManager.test.js
浏览文件 @
ff96c6dc
...
@@ -75,13 +75,14 @@ describe('btGattManagerTest', function() {
...
@@ -75,13 +75,14 @@ describe('btGattManagerTest', function() {
* @tc.level Level 2
* @tc.level Level 2
*/
*/
it
(
'
SUB_COMMUNICATION_BLUETOOTH_GATTCLICONNECT_0100
'
,
0
,
async
function
(
done
)
{
it
(
'
SUB_COMMUNICATION_BLUETOOTH_GATTCLICONNECT_0100
'
,
0
,
async
function
(
done
)
{
let
ret
=
gattClient
.
connect
();
try
{
await
sleep
(
2000
);
gattClient
.
connect
();
console
.
info
(
'
[bluetooth_js] gattClient connect
'
+
ret
)
await
sleep
(
2000
);
expect
(
ret
).
assertFalse
();
gattClient
.
disconnect
();
let
disconnect
=
gattClient
.
disconnect
();
}
catch
(
error
)
{
console
.
info
(
'
[bluetooth_js] gatt disconnect:
'
+
disconnect
);
console
.
info
(
'
[bluetooth_js] gatt disconnect:
'
+
disconnect
);
expect
(
disconnect
).
assertEqual
(
false
);
expect
(
error
.
code
).
assertEqual
(
'
2900099
'
);
}
done
();
done
();
})
})
...
@@ -113,12 +114,14 @@ describe('btGattManagerTest', function() {
...
@@ -113,12 +114,14 @@ describe('btGattManagerTest', function() {
console
.
info
(
'
[bluetooth_js] state changed
'
+
connectState
)
console
.
info
(
'
[bluetooth_js] state changed
'
+
connectState
)
expect
(
true
).
assertEqual
(
connectState
!=
null
);
expect
(
true
).
assertEqual
(
connectState
!=
null
);
}
}
await
gattClient
.
on
(
'
BLEConnectionStateChange
'
,
ConnectStateChanged
);
try
{
let
ret
=
gattClient
.
connect
();
await
gattClient
.
on
(
'
BLEConnectionStateChange
'
,
ConnectStateChanged
);
console
.
info
(
'
[bluetooth_js] gattClient connect
'
+
ret
)
gattClient
.
connect
();
expect
(
ret
).
assertFalse
();
gattClient
.
disconnect
();
gattClient
.
disconnect
();
}
catch
(
error
)
{
await
sleep
(
2000
);
console
.
info
(
'
[bluetooth_js] gatt disconnect:
'
+
disconnect
);
expect
(
error
.
code
).
assertEqual
(
'
2900099
'
);
}
await
gattClient
.
off
(
"
BLEConnectionStateChange
"
);
await
gattClient
.
off
(
"
BLEConnectionStateChange
"
);
done
();
done
();
})
})
...
@@ -131,9 +134,7 @@ describe('btGattManagerTest', function() {
...
@@ -131,9 +134,7 @@ describe('btGattManagerTest', function() {
* @tc.level Level 2
* @tc.level Level 2
*/
*/
it
(
'
SUB_COMMUNICATION_BLUETOOTH_GETRSSIVALUE_0100
'
,
0
,
async
function
(
done
)
{
it
(
'
SUB_COMMUNICATION_BLUETOOTH_GETRSSIVALUE_0100
'
,
0
,
async
function
(
done
)
{
let
ret
=
gattClient
.
connect
();
gattClient
.
connect
();
console
.
info
(
'
[bluetooth_js] gattClient getrssi connect:
'
+
JSON
.
stringify
(
ret
))
expect
(
ret
).
assertFalse
();
try
{
try
{
await
gattClient
.
getRssiValue
().
then
((
data
)
=>
{
await
gattClient
.
getRssiValue
().
then
((
data
)
=>
{
console
.
info
(
'
[bluetooth_js] BLE read rssi:
'
+
JSON
.
stringify
(
data
));
console
.
info
(
'
[bluetooth_js] BLE read rssi:
'
+
JSON
.
stringify
(
data
));
...
@@ -150,14 +151,13 @@ describe('btGattManagerTest', function() {
...
@@ -150,14 +151,13 @@ describe('btGattManagerTest', function() {
expect
(
true
).
assertEqual
(
b
);
expect
(
true
).
assertEqual
(
b
);
done
();
done
();
});
});
let
disconnect
=
gattClient
.
disconnect
();
gattClient
.
disconnect
();
console
.
info
(
'
[bluetooth_js] gatt getrssi disconnect:
'
+
disconnect
);
expect
(
disconnect
).
assertEqual
(
false
);
}
catch
(
error
)
{
}
catch
(
error
)
{
console
.
error
(
`[bluetooth_js]
GetRssiValue_0100
error, code is
${
error
.
code
}
,
console
.
error
(
`[bluetooth_js]error, code is
${
error
.
code
}
,
message is
${
error
.
message
}
`
);
message is
${
error
.
message
}
`
);
expect
(
error
.
code
).
assertEqual
(
'
2900099
'
);
}
}
done
()
done
()
;
})
})
...
@@ -169,31 +169,32 @@ describe('btGattManagerTest', function() {
...
@@ -169,31 +169,32 @@ describe('btGattManagerTest', function() {
* @tc.level Level 2
* @tc.level Level 2
*/
*/
it
(
'
SUB_COMMUNICATION_BLUETOOTH_GETRSSIVALUE_0200
'
,
0
,
async
function
(
done
)
{
it
(
'
SUB_COMMUNICATION_BLUETOOTH_GETRSSIVALUE_0200
'
,
0
,
async
function
(
done
)
{
let
ret
=
gattClient
.
connect
();
try
{
console
.
info
(
'
[bluetooth_js] gattClient getRssi connect
'
+
JSON
.
stringify
(
ret
))
gattClient
.
connect
();
expect
(
ret
).
assertFalse
();
gattClient
.
getRssiValue
((
err
,
data
)
=>
{
gattClient
.
getRssiValue
((
err
,
data
)
=>
{
if
(
err
)
if
(
err
)
{
{
console
.
info
(
'
[bluetooth_js]getRssi value:
'
+
JSON
.
stringify
(
err
));
console
.
info
(
'
[bluetooth_js]getRssi value:
'
+
JSON
.
stringify
(
err
));
let
b
=
false
;
let
b
=
false
;
if
(
err
.
code
==
2900099
||
err
.
code
==-
1
)
if
(
err
.
code
==
2900099
||
err
.
code
==-
1
)
{
{
b
=
true
b
=
true
}
}
expect
(
true
).
assertEqual
(
b
);
expect
(
true
).
assertEqual
(
b
);
}
}
else
else
{
{
console
.
info
(
'
[bluetooth_js]getRssi value:
'
+
JSON
.
stringify
(
data
));
console
.
info
(
'
[bluetooth_js]getRssi value:
'
+
JSON
.
stringify
(
data
));
expect
(
true
).
assertEqual
(
data
!=
null
)
expect
(
true
).
assertEqual
(
data
!=
null
)
}
}
});
});
let
disconnect
=
gattClient
.
disconnect
();
gattClient
.
disconnect
();
console
.
info
(
'
[bluetooth_js] gatt getrssi1 disconnect:
'
+
disconnect
);
}
catch
(
error
)
{
expect
(
disconnect
).
assertEqual
(
false
);
console
.
error
(
`[bluetooth_js]error, code is
${
error
.
code
}
,
await
sleep
(
3000
);
message is
${
error
.
message
}
`
);
done
()
expect
(
error
.
code
).
assertEqual
(
'
2900099
'
);
}
done
();
})
})
/**
/**
...
@@ -204,22 +205,24 @@ describe('btGattManagerTest', function() {
...
@@ -204,22 +205,24 @@ describe('btGattManagerTest', function() {
* @tc.level Level 2
* @tc.level Level 2
*/
*/
it
(
'
SUB_COMMUNICATION_BLUETOOTH_GETDEVICENAME_0100
'
,
0
,
async
function
(
done
)
{
it
(
'
SUB_COMMUNICATION_BLUETOOTH_GETDEVICENAME_0100
'
,
0
,
async
function
(
done
)
{
let
ret
=
gattClient
.
connect
();
try
{
console
.
info
(
'
[bluetooth_js] gattClient getname2 connect
'
+
JSON
.
stringify
(
ret
))
gattClient
.
connect
();
expect
(
ret
).
assertFalse
();
await
gattClient
.
getDeviceName
().
then
((
data
)
=>
{
await
gattClient
.
getDeviceName
().
then
((
data
)
=>
{
console
.
info
(
'
[bluetooth_js] device name
'
+
JSON
.
stringify
(
data
))
console
.
info
(
'
[bluetooth_js] device name
'
+
JSON
.
stringify
(
data
))
expect
(
true
).
assertEqual
(
data
!=
null
);
expect
(
true
).
assertEqual
(
data
!=
null
);
done
();
done
();
}).
catch
(
err
=>
{
}).
catch
(
err
=>
{
console
.
error
(
'
bluetooth getDeviceName has error:
'
+
err
);
console
.
error
(
'
bluetooth getDeviceName has error:
'
+
err
);
expect
(
err
.
code
).
assertEqual
(
2900099
);
expect
(
err
.
code
).
assertEqual
(
2900099
);
done
();
done
();
});
});
gattClient
.
disconnect
();
let
disconnect
=
gattClient
.
disconnect
();
}
catch
(
error
)
{
console
.
info
(
'
[bluetooth_js] gatt getname2 disconnect:
'
+
disconnect
);
console
.
error
(
`[bluetooth_js]error, code is
${
error
.
code
}
,
expect
(
disconnect
).
assertEqual
(
false
);
message is
${
error
.
message
}
`
);
expect
(
error
.
code
).
assertEqual
(
'
2900099
'
);
}
done
();
})
})
...
@@ -231,17 +234,19 @@ describe('btGattManagerTest', function() {
...
@@ -231,17 +234,19 @@ describe('btGattManagerTest', function() {
* @tc.level Level 2
* @tc.level Level 2
*/
*/
it
(
'
SUB_COMMUNICATION_BLUETOOTH_GETDEVICENAME_0200
'
,
0
,
async
function
(
done
)
{
it
(
'
SUB_COMMUNICATION_BLUETOOTH_GETDEVICENAME_0200
'
,
0
,
async
function
(
done
)
{
let
ret
=
gattClient
.
connect
();
try
{
console
.
info
(
'
[bluetooth_js] gattClient getname1 connect
'
+
JSON
.
stringify
(
ret
))
gattClient
.
connect
();
expect
(
ret
).
assertFalse
();
gattClient
.
getDeviceName
((
err
,
data
)
=>
{
gattClient
.
getDeviceName
((
err
,
data
)
=>
{
console
.
info
(
'
[bluetooth_js]getname value:
'
+
JSON
.
stringify
(
data
));
console
.
info
(
'
[bluetooth_js]getname value:
'
+
JSON
.
stringify
(
data
));
console
.
info
(
'
[bluetooth_js]getname err code:
'
+
JSON
.
stringify
(
err
));
console
.
info
(
'
[bluetooth_js]getname err code:
'
+
JSON
.
stringify
(
err
));
expect
(
true
).
assertEqual
(
data
!=
null
);
expect
(
true
).
assertEqual
(
data
!=
null
);
gattClient
.
disconnect
();
let
disconnect
=
gattClient
.
disconnect
();
});
console
.
info
(
'
[bluetooth_js] gatt getname1 disconnect:
'
+
disconnect
);
}
catch
(
error
)
{
expect
(
disconnect
).
assertEqual
(
false
);
console
.
error
(
`[bluetooth_js]error, code is
${
error
.
code
}
,
});
message is
${
error
.
message
}
`
);
expect
(
error
.
code
).
assertEqual
(
'
2900099
'
);
}
done
();
done
();
})
})
...
@@ -253,21 +258,24 @@ describe('btGattManagerTest', function() {
...
@@ -253,21 +258,24 @@ describe('btGattManagerTest', function() {
* @tc.level Level 3
* @tc.level Level 3
*/
*/
it
(
'
SUB_COMMUNICATION_BLUETOOTH_GETSERVICE_0100
'
,
0
,
async
function
(
done
)
{
it
(
'
SUB_COMMUNICATION_BLUETOOTH_GETSERVICE_0100
'
,
0
,
async
function
(
done
)
{
let
ret
=
gattClient
.
connect
();
try
{
console
.
info
(
'
[bluetooth_js]gattClient getservices1 connect
'
+
JSON
.
stringify
(
ret
))
gattClient
.
connect
();
expect
(
ret
).
assertFalse
();
await
gattClient
.
getServices
().
then
((
GattService
)
=>
{
await
gattClient
.
getServices
().
then
((
GattService
)
=>
{
console
.
info
(
'
[bluetooth_js] getServices successfully:
'
+
JSON
.
stringify
(
GattService
));
console
.
info
(
'
[bluetooth_js] getServices successfully:
'
+
JSON
.
stringify
(
GattService
));
expect
(
GattService
).
assertNull
();
expect
(
GattService
).
assertNull
();
done
();
done
();
}).
catch
(
err
=>
{
}).
catch
(
err
=>
{
console
.
error
(
'
[bluetooth_js] getServices has error:
'
+
JSON
.
stringify
(
err
));
console
.
error
(
'
[bluetooth_js] getServices has error:
'
+
JSON
.
stringify
(
err
));
expect
(
true
).
assertEqual
(
true
);
expect
(
true
).
assertEqual
(
true
);
done
();
done
();
});
});
gattClient
.
disconnect
();
let
disconnect
=
gattClient
.
disconnect
();
}
catch
(
error
)
{
console
.
info
(
'
[bluetooth_js] gatt getservices1 disconnect:
'
+
disconnect
);
console
.
error
(
`[bluetooth_js]error, code is
${
error
.
code
}
,
expect
(
disconnect
).
assertEqual
(
false
);
message is
${
error
.
message
}
`
);
expect
(
error
.
code
).
assertEqual
(
'
2900099
'
);
}
done
();
})
})
/**
/**
...
...
communication/bluetooth_gatt/src/main/js/test/BtGattService.test.js
浏览文件 @
ff96c6dc
...
@@ -81,13 +81,14 @@ describe('btGattServiceTest', function() {
...
@@ -81,13 +81,14 @@ describe('btGattServiceTest', function() {
let
status
=
BLEConnectChangedState
.
state
;
let
status
=
BLEConnectChangedState
.
state
;
console
.
info
(
"
[bluetooth_js] connectStateChange jsondata:
"
console
.
info
(
"
[bluetooth_js] connectStateChange jsondata:
"
+
'
deviceId:
'
+
deviceId
+
'
status:
'
+
status
);
+
'
deviceId:
'
+
deviceId
+
'
status:
'
+
status
);
expect
(
true
).
assertEqual
(
BLEConnectChangedState
!=
null
);
}
}
try
{
await
gattServer
.
on
(
"
connectStateChange
"
,
Connected
);
await
gattServer
.
on
(
"
connectStateChange
"
,
Connected
);
let
ret
=
gattClient
.
connect
();
gattClient
.
connect
();
await
sleep
(
2000
);
}
catch
(
error
)
{
console
.
info
(
'
[bluetooth_js] gattClient connect
'
+
ret
)
console
.
error
(
`[bluetooth_js]code is
${
error
.
code
}
,message is
${
error
.
message
}
`
);
expect
(
ret
).
assertFalse
();
expect
(
error
.
code
).
assertEqual
(
'
2900099
'
);
}
await
gattServer
.
off
(
"
connectStateChange
"
);
await
gattServer
.
off
(
"
connectStateChange
"
);
done
();
done
();
})
})
...
...
communication/bluetooth_gatt/src/main/js/test/BtManagerGattManager.test.js
浏览文件 @
ff96c6dc
...
@@ -51,7 +51,7 @@ describe('btManagerGattManagerTest', function() {
...
@@ -51,7 +51,7 @@ describe('btManagerGattManagerTest', function() {
beforeAll
(
function
()
{
beforeAll
(
function
()
{
console
.
info
(
'
beforeAll called
'
)
console
.
info
(
'
beforeAll called
'
)
gattServer
=
bluetooth
.
BLE
.
createGattServer
();
gattServer
=
bluetooth
.
BLE
.
createGattServer
();
gattClient
=
bluetooth
.
BLE
.
createGattClientDevice
(
"
92:3A:C0:3A:4C:28
"
);
gattClient
=
bluetooth
.
BLE
.
createGattClientDevice
(
'
92:3A:C0:3A:4C:28
'
);
})
})
beforeEach
(
async
function
(
done
)
{
beforeEach
(
async
function
(
done
)
{
console
.
info
(
'
beforeEach called
'
)
console
.
info
(
'
beforeEach called
'
)
...
@@ -78,15 +78,21 @@ describe('btManagerGattManagerTest', function() {
...
@@ -78,15 +78,21 @@ describe('btManagerGattManagerTest', function() {
it
(
'
SUB_COMMUNICATION_BTMANAGER_GATTCONNECT_0100
'
,
0
,
async
function
(
done
)
{
it
(
'
SUB_COMMUNICATION_BTMANAGER_GATTCONNECT_0100
'
,
0
,
async
function
(
done
)
{
try
{
try
{
gattClient
.
connect
();
gattClient
.
connect
();
await
sleep
(
2000
);
console
.
info
(
`[bluetooth_js]connect success`
);
}
catch
(
error
)
{
console
.
info
(
`[bluetooth_js]connect failed, code is
${
error
.
code
}
,message is
${
error
.
message
}
`
);
expect
(
error
.
code
).
assertEqual
(
'
2900099
'
);
}
try
{
gattClient
.
disconnect
();
gattClient
.
disconnect
();
expect
(
true
).
assertFalse
(
);
console
.
info
(
`[bluetooth_js]disconnect success`
);
}
catch
(
error
)
{
}
console
.
error
(
`[bluetooth_js]disconnect failed, code is
${
error
.
code
}
,
catch
(
error
)
{
message is
${
error
.
message
}
`
);
console
.
info
(
`[bluetooth_js]disconnect failed, code is
${
error
.
code
}
,
message is
${
error
.
message
}
`
);
expect
(
error
.
code
).
assertEqual
(
'
2900099
'
);
expect
(
error
.
code
).
assertEqual
(
'
2900099
'
);
}
}
done
()
done
()
;
})
})
/**
/**
...
@@ -147,28 +153,16 @@ describe('btManagerGattManagerTest', function() {
...
@@ -147,28 +153,16 @@ describe('btManagerGattManagerTest', function() {
*/
*/
it
(
'
SUB_COMMUNICATION_BTMANAGER_GETRSSIVALUE_0100
'
,
0
,
async
function
(
done
)
{
it
(
'
SUB_COMMUNICATION_BTMANAGER_GETRSSIVALUE_0100
'
,
0
,
async
function
(
done
)
{
try
{
try
{
await
gattClient
.
getRssiValue
().
then
((
data
)
=>
{
console
.
info
(
'
[bluetooth_js] BLE read rssi:
'
+
JSON
.
stringify
(
data
));
let
gattRssi
=
gattClient
.
getRssiValue
().
then
((
data
)
=>
{
expect
(
true
).
assertEqual
(
data
!=
null
);
console
.
info
(
'
[bluetooth_js] gattRssi:
'
+
gattRssi
);
done
();
console
.
info
(
'
[bluetooth_js] gattRssi data:
'
+
JSON
.
stringify
(
data
));
}).
catch
(
err
=>
{
})
console
.
info
(
'
bluetooth getRssiValue has error:
'
+
JSON
.
stringify
(
err
));
// expect(true).assertEqual(error.code==2900099||error.code==-1);
let
b
=
false
;
if
(
err
.
code
==
2900099
||
err
.
code
==-
1
)
{
b
=
true
}
expect
(
true
).
assertEqual
(
b
);
done
();
});
}
catch
(
error
)
{
}
catch
(
error
)
{
console
.
error
(
`[bluetooth_js]GetRssiValue_0100 error, code is
${
error
.
code
}
,
console
.
error
(
`[bluetooth_js]GetRssiValue_0100 error, code is
${
error
.
code
}
,message is
${
error
.
message
}
`
);
message is
${
error
.
message
}
`
);
expect
(
true
).
assertEqual
(
error
.
code
==
'
2900099
'
||
error
.
code
==
2900099
||
error
.
code
==
-
1
);
expect
(
false
).
assertEqual
(
true
);
done
()
}
}
done
();
})
})
/**
/**
...
@@ -195,7 +189,6 @@ describe('btManagerGattManagerTest', function() {
...
@@ -195,7 +189,6 @@ describe('btManagerGattManagerTest', function() {
else
else
{
{
console
.
info
(
'
[bluetooth_js]getRssi value:
'
+
JSON
.
stringify
(
data
));
console
.
info
(
'
[bluetooth_js]getRssi value:
'
+
JSON
.
stringify
(
data
));
expect
(
true
).
assertEqual
(
data
!=
null
);
}
}
resolve
();
resolve
();
});
});
...
@@ -203,11 +196,9 @@ describe('btManagerGattManagerTest', function() {
...
@@ -203,11 +196,9 @@ describe('btManagerGattManagerTest', function() {
}
}
await
getRssi
();
await
getRssi
();
}
catch
(
error
)
{
}
catch
(
error
)
{
console
.
error
(
`[bluetooth_js]GetRssiValue_0200 error, code is
${
error
.
code
}
,
console
.
error
(
`[bluetooth_js]GetRssiValue_0200 error, code is
${
error
.
code
}
,message is
${
error
.
message
}
`
);
message is
${
error
.
message
}
`
);
expect
(
error
.
code
).
assertEqual
(
'
2900099
'
);
expect
(
false
).
assertEqual
(
true
);
}
}
await
sleep
(
2000
);
done
();
done
();
})
})
...
@@ -250,14 +241,13 @@ describe('btManagerGattManagerTest', function() {
...
@@ -250,14 +241,13 @@ describe('btManagerGattManagerTest', function() {
console
.
info
(
'
[bluetooth_js]getname value:
'
+
JSON
.
stringify
(
data
));
console
.
info
(
'
[bluetooth_js]getname value:
'
+
JSON
.
stringify
(
data
));
expect
(
true
).
assertEqual
(
data
!=
null
);
expect
(
true
).
assertEqual
(
data
!=
null
);
});
});
await
sleep
(
2000
);
done
();
done
();
}
catch
(
error
)
{
}
catch
(
error
)
{
console
.
error
(
`[bluetooth_js]GetDeviceName_0200 failed, code is
${
error
.
code
}
,
console
.
error
(
`[bluetooth_js]GetDeviceName_0200 failed, code is
${
error
.
code
}
,
message is
${
error
.
message
}
`
);
message is
${
error
.
message
}
`
);
expect
(
error
.
code
).
assertEqual
(
'
2900099
'
);
expect
(
true
).
assertFals
e
();
don
e
();
done
()
}
}
done
();
})
})
/**
/**
...
@@ -279,11 +269,11 @@ describe('btManagerGattManagerTest', function() {
...
@@ -279,11 +269,11 @@ describe('btManagerGattManagerTest', function() {
done
();
done
();
});
});
}
catch
(
error
)
{
}
catch
(
error
)
{
console
.
error
(
`[bluetooth_js]GetService_0100 failed, code is
${
error
.
code
}
,
console
.
error
(
`[bluetooth_js]GetService_0100 failed, code is
${
error
.
code
}
,
message is
${
error
.
message
}
`
);
message is
${
error
.
message
}
`
);
expect
(
error
.
code
).
assertEqual
(
'
2900099
'
);
expect
(
true
).
assertFals
e
();
don
e
();
done
()
}
}
done
();
})
})
/**
/**
...
@@ -307,7 +297,7 @@ describe('btManagerGattManagerTest', function() {
...
@@ -307,7 +297,7 @@ describe('btManagerGattManagerTest', function() {
});
});
}
catch
(
error
)
{
}
catch
(
error
)
{
console
.
error
(
`[bluetooth_js]GetService_0200 failed, code is
${
error
.
code
}
,message is
${
error
.
message
}
`
);
console
.
error
(
`[bluetooth_js]GetService_0200 failed, code is
${
error
.
code
}
,message is
${
error
.
message
}
`
);
expect
(
true
).
assertFalse
(
);
expect
(
error
.
code
).
assertEqual
(
'
2900099
'
);
done
();
done
();
}
}
done
();
done
();
...
...
communication/bluetooth_gatt/src/main/js/test/List.test.js
浏览文件 @
ff96c6dc
...
@@ -19,12 +19,15 @@ import btGattServiceTest from './BtGattService.test.js'
...
@@ -19,12 +19,15 @@ import btGattServiceTest from './BtGattService.test.js'
import
btManagerGattAdvertTest
from
'
./BtManagerGattAdvertiser.test.js
'
import
btManagerGattAdvertTest
from
'
./BtManagerGattAdvertiser.test.js
'
import
btManagerGattManagerTest
from
'
./BtManagerGattManager.test.js
'
import
btManagerGattManagerTest
from
'
./BtManagerGattManager.test.js
'
import
btManagerGattServiceTest
from
'
./BtManagerGattService.test.js
'
import
btManagerGattServiceTest
from
'
./BtManagerGattService.test.js
'
import
btBleManagerTest
from
'
./BtBleManager.test.js
'
import
btBleServiceTest
from
'
./BtBleService.test.js
'
export
default
function
testsuite
()
{
export
default
function
testsuite
()
{
btGattAdvertTest
()
btBleManagerTest
()
btBleServiceTest
()
btManagerGattManagerTest
()
btManagerGattServiceTest
()
btManagerGattServiceTest
()
btGattServiceTest
()
btGattServiceTest
()
btManagerGattAdvertTest
()
btManagerGattManagerTest
()
btGattManagerTest
()
btGattManagerTest
()
btManagerGattAdvertTest
()
btGattAdvertTest
()
}
}
communication/bluetooth_profile/signature/openharmony_sx.p7b
浏览文件 @
ff96c6dc
无法预览此类型文件
communication/bluetooth_profile/src/main/config.json
浏览文件 @
ff96c6dc
...
@@ -106,10 +106,6 @@
...
@@ -106,10 +106,6 @@
"when"
:
"inuse"
"when"
:
"inuse"
}
}
},
},
{
"name"
:
"ohos.permission.GRANT_SENSITIVE_PERMISSIONS"
,
"reason"
:
"use ohos.permission.GRANT_SENSITIVE_PERMISSIONS"
},
{
{
"name"
:
"ohos.permission.DISCOVER_BLUETOOTH"
,
"name"
:
"ohos.permission.DISCOVER_BLUETOOTH"
,
"reason"
:
""
,
"reason"
:
""
,
...
@@ -129,6 +125,16 @@
...
@@ -129,6 +125,16 @@
],
],
"when"
:
"inuse"
"when"
:
"inuse"
}
}
},
{
"name"
:
"ohos.permission.ACCESS_BLUETOOTH"
,
"reason"
:
""
,
"usedScene"
:
{
"ability"
:
[
"ohos.acts.communication.bluetooth.bluetoothhost.MainAbility"
],
"when"
:
"inuse"
}
}
}
],
],
"testRunner"
:
{
"testRunner"
:
{
...
...
communication/bluetooth_profile/src/main/js/test/BtA2dp.test.js
0 → 100644
浏览文件 @
ff96c6dc
/*
* Copyright (C) 2022 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import
bluetooth
from
'
@ohos.bluetooth.a2dp
'
;
import
{
describe
,
beforeAll
,
beforeEach
,
afterEach
,
afterAll
,
it
,
expect
}
from
'
@ohos/hypium
'
export
default
function
btA2dpTest
()
{
describe
(
'
btA2dpTest
'
,
function
()
{
let
A2dpSourceProfile
=
null
;
function
sleep
(
delay
)
{
return
new
Promise
(
resovle
=>
setTimeout
(
resovle
,
delay
))
}
async
function
tryToEnableBt
()
{
let
sta
=
bluetooth
.
getState
();
switch
(
sta
)
{
case
0
:
bluetooth
.
enableBluetooth
();
await
sleep
(
10000
);
let
sta1
=
bluetooth
.
getState
();
console
.
info
(
'
[bluetooth_js] bt turn off:
'
+
JSON
.
stringify
(
sta1
));
break
;
case
1
:
console
.
info
(
'
[bluetooth_js] bt turning on:
'
+
JSON
.
stringify
(
sta
));
await
sleep
(
3000
);
break
;
case
2
:
console
.
info
(
'
[bluetooth_js] bt turn on:
'
+
JSON
.
stringify
(
sta
));
break
;
case
3
:
bluetooth
.
enableBluetooth
();
await
sleep
(
10000
);
let
sta2
=
bluetooth
.
getState
();
console
.
info
(
'
[bluetooth_js] bt turning off:
'
+
JSON
.
stringify
(
sta2
));
break
;
default
:
console
.
info
(
'
[bluetooth_js] enable success
'
);
}
}
beforeAll
(
function
()
{
console
.
info
(
'
beforeAll called
'
)
A2dpSourceProfile
=
bluetooth
.
createA2dpSrcProfile
();
})
beforeEach
(
async
function
(
done
)
{
console
.
info
(
'
beforeEach called
'
)
await
tryToEnableBt
()
done
();
})
afterEach
(
function
()
{
console
.
info
(
'
afterEach called
'
)
})
afterAll
(
function
()
{
console
.
info
(
'
afterAll called
'
)
})
/**
* @tc.number SUB_COMMUNICATION_BLUETOOTHA2DP_STATE_0100
* @tc.name test getPlayingState
* @tc.desc Test getPlayingState api10.
* @tc.type Function
* @tc.level Level 1
*/
it
(
'
SUB_COMMUNICATION_BLUETOOTHA2DP_STATE_0100
'
,
0
,
async
function
(
done
)
{
try
{
let
state
=
A2dpSourceProfile
.
getPlayingState
(
'
11:22:33:44:55:66
'
);
assert
(
true
).
assertEqual
(
state
==
bluetooth
.
PlayingState
.
STATE_NOT_PLAYING
||
state
==
bluetooth
.
PlayingState
.
STATE_PLAYING
);
}
catch
(
err
)
{
console
.
error
(
"
bluetooth a2dp getPlayingState errCode:
"
+
err
.
code
+
"
,bluetooth a2dp getPlayingState errMessage:
"
+
err
.
message
);
expect
(
err
.
code
).
assertEqual
(
'
2900099
'
);
}
done
();
})
/**
* @tc.number SUB_COMMUNICATION_BLUETOOTHA2DP_STATE_0200
* @tc.name test PlayingState
* @tc.desc Test PlayingState api10.
* @tc.type Function
* @tc.level Level 1
*/
it
(
'
SUB_COMMUNICATION_BLUETOOTHA2DP_STATE_0200
'
,
0
,
async
function
(
done
)
{
let
statePlaying
=
bluetooth
.
PlayingState
.
STATE_PLAYING
;
console
.
info
(
"
[bluetooth_js]PlayingState:
"
+
JSON
.
stringify
(
statePlaying
));
expect
(
statePlaying
).
assertEqual
(
1
);
let
stateNotPlaying
=
bluetooth
.
PlayingState
.
STATE_NOT_PLAYING
;
console
.
info
(
"
[bluetooth_js]PlayingState:
"
+
JSON
.
stringify
(
stateNotPlaying
));
expect
(
stateNotPlaying
).
assertEqual
(
0
);
done
();
})
})
}
\ No newline at end of file
communication/bluetooth_profile/src/main/js/test/BtBaseProfile.test.js
0 → 100644
浏览文件 @
ff96c6dc
/*
* Copyright (C) 2022 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import
btAccess
from
'
@ohos.bluetooth.access
'
;
import
a2dp
from
'
@ohos.bluetooth.a2dp
'
;
import
hid
from
'
@ohos.bluetooth.hid
'
;
import
hfp
from
'
@ohos.bluetooth.hfp
'
;
import
pan
from
'
@ohos.bluetooth.pan
'
;
import
{
describe
,
beforeAll
,
beforeEach
,
afterEach
,
afterAll
,
it
,
expect
}
from
'
@ohos/hypium
'
export
default
function
btBaseProfileTest
()
{
describe
(
'
btBaseProfileTest
'
,
function
()
{
let
A2dpSourceProfile
=
null
;
let
HandsFreeAudioGatewayProfile
=
null
;
let
HidHostProfile
=
null
;
let
PanProfile
=
null
;
function
sleep
(
delay
)
{
return
new
Promise
(
resovle
=>
setTimeout
(
resovle
,
delay
))
}
async
function
tryToEnableBt
()
{
let
sta
=
btAccess
.
getState
();
switch
(
sta
)
{
case
0
:
btAccess
.
enableBluetooth
();
await
sleep
(
10000
);
let
sta1
=
btAccess
.
getState
();
console
.
info
(
'
[bluetooth_js] bt turn off:
'
+
JSON
.
stringify
(
sta1
));
break
;
case
1
:
console
.
info
(
'
[bluetooth_js] bt turning on:
'
+
JSON
.
stringify
(
sta
));
await
sleep
(
3000
);
break
;
case
2
:
console
.
info
(
'
[bluetooth_js] bt turn on:
'
+
JSON
.
stringify
(
sta
));
break
;
case
3
:
btAccess
.
enableBluetooth
();
await
sleep
(
10000
);
let
sta2
=
btAccess
.
getState
();
console
.
info
(
'
[bluetooth_js] bt turning off:
'
+
JSON
.
stringify
(
sta2
));
break
;
default
:
console
.
info
(
'
[bluetooth_js] enable success
'
);
}
}
beforeAll
(
function
()
{
console
.
info
(
'
beforeAll called
'
)
A2dpSourceProfile
=
a2dp
.
createA2dpSrcProfile
();
HandsFreeAudioGatewayProfile
=
hfp
.
createHfpAgProfile
();
HidHostProfile
=
hid
.
createHidHostProfile
();
PanProfile
=
pan
.
createPanProfile
();
expect
(
true
).
assertEqual
(
A2dpSourceProfile
!=
null
&&
HandsFreeAudioGatewayProfile
!=
null
&&
HidHostProfile
!=
null
&&
PanProfile
!=
null
);
})
beforeEach
(
async
function
(
done
)
{
console
.
info
(
'
beforeEach called
'
)
await
tryToEnableBt
()
done
()
})
afterEach
(
function
()
{
console
.
info
(
'
afterEach called
'
)
})
afterAll
(
function
()
{
console
.
info
(
'
afterAll called
'
)
})
/**
* @tc.number SUB_COMMUNICATION_BLUETOOTH_BASEPROFILE_0100
* @tc.name test getConnectedDevices
* @tc.desc Test getConnectedDevices api10.
* @tc.type Function
* @tc.level Level 1
*/
it
(
'
SUB_COMMUNICATION_BLUETOOTH_BASEPROFILE_0100
'
,
0
,
async
function
(
done
)
{
try
{
let
devices
=
A2dpSourceProfile
.
getConnectedDevices
();
console
.
info
(
"
address of connected devices list:
"
+
devices
);
expect
(
true
).
assertEqual
(
devices
!=
null
);
}
catch
(
err
)
{
console
.
error
(
"
bluetooth getConnectedDevices errCode:
"
+
err
.
code
+
"
,errMessage:
"
+
err
.
message
);
expect
(
true
).
assertFalse
();
}
done
();
})
/**
* @tc.number SUB_COMMUNICATION_BLUETOOTH_BASEPROFILE_0200
* @tc.name test getConnectionState
* @tc.desc Test getConnectionState api10.
* @tc.type Function
* @tc.level Level 1
*/
it
(
'
SUB_COMMUNICATION_BLUETOOTH_BASEPROFILE_0200
'
,
0
,
async
function
(
done
)
{
try
{
let
state
=
A2dpSourceProfile
.
getConnectionState
(
"
11:22:33:AA:BB:FF
"
);
console
.
info
(
"
the connection state:
"
+
state
);
expect
(
true
).
assertEqual
(
state
==
0
||
state
==
1
||
state
==
2
);
}
catch
(
err
)
{
console
.
error
(
"
bluetooth getConnectionState errCode:
"
+
err
.
code
+
"
,errMessage:
"
+
err
.
message
);
expect
(
err
.
code
).
assertEqual
(
'
2900099
'
);
}
done
();
})
/**
* @tc.number SUB_COMMUNICATION_BLUETOOTH_BASEPROFILE_0300
* @tc.name test on type: 'connectionStateChange'
* @tc.desc Test on type: 'connectionStateChange' api10.
* @tc.type Function
* @tc.level Level 1
*/
it
(
'
SUB_COMMUNICATION_BLUETOOTH_BASEPROFILE_0300
'
,
0
,
async
function
(
done
)
{
function
onReceiveEvent
(
data
)
{
console
.
info
(
'
connection state change:
'
+
JSON
.
stringify
(
data
));
}
try
{
A2dpSourceProfile
.
on
(
'
connectionStateChange
'
,
onReceiveEvent
);
}
catch
(
err
)
{
console
.
error
(
"
bluetooth connectionStateChange errCode:
"
+
err
.
code
+
"
,errMessage:
"
+
err
.
message
);
expect
(
true
).
assertFalse
();
}
A2dpSourceProfile
.
off
(
'
connectionStateChange
'
,
onReceiveEvent
);
done
();
})
/**
* @tc.number SUB_COMMUNICATION_BLUETOOTH_BASEPROFILE_0400
* @tc.name test off type: 'connectionStateChange'
* @tc.desc Test off type: 'connectionStateChange' api10.
* @tc.type Function
* @tc.level Level 1
*/
it
(
'
SUB_COMMUNICATION_BLUETOOTH_BASEPROFILE_0400
'
,
0
,
async
function
(
done
)
{
function
onReceiveEvent
(
data
)
{
console
.
info
(
'
connection state change:
'
+
JSON
.
stringify
(
data
));
}
A2dpSourceProfile
.
on
(
'
connectionStateChange
'
,
onReceiveEvent
);
try
{
A2dpSourceProfile
.
off
(
'
connectionStateChange
'
,
onReceiveEvent
);
}
catch
(
err
)
{
console
.
error
(
"
bluetooth connectionStateChange errCode:
"
+
err
.
code
+
"
,errMessage:
"
+
err
.
message
);
expect
(
true
).
assertFalse
();
}
done
();
})
/**
* @tc.number SUB_COMMUNICATION_BLUETOOTH_BASEPROFILE_0500
* @tc.name test getConnectedDevices
* @tc.desc Test getConnectedDevices api10.
* @tc.type Function
* @tc.level Level 1
*/
it
(
'
SUB_COMMUNICATION_BLUETOOTH_BASEPROFILE_0500
'
,
0
,
async
function
(
done
)
{
try
{
let
devices
=
HandsFreeAudioGatewayProfile
.
getConnectedDevices
();
console
.
info
(
"
address of connected devices list:
"
+
devices
);
expect
(
true
).
assertEqual
(
devices
!=
null
);
}
catch
(
err
)
{
console
.
error
(
"
bluetooth getConnectedDevices errCode:
"
+
err
.
code
+
"
,errMessage:
"
+
err
.
message
);
expect
(
true
).
assertFalse
();
}
done
();
})
/**
* @tc.number SUB_COMMUNICATION_BLUETOOTH_BASEPROFILE_0600
* @tc.name test getConnectionState
* @tc.desc Test getConnectionState api10.
* @tc.type Function
* @tc.level Level 1
*/
it
(
'
SUB_COMMUNICATION_BLUETOOTH_BASEPROFILE_0600
'
,
0
,
async
function
(
done
)
{
try
{
let
state
=
HandsFreeAudioGatewayProfile
.
getConnectionState
(
"
11:22:33:AA:BB:FF
"
);
console
.
info
(
"
the connection state:
"
+
state
);
expect
(
true
).
assertEqual
(
state
==
0
||
state
==
1
||
state
==
2
);
}
catch
(
err
)
{
console
.
error
(
"
bluetooth getConnectionState errCode:
"
+
err
.
code
+
"
,errMessage:
"
+
err
.
message
);
expect
(
err
.
code
).
assertEqual
(
'
2900099
'
);
}
done
();
})
/**
* @tc.number SUB_COMMUNICATION_BLUETOOTH_BASEPROFILE_0700
* @tc.name test on type: 'connectionStateChange'
* @tc.desc Test on type: 'connectionStateChange' api10.
* @tc.type Function
* @tc.level Level 1
*/
it
(
'
SUB_COMMUNICATION_BLUETOOTH_BASEPROFILE_0700
'
,
0
,
async
function
(
done
)
{
function
onReceiveEvent
(
data
)
{
console
.
info
(
'
connection state change:
'
+
JSON
.
stringify
(
data
));
console
.
info
(
'
connection state change:
'
+
data
.
deviceId
);
console
.
info
(
'
connection state change:
'
+
data
.
state
);
}
try
{
HandsFreeAudioGatewayProfile
.
on
(
'
connectionStateChange
'
,
onReceiveEvent
);
}
catch
(
err
)
{
console
.
error
(
"
bluetooth connectionStateChange errCode:
"
+
err
.
code
+
"
,errMessage:
"
+
err
.
message
);
expect
(
true
).
assertFalse
();
}
HandsFreeAudioGatewayProfile
.
off
(
'
connectionStateChange
'
,
onReceiveEvent
);
done
();
})
/**
* @tc.number SUB_COMMUNICATION_BLUETOOTH_BASEPROFILE_0800
* @tc.name test off type: 'connectionStateChange'
* @tc.desc Test off type: 'connectionStateChange' api10.
* @tc.type Function
* @tc.level Level 1
*/
it
(
'
SUB_COMMUNICATION_BLUETOOTH_BASEPROFILE_0800
'
,
0
,
async
function
(
done
)
{
function
onReceiveEvent
(
data
)
{
console
.
info
(
'
connection state change:
'
+
JSON
.
stringify
(
data
));
}
HandsFreeAudioGatewayProfile
.
on
(
'
connectionStateChange
'
,
onReceiveEvent
);
try
{
HandsFreeAudioGatewayProfile
.
off
(
'
connectionStateChange
'
,
onReceiveEvent
);
}
catch
(
err
)
{
console
.
error
(
"
bluetooth connectionStateChange errCode:
"
+
err
.
code
+
"
,errMessage:
"
+
err
.
message
);
expect
(
true
).
assertFalse
();
}
done
();
})
/**
* @tc.number SUB_COMMUNICATION_BLUETOOTH_BASEPROFILE_0900
* @tc.name test getConnectedDevices
* @tc.desc Test getConnectedDevices api10.
* @tc.type Function
* @tc.level Level 1
*/
it
(
'
SUB_COMMUNICATION_BLUETOOTH_BASEPROFILE_0900
'
,
0
,
async
function
(
done
)
{
try
{
let
devices
=
HidHostProfile
.
getConnectedDevices
();
console
.
info
(
"
address of connected devices list:
"
+
devices
);
expect
(
true
).
assertEqual
(
devices
!=
null
);
}
catch
(
err
)
{
console
.
error
(
"
bluetooth getConnectedDevices errCode:
"
+
err
.
code
+
"
,errMessage:
"
+
err
.
message
);
expect
(
true
).
assertFalse
();
}
done
();
})
/**
* @tc.number SUB_COMMUNICATION_BLUETOOTH_BASEPROFILE_1000
* @tc.name test getConnectionState
* @tc.desc Test getConnectionState api10.
* @tc.type Function
* @tc.level Level 1
*/
it
(
'
SUB_COMMUNICATION_BLUETOOTH_BASEPROFILE_1000
'
,
0
,
async
function
(
done
)
{
try
{
let
state
=
HidHostProfile
.
getConnectionState
(
"
11:22:33:AA:BB:FF
"
);
console
.
info
(
"
the connection state:
"
+
state
);
expect
(
true
).
assertEqual
(
state
==
0
||
state
==
1
||
state
==
2
);
}
catch
(
err
)
{
console
.
error
(
"
bluetooth getConnectionState errCode:
"
+
err
.
code
+
"
,errMessage:
"
+
err
.
message
);
expect
(
err
.
code
).
assertEqual
(
'
2900099
'
);
}
done
();
})
/**
* @tc.number SUB_COMMUNICATION_BLUETOOTH_BASEPROFILE_1100
* @tc.name test on type: 'connectionStateChange'
* @tc.desc Test on type: 'connectionStateChange' api10.
* @tc.type Function
* @tc.level Level 1
*/
it
(
'
SUB_COMMUNICATION_BLUETOOTH_BASEPROFILE_1100
'
,
0
,
async
function
(
done
)
{
function
onReceiveEvent
(
data
)
{
console
.
info
(
'
connection state change:
'
+
JSON
.
stringify
(
data
));
}
try
{
HidHostProfile
.
on
(
'
connectionStateChange
'
,
onReceiveEvent
);
}
catch
(
err
)
{
console
.
error
(
"
bluetooth connectionStateChange errCode:
"
+
err
.
code
+
"
,errMessage:
"
+
err
.
message
);
expect
(
true
).
assertFalse
();
}
HidHostProfile
.
off
(
'
connectionStateChange
'
,
onReceiveEvent
);
done
();
})
/**
* @tc.number SUB_COMMUNICATION_BLUETOOTH_BASEPROFILE_1200
* @tc.name test off type: 'connectionStateChange'
* @tc.desc Test off type: 'connectionStateChange' api10.
* @tc.type Function
* @tc.level Level 1
*/
it
(
'
SUB_COMMUNICATION_BLUETOOTH_BASEPROFILE_1200
'
,
0
,
async
function
(
done
)
{
function
onReceiveEvent
(
data
)
{
console
.
info
(
'
connection state change:
'
+
JSON
.
stringify
(
data
));
}
HidHostProfile
.
on
(
'
connectionStateChange
'
,
onReceiveEvent
);
try
{
HidHostProfile
.
off
(
'
connectionStateChange
'
,
onReceiveEvent
);
}
catch
(
err
)
{
console
.
error
(
"
bluetooth connectionStateChange errCode:
"
+
err
.
code
+
"
,errMessage:
"
+
err
.
message
);
expect
(
true
).
assertFalse
();
}
done
();
})
/**
* @tc.number SUB_COMMUNICATION_BLUETOOTH_BASEPROFILE_1300
* @tc.name test getConnectedDevices
* @tc.desc Test getConnectedDevices api10.
* @tc.type Function
* @tc.level Level 1
*/
it
(
'
SUB_COMMUNICATION_BLUETOOTH_BASEPROFILE_1300
'
,
0
,
async
function
(
done
)
{
try
{
let
devices
=
PanProfile
.
getConnectedDevices
();
console
.
info
(
"
address of connected devices list:
"
+
devices
);
expect
(
true
).
assertEqual
(
devices
!=
null
);
}
catch
(
err
)
{
console
.
error
(
"
bluetooth getConnectedDevices errCode:
"
+
err
.
code
+
"
,errMessage:
"
+
err
.
message
);
expect
(
true
).
assertFalse
();
}
done
();
})
/**
* @tc.number SUB_COMMUNICATION_BLUETOOTH_BASEPROFILE_1400
* @tc.name test getConnectionState
* @tc.desc Test getConnectionState api10.
* @tc.type Function
* @tc.level Level 1
*/
it
(
'
SUB_COMMUNICATION_BLUETOOTH_BASEPROFILE_1400
'
,
0
,
async
function
(
done
)
{
try
{
let
state
=
PanProfile
.
getConnectionState
(
"
11:22:33:AA:BB:FF
"
);
console
.
info
(
"
the connection state:
"
+
state
);
expect
(
true
).
assertEqual
(
state
==
0
||
state
==
1
||
state
==
2
);
}
catch
(
err
)
{
console
.
error
(
"
bluetooth getConnectionState errCode:
"
+
err
.
code
+
"
,errMessage:
"
+
err
.
message
);
expect
(
err
.
code
).
assertEqual
(
'
2900099
'
);
}
done
();
})
/**
* @tc.number SUB_COMMUNICATION_BLUETOOTH_BASEPROFILE_1500
* @tc.name test on type: 'connectionStateChange'
* @tc.desc Test on type: 'connectionStateChange' api10.
* @tc.type Function
* @tc.level Level 1
*/
it
(
'
SUB_COMMUNICATION_BLUETOOTH_BASEPROFILE_1500
'
,
0
,
async
function
(
done
)
{
function
onReceiveEvent
(
data
)
{
console
.
info
(
'
connection state change:
'
+
JSON
.
stringify
(
data
));
}
try
{
PanProfile
.
on
(
'
connectionStateChange
'
,
onReceiveEvent
);
}
catch
(
err
)
{
console
.
error
(
"
bluetooth connectionStateChange errCode:
"
+
err
.
code
+
"
,errMessage:
"
+
err
.
message
);
expect
(
true
).
assertFalse
();
}
PanProfile
.
off
(
'
connectionStateChange
'
,
onReceiveEvent
);
done
();
})
/**
* @tc.number SUB_COMMUNICATION_BLUETOOTH_BASEPROFILE_1600
* @tc.name test off type: 'connectionStateChange'
* @tc.desc Test off type: 'connectionStateChange' api10.
* @tc.type Function
* @tc.level Level 1
*/
it
(
'
SUB_COMMUNICATION_BLUETOOTH_BASEPROFILE_1600
'
,
0
,
async
function
(
done
)
{
function
onReceiveEvent
(
data
)
{
console
.
info
(
'
connection state change:
'
+
JSON
.
stringify
(
data
));
}
PanProfile
.
on
(
'
connectionStateChange
'
,
onReceiveEvent
);
try
{
PanProfile
.
off
(
'
connectionStateChange
'
,
onReceiveEvent
);
}
catch
(
err
)
{
console
.
error
(
"
bluetooth connectionStateChange errCode:
"
+
err
.
code
+
"
,errMessage:
"
+
err
.
message
);
expect
(
true
).
assertFalse
();
}
done
();
})
/**
* @tc.number SUB_COMMUNICATION_BLUETOOTH_BASEPROFILE_1700
* @tc.name test createA2dpSrcProfile/createHfpAgProfile/createHidHostProfile/createPanProfile
* @tc.desc Test createA2dpSrcProfile/createHfpAgProfile/createHidHostProfile/createPanProfile api10.
* @tc.type Function
* @tc.level Level 1
*/
it
(
'
SUB_COMMUNICATION_BLUETOOTHA2DP_STATE_1700
'
,
0
,
async
function
(
done
)
{
try
{
let
asp
=
a2dp
.
createA2dpSrcProfile
();
let
hp
=
hfp
.
createHfpAgProfile
();
let
hhp
=
hid
.
createHidHostProfile
();
let
pp
=
pan
.
createPanProfile
();
expect
(
true
).
assertEqual
(
asp
!=
null
);
expect
(
true
).
assertEqual
(
hp
!=
null
);
expect
(
true
).
assertEqual
(
hhp
!=
null
);
expect
(
true
).
assertEqual
(
pp
!=
null
);
}
catch
(
err
)
{
console
.
error
(
"
bluetooth createProfile errCode:
"
+
err
.
code
+
"
,errMessage:
"
+
err
.
message
);
expect
(
err
.
code
).
assertEqual
(
'
2900099
'
);
}
done
();
})
})
}
\ No newline at end of file
communication/bluetooth_profile/src/main/js/test/List.test.js
浏览文件 @
ff96c6dc
...
@@ -17,9 +17,13 @@ import btHfpConnTest from './BluetoothHfp.test.js'
...
@@ -17,9 +17,13 @@ import btHfpConnTest from './BluetoothHfp.test.js'
import
btA2dpConnTest
from
'
./BluetoothA2dp.test.js
'
import
btA2dpConnTest
from
'
./BluetoothA2dp.test.js
'
import
btManagerHfpConnTest
from
'
./BtManagerHfp.test.js
'
import
btManagerHfpConnTest
from
'
./BtManagerHfp.test.js
'
import
btManagerA2dpConnTest
from
'
./BtManagerA2dp.test.js
'
import
btManagerA2dpConnTest
from
'
./BtManagerA2dp.test.js
'
import
btA2dpTest
from
'
./BtA2dp.test.js
'
import
btBaseProfileTest
from
'
./BtBaseProfile.test.js
'
export
default
function
testsuite
()
{
export
default
function
testsuite
()
{
btBaseProfileTest
()
btHfpConnTest
()
btHfpConnTest
()
btA2dpConnTest
()
btA2dpConnTest
()
btManagerHfpConnTest
()
btManagerHfpConnTest
()
btManagerA2dpConnTest
()
btManagerA2dpConnTest
()
btA2dpTest
()
}
}
communication/bluetooth_scanpairing/signature/openharmony_sx.p7b
浏览文件 @
ff96c6dc
无法预览此类型文件
communication/bluetooth_scanpairing/src/main/config.json
浏览文件 @
ff96c6dc
...
@@ -106,10 +106,6 @@
...
@@ -106,10 +106,6 @@
"when"
:
"inuse"
"when"
:
"inuse"
}
}
},
},
{
"name"
:
"ohos.permission.GRANT_SENSITIVE_PERMISSIONS"
,
"reason"
:
"use ohos.permission.GRANT_SENSITIVE_PERMISSIONS"
},
{
{
"name"
:
"ohos.permission.DISCOVER_BLUETOOTH"
,
"name"
:
"ohos.permission.DISCOVER_BLUETOOTH"
,
"reason"
:
""
,
"reason"
:
""
,
...
@@ -129,6 +125,24 @@
...
@@ -129,6 +125,24 @@
],
],
"when"
:
"inuse"
"when"
:
"inuse"
}
}
},
{
"name"
:
"ohos.permission.ACCESS_BLUETOOTH"
,
"reason"
:
""
,
"usedScene"
:
{
"ability"
:
[
"ohos.acts.communication.bluetooth.bluetoothhost.MainAbility"
],
"when"
:
"inuse"
}
},
{
"name"
:
"ohos.permission.GRANT_SENSITIVE_PERMISSIONS"
,
"reason"
:
""
},
{
"name"
:
"ohos.permission.REVOKE_SENSITIVE_PERMISSIONS"
,
"reason"
:
""
}
}
],
],
"testRunner"
:
{
"testRunner"
:
{
...
...
communication/bluetooth_scanpairing/src/main/js/test/BluetoothBle.test.js
0 → 100644
浏览文件 @
ff96c6dc
/*
* Copyright (C) 2022 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import
bluetooth
from
'
@ohos.bluetooth.ble
'
;
import
btAccess
from
'
@ohos.bluetooth.access
'
;
import
{
describe
,
beforeAll
,
beforeEach
,
afterEach
,
afterAll
,
it
,
expect
}
from
'
@ohos/hypium
'
export
default
function
bluetoothBleTest
()
{
describe
(
'
bluetoothBleTest
'
,
function
()
{
function
sleep
(
delay
)
{
return
new
Promise
(
resovle
=>
setTimeout
(
resovle
,
delay
))
}
async
function
tryToEnableBt
()
{
let
sta
=
btAccess
.
getState
();
switch
(
sta
){
case
0
:
btAccess
.
enableBluetooth
();
await
sleep
(
10000
);
let
sta1
=
btAccess
.
getState
();
console
.
info
(
'
[bluetooth_js] bt turn off:
'
+
JSON
.
stringify
(
sta1
));
break
;
case
1
:
console
.
info
(
'
[bluetooth_js] bt turning on:
'
+
JSON
.
stringify
(
sta
));
await
sleep
(
3000
);
break
;
case
2
:
console
.
info
(
'
[bluetooth_js] bt turn on:
'
+
JSON
.
stringify
(
sta
));
break
;
case
3
:
btAccess
.
enableBluetooth
();
await
sleep
(
10000
);
let
sta2
=
btAccess
.
getState
();
console
.
info
(
'
[bluetooth_js] bt turning off:
'
+
JSON
.
stringify
(
sta2
));
break
;
default
:
console
.
info
(
'
[bluetooth_js] enable success
'
);
}
}
beforeAll
(
function
()
{
console
.
info
(
'
beforeAll called
'
)
})
beforeEach
(
async
function
(
done
)
{
console
.
info
(
'
beforeEach called
'
)
await
tryToEnableBt
()
done
();
})
afterEach
(
function
()
{
console
.
info
(
'
afterEach called
'
)
})
afterAll
(
function
()
{
console
.
info
(
'
afterAll called
'
)
})
/**
* @tc.number SUB_COMMUNICATION_BLUETOOTHBLE_BLESCAN_0100
* @tc.name test startBLEScan
* @tc.desc Test startBLEScan api10
* @tc.type Function
* @tc.level Level 0
*/
it
(
'
SUB_COMMUNICATION_BLUETOOTHBLE_BLESCAN_0100
'
,
0
,
async
function
(
done
)
{
function
onReceiveEvent
(
data
)
{
console
.
info
(
'
BLE scan device find result =
'
+
JSON
.
stringify
(
data
));
}
try
{
bluetooth
.
on
(
"
BLEDeviceFind
"
,
onReceiveEvent
);
bluetooth
.
startBLEScan
(
[{
deviceId
:
"
00:11:22:33:44:55
"
,
name
:
"
test
"
,
serviceUuid
:
"
00001888-0000-1000-8000-00805f9b34fb
"
}],
{
interval
:
500
,
dutyMode
:
bluetooth
.
ScanDuty
.
SCAN_MODE_LOW_POWER
,
matchMode
:
bluetooth
.
MatchMode
.
MATCH_MODE_AGGRESSIVE
,
}
);
}
catch
(
err
)
{
console
.
error
(
"
errCode:
"
+
err
.
code
+
"
,errMessage:
"
+
err
.
message
);
expect
(
err
.
code
).
assertEqual
(
'
2900099
'
);
}
bluetooth
.
off
(
"
BLEDeviceFind
"
,
onReceiveEvent
);
done
();
})
/**
* @tc.number SUB_COMMUNICATION_BLUETOOTHBLE_BLESCAN_0200
* @tc.name test stopBLEScan
* @tc.desc Test stopBLEScan api10
* @tc.type Function
* @tc.level Level 0
*/
it
(
'
SUB_COMMUNICATION_BLUETOOTHBLE_BLESCAN_0200
'
,
0
,
async
function
(
done
)
{
try
{
bluetooth
.
stopBLEScan
();
}
catch
(
err
)
{
console
.
error
(
"
errCode:
"
+
err
.
code
+
"
,errMessage:
"
+
err
.
message
);
expect
(
err
.
code
).
assertEqual
(
'
2900099
'
);
}
done
();
})
/**
* @tc.number SUB_COMMUNICATION_BLUETOOTHBLE_BLESCAN_0300
* @tc.name test on-BLEDeviceFind
* @tc.desc Test on-BLEDeviceFind api10
* @tc.type Function
* @tc.level Level 0
*/
it
(
'
SUB_COMMUNICATION_BLUETOOTHBLE_BLESCAN_0300
'
,
0
,
async
function
(
done
)
{
function
onReceiveEvent
(
data
)
{
console
.
info
(
'
bluetooth device find =
'
+
JSON
.
stringify
(
data
));
}
try
{
bluetooth
.
on
(
'
BLEDeviceFind
'
,
onReceiveEvent
);
}
catch
(
err
)
{
console
.
error
(
"
errCode:
"
+
err
.
code
+
"
,errMessage:
"
+
err
.
message
);
expect
(
err
.
code
).
assertEqual
(
'
2900099
'
);
}
bluetooth
.
off
(
'
BLEDeviceFind
'
,
onReceiveEvent
);
done
();
})
/**
* @tc.number SUB_COMMUNICATION_BLUETOOTHBLE_BLESCAN_0400
* @tc.name test off-BLEDeviceFind
* @tc.desc Test off-BLEDeviceFind api10
* @tc.type Function
* @tc.level Level 0
*/
it
(
'
SUB_COMMUNICATION_BLUETOOTHBLE_BLESCAN_0400
'
,
0
,
async
function
(
done
)
{
function
onReceiveEvent
(
data
)
{
console
.
info
(
'
bluetooth device find =
'
+
JSON
.
stringify
(
data
));
}
bluetooth
.
on
(
'
BLEDeviceFind
'
,
onReceiveEvent
);
try
{
bluetooth
.
off
(
'
BLEDeviceFind
'
,
onReceiveEvent
);
}
catch
(
err
)
{
console
.
error
(
"
errCode:
"
+
err
.
code
+
"
,errMessage:
"
+
err
.
message
);
expect
(
err
.
code
).
assertEqual
(
'
2900099
'
);
}
done
();
})
})
}
communication/bluetooth_scanpairing/src/main/js/test/BtConnection.test.js
0 → 100644
浏览文件 @
ff96c6dc
/*
* Copyright (C) 2022 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import
bluetooth
from
'
@ohos.bluetooth.connection
'
;
import
btAccess
from
'
@ohos.bluetooth.access
'
;
import
{
describe
,
beforeAll
,
beforeEach
,
afterEach
,
afterAll
,
it
,
expect
}
from
'
@ohos/hypium
'
export
default
function
btConnectionTest
()
{
describe
(
'
btConnectionTest
'
,
function
()
{
let
Btname
=
{
LETTERS_TEST
:
'
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
'
,
CHINESES_TEST2
:
'
测试蓝牙名称正常
'
,
}
function
sleep
(
delay
)
{
return
new
Promise
(
resovle
=>
setTimeout
(
resovle
,
delay
))
}
async
function
tryToEnableBt
()
{
let
sta
=
btAccess
.
getState
();
switch
(
sta
)
{
case
0
:
btAccess
.
enableBluetooth
();
await
sleep
(
10000
);
let
sta1
=
btAccess
.
getState
();
console
.
info
(
'
[bluetooth_js] bt turn off:
'
+
JSON
.
stringify
(
sta1
));
break
;
case
1
:
console
.
info
(
'
[bluetooth_js] bt turning on:
'
+
JSON
.
stringify
(
sta
));
await
sleep
(
3000
);
break
;
case
2
:
console
.
info
(
'
[bluetooth_js] bt turn on:
'
+
JSON
.
stringify
(
sta
));
break
;
case
3
:
btAccess
.
enableBluetooth
();
await
sleep
(
10000
);
let
sta2
=
btAccess
.
getState
();
console
.
info
(
'
[bluetooth_js] bt turning off:
'
+
JSON
.
stringify
(
sta2
));
break
;
default
:
console
.
info
(
'
[bluetooth_js] enable success
'
);
}
}
beforeAll
(
function
()
{
console
.
info
(
'
beforeAll called
'
)
})
beforeEach
(
async
function
(
done
)
{
console
.
info
(
'
beforeEach called
'
)
await
tryToEnableBt
()
done
()
})
afterEach
(
function
()
{
console
.
info
(
'
afterEach called
'
)
})
afterAll
(
function
()
{
console
.
info
(
'
afterAll called
'
)
})
/**
* @tc.number SUB_COMMUNICATION_BLUETOOTHCONNECTION_PAIR_0100
* @tc.name Test pinRequired and setDevicePairing true
* @tc.desc Test pinRequired off api10
* @tc.type Function
* @tc.level Level 3
*/
it
(
'
SUB_COMMUNICATION_BLUETOOTHCONNECTION_PAIR_0100
'
,
0
,
async
function
(
done
)
{
function
onReceiveEvent
(
data
)
{
console
.
info
(
'
pin required =
'
+
JSON
.
stringify
(
data
));
}
try
{
bluetooth
.
on
(
'
pinRequired
'
,
onReceiveEvent
);
bluetooth
.
off
(
'
pinRequired
'
,
onReceiveEvent
);
}
catch
(
error
)
{
console
.
error
(
`[bluetooth_js]PairDevice error, code is
${
error
.
code
}
,
message is
${
error
.
message
}
`
);
expect
(
error
.
code
).
assertEqual
(
'
2900099
'
);
}
done
();
})
/**
* @tc.number SUB_COMMUNICATION_BLUETOOTHCONNECTION_PAIR_0200
* @tc.name test get PairedDevices
* @tc.desc Test getPairedDevices api10
* @tc.type Function
* @tc.level Level 3
*/
it
(
'
SUB_COMMUNICATION_BLUETOOTHCONNECTION_PAIR_0200
'
,
0
,
async
function
(
done
)
{
try
{
let
ret
=
bluetooth
.
getPairedDevices
();
console
.
info
(
'
[bluetooth_js] getPairedDevices ret2:
'
+
JSON
.
stringify
(
ret
));
expect
(
true
).
assertEqual
(
ret
.
length
>=
0
);
}
catch
(
err
)
{
console
.
error
(
"
errCode:
"
+
err
.
code
+
"
,errMessage:
"
+
err
.
message
);
expect
(
err
.
code
).
assertEqual
(
'
2900099
'
);
}
done
();
})
/**
* @tc.number SUB_COMMUNICATION_BLUETOOTHCONNECTION_PAIR_0300
* @tc.name test getRemoteDeviceName
* @tc.desc Test get RemoteDeviceName api 10
* @tc.type Function
* @tc.level Level 3
*/
it
(
'
SUB_COMMUNICATION_BLUETOOTHCONNECTION_PAIR_0300
'
,
0
,
async
function
(
done
)
{
try
{
let
ret
=
bluetooth
.
getRemoteDeviceName
(
"
00:00:00:00:00:00
"
);
console
.
info
(
'
[bluetooth_js] getRemoteDeviceName ret2:
'
+
JSON
.
stringify
(
ret
));
}
catch
(
err
)
{
console
.
error
(
"
errCode:
"
+
err
.
code
+
"
,errMessage:
"
+
err
.
message
);
expect
(
err
.
code
).
assertEqual
(
'
2900099
'
);
}
done
();
})
/**
* @tc.number SUB_COMMUNICATION_BLUETOOTHCONNECTION_PAIR_0400
* @tc.name Test On pair StateChange
* @tc.desc Test bondStateChange ON api10
* @tc.type Function
* @tc.level Level 3
*/
it
(
'
SUB_COMMUNICATION_BLUETOOTHCONNECTION_PAIR_0400
'
,
0
,
async
function
(
done
)
{
function
BondStateParam
(
data
)
{
console
.
info
(
"
[bluetooth_js] bondStateChange on:
"
+
JSON
.
stringify
(
data
)
+
'
bondStateChange deviceId:
'
+
data
.
deviceId
+
'
bondStateChange state:
'
+
data
.
state
);
}
try
{
bluetooth
.
on
(
'
bondStateChange
'
,
BondStateParam
);
bluetooth
.
pairDevice
(
"
11:22:55:66:33:44
"
);
expect
(
bluetooth
.
BondState
.
BOND_STATE_INVALID
==
0
).
assertTrue
();
expect
(
bluetooth
.
BondState
.
BOND_STATE_BONDING
==
1
).
assertTrue
();
expect
(
bluetooth
.
BondState
.
BOND_STATE_BONDED
==
2
).
assertTrue
();
bluetooth
.
off
(
'
bondStateChange
'
,
BondStateParam
);
}
catch
(
err
)
{
console
.
error
(
"
errCode:
"
+
err
.
code
+
"
,errMessage:
"
+
err
.
message
);
expect
(
error
.
code
).
assertEqual
(
'
2900099
'
);
}
done
();
})
/**
* @tc.number SUB_COMMUNICATION_BLUETOOTHCONNECTION_PAIR_0500
* @tc.name Test setDevicePairingConfirmation
* @tc.desc Test setDevicePairingConfirmation api10
* @tc.type Function
* @tc.level Level 3
*/
it
(
'
SUB_COMMUNICATION_BLUETOOTHCONNECTION_PAIR_0500
'
,
0
,
async
function
(
done
)
{
function
PinRequiredParam
(
data
)
{
console
.
info
(
"
[bluetooth_js] pinRequired on:
"
+
JSON
.
stringify
(
data
));
bluetooth
.
setDevicePairingConfirmation
(
data
.
deviceId
,
false
);
console
.
info
(
"
[bluetooth_js] setDevicePairingConfirmation data.deviceId:
"
+
data
.
deviceId
);
}
try
{
bluetooth
.
on
(
'
pinRequired
'
,
PinRequiredParam
);
await
sleep
(
2000
);
bluetooth
.
off
(
'
pinRequired
'
,
PinRequiredParam
);
}
catch
(
err
)
{
console
.
error
(
"
setDevicePairingConfirmation errCode:
"
+
err
.
code
+
"
,errMessage:
"
+
err
.
message
);
expect
(
err
.
code
).
assertEqual
(
'
2900099
'
);
}
done
();
})
/**
* @tc.number SUB_COMMUNICATION_BLUETOOTHCONNECTION_PAIR_0600
* @tc.name test getRemoteDeviceClass
* @tc.desc Test get RemoteDeviceClass api10
* @tc.type Function
* @tc.level Level 1
*/
it
(
'
SUB_COMMUNICATION_BLUETOOTHCONNECTION_PAIR_0600
'
,
0
,
async
function
(
done
)
{
try
{
let
DeviceClass
=
bluetooth
.
getRemoteDeviceClass
(
"
00:00:00:00:00:00
"
);
console
.
info
(
'
[bluetooth_js]getRemoteDeviceClass majorClass:
'
+
DeviceClass
.
majorClass
);
console
.
info
(
'
[bluetooth_js]getRemoteDeviceClass majorMinorClass:
'
+
DeviceClass
.
majorMinorClass
);
console
.
info
(
'
[bluetooth_js]getRemoteDeviceClass classOfDevice:
'
+
DeviceClass
.
classOfDevice
);
}
catch
(
err
)
{
console
.
error
(
"
getRemoteDeviceClass errCode:
"
+
err
.
code
+
"
,errMessage:
"
+
err
.
message
);
expect
(
err
.
code
).
assertEqual
(
'
2900099
'
);
}
done
();
})
/**
* @tc.number SUB_COMMUNICATION_BLUETOOTHCONNECTION_PAIR_0700
* @tc.name Test setDevicePinCode callback
* @tc.desc Test setDevicePinCode api10
* @tc.type Function
* @tc.level Level 3
*/
it
(
'
SUB_COMMUNICATION_BLUETOOTHCONNECTION_PAIR_0700
'
,
0
,
async
function
(
done
)
{
try
{
bluetooth
.
setDevicePinCode
(
'
11:22:33:44:55:66
'
,
'
12345
'
,
(
err
,
data
)
=>
{
console
.
info
(
'
setDevicePinCode callback,device name err:
'
+
JSON
.
stringify
(
err
)
+
'
,device name:
'
+
JSON
.
stringify
(
data
));
});
}
catch
(
err
)
{
console
.
error
(
"
setDevicePinCode callback errCode:
"
+
err
.
code
+
"
,errMessage:
"
+
err
.
message
);
expect
(
err
.
code
).
assertEqual
(
'
2900099
'
);
}
done
();
})
/**
* @tc.number SUB_COMMUNICATION_BLUETOOTHCONNECTION_PAIR_0800
* @tc.name Test setDevicePinCode promise
* @tc.desc Test setDevicePinCode api10
* @tc.type Function
* @tc.level Level 3
*/
it
(
'
SUB_COMMUNICATION_BLUETOOTHCONNECTION_PAIR_0800
'
,
0
,
async
function
(
done
)
{
try
{
bluetooth
.
setDevicePinCode
(
'
11:22:33:44:55:66
'
,
'
12345
'
).
then
(()
=>
{
console
.
info
(
'
setDevicePinCode promise
'
);
},
error
=>
{
console
.
info
(
'
setDevicePinCode promise: errCode:
'
+
error
.
code
+
'
,errMessage
'
+
error
.
message
);
})
}
catch
(
err
)
{
console
.
error
(
"
setDevicePinCode promise errCode:
"
+
err
.
code
+
"
,errMessage:
"
+
err
.
message
);
expect
(
err
.
code
).
assertEqual
(
'
2900099
'
);
}
done
();
})
/**
* @tc.number SUB_COMMUNICATION_BLUETOOTHCONNECTION_SCANMODE_0100
* @tc.name TEST scanmode
* @tc.desc TEST scanmode api10 by promise.
* @tc.type Function
* @tc.level Level 2
*/
it
(
'
SUB_COMMUNICATION_BLUETOOTHCONNECTION_SCANMODE_0100
'
,
0
,
async
function
(
done
)
{
let
state
=
btAccess
.
getState
();
console
.
info
(
'
[bluetooth_js] get bluetooth state001
'
+
JSON
.
stringify
(
state
));
if
(
state
==
2
)
{
let
oldScanMode
=
bluetooth
.
getBluetoothScanMode
();
console
.
info
(
'
[bluetooth_js] ScanMode_0100 oldScanMode =
'
+
JSON
.
stringify
(
oldScanMode
));
let
result
=
bluetooth
.
setBluetoothScanMode
(
bluetooth
.
ScanMode
.
SCAN_MODE_NONE
,
0
);
expect
(
result
).
assertTrue
();
let
getScanMode
=
bluetooth
.
getBluetoothScanMode
();
console
.
info
(
'
[bluetooth_js] ScanMode_0100 newscanmode =
'
+
JSON
.
stringify
(
getScanMode
));
expect
(
true
).
assertEqual
(
getScanMode
==
bluetooth
.
ScanMode
.
SCAN_MODE_NONE
);
result
=
bluetooth
.
setBluetoothScanMode
(
oldScanMode
,
0
);
expect
(
result
).
assertTrue
();
let
getOldScanMode
=
bluetooth
.
getBluetoothScanMode
();
console
.
info
(
'
[bluetooth_js] ScanMode_0100 setoldscanmode =
'
+
JSON
.
stringify
(
getOldScanMode
));
expect
(
true
).
assertEqual
(
oldScanMode
==
getOldScanMode
);
done
();
}
else
{
console
.
info
(
'
[bluetooth_js] bluetooth switch off,state is =
'
+
JSON
.
stringify
(
state
));
expect
(
true
).
assertFalse
();
done
();
}
})
/**
* @tc.number SUB_COMMUNICATION_BLUETOOTHCONNECTION_SCANMODE_0200
* @tc.name TEST scanmode
* @tc.desc TEST scanmode api by promise.
* @tc.type Function
* @tc.level Level 2
*/
it
(
'
SUB_COMMUNICATION_BLUETOOTHCONNECTION_SCANMODE_0200
'
,
0
,
async
function
(
done
)
{
let
state
=
btAccess
.
getState
();
console
.
info
(
'
[bluetooth_js] get bluetooth state001
'
+
JSON
.
stringify
(
state
));
if
(
state
==
2
)
{
let
oldScanMode
=
bluetooth
.
getBluetoothScanMode
();
console
.
info
(
'
[bluetooth_js] ScanMode_0200 oldScanMode =
'
+
JSON
.
stringify
(
oldScanMode
));
let
result
=
bluetooth
.
setBluetoothScanMode
(
bluetooth
.
ScanMode
.
SCAN_MODE_LIMITED_DISCOVERABLE
,
0
);
expect
(
result
).
assertTrue
();
let
getScanMode
=
bluetooth
.
getBluetoothScanMode
();
console
.
info
(
'
[bluetooth_js] ScanMode_0200 newscanmode =
'
+
JSON
.
stringify
(
getScanMode
));
expect
(
true
).
assertEqual
(
getScanMode
==
bluetooth
.
ScanMode
.
SCAN_MODE_LIMITED_DISCOVERABLE
);
result
=
bluetooth
.
setBluetoothScanMode
(
oldScanMode
,
0
);
expect
(
result
).
assertTrue
();
let
getOldScanMode
=
bluetooth
.
getBluetoothScanMode
();
console
.
info
(
'
[bluetooth_js] ScanMode_0200 setoldscanmode =
'
+
JSON
.
stringify
(
getOldScanMode
));
expect
(
true
).
assertEqual
(
oldScanMode
==
getOldScanMode
);
done
();
}
else
{
console
.
info
(
'
[bluetooth_js] bluetooth switch off,state is =
'
+
JSON
.
stringify
(
state
));
expect
(
true
).
assertFalse
();
done
();
}
})
/**
* @tc.number SUB_COMMUNICATION_BTMANAGER_DISCOVERY_0100
* @tc.name TEST bluetoothDeviceFind on&off
* @tc.desc TEST bluetoothDeviceFind api10
* @tc.type Function
* @tc.level Level 0
*/
it
(
'
SUB_COMMUNICATION_BLUETOOTHCONNECTION_DISCOVERY_0100
'
,
0
,
async
function
(
done
)
{
function
onReceiveEvent
(
data
)
{
console
.
info
(
'
[bluetooth_js] Device
'
+
JSON
.
stringify
(
data
)
+
'
length
'
+
data
.
length
);
expect
(
true
).
assertTrue
(
data
.
length
>
0
);
}
try
{
bluetooth
.
on
(
"
bluetoothDeviceFind
"
,
onReceiveEvent
);
let
result
=
bluetooth
.
startBluetoothDiscovery
();
await
sleep
(
3000
);
console
.
info
(
'
[bluetooth_js] startDiscovery
'
+
result
);
expect
(
result
).
assertTrue
();
bluetooth
.
off
(
'
bluetoothDeviceFind
'
,
onReceiveEvent
);
result
=
bluetooth
.
stopBluetoothDiscovery
();
console
.
info
(
'
[bluetooth_js] stopDiscovery
'
+
result
);
expect
(
true
).
assertTrue
();
}
catch
(
error
)
{
console
.
error
(
`[bluetooth_js]bluetoothDeviceFin error, code is
${
error
.
code
}
,message is
${
error
.
message
}
`
);
expect
(
error
.
code
).
assertEqual
(
'
2900099
'
);
}
done
();
})
/**
* @tc.number SUB_COMMUNICATION_BLUETOOTHCONNECTION_LOCALNAME_0100
* @tc.name setLocalName
* @tc.desc Test setLocalName api10
* @tc.type Function
* @tc.level Level 1
*/
it
(
'
SUB_COMMUNICATION_BLUETOOTHCONNECTION_LOCALNAME_0100
'
,
0
,
async
function
(
done
)
{
let
result
=
bluetooth
.
setLocalName
(
Btname
.
LETTERS_TEST
);
expect
(
result
).
assertTrue
();
await
sleep
(
1000
);
try
{
let
getNewName
=
bluetooth
.
getLocalName
();
console
.
info
(
'
[bluetooth_js] LocalName_0100 NewName =
'
+
JSON
.
stringify
(
getNewName
));
expect
(
true
).
assertEqual
(
Btname
.
LETTERS_TEST
==
getNewName
);
}
catch
(
err
)
{
console
.
error
(
"
errCode:
"
+
err
.
code
+
"
,errMessage:
"
+
err
.
message
);
expect
(
error
.
code
).
assertEqual
(
'
2900099
'
);
}
done
();
})
/**
* @tc.number SUB_COMMUNICATION_BLUETOOTHCONNECTION_LOCALNAME_0200
* @tc.name setLocalName
* @tc.desc Test setLocalName api10
* @tc.type Function
* @tc.level Level 3
*/
it
(
'
SUB_COMMUNICATION_BLUETOOTHCONNECTION_LOCALNAME_0200
'
,
0
,
async
function
(
done
)
{
try
{
let
result
=
bluetooth
.
setLocalName
(
Btname
.
CHINESES_TEST2
);
expect
(
result
).
assertTrue
();
await
sleep
(
1000
);
let
getNewName
=
bluetooth
.
getLocalName
();
console
.
info
(
'
[bluetooth_js] LocalName_0200 NewName =
'
+
JSON
.
stringify
(
getNewName
));
expect
(
true
).
assertEqual
(
Btname
.
CHINESES_TEST2
==
getNewName
);
}
catch
(
err
)
{
console
.
error
(
"
errCode:
"
+
err
.
code
+
"
,errMessage:
"
+
err
.
message
);
expect
(
error
.
code
).
assertEqual
(
'
2900099
'
);
}
done
();
})
/**
* @tc.number SUB_COMMUNICATION_BLUETOOTHCONNECTION_PROFILE_0100
* @tc.name test getBtConnectionState
* @tc.desc Test getBtConnectionState api10
* @tc.type Function
* @tc.level Level 3
*/
it
(
'
SUB_COMMUNICATION_BLUETOOTHCONNECTION_PROFILE_0100
'
,
0
,
async
function
(
done
)
{
try
{
let
connectionState
=
bluetooth
.
getBtConnectionState
();
expect
(
true
).
assertEqual
(
connectionState
==
0
||
connectionState
==
1
||
connectionState
==
2
||
connectionState
==
3
);
}
catch
(
err
)
{
console
.
error
(
"
errCode:
"
+
err
.
code
+
"
,errMessage:
"
+
err
.
message
);
expect
(
error
.
code
).
assertEqual
(
'
2900099
'
);
}
done
();
})
/**
* @tc.number SUB_COMMUNICATION_BLUETOOTHCONNECTION_PROFILE_0200
* @tc.name getProfileConnectionState
* @tc.desc Test getProfileConnectionState api10
* @tc.type Function
* @tc.level Level 3
*/
it
(
'
SUB_COMMUNICATION_BLUETOOTHCONNECTION_PROFILE_0200
'
,
0
,
async
function
(
done
)
{
try
{
let
result
=
bluetooth
.
getProfileConnectionState
(
1
);
expect
(
true
).
assertEqual
(
result
==
0
||
result
==
1
||
result
==
2
||
result
==
3
);
}
catch
(
err
)
{
console
.
error
(
"
getProfileConnectionState errCode:
"
+
err
.
code
+
"
,errMessage:
"
+
err
.
message
);
expect
(
error
.
code
).
assertEqual
(
'
2900099
'
);
}
done
();
})
/**
* @tc.number SUB_COMMUNICATION_BLUETOOTHCONNECTION_CONSTANT_0100
* @tc.name BluetoothTransport
* @tc.desc Test BluetoothTransport api10
* @tc.type Function
* @tc.level Level 3
*/
it
(
'
SUB_COMMUNICATION_BLUETOOTHCONNECTION_CONSTANT_0100
'
,
0
,
async
function
(
done
)
{
try
{
let
TRANSPORT_BR_EDR
=
bluetooth
.
BluetoothTransport
.
TRANSPORT_BR_EDR
;
let
TRANSPORT_LE
=
bluetooth
.
BluetoothTransport
.
TRANSPORT_LE
;
expect
(
TRANSPORT_BR_EDR
).
assertEqual
(
0
);
expect
(
TRANSPORT_LE
).
assertEqual
(
1
);
}
catch
(
err
)
{
console
.
error
(
"
BluetoothTransport errCode:
"
+
err
.
code
+
"
,errMessage:
"
+
err
.
message
);
expect
(
error
.
code
).
assertEqual
(
'
2900099
'
);
}
done
();
})
})
}
\ No newline at end of file
communication/bluetooth_scanpairing/src/main/js/test/BtPair.test.js
浏览文件 @
ff96c6dc
...
@@ -73,9 +73,8 @@ describe('btPairTest', function() {
...
@@ -73,9 +73,8 @@ describe('btPairTest', function() {
*/
*/
it
(
'
SUB_COMMUNICATION_BLUETOOTH_PAIR_0100
'
,
0
,
async
function
(
done
)
{
it
(
'
SUB_COMMUNICATION_BLUETOOTH_PAIR_0100
'
,
0
,
async
function
(
done
)
{
try
{
try
{
let
result
=
bluetooth
.
pairDevice
(
"
11:22:55:66:33:44
"
);
bluetooth
.
pairDevice
(
"
11:22:55:66:33:44
"
);
await
sleep
(
3000
);
await
sleep
(
3000
);
expect
(
true
).
assertEqual
(
result
==
false
);
}
catch
(
err
)
{
}
catch
(
err
)
{
console
.
error
(
"
pairDevice errCode:
"
+
err
.
code
+
"
,errMessage:
"
+
err
.
message
);
console
.
error
(
"
pairDevice errCode:
"
+
err
.
code
+
"
,errMessage:
"
+
err
.
message
);
expect
(
err
.
code
).
assertEqual
(
'
2900099
'
);
expect
(
err
.
code
).
assertEqual
(
'
2900099
'
);
...
@@ -229,13 +228,13 @@ describe('btPairTest', function() {
...
@@ -229,13 +228,13 @@ describe('btPairTest', function() {
it
(
'
SUB_COMMUNICATION_BLUETOOTH_PAIR_0700
'
,
0
,
async
function
(
done
)
{
it
(
'
SUB_COMMUNICATION_BLUETOOTH_PAIR_0700
'
,
0
,
async
function
(
done
)
{
function
PinRequiredParam
(
data
)
{
function
PinRequiredParam
(
data
)
{
console
.
info
(
"
[bluetooth_js] pinRequired on:
"
+
JSON
.
stringify
(
data
));
console
.
info
(
"
[bluetooth_js] pinRequired on:
"
+
JSON
.
stringify
(
data
));
bluetooth
.
setDevicePairingConfirmation
(
data
.
deviceId
,
false
);
let
ret
=
bluetooth
.
setDevicePairingConfirmation
(
data
.
deviceId
,
false
);
expect
(
ret
).
assertFalse
();
}
}
try
{
try
{
bluetooth
.
BLE
.
on
(
'
pinRequired
'
,
PinRequiredParam
);
bluetooth
.
BLE
.
on
(
'
pinRequired
'
,
PinRequiredParam
);
let
result
=
bluetooth
.
pairDevice
(
"
11:22:55:66:33:44
"
);
bluetooth
.
pairDevice
(
"
99:55:22:88:66:11
"
);
await
sleep
(
2000
);
await
sleep
(
2000
);
expect
(
true
).
assertEqual
(
result
==
false
);
bluetooth
.
BLE
.
off
(
'
pinRequired
'
,
PinRequiredParam
);
bluetooth
.
BLE
.
off
(
'
pinRequired
'
,
PinRequiredParam
);
}
catch
(
err
)
{
}
catch
(
err
)
{
console
.
error
(
"
errCode:
"
+
err
.
code
+
"
,errMessage:
"
+
err
.
message
);
console
.
error
(
"
errCode:
"
+
err
.
code
+
"
,errMessage:
"
+
err
.
message
);
...
@@ -254,13 +253,13 @@ describe('btPairTest', function() {
...
@@ -254,13 +253,13 @@ describe('btPairTest', function() {
it
(
'
SUB_COMMUNICATION_BLUETOOTH_PAIR_0800
'
,
0
,
async
function
(
done
)
{
it
(
'
SUB_COMMUNICATION_BLUETOOTH_PAIR_0800
'
,
0
,
async
function
(
done
)
{
function
PinRequiredParam
(
data
)
{
function
PinRequiredParam
(
data
)
{
console
.
info
(
"
[bluetooth_js] pinRequired on:
"
+
JSON
.
stringify
(
data
));
console
.
info
(
"
[bluetooth_js] pinRequired on:
"
+
JSON
.
stringify
(
data
));
bluetooth
.
setDevicePairingConfirmation
(
data
.
deviceId
,
true
);
let
ret
=
bluetooth
.
setDevicePairingConfirmation
(
data
.
deviceId
,
true
);
expect
(
ret
).
assertTrue
();
}
}
try
{
try
{
bluetooth
.
BLE
.
on
(
'
pinRequired
'
,
PinRequiredParam
);
bluetooth
.
BLE
.
on
(
'
pinRequired
'
,
PinRequiredParam
);
let
result
=
bluetooth
.
pairDevice
(
"
11:22:55:66:33:44
"
);
bluetooth
.
pairDevice
(
"
66:88:33:55:22:99
"
);
await
sleep
(
2000
);
await
sleep
(
1000
);
expect
(
true
).
assertEqual
(
result
==
false
);
bluetooth
.
BLE
.
off
(
'
pinRequired
'
,
PinRequiredParam
);
bluetooth
.
BLE
.
off
(
'
pinRequired
'
,
PinRequiredParam
);
}
catch
(
err
)
{
}
catch
(
err
)
{
console
.
error
(
"
errCode:
"
+
err
.
code
+
"
,errMessage:
"
+
err
.
message
);
console
.
error
(
"
errCode:
"
+
err
.
code
+
"
,errMessage:
"
+
err
.
message
);
...
@@ -282,12 +281,12 @@ describe('btPairTest', function() {
...
@@ -282,12 +281,12 @@ describe('btPairTest', function() {
+
'
bondStateChange deviceId:
'
+
data
.
deviceId
+
'
bondStateChange state:
'
+
data
.
state
);
+
'
bondStateChange deviceId:
'
+
data
.
deviceId
+
'
bondStateChange state:
'
+
data
.
state
);
}
}
bluetooth
.
BLE
.
on
(
'
bondStateChange
'
,
BondStateParam
);
bluetooth
.
BLE
.
on
(
'
bondStateChange
'
,
BondStateParam
);
let
result
=
bluetooth
.
pairDevice
(
"
11:22:55:66:33:4
4
"
);
bluetooth
.
pairDevice
(
"
58:62:22:23:69:5
4
"
);
expect
(
bluetooth
.
BondState
.
BOND_STATE_INVALID
==
0
).
assertTrue
();
expect
(
bluetooth
.
BondState
.
BOND_STATE_INVALID
==
0
).
assertTrue
();
expect
(
bluetooth
.
BondState
.
BOND_STATE_BONDING
==
1
).
assertTrue
();
expect
(
bluetooth
.
BondState
.
BOND_STATE_BONDING
==
1
).
assertTrue
();
expect
(
bluetooth
.
BondState
.
BOND_STATE_BONDED
==
2
).
assertTrue
();
expect
(
bluetooth
.
BondState
.
BOND_STATE_BONDED
==
2
).
assertTrue
();
bluetooth
.
BLE
.
off
(
'
bondStateChange
'
,
BondStateParam
);
bluetooth
.
BLE
.
off
(
'
bondStateChange
'
,
BondStateParam
);
done
()
done
()
;
})
})
})
})
...
...
communication/bluetooth_scanpairing/src/main/js/test/List.test.js
浏览文件 @
ff96c6dc
...
@@ -20,13 +20,18 @@ import btPairTest from './BtPair.test.js'
...
@@ -20,13 +20,18 @@ import btPairTest from './BtPair.test.js'
import
btScanModeTest
from
'
./BtScanMode.test.js
'
import
btScanModeTest
from
'
./BtScanMode.test.js
'
import
btManagerDiscoveryTest
from
'
./BtManagerDiscovery.test.js
'
import
btManagerDiscoveryTest
from
'
./BtManagerDiscovery.test.js
'
import
btManagerPairTest
from
'
./BtManagerPair.test.js
'
import
btManagerPairTest
from
'
./BtManagerPair.test.js
'
import
bluetoothBleTest
from
'
./BluetoothBle.test.js
'
import
btConnectionTest
from
'
./BtConnection.test.js
'
export
default
function
testsuite
()
{
export
default
function
testsuite
()
{
bluetoothBleTest
()
btConnectionTest
()
btPairTest
()
btBleScanTest
()
btBleScanTest
()
btDiscoveryTest
()
btDiscoveryTest
()
btManagerBleScanTest
()
btManagerBleScanTest
()
btPairTest
()
btScanModeTest
()
btScanModeTest
()
btManagerDiscoveryTest
()
btManagerDiscoveryTest
()
btManagerPairTest
()
btManagerPairTest
()
}
}
communication/bluetooth_standard/signature/openharmony_sx.p7b
浏览文件 @
ff96c6dc
无法预览此类型文件
communication/bluetooth_standard/src/main/config.json
浏览文件 @
ff96c6dc
...
@@ -88,47 +88,31 @@
...
@@ -88,47 +88,31 @@
"reqPermissions"
:
[
"reqPermissions"
:
[
{
{
"name"
:
"ohos.permission.USE_BLUETOOTH"
,
"name"
:
"ohos.permission.USE_BLUETOOTH"
,
"reason"
:
""
,
"reason"
:
""
"usedScene"
:
{
"ability"
:
[
"ohos.acts.communication.bluetooth.bluetoothhost.MainAbility"
],
"when"
:
"inuse"
}
},
{
"name"
:
"ohos.permission.GRANT_SENSITIVE_PERMISSIONS"
,
"reason"
:
"use ohos.permission.GRANT_SENSITIVE_PERMISSIONS"
},
},
{
{
"name"
:
"ohos.permission.MANAGE_BLUETOOTH"
,
"name"
:
"ohos.permission.MANAGE_BLUETOOTH"
,
"reason"
:
""
,
"reason"
:
""
"usedScene"
:
{
"ability"
:
[
"ohos.acts.communication.bluetooth.bluetoothhost.MainAbility"
],
"when"
:
"inuse"
}
},
},
{
{
"name"
:
"ohos.permission.DISCOVER_BLUETOOTH"
,
"name"
:
"ohos.permission.DISCOVER_BLUETOOTH"
,
"reason"
:
""
,
"reason"
:
""
"usedScene"
:
{
"ability"
:
[
"ohos.acts.communication.bluetooth.bluetoothhost.MainAbility"
],
"when"
:
"inuse"
}
},
},
{
{
"name"
:
"ohos.permission.LOCATION"
,
"name"
:
"ohos.permission.LOCATION"
,
"reason"
:
""
,
"reason"
:
""
"usedScene"
:
{
},
"ability"
:
[
{
"ohos.acts.communication.bluetooth.bluetoothhost.MainAbility"
"name"
:
"ohos.permission.ACCESS_BLUETOOTH"
,
],
"reason"
:
""
"when"
:
"inuse"
},
}
{
"name"
:
"ohos.permission.GRANT_SENSITIVE_PERMISSIONS"
,
"reason"
:
""
},
{
"name"
:
"ohos.permission.REVOKE_SENSITIVE_PERMISSIONS"
,
"reason"
:
""
}
}
],
],
"testRunner"
:
{
"testRunner"
:
{
...
...
communication/bluetooth_standard/src/main/js/test/BluetoothAccess.test.js
0 → 100644
浏览文件 @
ff96c6dc
/*
* Copyright (C) 2022 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import
bluetooth
from
'
@ohos.bluetooth.access
'
;
import
{
describe
,
beforeAll
,
beforeEach
,
afterEach
,
afterAll
,
it
,
expect
}
from
'
@ohos/hypium
'
export
default
function
btAccessTest
()
{
describe
(
'
btAccessTest
'
,
function
()
{
function
sleep
(
delay
)
{
return
new
Promise
(
resovle
=>
setTimeout
(
resovle
,
delay
))
}
beforeAll
(
function
()
{
console
.
info
(
'
beforeAll called
'
)
})
beforeEach
(
function
()
{
console
.
info
(
'
beforeEach called
'
)
})
afterEach
(
function
()
{
console
.
info
(
'
afterEach called
'
)
})
afterAll
(
function
()
{
console
.
info
(
'
afterAll called
'
)
})
/**
* @tc.number SUB_COMMUNICATION_BLUETOOTHACCESS_STATECHANGE_0100
* @tc.name test enableBluetooth
* @tc.desc Test enableBluetooth api10
* @tc.type Function
* @tc.level Level 3
*/
it
(
'
SUB_COMMUNICATION_BLUETOOTHACCESS_STATECHANGE_0100
'
,
0
,
async
function
(
done
)
{
let
state
=
bluetooth
.
getState
();
console
.
info
(
'
[bluetooth_js] bluetooth state =
'
+
JSON
.
stringify
(
state
));
if
(
state
!=
bluetooth
.
BluetoothState
.
STATE_OFF
)
{
bluetooth
.
disableBluetooth
();
await
sleep
(
10000
);
let
closeSt
=
bluetooth
.
getState
();
console
.
info
(
'
[bluetooth_js] bluetooth disable state =
'
+
JSON
.
stringify
(
closeSt
));
expect
(
closeSt
).
assertEqual
(
bluetooth
.
BluetoothState
.
STATE_OFF
);
}
else
{
console
.
info
(
'
[bluetooth_js] bluetooth state is OFF
'
);
}
try
{
bluetooth
.
enableBluetooth
();
await
sleep
(
10000
);
}
catch
{
console
.
error
(
`[bluetooth_js] enable StateChange error, code is
${
error
.
code
}
,message is
${
error
.
message
}
`
);
expect
(
error
.
code
).
assertEqual
(
'
2900099
'
);
}
let
openSt
=
bluetooth
.
getState
();
console
.
info
(
'
[bluetooth_js] bluetooth enable state =
'
+
JSON
.
stringify
(
openSt
));
expect
(
openSt
).
assertEqual
(
bluetooth
.
BluetoothState
.
STATE_ON
);
done
();
})
/**
* @tc.number SUB_COMMUNICATION_BLUETOOTHACCESS_STATECHANGE_0200
* @tc.name test disableBluetooth
* @tc.desc Test disableBluetooth api10
* @tc.type Function
* @tc.level Level 3
*/
it
(
'
SUB_COMMUNICATION_BLUETOOTHACCESS_STATECHANGE_0200
'
,
0
,
async
function
(
done
)
{
let
state
=
bluetooth
.
getState
();
console
.
info
(
'
[bluetooth_js] bluetooth state =
'
+
JSON
.
stringify
(
state
));
if
(
state
!=
bluetooth
.
BluetoothState
.
STATE_ON
)
{
bluetooth
.
enableBluetooth
();
await
sleep
(
10000
);
let
openSt
=
bluetooth
.
getState
();
console
.
info
(
'
[bluetooth_js] bluetooth enable state =
'
+
JSON
.
stringify
(
openSt
));
expect
(
openSt
).
assertEqual
(
bluetooth
.
BluetoothState
.
STATE_ON
);
}
else
{
console
.
info
(
'
[bluetooth_js] bluetooth state is ON
'
);
}
try
{
bluetooth
.
disableBluetooth
();
await
sleep
(
10000
);
}
catch
{
console
.
error
(
`[bluetooth_js] disable StateChange error, code is
${
error
.
code
}
,message is
${
error
.
message
}
`
);
expect
(
error
.
code
).
assertEqual
(
'
2900099
'
);
}
let
closeSt
=
bluetooth
.
getState
();
console
.
info
(
'
[bluetooth_js] bluetooth disable state =
'
+
JSON
.
stringify
(
closeSt
));
expect
(
closeSt
).
assertEqual
(
bluetooth
.
BluetoothState
.
STATE_OFF
);
done
();
})
/**
* @tc.number SUB_COMMUNICATION_BLUETOOTHACCESS_STATECHANGE_0300
* @tc.name test getState
* @tc.desc Test getState api10
* @tc.type Function
* @tc.level Level 3
*/
it
(
'
SUB_COMMUNICATION_BLUETOOTHACCESS_STATECHANGE_0300
'
,
0
,
async
function
(
done
)
{
try
{
let
state
=
bluetooth
.
getState
();
expect
(
true
).
assertTrue
(
0
<=
state
<=
6
);
}
catch
{
console
.
error
(
"
[bluetooth_js] bluetooth getState errCode:
"
+
err
.
code
+
"
,bluetooth getState errMessage:
"
+
err
.
message
);
expect
(
error
.
code
).
assertEqual
(
'
2900099
'
);
}
done
();
})
/**
* @tc.number SUB_COMMUNICATION_BLUETOOTHACCESS_STATECHANGE_0400
* @tc.name test on 'stateChange'
* @tc.desc Test on 'stateChange' api10
* @tc.type Function
* @tc.level Level 0
*/
it
(
'
SUB_COMMUNICATION_BLUETOOTHACCESS_STATECHANGE_0400
'
,
0
,
async
function
(
done
)
{
function
onReceiveEvent
(
data
)
{
console
.
info
(
'
bluetooth state001 =
'
+
JSON
.
stringify
(
data
));
}
try
{
await
bluetooth
.
on
(
'
stateChange
'
,
onReceiveEvent
);
let
state
=
bluetooth
.
getState
();
console
.
info
(
'
[bluetooth_js] get bluetooth state
'
+
JSON
.
stringify
(
state
));
if
(
state
!=
bluetooth
.
BluetoothState
.
STATE_ON
)
{
let
enable
=
bluetooth
.
enableBluetooth
();
await
sleep
(
10000
);
console
.
info
(
'
[bluetooth_js] bluetooth enable
'
+
JSON
.
stringify
(
enable
));
expect
(
enable
).
assertTrue
();
let
state1
=
bluetooth
.
getState
();
console
.
info
(
'
[bluetooth_js] enable state
'
+
JSON
.
stringify
(
state1
));
expect
(
state1
).
assertEqual
(
bluetooth
.
BluetoothState
.
STATE_ON
);
}
}
catch
(
error
)
{
console
.
error
(
`[bluetooth_js]enable StateChange error, code is
${
error
.
code
}
,message is
${
error
.
message
}
`
);
expect
(
error
.
code
).
assertEqual
(
'
2900099
'
);
}
bluetooth
.
off
(
'
stateChange
'
,
onReceiveEvent
);
done
();
})
/**
* @tc.number SUB_COMMUNICATION_BLUETOOTHACCESS_STATECHANGE_0500
* @tc.name test off 'stateChange'
* @tc.desc Test off 'stateChange' api10
* @tc.type Function
* @tc.level Level 0
*/
it
(
'
SUB_COMMUNICATION_BLUETOOTHACCESS_STATECHANGE_0500
'
,
0
,
async
function
(
done
)
{
function
onReceiveEvent
(
data
)
{
console
.
info
(
'
bluetooth state001 =
'
+
JSON
.
stringify
(
data
));
}
try
{
await
bluetooth
.
on
(
'
stateChange
'
,
onReceiveEvent
);
await
sleep
(
3000
);
await
bluetooth
.
off
(
'
stateChange
'
,
onReceiveEvent
);
let
state
=
bluetooth
.
getState
();
console
.
info
(
'
[bluetooth_js] get bluetooth state001
'
+
JSON
.
stringify
(
state
));
if
(
state
!=
bluetooth
.
BluetoothState
.
STATE_OFF
)
{
let
disable
=
bluetooth
.
disableBluetooth
();
await
sleep
(
10000
);
console
.
info
(
'
[bluetooth_js] bluetooth disable001
'
+
JSON
.
stringify
(
disable
));
expect
(
disable
).
assertTrue
();
let
state1
=
bluetooth
.
getState
();
console
.
info
(
'
[bluetooth_js] disable state001
'
+
JSON
.
stringify
(
state1
));
expect
(
state1
).
assertEqual
(
bluetooth
.
BluetoothState
.
STATE_OFF
);
}
}
catch
(
error
)
{
console
.
error
(
`[bluetooth_js]disable StateChange error, code is
${
error
.
code
}
,message is
${
error
.
message
}
`
);
expect
(
error
.
code
).
assertEqual
(
'
2900099
'
);
}
done
();
})
/**
* @tc.number SUB_COMMUNICATION_BLUETOOTHACCESS_STATECHANGE_0600
* @tc.name test BluetoothState
* @tc.desc Test BluetoothState api10
* @tc.type Function
* @tc.level Level 0
*/
it
(
'
SUB_COMMUNICATION_BLUETOOTHACCESS_STATECHANGE_0600
'
,
0
,
async
function
(
done
)
{
let
STATE_ON
=
bluetooth
.
BluetoothState
.
STATE_ON
;
console
.
info
(
"
[bluetooth_js]STATE_ON :
"
+
JSON
.
stringify
(
STATE_ON
));
expect
(
true
).
assertTrue
(
STATE_ON
==
2
);
let
STATE_OFF
=
bluetooth
.
BluetoothState
.
STATE_OFF
;
console
.
info
(
"
[bluetooth_js]STATE_OFF :
"
+
JSON
.
stringify
(
STATE_OFF
));
expect
(
true
).
assertTrue
(
STATE_OFF
==
0
);
let
STATE_TURNING_ON
=
bluetooth
.
BluetoothState
.
STATE_TURNING_ON
;
console
.
info
(
"
[bluetooth_js]STATE_TURNING_ON :
"
+
JSON
.
stringify
(
STATE_TURNING_ON
));
expect
(
true
).
assertTrue
(
STATE_TURNING_ON
==
1
);
let
STATE_TURNING_OFF
=
bluetooth
.
BluetoothState
.
STATE_TURNING_OFF
;
console
.
info
(
"
[bluetooth_js]STATE_TURNING_OFF :
"
+
JSON
.
stringify
(
STATE_TURNING_OFF
));
expect
(
true
).
assertTrue
(
STATE_TURNING_OFF
==
3
);
let
STATE_BLE_TURNING_ON
=
bluetooth
.
BluetoothState
.
STATE_BLE_TURNING_ON
;
console
.
info
(
"
[bluetooth_js]STATE_BLE_TURNING_ON :
"
+
JSON
.
stringify
(
STATE_BLE_TURNING_ON
));
expect
(
true
).
assertTrue
(
STATE_BLE_TURNING_ON
==
4
);
let
STATE_BLE_ON
=
bluetooth
.
BluetoothState
.
STATE_BLE_ON
;
console
.
info
(
"
[bluetooth_js]STATE_BLE_ON :
"
+
JSON
.
stringify
(
STATE_BLE_ON
));
expect
(
true
).
assertTrue
(
STATE_BLE_ON
==
5
);
let
STATE_BLE_TURNING_OFF
=
bluetooth
.
BluetoothState
.
STATE_BLE_TURNING_OFF
;
console
.
info
(
"
[bluetooth_js]STATE_BLE_TURNING_OFF :
"
+
JSON
.
stringify
(
STATE_BLE_TURNING_OFF
));
expect
(
true
).
assertTrue
(
STATE_BLE_TURNING_OFF
==
6
);
done
();
})
})
}
\ No newline at end of file
communication/bluetooth_standard/src/main/js/test/BluetoothConstant.test.js
0 → 100644
浏览文件 @
ff96c6dc
/*
* Copyright (C) 2022 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import
bluetooth
from
'
@ohos.bluetooth.constant
'
;
import
{
describe
,
beforeAll
,
beforeEach
,
afterEach
,
afterAll
,
it
,
expect
}
from
'
@ohos/hypium
'
export
default
function
btConstantTest
()
{
describe
(
'
btConstantTest
'
,
function
()
{
beforeAll
(
function
()
{
console
.
info
(
'
beforeAll called
'
)
})
beforeEach
(
function
()
{
console
.
info
(
'
beforeEach called
'
)
})
afterEach
(
function
()
{
console
.
info
(
'
afterEach called
'
)
})
afterAll
(
function
()
{
console
.
info
(
'
afterAll called
'
)
})
/**
* @tc.number SUB_COMMUNICATION_BLUETOOTH_CONSTANT_0100
* @tc.name test constant
* @tc.desc Test constant api10
* @tc.type Function
* @tc.level Level 1
*/
it
(
'
SUB_COMMUNICATION_BLUETOOTH_CONSTANT_0100
'
,
0
,
async
function
(
done
)
{
let
STATE_DISCONNECTED
=
bluetooth
.
ProfileConnectionState
.
STATE_DISCONNECTED
;
console
.
info
(
"
[bluetooth_js]STATE_DISCONNECTED :
"
+
JSON
.
stringify
(
STATE_DISCONNECTED
));
expect
(
true
).
assertTrue
(
STATE_DISCONNECTED
==
0
);
let
STATE_CONNECTING
=
bluetooth
.
ProfileConnectionState
.
STATE_CONNECTING
;
console
.
info
(
"
[bluetooth_js]STATE_CONNECTING :
"
+
JSON
.
stringify
(
STATE_CONNECTING
));
expect
(
true
).
assertTrue
(
STATE_CONNECTING
==
1
);
let
STATE_CONNECTED
=
bluetooth
.
ProfileConnectionState
.
STATE_CONNECTED
;
console
.
info
(
"
[bluetooth_js]STATE_CONNECTED :
"
+
JSON
.
stringify
(
STATE_CONNECTED
));
expect
(
true
).
assertTrue
(
STATE_CONNECTED
==
2
);
let
STATE_DISCONNECTING
=
bluetooth
.
ProfileConnectionState
.
STATE_DISCONNECTING
;
console
.
info
(
"
[bluetooth_js]STATE_DISCONNECTING :
"
+
JSON
.
stringify
(
STATE_DISCONNECTING
));
expect
(
true
).
assertTrue
(
STATE_DISCONNECTING
==
3
);
done
();
})
/**
* @tc.number SUB_COMMUNICATION_BLUETOOTH_CONSTANT_0200
* @tc.name test constant
* @tc.desc Test constant api10
* @tc.type Function
* @tc.level Level 1
*/
it
(
'
SUB_COMMUNICATION_BLUETOOTH_CONSTANT_0200
'
,
0
,
async
function
(
done
)
{
let
PROFILE_A2DP_SOURCE
=
bluetooth
.
ProfileId
.
PROFILE_A2DP_SOURCE
;
console
.
info
(
"
[bluetooth_js]PROFILE_A2DP_SOURCE :
"
+
JSON
.
stringify
(
PROFILE_A2DP_SOURCE
));
expect
(
true
).
assertTrue
(
PROFILE_A2DP_SOURCE
==
1
);
let
PROFILE_HANDSFREE_AUDIO_GATEWAY
=
bluetooth
.
ProfileId
.
PROFILE_HANDSFREE_AUDIO_GATEWAY
;
console
.
info
(
"
[bluetooth_js]PROFILE_HANDSFREE_AUDIO_GATEWAY :
"
+
JSON
.
stringify
(
PROFILE_HANDSFREE_AUDIO_GATEWAY
));
expect
(
true
).
assertTrue
(
PROFILE_HANDSFREE_AUDIO_GATEWAY
==
4
);
let
PROFILE_HID_HOST
=
bluetooth
.
ProfileId
.
PROFILE_HID_HOST
;
console
.
info
(
"
[bluetooth_js]PROFILE_HID_HOST :
"
+
JSON
.
stringify
(
PROFILE_HID_HOST
));
expect
(
true
).
assertTrue
(
PROFILE_HID_HOST
==
6
);
let
PROFILE_PAN_NETWORK
=
bluetooth
.
ProfileId
.
PROFILE_PAN_NETWORK
;
console
.
info
(
"
[bluetooth_js]PROFILE_PAN_NETWORK :
"
+
JSON
.
stringify
(
PROFILE_PAN_NETWORK
));
expect
(
true
).
assertTrue
(
PROFILE_PAN_NETWORK
==
7
);
done
();
})
/**
* @tc.number SUB_COMMUNICATION_BLUETOOTH_CONSTANT_0300
* @tc.name test constant
* @tc.desc Test constant api10
* @tc.type Function
* @tc.level Level 1
*/
it
(
'
SUB_COMMUNICATION_BLUETOOTH_CONSTANT_0300
'
,
0
,
async
function
(
done
)
{
let
MAJOR_MISC
=
bluetooth
.
MajorClass
.
MAJOR_MISC
;
console
.
info
(
"
[bluetooth_js]MAJOR_MISC :
"
+
JSON
.
stringify
(
MAJOR_MISC
));
expect
(
true
).
assertTrue
(
MAJOR_MISC
==
0x0000
);
let
MAJOR_COMPUTER
=
bluetooth
.
MajorClass
.
MAJOR_COMPUTER
;
console
.
info
(
"
[bluetooth_js]MAJOR_COMPUTER :
"
+
JSON
.
stringify
(
MAJOR_COMPUTER
));
expect
(
true
).
assertTrue
(
MAJOR_COMPUTER
==
0x0100
);
let
MAJOR_PHONE
=
bluetooth
.
MajorClass
.
MAJOR_PHONE
;
console
.
info
(
"
[bluetooth_js]MAJOR_PHONE :
"
+
JSON
.
stringify
(
MAJOR_PHONE
));
expect
(
true
).
assertTrue
(
MAJOR_PHONE
==
0x0200
);
let
MAJOR_NETWORKING
=
bluetooth
.
MajorClass
.
MAJOR_NETWORKING
;
console
.
info
(
"
[bluetooth_js]MAJOR_NETWORKING :
"
+
JSON
.
stringify
(
MAJOR_NETWORKING
));
expect
(
true
).
assertTrue
(
MAJOR_NETWORKING
==
0x0300
);
let
MAJOR_AUDIO_VIDEO
=
bluetooth
.
MajorClass
.
MAJOR_AUDIO_VIDEO
;
console
.
info
(
"
[bluetooth_js]MAJOR_AUDIO_VIDEO :
"
+
JSON
.
stringify
(
MAJOR_AUDIO_VIDEO
));
expect
(
true
).
assertTrue
(
MAJOR_AUDIO_VIDEO
==
0x0400
);
let
MAJOR_PERIPHERAL
=
bluetooth
.
MajorClass
.
MAJOR_PERIPHERAL
;
console
.
info
(
"
[bluetooth_js]MAJOR_PERIPHERAL :
"
+
JSON
.
stringify
(
MAJOR_PERIPHERAL
));
expect
(
true
).
assertTrue
(
MAJOR_PERIPHERAL
==
0x0500
);
let
MAJOR_IMAGING
=
bluetooth
.
MajorClass
.
MAJOR_IMAGING
;
console
.
info
(
"
[bluetooth_js]MAJOR_IMAGING :
"
+
JSON
.
stringify
(
MAJOR_IMAGING
));
expect
(
true
).
assertTrue
(
MAJOR_IMAGING
==
0x0600
);
let
MAJOR_WEARABLE
=
bluetooth
.
MajorClass
.
MAJOR_WEARABLE
;
console
.
info
(
"
[bluetooth_js]MAJOR_WEARABLE :
"
+
JSON
.
stringify
(
MAJOR_WEARABLE
));
expect
(
true
).
assertTrue
(
MAJOR_WEARABLE
==
0x0700
);
let
MAJOR_TOY
=
bluetooth
.
MajorClass
.
MAJOR_TOY
;
console
.
info
(
"
[bluetooth_js]MAJOR_TOY :
"
+
JSON
.
stringify
(
MAJOR_TOY
));
expect
(
true
).
assertTrue
(
MAJOR_TOY
==
0x0800
);
let
MAJOR_HEALTH
=
bluetooth
.
MajorClass
.
MAJOR_HEALTH
;
console
.
info
(
"
[bluetooth_js]MAJOR_HEALTH :
"
+
JSON
.
stringify
(
MAJOR_HEALTH
));
expect
(
true
).
assertTrue
(
MAJOR_HEALTH
==
0x0900
);
let
MAJOR_UNCATEGORIZED
=
bluetooth
.
MajorClass
.
MAJOR_UNCATEGORIZED
;
console
.
info
(
"
[bluetooth_js]MAJOR_UNCATEGORIZED :
"
+
JSON
.
stringify
(
MAJOR_UNCATEGORIZED
));
expect
(
true
).
assertTrue
(
MAJOR_UNCATEGORIZED
==
0x1F00
);
done
();
})
/**
* @tc.number SUB_COMMUNICATION_BLUETOOTH_CONSTANT_0400
* @tc.name test constant
* @tc.desc Test constant api10
* @tc.type Function
* @tc.level Level 1
*/
it
(
'
SUB_COMMUNICATION_BLUETOOTH_CONSTANT_0800
'
,
0
,
async
function
(
done
)
{
let
COMPUTER_UNCATEGORIZED
=
bluetooth
.
MajorMinorClass
.
COMPUTER_UNCATEGORIZED
;
console
.
info
(
"
[bluetooth_js]COMPUTER_UNCATEGORIZED :
"
+
JSON
.
stringify
(
COMPUTER_UNCATEGORIZED
));
expect
(
true
).
assertTrue
(
COMPUTER_UNCATEGORIZED
==
0x0100
);
let
COMPUTER_DESKTOP
=
bluetooth
.
MajorMinorClass
.
COMPUTER_DESKTOP
;
console
.
info
(
"
[bluetooth_js]COMPUTER_DESKTOP :
"
+
JSON
.
stringify
(
COMPUTER_DESKTOP
));
expect
(
true
).
assertTrue
(
COMPUTER_DESKTOP
==
0x0104
);
let
COMPUTER_SERVER
=
bluetooth
.
MajorMinorClass
.
COMPUTER_SERVER
;
console
.
info
(
"
[bluetooth_js]COMPUTER_SERVER :
"
+
JSON
.
stringify
(
COMPUTER_SERVER
));
expect
(
true
).
assertTrue
(
COMPUTER_SERVER
==
0x0108
);
let
COMPUTER_LAPTOP
=
bluetooth
.
MajorMinorClass
.
COMPUTER_LAPTOP
;
console
.
info
(
"
[bluetooth_js]COMPUTER_LAPTOP :
"
+
JSON
.
stringify
(
COMPUTER_LAPTOP
));
expect
(
true
).
assertTrue
(
COMPUTER_LAPTOP
==
0x010C
);
let
COMPUTER_HANDHELD_PC_PDA
=
bluetooth
.
MajorMinorClass
.
COMPUTER_HANDHELD_PC_PDA
;
console
.
info
(
"
[bluetooth_js]COMPUTER_HANDHELD_PC_PDA :
"
+
JSON
.
stringify
(
COMPUTER_HANDHELD_PC_PDA
));
expect
(
true
).
assertTrue
(
COMPUTER_HANDHELD_PC_PDA
==
0x0110
);
let
COMPUTER_PALM_SIZE_PC_PDA
=
bluetooth
.
MajorMinorClass
.
COMPUTER_PALM_SIZE_PC_PDA
;
console
.
info
(
"
[bluetooth_js]COMPUTER_PALM_SIZE_PC_PDA :
"
+
JSON
.
stringify
(
COMPUTER_PALM_SIZE_PC_PDA
));
expect
(
true
).
assertTrue
(
COMPUTER_PALM_SIZE_PC_PDA
==
0x0114
);
let
COMPUTER_WEARABLE
=
bluetooth
.
MajorMinorClass
.
COMPUTER_WEARABLE
;
console
.
info
(
"
[bluetooth_js]COMPUTER_WEARABLE :
"
+
JSON
.
stringify
(
COMPUTER_WEARABLE
));
expect
(
true
).
assertTrue
(
COMPUTER_WEARABLE
==
0x0118
);
let
COMPUTER_TABLET
=
bluetooth
.
MajorMinorClass
.
COMPUTER_TABLET
;
console
.
info
(
"
[bluetooth_js]COMPUTER_TABLET :
"
+
JSON
.
stringify
(
COMPUTER_TABLET
));
expect
(
true
).
assertTrue
(
COMPUTER_TABLET
==
0x011C
);
let
PHONE_UNCATEGORIZED
=
bluetooth
.
MajorMinorClass
.
PHONE_UNCATEGORIZED
;
console
.
info
(
"
[bluetooth_js]PHONE_UNCATEGORIZED :
"
+
JSON
.
stringify
(
PHONE_UNCATEGORIZED
));
expect
(
true
).
assertTrue
(
PHONE_UNCATEGORIZED
==
0x0200
);
let
PHONE_CELLULAR
=
bluetooth
.
MajorMinorClass
.
PHONE_CELLULAR
;
console
.
info
(
"
[bluetooth_js]PHONE_CELLULAR :
"
+
JSON
.
stringify
(
PHONE_CELLULAR
));
expect
(
true
).
assertTrue
(
PHONE_CELLULAR
==
0x0204
);
let
PHONE_CORDLESS
=
bluetooth
.
MajorMinorClass
.
PHONE_CORDLESS
;
console
.
info
(
"
[bluetooth_js]PHONE_CORDLESS :
"
+
JSON
.
stringify
(
PHONE_CORDLESS
));
expect
(
true
).
assertTrue
(
PHONE_CORDLESS
==
0x0208
);
let
PHONE_SMART
=
bluetooth
.
MajorMinorClass
.
PHONE_SMART
;
console
.
info
(
"
[bluetooth_js]PHONE_SMART :
"
+
JSON
.
stringify
(
PHONE_SMART
));
expect
(
true
).
assertTrue
(
PHONE_SMART
==
0x020C
);
let
PHONE_MODEM_OR_GATEWAY
=
bluetooth
.
MajorMinorClass
.
PHONE_MODEM_OR_GATEWAY
;
console
.
info
(
"
[bluetooth_js]PHONE_MODEM_OR_GATEWAY :
"
+
JSON
.
stringify
(
PHONE_MODEM_OR_GATEWAY
));
expect
(
true
).
assertTrue
(
PHONE_MODEM_OR_GATEWAY
==
0x0210
);
let
PHONE_ISDN
=
bluetooth
.
MajorMinorClass
.
PHONE_ISDN
;
console
.
info
(
"
[bluetooth_js]PHONE_ISDN :
"
+
JSON
.
stringify
(
PHONE_ISDN
));
expect
(
true
).
assertTrue
(
PHONE_ISDN
==
0x0214
);
let
NETWORK_FULLY_AVAILABLE
=
bluetooth
.
MajorMinorClass
.
NETWORK_FULLY_AVAILABLE
;
console
.
info
(
"
[bluetooth_js]NETWORK_FULLY_AVAILABLE :
"
+
JSON
.
stringify
(
NETWORK_FULLY_AVAILABLE
));
expect
(
true
).
assertTrue
(
NETWORK_FULLY_AVAILABLE
==
0x0300
);
let
NETWORK_1_TO_17_UTILIZED
=
bluetooth
.
MajorMinorClass
.
NETWORK_1_TO_17_UTILIZED
;
console
.
info
(
"
[bluetooth_js]NETWORK_1_TO_17_UTILIZED :
"
+
JSON
.
stringify
(
NETWORK_1_TO_17_UTILIZED
));
expect
(
true
).
assertTrue
(
NETWORK_1_TO_17_UTILIZED
==
0x0320
);
let
NETWORK_17_TO_33_UTILIZED
=
bluetooth
.
MajorMinorClass
.
NETWORK_17_TO_33_UTILIZED
;
console
.
info
(
"
[bluetooth_js]NETWORK_17_TO_33_UTILIZED :
"
+
JSON
.
stringify
(
NETWORK_17_TO_33_UTILIZED
));
expect
(
true
).
assertTrue
(
NETWORK_17_TO_33_UTILIZED
==
0x0340
);
let
NETWORK_33_TO_50_UTILIZED
=
bluetooth
.
MajorMinorClass
.
NETWORK_33_TO_50_UTILIZED
;
console
.
info
(
"
[bluetooth_js]NETWORK_33_TO_50_UTILIZED :
"
+
JSON
.
stringify
(
NETWORK_33_TO_50_UTILIZED
));
expect
(
true
).
assertTrue
(
NETWORK_33_TO_50_UTILIZED
==
0x0360
);
let
NETWORK_60_TO_67_UTILIZED
=
bluetooth
.
MajorMinorClass
.
NETWORK_60_TO_67_UTILIZED
;
console
.
info
(
"
[bluetooth_js]NETWORK_60_TO_67_UTILIZED :
"
+
JSON
.
stringify
(
NETWORK_60_TO_67_UTILIZED
));
expect
(
true
).
assertTrue
(
NETWORK_60_TO_67_UTILIZED
==
0x0380
);
let
NETWORK_67_TO_83_UTILIZED
=
bluetooth
.
MajorMinorClass
.
NETWORK_67_TO_83_UTILIZED
;
console
.
info
(
"
[bluetooth_js]NETWORK_67_TO_83_UTILIZED :
"
+
JSON
.
stringify
(
NETWORK_67_TO_83_UTILIZED
));
expect
(
true
).
assertTrue
(
NETWORK_67_TO_83_UTILIZED
==
0x03A0
);
let
NETWORK_83_TO_99_UTILIZED
=
bluetooth
.
MajorMinorClass
.
NETWORK_83_TO_99_UTILIZED
;
console
.
info
(
"
[bluetooth_js]NETWORK_83_TO_99_UTILIZED :
"
+
JSON
.
stringify
(
NETWORK_83_TO_99_UTILIZED
));
expect
(
true
).
assertTrue
(
NETWORK_83_TO_99_UTILIZED
==
0x03C0
);
let
NETWORK_NO_SERVICE
=
bluetooth
.
MajorMinorClass
.
NETWORK_NO_SERVICE
;
console
.
info
(
"
[bluetooth_js]NETWORK_NO_SERVICE :
"
+
JSON
.
stringify
(
NETWORK_NO_SERVICE
));
expect
(
true
).
assertTrue
(
NETWORK_NO_SERVICE
==
0x03E0
);
let
AUDIO_VIDEO_UNCATEGORIZED
=
bluetooth
.
MajorMinorClass
.
AUDIO_VIDEO_UNCATEGORIZED
;
console
.
info
(
"
[bluetooth_js]AUDIO_VIDEO_UNCATEGORIZED :
"
+
JSON
.
stringify
(
AUDIO_VIDEO_UNCATEGORIZED
));
expect
(
true
).
assertTrue
(
AUDIO_VIDEO_UNCATEGORIZED
==
0x0400
);
let
AUDIO_VIDEO_WEARABLE_HEADSET
=
bluetooth
.
MajorMinorClass
.
AUDIO_VIDEO_WEARABLE_HEADSET
;
console
.
info
(
"
[bluetooth_js]AUDIO_VIDEO_WEARABLE_HEADSET :
"
+
JSON
.
stringify
(
AUDIO_VIDEO_WEARABLE_HEADSET
));
expect
(
true
).
assertTrue
(
AUDIO_VIDEO_WEARABLE_HEADSET
==
0x0404
);
let
AUDIO_VIDEO_HANDSFREE
=
bluetooth
.
MajorMinorClass
.
AUDIO_VIDEO_HANDSFREE
;
console
.
info
(
"
[bluetooth_js]AUDIO_VIDEO_HANDSFREE :
"
+
JSON
.
stringify
(
AUDIO_VIDEO_HANDSFREE
));
expect
(
true
).
assertTrue
(
AUDIO_VIDEO_HANDSFREE
==
0x0408
);
let
AUDIO_VIDEO_MICROPHONE
=
bluetooth
.
MajorMinorClass
.
AUDIO_VIDEO_MICROPHONE
;
console
.
info
(
"
[bluetooth_js]AUDIO_VIDEO_MICROPHONE :
"
+
JSON
.
stringify
(
AUDIO_VIDEO_MICROPHONE
));
expect
(
true
).
assertTrue
(
AUDIO_VIDEO_MICROPHONE
==
0x0410
);
let
AUDIO_VIDEO_LOUDSPEAKER
=
bluetooth
.
MajorMinorClass
.
AUDIO_VIDEO_LOUDSPEAKER
;
console
.
info
(
"
[bluetooth_js]AUDIO_VIDEO_LOUDSPEAKER :
"
+
JSON
.
stringify
(
AUDIO_VIDEO_LOUDSPEAKER
));
expect
(
true
).
assertTrue
(
AUDIO_VIDEO_LOUDSPEAKER
==
0x0414
);
let
AUDIO_VIDEO_HEADPHONES
=
bluetooth
.
MajorMinorClass
.
AUDIO_VIDEO_HEADPHONES
;
console
.
info
(
"
[bluetooth_js]AUDIO_VIDEO_HEADPHONES :
"
+
JSON
.
stringify
(
AUDIO_VIDEO_HEADPHONES
));
expect
(
true
).
assertTrue
(
AUDIO_VIDEO_HEADPHONES
==
0x0418
);
let
AUDIO_VIDEO_PORTABLE_AUDIO
=
bluetooth
.
MajorMinorClass
.
AUDIO_VIDEO_PORTABLE_AUDIO
;
console
.
info
(
"
[bluetooth_js]AUDIO_VIDEO_PORTABLE_AUDIO :
"
+
JSON
.
stringify
(
AUDIO_VIDEO_PORTABLE_AUDIO
));
expect
(
true
).
assertTrue
(
AUDIO_VIDEO_PORTABLE_AUDIO
==
0x041C
);
let
AUDIO_VIDEO_CAR_AUDIO
=
bluetooth
.
MajorMinorClass
.
AUDIO_VIDEO_CAR_AUDIO
;
console
.
info
(
"
[bluetooth_js]AUDIO_VIDEO_CAR_AUDIO :
"
+
JSON
.
stringify
(
AUDIO_VIDEO_CAR_AUDIO
));
expect
(
true
).
assertTrue
(
AUDIO_VIDEO_CAR_AUDIO
==
0x0420
);
let
AUDIO_VIDEO_SET_TOP_BOX
=
bluetooth
.
MajorMinorClass
.
AUDIO_VIDEO_SET_TOP_BOX
;
console
.
info
(
"
[bluetooth_js]AUDIO_VIDEO_SET_TOP_BOX :
"
+
JSON
.
stringify
(
AUDIO_VIDEO_SET_TOP_BOX
));
expect
(
true
).
assertTrue
(
AUDIO_VIDEO_SET_TOP_BOX
==
0x0424
);
let
AUDIO_VIDEO_HIFI_AUDIO
=
bluetooth
.
MajorMinorClass
.
AUDIO_VIDEO_HIFI_AUDIO
;
console
.
info
(
"
[bluetooth_js]AUDIO_VIDEO_HIFI_AUDIO :
"
+
JSON
.
stringify
(
AUDIO_VIDEO_HIFI_AUDIO
));
expect
(
true
).
assertTrue
(
AUDIO_VIDEO_HIFI_AUDIO
==
0x0428
);
let
AUDIO_VIDEO_VCR
=
bluetooth
.
MajorMinorClass
.
AUDIO_VIDEO_VCR
;
console
.
info
(
"
[bluetooth_js]AUDIO_VIDEO_VCR :
"
+
JSON
.
stringify
(
AUDIO_VIDEO_VCR
));
expect
(
true
).
assertTrue
(
AUDIO_VIDEO_VCR
==
0x042C
);
let
AUDIO_VIDEO_VIDEO_CAMERA
=
bluetooth
.
MajorMinorClass
.
AUDIO_VIDEO_VIDEO_CAMERA
;
console
.
info
(
"
[bluetooth_js]AUDIO_VIDEO_VIDEO_CAMERA :
"
+
JSON
.
stringify
(
AUDIO_VIDEO_VIDEO_CAMERA
));
expect
(
true
).
assertTrue
(
AUDIO_VIDEO_VIDEO_CAMERA
==
0x0430
);
let
AUDIO_VIDEO_CAMCORDER
=
bluetooth
.
MajorMinorClass
.
AUDIO_VIDEO_CAMCORDER
;
console
.
info
(
"
[bluetooth_js]AUDIO_VIDEO_CAMCORDER :
"
+
JSON
.
stringify
(
AUDIO_VIDEO_CAMCORDER
));
expect
(
true
).
assertTrue
(
AUDIO_VIDEO_CAMCORDER
==
0x0434
);
let
AUDIO_VIDEO_VIDEO_MONITOR
=
bluetooth
.
MajorMinorClass
.
AUDIO_VIDEO_VIDEO_MONITOR
;
console
.
info
(
"
[bluetooth_js]AUDIO_VIDEO_VIDEO_MONITOR :
"
+
JSON
.
stringify
(
AUDIO_VIDEO_VIDEO_MONITOR
));
expect
(
true
).
assertTrue
(
AUDIO_VIDEO_VIDEO_MONITOR
==
0x0438
);
let
AUDIO_VIDEO_VIDEO_DISPLAY_AND_LOUDSPEAKER
=
bluetooth
.
MajorMinorClass
.
AUDIO_VIDEO_VIDEO_DISPLAY_AND_LOUDSPEAKER
;
console
.
info
(
"
[bluetooth_js]AUDIO_VIDEO_VIDEO_DISPLAY_AND_LOUDSPEAKER :
"
+
JSON
.
stringify
(
AUDIO_VIDEO_VIDEO_DISPLAY_AND_LOUDSPEAKER
));
expect
(
true
).
assertTrue
(
AUDIO_VIDEO_VIDEO_DISPLAY_AND_LOUDSPEAKER
==
0x043C
);
let
AUDIO_VIDEO_VIDEO_CONFERENCING
=
bluetooth
.
MajorMinorClass
.
AUDIO_VIDEO_VIDEO_CONFERENCING
;
console
.
info
(
"
[bluetooth_js]AUDIO_VIDEO_VIDEO_CONFERENCING :
"
+
JSON
.
stringify
(
AUDIO_VIDEO_VIDEO_CONFERENCING
));
expect
(
true
).
assertTrue
(
AUDIO_VIDEO_VIDEO_CONFERENCING
==
0x0440
);
let
AUDIO_VIDEO_VIDEO_GAMING_TOY
=
bluetooth
.
MajorMinorClass
.
AUDIO_VIDEO_VIDEO_GAMING_TOY
;
console
.
info
(
"
[bluetooth_js]AUDIO_VIDEO_VIDEO_GAMING_TOY :
"
+
JSON
.
stringify
(
AUDIO_VIDEO_VIDEO_GAMING_TOY
));
expect
(
true
).
assertTrue
(
AUDIO_VIDEO_VIDEO_GAMING_TOY
==
0x0448
);
let
PERIPHERAL_NON_KEYBOARD_NON_POINTING
=
bluetooth
.
MajorMinorClass
.
PERIPHERAL_NON_KEYBOARD_NON_POINTING
;
console
.
info
(
"
[bluetooth_js]PERIPHERAL_NON_KEYBOARD_NON_POINTING :
"
+
JSON
.
stringify
(
PERIPHERAL_NON_KEYBOARD_NON_POINTING
));
expect
(
true
).
assertTrue
(
PERIPHERAL_NON_KEYBOARD_NON_POINTING
==
0x0500
);
let
PERIPHERAL_KEYBOARD
=
bluetooth
.
MajorMinorClass
.
PERIPHERAL_KEYBOARD
;
console
.
info
(
"
[bluetooth_js]PERIPHERAL_KEYBOARD :
"
+
JSON
.
stringify
(
PERIPHERAL_KEYBOARD
));
expect
(
true
).
assertTrue
(
PERIPHERAL_KEYBOARD
==
0x0540
);
let
PERIPHERAL_POINTING_DEVICE
=
bluetooth
.
MajorMinorClass
.
PERIPHERAL_POINTING_DEVICE
;
console
.
info
(
"
[bluetooth_js]PERIPHERAL_POINTING_DEVICE :
"
+
JSON
.
stringify
(
PERIPHERAL_POINTING_DEVICE
));
expect
(
true
).
assertTrue
(
PERIPHERAL_POINTING_DEVICE
==
0x0580
);
let
PERIPHERAL_KEYBOARD_POINTING
=
bluetooth
.
MajorMinorClass
.
PERIPHERAL_KEYBOARD_POINTING
;
console
.
info
(
"
[bluetooth_js]PERIPHERAL_KEYBOARD_POINTING :
"
+
JSON
.
stringify
(
PERIPHERAL_KEYBOARD_POINTING
));
expect
(
true
).
assertTrue
(
PERIPHERAL_KEYBOARD_POINTING
==
0x05C0
);
let
PERIPHERAL_UNCATEGORIZED
=
bluetooth
.
MajorMinorClass
.
PERIPHERAL_UNCATEGORIZED
;
console
.
info
(
"
[bluetooth_js]PERIPHERAL_UNCATEGORIZED :
"
+
JSON
.
stringify
(
PERIPHERAL_UNCATEGORIZED
));
expect
(
true
).
assertTrue
(
PERIPHERAL_UNCATEGORIZED
==
0x0500
);
let
PERIPHERAL_JOYSTICK
=
bluetooth
.
MajorMinorClass
.
PERIPHERAL_JOYSTICK
;
console
.
info
(
"
[bluetooth_js]PERIPHERAL_JOYSTICK :
"
+
JSON
.
stringify
(
PERIPHERAL_JOYSTICK
));
expect
(
true
).
assertTrue
(
PERIPHERAL_JOYSTICK
==
0x0504
);
let
PERIPHERAL_GAMEPAD
=
bluetooth
.
MajorMinorClass
.
PERIPHERAL_GAMEPAD
;
console
.
info
(
"
[bluetooth_js]PERIPHERAL_GAMEPAD :
"
+
JSON
.
stringify
(
PERIPHERAL_GAMEPAD
));
expect
(
true
).
assertTrue
(
PERIPHERAL_GAMEPAD
==
0x0508
);
let
PERIPHERAL_REMOTE_CONTROL
=
bluetooth
.
MajorMinorClass
.
PERIPHERAL_REMOTE_CONTROL
;
console
.
info
(
"
[bluetooth_js]PERIPHERAL_REMOTE_CONTROL :
"
+
JSON
.
stringify
(
PERIPHERAL_REMOTE_CONTROL
));
expect
(
true
).
assertTrue
(
PERIPHERAL_REMOTE_CONTROL
==
0x05C0
);
let
PERIPHERAL_SENSING_DEVICE
=
bluetooth
.
MajorMinorClass
.
PERIPHERAL_SENSING_DEVICE
;
console
.
info
(
"
[bluetooth_js]PERIPHERAL_SENSING_DEVICE :
"
+
JSON
.
stringify
(
PERIPHERAL_SENSING_DEVICE
));
expect
(
true
).
assertTrue
(
PERIPHERAL_SENSING_DEVICE
==
0x0510
);
let
PERIPHERAL_DIGITIZER_TABLET
=
bluetooth
.
MajorMinorClass
.
PERIPHERAL_DIGITIZER_TABLET
;
console
.
info
(
"
[bluetooth_js]PERIPHERAL_DIGITIZER_TABLET :
"
+
JSON
.
stringify
(
PERIPHERAL_DIGITIZER_TABLET
));
expect
(
true
).
assertTrue
(
PERIPHERAL_DIGITIZER_TABLET
==
0x0514
);
let
PERIPHERAL_CARD_READER
=
bluetooth
.
MajorMinorClass
.
PERIPHERAL_CARD_READER
;
console
.
info
(
"
[bluetooth_js]PERIPHERAL_CARD_READER :
"
+
JSON
.
stringify
(
PERIPHERAL_CARD_READER
));
expect
(
true
).
assertTrue
(
PERIPHERAL_CARD_READER
==
0x0518
);
let
PERIPHERAL_DIGITAL_PEN
=
bluetooth
.
MajorMinorClass
.
PERIPHERAL_DIGITAL_PEN
;
console
.
info
(
"
[bluetooth_js]PERIPHERAL_DIGITAL_PEN :
"
+
JSON
.
stringify
(
PERIPHERAL_DIGITAL_PEN
));
expect
(
true
).
assertTrue
(
PERIPHERAL_DIGITAL_PEN
==
0x051C
);
let
PERIPHERAL_SCANNER_RFID
=
bluetooth
.
MajorMinorClass
.
PERIPHERAL_SCANNER_RFID
;
console
.
info
(
"
[bluetooth_js]PERIPHERAL_SCANNER_RFID :
"
+
JSON
.
stringify
(
PERIPHERAL_SCANNER_RFID
));
expect
(
true
).
assertTrue
(
PERIPHERAL_SCANNER_RFID
==
0x0520
);
let
PERIPHERAL_GESTURAL_INPUT
=
bluetooth
.
MajorMinorClass
.
PERIPHERAL_GESTURAL_INPUT
;
console
.
info
(
"
[bluetooth_js]PERIPHERAL_GESTURAL_INPUT :
"
+
JSON
.
stringify
(
PERIPHERAL_GESTURAL_INPUT
));
expect
(
true
).
assertTrue
(
PERIPHERAL_GESTURAL_INPUT
==
0x0522
);
let
IMAGING_UNCATEGORIZED
=
bluetooth
.
MajorMinorClass
.
IMAGING_UNCATEGORIZED
;
console
.
info
(
"
[bluetooth_js]IMAGING_UNCATEGORIZED :
"
+
JSON
.
stringify
(
IMAGING_UNCATEGORIZED
));
expect
(
true
).
assertTrue
(
IMAGING_UNCATEGORIZED
==
0x0600
);
let
IMAGING_DISPLAY
=
bluetooth
.
MajorMinorClass
.
IMAGING_DISPLAY
;
console
.
info
(
"
[bluetooth_js]IMAGING_DISPLAY :
"
+
JSON
.
stringify
(
IMAGING_DISPLAY
));
expect
(
true
).
assertTrue
(
IMAGING_DISPLAY
==
0x0610
);
let
IMAGING_CAMERA
=
bluetooth
.
MajorMinorClass
.
IMAGING_CAMERA
;
console
.
info
(
"
[bluetooth_js]IMAGING_CAMERA :
"
+
JSON
.
stringify
(
IMAGING_CAMERA
));
expect
(
true
).
assertTrue
(
IMAGING_CAMERA
==
0x0620
);
let
IMAGING_SCANNER
=
bluetooth
.
MajorMinorClass
.
IMAGING_SCANNER
;
console
.
info
(
"
[bluetooth_js]IMAGING_SCANNER :
"
+
JSON
.
stringify
(
IMAGING_SCANNER
));
expect
(
true
).
assertTrue
(
IMAGING_SCANNER
==
0x0640
);
let
IMAGING_PRINTER
=
bluetooth
.
MajorMinorClass
.
IMAGING_PRINTER
;
console
.
info
(
"
[bluetooth_js]IMAGING_PRINTER :
"
+
JSON
.
stringify
(
IMAGING_PRINTER
));
expect
(
true
).
assertTrue
(
IMAGING_PRINTER
==
0x0680
);
let
WEARABLE_UNCATEGORIZED
=
bluetooth
.
MajorMinorClass
.
WEARABLE_UNCATEGORIZED
;
console
.
info
(
"
[bluetooth_js]WEARABLE_UNCATEGORIZED :
"
+
JSON
.
stringify
(
WEARABLE_UNCATEGORIZED
));
expect
(
true
).
assertTrue
(
WEARABLE_UNCATEGORIZED
==
0x0700
);
let
WEARABLE_WRIST_WATCH
=
bluetooth
.
MajorMinorClass
.
WEARABLE_WRIST_WATCH
;
console
.
info
(
"
[bluetooth_js]WEARABLE_WRIST_WATCH :
"
+
JSON
.
stringify
(
WEARABLE_WRIST_WATCH
));
expect
(
true
).
assertTrue
(
WEARABLE_WRIST_WATCH
==
0x0704
);
let
WEARABLE_PAGER
=
bluetooth
.
MajorMinorClass
.
WEARABLE_PAGER
;
console
.
info
(
"
[bluetooth_js]WEARABLE_PAGER :
"
+
JSON
.
stringify
(
WEARABLE_PAGER
));
expect
(
true
).
assertTrue
(
WEARABLE_PAGER
==
0x0708
);
let
WEARABLE_JACKET
=
bluetooth
.
MajorMinorClass
.
WEARABLE_JACKET
;
console
.
info
(
"
[bluetooth_js]WEARABLE_JACKET :
"
+
JSON
.
stringify
(
WEARABLE_JACKET
));
expect
(
true
).
assertTrue
(
WEARABLE_JACKET
==
0x070C
);
let
WEARABLE_HELMET
=
bluetooth
.
MajorMinorClass
.
WEARABLE_HELMET
;
console
.
info
(
"
[bluetooth_js]WEARABLE_HELMET :
"
+
JSON
.
stringify
(
WEARABLE_HELMET
));
expect
(
true
).
assertTrue
(
WEARABLE_HELMET
==
0x0710
);
let
WEARABLE_GLASSES
=
bluetooth
.
MajorMinorClass
.
WEARABLE_GLASSES
;
console
.
info
(
"
[bluetooth_js]WEARABLE_GLASSES :
"
+
JSON
.
stringify
(
WEARABLE_GLASSES
));
expect
(
true
).
assertTrue
(
WEARABLE_GLASSES
==
0x0714
);
let
TOY_UNCATEGORIZED
=
bluetooth
.
MajorMinorClass
.
TOY_UNCATEGORIZED
;
console
.
info
(
"
[bluetooth_js]TOY_UNCATEGORIZED :
"
+
JSON
.
stringify
(
TOY_UNCATEGORIZED
));
expect
(
true
).
assertTrue
(
TOY_UNCATEGORIZED
==
0x0800
);
let
TOY_ROBOT
=
bluetooth
.
MajorMinorClass
.
TOY_ROBOT
;
console
.
info
(
"
[bluetooth_js]TOY_ROBOT :
"
+
JSON
.
stringify
(
TOY_ROBOT
));
expect
(
true
).
assertTrue
(
TOY_ROBOT
==
0x0804
);
let
TOY_VEHICLE
=
bluetooth
.
MajorMinorClass
.
TOY_VEHICLE
;
console
.
info
(
"
[bluetooth_js]TOY_VEHICLE :
"
+
JSON
.
stringify
(
TOY_VEHICLE
));
expect
(
true
).
assertTrue
(
TOY_VEHICLE
==
0x0808
);
let
TOY_DOLL_ACTION_FIGURE
=
bluetooth
.
MajorMinorClass
.
TOY_DOLL_ACTION_FIGURE
;
console
.
info
(
"
[bluetooth_js]TOY_DOLL_ACTION_FIGURE :
"
+
JSON
.
stringify
(
TOY_DOLL_ACTION_FIGURE
));
expect
(
true
).
assertTrue
(
TOY_DOLL_ACTION_FIGURE
==
0x080C
);
let
TOY_CONTROLLER
=
bluetooth
.
MajorMinorClass
.
TOY_CONTROLLER
;
console
.
info
(
"
[bluetooth_js]TOY_CONTROLLER :
"
+
JSON
.
stringify
(
TOY_CONTROLLER
));
expect
(
true
).
assertTrue
(
TOY_CONTROLLER
==
0x0810
);
let
TOY_GAME
=
bluetooth
.
MajorMinorClass
.
TOY_GAME
;
console
.
info
(
"
[bluetooth_js]TOY_GAME :
"
+
JSON
.
stringify
(
TOY_GAME
));
expect
(
true
).
assertTrue
(
TOY_GAME
==
0x0814
);
let
HEALTH_UNCATEGORIZED
=
bluetooth
.
MajorMinorClass
.
HEALTH_UNCATEGORIZED
;
console
.
info
(
"
[bluetooth_js]HEALTH_UNCATEGORIZED :
"
+
JSON
.
stringify
(
HEALTH_UNCATEGORIZED
));
expect
(
true
).
assertTrue
(
HEALTH_UNCATEGORIZED
==
0x0900
);
let
HEALTH_BLOOD_PRESSURE
=
bluetooth
.
MajorMinorClass
.
HEALTH_BLOOD_PRESSURE
;
console
.
info
(
"
[bluetooth_js]HEALTH_BLOOD_PRESSURE :
"
+
JSON
.
stringify
(
HEALTH_BLOOD_PRESSURE
));
expect
(
true
).
assertTrue
(
HEALTH_BLOOD_PRESSURE
==
0x0904
);
let
HEALTH_THERMOMETER
=
bluetooth
.
MajorMinorClass
.
HEALTH_THERMOMETER
;
console
.
info
(
"
[bluetooth_js]HEALTH_THERMOMETER :
"
+
JSON
.
stringify
(
HEALTH_THERMOMETER
));
expect
(
true
).
assertTrue
(
HEALTH_THERMOMETER
==
0x0908
);
let
HEALTH_WEIGHING
=
bluetooth
.
MajorMinorClass
.
HEALTH_WEIGHING
;
console
.
info
(
"
[bluetooth_js]HEALTH_WEIGHING :
"
+
JSON
.
stringify
(
HEALTH_WEIGHING
));
expect
(
true
).
assertTrue
(
HEALTH_WEIGHING
==
0x090C
);
let
HEALTH_GLUCOSE
=
bluetooth
.
MajorMinorClass
.
HEALTH_GLUCOSE
;
console
.
info
(
"
[bluetooth_js]HEALTH_GLUCOSE :
"
+
JSON
.
stringify
(
HEALTH_GLUCOSE
));
expect
(
true
).
assertTrue
(
HEALTH_GLUCOSE
==
0x0910
);
let
HEALTH_PULSE_OXIMETER
=
bluetooth
.
MajorMinorClass
.
HEALTH_PULSE_OXIMETER
;
console
.
info
(
"
[bluetooth_js]HEALTH_PULSE_OXIMETER :
"
+
JSON
.
stringify
(
HEALTH_PULSE_OXIMETER
));
expect
(
true
).
assertTrue
(
HEALTH_PULSE_OXIMETER
==
0x0914
);
let
HEALTH_PULSE_RATE
=
bluetooth
.
MajorMinorClass
.
HEALTH_PULSE_RATE
;
console
.
info
(
"
[bluetooth_js]HEALTH_PULSE_RATE :
"
+
JSON
.
stringify
(
HEALTH_PULSE_RATE
));
expect
(
true
).
assertTrue
(
HEALTH_PULSE_RATE
==
0x0918
);
let
HEALTH_DATA_DISPLAY
=
bluetooth
.
MajorMinorClass
.
HEALTH_DATA_DISPLAY
;
console
.
info
(
"
[bluetooth_js]HEALTH_DATA_DISPLAY :
"
+
JSON
.
stringify
(
HEALTH_DATA_DISPLAY
));
expect
(
true
).
assertTrue
(
HEALTH_DATA_DISPLAY
==
0x091C
);
let
HEALTH_STEP_COUNTER
=
bluetooth
.
MajorMinorClass
.
HEALTH_STEP_COUNTER
;
console
.
info
(
"
[bluetooth_js]HEALTH_STEP_COUNTER :
"
+
JSON
.
stringify
(
HEALTH_STEP_COUNTER
));
expect
(
true
).
assertTrue
(
HEALTH_STEP_COUNTER
==
0x0920
);
let
HEALTH_BODY_COMPOSITION_ANALYZER
=
bluetooth
.
MajorMinorClass
.
HEALTH_BODY_COMPOSITION_ANALYZER
;
console
.
info
(
"
[bluetooth_js]HEALTH_BODY_COMPOSITION_ANALYZER :
"
+
JSON
.
stringify
(
HEALTH_BODY_COMPOSITION_ANALYZER
));
expect
(
true
).
assertTrue
(
HEALTH_BODY_COMPOSITION_ANALYZER
==
0x0924
);
let
HEALTH_PEAK_FLOW_MONITOR
=
bluetooth
.
MajorMinorClass
.
HEALTH_PEAK_FLOW_MONITOR
;
console
.
info
(
"
[bluetooth_js]HEALTH_PEAK_FLOW_MONITOR :
"
+
JSON
.
stringify
(
HEALTH_PEAK_FLOW_MONITOR
));
expect
(
true
).
assertTrue
(
HEALTH_PEAK_FLOW_MONITOR
==
0x0928
);
let
HEALTH_MEDICATION_MONITOR
=
bluetooth
.
MajorMinorClass
.
HEALTH_MEDICATION_MONITOR
;
console
.
info
(
"
[bluetooth_js]HEALTH_MEDICATION_MONITOR :
"
+
JSON
.
stringify
(
HEALTH_MEDICATION_MONITOR
));
expect
(
true
).
assertTrue
(
HEALTH_MEDICATION_MONITOR
==
0x092C
);
let
HEALTH_KNEE_PROSTHESIS
=
bluetooth
.
MajorMinorClass
.
HEALTH_KNEE_PROSTHESIS
;
console
.
info
(
"
[bluetooth_js]HEALTH_KNEE_PROSTHESIS :
"
+
JSON
.
stringify
(
HEALTH_KNEE_PROSTHESIS
));
expect
(
true
).
assertTrue
(
HEALTH_KNEE_PROSTHESIS
==
0x0930
);
let
HEALTH_ANKLE_PROSTHESIS
=
bluetooth
.
MajorMinorClass
.
HEALTH_ANKLE_PROSTHESIS
;
console
.
info
(
"
[bluetooth_js]HEALTH_ANKLE_PROSTHESIS :
"
+
JSON
.
stringify
(
HEALTH_ANKLE_PROSTHESIS
));
expect
(
true
).
assertTrue
(
HEALTH_ANKLE_PROSTHESIS
==
0x0934
);
let
HEALTH_GENERIC_HEALTH_MANAGER
=
bluetooth
.
MajorMinorClass
.
HEALTH_GENERIC_HEALTH_MANAGER
;
console
.
info
(
"
[bluetooth_js]HEALTH_GENERIC_HEALTH_MANAGER :
"
+
JSON
.
stringify
(
HEALTH_GENERIC_HEALTH_MANAGER
));
expect
(
true
).
assertTrue
(
HEALTH_GENERIC_HEALTH_MANAGER
==
0x0938
);
let
HEALTH_PERSONAL_MOBILITY_DEVICE
=
bluetooth
.
MajorMinorClass
.
HEALTH_PERSONAL_MOBILITY_DEVICE
;
console
.
info
(
"
[bluetooth_js]HEALTH_PERSONAL_MOBILITY_DEVICE :
"
+
JSON
.
stringify
(
HEALTH_PERSONAL_MOBILITY_DEVICE
));
expect
(
true
).
assertTrue
(
HEALTH_PERSONAL_MOBILITY_DEVICE
==
0x093C
);
done
();
})
})
}
\ No newline at end of file
communication/bluetooth_standard/src/main/js/test/BtSocket.test.js
0 → 100644
浏览文件 @
ff96c6dc
/*
* Copyright (C) 2022 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import
bluetooth
from
'
@ohos.bluetooth.socket
'
;
import
btAccess
from
'
@ohos.bluetooth.access
'
;
import
{
describe
,
beforeAll
,
beforeEach
,
afterEach
,
afterAll
,
it
,
expect
}
from
'
@ohos/hypium
'
export
default
function
btSocketTest
()
{
describe
(
'
btSocketTest
'
,
function
()
{
function
sleep
(
delay
)
{
return
new
Promise
(
resovle
=>
setTimeout
(
resovle
,
delay
))
}
async
function
tryToEnableBt
()
{
let
sta
=
btAccess
.
getState
();
switch
(
sta
)
{
case
0
:
btAccess
.
enableBluetooth
();
await
sleep
(
10000
);
let
sta1
=
btAccess
.
getState
();
console
.
info
(
'
[bluetooth_js] bt turn off:
'
+
JSON
.
stringify
(
sta1
));
break
;
case
1
:
console
.
info
(
'
[bluetooth_js] bt turning on:
'
+
JSON
.
stringify
(
sta
));
await
sleep
(
3000
);
break
;
case
2
:
console
.
info
(
'
[bluetooth_js] bt turn on:
'
+
JSON
.
stringify
(
sta
));
break
;
case
3
:
btAccess
.
enableBluetooth
();
await
sleep
(
10000
);
let
sta2
=
btAccess
.
getState
();
console
.
info
(
'
[bluetooth_js] bt turning off:
'
+
JSON
.
stringify
(
sta2
));
break
;
default
:
console
.
info
(
'
[bluetooth_js] enable success
'
);
}
}
beforeAll
(
function
()
{
console
.
info
(
'
beforeAll called
'
)
})
beforeEach
(
async
function
(
done
)
{
console
.
info
(
'
beforeEach called
'
)
await
tryToEnableBt
()
done
()
})
afterEach
(
function
()
{
console
.
info
(
'
afterEach called
'
)
})
afterAll
(
function
()
{
console
.
info
(
'
afterAll called
'
)
})
/**
* @tc.number SUB_COMMUNICATION_BLUETOOTHSOCKET_SPP_0100
* @tc.name test SppListen
* @tc.desc Test SppListen api10
* @tc.type Function
* @tc.level Level 1
*/
it
(
'
SUB_COMMUNICATION_BLUETOOTHSOCKET_SPP_0100
'
,
0
,
async
function
(
done
)
{
let
SppOptions
=
{
uuid
:
'
00001810-0000-1000-8000-00805F9B34FB
'
,
secure
:
false
,
type
:
bluetooth
.
SppType
.
SPP_RFCOMM
};
let
serverNumber
=
-
1
;
function
serverSocket
(
code
,
number
)
{
if
(
code
)
{
console
.
log
(
'
bluetooth error code01:
'
+
code
);
}
else
{
console
.
log
(
'
bluetooth serverSocket Number:
'
+
JSON
.
stringify
(
number
));
serverNumber
=
number
;
expect
(
true
).
assertEqual
(
serverNumber
!=
-
1
);
}
}
try
{
await
bluetooth
.
sppListen
(
'
server1
'
,
SppOptions
,
serverSocket
);
}
catch
(
error
)
{
console
.
error
(
`[bluetooth_js]SPPListen error, code is
${
error
.
code
}
,message is
${
error
.
message
}
`
);
expect
(
true
).
assertEqual
(
error
==
null
);
}
done
();
})
/**
* @tc.number SUB_COMMUNICATION_BLUETOOTHSOCKET_SPP_0200
* @tc.name testSppAccept
* @tc.desc Test SppAccept api10
* @tc.type Function
* @tc.level Level 2
*/
it
(
'
SUB_COMMUNICATION_BLUETOOTHSOCKET_SPP_0200
'
,
0
,
async
function
(
done
)
{
let
SppOption
=
{
uuid
:
'
00001810-0000-1000-8000-00805F9B34FB
'
,
secure
:
false
,
type
:
bluetooth
.
SppType
.
SPP_RFCOMM
};
let
serverNumber
=
-
1
;
function
serverSocket
(
code
,
number
)
{
if
(
code
)
{
console
.
log
(
'
bluetooth error code02:
'
+
code
);
}
else
{
console
.
log
(
'
bluetooth serverSocket Number02:
'
+
JSON
.
stringify
(
number
));
serverNumber
=
number
;
expect
(
true
).
assertEqual
(
serverNumber
!=
-
1
);
}
}
bluetooth
.
sppListen
(
'
server_accept
'
,
SppOption
,
serverSocket
);
let
clientNumber
=
-
1
;
function
acceptClientSocket
(
code
,
number
)
{
console
.
log
(
'
bluetooth error code:
'
+
code
.
code
);
if
(
code
.
code
==
0
)
{
console
.
log
(
'
bluetooth clientSocket Number:
'
+
number
);
clientNumber
=
number
;
expect
(
true
).
assertEqual
(
clientNumber
!=
-
1
);
}
}
try
{
bluetooth
.
sppAccept
(
serverNumber
,
acceptClientSocket
);
}
catch
(
error
)
{
console
.
error
(
`[bluetooth_js]SPPAccept error, code is
${
error
.
code
}
,message is
${
error
.
message
}
`
);
expect
(
error
.
code
).
assertEqual
(
'
401
'
);
}
done
();
})
/**
* @tc.number SUB_COMMUNICATION_BLUETOOTHSOCKET_SPP_0300
* @tc.name test SppConnect
* @tc.desc Test SppConnect api10
* @tc.type Function
* @tc.level Level 1
*/
it
(
'
SUB_COMMUNICATION_BLUETOOTHSOCKET_SPP_0300
'
,
0
,
async
function
(
done
)
{
let
sppOption
=
{
uuid
:
'
00001810-0000-1000-8000-00805F9B34FB
'
,
secure
:
true
,
type
:
0
};
try
{
await
bluetooth
.
sppConnect
(
'
00:11:22:33:44:55
'
,
sppOption
,
function
(
code
,
number
)
{
if
(
code
)
{
console
.
info
(
'
[bluetooth_js] code is:
'
+
JSON
.
stringify
(
code
));
}
else
{
console
.
log
(
'
[bluetooth_js]sppConnect Number:
'
+
JSON
.
stringify
(
number
));
expect
(
true
).
assertEqual
(
number
!=
null
);
}
});
}
catch
(
error
)
{
console
.
error
(
`[bluetooth_js]SPPConnect error, code is
${
error
.
code
}
,message is
${
error
.
message
}
`
);
expect
(
true
).
assertEqual
(
error
==
null
);
}
done
();
})
/**
* @tc.number SUB_COMMUNICATION_BLUETOOTHSOCKET_SPP_0400
* @tc.name test sppReadOn
* @tc.desc Test On and Off api10
* @tc.type Function
* @tc.level Level 2
*/
it
(
'
SUB_COMMUNICATION_BLUETOOTHSOCKET_SPP_0400
'
,
0
,
async
function
(
done
)
{
let
SppOption
=
{
uuid
:
'
00001810-0000-1000-8000-00805F9B34FB
'
,
secure
:
false
,
type
:
bluetooth
.
SppType
.
SPP_RFCOMM
};
let
serverNumber
=
-
1
;
function
serverSocket
(
code
,
number
)
{
if
(
code
)
{
console
.
log
(
'
bluetooth error code01:
'
+
code
);
}
else
{
console
.
log
(
'
bluetooth serverSocket Number:
'
+
JSON
.
stringify
(
number
));
serverNumber
=
number
;
expect
(
true
).
assertEqual
(
serverNumber
!=
-
1
);
}
}
let
clientNumber
=
-
1
;
function
acceptClientSocket
(
code
,
number
)
{
console
.
log
(
'
bluetooth error code:
'
+
code
.
code
);
if
(
code
.
code
==
0
)
{
console
.
log
(
'
bluetooth clientSocket Number:
'
+
number
);
clientNumber
=
number
;
expect
(
true
).
assertEqual
(
clientNumber
!=
-
1
);
}
}
function
dataRead
(
dataBuffer
)
{
let
data
=
new
Uint8Array
(
dataBuffer
);
console
.
log
(
'
bluetooth data is:
'
+
data
[
0
]);
}
try
{
bluetooth
.
sppListen
(
'
server04
'
,
SppOption
,
serverSocket
);
bluetooth
.
sppAccept
(
serverNumber
,
acceptClientSocket
);
bluetooth
.
on
(
'
sppRead
'
,
clientNumber
,
dataRead
);
bluetooth
.
off
(
'
sppRead
'
,
clientNumber
);
}
catch
(
err
)
{
console
.
error
(
"
errCode:
"
+
err
.
code
+
"
,errMessage:
"
+
err
.
message
);
expect
(
err
.
code
).
assertEqual
(
'
401
'
);
}
done
();
})
/**
* @tc.number SUB_COMMUNICATION_BLUETOOTHSOCKET_SPP_0800
* @tc.name test sppReadOn
* @tc.desc Test On and Off api10
* @tc.type Function
* @tc.level Level 2
*/
it
(
'
SUB_COMMUNICATION_BLUETOOTHSOCKET_SPP_0800
'
,
0
,
async
function
(
done
)
{
let
SppOption
=
{
uuid
:
'
00001810-0000-1000-8000-00805F9B34FB
'
,
secure
:
false
,
type
:
bluetooth
.
SppType
.
SPP_RFCOMM
};
let
serverNumber
=
-
1
;
function
serverSocket
(
code
,
number
)
{
if
(
code
)
{
console
.
log
(
'
bluetooth error code01:
'
+
code
);
}
else
{
console
.
log
(
'
bluetooth serverSocket Number:
'
+
JSON
.
stringify
(
number
));
serverNumber
=
number
;
expect
(
true
).
assertEqual
(
serverNumber
!=
-
1
);
}
}
let
clientNumber
=
-
1
;
function
acceptClientSocket
(
code
,
number
)
{
console
.
log
(
'
bluetooth error code:
'
+
code
.
code
);
if
(
code
.
code
==
0
)
{
console
.
log
(
'
bluetooth clientSocket Number:
'
+
number
);
clientNumber
=
number
;
expect
(
true
).
assertEqual
(
clientNumber
!=
-
1
);
}
}
function
dataRead
(
dataBuffer
)
{
let
data
=
new
Uint8Array
(
dataBuffer
);
console
.
log
(
'
bluetooth data is:
'
+
data
[
0
]);
}
try
{
bluetooth
.
sppListen
(
'
server08
'
,
SppOption
,
serverSocket
);
bluetooth
.
sppAccept
(
serverNumber
,
acceptClientSocket
);
bluetooth
.
on
(
'
sppRead
'
,
clientNumber
,
dataRead
);
bluetooth
.
off
(
'
sppRead
'
,
clientNumber
);
}
catch
(
err
)
{
console
.
error
(
"
errCode:
"
+
err
.
code
+
"
,errMessage:
"
+
err
.
message
);
expect
(
err
.
code
).
assertEqual
(
'
401
'
);
}
done
();
})
/**
* @tc.number SUB_COMMUNICATION_BLUETOOTHSOCKET_SPP_0500
* @tc.name testsppCloseServerSocket
* @tc.desc Test sppCloseServerSocket api10 by callback.
* @tc.type Function
* @tc.level Level 3
*/
it
(
'
SUB_COMMUNICATION_BLUETOOTHSOCKET_SPP_0500
'
,
0
,
async
function
(
done
)
{
let
serverNumber
=
-
1
;
function
serverSocket
(
code
,
number
)
{
if
(
code
)
{
console
.
log
(
'
bluetooth error code10:
'
+
JSON
.
stringify
(
code
));
}
else
{
console
.
log
(
'
bluetooth serverSocket Number:
'
+
JSON
.
stringify
(
number
));
serverNumber
=
number
;
expect
(
true
).
assertEqual
(
serverNumber
!=
null
);
}
}
let
SppOption
=
{
uuid
:
'
00001810-0000-1000-8000-00805F9B34FB
'
,
secure
:
true
,
type
:
0
};
await
bluetooth
.
sppListen
(
'
server1
'
,
SppOption
,
serverSocket
);
try
{
bluetooth
.
sppCloseServerSocket
(
serverNumber
);
}
catch
(
err
)
{
console
.
error
(
"
errCode:
"
+
err
.
code
+
"
,errMessage:
"
+
err
.
message
);
expect
(
true
).
assertEqual
(
error
==
null
);
}
done
();
})
/**
* @tc.number SUB_COMMUNICATION_BLUETOOTHSOCKET_SPP_0600
* @tc.name testsppCloseClientSocket
* @tc.desc Test sppCloseClientSocket api10 by callback.
* @tc.type Function
* @tc.level Level 3
*/
it
(
'
SUB_COMMUNICATION_BLUETOOTHSOCKET_SPP_0600
'
,
0
,
async
function
(
done
)
{
let
SppOption
=
{
uuid
:
'
00001810-0000-1000-8000-00805F9B34FB
'
,
secure
:
false
,
type
:
bluetooth
.
SppType
.
SPP_RFCOMM
};
let
serverNumber
=
-
1
;
function
serverSocket
(
code
,
number
)
{
if
(
code
)
{
console
.
log
(
'
bluetooth error code01:
'
+
code
);
}
else
{
console
.
log
(
'
bluetooth serverSocket Number:
'
+
JSON
.
stringify
(
number
));
serverNumber
=
number
;
expect
(
true
).
assertEqual
(
serverNumber
!=
-
1
);
}
}
let
clientNumber
=
-
1
;
function
acceptClientSocket
(
code
,
number
)
{
console
.
log
(
'
bluetooth error code:
'
+
code
.
code
);
if
(
code
.
code
==
0
)
{
console
.
log
(
'
bluetooth clientSocket Number:
'
+
number
);
clientNumber
=
number
;
expect
(
true
).
assertEqual
(
clientNumber
!=
-
1
);
}
}
try
{
bluetooth
.
sppListen
(
'
server06
'
,
SppOption
,
serverSocket
);
bluetooth
.
sppAccept
(
serverNumber
,
acceptClientSocket
);
bluetooth
.
sppCloseClientSocket
(
clientNumber
);
}
catch
(
err
)
{
console
.
error
(
"
errCode:
"
+
err
.
code
+
"
,errMessage:
"
+
err
.
message
);
expect
(
err
.
code
).
assertEqual
(
'
401
'
);
}
done
();
})
/**
* @tc.number SUB_COMMUNICATION_BLUETOOTHSOCKET_SPP_0700
* @tc.name testSppWrite
* @tc.desc Test sppWrite api10
* @tc.type Function
* @tc.level Level 3
*/
it
(
'
SUB_COMMUNICATION_BLUETOOTHSOCKET_SPP_0700
'
,
0
,
async
function
(
done
)
{
let
SppOption
=
{
uuid
:
'
00001810-0000-1000-8000-00805F9B34FB
'
,
secure
:
false
,
type
:
bluetooth
.
SppType
.
SPP_RFCOMM
};
let
serverNumber
=
-
1
;
function
serverSocket
(
code
,
number
)
{
if
(
code
)
{
console
.
log
(
'
bluetooth error code01:
'
+
code
);
}
else
{
console
.
log
(
'
bluetooth serverSocket Number:
'
+
JSON
.
stringify
(
number
));
serverNumber
=
number
;
expect
(
true
).
assertEqual
(
serverNumber
!=
-
1
);
}
}
let
clientNumber
=
-
1
;
function
acceptClientSocket
(
code
,
number
)
{
console
.
log
(
'
bluetooth error code:
'
+
code
.
code
);
if
(
code
.
code
==
0
)
{
console
.
log
(
'
bluetooth clientSocket Number:
'
+
number
);
clientNumber
=
number
;
expect
(
true
).
assertEqual
(
clientNumber
!=
-
1
);
}
}
let
arrayBuffer
=
new
ArrayBuffer
(
8
);
let
data
=
new
Uint8Array
(
arrayBuffer
);
data
[
0
]
=
123
;
try
{
bluetooth
.
sppListen
(
'
server07
'
,
SppOption
,
serverSocket
);
bluetooth
.
sppAccept
(
serverNumber
,
acceptClientSocket
);
bluetooth
.
sppWrite
(
clientNumber
,
arrayBuffer
);
}
catch
(
err
)
{
console
.
error
(
"
errCode:
"
+
err
.
code
+
"
,errMessage:
"
+
err
.
message
);
expect
(
err
.
code
).
assertEqual
(
'
401
'
);
}
done
();
})
})
}
\ No newline at end of file
communication/bluetooth_standard/src/main/js/test/BtSpp.test.js
浏览文件 @
ff96c6dc
...
@@ -81,9 +81,9 @@ describe('btSppTest', function() {
...
@@ -81,9 +81,9 @@ describe('btSppTest', function() {
serverNumber
=
number
;
serverNumber
=
number
;
expect
(
true
).
assertEqual
(
number
!=
null
);
expect
(
true
).
assertEqual
(
number
!=
null
);
}
}
done
();
}
}
await
bluetooth
.
sppListen
(
'
server1
'
,
SppOption
,
serverSocket
);
bluetooth
.
sppListen
(
'
server1
'
,
SppOption
,
serverSocket
);
done
()
})
})
/**
/**
...
@@ -105,9 +105,9 @@ describe('btSppTest', function() {
...
@@ -105,9 +105,9 @@ describe('btSppTest', function() {
serverNumber
=
number
;
serverNumber
=
number
;
expect
(
true
).
assertEqual
(
number
!=
null
);
expect
(
true
).
assertEqual
(
number
!=
null
);
}
}
done
();
}
}
await
bluetooth
.
sppListen
(
'
server1
'
,
sppOption
,
serverSocket
);
bluetooth
.
sppListen
(
'
server1
'
,
sppOption
,
serverSocket
);
done
();
})
})
/**
/**
...
@@ -154,9 +154,9 @@ describe('btSppTest', function() {
...
@@ -154,9 +154,9 @@ describe('btSppTest', function() {
serverNumber
=
number
;
serverNumber
=
number
;
expect
(
true
).
assertEqual
(
serverNumber
!=
null
);
expect
(
true
).
assertEqual
(
serverNumber
!=
null
);
}
}
done
();
}
}
await
bluetooth
.
sppListen
(
'
server1
'
,
sppOption
,
serverSocket
);
bluetooth
.
sppListen
(
'
server1
'
,
sppOption
,
serverSocket
);
done
();
})
})
/**
/**
...
@@ -175,9 +175,9 @@ describe('btSppTest', function() {
...
@@ -175,9 +175,9 @@ describe('btSppTest', function() {
console
.
log
(
'
[bluetooth_js] clientSocket Number:
'
+
JSON
.
stringify
(
number
));
console
.
log
(
'
[bluetooth_js] clientSocket Number:
'
+
JSON
.
stringify
(
number
));
expect
(
true
).
assertEqual
(
number
!=
null
);
expect
(
true
).
assertEqual
(
number
!=
null
);
}
}
done
();
}
}
await
bluetooth
.
sppAccept
(
0
,
acceptClientSocket
);
bluetooth
.
sppAccept
(
0
,
acceptClientSocket
);
done
();
})
})
/**
/**
...
...
communication/bluetooth_standard/src/main/js/test/List.test.js
浏览文件 @
ff96c6dc
...
@@ -13,14 +13,20 @@
...
@@ -13,14 +13,20 @@
* limitations under the License.
* limitations under the License.
*/
*/
import
btAccessTest
from
'
./BluetoothAccess.test.js
'
import
btManagerSwitchTest
from
'
./BtManagerSetSwitch.test.js
'
import
btLocalNameTest
from
'
./BtSetLocalName.test.js
'
import
btLocalNameTest
from
'
./BtSetLocalName.test.js
'
import
btSwitchTest
from
'
./BtSetSwitch.test.js
'
import
btSwitchTest
from
'
./BtSetSwitch.test.js
'
import
btSppTest
from
'
./BtSpp.test.js
'
import
btSppTest
from
'
./BtSpp.test.js
'
import
btSubscBleTest
from
'
./BtSysSubscBle.test.js
'
import
btSubscBleTest
from
'
./BtSysSubscBle.test.js
'
import
btManagerSppTest
from
'
./BtManagerSpp.test.js
'
import
btManagerSppTest
from
'
./BtManagerSpp.test.js
'
import
btManagerSwitchTest
from
'
./BtManagerSetSwitch.test.js
'
import
btSocketTest
from
'
./BtSocket.test.js
'
import
btConstantTest
from
'
./BluetoothConstant.test.js
'
export
default
function
testsuite
()
{
export
default
function
testsuite
()
{
btAccessTest
()
btConstantTest
()
btSocketTest
()
btLocalNameTest
()
btLocalNameTest
()
btSwitchTest
()
btSwitchTest
()
btSppTest
()
btSppTest
()
...
...
communication/nfc_Controller/signature/openharmony_sx.p7b
浏览文件 @
ff96c6dc
无法预览此类型文件
communication/nfc_Controller/src/main/js/test/TagABFV.test.js
浏览文件 @
ff96c6dc
...
@@ -674,6 +674,36 @@ export default function nfcTagABFVTest() {
...
@@ -674,6 +674,36 @@ export default function nfcTagABFVTest() {
}
}
})
})
/**
* @tc.number SUB_Communication_NFC_nfctage_js_2300
* @tc.name Test registerForegroundDispatch
* @tc.desc This interface registerForegroundDispatch.
* @tc.size since 7
* @tc.type Function
* @tc.level Level 2
*/
it
(
'
SUB_Communication_NFC_nfctage_js_2300
'
,
0
,
function
()
{
let
elementName
=
{
"
bundleName
"
:
"
com.test.cardemulation
"
,
"
abilityName
"
:
"
MainAbility
"
,
"
moduleName
"
:
"
entry
"
};
let
discTech
=
[
1
,
2
,
4
];
try
{
let
recvNfcTagFunc
=
tagInfo
=>
{
console
.
info
(
"
[NFC_test] controller1 nfc state receive state ->
"
+
tagInfo
);
expect
(
tagInfo
!=
null
).
assertTrue
();
}
tag
.
registerForegroundDispatch
(
elementName
,
discTech
,
recvNfcTagFunc
);
console
.
info
(
'
[NFC_test] nfc registerForegroundDispatch pass
'
)
tag
.
unregisterForegroundDispatch
(
elementName
);
console
.
info
(
'
[NFC_test] nfc unregisterForegroundDispatch pass
'
)
}
catch
(
error
)
{
console
.
info
(
'
nfc registerForegroundDispatch error
'
+
error
)
expect
().
assertFail
();
}
})
console
.
info
(
"
*************[nfc_test] start nfc js unit test end*************
"
);
console
.
info
(
"
*************[nfc_test] start nfc js unit test end*************
"
);
})
})
}
}
\ No newline at end of file
communication/nfc_ErrorCode/signature/openharmony_sx.p7b
浏览文件 @
ff96c6dc
无法预览此类型文件
communication/nfc_SecureElement/BUILD.gn
0 → 100644
浏览文件 @
ff96c6dc
# Copyright (C) 2023 Huawei Device Co., Ltd.
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import("//test/xts/tools/build/suite.gni")
ohos_js_hap_suite("ActsnfcSEServiceTest") {
hap_profile = "./src/main/config.json"
deps = [
":nfc_js_assets",
":nfc_resources",
]
certificate_profile = "./signature/openharmony_sx.p7b"
hap_name = "ActsnfcSEServiceTest"
part_name = "nfc"
subsystem_name = "communication"
}
ohos_js_assets("nfc_js_assets") {
js2abc = true
hap_profile = "./src/main/config.json"
source_dir = "./src/main/js"
}
ohos_resources("nfc_resources") {
sources = [ "./src/main/resources" ]
hap_profile = "./src/main/config.json"
}
communication/nfc_SecureElement/Test.json
0 → 100644
浏览文件 @
ff96c6dc
{
"description"
:
"Configuration for nfc js api Tests"
,
"driver"
:
{
"type"
:
"OHJSUnitTest"
,
"test-timeout"
:
"600000"
,
"shell-timeout"
:
"600000"
,
"testcase-timeout"
:
"600000"
,
"bundle-name"
:
"ohos.acts.communication.nfc.nfcdevice"
,
"package-name"
:
"ohos.acts.communication.nfc.nfcdevice"
},
"kits"
:
[
{
"test-file-name"
:
[
"ActsnfcSEServiceTest.hap"
],
"type"
:
"AppInstallKit"
,
"cleanup-apps"
:
true
},
{
"type"
:
"ShellKit"
,
"run-command"
:
[
"svc nfc enable"
,
"power-shell wakeup"
,
"power-shell setmode 602"
]
}
]
}
\ No newline at end of file
communication/nfc_SecureElement/signature/openharmony_sx.p7b
0 → 100644
浏览文件 @
ff96c6dc
文件已添加
communication/nfc_SecureElement/src/main/config.json
0 → 100644
浏览文件 @
ff96c6dc
{
"app"
:
{
"bundleName"
:
"ohos.acts.communication.nfc.nfcdevice"
,
"vendor"
:
"acts"
,
"version"
:
{
"code"
:
1000000
,
"name"
:
"1.0.0"
},
"apiVersion"
:
{
"compatible"
:
4
,
"target"
:
5
}
},
"deviceConfig"
:
{},
"module"
:
{
"package"
:
"ohos.acts.communication.nfc.nfcdevice"
,
"name"
:
".entry"
,
"mainAbility"
:
".MainAbility"
,
"deviceType"
:
[
"tablet"
,
"default"
,
"phone"
],
"distro"
:
{
"deliveryWithInstall"
:
true
,
"moduleName"
:
"nfc_standard"
,
"moduleType"
:
"entry"
},
"abilities"
:
[
{
"skills"
:
[
{
"entities"
:
[
"entity.system.home"
],
"actions"
:
[
"action.system.home"
]
}
],
"orientation"
:
"unspecified"
,
"formsEnabled"
:
false
,
"name"
:
".MainAbility"
,
"srcLanguage"
:
"js"
,
"srcPath"
:
"MainAbility"
,
"icon"
:
"$media:icon"
,
"description"
:
"$string:MainAbility_desc"
,
"label"
:
"$string:MainAbility_label"
,
"type"
:
"page"
,
"visible"
:
true
,
"launchType"
:
"standard"
},
{
"orientation"
:
"unspecified"
,
"formsEnabled"
:
false
,
"name"
:
".TestAbility"
,
"srcLanguage"
:
"js"
,
"srcPath"
:
"TestAbility"
,
"icon"
:
"$media:icon"
,
"description"
:
"$string:TestAbility_desc"
,
"label"
:
"$string:TestAbility_label"
,
"type"
:
"page"
,
"visible"
:
true
,
"launchType"
:
"standard"
}
],
"js"
:
[
{
"pages"
:
[
"pages/index/index"
],
"name"
:
"default"
,
"window"
:
{
"designWidth"
:
720
,
"autoDesignWidth"
:
false
}
},
{
"pages"
:
[
"pages/index/index"
],
"name"
:
".TestAbility"
,
"window"
:
{
"designWidth"
:
720
,
"autoDesignWidth"
:
false
}
}
],
"reqPermissions"
:
[
{
"name"
:
"ohos.permission.NFC_CARD_EMULATION"
,
"reason"
:
"use ohos.permission.SET_nfc_INFO"
},
{
"name"
:
"ohos.permission.NFC_TAG"
,
"reason"
:
"use ohos.permission.NFC_TAG"
}
],
"testRunner"
:
{
"name"
:
"OpenHarmonyTestRunner"
,
"srcPath"
:
"TestRunner"
},
"srcPath"
:
""
}
}
communication/nfc_SecureElement/src/main/js/MainAbility/app.js
0 → 100644
浏览文件 @
ff96c6dc
/*
* Copyright (C) 2023 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
export
default
{
onCreate
()
{
console
.
info
(
'
AceApplication onCreate
'
);
},
onDestroy
()
{
console
.
info
(
'
AceApplication onDestroy
'
);
}
};
communication/nfc_SecureElement/src/main/js/MainAbility/i18n/en-US.json
0 → 100644
浏览文件 @
ff96c6dc
{
"strings"
:
{
"hello"
:
"Hello"
,
"world"
:
"World"
}
}
\ No newline at end of file
communication/nfc_SecureElement/src/main/js/MainAbility/i18n/zh-CN.json
0 → 100644
浏览文件 @
ff96c6dc
{
"strings"
:
{
"hello"
:
"您好"
,
"world"
:
"世界"
}
}
\ No newline at end of file
communication/nfc_SecureElement/src/main/js/MainAbility/pages/index/index.css
0 → 100644
浏览文件 @
ff96c6dc
/*
* Copyright (C) 2023 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
.container
{
flex-direction
:
column
;
justify-content
:
center
;
align-items
:
center
;
}
.title
{
font-size
:
100px
;
}
communication/nfc_SecureElement/src/main/js/MainAbility/pages/index/index.hml
0 → 100644
浏览文件 @
ff96c6dc
/*
* Copyright (C) 2023 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
<div class="container">
<text class="title">
{{ $t('strings.hello') }} {{ title }}
</text>
</div>
communication/nfc_SecureElement/src/main/js/MainAbility/pages/index/index.js
0 → 100644
浏览文件 @
ff96c6dc
/*
* Copyright (C) 2023 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
export
default
{
data
:
{
title
:
''
,
myTimeout
:
25000
},
onInit
()
{
this
.
title
=
this
.
$t
(
'
strings.world
'
);
},
onShow
()
{
console
.
info
(
'
onShow finish
'
)
},
onReady
()
{
console
.
info
(
'
onReady finish
'
)
},
}
communication/nfc_SecureElement/src/main/js/TestAbility/app.js
0 → 100644
浏览文件 @
ff96c6dc
/*
* Copyright (c) 2023 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import
AbilityDelegatorRegistry
from
'
@ohos.application.abilityDelegatorRegistry
'
import
{
Hypium
}
from
'
@ohos/hypium
'
import
testsuite
from
'
../test/List.test
'
export
default
{
onCreate
()
{
console
.
info
(
'
TestApplication onCreate
'
)
var
abilityDelegator
=
AbilityDelegatorRegistry
.
getAbilityDelegator
()
var
abilityDelegatorArguments
=
AbilityDelegatorRegistry
.
getArguments
()
console
.
info
(
'
start run testcase!!!
'
)
Hypium
.
hypiumTest
(
abilityDelegator
,
abilityDelegatorArguments
,
testsuite
)
},
onDestroy
()
{
console
.
info
(
"
TestApplication onDestroy
"
);
}
};
communication/nfc_SecureElement/src/main/js/TestAbility/i18n/en-US.json
0 → 100644
浏览文件 @
ff96c6dc
{
"strings"
:
{
"hello"
:
"Hello"
,
"world"
:
"World"
},
"Files"
:
{
}
}
\ No newline at end of file
communication/nfc_SecureElement/src/main/js/TestAbility/i18n/zh-CN.json
0 → 100644
浏览文件 @
ff96c6dc
{
"strings"
:
{
"hello"
:
"您好"
,
"world"
:
"世界"
},
"Files"
:
{
}
}
\ No newline at end of file
communication/nfc_SecureElement/src/main/js/TestAbility/pages/index/index.css
0 → 100644
浏览文件 @
ff96c6dc
.container
{
display
:
flex
;
flex-direction
:
column
;
justify-content
:
center
;
align-items
:
center
;
left
:
0px
;
top
:
0px
;
width
:
100%
;
height
:
100%
;
}
.title
{
font-size
:
60px
;
text-align
:
center
;
width
:
100%
;
height
:
40%
;
margin
:
10px
;
}
@media
screen
and
(
device-type
:
phone
)
and
(
orientation
:
landscape
)
{
.title
{
font-size
:
60px
;
}
}
@media
screen
and
(
device-type
:
tablet
)
and
(
orientation
:
landscape
)
{
.title
{
font-size
:
100px
;
}
}
\ No newline at end of file
communication/nfc_SecureElement/src/main/js/TestAbility/pages/index/index.hml
0 → 100644
浏览文件 @
ff96c6dc
<div class="container">
<text class="title">
{{ $t('strings.hello') }} {{ title }}
</text>
</div>
communication/nfc_SecureElement/src/main/js/TestAbility/pages/index/index.js
0 → 100644
浏览文件 @
ff96c6dc
/*
* Copyright (c) 2023 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
export
default
{
data
:
{
title
:
""
},
onInit
()
{
this
.
title
=
this
.
$t
(
'
strings.world
'
);
}
}
communication/nfc_SecureElement/src/main/js/TestRunner/OpenHarmonyTestRunner.js
0 → 100644
浏览文件 @
ff96c6dc
/*
* Copyright (c) 2023 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import
AbilityDelegatorRegistry
from
'
@ohos.application.abilityDelegatorRegistry
'
function
translateParamsToString
(
parameters
)
{
const
keySet
=
new
Set
([
'
-s class
'
,
'
-s notClass
'
,
'
-s suite
'
,
'
-s itName
'
,
'
-s level
'
,
'
-s testType
'
,
'
-s size
'
,
'
-s timeout
'
,
'
-s package
'
,
'
-s dryRun
'
])
let
targetParams
=
''
;
for
(
const
key
in
parameters
)
{
if
(
keySet
.
has
(
key
))
{
targetParams
+=
'
'
+
key
+
'
'
+
parameters
[
key
]
}
}
return
targetParams
.
trim
()
}
export
default
{
onPrepare
()
{
console
.
info
(
'
OpenHarmonyTestRunner OnPrepare
'
)
},
onRun
()
{
console
.
info
(
'
OpenHarmonyTestRunner onRun run
'
)
var
abilityDelegatorArguments
=
AbilityDelegatorRegistry
.
getArguments
()
var
abilityDelegator
=
AbilityDelegatorRegistry
.
getAbilityDelegator
()
var
testAbilityName
=
abilityDelegatorArguments
.
parameters
[
'
-p
'
]
+
'
.TestAbility
'
var
cmd
=
'
aa start -d 0 -a
'
+
testAbilityName
+
'
-b
'
+
abilityDelegatorArguments
.
bundleName
cmd
+=
'
'
+
translateParamsToString
(
abilityDelegatorArguments
.
parameters
)
var
debug
=
abilityDelegatorArguments
.
parameters
[
"
-D
"
]
console
.
info
(
'
debug value :
'
+
debug
)
if
(
debug
==
'
true
'
)
{
cmd
+=
'
-D
'
}
console
.
info
(
'
cmd :
'
+
cmd
)
abilityDelegator
.
executeShellCommand
(
cmd
,
(
err
,
data
)
=>
{
console
.
info
(
'
executeShellCommand : err :
'
+
JSON
.
stringify
(
err
));
console
.
info
(
'
executeShellCommand : data :
'
+
data
.
stdResult
);
console
.
info
(
'
executeShellCommand : data :
'
+
data
.
exitCode
);
})
}
};
communication/nfc_SecureElement/src/main/js/test/List.test.js
0 → 100644
浏览文件 @
ff96c6dc
/*
* Copyright (C) 2023 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import
newSEServicetest
from
'
./newSEService.test.js
'
;
import
openSessionTest
from
'
./openSession.test.js
'
;
import
openBasicChanneltest
from
'
./openBasicChannel.test.js
'
;
import
openLogicalChanneltest
from
'
./openLogicalChannel.test.js
'
;
import
channelCallbacktest
from
'
./channelCallback.test.js
'
;
import
parameter
from
'
@ohos.systemparameter
'
;
let
info
=
parameter
.
getSync
(
"
const.SystemCapability.Communication.NFC.Core
"
,
"
false
"
);
export
default
function
testsuite
()
{
if
(
info
!=
"
false
"
)
{
newSEServicetest
();
openSessionTest
();
openBasicChanneltest
();
openLogicalChanneltest
();
channelCallbacktest
();
}
}
\ No newline at end of file
communication/nfc_SecureElement/src/main/js/test/channelCallback.test.js
0 → 100644
浏览文件 @
ff96c6dc
/*
* Copyright (C) 2023 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import
secureElement
from
'
@ohos.secureElement
'
;
import
{
describe
,
beforeAll
,
beforeEach
,
afterEach
,
afterAll
,
it
,
expect
}
from
'
@ohos/hypium
'
;
function
sleep
(
delay
)
{
// delay x ms
let
start
=
(
new
Date
()).
getTime
();
while
((
new
Date
()).
getTime
()
-
start
<
delay
)
{
continue
;
}
}
let
nfcSEService
=
null
;
let
nfcESEReader
=
null
;
let
nfcOmaSession
=
null
;
let
nfcOmaReaderList
=
[];
let
aidArray
=
[
160
,
0
,
0
,
1
,
81
,
0
,
0
,
0
];
let
p2
=
0x00
;
let
command
=
[
128
,
202
,
159
,
127
,
0
];
export
default
function
channelCallbacktest
()
{
describe
(
'
channelCallbacktest
'
,
function
()
{
beforeAll
(
function
()
{
try
{
nfcSEService
=
secureElement
.
newSEService
(
"
serviceState
"
,
(
state
)
=>
{
if
(
state
==
secureElement
.
ServiceState
.
DISCONNECTED
)
{
console
.
info
(
"
[nfc_test] beforeAll Se_channel state is Disconnected
"
);
}
else
{
console
.
info
(
"
[nfc_test] beforeAll Se_channel state is Connected
"
);
}
expect
(
state
instanceof
Object
).
assertTrue
();
console
.
info
(
"
[nfc_test] beforeAll Se_channel state is getReaders
"
+
state
);
});
sleep
(
1000
);
nfcOmaReaderList
=
nfcSEService
.
getReaders
();
if
(
nfcOmaReaderList
.
length
===
0
)
{
console
.
info
(
"
[NFC_test]This function is not supported because the phone NFC chip is ST chip.
"
);
}
else
{
console
.
info
(
"
[nfc_test] beforeAll Se_channel Result of getReaders:
"
+
nfcOmaReaderList
.
length
);
nfcESEReader
=
nfcOmaReaderList
[
0
];
console
.
info
(
"
[nfc_test] beforeAll Se_channel getReaders results list 0 is
"
+
nfcESEReader
);
nfcOmaSession
=
nfcESEReader
.
openSession
();
console
.
info
(
"
[nfc_test] beforeAll Se_channel openSession The result is
"
+
nfcOmaSession
);
}
}
catch
(
e
)
{
console
.
info
(
"
[nfc_test] beforeAll Se_channel occurs exception:
"
+
e
.
message
);
}
})
beforeEach
(
function
()
{
console
.
info
(
'
beforeEach called
'
);
})
afterEach
(
function
()
{
console
.
info
(
'
shutdown success
'
);
})
afterAll
(
function
()
{
nfcSEService
.
shutdown
();
sleep
(
5000
);
console
.
info
(
'
[nfc_test] afterAll channelcallback shutdown success
'
);
})
/**
* @tc.number SUB_Communication_Ese_LogicalChannel_js_2400
* @tc.name Test isBasicChannel
* @tc.desc open BasicChannel Check whether the channel is a basic channel.
* @tc.type Function
* @tc.level Level 2
*/
it
(
'
SUB_Communication_Ese_LogicalChannel_js_2400
'
,
0
,
async
function
(
done
)
{
try
{
if
(
nfcOmaReaderList
==
undefined
)
{
console
.
info
(
"
[NFC_test]24 This function is not supported because the phone NFC chip is ST chip.
"
);
}
else
{
function
P2BasicChannel_callback
(){
return
new
Promise
((
resolve
,
reject
)
=>
{
nfcOmaSession
.
openBasicChannel
(
aidArray
,
p2
,
(
err
,
result
)
=>
{
if
(
err
)
{
console
.
info
(
"
[NFC_test]24 openBasicChannel data == null
"
+
err
);
expect
().
assertFail
();
}
console
.
info
(
"
[NFC_test]24 openBasicChannel data != null
"
+
result
);
let
P2BasicChannel
=
result
;
let
isBasic
=
P2BasicChannel
.
isBasicChannel
();
console
.
info
(
"
[NFC_test]24 Check whether the channel is a basic channel:
"
+
isBasic
);
expect
(
isBasic
).
assertTrue
();
P2BasicChannel
.
close
();
console
.
info
(
"
[NFC_test]24 Data received by the application select command:
"
);
resolve
();
});
});
}
await
P2BasicChannel_callback
();
}
}
catch
(
error
)
{
console
.
info
(
"
[NFC_test]24 openBasicChannel_p2_callback occurs exception:
"
+
error
);
expect
().
assertFail
();
}
sleep
(
3000
);
done
();
})
/**
* @tc.number SUB_Communication_Ese_LogicalChannel_js_2500
* @tc.name Test isClosed
* @tc.desc open LogicalChannel Check whether the channel is closed.
* @tc.type Function
* @tc.level Level 2
*/
it
(
'
SUB_Communication_Ese_LogicalChannel_js_2500
'
,
0
,
async
function
(
done
)
{
try
{
if
(
nfcOmaReaderList
==
undefined
)
{
console
.
info
(
"
[NFC_test]25 This function is not supported because the phone NFC chip is ST chip.
"
);
}
else
{
function
LogicalChannel_callback
(){
return
new
Promise
((
resolve
,
reject
)
=>
{
nfcOmaSession
.
openLogicalChannel
(
aidArray
,
p2
,
(
err
,
result
)
=>
{
if
(
err
)
{
console
.
info
(
"
[NFC_test]25 openLogicalChannel data == null
"
+
err
);
expect
().
assertFail
();
}
console
.
info
(
"
[NFC_test]25 openLogicalChannel data == null
"
+
result
);
let
P2LogicalChannel
=
result
;
P2LogicalChannel
.
close
();
console
.
info
(
"
[NFC_test]25 Data received by the application select command:
"
);
let
isChannelClosed
=
P2LogicalChannel
.
isClosed
();
console
.
info
(
"
[NFC_test]25 Check whether the channel is closed:
"
+
isChannelClosed
);
expect
(
isChannelClosed
).
assertTrue
();
resolve
();
});
});
}
await
LogicalChannel_callback
();
}
}
catch
(
error
)
{
console
.
info
(
"
[NFC_test]25 openLogicalChannel_P2_callback occurs exception:
"
+
error
);
expect
().
assertFail
();
}
sleep
(
3000
);
done
();
})
/**
* @tc.number SUB_Communication_Ese_LogicalChannel_js_2600
* @tc.name Test getSelectResponse
* @tc.desc open BasicChannel Returns the data received from the application selection command.
* @tc.type Function
* @tc.level Level 2
*/
it
(
'
SUB_Communication_Ese_LogicalChannel_js_2600
'
,
0
,
async
function
(
done
)
{
try
{
if
(
nfcOmaReaderList
==
undefined
)
{
console
.
info
(
"
[NFC_test]26 This function is not supported because the phone NFC chip is ST chip.
"
);
}
else
{
function
BasicChannel_callback
(){
return
new
Promise
((
resolve
,
reject
)
=>
{
nfcOmaSession
.
openBasicChannel
(
aidArray
,
(
err
,
result
)
=>
{
if
(
err
)
{
console
.
info
(
"
[NFC_test]26 to get openBasicChannel:
"
+
JSON
.
stringify
(
err
));
expect
().
assertFail
();
}
console
.
info
(
"
[NFC_test]26 openBasicChannel data != null
"
+
result
);
let
nfcBasicChannel
=
result
;
let
getResponse
=
nfcBasicChannel
.
getSelectResponse
();
console
.
info
(
"
[NFC_test]26 getSelectResponse data:
"
+
getResponse
);
nfcBasicChannel
.
close
();
console
.
info
(
"
[NFC_test]26 Data received by the application select command:
"
);
expect
(
getResponse
).
assertInstanceOf
(
'
Array
'
);
resolve
();
});
});
}
await
BasicChannel_callback
();
}
}
catch
(
error
)
{
console
.
info
(
"
[NFC_test]26 openBasicChannel_callback occurs exception:
"
+
error
);
expect
().
assertFail
();
}
sleep
(
5000
);
done
();
})
/**
* @tc.number SUB_Communication_Ese_LogicalChannel_js_2700
* @tc.name Test transmit
* @tc.desc open LogicalChannel Send an APDU command to the SE
* @tc.type Function
* @tc.level Level 2
*/
it
(
'
SUB_Communication_Ese_LogicalChannel_js_2700
'
,
0
,
async
function
(
done
)
{
try
{
if
(
nfcOmaReaderList
==
undefined
)
{
console
.
info
(
"
[NFC_test]27 This function is not supported because the phone NFC chip is ST chip.
"
);
}
else
{
function
LogicalChannel_callback
(){
return
new
Promise
((
resolve
,
reject
)
=>
{
nfcOmaSession
.
openLogicalChannel
(
aidArray
,
(
err
,
result
)
=>
{
if
(
err
)
{
console
.
info
(
"
[NFC_test]27 failed to get openLogicalChannel:
"
+
JSON
.
stringify
(
err
));
expect
().
assertFail
();
}
console
.
info
(
"
[NFC_test]27 openLogicalChannel data != null
"
+
result
);
let
nfcLogicalChannel
=
result
;
nfcLogicalChannel
.
transmit
(
command
,
(
err
,
data
)
=>
{
if
(
err
)
{
console
.
info
(
"
[NFC_test]27 Send error an APDU command to the SE:
"
+
err
);
expect
().
assertFail
();
}
else
{
console
.
info
(
"
[NFC_test]27 Send an APDU command to the SE:
"
+
data
);
expect
(
data
).
assertInstanceOf
(
'
Array
'
);
}
});
sleep
(
5000
);
nfcLogicalChannel
.
close
();
console
.
info
(
"
[NFC_test]27 Data received by the application select command:
"
);
resolve
();
});
});
}
await
LogicalChannel_callback
();
}
}
catch
(
error
)
{
console
.
info
(
"
[NFC_test]27 openLogicalChannel_callback occurs exception:
"
+
error
);
expect
().
assertFail
();
}
sleep
(
3000
);
done
();
})
/**
* @tc.number SUB_Communication_Ese_LogicalChannel_js_2800
* @tc.name Test transmit
* @tc.desc open LogicalChannel Send an APDU command to the SE
* @tc.type Function
* @tc.level Level 2
*/
it
(
'
SUB_Communication_Ese_LogicalChannel_js_2800
'
,
0
,
async
function
(
done
)
{
try
{
if
(
nfcOmaReaderList
==
undefined
)
{
console
.
info
(
"
[NFC_test]28 This function is not supported because the phone NFC chip is ST chip.
"
);
}
else
{
let
getPromise
=
nfcOmaSession
.
openBasicChannel
(
aidArray
);
await
getPromise
.
then
((
data
)
=>
{
console
.
info
(
"
[NFC_test]28 openBasicChannel openBasicChannel data:
"
+
data
);
if
(
data
!=
undefined
&&
data
!=
null
){
console
.
info
(
"
[NFC_test]28 openBasicChannel data != null
"
);
let
OmaBasicChannel
=
data
;
OmaBasicChannel
.
close
();
console
.
info
(
"
[NFC_test]28 Data received by the application select command:
"
);
}
else
{
console
.
info
(
"
[NFC_test]28 openBasicChannel data == null
"
);
}
}).
catch
((
error
)
=>
{
console
.
info
(
"
[NFC_test]28 openBasicChannel catch error
"
+
error
);
expect
().
assertFail
();
});
sleep
(
5000
);
}
}
catch
(
error
)
{
console
.
info
(
"
[NFC_test]28 openBasicChannel_Promise occurs exception:
"
+
error
);
expect
().
assertFail
();
}
done
();
})
/**
* @tc.number SUB_Communication_Ese_LogicalChannel_js_2900
* @tc.name Test isClosed
* @tc.desc Check whether the channel is closed.
* @tc.type Function
* @tc.level Level 2
*/
it
(
'
SUB_Communication_Ese_LogicalChannel_js_2900
'
,
0
,
async
function
(
done
)
{
try
{
if
(
nfcOmaReaderList
==
undefined
)
{
console
.
info
(
"
[NFC_test]29 This function is not supported because the phone NFC chip is ST chip.
"
);
}
else
{
let
getPromise
=
nfcOmaSession
.
openLogicalChannel
(
aidArray
);
await
getPromise
.
then
((
data
)
=>
{
console
.
info
(
"
[NFC_test]29 openLogicalChannel data:
"
+
data
);
if
(
data
!=
undefined
&&
data
!=
null
){
console
.
info
(
"
[NFC_test]29 openLogicalChannel data != null
"
);
let
OmaLogicalChannel
=
data
;
let
isChannelClosed
=
OmaLogicalChannel
.
isClosed
();
console
.
info
(
"
[NFC_test]29 Check whether the channel is disabled:
"
+
isChannelClosed
);
expect
(
isChannelClosed
).
assertFalse
();
}
else
{
console
.
info
(
"
[NFC_test]29 openLogicalChannel data == null
"
);
}
}).
catch
((
error
)
=>
{
console
.
info
(
"
[NFC_test]29 openLogicalChannel catch error
"
+
error
);
expect
().
assertFail
();
});
sleep
(
5000
);
}
}
catch
(
error
)
{
console
.
info
(
"
[NFC_test]29 openLogicalChannel_Promise occurs exception:
"
+
error
);
expect
().
assertFail
();
}
done
();
})
console
.
info
(
"
*************[nfc_test] start nfc js unit test end*************
"
);
})
}
\ No newline at end of file
communication/nfc_SecureElement/src/main/js/test/newSEService.test.js
0 → 100644
浏览文件 @
ff96c6dc
/*
* Copyright (C) 2023 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import
secureElement
from
'
@ohos.secureElement
'
;
import
{
describe
,
beforeAll
,
beforeEach
,
afterEach
,
afterAll
,
it
,
expect
}
from
'
@ohos/hypium
'
;
function
sleep
(
delay
)
{
// delay x ms
let
start
=
(
new
Date
()).
getTime
();
while
((
new
Date
()).
getTime
()
-
start
<
delay
)
{
continue
;
}
}
let
nfcSEService
=
null
;
export
default
function
newSEServicetest
()
{
describe
(
'
newSEServicetest
'
,
function
()
{
beforeAll
(
function
()
{
try
{
nfcSEService
=
secureElement
.
newSEService
(
"
serviceState
"
,
(
state
)
=>
{
if
(
state
==
secureElement
.
ServiceState
.
DISCONNECTED
)
{
console
.
info
(
"
[nfc_test] beforeAll newService state is Disconnected
"
);
}
else
{
console
.
info
(
"
[nfc_test] beforeAll newService state is Connected
"
);
}
expect
(
state
instanceof
Object
).
assertTrue
();
console
.
info
(
"
[nfc_test] beforeAll newService state is
"
+
state
);
});
sleep
(
1000
);
}
catch
(
e
)
{
console
.
info
(
"
[nfc_test] beforeAll newService occurs exception:
"
+
e
.
message
);
}
})
beforeEach
(
function
()
{
console
.
info
(
'
beforeEach called
'
);
})
afterEach
(
function
()
{
console
.
info
(
'
afterEach called
'
);
})
afterAll
(
function
()
{
nfcSEService
.
shutdown
();
sleep
(
5000
);
console
.
info
(
'
[nfc_test] afterAll newService shutdown success
'
);
})
/**
* @tc.number SUB_Communication_NFC_secureElement_js_0100
* @tc.name Test isConnected
* @tc.desc Check whether the SE service is connected.
* @tc.type Function
* @tc.level Level 2
*/
it
(
'
SUB_Communication_NFC_secureElement_js_0100
'
,
0
,
function
()
{
try
{
let
nfcisConnected
=
nfcSEService
.
isConnected
();
console
.
info
(
"
[NFC_test]1 SEService The connection status is:
"
+
nfcisConnected
);
expect
(
nfcisConnected
).
assertTrue
();
}
catch
(
error
)
{
console
.
info
(
"
[NFC_test]1 exception occurred when checking the connection status.:
"
+
error
)
expect
().
assertFail
();
}
})
/**
* @tc.number SUB_Communication_NFC_secureElement_js_0200
* @tc.name Test getVersion
* @tc.desc Returns the version number of the OMA specification.
* @tc.type Function
* @tc.level Level 2
*/
it
(
'
SUB_Communication_NFC_secureElement_js_0200
'
,
0
,
function
()
{
try
{
let
getSEVersion
=
nfcSEService
.
getVersion
();
console
.
info
(
"
[NFC_test]2 OMA The version number is:
"
+
getSEVersion
);
expect
(
typeof
(
getSEVersion
)).
assertEqual
(
'
string
'
);
}
catch
(
error
)
{
console
.
info
(
"
[NFC_test]2 Failed to obtain the version.:
"
+
error
);
expect
().
assertFail
();
}
})
/**
* @tc.number SUB_Communication_NFC_secureElement_js_0300
* @tc.name Test getName
* @tc.desc Returns the name of this reader.
* @tc.type Function
* @tc.level Level 2
*/
it
(
'
SUB_Communication_NFC_secureElement_js_0300
'
,
0
,
function
()
{
try
{
let
nfcOmaReaderList
=
nfcSEService
.
getReaders
();
console
.
info
(
"
[nfc_test]3 Result of getReaders:
"
+
nfcOmaReaderList
);
if
(
nfcOmaReaderList
==
undefined
)
{
console
.
info
(
"
[NFC_test]3 This function is not supported because the phone NFC chip is ST chip.
"
);
}
else
{
expect
(
nfcOmaReaderList
instanceof
Object
).
assertTrue
();
let
nfcESEReader
=
nfcOmaReaderList
[
0
];
console
.
info
(
"
[nfc_test]3 getReaders results list 0 is
"
+
nfcESEReader
);
expect
(
nfcESEReader
instanceof
Object
).
assertTrue
();
let
getNfcname
=
nfcESEReader
.
getName
();
console
.
info
(
"
[NFC_test]3 The reader name is:
"
+
getNfcname
);
expect
(
typeof
(
getNfcname
)).
assertEqual
(
'
string
'
);
}
}
catch
(
error
)
{
console
.
info
(
"
[NFC_test]3 getName occurs exception:
"
+
error
);
expect
().
assertFail
();
}
})
/**
* @tc.number SUB_Communication_NFC_secureElement_js_0400
* @tc.name Test isSecureElementPresent
* @tc.desc Indicates whether the corresponding secure element is available.
* @tc.type Function
* @tc.level Level 2
*/
it
(
'
SUB_Communication_NFC_secureElement_js_0400
'
,
0
,
function
()
{
try
{
let
nfcOmaReaderList2
=
[];
nfcOmaReaderList2
=
nfcSEService
.
getReaders
();
if
(
nfcOmaReaderList2
==
undefined
)
{
console
.
info
(
"
[NFC_test]4 This function is not supported because the phone NFC chip is ST chip.
"
);
}
else
{
console
.
info
(
"
[nfc_test]4 Result of getReaders:
"
+
nfcOmaReaderList2
);
expect
(
nfcOmaReaderList2
instanceof
Object
).
assertTrue
();
let
nfcESEReader2
=
nfcOmaReaderList2
[
0
];
console
.
info
(
"
[nfc_test]4 getReaders results list 0 is
"
+
nfcESEReader2
);
expect
(
nfcESEReader2
instanceof
Object
).
assertTrue
();
let
nfcSePresent
=
nfcESEReader2
.
isSecureElementPresent
();
console
.
info
(
"
[NFC_test]4 security unit check result is:
"
+
nfcSePresent
);
expect
(
nfcSePresent
).
assertTrue
();
let
nfcOmaSession2
=
nfcESEReader2
.
openSession
();
sleep
(
3000
)
console
.
info
(
"
[nfc_test]4 Open the second session result
"
+
nfcOmaSession2
);
expect
(
nfcOmaSession2
instanceof
Object
).
assertTrue
();
let
openSession2
=
nfcOmaSession2
.
isClosed
();
console
.
info
(
"
[NFC_test]4 After close Check the second session is open:
"
+
openSession2
);
expect
(
openSession2
).
assertFalse
();
nfcESEReader2
.
closeSessions
();
sleep
(
3000
)
console
.
info
(
"
[NFC_test]4 close the Reader of SE successfully
"
);
let
closeSession2
=
nfcOmaSession2
.
isClosed
();
console
.
info
(
"
[NFC_test]4 After close Check the second session is open:
"
+
closeSession2
);
expect
(
closeSession2
).
assertTrue
();
}
}
catch
(
error
)
{
console
.
info
(
"
[NFC_test]4 isSecureElementPresent occurs exception:
"
+
error
);
expect
().
assertFail
();
}
})
/**
* @tc.number SUB_Communication_NFC_secureElement_js_0500
* @tc.name Test shutdown
* @tc.desc Release all SE resources allocated to the service.
* @tc.type Function
* @tc.level Level 2
*/
it
(
'
SUB_Communication_NFC_secureElement_js_0500
'
,
0
,
function
()
{
try
{
nfcSEService
.
shutdown
();
console
.
info
(
'
[NFC_test] 05 eseshutdown pass
'
);
let
downESEisconnected
=
nfcSEService
.
isConnected
();
console
.
info
(
"
[NFC_test]5 shutdown the SE SEService The connection status is:
"
+
downESEisconnected
);
expect
(
downESEisconnected
).
assertFalse
();
sleep
(
5000
);
let
SEService
=
secureElement
.
newSEService
(
"
serviceState
"
,
(
state
)
=>
{
if
(
state
==
secureElement
.
ServiceState
.
DISCONNECTED
)
{
console
.
info
(
"
[nfc_test]5 Service state is Disconnected
"
);
}
else
{
console
.
info
(
"
[nfc_test]5 Service state is Connected
"
);
}
console
.
info
(
"
[nfc_test]5 Service state is
"
+
state
);
});
sleep
(
1000
);
expect
(
SEService
instanceof
Object
).
assertTrue
();
let
openESEisconnected
=
SEService
.
isConnected
();
console
.
info
(
"
[NFC_test]5 SEService The connection status is::
"
+
openESEisconnected
);
expect
(
openESEisconnected
).
assertTrue
();
let
nfcReadersList
=
SEService
.
getReaders
();
if
(
nfcReadersList
==
undefined
)
{
console
.
info
(
"
[NFC_test]5 This function is not supported because the phone NFC chip is ST chip.
"
);
}
else
{
expect
(
nfcReadersList
instanceof
Object
).
assertTrue
();
console
.
info
(
"
[nfc_test]5 Result of getReaders:
"
+
nfcReadersList
);
}
}
catch
(
error
)
{
console
.
info
(
"
[NFC_test]5 getReaders occurs exception:
"
+
error
);
expect
().
assertFail
();
}
})
console
.
info
(
"
*************[nfc_test] start nfc js unit test end*************
"
);
})
}
\ No newline at end of file
communication/nfc_SecureElement/src/main/js/test/openBasicChannel.test.js
0 → 100644
浏览文件 @
ff96c6dc
/*
* Copyright (C) 2023 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import
secureElement
from
'
@ohos.secureElement
'
;
import
{
describe
,
beforeAll
,
beforeEach
,
afterEach
,
afterAll
,
it
,
expect
}
from
'
@ohos/hypium
'
;
function
sleep
(
delay
)
{
// delay x ms
let
start
=
(
new
Date
()).
getTime
();
while
((
new
Date
()).
getTime
()
-
start
<
delay
)
{
continue
;
}
}
let
nfcSEService
=
null
;
let
nfcESEReader
=
null
;
let
nfcOmaSession
=
null
;
let
nfcOmaChannel
=
null
;
let
nfcOmaReaderList
=
[];
let
aidArray
=
[
160
,
0
,
0
,
1
,
81
,
0
,
0
,
0
];
let
p2
=
0x00
;
let
command
=
[
128
,
202
,
159
,
127
,
0
];
export
default
function
openBasicChanneltest
()
{
describe
(
'
openBasicChanneltest
'
,
function
()
{
beforeAll
(
async
function
(
done
)
{
try
{
nfcSEService
=
secureElement
.
newSEService
(
"
serviceState
"
,
(
state
)
=>
{
if
(
state
==
secureElement
.
ServiceState
.
DISCONNECTED
)
{
console
.
info
(
"
[NFC_test] beforeAll se_basic Opened successfully
"
);
}
else
{
console
.
info
(
"
[NFC_test] beforeAll se_basic Failed to open
"
);
}
expect
(
state
instanceof
Object
).
assertTrue
();
});
sleep
(
1000
);
nfcOmaReaderList
=
nfcSEService
.
getReaders
();
if
(
nfcOmaReaderList
==
undefined
)
{
console
.
info
(
"
[NFC_test]This function is not supported because the phone NFC chip is ST chip.
"
);
}
else
{
console
.
info
(
"
[nfc_test] beforeAll se_basic Result of getReaders:
"
+
nfcOmaReaderList
.
length
);
nfcESEReader
=
nfcOmaReaderList
[
0
];
console
.
info
(
"
[nfc_test] beforeAll se_basic getReaders results list 0 is
"
+
nfcESEReader
);
nfcOmaSession
=
nfcESEReader
.
openSession
();
console
.
info
(
"
[nfc_test] beforeAll se_basic openSession The result is
"
+
nfcOmaSession
);
let
getPromise
=
nfcOmaSession
.
openBasicChannel
(
aidArray
,
p2
);
await
getPromise
.
then
((
data
)
=>
{
console
.
info
(
"
[NFC_test] beforeAll se_basic openBasicChannel data:
"
+
data
);
return
nfcOmaChannel
=
data
;
}).
catch
((
error
)
=>
{
console
.
info
(
"
[NFC_test] beforeAll se_basic openBasicChannel catch error:
"
+
error
);
expect
().
assertFail
();
});
sleep
(
5000
);
}
}
catch
(
e
)
{
console
.
info
(
"
[NFC_test] beforeAll se_basic occurs exception:
"
+
e
.
message
);
expect
().
assertFail
();
}
done
();
console
.
info
(
'
beforeAll called
'
);
})
beforeEach
(
function
()
{
console
.
info
(
'
beforeEach called
'
);
})
afterEach
(
function
()
{
console
.
info
(
'
afterEach called
'
);
})
afterAll
(
function
()
{
nfcSEService
.
shutdown
();
sleep
(
5000
);
console
.
info
(
'
shutdown success
'
);
})
/**
* @tc.number SUB_Communication_Ese_BasicChannel_js_1000
* @tc.name Test isBasicChannel
* @tc.desc Check whether the channel is a basic channel.
* @tc.type Function
* @tc.level Level 2
*/
it
(
'
SUB_Communication_Ese_BasicChannel_js_1000
'
,
0
,
function
()
{
try
{
if
(
nfcOmaReaderList
==
undefined
)
{
console
.
log
(
"
[NFC_test]10 This function is not supported because the phone NFC chip is ST chip.
"
);
}
else
{
let
isBasic
=
nfcOmaChannel
.
isBasicChannel
();
console
.
info
(
"
[NFC_test]10 Check whether the channel is a basic channel:
"
+
isBasic
);
expect
(
isBasic
).
assertTrue
();
}
}
catch
(
error
)
{
console
.
info
(
"
[NFC_test]10 isBasicChannel occurs exception:
"
+
error
);
expect
().
assertFail
();
}
})
/**
* @tc.number SUB_Communication_Ese_BasicChannel_js_1100
* @tc.name Test isClosed
* @tc.desc Check whether the channel is closed.
* @tc.type Function
* @tc.level Level 2
*/
it
(
'
SUB_Communication_Ese_BasicChannel_js_1100
'
,
0
,
function
()
{
try
{
if
(
nfcOmaReaderList
==
undefined
)
{
console
.
log
(
"
[NFC_test]11 This function is not supported because the phone NFC chip is ST chip.
"
);;
}
else
{
let
isChannelClosed
=
nfcOmaChannel
.
isClosed
();
console
.
info
(
"
[NFC_test]11 Check whether the channel is closed:
"
+
isChannelClosed
);
expect
(
isChannelClosed
).
assertFalse
();
}
}
catch
(
error
)
{
console
.
info
(
"
[NFC_test]11 isClosed occurs exception:
"
+
error
);
expect
().
assertFail
();
}
})
/**
* @tc.number SUB_Communication_Ese_BasicChannel_js_1200
* @tc.name Test getSelectResponse
* @tc.desc Returns the data received from the application selection command.
* @tc.type Function
* @tc.level Level 2
*/
it
(
'
SUB_Communication_Ese_BasicChannel_js_1200
'
,
0
,
function
()
{
try
{
if
(
nfcOmaReaderList
==
undefined
)
{
console
.
log
(
"
[NFC_test]12 This function is not supported because the phone NFC chip is ST chip.
"
);
}
else
{
let
getResponse
=
nfcOmaChannel
.
getSelectResponse
();
console
.
info
(
"
[NFC_test]12 Data received by the application select command:
"
+
getResponse
);
expect
(
getResponse
).
assertInstanceOf
(
'
Array
'
);
}
}
catch
(
error
)
{
console
.
info
(
"
[NFC_test]12 getSelectResponse occurs exception:
"
+
error
);
expect
().
assertFail
();
}
})
/**
* @tc.number SUB_Communication_Ese_BasicChannel_js_1300
* @tc.name Test transmit
* @tc.desc Send an APDU command to the SE
* @tc.type Function
* @tc.level Level 2
*/
it
(
'
SUB_Communication_Ese_BasicChannel_js_1300
'
,
0
,
async
function
(
done
)
{
try
{
if
(
nfcOmaReaderList
==
undefined
)
{
console
.
log
(
"
[NFC_test]13 This function is not supported because the phone NFC chip is ST chip.
"
);
}
else
{
nfcOmaChannel
.
transmit
(
command
,
(
err
,
data
)
=>
{
if
(
err
)
{
console
.
info
(
"
[NFC_test]13 Send error an APDU command to the SE:
"
+
err
);
expect
().
assertFail
();
}
else
{
console
.
info
(
"
[NFC_test]13 Send an APDU command to the SE:
"
+
data
);
expect
(
data
).
assertInstanceOf
(
'
Array
'
)
}
});
}
}
catch
(
error
)
{
console
.
info
(
"
[NFC_test]13 exception when sending the APDU command to the SE:
"
+
error
);
expect
().
assertFail
();
}
sleep
(
5000
);
done
();
})
/**
* @tc.number SUB_Communication_Ese_BasicChannel_js_1400
* @tc.name Test transmit
* @tc.desc Send an APDU command to the SE
* @tc.type Function
* @tc.level Level 2
*/
it
(
'
SUB_Communication_Ese_BasicChannel_js_1400
'
,
0
,
async
function
(
done
)
{
try
{
if
(
nfcOmaReaderList
==
undefined
)
{
console
.
log
(
"
[NFC_test]14 This function is not supported because the phone NFC chip is ST chip.
"
);
}
else
{
let
getPromise
=
nfcOmaChannel
.
transmit
(
command
);
await
getPromise
.
then
((
data
)
=>
{
console
.
info
(
"
[NFC_test]14 Send an APDU command to the SE:
"
+
data
);
expect
(
data
).
assertInstanceOf
(
'
Array
'
);
}).
catch
((
err
)
=>
{
console
.
info
(
"
[NFC_test]14 Send error an APDU command to the SE::
"
+
err
);
expect
().
assertFail
();
});
}
}
catch
(
error
)
{
console
.
info
(
"
[NFC_test]14 exception when sending the APDU command to the SE:
"
+
error
);
expect
().
assertFail
();
}
done
();
})
/**
* @tc.number SUB_Communication_Ese_BasicChannel_js_1500
* @tc.name Test close
* @tc.desc Obtains the session object that opens the channel.
* @tc.type Function
* @tc.level Level 2
*/
it
(
'
SUB_Communication_Ese_BasicChannel_js_1500
'
,
0
,
function
()
{
try
{
if
(
nfcOmaReaderList
==
undefined
)
{
console
.
log
(
"
[NFC_test]15 This function is not supported because the phone NFC chip is ST chip.
"
);
}
else
{
let
getchannelSession
=
nfcOmaChannel
.
getSession
();
expect
(
getchannelSession
instanceof
Object
).
assertTrue
();
console
.
info
(
"
[NFC_test] 15 getSession data:
"
+
getchannelSession
);
}
}
catch
(
error
)
{
console
.
info
(
"
[NFC_test]15 getSession occurs exception:
"
+
error
);
expect
().
assertFail
();
}
})
/**
* @tc.number SUB_Communication_Ese_BasicChannel_js_1600
* @tc.name Test close
* @tc.desc Close the channel with the SE.
* @tc.type Function
* @tc.level Level 2
*/
it
(
'
SUB_Communication_Ese_BasicChannel_js_1600
'
,
0
,
function
()
{
try
{
if
(
nfcOmaReaderList
==
undefined
)
{
console
.
log
(
"
[NFC_test]16 This function is not supported because the phone NFC chip is ST chip.
"
);
}
else
{
nfcOmaChannel
.
close
();
console
.
info
(
"
[NFC_test] 1600 The closeChannel test is successfully
"
);
let
isChannelClosed
=
nfcOmaChannel
.
isClosed
();
console
.
info
(
"
[NFC_test]16 Check whether the channel is disabled:
"
+
isChannelClosed
);
expect
(
isChannelClosed
).
assertTrue
();
}
}
catch
(
error
)
{
console
.
info
(
"
[NFC_test]16 close and isclosed occurs exception:
"
+
error
);
expect
().
assertFail
();
}
})
console
.
info
(
"
*************[nfc_test] start nfc js unit test end*************
"
);
})
}
\ No newline at end of file
communication/nfc_SecureElement/src/main/js/test/openLogicalChannel.test.js
0 → 100644
浏览文件 @
ff96c6dc
/*
* Copyright (C) 2023 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import
secureElement
from
'
@ohos.secureElement
'
;
import
{
describe
,
beforeAll
,
beforeEach
,
afterEach
,
afterAll
,
it
,
expect
}
from
'
@ohos/hypium
'
;
function
sleep
(
delay
)
{
// delay x ms
let
start
=
(
new
Date
()).
getTime
();
while
((
new
Date
()).
getTime
()
-
start
<
delay
)
{
continue
;
}
}
let
nfcSEService
=
null
;
let
nfcESEReader
=
null
;
let
nfcOmaSession
=
null
;
let
nfcOmaChannel
=
null
;
let
nfcOmaReaderList
=
[];
let
aidArray
=
[
160
,
0
,
0
,
1
,
81
,
0
,
0
,
0
];
let
p2
=
0x00
;
let
command
=
[
128
,
202
,
159
,
127
,
0
];
export
default
function
openLogicalChanneltest
()
{
describe
(
'
openLogicalChanneltest
'
,
function
()
{
beforeAll
(
async
function
(
done
)
{
try
{
nfcSEService
=
secureElement
.
newSEService
(
"
serviceState
"
,
(
state
)
=>
{
if
(
state
==
secureElement
.
ServiceState
.
DISCONNECTED
)
{
console
.
info
(
"
[NFC_test] se_Logical Opened successfully
"
);
}
else
{
console
.
info
(
"
[NFC_test] se_Logical Failed to open
"
);
}
expect
(
state
instanceof
Object
).
assertTrue
();
});
sleep
(
1000
);
nfcOmaReaderList
=
nfcSEService
.
getReaders
();
if
(
nfcOmaReaderList
==
undefined
)
{
console
.
info
(
"
[NFC_test]This function is not supported because the phone NFC chip is ST chip.
"
);
}
else
{
console
.
info
(
"
[nfc_test] beforeAll se_Logical Result of getReaders:
"
+
nfcOmaReaderList
.
length
);
nfcESEReader
=
nfcOmaReaderList
[
0
];
console
.
info
(
"
[nfc_test] beforeAll se_Logical getReaders results list 0 is
"
+
nfcESEReader
);
nfcOmaSession
=
nfcESEReader
.
openSession
();
console
.
info
(
"
[nfc_test] beforeAll se_Logical openSession The result is
"
+
nfcOmaSession
);
let
getPromise
=
nfcOmaSession
.
openLogicalChannel
(
aidArray
,
p2
);
await
getPromise
.
then
((
data
)
=>
{
console
.
info
(
"
[NFC_test] beforeAll se_Logical openLogicalChannel data:
"
+
data
);
return
nfcOmaChannel
=
data
;
}).
catch
((
error
)
=>
{
console
.
info
(
"
[NFC_test] beforeAll se_Logical openLogicalChannel catch error:
"
+
error
);
expect
().
assertFail
();
done
();
});
sleep
(
5000
);
}
}
catch
(
e
)
{
console
.
info
(
"
[NFC_test] beforeAll se_Logical occurs exception:
"
+
e
.
message
);
expect
().
assertFail
();
}
done
();
console
.
info
(
'
beforeAll called
'
);
})
beforeEach
(
function
()
{
console
.
info
(
'
beforeEach called
'
);
})
afterEach
(
function
()
{
console
.
info
(
'
afterEach called
'
);
})
afterAll
(
function
()
{
nfcSEService
.
shutdown
();
sleep
(
5000
);
console
.
info
(
'
shutdown success
'
);
})
/**
* @tc.number SUB_Communication_Ese_LogicalChannel_js_1700
* @tc.name Test isBasicChannel
* @tc.desc Check whether the channel is a basic channel.
* @tc.type Function
* @tc.level Level 2
*/
it
(
'
SUB_Communication_Ese_LogicalChannel_js_1700
'
,
0
,
function
()
{
try
{
if
(
nfcOmaReaderList
==
undefined
)
{
console
.
log
(
"
[NFC_test]17 This function is not supported because the phone NFC chip is ST chip.
"
);
}
else
{
let
isBasic
=
nfcOmaChannel
.
isBasicChannel
();
console
.
info
(
"
[NFC_test]17 Check whether the channel is a basic channel:
"
+
isBasic
);
expect
(
isBasic
).
assertFalse
();
}
}
catch
(
error
)
{
console
.
info
(
"
[NFC_test]17 isBasicChannel occurs exception:
"
+
error
);
expect
().
assertFail
();
}
})
/**
* @tc.number SUB_Communication_Ese_LogicalChannel_js_1800
* @tc.name Test isClosed
* @tc.desc Check whether the channel is closed.
* @tc.type Function
* @tc.level Level 2
*/
it
(
'
SUB_Communication_Ese_LogicalChannel_js_1800
'
,
0
,
function
()
{
try
{
if
(
nfcOmaReaderList
==
undefined
)
{
console
.
log
(
"
[NFC_test]18 This function is not supported because the phone NFC chip is ST chip.
"
);
}
else
{
let
isChannelClosed
=
nfcOmaChannel
.
isClosed
();
console
.
info
(
"
[NFC_test]18 Check whether the channel is closed:
"
+
isChannelClosed
);
expect
(
isChannelClosed
).
assertFalse
();
}
}
catch
(
error
)
{
console
.
info
(
"
[NFC_test]18 isClosed occurs exception:
"
+
error
);
expect
().
assertFail
();
}
})
/**
* @tc.number SUB_Communication_Ese_LogicalChannel_js_1900
* @tc.name Test getSelectResponse
* @tc.desc Returns the data received from the application selection command.
* @tc.type Function
* @tc.level Level 2
*/
it
(
'
SUB_Communication_Ese_LogicalChannel_js_1900
'
,
0
,
function
()
{
try
{
if
(
nfcOmaReaderList
==
undefined
)
{
console
.
log
(
"
[NFC_test]19 This function is not supported because the phone NFC chip is ST chip.
"
);
}
else
{
let
getResponse
=
nfcOmaChannel
.
getSelectResponse
();
console
.
info
(
"
[NFC_test]19 Data received by the application select command:
"
+
getResponse
);
expect
(
getResponse
).
assertInstanceOf
(
'
Array
'
);
}
}
catch
(
error
)
{
console
.
info
(
"
[NFC_test]19 getSelectResponse occurs exception:
"
+
error
);
expect
().
assertFail
();
}
})
/**
* @tc.number SUB_Communication_Ese_LogicalChannel_js_2000
* @tc.name Test transmit
* @tc.desc Send an APDU command to the SE
* @tc.type Function
* @tc.level Level 2
*/
it
(
'
SUB_Communication_Ese_LogicalChannel_js_2000
'
,
0
,
async
function
(
done
)
{
try
{
if
(
nfcOmaReaderList
==
undefined
)
{
console
.
log
(
"
[NFC_test]20 This function is not supported because the phone NFC chip is ST chip.
"
);
}
else
{
nfcOmaChannel
.
transmit
(
command
,
(
err
,
data
)
=>
{
if
(
err
)
{
console
.
info
(
"
[NFC_test]20 Send error an APDU command to the SE:
"
+
err
);
expect
().
assertFail
();
}
else
{
console
.
info
(
"
[NFC_test]20 Send an APDU command to the SE:
"
+
data
);
expect
(
data
).
assertInstanceOf
(
'
Array
'
);
}
});
}
}
catch
(
error
)
{
console
.
info
(
"
[NFC_test]19 exception when sending the APDU command to the SE:
"
+
error
);
expect
().
assertFail
();
}
sleep
(
5000
);
done
();
})
/**
* @tc.number SUB_Communication_Ese_LogicalChannel_js_2100
* @tc.name Test transmit
* @tc.desc Send an APDU command to the SE
* @tc.type Function
* @tc.level Level 2
*/
it
(
'
SUB_Communication_Ese_LogicalChannel_js_2100
'
,
0
,
async
function
(
done
)
{
try
{
if
(
nfcOmaReaderList
==
undefined
)
{
console
.
log
(
"
[NFC_test]21 This function is not supported because the phone NFC chip is ST chip.
"
);
done
();
}
else
{
let
getPromise
=
nfcOmaChannel
.
transmit
(
command
);
await
getPromise
.
then
((
data
)
=>
{
console
.
info
(
"
[NFC_test]21 secureElement transmit data:
"
+
data
);
expect
(
data
).
assertInstanceOf
(
'
Array
'
);
done
();
}).
catch
((
err
)
=>
{
console
.
info
(
"
[NFC_test]21 secureElement transmit err:
"
+
err
);
expect
().
assertFail
();
done
();
});
}
}
catch
(
error
)
{
console
.
info
(
"
[NFC_test]21 exception when sending the APDU command to the SE:
"
+
error
);
expect
().
assertFail
();
done
();
}
})
/**
* @tc.number SUB_Communication_Ese_LogicalChannel_js_2200
* @tc.name Test close
* @tc.desc Obtains the session object that opens the channel.
* @tc.type Function
* @tc.level Level 2
*/
it
(
'
SUB_Communication_Ese_LogicalChannel_js_2200
'
,
0
,
function
()
{
try
{
if
(
nfcOmaReaderList
==
undefined
)
{
console
.
log
(
"
[NFC_test]22 This function is not supported because the phone NFC chip is ST chip.
"
);
}
else
{
let
getchannelSession
=
nfcOmaChannel
.
getSession
();
expect
(
getchannelSession
instanceof
Object
).
assertTrue
();
console
.
info
(
"
[NFC_test]22 getSession data:
"
+
getchannelSession
);
}
}
catch
(
error
)
{
console
.
info
(
"
[NFC_test]22 getSession occurs exception:
"
+
error
);
expect
().
assertFail
();
}
})
/**
* @tc.number SUB_Communication_Ese_LogicalChannel_js_2300
* @tc.name Test getNfcATag
* @tc.desc This interface is used to obtain the NFC A tag object.
* @tc.type Function
* @tc.level Level 2
*/
it
(
'
SUB_Communication_Ese_LogicalChannel_js_2300
'
,
0
,
function
()
{
try
{
if
(
nfcOmaReaderList
==
undefined
)
{
console
.
log
(
"
[NFC_test]23 This function is not supported because the phone NFC chip is ST chip.
"
);
}
else
{
nfcOmaChannel
.
close
();
console
.
info
(
"
[NFC_test] 23 The closeChannel test is successfully
"
);
let
isChannelClosed
=
nfcOmaChannel
.
isClosed
();
console
.
info
(
"
[NFC_test]23 Check whether the channel is disabled:
"
+
isChannelClosed
);
expect
(
isChannelClosed
).
assertTrue
();
}
}
catch
(
error
)
{
console
.
info
(
"
[NFC_test]23 close and isclosed occurs exception:
"
+
error
);
expect
().
assertFail
();
}
})
console
.
info
(
"
*************[nfc_test] start nfc js unit test end*************
"
);
})
}
\ No newline at end of file
communication/nfc_SecureElement/src/main/js/test/openSession.test.js
0 → 100644
浏览文件 @
ff96c6dc
/*
* Copyright (C) 2023 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import
secureElement
from
'
@ohos.secureElement
'
;
import
{
describe
,
beforeAll
,
beforeEach
,
afterEach
,
afterAll
,
it
,
expect
}
from
'
@ohos/hypium
'
;
function
sleep
(
delay
)
{
// delay x ms
let
start
=
(
new
Date
()).
getTime
();
while
((
new
Date
()).
getTime
()
-
start
<
delay
)
{
continue
;
}
}
let
nfcSEService
=
null
;
let
nfcESEReader
=
null
;
let
nfcOmaSession
=
null
;
let
nfcOmaReaderList
=
[];
export
default
function
openSessionTest
()
{
describe
(
'
openSessionTest
'
,
function
()
{
beforeAll
(
function
()
{
try
{
nfcSEService
=
secureElement
.
newSEService
(
"
serviceState
"
,
(
state
)
=>
{
if
(
state
==
secureElement
.
ServiceState
.
DISCONNECTED
)
{
console
.
info
(
"
[nfc_test] beforeAll Se_session state is Disconnected
"
);
}
else
{
console
.
info
(
"
[nfc_test] beforeAll Se_session state is Connected
"
);
}
expect
(
state
instanceof
Object
).
assertTrue
();
console
.
info
(
"
[nfc_test] beforeAll Se_session state is getReaders
"
+
state
);
});
sleep
(
1000
);
nfcOmaReaderList
=
nfcSEService
.
getReaders
();
if
(
nfcOmaReaderList
==
undefined
)
{
console
.
info
(
"
[NFC_test]This function is not supported because the phone NFC chip is ST chip.
"
);
}
else
{
console
.
info
(
"
[nfc_test] beforeAll Se_session Result of getReaders:
"
+
nfcOmaReaderList
.
length
);
nfcESEReader
=
nfcOmaReaderList
[
0
];
console
.
info
(
"
[nfc_test] beforeAll Se_session getReaders results list 0 is
"
+
nfcESEReader
);
nfcOmaSession
=
nfcESEReader
.
openSession
();
console
.
info
(
"
[nfc_test] beforeAll Se_session openSession The result is
"
+
nfcOmaSession
);
sleep
(
3000
);
}
}
catch
(
e
)
{
console
.
info
(
"
[nfc_test] beforeAll Se_session occurs exception:
"
+
e
.
message
);
}
})
beforeEach
(
function
()
{
console
.
info
(
'
beforeEach called
'
);
})
afterEach
(
function
()
{
console
.
info
(
'
afterEach called
'
);
})
afterAll
(
function
()
{
nfcSEService
.
shutdown
();
sleep
(
5000
);
console
.
info
(
'
[nfc_test] afterAll Se_session shutdown success
'
);
})
/**
* @tc.number SUB_Communication_NFC_secureElement_js_0600
* @tc.name Test getReader
* @tc.desc Obtains the reader that provides the session.
* @tc.type Function
* @tc.level Level 2
*/
it
(
'
SUB_Communication_NFC_secureElement_js_0600
'
,
0
,
function
()
{
try
{
if
(
nfcOmaReaderList
==
undefined
)
{
console
.
info
(
"
[NFC_test]6 This function is not supported because the phone NFC chip is ST chip.
"
);
}
else
{
let
getNfcreader
=
nfcOmaSession
.
getReader
();
console
.
info
(
"
[NFC_test]6 Reader result of this session:
"
+
getNfcreader
);
expect
(
getNfcreader
instanceof
Object
).
assertTrue
();
}
}
catch
(
error
)
{
console
.
info
(
"
[NFC_test]6 The reader result of the session is abnormal:
"
+
error
);
expect
().
assertFail
();
}
})
/**
* @tc.number SUB_Communication_NFC_secureElement_js_0700
* @tc.name Test getATR
* @tc.desc Obtain the ATR of the SE.
* @tc.type Function
* @tc.level Level 2
*/
it
(
'
SUB_Communication_NFC_secureElement_js_0700
'
,
0
,
function
()
{
try
{
if
(
nfcOmaReaderList
==
undefined
)
{
console
.
info
(
"
[NFC_test]7 This function is not supported because the phone NFC chip is ST chip.
"
);
}
else
{
let
nfcGetart
=
nfcOmaSession
.
getATR
();
expect
(
nfcGetart
).
assertInstanceOf
(
'
Array
'
);
expect
(
!
nfcGetart
==
false
).
assertTrue
();
console
.
info
(
"
[NFC_test]7 Get the ATR of this SE:
"
+
nfcGetart
);
}
}
catch
(
error
)
{
console
.
info
(
"
[NFC_test]7 Get the ATR of this SE occurs exception:
"
+
error
);
expect
().
assertFail
();
}
})
/**
* @tc.number SUB_Communication_NFC_secureElement_js_0800
* @tc.name Test close Session
* @tc.desc Close a single session.
* @tc.type Function
* @tc.level Level 2
*/
it
(
'
SUB_Communication_NFC_secureElement_js_0800
'
,
0
,
function
()
{
try
{
if
(
nfcOmaReaderList
==
undefined
)
{
console
.
info
(
"
[NFC_test]8 This function is not supported because the phone NFC chip is ST chip.
"
);
}
else
{
let
isopenSession
=
nfcOmaSession
.
isClosed
();
console
.
info
(
"
[NFC_test]8 Check the first one session is open:
"
+
isopenSession
);
expect
(
isopenSession
).
assertFalse
();
nfcOmaSession
.
close
();
sleep
(
3000
)
console
.
info
(
"
[NFC_test]8 second session is closed successfully
"
);
let
iscloseSession
=
nfcOmaSession
.
isClosed
();
console
.
info
(
"
[NFC_test]8 After close Check the first one session is open:
"
+
iscloseSession
);
expect
(
iscloseSession
).
assertTrue
();
}
}
catch
(
error
)
{
console
.
info
(
"
[NFC_test]8 0800 occurs exception:
"
+
error
);
expect
().
assertFail
();
}
})
console
.
info
(
"
*************[nfc_test] start nfc js unit test end*************
"
);
})
}
\ No newline at end of file
communication/nfc_SecureElement/src/main/resources/base/element/string.json
0 → 100644
浏览文件 @
ff96c6dc
{
"string"
:
[
{
"name"
:
"app_name"
,
"value"
:
"OsAccountTest"
},
{
"name"
:
"mainability_description"
,
"value"
:
"JS_Phone_Empty Feature Ability"
},
{
"name"
:
"MainAbility_desc"
,
"value"
:
"description"
},
{
"name"
:
"MainAbility_label"
,
"value"
:
"label"
},
{
"name"
:
"TestAbility_desc"
,
"value"
:
"description"
},
{
"name"
:
"TestAbility_label"
,
"value"
:
"label"
}
]
}
\ No newline at end of file
communication/nfc_SecureElement/src/main/resources/base/media/icon.png
0 → 100644
浏览文件 @
ff96c6dc
6.6 KB
communication/wifi_standard/src/main/js/test/WifiManagerCandidateNetWork.test.js
浏览文件 @
ff96c6dc
...
@@ -165,9 +165,9 @@ export default function actsWifiManagerCandidateNetWorkTest() {
...
@@ -165,9 +165,9 @@ export default function actsWifiManagerCandidateNetWorkTest() {
"
identity
"
:
"
aaa
"
,
"
identity
"
:
"
aaa
"
,
"
anonymousIdentity
"
:
"
bbb
"
,
"
anonymousIdentity
"
:
"
bbb
"
,
"
password
"
:
"
12345678
"
,
"
password
"
:
"
12345678
"
,
"
caCertAlias
es
"
:
"
ddd
"
,
"
caCertAlias
"
:
"
ddd
"
,
"
caPath
"
:
"
eee
"
,
"
caPath
"
:
"
eee
"
,
"
clientCertAlias
es
"
:
"
fff
"
,
"
clientCertAlias
"
:
"
fff
"
,
"
certEntry
"
:
new
Uint8Array
(),
"
certEntry
"
:
new
Uint8Array
(),
"
certPassword
"
:
"
12345678
"
,
"
certPassword
"
:
"
12345678
"
,
"
altSubjectMatch
"
:
"
ggg
"
,
"
altSubjectMatch
"
:
"
ggg
"
,
...
...
location/geolocation_standard/src/main/js/test/LocationMTest.test.js
浏览文件 @
ff96c6dc
...
@@ -548,7 +548,7 @@ export default function geolocationTest_geo7() {
...
@@ -548,7 +548,7 @@ export default function geolocationTest_geo7() {
});
});
}
catch
(
error
)
{
}
catch
(
error
)
{
console
.
info
(
"
[lbs_js] getCurrentLocation271 promise try err.
"
+
JSON
.
stringify
(
error
));
console
.
info
(
"
[lbs_js] getCurrentLocation271 promise try err.
"
+
JSON
.
stringify
(
error
));
expect
(
true
).
assertFalse
(
);
expect
(
error
.
code
).
assertEqual
(
"
401
"
);
}
}
await
sleep
(
1000
);
await
sleep
(
1000
);
try
{
try
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录