File: XmlSchemaBuiltInDatatypeTests.cs

package info (click to toggle)
mono 4.6.2.7+dfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 778,148 kB
  • ctags: 914,052
  • sloc: cs: 5,779,509; xml: 2,773,713; ansic: 432,645; sh: 14,749; makefile: 12,361; perl: 2,488; python: 1,434; cpp: 849; asm: 531; sql: 95; sed: 16; php: 1
file content (82 lines) | stat: -rw-r--r-- 2,663 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
//
// Tests for the properties of the builtin types.
// 
// Author:
//   David Sheldon <dave-mono@earth.li>
//
//

using System;
using System.Xml;
using System.Xml.Schema;
using System.IO;
using NUnit.Framework;

namespace MonoTests.System.Xml
{
	[TestFixture]
	public class XmlSchemaBuiltInDatatypeTests
	{

    [Test]
    public void TestWhiteSpaceCollapse () {
       WhiteSpaceTest("date", "2003-10-10");
       WhiteSpaceTest("decimal", "2003.10");
       WhiteSpaceTest("integer", "0004");
       WhiteSpaceTest("float", "1.3");
       WhiteSpaceTest("boolean", "true");
       WhiteSpaceTest("double", "2.3");
       WhiteSpaceTest("time", "12:34:56");
       WhiteSpaceTest("duration", "P1347Y");
       WhiteSpaceTest("dateTime", "2003-10-10T12:34:56.78");
       WhiteSpaceTest("gYearMonth", "2003-10");
       WhiteSpaceTest("gYear", "2003");
       WhiteSpaceTest("gMonthDay", "--12-12");  // 
       WhiteSpaceTest("gMonth", "--12--");      //  These three will fail, due to 
       WhiteSpaceTest("gDay", "---12");         //  bug 52274
       WhiteSpaceTest("hexBinary", "0fB7");
    }


    /* Takes a type name, and a valid example of that type, 
       Creates a schema consisting of a single element of that
       type, and validates a bit of xml containing the valid 
       value, with whitespace against that schema.
     
FIXME: Really we want to test the value of whitespace more
       directly that by creating a schema then parsing a string.
     
     */

    public void WhiteSpaceTest(string type, string valid) {
      passed = true;
      XmlSchema schema = new XmlSchema();

      schema.TargetNamespace= "http://example.com/testCase";
      XmlSchemaElement element = new XmlSchemaElement();
      element.Name = "a";
      element.SchemaTypeName = new XmlQualifiedName(type, "http://www.w3.org/2001/XMLSchema");
      schema.Items.Add(element);
      schema.Compile(new ValidationEventHandler(ValidationCallbackOne));

      XmlValidatingReader vr = new XmlValidatingReader(new XmlTextReader(new StringReader("<a xmlns='http://example.com/testCase'>\n\n"+valid+"\n\n</a>" )));
      vr.Schemas.Add(schema);
      vr.ValidationType = ValidationType.Schema;
//      vr.ValidationEventHandler += new ValidationEventHandler(ValidationCallbackOne);
      while(vr.Read()) { };
      vr.Close();
      
      Assert.IsTrue (passed, type + " doesn't collapse whitespace: " + (errorInfo != null ? errorInfo.Message : null));
    }

    bool passed = true;
    ValidationEventArgs errorInfo;

    public void ValidationCallbackOne(object sender, ValidationEventArgs args) {
      passed = false;
      errorInfo = args;
    }


  }  
}