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.IO; 7 using XmlCoreTest.Common; 8 9 namespace System.Xml.Tests 10 { 11 public enum EREADER_TYPE 12 { 13 UNICODE = 0, 14 UTF8, 15 BIGENDIAN, 16 BYTE, 17 GENERIC, 18 STRING_ONLY, 19 BIG_ELEMENT_SIZE, 20 JUNK, 21 INVALID_NAMESPACE, 22 XMLNAMESPACE_TEST, 23 XMLLANG_TEST, 24 XMLSPACE_TEST, 25 WELLFORMED_DTD, 26 NONWELLFORMED_DTD, 27 INVWELLFORMED_DTD, 28 VALID_DTD, 29 INVALID_DTD, 30 INVALID_SCHEMA, 31 XMLSCHEMA, 32 XSLT_COPY, 33 WHITESPACE_TEST, 34 BASE64_TEST, 35 BINHEX_TEST, 36 CONSTRUCTOR, 37 LINENUMBER, 38 LBNORMALIZATION, 39 SCHEMATYPE, 40 BINARY 41 }; 42 43 //////////////////////////////////////////////////////////////// 44 // CDataReader 45 // 46 //////////////////////////////////////////////////////////////// 47 public class CDataReader 48 { 49 private const String ST_XML = "xml"; 50 51 public const int STATUS_PASSED = 1; 52 public const int STATUS_FAILED = 0; 53 54 private EREADER_TYPE _eType; 55 private string _strSource; 56 private object _oInternal; 57 58 // CDataReader constructor 59 internal bool _iswrapping = false; 60 CDataReader(object objInternal, EREADER_TYPE eReaderType, string strSource)61 public CDataReader(object objInternal, EREADER_TYPE eReaderType, string strSource) 62 { 63 _eType = eReaderType; 64 _strSource = strSource; 65 _oInternal = objInternal; 66 } 67 68 public virtual XmlReader Internal 69 { 70 get { return (XmlReader)_oInternal; } 71 set { _oInternal = value; } 72 } 73 74 public virtual EREADER_TYPE ReaderType 75 { 76 get { return _eType; } 77 } 78 79 80 /// <summary> 81 /// The following methods just wrap the XmlReader methods by explicitly calling XmlReader methods from CDataReader. 82 /// </summary> 83 84 public virtual XmlNodeType NodeType 85 { 86 get { return Internal.NodeType; } 87 } 88 CheckWrappingReader()89 public void CheckWrappingReader() 90 { 91 if (_iswrapping) 92 { 93 XmlCustomReader customReader = _oInternal as XmlCustomReader; 94 if (!customReader.IsCalled) 95 throw new CTestFailedException("Custom Extended reader not called"); 96 } 97 } 98 ResetWrappingReader()99 public void ResetWrappingReader() 100 { 101 if (_iswrapping) 102 { 103 ((XmlCustomReader)_oInternal).IsCalled = true; 104 } 105 } 106 107 public virtual string Name 108 { 109 get { return Internal.Name; } 110 } 111 112 public virtual string LocalName 113 { 114 get { return Internal.LocalName; } 115 } 116 117 public virtual string NamespaceURI 118 { 119 get { return Internal.NamespaceURI; } 120 } 121 122 public virtual string Prefix 123 { 124 get { return Internal.Prefix; } 125 } 126 127 public virtual bool HasValue 128 { 129 get { return Internal.HasValue; } 130 } 131 132 public virtual string Value 133 { 134 get { return Internal.Value; } 135 } 136 137 public virtual Type ValueType 138 { 139 get { return Internal.ValueType; } 140 } 141 142 public virtual int Depth 143 { 144 get { return Internal.Depth; } 145 } 146 147 public virtual string BaseURI 148 { 149 get { return Internal.BaseURI; } 150 } 151 152 public virtual bool IsEmptyElement 153 { 154 get { return Internal.IsEmptyElement; } 155 } 156 157 public virtual bool IsDefault 158 { 159 get { return Internal.IsDefault; } 160 } 161 162 public virtual XmlSpace XmlSpace 163 { 164 get { return Internal.XmlSpace; } 165 } 166 167 public virtual string XmlLang 168 { 169 get { return Internal.XmlLang; } 170 } 171 172 public virtual int AttributeCount 173 { 174 get { return Internal.AttributeCount; } 175 } 176 177 public virtual bool HasAttributes 178 { 179 get { return Internal.HasAttributes; } 180 } 181 182 public virtual bool CanResolveEntity 183 { 184 get { return Internal.CanResolveEntity; } 185 } 186 GetAttribute(string name)187 public string GetAttribute(string name) 188 { 189 ResetWrappingReader(); 190 string s = Internal.GetAttribute(name); 191 CheckWrappingReader(); 192 return s; 193 } 194 GetAttribute(string name, string namespaceURI)195 public string GetAttribute(string name, string namespaceURI) 196 { 197 ResetWrappingReader(); 198 string s = Internal.GetAttribute(name, namespaceURI); 199 CheckWrappingReader(); 200 return s; 201 } 202 GetAttribute(int i)203 public string GetAttribute(int i) 204 { 205 ResetWrappingReader(); 206 string s = Internal.GetAttribute(i); 207 CheckWrappingReader(); 208 return s; 209 } 210 211 public string this[string name] 212 { 213 get 214 { 215 ResetWrappingReader(); 216 string s = Internal[name]; 217 CheckWrappingReader(); 218 return s; 219 } 220 } 221 222 public string this[string name, string namespaceURI] 223 { 224 get 225 { 226 ResetWrappingReader(); 227 string s = Internal[name, namespaceURI]; 228 CheckWrappingReader(); 229 return s; 230 } 231 } 232 233 public string this[int i] 234 { 235 get 236 { 237 ResetWrappingReader(); 238 string s = Internal[i]; 239 CheckWrappingReader(); 240 return s; 241 } 242 } 243 MoveToAttribute(string name)244 public bool MoveToAttribute(string name) 245 { 246 ResetWrappingReader(); 247 bool x = Internal.MoveToAttribute(name); 248 CheckWrappingReader(); 249 return x; 250 } 251 MoveToAttribute(string name, string namespaceURI)252 public bool MoveToAttribute(string name, string namespaceURI) 253 { 254 bool x = Internal.MoveToAttribute(name, namespaceURI); 255 return x; 256 } 257 MoveToAttribute(int i)258 public void MoveToAttribute(int i) 259 { 260 ResetWrappingReader(); 261 Internal.MoveToAttribute(i); 262 CheckWrappingReader(); 263 } 264 MoveToFirstAttribute()265 public bool MoveToFirstAttribute() 266 { 267 ResetWrappingReader(); 268 bool x = Internal.MoveToFirstAttribute(); 269 CheckWrappingReader(); 270 return x; 271 } 272 MoveToNextAttribute()273 public bool MoveToNextAttribute() 274 { 275 ResetWrappingReader(); 276 bool x = Internal.MoveToNextAttribute(); 277 CheckWrappingReader(); 278 return x; 279 } 280 MoveToElement()281 public bool MoveToElement() 282 { 283 ResetWrappingReader(); 284 bool x = Internal.MoveToElement(); 285 CheckWrappingReader(); 286 return x; 287 } 288 Read()289 public virtual bool Read() 290 { 291 ResetWrappingReader(); 292 bool x = Internal.Read(); 293 CheckWrappingReader(); 294 return x; 295 } 296 297 public virtual bool EOF 298 { 299 get 300 { 301 ResetWrappingReader(); 302 bool x = Internal.EOF; 303 CheckWrappingReader(); 304 return x; 305 } 306 } 307 Close()308 public virtual void Close() 309 { 310 Dispose(); 311 } 312 Dispose()313 public virtual void Dispose() 314 { 315 if (Internal != null) 316 { 317 IDisposable disposableObj = Internal as IDisposable; 318 if (disposableObj != null) 319 disposableObj.Dispose(); 320 } 321 } 322 323 public virtual ReadState ReadState 324 { 325 get 326 { 327 ResetWrappingReader(); 328 ReadState rs = Internal.ReadState; 329 CheckWrappingReader(); 330 return rs; 331 } 332 } 333 Skip()334 public virtual void Skip() 335 { 336 ResetWrappingReader(); 337 Internal.Skip(); 338 CheckWrappingReader(); 339 } 340 ReadInnerXml()341 public string ReadInnerXml() 342 { 343 ResetWrappingReader(); 344 string s = Internal.ReadInnerXml(); 345 CheckWrappingReader(); 346 return s; 347 } 348 ReadOuterXml()349 public string ReadOuterXml() 350 { 351 ResetWrappingReader(); 352 string s = Internal.ReadOuterXml(); 353 CheckWrappingReader(); 354 return s; 355 } 356 MoveToContent()357 public XmlNodeType MoveToContent() 358 { 359 ResetWrappingReader(); 360 XmlNodeType s = Internal.MoveToContent(); 361 CheckWrappingReader(); 362 return s; 363 } 364 IsStartElement()365 public bool IsStartElement() 366 { 367 ResetWrappingReader(); 368 bool x = Internal.IsStartElement(); 369 CheckWrappingReader(); 370 return x; 371 } 372 IsStartElement(String name)373 public bool IsStartElement(String name) 374 { 375 ResetWrappingReader(); 376 bool x = Internal.IsStartElement(name); 377 CheckWrappingReader(); 378 return x; 379 } 380 IsStartElement(String name, String ns)381 public bool IsStartElement(String name, String ns) 382 { 383 ResetWrappingReader(); 384 bool x = Internal.IsStartElement(name, ns); 385 CheckWrappingReader(); 386 return x; 387 } 388 ReadStartElement()389 public void ReadStartElement() 390 { 391 ResetWrappingReader(); 392 Internal.ReadStartElement(); 393 CheckWrappingReader(); 394 } 395 ReadStartElement(String name)396 public void ReadStartElement(String name) 397 { 398 ResetWrappingReader(); 399 Internal.ReadStartElement(name); 400 CheckWrappingReader(); 401 } 402 ReadStartElement(String name, String ns)403 public void ReadStartElement(String name, String ns) 404 { 405 ResetWrappingReader(); 406 Internal.ReadStartElement(name, ns); 407 CheckWrappingReader(); 408 } 409 ReadEndElement()410 public void ReadEndElement() 411 { 412 ResetWrappingReader(); 413 Internal.ReadEndElement(); 414 CheckWrappingReader(); 415 } 416 417 public virtual XmlNameTable NameTable 418 { 419 get 420 { 421 ResetWrappingReader(); 422 XmlNameTable n = Internal.NameTable; 423 CheckWrappingReader(); 424 return n; 425 } 426 } 427 LookupNamespace(String prefix)428 public string LookupNamespace(String prefix) 429 { 430 ResetWrappingReader(); 431 string s = Internal.LookupNamespace(prefix); 432 CheckWrappingReader(); 433 return s; 434 } 435 ResolveEntity()436 public void ResolveEntity() 437 { 438 ResetWrappingReader(); 439 Internal.ResolveEntity(); 440 CheckWrappingReader(); 441 } 442 ReadAttributeValue()443 public bool ReadAttributeValue() 444 { 445 ResetWrappingReader(); 446 bool x = Internal.ReadAttributeValue(); 447 CheckWrappingReader(); 448 return x; 449 } 450 ReadSubtree()451 public XmlReader ReadSubtree() 452 { 453 ResetWrappingReader(); 454 XmlReader x = Internal.ReadSubtree(); 455 CheckWrappingReader(); 456 return x; 457 } 458 ReadToDescendant(string name)459 public bool ReadToDescendant(string name) 460 { 461 ResetWrappingReader(); 462 bool x = Internal.ReadToDescendant(name); 463 CheckWrappingReader(); 464 return x; 465 } 466 ReadToDescendant(string localName, string ns)467 public bool ReadToDescendant(string localName, string ns) 468 { 469 ResetWrappingReader(); 470 bool x = Internal.ReadToDescendant(localName, ns); 471 CheckWrappingReader(); 472 return x; 473 } 474 ReadToFollowing(string name)475 public bool ReadToFollowing(string name) 476 { 477 ResetWrappingReader(); 478 bool x = Internal.ReadToFollowing(name); 479 CheckWrappingReader(); 480 return x; 481 } 482 ReadToFollowing(string localName, string ns)483 public bool ReadToFollowing(string localName, string ns) 484 { 485 ResetWrappingReader(); 486 bool x = Internal.ReadToFollowing(localName, ns); 487 CheckWrappingReader(); 488 return x; 489 } 490 ReadToNextSibling(string name)491 public bool ReadToNextSibling(string name) 492 { 493 ResetWrappingReader(); 494 bool x = Internal.ReadToNextSibling(name); 495 CheckWrappingReader(); 496 return x; 497 } 498 ReadToNextSibling(string localName, string ns)499 public bool ReadToNextSibling(string localName, string ns) 500 { 501 ResetWrappingReader(); 502 bool x = Internal.ReadToNextSibling(localName, ns); 503 CheckWrappingReader(); 504 return x; 505 } 506 507 public XmlReaderSettings Settings 508 { 509 get 510 { 511 ResetWrappingReader(); 512 XmlReaderSettings x = Internal.Settings; 513 CheckWrappingReader(); 514 return x; 515 } 516 } 517 ReadElementContentAsObject()518 public virtual object ReadElementContentAsObject() 519 { 520 ResetWrappingReader(); 521 object x = Internal.ReadElementContentAsObject(); 522 CheckWrappingReader(); 523 return x; 524 } 525 ReadElementContentAsBoolean()526 public virtual Boolean ReadElementContentAsBoolean() 527 { 528 ResetWrappingReader(); 529 bool x = Internal.ReadElementContentAsBoolean(); 530 CheckWrappingReader(); 531 return x; 532 } 533 ReadElementContentAsDouble()534 public virtual Double ReadElementContentAsDouble() 535 { 536 ResetWrappingReader(); 537 double x = Internal.ReadElementContentAsDouble(); 538 CheckWrappingReader(); 539 return x; 540 } 541 ReadElementContentAsInt()542 public virtual int ReadElementContentAsInt() 543 { 544 ResetWrappingReader(); 545 int x = Internal.ReadElementContentAsInt(); 546 CheckWrappingReader(); 547 return x; 548 } 549 ReadElementContentAsLong()550 public virtual long ReadElementContentAsLong() 551 { 552 ResetWrappingReader(); 553 long x = Internal.ReadElementContentAsLong(); 554 CheckWrappingReader(); 555 return x; 556 } 557 ReadElementContentAsFloat()558 public virtual float ReadElementContentAsFloat() 559 { 560 ResetWrappingReader(); 561 float x = Internal.ReadElementContentAsFloat(); 562 CheckWrappingReader(); 563 return x; 564 } 565 ReadElementContentAsDecimal()566 public virtual decimal ReadElementContentAsDecimal() 567 { 568 ResetWrappingReader(); 569 decimal x = Internal.ReadElementContentAsDecimal(); 570 CheckWrappingReader(); 571 return x; 572 } 573 ReadElementContentAsString()574 public virtual String ReadElementContentAsString() 575 { 576 ResetWrappingReader(); 577 string x = Internal.ReadElementContentAsString(); 578 CheckWrappingReader(); 579 return x; 580 } 581 582 //Overloads ReadElementContentAsObject(string localName, string namespaceUri)583 public virtual object ReadElementContentAsObject(string localName, string namespaceUri) 584 { 585 ResetWrappingReader(); 586 object x = Internal.ReadElementContentAsObject(localName, namespaceUri); 587 CheckWrappingReader(); 588 return x; 589 } 590 ReadElementContentAs(System.Type type, IXmlNamespaceResolver resolver)591 public virtual object ReadElementContentAs(System.Type type, IXmlNamespaceResolver resolver) 592 { 593 ResetWrappingReader(); 594 object x = Internal.ReadElementContentAs(type, resolver); 595 CheckWrappingReader(); 596 return x; 597 } 598 ReadElementContentAs(System.Type type, IXmlNamespaceResolver resolver, string localName, string namespaceUri)599 public virtual object ReadElementContentAs(System.Type type, IXmlNamespaceResolver resolver, string localName, string namespaceUri) 600 { 601 ResetWrappingReader(); 602 object x = Internal.ReadElementContentAs(type, resolver, localName, namespaceUri); 603 CheckWrappingReader(); 604 return x; 605 } 606 ReadElementContentAsBoolean(string localName, string namespaceUri)607 public virtual Boolean ReadElementContentAsBoolean(string localName, string namespaceUri) 608 { 609 ResetWrappingReader(); 610 bool x = Internal.ReadElementContentAsBoolean(localName, namespaceUri); 611 CheckWrappingReader(); 612 return x; 613 } 614 ReadElementContentAsDouble(string localName, string namespaceUri)615 public virtual Double ReadElementContentAsDouble(string localName, string namespaceUri) 616 { 617 ResetWrappingReader(); 618 double x = Internal.ReadElementContentAsDouble(localName, namespaceUri); 619 CheckWrappingReader(); 620 return x; 621 } 622 ReadElementContentAsInt(string localName, string namespaceUri)623 public virtual int ReadElementContentAsInt(string localName, string namespaceUri) 624 { 625 ResetWrappingReader(); 626 int x = Internal.ReadElementContentAsInt(localName, namespaceUri); 627 CheckWrappingReader(); 628 return x; 629 } 630 ReadElementContentAsLong(string localName, string namespaceUri)631 public virtual long ReadElementContentAsLong(string localName, string namespaceUri) 632 { 633 ResetWrappingReader(); 634 long x = Internal.ReadElementContentAsLong(localName, namespaceUri); 635 CheckWrappingReader(); 636 return x; 637 } 638 ReadElementContentAsDecimal(string localName, string namespaceUri)639 public virtual decimal ReadElementContentAsDecimal(string localName, string namespaceUri) 640 { 641 ResetWrappingReader(); 642 decimal x = Internal.ReadElementContentAsDecimal(localName, namespaceUri); 643 CheckWrappingReader(); 644 return x; 645 } 646 ReadElementContentAsFloat(string localName, string namespaceUri)647 public virtual float ReadElementContentAsFloat(string localName, string namespaceUri) 648 { 649 ResetWrappingReader(); 650 float x = Internal.ReadElementContentAsFloat(localName, namespaceUri); 651 CheckWrappingReader(); 652 return x; 653 } 654 ReadElementContentAsString(string localName, string namespaceUri)655 public virtual String ReadElementContentAsString(string localName, string namespaceUri) 656 { 657 ResetWrappingReader(); 658 string x = Internal.ReadElementContentAsString(localName, namespaceUri); 659 CheckWrappingReader(); 660 return x; 661 } 662 663 664 //Non-Element calls. ReadContentAs(System.Type type, IXmlNamespaceResolver resolver)665 public virtual object ReadContentAs(System.Type type, IXmlNamespaceResolver resolver) 666 { 667 ResetWrappingReader(); 668 object x = Internal.ReadContentAs(type, resolver); 669 CheckWrappingReader(); 670 return x; 671 } 672 ReadContentAsBoolean()673 public virtual Boolean ReadContentAsBoolean() 674 { 675 ResetWrappingReader(); 676 bool x = Internal.ReadContentAsBoolean(); 677 CheckWrappingReader(); 678 return x; 679 } 680 ReadContentAsDateTimeOffset()681 public virtual DateTimeOffset ReadContentAsDateTimeOffset() 682 { 683 ResetWrappingReader(); 684 DateTimeOffset x = Internal.ReadContentAsDateTimeOffset(); 685 CheckWrappingReader(); 686 return x; 687 } 688 ReadContentAsDouble()689 public virtual Double ReadContentAsDouble() 690 { 691 ResetWrappingReader(); 692 Double x = Internal.ReadContentAsDouble(); 693 CheckWrappingReader(); 694 return x; 695 } 696 ReadContentAsInt()697 public virtual int ReadContentAsInt() 698 { 699 ResetWrappingReader(); 700 int x = Internal.ReadContentAsInt(); 701 CheckWrappingReader(); 702 return x; 703 } 704 ReadContentAsLong()705 public virtual long ReadContentAsLong() 706 { 707 ResetWrappingReader(); 708 long x = Internal.ReadContentAsLong(); 709 CheckWrappingReader(); 710 return x; 711 } 712 ReadContentAsString()713 public virtual String ReadContentAsString() 714 { 715 ResetWrappingReader(); 716 string x = Internal.ReadContentAsString(); 717 CheckWrappingReader(); 718 return x; 719 } 720 ReadContentAsDecimal()721 public virtual decimal ReadContentAsDecimal() 722 { 723 ResetWrappingReader(); 724 decimal x = Internal.ReadContentAsDecimal(); 725 CheckWrappingReader(); 726 return x; 727 } 728 ReadContentAsFloat()729 public virtual float ReadContentAsFloat() 730 { 731 ResetWrappingReader(); 732 float x = Internal.ReadContentAsFloat(); 733 CheckWrappingReader(); 734 return x; 735 } 736 ReadContentAsObject()737 public virtual object ReadContentAsObject() 738 { 739 ResetWrappingReader(); 740 object x = Internal.ReadContentAsObject(); 741 CheckWrappingReader(); 742 return x; 743 } 744 745 public virtual int LineNumber 746 { 747 get 748 { 749 IXmlLineInfo li = (IXmlLineInfo)Internal; 750 751 if (li.HasLineInfo()) 752 return li.LineNumber; 753 else 754 throw new XmlException("Line Number information is not available"); 755 } 756 } 757 758 public virtual int LinePosition 759 { 760 get 761 { 762 IXmlLineInfo li = (IXmlLineInfo)Internal; 763 if (li.HasLineInfo()) 764 { 765 return li.LinePosition; 766 } 767 else 768 { 769 throw new Exception("LinePosition not supported in " + Internal.GetType()); 770 } 771 } 772 } 773 774 public virtual bool Namespaces 775 { 776 set 777 { 778 } 779 get 780 { 781 return false; 782 } 783 } 784 785 public bool CanReadBinaryContent 786 { 787 get 788 { 789 ResetWrappingReader(); 790 bool x = Internal.CanReadBinaryContent; 791 CheckWrappingReader(); 792 return x; 793 } 794 } 795 ReadContentAsBase64(byte[] array, int offset, int len)796 public int ReadContentAsBase64(byte[] array, int offset, int len) 797 { 798 ResetWrappingReader(); 799 int x = Internal.ReadContentAsBase64(array, offset, len); 800 CheckWrappingReader(); 801 return x; 802 } 803 ReadContentAsBinHex(byte[] array, int offset, int len)804 public int ReadContentAsBinHex(byte[] array, int offset, int len) 805 { 806 ResetWrappingReader(); 807 int x = Internal.ReadContentAsBinHex(array, offset, len); 808 CheckWrappingReader(); 809 return x; 810 } 811 ReadElementContentAsBase64(byte[] array, int offset, int len)812 public int ReadElementContentAsBase64(byte[] array, int offset, int len) 813 { 814 ResetWrappingReader(); 815 int x = Internal.ReadElementContentAsBase64(array, offset, len); 816 CheckWrappingReader(); 817 return x; 818 } 819 ReadElementContentAsBinHex(byte[] array, int offset, int len)820 public int ReadElementContentAsBinHex(byte[] array, int offset, int len) 821 { 822 ResetWrappingReader(); 823 int x = Internal.ReadElementContentAsBinHex(array, offset, len); 824 CheckWrappingReader(); 825 return x; 826 } 827 828 public bool CanReadValueChunk 829 { 830 get 831 { 832 ResetWrappingReader(); 833 bool x = Internal.CanReadValueChunk; 834 CheckWrappingReader(); 835 return x; 836 } 837 } 838 ReadValueChunk(char[] buffer, int offset, int count)839 public int ReadValueChunk(char[] buffer, int offset, int count) 840 { 841 ResetWrappingReader(); 842 int x = Internal.ReadValueChunk(buffer, offset, count); 843 CheckWrappingReader(); 844 return x; 845 } 846 ResetState()847 public void ResetState() 848 { 849 } 850 851 //////////////////////////////////////////////////////////////// 852 // Dump ALL properties 853 // 854 //////////////////////////////////////////////////////////////// DumpAll()855 public void DumpAll() 856 { 857 while (Read()) 858 { 859 CError.Write("NodeType = " + NodeType + "\t|\t"); 860 CError.Write("NodeName = " + Name + "\t|\t"); 861 CError.Write("NodeLocalName = " + LocalName + "\t|\t"); 862 CError.Write("NodeNamespace = " + NamespaceURI + "\t|\t"); 863 CError.Write("NodePrefix = " + Prefix + "\t|\t"); 864 CError.Write("NodeHasValue = " + (HasValue).ToString() + "\t|\t"); 865 CError.Write("NodeValue = " + Value + "\t|\t"); 866 CError.Write("NodeDepth = " + Depth + "\t|\t"); 867 CError.Write("IsEmptyElement = " + IsEmptyElement.ToString() + "\t|\t"); 868 CError.Write("IsDefault = " + IsDefault.ToString() + "\t|\t"); 869 CError.Write("XmlSpace = " + XmlSpace + "\t|\t"); 870 CError.Write("XmlLang = " + XmlLang + "\t|\t"); 871 872 CError.Write("AttributeCount = " + AttributeCount + "\t|\t"); 873 CError.Write("HasAttributes = " + HasAttributes.ToString() + "\t|\t"); 874 875 CError.Write("EOF = " + EOF.ToString() + "\t|\t"); 876 CError.Write("ReadState = " + ReadState.ToString() + "\t|\t"); 877 CError.WriteLine(); 878 } 879 } 880 DumpOneNode()881 public void DumpOneNode() 882 { 883 CError.Write("NodeType = " + NodeType + "\t|\t"); 884 CError.Write("NodeName = " + Name + "\t|\t"); 885 CError.Write("NodeLocalName = " + LocalName + "\t|\t"); 886 CError.Write("NodeNamespace = " + NamespaceURI + "\t|\t"); 887 CError.Write("NodePrefix = " + Prefix + "\t|\t"); 888 CError.Write("NodeHasValue = " + (HasValue).ToString() + "\t|\t"); 889 CError.Write("NodeValue = " + Value + "\t|\t"); 890 CError.Write("NodeDepth = " + Depth + "\t|\t"); 891 CError.Write("IsEmptyElement = " + (IsEmptyElement).ToString() + "\t|\t"); 892 CError.Write("IsDefault = " + (IsDefault).ToString() + "\t|\t"); 893 CError.Write("XmlSpace = " + XmlSpace + "\t|\t"); 894 CError.Write("XmlLang = " + XmlLang + "\t|\t"); 895 896 CError.Write("AttributeCount = " + AttributeCount + "\t|\t"); 897 CError.Write("HasAttributes = " + (HasAttributes).ToString() + "\t|\t"); 898 899 CError.Write("EOF = " + (EOF).ToString() + "\t|\t"); 900 CError.Write("ReadState = " + (ReadState).ToString() + "\t|\t"); 901 902 if (AttributeCount > 0) 903 { 904 CError.WriteLine(); 905 for (int i = 0; i < AttributeCount; i++) 906 { 907 CError.Write("GetAttribute(" + i + ")= " + GetAttribute(i) + "\t|\t"); 908 } 909 } 910 911 CError.WriteLine(); 912 } 913 DumpChars(String strActValue)914 private void DumpChars(String strActValue) 915 { 916 Byte c; 917 int i; 918 919 for (i = 0; i < strActValue.Length; i++) 920 { 921 c = Convert.ToByte(strActValue[i]); 922 CError.WriteLine("Char[" + i.ToString() + "] : " + c.ToString()); 923 } 924 } 925 FindNodeType(XmlNodeType _nodetype)926 public int FindNodeType(XmlNodeType _nodetype) 927 { 928 if (NodeType == _nodetype) 929 return STATUS_PASSED; 930 931 while (Read()) 932 { 933 if (NodeType == XmlNodeType.EntityReference) 934 { 935 if (CanResolveEntity) 936 ResolveEntity(); 937 } 938 939 if (NodeType == XmlNodeType.ProcessingInstruction && NodeType == XmlNodeType.XmlDeclaration) 940 { 941 if (String.Compare(Name, 0, ST_XML, 0, 3) != 0) 942 return STATUS_PASSED; 943 } 944 945 if (NodeType == _nodetype) 946 { 947 return STATUS_PASSED; 948 } 949 950 if (NodeType == XmlNodeType.Element && (_nodetype == XmlNodeType.Attribute)) 951 { 952 if (MoveToFirstAttribute()) 953 { 954 return STATUS_PASSED; 955 } 956 } 957 } 958 return STATUS_FAILED; 959 } 960 961 /////////////////////////////////////// 962 // PositionOnElement 963 /////////////////////////////////////// PositionOnElement(String strElementName)964 public void PositionOnElement(String strElementName) 965 { 966 CError.WriteLine("Seeking Element : " + strElementName); 967 968 if (NodeType == XmlNodeType.Element && Name == strElementName) 969 return; 970 971 while (Read()) 972 { 973 if (NodeType == XmlNodeType.Element && Name == strElementName) 974 break; 975 } 976 977 if (EOF) 978 { 979 throw new CTestException(CTestBase.TEST_FAIL, "Couldn't find element '" + strElementName + "'"); 980 } 981 } 982 983 ////////////////////////////////////////// 984 // PositionOnNodeType 985 ////////////////////////////////////////// PositionOnNodeType(XmlNodeType nodeType)986 public void PositionOnNodeType(XmlNodeType nodeType) 987 { 988 CError.WriteLine("Seeking Nodetype : " + nodeType.ToString()); 989 990 if (NodeType == nodeType) 991 return; 992 993 while (Read() && NodeType != nodeType) 994 { 995 if (NodeType == XmlNodeType.EntityReference) 996 { 997 if (CanResolveEntity) 998 ResolveEntity(); 999 } 1000 if (nodeType == XmlNodeType.ProcessingInstruction && NodeType == XmlNodeType.XmlDeclaration) 1001 { 1002 if (String.Compare(Name, 0, ST_XML, 0, 3) != 0) 1003 return; 1004 } 1005 if (NodeType == XmlNodeType.Element && nodeType == XmlNodeType.Attribute) 1006 { 1007 if (MoveToFirstAttribute()) 1008 { 1009 return; 1010 }; 1011 } 1012 } 1013 if (EOF) 1014 { 1015 throw new CTestException(CTestBase.TEST_FAIL, "Couldn't find XmlNodeType " + nodeType); 1016 } 1017 } 1018 1019 /////////////////////// 1020 // VerifyNode 1021 /////////////////////// VerifyNode(XmlNodeType eExpNodeType, String strExpName, String strExpValue)1022 public bool VerifyNode(XmlNodeType eExpNodeType, String strExpName, String strExpValue) 1023 { 1024 bool bPassed = true; 1025 1026 if (NodeType != eExpNodeType) 1027 { 1028 CError.WriteLine("NodeType doesn't match"); 1029 CError.WriteLine(" Expected NodeType: " + eExpNodeType); 1030 CError.WriteLine(" Actual NodeType: " + NodeType); 1031 bPassed = false; 1032 } 1033 if (Name != strExpName) 1034 { 1035 CError.WriteLine("Name doesn't match:"); 1036 CError.WriteLine(" Expected Name: '" + strExpName + "'"); 1037 CError.WriteLine(" Actual Name: '" + Name + "'"); 1038 1039 bPassed = false; 1040 } 1041 if (Value != strExpValue) 1042 { 1043 CError.WriteLine("Value doesn't match:"); 1044 CError.WriteLine(" Expected Value: '" + strExpValue + "'"); 1045 CError.WriteLine(" Actual Value: '" + Value + "'"); 1046 1047 bPassed = false; 1048 } 1049 1050 if (bPassed) 1051 { 1052 CError.WriteLine("Passed"); 1053 } 1054 1055 return bPassed; 1056 } 1057 1058 /////////////////////// 1059 // CompareNode 1060 /////////////////////// CompareNode(XmlNodeType eExpNodeType, String strExpName, String strExpValue)1061 public void CompareNode(XmlNodeType eExpNodeType, String strExpName, String strExpValue) 1062 { 1063 bool bNode = VerifyNode(eExpNodeType, strExpName, strExpValue); 1064 CError.Compare(bNode, "VerifyNode failed"); 1065 } 1066 } 1067 1068 1069 #region CustomReader 1070 /// <summary> 1071 /// CustomReader which wraps Factory created reader. 1072 /// </summary> 1073 1074 public class CustomReader : XmlReader, IXmlLineInfo 1075 { 1076 private XmlReader _tr = null; 1077 Dispose(bool disposing)1078 protected override void Dispose(bool disposing) 1079 { 1080 base.Dispose(disposing); 1081 1082 if (_tr != null) 1083 _tr.Dispose(); 1084 } 1085 1086 public int LinePosition 1087 { 1088 get 1089 { 1090 return ((IXmlLineInfo)_tr).LinePosition; 1091 } 1092 } 1093 1094 public int LineNumber 1095 { 1096 get 1097 { 1098 return ((IXmlLineInfo)_tr).LineNumber; 1099 } 1100 } 1101 HasLineInfo()1102 public bool HasLineInfo() 1103 { 1104 return ((IXmlLineInfo)_tr).HasLineInfo(); 1105 } 1106 CustomReader(string filename)1107 public CustomReader(string filename) 1108 { 1109 XmlReaderSettings rs = new XmlReaderSettings(); 1110 rs.DtdProcessing = DtdProcessing.Ignore; 1111 _tr = ReaderHelper.Create(filename, rs); 1112 } 1113 CustomReader(TextReader txtReader, bool isFragment)1114 public CustomReader(TextReader txtReader, bool isFragment) 1115 { 1116 XmlReaderSettings settings = new XmlReaderSettings(); 1117 settings.DtdProcessing = DtdProcessing.Ignore; 1118 if (!isFragment) 1119 _tr = ReaderHelper.Create(txtReader, settings, (string)null); 1120 else 1121 { 1122 settings.ConformanceLevel = ConformanceLevel.Fragment; 1123 _tr = ReaderHelper.Create(txtReader, settings, (string)null); 1124 } 1125 } 1126 CustomReader(string url, bool isFragment)1127 public CustomReader(string url, bool isFragment) 1128 { 1129 XmlReaderSettings settings = new XmlReaderSettings(); 1130 settings.DtdProcessing = DtdProcessing.Ignore; 1131 if (!isFragment) 1132 _tr = ReaderHelper.Create(url, settings); 1133 else 1134 { 1135 settings.ConformanceLevel = ConformanceLevel.Fragment; 1136 _tr = ReaderHelper.Create(url, settings); 1137 } 1138 } 1139 CustomReader(Stream stream)1140 public CustomReader(Stream stream) 1141 { 1142 XmlReaderSettings rs = new XmlReaderSettings(); 1143 rs.DtdProcessing = DtdProcessing.Ignore; 1144 _tr = ReaderHelper.Create(stream, rs, (string)null); 1145 } 1146 1147 public override int Depth 1148 { 1149 get 1150 { 1151 return _tr.Depth; 1152 } 1153 } 1154 1155 public override string Value 1156 { 1157 get 1158 { 1159 return _tr.Value; 1160 } 1161 } 1162 MoveToElement()1163 public override bool MoveToElement() 1164 { 1165 return _tr.MoveToElement(); 1166 } 1167 1168 public override string LocalName 1169 { 1170 get 1171 { 1172 return _tr.LocalName; 1173 } 1174 } 1175 1176 public override XmlNodeType NodeType 1177 { 1178 get 1179 { 1180 return _tr.NodeType; 1181 } 1182 } 1183 MoveToNextAttribute()1184 public override bool MoveToNextAttribute() 1185 { 1186 return _tr.MoveToNextAttribute(); 1187 } 1188 MoveToFirstAttribute()1189 public override bool MoveToFirstAttribute() 1190 { 1191 return _tr.MoveToFirstAttribute(); 1192 } 1193 LookupNamespace(string prefix)1194 public override string LookupNamespace(string prefix) 1195 { 1196 return _tr.LookupNamespace(prefix); 1197 } 1198 1199 public override bool EOF 1200 { 1201 get 1202 { 1203 return _tr.EOF; 1204 } 1205 } 1206 1207 public override bool HasValue 1208 { 1209 get 1210 { 1211 return _tr.HasValue; 1212 } 1213 } 1214 1215 public override string NamespaceURI 1216 { 1217 get 1218 { 1219 return _tr.NamespaceURI; 1220 } 1221 } 1222 Read()1223 public override bool Read() 1224 { 1225 return _tr.Read(); 1226 } 1227 1228 public override XmlNameTable NameTable 1229 { 1230 get 1231 { 1232 return _tr.NameTable; 1233 } 1234 } 1235 1236 public override bool CanResolveEntity 1237 { 1238 get 1239 { 1240 return _tr.CanResolveEntity; 1241 } 1242 } 1243 ResolveEntity()1244 public override void ResolveEntity() 1245 { 1246 _tr.ResolveEntity(); 1247 } 1248 GetAttribute(string name, string namespaceURI)1249 public override string GetAttribute(string name, string namespaceURI) 1250 { 1251 return _tr.GetAttribute(name, namespaceURI); 1252 } 1253 GetAttribute(string name)1254 public override string GetAttribute(string name) 1255 { 1256 return _tr.GetAttribute(name); 1257 } 1258 GetAttribute(int i)1259 public override string GetAttribute(int i) 1260 { 1261 return _tr.GetAttribute(i); 1262 } 1263 1264 public override string BaseURI 1265 { 1266 get 1267 { 1268 return _tr.BaseURI; 1269 } 1270 } 1271 ReadAttributeValue()1272 public override bool ReadAttributeValue() 1273 { 1274 return _tr.ReadAttributeValue(); 1275 } 1276 1277 public override string Prefix 1278 { 1279 get 1280 { 1281 return _tr.Prefix; 1282 } 1283 } 1284 MoveToAttribute(string name, string ns)1285 public override bool MoveToAttribute(string name, string ns) 1286 { 1287 return _tr.MoveToAttribute(name, ns); 1288 } 1289 MoveToAttribute(string name)1290 public override bool MoveToAttribute(string name) 1291 { 1292 return _tr.MoveToAttribute(name); 1293 } 1294 1295 public override int AttributeCount 1296 { 1297 get 1298 { 1299 return _tr.AttributeCount; 1300 } 1301 } 1302 1303 public override ReadState ReadState 1304 { 1305 get 1306 { 1307 return _tr.ReadState; 1308 } 1309 } 1310 1311 public override bool IsEmptyElement 1312 { 1313 get 1314 { 1315 return _tr.IsEmptyElement; 1316 } 1317 } 1318 } 1319 #endregion 1320 } 1321