--- /dev/null
+//\r
+// ComplexDataStructure.cs\r
+//\r
+// Author:\r
+// Lluis Sanchez Gual (lluis@ximian.com)\r
+//\r
+// (C) 2004 Novell, Inc.\r
+//\r
+//\r
+using System;\r
+using System.IO;\r
+using System.Xml;\r
+using System.Xml.Schema;\r
+using System.Xml.Serialization;\r
+using System.Collections;\r
+using System.ComponentModel; \r
+using NUnit.Framework;\r
+\r
+namespace MonoTests.System.XmlSerialization\r
+{\r
+ [TestFixture]\r
+ public class ComplexDataStructure: Assertion\r
+ {\r
+ [Test]\r
+ public void TestWriteLiteral ()\r
+ {\r
+ Test data = BuildTestObject ();\r
+\r
+ XmlSerializer ss = new XmlSerializer (GetLiteralTypeMapping ());\r
+ XmlSerializerNamespaces nams = new XmlSerializerNamespaces ();\r
+ StringWriter sw = new StringWriter();\r
+ ss.Serialize (sw,data,nams);\r
+ string serialized = sw.ToString ();\r
+ serialized = XmlSerializerTests.Infoset (serialized);\r
+\r
+ StreamReader sr = new StreamReader ("Test/XmlFiles/literal-data.xml");\r
+ string expected = sr.ReadToEnd ();\r
+ sr.Close ();\r
+ \r
+ expected = XmlSerializerTests.Infoset (expected);\r
+ AssertEquals (expected, serialized);\r
+ }\r
+ \r
+ public void TestReadLiteral ()\r
+ {\r
+ XmlSerializer ss = new XmlSerializer (GetLiteralTypeMapping ());\r
+ XmlSerializerNamespaces nams = new XmlSerializerNamespaces ();\r
+ \r
+ StreamReader sr = new StreamReader ("Test/XmlFiles/literal-data.xml");\r
+ Test data = (Test) ss.Deserialize (sr);\r
+ sr.Close ();\r
+ \r
+ CheckObjectContent (BuildTestObject(), data);\r
+ }\r
+ \r
+ XmlTypeMapping GetLiteralTypeMapping ()\r
+ {\r
+ XmlRootAttribute root = new XmlRootAttribute("rootroot");\r
+ Type[] types = new Type[] {typeof(UknTestPart), typeof(AnotherTestPart), typeof(DblStringContainer) };\r
+ XmlReflectionImporter ri = new XmlReflectionImporter ();\r
+ foreach (Type t in types) ri.IncludeType (t);\r
+ return ri.ImportTypeMapping (typeof(Test), root);\r
+ }\r
+\r
+ XmlTypeMapping GetEncodedTypeMapping ()\r
+ {\r
+ SoapReflectionImporter sri = new SoapReflectionImporter ();\r
+ sri.IncludeType (typeof(UknTestPart));\r
+ sri.IncludeType (typeof(AnotherTestPart));\r
+ sri.IncludeType (typeof(DblStringContainer));\r
+ return sri.ImportTypeMapping (typeof(Test));\r
+ }\r
+ \r
+ Test BuildTestObject ()\r
+ {\r
+ XmlDocument doc = new XmlDocument();\r
+\r
+ Test t = new UknTestPart();\r
+ t.a = 1;\r
+ t.b = "hola";\r
+ t.bbis = t.b;\r
+ t.c = 44;\r
+ t.parts = new TestPart[3];\r
+ t.parts[0] = new TestPart();\r
+ t.parts[0].name = "un";\r
+ t.parts[0].bval = true;\r
+ t.parts[1] = new TestPart();\r
+ t.parts[1].name = "dos";\r
+ t.parts[1].bval = false;\r
+ t.parts[2] = t.parts[0];\r
+ t.part = t.parts[1];\r
+ t.strings = new string[] { "un", "dos", null, "tres" };\r
+ t.ushorts = new ushort[] { 1,2,3 };\r
+ t.ta = new TB();\r
+ t.ta.extraTextNodes = new XmlNode[] { doc.CreateTextNode ("AA"), doc.CreateTextNode ("BB") };\r
+\r
+ t.tam2 = new TA[][][]\r
+ {\r
+ new TA[][] { new TA[] {new TA(), new TA()}, new TA[] {new TA(), new TA()}},\r
+ new TA[][] { new TA[] {new TB(), new TA()}, new TA[] {new TB(), new TA()}},\r
+ new TA[][] { new TA[] {new TA(), new TB()}, new TA[] {new TA(), new TA()}} \r
+ };\r
+\r
+ t.tam3 = t.tam2;\r
+ t.flatParts = t.parts;\r
+\r
+ t.flatParts2 = new TA[] {new TA(), new TB(), null, new TB()};\r
+\r
+ t.anot = new AnotherTestPart ();\r
+ ((AnotherTestPart)t.anot).lo = 1234567890;\r
+\r
+ t.ob = t.parts[1];\r
+ t.ob2 = t.parts[1];\r
+\r
+ XmlElement e1 = doc.CreateElement ("explicitElement");\r
+ XmlElement e2 = doc.CreateElement ("subElement");\r
+ e2.SetAttribute ("unAtrib","val");\r
+ doc.AppendChild (e1);\r
+ e1.AppendChild (e2);\r
+\r
+ t.oneElem = e1;\r
+ t.oneElem2 = e1;\r
+ t.someElems = new XmlNode[3];\r
+ t.someElems[0] = e1;\r
+ t.someElems[1] = null;\r
+ t.someElems[2] = e2;\r
+\r
+ t.extraElems = new XmlElement[1];\r
+ t.extraElems[0] = doc.CreateElement ("extra1");\r
+ t.extraElems[0].SetAttribute ("val","1");\r
+\r
+ t.extraElems23 = new XmlElement[2];\r
+ t.extraElems23[0] = doc.CreateElement ("extra2");\r
+ t.extraElems23[0].SetAttribute ("val","2");\r
+ t.extraElems23[1] = doc.CreateElement ("extra3");\r
+ t.extraElems23[1].SetAttribute ("val","3");\r
+\r
+ t.extraElemsRest = doc.CreateElement ("extra4");\r
+ t.extraElemsRest.SetAttribute ("val","4");\r
+\r
+ t.uktester = new UnknownAttributeTester();\r
+ t.uktester.aa = "hihi";\r
+\r
+ t.uktester.extraAtts = new XmlAttribute[3];\r
+ t.uktester.extraAtts[0] = doc.CreateAttribute ("extraAtt1");\r
+ t.uktester.extraAtts[0].Value = "val1";\r
+ t.uktester.extraAtts[1] = doc.CreateAttribute ("extraAtt2");\r
+ t.uktester.extraAtts[1].Value = "val2";\r
+ t.uktester.extraAtts[2] = doc.CreateAttribute ("extraAtt3");\r
+ t.uktester.extraAtts[2].Value = "val3";\r
+\r
+ t.ob3 = 12345;\r
+ t.ob4 = (float)54321.12;\r
+\r
+ t.op1 = option.AA;\r
+ t.opArray = new option[] { option.CC, option.BB, option.AA };\r
+ t.ukOpt = option.DD;\r
+ t.opAtt = option.BB;\r
+\r
+ t.byteArray = new byte[] { 11,33,55,222 };\r
+ t.byteByteArray = new byte[][] { t.byteArray, t.byteArray };\r
+\r
+ t.ttList = new ArrayList();\r
+ t.ttList.Add ("two");\r
+ t.ttList.Add ("strings");\r
+ // t.extraText = "Additional text";\r
+\r
+ t.RoList = new ArrayList ();\r
+ t.RoList.Add (t.parts[0]);\r
+ t.RoList.Add (t.parts[1]);\r
+\r
+/* t.struc = new OneStruct();\r
+ t.struc.aa = 776655;\r
+ t.struc.cc = "this is a struct";\r
+*/\r
+ t.multiList = new ArrayList[2];\r
+ t.multiList[0] = new ArrayList ();\r
+ t.multiList[0].Add (22);\r
+ t.multiList[0].Add (33);\r
+ t.multiList[1] = new ArrayList ();\r
+ t.multiList[1].Add (888);\r
+ t.multiList[1].Add (999);\r
+\r
+\r
+ t.defElem = "theDefValue";\r
+ t.defAttr = "theDefValue";\r
+\r
+ t.special = new CustomHashtable ();\r
+ t.special.Add ("one","1");\r
+ t.special.Add ("two","2");\r
+ t.special.Add ("three","3");\r
+\r
+ t.attqname = new XmlQualifiedName ("thename","thenamespace");\r
+\r
+ DblStringContainer dbc = new DblStringContainer ();\r
+ dbc.doublestring = new string [][] { null, new string[] {"hello"} };\r
+ AnotherTestPart at = new AnotherTestPart ();\r
+ at.lo = 567;\r
+ dbc.at = at;\r
+\r
+ DblStringContainerAnm dbca = new DblStringContainerAnm ();\r
+ dbca.at = dbc;\r
+ t.dbscontainer = dbca;\r
+ \r
+ return t;\r
+ }\r
+ \r
+ void CheckObjectContent (Test exp, Test t)\r
+ {\r
+ AssertEquals ("t.a", exp.a, t.a);\r
+ AssertEquals ("t.b", exp.b, t.b);\r
+ AssertEquals ("t.bbis", exp.bbis, t.bbis);\r
+ AssertEquals ("t.c", exp.c, t.c);\r
+ \r
+ AssertNotNull ("t.parts", t.parts);\r
+ CheckParts ("t.parts", exp.parts, t.parts);\r
+ \r
+ TestPart.AssertEquals ("t.part", exp.part, t.part);\r
+ \r
+ AssertionHelper.AssertEqualsArray ("t.strings", exp.strings, t.strings);\r
+ AssertionHelper.AssertEqualsArray ("t.ushorts", exp.ushorts, t.ushorts);\r
+ \r
+ TA.AssertEquals ("t.ta", exp.ta, t.ta);\r
+\r
+ AssertNotNull ("t.tam2", t.tam2);\r
+ CheckTaArray ("t.tam2", exp.tam2, t.tam2);\r
+ \r
+ AssertNotNull ("t.tam3", t.tam3);\r
+ CheckTaArray ("t.tam3", exp.tam3, t.tam3);\r
+ \r
+ AssertNotNull ("t.flatParts", t.flatParts);\r
+ CheckParts ("t.flatParts", exp.flatParts, t.flatParts);\r
+\r
+ // Null element is ignored\r
+ AssertNotNull ("t.flatParts2", t.flatParts2);\r
+ AssertEquals ("t.flatParts2.Length", 3, t.flatParts2.Length);\r
+ TA.AssertEquals ("t.flatParts2 0", exp.flatParts2[0], t.flatParts2[0]);\r
+ TA.AssertEquals ("t.flatParts2 1", exp.flatParts2[1], t.flatParts2[1]);\r
+ TA.AssertEquals ("t.flatParts2 2", exp.flatParts2[3], t.flatParts2[2]);\r
+ \r
+ AssertNotNull ("t.anot", t.anot);\r
+ AssertEquals ("t.anot.lo", ((AnotherTestPart)exp.anot).lo, ((AnotherTestPart)t.anot).lo);\r
+\r
+ TestPart.AssertEquals ("t.ob", exp.ob as TestPart, t.ob as TestPart);\r
+ TestPart.AssertEquals ("t.ob2", exp.ob2 as TestPart, t.ob2 as TestPart);\r
+ \r
+ AssertionHelper.AssertEqualsXml ("t.oneElem", exp.oneElem, t.oneElem);\r
+ AssertionHelper.AssertEqualsXml ("t.oneElem2", exp.oneElem2, t.oneElem2);\r
+ \r
+ // One of the elements was null and it is ignored\r
+ AssertNotNull ("t.someElems", t.someElems);\r
+ AssertEquals ("t.someElems.Length", 2, t.someElems.Length);\r
+ AssertionHelper.AssertEqualsXml ("t.someElems[0]", exp.someElems[0], t.someElems[0]);\r
+ AssertionHelper.AssertEqualsXml ("t.someElems[1]", exp.someElems[2], t.someElems[1]);\r
+\r
+ AssertNotNull ("t.extraElems", t.extraElems);\r
+ AssertEquals ("t.extraElems.Length", exp.extraElems.Length, t.extraElems.Length);\r
+ for (int n=0; n<exp.extraElems.Length; n++)\r
+ AssertionHelper.AssertEqualsXml ("t.extraElems[" + n + "]", exp.extraElems[n], t.extraElems[n]);\r
+ \r
+ AssertNotNull ("t.extraElems23", t.extraElems23);\r
+ AssertEquals ("t.extraElems23.Length", exp.extraElems23.Length, t.extraElems23.Length);\r
+ for (int n=0; n<t.extraElems23.Length; n++)\r
+ AssertionHelper.AssertEqualsXml ("t.extraElems23[" + n + "]", exp.extraElems23[n], t.extraElems23[n]);\r
+ \r
+ AssertionHelper.AssertEqualsXml ("t.extraElemsRest", exp.extraElemsRest, t.extraElemsRest);\r
+ \r
+ UnknownAttributeTester.AssertEquals ("t.uktester", exp.uktester, t.uktester);\r
+\r
+ AssertEquals ("t.ob3", exp.ob3, t.ob3);\r
+ AssertEquals ("t.ob4", exp.ob4, t.ob4);\r
+ AssertEquals ("t.op1", exp.op1, t.op1);\r
+ \r
+ AssertionHelper.AssertEqualsArray ("t.opArray", exp.opArray, t.opArray);\r
+\r
+ AssertEquals ("t.ukOpt", exp.ukOpt, t.ukOpt);\r
+ AssertEquals ("t.opAtt", exp.opAtt, t.opAtt);\r
+\r
+ AssertionHelper.AssertEqualsArray ("t.byteArray", exp.byteArray, t.byteArray);\r
+ AssertionHelper.AssertEqualsArray ("t.byteByteArray", exp.byteByteArray, t.byteByteArray);\r
+ \r
+ AssertNotNull ("t.ttList", t.ttList);\r
+ AssertionHelper.AssertEqualsArray ("t.ttList", exp.ttList.ToArray(), t.ttList.ToArray());\r
+ \r
+ AssertNotNull ("t.RoList", t.RoList);\r
+ AssertEquals ("t.RoList.Count", exp.RoList.Count, t.RoList.Count);\r
+ for (int n=0; n<exp.RoList.Count; n++)\r
+ TestPart.AssertEquals ("t.RoList " + n, (TestPart)exp.RoList[n], (TestPart)t.RoList[n]);\r
+ \r
+ AssertEquals ("t.struc.aa", exp.struc.aa, t.struc.aa);\r
+ AssertEquals ("t.struc.cc", exp.struc.cc, t.struc.cc);\r
+\r
+ AssertNotNull ("t.multiList", t.multiList);\r
+ AssertEquals ("t.multiList.Count", exp.multiList.Length, t.multiList.Length);\r
+ for (int n=0; n<exp.multiList.Length; n++)\r
+ AssertionHelper.AssertEqualsArray ("t.multiList " + n, exp.multiList[n].ToArray(), t.multiList[n].ToArray());\r
+ \r
+ AssertEquals ("t.defElem", exp.defElem, t.defElem);\r
+ AssertEquals ("t.defAttr", exp.defAttr, t.defAttr);\r
+\r
+ CustomHashtable.AssertEquals ("t.special", exp.special, t.special);\r
+\r
+ AssertEquals ("t.attqname", exp.attqname, t.attqname);\r
+\r
+ AssertNotNull ("t.dbscontainer", t.dbscontainer);\r
+ DblStringContainer tdbca = t.dbscontainer.at as DblStringContainer;\r
+ DblStringContainer expdbca = exp.dbscontainer.at as DblStringContainer;\r
+ AssertNotNull ("t.dbscontainer.at", tdbca);\r
+ \r
+ AssertNotNull ("t.dbscontainer.dbca", tdbca);\r
+ AssertionHelper.AssertEqualsArray ("t.dbscontainer.at.doublestring", expdbca.doublestring, tdbca.doublestring);\r
+ \r
+ AnotherTestPart tat = tdbca.at as AnotherTestPart;\r
+ AnotherTestPart expat = expdbca.at as AnotherTestPart;\r
+ AssertNotNull ("t.dbscontainer.dbca.at", tat);\r
+ AssertEquals ("t.dbscontainer.dbca.at.lo", expat.lo, tat.lo);\r
+ }\r
+ \r
+ void CheckParts (string id, TestPart[] exp, TestPart[] parts)\r
+ {\r
+ AssertionHelper.AssertType (id, exp, parts);\r
+ AssertEquals (id + " Len", exp.Length, parts.Length);\r
+ for (int n=0; n<exp.Length; n++)\r
+ TestPart.AssertEquals (id + "[" + n + "]", exp[n], parts[n]);\r
+ }\r
+ \r
+ void CheckTaArray (string id, TA[][][] exp, TA[][][] arr)\r
+ {\r
+ AssertionHelper.AssertType (id, exp, arr);\r
+ AssertEquals (id + " Len", exp.Length, arr.Length);\r
+ for (int n=0; n<exp.Length; n++)\r
+ {\r
+ TA[][] tar = arr[n];\r
+ TA[][] expar = exp[n];\r
+ \r
+ AssertionHelper.AssertType (id, expar, tar);\r
+ AssertEquals (expar.Length, tar.Length);\r
+ \r
+ for (int m=0; m<expar.Length; m++)\r
+ {\r
+ TA[] tar2 = tar[m];\r
+ TA[] expar2 = expar[m];\r
+ \r
+ AssertionHelper.AssertType (id, expar2, tar2);\r
+ AssertEquals (id, expar2.Length, tar2.Length);\r
+ \r
+ for (int i=0; i<expar2.Length; i++)\r
+ TA.AssertEquals (id + "[" + n + "][" + m + "][" + i + "]", expar2[i], tar2[i]);\r
+ }\r
+ }\r
+ }\r
+ }\r
+ \r
+ public class AssertionHelper\r
+ {\r
+ public static bool AssertType (string id, object exp, object ob)\r
+ {\r
+ if (exp == null) {\r
+ Assertion.AssertNull (id, ob);\r
+ return false;\r
+ }\r
+ else {\r
+ Assertion.AssertNotNull (id, ob);\r
+ Assertion.AssertEquals (id + " type", exp.GetType(), ob.GetType());\r
+ return true;\r
+ }\r
+ }\r
+ \r
+ public static void AssertEqualsXml (string id, XmlNode exp, XmlNode ob)\r
+ {\r
+ if (!AssertType (id, exp, ob)) return;\r
+ Assertion.AssertEquals (id, XmlSerializerTests.Infoset (exp), XmlSerializerTests.Infoset (ob));\r
+ }\r
+ \r
+ public static void AssertEqualsArray (string id, Array exp, Array ob)\r
+ {\r
+ if (!AssertType (id, exp, ob)) return;\r
+ Assertion.AssertEquals (id + " Length", exp.GetLength(0), ob.GetLength(0));\r
+ for (int n=0; n<exp.GetLength(0); n++) {\r
+ object it = exp.GetValue(n);\r
+ if (it is Array) \r
+ AssertEqualsArray (id + "[" + n + "]", it as Array, ob.GetValue(n) as Array);\r
+ else\r
+ Assertion.AssertEquals (id + "[" + n + "]", it, ob.GetValue(n));\r
+ }\r
+ }\r
+ }\r
+ \r
+ [XmlType(TypeName="")]\r
+ [XmlRoot(ElementName="aaaaaa",Namespace="")]\r
+ [XmlInclude(typeof(UknTestPart))]\r
+ [SoapInclude(typeof(UknTestPart))]\r
+ public class Test\r
+ {\r
+ // public option op;elem.SchemaTypeName\r
+ public object anot;\r
+\r
+ [SoapElement(ElementName="suba")]\r
+ [XmlElement(ElementName="suba",Namespace="kk")]\r
+ public int a;\r
+\r
+ public string b;\r
+ public string bbis;\r
+\r
+ [SoapAttribute]\r
+ [XmlAttribute (Namespace="attribns")]\r
+ public byte c;\r
+\r
+ [XmlElement(Namespace="oo")]\r
+ public TestPart part;\r
+\r
+ public TA ta;\r
+\r
+ public TestPart[] parts;\r
+\r
+ [SoapElement(ElementName="multita")]\r
+ [XmlArray(ElementName="multita")]\r
+ // [XmlArrayItem(ElementName="itema",NestingLevel=1)]\r
+ [XmlArrayItem(ElementName="itema",Type=typeof(TA),NestingLevel=1)]\r
+ [XmlArrayItem(ElementName="itemb",Type=typeof(TB),NestingLevel=1)]\r
+ public TA[][] tam = new TA[][] { new TA[] {new TA(), new TB()}, new TA[] {new TA(), new TA()}};\r
+\r
+// [SoapElement(ElementName="multita2")]\r
+ [SoapIgnore]\r
+ [XmlArray(ElementName="multita2")]\r
+ [XmlArrayItem(ElementName="data1",NestingLevel=0)]\r
+\r
+ [XmlArrayItem(ElementName="data2",NestingLevel=1,Namespace="da2")]\r
+ [XmlArrayItem(ElementName="data3a",Type=typeof(TA),NestingLevel=2,Namespace="da3")]\r
+ [XmlArrayItem(ElementName="data3b",Type=typeof(TB),NestingLevel=2,Namespace="da3")]\r
+ public TA[][][] tam2;\r
+\r
+ [SoapIgnore]\r
+ public TA[][][] tam3;\r
+\r
+ [SoapElement(IsNullable=true)]\r
+ [XmlElement(IsNullable=true)]\r
+ public string mayBeNull;\r
+\r
+ public string[] strings;\r
+\r
+ [XmlArray(Namespace="arrayNamespace")]\r
+ public ushort[] ushorts;\r
+\r
+ [XmlElement]\r
+ public TestPart[] flatParts;\r
+\r
+ [SoapElement (ElementName="flatTAs")]\r
+ [XmlElement (ElementName="flatTAs")]\r
+ public TA[] flatParts2;\r
+\r
+ public object ob;\r
+\r
+ [XmlElement (Namespace="uimp")]\r
+ public object ob2;\r
+\r
+ public object ob3;\r
+ public object ob4;\r
+\r
+ [SoapIgnore]\r
+ public XmlElement oneElem;\r
+\r
+ [SoapIgnore]\r
+ [XmlElement (ElementName="unElement", Namespace="elemns")]\r
+ public XmlElement oneElem2;\r
+\r
+ [SoapIgnore]\r
+ [XmlElement (ElementName="unsElements", Namespace="elemns")]\r
+ public XmlNode[] someElems;\r
+\r
+ [SoapIgnore]\r
+ [XmlAnyElement ("extra1")]\r
+ public XmlElement[] extraElems;\r
+\r
+ [SoapIgnore]\r
+ [XmlAnyElement ("extra2")]\r
+ [XmlAnyElement ("extra3")]\r
+ [XmlAnyElement ("extra3","nnn")]\r
+ public XmlElement[] extraElems23;\r
+\r
+ [SoapIgnore]\r
+ [XmlAnyElement]\r
+ public XmlElement extraElemsRest;\r
+\r
+ public UnknownAttributeTester uktester;\r
+\r
+ public option op1;\r
+ public option[] opArray;\r
+ public object ukOpt;\r
+\r
+ [XmlAttribute]\r
+ [SoapIgnore]\r
+ public option opAtt;\r
+\r
+\r
+ public byte[] byteArray;\r
+ [SoapIgnore]\r
+ public byte[][] byteByteArray;\r
+\r
+ [XmlElement(Type=typeof(string))]\r
+ [XmlElement(ElementName="kk",Type=typeof(int))]\r
+ public object[] tt = new object[] { "aa",22 };\r
+\r
+ public ArrayList ttList;\r
+\r
+ ArrayList roList;\r
+ public ArrayList RoList\r
+ {\r
+ get { return roList; }\r
+ set { roList = value; }\r
+ }\r
+\r
+ [SoapIgnore]\r
+// [XmlIgnore]\r
+ public ArrayList[] multiList;\r
+\r
+ [SoapIgnore]\r
+ [XmlIgnore]\r
+ public OneStruct struc;\r
+\r
+ [DefaultValue("theDefValue")]\r
+ public string defElem;\r
+\r
+ [XmlAttribute]\r
+ [DefaultValue("theDefValue")]\r
+ public string defAttr;\r
+\r
+ [XmlText (Type=typeof(string))]\r
+ [XmlElement (Type=typeof(int))]\r
+ public object[] xmltext = new object[] {"aa",33,"bb",776};\r
+\r
+ [SoapIgnore]\r
+ public CustomHashtable special;\r
+\r
+ [XmlAttribute]\r
+ public XmlQualifiedName attqname;\r
+\r
+ [XmlAttribute]\r
+ public DateTime[] arrayAttribute;\r
+\r
+ [XmlArray (Namespace="mm")]\r
+ public string[][] dummyStringArray = new string[][] {null,null};\r
+ \r
+ [XmlElement (Namespace="mm")]\r
+ public DblStringContainerAnm dbscontainer;\r
+ }\r
+\r
+ public class DblStringContainerAnm\r
+ {\r
+ public object at;\r
+ }\r
+\r
+ [XmlType(Namespace="mm")]\r
+ public class DblStringContainer\r
+ {\r
+ [XmlArrayItem (NestingLevel=1)]\r
+ public string [][] doublestring;\r
+ public object at;\r
+ }\r
+\r
+ [SoapType(TypeName="TC")]\r
+ [XmlType(TypeName="TC")]\r
+ [XmlInclude(typeof(TB))]\r
+ [SoapInclude(typeof(TB))]\r
+ public class TA\r
+ {\r
+ public int xx = 1;\r
+\r
+ [XmlText]\r
+ [SoapIgnore]\r
+ public XmlNode[] extraTextNodes;\r
+ \r
+ public static void AssertEquals (string id, TA expected, TA ob)\r
+ {\r
+ if (!AssertionHelper.AssertType (id, expected, ob)) return;\r
+ Assertion.AssertEquals (id + " xx", expected.xx, ob.xx);\r
+ // TODO: extraTextNodes\r
+ }\r
+ }\r
+\r
+ public class TB: TA\r
+ {\r
+ public int yy = 2;\r
+ \r
+ public static void AssertEquals (string id, TB expected, TB ob)\r
+ {\r
+ if (!AssertionHelper.AssertType (id, expected, ob)) return;\r
+ Assertion.AssertEquals (id + " yy", expected.yy, ob.yy);\r
+ TA.AssertEquals (id + " base", expected, ob);\r
+ }\r
+ }\r
+\r
+ public class UnknownAttributeTester\r
+\r
+ {\r
+ [SoapAttribute]\r
+ [XmlAttribute]\r
+ public string aa;\r
+ \r
+ [SoapIgnore]\r
+ [XmlAnyAttribute]\r
+ public XmlAttribute[] extraAtts;\r
+\r
+ // [XmlText(Type=typeof(XmlNode))]\r
+ // public XmlNode extraText;\r
+ \r
+ public static void AssertEquals (string id, UnknownAttributeTester exp, UnknownAttributeTester ob)\r
+ {\r
+ if (!AssertionHelper.AssertType (id, exp, ob)) return;\r
+ Assertion.AssertEquals (id + " aa", exp.aa, ob.aa);\r
+ \r
+ if (!AssertionHelper.AssertType (id + " extraAtts", exp.extraAtts, ob.extraAtts)) return;\r
+ \r
+ int p = 0;\r
+ for (int n=0; n<ob.extraAtts.Length; n++)\r
+ {\r
+ XmlAttribute at = ob.extraAtts [n];\r
+ if (at.NamespaceURI == "http://www.w3.org/2000/xmlns/") continue;\r
+ Assertion.Assert (id + " extraAtts length", p < exp.extraAtts.Length);\r
+ AssertionHelper.AssertEqualsXml (id + ".extraAtts " + n, exp.extraAtts [p], ob.extraAtts[n]);\r
+ p++;\r
+ }\r
+ }\r
+ }\r
+\r
+ [SoapType(TypeName="UnTestPart", Namespace="mm")]\r
+ [XmlType(TypeName="UnTestPart", Namespace="mm")]\r
+ public class TestPart\r
+ {\r
+ public string name;\r
+ public bool bval;\r
+ \r
+ public static void AssertEquals (string id, TestPart expected, TestPart ob)\r
+ {\r
+ if (!AssertionHelper.AssertType (id, expected, ob)) return;\r
+ Assertion.AssertEquals (id + " name", expected.name, ob.name);\r
+ Assertion.AssertEquals (id + " bval", expected.bval, ob.bval);\r
+ }\r
+ }\r
+\r
+ [SoapType(Namespace="mm")]\r
+ [XmlType(Namespace="mm")]\r
+ public class AnotherTestPart\r
+ {\r
+ [XmlText]\r
+ public long lo;\r
+ }\r
+\r
+ public class UknTestPart : Test\r
+ {\r
+ [XmlElement(IsNullable=true)]\r
+ public string uname;\r
+ public bool uval;\r
+ }\r
+\r
+ public struct OneStruct\r
+ {\r
+ public int aa;\r
+ public string cc;\r
+ }\r
+\r
+// [XmlType(Namespace="enum_namespace")]\r
+ public enum option \r
+ { \r
+ AA, \r
+ [SoapEnum(Name="xmlBB")]\r
+ [XmlEnum(Name="xmlBB")]\r
+ BB, \r
+ CC, \r
+ DD \r
+ }\r
+\r
+ public class CustomHashtable : IXmlSerializable\r
+ {\r
+ Hashtable data = new Hashtable ();\r
+\r
+ public void Add (string key, string value)\r
+ {\r
+ data.Add (key, value);\r
+ }\r
+ \r
+ public static void AssertEquals (string id, CustomHashtable exp, CustomHashtable ob)\r
+ {\r
+ if (!AssertionHelper.AssertType (id, exp, ob)) return;\r
+ if (!AssertionHelper.AssertType (id, exp.data, ob.data)) return;\r
+ \r
+ Assertion.AssertEquals (id + " data Count", exp.data.Count, ob.data.Count);\r
+ \r
+ foreach (DictionaryEntry entry in exp.data)\r
+ Assertion.AssertEquals (entry.Value, ob.data[entry.Key]);\r
+ }\r
+ \r
+ public void ReadXml (XmlReader reader)\r
+ {\r
+ // Read the element enclosing the object\r
+ reader.ReadStartElement();\r
+ reader.MoveToContent ();\r
+\r
+ // Reads the "data" element\r
+ reader.ReadStartElement();\r
+ reader.MoveToContent ();\r
+ while (reader.NodeType != XmlNodeType.EndElement)\r
+ {\r
+ if (reader.NodeType == XmlNodeType.Element)\r
+ {\r
+ string key = reader.LocalName;\r
+ data [key] = reader.ReadElementString ();\r
+ }\r
+ else\r
+ reader.Skip ();\r
+ reader.MoveToContent ();\r
+ }\r
+\r
+ reader.ReadEndElement ();\r
+ }\r
+\r
+ public void WriteXml (XmlWriter writer)\r
+ {\r
+ writer.WriteStartElement ("data");\r
+ foreach (DictionaryEntry entry in data) \r
+ {\r
+ writer.WriteElementString ((string)entry.Key, (string)entry.Value);\r
+ }\r
+ writer.WriteEndElement ();\r
+ }\r
+\r
+ public XmlSchema GetSchema ()\r
+ {\r
+ XmlSchema s = new XmlSchema ();\r
+ s.TargetNamespace = "http://www.go-mono.org/schemas";\r
+ s.Id = "monoschema";\r
+ XmlSchemaElement e = new XmlSchemaElement ();\r
+ e.Name = "data";\r
+ s.Items.Add (e);\r
+ XmlSchemaComplexType cs = new XmlSchemaComplexType ();\r
+ XmlSchemaSequence seq = new XmlSchemaSequence ();\r
+ XmlSchemaAny any = new XmlSchemaAny ();\r
+ any.MinOccurs = 0;\r
+ any.MaxOccurs = decimal.MaxValue;\r
+ seq.Items.Add (any);\r
+ cs.Particle = seq;\r
+ e.SchemaType = cs;\r
+ return s;\r
+ }\r
+ }\r
+}\r