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