Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
OpenHarmony
Xts Acts
提交
0cab7285
X
Xts Acts
项目概览
OpenHarmony
/
Xts Acts
大约 1 年 前同步成功
通知
9
Star
22
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
X
Xts Acts
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
0cab7285
编写于
2月 16, 2023
作者:
Q
quanli
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
quanli1@huawei.com
Signed-off-by:
N
quanli
<
quanli1@huawei.com
>
上级
4901cdb1
变更
36
隐藏空白更改
内联
并排
Showing
36 changed file
with
4239 addition
and
1752 deletion
+4239
-1752
communication/BUILD.gn
communication/BUILD.gn
+1
-0
communication/bluetooth_manager/src/main/js/test/SwitchOff003.test.js
...n/bluetooth_manager/src/main/js/test/SwitchOff003.test.js
+0
-152
communication/bluetooth_profile/src/main/js/test/BluetoothHfp.test.js
...n/bluetooth_profile/src/main/js/test/BluetoothHfp.test.js
+3
-2
communication/nfc_ErrorCode/BUILD.gn
communication/nfc_ErrorCode/BUILD.gn
+35
-0
communication/nfc_ErrorCode/Test.json
communication/nfc_ErrorCode/Test.json
+20
-0
communication/nfc_ErrorCode/signature/openharmony_sx.p7b
communication/nfc_ErrorCode/signature/openharmony_sx.p7b
+0
-0
communication/nfc_ErrorCode/src/main/config.json
communication/nfc_ErrorCode/src/main/config.json
+105
-0
communication/nfc_ErrorCode/src/main/js/MainAbility/app.js
communication/nfc_ErrorCode/src/main/js/MainAbility/app.js
+23
-0
communication/nfc_ErrorCode/src/main/js/MainAbility/i18n/en-US.json
...ion/nfc_ErrorCode/src/main/js/MainAbility/i18n/en-US.json
+6
-0
communication/nfc_ErrorCode/src/main/js/MainAbility/i18n/zh-CN.json
...ion/nfc_ErrorCode/src/main/js/MainAbility/i18n/zh-CN.json
+6
-0
communication/nfc_ErrorCode/src/main/js/MainAbility/pages/index/index.css
...c_ErrorCode/src/main/js/MainAbility/pages/index/index.css
+25
-0
communication/nfc_ErrorCode/src/main/js/MainAbility/pages/index/index.hml
...c_ErrorCode/src/main/js/MainAbility/pages/index/index.hml
+21
-0
communication/nfc_ErrorCode/src/main/js/MainAbility/pages/index/index.js
...fc_ErrorCode/src/main/js/MainAbility/pages/index/index.js
+34
-0
communication/nfc_ErrorCode/src/main/js/TestAbility/app.js
communication/nfc_ErrorCode/src/main/js/TestAbility/app.js
+31
-0
communication/nfc_ErrorCode/src/main/js/TestAbility/i18n/en-US.json
...ion/nfc_ErrorCode/src/main/js/TestAbility/i18n/en-US.json
+8
-0
communication/nfc_ErrorCode/src/main/js/TestAbility/i18n/zh-CN.json
...ion/nfc_ErrorCode/src/main/js/TestAbility/i18n/zh-CN.json
+8
-0
communication/nfc_ErrorCode/src/main/js/TestAbility/pages/index/index.css
...c_ErrorCode/src/main/js/TestAbility/pages/index/index.css
+30
-0
communication/nfc_ErrorCode/src/main/js/TestAbility/pages/index/index.hml
...c_ErrorCode/src/main/js/TestAbility/pages/index/index.hml
+5
-0
communication/nfc_ErrorCode/src/main/js/TestAbility/pages/index/index.js
...fc_ErrorCode/src/main/js/TestAbility/pages/index/index.js
+26
-0
communication/nfc_ErrorCode/src/main/js/TestRunner/OpenHarmonyTestRunner.js
...ErrorCode/src/main/js/TestRunner/OpenHarmonyTestRunner.js
+59
-0
communication/nfc_ErrorCode/src/main/js/test/List.test.js
communication/nfc_ErrorCode/src/main/js/test/List.test.js
+33
-0
communication/nfc_ErrorCode/src/main/js/test/error.IsoDepTag.js
...ication/nfc_ErrorCode/src/main/js/test/error.IsoDepTag.js
+172
-0
communication/nfc_ErrorCode/src/main/js/test/error.MifareClassicTag.js
.../nfc_ErrorCode/src/main/js/test/error.MifareClassicTag.js
+630
-0
communication/nfc_ErrorCode/src/main/js/test/error.MifareUltralightTag.js
...c_ErrorCode/src/main/js/test/error.MifareUltralightTag.js
+226
-0
communication/nfc_ErrorCode/src/main/js/test/error.NDEFTag.js
...unication/nfc_ErrorCode/src/main/js/test/error.NDEFTag.js
+737
-0
communication/nfc_ErrorCode/src/main/js/test/error.TagABFV.js
...unication/nfc_ErrorCode/src/main/js/test/error.TagABFV.js
+218
-0
communication/nfc_ErrorCode/src/main/resources/base/element/string.json
...nfc_ErrorCode/src/main/resources/base/element/string.json
+28
-0
communication/nfc_ErrorCode/src/main/resources/base/media/icon.png
...tion/nfc_ErrorCode/src/main/resources/base/media/icon.png
+0
-0
communication/wifi_p2p/signature/openharmony_sx.p7b
communication/wifi_p2p/signature/openharmony_sx.p7b
+0
-0
communication/wifi_p2p/src/main/js/test/WifiManagerP2PEvent.test.js
...ion/wifi_p2p/src/main/js/test/WifiManagerP2PEvent.test.js
+194
-187
communication/wifi_p2p/src/main/js/test/WifiManagerP2PFunction.test.js
.../wifi_p2p/src/main/js/test/WifiManagerP2PFunction.test.js
+733
-663
communication/wifi_p2p/src/main/js/test/WifiP2PEvent.test.js
communication/wifi_p2p/src/main/js/test/WifiP2PEvent.test.js
+199
-192
communication/wifi_p2p/src/main/js/test/WifiP2PFunction.test.js
...ication/wifi_p2p/src/main/js/test/WifiP2PFunction.test.js
+617
-548
communication/wifi_standard/signature/openharmony_sx.p7b
communication/wifi_standard/signature/openharmony_sx.p7b
+0
-0
location/geolocation_standard/src/main/js/test/GetCountryCode.test.js
...location_standard/src/main/js/test/GetCountryCode.test.js
+3
-4
location/geolocation_standard/src/main/js/test/GetCountryCodeM.test.js
...ocation_standard/src/main/js/test/GetCountryCodeM.test.js
+3
-4
未找到文件。
communication/BUILD.gn
浏览文件 @
0cab7285
...
...
@@ -23,6 +23,7 @@ group("communication") {
"bluetooth_standard:ActsBluetoothJsTest",
"dsoftbus/rpc:ActsRpcJsTest",
"nfc_Controller:ActsNFCJSTest",
"nfc_ErrorCode:ActsNFCErrorJSTest",
"wifi_p2p:ActsP2PJSTest",
"wifi_standard:ActsWifiJSTest",
]
...
...
communication/bluetooth_manager/src/main/js/test/SwitchOff003.test.js
浏览文件 @
0cab7285
...
...
@@ -344,99 +344,6 @@ describe('bluetoothBLETest3', function() {
}
})
/**
* @tc.number COMMUNICATION_BLUETOOTH_SwitchOff_1300
* @tc.name testSppListen
* @tc.desc Test 2900003 - Bluetooth switch is off
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 2
*/
it
(
'
COMMUNICATION_BLUETOOTH_SwitchOff_1300
'
,
0
,
async
function
(
done
)
{
try
{
let
SppOption
=
{
uuid
:
'
00001810-0000-1000-8000-00805F9B34FB
'
,
secure
:
true
,
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
(
number
!=
null
);
}
}
bluetooth
.
sppListen
(
'
server1
'
,
SppOption
,
serverSocket
);
expect
(
true
).
assertFalse
();
done
()
}
catch
(
error
)
{
console
.
error
(
'
[bluetooth_js]sppListen error.code:
'
+
JSON
.
stringify
(
error
.
code
)
+
'
error.message:
'
+
JSON
.
stringify
(
error
.
message
));
expect
(
error
.
code
).
assertEqual
(
'
2900003
'
);
done
()
}
})
/**
* @tc.number COMMUNICATION_BLUETOOTH_SwitchOff_1400
* @tc.name testSppAccept
* @tc.desc Test 2900003 - Bluetooth switch is off.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 2
*/
it
(
'
COMMUNICATION_BLUETOOTH_SwitchOff_1400
'
,
0
,
async
function
(
done
)
{
try
{
function
acceptClientSocket
(
code
,
number
)
{
if
(
code
)
{
console
.
log
(
'
[bluetooth_js] error code05:
'
+
JSON
.
stringify
(
code
));
}
else
{
console
.
log
(
'
[bluetooth_js] clientSocket Number:
'
+
JSON
.
stringify
(
number
));
expect
(
true
).
assertEqual
(
number
!=
null
);
}
}
bluetooth
.
sppAccept
(
0
,
acceptClientSocket
);
expect
(
true
).
assertFalse
();
done
()
}
catch
(
error
)
{
console
.
error
(
'
[bluetooth_js]sppAccept error.code:
'
+
JSON
.
stringify
(
error
.
code
)
+
'
error.message:
'
+
JSON
.
stringify
(
error
.
message
));
expect
(
error
.
code
).
assertEqual
(
'
2900003
'
);
done
()
}
})
/**
* @tc.number COMMUNICATION_BLUETOOTH_SwitchOff_1500
* @tc.name testSppConnect
* @tc.desc Test 2900003 - Bluetooth switch is off.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 2
*/
it
(
'
COMMUNICATION_BLUETOOTH_SwitchOff_1500
'
,
0
,
async
function
(
done
)
{
try
{
let
sppOption
=
{
uuid
:
'
00001810-0000-1000-8000-00805F9B34FB
'
,
secure
:
true
,
type
:
0
};
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
).
assertFalse
();
done
()
}
catch
(
error
)
{
console
.
error
(
'
[bluetooth_js]sppConnect error.code:
'
+
JSON
.
stringify
(
error
.
code
)
+
'
error.message:
'
+
JSON
.
stringify
(
error
.
message
));
expect
(
error
.
code
).
assertEqual
(
'
2900003
'
);
done
()
}
})
/**
* @tc.number COMMUNICATION_BLUETOOTH_SwitchOff_1600
* @tc.name test getDevice HFP State.
...
...
@@ -701,28 +608,6 @@ describe('bluetoothBLETest3', function() {
}
})
/**
* @tc.number COMMUNICATION_BLUETOOTH_SwitchOff_2700
* @tc.name test getConnectedBLEDevices
* @tc.desc Test 2900003 - Bluetooth switch is off.
* @tc.size MEDIUM
* @ since 7
* @tc.type Function
* @tc.level Level 2
*/
it
(
'
COMMUNICATION_BLUETOOTH_SwitchOff_2700
'
,
0
,
function
()
{
try
{
let
result
=
bluetooth
.
BLE
.
getConnectedBLEDevices
();
console
.
info
(
"
[bluetooth_js] getConnDev:
"
+
JSON
.
stringify
(
result
)
+
"
length:
"
+
result
.
length
);
expect
(
true
).
assertFalse
();
}
catch
(
error
)
{
console
.
error
(
`[bluetooth_js]getConnDev failed, code is
${
error
.
code
}
,
message is
${
error
.
message
}
`
);
expect
(
error
.
code
).
assertEqual
(
'
2900003
'
);
}
})
/**
* @tc.number COMMUNICATION_BLUETOOTH_SwitchOff_2800
* @tc.name testClassicStartBLEScan
...
...
@@ -971,43 +856,6 @@ describe('bluetoothBLETest3', function() {
}
})
/**
* @tc.number COMMUNICATION_BLUETOOTH_SwitchOff_3500
* @tc.name testNotifyCharacteristicChanged
* @tc.desc Test 2900003 - Bluetooth switch is off.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 2
*/
it
(
'
COMMUNICATION_BLUETOOTH_SwitchOff_3500
'
,
0
,
async
function
(
done
)
{
try
{
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
:
descV
};
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
};
gattServer
.
notifyCharacteristicChanged
(
'
00:11:22:33:44:55
'
,
NotifyCharacteristic
);
expect
(
true
).
assertFalse
();
done
();
}
catch
(
error
)
{
console
.
error
(
'
[bluetooth_js]notifyCharacteristicChanged1 failed, code:
'
+
JSON
.
stringify
(
error
.
code
)
+
'
error.message:
'
+
JSON
.
stringify
(
error
.
message
));
expect
(
error
.
code
).
assertEqual
(
'
2900003
'
);
done
()
}
})
/**
* @tc.number COMMUNICATION_BLUETOOTH_SwitchOff_3600
* @tc.name testSendResponse success
...
...
communication/bluetooth_profile/src/main/js/test/BluetoothHfp.test.js
浏览文件 @
0cab7285
...
...
@@ -132,8 +132,10 @@ describe('bluetoothhostTest_host_3', function () {
}
let
hfpSrc
=
bluetooth
.
getProfile
(
bluetooth
.
ProfileId
.
PROFILE_HANDS_FREE_AUDIO_GATEWAY
);
hfpSrc
.
on
(
'
connectionStateChange
'
,
StateChangeParam
);
hfpSrc
.
connect
(
'
11:22:33:44:55:66
'
);
let
conn
=
hfpSrc
.
connect
(
'
11:22:33:44:55:66
'
);
await
sleep
(
6000
);
console
.
info
(
'
[bluetooth_js]hfp connect result:
'
+
JSON
.
stringify
(
conn
));
expect
(
conn
).
assertFalse
();
hfpSrc
.
off
(
'
connectionStateChange
'
,
StateChangeParam
);
done
();
})
...
...
@@ -220,4 +222,3 @@ describe('bluetoothhostTest_host_3', function () {
}
communication/nfc_ErrorCode/BUILD.gn
0 → 100644
浏览文件 @
0cab7285
# 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("//test/xts/tools/build/suite.gni")
ohos_js_hap_suite("ActsNFCErrorJSTest") {
hap_profile = "./src/main/config.json"
deps = [
":nfc_js_assets",
":nfc_resources",
]
certificate_profile = "./signature/openharmony_sx.p7b"
hap_name = "ActsNFCErrorJSTest"
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_ErrorCode/Test.json
0 → 100644
浏览文件 @
0cab7285
{
"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"
:
[
"ActsNFCErrorJSTest.hap"
],
"type"
:
"AppInstallKit"
,
"cleanup-apps"
:
true
}
]
}
communication/nfc_ErrorCode/signature/openharmony_sx.p7b
0 → 100644
浏览文件 @
0cab7285
文件已添加
communication/nfc_ErrorCode/src/main/config.json
0 → 100644
浏览文件 @
0cab7285
{
"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_ErrorCode/src/main/js/MainAbility/app.js
0 → 100644
浏览文件 @
0cab7285
/*
* Copyright (C) 2022 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
export
default
{
onCreate
()
{
console
.
info
(
'
AceApplication onCreate
'
);
},
onDestroy
()
{
console
.
info
(
'
AceApplication onDestroy
'
);
}
};
communication/nfc_ErrorCode/src/main/js/MainAbility/i18n/en-US.json
0 → 100644
浏览文件 @
0cab7285
{
"strings"
:
{
"hello"
:
"Hello"
,
"world"
:
"World"
}
}
\ No newline at end of file
communication/nfc_ErrorCode/src/main/js/MainAbility/i18n/zh-CN.json
0 → 100644
浏览文件 @
0cab7285
{
"strings"
:
{
"hello"
:
"您好"
,
"world"
:
"世界"
}
}
\ No newline at end of file
communication/nfc_ErrorCode/src/main/js/MainAbility/pages/index/index.css
0 → 100644
浏览文件 @
0cab7285
/*
* 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.
*/
.container
{
flex-direction
:
column
;
justify-content
:
center
;
align-items
:
center
;
}
.title
{
font-size
:
100px
;
}
communication/nfc_ErrorCode/src/main/js/MainAbility/pages/index/index.hml
0 → 100644
浏览文件 @
0cab7285
/*
* 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.
*/
<div class="container">
<text class="title">
{{ $t('strings.hello') }} {{ title }}
</text>
</div>
communication/nfc_ErrorCode/src/main/js/MainAbility/pages/index/index.js
0 → 100644
浏览文件 @
0cab7285
/*
* Copyright (C) 2022 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
export
default
{
data
:
{
title
:
''
,
myTimeout
:
25000
},
onInit
()
{
this
.
title
=
this
.
$t
(
'
strings.world
'
);
},
onShow
()
{
console
.
info
(
'
onShow finish
'
)
},
onReady
()
{
console
.
info
(
'
onReady finish
'
)
},
}
communication/nfc_ErrorCode/src/main/js/TestAbility/app.js
0 → 100644
浏览文件 @
0cab7285
/*
* Copyright (c) 2022 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import
AbilityDelegatorRegistry
from
'
@ohos.application.abilityDelegatorRegistry
'
import
{
Hypium
}
from
'
@ohos/hypium
'
import
testsuite
from
'
../test/List.test
'
export
default
{
onCreate
()
{
console
.
info
(
'
TestApplication onCreate
'
)
var
abilityDelegator
=
AbilityDelegatorRegistry
.
getAbilityDelegator
()
var
abilityDelegatorArguments
=
AbilityDelegatorRegistry
.
getArguments
()
console
.
info
(
'
start run testcase!!!
'
)
Hypium
.
hypiumTest
(
abilityDelegator
,
abilityDelegatorArguments
,
testsuite
)
},
onDestroy
()
{
console
.
info
(
"
TestApplication onDestroy
"
);
}
};
communication/nfc_ErrorCode/src/main/js/TestAbility/i18n/en-US.json
0 → 100644
浏览文件 @
0cab7285
{
"strings"
:
{
"hello"
:
"Hello"
,
"world"
:
"World"
},
"Files"
:
{
}
}
\ No newline at end of file
communication/nfc_ErrorCode/src/main/js/TestAbility/i18n/zh-CN.json
0 → 100644
浏览文件 @
0cab7285
{
"strings"
:
{
"hello"
:
"您好"
,
"world"
:
"世界"
},
"Files"
:
{
}
}
\ No newline at end of file
communication/nfc_ErrorCode/src/main/js/TestAbility/pages/index/index.css
0 → 100644
浏览文件 @
0cab7285
.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_ErrorCode/src/main/js/TestAbility/pages/index/index.hml
0 → 100644
浏览文件 @
0cab7285
<div class="container">
<text class="title">
{{ $t('strings.hello') }} {{ title }}
</text>
</div>
communication/nfc_ErrorCode/src/main/js/TestAbility/pages/index/index.js
0 → 100644
浏览文件 @
0cab7285
/*
* Copyright (c) 2022 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
export
default
{
data
:
{
title
:
""
},
onInit
()
{
this
.
title
=
this
.
$t
(
'
strings.world
'
);
}
}
communication/nfc_ErrorCode/src/main/js/TestRunner/OpenHarmonyTestRunner.js
0 → 100644
浏览文件 @
0cab7285
/*
* Copyright (c) 2022 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import
AbilityDelegatorRegistry
from
'
@ohos.application.abilityDelegatorRegistry
'
function
translateParamsToString
(
parameters
)
{
const
keySet
=
new
Set
([
'
-s class
'
,
'
-s notClass
'
,
'
-s suite
'
,
'
-s itName
'
,
'
-s level
'
,
'
-s testType
'
,
'
-s size
'
,
'
-s timeout
'
,
'
-s package
'
,
'
-s dryRun
'
])
let
targetParams
=
''
;
for
(
const
key
in
parameters
)
{
if
(
keySet
.
has
(
key
))
{
targetParams
+=
'
'
+
key
+
'
'
+
parameters
[
key
]
}
}
return
targetParams
.
trim
()
}
export
default
{
onPrepare
()
{
console
.
info
(
'
OpenHarmonyTestRunner OnPrepare
'
)
},
onRun
()
{
console
.
log
(
'
OpenHarmonyTestRunner onRun run
'
)
var
abilityDelegatorArguments
=
AbilityDelegatorRegistry
.
getArguments
()
var
abilityDelegator
=
AbilityDelegatorRegistry
.
getAbilityDelegator
()
var
testAbilityName
=
abilityDelegatorArguments
.
parameters
[
'
-p
'
]
+
'
.TestAbility
'
var
cmd
=
'
aa start -d 0 -a
'
+
testAbilityName
+
'
-b
'
+
abilityDelegatorArguments
.
bundleName
cmd
+=
'
'
+
translateParamsToString
(
abilityDelegatorArguments
.
parameters
)
var
debug
=
abilityDelegatorArguments
.
parameters
[
"
-D
"
]
console
.
info
(
'
debug value :
'
+
debug
)
if
(
debug
==
'
true
'
)
{
cmd
+=
'
-D
'
}
console
.
info
(
'
cmd :
'
+
cmd
)
abilityDelegator
.
executeShellCommand
(
cmd
,
(
err
,
data
)
=>
{
console
.
info
(
'
executeShellCommand : err :
'
+
JSON
.
stringify
(
err
));
console
.
info
(
'
executeShellCommand : data :
'
+
data
.
stdResult
);
console
.
info
(
'
executeShellCommand : data :
'
+
data
.
exitCode
);
})
}
};
communication/nfc_ErrorCode/src/main/js/test/List.test.js
0 → 100644
浏览文件 @
0cab7285
/*
* 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
nfcIsoDepErrorTest
from
'
./error.IsoDepTag.js
'
import
MifareClassicErrorTest
from
'
./error.MifareClassicTag.js
'
import
UltralightTagErrorTest
from
'
./error.MifareUltralightTag.js
'
import
nfcNDEFErrorTest
from
'
./error.NDEFTag.js
'
import
nfcTagABFVErrorTest
from
'
./error.TagABFV.js
'
import
parameter
from
'
@ohos.systemparameter
'
;
let
info
=
parameter
.
getSync
(
"
const.SystemCapability.Communication.NFC.Core
"
,
"
false
"
);
export
default
function
testsuite
()
{
if
(
info
!=
"
false
"
)
{
nfcIsoDepErrorTest
();
MifareClassicErrorTest
();
UltralightTagErrorTest
();
nfcNDEFErrorTest
();
nfcTagABFVErrorTest
();
}
}
\ No newline at end of file
communication/nfc_ErrorCode/src/main/js/test/error.IsoDepTag.js
0 → 100644
浏览文件 @
0cab7285
/*
* 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
tag
from
'
@ohos.nfc.tag
'
;
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
NdefRecord
=
{
NFC_A
:
1
,
NFC_B
:
2
,
ISO_DEP
:
3
,
NFC_F
:
4
,
NFC_V
:
5
,
NDEF
:
6
,
MIFARE_CLASSIC
:
8
,
MIFARE_ULTRALIGHT
:
9
,
NDEF_FORMATABLE
:
10
,
};
let
NfcForumType
=
{
NFC_FORUM_TYPE_1
:
1
,
NFC_FORUM_TYPE_2
:
2
,
NFC_FORUM_TYPE_3
:
3
,
NFC_FORUM_TYPE_4
:
4
,
MIFARE_CLASSIC
:
101
,
};
let
FeatureType
=
{
HCE
:
0
,
UICC
:
0
,
ESE
:
0
,
}
let
isoDepTaginfo
=
{
"
uid
"
:
[
0x01
,
0x02
,
0x03
,
0x04
],
"
technology
"
:
[
1
,
3
],
"
extrasData
"
:
[
{
"
Sak
"
:
0x08
,
"
Atqa
"
:
"
B000
"
,
},
{
"
HistoricalBytes
"
:
"
4D54000500308693695B
"
,
"
HiLayerResponse
"
:
""
,
},
],
"
tagRfDiscId
"
:
1
,
};
let
IsoDepTag
;
export
default
function
nfcIsoDepErrorTest
()
{
describe
(
'
nfcIsoDepErrorTest
'
,
function
()
{
beforeAll
(
function
()
{
console
.
info
(
'
beforeAll called
'
)
})
beforeEach
(
function
()
{
console
.
info
(
'
beforeEach called
'
)
try
{
IsoDepTag
=
tag
.
getIsoDep
(
isoDepTaginfo
);
}
catch
(
error
){
console
.
info
(
'
getIsoDep is ->
'
+
error
)
}
})
afterEach
(
function
()
{
console
.
info
(
'
afterEach called
'
)
})
afterAll
(
function
()
{
console
.
info
(
'
afterAll called
'
)
})
/**
* @tc.number SUB_Communication_NFC_nfcIsoDep_js_0100
* @tc.name Test isExtendedApduSupported IsoDep
* @tc.desc Check whether extended APDUs are supported Promise. The error code is 401
* @tc.size since 9
* @tc.type Function
* @tc.level Level 2
*/
it
(
'
SUB_Communication_NFC_nfcIsoDep_js_0100
'
,
0
,
async
function
(
done
)
{
if
(
IsoDepTag
!=
null
&&
IsoDepTag
!=
undefined
)
{
(
async
()
=>
{
try
{
let
result
=
await
IsoDepTag
.
isExtendedApduSupported
(
'
test
'
);
console
.
info
(
"
[NFC_test]isoDep1 isExtendedApduSupported data:
"
+
result
);
expect
(
result
).
assertInstanceOf
(
'
Array
'
)
expect
().
assertFail
()
}
catch
(
error
)
{
console
.
info
(
"
[NFC_test]isoDep1 isExtendedApduSupported errorcode:
"
+
error
.
code
);
expect
(
401
).
assertEqual
(
error
.
code
)
}
})();
sleep
(
3000
);
done
();
}
else
{
console
.
info
(
"
[NFC_test]IsoDepTag1 = null & = undefined:
"
);
expect
(
true
).
assertFalse
();
}
})
/**
* @tc.number SUB_Communication_NFC_nfcIsoDep_js_0200
* @tc.name Test isExtendedApduSupported IsoDep
* @tc.desc Check whether extended APDUs are supported callback. The error code is 401
* @tc.size since 9
* @tc.type Function
* @tc.level Level 2
*/
it
(
'
SUB_Communication_NFC_nfcIsoDep_js_0200
'
,
0
,
async
function
(
done
)
{
if
(
IsoDepTag
!=
null
&&
IsoDepTag
!=
undefined
)
{
try
{
IsoDepTag
.
isExtendedApduSupported
(
'
test
'
)((
err
,
data
)
=>
{
if
(
err
)
{
expect
().
assertFail
();
console
.
info
(
"
[NFC_test]isoDep2 isExtendedApduSupported errcode:
"
+
err
);
}
else
{
expect
(
false
).
assertEqual
(
data
);
console
.
info
(
"
[NFC_test]isoDep2 isExtendedApduSupported data:
"
+
data
);
}
});
}
catch
(
error
)
{
console
.
info
(
"
[NFC_test]isoDep2 isExtendedApduSupported errorcode:
"
+
error
.
code
);
expect
(
401
).
assertEqual
(
error
.
code
)
}
done
();
}
else
{
console
.
info
(
"
[NFC_test]IsoDepTag2 = null & = undefined:
"
);
expect
(
true
).
assertFalse
();
}
})
/**
* @tc.number SUB_Communication_NFC_nfcIsoDep_js_0300
* @tc.name Test getIsoDep IsoDep
* @tc.desc Obtains an object based on the tag information The error code is 401
* @tc.size since 9
* @tc.type Function
* @tc.level Level 2
*/
it
(
'
SUB_Communication_NFC_nfcIsoDep_js_0300
'
,
0
,
function
()
{
if
(
IsoDepTag
!=
null
&&
IsoDepTag
!=
undefined
)
{
try
{
let
getIsoDepTaginfo
=
tag
.
getIsoDep
(
"
test
"
);
console
.
info
(
"
[NFC_test]isoDep3 getIsoDep:
"
+
getIsoDepTaginfo
);
}
catch
(
error
)
{
console
.
info
(
"
[NFC_test]isoDep3 getIsoDep errorcode:
"
+
error
.
code
);
expect
(
401
).
assertEqual
(
error
.
code
)
}
}
else
{
console
.
info
(
"
[NFC_test]IsoDepTag3 = null & = undefined:
"
);
expect
(
true
).
assertFalse
();
}
})
console
.
info
(
"
*************[nfc_test] start nfc js unit test end*************
"
);
})
}
\ No newline at end of file
communication/nfc_ErrorCode/src/main/js/test/error.MifareClassicTag.js
0 → 100644
浏览文件 @
0cab7285
/*
* 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
tag
from
'
@ohos.nfc.tag
'
;
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
MifareClassicType
=
{
TYPE_UNKNOWN
:
-
1
,
TYPE_CLASSIC
:
0
,
TYPE_PLUS
:
1
,
TYPE_PRO
:
2
,
}
let
MifareTagSize
=
{
MC_SIZE_MINI
:
320
,
MC_SIZE_1K
:
1024
,
MC_SIZE_2K
:
2048
,
MC_SIZE_4K
:
4096
,
}
let
mifareclassicTaginfo
=
{
"
uid
"
:
[
0x01
,
0x02
,
0x03
,
0x04
],
"
technology
"
:
[
1
,
8
],
"
extrasData
"
:
[
{
"
Sak
"
:
0x08
,
"
Atqa
"
:
"
B000
"
,
},
{
},
],
"
tagRfDiscId
"
:
1
,
};
let
MifareClassicTag
;
export
default
function
MifareClassicErrorTest
()
{
describe
(
'
MifareClassicErrorTest
'
,
function
()
{
beforeAll
(
function
()
{
console
.
info
(
'
beforeAll called
'
)
})
beforeEach
(
function
()
{
console
.
info
(
'
beforeEach called
'
)
try
{
MifareClassicTag
=
tag
.
getMifareClassic
(
mifareclassicTaginfo
);
}
catch
(
error
){
console
.
info
(
'
beforeAll mifareClassic error
'
+
error
)
}
})
afterEach
(
function
()
{
console
.
info
(
'
afterEach called
'
)
})
afterAll
(
function
()
{
console
.
info
(
'
afterAll called
'
)
})
/**
* @tc.number SUB_Communication_NFC_mifareClassic_js_0100
* @tc.name testauthenticateSector
* @tc.desc Test authenticateSector api by callback. The error code is 401
* @tc.size MEDIUM
* @ since 9
* @tc.type Function
* @tc.level Level 2
*/
it
(
'
SUB_Communication_NFC_mifareClassic_js_0100
'
,
0
,
async
function
(
done
)
{
if
(
MifareClassicTag
!=
null
&&
MifareClassicTag
!=
undefined
)
{
let
sectorIndex
=
1
;
let
key
=
[
0x04
,
0x05
];
(
async
()
=>
{
try
{
let
result
=
await
MifareClassicTag
.
authenticateSector
(
'
test
'
,
'
test
'
,
true
);
console
.
info
(
"
[NFC_test]MifareClassic1 authenticateSector data:
"
+
result
);
}
catch
(
error
)
{
console
.
info
(
"
[NFC_test]MifareClassic1 authenticateSector errorcode:
"
+
error
.
code
);
expect
(
401
).
assertEqual
(
error
.
code
);
}
})();
sleep
(
3000
);
done
();
}
else
{
console
.
info
(
"
[NFC_test]MifareClassicTag1 = null & = undefined:
"
);
expect
(
true
).
assertFalse
();
}
})
/**
* @tc.number SUB_Communication_NFC_mifareClassic_js_0200
* @tc.name testauthenticateSector
* @tc.desc Test authenticateSector api. The error code is 401
* @tc.size MEDIUM
* @ since 9
* @tc.type Function
* @tc.level Level 2
*/
it
(
'
SUB_Communication_NFC_mifareClassic_js_0200
'
,
0
,
async
function
(
done
)
{
if
(
MifareClassicTag
!=
null
&&
MifareClassicTag
!=
undefined
)
{
let
sectorIndex
=
1
;
let
key
=
[
0x04
,
0x05
];
try
{
MifareClassicTag
.
authenticateSector
(
'
test
'
,
'
test
'
,
true
,
(
err
,
data
)
=>
{
if
(
err
)
{
console
.
info
(
"
[NFC_test]mifareClassic2 authenticateSector errcode:
"
+
err
);
expect
(
true
).
assertEqual
(
true
);
}
else
{
console
.
info
(
"
[NFC_test]mifareClassic2 authenticateSector data:
"
+
data
+
"
json2:
"
+
JSON
.
stringify
(
data
));
expect
(
data
).
assertTrue
();
}
});
}
catch
(
error
)
{
console
.
info
(
"
[NFC_test]mifareClassic2 authenticateSector errorcode:
"
+
error
.
code
);
expect
(
401
).
assertEqual
(
error
.
code
);
}
sleep
(
3000
);
done
();
}
else
{
console
.
info
(
"
[NFC_test]MifareClassicTag2 = null & = undefined:
"
);
expect
(
true
).
assertFalse
();
}
})
/**
* @tc.number SUB_Communication_NFC_mifareClassic_js_0300
* @tc.name testreadSingleBlock
* @tc.desc Test readSingleBlock api. The error code is 401
* @tc.size MEDIUM
* @ since 9
* @tc.type Function
* @tc.level Level 2
*/
it
(
'
SUB_Communication_NFC_mifareClassic_js_0300
'
,
0
,
async
function
(
done
)
{
if
(
MifareClassicTag
!=
null
&&
MifareClassicTag
!=
undefined
)
{
let
blockIndex
=
1
;
(
async
()
=>
{
try
{
let
result
=
await
MifareClassicTag
.
readSingleBlock
(
'
test
'
);
console
.
info
(
"
[NFC_test]mifareClassic3 readSingleBlock data:
"
+
result
);
}
catch
(
error
)
{
console
.
info
(
"
[NFC_test]mifareClassic3 readSingleBlock errorcode:
"
+
error
.
code
);
expect
(
401
).
assertEqual
(
error
.
code
);
}
})();
sleep
(
3000
);
done
();
}
else
{
console
.
info
(
"
[NFC_test]mifareClassic3 = null & = undefined:
"
);
expect
(
true
).
assertFalse
();
}
})
/**
* @tc.number SUB_Communication_NFC_mifareClassic_js_0400
* @tc.name testreadSingleBlock
* @tc.desc Test readSingleBlock api. The error code is 401
* @tc.size MEDIUM
* @ since 9
* @tc.type Function
* @tc.level Level 2
*/
it
(
'
SUB_Communication_NFC_mifareClassic_js_0400
'
,
0
,
async
function
(
done
)
{
if
(
MifareClassicTag
!=
null
&&
MifareClassicTag
!=
undefined
)
{
let
blockIndex
=
1
;
try
{
MifareClassicTag
.
readSingleBlock
(
'
test
'
,
(
err
,
data
)
=>
{
if
(
err
)
{
console
.
info
(
"
[NFC_test]mifareClassic4 readSingleBlock errcode:
"
+
err
);
expect
(
true
).
assertEqual
(
true
);
}
else
{
console
.
info
(
"
[NFC_test]mifareClassic4 readSingleBlock data:
"
+
data
+
"
json4:
"
+
JSON
.
stringify
(
data
));
expect
(
data
).
assertInstanceOf
(
'
Array
'
)
}
});
}
catch
(
error
)
{
console
.
info
(
"
[NFC_test]mifareClassic4 readSingleBlock errorcode:
"
+
error
.
code
);
expect
(
401
).
assertEqual
(
error
.
code
)
}
sleep
(
3000
);
done
();
}
else
{
console
.
info
(
"
[NFC_test]MifareClassicTag4 = null & = undefined:
"
);
expect
(
true
).
assertFalse
();
}
})
/**
* @tc.number SUB_Communication_NFC_mifareClassic_js_0500
* @tc.name testwriteSingleBlock
* @tc.desc Test writeSingleBlock api. The error code is 401
* @tc.size MEDIUM
* @ since 9
* @tc.type Function
* @tc.level Level 2
*/
it
(
'
SUB_Communication_NFC_mifareClassic_js_0500
'
,
0
,
async
function
(
done
)
{
if
(
MifareClassicTag
!=
null
&&
MifareClassicTag
!=
undefined
)
{
let
blockIndex
=
1
;
let
rawData
=
[
0x0a
,
0x14
];
(
async
()
=>
{
try
{
let
result
=
await
MifareClassicTag
.
writeSingleBlock
(
'
test
'
,
rawData
);
console
.
info
(
"
[NFC_test]mifareClassic5 writeSingleBlock data:
"
+
result
);
}
catch
(
error
)
{
console
.
info
(
"
[NFC_test]mifareClassic5 writeSingleBlock errorcode:
"
+
error
.
code
);
expect
(
401
).
assertEqual
(
error
.
code
)
}
})();
sleep
(
3000
);
done
();
}
else
{
console
.
info
(
"
[NFC_test]MifareClassicTag5 = null & = undefined:
"
);
expect
(
true
).
assertFalse
();
}
})
/**
* @tc.number SUB_Communication_NFC_mifareClassic_js_0600
* @tc.name testwriteSingleBlock
* @tc.desc Test writeSingleBlock api. The error code is 401
* @tc.size MEDIUM
* @ since 9
* @tc.type Function
* @tc.level Level 2
*/
it
(
'
SUB_Communication_NFC_mifareClassic_js_0600
'
,
0
,
async
function
(
done
)
{
if
(
MifareClassicTag
!=
null
&&
MifareClassicTag
!=
undefined
)
{
let
blockIndex
=
1
;
let
rawData
=
[
0x0a
,
0x14
];
try
{
MifareClassicTag
.
writeSingleBlock
(
'
test
'
,
rawData
,
(
err
,
data
)
=>
{
if
(
err
)
{
console
.
info
(
"
[NFC_test]mifareClassic6 writeSingleBlock errcode:
"
+
err
);
expect
(
true
).
assertEqual
(
true
);
}
else
{
console
.
info
(
"
[NFC_test]mifareClassic6 writeSingleBlock data:
"
+
data
+
"
json6:
"
+
JSON
.
stringify
(
data
));
expect
(
data
).
assertTrue
();
}
});
}
catch
(
error
)
{
console
.
info
(
"
[NFC_test]mifareClassic6 errorcode:
"
+
error
.
code
);
expect
(
401
).
assertEqual
(
error
.
code
)
}
sleep
(
3000
);
done
();
}
else
{
console
.
info
(
"
[NFC_test]MifareClassicTag6 = null & = undefined:
"
);
expect
(
true
).
assertFalse
();
}
})
/**
* @tc.number SUB_Communication_NFC_mifareClassic_js_0700
* @tc.name testincrementBlock
* @tc.desc Test incrementBlock api. The error code is 401
* @tc.size MEDIUM
* @ since 9
* @tc.type Function
* @tc.level Level 2
*/
it
(
'
SUB_Communication_NFC_mifareClassic_js_0700
'
,
0
,
async
function
(
done
)
{
if
(
MifareClassicTag
!=
null
&&
MifareClassicTag
!=
undefined
)
{
let
blockIndex
=
1
;
let
value
=
0x20
;
(
async
()
=>
{
try
{
let
result
=
await
MifareClassicTag
.
incrementBlock
(
'
test
'
,
'
test
'
);
console
.
info
(
"
[NFC_test]mifareClassic7 incrementBlock data:
"
+
result
);
}
catch
(
error
)
{
console
.
info
(
"
[NFC_test]mifareClassic7 incrementBlock errorcode:
"
+
error
.
code
);
expect
(
401
).
assertEqual
(
error
.
code
)
}
})();
sleep
(
3000
);
done
();
}
else
{
console
.
info
(
"
[NFC_test]MifareClassicTag7 = null & = undefined:
"
);
expect
(
true
).
assertFalse
();
}
})
/**
* @tc.number SUB_Communication_NFC_mifareClassic_js_0800
* @tc.name testincrementBlock
* @tc.desc Test incrementBlock api. The error code is 401
* @tc.size MEDIUM
* @ since 9
* @tc.type Function
* @tc.level Level 2
*/
it
(
'
SUB_Communication_NFC_mifareClassic_js_0800
'
,
0
,
async
function
(
done
)
{
if
(
MifareClassicTag
!=
null
&&
MifareClassicTag
!=
undefined
)
{
let
blockIndex
=
1
;
let
value
=
0x20
;
try
{
MifareClassicTag
.
incrementBlock
(
blockIndex
,
'
test
'
,
(
err
,
data
)
=>
{
if
(
err
)
{
console
.
info
(
"
[NFC_test]mifareClassic8 incrementBlock errcode:
"
+
err
);
expect
(
true
).
assertEqual
(
true
);
}
else
{
console
.
info
(
"
[NFC_test]mifareClassic8 incrementBlock data:
"
+
data
);
expect
(
data
).
assertInstanceOf
(
'
Number
'
)
}
});
}
catch
(
error
)
{
console
.
info
(
"
[NFC_test]mifareClassic8 incrementBlock2 errorcode:
"
+
error
.
code
);
expect
(
401
).
assertEqual
(
error
.
code
)
}
sleep
(
3000
);
done
();
}
else
{
console
.
info
(
"
[NFC_test]MifareClassicTag8 = null & = undefined:
"
);
expect
(
true
).
assertFalse
();
}
})
/**
* @tc.number SUB_Communication_NFC_mifareClassic_js_0900
* @tc.name testdecrementBlock
* @tc.desc Test decrementBlock api. The error code is 401
* @tc.size MEDIUM
* @ since 9
* @tc.type Function
* @tc.level Level 2
*/
it
(
'
SUB_Communication_NFC_mifareClassic_js_0900
'
,
0
,
async
function
(
done
)
{
if
(
MifareClassicTag
!=
null
&&
MifareClassicTag
!=
undefined
)
{
let
blockIndex
=
1
;
let
value
=
0x20
;
(
async
()
=>
{
try
{
let
result
=
await
MifareClassicTag
.
decrementBlock
(
'
test
'
,
value
);
console
.
info
(
"
[NFC_test]mifareClassic9 decrementBlock data:
"
+
result
);
}
catch
(
error
)
{
console
.
info
(
"
[NFC_test]mifareClassic9 decrementBlock errorcode:
"
+
error
.
code
);
expect
(
401
).
assertEqual
(
error
.
code
)
}
})();
sleep
(
3000
);
done
();
}
else
{
console
.
info
(
"
[NFC_test]MifareClassicTag9 = null & = undefined:
"
);
expect
(
true
).
assertFalse
();
}
})
/**
* @tc.number SUB_Communication_NFC_mifareClassic_js_1000
* @tc.name testdecrementBlock
* @tc.desc Test decrementBlock api. The error code is 401
* @tc.size MEDIUM
* @ since 9
* @tc.type Function
* @tc.level Level 2
*/
it
(
'
SUB_Communication_NFC_mifareClassic_js_1000
'
,
0
,
async
function
(
done
)
{
if
(
MifareClassicTag
!=
null
&&
MifareClassicTag
!=
undefined
)
{
let
blockIndex
=
1
;
let
value
=
0x20
;
try
{
MifareClassicTag
.
decrementBlock
(
'
test
'
,
value
,
(
err
,
data
)
=>
{
if
(
err
)
{
console
.
info
(
"
[NFC_test]mifareClassic10 decrementBlock errcode:
"
+
err
);
expect
(
true
).
assertEqual
(
true
);
}
else
{
console
.
info
(
"
[NFC_test]mifareClassic10 decrementBlock data:
"
+
data
+
"
json10:
"
+
JSON
.
stringify
(
data
));
expect
(
data
).
assertInstanceOf
(
'
Number
'
)
}
});
}
catch
(
error
)
{
console
.
info
(
"
[NFC_test]mifareClassic10 decrementBlock errorcode:
"
+
error
.
code
);
expect
(
401
).
assertEqual
(
error
.
code
)
}
sleep
(
3000
);
done
();
}
else
{
console
.
info
(
"
[NFC_test]MifareClassicTag10 = null & = undefined:
"
);
expect
(
true
).
assertFalse
();
}
})
/**
* @tc.number SUB_Communication_NFC_mifareClassic_js_1100
* @tc.name testtransferToBlock
* @tc.desc Test transferToBlock api. The error code is 401
* @tc.size MEDIUM
* @ since 9
* @tc.type Function
* @tc.level Level 2
*/
it
(
'
SUB_Communication_NFC_mifareClassic_js_1100
'
,
0
,
async
function
(
done
)
{
if
(
MifareClassicTag
!=
null
&&
MifareClassicTag
!=
undefined
)
{
let
blockIndex
=
1
;
(
async
()
=>
{
try
{
let
result
=
await
MifareClassicTag
.
transferToBlock
(
'
test
'
);
console
.
info
(
"
[NFC_test]mifareClassic11 transferToBlock data:
"
+
result
);
}
catch
(
error
)
{
console
.
info
(
"
[NFC_test]mifareClassic11 transferToBlock errorcode:
"
+
error
.
code
);
expect
(
401
).
assertEqual
(
error
.
code
)
}
})();
sleep
(
3000
);
done
();
}
else
{
console
.
info
(
"
[NFC_test]MifareClassicTag11 = null & = undefined:
"
);
expect
(
true
).
assertFalse
();
}
})
/**
* @tc.number SUB_Communication_NFC_mifareClassic_js_1200
* @tc.name testtransferToBlock
* @tc.desc Test transferToBlock api. The error code is 401
* @tc.size MEDIUM
* @ since 9
* @tc.type Function
* @tc.level Level 2
*/
it
(
'
SUB_Communication_NFC_mifareClassic_js_1200
'
,
0
,
async
function
(
done
)
{
if
(
MifareClassicTag
!=
null
&&
MifareClassicTag
!=
undefined
)
{
let
blockIndex
=
1
;
try
{
MifareClassicTag
.
transferToBlock
(
'
test
'
,
(
err
,
data
)
=>
{
if
(
err
)
{
console
.
info
(
"
[NFC_test]mifareClassic12 transferToBlock errcode:
"
+
err
);
expect
(
true
).
assertEqual
(
true
);
}
else
{
console
.
info
(
"
[NFC_test]mifareClassic12 transferToBlock data:
"
+
data
+
"
json10:
"
+
JSON
.
stringify
(
data
));
expect
(
data
).
assertInstanceOf
(
'
Number
'
)
}
});
}
catch
(
error
)
{
console
.
info
(
"
[NFC_test]mifareClassic12 transferToBlock errorcode:
"
+
error
.
code
);
expect
(
401
).
assertEqual
(
error
.
code
)
}
sleep
(
3000
);
done
();
}
else
{
console
.
info
(
"
[NFC_test]MifareClassicTag12 = null & = undefined:
"
);
expect
(
true
).
assertFalse
();
}
})
/**
* @tc.number SUB_Communication_NFC_mifareClassic_js_1300
* @tc.name testrestoreFromBlock
* @tc.desc Test restoreFromBlock api. The error code is 401
* @tc.size MEDIUM
* @ since 9
* @tc.type Function
* @tc.level Level 2
*/
it
(
'
SUB_Communication_NFC_mifareClassic_js_1300
'
,
0
,
async
function
(
done
)
{
if
(
MifareClassicTag
!=
null
&&
MifareClassicTag
!=
undefined
)
{
let
blockIndex
=
1
;
(
async
()
=>
{
try
{
let
result
=
await
MifareClassicTag
.
restoreFromBlock
(
'
test
'
);
console
.
info
(
"
[NFC_test]mifareClassic13 restoreFromBlock data:
"
+
result
);
}
catch
(
error
)
{
console
.
info
(
"
[NFC_test]mifareClassic13 restoreFromBlock errorcode:
"
+
error
.
code
);
expect
(
401
).
assertEqual
(
error
.
code
)
}
})();
sleep
(
3000
);
done
();
}
else
{
console
.
info
(
"
[NFC_test]MifareClassicTag13 = null & = undefined:
"
);
expect
(
true
).
assertFalse
();
}
})
/**
* @tc.number SUB_Communication_NFC_mifareClassic_js_1400
* @tc.name testrestoreFromBlock
* @tc.desc Test restoreFromBlock api. The error code is 401
* @tc.size MEDIUM
* @ since 9
* @tc.type Function
* @tc.level Level 2
*/
it
(
'
SUB_Communication_NFC_mifareClassic_js_1400
'
,
0
,
async
function
(
done
)
{
if
(
MifareClassicTag
!=
null
&&
MifareClassicTag
!=
undefined
)
{
let
blockIndex
=
1
;
try
{
MifareClassicTag
.
restoreFromBlock
(
'
test
'
,
(
err
,
data
)
=>
{
if
(
err
)
{
console
.
info
(
"
[NFC_test]mifareClassic14 restoreFromBlock2 errcode:
"
+
err
);
expect
(
true
).
assertEqual
(
true
);
}
else
{
console
.
info
(
"
[NFC_test]mifareClassic14 restoreFromBlock2 data:
"
+
data
+
"
json12:
"
+
JSON
.
stringify
(
data
));
expect
(
data
).
assertInstanceOf
(
'
Number
'
)
}
});
}
catch
(
error
)
{
console
.
info
(
"
[NFC_test]mifareClassic14 restoreFromBlock2 errorcode:
"
+
error
.
code
);
expect
(
401
).
assertEqual
(
error
.
code
)
}
sleep
(
3000
);
done
();
}
else
{
console
.
info
(
"
[NFC_test]MifareClassicTag14 = null & = undefined:
"
);
expect
(
true
).
assertFalse
();
}
})
/**
* @tc.number SUB_Communication_NFC_mifareClassic_js_1500
* @tc.name testgetBlockCountInSector
* @tc.desc Test getBlockCountInSector api. The error code is 401
* @tc.size MEDIUM
* @ since 9
* @tc.type Function
* @tc.level Level 2
*/
it
(
'
SUB_Communication_NFC_mifareClassic_js_1500
'
,
0
,
function
()
{
if
(
MifareClassicTag
!=
null
&&
MifareClassicTag
!=
undefined
)
{
try
{
let
sectorIndex
=
1
;
let
blockCountInSector
=
MifareClassicTag
.
getBlockCountInSector
(
'
test
'
);
console
.
info
(
"
[NFC_test]mifareClassic15 getBlockCountInSector:
"
+
blockCountInSector
);
expect
(
blockCountInSector
).
assertInstanceOf
(
'
Number
'
)
}
catch
(
error
)
{
console
.
info
(
"
[NFC_test]mifareClassic15 getBlockCountInSector errorcode:
"
+
error
.
code
);
expect
(
401
).
assertEqual
(
error
.
code
)
}
}
else
{
console
.
info
(
"
[NFC_test]MifareClassicTag15 = null & = undefined:
"
);
expect
(
true
).
assertFalse
();
}
})
/**
* @tc.number SUB_Communication_NFC_mifareClassic_js_1600
* @tc.name testgetBlockIndex
* @tc.desc Test getBlockIndex api. The error code is 401
* @tc.size MEDIUM
* @ since 9
* @tc.type Function
* @tc.level Level 2
*/
it
(
'
SUB_Communication_NFC_mifareClassic_js_1600
'
,
0
,
function
()
{
if
(
MifareClassicTag
!=
null
&&
MifareClassicTag
!=
undefined
)
{
try
{
let
sectorIndex
=
1
;
let
blockIndex
=
MifareClassicTag
.
getBlockIndex
(
'
test
'
);
console
.
info
(
"
[NFC_test]mifareClassic16 getBlockIndex:
"
+
blockIndex
);
expect
(
true
).
assertTrue
(
blockIndex
>=
0
);
}
catch
(
error
)
{
console
.
info
(
"
[NFC_test]mifareClassic16 getBlockIndex errorcode:
"
+
error
.
code
);
expect
(
401
).
assertEqual
(
error
.
code
)
}
}
else
{
console
.
info
(
"
[NFC_test]MifareClassicTag16 = null & = undefined:
"
);
expect
(
true
).
assertFalse
();
}
})
/**
* @tc.number SUB_Communication_NFC_mifareClassic_js_1700
* @tc.name testgetSectorIndex
* @tc.desc Test getSectorIndex api. The error code is 401
* @tc.size MEDIUM
* @ since 9
* @tc.type Function
* @tc.level Level 2
*/
it
(
'
SUB_Communication_NFC_mifareClassic_js_1700
'
,
0
,
function
()
{
if
(
MifareClassicTag
!=
null
&&
MifareClassicTag
!=
undefined
)
{
try
{
let
blockIndex
=
1
;
let
sectorIndex
=
MifareClassicTag
.
getSectorIndex
(
'
test
'
);
console
.
info
(
"
[NFC_test]mifareClassic17 getSectorIndex:
"
+
sectorIndex
);
expect
(
true
).
assertTrue
(
sectorIndex
>=
0
);
}
catch
(
error
)
{
console
.
info
(
"
[NFC_test]mifareClassic17 getSectorIndex errorcode:
"
+
error
.
code
);
expect
(
401
).
assertEqual
(
error
.
code
)
}
}
else
{
console
.
info
(
"
[NFC_test]MifareClassicTag17 = null & = undefined:
"
);
expect
(
true
).
assertFalse
();
}
})
/**
* @tc.number SUB_Communication_NFC_mifareClassic_js_1800
* @tc.name getMifareClassic
* @tc.desc Test getMifareClassic api. The error code is 401
* @tc.size MEDIUM
* @ since 9
* @tc.type Function
* @tc.level Level 2
*/
it
(
'
SUB_Communication_NFC_mifareClassic_js_1800
'
,
0
,
function
()
{
if
(
MifareClassicTag
!=
null
&&
MifareClassicTag
!=
undefined
)
{
try
{
let
NFCMifareClassicTag
=
tag
.
getMifareClassic
(
"
test
"
);
console
.
info
(
"
[NFC_test]mifareClassic18 getMifareClassic:
"
+
NFCMifareClassicTag
);
expect
(
true
).
assertTrue
(
NFCMifareClassicTag
>=
0
);
}
catch
(
error
)
{
console
.
info
(
"
[NFC_test]mifareClassic18 getMifareClassic errorcode:
"
+
error
.
code
);
expect
(
401
).
assertEqual
(
error
.
code
)
}
}
else
{
console
.
info
(
"
[NFC_test]MifareClassicTag18 = null & = undefined:
"
);
expect
(
true
).
assertFalse
();
}
})
console
.
info
(
"
*************[nfc_test] start nfc js unit test end*************
"
);
})
}
communication/nfc_ErrorCode/src/main/js/test/error.MifareUltralightTag.js
0 → 100644
浏览文件 @
0cab7285
/*
* 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
tag
from
'
@ohos.nfc.tag
'
;
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
mifareUltralightTaginfo
=
{
"
uid
"
:
[
0x01
,
0x02
,
0x03
,
0x04
],
"
technology
"
:
[
1
,
9
],
"
extrasData
"
:
[
{
"
Sak
"
:
0x08
,
"
Atqa
"
:
"
B000
"
,
},
{
"
MifareUltralightC
"
:
"
ture
"
,
},
],
"
tagRfDiscId
"
:
1
,
};
let
MifareUltralightType
=
{
TYPE_UNKOWN
:
0x04
,
TYPE_ULTRALIGHT
:
1
,
TYPE_ULTRALIGHT_C
:
2
,
}
let
MifareUltralightTag
=
null
;
export
default
function
UltralightTagErrorTest
()
{
describe
(
'
UltralightTagErrorTest
'
,
function
()
{
beforeAll
(
function
()
{
console
.
info
(
'
beforeAll called
'
)
})
beforeEach
(
function
()
{
console
.
info
(
'
beforeEach called
'
)
try
{
MifareUltralightTag
=
tag
.
getMifareUltralight
(
mifareUltralightTaginfo
);
console
.
info
(
'
mifareUltralight is
'
+
mifareUltralight
)
}
catch
(
error
){
console
.
info
(
'
mifareUltralight error
'
+
error
)
}
})
afterEach
(
function
()
{
console
.
info
(
'
afterEach called
'
)
})
afterAll
(
function
()
{
console
.
info
(
'
afterAll called
'
)
})
/**
* @tc.number SUB_Communication_NFC_mifareUltralight_0100
* @tc.name testreadMultiplePages
* @tc.desc Test readMultiplePages api by promise. The error code is 401
* @tc.size MEDIUM
* @ since 9
* @tc.type Function
* @tc.level Level 2
*/
it
(
'
SUB_Communication_NFC_mifareUltralight_0100
'
,
0
,
async
function
(
done
)
{
if
(
MifareUltralightTag
!=
null
&&
MifareUltralightTag
!=
undefined
)
{
let
pageIndex
=
1
;
(
async
()
=>
{
try
{
let
result
=
await
MifareUltralightTag
.
readMultiplePages
(
'
test
'
);
console
.
info
(
"
[NFC_test]mifareUltralight1 readMultiplePages data:
"
+
result
);
}
catch
(
error
)
{
console
.
info
(
"
[NFC_test]mifareUltralight1 readMultiplePages errorcode:
"
+
error
.
code
);
expect
(
401
).
assertEqual
(
error
.
code
);
}
})();
sleep
(
3000
);
done
();
}
else
{
console
.
info
(
"
[NFC_test]mifareUltralight1 = null & = undefined:
"
);
expect
(
true
).
assertFalse
();
}
})
/**
* @tc.number SUB_Communication_NFC_mifareUltralight_0200
* @tc.name testreadMultiplePages
* @tc.desc Test readMultiplePages api by callback. The error code is 401
* @tc.size MEDIUM
* @ since 9
* @tc.type Function
* @tc.level Level 2
*/
it
(
'
SUB_Communication_NFC_mifareUltralight_0200
'
,
0
,
async
function
(
done
)
{
if
(
MifareUltralightTag
!=
null
&&
MifareUltralightTag
!=
undefined
)
{
let
pageIndex
=
1
;
try
{
MifareUltralightTag
.
readMultiplePages
(
'
test
'
,
(
err
,
data
)
=>
{
if
(
err
)
{
console
.
info
(
"
[NFC_test]mifareUltralight2 readMultiplePages errcode:
"
+
err
);
expect
(
true
).
assertEqual
(
true
);
}
else
{
console
.
info
(
"
[NFC_test]mifareUltralight2 readMultiplePages data:
"
+
data
+
"
json2:
"
+
JSON
.
stringify
(
data
));
expect
(
true
).
assertTrue
(
data
>=
0
);
}
});
}
catch
(
error
)
{
console
.
info
(
"
[NFC_test]mifareUltralight2 readMultiplePages errorcode:
"
+
error
.
code
);
expect
(
401
).
assertEqual
(
error
.
code
);
}
sleep
(
3000
);
done
();
}
else
{
console
.
info
(
"
[NFC_test]mifareUltralight2 = null & = undefined:
"
);
expect
(
true
).
assertFalse
();
}
})
/**
* @tc.number SUB_Communication_NFC_mifareUltralight_0300
* @tc.name testwriteSinglePage
* @tc.desc Test writeSinglePage api by promise. The error code is 401
* @tc.size MEDIUM
* @ since 7
* @tc.type Function
* @tc.level Level 2
*/
it
(
'
SUB_Communication_NFC_mifareUltralight_0300
'
,
0
,
async
function
(
done
)
{
if
(
MifareUltralightTag
!=
null
&&
MifareUltralightTag
!=
undefined
)
{
let
pageIndex
=
1
;
let
rawData
=
[
0x01
,
0x02
];
(
async
()
=>
{
try
{
let
result
=
await
MifareUltralightTag
.
writeSinglePage
(
'
test
'
,
rawData
);
console
.
info
(
"
[NFC_test]mifareUltralight3 writeSinglePage data:
"
+
result
);
}
catch
(
error
)
{
console
.
info
(
"
[NFC_test]mifareUltralight3 writeSinglePage errorcode:
"
+
error
.
code
);
expect
(
401
).
assertEqual
(
error
.
code
);
}
})();
sleep
(
3000
);
done
();
}
else
{
console
.
info
(
"
[NFC_test]mifareUltralight3 = null & = undefined:
"
);
expect
(
true
).
assertFalse
();
}
})
/**
* @tc.number SUB_Communication_NFC_mifareUltralight_0400
* @tc.name testwriteSinglePage
* @tc.desc Test writeSinglePage api by callback. The error code is 401
* @tc.size MEDIUM
* @ since 7
* @tc.type Function
* @tc.level Level 2
*/
it
(
'
SUB_Communication_NFC_mifareUltralight_0400
'
,
0
,
async
function
(
done
)
{
if
(
MifareUltralightTag
!=
null
&&
MifareUltralightTag
!=
undefined
)
{
let
pageIndex
=
1
;
let
rawData
=
[
0x01
,
0x02
];
try
{
MifareUltralightTag
.
writeSinglePage
(
'
test
'
,
rawData
,
(
err
,
data
)
=>
{
if
(
err
)
{
console
.
log
(
"
[NFC_test]mifareUltralight4 writeSinglePage errcode:
"
+
err
);
expect
(
true
).
assertEqual
(
true
);
}
else
{
console
.
log
(
"
[NFC_test]mifareUltralight4 writeSinglePage data:
"
+
data
+
"
json2:
"
+
JSON
.
stringify
(
data
));
expect
(
true
).
assertTrue
(
data
>=
0
);
}
});
}
catch
(
error
)
{
console
.
info
(
"
[NFC_test]mifareUltralight4 writeSinglePage errorcode:
"
+
error
.
code
);
expect
(
401
).
assertEqual
(
error
.
code
);
}
sleep
(
3000
);
done
();
}
else
{
console
.
info
(
"
[NFC_test]mifareUltralight4 = null & = undefined:
"
);
expect
(
true
).
assertFalse
();
}
})
/**
* @tc.number SUB_Communication_NFC_mifareUltralight_0500
* @tc.name getMifareUltralight
* @tc.desc Test getMifareUltralight api. The error code is 401
* @tc.size MEDIUM
* @ since 9
* @tc.type Function
* @tc.level Level 2
*/
it
(
'
SUB_Communication_NFC_mifareUltralight_0500
'
,
0
,
function
()
{
if
(
MifareUltralightTag
!=
null
&&
MifareUltralightTag
!=
undefined
)
{
try
{
let
nfcMifareUltralightTag
=
tag
.
getMifareUltralight
(
"
test
"
);
console
.
info
(
"
[NFC_test]mifareUltralight5 getMifareUl:
"
+
nfcMifareUltralightTag
);
}
catch
(
error
)
{
console
.
info
(
"
[NFC_test]mifareUltralight5 getMifareUl errorcode:
"
+
error
.
code
);
expect
(
401
).
assertEqual
(
error
.
code
)
}
}
else
{
console
.
info
(
"
[NFC_test]mifareUltralight5 = null & = undefined:
"
);
expect
(
true
).
assertFalse
();
}
})
console
.
info
(
"
*************[nfc_test] start nfc js unit test end*************
"
);
})
}
communication/nfc_ErrorCode/src/main/js/test/error.NDEFTag.js
0 → 100644
浏览文件 @
0cab7285
/*
* 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
tag
from
'
@ohos.nfc.tag
'
;
import
cardEmulation
from
'
@ohos.nfc.cardEmulation
'
;
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
NdefRecord
=
{
NFC_A
:
1
,
NFC_B
:
2
,
ISO_DEP
:
3
,
NFC_F
:
4
,
NFC_V
:
5
,
NDEF
:
6
,
NDEF_FORMATABLE
:
7
,
MIFARE_CLASSIC
:
8
,
MIFARE_ULTRALIGHT
:
9
,
};
let
NfcForumType
=
{
NFC_FORUM_TYPE_1
:
1
,
NFC_FORUM_TYPE_2
:
2
,
NFC_FORUM_TYPE_3
:
3
,
NFC_FORUM_TYPE_4
:
4
,
MIFARE_CLASSIC
:
101
,
};
let
TnfType
=
{
TNF_EMPTY
:
0x0
,
TNF_WELL_KNOWN
:
0x01
,
TNF_MEDIA
:
0x02
,
TNF_ABSOLUTE_URI
:
0x03
,
TNF_EXT_APP
:
0x04
,
TNF_UNKNOWN
:
0x05
,
TNF_UNCHANGED
:
0x06
,
};
let
NDEFRecordRTD
=
{
RTD_TEXT
:
0x54
,
RTD_URI
:
0x55
,
}
let
NDEFTaginfo
=
{
"
uid
"
:
[
0x01
,
0x02
,
0x03
,
0x04
],
"
technology
"
:
[
1
,
6
],
"
extrasData
"
:
[
{
"
Sak
"
:
0x08
,
"
Atqa
"
:
"
B000
"
,
},
{
"
NdefMsg
"
:
"
D4010354787473
"
,
"
NdefForumType
"
:
1
,
"
NdefTagLength
"
:
255
,
"
NdefTagMode
"
:
1
,
},
],
"
tagRfDiscId
"
:
1
,
};
let
FeatureType
=
{
HCE
:
0
,
UICC
:
0
,
ESE
:
0
,
};
let
NdefFormatableTag
=
{
"
uid
"
:
[
0x01
,
0x02
,
0x03
,
0x04
],
"
technology
"
:
[
1
,
7
],
"
extrasData
"
:
[
{
"
Sak
"
:
0x08
,
"
Atqa
"
:
"
B000
"
,
},
{
},
],
"
tagRfDiscId
"
:
1
,
};
let
NdefTag
;
export
default
function
nfcNDEFErrorTest
()
{
describe
(
'
nfcNDEFErrorTest
'
,
function
()
{
beforeAll
(
function
()
{
console
.
info
(
'
beforeAll called
'
)
})
beforeEach
(
function
()
{
console
.
info
(
'
beforeEach called
'
)
try
{
NdefTag
=
tag
.
getNdef
(
NDEFTaginfo
);
}
catch
(
error
){
console
.
info
(
'
SUB_Communication_NFC_nfcNDEF_js_0800 error
'
+
error
)
}
})
afterEach
(
function
()
{
console
.
info
(
'
afterEach called
'
)
})
afterAll
(
function
()
{
console
.
info
(
'
afterAll called
'
)
})
/**
* @tc.number SUB_Communication_NFC_nfcNDEF_js_0100
* @tc.name Test createNdefMessage NDEF
* @tc.desc Creates an ndef message using the original bytes. The error code is 401
* @tc.size since 9
* @tc.type Function
* @tc.level Level 2
*/
it
(
'
SUB_Communication_NFC_nfcNDEF_js_0100
'
,
0
,
function
()
{
if
(
NdefTag
!=
null
&&
NdefTag
!=
undefined
)
{
let
rawData
=
[
0xD1
,
0x01
,
0x03
,
0x54
,
0x4E
,
0x46
,
0x43
];
let
ndefMessage
;
try
{
ndefMessage
=
tag
.
ndef
.
createNdefMessage
(
'
test
'
);
expect
(
ndefMessage
!=
null
).
assertTrue
();
expect
(
ndefMessage
instanceof
Object
).
assertTrue
();
console
.
info
(
"
[NFC_test]ndef1 createNdefMessage:
"
+
ndefMessage
);
}
catch
(
error
){
console
.
info
(
"
[NFC_test]ndef1 createNdefMessage errorcode:
"
+
error
.
code
);
expect
(
401
).
assertEqual
(
error
.
code
);
}
sleep
(
3000
);
}
else
{
console
.
info
(
"
[NFC_test]NdefTag1 = null & = undefined:
"
);
expect
(
true
).
assertFalse
();
}
})
/**
* @tc.number SUB_Communication_NFC_nfcNDEF_js_0200
* @tc.name Test createNdefMessage NDEF
* @tc.desc Creates an ndef message using the original bytes. The error code is 401
* @tc.size since 9
* @tc.type Function
* @tc.level Level 2
*/
it
(
'
SUB_Communication_NFC_nfcNDEF_js_0200
'
,
0
,
function
()
{
if
(
NdefTag
!=
null
&&
NdefTag
!=
undefined
)
{
let
ndefRecords
=
[
{
tnf
:
0x01
,
rtdType
:
[
0x54
],
id
:
[
0x01
,
0x02
],
payload
:
[
0x00
,
0xa4
,
0x04
]},
{
tnf
:
0x02
,
rtdType
:
[
0x55
],
id
:
[
0x03
,
0x04
],
payload
:
[
0x00
,
0xa4
,
0x04
]},
];
let
ndefMessage
;
try
{
ndefMessage
=
tag
.
ndef
.
createNdefMessage
(
'
test
'
);
if
(
ndefMessage
!=
null
&&
ndefMessage
!=
undefined
)
{
console
.
info
(
"
[NFC_test]ndef2 ndefMessage:
"
+
ndefMessage
);
expect
(
ndefMessage
!=
null
).
assertTrue
();
expect
(
ndefMessage
instanceof
Object
).
assertTrue
();
}
else
{
console
.
info
(
"
[NFC_test]ndef2 ndefMessage:
"
+
error
);
}
}
catch
(
error
){
console
.
info
(
"
[NFC_test]ndef2 createNdefMessage errorcode:
"
+
error
.
code
);
expect
(
401
).
assertEqual
(
error
.
code
);
}
sleep
(
3000
);
}
else
{
console
.
info
(
"
[NFC_test]NdefTag2 = null & = undefined:
"
);
expect
(
true
).
assertFalse
();
}
})
/**
* @tc.number SUB_Communication_NFC_nfcNDEF_js_0300
* @tc.name Test readNdef NDEF
* @tc.desc Read the ndef message on the tag promise. The error code is 401
* @tc.size since 9
* @tc.type Function
* @tc.level Level 2
*/
it
(
'
SUB_Communication_NFC_nfcNDEF_js_0300
'
,
0
,
async
function
(
done
)
{
if
(
NdefTag
!=
null
&&
NdefTag
!=
undefined
)
{
(
async
()
=>
{
try
{
let
result
=
await
NdefTag
.
readNdef
(
'
test
'
);
console
.
info
(
"
[NFC_test]ndef3 readNdef data:
"
+
result
);
}
catch
(
error
)
{
console
.
info
(
"
[NFC_test]ndef3 readNdef errorcode:
"
+
error
.
code
);
expect
(
401
).
assertEqual
(
error
.
code
);
}
})();
sleep
(
3000
);
done
();
}
else
{
console
.
info
(
"
[NFC_test]NdefTag3 = null & = undefined:
"
);
expect
(
true
).
assertFalse
();
}
})
/**
* @tc.number SUB_Communication_NFC_nfcNDEF_js_0400
* @tc.name Test readNdef NDEF
* @tc.desc Read the ndef message on the tag callback .The error code is 401
* @tc.size since 9
* @tc.type Function
* @tc.level Level 2
*/
it
(
'
SUB_Communication_NFC_nfcNDEF_js_0400
'
,
0
,
async
function
(
done
)
{
if
(
NdefTag
!=
null
&&
NdefTag
!=
undefined
)
{
try
{
NdefTag
.
readNdef
(
'
test
'
)((
err
,
data
)
=>
{
if
(
err
)
{
expect
(
true
).
assertEqual
(
true
);
console
.
info
(
"
[NFC_test]ndef4 readNdef errcode:
"
+
err
);
}
else
{
expect
(
data
!=
true
).
assertTrue
();
console
.
info
(
"
[NFC_test]ndef4 readNdef data:
"
+
data
);
}
});
}
catch
(
error
)
{
console
.
info
(
"
[NFC_test]ndef4 readNdef errorcode:
"
+
error
.
code
);
expect
(
401
).
assertEqual
(
error
.
code
);
}
done
();
sleep
(
3000
);
}
else
{
console
.
info
(
"
[NFC_test]NdefTag4 = null & = undefined:
"
);
expect
(
true
).
assertFalse
();
}
})
/**
* @tc.number SUB_Communication_NFC_nfcNDEF_js_0500
* @tc.name Test writeNdef NDEF
* @tc.desc Write ndef messages to this tag promise. The error code is 401
* @tc.size since 9
* @tc.type Function
* @tc.level Level 2
*/
it
(
'
SUB_Communication_NFC_nfcNDEF_js_0500
'
,
0
,
async
function
(
done
)
{
if
(
NdefTag
!=
null
&&
NdefTag
!=
undefined
)
{
let
rawData
=
[
0xD1
,
0x01
,
0x03
,
0x54
,
0x4E
,
0x46
,
0x43
];
let
ndefMessage
=
tag
.
ndef
.
createNdefMessage
(
rawData
);
(
async
()
=>
{
try
{
let
result
=
await
NdefTag
.
writeNdef
(
'
test
'
);
console
.
info
(
"
[NFC_test]ndef5 writeNdef data:
"
+
result
);
}
catch
(
error
)
{
console
.
info
(
"
[NFC_test]ndef5 writeNdef errorcode:
"
+
error
.
code
);
expect
(
401
).
assertEqual
(
error
.
code
);
}
})();
sleep
(
3000
);
done
();
}
else
{
console
.
info
(
"
[NFC_test]NdefTag5 = null & = undefined:
"
);
expect
(
true
).
assertFalse
();
}
})
/**
* @tc.number SUB_Communication_NFC_nfcNDEF_js_0600
* @tc.name Test writeNdef NDEF
* @tc.desc Write ndef messages to this tag callback. The error code is 401
* @tc.size since 9
* @tc.type Function
* @tc.level Level 2
*/
it
(
'
SUB_Communication_NFC_nfcNDEF_js_0600
'
,
0
,
async
function
(
done
)
{
if
(
NdefTag
!=
null
&&
NdefTag
!=
undefined
)
{
let
rawData
=
[
0xD1
,
0x01
,
0x03
,
0x54
,
0x4E
,
0x46
,
0x43
];
let
ndefMessage
=
tag
.
ndef
.
createNdefMessage
(
rawData
);
try
{
NdefTag
.
writeNdef
(
'
test
'
,
(
err
,
data
)
=>
{
if
(
err
)
{
console
.
info
(
"
[NFC_test]ndef6 writeNdef errcode:
"
+
err
);
expect
(
true
).
assertEqual
(
true
);
}
else
{
expect
(
data
).
assertInstanceOf
(
'
Number
'
)
console
.
info
(
"
[NFC_test]ndef6 writeNdef data:
"
+
data
);
}
});
}
catch
(
error
)
{
console
.
info
(
"
[NFC_test]ndef6 writeNdef errorcode:
"
+
error
.
code
);
expect
(
401
).
assertEqual
(
error
.
code
);
}
done
();
sleep
(
3000
);
}
else
{
console
.
info
(
"
[NFC_test]NdefTag6 = null & = undefined:
"
);
expect
(
true
).
assertFalse
();
}
})
/**
* @tc.number SUB_Communication_NFC_nfcNDEF_js_0700
* @tc.name Test setReadOnly NDEF
* @tc.desc Set the Ndef label to read-only Promise. The error code is 401
* @tc.size since 9
* @tc.type Function
* @tc.level Level 2
*/
it
(
'
SUB_Communication_NFC_nfcNDEF_js_0700
'
,
0
,
async
function
(
done
)
{
if
(
NdefTag
!=
null
&&
NdefTag
!=
undefined
)
{
(
async
()
=>
{
try
{
let
result
=
await
NdefTag
.
setReadOnly
(
'
test
'
);
console
.
info
(
"
[NFC_test]ndef7 setReadOnly data:
"
+
result
);
}
catch
(
error
)
{
console
.
info
(
"
[NFC_test]ndef7 setReadOnly errorcode:
"
+
error
.
code
);
expect
(
401
).
assertEqual
(
error
.
code
);
}
})();
sleep
(
3000
);
done
();
}
else
{
console
.
info
(
"
[NFC_test]NdefTag7 = null & = undefined:
"
);
expect
(
true
).
assertFalse
();
}
})
/**
* @tc.number SUB_Communication_NFC_nfcNDEF_js_0800
* @tc.name Test setReadOnly NDEF
* @tc.desc Set the Ndef label to read-only callback. The error code is 401
* @tc.size since 9
* @tc.type Function
* @tc.level Level 2
*/
it
(
'
SUB_Communication_NFC_nfcNDEF_js_0800
'
,
0
,
async
function
(
done
)
{
if
(
NdefTag
!=
null
&&
NdefTag
!=
undefined
)
{
try
{
NdefTag
.
setReadOnly
(
'
test
'
)((
err
,
data
)
=>
{
if
(
err
)
{
expect
(
true
).
assertEqual
(
true
);
console
.
info
(
"
[NFC_test]ndef8 setReadOnly errcode:
"
+
err
);
}
else
{
expect
(
data
).
assertInstanceOf
(
'
Number
'
)
console
.
info
(
"
[NFC_test]ndef8 setReadOnly data:
"
+
data
);
}
});
}
catch
(
error
)
{
console
.
info
(
"
[NFC_test]ndef8 setReadOnly errorcode:
"
+
error
.
code
);
expect
(
401
).
assertEqual
(
error
.
code
);
}
done
();
sleep
(
3000
);
}
else
{
console
.
info
(
"
[NFC_test]NdefTag8 = null & = undefined:
"
);
expect
(
true
).
assertFalse
();
}
})
/**
* @tc.number SUB_Communication_NFC_nfcNDEF_js_0900
* @tc.name getNdef
* @tc.desc Test getNdef api. The error code is 401
* @tc.size MEDIUM
* @ since 9
* @tc.type Function
* @tc.level Level 2
*/
it
(
'
SUB_Communication_NFC_nfcNDEF_js_0900
'
,
0
,
function
()
{
if
(
NdefTag
!=
null
&&
NdefTag
!=
undefined
)
{
try
{
let
nfcNdefTag
=
tag
.
getNdef
(
"
test
"
);
console
.
info
(
"
[NFC_test]ndef9 getNdef:
"
+
nfcNdefTag
);
}
catch
(
error
)
{
console
.
info
(
"
[NFC_test]ndef9 getNdef errorcode:
"
+
error
.
code
);
expect
(
401
).
assertEqual
(
error
.
code
)
}
}
else
{
console
.
info
(
"
[NFC_test]NdefTag9 = null & = undefined:
"
);
expect
(
true
).
assertFalse
();
}
})
/**
* @tc.number SUB_Communication_NFC_nfcNDEF_js_1000
* @tc.name Test getNdefTagTypeString NDEF
* @tc.desc Converts the Nfc forum type to the byte array defined in the Nfc forum. The error code is 401
* @tc.size since 9
* @tc.type Function
* @tc.level Level 2
*/
it
(
'
SUB_Communication_NFC_nfcNDEF_js_1000
'
,
0
,
function
()
{
if
(
NdefTag
!=
null
&&
NdefTag
!=
undefined
)
{
try
{
let
ndefTypeString
=
NdefTag
.
getNdefTagTypeString
(
'
test
'
);
console
.
info
(
"
[NFC_test]ndef10 ndefTypeString:
"
+
JSON
.
stringify
(
ndefTypeString
));
expect
(
ndefTypeString
.
length
>=
0
).
assertTrue
();
}
catch
(
error
)
{
console
.
info
(
"
[NFC_test]ndef10 ndefTypeString errorcode:
"
+
error
.
code
);
expect
(
401
).
assertEqual
(
error
.
code
);
}
}
else
{
console
.
info
(
"
[NFC_test]NdefTag10 = null & = undefined:
"
);
expect
(
true
).
assertFalse
();
}
})
/**
* @tc.number SUB_Communication_NFC_nfcNDEF_js_1100
* @tc.name Test createNdefMessage NDEF
* @tc.desc Formats the tag as an NDEF tag and writes the NDEF message to the NDEF tag Promise. The error code is 401
* @tc.size since 9
* @tc.type Function
* @tc.level Level 2
*/
it
(
'
SUB_Communication_NFC_nfcNDEF_js_1100
'
,
0
,
async
function
(
done
)
{
if
(
NdefTag
!=
null
&&
NdefTag
!=
undefined
)
{
let
rawData
=
[
0xD1
,
0x01
,
0x03
,
0x54
,
0x4E
,
0x46
,
0x43
];
let
ndefmessage
=
tag
.
ndef
.
createNdefMessage
(
rawData
);
let
NdefFormatable
=
tag
.
getNdefFormatable
(
NdefFormatableTag
);
(
async
()
=>
{
try
{
let
result
=
await
NdefFormatable
.
format
(
'
test
'
);
console
.
info
(
"
[NFC_test]ndef11 format data:
"
+
result
);
}
catch
(
error
)
{
console
.
info
(
"
[NFC_test]ndef11 format errorcode:
"
+
error
.
code
);
expect
(
401
).
assertEqual
(
error
.
code
);
}
})();
sleep
(
3000
);
done
();
}
else
{
console
.
info
(
"
[NFC_test]NdefTag11 = null & = undefined:
"
);
expect
(
true
).
assertFalse
();
}
})
/**
* @tc.number SUB_Communication_NFC_nfcNDEF_js_1200
* @tc.name Test createNdefMessage NDEF
* @tc.desc Formats the tag as an NDEF tag and writes the NDEF message to the NDEF tag callback. The error code is 401
* @tc.size since 9
* @tc.type Function
* @tc.level Level 2
*/
it
(
'
SUB_Communication_NFC_nfcNDEF_js_1200
'
,
0
,
async
function
(
done
)
{
if
(
NdefTag
!=
null
&&
NdefTag
!=
undefined
)
{
let
rawData
=
[
0xD1
,
0x01
,
0x03
,
0x54
,
0x4E
,
0x46
,
0x43
];
let
ndefmessage
=
tag
.
ndef
.
createNdefMessage
(
rawData
);
let
NdefFormatable
=
tag
.
getNdefFormatable
(
NdefFormatableTag
);
try
{
NdefFormatable
.
format
(
'
test
'
,
(
err
,
data
)
=>
{
if
(
err
)
{
console
.
log
(
"
[NFC_test]ndef12 format errcode:
"
+
err
);
expect
(
true
).
assertTrue
();
}
else
{
console
.
info
(
"
[NFC_test]ndef12 format formatReadOnly2
"
);
}
});
}
catch
(
error
)
{
console
.
info
(
"
[NFC_test]ndef12 format errorcode:
"
+
error
.
code
);
expect
(
401
).
assertEqual
(
error
.
code
);
}
sleep
(
3000
);
done
();
}
else
{
console
.
info
(
"
[NFC_test]NdefTag12 = null & = undefined:
"
);
expect
(
true
).
assertFalse
();
}
})
/**
* @tc.number SUB_Communication_NFC_nfcNDEF_js_1300
* @tc.name Test formatReadOnly NDEF
* @tc.desc Format as NDEF and set the NDEF message write label to read-only Promise. The error code is 401
* @tc.size since 9
* @tc.type Function
* @tc.level Level 2
*/
it
(
'
SUB_Communication_NFC_nfcNDEF_js_1300
'
,
0
,
async
function
(
done
)
{
if
(
NdefTag
!=
null
&&
NdefTag
!=
undefined
)
{
let
rawData
=
[
0xD1
,
0x01
,
0x03
,
0x54
,
0x4E
,
0x46
,
0x43
];
let
ndefmessage
=
tag
.
ndef
.
createNdefMessage
(
rawData
);
let
NdefFormatable
=
tag
.
getNdefFormatable
(
NdefFormatableTag
);
(
async
()
=>
{
try
{
let
result
=
await
NdefFormatable
.
formatReadOnly
(
'
test
'
);
console
.
info
(
"
[NFC_test]ndef13 formatReadOnly data:
"
+
result
);
}
catch
(
error
)
{
console
.
info
(
"
[NFC_test]ndef13 formatReadOnly errorcode:
"
+
error
.
code
);
expect
(
401
).
assertEqual
(
error
.
code
);
}
})();
sleep
(
3000
);
done
();
}
else
{
console
.
info
(
"
[NFC_test]NdefTag13 = null & = undefined:
"
);
expect
(
true
).
assertFalse
();
}
})
/**
* @tc.number SUB_Communication_NFC_nfcNDEF_js_1400
* @tc.name Test formatReadOnly NDEF
* @tc.desc Format as NDEF and set the NDEF message write label to read-only callback. The error code is 401
* @tc.size since 9
* @tc.type Function
* @tc.level Level 2
*/
it
(
'
SUB_Communication_NFC_nfcNDEF_js_1400
'
,
0
,
async
function
(
done
)
{
if
(
NdefTag
!=
null
&&
NdefTag
!=
undefined
)
{
let
rawData
=
[
0xD1
,
0x01
,
0x03
,
0x54
,
0x4E
,
0x46
,
0x43
];
let
ndefmessage
=
tag
.
ndef
.
createNdefMessage
(
rawData
);
let
NdefFormatable
=
tag
.
getNdefFormatable
(
NdefFormatableTag
);
try
{
NdefFormatable
.
formatReadOnly
(
'
test
'
,
(
err
,
data
)
=>
{
if
(
err
)
{
console
.
info
(
"
[NFC_test]ndef14 formatReadOnly errcode:
"
+
err
);
expect
(
true
).
assertTrue
();
}
else
{
console
.
info
(
"
[NFC_test]ndef14 formatReadOnly
"
+
data
);
}
});
}
catch
(
error
)
{
console
.
info
(
"
[NFC_test]ndef14 formatReadOnly2 errorcode:
"
+
error
.
code
);
expect
(
401
).
assertEqual
(
error
.
code
);
}
done
();
}
else
{
console
.
info
(
"
[NFC_test]NdefTag14 = null & = undefined:
"
);
expect
(
true
).
assertFalse
();
}
})
/**
* @tc.number SUB_Communication_NFC_nfcNDEF_js_1500
* @tc.name Test makeUriRecord NDEF
* @tc.desc Obtains all records of ndef makeUriRecord. The error code is 401
* @tc.size since 9
* @tc.type Function
* @tc.level Level 2
*/
it
(
'
SUB_Communication_NFC_nfcNDEF_js_1500
'
,
0
,
function
()
{
if
(
NdefTag
!=
null
&&
NdefTag
!=
undefined
)
{
let
rawData
=
[
0xD1
,
0x01
,
0x03
,
0x54
,
0x4E
,
0x46
,
0x43
];
try
{
let
ndefMessage
=
tag
.
ndef
.
createNdefMessage
(
'
test
'
);
console
.
info
(
"
[NFC_test]ndef15 createNdefMessage result:
"
+
JSON
.
stringify
(
ndefMessage
));
}
catch
(
error
){
console
.
info
(
"
[NFC_test]ndef15 createNdefMessage errorcode:
"
+
error
.
code
);
expect
(
401
).
assertEqual
(
error
.
code
);
};
try
{
let
makeRecords
=
tag
.
ndef
.
makeUriRecord
(
"
D4010354787473
"
);
console
.
info
(
"
[NFC_test]ndef15 makeUriRecord result:
"
+
JSON
.
stringify
(
'
test
'
));
expect
(
JSON
.
stringify
(
makeRecords
)
!=
null
).
assertTrue
();
}
catch
(
error
){
console
.
info
(
"
[NFC_test]ndef15 makeUriRecord errorcode:
"
+
error
.
code
);
expect
(
401
).
assertEqual
(
error
.
code
);
}
}
else
{
console
.
info
(
"
[NFC_test]NdefTag15 = null & = undefined:
"
);
expect
(
true
).
assertFalse
();
}
})
/**
* @tc.number SUB_Communication_NFC_nfcNDEF_js_1600
* @tc.name Test createNdefMessage NDEF
* @tc.desc Obtains all records of createNdefMessage NDEF. The error code is 401
* @tc.size since 9
* @tc.type Function
* @tc.level Level 2
*/
it
(
'
SUB_Communication_NFC_nfcNDEF_js_1600
'
,
0
,
function
()
{
if
(
NdefTag
!=
null
&&
NdefTag
!=
undefined
)
{
let
rawData
=
[
0xD1
,
0x01
,
0x03
,
0x54
,
0x4E
,
0x46
,
0x43
];
try
{
let
ndefMessage
=
tag
.
ndef
.
createNdefMessage
(
'
test
'
);
console
.
info
(
"
[NFC_test]ndef16 createNdefMessage result:
"
+
JSON
.
stringify
(
ndefMessage
));
}
catch
(
error
){
console
.
info
(
"
[NFC_test]ndef16 createNdefMessage errorcode:
"
+
error
.
code
);
expect
(
401
).
assertEqual
(
error
.
code
);
}
try
{
let
makeTRecords
=
tag
.
ndef
.
makeTextRecord
(
[
0x01
,
0x02
],
"
test
"
);
console
.
info
(
"
[NFC_test]ndef16 makeTextRecord result:
"
+
JSON
.
stringify
(
makeTRecords
));
expect
(
JSON
.
stringify
(
makeTRecords
)
!=
null
).
assertTrue
();
}
catch
(
error
){
console
.
info
(
"
[NFC_test]ndef16 makeTextRecord errorcode:
"
+
error
.
code
);
expect
(
401
).
assertEqual
(
error
.
code
);
}
}
else
{
console
.
info
(
"
[NFC_test]NdefTag16 = null & = undefined:
"
);
expect
(
true
).
assertFalse
();
}
})
/**
* @tc.number SUB_Communication_NFC_nfcNDEF_js_1700
* @tc.name Test makeMimeRecord NDEF
* @tc.desc Obtains all records of ndef makeMimeRecord. The error code is 401
* @tc.size since 9
* @tc.type Function
* @tc.level Level 2
*/
it
(
'
SUB_Communication_NFC_nfcNDEF_js_1700
'
,
0
,
function
()
{
if
(
NdefTag
!=
null
&&
NdefTag
!=
undefined
)
{
let
rawData
=
[
0xD1
,
0x01
,
0x03
,
0x54
,
0x4E
,
0x46
,
0x43
];
try
{
let
ndefMessage
=
tag
.
ndef
.
createNdefMessage
(
'
test
'
);
console
.
info
(
"
[NFC_test]ndef17 createNdefMessage result:
"
+
JSON
.
stringify
(
ndefMessage
));
}
catch
(
error
){
console
.
info
(
"
[NFC_test]ndef17 createNdefMessage errorcode:
"
+
error
.
code
);
expect
(
401
).
assertEqual
(
error
.
code
);
}
try
{
let
makeMRecords
=
tag
.
ndef
.
makeMimeRecord
(
[
0x01
,
0x02
],
"
0112
"
);
console
.
info
(
"
[NFC_test]ndef17 makeMimeRecord result:
"
+
JSON
.
stringify
(
makeMRecords
));
expect
(
JSON
.
stringify
(
makeMRecords
)
!=
null
).
assertTrue
();
}
catch
(
error
){
console
.
info
(
"
[NFC_test]ndef17 makeMimeRecord errorcode:
"
+
error
.
code
);
expect
(
401
).
assertEqual
(
error
.
code
);
}
}
else
{
console
.
info
(
"
[NFC_test]NdefTag17 = null & = undefined:
"
);
expect
(
true
).
assertFalse
();
}
})
/**
* @tc.number SUB_Communication_NFC_nfcNDEF_js_1800
* @tc.name Test makeExternalRecord NDEF
* @tc.desc Obtains all records of ndef makeExternalRecord. The error code is 401
* @tc.size since 9
* @tc.type Function
* @tc.level Level 2
*/
it
(
'
SUB_Communication_NFC_nfcNDEF_js_1800
'
,
0
,
function
()
{
if
(
NdefTag
!=
null
&&
NdefTag
!=
undefined
)
{
let
rawData
=
[
0xD1
,
0x01
,
0x03
,
0x54
,
0x4E
,
0x46
,
0x43
];
try
{
let
ndefMessage
=
tag
.
ndef
.
createNdefMessage
(
'
test
'
);
console
.
info
(
"
[NFC_test]ndef18 createNdefMessage result:
"
+
JSON
.
stringify
(
ndefMessage
));
}
catch
(
error
){
console
.
info
(
"
[NFC_test]ndef18 createNdefMessage errorcode:
"
+
error
.
code
);
expect
(
401
).
assertEqual
(
error
.
code
);
}
try
{
let
makeERecords
=
tag
.
ndef
.
makeExternalRecord
(
[
0x01
,
0x02
],
"
NFCtest
"
,
[
0x01
,
0x02
]);
console
.
info
(
"
[NFC_test]ndef18 makeExternalRecord result:
"
+
JSON
.
stringify
(
makeERecords
));
expect
(
makeERecords
instanceof
Object
).
assertTrue
();
}
catch
(
error
){
console
.
info
(
"
[NFC_test]ndef18 makeExternalRecord errorcode:
"
+
error
.
code
);
expect
(
401
).
assertEqual
(
error
.
code
);
}
}
else
{
console
.
info
(
"
[NFC_test]NdefTag18 = null & = undefined:
"
);
expect
(
true
).
assertFalse
();
}
})
/**
* @tc.number SUB_Communication_NFC_nfcNDEF_js_1900
* @tc.name Test messageToBytes NDEF
* @tc.desc Obtains all records of ndef messageToBytes. The error code is 401
* @tc.size since 9
* @tc.type Function
* @tc.level Level 2
*/
it
(
'
SUB_Communication_NFC_nfcNDEF_js_1900
'
,
0
,
function
()
{
if
(
NdefTag
!=
null
&&
NdefTag
!=
undefined
)
{
let
rawData
=
[
0xD1
,
0x01
,
0x03
,
0x54
,
0x4E
,
0x46
,
0x43
];
try
{
let
ndefMessage
=
tag
.
ndef
.
createNdefMessage
(
'
test
'
);
console
.
info
(
"
[NFC_test]ndef19 createNdefMessage result:
"
+
JSON
.
stringify
(
ndefMessage
));
}
catch
(
error
){
console
.
info
(
"
[NFC_test]ndef19 createNdefMessage errorcode:
"
+
error
.
code
);
expect
(
401
).
assertEqual
(
error
.
code
);
}
try
{
let
makeERecords
=
tag
.
ndef
.
messageToBytes
(
'
test
'
);
console
.
info
(
"
[NFC_test]ndef19 messageToBytes result:
"
+
JSON
.
stringify
(
makeERecords
));
expect
(
makeERecords
).
assertInstanceOf
(
'
Array
'
)
}
catch
(
error
){
console
.
info
(
"
[NFC_test]ndef19 messageToBytes errorcode:
"
+
error
.
code
);
expect
(
401
).
assertEqual
(
error
.
code
);
}
}
else
{
console
.
info
(
"
[NFC_test]NdefTag19 = null & = undefined:
"
);
expect
(
true
).
assertFalse
();
}
})
/**
* @tc.number SUB_Communication_NFC_nfcNDEF_js_2000
* @tc.name getNdefFormatable
* @tc.desc Test getNdefFormatable api. The error code is 401
* @tc.size MEDIUM
* @ since 9
* @tc.type Function
* @tc.level Level 2
*/
it
(
'
SUB_Communication_NFC_nfcNDEF_js_2000
'
,
0
,
function
()
{
if
(
NdefTag
!=
null
&&
NdefTag
!=
undefined
)
{
try
{
let
nfcNdefFormatable
=
tag
.
getNdefFormatable
(
"
test
"
);
console
.
info
(
"
[NFC_test]ndef20 getNdefFormatable:
"
+
nfcNdefFormatable
);
}
catch
(
error
)
{
console
.
info
(
"
[NFC_test]ndef20 getNdefFormatable errorcode:
"
+
error
.
code
);
expect
(
401
).
assertEqual
(
error
.
code
)
}
}
else
{
console
.
info
(
"
[NFC_test]NdefTag20 = null & = undefined:
"
);
expect
(
true
).
assertFalse
();
}
})
console
.
info
(
"
*************[nfc_test] start nfc js unit test end*************
"
);
})
}
communication/nfc_ErrorCode/src/main/js/test/error.TagABFV.js
0 → 100644
浏览文件 @
0cab7285
/*
* 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
tag
from
'
@ohos.nfc.tag
'
;
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
NdefRecord
=
{
NFC_A
:
1
,
NFC_B
:
2
,
ISO_DEP
:
3
,
NFC_F
:
4
,
NFC_V
:
5
,
NDEF
:
6
,
MIFARE_CLASSIC
:
8
,
MIFARE_ULTRALIGHT
:
9
,
NDEF_FORMATABLE
:
10
,
};
let
NfcForumType
=
{
NFC_FORUM_TYPE_1
:
1
,
NFC_FORUM_TYPE_2
:
2
,
NFC_FORUM_TYPE_3
:
3
,
NFC_FORUM_TYPE_4
:
4
,
MIFARE_CLASSIC
:
101
,
};
let
aTag
=
{
"
uid
"
:
[
0x01
,
0x02
,
0x03
,
0x04
],
"
technology
"
:
[
1
],
"
extrasData
"
:
[
{
"
Sak
"
:
0x08
,
"
Atqa
"
:
"
B000
"
,
},
],
"
tagRfDiscId
"
:
1
,
"
supportedProfiles
"
:
1
,
};
let
bTag
=
{
"
uid
"
:
[
0x01
,
0x02
,
0x03
,
0x04
],
"
technology
"
:
[
2
],
"
extrasData
"
:
[
{
"
AppData
"
:
"
A0C0
"
,
"
ProtocolInfo
"
:
"
131F
"
,
}
],
"
tagRfDiscId
"
:
1
,
};
let
fTag
=
{
"
uid
"
:
[
0x01
,
0x02
,
0x03
,
0x04
],
"
technology
"
:
[
4
],
"
extrasData
"
:
[
{
"
SystemCode
"
:
"
A0C0
"
,
"
Pmm
"
:
"
131F
"
,
}
],
"
tagRfDiscId
"
:
1
,
};
let
vTag
=
{
"
uid
"
:
[
0x01
,
0x02
,
0x03
,
0x04
],
"
technology
"
:
[
5
],
"
extrasData
"
:
[
{
"
ResponseFlags
"
:
0x09
,
"
DsfId
"
:
0x13
,
}
],
"
tagRfDiscId
"
:
1
,
};
let
Want
=
{
"
uid
"
:
'
01020304
'
,
"
technology
"
:
[
1
],
"
tagRfDiscId
"
:
1
,
"
Sak
"
:
0x08
,
"
Atqa
"
:
"
B000
"
,
}
export
default
function
nfcTagABFVErrorTest
()
{
describe
(
'
nfcTagABFVErrorTest
'
,
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_NFC_nfctage_js_0100
* @tc.name Test getTagInfo
* @tc.desc Obtains the DsfId value of the taginfo. The error code is 401
* @tc.size since 7
* @tc.type Function
* @tc.level Level 2
*/
it
(
'
SUB_Communication_NFC_nfctage_js_0100
'
,
0
,
function
()
{
let
TagInfo
;
try
{
TagInfo
=
tag
.
getTagInfo
(
"
test
"
);
console
.
info
(
'
[NFC_test]TagABFV1 TagInfo:
'
+
TagInfo
)
expect
(
TagInfo
instanceof
Object
).
assertTrue
();
}
catch
(
error
){
console
.
info
(
'
[NFC_test]TagABFV1 TagInfo errorcode:
'
+
error
.
code
)
expect
(
401
).
assertEqual
(
error
.
code
);
}
})
/**
* @tc.number SUB_Communication_NFC_nfctage_js_0200
* @tc.name Test getNfcA
* @tc.desc Obtains the DsfId value of the taginfo. The error code is 401
* @tc.size since 7
* @tc.type Function
* @tc.level Level 2
*/
it
(
'
SUB_Communication_NFC_nfctage_js_0200
'
,
0
,
function
()
{
let
TagInfo
;
try
{
TagInfo
=
tag
.
getNfcA
(
"
test
"
);
console
.
info
(
'
[NFC_test]TagABFV2 getNfcAtag:
'
+
TagInfo
)
expect
(
TagInfo
instanceof
Object
).
assertTrue
();
}
catch
(
error
){
console
.
info
(
'
[NFC_test]TagABFV2 getNfcAtag errorcode:
'
+
error
.
code
)
expect
(
401
).
assertEqual
(
error
.
code
);
}
})
/**
* @tc.number SUB_Communication_NFC_nfctage_js_0300
* @tc.name Test getNfcB
* @tc.desc Obtains the DsfId value of the taginfo. The error code is 401
* @tc.size since 7
* @tc.type Function
* @tc.level Level 2
*/
it
(
'
SUB_Communication_NFC_nfctage_js_0300
'
,
0
,
function
()
{
let
TagInfo
;
try
{
TagInfo
=
tag
.
getNfcB
(
"
test
"
);
console
.
info
(
'
[NFC_test]TagABFV3 getNfcBtag:
'
+
TagInfo
)
expect
(
TagInfo
instanceof
Object
).
assertTrue
();
}
catch
(
error
){
console
.
info
(
'
[NFC_test]TagABFV3 getNfcBtag errorcode:
'
+
error
.
code
)
expect
(
401
).
assertEqual
(
error
.
code
);
}
})
/**
* @tc.number SUB_Communication_NFC_nfctage_js_0400
* @tc.name Test getNfcF
* @tc.desc Obtains the DsfId value of the taginfo. The error code is 401
* @tc.size since 7
* @tc.type Function
* @tc.level Level 2
*/
it
(
'
SUB_Communication_NFC_nfctage_js_0400
'
,
0
,
function
()
{
let
TagInfo
;
try
{
TagInfo
=
tag
.
getNfcF
(
"
test
"
);
console
.
info
(
'
[NFC_test]TagABFV4 getNfcFtag:
'
+
TagInfo
)
expect
(
TagInfo
instanceof
Object
).
assertTrue
();
}
catch
(
error
){
console
.
info
(
'
[NFC_test]TagABFV4 getNfcFtag errorcode:
'
+
error
.
code
)
expect
(
401
).
assertEqual
(
error
.
code
);
}
})
/**
* @tc.number SUB_Communication_NFC_nfctage_js_0500
* @tc.name Test getNfcV
* @tc.desc Obtains the DsfId value of the taginfo. The error code is 401
* @tc.size since 7
* @tc.type Function
* @tc.level Level 2
*/
it
(
'
SUB_Communication_NFC_nfctage_js_0500
'
,
0
,
function
()
{
let
TagInfo
;
try
{
TagInfo
=
tag
.
getNfcV
(
"
test
"
);
console
.
info
(
'
[NFC_test]TagABFV5 getNfcVtag:
'
+
TagInfo
)
expect
(
TagInfo
instanceof
Object
).
assertTrue
();
}
catch
(
error
){
console
.
info
(
'
[NFC_test]TagABFV5 getNfcVtag errorcode:
'
+
error
.
code
)
expect
(
401
).
assertEqual
(
error
.
code
);
}
})
console
.
info
(
"
*************[nfc_test] start nfc js unit test end*************
"
);
})
}
communication/nfc_ErrorCode/src/main/resources/base/element/string.json
0 → 100644
浏览文件 @
0cab7285
{
"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_ErrorCode/src/main/resources/base/media/icon.png
0 → 100644
浏览文件 @
0cab7285
6.6 KB
communication/wifi_p2p/signature/openharmony_sx.p7b
浏览文件 @
0cab7285
无法预览此类型文件
communication/wifi_p2p/src/main/js/test/WifiManagerP2PEvent.test.js
浏览文件 @
0cab7285
/*
* Copyright (C) 2022 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import
{
describe
,
beforeAll
,
beforeEach
,
afterEach
,
afterAll
,
it
,
expect
}
from
'
@ohos/hypium
'
import
wifiMg
from
'
@ohos.wifiManager
'
function
sleep
(
delay
)
{
return
new
Promise
(
resovle
=>
setTimeout
(
resovle
,
delay
))
}
function
checkWifiPowerOn
(){
console
.
info
(
"
[wifi_test]wifi status:
"
+
wifiMg
.
isWifiActive
());
}
export
default
function
actsWifiManagerEventTest
()
{
describe
(
'
actsWifiManagerEventTest
'
,
function
()
{
beforeEach
(
function
()
{
console
.
info
(
"
[wifi_test]beforeEach start
"
);
checkWifiPowerOn
();
})
afterEach
(
async
function
()
{
console
.
info
(
"
[wifi_test]afterEach start
"
);
})
/**
* @tc.number SUB_Communication_WiFi_Event_Test_0008
* @tc.name testp2pStateChange
* @tc.desc Test p2pStateChange callback
* @tc.type Function
* @tc.level Level 3
*/
it
(
'
SUB_Communication_WiFi_Event_Test_0008
'
,
0
,
async
function
(
done
)
{
let
p2pState
=
"
p2pStateChange
"
;
let
p2pStateChangeCallback
=
result
=>
{
console
.
info
(
"
[wifi_test]p2pStateChange callback, result:
"
+
JSON
.
stringify
(
result
));
}
wifiMg
.
on
(
p2pState
,
p2pStateChangeCallback
);
await
sleep
(
3000
);
wifiMg
.
off
(
p2pState
,
p2pStateChangeCallback
);
done
();
})
/**
* @tc.number SUB_Communication_WiFi_Event_Test_0009
* @tc.name testp2pConnectionChange
* @tc.desc Test p2pConnectionChange callback
* @tc.type Function
* @tc.level Level 3
*/
it
(
'
SUB_Communication_WiFi_Event_Test_0009
'
,
0
,
async
function
(
done
)
{
let
p2pConnectionState
=
"
p2pConnectionChange
"
;
let
p2pConnectionChangeCallback
=
result
=>
{
console
.
info
(
"
[wifi_test]p2pConnectionChange callback, result:
"
+
JSON
.
stringify
(
result
));
}
wifiMg
.
on
(
p2pConnectionState
,
p2pConnectionChangeCallback
);
let
p2pConnectState
=
{
DISCONNECTED
:
0
,
CONNECTED
:
1
,
};
let
wifiP2PConfig
=
{
deviceAddress
:
"
00:00:00:00:00:00
"
,
netId
:
-
1
,
passphrase
:
"
12345678
"
,
groupName
:
"
AAAZZZ456
"
,
goBand
:
wifiMg
.
GroupOwnerBand
.
GO_BAND_AUTO
,
};
let
connectResult
=
wifiMg
.
p2pConnect
(
wifiP2PConfig
);
await
wifiMg
.
getP2pLinkedInfo
()
.
then
(
data
=>
{
let
resultLength
=
Object
.
keys
(
data
).
length
;
console
.
info
(
"
[wifi_test]getP2pLinkedInfo promise result :
"
+
JSON
.
stringify
(
data
));
expect
(
true
).
assertEqual
(
resultLength
!=
0
);
done
()
});
await
sleep
(
2000
);
wifiMg
.
off
(
p2pConnectionState
,
p2pConnectionChangeCallback
);
let
removeGroupResult
=
wifiMg
.
removeGroup
();
done
();
})
/**
* @tc.number SUB_Communication_WiFi_Event_Test_0012
* @tc.name testp2pDeviceChange
* @tc.desc Test p2pDeviceChange callback
* @tc.type Function
* @tc.level Level 3
*/
it
(
'
SUB_Communication_WiFi_Event_Test_0012
'
,
0
,
async
function
(
done
)
{
let
p2pDeviceState
=
"
p2pDeviceChange
"
;
let
p2pDeviceChangeCallback
=
result
=>
{
console
.
info
(
"
[wifi_test]p2pDeviceChange callback, result:
"
+
JSON
.
stringify
(
result
));
}
wifiMg
.
on
(
p2pDeviceState
,
p2pDeviceChangeCallback
);
await
sleep
(
3000
);
wifiMg
.
off
(
p2pDeviceState
,
p2pDeviceChangeCallback
);
done
();
})
/**
* @tc.number SUB_Communication_WiFi_Event_Test_0010
* @tc.name testp2pPeerDeviceChange
* @tc.desc Test p2pPeerDeviceChange callback
* @tc.type Function
* @tc.level Level 3
*/
it
(
'
SUB_Communication_WiFi_Event_Test_0010
'
,
0
,
async
function
(
done
)
{
let
p2pPeerDeviceState
=
"
p2pPeerDeviceChange
"
;
let
p2pPeerDeviceChangeCallback
=
result
=>
{
console
.
info
(
"
[wifi_test]p2pPeerDeviceChange callback, result:
"
+
JSON
.
stringify
(
result
));
}
wifiMg
.
on
(
p2pPeerDeviceState
,
p2pPeerDeviceChangeCallback
);
let
startDiscover
=
wifiMg
.
startDiscoverDevices
();
await
sleep
(
3000
);
let
stopDiscover
=
wifiMg
.
stopDiscoverDevices
();
wifiMg
.
off
(
p2pPeerDeviceState
,
p2pPeerDeviceChangeCallback
);
done
();
})
/**
* @tc.number SUB_Communication_WiFi_Event_Test_0013
* @tc.name testp2pPersistentGroupChange
* @tc.desc Test p2pPersistentGroupChange callback
* @tc.type Function
* @tc.level Level 3
*/
it
(
'
SUB_Communication_WiFi_Event_Test_0013
'
,
0
,
async
function
(
done
)
{
let
p2pGroupState
=
"
p2pPersistentGroupChange
"
;
let
p2pPersistentGroupChangeCallback
=
()
=>
{
console
.
info
(
"
[wifi_test]p2pPersistentGroupChange callback, result:
"
+
JSON
.
stringify
(
result
));
}
wifiMg
.
on
(
p2pGroupState
,
p2pPersistentGroupChangeCallback
);
let
WifiP2PConfig
=
{
deviceAddress
:
"
00:00:00:00:00:00
"
,
netId
:
-
2
,
passphrase
:
"
12345678
"
,
groupName
:
"
AAAZZZ123
"
,
goBand
:
wifiMg
.
GroupOwnerBand
.
GO_BAND_AUTO
,
};
let
createGroupResult
=
wifiMg
.
createGroup
(
WifiP2PConfig
);
await
(
2000
);
await
wifiMg
.
getCurrentGroup
()
.
then
(
data
=>
{
let
resultLength
=
Object
.
keys
(
data
).
length
;
console
.
info
(
"
[wifi_test] getCurrentGroup promise result ->
"
+
JSON
.
stringify
(
data
));
expect
(
true
).
assertEqual
(
resultLength
!=
0
);
});
wifiMg
.
off
(
p2pGroupState
,
p2pPersistentGroupChangeCallback
);
done
();
})
/**
* @tc.number SUB_Communication_WiFi_Event_Test_0011
* @tc.name testpp2pDiscoveryChange
* @tc.desc Test p2pDiscoveryChange callback
* @tc.type Function
* @tc.level Level 3
*/
it
(
'
SUB_Communication_WiFi_Event_Test_0011
'
,
0
,
async
function
(
done
)
{
let
p2pPeerDeviceState
=
"
p2pDiscoveryChange
"
;
let
p2pDiscoveryChangeCallback
=
result
=>
{
console
.
info
(
"
[wifi_test]p2pDiscoveryChange callback, result:
"
+
JSON
.
stringify
(
result
));
}
wifiMg
.
on
(
p2pPeerDeviceState
,
p2pDiscoveryChangeCallback
);
let
startDiscover
=
wifiMg
.
startDiscoverDevices
();
await
sleep
(
3000
);
let
stopDiscover
=
wifiMg
.
stopDiscoverDevices
();
wifiMg
.
off
(
p2pPeerDeviceState
,
p2pDiscoveryChangeCallback
);
done
();
})
console
.
log
(
"
*************[wifi_test] start wifi js unit test end*************
"
);
})
}
/*
* Copyright (C) 2022 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import
{
describe
,
beforeAll
,
beforeEach
,
afterEach
,
afterAll
,
it
,
expect
}
from
'
@ohos/hypium
'
import
wifiMg
from
'
@ohos.wifiManager
'
function
sleep
(
delay
)
{
return
new
Promise
(
resovle
=>
setTimeout
(
resovle
,
delay
))
}
function
checkWifiPowerOn
(){
console
.
info
(
"
[wifi_test]wifi status:
"
+
wifiMg
.
isWifiActive
());
}
export
default
function
actsWifiManagerEventTest
()
{
describe
(
'
actsWifiManagerEventTest
'
,
function
()
{
beforeEach
(
function
()
{
console
.
info
(
"
[wifi_test]beforeEach start
"
);
checkWifiPowerOn
();
})
afterEach
(
async
function
()
{
console
.
info
(
"
[wifi_test]afterEach start
"
);
})
/**
* @tc.number SUB_Communication_WiFi_Event_Test_0008
* @tc.name testp2pStateChange
* @tc.desc Test p2pStateChange callback
* @tc.type Function
* @tc.level Level 3
*/
it
(
'
SUB_Communication_WiFi_Event_Test_0008
'
,
0
,
async
function
(
done
)
{
let
p2pState
=
"
p2pStateChange
"
;
let
p2pStateChangeCallback
=
result
=>
{
console
.
info
(
"
[wifi_test]p2pStateChange callback, result:
"
+
JSON
.
stringify
(
result
));
}
wifiMg
.
on
(
p2pState
,
p2pStateChangeCallback
);
await
sleep
(
3000
);
wifiMg
.
off
(
p2pState
,
p2pStateChangeCallback
);
done
();
})
/**
* @tc.number SUB_Communication_WiFi_Event_Test_0009
* @tc.name testp2pConnectionChange
* @tc.desc Test p2pConnectionChange callback
* @tc.type Function
* @tc.level Level 3
*/
it
(
'
SUB_Communication_WiFi_Event_Test_0009
'
,
0
,
async
function
(
done
)
{
let
p2pConnectionState
=
"
p2pConnectionChange
"
;
let
p2pConnectionChangeCallback
=
result
=>
{
console
.
info
(
"
[wifi_test]p2pConnectionChange callback, result:
"
+
JSON
.
stringify
(
result
));
}
wifiMg
.
on
(
p2pConnectionState
,
p2pConnectionChangeCallback
);
let
p2pConnectState
=
{
DISCONNECTED
:
0
,
CONNECTED
:
1
,
};
let
wifiP2PConfig
=
{
deviceAddress
:
"
00:00:00:00:00:00
"
,
netId
:
-
1
,
passphrase
:
"
12345678
"
,
groupName
:
"
AAAZZZ456
"
,
goBand
:
wifiMg
.
GroupOwnerBand
.
GO_BAND_AUTO
,
};
let
connectResult
=
wifiMg
.
p2pConnect
(
wifiP2PConfig
);
await
wifiMg
.
getP2pLinkedInfo
()
.
then
(
data
=>
{
let
resultLength
=
Object
.
keys
(
data
).
length
;
console
.
info
(
"
[wifi_test]getP2pLinkedInfo promise result :
"
+
JSON
.
stringify
(
data
));
expect
(
true
).
assertEqual
(
resultLength
!=
0
);
done
()
});
await
sleep
(
2000
);
wifiMg
.
off
(
p2pConnectionState
,
p2pConnectionChangeCallback
);
let
removeGroupResult
=
wifiMg
.
removeGroup
();
done
();
})
/**
* @tc.number SUB_Communication_WiFi_Event_Test_0012
* @tc.name testp2pDeviceChange
* @tc.desc Test p2pDeviceChange callback
* @tc.type Function
* @tc.level Level 3
*/
it
(
'
SUB_Communication_WiFi_Event_Test_0012
'
,
0
,
async
function
(
done
)
{
let
p2pDeviceState
=
"
p2pDeviceChange
"
;
let
p2pDeviceChangeCallback
=
result
=>
{
console
.
info
(
"
[wifi_test]p2pDeviceChange callback, result:
"
+
JSON
.
stringify
(
result
));
}
wifiMg
.
on
(
p2pDeviceState
,
p2pDeviceChangeCallback
);
await
sleep
(
3000
);
wifiMg
.
off
(
p2pDeviceState
,
p2pDeviceChangeCallback
);
done
();
})
/**
* @tc.number SUB_Communication_WiFi_Event_Test_0010
* @tc.name testp2pPeerDeviceChange
* @tc.desc Test p2pPeerDeviceChange callback
* @tc.type Function
* @tc.level Level 3
*/
it
(
'
SUB_Communication_WiFi_Event_Test_0010
'
,
0
,
async
function
(
done
)
{
let
p2pPeerDeviceState
=
"
p2pPeerDeviceChange
"
;
let
p2pPeerDeviceChangeCallback
=
result
=>
{
console
.
info
(
"
[wifi_test]p2pPeerDeviceChange callback, result:
"
+
JSON
.
stringify
(
result
));
}
wifiMg
.
on
(
p2pPeerDeviceState
,
p2pPeerDeviceChangeCallback
);
let
startDiscover
=
wifiMg
.
startDiscoverDevices
();
await
sleep
(
3000
);
let
stopDiscover
=
wifiMg
.
stopDiscoverDevices
();
wifiMg
.
off
(
p2pPeerDeviceState
,
p2pPeerDeviceChangeCallback
);
done
();
})
/**
* @tc.number SUB_Communication_WiFi_Event_Test_0013
* @tc.name testp2pPersistentGroupChange
* @tc.desc Test p2pPersistentGroupChange callback
* @tc.type Function
* @tc.level Level 3
*/
it
(
'
SUB_Communication_WiFi_Event_Test_0013
'
,
0
,
async
function
(
done
)
{
let
p2pGroupState
=
"
p2pPersistentGroupChange
"
;
let
p2pPersistentGroupChangeCallback
=
()
=>
{
console
.
info
(
"
[wifi_test]p2pPersistentGroupChange callback, result:
"
+
JSON
.
stringify
(
result
));
}
wifiMg
.
on
(
p2pGroupState
,
p2pPersistentGroupChangeCallback
);
let
WifiP2PConfig
=
{
deviceAddress
:
"
00:00:00:00:00:00
"
,
netId
:
-
2
,
passphrase
:
"
12345678
"
,
groupName
:
"
AAAZZZ123
"
,
goBand
:
wifiMg
.
GroupOwnerBand
.
GO_BAND_AUTO
,
};
let
createGroupResult
=
wifiMg
.
createGroup
(
WifiP2PConfig
);
await
(
2000
);
try
{
await
wifiMg
.
getCurrentP2pGroup
()
.
then
(
data
=>
{
let
resultLength
=
Object
.
keys
(
data
).
length
;
console
.
info
(
"
[wifi_test] getCurrentP2pGroup promise result ->
"
+
JSON
.
stringify
(
data
));
expect
(
true
).
assertEqual
(
resultLength
!=
0
);
}).
catch
((
error
)
=>
{
console
.
error
(
'
[wifi_test] getCurrentP2pGroup promise failed :
'
+
JSON
.
stringify
(
error
));
expect
(
true
).
assertEqual
(
error
!=
null
);
});
}
catch
(
error
){
console
.
info
(
"
[wifi_test]getCurrentP2pGroup promise error:
"
+
JSON
.
stringify
(
error
.
message
));
expect
(
true
).
assertEqual
(
(
JSON
.
stringify
(
error
.
message
))
!=
null
);
}
wifiMg
.
off
(
p2pGroupState
,
p2pPersistentGroupChangeCallback
);
done
();
})
/**
* @tc.number SUB_Communication_WiFi_Event_Test_0011
* @tc.name testpp2pDiscoveryChange
* @tc.desc Test p2pDiscoveryChange callback
* @tc.type Function
* @tc.level Level 3
*/
it
(
'
SUB_Communication_WiFi_Event_Test_0011
'
,
0
,
async
function
(
done
)
{
let
p2pPeerDeviceState
=
"
p2pDiscoveryChange
"
;
let
p2pDiscoveryChangeCallback
=
result
=>
{
console
.
info
(
"
[wifi_test]p2pDiscoveryChange callback, result:
"
+
JSON
.
stringify
(
result
));
}
wifiMg
.
on
(
p2pPeerDeviceState
,
p2pDiscoveryChangeCallback
);
let
startDiscover
=
wifiMg
.
startDiscoverDevices
();
await
sleep
(
3000
);
let
stopDiscover
=
wifiMg
.
stopDiscoverDevices
();
wifiMg
.
off
(
p2pPeerDeviceState
,
p2pDiscoveryChangeCallback
);
done
();
})
console
.
log
(
"
*************[wifi_test] start wifi js unit test end*************
"
);
})
}
communication/wifi_p2p/src/main/js/test/WifiManagerP2PFunction.test.js
浏览文件 @
0cab7285
/*
* Copyright (C) 2022 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import
{
describe
,
beforeAll
,
beforeEach
,
afterEach
,
afterAll
,
it
,
expect
}
from
'
@ohos/hypium
'
import
wifiMg
from
'
@ohos.wifiManager
'
function
sleep
(
delay
)
{
return
new
Promise
(
resovle
=>
setTimeout
(
resovle
,
delay
))
}
function
checkWifiPowerOn
(){
console
.
info
(
"
[wifi_test]/wifi status:
"
+
wifiMg
.
isWifiActive
());
}
export
default
function
actsWifiManagerFunctionTest
()
{
describe
(
'
actsWifiManagerFunctionTest
'
,
function
()
{
beforeEach
(
function
()
{
console
.
info
(
"
[wifi_test]beforeEach start
"
);
checkWifiPowerOn
();
})
afterEach
(
async
function
()
{
console
.
info
(
"
[wifi_test]afterEach start
"
);
})
/**
* @tc.number SUB_Communication_WiFi_XTS_P2P_0003
* @tc.name testCreateGroup
* @tc.desc Test createGroup and getCurrentGroup API Function
* @tc.type Function
* @tc.level Level 3
*/
it
(
'
SUB_Communication_WiFi_XTS_P2P_0003
'
,
0
,
async
function
(
done
)
{
let
wifiP2PConfig
=
{
deviceAddress
:
"
00:00:00:00:00:00
"
,
netId
:
-
1
,
passphrase
:
"
12345678
"
,
groupName
:
"
AAAZZZ123
"
,
goBand
:
wifiMg
.
GroupOwnerBand
.
GO_BAND_2GHZ
,
};
console
.
log
(
"
[wifi_test]check the state of wifi:
"
+
wifiMg
.
isWifiActive
());
expect
(
wifiMg
.
isWifiActive
()).
assertTrue
();
let
createGroupResult
=
wifiMg
.
createGroup
(
wifiP2PConfig
);
await
sleep
(
2000
);
await
wifiMg
.
getCurrentGroup
()
.
then
(
data
=>
{
console
.
info
(
"
[wifi_test]getCurrentGroup promise result ->
"
+
JSON
.
stringify
(
data
));
expect
(
true
).
assertEqual
(
data
.
groupName
==
wifiP2PConfig
.
groupName
);
});
function
getCurrentGroupResult
(){
return
new
Promise
((
resolve
,
reject
)
=>
{
wifiMg
.
getCurrentGroup
(
(
err
,
result
)
=>
{
if
(
err
)
{
console
.
info
(
"
[wifi_test]failed to get getCurrentGroup:
"
+
JSON
.
stringify
(
err
));
expect
().
assertFail
();
}
console
.
info
(
"
[wifi_test]getCurrentGroup callback:
"
+
JSON
.
stringify
(
result
));
console
.
info
(
"
isP2pGo:
"
+
result
.
isP2pGo
+
"
deviceName:
"
+
result
.
ownerInfo
.
deviceName
+
"
deviceAddress:
"
+
result
.
ownerInfo
.
deviceAddress
+
"
primaryDeviceType:
"
+
result
.
ownerInfo
.
primaryDeviceType
+
"
deviceStatus:
"
+
result
.
ownerInfo
.
deviceStatus
+
"
groupCapabilitys:
"
+
result
.
ownerInfo
.
groupCapabilitys
+
"
passphrase:
"
+
result
.
passphrase
+
"
interface:
"
+
result
.
interface
+
"
groupName:
"
+
result
.
groupName
+
"
frequency:
"
+
result
.
frequency
+
"
goIpAddress:
"
+
result
.
goIpAddress
);
console
.
info
(
"
[wifi_test] clientDevices:
"
+
JSON
.
stringify
(
result
.
clientDevices
));
console
.
info
(
"
[wifi_test] ownerInfo:
"
+
JSON
.
stringify
(
result
.
WifiP2pDevice
));
resolve
();
});
});
}
await
getCurrentGroupResult
();
let
removeGroupResult
=
wifiMg
.
removeGroup
();
await
sleep
(
2000
);
await
wifiMg
.
getCurrentGroup
()
.
then
(
data
=>
{
console
.
info
(
"
[wifi_test] getCurrentGroup promise result1 :
"
+
JSON
.
stringify
(
data
));
expect
(
true
).
assertEqual
(
data
.
deviceName
==
null
);
});
done
();
})
/**
* @tc.number SUB_Communication_WiFi_XTS_P2P_0004
* @tc.name testCreateGroup
* @tc.desc Test createGroup-Setting a 7-bit Key Function.
* @tc.type Function
* @tc.level Level 3
*/
it
(
'
SUB_Communication_WiFi_XTS_P2P_0004
'
,
0
,
async
function
(
done
)
{
console
.
log
(
"
[wifi_test]check the state of wifi:
"
+
wifiMg
.
isWifiActive
());
expect
(
wifiMg
.
isWifiActive
()).
assertTrue
();
let
wifiP2PConfig
=
{
deviceAddress
:
"
00:00:00:00:00:00
"
,
netId
:
-
1
,
passphrase
:
"
1234567
"
,
groupName
:
"
test_pass
"
,
goBand
:
wifiMg
.
GroupOwnerBand
.
GO_BAND_2GHZ
,
};
let
createGroupResult
=
wifiMg
.
createGroup
(
wifiP2PConfig
);
await
sleep
(
2000
);
await
wifiMg
.
getCurrentGroup
()
.
then
(
data
=>
{
console
.
info
(
"
[wifi_test] getCurrentGroup promise result :
"
+
JSON
.
stringify
(
data
));
expect
(
true
).
assertEqual
(
data
.
networkId
==
-
999
);
});
let
removeGroupResult
=
wifiMg
.
removeGroup
();
await
sleep
(
2000
);
await
wifiMg
.
getCurrentGroup
()
.
then
(
data
=>
{
console
.
info
(
"
[wifi_test] getCurrentGroup promise result1 :
"
+
JSON
.
stringify
(
data
));
expect
(
true
).
assertEqual
(
data
.
deviceName
==
null
);
});
done
();
})
/**
* @tc.number SUB_Communication_WiFi_XTS_P2P_0104
* @tc.name testCreateGroup
* @tc.desc Test createGroup-Key setting: Chinese, English, and characters Function.
* @tc.type Function
* @tc.level Level 3
*/
it
(
'
SUB_Communication_WiFi_XTS_P2P_0104
'
,
0
,
async
function
(
done
)
{
console
.
log
(
"
[wifi_test]check the state of wifi:
"
+
wifiMg
.
isWifiActive
());
expect
(
wifiMg
.
isWifiActive
()).
assertTrue
();
let
wifiP2PConfig
=
{
deviceAddress
:
"
00:00:00:00:00:00
"
,
netId
:
-
1
,
passphrase
:
"
123@%abcD
"
,
groupName
:
"
test_pass1
"
,
goBand
:
wifiMg
.
GroupOwnerBand
.
GO_BAND_2GHZ
,
};
let
createGroupResult
=
wifiMg
.
createGroup
(
wifiP2PConfig
);
await
sleep
(
2000
);
await
wifiMg
.
getCurrentGroup
()
.
then
(
data
=>
{
console
.
info
(
"
[wifi_test]getCurrentGroup promise result :
"
+
JSON
.
stringify
(
data
));
expect
(
true
).
assertEqual
(
data
.
passphrase
==
wifiP2PConfig
.
passphrase
);
});
let
removeGroupResult
=
wifiMg
.
removeGroup
();
await
sleep
(
2000
);
await
wifiMg
.
getCurrentGroup
()
.
then
(
data
=>
{
console
.
info
(
"
[wifi_test] getCurrentGroup promise result1 :
"
+
JSON
.
stringify
(
data
));
expect
(
true
).
assertEqual
(
data
.
deviceName
==
null
);
});
done
();
})
/**
* @tc.number SUB_Communication_WiFi_XTS_P2P_0204
* @tc.name testCreateGroup
* @tc.desc Test createGroup-Key setting 64 bit Function.
* @tc.type Function
* @tc.level Level 3
*/
it
(
'
SUB_Communication_WiFi_XTS_P2P_0204
'
,
0
,
async
function
(
done
)
{
console
.
log
(
"
[wifi_test]check the state of wifi:
"
+
wifiMg
.
isWifiActive
());
expect
(
wifiMg
.
isWifiActive
()).
assertTrue
();
let
wifiP2PConfig
=
{
deviceAddress
:
"
00:00:00:00:00:00
"
,
netId
:
-
1
,
passphrase
:
"
abc345678901234567890123456789012345678901234567890123456789012
"
,
groupName
:
"
test_pass2
"
,
goBand
:
wifiMg
.
GroupOwnerBand
.
GO_BAND_2GHZ
,
};
let
createGroupResult
=
wifiMg
.
createGroup
(
wifiP2PConfig
);
await
sleep
(
2000
);
await
wifiMg
.
getCurrentGroup
()
.
then
(
data
=>
{
console
.
info
(
"
[wifi_test]getCurrentGroup promise result :
"
+
JSON
.
stringify
(
data
));
expect
(
true
).
assertEqual
(
data
.
passphrase
==
wifiP2PConfig
.
passphrase
);
});
let
removeGroupResult
=
wifiMg
.
removeGroup
();
await
sleep
(
2000
);
await
wifiMg
.
getCurrentGroup
()
.
then
(
data
=>
{
console
.
info
(
"
[wifi_test] getCurrentGroup promise result1 :
"
+
JSON
.
stringify
(
data
));
expect
(
true
).
assertEqual
(
data
.
deviceName
==
null
);
});
done
();
})
/**
* @tc.number SUB_Communication_WiFi_XTS_P2P_0304
* @tc.name testCreateGroup
* @tc.desc Test createGroup-Key setting 65 bitsFunction.
* @tc.type Function
* @tc.level Level 3
*/
it
(
'
SUB_Communication_WiFi_XTS_P2P_0304
'
,
0
,
async
function
(
done
)
{
console
.
log
(
"
[wifi_test]check the state of wifi:
"
+
wifiMg
.
isWifiActive
());
expect
(
wifiMg
.
isWifiActive
()).
assertTrue
();
let
wifiP2PConfig
=
{
deviceAddress
:
"
00:00:00:00:00:00
"
,
netId
:
-
1
,
passphrase
:
"
abc3456789012345678901234567890123456789012345678901234567890123
"
,
groupName
:
"
test_pass3
"
,
goBand
:
wifiMg
.
GroupOwnerBand
.
GO_BAND_2GHZ
,
};
let
createGroupResult
=
wifiMg
.
createGroup
(
wifiP2PConfig
);
await
sleep
(
2000
);
await
wifiMg
.
getCurrentGroup
()
.
then
(
data
=>
{
console
.
info
(
"
[wifi_test]getCurrentGroup promise result :
"
+
JSON
.
stringify
(
data
));
expect
(
true
).
assertEqual
(
data
.
passphrase
!=
wifiP2PConfig
.
passphrase
);
});
let
removeGroupResult
=
wifiMg
.
removeGroup
();
await
sleep
(
2000
);
await
wifiMg
.
getCurrentGroup
()
.
then
(
data
=>
{
console
.
info
(
"
[wifi_test] getCurrentGroup promise result1 :
"
+
JSON
.
stringify
(
data
));
expect
(
true
).
assertEqual
(
data
.
deviceName
==
null
);
});
done
();
})
/**
* @tc.number SUB_Communication_WiFi_XTS_P2P_0007
* @tc.name testCreateGroup
* @tc.desc Test createGroup-2.4 GHz frequency band setting Function
* @tc.type Function
* @tc.level Level 0
*/
it
(
'
SUB_Communication_WiFi_XTS_P2P_0007
'
,
0
,
async
function
(
done
)
{
console
.
log
(
"
[wifi_test]check the state of wifi:
"
+
wifiMg
.
isWifiActive
());
expect
(
wifiMg
.
isWifiActive
()).
assertTrue
();
let
wifiP2PConfig
=
{
deviceAddress
:
"
00:00:00:00:00:00
"
,
netId
:
-
1
,
passphrase
:
"
12345678
"
,
groupName
:
"
test_band1
"
,
goBand
:
wifiMg
.
GroupOwnerBand
.
GO_BAND_2GHZ
,
};
let
createGroupResult
=
wifiMg
.
createGroup
(
wifiP2PConfig
);
await
sleep
(
2000
);
await
wifiMg
.
getCurrentGroup
()
.
then
(
data
=>
{
console
.
info
(
"
[wifi_test]getCurrentGroup promise result :
"
+
JSON
.
stringify
(
data
));
expect
(
true
).
assertEqual
(
2412
<
data
.
frequency
<
2484
);
});
let
removeGroupResult
=
wifiMg
.
removeGroup
();
await
sleep
(
2000
);
await
wifiMg
.
getCurrentGroup
()
.
then
(
data
=>
{
console
.
info
(
"
[wifi_test] getCurrentGroup promise result1 :
"
+
JSON
.
stringify
(
data
));
expect
(
true
).
assertEqual
(
data
.
deviceName
==
null
);
});
done
();
})
/**
* @tc.number SUB_Communication_WiFi_XTS_P2P_0107
* @tc.name testCreateGroup
* @tc.desc Test createGroup-5 GHz frequency band setting Function
* @tc.type Function
* @tc.level Level 0
*/
it
(
'
SUB_Communication_WiFi_XTS_P2P_0107
'
,
0
,
async
function
(
done
)
{
console
.
log
(
"
[wifi_test]check the state of wifi:
"
+
wifiMg
.
isWifiActive
());
expect
(
wifiMg
.
isWifiActive
()).
assertTrue
();
try
{
let
wifiP2PConfig
=
{
deviceAddress
:
"
00:00:00:00:00:00
"
,
netId
:
-
1
,
passphrase
:
"
12345678
"
,
groupName
:
"
test_band2
"
,
goBand
:
wifiMg
.
GroupOwnerBand
.
GO_BAND_5GHZ
,
};
let
createGroupResult
=
wifiMg
.
createGroup
(
wifiP2PConfig
);
await
sleep
(
2000
);
await
wifiMg
.
getCurrentGroup
()
.
then
(
data
=>
{
console
.
info
(
"
[wifi_test] getCurrentGroup promise result :
"
+
JSON
.
stringify
(
data
));
expect
(
true
).
assertEqual
(
5160
<
data
.
frequency
<
5865
);
});
let
removeGroupResult
=
await
wifiMg
.
removeGroup
();
await
sleep
(
2000
);
await
wifiMg
.
getCurrentGroup
()
.
then
(
data
=>
{
console
.
info
(
"
[wifi_test] getCurrentGroup promise result1 :
"
+
JSON
.
stringify
(
data
));
expect
(
true
).
assertEqual
(
data
.
deviceName
==
null
);
});
}
catch
(
error
){
console
.
info
(
"
[wifi_test]createGroup 5G goBand result :
"
+
JSON
.
stringify
(
error
.
message
));
expect
(
true
).
assertEqual
(
(
JSON
.
stringify
(
error
.
message
))
!=
null
);
}
done
();
})
/**
* @tc.number SUB_Communication_WiFi_XTS_P2P_0207
* @tc.name testCreateGroup
* @tc.desc Test createGroup-Auto frequency band setting Function
* @tc.type Function
* @tc.level Level 0
*/
it
(
'
SUB_Communication_WiFi_XTS_P2P_0207
'
,
0
,
async
function
(
done
)
{
console
.
log
(
"
[wifi_test]check the state of wifi:
"
+
wifiMg
.
isWifiActive
());
expect
(
wifiMg
.
isWifiActive
()).
assertTrue
();
try
{
let
wifiP2PConfig
=
{
deviceAddress
:
"
00:00:00:00:00:00
"
,
netId
:
-
1
,
passphrase
:
"
12345678
"
,
groupName
:
"
test_band3
"
,
goBand
:
wifiMg
.
GroupOwnerBand
.
GO_BAND_AUTO
,
};
let
createGroupResult
=
wifiMg
.
createGroup
(
wifiP2PConfig
);
await
sleep
(
2000
);
await
wifiMg
.
getCurrentGroup
()
.
then
(
data
=>
{
console
.
info
(
"
[wifi_test]getCurrentGroup promise result :
"
+
JSON
.
stringify
(
data
));
expect
(
true
).
assertEqual
(
data
.
frequency
!=
null
);
});
let
removeGroupResult
=
await
wifiMg
.
removeGroup
();
await
sleep
(
2000
);
await
wifiMg
.
getCurrentGroup
()
.
then
(
data
=>
{
console
.
info
(
"
[wifi_test] getCurrentGroup promise result1 :
"
+
JSON
.
stringify
(
data
));
expect
(
true
).
assertEqual
(
data
.
deviceName
==
null
);
});
}
catch
(
error
){
console
.
info
(
"
[wifi_test]createGroup auto goBand result :
"
+
JSON
.
stringify
(
error
.
message
));
expect
(
true
).
assertEqual
(
(
JSON
.
stringify
(
error
.
message
))
!=
null
);
}
done
();
})
/**
* @tc.number SUB_Communication_WiFi_XTS_P2P_0008
* @tc.name testCreateGroup
* @tc.desc Test createGroup-SSID is an empty string Function.
* @tc.type Function
* @tc.level Level 0
*/
it
(
'
SUB_Communication_WiFi_XTS_P2P_0008
'
,
0
,
async
function
(
done
)
{
console
.
log
(
"
[wifi_test]check the state of wifi:
"
+
wifiMg
.
isWifiActive
());
expect
(
wifiMg
.
isWifiActive
()).
assertTrue
();
try
{
let
wifiP2PConfig
=
{
deviceAddress
:
"
00:00:00:00:00:00
"
,
netId
:
-
1
,
passphrase
:
"
12345678
"
,
groupName
:
""
,
goBand
:
wifiMg
.
GroupOwnerBand
.
GO_BAND_2GHZ
,
};
let
createGroupResult
=
wifi
.
createGroup
(
wifiP2PConfig
);
await
sleep
(
2000
);
await
wifi
.
getCurrentGroup
()
.
then
(
data
=>
{
console
.
info
(
"
[wifi_test]getCurrentGroup promise result :
"
+
JSON
.
stringify
(
data
));
});
let
removeGroupResult
=
wifi
.
removeGroup
();
await
sleep
(
2000
);
await
wifi
.
getCurrentGroup
()
.
then
(
data
=>
{
console
.
info
(
"
[wifi_test] getCurrentGroup promise result1 :
"
+
JSON
.
stringify
(
data
));
expect
(
true
).
assertEqual
(
data
.
deviceName
==
null
);
});
}
catch
(
error
){
console
.
info
(
"
[wifi_test]createGroup error passphrase result :
"
+
JSON
.
stringify
(
error
.
message
));
expect
(
true
).
assertEqual
(
(
JSON
.
stringify
(
error
.
message
))
!=
null
);
}
done
();
})
/**
* @tc.number SUB_Communication_WiFi_XTS_P2P_0108
* @tc.name testCreateGroup
* @tc.desc Test createGroup-SSID is a space Function.
* @tc.type Function
* @tc.level Level 0
*/
it
(
'
SUB_Communication_WiFi_XTS_P2P_0108
'
,
0
,
async
function
(
done
)
{
console
.
log
(
"
[wifi_test]check the state of wifi:
"
+
wifiMg
.
isWifiActive
());
expect
(
wifiMg
.
isWifiActive
()).
assertTrue
();
try
{
let
wifiP2PConfig
=
{
deviceAddress
:
"
00:00:00:00:00:00
"
,
netId
:
-
1
,
passphrase
:
"
12345678
"
,
groupName
:
"
"
,
goBand
:
wifiMg
.
GroupOwnerBand
.
GO_BAND_2GHZ
,
};
let
createGroupResult
=
wifi
.
createGroup
(
wifiP2PConfig
);
await
sleep
(
2000
);
await
wifi
.
getCurrentGroup
()
.
then
(
data
=>
{
console
.
info
(
"
[wifi_test]getCurrentGroup promise result :
"
+
JSON
.
stringify
(
data
));
});
let
removeGroupResult
=
wifi
.
removeGroup
();
await
sleep
(
2000
);
await
wifi
.
getCurrentGroup
()
.
then
(
data
=>
{
console
.
info
(
"
[wifi_test] getCurrentGroup promise result1 :
"
+
JSON
.
stringify
(
data
));
expect
(
true
).
assertEqual
(
data
.
deviceName
==
null
);
});
}
catch
(
error
){
console
.
info
(
"
[wifi_test]createGroup error passphrase result :
"
+
JSON
.
stringify
(
error
.
message
));
expect
(
true
).
assertEqual
(
(
JSON
.
stringify
(
error
.
message
))
!=
null
);
}
done
();
})
/**
* @tc.number SUB_Communication_WiFi_XTS_P2P_0308
* @tc.name testCreateGroup
* @tc.desc Test createGroup-the password must be a space.
* @tc.type Function
* @tc.level Level 0
*/
it
(
'
SUB_Communication_WiFi_XTS_P2P_0308
'
,
0
,
async
function
(
done
)
{
console
.
log
(
"
[wifi_test]check the state of wifi:
"
+
wifiMg
.
isWifiActive
());
expect
(
wifiMg
.
isWifiActive
()).
assertTrue
();
try
{
let
wifiP2PConfig
=
{
deviceAddress
:
"
00:00:00:00:00:00
"
,
netId
:
-
1
,
passphrase
:
"
"
,
groupName
:
"
testpassword
"
,
goBand
:
wifiMg
.
GroupOwnerBand
.
GO_BAND_2GHZ
,
};
let
createGroupResult
=
wifi
.
createGroup
(
wifiP2PConfig
);
await
sleep
(
2000
);
await
wifi
.
getCurrentGroup
()
.
then
(
data
=>
{
console
.
info
(
"
[wifi_test] getCurrentGroup promise result :
"
+
JSON
.
stringify
(
data
));
});
let
removeGroupResult
=
wifi
.
removeGroup
();
await
sleep
(
2000
);
await
wifi
.
getCurrentGroup
()
.
then
(
data
=>
{
console
.
info
(
"
[wifi_test] getCurrentGroup promise result1 :
"
+
JSON
.
stringify
(
data
));
expect
(
true
).
assertEqual
(
data
.
deviceName
==
null
);
});
}
catch
(
error
){
console
.
info
(
"
[wifi_test]createGroup error passphrase result :
"
+
JSON
.
stringify
(
error
.
message
));
expect
(
true
).
assertEqual
(
(
JSON
.
stringify
(
error
.
message
))
!=
null
);
}
done
();
})
/**
* @tc.number SUB_Communication_WiFi_XTS_P2P_0009
* @tc.name testP2pCancelConnect
* @tc.desc Test p2pCancelConnect Group API functionality.
* @tc.type Function
* @tc.level Level 3
*/
it
(
'
SUB_Communication_WiFi_XTS_P2P_0009
'
,
0
,
async
function
(
done
)
{
let
wifiP2PConfig
=
{
deviceAddress
:
"
11:22:33:44:55:66
"
,
netId
:
-
1
,
passphrase
:
"
12345678
"
,
groupName
:
"
AAAZZZ456
"
,
goBand
:
wifiMg
.
GroupOwnerBand
.
GO_BAND_2GHZ
,
};
let
p2pConnectResult
=
wifiMg
.
p2pConnect
(
wifiP2PConfig
);
console
.
info
(
"
[wifi_test]test p2pConnect successful.
"
);
let
p2pCancelResult
=
wifiMg
.
p2pCancelConnect
();
await
sleep
(
2000
);
console
.
info
(
"
[wifi_test]test p2pCancelConnect successful.
"
);
let
removeGroupResult
=
wifiMg
.
removeGroup
();
console
.
info
(
"
[wifi_test]test removeGroup successful
"
);
await
wifiMg
.
getCurrentGroup
()
.
then
(
data
=>
{
console
.
info
(
"
[wifi_test] getCurrentGroup promise result :
"
+
JSON
.
stringify
(
data
));
expect
(
true
).
assertEqual
(
data
.
deviceName
==
null
);
});
done
();
})
/**
* @tc.number SUB_Communication_WiFi_XTS_P2P_0011
* @tc.name testRemoveGroup
* @tc.desc Test remove a nonexistent group.
* @tc.type Function
* @tc.level Level 3
*/
it
(
'
SUB_Communication_WiFi_XTS_P2P_0011
'
,
0
,
async
function
(
done
)
{
let
removeGroupResult
=
wifiMg
.
removeGroup
(
10000
);
await
wifiMg
.
getCurrentGroup
()
.
then
(
data
=>
{
console
.
info
(
"
[wifi_test] getCurrentGroup promise result1 :
"
+
JSON
.
stringify
(
data
));
expect
(
true
).
assertEqual
(
data
.
deviceName
==
null
);
});
done
();
})
/**
* @tc.number SUB_Communication_WiFi_XTS_P2P_0002
* @tc.name testP2pLocalDevice
* @tc.desc Test get P2pLocalDevice API functionality.
* @tc.type Function
* @tc.level Level 3
*/
it
(
'
SUB_Communication_WiFi_XTS_P2P_0002
'
,
0
,
async
function
(
done
)
{
await
wifiMg
.
getP2pLocalDevice
()
.
then
(
data
=>
{
console
.
info
(
"
[wifi_test]getP2pLocalDevice promise result :
"
+
JSON
.
stringify
(
data
));
expect
(
true
).
assertEqual
(
data
.
deviceName
!=
null
);
}).
catch
((
error
)
=>
{
console
.
info
(
"
[wifi_test]getP2pLocalDevice promise error.
"
+
JSON
.
stringify
(
error
));
expect
().
assertFail
();
});
function
getP2pLocal
(){
return
new
Promise
((
resolve
,
reject
)
=>
{
wifiMg
.
getP2pLocalDevice
(
(
err
,
ret
)
=>
{
if
(
err
)
{
console
.
info
(
"
[wifi_test]getP2pLocalDevice callback failed :
"
+
JSON
.
stringify
(
err
));
return
;
}
console
.
info
(
"
[wifi_test]getP2pLocalDevice callback result:
"
+
JSON
.
stringify
(
ret
));
console
.
info
(
"
deviceName:
"
+
ret
.
deviceName
+
"
deviceAddress:
"
+
ret
.
deviceAddress
+
"
primaryDeviceType:
"
+
ret
.
primaryDeviceType
+
"
deviceStatus:
"
+
ret
.
deviceStatus
+
"
groupCapabilitys:
"
+
ret
.
groupCapabilitys
);
resolve
();
});
});
}
await
getP2pLocal
();
done
();
})
/**
* @tc.number SUB_Communication_WiFi_XTS_P2P_0010
* @tc.name testGetP2pLinkedInfo
* @tc.desc Test getP2pLinkedInfo API functionality
* @tc.type Function
* @tc.level Level 2
*/
it
(
'
SUB_Communication_WiFi_XTS_P2P_0010
'
,
0
,
async
function
(
done
)
{
let
p2pConnectState
=
{
DISCONNECTED
:
0
,
CONNECTED
:
1
,
};
await
wifiMg
.
getP2pLinkedInfo
()
.
then
(
data
=>
{
let
resultLength
=
Object
.
keys
(
data
).
length
;
console
.
info
(
"
[wifi_test]getP2pLinkedInfo promise result :
"
+
JSON
.
stringify
(
data
));
expect
(
true
).
assertEqual
(
resultLength
!=
0
);
done
()
});
function
getP2pLinkedInfoResult
(){
return
new
Promise
((
resolve
,
reject
)
=>
{
wifiMg
.
getP2pLinkedInfo
(
(
err
,
result
)
=>
{
if
(
err
)
{
console
.
info
(
"
[wifi_test]failed to getP2pLinkedInfo callback:
"
+
JSON
.
stringify
(
err
));
return
;
}
let
resultLength
=
Object
.
keys
(
result
).
length
;
console
.
info
(
"
[wifi_test]getP2pLinkedInfo callback:
"
+
JSON
.
stringify
(
resultLength
));
console
.
info
(
"
connectState:
"
+
result
.
connectState
+
"
isGroupOwner:
"
+
result
.
isGroupOwner
+
"
groupOwnerAddr:
"
+
result
.
groupOwnerAddr
);
expect
(
true
).
assertEqual
(
resultLength
!=
0
);
resolve
();
});
});
}
await
getP2pLinkedInfoResult
();
done
();
})
/**
* @tc.number SUB_Communication_WiFi_XTS_P2P_0001
* @tc.name testGetP2pPeerDevices
* @tc.desc Test getP2pPeerDevices promise API functionality
* @tc.type Function
* @tc.level Level 0
*/
it
(
'
SUB_Communication_WiFi_XTS_P2P_0001
'
,
0
,
async
function
(
done
){
console
.
log
(
"
[wifi_test]check the state of wifi:
"
+
wifiMg
.
isWifiActive
());
expect
(
wifiMg
.
isWifiActive
()).
assertTrue
();
let
startDiscover
=
wifiMg
.
startDiscoverDevices
();
await
sleep
(
2000
);
await
wifiMg
.
getP2pPeerDevices
()
.
then
((
data
)
=>
{
let
resultLength
=
Object
.
keys
(
data
).
length
;
console
.
info
(
"
[wifi_test]getP2pPeerDevices promise result ->
"
+
JSON
.
stringify
(
data
));
expect
(
true
).
assertEqual
(
resultLength
>=
0
);
}).
catch
((
error
)
=>
{
console
.
info
(
"
[wifi_test]getP2pPeerDevices promise then error.
"
+
JSON
.
stringify
(
error
));
expect
().
assertFail
();
});
let
stopDiscover
=
wifiMg
.
stopDiscoverDevices
();
done
();
})
/**
* @tc.number SUB_Communication_WiFi_XTS_P2P_0101
* @tc.name testGetP2pPeerDevices
* @tc.desc Test getP2pPeerDevices callback API functionality
* @tc.type Function
* @tc.level Level 0
*/
it
(
'
SUB_Communication_WiFi_XTS_P2P_0101
'
,
0
,
async
function
(
done
){
console
.
log
(
"
[wifi_test]check the state of wifi:
"
+
wifiMg
.
isWifiActive
());
expect
(
wifiMg
.
isWifiActive
()).
assertTrue
();
let
startDiscover
=
wifiMg
.
startDiscoverDevices
();
await
sleep
(
2000
);
function
getP2pPeerDevicesResult
(){
return
new
Promise
((
resolve
,
reject
)
=>
{
wifiMg
.
getP2pPeerDevices
(
(
err
,
result
)
=>
{
if
(
err
)
{
console
.
error
(
'
[wifi_test]failed to getP2pPeerDevices :
'
+
JSON
.
stringify
(
err
));
}
console
.
info
(
"
[wifi_test] getP2pPeerDevices callback result :
"
+
JSON
.
stringify
(
result
));
let
len
=
Object
.
keys
(
result
).
length
;
for
(
let
j
=
0
;
j
<
len
;
++
j
)
{
console
.
info
(
"
deviceName:
"
+
result
[
j
].
deviceName
+
"
deviceAddress:
"
+
result
[
j
].
deviceAddress
+
"
primaryDeviceType:
"
+
result
[
j
].
primaryDeviceType
+
"
deviceStatus:
"
+
result
[
j
].
deviceStatus
+
"
groupCapabilitys:
"
+
result
[
j
].
groupCapabilitys
);
if
(
result
[
j
].
deviceStatus
==
wifiMg
.
P2pDeviceStatus
.
UNAVAILABLE
){
console
.
info
(
"
deviceStatus:
"
+
result
[
j
].
deviceStatus
);
}
if
(
result
[
j
].
deviceStatus
==
wifiMg
.
P2pDeviceStatus
.
CONNECTED
){
console
.
info
(
"
deviceStatus:
"
+
result
[
j
].
deviceStatus
);
}
if
(
result
[
j
].
deviceStatus
==
wifiMg
.
P2pDeviceStatus
.
INVITED
){
console
.
info
(
"
deviceStatus:
"
+
result
[
j
].
deviceStatus
);
}
if
(
result
[
j
].
deviceStatus
==
wifiMg
.
P2pDeviceStatus
.
FAILED
){
console
.
info
(
"
deviceStatus:
"
+
result
[
j
].
deviceStatus
);
}
if
(
result
[
j
].
deviceStatus
==
wifiMg
.
P2pDeviceStatus
.
AVAILABLE
){
console
.
info
(
"
deviceStatus:
"
+
result
[
j
].
deviceStatus
);
}
}
resolve
();
});
});
}
await
getP2pPeerDevicesResult
();
done
();
});
console
.
log
(
"
*************[wifi_test] start wifi js unit test end*************
"
);
})
}
/*
* Copyright (C) 2022 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import
{
describe
,
beforeAll
,
beforeEach
,
afterEach
,
afterAll
,
it
,
expect
}
from
'
@ohos/hypium
'
import
wifiMg
from
'
@ohos.wifiManager
'
function
sleep
(
delay
)
{
return
new
Promise
(
resovle
=>
setTimeout
(
resovle
,
delay
))
}
function
checkWifiPowerOn
(){
console
.
info
(
"
[wifi_test]/wifi status:
"
+
wifiMg
.
isWifiActive
());
}
export
default
function
actsWifiManagerFunctionTest
()
{
describe
(
'
actsWifiManagerFunctionTest
'
,
function
()
{
beforeEach
(
function
()
{
console
.
info
(
"
[wifi_test]beforeEach start
"
);
checkWifiPowerOn
();
})
afterEach
(
async
function
()
{
console
.
info
(
"
[wifi_test]afterEach start
"
);
})
/**
* @tc.number SUB_Communication_WiFi_XTS_P2P_0003
* @tc.name testCreateGroup
* @tc.desc Test createGroup and getCurrentP2pGroup API Function
* @tc.type Function
* @tc.level Level 3
*/
it
(
'
SUB_Communication_WiFi_XTS_P2P_0003
'
,
0
,
async
function
(
done
)
{
let
wifiP2PConfig
=
{
deviceAddress
:
"
00:00:00:00:00:00
"
,
netId
:
-
1
,
passphrase
:
"
12345678
"
,
groupName
:
"
AAAZZZ123
"
,
goBand
:
wifiMg
.
GroupOwnerBand
.
GO_BAND_2GHZ
,
};
console
.
log
(
"
[wifi_test]check the state of wifi:
"
+
wifiMg
.
isWifiActive
());
expect
(
wifiMg
.
isWifiActive
()).
assertTrue
();
let
createGroupResult
=
wifiMg
.
createGroup
(
wifiP2PConfig
);
await
sleep
(
2000
);
await
wifiMg
.
getCurrentP2pGroup
()
.
then
(
data
=>
{
console
.
info
(
"
[wifi_test]getCurrentP2pGroup promise result ->
"
+
JSON
.
stringify
(
data
));
expect
(
true
).
assertEqual
(
data
.
groupName
==
wifiP2PConfig
.
groupName
);
});
function
getCurrentP2pGroupResult
(){
return
new
Promise
((
resolve
,
reject
)
=>
{
wifiMg
.
getCurrentP2pGroup
(
(
err
,
result
)
=>
{
if
(
err
)
{
console
.
info
(
"
[wifi_test]failed to get getCurrentP2pGroup:
"
+
JSON
.
stringify
(
err
));
expect
().
assertFail
();
}
console
.
info
(
"
[wifi_test]getCurrentP2pGroup callback:
"
+
JSON
.
stringify
(
result
));
console
.
info
(
"
isP2pGo:
"
+
result
.
isP2pGo
+
"
deviceName:
"
+
result
.
ownerInfo
.
deviceName
+
"
deviceAddress:
"
+
result
.
ownerInfo
.
deviceAddress
+
"
primaryDeviceType:
"
+
result
.
ownerInfo
.
primaryDeviceType
+
"
deviceStatus:
"
+
result
.
ownerInfo
.
deviceStatus
+
"
groupCapabilitys:
"
+
result
.
ownerInfo
.
groupCapabilitys
+
"
passphrase:
"
+
result
.
passphrase
+
"
interface:
"
+
result
.
interface
+
"
groupName:
"
+
result
.
groupName
+
"
frequency:
"
+
result
.
frequency
+
"
goIpAddress:
"
+
result
.
goIpAddress
);
console
.
info
(
"
[wifi_test] clientDevices:
"
+
JSON
.
stringify
(
result
.
clientDevices
));
console
.
info
(
"
[wifi_test] ownerInfo:
"
+
JSON
.
stringify
(
result
.
WifiP2pDevice
));
resolve
();
});
});
}
await
getCurrentP2pGroupResult
();
let
removeGroupResult
=
wifiMg
.
removeGroup
();
await
sleep
(
2000
);
try
{
await
wifiMg
.
getCurrentP2pGroup
()
.
then
(
data
=>
{
console
.
info
(
"
[wifi_test] getCurrentP2pGroup promise result1 :
"
+
JSON
.
stringify
(
data
));
expect
(
true
).
assertEqual
(
data
.
deviceName
==
null
);
}).
catch
((
error
)
=>
{
console
.
error
(
'
[wifi_test] getCurrentP2pGroup promise failed :
'
+
JSON
.
stringify
(
error
));
expect
(
true
).
assertEqual
(
error
!=
null
);
});
}
catch
(
error
){
console
.
info
(
"
[wifi_test]getCurrentP2pGroup promise error:
"
+
JSON
.
stringify
(
error
.
message
));
expect
(
true
).
assertEqual
(
(
JSON
.
stringify
(
error
.
message
))
!=
null
);
}
done
();
})
/**
* @tc.number SUB_Communication_WiFi_XTS_P2P_0004
* @tc.name testCreateGroup
* @tc.desc Test createGroup-Setting a 7-bit Key Function.
* @tc.type Function
* @tc.level Level 3
*/
it
(
'
SUB_Communication_WiFi_XTS_P2P_0004
'
,
0
,
async
function
(
done
)
{
console
.
log
(
"
[wifi_test]check the state of wifi:
"
+
wifiMg
.
isWifiActive
());
expect
(
wifiMg
.
isWifiActive
()).
assertTrue
();
let
wifiP2PConfig
=
{
deviceAddress
:
"
00:00:00:00:00:00
"
,
netId
:
-
1
,
passphrase
:
"
1234567
"
,
groupName
:
"
test_pass
"
,
goBand
:
wifiMg
.
GroupOwnerBand
.
GO_BAND_2GHZ
,
};
let
createGroupResult
=
wifiMg
.
createGroup
(
wifiP2PConfig
);
await
sleep
(
2000
);
await
wifiMg
.
getCurrentP2pGroup
()
.
then
(
data
=>
{
console
.
info
(
"
[wifi_test] getCurrentP2pGroup promise result :
"
+
JSON
.
stringify
(
data
));
expect
(
true
).
assertEqual
(
data
.
networkId
==
-
999
);
});
let
removeGroupResult
=
wifiMg
.
removeGroup
();
await
sleep
(
2000
);
try
{
await
wifiMg
.
getCurrentP2pGroup
()
.
then
(
data
=>
{
console
.
info
(
"
[wifi_test] getCurrentP2pGroup promise result1 :
"
+
JSON
.
stringify
(
data
));
expect
(
true
).
assertEqual
(
data
.
deviceName
==
null
);
}).
catch
((
error
)
=>
{
console
.
error
(
'
[wifi_test] getCurrentP2pGroup promise failed :
'
+
JSON
.
stringify
(
error
));
expect
(
true
).
assertEqual
(
error
!=
null
);
});
}
catch
(
error
){
console
.
info
(
"
[wifi_test]getCurrentP2pGroup promise error:
"
+
JSON
.
stringify
(
error
.
message
));
expect
(
true
).
assertEqual
(
(
JSON
.
stringify
(
error
.
message
))
!=
null
);
}
done
();
})
/**
* @tc.number SUB_Communication_WiFi_XTS_P2P_0104
* @tc.name testCreateGroup
* @tc.desc Test createGroup-Key setting: Chinese, English, and characters Function.
* @tc.type Function
* @tc.level Level 3
*/
it
(
'
SUB_Communication_WiFi_XTS_P2P_0104
'
,
0
,
async
function
(
done
)
{
console
.
log
(
"
[wifi_test]check the state of wifi:
"
+
wifiMg
.
isWifiActive
());
expect
(
wifiMg
.
isWifiActive
()).
assertTrue
();
let
wifiP2PConfig
=
{
deviceAddress
:
"
00:00:00:00:00:00
"
,
netId
:
-
1
,
passphrase
:
"
123@%abcD
"
,
groupName
:
"
test_pass1
"
,
goBand
:
wifiMg
.
GroupOwnerBand
.
GO_BAND_2GHZ
,
};
let
createGroupResult
=
wifiMg
.
createGroup
(
wifiP2PConfig
);
await
sleep
(
2000
);
await
wifiMg
.
getCurrentP2pGroup
()
.
then
(
data
=>
{
console
.
info
(
"
[wifi_test]getCurrentP2pGroup promise result :
"
+
JSON
.
stringify
(
data
));
expect
(
true
).
assertEqual
(
data
.
passphrase
==
wifiP2PConfig
.
passphrase
);
});
let
removeGroupResult
=
wifiMg
.
removeGroup
();
await
sleep
(
2000
);
try
{
await
wifiMg
.
getCurrentP2pGroup
()
.
then
(
data
=>
{
console
.
info
(
"
[wifi_test] getCurrentP2pGroup promise result1 :
"
+
JSON
.
stringify
(
data
));
expect
(
true
).
assertEqual
(
data
.
deviceName
==
null
);
}).
catch
((
error
)
=>
{
console
.
error
(
'
[wifi_test] getCurrentP2pGroup promise failed :
'
+
JSON
.
stringify
(
error
));
expect
(
true
).
assertEqual
(
error
!=
null
);
});
}
catch
(
error
){
console
.
info
(
"
[wifi_test]getCurrentP2pGroup promise error:
"
+
JSON
.
stringify
(
error
.
message
));
expect
(
true
).
assertEqual
(
(
JSON
.
stringify
(
error
.
message
))
!=
null
);
}
done
();
})
/**
* @tc.number SUB_Communication_WiFi_XTS_P2P_0204
* @tc.name testCreateGroup
* @tc.desc Test createGroup-Key setting 64 bit Function.
* @tc.type Function
* @tc.level Level 3
*/
it
(
'
SUB_Communication_WiFi_XTS_P2P_0204
'
,
0
,
async
function
(
done
)
{
console
.
log
(
"
[wifi_test]check the state of wifi:
"
+
wifiMg
.
isWifiActive
());
expect
(
wifiMg
.
isWifiActive
()).
assertTrue
();
let
wifiP2PConfig
=
{
deviceAddress
:
"
00:00:00:00:00:00
"
,
netId
:
-
1
,
passphrase
:
"
abc345678901234567890123456789012345678901234567890123456789012
"
,
groupName
:
"
test_pass2
"
,
goBand
:
wifiMg
.
GroupOwnerBand
.
GO_BAND_2GHZ
,
};
let
createGroupResult
=
wifiMg
.
createGroup
(
wifiP2PConfig
);
await
sleep
(
2000
);
await
wifiMg
.
getCurrentP2pGroup
()
.
then
(
data
=>
{
console
.
info
(
"
[wifi_test]getCurrentP2pGroup promise result :
"
+
JSON
.
stringify
(
data
));
expect
(
true
).
assertEqual
(
data
.
passphrase
==
wifiP2PConfig
.
passphrase
);
});
let
removeGroupResult
=
wifiMg
.
removeGroup
();
await
sleep
(
2000
);
try
{
await
wifiMg
.
getCurrentP2pGroup
()
.
then
(
data
=>
{
console
.
info
(
"
[wifi_test] getCurrentP2pGroup promise result1 :
"
+
JSON
.
stringify
(
data
));
expect
(
true
).
assertEqual
(
data
.
deviceName
==
null
);
}).
catch
((
error
)
=>
{
console
.
error
(
'
[wifi_test] getCurrentP2pGroup promise failed :
'
+
JSON
.
stringify
(
error
));
expect
(
true
).
assertEqual
(
error
!=
null
);
});
}
catch
(
error
){
console
.
info
(
"
[wifi_test]getCurrentP2pGroup promise error:
"
+
JSON
.
stringify
(
error
.
message
));
expect
(
true
).
assertEqual
(
(
JSON
.
stringify
(
error
.
message
))
!=
null
);
}
done
();
})
/**
* @tc.number SUB_Communication_WiFi_XTS_P2P_0304
* @tc.name testCreateGroup
* @tc.desc Test createGroup-Key setting 65 bitsFunction.
* @tc.type Function
* @tc.level Level 3
*/
it
(
'
SUB_Communication_WiFi_XTS_P2P_0304
'
,
0
,
async
function
(
done
)
{
console
.
log
(
"
[wifi_test]check the state of wifi:
"
+
wifiMg
.
isWifiActive
());
expect
(
wifiMg
.
isWifiActive
()).
assertTrue
();
let
wifiP2PConfig
=
{
deviceAddress
:
"
00:00:00:00:00:00
"
,
netId
:
-
1
,
passphrase
:
"
abc3456789012345678901234567890123456789012345678901234567890123
"
,
groupName
:
"
test_pass3
"
,
goBand
:
wifiMg
.
GroupOwnerBand
.
GO_BAND_2GHZ
,
};
let
createGroupResult
=
wifiMg
.
createGroup
(
wifiP2PConfig
);
await
sleep
(
2000
);
await
wifiMg
.
getCurrentP2pGroup
()
.
then
(
data
=>
{
console
.
info
(
"
[wifi_test]getCurrentP2pGroup promise result :
"
+
JSON
.
stringify
(
data
));
expect
(
true
).
assertEqual
(
data
.
passphrase
!=
wifiP2PConfig
.
passphrase
);
});
let
removeGroupResult
=
wifiMg
.
removeGroup
();
await
sleep
(
2000
);
try
{
await
wifiMg
.
getCurrentP2pGroup
()
.
then
(
data
=>
{
console
.
info
(
"
[wifi_test] getCurrentP2pGroup promise result1 :
"
+
JSON
.
stringify
(
data
));
expect
(
true
).
assertEqual
(
data
.
deviceName
==
null
);
}).
catch
((
error
)
=>
{
console
.
error
(
'
[wifi_test] getCurrentP2pGroup promise failed :
'
+
JSON
.
stringify
(
error
));
expect
(
true
).
assertEqual
(
error
!=
null
);
});
}
catch
(
error
){
console
.
info
(
"
[wifi_test]getCurrentP2pGroup promise error:
"
+
JSON
.
stringify
(
error
.
message
));
expect
(
true
).
assertEqual
(
(
JSON
.
stringify
(
error
.
message
))
!=
null
);
}
done
();
})
/**
* @tc.number SUB_Communication_WiFi_XTS_P2P_0007
* @tc.name testCreateGroup
* @tc.desc Test createGroup-2.4 GHz frequency band setting Function
* @tc.type Function
* @tc.level Level 0
*/
it
(
'
SUB_Communication_WiFi_XTS_P2P_0007
'
,
0
,
async
function
(
done
)
{
console
.
log
(
"
[wifi_test]check the state of wifi:
"
+
wifiMg
.
isWifiActive
());
expect
(
wifiMg
.
isWifiActive
()).
assertTrue
();
let
wifiP2PConfig
=
{
deviceAddress
:
"
00:00:00:00:00:00
"
,
netId
:
-
1
,
passphrase
:
"
12345678
"
,
groupName
:
"
test_band1
"
,
goBand
:
wifiMg
.
GroupOwnerBand
.
GO_BAND_2GHZ
,
};
let
createGroupResult
=
wifiMg
.
createGroup
(
wifiP2PConfig
);
await
sleep
(
2000
);
await
wifiMg
.
getCurrentP2pGroup
()
.
then
(
data
=>
{
console
.
info
(
"
[wifi_test]getCurrentP2pGroup promise result :
"
+
JSON
.
stringify
(
data
));
expect
(
true
).
assertEqual
(
2412
<
data
.
frequency
<
2484
);
});
let
removeGroupResult
=
wifiMg
.
removeGroup
();
await
sleep
(
2000
);
try
{
await
wifiMg
.
getCurrentP2pGroup
()
.
then
(
data
=>
{
console
.
info
(
"
[wifi_test] getCurrentP2pGroup promise result1 :
"
+
JSON
.
stringify
(
data
));
expect
(
true
).
assertEqual
(
data
.
deviceName
==
null
);
}).
catch
((
error
)
=>
{
console
.
error
(
'
[wifi_test] getCurrentP2pGroup promise failed :
'
+
JSON
.
stringify
(
error
));
expect
(
true
).
assertEqual
(
error
!=
null
);
});
}
catch
(
error
){
console
.
info
(
"
[wifi_test]getCurrentP2pGroup promise error:
"
+
JSON
.
stringify
(
error
.
message
));
expect
(
true
).
assertEqual
(
(
JSON
.
stringify
(
error
.
message
))
!=
null
);
}
done
();
})
/**
* @tc.number SUB_Communication_WiFi_XTS_P2P_0107
* @tc.name testCreateGroup
* @tc.desc Test createGroup-5 GHz frequency band setting Function
* @tc.type Function
* @tc.level Level 0
*/
it
(
'
SUB_Communication_WiFi_XTS_P2P_0107
'
,
0
,
async
function
(
done
)
{
console
.
log
(
"
[wifi_test]check the state of wifi:
"
+
wifiMg
.
isWifiActive
());
expect
(
wifiMg
.
isWifiActive
()).
assertTrue
();
try
{
let
wifiP2PConfig
=
{
deviceAddress
:
"
00:00:00:00:00:00
"
,
netId
:
-
1
,
passphrase
:
"
12345678
"
,
groupName
:
"
test_band2
"
,
goBand
:
wifiMg
.
GroupOwnerBand
.
GO_BAND_5GHZ
,
};
let
createGroupResult
=
wifiMg
.
createGroup
(
wifiP2PConfig
);
await
sleep
(
2000
);
await
wifiMg
.
getCurrentP2pGroup
()
.
then
(
data
=>
{
console
.
info
(
"
[wifi_test] getCurrentP2pGroup promise result :
"
+
JSON
.
stringify
(
data
));
expect
(
true
).
assertEqual
(
5160
<
data
.
frequency
<
5865
);
});
let
removeGroupResult
=
await
wifiMg
.
removeGroup
();
await
sleep
(
2000
);
await
wifiMg
.
getCurrentP2pGroup
()
.
then
(
data
=>
{
console
.
info
(
"
[wifi_test] getCurrentP2pGroup promise result1 :
"
+
JSON
.
stringify
(
data
));
expect
(
true
).
assertEqual
(
data
.
deviceName
==
null
);
}).
catch
((
error
)
=>
{
console
.
error
(
'
[wifi_test] getCurrentP2pGroup promise failed :
'
+
JSON
.
stringify
(
error
));
expect
(
true
).
assertEqual
(
error
!=
null
);
});
}
catch
(
error
){
console
.
info
(
"
[wifi_test]createGroup 5G goBand result :
"
+
JSON
.
stringify
(
error
.
message
));
expect
(
true
).
assertEqual
(
(
JSON
.
stringify
(
error
.
message
))
!=
null
);
}
done
();
})
/**
* @tc.number SUB_Communication_WiFi_XTS_P2P_0207
* @tc.name testCreateGroup
* @tc.desc Test createGroup-Auto frequency band setting Function
* @tc.type Function
* @tc.level Level 0
*/
it
(
'
SUB_Communication_WiFi_XTS_P2P_0207
'
,
0
,
async
function
(
done
)
{
console
.
log
(
"
[wifi_test]check the state of wifi:
"
+
wifiMg
.
isWifiActive
());
expect
(
wifiMg
.
isWifiActive
()).
assertTrue
();
try
{
let
wifiP2PConfig
=
{
deviceAddress
:
"
00:00:00:00:00:00
"
,
netId
:
-
1
,
passphrase
:
"
12345678
"
,
groupName
:
"
test_band3
"
,
goBand
:
wifiMg
.
GroupOwnerBand
.
GO_BAND_AUTO
,
};
let
createGroupResult
=
wifiMg
.
createGroup
(
wifiP2PConfig
);
await
sleep
(
2000
);
await
wifiMg
.
getCurrentP2pGroup
()
.
then
(
data
=>
{
console
.
info
(
"
[wifi_test]getCurrentP2pGroup promise result :
"
+
JSON
.
stringify
(
data
));
expect
(
true
).
assertEqual
(
data
.
frequency
!=
null
);
});
let
removeGroupResult
=
await
wifiMg
.
removeGroup
();
await
sleep
(
2000
);
await
wifiMg
.
getCurrentP2pGroup
()
.
then
(
data
=>
{
console
.
info
(
"
[wifi_test] getCurrentP2pGroup promise result1 :
"
+
JSON
.
stringify
(
data
));
expect
(
true
).
assertEqual
(
data
.
deviceName
==
null
);
}).
catch
((
error
)
=>
{
console
.
error
(
'
[wifi_test] getCurrentP2pGroup promise failed :
'
+
JSON
.
stringify
(
error
));
expect
(
true
).
assertEqual
(
error
!=
null
);
});
}
catch
(
error
){
console
.
info
(
"
[wifi_test]createGroup auto goBand result :
"
+
JSON
.
stringify
(
error
.
message
));
expect
(
true
).
assertEqual
(
(
JSON
.
stringify
(
error
.
message
))
!=
null
);
}
done
();
})
/**
* @tc.number SUB_Communication_WiFi_XTS_P2P_0008
* @tc.name testCreateGroup
* @tc.desc Test createGroup-SSID is an empty string Function.
* @tc.type Function
* @tc.level Level 0
*/
it
(
'
SUB_Communication_WiFi_XTS_P2P_0008
'
,
0
,
async
function
(
done
)
{
console
.
log
(
"
[wifi_test]check the state of wifi:
"
+
wifiMg
.
isWifiActive
());
expect
(
wifiMg
.
isWifiActive
()).
assertTrue
();
try
{
let
wifiP2PConfig
=
{
deviceAddress
:
"
00:00:00:00:00:00
"
,
netId
:
-
1
,
passphrase
:
"
12345678
"
,
groupName
:
""
,
goBand
:
wifiMg
.
GroupOwnerBand
.
GO_BAND_2GHZ
,
};
let
createGroupResult
=
wifi
.
createGroup
(
wifiP2PConfig
);
await
sleep
(
2000
);
await
wifi
.
getCurrentP2pGroup
()
.
then
(
data
=>
{
console
.
info
(
"
[wifi_test]getCurrentP2pGroup promise result :
"
+
JSON
.
stringify
(
data
));
});
let
removeGroupResult
=
wifi
.
removeGroup
();
await
sleep
(
2000
);
await
wifiMg
.
getCurrentP2pGroup
()
.
then
(
data
=>
{
console
.
info
(
"
[wifi_test] getCurrentP2pGroup promise result1 :
"
+
JSON
.
stringify
(
data
));
expect
(
true
).
assertEqual
(
data
.
deviceName
==
null
);
}).
catch
((
error
)
=>
{
console
.
error
(
'
[wifi_test] getCurrentP2pGroup promise failed :
'
+
JSON
.
stringify
(
error
));
expect
(
true
).
assertEqual
(
error
!=
null
);
});
}
catch
(
error
){
console
.
info
(
"
[wifi_test]createGroup error passphrase result :
"
+
JSON
.
stringify
(
error
.
message
));
expect
(
true
).
assertEqual
(
(
JSON
.
stringify
(
error
.
message
))
!=
null
);
}
done
();
})
/**
* @tc.number SUB_Communication_WiFi_XTS_P2P_0108
* @tc.name testCreateGroup
* @tc.desc Test createGroup-SSID is a space Function.
* @tc.type Function
* @tc.level Level 0
*/
it
(
'
SUB_Communication_WiFi_XTS_P2P_0108
'
,
0
,
async
function
(
done
)
{
console
.
log
(
"
[wifi_test]check the state of wifi:
"
+
wifiMg
.
isWifiActive
());
expect
(
wifiMg
.
isWifiActive
()).
assertTrue
();
try
{
let
wifiP2PConfig
=
{
deviceAddress
:
"
00:00:00:00:00:00
"
,
netId
:
-
1
,
passphrase
:
"
12345678
"
,
groupName
:
"
"
,
goBand
:
wifiMg
.
GroupOwnerBand
.
GO_BAND_2GHZ
,
};
let
createGroupResult
=
wifi
.
createGroup
(
wifiP2PConfig
);
await
sleep
(
2000
);
await
wifi
.
getCurrentP2pGroup
()
.
then
(
data
=>
{
console
.
info
(
"
[wifi_test]getCurrentP2pGroup promise result :
"
+
JSON
.
stringify
(
data
));
});
let
removeGroupResult
=
wifi
.
removeGroup
();
await
sleep
(
2000
);
await
wifiMg
.
getCurrentP2pGroup
()
.
then
(
data
=>
{
console
.
info
(
"
[wifi_test] getCurrentP2pGroup promise result1 :
"
+
JSON
.
stringify
(
data
));
expect
(
true
).
assertEqual
(
data
.
deviceName
==
null
);
}).
catch
((
error
)
=>
{
console
.
error
(
'
[wifi_test] getCurrentP2pGroup promise failed :
'
+
JSON
.
stringify
(
error
));
expect
(
true
).
assertEqual
(
error
!=
null
);
});
}
catch
(
error
){
console
.
info
(
"
[wifi_test]createGroup error passphrase result :
"
+
JSON
.
stringify
(
error
.
message
));
expect
(
true
).
assertEqual
(
(
JSON
.
stringify
(
error
.
message
))
!=
null
);
}
done
();
})
/**
* @tc.number SUB_Communication_WiFi_XTS_P2P_0308
* @tc.name testCreateGroup
* @tc.desc Test createGroup-the password must be a space.
* @tc.type Function
* @tc.level Level 0
*/
it
(
'
SUB_Communication_WiFi_XTS_P2P_0308
'
,
0
,
async
function
(
done
)
{
console
.
log
(
"
[wifi_test]check the state of wifi:
"
+
wifiMg
.
isWifiActive
());
expect
(
wifiMg
.
isWifiActive
()).
assertTrue
();
try
{
let
wifiP2PConfig
=
{
deviceAddress
:
"
00:00:00:00:00:00
"
,
netId
:
-
1
,
passphrase
:
"
"
,
groupName
:
"
testpassword
"
,
goBand
:
wifiMg
.
GroupOwnerBand
.
GO_BAND_2GHZ
,
};
let
createGroupResult
=
wifi
.
createGroup
(
wifiP2PConfig
);
await
sleep
(
2000
);
await
wifi
.
getCurrentP2pGroup
()
.
then
(
data
=>
{
console
.
info
(
"
[wifi_test] getCurrentP2pGroup promise result :
"
+
JSON
.
stringify
(
data
));
});
let
removeGroupResult
=
wifi
.
removeGroup
();
await
sleep
(
2000
);
await
wifiMg
.
getCurrentP2pGroup
()
.
then
(
data
=>
{
console
.
info
(
"
[wifi_test] getCurrentP2pGroup promise result1 :
"
+
JSON
.
stringify
(
data
));
expect
(
true
).
assertEqual
(
data
.
deviceName
==
null
);
}).
catch
((
error
)
=>
{
console
.
error
(
'
[wifi_test] getCurrentP2pGroup promise failed :
'
+
JSON
.
stringify
(
error
));
expect
(
true
).
assertEqual
(
error
!=
null
);
});
}
catch
(
error
){
console
.
info
(
"
[wifi_test]createGroup error passphrase result :
"
+
JSON
.
stringify
(
error
.
message
));
expect
(
true
).
assertEqual
(
(
JSON
.
stringify
(
error
.
message
))
!=
null
);
}
done
();
})
/**
* @tc.number SUB_Communication_WiFi_XTS_P2P_0009
* @tc.name testP2pCancelConnect
* @tc.desc Test p2pCancelConnect Group API functionality.
* @tc.type Function
* @tc.level Level 3
*/
it
(
'
SUB_Communication_WiFi_XTS_P2P_0009
'
,
0
,
async
function
(
done
)
{
let
wifiP2PConfig
=
{
deviceAddress
:
"
11:22:33:44:55:66
"
,
netId
:
-
1
,
passphrase
:
"
12345678
"
,
groupName
:
"
AAAZZZ456
"
,
goBand
:
wifiMg
.
GroupOwnerBand
.
GO_BAND_2GHZ
,
};
let
p2pConnectResult
=
wifiMg
.
p2pConnect
(
wifiP2PConfig
);
console
.
info
(
"
[wifi_test]test p2pConnect successful.
"
);
let
p2pCancelResult
=
wifiMg
.
p2pCancelConnect
();
await
sleep
(
2000
);
console
.
info
(
"
[wifi_test]test p2pCancelConnect successful.
"
);
let
removeGroupResult
=
wifiMg
.
removeGroup
();
console
.
info
(
"
[wifi_test]test removeGroup successful
"
);
try
{
await
wifiMg
.
getCurrentP2pGroup
()
.
then
(
data
=>
{
console
.
info
(
"
[wifi_test] getCurrentP2pGroup promise result1 :
"
+
JSON
.
stringify
(
data
));
expect
(
true
).
assertEqual
(
data
.
deviceName
==
null
);
}).
catch
((
error
)
=>
{
console
.
error
(
'
[wifi_test] getCurrentP2pGroup promise failed :
'
+
JSON
.
stringify
(
error
));
expect
(
true
).
assertEqual
(
error
!=
null
);
});
}
catch
(
error
){
console
.
info
(
"
[wifi_test]getCurrentP2pGroup promise error:
"
+
JSON
.
stringify
(
error
.
message
));
expect
(
true
).
assertEqual
(
(
JSON
.
stringify
(
error
.
message
))
!=
null
);
}
done
();
})
/**
* @tc.number SUB_Communication_WiFi_XTS_P2P_0011
* @tc.name testRemoveGroup
* @tc.desc Test remove a nonexistent group.
* @tc.type Function
* @tc.level Level 3
*/
it
(
'
SUB_Communication_WiFi_XTS_P2P_0011
'
,
0
,
async
function
(
done
)
{
let
removeGroupResult
=
wifiMg
.
removeGroup
(
10000
);
await
wifiMg
.
getCurrentP2pGroup
()
.
then
(
data
=>
{
console
.
info
(
"
[wifi_test] getCurrentP2pGroup promise result1 :
"
+
JSON
.
stringify
(
data
));
expect
(
true
).
assertEqual
(
data
.
deviceName
==
null
);
});
done
();
})
/**
* @tc.number SUB_Communication_WiFi_XTS_P2P_0002
* @tc.name testP2pLocalDevice
* @tc.desc Test get P2pLocalDevice API functionality.
* @tc.type Function
* @tc.level Level 3
*/
it
(
'
SUB_Communication_WiFi_XTS_P2P_0002
'
,
0
,
async
function
(
done
)
{
await
wifiMg
.
getP2pLocalDevice
()
.
then
(
data
=>
{
console
.
info
(
"
[wifi_test]getP2pLocalDevice promise result :
"
+
JSON
.
stringify
(
data
));
expect
(
true
).
assertEqual
(
data
.
deviceName
!=
null
);
}).
catch
((
error
)
=>
{
console
.
info
(
"
[wifi_test]getP2pLocalDevice promise error.
"
+
JSON
.
stringify
(
error
));
expect
().
assertFail
();
});
function
getP2pLocal
(){
return
new
Promise
((
resolve
,
reject
)
=>
{
wifiMg
.
getP2pLocalDevice
(
(
err
,
ret
)
=>
{
if
(
err
)
{
console
.
info
(
"
[wifi_test]getP2pLocalDevice callback failed :
"
+
JSON
.
stringify
(
err
));
return
;
}
console
.
info
(
"
[wifi_test]getP2pLocalDevice callback result:
"
+
JSON
.
stringify
(
ret
));
console
.
info
(
"
deviceName:
"
+
ret
.
deviceName
+
"
deviceAddress:
"
+
ret
.
deviceAddress
+
"
primaryDeviceType:
"
+
ret
.
primaryDeviceType
+
"
deviceStatus:
"
+
ret
.
deviceStatus
+
"
groupCapabilitys:
"
+
ret
.
groupCapabilitys
);
resolve
();
});
});
}
await
getP2pLocal
();
done
();
})
/**
* @tc.number SUB_Communication_WiFi_XTS_P2P_0010
* @tc.name testGetP2pLinkedInfo
* @tc.desc Test getP2pLinkedInfo API functionality
* @tc.type Function
* @tc.level Level 2
*/
it
(
'
SUB_Communication_WiFi_XTS_P2P_0010
'
,
0
,
async
function
(
done
)
{
let
p2pConnectState
=
{
DISCONNECTED
:
0
,
CONNECTED
:
1
,
};
await
wifiMg
.
getP2pLinkedInfo
()
.
then
(
data
=>
{
let
resultLength
=
Object
.
keys
(
data
).
length
;
console
.
info
(
"
[wifi_test]getP2pLinkedInfo promise result :
"
+
JSON
.
stringify
(
data
));
expect
(
true
).
assertEqual
(
resultLength
!=
0
);
done
()
});
function
getP2pLinkedInfoResult
(){
return
new
Promise
((
resolve
,
reject
)
=>
{
wifiMg
.
getP2pLinkedInfo
(
(
err
,
result
)
=>
{
if
(
err
)
{
console
.
info
(
"
[wifi_test]failed to getP2pLinkedInfo callback:
"
+
JSON
.
stringify
(
err
));
return
;
}
let
resultLength
=
Object
.
keys
(
result
).
length
;
console
.
info
(
"
[wifi_test]getP2pLinkedInfo callback:
"
+
JSON
.
stringify
(
resultLength
));
console
.
info
(
"
connectState:
"
+
result
.
connectState
+
"
isGroupOwner:
"
+
result
.
isGroupOwner
+
"
groupOwnerAddr:
"
+
result
.
groupOwnerAddr
);
expect
(
true
).
assertEqual
(
resultLength
!=
0
);
resolve
();
});
});
}
await
getP2pLinkedInfoResult
();
done
();
})
/**
* @tc.number SUB_Communication_WiFi_XTS_P2P_0001
* @tc.name testGetP2pPeerDevices
* @tc.desc Test getP2pPeerDevices promise API functionality
* @tc.type Function
* @tc.level Level 0
*/
it
(
'
SUB_Communication_WiFi_XTS_P2P_0001
'
,
0
,
async
function
(
done
){
console
.
log
(
"
[wifi_test]check the state of wifi:
"
+
wifiMg
.
isWifiActive
());
expect
(
wifiMg
.
isWifiActive
()).
assertTrue
();
let
startDiscover
=
wifiMg
.
startDiscoverDevices
();
await
sleep
(
2000
);
await
wifiMg
.
getP2pPeerDevices
()
.
then
((
data
)
=>
{
let
resultLength
=
Object
.
keys
(
data
).
length
;
console
.
info
(
"
[wifi_test]getP2pPeerDevices promise result ->
"
+
JSON
.
stringify
(
data
));
expect
(
true
).
assertEqual
(
resultLength
>=
0
);
}).
catch
((
error
)
=>
{
console
.
info
(
"
[wifi_test]getP2pPeerDevices promise then error.
"
+
JSON
.
stringify
(
error
));
expect
().
assertFail
();
});
let
stopDiscover
=
wifiMg
.
stopDiscoverDevices
();
done
();
})
/**
* @tc.number SUB_Communication_WiFi_XTS_P2P_0101
* @tc.name testGetP2pPeerDevices
* @tc.desc Test getP2pPeerDevices callback API functionality
* @tc.type Function
* @tc.level Level 0
*/
it
(
'
SUB_Communication_WiFi_XTS_P2P_0101
'
,
0
,
async
function
(
done
){
console
.
log
(
"
[wifi_test]check the state of wifi:
"
+
wifiMg
.
isWifiActive
());
expect
(
wifiMg
.
isWifiActive
()).
assertTrue
();
let
startDiscover
=
wifiMg
.
startDiscoverDevices
();
await
sleep
(
2000
);
function
getP2pPeerDevicesResult
(){
return
new
Promise
((
resolve
,
reject
)
=>
{
wifiMg
.
getP2pPeerDevices
(
(
err
,
result
)
=>
{
if
(
err
)
{
console
.
error
(
'
[wifi_test]failed to getP2pPeerDevices :
'
+
JSON
.
stringify
(
err
));
}
console
.
info
(
"
[wifi_test] getP2pPeerDevices callback result :
"
+
JSON
.
stringify
(
result
));
let
len
=
Object
.
keys
(
result
).
length
;
for
(
let
j
=
0
;
j
<
len
;
++
j
)
{
console
.
info
(
"
deviceName:
"
+
result
[
j
].
deviceName
+
"
deviceAddress:
"
+
result
[
j
].
deviceAddress
+
"
primaryDeviceType:
"
+
result
[
j
].
primaryDeviceType
+
"
deviceStatus:
"
+
result
[
j
].
deviceStatus
+
"
groupCapabilitys:
"
+
result
[
j
].
groupCapabilitys
);
if
(
result
[
j
].
deviceStatus
==
wifiMg
.
P2pDeviceStatus
.
UNAVAILABLE
){
console
.
info
(
"
deviceStatus:
"
+
result
[
j
].
deviceStatus
);
}
if
(
result
[
j
].
deviceStatus
==
wifiMg
.
P2pDeviceStatus
.
CONNECTED
){
console
.
info
(
"
deviceStatus:
"
+
result
[
j
].
deviceStatus
);
}
if
(
result
[
j
].
deviceStatus
==
wifiMg
.
P2pDeviceStatus
.
INVITED
){
console
.
info
(
"
deviceStatus:
"
+
result
[
j
].
deviceStatus
);
}
if
(
result
[
j
].
deviceStatus
==
wifiMg
.
P2pDeviceStatus
.
FAILED
){
console
.
info
(
"
deviceStatus:
"
+
result
[
j
].
deviceStatus
);
}
if
(
result
[
j
].
deviceStatus
==
wifiMg
.
P2pDeviceStatus
.
AVAILABLE
){
console
.
info
(
"
deviceStatus:
"
+
result
[
j
].
deviceStatus
);
}
}
resolve
();
});
});
}
await
getP2pPeerDevicesResult
();
done
();
});
console
.
log
(
"
*************[wifi_test] start wifi js unit test end*************
"
);
})
}
communication/wifi_p2p/src/main/js/test/WifiP2PEvent.test.js
浏览文件 @
0cab7285
/*
* Copyright (C) 2022 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import
{
describe
,
beforeAll
,
beforeEach
,
afterEach
,
afterAll
,
it
,
expect
}
from
'
@ohos/hypium
'
import
wifi
from
'
@ohos.wifi
'
function
sleep
(
delay
)
{
return
new
Promise
(
resovle
=>
setTimeout
(
resovle
,
delay
))
}
function
checkWifiPowerOn
(){
console
.
info
(
"
[wifi_test]wifi status:
"
+
wifi
.
isWifiActive
());
}
export
default
function
actsWifiEventTest
()
{
describe
(
'
actsWifiEventTest
'
,
function
()
{
beforeEach
(
function
()
{
console
.
info
(
"
[wifi_test]beforeEach start
"
);
checkWifiPowerOn
();
})
afterEach
(
async
function
()
{
console
.
info
(
"
[wifi_test]afterEach start
"
);
})
/**
* @tc.number Communication_WiFi_Event_Test_0008
* @tc.name testp2pStateChange
* @tc.desc Test p2pStateChange callback
* @tc.type Function
* @tc.level Level 3
*/
it
(
'
Communication_WiFi_Event_Test_0008
'
,
0
,
async
function
(
done
)
{
let
p2pState
=
"
p2pStateChange
"
;
let
p2pStateChangeCallback
=
result
=>
{
console
.
info
(
"
[wifi_test]p2pStateChange callback, result:
"
+
JSON
.
stringify
(
result
));
}
wifi
.
on
(
p2pState
,
p2pStateChangeCallback
);
await
sleep
(
3000
);
wifi
.
off
(
p2pState
,
p2pStateChangeCallback
);
done
();
})
/**
* @tc.number Communication_WiFi_Event_Test_0009
* @tc.name testp2pConnectionChange
* @tc.desc Test p2pConnectionChange callback
* @tc.type Function
* @tc.level Level 3
*/
it
(
'
Communication_WiFi_Event_Test_0009
'
,
0
,
async
function
(
done
)
{
let
p2pConnectionState
=
"
p2pConnectionChange
"
;
let
p2pConnectionChangeCallback
=
result
=>
{
console
.
info
(
"
[wifi_test]p2pConnectionChange callback, result:
"
+
JSON
.
stringify
(
result
));
}
wifi
.
on
(
p2pConnectionState
,
p2pConnectionChangeCallback
);
let
wifiP2PConfig
=
{
deviceAddress
:
"
00:00:00:00:00:00
"
,
netId
:
-
1
,
passphrase
:
"
12345678
"
,
groupName
:
"
AAAZZZ456
"
,
goBand
:
wifi
.
GroupOwnerBand
.
GO_BAND_AUTO
};
let
connectResult
=
wifi
.
p2pConnect
(
wifiP2PConfig
);
console
.
info
(
"
[wifi_test]test p2pConnect result.
"
+
connectResult
);
await
wifi
.
getP2pLinkedInfo
()
.
then
(
data
=>
{
let
resultLength
=
Object
.
keys
(
data
).
length
;
console
.
info
(
"
[wifi_test]getP2pLinkedInfo promise result :
"
+
JSON
.
stringify
(
data
));
expect
(
true
).
assertEqual
(
resultLength
!=
0
);
done
()
});
await
sleep
(
2000
);
wifi
.
off
(
p2pConnectionState
,
p2pConnectionChangeCallback
);
let
removeGroupResult
=
wifi
.
removeGroup
();
console
.
info
(
"
[wifi_test]test start removeGroup:
"
+
removeGroupResult
);
expect
(
removeGroupResult
).
assertTrue
();
done
();
})
/**
* @tc.number Communication_WiFi_Event_Test_0012
* @tc.name testp2pDeviceChange
* @tc.desc Test p2pDeviceChange callback
* @tc.type Function
* @tc.level Level 3
*/
it
(
'
Communication_WiFi_Event_Test_0012
'
,
0
,
async
function
(
done
)
{
let
p2pDeviceState
=
"
p2pDeviceChange
"
;
let
p2pDeviceChangeCallback
=
result
=>
{
console
.
info
(
"
[wifi_test]p2pDeviceChange callback, result:
"
+
JSON
.
stringify
(
result
));
}
wifi
.
on
(
p2pDeviceState
,
p2pDeviceChangeCallback
);
await
sleep
(
3000
);
wifi
.
off
(
p2pDeviceState
,
p2pDeviceChangeCallback
);
done
();
})
/**
* @tc.number Communication_WiFi_Event_Test_0010
* @tc.name testp2pPeerDeviceChange
* @tc.desc Test p2pPeerDeviceChange callback
* @tc.type Function
* @tc.level Level 3
*/
it
(
'
Communication_WiFi_Event_Test_0010
'
,
0
,
async
function
(
done
)
{
let
p2pPeerDeviceState
=
"
p2pPeerDeviceChange
"
;
let
p2pPeerDeviceChangeCallback
=
result
=>
{
console
.
info
(
"
[wifi_test]p2pPeerDeviceChange callback, result:
"
+
JSON
.
stringify
(
result
));
}
wifi
.
on
(
p2pPeerDeviceState
,
p2pPeerDeviceChangeCallback
);
let
startDiscover
=
wifi
.
startDiscoverDevices
();
await
sleep
(
3000
);
expect
(
startDiscover
).
assertTrue
();
let
stopDiscover
=
wifi
.
stopDiscoverDevices
();
console
.
info
(
"
[wifi_test] test stopDiscoverDevices result.
"
+
stopDiscover
);
wifi
.
off
(
p2pPeerDeviceState
,
p2pPeerDeviceChangeCallback
);
done
();
})
/**
* @tc.number Communication_WiFi_Event_Test_0013
* @tc.name testp2pPersistentGroupChange
* @tc.desc Test p2pPersistentGroupChange callback
* @tc.type Function
* @tc.level Level 3
*/
it
(
'
Communication_WiFi_Event_Test_0013
'
,
0
,
async
function
(
done
)
{
let
p2pGroupState
=
"
p2pPersistentGroupChange
"
;
let
p2pPersistentGroupChangeCallback
=
()
=>
{
console
.
info
(
"
[wifi_test]p2pPersistentGroupChange callback, result:
"
+
JSON
.
stringify
(
result
));
}
wifi
.
on
(
p2pGroupState
,
p2pPersistentGroupChangeCallback
);
let
WifiP2PConfig
=
{
deviceAddress
:
"
00:00:00:00:00:00
"
,
netId
:
-
2
,
passphrase
:
"
12345678
"
,
groupName
:
"
AAAZZZ123
"
,
goBand
:
wifi
.
GroupOwnerBand
.
GO_BAND_AUTO
,
};
let
createGroupResult
=
wifi
.
createGroup
(
WifiP2PConfig
);
await
(
2000
);
console
.
info
(
"
[wifi_test] test createGroup result.
"
+
createGroupResult
)
expect
(
createGroupResult
).
assertTrue
();
await
wifi
.
getCurrentGroup
()
.
then
(
data
=>
{
let
resultLength
=
Object
.
keys
(
data
).
length
;
console
.
info
(
"
[wifi_test] getCurrentGroup promise result ->
"
+
JSON
.
stringify
(
data
));
expect
(
true
).
assertEqual
(
resultLength
!=
0
);
});
wifi
.
off
(
p2pGroupState
,
p2pPersistentGroupChangeCallback
);
done
();
})
/**
* @tc.number Communication_WiFi_Event_Test_0011
* @tc.name testpp2pDiscoveryChange
* @tc.desc Test p2pDiscoveryChange callback
* @tc.type Function
* @tc.level Level 3
*/
it
(
'
Communication_WiFi_Event_Test_0011
'
,
0
,
async
function
(
done
)
{
let
p2pPeerDeviceState
=
"
p2pDiscoveryChange
"
;
let
p2pDiscoveryChangeCallback
=
result
=>
{
console
.
info
(
"
[wifi_test]p2pDiscoveryChange callback, result:
"
+
JSON
.
stringify
(
result
));
}
wifi
.
on
(
p2pPeerDeviceState
,
p2pDiscoveryChangeCallback
);
let
startDiscover
=
wifi
.
startDiscoverDevices
();
await
sleep
(
3000
);
expect
(
startDiscover
).
assertTrue
();
let
stopDiscover
=
wifi
.
stopDiscoverDevices
();
console
.
info
(
"
[wifi_test] test stopDiscoverDevices result.
"
+
stopDiscover
);
wifi
.
off
(
p2pPeerDeviceState
,
p2pDiscoveryChangeCallback
);
done
();
})
console
.
log
(
"
*************[wifi_test] start wifi js unit test end*************
"
);
})
}
/*
* Copyright (C) 2022 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import
{
describe
,
beforeAll
,
beforeEach
,
afterEach
,
afterAll
,
it
,
expect
}
from
'
@ohos/hypium
'
import
wifi
from
'
@ohos.wifi
'
function
sleep
(
delay
)
{
return
new
Promise
(
resovle
=>
setTimeout
(
resovle
,
delay
))
}
function
checkWifiPowerOn
(){
console
.
info
(
"
[wifi_test]wifi status:
"
+
wifi
.
isWifiActive
());
}
export
default
function
actsWifiEventTest
()
{
describe
(
'
actsWifiEventTest
'
,
function
()
{
beforeEach
(
function
()
{
console
.
info
(
"
[wifi_test]beforeEach start
"
);
checkWifiPowerOn
();
})
afterEach
(
async
function
()
{
console
.
info
(
"
[wifi_test]afterEach start
"
);
})
/**
* @tc.number Communication_WiFi_Event_Test_0008
* @tc.name testp2pStateChange
* @tc.desc Test p2pStateChange callback
* @tc.type Function
* @tc.level Level 3
*/
it
(
'
Communication_WiFi_Event_Test_0008
'
,
0
,
async
function
(
done
)
{
let
p2pState
=
"
p2pStateChange
"
;
let
p2pStateChangeCallback
=
result
=>
{
console
.
info
(
"
[wifi_test]p2pStateChange callback, result:
"
+
JSON
.
stringify
(
result
));
}
wifi
.
on
(
p2pState
,
p2pStateChangeCallback
);
await
sleep
(
3000
);
wifi
.
off
(
p2pState
,
p2pStateChangeCallback
);
done
();
})
/**
* @tc.number Communication_WiFi_Event_Test_0009
* @tc.name testp2pConnectionChange
* @tc.desc Test p2pConnectionChange callback
* @tc.type Function
* @tc.level Level 3
*/
it
(
'
Communication_WiFi_Event_Test_0009
'
,
0
,
async
function
(
done
)
{
let
p2pConnectionState
=
"
p2pConnectionChange
"
;
let
p2pConnectionChangeCallback
=
result
=>
{
console
.
info
(
"
[wifi_test]p2pConnectionChange callback, result:
"
+
JSON
.
stringify
(
result
));
}
wifi
.
on
(
p2pConnectionState
,
p2pConnectionChangeCallback
);
let
wifiP2PConfig
=
{
deviceAddress
:
"
00:00:00:00:00:00
"
,
netId
:
-
1
,
passphrase
:
"
12345678
"
,
groupName
:
"
AAAZZZ456
"
,
goBand
:
wifi
.
GroupOwnerBand
.
GO_BAND_AUTO
};
let
connectResult
=
wifi
.
p2pConnect
(
wifiP2PConfig
);
console
.
info
(
"
[wifi_test]test p2pConnect result.
"
+
connectResult
);
await
wifi
.
getP2pLinkedInfo
()
.
then
(
data
=>
{
let
resultLength
=
Object
.
keys
(
data
).
length
;
console
.
info
(
"
[wifi_test]getP2pLinkedInfo promise result :
"
+
JSON
.
stringify
(
data
));
expect
(
true
).
assertEqual
(
resultLength
!=
0
);
done
()
});
await
sleep
(
2000
);
wifi
.
off
(
p2pConnectionState
,
p2pConnectionChangeCallback
);
let
removeGroupResult
=
wifi
.
removeGroup
();
console
.
info
(
"
[wifi_test]test start removeGroup:
"
+
removeGroupResult
);
expect
(
removeGroupResult
).
assertTrue
();
done
();
})
/**
* @tc.number Communication_WiFi_Event_Test_0012
* @tc.name testp2pDeviceChange
* @tc.desc Test p2pDeviceChange callback
* @tc.type Function
* @tc.level Level 3
*/
it
(
'
Communication_WiFi_Event_Test_0012
'
,
0
,
async
function
(
done
)
{
let
p2pDeviceState
=
"
p2pDeviceChange
"
;
let
p2pDeviceChangeCallback
=
result
=>
{
console
.
info
(
"
[wifi_test]p2pDeviceChange callback, result:
"
+
JSON
.
stringify
(
result
));
}
wifi
.
on
(
p2pDeviceState
,
p2pDeviceChangeCallback
);
await
sleep
(
3000
);
wifi
.
off
(
p2pDeviceState
,
p2pDeviceChangeCallback
);
done
();
})
/**
* @tc.number Communication_WiFi_Event_Test_0010
* @tc.name testp2pPeerDeviceChange
* @tc.desc Test p2pPeerDeviceChange callback
* @tc.type Function
* @tc.level Level 3
*/
it
(
'
Communication_WiFi_Event_Test_0010
'
,
0
,
async
function
(
done
)
{
let
p2pPeerDeviceState
=
"
p2pPeerDeviceChange
"
;
let
p2pPeerDeviceChangeCallback
=
result
=>
{
console
.
info
(
"
[wifi_test]p2pPeerDeviceChange callback, result:
"
+
JSON
.
stringify
(
result
));
}
wifi
.
on
(
p2pPeerDeviceState
,
p2pPeerDeviceChangeCallback
);
let
startDiscover
=
wifi
.
startDiscoverDevices
();
await
sleep
(
3000
);
expect
(
startDiscover
).
assertTrue
();
let
stopDiscover
=
wifi
.
stopDiscoverDevices
();
console
.
info
(
"
[wifi_test] test stopDiscoverDevices result.
"
+
stopDiscover
);
wifi
.
off
(
p2pPeerDeviceState
,
p2pPeerDeviceChangeCallback
);
done
();
})
/**
* @tc.number Communication_WiFi_Event_Test_0013
* @tc.name testp2pPersistentGroupChange
* @tc.desc Test p2pPersistentGroupChange callback
* @tc.type Function
* @tc.level Level 3
*/
it
(
'
Communication_WiFi_Event_Test_0013
'
,
0
,
async
function
(
done
)
{
let
p2pGroupState
=
"
p2pPersistentGroupChange
"
;
let
p2pPersistentGroupChangeCallback
=
()
=>
{
console
.
info
(
"
[wifi_test]p2pPersistentGroupChange callback, result:
"
+
JSON
.
stringify
(
result
));
}
wifi
.
on
(
p2pGroupState
,
p2pPersistentGroupChangeCallback
);
let
WifiP2PConfig
=
{
deviceAddress
:
"
00:00:00:00:00:00
"
,
netId
:
-
2
,
passphrase
:
"
12345678
"
,
groupName
:
"
AAAZZZ123
"
,
goBand
:
wifi
.
GroupOwnerBand
.
GO_BAND_AUTO
,
};
let
createGroupResult
=
wifi
.
createGroup
(
WifiP2PConfig
);
await
(
2000
);
console
.
info
(
"
[wifi_test] test createGroup result.
"
+
createGroupResult
)
expect
(
createGroupResult
).
assertTrue
();
try
{
await
wifi
.
getCurrentGroup
()
.
then
(
data
=>
{
let
resultLength
=
Object
.
keys
(
data
).
length
;
console
.
info
(
"
[wifi_test] getCurrentGroup promise result ->
"
+
JSON
.
stringify
(
data
));
expect
(
true
).
assertEqual
(
resultLength
!=
0
);
}).
catch
((
error
)
=>
{
console
.
error
(
'
[wifi_test] getCurrentGroup promise failed :
'
+
JSON
.
stringify
(
error
));
expect
(
true
).
assertEqual
(
error
!=
null
);
});
}
catch
(
error
){
console
.
info
(
"
[wifi_test]getCurrentGroup promise error:
"
+
JSON
.
stringify
(
error
.
message
));
expect
(
true
).
assertEqual
(
(
JSON
.
stringify
(
error
.
message
))
!=
null
);
}
wifi
.
off
(
p2pGroupState
,
p2pPersistentGroupChangeCallback
);
done
();
})
/**
* @tc.number Communication_WiFi_Event_Test_0011
* @tc.name testpp2pDiscoveryChange
* @tc.desc Test p2pDiscoveryChange callback
* @tc.type Function
* @tc.level Level 3
*/
it
(
'
Communication_WiFi_Event_Test_0011
'
,
0
,
async
function
(
done
)
{
let
p2pPeerDeviceState
=
"
p2pDiscoveryChange
"
;
let
p2pDiscoveryChangeCallback
=
result
=>
{
console
.
info
(
"
[wifi_test]p2pDiscoveryChange callback, result:
"
+
JSON
.
stringify
(
result
));
}
wifi
.
on
(
p2pPeerDeviceState
,
p2pDiscoveryChangeCallback
);
let
startDiscover
=
wifi
.
startDiscoverDevices
();
await
sleep
(
3000
);
expect
(
startDiscover
).
assertTrue
();
let
stopDiscover
=
wifi
.
stopDiscoverDevices
();
console
.
info
(
"
[wifi_test] test stopDiscoverDevices result.
"
+
stopDiscover
);
wifi
.
off
(
p2pPeerDeviceState
,
p2pDiscoveryChangeCallback
);
done
();
})
console
.
log
(
"
*************[wifi_test] start wifi js unit test end*************
"
);
})
}
communication/wifi_p2p/src/main/js/test/WifiP2PFunction.test.js
浏览文件 @
0cab7285
/*
* Copyright (C) 2022 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import
{
describe
,
beforeAll
,
beforeEach
,
afterEach
,
afterAll
,
it
,
expect
}
from
'
@ohos/hypium
'
import
wifi
from
'
@ohos.wifi
'
function
sleep
(
delay
)
{
return
new
Promise
(
resovle
=>
setTimeout
(
resovle
,
delay
))
}
function
checkWifiPowerOn
(){
console
.
info
(
"
[wifi_test]/wifi status:
"
+
wifi
.
isWifiActive
());
}
export
default
function
actsWifiFunctionTest
()
{
describe
(
'
actsWifiFunctionTest
'
,
function
()
{
beforeEach
(
function
()
{
console
.
info
(
"
[wifi_test]beforeEach start
"
);
checkWifiPowerOn
();
})
afterEach
(
async
function
()
{
console
.
info
(
"
[wifi_test]afterEach start
"
);
})
/**
* @tc.number Communication_WiFi_XTS_P2P_0003
* @tc.name testCreateGroup
* @tc.desc Test createGroup and getCurrentGroup API Function
* @tc.type Function
* @tc.level Level 3
*/
it
(
'
Communication_WiFi_XTS_P2P_0003
'
,
0
,
async
function
(
done
)
{
let
wifiP2PConfig
=
{
deviceAddress
:
"
00:00:00:00:00:00
"
,
netId
:
-
1
,
passphrase
:
"
12345678
"
,
groupName
:
"
AAAZZZ123
"
,
goBand
:
wifi
.
GroupOwnerBand
.
GO_BAND_2GHZ
,
};
console
.
log
(
"
[wifi_test]check the state of wifi:
"
+
wifi
.
isWifiActive
());
expect
(
wifi
.
isWifiActive
()).
assertTrue
();
let
createGroupResult
=
wifi
.
createGroup
(
wifiP2PConfig
);
console
.
log
(
"
[wifi_test]createGroup result:
"
+
JSON
.
stringify
(
createGroupResult
));
await
sleep
(
2000
);
expect
(
createGroupResult
).
assertTrue
();
await
wifi
.
getCurrentGroup
()
.
then
(
data
=>
{
console
.
info
(
"
[wifi_test]getCurrentGroup promise result ->
"
+
JSON
.
stringify
(
data
));
expect
(
true
).
assertEqual
(
data
.
groupName
==
wifiP2PConfig
.
groupName
);
});
function
getCurrentGroupResult
(){
return
new
Promise
((
resolve
,
reject
)
=>
{
wifi
.
getCurrentGroup
(
(
err
,
result
)
=>
{
if
(
err
)
{
console
.
info
(
"
[wifi_test]failed to get getCurrentGroup:
"
+
JSON
.
stringify
(
err
));
expect
().
assertFail
();
}
console
.
info
(
"
[wifi_test]getCurrentGroup callback:
"
+
JSON
.
stringify
(
result
));
console
.
info
(
"
isP2pGo:
"
+
result
.
isP2pGo
+
"
deviceName:
"
+
result
.
ownerInfo
.
deviceName
+
"
deviceAddress:
"
+
result
.
ownerInfo
.
deviceAddress
+
"
primaryDeviceType:
"
+
result
.
ownerInfo
.
primaryDeviceType
+
"
deviceStatus:
"
+
result
.
ownerInfo
.
deviceStatus
+
"
groupCapabilitys:
"
+
result
.
ownerInfo
.
groupCapabilitys
+
"
passphrase:
"
+
result
.
passphrase
+
"
interface:
"
+
result
.
interface
+
"
groupName:
"
+
result
.
groupName
+
"
frequency:
"
+
result
.
frequency
+
"
goIpAddress:
"
+
result
.
goIpAddress
);
console
.
info
(
"
[wifi_test] clientDevices:
"
+
JSON
.
stringify
(
result
.
clientDevices
));
console
.
info
(
"
[wifi_test] ownerInfo:
"
+
JSON
.
stringify
(
result
.
WifiP2pDevice
));
resolve
();
});
});
}
await
getCurrentGroupResult
();
let
removeGroupResult
=
wifi
.
removeGroup
();
await
sleep
(
2000
);
expect
(
removeGroupResult
).
assertTrue
();
await
wifi
.
getCurrentGroup
()
.
then
(
data
=>
{
console
.
info
(
"
[wifi_test] getCurrentGroup promise result1 :
"
+
JSON
.
stringify
(
data
));
expect
(
true
).
assertEqual
(
data
.
deviceName
==
null
);
});
done
();
})
/**
* @tc.number Communication_WiFi_XTS_P2P_0004
* @tc.name testCreateGroup
* @tc.desc Test createGroup-Setting a 7-bit Key Function.
* @tc.type Function
* @tc.level Level 3
*/
it
(
'
Communication_WiFi_XTS_P2P_0004
'
,
0
,
async
function
(
done
)
{
console
.
log
(
"
[wifi_test]check the state of wifi:
"
+
wifi
.
isWifiActive
());
expect
(
wifi
.
isWifiActive
()).
assertTrue
();
let
wifiP2PConfig
=
{
deviceAddress
:
"
00:00:00:00:00:00
"
,
netId
:
-
1
,
passphrase
:
"
1234567
"
,
groupName
:
"
test_pass
"
,
goBand
:
wifi
.
GroupOwnerBand
.
GO_BAND_2GHZ
,
};
let
createGroupResult
=
wifi
.
createGroup
(
wifiP2PConfig
);
console
.
info
(
"
[wifi_test]test createGroup end.
"
+
JSON
.
stringify
(
createGroupResult
));
await
sleep
(
2000
);
expect
(
createGroupResult
).
assertTrue
();
await
wifi
.
getCurrentGroup
()
.
then
(
data
=>
{
console
.
info
(
"
[wifi_test] getCurrentGroup promise result :
"
+
JSON
.
stringify
(
data
));
expect
(
true
).
assertEqual
(
data
.
networkId
==
-
999
);
});
let
removeGroupResult
=
wifi
.
removeGroup
();
await
sleep
(
2000
);
expect
(
removeGroupResult
).
assertTrue
();
await
wifi
.
getCurrentGroup
()
.
then
(
data
=>
{
console
.
info
(
"
[wifi_test] getCurrentGroup promise result1 :
"
+
JSON
.
stringify
(
data
));
expect
(
true
).
assertEqual
(
data
.
deviceName
==
null
);
});
done
();
})
/**
* @tc.number Communication_WiFi_XTS_P2P_0104
* @tc.name testCreateGroup
* @tc.desc Test createGroup-Key setting: Chinese, English, and characters Function.
* @tc.type Function
* @tc.level Level 3
*/
it
(
'
Communication_WiFi_XTS_P2P_0104
'
,
0
,
async
function
(
done
)
{
console
.
log
(
"
[wifi_test]check the state of wifi:
"
+
wifi
.
isWifiActive
());
expect
(
wifi
.
isWifiActive
()).
assertTrue
();
let
wifiP2PConfig
=
{
deviceAddress
:
"
00:00:00:00:00:00
"
,
netId
:
-
1
,
passphrase
:
"
123@%abcD
"
,
groupName
:
"
test_pass1
"
,
goBand
:
wifi
.
GroupOwnerBand
.
GO_BAND_2GHZ
,
};
let
createGroupResult
=
wifi
.
createGroup
(
wifiP2PConfig
);
console
.
info
(
"
[wifi_test]test createGroup end.
"
+
JSON
.
stringify
(
createGroupResult
));
await
sleep
(
2000
);
expect
(
createGroupResult
).
assertTrue
();
await
wifi
.
getCurrentGroup
()
.
then
(
data
=>
{
console
.
info
(
"
[wifi_test]getCurrentGroup promise result :
"
+
JSON
.
stringify
(
data
));
expect
(
true
).
assertEqual
(
data
.
passphrase
==
wifiP2PConfig
.
passphrase
);
});
let
removeGroupResult
=
wifi
.
removeGroup
();
await
sleep
(
2000
);
expect
(
removeGroupResult
).
assertTrue
();
await
wifi
.
getCurrentGroup
()
.
then
(
data
=>
{
console
.
info
(
"
[wifi_test] getCurrentGroup promise result1 :
"
+
JSON
.
stringify
(
data
));
expect
(
true
).
assertEqual
(
data
.
deviceName
==
null
);
});
done
();
})
/**
* @tc.number Communication_WiFi_XTS_P2P_0204
* @tc.name testCreateGroup
* @tc.desc Test createGroup-Key setting 64 bit Function.
* @tc.type Function
* @tc.level Level 3
*/
it
(
'
Communication_WiFi_XTS_P2P_0204
'
,
0
,
async
function
(
done
)
{
console
.
log
(
"
[wifi_test]check the state of wifi:
"
+
wifi
.
isWifiActive
());
expect
(
wifi
.
isWifiActive
()).
assertTrue
();
let
wifiP2PConfig
=
{
deviceAddress
:
"
00:00:00:00:00:00
"
,
netId
:
-
1
,
passphrase
:
"
abc345678901234567890123456789012345678901234567890123456789012
"
,
groupName
:
"
test_pass2
"
,
goBand
:
wifi
.
GroupOwnerBand
.
GO_BAND_2GHZ
,
};
let
createGroupResult
=
wifi
.
createGroup
(
wifiP2PConfig
);
console
.
info
(
"
[wifi_test]test createGroup end.
"
+
JSON
.
stringify
(
createGroupResult
));
await
sleep
(
2000
);
expect
(
createGroupResult
).
assertTrue
();
await
wifi
.
getCurrentGroup
()
.
then
(
data
=>
{
console
.
info
(
"
[wifi_test]getCurrentGroup promise result :
"
+
JSON
.
stringify
(
data
));
expect
(
true
).
assertEqual
(
data
.
passphrase
==
wifiP2PConfig
.
passphrase
);
});
let
removeGroupResult
=
wifi
.
removeGroup
();
await
sleep
(
2000
);
expect
(
removeGroupResult
).
assertTrue
();
await
wifi
.
getCurrentGroup
()
.
then
(
data
=>
{
console
.
info
(
"
[wifi_test] getCurrentGroup promise result1 :
"
+
JSON
.
stringify
(
data
));
expect
(
true
).
assertEqual
(
data
.
deviceName
==
null
);
});
done
();
})
/**
* @tc.number Communication_WiFi_XTS_P2P_0304
* @tc.name testCreateGroup
* @tc.desc Test createGroup-Key setting 65 bitsFunction.
* @tc.type Function
* @tc.level Level 3
*/
it
(
'
Communication_WiFi_XTS_P2P_0304
'
,
0
,
async
function
(
done
)
{
console
.
log
(
"
[wifi_test]check the state of wifi:
"
+
wifi
.
isWifiActive
());
expect
(
wifi
.
isWifiActive
()).
assertTrue
();
let
wifiP2PConfig
=
{
deviceAddress
:
"
00:00:00:00:00:00
"
,
netId
:
-
1
,
passphrase
:
"
abc3456789012345678901234567890123456789012345678901234567890123
"
,
groupName
:
"
test_pass3
"
,
goBand
:
wifi
.
GroupOwnerBand
.
GO_BAND_2GHZ
,
};
let
createGroupResult
=
wifi
.
createGroup
(
wifiP2PConfig
);
console
.
info
(
"
[wifi_test]test createGroup end.
"
+
JSON
.
stringify
(
createGroupResult
));
await
sleep
(
2000
);
expect
(
createGroupResult
).
assertTrue
();
await
wifi
.
getCurrentGroup
()
.
then
(
data
=>
{
console
.
info
(
"
[wifi_test]getCurrentGroup promise result :
"
+
JSON
.
stringify
(
data
));
expect
(
true
).
assertEqual
(
data
.
passphrase
!=
wifiP2PConfig
.
passphrase
);
});
let
removeGroupResult
=
wifi
.
removeGroup
();
await
sleep
(
2000
);
expect
(
removeGroupResult
).
assertTrue
();
await
wifi
.
getCurrentGroup
()
.
then
(
data
=>
{
console
.
info
(
"
[wifi_test] getCurrentGroup promise result1 :
"
+
JSON
.
stringify
(
data
));
expect
(
true
).
assertEqual
(
data
.
deviceName
==
null
);
});
done
();
})
/**
* @tc.number Communication_WiFi_XTS_P2P_0007
* @tc.name testCreateGroup
* @tc.desc Test createGroup-2.4 GHz frequency band setting Function
* @tc.type Function
* @tc.level Level 0
*/
it
(
'
Communication_WiFi_XTS_P2P_0007
'
,
0
,
async
function
(
done
)
{
console
.
log
(
"
[wifi_test]check the state of wifi:
"
+
wifi
.
isWifiActive
());
expect
(
wifi
.
isWifiActive
()).
assertTrue
();
let
wifiP2PConfig
=
{
deviceAddress
:
"
00:00:00:00:00:00
"
,
netId
:
-
1
,
passphrase
:
"
12345678
"
,
groupName
:
"
test_band1
"
,
goBand
:
wifi
.
GroupOwnerBand
.
GO_BAND_2GHZ
,
};
let
createGroupResult
=
wifi
.
createGroup
(
wifiP2PConfig
);
await
sleep
(
2000
);
console
.
info
(
"
[wifi_test] test createGroup result.
"
+
createGroupResult
)
expect
(
createGroupResult
).
assertTrue
();
await
wifi
.
getCurrentGroup
()
.
then
(
data
=>
{
console
.
info
(
"
[wifi_test]getCurrentGroup promise result :
"
+
JSON
.
stringify
(
data
));
expect
(
true
).
assertEqual
(
2412
<
data
.
frequency
<
2484
);
});
let
removeGroupResult
=
wifi
.
removeGroup
();
await
sleep
(
2000
);
expect
(
removeGroupResult
).
assertTrue
();
await
wifi
.
getCurrentGroup
()
.
then
(
data
=>
{
console
.
info
(
"
[wifi_test] getCurrentGroup promise result1 :
"
+
JSON
.
stringify
(
data
));
expect
(
true
).
assertEqual
(
data
.
deviceName
==
null
);
});
done
();
})
/**
* @tc.number Communication_WiFi_XTS_P2P_0107
* @tc.name testCreateGroup
* @tc.desc Test createGroup-5 GHz frequency band setting Function
* @tc.type Function
* @tc.level Level 0
*/
it
(
'
Communication_WiFi_XTS_P2P_0107
'
,
0
,
async
function
(
done
)
{
console
.
log
(
"
[wifi_test]check the state of wifi:
"
+
wifi
.
isWifiActive
());
expect
(
wifi
.
isWifiActive
()).
assertTrue
();
try
{
let
wifiP2PConfig
=
{
deviceAddress
:
"
00:00:00:00:00:00
"
,
netId
:
-
1
,
passphrase
:
"
12345678
"
,
groupName
:
"
test_band2
"
,
goBand
:
wifi
.
GroupOwnerBand
.
GO_BAND_5GHZ
,
};
let
createGroupResult
=
wifi
.
createGroup
(
wifiP2PConfig
);
await
sleep
(
2000
);
console
.
info
(
"
[wifi_test]test createGroup result.
"
+
createGroupResult
)
expect
(
createGroupResult
).
assertTrue
();
await
wifi
.
getCurrentGroup
()
.
then
(
data
=>
{
console
.
info
(
"
[wifi_test] getCurrentGroup promise result :
"
+
JSON
.
stringify
(
data
));
expect
(
true
).
assertEqual
(
5160
<
data
.
frequency
<
5865
);
});
let
removeGroupResult
=
await
wifi
.
removeGroup
();
await
sleep
(
2000
);
expect
(
removeGroupResult
).
assertTrue
();
await
wifi
.
getCurrentGroup
()
.
then
(
data
=>
{
console
.
info
(
"
[wifi_test] getCurrentGroup promise result1 :
"
+
JSON
.
stringify
(
data
));
expect
(
true
).
assertEqual
(
data
.
deviceName
==
null
);
});
}
catch
(
error
){
console
.
info
(
"
[wifi_test]createGroup 5G goBand result :
"
+
JSON
.
stringify
(
error
.
message
));
expect
(
true
).
assertEqual
(
(
JSON
.
stringify
(
error
.
message
))
!=
null
);
}
done
();
})
/**
* @tc.number Communication_WiFi_XTS_P2P_0207
* @tc.name testCreateGroup
* @tc.desc Test createGroup-Auto frequency band setting Function
* @tc.type Function
* @tc.level Level 0
*/
it
(
'
Communication_WiFi_XTS_P2P_0207
'
,
0
,
async
function
(
done
)
{
console
.
log
(
"
[wifi_test]check the state of wifi:
"
+
wifi
.
isWifiActive
());
expect
(
wifi
.
isWifiActive
()).
assertTrue
();
try
{
let
wifiP2PConfig
=
{
deviceAddress
:
"
00:00:00:00:00:00
"
,
netId
:
-
1
,
passphrase
:
"
12345678
"
,
groupName
:
"
test_band3
"
,
goBand
:
wifi
.
GroupOwnerBand
.
GO_BAND_AUTO
,
};
let
createGroupResult
=
wifi
.
createGroup
(
wifiP2PConfig
);
await
sleep
(
2000
);
console
.
info
(
"
[wifi_test]test createGroup result.
"
+
createGroupResult
)
expect
(
createGroupResult
).
assertTrue
();
await
wifi
.
getCurrentGroup
()
.
then
(
data
=>
{
console
.
info
(
"
[wifi_test]getCurrentGroup promise result :
"
+
JSON
.
stringify
(
data
));
expect
(
true
).
assertEqual
(
data
.
frequency
!=
null
);
});
let
removeGroupResult
=
await
wifi
.
removeGroup
();
await
sleep
(
2000
);
expect
(
removeGroupResult
).
assertTrue
();
await
wifi
.
getCurrentGroup
()
.
then
(
data
=>
{
console
.
info
(
"
[wifi_test] getCurrentGroup promise result1 :
"
+
JSON
.
stringify
(
data
));
expect
(
true
).
assertEqual
(
data
.
deviceName
==
null
);
});
}
catch
(
error
){
console
.
info
(
"
[wifi_test]createGroup auto goBand result :
"
+
JSON
.
stringify
(
error
.
message
));
expect
(
true
).
assertEqual
(
(
JSON
.
stringify
(
error
.
message
))
!=
null
);
}
done
();
})
/**
* @tc.number Communication_WiFi_XTS_P2P_0009
* @tc.name testP2pCancelConnect
* @tc.desc Test p2pCancelConnect Group API functionality.
* @tc.type Function
* @tc.level Level 3
*/
it
(
'
Communication_WiFi_XTS_P2P_0009
'
,
0
,
async
function
(
done
)
{
let
wifiP2PConfig
=
{
deviceAddress
:
"
11:22:33:44:55:66
"
,
netId
:
-
1
,
passphrase
:
"
12345678
"
,
groupName
:
"
AAAZZZ456
"
,
goBand
:
wifi
.
GroupOwnerBand
.
GO_BAND_2GHZ
,
};
let
p2pConnectResult
=
wifi
.
p2pConnect
(
wifiP2PConfig
);
console
.
info
(
"
[wifi_test]test p2pConnect result.
"
+
p2pConnectResult
);
let
p2pCancelResult
=
wifi
.
p2pCancelConnect
();
await
sleep
(
2000
);
console
.
info
(
"
[wifi_test]test p2pCancelConnect result.
"
+
p2pCancelResult
);
expect
(
p2pCancelResult
).
assertTrue
();
let
removeGroupResult
=
wifi
.
removeGroup
();
console
.
info
(
"
[wifi_test]test start removeGroup:
"
+
removeGroupResult
);
expect
(
removeGroupResult
).
assertTrue
();
await
wifi
.
getCurrentGroup
()
.
then
(
data
=>
{
console
.
info
(
"
[wifi_test] getCurrentGroup promise result1 :
"
+
JSON
.
stringify
(
data
));
expect
(
true
).
assertEqual
(
data
.
deviceName
==
null
);
});
done
();
})
/**
* @tc.number Communication_WiFi_XTS_P2P_0011
* @tc.name testRemoveGroup
* @tc.desc Test remove a nonexistent group.
* @tc.type Function
* @tc.level Level 3
*/
it
(
'
Communication_WiFi_XTS_P2P_0011
'
,
0
,
async
function
(
done
)
{
let
removeGroupResult
=
wifi
.
removeGroup
(
10000
);
console
.
info
(
"
[wifi_test]removeGroup(10000) result :
"
+
JSON
.
stringify
(
removeGroupResult
));
expect
(
removeGroupResult
).
assertTrue
();
await
wifi
.
getCurrentGroup
()
.
then
(
data
=>
{
console
.
info
(
"
[wifi_test] getCurrentGroup promise result1 :
"
+
JSON
.
stringify
(
data
));
expect
(
true
).
assertEqual
(
data
.
deviceName
==
null
);
});
done
();
})
/**
* @tc.number Communication_WiFi_XTS_P2P_0010
* @tc.name testGetP2pLinkedInfo
* @tc.desc Test getP2pLinkedInfo API functionality
* @tc.type Function
* @tc.level Level 2
*/
it
(
'
Communication_WiFi_XTS_P2P_0010
'
,
0
,
async
function
(
done
)
{
let
P2pConnectState
=
{
DISCONNECTED
:
0
,
CONNECTED
:
1
,
};
await
wifi
.
getP2pLinkedInfo
()
.
then
(
data
=>
{
let
resultLength
=
Object
.
keys
(
data
).
length
;
console
.
info
(
"
[wifi_test]getP2pLinkedInfo promise result :
"
+
JSON
.
stringify
(
data
));
expect
(
true
).
assertEqual
(
resultLength
!=
0
);
done
()
});
function
getP2pLinkedInfoResult
(){
return
new
Promise
((
resolve
,
reject
)
=>
{
wifi
.
getP2pLinkedInfo
(
(
err
,
result
)
=>
{
if
(
err
)
{
console
.
info
(
"
[wifi_test]failed to getP2pLinkedInfo callback:
"
+
JSON
.
stringify
(
err
));
return
;
}
let
resultLength
=
Object
.
keys
(
result
).
length
;
console
.
info
(
"
[wifi_test]getP2pLinkedInfo callback:
"
+
JSON
.
stringify
(
resultLength
));
console
.
info
(
"
connectState:
"
+
result
.
connectState
+
"
isGroupOwner:
"
+
result
.
isGroupOwner
+
"
groupOwnerAddr:
"
+
result
.
groupOwnerAddr
);
expect
(
true
).
assertEqual
(
resultLength
!=
0
);
resolve
();
});
});
}
await
getP2pLinkedInfoResult
();
done
();
})
/**
* @tc.number Communication_WiFi_XTS_P2P_0001
* @tc.name testGetP2pPeerDevices
* @tc.desc Test getP2pPeerDevices promise API functionality
* @tc.type Function
* @tc.level Level 0
*/
it
(
'
Communication_WiFi_XTS_P2P_0001
'
,
0
,
async
function
(
done
){
console
.
log
(
"
[wifi_test]check the state of wifi:
"
+
wifi
.
isWifiActive
());
expect
(
wifi
.
isWifiActive
()).
assertTrue
();
let
startDiscover
=
wifi
.
startDiscoverDevices
();
await
sleep
(
2000
);
expect
(
startDiscover
).
assertTrue
();
await
wifi
.
getP2pPeerDevices
()
.
then
((
data
)
=>
{
let
resultLength
=
Object
.
keys
(
data
).
length
;
console
.
info
(
"
[wifi_test]getP2pPeerDevices promise result ->
"
+
JSON
.
stringify
(
data
));
expect
(
true
).
assertEqual
(
resultLength
>=
0
);
}).
catch
((
error
)
=>
{
console
.
info
(
"
[wifi_test]getP2pPeerDevices promise then error.
"
+
JSON
.
stringify
(
error
));
expect
().
assertFail
();
});
let
stopDiscover
=
wifi
.
stopDiscoverDevices
();
console
.
info
(
"
[wifi_test]test stopDiscoverDevices result.
"
+
stopDiscover
);
done
();
})
/**
* @tc.number Communication_WiFi_XTS_P2P_0101
* @tc.name testGetP2pPeerDevices
* @tc.desc Test getP2pPeerDevices callback API functionality
* @tc.type Function
* @tc.level Level 0
*/
it
(
'
Communication_WiFi_XTS_P2P_0101
'
,
0
,
async
function
(
done
){
console
.
log
(
"
[wifi_test]check the state of wifi:
"
+
wifi
.
isWifiActive
());
expect
(
wifi
.
isWifiActive
()).
assertTrue
();
let
startDiscover
=
wifi
.
startDiscoverDevices
();
await
sleep
(
2000
);
expect
(
startDiscover
).
assertTrue
();
function
getP2pPeerDevicesResult
(){
return
new
Promise
((
resolve
,
reject
)
=>
{
wifi
.
getP2pPeerDevices
(
(
err
,
result
)
=>
{
if
(
err
)
{
console
.
error
(
'
[wifi_test]failed to getP2pPeerDevices :
'
+
JSON
.
stringify
(
err
));
}
console
.
info
(
"
[wifi_test] getP2pPeerDevices callback result :
"
+
JSON
.
stringify
(
result
));
let
len
=
Object
.
keys
(
result
).
length
;
for
(
let
j
=
0
;
j
<
len
;
++
j
)
{
console
.
info
(
"
deviceName:
"
+
result
[
j
].
deviceName
+
"
deviceAddress:
"
+
result
[
j
].
deviceAddress
+
"
primaryDeviceType:
"
+
result
[
j
].
primaryDeviceType
+
"
deviceStatus:
"
+
result
[
j
].
deviceStatus
+
"
groupCapabilitys:
"
+
result
[
j
].
groupCapabilitys
);
if
(
result
[
j
].
deviceStatus
==
wifi
.
P2pDeviceStatus
.
UNAVAILABLE
){
console
.
info
(
"
deviceStatus:
"
+
result
[
j
].
deviceStatus
);
}
if
(
result
[
j
].
deviceStatus
==
wifi
.
P2pDeviceStatus
.
CONNECTED
){
console
.
info
(
"
deviceStatus:
"
+
result
[
j
].
deviceStatus
);
}
if
(
result
[
j
].
deviceStatus
==
wifi
.
P2pDeviceStatus
.
INVITED
){
console
.
info
(
"
deviceStatus:
"
+
result
[
j
].
deviceStatus
);
}
if
(
result
[
j
].
deviceStatus
==
wifi
.
P2pDeviceStatus
.
FAILED
){
console
.
info
(
"
deviceStatus:
"
+
result
[
j
].
deviceStatus
);
}
if
(
result
[
j
].
deviceStatus
==
wifi
.
P2pDeviceStatus
.
AVAILABLE
){
console
.
info
(
"
deviceStatus:
"
+
result
[
j
].
deviceStatus
);
}
}
resolve
();
});
});
}
await
getP2pPeerDevicesResult
();
done
();
});
console
.
log
(
"
*************[wifi_test] start wifi js unit test end*************
"
);
})
}
/*
* Copyright (C) 2022 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import
{
describe
,
beforeAll
,
beforeEach
,
afterEach
,
afterAll
,
it
,
expect
}
from
'
@ohos/hypium
'
import
wifi
from
'
@ohos.wifi
'
function
sleep
(
delay
)
{
return
new
Promise
(
resovle
=>
setTimeout
(
resovle
,
delay
))
}
function
checkWifiPowerOn
(){
console
.
info
(
"
[wifi_test]/wifi status:
"
+
wifi
.
isWifiActive
());
}
export
default
function
actsWifiFunctionTest
()
{
describe
(
'
actsWifiFunctionTest
'
,
function
()
{
beforeEach
(
function
()
{
console
.
info
(
"
[wifi_test]beforeEach start
"
);
checkWifiPowerOn
();
})
afterEach
(
async
function
()
{
console
.
info
(
"
[wifi_test]afterEach start
"
);
})
/**
* @tc.number Communication_WiFi_XTS_P2P_0003
* @tc.name testCreateGroup
* @tc.desc Test createGroup and getCurrentGroup API Function
* @tc.type Function
* @tc.level Level 3
*/
it
(
'
Communication_WiFi_XTS_P2P_0003
'
,
0
,
async
function
(
done
)
{
let
wifiP2PConfig
=
{
deviceAddress
:
"
00:00:00:00:00:00
"
,
netId
:
-
1
,
passphrase
:
"
12345678
"
,
groupName
:
"
AAAZZZ123
"
,
goBand
:
wifi
.
GroupOwnerBand
.
GO_BAND_2GHZ
,
};
console
.
log
(
"
[wifi_test]check the state of wifi:
"
+
wifi
.
isWifiActive
());
expect
(
wifi
.
isWifiActive
()).
assertTrue
();
let
createGroupResult
=
wifi
.
createGroup
(
wifiP2PConfig
);
console
.
log
(
"
[wifi_test]createGroup result:
"
+
JSON
.
stringify
(
createGroupResult
));
await
sleep
(
2000
);
expect
(
createGroupResult
).
assertTrue
();
await
wifi
.
getCurrentGroup
()
.
then
(
data
=>
{
console
.
info
(
"
[wifi_test]getCurrentGroup promise result ->
"
+
JSON
.
stringify
(
data
));
expect
(
true
).
assertEqual
(
data
.
groupName
==
wifiP2PConfig
.
groupName
);
});
function
getCurrentGroupResult
(){
return
new
Promise
((
resolve
,
reject
)
=>
{
wifi
.
getCurrentGroup
(
(
err
,
result
)
=>
{
if
(
err
)
{
console
.
info
(
"
[wifi_test]failed to get getCurrentGroup:
"
+
JSON
.
stringify
(
err
));
expect
().
assertFail
();
}
console
.
info
(
"
[wifi_test]getCurrentGroup callback:
"
+
JSON
.
stringify
(
result
));
console
.
info
(
"
isP2pGo:
"
+
result
.
isP2pGo
+
"
deviceName:
"
+
result
.
ownerInfo
.
deviceName
+
"
deviceAddress:
"
+
result
.
ownerInfo
.
deviceAddress
+
"
primaryDeviceType:
"
+
result
.
ownerInfo
.
primaryDeviceType
+
"
deviceStatus:
"
+
result
.
ownerInfo
.
deviceStatus
+
"
groupCapabilitys:
"
+
result
.
ownerInfo
.
groupCapabilitys
+
"
passphrase:
"
+
result
.
passphrase
+
"
interface:
"
+
result
.
interface
+
"
groupName:
"
+
result
.
groupName
+
"
frequency:
"
+
result
.
frequency
+
"
goIpAddress:
"
+
result
.
goIpAddress
);
console
.
info
(
"
[wifi_test] clientDevices:
"
+
JSON
.
stringify
(
result
.
clientDevices
));
console
.
info
(
"
[wifi_test] ownerInfo:
"
+
JSON
.
stringify
(
result
.
WifiP2pDevice
));
resolve
();
});
});
}
await
getCurrentGroupResult
();
let
removeGroupResult
=
wifi
.
removeGroup
();
await
sleep
(
2000
);
expect
(
removeGroupResult
).
assertTrue
();
try
{
await
wifi
.
getCurrentGroup
()
.
then
(
data
=>
{
console
.
info
(
"
[wifi_test] getCurrentGroup promise result1 :
"
+
JSON
.
stringify
(
data
));
expect
(
true
).
assertEqual
(
data
.
deviceName
==
null
);
}).
catch
((
error
)
=>
{
console
.
error
(
'
[wifi_test] getCurrentGroup promise failed :
'
+
JSON
.
stringify
(
error
));
expect
(
true
).
assertEqual
(
error
!=
null
);
});
}
catch
(
error
){
console
.
info
(
"
[wifi_test]getCurrentGroup promise error:
"
+
JSON
.
stringify
(
error
.
message
));
expect
(
true
).
assertEqual
(
(
JSON
.
stringify
(
error
.
message
))
!=
null
);
}
done
();
})
/**
* @tc.number Communication_WiFi_XTS_P2P_0004
* @tc.name testCreateGroup
* @tc.desc Test createGroup-Setting a 7-bit Key Function.
* @tc.type Function
* @tc.level Level 3
*/
it
(
'
Communication_WiFi_XTS_P2P_0004
'
,
0
,
async
function
(
done
)
{
console
.
log
(
"
[wifi_test]check the state of wifi:
"
+
wifi
.
isWifiActive
());
expect
(
wifi
.
isWifiActive
()).
assertTrue
();
let
wifiP2PConfig
=
{
deviceAddress
:
"
00:00:00:00:00:00
"
,
netId
:
-
1
,
passphrase
:
"
1234567
"
,
groupName
:
"
test_pass
"
,
goBand
:
wifi
.
GroupOwnerBand
.
GO_BAND_2GHZ
,
};
let
createGroupResult
=
wifi
.
createGroup
(
wifiP2PConfig
);
console
.
info
(
"
[wifi_test]test createGroup end.
"
+
JSON
.
stringify
(
createGroupResult
));
await
sleep
(
2000
);
expect
(
createGroupResult
).
assertTrue
();
await
wifi
.
getCurrentGroup
()
.
then
(
data
=>
{
console
.
info
(
"
[wifi_test] getCurrentGroup promise result :
"
+
JSON
.
stringify
(
data
));
expect
(
true
).
assertEqual
(
data
.
networkId
==
-
999
);
});
let
removeGroupResult
=
wifi
.
removeGroup
();
await
sleep
(
2000
);
expect
(
removeGroupResult
).
assertTrue
();
try
{
await
wifi
.
getCurrentGroup
()
.
then
(
data
=>
{
console
.
info
(
"
[wifi_test] getCurrentGroup promise result1 :
"
+
JSON
.
stringify
(
data
));
expect
(
true
).
assertEqual
(
data
.
deviceName
==
null
);
}).
catch
((
error
)
=>
{
console
.
error
(
'
[wifi_test] getCurrentGroup promise failed :
'
+
JSON
.
stringify
(
error
));
expect
(
true
).
assertEqual
(
error
!=
null
);
});
}
catch
(
error
){
console
.
info
(
"
[wifi_test]getCurrentGroup promise error:
"
+
JSON
.
stringify
(
error
.
message
));
expect
(
true
).
assertEqual
(
(
JSON
.
stringify
(
error
.
message
))
!=
null
);
}
done
();
})
/**
* @tc.number Communication_WiFi_XTS_P2P_0104
* @tc.name testCreateGroup
* @tc.desc Test createGroup-Key setting: Chinese, English, and characters Function.
* @tc.type Function
* @tc.level Level 3
*/
it
(
'
Communication_WiFi_XTS_P2P_0104
'
,
0
,
async
function
(
done
)
{
console
.
log
(
"
[wifi_test]check the state of wifi:
"
+
wifi
.
isWifiActive
());
expect
(
wifi
.
isWifiActive
()).
assertTrue
();
let
wifiP2PConfig
=
{
deviceAddress
:
"
00:00:00:00:00:00
"
,
netId
:
-
1
,
passphrase
:
"
123@%abcD
"
,
groupName
:
"
test_pass1
"
,
goBand
:
wifi
.
GroupOwnerBand
.
GO_BAND_2GHZ
,
};
let
createGroupResult
=
wifi
.
createGroup
(
wifiP2PConfig
);
console
.
info
(
"
[wifi_test]test createGroup end.
"
+
JSON
.
stringify
(
createGroupResult
));
await
sleep
(
2000
);
expect
(
createGroupResult
).
assertTrue
();
await
wifi
.
getCurrentGroup
()
.
then
(
data
=>
{
console
.
info
(
"
[wifi_test]getCurrentGroup promise result :
"
+
JSON
.
stringify
(
data
));
expect
(
true
).
assertEqual
(
data
.
passphrase
==
wifiP2PConfig
.
passphrase
);
});
let
removeGroupResult
=
wifi
.
removeGroup
();
await
sleep
(
2000
);
expect
(
removeGroupResult
).
assertTrue
();
try
{
await
wifi
.
getCurrentGroup
()
.
then
(
data
=>
{
console
.
info
(
"
[wifi_test] getCurrentGroup promise result1 :
"
+
JSON
.
stringify
(
data
));
expect
(
true
).
assertEqual
(
data
.
deviceName
==
null
);
}).
catch
((
error
)
=>
{
console
.
error
(
'
[wifi_test] getCurrentGroup promise failed :
'
+
JSON
.
stringify
(
error
));
expect
(
true
).
assertEqual
(
error
!=
null
);
});
}
catch
(
error
){
console
.
info
(
"
[wifi_test]getCurrentGroup promise error:
"
+
JSON
.
stringify
(
error
.
message
));
expect
(
true
).
assertEqual
(
(
JSON
.
stringify
(
error
.
message
))
!=
null
);
}
done
();
})
/**
* @tc.number Communication_WiFi_XTS_P2P_0204
* @tc.name testCreateGroup
* @tc.desc Test createGroup-Key setting 64 bit Function.
* @tc.type Function
* @tc.level Level 3
*/
it
(
'
Communication_WiFi_XTS_P2P_0204
'
,
0
,
async
function
(
done
)
{
console
.
log
(
"
[wifi_test]check the state of wifi:
"
+
wifi
.
isWifiActive
());
expect
(
wifi
.
isWifiActive
()).
assertTrue
();
let
wifiP2PConfig
=
{
deviceAddress
:
"
00:00:00:00:00:00
"
,
netId
:
-
1
,
passphrase
:
"
abc345678901234567890123456789012345678901234567890123456789012
"
,
groupName
:
"
test_pass2
"
,
goBand
:
wifi
.
GroupOwnerBand
.
GO_BAND_2GHZ
,
};
let
createGroupResult
=
wifi
.
createGroup
(
wifiP2PConfig
);
console
.
info
(
"
[wifi_test]test createGroup end.
"
+
JSON
.
stringify
(
createGroupResult
));
await
sleep
(
2000
);
expect
(
createGroupResult
).
assertTrue
();
await
wifi
.
getCurrentGroup
()
.
then
(
data
=>
{
console
.
info
(
"
[wifi_test]getCurrentGroup promise result :
"
+
JSON
.
stringify
(
data
));
expect
(
true
).
assertEqual
(
data
.
passphrase
==
wifiP2PConfig
.
passphrase
);
});
let
removeGroupResult
=
wifi
.
removeGroup
();
await
sleep
(
2000
);
expect
(
removeGroupResult
).
assertTrue
();
try
{
await
wifi
.
getCurrentGroup
()
.
then
(
data
=>
{
console
.
info
(
"
[wifi_test] getCurrentGroup promise result1 :
"
+
JSON
.
stringify
(
data
));
expect
(
true
).
assertEqual
(
data
.
deviceName
==
null
);
}).
catch
((
error
)
=>
{
console
.
error
(
'
[wifi_test] getCurrentGroup promise failed :
'
+
JSON
.
stringify
(
error
));
expect
(
true
).
assertEqual
(
error
!=
null
);
});
}
catch
(
error
){
console
.
info
(
"
[wifi_test]getCurrentGroup promise error:
"
+
JSON
.
stringify
(
error
.
message
));
expect
(
true
).
assertEqual
(
(
JSON
.
stringify
(
error
.
message
))
!=
null
);
}
done
();
})
/**
* @tc.number Communication_WiFi_XTS_P2P_0304
* @tc.name testCreateGroup
* @tc.desc Test createGroup-Key setting 65 bitsFunction.
* @tc.type Function
* @tc.level Level 3
*/
it
(
'
Communication_WiFi_XTS_P2P_0304
'
,
0
,
async
function
(
done
)
{
console
.
log
(
"
[wifi_test]check the state of wifi:
"
+
wifi
.
isWifiActive
());
expect
(
wifi
.
isWifiActive
()).
assertTrue
();
let
wifiP2PConfig
=
{
deviceAddress
:
"
00:00:00:00:00:00
"
,
netId
:
-
1
,
passphrase
:
"
abc3456789012345678901234567890123456789012345678901234567890123
"
,
groupName
:
"
test_pass3
"
,
goBand
:
wifi
.
GroupOwnerBand
.
GO_BAND_2GHZ
,
};
let
createGroupResult
=
wifi
.
createGroup
(
wifiP2PConfig
);
console
.
info
(
"
[wifi_test]test createGroup end.
"
+
JSON
.
stringify
(
createGroupResult
));
await
sleep
(
2000
);
expect
(
createGroupResult
).
assertTrue
();
await
wifi
.
getCurrentGroup
()
.
then
(
data
=>
{
console
.
info
(
"
[wifi_test]getCurrentGroup promise result :
"
+
JSON
.
stringify
(
data
));
expect
(
true
).
assertEqual
(
data
.
passphrase
!=
wifiP2PConfig
.
passphrase
);
});
let
removeGroupResult
=
wifi
.
removeGroup
();
await
sleep
(
2000
);
expect
(
removeGroupResult
).
assertTrue
();
try
{
await
wifi
.
getCurrentGroup
()
.
then
(
data
=>
{
console
.
info
(
"
[wifi_test] getCurrentGroup promise result1 :
"
+
JSON
.
stringify
(
data
));
expect
(
true
).
assertEqual
(
data
.
deviceName
==
null
);
}).
catch
((
error
)
=>
{
console
.
error
(
'
[wifi_test] getCurrentGroup promise failed :
'
+
JSON
.
stringify
(
error
));
expect
(
true
).
assertEqual
(
error
!=
null
);
});
}
catch
(
error
){
console
.
info
(
"
[wifi_test]getCurrentGroup promise error:
"
+
JSON
.
stringify
(
error
.
message
));
expect
(
true
).
assertEqual
(
(
JSON
.
stringify
(
error
.
message
))
!=
null
);
}
done
();
})
/**
* @tc.number Communication_WiFi_XTS_P2P_0007
* @tc.name testCreateGroup
* @tc.desc Test createGroup-2.4 GHz frequency band setting Function
* @tc.type Function
* @tc.level Level 0
*/
it
(
'
Communication_WiFi_XTS_P2P_0007
'
,
0
,
async
function
(
done
)
{
console
.
log
(
"
[wifi_test]check the state of wifi:
"
+
wifi
.
isWifiActive
());
expect
(
wifi
.
isWifiActive
()).
assertTrue
();
let
wifiP2PConfig
=
{
deviceAddress
:
"
00:00:00:00:00:00
"
,
netId
:
-
1
,
passphrase
:
"
12345678
"
,
groupName
:
"
test_band1
"
,
goBand
:
wifi
.
GroupOwnerBand
.
GO_BAND_2GHZ
,
};
let
createGroupResult
=
wifi
.
createGroup
(
wifiP2PConfig
);
await
sleep
(
2000
);
console
.
info
(
"
[wifi_test] test createGroup result.
"
+
createGroupResult
)
expect
(
createGroupResult
).
assertTrue
();
await
wifi
.
getCurrentGroup
()
.
then
(
data
=>
{
console
.
info
(
"
[wifi_test]getCurrentGroup promise result :
"
+
JSON
.
stringify
(
data
));
expect
(
true
).
assertEqual
(
2412
<
data
.
frequency
<
2484
);
});
let
removeGroupResult
=
wifi
.
removeGroup
();
await
sleep
(
2000
);
expect
(
removeGroupResult
).
assertTrue
();
try
{
await
wifi
.
getCurrentGroup
()
.
then
(
data
=>
{
console
.
info
(
"
[wifi_test] getCurrentGroup promise result1 :
"
+
JSON
.
stringify
(
data
));
expect
(
true
).
assertEqual
(
data
.
deviceName
==
null
);
}).
catch
((
error
)
=>
{
console
.
error
(
'
[wifi_test] getCurrentGroup promise failed :
'
+
JSON
.
stringify
(
error
));
expect
(
true
).
assertEqual
(
error
!=
null
);
});
}
catch
(
error
){
console
.
info
(
"
[wifi_test]getCurrentGroup promise error:
"
+
JSON
.
stringify
(
error
.
message
));
expect
(
true
).
assertEqual
(
(
JSON
.
stringify
(
error
.
message
))
!=
null
);
}
done
();
})
/**
* @tc.number Communication_WiFi_XTS_P2P_0107
* @tc.name testCreateGroup
* @tc.desc Test createGroup-5 GHz frequency band setting Function
* @tc.type Function
* @tc.level Level 0
*/
it
(
'
Communication_WiFi_XTS_P2P_0107
'
,
0
,
async
function
(
done
)
{
console
.
log
(
"
[wifi_test]check the state of wifi:
"
+
wifi
.
isWifiActive
());
expect
(
wifi
.
isWifiActive
()).
assertTrue
();
try
{
let
wifiP2PConfig
=
{
deviceAddress
:
"
00:00:00:00:00:00
"
,
netId
:
-
1
,
passphrase
:
"
12345678
"
,
groupName
:
"
test_band2
"
,
goBand
:
wifi
.
GroupOwnerBand
.
GO_BAND_5GHZ
,
};
let
createGroupResult
=
wifi
.
createGroup
(
wifiP2PConfig
);
await
sleep
(
2000
);
console
.
info
(
"
[wifi_test]test createGroup result.
"
+
createGroupResult
)
expect
(
createGroupResult
).
assertTrue
();
await
wifi
.
getCurrentGroup
()
.
then
(
data
=>
{
console
.
info
(
"
[wifi_test] getCurrentGroup promise result :
"
+
JSON
.
stringify
(
data
));
expect
(
true
).
assertEqual
(
5160
<
data
.
frequency
<
5865
);
});
let
removeGroupResult
=
await
wifi
.
removeGroup
();
await
sleep
(
2000
);
expect
(
removeGroupResult
).
assertTrue
();
await
wifi
.
getCurrentGroup
()
.
then
(
data
=>
{
console
.
info
(
"
[wifi_test] getCurrentGroup promise result1 :
"
+
JSON
.
stringify
(
data
));
expect
(
true
).
assertEqual
(
data
.
deviceName
==
null
);
}).
catch
((
error
)
=>
{
console
.
error
(
'
[wifi_test] getCurrentGroup promise failed :
'
+
JSON
.
stringify
(
error
));
expect
(
true
).
assertEqual
(
error
!=
null
);
});
}
catch
(
error
){
console
.
info
(
"
[wifi_test]createGroup 5G goBand result :
"
+
JSON
.
stringify
(
error
.
message
));
expect
(
true
).
assertEqual
(
(
JSON
.
stringify
(
error
.
message
))
!=
null
);
}
done
();
})
/**
* @tc.number Communication_WiFi_XTS_P2P_0207
* @tc.name testCreateGroup
* @tc.desc Test createGroup-Auto frequency band setting Function
* @tc.type Function
* @tc.level Level 0
*/
it
(
'
Communication_WiFi_XTS_P2P_0207
'
,
0
,
async
function
(
done
)
{
console
.
log
(
"
[wifi_test]check the state of wifi:
"
+
wifi
.
isWifiActive
());
expect
(
wifi
.
isWifiActive
()).
assertTrue
();
try
{
let
wifiP2PConfig
=
{
deviceAddress
:
"
00:00:00:00:00:00
"
,
netId
:
-
1
,
passphrase
:
"
12345678
"
,
groupName
:
"
test_band3
"
,
goBand
:
wifi
.
GroupOwnerBand
.
GO_BAND_AUTO
,
};
let
createGroupResult
=
wifi
.
createGroup
(
wifiP2PConfig
);
await
sleep
(
2000
);
console
.
info
(
"
[wifi_test]test createGroup result.
"
+
createGroupResult
)
expect
(
createGroupResult
).
assertTrue
();
await
wifi
.
getCurrentGroup
()
.
then
(
data
=>
{
console
.
info
(
"
[wifi_test]getCurrentGroup promise result :
"
+
JSON
.
stringify
(
data
));
expect
(
true
).
assertEqual
(
data
.
frequency
!=
null
);
});
let
removeGroupResult
=
await
wifi
.
removeGroup
();
await
sleep
(
2000
);
expect
(
removeGroupResult
).
assertTrue
();
await
wifi
.
getCurrentGroup
()
.
then
(
data
=>
{
console
.
info
(
"
[wifi_test] getCurrentGroup promise result1 :
"
+
JSON
.
stringify
(
data
));
expect
(
true
).
assertEqual
(
data
.
deviceName
==
null
);
}).
catch
((
error
)
=>
{
console
.
error
(
'
[wifi_test] getCurrentGroup promise failed :
'
+
JSON
.
stringify
(
error
));
expect
(
true
).
assertEqual
(
error
!=
null
);
});
}
catch
(
error
){
console
.
info
(
"
[wifi_test]createGroup auto goBand result :
"
+
JSON
.
stringify
(
error
.
message
));
expect
(
true
).
assertEqual
(
(
JSON
.
stringify
(
error
.
message
))
!=
null
);
}
done
();
})
/**
* @tc.number Communication_WiFi_XTS_P2P_0009
* @tc.name testP2pCancelConnect
* @tc.desc Test p2pCancelConnect Group API functionality.
* @tc.type Function
* @tc.level Level 3
*/
it
(
'
Communication_WiFi_XTS_P2P_0009
'
,
0
,
async
function
(
done
)
{
let
wifiP2PConfig
=
{
deviceAddress
:
"
11:22:33:44:55:66
"
,
netId
:
-
1
,
passphrase
:
"
12345678
"
,
groupName
:
"
AAAZZZ456
"
,
goBand
:
wifi
.
GroupOwnerBand
.
GO_BAND_2GHZ
,
};
let
p2pConnectResult
=
wifi
.
p2pConnect
(
wifiP2PConfig
);
console
.
info
(
"
[wifi_test]test p2pConnect result.
"
+
p2pConnectResult
);
let
p2pCancelResult
=
wifi
.
p2pCancelConnect
();
await
sleep
(
2000
);
console
.
info
(
"
[wifi_test]test p2pCancelConnect result.
"
+
p2pCancelResult
);
expect
(
p2pCancelResult
).
assertTrue
();
let
removeGroupResult
=
wifi
.
removeGroup
();
console
.
info
(
"
[wifi_test]test start removeGroup:
"
+
removeGroupResult
);
expect
(
removeGroupResult
).
assertTrue
();
try
{
await
wifi
.
getCurrentGroup
()
.
then
(
data
=>
{
console
.
info
(
"
[wifi_test] getCurrentGroup promise result1 :
"
+
JSON
.
stringify
(
data
));
expect
(
true
).
assertEqual
(
data
.
deviceName
==
null
);
}).
catch
((
error
)
=>
{
console
.
error
(
'
[wifi_test] getCurrentGroup promise failed :
'
+
JSON
.
stringify
(
error
));
expect
(
true
).
assertEqual
(
error
!=
null
);
});
}
catch
(
error
){
console
.
info
(
"
[wifi_test]getCurrentGroup promise error:
"
+
JSON
.
stringify
(
error
.
message
));
expect
(
true
).
assertEqual
(
(
JSON
.
stringify
(
error
.
message
))
!=
null
);
}
done
();
})
/**
* @tc.number Communication_WiFi_XTS_P2P_0011
* @tc.name testRemoveGroup
* @tc.desc Test remove a nonexistent group.
* @tc.type Function
* @tc.level Level 3
*/
it
(
'
Communication_WiFi_XTS_P2P_0011
'
,
0
,
async
function
(
done
)
{
let
removeGroupResult
=
wifi
.
removeGroup
(
10000
);
console
.
info
(
"
[wifi_test]removeGroup(10000) result :
"
+
JSON
.
stringify
(
removeGroupResult
));
expect
(
removeGroupResult
).
assertTrue
();
try
{
await
wifi
.
getCurrentGroup
()
.
then
(
data
=>
{
console
.
info
(
"
[wifi_test] getCurrentGroup promise result1 :
"
+
JSON
.
stringify
(
data
));
expect
(
true
).
assertEqual
(
data
.
deviceName
==
null
);
}).
catch
((
error
)
=>
{
console
.
error
(
'
[wifi_test] getCurrentGroup promise failed :
'
+
JSON
.
stringify
(
error
));
expect
(
true
).
assertEqual
(
error
!=
null
);
});
}
catch
(
error
){
console
.
info
(
"
[wifi_test]getCurrentGroup promise error message :
"
+
JSON
.
stringify
(
error
.
message
));
expect
(
true
).
assertEqual
(
(
JSON
.
stringify
(
error
.
message
))
!=
null
);
}
done
();
})
/**
* @tc.number Communication_WiFi_XTS_P2P_0010
* @tc.name testGetP2pLinkedInfo
* @tc.desc Test getP2pLinkedInfo API functionality
* @tc.type Function
* @tc.level Level 2
*/
it
(
'
Communication_WiFi_XTS_P2P_0010
'
,
0
,
async
function
(
done
)
{
let
P2pConnectState
=
{
DISCONNECTED
:
0
,
CONNECTED
:
1
,
};
await
wifi
.
getP2pLinkedInfo
()
.
then
(
data
=>
{
let
resultLength
=
Object
.
keys
(
data
).
length
;
console
.
info
(
"
[wifi_test]getP2pLinkedInfo promise result :
"
+
JSON
.
stringify
(
data
));
expect
(
true
).
assertEqual
(
resultLength
!=
0
);
done
()
});
function
getP2pLinkedInfoResult
(){
return
new
Promise
((
resolve
,
reject
)
=>
{
wifi
.
getP2pLinkedInfo
(
(
err
,
result
)
=>
{
if
(
err
)
{
console
.
info
(
"
[wifi_test]failed to getP2pLinkedInfo callback:
"
+
JSON
.
stringify
(
err
));
return
;
}
let
resultLength
=
Object
.
keys
(
result
).
length
;
console
.
info
(
"
[wifi_test]getP2pLinkedInfo callback:
"
+
JSON
.
stringify
(
resultLength
));
console
.
info
(
"
connectState:
"
+
result
.
connectState
+
"
isGroupOwner:
"
+
result
.
isGroupOwner
+
"
groupOwnerAddr:
"
+
result
.
groupOwnerAddr
);
expect
(
true
).
assertEqual
(
resultLength
!=
0
);
resolve
();
});
});
}
await
getP2pLinkedInfoResult
();
done
();
})
/**
* @tc.number Communication_WiFi_XTS_P2P_0001
* @tc.name testGetP2pPeerDevices
* @tc.desc Test getP2pPeerDevices promise API functionality
* @tc.type Function
* @tc.level Level 0
*/
it
(
'
Communication_WiFi_XTS_P2P_0001
'
,
0
,
async
function
(
done
){
console
.
log
(
"
[wifi_test]check the state of wifi:
"
+
wifi
.
isWifiActive
());
expect
(
wifi
.
isWifiActive
()).
assertTrue
();
let
startDiscover
=
wifi
.
startDiscoverDevices
();
await
sleep
(
2000
);
expect
(
startDiscover
).
assertTrue
();
await
wifi
.
getP2pPeerDevices
()
.
then
((
data
)
=>
{
let
resultLength
=
Object
.
keys
(
data
).
length
;
console
.
info
(
"
[wifi_test]getP2pPeerDevices promise result ->
"
+
JSON
.
stringify
(
data
));
expect
(
true
).
assertEqual
(
resultLength
>=
0
);
}).
catch
((
error
)
=>
{
console
.
info
(
"
[wifi_test]getP2pPeerDevices promise then error.
"
+
JSON
.
stringify
(
error
));
expect
().
assertFail
();
});
let
stopDiscover
=
wifi
.
stopDiscoverDevices
();
console
.
info
(
"
[wifi_test]test stopDiscoverDevices result.
"
+
stopDiscover
);
done
();
})
/**
* @tc.number Communication_WiFi_XTS_P2P_0101
* @tc.name testGetP2pPeerDevices
* @tc.desc Test getP2pPeerDevices callback API functionality
* @tc.type Function
* @tc.level Level 0
*/
it
(
'
Communication_WiFi_XTS_P2P_0101
'
,
0
,
async
function
(
done
){
console
.
log
(
"
[wifi_test]check the state of wifi:
"
+
wifi
.
isWifiActive
());
expect
(
wifi
.
isWifiActive
()).
assertTrue
();
let
startDiscover
=
wifi
.
startDiscoverDevices
();
await
sleep
(
2000
);
expect
(
startDiscover
).
assertTrue
();
function
getP2pPeerDevicesResult
(){
return
new
Promise
((
resolve
,
reject
)
=>
{
wifi
.
getP2pPeerDevices
(
(
err
,
result
)
=>
{
if
(
err
)
{
console
.
error
(
'
[wifi_test]failed to getP2pPeerDevices :
'
+
JSON
.
stringify
(
err
));
}
console
.
info
(
"
[wifi_test] getP2pPeerDevices callback result :
"
+
JSON
.
stringify
(
result
));
let
len
=
Object
.
keys
(
result
).
length
;
for
(
let
j
=
0
;
j
<
len
;
++
j
)
{
console
.
info
(
"
deviceName:
"
+
result
[
j
].
deviceName
+
"
deviceAddress:
"
+
result
[
j
].
deviceAddress
+
"
primaryDeviceType:
"
+
result
[
j
].
primaryDeviceType
+
"
deviceStatus:
"
+
result
[
j
].
deviceStatus
+
"
groupCapabilitys:
"
+
result
[
j
].
groupCapabilitys
);
if
(
result
[
j
].
deviceStatus
==
wifi
.
P2pDeviceStatus
.
UNAVAILABLE
){
console
.
info
(
"
deviceStatus:
"
+
result
[
j
].
deviceStatus
);
}
if
(
result
[
j
].
deviceStatus
==
wifi
.
P2pDeviceStatus
.
CONNECTED
){
console
.
info
(
"
deviceStatus:
"
+
result
[
j
].
deviceStatus
);
}
if
(
result
[
j
].
deviceStatus
==
wifi
.
P2pDeviceStatus
.
INVITED
){
console
.
info
(
"
deviceStatus:
"
+
result
[
j
].
deviceStatus
);
}
if
(
result
[
j
].
deviceStatus
==
wifi
.
P2pDeviceStatus
.
FAILED
){
console
.
info
(
"
deviceStatus:
"
+
result
[
j
].
deviceStatus
);
}
if
(
result
[
j
].
deviceStatus
==
wifi
.
P2pDeviceStatus
.
AVAILABLE
){
console
.
info
(
"
deviceStatus:
"
+
result
[
j
].
deviceStatus
);
}
}
resolve
();
});
});
}
await
getP2pPeerDevicesResult
();
done
();
});
console
.
log
(
"
*************[wifi_test] start wifi js unit test end*************
"
);
})
}
communication/wifi_standard/signature/openharmony_sx.p7b
浏览文件 @
0cab7285
无法预览此类型文件
location/geolocation_standard/src/main/js/test/GetCountryCode.test.js
浏览文件 @
0cab7285
...
...
@@ -105,10 +105,9 @@ export default function geolocationTest_4() {
console
.
info
(
"
[lbs_js] getCountryCode promise result:
"
+
JSON
.
stringify
(
result
));
console
.
info
(
"
[lbs_js] country :
"
+
result
.
country
);
console
.
info
(
"
[lbs_js] type:
"
+
result
.
type
);
expect
(
true
).
assertEqual
(
JSON
.
stringify
(
result
.
type
)
==
CountryCodeType
.
COUNTRY_CODE_FROM_LOCALE
);
expect
(
true
).
assertEqual
(
JSON
.
stringify
(
result
.
type
)
!=
CountryCodeType
.
COUNTRY_CODE_FROM_SIM
);
expect
(
true
).
assertEqual
(
JSON
.
stringify
(
result
.
type
)
!=
CountryCodeType
.
COUNTRY_CODE_FROM_LOCATION
);
expect
(
true
).
assertEqual
(
JSON
.
stringify
(
result
.
type
)
!=
CountryCodeType
.
COUNTRY_CODE_FROM_NETWORK
);
expect
(
true
).
assertEqual
(
result
!=
null
);
expect
(
true
).
assertEqual
(
JSON
.
stringify
(
result
.
country
)
!=
null
);
expect
(
true
).
assertEqual
(
JSON
.
stringify
(
result
.
type
)
!=
null
);
}).
catch
((
error
)
=>
{
console
.
info
(
"
[lbs_js] getCountryCode promise then error.
"
+
JSON
.
stringify
(
error
));
expect
().
assertFail
();
...
...
location/geolocation_standard/src/main/js/test/GetCountryCodeM.test.js
浏览文件 @
0cab7285
...
...
@@ -104,10 +104,9 @@ export default function geolocationTest_6() {
console
.
info
(
"
[lbs_js] getCountryCode promise result:
"
+
JSON
.
stringify
(
result
));
console
.
info
(
"
[lbs_js] country :
"
+
result
.
country
);
console
.
info
(
"
[lbs_js] type:
"
+
result
.
type
);
expect
(
true
).
assertEqual
(
JSON
.
stringify
(
result
.
type
)
==
CountryCodeType
.
COUNTRY_CODE_FROM_LOCALE
);
expect
(
true
).
assertEqual
(
JSON
.
stringify
(
result
.
type
)
!=
CountryCodeType
.
COUNTRY_CODE_FROM_SIM
);
expect
(
true
).
assertEqual
(
JSON
.
stringify
(
result
.
type
)
!=
CountryCodeType
.
COUNTRY_CODE_FROM_LOCATION
);
expect
(
true
).
assertEqual
(
JSON
.
stringify
(
result
.
type
)
!=
CountryCodeType
.
COUNTRY_CODE_FROM_NETWORK
);
expect
(
true
).
assertEqual
(
result
!=
null
);
expect
(
true
).
assertEqual
(
JSON
.
stringify
(
result
.
country
)
!=
null
);
expect
(
true
).
assertEqual
(
JSON
.
stringify
(
result
.
type
)
!=
null
);
}).
catch
((
error
)
=>
{
console
.
info
(
"
[lbs_js] getCountryCode promise then error.
"
+
JSON
.
stringify
(
error
));
expect
().
assertFail
();
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录