ComplexDataStructure.cs 21 KB

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