XmlReaderCommonTests.cs 36 KB

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