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 
8 namespace System.Xml.Tests
9 {
10     ////////////////////////////////////////////////////////////////
11     // TestCase TCXML BaseGeneral
12     //
13     ////////////////////////////////////////////////////////////////
14     public abstract class TCXMLReaderBaseGeneral : CDataReaderTestCase
15     {
16         public static string strAttr = "Attr";
17         public static string strNamespace = "http://www.foo.com";
18 
19         public const int ASCII_ZERO = 48;
20 
21         public const String ST_ENTTEST_NAME = "ENTITY1";
22 
23         public const String ST_TEXT_VALUE = "xxx";
24 
25         public const String ST_DECIMAL = "#decimal";
26         public const String ST_HEXIDECIMAL = "#hexidecimal";
27         public const String ST_GT = "gt";
28         public const String ST_LT = "lt";
29 
30         public const String ST_IGNORE_ENTITIES = "xxx>xxxBxxxDxxx&e1;xxx";
31         public const String ST_EXPAND_ENTITIES = "xxx>xxxBxxxDxxxe1fooxxx";
32         public const String ST_EXPAND_ENTITIES2 = "xxx>xxxBxxxDxxxe1fooxxx";
33         public const String ST_EXPAND_ENTITIES3 = "xxx>xxxBxxxDxxx&e1;xxx";
34         public const String ST_EXPAND_CHAR_ENTITIES = "xxx>xxxBxxxDxxx";
35         public const String ST_ENT1_ATT_EXPAND_ENTITIES = "xxx<xxxAxxxCxxxNO_REFERENCEe1;xxx";
36         public const String ST_ENT1_ATT_EXPAND_CHAR_ENTITIES = "xxx<xxxAxxxCxxx&e1;xxx";
37 
38         public const String ST_ENT1_ATT_IGNORE_ENTITIES = "xxx&lt;xxx&#65;xxx&#x43;xxx&e1;xxx";
39         public const String ST_ENT1_ATT_EXPAND_CHAR_ENTITIES2 = "xxx&lt;xxxAxxxCxxx&e1;xxx";
40         public const String ST_ENT1_ATT_EXPAND_CHAR_ENTITIES3 = "xxx<xxxAxxxCxxx";
41         public const String ST_ENT1_ATT_EXPAND_CHAR_ENTITIES4 = "xxx&lt;xxxAxxxCxxxe1fooxxx";
42 
43         private const string _NOVALIDATION = "None";
44         private const string _VALIDATION_ONE = "Validation_One";
45         private const string _VALIDATION_TWO = "Validation_Two";
46 
47         protected XmlReader MainReader = null;
48 
PostReloadSource()49         public virtual void PostReloadSource()
50         {
51         }
52 
CloseReader()53         public virtual void CloseReader()
54         {
55             if (DataReader.Internal != null && !IsSubtreeReader())
56             {
57                 DataReader.Close();
58             }
59         }
60 
ReloadSource(MyDict<string, object> options)61         public virtual void ReloadSource(MyDict<string, object> options)
62         {
63             CloseReader();
64             options[ReaderFactory.HT_CURDESC] = GetDescription().ToLowerInvariant();
65             options[ReaderFactory.HT_CURVAR] = CurVariation.Desc.ToLowerInvariant();
66             DataReader.Internal = TestModule.ReaderFactory.Create(options);
67             PostReloadSource();
68         }
69 
ReloadSource()70         public virtual void ReloadSource()
71         {
72             EREADER_TYPE eReaderType = EREADER_TYPE.GENERIC;
73 
74             if (GetDescription().ToUpperInvariant() == "XSLTREADER")
75                 eReaderType = EREADER_TYPE.XSLT_COPY;
76 
77             ReloadSource(eReaderType);
78         }
79 
ReloadSource(EREADER_TYPE eReaderType)80         public virtual void ReloadSource(EREADER_TYPE eReaderType)
81         {
82             string filename = TestFiles.GetTestFileName(eReaderType);
83 
84             ReloadSource(filename);
85         }
86 
ReloadSource(string filename)87         public virtual void ReloadSource(string filename)
88         {
89             MyDict<string, object> ht = new MyDict<string, object>();
90             ht[ReaderFactory.HT_FILENAME] = filename;
91 
92             ReloadSource(ht);
93         }
94 
ReloadSource(StringReader strRdr)95         public virtual void ReloadSource(StringReader strRdr)
96         {
97             MyDict<string, object> ht = new MyDict<string, object>();
98             ht[ReaderFactory.HT_STRINGREADER] = strRdr;
99             ReloadSource(ht);
100         }
101 
ReloadSource(Stream stream, string filename)102         public virtual void ReloadSource(Stream stream, string filename)
103         {
104             MyDict<string, object> ht = new MyDict<string, object>();
105             ht[ReaderFactory.HT_FILENAME] = filename;
106             ht[ReaderFactory.HT_STREAM] = stream;
107             ReloadSource(ht);
108         }
109 
ReloadSourceStr(string strxml)110         public virtual void ReloadSourceStr(string strxml)
111         {
112             MyDict<string, object> ht = new MyDict<string, object>();
113             ht[ReaderFactory.HT_FRAGMENT] = strxml;
114             ReloadSource(ht);
115         }
116 
PostExecuteVariation(int index, object param)117         public override void PostExecuteVariation(int index, object param)
118         {
119             if (DataReader.Internal != null && !IsSubtreeReader())
120             {
121             }
122 
123             if (MainReader != null)
124             {
125             }
126         }
127 
128         //////////////////////////////////////////
129         // PositionOnNodeType
130         //////////////////////////////////////////
PositionOnNodeType(XmlNodeType nodeType)131         protected void PositionOnNodeType(XmlNodeType nodeType)
132         {
133             DataReader.PositionOnNodeType(nodeType);
134         }
135 
FindNodeType(XmlNodeType nodeType)136         protected int FindNodeType(XmlNodeType nodeType)
137         {
138             return DataReader.FindNodeType(nodeType);
139         }
140 
IsXsltReader()141         protected bool IsXsltReader()
142         {
143             return GetDescription().ToUpperInvariant() == "XSLTREADER";
144         }
145 
IsXmlTextReader()146         protected bool IsXmlTextReader()
147         {
148             return (GetDescription().ToUpperInvariant() == "XMLREADER" ||
149                             GetDescription().ToUpperInvariant() == "XMLTEXTREADER");
150         }
151 
IsXmlValidatingReader()152         protected bool IsXmlValidatingReader()
153         {
154             return GetDescription().ToUpperInvariant() == "XMLVALIDATINGREADER";
155         }
156 
IsXmlNodeReader()157         protected bool IsXmlNodeReader()
158         {
159             return GetDescription().ToUpperInvariant() == "XMLNODEREADER";
160         }
161 
IsXmlNodeReaderDataDoc()162         protected bool IsXmlNodeReaderDataDoc()
163         {
164             return GetDescription().ToUpperInvariant() == "XMLNODEREADER(DATADOC)";
165         }
166 
IsCharCheckingReader()167         protected bool IsCharCheckingReader()
168         {
169             return GetDescription().ToUpperInvariant() == "CHARCHECKINGREADER";
170         }
171 
IsWrappedReader()172         protected bool IsWrappedReader()
173         {
174             return (GetDescription().ToUpperInvariant() == "WRAPPEDREADER");
175         }
176 
IsCoreReader()177         protected bool IsCoreReader()
178         {
179             return (GetDescription().ToUpperInvariant() == "FACTORYREADER" ||
180                 GetDescription().ToUpperInvariant() == "COREVALIDATINGREADER" ||
181                 GetDescription().ToUpperInvariant() == "XSDVALIDATINGREADER" ||
182                 GetDescription().ToUpperInvariant() == "BINARYREADER" ||
183                 GetDescription().ToUpperInvariant() == "SUBTREEREADER" ||
184                 GetDescription().ToUpperInvariant() == "CUSTOMINHERITEDREADER" ||
185                 GetDescription().ToUpperInvariant() == "CHARCHECKINGREADER" ||
186                 GetDescription().ToUpperInvariant() == "WRAPPEDREADER");
187         }
188 
IsFactoryReader()189         protected bool IsFactoryReader()
190         {
191             return (GetDescription().ToUpperInvariant() == "FACTORYREADER" ||
192                 GetDescription().ToUpperInvariant() == "COREVALIDATINGREADER" ||
193                 GetDescription().ToUpperInvariant() == "XSDVALIDATINGREADER");
194         }
195 
IsFactoryTextReader()196         protected bool IsFactoryTextReader()
197         {
198             return (GetDescription().ToUpperInvariant() == "FACTORYREADER" ||
199                 GetDescription().ToUpperInvariant() == "CUSTOMINHERITEDREADER");
200         }
201 
IsCustomReader()202         protected bool IsCustomReader()
203         {
204             return GetDescription().ToUpperInvariant().StartsWith("CUSTOMINHERITEDREADER");
205         }
206 
IsFactoryValidatingReader()207         protected bool IsFactoryValidatingReader()
208         {
209             return (GetDescription().ToUpperInvariant() == "COREVALIDATINGREADER" || GetDescription().ToUpperInvariant() == "XSDVALIDATINGREADER");
210         }
211 
IsBinaryReader()212         protected bool IsBinaryReader()
213         {
214             return (GetDescription().ToUpperInvariant() == "BINARYREADER");
215         }
216 
IsSubtreeReader()217         protected bool IsSubtreeReader()
218         {
219             return (GetDescription().ToUpperInvariant() == "SUBTREEREADER");
220         }
221 
IsXPathNavigatorReader()222         protected bool IsXPathNavigatorReader()
223         {
224             return (GetDescription().ToUpperInvariant() == "NAVIGATORREADER");
225         }
226 
IsRoundTrippedReader()227         protected bool IsRoundTrippedReader()
228         {
229             return IsBinaryReader() || IsXmlNodeReader() || IsXmlNodeReaderDataDoc() || IsXPathNavigatorReader() || IsXsltReader();
230         }
231 
CheckCanReadBinaryContent()232         public bool CheckCanReadBinaryContent()
233         {
234             byte[] buffer = new byte[1];
235 
236             if (!DataReader.CanReadBinaryContent)
237             {
238                 try
239                 {
240                     int nBytes = 0;
241                     switch ((int)new Random().Next(4))
242                     {
243                         case 0:
244                             CError.WriteLineIgnore("Selecting RCABH");
245                             nBytes = DataReader.ReadContentAsBinHex(buffer, 0, 1);
246                             break;
247                         case 1:
248                             CError.WriteLineIgnore("Selecting RECABH");
249                             nBytes = DataReader.ReadElementContentAsBinHex(buffer, 0, 1);
250                             break;
251                         case 2:
252                             CError.WriteLineIgnore("Selecting RCAB64");
253                             nBytes = DataReader.ReadContentAsBase64(buffer, 0, 1);
254                             break;
255                         case 3:
256                             CError.WriteLineIgnore("Selecting RECAB64");
257                             nBytes = DataReader.ReadElementContentAsBase64(buffer, 0, 1);
258                             break;
259                     }
260                     throw new CTestFailedException("ReadContentAsBinHex doesn't throw NotSupportedException");
261                 }
262                 catch (NotSupportedException)
263                 {
264                     return true;
265                 }
266             }
267             return false;
268         }
269 
270         private static string s_strValidation = _NOVALIDATION;
271 
272         public string StrValidation
273         {
274             get { return s_strValidation; }
275             set { s_strValidation = value; }
276         }
277 
DumpStat()278         public void DumpStat()
279         {
280             if (DataReader == null)
281             {
282                 CError.WriteLine("Reader not initialized");
283                 return;
284             }
285 
286             CError.WriteLine("Dumping DataReader Status ... ");
287             CError.WriteLine("Status : " + DataReader.ReadState);
288             CError.WriteLine("Name = " + DataReader.Name);
289             CError.WriteLine("Value = " + DataReader.Value);
290             CError.WriteLine("ValueType = " + DataReader.ValueType);
291             CError.WriteLine("NodeType = " + DataReader.NodeType);
292             CError.WriteLine("-----------------");
293         }
294     }
295 
296     ////////////////////////////////////////////////////////////////
297     // TestCase TCXML Depth
298     //
299     ////////////////////////////////////////////////////////////////
300     [InheritRequired()]
301     public abstract partial class TCDepth : TCXMLReaderBaseGeneral
302     {
303         [Variation("XmlReader Depth at the Root", Pri = 0)]
TestDepth1()304         public int TestDepth1()
305         {
306             ReloadSource();
307             int iDepth = 0;
308 
309             DataReader.PositionOnElement("PLAY");
310             CError.Compare(DataReader.Depth, iDepth, "Depth should be " + iDepth);
311             DataReader.Close();
312             return TEST_PASS;
313         }
314 
315         [Variation("XmlReader Depth at Empty Tag")]
TestDepth2()316         public int TestDepth2()
317         {
318             ReloadSource();
319             int iDepth = 2;
320 
321             DataReader.PositionOnElement("EMPTY1");
322             CError.Compare(DataReader.Depth, iDepth, "Depth should be " + iDepth);
323             return TEST_PASS;
324         }
325 
326         [Variation("XmlReader Depth at Empty Tag with Attributes")]
TestDepth3()327         public int TestDepth3()
328         {
329             ReloadSource();
330             int iDepth = 2;
331 
332             DataReader.PositionOnElement("ACT1");
333             CError.Compare(DataReader.Depth, iDepth, "Element Depth should be " + (iDepth).ToString());
334 
335             while (DataReader.MoveToNextAttribute() == true)
336             {
337                 CError.WriteLine("Name=" + DataReader.Name + " Value=" + DataReader.Value + " NodeType=" + (DataReader.NodeType).ToString());
338                 CError.Compare(DataReader.Depth, iDepth + 1, "Attr Depth should be " + (iDepth + 1).ToString());
339             }
340             return TEST_PASS;
341         }
342 
343         [Variation("XmlReader Depth at Non Empty Tag with Text")]
TestDepth4()344         public int TestDepth4()
345         {
346             ReloadSource();
347             int iDepth = 2;
348 
349             DataReader.PositionOnElement("NONEMPTY1");
350 
351             CError.Compare(DataReader.Depth, iDepth, "Depth should be " + iDepth);
352             while (true == DataReader.Read())
353             {
354                 CError.WriteLine("Name=" + DataReader.Name + " Value=" + DataReader.Value + " NodeType=" + (DataReader.NodeType).ToString());
355                 if (DataReader.NodeType == XmlNodeType.Text)
356                     CError.Compare(DataReader.Depth, iDepth + 1, "Depth should be " + (iDepth + 1).ToString());
357 
358                 if (DataReader.Name == "NONEMPTY1" && (DataReader.NodeType == XmlNodeType.EndElement)) break;
359             }
360             CError.Compare(DataReader.Depth, iDepth, "Depth should be " + iDepth);
361             return TEST_PASS;
362         }
363 
364         [Variation("Depth on node from expanded entity")]
TestDepth5()365         public int TestDepth5()
366         {
367             string strxml = "<!DOCTYPE root[<!ELEMENT root ANY><!ENTITY MyEntity \"<E a='1'/>\nT2<E/>\">]><root>&MyEntity;</root>";
368 
369             if (IsXmlTextReader() || IsCoreReader())
370                 return TEST_SKIPPED;
371 
372             ReloadSource(new StringReader(strxml));
373             while (DataReader.Read())
374             {
375                 if (DataReader.NodeType == XmlNodeType.EntityReference)
376                     DataReader.ResolveEntity();
377 
378                 if (DataReader.Name == "E")
379                     break;
380             }
381 
382             int nDepth = 1;
383             if (IsXmlNodeReader() || IsXmlValidatingReader())
384                 nDepth++; // they also see the entity reference node
385 
386             CError.Compare(DataReader.Depth, nDepth, "E");
387 
388             DataReader.Read();
389             CError.Compare(DataReader.VerifyNode(XmlNodeType.Text, String.Empty, "\nT2"), "nT2");
390             CError.Compare(DataReader.Depth, nDepth, "T2");
391 
392             DataReader.Read();
393             CError.Compare(DataReader.VerifyNode(XmlNodeType.Element, "E", String.Empty), "nE2");
394             CError.Compare(DataReader.Depth, nDepth, "E2");
395 
396             if (IsXmlNodeReader() || IsXmlValidatingReader())
397             {
398                 DataReader.Read();
399                 CError.Compare(DataReader.VerifyNode(XmlNodeType.EndEntity, "MyEntity", String.Empty), "ee");
400                 CError.Compare(DataReader.Depth, 1, "eed");
401             }
402 
403             DataReader.Read();
404             CError.Compare(DataReader.VerifyNode(XmlNodeType.EndElement, "root", String.Empty), "nr");
405             CError.Compare(DataReader.Depth, 0, "er");
406 
407             return TEST_PASS;
408         }
409 
410         [Variation("Depth on node from expanded entity EntityHandling = ExpandEntities")]
TestDepth6()411         public int TestDepth6()
412         {
413             string strxml = "<!DOCTYPE root[<!ELEMENT root ANY><!ENTITY MyEntity \"<E a='1'/>\nT2<E/>\">]><root>&MyEntity;</root>";
414 
415             if (IsXmlTextReader() || IsCoreReader())
416                 return TEST_SKIPPED;
417 
418             ReloadSource(new StringReader(strxml));
419 
420             DataReader.PositionOnElement("E");
421 
422             CError.Compare(DataReader.Depth, 1, "E");
423 
424             DataReader.Read();
425             CError.Compare(DataReader.VerifyNode(XmlNodeType.Text, String.Empty, "\nT2"), "nT2");
426             CError.Compare(DataReader.Depth, 1, "T2");
427 
428             DataReader.Read();
429             CError.Compare(DataReader.VerifyNode(XmlNodeType.Element, "E", String.Empty), "nE2");
430             CError.Compare(DataReader.Depth, 1, "E2");
431 
432             DataReader.Read();
433             CError.Compare(DataReader.VerifyNode(XmlNodeType.EndElement, "root", String.Empty), "nr");
434             CError.Compare(DataReader.Depth, 0, "er");
435 
436             return TEST_PASS;
437         }
438     }
439 
440     ////////////////////////////////////////////////////////////////
441     // TestCase TCXML Namespace
442     //
443     ////////////////////////////////////////////////////////////////
444     [InheritRequired()]
445     public abstract partial class TCNamespace : TCXMLReaderBaseGeneral
446     {
447         private static string s_NONAMESPACE = "NONAMESPACE";
448 
449         [Variation("Namespace test within a scope (no nested element)", Pri = 0)]
TestNamespace1()450         public int TestNamespace1()
451         {
452             ReloadSource();
453             int i = 0;
454 
455             DataReader.PositionOnElement("NAMESPACE0");
456 
457             while (true == DataReader.Read())
458             {
459                 if (DataReader.Name == "NAMESPACE1") break;
460                 CError.WriteLine("Name=" + DataReader.Name + " Value=" + DataReader.Value + " NodeType=" + (DataReader.NodeType).ToString() + " Loop " + i); i++;
461 
462                 if (DataReader.NodeType == XmlNodeType.Element)
463                 {
464                     CError.Compare(DataReader.NamespaceURI, "1", "Compare Namespace");
465                     CError.Compare(DataReader.Name, "bar:check", "Compare Name");
466                     CError.Compare(DataReader.LocalName, "check", "Compare LocalName");
467                     CError.Compare(DataReader.Prefix, "bar", "Compare Prefix");
468                 }
469             }
470             return TEST_PASS;
471         }
472 
473         [Variation("Namespace test within a scope (with nested element)", Pri = 0)]
TestNamespace2()474         public int TestNamespace2()
475         {
476             ReloadSource();
477 
478             DataReader.PositionOnElement("NAMESPACE1");
479             while (true == DataReader.Read())
480             {
481                 if (DataReader.Name == "NONAMESPACE") break;
482                 CError.WriteLine("Name=" + DataReader.Name + " Value=" + DataReader.Value + " NodeType=" + (DataReader.NodeType).ToString());
483                 if ((DataReader.NodeType == XmlNodeType.Element) && (DataReader.LocalName == "check"))
484                 {
485                     CError.Compare(DataReader.NamespaceURI, "1", "Compare Namespace");
486                     CError.Compare(DataReader.Name, "bar:check", "Compare Name");
487                     CError.Compare(DataReader.LocalName, "check", "Compare LocalName");
488                     CError.Compare(DataReader.Prefix, "bar", "Compare Prefix");
489                 }
490             }
491             CError.Compare(DataReader.NamespaceURI, String.Empty, "Compare Namespace with String.Empty");
492 
493             return TEST_PASS;
494         }
495 
496         [Variation("Namespace test immediately outside the Namespace scope")]
TestNamespace3()497         public int TestNamespace3()
498         {
499             ReloadSource();
500 
501             DataReader.PositionOnElement(s_NONAMESPACE);
502             CError.Compare(DataReader.NamespaceURI, String.Empty, "Compare Namespace with EmptyString");
503             CError.Compare(DataReader.Name, s_NONAMESPACE, "Compare Name");
504             CError.Compare(DataReader.LocalName, s_NONAMESPACE, "Compare LocalName");
505             CError.Compare(DataReader.Prefix, String.Empty, "Compare Prefix");
506 
507             return TEST_PASS;
508         }
509 
510         [Variation("Namespace test Attribute should has no default namespace", Pri = 0)]
TestNamespace4()511         public int TestNamespace4()
512         {
513             if (IsXPathNavigatorReader())
514                 return TEST_SKIPPED;
515 
516             ReloadSource();
517 
518             DataReader.PositionOnElement("NONAMESPACE1");
519             CError.Compare(DataReader.NamespaceURI, "1000", "Compare Namespace for Element");
520             if (DataReader.MoveToFirstAttribute())
521             {
522                 CError.Compare(DataReader.NamespaceURI, String.Empty, "Compare Namespace for Attr");
523             }
524             return TEST_PASS;
525         }
526 
527         [Variation("Namespace test with multiple Namespace declaration", Pri = 0)]
TestNamespace5()528         public int TestNamespace5()
529         {
530             ReloadSource();
531 
532             DataReader.PositionOnElement("NAMESPACE2");
533             while (true == DataReader.Read())
534             {
535                 if (DataReader.Name == "NAMESPACE3") break;
536                 CError.WriteLine("Name=" + DataReader.Name + " Value=" + DataReader.Value + " NodeType=" + (DataReader.NodeType).ToString());
537                 if ((DataReader.NodeType == XmlNodeType.Element) && (DataReader.LocalName == "check"))
538                 {
539                     CError.Compare(DataReader.NamespaceURI, "2", "Compare Namespace");
540                     CError.Compare(DataReader.Name, "bar:check", "Compare Name");
541                     CError.Compare(DataReader.LocalName, "check", "Compare LocalName");
542                     CError.Compare(DataReader.Prefix, "bar", "Compare Prefix");
543                 }
544             }
545             return TEST_PASS;
546         }
547 
548         [Variation("Namespace test with multiple Namespace declaration, including default namespace")]
TestNamespace6()549         public int TestNamespace6()
550         {
551             if (IsXPathNavigatorReader())
552                 return TEST_SKIPPED;
553 
554             ReloadSource();
555 
556             DataReader.PositionOnElement("NAMESPACE3");
557             while (true == DataReader.Read())
558             {
559                 if (DataReader.Name == "NONAMESPACE") break;
560                 CError.WriteLine("N=" + DataReader.Name + " NS=" + DataReader.NamespaceURI + " V=" + DataReader.Value + " NodeType=" + (DataReader.NodeType).ToString());
561 
562                 if (DataReader.NodeType == XmlNodeType.Element)
563                 {
564                     if (DataReader.LocalName == "check")
565                     {
566                         CError.WriteLine("Here1");
567                         CError.Compare(DataReader.NamespaceURI, "1", "Compare Namespace");
568                         CError.Compare(DataReader.Name, "check", "Compare Name");
569                         CError.Compare(DataReader.LocalName, "check", "Compare LocalName");
570                         CError.Compare(DataReader.Prefix, String.Empty, "Compare Prefix");
571                     }
572                     else if (DataReader.LocalName == "check1")
573                     {
574                         CError.WriteLine("Here2");
575                         CError.Compare(DataReader.NamespaceURI, "1", "Compare Namespace");
576                         CError.Compare(DataReader.Name, "check1", "Compare Name");
577                         CError.Compare(DataReader.LocalName, "check1", "Compare LocalName");
578                         CError.Compare(DataReader.Prefix, String.Empty, "Compare Prefix");
579                     }
580                     else if (DataReader.LocalName == "check8")
581                     {
582                         CError.WriteLine("Here3");
583                         CError.Compare(DataReader.NamespaceURI, "8", "Compare Namespace");
584                         CError.Compare(DataReader.Name, "d:check8", "Compare Name");
585                         CError.Compare(DataReader.LocalName, "check8", "Compare LocalName");
586                         CError.Compare(DataReader.Prefix, "d", "Compare Prefix");
587                     }
588                     else if (DataReader.LocalName == "check100")
589                     {
590                         CError.WriteLine("Here4");
591                         CError.Compare(DataReader.NamespaceURI, "100", "Compare Namespace");
592                         CError.Compare(DataReader.Name, "check100", "Compare Name");
593                         CError.Compare(DataReader.LocalName, "check100", "Compare LocalName");
594                         CError.Compare(DataReader.Prefix, String.Empty, "Compare Prefix");
595                     }
596                     else if (DataReader.LocalName == "check5")
597                     {
598                         CError.WriteLine("Here5");
599                         CError.Compare(DataReader.NamespaceURI, "5", "Compare Namespace");
600                         CError.Compare(DataReader.Name, "d:check5", "Compare Name");
601                         CError.Compare(DataReader.LocalName, "check5", "Compare LocalName");
602                         CError.Compare(DataReader.Prefix, "d", "Compare Prefix");
603                     }
604                     else if (DataReader.LocalName == "check14")
605                     {
606                         CError.WriteLine("Here6");
607                         CError.Compare(DataReader.NamespaceURI, "14", "Compare Namespace");
608                         CError.Compare(DataReader.Name, "check14", "Compare Name");
609                         CError.Compare(DataReader.LocalName, "check14", "Compare LocalName");
610                         CError.Compare(DataReader.Prefix, String.Empty, "Compare Prefix");
611                     }
612                     else if (DataReader.LocalName == "a13")
613                     {
614                         CError.WriteLine("Here7");
615                         CError.Compare(DataReader.NamespaceURI, "1", "Compare Namespace1");
616                         CError.Compare(DataReader.Name, "a13", "Compare Name1");
617                         CError.Compare(DataReader.LocalName, "a13", "Compare LocalName1");
618                         CError.Compare(DataReader.Prefix, String.Empty, "Compare Prefix1");
619                         DataReader.MoveToFirstAttribute();
620                         CError.Compare(DataReader.NamespaceURI, "13", "Compare Namespace2");
621                         CError.Compare(DataReader.Name, "a:check", "Compare Name2");
622                         CError.Compare(DataReader.LocalName, "check", "Compare LocalName2");
623                         CError.Compare(DataReader.Prefix, "a", "Compare Prefix2");
624                         CError.Compare(DataReader.Value, "Namespace=13", "Compare Name2");
625                     }
626                 }
627             }
628             return TEST_PASS;
629         }
630 
631         [Variation("Namespace URI for xml prefix", Pri = 0)]
TestNamespace7()632         public int TestNamespace7()
633         {
634             string strxml = "<ROOT xml:space='preserve'/>";
635             ReloadSource(new StringReader(strxml));
636 
637             DataReader.PositionOnElement("ROOT");
638             DataReader.MoveToFirstAttribute();
639             CError.Compare(DataReader.NamespaceURI, "http://www.w3.org/XML/1998/namespace", "xml");
640 
641             return TEST_PASS;
642         }
643 
644         [Variation("XmlReader.ReadContentAs does not use the provided IXmlNamespaceResolver")]
sqlbu435761()645         public int sqlbu435761()
646         {
647             string xml = @"<a>p:foo</a>";
648             ReloadSource(new StringReader(xml));
649 
650             while (DataReader.Read())
651             {
652                 if (DataReader.NodeType == XmlNodeType.Text)
653                 {
654                     break;
655                 }
656             }
657             XmlNamespaceManager nsm = new XmlNamespaceManager(DataReader.NameTable);
658             nsm.AddNamespace("p", "ns1");
659             XmlQualifiedName qname = (XmlQualifiedName)DataReader.ReadContentAs(typeof(XmlQualifiedName), nsm);
660             CError.Compare("ns1:foo", qname.ToString(), "Wrong namespace returned");
661 
662             return TEST_PASS;
663         }
664     }
665 
666     ////////////////////////////////////////////////////////////////
667     // TestCase TCXML LookupNamespace
668     //
669     ////////////////////////////////////////////////////////////////
670     [InheritRequired()]
671     public abstract class TCLookupNamespace : TCXMLReaderBaseGeneral
672     {
673         [Variation("LookupNamespace test within EmptyTag")]
LookupNamespace1()674         public int LookupNamespace1()
675         {
676             ReloadSource();
677             DataReader.PositionOnElement("EMPTY_NAMESPACE");
678             do
679             {
680                 CError.WriteLine("Name=" + DataReader.Name + " Value=" + DataReader.Value + " NodeType=" + (DataReader.NodeType).ToString());
681                 CError.Compare(DataReader.LookupNamespace("bar"), "1", "Compare LookupNamespace");
682             } while (DataReader.MoveToNextAttribute() == true);
683             return TEST_PASS;
684         }
685 
686         [Variation("LookupNamespace test with Default namespace within EmptyTag", Pri = 0)]
LookupNamespace2()687         public int LookupNamespace2()
688         {
689             ReloadSource();
690             DataReader.PositionOnElement("EMPTY_NAMESPACE1");
691             do
692             {
693                 CError.WriteLine("Name=" + DataReader.Name + " Value=" + DataReader.Value + " NodeType=" + (DataReader.NodeType).ToString());
694                 CError.Compare(DataReader.LookupNamespace(String.Empty), "14", "Compare LookupNamespace");
695             } while (DataReader.MoveToNextAttribute() == true);
696             return TEST_PASS;
697         }
698 
699         [Variation("LookupNamespace test within a scope (no nested element)", Pri = 0)]
LookupNamespace3()700         public int LookupNamespace3()
701         {
702             ReloadSource();
703             int i = 0;
704             while (true == DataReader.Read())
705             {
706                 if (DataReader.Name == "NAMESPACE0") break;
707                 CError.Compare(DataReader.LookupNamespace("bar"), null, "Compare LookupNamespace");
708             }
709 
710             while (true == DataReader.Read())
711             {
712                 CError.WriteLine("Name=" + DataReader.Name + " Value=" + DataReader.Value + " NodeType=" + (DataReader.NodeType).ToString() + " Loop " + i); i++;
713                 CError.Compare(DataReader.LookupNamespace("bar"), "1", "Compare LookupNamespace");
714                 if (DataReader.Name == "NAMESPACE0" && DataReader.NodeType == XmlNodeType.EndElement) break;
715             }
716             return TEST_PASS;
717         }
718 
719         [Variation("LookupNamespace test within a scope (with nested element)", Pri = 0)]
LookupNamespace4()720         public int LookupNamespace4()
721         {
722             ReloadSource();
723             DataReader.PositionOnElement("NAMESPACE1");
724             while (true == DataReader.Read())
725             {
726                 CError.WriteLine("Name=" + DataReader.Name + " Value=" + DataReader.Value + " NodeType=" + (DataReader.NodeType).ToString());
727                 CError.Compare(DataReader.LookupNamespace("bar"), "1", "Compare LookupNamespace");
728                 if (DataReader.Name == "NAMESPACE1" && DataReader.NodeType == XmlNodeType.EndElement)
729                 {
730                     DataReader.Read();
731                     break;
732                 }
733             }
734             CError.Compare(DataReader.LookupNamespace("bar"), null, "Compare LookupNamespace with String.Empty");
735 
736             return TEST_PASS;
737         }
738 
739         [Variation("LookupNamespace test immediately outside the Namespace scope")]
LookupNamespace5()740         public int LookupNamespace5()
741         {
742             ReloadSource();
743             DataReader.PositionOnElement("NONAMESPACE");
744             CError.Compare(DataReader.LookupNamespace("bar"), null, "Compare LookupNamespace with null");
745 
746             return TEST_PASS;
747         }
748 
749         [Variation("LookupNamespace test with multiple Namespace declaration", Pri = 0)]
LookupNamespace6()750         public int LookupNamespace6()
751         {
752             ReloadSource();
753             DataReader.PositionOnElement("NAMESPACE2");
754 
755             string strValue = "1";
756             while (true == DataReader.Read())
757             {
758                 CError.WriteLine("Name=" + DataReader.Name + " Value=" + DataReader.Value + " NodeType=" + (DataReader.NodeType).ToString());
759 
760                 if (DataReader.Name == "c")
761                 {
762                     strValue = "2";
763                     CError.Compare(DataReader.LookupNamespace("bar"), strValue, "Compare LookupNamespace-a");
764                     if (DataReader.NodeType == XmlNodeType.EndElement)
765                         strValue = "1";
766                 }
767                 else
768                     CError.Compare(DataReader.LookupNamespace("bar"), strValue, "Compare LookupNamespace-a");
769 
770                 if (DataReader.Name == "NAMESPACE2" && DataReader.NodeType == XmlNodeType.EndElement)
771                 {
772                     CError.Compare(DataReader.LookupNamespace("bar"), strValue, "Compare LookupNamespace-a");
773                     DataReader.Read();
774                     break;
775                 }
776             }
777             return TEST_PASS;
778         }
779 
CompareAllNS(string strDef, string strA, string strB, string strC, string strD, string strE, string strF, string strG, string strH)780         private void CompareAllNS(string strDef, string strA, string strB, string strC, string strD, string strE, string strF, string strG, string strH)
781         {
782             CError.Compare(DataReader.LookupNamespace(String.Empty), strDef, "Compare LookupNamespace-default");
783             CError.Compare(DataReader.LookupNamespace("a"), strA, "Compare LookupNamespace-a");
784             CError.Compare(DataReader.LookupNamespace("b"), strB, "Compare LookupNamespace-b");
785             CError.Compare(DataReader.LookupNamespace("c"), strC, "Compare LookupNamespace-c");
786             CError.Compare(DataReader.LookupNamespace("d"), strD, "Compare LookupNamespace-d");
787             CError.Compare(DataReader.LookupNamespace("e"), strE, "Compare LookupNamespace-e");
788             CError.Compare(DataReader.LookupNamespace("f"), strF, "Compare LookupNamespace-f");
789             CError.Compare(DataReader.LookupNamespace("g"), strG, "Compare LookupNamespace-g");
790             CError.Compare(DataReader.LookupNamespace("h"), strH, "Compare LookupNamespace-h");
791         }
792 
793         [Variation("Namespace test with multiple Namespace declaration, including default namespace")]
LookupNamespace7()794         public int LookupNamespace7()
795         {
796             ReloadSource();
797             DataReader.PositionOnElement("NAMESPACE3");
798 
799             string strDef = "1";
800             string strA = null;
801             string strB = null;
802             string strC = null;
803             string strD = null;
804             string strE = null;
805             string strF = null;
806             string strG = null;
807             string strH = null;
808             while (true == DataReader.Read())
809             {
810                 CError.WriteLine("N=" + DataReader.Name + " NS=" + DataReader.NamespaceURI + " V=" + DataReader.Value + " NodeType=" + (DataReader.NodeType).ToString());
811                 if (DataReader.Name == "a")
812                 {
813                     strA = "2";
814                     strB = "3";
815                     strC = "4";
816                     CompareAllNS(strDef, strA, strB, strC, strD, strE, strF, strG, strH);
817                     if (DataReader.NodeType == XmlNodeType.EndElement)
818                     {
819                         strA = null;
820                         strB = null;
821                         strC = null;
822                     }
823                 }
824                 else if (DataReader.Name == "b")
825                 {
826                     strD = "5";
827                     strE = "6";
828                     strF = "7";
829                     CompareAllNS(strDef, strA, strB, strC, strD, strE, strF, strG, strH);
830                     if (DataReader.NodeType == XmlNodeType.EndElement)
831                     {
832                         strD = null;
833                         strE = null;
834                         strF = null;
835                     }
836                 }
837                 else if (DataReader.Name == "c")
838                 {
839                     strD = "8";
840                     strE = "9";
841                     strF = "10";
842                     CompareAllNS(strDef, strA, strB, strC, strD, strE, strF, strG, strH);
843                     if (DataReader.NodeType == XmlNodeType.EndElement)
844                     {
845                         strD = "5";
846                         strE = "6";
847                         strF = "7";
848                     }
849                 }
850                 else if (DataReader.Name == "d")
851                 {
852                     strG = "11";
853                     strH = "12";
854                     CompareAllNS(strDef, strA, strB, strC, strD, strE, strF, strG, strH);
855                     if (DataReader.NodeType == XmlNodeType.EndElement)
856                     {
857                         strG = null;
858                         strH = null;
859                     }
860                 }
861                 else if (DataReader.Name == "testns")
862                 {
863                     strDef = "100";
864                     CompareAllNS(strDef, strA, strB, strC, strD, strE, strF, strG, strH);
865                     if (DataReader.NodeType == XmlNodeType.EndElement)
866                     {
867                         strDef = "1";
868                     }
869                 }
870                 else if (DataReader.Name == "a13")
871                 {
872                     strA = "13";
873                     CompareAllNS(strDef, strA, strB, strC, strD, strE, strF, strG, strH);
874                     do
875                     {
876                         CError.WriteLine("Name=" + DataReader.Name + " Value=" + DataReader.Value + " NodeType=" + (DataReader.NodeType).ToString());
877                         CompareAllNS(strDef, strA, strB, strC, strD, strE, strF, strG, strH);
878                     } while (DataReader.MoveToNextAttribute() == true);
879                     strA = null;
880                 }
881                 else if (DataReader.Name == "check14")
882                 {
883                     strDef = "14";
884                     CError.WriteLine(strA + " XXX N=" + DataReader.Name + " NS=" + DataReader.NamespaceURI + " V=" + DataReader.Value + " NodeType=" + (DataReader.NodeType).ToString());
885                     CompareAllNS(strDef, strA, strB, strC, strD, strE, strF, strG, strH);
886                     if (DataReader.NodeType == XmlNodeType.EndElement)
887                     {
888                         strDef = "1";
889                     }
890                 }
891                 else
892                     CompareAllNS(strDef, strA, strB, strC, strD, strE, strF, strG, strH);
893 
894                 if (DataReader.Name == "NAMESPACE3" && DataReader.NodeType == XmlNodeType.EndElement)
895                 {
896                     CompareAllNS(strDef, strA, strB, strC, strD, strE, strF, strG, strH);
897                     DataReader.Read();
898                     break;
899                 }
900             }
901             return TEST_PASS;
902         }
903 
904         [Variation("LookupNamespace on whitespace node PreserveWhitespaces = true", Pri = 0)]
LookupNamespace8()905         public int LookupNamespace8()
906         {
907             if (IsXPathNavigatorReader())
908                 return TEST_SKIPPED;
909             string strxml = "<ROOT xmlns:p='1'>\n<E1/></ROOT>";
910             ReloadSource(new StringReader(strxml));
911             PositionOnNodeType(XmlNodeType.Whitespace);
912 
913             string ns = DataReader.LookupNamespace("p");
914             CError.Compare(ns, "1", "ln");
915 
916             return TEST_PASS;
917         }
918 
919         [Variation("Different prefix on inner element for the same namespace", Pri = 0)]
LookupNamespace9()920         public int LookupNamespace9()
921         {
922             string ns = "http://www.w3.org/1999/XMLSchema";
923             string filename = Path.Combine(TestData, "Common", "bug_57723.xml");
924 
925             ReloadSource(filename);
926 
927             DataReader.PositionOnElement("element");
928             CError.Compare(DataReader.LookupNamespace("q1"), ns, "q11");
929             CError.Compare(DataReader.LookupNamespace("q2"), null, "q21");
930 
931             DataReader.Read();
932             DataReader.PositionOnElement("element");
933             CError.Compare(DataReader.LookupNamespace("q1"), ns, "q12");
934             CError.Compare(DataReader.LookupNamespace("q2"), ns, "q22");
935 
936             return TEST_PASS;
937         }
938 
939         [Variation("LookupNamespace when Namespaces = false", Pri = 0)]
LookupNamespace10()940         public int LookupNamespace10()
941         {
942             if (!(IsXmlTextReader() || IsXmlValidatingReader()))
943             {
944                 return TEST_SKIPPED;
945             }
946 
947             string strxml = "<ROOT xmlns:p='1'>\n<E1/></ROOT>";
948             ReloadSourceStr(strxml);
949             DataReader.PositionOnElement("ROOT");
950             CError.Compare(DataReader.LookupNamespace("p"), null, "ln ROOT");
951             DataReader.PositionOnElement("E1");
952             CError.Compare(DataReader.LookupNamespace("p"), null, "ln E1");
953             DataReader.Read();
954             CError.Compare(DataReader.LookupNamespace("p"), null, "ln /ROOT");
955 
956             return TEST_PASS;
957         }
958     }
959 
960     ////////////////////////////////////////////////////////////////
961     // TestCase TCXML HasValue
962     //
963     ////////////////////////////////////////////////////////////////
964     [InheritRequired()]
965     public abstract partial class TCHasValue : TCXMLReaderBaseGeneral
966     {
967         [Variation("HasValue On None")]
TestHasValueNodeType_None()968         public int TestHasValueNodeType_None()
969         {
970             ReloadSource();
971             if (FindNodeType(XmlNodeType.None) == TEST_PASS)
972             {
973                 bool b = DataReader.HasValue;
974                 if (!b)
975                     return TEST_PASS;
976                 else
977                     throw new CTestException(CTestBase.TEST_FAIL, "HasValue returns True");
978             }
979             return TEST_FAIL;
980         }
981 
982         [Variation("HasValue On Element", Pri = 0)]
TestHasValueNodeType_Element()983         public int TestHasValueNodeType_Element()
984         {
985             ReloadSource();
986             while (FindNodeType(XmlNodeType.Element) == TEST_PASS)
987             {
988                 CError.WriteLine("Name=" + DataReader.Name + " Value=" + DataReader.Value);
989                 bool b = DataReader.HasValue;
990                 if (!b)
991                     return TEST_PASS;
992                 else
993                     throw new CTestException(CTestBase.TEST_FAIL, "HasValue returns True");
994             }
995             return TEST_FAIL;
996         }
997 
998         [Variation("Get node with a scalar value, verify the value with valid ReadString")]
TestHasValue1()999         public int TestHasValue1()
1000         {
1001             ReloadSource();
1002             DataReader.PositionOnElement("NONEMPTY1");
1003 
1004             DataReader.Read();
1005             CError.Compare(DataReader.HasValue, true, "HasValue test");
1006             return TEST_PASS;
1007         }
1008 
1009         [Variation("HasValue On Attribute", Pri = 0)]
TestHasValueNodeType_Attribute()1010         public int TestHasValueNodeType_Attribute()
1011         {
1012             ReloadSource();
1013             while (FindNodeType(XmlNodeType.Attribute) == TEST_PASS)
1014             {
1015                 CError.WriteLine("Name=" + DataReader.Name + " Value=" + DataReader.Value);
1016                 bool b = DataReader.HasValue;
1017                 if (b)
1018                     return TEST_PASS;
1019                 else
1020                     throw new CTestException(CTestBase.TEST_FAIL, "HasValue for Attribute returns false");
1021             }
1022             return TEST_FAIL;
1023         }
1024 
1025         [Variation("HasValue On Text", Pri = 0)]
TestHasValueNodeType_Text()1026         public int TestHasValueNodeType_Text()
1027         {
1028             ReloadSource();
1029             while (FindNodeType(XmlNodeType.Text) == TEST_PASS)
1030             {
1031                 CError.WriteLine("Name=" + DataReader.Name + " Value=" + DataReader.Value);
1032                 bool b = DataReader.HasValue;
1033                 if (b)
1034                     return TEST_PASS;
1035                 else
1036                     throw new CTestException(CTestBase.TEST_FAIL, "HasValue for Text returns false");
1037             }
1038             return TEST_FAIL;
1039         }
1040 
1041         [Variation("HasValue On CDATA", Pri = 0)]
TestHasValueNodeType_CDATA()1042         public int TestHasValueNodeType_CDATA()
1043         {
1044             ReloadSource();
1045 
1046             // No CDATA for Xslt
1047             if (IsXsltReader() || IsXPathNavigatorReader())
1048             {
1049                 while (FindNodeType(XmlNodeType.CDATA) == TEST_PASS)
1050                     return TEST_FAIL;
1051                 return TEST_PASS;
1052             }
1053 
1054             while (FindNodeType(XmlNodeType.CDATA) == TEST_PASS)
1055             {
1056                 CError.WriteLine("Name=" + DataReader.Name + " Value=" + DataReader.Value);
1057                 bool b = DataReader.HasValue;
1058                 if (b)
1059                     return TEST_PASS;
1060                 else
1061                     throw new CTestException(CTestBase.TEST_FAIL, "HasValue for CDATA returns false");
1062             }
1063             return TEST_FAIL;
1064         }
1065 
1066         [Variation("HasValue On ProcessingInstruction", Pri = 0)]
TestHasValueNodeType_ProcessingInstruction()1067         public int TestHasValueNodeType_ProcessingInstruction()
1068         {
1069             ReloadSource();
1070             while (FindNodeType(XmlNodeType.ProcessingInstruction) == TEST_PASS)
1071             {
1072                 CError.WriteLine("Name=" + DataReader.Name + " Value=" + DataReader.Value);
1073                 bool b = DataReader.HasValue;
1074                 if (b)
1075                     return TEST_PASS;
1076                 else
1077                     throw new CTestException(CTestBase.TEST_FAIL, "HasValue for PI returns false");
1078             }
1079             return TEST_FAIL;
1080         }
1081 
1082         [Variation("HasValue On Comment", Pri = 0)]
TestHasValueNodeType_Comment()1083         public int TestHasValueNodeType_Comment()
1084         {
1085             ReloadSource();
1086             while (FindNodeType(XmlNodeType.Comment) == TEST_PASS)
1087             {
1088                 CError.WriteLine("Name=" + DataReader.Name + " Value=" + DataReader.Value);
1089                 bool b = DataReader.HasValue;
1090                 if (b)
1091                     return TEST_PASS;
1092                 else
1093                     throw new CTestException(CTestBase.TEST_FAIL, "HasValue for Comment returns false");
1094             }
1095             return TEST_FAIL;
1096         }
1097 
1098         [Variation("HasValue On Whitespace PreserveWhitespaces = true", Pri = 0)]
TestHasValueNodeType_Whitespace()1099         public int TestHasValueNodeType_Whitespace()
1100         {
1101             if (IsXPathNavigatorReader())
1102                 return TEST_SKIPPED;
1103             ReloadSource();
1104             while (FindNodeType(XmlNodeType.Whitespace) == TEST_PASS)
1105             {
1106                 bool b = DataReader.HasValue;
1107                 if (b)
1108                     return TEST_PASS;
1109                 else
1110                     throw new CTestException(CTestBase.TEST_FAIL, "HasValue returns False");
1111             }
1112             return TEST_FAIL;
1113         }
1114 
1115         [Variation("HasValue On EndElement")]
TestHasValueNodeType_EndElement()1116         public int TestHasValueNodeType_EndElement()
1117         {
1118             ReloadSource();
1119             while (FindNodeType(XmlNodeType.EndElement) == TEST_PASS)
1120             {
1121                 bool b = DataReader.HasValue;
1122                 if (!b)
1123                     return TEST_PASS;
1124                 else
1125                     throw new CTestException(CTestBase.TEST_FAIL, "HasValue returns True");
1126             }
1127             return TEST_FAIL;
1128         }
1129 
1130         [Variation("HasValue On XmlDeclaration", Pri = 0)]
TestHasValueNodeType_XmlDeclaration()1131         public int TestHasValueNodeType_XmlDeclaration()
1132         {
1133             if (IsXsltReader() || IsXPathNavigatorReader() || IsSubtreeReader())
1134                 return TEST_SKIPPED;
1135 
1136             ReloadSource();
1137             if (FindNodeType(XmlNodeType.XmlDeclaration) == TEST_PASS)
1138             {
1139                 bool b = DataReader.HasValue;
1140                 if (b)
1141                     return TEST_PASS;
1142                 else
1143                     throw new CTestException(CTestBase.TEST_FAIL, "HasValue returns False");
1144             }
1145             return TEST_FAIL;
1146         }
1147 
1148         [Variation("HasValue On EntityReference")]
TestHasValueNodeType_EntityReference()1149         public int TestHasValueNodeType_EntityReference()
1150         {
1151             if (!IsXmlTextReader())
1152                 return TEST_SKIPPED;
1153 
1154             ReloadSource();
1155             if (FindNodeType(XmlNodeType.EntityReference) == TEST_PASS)
1156             {
1157                 bool b = DataReader.HasValue;
1158                 if (!b)
1159                     return TEST_PASS;
1160                 else
1161                     throw new CTestException(CTestBase.TEST_FAIL, "HasValue returns True");
1162             }
1163             return TEST_FAIL;
1164         }
1165 
1166         [Variation("HasValue On EndEntity")]
TestHasValueNodeType_EndEntity()1167         public int TestHasValueNodeType_EndEntity()
1168         {
1169             if (!IsXmlTextReader())
1170                 return TEST_SKIPPED;
1171 
1172             ReloadSource();
1173             while (FindNodeType(XmlNodeType.EndEntity) == TEST_PASS)
1174             {
1175                 bool b = DataReader.HasValue;
1176                 if (!b)
1177                     return TEST_PASS;
1178                 else
1179                     throw new CTestException(CTestBase.TEST_FAIL, "HasValue returns True");
1180             }
1181             return TEST_FAIL;
1182         }
1183 
1184         [Variation("PI Value containing surrogates", Pri = 0)]
v13()1185         public int v13()
1186         {
1187             if (IsBinaryReader())
1188                 return TEST_SKIPPED;
1189 
1190             string strxml = "<root><?target \uD800\uDC00\uDBFF\uDFFF?></root>"; //Fail
1191             ReloadSourceStr(strxml);
1192 
1193             DataReader.Read();
1194             DataReader.Read();
1195             CError.Compare(DataReader.NodeType, XmlNodeType.ProcessingInstruction, "nt");
1196             CError.Compare(DataReader.Value, "\uD800\uDC00\uDBFF\uDFFF", "piv");
1197 
1198             return TEST_PASS;
1199         }
1200     }
1201 
1202     ////////////////////////////////////////////////////////////////
1203     // TestCase TCXML IsEmptyElement
1204     //
1205     ////////////////////////////////////////////////////////////////
1206     [InheritRequired()]
1207     public abstract partial class TCIsEmptyElement : TCXMLReaderBaseGeneral
1208     {
1209         [Variation("Set and Get an element that ends with />", Pri = 0)]
TestEmpty1()1210         public int TestEmpty1()
1211         {
1212             ReloadSource();
1213             DataReader.PositionOnElement("EMPTY1");
1214 
1215             bool b = DataReader.IsEmptyElement;
1216             if (b)
1217                 return TEST_PASS;
1218             else
1219                 throw new CTestException(CTestBase.TEST_FAIL, "DataReader is NOT_EMPTY, supposed to be EMPTY");
1220         }
1221 
1222         [Variation("Set and Get an element with an attribute that ends with />", Pri = 0)]
TestEmpty2()1223         public int TestEmpty2()
1224         {
1225             ReloadSource();
1226             DataReader.PositionOnElement("EMPTY2");
1227 
1228             bool b = DataReader.IsEmptyElement;
1229             if (b)
1230                 return TEST_PASS;
1231             else
1232                 throw new CTestException(CTestBase.TEST_FAIL, "DataReader is NOT_EMPTY, supposed to be EMPTY");
1233         }
1234 
1235         [Variation("Set and Get an element that ends without />", Pri = 0)]
TestEmpty3()1236         public int TestEmpty3()
1237         {
1238             ReloadSource();
1239             DataReader.PositionOnElement("NONEMPTY1");
1240 
1241             bool b = DataReader.IsEmptyElement;
1242             if (!b)
1243                 return TEST_PASS;
1244             else
1245                 return TEST_FAIL;
1246         }
1247 
1248         [Variation("Set and Get an element with an attribute that ends with />", Pri = 0)]
TestEmpty4()1249         public int TestEmpty4()
1250         {
1251             ReloadSource();
1252             DataReader.PositionOnElement("NONEMPTY2");
1253             bool b = DataReader.IsEmptyElement;
1254             if (!b)
1255                 return TEST_PASS;
1256             else
1257                 throw new CTestException(CTestBase.TEST_FAIL, "DataReader is EMPTY, supposed to be NOT_EMPTY");
1258         }
1259 
1260         [Variation("IsEmptyElement On Element", Pri = 0)]
TestEmptyNodeType_Element()1261         public int TestEmptyNodeType_Element()
1262         {
1263             ReloadSource();
1264             while (FindNodeType(XmlNodeType.Element) == TEST_PASS)
1265             {
1266                 CError.WriteLine("Name=" + DataReader.Name + " Value=" + DataReader.Value);
1267                 bool b = DataReader.IsEmptyElement;
1268                 if (!b)
1269                     return TEST_PASS;
1270                 else
1271                     throw new CTestException(CTestBase.TEST_FAIL, "IsEmptyElement returns True");
1272             }
1273             return TEST_FAIL;
1274         }
1275 
1276         [Variation("IsEmptyElement On None")]
TestEmptyNodeType_None()1277         public int TestEmptyNodeType_None()
1278         {
1279             ReloadSource();
1280             while (FindNodeType(XmlNodeType.None) == TEST_PASS)
1281             {
1282                 bool b = DataReader.IsEmptyElement;
1283                 if (!b)
1284                     return TEST_PASS;
1285                 else
1286                     throw new CTestException(CTestBase.TEST_FAIL, "IsEmptyElement returns True");
1287             }
1288             return TEST_FAIL;
1289         }
1290 
1291         [Variation("IsEmptyElement On Text")]
TestEmptyNodeType_Text()1292         public int TestEmptyNodeType_Text()
1293         {
1294             ReloadSource();
1295             while (FindNodeType(XmlNodeType.Text) == TEST_PASS)
1296             {
1297                 CError.WriteLine("Name=" + DataReader.Name + " Value=" + DataReader.Value);
1298                 bool b = DataReader.IsEmptyElement;
1299                 if (!b)
1300                     return TEST_PASS;
1301                 else
1302                     throw new CTestException(CTestBase.TEST_FAIL, "IsEmptyElement returns True");
1303             }
1304             return TEST_FAIL;
1305         }
1306 
1307         [Variation("IsEmptyElement On CDATA")]
TestEmptyNodeType_CDATA()1308         public int TestEmptyNodeType_CDATA()
1309         {
1310             ReloadSource();
1311 
1312             // No CDATA for Xslt
1313             if (IsXsltReader() || IsXPathNavigatorReader())
1314             {
1315                 while (FindNodeType(XmlNodeType.CDATA) == TEST_PASS)
1316                     return TEST_FAIL;
1317                 return TEST_PASS;
1318             }
1319 
1320             while (FindNodeType(XmlNodeType.CDATA) == TEST_PASS)
1321             {
1322                 CError.WriteLine("Name=" + DataReader.Name + " Value=" + DataReader.Value);
1323                 bool b = DataReader.IsEmptyElement;
1324                 if (!b)
1325                     return TEST_PASS;
1326                 else
1327                     throw new CTestException(CTestBase.TEST_FAIL, "IsEmptyElement returns True");
1328             }
1329             return TEST_FAIL;
1330         }
1331 
1332         [Variation("IsEmptyElement On ProcessingInstruction")]
TestEmptyNodeType_ProcessingInstruction()1333         public int TestEmptyNodeType_ProcessingInstruction()
1334         {
1335             ReloadSource();
1336             while (FindNodeType(XmlNodeType.ProcessingInstruction) == TEST_PASS)
1337             {
1338                 CError.WriteLine("Name=" + DataReader.Name + " Value=" + DataReader.Value);
1339                 bool b = DataReader.IsEmptyElement;
1340                 if (!b)
1341                     return TEST_PASS;
1342                 else
1343                     throw new CTestException(CTestBase.TEST_FAIL, "IsEmptyElement returns True");
1344             }
1345             return TEST_FAIL;
1346         }
1347 
1348         [Variation("IsEmptyElement On Comment")]
TestEmptyNodeType_Comment()1349         public int TestEmptyNodeType_Comment()
1350         {
1351             ReloadSource();
1352             while (FindNodeType(XmlNodeType.Comment) == TEST_PASS)
1353             {
1354                 CError.WriteLine("Name=" + DataReader.Name + " Value=" + DataReader.Value);
1355                 bool b = DataReader.IsEmptyElement;
1356                 if (!b)
1357                     return TEST_PASS;
1358                 else
1359                     throw new CTestException(CTestBase.TEST_FAIL, "IsEmptyElement returns True");
1360             }
1361             return TEST_FAIL;
1362         }
1363 
1364         [Variation("IsEmptyElement On DocumentType")]
TestEmptyNodeType_DocumentType()1365         public int TestEmptyNodeType_DocumentType()
1366         {
1367             if (IsXsltReader() || IsXPathNavigatorReader() || IsSubtreeReader())
1368                 return TEST_SKIPPED;
1369 
1370             ReloadSource();
1371             if (FindNodeType(XmlNodeType.DocumentType) == TEST_PASS)
1372             {
1373                 bool b = DataReader.IsEmptyElement;
1374                 if (!b)
1375                     return TEST_PASS;
1376                 else
1377                     throw new CTestException(CTestBase.TEST_FAIL, "IsEmptyElement returns True");
1378             }
1379             return TEST_FAIL;
1380         }
1381 
1382         [Variation("IsEmptyElement On Whitespace PreserveWhitespaces = true")]
TestEmptyNodeType_Whitespace()1383         public int TestEmptyNodeType_Whitespace()
1384         {
1385             if (IsXPathNavigatorReader())
1386                 return TEST_SKIPPED;
1387             ReloadSource();
1388             while (FindNodeType(XmlNodeType.Whitespace) == TEST_PASS)
1389             {
1390                 bool b = DataReader.IsEmptyElement;
1391                 if (!b)
1392                     return TEST_PASS;
1393                 else
1394                     throw new CTestException(CTestBase.TEST_FAIL, "IsEmptyElement returns True");
1395             }
1396             return TEST_FAIL;
1397         }
1398 
1399         [Variation("IsEmptyElement On EndElement")]
TestEmptyNodeType_EndElement()1400         public int TestEmptyNodeType_EndElement()
1401         {
1402             ReloadSource();
1403             while (FindNodeType(XmlNodeType.EndElement) == TEST_PASS)
1404             {
1405                 bool b = DataReader.IsEmptyElement;
1406                 if (!b)
1407                     return TEST_PASS;
1408                 else
1409                     throw new CTestException(CTestBase.TEST_FAIL, "IsEmptyElement returns True");
1410             }
1411             return TEST_FAIL;
1412         }
1413 
1414         [Variation("IsEmptyElement On XmlDeclaration")]
TestEmptyNodeType_XmlDeclaration()1415         public int TestEmptyNodeType_XmlDeclaration()
1416         {
1417             if (IsXsltReader() || IsXPathNavigatorReader() || IsSubtreeReader())
1418                 return TEST_SKIPPED;
1419 
1420             ReloadSource();
1421             if (FindNodeType(XmlNodeType.XmlDeclaration) == TEST_PASS)
1422             {
1423                 bool b = DataReader.IsEmptyElement;
1424                 if (!b)
1425                     return TEST_PASS;
1426                 else
1427                     throw new CTestException(CTestBase.TEST_FAIL, "IsEmptyElement returns True");
1428             }
1429             return TEST_FAIL;
1430         }
1431 
1432         [Variation("IsEmptyElement On EntityReference")]
TestEmptyNodeType_EntityReference()1433         public int TestEmptyNodeType_EntityReference()
1434         {
1435             if (!IsXmlTextReader())
1436                 return TEST_SKIPPED;
1437 
1438             ReloadSource();
1439             while (FindNodeType(XmlNodeType.EntityReference) == TEST_PASS)
1440             {
1441                 bool b = DataReader.IsEmptyElement;
1442                 if (!b)
1443                     return TEST_PASS;
1444                 else
1445                     throw new CTestException(CTestBase.TEST_FAIL, "IsEmptyElement returns True");
1446             }
1447             throw new CTestException(CTestBase.TEST_FAIL, "Entity Reference XMLNodeType Not Found");
1448         }
1449 
1450         [Variation("IsEmptyElement On EndEntity")]
TestEmptyNodeType_EndEntity()1451         public int TestEmptyNodeType_EndEntity()
1452         {
1453             if (!IsXmlTextReader())
1454                 return TEST_SKIPPED;
1455 
1456             ReloadSource();
1457             while (FindNodeType(XmlNodeType.EndEntity) == TEST_PASS)
1458             {
1459                 bool b = DataReader.IsEmptyElement;
1460                 if (!b)
1461                     return TEST_PASS;
1462                 else
1463                     throw new CTestException(CTestBase.TEST_FAIL, "IsEmptyElement returns True");
1464             }
1465             return TEST_FAIL;
1466         }
1467     }
1468 
1469     ////////////////////////////////////////////////////////////////
1470     // TestCase TCXML XmlSpace
1471     //
1472     ////////////////////////////////////////////////////////////////
1473     [InheritRequired()]
1474     public abstract partial class TCXmlSpace : TCXMLReaderBaseGeneral
1475     {
1476         [Variation("XmlSpace test within EmptyTag")]
TestXmlSpace1()1477         public int TestXmlSpace1()
1478         {
1479             ReloadSource();
1480             DataReader.PositionOnElement("EMPTY_XMLSPACE");
1481 
1482             do
1483             {
1484                 CError.WriteLine("N=" + DataReader.Name + " V=" + DataReader.Value + " NodeType=" + (DataReader.NodeType).ToString());
1485                 CError.Compare(DataReader.XmlSpace, XmlSpace.Default, "Compare XmlSpace with Default");
1486             } while (DataReader.MoveToNextAttribute() == true);
1487             return TEST_PASS;
1488         }
1489 
1490         [Variation("Xmlspace test within a scope (no nested element)", Pri = 0)]
TestXmlSpace2()1491         public int TestXmlSpace2()
1492         {
1493             ReloadSource();
1494             int i = 0;
1495             while (true == DataReader.Read())
1496             {
1497                 if (DataReader.Name == "XMLSPACE1") break;
1498                 CError.Compare(DataReader.XmlSpace, XmlSpace.None, "Compare XmlSpace with None");
1499             }
1500 
1501             while (true == DataReader.Read())
1502             {
1503                 if (DataReader.Name == "XMLSPACE1" && (DataReader.NodeType == XmlNodeType.EndElement)) break;
1504                 CError.WriteLine("Name=" + DataReader.Name + " Value=" + DataReader.Value + " NodeType=" + (DataReader.NodeType).ToString() + " Loop " + i); i++;
1505                 CError.Compare(DataReader.XmlSpace, XmlSpace.Default, "Compare XmlSpace with Default");
1506             }
1507 
1508             return TEST_PASS;
1509         }
1510 
1511         [Variation("Xmlspace test within a scope (with nested element)", Pri = 0)]
TestXmlSpace3()1512         public int TestXmlSpace3()
1513         {
1514             ReloadSource();
1515             DataReader.PositionOnElement("XMLSPACE2");
1516             while (true == DataReader.Read())
1517             {
1518                 if (DataReader.Name == "NOSPACE") break;
1519                 CError.WriteLine("Name=" + DataReader.Name + " Value=" + DataReader.Value + " NodeType=" + (DataReader.NodeType).ToString());
1520                 CError.Compare(DataReader.XmlSpace, XmlSpace.Preserve, "Compare XmlSpace with Preserve");
1521             }
1522             CError.Compare(DataReader.XmlSpace, XmlSpace.None, "Compare XmlSpace outside scope");
1523 
1524             return TEST_PASS;
1525         }
1526 
1527         [Variation("Xmlspace test immediately outside the XmlSpace scope")]
TestXmlSpace4()1528         public int TestXmlSpace4()
1529         {
1530             ReloadSource();
1531             DataReader.PositionOnElement("NOSPACE");
1532             CError.Compare(DataReader.XmlSpace, XmlSpace.None, "Compare XmlSpace with None");
1533 
1534             return TEST_PASS;
1535         }
1536 
1537         [Variation("XmlSpace test with multiple XmlSpace declaration")]
TestXmlSpace5()1538         public int TestXmlSpace5()
1539         {
1540             ReloadSource();
1541             DataReader.PositionOnElement("XMLSPACE2A");
1542 
1543             while (true == DataReader.Read())
1544             {
1545                 if (DataReader.Name == "XMLSPACE3") break;
1546                 CError.WriteLine("Name=" + DataReader.Name + " Value=" + DataReader.Value + " NodeType=" + (DataReader.NodeType).ToString());
1547                 CError.Compare(DataReader.XmlSpace, XmlSpace.Default, "Compare XmlSpace with Default");
1548             }
1549 
1550             while (true == DataReader.Read())
1551             {
1552                 if (DataReader.Name == "XMLSPACE4")
1553                 {
1554                     while (true == DataReader.Read())
1555                     {
1556                         CError.WriteLine("Name=" + DataReader.Name + " Value=" + DataReader.Value + " NodeType=" + (DataReader.NodeType).ToString());
1557                         CError.Compare(DataReader.XmlSpace, XmlSpace.Default, "Compare XmlSpace with Default");
1558                         if (DataReader.Name == "XMLSPACE4" && DataReader.NodeType == XmlNodeType.EndElement)
1559                         {
1560                             DataReader.Read();
1561                             break;
1562                         }
1563                     }
1564                 }
1565 
1566                 CError.WriteLine("Name=" + DataReader.Name + " Value=" + DataReader.Value + " NodeType=" + (DataReader.NodeType).ToString());
1567                 CError.Compare(DataReader.XmlSpace, XmlSpace.Preserve, "Compare XmlSpace with Preserve");
1568 
1569                 if (DataReader.Name == "XMLSPACE3" && DataReader.NodeType == XmlNodeType.EndElement)
1570                 {
1571                     DataReader.Read();
1572                     break;
1573                 }
1574             }
1575 
1576             do
1577             {
1578                 CError.WriteLine("Name=" + DataReader.Name + " Value=" + DataReader.Value + " NodeType=" + (DataReader.NodeType).ToString());
1579                 CError.Compare(DataReader.XmlSpace, XmlSpace.Default, "Compare XmlSpace with Default");
1580                 if (DataReader.Name == "XMLSPACE2A" && DataReader.NodeType == XmlNodeType.EndElement)
1581                 {
1582                     DataReader.Read();
1583                     break;
1584                 }
1585             } while (true == DataReader.Read());
1586 
1587             CError.Compare(DataReader.XmlSpace, XmlSpace.None, "Compare XmlSpace outside scope");
1588 
1589             return TEST_PASS;
1590         }
1591     }
1592 
1593     ////////////////////////////////////////////////////////////////
1594     // TestCase TCXML XmlLang
1595     //
1596     ////////////////////////////////////////////////////////////////
1597     [InheritRequired()]
1598     public abstract partial class TCXmlLang : TCXMLReaderBaseGeneral
1599     {
1600         [Variation("XmlLang test within EmptyTag")]
TestXmlLang1()1601         public int TestXmlLang1()
1602         {
1603             ReloadSource();
1604             DataReader.PositionOnElement("EMPTY_XMLLANG");
1605             do
1606             {
1607                 CError.WriteLine("N=" + DataReader.Name + " V=" + DataReader.Value + " NodeType=" + (DataReader.NodeType).ToString());
1608                 CError.Compare(DataReader.XmlLang, "en-US", "Compare XmlLang with en-US");
1609             } while (DataReader.MoveToNextAttribute() == true);
1610             return TEST_PASS;
1611         }
1612 
1613         [Variation("XmlLang test within a scope (no nested element)", Pri = 0)]
TestXmlLang2()1614         public int TestXmlLang2()
1615         {
1616             ReloadSource();
1617             int i = 0;
1618             while (true == DataReader.Read())
1619             {
1620                 if (DataReader.Name == "XMLLANG0") break;
1621                 CError.Compare(DataReader.XmlLang, String.Empty, "Compare XmlLang with String.Empty");
1622             }
1623 
1624             while (true == DataReader.Read())
1625             {
1626                 if (DataReader.Name == "XMLLANG0" && (DataReader.NodeType == XmlNodeType.EndElement)) break;
1627 
1628                 CError.WriteLine("Name=" + DataReader.Name + " Value=" + DataReader.Value + " NodeType=" + (DataReader.NodeType).ToString() + " Loop " + i); i++;
1629 
1630                 if (DataReader.NodeType == XmlNodeType.EntityReference)
1631                 {
1632                     CError.Compare(DataReader.XmlLang, "en-US", "Compare XmlLang with EntityRef");
1633 
1634                     if (DataReader.CanResolveEntity)
1635                     {
1636                         DataReader.ResolveEntity();
1637                         CError.Compare(DataReader.XmlLang, "en-US", "Compare XmlLang after ResolveEntity");
1638                         while (DataReader.Read() && DataReader.NodeType != XmlNodeType.EndEntity)
1639                         {
1640                             CError.Compare(DataReader.XmlLang, "en-US", "Compare XmlLang While Read ");
1641                         }
1642                         if (DataReader.NodeType == XmlNodeType.EndEntity)
1643                         {
1644                             CError.Compare(DataReader.XmlLang, "en-US", "Compare XmlLang at EndEntity ");
1645                         }
1646                     }
1647                 }
1648                 else
1649                     CError.Compare(DataReader.XmlLang, "en-US", "Compare XmlLang with Preserve");
1650             }
1651             return TEST_PASS;
1652         }
1653 
1654         [Variation("XmlLang test within a scope (with nested element)", Pri = 0)]
TestXmlLang3()1655         public int TestXmlLang3()
1656         {
1657             ReloadSource();
1658             DataReader.PositionOnElement("XMLLANG1");
1659 
1660             while (true == DataReader.Read())
1661             {
1662                 if (DataReader.Name == "NOXMLLANG") break;
1663                 CError.WriteLine("Name=" + DataReader.Name + " Value=" + DataReader.Value + " NodeType=" + (DataReader.NodeType).ToString());
1664                 CError.Compare(DataReader.XmlLang, "en-GB", "Compare XmlLang with en-GB");
1665             }
1666 
1667             return TEST_PASS;
1668         }
1669 
1670         [Variation("XmlLang test immediately outside the XmlLang scope")]
TestXmlLang4()1671         public int TestXmlLang4()
1672         {
1673             ReloadSource();
1674             DataReader.PositionOnElement("NOXMLLANG");
1675             CError.Compare(DataReader.XmlLang, String.Empty, "Compare XmlLang with EmptyString");
1676 
1677             return TEST_PASS;
1678         }
1679 
1680         [Variation("XmlLang test with multiple XmlLang declaration")]
TestXmlLang5()1681         public int TestXmlLang5()
1682         {
1683             ReloadSource();
1684             DataReader.PositionOnElement("XMLLANG2");
1685             while (true == DataReader.Read())
1686             {
1687                 if (DataReader.Name == "XMLLANG1") break;
1688                 CError.WriteLine("Name=" + DataReader.Name + " Value=" + DataReader.Value + " NodeType=" + (DataReader.NodeType).ToString());
1689                 CError.Compare(DataReader.XmlLang, "en-US", "Compare XmlLang with Preserve");
1690             }
1691 
1692             while (true == DataReader.Read())
1693             {
1694                 if (DataReader.Name == "XMLLANG0")
1695                 {
1696                     while (true == DataReader.Read())
1697                     {
1698                         CError.WriteLine("Name=" + DataReader.Name + " Value=" + DataReader.Value + " NodeType=" + (DataReader.NodeType).ToString());
1699                         CError.Compare(DataReader.XmlLang, "en-US", "Compare XmlLang with en-US");
1700                         if (DataReader.Name == "XMLLANG0" && DataReader.NodeType == XmlNodeType.EndElement)
1701                         {
1702                             DataReader.Read();
1703                             break;
1704                         }
1705                     }
1706                 }
1707 
1708                 CError.WriteLine("Name=" + DataReader.Name + " Value=" + DataReader.Value + " NodeType=" + (DataReader.NodeType).ToString());
1709                 CError.Compare(DataReader.XmlLang, "en-GB", "Compare XmlLang with en_GB");
1710 
1711                 if (DataReader.Name == "XMLLANG1" && DataReader.NodeType == XmlNodeType.EndElement)
1712                 {
1713                     DataReader.Read();
1714                     break;
1715                 }
1716             }
1717 
1718             do
1719             {
1720                 CError.WriteLine("Name=" + DataReader.Name + " Value=" + DataReader.Value + " NodeType=" + (DataReader.NodeType).ToString());
1721                 CError.Compare(DataReader.XmlLang, "en-US", "Compare XmlLang with en-US");
1722                 if (DataReader.Name == "XMLLANG2" && DataReader.NodeType == XmlNodeType.EndElement)
1723                 {
1724                     DataReader.Read();
1725                     break;
1726                 }
1727             } while (true == DataReader.Read());
1728 
1729             return TEST_PASS;
1730         }
1731 
1732         // XML 1.0 SE
1733         [Variation("XmlLang valid values", Pri = 0)]
TestXmlLang6()1734         public int TestXmlLang6()
1735         {
1736             const string ST_VALIDXMLLANG = "VALIDXMLLANG";
1737             string[] aValidLang = { "a", "", "ab-cd-", "a b-cd" };
1738 
1739             ReloadSource();
1740 
1741             for (int i = 0; i < aValidLang.Length; i++)
1742             {
1743                 string strelem = ST_VALIDXMLLANG + i;
1744                 DataReader.PositionOnElement(strelem);
1745                 CError.Compare(DataReader.XmlLang, aValidLang[i], "XmlLang");
1746             }
1747 
1748             return TEST_PASS;
1749         }
1750 
1751         // XML 1.0 SE
1752         [Variation("More XmlLang valid values")]
TestXmlTextReaderLang1()1753         public int TestXmlTextReaderLang1()
1754         {
1755             string[] aValidLang = { "", "ab-cd-", "abcdefghi", "ab-cdefghijk", "a b-cd", "ab-c d" };
1756 
1757             for (int i = 0; i < aValidLang.Length; i++)
1758             {
1759                 string strxml = String.Format("<ROOT xml:lang='{0}'/>", aValidLang[i]);
1760 
1761                 ReloadSourceStr(strxml);
1762 
1763                 while (DataReader.Read()) ;
1764             }
1765 
1766             return TEST_PASS;
1767         }
1768     }
1769 
1770     /////////////////////////////////////////////////////////////////////////
1771     // TestCase TCXML Skip
1772     //
1773     /////////////////////////////////////////////////////////////////////////
1774     [InheritRequired()]
1775     public abstract partial class TCSkip : TCXMLReaderBaseGeneral
1776     {
VerifySkipOnNodeType(XmlNodeType testNodeType)1777         public bool VerifySkipOnNodeType(XmlNodeType testNodeType)
1778         {
1779             bool bPassed = false;
1780             XmlNodeType actNodeType;
1781             String strActName;
1782             String strActValue;
1783 
1784             ReloadSource();
1785             PositionOnNodeType(testNodeType);
1786             DataReader.Read();
1787             actNodeType = DataReader.NodeType;
1788             strActName = DataReader.Name;
1789             strActValue = DataReader.Value;
1790 
1791             ReloadSource();
1792             PositionOnNodeType(testNodeType);
1793             DataReader.Skip();
1794             bPassed = DataReader.VerifyNode(actNodeType, strActName, strActValue);
1795 
1796             return bPassed;
1797         }
1798 
1799         ////////////////////////////////////////////////////////////////
1800         // Variations
1801         ////////////////////////////////////////////////////////////////
1802         [Variation("Call Skip on empty element", Pri = 0)]
TestSkip1()1803         public int TestSkip1()
1804         {
1805             bool bPassed = false;
1806 
1807             ReloadSource();
1808             DataReader.PositionOnElement("SKIP1");
1809 
1810             DataReader.Skip();
1811 
1812             bPassed = DataReader.VerifyNode(XmlNodeType.Element, "AFTERSKIP1", String.Empty);
1813 
1814             return BoolToLTMResult(bPassed);
1815         }
1816 
1817         [Variation("Call Skip on element", Pri = 0)]
TestSkip2()1818         public int TestSkip2()
1819         {
1820             bool bPassed = false;
1821 
1822             ReloadSource();
1823             DataReader.PositionOnElement("SKIP2");
1824 
1825             DataReader.Skip();
1826 
1827             bPassed = DataReader.VerifyNode(XmlNodeType.Element, "AFTERSKIP2", String.Empty);
1828 
1829             return BoolToLTMResult(bPassed);
1830         }
1831 
1832         [Variation("Call Skip on element with content", Pri = 0)]
TestSkip3()1833         public int TestSkip3()
1834         {
1835             bool bPassed = false;
1836 
1837             ReloadSource();
1838             DataReader.PositionOnElement("SKIP3");
1839 
1840             DataReader.Skip();
1841 
1842             bPassed = DataReader.VerifyNode(XmlNodeType.Element, "AFTERSKIP3", String.Empty);
1843 
1844             return BoolToLTMResult(bPassed);
1845         }
1846 
1847         [Variation("Call Skip on text node (leave node)", Pri = 0)]
TestSkip4()1848         public int TestSkip4()
1849         {
1850             bool bPassed = false;
1851 
1852             ReloadSource();
1853             DataReader.PositionOnElement("SKIP3");
1854             DataReader.PositionOnElement("ELEM2");
1855             DataReader.Read();
1856             bPassed = (DataReader.NodeType == XmlNodeType.Text);
1857 
1858             DataReader.Skip();
1859 
1860             bPassed = DataReader.VerifyNode(XmlNodeType.EndElement, "ELEM2", String.Empty) && bPassed;
1861 
1862             return BoolToLTMResult(bPassed);
1863         }
1864 
1865         [Variation("Call Skip in while read loop", Pri = 0)]
skip307543()1866         public int skip307543()
1867         {
1868             string fileName = Path.Combine(TestData, "Common", "skip307543.xml");
1869             ReloadSource(fileName);
1870             while (DataReader.Read())
1871                 DataReader.Skip();
1872 
1873             return TEST_PASS;
1874         }
1875 
1876         [Variation("Call Skip on text node with another element: <elem2>text<elem3></elem3></elem2>")]
TestSkip5()1877         public int TestSkip5()
1878         {
1879             bool bPassed = false;
1880 
1881             ReloadSource();
1882             DataReader.PositionOnElement("SKIP4");
1883             DataReader.PositionOnElement("ELEM2");
1884             DataReader.Read();
1885             bPassed = (DataReader.NodeType == XmlNodeType.Text);
1886 
1887             DataReader.Skip();
1888 
1889             bPassed = DataReader.VerifyNode(XmlNodeType.Element, "ELEM3", String.Empty) && bPassed;
1890 
1891             return BoolToLTMResult(bPassed);
1892         }
1893 
1894         [Variation("Call Skip on attribute", Pri = 0)]
TestSkip6()1895         public int TestSkip6()
1896         {
1897             bool bPassed = false;
1898 
1899             ReloadSource();
1900             DataReader.PositionOnElement(ST_ENTTEST_NAME);
1901             bPassed = DataReader.MoveToFirstAttribute();
1902 
1903             DataReader.Skip();
1904 
1905             bPassed = DataReader.VerifyNode(XmlNodeType.Element, "ENTITY2", String.Empty) && bPassed;
1906 
1907             return BoolToLTMResult(bPassed);
1908         }
1909 
1910         [Variation("Call Skip on text node of attribute")]
TestSkip7()1911         public int TestSkip7()
1912         {
1913             bool bPassed = false;
1914 
1915             ReloadSource();
1916 
1917             DataReader.PositionOnElement(ST_ENTTEST_NAME);
1918             bPassed = DataReader.MoveToFirstAttribute();
1919             bPassed = DataReader.ReadAttributeValue() && bPassed;
1920             bPassed = (DataReader.NodeType == XmlNodeType.Text) && bPassed;
1921 
1922             DataReader.Skip();
1923 
1924             bPassed = DataReader.VerifyNode(XmlNodeType.Element, "ENTITY2", String.Empty) && bPassed;
1925 
1926             return BoolToLTMResult(bPassed);
1927         }
1928 
1929         [Variation("Call Skip on CDATA", Pri = 0)]
TestSkip8()1930         public int TestSkip8()
1931         {
1932             ReloadSource();
1933 
1934             // No CDATA for Xslt
1935             if (IsXsltReader() || IsXPathNavigatorReader())
1936             {
1937                 if (FindNodeType(XmlNodeType.CDATA) == TEST_PASS)
1938                     return TEST_FAIL;
1939                 return TEST_PASS;
1940             }
1941 
1942             return BoolToLTMResult(VerifySkipOnNodeType(XmlNodeType.CDATA));
1943         }
1944 
1945         [Variation("Call Skip on Processing Instruction", Pri = 0)]
TestSkip9()1946         public int TestSkip9()
1947         {
1948             return BoolToLTMResult(VerifySkipOnNodeType(XmlNodeType.ProcessingInstruction));
1949         }
1950 
1951         [Variation("Call Skip on Comment", Pri = 0)]
TestSkip10()1952         public int TestSkip10()
1953         {
1954             return BoolToLTMResult(VerifySkipOnNodeType(XmlNodeType.Comment));
1955         }
1956 
1957         [Variation("Call Skip on Document Type")]
TestSkip11()1958         public int TestSkip11()
1959         {
1960             if (IsXsltReader() || IsXPathNavigatorReader() || IsSubtreeReader())
1961                 return TEST_SKIPPED;
1962 
1963             return BoolToLTMResult(VerifySkipOnNodeType(XmlNodeType.DocumentType));
1964         }
1965 
1966         [Variation("Call Skip on Whitespace", Pri = 0)]
TestSkip12()1967         public int TestSkip12()
1968         {
1969             ReloadSource();
1970 
1971             // Do not want to run this test for the Xslt Reader
1972             if (IsXsltReader() || IsXPathNavigatorReader())
1973             {
1974                 if (FindNodeType(XmlNodeType.Whitespace) == TEST_PASS)
1975                     return TEST_FAIL;
1976                 return TEST_PASS;
1977             }
1978 
1979             return BoolToLTMResult(VerifySkipOnNodeType(XmlNodeType.Whitespace));
1980         }
1981 
1982         [Variation("Call Skip on EndElement", Pri = 0)]
TestSkip13()1983         public int TestSkip13()
1984         {
1985             return BoolToLTMResult(VerifySkipOnNodeType(XmlNodeType.EndElement));
1986         }
1987 
1988         [Variation("Call Skip on root Element")]
TestSkip14()1989         public int TestSkip14()
1990         {
1991             bool bPassed;
1992 
1993             ReloadSource();
1994             DataReader.PositionOnNodeType(XmlNodeType.Element);
1995 
1996             DataReader.Skip();
1997 
1998             bPassed = DataReader.VerifyNode(XmlNodeType.None, String.Empty, String.Empty);
1999 
2000             return BoolToLTMResult(bPassed);
2001         }
2002 
2003         [Variation("Call Skip on Entity Reference", Pri = 0)]
TestSkip15()2004         public int TestSkip15()
2005         {
2006             if (!IsXmlTextReader())
2007                 return TEST_SKIPPED;
2008 
2009             return BoolToLTMResult(VerifySkipOnNodeType(XmlNodeType.EntityReference));
2010         }
2011 
2012         [Variation("Call Skip on general entity ref node of attribute")]
TestTextSkip1()2013         public int TestTextSkip1()
2014         {
2015             if (!IsXmlTextReader())
2016                 return TEST_SKIPPED;
2017             bool bPassed = false;
2018 
2019             ReloadSource();
2020 
2021             DataReader.PositionOnElement(ST_ENTTEST_NAME);
2022             bPassed = DataReader.MoveToFirstAttribute();
2023             while (DataReader.ReadAttributeValue() && DataReader.NodeType != XmlNodeType.EntityReference)
2024             {
2025                 CError.WriteLine(DataReader.Value);
2026             }
2027             bPassed = DataReader.VerifyNode(XmlNodeType.EntityReference, "e1", String.Empty) && bPassed;
2028 
2029             DataReader.Skip();
2030 
2031             bPassed = DataReader.VerifyNode(XmlNodeType.Element, "ENTITY2", String.Empty) && bPassed;
2032 
2033             return BoolToLTMResult(bPassed);
2034         }
2035 
2036         [Variation("XmlTextReader ArgumentOutOfRangeException when handling ampersands")]
XmlTextReaderDoesHandleAmpersands()2037         public int XmlTextReaderDoesHandleAmpersands()
2038         {
2039             string xmlStr = @"<a>
2040     fffffffffffffffffffffffffffffffffffffff
2041     fffffffffffffffffffffffffffffffffffffff
2042     fffffffffffffffffffffffffffffffffffffff
2043     fffffffffffffffffffffffffffffffffffffff
2044     fffffffffffffffffffffffffffffffffffffff
2045     fffffffffffffffffffffffffffffffffffffff
2046     fffffffffffffffffffffffffffffffffffffff
2047     fffffffffffffffffffffffffffffffffffffff
2048     fffffffffffffffffffffffffffffffffffffff
2049     fffffffffffffffffffffffffffffffffffffff
2050     fffffffffffffffffffffffffffffffffffffff
2051     fffffffffffffffffffffffffffffffffffffff
2052     fffffffffffffffffffffffffffffffffffffff
2053     fffffffffffffffffffffffffffffffffffffff
2054     fffffffffffffffffffffffffffffffffffffff
2055     fffffffffffffffffffffffffffffffffffffff
2056     fffffffffffffffffffffffffffffffffffffff
2057 &gt;
2058     fffffffffffffffffffffffffffffffffffffff
2059     fffffffffffffffffffffffffffffffffffffff
2060     fffffffffffffffffffffffffffffffffffffff
2061     fffffffffffffffffffffffffffffffffffffff
2062     fffffffffffffffffffffffffffffffffffffff
2063     fffffffffffffffffffffffffffffffffffffff
2064     fffffffffffffffffffffffffffffffffffffff
2065     fffffffffffffffffffffffffffffffffffffff
2066 &amp;
2067 </a>
2068 ";
2069             ReloadSource(new StringReader(xmlStr));
2070             DataReader.PositionOnElement("a");
2071             DataReader.Skip();
2072             return TEST_PASS;
2073         }
2074     }
2075 
2076     /////////////////////////////////////////////////////////////////////////
2077     // TestCase BaseURI
2078     //
2079     /////////////////////////////////////////////////////////////////////////
2080     [InheritRequired()]
2081     public abstract partial class TCBaseURI : TCXMLReaderBaseGeneral
2082     {
2083         public const String ST_TEST_ENT = "AllNodeTypes.ent";
2084 
2085         public const String ST_GEN_ENT_NAME = "ext3";
2086         public const String ST_GEN_ENT_VALUE = "blah";
2087 
2088         ////////////////////////////////////////////////////////////////
2089         // Variations
2090         ////////////////////////////////////////////////////////////////
2091         [Variation("BaseURI for element node", Pri = 0)]
TestBaseURI1()2092         public int TestBaseURI1()
2093         {
2094             bool bPassed = false;
2095             String strExpBaseURI;
2096 
2097             ReloadSource();
2098             PositionOnNodeType(XmlNodeType.Element);
2099 
2100             strExpBaseURI = "Environment.CurrentDirectory" + "\\" + GetTestFileName(EREADER_TYPE.GENERIC);
2101             if (IsBinaryReader())
2102                 strExpBaseURI = strExpBaseURI + ".bin";
2103             Uri ExpBaseURI = new Uri("file:///" + strExpBaseURI);
2104 
2105             if (IsXsltReader())
2106                 bPassed = CError.Equals(DataReader.BaseURI, String.Empty, CurVariation.Desc);
2107             else
2108                 bPassed = CError.Equals(DataReader.BaseURI, ExpBaseURI.ToString(), CurVariation.Desc);
2109 
2110             return BoolToLTMResult(bPassed);
2111         }
2112 
2113         [Variation("BaseURI for attribute node", Pri = 0)]
TestBaseURI2()2114         public int TestBaseURI2()
2115         {
2116             bool bPassed = false;
2117             String strExpBaseURI;
2118 
2119             ReloadSource();
2120             PositionOnNodeType(XmlNodeType.Attribute);
2121 
2122             strExpBaseURI = "Environment.CurrentDirectory" + "\\" + GetTestFileName(EREADER_TYPE.GENERIC);
2123             if (IsBinaryReader())
2124                 strExpBaseURI = strExpBaseURI + ".bin";
2125 
2126             Uri ExpBaseURI = new Uri("file:///" + strExpBaseURI);
2127 
2128             if (IsXsltReader())
2129                 bPassed = CError.Equals(DataReader.BaseURI, String.Empty, CurVariation.Desc);
2130             else
2131                 bPassed = CError.Equals(DataReader.BaseURI, ExpBaseURI.ToString(), CurVariation.Desc);
2132 
2133             return BoolToLTMResult(bPassed);
2134         }
2135 
2136         [Variation("BaseURI for text node", Pri = 0)]
TestBaseURI3()2137         public int TestBaseURI3()
2138         {
2139             bool bPassed = false;
2140             String strExpBaseURI;
2141 
2142             ReloadSource();
2143             PositionOnNodeType(XmlNodeType.Text);
2144 
2145             strExpBaseURI = "Environment.CurrentDirectory" + "\\" + GetTestFileName(EREADER_TYPE.GENERIC);
2146             if (IsBinaryReader())
2147                 strExpBaseURI = strExpBaseURI + ".bin";
2148 
2149             Uri ExpBaseURI = new Uri("file:///" + strExpBaseURI);
2150 
2151             if (IsXsltReader())
2152                 bPassed = CError.Equals(DataReader.BaseURI, String.Empty, CurVariation.Desc);
2153             else
2154                 bPassed = CError.Equals(DataReader.BaseURI, ExpBaseURI.ToString(), CurVariation.Desc);
2155 
2156             return BoolToLTMResult(bPassed);
2157         }
2158 
2159         [Variation("BaseURI for CDATA node")]
TestBaseURI4()2160         public int TestBaseURI4()
2161         {
2162             ReloadSource();
2163 
2164             // No CDATA for Xslt
2165             if (IsXsltReader() || IsXPathNavigatorReader())
2166             {
2167                 while (FindNodeType(XmlNodeType.CDATA) == TEST_PASS)
2168                     return TEST_FAIL;
2169                 return TEST_PASS;
2170             }
2171 
2172             bool bPassed = false;
2173             string strExpBaseURI = "Environment.CurrentDirectory" + "\\" + GetTestFileName(EREADER_TYPE.GENERIC);
2174             if (IsBinaryReader())
2175                 strExpBaseURI = strExpBaseURI + ".bin";
2176 
2177             PositionOnNodeType(XmlNodeType.CDATA);
2178             Uri ExpBaseURI = new Uri("file:///" + strExpBaseURI);
2179             bPassed = CError.Equals(DataReader.BaseURI, ExpBaseURI.ToString(), CurVariation.Desc);
2180 
2181             return BoolToLTMResult(bPassed);
2182         }
2183 
2184         [Variation("BaseURI for PI node")]
TestBaseURI6()2185         public int TestBaseURI6()
2186         {
2187             bool bPassed = false;
2188             String strExpBaseURI;
2189 
2190             ReloadSource();
2191             PositionOnNodeType(XmlNodeType.ProcessingInstruction);
2192 
2193             strExpBaseURI = "Environment.CurrentDirectory" + "\\" + GetTestFileName(EREADER_TYPE.GENERIC);
2194             if (IsBinaryReader())
2195                 strExpBaseURI = strExpBaseURI + ".bin";
2196 
2197             Uri ExpBaseURI = new Uri("file:///" + strExpBaseURI);
2198 
2199             if (IsXsltReader())
2200                 bPassed = CError.Equals(DataReader.BaseURI, String.Empty, CurVariation.Desc);
2201             else
2202                 bPassed = CError.Equals(DataReader.BaseURI, ExpBaseURI.ToString(), CurVariation.Desc);
2203 
2204             return BoolToLTMResult(bPassed);
2205         }
2206 
2207         [Variation("BaseURI for Comment node")]
TestBaseURI7()2208         public int TestBaseURI7()
2209         {
2210             bool bPassed = false;
2211             String strExpBaseURI;
2212 
2213             ReloadSource();
2214             PositionOnNodeType(XmlNodeType.Comment);
2215 
2216             strExpBaseURI = "Environment.CurrentDirectory" + "\\" + GetTestFileName(EREADER_TYPE.GENERIC);
2217             if (IsBinaryReader())
2218                 strExpBaseURI = strExpBaseURI + ".bin";
2219 
2220             Uri ExpBaseURI = new Uri("file:///" + strExpBaseURI);
2221 
2222             if (IsXsltReader())
2223                 bPassed = CError.Equals(DataReader.BaseURI, String.Empty, CurVariation.Desc);
2224             else
2225                 bPassed = CError.Equals(DataReader.BaseURI, ExpBaseURI.ToString(), CurVariation.Desc);
2226 
2227             return BoolToLTMResult(bPassed);
2228         }
2229 
2230         [Variation("BaseURI for DTD node")]
TestBaseURI8()2231         public int TestBaseURI8()
2232         {
2233             bool bPassed = false;
2234             String strExpBaseURI;
2235 
2236             if (IsXsltReader() || IsXPathNavigatorReader())
2237                 return TEST_SKIPPED;
2238 
2239             ReloadSource();
2240             PositionOnNodeType(XmlNodeType.DocumentType);
2241 
2242             strExpBaseURI = "Environment.CurrentDirectory" + "\\" + GetTestFileName(EREADER_TYPE.GENERIC);
2243             if (IsBinaryReader())
2244                 strExpBaseURI = strExpBaseURI + ".bin";
2245 
2246             Uri ExpBaseURI = new Uri("file:///" + strExpBaseURI);
2247 
2248             if (IsXsltReader() || IsXPathNavigatorReader())
2249                 bPassed = CError.Equals(DataReader.BaseURI, String.Empty, CurVariation.Desc);
2250             else
2251                 bPassed = CError.Equals(DataReader.BaseURI, ExpBaseURI.ToString(), CurVariation.Desc);
2252 
2253             return BoolToLTMResult(bPassed);
2254         }
2255 
2256         [Variation("BaseURI for Whitespace node PreserveWhitespaces = true")]
TestBaseURI9()2257         public int TestBaseURI9()
2258         {
2259             if (IsXsltReader() || IsXPathNavigatorReader())
2260                 return TEST_SKIPPED;
2261 
2262             bool bPassed = false;
2263             string strExpBaseURI = String.Empty;
2264 
2265             ReloadSource();
2266             PositionOnNodeType(XmlNodeType.Whitespace);
2267 
2268             string tmp = "Environment.CurrentDirectory" + "\\" + GetTestFileName(EREADER_TYPE.GENERIC);
2269             if (IsBinaryReader())
2270                 tmp = tmp + ".bin";
2271 
2272             Uri ExpBaseURI = new Uri("file:///" + tmp);
2273             strExpBaseURI = ExpBaseURI.ToString();
2274 
2275             bPassed = CError.Equals(DataReader.BaseURI, strExpBaseURI, CurVariation.Desc);
2276 
2277             return BoolToLTMResult(bPassed);
2278         }
2279 
2280         [Variation("BaseURI for EndElement node")]
TestBaseURI10()2281         public int TestBaseURI10()
2282         {
2283             bool bPassed = false;
2284             String strExpBaseURI;
2285 
2286             ReloadSource();
2287             PositionOnNodeType(XmlNodeType.EndElement);
2288 
2289             strExpBaseURI = "Environment.CurrentDirectory" + "\\" + GetTestFileName(EREADER_TYPE.GENERIC);
2290             if (IsBinaryReader())
2291                 strExpBaseURI = strExpBaseURI + ".bin";
2292 
2293             Uri ExpBaseURI = new Uri("file:///" + strExpBaseURI);
2294 
2295             if (IsXsltReader())
2296                 bPassed = CError.Equals(DataReader.BaseURI, String.Empty, CurVariation.Desc);
2297             else
2298                 bPassed = CError.Equals(DataReader.BaseURI, ExpBaseURI.ToString(), CurVariation.Desc);
2299 
2300             return BoolToLTMResult(bPassed);
2301         }
2302 
2303         [Variation("BaseURI for EntityReference node", Pri = 0)]
TestTextBaseURI1()2304         public int TestTextBaseURI1()
2305         {
2306             if (IsXmlNodeReaderDataDoc() || IsXsltReader() || IsCoreReader() || IsXPathNavigatorReader())
2307                 return TEST_SKIPPED;
2308 
2309             bool bPassed = false;
2310             String strExpBaseURI;
2311 
2312             ReloadSource();
2313             PositionOnNodeType(XmlNodeType.EntityReference);
2314 
2315             strExpBaseURI = "Environment.CurrentDirectory" + "\\" + GetTestFileName(EREADER_TYPE.GENERIC);
2316             if (IsBinaryReader())
2317                 strExpBaseURI = strExpBaseURI + ".bin";
2318 
2319             Uri ExpBaseURI = new Uri("file:///" + strExpBaseURI);
2320             bPassed = CError.Equals(DataReader.BaseURI, ExpBaseURI.ToString(), CurVariation.Desc);
2321 
2322             return BoolToLTMResult(bPassed);
2323         }
2324 
2325         [Variation("BaseURI for EndEntity node")]
TestTextReaderBaseURI2()2326         public int TestTextReaderBaseURI2()
2327         {
2328             if (IsXmlTextReader() || IsXmlNodeReaderDataDoc() || IsXsltReader() || IsCoreReader() || IsXPathNavigatorReader())
2329                 return TEST_SKIPPED;
2330 
2331             bool bPassed = false;
2332             String strExpBaseURI;
2333 
2334             ReloadSource();
2335 
2336             PositionOnNodeType(XmlNodeType.EndEntity);
2337 
2338             strExpBaseURI = "Environment.CurrentDirectory" + "\\" + GetTestFileName(EREADER_TYPE.GENERIC);
2339             if (IsBinaryReader())
2340                 strExpBaseURI = strExpBaseURI + ".bin";
2341 
2342             Uri ExpBaseURI = new Uri("file:///" + strExpBaseURI);
2343             CError.WriteLine("EndEntity " + DataReader.BaseURI);
2344             bPassed = CError.Equals(DataReader.BaseURI, ExpBaseURI.ToString(), CurVariation.Desc);
2345 
2346             return BoolToLTMResult(bPassed);
2347         }
2348 
2349         [Variation("BaseURI for external General Entity")]
TestTextReaderBaseURI4()2350         public int TestTextReaderBaseURI4()
2351         {
2352             bool bPassed = false;
2353             String strExpBaseURI;
2354 
2355             if (IsXsltReader() || IsXPathNavigatorReader())
2356                 return TEST_SKIPPED;
2357 
2358             ReloadSource();
2359             DataReader.PositionOnElement("ENTITY5");
2360 
2361             DataReader.Read();
2362             strExpBaseURI = "Environment.CurrentDirectory" + "\\" + GetTestFileName(EREADER_TYPE.GENERIC);
2363             if (IsBinaryReader())
2364                 strExpBaseURI = strExpBaseURI + ".bin";
2365 
2366             Uri ExpBaseURI = new Uri("file:///" + strExpBaseURI);
2367             bPassed = CError.Equals(DataReader.BaseURI, ExpBaseURI.ToString(), "Before ResolveEntity");
2368 
2369             if (IsXmlTextReader() || IsXmlNodeReader() || IsXmlValidatingReader())
2370             {
2371                 bPassed = DataReader.VerifyNode(XmlNodeType.EntityReference, ST_GEN_ENT_NAME, String.Empty);
2372 
2373                 if (DataReader.CanResolveEntity)
2374                 {
2375                     DataReader.ResolveEntity();
2376                     DataReader.Read();
2377                     CError.WriteLine("HeRE" + DataReader.Value);
2378                     bPassed = DataReader.VerifyNode(XmlNodeType.Text, String.Empty, ST_GEN_ENT_VALUE) && bPassed;
2379                 }
2380             }
2381             else
2382                 bPassed = DataReader.VerifyNode(XmlNodeType.Text, String.Empty, ST_GEN_ENT_VALUE) && bPassed;
2383 
2384             bPassed = CError.Equals(DataReader.BaseURI, ExpBaseURI.ToString(), "After ResolveEntity");
2385 
2386             return BoolToLTMResult(bPassed);
2387         }
2388 
2389         [Variation("BaseURI for entity defined in nested parameter entity")]
TestTextReaderBaseURI5()2390         public int TestTextReaderBaseURI5()
2391         {
2392             bool bPassed = false;
2393 
2394             if (IsXsltReader() || IsXPathNavigatorReader())
2395                 return TEST_SKIPPED;
2396 
2397             string filename = Path.Combine(TestData, "Common", "bug_62426.xml");
2398             if (IsBinaryReader())
2399                 filename = Path.GetFileName(filename) + ".bin";
2400 
2401             Uri uri = new Uri("file:" + filename);
2402 
2403             ReloadSource(filename);
2404 
2405             DataReader.PositionOnElement("root");
2406 
2407             DataReader.Read();
2408             bPassed = CError.Equals(DataReader.BaseURI.Contains("Common/bug_62426.xml"), true, "Before ResolveEntity");
2409 
2410             if (IsXmlTextReader() || IsXmlNodeReader() || IsXmlValidatingReader())
2411             {
2412                 bPassed = DataReader.VerifyNode(XmlNodeType.EntityReference, "bug62426", String.Empty);
2413 
2414                 if (DataReader.CanResolveEntity)
2415                 {
2416                     DataReader.ResolveEntity();
2417                     DataReader.Read();
2418                     CError.WriteLine("HeRE" + DataReader.Value);
2419                     bPassed = DataReader.VerifyNode(XmlNodeType.Text, String.Empty, "bug62426") && bPassed;
2420                 }
2421             }
2422             else
2423                 bPassed = DataReader.VerifyNode(XmlNodeType.Text, String.Empty, "bug62426") && bPassed;
2424 
2425             bPassed = CError.Compare(DataReader.BaseURI.Contains("Common/bug_62426.xml"), "After ResolveEntity");
2426 
2427             return BoolToLTMResult(bPassed);
2428         }
2429 
2430         [Variation("BaseURI for filename containing # and %23")]
TestTextReaderBaseURI6()2431         public int TestTextReaderBaseURI6()
2432         {
2433             if (IsXsltReader() || IsXPathNavigatorReader())
2434                 return TEST_SKIPPED;
2435 
2436             string filename = Path.Combine(TestData, "Common", "file#%23.xml");
2437             if (IsBinaryReader())
2438                 filename = Path.GetFileName(filename) + ".bin";
2439 
2440             ReloadSource(filename);
2441             DataReader.Read();
2442             Uri uri = new Uri(filename);
2443 
2444             string expectedUri = uri.ToString();
2445             if (IsBinaryReader())
2446                 expectedUri = expectedUri + ".bin";
2447 
2448             expectedUri = expectedUri.Replace(@"\", @"/");
2449             CError.WriteLine("Expected URI = " + expectedUri);
2450             CError.WriteLine("Actual URI =   " + DataReader.BaseURI);
2451             CError.Compare(DataReader.BaseURI.Contains("Common/file%23%2523.xml"), "baseUri");
2452             return TEST_PASS;
2453         }
2454 
2455         [Variation("BaseURI for external entity in external DTD")]
TestTextReaderBaseURI7()2456         public int TestTextReaderBaseURI7()
2457         {
2458             if (IsXsltReader() || IsXPathNavigatorReader())
2459                 return TEST_SKIPPED;
2460 
2461             string filepath = Path.Combine(TestData, "Common");
2462             string filename = Path.Combine(filepath, "bug_60677.xml");
2463             if (IsBinaryReader())
2464                 filename = Path.GetFileName(filename) + ".bin";
2465 
2466             string fileent = Path.Combine(filepath, "A", "B", "bug60677.ent");
2467 
2468             Uri uriFile = new Uri("file:" + filename);
2469             Uri uriEnt = new Uri("file:" + fileent);
2470 
2471             ReloadSource(filename);
2472 
2473             while (DataReader.Read())
2474             {
2475                 if (DataReader.NodeType == XmlNodeType.EntityReference && DataReader.CanResolveEntity)
2476                 {
2477                     DataReader.ResolveEntity();
2478                     DataReader.Read(); // Text
2479                     CError.Compare(DataReader.BaseURI, uriEnt.ToString(), "ent1 baseuri");
2480                     DataReader.Read(); // EndEntity
2481                     CError.Compare(DataReader.BaseURI, uriFile.ToString(), "ent2 baseuri");
2482                 }
2483             }
2484             return TEST_PASS;
2485         }
2486 
2487         [Variation("BaseURI for external entity in external DTD with default entity handling")]
TestTextReaderBaseURI107315()2488         public int TestTextReaderBaseURI107315()
2489         {
2490             if (!IsXmlValidatingReader())
2491                 return TEST_SKIPPED;
2492 
2493             string filepath = Path.Combine(TestData, "Common");
2494             string filename = Path.Combine(filepath, "bug_60677.xml");
2495             if (IsBinaryReader())
2496                 filename = Path.GetFileName(filename) + ".bin";
2497 
2498             string fileent = Path.Combine(filepath, "bug_60677.xml");
2499 
2500             Uri uriFile = new Uri("file:" + filename);
2501             Uri uriEnt = new Uri("file:" + fileent);
2502 
2503             ReloadSource(filename);
2504 
2505             while (DataReader.Read())
2506             {
2507                 if (DataReader.NodeType == XmlNodeType.Text && DataReader.Value == "ABC")
2508                 {
2509                     CError.Compare(DataReader.BaseURI, uriEnt.ToString(), "ent1 baseuri");
2510                 }
2511             }
2512 
2513             return TEST_PASS;
2514         }
2515 
2516         [Variation("BaseUri for element expanded from nested parameter entities")]
TestTextReaderBaseURI8()2517         public int TestTextReaderBaseURI8()
2518         {
2519             if (IsXsltReader() || IsXmlNodeReader() || IsXmlNodeReaderDataDoc() || IsCoreReader() || IsXPathNavigatorReader())
2520                 return TEST_SKIPPED;
2521 
2522             string filename = Path.Combine(TestData, "Common", "Bug94358.xml");
2523             if (IsBinaryReader())
2524                 filename = Path.GetFileName(filename) + ".bin";
2525 
2526             Uri uriFile = new Uri("file:" + filename);
2527 
2528             ReloadSource(filename);
2529 
2530             while (DataReader.Read())
2531             {
2532                 if (DataReader.ReadState == ReadState.Interactive && DataReader.LocalName == "x")
2533                 {
2534                     break;
2535                 }
2536             }
2537 
2538             CError.WriteLine("Base URI of element <x> is " + DataReader.BaseURI.ToString());
2539 
2540             if (CError.Compare(DataReader.BaseURI.ToString(), uriFile.ToString(), "Expected BaseURI : " + filename))
2541                 return TEST_PASS;
2542             else
2543                 return TEST_FAIL;
2544         }
2545     }
2546 }
2547