From 11781269159d554652438b47347697f432639538 Mon Sep 17 00:00:00 2001 From: Gert Driesen Date: Thu, 29 Dec 2005 18:50:09 +0000 Subject: * XmlSchemaExporterTests.cs: Added tests for exporting structs, and arrays. Added tests for bug #77117. Refactored some existing tests. svn path=/trunk/mcs/; revision=54915 --- .../Test/System.Xml.Serialization/ChangeLog | 5 + .../XmlSchemaExporterTests.cs | 294 +++++++++++++++++++-- 2 files changed, 280 insertions(+), 19 deletions(-) (limited to 'mcs/class/System.XML') diff --git a/mcs/class/System.XML/Test/System.Xml.Serialization/ChangeLog b/mcs/class/System.XML/Test/System.Xml.Serialization/ChangeLog index bba7135fab2..e4f27de1c65 100644 --- a/mcs/class/System.XML/Test/System.Xml.Serialization/ChangeLog +++ b/mcs/class/System.XML/Test/System.Xml.Serialization/ChangeLog @@ -1,3 +1,8 @@ +2005-12-29 Gert Driesen + + * XmlSchemaExporterTests.cs: Added tests for exporting structs, and + arrays. Added tests for bug #77117. Refactored some existing tests. + 2005-12-28 Gert Driesen * XmlSerializerTests.cs: Added serialization test for XmlSchema. diff --git a/mcs/class/System.XML/Test/System.Xml.Serialization/XmlSchemaExporterTests.cs b/mcs/class/System.XML/Test/System.Xml.Serialization/XmlSchemaExporterTests.cs index b40bf91b978..0f225fc4f7b 100644 --- a/mcs/class/System.XML/Test/System.Xml.Serialization/XmlSchemaExporterTests.cs +++ b/mcs/class/System.XML/Test/System.Xml.Serialization/XmlSchemaExporterTests.cs @@ -8,6 +8,7 @@ // using System; +using System.Collections; using System.Globalization; using System.IO; using System.Xml; @@ -23,6 +24,57 @@ namespace MonoTests.System.XmlSerialization [TestFixture] public class XmlSchemaExporterTests { + [Test] + [Category ("NotWorking")] // on Mono, element is output before type + public void ExportStruct () + { + XmlReflectionImporter ri = new XmlReflectionImporter ("NSTimeSpan"); + XmlSchemas schemas = new XmlSchemas (); + XmlSchemaExporter sx = new XmlSchemaExporter (schemas); + XmlTypeMapping tm = ri.ImportTypeMapping (typeof (TimeSpan)); + sx.ExportTypeMapping (tm); + + Assert.AreEqual (1, schemas.Count, "#1"); + + StringWriter sw = new StringWriter (); + schemas[0].Write (sw); + + Assert.AreEqual (string.Format (CultureInfo.InvariantCulture, + "{0}" + + "{0}" + + " {0}" + + " {0}" + + "", Environment.NewLine), sw.ToString (), "#2"); + } + + [Test] + [Category ("NotWorking")] // on Mono, element is output before type + public void ExportStruct_Array () + { + XmlReflectionImporter ri = new XmlReflectionImporter ("NSTimeSpanArray"); + XmlSchemas schemas = new XmlSchemas (); + XmlSchemaExporter sx = new XmlSchemaExporter (schemas); + XmlTypeMapping tm = ri.ImportTypeMapping (typeof (TimeSpan[])); + sx.ExportTypeMapping (tm); + + Assert.AreEqual (1, schemas.Count, "#1"); + + StringWriter sw = new StringWriter (); + schemas[0].Write (sw); + + Assert.AreEqual (string.Format (CultureInfo.InvariantCulture, + "{0}" + + "{0}" + + " {0}" + + " {0}" + + " {0}" + + " {0}" + + " {0}" + + " {0}" + + " {0}" + + "", Environment.NewLine), sw.ToString (), "#2"); + } + [Test] [Category ("NotWorking")] // on Mono, element is output before type public void ExportClass () @@ -30,19 +82,14 @@ namespace MonoTests.System.XmlSerialization XmlAttributeOverrides overrides = new XmlAttributeOverrides (); XmlAttributes attr = new XmlAttributes (); XmlElementAttribute element = new XmlElementAttribute (); - attr.XmlElements.Add (element); - overrides.Add (typeof (SimpleClass), "something", attr); - - SimpleClass simple = new SimpleClass (); element.ElementName = "saying"; element.IsNullable = true; - simple.something = null; + attr.XmlElements.Add (element); + overrides.Add (typeof (SimpleClass), "something", attr); XmlReflectionImporter ri = new XmlReflectionImporter (overrides, "NS1"); - XmlSchemas schemas = new XmlSchemas (); XmlSchemaExporter sx = new XmlSchemaExporter (schemas); - XmlTypeMapping tm = ri.ImportTypeMapping (typeof (SimpleClass)); sx.ExportTypeMapping (tm); @@ -65,13 +112,51 @@ namespace MonoTests.System.XmlSerialization [Test] [Category ("NotWorking")] // on Mono, element is output before type - public void ExportEnum () + public void ExportClass_Array () { - XmlReflectionImporter ri = new XmlReflectionImporter ("NS2"); + XmlAttributeOverrides overrides = new XmlAttributeOverrides (); + XmlAttributes attr = new XmlAttributes (); + XmlElementAttribute element = new XmlElementAttribute (); + element.ElementName = "saying"; + element.IsNullable = true; + attr.XmlElements.Add (element); + overrides.Add (typeof (SimpleClass), "something", attr); + XmlReflectionImporter ri = new XmlReflectionImporter (overrides, "NSSimpleClassArray"); XmlSchemas schemas = new XmlSchemas (); XmlSchemaExporter sx = new XmlSchemaExporter (schemas); + XmlTypeMapping tm = ri.ImportTypeMapping (typeof (SimpleClass[])); + sx.ExportTypeMapping (tm); + + Assert.AreEqual (1, schemas.Count, "#1"); + + StringWriter sw = new StringWriter (); + schemas[0].Write (sw); + + Assert.AreEqual (string.Format (CultureInfo.InvariantCulture, + "{0}" + + "{0}" + + " {0}" + + " {0}" + + " {0}" + + " {0}" + + " {0}" + + " {0}" + + " {0}" + + " {0}" + + " {0}" + + " {0}" + + " {0}" + + "", Environment.NewLine), sw.ToString (), "#2"); + } + [Test] + [Category ("NotWorking")] // on Mono, element is output before type + public void ExportEnum () + { + XmlReflectionImporter ri = new XmlReflectionImporter ("NS2"); + XmlSchemas schemas = new XmlSchemas (); + XmlSchemaExporter sx = new XmlSchemaExporter (schemas); XmlTypeMapping tm = ri.ImportTypeMapping (typeof (EnumDefaultValue)); sx.ExportTypeMapping (tm); @@ -103,10 +188,8 @@ namespace MonoTests.System.XmlSerialization public void ExportXmlSerializable () { XmlReflectionImporter ri = new XmlReflectionImporter ("NS3"); - XmlSchemas schemas = new XmlSchemas (); XmlSchemaExporter sx = new XmlSchemaExporter (schemas); - XmlTypeMapping tm = ri.ImportTypeMapping (typeof (Employee)); sx.ExportTypeMapping (tm); @@ -133,7 +216,6 @@ namespace MonoTests.System.XmlSerialization schemas = new XmlSchemas (); sx = new XmlSchemaExporter (schemas); - tm = ri.ImportTypeMapping (typeof (EmployeeSchema)); sx.ExportTypeMapping (tm); @@ -163,12 +245,59 @@ namespace MonoTests.System.XmlSerialization } [Test] - public void ExportPrimitive_Int () + [Category ("NotWorking")] // bug #77117 + public void ExportXsdPrimitive () + { + ArrayList types = new ArrayList (); + types.Add (new TypeDescription (typeof (byte), true, "unsignedByte", "Byte")); + types.Add (new TypeDescription (typeof (sbyte), true, "byte", "Byte")); + types.Add (new TypeDescription (typeof (bool), true, "boolean", "Boolean")); + types.Add (new TypeDescription (typeof (short), true, "short", "Short")); + types.Add (new TypeDescription (typeof (int), true, "int", "Int")); + types.Add (new TypeDescription (typeof (long), true, "long", "Long")); + types.Add (new TypeDescription (typeof (float), true, "float", "Float")); + types.Add (new TypeDescription (typeof (double), true, "double", "Double")); + types.Add (new TypeDescription (typeof (decimal), true, "decimal", "Decimal")); + types.Add (new TypeDescription (typeof (ushort), true, "unsignedShort", "UnsignedShort")); + types.Add (new TypeDescription (typeof (uint), true, "unsignedInt", "UnsignedInt")); + types.Add (new TypeDescription (typeof (ulong), true, "unsignedLong", "UnsignedLong")); + types.Add (new TypeDescription (typeof (DateTime), true, "dateTime", "DateTime")); +#if NET_2_0 + types.Add (new TypeDescription (typeof (XmlQualifiedName), true, "QName", "QName", true)); +#else + types.Add (new TypeDescription (typeof (XmlQualifiedName), true, "QName", "QName")); +#endif + types.Add (new TypeDescription (typeof (string), true, "string", "String", true)); + + foreach (TypeDescription typeDesc in types) { + XmlReflectionImporter ri = new XmlReflectionImporter (typeDesc.Type.Name); + XmlSchemas schemas = new XmlSchemas (); + XmlSchemaExporter sx = new XmlSchemaExporter (schemas); + XmlTypeMapping tm = ri.ImportTypeMapping (typeDesc.Type); + sx.ExportTypeMapping (tm); + + Assert.AreEqual (1, schemas.Count, typeDesc.Type.FullName + "#1"); + + StringWriter sw = new StringWriter (); + schemas[0].Write (sw); + + Assert.AreEqual (string.Format (CultureInfo.InvariantCulture, + "{0}" + + "{0}" + + " {0}" + + "", Environment.NewLine, typeDesc.Type.Name, typeDesc.XmlType, typeDesc.IsNillable ? "nillable=\"true\" " : ""), + sw.ToString (), typeDesc.Type.FullName + "#2"); + } + } + + [Test] + [Category ("NotWorking")] // bug #77117 + public void ExportXsdPrimitive_ByteArray () { - XmlReflectionImporter ri = new XmlReflectionImporter ("NSPrim1"); + XmlReflectionImporter ri = new XmlReflectionImporter ("ByteArray"); XmlSchemas schemas = new XmlSchemas (); XmlSchemaExporter sx = new XmlSchemaExporter (schemas); - XmlTypeMapping tm = ri.ImportTypeMapping (typeof (int)); + XmlTypeMapping tm = ri.ImportTypeMapping (typeof (byte[])); sx.ExportTypeMapping (tm); Assert.AreEqual (1, schemas.Count, "#1"); @@ -178,14 +307,65 @@ namespace MonoTests.System.XmlSerialization Assert.AreEqual (string.Format (CultureInfo.InvariantCulture, "{0}" + - "{0}" + - " {0}" + + "{0}" + + " {0}" + "", Environment.NewLine), sw.ToString (), "#2"); } [Test] - [Category ("NotWorking")] // on Mono, only one schema is created - public void ExportPrimitive_Guid () + [Category ("NotWorking")] // bug #77117 + public void ExportXsdPrimitive_Arrays () + { + ArrayList types = new ArrayList (); + types.Add (new TypeDescription (typeof (sbyte[]), true, "byte", "Byte")); + types.Add (new TypeDescription (typeof (bool[]), true, "boolean", "Boolean")); + types.Add (new TypeDescription (typeof (short[]), true, "short", "Short")); + types.Add (new TypeDescription (typeof (int[]), true, "int", "Int")); + types.Add (new TypeDescription (typeof (long[]), true, "long", "Long")); + types.Add (new TypeDescription (typeof (float[]), true, "float", "Float")); + types.Add (new TypeDescription (typeof (double[]), true, "double", "Double")); + types.Add (new TypeDescription (typeof (decimal[]), true, "decimal", "Decimal")); + types.Add (new TypeDescription (typeof (ushort[]), true, "unsignedShort", "UnsignedShort")); + types.Add (new TypeDescription (typeof (uint[]), true, "unsignedInt", "UnsignedInt")); + types.Add (new TypeDescription (typeof (ulong[]), true, "unsignedLong", "UnsignedLong")); + types.Add (new TypeDescription (typeof (DateTime[]), true, "dateTime", "DateTime")); +#if NET_2_0 + types.Add (new TypeDescription (typeof (XmlQualifiedName[]), true, "QName", "QName", true)); +#else + types.Add (new TypeDescription (typeof (XmlQualifiedName[]), true, "QName", "QName")); +#endif + types.Add (new TypeDescription (typeof (string[]), true, "string", "String", true)); + + foreach (TypeDescription typeDesc in types) { + XmlReflectionImporter ri = new XmlReflectionImporter (typeDesc.Type.Name); + XmlSchemas schemas = new XmlSchemas (); + XmlSchemaExporter sx = new XmlSchemaExporter (schemas); + XmlTypeMapping tm = ri.ImportTypeMapping (typeDesc.Type); + sx.ExportTypeMapping (tm); + + Assert.AreEqual (1, schemas.Count, typeDesc.Type.FullName + "#1"); + + StringWriter sw = new StringWriter (); + schemas[0].Write (sw); + + Assert.AreEqual (string.Format (CultureInfo.InvariantCulture, + "{0}" + + "{0}" + + " {0}" + + " {0}" + + " {0}" + + " {0}" + + " {0}" + + " {0}" + + "", Environment.NewLine, typeDesc.Type.Name, typeDesc.ArrayType, typeDesc.XmlType, + typeDesc.XsdType ? "xs" : "tns", typeDesc.IsNillable ? "nillable=\"true\" " : ""), + sw.ToString (), typeDesc.Type.FullName + "#2"); + } + } + + [Test] + [Category ("NotWorking")] // bug #77117 + public void ExportNonXsdPrimitive_Guid () { XmlReflectionImporter ri = new XmlReflectionImporter ("NSPrimGuid"); XmlSchemas schemas = new XmlSchemas (); @@ -219,6 +399,40 @@ namespace MonoTests.System.XmlSerialization "", Environment.NewLine), sw.ToString (), "#3"); } + [Test] + [Category ("NotWorking")] // bug #77117 + public void ExportNonXsdPrimitive_Char () + { + XmlReflectionImporter ri = new XmlReflectionImporter ("NSPrimChar"); + XmlSchemas schemas = new XmlSchemas (); + XmlSchemaExporter sx = new XmlSchemaExporter (schemas); + XmlTypeMapping tm = ri.ImportTypeMapping (typeof (Char)); + sx.ExportTypeMapping (tm); + + Assert.AreEqual (2, schemas.Count, "#1"); + + StringWriter sw = new StringWriter (); + schemas[0].Write (sw); + + Assert.AreEqual (string.Format (CultureInfo.InvariantCulture, + "{0}" + + "{0}" + + " {0}" + + " {0}" + + "", Environment.NewLine), sw.ToString (), "#2"); + + sw = new StringWriter (); + schemas[1].Write (sw); + + Assert.AreEqual (string.Format (CultureInfo.InvariantCulture, + "{0}" + + "{0}" + + " {0}" + + " {0}" + + " {0}" + + "", Environment.NewLine), sw.ToString (), "#3"); + } + public class Employee : IXmlSerializable { private string _firstName; @@ -288,5 +502,47 @@ namespace MonoTests.System.XmlSerialization } #endif } + + private class TypeDescription + { + public TypeDescription (Type type, bool xsdType, string xmlType, string arrayType) : this (type, xsdType, xmlType, arrayType, false) + { + } + + public TypeDescription (Type type, bool xsdType, string xmlType, string arrayType, bool isNillable) + { + _type = type; + _xsdType = xsdType; + _xmlType = xmlType; + _arrayType = arrayType; + _isNillable = isNillable; + } + + public Type Type { + get { return _type; } + } + + public string XmlType { + get { return _xmlType; } + } + + public string ArrayType { + get { return _arrayType; } + } + + public bool XsdType { + get { return _xsdType; } + } + + public bool IsNillable { + get { return _isNillable; } + } + + private Type _type; + private bool _xsdType; + private string _xmlType; + private string _arrayType; + private bool _isNillable; + } } } -- cgit v1.2.3