ComplexDataStructure.cs 22 KB

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