2010-02-17 Atsushi Enomoto <atsushi@ximian.com>
authorAtsushi Eno <atsushieno@gmail.com>
Wed, 17 Feb 2010 11:28:31 +0000 (11:28 -0000)
committerAtsushi Eno <atsushieno@gmail.com>
Wed, 17 Feb 2010 11:28:31 +0000 (11:28 -0000)
* XsdDataContractImporter-new.cs : refresh implementation that is
  not based on xml serialization. Not enabled yet.
* KnownTypeCollection.cs : add cosmetic comment.

* ns0,xsd ... ns27.xsd : new test files.
* ns-readme.txt : description.

* XsdDataContractImporterTest.cs : added a bunch of tests for new
  implementation. Disable yet.

svn path=/trunk/mcs/; revision=151902

35 files changed:
mcs/class/System.Runtime.Serialization/System.Runtime.Serialization/ChangeLog
mcs/class/System.Runtime.Serialization/System.Runtime.Serialization/KnownTypeCollection.cs
mcs/class/System.Runtime.Serialization/System.Runtime.Serialization/XsdDataContractImporter-new.cs [new file with mode: 0644]
mcs/class/System.Runtime.Serialization/Test/Resources/Schemas/ChangeLog
mcs/class/System.Runtime.Serialization/Test/Resources/Schemas/ns-readme.txt [new file with mode: 0644]
mcs/class/System.Runtime.Serialization/Test/Resources/Schemas/ns0.xsd [new file with mode: 0644]
mcs/class/System.Runtime.Serialization/Test/Resources/Schemas/ns1.xsd [new file with mode: 0644]
mcs/class/System.Runtime.Serialization/Test/Resources/Schemas/ns10.xsd [new file with mode: 0644]
mcs/class/System.Runtime.Serialization/Test/Resources/Schemas/ns11.xsd [new file with mode: 0644]
mcs/class/System.Runtime.Serialization/Test/Resources/Schemas/ns12.xsd [new file with mode: 0644]
mcs/class/System.Runtime.Serialization/Test/Resources/Schemas/ns13.xsd [new file with mode: 0644]
mcs/class/System.Runtime.Serialization/Test/Resources/Schemas/ns14.xsd [new file with mode: 0644]
mcs/class/System.Runtime.Serialization/Test/Resources/Schemas/ns15.xsd [new file with mode: 0644]
mcs/class/System.Runtime.Serialization/Test/Resources/Schemas/ns16.xsd [new file with mode: 0644]
mcs/class/System.Runtime.Serialization/Test/Resources/Schemas/ns17.xsd [new file with mode: 0644]
mcs/class/System.Runtime.Serialization/Test/Resources/Schemas/ns18.xsd [new file with mode: 0644]
mcs/class/System.Runtime.Serialization/Test/Resources/Schemas/ns19.xsd [new file with mode: 0644]
mcs/class/System.Runtime.Serialization/Test/Resources/Schemas/ns2.xsd [new file with mode: 0644]
mcs/class/System.Runtime.Serialization/Test/Resources/Schemas/ns20.xsd [new file with mode: 0644]
mcs/class/System.Runtime.Serialization/Test/Resources/Schemas/ns21.xsd [new file with mode: 0644]
mcs/class/System.Runtime.Serialization/Test/Resources/Schemas/ns22.xsd [new file with mode: 0644]
mcs/class/System.Runtime.Serialization/Test/Resources/Schemas/ns23.xsd [new file with mode: 0644]
mcs/class/System.Runtime.Serialization/Test/Resources/Schemas/ns24.xsd [new file with mode: 0644]
mcs/class/System.Runtime.Serialization/Test/Resources/Schemas/ns25.xsd [new file with mode: 0644]
mcs/class/System.Runtime.Serialization/Test/Resources/Schemas/ns26.xsd [new file with mode: 0644]
mcs/class/System.Runtime.Serialization/Test/Resources/Schemas/ns27.xsd [new file with mode: 0644]
mcs/class/System.Runtime.Serialization/Test/Resources/Schemas/ns3.xsd [new file with mode: 0644]
mcs/class/System.Runtime.Serialization/Test/Resources/Schemas/ns4.xsd [new file with mode: 0644]
mcs/class/System.Runtime.Serialization/Test/Resources/Schemas/ns5.xsd [new file with mode: 0644]
mcs/class/System.Runtime.Serialization/Test/Resources/Schemas/ns6.xsd [new file with mode: 0644]
mcs/class/System.Runtime.Serialization/Test/Resources/Schemas/ns7.xsd [new file with mode: 0644]
mcs/class/System.Runtime.Serialization/Test/Resources/Schemas/ns8.xsd [new file with mode: 0644]
mcs/class/System.Runtime.Serialization/Test/Resources/Schemas/ns9.xsd [new file with mode: 0644]
mcs/class/System.Runtime.Serialization/Test/System.Runtime.Serialization/ChangeLog
mcs/class/System.Runtime.Serialization/Test/System.Runtime.Serialization/XsdDataContractImporterTest.cs

index f81a0eb1be7bfb160abe4e894032d7638470ca61..531c58e070170da0126b50a193c68643826d6a4a 100755 (executable)
@@ -1,3 +1,9 @@
+2010-02-17  Atsushi Enomoto  <atsushi@ximian.com>
+
+       * XsdDataContractImporter-new.cs : refresh implementation that is
+         not based on xml serialization. Not enabled yet.
+       * KnownTypeCollection.cs : add cosmetic comment.
+
 2010-02-09  Atsushi Enomoto  <atsushi@ximian.com>
 
        * XsdDataContractImporter.cs : add appropriate code namespaces
index 3690c5ae4c7525fabbda34e2ced30442947f28cb..621f05aea8592ba2202d3786896bd87fb855d795 100644 (file)
@@ -266,6 +266,7 @@ namespace System.Runtime.Serialization
                        }
                }
 
+               // FIXME: xsd types and ms serialization types should be differentiated.
                internal static Type GetPrimitiveTypeFromName (string name)
                {
                        switch (name) {
diff --git a/mcs/class/System.Runtime.Serialization/System.Runtime.Serialization/XsdDataContractImporter-new.cs b/mcs/class/System.Runtime.Serialization/System.Runtime.Serialization/XsdDataContractImporter-new.cs
new file mode 100644 (file)
index 0000000..50ba0cb
--- /dev/null
@@ -0,0 +1,618 @@
+//
+// XsdDataContractImporter.cs
+//
+// Author:
+//     Atsushi Enomoto <atsushi@ximian.com>
+//
+// Copyright (C) 2010 Novell, Inc.  http://www.novell.com
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+// 
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+// 
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+using System;
+using System.CodeDom;
+using System.CodeDom.Compiler;
+using System.Collections.Generic;
+using System.IO;
+using System.Linq;
+using System.Xml;
+using System.Xml.Schema;
+using System.Xml.Serialization;
+
+namespace System.Runtime.Serialization
+{
+       [MonoTODO ("Support ImportXmlType option; support arrays; CanImport is not up to date with Import")]
+       public class XsdDataContractImporter
+       {
+               static readonly XmlQualifiedName qname_anytype = new XmlQualifiedName ("anyType", XmlSchema.Namespace);
+
+               public XsdDataContractImporter ()
+                       : this (null)
+               {
+               }
+
+               public XsdDataContractImporter (CodeCompileUnit codeCompileUnit)
+               {
+                       // null argument is ok.
+                       CodeCompileUnit = codeCompileUnit ?? new CodeCompileUnit ();
+
+                       // Options is null by default
+               }
+
+               public CodeCompileUnit CodeCompileUnit { get; private set; }
+
+               CodeDomProvider code_provider = CodeDomProvider.CreateProvider ("csharp");
+               ImportOptions import_options;
+
+               public ImportOptions Options {
+                       get { return import_options; }
+                       set {
+                               import_options = value;
+                               code_provider = value.CodeProvider ?? code_provider;
+                       }
+               }
+
+               // CanImport
+
+               public bool CanImport (XmlSchemaSet schemas)
+               {
+                       if (schemas == null)
+                               throw new ArgumentNullException ("schemas");
+
+                       if (!schemas.IsCompiled)
+                               schemas.Compile ();
+
+                       foreach (XmlSchemaElement xe in schemas.GlobalElements.Values)
+                               if (!CanImport (schemas, xe))
+                                       return false;
+                       return true;
+               }
+
+               public bool CanImport (XmlSchemaSet schemas, ICollection<XmlQualifiedName> typeNames)
+               {
+                       if (schemas == null)
+                               throw new ArgumentNullException ("schemas");
+                       if (typeNames == null)
+                               throw new ArgumentNullException ("typeNames");
+
+                       if (!schemas.IsCompiled)
+                               schemas.Compile ();
+
+                       foreach (var name in typeNames)
+                               if (!CanImport (schemas, name))
+                                       return false;
+                       return true;
+               }
+
+               public bool CanImport (XmlSchemaSet schemas, XmlQualifiedName typeName)
+               {
+                       if (schemas == null)
+                               throw new ArgumentNullException ("schemas");
+                       if (typeName == null)
+                               throw new ArgumentNullException ("typeName");
+
+                       if (!schemas.IsCompiled)
+                               schemas.Compile ();
+
+                       if (!schemas.GlobalTypes.Contains (typeName))
+                               throw new InvalidDataContractException (String.Format ("Type {0} is not found in the schemas", typeName));
+
+                       return CanImport (schemas, schemas.GlobalTypes [typeName] as XmlSchemaComplexType);
+               }
+
+               public bool CanImport (XmlSchemaSet schemas, XmlSchemaElement element)
+               {
+                       if (schemas == null)
+                               throw new ArgumentNullException ("schemas");
+
+                       if (!schemas.IsCompiled)
+                               schemas.Compile ();
+
+                       return CanImport (schemas, element.ElementSchemaType as XmlSchemaComplexType);
+               }
+
+               bool CanImport (XmlSchemaSet schemas, XmlSchemaComplexType type)
+               {
+                       if (type == null || type.QualifiedName.Namespace == XmlSchema.Namespace) // xs:anyType -> not supported.
+                               return false;
+
+                       if (type.ContentModel is XmlSchemaSimpleContent) // simple content derivation is not supported.
+                               return false;
+                       if (type.ContentModel != null && type.ContentModel.Content != null) {
+                               var xscce = type.ContentModel.Content as XmlSchemaComplexContentExtension;
+                               if (xscce == null) // complex DBR is not supported.
+                                       return false;
+                               // check base type
+                               if (xscce.BaseTypeName != qname_anytype && !CanImport (schemas, xscce.BaseTypeName))
+                                       return false;
+                       }
+
+                       return true;
+               }
+
+               // Import
+
+               public void Import (XmlSchemaSet schemas)
+               {
+                       if (schemas == null)
+                               throw new ArgumentNullException ("schemas");
+
+                       if (!schemas.IsCompiled)
+                               schemas.Compile ();
+
+                       foreach (XmlSchemaElement xe in schemas.GlobalElements.Values)
+                               Import (schemas, xe);
+               }
+
+               public void Import (XmlSchemaSet schemas, ICollection<XmlQualifiedName> typeNames)
+               {
+                       if (schemas == null)
+                               throw new ArgumentNullException ("schemas");
+                       if (typeNames == null)
+                               throw new ArgumentNullException ("typeNames");
+                       foreach (var name in typeNames)
+                               Import (schemas, name);
+               }
+
+               // This checks type existence and raises an error if it is missing.
+               public void Import (XmlSchemaSet schemas, XmlQualifiedName typeName)
+               {
+                       if (schemas == null)
+                               throw new ArgumentNullException ("schemas");
+                       if (typeName == null)
+                               throw new ArgumentNullException ("typeName");
+
+                       if (IsPredefinedType (typeName))
+                               return;
+
+                       if (!schemas.GlobalTypes.Contains (typeName))
+                               throw new InvalidDataContractException (String.Format ("Type {0} is not found in the schemas", typeName));
+
+                       Import (schemas, schemas.GlobalTypes [typeName] as XmlSchemaType, typeName);
+               }
+
+               public XmlQualifiedName Import (XmlSchemaSet schemas, XmlSchemaElement element)
+               {
+                       if (schemas == null)
+                               throw new ArgumentNullException ("schemas");
+                       if (element == null)
+                               throw new ArgumentNullException ("element");
+
+                       var elname = element.QualifiedName;
+
+                       switch (elname.Namespace) {
+                       case KnownTypeCollection.MSSimpleNamespace:
+                               switch (elname.Name) {
+                               case "char":
+                               case "duration":
+                               case "guid":
+                                       return elname;
+                               }
+                               break;
+                       }
+
+                       // FIXME: use element to fill nillable and arrays.
+                       var qname = element.SchemaType != null ? element.QualifiedName : element.ElementSchemaType.QualifiedName;
+                       Import (schemas, element.ElementSchemaType, qname);
+                       return qname;
+               }
+
+               void Import (XmlSchemaSet schemas, XmlSchemaType type)
+               {
+                       Import (schemas, type, type.QualifiedName);
+               }
+
+               void Import (XmlSchemaSet schemas, XmlSchemaType type, XmlQualifiedName qname)
+               {
+                       var existing = imported_types.FirstOrDefault (it => it.XsdType == type);
+                       if (existing != null)
+                               return;// existing.XsdTypeName;
+
+                       if (IsPredefinedType (type.QualifiedName))
+                               return;
+
+                       DoImport (schemas, type, qname);
+               }
+
+               void DoImport (XmlSchemaSet schemas, XmlSchemaType type, XmlQualifiedName qname)
+               {
+                       CodeNamespace cns = null;
+                       CodeTypeReference clrRef;
+                       cns = GetCodeNamespace (qname);
+                       clrRef = new CodeTypeReference (cns.Name.Length > 0 ? cns.Name + "." + qname.Name : qname.Name);
+
+                       var td = new CodeTypeDeclaration ();
+                       td.Name = CodeIdentifier.MakeValid (qname.Name);
+                       cns.Types.Add (td);
+
+                       var info = new TypeImportInfo () { ClrType = clrRef, XsdType = type,  XsdTypeName = qname };
+                       imported_types.Add (info);
+
+                       var st = type as XmlSchemaSimpleType;
+                       if (st != null) {
+                               ImportSimpleType (td, schemas, st, qname);
+                       } else {
+                               var ct = (XmlSchemaComplexType) type;
+                               var sc = ct.ContentModel as XmlSchemaSimpleContent;
+                               if (sc != null) {
+                                       if (sc.Content is XmlSchemaSimpleContentExtension)
+                                               throw new InvalidDataContractException (String.Format ("complex type '{0}' with simple content extension is not supported", type.QualifiedName));
+                               }
+                               if (!ImportComplexType (td, schemas, ct, qname)) {
+                                       cns.Types.Remove (td);
+                                       if (cns.Types.Count == 0)
+                                               CodeCompileUnit.Namespaces.Remove (cns);
+                               }
+                       }
+               }
+
+               static readonly string ass_name = typeof (DataContractAttribute).Assembly.GetName ().Name;
+               static readonly string ass_version = typeof (DataContractAttribute).Assembly.GetName ().Version.ToString ();
+               static readonly CodeTypeReference typeref_data_contract = new CodeTypeReference (typeof (DataContractAttribute));
+               static readonly CodeTypeReference typeref_coll_contract = new CodeTypeReference (typeof (CollectionDataContractAttribute));
+
+               void AddTypeAttributes (CodeTypeDeclaration td, XmlSchemaType type, string collectionItemName)
+               {
+                       var name = type.QualifiedName;
+                       // [GeneratedCode (assembly_name, assembly_version)]
+                       td.CustomAttributes.Add (new CodeAttributeDeclaration (
+                               new CodeTypeReference (typeof (GeneratedCodeAttribute)),
+                               new CodeAttributeArgument (new CodePrimitiveExpression (ass_name)),
+                               new CodeAttributeArgument (new CodePrimitiveExpression (ass_version))));
+
+                       var ct = type as XmlSchemaComplexType;
+
+                       // [DataContract(Name="foobar",Namespace="urn:foobar")] (optionally IsReference=true),
+                       // or [CollectionDataContract(ditto)]
+                       var dca = new CodeAttributeDeclaration (
+                               collectionItemName != null ? typeref_coll_contract : typeref_data_contract,
+                               new CodeAttributeArgument ("Name", new CodePrimitiveExpression (name.Name)),
+                               new CodeAttributeArgument ("Namespace", new CodePrimitiveExpression (name.Namespace)));
+                       if (collectionItemName != null)
+                               dca.Arguments.Add (new CodeAttributeArgument ("ItemName", new CodePrimitiveExpression (collectionItemName)));
+                       if (ct != null && ct.AttributeUses [new XmlQualifiedName ("Ref", KnownTypeCollection.MSSimpleNamespace)] != null)
+                               dca.Arguments.Add (new CodeAttributeArgument ("IsReference", new CodePrimitiveExpression (true)));
+                       td.CustomAttributes.Add (dca);
+
+                       // optional [Serializable]
+                       if (Options != null && Options.GenerateSerializable)
+                               td.CustomAttributes.Add (new CodeAttributeDeclaration ("System.SerializableAttribute"));
+               }
+
+               static readonly CodeTypeReference typeref_ext_iface = new CodeTypeReference ("System.Runtime.Serialization.IExtensibleDataObject");
+               static readonly CodeTypeReference typeref_ext_class = new CodeTypeReference ("System.Runtime.Serialization.ExtensibleDataObject");
+
+               void AddExtensionData (CodeTypeDeclaration td)
+               {
+                       td.BaseTypes.Add (typeref_ext_iface);
+
+                       var field = new CodeMemberField (typeref_ext_class, "extensionDataField");
+                       td.Members.Add (field);
+
+                       var prop = new CodeMemberProperty () { Type = field.Type, Name = "ExtensionData", Attributes = MemberAttributes.Public | MemberAttributes.Final };
+                       prop.GetStatements.Add (new CodeMethodReturnStatement (
+                               new CodeFieldReferenceExpression (
+                               new CodeThisReferenceExpression (),
+                               "extensionDataField")));
+                       prop.SetStatements.Add (new CodeAssignStatement (
+                               new CodeFieldReferenceExpression (
+                               new CodeThisReferenceExpression (),
+                               "extensionDataField"),
+                               new CodePropertySetValueReferenceExpression ()));
+
+                       td.Members.Add (prop);
+               }
+
+               void ImportSimpleType (CodeTypeDeclaration td, XmlSchemaSet schemas, XmlSchemaSimpleType type, XmlQualifiedName qname)
+               {
+                       var scl = type.Content as XmlSchemaSimpleTypeList;
+                       if (scl != null) {
+                               if (scl.ItemType == null)
+                                       throw new InvalidDataContractException (String.Format ("simple type list is allowed only with an anonymous simple type with enumeration restriction content as its item type definition (type is {0})", type.QualifiedName));
+                               var itemType = scl.ItemType as XmlSchemaSimpleType;
+                               var ir = itemType.Content as XmlSchemaSimpleTypeRestriction;
+                               if (ir == null)
+                                       throw new InvalidDataContractException (String.Format ("simple type list is allowed only with an anonymous simple type with enumeration restriction content as its item type definition (type is {0})", type.QualifiedName));
+                               ImportEnum (td, schemas, ir, type, qname, true);
+                               return;
+                       }
+                       var scr = type.Content as XmlSchemaSimpleTypeRestriction;
+                       if (scr != null) {
+                               ImportEnum (td, schemas, scr, type, qname, false);
+                               return;
+                       }
+
+                       throw new InvalidDataContractException (String.Format ("simple type is supported only if it has enumeration or list of an anonymous simple type with enumeration restriction content as its item type definition (type is {0})", qname));
+               }
+
+               static readonly CodeTypeReference enum_member_att_ref = new CodeTypeReference (typeof (EnumMemberAttribute));
+
+               void ImportEnum (CodeTypeDeclaration td, XmlSchemaSet schemas, XmlSchemaSimpleTypeRestriction r, XmlSchemaType type, XmlQualifiedName qname, bool isFlag)
+               {
+                       if (isFlag && !r.BaseTypeName.Equals (new XmlQualifiedName ("string", XmlSchema.Namespace)))
+                               throw new InvalidDataContractException (String.Format ("For flags enumeration '{0}', the base type for the simple type restriction must be XML schema string", qname));
+
+                       td.IsEnum = true;
+                       AddTypeAttributes (td, type, null);
+                       if (isFlag)
+                               td.CustomAttributes.Add (new CodeAttributeDeclaration (new CodeTypeReference (typeof (FlagsAttribute))));
+
+                       foreach (var facet in r.Facets) {
+                               var e = facet as XmlSchemaEnumerationFacet;
+                               if (e == null)
+                                       throw new InvalidDataContractException (String.Format ("Invalid simple type restriction (type {0}). Only enumeration is allowed.", qname));
+                               var em = new CodeMemberField () { Name = CodeIdentifier.MakeValid (e.Value) };
+                               var ea = new CodeAttributeDeclaration (enum_member_att_ref);
+                               if (e.Value != em.Name)
+                                       ea.Arguments.Add (new CodeAttributeArgument ("Value", new CodePrimitiveExpression (e.Value)));
+                               em.CustomAttributes.Add (ea);
+                               td.Members.Add (em);
+                       }
+               }
+
+               // Returns false if it should remove the imported type.
+               // FIXME: also support ImportXmlType
+               bool ImportComplexType (CodeTypeDeclaration td, XmlSchemaSet schemas, XmlSchemaComplexType type, XmlQualifiedName qname)
+               {
+                       foreach (XmlSchemaAttribute att in type.AttributeUses.Values)
+                               if (att.Use != XmlSchemaUse.Optional || att.QualifiedName.Namespace != KnownTypeCollection.MSSimpleNamespace)
+                                       throw new InvalidDataContractException (String.Format ("attribute in DataContract complex type '{0}' is limited to those in {1} namespace, and optional.", qname, KnownTypeCollection.MSSimpleNamespace));
+
+                       CodeTypeReference baseClrType = null;
+                       var particle = type.Particle;
+                       if (type.ContentModel != null) {
+                               var xsscr = type.ContentModel.Content as XmlSchemaSimpleContentRestriction;
+                               if (xsscr != null) {
+                                       if (xsscr.BaseType != null)
+                                               Import (schemas, xsscr.BaseType);
+                                       else
+                                               Import (schemas, xsscr.BaseTypeName);
+                                       // The above will result in an error, but make sure to show we don't support it.
+                                       throw new InvalidDataContractException (String.Format ("complex type simple content restriction is not supported in DataContract (type '{0}')", qname));
+                               }
+                               var xscce = type.ContentModel.Content as XmlSchemaComplexContentExtension;
+                               if (xscce != null) {
+                                       Import (schemas, xscce.BaseTypeName);
+                                       baseClrType = GetCodeTypeReferenceInternal (xscce.BaseTypeName, false);
+                                       if (baseClrType != null)
+                                               td.BaseTypes.Add (baseClrType);
+
+                                       var baseInfo = GetTypeInfo (xscce.BaseTypeName, false);
+                                       if (baseInfo != null)
+                                               baseInfo.KnownClrTypes.Add (imported_types.First (it => it.XsdType == type).ClrType);
+                                       particle = xscce.Particle;
+                               }
+                               var xsccr = type.ContentModel.Content as XmlSchemaComplexContentRestriction;
+                               if (xsccr != null)
+                                       throw new InvalidDataContractException (String.Format ("complex content type (for type '{0}') has a restriction content model, which is not supported in DataContract.", qname));
+                       }
+
+                       var seq = particle as XmlSchemaSequence;
+                       if (seq == null && particle != null)
+                               throw new InvalidDataContractException (String.Format ("Not supported particle {1}. In DataContract, only sequence particle is allowed as the top-level content of a complex type (type '{0}')", qname, particle));
+
+                       if (seq != null) {
+
+                       foreach (var child in seq.Items)
+                               if (!(child is XmlSchemaElement))
+                                       throw new InvalidDataContractException (String.Format ("Only local element is allowed as the content of the sequence of the top-level content of a complex type '{0}'. Other particles (sequence, choice, all, any, group ref) are not supported.", qname));
+
+                       if (seq.Items.Count == 1) {
+                               var xe = (XmlSchemaElement) seq.Items [0];
+                               if (xe.MaxOccursString == "unbounded") {
+                                       // import as a collection contract.
+                                       if (type.QualifiedName.Namespace == KnownTypeCollection.MSArraysNamespace &&
+                                           IsPredefinedType (xe.ElementSchemaType.QualifiedName)) {
+                                               // then this CodeTypeDeclaration is to be removed, and CodeTypeReference to this type should be an array instead.
+                                               var cti = imported_types.First (i => i.XsdType == type);
+                                               cti.ClrType = new CodeTypeReference (GetCodeTypeReference (xe.ElementSchemaType.QualifiedName), 1);
+                                               
+                                               return false;
+                                       }
+                                       else
+                                               Import (schemas, xe.ElementSchemaType);
+                                       td.BaseTypes.Add (new CodeTypeReference ("System.Collections.Generic.List", GetCodeTypeReference (xe.ElementSchemaType.QualifiedName)));
+                                       AddTypeAttributes (td, type, CodeIdentifier.MakeValid (xe.QualifiedName.Name));
+                                       return true;
+                               }
+                       }
+
+                       // import as a (normal) contract.
+                       var elems = new List<XmlSchemaElement> ();
+                       foreach (XmlSchemaElement xe in seq.Items) {
+                               if (xe.MaxOccurs != 1)
+                                       throw new InvalidDataContractException (String.Format ("schema complex type '{0}' has a content sequence containing an element '{1}' with 'maxOccurs' value as more than 1, which is not supported in DataContract.", qname, xe.QualifiedName));
+
+                               if (elems.Any (e => e.QualifiedName.Name == xe.QualifiedName.Name))
+                                       throw new InvalidDataContractException (String.Format ("In schema type '{0}', there already is an element whose name is {1}, where duplicate of element names are not supported.", qname, xe.QualifiedName.Name));
+
+                               elems.Add (xe);
+                       }
+                       foreach (var xe in elems) {
+                               // import property type in prior.
+                               Import (schemas, xe.ElementSchemaType.QualifiedName);
+                               AddProperty (td, xe);
+                       }
+
+                       } // if (seq != 0)
+
+                       AddTypeAttributes (td, type, null);
+                       AddExtensionData (td);
+
+                       return true;
+               }
+
+               static readonly CodeExpression this_expr = new CodeThisReferenceExpression ();
+               static readonly CodeExpression arg_value_expr = new CodePropertySetValueReferenceExpression ();
+
+               void AddProperty (CodeTypeDeclaration td, XmlSchemaElement xe)
+               {
+                       var att = Options != null && Options.GenerateInternal ? MemberAttributes.Assembly : MemberAttributes.Public;
+                       var fi = new CodeMemberField () { Name = CodeIdentifier.MakeValid (xe.QualifiedName.Name + "Field"), Type = GetCodeTypeReference (xe.ElementSchemaType.QualifiedName, xe) };
+                       td.Members.Add (fi);
+                       var pi = new CodeMemberProperty () { Name = xe.QualifiedName.Name, Attributes = att, HasGet = true, HasSet = true, Type = fi.Type };
+                       // [DataMember(Name=foobar, IsRequired=!nillable)]
+                       var dma = new CodeAttributeDeclaration (
+                               new CodeTypeReference (typeof (DataMemberAttribute)));
+                       if (fi.Name != xe.QualifiedName.Name)
+                               new CodeAttributeArgument ("Name", new CodePrimitiveExpression (xe.QualifiedName.Name));
+                       if (!xe.IsNillable)
+                               new CodeAttributeArgument ("IsRequired", new CodePrimitiveExpression (true));
+                       pi.CustomAttributes.Add (dma);
+
+                       pi.GetStatements.Add (new CodeMethodReturnStatement () { Expression = new CodeFieldReferenceExpression (this_expr, fi.Name) });
+                       pi.SetStatements.Add (new CodeAssignStatement (new CodeFieldReferenceExpression (this_expr, fi.Name), arg_value_expr));
+
+
+                       td.Members.Add (pi);
+               }
+
+               bool IsPredefinedType (XmlQualifiedName qname)
+               {
+                       // FIXME: support char, guid and duration (MSSimpleNamespace); fix GetPrimitiveTypeFromName() first and then this at a time.
+                       switch (qname.Namespace) {
+                       case KnownTypeCollection.MSSimpleNamespace:
+                               switch (qname.Name) {
+                               case "char":
+                               case "guid":
+                               case "duration":
+                                       return true;
+                               }
+                               return false;
+                       case XmlSchema.Namespace:
+                               return KnownTypeCollection.GetPrimitiveTypeFromName (qname.Name) != null;
+                       }
+                       return false;
+               }
+
+               CodeNamespace GetCodeNamespace (XmlQualifiedName name)
+               {
+                       string ns = null;
+                       if (Options == null || !Options.Namespaces.TryGetValue (name.Namespace, out ns))
+                               ns = GetCodeNamespaceFromXmlns (name.Namespace);
+
+                       foreach (CodeNamespace cns in CodeCompileUnit.Namespaces)
+                               if (cns.Name == ns)
+                                       return cns;
+                       var newCns = new CodeNamespace () { Name = ns };
+                       CodeCompileUnit.Namespaces.Add (newCns);
+                       return newCns;
+               }
+
+               const string default_ns_prefix = "http://schemas.datacontract.org/2004/07/";
+
+               string GetCodeNamespaceFromXmlns (string xns)
+               {
+                       if (xns.StartsWith (default_ns_prefix, StringComparison.Ordinal))
+                               xns = xns.Substring (default_ns_prefix.Length);
+                       else {
+                               Uri u;
+                               string tmp;
+                               if (Uri.TryCreate (xns, UriKind.Absolute, out u) && (tmp = MakeStringNamespaceComponentsValid (u.GetComponents (UriComponents.Host | UriComponents.Path, UriFormat.Unescaped))).Length > 0)
+                                       xns = tmp;
+                       }
+                       return MakeStringNamespaceComponentsValid (xns);
+               }
+
+               static readonly char [] split_tokens = new char [] {'/', '.'};
+
+               string MakeStringNamespaceComponentsValid (string ns)
+               {
+                       var arr = ns.Split (split_tokens, StringSplitOptions.RemoveEmptyEntries);
+                       for (int i = 0; i < arr.Length; i++)
+                               arr [i] = CodeIdentifier.MakeValid (arr [i]);
+                       return String.Join (".", arr);
+               }
+
+               // Post-compilation information retrieval
+
+               TypeImportInfo GetTypeInfo (XmlQualifiedName typeName, bool throwError)
+               {
+                       var info = imported_types.FirstOrDefault (i => i.XsdTypeName.Equals (typeName));
+                       if (info == null) {
+                               if (throwError)
+                                       throw new InvalidOperationException (String.Format ("schema type '{0}' has not been imported yet. Import it first.", typeName));
+                               return null;
+                       }
+                       return info;
+               }
+
+               public CodeTypeReference GetCodeTypeReference (XmlQualifiedName typeName)
+               {
+                       return GetCodeTypeReferenceInternal (typeName, true);
+               }
+
+               CodeTypeReference GetCodeTypeReferenceInternal (XmlQualifiedName typeName, bool throwError)
+               {
+                       if (typeName == null)
+                               throw new ArgumentNullException ("typeName");
+
+                       switch (typeName.Namespace) {
+                       case XmlSchema.Namespace:
+                               return new CodeTypeReference (KnownTypeCollection.GetPrimitiveTypeFromName (typeName.Name));
+                       case KnownTypeCollection.MSSimpleNamespace:
+                               switch (typeName.Name) {
+                               case "guid":
+                                       return new CodeTypeReference (typeof (Guid));
+                               case "duration":
+                                       return new CodeTypeReference (typeof (TimeSpan));
+                               }
+                               break;
+                       }
+
+                       var info = GetTypeInfo (typeName, throwError);
+                       return info != null ? info.ClrType : null;
+               }
+
+               [MonoTODO ("use element argument and fill Nullable etc.")]
+               public CodeTypeReference GetCodeTypeReference (XmlQualifiedName typeName, XmlSchemaElement element)
+               {
+                       if (typeName == null)
+                               throw new ArgumentNullException ("typeName");
+                       if (element == null)
+                               throw new ArgumentNullException ("element");
+
+                       return GetCodeTypeReference (typeName);
+               }
+
+               public ICollection<CodeTypeReference> GetKnownTypeReferences (XmlQualifiedName typeName)
+               {
+                       if (typeName == null)
+                               throw new ArgumentNullException ("typeName");
+
+                       return GetTypeInfo (typeName, true).KnownClrTypes;
+               }
+
+               List<TypeImportInfo> imported_types = new List<TypeImportInfo> ();
+
+               class TypeImportInfo
+               {
+                       public TypeImportInfo ()
+                       {
+                               KnownClrTypes = new List<CodeTypeReference> ();
+                       }
+
+                       public CodeTypeReference ClrType { get; set; }
+                       public XmlQualifiedName XsdTypeName { get; set; }
+                       public XmlSchemaType XsdType { get; set; }
+                       public List<CodeTypeReference> KnownClrTypes { get; private set; }
+               }
+       }
+}
index 9687ab3d65d0018d88ce4329980fbfb192bb1087..5dfa8b1464483a2cdfc345166aa19cd9075aa80a 100644 (file)
@@ -1,3 +1,8 @@
+2010-02-17  Atsushi Enomoto  <atsushi@ximian.com>
+
+       * ns0,xsd ... ns27.xsd : new test files.
+       * ns-readme.txt : description.
+
 2010-02-09  Atsushi Enomoto  <atsushi@ximian.com>
 
        * schema3.xsd : new test file.
diff --git a/mcs/class/System.Runtime.Serialization/Test/Resources/Schemas/ns-readme.txt b/mcs/class/System.Runtime.Serialization/Test/Resources/Schemas/ns-readme.txt
new file mode 100644 (file)
index 0000000..2b646f3
--- /dev/null
@@ -0,0 +1,36 @@
+ns0.xsd : MS default serialization namespace.
+ns1.xsd : imports ns2.xsd, has duplicate name to ns2
+ns2.xsd : used with ns1.xsd, not much special.
+ns3.xsd : has simple content extension, seems like not supported in WCF.
+ns4.xsd : has required attributes, not supported in WCF.
+ns5.xsd : has optional attributes but not in MS serialization namespace,
+         not supported in WCF either.
+ns6.xsd : derivation by extension example. Must be used with ns0.xsd.
+ns7.xsd : derivation by restriction example. Must be used with ns0,xsd, but
+         not supported in WCF.
+ns8.xsd : attempt to examine if complex type simple content restriction is
+         supported. There is no way to define it without simple DBE (and
+         simple DBE is not supported in WCF).
+ns9.xsd : contains elements with an identical name, not supported in WCF.
+ns10.xsd : contains element with substitutionGroup. E2 is resolved to be
+          mapped to T1. To verify it, Import() only E2 element.
+ns11.xsd : contains xs:choice as the particle, not supported in WCF(!)
+ns12.xsd : contains xs:all as the particle, not supported in WCF(!)
+ns13.xsd : contains xs:any as the content of xs:sequence, not supported in WCF.
+ns14.xsd : contains simple content restriction by enum. Mapped to CLI enum.
+ns15.xsd : contains simple list by string, not supported in WCF.
+ns16.xsd : contains simple list by embedded enumeration string type.
+ns17.xsd : contains simple list by external enumeration string type, not
+          supported in WCF.
+ns18.xsd : variation of ns14, replaced xs:string with xs:int. No output.
+ns19.xsd : variation of ns16, replaced xs:string with xs:int. Error.
+ns20.xsd : variation of ns16, added maxLength facet. Error.
+ns21.xsd : array of int, gives no output.
+ns22.xsd : use of Id/Ref attributes, makes DataContract(IsReference=true).
+ns23.xsd : collection contract, to prove that xmlns does not matter (rrays
+          instead of Arrays).
+          cf. it matters when it comes to primitive type, see ns27.
+ns24.xsd : ArrayOfint type contains two elements, not supported in WCF.
+ns25.xsd : uses ArrayOfint as a member type. Gives int[] instead of ArrayOfint.
+ns26.xsd : variation of ns25, uses custom simpleType. Gives ArrayOfint.
+ns27.xsd : variation of ns25, uses non-Arrays xmlns. Gives ArrayOfint.
diff --git a/mcs/class/System.Runtime.Serialization/Test/Resources/Schemas/ns0.xsd b/mcs/class/System.Runtime.Serialization/Test/Resources/Schemas/ns0.xsd
new file mode 100644 (file)
index 0000000..2ac161f
--- /dev/null
@@ -0,0 +1,42 @@
+<?xml version="1.0" encoding="shift_jis"?>
+<xs:schema xmlns:tns="http://schemas.microsoft.com/2003/10/Serialization/" attributeFormDefault="qualified" elementFormDefault="qualified" targetNamespace="http://schemas.microsoft.com/2003/10/Serialization/" xmlns:xs="http://www.w3.org/2001/XMLSchema">
+  <xs:element name="anyType" nillable="true" type="xs:anyType" />
+  <xs:element name="anyURI" nillable="true" type="xs:anyURI" />
+  <xs:element name="base64Binary" nillable="true" type="xs:base64Binary" />
+  <xs:element name="boolean" nillable="true" type="xs:boolean" />
+  <xs:element name="byte" nillable="true" type="xs:byte" />
+  <xs:element name="dateTime" nillable="true" type="xs:dateTime" />
+  <xs:element name="decimal" nillable="true" type="xs:decimal" />
+  <xs:element name="double" nillable="true" type="xs:double" />
+  <xs:element name="float" nillable="true" type="xs:float" />
+  <xs:element name="int" nillable="true" type="xs:int" />
+  <xs:element name="long" nillable="true" type="xs:long" />
+  <xs:element name="QName" nillable="true" type="xs:QName" />
+  <xs:element name="short" nillable="true" type="xs:short" />
+  <xs:element name="string" nillable="true" type="xs:string" />
+  <xs:element name="unsignedByte" nillable="true" type="xs:unsignedByte" />
+  <xs:element name="unsignedInt" nillable="true" type="xs:unsignedInt" />
+  <xs:element name="unsignedLong" nillable="true" type="xs:unsignedLong" />
+  <xs:element name="unsignedShort" nillable="true" type="xs:unsignedShort" />
+  <xs:element name="char" nillable="true" type="tns:char" />
+  <xs:simpleType name="char">
+    <xs:restriction base="xs:int" />
+  </xs:simpleType>
+  <xs:element name="duration" nillable="true" type="tns:duration" />
+  <xs:simpleType name="duration">
+    <xs:restriction base="xs:duration">
+      <xs:pattern value="\-?P(\d*D)?(T(\d*H)?(\d*M)?(\d*(\.\d*)?S)?)?" />
+      <xs:minInclusive value="-P10675199DT2H48M5.4775808S" />
+      <xs:maxInclusive value="P10675199DT2H48M5.4775807S" />
+    </xs:restriction>
+  </xs:simpleType>
+  <xs:element name="guid" nillable="true" type="tns:guid" />
+  <xs:simpleType name="guid">
+    <xs:restriction base="xs:string">
+      <xs:pattern value="[\da-fA-F]{8}-[\da-fA-F]{4}-[\da-fA-F]{4}-[\da-fA-F]{4}-[\da-fA-F]{12}" />
+    </xs:restriction>
+  </xs:simpleType>
+  <xs:attribute name="FactoryType" type="xs:QName" />
+  <xs:attribute name="Id" type="xs:ID" />
+  <xs:attribute name="Ref" type="xs:IDREF" />
+</xs:schema>
diff --git a/mcs/class/System.Runtime.Serialization/Test/Resources/Schemas/ns1.xsd b/mcs/class/System.Runtime.Serialization/Test/Resources/Schemas/ns1.xsd
new file mode 100644 (file)
index 0000000..7af602b
--- /dev/null
@@ -0,0 +1,15 @@
+<xs:schema targetNamespace="urn:foo" 
+    xmlns="urn:foo" xmlns:x="urn:bar"
+    xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified">
+  <xs:import namespace="urn:bar" schemaLocation="ns2.xsd" />
+
+  <xs:element name="E1" type="T1" />
+  <xs:complexType name="T1"><xs:complexContent>
+    <xs:extension base="x:T1">
+      <xs:sequence>
+        <xs:element name="T2" />
+      </xs:sequence>
+    </xs:extension>
+  </xs:complexContent></xs:complexType>
+  <xs:element name="T2" type="xs:string" />
+</xs:schema>
diff --git a/mcs/class/System.Runtime.Serialization/Test/Resources/Schemas/ns10.xsd b/mcs/class/System.Runtime.Serialization/Test/Resources/Schemas/ns10.xsd
new file mode 100644 (file)
index 0000000..e1abc3c
--- /dev/null
@@ -0,0 +1,10 @@
+<xs:schema targetNamespace="urn:bar" xmlns="urn:bar"
+    xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified">
+  <xs:element name="E1" type="T1" />
+  <xs:complexType name="T1">
+    <xs:sequence>
+      <xs:element name="c1" type="xs:string" />
+    </xs:sequence>
+  </xs:complexType>
+  <xs:element name="E2" substitutionGroup="E1" />
+</xs:schema>
diff --git a/mcs/class/System.Runtime.Serialization/Test/Resources/Schemas/ns11.xsd b/mcs/class/System.Runtime.Serialization/Test/Resources/Schemas/ns11.xsd
new file mode 100644 (file)
index 0000000..f295cec
--- /dev/null
@@ -0,0 +1,11 @@
+<xs:schema targetNamespace="urn:bar" xmlns="urn:bar"
+    xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified">
+  <xs:element name="E1" type="T1" />
+  <xs:complexType name="T1">
+    <xs:choice>
+      <xs:element name="c1" type="xs:string" />
+      <xs:element name="c2" type="xs:string" />
+      <xs:element name="c3" type="xs:string" />
+    </xs:choice>
+  </xs:complexType>
+</xs:schema>
diff --git a/mcs/class/System.Runtime.Serialization/Test/Resources/Schemas/ns12.xsd b/mcs/class/System.Runtime.Serialization/Test/Resources/Schemas/ns12.xsd
new file mode 100644 (file)
index 0000000..991a530
--- /dev/null
@@ -0,0 +1,11 @@
+<xs:schema targetNamespace="urn:bar" xmlns="urn:bar"
+    xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified">
+  <xs:element name="E1" type="T1" />
+  <xs:complexType name="T1">
+    <xs:all>
+      <xs:element name="c1" type="xs:string" />
+      <xs:element name="c2" type="xs:string" />
+      <xs:element name="c3" type="xs:string" />
+    </xs:all>
+  </xs:complexType>
+</xs:schema>
diff --git a/mcs/class/System.Runtime.Serialization/Test/Resources/Schemas/ns13.xsd b/mcs/class/System.Runtime.Serialization/Test/Resources/Schemas/ns13.xsd
new file mode 100644 (file)
index 0000000..2b47f11
--- /dev/null
@@ -0,0 +1,9 @@
+<xs:schema targetNamespace="urn:bar" xmlns="urn:bar"
+    xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified">
+  <xs:element name="E1" type="T1" />
+  <xs:complexType name="T1">
+    <xs:sequence>
+      <xs:any />
+    </xs:sequence>
+  </xs:complexType>
+</xs:schema>
diff --git a/mcs/class/System.Runtime.Serialization/Test/Resources/Schemas/ns14.xsd b/mcs/class/System.Runtime.Serialization/Test/Resources/Schemas/ns14.xsd
new file mode 100644 (file)
index 0000000..50cb808
--- /dev/null
@@ -0,0 +1,11 @@
+<xs:schema targetNamespace="urn:bar" xmlns="urn:bar" xmlns:x="urn:bar"
+    xmlns:m="http://schemas.microsoft.com/2003/10/Serialization/"
+    xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified">
+  <xs:element name="E1" type="T1" nillable="true" />
+  <xs:simpleType name="T1">
+    <xs:restriction base="xs:string">
+      <xs:enumeration value="x" />
+      <xs:enumeration value="y" />
+    </xs:restriction>
+  </xs:simpleType>
+</xs:schema>
diff --git a/mcs/class/System.Runtime.Serialization/Test/Resources/Schemas/ns15.xsd b/mcs/class/System.Runtime.Serialization/Test/Resources/Schemas/ns15.xsd
new file mode 100644 (file)
index 0000000..3ad7b46
--- /dev/null
@@ -0,0 +1,14 @@
+<xs:schema targetNamespace="urn:bar" xmlns="urn:bar" xmlns:x="urn:bar"
+    xmlns:m="http://schemas.microsoft.com/2003/10/Serialization/"
+    xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified">
+  <xs:element name="E1" type="T1" nillable="true" />
+  <xs:simpleType name="T1">
+    <xs:restriction base="xs:string">
+      <xs:enumeration value="x" />
+    </xs:restriction>
+  </xs:simpleType>
+  <xs:element name="E2" type="T2" nillable="true" />
+  <xs:simpleType name="T2">
+    <xs:list itemType="xs:string"/>
+  </xs:simpleType>
+</xs:schema>
diff --git a/mcs/class/System.Runtime.Serialization/Test/Resources/Schemas/ns16.xsd b/mcs/class/System.Runtime.Serialization/Test/Resources/Schemas/ns16.xsd
new file mode 100644 (file)
index 0000000..248e2fe
--- /dev/null
@@ -0,0 +1,20 @@
+<xs:schema targetNamespace="urn:bar" xmlns="urn:bar" xmlns:x="urn:bar"
+    xmlns:m="http://schemas.microsoft.com/2003/10/Serialization/"
+    xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified">
+  <xs:element name="E1" type="T1" nillable="true" />
+  <xs:simpleType name="T1">
+    <xs:restriction base="xs:string">
+      <xs:enumeration value="x" />
+    </xs:restriction>
+  </xs:simpleType>
+  <xs:element name="E2" type="T2" nillable="true" />
+  <xs:simpleType name="T2">
+    <xs:list>
+      <xs:simpleType>
+        <xs:restriction base="xs:string">
+          <xs:enumeration value="x" />
+        </xs:restriction>
+      </xs:simpleType>
+    </xs:list>
+  </xs:simpleType>
+</xs:schema>
diff --git a/mcs/class/System.Runtime.Serialization/Test/Resources/Schemas/ns17.xsd b/mcs/class/System.Runtime.Serialization/Test/Resources/Schemas/ns17.xsd
new file mode 100644 (file)
index 0000000..a945bff
--- /dev/null
@@ -0,0 +1,19 @@
+<xs:schema targetNamespace="urn:bar" xmlns="urn:bar" xmlns:x="urn:bar"
+    xmlns:m="http://schemas.microsoft.com/2003/10/Serialization/"
+    xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified">
+  <xs:element name="E1" type="T1" nillable="true" />
+  <xs:simpleType name="T1">
+    <xs:restriction base="xs:string">
+      <xs:enumeration value="x" />
+    </xs:restriction>
+  </xs:simpleType>
+  <xs:element name="E2" type="T2" nillable="true" />
+  <xs:simpleType name="T2">
+    <xs:list itemType="T3" />
+  </xs:simpleType>
+  <xs:simpleType name="T3">
+    <xs:restriction base="xs:string">
+      <xs:enumeration value="x" />
+    </xs:restriction>
+  </xs:simpleType>
+</xs:schema>
diff --git a/mcs/class/System.Runtime.Serialization/Test/Resources/Schemas/ns18.xsd b/mcs/class/System.Runtime.Serialization/Test/Resources/Schemas/ns18.xsd
new file mode 100644 (file)
index 0000000..4e0cce5
--- /dev/null
@@ -0,0 +1,11 @@
+<xs:schema targetNamespace="urn:bar" xmlns="urn:bar" xmlns:x="urn:bar"
+    xmlns:m="http://schemas.microsoft.com/2003/10/Serialization/"
+    xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified">
+  <xs:element name="E1" type="T1" nillable="true" />
+  <xs:simpleType name="T1">
+    <xs:restriction base="xs:int">
+      <xs:enumeration value="0" />
+      <xs:enumeration value="1" />
+    </xs:restriction>
+  </xs:simpleType>
+</xs:schema>
diff --git a/mcs/class/System.Runtime.Serialization/Test/Resources/Schemas/ns19.xsd b/mcs/class/System.Runtime.Serialization/Test/Resources/Schemas/ns19.xsd
new file mode 100644 (file)
index 0000000..8f60a50
--- /dev/null
@@ -0,0 +1,20 @@
+<xs:schema targetNamespace="urn:bar" xmlns="urn:bar" xmlns:x="urn:bar"
+    xmlns:m="http://schemas.microsoft.com/2003/10/Serialization/"
+    xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified">
+  <xs:element name="E1" type="T1" nillable="true" />
+  <xs:simpleType name="T1">
+    <xs:restriction base="xs:int">
+      <xs:enumeration value="0" />
+    </xs:restriction>
+  </xs:simpleType>
+  <xs:element name="E2" type="T2" nillable="true" />
+  <xs:simpleType name="T2">
+    <xs:list>
+      <xs:simpleType>
+        <xs:restriction base="xs:int">
+          <xs:enumeration value="1" />
+        </xs:restriction>
+      </xs:simpleType>
+    </xs:list>
+  </xs:simpleType>
+</xs:schema>
diff --git a/mcs/class/System.Runtime.Serialization/Test/Resources/Schemas/ns2.xsd b/mcs/class/System.Runtime.Serialization/Test/Resources/Schemas/ns2.xsd
new file mode 100644 (file)
index 0000000..b457922
--- /dev/null
@@ -0,0 +1,9 @@
+<xs:schema targetNamespace="urn:bar" xmlns="urn:bar"
+    xmlns:xs="http://www.w3.org/2001/XMLSchema">
+  <xs:element name="E1" type="T1" />
+  <xs:complexType name="T1">
+    <xs:sequence>
+    </xs:sequence>
+  </xs:complexType>
+  <xs:element name="E2" type="xs:string" />
+</xs:schema>
diff --git a/mcs/class/System.Runtime.Serialization/Test/Resources/Schemas/ns20.xsd b/mcs/class/System.Runtime.Serialization/Test/Resources/Schemas/ns20.xsd
new file mode 100644 (file)
index 0000000..daa90c8
--- /dev/null
@@ -0,0 +1,21 @@
+<xs:schema targetNamespace="urn:bar" xmlns="urn:bar" xmlns:x="urn:bar"
+    xmlns:m="http://schemas.microsoft.com/2003/10/Serialization/"
+    xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified">
+  <xs:element name="E1" type="T1" nillable="true" />
+  <xs:simpleType name="T1">
+    <xs:restriction base="xs:string">
+      <xs:enumeration value="x" />
+    </xs:restriction>
+  </xs:simpleType>
+  <xs:element name="E2" type="T2" nillable="true" />
+  <xs:simpleType name="T2">
+    <xs:list>
+      <xs:simpleType>
+        <xs:restriction base="xs:string">
+          <xs:enumeration value="x" />
+          <xs:maxLength value="10" />
+        </xs:restriction>
+      </xs:simpleType>
+    </xs:list>
+  </xs:simpleType>
+</xs:schema>
diff --git a/mcs/class/System.Runtime.Serialization/Test/Resources/Schemas/ns21.xsd b/mcs/class/System.Runtime.Serialization/Test/Resources/Schemas/ns21.xsd
new file mode 100644 (file)
index 0000000..52ebba1
--- /dev/null
@@ -0,0 +1,9 @@
+<?xml version="1.0" encoding="utf-8"?>
+<xs:schema elementFormDefault="qualified" targetNamespace="http://schemas.microsoft.com/2003/10/Serialization/Arrays" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:tns="http://schemas.microsoft.com/2003/10/Serialization/Arrays">
+  <xs:complexType name="ArrayOfint">
+    <xs:sequence>
+      <xs:element minOccurs="0" maxOccurs="unbounded" name="int" type="xs:int" />
+    </xs:sequence>
+  </xs:complexType>
+  <xs:element name="ArrayOfint" nillable="true" type="tns:ArrayOfint" />
+</xs:schema>
diff --git a/mcs/class/System.Runtime.Serialization/Test/Resources/Schemas/ns22.xsd b/mcs/class/System.Runtime.Serialization/Test/Resources/Schemas/ns22.xsd
new file mode 100644 (file)
index 0000000..9113145
--- /dev/null
@@ -0,0 +1,17 @@
+<xs:schema targetNamespace="urn:bar" xmlns="urn:bar" xmlns:x="urn:bar"
+    xmlns:m="http://schemas.microsoft.com/2003/10/Serialization/"
+    elementFormDefault="qualified" xmlns:xs="http://www.w3.org/2001/XMLSchema">
+  <xs:import namespace="http://schemas.microsoft.com/2003/10/Serialization/" />
+  <xs:element name="E2" type="x:T2" nillable="true" />
+  <xs:complexType name="T2">
+    <xs:complexContent>
+      <xs:extension base="T1">
+        <xs:attribute ref="m:Ref" use="optional" />
+        <xs:attribute ref="m:Id" use="optional" />
+      </xs:extension>
+    </xs:complexContent>
+  </xs:complexType>
+  <xs:complexType name="T1">
+    <xs:sequence />
+  </xs:complexType>
+</xs:schema>
diff --git a/mcs/class/System.Runtime.Serialization/Test/Resources/Schemas/ns23.xsd b/mcs/class/System.Runtime.Serialization/Test/Resources/Schemas/ns23.xsd
new file mode 100644 (file)
index 0000000..15833a1
--- /dev/null
@@ -0,0 +1,12 @@
+<?xml version="1.0" encoding="utf-8"?>
+<xs:schema elementFormDefault="qualified" targetNamespace="http://schemas.microsoft.com/2003/10/Serialization/Arrays" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:tns="http://schemas.microsoft.com/2003/10/Serialization/Arrays">
+  <xs:complexType name="ArrayOfX">
+    <xs:sequence>
+      <xs:element minOccurs="0" maxOccurs="unbounded" name="guid" type="tns:X" />
+    </xs:sequence>
+  </xs:complexType>
+  <xs:element name="ArrayOfint" nillable="true" type="tns:ArrayOfX" />
+  <xs:complexType name="X">
+    <xs:sequence><xs:element name="y" type="xs:string" /></xs:sequence>
+  </xs:complexType>
+</xs:schema>
diff --git a/mcs/class/System.Runtime.Serialization/Test/Resources/Schemas/ns24.xsd b/mcs/class/System.Runtime.Serialization/Test/Resources/Schemas/ns24.xsd
new file mode 100644 (file)
index 0000000..b637752
--- /dev/null
@@ -0,0 +1,10 @@
+<?xml version="1.0" encoding="utf-8"?>
+<xs:schema elementFormDefault="qualified" targetNamespace="http://schemas.microsoft.com/2003/10/Serialization/Arrays" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:tns="http://schemas.microsoft.com/2003/10/Serialization/Arrays">
+  <xs:complexType name="ArrayOfint">
+    <xs:sequence>
+      <xs:element minOccurs="0" maxOccurs="unbounded" name="int" type="xs:int" />
+      <xs:element minOccurs="0" name="ext" type="xs:int" />
+    </xs:sequence>
+  </xs:complexType>
+  <xs:element name="ArrayOfint" nillable="true" type="tns:ArrayOfint" />
+</xs:schema>
diff --git a/mcs/class/System.Runtime.Serialization/Test/Resources/Schemas/ns25.xsd b/mcs/class/System.Runtime.Serialization/Test/Resources/Schemas/ns25.xsd
new file mode 100644 (file)
index 0000000..c88eadd
--- /dev/null
@@ -0,0 +1,15 @@
+<?xml version="1.0" encoding="utf-8"?>
+<xs:schema elementFormDefault="qualified" targetNamespace="http://schemas.microsoft.com/2003/10/Serialization/Arrays" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:tns="http://schemas.microsoft.com/2003/10/Serialization/Arrays">
+  <xs:complexType name="ArrayOfint">
+    <xs:sequence>
+      <xs:element minOccurs="0" maxOccurs="unbounded" name="int" type="xs:int" />
+    </xs:sequence>
+  </xs:complexType>
+  <xs:element name="ArrayOfint" nillable="true" type="tns:ArrayOfint" />
+  <xs:complexType name="T1">
+    <xs:sequence>
+      <xs:element name="arr" type="tns:ArrayOfint" />
+    </xs:sequence>
+  </xs:complexType>
+  <xs:element name="E1" type="tns:T1" />
+</xs:schema>
diff --git a/mcs/class/System.Runtime.Serialization/Test/Resources/Schemas/ns26.xsd b/mcs/class/System.Runtime.Serialization/Test/Resources/Schemas/ns26.xsd
new file mode 100644 (file)
index 0000000..9932b7d
--- /dev/null
@@ -0,0 +1,20 @@
+<?xml version="1.0" encoding="utf-8"?>
+<xs:schema elementFormDefault="qualified" targetNamespace="http://schemas.microsoft.com/2003/10/Serialization/Arrays" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:tns="http://schemas.microsoft.com/2003/10/Serialization/Arrays">
+  <xs:simpleType name="X">
+    <xs:restriction base="xs:string">
+      <xs:enumeration value="s1" />
+      <xs:enumeration value="s2" />
+    </xs:restriction>
+  </xs:simpleType>
+  <xs:complexType name="ArrayOfint">
+    <xs:sequence>
+      <xs:element minOccurs="0" maxOccurs="unbounded" name="int" type="tns:X" />
+    </xs:sequence>
+  </xs:complexType>
+  <xs:complexType name="T1">
+    <xs:sequence>
+      <xs:element name="arr" type="tns:ArrayOfint" />
+    </xs:sequence>
+  </xs:complexType>
+  <xs:element name="E1" type="tns:T1" />
+</xs:schema>
diff --git a/mcs/class/System.Runtime.Serialization/Test/Resources/Schemas/ns27.xsd b/mcs/class/System.Runtime.Serialization/Test/Resources/Schemas/ns27.xsd
new file mode 100644 (file)
index 0000000..8a8a733
--- /dev/null
@@ -0,0 +1,14 @@
+<?xml version="1.0" encoding="utf-8"?>
+<xs:schema elementFormDefault="qualified" targetNamespace="urn:foo" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:tns="urn:foo">
+  <xs:complexType name="ArrayOfint">
+    <xs:sequence>
+      <xs:element minOccurs="0" maxOccurs="unbounded" name="int" type="xs:int" />
+    </xs:sequence>
+  </xs:complexType>
+  <xs:complexType name="T1">
+    <xs:sequence>
+      <xs:element name="arr" type="tns:ArrayOfint" />
+    </xs:sequence>
+  </xs:complexType>
+  <xs:element name="E1" type="tns:T1" />
+</xs:schema>
diff --git a/mcs/class/System.Runtime.Serialization/Test/Resources/Schemas/ns3.xsd b/mcs/class/System.Runtime.Serialization/Test/Resources/Schemas/ns3.xsd
new file mode 100644 (file)
index 0000000..b0bddc2
--- /dev/null
@@ -0,0 +1,12 @@
+<xs:schema targetNamespace="urn:bar" xmlns="urn:bar"
+    xmlns:xs="http://www.w3.org/2001/XMLSchema">
+  <xs:element name="E2" type="T2" />
+  <xs:complexType name="T2">
+    <xs:simpleContent>
+      <xs:extension base="xs:string">
+        <xs:attribute name="a1" type="xs:string" />
+        <xs:attribute name="a2" type="xs:int" />
+      </xs:extension>
+    </xs:simpleContent>
+  </xs:complexType>
+</xs:schema>
diff --git a/mcs/class/System.Runtime.Serialization/Test/Resources/Schemas/ns4.xsd b/mcs/class/System.Runtime.Serialization/Test/Resources/Schemas/ns4.xsd
new file mode 100644 (file)
index 0000000..edac2b5
--- /dev/null
@@ -0,0 +1,8 @@
+<xs:schema targetNamespace="urn:bar" xmlns="urn:bar"
+    xmlns:xs="http://www.w3.org/2001/XMLSchema">
+  <xs:element name="E2" type="T2" />
+  <xs:complexType name="T2">
+    <xs:attribute name="a1" type="xs:string" />
+    <xs:attribute name="a2" type="xs:int" />
+  </xs:complexType>
+</xs:schema>
diff --git a/mcs/class/System.Runtime.Serialization/Test/Resources/Schemas/ns5.xsd b/mcs/class/System.Runtime.Serialization/Test/Resources/Schemas/ns5.xsd
new file mode 100644 (file)
index 0000000..b3914ea
--- /dev/null
@@ -0,0 +1,12 @@
+<xs:schema targetNamespace="urn:bar" xmlns="urn:bar" xmlns:x="urn:bar"
+    elementFormDefault="qualified" xmlns:xs="http://www.w3.org/2001/XMLSchema">
+  <xs:element name="E2" type="x:T2" nillable="true" />
+  <xs:complexType name="T2">
+    <xs:complexContent>
+      <xs:extension base="xs:anyType">
+        <xs:attribute name="a1" type="xs:string" use="optional" />
+        <xs:attribute name="a2" type="xs:int" use="optional" />
+      </xs:extension>
+    </xs:complexContent>
+  </xs:complexType>
+</xs:schema>
diff --git a/mcs/class/System.Runtime.Serialization/Test/Resources/Schemas/ns6.xsd b/mcs/class/System.Runtime.Serialization/Test/Resources/Schemas/ns6.xsd
new file mode 100644 (file)
index 0000000..4deccd5
--- /dev/null
@@ -0,0 +1,31 @@
+<xs:schema targetNamespace="urn:bar" xmlns="urn:bar" xmlns:x="urn:bar"
+    xmlns:m="http://schemas.microsoft.com/2003/10/Serialization/"
+    xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified">
+  <xs:import namespace="http://schemas.microsoft.com/2003/10/Serialization/" />
+  <xs:element name="E2" type="T2" nillable="true" />
+  <xs:complexType name="T1">
+    <xs:sequence>
+      <xs:element name="c1" type="xs:string" nillable="true" />
+      <xs:element name="c2" type="xs:int" nillable="true" />
+      <xs:element name="c3" type="xs:duration" nillable="true" />
+    </xs:sequence>
+  </xs:complexType>
+  <xs:complexType name="T2">
+    <xs:complexContent>
+      <xs:extension base="T1">
+    <xs:sequence>
+      <xs:element name="c1" type="xs:string" nillable="true" />
+      <xs:element name="c2" type="xs:int" nillable="true" />
+      <xs:element name="c3" type="xs:duration" nillable="true" />
+      <xs:element name="c4" type="m:guid" nillable="true" />
+    </xs:sequence>
+      </xs:extension>
+    </xs:complexContent>
+  </xs:complexType>
+  <xs:element name="E3" type="xs:anyType"/>
+    <xs:simpleType name="T3">
+      <xs:restriction base="xs:string">
+        <xs:enumeration value="x" />
+      </xs:restriction>
+    </xs:simpleType>
+</xs:schema>
diff --git a/mcs/class/System.Runtime.Serialization/Test/Resources/Schemas/ns7.xsd b/mcs/class/System.Runtime.Serialization/Test/Resources/Schemas/ns7.xsd
new file mode 100644 (file)
index 0000000..43c9af7
--- /dev/null
@@ -0,0 +1,26 @@
+<xs:schema targetNamespace="urn:bar" xmlns="urn:bar" xmlns:x="urn:bar"
+    xmlns:m="http://schemas.microsoft.com/2003/10/Serialization/"
+    xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified">
+  <xs:import namespace="http://schemas.microsoft.com/2003/10/Serialization/" />
+  <xs:element name="E2" type="T2" nillable="true" />
+  <xs:complexType name="T1">
+    <xs:sequence>
+      <xs:element name="c1" type="xs:string" nillable="true" />
+      <xs:element name="c2" type="xs:int" nillable="true" />
+      <xs:element name="c3" type="xs:duration" nillable="true" />
+      <xs:element name="c4" type="m:guid" nillable="true" />
+    </xs:sequence>
+  </xs:complexType>
+  <xs:complexType name="T2">
+    <xs:complexContent>
+      <xs:restriction base="T1">
+    <xs:sequence>
+      <xs:element name="c1" type="xs:string" nillable="true" />
+      <xs:element name="c2" type="xs:int" nillable="true" />
+      <xs:element name="c3" type="xs:duration" nillable="true" />
+      <xs:element name="c4" type="m:guid" nillable="false" />
+    </xs:sequence>
+      </xs:restriction>
+    </xs:complexContent>
+  </xs:complexType>
+</xs:schema>
diff --git a/mcs/class/System.Runtime.Serialization/Test/Resources/Schemas/ns8.xsd b/mcs/class/System.Runtime.Serialization/Test/Resources/Schemas/ns8.xsd
new file mode 100644 (file)
index 0000000..d125dae
--- /dev/null
@@ -0,0 +1,19 @@
+<xs:schema targetNamespace="urn:bar" xmlns="urn:bar" 
+    elementFormDefault="qualified" xmlns:xs="http://www.w3.org/2001/XMLSchema">
+  <xs:element name="E2" type="T2" />
+  <xs:complexType name="T2">
+    <xs:simpleContent>
+      <xs:restriction base="T1">
+        <xs:enumeration value="v1" />
+        <xs:enumeration value="v2" />
+        <xs:enumeration value="v3" />
+      </xs:restriction>
+    </xs:simpleContent>
+  </xs:complexType>
+  <xs:complexType name="T1">
+    <xs:simpleContent>
+      <xs:extension base="xs:string">
+      </xs:extension>
+    </xs:simpleContent>
+  </xs:complexType>
+</xs:schema>
diff --git a/mcs/class/System.Runtime.Serialization/Test/Resources/Schemas/ns9.xsd b/mcs/class/System.Runtime.Serialization/Test/Resources/Schemas/ns9.xsd
new file mode 100644 (file)
index 0000000..5695c26
--- /dev/null
@@ -0,0 +1,11 @@
+<xs:schema targetNamespace="urn:bar" xmlns="urn:bar"
+    xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified">
+  <xs:element name="E1" type="T1" />
+  <xs:complexType name="T1">
+    <xs:sequence>
+      <xs:element name="c1" type="xs:string" />
+      <xs:element name="c1" type="xs:string" />
+      <xs:element name="c1" type="xs:string" />
+    </xs:sequence>
+  </xs:complexType>
+</xs:schema>
index fb073baa391d5372ae6e02bc4702d4babb5714fd..f11b69847b8b56149c267419c6627aa9cac75c10 100644 (file)
@@ -1,3 +1,8 @@
+2010-02-17  Atsushi Enomoto  <atsushi@ximian.com>
+
+       * XsdDataContractImporterTest.cs : added a bunch of tests for new
+         implementation. Disable yet.
+
 2010-02-09  Atsushi Enomoto  <atsushi@ximian.com>
 
        * XsdDataContractImporterTest.cs : add test that it gives
index 6cd8da7074fb1a9923c306a629e3057fe6cad905..713e9822c62bf5668dd6ac6c2f2a5534a84186b2 100644 (file)
@@ -409,6 +409,208 @@ namespace MonoTests.System.Runtime.Serialization
                        Assert.IsTrue (t, "te");
                }
 
+#if false // FIXME: enable when we switch to the new implementation.
+
+               CodeCompileUnit DoImport (params string [] schemaFiles)
+               {
+                       var ccu = new CodeCompileUnit ();
+                       var xdi = new XsdDataContractImporter (ccu);
+                       var xss = new XmlSchemaSet ();
+                       foreach (var schemaFile in schemaFiles)
+                               xss.Add (null, schemaFile);
+                       xdi.Import (xss);
+
+                       return ccu;
+               }
+
+               // FIXME: this set of tests need further assertion in each test case. Right now it just checks if things import or fail just fine.
+
+               [Test]
+               public void ImportTestX0 ()
+               {
+                       DoImport ("Test/Resources/Schemas/ns0.xsd");
+               }
+
+               [Test]
+               public void ImportTestX1 ()
+               {
+                       DoImport ("Test/Resources/Schemas/ns1.xsd");
+               }
+
+               [Test]
+               public void ImportTestX2 ()
+               {
+                       DoImport ("Test/Resources/Schemas/ns2.xsd");
+               }
+
+               [Test]
+               [ExpectedException (typeof (InvalidDataContractException))]
+               public void ImportTestX3 ()
+               {
+                       DoImport ("Test/Resources/Schemas/ns3.xsd");
+               }
+
+               [Test]
+               [ExpectedException (typeof (InvalidDataContractException))]
+               public void ImportTestX4 ()
+               {
+                       DoImport ("Test/Resources/Schemas/ns4.xsd");
+               }
+
+               [Test]
+               [ExpectedException (typeof (InvalidDataContractException))]
+               public void ImportTestX5 ()
+               {
+                       DoImport ("Test/Resources/Schemas/ns5.xsd");
+               }
+
+               [Test]
+               public void ImportTestX6 ()
+               {
+                       DoImport ("Test/Resources/Schemas/ns6.xsd",
+                                 "Test/Resources/Schemas/ns0.xsd");
+               }
+
+               [Test]
+               [ExpectedException (typeof (InvalidDataContractException))]
+               public void ImportTestX7 ()
+               {
+                       DoImport ("Test/Resources/Schemas/ns7.xsd",
+                                 "Test/Resources/Schemas/ns0.xsd");
+               }
+
+               [Test]
+               [ExpectedException (typeof (InvalidDataContractException))]
+               public void ImportTestX8 ()
+               {
+                       DoImport ("Test/Resources/Schemas/ns8.xsd");
+               }
+
+               [Test]
+               [ExpectedException (typeof (InvalidDataContractException))]
+               public void ImportTestX9 ()
+               {
+                       DoImport ("Test/Resources/Schemas/ns9.xsd");
+               }
+
+               [Test]
+               public void ImportTestX10 ()
+               {
+                       DoImport ("Test/Resources/Schemas/ns10.xsd");
+               }
+
+               [Test]
+               [ExpectedException (typeof (InvalidDataContractException))]
+               public void ImportTestX11 ()
+               {
+                       DoImport ("Test/Resources/Schemas/ns11.xsd");
+               }
+
+               [Test]
+               [ExpectedException (typeof (InvalidDataContractException))]
+               public void ImportTestX12 ()
+               {
+                       DoImport ("Test/Resources/Schemas/ns12.xsd");
+               }
+
+               [Test]
+               [ExpectedException (typeof (InvalidDataContractException))]
+               public void ImportTestX13 ()
+               {
+                       DoImport ("Test/Resources/Schemas/ns13.xsd");
+               }
+
+               [Test]
+               public void ImportTestX14 ()
+               {
+                       DoImport ("Test/Resources/Schemas/ns14.xsd");
+               }
+
+               [Test]
+               [ExpectedException (typeof (InvalidDataContractException))]
+               public void ImportTestX15 ()
+               {
+                       DoImport ("Test/Resources/Schemas/ns15.xsd");
+               }
+
+               [Test]
+               public void ImportTestX16 ()
+               {
+                       DoImport ("Test/Resources/Schemas/ns16.xsd");
+               }
+
+               [Test]
+               [ExpectedException (typeof (InvalidDataContractException))]
+               public void ImportTestX17 ()
+               {
+                       DoImport ("Test/Resources/Schemas/ns17.xsd");
+               }
+
+               [Test]
+               public void ImportTestX18 ()
+               {
+                       DoImport ("Test/Resources/Schemas/ns18.xsd");
+               }
+
+               [Test]
+               [ExpectedException (typeof (InvalidDataContractException))]
+               public void ImportTestX19 ()
+               {
+                       DoImport ("Test/Resources/Schemas/ns19.xsd");
+               }
+
+               [Test]
+               [ExpectedException (typeof (InvalidDataContractException))]
+               public void ImportTestX20 ()
+               {
+                       DoImport ("Test/Resources/Schemas/ns20.xsd");
+               }
+
+               [Test]
+               public void ImportTestX21 ()
+               {
+                       DoImport ("Test/Resources/Schemas/ns21.xsd");
+               }
+
+               [Test]
+               public void ImportTestX22 ()
+               {
+                       DoImport ("Test/Resources/Schemas/ns22.xsd");
+               }
+
+               [Test]
+               public void ImportTestX23 ()
+               {
+                       DoImport ("Test/Resources/Schemas/ns23.xsd");
+               }
+
+               [ExpectedException (typeof (InvalidDataContractException))]
+               [Test]
+               public void ImportTestX24 ()
+               {
+                       DoImport ("Test/Resources/Schemas/ns24.xsd");
+               }
+
+               [Test]
+               public void ImportTestX25 ()
+               {
+                       DoImport ("Test/Resources/Schemas/ns25.xsd");
+               }
+
+               [Test]
+               public void ImportTestX26 ()
+               {
+                       DoImport ("Test/Resources/Schemas/ns26.xsd");
+               }
+
+               [Test]
+               public void ImportTestX27 ()
+               {
+                       DoImport ("Test/Resources/Schemas/ns27.xsd");
+               }
+
+#endif
+
                /* Helper methods */
                private void CheckDC (CodeTypeDeclaration type, string name, Dictionary<string, string> members, string msg)
                {