提交 664cb73e 编写于 作者: H hu0475

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

Signed-off-by: Nhu0475 <huyanqiang5@huawei.com>
上级 166733e6
...@@ -18,6 +18,7 @@ group("commonlibrary") { ...@@ -18,6 +18,7 @@ group("commonlibrary") {
deps = [ deps = [
"ets_utils:ets_utils", "ets_utils:ets_utils",
"toolchain:toolchain", "toolchain:toolchain",
"crossplatform/commonlibraryxmletstest:xml_ets_test"
] ]
} }
} }
{
"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": 9,
"targetAPIVersion": 9,
"car": {
"apiCompatibleVersion": 9,
"singleUser": false
}
}
}
import("//test/xts/tools/build/suite.gni")
ohos_js_hap_suite("xml_ets_test") {
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 = "xml_ets_test"
subsystem_name = "commonlibrary"
part_name = "ets_utils"
}
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"
}
\ No newline at end of file
{
"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.commonlibrary.crossplatform.convertxml.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
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
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
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("XmlSerializerXmlPullParserTest", function () {
/**
* @tc.number: TEST_CONSTRUCTOR_001
* @tc.name : testConstructor001
* @tc.desc : Create an xml instance. For example: let xml = new xml.XmlSerializer(arrayBuffer).
* @tc.size : MediumTest
* @tc.type : Method
* @tc.level : Level 2
*/
it("testConstructor001", 0, function () {
try {
const myMAX = 2048;
var arrayBuffer = new ArrayBuffer(myMAX);
var thatSer = new xml.XmlSerializer(arrayBuffer);
expect(thatSer != null).assertEqual(true);
} catch (err) {
console.log("testConstructor001 meet error: " + err);
}
});
/**
* @tc.number: TEST_CONSTRUCTOR_002
* @tc.name : testConstructor002
* @tc.desc : Create an xml instance. For example: let xml = new xml.XmlSerializer(arrayBuffer, encoding).
* @tc.size : MediumTest
* @tc.type : Method
* @tc.level : Level 2
*/
it("testConstructor002", 0, function () {
try {
const myMAX = 2048;
var arrayBuffer = new ArrayBuffer(myMAX);
var thatSer = new xml.XmlSerializer(arrayBuffer, "utf-8");
expect(thatSer != null).assertEqual(true);
} catch (err) {
console.log("testConstructor001 meet error: " + err);
}
});
/**
* @tc.number: TEST_SET_ATTRIBUTES_001
* @tc.name : testsetAttributes001
* @tc.desc : Write an attribute.
* @tc.size : MediumTest
* @tc.type : Method
* @tc.level : Level 2
*/
it("testSetAttributes001", 0, function () {
const myMAX = 2048;
var arrayBuffer = new ArrayBuffer(myMAX);
var thatSer = new xml.XmlSerializer(arrayBuffer);
thatSer.startElement("note");
thatSer.setAttributes("importance1", "high1");
thatSer.endElement();
var result = '<note importance1="high1"/>';
var view = new Uint8Array(arrayBuffer);
var view1 = "";
for (var i = 0; i < result.length; ++i) {
view1 = view1 + String.fromCodePoint(view[i]);
}
expect(view1).assertEqual(result);
});
/**
* @tc.number: TEST_SET_ATTRIBUTES_002
* @tc.name : testsetAttributes002
* @tc.desc : Write an attribute.
* @tc.size : MediumTest
* @tc.type : Method
* @tc.level : Level 2
*/
it("testSetAttributes002", 0, function () {
const myMAX = 2048;
var arrayBuffer = new ArrayBuffer(myMAX);
var thatSer = new xml.XmlSerializer(arrayBuffer);
thatSer.startElement("note");
thatSer.setAttributes("importance1", "high1");
thatSer.setAttributes("importance2", "high2");
thatSer.endElement();
var result = '<note importance1="high1" importance2="high2"/>';
var view = new Uint8Array(arrayBuffer);
var view1 = "";
for (var i = 0; i < result.length; ++i) {
view1 = view1 + String.fromCodePoint(view[i]);
}
expect(view1).assertEqual(result);
});
/**
* @tc.number: TEST_SET_ATTRIBUTES_003
* @tc.name : testsetAttributes003
* @tc.desc : Write an attribute.
* @tc.size : MediumTest
* @tc.type : Method
* @tc.level : Level 2
*/
it("testSetAttributes003", 0, function () {
const myMAX = 2048;
var arrayBuffer = new ArrayBuffer(myMAX);
var thatSer = new xml.XmlSerializer(arrayBuffer);
thatSer.startElement("note");
thatSer.setAttributes("importance1", "high1");
thatSer.setAttributes("importance2", "high2");
thatSer.setAttributes("importance3", "high3");
thatSer.endElement();
var result =
'<note importance1="high1" importance2="high2" importance3="high3"/>';
var view = new Uint8Array(arrayBuffer);
var view1 = "";
for (var i = 0; i < result.length; ++i) {
view1 = view1 + String.fromCodePoint(view[i]);
}
expect(view1).assertEqual(result);
});
/**
* @tc.number: TEST_SET_ATTRIBUTES_004
* @tc.name : testsetAttributes004
* @tc.desc : Write an attribute.
* @tc.size : MediumTest
* @tc.type : Method
* @tc.level : Level 2
*/
it("testSetAttributes004", 0, function () {
const myMAX = 2048;
var arrayBuffer = new ArrayBuffer(myMAX);
var thatSer = new xml.XmlSerializer(arrayBuffer);
thatSer.startElement("note");
thatSer.setAttributes("importance1", "high1");
thatSer.setAttributes("importance2", "high2");
thatSer.setAttributes("importance3", "high3");
thatSer.setAttributes("importance4", "high4");
thatSer.endElement();
var result =
'<note importance1="high1" importance2="high2" importance3="high3" importance4="high4"/>';
var view = new Uint8Array(arrayBuffer);
var view1 = "";
for (var i = 0; i < result.length; ++i) {
view1 = view1 + String.fromCodePoint(view[i]);
}
expect(view1).assertEqual(result);
});
/**
* @tc.number: TEST_ADD_EMPTY_ELEMENT_001
* @tc.name : testAddEmptyElement001
* @tc.desc : Add an empty element.
* @tc.size : MediumTest
* @tc.type : Method
* @tc.level : Level 2
*/
it("testAddEmptyElement001", 0, function () {
const myMAX = 2048;
var arrayBuffer = new ArrayBuffer(myMAX);
var thatSer = new xml.XmlSerializer(arrayBuffer);
thatSer.startElement("note");
thatSer.addEmptyElement("a");
thatSer.endElement();
var result = "<note>\r\n <a/>\r\n</note>";
var view = new Uint8Array(arrayBuffer);
var view1 = "";
for (var i = 0; i < result.length; ++i) {
view1 = view1 + String.fromCodePoint(view[i]);
}
expect(view1).assertEqual(result);
});
/**
* @tc.number: TEST_ADD_EMPTY_ELEMENT_002
* @tc.name : testAddEmptyElement002
* @tc.desc : Add an empty element.
* @tc.size : MediumTest
* @tc.type : Method
* @tc.level : Level 2
*/
it("testAddEmptyElement002", 0, function () {
const myMAX = 2048;
var arrayBuffer = new ArrayBuffer(myMAX);
var thatSer = new xml.XmlSerializer(arrayBuffer);
thatSer.startElement("note");
thatSer.endElement();
thatSer.addEmptyElement("b");
var result = "<note/>\r\n<b/>";
var view = new Uint8Array(arrayBuffer);
var view1 = "";
for (var i = 0; i < result.length; ++i) {
view1 = view1 + String.fromCodePoint(view[i]);
}
expect(view1).assertEqual(result);
});
/**
* @tc.number: TEST_ADD_EMPTY_ELEMENT_003
* @tc.name : testAddEmptyElement003
* @tc.desc : Add an empty element.
* @tc.size : MediumTest
* @tc.type : Method
* @tc.level : Level 2
*/
it("testAddEmptyElement003", 0, function () {
const myMAX = 2048;
var arrayBuffer = new ArrayBuffer(myMAX);
var thatSer = new xml.XmlSerializer(arrayBuffer);
thatSer.addEmptyElement("c");
thatSer.startElement("note");
thatSer.endElement();
var result = "<c/>\r\n<note/>";
var view = new Uint8Array(arrayBuffer);
var view1 = "";
for (var i = 0; i < result.length; ++i) {
view1 = view1 + String.fromCodePoint(view[i]);
}
expect(view1).assertEqual(result);
});
/**
* @tc.number: TEST_ADD_EMPTY_ELEMENT_004
* @tc.name : testAddEmptyElement004
* @tc.desc : Add an empty element.
* @tc.size : MediumTest
* @tc.type : Method
* @tc.level : Level 2
*/
it("testAddEmptyElement004", 0, function () {
const myMAX = 2048;
var arrayBuffer = new ArrayBuffer(myMAX);
var thatSer = new xml.XmlSerializer(arrayBuffer);
thatSer.addEmptyElement("d");
var result = "<d/>";
var view = new Uint8Array(arrayBuffer);
var view1 = "";
for (var i = 0; i < result.length; ++i) {
view1 = view1 + String.fromCodePoint(view[i]);
}
expect(view1).assertEqual(result);
});
/**
* @tc.number: TEST_ADD_EMPTY_ELEMENT_005
* @tc.name : testAddEmptyElement005
* @tc.desc : Add an empty element.
* @tc.size : MediumTest
* @tc.type : Method
* @tc.level : Level 2
*/
it("testAddEmptyElement005", 0, function () {
const myMAX = 2048;
var arrayBuffer = new ArrayBuffer(myMAX);
var thatSer = new xml.XmlSerializer(arrayBuffer);
thatSer.startElement("note");
thatSer.addEmptyElement("c");
thatSer.addEmptyElement("d");
thatSer.endElement();
var result = "<note>\r\n <c/>\r\n <d/>\r\n</note>";
var view = new Uint8Array(arrayBuffer);
var view1 = "";
for (var i = 0; i < result.length; ++i) {
view1 = view1 + String.fromCodePoint(view[i]);
}
expect(view1).assertEqual(result);
});
/**
* @tc.number: TEST_SET_DECLARATION_001
* @tc.name : testSetDeclaration001
* @tc.desc : Writes xml declaration with encoding. For example: <?xml version="1.0" encoding="utf-8"?>.
* @tc.size : MediumTest
* @tc.type : Method
* @tc.level : Level 2
*/
it("testSetDeclaration001", 0, function () {
var arrayBuffer = new ArrayBuffer(2048);
var thatSer = new xml.XmlSerializer(arrayBuffer, "utf-8");
thatSer.setDeclaration();
var result = '<?xml version="1.0" encoding="utf-8"?>';
var view = new Uint8Array(arrayBuffer);
var view1 = "";
for (var i = 0; i < result.length; ++i) {
view1 = view1 + String.fromCodePoint(view[i]);
}
expect(view1).assertEqual(result);
});
/**
* @tc.number: TEST_START_ELEMENT_001
* @tc.name : testStartElement001
* @tc.desc : Writes an elemnet start tag with the given name.
* @tc.size : MediumTest
* @tc.type : Method
* @tc.level : Level 2
*/
it("testStartElement001", 0, function () {
const myMAX = 2048;
var arrayBuffer = new ArrayBuffer(myMAX);
var thatSer = new xml.XmlSerializer(arrayBuffer);
thatSer.startElement("note1");
thatSer.endElement();
var result = "<note1/>";
var view = new Uint8Array(arrayBuffer);
var view1 = "";
for (var i = 0; i < result.length; ++i) {
view1 = view1 + String.fromCodePoint(view[i]);
}
expect(view1).assertEqual(result);
});
/**
* @tc.number: TEST_START_ELEMENT_002
* @tc.name : testStartElement002
* @tc.desc : Writes an elemnet start tag with the given name.
* @tc.size : MediumTest
* @tc.type : Method
* @tc.level : Level 2
*/
it("testStartElement002", 0, function () {
const myMAX = 2048;
var arrayBuffer = new ArrayBuffer(myMAX);
var thatSer = new xml.XmlSerializer(arrayBuffer);
thatSer.startElement("note1");
thatSer.endElement();
thatSer.startElement("note2");
thatSer.endElement();
var result = "<note1/>\r\n<note2/>";
var view = new Uint8Array(arrayBuffer);
var view1 = "";
for (var i = 0; i < result.length; ++i) {
view1 = view1 + String.fromCodePoint(view[i]);
}
expect(view1).assertEqual(result);
});
/**
* @tc.number: TEST_START_ELEMENT_003
* @tc.name : testStartElement003
* @tc.desc : Writes an elemnet start tag with the given name.
* @tc.size : MediumTest
* @tc.type : Method
* @tc.level : Level 2
*/
it("testStartElement003", 0, function () {
const myMAX = 2048;
var arrayBuffer = new ArrayBuffer(myMAX);
var thatSer = new xml.XmlSerializer(arrayBuffer);
thatSer.startElement("note1");
thatSer.startElement("note2");
thatSer.endElement();
thatSer.endElement();
var result = "<note1>\r\n <note2/>\r\n</note1>";
var view = new Uint8Array(arrayBuffer);
var view1 = "";
for (var i = 0; i < result.length; ++i) {
view1 = view1 + String.fromCodePoint(view[i]);
}
expect(view1).assertEqual(result);
});
/**
* @tc.number: TEST_START_ELEMENT_004
* @tc.name : testStartElement004
* @tc.desc : Writes an elemnet start tag with the given name.
* @tc.size : MediumTest
* @tc.type : Method
* @tc.level : Level 2
*/
it("testStartElement004", 0, function () {
const myMAX = 2048;
var arrayBuffer = new ArrayBuffer(myMAX);
var thatSer = new xml.XmlSerializer(arrayBuffer);
thatSer.startElement("note1");
thatSer.startElement("note2");
thatSer.startElement("note3");
thatSer.endElement();
thatSer.endElement();
thatSer.endElement();
var result =
"<note1>\r\n <note2>\r\n <note3/>\r\n </note2>\r\n</note1>";
var view = new Uint8Array(arrayBuffer);
var view1 = "";
for (var i = 0; i < result.length; ++i) {
view1 = view1 + String.fromCodePoint(view[i]);
}
expect(view1).assertEqual(result);
});
/**
* @tc.number: TEST_START_ELEMENT_005
* @tc.name : testStartElement005
* @tc.desc : Writes an elemnet start tag with the given name.
* @tc.size : MediumTest
* @tc.type : Method
* @tc.level : Level 2
*/
it("testStartElement005", 0, function () {
const myMAX = 2048;
var arrayBuffer = new ArrayBuffer(myMAX);
var thatSer = new xml.XmlSerializer(arrayBuffer);
thatSer.startElement("note1");
thatSer.startElement("note2");
thatSer.endElement();
thatSer.startElement("note3");
thatSer.endElement();
thatSer.endElement();
var result = "<note1>\r\n <note2/>\r\n <note3/>\r\n</note1>";
var view = new Uint8Array(arrayBuffer);
var view1 = "";
for (var i = 0; i < result.length; ++i) {
view1 = view1 + String.fromCodePoint(view[i]);
}
expect(view1).assertEqual(result);
});
/**
* @tc.number: TEST_END_ELEMENT_001
* @tc.name : testEndElement001
* @tc.desc : Writes end tag of the element.
* @tc.size : MediumTest
* @tc.type : Method
* @tc.level : Level 2
*/
it("testEndElement001", 0, function () {
const myMAX = 2048;
var arrayBuffer = new ArrayBuffer(myMAX);
var thatSer = new xml.XmlSerializer(arrayBuffer);
thatSer.startElement("note");
thatSer.endElement();
var result = "<note/>";
var view = new Uint8Array(arrayBuffer);
var view1 = "";
for (var i = 0; i < result.length; ++i) {
view1 = view1 + String.fromCodePoint(view[i]);
}
expect(view1).assertEqual(result);
});
/**
* @tc.number: TEST_END_ELEMENT_002
* @tc.name : testEndElement002
* @tc.desc : Writes end tag of the element.
* @tc.size : MediumTest
* @tc.type : Method
* @tc.level : Level 2
*/
it("testEndElement002", 0, function () {
const myMAX = 2048;
var arrayBuffer = new ArrayBuffer(myMAX);
var thatSer = new xml.XmlSerializer(arrayBuffer);
thatSer.startElement("note");
thatSer.setAttributes("importance", "high");
thatSer.endElement();
var result = '<note importance="high"/>';
var view = new Uint8Array(arrayBuffer);
var view1 = "";
for (var i = 0; i < result.length; ++i) {
view1 = view1 + String.fromCodePoint(view[i]);
}
expect(view1).assertEqual(result);
});
/**
* @tc.number: TEST_END_ELEMENT_003
* @tc.name : testEndElement003
* @tc.desc : Writes end tag of the element.
* @tc.size : MediumTest
* @tc.type : Method
* @tc.level : Level 2
*/
it("testEndElement003", 0, function () {
const myMAX = 2048;
var arrayBuffer = new ArrayBuffer(myMAX);
var thatSer = new xml.XmlSerializer(arrayBuffer);
thatSer.startElement("note");
thatSer.setAttributes("impo", "hi");
thatSer.endElement();
var result = '<note impo="hi"/>';
var view = new Uint8Array(arrayBuffer);
var view1 = "";
for (var i = 0; i < result.length; ++i) {
view1 = view1 + String.fromCodePoint(view[i]);
}
expect(view1).assertEqual(result);
});
/**
* @tc.number: TEST_END_ELEMENT_004
* @tc.name : testEndElement004
* @tc.desc : Writes end tag of the element.
* @tc.size : MediumTest
* @tc.type : Method
* @tc.level : Level 2
*/
it("testEndElement004", 0, function () {
const myMAX = 2048;
var arrayBuffer = new ArrayBuffer(myMAX);
var thatSer = new xml.XmlSerializer(arrayBuffer);
thatSer.startElement("note1");
thatSer.startElement("note2");
thatSer.endElement();
thatSer.endElement();
var result = "<note1>\r\n <note2/>\r\n</note1>";
var view = new Uint8Array(arrayBuffer);
var view1 = "";
for (var i = 0; i < result.length; ++i) {
view1 = view1 + String.fromCodePoint(view[i]);
}
expect(view1).assertEqual(result);
});
/**
* @tc.number: TEST_END_ELEMENT_005
* @tc.name : testEndElement005
* @tc.desc : Writes end tag of the element.
* @tc.size : MediumTest
* @tc.type : Method
* @tc.level : Level 2
*/
it("testEndElement005", 0, function () {
const myMAX = 2048;
var arrayBuffer = new ArrayBuffer(myMAX);
var thatSer = new xml.XmlSerializer(arrayBuffer);
thatSer.startElement("note2");
thatSer.setAttributes("importance", "high");
thatSer.endElement();
var result = '<note2 importance="high"/>';
var view = new Uint8Array(arrayBuffer);
var view1 = "";
for (var i = 0; i < result.length; ++i) {
view1 = view1 + String.fromCodePoint(view[i]);
}
expect(view1).assertEqual(result);
});
/**
* @tc.number: TEST_SET_NAMESPECE_001
* @tc.name : testSetNamespace001
* @tc.desc : Writes the namespace of the current element tag.
* @tc.size : MediumTest
* @tc.type : Method
* @tc.level : Level 2
*/
it("testSetNamespace001", 0, function () {
const myMAX = 2048;
var arrayBuffer = new ArrayBuffer(myMAX);
var thatSer = new xml.XmlSerializer(arrayBuffer);
thatSer.setDeclaration();
thatSer.setNamespace("h", "http://www.w3.org/TR/html4/");
thatSer.startElement("note");
thatSer.endElement();
var result =
'<?xml version="1.0" encoding="utf-8"?>\r\n<h:note xmlns:h="http://www.w3.org/TR/html4/"/>';
var view = new Uint8Array(arrayBuffer);
var view1 = "";
for (var i = 0; i < result.length; ++i) {
view1 = view1 + String.fromCodePoint(view[i]);
}
expect(view1).assertEqual(result);
});
/**
* @tc.number: TEST_SET_NAMESPECE_002
* @tc.name : testSetNamespace002
* @tc.desc : Writes the namespace of the current element tag.
* @tc.size : MediumTest
* @tc.type : Method
* @tc.level : Level 2
*/
it("testSetNamespace002", 0, function () {
const myMAX = 2048;
var arrayBuffer = new ArrayBuffer(myMAX);
var thatSer = new xml.XmlSerializer(arrayBuffer);
thatSer.setDeclaration();
thatSer.setNamespace("b", "http://www.w3.org/TR/html4/");
thatSer.startElement("note");
thatSer.endElement();
var result =
'<?xml version="1.0" encoding="utf-8"?>\r\n<b:note xmlns:b="http://www.w3.org/TR/html4/"/>';
var view = new Uint8Array(arrayBuffer);
var view1 = "";
for (var i = 0; i < result.length; ++i) {
view1 = view1 + String.fromCodePoint(view[i]);
}
expect(view1).assertEqual(result);
});
/**
* @tc.number: TEST_SET_NAMESPECE_003
* @tc.name : testSetNamespace003
* @tc.desc : Writes the namespace of the current element tag.
* @tc.size : MediumTest
* @tc.type : Method
* @tc.level : Level 2
*/
it("testSetNamespace003", 0, function () {
const myMAX = 2048;
var arrayBuffer = new ArrayBuffer(myMAX);
var thatSer = new xml.XmlSerializer(arrayBuffer);
thatSer.setDeclaration();
thatSer.setNamespace("h", "http://www.111/");
thatSer.startElement("note");
thatSer.endElement();
var result =
'<?xml version="1.0" encoding="utf-8"?>\r\n<h:note xmlns:h="http://www.111/"/>';
var view = new Uint8Array(arrayBuffer);
var view1 = "";
for (var i = 0; i < result.length; ++i) {
view1 = view1 + String.fromCodePoint(view[i]);
}
expect(view1).assertEqual(result);
});
/**
* @tc.number: TEST_SET_NAMESPECE_004
* @tc.name : testSetNamespace004
* @tc.desc : Writes the namespace of the current element tag.
* @tc.size : MediumTest
* @tc.type : Method
* @tc.level : Level 2
*/
it("testSetNamespace004", 0, function () {
const myMAX = 2048;
var arrayBuffer = new ArrayBuffer(myMAX);
var thatSer = new xml.XmlSerializer(arrayBuffer);
thatSer.setDeclaration();
thatSer.setNamespace("h", "http://www.w3.org/TR/html4/");
thatSer.startElement("note1");
thatSer.startElement("note2");
thatSer.endElement();
thatSer.endElement();
var result =
'<?xml version="1.0" encoding="utf-8"?>\r\n<h:note1 xmlns:h="http://www.w3.org/TR/html4/">' +
"\r\n <h:note2/>\r\n</h:note1>";
var view = new Uint8Array(arrayBuffer);
var view1 = "";
for (var i = 0; i < result.length; ++i) {
view1 = view1 + String.fromCodePoint(view[i]);
}
expect(view1).assertEqual(result);
});
/**
* @tc.number: TEST_SET_COMMENT_001
* @tc.name : testSetComment001
* @tc.desc : Writes the comment.
* @tc.size : MediumTest
* @tc.type : Method
* @tc.level : Level 2
*/
it("testSetComment001", 0, function () {
const myMAX = 2048;
var arrayBuffer = new ArrayBuffer(myMAX);
var thatSer = new xml.XmlSerializer(arrayBuffer);
thatSer.startElement("note");
thatSer.setComment("Hi!");
thatSer.endElement();
var result = "<note>\r\n <!--Hi!-->\r\n</note>";
var view = new Uint8Array(arrayBuffer);
var view1 = "";
for (var i = 0; i < result.length; ++i) {
view1 = view1 + String.fromCodePoint(view[i]);
}
expect(view1).assertEqual(result);
});
/**
* @tc.number: TEST_SET_COMMENT_002
* @tc.name : testSetComment002
* @tc.desc : Writes the comment.
* @tc.size : MediumTest
* @tc.type : Method
* @tc.level : Level 2
*/
it("testSetComment002", 0, function () {
const myMAX = 2048;
var arrayBuffer = new ArrayBuffer(myMAX);
var thatSer = new xml.XmlSerializer(arrayBuffer);
thatSer.startElement("note");
thatSer.setComment("Hello, World!");
thatSer.endElement();
var result = "<note>\r\n <!--Hello, World!-->\r\n</note>";
var view = new Uint8Array(arrayBuffer);
var view1 = "";
for (var i = 0; i < result.length; ++i) {
view1 = view1 + String.fromCodePoint(view[i]);
}
expect(view1).assertEqual(result);
});
/**
* @tc.number: TEST_SET_COMMENT_003
* @tc.name : testSetComment003
* @tc.desc : Writes the comment.
* @tc.size : MediumTest
* @tc.type : Method
* @tc.level : Level 2
*/
it("testSetComment003", 0, function () {
const myMAX = 2048;
var arrayBuffer = new ArrayBuffer(myMAX);
var thatSer = new xml.XmlSerializer(arrayBuffer);
thatSer.setComment("Hello, World!");
var result = "<!--Hello, World!-->";
var view = new Uint8Array(arrayBuffer);
var view1 = "";
for (var i = 0; i < result.length; ++i) {
view1 = view1 + String.fromCodePoint(view[i]);
}
expect(view1).assertEqual(result);
});
/**
* @tc.number: TEST_SET_COMMENT_005
* @tc.name : testSetComment005
* @tc.desc : Writes the comment.
* @tc.size : MediumTest
* @tc.type : Method
* @tc.level : Level 2
*/
it("testSetComment004", 0, function () {
const myMAX = 2048;
var arrayBuffer = new ArrayBuffer(myMAX);
var thatSer = new xml.XmlSerializer(arrayBuffer);
thatSer.setComment("Hello, World!");
thatSer.startElement("note");
thatSer.endElement();
var result = "<!--Hello, World!-->\r\n<note/>";
var view = new Uint8Array(arrayBuffer);
var view1 = "";
for (var i = 0; i < result.length; ++i) {
view1 = view1 + String.fromCodePoint(view[i]);
}
expect(view1).assertEqual(result);
});
/**
* @tc.number: TEST_SET_CDATA_001
* @tc.name : testSetCDATA001
* @tc.desc : Writes the CDATA.
* @tc.size : MediumTest
* @tc.type : Method
* @tc.level : Level 2
*/
it("testSetCDATA001", 0, function () {
const myMAX = 2048;
var arrayBuffer = new ArrayBuffer(myMAX);
var thatSer = new xml.XmlSerializer(arrayBuffer);
thatSer.setCDATA("root SYSTEM");
var result = "<![CDATA[root SYSTEM]]>";
var view = new Uint8Array(arrayBuffer);
var view1 = "";
for (var i = 0; i < result.length; ++i) {
view1 = view1 + String.fromCodePoint(view[i]);
}
expect(view1).assertEqual(result);
});
/**
* @tc.number: TEST_SET_CDATA_002
* @tc.name : testSetCDATA002
* @tc.desc : Writes the CDATA.
* @tc.size : MediumTest
* @tc.type : Method
* @tc.level : Level 2
*/
it("testSetCDATA002", 0, function () {
const myMAX = 2048;
var arrayBuffer = new ArrayBuffer(myMAX);
var thatSer = new xml.XmlSerializer(arrayBuffer);
thatSer.setCDATA('root SYSTEM "http://www.test.org/test.dtd"');
var result = '<![CDATA[root SYSTEM "http://www.test.org/test.dtd"]]>';
var view = new Uint8Array(arrayBuffer);
var view1 = "";
for (var i = 0; i < result.length; ++i) {
view1 = view1 + String.fromCodePoint(view[i]);
}
expect(view1).assertEqual(result);
});
/**
* @tc.number: TEST_SET_CDATA_003
* @tc.name : testSetCDATA003
* @tc.desc : Writes the CDATA.
* @tc.size : MediumTest
* @tc.type : Method
* @tc.level : Level 2
*/
it("testSetCDATA003", 0, function () {
const myMAX = 2048;
var arrayBuffer = new ArrayBuffer(myMAX);
var thatSer = new xml.XmlSerializer(arrayBuffer);
thatSer.startElement("note");
thatSer.endElement();
thatSer.setCDATA('root SYSTEM "http://www.test.org/test.dtd"');
var result =
'<note/>\r\n<![CDATA[root SYSTEM "http://www.test.org/test.dtd"]]>';
var view = new Uint8Array(arrayBuffer);
var view1 = "";
for (var i = 0; i < result.length; ++i) {
view1 = view1 + String.fromCodePoint(view[i]);
}
expect(view1).assertEqual(result);
});
/**
* @tc.number: TEST_SET_CDATA_004
* @tc.name : testSetCDATA004
* @tc.desc : Writes the CDATA.
* @tc.size : MediumTest
* @tc.type : Method
* @tc.level : Level 2
*/
it("testSetCDATA004", 0, function () {
const myMAX = 2048;
var arrayBuffer = new ArrayBuffer(myMAX);
var thatSer = new xml.XmlSerializer(arrayBuffer);
thatSer.setCDATA('root SYSTEM "http://www.test.org/test.dtd"');
thatSer.startElement("note");
thatSer.endElement();
var result =
'<![CDATA[root SYSTEM "http://www.test.org/test.dtd"]]>\r\n<note/>';
var view = new Uint8Array(arrayBuffer);
var view1 = "";
for (var i = 0; i < result.length; ++i) {
view1 = view1 + String.fromCodePoint(view[i]);
}
expect(view1).assertEqual(result);
});
/**
* @tc.number: TEST_SET_CDATA_005
* @tc.name : testSetCDATA005
* @tc.desc : Writes the CDATA.
* @tc.size : MediumTest
* @tc.type : Method
* @tc.level : Level 2
*/
it("testSetCDATA005", 0, function () {
const myMAX = 2048;
var arrayBuffer = new ArrayBuffer(myMAX);
var thatSer = new xml.XmlSerializer(arrayBuffer);
thatSer.startElement("note");
thatSer.setCDATA('root SYSTEM "http://www.test.org/test.dtd"');
thatSer.endElement();
var result =
'<note>\r\n <![CDATA[root SYSTEM "http://www.test.org/test.dtd"]]>\r\n</note>';
var view = new Uint8Array(arrayBuffer);
var view1 = "";
for (var i = 0; i < result.length; ++i) {
view1 = view1 + String.fromCodePoint(view[i]);
}
expect(view1).assertEqual(result);
});
/**
* @tc.number: TEST_SET_TEXT_001
* @tc.name : testSetText001
* @tc.desc : Writes the CDATA.
* @tc.size : MediumTest
* @tc.type : Method
* @tc.level : Level 2
*/
it("testSetText001", 0, function () {
const myMAX = 2048;
var arrayBuffer = new ArrayBuffer(myMAX);
var thatSer = new xml.XmlSerializer(arrayBuffer);
thatSer.startElement("note");
thatSer.setAttributes("importance", "high");
thatSer.setText("Happy1");
thatSer.endElement();
var result = '<note importance="high">Happy1</note>';
var view = new Uint8Array(arrayBuffer);
var view1 = "";
for (var i = 0; i < result.length; ++i) {
view1 = view1 + String.fromCodePoint(view[i]);
}
expect(view1).assertEqual(result);
});
/**
* @tc.number: TEST_SET_TEXT_002
* @tc.name : testSetText002
* @tc.desc : Writes the CDATA.
* @tc.size : MediumTest
* @tc.type : Method
* @tc.level : Level 2
*/
it("testSetText002", 0, function () {
const myMAX = 2048;
var arrayBuffer = new ArrayBuffer(myMAX);
var thatSer = new xml.XmlSerializer(arrayBuffer);
thatSer.startElement("note");
thatSer.setAttributes("importance", "high");
thatSer.setText("Happy2");
thatSer.endElement();
var result = '<note importance="high">Happy2</note>';
var view = new Uint8Array(arrayBuffer);
var view1 = "";
for (var i = 0; i < result.length; ++i) {
view1 = view1 + String.fromCodePoint(view[i]);
}
expect(view1).assertEqual(result);
});
/**
* @tc.number: TEST_SET_DOC_TYPE_001
* @tc.name : testSetDocType001
* @tc.desc : Writes the DOCTYPE.
* @tc.size : MediumTest
* @tc.type : Method
* @tc.level : Level 2
*/
it("testSetDocType001", 0, function () {
const myMAX = 2048;
var arrayBuffer = new ArrayBuffer(myMAX);
var thatSer = new xml.XmlSerializer(arrayBuffer);
thatSer.setDocType("root SYSTEM");
var result = "<!DOCTYPE root SYSTEM>";
var view = new Uint8Array(arrayBuffer);
var view1 = "";
for (var i = 0; i < result.length; ++i) {
view1 = view1 + String.fromCodePoint(view[i]);
}
expect(view1).assertEqual(result);
});
/**
* @tc.number: TEST_SET_DOC_TYPE_002
* @tc.name : testSetDocType002
* @tc.desc : Writes the DOCTYPE.
* @tc.size : MediumTest
* @tc.type : Method
* @tc.level : Level 2
*/
it("testSetDocType002", 0, function () {
const myMAX = 2048;
var arrayBuffer = new ArrayBuffer(myMAX);
var thatSer = new xml.XmlSerializer(arrayBuffer);
thatSer.setDocType('root SYSTEM "http://www.test.org/test.dtd"');
var result = '<!DOCTYPE root SYSTEM "http://www.test.org/test.dtd">';
var view = new Uint8Array(arrayBuffer);
var view1 = "";
for (var i = 0; i < result.length; ++i) {
view1 = view1 + String.fromCodePoint(view[i]);
}
expect(view1).assertEqual(result);
});
/**
* @tc.number: TEST_SET_DOC_TYPE_003
* @tc.name : testSetDocType003
* @tc.desc : Writes the DOCTYPE.
* @tc.size : MediumTest
* @tc.type : Method
* @tc.level : Level 2
*/
it("testSetDocType003", 0, function () {
const myMAX = 2048;
var arrayBuffer = new ArrayBuffer(myMAX);
var thatSer = new xml.XmlSerializer(arrayBuffer);
thatSer.startElement("note");
thatSer.endElement();
thatSer.setDocType('root SYSTEM "http://www.test.org/test.dtd"');
var result =
'<note/>\r\n<!DOCTYPE root SYSTEM "http://www.test.org/test.dtd">';
var view = new Uint8Array(arrayBuffer);
var view1 = "";
for (var i = 0; i < result.length; ++i) {
view1 = view1 + String.fromCodePoint(view[i]);
}
expect(view1).assertEqual(result);
});
/**
* @tc.number: TEST_SET_DOC_TYPE_004
* @tc.name : testSetDocType004
* @tc.desc : Writes the DOCTYPE.
* @tc.size : MediumTest
* @tc.type : Method
* @tc.level : Level 2
*/
it("testSetDocType004", 0, function () {
const myMAX = 2048;
var arrayBuffer = new ArrayBuffer(myMAX);
var thatSer = new xml.XmlSerializer(arrayBuffer);
thatSer.setDocType('root SYSTEM "http://www.test.org/test.dtd"');
thatSer.startElement("note");
thatSer.endElement();
var result =
'<!DOCTYPE root SYSTEM "http://www.test.org/test.dtd">\r\n<note/>';
var view = new Uint8Array(arrayBuffer);
var view1 = "";
for (var i = 0; i < result.length; ++i) {
view1 = view1 + String.fromCodePoint(view[i]);
}
expect(view1).assertEqual(result);
});
/**
* @tc.number: TEST_SET_DOC_TYPE_005
* @tc.name : testSetDocType005
* @tc.desc : Writes the DOCTYPE.
* @tc.size : MediumTest
* @tc.type : Method
* @tc.level : Level 2
*/
it("testSetDocType005", 0, function () {
const myMAX = 2048;
var arrayBuffer = new ArrayBuffer(myMAX);
var thatSer = new xml.XmlSerializer(arrayBuffer);
thatSer.startElement("note");
thatSer.setDocType('root SYSTEM "http://www.test.org/test.dtd"');
thatSer.endElement();
var result =
'<note>\r\n <!DOCTYPE root SYSTEM "http://www.test.org/test.dtd">\r\n</note>';
var view = new Uint8Array(arrayBuffer);
var view1 = "";
for (var i = 0; i < result.length; ++i) {
view1 = view1 + String.fromCodePoint(view[i]);
}
expect(view1).assertEqual(result);
});
/**
* @tc.number: TEST_GET_COLUMN_NUMBER_001
* @tc.name : testGetColumnNumber001
* @tc.desc : Get the current column number, starting from 1.
* @tc.size : MediumTest
* @tc.type : Method
* @tc.level : Level 2
*/
it("testGetColumnNumber001", 0, function () {
let strXml =
'<?xml version="1.0" encoding="utf-8"?>' +
'<note importance="high" logged="true">' +
" <title>Happy</title>" +
"</note>";
let textEncoder = new util.TextEncoder();
let arrbuffer = textEncoder.encodeInto(strXml);
let that = new xml.XmlPullParser(arrbuffer.buffer);
let arrTag = {};
let str = "";
let i = 0;
function func(key, value) {
arrTag[i] = "key:" + key + " value:" + value.getColumnNumber();
str += arrTag[i];
i++;
return true;
}
let options = {
supportDoctype: true,
ignoreNameSpace: true,
tokenValueCallbackFunction: func,
};
that.parse(options);
const expectResult =
"key:0 value:1key:2 value:77key:10 value:81key:2 value:88key:4 value:93key:3 value:101" +
"key:3 value:108key:1 value:215";
expect(expectResult == str).assertTrue();
});
/**
* @tc.number: TEST_GET_DEPTH_001
* @tc.name : testGetDepth001
* @tc.desc : Gets the current depth of the element.
* @tc.size : MediumTest
* @tc.type : Method
* @tc.level : Level 2
*/
it("testGetDepth001", 0, function () {
let strXml =
'<?xml version="1.0" encoding="utf-8"?>' +
'<note importance="high" logged="true">' +
" <title>Happy</title>" +
"</note>";
let textEncoder = new util.TextEncoder();
let arrbuffer = textEncoder.encodeInto(strXml);
let that = new xml.XmlPullParser(arrbuffer.buffer);
let arrTag = {};
let str = "";
let i = 0;
function func(key, value) {
arrTag[i] = "key:" + key + " value:" + value.getDepth();
str += arrTag[i];
i++;
return true;
}
let options = {
supportDoctype: true,
ignoreNameSpace: true,
tokenValueCallbackFunction: func,
};
that.parse(options);
const expectResult =
"key:0 value:0key:2 value:1key:10 value:1key:2 value:2key:4 value:2key:3 value:2key:3 value:1key:1 value:0";
expect(expectResult == str).assertTrue();
});
/**
* @tc.number: TEST_GET_LINE_NUMBER_001
* @tc.name : testGetLineNumber001
* @tc.desc : Get the current line number, starting from 1.
* @tc.size : MediumTest
* @tc.type : Method
* @tc.level : Level 2
*/
it("testGetLineNumber001", 0, function () {
let strXml =
'<?xml version="1.0" encoding="utf-8"?>' +
'<note importance="high" logged="true">' +
" <title>Happy</title>" +
"</note>";
let textEncoder = new util.TextEncoder();
let arrbuffer = textEncoder.encodeInto(strXml);
let that = new xml.XmlPullParser(arrbuffer.buffer);
let arrTag = {};
let str = "";
let i = 0;
function func(key, value) {
arrTag[i] = "key:" + key + " value:" + value.getLineNumber();
str += arrTag[i];
i++;
return true;
}
let options = {
supportDoctype: true,
ignoreNameSpace: true,
tokenValueCallbackFunction: func,
};
that.parse(options);
const expectResult =
"key:0 value:1key:2 value:1key:10 value:1key:2 value:1key:4 value:1key:3 value:1key:3 value:1key:1 value:1";
expect(expectResult == str).assertTrue();
});
/**
* @tc.number: TEST_GET_NAME_001
* @tc.name : testGetName001
* @tc.desc : Gets the current element name.
* @tc.size : MediumTest
* @tc.type : Method
* @tc.level : Level 2
*/
it("testGetName001", 0, function () {
let strXml =
'<?xml version="1.0" encoding="utf-8"?>' +
'<note importance="high" logged="true">' +
" <title>Happy</title>" +
"</note>";
let textEncoder = new util.TextEncoder();
let arrbuffer = textEncoder.encodeInto(strXml);
let that = new xml.XmlPullParser(arrbuffer.buffer);
let arrTag = {};
let str = "";
let i = 0;
function func(key, value) {
arrTag[i] = "key:" + key + " value:" + value.getName();
str += arrTag[i];
i++;
return true;
}
let options = {
supportDoctype: true,
ignoreNameSpace: true,
tokenValueCallbackFunction: func,
};
that.parse(options);
const expectResult =
"key:0 value:key:2 value:notekey:10 value:key:2 value:titlekey:4 value:key:3 value:titlekey:3 value:notekey:1 value:";
expect(expectResult == str).assertTrue();
});
/**
* @tc.number: TEST_GET_NAME_SPACE_001
* @tc.name : testGetNamespace001
* @tc.desc : Gets the namespace of the current element.
* @tc.size : MediumTest
* @tc.type : Method
* @tc.level : Level 2
*/
it("testGetNamespace001", 0, function () {
let strXml =
'<?xml version="1.0" encoding="utf-8"?>' +
'<note importance="high" logged="true">' +
" <title>Happy</title>" +
"</note>";
let textEncoder = new util.TextEncoder();
let arrbuffer = textEncoder.encodeInto(strXml);
let that = new xml.XmlPullParser(arrbuffer.buffer);
let arrTag = {};
let str = "";
let i = 0;
function func(key, value) {
arrTag[i] = "key:" + key + " value:" + value.getNamespace();
str += arrTag[i];
i++;
return true;
}
let options = {
supportDoctype: true,
ignoreNameSpace: true,
tokenValueCallbackFunction: func,
};
that.parse(options);
const expectResult =
"key:0 value:key:2 value:key:10 value:key:2 value:key:4 value:key:3 value:key:3 value:key:1 value:";
expect(expectResult == str).assertTrue();
});
/**
* @tc.number: TEST_GET_PREFIX_001
* @tc.name : testGetPrefix001
* @tc.desc : Gets the namespace of the current element.
* @tc.size : MediumTest
* @tc.type : Method
* @tc.level : Level 2
*/
it("testGetPrefix001", 0, function () {
let strXml =
'<?xml version="1.0" encoding="utf-8"?>' +
'<note importance="high" logged="true">' +
" <title>Happy</title>" +
"</note>";
let textEncoder = new util.TextEncoder();
let arrbuffer = textEncoder.encodeInto(strXml);
let that = new xml.XmlPullParser(arrbuffer.buffer);
let arrTag = {};
let str = "";
let i = 0;
function func(key, value) {
arrTag[i] = "key:" + key + " value:" + value.getPrefix();
str += arrTag[i];
i++;
return true;
}
let options = {
supportDoctype: true,
ignoreNameSpace: true,
tokenValueCallbackFunction: func,
};
that.parse(options);
const expectResult =
"key:0 value:key:2 value:key:10 value:key:2 value:key:4 value:key:3 value:key:3 value:key:1 value:";
expect(expectResult == str).assertTrue();
});
/**
* @tc.number: TEST_GET_TEXT_001
* @tc.name : testGetText001
* @tc.desc : Gets the text content of the current event.
* @tc.size : MediumTest
* @tc.type : Method
* @tc.level : Level 2
*/
it("testGetText001", 0, function () {
let strXml =
'<?xml version="1.0" encoding="utf-8"?>' +
'<note importance="high" logged="true">' +
" <title>Happy</title>" +
"</note>";
let textEncoder = new util.TextEncoder();
let arrbuffer = textEncoder.encodeInto(strXml);
let that = new xml.XmlPullParser(arrbuffer.buffer);
let arrTag = {};
let str = "";
let i = 0;
function func(key, value) {
arrTag[i] = "key:" + key + " value:" + value.getText();
str += arrTag[i];
i++;
return true;
}
let options = {
supportDoctype: true,
ignoreNameSpace: true,
tokenValueCallbackFunction: func,
};
that.parse(options);
const expectResult =
"key:0 value:key:2 value:key:10 value: key:2 value:key:4 value:Happykey:3 value:key:3 value:key:1 value:";
expect(expectResult == str).assertTrue();
});
/**
* @tc.number: TEST_IS_EMPTY_ELEMENT_001
* @tc.name : testIsEmptyElementTag001
* @tc.desc : Determine whether the current element is an empty element.
* @tc.size : MediumTest
* @tc.type : Method
* @tc.level : Level 2
*/
it("testIsEmptyElementTag001", 0, function () {
let strXml =
'<?xml version="1.0" encoding="utf-8"?>' +
'<note importance="high" logged="true">' +
" <title>Happy</title>" +
"</note>";
let textEncoder = new util.TextEncoder();
let arrbuffer = textEncoder.encodeInto(strXml);
let that = new xml.XmlPullParser(arrbuffer.buffer);
let arrTag = {};
let str = "";
let i = 0;
function func(key, value) {
arrTag[i] = "key:" + key + " value:" + value.isEmptyElementTag();
str += arrTag[i];
i++;
return true;
}
let options = {
supportDoctype: true,
ignoreNameSpace: true,
tokenValueCallbackFunction: func,
};
that.parse(options);
const expectResult =
"key:0 value:falsekey:2 value:falsekey:10 value:falsekey:2 value:falsekey:4 value:falsekey:3 value:falsekey:3 value:falsekey:1 value:false";
expect(expectResult == str).assertTrue();
});
/**
* @tc.number: TEST_IS_WHITE_SPACE_001
* @tc.name : testIsWhitespace001
* @tc.desc : Determine whether the current element is an empty element.
* @tc.size : MediumTest
* @tc.type : Method
* @tc.level : Level 2
*/
it("testIsWhitespace001", 0, function () {
let strXml =
'<?xml version="1.0" encoding="utf-8"?>' +
'<note importance="high" logged="true">' +
" <title>Happy</title>" +
"</note>";
let textEncoder = new util.TextEncoder();
let arrbuffer = textEncoder.encodeInto(strXml);
let that = new xml.XmlPullParser(arrbuffer.buffer);
let arrTag = {};
let str = "";
let i = 0;
function func(key, value) {
arrTag[i] = "key:" + key + " value:" + value.isWhitespace();
str += arrTag[i];
i++;
return true;
}
let options = {
supportDoctype: true,
ignoreNameSpace: true,
tokenValueCallbackFunction: func,
};
that.parse(options);
const expectResult =
"key:0 value:truekey:2 value:falsekey:10 value:truekey:2 value:truekey:4 value:falsekey:3 value:truekey:3 value:truekey:1 value:true";
expect(expectResult == str).assertTrue();
});
/**
* @tc.number: TEST_GET_ATTRIBUTE_COUNT_001
* @tc.name : testGetAttributeCount001
* @tc.desc : Gets the number of attributes for the current start tag.
* @tc.size : MediumTest
* @tc.type : Method
* @tc.level : Level 2
*/
it("testGetAttributeCount001", 0, function () {
let strXml =
'<?xml version="1.0" encoding="utf-8"?>' +
'<note importance="high" logged="true">' +
" <title>Happy</title>" +
"</note>";
let textEncoder = new util.TextEncoder();
let arrbuffer = textEncoder.encodeInto(strXml);
let that = new xml.XmlPullParser(arrbuffer.buffer);
let arrTag = {};
let str = "";
let i = 0;
function func(key, value) {
arrTag[i] = "key:" + key + " value:" + value.getAttributeCount();
str += arrTag[i];
i++;
return true;
}
let options = {
supportDoctype: true,
ignoreNameSpace: true,
tokenValueCallbackFunction: func,
};
that.parse(options);
const expectResult =
"key:0 value:0key:2 value:2key:10 value:0key:2 value:0key:4 value:0key:3 value:0key:3 value:0key:1 value:0";
expect(expectResult == str).assertTrue();
});
/**
* @tc.number: TEST_CONSTRUCTOR_001
* @tc.name : testConstructor001
* @tc.desc : Construct and return an XmlPullParser object.
* @tc.size : MediumTest
* @tc.type : Method
* @tc.level : Level 2
*/
it("testConstructor001", 0, function () {
let 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>" +
"</note>";
let textEncoder = new util.TextEncoder();
let arrbuffer = textEncoder.encodeInto(strXml);
let that = new xml.XmlPullParser(arrbuffer.buffer, "UTF-8");
let str = "";
function func1(name, value) {
str += name + ":" + value;
return true;
}
let options = {
supportDoctype: true,
ignoreNameSpace: true,
tagValueCallbackFunction: func1,
};
that.parse(options);
const expectResult =
':: note [<!ENTITY foo "baa">]note:: :funcrion matchwo(a,6){return 1;}: :Hello, World!: company::John amp;:amp;: Hanscompany:: title::Happytitle:note::';
expect(expectResult == str).assertTrue();
});
/**
* @tc.number: TEST_PARSE_001
* @tc.name : testParse001
* @tc.desc : Starts parsing the XML file.
* @tc.size : MediumTest
* @tc.type : Method
* @tc.level : Level 2
*/
it("testParse001", 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_002
* @tc.name : testParse002
* @tc.desc : Starts parsing the XML file.
* @tc.size : MediumTest
* @tc.type : Method
* @tc.level : Level 2
*/
it("testParse002", 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_003
* @tc.name : testParse003
* @tc.desc : Starts parsing the XML file.
* @tc.size : MediumTest
* @tc.type : Method
* @tc.level : Level 2
*/
it("testParse003", 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);
});
/**
* @tc.number: TEST_PARSE_004
* @tc.name : testParse004
* @tc.desc : Starts parsing the XML file.
* @tc.size : MediumTest
* @tc.type : Method
* @tc.level : Level 2
*/
it("testParse004", 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.getDepth() + " ";
return true;
}
let options = {
supportDoctype: true,
ignoreNameSpace: true,
tokenValueCallbackFunction: func,
};
that.parse(options);
let result =
"key:0 value:0 key:2 value:1 key:10 value:1 key:2 value:2 key:4 value:2 key:3 value:2 " +
"key:10 value:1 key:2 value:2 key:4 value:2 key:3 value:2 key:10 value:1 key:2 value:2 " +
"key:4 value:2 key:3 value:2 key:3 value:1 key:1 value:0 ";
expect(str).assertEqual(result);
});
/**
* @tc.number: TEST_PARSE_005
* @tc.name : testParse005
* @tc.desc : Starts parsing the XML file.
* @tc.size : MediumTest
* @tc.type : Method
* @tc.level : Level 2
*/
it("testParse005", 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.getLineNumber() + " ";
return true;
}
let options = {
supportDoctype: true,
ignoreNameSpace: true,
tokenValueCallbackFunction: func,
};
that.parse(options);
let result =
"key:0 value:1 key:2 value:1 key:10 value:1 key:2 value:1 key:4 value:1 key:3 value:1 " +
"key:10 value:1 key:2 value:1 key:4 value:1 key:3 value:1 key:10 value:1 key:2 value:1 " +
"key:4 value:1 key:3 value:1 key:3 value:1 key:1 value:1 ";
expect(str).assertEqual(result);
});
});
}
/*
* 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 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) 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 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.
先完成此消息的编辑!
想要评论请 注册