未验证 提交 9a2af79c 编写于 作者: O openharmony_ci 提交者: Gitee

!9320 完成telephony子系统模块的跨平台测试套【Connection、WebSocket】

Merge pull request !9320 from huyanqiang/telephony_lgc
# Copyright (C) 2021 Huawei Device Co., Ltd.
# Copyright (C) 2023 Huawei Device Co., Ltd.
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
......@@ -14,6 +14,7 @@
group("telephony") {
testonly = true
deps = [
"crossplatform:crossplatform",
"crossplatform/telephony_http_test:ActsCrossplatformTelephonyHttpEtsTest",
"telephonyjstest:telephonyjstest",
]
......
# Copyright (C) 2023 Huawei Device Co., Ltd.
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import("//test/xts/tools/build/suite.gni")
group("crossplatform") {
testonly = true
if (is_standard_system) {
deps = [
"telephonyConnectionetstest:ActsCrossplatformConnectionTest",
"telephonyWebSocketetstest:ActsCrossplatformWebSocketTest",
]
}
}
{
"app": {
"bundleName": "ohos.acts.telephony.crossplatform.Connection.normal",
"vendor": "example",
"versionCode": 1000000,
"versionName": "1.0.0",
"icon": "$media:app_icon",
"label": "$string:app_name",
"minAPIVersion": 10,
"targetAPIVersion": 10,
"car": {
"apiCompatibleVersion": 10,
"singleUser": false
}
}
}
# Copyright (C) 2023 Huawei Device Co., Ltd.
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import("//test/xts/tools/build/suite.gni")
ohos_js_hap_suite("ActsCrossplatformConnectionTest") {
hap_profile = "src/main/module.json"
deps = [
":windowStage_js_assets",
":windowStage_resources",
]
ets2abc = true
certificate_profile = "./signature/openharmony_sx.p7b"
# hap_name: HAP的名字,可选,默认为目标名
hap_name = "ActsCrossplatformConnectionTest"
subsystem_name = "communication"
part_name = "netstack"
}
ohos_app_scope("windowStage_app_profile") {
# app_profile: HAP的AppScope中的app.json,只在Stage模型下使用
app_profile = "AppScope/app.json"
# sources: 资源文件路径
sources = [ "AppScope/resources" ]
}
ohos_js_assets("windowStage_js_assets") {
# source_dir: js或ets代码路径,兼容FA模型的单ability配置到ability目录
source_dir = "src/main/ets"
}
ohos_resources("windowStage_resources") {
# sources: 资源文件路径
sources = [ "src/main/resources" ]
# deps: 当前目标的依赖
deps = [ ":windowStage_app_profile" ]
# hap_profile: HAP的config.json,Stage模型对应module.json
hap_profile = "src/main/module.json"
}
{
"description": "Configuration for hjunit demo Tests",
// 指定设备执行的驱动
"driver": {
"type": "OHJSUnitTest",
//test-timeout: 测试hap 整体执行用例的执行时长
"test-timeout": "60000",
//shell-timeout: aa test 拉起命令执行时长
"shell-timeout": "60000",
//bundle-name: 与HAP的app.json bundleName 保持一致
"bundle-name": "ohos.acts.telephony.crossplatform.Connection.normal",
//module-name: 与HAP的module.json "module"字段的 name 保持一致
"module-name": "entry_test"
//testcase-timeout: 测试hap 单条用例的执行时长
//"testcase-timeout": 5000
},
// kit的作用主要是为了支撑测试执行活动,在测试前执行预制操作(Setup),在测试后执行清理操作(Teardown)
"kits": [
{
"test-file-name": [
"ActsDemoStageTest.hap"
],
"type": "AppInstallKit",
"cleanup-apps": true
}
]
}
\ No newline at end of file
/**
* Copyright (c) 2023 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import UIAbility from '@ohos.app.ability.UIAbility';
import AbilityDelegatorRegistry from '@ohos.app.ability.abilityDelegatorRegistry';
import hilog from '@ohos.hilog';
import { Hypium } from '@ohos/hypium';
import testsuite from '../test/List.test';
import window from '@ohos.window';
export default class TestAbility extends UIAbility {
onCreate(want, launchParam) {
hilog.info(0x0000, 'testTag', '%{public}s', 'TestAbility onCreate');
hilog.info(0x0000, 'testTag', '%{public}s', 'want param:' + JSON.stringify(want) ?? '');
hilog.info(0x0000, 'testTag', '%{public}s', 'launchParam:'+ JSON.stringify(launchParam) ?? '');
var abilityDelegator: any
abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator()
var abilityDelegatorArguments: any
abilityDelegatorArguments = AbilityDelegatorRegistry.getArguments()
hilog.info(0x0000, 'testTag', '%{public}s', 'start run testcase!!!');
Hypium.hypiumTest(abilityDelegator, abilityDelegatorArguments, testsuite)
}
onDestroy() {
hilog.info(0x0000, 'testTag', '%{public}s', 'TestAbility onDestroy');
}
onWindowStageCreate(windowStage: window.WindowStage) {
hilog.info(0x0000, 'testTag', '%{public}s', 'TestAbility onWindowStageCreate');
windowStage.loadContent('TestAbility/pages/Index', (err, data) => {
if (err.code) {
hilog.error(0x0000, 'testTag', 'Failed to load the content. Cause: %{public}s', JSON.stringify(err) ?? '');
return;
}
hilog.info(0x0000, 'testTag', 'Succeeded in loading the content. Data: %{public}s',
JSON.stringify(data) ?? '');
});
}
onWindowStageDestroy() {
hilog.info(0x0000, 'testTag', '%{public}s', 'TestAbility onWindowStageDestroy');
}
onForeground() {
hilog.info(0x0000, 'testTag', '%{public}s', 'TestAbility onForeground');
}
onBackground() {
hilog.info(0x0000, 'testTag', '%{public}s', 'TestAbility onBackground');
}
}
\ No newline at end of file
/**
* Copyright (c) 2023 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import hilog from '@ohos.hilog';
@Entry
@Component
struct Index {
aboutToAppear() {
hilog.info(0x0000, 'testTag', '%{public}s', 'TestAbility index aboutToAppear');
}
@State message: string = 'Hello World'
build() {
Row() {
Column() {
Text(this.message)
.fontSize(50)
.fontWeight(FontWeight.Bold)
Button() {
Text('next page')
.fontSize(20)
.fontWeight(FontWeight.Bold)
}.type(ButtonType.Capsule)
.margin({
top: 20
})
.backgroundColor('#0D9FFB')
.width('35%')
.height('5%')
.onClick(()=>{
})
}
.width('100%')
}
.height('100%')
}
}
\ No newline at end of file
import hilog from '@ohos.hilog';
import TestRunner from '@ohos.application.testRunner';
import AbilityDelegatorRegistry from '@ohos.app.ability.abilityDelegatorRegistry';
var abilityDelegator = undefined
var abilityDelegatorArguments = undefined
async function onAbilityCreateCallback() {
hilog.info(0x0000, 'testTag', '%{public}s', 'onAbilityCreateCallback');
}
async function addAbilityMonitorCallback(err: any) {
hilog.info(0x0000, 'testTag', 'addAbilityMonitorCallback : %{public}s', JSON.stringify(err) ?? '');
}
export default class OpenHarmonyTestRunner implements TestRunner {
constructor() {
}
onPrepare() {
hilog.info(0x0000, 'testTag', '%{public}s', 'OpenHarmonyTestRunner OnPrepare ');
}
async onRun() {
hilog.info(0x0000, 'testTag', '%{public}s', 'OpenHarmonyTestRunner onRun run');
abilityDelegatorArguments = AbilityDelegatorRegistry.getArguments()
abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator()
var testAbilityName = abilityDelegatorArguments.bundleName + '.TestAbility'
let lMonitor = {
abilityName: testAbilityName,
onAbilityCreate: onAbilityCreateCallback,
};
abilityDelegator.addAbilityMonitor(lMonitor, addAbilityMonitorCallback)
var cmd = 'aa start -d 0 -a TestAbility' + ' -b ' + abilityDelegatorArguments.bundleName
var debug = abilityDelegatorArguments.parameters['-D']
if (debug == 'true')
{
cmd += ' -D'
}
hilog.info(0x0000, 'testTag', 'cmd : %{public}s', cmd);
abilityDelegator.executeShellCommand(cmd,
(err: any, d: any) => {
hilog.info(0x0000, 'testTag', 'executeShellCommand : err : %{public}s', JSON.stringify(err) ?? '');
hilog.info(0x0000, 'testTag', 'executeShellCommand : data : %{public}s', d.stdResult ?? '');
hilog.info(0x0000, 'testTag', 'executeShellCommand : data : %{public}s', d.exitCode ?? '');
})
hilog.info(0x0000, 'testTag', '%{public}s', 'OpenHarmonyTestRunner onRun end');
}
}
\ No newline at end of file
/**
* Copyright (c) 2023 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from '@ohos/hypium'
import connection from '@ohos.net.connection'
export default function connectionTest() {
describe('connectionTest', function () {
const TIMEOUT = 100;
const DELAY = 1000;
const NETID_IVVALID = 99;
const NETID_IVVALID2 = 0;
let envReady = false;
/*
* @tc.number: TEST_CREATE_NET_CONNECTION_001
* @tc.name : testCreateNetConnection001
* @tc.desc : Create a network connection with optional netSpecifier and timeout.
* @tc.size : MediumTest
* @tc.type : Method
* @tc.level : Level 2
*/
it('testCreateNetConnection001', 0, function (done) {
try {
connection.createNetConnection();
console.log("create success11:" + connection.createNetConnection);
expect(true).assertTrue();
done();
} catch (error) {
expect().assertFail();
done();
}
});
/*
* @tc.number: TEST_HAS_DEFAULT_NET_001
* @tc.name : testHasDefaultNet001
* @tc.desc : Checks whether the default data network is activated.
* @tc.size : MediumTest
* @tc.type : Method
* @tc.level : Level 2
*/
it('testHasDefaultNet001', 0, function (done) {
console.log('testHasDefaultNet001 1');
connection.hasDefaultNet((error, value) => {
console.log('testHasDefaultNet001 2');
if (!error) {
console.log('testHasDefaultNet001 3');
console.log(`testHasDefaultNet001 case success,data:` + value);
console.log('testHasDefaultNet001 4');
expect(value).assertTrue();
done();
} else {
console.log('testHasDefaultNet001 6');
console.log(`testHasDefaultNet001 error, case failed,errCode:` + error.code);
console.log('testHasDefaultNet001 7');
expect().assertFail();
done();
}
});
console.log('testHasDefaultNet001 9');
});
/*
* @tc.number: TEST_HAS_DEFAULT_NET_002
* @tc.name : testHasDefaultNet002
* @tc.desc : Checks whether the default data network is activated.
* @tc.size : MediumTest
* @tc.type : Method
* @tc.level : Level 2
*/
it('testHasDefaultNet002', 0, function (done) {
connection.hasDefaultNet().then(value => {
console.log(`case success,data:` + value);
expect(value).assertTrue();
done();
}).catch((error) => {
console.log(`error, case failed,errCode:` + error.code);
expect().assertFail();
done();
});
});
/**
* @tc.number: TEST_REGISTER_001
* @tc.name : testRegister001
* @tc.desc : Receives status change notifications of a specified network.
* @tc.size : MediumTest
* @tc.type : Method
* @tc.level : Level 2
*/
it('testRegister001', 0, function (done) {
let netConn = connection.createNetConnection();
netConn.register((error) => {
if (!error) {
console.log(`register success11`);
netConn.unregister((error) => {
expect(true).assertTrue();
done();
});
} else {
console.log(`register failed,errCode:` + error.code);
expect().assertFail();
done();
}
});
});
/**
* @tc.number: TEST_UNREGISTER_001
* @tc.name : testUnregister001
* @tc.desc : Cancels listening for network status changes. test
* @tc.size : MediumTest
* @tc.type : Method
* @tc.level : Level 2
*/
it('testUnregister001', 0, function (done) {
let netConn = connection.createNetConnection();
netConn.register((error) => {
if (!error) {
console.log(`register success11`);
netConn.unregister((error) => {
if (!error) {
console.log(`unregister success11`);
expect(true).assertTrue();
done();
} else {
console.log(`register failed,errCode:` + error.code);
expect().assertFail();
done();
}
});
}
});
});
/**
* @tc.number: TEST_ON_NET_AVAILABLE_001
* @tc.name : testOn_NetAvailable001
* @tc.desc : Subscribe to network available events.
* @tc.size : MediumTest
* @tc.type : Method
* @tc.level : Level 2
*/
it('testOn_NetAvailable001', 0, function (done) {
try {
let netConn = connection.createNetConnection();
netConn.register((error) => {
if (!error) {
console.log("register success11:" + error);
netConn.on("netAvailable",(data) => {
console.log("netAvailable success11:" + data);
});
netConn.unregister((error) => {
console.log("unregister success11:" + error);
});
expect(true).assertTrue();
done();
}
});
} catch (err) {
console.log(`register failed,errCode:` + err);
expect().assertFail();
done();
}
});
/**
* @tc.number: TEST_ON_NET_CAPABILITIES_CHANGE_001
* @tc.name : testOn_NetCapabilitiesChange001
* @tc.desc : Subscribe to network capability change events.
* @tc.size : MediumTest
* @tc.type : Method
* @tc.level : Level 2
*/
it('testOn_NetCapabilitiesChange001', 0, function (done) {
let netConn = connection.createNetConnection();
netConn.register((error) => {
if (!error) {
netConn.on('netCapabilitiesChange',(data) => {
console.log("success11:" + data);
expect(data.netCap.bearerTypes.length >= 0).assertTrue();
});
netConn.unregister((error) => {
console.log("result11:" + error);
});
expect(true).assertTrue();
done();
} else {
console.log(`register failed,errCode:` + error.code);
expect().assertFail();
done();
}
});
});
/**
* @tc.number: TEST_ON_NET_LOST_001
* @tc.name : testOn_NetLost001
* @tc.desc : Subscribe to network loss events.
* @tc.size : MediumTest
* @tc.type : Method
* @tc.level : Level 2
*/
it('testOn_NetLost001', 0, function (done) {
let netConn = connection.createNetConnection();
netConn.register((error) => {
if (!error) {
netConn.on('netLost',(data) => {
console.log("testOn_NetLost001 success11:" + data.netId);
});
netConn.unregister((error) => {
console.log("testOn_NetLost001 result11:" + error);
});
expect(true).assertTrue();
done();
} else {
console.log(`testOn_NetLost001 register failed,errCode:` + error.code);
expect().assertFail();
done();
}
});
});
/**
* @tc.number: TEST_ON_NET_UNAVAILABLE_001
* @tc.name : testOn_NetUnavailable001
* @tc.desc : Subscribe to network loss events.
* @tc.size : MediumTest
* @tc.type : Method
* @tc.level : Level 2
*/
it('testOn_NetUnavailable001', 0, function (done) {
let netConn = connection.createNetConnection();
netConn.register((error) => {
if (!error) {
netConn.on('netUnavailable',(data) => {
console.log("on success11:" + data);
});
netConn.unregister((error) => {
console.log("result11:" + error);
});
expect(true).assertTrue();
done();
} else {
console.log(`register failed,errCode:` + error.code);
expect().assertFail();
done();
}
});
});
/*
* @tc.number: TEST_NET_ID_001
* @tc.name : testNetId001
* @tc.desc : netId test.
* @tc.size : MediumTest
* @tc.type : Field
* @tc.level : Level 1
*/
it('testNetId001', 0, function (done) {
let netConn = connection.createNetConnection();
netConn.register((error) => {
if (!error) {
console.log(`register success11`);
netConn.on("netAvailable",(data) => {
console.log(`netId success11 data:` +data.netId);
expect(data.netId >= 100).assertTrue();
});
done();
} else {
console.log(`register failed,errCode:` + error.code);
expect().assertFail();
done();
}
});
});
/**
* @tc.number: TEST_NET_BEAR_TYPE_001
* @tc.name : testNetBearType001
* @tc.desc : NetBearType test
* @tc.size : MediumTest
* @tc.type : Enum
* @tc.level : Level 0
*/
it('testNetBearType001', 0, function (done) {
let nbt_0 = connection.NetBearType.BEARER_CELLULAR;
let nbt_1 = connection.NetBearType.BEARER_WIFI;
expect(nbt_0).assertEqual(0);
expect(nbt_1).assertEqual(1);
done();
});
})
}
/**
* Copyright (c) 2023 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import connectionTest from './Connection.test'
export default function testsuite() {
connectionTest()
}
\ No newline at end of file
{
"module": {
"name": "entry_test",
"type": "feature",
"description": "$string:module_test_desc",
"mainElement": "TestAbility",
"deviceTypes": [
"phone"
],
"deliveryWithInstall": true,
"installationFree": false,
"pages": "$profile:test_pages",
"abilities": [
{
"name": "TestAbility",
"srcEntry": "./ets/TestAbility/TestAbility.ets",
"description": "$string:TestAbility_desc",
"icon": "$media:icon",
"label": "$string:TestAbility_label",
"exported": true,
"startWindowIcon": "$media:icon",
"startWindowBackground": "$color:start_window_background",
"skills": [
{
"actions": [
"action.system.home"
],
"entities": [
"entity.system.home"
]
}
]
}
],
"requestPermissions": [
{
"name": "ohos.permission.INTERNET"
},
{
"name": "ohos.permission.GET_NETWORK_INFO"
}
]
}
}
{
"color": [
{
"name": "start_window_background",
"value": "#FFFFFF"
}
]
}
\ No newline at end of file
{
"string": [
{
"name": "module_test_desc",
"value": "test ability description"
},
{
"name": "TestAbility_desc",
"value": "the test ability"
},
{
"name": "TestAbility_label",
"value": "test label"
}
]
}
\ No newline at end of file
{
"app": {
"bundleName": "ohos.acts.telephony.crossplatform.WebSocket.normal",
"vendor": "example",
"versionCode": 1000000,
"versionName": "1.0.0",
"icon": "$media:app_icon",
"label": "$string:app_name",
"minAPIVersion": 10,
"targetAPIVersion": 10,
"car": {
"apiCompatibleVersion": 10,
"singleUser": false
}
}
}
# Copyright (C) 2023 Huawei Device Co., Ltd.
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import("//test/xts/tools/build/suite.gni")
ohos_js_hap_suite("ActsCrossplatformWebSocketTest") {
hap_profile = "src/main/module.json"
deps = [
":windowStage_js_assets",
":windowStage_resources",
]
ets2abc = true
certificate_profile = "./signature/openharmony_sx.p7b"
# hap_name: HAP的名字,可选,默认为目标名
hap_name = "ActsCrossplatformWebSocketTest"
subsystem_name = "communication"
part_name = "netstack"
}
ohos_app_scope("windowStage_app_profile") {
# app_profile: HAP的AppScope中的app.json,只在Stage模型下使用
app_profile = "AppScope/app.json"
# sources: 资源文件路径
sources = [ "AppScope/resources" ]
}
ohos_js_assets("windowStage_js_assets") {
# source_dir: js或ets代码路径,兼容FA模型的单ability配置到ability目录
source_dir = "src/main/ets"
}
ohos_resources("windowStage_resources") {
# sources: 资源文件路径
sources = [ "src/main/resources" ]
# deps: 当前目标的依赖
deps = [ ":windowStage_app_profile" ]
# hap_profile: HAP的config.json,Stage模型对应module.json
hap_profile = "src/main/module.json"
}
{
"description": "Configuration for hjunit demo Tests",
// 指定设备执行的驱动
"driver": {
"type": "OHJSUnitTest",
//test-timeout: 测试hap 整体执行用例的执行时长
"test-timeout": "60000",
//shell-timeout: aa test 拉起命令执行时长
"shell-timeout": "60000",
//bundle-name: 与HAP的app.json bundleName 保持一致
"bundle-name": "ohos.acts.telephony.crossplatform.WebSocket.normal",
//module-name: 与HAP的module.json "module"字段的 name 保持一致
"module-name": "entry_test"
//testcase-timeout: 测试hap 单条用例的执行时长
//"testcase-timeout": 5000
},
// kit的作用主要是为了支撑测试执行活动,在测试前执行预制操作(Setup),在测试后执行清理操作(Teardown)
"kits": [
{
"test-file-name": [
"ActsDemoStageTest.hap"
],
"type": "AppInstallKit",
"cleanup-apps": true
}
]
}
\ No newline at end of file
/**
* Copyright (c) 2023 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import UIAbility from '@ohos.app.ability.UIAbility';
import AbilityDelegatorRegistry from '@ohos.app.ability.abilityDelegatorRegistry';
import hilog from '@ohos.hilog';
import { Hypium } from '@ohos/hypium';
import testsuite from '../test/List.test';
import window from '@ohos.window';
export default class TestAbility extends UIAbility {
onCreate(want, launchParam) {
hilog.info(0x0000, 'testTag', '%{public}s', 'TestAbility onCreate');
hilog.info(0x0000, 'testTag', '%{public}s', 'want param:' + JSON.stringify(want) ?? '');
hilog.info(0x0000, 'testTag', '%{public}s', 'launchParam:'+ JSON.stringify(launchParam) ?? '');
var abilityDelegator: any
abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator()
var abilityDelegatorArguments: any
abilityDelegatorArguments = AbilityDelegatorRegistry.getArguments()
hilog.info(0x0000, 'testTag', '%{public}s', 'start run testcase!!!');
Hypium.hypiumTest(abilityDelegator, abilityDelegatorArguments, testsuite)
}
onDestroy() {
hilog.info(0x0000, 'testTag', '%{public}s', 'TestAbility onDestroy');
}
onWindowStageCreate(windowStage: window.WindowStage) {
hilog.info(0x0000, 'testTag', '%{public}s', 'TestAbility onWindowStageCreate');
windowStage.loadContent('TestAbility/pages/Index', (err, data) => {
if (err.code) {
hilog.error(0x0000, 'testTag', 'Failed to load the content. Cause: %{public}s', JSON.stringify(err) ?? '');
return;
}
hilog.info(0x0000, 'testTag', 'Succeeded in loading the content. Data: %{public}s',
JSON.stringify(data) ?? '');
});
}
onWindowStageDestroy() {
hilog.info(0x0000, 'testTag', '%{public}s', 'TestAbility onWindowStageDestroy');
}
onForeground() {
hilog.info(0x0000, 'testTag', '%{public}s', 'TestAbility onForeground');
}
onBackground() {
hilog.info(0x0000, 'testTag', '%{public}s', 'TestAbility onBackground');
}
}
\ No newline at end of file
/**
* Copyright (c) 2023 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import hilog from '@ohos.hilog';
@Entry
@Component
struct Index {
aboutToAppear() {
hilog.info(0x0000, 'testTag', '%{public}s', 'TestAbility index aboutToAppear');
}
@State message: string = 'Hello World'
build() {
Row() {
Column() {
Text(this.message)
.fontSize(50)
.fontWeight(FontWeight.Bold)
Button() {
Text('next page')
.fontSize(20)
.fontWeight(FontWeight.Bold)
}.type(ButtonType.Capsule)
.margin({
top: 20
})
.backgroundColor('#0D9FFB')
.width('35%')
.height('5%')
.onClick(()=>{
})
}
.width('100%')
}
.height('100%')
}
}
\ No newline at end of file
import hilog from '@ohos.hilog';
import TestRunner from '@ohos.application.testRunner';
import AbilityDelegatorRegistry from '@ohos.app.ability.abilityDelegatorRegistry';
var abilityDelegator = undefined
var abilityDelegatorArguments = undefined
async function onAbilityCreateCallback() {
hilog.info(0x0000, 'testTag', '%{public}s', 'onAbilityCreateCallback');
}
async function addAbilityMonitorCallback(err: any) {
hilog.info(0x0000, 'testTag', 'addAbilityMonitorCallback : %{public}s', JSON.stringify(err) ?? '');
}
export default class OpenHarmonyTestRunner implements TestRunner {
constructor() {
}
onPrepare() {
hilog.info(0x0000, 'testTag', '%{public}s', 'OpenHarmonyTestRunner OnPrepare ');
}
async onRun() {
hilog.info(0x0000, 'testTag', '%{public}s', 'OpenHarmonyTestRunner onRun run');
abilityDelegatorArguments = AbilityDelegatorRegistry.getArguments()
abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator()
var testAbilityName = abilityDelegatorArguments.bundleName + '.TestAbility'
let lMonitor = {
abilityName: testAbilityName,
onAbilityCreate: onAbilityCreateCallback,
};
abilityDelegator.addAbilityMonitor(lMonitor, addAbilityMonitorCallback)
var cmd = 'aa start -d 0 -a TestAbility' + ' -b ' + abilityDelegatorArguments.bundleName
var debug = abilityDelegatorArguments.parameters['-D']
if (debug == 'true')
{
cmd += ' -D'
}
hilog.info(0x0000, 'testTag', 'cmd : %{public}s', cmd);
abilityDelegator.executeShellCommand(cmd,
(err: any, d: any) => {
hilog.info(0x0000, 'testTag', 'executeShellCommand : err : %{public}s', JSON.stringify(err) ?? '');
hilog.info(0x0000, 'testTag', 'executeShellCommand : data : %{public}s', d.stdResult ?? '');
hilog.info(0x0000, 'testTag', 'executeShellCommand : data : %{public}s', d.exitCode ?? '');
})
hilog.info(0x0000, 'testTag', '%{public}s', 'OpenHarmonyTestRunner onRun end');
}
}
\ No newline at end of file
/**
* Copyright (c) 2023 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import webSocketTest from './WebSocket.test'
export default function testsuite() {
webSocketTest()
}
\ No newline at end of file
/**
* Copyright (c) 2023 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from '@ohos/hypium'
import webSocket from '@ohos.net.webSocket'
export default function webSocketTest() {
describe('webSocketTest', function () {
console.log("************* webSocket Test start*************");
/*
* @tc.number: TEST_CREATE_WEB_SOCKET_001
* @tc.name : testCreateWebSocket001
* @tc.desc : Creates a web socket connection.
* @tc.size : MediumTest
* @tc.type : Method
* @tc.level : Level 2
*/
it('testCreateWebSocket001', 0, async function (done) {
var mWebSocket = webSocket.createWebSocket();
expect(mWebSocket != null).assertTrue();
mWebSocket.close((error, value) => {
if (!error) {
console.log(`case success:` + value);
expect(value).assertTrue();
done();
} else {
console.log(`error, case failed,errCode:` + error.code);
expect(error.code).assertEqual(2302999);
done();
}
});
done();
});
/*
* @tc.number: TEST_WEB_SOCKET_REQUEST_OPTIONS_HEADER_001
* @tc.name : testWebSocketRequestOptions_header001
* @tc.desc : webSocketRequestOptions.header
* @tc.size : MediumTest
* @tc.type : Field
* @tc.level : Level 1
*/
it('testWebSocketRequestOptions_header001', 0, async function (done) {
let webSocketRequestOptions: webSocket.WebSocketRequestOptions = {
header: "test header"
}
expect(webSocketRequestOptions.header === "test header").assertTrue();
done();
});
/*
* @tc.number: TEST_WEB_SOCKET_CLOSE_OPTIONS_CODE_001
* @tc.name : testWebSocketCloseOptions_code001
* @tc.desc : webSocketCloseOptions.code
* @tc.size : MediumTest
* @tc.type : Field
* @tc.level : Level 1
*/
it('testWebSocketCloseOptions_code001', 0, async function (done) {
let webSocketCloseOptions: webSocket.WebSocketCloseOptions = {
code: 1,
reason: "test reason"
}
expect(webSocketCloseOptions.code === 1).assertTrue();
done();
});
/*
* @tc.number: TEST_WEB_SOCKET_CLOSE_OPTIONS_001
* @tc.name : testWebSocketCloseOptions_Reason001
* @tc.desc : webSocketCloseOptions.reason
* @tc.size : MediumTest
* @tc.type : Field
* @tc.level : Level 1
*/
it('testWebSocketCloseOptions_Reason001', 0, async function (done) {
let webSocketCloseOptions: webSocket.WebSocketCloseOptions = {
code: 1,
reason: "test reason"
}
expect(webSocketCloseOptions.reason).assertEqual("test reason");
done();
});
/*
* @tc.number: TEST_CONNECT_001
* @tc.name : testConnect001
* @tc.desc : Initiates a WebSocket request to establish a WebSocket connection to a given URL.
* @tc.size : MediumTest
* @tc.type : Method
* @tc.level : Level 2
*/
it('testConnect001', 0, async function (done) {
let mWebSocket = webSocket.createWebSocket();
mWebSocket.connect(null, (error, value) => {
if (!error) {
console.log(`case success11:` + value);
expect(value).assertTrue();
done();
} else {
console.log(`error, case failed,errCode:` + error.code);
expect(error.code).assertEqual(401);
done();
}
});
});
/*
* @tc.number: TEST_CONNECT_002
* @tc.name : testConnect002
* @tc.desc : Initiates a WebSocket request to establish a WebSocket connection to a given URL.
* @tc.size : MediumTest
* @tc.type : Method
* @tc.level : Level 2
*/
it('testConnect002', 0, async function (done) {
let mWebSocket = webSocket.createWebSocket();
let webSocketRequestOptions: webSocket.WebSocketRequestOptions = {
header: {
key: "value",
key2: "value2"
}
}
console.info('webSocket: start11');
mWebSocket.connect("ws://19211.16811.1.100:8081/string", webSocketRequestOptions, (error, value) => {
if (!error) {
console.log(`case success11:` + value);
expect(value).assertTrue();
done();
} else {
console.log(`error, case failed,errCode:` + error.code);
expect(error.code).assertEqual(-1);
done();
}
});
});
/*
* @tc.number: TEST_CONNECT_003
* @tc.name : testConnect003
* @tc.desc : Initiates a WebSocket request to establish a WebSocket connection to a given URL.
* @tc.size : MediumTest
* @tc.type : Method
* @tc.level : Level 2
*/
it('testConnect003', 0, async function (done) {
let mWebSocket = webSocket.createWebSocket();
mWebSocket.connect("", (error, value) => {
if (!error) {
console.log(`case success11:` + value);
expect(value).assertTrue();
done();
} else {
console.log(`error, case failed,errCode:` + error.code);
expect(error.code).assertEqual(-1);
done();
}
});
});
/*
* @tc.number: TEST_CONNECT_004
* @tc.name : testConnect004
* @tc.desc : Initiates a WebSocket request to establish a WebSocket connection to a given URL.
* @tc.size : MediumTest
* @tc.type : Method
* @tc.level : Level 2
*/
it('testConnect004', 0, async function (done) {
let mWebSocket = webSocket.createWebSocket();
mWebSocket.connect(null).then(value => {
console.log(`case success11:` + value);
expect(value).assertTrue();
done();
}).catch((error) => {
console.log(`error, case failed,errCode:` + error.code);
expect(error.code).assertEqual(401);
done();
});
});
/*
* @tc.number: TEST_CONNECT_005
* @tc.name : testConnect005
* @tc.desc : Initiates a WebSocket request to establish a WebSocket connection to a given URL.
* @tc.size : MediumTest
* @tc.type : Method
* @tc.level : Level 2
*/
it('testConnect005', 0, async function (done) {
let mWebSocket = webSocket.createWebSocket();
let webSocketRequestOptions: webSocket.WebSocketRequestOptions = {
header: {
key: "value",
key2: "value2"
}
}
mWebSocket.connect("ws://19211.16811.1.100:8081/string", webSocketRequestOptions).then(value => {
console.log(`case success11:` + value);
expect(value).assertTrue();
done();
}).catch((error) => {
console.log(`error, case failed,errCode:` + error.code);
expect(error.code).assertEqual(-1);
done();
});
});
/*
* @tc.number: TEST_SEND_001
* @tc.name : testSend001
* @tc.desc : Sends data through a WebSocket connection.
* @tc.size : MediumTest
* @tc.type : Method
* @tc.level : Level 2
*/
it('testSend001', 0, async function (done) {
let mWebSocket = webSocket.createWebSocket();
mWebSocket.send("test data", (error, value) => {
if (!error) {
console.log(`case success,data:` + value);
expect(value).assertTrue();
done();
} else {
console.log(`error, case failed,errCode:` + error.code);
expect(error.code).assertEqual(2302999);
done();
}
});
});
/*
* @tc.number: TEST_SEND_002
* @tc.name : testSend002
* @tc.desc : Sends data through a WebSocket connection.
* @tc.size : MediumTest
* @tc.type : Method
* @tc.level : Level 2
*/
it('testSend002', 0, async function (done) {
let mWebSocket = webSocket.createWebSocket();
let promise = mWebSocket.send("test data");
promise.then(value => {
console.log(`case success,data:` + value);
expect(value).assertTrue();
done();
}).catch((error) => {
console.log(`error, case failed,errCode:` + error.code);
expect(error.code).assertEqual(2302999);
done();
});
});
/*
* @tc.number: TEST_SEND_003
* @tc.name : testSend003
* @tc.desc : Sends data through a WebSocket connection.
* @tc.size : MediumTest
* @tc.type : Method
* @tc.level : Level 2
*/
it('testSend003', 0, async function (done) {
let mWebSocket = webSocket.createWebSocket();
var str = "Hello, server!(arrayBuffer promise mode)";
var buf = new ArrayBuffer(str.length);
var message = new Uint8Array(buf);
for (var i = 0, strLen = str.length; i < strLen; i++) {
message[i] = str.charCodeAt(i);
}
let promise = mWebSocket.send(message.buffer);
promise.then(value => {
console.log(`case success,data:` + value);
expect(value).assertTrue();
done();
}).catch((error) => {
console.log(`error, case failed,errCode:` + error.code);
expect(error.code).assertEqual(2302999);
done();
});
});
/*
* @tc.number: TEST_SEND_004
* @tc.name : testSend004
* @tc.desc : Sends data through a WebSocket connection.
* @tc.size : MediumTest
* @tc.type : Method
* @tc.level : Level 2
*/
it('testSend004', 0, async function (done) {
let mWebSocket = webSocket.createWebSocket();
var str = "Hello, server!(arrayBuffer promise mode)";
var buf = new ArrayBuffer(str.length);
var message = new Uint8Array(buf);
for (var i = 0, strLen = str.length; i < strLen; i++) {
message[i] = str.charCodeAt(i);
}
mWebSocket.send(message.buffer, (error, value) => {
if (!error) {
console.log(`case success:` + value);
expect(value).assertTrue();
done();
} else {
console.log(`error, case failed,errCode:` + error.code);
expect(error.code).assertEqual(2302999);
done();
}
});
});
/*
* @tc.number: TEST_CLOSE_001
* @tc.name : testClose001
* @tc.desc : Closes a WebSocket connection.
* @tc.size : MediumTest
* @tc.type : Method
* @tc.level : Level 2
*/
it('testClose001', 0, async function (done) {
let mWebSocket = webSocket.createWebSocket();
mWebSocket.close((error, value) => {
if (!error) {
console.log(`case success:` + value);
expect(value).assertTrue();
done();
} else {
console.log(`error, case failed,errCode:` + error.code);
expect(error.code).assertEqual(2302999);
done();
}
});
});
/*
* @tc.number: TEST_CLOSE_002
* @tc.name : testClose002
* @tc.desc : Closes a WebSocket connection.
* @tc.size : MediumTest
* @tc.type : Method
* @tc.level : Level 2
*/
it('testClose002', 0, async function (done) {
let mWebSocket = webSocket.createWebSocket();
let webSocketCloseOptions: webSocket.WebSocketCloseOptions = {
code: 1,
reason: "test reason"
}
mWebSocket.close(webSocketCloseOptions, (error, value) => {
if (!error) {
console.log(`case success,data:` + value);
expect(value).assertTrue();
done();
} else {
console.log(`error, case failed,errCode:` + error.code);
expect(error.code).assertEqual(2302999);
done();
}
});
});
/*
* @tc.number: TEST_CLOSE_003
* @tc.name : testClose003
* @tc.desc : Closes a WebSocket connection.
* @tc.size : MediumTest
* @tc.type : Method
* @tc.level : Level 2
*/
it('testClose003', 0, async function (done) {
let mWebSocket = webSocket.createWebSocket();
let webSocketCloseOptions: webSocket.WebSocketCloseOptions = {
code: 1,
reason: "test reason"
}
mWebSocket.close(webSocketCloseOptions).then(value => {
console.log(`success11`);
expect(true).assertTrue();
done();
}).catch((error) => {
console.log(`error, case failed,errCode:` + error.code);
expect(error.code).assertEqual(2302999);
done();
});
});
/*
* @tc.number: TEST_ON_OPEN_001
* @tc.name : testOn_Open001
* @tc.desc : Subscribe to WebSocket open events, using callback as an asynchronous method.
* @tc.size : MediumTest
* @tc.type : Method
* @tc.level : Level 2
*/
it('testOn_Open001', 0, async function (done) {
let ws = webSocket.createWebSocket();
done();
console.log("testOn_Open001: 0");
ws.on('open', (err, value) => {
console.log("testOn_Open001: 1");
console.log("on open, status:" + value['status'] + ", message:" + value['message']);
console.log("testOn_Open001: 2");
expect(true).assertTrue();
done();
});
ws.off('open');
console.log("testOn_Open001: 3");
});
/*
* @tc.number: TEST_OFF_OPEN_001
* @tc.name : testOff_Open001
* @tc.desc : Unsubscribe from WebSocket open events, using callback as an asynchronous method.
* @tc.size : MediumTest
* @tc.type : Method
* @tc.level : Level 2
*/
it('testOff_Open001', 0, async function (done) {
let ws = webSocket.createWebSocket();
done();
let callback1 = (err, value) => {
console.log("on open, status:" + value['status'] + ", message:" + value['message']);
}
ws.on('open', callback1);
ws.off('open', callback1);
expect(true).assertTrue();
});
/*
* @tc.number: TEST_ON_OFF_MESSAGE_001
* @tc.name : testOn_Off_Message001
* @tc.desc : Subscribe to WebSocket received server message events, using callback as an asynchronous method. The maximum length of each message is 4K, and more than 4K automatic fragmentation.
* @tc.size : MediumTest
* @tc.type : Method
* @tc.level : Level 2
*/
it('testOn_Off_Message001', 0, async function (done) {
let ws = webSocket.createWebSocket();
done();
ws.on('message', (err, value) => {
console.log("on message, message:" + value);
expect(true).assertTrue();
});
ws.off('message');
});
/*
* @tc.number: TEST_On_Off_CLOSE_001
* @tc.name : testOn_Off_Close001
* @tc.desc : Subscribe to WebSocket shutdown events, using the callback method as an asynchronous method.
* @tc.size : MediumTest
* @tc.type : Method
* @tc.level : Level 2
*/
it('testOn_Off_Close001', 0, async function (done) {
let ws = webSocket.createWebSocket();
done();
ws.on('close', (err, value) => {
console.log("on close, code is " + value.code + ", reason is " + value.reason);
});
ws.off('close');
expect(true).assertTrue();
});
/*
* @tc.number: TEST_ON_OFF_ERROR_001
* @tc.name : testOn_Off_Error001
* @tc.desc : Unsubscribe to WebSocket shutdown events, using the callback method as an asynchronous method.
* @tc.size : MediumTest
* @tc.type : Method
* @tc.level : Level 2
*/
it('testOn_Off_Error001', 0, async function (done) {
let ws = webSocket.createWebSocket();
done();
ws.on('error', (err) => {
console.log("on error, error:" + JSON.stringify(err))
});
ws.off('error');
expect(true).assertTrue();
});
})
}
\ No newline at end of file
{
"module": {
"name": "entry_test",
"type": "feature",
"description": "$string:module_test_desc",
"mainElement": "TestAbility",
"deviceTypes": [
"phone"
],
"deliveryWithInstall": true,
"installationFree": false,
"pages": "$profile:test_pages",
"abilities": [
{
"name": "TestAbility",
"srcEntry": "./ets/TestAbility/TestAbility.ets",
"description": "$string:TestAbility_desc",
"icon": "$media:icon",
"label": "$string:TestAbility_label",
"exported": true,
"startWindowIcon": "$media:icon",
"startWindowBackground": "$color:start_window_background",
"skills": [
{
"actions": [
"action.system.home"
],
"entities": [
"entity.system.home"
]
}
]
}
],
"requestPermissions": [
{
"name": "ohos.permission.INTERNET"
},
{
"name": "ohos.permission.GET_NETWORK_INFO"
}
]
}
}
{
"color": [
{
"name": "start_window_background",
"value": "#FFFFFF"
}
]
}
\ No newline at end of file
{
"string": [
{
"name": "module_test_desc",
"value": "test ability description"
},
{
"name": "TestAbility_desc",
"value": "the test ability"
},
{
"name": "TestAbility_label",
"value": "test label"
}
]
}
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册