2
0

ComplexDataStructure.cs 22 KB

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