1 // Licensed to the .NET Foundation under one or more agreements. 2 // The .NET Foundation licenses this file to you under the MIT license. 3 // See the LICENSE file in the project root for more information. 4 5 using OLEDB.Test.ModuleCore; 6 using System.Collections.Generic; 7 using System.Globalization; 8 using System.IO; 9 using System.Text; 10 using XmlCoreTest.Common; 11 using Xunit; 12 13 namespace System.Xml.Tests 14 { 15 //[TestCase(Name = "WriteFullEndElement")] 16 public class TCFullEndElement 17 { 18 // Sanity test for WriteFullEndElement() 19 [Theory] 20 [XmlWriterInlineData] fullEndElement_1(XmlWriterUtils utils)21 public void fullEndElement_1(XmlWriterUtils utils) 22 { 23 using (XmlWriter w = utils.CreateWriter()) 24 { 25 w.WriteStartElement("Root"); 26 w.WriteFullEndElement(); 27 } 28 Assert.True(utils.CompareReader("<Root></Root>")); 29 } 30 31 // Call WriteFullEndElement before calling WriteStartElement 32 [Theory] 33 [XmlWriterInlineData] fullEndElement_2(XmlWriterUtils utils)34 public void fullEndElement_2(XmlWriterUtils utils) 35 { 36 using (XmlWriter w = utils.CreateWriter()) 37 { 38 try 39 { 40 w.WriteFullEndElement(); 41 } 42 catch (InvalidOperationException e) 43 { 44 CError.WriteLineIgnore("Exception: " + e.ToString()); 45 CError.Compare(w.WriteState, WriteState.Error, "WriteState should be Error"); 46 return; 47 } 48 } 49 CError.WriteLine("Did not throw exception"); 50 Assert.True(false); 51 } 52 53 // Call WriteFullEndElement after WriteEndElement 54 [Theory] 55 [XmlWriterInlineData] fullEndElement_3(XmlWriterUtils utils)56 public void fullEndElement_3(XmlWriterUtils utils) 57 { 58 using (XmlWriter w = utils.CreateWriter()) 59 { 60 try 61 { 62 w.WriteStartElement("Root"); 63 w.WriteEndElement(); 64 w.WriteFullEndElement(); 65 } 66 catch (InvalidOperationException e) 67 { 68 CError.WriteLineIgnore("Exception: " + e.ToString()); 69 CError.Compare(w.WriteState, WriteState.Error, "WriteState should be Error"); 70 return; 71 } 72 } 73 CError.WriteLine("Did not throw exception"); 74 Assert.True(false); 75 } 76 77 // Call WriteFullEndElement without closing attributes 78 [Theory] 79 [XmlWriterInlineData] fullEndElement_4(XmlWriterUtils utils)80 public void fullEndElement_4(XmlWriterUtils utils) 81 { 82 using (XmlWriter w = utils.CreateWriter()) 83 { 84 w.WriteStartElement("Root"); 85 w.WriteStartAttribute("a"); 86 w.WriteString("b"); 87 w.WriteFullEndElement(); 88 } 89 Assert.True(utils.CompareReader("<Root a=\"b\"></Root>")); 90 } 91 92 // Call WriteFullEndElement after WriteStartAttribute 93 [Theory] 94 [XmlWriterInlineData] fullEndElement_5(XmlWriterUtils utils)95 public void fullEndElement_5(XmlWriterUtils utils) 96 { 97 using (XmlWriter w = utils.CreateWriter()) 98 { 99 w.WriteStartElement("Root"); 100 w.WriteStartAttribute("a"); 101 w.WriteFullEndElement(); 102 } 103 Assert.True(utils.CompareReader("<Root a=\"\"></Root>")); 104 } 105 106 // WriteFullEndElement for 100 nested elements 107 [Theory] 108 [XmlWriterInlineData] fullEndElement_6(XmlWriterUtils utils)109 public void fullEndElement_6(XmlWriterUtils utils) 110 { 111 using (XmlWriter w = utils.CreateWriter()) 112 { 113 for (int i = 0; i < 100; i++) 114 { 115 string eName = "Node" + i.ToString(); 116 w.WriteStartElement(eName); 117 } 118 for (int i = 0; i < 100; i++) 119 w.WriteFullEndElement(); 120 121 w.Dispose(); 122 Assert.True(utils.CompareBaseline("100FullEndElements.txt")); 123 } 124 } 125 126 //[TestCase(Name = "Element Namespace")] 127 public partial class TCElemNamespace 128 { 129 // Multiple NS decl for same prefix on an element 130 [Theory] 131 [XmlWriterInlineData] elemNamespace_1(XmlWriterUtils utils)132 public void elemNamespace_1(XmlWriterUtils utils) 133 { 134 using (XmlWriter w = utils.CreateWriter()) 135 { 136 try 137 { 138 w.WriteStartElement("Root"); 139 w.WriteAttributeString("xmlns", "x", null, "foo"); 140 w.WriteAttributeString("xmlns", "x", null, "bar"); 141 } 142 catch (XmlException e) 143 { 144 CError.WriteLineIgnore("Exception: " + e.ToString()); 145 return; 146 } 147 } 148 CError.WriteLine("Did not throw exception"); 149 Assert.True(false); 150 } 151 152 // Multiple NS decl for same prefix (same NS value) on an element 153 [Theory] 154 [XmlWriterInlineData] elemNamespace_2(XmlWriterUtils utils)155 public void elemNamespace_2(XmlWriterUtils utils) 156 { 157 using (XmlWriter w = utils.CreateWriter()) 158 { 159 try 160 { 161 w.WriteStartElement("Root"); 162 w.WriteAttributeString("xmlns", "x", null, "foo"); 163 w.WriteAttributeString("xmlns", "x", null, "foo"); 164 w.WriteEndElement(); 165 } 166 catch (XmlException e) 167 { 168 CError.WriteLineIgnore("Exception: " + e.ToString()); 169 CError.Compare(w.WriteState, WriteState.Error, "WriteState should be Error"); 170 return; 171 } 172 } 173 CError.WriteLine("Did not throw exception"); 174 Assert.True(false); 175 } 176 177 // Element and attribute have same prefix, but different namespace value 178 [Theory] 179 [XmlWriterInlineData] elemNamespace_3(XmlWriterUtils utils)180 public void elemNamespace_3(XmlWriterUtils utils) 181 { 182 using (XmlWriter w = utils.CreateWriter()) 183 { 184 w.WriteStartElement("x", "Root", "foo"); 185 w.WriteAttributeString("x", "a", "bar", "b"); 186 w.WriteEndElement(); 187 } 188 Assert.True(utils.CompareString("<~f x a~:Root ~a p1 a~:a=\"b\" xmlns:~a p1 A~=\"bar\" xmlns:~f x A~=\"foo\" />")); 189 } 190 191 // Nested elements have same prefix, but different namespace 192 [Theory] 193 [XmlWriterInlineData] elemNamespace_4(XmlWriterUtils utils)194 public void elemNamespace_4(XmlWriterUtils utils) 195 { 196 using (XmlWriter w = utils.CreateWriter()) 197 { 198 w.WriteStartElement("x", "Root", "foo"); 199 w.WriteStartElement("x", "level1", "bar"); 200 w.WriteStartElement("x", "level2", "blah"); 201 w.WriteEndElement(); 202 w.WriteEndElement(); 203 w.WriteEndElement(); 204 } 205 Assert.True(utils.CompareReader("<x:Root xmlns:x=\"foo\"><x:level1 xmlns:x=\"bar\"><x:level2 xmlns:x=\"blah\" /></x:level1></x:Root>")); 206 } 207 208 // Mapping reserved prefix xml to invalid namespace 209 [Theory] 210 [XmlWriterInlineData] elemNamespace_5(XmlWriterUtils utils)211 public void elemNamespace_5(XmlWriterUtils utils) 212 { 213 using (XmlWriter w = utils.CreateWriter()) 214 { 215 try 216 { 217 w.WriteStartElement("xml", "Root", "blah"); 218 } 219 catch (ArgumentException e) 220 { 221 CError.WriteLineIgnore("Exception: " + e.ToString()); 222 CError.Compare(w.WriteState, WriteState.Error, "WriteState should be Error"); 223 return; 224 } 225 } 226 CError.WriteLine("Did not throw exception"); 227 Assert.True(false); 228 } 229 230 // Mapping reserved prefix xml to correct namespace 231 [Theory] 232 [XmlWriterInlineData] elemNamespace_6(XmlWriterUtils utils)233 public void elemNamespace_6(XmlWriterUtils utils) 234 { 235 using (XmlWriter w = utils.CreateWriter()) 236 { 237 w.WriteStartElement("xml", "Root", "http://www.w3.org/XML/1998/namespace"); 238 w.WriteEndElement(); 239 } 240 241 Assert.True(utils.CompareReader("<xml:Root />")); 242 } 243 244 // Write element with prefix beginning with xml 245 [Theory] 246 [XmlWriterInlineData] elemNamespace_7(XmlWriterUtils utils)247 public void elemNamespace_7(XmlWriterUtils utils) 248 { 249 using (XmlWriter w = utils.CreateWriter()) 250 { 251 w.WriteStartElement("Root"); 252 w.WriteStartElement("xmlA", "elem1", "test"); 253 w.WriteEndElement(); 254 w.WriteStartElement("xMlB", "elem2", "test"); 255 w.WriteEndElement(); 256 w.WriteEndElement(); 257 } 258 Assert.True(utils.CompareReader("<Root><xmlA:elem1 xmlns:xmlA=\"test\" /><xMlB:elem2 xmlns:xMlB=\"test\" /></Root>")); 259 } 260 261 // Reuse prefix that refers the same as default namespace 262 [Theory] 263 [XmlWriterInlineData] elemNamespace_8(XmlWriterUtils utils)264 public void elemNamespace_8(XmlWriterUtils utils) 265 { 266 using (XmlWriter w = utils.CreateWriter()) 267 { 268 w.WriteStartElement("x", "foo", "uri-1"); 269 w.WriteStartElement("", "bar", "uri-1"); 270 w.WriteStartElement("x", "bop", "uri-1"); 271 w.WriteEndElement(); 272 w.WriteEndElement(); 273 w.WriteEndElement(); 274 } 275 Assert.True(utils.CompareReader("<x:foo xmlns:x=\"uri-1\"><bar xmlns=\"uri-1\"><x:bop /></bar></x:foo>")); 276 } 277 278 // Should throw error for prefix=xmlns 279 [Theory] 280 [XmlWriterInlineData] elemNamespace_9(XmlWriterUtils utils)281 public void elemNamespace_9(XmlWriterUtils utils) 282 { 283 using (XmlWriter w = utils.CreateWriter()) 284 { 285 try 286 { 287 w.WriteStartElement("xmlns", "localname", "uri:bogus"); 288 w.WriteEndElement(); 289 } 290 catch (Exception e) 291 { 292 CError.WriteLineIgnore("Exception: " + e.ToString()); 293 CError.Compare(w.WriteState, WriteState.Error, "WriteState should be Error"); 294 return; 295 } 296 } 297 CError.WriteLine("Did not throw error"); 298 Assert.True(false); 299 } 300 301 // Create nested element without prefix but with namespace of parent element with a defined prefix 302 [Theory] 303 [XmlWriterInlineData] elemNamespace_10(XmlWriterUtils utils)304 public void elemNamespace_10(XmlWriterUtils utils) 305 { 306 using (XmlWriter w = utils.CreateWriter()) 307 { 308 w.WriteStartElement("Root"); 309 w.WriteAttributeString("xmlns", "x", null, "fo"); 310 w.WriteStartElement("level1", "fo"); 311 w.WriteEndElement(); 312 w.WriteEndElement(); 313 } 314 Assert.True(utils.CompareReader("<Root xmlns:x=\"fo\"><x:level1 /></Root>")); 315 } 316 317 // Create different prefix for element and attribute that have same namespace 318 [Theory] 319 [XmlWriterInlineData] elemNamespace_11(XmlWriterUtils utils)320 public void elemNamespace_11(XmlWriterUtils utils) 321 { 322 using (XmlWriter w = utils.CreateWriter()) 323 { 324 w.WriteStartElement("x", "Root", "foo"); 325 w.WriteAttributeString("y", "attr", "foo", "b"); 326 w.WriteEndElement(); 327 } 328 Assert.True(utils.CompareReader("<x:Root y:attr=\"b\" xmlns:y=\"foo\" xmlns:x=\"foo\" />")); 329 } 330 331 // Create same prefix for element and attribute that have same namespace 332 [Theory] 333 [XmlWriterInlineData] elemNamespace_12(XmlWriterUtils utils)334 public void elemNamespace_12(XmlWriterUtils utils) 335 { 336 using (XmlWriter w = utils.CreateWriter()) 337 { 338 w.WriteStartElement("x", "Root", "foo"); 339 w.WriteAttributeString("x", "attr", "foo", "b"); 340 w.WriteEndElement(); 341 } 342 Assert.True(utils.CompareReader("<x:Root x:attr=\"b\" xmlns:x=\"foo\" />")); 343 } 344 345 // Try to re-define NS prefix on attribute which is already defined on an element 346 [Theory] 347 [XmlWriterInlineData] elemNamespace_13(XmlWriterUtils utils)348 public void elemNamespace_13(XmlWriterUtils utils) 349 { 350 using (XmlWriter w = utils.CreateWriter()) 351 { 352 w.WriteStartElement("x", "Root", "foo"); 353 w.WriteAttributeString("x", "attr", "bar", "test"); 354 w.WriteEndElement(); 355 } 356 Assert.True(utils.CompareString("<~f x a~:Root ~a p1 a~:attr=\"test\" xmlns:~a p1 A~=\"bar\" xmlns:~f x A~=\"foo\" />")); 357 } 358 359 // Namespace string contains surrogates, reuse at different levels 360 [Theory] 361 [XmlWriterInlineData] elemNamespace_14(XmlWriterUtils utils)362 public void elemNamespace_14(XmlWriterUtils utils) 363 { 364 string uri = "urn:\uD800\uDC00"; 365 366 using (XmlWriter w = utils.CreateWriter()) 367 { 368 w.WriteStartElement("root"); 369 w.WriteAttributeString("xmlns", "pre", null, uri); 370 w.WriteElementString("elt", uri, "text"); 371 w.WriteEndElement(); 372 } 373 string strExpected = String.Format("<root xmlns:pre=\"{0}\"><pre:elt>text</pre:elt></root>", uri); 374 Assert.True(utils.CompareReader(strExpected)); 375 } 376 377 // Namespace containing entities, use at multiple levels 378 [Theory] 379 [XmlWriterInlineData] elemNamespace_15(XmlWriterUtils utils)380 public void elemNamespace_15(XmlWriterUtils utils) 381 { 382 using (XmlWriter w = utils.CreateWriter()) 383 { 384 string strxml = "<?xml version=\"1.0\" ?><root xmlns:foo=\"urn:<>\"><foo:elt1 /><foo:elt2 /><foo:elt3 /></root>"; 385 386 XmlReader xr = ReaderHelper.Create(new StringReader(strxml)); 387 w.WriteNode(xr, false); 388 xr.Dispose(); 389 } 390 Assert.True(utils.CompareReader("<root xmlns:foo=\"urn:<>\"><foo:elt1 /><foo:elt2 /><foo:elt3 /></root>")); 391 } 392 393 // Verify it resets default namespace when redefined earlier in the stack 394 [Theory] 395 [XmlWriterInlineData] elemNamespace_16(XmlWriterUtils utils)396 public void elemNamespace_16(XmlWriterUtils utils) 397 { 398 using (XmlWriter w = utils.CreateWriter()) 399 { 400 w.WriteStartElement("", "x", "foo"); 401 w.WriteAttributeString("xmlns", "foo"); 402 w.WriteStartElement("", "y", ""); 403 w.WriteStartElement("", "z", "foo"); 404 w.WriteEndElement(); 405 w.WriteEndElement(); 406 w.WriteEndElement(); 407 } 408 Assert.True(utils.CompareReader("<x xmlns=\"foo\"><y xmlns=\"\"><z xmlns=\"foo\" /></y></x>")); 409 } 410 411 // The default namespace for an element can not be changed once it is written out 412 [Theory] 413 [XmlWriterInlineData] elemNamespace_17(XmlWriterUtils utils)414 public void elemNamespace_17(XmlWriterUtils utils) 415 { 416 using (XmlWriter w = utils.CreateWriter()) 417 { 418 try 419 { 420 w.WriteStartElement("Root"); 421 w.WriteAttributeString("xmlns", null, "test"); 422 w.WriteEndElement(); 423 } 424 catch (XmlException e) 425 { 426 CError.WriteLineIgnore("Exception: " + e.ToString()); 427 CError.Compare(w.WriteState, WriteState.Error, "WriteState should be Error"); 428 return; 429 } 430 } 431 CError.WriteLine("Did not throw exception"); 432 Assert.True(false); 433 } 434 435 // Map XML NS 'http://www.w3.org/XML/1998/namaespace' to another prefix 436 [Theory] 437 [XmlWriterInlineData] elemNamespace_18(XmlWriterUtils utils)438 public void elemNamespace_18(XmlWriterUtils utils) 439 { 440 using (XmlWriter w = utils.CreateWriter()) 441 { 442 w.WriteStartElement("foo", "bar", "http://www.w3.org/XML/1998/namaespace"); 443 w.WriteEndElement(); 444 } 445 Assert.True(utils.CompareReader("<foo:bar xmlns:foo=\"http://www.w3.org/XML/1998/namaespace\" />")); 446 } 447 448 // Pass NULL as NS to WriteStartElement 449 [Theory] 450 [XmlWriterInlineData] elemNamespace_19(XmlWriterUtils utils)451 public void elemNamespace_19(XmlWriterUtils utils) 452 { 453 using (XmlWriter w = utils.CreateWriter()) 454 { 455 w.WriteStartElement("foo", "Root", "NS"); 456 w.WriteStartElement("bar", null); 457 w.WriteEndElement(); 458 w.WriteEndElement(); 459 } 460 Assert.True(utils.CompareReader("<foo:Root xmlns:foo=\"NS\"><bar /></foo:Root>")); 461 } 462 463 // Write element in reserved XML namespace, should error 464 [Theory] 465 [XmlWriterInlineData] elemNamespace_20(XmlWriterUtils utils)466 public void elemNamespace_20(XmlWriterUtils utils) 467 { 468 using (XmlWriter w = utils.CreateWriter()) 469 { 470 try 471 { 472 w.WriteStartElement("foo", "Root", "http://www.w3.org/XML/1998/namespace"); 473 } 474 catch (ArgumentException e) 475 { 476 CError.WriteLineIgnore(e.ToString()); 477 CError.Compare(w.WriteState, WriteState.Error, "WriteState should be Error"); 478 return; 479 } 480 } 481 Assert.True(false); 482 } 483 484 // Write element in reserved XMLNS namespace, should error 485 [Theory] 486 [XmlWriterInlineData] elemNamespace_21(XmlWriterUtils utils)487 public void elemNamespace_21(XmlWriterUtils utils) 488 { 489 using (XmlWriter w = utils.CreateWriter()) 490 { 491 try 492 { 493 w.WriteStartElement("foo", "Root", "http://www.w3.org/XML/1998/namespace"); 494 } 495 catch (ArgumentException e) 496 { 497 CError.WriteLineIgnore(e.ToString()); 498 CError.Compare(w.WriteState, WriteState.Error, "WriteState should be Error"); 499 return; 500 } 501 } 502 Assert.True(false); 503 } 504 505 // Mapping a prefix to empty ns should error 506 [Theory] 507 [XmlWriterInlineData] elemNamespace_22(XmlWriterUtils utils)508 public void elemNamespace_22(XmlWriterUtils utils) 509 { 510 using (XmlWriter w = utils.CreateWriter()) 511 { 512 try 513 { 514 w.WriteStartElement("pre", "test", string.Empty); 515 w.WriteEndElement(); 516 } 517 catch (ArgumentException e) 518 { 519 CError.WriteLineIgnore("Exception: " + e.ToString()); 520 CError.Compare(w.WriteState, WriteState.Error, "WriteState should be Error"); 521 return; 522 } 523 } 524 CError.WriteLine("Did not throw exception"); 525 Assert.True(false); 526 } 527 528 // Pass null prefix to WriteStartElement() 529 [Theory] 530 [XmlWriterInlineData] elemNamespace_23(XmlWriterUtils utils)531 public void elemNamespace_23(XmlWriterUtils utils) 532 { 533 using (XmlWriter w = utils.CreateWriter()) 534 { 535 w.WriteStartElement(null, "Root", "ns"); 536 w.WriteEndElement(); 537 } 538 Assert.True(utils.CompareReader("<Root xmlns='ns' />")); 539 } 540 541 // Pass String.Empty prefix to WriteStartElement() 542 [Theory] 543 [XmlWriterInlineData] elemNamespace_24(XmlWriterUtils utils)544 public void elemNamespace_24(XmlWriterUtils utils) 545 { 546 using (XmlWriter w = utils.CreateWriter()) 547 { 548 w.WriteStartElement(String.Empty, "Root", "ns"); 549 w.WriteEndElement(); 550 } 551 Assert.True(utils.CompareReader("<Root xmlns='ns' />")); 552 } 553 554 // Pass null ns to WriteStartElement() 555 [Theory] 556 [XmlWriterInlineData] elemNamespace_25(XmlWriterUtils utils)557 public void elemNamespace_25(XmlWriterUtils utils) 558 { 559 using (XmlWriter w = utils.CreateWriter()) 560 { 561 w.WriteStartElement("Root", null); 562 w.WriteEndElement(); 563 } 564 Assert.True(utils.CompareReader("<Root />")); 565 } 566 567 // Pass String.Empty ns to WriteStartElement() 568 [Theory] 569 [XmlWriterInlineData] elemNamespace_26(XmlWriterUtils utils)570 public void elemNamespace_26(XmlWriterUtils utils) 571 { 572 using (XmlWriter w = utils.CreateWriter()) 573 { 574 w.WriteStartElement("Root", String.Empty); 575 w.WriteEndElement(); 576 } 577 Assert.True(utils.CompareReader("<Root />")); 578 } 579 580 // Pass null prefix to WriteStartElement() when namespace is in scope 581 [Theory] 582 [XmlWriterInlineData] elemNamespace_27(XmlWriterUtils utils)583 public void elemNamespace_27(XmlWriterUtils utils) 584 { 585 using (XmlWriter w = utils.CreateWriter()) 586 { 587 w.WriteStartElement("pre", "Root", "ns"); 588 w.WriteElementString(null, "child", "ns", "test"); 589 w.WriteEndElement(); 590 } 591 Assert.True(utils.CompareReader("<pre:Root xmlns:pre='ns'><pre:child>test</pre:child></pre:Root>")); 592 } 593 594 // Pass String.Empty prefix to WriteStartElement() when namespace is in scope 595 [Theory] 596 [XmlWriterInlineData] elemNamespace_28(XmlWriterUtils utils)597 public void elemNamespace_28(XmlWriterUtils utils) 598 { 599 using (XmlWriter w = utils.CreateWriter()) 600 { 601 w.WriteStartElement("pre", "Root", "ns"); 602 w.WriteElementString(String.Empty, "child", "ns", "test"); 603 w.WriteEndElement(); 604 } 605 Assert.True(utils.CompareReader("<pre:Root xmlns:pre='ns'><child xmlns='ns'>test</child></pre:Root>")); 606 } 607 608 // Pass null ns to WriteStartElement() when prefix is in scope 609 [Theory] 610 [XmlWriterInlineData] elemNamespace_29(XmlWriterUtils utils)611 public void elemNamespace_29(XmlWriterUtils utils) 612 { 613 using (XmlWriter w = utils.CreateWriter()) 614 { 615 w.WriteStartElement("pre", "Root", "ns"); 616 w.WriteElementString("pre", "child", null, "test"); 617 w.WriteEndElement(); 618 } 619 Assert.True(utils.CompareReader("<pre:Root xmlns:pre='ns'><pre:child>test</pre:child></pre:Root>")); 620 } 621 622 // Pass String.Empty ns to WriteStartElement() when prefix is in scope 623 [Theory] 624 [XmlWriterInlineData] elemNamespace_30(XmlWriterUtils utils)625 public void elemNamespace_30(XmlWriterUtils utils) 626 { 627 using (XmlWriter w = utils.CreateWriter()) 628 { 629 try 630 { 631 w.WriteStartElement("pre", "Root", "ns"); 632 w.WriteElementString("pre", "child", String.Empty, "test"); 633 } 634 catch (ArgumentException) 635 { 636 return; 637 } 638 } 639 Assert.True(false); 640 } 641 642 // Pass String.Empty ns to WriteStartElement() when prefix is in scope 643 [Theory] 644 [XmlWriterInlineData] elemNamespace_31(XmlWriterUtils utils)645 public void elemNamespace_31(XmlWriterUtils utils) 646 { 647 using (XmlWriter w = utils.CreateWriter()) 648 { 649 try 650 { 651 w.WriteStartElement("pre", "Root", "ns"); 652 w.WriteElementString("pre", "child", String.Empty, "test"); 653 } 654 catch (ArgumentException) 655 { 656 return; 657 } 658 } 659 Assert.True(false); 660 } 661 662 // Mapping empty ns uri to a prefix should error 663 [Theory] 664 [XmlWriterInlineData] elemNamespace_32(XmlWriterUtils utils)665 public void elemNamespace_32(XmlWriterUtils utils) 666 { 667 using (XmlWriter w = utils.CreateWriter()) 668 { 669 try 670 { 671 w.WriteStartElement("prefix", "localname", null); 672 w.WriteEndElement(); 673 } 674 catch (ArgumentException e) 675 { 676 CError.WriteLineIgnore(e.ToString()); 677 return; 678 } 679 } 680 Assert.True(false); 681 } 682 } 683 684 //[TestCase(Name = "Attribute Namespace")] 685 public partial class TCAttrNamespace 686 { 687 // Define prefix 'xml' with invalid namespace URI 'foo' 688 [Theory] 689 [XmlWriterInlineData] attrNamespace_1(XmlWriterUtils utils)690 public void attrNamespace_1(XmlWriterUtils utils) 691 { 692 using (XmlWriter w = utils.CreateWriter()) 693 { 694 try 695 { 696 w.WriteStartElement("Root"); 697 w.WriteAttributeString("xmlns", "xml", null, "foo"); 698 } 699 catch (ArgumentException e) 700 { 701 CError.WriteLineIgnore("Exception: " + e.ToString()); 702 CError.Compare(w.WriteState, WriteState.Error, "WriteState should be Error"); 703 return; 704 } 705 } 706 CError.WriteLine("Did not throw exception"); 707 Assert.True(false); 708 } 709 710 // Bind NS prefix 'xml' with valid namespace URI 711 [Theory] 712 [XmlWriterInlineData] attrNamespace_2(XmlWriterUtils utils)713 public void attrNamespace_2(XmlWriterUtils utils) 714 { 715 using (XmlWriter w = utils.CreateWriter()) 716 { 717 w.WriteStartElement("Root"); 718 w.WriteAttributeString("xmlns", "xml", null, "http://www.w3.org/XML/1998/namespace"); 719 w.WriteEndElement(); 720 } 721 string exp = (utils.WriterType == WriterType.UnicodeWriter) ? "<Root />" : "<Root xmlns:xml=\"http://www.w3.org/XML/1998/namespace\" />"; 722 Assert.True(utils.CompareReader(exp)); 723 } 724 725 // Bind NS prefix 'xmlA' with namespace URI 'foo' 726 [Theory] 727 [XmlWriterInlineData] attrNamespace_3(XmlWriterUtils utils)728 public void attrNamespace_3(XmlWriterUtils utils) 729 { 730 using (XmlWriter w = utils.CreateWriter()) 731 { 732 w.WriteStartElement("Root"); 733 w.WriteAttributeString("xmlns", "xmlA", null, "foo"); 734 w.WriteEndElement(); 735 } 736 Assert.True(utils.CompareReader("<Root xmlns:xmlA=\"foo\" />")); 737 } 738 739 // Write attribute xml:space with correct namespace 740 [Theory] 741 [XmlWriterInlineData] attrNamespace_4(XmlWriterUtils utils)742 public void attrNamespace_4(XmlWriterUtils utils) 743 { 744 using (XmlWriter w = utils.CreateWriter()) 745 { 746 w.WriteStartElement("Root"); 747 w.WriteAttributeString("xml", "space", "http://www.w3.org/XML/1998/namespace", "default"); 748 w.WriteEndElement(); 749 } 750 Assert.True(utils.CompareReader("<Root xml:space=\"default\" />")); 751 } 752 753 // Write attribute xml:space with incorrect namespace 754 [Theory] 755 [XmlWriterInlineData] attrNamespace_5(XmlWriterUtils utils)756 public void attrNamespace_5(XmlWriterUtils utils) 757 { 758 using (XmlWriter w = utils.CreateWriter()) 759 { 760 try 761 { 762 w.WriteStartElement("Root"); 763 w.WriteAttributeString("xml", "space", "foo", "default"); 764 w.WriteEndElement(); 765 } 766 catch (ArgumentException e) 767 { 768 CError.WriteLineIgnore("Exception: " + e.ToString()); 769 CError.Compare(w.WriteState, WriteState.Error, "WriteState should be Error"); 770 return; 771 } 772 } 773 CError.WriteLine("Did not throw exception"); 774 Assert.True(false); 775 } 776 777 // Write attribute xml:lang with incorrect namespace 778 [Theory] 779 [XmlWriterInlineData] attrNamespace_6(XmlWriterUtils utils)780 public void attrNamespace_6(XmlWriterUtils utils) 781 { 782 using (XmlWriter w = utils.CreateWriter()) 783 { 784 try 785 { 786 w.WriteStartElement("Root"); 787 w.WriteAttributeString("xml", "lang", "foo", "EN"); 788 w.WriteEndElement(); 789 } 790 catch (ArgumentException e) 791 { 792 CError.WriteLineIgnore("Exception: " + e.ToString()); 793 CError.Compare(w.WriteState, WriteState.Error, "WriteState should be Error"); 794 return; 795 } 796 } 797 CError.WriteLine("Did not throw exception"); 798 Assert.True(false); 799 } 800 801 802 // WriteAttribute, define namespace attribute before value attribute 803 [Theory] 804 [XmlWriterInlineData] attrNamespace_7(XmlWriterUtils utils)805 public void attrNamespace_7(XmlWriterUtils utils) 806 { 807 using (XmlWriter w = utils.CreateWriter()) 808 { 809 w.WriteStartElement("Root"); 810 w.WriteAttributeString("xmlns", "x", null, "fo"); 811 w.WriteAttributeString("a", "fo", "b"); 812 w.WriteEndElement(); 813 } 814 Assert.True(utils.CompareReader("<Root xmlns:x=\"fo\" x:a=\"b\" />")); 815 } 816 817 // WriteAttribute, define namespace attribute after value attribute 818 [Theory] 819 [XmlWriterInlineData] attrNamespace_8(XmlWriterUtils utils)820 public void attrNamespace_8(XmlWriterUtils utils) 821 { 822 using (XmlWriter w = utils.CreateWriter()) 823 { 824 w.WriteStartElement("Root"); 825 w.WriteAttributeString("x", "a", "fo", "b"); 826 w.WriteAttributeString("xmlns", "x", null, "fo"); 827 w.WriteEndElement(); 828 } 829 Assert.True(utils.CompareReader("<Root x:a=\"b\" xmlns:x=\"fo\" />")); 830 } 831 832 // WriteAttribute, redefine prefix at different scope and use both of them 833 [Theory] 834 [XmlWriterInlineData] attrNamespace_9(XmlWriterUtils utils)835 public void attrNamespace_9(XmlWriterUtils utils) 836 { 837 using (XmlWriter w = utils.CreateWriter()) 838 { 839 w.WriteStartElement("level1"); 840 w.WriteAttributeString("xmlns", "x", null, "fo"); 841 w.WriteAttributeString("a", "fo", "b"); 842 w.WriteStartElement("level2"); 843 w.WriteAttributeString("xmlns", "x", null, "bar"); 844 w.WriteAttributeString("c", "bar", "d"); 845 w.WriteEndElement(); 846 w.WriteEndElement(); 847 } 848 Assert.True(utils.CompareReader("<level1 xmlns:x=\"fo\" x:a=\"b\"><level2 xmlns:x=\"bar\" x:c=\"d\" /></level1>")); 849 } 850 851 // WriteAttribute, redefine namespace at different scope and use both of them 852 [Theory] 853 [XmlWriterInlineData] attrNamespace_10(XmlWriterUtils utils)854 public void attrNamespace_10(XmlWriterUtils utils) 855 { 856 using (XmlWriter w = utils.CreateWriter()) 857 { 858 w.WriteStartElement("level1"); 859 w.WriteAttributeString("xmlns", "x", null, "fo"); 860 w.WriteAttributeString("a", "fo", "b"); 861 w.WriteStartElement("level2"); 862 w.WriteAttributeString("xmlns", "y", null, "fo"); 863 w.WriteAttributeString("c", "fo", "d"); 864 w.WriteEndElement(); 865 w.WriteEndElement(); 866 } 867 Assert.True(utils.CompareReader("<level1 xmlns:x=\"fo\" x:a=\"b\"><level2 xmlns:y=\"fo\" y:c=\"d\" /></level1>")); 868 } 869 870 // WriteAttribute with colliding prefix with element 871 [Theory] 872 [XmlWriterInlineData] attrNamespace_11(XmlWriterUtils utils)873 public void attrNamespace_11(XmlWriterUtils utils) 874 { 875 using (XmlWriter w = utils.CreateWriter()) 876 { 877 w.WriteStartElement("x", "Root", "fo"); 878 w.WriteAttributeString("x", "a", "bar", "b"); 879 w.WriteEndElement(); 880 } 881 Assert.True(utils.CompareString("<~f x a~:Root ~a p1 a~:a=\"b\" xmlns:~a p1 A~=\"bar\" xmlns:~f x A~=\"fo\" />")); 882 } 883 884 // WriteAttribute with colliding namespace with element 885 [Theory] 886 [XmlWriterInlineData] attrNamespace_12(XmlWriterUtils utils)887 public void attrNamespace_12(XmlWriterUtils utils) 888 { 889 using (XmlWriter w = utils.CreateWriter()) 890 { 891 w.WriteStartElement("x", "Root", "fo"); 892 w.WriteAttributeString("y", "a", "fo", "b"); 893 w.WriteEndElement(); 894 } 895 Assert.True(utils.CompareReader("<x:Root y:a=\"b\" xmlns:y=\"fo\" xmlns:x=\"fo\" />")); 896 } 897 898 // WriteAttribute with namespace but no prefix 899 [Theory] 900 [XmlWriterInlineData] attrNamespace_13(XmlWriterUtils utils)901 public void attrNamespace_13(XmlWriterUtils utils) 902 { 903 using (XmlWriter w = utils.CreateWriter()) 904 { 905 w.WriteStartElement("Root"); 906 w.WriteAttributeString("a", "fo", "b"); 907 w.WriteEndElement(); 908 } 909 Assert.True(utils.CompareString("<Root ~a p1 a~:a=\"b\" xmlns:~a p1 A~=\"fo\" />")); 910 } 911 912 // WriteAttribute for 2 attributes with same prefix but different namespace 913 [Theory] 914 [XmlWriterInlineData] attrNamespace_14(XmlWriterUtils utils)915 public void attrNamespace_14(XmlWriterUtils utils) 916 { 917 using (XmlWriter w = utils.CreateWriter()) 918 { 919 w.WriteStartElement("Root"); 920 w.WriteAttributeString("x", "a", "fo", "b"); 921 w.WriteAttributeString("x", "c", "bar", "d"); 922 w.WriteEndElement(); 923 } 924 Assert.True(utils.CompareString("<Root ~f x a~:a=\"b\" ~a p2 a~:c=\"d\" xmlns:~a p2 A~=\"bar\" xmlns:~f x A~=\"fo\" />")); 925 } 926 927 // WriteAttribute with String.Empty and null as namespace and prefix values 928 [Theory] 929 [XmlWriterInlineData] attrNamespace_15(XmlWriterUtils utils)930 public void attrNamespace_15(XmlWriterUtils utils) 931 { 932 using (XmlWriter w = utils.CreateWriter()) 933 { 934 w.WriteStartElement("Root"); 935 w.WriteAttributeString(null, "a", null, "b"); 936 w.WriteAttributeString(String.Empty, "c", String.Empty, "d"); 937 w.WriteAttributeString(null, "e", String.Empty, "f"); 938 w.WriteAttributeString(String.Empty, "g", null, "h"); 939 w.WriteEndElement(); 940 } 941 Assert.True(utils.CompareReader("<Root a=\"b\" c=\"d\" e=\"f\" g=\"h\" />")); 942 } 943 944 // WriteAttribute to manually create attribute of xmlns:x 945 [Theory] 946 [XmlWriterInlineData] attrNamespace_16(XmlWriterUtils utils)947 public void attrNamespace_16(XmlWriterUtils utils) 948 { 949 using (XmlWriter w = utils.CreateWriter()) 950 { 951 w.WriteStartElement("Root"); 952 w.WriteAttributeString("xmlns", "x", null, "test"); 953 w.WriteStartElement("x", "level1", null); 954 w.WriteEndElement(); 955 w.WriteEndElement(); 956 } 957 Assert.True(utils.CompareReader("<Root xmlns:x=\"test\"><x:level1 /></Root>")); 958 } 959 960 // WriteAttribute with namespace value = null while a prefix exists 961 [Theory] 962 [XmlWriterInlineData] attrNamespace_17(XmlWriterUtils utils)963 public void attrNamespace_17(XmlWriterUtils utils) 964 { 965 using (XmlWriter w = utils.CreateWriter()) 966 { 967 w.WriteStartElement("Root"); 968 w.WriteAttributeString("x", "a", null, "b"); 969 w.WriteEndElement(); 970 } 971 Assert.True(utils.CompareReader("<Root a=\"b\" />")); 972 } 973 974 // WriteAttribute with namespace value = String.Empty while a prefix exists 975 [Theory] 976 [XmlWriterInlineData] attrNamespace_18(XmlWriterUtils utils)977 public void attrNamespace_18(XmlWriterUtils utils) 978 { 979 using (XmlWriter w = utils.CreateWriter()) 980 { 981 w.WriteStartElement("Root"); 982 w.WriteAttributeString("x", "a", String.Empty, "b"); 983 w.WriteEndElement(); 984 } 985 Assert.True(utils.CompareReader("<Root a=\"b\" />")); 986 } 987 988 989 // WriteAttribe in nested elements with same namespace but different prefix 990 [Theory] 991 [XmlWriterInlineData] attrNamespace_19(XmlWriterUtils utils)992 public void attrNamespace_19(XmlWriterUtils utils) 993 { 994 using (XmlWriter w = utils.CreateWriter()) 995 { 996 w.WriteStartElement("Root"); 997 w.WriteAttributeString("a", "x", "fo", "y"); 998 w.WriteAttributeString("xmlns", "a", null, "fo"); 999 w.WriteStartElement("level1"); 1000 w.WriteAttributeString("b", "x", "fo", "y"); 1001 w.WriteAttributeString("xmlns", "b", null, "fo"); 1002 w.WriteStartElement("level2"); 1003 w.WriteAttributeString("c", "x", "fo", "y"); 1004 w.WriteAttributeString("xmlns", "c", null, "fo"); 1005 w.WriteEndElement(); 1006 w.WriteEndElement(); 1007 w.WriteEndElement(); 1008 } 1009 Assert.True(utils.CompareReader("<Root a:x=\"y\" xmlns:a=\"fo\"><level1 b:x=\"y\" xmlns:b=\"fo\"><level2 c:x=\"y\" xmlns:c=\"fo\" /></level1></Root>")); 1010 } 1011 1012 // WriteAttribute for x:a and xmlns:a diff namespace 1013 [Theory] 1014 [XmlWriterInlineData] attrNamespace_20(XmlWriterUtils utils)1015 public void attrNamespace_20(XmlWriterUtils utils) 1016 { 1017 using (XmlWriter w = utils.CreateWriter()) 1018 { 1019 w.WriteStartElement("Root"); 1020 w.WriteAttributeString("x", "a", "bar", "b"); 1021 w.WriteAttributeString("xmlns", "a", null, "foo"); 1022 w.WriteEndElement(); 1023 } 1024 Assert.True(utils.CompareReader("<Root x:a=\"b\" xmlns:a=\"foo\" xmlns:x=\"bar\" />")); 1025 } 1026 1027 // WriteAttribute for x:a and xmlns:a same namespace 1028 [Theory] 1029 [XmlWriterInlineData] attrNamespace_21(XmlWriterUtils utils)1030 public void attrNamespace_21(XmlWriterUtils utils) 1031 { 1032 using (XmlWriter w = utils.CreateWriter()) 1033 { 1034 w.WriteStartElement("Root"); 1035 w.WriteAttributeString("x", "a", "foo", "b"); 1036 w.WriteAttributeString("xmlns", "a", null, "foo"); 1037 w.WriteEndElement(); 1038 } 1039 Assert.True(utils.CompareReader("<Root x:a=\"b\" xmlns:a=\"foo\" xmlns:x=\"foo\" />")); 1040 } 1041 1042 // WriteAttribute with colliding NS and prefix for 2 attributes 1043 [Theory] 1044 [XmlWriterInlineData] attrNamespace_22(XmlWriterUtils utils)1045 public void attrNamespace_22(XmlWriterUtils utils) 1046 { 1047 using (XmlWriter w = utils.CreateWriter()) 1048 { 1049 w.WriteStartElement("Root"); 1050 w.WriteAttributeString("xmlns", "x", null, "foo"); 1051 w.WriteAttributeString("x", "a", "foo", "b"); 1052 w.WriteAttributeString("x", "c", "foo", "b"); 1053 w.WriteEndElement(); 1054 } 1055 Assert.True(utils.CompareReader("<Root xmlns:x=\"foo\" x:a=\"b\" x:c=\"b\" />")); 1056 } 1057 1058 // WriteAttribute with DQ in namespace 1059 [Theory] 1060 [XmlWriterInlineData] attrNamespace_23(XmlWriterUtils utils)1061 public void attrNamespace_23(XmlWriterUtils utils) 1062 { 1063 using (XmlWriter w = utils.CreateWriter()) 1064 { 1065 w.WriteStartElement("Root"); 1066 w.WriteAttributeString("a", "\"", "b"); 1067 w.WriteEndElement(); 1068 } 1069 Assert.True(utils.CompareString("<Root ~a p1 a~:a=\"b\" xmlns:~a p1 A~=\""\" />")); 1070 } 1071 1072 // Attach prefix with empty namespace 1073 [Theory] 1074 [XmlWriterInlineData] attrNamespace_24(XmlWriterUtils utils)1075 public void attrNamespace_24(XmlWriterUtils utils) 1076 { 1077 using (XmlWriter w = utils.CreateWriter()) 1078 { 1079 try 1080 { 1081 w.WriteStartElement("Root"); 1082 w.WriteAttributeString("xmlns", "foo", "bar", ""); 1083 w.WriteEndElement(); 1084 } 1085 catch (ArgumentException e) 1086 { 1087 CError.WriteLineIgnore(e.ToString()); 1088 CError.Compare(w.WriteState, WriteState.Error, "WriteState should be Error"); 1089 return; 1090 } 1091 } 1092 CError.WriteLine("Did not throw exception"); 1093 Assert.True(false); 1094 } 1095 1096 // Explicitly write namespace attribute that maps XML NS 'http://www.w3.org/XML/1998/namaespace' to another prefix 1097 [Theory] 1098 [XmlWriterInlineData] attrNamespace_25(XmlWriterUtils utils)1099 public void attrNamespace_25(XmlWriterUtils utils) 1100 { 1101 using (XmlWriter w = utils.CreateWriter()) 1102 { 1103 w.WriteStartElement("Root"); 1104 w.WriteAttributeString("xmlns", "foo", "", "http://www.w3.org/XML/1998/namaespace"); 1105 w.WriteEndElement(); 1106 } 1107 Assert.True(utils.CompareReader("<Root xmlns:foo=\"http://www.w3.org/XML/1998/namaespace\" />")); 1108 } 1109 1110 // Map XML NS 'http://www.w3.org/XML/1998/namaespace' to another prefix 1111 [Theory] 1112 [XmlWriterInlineData] attrNamespace_26(XmlWriterUtils utils)1113 public void attrNamespace_26(XmlWriterUtils utils) 1114 { 1115 using (XmlWriter w = utils.CreateWriter()) 1116 { 1117 w.WriteStartElement("Root"); 1118 w.WriteAttributeString("foo", "bar", "http://www.w3.org/XML/1998/namaespace", "test"); 1119 w.WriteEndElement(); 1120 } 1121 Assert.True(utils.CompareReader("<Root foo:bar=\"test\" xmlns:foo=\"http://www.w3.org/XML/1998/namaespace\" />")); 1122 } 1123 1124 // Pass empty namespace to WriteAttributeString(prefix, name, ns, value) 1125 [Theory] 1126 [XmlWriterInlineData] attrNamespace_27(XmlWriterUtils utils)1127 public void attrNamespace_27(XmlWriterUtils utils) 1128 { 1129 using (XmlWriter w = utils.CreateWriter()) 1130 { 1131 w.WriteStartElement("pre", "Root", "urn:pre"); 1132 w.WriteAttributeString("pre", "attr", "", "test"); 1133 w.WriteEndElement(); 1134 } 1135 Assert.True(utils.CompareReader("<pre:Root attr=\"test\" xmlns:pre=\"urn:pre\" />")); 1136 } 1137 1138 // Write attribute with prefix = xmlns 1139 [Theory] 1140 [XmlWriterInlineData] attrNamespace_28(XmlWriterUtils utils)1141 public void attrNamespace_28(XmlWriterUtils utils) 1142 { 1143 using (XmlWriter w = utils.CreateWriter()) 1144 { 1145 try 1146 { 1147 w.WriteStartElement("Root"); 1148 w.WriteAttributeString("xmlns", "xmlns", null, "test"); 1149 } 1150 catch (ArgumentException e) 1151 { 1152 CError.WriteLineIgnore(e.ToString()); 1153 CError.Compare(w.WriteState, WriteState.Error, "WriteState should be Error"); 1154 return; 1155 } 1156 } 1157 CError.WriteLine("Did not throw exception"); 1158 Assert.True(false); 1159 } 1160 1161 // Write attribute in reserved XML namespace, should error 1162 [Theory] 1163 [XmlWriterInlineData] attrNamespace_29(XmlWriterUtils utils)1164 public void attrNamespace_29(XmlWriterUtils utils) 1165 { 1166 using (XmlWriter w = utils.CreateWriter()) 1167 { 1168 try 1169 { 1170 w.WriteStartElement("foo"); 1171 w.WriteAttributeString("aaa", "bbb", "http://www.w3.org/XML/1998/namespace", "ccc"); 1172 } 1173 catch (ArgumentException e) 1174 { 1175 CError.WriteLineIgnore(e.ToString()); 1176 CError.Compare(w.WriteState, WriteState.Error, "WriteState should be Error"); 1177 return; 1178 } 1179 } 1180 Assert.True(false); 1181 } 1182 1183 // Write attribute in reserved XMLNS namespace, should error 1184 [Theory] 1185 [XmlWriterInlineData] attrNamespace_30(XmlWriterUtils utils)1186 public void attrNamespace_30(XmlWriterUtils utils) 1187 { 1188 using (XmlWriter w = utils.CreateWriter()) 1189 { 1190 try 1191 { 1192 w.WriteStartElement("foo"); 1193 w.WriteStartAttribute("aaa", "bbb", "http://www.w3.org/XML/1998/namespace"); 1194 } 1195 catch (ArgumentException e) 1196 { 1197 CError.WriteLineIgnore(e.ToString()); 1198 CError.Compare(w.WriteState, WriteState.Error, "WriteState should be Error"); 1199 return; 1200 } 1201 } 1202 Assert.True(false); 1203 } 1204 1205 // WriteAttributeString with no namespace under element with empty prefix 1206 [Theory] 1207 [XmlWriterInlineData] attrNamespace_31(XmlWriterUtils utils)1208 public void attrNamespace_31(XmlWriterUtils utils) 1209 { 1210 using (XmlWriter w = utils.CreateWriter()) 1211 { 1212 w.WriteStartElement("d", "Data", "http://example.org/data"); 1213 w.WriteStartElement("g", "GoodStuff", "http://example.org/data/good"); 1214 w.WriteAttributeString("hello", "world"); 1215 w.WriteEndElement(); 1216 w.WriteStartElement("BadStuff", "http://example.org/data/bad"); 1217 w.WriteAttributeString("hello", "world"); 1218 w.WriteEndElement(); 1219 w.WriteEndElement(); 1220 } 1221 Assert.True(utils.CompareReader("<d:Data xmlns:d=\"http://example.org/data\">" + 1222 "<g:GoodStuff hello=\"world\" xmlns:g=\"http://example.org/data/good\" />" + 1223 "<BadStuff hello=\"world\" xmlns=\"http://example.org/data/bad\" />" + 1224 "</d:Data>")); 1225 } 1226 1227 // Pass null prefix to WriteAttributeString() 1228 [Theory] 1229 [XmlWriterInlineData] attrNamespace_32(XmlWriterUtils utils)1230 public void attrNamespace_32(XmlWriterUtils utils) 1231 { 1232 using (XmlWriter w = utils.CreateWriter()) 1233 { 1234 w.WriteStartElement("Root"); 1235 w.WriteAttributeString(null, "attr", "ns", "value"); 1236 w.WriteEndElement(); 1237 } 1238 Assert.True(utils.CompareString("<Root ~a p1 a~:attr=\"value\" xmlns:~a p1 A~=\"ns\" />")); 1239 } 1240 1241 // Pass String.Empty prefix to WriteAttributeString() 1242 [Theory] 1243 [XmlWriterInlineData] attrNamespace_33(XmlWriterUtils utils)1244 public void attrNamespace_33(XmlWriterUtils utils) 1245 { 1246 using (XmlWriter w = utils.CreateWriter()) 1247 { 1248 w.WriteStartElement("Root"); 1249 w.WriteAttributeString(String.Empty, "attr", "ns", "value"); 1250 w.WriteEndElement(); 1251 } 1252 Assert.True(utils.CompareString("<Root ~a p1 a~:attr=\"value\" xmlns:~a p1 A~=\"ns\" />")); 1253 } 1254 1255 // Pass null ns to WriteAttributeString() 1256 [Theory] 1257 [XmlWriterInlineData] attrNamespace_34(XmlWriterUtils utils)1258 public void attrNamespace_34(XmlWriterUtils utils) 1259 { 1260 using (XmlWriter w = utils.CreateWriter()) 1261 { 1262 w.WriteStartElement("Root"); 1263 w.WriteAttributeString("pre", "attr", null, "value"); 1264 w.WriteEndElement(); 1265 } 1266 Assert.True(utils.CompareReader("<Root attr='value' />")); 1267 } 1268 1269 // Pass String.Empty ns to WriteAttributeString() 1270 [Theory] 1271 [XmlWriterInlineData] attrNamespace_35(XmlWriterUtils utils)1272 public void attrNamespace_35(XmlWriterUtils utils) 1273 { 1274 using (XmlWriter w = utils.CreateWriter()) 1275 { 1276 w.WriteStartElement("Root"); 1277 w.WriteAttributeString("pre", "attr", String.Empty, "value"); 1278 w.WriteEndElement(); 1279 } 1280 Assert.True(utils.CompareReader("<Root attr='value' />")); 1281 } 1282 1283 // Pass null prefix to WriteAttributeString() when namespace is in scope 1284 [Theory] 1285 [XmlWriterInlineData] attrNamespace_36(XmlWriterUtils utils)1286 public void attrNamespace_36(XmlWriterUtils utils) 1287 { 1288 using (XmlWriter w = utils.CreateWriter()) 1289 { 1290 w.WriteStartElement("pre", "Root", "ns"); 1291 w.WriteAttributeString(null, "child", "ns", "test"); 1292 w.WriteEndElement(); 1293 } 1294 Assert.True(utils.CompareReader("<pre:Root pre:child='test' xmlns:pre='ns' />")); 1295 } 1296 1297 // Pass String.Empty prefix to WriteAttributeString() when namespace is in scope 1298 [Theory] 1299 [XmlWriterInlineData] attrNamespace_37(XmlWriterUtils utils)1300 public void attrNamespace_37(XmlWriterUtils utils) 1301 { 1302 using (XmlWriter w = utils.CreateWriter()) 1303 { 1304 w.WriteStartElement("pre", "Root", "ns"); 1305 w.WriteAttributeString(String.Empty, "child", "ns", "test"); 1306 w.WriteEndElement(); 1307 } 1308 Assert.True(utils.CompareReader("<pre:Root pre:child='test' xmlns:pre='ns' />")); 1309 } 1310 1311 // Pass null ns to WriteAttributeString() when prefix is in scope 1312 [Theory] 1313 [XmlWriterInlineData] attrNamespace_38(XmlWriterUtils utils)1314 public void attrNamespace_38(XmlWriterUtils utils) 1315 { 1316 using (XmlWriter w = utils.CreateWriter()) 1317 { 1318 w.WriteStartElement("pre", "Root", "ns"); 1319 w.WriteAttributeString("pre", "child", null, "test"); 1320 w.WriteEndElement(); 1321 } 1322 Assert.True(utils.CompareReader("<pre:Root pre:child='test' xmlns:pre='ns' />")); 1323 } 1324 1325 // Pass String.Empty ns to WriteAttributeString() when prefix is in scope 1326 [Theory] 1327 [XmlWriterInlineData] attrNamespace_39(XmlWriterUtils utils)1328 public void attrNamespace_39(XmlWriterUtils utils) 1329 { 1330 using (XmlWriter w = utils.CreateWriter()) 1331 { 1332 w.WriteStartElement("pre", "Root", "ns"); 1333 w.WriteAttributeString("pre", "child", String.Empty, "test"); 1334 w.WriteEndElement(); 1335 } 1336 Assert.True(utils.CompareReader("<pre:Root child='test' xmlns:pre='ns' />")); 1337 } 1338 1339 // Mapping empty ns uri to a prefix should error 1340 [Theory] 1341 [XmlWriterInlineData] attrNamespace_40(XmlWriterUtils utils)1342 public void attrNamespace_40(XmlWriterUtils utils) 1343 { 1344 using (XmlWriter w = utils.CreateWriter()) 1345 { 1346 try 1347 { 1348 w.WriteStartElement("root"); 1349 w.WriteAttributeString("xmlns", null, null, "test"); 1350 w.WriteEndElement(); 1351 } 1352 catch (XmlException e) 1353 { 1354 CError.WriteLineIgnore(e.ToString()); 1355 return; 1356 } 1357 catch (ArgumentException e) 1358 { 1359 CError.WriteLineIgnore(e.ToString()); 1360 return; 1361 } 1362 } 1363 Assert.True(false); 1364 } 1365 1366 // WriteStartAttribute with prefix = null, localName = xmlns - case 2 1367 [Theory] 1368 [XmlWriterInlineData] attrNamespace_42(XmlWriterUtils utils)1369 public void attrNamespace_42(XmlWriterUtils utils) 1370 { 1371 using (XmlWriter w = utils.CreateWriter()) 1372 { 1373 w.WriteStartElement("pre", "foo", "ns1"); 1374 w.WriteAttributeString(null, "xmlns", "http://www.w3.org/2000/xmlns/", "ns"); 1375 w.WriteEndElement(); 1376 } 1377 Assert.True(utils.CompareReader("<pre:foo xmlns='ns' xmlns:pre='ns1' />")); 1378 } 1379 } 1380 1381 //[TestCase(Name = "WriteCData")] 1382 public partial class TCCData 1383 { 1384 // WriteCData with null 1385 [Theory] 1386 [XmlWriterInlineData] CData_1(XmlWriterUtils utils)1387 public void CData_1(XmlWriterUtils utils) 1388 { 1389 using (XmlWriter w = utils.CreateWriter()) 1390 { 1391 w.WriteStartElement("Root"); 1392 w.WriteCData(null); 1393 w.WriteEndElement(); 1394 } 1395 Assert.True(utils.CompareReader("<Root><![CDATA[]]></Root>")); 1396 } 1397 1398 // WriteCData with String.Empty 1399 [Theory] 1400 [XmlWriterInlineData] CData_2(XmlWriterUtils utils)1401 public void CData_2(XmlWriterUtils utils) 1402 { 1403 using (XmlWriter w = utils.CreateWriter()) 1404 { 1405 w.WriteStartElement("Root"); 1406 w.WriteCData(String.Empty); 1407 w.WriteEndElement(); 1408 } 1409 Assert.True(utils.CompareReader("<Root><![CDATA[]]></Root>")); 1410 } 1411 1412 // WriteCData Sanity test 1413 [Theory] 1414 [XmlWriterInlineData] CData_3(XmlWriterUtils utils)1415 public void CData_3(XmlWriterUtils utils) 1416 { 1417 using (XmlWriter w = utils.CreateWriter()) 1418 { 1419 w.WriteStartElement("Root"); 1420 w.WriteCData("This text is in a CDATA section"); 1421 w.WriteEndElement(); 1422 } 1423 Assert.True(utils.CompareReader("<Root><![CDATA[This text is in a CDATA section]]></Root>")); 1424 } 1425 1426 // WriteCData with valid surrogate pair 1427 [Theory] 1428 [XmlWriterInlineData] CData_4(XmlWriterUtils utils)1429 public void CData_4(XmlWriterUtils utils) 1430 { 1431 using (XmlWriter w = utils.CreateWriter()) 1432 { 1433 w.WriteStartElement("Root"); 1434 w.WriteCData("\uD812\uDD12"); 1435 w.WriteEndElement(); 1436 } 1437 Assert.True(utils.CompareReader("<Root><![CDATA[\uD812\uDD12]]></Root>")); 1438 } 1439 1440 // WriteCData with ]]> 1441 [Theory] 1442 [XmlWriterInlineData] CData_5(XmlWriterUtils utils)1443 public void CData_5(XmlWriterUtils utils) 1444 { 1445 using (XmlWriter w = utils.CreateWriter()) 1446 { 1447 w.WriteStartElement("Root"); 1448 w.WriteCData("test ]]> test"); 1449 w.WriteEndElement(); 1450 } 1451 Assert.True(utils.CompareReader("<Root><![CDATA[test ]]]]><![CDATA[> test]]></Root>")); 1452 } 1453 1454 // WriteCData with & < > chars, they should not be escaped 1455 [Theory] 1456 [XmlWriterInlineData] CData_6(XmlWriterUtils utils)1457 public void CData_6(XmlWriterUtils utils) 1458 { 1459 using (XmlWriter w = utils.CreateWriter()) 1460 { 1461 w.WriteStartElement("Root"); 1462 w.WriteCData("<greeting>Hello World! & Hello XML</greeting>"); 1463 w.WriteEndElement(); 1464 } 1465 Assert.True(utils.CompareReader("<Root><![CDATA[<greeting>Hello World! & Hello XML</greeting>]]></Root>")); 1466 } 1467 1468 // WriteCData with <![CDATA[ 1469 [Theory] 1470 [XmlWriterInlineData] CData_7(XmlWriterUtils utils)1471 public void CData_7(XmlWriterUtils utils) 1472 { 1473 using (XmlWriter w = utils.CreateWriter()) 1474 { 1475 w.WriteStartElement("Root"); 1476 w.WriteCData("<![CDATA["); 1477 w.WriteEndElement(); 1478 } 1479 Assert.True(utils.CompareReader("<Root><![CDATA[<![CDATA[]]></Root>")); 1480 } 1481 // CData state machine 1482 [Theory] 1483 [XmlWriterInlineData] CData_8(XmlWriterUtils utils)1484 public void CData_8(XmlWriterUtils utils) 1485 { 1486 using (XmlWriter w = utils.CreateWriter()) 1487 { 1488 w.WriteStartElement("Root"); 1489 w.WriteCData("]x]>]]x> x]x]x> x]]x]]x>"); 1490 w.WriteEndElement(); 1491 } 1492 Assert.True(utils.CompareReader("<Root><![CDATA[]x]>]]x> x]x]x> x]]x]]x>]]></Root>")); 1493 } 1494 1495 // WriteCData with invalid surrogate pair 1496 [Theory] 1497 [XmlWriterInlineData] CData_9(XmlWriterUtils utils)1498 public void CData_9(XmlWriterUtils utils) 1499 { 1500 using (XmlWriter w = utils.CreateWriter()) 1501 { 1502 try 1503 { 1504 w.WriteStartElement("Root"); 1505 w.WriteCData("\uD812"); 1506 } 1507 catch (ArgumentException e) 1508 { 1509 CError.WriteLineIgnore("Exception: " + e.ToString()); 1510 utils.CheckErrorState(w.WriteState); 1511 return; 1512 } 1513 } 1514 CError.WriteLine("Did not throw exception"); 1515 Assert.True(false); 1516 } 1517 1518 // WriteCData after root element 1519 [Theory] 1520 [XmlWriterInlineData] CData_10(XmlWriterUtils utils)1521 public void CData_10(XmlWriterUtils utils) 1522 { 1523 using (XmlWriter w = utils.CreateWriter()) 1524 { 1525 try 1526 { 1527 w.WriteStartElement("Root"); 1528 w.WriteEndElement(); 1529 w.WriteCData("foo"); 1530 } 1531 catch (InvalidOperationException e) 1532 { 1533 CError.WriteLineIgnore("Exception: " + e.ToString()); 1534 CError.Compare(w.WriteState, WriteState.Error, "WriteState should be Error"); 1535 return; 1536 } 1537 } 1538 CError.WriteLine("Did not throw exception"); 1539 Assert.True(false); 1540 } 1541 1542 // Call WriteCData twice - that should write two CData blocks 1543 [Theory] 1544 [XmlWriterInlineData] CData_11(XmlWriterUtils utils)1545 public void CData_11(XmlWriterUtils utils) 1546 { 1547 using (XmlWriter w = utils.CreateWriter()) 1548 { 1549 w.WriteStartElement("Root"); 1550 w.WriteCData("foo"); 1551 w.WriteCData("bar"); 1552 w.WriteEndElement(); 1553 } 1554 Assert.True(utils.CompareReader("<Root><![CDATA[foo]]><![CDATA[bar]]></Root>")); 1555 } 1556 1557 // WriteCData with empty string at the buffer boundary 1558 [Theory] 1559 [XmlWriterInlineData] CData_12(XmlWriterUtils utils)1560 public void CData_12(XmlWriterUtils utils) 1561 { 1562 // WriteCData with empty string when the write buffer looks like 1563 // <r>aaaaaaa.... (currently lenght is 2048 * 3 - len("<![CDATA[") 1564 int buflen = 2048 * 3; 1565 string xml1 = "<r>"; 1566 string xml3 = "<![CDATA["; 1567 int padlen = buflen - xml1.Length - xml3.Length; 1568 string xml2 = new string('a', padlen); 1569 string xml4 = "]]></r>"; 1570 string expXml = String.Format("{0}{1}{2}{3}", xml1, xml2, xml3, xml4); 1571 using (XmlWriter w = utils.CreateWriter()) 1572 { 1573 w.WriteStartElement("r"); 1574 w.WriteRaw(xml2); 1575 w.WriteCData(""); 1576 w.WriteEndElement(); 1577 } 1578 1579 Assert.True(utils.CompareReader(expXml)); 1580 } 1581 1582 [Theory] 1583 [XmlWriterInlineData(0x0d, NewLineHandling.Replace, "<r><![CDATA[\r\n]]></r>" )] 1584 [XmlWriterInlineData(0x0d, NewLineHandling.None, "<r><![CDATA[\r]]></r>" )] 1585 [XmlWriterInlineData(0x0d, NewLineHandling.Entitize, "<r><![CDATA[\r]]></r>" )] 1586 [XmlWriterInlineData(0x0a, NewLineHandling.Replace, "<r><![CDATA[\r\n]]></r>" )] 1587 [XmlWriterInlineData(0x0a, NewLineHandling.None, "<r><![CDATA[\n]]></r>" )] 1588 [XmlWriterInlineData(0x0a, NewLineHandling.Entitize, "<r><![CDATA[\n]]></r>" )] CData_13(XmlWriterUtils utils, char ch, NewLineHandling nlh, string expXml)1589 public void CData_13(XmlWriterUtils utils, char ch, NewLineHandling nlh, string expXml) 1590 { 1591 XmlWriterSettings xws = new XmlWriterSettings(); 1592 xws.OmitXmlDeclaration = true; 1593 xws.NewLineHandling = nlh; 1594 xws.NewLineChars = "\r\n"; 1595 1596 using (XmlWriter w = utils.CreateWriter(xws)) 1597 { 1598 w.WriteStartElement("r"); 1599 w.WriteCData(new string(ch, 1)); 1600 w.WriteEndElement(); 1601 } 1602 Assert.Equal(expXml, utils.GetString()); 1603 } 1604 } 1605 1606 //[TestCase(Name = "WriteComment")] 1607 public partial class TCComment 1608 { 1609 // Sanity test for WriteComment 1610 [Theory] 1611 [XmlWriterInlineData] comment_1(XmlWriterUtils utils)1612 public void comment_1(XmlWriterUtils utils) 1613 { 1614 using (XmlWriter w = utils.CreateWriter()) 1615 { 1616 w.WriteStartElement("Root"); 1617 w.WriteComment("This text is a comment"); 1618 w.WriteEndElement(); 1619 } 1620 Assert.True(utils.CompareReader("<Root><!--This text is a comment--></Root>")); 1621 } 1622 1623 // Comment value = String.Empty 1624 [Theory] 1625 [XmlWriterInlineData] comment_2(XmlWriterUtils utils)1626 public void comment_2(XmlWriterUtils utils) 1627 { 1628 using (XmlWriter w = utils.CreateWriter()) 1629 { 1630 w.WriteStartElement("Root"); 1631 w.WriteComment(String.Empty); 1632 w.WriteEndElement(); 1633 } 1634 Assert.True(utils.CompareReader("<Root><!----></Root>")); 1635 } 1636 1637 // Comment value = null 1638 [Theory] 1639 [XmlWriterInlineData] comment_3(XmlWriterUtils utils)1640 public void comment_3(XmlWriterUtils utils) 1641 { 1642 using (XmlWriter w = utils.CreateWriter()) 1643 { 1644 w.WriteStartElement("Root"); 1645 w.WriteComment(null); 1646 w.WriteEndElement(); 1647 } 1648 Assert.True(utils.CompareReader("<Root><!----></Root>")); 1649 } 1650 1651 // WriteComment with valid surrogate pair 1652 [Theory] 1653 [XmlWriterInlineData] comment_4(XmlWriterUtils utils)1654 public void comment_4(XmlWriterUtils utils) 1655 { 1656 using (XmlWriter w = utils.CreateWriter()) 1657 { 1658 w.WriteStartElement("Root"); 1659 w.WriteComment("\uD812\uDD12"); 1660 w.WriteEndElement(); 1661 } 1662 Assert.True(utils.CompareReader("<Root><!--\uD812\uDD12--></Root>")); 1663 } 1664 1665 // WriteComment with invalid surrogate pair 1666 [Theory] 1667 [XmlWriterInlineData] comment_5(XmlWriterUtils utils)1668 public void comment_5(XmlWriterUtils utils) 1669 { 1670 using (XmlWriter w = utils.CreateWriter()) 1671 { 1672 try 1673 { 1674 w.WriteStartElement("Root"); 1675 w.WriteComment("\uD812"); 1676 w.WriteEndElement(); 1677 } 1678 catch (ArgumentException e) 1679 { 1680 CError.WriteLineIgnore("Exception: " + e.ToString()); 1681 utils.CheckErrorState(w.WriteState); 1682 return; 1683 } 1684 } 1685 CError.WriteLine("Did not throw error"); 1686 Assert.True(false); 1687 } 1688 1689 // WriteComment with -- in value 1690 [Theory] 1691 [XmlWriterInlineData] comment_6(XmlWriterUtils utils)1692 public void comment_6(XmlWriterUtils utils) 1693 { 1694 using (XmlWriter w = utils.CreateWriter()) 1695 { 1696 w.WriteStartElement("Root"); 1697 w.WriteComment("test --"); 1698 w.WriteEndElement(); 1699 } 1700 Assert.True(utils.CompareReader("<Root><!--test - - --></Root>")); 1701 } 1702 } 1703 1704 //[TestCase(Name = "WriteEntityRef")] 1705 public partial class TCEntityRef 1706 { 1707 [Theory] 1708 [XmlWriterInlineData("null")] 1709 [XmlWriterInlineData("String.Empty")] 1710 [XmlWriterInlineData("test<test")] 1711 [XmlWriterInlineData("test>test")] 1712 [XmlWriterInlineData("test&test")] 1713 [XmlWriterInlineData("&test;")] 1714 [XmlWriterInlineData("test'test")] 1715 [XmlWriterInlineData("test\"test")] 1716 [XmlWriterInlineData("\xD")] 1717 [XmlWriterInlineData("\xD")] 1718 [XmlWriterInlineData("\xD\xA")] entityRef_1(XmlWriterUtils utils, string param)1719 public void entityRef_1(XmlWriterUtils utils, string param) 1720 { 1721 string temp = null; 1722 switch (param) 1723 { 1724 case "null": 1725 temp = null; 1726 break; 1727 case "String.Empty": 1728 temp = String.Empty; 1729 break; 1730 default: 1731 temp = param; 1732 break; 1733 } 1734 using (XmlWriter w = utils.CreateWriter()) 1735 { 1736 try 1737 { 1738 w.WriteStartElement("Root"); 1739 w.WriteEntityRef(temp); 1740 w.WriteEndElement(); 1741 } 1742 catch (ArgumentException e) 1743 { 1744 CError.WriteLineIgnore("Exception: " + e.ToString()); 1745 CError.Compare(w.WriteState, (utils.WriterType == WriterType.CharCheckingWriter) ? WriteState.Element : WriteState.Error, "WriteState should be Error"); 1746 return; 1747 } 1748 catch (NullReferenceException e) 1749 { 1750 CError.WriteLineIgnore("Exception: " + e.ToString()); 1751 CError.Compare(w.WriteState, (utils.WriterType == WriterType.CharCheckingWriter) ? WriteState.Element : WriteState.Error, "WriteState should be Error"); 1752 return; 1753 } 1754 } 1755 CError.WriteLine("Did not throw error"); 1756 Assert.True(false); 1757 } 1758 1759 // WriteEntityRef with entity defined in doctype 1760 [Theory] 1761 [XmlWriterInlineData] entityRef_2(XmlWriterUtils utils)1762 public void entityRef_2(XmlWriterUtils utils) 1763 { 1764 string exp = utils.IsIndent() ? 1765 "<!DOCTYPE Root [<!ENTITY e \"test\">]>" + Environment.NewLine + "<Root>&e;</Root>" : 1766 "<!DOCTYPE Root [<!ENTITY e \"test\">]><Root>&e;</Root>"; 1767 1768 using (XmlWriter w = utils.CreateWriter()) 1769 { 1770 w.WriteDocType("Root", null, null, "<!ENTITY e \"test\">"); 1771 w.WriteStartElement("Root"); 1772 w.WriteEntityRef("e"); 1773 w.WriteEndElement(); 1774 } 1775 1776 Assert.Equal(exp, utils.GetString()); 1777 } 1778 1779 // WriteEntityRef in value for xml:lang attribute 1780 [Theory] 1781 [XmlWriterInlineData] entityRef_3(XmlWriterUtils utils)1782 public void entityRef_3(XmlWriterUtils utils) 1783 { 1784 string exp = utils.IsIndent() ? 1785 "<!DOCTYPE root [<!ENTITY e \"en-us\">]>" + Environment.NewLine + "<root xml:lang=\"&e;<\" />" : 1786 "<!DOCTYPE root [<!ENTITY e \"en-us\">]><root xml:lang=\"&e;<\" />"; 1787 1788 using (XmlWriter w = utils.CreateWriter()) 1789 { 1790 w.WriteDocType("root", null, null, "<!ENTITY e \"en-us\">"); 1791 w.WriteStartElement("root"); 1792 w.WriteStartAttribute("xml", "lang", null); 1793 w.WriteEntityRef("e"); 1794 w.WriteString("<"); 1795 w.WriteEndAttribute(); 1796 w.WriteEndElement(); 1797 } 1798 1799 Assert.Equal(exp, utils.GetString()); 1800 } 1801 1802 // XmlWriter: Entity Refs are entitized twice in xml:lang attributes 1803 [Theory] 1804 [XmlWriterInlineData] var_14(XmlWriterUtils utils)1805 public void var_14(XmlWriterUtils utils) 1806 { 1807 string exp = utils.IsIndent() ? 1808 "<!DOCTYPE root [<!ENTITY e \"en-us\">]>" + Environment.NewLine + "<root xml:lang=\"&e;\" />" : 1809 "<!DOCTYPE root [<!ENTITY e \"en-us\">]><root xml:lang=\"&e;\" />"; 1810 1811 using (XmlWriter w = utils.CreateWriter()) 1812 { 1813 w.WriteDocType("root", null, null, "<!ENTITY e \"en-us\">"); 1814 w.WriteStartElement("root"); 1815 w.WriteStartAttribute("xml", "lang", null); 1816 w.WriteEntityRef("e"); 1817 w.WriteEndAttribute(); 1818 w.WriteEndElement(); 1819 } 1820 1821 Assert.Equal(exp, utils.GetString()); 1822 } 1823 } 1824 1825 //[TestCase(Name = "WriteCharEntity")] 1826 public partial class TCCharEntity 1827 { 1828 // WriteCharEntity with valid Unicode character 1829 [Theory] 1830 [XmlWriterInlineData] charEntity_1(XmlWriterUtils utils)1831 public void charEntity_1(XmlWriterUtils utils) 1832 { 1833 using (XmlWriter w = utils.CreateWriter()) 1834 { 1835 w.WriteStartElement("Root"); 1836 w.WriteStartAttribute("a"); 1837 w.WriteCharEntity('\uD23E'); 1838 w.WriteEndAttribute(); 1839 w.WriteCharEntity('\uD7FF'); 1840 w.WriteCharEntity('\uE000'); 1841 w.WriteEndElement(); 1842 } 1843 Assert.True(utils.CompareReader("<Root a=\"툾\">퟿</Root>")); 1844 } 1845 1846 // Call WriteCharEntity after WriteStartElement/WriteEndElement 1847 [Theory] 1848 [XmlWriterInlineData] charEntity_2(XmlWriterUtils utils)1849 public void charEntity_2(XmlWriterUtils utils) 1850 { 1851 using (XmlWriter w = utils.CreateWriter()) 1852 { 1853 w.WriteStartElement("Root"); 1854 w.WriteCharEntity('\uD001'); 1855 w.WriteStartElement("elem"); 1856 w.WriteCharEntity('\uF345'); 1857 w.WriteEndElement(); 1858 w.WriteCharEntity('\u0048'); 1859 w.WriteEndElement(); 1860 } 1861 Assert.True(utils.CompareReader("<Root>퀁<elem></elem>H</Root>")); 1862 } 1863 1864 // Call WriteCharEntity after WriteStartAttribute/WriteEndAttribute 1865 [Theory] 1866 [XmlWriterInlineData] charEntity_3(XmlWriterUtils utils)1867 public void charEntity_3(XmlWriterUtils utils) 1868 { 1869 using (XmlWriter w = utils.CreateWriter()) 1870 { 1871 w.WriteStartElement("Root"); 1872 w.WriteStartAttribute("a"); 1873 w.WriteCharEntity('\u1289'); 1874 w.WriteEndAttribute(); 1875 w.WriteCharEntity('\u2584'); 1876 w.WriteEndElement(); 1877 } 1878 Assert.True(utils.CompareReader("<Root a=\"኉\">▄</Root>")); 1879 } 1880 1881 // Character from low surrogate range 1882 [Theory] 1883 [XmlWriterInlineData] charEntity_4(XmlWriterUtils utils)1884 public void charEntity_4(XmlWriterUtils utils) 1885 { 1886 using (XmlWriter w = utils.CreateWriter()) 1887 { 1888 try 1889 { 1890 w.WriteStartElement("Root"); 1891 w.WriteCharEntity('\uDD12'); 1892 } 1893 catch (ArgumentException e) 1894 { 1895 CError.WriteLineIgnore("Exception: " + e.ToString()); 1896 CError.Compare(w.WriteState, WriteState.Error, "WriteState should be Error"); 1897 return; 1898 } 1899 } 1900 CError.WriteLine("Did not throw exception"); 1901 Assert.True(false); 1902 } 1903 1904 // Character from high surrogate range 1905 [Theory] 1906 [XmlWriterInlineData] charEntity_5(XmlWriterUtils utils)1907 public void charEntity_5(XmlWriterUtils utils) 1908 { 1909 using (XmlWriter w = utils.CreateWriter()) 1910 { 1911 try 1912 { 1913 w.WriteStartElement("Root"); 1914 w.WriteCharEntity('\uD812'); 1915 } 1916 catch (ArgumentException e) 1917 { 1918 CError.WriteLineIgnore("Exception: " + e.ToString()); 1919 CError.Compare(w.WriteState, WriteState.Error, "WriteState should be Error"); 1920 return; 1921 } 1922 } 1923 CError.WriteLine("Did not throw exception"); 1924 Assert.True(false); 1925 } 1926 1927 // Sanity test, pass 'a' 1928 [Theory] 1929 [XmlWriterInlineData] charEntity_7(XmlWriterUtils utils)1930 public void charEntity_7(XmlWriterUtils utils) 1931 { 1932 using (XmlWriter w = utils.CreateWriter()) 1933 { 1934 w.WriteStartElement("root"); 1935 w.WriteCharEntity('c'); 1936 w.WriteEndElement(); 1937 } 1938 string strExp = "<root>c</root>"; 1939 Assert.True(utils.CompareReader(strExp)); 1940 } 1941 1942 // WriteCharEntity for special attributes 1943 [Theory] 1944 [XmlWriterInlineData] charEntity_8(XmlWriterUtils utils)1945 public void charEntity_8(XmlWriterUtils utils) 1946 { 1947 using (XmlWriter w = utils.CreateWriter()) 1948 { 1949 w.WriteStartElement("root"); 1950 w.WriteStartAttribute("xml", "lang", null); 1951 w.WriteCharEntity('A'); 1952 w.WriteString("\n"); 1953 w.WriteEndAttribute(); 1954 w.WriteEndElement(); 1955 } 1956 Assert.True(utils.CompareReader("<root xml:lang=\"A
\" />")); 1957 } 1958 1959 // XmlWriter generates invalid XML 1960 [Theory] 1961 [XmlWriterInlineData] bug35637(XmlWriterUtils utils)1962 public void bug35637(XmlWriterUtils utils) 1963 { 1964 XmlWriterSettings settings = new XmlWriterSettings 1965 { 1966 Indent = true, 1967 IndentChars = "\t", 1968 }; 1969 1970 using (XmlWriter xw = utils.CreateWriter()) 1971 { 1972 xw.WriteStartElement("root"); 1973 for (int i = 0; i < 150; i++) 1974 { 1975 xw.WriteElementString("e", "\u00e6\u00f8\u00e5\u00e9\u00ed\u00e8\u00f9\u00f6\u00f1\u00ea\u00fb\u00ee\u00c2\u00c5\u00d8\u00f5\u00cf"); 1976 } 1977 xw.WriteElementString("end", "end"); 1978 xw.WriteEndElement(); 1979 } 1980 1981 using (XmlReader reader = utils.GetReader()) 1982 { 1983 reader.ReadToDescendant("end"); // should not throw here 1984 } 1985 1986 return; 1987 } 1988 } 1989 1990 //[TestCase(Name = "WriteSurrogateCharEntity")] 1991 public partial class TCSurrogateCharEntity 1992 { 1993 // SurrogateCharEntity after WriteStartElement/WriteEndElement 1994 [Theory] 1995 [XmlWriterInlineData] surrogateEntity_1(XmlWriterUtils utils)1996 public void surrogateEntity_1(XmlWriterUtils utils) 1997 { 1998 using (XmlWriter w = utils.CreateWriter()) 1999 { 2000 w.WriteStartElement("Root"); 2001 w.WriteSurrogateCharEntity('\uDF41', '\uD920'); 2002 w.WriteStartElement("Elem"); 2003 w.WriteSurrogateCharEntity('\uDE44', '\uDAFF'); 2004 w.WriteEndElement(); 2005 w.WriteSurrogateCharEntity('\uDC22', '\uD820'); 2006 w.WriteEndElement(); 2007 } 2008 Assert.True(utils.CompareReader("<Root>񘍁<Elem>󏹄</Elem>𘀢</Root>")); 2009 } 2010 2011 // SurrogateCharEntity after WriteStartAttribute/WriteEndAttribute 2012 [Theory] 2013 [XmlWriterInlineData] surrogateEntity_2(XmlWriterUtils utils)2014 public void surrogateEntity_2(XmlWriterUtils utils) 2015 { 2016 using (XmlWriter w = utils.CreateWriter()) 2017 { 2018 w.WriteStartElement("Root"); 2019 w.WriteStartAttribute("a"); 2020 w.WriteSurrogateCharEntity('\uDF41', '\uD920'); 2021 w.WriteEndAttribute(); 2022 w.WriteSurrogateCharEntity('\uDE44', '\uDAFF'); 2023 w.WriteEndElement(); 2024 } 2025 Assert.True(utils.CompareReader("<Root a=\"񘍁\">󏹄</Root>")); 2026 } 2027 2028 // Test with limits of surrogate range 2029 [Theory] 2030 [XmlWriterInlineData] surrogateEntity_3(XmlWriterUtils utils)2031 public void surrogateEntity_3(XmlWriterUtils utils) 2032 { 2033 using (XmlWriter w = utils.CreateWriter()) 2034 { 2035 w.WriteStartElement("Root"); 2036 w.WriteStartAttribute("a"); 2037 w.WriteSurrogateCharEntity('\uDC00', '\uD800'); 2038 w.WriteEndAttribute(); 2039 w.WriteSurrogateCharEntity('\uDFFF', '\uD800'); 2040 w.WriteSurrogateCharEntity('\uDC00', '\uDBFF'); 2041 w.WriteSurrogateCharEntity('\uDFFF', '\uDBFF'); 2042 w.WriteEndElement(); 2043 } 2044 Assert.True(utils.CompareReader("<Root a=\"𐀀\">𐏿􏰀</Root>")); 2045 } 2046 2047 // Middle surrogate character 2048 [Theory] 2049 [XmlWriterInlineData] surrogateEntity_4(XmlWriterUtils utils)2050 public void surrogateEntity_4(XmlWriterUtils utils) 2051 { 2052 using (XmlWriter w = utils.CreateWriter()) 2053 { 2054 w.WriteStartElement("Root"); 2055 w.WriteSurrogateCharEntity('\uDD12', '\uDA34'); 2056 w.WriteEndElement(); 2057 } 2058 Assert.True(utils.CompareReader("<Root>򝄒</Root>")); 2059 } 2060 2061 // Invalid high surrogate character 2062 [Theory] 2063 [XmlWriterInlineData] surrogateEntity_5(XmlWriterUtils utils)2064 public void surrogateEntity_5(XmlWriterUtils utils) 2065 { 2066 using (XmlWriter w = utils.CreateWriter()) 2067 { 2068 try 2069 { 2070 w.WriteStartElement("Root"); 2071 w.WriteSurrogateCharEntity('\uDD12', '\uDD01'); 2072 } 2073 catch (ArgumentException e) 2074 { 2075 CError.WriteLineIgnore("Exception: " + e.ToString()); 2076 CError.Compare(w.WriteState, WriteState.Error, "WriteState should be Error"); 2077 return; 2078 } 2079 } 2080 CError.WriteLine("Did not throw exception"); 2081 Assert.True(false); 2082 } 2083 2084 // Invalid low surrogate character 2085 [Theory] 2086 [XmlWriterInlineData] surrogateEntity_6(XmlWriterUtils utils)2087 public void surrogateEntity_6(XmlWriterUtils utils) 2088 { 2089 using (XmlWriter w = utils.CreateWriter()) 2090 { 2091 try 2092 { 2093 w.WriteStartElement("Root"); 2094 w.WriteSurrogateCharEntity('\u1025', '\uD900'); 2095 } 2096 catch (ArgumentException e) 2097 { 2098 CError.WriteLineIgnore("Exception: " + e.ToString()); 2099 CError.Compare(w.WriteState, WriteState.Error, "WriteState should be Error"); 2100 return; 2101 } 2102 } 2103 CError.WriteLine("Did not throw exception"); 2104 Assert.True(false); 2105 } 2106 2107 // Swap high-low surrogate characters 2108 [Theory] 2109 [XmlWriterInlineData] surrogateEntity_7(XmlWriterUtils utils)2110 public void surrogateEntity_7(XmlWriterUtils utils) 2111 { 2112 using (XmlWriter w = utils.CreateWriter()) 2113 { 2114 try 2115 { 2116 w.WriteStartElement("Root"); 2117 w.WriteSurrogateCharEntity('\uD9A2', '\uDE34'); 2118 } 2119 catch (ArgumentException e) 2120 { 2121 CError.WriteLineIgnore("Exception: " + e.ToString()); 2122 CError.Compare(w.WriteState, WriteState.Error, "WriteState should be Error"); 2123 return; 2124 } 2125 } 2126 CError.WriteLine("Did not throw exception"); 2127 Assert.True(false); 2128 } 2129 2130 // WriteSurrogateCharEntity for special attributes 2131 [Theory] 2132 [XmlWriterInlineData] surrogateEntity_8(XmlWriterUtils utils)2133 public void surrogateEntity_8(XmlWriterUtils utils) 2134 { 2135 using (XmlWriter w = utils.CreateWriter()) 2136 { 2137 w.WriteStartElement("root"); 2138 w.WriteStartAttribute("xml", "lang", null); 2139 w.WriteSurrogateCharEntity('\uDC00', '\uDBFF'); 2140 w.WriteEndAttribute(); 2141 w.WriteEndElement(); 2142 } 2143 string strExp = "<root xml:lang=\"􏰀\" />"; 2144 Assert.True(utils.CompareReader(strExp)); 2145 } 2146 } 2147 2148 //[TestCase(Name = "WriteProcessingInstruction")] 2149 public partial class TCPI 2150 { 2151 // Sanity test for WritePI 2152 [Theory] 2153 [XmlWriterInlineData] pi_1(XmlWriterUtils utils)2154 public void pi_1(XmlWriterUtils utils) 2155 { 2156 using (XmlWriter w = utils.CreateWriter()) 2157 { 2158 w.WriteStartElement("Root"); 2159 w.WriteProcessingInstruction("test", "This text is a PI"); 2160 w.WriteEndElement(); 2161 } 2162 Assert.True(utils.CompareReader("<Root><?test This text is a PI?></Root>")); 2163 } 2164 2165 // PI text value = null 2166 [Theory] 2167 [XmlWriterInlineData] pi_2(XmlWriterUtils utils)2168 public void pi_2(XmlWriterUtils utils) 2169 { 2170 using (XmlWriter w = utils.CreateWriter()) 2171 { 2172 w.WriteStartElement("Root"); 2173 w.WriteProcessingInstruction("test", null); 2174 w.WriteEndElement(); 2175 } 2176 Assert.True(utils.CompareReader("<Root><?test?></Root>")); 2177 } 2178 2179 // PI text value = String.Empty 2180 [Theory] 2181 [XmlWriterInlineData] pi_3(XmlWriterUtils utils)2182 public void pi_3(XmlWriterUtils utils) 2183 { 2184 using (XmlWriter w = utils.CreateWriter()) 2185 { 2186 w.WriteStartElement("Root"); 2187 w.WriteProcessingInstruction("test", String.Empty); 2188 w.WriteEndElement(); 2189 } 2190 Assert.True(utils.CompareReader("<Root><?test?></Root>")); 2191 } 2192 2193 // PI name = null should error 2194 [Theory] 2195 [XmlWriterInlineData] pi_4(XmlWriterUtils utils)2196 public void pi_4(XmlWriterUtils utils) 2197 { 2198 using (XmlWriter w = utils.CreateWriter()) 2199 { 2200 try 2201 { 2202 w.WriteStartElement("Root"); 2203 w.WriteProcessingInstruction(null, "test"); 2204 } 2205 catch (ArgumentException e) 2206 { 2207 CError.WriteLineIgnore("Exception: " + e.ToString()); 2208 CError.Compare(w.WriteState, WriteState.Error, "WriteState should be Error"); 2209 return; 2210 } 2211 catch (NullReferenceException e) 2212 { 2213 CError.WriteLineIgnore("Exception: " + e.ToString()); 2214 CError.Compare(w.WriteState, WriteState.Element, "WriteState should be Element "); 2215 return; 2216 } 2217 } 2218 CError.WriteLine("Did not throw exception"); 2219 Assert.True(false); 2220 } 2221 2222 // PI name = String.Empty should error 2223 [Theory] 2224 [XmlWriterInlineData] pi_5(XmlWriterUtils utils)2225 public void pi_5(XmlWriterUtils utils) 2226 { 2227 using (XmlWriter w = utils.CreateWriter()) 2228 { 2229 try 2230 { 2231 w.WriteStartElement("Root"); 2232 w.WriteProcessingInstruction(String.Empty, "test"); 2233 } 2234 catch (ArgumentException e) 2235 { 2236 CError.WriteLineIgnore("Exception: " + e.ToString()); 2237 CError.Compare(w.WriteState, (utils.WriterType == WriterType.CharCheckingWriter) ? WriteState.Element : WriteState.Error, "WriteState should be Error"); 2238 return; 2239 } 2240 } 2241 CError.WriteLine("Did not throw exception"); 2242 Assert.True(false); 2243 } 2244 2245 // WritePI with xmlns as the name value 2246 [Theory] 2247 [XmlWriterInlineData] pi_6(XmlWriterUtils utils)2248 public void pi_6(XmlWriterUtils utils) 2249 { 2250 using (XmlWriter w = utils.CreateWriter()) 2251 { 2252 w.WriteStartElement("Root"); 2253 w.WriteProcessingInstruction("xmlns", "text"); 2254 w.WriteEndElement(); 2255 } 2256 Assert.True(utils.CompareReader("<Root><?xmlns text?></Root>")); 2257 } 2258 2259 // WritePI with XmL as the name value 2260 [Theory] 2261 [XmlWriterInlineData] pi_7(XmlWriterUtils utils)2262 public void pi_7(XmlWriterUtils utils) 2263 { 2264 using (XmlWriter w = utils.CreateWriter()) 2265 { 2266 try 2267 { 2268 w.WriteStartElement("Root"); 2269 w.WriteProcessingInstruction("XmL", "text"); 2270 w.WriteEndElement(); 2271 w.Dispose(); 2272 } 2273 catch (ArgumentException e) 2274 { 2275 CError.WriteLineIgnore("Exception: " + e.ToString()); 2276 CError.Compare(w.WriteState, WriteState.Error, "WriteState should be Error"); 2277 return; 2278 } 2279 } 2280 CError.WriteLine("Did not throw exception"); 2281 Assert.True(false); 2282 } 2283 2284 // WritePI before XmlDecl 2285 [Theory] 2286 [XmlWriterInlineData] pi_8(XmlWriterUtils utils)2287 public void pi_8(XmlWriterUtils utils) 2288 { 2289 using (XmlWriter w = utils.CreateWriter()) 2290 { 2291 try 2292 { 2293 w.WriteProcessingInstruction("pi", "text"); 2294 w.WriteStartDocument(true); 2295 } 2296 catch (InvalidOperationException e) 2297 { 2298 CError.WriteLineIgnore("Exception: " + e.ToString()); 2299 CError.Compare(w.WriteState, WriteState.Error, "WriteState should be Error"); 2300 return; 2301 } 2302 } 2303 CError.WriteLine("Did not throw exception"); 2304 Assert.True(false); 2305 } 2306 2307 // WritePI (after StartDocument) with name = 'xml' text = 'version = 1.0' should error 2308 [Theory] 2309 [XmlWriterInlineData] pi_9(XmlWriterUtils utils)2310 public void pi_9(XmlWriterUtils utils) 2311 { 2312 using (XmlWriter w = utils.CreateWriter()) 2313 { 2314 try 2315 { 2316 w.WriteStartDocument(); 2317 w.WriteProcessingInstruction("xml", "version = \"1.0\""); 2318 } 2319 catch (ArgumentException e) 2320 { 2321 CError.WriteLineIgnore("Exception: " + e.ToString()); 2322 CError.Compare(w.WriteState, WriteState.Error, "WriteState should be Error"); 2323 return; 2324 } 2325 } 2326 CError.WriteLine("Did not throw exception"); 2327 Assert.True(false); 2328 } 2329 2330 // WritePI (before StartDocument) with name = 'xml' text = 'version = 1.0' should error 2331 [Theory] 2332 [XmlWriterInlineData] pi_10(XmlWriterUtils utils)2333 public void pi_10(XmlWriterUtils utils) 2334 { 2335 using (XmlWriter w = utils.CreateWriter()) 2336 { 2337 try 2338 { 2339 w.WriteProcessingInstruction("xml", "version = \"1.0\""); 2340 w.WriteStartDocument(); 2341 } 2342 catch (InvalidOperationException e) 2343 { 2344 CError.WriteLineIgnore("Exception: " + e.ToString()); 2345 CError.Compare(w.WriteState, WriteState.Error, "WriteState should be Error"); 2346 return; 2347 } 2348 } 2349 CError.WriteLine("Did not throw exception"); 2350 Assert.True(false); 2351 } 2352 2353 // Include PI end tag ?> as part of the text value 2354 [Theory] 2355 [XmlWriterInlineData] pi_11(XmlWriterUtils utils)2356 public void pi_11(XmlWriterUtils utils) 2357 { 2358 using (XmlWriter w = utils.CreateWriter()) 2359 { 2360 w.WriteStartElement("Root"); 2361 w.WriteProcessingInstruction("badpi", "text ?>"); 2362 w.WriteEndElement(); 2363 } 2364 Assert.True(utils.CompareReader("<Root><?badpi text ? >?></Root>")); 2365 } 2366 2367 // WriteProcessingInstruction with valid surrogate pair 2368 [Theory] 2369 [XmlWriterInlineData] pi_12(XmlWriterUtils utils)2370 public void pi_12(XmlWriterUtils utils) 2371 { 2372 using (XmlWriter w = utils.CreateWriter()) 2373 { 2374 w.WriteStartElement("Root"); 2375 w.WriteProcessingInstruction("pi", "\uD812\uDD12"); 2376 w.WriteEndElement(); 2377 } 2378 Assert.True(utils.CompareReader("<Root><?pi \uD812\uDD12?></Root>")); 2379 } 2380 2381 // WritePI with invalid surrogate pair 2382 [Theory] 2383 [XmlWriterInlineData] pi_13(XmlWriterUtils utils)2384 public void pi_13(XmlWriterUtils utils) 2385 { 2386 using (XmlWriter w = utils.CreateWriter()) 2387 { 2388 try 2389 { 2390 w.WriteStartElement("Root"); 2391 w.WriteProcessingInstruction("pi", "\uD812"); 2392 w.WriteEndElement(); 2393 } 2394 catch (ArgumentException e) 2395 { 2396 CError.WriteLineIgnore("Exception: " + e.ToString()); 2397 utils.CheckErrorState(w.WriteState); 2398 return; 2399 } 2400 } 2401 CError.WriteLine("Did not throw exception"); 2402 Assert.True(false); 2403 } 2404 } 2405 2406 //[TestCase(Name = "WriteNmToken")] 2407 public partial class TCWriteNmToken 2408 { 2409 [Theory] 2410 [XmlWriterInlineData("null")] 2411 [XmlWriterInlineData("String.Empty")] writeNmToken_1(XmlWriterUtils utils, string param)2412 public void writeNmToken_1(XmlWriterUtils utils, string param) 2413 { 2414 using (XmlWriter w = utils.CreateWriter()) 2415 { 2416 try 2417 { 2418 w.WriteStartElement("root"); 2419 string temp; 2420 if (param == "null") 2421 temp = null; 2422 else 2423 temp = String.Empty; 2424 w.WriteNmToken(temp); 2425 w.WriteEndElement(); 2426 } 2427 catch (ArgumentException e) 2428 { 2429 CError.WriteLineIgnore(e.ToString()); 2430 utils.CheckElementState(w.WriteState);//by design 396962 2431 return; 2432 } 2433 } 2434 CError.WriteLine("Did not throw exception"); 2435 Assert.True(false); 2436 } 2437 2438 // Sanity test, Name = foo 2439 [Theory] 2440 [XmlWriterInlineData] writeNmToken_2(XmlWriterUtils utils)2441 public void writeNmToken_2(XmlWriterUtils utils) 2442 { 2443 using (XmlWriter w = utils.CreateWriter()) 2444 { 2445 w.WriteStartElement("root"); 2446 w.WriteNmToken("foo"); 2447 w.WriteEndElement(); 2448 } 2449 Assert.True(utils.CompareReader("<root>foo</root>")); 2450 } 2451 2452 // Name contains letters, digits, . _ - : chars 2453 [Theory] 2454 [XmlWriterInlineData] writeNmToken_3(XmlWriterUtils utils)2455 public void writeNmToken_3(XmlWriterUtils utils) 2456 { 2457 using (XmlWriter w = utils.CreateWriter()) 2458 { 2459 w.WriteStartElement("root"); 2460 w.WriteNmToken("_foo:1234.bar-"); 2461 w.WriteEndElement(); 2462 } 2463 Assert.True(utils.CompareReader("<root>_foo:1234.bar-</root>")); 2464 } 2465 2466 [Theory] 2467 [XmlWriterInlineData("test test")] 2468 [XmlWriterInlineData("test?")] 2469 [XmlWriterInlineData("test'")] 2470 [XmlWriterInlineData("\"test")] writeNmToken_4(XmlWriterUtils utils, string param)2471 public void writeNmToken_4(XmlWriterUtils utils, string param) 2472 { 2473 using (XmlWriter w = utils.CreateWriter()) 2474 { 2475 try 2476 { 2477 w.WriteStartElement("root"); 2478 w.WriteNmToken(param); 2479 w.WriteEndElement(); 2480 } 2481 catch (ArgumentException e) 2482 { 2483 CError.WriteLineIgnore(e.ToString()); 2484 utils.CheckElementState(w.WriteState); 2485 return; 2486 } 2487 catch (XmlException e) 2488 { 2489 CError.WriteLineIgnore(e.ToString()); 2490 utils.CheckElementState(w.WriteState); 2491 return; 2492 } 2493 } 2494 CError.WriteLine("Did not throw exception"); 2495 Assert.True(false); 2496 } 2497 } 2498 2499 //[TestCase(Name = "WriteName")] 2500 public partial class TCWriteName 2501 { 2502 [Theory] 2503 [XmlWriterInlineData("null")] 2504 [XmlWriterInlineData("String.Empty")] writeName_1(XmlWriterUtils utils, string param)2505 public void writeName_1(XmlWriterUtils utils, string param) 2506 { 2507 using (XmlWriter w = utils.CreateWriter()) 2508 { 2509 try 2510 { 2511 w.WriteStartElement("root"); 2512 string temp; 2513 if (param == "null") 2514 temp = null; 2515 else 2516 temp = String.Empty; 2517 w.WriteName(temp); 2518 w.WriteEndElement(); 2519 } 2520 catch (ArgumentException e) 2521 { 2522 CError.WriteLineIgnore(e.ToString()); 2523 utils.CheckElementState(w.WriteState); 2524 return; 2525 } 2526 } 2527 CError.WriteLine("Did not throw exception"); 2528 Assert.True(false); 2529 } 2530 2531 // Sanity test, Name = foo 2532 [Theory] 2533 [XmlWriterInlineData] writeName_2(XmlWriterUtils utils)2534 public void writeName_2(XmlWriterUtils utils) 2535 { 2536 using (XmlWriter w = utils.CreateWriter()) 2537 { 2538 w.WriteStartElement("root"); 2539 w.WriteName("foo"); 2540 w.WriteEndElement(); 2541 } 2542 Assert.True(utils.CompareReader("<root>foo</root>")); 2543 } 2544 2545 // Sanity test, Name = foo:bar 2546 [Theory] 2547 [XmlWriterInlineData] writeName_3(XmlWriterUtils utils)2548 public void writeName_3(XmlWriterUtils utils) 2549 { 2550 using (XmlWriter w = utils.CreateWriter()) 2551 { 2552 w.WriteStartElement("root"); 2553 w.WriteName("foo:bar"); 2554 w.WriteEndElement(); 2555 } 2556 Assert.True(utils.CompareReader("<root>foo:bar</root>")); 2557 } 2558 2559 [Theory] 2560 [XmlWriterInlineData(":bar")] 2561 [XmlWriterInlineData("foo bar")] writeName_4(XmlWriterUtils utils, string param)2562 public void writeName_4(XmlWriterUtils utils, string param) 2563 { 2564 using (XmlWriter w = utils.CreateWriter()) 2565 { 2566 try 2567 { 2568 w.WriteStartElement("root"); 2569 w.WriteName(param); 2570 w.WriteEndElement(); 2571 } 2572 catch (ArgumentException e) 2573 { 2574 CError.WriteLineIgnore(e.ToString()); 2575 utils.CheckElementState(w.WriteState); 2576 return; 2577 } 2578 catch (XmlException e) 2579 { 2580 CError.WriteLineIgnore(e.ToString()); 2581 utils.CheckElementState(w.WriteState); 2582 return; 2583 } 2584 } 2585 CError.WriteLine("Did not throw exception"); 2586 Assert.True(false); 2587 } 2588 } 2589 2590 //[TestCase(Name = "WriteQualifiedName")] 2591 public partial class TCWriteQName 2592 { 2593 [Theory] 2594 [XmlWriterInlineData("null")] 2595 [XmlWriterInlineData("String.Empty")] writeQName_1(XmlWriterUtils utils, string param)2596 public void writeQName_1(XmlWriterUtils utils, string param) 2597 { 2598 using (XmlWriter w = utils.CreateWriter()) 2599 { 2600 try 2601 { 2602 w.WriteStartElement("root"); 2603 w.WriteAttributeString("xmlns", "foo", null, "test"); 2604 string temp; 2605 if (param == "null") 2606 temp = null; 2607 else 2608 temp = String.Empty; 2609 w.WriteQualifiedName(temp, "test"); 2610 w.WriteEndElement(); 2611 } 2612 catch (ArgumentException e) 2613 { 2614 CError.WriteLineIgnore(e.ToString()); 2615 CError.Compare(w.WriteState, (utils.WriterType == WriterType.CharCheckingWriter) ? WriteState.Element : WriteState.Error, "WriteState should be Error"); 2616 return; 2617 } 2618 catch (NullReferenceException e) 2619 { 2620 CError.WriteLineIgnore(e.ToString()); 2621 CError.Compare(w.WriteState, (utils.WriterType == WriterType.CharCheckingWriter) ? WriteState.Element : WriteState.Error, "WriteState should be Error"); 2622 return; 2623 } 2624 } 2625 CError.WriteLine("Did not throw exception"); 2626 Assert.True(utils.WriterType == WriterType.CustomWriter); 2627 } 2628 2629 // WriteQName with correct NS 2630 [Theory] 2631 [XmlWriterInlineData] writeQName_2(XmlWriterUtils utils)2632 public void writeQName_2(XmlWriterUtils utils) 2633 { 2634 using (XmlWriter w = utils.CreateWriter()) 2635 { 2636 w.WriteStartElement("root"); 2637 w.WriteAttributeString("xmlns", "foo", null, "test"); 2638 w.WriteQualifiedName("bar", "test"); 2639 w.WriteEndElement(); 2640 } 2641 Assert.True(utils.CompareReader("<root xmlns:foo=\"test\">foo:bar</root>")); 2642 } 2643 2644 // WriteQName when NS is auto-generated 2645 [Theory] 2646 [XmlWriterInlineData] writeQName_3(XmlWriterUtils utils)2647 public void writeQName_3(XmlWriterUtils utils) 2648 { 2649 using (XmlWriter w = utils.CreateWriter()) 2650 { 2651 w.WriteStartElement("foo", "root", "test"); 2652 w.WriteQualifiedName("bar", "test"); 2653 w.WriteEndElement(); 2654 } 2655 Assert.True(utils.CompareReader("<foo:root xmlns:foo=\"test\">foo:bar</foo:root>")); 2656 } 2657 2658 // QName = foo:bar when foo is not in scope 2659 [Theory] 2660 [XmlWriterInlineData] writeQName_4(XmlWriterUtils utils)2661 public void writeQName_4(XmlWriterUtils utils) 2662 { 2663 using (XmlWriter w = utils.CreateWriter()) 2664 { 2665 try 2666 { 2667 w.WriteStartElement("root"); 2668 w.WriteQualifiedName("bar", "foo"); 2669 w.WriteEndElement(); 2670 } 2671 catch (ArgumentException e) 2672 { 2673 CError.WriteLineIgnore(e.ToString()); 2674 if (utils.WriterType == WriterType.CustomWriter) 2675 { 2676 CError.Compare(w.WriteState, WriteState.Element, "WriteState should be Element"); 2677 } 2678 else 2679 { 2680 CError.Compare(w.WriteState, WriteState.Error, "WriteState should be Error"); 2681 } 2682 return; 2683 } 2684 } 2685 CError.WriteLine("Did not throw exception"); 2686 Assert.True(false); 2687 } 2688 2689 [Theory] 2690 [XmlWriterInlineData(":bar")] 2691 [XmlWriterInlineData("foo bar")] writeQName_5(XmlWriterUtils utils, string param)2692 public void writeQName_5(XmlWriterUtils utils, string param) 2693 { 2694 using (XmlWriter w = utils.CreateWriter()) 2695 { 2696 try 2697 { 2698 w.WriteStartElement("root"); 2699 w.WriteAttributeString("xmlns", "foo", null, "test"); 2700 w.WriteQualifiedName(param, "test"); 2701 w.WriteEndElement(); 2702 } 2703 catch (ArgumentException e) 2704 { 2705 CError.WriteLineIgnore(e.ToString()); 2706 CError.Compare(w.WriteState, (utils.WriterType == WriterType.CharCheckingWriter) ? WriteState.Element : WriteState.Error, "WriteState should be Error"); 2707 return; 2708 } 2709 } 2710 CError.WriteLine("Did not throw exception"); 2711 Assert.True(utils.WriterType == WriterType.CustomWriter); 2712 } 2713 } 2714 2715 //[TestCase(Name = "WriteChars")] 2716 public partial class TCWriteChars : TCWriteBuffer 2717 { 2718 // WriteChars with valid buffer, number, count 2719 [Theory] 2720 [XmlWriterInlineData] writeChars_1(XmlWriterUtils utils)2721 public void writeChars_1(XmlWriterUtils utils) 2722 { 2723 using (XmlWriter w = utils.CreateWriter()) 2724 { 2725 string s = "test the buffer"; 2726 char[] buf = s.ToCharArray(); 2727 w.WriteStartElement("Root"); 2728 w.WriteChars(buf, 0, 4); 2729 w.WriteEndElement(); 2730 } 2731 Assert.True(utils.CompareReader("<Root>test</Root>")); 2732 } 2733 2734 // WriteChars with & < > 2735 [Theory] 2736 [XmlWriterInlineData] writeChars_2(XmlWriterUtils utils)2737 public void writeChars_2(XmlWriterUtils utils) 2738 { 2739 using (XmlWriter w = utils.CreateWriter()) 2740 { 2741 string s = "&<>theend"; 2742 char[] buf = s.ToCharArray(); 2743 2744 w.WriteStartElement("Root"); 2745 w.WriteChars(buf, 0, 5); 2746 w.WriteEndElement(); 2747 } 2748 Assert.True(utils.CompareReader("<Root>&<>th</Root>")); 2749 } 2750 2751 // WriteChars following WriteStartAttribute 2752 [Theory] 2753 [XmlWriterInlineData] writeChars_3(XmlWriterUtils utils)2754 public void writeChars_3(XmlWriterUtils utils) 2755 { 2756 using (XmlWriter w = utils.CreateWriter()) 2757 { 2758 string s = "valid"; 2759 char[] buf = s.ToCharArray(); 2760 2761 w.WriteStartElement("Root"); 2762 w.WriteStartAttribute("a"); 2763 w.WriteChars(buf, 0, 5); 2764 w.WriteEndElement(); 2765 } 2766 Assert.True(utils.CompareReader("<Root a=\"valid\" />")); 2767 } 2768 2769 // WriteChars with entity ref included 2770 [Theory] 2771 [XmlWriterInlineData] writeChars_4(XmlWriterUtils utils)2772 public void writeChars_4(XmlWriterUtils utils) 2773 { 2774 using (XmlWriter w = utils.CreateWriter()) 2775 { 2776 string s = "this is an entity &foo;"; 2777 char[] buf = s.ToCharArray(); 2778 2779 w.WriteStartElement("Root"); 2780 w.WriteChars(buf, 0, buf.Length); 2781 w.WriteEndElement(); 2782 } 2783 Assert.True(utils.CompareReader("<Root>this is an entity &foo;</Root>")); 2784 } 2785 2786 // WriteChars with buffer = null 2787 [Theory] 2788 [XmlWriterInlineData] writeChars_5(XmlWriterUtils utils)2789 public void writeChars_5(XmlWriterUtils utils) 2790 { 2791 using (XmlWriter w = utils.CreateWriter()) 2792 { 2793 try 2794 { 2795 w.WriteStartElement("Root"); 2796 w.WriteChars(null, 0, 0); 2797 } 2798 catch (ArgumentException e) 2799 { 2800 CError.WriteLineIgnore("Exception: " + e.ToString()); 2801 CError.Compare(w.WriteState, WriteState.Error, WriteState.Element, "WriteState should be Error"); 2802 return; 2803 } 2804 } 2805 CError.WriteLine("Did not throw exception"); 2806 Assert.True(false); 2807 } 2808 2809 // WriteChars with count > buffer size 2810 [Theory] 2811 [XmlWriterInlineData] writeChars_6(XmlWriterUtils utils)2812 public void writeChars_6(XmlWriterUtils utils) 2813 { 2814 VerifyInvalidWrite(utils, "WriteChars", 5, 0, 6, typeof(ArgumentOutOfRangeException)); 2815 } 2816 2817 // WriteChars with count < 0 2818 [Theory] 2819 [XmlWriterInlineData] writeChars_7(XmlWriterUtils utils)2820 public void writeChars_7(XmlWriterUtils utils) 2821 { 2822 VerifyInvalidWrite(utils, "WriteChars", 5, 2, -1, typeof(ArgumentOutOfRangeException)); 2823 } 2824 2825 // WriteChars with index > buffer size 2826 [Theory] 2827 [XmlWriterInlineData] writeChars_8(XmlWriterUtils utils)2828 public void writeChars_8(XmlWriterUtils utils) 2829 { 2830 VerifyInvalidWrite(utils, "WriteChars", 5, 6, 1, typeof(ArgumentOutOfRangeException)); 2831 } 2832 2833 // WriteChars with index < 0 2834 [Theory] 2835 [XmlWriterInlineData] writeChars_9(XmlWriterUtils utils)2836 public void writeChars_9(XmlWriterUtils utils) 2837 { 2838 VerifyInvalidWrite(utils, "WriteChars", 5, -1, 1, typeof(ArgumentOutOfRangeException)); 2839 } 2840 2841 // WriteChars with index + count exceeds buffer 2842 [Theory] 2843 [XmlWriterInlineData] writeChars_10(XmlWriterUtils utils)2844 public void writeChars_10(XmlWriterUtils utils) 2845 { 2846 VerifyInvalidWrite(utils, "WriteChars", 5, 2, 5, typeof(ArgumentOutOfRangeException)); 2847 } 2848 2849 // WriteChars for xml:lang attribute, index = count = 0 2850 [Theory] 2851 [XmlWriterInlineData] writeChars_11(XmlWriterUtils utils)2852 public void writeChars_11(XmlWriterUtils utils) 2853 { 2854 using (XmlWriter w = utils.CreateWriter()) 2855 { 2856 string s = "en-us;"; 2857 char[] buf = s.ToCharArray(); 2858 2859 w.WriteStartElement("root"); 2860 w.WriteStartAttribute("xml", "lang", null); 2861 w.WriteChars(buf, 0, 0); 2862 w.WriteEndElement(); 2863 } 2864 Assert.True(utils.CompareReader("<root xml:lang=\"\" />")); 2865 } 2866 } 2867 2868 //[TestCase(Name = "WriteString")] 2869 public partial class TCWriteString 2870 { 2871 // WriteString(null) 2872 [Theory] 2873 [XmlWriterInlineData] writeString_1(XmlWriterUtils utils)2874 public void writeString_1(XmlWriterUtils utils) 2875 { 2876 using (XmlWriter w = utils.CreateWriter()) 2877 { 2878 w.WriteStartElement("Root"); 2879 w.WriteString(null); 2880 w.WriteEndElement(); 2881 } 2882 Assert.True(utils.CompareReader("<Root />")); 2883 } 2884 2885 // WriteString(String.Empty) 2886 [Theory] 2887 [XmlWriterInlineData] writeString_2(XmlWriterUtils utils)2888 public void writeString_2(XmlWriterUtils utils) 2889 { 2890 using (XmlWriter w = utils.CreateWriter()) 2891 { 2892 w.WriteStartElement("Root"); 2893 w.WriteString(String.Empty); 2894 w.WriteEndElement(); 2895 } 2896 Assert.True(utils.CompareReader("<Root></Root>")); 2897 } 2898 2899 // WriteString with valid surrogate pair 2900 [Theory] 2901 [XmlWriterInlineData] writeString_3(XmlWriterUtils utils)2902 public void writeString_3(XmlWriterUtils utils) 2903 { 2904 using (XmlWriter w = utils.CreateWriter()) 2905 { 2906 w.WriteStartElement("Root"); 2907 w.WriteString("\uD812\uDD12"); 2908 w.WriteEndElement(); 2909 } 2910 Assert.True(utils.CompareReader("<Root>\uD812\uDD12</Root>")); 2911 } 2912 2913 // WriteString with invalid surrogate pair 2914 [Theory] 2915 [XmlWriterInlineData] writeString_4(XmlWriterUtils utils)2916 public void writeString_4(XmlWriterUtils utils) 2917 { 2918 using (XmlWriter w = utils.CreateWriter()) 2919 { 2920 try 2921 { 2922 w.WriteStartElement("Root"); 2923 w.WriteString("\uD812"); 2924 w.WriteEndElement(); 2925 } 2926 catch (ArgumentException e) 2927 { 2928 CError.WriteLineIgnore("Exception: " + e.ToString()); 2929 utils.CheckErrorState(w.WriteState); 2930 return; 2931 } 2932 } 2933 CError.WriteLine("Did not throw exception"); 2934 Assert.True(false); 2935 } 2936 2937 // WriteString with entity reference 2938 [Theory] 2939 [XmlWriterInlineData] writeString_5(XmlWriterUtils utils)2940 public void writeString_5(XmlWriterUtils utils) 2941 { 2942 using (XmlWriter w = utils.CreateWriter()) 2943 { 2944 w.WriteStartElement("Root"); 2945 w.WriteString("&test;"); 2946 w.WriteEndElement(); 2947 } 2948 Assert.True(utils.CompareReader("<Root>&test;</Root>")); 2949 } 2950 2951 // WriteString with single/double quote, &, <, > 2952 [Theory] 2953 [XmlWriterInlineData] writeString_6(XmlWriterUtils utils)2954 public void writeString_6(XmlWriterUtils utils) 2955 { 2956 using (XmlWriter w = utils.CreateWriter()) 2957 { 2958 w.WriteStartElement("Root"); 2959 w.WriteString("' & < > \""); 2960 w.WriteEndElement(); 2961 } 2962 Assert.True(utils.CompareReader("<Root>' & < > \"</Root>")); 2963 } 2964 2965 // WriteString for value greater than x1F 2966 [Theory] 2967 [XmlWriterInlineData] writeString_9(XmlWriterUtils utils)2968 public void writeString_9(XmlWriterUtils utils) 2969 { 2970 using (XmlWriter w = utils.CreateWriter()) 2971 { 2972 w.WriteStartElement("Root"); 2973 w.WriteString(XmlConvert.ToString('\x21')); 2974 w.WriteEndElement(); 2975 } 2976 Assert.True(utils.CompareReader("<Root>!</Root>")); 2977 } 2978 2979 // WriteString with CR, LF, CR LF inside element 2980 [Theory] 2981 [XmlWriterInlineData] writeString_10(XmlWriterUtils utils)2982 public void writeString_10(XmlWriterUtils utils) 2983 { 2984 // By default NormalizeNewLines = false and NewLineChars = \r\n 2985 // So \r, \n or \r\n gets replaces by \r\n in element content 2986 using (XmlWriter w = utils.CreateWriter()) 2987 { 2988 w.WriteStartElement("Root"); 2989 w.WriteStartElement("ws1"); 2990 w.WriteString("\r"); 2991 w.WriteEndElement(); 2992 w.WriteStartElement("ws2"); 2993 w.WriteString("\n"); 2994 w.WriteEndElement(); 2995 w.WriteStartElement("ws3"); 2996 w.WriteString("\r\n"); 2997 w.WriteEndElement(); 2998 w.WriteEndElement(); 2999 } 3000 Assert.True(utils.CompareBaseline("writeStringWhiespaceInElem.txt")); 3001 } 3002 3003 // WriteString with CR, LF, CR LF inside attribute value 3004 [Theory] 3005 [XmlWriterInlineData] writeString_11(XmlWriterUtils utils)3006 public void writeString_11(XmlWriterUtils utils) 3007 { 3008 // \r, \n and \r\n gets replaced by char entities 
 
 and 
 respectively 3009 3010 using (XmlWriter w = utils.CreateWriter()) 3011 { 3012 w.WriteStartElement("Root"); 3013 w.WriteStartAttribute("attr1"); 3014 w.WriteString("\r"); 3015 w.WriteStartAttribute("attr2"); 3016 w.WriteString("\n"); 3017 w.WriteStartAttribute("attr3"); 3018 w.WriteString("\r\n"); 3019 w.WriteEndElement(); 3020 } 3021 Assert.True(utils.CompareBaseline("writeStringWhiespaceInAttr.txt")); 3022 } 3023 3024 // Call WriteString for LF inside attribute 3025 [Theory] 3026 [XmlWriterInlineData] writeString_12(XmlWriterUtils utils)3027 public void writeString_12(XmlWriterUtils utils) 3028 { 3029 using (XmlWriter w = utils.CreateWriter()) 3030 { 3031 w.WriteStartElement("Root", ""); 3032 w.WriteStartAttribute("a1", ""); 3033 w.WriteString("x\ny"); 3034 w.WriteEndElement(); 3035 } 3036 Assert.True(utils.CompareReader("<Root a1=\"x
y\" />")); 3037 } 3038 3039 // Surrogate characters in text nodes, range limits 3040 [Theory] 3041 [XmlWriterInlineData] writeString_13(XmlWriterUtils utils)3042 public void writeString_13(XmlWriterUtils utils) 3043 { 3044 char[] invalidXML = { '\uD800', '\uDC00', '\uD800', '\uDFFF', '\uDBFF', '\uDC00', '\uDBFF', '\uDFFF' }; 3045 string invXML = new String(invalidXML); 3046 3047 using (XmlWriter w = utils.CreateWriter()) 3048 { 3049 w.WriteStartElement("Root"); 3050 w.WriteString(invXML); 3051 w.WriteEndElement(); 3052 } 3053 Assert.True(utils.CompareReader("<Root>\uD800\uDC00\uD800\uDFFF\uDBFF\uDC00\uDBFF\uDFFF</Root>")); 3054 } 3055 3056 // High surrogate on last position 3057 [Theory] 3058 [XmlWriterInlineData] writeString_14(XmlWriterUtils utils)3059 public void writeString_14(XmlWriterUtils utils) 3060 { 3061 char[] invalidXML = { 'a', 'b', '\uDA34' }; 3062 string invXML = new String(invalidXML); 3063 3064 using (XmlWriter w = utils.CreateWriter()) 3065 { 3066 try 3067 { 3068 w.WriteStartElement("Root"); 3069 w.WriteString(invXML); 3070 } 3071 catch (ArgumentException e) 3072 { 3073 CError.WriteLineIgnore("Exception: " + e.ToString()); 3074 utils.CheckErrorState(w.WriteState); 3075 return; 3076 } 3077 } 3078 CError.WriteLine("Did not throw exception"); 3079 Assert.True(false); 3080 } 3081 3082 // Low surrogate on first position 3083 [Theory] 3084 [XmlWriterInlineData] writeString_15(XmlWriterUtils utils)3085 public void writeString_15(XmlWriterUtils utils) 3086 { 3087 char[] invalidXML = { '\uDF20', 'b', 'c' }; 3088 string invXML = new String(invalidXML); 3089 3090 using (XmlWriter w = utils.CreateWriter()) 3091 { 3092 try 3093 { 3094 w.WriteStartElement("Root"); 3095 w.WriteString(invXML); 3096 } 3097 catch (ArgumentException e) 3098 { 3099 CError.WriteLineIgnore("Exception: " + e.ToString()); 3100 utils.CheckErrorState(w.WriteState); 3101 return; 3102 } 3103 } 3104 CError.WriteLine("Did not throw exception"); 3105 Assert.True(false); 3106 } 3107 3108 // Swap low-high surrogates 3109 [Theory] 3110 [XmlWriterInlineData] writeString_16(XmlWriterUtils utils)3111 public void writeString_16(XmlWriterUtils utils) 3112 { 3113 char[] invalidXML = { 'a', '\uDE40', '\uDA72', 'c' }; 3114 string invXML = new String(invalidXML); 3115 3116 using (XmlWriter w = utils.CreateWriter()) 3117 { 3118 try 3119 { 3120 w.WriteStartElement("Root"); 3121 w.WriteString(invXML); 3122 } 3123 catch (ArgumentException e) 3124 { 3125 CError.WriteLineIgnore("Exception: " + e.ToString()); 3126 utils.CheckErrorState(w.WriteState); 3127 return; 3128 } 3129 } 3130 CError.WriteLine("Did not throw exception"); 3131 Assert.True(false); 3132 } 3133 } 3134 3135 //[TestCase(Name = "WriteWhitespace")] 3136 public partial class TCWhiteSpace 3137 { 3138 // WriteWhitespace with values #x20 #x9 #xD #xA 3139 [Theory] 3140 [XmlWriterInlineData] whitespace_1(XmlWriterUtils utils)3141 public void whitespace_1(XmlWriterUtils utils) 3142 { 3143 using (XmlWriter w = utils.CreateWriter()) 3144 { 3145 w.WriteStartElement("Root"); 3146 w.WriteString("text"); 3147 w.WriteWhitespace("\x20"); 3148 w.WriteString("text"); 3149 w.WriteWhitespace("\x9"); 3150 w.WriteString("text"); 3151 w.WriteWhitespace("\xD"); 3152 w.WriteString("text"); 3153 w.WriteWhitespace("\xA"); 3154 w.WriteString("text"); 3155 w.WriteEndElement(); 3156 } 3157 Assert.True(utils.CompareBaseline("whitespace1.txt")); 3158 } 3159 3160 // WriteWhitespace in the middle of text 3161 [Theory] 3162 [XmlWriterInlineData] whitespace_2(XmlWriterUtils utils)3163 public void whitespace_2(XmlWriterUtils utils) 3164 { 3165 using (XmlWriter w = utils.CreateWriter()) 3166 { 3167 w.WriteStartElement("Root"); 3168 w.WriteString("text"); 3169 w.WriteWhitespace("\xD"); 3170 w.WriteString("text"); 3171 w.WriteEndElement(); 3172 } 3173 Assert.True(utils.CompareBaseline("whitespace2.txt")); 3174 } 3175 3176 // WriteWhitespace before and after root element 3177 [Theory] 3178 [XmlWriterInlineData] whitespace_3(XmlWriterUtils utils)3179 public void whitespace_3(XmlWriterUtils utils) 3180 { 3181 using (XmlWriter w = utils.CreateWriter()) 3182 { 3183 w.WriteStartDocument(); 3184 w.WriteWhitespace("\x20"); 3185 w.WriteStartElement("Root"); 3186 w.WriteEndElement(); 3187 w.WriteWhitespace("\x20"); 3188 w.WriteEndDocument(); 3189 } 3190 Assert.True(utils.CompareBaseline("whitespace3.txt")); 3191 } 3192 3193 [Theory] 3194 [XmlWriterInlineData("null")] 3195 [XmlWriterInlineData("String.Empty")] whitespace_4(XmlWriterUtils utils, string param)3196 public void whitespace_4(XmlWriterUtils utils, string param) 3197 { 3198 using (XmlWriter w = utils.CreateWriter()) 3199 { 3200 string temp; 3201 if (param == "null") 3202 temp = null; 3203 else 3204 temp = String.Empty; 3205 w.WriteStartElement("Root"); 3206 3207 w.WriteWhitespace(temp); 3208 w.WriteEndElement(); 3209 } 3210 Assert.True(utils.CompareReader("<Root></Root>")); 3211 } 3212 3213 [Theory] 3214 [XmlWriterInlineData("a")] 3215 [XmlWriterInlineData("\xE")] 3216 [XmlWriterInlineData("\x0")] 3217 [XmlWriterInlineData("\x10")] 3218 [XmlWriterInlineData("\x1F")] whitespace_5(XmlWriterUtils utils, string param)3219 public void whitespace_5(XmlWriterUtils utils, string param) 3220 { 3221 using (XmlWriter w = utils.CreateWriter()) 3222 { 3223 try 3224 { 3225 w.WriteStartElement("Root"); 3226 w.WriteWhitespace(param); 3227 } 3228 catch (ArgumentException e) 3229 { 3230 CError.WriteLineIgnore("Exception: " + e.ToString()); 3231 CError.Compare(w.WriteState, (utils.WriterType == WriterType.CharCheckingWriter) ? WriteState.Element : WriteState.Error, "WriteState should be Error"); 3232 return; 3233 } 3234 } 3235 CError.WriteLine("Did not throw exception"); 3236 Assert.True(false); 3237 } 3238 } 3239 3240 //[TestCase(Name = "WriteValue")] 3241 public partial class TCWriteValue 3242 { 3243 // Write multiple atomic values inside element 3244 [Theory] 3245 [XmlWriterInlineData] writeValue_1(XmlWriterUtils utils)3246 public void writeValue_1(XmlWriterUtils utils) 3247 { 3248 using (XmlWriter w = utils.CreateWriter()) 3249 { 3250 w.WriteStartElement("Root"); 3251 w.WriteValue((int)2); 3252 w.WriteValue((bool)true); 3253 w.WriteValue((double)3.14); 3254 w.WriteEndElement(); 3255 } 3256 Assert.True((utils.CompareReader("<Root>2true3.14</Root>"))); 3257 } 3258 3259 // Write multiple atomic values inside attribute 3260 [Theory] 3261 [XmlWriterInlineData] writeValue_2(XmlWriterUtils utils)3262 public void writeValue_2(XmlWriterUtils utils) 3263 { 3264 using (XmlWriter w = utils.CreateWriter()) 3265 { 3266 w.WriteStartElement("Root"); 3267 w.WriteStartAttribute("attr"); 3268 w.WriteValue((int)2); 3269 w.WriteValue((bool)true); 3270 w.WriteValue((double)3.14); 3271 w.WriteEndElement(); 3272 } 3273 Assert.True((utils.CompareReader("<Root attr=\"2true3.14\" />"))); 3274 } 3275 3276 // Write multiple atomic values inside element, separate by WriteWhitespace(' ') 3277 [Theory] 3278 [XmlWriterInlineData] writeValue_3(XmlWriterUtils utils)3279 public void writeValue_3(XmlWriterUtils utils) 3280 { 3281 using (XmlWriter w = utils.CreateWriter()) 3282 { 3283 w.WriteStartElement("Root"); 3284 w.WriteValue((int)2); 3285 w.WriteWhitespace(" "); 3286 w.WriteValue((bool)true); 3287 w.WriteWhitespace(" "); 3288 w.WriteValue((double)3.14); 3289 w.WriteWhitespace(" "); 3290 w.WriteEndElement(); 3291 } 3292 Assert.True((utils.CompareReader("<Root>2 true 3.14 </Root>"))); 3293 } 3294 3295 // Write multiple atomic values inside element, separate by WriteString(' ') 3296 [Theory] 3297 [XmlWriterInlineData] writeValue_4(XmlWriterUtils utils)3298 public void writeValue_4(XmlWriterUtils utils) 3299 { 3300 using (XmlWriter w = utils.CreateWriter()) 3301 { 3302 w.WriteStartElement("Root"); 3303 w.WriteValue((int)2); 3304 w.WriteString(" "); 3305 w.WriteValue((bool)true); 3306 w.WriteString(" "); 3307 w.WriteValue((double)3.14); 3308 w.WriteString(" "); 3309 w.WriteEndElement(); 3310 } 3311 Assert.True((utils.CompareReader("<Root>2 true 3.14 </Root>"))); 3312 } 3313 3314 // Write multiple atomic values inside attribute, separate by WriteWhitespace(' ') 3315 [Theory] 3316 [XmlWriterInlineData] writeValue_5(XmlWriterUtils utils)3317 public void writeValue_5(XmlWriterUtils utils) 3318 { 3319 using (XmlWriter w = utils.CreateWriter()) 3320 { 3321 try 3322 { 3323 w.WriteStartElement("Root"); 3324 w.WriteStartAttribute("attr"); 3325 w.WriteValue((int)2); 3326 w.WriteWhitespace(" "); 3327 w.WriteValue((bool)true); 3328 w.WriteWhitespace(" "); 3329 w.WriteValue((double)3.14); 3330 w.WriteWhitespace(" "); 3331 w.WriteEndElement(); 3332 } 3333 catch (InvalidOperationException e) 3334 { 3335 CError.WriteLine(e); 3336 Assert.True(false); 3337 } 3338 } 3339 Assert.True((utils.CompareReader("<Root attr=\"2 true 3.14 \" />"))); 3340 } 3341 3342 // Write multiple atomic values inside attribute, separate by WriteString(' ') 3343 [Theory] 3344 [XmlWriterInlineData] writeValue_6(XmlWriterUtils utils)3345 public void writeValue_6(XmlWriterUtils utils) 3346 { 3347 using (XmlWriter w = utils.CreateWriter()) 3348 { 3349 w.WriteStartElement("Root"); 3350 w.WriteStartAttribute("attr"); 3351 w.WriteValue((int)2); 3352 w.WriteString(" "); 3353 w.WriteValue((bool)true); 3354 w.WriteString(" "); 3355 w.WriteValue((double)3.14); 3356 w.WriteString(" "); 3357 w.WriteEndElement(); 3358 } 3359 Assert.True((utils.CompareReader("<Root attr=\"2 true 3.14 \" />"))); 3360 } 3361 3362 // WriteValue(long) 3363 [Theory] 3364 [XmlWriterInlineData] writeValue_7(XmlWriterUtils utils)3365 public void writeValue_7(XmlWriterUtils utils) 3366 { 3367 using (XmlWriter w = utils.CreateWriter()) 3368 { 3369 w.WriteStartElement("Root"); 3370 w.WriteValue(long.MaxValue); 3371 w.WriteStartElement("child"); 3372 w.WriteValue(long.MinValue); 3373 w.WriteEndElement(); 3374 w.WriteEndElement(); 3375 } 3376 Assert.True((utils.CompareReader("<Root>9223372036854775807<child>-9223372036854775808</child></Root>"))); 3377 } 3378 3379 [Theory] 3380 [XmlWriterInlineData("string")] 3381 [XmlWriterInlineData("object")] writeValue_8(XmlWriterUtils utils, string param)3382 public void writeValue_8(XmlWriterUtils utils, string param) 3383 { 3384 using (XmlWriter w = utils.CreateWriter()) 3385 { 3386 w.WriteStartElement("root"); 3387 switch (param) 3388 { 3389 case "string": 3390 w.WriteValue((string)null); 3391 return; 3392 case "object": 3393 try 3394 { 3395 w.WriteValue((object)null); 3396 } 3397 catch (ArgumentNullException) { return; } 3398 break; 3399 } 3400 throw new CTestFailedException("Test failed."); 3401 } 3402 } 3403 VerifyValue(Type dest, object expVal, int param)3404 public void VerifyValue(Type dest, object expVal, int param) 3405 { 3406 object actual; 3407 3408 using (Stream fsr = FilePathUtil.getStream("writer.out")) 3409 { 3410 using (XmlReader r = ReaderHelper.Create(fsr)) 3411 { 3412 while (r.Read()) 3413 { 3414 if (r.NodeType == XmlNodeType.Element) 3415 break; 3416 } 3417 if (param == 1) 3418 { 3419 actual = (object)r.ReadElementContentAs(dest, null); 3420 if (!actual.Equals(expVal)) 3421 CError.Compare(actual.ToString(), expVal.ToString(), "RECA"); 3422 } 3423 else 3424 { 3425 r.MoveToAttribute("a"); 3426 actual = (object)r.ReadContentAs(dest, null); 3427 if (!actual.Equals(expVal)) 3428 CError.Compare(actual.ToString(), expVal.ToString(), "RCA"); 3429 } 3430 } 3431 } 3432 } 3433 3434 public static Dictionary<string, Type> typeMapper; 3435 public static Dictionary<string, object> value; 3436 public static Dictionary<string, object> expValue; 3437 TCWriteValue()3438 static TCWriteValue() 3439 { 3440 if (typeMapper == null) 3441 { 3442 typeMapper = new Dictionary<string, Type>(); 3443 typeMapper.Add("UInt64", typeof(UInt64)); 3444 typeMapper.Add("UInt32", typeof(UInt32)); 3445 typeMapper.Add("UInt16", typeof(UInt16)); 3446 typeMapper.Add("Int64", typeof(Int64)); 3447 typeMapper.Add("Int32", typeof(Int32)); 3448 typeMapper.Add("Int16", typeof(Int16)); 3449 typeMapper.Add("Byte", typeof(Byte)); 3450 typeMapper.Add("SByte", typeof(SByte)); 3451 typeMapper.Add("Decimal", typeof(Decimal)); 3452 typeMapper.Add("Single", typeof(Single)); 3453 typeMapper.Add("float", typeof(float)); 3454 typeMapper.Add("object", typeof(object)); 3455 typeMapper.Add("bool", typeof(bool)); 3456 typeMapper.Add("DateTime", typeof(DateTime)); 3457 typeMapper.Add("DateTimeOffset", typeof(DateTimeOffset)); 3458 typeMapper.Add("ByteArray", typeof(byte[])); 3459 typeMapper.Add("BoolArray", typeof(bool[])); 3460 typeMapper.Add("ObjectArray", typeof(Object[])); 3461 typeMapper.Add("DecimalArray", typeof(Decimal[])); 3462 typeMapper.Add("DoubleArray", typeof(Double[])); 3463 typeMapper.Add("DateTimeArray", typeof(DateTime[])); 3464 typeMapper.Add("DateTimeOffsetArray", typeof(DateTimeOffset[])); 3465 typeMapper.Add("Int16Array", typeof(Int16[])); 3466 typeMapper.Add("Int32Array", typeof(Int32[])); 3467 typeMapper.Add("Int64Array", typeof(Int64[])); 3468 typeMapper.Add("SByteArray", typeof(SByte[])); 3469 typeMapper.Add("SingleArray", typeof(Single[])); 3470 typeMapper.Add("StringArray", typeof(string[])); 3471 typeMapper.Add("TimeSpanArray", typeof(TimeSpan[])); 3472 typeMapper.Add("UInt16Array", typeof(UInt16[])); 3473 typeMapper.Add("UInt32Array", typeof(UInt32[])); 3474 typeMapper.Add("UInt64Array", typeof(UInt64[])); 3475 typeMapper.Add("UriArray", typeof(Uri[])); 3476 typeMapper.Add("XmlQualifiedNameArray", typeof(XmlQualifiedName[])); 3477 typeMapper.Add("List", typeof(List<string>)); 3478 typeMapper.Add("TimeSpan", typeof(TimeSpan)); 3479 typeMapper.Add("Double", typeof(Double)); 3480 typeMapper.Add("Uri", typeof(Uri)); 3481 typeMapper.Add("XmlQualifiedName", typeof(XmlQualifiedName)); 3482 typeMapper.Add("Char", typeof(Char)); 3483 typeMapper.Add("string", typeof(string)); 3484 } 3485 if (value == null) 3486 { 3487 value = new Dictionary<string, object>(); 3488 value.Add("UInt64", UInt64.MaxValue); 3489 value.Add("UInt32", UInt32.MaxValue); 3490 value.Add("UInt16", UInt16.MaxValue); 3491 value.Add("Int64", Int64.MaxValue); 3492 value.Add("Int32", Int32.MaxValue); 3493 value.Add("Int16", Int16.MaxValue); 3494 value.Add("Byte", Byte.MaxValue); 3495 value.Add("SByte", SByte.MaxValue); 3496 value.Add("Decimal", Decimal.MaxValue); 3497 value.Add("Single", -4582.24); 3498 value.Add("float", -4582.24F); 3499 value.Add("object", 0); 3500 value.Add("bool", false); 3501 value.Add("DateTime", new DateTime(2002, 1, 3, 21, 59, 59, 59)); 3502 value.Add("DateTimeOffset", new DateTimeOffset(2002, 1, 3, 21, 59, 59, 59, TimeSpan.FromHours(0))); 3503 value.Add("ByteArray", new byte[] { 0xd8, 0x7e }); 3504 value.Add("BoolArray", new bool[] { true, false }); 3505 value.Add("ObjectArray", new Object[] { 0, 1 }); 3506 value.Add("DecimalArray", new Decimal[] { 0, 1 }); 3507 value.Add("DoubleArray", new Double[] { 0, 1 }); 3508 value.Add("DateTimeArray", new DateTime[] { new DateTime(2002, 12, 30), new DateTime(2, 1, 3, 23, 59, 59, 59) }); 3509 value.Add("DateTimeOffsetArray", new DateTimeOffset[] { new DateTimeOffset(2002, 12, 30, 0, 0, 0, TimeSpan.FromHours(-8.0)), new DateTimeOffset(2, 1, 3, 23, 59, 59, 59, TimeSpan.FromHours(0)) }); 3510 value.Add("Int16Array", new Int16[] { 0, 1 }); 3511 value.Add("Int32Array", new Int32[] { 0, 1 }); 3512 value.Add("Int64Array", new Int64[] { 0, 1 }); 3513 value.Add("SByteArray", new SByte[] { 0, 1 }); 3514 value.Add("SingleArray", new Single[] { 0, 1 }); 3515 value.Add("StringArray", new string[] { "0", "1" }); 3516 value.Add("TimeSpanArray", new TimeSpan[] { TimeSpan.MinValue, TimeSpan.MaxValue }); 3517 value.Add("UInt16Array", new UInt16[] { 0, 1 }); 3518 value.Add("UInt32Array", new UInt32[] { 0, 1 }); 3519 value.Add("UInt64Array", new UInt64[] { 0, 1 }); 3520 value.Add("UriArray", new Uri[] { new Uri("http://wddata", UriKind.Absolute), new Uri("http://webxtest") }); 3521 value.Add("XmlQualifiedNameArray", new XmlQualifiedName[] { new XmlQualifiedName("a"), new XmlQualifiedName("b", null) }); 3522 value.Add("List", new List<Guid>[] { }); 3523 value.Add("TimeSpan", new TimeSpan()); 3524 value.Add("Double", Double.MaxValue); 3525 value.Add("Uri", "http"); 3526 value.Add("XmlQualifiedName", new XmlQualifiedName("a", null)); 3527 value.Add("Char", Char.MaxValue); 3528 value.Add("string", "123"); 3529 } 3530 } 3531 private object[] _dates = new object[] 3532 { 3533 new DateTimeOffset(2002,1,3,21,59,59,59, TimeZoneInfo.Local.GetUtcOffset(new DateTime(2002,1,3))), 3534 "2002-01-03T21:59:59.059", 3535 XmlConvert.ToString(new DateTimeOffset(2002,1,3,21,59,59,59, TimeSpan.FromHours(0))) 3536 }; 3537 3538 [Theory] 3539 [ActiveIssue(22705, TargetFrameworkMonikers.Uap)] 3540 [XmlWriterInlineData(1, "UInt64", "string", true, null )] 3541 [XmlWriterInlineData(1, "UInt32", "string", true, null )] 3542 [XmlWriterInlineData(1, "UInt16", "string", true, null )] 3543 [XmlWriterInlineData(1, "Int64", "string", true, null )] 3544 [XmlWriterInlineData(1, "Int32", "string", true, null )] 3545 [XmlWriterInlineData(1, "Int16", "string", true, null )] 3546 [XmlWriterInlineData(1, "Byte", "string", true, null )] 3547 [XmlWriterInlineData(1, "SByte", "string", true, null )] 3548 [XmlWriterInlineData(1, "Decimal", "string", true, null )] 3549 [XmlWriterInlineData(1, "float", "string", true, null )] 3550 [XmlWriterInlineData(1, "object", "string", true, null )] 3551 [XmlWriterInlineData(1, "bool", "string", true, "false" )] 3552 [XmlWriterInlineData(1, "DateTime", "string", true, 1 )] 3553 [XmlWriterInlineData(1, "DateTimeOffset", "string", true, 2 )] 3554 [XmlWriterInlineData(1, "ByteArray", "string", true, "2H4=" )] 3555 [XmlWriterInlineData(1, "List", "string", true, "" )] 3556 [XmlWriterInlineData(1, "TimeSpan", "string", true, "PT0S" )] 3557 [XmlWriterInlineData(1, "Uri", "string", true, null )] 3558 [XmlWriterInlineData(1, "Double", "string", true, "1.7976931348623157E+308" )] 3559 [XmlWriterInlineData(1, "Single", "string", true, null )] 3560 [XmlWriterInlineData(1, "XmlQualifiedName", "string", true, null )] 3561 [XmlWriterInlineData(1, "string", "string", true, null )] 3562 3563 [XmlWriterInlineData(1, "UInt64", "UInt64", true, null )] 3564 [XmlWriterInlineData(1, "UInt32", "UInt64", true, null )] 3565 [XmlWriterInlineData(1, "UInt16", "UInt64", true, null )] 3566 [XmlWriterInlineData(1, "Int64", "UInt64", true, null )] 3567 [XmlWriterInlineData(1, "Int32", "UInt64", true, null )] 3568 [XmlWriterInlineData(1, "Int16", "UInt64", true, null )] 3569 [XmlWriterInlineData(1, "Byte", "UInt64", true, null )] 3570 [XmlWriterInlineData(1, "SByte", "UInt64", true, null )] 3571 [XmlWriterInlineData(1, "Decimal", "UInt64", false, null )] 3572 [XmlWriterInlineData(1, "float", "UInt64", false, null )] 3573 [XmlWriterInlineData(1, "object", "UInt64", true, null )] 3574 [XmlWriterInlineData(1, "bool", "UInt64", false, null )] 3575 [XmlWriterInlineData(1, "DateTime", "UInt64", false, null )] 3576 [XmlWriterInlineData(1, "DateTimeOffset", "UInt64", false, null )] 3577 [XmlWriterInlineData(1, "ByteArray", "UInt64", false, null )] 3578 [XmlWriterInlineData(1, "List", "UInt64", false, null )] 3579 [XmlWriterInlineData(1, "TimeSpan", "UInt64", false, null )] 3580 [XmlWriterInlineData(1, "Uri", "UInt64", false, null )] 3581 [XmlWriterInlineData(1, "Double", "UInt64", false, null )] 3582 [XmlWriterInlineData(1, "Single", "UInt64", false, null )] 3583 [XmlWriterInlineData(1, "XmlQualifiedName", "UInt64", false, null )] 3584 [XmlWriterInlineData(1, "string", "UInt64", true, null )] 3585 3586 [XmlWriterInlineData(1, "UInt64", "Int64", false, null )] 3587 [XmlWriterInlineData(1, "UInt32", "Int64", true, null )] 3588 [XmlWriterInlineData(1, "UInt16", "Int64", true, null )] 3589 [XmlWriterInlineData(1, "Int64", "Int64", true, null )] 3590 [XmlWriterInlineData(1, "Int32", "Int64", true, null )] 3591 [XmlWriterInlineData(1, "Int16", "Int64", true, null )] 3592 [XmlWriterInlineData(1, "Byte", "Int64", true, null )] 3593 [XmlWriterInlineData(1, "SByte", "Int64", true, null )] 3594 [XmlWriterInlineData(1, "Decimal", "Int64", false, null )] 3595 [XmlWriterInlineData(1, "float", "Int64", false, null )] 3596 [XmlWriterInlineData(1, "object", "Int64", true, null )] 3597 [XmlWriterInlineData(1, "bool", "Int64", false, null )] 3598 [XmlWriterInlineData(1, "DateTime", "Int64", false, null )] 3599 [XmlWriterInlineData(1, "DateTimeOffset", "Int64", false, null )] 3600 [XmlWriterInlineData(1, "ByteArray", "Int64", false, null )] 3601 [XmlWriterInlineData(1, "List", "Int64", false, null )] 3602 [XmlWriterInlineData(1, "TimeSpan", "Int64", false, null )] 3603 [XmlWriterInlineData(1, "Uri", "Int64", false, null )] 3604 [XmlWriterInlineData(1, "Double", "Int64", false, null )] 3605 [XmlWriterInlineData(1, "Single", "Int64", false, null )] 3606 [XmlWriterInlineData(1, "XmlQualifiedName", "Int64", false, null )] 3607 [XmlWriterInlineData(1, "string", "Int64", true, null )] 3608 3609 [XmlWriterInlineData(1, "UInt64", "UInt32", false, null )] 3610 [XmlWriterInlineData(1, "UInt32", "UInt32", true, null )] 3611 [XmlWriterInlineData(1, "UInt16", "UInt32", true, null )] 3612 [XmlWriterInlineData(1, "Int64", "UInt32", false, null )] 3613 [XmlWriterInlineData(1, "Int32", "UInt32", true, null )] 3614 [XmlWriterInlineData(1, "Int16", "UInt32", true, null )] 3615 [XmlWriterInlineData(1, "Byte", "UInt32", true, null )] 3616 [XmlWriterInlineData(1, "SByte", "UInt32", true, null )] 3617 [XmlWriterInlineData(1, "Decimal", "UInt32", false, null )] 3618 [XmlWriterInlineData(1, "float", "UInt32", false, null )] 3619 [XmlWriterInlineData(1, "object", "UInt32", true, null )] 3620 [XmlWriterInlineData(1, "bool", "UInt32", false, null )] 3621 [XmlWriterInlineData(1, "DateTime", "UInt32", false, null )] 3622 [XmlWriterInlineData(1, "DateTimeOffset", "UInt32", false, null )] 3623 [XmlWriterInlineData(1, "ByteArray", "UInt32", false, null )] 3624 [XmlWriterInlineData(1, "List", "UInt32", false, null )] 3625 [XmlWriterInlineData(1, "TimeSpan", "UInt32", false, null )] 3626 [XmlWriterInlineData(1, "Uri", "UInt32", false, null )] 3627 [XmlWriterInlineData(1, "Double", "UInt32", false, null )] 3628 [XmlWriterInlineData(1, "Single", "UInt32", false, null )] 3629 [XmlWriterInlineData(1, "XmlQualifiedName", "UInt32", false, null )] 3630 [XmlWriterInlineData(1, "string", "UInt32", true, null )] 3631 3632 [XmlWriterInlineData(1, "UInt64", "Int32", false, null )] 3633 [XmlWriterInlineData(1, "UInt32", "Int32", false, null )] 3634 [XmlWriterInlineData(1, "UInt16", "Int32", true, null )] 3635 [XmlWriterInlineData(1, "Int64", "Int32", false, null )] 3636 [XmlWriterInlineData(1, "Int32", "Int32", true, null )] 3637 [XmlWriterInlineData(1, "Int16", "Int32", true, null )] 3638 [XmlWriterInlineData(1, "Byte", "Int32", true, null )] 3639 [XmlWriterInlineData(1, "SByte", "Int32", true, null )] 3640 [XmlWriterInlineData(1, "Decimal", "Int32", false, null )] 3641 [XmlWriterInlineData(1, "float", "Int32", false, null )] 3642 [XmlWriterInlineData(1, "object", "Int32", true, null )] 3643 [XmlWriterInlineData(1, "bool", "Int32", false, null )] 3644 [XmlWriterInlineData(1, "DateTime", "Int32", false, null )] 3645 [XmlWriterInlineData(1, "DateTimeOffset", "Int32", false, null )] 3646 [XmlWriterInlineData(1, "ByteArray", "Int32", false, null )] 3647 [XmlWriterInlineData(1, "List", "Int32", false, null )] 3648 [XmlWriterInlineData(1, "TimeSpan", "Int32", false, null )] 3649 [XmlWriterInlineData(1, "Uri", "Int32", false, null )] 3650 [XmlWriterInlineData(1, "Double", "Int32", false, null )] 3651 [XmlWriterInlineData(1, "Single", "Int32", false, null )] 3652 [XmlWriterInlineData(1, "XmlQualifiedName", "Int32", false, null )] 3653 [XmlWriterInlineData(1, "string", "Int32", true, null )] 3654 3655 [XmlWriterInlineData(1, "UInt64", "UInt16", false, null )] 3656 [XmlWriterInlineData(1, "UInt32", "UInt16", false, null )] 3657 [XmlWriterInlineData(1, "UInt16", "UInt16", true, null )] 3658 [XmlWriterInlineData(1, "Int64", "UInt16", false, null )] 3659 [XmlWriterInlineData(1, "Int32", "UInt16", false, null )] 3660 [XmlWriterInlineData(1, "Int16", "UInt16", true, null )] 3661 [XmlWriterInlineData(1, "Byte", "UInt16", true, null )] 3662 [XmlWriterInlineData(1, "SByte", "UInt16", true, null )] 3663 [XmlWriterInlineData(1, "Decimal", "UInt16", false, null )] 3664 [XmlWriterInlineData(1, "float", "UInt16", false, null )] 3665 [XmlWriterInlineData(1, "object", "UInt16", true, null )] 3666 [XmlWriterInlineData(1, "bool", "UInt16", false, null )] 3667 [XmlWriterInlineData(1, "DateTime", "UInt16", false, null )] 3668 [XmlWriterInlineData(1, "DateTimeOffset", "UInt16", false, null )] 3669 [XmlWriterInlineData(1, "ByteArray", "UInt16", false, null )] 3670 [XmlWriterInlineData(1, "List", "UInt16", false, null )] 3671 [XmlWriterInlineData(1, "TimeSpan", "UInt16", false, null )] 3672 [XmlWriterInlineData(1, "Uri", "UInt16", false, null )] 3673 [XmlWriterInlineData(1, "Double", "UInt16", false, null )] 3674 [XmlWriterInlineData(1, "Single", "UInt16", false, null )] 3675 [XmlWriterInlineData(1, "XmlQualifiedName", "UInt16", false, null )] 3676 [XmlWriterInlineData(1, "string", "UInt16", true, null )] 3677 3678 [XmlWriterInlineData(1, "UInt64", "Int16", false, null )] 3679 [XmlWriterInlineData(1, "UInt32", "Int16", false, null )] 3680 [XmlWriterInlineData(1, "UInt16", "Int16", false, null )] 3681 [XmlWriterInlineData(1, "Int64", "Int16", false, null )] 3682 [XmlWriterInlineData(1, "Int32", "Int16", false, null )] 3683 [XmlWriterInlineData(1, "Int16", "Int16", true, null )] 3684 [XmlWriterInlineData(1, "Byte", "Int16", true, null )] 3685 [XmlWriterInlineData(1, "SByte", "Int16", true, null )] 3686 [XmlWriterInlineData(1, "Decimal", "Int16", false, null )] 3687 [XmlWriterInlineData(1, "float", "Int16", false, null )] 3688 [XmlWriterInlineData(1, "object", "Int16", true, null )] 3689 [XmlWriterInlineData(1, "bool", "Int16", false, null )] 3690 [XmlWriterInlineData(1, "DateTime", "Int16", false, null )] 3691 [XmlWriterInlineData(1, "DateTimeOffset", "Int16", false, null )] 3692 [XmlWriterInlineData(1, "ByteArray", "Int16", false, null )] 3693 [XmlWriterInlineData(1, "List", "Int16", false, null )] 3694 [XmlWriterInlineData(1, "TimeSpan", "Int16", false, null )] 3695 [XmlWriterInlineData(1, "Uri", "Int16", false, null )] 3696 [XmlWriterInlineData(1, "Double", "Int16", false, null )] 3697 [XmlWriterInlineData(1, "Single", "Int16", false, null )] 3698 [XmlWriterInlineData(1, "XmlQualifiedName", "Int16", false, null )] 3699 [XmlWriterInlineData(1, "string", "Int16", true, null )] 3700 3701 [XmlWriterInlineData(1, "UInt64", "Byte", false, null )] 3702 [XmlWriterInlineData(1, "UInt32", "Byte", false, null )] 3703 [XmlWriterInlineData(1, "UInt16", "Byte", false, null )] 3704 [XmlWriterInlineData(1, "Int64", "Byte", false, null )] 3705 [XmlWriterInlineData(1, "Int32", "Byte", false, null )] 3706 [XmlWriterInlineData(1, "Int16", "Byte", false, null )] 3707 [XmlWriterInlineData(1, "Byte", "Byte", true, null )] 3708 [XmlWriterInlineData(1, "SByte", "Byte", true, null )] 3709 [XmlWriterInlineData(1, "Decimal", "Byte", false, null )] 3710 [XmlWriterInlineData(1, "float", "Byte", false, null )] 3711 [XmlWriterInlineData(1, "object", "Byte", true, null )] 3712 [XmlWriterInlineData(1, "bool", "Byte", false, null )] 3713 [XmlWriterInlineData(1, "DateTime", "Byte", false, null )] 3714 [XmlWriterInlineData(1, "DateTimeOffset", "Byte", false, null )] 3715 [XmlWriterInlineData(1, "ByteArray", "Byte", false, null )] 3716 [XmlWriterInlineData(1, "List", "Byte", false, null )] 3717 [XmlWriterInlineData(1, "TimeSpan", "Byte", false, null )] 3718 [XmlWriterInlineData(1, "Uri", "Byte", false, null )] 3719 [XmlWriterInlineData(1, "Double", "Byte", false, null )] 3720 [XmlWriterInlineData(1, "Single", "Byte", false, null )] 3721 [XmlWriterInlineData(1, "XmlQualifiedName", "Byte", false, null )] 3722 [XmlWriterInlineData(1, "string", "Byte", true, null )] 3723 3724 [XmlWriterInlineData(1, "UInt64", "SByte", false, null )] 3725 [XmlWriterInlineData(1, "UInt32", "SByte", false, null )] 3726 [XmlWriterInlineData(1, "UInt16", "SByte", false, null )] 3727 [XmlWriterInlineData(1, "Int64", "SByte", false, null )] 3728 [XmlWriterInlineData(1, "Int32", "SByte", false, null )] 3729 [XmlWriterInlineData(1, "Int16", "SByte", false, null )] 3730 [XmlWriterInlineData(1, "Byte", "SByte", false, null )] 3731 [XmlWriterInlineData(1, "SByte", "SByte", true, null )] 3732 [XmlWriterInlineData(1, "Decimal", "SByte", false, null )] 3733 [XmlWriterInlineData(1, "float", "SByte", false, null )] 3734 [XmlWriterInlineData(1, "object", "SByte", true, null )] 3735 [XmlWriterInlineData(1, "bool", "SByte", false, null )] 3736 [XmlWriterInlineData(1, "DateTime", "SByte", false, null )] 3737 [XmlWriterInlineData(1, "DateTimeOffset", "SByte", false, null )] 3738 [XmlWriterInlineData(1, "ByteArray", "SByte", false, null )] 3739 [XmlWriterInlineData(1, "List", "SByte", false, null )] 3740 [XmlWriterInlineData(1, "TimeSpan", "SByte", false, null )] 3741 [XmlWriterInlineData(1, "Uri", "SByte", false, null )] 3742 [XmlWriterInlineData(1, "Double", "SByte", false, null )] 3743 [XmlWriterInlineData(1, "Single", "SByte", false, null )] 3744 [XmlWriterInlineData(1, "XmlQualifiedName", "SByte", false, null )] 3745 [XmlWriterInlineData(1, "string", "SByte", true, null )] 3746 3747 [XmlWriterInlineData(1, "UInt64", "Decimal", true, null )] 3748 [XmlWriterInlineData(1, "UInt32", "Decimal", true, null )] 3749 [XmlWriterInlineData(1, "UInt16", "Decimal", true, null )] 3750 [XmlWriterInlineData(1, "Int64", "Decimal", true, null )] 3751 [XmlWriterInlineData(1, "Int32", "Decimal", true, null )] 3752 [XmlWriterInlineData(1, "Int16", "Decimal", true, null )] 3753 [XmlWriterInlineData(1, "Byte", "Decimal", true, null )] 3754 [XmlWriterInlineData(1, "SByte", "Decimal", true, null )] 3755 [XmlWriterInlineData(1, "Decimal", "Decimal", true, null )] 3756 [XmlWriterInlineData(1, "float", "Decimal", true, null )] 3757 [XmlWriterInlineData(1, "object", "Decimal", true, null )] 3758 [XmlWriterInlineData(1, "bool", "Decimal", false, null )] 3759 [XmlWriterInlineData(1, "DateTime", "Decimal", false, null )] 3760 [XmlWriterInlineData(1, "DateTimeOffset", "Decimal", false, null )] 3761 [XmlWriterInlineData(1, "ByteArray", "Decimal", false, null )] 3762 [XmlWriterInlineData(1, "List", "Decimal", false, null )] 3763 [XmlWriterInlineData(1, "TimeSpan", "Decimal", false, null )] 3764 [XmlWriterInlineData(1, "Uri", "Decimal", false, null )] 3765 [XmlWriterInlineData(1, "Double", "Decimal", false, null )] 3766 [XmlWriterInlineData(1, "Single", "Decimal", true, null )] 3767 [XmlWriterInlineData(1, "XmlQualifiedName", "Decimal", false, null )] 3768 [XmlWriterInlineData(1, "string", "Decimal", true, null )] 3769 3770 [XmlWriterInlineData(1, "UInt64", "float", true, 1.844674E+19F )] 3771 [XmlWriterInlineData(1, "UInt32", "float", true, 4.294967E+09F )] 3772 [XmlWriterInlineData(1, "UInt16", "float", true, null )] 3773 [XmlWriterInlineData(1, "Int64", "float", true, 9.223372E+18F )] 3774 [XmlWriterInlineData(1, "Int32", "float", true, 2.147484E+09F )] 3775 [XmlWriterInlineData(1, "Int16", "float", true, null )] 3776 [XmlWriterInlineData(1, "Byte", "float", true, null )] 3777 [XmlWriterInlineData(1, "SByte", "float", true, null )] 3778 [XmlWriterInlineData(1, "Decimal", "float", true, 7.922816E+28F )] 3779 [XmlWriterInlineData(1, "float", "float", true, null )] 3780 [XmlWriterInlineData(1, "object", "float", true, null )] 3781 [XmlWriterInlineData(1, "bool", "float", false, null )] 3782 [XmlWriterInlineData(1, "DateTime", "float", false, null )] 3783 [XmlWriterInlineData(1, "DateTimeOffset", "float", false, null )] 3784 [XmlWriterInlineData(1, "ByteArray", "float", false, null )] 3785 [XmlWriterInlineData(1, "List", "float", false, null )] 3786 [XmlWriterInlineData(1, "TimeSpan", "float", false, null )] 3787 [XmlWriterInlineData(1, "Uri", "float", false, null )] 3788 [XmlWriterInlineData(1, "Double", "float", false, null )] 3789 [XmlWriterInlineData(1, "Single", "float", true, null )] 3790 [XmlWriterInlineData(1, "XmlQualifiedName", "float", false, null )] 3791 [XmlWriterInlineData(1, "string", "float", true, null )] 3792 3793 [XmlWriterInlineData(1, "UInt64", "bool", false, null )] 3794 [XmlWriterInlineData(1, "UInt32", "bool", false, null )] 3795 [XmlWriterInlineData(1, "UInt16", "bool", false, null )] 3796 [XmlWriterInlineData(1, "Int64", "bool", false, null )] 3797 [XmlWriterInlineData(1, "Int32", "bool", false, null )] 3798 [XmlWriterInlineData(1, "Int16", "bool", false, null )] 3799 [XmlWriterInlineData(1, "Byte", "bool", false, null )] 3800 [XmlWriterInlineData(1, "SByte", "bool", false, null )] 3801 [XmlWriterInlineData(1, "Decimal", "bool", false, null )] 3802 [XmlWriterInlineData(1, "float", "bool", false, null )] 3803 [XmlWriterInlineData(1, "object", "bool", true, false )] 3804 [XmlWriterInlineData(1, "bool", "bool", true, null )] 3805 [XmlWriterInlineData(1, "DateTime", "bool", false, null )] 3806 [XmlWriterInlineData(1, "DateTimeOffset", "bool", false, null )] 3807 [XmlWriterInlineData(1, "ByteArray", "bool", false, null )] 3808 [XmlWriterInlineData(1, "List", "bool", false, null )] 3809 [XmlWriterInlineData(1, "TimeSpan", "bool", false, null )] 3810 [XmlWriterInlineData(1, "Uri", "bool", false, null )] 3811 [XmlWriterInlineData(1, "Double", "bool", false, null )] 3812 [XmlWriterInlineData(1, "Single", "bool", false, null )] 3813 [XmlWriterInlineData(1, "XmlQualifiedName", "bool", false, null )] 3814 [XmlWriterInlineData(1, "string", "bool", false, null )] 3815 3816 [XmlWriterInlineData(1, "UInt64", "DateTime", false, null )] 3817 [XmlWriterInlineData(1, "UInt32", "DateTime", false, null )] 3818 [XmlWriterInlineData(1, "UInt16", "DateTime", false, null )] 3819 [XmlWriterInlineData(1, "Int64", "DateTime", false, null )] 3820 [XmlWriterInlineData(1, "Int32", "DateTime", false, null )] 3821 [XmlWriterInlineData(1, "Int16", "DateTime", false, null )] 3822 [XmlWriterInlineData(1, "Byte", "DateTime", false, null )] 3823 [XmlWriterInlineData(1, "SByte", "DateTime", false, null )] 3824 [XmlWriterInlineData(1, "Decimal", "DateTime", false, null )] 3825 [XmlWriterInlineData(1, "float", "DateTime", false, null )] 3826 [XmlWriterInlineData(1, "object", "DateTime", false, null )] 3827 [XmlWriterInlineData(1, "bool", "DateTime", false, null )] 3828 [XmlWriterInlineData(1, "DateTime", "DateTime", true, null )] 3829 [XmlWriterInlineData(1, "DateTimeOffset", "DateTime", true, null )] 3830 [XmlWriterInlineData(1, "ByteArray", "DateTime", false, null )] 3831 [XmlWriterInlineData(1, "List", "DateTime", false, null )] 3832 [XmlWriterInlineData(1, "TimeSpan", "DateTime", false, null )] 3833 [XmlWriterInlineData(1, "Uri", "DateTime", false, null )] 3834 [XmlWriterInlineData(1, "Double", "DateTime", false, null )] 3835 [XmlWriterInlineData(1, "Single", "DateTime", false, null )] 3836 [XmlWriterInlineData(1, "XmlQualifiedName", "DateTime", false, null )] 3837 [XmlWriterInlineData(1, "string", "DateTime", false, null )] 3838 3839 [XmlWriterInlineData(1, "UInt64", "DateTimeOffset", false, null )] 3840 [XmlWriterInlineData(1, "UInt32", "DateTimeOffset", false, null )] 3841 [XmlWriterInlineData(1, "UInt16", "DateTimeOffset", false, null )] 3842 [XmlWriterInlineData(1, "Int64", "DateTimeOffset", false, null )] 3843 [XmlWriterInlineData(1, "Int32", "DateTimeOffset", false, null )] 3844 [XmlWriterInlineData(1, "Int16", "DateTimeOffset", false, null )] 3845 [XmlWriterInlineData(1, "Byte", "DateTimeOffset", false, null )] 3846 [XmlWriterInlineData(1, "SByte", "DateTimeOffset", false, null )] 3847 [XmlWriterInlineData(1, "Decimal", "DateTimeOffset", false, null )] 3848 [XmlWriterInlineData(1, "float", "DateTimeOffset", false, null )] 3849 [XmlWriterInlineData(1, "object", "DateTimeOffset", false, null )] 3850 [XmlWriterInlineData(1, "bool", "DateTimeOffset", false, null )] 3851 [XmlWriterInlineData(1, "DateTime", "DateTimeOffset", true, 0 )] 3852 [XmlWriterInlineData(1, "DateTimeOffset", "DateTimeOffset", true, null )] 3853 [XmlWriterInlineData(1, "ByteArray", "DateTimeOffset", false, null )] 3854 [XmlWriterInlineData(1, "List", "DateTimeOffset", false, null )] 3855 [XmlWriterInlineData(1, "TimeSpan", "DateTimeOffset", false, null )] 3856 [XmlWriterInlineData(1, "Uri", "DateTimeOffset", false, null )] 3857 [XmlWriterInlineData(1, "Double", "DateTimeOffset", false, null )] 3858 [XmlWriterInlineData(1, "Single", "DateTimeOffset", false, null )] 3859 [XmlWriterInlineData(1, "XmlQualifiedName", "DateTimeOffset", false, null )] 3860 [XmlWriterInlineData(1, "string", "DateTimeOffset", false, null )] 3861 3862 [XmlWriterInlineData(1, "UInt64", "List", false, null )] 3863 [XmlWriterInlineData(1, "UInt32", "List", false, null )] 3864 [XmlWriterInlineData(1, "UInt16", "List", false, null )] 3865 [XmlWriterInlineData(1, "Int64", "List", false, null )] 3866 [XmlWriterInlineData(1, "Int32", "List", false, null )] 3867 [XmlWriterInlineData(1, "Int16", "List", false, null )] 3868 [XmlWriterInlineData(1, "Byte", "List", false, null )] 3869 [XmlWriterInlineData(1, "SByte", "List", false, null )] 3870 [XmlWriterInlineData(1, "Decimal", "List", false, null )] 3871 [XmlWriterInlineData(1, "float", "List", false, null )] 3872 [XmlWriterInlineData(1, "object", "List", false, null )] 3873 [XmlWriterInlineData(1, "bool", "List", false, null )] 3874 [XmlWriterInlineData(1, "DateTime", "List", false, null )] 3875 [XmlWriterInlineData(1, "DateTimeOffset", "List", false, null )] 3876 [XmlWriterInlineData(1, "ByteArray", "List", false, null )] 3877 [XmlWriterInlineData(1, "List", "List", false, null )] 3878 [XmlWriterInlineData(1, "TimeSpan", "List", false, null )] 3879 [XmlWriterInlineData(1, "Uri", "List", false, null )] 3880 [XmlWriterInlineData(1, "Double", "List", false, null )] 3881 [XmlWriterInlineData(1, "Single", "List", false, null )] 3882 [XmlWriterInlineData(1, "XmlQualifiedName", "List", false, null )] 3883 [XmlWriterInlineData(1, "string", "List", false, null )] 3884 3885 [XmlWriterInlineData(1, "UInt64", "Uri", true, null )] 3886 [XmlWriterInlineData(1, "UInt32", "Uri", true, null )] 3887 [XmlWriterInlineData(1, "UInt16", "Uri", true, null )] 3888 [XmlWriterInlineData(1, "Int64", "Uri", true, null )] 3889 [XmlWriterInlineData(1, "Int32", "Uri", true, null )] 3890 [XmlWriterInlineData(1, "Int16", "Uri", true, null )] 3891 [XmlWriterInlineData(1, "Byte", "Uri", true, null )] 3892 [XmlWriterInlineData(1, "SByte", "Uri", true, null )] 3893 [XmlWriterInlineData(1, "Decimal", "Uri", true, null )] 3894 [XmlWriterInlineData(1, "float", "Uri", true, null )] 3895 [XmlWriterInlineData(1, "object", "Uri", true, null )] 3896 [XmlWriterInlineData(1, "bool", "Uri", true, "false" )] 3897 [XmlWriterInlineData(1, "DateTime", "Uri", true, 1 )] 3898 [XmlWriterInlineData(1, "DateTimeOffset", "Uri", true, 2 )] 3899 [XmlWriterInlineData(1, "ByteArray", "Uri", true, "2H4=" )] 3900 [XmlWriterInlineData(1, "List", "Uri", true, "" )] 3901 [XmlWriterInlineData(1, "TimeSpan", "Uri", true, "PT0S" )] 3902 [XmlWriterInlineData(1, "Uri", "Uri", true, null )] 3903 [XmlWriterInlineData(1, "Double", "Uri", true, "1.7976931348623157E+308" )] 3904 [XmlWriterInlineData(1, "Single", "Uri", true, null )] 3905 [XmlWriterInlineData(1, "XmlQualifiedName", "Uri", true, null )] 3906 [XmlWriterInlineData(1, "string", "Uri", true, null )] 3907 3908 [XmlWriterInlineData(1, "UInt64", "Double", true, 1.84467440737096E+19D )] 3909 [XmlWriterInlineData(1, "UInt32", "Double", true, null )] 3910 [XmlWriterInlineData(1, "UInt16", "Double", true, null )] 3911 [XmlWriterInlineData(1, "Int64", "Double", true, 9.22337203685478E+18D )] 3912 [XmlWriterInlineData(1, "Int32", "Double", true, null )] 3913 [XmlWriterInlineData(1, "Int16", "Double", true, null )] 3914 [XmlWriterInlineData(1, "Byte", "Double", true, null )] 3915 [XmlWriterInlineData(1, "SByte", "Double", true, null )] 3916 [XmlWriterInlineData(1, "Decimal", "Double", true, 7.92281625142643E+28D )] 3917 [XmlWriterInlineData(1, "float", "Double", true, null )] 3918 [XmlWriterInlineData(1, "object", "Double", true, null )] 3919 [XmlWriterInlineData(1, "bool", "Double", false, null )] 3920 [XmlWriterInlineData(1, "DateTime", "Double", false, null )] 3921 [XmlWriterInlineData(1, "DateTimeOffset", "Double", false, null )] 3922 [XmlWriterInlineData(1, "ByteArray", "Double", false, null )] 3923 [XmlWriterInlineData(1, "List", "Double", false, null )] 3924 [XmlWriterInlineData(1, "TimeSpan", "Double", false, null )] 3925 [XmlWriterInlineData(1, "Uri", "Double", false, null )] 3926 [XmlWriterInlineData(1, "Double", "Double", true, null )] 3927 [XmlWriterInlineData(1, "Single", "Double", true, null )] 3928 [XmlWriterInlineData(1, "XmlQualifiedName", "Double", false, null )] 3929 [XmlWriterInlineData(1, "string", "Double", true, null )] 3930 3931 [XmlWriterInlineData(1, "UInt64", "Single", true, 1.844674E+19F )] 3932 [XmlWriterInlineData(1, "UInt32", "Single", true, 4.294967E+09F )] 3933 [XmlWriterInlineData(1, "UInt16", "Single", true, null )] 3934 [XmlWriterInlineData(1, "Int64", "Single", true, 9.223372E+18F )] 3935 [XmlWriterInlineData(1, "Int32", "Single", true, 2.147484E+09F )] 3936 [XmlWriterInlineData(1, "Int16", "Single", true, null )] 3937 [XmlWriterInlineData(1, "Byte", "Single", true, null )] 3938 [XmlWriterInlineData(1, "SByte", "Single", true, null )] 3939 [XmlWriterInlineData(1, "Decimal", "Single", true, 7.922816E+28F )] 3940 [XmlWriterInlineData(1, "float", "Single", true, null )] 3941 [XmlWriterInlineData(1, "object", "Single", true, null )] 3942 [XmlWriterInlineData(1, "bool", "Single", false, null )] 3943 [XmlWriterInlineData(1, "DateTime", "Single", false, null )] 3944 [XmlWriterInlineData(1, "DateTimeOffset", "Single", false, null )] 3945 [XmlWriterInlineData(1, "ByteArray", "Single", false, null )] 3946 [XmlWriterInlineData(1, "List", "Single", false, null )] 3947 [XmlWriterInlineData(1, "TimeSpan", "Single", false, null )] 3948 [XmlWriterInlineData(1, "Uri", "Single", false, null )] 3949 [XmlWriterInlineData(1, "Double", "Single", false, null )] 3950 [XmlWriterInlineData(1, "Single", "Single", true, null )] 3951 [XmlWriterInlineData(1, "XmlQualifiedName", "Single", false, null )] 3952 [XmlWriterInlineData(1, "string", "Single", true, null )] 3953 3954 [XmlWriterInlineData(1, "UInt64", "object", true, null )] 3955 [XmlWriterInlineData(1, "UInt32", "object", true, null )] 3956 [XmlWriterInlineData(1, "UInt16", "object", true, null )] 3957 [XmlWriterInlineData(1, "Int64", "object", true, null )] 3958 [XmlWriterInlineData(1, "Int32", "object", true, null )] 3959 [XmlWriterInlineData(1, "Int16", "object", true, null )] 3960 [XmlWriterInlineData(1, "Byte", "object", true, null )] 3961 [XmlWriterInlineData(1, "SByte", "object", true, null )] 3962 [XmlWriterInlineData(1, "Decimal", "object", true, null )] 3963 [XmlWriterInlineData(1, "float", "object", true, null )] 3964 [XmlWriterInlineData(1, "object", "object", true, null )] 3965 [XmlWriterInlineData(1, "bool", "object", true, "false" )] 3966 [XmlWriterInlineData(1, "DateTime", "object", true, 1 )] 3967 [XmlWriterInlineData(1, "DateTimeOffset", "object", true, 2 )] 3968 [XmlWriterInlineData(1, "ByteArray", "object", true, "2H4=" )] 3969 [XmlWriterInlineData(1, "List", "object", true, "" )] 3970 [XmlWriterInlineData(1, "TimeSpan", "object", true, "PT0S" )] 3971 [XmlWriterInlineData(1, "Uri", "object", true, null )] 3972 [XmlWriterInlineData(1, "Double", "object", true, "1.7976931348623157E+308" )] 3973 [XmlWriterInlineData(1, "Single", "object", true, null )] 3974 [XmlWriterInlineData(1, "XmlQualifiedName", "object", true, null )] 3975 [XmlWriterInlineData(1, "string", "object", true, null )] 3976 3977 [XmlWriterInlineData(1, "ByteArray", "ByteArray", true, null )] 3978 [XmlWriterInlineData(1, "BoolArray", "BoolArray", true, null )] 3979 [XmlWriterInlineData(1, "ObjectArray", "ObjectArray", true, null )] 3980 [XmlWriterInlineData(1, "DateTimeArray", "DateTimeArray", true, null )] 3981 [XmlWriterInlineData(1, "DateTimeOffsetArray", "DateTimeOffsetArray", true, null )] 3982 [XmlWriterInlineData(1, "DecimalArray", "DecimalArray", true, null )] 3983 [XmlWriterInlineData(1, "DoubleArray", "DoubleArray", true, null )] 3984 [XmlWriterInlineData(1, "Int16Array", "Int16Array", true, null )] 3985 [XmlWriterInlineData(1, "Int32Array", "Int32Array", true, null )] 3986 [XmlWriterInlineData(1, "Int64Array", "Int64Array", true, null )] 3987 [XmlWriterInlineData(1, "SByteArray", "SByteArray", true, null )] 3988 [XmlWriterInlineData(1, "SingleArray", "SingleArray", true, null )] 3989 [XmlWriterInlineData(1, "StringArray", "StringArray", true, null )] 3990 [XmlWriterInlineData(1, "TimeSpanArray", "TimeSpanArray", true, null )] 3991 [XmlWriterInlineData(1, "UInt16Array", "UInt16Array", true, null )] 3992 [XmlWriterInlineData(1, "UInt32Array", "UInt32Array", true, null )] 3993 [XmlWriterInlineData(1, "UInt64Array", "UInt64Array", true, null )] 3994 [XmlWriterInlineData(1, "UriArray", "UriArray", true, null )] 3995 [XmlWriterInlineData(1, "XmlQualifiedNameArray", "XmlQualifiedNameArray", true, null )] 3996 [XmlWriterInlineData(1, "TimeSpan", "TimeSpan", true, null )] 3997 [XmlWriterInlineData(1, "XmlQualifiedName", "XmlQualifiedName", true, null )] 3998 3999 //////////attr 4000 [XmlWriterInlineData(2, "Int16", "string", true, null )] 4001 [XmlWriterInlineData(2, "Byte", "string", true, null )] 4002 [XmlWriterInlineData(2, "SByte", "string", true, null )] 4003 [XmlWriterInlineData(2, "Decimal", "string", true, null )] 4004 [XmlWriterInlineData(2, "float", "string", true, null )] 4005 [XmlWriterInlineData(2, "object", "string", true, null )] 4006 [XmlWriterInlineData(2, "bool", "string", true, "False" )] 4007 [XmlWriterInlineData(2, "Uri", "string", true, null )] 4008 [XmlWriterInlineData(2, "Double", "string", true, null )] 4009 [XmlWriterInlineData(2, "Single", "string", true, null )] 4010 [XmlWriterInlineData(2, "XmlQualifiedName", "string", true, null )] 4011 [XmlWriterInlineData(2, "string", "string", true, null )] 4012 4013 [XmlWriterInlineData(2, "UInt64", "UInt64", true, null )] 4014 [XmlWriterInlineData(2, "UInt32", "UInt64", true, null )] 4015 [XmlWriterInlineData(2, "UInt16", "UInt64", true, null )] 4016 [XmlWriterInlineData(2, "Int64", "UInt64", true, null )] 4017 [XmlWriterInlineData(2, "Int32", "UInt64", true, null )] 4018 [XmlWriterInlineData(2, "Int16", "UInt64", true, null )] 4019 [XmlWriterInlineData(2, "List", "UInt64", false, null )] 4020 [XmlWriterInlineData(2, "TimeSpan", "UInt64", false, null )] 4021 [XmlWriterInlineData(2, "Uri", "UInt64", false, null )] 4022 [XmlWriterInlineData(2, "Double", "UInt64", false, null )] 4023 [XmlWriterInlineData(2, "Single", "UInt64", false, null )] 4024 [XmlWriterInlineData(2, "XmlQualifiedName", "UInt64", false, null )] 4025 [XmlWriterInlineData(2, "string", "UInt64", true, null )] 4026 4027 [XmlWriterInlineData(2, "UInt64", "Int64", false, null )] 4028 [XmlWriterInlineData(2, "UInt32", "Int64", true, null )] 4029 [XmlWriterInlineData(2, "UInt16", "Int64", true, null )] 4030 [XmlWriterInlineData(2, "Int64", "Int64", true, null )] 4031 [XmlWriterInlineData(2, "Int32", "Int64", true, null )] 4032 [XmlWriterInlineData(2, "Int16", "Int64", true, null )] 4033 [XmlWriterInlineData(2, "Byte", "Int64", true, null )] 4034 [XmlWriterInlineData(2, "TimeSpan", "Int64", false, null )] 4035 [XmlWriterInlineData(2, "Uri", "Int64", false, null )] 4036 [XmlWriterInlineData(2, "Double", "Int64", false, null )] 4037 [XmlWriterInlineData(2, "Single", "Int64", false, null )] 4038 [XmlWriterInlineData(2, "XmlQualifiedName", "Int64", false, null )] 4039 [XmlWriterInlineData(2, "string", "Int64", true, null )] 4040 4041 [XmlWriterInlineData(2, "UInt64", "UInt32", false, null )] 4042 [XmlWriterInlineData(2, "UInt32", "UInt32", true, null )] 4043 [XmlWriterInlineData(2, "UInt16", "UInt32", true, null )] 4044 [XmlWriterInlineData(2, "Int64", "UInt32", false, null )] 4045 [XmlWriterInlineData(2, "Int32", "UInt32", true, null )] 4046 [XmlWriterInlineData(2, "Int16", "UInt32", true, null )] 4047 [XmlWriterInlineData(2, "Byte", "UInt32", true, null )] 4048 [XmlWriterInlineData(2, "SByte", "UInt32", true, null )] 4049 [XmlWriterInlineData(2, "string", "UInt32", true, null )] 4050 4051 [XmlWriterInlineData(2, "UInt64", "Int32", false, null )] 4052 [XmlWriterInlineData(2, "UInt32", "Int32", false, null )] 4053 [XmlWriterInlineData(2, "UInt16", "Int32", true, null )] 4054 [XmlWriterInlineData(2, "Int64", "Int32", false, null )] 4055 [XmlWriterInlineData(2, "Int32", "Int32", true, null )] 4056 [XmlWriterInlineData(2, "Int16", "Int32", true, null )] 4057 [XmlWriterInlineData(2, "Byte", "Int32", true, null )] 4058 [XmlWriterInlineData(2, "SByte", "Int32", true, null )] 4059 [XmlWriterInlineData(2, "Single", "Int32", false, null )] 4060 [XmlWriterInlineData(2, "XmlQualifiedName", "Int32", false, null )] 4061 [XmlWriterInlineData(2, "string", "Int32", true, null )] 4062 4063 [XmlWriterInlineData(2, "UInt64", "UInt16", false, null )] 4064 [XmlWriterInlineData(2, "UInt32", "UInt16", false, null )] 4065 [XmlWriterInlineData(2, "UInt16", "UInt16", true, null )] 4066 [XmlWriterInlineData(2, "Int64", "UInt16", false, null )] 4067 [XmlWriterInlineData(2, "Int32", "UInt16", false, null )] 4068 [XmlWriterInlineData(2, "Int16", "UInt16", true, null )] 4069 [XmlWriterInlineData(2, "Byte", "UInt16", true, null )] 4070 [XmlWriterInlineData(2, "SByte", "UInt16", true, null )] 4071 [XmlWriterInlineData(2, "Decimal", "UInt16", false, null )] 4072 [XmlWriterInlineData(2, "float", "UInt16", false, null )] 4073 [XmlWriterInlineData(2, "object", "UInt16", true, null )] 4074 [XmlWriterInlineData(2, "bool", "UInt16", false, null )] 4075 [XmlWriterInlineData(2, "string", "UInt16", true, null )] 4076 4077 [XmlWriterInlineData(2, "UInt64", "Int16", false, null )] 4078 [XmlWriterInlineData(2, "UInt32", "Int16", false, null )] 4079 [XmlWriterInlineData(2, "UInt16", "Int16", false, null )] 4080 [XmlWriterInlineData(2, "Int64", "Int16", false, null )] 4081 [XmlWriterInlineData(2, "Int32", "Int16", false, null )] 4082 [XmlWriterInlineData(2, "Int16", "Int16", true, null )] 4083 [XmlWriterInlineData(2, "Byte", "Int16", true, null )] 4084 [XmlWriterInlineData(2, "SByte", "Int16", true, null )] 4085 [XmlWriterInlineData(2, "Decimal", "Int16", false, null )] 4086 [XmlWriterInlineData(2, "float", "Int16", false, null )] 4087 [XmlWriterInlineData(2, "object", "Int16", true, null )] 4088 [XmlWriterInlineData(2, "bool", "Int16", false, null )] 4089 [XmlWriterInlineData(2, "DateTime", "Int16", false, null )] 4090 [XmlWriterInlineData(2, "string", "Int16", true, null )] 4091 4092 [XmlWriterInlineData(2, "UInt64", "Byte", false, null )] 4093 [XmlWriterInlineData(2, "UInt32", "Byte", false, null )] 4094 [XmlWriterInlineData(2, "UInt16", "Byte", false, null )] 4095 [XmlWriterInlineData(2, "Int64", "Byte", false, null )] 4096 [XmlWriterInlineData(2, "Int32", "Byte", false, null )] 4097 [XmlWriterInlineData(2, "Int16", "Byte", false, null )] 4098 [XmlWriterInlineData(2, "Byte", "Byte", true, null )] 4099 [XmlWriterInlineData(2, "SByte", "Byte", true, null )] 4100 [XmlWriterInlineData(2, "string", "Byte", true, null )] 4101 4102 [XmlWriterInlineData(2, "UInt64", "SByte", false, null )] 4103 [XmlWriterInlineData(2, "UInt32", "SByte", false, null )] 4104 [XmlWriterInlineData(2, "UInt16", "SByte", false, null )] 4105 [XmlWriterInlineData(2, "Int64", "SByte", false, null )] 4106 [XmlWriterInlineData(2, "Int32", "SByte", false, null )] 4107 [XmlWriterInlineData(2, "Uri", "SByte", false, null )] 4108 [XmlWriterInlineData(2, "Double", "SByte", false, null )] 4109 [XmlWriterInlineData(2, "Single", "SByte", false, null )] 4110 [XmlWriterInlineData(2, "XmlQualifiedName", "SByte", false, null )] 4111 [XmlWriterInlineData(2, "string", "SByte", true, null )] 4112 4113 [XmlWriterInlineData(2, "UInt64", "Decimal", true, null )] 4114 [XmlWriterInlineData(2, "UInt32", "Decimal", true, null )] 4115 [XmlWriterInlineData(2, "UInt16", "Decimal", true, null )] 4116 [XmlWriterInlineData(2, "Int64", "Decimal", true, null )] 4117 [XmlWriterInlineData(2, "Int32", "Decimal", true, null )] 4118 [XmlWriterInlineData(2, "Int16", "Decimal", true, null )] 4119 [XmlWriterInlineData(2, "Byte", "Decimal", true, null )] 4120 [XmlWriterInlineData(2, "SByte", "Decimal", true, null )] 4121 [XmlWriterInlineData(2, "Decimal", "Decimal", true, null )] 4122 [XmlWriterInlineData(2, "float", "Decimal", true, null )] 4123 [XmlWriterInlineData(2, "object", "Decimal", true, null )] 4124 [XmlWriterInlineData(21, "XmlQualifiedName", "Decimal", false, null )] 4125 [XmlWriterInlineData(2, "string", "Decimal", true, null )] 4126 4127 [XmlWriterInlineData(2, "UInt64", "float", true, 1.844674E+19F )] 4128 [XmlWriterInlineData(2, "UInt32", "float", true, 4.294967E+09F )] 4129 [XmlWriterInlineData(2, "UInt16", "float", true, null )] 4130 [XmlWriterInlineData(2, "Int64", "float", true, 9.223372E+18F )] 4131 [XmlWriterInlineData(2, "Int32", "float", true, 2.147484E+09F )] 4132 [XmlWriterInlineData(2, "Int16", "float", true, null )] 4133 [XmlWriterInlineData(2, "Byte", "float", true, null )] 4134 [XmlWriterInlineData(2, "SByte", "float", true, null )] 4135 [XmlWriterInlineData(2, "Decimal", "float", true, 7.922816E+28F )] 4136 [XmlWriterInlineData(2, "float", "float", true, null )] 4137 [XmlWriterInlineData(2, "object", "float", true, null )] 4138 [XmlWriterInlineData(2, "bool", "float", false, null )] 4139 [XmlWriterInlineData(2, "Single", "float", true, null )] 4140 [XmlWriterInlineData(2, "XmlQualifiedName", "float", false, null )] 4141 [XmlWriterInlineData(2, "string", "float", true, null )] 4142 4143 [XmlWriterInlineData(2, "UInt64", "bool", false, null )] 4144 [XmlWriterInlineData(2, "UInt32", "bool", false, null )] 4145 [XmlWriterInlineData(2, "object", "bool", true, false )] 4146 [XmlWriterInlineData(2, "DateTime", "bool", false, null )] 4147 [XmlWriterInlineData(2, "DateTimeOffset", "bool", false, null )] 4148 [XmlWriterInlineData(2, "ByteArray", "bool", false, null )] 4149 [XmlWriterInlineData(2, "List", "bool", false, null )] 4150 [XmlWriterInlineData(2, "TimeSpan", "bool", false, null )] 4151 [XmlWriterInlineData(2, "Uri", "bool", false, null )] 4152 [XmlWriterInlineData(2, "Double", "bool", false, null )] 4153 [XmlWriterInlineData(2, "Single", "bool", false, null )] 4154 4155 [XmlWriterInlineData(2, "float", "DateTime", false, null )] 4156 [XmlWriterInlineData(2, "object", "DateTime", false, null )] 4157 [XmlWriterInlineData(2, "bool", "DateTime", false, null )] 4158 [XmlWriterInlineData(2, "ByteArray", "DateTime", false, null )] 4159 [XmlWriterInlineData(2, "List", "DateTime", false, null )] 4160 [XmlWriterInlineData(2, "Uri", "DateTime", false, null )] 4161 [XmlWriterInlineData(2, "Double", "DateTime", false, null )] 4162 [XmlWriterInlineData(2, "Single", "DateTime", false, null )] 4163 [XmlWriterInlineData(2, "XmlQualifiedName", "DateTime", false, null )] 4164 [XmlWriterInlineData(2, "string", "DateTime", false, null )] 4165 4166 [XmlWriterInlineData(2, "UInt64", "DateTimeOffset", false, null )] 4167 [XmlWriterInlineData(2, "UInt32", "DateTimeOffset", false, null )] 4168 [XmlWriterInlineData(2, "UInt16", "DateTimeOffset", false, null )] 4169 [XmlWriterInlineData(2, "Int64", "DateTimeOffset", false, null )] 4170 [XmlWriterInlineData(2, "Int32", "DateTimeOffset", false, null )] 4171 [XmlWriterInlineData(2, "Int16", "DateTimeOffset", false, null )] 4172 [XmlWriterInlineData(2, "Byte", "DateTimeOffset", false, null )] 4173 [XmlWriterInlineData(2, "SByte", "DateTimeOffset", false, null )] 4174 [XmlWriterInlineData(2, "Decimal", "DateTimeOffset", false, null )] 4175 4176 [XmlWriterInlineData(2, "UInt64", "List", false, null )] 4177 [XmlWriterInlineData(2, "UInt32", "List", false, null )] 4178 [XmlWriterInlineData(2, "UInt16", "List", false, null )] 4179 [XmlWriterInlineData(2, "Int64", "List", false, null )] 4180 [XmlWriterInlineData(2, "Int32", "List", false, null )] 4181 [XmlWriterInlineData(2, "Int16", "List", false, null )] 4182 [XmlWriterInlineData(2, "Byte", "List", false, null )] 4183 [XmlWriterInlineData(2, "SByte", "List", false, null )] 4184 [XmlWriterInlineData(2, "Decimal", "List", false, null )] 4185 [XmlWriterInlineData(2, "float", "List", false, null )] 4186 4187 [XmlWriterInlineData(2, "UInt64", "Uri", true, null )] 4188 [XmlWriterInlineData(2, "UInt32", "Uri", true, null )] 4189 [XmlWriterInlineData(2, "UInt16", "Uri", true, null )] 4190 [XmlWriterInlineData(2, "Int64", "Uri", true, null )] 4191 [XmlWriterInlineData(2, "Int32", "Uri", true, null )] 4192 [XmlWriterInlineData(2, "Int16", "Uri", true, null )] 4193 [XmlWriterInlineData(2, "Byte", "Uri", true, null )] 4194 [XmlWriterInlineData(2, "SByte", "Uri", true, null )] 4195 [XmlWriterInlineData(2, "Decimal", "Uri", true, null )] 4196 [XmlWriterInlineData(2, "float", "Uri", true, null )] 4197 [XmlWriterInlineData(2, "object", "Uri", true, null )] 4198 [XmlWriterInlineData(2, "bool", "Uri", true, "False" )] 4199 [XmlWriterInlineData(2, "Uri", "Uri", true, null )] 4200 [XmlWriterInlineData(2, "Double", "Uri", true, null )] 4201 [XmlWriterInlineData(2, "Single", "Uri", true, null )] 4202 [XmlWriterInlineData(2, "XmlQualifiedName", "Uri", true, null )] 4203 [XmlWriterInlineData(2, "string", "Uri", true, null )] 4204 4205 [XmlWriterInlineData(2, "UInt64", "Double", true, 1.84467440737096E+19D )] 4206 [XmlWriterInlineData(2, "UInt32", "Double", true, null )] 4207 [XmlWriterInlineData(2, "UInt16", "Double", true, null )] 4208 [XmlWriterInlineData(2, "Int64", "Double", true, 9.22337203685478E+18D )] 4209 [XmlWriterInlineData(2, "Int32", "Double", true, null )] 4210 [XmlWriterInlineData(2, "Int16", "Double", true, null )] 4211 [XmlWriterInlineData(2, "Byte", "Double", true, null )] 4212 [XmlWriterInlineData(2, "SByte", "Double", true, null )] 4213 [XmlWriterInlineData(2, "Decimal", "Double", true, 7.92281625142643E+28D )] 4214 [XmlWriterInlineData(2, "float", "Double", true, null )] 4215 [XmlWriterInlineData(2, "object", "Double", true, null )] 4216 [XmlWriterInlineData(2, "bool", "Double", false, null )] 4217 [XmlWriterInlineData(2, "Double", "Double", false, null )] 4218 [XmlWriterInlineData(2, "Single", "Double", true, null )] 4219 [XmlWriterInlineData(2, "string", "Double", true, null )] 4220 4221 [XmlWriterInlineData(2, "UInt64", "Single", true, 1.844674E+19F )] 4222 [XmlWriterInlineData(2, "UInt32", "Single", true, 4.294967E+09F )] 4223 [XmlWriterInlineData(2, "UInt16", "Single", true, null )] 4224 [XmlWriterInlineData(2, "Int64", "Single", true, 9.223372E+18F )] 4225 [XmlWriterInlineData(2, "Int32", "Single", true, 2.147484E+09F )] 4226 [XmlWriterInlineData(2, "Int16", "Single", true, null )] 4227 [XmlWriterInlineData(2, "Byte", "Single", true, null )] 4228 [XmlWriterInlineData(2, "SByte", "Single", true, null )] 4229 [XmlWriterInlineData(2, "Decimal", "Single", true, 7.922816E+28F )] 4230 [XmlWriterInlineData(2, "float", "Single", true, null )] 4231 [XmlWriterInlineData(2, "object", "Single", true, null )] 4232 [XmlWriterInlineData(2, "bool", "Single", false, null )] 4233 [XmlWriterInlineData(2, "DateTimeOffset", "Single", false, null )] 4234 [XmlWriterInlineData(2, "Single", "Single", true, null )] 4235 [XmlWriterInlineData(2, "string", "Single", true, null )] 4236 4237 [XmlWriterInlineData(2, "UInt64", "object", true, null )] 4238 [XmlWriterInlineData(2, "Int32", "object", true, null )] 4239 [XmlWriterInlineData(2, "Int16", "object", true, null )] 4240 [XmlWriterInlineData(2, "Byte", "object", true, null )] 4241 [XmlWriterInlineData(2, "SByte", "object", true, null )] 4242 [XmlWriterInlineData(2, "Decimal", "object", true, null )] 4243 [XmlWriterInlineData(2, "float", "object", true, null )] 4244 [XmlWriterInlineData(2, "object", "object", true, null )] 4245 [XmlWriterInlineData(2, "bool", "object", true, "False" )] 4246 [XmlWriterInlineData(2, "XmlQualifiedName", "object", true, null )] 4247 [XmlWriterInlineData(2, "string", "object", true, null )] 4248 [XmlWriterInlineData(2, "ObjectArray", "ObjectArray", true, null )] 4249 [XmlWriterInlineData(2, "StringArray", "StringArray", true, null )] 4250 [XmlWriterInlineData(2, "UriArray", "UriArray", true, null )] 4251 [XmlWriterInlineData(2, "XmlQualifiedName", "XmlQualifiedName", true, null )] writeValue_27(XmlWriterUtils utils, int param, string sourceStr, string destStr, bool isValid, object expVal)4252 public void writeValue_27(XmlWriterUtils utils, int param, string sourceStr, string destStr, bool isValid, object expVal) 4253 { 4254 Type source = typeMapper[sourceStr]; 4255 Type dest = typeMapper[destStr]; 4256 CultureInfo origCulture = null; 4257 4258 if (expVal == null && destStr.Contains("DateTime")) 4259 expVal = value[destStr]; 4260 else if (expVal != null && sourceStr.Contains("DateTime")) 4261 expVal = _dates[(int)expVal]; 4262 else if (sourceStr.Equals("XmlQualifiedName") && (utils.WriterType == WriterType.CustomWriter) && param == 1) 4263 expVal = "{}a"; 4264 else if (expVal == null) 4265 expVal = value[sourceStr]; 4266 4267 using (XmlWriter w = utils.CreateWriter()) 4268 { 4269 w.WriteStartElement("Root"); 4270 if (param == 1) 4271 w.WriteValue(value[sourceStr]); 4272 else 4273 w.WriteAttributeString("a", value[sourceStr].ToString()); 4274 w.WriteEndElement(); 4275 } 4276 try 4277 { 4278 origCulture = CultureInfo.CurrentCulture; 4279 CultureInfo.CurrentCulture = CultureInfo.InvariantCulture; // So that the number format doesn't depend on the current culture 4280 VerifyValue(dest, expVal, param); 4281 } 4282 catch (XmlException) 4283 { 4284 if (!isValid || (utils.WriterType == WriterType.CustomWriter) && sourceStr.Contains("XmlQualifiedName")) 4285 return; 4286 CError.Compare(false, "XmlException"); 4287 } 4288 catch (OverflowException) 4289 { 4290 if (!isValid) 4291 return; 4292 CError.Compare(false, "OverflowException"); 4293 } 4294 catch (FormatException) 4295 { 4296 if (!isValid) 4297 return; 4298 CError.Compare(false, "FormatException"); 4299 } 4300 catch (ArgumentOutOfRangeException) 4301 { 4302 if (!isValid) 4303 return; 4304 CError.Compare(false, "ArgumentOutOfRangeException"); 4305 } 4306 catch (InvalidCastException) 4307 { 4308 if (!isValid) 4309 return; 4310 CError.Compare(false, "ArgumentException"); 4311 } 4312 finally 4313 { 4314 CultureInfo.CurrentCulture = origCulture; 4315 } 4316 Assert.True((isValid)); 4317 } 4318 4319 [Theory] 4320 [XmlWriterInlineData(1)] 4321 [XmlWriterInlineData(2)] 4322 [XmlWriterInlineData(3)] 4323 [XmlWriterInlineData(4)] 4324 [XmlWriterInlineData(6)] 4325 [XmlWriterInlineData(7)] 4326 [XmlWriterInlineData(9)] writeValue_28(XmlWriterUtils utils, int param)4327 public void writeValue_28(XmlWriterUtils utils, int param) 4328 { 4329 Tuple<Int32, String, Double> t = Tuple.Create(1, "Melitta", 7.5); 4330 4331 using (XmlWriter w = utils.CreateWriter()) 4332 { 4333 w.WriteStartElement("Root"); 4334 try 4335 { 4336 switch (param) 4337 { 4338 case 1: 4339 w.WriteValue(new XmlException()); 4340 break; 4341 case 2: 4342 w.WriteValue(DayOfWeek.Friday); 4343 break; 4344 case 3: 4345 w.WriteValue(new XmlQualifiedName("b", "c")); 4346 break; 4347 case 4: 4348 w.WriteValue(new Guid()); 4349 break; 4350 case 6: 4351 w.WriteValue(NewLineHandling.Entitize); 4352 break; 4353 case 7: 4354 w.WriteValue(ConformanceLevel.Auto); 4355 break; 4356 case 9: 4357 w.WriteValue(t); 4358 break; 4359 default: 4360 Assert.True(false, "invalid param"); 4361 break; 4362 } 4363 } 4364 catch (InvalidCastException e) 4365 { 4366 CError.WriteLine(e.Message); 4367 try 4368 { 4369 switch (param) 4370 { 4371 case 1: 4372 w.WriteValue(new XmlException()); 4373 break; 4374 case 2: 4375 w.WriteValue(DayOfWeek.Friday); 4376 break; 4377 case 3: 4378 w.WriteValue(new XmlQualifiedName("b", "c")); 4379 break; 4380 case 4: 4381 w.WriteValue(new Guid()); 4382 break; 4383 case 6: 4384 w.WriteValue(NewLineHandling.Entitize); 4385 break; 4386 case 7: 4387 w.WriteValue(ConformanceLevel.Auto); 4388 break; 4389 case 9: 4390 w.WriteValue(t); 4391 break; 4392 } 4393 } 4394 catch (InvalidOperationException) { return; } 4395 catch (InvalidCastException) { return; } 4396 } 4397 } 4398 Assert.True(param == 3 && (utils.WriterType == WriterType.CustomWriter)); 4399 } 4400 4401 [Theory] 4402 [XmlWriterInlineData(1)] 4403 [XmlWriterInlineData(2)] writeValue_30(XmlWriterUtils utils, int param)4404 public void writeValue_30(XmlWriterUtils utils, int param) 4405 { 4406 using (XmlWriter w = utils.CreateWriter()) 4407 { 4408 w.WriteStartElement("Root"); 4409 if (param == 1) 4410 w.WriteValue("p:foo"); 4411 else 4412 w.WriteAttributeString("a", "p:foo"); 4413 w.WriteEndElement(); 4414 } 4415 try 4416 { 4417 VerifyValue(typeof(XmlQualifiedName), "p:foo", param); 4418 } 4419 catch (XmlException) { return; } 4420 catch (InvalidOperationException) { return; } 4421 Assert.True(false); 4422 } 4423 4424 [Theory] 4425 [XmlWriterInlineData(WriterType.AllButCustom, "2002-12-30T00:00:00-08:00", "<Root>2002-12-30T00:00:00-08:00</Root>" )] 4426 [XmlWriterInlineData(WriterType.AllButCustom, "2000-02-29T23:59:59.999999999999-13:60", "<Root>2000-03-01T00:00:00-14:00</Root>" )] 4427 [XmlWriterInlineData(WriterType.AllButCustom, "0001-01-01T00:00:00+00:00", "<Root>0001-01-01T00:00:00Z</Root>" )] 4428 [XmlWriterInlineData(WriterType.AllButCustom, "0001-01-01T00:00:00.9999999-14:00", "<Root>0001-01-01T00:00:00.9999999-14:00</Root>" )] 4429 [XmlWriterInlineData(WriterType.AllButCustom, "9999-12-31T12:59:59.9999999+14:00", "<Root>9999-12-31T12:59:59.9999999+14:00</Root>" )] 4430 [XmlWriterInlineData(WriterType.AllButCustom, "9999-12-31T12:59:59-11:00", "<Root>9999-12-31T12:59:59-11:00</Root>" )] 4431 [XmlWriterInlineData(WriterType.AllButCustom, "2000-02-29T23:59:59.999999999999+13:60", "<Root>2000-03-01T00:00:00+14:00</Root>" )] writeValue_31(XmlWriterUtils utils, string value, string expectedValue)4432 public void writeValue_31(XmlWriterUtils utils, string value, string expectedValue) 4433 { 4434 DateTimeOffset a = XmlConvert.ToDateTimeOffset(value); 4435 using (XmlWriter w = utils.CreateWriter()) 4436 { 4437 w.WriteStartElement("Root"); 4438 w.WriteValue(XmlConvert.ToDateTimeOffset(value)); 4439 w.WriteEndElement(); 4440 } 4441 Assert.True((utils.CompareReader(expectedValue))); 4442 } 4443 4444 // WriteValue(new DateTimeOffset) - valid 4445 [Theory] 4446 [XmlWriterInlineData(WriterType.AllButCustom)] writeValue_32(XmlWriterUtils utils)4447 public void writeValue_32(XmlWriterUtils utils) 4448 { 4449 DateTimeOffset actual; 4450 string expect; 4451 bool isPassed = true; 4452 object[] actualArray = 4453 { 4454 new DateTimeOffset(2002,2,1,0,0,0,TimeSpan.FromHours(-8.0)), 4455 new DateTimeOffset(9999,1,1,0,0,0,TimeSpan.FromHours(-8.0)), 4456 new DateTimeOffset(9999,1,1,0,0,0,TimeSpan.FromHours(0)), 4457 new DateTimeOffset(9999,12,31,12,59,59,TimeSpan.FromHours(-11.0)), 4458 new DateTimeOffset(9999,12,31,12,59,59,TimeSpan.FromHours(-10) + TimeSpan.FromMinutes(-59)), 4459 new DateTimeOffset(9999,12,31,12,59,59,new TimeSpan(13,59,0)), 4460 new DateTimeOffset(9999,12,31,23,59,59,TimeSpan.FromHours(0)), 4461 new DateTimeOffset(9999,12,31,23,59,59, new TimeSpan(14,0,0)), 4462 new DateTimeOffset(9999,12,31,23,59,59, new TimeSpan(13,60,0)), 4463 new DateTimeOffset(9999,12,31,23,59,59, new TimeSpan(13,59,60)), 4464 new DateTimeOffset(9998,12,31,12,59,59, new TimeSpan(13,60,0)), 4465 new DateTimeOffset(9998,12,31,12,59,59,TimeSpan.FromHours(-14.0)), 4466 new DateTimeOffset(1,1,1,0,0,0,TimeSpan.FromHours(-8.0)), 4467 new DateTimeOffset(1,1,1,0,0,0,TimeSpan.FromHours(-14.0)), 4468 new DateTimeOffset(1,1,1,0,0,0,TimeSpan.FromHours(-13) + TimeSpan.FromMinutes(-59)), 4469 new DateTimeOffset(1,1,1,0,0,0,TimeSpan.Zero), 4470 }; 4471 object[] expectArray = 4472 { 4473 "<Root>2002-02-01T00:00:00-08:00</Root>", 4474 "<Root>9999-01-01T00:00:00-08:00</Root>", 4475 "<Root>9999-01-01T00:00:00Z</Root>", 4476 "<Root>9999-12-31T12:59:59-11:00</Root>", 4477 "<Root>9999-12-31T12:59:59-10:59</Root>", 4478 "<Root>9999-12-31T12:59:59+13:59</Root>", 4479 "<Root>9999-12-31T23:59:59Z</Root>", 4480 "<Root>9999-12-31T23:59:59+14:00</Root>", 4481 "<Root>9999-12-31T23:59:59+14:00</Root>", 4482 "<Root>9999-12-31T23:59:59+14:00</Root>", 4483 "<Root>9998-12-31T12:59:59+14:00</Root>", 4484 "<Root>9998-12-31T12:59:59-14:00</Root>", 4485 "<Root>0001-01-01T00:00:00-08:00</Root>", 4486 "<Root>0001-01-01T00:00:00-14:00</Root>", 4487 "<Root>0001-01-01T00:00:00-13:59</Root>", 4488 "<Root>0001-01-01T00:00:00Z</Root>" 4489 }; 4490 4491 for (int i = 0; i < actualArray.Length; i++) 4492 { 4493 actual = (DateTimeOffset)actualArray[i]; 4494 expect = (string)expectArray[i]; 4495 4496 using (XmlWriter w = utils.CreateWriter()) 4497 { 4498 w.WriteStartElement("Root"); 4499 w.WriteValue(actual); 4500 w.WriteEndElement(); 4501 w.Dispose(); 4502 if (!utils.CompareReader((string)expect)) 4503 { 4504 isPassed = false; 4505 } 4506 } 4507 } 4508 Assert.True((isPassed)); 4509 } 4510 4511 //[TestCase(Name = "LookupPrefix")] 4512 public partial class TCLookUpPrefix 4513 { 4514 // LookupPrefix with null 4515 [Theory] 4516 [XmlWriterInlineData] lookupPrefix_1(XmlWriterUtils utils)4517 public void lookupPrefix_1(XmlWriterUtils utils) 4518 { 4519 using (XmlWriter w = utils.CreateWriter()) 4520 { 4521 try 4522 { 4523 w.WriteStartElement("Root"); 4524 string s = w.LookupPrefix(null); 4525 w.Dispose(); 4526 } 4527 catch (ArgumentException e) 4528 { 4529 CError.WriteLineIgnore("Exception: " + e.ToString()); 4530 utils.CheckErrorState(w.WriteState); 4531 return; 4532 } 4533 } 4534 CError.WriteLine("Did not throw exception"); 4535 Assert.True(false); 4536 } 4537 4538 // LookupPrefix with String.Empty should return String.Empty 4539 [Theory] 4540 [XmlWriterInlineData] lookupPrefix_2(XmlWriterUtils utils)4541 public void lookupPrefix_2(XmlWriterUtils utils) 4542 { 4543 using (XmlWriter w = utils.CreateWriter()) 4544 { 4545 w.WriteStartElement("Root"); 4546 string s = w.LookupPrefix(String.Empty); 4547 CError.Compare(s, String.Empty, "Error"); 4548 } 4549 return; 4550 } 4551 4552 // LookupPrefix with generated namespace used for attributes 4553 [Theory] 4554 [XmlWriterInlineData] lookupPrefix_3(XmlWriterUtils utils)4555 public void lookupPrefix_3(XmlWriterUtils utils) 4556 { 4557 using (XmlWriter w = utils.CreateWriter()) 4558 { 4559 w.WriteStartElement("Root"); 4560 w.WriteAttributeString("a", "foo", "b"); 4561 string s = w.LookupPrefix("foo"); 4562 string exp = "p1"; 4563 CError.Compare(s, exp, "Error"); 4564 } 4565 return; 4566 } 4567 4568 // LookupPrefix for namespace used with element 4569 [Theory] 4570 [XmlWriterInlineData] lookupPrefix_4(XmlWriterUtils utils)4571 public void lookupPrefix_4(XmlWriterUtils utils) 4572 { 4573 using (XmlWriter w = utils.CreateWriter()) 4574 { 4575 w.WriteStartElement("ns1", "Root", "foo"); 4576 string s = w.LookupPrefix("foo"); 4577 CError.Compare(s, "ns1", "Error"); 4578 } 4579 return; 4580 } 4581 4582 // LookupPrefix for namespace used with attribute 4583 [Theory] 4584 [XmlWriterInlineData] lookupPrefix_5(XmlWriterUtils utils)4585 public void lookupPrefix_5(XmlWriterUtils utils) 4586 { 4587 using (XmlWriter w = utils.CreateWriter()) 4588 { 4589 w.WriteStartElement("Root"); 4590 w.WriteAttributeString("ns1", "attr1", "foo", "val1"); 4591 string s = w.LookupPrefix("foo"); 4592 CError.Compare(s, "ns1", "Error"); 4593 } 4594 return; 4595 } 4596 4597 // Lookup prefix for a default namespace 4598 [Theory] 4599 [XmlWriterInlineData] lookupPrefix_6(XmlWriterUtils utils)4600 public void lookupPrefix_6(XmlWriterUtils utils) 4601 { 4602 using (XmlWriter w = utils.CreateWriter()) 4603 { 4604 w.WriteStartElement("Root", "foo"); 4605 w.WriteString("content"); 4606 string s = w.LookupPrefix("foo"); 4607 CError.Compare(s, String.Empty, "Error"); 4608 } 4609 return; 4610 } 4611 4612 // Lookup prefix for nested element with same namespace but different prefix 4613 [Theory] 4614 [XmlWriterInlineData] lookupPrefix_7(XmlWriterUtils utils)4615 public void lookupPrefix_7(XmlWriterUtils utils) 4616 { 4617 string s = ""; 4618 using (XmlWriter w = utils.CreateWriter()) 4619 { 4620 w.WriteStartElement("x", "Root", "foo"); 4621 s = w.LookupPrefix("foo"); 4622 CError.Compare(s, "x", "Error"); 4623 4624 w.WriteStartElement("y", "node", "foo"); 4625 s = w.LookupPrefix("foo"); 4626 CError.Compare(s, "y", "Error"); 4627 4628 w.WriteStartElement("z", "node1", "foo"); 4629 s = w.LookupPrefix("foo"); 4630 CError.Compare(s, "z", "Error"); 4631 w.WriteEndElement(); 4632 4633 s = w.LookupPrefix("foo"); 4634 CError.Compare(s, "y", "Error"); 4635 w.WriteEndElement(); 4636 4637 w.WriteEndElement(); 4638 } 4639 return; 4640 } 4641 4642 // Lookup prefix for multiple prefix associated with the same namespace 4643 [Theory] 4644 [XmlWriterInlineData] lookupPrefix_8(XmlWriterUtils utils)4645 public void lookupPrefix_8(XmlWriterUtils utils) 4646 { 4647 using (XmlWriter w = utils.CreateWriter()) 4648 { 4649 w.WriteStartElement("x", "Root", "foo"); 4650 w.WriteAttributeString("y", "a", "foo", "b"); 4651 string s = w.LookupPrefix("foo"); 4652 CError.Compare(s, "y", "Error"); 4653 } 4654 return; 4655 } 4656 4657 // Lookup prefix for namespace defined outside the scope of an empty element and also defined in its parent 4658 [Theory] 4659 [XmlWriterInlineData] lookupPrefix_9(XmlWriterUtils utils)4660 public void lookupPrefix_9(XmlWriterUtils utils) 4661 { 4662 using (XmlWriter w = utils.CreateWriter()) 4663 { 4664 w.WriteStartElement("x", "Root", "foo"); 4665 w.WriteStartElement("y", "node", "foo"); 4666 w.WriteEndElement(); 4667 string s = w.LookupPrefix("foo"); 4668 CError.Compare(s, "x", "Error"); 4669 w.WriteEndElement(); 4670 } 4671 return; 4672 } 4673 4674 // Bug 53940: Lookup prefix for namespace declared as default and also with a prefix 4675 [Theory] 4676 [XmlWriterInlineData] lookupPrefix_10(XmlWriterUtils utils)4677 public void lookupPrefix_10(XmlWriterUtils utils) 4678 { 4679 string s; 4680 using (XmlWriter w = utils.CreateWriter()) 4681 { 4682 w.WriteStartElement("Root", "foo"); 4683 w.WriteStartElement("x", "node", "foo"); 4684 s = w.LookupPrefix("foo"); 4685 CError.Compare(s, "x", "Error in nested element"); 4686 w.WriteEndElement(); 4687 s = w.LookupPrefix("foo"); 4688 CError.Compare(s, String.Empty, "Error in root element"); 4689 w.WriteEndElement(); 4690 } 4691 return; 4692 } 4693 } 4694 4695 //[TestCase(Name = "XmlSpace")] 4696 public partial class TCXmlSpace 4697 { 4698 // Verify XmlSpace as Preserve 4699 [Theory] 4700 [XmlWriterInlineData] xmlSpace_1(XmlWriterUtils utils)4701 public void xmlSpace_1(XmlWriterUtils utils) 4702 { 4703 using (XmlWriter w = utils.CreateWriter()) 4704 { 4705 w.WriteStartElement("Root"); 4706 w.WriteAttributeString("xml", "space", null, "preserve"); 4707 CError.Compare(w.XmlSpace, XmlSpace.Preserve, "Error"); 4708 } 4709 return; 4710 } 4711 4712 // Verify XmlSpace as Default 4713 [Theory] 4714 [XmlWriterInlineData] xmlSpace_2(XmlWriterUtils utils)4715 public void xmlSpace_2(XmlWriterUtils utils) 4716 { 4717 using (XmlWriter w = utils.CreateWriter()) 4718 { 4719 w.WriteStartElement("Root"); 4720 w.WriteAttributeString("xml", "space", null, "default"); 4721 CError.Compare(w.XmlSpace, XmlSpace.Default, "Error"); 4722 } 4723 return; 4724 } 4725 4726 // Verify XmlSpace as None 4727 [Theory] 4728 [XmlWriterInlineData] xmlSpace_3(XmlWriterUtils utils)4729 public void xmlSpace_3(XmlWriterUtils utils) 4730 { 4731 using (XmlWriter w = utils.CreateWriter()) 4732 { 4733 w.WriteStartElement("Root"); 4734 CError.Compare(w.XmlSpace, XmlSpace.None, "Error"); 4735 } 4736 return; 4737 } 4738 4739 // Verify XmlSpace within an empty element 4740 [Theory] 4741 [XmlWriterInlineData] xmlSpace_4(XmlWriterUtils utils)4742 public void xmlSpace_4(XmlWriterUtils utils) 4743 { 4744 using (XmlWriter w = utils.CreateWriter()) 4745 { 4746 w.WriteStartElement("Root"); 4747 w.WriteAttributeString("xml", "space", null, "preserve"); 4748 w.WriteStartElement("node", null); 4749 4750 CError.Compare(w.XmlSpace, XmlSpace.Preserve, "Error"); 4751 4752 w.WriteEndElement(); 4753 w.WriteEndElement(); 4754 } 4755 return; 4756 } 4757 4758 // Verify XmlSpace - scope with nested elements (both PROLOG and EPILOG) 4759 [Theory] 4760 [XmlWriterInlineData] xmlSpace_5(XmlWriterUtils utils)4761 public void xmlSpace_5(XmlWriterUtils utils) 4762 { 4763 using (XmlWriter w = utils.CreateWriter()) 4764 { 4765 w.WriteStartElement("Root"); 4766 4767 w.WriteStartElement("node", null); 4768 w.WriteAttributeString("xml", "space", null, "preserve"); 4769 CError.Compare(w.XmlSpace, XmlSpace.Preserve, "Error"); 4770 4771 w.WriteStartElement("node1"); 4772 CError.Compare(w.XmlSpace, XmlSpace.Preserve, "Error"); 4773 4774 w.WriteStartElement("node2"); 4775 w.WriteAttributeString("xml", "space", null, "default"); 4776 CError.Compare(w.XmlSpace, XmlSpace.Default, "Error"); 4777 w.WriteEndElement(); 4778 4779 CError.Compare(w.XmlSpace, XmlSpace.Preserve, "Error"); 4780 w.WriteEndElement(); 4781 4782 CError.Compare(w.XmlSpace, XmlSpace.Preserve, "Error"); 4783 w.WriteEndElement(); 4784 4785 CError.Compare(w.XmlSpace, XmlSpace.None, "Error"); 4786 w.WriteEndElement(); 4787 } 4788 4789 return; 4790 } 4791 4792 // Verify XmlSpace - outside defined scope 4793 [Theory] 4794 [XmlWriterInlineData] xmlSpace_6(XmlWriterUtils utils)4795 public void xmlSpace_6(XmlWriterUtils utils) 4796 { 4797 using (XmlWriter w = utils.CreateWriter()) 4798 { 4799 w.WriteStartElement("Root"); 4800 w.WriteStartElement("node", null); 4801 w.WriteAttributeString("xml", "space", null, "preserve"); 4802 w.WriteEndElement(); 4803 4804 CError.Compare(w.XmlSpace, XmlSpace.None, "Error"); 4805 w.WriteEndElement(); 4806 } 4807 4808 return; 4809 } 4810 4811 // Verify XmlSpace with invalid space value 4812 [Theory] 4813 [XmlWriterInlineData] xmlSpace_7(XmlWriterUtils utils)4814 public void xmlSpace_7(XmlWriterUtils utils) 4815 { 4816 using (XmlWriter w = utils.CreateWriter()) 4817 { 4818 try 4819 { 4820 w.WriteStartElement("Root"); 4821 w.WriteStartElement("node", null); 4822 w.WriteAttributeString("xml", "space", null, "reserve"); 4823 } 4824 catch (ArgumentException e) 4825 { 4826 CError.WriteLineIgnore(e.ToString()); 4827 CError.Compare(w.WriteState, WriteState.Error, "WriteState should be Error"); 4828 return; 4829 } 4830 } 4831 CError.WriteLine("Exception expected"); 4832 Assert.True(false); 4833 } 4834 4835 // Duplicate xml:space attr should error 4836 [Theory] 4837 [XmlWriterInlineData] xmlSpace_8(XmlWriterUtils utils)4838 public void xmlSpace_8(XmlWriterUtils utils) 4839 { 4840 using (XmlWriter w = utils.CreateWriter()) 4841 { 4842 try 4843 { 4844 w.WriteStartElement("Root"); 4845 w.WriteAttributeString("xml", "space", null, "preserve"); 4846 w.WriteAttributeString("xml", "space", null, "default"); 4847 } 4848 catch (XmlException e) 4849 { 4850 CError.WriteLineIgnore(e.ToString()); 4851 CError.Compare(w.WriteState, WriteState.Error, "WriteState should be Error"); 4852 return; 4853 } 4854 } 4855 CError.WriteLine("Exception expected"); 4856 Assert.True(false); 4857 } 4858 4859 // Verify XmlSpace value when received through WriteString 4860 [Theory] 4861 [XmlWriterInlineData] xmlSpace_9(XmlWriterUtils utils)4862 public void xmlSpace_9(XmlWriterUtils utils) 4863 { 4864 using (XmlWriter w = utils.CreateWriter()) 4865 { 4866 w.WriteStartElement("Root"); 4867 w.WriteStartAttribute("xml", "space", null); 4868 w.WriteString("default"); 4869 w.WriteEndAttribute(); 4870 4871 CError.Compare(w.XmlSpace, XmlSpace.Default, "Error"); 4872 w.WriteEndElement(); 4873 } 4874 return; 4875 } 4876 } 4877 4878 //[TestCase(Name = "XmlLang")] 4879 public partial class TCXmlLang 4880 { 4881 // Verify XmlLang sanity test 4882 [Theory] 4883 [XmlWriterInlineData] XmlLang_1(XmlWriterUtils utils)4884 public void XmlLang_1(XmlWriterUtils utils) 4885 { 4886 using (XmlWriter w = utils.CreateWriter()) 4887 { 4888 w.WriteStartElement("Root"); 4889 w.WriteStartElement("node", null); 4890 w.WriteAttributeString("xml", "lang", null, "en"); 4891 4892 CError.Compare(w.XmlLang, "en", "Error"); 4893 4894 w.WriteEndElement(); 4895 w.WriteEndElement(); 4896 } 4897 return; 4898 } 4899 4900 // Verify that default value of XmlLang is NULL 4901 [Theory] 4902 [XmlWriterInlineData] XmlLang_2(XmlWriterUtils utils)4903 public void XmlLang_2(XmlWriterUtils utils) 4904 { 4905 using (XmlWriter w = utils.CreateWriter()) 4906 { 4907 w.WriteStartElement("Root"); 4908 if (w.XmlLang != null) 4909 { 4910 w.Dispose(); 4911 CError.WriteLine("Default value if no xml:lang attributes are currently on the stack should be null"); 4912 CError.WriteLine("Actual value: {0}", w.XmlLang.ToString()); 4913 Assert.True(false); 4914 } 4915 } 4916 return; 4917 } 4918 4919 // Verify XmlLang scope inside nested elements (both PROLOG and EPILOG) 4920 [Theory] 4921 [XmlWriterInlineData] XmlLang_3(XmlWriterUtils utils)4922 public void XmlLang_3(XmlWriterUtils utils) 4923 { 4924 using (XmlWriter w = utils.CreateWriter()) 4925 { 4926 w.WriteStartElement("Root"); 4927 4928 w.WriteStartElement("node", null); 4929 w.WriteAttributeString("xml", "lang", null, "fr"); 4930 CError.Compare(w.XmlLang, "fr", "Error"); 4931 4932 w.WriteStartElement("node1"); 4933 w.WriteAttributeString("xml", "lang", null, "en-US"); 4934 CError.Compare(w.XmlLang, "en-US", "Error"); 4935 4936 w.WriteStartElement("node2"); 4937 CError.Compare(w.XmlLang, "en-US", "Error"); 4938 w.WriteEndElement(); 4939 4940 CError.Compare(w.XmlLang, "en-US", "Error"); 4941 w.WriteEndElement(); 4942 4943 CError.Compare(w.XmlLang, "fr", "Error"); 4944 w.WriteEndElement(); 4945 4946 CError.Compare(w.XmlLang, null, "Error"); 4947 w.WriteEndElement(); 4948 } 4949 return; 4950 } 4951 4952 // Duplicate xml:lang attr should error 4953 [Theory] 4954 [XmlWriterInlineData] XmlLang_4(XmlWriterUtils utils)4955 public void XmlLang_4(XmlWriterUtils utils) 4956 { 4957 /*if (WriterType == WriterType.XmlTextWriter) 4958 return;*/ 4959 4960 using (XmlWriter w = utils.CreateWriter()) 4961 { 4962 try 4963 { 4964 w.WriteStartElement("Root"); 4965 w.WriteAttributeString("xml", "lang", null, "en-us"); 4966 w.WriteAttributeString("xml", "lang", null, "ja"); 4967 } 4968 catch (XmlException e) 4969 { 4970 CError.WriteLineIgnore(e.ToString()); 4971 CError.Compare(w.WriteState, WriteState.Error, "WriteState should be Error"); 4972 return; 4973 } 4974 } 4975 CError.WriteLine("Exception expected"); 4976 Assert.True(false); 4977 } 4978 4979 // Verify XmlLang value when received through WriteAttributes 4980 [Theory] 4981 [XmlWriterInlineData] XmlLang_5(XmlWriterUtils utils)4982 public void XmlLang_5(XmlWriterUtils utils) 4983 { 4984 XmlReaderSettings xrs = new XmlReaderSettings(); 4985 xrs.IgnoreWhitespace = true; 4986 XmlReader tr = XmlReader.Create(FilePathUtil.getStream(XmlWriterUtils.FullPath("XmlReader.xml")), xrs); 4987 4988 while (tr.Read()) 4989 { 4990 if (tr.LocalName == "XmlLangNode") 4991 { 4992 tr.Read(); 4993 tr.MoveToNextAttribute(); 4994 break; 4995 } 4996 } 4997 4998 using (XmlWriter w = utils.CreateWriter()) 4999 { 5000 w.WriteStartElement("Root"); 5001 w.WriteAttributes(tr, false); 5002 5003 CError.Compare(w.XmlLang, "fr", "Error"); 5004 w.WriteEndElement(); 5005 } 5006 return; 5007 } 5008 5009 // Verify XmlLang value when received through WriteString 5010 [Theory] 5011 [XmlWriterInlineData] XmlLang_6(XmlWriterUtils utils)5012 public void XmlLang_6(XmlWriterUtils utils) 5013 { 5014 using (XmlWriter w = utils.CreateWriter()) 5015 { 5016 w.WriteStartElement("Root"); 5017 w.WriteStartAttribute("xml", "lang", null); 5018 w.WriteString("en-US"); 5019 w.WriteEndAttribute(); 5020 5021 CError.Compare(w.XmlLang, "en-US", "Error"); 5022 w.WriteEndElement(); 5023 } 5024 return; 5025 } 5026 5027 // Should not check XmlLang value 5028 [Theory] 5029 [XmlWriterInlineData] XmlLang_7(XmlWriterUtils utils)5030 public void XmlLang_7(XmlWriterUtils utils) 5031 { 5032 string[] langs = new string[] { "en-", "e n", "en", "en-US", "e?", "en*US" }; 5033 5034 for (int i = 0; i < langs.Length; i++) 5035 { 5036 using (XmlWriter w = utils.CreateWriter()) 5037 { 5038 w.WriteStartElement("Root"); 5039 w.WriteAttributeString("xml", "lang", null, langs[i]); 5040 w.WriteEndElement(); 5041 } 5042 5043 string strExp = "<Root xml:lang=\"" + langs[i] + "\" />"; 5044 if (!utils.CompareReader(strExp)) 5045 Assert.True(false); 5046 } 5047 return; 5048 } 5049 5050 // More XmlLang with valid sequence 5051 [Theory] 5052 [XmlWriterInlineData] XmlLang_8(XmlWriterUtils utils)5053 public void XmlLang_8(XmlWriterUtils utils) 5054 { 5055 using (XmlWriter w = utils.CreateWriter()) 5056 { 5057 w.WriteStartElement("Root"); 5058 w.WriteAttributeString("xml", "lang", null, "U.S.A."); 5059 } 5060 return; 5061 } 5062 } 5063 5064 //[TestCase(Name = "WriteRaw")] 5065 public partial class TCWriteRaw : TCWriteBuffer 5066 { 5067 // Call both WriteRaw Methods 5068 [Theory] 5069 [XmlWriterInlineData] writeRaw_1(XmlWriterUtils utils)5070 public void writeRaw_1(XmlWriterUtils utils) 5071 { 5072 using (XmlWriter w = utils.CreateWriter()) 5073 { 5074 string t = "Test Case"; 5075 w.WriteStartElement("Root"); 5076 w.WriteStartAttribute("a"); 5077 w.WriteRaw(t); 5078 w.WriteStartAttribute("b"); 5079 w.WriteRaw(t.ToCharArray(), 0, 4); 5080 w.WriteEndElement(); 5081 } 5082 Assert.True(utils.CompareReader("<Root a=\"Test Case\" b=\"Test\" />")); 5083 } 5084 5085 // WriteRaw with entites and entitized characters 5086 [Theory] 5087 [XmlWriterInlineData] writeRaw_2(XmlWriterUtils utils)5088 public void writeRaw_2(XmlWriterUtils utils) 5089 { 5090 using (XmlWriter w = utils.CreateWriter()) 5091 { 5092 String t = "<node a=\"&'b\">\" c=\"'d\">&</node>"; 5093 5094 w.WriteStartElement("Root"); 5095 w.WriteRaw(t); 5096 w.WriteEndElement(); 5097 } 5098 5099 string strExp = "<Root><node a=\"&'b\">\" c=\"'d\">&</node></Root>"; 5100 5101 Assert.True(utils.CompareString(strExp)); 5102 } 5103 5104 // WriteRaw with entire Xml Document in string 5105 [Theory] 5106 [XmlWriterInlineData] writeRaw_3(XmlWriterUtils utils)5107 public void writeRaw_3(XmlWriterUtils utils) 5108 { 5109 XmlWriter w = utils.CreateWriter(); 5110 String t = "<root><node1></node1><node2></node2></root>"; 5111 5112 w.WriteRaw(t); 5113 5114 w.Dispose(); 5115 Assert.True(utils.CompareReader("<root><node1></node1><node2></node2></root>")); 5116 } 5117 5118 // Call WriteRaw to write the value of xml:space 5119 [Theory] 5120 [XmlWriterInlineData] writeRaw_4(XmlWriterUtils utils)5121 public void writeRaw_4(XmlWriterUtils utils) 5122 { 5123 using (XmlWriter w = utils.CreateWriter()) 5124 { 5125 w.WriteStartElement("Root"); 5126 w.WriteStartAttribute("xml", "space", null); 5127 w.WriteRaw("default"); 5128 w.WriteEndAttribute(); 5129 w.WriteEndElement(); 5130 } 5131 Assert.True(utils.CompareReader("<Root xml:space=\"default\" />")); 5132 } 5133 5134 // Call WriteRaw to write the value of xml:lang 5135 [Theory] 5136 [XmlWriterInlineData] writerRaw_5(XmlWriterUtils utils)5137 public void writerRaw_5(XmlWriterUtils utils) 5138 { 5139 using (XmlWriter w = utils.CreateWriter()) 5140 { 5141 string strraw = "abc"; 5142 char[] buffer = strraw.ToCharArray(); 5143 5144 w.WriteStartElement("root"); 5145 w.WriteStartAttribute("xml", "lang", null); 5146 w.WriteRaw(buffer, 1, 1); 5147 w.WriteRaw(buffer, 0, 2); 5148 w.WriteEndAttribute(); 5149 w.WriteEndElement(); 5150 } 5151 Assert.True(utils.CompareReader("<root xml:lang=\"bab\" />")); 5152 } 5153 5154 // WriteRaw with count > buffer size 5155 [Theory] 5156 [XmlWriterInlineData] writeRaw_6(XmlWriterUtils utils)5157 public void writeRaw_6(XmlWriterUtils utils) 5158 { 5159 VerifyInvalidWrite(utils, "WriteRaw", 5, 0, 6, typeof(ArgumentOutOfRangeException/*ArgumentException*/)); 5160 } 5161 5162 // WriteRaw with count < 0 5163 [Theory] 5164 [XmlWriterInlineData] writeRaw_7(XmlWriterUtils utils)5165 public void writeRaw_7(XmlWriterUtils utils) 5166 { 5167 VerifyInvalidWrite(utils, "WriteRaw", 5, 2, -1, typeof(ArgumentOutOfRangeException)); 5168 } 5169 5170 // WriteRaw with index > buffer size 5171 [Theory] 5172 [XmlWriterInlineData] writeRaw_8(XmlWriterUtils utils)5173 public void writeRaw_8(XmlWriterUtils utils) 5174 { 5175 VerifyInvalidWrite(utils, "WriteRaw", 5, 6, 1, typeof(ArgumentOutOfRangeException/*ArgumentException*/)); 5176 } 5177 5178 // WriteRaw with index < 0 5179 [Theory] 5180 [XmlWriterInlineData] writeRaw_9(XmlWriterUtils utils)5181 public void writeRaw_9(XmlWriterUtils utils) 5182 { 5183 VerifyInvalidWrite(utils, "WriteRaw", 5, -1, 1, typeof(ArgumentOutOfRangeException)); 5184 } 5185 5186 // WriteRaw with index + count exceeds buffer 5187 [Theory] 5188 [XmlWriterInlineData] writeRaw_10(XmlWriterUtils utils)5189 public void writeRaw_10(XmlWriterUtils utils) 5190 { 5191 VerifyInvalidWrite(utils, "WriteRaw", 5, 2, 5, typeof(ArgumentOutOfRangeException/*ArgumentException*/)); 5192 } 5193 5194 // WriteRaw with buffer = null 5195 [Theory] 5196 [XmlWriterInlineData] writeRaw_11(XmlWriterUtils utils)5197 public void writeRaw_11(XmlWriterUtils utils) 5198 { 5199 using (XmlWriter w = utils.CreateWriter()) 5200 { 5201 try 5202 { 5203 w.WriteStartElement("Root"); 5204 w.WriteRaw(null, 0, 0); 5205 } 5206 catch (ArgumentNullException) 5207 { 5208 CError.Compare(w.WriteState, WriteState.Error, "WriteState should be Error"); 5209 return; 5210 } 5211 } 5212 CError.WriteLine("Did not throw exception"); 5213 Assert.True(false); 5214 } 5215 5216 // WriteRaw with valid surrogate pair 5217 [Theory] 5218 [XmlWriterInlineData] writeRaw_12(XmlWriterUtils utils)5219 public void writeRaw_12(XmlWriterUtils utils) 5220 { 5221 using (XmlWriter w = utils.CreateWriter()) 5222 { 5223 w.WriteStartElement("Root"); 5224 5225 string str = "\uD812\uDD12"; 5226 char[] chr = str.ToCharArray(); 5227 5228 w.WriteRaw(str); 5229 w.WriteRaw(chr, 0, chr.Length); 5230 w.WriteEndElement(); 5231 } 5232 string strExp = "<Root>\uD812\uDD12\uD812\uDD12</Root>"; 5233 Assert.True(utils.CompareReader(strExp)); 5234 } 5235 5236 // WriteRaw with invalid surrogate pair 5237 [Theory] 5238 [XmlWriterInlineData] writeRaw_13(XmlWriterUtils utils)5239 public void writeRaw_13(XmlWriterUtils utils) 5240 { 5241 using (XmlWriter w = utils.CreateWriter()) 5242 { 5243 try 5244 { 5245 w.WriteStartElement("Root"); 5246 w.WriteRaw("\uD812"); 5247 } 5248 catch (ArgumentException e) 5249 { 5250 CError.WriteLineIgnore(e.ToString()); 5251 CError.Compare(w.WriteState, WriteState.Error, "WriteState should be Error"); 5252 return; 5253 } 5254 } 5255 CError.WriteLine("Did not throw exception"); 5256 Assert.True(false); 5257 } 5258 5259 // Index = Count = 0 5260 [Theory] 5261 [XmlWriterInlineData] writeRaw_14(XmlWriterUtils utils)5262 public void writeRaw_14(XmlWriterUtils utils) 5263 { 5264 string lang = new String('a', 1); 5265 char[] buffer = lang.ToCharArray(); 5266 5267 using (XmlWriter w = utils.CreateWriter()) 5268 { 5269 w.WriteStartElement("root"); 5270 w.WriteStartAttribute("xml", "lang", null); 5271 w.WriteRaw(buffer, 0, 0); 5272 w.WriteEndElement(); 5273 } 5274 Assert.True(utils.CompareReader("<root xml:lang=\"\" />")); 5275 } 5276 } 5277 5278 //[TestCase(Name = "WriteBase64")] 5279 public partial class TCWriteBase64 : TCWriteBuffer 5280 { 5281 // Base64LineSize = 76, test around this boundary size 5282 [Theory] 5283 [XmlWriterInlineData(75)] 5284 [XmlWriterInlineData(76)] 5285 [XmlWriterInlineData(77)] 5286 [XmlWriterInlineData(1024)] 5287 [XmlWriterInlineData(4096)] Base64_1(XmlWriterUtils utils, int strBase64Len)5288 public void Base64_1(XmlWriterUtils utils, int strBase64Len) 5289 { 5290 String strBase64 = String.Empty; 5291 for (int i = 0; i < strBase64Len; i++) 5292 { 5293 strBase64 += "A"; 5294 } 5295 5296 byte[] Wbase64 = new byte[strBase64Len * 2]; 5297 int Wbase64len = 0; 5298 5299 for (int i = 0; i < strBase64.Length; i++) 5300 { 5301 WriteToBuffer(ref Wbase64, ref Wbase64len, System.BitConverter.GetBytes(strBase64[i])); 5302 } 5303 5304 using (XmlWriter w = utils.CreateWriter()) 5305 { 5306 w.WriteStartElement("root"); 5307 w.WriteBase64(Wbase64, 0, (int)Wbase64len); 5308 w.WriteEndElement(); 5309 } 5310 5311 XmlReader r = utils.GetReader(); 5312 r.Read(); 5313 byte[] buffer = new byte[strBase64Len * 2]; 5314 int nRead = r.ReadElementContentAsBase64(buffer, 0, strBase64Len * 2); 5315 r.Dispose(); 5316 5317 CError.Compare(nRead, strBase64Len * 2, "Read count"); 5318 5319 string strRes = String.Empty; 5320 for (int i = 0; i < nRead; i += 2) 5321 { 5322 strRes += BitConverter.ToChar(buffer, i); 5323 } 5324 CError.Compare(strRes, strBase64, "Base64 value"); 5325 5326 return; 5327 } 5328 5329 // WriteBase64 with count > buffer size 5330 [Theory] 5331 [XmlWriterInlineData] Base64_2(XmlWriterUtils utils)5332 public void Base64_2(XmlWriterUtils utils) 5333 { 5334 VerifyInvalidWrite(utils, "WriteBase64", 5, 0, 6, typeof(ArgumentOutOfRangeException/*ArgumentException*/)); 5335 } 5336 5337 // WriteBase64 with count < 0 5338 [Theory] 5339 [XmlWriterInlineData] Base64_3(XmlWriterUtils utils)5340 public void Base64_3(XmlWriterUtils utils) 5341 { 5342 VerifyInvalidWrite(utils, "WriteBase64", 5, 2, -1, typeof(ArgumentOutOfRangeException)); 5343 } 5344 5345 // WriteBase64 with index > buffer size 5346 [Theory] 5347 [XmlWriterInlineData] Base64_4(XmlWriterUtils utils)5348 public void Base64_4(XmlWriterUtils utils) 5349 { 5350 VerifyInvalidWrite(utils, "WriteBase64", 5, 5, 1, typeof(ArgumentOutOfRangeException/*ArgumentException*/)); 5351 } 5352 5353 // WriteBase64 with index < 0 5354 [Theory] 5355 [XmlWriterInlineData] Base64_5(XmlWriterUtils utils)5356 public void Base64_5(XmlWriterUtils utils) 5357 { 5358 VerifyInvalidWrite(utils, "WriteBase64", 5, -1, 1, typeof(ArgumentOutOfRangeException)); 5359 } 5360 5361 // WriteBase64 with index + count exceeds buffer 5362 [Theory] 5363 [XmlWriterInlineData] Base64_6(XmlWriterUtils utils)5364 public void Base64_6(XmlWriterUtils utils) 5365 { 5366 VerifyInvalidWrite(utils, "WriteBase64", 5, 2, 5, typeof(ArgumentOutOfRangeException/*ArgumentException*/)); 5367 } 5368 5369 // WriteBase64 with buffer = null 5370 [Theory] 5371 [XmlWriterInlineData] Base64_7(XmlWriterUtils utils)5372 public void Base64_7(XmlWriterUtils utils) 5373 { 5374 using (XmlWriter w = utils.CreateWriter()) 5375 { 5376 try 5377 { 5378 w.WriteStartElement("root"); 5379 w.WriteBase64(null, 0, 0); 5380 } 5381 catch (ArgumentNullException) 5382 { 5383 CError.Compare(w.WriteState, WriteState.Error, "WriteState should be Error"); 5384 return; 5385 } 5386 } 5387 CError.WriteLine("Did not throw exception"); 5388 Assert.True(false); 5389 } 5390 5391 // Index = Count = 0 5392 [Theory] 5393 [XmlWriterInlineData] Base64_8(XmlWriterUtils utils)5394 public void Base64_8(XmlWriterUtils utils) 5395 { 5396 byte[] buffer = new byte[10]; 5397 5398 using (XmlWriter w = utils.CreateWriter()) 5399 { 5400 w.WriteStartElement("root"); 5401 w.WriteStartAttribute("foo"); 5402 w.WriteBase64(buffer, 0, 0); 5403 w.WriteEndElement(); 5404 } 5405 Assert.True(utils.CompareReader("<root foo=\"\" />")); 5406 } 5407 5408 [Theory] 5409 [XmlWriterInlineData("lang")] 5410 [XmlWriterInlineData("space")] 5411 [XmlWriterInlineData("ns")] Base64_9(XmlWriterUtils utils, string param)5412 public void Base64_9(XmlWriterUtils utils, string param) 5413 { 5414 byte[] buffer = new byte[10]; 5415 5416 using (XmlWriter w = utils.CreateWriter()) 5417 { 5418 try 5419 { 5420 w.WriteStartElement("root"); 5421 switch (param) 5422 { 5423 case "lang": 5424 w.WriteStartAttribute("xml", "lang", null); 5425 break; 5426 case "space": 5427 w.WriteStartAttribute("xml", "space", null); 5428 break; 5429 case "ns": 5430 w.WriteStartAttribute("xmlns", "foo", null); 5431 break; 5432 } 5433 w.WriteBase64(buffer, 0, 5); 5434 } 5435 catch (InvalidOperationException) 5436 { 5437 return; 5438 } 5439 } 5440 5441 CError.WriteLine("Did not throw exception"); 5442 Assert.True(false); 5443 } 5444 5445 // WriteBase64 should flush the buffer if WriteString is called 5446 [Theory] 5447 [XmlWriterInlineData] Base64_11(XmlWriterUtils utils)5448 public void Base64_11(XmlWriterUtils utils) 5449 { 5450 using (XmlWriter w = utils.CreateWriter()) 5451 { 5452 w.WriteStartElement("fromname"); 5453 w.WriteString("=?gb2312?B?"); 5454 w.Flush(); 5455 byte[] bytesFrom = new byte[] { 1, 2 }; 5456 w.WriteBase64(bytesFrom, 0, bytesFrom.Length); 5457 w.Flush(); 5458 w.WriteString("?="); 5459 w.Flush(); 5460 w.WriteEndElement(); 5461 } 5462 5463 string strExp = "<fromname>=?gb2312?B?AQI=?=</fromname>"; 5464 utils.CompareString(strExp); 5465 return; 5466 } 5467 5468 // XmlWriter.WriteBase64 inserts new lines where they should not be... 5469 [Theory] 5470 [XmlWriterInlineData] Base64_12(XmlWriterUtils utils)5471 public void Base64_12(XmlWriterUtils utils) 5472 { 5473 byte[][] byteArrays = new byte[][] 5474 { 5475 new byte[] {0xd8,0x7e,0x8d,0xf9,0x84,0x06,0x4a,0x67,0x93,0xba,0xc1,0x0d,0x16,0x53,0xb2,0xcc,0xbb,0x03,0xe3,0xf9}, 5476 new byte[] { 5477 0xaa, 5478 0x48, 5479 0x60, 5480 0x49, 5481 0xa1, 5482 0xb4, 5483 0xa2, 5484 0xe4, 5485 0x65, 5486 0x74, 5487 0x5e, 5488 0xc8, 5489 0x84, 5490 0x33, 5491 0xae, 5492 0x6a, 5493 0xe3, 5494 0xb5, 5495 0x2f, 5496 0x8c, 5497 }, 5498 new byte[] { 5499 0x46, 5500 0xe4, 5501 0xf9, 5502 0xb9, 5503 0x3e, 5504 0xb6, 5505 0x6b, 5506 0x3f, 5507 0xf9, 5508 0x01, 5509 0x67, 5510 0x5b, 5511 0xf5, 5512 0x2c, 5513 0xfd, 5514 0xe6, 5515 0x8e, 5516 0x52, 5517 0xc4, 5518 0x1b, 5519 }, 5520 new byte[] { 5521 0x55, 5522 0xca, 5523 0x97, 5524 0xfb, 5525 0xaa, 5526 0xc6, 5527 0x9a, 5528 0x69, 5529 0xa0, 5530 0x2e, 5531 0x1f, 5532 0xa7, 5533 0xa9, 5534 0x3c, 5535 0x62, 5536 0xe9, 5537 0xa1, 5538 0xf3, 5539 0x0a, 5540 0x07, 5541 }, 5542 new byte[] { 5543 0x28, 5544 0x82, 5545 0xb7, 5546 0xbe, 5547 0x49, 5548 0x45, 5549 0x37, 5550 0x54, 5551 0x26, 5552 0x31, 5553 0xd4, 5554 0x24, 5555 0xa6, 5556 0x5a, 5557 0xb6, 5558 0x6b, 5559 0x37, 5560 0xf3, 5561 0xaf, 5562 0x38, 5563 }, 5564 new byte[] { 5565 0xdd, 5566 0xbd, 5567 0x3f, 5568 0x8f, 5569 0xd5, 5570 0xeb, 5571 0x5b, 5572 0xcc, 5573 0x9d, 5574 0xdd, 5575 0x00, 5576 0xba, 5577 0x90, 5578 0x76, 5579 0x4c, 5580 0xcb, 5581 0xd3, 5582 0xd5, 5583 0xfa, 5584 0xd2, 5585 } 5586 }; 5587 5588 XmlWriter writer = utils.CreateWriter(); 5589 writer.WriteStartElement("Root"); 5590 for (int i = 0; i < byteArrays.Length; i++) 5591 { 5592 writer.WriteStartElement("DigestValue"); 5593 byte[] bytes = byteArrays[i]; 5594 writer.WriteBase64(bytes, 0, bytes.Length); 5595 writer.WriteEndElement(); 5596 } 5597 writer.WriteEndElement(); 5598 writer.Dispose(); 5599 5600 Assert.True(utils.CompareBaseline("bug364698.xml")); 5601 } 5602 5603 // XmlWriter does not flush Base64 data on the Close 5604 [Theory] 5605 [XmlWriterInlineData(WriterType.All & ~WriterType.Async)] Base64_13(XmlWriterUtils utils)5606 public void Base64_13(XmlWriterUtils utils) 5607 { 5608 byte[] data = new byte[] { 60, 65, 47, 62 }; // <A/> 5609 5610 XmlWriterSettings ws = new XmlWriterSettings(); 5611 ws.ConformanceLevel = ConformanceLevel.Fragment; 5612 5613 StringBuilder sb = new StringBuilder(); 5614 using (XmlWriter w = WriterHelper.Create(sb, ws, overrideAsync: true, async: utils.Async)) 5615 { 5616 w.WriteBase64(data, 0, data.Length); 5617 } 5618 5619 Assert.Equal("PEEvPg==", sb.ToString()); 5620 } 5621 } 5622 5623 //[TestCase(Name = "WriteBinHex")] 5624 public partial class TCWriteBinHex : TCWriteBuffer 5625 { 5626 // Call WriteBinHex with correct byte, index, and count 5627 [Theory] 5628 [XmlWriterInlineData] BinHex_1(XmlWriterUtils utils)5629 public void BinHex_1(XmlWriterUtils utils) 5630 { 5631 using (XmlWriter w = utils.CreateWriter()) 5632 { 5633 w.WriteStartElement("root"); 5634 5635 string str = "abcdefghijk1234567890"; 5636 byte[] buffer = StringToByteArray(str); 5637 w.WriteBinHex(buffer, 0, str.Length * 2); 5638 w.WriteEndElement(); 5639 } 5640 return; 5641 } 5642 5643 // WriteBinHex with count > buffer size 5644 [Theory] 5645 [XmlWriterInlineData] BinHex_2(XmlWriterUtils utils)5646 public void BinHex_2(XmlWriterUtils utils) 5647 { 5648 VerifyInvalidWrite(utils, "WriteBinHex", 5, 0, 6, typeof(ArgumentOutOfRangeException/*ArgumentException*/)); 5649 } 5650 5651 // WriteBinHex with count < 0 5652 [Theory] 5653 [XmlWriterInlineData] BinHex_3(XmlWriterUtils utils)5654 public void BinHex_3(XmlWriterUtils utils) 5655 { 5656 VerifyInvalidWrite(utils, "WriteBinHex", 5, 2, -1, typeof(ArgumentOutOfRangeException)); 5657 } 5658 5659 // WriteBinHex with index > buffer size 5660 [Theory] 5661 [XmlWriterInlineData] BinHex_4(XmlWriterUtils utils)5662 public void BinHex_4(XmlWriterUtils utils) 5663 { 5664 VerifyInvalidWrite(utils, "WriteBinHex", 5, 5, 1, typeof(ArgumentOutOfRangeException/*ArgumentException*/)); 5665 } 5666 5667 // WriteBinHex with index < 0 5668 [Theory] 5669 [XmlWriterInlineData] BinHex_5(XmlWriterUtils utils)5670 public void BinHex_5(XmlWriterUtils utils) 5671 { 5672 VerifyInvalidWrite(utils, "WriteBinHex", 5, -1, 1, typeof(ArgumentOutOfRangeException)); 5673 } 5674 5675 // WriteBinHex with index + count exceeds buffer 5676 [Theory] 5677 [XmlWriterInlineData] BinHex_6(XmlWriterUtils utils)5678 public void BinHex_6(XmlWriterUtils utils) 5679 { 5680 VerifyInvalidWrite(utils, "WriteBinHex", 5, 2, 5, typeof(ArgumentOutOfRangeException/*ArgumentException*/)); 5681 } 5682 5683 // WriteBinHex with buffer = null 5684 [Theory] 5685 [XmlWriterInlineData] BinHex_7(XmlWriterUtils utils)5686 public void BinHex_7(XmlWriterUtils utils) 5687 { 5688 using (XmlWriter w = utils.CreateWriter()) 5689 { 5690 try 5691 { 5692 w.WriteStartElement("root"); 5693 w.WriteBinHex(null, 0, 0); 5694 } 5695 catch (ArgumentNullException) 5696 { 5697 if (utils.WriterType == WriterType.CustomWriter) 5698 { 5699 CError.Compare(w.WriteState, WriteState.Element, "WriteState should be Element"); 5700 } 5701 else 5702 { 5703 utils.CheckErrorState(w.WriteState); 5704 } 5705 return; 5706 } 5707 } 5708 CError.WriteLine("Did not throw exception"); 5709 Assert.True(false); 5710 } 5711 5712 // Index = Count = 0 5713 [Theory] 5714 [XmlWriterInlineData] BinHex_8(XmlWriterUtils utils)5715 public void BinHex_8(XmlWriterUtils utils) 5716 { 5717 byte[] buffer = new byte[10]; 5718 5719 using (XmlWriter w = utils.CreateWriter()) 5720 { 5721 w.WriteStartElement("root"); 5722 w.WriteStartAttribute("xml", "lang", null); 5723 w.WriteBinHex(buffer, 0, 0); 5724 w.WriteEndElement(); 5725 } 5726 Assert.True(utils.CompareReader("<root xml:lang=\"\" />")); 5727 } 5728 5729 // Call WriteBinHex as an attribute value 5730 [Theory] 5731 [XmlWriterInlineData] BinHex_9(XmlWriterUtils utils)5732 public void BinHex_9(XmlWriterUtils utils) 5733 { 5734 String strBinHex = "abc"; 5735 byte[] Wbase64 = new byte[2000]; 5736 int/*uint*/ Wbase64len = 0; 5737 5738 using (XmlWriter w = utils.CreateWriter()) 5739 { 5740 w.WriteStartElement("root"); 5741 w.WriteStartAttribute("a", null); 5742 for (int i = 0; i < strBinHex.Length; i++) 5743 { 5744 WriteToBuffer(ref Wbase64, ref Wbase64len, System.BitConverter.GetBytes(strBinHex[i])); 5745 } 5746 w.WriteBinHex(Wbase64, 0, (int)Wbase64len); 5747 w.WriteEndElement(); 5748 } 5749 Assert.True(utils.CompareReader("<root a='610062006300' />")); 5750 } 5751 5752 // Call WriteBinHex and verify results can be read as a string 5753 [Theory] 5754 [XmlWriterInlineData] BinHex_10(XmlWriterUtils utils)5755 public void BinHex_10(XmlWriterUtils utils) 5756 { 5757 String strBinHex = "abc"; 5758 byte[] Wbase64 = new byte[2000]; 5759 int/*uint*/ Wbase64len = 0; 5760 5761 using (XmlWriter w = utils.CreateWriter()) 5762 { 5763 w.WriteStartElement("root"); 5764 for (int i = 0; i < strBinHex.Length; i++) 5765 { 5766 WriteToBuffer(ref Wbase64, ref Wbase64len, System.BitConverter.GetBytes(strBinHex[i])); 5767 } 5768 w.WriteBinHex(Wbase64, 0, (int)Wbase64len); 5769 w.WriteEndElement(); 5770 } 5771 Assert.True(utils.CompareReader("<root>610062006300</root>")); 5772 } 5773 } 5774 5775 //[TestCase(Name = "WriteState")] 5776 public partial class TCWriteState 5777 { 5778 // Verify WriteState.Start when nothing has been written yet 5779 [Theory] 5780 [XmlWriterInlineData] writeState_1(XmlWriterUtils utils)5781 public void writeState_1(XmlWriterUtils utils) 5782 { 5783 XmlWriter w = utils.CreateWriter(); 5784 CError.Compare(w.WriteState, WriteState.Start, "Error"); 5785 try 5786 { 5787 w.Dispose(); 5788 } 5789 catch (InvalidOperationException) 5790 { 5791 Assert.True(false); 5792 } 5793 return; 5794 } 5795 5796 // Verify correct state when writing in Prolog 5797 [Theory] 5798 [XmlWriterInlineData] writeState_2(XmlWriterUtils utils)5799 public void writeState_2(XmlWriterUtils utils) 5800 { 5801 using (XmlWriter w = utils.CreateWriter()) 5802 { 5803 CError.Compare(w.WriteState, WriteState.Start, "Error"); 5804 w.WriteDocType("Root", null, null, "<!ENTITY e \"test\">"); 5805 CError.Compare(w.WriteState, WriteState.Prolog, "Error"); 5806 w.WriteStartElement("Root"); 5807 CError.Compare(w.WriteState, WriteState.Element, "Error"); 5808 w.WriteEndElement(); 5809 } 5810 return; 5811 } 5812 5813 // Verify correct state when writing an attribute 5814 [Theory] 5815 [XmlWriterInlineData] writeState_3(XmlWriterUtils utils)5816 public void writeState_3(XmlWriterUtils utils) 5817 { 5818 using (XmlWriter w = utils.CreateWriter()) 5819 { 5820 w.WriteStartElement("Root"); 5821 w.WriteStartAttribute("a"); 5822 CError.Compare(w.WriteState, WriteState.Attribute, "Error"); 5823 w.WriteString("content"); 5824 w.WriteEndAttribute(); 5825 w.WriteEndElement(); 5826 } 5827 return; 5828 } 5829 5830 // Verify correct state when writing element content 5831 [Theory] 5832 [XmlWriterInlineData] writeState_4(XmlWriterUtils utils)5833 public void writeState_4(XmlWriterUtils utils) 5834 { 5835 using (XmlWriter w = utils.CreateWriter()) 5836 { 5837 w.WriteStartElement("Root"); 5838 w.WriteString("content"); 5839 CError.Compare(w.WriteState, WriteState.Content, "Error"); 5840 w.WriteEndElement(); 5841 } 5842 return; 5843 } 5844 5845 // Verify correct state after Close has been called 5846 [Theory] 5847 [XmlWriterInlineData] writeState_5(XmlWriterUtils utils)5848 public void writeState_5(XmlWriterUtils utils) 5849 { 5850 XmlWriter w = utils.CreateWriter(); 5851 w.WriteStartElement("Root"); 5852 w.WriteEndElement(); 5853 w.Dispose(); 5854 CError.Compare(w.WriteState, WriteState.Closed, "Error"); 5855 return; 5856 } 5857 5858 // Verify WriteState = Error after an exception 5859 [Theory] 5860 [XmlWriterInlineData] writeState_6(XmlWriterUtils utils)5861 public void writeState_6(XmlWriterUtils utils) 5862 { 5863 using (XmlWriter w = utils.CreateWriter()) 5864 { 5865 try 5866 { 5867 w.WriteStartElement("Root"); 5868 w.WriteStartElement("Root"); 5869 } 5870 catch (InvalidOperationException e) 5871 { 5872 CError.WriteLineIgnore(e.ToString()); 5873 CError.Compare(w.WriteState, WriteState.Error, "Error"); 5874 } 5875 } 5876 return; 5877 } 5878 5879 [Theory] 5880 [XmlWriterInlineData("WriteStartDocument")] 5881 [XmlWriterInlineData("WriteStartElement")] 5882 [XmlWriterInlineData("WriteEndElement")] 5883 [XmlWriterInlineData("WriteStartAttribute")] 5884 [XmlWriterInlineData("WriteEndAttribute")] 5885 [XmlWriterInlineData("WriteCData")] 5886 [XmlWriterInlineData("WriteComment")] 5887 [XmlWriterInlineData("WritePI")] 5888 [XmlWriterInlineData("WriteEntityRef")] 5889 [XmlWriterInlineData("WriteCharEntity")] 5890 [XmlWriterInlineData("WriteSurrogateCharEntity")] 5891 [XmlWriterInlineData("WriteWhitespace")] 5892 [XmlWriterInlineData("WriteString")] 5893 [XmlWriterInlineData("WriteChars")] 5894 [XmlWriterInlineData("WriteRaw")] 5895 [XmlWriterInlineData("WriteBase64")] 5896 [XmlWriterInlineData("WriteBinHex")] 5897 [XmlWriterInlineData("LookupPrefix")] 5898 [XmlWriterInlineData("WriteNmToken")] 5899 [XmlWriterInlineData("WriteName")] 5900 [XmlWriterInlineData("WriteQualifiedName")] 5901 [XmlWriterInlineData("WriteValue")] 5902 [XmlWriterInlineData("WriteAttributes")] 5903 [XmlWriterInlineData("WriteNodeReader")] 5904 [XmlWriterInlineData("Flush")] writeState_7(XmlWriterUtils utils, string methodName)5905 public void writeState_7(XmlWriterUtils utils, string methodName) 5906 { 5907 using (XmlWriter w = utils.CreateWriter()) 5908 { 5909 try 5910 { 5911 w.WriteStartDocument(); 5912 w.WriteStartDocument(); 5913 } 5914 catch (InvalidOperationException) 5915 { 5916 CError.Equals(w.WriteState, WriteState.Error, "Error"); 5917 try 5918 { 5919 this.InvokeMethod(w, methodName); 5920 } 5921 catch (InvalidOperationException) 5922 { 5923 CError.Equals(w.WriteState, WriteState.Error, "Error"); 5924 try 5925 { 5926 this.InvokeMethod(w, methodName); 5927 } 5928 catch (InvalidOperationException) 5929 { 5930 return; 5931 } 5932 } 5933 catch (ArgumentException) 5934 { 5935 if (utils.WriterType == WriterType.CustomWriter) 5936 { 5937 CError.Equals(w.WriteState, WriteState.Error, "Error"); 5938 try 5939 { 5940 this.InvokeMethod(w, methodName); 5941 } 5942 catch (ArgumentException) 5943 { 5944 return; 5945 } 5946 } 5947 } 5948 // Flush/LookupPrefix is a NOOP 5949 if (methodName == "Flush" || methodName == "LookupPrefix") 5950 return; 5951 } 5952 } 5953 Assert.True(false); 5954 } 5955 5956 [Theory] 5957 [XmlWriterInlineData("XmlSpace")] 5958 [XmlWriterInlineData("XmlLang")] writeState_8(XmlWriterUtils utils, string what)5959 public void writeState_8(XmlWriterUtils utils, string what) 5960 { 5961 using (XmlWriter w = utils.CreateWriter()) 5962 { 5963 try 5964 { 5965 w.WriteStartDocument(); 5966 w.WriteStartDocument(); 5967 } 5968 catch (InvalidOperationException) 5969 { 5970 CError.Equals(w.WriteState, WriteState.Error, "Error"); 5971 switch (what) 5972 { 5973 case "XmlSpace": 5974 CError.Equals(w.XmlSpace, XmlSpace.None, "Error"); 5975 break; 5976 case "XmlLang": 5977 CError.Equals(w.XmlLang, null, "Error"); 5978 break; 5979 } 5980 } 5981 } 5982 return; 5983 } 5984 5985 [Theory] 5986 [XmlWriterInlineData("WriteStartDocument")] 5987 [XmlWriterInlineData("WriteStartElement")] 5988 [XmlWriterInlineData("WriteEndElement")] 5989 [XmlWriterInlineData("WriteStartAttribute")] 5990 [XmlWriterInlineData("WriteEndAttribute")] 5991 [XmlWriterInlineData("WriteCData")] 5992 [XmlWriterInlineData("WriteComment")] 5993 [XmlWriterInlineData("WritePI")] 5994 [XmlWriterInlineData("WriteEntityRef")] 5995 [XmlWriterInlineData("WriteCharEntity")] 5996 [XmlWriterInlineData("WriteSurrogateCharEntity")] 5997 [XmlWriterInlineData("WriteWhitespace")] 5998 [XmlWriterInlineData("WriteString")] 5999 [XmlWriterInlineData("WriteChars")] 6000 [XmlWriterInlineData("WriteRaw")] 6001 [XmlWriterInlineData("WriteBase64")] 6002 [XmlWriterInlineData("WriteBinHex")] 6003 [XmlWriterInlineData("LookupPrefix")] 6004 [XmlWriterInlineData("WriteNmToken")] 6005 [XmlWriterInlineData("WriteName")] 6006 [XmlWriterInlineData("WriteQualifiedName")] 6007 [XmlWriterInlineData("WriteValue")] 6008 [XmlWriterInlineData("WriteAttributes")] 6009 [XmlWriterInlineData("WriteNodeReader")] 6010 [XmlWriterInlineData("Flush")] writeState_9(XmlWriterUtils utils, string methodName)6011 public void writeState_9(XmlWriterUtils utils, string methodName) 6012 { 6013 XmlWriter w = utils.CreateWriter(); 6014 w.WriteElementString("root", ""); 6015 w.Dispose(); 6016 try 6017 { 6018 this.InvokeMethod(w, methodName); 6019 } 6020 catch (InvalidOperationException) 6021 { 6022 try 6023 { 6024 this.InvokeMethod(w, methodName); 6025 } 6026 catch (InvalidOperationException) 6027 { 6028 return; 6029 } 6030 } 6031 catch (ArgumentException) 6032 { 6033 if (utils.WriterType == WriterType.CustomWriter) 6034 { 6035 try 6036 { 6037 this.InvokeMethod(w, methodName); 6038 } 6039 catch (ArgumentException) 6040 { 6041 return; 6042 } 6043 } 6044 } 6045 // Flush/LookupPrefix is a NOOP 6046 if (methodName == "Flush" || methodName == "LookupPrefix") 6047 return; 6048 6049 Assert.True(false); 6050 } 6051 InvokeMethod(XmlWriter w, string methodName)6052 private void InvokeMethod(XmlWriter w, string methodName) 6053 { 6054 byte[] buffer = new byte[10]; 6055 switch (methodName) 6056 { 6057 case "WriteStartDocument": 6058 w.WriteStartDocument(); 6059 break; 6060 case "WriteStartElement": 6061 w.WriteStartElement("root"); 6062 break; 6063 case "WriteEndElement": 6064 w.WriteEndElement(); 6065 break; 6066 case "WriteStartAttribute": 6067 w.WriteStartAttribute("attr"); 6068 break; 6069 case "WriteEndAttribute": 6070 w.WriteEndAttribute(); 6071 break; 6072 case "WriteCData": 6073 w.WriteCData("test"); 6074 break; 6075 case "WriteComment": 6076 w.WriteComment("test"); 6077 break; 6078 case "WritePI": 6079 w.WriteProcessingInstruction("name", "test"); 6080 break; 6081 case "WriteEntityRef": 6082 w.WriteEntityRef("e"); 6083 break; 6084 case "WriteCharEntity": 6085 w.WriteCharEntity('c'); 6086 break; 6087 case "WriteSurrogateCharEntity": 6088 w.WriteSurrogateCharEntity('\uDC00', '\uDBFF'); 6089 break; 6090 case "WriteWhitespace": 6091 w.WriteWhitespace(" "); 6092 break; 6093 case "WriteString": 6094 w.WriteString("foo"); 6095 break; 6096 case "WriteChars": 6097 char[] charArray = new char[] { 'a', 'b', 'c', 'd' }; 6098 w.WriteChars(charArray, 0, 3); 6099 break; 6100 case "WriteRaw": 6101 w.WriteRaw("<foo>bar</foo>"); 6102 break; 6103 case "WriteBase64": 6104 w.WriteBase64(buffer, 0, 9); 6105 break; 6106 case "WriteBinHex": 6107 w.WriteBinHex(buffer, 0, 9); 6108 break; 6109 case "LookupPrefix": 6110 string str = w.LookupPrefix("foo"); 6111 break; 6112 case "WriteNmToken": 6113 w.WriteNmToken("foo"); 6114 break; 6115 case "WriteName": 6116 w.WriteName("foo"); 6117 break; 6118 case "WriteQualifiedName": 6119 w.WriteQualifiedName("foo", "bar"); 6120 break; 6121 case "WriteValue": 6122 w.WriteValue(Int32.MaxValue); 6123 break; 6124 case "WriteAttributes": 6125 XmlReader xr1 = ReaderHelper.Create(new StringReader("<root attr='test'/>")); 6126 xr1.Read(); 6127 w.WriteAttributes(xr1, false); 6128 break; 6129 case "WriteNodeReader": 6130 XmlReader xr2 = ReaderHelper.Create(new StringReader("<root/>")); 6131 xr2.Read(); 6132 w.WriteNode(xr2, false); 6133 break; 6134 case "Flush": 6135 w.Flush(); 6136 break; 6137 default: 6138 CError.Equals(false, "Unexpected param in testcase: {0}", methodName); 6139 break; 6140 } 6141 } 6142 } 6143 6144 //[TestCase(Name = "NDP20_NewMethods")] 6145 public partial class TC_NDP20_NewMethods 6146 { 6147 // WriteElementString(prefix, name, ns, value) sanity test 6148 [Theory] 6149 [XmlWriterInlineData] var_1(XmlWriterUtils utils)6150 public void var_1(XmlWriterUtils utils) 6151 { 6152 using (XmlWriter w = utils.CreateWriter()) 6153 { 6154 w.WriteElementString("foo", "elem", "bar", "test"); 6155 } 6156 Assert.True(utils.CompareReader("<foo:elem xmlns:foo=\"bar\">test</foo:elem>")); 6157 } 6158 6159 // WriteElementString(prefix = xml, ns = XML namespace) 6160 [Theory] 6161 [XmlWriterInlineData] var_2(XmlWriterUtils utils)6162 public void var_2(XmlWriterUtils utils) 6163 { 6164 using (XmlWriter w = utils.CreateWriter()) 6165 { 6166 w.WriteElementString("xml", "elem", "http://www.w3.org/XML/1998/namespace", "test"); 6167 } 6168 Assert.True(utils.CompareReader("<xml:elem>test</xml:elem>")); 6169 } 6170 6171 // WriteStartAttribute(string name) sanity test 6172 [Theory] 6173 [XmlWriterInlineData] var_3(XmlWriterUtils utils)6174 public void var_3(XmlWriterUtils utils) 6175 { 6176 using (XmlWriter w = utils.CreateWriter()) 6177 { 6178 w.WriteStartElement("elem"); 6179 w.WriteStartAttribute("attr"); 6180 w.WriteEndElement(); 6181 } 6182 Assert.True(utils.CompareReader("<elem attr=\"\" />")); 6183 } 6184 6185 // WriteElementString followed by attribute should error 6186 [Theory] 6187 [XmlWriterInlineData] var_4(XmlWriterUtils utils)6188 public void var_4(XmlWriterUtils utils) 6189 { 6190 using (XmlWriter w = utils.CreateWriter()) 6191 { 6192 try 6193 { 6194 w.WriteElementString("foo", "elem", "bar", "test"); 6195 w.WriteStartAttribute("attr"); 6196 } 6197 catch (InvalidOperationException) 6198 { 6199 return; 6200 } 6201 } 6202 6203 Assert.True(false); 6204 } 6205 6206 // XmlWellformedWriter wrapping another XmlWriter should check the duplicate attributes first 6207 [Theory] 6208 [XmlWriterInlineData(WriterType.All & ~WriterType.Async)] var_5(XmlWriterUtils utils)6209 public void var_5(XmlWriterUtils utils) 6210 { 6211 using (XmlWriter wf = utils.CreateWriter()) 6212 { 6213 using (XmlWriter w = WriterHelper.Create(wf, overrideAsync: true, async: utils.Async)) 6214 { 6215 w.WriteStartElement("B"); 6216 w.WriteStartAttribute("aaa"); 6217 try 6218 { 6219 w.WriteStartAttribute("aaa"); 6220 } 6221 catch (XmlException) 6222 { 6223 return; 6224 } 6225 } 6226 } 6227 Assert.True(false); 6228 } 6229 6230 [Theory] 6231 [XmlWriterInlineData(true)] 6232 [XmlWriterInlineData(false)] var_6a(XmlWriterUtils utils, bool standalone)6233 public void var_6a(XmlWriterUtils utils, bool standalone) 6234 { 6235 XmlWriterSettings ws = new XmlWriterSettings(); 6236 ws.ConformanceLevel = ConformanceLevel.Auto; 6237 XmlWriter w = utils.CreateWriter(ws); 6238 w.WriteStartDocument(standalone); 6239 w.WriteStartElement("a"); 6240 6241 w.Dispose(); 6242 string enc = (utils.WriterType == WriterType.UnicodeWriter || utils.WriterType == WriterType.UnicodeWriterIndent) ? "16" : "8"; 6243 string param = (standalone) ? "yes" : "no"; 6244 6245 string exp = (utils.WriterType == WriterType.UTF8WriterIndent || utils.WriterType == WriterType.UnicodeWriterIndent) ? 6246 String.Format("<?xml version=\"1.0\" encoding=\"utf-{0}\" standalone=\"{1}\"?>" + Environment.NewLine + "<a />", enc, param) : 6247 String.Format("<?xml version=\"1.0\" encoding=\"utf-{0}\" standalone=\"{1}\"?><a />", enc, param); 6248 6249 Assert.True((utils.CompareString(exp))); 6250 } 6251 6252 // Wrapped XmlWriter::WriteStartDocument(true) is missing standalone attribute 6253 [Theory] 6254 [XmlWriterInlineData(WriterType.All & ~WriterType.Async)] var_6b(XmlWriterUtils utils)6255 public void var_6b(XmlWriterUtils utils) 6256 { 6257 XmlWriterSettings ws = new XmlWriterSettings(); 6258 ws.ConformanceLevel = ConformanceLevel.Auto; 6259 6260 XmlWriter wf = utils.CreateWriter(ws); 6261 XmlWriter w = WriterHelper.Create(wf, overrideAsync: true, async: utils.Async); 6262 w.WriteStartDocument(true); 6263 w.WriteStartElement("a"); 6264 6265 w.Dispose(); 6266 6267 string enc = (utils.WriterType == WriterType.UnicodeWriter || utils.WriterType == WriterType.UnicodeWriterIndent) ? "16" : "8"; 6268 string exp = (utils.WriterType == WriterType.UTF8WriterIndent || utils.WriterType == WriterType.UnicodeWriterIndent) ? 6269 String.Format("<?xml version=\"1.0\" encoding=\"utf-{0}\"?>" + Environment.NewLine + "<a />", enc) : 6270 String.Format("<?xml version=\"1.0\" encoding=\"utf-{0}\"?><a />", enc); 6271 6272 exp = (utils.WriterType == WriterType.CustomWriter) ? "<?xml version=\"1.0\" encoding=\"utf-8\" standalone=\"yes\"?><a />" : exp; 6273 6274 Assert.True((utils.CompareString(exp))); 6275 } 6276 } 6277 6278 //[TestCase(Name = "Globalization")] 6279 public partial class TCGlobalization 6280 { 6281 // Characters between 0xdfff and 0xfffe are valid Unicode characters 6282 [Theory] 6283 [XmlWriterInlineData] var_1(XmlWriterUtils utils)6284 public void var_1(XmlWriterUtils utils) 6285 { 6286 string UniStr = ""; 6287 using (XmlWriter w = utils.CreateWriter()) 6288 { 6289 for (char ch = '\ue000'; ch < '\ufffe'; ch++) 6290 UniStr += ch; 6291 w.WriteElementString("root", UniStr); 6292 } 6293 6294 Assert.True(utils.CompareReader("<root>" + UniStr + "</root>")); 6295 } 6296 6297 [Fact] XmlWriterUsingUtf16BEWritesCorrectEncodingInTheXmlDecl()6298 public void XmlWriterUsingUtf16BEWritesCorrectEncodingInTheXmlDecl() 6299 { 6300 Encoding enc = Encoding.GetEncoding("UTF-16BE"); 6301 Assert.NotNull(enc); 6302 6303 using (var ms = new MemoryStream()) 6304 { 6305 var settings = new XmlWriterSettings(); 6306 settings.Encoding = enc; 6307 6308 using (XmlWriter writer = XmlWriter.Create(ms, settings)) 6309 { 6310 writer.WriteStartDocument(); 6311 writer.WriteElementString("A", "value"); 6312 writer.WriteEndDocument(); 6313 } 6314 6315 ms.Position = 0; 6316 StreamReader sr = new StreamReader(ms); 6317 string str = sr.ReadToEnd(); 6318 CError.WriteLine(str); 6319 Assert.Equal("<?xml version=\"1.0\" encoding=\"utf-16BE\"?><A>value</A>", str); 6320 } 6321 } 6322 } 6323 6324 //[TestCase(Name = "Close()")] 6325 public partial class TCClose 6326 { 6327 // Closing an XmlWriter should close all opened elements 6328 [Theory] 6329 [XmlWriterInlineData] var_1(XmlWriterUtils utils)6330 public void var_1(XmlWriterUtils utils) 6331 { 6332 using (XmlWriter writer = utils.CreateWriter()) 6333 { 6334 writer.WriteStartElement("Root"); 6335 writer.WriteStartElement("Nesting"); 6336 writer.WriteStartElement("SomeDeep"); 6337 } 6338 Assert.True(utils.CompareReader("<Root><Nesting><SomeDeep /></Nesting></Root>")); 6339 } 6340 6341 // Disposing an XmlWriter should close all opened elements 6342 [Theory] 6343 [XmlWriterInlineData] var_2(XmlWriterUtils utils)6344 public void var_2(XmlWriterUtils utils) 6345 { 6346 using (XmlWriter writer = utils.CreateWriter()) 6347 { 6348 writer.WriteStartElement("Root"); 6349 writer.WriteStartElement("Nesting"); 6350 writer.WriteStartElement("SomeDeep"); 6351 } 6352 Assert.True(utils.CompareReader("<Root><Nesting><SomeDeep /></Nesting></Root>")); 6353 } 6354 6355 // Dispose() shouldn't throw when a tag is not closed and inner stream is closed 6356 [Theory] 6357 [XmlWriterInlineData(WriterType.All & ~WriterType.Async)] var_3(XmlWriterUtils utils)6358 public void var_3(XmlWriterUtils utils) 6359 { 6360 XmlWriter w; 6361 StringWriter sw = new StringWriter(CultureInfo.InvariantCulture); 6362 XmlWriterSettings s = new XmlWriterSettings(); 6363 6364 6365 switch (utils.WriterType) 6366 { 6367 case WriterType.UnicodeWriter: 6368 s.Encoding = Encoding.Unicode; 6369 w = WriterHelper.Create(sw, s, overrideAsync: true, async: utils.Async); 6370 break; 6371 case WriterType.UTF8Writer: 6372 s.Encoding = Encoding.UTF8; 6373 w = WriterHelper.Create(sw, s, overrideAsync: true, async: utils.Async); 6374 break; 6375 case WriterType.WrappedWriter: 6376 XmlWriter ww = WriterHelper.Create(sw, s, overrideAsync: true, async: utils.Async); 6377 w = WriterHelper.Create(ww, s, overrideAsync: true, async: utils.Async); 6378 break; 6379 case WriterType.CharCheckingWriter: 6380 s.CheckCharacters = false; 6381 XmlWriter w1 = WriterHelper.Create(sw, s, overrideAsync: true, async: utils.Async); 6382 XmlWriterSettings ws2 = new XmlWriterSettings(); 6383 ws2.CheckCharacters = true; 6384 w = WriterHelper.Create(w1, ws2, overrideAsync: true, async: utils.Async); 6385 break; 6386 case WriterType.UnicodeWriterIndent: 6387 s.Encoding = Encoding.Unicode; 6388 s.Indent = true; 6389 w = WriterHelper.Create(sw, s, overrideAsync: true, async: utils.Async); 6390 break; 6391 case WriterType.UTF8WriterIndent: 6392 s.Encoding = Encoding.UTF8; 6393 s.Indent = true; 6394 w = WriterHelper.Create(sw, s, overrideAsync: true, async: utils.Async); 6395 break; 6396 default: 6397 return; 6398 } 6399 6400 w.WriteStartElement("root"); 6401 6402 ((IDisposable)sw).Dispose(); 6403 sw = null; 6404 try 6405 { 6406 ((IDisposable)w).Dispose(); 6407 } 6408 catch (ObjectDisposedException e) { CError.WriteLine(e.Message); return; } 6409 Assert.True(false); 6410 } 6411 6412 // Close() should be allowed when XML doesn't have content 6413 [Theory] 6414 [XmlWriterInlineData] var_4(XmlWriterUtils utils)6415 public void var_4(XmlWriterUtils utils) 6416 { 6417 XmlWriter w = utils.CreateWriter(); 6418 w.Dispose(); 6419 6420 try 6421 { 6422 utils.CompareReader(""); 6423 } 6424 catch (XmlException e) 6425 { 6426 CError.WriteLine(e.Message); 6427 if (e.Message.EndsWith("..")) 6428 { 6429 Assert.True(false); 6430 } 6431 Assert.True(false); 6432 } 6433 return; 6434 } 6435 6436 [Theory] 6437 [XmlWriterInlineData(WriterType.UnicodeWriterIndent | WriterType.UTF8WriterIndent)] SettingIndetingAllowsIndentingWhileWritingBase64(XmlWriterUtils utils)6438 public void SettingIndetingAllowsIndentingWhileWritingBase64(XmlWriterUtils utils) 6439 { 6440 string base64test = "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz"; 6441 byte[] bytesToWrite = Encoding.Unicode.GetBytes(base64test.ToCharArray()); 6442 6443 using (XmlWriter writer = utils.CreateWriter()) 6444 { 6445 writer.WriteStartDocument(); 6446 writer.WriteStartElement("Root"); 6447 writer.WriteStartElement("WB64"); 6448 writer.WriteBase64(bytesToWrite, 0, bytesToWrite.Length); 6449 writer.WriteEndElement(); 6450 6451 writer.WriteStartElement("WBC64"); 6452 writer.WriteString(Convert.ToBase64String(bytesToWrite)); 6453 writer.WriteEndElement(); 6454 writer.WriteEndElement(); 6455 writer.WriteEndDocument(); 6456 } 6457 6458 string xml = utils.GetString(); 6459 6460 var readerSettings = new XmlReaderSettings() 6461 { 6462 IgnoreWhitespace = false 6463 }; 6464 6465 using (StringReader sr = new StringReader(xml)) 6466 using (XmlReader reader = XmlReader.Create(sr, readerSettings)) 6467 { 6468 reader.ReadToFollowing("WB64"); 6469 Assert.Equal("WB64", reader.LocalName); 6470 string one = reader.ReadInnerXml(); 6471 6472 Assert.Equal(XmlNodeType.Whitespace, reader.NodeType); 6473 reader.Read(); 6474 6475 Assert.Equal("WBC64", reader.LocalName); 6476 string two = reader.ReadInnerXml(); 6477 6478 Assert.Equal(one, two); 6479 } 6480 } 6481 6482 //[Variation("WriteState returns Content even though document element has been closed")] 6483 [Theory] 6484 [XmlWriterInlineData] WriteStateReturnsContentAfterDocumentClosed(XmlWriterUtils utils)6485 public void WriteStateReturnsContentAfterDocumentClosed(XmlWriterUtils utils) 6486 { 6487 XmlWriter xw = utils.CreateWriter(); 6488 xw.WriteStartDocument(false); 6489 xw.WriteStartElement("foo"); 6490 xw.WriteString("bar"); 6491 xw.WriteEndElement(); 6492 6493 try 6494 { 6495 xw.WriteStartElement("foo2"); 6496 xw.Dispose(); 6497 } 6498 catch (System.InvalidOperationException) 6499 { 6500 return; 6501 } 6502 Assert.True(false); 6503 } 6504 } 6505 } 6506 } 6507 } 6508