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

!8743 The issue of modifying XML test cases failed

Merge pull request !8743 from bihu/OpenHarmony-3.2-Release
...@@ -14,6 +14,7 @@ ...@@ -14,6 +14,7 @@
*/ */
import {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from '@ohos/hypium' import {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from '@ohos/hypium'
import xml from '@ohos.xml' import xml from '@ohos.xml'
import util from '@ohos.util'
export default function XmlSerializerXmlPullParserTest() { export default function XmlSerializerXmlPullParserTest() {
describe('XmlSerializerXmlPullParserTest', function () { describe('XmlSerializerXmlPullParserTest', function () {
...@@ -1046,46 +1047,17 @@ describe('XmlSerializerXmlPullParserTest', function () { ...@@ -1046,46 +1047,17 @@ describe('XmlSerializerXmlPullParserTest', function () {
' </h:tr>' + ' </h:tr>' +
' </h:table>' + ' </h:table>' +
'</note>'; '</note>';
var arrayBuffer = new ArrayBuffer(strXml.length); let textEncoder = new util.TextEncoder();
var bufView = new Uint8Array(arrayBuffer); let arrbuffer = textEncoder.encodeInto(strXml);
var strLen = strXml.length; let that = new xml.XmlPullParser(arrbuffer.buffer, 'UTF-8');
for (var i = 0; i < strLen; ++i) { var str = '';
bufView[i] = strXml.charCodeAt(i); function func2(name, value){
} str += name+':'+value;
var that = new xml.XmlPullParser(arrayBuffer, 'UTF-8');
var arr = {};
var i = 0;
function func3(key, info){
arr[i] = 'key:' + JSON.stringify(key) + info.getDepth() + info.getColumnNumber() + info.getLineNumber() +
info.getAttributeCount() + info.getName() + info.getNamespace() + info.getPrefix() + info.getText() +
info.isEmptyElementTag()+ info.isWhitespace();
i++;
return true; return true;
} }
var options = {supportDoctype:true, ignoreNameSpace:false, tokenValueCallbackFunction:func3} var options = {supportDoctype:true, ignoreNameSpace:true, attributeValueCallbackFunction:func2}
that.parse(options); that.parse(options);
var str = ''; var str1= 'importance:highlogged:truexmlns:h:http://www.w3.org/TR/html4/';
for(var j = 0; j < i; ++j) {
str = str + arr[j];
}
var str1 = 'key:00110falsetruekey:702220 note [\n<!ENTITY foo "baa">]falsefalsekey:216022notefalsefalsekey:' +
'1016420 falsetruekey:51470\r\nfuncrion matchwo(a,6)\r\n{\r\nreturn 1;\r\n}\r\nfalsetruekey:101870 ' +
'falsetruekey:612870Hello, World!falsetruekey:1013270 falsetruekey:224170companyfalsetruekey:424670John ' +
'falsefalsekey:925170amp;amp;falsetruekey:425670 Hansfalsefalsekey:326670companyfalsetruekey:1017070 ' +
'falsetruekey:227770titlefalsetruekey:428270Happyfalsefalsekey:329070titlefalsetruekey:1019470 ' +
'falsetruekey:2210170titlefalsetruekey:4210670Happyfalsefalsekey:3211470titlefalsetruekey:10111870 ' +
'falsetruekey:2212470lensfalsetruekey:4212870Workfalsefalsekey:3213570lensfalsetruekey:10113970 ' +
'falsetruekey:2214570lensfalsetruekey:4214970Playfalsefalsekey:3215670lensfalsetruekey:10116070 ' +
'falsetruekey:8117270go therefalsetruekey:10117670 falsetruekey:2217970afalsetruekey:' +
'2318370btruetruekey:3318370bfalsetruekey:3218770afalsetruekey:10119170 falsetruekey:2223870table' +
'http://www.w3.org/TR/html4/hfalsefalsekey:10224670 ' +
'falsetruekey:2325270trhttp://www.w3.org/TR/html4/hfalsetruekey:10326470 ' +
'falsetruekey:2427070tdhttp://www.w3.org/TR/html4/hfalsetruekey:4427670Applesfalsefalsekey:3428370td' +
'http://www.w3.org/TR/html4/hfalsetruekey:10329570 ' +
'falsetruekey:2430170tdhttp://www.w3.org/TR/html4/hfalsetruekey:4430870Bananasfalsefalsekey:3431570td' +
'http://www.w3.org/TR/html4/hfalsetruekey:10332370 falsetruekey:3333070tr' +
'http://www.w3.org/TR/html4/hfalsetruekey:10233470 falsetruekey:3234470table' +
'http://www.w3.org/TR/html4/hfalsetruekey:3135170notefalsetruekey:10351130falsetrue';
expect(str).assertEqual(str1); expect(str).assertEqual(str1);
}) })
...@@ -1114,44 +1086,22 @@ describe('XmlSerializerXmlPullParserTest', function () { ...@@ -1114,44 +1086,22 @@ describe('XmlSerializerXmlPullParserTest', function () {
' </h:tr>' + ' </h:tr>' +
' </h:table>' + ' </h:table>' +
'</note>'; '</note>';
var arrayBuffer = new ArrayBuffer(strXml.length); let textEncoder = new util.TextEncoder();
var bufView = new Uint8Array(arrayBuffer); let arrbuffer = textEncoder.encodeInto(strXml);
var strLen = strXml.length; let that = new xml.XmlPullParser(arrbuffer.buffer);
for (var i = 0; i < strLen; ++i) { var str1 = '';
bufView[i] = strXml.charCodeAt(i); function func1(name, value){
} str1 += name + value + ' ';
var that = new xml.XmlPullParser(arrayBuffer);
var arr = {};
var i = 0;
function func3(key, info){
arr[i] = 'key:' + JSON.stringify(key) + info.getDepth() + info.getColumnNumber() + info.getLineNumber() +
info.getAttributeCount() + info.getName() + info.getNamespace() + info.getPrefix() + info.getText() +
info.isEmptyElementTag()+ info.isWhitespace();
i++;
return true; return true;
} }
var options = {supportDoctype:true, ignoreNameSpace:true, tokenValueCallbackFunction:func3} var options = {supportDoctype:true, ignoreNameSpace:true, tagValueCallbackFunction:func1}
that.parse(options); that.parse(options);
var str = ''; var str3 = ' note [<!ENTITY foo "baa">] note funcrion matchwo(a,6){return 1;} Hello, World! ' +
for(var j = 0; j < i; ++j) { 'company John amp;amp; Hans company title Happy title title Happy title ' +
str = str + arr[j]; '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 ' +
var str1 = 'key:00110falsetruekey:702220 note [\n<!ENTITY foo "baa">]falsefalsekey:216022notefalsefalsekey:' + 'h:table note ';
'1016420 falsetruekey:51470\r\nfuncrion matchwo(a,6)\r\n{\r\nreturn 1;\r\n}\r\nfalsetruekey:101870 ' + expect(str1).assertEqual(str3)
'falsetruekey:612870Hello, World!falsetruekey:1013270 falsetruekey:224170companyfalsetruekey:424670' +
'John falsefalsekey:925170amp;amp;falsetruekey:425670 Hansfalsefalsekey:326670companyfalsetruekey:1017070' +
' falsetruekey:227770titlefalsetruekey:428270Happyfalsefalsekey:329070titlefalsetruekey:1019470 ' +
'falsetruekey:2210170titlefalsetruekey:4210670Happyfalsefalsekey:3211470titlefalsetruekey:10111870 ' +
'falsetruekey:2212470lensfalsetruekey:4212870Workfalsefalsekey:3213570lensfalsetruekey:10113970 ' +
'falsetruekey:2214570lensfalsetruekey:4214970Playfalsefalsekey:3215670lensfalsetruekey:10116070 ' +
'falsetruekey:8117270go therefalsetruekey:10117670 falsetruekey:2217970afalsetruekey:' +
'2318370btruetruekey:3318370bfalsetruekey:3218770afalsetruekey:10119170 falsetruekey:' +
'2223871h:tablefalsefalsekey:10224670 falsetruekey:2325270h:trfalsetruekey:10326470 ' +
'falsetruekey:2427070h:tdfalsetruekey:4427670Applesfalsefalsekey:3428370h:tdfalsetruekey:' +
'10329570 falsetruekey:2430170h:tdfalsetruekey:4430870Bananasfalsefalsekey:3431570h:' +
'tdfalsetruekey:10332370 falsetruekey:3333070h:trfalsetruekey:10233470 falsetruekey:3234470h:' +
'tablefalsetruekey:3135170notefalsetruekey:10351130falsetrue'
expect(str).assertEqual(str1);
}) })
/** /**
...@@ -1159,65 +1109,27 @@ describe('XmlSerializerXmlPullParserTest', function () { ...@@ -1159,65 +1109,27 @@ describe('XmlSerializerXmlPullParserTest', function () {
* @tc.desc: Starts parsing the XML file. * @tc.desc: Starts parsing the XML file.
*/ */
it('testParse003', 0, function () { it('testParse003', 0, function () {
var strXml = let strXml =
'<?xml version="1.0" encoding="utf-8"?>' + '<?xml version="1.0" encoding="utf-8"?>' +
'<!DOCTYPE note [\n<!ENTITY foo "baa">]>' + '<note importance="high" logged="true">' +
'<note importance="high" logged="true">' + ' <title>Happy</title>' +
' <![CDATA[\r\nfuncrion matchwo(a,6)\r\n{\r\nreturn 1;\r\n}\r\n]]>' + ' <todo>Work</todo>' +
' <!--Hello, World!-->' + ' <todo>Play</todo>' +
' <company>John &amp; Hans</company>' + '</note>';
' <title>Happy</title>' + let textEncoder = new util.TextEncoder();
' <title>Happy</title>' + let arrbuffer = textEncoder.encodeInto(strXml);
' <lens>Work</lens>' + let that = new xml.XmlPullParser(arrbuffer.buffer);
' <lens>Play</lens>' + let str = "";
' <?go there?>' + function func(key, value){
' <a><b/></a>' + str += 'key:' + key + ' value:'+ value.getColumnNumber() + ' ';
' <h:table xmlns:h="http://www.w3.org/TR/html4/">' + return true;
' <h:tr>' + }
' <h:td>Apples</h:td>' + let options = {supportDoctype:true, ignoreNameSpace:true, tokenValueCallbackFunction:func}
' <h:td>Bananas</h:td>' +
' </h:tr>' +
' </h:table>' +
'</note>';
var arrayBuffer = new ArrayBuffer(strXml.length);
var bufView = new Uint8Array(arrayBuffer);
var strLen = strXml.length;
for (var i = 0; i < strLen; ++i) {
bufView[i] = strXml.charCodeAt(i);
}
var that = new xml.XmlPullParser(arrayBuffer, 'UTF-8');
var arr = {};
var i = 0;
function func3(key, info){
arr[i] = 'key:' + JSON.stringify(key) + info.getDepth() + info.getColumnNumber() + info.getLineNumber() +
info.getAttributeCount() + info.getName() + info.getNamespace() + info.getPrefix() + info.getText() +
info.isEmptyElementTag()+ info.isWhitespace();
i++;
return true;
}
var options = {supportDoctype:false, ignoreNameSpace:true, tokenValueCallbackFunction:func3}
that.parse(options); that.parse(options);
var str = ''; let result = 'key:0 value:1 key:2 value:77 key:10 value:81 key:2 value:88 key:4 value:93 ' +
for(var j = 0; j < i; ++j) { 'key:3 value:101 key:10 value:105 key:2 value:111 key:4 value:115 key:3 value:122 key:10 value:126 ' +
str = str + arr[j]; 'key:2 value:132 key:4 value:136 key:3 value:143 key:3 value:150 key:1 value:299 ';
} expect(str).assertEqual(result);
var str1 = 'key:00110falsetruekey:216022notefalsefalsekey:1016420 falsetruekey:51470\r\nfuncrion ' +
'matchwo(a,6)\r\n{\r\nreturn 1;\r\n}\r\nfalsetruekey:101870 falsetruekey:612870Hello, World!falsetruekey' +
':1013270 falsetruekey:224170companyfalsetruekey:424670John falsefalsekey:925170amp;amp;falsetruekey' +
':425670 Hansfalsefalsekey:326670companyfalsetruekey:1017070 falsetruekey:227770titlefalsetruekey:428' +
'270Happyfalsefalsekey:329070titlefalsetruekey:1019470 falsetruekey:2210170titlefalsetruekey:4210670' +
'Happyfalsefalsekey:3211470titlefalsetruekey:10111870 falsetruekey:2212470lensfalsetruekey:4212870' +
'Workfalsefalsekey:3213570lensfalsetruekey:10113970 falsetruekey:2214570lensfalsetruekey:4214970' +
'Playfalsefalsekey:3215670lensfalsetruekey:10116070 falsetruekey:8117270go therefalsetruekey' +
':10117670 falsetruekey:2217970afalsetruekey:2318370btruetruekey:3318370bfalsetruekey' +
':3218770afalsetruekey:10119170 falsetruekey:2223871h:tablefalsefalsekey:10224670 ' +
'falsetruekey:2325270h:trfalsetruekey:10326470 falsetruekey:' +
'2427070h:tdfalsetruekey:4427670Applesfalsefalsekey:3428370h:tdfalsetruekey:10329570 ' +
'falsetruekey:2430170h:tdfalsetruekey:4430870Bananasfalsefalsekey:3431570h:tdfalsetruekey:10332370 ' +
' falsetruekey:3333070h:trfalsetruekey:10233470 falsetruekey:3234470h:tablefalsetruekey:' +
'3135170notefalsetruekey:10351130falsetrue'
expect(str).assertEqual(str1);
}) })
/** /**
...@@ -1225,42 +1137,27 @@ describe('XmlSerializerXmlPullParserTest', function () { ...@@ -1225,42 +1137,27 @@ describe('XmlSerializerXmlPullParserTest', function () {
* @tc.desc: Starts parsing the XML file. * @tc.desc: Starts parsing the XML file.
*/ */
it('testParse004', 0, function () { it('testParse004', 0, function () {
var strXml = let strXml =
'<?xml version="1.0" encoding="utf-8"?>' + '<?xml version="1.0" encoding="utf-8"?>' +
'<!DOCTYPE note [\n<!ENTITY foo "baa">]>' + '<note importance="high" logged="true">' +
'<note importance="high" logged="true">' + ' <title>Happy</title>' +
' <![CDATA[\r\nfuncrion matchwo(a,6)\r\n{\r\nreturn 1;\r\n}\r\n]]>' + ' <todo>Work</todo>' +
' <!--Hello, World!-->' + ' <todo>Play</todo>' +
' <company>John &amp; Hans</company>' + '</note>';
' <title>Happy</title>' + let textEncoder = new util.TextEncoder();
' <title>Happy</title>' + let arrbuffer = textEncoder.encodeInto(strXml);
' <lens>Work</lens>' + let that = new xml.XmlPullParser(arrbuffer.buffer);
' <lens>Play</lens>' + let str = "";
' <?go there?>' + function func(key, value){
' <a><b/></a>' + str += 'key:' + key + ' value:'+ value.getDepth() + ' ';
' <h:table xmlns:h="http://www.w3.org/TR/html4/">' + return true;
' <h:tr>' + }
' <h:td>Apples</h:td>' + let options = {supportDoctype:true, ignoreNameSpace:true, tokenValueCallbackFunction:func}
' <h:td>Bananas</h:td>' +
' </h:tr>' +
' </h:table>' +
'</note>';
var arrayBuffer = new ArrayBuffer(strXml.length);
var bufView = new Uint8Array(arrayBuffer);
var strLen = strXml.length;
for (var i = 0; i < strLen; ++i) {
bufView[i] = strXml.charCodeAt(i);
}
var that = new xml.XmlPullParser(arrayBuffer, 'UTF-8');
var str = '';
function func2(name, value){
str += name+':'+value;
return true;
}
var options = {supportDoctype:true, ignoreNameSpace:true, attributeValueCallbackFunction:func2}
that.parse(options); that.parse(options);
var str1= 'importance:highlogged:truexmlns:h:http://www.w3.org/TR/html4/'; 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 ' +
expect(str).assertEqual(str1); '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);
}) })
/** /**
...@@ -1268,42 +1165,225 @@ describe('XmlSerializerXmlPullParserTest', function () { ...@@ -1268,42 +1165,225 @@ describe('XmlSerializerXmlPullParserTest', function () {
* @tc.desc: Starts parsing the XML file. * @tc.desc: Starts parsing the XML file.
*/ */
it('testParse005', 0, function () { it('testParse005', 0, function () {
var strXml = let strXml =
'<?xml version="1.0" encoding="utf-8"?>' + '<?xml version="1.0" encoding="utf-8"?>' +
'<!DOCTYPE note [\n<!ENTITY foo "baa">]>' + '<note importance="high" logged="true">' +
'<note importance="high" logged="true">' + ' <title>Happy</title>' +
' <![CDATA[\r\nfuncrion matchwo(a,6)\r\n{\r\nreturn 1;\r\n}\r\n]]>' + ' <todo>Work</todo>' +
' <!--Hello, World!-->' + ' <todo>Play</todo>' +
' <company>John &amp; Hans</company>' + '</note>';
' <title>Happy</title>' + let textEncoder = new util.TextEncoder();
' <title>Happy</title>' + let arrbuffer = textEncoder.encodeInto(strXml);
' <lens>Work</lens>' + let that = new xml.XmlPullParser(arrbuffer.buffer);
' <lens>Play</lens>' + let str = "";
' <?go there?>' + function func(key, value){
' <a><b/></a>' + str += 'key:'+ key + ' value:' + value.getLineNumber() + ' ';
' <h:table xmlns:h="http://www.w3.org/TR/html4/">' + return true;
' <h:tr>' + }
' <h:td>Apples</h:td>' + let options = {supportDoctype:true, ignoreNameSpace:true, tokenValueCallbackFunction:func}
' <h:td>Bananas</h:td>' +
' </h:tr>' +
' </h:table>' +
'</note>';
var arrayBuffer = new ArrayBuffer(strXml.length);
var bufView = new Uint8Array(arrayBuffer);
var strLen = strXml.length;
for (var i = 0; i < strLen; ++i) {
bufView[i] = strXml.charCodeAt(i);
}
var that = new xml.XmlPullParser(arrayBuffer, 'UTF-8');
var str1 = '';
function func1(name, value){
str1 += name+':'+value;
return true;
}
var options = {supportDoctype:true, ignoreNameSpace:true, tagValueCallbackFunction:func1}
that.parse(options); that.parse(options);
var str3 = 'note:company:title:title:lens:lens:a:b:h:table:h:tr:h:td:h:td:' 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 ' +
expect(str1).assertEqual(str3) '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);
})
/**
* @tc.name: testParse006
* @tc.desc: Starts parsing the XML file.
*/
it('testParse006', 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.getName() + ' ';
return true;
}
let options = {supportDoctype:true, ignoreNameSpace:true, tokenValueCallbackFunction:func}
that.parse(options);
let result = 'key:0 value: key:2 value:note key:10 value: key:2 value:title key:4 value: ' +
'key:3 value:title key:10 value: key:2 value:todo key:4 value: key:3 value:todo key:10 value: ' +
'key:2 value:todo key:4 value: key:3 value:todo key:3 value:note key:1 value: ';
expect(str).assertEqual(result);
})
/**
* @tc.name: testParse007
* @tc.desc: Starts parsing the XML file.
*/
it('testParse007', 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.getNamespace() + ' ';
return true;
}
let options = {supportDoctype:true, ignoreNameSpace:true, tokenValueCallbackFunction:func}
that.parse(options);
let result = 'key:0 value: key:2 value: key:10 value: key:2 value: key:4 value: key:3 value: ' +
'key:10 value: key:2 value: key:4 value: key:3 value: key:10 value: key:2 value: key:4 value: ' +
'key:3 value: key:3 value: key:1 value: ';
expect(str).assertEqual(result);
})
/**
* @tc.name: testParse008
* @tc.desc: Starts parsing the XML file.
*/
it('testParse008', 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.getPrefix() + ' ';
return true;
}
let options = {supportDoctype:true, ignoreNameSpace:true, tokenValueCallbackFunction:func}
that.parse(options);
let result = 'key:0 value: key:2 value: key:10 value: key:2 value: key:4 value: key:3 value: ' +
'key:10 value: key:2 value: key:4 value: key:3 value: key:10 value: key:2 value: key:4 value: ' +
'key:3 value: key:3 value: key:1 value: ';
expect(str).assertEqual(result);
})
/**
* @tc.name: testParse009
* @tc.desc: Starts parsing the XML file.
*/
it('testParse009', 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.getText() + ' ';
return true;
}
let options = {supportDoctype:true, ignoreNameSpace:true, tokenValueCallbackFunction:func}
that.parse(options);
let result = 'key:0 value: key:2 value: key:10 value: key:2 value: key:4 value:Happy ' +
'key:3 value: key:10 value: key:2 value: key:4 value:Work key:3 value: key:10 value: ' +
'key:2 value: key:4 value:Play key:3 value: key:3 value: key:1 value: ';
expect(str).assertEqual(result);
})
/**
* @tc.name: testParse010
* @tc.desc: Starts parsing the XML file.
*/
it('testParse010', 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.isEmptyElementTag() + ' ';
return true;
}
let options = {supportDoctype:true, ignoreNameSpace:true, tokenValueCallbackFunction:func}
that.parse(options);
let result = 'key:0 value:false key:2 value:false key:10 value:false key:2 value:false ' +
'key:4 value:false key:3 value:false key:10 value:false key:2 value:false key:4 value:false ' +
'key:3 value:false key:10 value:false key:2 value:false key:4 value:false key:3 value:false ' +
'key:3 value:false key:1 value:false ';
expect(str).assertEqual(result);
})
/**
* @tc.name: testParse011
* @tc.desc: Starts parsing the XML file.
*/
it('testParse011', 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.isWhitespace() + ' ';
return true;
}
let options = {supportDoctype:true, ignoreNameSpace:true, tokenValueCallbackFunction:func}
that.parse(options);
let result = 'key:0 value:true key:2 value:false key:10 value:true key:2 value:true ' +
'key:4 value:false key:3 value:true key:10 value:true key:2 value:true key:4 value:false ' +
'key:3 value:true key:10 value:true key:2 value:true key:4 value:false key:3 value:true ' +
'key:3 value:true key:1 value:true ';
expect(str).assertEqual(result);
})
/**
* @tc.name: testParse012
* @tc.desc: Starts parsing the XML file.
*/
it('testParse012', 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.getAttributeCount() + ' ';
return true;
}
let options = {supportDoctype:true, ignoreNameSpace:true, tokenValueCallbackFunction:func}
that.parse(options);
let result = 'key:0 value:0 key:2 value:2 key:10 value:0 key:2 value:0 key:4 value:0 ' +
'key:3 value:0 key:10 value:0 key:2 value:0 key:4 value:0 key:3 value:0 key:10 value:0 ' +
'key:2 value:0 key:4 value:0 key:3 value:0 key:3 value:0 key:1 value:0 ';
expect(str).assertEqual(result);
}) })
/** /**
...@@ -1406,10 +1486,10 @@ describe('XmlSerializerXmlPullParserTest', function () { ...@@ -1406,10 +1486,10 @@ describe('XmlSerializerXmlPullParserTest', function () {
}) })
/** /**
* @tc.name: testBusinessError001 * @tc.name: testXmlBusinessError001
* @tc.desc: To XML text to JavaScript object. * @tc.desc: To XML text to JavaScript object.
*/ */
it('testBusinessError001', 0, function () { it('testXmlBusinessError001', 0, function () {
try { try {
new xml.XmlSerializer(123,"utf-8"); new xml.XmlSerializer(123,"utf-8");
} catch (e) { } catch (e) {
...@@ -1418,10 +1498,10 @@ describe('XmlSerializerXmlPullParserTest', function () { ...@@ -1418,10 +1498,10 @@ describe('XmlSerializerXmlPullParserTest', function () {
}) })
/** /**
* @tc.name: testBusinessError002 * @tc.name: testXmlBusinessError002
* @tc.desc: To XML text to JavaScript object. * @tc.desc: To XML text to JavaScript object.
*/ */
it('testBusinessError002', 0, function () { it('testXmlBusinessError002', 0, function () {
try { try {
var arrayBuffer = new ArrayBuffer(2048); var arrayBuffer = new ArrayBuffer(2048);
new xml.XmlSerializer(arrayBuffer,123); new xml.XmlSerializer(arrayBuffer,123);
...@@ -1431,10 +1511,10 @@ describe('XmlSerializerXmlPullParserTest', function () { ...@@ -1431,10 +1511,10 @@ describe('XmlSerializerXmlPullParserTest', function () {
}) })
/** /**
* @tc.name: testBusinessError003 * @tc.name: testXmlBusinessError003
* @tc.desc: To XML text to JavaScript object. * @tc.desc: To XML text to JavaScript object.
*/ */
it('testBusinessError003', 0, function () { it('testXmlBusinessError003', 0, function () {
try { try {
var arrayBuffer = new ArrayBuffer(2048); var arrayBuffer = new ArrayBuffer(2048);
var thatSer = new xml.XmlSerializer(arrayBuffer,"utf-8"); var thatSer = new xml.XmlSerializer(arrayBuffer,"utf-8");
...@@ -1445,10 +1525,10 @@ describe('XmlSerializerXmlPullParserTest', function () { ...@@ -1445,10 +1525,10 @@ describe('XmlSerializerXmlPullParserTest', function () {
}) })
/** /**
* @tc.name: testBusinessError004 * @tc.name: testXmlBusinessError004
* @tc.desc: To XML text to JavaScript object. * @tc.desc: To XML text to JavaScript object.
*/ */
it('testBusinessError004', 0, function () { it('testXmlBusinessError004', 0, function () {
try { try {
var arrayBuffer = new ArrayBuffer(2048); var arrayBuffer = new ArrayBuffer(2048);
var thatSer = new xml.XmlSerializer(arrayBuffer,"utf-8"); var thatSer = new xml.XmlSerializer(arrayBuffer,"utf-8");
...@@ -1460,10 +1540,10 @@ describe('XmlSerializerXmlPullParserTest', function () { ...@@ -1460,10 +1540,10 @@ describe('XmlSerializerXmlPullParserTest', function () {
}) })
/** /**
* @tc.name: testBusinessError005 * @tc.name: testXmlBusinessError005
* @tc.desc: To XML text to JavaScript object. * @tc.desc: To XML text to JavaScript object.
*/ */
it('testBusinessError005', 0, function () { it('testXmlBusinessError005', 0, function () {
try { try {
var arrayBuffer = new ArrayBuffer(2048); var arrayBuffer = new ArrayBuffer(2048);
var thatSer = new xml.XmlSerializer(arrayBuffer,"utf-8"); var thatSer = new xml.XmlSerializer(arrayBuffer,"utf-8");
...@@ -1475,10 +1555,10 @@ describe('XmlSerializerXmlPullParserTest', function () { ...@@ -1475,10 +1555,10 @@ describe('XmlSerializerXmlPullParserTest', function () {
}) })
/** /**
* @tc.name: testBusinessError006 * @tc.name: testXmlBusinessError006
* @tc.desc: To XML text to JavaScript object. * @tc.desc: To XML text to JavaScript object.
*/ */
it('testBusinessError006', 0, function () { it('testXmlBusinessError006', 0, function () {
try { try {
var arrayBuffer = new ArrayBuffer(2048); var arrayBuffer = new ArrayBuffer(2048);
var thatSer = new xml.XmlSerializer(arrayBuffer,"utf-8"); var thatSer = new xml.XmlSerializer(arrayBuffer,"utf-8");
...@@ -1491,10 +1571,10 @@ describe('XmlSerializerXmlPullParserTest', function () { ...@@ -1491,10 +1571,10 @@ describe('XmlSerializerXmlPullParserTest', function () {
}) })
/** /**
* @tc.name: testBusinessError007 * @tc.name: testXmlBusinessError007
* @tc.desc: To XML text to JavaScript object. * @tc.desc: To XML text to JavaScript object.
*/ */
it('testBusinessError007', 0, function () { it('testXmlBusinessError007', 0, function () {
try { try {
var arrayBuffer = new ArrayBuffer(2048); var arrayBuffer = new ArrayBuffer(2048);
var thatSer = new xml.XmlSerializer(arrayBuffer,"utf-8"); var thatSer = new xml.XmlSerializer(arrayBuffer,"utf-8");
...@@ -1506,10 +1586,10 @@ describe('XmlSerializerXmlPullParserTest', function () { ...@@ -1506,10 +1586,10 @@ describe('XmlSerializerXmlPullParserTest', function () {
}) })
/** /**
* @tc.name: testBusinessError008 * @tc.name: testXmlBusinessError008
* @tc.desc: To XML text to JavaScript object. * @tc.desc: To XML text to JavaScript object.
*/ */
it('testBusinessError008', 0, function () { it('testXmlBusinessError008', 0, function () {
try { try {
var arrayBuffer = new ArrayBuffer(2048); var arrayBuffer = new ArrayBuffer(2048);
var thatSer = new xml.XmlSerializer(arrayBuffer,"utf-8"); var thatSer = new xml.XmlSerializer(arrayBuffer,"utf-8");
...@@ -1521,10 +1601,10 @@ describe('XmlSerializerXmlPullParserTest', function () { ...@@ -1521,10 +1601,10 @@ describe('XmlSerializerXmlPullParserTest', function () {
}) })
/** /**
* @tc.name: testBusinessError009 * @tc.name: testXmlBusinessError009
* @tc.desc: To XML text to JavaScript object. * @tc.desc: To XML text to JavaScript object.
*/ */
it('testBusinessError009', 0, function () { it('testXmlBusinessError009', 0, function () {
try { try {
var arrayBuffer = new ArrayBuffer(2048); var arrayBuffer = new ArrayBuffer(2048);
var thatSer = new xml.XmlSerializer(arrayBuffer,"utf-8"); var thatSer = new xml.XmlSerializer(arrayBuffer,"utf-8");
...@@ -1536,10 +1616,10 @@ describe('XmlSerializerXmlPullParserTest', function () { ...@@ -1536,10 +1616,10 @@ describe('XmlSerializerXmlPullParserTest', function () {
}) })
/** /**
* @tc.name: testBusinessError010 * @tc.name: testXmlBusinessError010
* @tc.desc: To XML text to JavaScript object. * @tc.desc: To XML text to JavaScript object.
*/ */
it('testBusinessError010', 0, function () { it('testXmlBusinessError010', 0, function () {
try { try {
var arrayBuffer = new ArrayBuffer(2048); var arrayBuffer = new ArrayBuffer(2048);
var thatSer = new xml.XmlSerializer(arrayBuffer,"utf-8"); var thatSer = new xml.XmlSerializer(arrayBuffer,"utf-8");
...@@ -1551,10 +1631,10 @@ describe('XmlSerializerXmlPullParserTest', function () { ...@@ -1551,10 +1631,10 @@ describe('XmlSerializerXmlPullParserTest', function () {
}) })
/** /**
* @tc.name: testBusinessError011 * @tc.name: testXmlBusinessError011
* @tc.desc: To XML text to JavaScript object. * @tc.desc: To XML text to JavaScript object.
*/ */
it('testBusinessError0011', 0, function () { it('testXmlBusinessError011', 0, function () {
try { try {
var arrayBuffer = new ArrayBuffer(2048); var arrayBuffer = new ArrayBuffer(2048);
var thatSer = new xml.XmlSerializer(arrayBuffer,"utf-8"); var thatSer = new xml.XmlSerializer(arrayBuffer,"utf-8");
...@@ -1565,10 +1645,10 @@ describe('XmlSerializerXmlPullParserTest', function () { ...@@ -1565,10 +1645,10 @@ describe('XmlSerializerXmlPullParserTest', function () {
}) })
/** /**
* @tc.name: testBusinessError012 * @tc.name: testXmlBusinessError012
* @tc.desc: To XML text to JavaScript object. * @tc.desc: To XML text to JavaScript object.
*/ */
it('testBusinessError0012', 0, function () { it('testXmlBusinessError012', 0, function () {
try { try {
var arrayBuffer = new ArrayBuffer(2048); var arrayBuffer = new ArrayBuffer(2048);
var thatSer = new xml.XmlSerializer(arrayBuffer,"utf-8"); var thatSer = new xml.XmlSerializer(arrayBuffer,"utf-8");
...@@ -1579,10 +1659,10 @@ describe('XmlSerializerXmlPullParserTest', function () { ...@@ -1579,10 +1659,10 @@ describe('XmlSerializerXmlPullParserTest', function () {
}) })
/** /**
* @tc.name: testBusinessError013 * @tc.name: testXmlBusinessError013
* @tc.desc: To XML text to JavaScript object. * @tc.desc: To XML text to JavaScript object.
*/ */
it('testBusinessError0013', 0, function () { it('testXmlBusinessError013', 0, function () {
try { try {
new xml.XmlPullParser(111, 'UTF-8'); new xml.XmlPullParser(111, 'UTF-8');
} catch (e) { } catch (e) {
...@@ -1591,10 +1671,10 @@ describe('XmlSerializerXmlPullParserTest', function () { ...@@ -1591,10 +1671,10 @@ describe('XmlSerializerXmlPullParserTest', function () {
}) })
/** /**
* @tc.name: testBusinessError014 * @tc.name: testXmlBusinessError014
* @tc.desc: To XML text to JavaScript object. * @tc.desc: To XML text to JavaScript object.
*/ */
it('testBusinessError0014', 0, function () { it('testXmlBusinessError014', 0, function () {
try { try {
var arrayBuffer = new ArrayBuffer(2048); var arrayBuffer = new ArrayBuffer(2048);
new xml.XmlPullParser(arrayBuffer, 111); new xml.XmlPullParser(arrayBuffer, 111);
...@@ -1604,10 +1684,10 @@ describe('XmlSerializerXmlPullParserTest', function () { ...@@ -1604,10 +1684,10 @@ describe('XmlSerializerXmlPullParserTest', function () {
}) })
/** /**
* @tc.name: testBusinessError015 * @tc.name: testXmlBusinessError015
* @tc.desc: To XML text to JavaScript object. * @tc.desc: To XML text to JavaScript object.
*/ */
it('testBusinessError0015', 0, function () { it('testXmlBusinessError015', 0, function () {
try { try {
var strXml = var strXml =
'<?xml version="1.0" encoding="utf-8"?>' + '<?xml version="1.0" encoding="utf-8"?>' +
...@@ -1629,19 +1709,15 @@ describe('XmlSerializerXmlPullParserTest', function () { ...@@ -1629,19 +1709,15 @@ describe('XmlSerializerXmlPullParserTest', function () {
' </h:tr>' + ' </h:tr>' +
' </h:table>' + ' </h:table>' +
'</note>'; '</note>';
var arrayBuffer = new ArrayBuffer(strXml.length*2); let textEncoder = new util.TextEncoder();
var bufView = new Uint8Array(arrayBuffer); let arrbuffer = textEncoder.encodeInto(strXml);
var strLen = strXml.length; let that = new xml.XmlPullParser(arrbuffer.buffer, 'UTF-8');
for (var i = 0; i < strLen; ++i) {
bufView[i] = strXml.charCodeAt(i);
}
var that = new xml.XmlPullParser(arrayBuffer, 'UTF-8');
var str1 = ''; var str1 = '';
function func1(name, value){ function func1(name, value){
str1 += name+':'+value; str1 += name+':'+value;
return true; return true;
} }
var options = {supportDoctype:true, ignoreNameSpace:true, tagValueCallbackFunction:func1} var options = 111
that.parse(options); that.parse(options);
} catch (e) { } catch (e) {
expect(e.toString()).assertEqual("BusinessError: Parameter error.The type of 111 must be object") expect(e.toString()).assertEqual("BusinessError: Parameter error.The type of 111 must be object")
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册