2005-01-31 Zoltan Varga <vargaz@freemail.hu>
[mono.git] / mcs / class / System.XML / Test / System.Xml.Serialization / ComplexDataStructure.cs
1 //\r
2 // ComplexDataStructure.cs\r
3 //\r
4 // Author:\r
5 //      Lluis Sanchez Gual (lluis@ximian.com)\r
6 //\r
7 // (C) 2004 Novell, Inc.\r
8 //\r
9 //\r
10 using System;\r
11 using System.IO;\r
12 using System.Xml;\r
13 using System.Xml.Schema;\r
14 using System.Xml.Serialization;\r
15 using System.Collections;\r
16 using System.ComponentModel; \r
17 using NUnit.Framework;\r
18 \r
19 namespace MonoTests.System.XmlSerialization\r
20 {\r
21         [TestFixture]\r
22         public class ComplexDataStructure: Assertion\r
23         {\r
24                 [Test]\r
25                 [NUnit.Framework.Category("NotDotNet")]\r
26                 public void WriteLiteral ()\r
27                 {\r
28                         Test data = BuildTestObject ();\r
29 \r
30                         XmlSerializer ss = new XmlSerializer (GetLiteralTypeMapping ());\r
31                         XmlSerializerNamespaces nams = new XmlSerializerNamespaces ();\r
32                         StringWriter sw = new StringWriter();\r
33                         ss.Serialize (sw,data,nams);\r
34                         string serialized = sw.ToString ();\r
35                         serialized = XmlSerializerTests.Infoset (serialized);\r
36 \r
37                         StreamReader sr = new StreamReader ("Test/XmlFiles/literal-data.xml");\r
38                         string expected = sr.ReadToEnd ();\r
39                         sr.Close ();\r
40                         \r
41                         expected = XmlSerializerTests.Infoset (expected);\r
42                         AssertEquals (expected, serialized);\r
43                 }\r
44                 \r
45                 [Test]\r
46                 [NUnit.Framework.Category("NotDotNet")]\r
47                 public void ReadLiteral ()\r
48                 {\r
49                         XmlSerializer ss = new XmlSerializer (GetLiteralTypeMapping ());\r
50                         XmlSerializerNamespaces nams = new XmlSerializerNamespaces ();\r
51                         \r
52                         StreamReader sr = new StreamReader ("Test/XmlFiles/literal-data.xml");\r
53                         Test data = (Test) ss.Deserialize (sr);\r
54                         sr.Close ();\r
55                         \r
56                         CheckObjectContent (BuildTestObject(), data);\r
57                 }\r
58                 \r
59                 XmlTypeMapping GetLiteralTypeMapping ()\r
60                 {\r
61                         XmlRootAttribute root = new XmlRootAttribute("rootroot");\r
62                         Type[] types = new Type[] {typeof(UknTestPart), typeof(AnotherTestPart), typeof(DblStringContainer) };\r
63                         XmlReflectionImporter ri = new XmlReflectionImporter ();\r
64                         foreach (Type t in types) ri.IncludeType (t);\r
65                         return ri.ImportTypeMapping (typeof(Test), root);\r
66                 }\r
67 \r
68                 XmlTypeMapping GetEncodedTypeMapping ()\r
69                 {\r
70                         SoapReflectionImporter sri = new SoapReflectionImporter ();\r
71                         sri.IncludeType (typeof(UknTestPart));\r
72                         sri.IncludeType (typeof(AnotherTestPart));\r
73                         sri.IncludeType (typeof(DblStringContainer));\r
74                         return sri.ImportTypeMapping (typeof(Test));\r
75                 }\r
76                 \r
77                 Test BuildTestObject ()\r
78                 {\r
79                         XmlDocument doc = new XmlDocument();\r
80 \r
81                         Test t = new UknTestPart();\r
82                         t.a = 1;\r
83                         t.b = "hola";\r
84                         t.bbis = t.b;\r
85                         t.c = 44;\r
86                         t.parts = new TestPart[3];\r
87                         t.parts[0] = new TestPart();\r
88                         t.parts[0].name = "un";\r
89                         t.parts[0].bval = true;\r
90                         t.parts[1] = new TestPart();\r
91                         t.parts[1].name = "dos";\r
92                         t.parts[1].bval = false;\r
93                         t.parts[2] = t.parts[0];\r
94                         t.part = t.parts[1];\r
95                         t.strings = new string[] { "un", "dos", null, "tres" };\r
96                         t.ushorts = new ushort[] { 1,2,3 };\r
97                         t.ta = new TB();\r
98                         t.ta.extraTextNodes = new XmlNode[] { doc.CreateTextNode ("AA"), doc.CreateTextNode ("BB") };\r
99 \r
100                         t.tam2 = new TA[][][]\r
101                                         {\r
102                                                 new TA[][] { new TA[] {new TA(), new TA()}, new TA[] {new TA(), new TA()}},\r
103                                                 new TA[][] { new TA[] {new TB(), new TA()}, new TA[] {new TB(), new TA()}},\r
104                                                 new TA[][] { new TA[] {new TA(), new TB()}, new TA[] {new TA(), new TA()}} \r
105                                         };\r
106 \r
107                         t.tam3 = t.tam2;\r
108                         t.flatParts = t.parts;\r
109 \r
110                         t.flatParts2 = new TA[] {new TA(), new TB(), null, new TB()};\r
111 \r
112                         t.anot = new AnotherTestPart ();\r
113                         ((AnotherTestPart)t.anot).lo = 1234567890;\r
114 \r
115                         t.ob = t.parts[1];\r
116                         t.ob2 = t.parts[1];\r
117 \r
118                         XmlElement e1 = doc.CreateElement ("explicitElement");\r
119                         XmlElement e2 = doc.CreateElement ("subElement");\r
120                         e2.SetAttribute ("unAtrib","val");\r
121                         doc.AppendChild (e1);\r
122                         e1.AppendChild (e2);\r
123 \r
124                         t.oneElem = e1;\r
125                         t.oneElem2 = e1;\r
126                         t.someElems = new XmlNode[3];\r
127                         t.someElems[0] = e1;\r
128                         t.someElems[1] = null;\r
129                         t.someElems[2] = e2;\r
130 \r
131                         t.extraElems = new XmlElement[1];\r
132                         t.extraElems[0] = doc.CreateElement ("extra1");\r
133                         t.extraElems[0].SetAttribute ("val","1");\r
134 \r
135                         t.extraElems23 = new XmlElement[2];\r
136                         t.extraElems23[0] = doc.CreateElement ("extra2");\r
137                         t.extraElems23[0].SetAttribute ("val","2");\r
138                         t.extraElems23[1] = doc.CreateElement ("extra3");\r
139                         t.extraElems23[1].SetAttribute ("val","3");\r
140 \r
141                         t.extraElemsRest = doc.CreateElement ("extra4");\r
142                         t.extraElemsRest.SetAttribute ("val","4");\r
143 \r
144                         t.uktester = new UnknownAttributeTester();\r
145                         t.uktester.aa = "hihi";\r
146 \r
147                         t.uktester.extraAtts = new XmlAttribute[3];\r
148                         t.uktester.extraAtts[0] = doc.CreateAttribute ("extraAtt1");\r
149                         t.uktester.extraAtts[0].Value = "val1";\r
150                         t.uktester.extraAtts[1] = doc.CreateAttribute ("extraAtt2");\r
151                         t.uktester.extraAtts[1].Value = "val2";\r
152                         t.uktester.extraAtts[2] = doc.CreateAttribute ("extraAtt3");\r
153                         t.uktester.extraAtts[2].Value = "val3";\r
154 \r
155                         t.ob3 = 12345;\r
156                         t.ob4 = (float)54321.12;\r
157 \r
158                         t.op1 = option.AA;\r
159                         t.opArray = new option[] { option.CC, option.BB, option.AA };\r
160                         t.ukOpt = option.DD;\r
161                         t.opAtt = option.BB;\r
162 \r
163                         t.byteArray = new byte[] { 11,33,55,222 };\r
164                         t.byteByteArray = new byte[][] { t.byteArray, t.byteArray };\r
165 \r
166                         t.ttList = new ArrayList();\r
167                         t.ttList.Add ("two");\r
168                         t.ttList.Add ("strings");\r
169                         //                      t.extraText = "Additional text";\r
170 \r
171                         t.RoList = new ArrayList ();\r
172                         t.RoList.Add (t.parts[0]);\r
173                         t.RoList.Add (t.parts[1]);\r
174 \r
175 /*                      t.struc = new OneStruct();\r
176                         t.struc.aa = 776655;\r
177                         t.struc.cc = "this is a struct";\r
178 */\r
179                         t.multiList = new ArrayList[2];\r
180                         t.multiList[0] = new ArrayList ();\r
181                         t.multiList[0].Add (22);\r
182                         t.multiList[0].Add (33);\r
183                         t.multiList[1] = new ArrayList ();\r
184                         t.multiList[1].Add (888);\r
185                         t.multiList[1].Add (999);\r
186 \r
187 \r
188                         t.defElem = "theDefValue";\r
189                         t.defAttr = "theDefValue";\r
190 \r
191                         t.special = new CustomHashtable ();\r
192                         t.special.Add ("one","1");\r
193                         t.special.Add ("two","2");\r
194                         t.special.Add ("three","3");\r
195 \r
196                         t.attqname = new XmlQualifiedName ("thename","thenamespace");\r
197 \r
198                         DblStringContainer dbc = new DblStringContainer ();\r
199                         dbc.doublestring = new string [][] { null, new string[] {"hello"} };\r
200                         AnotherTestPart at = new AnotherTestPart ();\r
201                         at.lo = 567;\r
202                         dbc.at = at;\r
203 \r
204                         DblStringContainerAnm dbca = new DblStringContainerAnm ();\r
205                         dbca.at = dbc;\r
206                         t.dbscontainer = dbca;\r
207                         \r
208                         return t;\r
209                 }\r
210                 \r
211                 void CheckObjectContent (Test exp, Test t)\r
212                 {\r
213                         AssertEquals ("t.a", exp.a, t.a);\r
214                         AssertEquals ("t.b", exp.b, t.b);\r
215                         AssertEquals ("t.bbis", exp.bbis, t.bbis);\r
216                         AssertEquals ("t.c", exp.c, t.c);\r
217                         \r
218                         AssertNotNull ("t.parts", t.parts);\r
219                         CheckParts ("t.parts", exp.parts, t.parts);\r
220                         \r
221                         TestPart.AssertEquals ("t.part", exp.part, t.part);\r
222                         \r
223                         AssertionHelper.AssertEqualsArray ("t.strings", exp.strings, t.strings);\r
224                         AssertionHelper.AssertEqualsArray ("t.ushorts", exp.ushorts, t.ushorts);\r
225                         \r
226                         TA.AssertEquals ("t.ta", exp.ta, t.ta);\r
227 \r
228                         AssertNotNull ("t.tam2", t.tam2);\r
229                         CheckTaArray ("t.tam2", exp.tam2, t.tam2);\r
230                         \r
231                         AssertNotNull ("t.tam3", t.tam3);\r
232                         CheckTaArray ("t.tam3", exp.tam3, t.tam3);\r
233                         \r
234                         AssertNotNull ("t.flatParts", t.flatParts);\r
235                         CheckParts ("t.flatParts", exp.flatParts, t.flatParts);\r
236 \r
237                         // Null element is ignored\r
238                         AssertNotNull ("t.flatParts2", t.flatParts2);\r
239                         AssertEquals ("t.flatParts2.Length", 3, t.flatParts2.Length);\r
240                         TA.AssertEquals ("t.flatParts2 0", exp.flatParts2[0], t.flatParts2[0]);\r
241                         TA.AssertEquals ("t.flatParts2 1", exp.flatParts2[1], t.flatParts2[1]);\r
242                         TA.AssertEquals ("t.flatParts2 2", exp.flatParts2[3], t.flatParts2[2]);\r
243                         \r
244                         AssertNotNull ("t.anot", t.anot);\r
245                         AssertEquals ("t.anot.lo", ((AnotherTestPart)exp.anot).lo, ((AnotherTestPart)t.anot).lo);\r
246 \r
247                         TestPart.AssertEquals ("t.ob", exp.ob as TestPart, t.ob as TestPart);\r
248                         TestPart.AssertEquals ("t.ob2", exp.ob2 as TestPart, t.ob2 as TestPart);\r
249                         \r
250                         AssertionHelper.AssertEqualsXml ("t.oneElem", exp.oneElem, t.oneElem);\r
251                         AssertionHelper.AssertEqualsXml ("t.oneElem2", exp.oneElem2, t.oneElem2);\r
252                         \r
253                         // One of the elements was null and it is ignored\r
254                         AssertNotNull ("t.someElems", t.someElems);\r
255                         AssertEquals ("t.someElems.Length", 2, t.someElems.Length);\r
256                         AssertionHelper.AssertEqualsXml ("t.someElems[0]", exp.someElems[0], t.someElems[0]);\r
257                         AssertionHelper.AssertEqualsXml ("t.someElems[1]", exp.someElems[2], t.someElems[1]);\r
258 \r
259                         AssertNotNull ("t.extraElems", t.extraElems);\r
260                         AssertEquals ("t.extraElems.Length", exp.extraElems.Length, t.extraElems.Length);\r
261                         for (int n=0; n<exp.extraElems.Length; n++)\r
262                                 AssertionHelper.AssertEqualsXml ("t.extraElems[" + n + "]", exp.extraElems[n], t.extraElems[n]);\r
263                         \r
264                         AssertNotNull ("t.extraElems23", t.extraElems23);\r
265                         AssertEquals ("t.extraElems23.Length", exp.extraElems23.Length, t.extraElems23.Length);\r
266                         for (int n=0; n<t.extraElems23.Length; n++)\r
267                                 AssertionHelper.AssertEqualsXml ("t.extraElems23[" + n + "]", exp.extraElems23[n], t.extraElems23[n]);\r
268                         \r
269                         AssertionHelper.AssertEqualsXml ("t.extraElemsRest", exp.extraElemsRest, t.extraElemsRest);\r
270                         \r
271                         UnknownAttributeTester.AssertEquals ("t.uktester", exp.uktester, t.uktester);\r
272 \r
273                         AssertEquals ("t.ob3", exp.ob3, t.ob3);\r
274                         AssertEquals ("t.ob4", exp.ob4, t.ob4);\r
275                         AssertEquals ("t.op1", exp.op1, t.op1);\r
276                         \r
277                         AssertionHelper.AssertEqualsArray ("t.opArray", exp.opArray, t.opArray);\r
278 \r
279                         AssertEquals ("t.ukOpt", exp.ukOpt, t.ukOpt);\r
280                         AssertEquals ("t.opAtt", exp.opAtt, t.opAtt);\r
281 \r
282                         AssertionHelper.AssertEqualsArray ("t.byteArray", exp.byteArray, t.byteArray);\r
283                         AssertionHelper.AssertEqualsArray ("t.byteByteArray", exp.byteByteArray, t.byteByteArray);\r
284                         \r
285                         AssertNotNull ("t.ttList", t.ttList);\r
286                         AssertionHelper.AssertEqualsArray ("t.ttList", exp.ttList.ToArray(), t.ttList.ToArray());\r
287                         \r
288                         AssertNotNull ("t.RoList", t.RoList);\r
289                         AssertEquals ("t.RoList.Count", exp.RoList.Count, t.RoList.Count);\r
290                         for (int n=0; n<exp.RoList.Count; n++)\r
291                                 TestPart.AssertEquals ("t.RoList " + n, (TestPart)exp.RoList[n], (TestPart)t.RoList[n]);\r
292                         \r
293                         AssertEquals ("t.struc.aa", exp.struc.aa, t.struc.aa);\r
294                         AssertEquals ("t.struc.cc", exp.struc.cc, t.struc.cc);\r
295 \r
296                         AssertNotNull ("t.multiList", t.multiList);\r
297                         AssertEquals ("t.multiList.Count", exp.multiList.Length, t.multiList.Length);\r
298                         for (int n=0; n<exp.multiList.Length; n++)\r
299                                 AssertionHelper.AssertEqualsArray ("t.multiList " + n, exp.multiList[n].ToArray(), t.multiList[n].ToArray());\r
300                         \r
301                         AssertEquals ("t.defElem", exp.defElem, t.defElem);\r
302                         AssertEquals ("t.defAttr", exp.defAttr, t.defAttr);\r
303 \r
304                         CustomHashtable.AssertEquals ("t.special", exp.special, t.special);\r
305 \r
306                         AssertEquals ("t.attqname", exp.attqname, t.attqname);\r
307 \r
308                         AssertNotNull ("t.dbscontainer", t.dbscontainer);\r
309                         DblStringContainer tdbca = t.dbscontainer.at as DblStringContainer;\r
310                         DblStringContainer expdbca = exp.dbscontainer.at as DblStringContainer;\r
311                         AssertNotNull ("t.dbscontainer.at", tdbca);\r
312                         \r
313                         AssertNotNull ("t.dbscontainer.dbca", tdbca);\r
314                         AssertionHelper.AssertEqualsArray ("t.dbscontainer.at.doublestring", expdbca.doublestring, tdbca.doublestring);\r
315                         \r
316                         AnotherTestPart tat = tdbca.at as AnotherTestPart;\r
317                         AnotherTestPart expat = expdbca.at as AnotherTestPart;\r
318                         AssertNotNull ("t.dbscontainer.dbca.at", tat);\r
319                         AssertEquals ("t.dbscontainer.dbca.at.lo", expat.lo, tat.lo);\r
320                 }\r
321                 \r
322                 void CheckParts (string id, TestPart[] exp, TestPart[] parts)\r
323                 {\r
324                         AssertionHelper.AssertType (id, exp, parts);\r
325                         AssertEquals (id + " Len", exp.Length, parts.Length);\r
326                         for (int n=0; n<exp.Length; n++)\r
327                                 TestPart.AssertEquals (id + "[" + n + "]", exp[n], parts[n]);\r
328                 }\r
329                 \r
330                 void CheckTaArray (string id, TA[][][] exp, TA[][][] arr)\r
331                 {\r
332                         AssertionHelper.AssertType (id, exp, arr);\r
333                         AssertEquals (id + " Len", exp.Length, arr.Length);\r
334                         for (int n=0; n<exp.Length; n++)\r
335                         {\r
336                                 TA[][] tar = arr[n];\r
337                                 TA[][] expar = exp[n];\r
338                                 \r
339                                 AssertionHelper.AssertType (id, expar, tar);\r
340                                 AssertEquals (expar.Length, tar.Length);\r
341                                 \r
342                                 for (int m=0; m<expar.Length; m++)\r
343                                 {\r
344                                         TA[] tar2 = tar[m];\r
345                                         TA[] expar2 = expar[m];\r
346                                         \r
347                                         AssertionHelper.AssertType (id, expar2, tar2);\r
348                                         AssertEquals (id, expar2.Length, tar2.Length);\r
349                                         \r
350                                         for (int i=0; i<expar2.Length; i++)\r
351                                                 TA.AssertEquals (id + "[" + n + "][" + m + "][" + i + "]", expar2[i], tar2[i]);\r
352                                 }\r
353                         }\r
354                 }\r
355         }\r
356         \r
357         public class AssertionHelper\r
358         {\r
359                 public static bool AssertType (string id, object exp, object ob)\r
360                 {\r
361                         if (exp == null) {\r
362                                 Assertion.AssertNull (id, ob);\r
363                                 return false;\r
364                         }\r
365                         else {\r
366                                 Assertion.AssertNotNull (id, ob);\r
367                                 Assertion.AssertEquals (id + " type", exp.GetType(), ob.GetType());\r
368                                 return true;\r
369                         }\r
370                 }\r
371                 \r
372                 public static void AssertEqualsXml (string id, XmlNode exp, XmlNode ob)\r
373                 {\r
374                         if (!AssertType (id, exp, ob)) return;\r
375                         Assertion.AssertEquals (id, XmlSerializerTests.Infoset (exp), XmlSerializerTests.Infoset (ob));\r
376                 }\r
377                 \r
378                 public static void AssertEqualsArray (string id, Array exp, Array ob)\r
379                 {\r
380                         if (!AssertType (id, exp, ob)) return;\r
381                         Assertion.AssertEquals (id + " Length", exp.GetLength(0), ob.GetLength(0));\r
382                         for (int n=0; n<exp.GetLength(0); n++) {\r
383                                 object it = exp.GetValue(n);\r
384                                 if (it is Array) \r
385                                         AssertEqualsArray (id + "[" + n + "]", it as Array, ob.GetValue(n) as Array);\r
386                                 else\r
387                                         Assertion.AssertEquals (id + "[" + n + "]", it, ob.GetValue(n));\r
388                         }\r
389                 }\r
390         }\r
391         \r
392         [XmlType(TypeName="")]\r
393         [XmlRoot(ElementName="aaaaaa",Namespace="")]\r
394         [XmlInclude(typeof(UknTestPart))]\r
395         [SoapInclude(typeof(UknTestPart))]\r
396         public class Test\r
397         {\r
398                 //              public option op;elem.SchemaTypeName\r
399                 public object anot;\r
400 \r
401                 [SoapElement(ElementName="suba")]\r
402                 [XmlElement(ElementName="suba",Namespace="kk")]\r
403                 public int a;\r
404 \r
405                 public string b;\r
406                 public string bbis;\r
407 \r
408                 [SoapAttribute]\r
409                 [XmlAttribute (Namespace="attribns")]\r
410                 public byte c;\r
411 \r
412                 [XmlElement(Namespace="oo")]\r
413                 public TestPart part;\r
414 \r
415                 public TA ta;\r
416 \r
417                 public TestPart[] parts;\r
418 \r
419                 [SoapElement(ElementName="multita")]\r
420                 [XmlArray(ElementName="multita")]\r
421                         //              [XmlArrayItem(ElementName="itema",NestingLevel=1)]\r
422                 [XmlArrayItem(ElementName="itema",Type=typeof(TA),NestingLevel=1)]\r
423                 [XmlArrayItem(ElementName="itemb",Type=typeof(TB),NestingLevel=1)]\r
424                 public TA[][] tam = new TA[][] { new TA[] {new TA(), new TB()}, new TA[] {new TA(), new TA()}};\r
425 \r
426 //              [SoapElement(ElementName="multita2")]\r
427                 [SoapIgnore]\r
428                 [XmlArray(ElementName="multita2")]\r
429                 [XmlArrayItem(ElementName="data1",NestingLevel=0)]\r
430 \r
431                 [XmlArrayItem(ElementName="data2",NestingLevel=1,Namespace="da2")]\r
432                 [XmlArrayItem(ElementName="data3a",Type=typeof(TA),NestingLevel=2,Namespace="da3")]\r
433                 [XmlArrayItem(ElementName="data3b",Type=typeof(TB),NestingLevel=2,Namespace="da3")]\r
434                 public TA[][][] tam2;\r
435 \r
436                 [SoapIgnore]\r
437                 public TA[][][] tam3;\r
438 \r
439                 [SoapElement(IsNullable=true)]\r
440                 [XmlElement(IsNullable=true)]\r
441                 public string mayBeNull;\r
442 \r
443                 public string[] strings;\r
444 \r
445                 [XmlArray(Namespace="arrayNamespace")]\r
446                 public ushort[] ushorts;\r
447 \r
448                 [XmlElement]\r
449                 public TestPart[] flatParts;\r
450 \r
451                 [SoapElement (ElementName="flatTAs")]\r
452                 [XmlElement (ElementName="flatTAs")]\r
453                 public TA[] flatParts2;\r
454 \r
455                 public object ob;\r
456 \r
457                 [XmlElement (Namespace="uimp")]\r
458                 public object ob2;\r
459 \r
460                 public object ob3;\r
461                 public object ob4;\r
462 \r
463                 [SoapIgnore]\r
464                 public XmlElement oneElem;\r
465 \r
466                 [SoapIgnore]\r
467                 [XmlElement (ElementName="unElement", Namespace="elemns")]\r
468                 public XmlElement oneElem2;\r
469 \r
470                 [SoapIgnore]\r
471                 [XmlElement (ElementName="unsElements", Namespace="elemns")]\r
472                 public XmlNode[] someElems;\r
473 \r
474                 [SoapIgnore]\r
475                 [XmlAnyElement ("extra1")]\r
476                 public XmlElement[] extraElems;\r
477 \r
478                 [SoapIgnore]\r
479                 [XmlAnyElement ("extra2")]\r
480                 [XmlAnyElement ("extra3")]\r
481                 [XmlAnyElement ("extra3","nnn")]\r
482                 public XmlElement[] extraElems23;\r
483 \r
484                 [SoapIgnore]\r
485                 [XmlAnyElement]\r
486                 public XmlElement extraElemsRest;\r
487 \r
488                 public UnknownAttributeTester uktester;\r
489 \r
490                 public option op1;\r
491                 public option[] opArray;\r
492                 public object ukOpt;\r
493 \r
494                 [XmlAttribute]\r
495                 [SoapIgnore]\r
496                 public option opAtt;\r
497 \r
498 \r
499                 public byte[] byteArray;\r
500                 [SoapIgnore]\r
501                 public byte[][] byteByteArray;\r
502 \r
503                 [XmlElement(Type=typeof(string))]\r
504                 [XmlElement(ElementName="kk",Type=typeof(int))]\r
505                 public object[] tt = new object[] { "aa",22 };\r
506 \r
507                 public ArrayList ttList;\r
508 \r
509                 ArrayList roList;\r
510                 public ArrayList RoList\r
511                 {\r
512                         get { return roList; }\r
513                         set { roList = value; }\r
514                 }\r
515 \r
516                 [SoapIgnore]\r
517 //              [XmlIgnore]\r
518                 public ArrayList[] multiList;\r
519 \r
520                 [SoapIgnore]\r
521                 [XmlIgnore]\r
522                 public OneStruct struc;\r
523 \r
524                 [DefaultValue("theDefValue")]\r
525                 public string defElem;\r
526 \r
527                 [XmlAttribute]\r
528                 [DefaultValue("theDefValue")]\r
529                 public string defAttr;\r
530 \r
531                 [XmlText (Type=typeof(string))]\r
532                 [XmlElement (Type=typeof(int))]\r
533                 public object[] xmltext = new object[] {"aa",33,"bb",776};\r
534 \r
535                 [SoapIgnore]\r
536                 public CustomHashtable special;\r
537 \r
538                 [XmlAttribute]\r
539                 public XmlQualifiedName attqname;\r
540 \r
541                 [XmlAttribute]\r
542                 public DateTime[] arrayAttribute;\r
543 \r
544                 [XmlArray (Namespace="mm")]\r
545                 public string[][] dummyStringArray = new string[][] {null,null};\r
546                 \r
547                 [XmlElement (Namespace="mm")]\r
548                 public DblStringContainerAnm dbscontainer;\r
549         }\r
550 \r
551         public class DblStringContainerAnm\r
552         {\r
553                 public object at;\r
554         }\r
555 \r
556         [XmlType(Namespace="mm")]\r
557         public class DblStringContainer\r
558         {\r
559                 [XmlArrayItem (NestingLevel=1)]\r
560                 public string [][] doublestring;\r
561                 public object at;\r
562         }\r
563 \r
564         [SoapType(TypeName="TC")]\r
565         [XmlType(TypeName="TC")]\r
566         [XmlInclude(typeof(TB))]\r
567         [SoapInclude(typeof(TB))]\r
568         public class TA\r
569         {\r
570                 public int xx = 1;\r
571 \r
572                 [XmlText]\r
573                 [SoapIgnore]\r
574                 public XmlNode[] extraTextNodes;\r
575                 \r
576                 public static void AssertEquals (string id, TA expected, TA ob)\r
577                 {\r
578                         if (!AssertionHelper.AssertType (id, expected, ob)) return;\r
579                         Assertion.AssertEquals (id + " xx", expected.xx, ob.xx);\r
580                         // TODO: extraTextNodes\r
581                 }\r
582         }\r
583 \r
584         public class TB: TA\r
585         {\r
586                 public int yy = 2;\r
587                 \r
588                 public static void AssertEquals (string id, TB expected, TB ob)\r
589                 {\r
590                         if (!AssertionHelper.AssertType (id, expected, ob)) return;\r
591                         Assertion.AssertEquals (id + " yy", expected.yy, ob.yy);\r
592                         TA.AssertEquals (id + " base", expected, ob);\r
593                 }\r
594         }\r
595 \r
596         public class UnknownAttributeTester\r
597 \r
598         {\r
599                 [SoapAttribute]\r
600                 [XmlAttribute]\r
601                 public string aa;\r
602         \r
603                 [SoapIgnore]\r
604                 [XmlAnyAttribute]\r
605                 public XmlAttribute[] extraAtts;\r
606 \r
607                 //              [XmlText(Type=typeof(XmlNode))]\r
608                 //              public XmlNode extraText;\r
609                 \r
610                 public static void AssertEquals (string id, UnknownAttributeTester exp, UnknownAttributeTester ob)\r
611                 {\r
612                         if (!AssertionHelper.AssertType (id, exp, ob)) return;\r
613                         Assertion.AssertEquals (id + " aa", exp.aa, ob.aa);\r
614                         \r
615                         if (!AssertionHelper.AssertType (id + " extraAtts", exp.extraAtts, ob.extraAtts)) return;\r
616                         \r
617                         int p = 0;\r
618                         for (int n=0; n<ob.extraAtts.Length; n++)\r
619                         {\r
620                                 XmlAttribute at = ob.extraAtts [n];\r
621                                 if (at.NamespaceURI == "http://www.w3.org/2000/xmlns/") continue;\r
622                                 Assertion.Assert (id + " extraAtts length", p < exp.extraAtts.Length);\r
623                                 AssertionHelper.AssertEqualsXml (id + ".extraAtts " + n, exp.extraAtts [p], ob.extraAtts[n]);\r
624                                 p++;\r
625                         }\r
626                 }\r
627         }\r
628 \r
629         [SoapType(TypeName="UnTestPart", Namespace="mm")]\r
630         [XmlType(TypeName="UnTestPart", Namespace="mm")]\r
631         public class TestPart\r
632         {\r
633                 public string name;\r
634                 public bool bval;\r
635                 \r
636                 public static void AssertEquals (string id, TestPart expected, TestPart ob)\r
637                 {\r
638                         if (!AssertionHelper.AssertType (id, expected, ob)) return;\r
639                         Assertion.AssertEquals (id + " name", expected.name, ob.name);\r
640                         Assertion.AssertEquals (id + " bval", expected.bval, ob.bval);\r
641                 }\r
642         }\r
643 \r
644         [SoapType(Namespace="mm")]\r
645         [XmlType(Namespace="mm")]\r
646         public class AnotherTestPart\r
647         {\r
648                 [XmlText]\r
649                 public long lo;\r
650         }\r
651 \r
652         public class UknTestPart : Test\r
653         {\r
654                 [XmlElement(IsNullable=true)]\r
655                 public string uname;\r
656                 public bool uval;\r
657         }\r
658 \r
659         public struct OneStruct\r
660         {\r
661                 public int aa;\r
662                 public string cc;\r
663         }\r
664 \r
665 //      [XmlType(Namespace="enum_namespace")]\r
666         public enum option \r
667         { \r
668                 AA, \r
669                 [SoapEnum(Name="xmlBB")]\r
670                 [XmlEnum(Name="xmlBB")]\r
671                 BB, \r
672                 CC, \r
673                 DD \r
674         }\r
675 \r
676         public class CustomHashtable : IXmlSerializable\r
677         {\r
678                 Hashtable data = new Hashtable ();\r
679 \r
680                 public void Add (string key, string value)\r
681                 {\r
682                         data.Add (key, value);\r
683                 }\r
684                 \r
685                 public static void AssertEquals (string id, CustomHashtable exp, CustomHashtable ob)\r
686                 {\r
687                         if (!AssertionHelper.AssertType (id, exp, ob)) return;\r
688                         if (!AssertionHelper.AssertType (id, exp.data, ob.data)) return;\r
689                         \r
690                         Assertion.AssertEquals (id + " data Count", exp.data.Count, ob.data.Count);\r
691                         \r
692                         foreach (DictionaryEntry entry in exp.data)\r
693                                 Assertion.AssertEquals (entry.Value, ob.data[entry.Key]);\r
694                 }\r
695                 \r
696                 public void ReadXml (XmlReader reader)\r
697                 {\r
698                         // Read the element enclosing the object\r
699                         reader.ReadStartElement();\r
700                         reader.MoveToContent ();\r
701 \r
702                         // Reads the "data" element\r
703                         reader.ReadStartElement();\r
704                         reader.MoveToContent ();\r
705                         while (reader.NodeType != XmlNodeType.EndElement)\r
706                         {\r
707                                 if (reader.NodeType == XmlNodeType.Element)\r
708                                 {\r
709                                         string key = reader.LocalName;\r
710                                         data [key] = reader.ReadElementString ();\r
711                                 }\r
712                                 else\r
713                                         reader.Skip ();\r
714                                 reader.MoveToContent ();\r
715                         }\r
716 \r
717                         reader.ReadEndElement ();\r
718                 }\r
719 \r
720                 public void WriteXml (XmlWriter writer)\r
721                 {\r
722                         writer.WriteStartElement ("data");\r
723                         foreach (DictionaryEntry entry in data) \r
724                         {\r
725                                 writer.WriteElementString ((string)entry.Key, (string)entry.Value);\r
726                         }\r
727                         writer.WriteEndElement ();\r
728                 }\r
729 \r
730                 public XmlSchema GetSchema ()\r
731                 {\r
732                         XmlSchema s = new XmlSchema ();\r
733                         s.TargetNamespace = "http://www.go-mono.org/schemas";\r
734                         s.Id = "monoschema";\r
735                         XmlSchemaElement e = new XmlSchemaElement ();\r
736                         e.Name = "data";\r
737                         s.Items.Add (e);\r
738                         XmlSchemaComplexType cs = new XmlSchemaComplexType ();\r
739                         XmlSchemaSequence seq = new XmlSchemaSequence ();\r
740                         XmlSchemaAny any = new XmlSchemaAny ();\r
741                         any.MinOccurs = 0;\r
742                         any.MaxOccurs = decimal.MaxValue;\r
743                         seq.Items.Add (any);\r
744                         cs.Particle = seq;\r
745                         e.SchemaType = cs;\r
746                         return s;\r
747                 }\r
748         }\r
749 }\r