XmlReaderCommonTests.cs 37 KB

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