2003-01-26 Atsushi Enomoto <ginga@kit.hi-ho.ne.jp>
[mono.git] / mcs / class / System.XML / Test / XmlTextReaderTests.cs
1 //
2 // XmlTextReaderTests.cs
3 //
4 // Author:
5 //   Jason Diamond (jason@injektilo.org)
6 //
7 // (C) 2001, 2002 Jason Diamond  http://injektilo.org/
8 //
9
10 using System;
11 using System.IO;
12 using System.Xml;
13 using System.Text;
14
15 using NUnit.Framework;
16
17 namespace MonoTests.System.Xml
18 {
19         public class XmlTextReaderTests : TestCase
20         {
21                 public XmlTextReaderTests () : base ("MonoTests.System.Xml.XmlTextReaderTests testsuite") { }
22                 public XmlTextReaderTests (string name) : base (name) { }
23
24                 private void AssertStartDocument (XmlReader xmlReader)
25                 {
26                         Assert (xmlReader.ReadState == ReadState.Initial);
27                         Assert (xmlReader.NodeType == XmlNodeType.None);
28                         Assert (xmlReader.Depth == 0);
29                         Assert (!xmlReader.EOF);
30                 }
31
32                 private void AssertNode (
33                         XmlReader xmlReader,
34                         XmlNodeType nodeType,
35                         int depth,
36                         bool isEmptyElement,
37                         string name,
38                         string prefix,
39                         string localName,
40                         string namespaceURI,
41                         string value,
42                         int attributeCount)
43                 {
44                         Assert (xmlReader.Read ());
45                         Assert (xmlReader.ReadState == ReadState.Interactive);
46                         Assert (!xmlReader.EOF);
47                         AssertNodeValues (xmlReader, nodeType, depth, isEmptyElement, name, prefix, localName, namespaceURI, value, attributeCount);
48                 }
49
50                 private void AssertNodeValues (
51                         XmlReader xmlReader,
52                         XmlNodeType nodeType,
53                         int depth,
54                         bool isEmptyElement,
55                         string name,
56                         string prefix,
57                         string localName,
58                         string namespaceURI,
59                         string value,
60                         int attributeCount)
61                 {
62                         AssertEquals ("NodeType", nodeType, xmlReader.NodeType);
63                         AssertEquals ("Depth", depth, xmlReader.Depth);
64                         AssertEquals ("IsEmptyElement", isEmptyElement, xmlReader.IsEmptyElement);
65
66                         AssertEquals ("name", name, xmlReader.Name);
67
68                         AssertEquals ("prefix", prefix, xmlReader.Prefix);
69
70                         AssertEquals ("localName", localName, xmlReader.LocalName);
71
72                         AssertEquals ("namespaceURI", namespaceURI, xmlReader.NamespaceURI);
73
74                         AssertEquals ("hasValue", (value != String.Empty), xmlReader.HasValue);
75
76                         AssertEquals ("Value", value, xmlReader.Value);
77
78                         AssertEquals ("hasAttributes", attributeCount > 0, xmlReader.HasAttributes);
79
80                         AssertEquals ("attributeCount", attributeCount, xmlReader.AttributeCount);
81                 }
82
83                 private void AssertAttribute (
84                         XmlReader xmlReader,
85                         string name,
86                         string prefix,
87                         string localName,
88                         string namespaceURI,
89                         string value)
90                 {
91                         AssertEquals ("value", value, xmlReader [name]);
92
93                         Assert (xmlReader.GetAttribute (name) == value);
94
95                         if (namespaceURI != String.Empty) {
96                                 Assert (xmlReader[localName, namespaceURI] == value);
97                                 Assert (xmlReader.GetAttribute (localName, namespaceURI) == value);
98                         }
99                 }
100
101                 private void AssertEndDocument (XmlReader xmlReader)
102                 {
103                         Assert ("could read", !xmlReader.Read ());
104                         AssertEquals ("NodeType is not XmlNodeType.None", XmlNodeType.None, xmlReader.NodeType);
105                         AssertEquals ("Depth is not 0", 0, xmlReader.Depth);
106                         AssertEquals ("ReadState is not ReadState.EndOfFile",  ReadState.EndOfFile, xmlReader.ReadState);
107                         Assert ("not EOF", xmlReader.EOF);
108
109                         xmlReader.Close ();
110                         AssertEquals ("ReadState is not ReadState.Cosed", ReadState.Closed, xmlReader.ReadState);
111                 }
112
113                 public void TestEmptyElement ()
114                 {
115                         string xml = "<foo/>";
116                         XmlReader xmlReader =
117                                 new XmlTextReader (new StringReader (xml));
118
119                         AssertStartDocument (xmlReader);
120
121                         AssertNode (
122                                 xmlReader, // xmlReader
123                                 XmlNodeType.Element, // nodeType
124                                 0, // depth
125                                 true, // isEmptyElement
126                                 "foo", // name
127                                 String.Empty, // prefix
128                                 "foo", // localName
129                                 String.Empty, // namespaceURI
130                                 String.Empty, // value
131                                 0 // attributeCount
132                         );
133
134                         AssertEndDocument (xmlReader);
135                 }
136
137                 public void TestEmptyElementWithBadName ()
138                 {
139                         string xml = "<1foo/>";
140                         XmlReader xmlReader =
141                                 new XmlTextReader (new StringReader (xml));
142
143                         bool caughtXmlException = false;
144
145                         try {
146                                 xmlReader.Read();
147                         } catch (XmlException) {
148                                 caughtXmlException = true;
149                         }
150
151                         Assert(caughtXmlException);
152                 }
153
154                 public void TestEmptyElementWithWhitespace ()
155                 {
156                         string xml = "<foo />";
157                         XmlReader xmlReader =
158                                 new XmlTextReader (new StringReader (xml));
159
160                         AssertStartDocument (xmlReader);
161
162                         AssertNode (
163                                 xmlReader, // xmlReader
164                                 XmlNodeType.Element, // nodeType
165                                 0, //depth
166                                 true, // isEmptyElement
167                                 "foo", // name
168                                 String.Empty, // prefix
169                                 "foo", // localName
170                                 String.Empty, // namespaceURI
171                                 String.Empty, // value
172                                 0 // attributeCount
173                         );
174
175                         AssertEndDocument (xmlReader);
176                 }
177
178                 public void TestEmptyElementWithStartAndEndTag ()
179                 {
180                         string xml = "<foo></foo>";
181                         XmlReader xmlReader =
182                                 new XmlTextReader (new StringReader (xml));
183
184                         AssertStartDocument (xmlReader);
185
186                         AssertNode (
187                                 xmlReader, // xmlReader
188                                 XmlNodeType.Element, // nodeType
189                                 0, //depth
190                                 false, // isEmptyElement
191                                 "foo", // name
192                                 String.Empty, // prefix
193                                 "foo", // localName
194                                 String.Empty, // namespaceURI
195                                 String.Empty, // value
196                                 0 // attributeCount
197                         );
198
199                         AssertNode (
200                                 xmlReader, // xmlReader
201                                 XmlNodeType.EndElement, // nodeType
202                                 0, //depth
203                                 false, // isEmptyElement
204                                 "foo", // name
205                                 String.Empty, // prefix
206                                 "foo", // localName
207                                 String.Empty, // namespaceURI
208                                 String.Empty, // value
209                                 0 // attributeCount
210                         );
211
212                         AssertEndDocument (xmlReader);
213                 }
214
215                 public void TestEmptyElementWithStartAndEndTagWithWhitespace ()
216                 {
217                         string xml = "<foo ></foo >";
218                         XmlReader xmlReader =
219                                 new XmlTextReader (new StringReader (xml));
220
221                         AssertStartDocument (xmlReader);
222
223                         AssertNode (
224                                 xmlReader, // xmlReader
225                                 XmlNodeType.Element, // nodeType
226                                 0, //depth
227                                 false, // isEmptyElement
228                                 "foo", // name
229                                 String.Empty, // prefix
230                                 "foo", // localName
231                                 String.Empty, // namespaceURI
232                                 String.Empty, // value
233                                 0 // attributeCount
234                         );
235
236                         AssertNode (
237                                 xmlReader, // xmlReader
238                                 XmlNodeType.EndElement, // nodeType
239                                 0, //depth
240                                 false, // isEmptyElement
241                                 "foo", // name
242                                 String.Empty, // prefix
243                                 "foo", // localName
244                                 String.Empty, // namespaceURI
245                                 String.Empty, // value
246                                 0 // attributeCount
247                         );
248
249                         AssertEndDocument (xmlReader);
250                 }
251
252                 public void TestNestedEmptyTag ()
253                 {
254                         string xml = "<foo><bar/></foo>";
255                         XmlReader xmlReader =
256                                 new XmlTextReader (new StringReader (xml));
257
258                         AssertStartDocument (xmlReader);
259
260                         AssertNode (
261                                 xmlReader, // xmlReader
262                                 XmlNodeType.Element, // nodeType
263                                 0, //depth
264                                 false, // isEmptyElement
265                                 "foo", // name
266                                 String.Empty, // prefix
267                                 "foo", // localName
268                                 String.Empty, // namespaceURI
269                                 String.Empty, // value
270                                 0 // attributeCount
271                         );
272
273                         AssertNode (
274                                 xmlReader, // xmlReader
275                                 XmlNodeType.Element, // nodeType
276                                 1, //depth
277                                 true, // isEmptyElement
278                                 "bar", // name
279                                 String.Empty, // prefix
280                                 "bar", // localName
281                                 String.Empty, // namespaceURI
282                                 String.Empty, // value
283                                 0 // attributeCount
284                         );
285
286                         AssertNode (
287                                 xmlReader, // xmlReader
288                                 XmlNodeType.EndElement, // nodeType
289                                 0, //depth
290                                 false, // isEmptyElement
291                                 "foo", // name
292                                 String.Empty, // prefix
293                                 "foo", // localName
294                                 String.Empty, // namespaceURI
295                                 String.Empty, // value
296                                 0 // attributeCount
297                         );
298
299                         AssertEndDocument (xmlReader);
300                 }
301
302                 public void TestNestedText ()
303                 {
304                         string xml = "<foo>bar</foo>";
305                         XmlReader xmlReader =
306                                 new XmlTextReader (new StringReader (xml));
307
308                         AssertStartDocument (xmlReader);
309
310                         AssertNode (
311                                 xmlReader, // xmlReader
312                                 XmlNodeType.Element, // nodeType
313                                 0, //depth
314                                 false, // isEmptyElement
315                                 "foo", // name
316                                 String.Empty, // prefix
317                                 "foo", // localName
318                                 String.Empty, // namespaceURI
319                                 String.Empty, // value
320                                 0 // attributeCount
321                         );
322
323                         AssertNode (
324                                 xmlReader, // xmlReader
325                                 XmlNodeType.Text, // nodeType
326                                 1, //depth
327                                 false, // isEmptyElement
328                                 String.Empty, // name
329                                 String.Empty, // prefix
330                                 String.Empty, // localName
331                                 String.Empty, // namespaceURI
332                                 "bar", // value
333                                 0 // attributeCount
334                         );
335
336                         AssertNode (
337                                 xmlReader, // xmlReader
338                                 XmlNodeType.EndElement, // nodeType
339                                 0, //depth
340                                 false, // isEmptyElement
341                                 "foo", // name
342                                 String.Empty, // prefix
343                                 "foo", // localName
344                                 String.Empty, // namespaceURI
345                                 String.Empty, // value
346                                 0 // attributeCount
347                         );
348
349                         AssertEndDocument (xmlReader);
350                 }
351
352                 public void TestEmptyElementWithAttribute ()
353                 {
354                         string xml = @"<foo bar=""baz""/>";
355                         XmlReader xmlReader =
356                                 new XmlTextReader (new StringReader (xml));
357
358                         AssertStartDocument (xmlReader);
359
360                         AssertNode (
361                                 xmlReader, // xmlReader
362                                 XmlNodeType.Element, // nodeType
363                                 0, //depth
364                                 true, // isEmptyElement
365                                 "foo", // name
366                                 String.Empty, // prefix
367                                 "foo", // localName
368                                 String.Empty, // namespaceURI
369                                 String.Empty, // value
370                                 1 // attributeCount
371                         );
372
373                         AssertAttribute (
374                                 xmlReader, // xmlReader
375                                 "bar", // name
376                                 String.Empty, // prefix
377                                 "bar", // localName
378                                 String.Empty, // namespaceURI
379                                 "baz" // value
380                         );
381
382                         AssertEndDocument (xmlReader);
383                 }
384
385                 public void TestStartAndEndTagWithAttribute ()
386                 {
387                         string xml = @"<foo bar='baz'></foo>";
388                         XmlReader xmlReader =
389                                 new XmlTextReader (new StringReader (xml));
390
391                         AssertStartDocument (xmlReader);
392
393                         AssertNode (
394                                 xmlReader, // xmlReader
395                                 XmlNodeType.Element, // nodeType
396                                 0, //depth
397                                 false, // isEmptyElement
398                                 "foo", // name
399                                 String.Empty, // prefix
400                                 "foo", // localName
401                                 String.Empty, // namespaceURI
402                                 String.Empty, // value
403                                 1 // attributeCount
404                         );
405
406                         AssertAttribute (
407                                 xmlReader, // xmlReader
408                                 "bar", // name
409                                 String.Empty, // prefix
410                                 "bar", // localName
411                                 String.Empty, // namespaceURI
412                                 "baz" // value
413                         );
414
415                         AssertNode (
416                                 xmlReader, // xmlReader
417                                 XmlNodeType.EndElement, // nodeType
418                                 0, //depth
419                                 false, // isEmptyElement
420                                 "foo", // name
421                                 String.Empty, // prefix
422                                 "foo", // localName
423                                 String.Empty, // namespaceURI
424                                 String.Empty, // value
425                                 0 // attributeCount
426                         );
427
428                         AssertEndDocument (xmlReader);
429                 }
430
431                 public void TestEmptyElementWithTwoAttributes ()
432                 {
433                         string xml = @"<foo bar=""baz"" quux='quuux'/>";
434                         XmlReader xmlReader =
435                                 new XmlTextReader (new StringReader (xml));
436
437                         AssertStartDocument (xmlReader);
438
439                         AssertNode (
440                                 xmlReader, // xmlReader
441                                 XmlNodeType.Element, // nodeType
442                                 0, //depth
443                                 true, // isEmptyElement
444                                 "foo", // name
445                                 String.Empty, // prefix
446                                 "foo", // localName
447                                 String.Empty, // namespaceURI
448                                 String.Empty, // value
449                                 2 // attributeCount
450                         );
451
452                         AssertAttribute (
453                                 xmlReader, // xmlReader
454                                 "bar", // name
455                                 String.Empty, // prefix
456                                 "bar", // localName
457                                 String.Empty, // namespaceURI
458                                 "baz" // value
459                         );
460
461                         AssertAttribute (
462                                 xmlReader, // xmlReader
463                                 "quux", // name
464                                 String.Empty, // prefix
465                                 "quux", // localName
466                                 String.Empty, // namespaceURI
467                                 "quuux" // value
468                         );
469
470                         AssertEndDocument (xmlReader);
471                 }
472
473                 public void TestProcessingInstructionBeforeDocumentElement ()
474                 {
475                         string xml = "<?foo bar?><baz/>";
476                         XmlReader xmlReader =
477                                 new XmlTextReader (new StringReader (xml));
478
479                         AssertStartDocument (xmlReader);
480
481                         AssertNode (
482                                 xmlReader, // xmlReader
483                                 XmlNodeType.ProcessingInstruction, // nodeType
484                                 0, //depth
485                                 false, // isEmptyElement
486                                 "foo", // name
487                                 String.Empty, // prefix
488                                 "foo", // localName
489                                 String.Empty, // namespaceURI
490                                 "bar", // value
491                                 0 // attributeCount
492                         );
493
494                         AssertNode (
495                                 xmlReader, // xmlReader
496                                 XmlNodeType.Element, // nodeType
497                                 0, //depth
498                                 true, // isEmptyElement
499                                 "baz", // name
500                                 String.Empty, // prefix
501                                 "baz", // localName
502                                 String.Empty, // namespaceURI
503                                 String.Empty, // value
504                                 0 // attributeCount
505                         );
506
507                         AssertEndDocument (xmlReader);
508                 }
509
510                 public void TestCommentBeforeDocumentElement ()
511                 {
512                         string xml = "<!--foo--><bar/>";
513                         XmlReader xmlReader =
514                                 new XmlTextReader (new StringReader (xml));
515
516                         AssertStartDocument (xmlReader);
517
518                         AssertNode (
519                                 xmlReader, // xmlReader
520                                 XmlNodeType.Comment, // nodeType
521                                 0, //depth
522                                 false, // isEmptyElement
523                                 String.Empty, // name
524                                 String.Empty, // prefix
525                                 String.Empty, // localName
526                                 String.Empty, // namespaceURI
527                                 "foo", // value
528                                 0 // attributeCount
529                         );
530
531                         AssertNode (
532                                 xmlReader, // xmlReader
533                                 XmlNodeType.Element, // nodeType
534                                 0, //depth
535                                 true, // isEmptyElement
536                                 "bar", // name
537                                 String.Empty, // prefix
538                                 "bar", // localName
539                                 String.Empty, // namespaceURI
540                                 String.Empty, // value
541                                 0 // attributeCount
542                         );
543
544                         AssertEndDocument (xmlReader);
545                 }
546
547                 public void TestPredefinedEntities ()
548                 {
549                         string xml = "<foo>&lt;&gt;&amp;&apos;&quot;</foo>";
550                         XmlReader xmlReader =
551                                 new XmlTextReader (new StringReader (xml));
552
553                         AssertStartDocument (xmlReader);
554
555                         AssertNode (
556                                 xmlReader, // xmlReader
557                                 XmlNodeType.Element, // nodeType
558                                 0, //depth
559                                 false, // isEmptyElement
560                                 "foo", // name
561                                 String.Empty, // prefix
562                                 "foo", // localName
563                                 String.Empty, // namespaceURI
564                                 String.Empty, // value
565                                 0 // attributeCount
566                         );
567
568                         AssertNode (
569                                 xmlReader, // xmlReader
570                                 XmlNodeType.Text, // nodeType
571                                 1, //depth
572                                 false, // isEmptyElement
573                                 String.Empty, // name
574                                 String.Empty, // prefix
575                                 String.Empty, // localName
576                                 String.Empty, // namespaceURI
577                                 "<>&'\"", // value
578                                 0 // attributeCount
579                         );
580
581                         AssertNode (
582                                 xmlReader, // xmlReader
583                                 XmlNodeType.EndElement, // nodeType
584                                 0, //depth
585                                 false, // isEmptyElement
586                                 "foo", // name
587                                 String.Empty, // prefix
588                                 "foo", // localName
589                                 String.Empty, // namespaceURI
590                                 String.Empty, // value
591                                 0 // attributeCount
592                         );
593
594                         AssertEndDocument (xmlReader);
595                 }
596
597                 public void TestEntityReference ()
598                 {
599                         string xml = "<foo>&bar;</foo>";
600                         XmlReader xmlReader =
601                                 new XmlTextReader (new StringReader (xml));
602
603                         AssertStartDocument (xmlReader);
604
605                         AssertNode (
606                                 xmlReader, // xmlReader
607                                 XmlNodeType.Element, // nodeType
608                                 0, //depth
609                                 false, // isEmptyElement
610                                 "foo", // name
611                                 String.Empty, // prefix
612                                 "foo", // localName
613                                 String.Empty, // namespaceURI
614                                 String.Empty, // value
615                                 0 // attributeCount
616                         );
617
618                         AssertNode (
619                                 xmlReader, // xmlReader
620                                 XmlNodeType.EntityReference, // nodeType
621                                 1, //depth
622                                 false, // isEmptyElement
623                                 "bar", // name
624                                 String.Empty, // prefix
625                                 "bar", // localName
626                                 String.Empty, // namespaceURI
627                                 String.Empty, // value
628                                 0 // attributeCount
629                         );
630
631                         AssertNode (
632                                 xmlReader, // xmlReader
633                                 XmlNodeType.EndElement, // nodeType
634                                 0, //depth
635                                 false, // isEmptyElement
636                                 "foo", // name
637                                 String.Empty, // prefix
638                                 "foo", // localName
639                                 String.Empty, // namespaceURI
640                                 String.Empty, // value
641                                 0 // attributeCount
642                         );
643
644                         AssertEndDocument (xmlReader);
645                 }
646
647                 public void TestEntityReferenceInsideText ()
648                 {
649                         string xml = "<foo>bar&baz;quux</foo>";
650                         XmlReader xmlReader =
651                                 new XmlTextReader (new StringReader (xml));
652
653                         AssertStartDocument (xmlReader);
654
655                         AssertNode (
656                                 xmlReader, // xmlReader
657                                 XmlNodeType.Element, // nodeType
658                                 0, //depth
659                                 false, // isEmptyElement
660                                 "foo", // name
661                                 String.Empty, // prefix
662                                 "foo", // localName
663                                 String.Empty, // namespaceURI
664                                 String.Empty, // value
665                                 0 // attributeCount
666                         );
667
668                         AssertNode (
669                                 xmlReader, // xmlReader
670                                 XmlNodeType.Text, // nodeType
671                                 1, //depth
672                                 false, // isEmptyElement
673                                 String.Empty, // name
674                                 String.Empty, // prefix
675                                 String.Empty, // localName
676                                 String.Empty, // namespaceURI
677                                 "bar", // value
678                                 0 // attributeCount
679                         );
680
681                         AssertNode (
682                                 xmlReader, // xmlReader
683                                 XmlNodeType.EntityReference, // nodeType
684                                 1, //depth
685                                 false, // isEmptyElement
686                                 "baz", // name
687                                 String.Empty, // prefix
688                                 "baz", // localName
689                                 String.Empty, // namespaceURI
690                                 String.Empty, // value
691                                 0 // attributeCount
692                         );
693
694                         AssertNode (
695                                 xmlReader, // xmlReader
696                                 XmlNodeType.Text, // nodeType
697                                 1, //depth
698                                 false, // isEmptyElement
699                                 String.Empty, // name
700                                 String.Empty, // prefix
701                                 String.Empty, // localName
702                                 String.Empty, // namespaceURI
703                                 "quux", // value
704                                 0 // attributeCount
705                         );
706
707                         AssertNode (
708                                 xmlReader, // xmlReader
709                                 XmlNodeType.EndElement, // nodeType
710                                 0, //depth
711                                 false, // isEmptyElement
712                                 "foo", // name
713                                 String.Empty, // prefix
714                                 "foo", // localName
715                                 String.Empty, // namespaceURI
716                                 String.Empty, // value
717                                 0 // attributeCount
718                         );
719
720                         AssertEndDocument (xmlReader);
721                 }
722
723                 public void TestCharacterReferences ()
724                 {
725                         string xml = "<foo>&#70;&#x4F;&#x4f;</foo>";
726                         XmlReader xmlReader =
727                                 new XmlTextReader (new StringReader (xml));
728
729                         AssertStartDocument (xmlReader);
730
731                         AssertNode (
732                                 xmlReader, // xmlReader
733                                 XmlNodeType.Element, // nodeType
734                                 0, //depth
735                                 false, // isEmptyElement
736                                 "foo", // name
737                                 String.Empty, // prefix
738                                 "foo", // localName
739                                 String.Empty, // namespaceURI
740                                 String.Empty, // value
741                                 0 // attributeCount
742                         );
743
744                         AssertNode (
745                                 xmlReader, // xmlReader
746                                 XmlNodeType.Text, // nodeType
747                                 1, //depth
748                                 false, // isEmptyElement
749                                 String.Empty, // name
750                                 String.Empty, // prefix
751                                 String.Empty, // localName
752                                 String.Empty, // namespaceURI
753                                 "FOO", // value
754                                 0 // attributeCount
755                         );
756
757                         AssertNode (
758                                 xmlReader, // xmlReader
759                                 XmlNodeType.EndElement, // nodeType
760                                 0, //depth
761                                 false, // isEmptyElement
762                                 "foo", // name
763                                 String.Empty, // prefix
764                                 "foo", // localName
765                                 String.Empty, // namespaceURI
766                                 String.Empty, // value
767                                 0 // attributeCount
768                         );
769
770                         AssertEndDocument (xmlReader);
771                 }
772
773                 public void TestEntityReferenceInAttribute ()
774                 {
775                         string xml = "<foo bar='&baz;'/>";
776                         XmlReader xmlReader =
777                                 new XmlTextReader (new StringReader (xml));
778
779                         AssertStartDocument (xmlReader);
780
781                         AssertNode (
782                                 xmlReader, // xmlReader
783                                 XmlNodeType.Element, // nodeType
784                                 0, //depth
785                                 true, // isEmptyElement
786                                 "foo", // name
787                                 String.Empty, // prefix
788                                 "foo", // localName
789                                 String.Empty, // namespaceURI
790                                 String.Empty, // value
791                                 1 // attributeCount
792                         );
793
794                         AssertAttribute (
795                                 xmlReader, // xmlReader
796                                 "bar", // name
797                                 String.Empty, // prefix
798                                 "bar", // localName
799                                 String.Empty, // namespaceURI
800                                 "&baz;" // value
801                         );
802
803                         AssertEndDocument (xmlReader);
804                 }
805
806                 public void TestPredefinedEntitiesInAttribute ()
807                 {
808                         string xml = "<foo bar='&lt;&gt;&amp;&apos;&quot;'/>";
809                         XmlReader xmlReader =
810                                 new XmlTextReader (new StringReader (xml));
811
812                         AssertStartDocument (xmlReader);
813
814                         AssertNode (
815                                 xmlReader, // xmlReader
816                                 XmlNodeType.Element, // nodeType
817                                 0, //depth
818                                 true, // isEmptyElement
819                                 "foo", // name
820                                 String.Empty, // prefix
821                                 "foo", // localName
822                                 String.Empty, // namespaceURI
823                                 String.Empty, // value
824                                 1 // attributeCount
825                         );
826
827                         AssertAttribute (
828                                 xmlReader, // xmlReader
829                                 "bar", // name
830                                 String.Empty, // prefix
831                                 "bar", // localName
832                                 String.Empty, // namespaceURI
833                                 "<>&'\"" // value
834                         );
835
836                         AssertEndDocument (xmlReader);
837                 }
838
839                 public void TestCharacterReferencesInAttribute ()
840                 {
841                         string xml = "<foo bar='&#70;&#x4F;&#x4f;'/>";
842                         XmlReader xmlReader =
843                                 new XmlTextReader (new StringReader (xml));
844
845                         AssertStartDocument (xmlReader);
846
847                         AssertNode (
848                                 xmlReader, // xmlReader
849                                 XmlNodeType.Element, // nodeType
850                                 0, //depth
851                                 true, // isEmptyElement
852                                 "foo", // name
853                                 String.Empty, // prefix
854                                 "foo", // localName
855                                 String.Empty, // namespaceURI
856                                 String.Empty, // value
857                                 1 // attributeCount
858                         );
859
860                         AssertAttribute (
861                                 xmlReader, // xmlReader
862                                 "bar", // name
863                                 String.Empty, // prefix
864                                 "bar", // localName
865                                 String.Empty, // namespaceURI
866                                 "FOO" // value
867                         );
868
869                         AssertEndDocument (xmlReader);
870                 }
871
872                 public void TestCDATA ()
873                 {
874                         string xml = "<foo><![CDATA[<>&]]></foo>";
875                         XmlReader xmlReader =
876                                 new XmlTextReader (new StringReader (xml));
877
878                         AssertStartDocument (xmlReader);
879
880                         AssertNode (
881                                 xmlReader, // xmlReader
882                                 XmlNodeType.Element, // nodeType
883                                 0, //depth
884                                 false, // isEmptyElement
885                                 "foo", // name
886                                 String.Empty, // prefix
887                                 "foo", // localName
888                                 String.Empty, // namespaceURI
889                                 String.Empty, // value
890                                 0 // attributeCount
891                         );
892
893                         AssertNode (
894                                 xmlReader, // xmlReader
895                                 XmlNodeType.CDATA, // nodeType
896                                 1, //depth
897                                 false, // isEmptyElement
898                                 String.Empty, // name
899                                 String.Empty, // prefix
900                                 String.Empty, // localName
901                                 String.Empty, // namespaceURI
902                                 "<>&", // value
903                                 0 // attributeCount
904                         );
905
906                         AssertNode (
907                                 xmlReader, // xmlReader
908                                 XmlNodeType.EndElement, // nodeType
909                                 0, //depth
910                                 false, // isEmptyElement
911                                 "foo", // name
912                                 String.Empty, // prefix
913                                 "foo", // localName
914                                 String.Empty, // namespaceURI
915                                 String.Empty, // value
916                                 0 // attributeCount
917                         );
918
919                         AssertEndDocument (xmlReader);
920                 }
921
922                 public void TestEmptyElementInNamespace ()
923                 {
924                         string xml = @"<foo:bar xmlns:foo='http://foo/' />";
925                         XmlReader xmlReader =
926                                 new XmlTextReader (new StringReader (xml));
927
928                         AssertStartDocument (xmlReader);
929
930                         AssertNode (
931                                 xmlReader, // xmlReader
932                                 XmlNodeType.Element, // nodeType
933                                 0, // depth
934                                 true, // isEmptyElement
935                                 "foo:bar", // name
936                                 "foo", // prefix
937                                 "bar", // localName
938                                 "http://foo/", // namespaceURI
939                                 String.Empty, // value
940                                 1 // attributeCount
941                         );
942
943                         AssertAttribute (
944                                 xmlReader, // xmlReader
945                                 "xmlns:foo", // name
946                                 "xmlns", // prefix
947                                 "foo", // localName
948                                 "http://www.w3.org/2000/xmlns/", // namespaceURI
949                                 "http://foo/" // value
950                         );
951
952                         AssertEquals ("http://foo/", xmlReader.LookupNamespace ("foo"));
953
954                         AssertEndDocument (xmlReader);
955                 }
956
957                 public void TestEmptyElementInDefaultNamespace ()
958                 {
959                         string xml = @"<foo xmlns='http://foo/' />";
960                         XmlReader xmlReader =
961                                 new XmlTextReader (new StringReader (xml));
962
963                         AssertStartDocument (xmlReader);
964
965                         AssertNode (
966                                 xmlReader, // xmlReader
967                                 XmlNodeType.Element, // nodeType
968                                 0, // depth
969                                 true, // isEmptyElement
970                                 "foo", // name
971                                 String.Empty, // prefix
972                                 "foo", // localName
973                                 "http://foo/", // namespaceURI
974                                 String.Empty, // value
975                                 1 // attributeCount
976                         );
977
978                         AssertAttribute (
979                                 xmlReader, // xmlReader
980                                 "xmlns", // name
981                                 String.Empty, // prefix
982                                 "xmlns", // localName
983                                 "http://www.w3.org/2000/xmlns/", // namespaceURI
984                                 "http://foo/" // value
985                         );
986
987                         AssertEquals ("http://foo/", xmlReader.LookupNamespace (String.Empty));
988
989                         AssertEndDocument (xmlReader);
990                 }
991
992                 public void TestChildElementInNamespace ()
993                 {
994                         string xml = @"<foo:bar xmlns:foo='http://foo/'><baz:quux xmlns:baz='http://baz/' /></foo:bar>";
995                         XmlReader xmlReader =
996                                 new XmlTextReader (new StringReader (xml));
997
998                         AssertStartDocument (xmlReader);
999
1000                         AssertNode (
1001                                 xmlReader, // xmlReader
1002                                 XmlNodeType.Element, // nodeType
1003                                 0, // depth
1004                                 false, // isEmptyElement
1005                                 "foo:bar", // name
1006                                 "foo", // prefix
1007                                 "bar", // localName
1008                                 "http://foo/", // namespaceURI
1009                                 String.Empty, // value
1010                                 1 // attributeCount
1011                         );
1012
1013                         AssertAttribute (
1014                                 xmlReader, // xmlReader
1015                                 "xmlns:foo", // name
1016                                 "xmlns", // prefix
1017                                 "foo", // localName
1018                                 "http://www.w3.org/2000/xmlns/", // namespaceURI
1019                                 "http://foo/" // value
1020                         );
1021
1022                         AssertEquals ("http://foo/", xmlReader.LookupNamespace ("foo"));
1023
1024                         AssertNode (
1025                                 xmlReader, // xmlReader
1026                                 XmlNodeType.Element, // nodeType
1027                                 1, // depth
1028                                 true, // isEmptyElement
1029                                 "baz:quux", // name
1030                                 "baz", // prefix
1031                                 "quux", // localName
1032                                 "http://baz/", // namespaceURI
1033                                 String.Empty, // value
1034                                 1 // attributeCount
1035                         );
1036
1037                         AssertAttribute (
1038                                 xmlReader, // xmlReader
1039                                 "xmlns:baz", // name
1040                                 "xmlns", // prefix
1041                                 "baz", // localName
1042                                 "http://www.w3.org/2000/xmlns/", // namespaceURI
1043                                 "http://baz/" // value
1044                         );
1045
1046                         AssertEquals ("http://foo/", xmlReader.LookupNamespace ("foo"));
1047                         AssertEquals ("http://baz/", xmlReader.LookupNamespace ("baz"));
1048
1049                         AssertNode (
1050                                 xmlReader, // xmlReader
1051                                 XmlNodeType.EndElement, // nodeType
1052                                 0, // depth
1053                                 false, // isEmptyElement
1054                                 "foo:bar", // name
1055                                 "foo", // prefix
1056                                 "bar", // localName
1057                                 "http://foo/", // namespaceURI
1058                                 String.Empty, // value
1059                                 0 // attributeCount
1060                         );
1061
1062                         AssertEquals ("http://foo/", xmlReader.LookupNamespace ("foo"));
1063                         AssertNull (xmlReader.LookupNamespace ("baz"));
1064
1065                         AssertEndDocument (xmlReader);
1066                 }
1067
1068                 public void TestChildElementInDefaultNamespace ()
1069                 {
1070                         string xml = @"<foo:bar xmlns:foo='http://foo/'><baz xmlns='http://baz/' /></foo:bar>";
1071                         XmlReader xmlReader =
1072                                 new XmlTextReader (new StringReader (xml));
1073
1074                         AssertStartDocument (xmlReader);
1075
1076                         AssertNode (
1077                                 xmlReader, // xmlReader
1078                                 XmlNodeType.Element, // nodeType
1079                                 0, // depth
1080                                 false, // isEmptyElement
1081                                 "foo:bar", // name
1082                                 "foo", // prefix
1083                                 "bar", // localName
1084                                 "http://foo/", // namespaceURI
1085                                 String.Empty, // value
1086                                 1 // attributeCount
1087                         );
1088
1089                         AssertAttribute (
1090                                 xmlReader, // xmlReader
1091                                 "xmlns:foo", // name
1092                                 "xmlns", // prefix
1093                                 "foo", // localName
1094                                 "http://www.w3.org/2000/xmlns/", // namespaceURI
1095                                 "http://foo/" // value
1096                         );
1097
1098                         AssertEquals ("http://foo/", xmlReader.LookupNamespace ("foo"));
1099
1100                         AssertNode (
1101                                 xmlReader, // xmlReader
1102                                 XmlNodeType.Element, // nodeType
1103                                 1, // depth
1104                                 true, // isEmptyElement
1105                                 "baz", // name
1106                                 String.Empty, // prefix
1107                                 "baz", // localName
1108                                 "http://baz/", // namespaceURI
1109                                 String.Empty, // value
1110                                 1 // attributeCount
1111                         );
1112
1113                         AssertAttribute (
1114                                 xmlReader, // xmlReader
1115                                 "xmlns", // name
1116                                 String.Empty, // prefix
1117                                 "xmlns", // localName
1118                                 "http://www.w3.org/2000/xmlns/", // namespaceURI
1119                                 "http://baz/" // value
1120                         );
1121
1122                         AssertEquals ("http://foo/", xmlReader.LookupNamespace ("foo"));
1123                         AssertEquals ("http://baz/", xmlReader.LookupNamespace (String.Empty));
1124
1125                         AssertNode (
1126                                 xmlReader, // xmlReader
1127                                 XmlNodeType.EndElement, // nodeType
1128                                 0, // depth
1129                                 false, // isEmptyElement
1130                                 "foo:bar", // name
1131                                 "foo", // prefix
1132                                 "bar", // localName
1133                                 "http://foo/", // namespaceURI
1134                                 String.Empty, // value
1135                                 0 // attributeCount
1136                         );
1137
1138                         AssertEquals ("http://foo/", xmlReader.LookupNamespace ("foo"));
1139
1140                         AssertEndDocument (xmlReader);
1141                 }
1142
1143                 public void TestAttributeInNamespace ()
1144                 {
1145                         string xml = @"<foo bar:baz='quux' xmlns:bar='http://bar/' />";
1146                         XmlReader xmlReader =
1147                                 new XmlTextReader (new StringReader (xml));
1148
1149                         AssertStartDocument (xmlReader);
1150
1151                         AssertNode (
1152                                 xmlReader, // xmlReader
1153                                 XmlNodeType.Element, // nodeType
1154                                 0, // depth
1155                                 true, // isEmptyElement
1156                                 "foo", // name
1157                                 String.Empty, // prefix
1158                                 "foo", // localName
1159                                 String.Empty, // namespaceURI
1160                                 String.Empty, // value
1161                                 2 // attributeCount
1162                         );
1163
1164                         AssertAttribute (
1165                                 xmlReader, // xmlReader
1166                                 "bar:baz", // name
1167                                 "bar", // prefix
1168                                 "baz", // localName
1169                                 "http://bar/", // namespaceURI
1170                                 "quux" // value
1171                         );
1172
1173                         AssertAttribute (
1174                                 xmlReader, // xmlReader
1175                                 "xmlns:bar", // name
1176                                 "xmlns", // prefix
1177                                 "bar", // localName
1178                                 "http://www.w3.org/2000/xmlns/", // namespaceURI
1179                                 "http://bar/" // value
1180                         );
1181
1182                         AssertEquals ("http://bar/", xmlReader.LookupNamespace ("bar"));
1183
1184                         AssertEndDocument (xmlReader);
1185                 }
1186
1187 // The following is #if'ed out because it's specific to the Mono
1188 // implementation and won't compile when testing Microsoft's code.
1189 // Feel free to turn it on if you want to test Mono's name tables.
1190
1191 #if false
1192
1193                 public void TestIsFirstNameChar ()
1194                 {
1195                         for (int ch = 0; ch <= 0xFFFF; ++ch) {
1196                                 Assert (
1197                                         XmlChar.IsFirstNameChar (ch) ==
1198                                                 IsFirstNameChar (ch));
1199                         }
1200                 }
1201
1202                 public void TestIsNameChar ()
1203                 {
1204                         for (int ch = 0; ch <= 0xFFFF; ++ch) {
1205                                 Assert (
1206                                         XmlChar.IsNameChar (ch) ==
1207                                                 IsNameChar (ch));
1208                         }
1209                 }
1210
1211                 private static bool IsFirstNameChar (int ch)
1212                 {
1213                         return
1214                                 IsLetter (ch) ||
1215                                 (ch == '_') ||
1216                                 (ch == ':');
1217                 }
1218
1219                 private static bool IsNameChar (int ch)
1220                 {
1221                         return
1222                                 IsLetter (ch) ||
1223                                 IsDigit (ch) ||
1224                                 (ch == '.') ||
1225                                 (ch == '-') ||
1226                                 (ch == '_') ||
1227                                 (ch == ':') ||
1228                                 IsCombiningChar (ch) ||
1229                                 IsExtender (ch);
1230                 }
1231
1232                 private static bool IsLetter (int ch)
1233                 {
1234                         return
1235                                 IsBaseChar (ch) ||
1236                                 IsIdeographic (ch);
1237                 }
1238
1239                 private static bool IsBaseChar (int ch)
1240                 {
1241                         return
1242                                 (ch >= 0x0041 && ch <= 0x005A) ||
1243                                 (ch >= 0x0061 && ch <= 0x007A) ||
1244                                 (ch >= 0x00C0 && ch <= 0x00D6) ||
1245                                 (ch >= 0x00D8 && ch <= 0x00F6) ||
1246                                 (ch >= 0x00F8 && ch <= 0x00FF) ||
1247                                 (ch >= 0x0100 && ch <= 0x0131) ||
1248                                 (ch >= 0x0134 && ch <= 0x013E) ||
1249                                 (ch >= 0x0141 && ch <= 0x0148) ||
1250                                 (ch >= 0x014A && ch <= 0x017E) ||
1251                                 (ch >= 0x0180 && ch <= 0x01C3) ||
1252                                 (ch >= 0x01CD && ch <= 0x01F0) ||
1253                                 (ch >= 0x01F4 && ch <= 0x01F5) ||
1254                                 (ch >= 0x01FA && ch <= 0x0217) ||
1255                                 (ch >= 0x0250 && ch <= 0x02A8) ||
1256                                 (ch >= 0x02BB && ch <= 0x02C1) ||
1257                                 (ch == 0x0386) ||
1258                                 (ch >= 0x0388 && ch <= 0x038A) ||
1259                                 (ch == 0x038C) ||
1260                                 (ch >= 0x038E && ch <= 0x03A1) ||
1261                                 (ch >= 0x03A3 && ch <= 0x03CE) ||
1262                                 (ch >= 0x03D0 && ch <= 0x03D6) ||
1263                                 (ch == 0x03DA) ||
1264                                 (ch == 0x03DC) ||
1265                                 (ch == 0x03DE) ||
1266                                 (ch == 0x03E0) ||
1267                                 (ch >= 0x03E2 && ch <= 0x03F3) ||
1268                                 (ch >= 0x0401 && ch <= 0x040C) ||
1269                                 (ch >= 0x040E && ch <= 0x044F) ||
1270                                 (ch >= 0x0451 && ch <= 0x045C) ||
1271                                 (ch >= 0x045E && ch <= 0x0481) ||
1272                                 (ch >= 0x0490 && ch <= 0x04C4) ||
1273                                 (ch >= 0x04C7 && ch <= 0x04C8) ||
1274                                 (ch >= 0x04CB && ch <= 0x04CC) ||
1275                                 (ch >= 0x04D0 && ch <= 0x04EB) ||
1276                                 (ch >= 0x04EE && ch <= 0x04F5) ||
1277                                 (ch >= 0x04F8 && ch <= 0x04F9) ||
1278                                 (ch >= 0x0531 && ch <= 0x0556) ||
1279                                 (ch == 0x0559) ||
1280                                 (ch >= 0x0561 && ch <= 0x0586) ||
1281                                 (ch >= 0x05D0 && ch <= 0x05EA) ||
1282                                 (ch >= 0x05F0 && ch <= 0x05F2) ||
1283                                 (ch >= 0x0621 && ch <= 0x063A) ||
1284                                 (ch >= 0x0641 && ch <= 0x064A) ||
1285                                 (ch >= 0x0671 && ch <= 0x06B7) ||
1286                                 (ch >= 0x06BA && ch <= 0x06BE) ||
1287                                 (ch >= 0x06C0 && ch <= 0x06CE) ||
1288                                 (ch >= 0x06D0 && ch <= 0x06D3) ||
1289                                 (ch == 0x06D5) ||
1290                                 (ch >= 0x06E5 && ch <= 0x06E6) ||
1291                                 (ch >= 0x0905 && ch <= 0x0939) ||
1292                                 (ch == 0x093D) ||
1293                                 (ch >= 0x0958 && ch <= 0x0961) ||
1294                                 (ch >= 0x0985 && ch <= 0x098C) ||
1295                                 (ch >= 0x098F && ch <= 0x0990) ||
1296                                 (ch >= 0x0993 && ch <= 0x09A8) ||
1297                                 (ch >= 0x09AA && ch <= 0x09B0) ||
1298                                 (ch == 0x09B2) ||
1299                                 (ch >= 0x09B6 && ch <= 0x09B9) ||
1300                                 (ch >= 0x09DC && ch <= 0x09DD) ||
1301                                 (ch >= 0x09DF && ch <= 0x09E1) ||
1302                                 (ch >= 0x09F0 && ch <= 0x09F1) ||
1303                                 (ch >= 0x0A05 && ch <= 0x0A0A) ||
1304                                 (ch >= 0x0A0F && ch <= 0x0A10) ||
1305                                 (ch >= 0x0A13 && ch <= 0x0A28) ||
1306                                 (ch >= 0x0A2A && ch <= 0x0A30) ||
1307                                 (ch >= 0x0A32 && ch <= 0x0A33) ||
1308                                 (ch >= 0x0A35 && ch <= 0x0A36) ||
1309                                 (ch >= 0x0A38 && ch <= 0x0A39) ||
1310                                 (ch >= 0x0A59 && ch <= 0x0A5C) ||
1311                                 (ch == 0x0A5E) ||
1312                                 (ch >= 0x0A72 && ch <= 0x0A74) ||
1313                                 (ch >= 0x0A85 && ch <= 0x0A8B) ||
1314                                 (ch == 0x0A8D) ||
1315                                 (ch >= 0x0A8F && ch <= 0x0A91) ||
1316                                 (ch >= 0x0A93 && ch <= 0x0AA8) ||
1317                                 (ch >= 0x0AAA && ch <= 0x0AB0) ||
1318                                 (ch >= 0x0AB2 && ch <= 0x0AB3) ||
1319                                 (ch >= 0x0AB5 && ch <= 0x0AB9) ||
1320                                 (ch == 0x0ABD) ||
1321                                 (ch == 0x0AE0) ||
1322                                 (ch >= 0x0B05 && ch <= 0x0B0C) ||
1323                                 (ch >= 0x0B0F && ch <= 0x0B10) ||
1324                                 (ch >= 0x0B13 && ch <= 0x0B28) ||
1325                                 (ch >= 0x0B2A && ch <= 0x0B30) ||
1326                                 (ch >= 0x0B32 && ch <= 0x0B33) ||
1327                                 (ch >= 0x0B36 && ch <= 0x0B39) ||
1328                                 (ch == 0x0B3D) ||
1329                                 (ch >= 0x0B5C && ch <= 0x0B5D) ||
1330                                 (ch >= 0x0B5F && ch <= 0x0B61) ||
1331                                 (ch >= 0x0B85 && ch <= 0x0B8A) ||
1332                                 (ch >= 0x0B8E && ch <= 0x0B90) ||
1333                                 (ch >= 0x0B92 && ch <= 0x0B95) ||
1334                                 (ch >= 0x0B99 && ch <= 0x0B9A) ||
1335                                 (ch == 0x0B9C) ||
1336                                 (ch >= 0x0B9E && ch <= 0x0B9F) ||
1337                                 (ch >= 0x0BA3 && ch <= 0x0BA4) ||
1338                                 (ch >= 0x0BA8 && ch <= 0x0BAA) ||
1339                                 (ch >= 0x0BAE && ch <= 0x0BB5) ||
1340                                 (ch >= 0x0BB7 && ch <= 0x0BB9) ||
1341                                 (ch >= 0x0C05 && ch <= 0x0C0C) ||
1342                                 (ch >= 0x0C0E && ch <= 0x0C10) ||
1343                                 (ch >= 0x0C12 && ch <= 0x0C28) ||
1344                                 (ch >= 0x0C2A && ch <= 0x0C33) ||
1345                                 (ch >= 0x0C35 && ch <= 0x0C39) ||
1346                                 (ch >= 0x0C60 && ch <= 0x0C61) ||
1347                                 (ch >= 0x0C85 && ch <= 0x0C8C) ||
1348                                 (ch >= 0x0C8E && ch <= 0x0C90) ||
1349                                 (ch >= 0x0C92 && ch <= 0x0CA8) ||
1350                                 (ch >= 0x0CAA && ch <= 0x0CB3) ||
1351                                 (ch >= 0x0CB5 && ch <= 0x0CB9) ||
1352                                 (ch == 0x0CDE) ||
1353                                 (ch >= 0x0CE0 && ch <= 0x0CE1) ||
1354                                 (ch >= 0x0D05 && ch <= 0x0D0C) ||
1355                                 (ch >= 0x0D0E && ch <= 0x0D10) ||
1356                                 (ch >= 0x0D12 && ch <= 0x0D28) ||
1357                                 (ch >= 0x0D2A && ch <= 0x0D39) ||
1358                                 (ch >= 0x0D60 && ch <= 0x0D61) ||
1359                                 (ch >= 0x0E01 && ch <= 0x0E2E) ||
1360                                 (ch == 0x0E30) ||
1361                                 (ch >= 0x0E32 && ch <= 0x0E33) ||
1362                                 (ch >= 0x0E40 && ch <= 0x0E45) ||
1363                                 (ch >= 0x0E81 && ch <= 0x0E82) ||
1364                                 (ch == 0x0E84) ||
1365                                 (ch >= 0x0E87 && ch <= 0x0E88) ||
1366                                 (ch == 0x0E8A) ||
1367                                 (ch == 0x0E8D) ||
1368                                 (ch >= 0x0E94 && ch <= 0x0E97) ||
1369                                 (ch >= 0x0E99 && ch <= 0x0E9F) ||
1370                                 (ch >= 0x0EA1 && ch <= 0x0EA3) ||
1371                                 (ch == 0x0EA5) ||
1372                                 (ch == 0x0EA7) ||
1373                                 (ch >= 0x0EAA && ch <= 0x0EAB) ||
1374                                 (ch >= 0x0EAD && ch <= 0x0EAE) ||
1375                                 (ch == 0x0EB0) ||
1376                                 (ch >= 0x0EB2 && ch <= 0x0EB3) ||
1377                                 (ch == 0x0EBD) ||
1378                                 (ch >= 0x0EC0 && ch <= 0x0EC4) ||
1379                                 (ch >= 0x0F40 && ch <= 0x0F47) ||
1380                                 (ch >= 0x0F49 && ch <= 0x0F69) ||
1381                                 (ch >= 0x10A0 && ch <= 0x10C5) ||
1382                                 (ch >= 0x10D0 && ch <= 0x10F6) ||
1383                                 (ch == 0x1100) ||
1384                                 (ch >= 0x1102 && ch <= 0x1103) ||
1385                                 (ch >= 0x1105 && ch <= 0x1107) ||
1386                                 (ch == 0x1109) ||
1387                                 (ch >= 0x110B && ch <= 0x110C) ||
1388                                 (ch >= 0x110E && ch <= 0x1112) ||
1389                                 (ch == 0x113C) ||
1390                                 (ch == 0x113E) ||
1391                                 (ch == 0x1140) ||
1392                                 (ch == 0x114C) ||
1393                                 (ch == 0x114E) ||
1394                                 (ch == 0x1150) ||
1395                                 (ch >= 0x1154 && ch <= 0x1155) ||
1396                                 (ch == 0x1159) ||
1397                                 (ch >= 0x115F && ch <= 0x1161) ||
1398                                 (ch == 0x1163) ||
1399                                 (ch == 0x1165) ||
1400                                 (ch == 0x1167) ||
1401                                 (ch == 0x1169) ||
1402                                 (ch >= 0x116D && ch <= 0x116E) ||
1403                                 (ch >= 0x1172 && ch <= 0x1173) ||
1404                                 (ch == 0x1175) ||
1405                                 (ch == 0x119E) ||
1406                                 (ch == 0x11A8) ||
1407                                 (ch == 0x11AB) ||
1408                                 (ch >= 0x11AE && ch <= 0x11AF) ||
1409                                 (ch >= 0x11B7 && ch <= 0x11B8) ||
1410                                 (ch == 0x11BA) ||
1411                                 (ch >= 0x11BC && ch <= 0x11C2) ||
1412                                 (ch == 0x11EB) ||
1413                                 (ch == 0x11F0) ||
1414                                 (ch == 0x11F9) ||
1415                                 (ch >= 0x1E00 && ch <= 0x1E9B) ||
1416                                 (ch >= 0x1EA0 && ch <= 0x1EF9) ||
1417                                 (ch >= 0x1F00 && ch <= 0x1F15) ||
1418                                 (ch >= 0x1F18 && ch <= 0x1F1D) ||
1419                                 (ch >= 0x1F20 && ch <= 0x1F45) ||
1420                                 (ch >= 0x1F48 && ch <= 0x1F4D) ||
1421                                 (ch >= 0x1F50 && ch <= 0x1F57) ||
1422                                 (ch == 0x1F59) ||
1423                                 (ch == 0x1F5B) ||
1424                                 (ch == 0x1F5D) ||
1425                                 (ch >= 0x1F5F && ch <= 0x1F7D) ||
1426                                 (ch >= 0x1F80 && ch <= 0x1FB4) ||
1427                                 (ch >= 0x1FB6 && ch <= 0x1FBC) ||
1428                                 (ch == 0x1FBE) ||
1429                                 (ch >= 0x1FC2 && ch <= 0x1FC4) ||
1430                                 (ch >= 0x1FC6 && ch <= 0x1FCC) ||
1431                                 (ch >= 0x1FD0 && ch <= 0x1FD3) ||
1432                                 (ch >= 0x1FD6 && ch <= 0x1FDB) ||
1433                                 (ch >= 0x1FE0 && ch <= 0x1FEC) ||
1434                                 (ch >= 0x1FF2 && ch <= 0x1FF4) ||
1435                                 (ch >= 0x1FF6 && ch <= 0x1FFC) ||
1436                                 (ch == 0x2126) ||
1437                                 (ch >= 0x212A && ch <= 0x212B) ||
1438                                 (ch == 0x212E) ||
1439                                 (ch >= 0x2180 && ch <= 0x2182) ||
1440                                 (ch >= 0x3041 && ch <= 0x3094) ||
1441                                 (ch >= 0x30A1 && ch <= 0x30FA) ||
1442                                 (ch >= 0x3105 && ch <= 0x312C) ||
1443                                 (ch >= 0xAC00 && ch <= 0xD7A3);
1444                 }
1445
1446                 private static bool IsIdeographic (int ch)
1447                 {
1448                         return
1449                                 (ch >= 0x4E00 && ch <= 0x9FA5) ||
1450                                 (ch == 0x3007) ||
1451                                 (ch >= 0x3021 && ch <= 0x3029);
1452                 }
1453
1454                 private static bool IsDigit (int ch)
1455                 {
1456                         return
1457                                 (ch >= 0x0030 && ch <= 0x0039) ||
1458                                 (ch >= 0x0660 && ch <= 0x0669) ||
1459                                 (ch >= 0x06F0 && ch <= 0x06F9) ||
1460                                 (ch >= 0x0966 && ch <= 0x096F) ||
1461                                 (ch >= 0x09E6 && ch <= 0x09EF) ||
1462                                 (ch >= 0x0A66 && ch <= 0x0A6F) ||
1463                                 (ch >= 0x0AE6 && ch <= 0x0AEF) ||
1464                                 (ch >= 0x0B66 && ch <= 0x0B6F) ||
1465                                 (ch >= 0x0BE7 && ch <= 0x0BEF) ||
1466                                 (ch >= 0x0C66 && ch <= 0x0C6F) ||
1467                                 (ch >= 0x0CE6 && ch <= 0x0CEF) ||
1468                                 (ch >= 0x0D66 && ch <= 0x0D6F) ||
1469                                 (ch >= 0x0E50 && ch <= 0x0E59) ||
1470                                 (ch >= 0x0ED0 && ch <= 0x0ED9) ||
1471                                 (ch >= 0x0F20 && ch <= 0x0F29);
1472                 }
1473
1474                 private static bool IsCombiningChar (int ch)
1475                 {
1476                         return
1477                                 (ch >= 0x0300 && ch <= 0x0345) ||
1478                                 (ch >= 0x0360 && ch <= 0x0361) ||
1479                                 (ch >= 0x0483 && ch <= 0x0486) ||
1480                                 (ch >= 0x0591 && ch <= 0x05A1) ||
1481                                 (ch >= 0x05A3 && ch <= 0x05B9) ||
1482                                 (ch >= 0x05BB && ch <= 0x05BD) ||
1483                                 (ch == 0x05BF) ||
1484                                 (ch >= 0x05C1 && ch <= 0x05C2) ||
1485                                 (ch == 0x05C4) ||
1486                                 (ch >= 0x064B && ch <= 0x0652) ||
1487                                 (ch == 0x0670) ||
1488                                 (ch >= 0x06D6 && ch <= 0x06DC) ||
1489                                 (ch >= 0x06DD && ch <= 0x06DF) ||
1490                                 (ch >= 0x06E0 && ch <= 0x06E4) ||
1491                                 (ch >= 0x06E7 && ch <= 0x06E8) ||
1492                                 (ch >= 0x06EA && ch <= 0x06ED) ||
1493                                 (ch >= 0x0901 && ch <= 0x0903) ||
1494                                 (ch == 0x093C) ||
1495                                 (ch >= 0x093E && ch <= 0x094C) ||
1496                                 (ch == 0x094D) ||
1497                                 (ch >= 0x0951 && ch <= 0x0954) ||
1498                                 (ch >= 0x0962 && ch <= 0x0963) ||
1499                                 (ch >= 0x0981 && ch <= 0x0983) ||
1500                                 (ch == 0x09BC) ||
1501                                 (ch == 0x09BE) ||
1502                                 (ch == 0x09BF) ||
1503                                 (ch >= 0x09C0 && ch <= 0x09C4) ||
1504                                 (ch >= 0x09C7 && ch <= 0x09C8) ||
1505                                 (ch >= 0x09CB && ch <= 0x09CD) ||
1506                                 (ch == 0x09D7) ||
1507                                 (ch >= 0x09E2 && ch <= 0x09E3) ||
1508                                 (ch == 0x0A02) ||
1509                                 (ch == 0x0A3C) ||
1510                                 (ch == 0x0A3E) ||
1511                                 (ch == 0x0A3F) ||
1512                                 (ch >= 0x0A40 && ch <= 0x0A42) ||
1513                                 (ch >= 0x0A47 && ch <= 0x0A48) ||
1514                                 (ch >= 0x0A4B && ch <= 0x0A4D) ||
1515                                 (ch >= 0x0A70 && ch <= 0x0A71) ||
1516                                 (ch >= 0x0A81 && ch <= 0x0A83) ||
1517                                 (ch == 0x0ABC) ||
1518                                 (ch >= 0x0ABE && ch <= 0x0AC5) ||
1519                                 (ch >= 0x0AC7 && ch <= 0x0AC9) ||
1520                                 (ch >= 0x0ACB && ch <= 0x0ACD) ||
1521                                 (ch >= 0x0B01 && ch <= 0x0B03) ||
1522                                 (ch == 0x0B3C) ||
1523                                 (ch >= 0x0B3E && ch <= 0x0B43) ||
1524                                 (ch >= 0x0B47 && ch <= 0x0B48) ||
1525                                 (ch >= 0x0B4B && ch <= 0x0B4D) ||
1526                                 (ch >= 0x0B56 && ch <= 0x0B57) ||
1527                                 (ch >= 0x0B82 && ch <= 0x0B83) ||
1528                                 (ch >= 0x0BBE && ch <= 0x0BC2) ||
1529                                 (ch >= 0x0BC6 && ch <= 0x0BC8) ||
1530                                 (ch >= 0x0BCA && ch <= 0x0BCD) ||
1531                                 (ch == 0x0BD7) ||
1532                                 (ch >= 0x0C01 && ch <= 0x0C03) ||
1533                                 (ch >= 0x0C3E && ch <= 0x0C44) ||
1534                                 (ch >= 0x0C46 && ch <= 0x0C48) ||
1535                                 (ch >= 0x0C4A && ch <= 0x0C4D) ||
1536                                 (ch >= 0x0C55 && ch <= 0x0C56) ||
1537                                 (ch >= 0x0C82 && ch <= 0x0C83) ||
1538                                 (ch >= 0x0CBE && ch <= 0x0CC4) ||
1539                                 (ch >= 0x0CC6 && ch <= 0x0CC8) ||
1540                                 (ch >= 0x0CCA && ch <= 0x0CCD) ||
1541                                 (ch >= 0x0CD5 && ch <= 0x0CD6) ||
1542                                 (ch >= 0x0D02 && ch <= 0x0D03) ||
1543                                 (ch >= 0x0D3E && ch <= 0x0D43) ||
1544                                 (ch >= 0x0D46 && ch <= 0x0D48) ||
1545                                 (ch >= 0x0D4A && ch <= 0x0D4D) ||
1546                                 (ch == 0x0D57) ||
1547                                 (ch == 0x0E31) ||
1548                                 (ch >= 0x0E34 && ch <= 0x0E3A) ||
1549                                 (ch >= 0x0E47 && ch <= 0x0E4E) ||
1550                                 (ch == 0x0EB1) ||
1551                                 (ch >= 0x0EB4 && ch <= 0x0EB9) ||
1552                                 (ch >= 0x0EBB && ch <= 0x0EBC) ||
1553                                 (ch >= 0x0EC8 && ch <= 0x0ECD) ||
1554                                 (ch >= 0x0F18 && ch <= 0x0F19) ||
1555                                 (ch == 0x0F35) ||
1556                                 (ch == 0x0F37) ||
1557                                 (ch == 0x0F39) ||
1558                                 (ch == 0x0F3E) ||
1559                                 (ch == 0x0F3F) ||
1560                                 (ch >= 0x0F71 && ch <= 0x0F84) ||
1561                                 (ch >= 0x0F86 && ch <= 0x0F8B) ||
1562                                 (ch >= 0x0F90 && ch <= 0x0F95) ||
1563                                 (ch == 0x0F97) ||
1564                                 (ch >= 0x0F99 && ch <= 0x0FAD) ||
1565                                 (ch >= 0x0FB1 && ch <= 0x0FB7) ||
1566                                 (ch == 0x0FB9) ||
1567                                 (ch >= 0x20D0 && ch <= 0x20DC) ||
1568                                 (ch == 0x20E1) ||
1569                                 (ch >= 0x302A && ch <= 0x302F) ||
1570                                 (ch == 0x3099) ||
1571                                 (ch == 0x309A);
1572                 }
1573
1574                 private static bool IsExtender (int ch)
1575                 {
1576                         return
1577                                 (ch == 0x00B7) ||
1578                                 (ch == 0x02D0) ||
1579                                 (ch == 0x02D1) ||
1580                                 (ch == 0x0387) ||
1581                                 (ch == 0x0640) ||
1582                                 (ch == 0x0E46) ||
1583                                 (ch == 0x0EC6) ||
1584                                 (ch == 0x3005) ||
1585                                 (ch >= 0x3031 && ch <= 0x3035) ||
1586                                 (ch >= 0x309D && ch <= 0x309E) ||
1587                                 (ch >= 0x30FC && ch <= 0x30FE);
1588                 }
1589
1590 #endif
1591
1592                 public void TestIsName ()
1593                 {
1594                         Assert (XmlReader.IsName ("foo"));
1595                         Assert (!XmlReader.IsName ("1foo"));
1596                         Assert (!XmlReader.IsName (" foo"));
1597                 }
1598
1599                 public void TestIsNameToken ()
1600                 {
1601                         Assert (XmlReader.IsNameToken ("foo"));
1602                         Assert (XmlReader.IsNameToken ("1foo"));
1603                         Assert (!XmlReader.IsNameToken (" foo"));
1604                 }
1605
1606                 public void TestMoveToElementFromAttribute ()
1607                 {
1608                         string xml = @"<foo bar=""baz"" />";
1609                         XmlReader xmlReader =
1610                                 new XmlTextReader (new StringReader (xml));
1611
1612                         Assert (xmlReader.Read ());
1613                         AssertEquals (XmlNodeType.Element, xmlReader.NodeType);
1614                         Assert (xmlReader.MoveToFirstAttribute ());
1615                         AssertEquals (XmlNodeType.Attribute, xmlReader.NodeType);
1616                         Assert (xmlReader.MoveToElement ());
1617                         AssertEquals (XmlNodeType.Element, xmlReader.NodeType);
1618                 }
1619
1620                 public void TestMoveToElementFromElement ()
1621                 {
1622                         string xml = @"<foo bar=""baz"" />";
1623                         XmlReader xmlReader =
1624                                 new XmlTextReader (new StringReader (xml));
1625
1626                         Assert (xmlReader.Read ());
1627                         AssertEquals (XmlNodeType.Element, xmlReader.NodeType);
1628                         Assert (!xmlReader.MoveToElement ());
1629                         AssertEquals (XmlNodeType.Element, xmlReader.NodeType);
1630                 }
1631
1632                 public void TestMoveToFirstAttributeWithNoAttributes ()
1633                 {
1634                         string xml = @"<foo />";
1635                         XmlReader xmlReader =
1636                                 new XmlTextReader (new StringReader (xml));
1637
1638                         Assert (xmlReader.Read ());
1639                         AssertEquals (XmlNodeType.Element, xmlReader.NodeType);
1640                         Assert (!xmlReader.MoveToFirstAttribute ());
1641                         AssertEquals (XmlNodeType.Element, xmlReader.NodeType);
1642                 }
1643
1644                 public void TestMoveToNextAttributeWithNoAttributes ()
1645                 {
1646                         string xml = @"<foo />";
1647                         XmlReader xmlReader =
1648                                 new XmlTextReader (new StringReader (xml));
1649
1650                         Assert (xmlReader.Read ());
1651                         AssertEquals (XmlNodeType.Element, xmlReader.NodeType);
1652                         Assert (!xmlReader.MoveToNextAttribute ());
1653                         AssertEquals (XmlNodeType.Element, xmlReader.NodeType);
1654                 }
1655
1656                 public void TestMoveToNextAttribute()
1657                 {
1658                         string xml = @"<foo bar=""baz"" quux='quuux'/>";
1659                         XmlReader xmlReader =
1660                                 new XmlTextReader (new StringReader (xml));
1661
1662                         AssertStartDocument (xmlReader);
1663
1664                         AssertNode (
1665                                 xmlReader, // xmlReader
1666                                 XmlNodeType.Element, // nodeType
1667                                 0, //depth
1668                                 true, // isEmptyElement
1669                                 "foo", // name
1670                                 String.Empty, // prefix
1671                                 "foo", // localName
1672                                 String.Empty, // namespaceURI
1673                                 String.Empty, // value
1674                                 2 // attributeCount
1675                         );
1676
1677                         AssertAttribute (
1678                                 xmlReader, // xmlReader
1679                                 "bar", // name
1680                                 String.Empty, // prefix
1681                                 "bar", // localName
1682                                 String.Empty, // namespaceURI
1683                                 "baz" // value
1684                         );
1685
1686                         AssertAttribute (
1687                                 xmlReader, // xmlReader
1688                                 "quux", // name
1689                                 String.Empty, // prefix
1690                                 "quux", // localName
1691                                 String.Empty, // namespaceURI
1692                                 "quuux" // value
1693                         );
1694
1695                         Assert (xmlReader.MoveToNextAttribute ());
1696                         Assert ("bar" == xmlReader.Name || "quux" == xmlReader.Name);
1697                         Assert ("baz" == xmlReader.Value || "quuux" == xmlReader.Value);
1698
1699                         Assert (xmlReader.MoveToNextAttribute ());
1700                         Assert ("bar" == xmlReader.Name || "quux" == xmlReader.Name);
1701                         Assert ("baz" == xmlReader.Value || "quuux" == xmlReader.Value);
1702
1703                         Assert (!xmlReader.MoveToNextAttribute ());
1704
1705             Assert (xmlReader.MoveToElement ());
1706
1707                         AssertNodeValues (
1708                                 xmlReader, // xmlReader
1709                                 XmlNodeType.Element, // nodeType
1710                                 0, //depth
1711                                 true, // isEmptyElement
1712                                 "foo", // name
1713                                 String.Empty, // prefix
1714                                 "foo", // localName
1715                                 String.Empty, // namespaceURI
1716                                 String.Empty, // value
1717                                 2 // attributeCount
1718                         );
1719
1720                         AssertEndDocument (xmlReader);
1721                 }
1722
1723                 public void TestAttributeOrder ()
1724                 {
1725                         string xml = @"<foo _1='1' _2='2' _3='3' />";
1726                         XmlReader xmlReader =
1727                                 new XmlTextReader (new StringReader (xml));
1728
1729                         Assert (xmlReader.Read ());
1730                         AssertEquals (XmlNodeType.Element, xmlReader.NodeType);
1731
1732                         Assert (xmlReader.MoveToFirstAttribute ());
1733                         AssertEquals ("_1", xmlReader.Name);
1734                         Assert (xmlReader.MoveToNextAttribute ());
1735                         AssertEquals ("_2", xmlReader.Name);
1736                         Assert (xmlReader.MoveToNextAttribute ());
1737                         AssertEquals ("_3", xmlReader.Name);
1738
1739                         Assert (!xmlReader.MoveToNextAttribute ());
1740                 }
1741
1742                 public void TestFragmentConstructor()
1743                 {
1744                         XmlDocument doc = new XmlDocument();
1745 //                      doc.LoadXml("<root/>");
1746
1747                         string xml = @"<foo><bar xmlns=""NSURI"">TEXT NODE</bar></foo>";
1748                         MemoryStream ms = new MemoryStream(Encoding.Default.GetBytes(xml));
1749
1750                         XmlParserContext ctx = new XmlParserContext(doc.NameTable, new XmlNamespaceManager(doc.NameTable), "", "", "", "",
1751                                 doc.BaseURI, "", XmlSpace.Default, Encoding.Default);
1752
1753                         XmlTextReader xmlReader = new XmlTextReader(ms, XmlNodeType.Element, ctx);
1754                         AssertNode(xmlReader, XmlNodeType.Element, 0, false, "foo", "", "foo", "", "", 0);
1755
1756                         AssertNode(xmlReader, XmlNodeType.Element, 1, false, "bar", "", "bar", "NSURI", "", 1);
1757
1758                         AssertNode(xmlReader, XmlNodeType.Text, 2, false, "", "", "", "NSURI", "TEXT NODE", 0);
1759
1760                         AssertNode(xmlReader, XmlNodeType.EndElement, 1, false, "bar", "", "bar", "NSURI", "", 0);
1761
1762                         AssertNode(xmlReader, XmlNodeType.EndElement, 0, false, "foo", "", "foo", "", "", 0);
1763
1764                         AssertEndDocument (xmlReader);
1765                 }
1766
1767                 public void TestAttributeWithEntityReference ()
1768                 {
1769                         string xml = @"<a value='hello &amp; world' />";
1770                         XmlReader xmlReader =
1771                                 new XmlTextReader (new StringReader (xml));
1772                         xmlReader.Read ();
1773                         AssertEquals ("hello & world", xmlReader ["value"]);
1774                 }
1775         }
1776 }