未验证 提交 64f2653e 编写于 作者: O openharmony_ci 提交者: Gitee

!9276 完成commonlibrary子系统xml模块的跨平台测试套

Merge pull request !9276 from huyanqiang/commonlibrary_llq7_112
......@@ -17,6 +17,7 @@ group("commonlibrary") {
if (is_standard_system) {
deps = [
"crossplatform:crossplatform",
"crossplatform/commonlibraryxmletstest:ActsCrossplatformXmlTest",
"ets_utils:ets_utils",
"toolchain:toolchain",
]
......
{
"app": {
"bundleName": "ohos.acts.commonlibrary.crossplatform.convertxml.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("ActsCrossplatformXmlTest") {
hap_profile = "src/main/module.json"
deps = [
":windowStage_js_assets",
":windowStage_resources",
]
ets2abc = true
certificate_profile = "./signature/openharmony_sx.p7b"
hap_name = "ActsCrossplatformXmlTest"
subsystem_name = "commonlibrary"
part_name = "ets_utils"
}
ohos_app_scope("windowStage_app_profile") {
app_profile = "AppScope/app.json"
sources = [ "AppScope/resources" ]
}
ohos_js_assets("windowStage_js_assets") {
source_dir = "src/main/ets"
}
ohos_resources("windowStage_resources") {
sources = [ "src/main/resources" ]
deps = [ ":windowStage_app_profile" ]
hap_profile = "src/main/module.json"
}
{
"description": "Configuration for hjunit demo Tests",
"driver": {
"type": "OHJSUnitTest",
"test-timeout": "60000",
"shell-timeout": "60000",
"bundle-name": "ohos.acts.commonlibrary.crossplatform.convertxml.normal",
"module-name": "entry_test"
},
"kits": [
{
"test-file-name": [
"ActsCrossplatformXmlTest.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 xmlTest from './xml.test'
import xmlParseOptionTest from './xmlEventType.test'
import xmlEventTypeTest from './xmlParseOption.test'
export default function testsuite() {
xmlTest();
xmlParseOptionTest();
xmlEventTypeTest();
}
\ 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 xml from "@ohos.xml";
import util from "@ohos.util";
export default function XmlSerializerXmlPullParserTest() {
describe("XmlEventTypeTest", function () {
/**
* @tc.number: TEST_START_DOCUMENT_001
* @tc.name : testSTART_DOCUMENT001
* @tc.desc : Start file event.
* @tc.size : MediumTest
* @tc.type : Enum
* @tc.level : Level 0
*/
it("testSTART_DOCUMENT001", 0, function () {
var event = xml.EventType.START_DOCUMENT;
expect(event).assertEqual(0);
});
/**
* @tc.number: TEST_END_DOCUMENT_001
* @tc.name : testEND_DOCUMENT001
* @tc.desc : End file event.
* @tc.size : MediumTest
* @tc.type : Enum
* @tc.level : Level 0
*/
it("testEND_DOCUMENT001", 0, function () {
var event = xml.EventType.END_DOCUMENT;
expect(event).assertEqual(1);
});
/**
* @tc.number: TEST_START_TAG_001
* @tc.name : testSTART_TAG001
* @tc.desc : Start the tag event.
* @tc.size : MediumTest
* @tc.type : Enum
* @tc.level : Level 0
*/
it("testSTART_TAG001", 0, function () {
var event = xml.EventType.START_TAG;
expect(event).assertEqual(2);
});
/**
* @tc.number: TEST_END_TAG_001
* @tc.name : testEND_TAG001
* @tc.desc : End tag event.
* @tc.size : MediumTest
* @tc.type : Enum
* @tc.level : Level 0
*/
it("testEND_TAG001", 0, function () {
var event = xml.EventType.END_TAG;
expect(event).assertEqual(3);
});
/**
* @tc.number: TEST_TEXT_001
* @tc.name : testTEXT001
* @tc.desc : Text event.
* @tc.size : MediumTest
* @tc.type : Enum
* @tc.level : Level 0
*/
it("testTEXT001", 0, function () {
var event = xml.EventType.TEXT;
expect(event).assertEqual(4);
});
/**
* @tc.number: TEST_CDSECT_001
* @tc.name : testCDSECT001
* @tc.desc : CDATA Event.
* @tc.size : MediumTest
* @tc.type : Enum
* @tc.level : Level 0
*/
it("testCDSECT001", 0, function () {
var event = xml.EventType.CDSECT;
expect(event).assertEqual(5);
});
/**
* @tc.number: TEST_COMMENT_001
* @tc.name : testCOMMENT001
* @tc.desc : XML comment event.
* @tc.size : MediumTest
* @tc.type : Enum
* @tc.level : Level 0
*/
it("testCOMMENT001", 0, function () {
var event = xml.EventType.COMMENT;
expect(event).assertEqual(6);
});
/**
* @tc.number: TEST_DOCDECL_001
* @tc.name : testDOCDECL001
* @tc.desc : XML document type declaration event.
* @tc.size : MediumTest
* @tc.type : Enum
* @tc.level : Level 0
*/
it("testDOCDECL001", 0, function () {
var event = xml.EventType.DOCDECL;
expect(event).assertEqual(7);
});
/**
* @tc.number: TEST_INSTRUCTION_001
* @tc.name : testINSTRUCTION001
* @tc.desc : XML processing instruction declaration event.
* @tc.size : MediumTest
* @tc.type : Enum
* @tc.level : Level 0
*/
it("testINSTRUCTION001", 0, function () {
var event = xml.EventType.INSTRUCTION;
expect(event).assertEqual(8);
});
/**
* @tc.number: TEST_ENTITY_REFERENCE_001
* @tc.name : testENTITY_REFERENCE001
* @tc.desc : Entity reference event.
* @tc.size : MediumTest
* @tc.type : Enum
* @tc.level : Level 0
*/
it("testENTITY_REFERENCE001", 0, function () {
var event = xml.EventType.ENTITY_REFERENCE;
expect(event).assertEqual(9);
});
/**
* @tc.number: TEST_WHITESPACE_001
* @tc.name : testWHITESPACE001
* @tc.desc : Blank event.
* @tc.size : MediumTest
* @tc.type : Enum
* @tc.level : Level 0
*/
it("testWHITESPACE001", 0, function () {
var event = xml.EventType.WHITESPACE;
expect(event).assertEqual(10);
});
});
}
/*
* 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 xml from "@ohos.xml";
import util from "@ohos.util";
export default function XmlSerializerXmlPullParserTest() {
describe("XmlParseOptionTest", function () {
/**
* @tc.number: TEST_PARSE_OPTION_001
* @tc.name : testParseOptions001
* @tc.desc : Starts parsing the XML file.
* @tc.size : MediumTest
* @tc.type : Method
* @tc.level : Level 2
*/
it("testParseOptions001", 0, function () {
var strXml =
'<?xml version="1.0" encoding="utf-8"?>' +
'<!DOCTYPE note [\n<!ENTITY foo "baa">]>' +
'<note importance="high" logged="true">' +
" <![CDATA[\r\nfuncrion matchwo(a,6)\r\n{\r\nreturn 1;\r\n}\r\n]]>" +
" <!--Hello, World!-->" +
" <company>John &amp; Hans</company>" +
" <title>Happy</title>" +
" <title>Happy</title>" +
" <lens>Work</lens>" +
" <lens>Play</lens>" +
" <?go there?>" +
" <a><b/></a>" +
' <h:table xmlns:h="http://www.w3.org/TR/html4/">' +
" <h:tr>" +
" <h:td>Apples</h:td>" +
" <h:td>Bananas</h:td>" +
" </h:tr>" +
" </h:table>" +
"</note>";
let textEncoder = new util.TextEncoder();
let arrbuffer = textEncoder.encodeInto(strXml);
let that = new xml.XmlPullParser(arrbuffer.buffer, "UTF-8");
var str = "";
function func2(name, value) {
str += name + ":" + value;
return true;
}
var options = {
supportDoctype: true,
ignoreNameSpace: true,
attributeValueCallbackFunction: func2,
};
that.parse(options);
var str1 =
"importance:highlogged:truexmlns:h:http://www.w3.org/TR/html4/";
expect(str).assertEqual(str1);
});
/**
* @tc.number: TEST_PARSE_OPTION_002
* @tc.name : testParseOptions002
* @tc.desc : Starts parsing the XML file.
* @tc.size : MediumTest
* @tc.type : Method
* @tc.level : Level 2
*/
it("testParseOptions002", 0, function () {
var strXml =
'<?xml version="1.0" encoding="utf-8"?>' +
'<!DOCTYPE note [\n<!ENTITY foo "baa">]>' +
'<note importance="high" logged="true">' +
" <![CDATA[\r\nfuncrion matchwo(a,6)\r\n{\r\nreturn 1;\r\n}\r\n]]>" +
" <!--Hello, World!-->" +
" <company>John &amp; Hans</company>" +
" <title>Happy</title>" +
" <title>Happy</title>" +
" <lens>Work</lens>" +
" <lens>Play</lens>" +
" <?go there?>" +
" <a><b/></a>" +
' <h:table xmlns:h="http://www.w3.org/TR/html4/">' +
" <h:tr>" +
" <h:td>Apples</h:td>" +
" <h:td>Bananas</h:td>" +
" </h:tr>" +
" </h:table>" +
"</note>";
let textEncoder = new util.TextEncoder();
let arrbuffer = textEncoder.encodeInto(strXml);
let that = new xml.XmlPullParser(arrbuffer.buffer);
var str1 = "";
function func1(name, value) {
str1 += name + value + " ";
return true;
}
var options = {
supportDoctype: true,
ignoreNameSpace: true,
tagValueCallbackFunction: func1,
};
that.parse(options);
var str3 =
' note [<!ENTITY foo "baa">] note funcrion matchwo(a,6){return 1;} Hello, World! ' +
"company John amp;amp; Hans company title Happy title title Happy title " +
"lens Work lens lens Play lens go there a b b a h:table " +
"h:tr h:td Apples h:td h:td Bananas h:td h:tr " +
"h:table note ";
expect(str1).assertEqual(str3);
});
/**
* @tc.number: TEST_PARSE_OPTION_002
* @tc.name : testParseOptions002
* @tc.desc : Starts parsing the XML file.
* @tc.size : MediumTest
* @tc.type : Method
* @tc.level : Level 2
*/
it("testParseOptions003", 0, function () {
let strXml =
'<?xml version="1.0" encoding="utf-8"?>' +
'<note importance="high" logged="true">' +
" <title>Happy</title>" +
" <todo>Work</todo>" +
" <todo>Play</todo>" +
"</note>";
let textEncoder = new util.TextEncoder();
let arrbuffer = textEncoder.encodeInto(strXml);
let that = new xml.XmlPullParser(arrbuffer.buffer);
let str = "";
function func(key, value) {
str += "key:" + key + " value:" + value.getColumnNumber() + " ";
return true;
}
let options = {
supportDoctype: true,
ignoreNameSpace: true,
tokenValueCallbackFunction: func,
};
that.parse(options);
let result =
"key:0 value:1 key:2 value:77 key:10 value:81 key:2 value:88 key:4 value:93 " +
"key:3 value:101 key:10 value:105 key:2 value:111 key:4 value:115 key:3 value:122 key:10 value:126 " +
"key:2 value:132 key:4 value:136 key:3 value:143 key:3 value:150 key:1 value:299 ";
expect(str).assertEqual(result);
});
});
}
{
"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"
]
}
]
}
]
}
}
{
"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.
先完成此消息的编辑!
想要评论请 注册