Merge pull request #496 from nicolas-raoul/unit-test-for-issue2907
authorMiguel de Icaza <miguel@gnome.org>
Fri, 7 Dec 2012 21:58:25 +0000 (13:58 -0800)
committerMiguel de Icaza <miguel@gnome.org>
Fri, 7 Dec 2012 21:58:25 +0000 (13:58 -0800)
Unit test for issue2907

mono/tests/Makefile.am
mono/tests/bug-2907.cs [new file with mode: 0644]

index 57e016c111ef1bc1aea96fd903a4b66c47c6f6e8..e1ce3f32373a87be1344f7222899a805f8db2366 100644 (file)
@@ -44,6 +44,7 @@ STRESS_TESTS_SRC=     \
 # Disabled until ?mcs is fixed
 #      bug-331958.cs
 BASE_TEST_CS_SRC=              \
+       bug-2907.cs             \
        array-init.cs           \
        arraylist.cs            \
        assemblyresolve_event.cs        \
diff --git a/mono/tests/bug-2907.cs b/mono/tests/bug-2907.cs
new file mode 100644 (file)
index 0000000..c1223c4
--- /dev/null
@@ -0,0 +1,132 @@
+using System;
+using System.IO;
+using System.Xml.Serialization;
+
+
+class Program
+{
+    static public T DeserializeFromString<T>(string xml) where T : class
+    {
+
+        if (String.IsNullOrEmpty(xml))
+        {
+            return null;
+        }
+
+        StringReader reader = null;
+        T deserializedObject = null;
+        try
+        {
+            reader = new StringReader(xml);
+            XmlSerializer serializer = new XmlSerializer(typeof(T));
+            deserializedObject = serializer.Deserialize(reader) as T;
+        }
+        finally
+        {
+            if (null != reader)
+            {
+                reader.Close();
+            }
+        }
+        return deserializedObject;
+    }
+
+
+    static void Main(string[] args)
+    {
+        string myXML = @"<?xml version=""1.0"" encoding=""utf-8""?><TASK><OptionA/></TASK>";
+
+        // The following line fails on Mono 2.8 2.10 2.10.8.1 2.10.9
+        TASK data = DeserializeFromString<TASK>(myXML);
+        if(data == null)
+        {
+            throw new Exception("A#01");
+        }
+        if(data.ItemElementName != ItemChoiceType.OptionA)
+        {
+            throw new Exception("A#02");
+        }
+    }
+}
+
+// Below is the code generated from the following XSD:
+/*
+<?xml version="1.0" encoding="UTF-8"?>
+<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified" attributeFormDefault="unqualified">
+        <xs:element name="TASK">
+                <xs:complexType>
+                        <xs:choice>
+                                <xs:element name="OptionA"/>
+                                <xs:element name="OptionB"/>
+                        </xs:choice>
+                </xs:complexType>
+        </xs:element>
+</xs:schema>
+*/
+
+//------------------------------------------------------------------------------
+// <auto-generated>
+//     This code was generated by a tool.
+//     Runtime Version:4.0.30319.239
+//
+//     Changes to this file may cause incorrect behavior and will be lost if
+//     the code is regenerated.
+// </auto-generated>
+//------------------------------------------------------------------------------
+
+// 
+// This source code was auto-generated by xsd, Version=4.0.30319.1.
+// 
+
+
+/// <remarks/>
+[System.CodeDom.Compiler.GeneratedCodeAttribute("xsd", "4.0.30319.1")]
+[System.SerializableAttribute()]
+[System.Diagnostics.DebuggerStepThroughAttribute()]
+[System.ComponentModel.DesignerCategoryAttribute("code")]
+[System.Xml.Serialization.XmlTypeAttribute(AnonymousType=true)]
+[System.Xml.Serialization.XmlRootAttribute(Namespace="", IsNullable=false)]
+public partial class TASK {
+    
+    private object itemField;
+    
+    private ItemChoiceType itemElementNameField;
+    
+    /// <remarks/>
+    [System.Xml.Serialization.XmlElementAttribute("OptionA", typeof(object), Order=0)]
+    [System.Xml.Serialization.XmlElementAttribute("OptionB", typeof(object), Order=0)]
+    [System.Xml.Serialization.XmlChoiceIdentifierAttribute("ItemElementName")]
+    public object Item {
+        get {
+            return this.itemField;
+        }
+        set {
+            this.itemField = value;
+        }
+    }
+    
+    /// <remarks/>
+    [System.Xml.Serialization.XmlElementAttribute(Order=1)]
+    [System.Xml.Serialization.XmlIgnoreAttribute()]
+    public ItemChoiceType ItemElementName {
+        get {
+            return this.itemElementNameField;
+        }
+        set {
+            this.itemElementNameField = value;
+        }
+    }
+}
+
+/// <remarks/>
+[System.CodeDom.Compiler.GeneratedCodeAttribute("xsd", "4.0.30319.1")]
+[System.SerializableAttribute()]
+[System.Xml.Serialization.XmlTypeAttribute(IncludeInSchema=false)]
+public enum ItemChoiceType {
+    
+    /// <remarks/>
+    OptionA,
+    
+    /// <remarks/>
+    OptionB,
+}