Merge pull request #916 from akoeplinger/fix-gac-test
[mono.git] / mcs / class / System.XML / Test / System.Xml.Schema / XmlSchemaBuiltInDatatypeTests.cs
1 //\r
2 // Tests for the properties of the builtin types.\r
3 // \r
4 // Author:\r
5 //   David Sheldon <dave-mono@earth.li>\r
6 //\r
7 //\r
8 \r
9 using System;\r
10 using System.Xml;\r
11 using System.Xml.Schema;\r
12 using System.IO;\r
13 using NUnit.Framework;\r
14 \r
15 namespace MonoTests.System.Xml\r
16 {\r
17         [TestFixture]\r
18         public class XmlSchemaBuiltInDatatypeTests\r
19         {\r
20 \r
21     [Test]\r
22     public void TestWhiteSpaceCollapse () {\r
23        WhiteSpaceTest("date", "2003-10-10");\r
24        WhiteSpaceTest("decimal", "2003.10");\r
25        WhiteSpaceTest("integer", "0004");\r
26        WhiteSpaceTest("float", "1.3");\r
27        WhiteSpaceTest("boolean", "true");\r
28        WhiteSpaceTest("double", "2.3");\r
29        WhiteSpaceTest("time", "12:34:56");\r
30        WhiteSpaceTest("duration", "P1347Y");\r
31        WhiteSpaceTest("dateTime", "2003-10-10T12:34:56.78");\r
32        WhiteSpaceTest("gYearMonth", "2003-10");\r
33        WhiteSpaceTest("gYear", "2003");\r
34        WhiteSpaceTest("gMonthDay", "--12-12");  // \r
35        WhiteSpaceTest("gMonth", "--12--");      //  These three will fail, due to \r
36        WhiteSpaceTest("gDay", "---12");         //  bug 52274\r
37        WhiteSpaceTest("hexBinary", "0fB7");\r
38     }\r
39 \r
40 \r
41     /* Takes a type name, and a valid example of that type, \r
42        Creates a schema consisting of a single element of that\r
43        type, and validates a bit of xml containing the valid \r
44        value, with whitespace against that schema.\r
45      \r
46 FIXME: Really we want to test the value of whitespace more\r
47        directly that by creating a schema then parsing a string.\r
48      \r
49      */\r
50 \r
51     public void WhiteSpaceTest(string type, string valid) {\r
52       passed = true;\r
53       XmlSchema schema = new XmlSchema();\r
54 \r
55       schema.TargetNamespace= "http://example.com/testCase";\r
56       XmlSchemaElement element = new XmlSchemaElement();\r
57       element.Name = "a";\r
58       element.SchemaTypeName = new XmlQualifiedName(type, "http://www.w3.org/2001/XMLSchema");\r
59       schema.Items.Add(element);\r
60       schema.Compile(new ValidationEventHandler(ValidationCallbackOne));\r
61 \r
62       XmlValidatingReader vr = new XmlValidatingReader(new XmlTextReader(new StringReader("<a xmlns='http://example.com/testCase'>\n\n"+valid+"\n\n</a>" )));\r
63       vr.Schemas.Add(schema);\r
64       vr.ValidationType = ValidationType.Schema;\r
65 //      vr.ValidationEventHandler += new ValidationEventHandler(ValidationCallbackOne);\r
66       while(vr.Read()) { };\r
67       vr.Close();\r
68       \r
69       Assert.IsTrue (passed, type + " doesn't collapse whitespace: " + (errorInfo != null ? errorInfo.Message : null));\r
70     }\r
71 \r
72     bool passed = true;\r
73     ValidationEventArgs errorInfo;\r
74 \r
75     public void ValidationCallbackOne(object sender, ValidationEventArgs args) {\r
76       passed = false;\r
77       errorInfo = args;\r
78     }\r
79 \r
80 \r
81   }  \r
82 }\r