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