ComplexDataStructure.cs 21 KB

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