XmlBinaryDictionaryReaderTest.cs 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496
  1. //
  2. // XmlSimpleDictionaryReaderTest.cs
  3. //
  4. // Author:
  5. // Atsushi Enomoto <[email protected]>
  6. //
  7. // Copyright (C) 2007 Novell, Inc. http://www.novell.com
  8. //
  9. // Permission is hereby granted, free of charge, to any person obtaining
  10. // a copy of this software and associated documentation files (the
  11. // "Software"), to deal in the Software without restriction, including
  12. // without limitation the rights to use, copy, modify, merge, publish,
  13. // distribute, sublicense, and/or sell copies of the Software, and to
  14. // permit persons to whom the Software is furnished to do so, subject to
  15. // the following conditions:
  16. //
  17. // The above copyright notice and this permission notice shall be
  18. // included in all copies or substantial portions of the Software.
  19. //
  20. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  21. // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  22. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  23. // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  24. // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  25. // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  26. // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  27. //
  28. using System;
  29. using System.IO;
  30. using System.Text;
  31. using System.Xml;
  32. using NUnit.Framework;
  33. namespace MonoTests.System.Xml
  34. {
  35. [TestFixture]
  36. public class XmlBinaryDictionaryReaderTest
  37. {
  38. void Read (byte [] buf)
  39. {
  40. XmlDictionaryReader reader = XmlDictionaryReader.CreateBinaryReader (new MemoryStream (buf), new XmlDictionaryReaderQuotas ());
  41. while (!reader.EOF)
  42. reader.Read ();
  43. // FIXME: use this instead; right now some tests are broken.
  44. //XmlDocument doc = new XmlDocument ();
  45. //doc.AppendChild (doc.CreateElement ("root"));
  46. //while (!reader.EOF)
  47. // doc.DocumentElement.AppendChild (doc.ReadNode (reader));
  48. }
  49. void AssertNode (XmlNodeType nodeType, string localName, string ns, string value, int depth, XmlReader reader, string label)
  50. {
  51. Assert.AreEqual (nodeType, reader.NodeType, label + ".Node");
  52. Assert.AreEqual (localName, reader.LocalName, label + ".LocalName");
  53. Assert.AreEqual (ns, reader.NamespaceURI, label + ".NS");
  54. Assert.AreEqual (value, reader.Value, label + ".Value");
  55. Assert.AreEqual (depth, reader.Depth, label + ".Depth");
  56. }
  57. [Test]
  58. [ExpectedException (typeof (ArgumentNullException))]
  59. public void NullQuotas ()
  60. {
  61. XmlDictionaryReader.CreateBinaryReader (usecase1,null);
  62. }
  63. [Test]
  64. public void UseCase1 ()
  65. {
  66. string xml = @"<?xml version=""1.0"" encoding=""utf-16""?><root a=""""><!----> <AAA xmlns=""urn:AAA""></AAA><ePfix:AAA xmlns:ePfix=""urn:AAABBB""></ePfix:AAA><AAA>CCC" + "\u3005\u4E00" + @"CCCAAA&amp;AAADDD&amp;DDD" + '\u4E01' + @"<!--COMMENT--></AAA><AAA BBB=""bbb"" pfix:BBB=""bbbbb"" xml:lang=""ja"" xml:space=""preserve"" xml:base=""local:hogehoge"" xmlns:pfix=""urn:bbb"">CCCICAg/4Aw</AAA></root>";
  67. XmlDictionaryReader reader =
  68. XmlDictionaryReader.CreateBinaryReader (usecase1,new XmlDictionaryReaderQuotas ());
  69. StringWriter sw = new StringWriter ();
  70. XmlWriter xw = XmlWriter.Create (sw);
  71. reader.Read ();
  72. while (!reader.EOF)
  73. xw.WriteNode (reader, false);
  74. xw.Close ();
  75. Assert.AreEqual (xml, sw.ToString ());
  76. }
  77. // $ : kind
  78. // ! : length
  79. static readonly byte [] usecase1 = new byte [] {
  80. // $!root$! a....!__ ___.!AAA $!urn:AA A$$!ePfi
  81. 0x40, 0x04, 0x72, 0x6F, 0x6F, 0x74, 0x04, 0x01,
  82. 0x61, 0xA8, 0x02, 0x00, 0x98, 0x05, 0x20, 0x20,
  83. 0x20, 0x20, 0x20, 0x40, 0x03, 0x41, 0x41, 0x41,
  84. 0x08, 0x07, 0x75, 0x72, 0x6E, 0x3A, 0x41, 0x41,
  85. 0x41, 0x01, 0x41, 0x05, 0x65, 0x50, 0x66, 0x69,// 40
  86. // x!AAA$!e Pfix!urn :AAABBB$ $!AAA$!C CC......
  87. 0x78, 0x03, 0x41, 0x41, 0x41, 0x09, 0x05, 0x65,
  88. 0x50, 0x66, 0x69, 0x78, 0x0A, 0x75, 0x72, 0x6E,
  89. 0x3A, 0x41, 0x41, 0x41, 0x42, 0x42, 0x42, 0x01,
  90. 0x40, 0x03, 0x41, 0x41, 0x41, 0x98, 0x0C, 0x43,
  91. 0x43, 0x43, 0xE3, 0x80, 0x85, 0xE4, 0xB8, 0x80,// 80
  92. // AAA$!DDD $AAA$!DD D$DDD... ..$!COMM ENT$$!AA
  93. 0x43, 0x43, 0x43, 0x98, 0x07, 0x41, 0x41, 0x41,
  94. 0x26, 0x41, 0x41, 0x41, 0x98, 0x07, 0x44, 0x44,
  95. 0x44, 0x26, 0x44, 0x44, 0x44, 0x98, 0x03, 0xE4,
  96. 0xB8, 0x81, 0x02, 0x07, 0x43, 0x4F, 0x4D, 0x4D,
  97. 0x45, 0x4E, 0x54, 0x01, 0x40, 0x03, 0x41, 0x41,// 120
  98. // A$!BBB$! bbb$!pfi x!BBB$!b bbbb$!xm l!lang$!
  99. 0x41, 0x04, 0x03, 0x42, 0x42, 0x42, 0x98, 0x03,
  100. 0x62, 0x62, 0x62, 0x05, 0x04, 0x70, 0x66, 0x69,
  101. 0x78, 0x03, 0x42, 0x42, 0x42, 0x98, 0x05, 0x62,
  102. 0x62, 0x62, 0x62, 0x62, 0x05, 0x03, 0x78, 0x6D,
  103. 0x6C, 0x04, 0x6C, 0x61, 0x6E, 0x67, 0x98, 0x02,// 160
  104. // ja$!xml! space$!p reserve
  105. 0x6A, 0x61, 0x05, 0x03, 0x78, 0x6D, 0x6C, 0x05,
  106. 0x73, 0x70, 0x61, 0x63, 0x65, 0x98, 0x08, 0x70,
  107. 0x72, 0x65, 0x73, 0x65, 0x72, 0x76, 0x65, 0x05,
  108. 0x03, 0x78, 0x6D, 0x6C, 0x04, 0x62, 0x61, 0x73,
  109. 0x65, 0x98, 0x0E, 0x6C, 0x6F, 0x63, 0x61, 0x6C,// 200
  110. // ..hogehog e$!pfix! urn:bbb$ $CCC$!BA SE64$
  111. 0x3A, 0x68, 0x6F, 0x67, 0x65, 0x68, 0x6F, 0x67,
  112. 0x65, 0x09, 0x04, 0x70, 0x66, 0x69, 0x78, 0x07,
  113. 0x75, 0x72, 0x6E, 0x3A, 0x62, 0x62, 0x62, 0x98,
  114. 0x03, 0x43, 0x43, 0x43, 0x9F, 0x06, 0x20, 0x20,
  115. 0x20, 0xFF, 0x80, 0x30, 0x01,
  116. };
  117. [Test]
  118. public void UseCase2 ()
  119. {
  120. XmlDictionary dic = new XmlDictionary ();
  121. dic.Add (String.Empty);
  122. dic.Add ("FOO");
  123. dic.Add ("BAR");
  124. dic.Add ("urn:bar");
  125. XmlDictionaryReader reader =
  126. XmlDictionaryReader.CreateBinaryReader (new MemoryStream (usecase2), dic, new XmlDictionaryReaderQuotas ());
  127. while (!reader.EOF)
  128. reader.Read ();
  129. }
  130. // $ : kind
  131. // / : especially. EndElement
  132. // ! : length
  133. // @ : dictionary index
  134. // ^ : missing ns decl?
  135. static readonly byte [] usecase2 = new byte [] {
  136. // $@$!BAR$ @$@///$@ ^@$!ppp! $!ppp@$! xyz$!bbb
  137. 0x42, 2, 0x40, 3, 0x42, 0x41, 0x52, 0x42,
  138. 2, 0x42, 4, 1, 1, 1, 0x42, 4,
  139. 10, 6, 0x43, 3, 0x70, 0x70, 0x70, 4,
  140. 11, 3, 0x70, 0x70, 0x70, 6, 0x99, 3,
  141. 0x78, 0x79, 0x7A, 0x98, 4, 0x62, 0x62, 0x62,
  142. // b$!ccc$G UIDGUIDG UIDGUID$ !FOO$!GU IDGUIDGU
  143. 0x62, 0x98, 3, 0x63, 0x63, 0x63, 0xB1, 0x22,
  144. 0x22, 0x11, 0x11, 0x33, 0x33, 0x44, 0x44, 0x55,
  145. 0x55, 0x66, 0x66, 0x77, 0x77, 0x88, 0x88, 0x40,
  146. 3, 0x46, 0x4F, 0x4F, 0x04, 3, 0x41, 0x41,
  147. 0x41, 0xB0, 0x22, 0x22, 0x11, 0x11, 0x33, 0x33,
  148. // IDGUIDGU ID$!BBB$T IMESPAN $!CC$!UN IQUEIDUN
  149. 0x44, 0x44, 0x55, 0x55, 0x66, 0x66, 0x77, 0x77,
  150. 0x88, 0x88, 0x04, 3, 0x42, 0x42, 0x42, 0xAE,
  151. 0, 0, 0, 0, 0, 0, 0, 0,
  152. 0x04, 2, 0x43, 0x43, 0x98, 0x2B, 0x75, 0x75,
  153. 0x69, 0x64, 0x2D, 0x30, 0x30, 0x30, 0x30, 0x30,
  154. // IQUEIDUN IQUEIDUN IQUEIDUN IQUEID.. .$!XX$$$!
  155. 0x30, 0x30, 0x30, 0x2D, 0x30, 0x30, 0x30, 0x30,
  156. 0x2D, 0x30, 0x30, 0x30, 0x30, 0x2D, 0x30, 0x30,
  157. 0x30, 0x30, 0x2D, 0x30, 0x30, 0x30, 0x30, 0x30,
  158. 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x2D,
  159. 0x31, 0x40, 2, 0x58, 0x58, 0x86, 0x85, 0x41, 2,
  160. // xx!aaa$!x x!urn:xxx
  161. 0x78, 0x78, 3, 0x61, 0x61, 0x61, 0x09, 2, 0x78,
  162. 0x78, 0x07, 0x75, 0x72, 0x6E, 0x3A, 0x7A, 0x7A,
  163. 0x7A, 1, 1, 1
  164. };
  165. [Test]
  166. public void ElementWithNS ()
  167. {
  168. byte [] bytes = new byte [] {
  169. 0x42, 0, 10, 2, 0x98, 3, 0x61, 0x61,
  170. 0x61, 0x42, 0, 0x42, 2, 1, 1, 1};
  171. XmlDictionary dic = new XmlDictionary ();
  172. dic.Add ("FOO");
  173. dic.Add ("foo");
  174. XmlDictionaryReader reader =
  175. XmlDictionaryReader.CreateBinaryReader (new MemoryStream (bytes), dic, new XmlDictionaryReaderQuotas ());
  176. while (!reader.EOF)
  177. reader.Read ();
  178. }
  179. [Test]
  180. public void ContainsInvalidIndex ()
  181. {
  182. byte [] bytes = new byte [] {
  183. 0x42, 1, 10, 2, 0x98, 3, 0x61, 0x61,
  184. 0x61, 0x42, 0, 0x42, 2, 1, 1, 1};
  185. XmlDictionary dic = new XmlDictionary ();
  186. dic.Add ("FOO");
  187. dic.Add ("foo");
  188. XmlDictionaryReader dr = XmlDictionaryReader.CreateBinaryReader (new MemoryStream (bytes), dic, new XmlDictionaryReaderQuotas ());
  189. try {
  190. dr.Read ();
  191. Assert.Fail ("dictionary index 1 should be regarded as invalid.");
  192. } catch (XmlException) {
  193. }
  194. }
  195. [Test]
  196. public void Beyond128DictionaryEntries ()
  197. {
  198. XmlDictionaryString ds;
  199. MemoryStream ms = new MemoryStream ();
  200. XmlDictionary dic = new XmlDictionary ();
  201. for (int i = 0; i < 260; i++)
  202. Assert.AreEqual (i, dic.Add ("n" + i).Key, "dic");
  203. XmlDictionary dic2 = new XmlDictionary ();
  204. XmlBinaryReaderSession session = new XmlBinaryReaderSession ();
  205. int idx;
  206. for (int i = 0; i < 260; i++)
  207. Assert.AreEqual (i, session.Add (i, "s" + i).Key, "session");
  208. byte [] bytes = new byte [] {
  209. // so, when it went beyond 128, the index
  210. // becomes 2 bytes, where
  211. // - the first byte always becomes > 80, and
  212. // - the second byte becomes (n / 0x80) * 2.
  213. 0x42, 0x80, 2, 0x0A, 0x82, 2,
  214. 0x42, 0x85, 2, 0x0A, 0x87, 2,
  215. 0x42, 0x88, 2, 0x0A, 0x8B, 2,
  216. 0x42, 0x80, 4, 0x0A, 0x81, 4,
  217. 1, 1, 1, 1};
  218. XmlDictionaryReader reader = XmlDictionaryReader.CreateBinaryReader (new MemoryStream (bytes), dic, new XmlDictionaryReaderQuotas (), session);
  219. Assert.IsTrue (reader.Read (), "#r1");
  220. Assert.AreEqual ("n128", reader.LocalName, "#l1");
  221. Assert.IsTrue (reader.Read (), "#r2");
  222. Assert.AreEqual ("s130", reader.LocalName, "#l1");
  223. Assert.IsTrue (reader.Read (), "#r3");
  224. Assert.AreEqual ("n132", reader.LocalName, "#l1");
  225. Assert.IsTrue (reader.Read (), "#r4");
  226. Assert.AreEqual ("n256", reader.LocalName, "#l1");
  227. for (int i = 0; i < 4; i++) {
  228. Assert.IsTrue (reader.Read (), "#re" + i);
  229. Assert.AreEqual (XmlNodeType.EndElement, reader.NodeType, "#ne" + i);
  230. }
  231. Assert.IsFalse (reader.Read ()); // EOF
  232. }
  233. [Test]
  234. public void GlobalAttributes ()
  235. {
  236. XmlDictionary dic = new XmlDictionary ();
  237. dic.Add ("n1");
  238. dic.Add ("urn:foo");
  239. dic.Add ("n2");
  240. dic.Add ("n3");
  241. dic.Add ("n4");
  242. dic.Add ("urn:bar");
  243. dic.Add ("n7");
  244. // 0x0C nameidx (value) 0x0D nameidx (value)
  245. // 0x07 (prefix) nameidx (value)
  246. // 0x05 (prefix) (name) (value)
  247. // 0x04... 0x06... 0x05...
  248. // 0x0A nsidx
  249. // 0x0B (prefix) nsidx
  250. // 0x0B... 0x0B...
  251. // 0x09 (prefix) (ns)
  252. byte [] bytes = new byte [] {
  253. // $@$@$$@$ !v$!aaa@
  254. // $@!bbb!n 5$$@$!a@
  255. // $!aaa!$! bbb$urn:foo$
  256. 0x42, 0,
  257. 0x0C, 4, 0xA8,
  258. 0x0D, 6, 0x98, 1, 0x76,
  259. 0x07, 3, 0x61, 0x61, 0x61, 8, 0xA8, // 16
  260. 0x05, 3, 0x62, 0x62, 0x62, 2, 0x6E, 0x35, 0xA8,
  261. 0x04, 2, 0x6E, 0x36, 0xA8, // 30
  262. 0x06, 12, 0xA8,
  263. 0x05, 3, 0x62, 0x62, 0x62, 2, 0x6E, 0x38, 0xA8,
  264. 0x0A, 2,
  265. 0x0B, 1, 0x61, 10, // 48
  266. 0x0B, 1, 0x62, 2,
  267. 0x0B, 3, 0x61, 0x61, 0x61, 10,
  268. 0x09, 3, 0x62, 0x62, 0x62,
  269. 0x07, 0x75, 0x72, 0x6E, 0x3A, 0x66, 0x6F, 0x6F,
  270. 1};
  271. XmlDictionaryReader reader = XmlDictionaryReader.CreateBinaryReader (new MemoryStream (bytes), dic, new XmlDictionaryReaderQuotas ());
  272. while (!reader.EOF)
  273. reader.Read ();
  274. }
  275. [Test]
  276. public void AttributeXmlns ()
  277. {
  278. // equivalent to WriteXmlnsAttribute()
  279. XmlDictionaryString ds;
  280. XmlDictionary dic = new XmlDictionary ();
  281. dic.Add ("xmlns");
  282. dic.Add ("http://www.w3.org/2000/xmlns/");
  283. byte [] bytes = new byte [] {
  284. // 40 (root) 04 (a) A8
  285. // 09 (foo) (urn:foo) 08 (urn:bar)
  286. 0x40, 4, 0x72, 0x6F, 0x6F, 0x74,
  287. 0x04, 1, 0x61, 0xA8,
  288. 0x09, 3, 0x66, 0x6F, 0x6F, 7, 0x75, 0x72, 0x6E, 0x3A, 0x66, 0x6F, 0x6F,
  289. 0x08, 7, 0x75, 0x72, 0x6E, 0x3A, 0x62, 0x61, 0x72, 1
  290. };
  291. Read (bytes);
  292. XmlDictionaryReader reader = XmlDictionaryReader.CreateBinaryReader (new MemoryStream (bytes), new XmlDictionaryReaderQuotas ());
  293. Assert.IsTrue (reader.Read (), "#1-1");
  294. AssertNode (XmlNodeType.Element, "root", "urn:bar", "", 0, reader, "#1");
  295. reader.MoveToAttribute (0);
  296. if (reader.LocalName != "a")
  297. reader.MoveToAttribute (1);
  298. AssertNode (XmlNodeType.Attribute, "a", "", "", 1, reader, "#2");
  299. Assert.IsTrue (reader.ReadAttributeValue (), "#3");
  300. AssertNode (XmlNodeType.Text, "a", "", "", 2, reader, "#4");
  301. Assert.IsFalse (reader.ReadAttributeValue (), "#5");
  302. }
  303. [Test]
  304. public void AttributeWithLocalDictQNameIndex ()
  305. {
  306. XmlDictionary dic = new XmlDictionary ();
  307. dic.Add ("xmlns");
  308. dic.Add ("http://www.w3.org/2000/xmlns/");
  309. dic.Add ("DictionaryValue");
  310. dic.Add ("SomeDictionaryString");
  311. dic.Add ("AdditionalDictionaryString");
  312. // <d a="QNameIndex(0,8)"></d>
  313. byte [] bytes = new byte [] { 0x40, 0x01, 0x64, 0x04, 0x01, 0x61, 0xbc, 0x00, 0x08, 0x01 };
  314. XmlDictionaryReader reader = XmlDictionaryReader.CreateBinaryReader (
  315. new MemoryStream (bytes), dic, new XmlDictionaryReaderQuotas ());
  316. Assert.IsTrue (reader.Read (), "#1");
  317. AssertNode (XmlNodeType.Element, "d", "", "", 0, reader, "#2");
  318. reader.MoveToAttribute (0);
  319. if (reader.LocalName != "a")
  320. reader.MoveToAttribute (1);
  321. AssertNode (XmlNodeType.Attribute, "a", "", "a:AdditionalDictionaryString", 1, reader, "#3");
  322. Assert.IsTrue (reader.ReadAttributeValue (), "#4");
  323. AssertNode (XmlNodeType.Text, "a", "", "a:AdditionalDictionaryString", 2, reader, "#5");
  324. Assert.IsFalse (reader.ReadAttributeValue (), "#6");
  325. }
  326. [Test]
  327. public void AttributeWithSessionQNameIndex ()
  328. {
  329. XmlDictionaryString ds;
  330. XmlDictionary dic = new XmlDictionary ();
  331. XmlBinaryReaderSession ses = new XmlBinaryReaderSession();
  332. ses.Add(0, "SessionLookupValue");
  333. // <d a="QNameIndex(0x18,1)"></d>
  334. byte [] bytes = new byte [] { 0x40, 0x01, 0x64, 0x04, 0x01, 0x61, 0xbc, 0x18, 0x01, 0x01 };
  335. XmlDictionaryReader reader = XmlDictionaryReader.CreateBinaryReader (
  336. new MemoryStream (bytes), dic, new XmlDictionaryReaderQuotas (), ses);
  337. Assert.IsTrue (reader.Read (), "#1");
  338. AssertNode (XmlNodeType.Element, "d", "", "", 0, reader, "#2");
  339. reader.MoveToAttribute (0);
  340. if (reader.LocalName != "a")
  341. reader.MoveToAttribute (1);
  342. AssertNode (XmlNodeType.Attribute, "a", "", "y:SessionLookupValue", 1, reader, "#3");
  343. Assert.IsTrue (reader.ReadAttributeValue (), "#4");
  344. AssertNode (XmlNodeType.Text, "a", "", "y:SessionLookupValue", 2, reader, "#5");
  345. reader.MoveToContent ();
  346. Assert.IsFalse (reader.ReadAttributeValue (), "#6");
  347. }
  348. [Test]
  349. public void ReadTypedValues ()
  350. {
  351. Read (typed_values);
  352. }
  353. byte [] typed_values = new byte [] {
  354. 0x40, 4, 0x72, 0x6F, 0x6F, 0x74,
  355. 0x88, 5,
  356. 0x8A, 0x7D, 0x03,
  357. 0x8C, 0xBC, 0x92, 0, 0, // int
  358. 0x8C, 0x2C, 0xEB, 0x6D, 0x08, // 20
  359. 0x8E, 0x80, 0x55, 0xF5, 0x51, 0x01, 0, 0, 0,
  360. 0x90, 0xD7, 0xB3, 0xDD, 0x3F, // float
  361. 0x92, 0x4C, 0x15, 0x31, 0x91, 0x77, 0xE3, 0x01, 0x40, // 43
  362. 0x94, 0, 0, 6, 0, 0, 0, 0, 0, 0xD8, 0xEF, 0x2F, 0, 0, 0, 0, 0,
  363. 0x97, 0x80, 0x40, 0xA3, 0x29, 0xE5, 0x22, 0xC1, 8
  364. };
  365. [Test]
  366. public void ReadShortPrefixedElement ()
  367. {
  368. Read (short_prefixed_elem_value);
  369. }
  370. static readonly byte [] short_prefixed_elem_value = {
  371. 0x6D, 4, 0x72, 0x6F, 0x6F, 0x74,
  372. 0x09, 1, 0x70, 7, 0x75, 0x72, 0x6E, 0x3A, 0x66, 0x6F, 0x6F,
  373. 0x99, 4, 0x74, 0x65, 0x73, 0x74,
  374. };
  375. [Test]
  376. public void ReadInt16Array ()
  377. {
  378. Read (array_int32);
  379. XmlDictionaryReader reader = XmlDictionaryReader.CreateBinaryReader (new MemoryStream (array_int16), new XmlDictionaryReaderQuotas ());
  380. Assert.IsTrue (reader.Read (), "#1-1");
  381. AssertNode (XmlNodeType.Element, "el", "", "", 0, reader, "#1-2");
  382. Assert.IsTrue (reader.Read (), "#2-1");
  383. AssertNode (XmlNodeType.Text, "", "", "4", 1, reader, "#2-2");
  384. Assert.IsTrue (reader.Read (), "#3-1");
  385. AssertNode (XmlNodeType.EndElement, "el", "", "", 0, reader, "#3-2");
  386. Assert.IsTrue (reader.Read (), "#4-1");
  387. AssertNode (XmlNodeType.Element, "el", "", "", 0, reader, "#4-2");
  388. Assert.IsTrue (reader.Read (), "#5-1");
  389. AssertNode (XmlNodeType.Text, "", "", "6", 1, reader, "#5-2");
  390. Assert.IsTrue (reader.Read (), "#6-1");
  391. AssertNode (XmlNodeType.EndElement, "el", "", "", 0, reader, "#6-2");
  392. for (int i = 0; i < 3; i++) // 6, 8, 10
  393. for (int j = 0; j < 3; j++) // el / text / endel
  394. Assert.IsTrue (reader.Read (), "#x-" + i + j);
  395. Assert.IsFalse (reader.Read (), "End");
  396. }
  397. static readonly byte [] array_int16 = {
  398. 0x03, 0x40, 2, 0x65, 0x6C, 0x01,
  399. 0x8B, 5, 4, 0, 6, 0, 8, 0, 10, 0, 12, 0,
  400. };
  401. [Test]
  402. public void ReadInt32Array ()
  403. {
  404. Read (array_int32);
  405. }
  406. // make sure that 0 is not written in shortened format.
  407. static readonly byte [] array_int32 = {
  408. 0x03, 0x40, 2, 0x65, 0x6C, 0x01,
  409. 0x8D, 3, 0, 0, 0, 0, 6, 0, 0, 0, 8, 0, 0, 0,
  410. };
  411. [Test]
  412. public void ReadUtf16Array ()
  413. {
  414. // example of SOAP fault returned by .NET.
  415. var buffer = new byte [] {
  416. 0x56,0x02,0x0B,0x01,0x73,0x04,0x0B,0x01,0x61,0x06,0x56,0x08,0x44,0x0A,0x1E,0x00,
  417. 0x82,0x99,0x2F,0x68,0x74,0x74,0x70,0x3A,0x2F,0x2F,0x77,0x77,0x77,0x2E,0x77,0x33,
  418. 0x2E,0x6F,0x72,0x67,0x2F,0x32,0x30,0x30,0x35,0x2F,0x30,0x38,0x2F,0x61,0x64,0x64,
  419. 0x72,0x65,0x73,0x73,0x69,0x6E,0x67,0x2F,0x73,0x6F,0x61,0x70,0x2F,0x66,0x61,0x75,
  420. 0x6C,0x74,0x44,0x0C,0x1E,0x00,0x82,0xAB,0x14,0x01,0x56,0x0E,0x56,0x86,0x01,0x56,
  421. 0x8E,0x01,0x56,0x9A,0x01,0x98,0x01,0x73,0x98,0x01,0x3A,0x99,0x06,0x53,0x65,0x6E,
  422. 0x64,0x65,0x72,0x56,0x9C,0x01,0x56,0x9A,0x01,0x98,0x01,0x61,0x98,0x01,0x3A,0x99,
  423. 0x16,0x44,0x65,0x73,0x74,0x69,0x6E,0x61,0x74,0x69,0x6F,0x6E,0x55,0x6E,0x72,0x65,
  424. 0x61,0x63,0x68,0x61,0x62,0x6C,0x65,0x01,0x01,0x56,0x90,0x01,0x56,0x92,0x01,0x05,
  425. 0x03,0x78,0x6D,0x6C,0x04,0x6C,0x61,0x6E,0x67,0x98,0x05,0x6A,0x61,0x2D,0x4A,0x50,
  426. 0xB7,0xEA,0x45,0x00,0x6E,0x00,0x64,0x00,0x70,0x00,0x6F,0x00,0x69,0x00,0x6E,0x00,
  427. 0x74,0x00,0x44,0x00,0x69,0x00,0x73,0x00,0x70,0x00,0x61,0x00,0x74,0x00,0x63,0x00,
  428. 0x68,0x00,0x65,0x00,0x72,0x00,0x20,0x00,0x67,0x30,0x20,0x00,0x41,0x00,0x64,0x00,
  429. 0x64,0x00,0x72,0x00,0x65,0x00,0x73,0x00,0x73,0x00,0x46,0x00,0x69,0x00,0x6C,0x00,
  430. 0x74,0x00,0x65,0x00,0x72,0x00,0x20,0x00,0x4C,0x30,0x00,0x4E,0xF4,0x81,0x57,0x30,
  431. 0x66,0x30,0x44,0x30,0x6A,0x30,0x44,0x30,0x5F,0x30,0x81,0x30,0x01,0x30,0x54,0x00,
  432. 0x6F,0x00,0x20,0x00,0x27,0x00,0x27,0x00,0x20,0x00,0x92,0x30,0x2B,0x54,0x80,0x30,
  433. 0xE1,0x30,0xC3,0x30,0xBB,0x30,0xFC,0x30,0xB8,0x30,0x92,0x30,0xD7,0x53,0xE1,0x4F,
  434. 0x74,0x50,0x67,0x30,0xE6,0x51,0x06,0x74,0x67,0x30,0x4D,0x30,0x7E,0x30,0x5B,0x30,
  435. 0x93,0x30,0x02,0x30,0x01,0x90,0xE1,0x4F,0x74,0x50,0x68,0x30,0xD7,0x53,0xE1,0x4F,
  436. 0x74,0x50,0x6E,0x30,0x20,0x00,0x45,0x00,0x6E,0x00,0x64,0x00,0x70,0x00,0x6F,0x00,
  437. 0x69,0x00,0x6E,0x00,0x74,0x00,0x41,0x00,0x64,0x00,0x64,0x00,0x72,0x00,0x65,0x00,
  438. 0x73,0x00,0x73,0x00,0x20,0x00,0x4C,0x30,0x00,0x4E,0xF4,0x81,0x57,0x30,0x66,0x30,
  439. 0x44,0x30,0x8B,0x30,0x53,0x30,0x68,0x30,0x92,0x30,0xBA,0x78,0x8D,0x8A,0x57,0x30,
  440. 0x66,0x30,0x4F,0x30,0x60,0x30,0x55,0x30,0x44,0x30,0x02,0x30,0x01,0x01,0x01,0x01};
  441. var dic = new XmlDictionary ();
  442. for (int i = 0; i < 128; i++) dic.Add ("s" + i);
  443. var xr = XmlDictionaryReader.CreateBinaryReader (new MemoryStream (buffer), dic, new XmlDictionaryReaderQuotas ());
  444. while (!xr.EOF) {
  445. xr.Read ();
  446. if (xr.NodeType == XmlNodeType.EndElement && xr.LocalName == String.Empty)
  447. Assert.Fail ("EndElement has empty name");
  448. }
  449. }
  450. }
  451. }