XmlReaderCommonTests.cs 36 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417
  1. //
  2. // System.Xml.XmlReaderCommonTests
  3. //
  4. // Authors:
  5. // Atsushi Enomoto <[email protected]>
  6. //
  7. // (C) 2003 Atsushi Enomoto
  8. // Note: Most of testcases are moved from XmlTextReaderTests.cs and
  9. // XmlNodeReaderTests.cs.
  10. //
  11. using System;
  12. using System.IO;
  13. using System.Text;
  14. using System.Xml;
  15. using System.Xml.Schema;
  16. using System.Xml.XPath;
  17. using NUnit.Framework;
  18. namespace MonoTests.System.Xml
  19. {
  20. [TestFixture]
  21. public class XmlReaderTests : Assertion
  22. {
  23. [SetUp]
  24. public void GetReady ()
  25. {
  26. document = new XmlDocument ();
  27. document.LoadXml (xml1);
  28. }
  29. XmlDocument document;
  30. const string xml1 = "<root attr1='value1'><child /></root>";
  31. const string xml2 = "<root><foo/><bar>test.</bar></root>";
  32. const string xml3 = "<root> test of <b>mixed</b> string.<![CDATA[ cdata string.]]></root>";
  33. const string xml4 = "<root>test of <b>mixed</b> string.</root>";
  34. XmlTextReader xtr;
  35. XmlNodeReader xnr;
  36. // copy from XmlTextReaderTests
  37. private void AssertStartDocument (XmlReader xmlReader)
  38. {
  39. Assert (xmlReader.ReadState == ReadState.Initial);
  40. Assert (xmlReader.NodeType == XmlNodeType.None);
  41. Assert (xmlReader.Depth == 0);
  42. Assert (!xmlReader.EOF);
  43. }
  44. private void AssertNode (
  45. XmlReader xmlReader,
  46. XmlNodeType nodeType,
  47. int depth,
  48. bool isEmptyElement,
  49. string name,
  50. string prefix,
  51. string localName,
  52. string namespaceURI,
  53. string value,
  54. int attributeCount)
  55. {
  56. Assert ("Read() return value", xmlReader.Read ());
  57. Assert ("ReadState", xmlReader.ReadState == ReadState.Interactive);
  58. Assert ("!EOF", !xmlReader.EOF);
  59. AssertNodeValues (xmlReader, nodeType, depth, isEmptyElement, name, prefix, localName, namespaceURI, value, attributeCount);
  60. }
  61. private void AssertNodeValues (
  62. XmlReader xmlReader,
  63. XmlNodeType nodeType,
  64. int depth,
  65. bool isEmptyElement,
  66. string name,
  67. string prefix,
  68. string localName,
  69. string namespaceURI,
  70. string value,
  71. int attributeCount)
  72. {
  73. AssertNodeValues (xmlReader, nodeType, depth, isEmptyElement, name, prefix, localName, namespaceURI, value, value != String.Empty, attributeCount, attributeCount > 0);
  74. }
  75. private void AssertNodeValues (
  76. XmlReader xmlReader,
  77. XmlNodeType nodeType,
  78. int depth,
  79. bool isEmptyElement,
  80. string name,
  81. string prefix,
  82. string localName,
  83. string namespaceURI,
  84. string value,
  85. bool hasValue,
  86. int attributeCount,
  87. bool hasAttributes)
  88. {
  89. AssertEquals ("NodeType", nodeType, xmlReader.NodeType);
  90. AssertEquals ("IsEmptyElement", isEmptyElement, xmlReader.IsEmptyElement);
  91. AssertEquals ("name", name, xmlReader.Name);
  92. AssertEquals ("prefix", prefix, xmlReader.Prefix);
  93. AssertEquals ("localName", localName, xmlReader.LocalName);
  94. AssertEquals ("namespaceURI", namespaceURI, xmlReader.NamespaceURI);
  95. AssertEquals ("Depth", depth, xmlReader.Depth);
  96. AssertEquals ("hasValue", hasValue, xmlReader.HasValue);
  97. AssertEquals ("Value", value, xmlReader.Value);
  98. AssertEquals ("hasAttributes", hasAttributes, xmlReader.HasAttributes);
  99. AssertEquals ("attributeCount", attributeCount, xmlReader.AttributeCount);
  100. }
  101. private void AssertAttribute (
  102. XmlReader xmlReader,
  103. string name,
  104. string prefix,
  105. string localName,
  106. string namespaceURI,
  107. string value)
  108. {
  109. AssertEquals ("value", value, xmlReader [name]);
  110. Assert (xmlReader.GetAttribute (name) == value);
  111. if (namespaceURI != String.Empty) {
  112. Assert (xmlReader[localName, namespaceURI] == value);
  113. Assert (xmlReader.GetAttribute (localName, namespaceURI) == value);
  114. }
  115. }
  116. private void AssertEndDocument (XmlReader xmlReader)
  117. {
  118. Assert ("could read", !xmlReader.Read ());
  119. AssertEquals ("NodeType is not XmlNodeType.None", XmlNodeType.None, xmlReader.NodeType);
  120. AssertEquals ("Depth is not 0", 0, xmlReader.Depth);
  121. AssertEquals ("ReadState is not ReadState.EndOfFile", ReadState.EndOfFile, xmlReader.ReadState);
  122. Assert ("not EOF", xmlReader.EOF);
  123. xmlReader.Close ();
  124. AssertEquals ("ReadState is not ReadState.Cosed", ReadState.Closed, xmlReader.ReadState);
  125. }
  126. private delegate void TestMethod (XmlReader reader);
  127. private void RunTest (string xml, TestMethod method)
  128. {
  129. xtr = new XmlTextReader (new StringReader (xml));
  130. method (xtr);
  131. // DTD validation
  132. xtr = new XmlTextReader (new StringReader (xml));
  133. XmlValidatingReader xvr = new XmlValidatingReader (xtr);
  134. xvr.ValidationType = ValidationType.DTD;
  135. xvr.EntityHandling = EntityHandling.ExpandCharEntities;
  136. method (xvr);
  137. // XSD validation
  138. xtr = new XmlTextReader (new StringReader (xml));
  139. xvr = new XmlValidatingReader (xtr);
  140. xvr.EntityHandling = EntityHandling.ExpandCharEntities;
  141. method (xvr);
  142. document.XmlResolver = null;
  143. document.LoadXml (xml);
  144. xnr = new XmlNodeReader (document);
  145. method (xnr);
  146. #if NET_2_0
  147. /*
  148. // XPathNavigatorReader tests
  149. System.Xml.XPath.XPathDocument doc = new System.Xml.XPath.XPathDocument (new StringReader (xml));
  150. XmlReader xpr = doc.CreateNavigator ().ReadSubtree ();
  151. method (xpr);
  152. */
  153. #endif
  154. }
  155. [Test]
  156. public void InitialState ()
  157. {
  158. RunTest (xml1, new TestMethod (InitialState));
  159. }
  160. private void InitialState (XmlReader reader)
  161. {
  162. AssertEquals ("Depth", 0, reader.Depth);
  163. AssertEquals ("EOF", false, reader.EOF);
  164. AssertEquals ("HasValue", false, reader.HasValue);
  165. AssertEquals ("IsEmptyElement", false, reader.IsEmptyElement);
  166. AssertEquals ("LocalName", String.Empty, reader.LocalName);
  167. AssertEquals ("NodeType", XmlNodeType.None, reader.NodeType);
  168. AssertEquals ("ReadState", ReadState.Initial, reader.ReadState);
  169. }
  170. [Test]
  171. public void Read ()
  172. {
  173. RunTest (xml1, new TestMethod (Read));
  174. }
  175. public void Read (XmlReader reader)
  176. {
  177. reader.Read ();
  178. AssertEquals ("<root>.NodeType", XmlNodeType.Element, reader.NodeType);
  179. AssertEquals ("<root>.Name", "root", reader.Name);
  180. AssertEquals ("<root>.ReadState", ReadState.Interactive, reader.ReadState);
  181. AssertEquals ("<root>.Depth", 0, reader.Depth);
  182. // move to 'child'
  183. reader.Read ();
  184. AssertEquals ("<child/>.Depth", 1, reader.Depth);
  185. AssertEquals ("<child/>.NodeType", XmlNodeType.Element, reader.NodeType);
  186. AssertEquals ("<child/>.Name", "child", reader.Name);
  187. reader.Read ();
  188. AssertEquals ("</root>.Depth", 0, reader.Depth);
  189. AssertEquals ("</root>.NodeType", XmlNodeType.EndElement, reader.NodeType);
  190. AssertEquals ("</root>.Name", "root", reader.Name);
  191. reader.Read ();
  192. AssertEquals ("end.EOF", true, reader.EOF);
  193. AssertEquals ("end.NodeType", XmlNodeType.None, reader.NodeType);
  194. }
  195. [Test]
  196. [Category ("NotDotNet")]
  197. public void ReadAttributeValue ()
  198. {
  199. RunTest ("<root attr=''/>", new TestMethod (ReadAttributeValue));
  200. }
  201. public void ReadAttributeValue (XmlReader reader)
  202. {
  203. reader.Read (); // root
  204. Assert (reader.MoveToFirstAttribute ());
  205. // It looks like that MS.NET shows AttributeCount and
  206. // HasAttributes as the same as element node!
  207. this.AssertNodeValues (reader, XmlNodeType.Attribute,
  208. 1, false, "attr", "", "attr", "", "", true, 1, true);
  209. Assert (reader.ReadAttributeValue ());
  210. // MS.NET XmlTextReader fails. Its Prefix returns
  211. // null instead of "". It is fixed in MS.NET 2.0.
  212. this.AssertNodeValues (reader, XmlNodeType.Text,
  213. 2, false, "", "", "", "", "", true, 1, true);
  214. Assert (reader.MoveToElement ());
  215. this.AssertNodeValues (reader, XmlNodeType.Element,
  216. 0, true, "root", "", "root", "", "", false, 1, true);
  217. }
  218. [Test]
  219. public void ReadEmptyElement ()
  220. {
  221. RunTest (xml2, new TestMethod (ReadEmptyElement));
  222. }
  223. public void ReadEmptyElement (XmlReader reader)
  224. {
  225. reader.Read (); // root
  226. AssertEquals (false, reader.IsEmptyElement);
  227. reader.Read (); // foo
  228. AssertEquals ("foo", reader.Name);
  229. AssertEquals (true, reader.IsEmptyElement);
  230. reader.Read (); // bar
  231. AssertEquals ("bar", reader.Name);
  232. AssertEquals (false, reader.IsEmptyElement);
  233. }
  234. [Test]
  235. public void ReadStringFromElement ()
  236. {
  237. RunTest (xml3, new TestMethod (ReadStringFromElement));
  238. }
  239. public void ReadStringFromElement (XmlReader reader)
  240. {
  241. // Note: ReadString() test works only when the reader is
  242. // positioned at the container element.
  243. // In case the reader is positioned at the first
  244. // character node, XmlTextReader and XmlNodeReader works
  245. // different!!
  246. reader.Read ();
  247. string s = reader.ReadString ();
  248. AssertEquals ("readString.1.ret_val", " test of ", s);
  249. AssertEquals ("readString.1.Name", "b", reader.Name);
  250. s = reader.ReadString ();
  251. AssertEquals ("readString.2.ret_val", "mixed", s);
  252. AssertEquals ("readString.2.NodeType", XmlNodeType.EndElement, reader.NodeType);
  253. s = reader.ReadString (); // never proceeds.
  254. AssertEquals ("readString.3.ret_val", String.Empty, s);
  255. AssertEquals ("readString.3.NodeType", XmlNodeType.EndElement, reader.NodeType);
  256. reader.Read ();
  257. AssertEquals ("readString.4.NodeType", XmlNodeType.Text, reader.NodeType);
  258. AssertEquals ("readString.4.Value", " string.", reader.Value);
  259. s = reader.ReadString (); // reads the same Text node.
  260. AssertEquals ("readString.5.ret_val", " string. cdata string.", s);
  261. AssertEquals ("readString.5.NodeType", XmlNodeType.EndElement, reader.NodeType);
  262. }
  263. [Test]
  264. public void ReadInnerXml ()
  265. {
  266. const string xml = "<root><foo>test of <b>mixed</b> string.</foo><bar /></root>";
  267. RunTest (xml, new TestMethod (ReadInnerXml));
  268. }
  269. public void ReadInnerXml (XmlReader reader)
  270. {
  271. reader.Read ();
  272. reader.Read ();
  273. AssertEquals ("initial.ReadState", ReadState.Interactive, reader.ReadState);
  274. AssertEquals ("initial.EOF", false, reader.EOF);
  275. AssertEquals ("initial.NodeType", XmlNodeType.Element, reader.NodeType);
  276. string s = reader.ReadInnerXml ();
  277. AssertEquals ("read_all", "test of <b>mixed</b> string.", s);
  278. AssertEquals ("after.Name", "bar", reader.Name);
  279. AssertEquals ("after.NodeType", XmlNodeType.Element, reader.NodeType);
  280. }
  281. [Test]
  282. public void EmptyElement ()
  283. {
  284. RunTest ("<foo/>", new TestMethod (EmptyElement));
  285. }
  286. public void EmptyElement (XmlReader xmlReader)
  287. {
  288. AssertStartDocument (xmlReader);
  289. AssertNode (
  290. xmlReader, // xmlReader
  291. XmlNodeType.Element, // nodeType
  292. 0, // depth
  293. true, // isEmptyElement
  294. "foo", // name
  295. String.Empty, // prefix
  296. "foo", // localName
  297. String.Empty, // namespaceURI
  298. String.Empty, // value
  299. 0 // attributeCount
  300. );
  301. AssertEndDocument (xmlReader);
  302. }
  303. [Test]
  304. public void NestedEmptyTag ()
  305. {
  306. string xml = "<foo><bar/></foo>";
  307. RunTest (xml, new TestMethod (NestedEmptyTag));
  308. }
  309. public void NestedEmptyTag (XmlReader xmlReader)
  310. {
  311. AssertStartDocument (xmlReader);
  312. AssertNode (
  313. xmlReader, // xmlReader
  314. XmlNodeType.Element, // nodeType
  315. 0, //depth
  316. false, // isEmptyElement
  317. "foo", // name
  318. String.Empty, // prefix
  319. "foo", // localName
  320. String.Empty, // namespaceURI
  321. String.Empty, // value
  322. 0 // attributeCount
  323. );
  324. AssertNode (
  325. xmlReader, // xmlReader
  326. XmlNodeType.Element, // nodeType
  327. 1, //depth
  328. true, // isEmptyElement
  329. "bar", // name
  330. String.Empty, // prefix
  331. "bar", // localName
  332. String.Empty, // namespaceURI
  333. String.Empty, // value
  334. 0 // attributeCount
  335. );
  336. AssertNode (
  337. xmlReader, // xmlReader
  338. XmlNodeType.EndElement, // nodeType
  339. 0, //depth
  340. false, // isEmptyElement
  341. "foo", // name
  342. String.Empty, // prefix
  343. "foo", // localName
  344. String.Empty, // namespaceURI
  345. String.Empty, // value
  346. 0 // attributeCount
  347. );
  348. AssertEndDocument (xmlReader);
  349. }
  350. [Test]
  351. public void NestedText ()
  352. {
  353. string xml = "<foo>bar</foo>";
  354. RunTest (xml, new TestMethod (NestedText));
  355. }
  356. public void NestedText (XmlReader xmlReader)
  357. {
  358. AssertStartDocument (xmlReader);
  359. AssertNode (
  360. xmlReader, // xmlReader
  361. XmlNodeType.Element, // nodeType
  362. 0, //depth
  363. false, // isEmptyElement
  364. "foo", // name
  365. String.Empty, // prefix
  366. "foo", // localName
  367. String.Empty, // namespaceURI
  368. String.Empty, // value
  369. 0 // attributeCount
  370. );
  371. AssertNode (
  372. xmlReader, // xmlReader
  373. XmlNodeType.Text, // nodeType
  374. 1, //depth
  375. false, // isEmptyElement
  376. String.Empty, // name
  377. String.Empty, // prefix
  378. String.Empty, // localName
  379. String.Empty, // namespaceURI
  380. "bar", // value
  381. 0 // attributeCount
  382. );
  383. AssertNode (
  384. xmlReader, // xmlReader
  385. XmlNodeType.EndElement, // nodeType
  386. 0, //depth
  387. false, // isEmptyElement
  388. "foo", // name
  389. String.Empty, // prefix
  390. "foo", // localName
  391. String.Empty, // namespaceURI
  392. String.Empty, // value
  393. 0 // attributeCount
  394. );
  395. AssertEndDocument (xmlReader);
  396. }
  397. [Test]
  398. public void EmptyElementWithAttributes ()
  399. {
  400. string xml = @"<foo bar=""baz"" quux='quuux' x:foo='x-foo' xmlns:x = 'urn:xfoo' />";
  401. RunTest (xml, new TestMethod (EmptyElementWithAttributes ));
  402. }
  403. public void EmptyElementWithAttributes (XmlReader xmlReader)
  404. {
  405. AssertStartDocument (xmlReader);
  406. AssertNode (
  407. xmlReader, // xmlReader
  408. XmlNodeType.Element, // nodeType
  409. 0, //depth
  410. true, // isEmptyElement
  411. "foo", // name
  412. String.Empty, // prefix
  413. "foo", // localName
  414. String.Empty, // namespaceURI
  415. String.Empty, // value
  416. 4 // attributeCount
  417. );
  418. AssertAttribute (
  419. xmlReader, // xmlReader
  420. "bar", // name
  421. String.Empty, // prefix
  422. "bar", // localName
  423. String.Empty, // namespaceURI
  424. "baz" // value
  425. );
  426. AssertAttribute (
  427. xmlReader, // xmlReader
  428. "quux", // name
  429. String.Empty, // prefix
  430. "quux", // localName
  431. String.Empty, // namespaceURI
  432. "quuux" // value
  433. );
  434. AssertAttribute (
  435. xmlReader, // xmlReader
  436. "notexist", // name
  437. String.Empty, // prefix
  438. "notexist", // localName
  439. String.Empty, // namespaceURI
  440. null // value
  441. );
  442. AssertAttribute (
  443. xmlReader, // xmlReader
  444. "x:foo", // name
  445. "x", // prefix
  446. "foo", // localName
  447. "urn:xfoo", // namespaceURI
  448. "x-foo" // value
  449. );
  450. AssertAttribute (
  451. xmlReader, // xmlReader
  452. "x:bar", // name
  453. "x", // prefix
  454. "bar", // localName
  455. "urn:xfoo", // namespaceURI
  456. null // value
  457. );
  458. AssertEndDocument (xmlReader);
  459. }
  460. [Test]
  461. public void ProcessingInstructionBeforeDocumentElement ()
  462. {
  463. string xml = "<?foo bar?><baz/>";
  464. RunTest (xml, new TestMethod (ProcessingInstructionBeforeDocumentElement));
  465. }
  466. public void ProcessingInstructionBeforeDocumentElement (XmlReader xmlReader)
  467. {
  468. AssertStartDocument (xmlReader);
  469. AssertNode (
  470. xmlReader, // xmlReader
  471. XmlNodeType.ProcessingInstruction, // nodeType
  472. 0, //depth
  473. false, // isEmptyElement
  474. "foo", // name
  475. String.Empty, // prefix
  476. "foo", // localName
  477. String.Empty, // namespaceURI
  478. "bar", // value
  479. 0 // attributeCount
  480. );
  481. AssertNode (
  482. xmlReader, // xmlReader
  483. XmlNodeType.Element, // nodeType
  484. 0, //depth
  485. true, // isEmptyElement
  486. "baz", // name
  487. String.Empty, // prefix
  488. "baz", // localName
  489. String.Empty, // namespaceURI
  490. String.Empty, // value
  491. 0 // attributeCount
  492. );
  493. AssertEndDocument (xmlReader);
  494. }
  495. [Test]
  496. public void CommentBeforeDocumentElement ()
  497. {
  498. string xml = "<!--foo--><bar/>";
  499. RunTest (xml, new TestMethod (CommentBeforeDocumentElement));
  500. }
  501. public void CommentBeforeDocumentElement (XmlReader xmlReader)
  502. {
  503. AssertStartDocument (xmlReader);
  504. AssertNode (
  505. xmlReader, // xmlReader
  506. XmlNodeType.Comment, // nodeType
  507. 0, //depth
  508. false, // isEmptyElement
  509. String.Empty, // name
  510. String.Empty, // prefix
  511. String.Empty, // localName
  512. String.Empty, // namespaceURI
  513. "foo", // value
  514. 0 // attributeCount
  515. );
  516. AssertNode (
  517. xmlReader, // xmlReader
  518. XmlNodeType.Element, // nodeType
  519. 0, //depth
  520. true, // isEmptyElement
  521. "bar", // name
  522. String.Empty, // prefix
  523. "bar", // localName
  524. String.Empty, // namespaceURI
  525. String.Empty, // value
  526. 0 // attributeCount
  527. );
  528. AssertEndDocument (xmlReader);
  529. }
  530. [Test]
  531. public void PredefinedEntities ()
  532. {
  533. string xml = "<foo>&lt;&gt;&amp;&apos;&quot;</foo>";
  534. RunTest (xml, new TestMethod (PredefinedEntities));
  535. }
  536. public void PredefinedEntities (XmlReader xmlReader)
  537. {
  538. AssertStartDocument (xmlReader);
  539. AssertNode (
  540. xmlReader, // xmlReader
  541. XmlNodeType.Element, // nodeType
  542. 0, //depth
  543. false, // isEmptyElement
  544. "foo", // name
  545. String.Empty, // prefix
  546. "foo", // localName
  547. String.Empty, // namespaceURI
  548. String.Empty, // value
  549. 0 // attributeCount
  550. );
  551. AssertNode (
  552. xmlReader, // xmlReader
  553. XmlNodeType.Text, // nodeType
  554. 1, //depth
  555. false, // isEmptyElement
  556. String.Empty, // name
  557. String.Empty, // prefix
  558. String.Empty, // localName
  559. String.Empty, // namespaceURI
  560. "<>&'\"", // value
  561. 0 // attributeCount
  562. );
  563. AssertNode (
  564. xmlReader, // xmlReader
  565. XmlNodeType.EndElement, // nodeType
  566. 0, //depth
  567. false, // isEmptyElement
  568. "foo", // name
  569. String.Empty, // prefix
  570. "foo", // localName
  571. String.Empty, // namespaceURI
  572. String.Empty, // value
  573. 0 // attributeCount
  574. );
  575. AssertEndDocument (xmlReader);
  576. }
  577. [Test]
  578. public void CharacterReferences ()
  579. {
  580. string xml = "<foo>&#70;&#x4F;&#x4f;</foo>";
  581. RunTest (xml, new TestMethod (CharacterReferences));
  582. }
  583. public void CharacterReferences (XmlReader xmlReader)
  584. {
  585. AssertStartDocument (xmlReader);
  586. AssertNode (
  587. xmlReader, // xmlReader
  588. XmlNodeType.Element, // nodeType
  589. 0, //depth
  590. false, // isEmptyElement
  591. "foo", // name
  592. String.Empty, // prefix
  593. "foo", // localName
  594. String.Empty, // namespaceURI
  595. String.Empty, // value
  596. 0 // attributeCount
  597. );
  598. AssertNode (
  599. xmlReader, // xmlReader
  600. XmlNodeType.Text, // nodeType
  601. 1, //depth
  602. false, // isEmptyElement
  603. String.Empty, // name
  604. String.Empty, // prefix
  605. String.Empty, // localName
  606. String.Empty, // namespaceURI
  607. "FOO", // value
  608. 0 // attributeCount
  609. );
  610. AssertNode (
  611. xmlReader, // xmlReader
  612. XmlNodeType.EndElement, // nodeType
  613. 0, //depth
  614. false, // isEmptyElement
  615. "foo", // name
  616. String.Empty, // prefix
  617. "foo", // localName
  618. String.Empty, // namespaceURI
  619. String.Empty, // value
  620. 0 // attributeCount
  621. );
  622. AssertEndDocument (xmlReader);
  623. }
  624. [Test]
  625. public void PredefinedEntitiesInAttribute ()
  626. {
  627. string xml = "<foo bar='&lt;&gt;&amp;&apos;&quot;'/>";
  628. RunTest (xml, new TestMethod (PredefinedEntitiesInAttribute ));
  629. }
  630. public void PredefinedEntitiesInAttribute (XmlReader xmlReader)
  631. {
  632. AssertStartDocument (xmlReader);
  633. AssertNode (
  634. xmlReader, // xmlReader
  635. XmlNodeType.Element, // nodeType
  636. 0, //depth
  637. true, // isEmptyElement
  638. "foo", // name
  639. String.Empty, // prefix
  640. "foo", // localName
  641. String.Empty, // namespaceURI
  642. String.Empty, // value
  643. 1 // attributeCount
  644. );
  645. AssertAttribute (
  646. xmlReader, // xmlReader
  647. "bar", // name
  648. String.Empty, // prefix
  649. "bar", // localName
  650. String.Empty, // namespaceURI
  651. "<>&'\"" // value
  652. );
  653. AssertEndDocument (xmlReader);
  654. }
  655. [Test]
  656. public void CharacterReferencesInAttribute ()
  657. {
  658. string xml = "<foo bar='&#70;&#x4F;&#x4f;'/>";
  659. RunTest (xml, new TestMethod (CharacterReferencesInAttribute));
  660. }
  661. public void CharacterReferencesInAttribute (XmlReader xmlReader)
  662. {
  663. AssertStartDocument (xmlReader);
  664. AssertNode (
  665. xmlReader, // xmlReader
  666. XmlNodeType.Element, // nodeType
  667. 0, //depth
  668. true, // isEmptyElement
  669. "foo", // name
  670. String.Empty, // prefix
  671. "foo", // localName
  672. String.Empty, // namespaceURI
  673. String.Empty, // value
  674. 1 // attributeCount
  675. );
  676. AssertAttribute (
  677. xmlReader, // xmlReader
  678. "bar", // name
  679. String.Empty, // prefix
  680. "bar", // localName
  681. String.Empty, // namespaceURI
  682. "FOO" // value
  683. );
  684. AssertEndDocument (xmlReader);
  685. }
  686. [Test]
  687. public void CDATA ()
  688. {
  689. string xml = "<foo><![CDATA[<>&]]></foo>";
  690. RunTest (xml, new TestMethod (CDATA));
  691. }
  692. public void CDATA (XmlReader xmlReader)
  693. {
  694. AssertStartDocument (xmlReader);
  695. AssertNode (
  696. xmlReader, // xmlReader
  697. XmlNodeType.Element, // nodeType
  698. 0, //depth
  699. false, // isEmptyElement
  700. "foo", // name
  701. String.Empty, // prefix
  702. "foo", // localName
  703. String.Empty, // namespaceURI
  704. String.Empty, // value
  705. 0 // attributeCount
  706. );
  707. AssertNode (
  708. xmlReader, // xmlReader
  709. XmlNodeType.CDATA, // nodeType
  710. 1, //depth
  711. false, // isEmptyElement
  712. String.Empty, // name
  713. String.Empty, // prefix
  714. String.Empty, // localName
  715. String.Empty, // namespaceURI
  716. "<>&", // value
  717. 0 // attributeCount
  718. );
  719. AssertNode (
  720. xmlReader, // xmlReader
  721. XmlNodeType.EndElement, // nodeType
  722. 0, //depth
  723. false, // isEmptyElement
  724. "foo", // name
  725. String.Empty, // prefix
  726. "foo", // localName
  727. String.Empty, // namespaceURI
  728. String.Empty, // value
  729. 0 // attributeCount
  730. );
  731. AssertEndDocument (xmlReader);
  732. }
  733. [Test]
  734. public void EmptyElementInDefaultNamespace ()
  735. {
  736. string xml = @"<foo xmlns='http://foo/' />";
  737. RunTest (xml, new TestMethod (EmptyElementInDefaultNamespace));
  738. }
  739. public void EmptyElementInDefaultNamespace (XmlReader xmlReader)
  740. {
  741. AssertStartDocument (xmlReader);
  742. AssertNode (
  743. xmlReader, // xmlReader
  744. XmlNodeType.Element, // nodeType
  745. 0, // depth
  746. true, // isEmptyElement
  747. "foo", // name
  748. String.Empty, // prefix
  749. "foo", // localName
  750. "http://foo/", // namespaceURI
  751. String.Empty, // value
  752. 1 // attributeCount
  753. );
  754. AssertAttribute (
  755. xmlReader, // xmlReader
  756. "xmlns", // name
  757. String.Empty, // prefix
  758. "xmlns", // localName
  759. "http://www.w3.org/2000/xmlns/", // namespaceURI
  760. "http://foo/" // value
  761. );
  762. AssertEquals ("http://foo/", xmlReader.LookupNamespace (String.Empty));
  763. AssertEndDocument (xmlReader);
  764. }
  765. [Test]
  766. public void ChildElementInNamespace ()
  767. {
  768. string xml = @"<foo:bar xmlns:foo='http://foo/'><baz:quux xmlns:baz='http://baz/' /></foo:bar>";
  769. RunTest (xml, new TestMethod (ChildElementInNamespace));
  770. }
  771. public void ChildElementInNamespace (XmlReader xmlReader)
  772. {
  773. AssertStartDocument (xmlReader);
  774. AssertNode (
  775. xmlReader, // xmlReader
  776. XmlNodeType.Element, // nodeType
  777. 0, // depth
  778. false, // isEmptyElement
  779. "foo:bar", // name
  780. "foo", // prefix
  781. "bar", // localName
  782. "http://foo/", // namespaceURI
  783. String.Empty, // value
  784. 1 // attributeCount
  785. );
  786. AssertAttribute (
  787. xmlReader, // xmlReader
  788. "xmlns:foo", // name
  789. "xmlns", // prefix
  790. "foo", // localName
  791. "http://www.w3.org/2000/xmlns/", // namespaceURI
  792. "http://foo/" // value
  793. );
  794. AssertEquals ("http://foo/", xmlReader.LookupNamespace ("foo"));
  795. AssertNode (
  796. xmlReader, // xmlReader
  797. XmlNodeType.Element, // nodeType
  798. 1, // depth
  799. true, // isEmptyElement
  800. "baz:quux", // name
  801. "baz", // prefix
  802. "quux", // localName
  803. "http://baz/", // namespaceURI
  804. String.Empty, // value
  805. 1 // attributeCount
  806. );
  807. AssertAttribute (
  808. xmlReader, // xmlReader
  809. "xmlns:baz", // name
  810. "xmlns", // prefix
  811. "baz", // localName
  812. "http://www.w3.org/2000/xmlns/", // namespaceURI
  813. "http://baz/" // value
  814. );
  815. AssertEquals ("http://foo/", xmlReader.LookupNamespace ("foo"));
  816. AssertEquals ("http://baz/", xmlReader.LookupNamespace ("baz"));
  817. AssertNode (
  818. xmlReader, // xmlReader
  819. XmlNodeType.EndElement, // nodeType
  820. 0, // depth
  821. false, // isEmptyElement
  822. "foo:bar", // name
  823. "foo", // prefix
  824. "bar", // localName
  825. "http://foo/", // namespaceURI
  826. String.Empty, // value
  827. 0 // attributeCount
  828. );
  829. AssertEquals ("http://foo/", xmlReader.LookupNamespace ("foo"));
  830. AssertNull (xmlReader.LookupNamespace ("baz"));
  831. AssertEndDocument (xmlReader);
  832. }
  833. [Test]
  834. public void ChildElementInDefaultNamespace ()
  835. {
  836. string xml = @"<foo:bar xmlns:foo='http://foo/'><baz xmlns='http://baz/' /></foo:bar>";
  837. RunTest (xml, new TestMethod (ChildElementInDefaultNamespace));
  838. }
  839. public void ChildElementInDefaultNamespace (XmlReader xmlReader)
  840. {
  841. AssertStartDocument (xmlReader);
  842. AssertNode (
  843. xmlReader, // xmlReader
  844. XmlNodeType.Element, // nodeType
  845. 0, // depth
  846. false, // isEmptyElement
  847. "foo:bar", // name
  848. "foo", // prefix
  849. "bar", // localName
  850. "http://foo/", // namespaceURI
  851. String.Empty, // value
  852. 1 // attributeCount
  853. );
  854. AssertAttribute (
  855. xmlReader, // xmlReader
  856. "xmlns:foo", // name
  857. "xmlns", // prefix
  858. "foo", // localName
  859. "http://www.w3.org/2000/xmlns/", // namespaceURI
  860. "http://foo/" // value
  861. );
  862. AssertEquals ("http://foo/", xmlReader.LookupNamespace ("foo"));
  863. AssertNode (
  864. xmlReader, // xmlReader
  865. XmlNodeType.Element, // nodeType
  866. 1, // depth
  867. true, // isEmptyElement
  868. "baz", // name
  869. String.Empty, // prefix
  870. "baz", // localName
  871. "http://baz/", // namespaceURI
  872. String.Empty, // value
  873. 1 // attributeCount
  874. );
  875. AssertAttribute (
  876. xmlReader, // xmlReader
  877. "xmlns", // name
  878. String.Empty, // prefix
  879. "xmlns", // localName
  880. "http://www.w3.org/2000/xmlns/", // namespaceURI
  881. "http://baz/" // value
  882. );
  883. AssertEquals ("http://foo/", xmlReader.LookupNamespace ("foo"));
  884. AssertEquals ("http://baz/", xmlReader.LookupNamespace (String.Empty));
  885. AssertNode (
  886. xmlReader, // xmlReader
  887. XmlNodeType.EndElement, // nodeType
  888. 0, // depth
  889. false, // isEmptyElement
  890. "foo:bar", // name
  891. "foo", // prefix
  892. "bar", // localName
  893. "http://foo/", // namespaceURI
  894. String.Empty, // value
  895. 0 // attributeCount
  896. );
  897. AssertEquals ("http://foo/", xmlReader.LookupNamespace ("foo"));
  898. AssertEndDocument (xmlReader);
  899. }
  900. [Test]
  901. public void AttributeInNamespace ()
  902. {
  903. string xml = @"<foo bar:baz='quux' xmlns:bar='http://bar/' />";
  904. RunTest (xml, new TestMethod (AttributeInNamespace));
  905. }
  906. public void AttributeInNamespace (XmlReader xmlReader)
  907. {
  908. AssertStartDocument (xmlReader);
  909. AssertNode (
  910. xmlReader, // xmlReader
  911. XmlNodeType.Element, // nodeType
  912. 0, // depth
  913. true, // isEmptyElement
  914. "foo", // name
  915. String.Empty, // prefix
  916. "foo", // localName
  917. String.Empty, // namespaceURI
  918. String.Empty, // value
  919. 2 // attributeCount
  920. );
  921. AssertAttribute (
  922. xmlReader, // xmlReader
  923. "bar:baz", // name
  924. "bar", // prefix
  925. "baz", // localName
  926. "http://bar/", // namespaceURI
  927. "quux" // value
  928. );
  929. AssertAttribute (
  930. xmlReader, // xmlReader
  931. "xmlns:bar", // name
  932. "xmlns", // prefix
  933. "bar", // localName
  934. "http://www.w3.org/2000/xmlns/", // namespaceURI
  935. "http://bar/" // value
  936. );
  937. AssertEquals ("http://bar/", xmlReader.LookupNamespace ("bar"));
  938. AssertEndDocument (xmlReader);
  939. }
  940. [Test]
  941. public void MoveToElementFromAttribute ()
  942. {
  943. string xml = @"<foo bar=""baz"" />";
  944. RunTest (xml, new TestMethod (MoveToElementFromAttribute));
  945. }
  946. public void MoveToElementFromAttribute (XmlReader xmlReader)
  947. {
  948. Assert (xmlReader.Read ());
  949. AssertEquals (XmlNodeType.Element, xmlReader.NodeType);
  950. Assert (xmlReader.MoveToFirstAttribute ());
  951. AssertEquals (XmlNodeType.Attribute, xmlReader.NodeType);
  952. Assert (xmlReader.MoveToElement ());
  953. AssertEquals (XmlNodeType.Element, xmlReader.NodeType);
  954. }
  955. [Test]
  956. public void MoveToElementFromElement ()
  957. {
  958. string xml = @"<foo bar=""baz"" />";
  959. RunTest (xml, new TestMethod (MoveToElementFromElement));
  960. }
  961. public void MoveToElementFromElement (XmlReader xmlReader)
  962. {
  963. Assert (xmlReader.Read ());
  964. AssertEquals (XmlNodeType.Element, xmlReader.NodeType);
  965. Assert (!xmlReader.MoveToElement ());
  966. AssertEquals (XmlNodeType.Element, xmlReader.NodeType);
  967. }
  968. [Test]
  969. public void MoveToFirstAttributeWithNoAttributes ()
  970. {
  971. string xml = @"<foo />";
  972. RunTest (xml, new TestMethod (MoveToFirstAttributeWithNoAttributes));
  973. }
  974. public void MoveToFirstAttributeWithNoAttributes (XmlReader xmlReader)
  975. {
  976. Assert (xmlReader.Read ());
  977. AssertEquals (XmlNodeType.Element, xmlReader.NodeType);
  978. Assert (!xmlReader.MoveToFirstAttribute ());
  979. AssertEquals (XmlNodeType.Element, xmlReader.NodeType);
  980. }
  981. [Test]
  982. public void MoveToNextAttributeWithNoAttributes ()
  983. {
  984. string xml = @"<foo />";
  985. RunTest (xml, new TestMethod (MoveToNextAttributeWithNoAttributes));
  986. }
  987. public void MoveToNextAttributeWithNoAttributes (XmlReader xmlReader)
  988. {
  989. Assert (xmlReader.Read ());
  990. AssertEquals (XmlNodeType.Element, xmlReader.NodeType);
  991. Assert (!xmlReader.MoveToNextAttribute ());
  992. AssertEquals (XmlNodeType.Element, xmlReader.NodeType);
  993. }
  994. [Test]
  995. public void MoveToNextAttribute()
  996. {
  997. string xml = @"<foo bar=""baz"" quux='quuux'/>";
  998. RunTest (xml, new TestMethod (MoveToNextAttribute));
  999. }
  1000. public void MoveToNextAttribute (XmlReader xmlReader)
  1001. {
  1002. AssertStartDocument (xmlReader);
  1003. AssertNode (
  1004. xmlReader, // xmlReader
  1005. XmlNodeType.Element, // nodeType
  1006. 0, //depth
  1007. true, // isEmptyElement
  1008. "foo", // name
  1009. String.Empty, // prefix
  1010. "foo", // localName
  1011. String.Empty, // namespaceURI
  1012. String.Empty, // value
  1013. 2 // attributeCount
  1014. );
  1015. AssertAttribute (
  1016. xmlReader, // xmlReader
  1017. "bar", // name
  1018. String.Empty, // prefix
  1019. "bar", // localName
  1020. String.Empty, // namespaceURI
  1021. "baz" // value
  1022. );
  1023. AssertAttribute (
  1024. xmlReader, // xmlReader
  1025. "quux", // name
  1026. String.Empty, // prefix
  1027. "quux", // localName
  1028. String.Empty, // namespaceURI
  1029. "quuux" // value
  1030. );
  1031. Assert (xmlReader.MoveToNextAttribute ());
  1032. AssertEquals ("bar", xmlReader.Name);
  1033. AssertEquals ("baz", xmlReader.Value);
  1034. Assert (xmlReader.MoveToNextAttribute ());
  1035. AssertEquals ("quux", xmlReader.Name);
  1036. AssertEquals ("quuux", xmlReader.Value);
  1037. Assert (!xmlReader.MoveToNextAttribute ());
  1038. Assert (xmlReader.MoveToElement ());
  1039. AssertNodeValues (
  1040. xmlReader, // xmlReader
  1041. XmlNodeType.Element, // nodeType
  1042. 0, //depth
  1043. true, // isEmptyElement
  1044. "foo", // name
  1045. String.Empty, // prefix
  1046. "foo", // localName
  1047. String.Empty, // namespaceURI
  1048. String.Empty, // value
  1049. 2 // attributeCount
  1050. );
  1051. AssertEndDocument (xmlReader);
  1052. }
  1053. [Test]
  1054. [Ignore ("XmlNodeReader never moves to xml declaration.")]
  1055. public void MoveToXmlDeclAttributes ()
  1056. {
  1057. string xml = "<?xml version=\"1.0\" standalone=\"yes\"?><root/>";
  1058. RunTest (xml, new TestMethod (MoveToXmlDeclAttributes));
  1059. }
  1060. public void MoveToXmlDeclAttributes (XmlReader xmlReader)
  1061. {
  1062. xmlReader.Read ();
  1063. this.AssertNodeValues (xmlReader,
  1064. XmlNodeType.XmlDeclaration,
  1065. 0,
  1066. false,
  1067. "xml",
  1068. String.Empty,
  1069. "xml",
  1070. String.Empty,
  1071. "version=\"1.0\" standalone=\"yes\"",
  1072. 2);
  1073. xmlReader.MoveToFirstAttribute ();
  1074. this.AssertNodeValues (xmlReader,
  1075. XmlNodeType.Attribute,
  1076. 1,
  1077. false,
  1078. "version",
  1079. String.Empty,
  1080. "version",
  1081. String.Empty,
  1082. "1.0",
  1083. 2);
  1084. xmlReader.ReadAttributeValue ();
  1085. this.AssertNodeValues (xmlReader,
  1086. XmlNodeType.Text,
  1087. 2,
  1088. false,
  1089. String.Empty,
  1090. String.Empty,
  1091. String.Empty,
  1092. String.Empty,
  1093. "1.0",
  1094. 2);
  1095. xmlReader.MoveToNextAttribute ();
  1096. this.AssertNodeValues (xmlReader,
  1097. XmlNodeType.Attribute,
  1098. 1,
  1099. false,
  1100. "standalone",
  1101. String.Empty,
  1102. "standalone",
  1103. String.Empty,
  1104. "yes",
  1105. 2);
  1106. xmlReader.ReadAttributeValue ();
  1107. this.AssertNodeValues (xmlReader,
  1108. XmlNodeType.Text,
  1109. 2,
  1110. false,
  1111. String.Empty,
  1112. String.Empty,
  1113. String.Empty,
  1114. String.Empty,
  1115. "yes",
  1116. 2);
  1117. }
  1118. [Test]
  1119. public void AttributeOrder ()
  1120. {
  1121. string xml = @"<foo _1='1' _2='2' _3='3' />";
  1122. RunTest (xml, new TestMethod (AttributeOrder));
  1123. }
  1124. public void AttributeOrder (XmlReader xmlReader)
  1125. {
  1126. Assert (xmlReader.Read ());
  1127. AssertEquals (XmlNodeType.Element, xmlReader.NodeType);
  1128. Assert (xmlReader.MoveToFirstAttribute ());
  1129. AssertEquals ("_1", xmlReader.Name);
  1130. Assert (xmlReader.MoveToNextAttribute ());
  1131. AssertEquals ("_2", xmlReader.Name);
  1132. Assert (xmlReader.MoveToNextAttribute ());
  1133. AssertEquals ("_3", xmlReader.Name);
  1134. Assert (!xmlReader.MoveToNextAttribute ());
  1135. }
  1136. [Test]
  1137. public void IndexerAndAttributes ()
  1138. {
  1139. string xml = @"<?xml version='1.0' standalone='no'?><foo _1='1' _2='2' _3='3' />";
  1140. RunTest (xml, new TestMethod (IndexerAndAttributes));
  1141. }
  1142. public void IndexerAndAttributes (XmlReader xmlReader)
  1143. {
  1144. Assert (xmlReader.Read ());
  1145. AssertEquals ("1.0", xmlReader ["version"]);
  1146. AssertEquals ("1.0", xmlReader.GetAttribute ("version"));
  1147. // .NET 1.1 BUG. XmlTextReader returns null, while XmlNodeReader returns "".
  1148. AssertEquals (null, xmlReader ["encoding"]);
  1149. AssertEquals (null, xmlReader.GetAttribute ("encoding"));
  1150. AssertEquals ("no", xmlReader ["standalone"]);
  1151. AssertEquals ("no", xmlReader.GetAttribute ("standalone"));
  1152. AssertEquals ("1.0", xmlReader [0]);
  1153. AssertEquals ("1.0", xmlReader.GetAttribute (0));
  1154. AssertEquals ("no", xmlReader [1]);
  1155. AssertEquals ("no", xmlReader.GetAttribute (1));
  1156. Assert (xmlReader.Read ());
  1157. AssertEquals (XmlNodeType.Element, xmlReader.NodeType);
  1158. AssertEquals ("1", xmlReader ["_1"]);
  1159. Assert (xmlReader.MoveToFirstAttribute ());
  1160. AssertEquals ("_1", xmlReader.Name);
  1161. AssertEquals ("1", xmlReader ["_1"]);
  1162. Assert (xmlReader.MoveToNextAttribute ());
  1163. AssertEquals ("_2", xmlReader.Name);
  1164. AssertEquals ("1", xmlReader ["_1"]);
  1165. Assert (xmlReader.MoveToNextAttribute ());
  1166. AssertEquals ("_3", xmlReader.Name);
  1167. AssertEquals ("1", xmlReader ["_1"]);
  1168. Assert (!xmlReader.MoveToNextAttribute ());
  1169. }
  1170. [Test]
  1171. public void ProhibitedMultipleAttributes ()
  1172. {
  1173. string xml = @"<foo _1='1' _1='1' />";
  1174. try {
  1175. RunTest (xml, new TestMethod (ReadAll));
  1176. } catch (XmlException) {
  1177. }
  1178. xml = @"<foo _1='1' _1='2' />";
  1179. try {
  1180. RunTest (xml, new TestMethod (ReadAll));
  1181. } catch (XmlException) {
  1182. }
  1183. }
  1184. public void ReadAll (XmlReader xmlReader)
  1185. {
  1186. while (!xmlReader.EOF)
  1187. xmlReader.Read ();
  1188. }
  1189. [Test]
  1190. public void SurrogatePairContent ()
  1191. {
  1192. string xml = "<root xmlns='&#x10100;'/>";
  1193. RunTest (xml, new TestMethod (SurrogatePairContent));
  1194. }
  1195. public void SurrogatePairContent (XmlReader xmlReader)
  1196. {
  1197. xmlReader.Read ();
  1198. AssertEquals (true, xmlReader.MoveToAttribute ("xmlns"));
  1199. AssertEquals ("xmlns", xmlReader.Name);
  1200. AssertEquals (2, xmlReader.Value.Length);
  1201. AssertEquals (0xD800, (int) xmlReader.Value [0]);
  1202. AssertEquals (0xDD00, (int) xmlReader.Value [1]);
  1203. }
  1204. [Test]
  1205. public void ReadOuterXmlOnEndElement ()
  1206. {
  1207. string xml = "<root><foo></foo></root>";
  1208. RunTest (xml, new TestMethod (ReadOuterXmlOnEndElement));
  1209. }
  1210. public void ReadOuterXmlOnEndElement (XmlReader xmlReader)
  1211. {
  1212. xmlReader.Read ();
  1213. xmlReader.Read ();
  1214. xmlReader.Read ();
  1215. AssertEquals (String.Empty, xmlReader.ReadOuterXml ());
  1216. }
  1217. [Test]
  1218. public void ReadInnerXmlOnEndElement ()
  1219. {
  1220. string xml = "<root><foo></foo></root>";
  1221. RunTest (xml, new TestMethod (ReadInnerXmlOnEndElement));
  1222. }
  1223. private void ReadInnerXmlOnEndElement (XmlReader xmlReader)
  1224. {
  1225. xmlReader.Read ();
  1226. xmlReader.Read ();
  1227. xmlReader.Read ();
  1228. AssertEquals (String.Empty, xmlReader.ReadInnerXml ());
  1229. }
  1230. }
  1231. }