Merge pull request #5714 from alexischr/update_bockbuild
[mono.git] / mcs / class / System.XML / Test / System.Xml.Schema / XmlSchemaCollectionTests.cs
1 //
2 // System.Xml.XmlSchemaCollectionTests.cs
3 //
4 // Author:
5 //   Atsushi Enomoto <ginga@kit.hi-ho.ne.jp>
6 //
7 // (C) 2002 Atsushi Enomoto
8 //
9
10 using System;
11 using System.Globalization;
12 using System.IO;
13 using System.Xml;
14 using System.Xml.Schema;
15 using NUnit.Framework;
16
17 namespace MonoTests.System.Xml
18 {
19         [TestFixture]
20         public class XmlSchemaCollectionTests
21         {
22                 private XmlSchema GetSchema (string path)
23                 {
24                         return XmlSchema.Read (new XmlTextReader (path), null);
25                 }
26
27                 private XmlQualifiedName QName (string name, string ns)
28                 {
29                         return new XmlQualifiedName (name, ns);
30                 }
31
32                 [Test]
33                 public void TestAdd ()
34                 {
35                         XmlSchemaCollection col = new XmlSchemaCollection ();
36                         XmlSchema schema = new XmlSchema ();
37                         XmlSchemaElement elem = new XmlSchemaElement ();
38                         elem.Name = "foo";
39                         schema.Items.Add (elem);
40                         schema.TargetNamespace = "urn:foo";
41                         col.Add (schema);
42                         col.Add (schema);       // No problem !?
43
44                         XmlSchema schema2 = new XmlSchema ();
45                         schema2.Items.Add (elem);
46                         schema2.TargetNamespace = "urn:foo";
47                         col.Add (schema2);      // No problem !!
48
49                         schema.Compile (null);
50                         col.Add (schema);
51                         col.Add (schema);       // Still no problem !!!
52
53                         schema2.Compile (null);
54                         col.Add (schema2);
55
56                         schema = GetSchema ("Test/XmlFiles/xsd/3.xsd");
57                         schema.Compile (null);
58                         col.Add (schema);
59
60                         schema2 = GetSchema ("Test/XmlFiles/xsd/3.xsd");
61                         schema2.Compile (null);
62                         col.Add (schema2);
63                 }
64
65                 [Test]
66                 public void TestAddDoesCompilation ()
67                 {
68                         XmlSchema schema = new XmlSchema ();
69                         Assert.IsFalse (schema.IsCompiled);
70                         XmlSchemaCollection col = new XmlSchemaCollection ();
71                         col.Add (schema);
72                         Assert.IsTrue (schema.IsCompiled);
73                 }
74
75                 [Test] // bug #75126
76                 public void TestGetEnumerator ()
77                 {
78                         new XmlSchemaCollection().GetEnumerator();
79                 }
80
81                 [Test] // bug #78220
82                 public void TestCompile ()
83                 {
84                         string schemaFragment1 = string.Format (CultureInfo.InvariantCulture,
85                                 "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
86                                 "<xs:schema xmlns:tns=\"NSDate\" elementFormDefault=\"qualified\" targetNamespace=\"NSDate\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
87                                 "  <xs:import namespace=\"NSStatus\" />{0}" +
88                                 "  <xs:element name=\"trans\" type=\"tns:TranslationStatus\" />{0}" +
89                                 "  <xs:complexType name=\"TranslationStatus\">{0}" +
90                                 "    <xs:simpleContent>{0}" +
91                                 "      <xs:extension xmlns:q1=\"NSStatus\" base=\"q1:StatusType\">{0}" +
92                                 "        <xs:attribute name=\"Language\" type=\"xs:int\" use=\"required\" />{0}" +
93                                 "      </xs:extension>{0}" +
94                                 "    </xs:simpleContent>{0}" +
95                                 "  </xs:complexType>{0}" +
96                                 "</xs:schema>", Environment.NewLine);
97
98                         string schemaFragment2 = string.Format (CultureInfo.InvariantCulture,
99                                 "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
100                                 "<xs:schema xmlns:tns=\"NSStatus\" elementFormDefault=\"qualified\" targetNamespace=\"NSStatus\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
101                                 "  <xs:simpleType name=\"StatusType\">{0}" +
102                                 "    <xs:restriction base=\"xs:string\">{0}" +
103                                 "      <xs:enumeration value=\"Untouched\" />{0}" +
104                                 "      <xs:enumeration value=\"Touched\" />{0}" +
105                                 "      <xs:enumeration value=\"Complete\" />{0}" +
106                                 "      <xs:enumeration value=\"None\" />{0}" +
107                                 "    </xs:restriction>{0}" +
108                                 "  </xs:simpleType>{0}" +
109                                 "</xs:schema>", Environment.NewLine);
110
111                         XmlSchema schema1 = XmlSchema.Read (new StringReader (schemaFragment1), null);
112                         XmlSchema schema2 = XmlSchema.Read (new StringReader (schemaFragment2), null);
113
114                         XmlSchemaCollection schemas = new XmlSchemaCollection ();
115                         schemas.Add (schema2);
116                         schemas.Add (schema1);
117
118                         Assert.IsTrue (schema1.IsCompiled, "#1");
119                         Assert.IsTrue (schema2.IsCompiled, "#2");
120                 }
121         }
122 }