1/* 2 * Copyright (C) 2022 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the 'License'); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an 'AS IS' BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15import {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from '@ohos/hypium' 16import xml from '@ohos.xml' 17import util from '@ohos.util' 18export default function XmlSerializerXmlPullParserTest() { 19describe('XmlSerializerXmlPullParserTest', function () { 20 21 /** 22 * @tc.name: testSetDeclaration001 23 * @tc.desc: Writes xml declaration with encoding. For example: <?xml version="1.0" encoding="utf-8"?>. 24 */ 25 it('testSetDeclaration001', 0, function () { 26 var arrayBuffer = new ArrayBuffer(2048); 27 var thatSer = new xml.XmlSerializer(arrayBuffer,"utf-8"); 28 thatSer.setDeclaration(); 29 var result = '<?xml version="1.0" encoding="utf-8"?>'; 30 var view = new Uint8Array(arrayBuffer); 31 var view1 = ""; 32 for (var i = 0; i < result.length; ++i) { 33 view1 = view1 + String.fromCodePoint(view[i]); 34 } 35 expect(view1).assertEqual(result); 36 }) 37 38 /** 39 * @tc.name: testSetDeclaration002 40 * @tc.desc: Writes xml declaration with encoding. For example: <?xml version="1.0" encoding="utf-8"?>. 41 */ 42 it('testSetDeclaration002', 0, function () { 43 var arrayBuffer = new ArrayBuffer(2048); 44 var thatSer = new xml.XmlSerializer(arrayBuffer,"utf-8"); 45 thatSer.setDeclaration(); 46 var result = '<?xml version="1.0" encoding="utf-8"?>'; 47 var view = new Uint8Array(arrayBuffer); 48 var view1 = ""; 49 for (var i = 0; i < result.length; ++i) { 50 view1 = view1 + String.fromCodePoint(view[i]); 51 } 52 expect(view1).assertEqual(result); 53 }) 54 55 /** 56 * @tc.name: testSetDeclaration003 57 * @tc.desc: Writes xml declaration with encoding. For example: <?xml version="1.0" encoding="utf-8"?>. 58 */ 59 it('testSetDeclaration003', 0, function () { 60 var arrayBuffer = new ArrayBuffer(2048); 61 var thatSer = new xml.XmlSerializer(arrayBuffer,"utf-8"); 62 thatSer.setDeclaration(); 63 var result = '<?xml version="1.0" encoding="utf-8"?>'; 64 var view = new Uint8Array(arrayBuffer); 65 var view1 = ""; 66 for (var i = 0; i < result.length; ++i) { 67 view1 = view1 + String.fromCodePoint(view[i]); 68 } 69 expect(view1).assertEqual(result); 70 }) 71 72 /** 73 * @tc.name: testSetDeclaration004 74 * @tc.desc: Writes xml declaration with encoding. For example: <?xml version="1.0" encoding="utf-8"?>. 75 */ 76 it('testSetDeclaration004', 0, function () { 77 var arrayBuffer = new ArrayBuffer(2048); 78 var thatSer = new xml.XmlSerializer(arrayBuffer); 79 thatSer.setDeclaration(); 80 var result = '<?xml version="1.0" encoding="utf-8"?>'; 81 var view = new Uint8Array(arrayBuffer); 82 var view1 = ""; 83 for (var i = 0; i < result.length; ++i) { 84 view1 = view1 + String.fromCodePoint(view[i]); 85 } 86 expect(view1).assertEqual(result); 87 }) 88 89 /** 90 * @tc.name: testSetDeclaration005 91 * @tc.desc: Writes xml declaration with encoding. For example: <?xml version="1.0" encoding="utf-8"?>. 92 */ 93 it('testSetDeclaration005', 0, function () { 94 var arrayBuffer = new ArrayBuffer(2048); 95 var thatSer = new xml.XmlSerializer(arrayBuffer); 96 thatSer.setDeclaration(); 97 var result = '<?xml version="1.0" encoding="utf-8"?>'; 98 var view = new Uint8Array(arrayBuffer); 99 var view1 = ""; 100 for (var i = 0; i < result.length; ++i) { 101 view1 = view1 + String.fromCodePoint(view[i]); 102 } 103 expect(view1).assertEqual(result); 104 }) 105 106 /** 107 * @tc.name: testStartElement001 108 * @tc.desc: Writes an elemnet start tag with the given name. 109 */ 110 it('testStartElement001', 0, function () { 111 const myMAX = 2048; 112 var arrayBuffer = new ArrayBuffer(myMAX); 113 var thatSer = new xml.XmlSerializer(arrayBuffer); 114 thatSer.startElement("note1"); 115 thatSer.endElement(); 116 var result = '<note1/>'; 117 var view = new Uint8Array(arrayBuffer); 118 var view1 = ""; 119 for (var i = 0; i < result.length; ++i) { 120 view1 = view1 + String.fromCodePoint(view[i]); 121 } 122 expect(view1).assertEqual(result); 123 }) 124 125 /** 126 * @tc.name: testStartElement002 127 * @tc.desc: Writes an elemnet start tag with the given name. 128 */ 129 it('testStartElement002', 0, function () { 130 const myMAX = 2048; 131 var arrayBuffer = new ArrayBuffer(myMAX); 132 var thatSer = new xml.XmlSerializer(arrayBuffer); 133 thatSer.startElement("note1"); 134 thatSer.endElement(); 135 thatSer.startElement("note2"); 136 thatSer.endElement(); 137 var result = '<note1/>\r\n<note2/>'; 138 var view = new Uint8Array(arrayBuffer); 139 var view1 = ""; 140 for (var i = 0; i < result.length; ++i) { 141 view1 = view1 + String.fromCodePoint(view[i]); 142 } 143 expect(view1).assertEqual(result); 144 }) 145 146 /** 147 * @tc.name: testStartElement003 148 * @tc.desc: Writes an elemnet start tag with the given name. 149 */ 150 it('testStartElement003', 0, function () { 151 const myMAX = 2048; 152 var arrayBuffer = new ArrayBuffer(myMAX); 153 var thatSer = new xml.XmlSerializer(arrayBuffer); 154 thatSer.startElement("note1"); 155 thatSer.startElement("note2"); 156 thatSer.endElement(); 157 thatSer.endElement(); 158 var result = '<note1>\r\n <note2/>\r\n</note1>'; 159 var view = new Uint8Array(arrayBuffer); 160 var view1 = ""; 161 for (var i = 0; i < result.length; ++i) { 162 view1 = view1 + String.fromCodePoint(view[i]); 163 } 164 expect(view1).assertEqual(result); 165 }) 166 167 /** 168 * @tc.name: testStartElement004 169 * @tc.desc: Writes an elemnet start tag with the given name. 170 */ 171 it('testStartElement004', 0, function () { 172 const myMAX = 2048; 173 var arrayBuffer = new ArrayBuffer(myMAX); 174 var thatSer = new xml.XmlSerializer(arrayBuffer); 175 thatSer.startElement("note1"); 176 thatSer.startElement("note2"); 177 thatSer.startElement("note3"); 178 thatSer.endElement(); 179 thatSer.endElement(); 180 thatSer.endElement(); 181 var result = '<note1>\r\n <note2>\r\n <note3/>\r\n </note2>\r\n</note1>'; 182 var view = new Uint8Array(arrayBuffer); 183 var view1 = ""; 184 for (var i = 0; i < result.length; ++i) { 185 view1 = view1 + String.fromCodePoint(view[i]); 186 } 187 expect(view1).assertEqual(result); 188 }) 189 190 /** 191 * @tc.name: testStartElement005 192 * @tc.desc: Writes an elemnet start tag with the given name. 193 */ 194 it('testStartElement005', 0, function () { 195 const myMAX = 2048; 196 var arrayBuffer = new ArrayBuffer(myMAX); 197 var thatSer = new xml.XmlSerializer(arrayBuffer); 198 thatSer.startElement("note1"); 199 thatSer.startElement("note2"); 200 thatSer.endElement(); 201 thatSer.startElement("note3"); 202 thatSer.endElement(); 203 thatSer.endElement(); 204 var result = '<note1>\r\n <note2/>\r\n <note3/>\r\n</note1>'; 205 var view = new Uint8Array(arrayBuffer); 206 var view1 = ""; 207 for (var i = 0; i < result.length; ++i) { 208 view1 = view1 + String.fromCodePoint(view[i]); 209 } 210 expect(view1).assertEqual(result); 211 }) 212 213 /** 214 * @tc.name: testSetAttributes001 215 * @tc.desc: Write an attribute. 216 */ 217 it('testSetAttributes001', 0, function () { 218 const myMAX = 2048; 219 var arrayBuffer = new ArrayBuffer(myMAX); 220 var thatSer = new xml.XmlSerializer(arrayBuffer); 221 thatSer.startElement("note"); 222 thatSer.setAttributes("importance1", "high1"); 223 thatSer.endElement(); 224 var result = '<note importance1="high1"/>'; 225 var view = new Uint8Array(arrayBuffer); 226 var view1 = ""; 227 for (var i = 0; i < result.length; ++i) { 228 view1 = view1 + String.fromCodePoint(view[i]); 229 } 230 expect(view1).assertEqual(result); 231 }) 232 233 /** 234 * @tc.name: testSetAttributes002 235 * @tc.desc: Write an attribute. 236 */ 237 it('testSetAttributes002', 0, function () { 238 const myMAX = 2048; 239 var arrayBuffer = new ArrayBuffer(myMAX); 240 var thatSer = new xml.XmlSerializer(arrayBuffer); 241 thatSer.startElement("note"); 242 thatSer.setAttributes("importance1", "high1"); 243 thatSer.setAttributes("importance2", "high2"); 244 thatSer.endElement(); 245 var result = '<note importance1="high1" importance2="high2"/>'; 246 var view = new Uint8Array(arrayBuffer); 247 var view1 = ""; 248 for (var i = 0; i < result.length; ++i) { 249 view1 = view1 + String.fromCodePoint(view[i]); 250 } 251 expect(view1).assertEqual(result); 252 }) 253 254 /** 255 * @tc.name: testSetAttributes003 256 * @tc.desc: Write an attribute. 257 */ 258 it('testSetAttributes003', 0, function () { 259 const myMAX = 2048; 260 var arrayBuffer = new ArrayBuffer(myMAX); 261 var thatSer = new xml.XmlSerializer(arrayBuffer); 262 thatSer.startElement("note"); 263 thatSer.setAttributes("importance1", "high1"); 264 thatSer.setAttributes("importance2", "high2"); 265 thatSer.setAttributes("importance3", "high3"); 266 thatSer.endElement(); 267 var result = '<note importance1="high1" importance2="high2" importance3="high3"/>'; 268 var view = new Uint8Array(arrayBuffer); 269 var view1 = ""; 270 for (var i = 0; i < result.length; ++i) { 271 view1 = view1 + String.fromCodePoint(view[i]); 272 } 273 expect(view1).assertEqual(result); 274 }) 275 276 /** 277 * @tc.name: testSetAttributes004 278 * @tc.desc: Write an attribute. 279 */ 280 it('testSetAttributes004', 0, function () { 281 const myMAX = 2048; 282 var arrayBuffer = new ArrayBuffer(myMAX); 283 var thatSer = new xml.XmlSerializer(arrayBuffer); 284 thatSer.startElement("note"); 285 thatSer.setAttributes("importance1", "high1"); 286 thatSer.setAttributes("importance2", "high2"); 287 thatSer.setAttributes("importance3", "high3"); 288 thatSer.setAttributes("importance4", "high4"); 289 thatSer.endElement(); 290 var result = '<note importance1="high1" importance2="high2" importance3="high3" importance4="high4"/>'; 291 var view = new Uint8Array(arrayBuffer); 292 var view1 = ""; 293 for (var i = 0; i < result.length; ++i) { 294 view1 = view1 + String.fromCodePoint(view[i]); 295 } 296 expect(view1).assertEqual(result); 297 }) 298 299 /** 300 * @tc.name: testSetAttributes005 301 * @tc.desc: Write an attribute. 302 */ 303 it('testSetAttributes005', 0, function () { 304 const myMAX = 2048; 305 var arrayBuffer = new ArrayBuffer(myMAX); 306 var thatSer = new xml.XmlSerializer(arrayBuffer); 307 thatSer.startElement("note"); 308 thatSer.setAttributes("importance1", "high1"); 309 thatSer.setAttributes("importance2", "high2"); 310 thatSer.setAttributes("importance3", "high3"); 311 thatSer.setAttributes("importance5", "high5"); 312 thatSer.endElement(); 313 var result = '<note importance1="high1" importance2="high2" importance3="high3" importance5="high5"/>'; 314 var view = new Uint8Array(arrayBuffer); 315 var view1 = ""; 316 for (var i = 0; i < result.length; ++i) { 317 view1 = view1 + String.fromCodePoint(view[i]); 318 } 319 expect(view1).assertEqual(result); 320 }) 321 322 /** 323 * @tc.name: testEndElement001 324 * @tc.desc: Writes end tag of the element. 325 */ 326 it('testEndElement001', 0, function () { 327 const myMAX = 2048; 328 var arrayBuffer = new ArrayBuffer(myMAX); 329 var thatSer = new xml.XmlSerializer(arrayBuffer); 330 thatSer.startElement("note"); 331 thatSer.endElement(); 332 var result = '<note/>'; 333 var view = new Uint8Array(arrayBuffer); 334 var view1 = ""; 335 for (var i = 0; i < result.length; ++i) { 336 view1 = view1 + String.fromCodePoint(view[i]); 337 } 338 expect(view1).assertEqual(result); 339 }) 340 341 /** 342 * @tc.name: testEndElement002 343 * @tc.desc: Writes end tag of the element. 344 */ 345 it('testEndElement002', 0, function () { 346 const myMAX = 2048; 347 var arrayBuffer = new ArrayBuffer(myMAX); 348 var thatSer = new xml.XmlSerializer(arrayBuffer); 349 thatSer.startElement("note"); 350 thatSer.setAttributes("importance", "high"); 351 thatSer.endElement(); 352 var result = '<note importance="high"/>'; 353 var view = new Uint8Array(arrayBuffer); 354 var view1 = ""; 355 for (var i = 0; i < result.length; ++i) { 356 view1 = view1 + String.fromCodePoint(view[i]); 357 } 358 expect(view1).assertEqual(result); 359 }) 360 361 /** 362 * @tc.name: testEndElement003 363 * @tc.desc: Writes end tag of the element. 364 */ 365 it('testEndElement003', 0, function () { 366 const myMAX = 2048; 367 var arrayBuffer = new ArrayBuffer(myMAX); 368 var thatSer = new xml.XmlSerializer(arrayBuffer); 369 thatSer.startElement("note"); 370 thatSer.setAttributes("impo", "hi"); 371 thatSer.endElement(); 372 var result = '<note impo="hi"/>'; 373 var view = new Uint8Array(arrayBuffer); 374 var view1 = ""; 375 for (var i = 0; i < result.length; ++i) { 376 view1 = view1 + String.fromCodePoint(view[i]); 377 } 378 expect(view1).assertEqual(result); 379 }) 380 381 /** 382 * @tc.name: testEndElement004 383 * @tc.desc: Writes end tag of the element. 384 */ 385 it('testEndElement004', 0, function () { 386 const myMAX = 2048; 387 var arrayBuffer = new ArrayBuffer(myMAX); 388 var thatSer = new xml.XmlSerializer(arrayBuffer); 389 thatSer.startElement("note1"); 390 thatSer.startElement("note2"); 391 thatSer.endElement(); 392 thatSer.endElement(); 393 var result = '<note1>\r\n <note2/>\r\n</note1>'; 394 var view = new Uint8Array(arrayBuffer); 395 var view1 = ""; 396 for (var i = 0; i < result.length; ++i) { 397 view1 = view1 + String.fromCodePoint(view[i]); 398 } 399 expect(view1).assertEqual(result); 400 }) 401 402 /** 403 * @tc.name: testEndElement005 404 * @tc.desc: Writes end tag of the element. 405 */ 406 it('testEndElement005', 0, function () { 407 const myMAX = 2048; 408 var arrayBuffer = new ArrayBuffer(myMAX); 409 var thatSer = new xml.XmlSerializer(arrayBuffer); 410 thatSer.startElement("note2"); 411 thatSer.setAttributes("importance", "high"); 412 thatSer.endElement(); 413 var result = '<note2 importance="high"/>'; 414 var view = new Uint8Array(arrayBuffer); 415 var view1 = ""; 416 for (var i = 0; i < result.length; ++i) { 417 view1 = view1 + String.fromCodePoint(view[i]); 418 } 419 expect(view1).assertEqual(result); 420 }) 421 422 /** 423 * @tc.name: testSetText001 424 * @tc.desc: Writes the text. 425 */ 426 it('testSetText001', 0, function () { 427 const myMAX = 2048; 428 var arrayBuffer = new ArrayBuffer(myMAX); 429 var thatSer = new xml.XmlSerializer(arrayBuffer); 430 thatSer.startElement("note"); 431 thatSer.setAttributes("importance", "high"); 432 thatSer.setText("Happy1"); 433 thatSer.endElement(); 434 var result = '<note importance="high">Happy1</note>'; 435 var view = new Uint8Array(arrayBuffer); 436 var view1 = ""; 437 for (var i = 0; i < result.length; ++i) { 438 view1 = view1 + String.fromCodePoint(view[i]); 439 } 440 expect(view1).assertEqual(result); 441 }) 442 443 /** 444 * @tc.name: testSetText002 445 * @tc.desc: Writes the text. 446 */ 447 it('testSetText002', 0, function () { 448 const myMAX = 2048; 449 var arrayBuffer = new ArrayBuffer(myMAX); 450 var thatSer = new xml.XmlSerializer(arrayBuffer); 451 thatSer.startElement("note"); 452 thatSer.setAttributes("importance", "high"); 453 thatSer.setText("Happy2"); 454 thatSer.endElement(); 455 var result = '<note importance="high">Happy2</note>'; 456 var view = new Uint8Array(arrayBuffer); 457 var view1 = ""; 458 for (var i = 0; i < result.length; ++i) { 459 view1 = view1 + String.fromCodePoint(view[i]); 460 } 461 expect(view1).assertEqual(result); 462 }) 463 464 /** 465 * @tc.name: testSetText003 466 * @tc.desc: Writes the text. 467 */ 468 it('testSetText003', 0, function () { 469 const myMAX = 2048; 470 var arrayBuffer = new ArrayBuffer(myMAX); 471 var thatSer = new xml.XmlSerializer(arrayBuffer); 472 thatSer.startElement("note"); 473 thatSer.setAttributes("importance", "high"); 474 thatSer.setText("Happy3"); 475 thatSer.endElement(); 476 var result = '<note importance="high">Happy3</note>'; 477 var view = new Uint8Array(arrayBuffer); 478 var view1 = ""; 479 for (var i = 0; i < result.length; ++i) { 480 view1 = view1 + String.fromCodePoint(view[i]); 481 } 482 expect(view1).assertEqual(result); 483 }) 484 485 /** 486 * @tc.name: testSetText004 487 * @tc.desc: Writes the text. 488 */ 489 it('testSetText004', 0, function () { 490 const myMAX = 2048; 491 var arrayBuffer = new ArrayBuffer(myMAX); 492 var thatSer = new xml.XmlSerializer(arrayBuffer); 493 thatSer.startElement("note"); 494 thatSer.setAttributes("importance", "high"); 495 thatSer.setText("Happy4"); 496 thatSer.endElement(); 497 var result = '<note importance="high">Happy4</note>'; 498 var view = new Uint8Array(arrayBuffer); 499 var view1 = ""; 500 for (var i = 0; i < result.length; ++i) { 501 view1 = view1 + String.fromCodePoint(view[i]); 502 } 503 expect(view1).assertEqual(result); 504 }) 505 506 /** 507 * @tc.name: testSetText005 508 * @tc.desc: Writes the text. 509 */ 510 it('testSetText005', 0, function () { 511 const myMAX = 2048; 512 var arrayBuffer = new ArrayBuffer(myMAX); 513 var thatSer = new xml.XmlSerializer(arrayBuffer); 514 thatSer.startElement("note"); 515 thatSer.setAttributes("importance", "high"); 516 thatSer.setText("Happy5"); 517 thatSer.endElement(); 518 var result = '<note importance="high">Happy5</note>'; 519 var view = new Uint8Array(arrayBuffer); 520 var view1 = ""; 521 for (var i = 0; i < result.length; ++i) { 522 view1 = view1 + String.fromCodePoint(view[i]); 523 } 524 expect(view1).assertEqual(result); 525 }) 526 527 /** 528 * @tc.name: testAddEmptyElement001 529 * @tc.desc: Add an empty element. 530 */ 531 it('testAddEmptyElement001', 0, function () { 532 const myMAX = 2048; 533 var arrayBuffer = new ArrayBuffer(myMAX); 534 var thatSer = new xml.XmlSerializer(arrayBuffer); 535 thatSer.startElement("note"); 536 thatSer.addEmptyElement("a"); 537 thatSer.endElement(); 538 var result = '<note>\r\n <a/>\r\n</note>'; 539 var view = new Uint8Array(arrayBuffer); 540 var view1 = ""; 541 for (var i = 0; i < result.length; ++i) { 542 view1 = view1 + String.fromCodePoint(view[i]); 543 } 544 expect(view1).assertEqual(result); 545 }) 546 547 /** 548 * @tc.name: testAddEmptyElement002 549 * @tc.desc: Add an empty element. 550 */ 551 it('testAddEmptyElement002', 0, function () { 552 const myMAX = 2048; 553 var arrayBuffer = new ArrayBuffer(myMAX); 554 var thatSer = new xml.XmlSerializer(arrayBuffer); 555 thatSer.startElement("note"); 556 thatSer.endElement(); 557 thatSer.addEmptyElement("b"); 558 var result = '<note/>\r\n<b/>'; 559 var view = new Uint8Array(arrayBuffer); 560 var view1 = ""; 561 for (var i = 0; i < result.length; ++i) { 562 view1 = view1 + String.fromCodePoint(view[i]); 563 } 564 expect(view1).assertEqual(result); 565 }) 566 567 /** 568 * @tc.name: testAddEmptyElement003 569 * @tc.desc: Add an empty element. 570 */ 571 it('testAddEmptyElement003', 0, function () { 572 const myMAX = 2048; 573 var arrayBuffer = new ArrayBuffer(myMAX); 574 var thatSer = new xml.XmlSerializer(arrayBuffer); 575 thatSer.addEmptyElement("c"); 576 thatSer.startElement("note"); 577 thatSer.endElement(); 578 var result = '<c/>\r\n<note/>'; 579 var view = new Uint8Array(arrayBuffer); 580 var view1 = ""; 581 for (var i = 0; i < result.length; ++i) { 582 view1 = view1 + String.fromCodePoint(view[i]); 583 } 584 expect(view1).assertEqual(result); 585 }) 586 587 /** 588 * @tc.name: testAddEmptyElement004 589 * @tc.desc: Add an empty element. 590 */ 591 it('testAddEmptyElement004', 0, function () { 592 const myMAX = 2048; 593 var arrayBuffer = new ArrayBuffer(myMAX); 594 var thatSer = new xml.XmlSerializer(arrayBuffer); 595 thatSer.addEmptyElement("d"); 596 var result = '<d/>'; 597 var view = new Uint8Array(arrayBuffer); 598 var view1 = ""; 599 for (var i = 0; i < result.length; ++i) { 600 view1 = view1 + String.fromCodePoint(view[i]); 601 } 602 expect(view1).assertEqual(result); 603 }) 604 605 /** 606 * @tc.name: testAddEmptyElement005 607 * @tc.desc: Add an empty element. 608 */ 609 it('testAddEmptyElement005', 0, function () { 610 const myMAX = 2048; 611 var arrayBuffer = new ArrayBuffer(myMAX); 612 var thatSer = new xml.XmlSerializer(arrayBuffer); 613 thatSer.startElement("note"); 614 thatSer.addEmptyElement("c"); 615 thatSer.addEmptyElement("d"); 616 thatSer.endElement(); 617 var result = '<note>\r\n <c/>\r\n <d/>\r\n</note>'; 618 var view = new Uint8Array(arrayBuffer); 619 var view1 = ""; 620 for (var i = 0; i < result.length; ++i) { 621 view1 = view1 + String.fromCodePoint(view[i]); 622 } 623 expect(view1).assertEqual(result); 624 }) 625 626 /** 627 * @tc.name: testSetNamespace001 628 * @tc.desc: Writes the namespace of the current element tag. 629 */ 630 it('testSetNamespace001', 0, function () { 631 const myMAX = 2048; 632 var arrayBuffer = new ArrayBuffer(myMAX); 633 var thatSer = new xml.XmlSerializer(arrayBuffer); 634 thatSer.setDeclaration(); 635 thatSer.setNamespace("h", "http://www.w3.org/TR/html4/"); 636 thatSer.startElement("note"); 637 thatSer.endElement(); 638 var result = '<?xml version="1.0" encoding="utf-8"?>\r\n<h:note xmlns:h="http://www.w3.org/TR/html4/"/>'; 639 var view = new Uint8Array(arrayBuffer); 640 var view1 = ""; 641 for (var i = 0; i < result.length; ++i) { 642 view1 = view1 + String.fromCodePoint(view[i]); 643 } 644 expect(view1).assertEqual(result); 645 }) 646 647 /** 648 * @tc.name: testSetNamespace002 649 * @tc.desc: Writes the namespace of the current element tag. 650 */ 651 it('testSetNamespace002', 0, function () { 652 const myMAX = 2048; 653 var arrayBuffer = new ArrayBuffer(myMAX); 654 var thatSer = new xml.XmlSerializer(arrayBuffer); 655 thatSer.setDeclaration(); 656 thatSer.setNamespace("b", "http://www.w3.org/TR/html4/"); 657 thatSer.startElement("note"); 658 thatSer.endElement(); 659 var result = '<?xml version="1.0" encoding="utf-8"?>\r\n<b:note xmlns:b="http://www.w3.org/TR/html4/"/>'; 660 var view = new Uint8Array(arrayBuffer); 661 var view1 = ""; 662 for (var i = 0; i < result.length; ++i) { 663 view1 = view1 + String.fromCodePoint(view[i]); 664 } 665 expect(view1).assertEqual(result); 666 }) 667 668 /** 669 * @tc.name: testSetNamespace003 670 * @tc.desc: Writes the namespace of the current element tag. 671 */ 672 it('testSetNamespace003', 0, function () { 673 const myMAX = 2048; 674 var arrayBuffer = new ArrayBuffer(myMAX); 675 var thatSer = new xml.XmlSerializer(arrayBuffer); 676 thatSer.setDeclaration(); 677 thatSer.setNamespace("h", "http://www.111/"); 678 thatSer.startElement("note"); 679 thatSer.endElement(); 680 var result = '<?xml version="1.0" encoding="utf-8"?>\r\n<h:note xmlns:h="http://www.111/"/>'; 681 var view = new Uint8Array(arrayBuffer); 682 var view1 = ""; 683 for (var i = 0; i < result.length; ++i) { 684 view1 = view1 + String.fromCodePoint(view[i]); 685 } 686 expect(view1).assertEqual(result); 687 }) 688 689 /** 690 * @tc.name: testSetNamespace004 691 * @tc.desc: Writes the namespace of the current element tag. 692 */ 693 it('testSetNamespace004', 0, function () { 694 const myMAX = 2048; 695 var arrayBuffer = new ArrayBuffer(myMAX); 696 var thatSer = new xml.XmlSerializer(arrayBuffer); 697 thatSer.setDeclaration(); 698 thatSer.setNamespace("h", "http://www.w3.org/TR/html4/"); 699 thatSer.startElement("note1"); 700 thatSer.startElement("note2"); 701 thatSer.endElement(); 702 thatSer.endElement(); 703 var result = '<?xml version="1.0" encoding="utf-8"?>\r\n<h:note1 xmlns:h="http://www.w3.org/TR/html4/">' + 704 '\r\n <h:note2/>\r\n</h:note1>'; 705 var view = new Uint8Array(arrayBuffer); 706 var view1 = ""; 707 for (var i = 0; i < result.length; ++i) { 708 view1 = view1 + String.fromCodePoint(view[i]); 709 } 710 expect(view1).assertEqual(result); 711 }) 712 713 /** 714 * @tc.name: testSetNamespace005 715 * @tc.desc: Writes the namespace of the current element tag. 716 */ 717 it('testSetNamespace005', 0, function () { 718 const myMAX = 2048; 719 var arrayBuffer = new ArrayBuffer(myMAX); 720 var thatSer = new xml.XmlSerializer(arrayBuffer); 721 thatSer.setDeclaration(); 722 thatSer.setNamespace("h", "http://www.w3.org/TR/html4/"); 723 thatSer.startElement("note1"); 724 thatSer.startElement("note2"); 725 thatSer.endElement(); 726 thatSer.endElement(); 727 var result = '<?xml version="1.0" encoding="utf-8"?>\r\n<h:note1 xmlns:h="http://www.w3.org/TR/html4/">' + 728 '\r\n <h:note2/>\r\n</h:note1>'; 729 var view = new Uint8Array(arrayBuffer); 730 var view1 = ""; 731 for (var i = 0; i < result.length; ++i) { 732 view1 = view1 + String.fromCodePoint(view[i]); 733 } 734 expect(view1).assertEqual(result); 735 }) 736 737 /** 738 * @tc.name: testSetComment001 739 * @tc.desc: Writes the comment. 740 */ 741 it('testSetComment001', 0, function () { 742 const myMAX = 2048; 743 var arrayBuffer = new ArrayBuffer(myMAX); 744 var thatSer = new xml.XmlSerializer(arrayBuffer); 745 thatSer.startElement("note"); 746 thatSer.setComment("Hi!"); 747 thatSer.endElement(); 748 var result = '<note>\r\n <!--Hi!-->\r\n</note>'; 749 var view = new Uint8Array(arrayBuffer); 750 var view1 = ""; 751 for (var i = 0; i < result.length; ++i) { 752 view1 = view1 + String.fromCodePoint(view[i]); 753 } 754 expect(view1).assertEqual(result); 755 }) 756 757 /** 758 * @tc.name: testSetComment002 759 * @tc.desc: Writes the comment. 760 */ 761 it('testSetComment002', 0, function () { 762 const myMAX = 2048; 763 var arrayBuffer = new ArrayBuffer(myMAX); 764 var thatSer = new xml.XmlSerializer(arrayBuffer); 765 thatSer.startElement("note"); 766 thatSer.setComment("Hello, World!"); 767 thatSer.endElement(); 768 var result = '<note>\r\n <!--Hello, World!-->\r\n</note>'; 769 var view = new Uint8Array(arrayBuffer); 770 var view1 = ""; 771 for (var i = 0; i < result.length; ++i) { 772 view1 = view1 + String.fromCodePoint(view[i]); 773 } 774 expect(view1).assertEqual(result); 775 }) 776 777 /** 778 * @tc.name: testSetComment003 779 * @tc.desc: Writes the comment. 780 */ 781 it('testSetComment003', 0, function () { 782 const myMAX = 2048; 783 var arrayBuffer = new ArrayBuffer(myMAX); 784 var thatSer = new xml.XmlSerializer(arrayBuffer); 785 thatSer.setComment("Hello, World!"); 786 var result = '<!--Hello, World!-->'; 787 var view = new Uint8Array(arrayBuffer); 788 var view1 = ""; 789 for (var i = 0; i < result.length; ++i) { 790 view1 = view1 + String.fromCodePoint(view[i]); 791 } 792 expect(view1).assertEqual(result); 793 }) 794 795 /** 796 * @tc.name: testSetComment004 797 * @tc.desc: Writes the comment. 798 */ 799 it('testSetComment004', 0, function () { 800 const myMAX = 2048; 801 var arrayBuffer = new ArrayBuffer(myMAX); 802 var thatSer = new xml.XmlSerializer(arrayBuffer); 803 thatSer.setComment("Hello, World!"); 804 var result = '<!--Hello, World!-->'; 805 var view = new Uint8Array(arrayBuffer); 806 var view1 = ""; 807 for (var i = 0; i < result.length; ++i) { 808 view1 = view1 + String.fromCodePoint(view[i]); 809 } 810 expect(view1).assertEqual(result); 811 }) 812 813 /** 814 * @tc.name: testSetComment005 815 * @tc.desc: Writes the comment. 816 */ 817 it('testSetComment005', 0, function () { 818 const myMAX = 2048; 819 var arrayBuffer = new ArrayBuffer(myMAX); 820 var thatSer = new xml.XmlSerializer(arrayBuffer); 821 thatSer.setComment("Hello, World!"); 822 thatSer.startElement("note"); 823 thatSer.endElement(); 824 var result = '<!--Hello, World!-->\r\n<note/>'; 825 var view = new Uint8Array(arrayBuffer); 826 var view1 = ""; 827 for (var i = 0; i < result.length; ++i) { 828 view1 = view1 + String.fromCodePoint(view[i]); 829 } 830 expect(view1).assertEqual(result); 831 }) 832 833 /** 834 * @tc.name: testSetDocType001 835 * @tc.desc: Writes the DOCTYPE. 836 */ 837 it('testSetDocType001', 0, function () { 838 const myMAX = 2048; 839 var arrayBuffer = new ArrayBuffer(myMAX); 840 var thatSer = new xml.XmlSerializer(arrayBuffer); 841 thatSer.setDocType('root SYSTEM'); 842 var result = '<!DOCTYPE root SYSTEM>'; 843 var view = new Uint8Array(arrayBuffer); 844 var view1 = ""; 845 for (var i = 0; i < result.length; ++i) { 846 view1 = view1 + String.fromCodePoint(view[i]); 847 } 848 expect(view1).assertEqual(result); 849 }) 850 851 /** 852 * @tc.name: testSetDocType002 853 * @tc.desc: Writes the DOCTYPE. 854 */ 855 it('testSetDocType002', 0, function () { 856 const myMAX = 2048; 857 var arrayBuffer = new ArrayBuffer(myMAX); 858 var thatSer = new xml.XmlSerializer(arrayBuffer); 859 thatSer.setDocType('root SYSTEM "http://www.test.org/test.dtd"'); 860 var result = '<!DOCTYPE root SYSTEM "http://www.test.org/test.dtd">'; 861 var view = new Uint8Array(arrayBuffer); 862 var view1 = ""; 863 for (var i = 0; i < result.length; ++i) { 864 view1 = view1 + String.fromCodePoint(view[i]); 865 } 866 expect(view1).assertEqual(result); 867 }) 868 869 /** 870 * @tc.name: testSetDocType003 871 * @tc.desc: Writes the DOCTYPE. 872 */ 873 it('testSetDocType003', 0, function () { 874 const myMAX = 2048; 875 var arrayBuffer = new ArrayBuffer(myMAX); 876 var thatSer = new xml.XmlSerializer(arrayBuffer); 877 thatSer.startElement("note"); 878 thatSer.endElement(); 879 thatSer.setDocType('root SYSTEM "http://www.test.org/test.dtd"'); 880 var result = '<note/>\r\n<!DOCTYPE root SYSTEM "http://www.test.org/test.dtd">'; 881 var view = new Uint8Array(arrayBuffer); 882 var view1 = ""; 883 for (var i = 0; i < result.length; ++i) { 884 view1 = view1 + String.fromCodePoint(view[i]); 885 } 886 expect(view1).assertEqual(result); 887 }) 888 889 /** 890 * @tc.name: testSetDocType004 891 * @tc.desc: Writes the DOCTYPE. 892 */ 893 it('testSetDocType004', 0, function () { 894 const myMAX = 2048; 895 var arrayBuffer = new ArrayBuffer(myMAX); 896 var thatSer = new xml.XmlSerializer(arrayBuffer); 897 thatSer.setDocType('root SYSTEM "http://www.test.org/test.dtd"'); 898 thatSer.startElement("note"); 899 thatSer.endElement(); 900 var result = '<!DOCTYPE root SYSTEM "http://www.test.org/test.dtd">\r\n<note/>'; 901 var view = new Uint8Array(arrayBuffer); 902 var view1 = ""; 903 for (var i = 0; i < result.length; ++i) { 904 view1 = view1 + String.fromCodePoint(view[i]); 905 } 906 expect(view1).assertEqual(result); 907 }) 908 909 /** 910 * @tc.name: testSetDocType005 911 * @tc.desc: Writes the DOCTYPE. 912 */ 913 it('testSetDocType005', 0, function () { 914 const myMAX = 2048; 915 var arrayBuffer = new ArrayBuffer(myMAX); 916 var thatSer = new xml.XmlSerializer(arrayBuffer); 917 thatSer.startElement("note"); 918 thatSer.setDocType('root SYSTEM "http://www.test.org/test.dtd"'); 919 thatSer.endElement(); 920 var result = '<note>\r\n <!DOCTYPE root SYSTEM "http://www.test.org/test.dtd">\r\n</note>'; 921 var view = new Uint8Array(arrayBuffer); 922 var view1 = ""; 923 for (var i = 0; i < result.length; ++i) { 924 view1 = view1 + String.fromCodePoint(view[i]); 925 } 926 expect(view1).assertEqual(result); 927 }) 928 929 /** 930 * @tc.name: testSetCDATA001 931 * @tc.desc: Writes the CDATA. 932 */ 933 it('testSetCDATA001', 0, function () { 934 const myMAX = 2048; 935 var arrayBuffer = new ArrayBuffer(myMAX); 936 var thatSer = new xml.XmlSerializer(arrayBuffer); 937 thatSer.setCDATA('root SYSTEM') 938 var result = '<![CDATA[root SYSTEM]]>'; 939 var view = new Uint8Array(arrayBuffer); 940 var view1 = ""; 941 for (var i = 0; i < result.length; ++i) { 942 view1 = view1 + String.fromCodePoint(view[i]); 943 } 944 expect(view1).assertEqual(result); 945 }) 946 947 /** 948 * @tc.name: testSetCDATA002 949 * @tc.desc: Writes the CDATA. 950 */ 951 it('testSetCDATA002', 0, function () { 952 const myMAX = 2048; 953 var arrayBuffer = new ArrayBuffer(myMAX); 954 var thatSer = new xml.XmlSerializer(arrayBuffer); 955 thatSer.setCDATA('root SYSTEM "http://www.test.org/test.dtd"') 956 var result = '<![CDATA[root SYSTEM "http://www.test.org/test.dtd"]]>'; 957 var view = new Uint8Array(arrayBuffer); 958 var view1 = ""; 959 for (var i = 0; i < result.length; ++i) { 960 view1 = view1 + String.fromCodePoint(view[i]); 961 } 962 expect(view1).assertEqual(result); 963 }) 964 965 /** 966 * @tc.name: testSetCDATA003 967 * @tc.desc: Writes the CDATA. 968 */ 969 it('testSetCDATA003', 0, function () { 970 const myMAX = 2048; 971 var arrayBuffer = new ArrayBuffer(myMAX); 972 var thatSer = new xml.XmlSerializer(arrayBuffer); 973 thatSer.startElement("note"); 974 thatSer.endElement(); 975 thatSer.setCDATA('root SYSTEM "http://www.test.org/test.dtd"') 976 var result = '<note/>\r\n<![CDATA[root SYSTEM "http://www.test.org/test.dtd"]]>'; 977 var view = new Uint8Array(arrayBuffer); 978 var view1 = ""; 979 for (var i = 0; i < result.length; ++i) { 980 view1 = view1 + String.fromCodePoint(view[i]); 981 } 982 expect(view1).assertEqual(result); 983 }) 984 985 /** 986 * @tc.name: testSetCDATA004 987 * @tc.desc: Writes the CDATA. 988 */ 989 it('testSetCDATA004', 0, function () { 990 const myMAX = 2048; 991 var arrayBuffer = new ArrayBuffer(myMAX); 992 var thatSer = new xml.XmlSerializer(arrayBuffer); 993 thatSer.setCDATA('root SYSTEM "http://www.test.org/test.dtd"') 994 thatSer.startElement("note"); 995 thatSer.endElement(); 996 var result = '<![CDATA[root SYSTEM "http://www.test.org/test.dtd"]]>\r\n<note/>'; 997 var view = new Uint8Array(arrayBuffer); 998 var view1 = ""; 999 for (var i = 0; i < result.length; ++i) { 1000 view1 = view1 + String.fromCodePoint(view[i]); 1001 } 1002 expect(view1).assertEqual(result); 1003 }) 1004 1005 /** 1006 * @tc.name: testSetCDATA005 1007 * @tc.desc: Writes the CDATA. 1008 */ 1009 it('testSetCDATA005', 0, function () { 1010 const myMAX = 2048; 1011 var arrayBuffer = new ArrayBuffer(myMAX); 1012 var thatSer = new xml.XmlSerializer(arrayBuffer); 1013 thatSer.startElement("note"); 1014 thatSer.setCDATA('root SYSTEM "http://www.test.org/test.dtd"') 1015 thatSer.endElement(); 1016 var result = '<note>\r\n <![CDATA[root SYSTEM "http://www.test.org/test.dtd"]]>\r\n</note>'; 1017 var view = new Uint8Array(arrayBuffer); 1018 var view1 = ""; 1019 for (var i = 0; i < result.length; ++i) { 1020 view1 = view1 + String.fromCodePoint(view[i]); 1021 } 1022 expect(view1).assertEqual(result); 1023 }) 1024 1025 /** 1026 * @tc.name: testParse001 1027 * @tc.desc: Starts parsing the XML file. 1028 */ 1029 it('testParse001', 0, function () { 1030 var strXml = 1031 '<?xml version="1.0" encoding="utf-8"?>' + 1032 '<!DOCTYPE note [\n<!ENTITY foo "baa">]>' + 1033 '<note importance="high" logged="true">' + 1034 ' <![CDATA[\r\nfuncrion matchwo(a,6)\r\n{\r\nreturn 1;\r\n}\r\n]]>' + 1035 ' <!--Hello, World!-->' + 1036 ' <company>John & Hans</company>' + 1037 ' <title>Happy</title>' + 1038 ' <title>Happy</title>' + 1039 ' <lens>Work</lens>' + 1040 ' <lens>Play</lens>' + 1041 ' <?go there?>' + 1042 ' <a><b/></a>' + 1043 ' <h:table xmlns:h="http://www.w3.org/TR/html4/">' + 1044 ' <h:tr>' + 1045 ' <h:td>Apples</h:td>' + 1046 ' <h:td>Bananas</h:td>' + 1047 ' </h:tr>' + 1048 ' </h:table>' + 1049 '</note>'; 1050 let textEncoder = new util.TextEncoder(); 1051 let arrbuffer = textEncoder.encodeInto(strXml); 1052 let that = new xml.XmlPullParser(arrbuffer.buffer, 'UTF-8'); 1053 var str = ''; 1054 function func2(name, value){ 1055 str += name+':'+value; 1056 return true; 1057 } 1058 var options = {supportDoctype:true, ignoreNameSpace:true, attributeValueCallbackFunction:func2} 1059 that.parse(options); 1060 var str1= 'importance:highlogged:truexmlns:h:http://www.w3.org/TR/html4/'; 1061 expect(str).assertEqual(str1); 1062 }) 1063 1064 /** 1065 * @tc.name: testParse002 1066 * @tc.desc: Starts parsing the XML file. 1067 */ 1068 it('testParse002', 0, function () { 1069 var strXml = 1070 '<?xml version="1.0" encoding="utf-8"?>' + 1071 '<!DOCTYPE note [\n<!ENTITY foo "baa">]>' + 1072 '<note importance="high" logged="true">' + 1073 ' <![CDATA[\r\nfuncrion matchwo(a,6)\r\n{\r\nreturn 1;\r\n}\r\n]]>' + 1074 ' <!--Hello, World!-->' + 1075 ' <company>John & Hans</company>' + 1076 ' <title>Happy</title>' + 1077 ' <title>Happy</title>' + 1078 ' <lens>Work</lens>' + 1079 ' <lens>Play</lens>' + 1080 ' <?go there?>' + 1081 ' <a><b/></a>' + 1082 ' <h:table xmlns:h="http://www.w3.org/TR/html4/">' + 1083 ' <h:tr>' + 1084 ' <h:td>Apples</h:td>' + 1085 ' <h:td>Bananas</h:td>' + 1086 ' </h:tr>' + 1087 ' </h:table>' + 1088 '</note>'; 1089 let textEncoder = new util.TextEncoder(); 1090 let arrbuffer = textEncoder.encodeInto(strXml); 1091 let that = new xml.XmlPullParser(arrbuffer.buffer); 1092 var str1 = ''; 1093 function func1(name, value){ 1094 str1 += name + value + ' '; 1095 return true; 1096 } 1097 var options = {supportDoctype:true, ignoreNameSpace:true, tagValueCallbackFunction:func1} 1098 that.parse(options); 1099 var str3 = ' note [<!ENTITY foo "baa">] note funcrion matchwo(a,6){return 1;} Hello, World! ' + 1100 'company John amp;amp; Hans company title Happy title title Happy title ' + 1101 'lens Work lens lens Play lens go there a b b a h:table ' + 1102 'h:tr h:td Apples h:td h:td Bananas h:td h:tr ' + 1103 'h:table note '; 1104 expect(str1).assertEqual(str3) 1105 }) 1106 1107 /** 1108 * @tc.name: testParse003 1109 * @tc.desc: Starts parsing the XML file. 1110 */ 1111 it('testParse003', 0, function () { 1112 let strXml = 1113 '<?xml version="1.0" encoding="utf-8"?>' + 1114 '<note importance="high" logged="true">' + 1115 ' <title>Happy</title>' + 1116 ' <todo>Work</todo>' + 1117 ' <todo>Play</todo>' + 1118 '</note>'; 1119 let textEncoder = new util.TextEncoder(); 1120 let arrbuffer = textEncoder.encodeInto(strXml); 1121 let that = new xml.XmlPullParser(arrbuffer.buffer); 1122 let str = ""; 1123 function func(key, value){ 1124 str += 'key:' + key + ' value:'+ value.getColumnNumber() + ' '; 1125 return true; 1126 } 1127 let options = {supportDoctype:true, ignoreNameSpace:true, tokenValueCallbackFunction:func} 1128 that.parse(options); 1129 let result = 'key:0 value:1 key:2 value:77 key:10 value:81 key:2 value:88 key:4 value:93 ' + 1130 'key:3 value:101 key:10 value:105 key:2 value:111 key:4 value:115 key:3 value:122 key:10 value:126 ' + 1131 'key:2 value:132 key:4 value:136 key:3 value:143 key:3 value:150 key:1 value:299 '; 1132 expect(str).assertEqual(result); 1133 }) 1134 1135 /** 1136 * @tc.name: testParse004 1137 * @tc.desc: Starts parsing the XML file. 1138 */ 1139 it('testParse004', 0, function () { 1140 let strXml = 1141 '<?xml version="1.0" encoding="utf-8"?>' + 1142 '<note importance="high" logged="true">' + 1143 ' <title>Happy</title>' + 1144 ' <todo>Work</todo>' + 1145 ' <todo>Play</todo>' + 1146 '</note>'; 1147 let textEncoder = new util.TextEncoder(); 1148 let arrbuffer = textEncoder.encodeInto(strXml); 1149 let that = new xml.XmlPullParser(arrbuffer.buffer); 1150 let str = ""; 1151 function func(key, value){ 1152 str += 'key:' + key + ' value:'+ value.getDepth() + ' '; 1153 return true; 1154 } 1155 let options = {supportDoctype:true, ignoreNameSpace:true, tokenValueCallbackFunction:func} 1156 that.parse(options); 1157 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 ' + 1158 'key:10 value:1 key:2 value:2 key:4 value:2 key:3 value:2 key:10 value:1 key:2 value:2 ' + 1159 'key:4 value:2 key:3 value:2 key:3 value:1 key:1 value:0 '; 1160 expect(str).assertEqual(result); 1161 }) 1162 1163 /** 1164 * @tc.name: testParse005 1165 * @tc.desc: Starts parsing the XML file. 1166 */ 1167 it('testParse005', 0, function () { 1168 let strXml = 1169 '<?xml version="1.0" encoding="utf-8"?>' + 1170 '<note importance="high" logged="true">' + 1171 ' <title>Happy</title>' + 1172 ' <todo>Work</todo>' + 1173 ' <todo>Play</todo>' + 1174 '</note>'; 1175 let textEncoder = new util.TextEncoder(); 1176 let arrbuffer = textEncoder.encodeInto(strXml); 1177 let that = new xml.XmlPullParser(arrbuffer.buffer); 1178 let str = ""; 1179 function func(key, value){ 1180 str += 'key:'+ key + ' value:' + value.getLineNumber() + ' '; 1181 return true; 1182 } 1183 let options = {supportDoctype:true, ignoreNameSpace:true, tokenValueCallbackFunction:func} 1184 that.parse(options); 1185 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 ' + 1186 'key:10 value:1 key:2 value:1 key:4 value:1 key:3 value:1 key:10 value:1 key:2 value:1 ' + 1187 'key:4 value:1 key:3 value:1 key:3 value:1 key:1 value:1 '; 1188 expect(str).assertEqual(result); 1189 }) 1190 1191 /** 1192 * @tc.name: testParse006 1193 * @tc.desc: Starts parsing the XML file. 1194 */ 1195 it('testParse006', 0, function () { 1196 let strXml = 1197 '<?xml version="1.0" encoding="utf-8"?>' + 1198 '<note importance="high" logged="true">' + 1199 ' <title>Happy</title>' + 1200 ' <todo>Work</todo>' + 1201 ' <todo>Play</todo>' + 1202 '</note>'; 1203 let textEncoder = new util.TextEncoder(); 1204 let arrbuffer = textEncoder.encodeInto(strXml); 1205 let that = new xml.XmlPullParser(arrbuffer.buffer); 1206 let str = ""; 1207 function func(key, value){ 1208 str += 'key:' + key + ' value:' + value.getName() + ' '; 1209 return true; 1210 } 1211 let options = {supportDoctype:true, ignoreNameSpace:true, tokenValueCallbackFunction:func} 1212 that.parse(options); 1213 let result = 'key:0 value: key:2 value:note key:10 value: key:2 value:title key:4 value: ' + 1214 'key:3 value:title key:10 value: key:2 value:todo key:4 value: key:3 value:todo key:10 value: ' + 1215 'key:2 value:todo key:4 value: key:3 value:todo key:3 value:note key:1 value: '; 1216 expect(str).assertEqual(result); 1217 }) 1218 1219 /** 1220 * @tc.name: testParse007 1221 * @tc.desc: Starts parsing the XML file. 1222 */ 1223 it('testParse007', 0, function () { 1224 let strXml = 1225 '<?xml version="1.0" encoding="utf-8"?>' + 1226 '<note importance="high" logged="true">' + 1227 ' <title>Happy</title>' + 1228 ' <todo>Work</todo>' + 1229 ' <todo>Play</todo>' + 1230 '</note>'; 1231 let textEncoder = new util.TextEncoder(); 1232 let arrbuffer = textEncoder.encodeInto(strXml); 1233 let that = new xml.XmlPullParser(arrbuffer.buffer); 1234 let str = ""; 1235 function func(key, value){ 1236 str += 'key:' + key + ' value:'+ value.getNamespace() + ' '; 1237 return true; 1238 } 1239 let options = {supportDoctype:true, ignoreNameSpace:true, tokenValueCallbackFunction:func} 1240 that.parse(options); 1241 let result = 'key:0 value: key:2 value: key:10 value: key:2 value: key:4 value: key:3 value: ' + 1242 'key:10 value: key:2 value: key:4 value: key:3 value: key:10 value: key:2 value: key:4 value: ' + 1243 'key:3 value: key:3 value: key:1 value: '; 1244 expect(str).assertEqual(result); 1245 }) 1246 1247 /** 1248 * @tc.name: testParse008 1249 * @tc.desc: Starts parsing the XML file. 1250 */ 1251 it('testParse008', 0, function () { 1252 let strXml = 1253 '<?xml version="1.0" encoding="utf-8"?>' + 1254 '<note importance="high" logged="true">' + 1255 ' <title>Happy</title>' + 1256 ' <todo>Work</todo>' + 1257 ' <todo>Play</todo>' + 1258 '</note>'; 1259 let textEncoder = new util.TextEncoder(); 1260 let arrbuffer = textEncoder.encodeInto(strXml); 1261 let that = new xml.XmlPullParser(arrbuffer.buffer); 1262 let str = ""; 1263 function func(key, value){ 1264 str += 'key:'+key+' value:'+ value.getPrefix() + ' '; 1265 return true; 1266 } 1267 let options = {supportDoctype:true, ignoreNameSpace:true, tokenValueCallbackFunction:func} 1268 that.parse(options); 1269 let result = 'key:0 value: key:2 value: key:10 value: key:2 value: key:4 value: key:3 value: ' + 1270 'key:10 value: key:2 value: key:4 value: key:3 value: key:10 value: key:2 value: key:4 value: ' + 1271 'key:3 value: key:3 value: key:1 value: '; 1272 expect(str).assertEqual(result); 1273 }) 1274 1275 /** 1276 * @tc.name: testParse009 1277 * @tc.desc: Starts parsing the XML file. 1278 */ 1279 it('testParse009', 0, function () { 1280 let strXml = 1281 '<?xml version="1.0" encoding="utf-8"?>' + 1282 '<note importance="high" logged="true">' + 1283 ' <title>Happy</title>' + 1284 ' <todo>Work</todo>' + 1285 ' <todo>Play</todo>' + 1286 '</note>'; 1287 let textEncoder = new util.TextEncoder(); 1288 let arrbuffer = textEncoder.encodeInto(strXml); 1289 let that = new xml.XmlPullParser(arrbuffer.buffer); 1290 let str = ""; 1291 function func(key, value){ 1292 str += 'key:' + key +' value:' + value.getText() + ' '; 1293 return true; 1294 } 1295 let options = {supportDoctype:true, ignoreNameSpace:true, tokenValueCallbackFunction:func} 1296 that.parse(options); 1297 let result = 'key:0 value: key:2 value: key:10 value: key:2 value: key:4 value:Happy ' + 1298 'key:3 value: key:10 value: key:2 value: key:4 value:Work key:3 value: key:10 value: ' + 1299 'key:2 value: key:4 value:Play key:3 value: key:3 value: key:1 value: '; 1300 expect(str).assertEqual(result); 1301 }) 1302 1303 /** 1304 * @tc.name: testParse010 1305 * @tc.desc: Starts parsing the XML file. 1306 */ 1307 it('testParse010', 0, function () { 1308 let strXml = 1309 '<?xml version="1.0" encoding="utf-8"?>' + 1310 '<note importance="high" logged="true">' + 1311 ' <title>Happy</title>' + 1312 ' <todo>Work</todo>' + 1313 ' <todo>Play</todo>' + 1314 '</note>'; 1315 let textEncoder = new util.TextEncoder(); 1316 let arrbuffer = textEncoder.encodeInto(strXml); 1317 let that = new xml.XmlPullParser(arrbuffer.buffer); 1318 let str = ""; 1319 function func(key, value){ 1320 str += 'key:' + key +' value:' + value.isEmptyElementTag() + ' '; 1321 return true; 1322 } 1323 let options = {supportDoctype:true, ignoreNameSpace:true, tokenValueCallbackFunction:func} 1324 that.parse(options); 1325 let result = 'key:0 value:false key:2 value:false key:10 value:false key:2 value:false ' + 1326 'key:4 value:false key:3 value:false key:10 value:false key:2 value:false key:4 value:false ' + 1327 'key:3 value:false key:10 value:false key:2 value:false key:4 value:false key:3 value:false ' + 1328 'key:3 value:false key:1 value:false '; 1329 expect(str).assertEqual(result); 1330 }) 1331 1332 /** 1333 * @tc.name: testParse011 1334 * @tc.desc: Starts parsing the XML file. 1335 */ 1336 it('testParse011', 0, function () { 1337 let strXml = 1338 '<?xml version="1.0" encoding="utf-8"?>' + 1339 '<note importance="high" logged="true">' + 1340 ' <title>Happy</title>' + 1341 ' <todo>Work</todo>' + 1342 ' <todo>Play</todo>' + 1343 '</note>'; 1344 let textEncoder = new util.TextEncoder(); 1345 let arrbuffer = textEncoder.encodeInto(strXml); 1346 let that = new xml.XmlPullParser(arrbuffer.buffer); 1347 let str = ""; 1348 function func(key, value){ 1349 str += 'key:' + key +' value:' + value.isWhitespace() + ' '; 1350 return true; 1351 } 1352 let options = {supportDoctype:true, ignoreNameSpace:true, tokenValueCallbackFunction:func} 1353 that.parse(options); 1354 let result = 'key:0 value:true key:2 value:false key:10 value:true key:2 value:true ' + 1355 'key:4 value:false key:3 value:true key:10 value:true key:2 value:true key:4 value:false ' + 1356 'key:3 value:true key:10 value:true key:2 value:true key:4 value:false key:3 value:true ' + 1357 'key:3 value:true key:1 value:true '; 1358 expect(str).assertEqual(result); 1359 }) 1360 1361 /** 1362 * @tc.name: testParse012 1363 * @tc.desc: Starts parsing the XML file. 1364 */ 1365 it('testParse012', 0, function () { 1366 let strXml = 1367 '<?xml version="1.0" encoding="utf-8"?>' + 1368 '<note importance="high" logged="true">' + 1369 ' <title>Happy</title>' + 1370 ' <todo>Work</todo>' + 1371 ' <todo>Play</todo>' + 1372 '</note>'; 1373 let textEncoder = new util.TextEncoder(); 1374 let arrbuffer = textEncoder.encodeInto(strXml); 1375 let that = new xml.XmlPullParser(arrbuffer.buffer); 1376 let str = ""; 1377 function func(key, value){ 1378 str += 'key:' + key +' value:' + value.getAttributeCount() + ' '; 1379 return true; 1380 } 1381 let options = {supportDoctype:true, ignoreNameSpace:true, tokenValueCallbackFunction:func} 1382 that.parse(options); 1383 let result = 'key:0 value:0 key:2 value:2 key:10 value:0 key:2 value:0 key:4 value:0 ' + 1384 'key:3 value:0 key:10 value:0 key:2 value:0 key:4 value:0 key:3 value:0 key:10 value:0 ' + 1385 'key:2 value:0 key:4 value:0 key:3 value:0 key:3 value:0 key:1 value:0 '; 1386 expect(str).assertEqual(result); 1387 }) 1388 1389 /** 1390 * @tc.name: testEventType001 1391 * @tc.desc: Gets the START_DOCUMENT of EventType. 1392 */ 1393 it('testEventType001', 0, function () { 1394 var event = xml.EventType.START_DOCUMENT; 1395 expect(event).assertEqual(0) 1396 }) 1397 1398 /** 1399 * @tc.name: testEventType002 1400 * @tc.desc: Gets the END_DOCUMENT of EventType. 1401 */ 1402 it('testEventType002', 0, function () { 1403 var event = xml.EventType.END_DOCUMENT; 1404 expect(event).assertEqual(1) 1405 }) 1406 1407 /** 1408 * @tc.name: testEventType003 1409 * @tc.desc: Gets the START_TAG of EventType. 1410 */ 1411 it('testEventType003', 0, function () { 1412 var event = xml.EventType.START_TAG; 1413 expect(event).assertEqual(2) 1414 }) 1415 1416 /** 1417 * @tc.name: testEventType004 1418 * @tc.desc: Gets the END_TAG of EventType. 1419 */ 1420 it('testEventType004', 0, function () { 1421 var event = xml.EventType.END_TAG; 1422 expect(event).assertEqual(3) 1423 }) 1424 1425 /** 1426 * @tc.name: testEventType005 1427 * @tc.desc: Gets the TEXT of EventType. 1428 */ 1429 it('testEventType005', 0, function () { 1430 var event = xml.EventType.TEXT; 1431 expect(event).assertEqual(4) 1432 }) 1433 1434 /** 1435 * @tc.name: testEventType006 1436 * @tc.desc: Gets the CDSECT of EventType. 1437 */ 1438 it('testEventType006', 0, function () { 1439 var event = xml.EventType.CDSECT; 1440 expect(event).assertEqual(5) 1441 }) 1442 1443 /** 1444 * @tc.name: testEventType007 1445 * @tc.desc: Gets the COMMENT of EventType. 1446 */ 1447 it('testEventType007', 0, function () { 1448 var event = xml.EventType.COMMENT; 1449 expect(event).assertEqual(6) 1450 }) 1451 1452 /** 1453 * @tc.name: testEventType008 1454 * @tc.desc: Gets the DOCDECL of EventType. 1455 */ 1456 it('testEventType008', 0, function () { 1457 var event = xml.EventType.DOCDECL; 1458 expect(event).assertEqual(7) 1459 }) 1460 1461 /** 1462 * @tc.name: testEventType009 1463 * @tc.desc: Gets the INSTRUCTION of EventType. 1464 */ 1465 it('testEventType009', 0, function () { 1466 var event = xml.EventType.INSTRUCTION; 1467 expect(event).assertEqual(8) 1468 }) 1469 1470 /** 1471 * @tc.name: testEventType010 1472 * @tc.desc: Gets the ENTITY_REFERENCE of EventType. 1473 */ 1474 it('testEventType010', 0, function () { 1475 var event = xml.EventType.ENTITY_REFERENCE; 1476 expect(event).assertEqual(9) 1477 }) 1478 1479 /** 1480 * @tc.name: testEventType011 1481 * @tc.desc: Gets the WHITESPACE of EventType. 1482 */ 1483 it('testEventType011', 0, function () { 1484 var event = xml.EventType.WHITESPACE; 1485 expect(event).assertEqual(10) 1486 }) 1487 1488 /** 1489 * @tc.name: testXmlBusinessError001 1490 * @tc.desc: To XML text to JavaScript object. 1491 */ 1492 it('testXmlBusinessError001', 0, function () { 1493 try { 1494 new xml.XmlSerializer(123,"utf-8"); 1495 } catch (e) { 1496 expect(e.toString()).assertEqual("BusinessError: Parameter error.The type of 123 must be object") 1497 } 1498 }) 1499 1500 /** 1501 * @tc.name: testXmlBusinessError002 1502 * @tc.desc: To XML text to JavaScript object. 1503 */ 1504 it('testXmlBusinessError002', 0, function () { 1505 try { 1506 var arrayBuffer = new ArrayBuffer(2048); 1507 new xml.XmlSerializer(arrayBuffer,123); 1508 } catch (e) { 1509 expect(e.toString()).assertEqual("BusinessError: Parameter error.The type of 123 must be string") 1510 } 1511 }) 1512 1513 /** 1514 * @tc.name: testXmlBusinessError003 1515 * @tc.desc: To XML text to JavaScript object. 1516 */ 1517 it('testXmlBusinessError003', 0, function () { 1518 try { 1519 var arrayBuffer = new ArrayBuffer(2048); 1520 var thatSer = new xml.XmlSerializer(arrayBuffer,"utf-8"); 1521 thatSer.startElement(111); 1522 } catch (e) { 1523 expect(e.toString()).assertEqual("BusinessError: Parameter error.The type of 111 must be string") 1524 } 1525 }) 1526 1527 /** 1528 * @tc.name: testXmlBusinessError004 1529 * @tc.desc: To XML text to JavaScript object. 1530 */ 1531 it('testXmlBusinessError004', 0, function () { 1532 try { 1533 var arrayBuffer = new ArrayBuffer(2048); 1534 var thatSer = new xml.XmlSerializer(arrayBuffer,"utf-8"); 1535 thatSer.startElement("note"); 1536 thatSer.setAttributes(111, "high1"); 1537 } catch (e) { 1538 expect(e.toString()).assertEqual("BusinessError: Parameter error.The type of 111 must be string") 1539 } 1540 }) 1541 1542 /** 1543 * @tc.name: testXmlBusinessError005 1544 * @tc.desc: To XML text to JavaScript object. 1545 */ 1546 it('testXmlBusinessError005', 0, function () { 1547 try { 1548 var arrayBuffer = new ArrayBuffer(2048); 1549 var thatSer = new xml.XmlSerializer(arrayBuffer,"utf-8"); 1550 thatSer.startElement("note"); 1551 thatSer.setAttributes("importance1", 111); 1552 } catch (e) { 1553 expect(e.toString()).assertEqual("BusinessError: Parameter error.The type of 111 must be string") 1554 } 1555 }) 1556 1557 /** 1558 * @tc.name: testXmlBusinessError006 1559 * @tc.desc: To XML text to JavaScript object. 1560 */ 1561 it('testXmlBusinessError006', 0, function () { 1562 try { 1563 var arrayBuffer = new ArrayBuffer(2048); 1564 var thatSer = new xml.XmlSerializer(arrayBuffer,"utf-8"); 1565 thatSer.startElement("note"); 1566 thatSer.setAttributes("importance", "high"); 1567 thatSer.setText(111); 1568 } catch (e) { 1569 expect(e.toString()).assertEqual("BusinessError: Parameter error.The type of 111 must be string") 1570 } 1571 }) 1572 1573 /** 1574 * @tc.name: testXmlBusinessError007 1575 * @tc.desc: To XML text to JavaScript object. 1576 */ 1577 it('testXmlBusinessError007', 0, function () { 1578 try { 1579 var arrayBuffer = new ArrayBuffer(2048); 1580 var thatSer = new xml.XmlSerializer(arrayBuffer,"utf-8"); 1581 thatSer.startElement("note"); 1582 thatSer.addEmptyElement(111); 1583 } catch (e) { 1584 expect(e.toString()).assertEqual("BusinessError: Parameter error.The type of 111 must be string") 1585 } 1586 }) 1587 1588 /** 1589 * @tc.name: testXmlBusinessError008 1590 * @tc.desc: To XML text to JavaScript object. 1591 */ 1592 it('testXmlBusinessError008', 0, function () { 1593 try { 1594 var arrayBuffer = new ArrayBuffer(2048); 1595 var thatSer = new xml.XmlSerializer(arrayBuffer,"utf-8"); 1596 thatSer.setDeclaration(); 1597 thatSer.setNamespace(111, "http://www.w3.org/TR/html4/"); 1598 } catch (e) { 1599 expect(e.toString()).assertEqual("BusinessError: Parameter error.The type of 111 must be string") 1600 } 1601 }) 1602 1603 /** 1604 * @tc.name: testXmlBusinessError009 1605 * @tc.desc: To XML text to JavaScript object. 1606 */ 1607 it('testXmlBusinessError009', 0, function () { 1608 try { 1609 var arrayBuffer = new ArrayBuffer(2048); 1610 var thatSer = new xml.XmlSerializer(arrayBuffer,"utf-8"); 1611 thatSer.setDeclaration(); 1612 thatSer.setNamespace("h", 111); 1613 } catch (e) { 1614 expect(e.toString()).assertEqual("BusinessError: Parameter error.The type of 111 must be string") 1615 } 1616 }) 1617 1618 /** 1619 * @tc.name: testXmlBusinessError010 1620 * @tc.desc: To XML text to JavaScript object. 1621 */ 1622 it('testXmlBusinessError010', 0, function () { 1623 try { 1624 var arrayBuffer = new ArrayBuffer(2048); 1625 var thatSer = new xml.XmlSerializer(arrayBuffer,"utf-8"); 1626 thatSer.startElement("note"); 1627 thatSer.setComment(111); 1628 } catch (e) { 1629 expect(e.toString()).assertEqual("BusinessError: Parameter error.The type of 111 must be string") 1630 } 1631 }) 1632 1633 /** 1634 * @tc.name: testXmlBusinessError011 1635 * @tc.desc: To XML text to JavaScript object. 1636 */ 1637 it('testXmlBusinessError011', 0, function () { 1638 try { 1639 var arrayBuffer = new ArrayBuffer(2048); 1640 var thatSer = new xml.XmlSerializer(arrayBuffer,"utf-8"); 1641 thatSer.setDocType(111); 1642 } catch (e) { 1643 expect(e.toString()).assertEqual("BusinessError: Parameter error.The type of 111 must be string") 1644 } 1645 }) 1646 1647 /** 1648 * @tc.name: testXmlBusinessError012 1649 * @tc.desc: To XML text to JavaScript object. 1650 */ 1651 it('testXmlBusinessError012', 0, function () { 1652 try { 1653 var arrayBuffer = new ArrayBuffer(2048); 1654 var thatSer = new xml.XmlSerializer(arrayBuffer,"utf-8"); 1655 thatSer.setCDATA(111) 1656 } catch (e) { 1657 expect(e.toString()).assertEqual("BusinessError: Parameter error.The type of 111 must be string") 1658 } 1659 }) 1660 1661 /** 1662 * @tc.name: testXmlBusinessError013 1663 * @tc.desc: To XML text to JavaScript object. 1664 */ 1665 it('testXmlBusinessError013', 0, function () { 1666 try { 1667 new xml.XmlPullParser(111, 'UTF-8'); 1668 } catch (e) { 1669 expect(e.toString()).assertEqual("BusinessError: Parameter error.The type of 111 must be object") 1670 } 1671 }) 1672 1673 /** 1674 * @tc.name: testXmlBusinessError014 1675 * @tc.desc: To XML text to JavaScript object. 1676 */ 1677 it('testXmlBusinessError014', 0, function () { 1678 try { 1679 var arrayBuffer = new ArrayBuffer(2048); 1680 new xml.XmlPullParser(arrayBuffer, 111); 1681 } catch (e) { 1682 expect(e.toString()).assertEqual("BusinessError: Parameter error.The type of 111 must be string") 1683 } 1684 }) 1685 1686 /** 1687 * @tc.name: testXmlBusinessError015 1688 * @tc.desc: To XML text to JavaScript object. 1689 */ 1690 it('testXmlBusinessError015', 0, function () { 1691 try { 1692 var strXml = 1693 '<?xml version="1.0" encoding="utf-8"?>' + 1694 '<!DOCTYPE note [\n<!ENTITY foo "baa">]>' + 1695 '<note importance="high" logged="true">' + 1696 ' <![CDATA[\r\nfuncrion matchwo(a,6)\r\n{\r\nreturn 1;\r\n}\r\n]]>' + 1697 ' <!--Hello, World!-->' + 1698 ' <company>John & Hans</company>' + 1699 ' <title>Happy</title>' + 1700 ' <title>Happy</title>' + 1701 ' <todo>Work</todo>' + 1702 ' <todo>Play</todo>' + 1703 ' <?go there?>' + 1704 ' <a><b/></a>' + 1705 ' <h:table xmlns:h="http://www.w3.org/TR/html4/">' + 1706 ' <h:tr>' + 1707 ' <h:td>Apples</h:td>' + 1708 ' <h:td>Bananas</h:td>' + 1709 ' </h:tr>' + 1710 ' </h:table>' + 1711 '</note>'; 1712 let textEncoder = new util.TextEncoder(); 1713 let arrbuffer = textEncoder.encodeInto(strXml); 1714 let that = new xml.XmlPullParser(arrbuffer.buffer, 'UTF-8'); 1715 var str1 = ''; 1716 function func1(name, value){ 1717 str1 += name+':'+value; 1718 return true; 1719 } 1720 var options = 111 1721 that.parse(options); 1722 } catch (e) { 1723 expect(e.toString()).assertEqual("BusinessError: Parameter error.The type of 111 must be object") 1724 } 1725 }) 1726})} 1727