XmlTextReaderTests.cs 43 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766
  1. //
  2. // XmlTextReaderTests.cs
  3. //
  4. // Author:
  5. // Jason Diamond ([email protected])
  6. //
  7. // (C) 2001, 2002 Jason Diamond http://injektilo.org/
  8. //
  9. using System;
  10. using System.IO;
  11. using System.Xml;
  12. using NUnit.Framework;
  13. namespace Ximian.Mono.Tests
  14. {
  15. public class XmlTextReaderTests : TestCase
  16. {
  17. public XmlTextReaderTests () : base ("Ximian.Mono.Tests.XmlTextReaderTests testsuite") { }
  18. public XmlTextReaderTests (string name) : base (name) { }
  19. private void AssertStartDocument (XmlReader xmlReader)
  20. {
  21. Assert (xmlReader.ReadState == ReadState.Initial);
  22. Assert (xmlReader.NodeType == XmlNodeType.None);
  23. Assert (xmlReader.Depth == 0);
  24. Assert (!xmlReader.EOF);
  25. }
  26. private void AssertNode (
  27. XmlReader xmlReader,
  28. XmlNodeType nodeType,
  29. int depth,
  30. bool isEmptyElement,
  31. string name,
  32. string prefix,
  33. string localName,
  34. string namespaceURI,
  35. string value,
  36. int attributeCount)
  37. {
  38. Assert (xmlReader.Read ());
  39. Assert (xmlReader.ReadState == ReadState.Interactive);
  40. Assert (!xmlReader.EOF);
  41. }
  42. private void AssertNodeValues (
  43. XmlReader xmlReader,
  44. XmlNodeType nodeType,
  45. int depth,
  46. bool isEmptyElement,
  47. string name,
  48. string prefix,
  49. string localName,
  50. string namespaceURI,
  51. string value,
  52. int attributeCount)
  53. {
  54. Assert (xmlReader.NodeType == nodeType);
  55. Assert (xmlReader.Depth == depth);
  56. Assert (xmlReader.IsEmptyElement == isEmptyElement);
  57. Assert (
  58. String.Format (
  59. "name was {0}, expected {1}",
  60. xmlReader.Name,
  61. name),
  62. xmlReader.Name == name);
  63. Assert (
  64. String.Format (
  65. "prefix was {0}, expected {1}",
  66. xmlReader.Prefix,
  67. prefix),
  68. xmlReader.Prefix == prefix);
  69. Assert (
  70. String.Format (
  71. "localName was {0}, expected {1}",
  72. xmlReader.LocalName,
  73. localName),
  74. xmlReader.LocalName == localName);
  75. Assert (
  76. String.Format (
  77. "namespaceURI was {0}, expected {1}",
  78. xmlReader.NamespaceURI,
  79. namespaceURI),
  80. xmlReader.NamespaceURI == namespaceURI);
  81. Assert (
  82. String.Format (
  83. "hasValue was {0}, expected {1}",
  84. xmlReader.HasValue,
  85. (value != String.Empty)),
  86. xmlReader.HasValue == (value != String.Empty));
  87. Assert (
  88. String.Format (
  89. "value was {0}, expected {1}",
  90. xmlReader.Value,
  91. value),
  92. xmlReader.Value == value);
  93. Assert (
  94. String.Format (
  95. "hasAttributes was {0}, expected {1}",
  96. xmlReader.HasAttributes,
  97. (attributeCount > 0)),
  98. xmlReader.HasAttributes == (attributeCount > 0));
  99. Assert (
  100. String.Format (
  101. "attributeCount was {0}, expected {1}",
  102. xmlReader.AttributeCount,
  103. attributeCount),
  104. xmlReader.AttributeCount == attributeCount);
  105. }
  106. private void AssertAttribute (
  107. XmlReader xmlReader,
  108. string name,
  109. string prefix,
  110. string localName,
  111. string namespaceURI,
  112. string value)
  113. {
  114. Assert (
  115. String.Format (
  116. "value was {0}, expected {1}",
  117. xmlReader[name],
  118. value),
  119. xmlReader[name] == value);
  120. Assert (xmlReader.GetAttribute (name) == value);
  121. if (namespaceURI != String.Empty) {
  122. Assert (xmlReader[localName, namespaceURI] == value);
  123. Assert (xmlReader.GetAttribute (localName, namespaceURI) == value);
  124. }
  125. }
  126. private void AssertEndDocument (XmlReader xmlReader)
  127. {
  128. Assert (!xmlReader.Read ());
  129. Assert (xmlReader.NodeType == XmlNodeType.None);
  130. Assert (xmlReader.Depth == 0);
  131. Assert (xmlReader.ReadState == ReadState.EndOfFile);
  132. Assert (xmlReader.EOF);
  133. xmlReader.Close ();
  134. Assert (xmlReader.ReadState == ReadState.Closed);
  135. }
  136. public void TestEmptyElement ()
  137. {
  138. string xml = "<foo/>";
  139. XmlReader xmlReader =
  140. new XmlTextReader (new StringReader (xml));
  141. AssertStartDocument (xmlReader);
  142. AssertNode (
  143. xmlReader, // xmlReader
  144. XmlNodeType.Element, // nodeType
  145. 0, // depth
  146. true, // isEmptyElement
  147. "foo", // name
  148. String.Empty, // prefix
  149. "foo", // localName
  150. String.Empty, // namespaceURI
  151. String.Empty, // value
  152. 0 // attributeCount
  153. );
  154. AssertEndDocument (xmlReader);
  155. }
  156. public void TestEmptyElementWithBadName ()
  157. {
  158. string xml = "<1foo/>";
  159. XmlReader xmlReader =
  160. new XmlTextReader (new StringReader (xml));
  161. bool caughtXmlException = false;
  162. try {
  163. xmlReader.Read();
  164. } catch (XmlException) {
  165. caughtXmlException = true;
  166. }
  167. Assert(caughtXmlException);
  168. }
  169. public void TestEmptyElementWithWhitespace ()
  170. {
  171. string xml = "<foo />";
  172. XmlReader xmlReader =
  173. new XmlTextReader (new StringReader (xml));
  174. AssertStartDocument (xmlReader);
  175. AssertNode (
  176. xmlReader, // xmlReader
  177. XmlNodeType.Element, // nodeType
  178. 0, //depth
  179. true, // isEmptyElement
  180. "foo", // name
  181. String.Empty, // prefix
  182. "foo", // localName
  183. String.Empty, // namespaceURI
  184. String.Empty, // value
  185. 0 // attributeCount
  186. );
  187. AssertEndDocument (xmlReader);
  188. }
  189. public void TestEmptyElementWithStartAndEndTag ()
  190. {
  191. string xml = "<foo></foo>";
  192. XmlReader xmlReader =
  193. new XmlTextReader (new StringReader (xml));
  194. AssertStartDocument (xmlReader);
  195. AssertNode (
  196. xmlReader, // xmlReader
  197. XmlNodeType.Element, // nodeType
  198. 0, //depth
  199. false, // isEmptyElement
  200. "foo", // name
  201. String.Empty, // prefix
  202. "foo", // localName
  203. String.Empty, // namespaceURI
  204. String.Empty, // value
  205. 0 // attributeCount
  206. );
  207. AssertNode (
  208. xmlReader, // xmlReader
  209. XmlNodeType.EndElement, // nodeType
  210. 0, //depth
  211. false, // isEmptyElement
  212. "foo", // name
  213. String.Empty, // prefix
  214. "foo", // localName
  215. String.Empty, // namespaceURI
  216. String.Empty, // value
  217. 0 // attributeCount
  218. );
  219. AssertEndDocument (xmlReader);
  220. }
  221. public void TestEmptyElementWithStartAndEndTagWithWhitespace ()
  222. {
  223. string xml = "<foo ></foo >";
  224. XmlReader xmlReader =
  225. new XmlTextReader (new StringReader (xml));
  226. AssertStartDocument (xmlReader);
  227. AssertNode (
  228. xmlReader, // xmlReader
  229. XmlNodeType.Element, // nodeType
  230. 0, //depth
  231. false, // isEmptyElement
  232. "foo", // name
  233. String.Empty, // prefix
  234. "foo", // localName
  235. String.Empty, // namespaceURI
  236. String.Empty, // value
  237. 0 // attributeCount
  238. );
  239. AssertNode (
  240. xmlReader, // xmlReader
  241. XmlNodeType.EndElement, // nodeType
  242. 0, //depth
  243. false, // isEmptyElement
  244. "foo", // name
  245. String.Empty, // prefix
  246. "foo", // localName
  247. String.Empty, // namespaceURI
  248. String.Empty, // value
  249. 0 // attributeCount
  250. );
  251. AssertEndDocument (xmlReader);
  252. }
  253. public void TestNestedEmptyTag ()
  254. {
  255. string xml = "<foo><bar/></foo>";
  256. XmlReader xmlReader =
  257. new XmlTextReader (new StringReader (xml));
  258. AssertStartDocument (xmlReader);
  259. AssertNode (
  260. xmlReader, // xmlReader
  261. XmlNodeType.Element, // nodeType
  262. 0, //depth
  263. false, // isEmptyElement
  264. "foo", // name
  265. String.Empty, // prefix
  266. "foo", // localName
  267. String.Empty, // namespaceURI
  268. String.Empty, // value
  269. 0 // attributeCount
  270. );
  271. AssertNode (
  272. xmlReader, // xmlReader
  273. XmlNodeType.Element, // nodeType
  274. 1, //depth
  275. true, // isEmptyElement
  276. "bar", // name
  277. String.Empty, // prefix
  278. "bar", // localName
  279. String.Empty, // namespaceURI
  280. String.Empty, // value
  281. 0 // attributeCount
  282. );
  283. AssertNode (
  284. xmlReader, // xmlReader
  285. XmlNodeType.EndElement, // nodeType
  286. 0, //depth
  287. false, // isEmptyElement
  288. "foo", // name
  289. String.Empty, // prefix
  290. "foo", // localName
  291. String.Empty, // namespaceURI
  292. String.Empty, // value
  293. 0 // attributeCount
  294. );
  295. AssertEndDocument (xmlReader);
  296. }
  297. public void TestNestedText ()
  298. {
  299. string xml = "<foo>bar</foo>";
  300. XmlReader xmlReader =
  301. new XmlTextReader (new StringReader (xml));
  302. AssertStartDocument (xmlReader);
  303. AssertNode (
  304. xmlReader, // xmlReader
  305. XmlNodeType.Element, // nodeType
  306. 0, //depth
  307. false, // isEmptyElement
  308. "foo", // name
  309. String.Empty, // prefix
  310. "foo", // localName
  311. String.Empty, // namespaceURI
  312. String.Empty, // value
  313. 0 // attributeCount
  314. );
  315. AssertNode (
  316. xmlReader, // xmlReader
  317. XmlNodeType.Text, // nodeType
  318. 1, //depth
  319. false, // isEmptyElement
  320. String.Empty, // name
  321. String.Empty, // prefix
  322. String.Empty, // localName
  323. String.Empty, // namespaceURI
  324. "bar", // value
  325. 0 // attributeCount
  326. );
  327. AssertNode (
  328. xmlReader, // xmlReader
  329. XmlNodeType.EndElement, // nodeType
  330. 0, //depth
  331. false, // isEmptyElement
  332. "foo", // name
  333. String.Empty, // prefix
  334. "foo", // localName
  335. String.Empty, // namespaceURI
  336. String.Empty, // value
  337. 0 // attributeCount
  338. );
  339. AssertEndDocument (xmlReader);
  340. }
  341. public void TestEmptyElementWithAttribute ()
  342. {
  343. string xml = @"<foo bar=""baz""/>";
  344. XmlReader xmlReader =
  345. new XmlTextReader (new StringReader (xml));
  346. AssertStartDocument (xmlReader);
  347. AssertNode (
  348. xmlReader, // xmlReader
  349. XmlNodeType.Element, // nodeType
  350. 0, //depth
  351. true, // isEmptyElement
  352. "foo", // name
  353. String.Empty, // prefix
  354. "foo", // localName
  355. String.Empty, // namespaceURI
  356. String.Empty, // value
  357. 1 // attributeCount
  358. );
  359. AssertAttribute (
  360. xmlReader, // xmlReader
  361. "bar", // name
  362. String.Empty, // prefix
  363. "bar", // localName
  364. String.Empty, // namespaceURI
  365. "baz" // value
  366. );
  367. AssertEndDocument (xmlReader);
  368. }
  369. public void TestStartAndEndTagWithAttribute ()
  370. {
  371. string xml = @"<foo bar='baz'></foo>";
  372. XmlReader xmlReader =
  373. new XmlTextReader (new StringReader (xml));
  374. AssertStartDocument (xmlReader);
  375. AssertNode (
  376. xmlReader, // xmlReader
  377. XmlNodeType.Element, // nodeType
  378. 0, //depth
  379. false, // isEmptyElement
  380. "foo", // name
  381. String.Empty, // prefix
  382. "foo", // localName
  383. String.Empty, // namespaceURI
  384. String.Empty, // value
  385. 1 // attributeCount
  386. );
  387. AssertAttribute (
  388. xmlReader, // xmlReader
  389. "bar", // name
  390. String.Empty, // prefix
  391. "bar", // localName
  392. String.Empty, // namespaceURI
  393. "baz" // value
  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. public void TestEmptyElementWithTwoAttributes ()
  410. {
  411. string xml = @"<foo bar=""baz"" quux='quuux'/>";
  412. XmlReader xmlReader =
  413. new XmlTextReader (new StringReader (xml));
  414. AssertStartDocument (xmlReader);
  415. AssertNode (
  416. xmlReader, // xmlReader
  417. XmlNodeType.Element, // nodeType
  418. 0, //depth
  419. true, // isEmptyElement
  420. "foo", // name
  421. String.Empty, // prefix
  422. "foo", // localName
  423. String.Empty, // namespaceURI
  424. String.Empty, // value
  425. 2 // attributeCount
  426. );
  427. AssertAttribute (
  428. xmlReader, // xmlReader
  429. "bar", // name
  430. String.Empty, // prefix
  431. "bar", // localName
  432. String.Empty, // namespaceURI
  433. "baz" // value
  434. );
  435. AssertAttribute (
  436. xmlReader, // xmlReader
  437. "quux", // name
  438. String.Empty, // prefix
  439. "quux", // localName
  440. String.Empty, // namespaceURI
  441. "quuux" // value
  442. );
  443. AssertEndDocument (xmlReader);
  444. }
  445. public void TestProcessingInstructionBeforeDocumentElement ()
  446. {
  447. string xml = "<?foo bar?><baz/>";
  448. XmlReader xmlReader =
  449. new XmlTextReader (new StringReader (xml));
  450. AssertStartDocument (xmlReader);
  451. AssertNode (
  452. xmlReader, // xmlReader
  453. XmlNodeType.ProcessingInstruction, // nodeType
  454. 0, //depth
  455. false, // isEmptyElement
  456. "foo", // name
  457. String.Empty, // prefix
  458. "foo", // localName
  459. String.Empty, // namespaceURI
  460. "bar", // value
  461. 0 // attributeCount
  462. );
  463. AssertNode (
  464. xmlReader, // xmlReader
  465. XmlNodeType.Element, // nodeType
  466. 0, //depth
  467. true, // isEmptyElement
  468. "baz", // name
  469. String.Empty, // prefix
  470. "baz", // localName
  471. String.Empty, // namespaceURI
  472. String.Empty, // value
  473. 0 // attributeCount
  474. );
  475. AssertEndDocument (xmlReader);
  476. }
  477. public void TestCommentBeforeDocumentElement ()
  478. {
  479. string xml = "<!--foo--><bar/>";
  480. XmlReader xmlReader =
  481. new XmlTextReader (new StringReader (xml));
  482. AssertStartDocument (xmlReader);
  483. AssertNode (
  484. xmlReader, // xmlReader
  485. XmlNodeType.Comment, // nodeType
  486. 0, //depth
  487. false, // isEmptyElement
  488. String.Empty, // name
  489. String.Empty, // prefix
  490. String.Empty, // localName
  491. String.Empty, // namespaceURI
  492. "foo", // value
  493. 0 // attributeCount
  494. );
  495. AssertNode (
  496. xmlReader, // xmlReader
  497. XmlNodeType.Element, // nodeType
  498. 0, //depth
  499. true, // isEmptyElement
  500. "bar", // name
  501. String.Empty, // prefix
  502. "bar", // localName
  503. String.Empty, // namespaceURI
  504. String.Empty, // value
  505. 0 // attributeCount
  506. );
  507. AssertEndDocument (xmlReader);
  508. }
  509. public void TestPredefinedEntities ()
  510. {
  511. string xml = "<foo>&lt;&gt;&amp;&apos;&quot;</foo>";
  512. XmlReader xmlReader =
  513. new XmlTextReader (new StringReader (xml));
  514. AssertStartDocument (xmlReader);
  515. AssertNode (
  516. xmlReader, // xmlReader
  517. XmlNodeType.Element, // nodeType
  518. 0, //depth
  519. false, // isEmptyElement
  520. "foo", // name
  521. String.Empty, // prefix
  522. "foo", // localName
  523. String.Empty, // namespaceURI
  524. String.Empty, // value
  525. 0 // attributeCount
  526. );
  527. AssertNode (
  528. xmlReader, // xmlReader
  529. XmlNodeType.Text, // nodeType
  530. 1, //depth
  531. false, // isEmptyElement
  532. String.Empty, // name
  533. String.Empty, // prefix
  534. String.Empty, // localName
  535. String.Empty, // namespaceURI
  536. "<>&'\"", // value
  537. 0 // attributeCount
  538. );
  539. AssertNode (
  540. xmlReader, // xmlReader
  541. XmlNodeType.EndElement, // 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. AssertEndDocument (xmlReader);
  552. }
  553. public void TestEntityReference ()
  554. {
  555. string xml = "<foo>&bar;</foo>";
  556. XmlReader xmlReader =
  557. new XmlTextReader (new StringReader (xml));
  558. AssertStartDocument (xmlReader);
  559. AssertNode (
  560. xmlReader, // xmlReader
  561. XmlNodeType.Element, // nodeType
  562. 0, //depth
  563. false, // isEmptyElement
  564. "foo", // name
  565. String.Empty, // prefix
  566. "foo", // localName
  567. String.Empty, // namespaceURI
  568. String.Empty, // value
  569. 0 // attributeCount
  570. );
  571. AssertNode (
  572. xmlReader, // xmlReader
  573. XmlNodeType.EntityReference, // nodeType
  574. 1, //depth
  575. false, // isEmptyElement
  576. "bar", // name
  577. String.Empty, // prefix
  578. "bar", // localName
  579. String.Empty, // namespaceURI
  580. String.Empty, // value
  581. 0 // attributeCount
  582. );
  583. AssertNode (
  584. xmlReader, // xmlReader
  585. XmlNodeType.EndElement, // nodeType
  586. 0, //depth
  587. false, // isEmptyElement
  588. "foo", // name
  589. String.Empty, // prefix
  590. "foo", // localName
  591. String.Empty, // namespaceURI
  592. String.Empty, // value
  593. 0 // attributeCount
  594. );
  595. AssertEndDocument (xmlReader);
  596. }
  597. public void TestEntityReferenceInsideText ()
  598. {
  599. string xml = "<foo>bar&baz;quux</foo>";
  600. XmlReader xmlReader =
  601. new XmlTextReader (new StringReader (xml));
  602. AssertStartDocument (xmlReader);
  603. AssertNode (
  604. xmlReader, // xmlReader
  605. XmlNodeType.Element, // nodeType
  606. 0, //depth
  607. false, // isEmptyElement
  608. "foo", // name
  609. String.Empty, // prefix
  610. "foo", // localName
  611. String.Empty, // namespaceURI
  612. String.Empty, // value
  613. 0 // attributeCount
  614. );
  615. AssertNode (
  616. xmlReader, // xmlReader
  617. XmlNodeType.Text, // nodeType
  618. 1, //depth
  619. false, // isEmptyElement
  620. String.Empty, // name
  621. String.Empty, // prefix
  622. String.Empty, // localName
  623. String.Empty, // namespaceURI
  624. "bar", // value
  625. 0 // attributeCount
  626. );
  627. AssertNode (
  628. xmlReader, // xmlReader
  629. XmlNodeType.EntityReference, // nodeType
  630. 1, //depth
  631. false, // isEmptyElement
  632. "baz", // name
  633. String.Empty, // prefix
  634. "baz", // localName
  635. String.Empty, // namespaceURI
  636. String.Empty, // value
  637. 0 // attributeCount
  638. );
  639. AssertNode (
  640. xmlReader, // xmlReader
  641. XmlNodeType.Text, // nodeType
  642. 1, //depth
  643. false, // isEmptyElement
  644. String.Empty, // name
  645. String.Empty, // prefix
  646. String.Empty, // localName
  647. String.Empty, // namespaceURI
  648. "quux", // value
  649. 0 // attributeCount
  650. );
  651. AssertNode (
  652. xmlReader, // xmlReader
  653. XmlNodeType.EndElement, // nodeType
  654. 0, //depth
  655. false, // isEmptyElement
  656. "foo", // name
  657. String.Empty, // prefix
  658. "foo", // localName
  659. String.Empty, // namespaceURI
  660. String.Empty, // value
  661. 0 // attributeCount
  662. );
  663. AssertEndDocument (xmlReader);
  664. }
  665. public void TestCharacterReferences ()
  666. {
  667. string xml = "<foo>&#70;&#x4F;&#x4f;</foo>";
  668. XmlReader xmlReader =
  669. new XmlTextReader (new StringReader (xml));
  670. AssertStartDocument (xmlReader);
  671. AssertNode (
  672. xmlReader, // xmlReader
  673. XmlNodeType.Element, // nodeType
  674. 0, //depth
  675. false, // isEmptyElement
  676. "foo", // name
  677. String.Empty, // prefix
  678. "foo", // localName
  679. String.Empty, // namespaceURI
  680. String.Empty, // value
  681. 0 // attributeCount
  682. );
  683. AssertNode (
  684. xmlReader, // xmlReader
  685. XmlNodeType.Text, // nodeType
  686. 1, //depth
  687. false, // isEmptyElement
  688. String.Empty, // name
  689. String.Empty, // prefix
  690. String.Empty, // localName
  691. String.Empty, // namespaceURI
  692. "FOO", // value
  693. 0 // attributeCount
  694. );
  695. AssertNode (
  696. xmlReader, // xmlReader
  697. XmlNodeType.EndElement, // 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. AssertEndDocument (xmlReader);
  708. }
  709. public void TestEntityReferenceInAttribute ()
  710. {
  711. string xml = "<foo bar='&baz;'/>";
  712. XmlReader xmlReader =
  713. new XmlTextReader (new StringReader (xml));
  714. AssertStartDocument (xmlReader);
  715. AssertNode (
  716. xmlReader, // xmlReader
  717. XmlNodeType.Element, // nodeType
  718. 0, //depth
  719. true, // isEmptyElement
  720. "foo", // name
  721. String.Empty, // prefix
  722. "foo", // localName
  723. String.Empty, // namespaceURI
  724. String.Empty, // value
  725. 1 // attributeCount
  726. );
  727. AssertAttribute (
  728. xmlReader, // xmlReader
  729. "bar", // name
  730. String.Empty, // prefix
  731. "bar", // localName
  732. String.Empty, // namespaceURI
  733. "&baz;" // value
  734. );
  735. AssertEndDocument (xmlReader);
  736. }
  737. public void TestPredefinedEntitiesInAttribute ()
  738. {
  739. string xml = "<foo bar='&lt;&gt;&amp;&apos;&quot;'/>";
  740. XmlReader xmlReader =
  741. new XmlTextReader (new StringReader (xml));
  742. AssertStartDocument (xmlReader);
  743. AssertNode (
  744. xmlReader, // xmlReader
  745. XmlNodeType.Element, // nodeType
  746. 0, //depth
  747. true, // isEmptyElement
  748. "foo", // name
  749. String.Empty, // prefix
  750. "foo", // localName
  751. String.Empty, // namespaceURI
  752. String.Empty, // value
  753. 1 // attributeCount
  754. );
  755. AssertAttribute (
  756. xmlReader, // xmlReader
  757. "bar", // name
  758. String.Empty, // prefix
  759. "bar", // localName
  760. String.Empty, // namespaceURI
  761. "<>&'\"" // value
  762. );
  763. AssertEndDocument (xmlReader);
  764. }
  765. public void TestCharacterReferencesInAttribute ()
  766. {
  767. string xml = "<foo bar='&#70;&#x4F;&#x4f;'/>";
  768. XmlReader xmlReader =
  769. new XmlTextReader (new StringReader (xml));
  770. AssertStartDocument (xmlReader);
  771. AssertNode (
  772. xmlReader, // xmlReader
  773. XmlNodeType.Element, // nodeType
  774. 0, //depth
  775. true, // isEmptyElement
  776. "foo", // name
  777. String.Empty, // prefix
  778. "foo", // localName
  779. String.Empty, // namespaceURI
  780. String.Empty, // value
  781. 1 // attributeCount
  782. );
  783. AssertAttribute (
  784. xmlReader, // xmlReader
  785. "bar", // name
  786. String.Empty, // prefix
  787. "bar", // localName
  788. String.Empty, // namespaceURI
  789. "FOO" // value
  790. );
  791. AssertEndDocument (xmlReader);
  792. }
  793. public void TestCDATA ()
  794. {
  795. string xml = "<foo><![CDATA[<>&]]></foo>";
  796. XmlReader xmlReader =
  797. new XmlTextReader (new StringReader (xml));
  798. AssertStartDocument (xmlReader);
  799. AssertNode (
  800. xmlReader, // xmlReader
  801. XmlNodeType.Element, // nodeType
  802. 0, //depth
  803. false, // isEmptyElement
  804. "foo", // name
  805. String.Empty, // prefix
  806. "foo", // localName
  807. String.Empty, // namespaceURI
  808. String.Empty, // value
  809. 0 // attributeCount
  810. );
  811. AssertNode (
  812. xmlReader, // xmlReader
  813. XmlNodeType.CDATA, // nodeType
  814. 1, //depth
  815. false, // isEmptyElement
  816. String.Empty, // name
  817. String.Empty, // prefix
  818. String.Empty, // localName
  819. String.Empty, // namespaceURI
  820. "<>&", // value
  821. 0 // attributeCount
  822. );
  823. AssertNode (
  824. xmlReader, // xmlReader
  825. XmlNodeType.EndElement, // nodeType
  826. 0, //depth
  827. false, // isEmptyElement
  828. "foo", // name
  829. String.Empty, // prefix
  830. "foo", // localName
  831. String.Empty, // namespaceURI
  832. String.Empty, // value
  833. 0 // attributeCount
  834. );
  835. AssertEndDocument (xmlReader);
  836. }
  837. public void TestEmptyElementInNamespace ()
  838. {
  839. string xml = @"<foo:bar xmlns:foo='http://foo/' />";
  840. XmlReader xmlReader =
  841. new XmlTextReader (new StringReader (xml));
  842. AssertStartDocument (xmlReader);
  843. AssertNode (
  844. xmlReader, // xmlReader
  845. XmlNodeType.Element, // nodeType
  846. 0, // depth
  847. true, // isEmptyElement
  848. "foo:bar", // name
  849. "foo", // prefix
  850. "bar", // localName
  851. "http://foo/", // namespaceURI
  852. String.Empty, // value
  853. 1 // attributeCount
  854. );
  855. AssertAttribute (
  856. xmlReader, // xmlReader
  857. "xmlns:foo", // name
  858. "xmlns", // prefix
  859. "foo", // localName
  860. "http://www.w3.org/2000/xmlns/", // namespaceURI
  861. "http://foo/" // value
  862. );
  863. AssertEquals ("http://foo/", xmlReader.LookupNamespace ("foo"));
  864. AssertEndDocument (xmlReader);
  865. }
  866. public void TestEmptyElementInDefaultNamespace ()
  867. {
  868. string xml = @"<foo xmlns='http://foo/' />";
  869. XmlReader xmlReader =
  870. new XmlTextReader (new StringReader (xml));
  871. AssertStartDocument (xmlReader);
  872. AssertNode (
  873. xmlReader, // xmlReader
  874. XmlNodeType.Element, // nodeType
  875. 0, // depth
  876. true, // isEmptyElement
  877. "foo", // name
  878. String.Empty, // prefix
  879. "foo", // localName
  880. "http://foo/", // namespaceURI
  881. String.Empty, // value
  882. 1 // attributeCount
  883. );
  884. AssertAttribute (
  885. xmlReader, // xmlReader
  886. "xmlns", // name
  887. String.Empty, // prefix
  888. "xmlns", // localName
  889. "http://www.w3.org/2000/xmlns/", // namespaceURI
  890. "http://foo/" // value
  891. );
  892. AssertEquals ("http://foo/", xmlReader.LookupNamespace (String.Empty));
  893. AssertEndDocument (xmlReader);
  894. }
  895. public void TestChildElementInNamespace ()
  896. {
  897. string xml = @"<foo:bar xmlns:foo='http://foo/'><baz:quux xmlns:baz='http://baz/' /></foo:bar>";
  898. XmlReader xmlReader =
  899. new XmlTextReader (new StringReader (xml));
  900. AssertStartDocument (xmlReader);
  901. AssertNode (
  902. xmlReader, // xmlReader
  903. XmlNodeType.Element, // nodeType
  904. 0, // depth
  905. false, // isEmptyElement
  906. "foo:bar", // name
  907. "foo", // prefix
  908. "bar", // localName
  909. "http://foo/", // namespaceURI
  910. String.Empty, // value
  911. 1 // attributeCount
  912. );
  913. AssertAttribute (
  914. xmlReader, // xmlReader
  915. "xmlns:foo", // name
  916. "xmlns", // prefix
  917. "foo", // localName
  918. "http://www.w3.org/2000/xmlns/", // namespaceURI
  919. "http://foo/" // value
  920. );
  921. AssertEquals ("http://foo/", xmlReader.LookupNamespace ("foo"));
  922. AssertNode (
  923. xmlReader, // xmlReader
  924. XmlNodeType.Element, // nodeType
  925. 1, // depth
  926. true, // isEmptyElement
  927. "baz:quux", // name
  928. "baz", // prefix
  929. "quux", // localName
  930. "http://baz/", // namespaceURI
  931. String.Empty, // value
  932. 1 // attributeCount
  933. );
  934. AssertAttribute (
  935. xmlReader, // xmlReader
  936. "xmlns:baz", // name
  937. "xmlns", // prefix
  938. "baz", // localName
  939. "http://www.w3.org/2000/xmlns/", // namespaceURI
  940. "http://baz/" // value
  941. );
  942. AssertEquals ("http://foo/", xmlReader.LookupNamespace ("foo"));
  943. AssertEquals ("http://baz/", xmlReader.LookupNamespace ("baz"));
  944. AssertNode (
  945. xmlReader, // xmlReader
  946. XmlNodeType.EndElement, // nodeType
  947. 0, // depth
  948. false, // isEmptyElement
  949. "foo:bar", // name
  950. "foo", // prefix
  951. "bar", // localName
  952. "http://foo/", // namespaceURI
  953. String.Empty, // value
  954. 0 // attributeCount
  955. );
  956. AssertEquals ("http://foo/", xmlReader.LookupNamespace ("foo"));
  957. AssertNull (xmlReader.LookupNamespace ("baz"));
  958. AssertEndDocument (xmlReader);
  959. }
  960. public void TestChildElementInDefaultNamespace ()
  961. {
  962. string xml = @"<foo:bar xmlns:foo='http://foo/'><baz xmlns='http://baz/' /></foo:bar>";
  963. XmlReader xmlReader =
  964. new XmlTextReader (new StringReader (xml));
  965. AssertStartDocument (xmlReader);
  966. AssertNode (
  967. xmlReader, // xmlReader
  968. XmlNodeType.Element, // nodeType
  969. 0, // depth
  970. false, // isEmptyElement
  971. "foo:bar", // name
  972. "foo", // prefix
  973. "bar", // localName
  974. "http://foo/", // namespaceURI
  975. String.Empty, // value
  976. 1 // attributeCount
  977. );
  978. AssertAttribute (
  979. xmlReader, // xmlReader
  980. "xmlns:foo", // name
  981. "xmlns", // prefix
  982. "foo", // localName
  983. "http://www.w3.org/2000/xmlns/", // namespaceURI
  984. "http://foo/" // value
  985. );
  986. AssertEquals ("http://foo/", xmlReader.LookupNamespace ("foo"));
  987. AssertNode (
  988. xmlReader, // xmlReader
  989. XmlNodeType.Element, // nodeType
  990. 1, // depth
  991. true, // isEmptyElement
  992. "baz", // name
  993. String.Empty, // prefix
  994. "baz", // localName
  995. "http://baz/", // namespaceURI
  996. String.Empty, // value
  997. 1 // attributeCount
  998. );
  999. AssertAttribute (
  1000. xmlReader, // xmlReader
  1001. "xmlns", // name
  1002. String.Empty, // prefix
  1003. "xmlns", // localName
  1004. "http://www.w3.org/2000/xmlns/", // namespaceURI
  1005. "http://baz/" // value
  1006. );
  1007. AssertEquals ("http://foo/", xmlReader.LookupNamespace ("foo"));
  1008. AssertEquals ("http://baz/", xmlReader.LookupNamespace (String.Empty));
  1009. AssertNode (
  1010. xmlReader, // xmlReader
  1011. XmlNodeType.EndElement, // nodeType
  1012. 0, // depth
  1013. false, // isEmptyElement
  1014. "foo:bar", // name
  1015. "foo", // prefix
  1016. "bar", // localName
  1017. "http://foo/", // namespaceURI
  1018. String.Empty, // value
  1019. 0 // attributeCount
  1020. );
  1021. AssertEquals ("http://foo/", xmlReader.LookupNamespace ("foo"));
  1022. AssertEndDocument (xmlReader);
  1023. }
  1024. public void TestAttributeInNamespace ()
  1025. {
  1026. string xml = @"<foo bar:baz='quux' xmlns:bar='http://bar/' />";
  1027. XmlReader xmlReader =
  1028. new XmlTextReader (new StringReader (xml));
  1029. AssertStartDocument (xmlReader);
  1030. AssertNode (
  1031. xmlReader, // xmlReader
  1032. XmlNodeType.Element, // nodeType
  1033. 0, // depth
  1034. true, // isEmptyElement
  1035. "foo", // name
  1036. String.Empty, // prefix
  1037. "foo", // localName
  1038. String.Empty, // namespaceURI
  1039. String.Empty, // value
  1040. 2 // attributeCount
  1041. );
  1042. AssertAttribute (
  1043. xmlReader, // xmlReader
  1044. "bar:baz", // name
  1045. "bar", // prefix
  1046. "baz", // localName
  1047. "http://bar/", // namespaceURI
  1048. "quux" // value
  1049. );
  1050. AssertAttribute (
  1051. xmlReader, // xmlReader
  1052. "xmlns:bar", // name
  1053. "xmlns", // prefix
  1054. "bar", // localName
  1055. "http://www.w3.org/2000/xmlns/", // namespaceURI
  1056. "http://bar/" // value
  1057. );
  1058. AssertEquals ("http://bar/", xmlReader.LookupNamespace ("bar"));
  1059. AssertEndDocument (xmlReader);
  1060. }
  1061. // The following is #if'ed out because it's specific to the Mono
  1062. // implementation and won't compile when testing Microsoft's code.
  1063. // Feel free to turn it on if you want to test Mono's name tables.
  1064. #if false
  1065. public void TestIsFirstNameChar ()
  1066. {
  1067. for (int ch = 0; ch <= 0xFFFF; ++ch) {
  1068. Assert (
  1069. XmlChar.IsFirstNameChar (ch) ==
  1070. IsFirstNameChar (ch));
  1071. }
  1072. }
  1073. public void TestIsNameChar ()
  1074. {
  1075. for (int ch = 0; ch <= 0xFFFF; ++ch) {
  1076. Assert (
  1077. XmlChar.IsNameChar (ch) ==
  1078. IsNameChar (ch));
  1079. }
  1080. }
  1081. private static bool IsFirstNameChar (int ch)
  1082. {
  1083. return
  1084. IsLetter (ch) ||
  1085. (ch == '_') ||
  1086. (ch == ':');
  1087. }
  1088. private static bool IsNameChar (int ch)
  1089. {
  1090. return
  1091. IsLetter (ch) ||
  1092. IsDigit (ch) ||
  1093. (ch == '.') ||
  1094. (ch == '-') ||
  1095. (ch == '_') ||
  1096. (ch == ':') ||
  1097. IsCombiningChar (ch) ||
  1098. IsExtender (ch);
  1099. }
  1100. private static bool IsLetter (int ch)
  1101. {
  1102. return
  1103. IsBaseChar (ch) ||
  1104. IsIdeographic (ch);
  1105. }
  1106. private static bool IsBaseChar (int ch)
  1107. {
  1108. return
  1109. (ch >= 0x0041 && ch <= 0x005A) ||
  1110. (ch >= 0x0061 && ch <= 0x007A) ||
  1111. (ch >= 0x00C0 && ch <= 0x00D6) ||
  1112. (ch >= 0x00D8 && ch <= 0x00F6) ||
  1113. (ch >= 0x00F8 && ch <= 0x00FF) ||
  1114. (ch >= 0x0100 && ch <= 0x0131) ||
  1115. (ch >= 0x0134 && ch <= 0x013E) ||
  1116. (ch >= 0x0141 && ch <= 0x0148) ||
  1117. (ch >= 0x014A && ch <= 0x017E) ||
  1118. (ch >= 0x0180 && ch <= 0x01C3) ||
  1119. (ch >= 0x01CD && ch <= 0x01F0) ||
  1120. (ch >= 0x01F4 && ch <= 0x01F5) ||
  1121. (ch >= 0x01FA && ch <= 0x0217) ||
  1122. (ch >= 0x0250 && ch <= 0x02A8) ||
  1123. (ch >= 0x02BB && ch <= 0x02C1) ||
  1124. (ch == 0x0386) ||
  1125. (ch >= 0x0388 && ch <= 0x038A) ||
  1126. (ch == 0x038C) ||
  1127. (ch >= 0x038E && ch <= 0x03A1) ||
  1128. (ch >= 0x03A3 && ch <= 0x03CE) ||
  1129. (ch >= 0x03D0 && ch <= 0x03D6) ||
  1130. (ch == 0x03DA) ||
  1131. (ch == 0x03DC) ||
  1132. (ch == 0x03DE) ||
  1133. (ch == 0x03E0) ||
  1134. (ch >= 0x03E2 && ch <= 0x03F3) ||
  1135. (ch >= 0x0401 && ch <= 0x040C) ||
  1136. (ch >= 0x040E && ch <= 0x044F) ||
  1137. (ch >= 0x0451 && ch <= 0x045C) ||
  1138. (ch >= 0x045E && ch <= 0x0481) ||
  1139. (ch >= 0x0490 && ch <= 0x04C4) ||
  1140. (ch >= 0x04C7 && ch <= 0x04C8) ||
  1141. (ch >= 0x04CB && ch <= 0x04CC) ||
  1142. (ch >= 0x04D0 && ch <= 0x04EB) ||
  1143. (ch >= 0x04EE && ch <= 0x04F5) ||
  1144. (ch >= 0x04F8 && ch <= 0x04F9) ||
  1145. (ch >= 0x0531 && ch <= 0x0556) ||
  1146. (ch == 0x0559) ||
  1147. (ch >= 0x0561 && ch <= 0x0586) ||
  1148. (ch >= 0x05D0 && ch <= 0x05EA) ||
  1149. (ch >= 0x05F0 && ch <= 0x05F2) ||
  1150. (ch >= 0x0621 && ch <= 0x063A) ||
  1151. (ch >= 0x0641 && ch <= 0x064A) ||
  1152. (ch >= 0x0671 && ch <= 0x06B7) ||
  1153. (ch >= 0x06BA && ch <= 0x06BE) ||
  1154. (ch >= 0x06C0 && ch <= 0x06CE) ||
  1155. (ch >= 0x06D0 && ch <= 0x06D3) ||
  1156. (ch == 0x06D5) ||
  1157. (ch >= 0x06E5 && ch <= 0x06E6) ||
  1158. (ch >= 0x0905 && ch <= 0x0939) ||
  1159. (ch == 0x093D) ||
  1160. (ch >= 0x0958 && ch <= 0x0961) ||
  1161. (ch >= 0x0985 && ch <= 0x098C) ||
  1162. (ch >= 0x098F && ch <= 0x0990) ||
  1163. (ch >= 0x0993 && ch <= 0x09A8) ||
  1164. (ch >= 0x09AA && ch <= 0x09B0) ||
  1165. (ch == 0x09B2) ||
  1166. (ch >= 0x09B6 && ch <= 0x09B9) ||
  1167. (ch >= 0x09DC && ch <= 0x09DD) ||
  1168. (ch >= 0x09DF && ch <= 0x09E1) ||
  1169. (ch >= 0x09F0 && ch <= 0x09F1) ||
  1170. (ch >= 0x0A05 && ch <= 0x0A0A) ||
  1171. (ch >= 0x0A0F && ch <= 0x0A10) ||
  1172. (ch >= 0x0A13 && ch <= 0x0A28) ||
  1173. (ch >= 0x0A2A && ch <= 0x0A30) ||
  1174. (ch >= 0x0A32 && ch <= 0x0A33) ||
  1175. (ch >= 0x0A35 && ch <= 0x0A36) ||
  1176. (ch >= 0x0A38 && ch <= 0x0A39) ||
  1177. (ch >= 0x0A59 && ch <= 0x0A5C) ||
  1178. (ch == 0x0A5E) ||
  1179. (ch >= 0x0A72 && ch <= 0x0A74) ||
  1180. (ch >= 0x0A85 && ch <= 0x0A8B) ||
  1181. (ch == 0x0A8D) ||
  1182. (ch >= 0x0A8F && ch <= 0x0A91) ||
  1183. (ch >= 0x0A93 && ch <= 0x0AA8) ||
  1184. (ch >= 0x0AAA && ch <= 0x0AB0) ||
  1185. (ch >= 0x0AB2 && ch <= 0x0AB3) ||
  1186. (ch >= 0x0AB5 && ch <= 0x0AB9) ||
  1187. (ch == 0x0ABD) ||
  1188. (ch == 0x0AE0) ||
  1189. (ch >= 0x0B05 && ch <= 0x0B0C) ||
  1190. (ch >= 0x0B0F && ch <= 0x0B10) ||
  1191. (ch >= 0x0B13 && ch <= 0x0B28) ||
  1192. (ch >= 0x0B2A && ch <= 0x0B30) ||
  1193. (ch >= 0x0B32 && ch <= 0x0B33) ||
  1194. (ch >= 0x0B36 && ch <= 0x0B39) ||
  1195. (ch == 0x0B3D) ||
  1196. (ch >= 0x0B5C && ch <= 0x0B5D) ||
  1197. (ch >= 0x0B5F && ch <= 0x0B61) ||
  1198. (ch >= 0x0B85 && ch <= 0x0B8A) ||
  1199. (ch >= 0x0B8E && ch <= 0x0B90) ||
  1200. (ch >= 0x0B92 && ch <= 0x0B95) ||
  1201. (ch >= 0x0B99 && ch <= 0x0B9A) ||
  1202. (ch == 0x0B9C) ||
  1203. (ch >= 0x0B9E && ch <= 0x0B9F) ||
  1204. (ch >= 0x0BA3 && ch <= 0x0BA4) ||
  1205. (ch >= 0x0BA8 && ch <= 0x0BAA) ||
  1206. (ch >= 0x0BAE && ch <= 0x0BB5) ||
  1207. (ch >= 0x0BB7 && ch <= 0x0BB9) ||
  1208. (ch >= 0x0C05 && ch <= 0x0C0C) ||
  1209. (ch >= 0x0C0E && ch <= 0x0C10) ||
  1210. (ch >= 0x0C12 && ch <= 0x0C28) ||
  1211. (ch >= 0x0C2A && ch <= 0x0C33) ||
  1212. (ch >= 0x0C35 && ch <= 0x0C39) ||
  1213. (ch >= 0x0C60 && ch <= 0x0C61) ||
  1214. (ch >= 0x0C85 && ch <= 0x0C8C) ||
  1215. (ch >= 0x0C8E && ch <= 0x0C90) ||
  1216. (ch >= 0x0C92 && ch <= 0x0CA8) ||
  1217. (ch >= 0x0CAA && ch <= 0x0CB3) ||
  1218. (ch >= 0x0CB5 && ch <= 0x0CB9) ||
  1219. (ch == 0x0CDE) ||
  1220. (ch >= 0x0CE0 && ch <= 0x0CE1) ||
  1221. (ch >= 0x0D05 && ch <= 0x0D0C) ||
  1222. (ch >= 0x0D0E && ch <= 0x0D10) ||
  1223. (ch >= 0x0D12 && ch <= 0x0D28) ||
  1224. (ch >= 0x0D2A && ch <= 0x0D39) ||
  1225. (ch >= 0x0D60 && ch <= 0x0D61) ||
  1226. (ch >= 0x0E01 && ch <= 0x0E2E) ||
  1227. (ch == 0x0E30) ||
  1228. (ch >= 0x0E32 && ch <= 0x0E33) ||
  1229. (ch >= 0x0E40 && ch <= 0x0E45) ||
  1230. (ch >= 0x0E81 && ch <= 0x0E82) ||
  1231. (ch == 0x0E84) ||
  1232. (ch >= 0x0E87 && ch <= 0x0E88) ||
  1233. (ch == 0x0E8A) ||
  1234. (ch == 0x0E8D) ||
  1235. (ch >= 0x0E94 && ch <= 0x0E97) ||
  1236. (ch >= 0x0E99 && ch <= 0x0E9F) ||
  1237. (ch >= 0x0EA1 && ch <= 0x0EA3) ||
  1238. (ch == 0x0EA5) ||
  1239. (ch == 0x0EA7) ||
  1240. (ch >= 0x0EAA && ch <= 0x0EAB) ||
  1241. (ch >= 0x0EAD && ch <= 0x0EAE) ||
  1242. (ch == 0x0EB0) ||
  1243. (ch >= 0x0EB2 && ch <= 0x0EB3) ||
  1244. (ch == 0x0EBD) ||
  1245. (ch >= 0x0EC0 && ch <= 0x0EC4) ||
  1246. (ch >= 0x0F40 && ch <= 0x0F47) ||
  1247. (ch >= 0x0F49 && ch <= 0x0F69) ||
  1248. (ch >= 0x10A0 && ch <= 0x10C5) ||
  1249. (ch >= 0x10D0 && ch <= 0x10F6) ||
  1250. (ch == 0x1100) ||
  1251. (ch >= 0x1102 && ch <= 0x1103) ||
  1252. (ch >= 0x1105 && ch <= 0x1107) ||
  1253. (ch == 0x1109) ||
  1254. (ch >= 0x110B && ch <= 0x110C) ||
  1255. (ch >= 0x110E && ch <= 0x1112) ||
  1256. (ch == 0x113C) ||
  1257. (ch == 0x113E) ||
  1258. (ch == 0x1140) ||
  1259. (ch == 0x114C) ||
  1260. (ch == 0x114E) ||
  1261. (ch == 0x1150) ||
  1262. (ch >= 0x1154 && ch <= 0x1155) ||
  1263. (ch == 0x1159) ||
  1264. (ch >= 0x115F && ch <= 0x1161) ||
  1265. (ch == 0x1163) ||
  1266. (ch == 0x1165) ||
  1267. (ch == 0x1167) ||
  1268. (ch == 0x1169) ||
  1269. (ch >= 0x116D && ch <= 0x116E) ||
  1270. (ch >= 0x1172 && ch <= 0x1173) ||
  1271. (ch == 0x1175) ||
  1272. (ch == 0x119E) ||
  1273. (ch == 0x11A8) ||
  1274. (ch == 0x11AB) ||
  1275. (ch >= 0x11AE && ch <= 0x11AF) ||
  1276. (ch >= 0x11B7 && ch <= 0x11B8) ||
  1277. (ch == 0x11BA) ||
  1278. (ch >= 0x11BC && ch <= 0x11C2) ||
  1279. (ch == 0x11EB) ||
  1280. (ch == 0x11F0) ||
  1281. (ch == 0x11F9) ||
  1282. (ch >= 0x1E00 && ch <= 0x1E9B) ||
  1283. (ch >= 0x1EA0 && ch <= 0x1EF9) ||
  1284. (ch >= 0x1F00 && ch <= 0x1F15) ||
  1285. (ch >= 0x1F18 && ch <= 0x1F1D) ||
  1286. (ch >= 0x1F20 && ch <= 0x1F45) ||
  1287. (ch >= 0x1F48 && ch <= 0x1F4D) ||
  1288. (ch >= 0x1F50 && ch <= 0x1F57) ||
  1289. (ch == 0x1F59) ||
  1290. (ch == 0x1F5B) ||
  1291. (ch == 0x1F5D) ||
  1292. (ch >= 0x1F5F && ch <= 0x1F7D) ||
  1293. (ch >= 0x1F80 && ch <= 0x1FB4) ||
  1294. (ch >= 0x1FB6 && ch <= 0x1FBC) ||
  1295. (ch == 0x1FBE) ||
  1296. (ch >= 0x1FC2 && ch <= 0x1FC4) ||
  1297. (ch >= 0x1FC6 && ch <= 0x1FCC) ||
  1298. (ch >= 0x1FD0 && ch <= 0x1FD3) ||
  1299. (ch >= 0x1FD6 && ch <= 0x1FDB) ||
  1300. (ch >= 0x1FE0 && ch <= 0x1FEC) ||
  1301. (ch >= 0x1FF2 && ch <= 0x1FF4) ||
  1302. (ch >= 0x1FF6 && ch <= 0x1FFC) ||
  1303. (ch == 0x2126) ||
  1304. (ch >= 0x212A && ch <= 0x212B) ||
  1305. (ch == 0x212E) ||
  1306. (ch >= 0x2180 && ch <= 0x2182) ||
  1307. (ch >= 0x3041 && ch <= 0x3094) ||
  1308. (ch >= 0x30A1 && ch <= 0x30FA) ||
  1309. (ch >= 0x3105 && ch <= 0x312C) ||
  1310. (ch >= 0xAC00 && ch <= 0xD7A3);
  1311. }
  1312. private static bool IsIdeographic (int ch)
  1313. {
  1314. return
  1315. (ch >= 0x4E00 && ch <= 0x9FA5) ||
  1316. (ch == 0x3007) ||
  1317. (ch >= 0x3021 && ch <= 0x3029);
  1318. }
  1319. private static bool IsDigit (int ch)
  1320. {
  1321. return
  1322. (ch >= 0x0030 && ch <= 0x0039) ||
  1323. (ch >= 0x0660 && ch <= 0x0669) ||
  1324. (ch >= 0x06F0 && ch <= 0x06F9) ||
  1325. (ch >= 0x0966 && ch <= 0x096F) ||
  1326. (ch >= 0x09E6 && ch <= 0x09EF) ||
  1327. (ch >= 0x0A66 && ch <= 0x0A6F) ||
  1328. (ch >= 0x0AE6 && ch <= 0x0AEF) ||
  1329. (ch >= 0x0B66 && ch <= 0x0B6F) ||
  1330. (ch >= 0x0BE7 && ch <= 0x0BEF) ||
  1331. (ch >= 0x0C66 && ch <= 0x0C6F) ||
  1332. (ch >= 0x0CE6 && ch <= 0x0CEF) ||
  1333. (ch >= 0x0D66 && ch <= 0x0D6F) ||
  1334. (ch >= 0x0E50 && ch <= 0x0E59) ||
  1335. (ch >= 0x0ED0 && ch <= 0x0ED9) ||
  1336. (ch >= 0x0F20 && ch <= 0x0F29);
  1337. }
  1338. private static bool IsCombiningChar (int ch)
  1339. {
  1340. return
  1341. (ch >= 0x0300 && ch <= 0x0345) ||
  1342. (ch >= 0x0360 && ch <= 0x0361) ||
  1343. (ch >= 0x0483 && ch <= 0x0486) ||
  1344. (ch >= 0x0591 && ch <= 0x05A1) ||
  1345. (ch >= 0x05A3 && ch <= 0x05B9) ||
  1346. (ch >= 0x05BB && ch <= 0x05BD) ||
  1347. (ch == 0x05BF) ||
  1348. (ch >= 0x05C1 && ch <= 0x05C2) ||
  1349. (ch == 0x05C4) ||
  1350. (ch >= 0x064B && ch <= 0x0652) ||
  1351. (ch == 0x0670) ||
  1352. (ch >= 0x06D6 && ch <= 0x06DC) ||
  1353. (ch >= 0x06DD && ch <= 0x06DF) ||
  1354. (ch >= 0x06E0 && ch <= 0x06E4) ||
  1355. (ch >= 0x06E7 && ch <= 0x06E8) ||
  1356. (ch >= 0x06EA && ch <= 0x06ED) ||
  1357. (ch >= 0x0901 && ch <= 0x0903) ||
  1358. (ch == 0x093C) ||
  1359. (ch >= 0x093E && ch <= 0x094C) ||
  1360. (ch == 0x094D) ||
  1361. (ch >= 0x0951 && ch <= 0x0954) ||
  1362. (ch >= 0x0962 && ch <= 0x0963) ||
  1363. (ch >= 0x0981 && ch <= 0x0983) ||
  1364. (ch == 0x09BC) ||
  1365. (ch == 0x09BE) ||
  1366. (ch == 0x09BF) ||
  1367. (ch >= 0x09C0 && ch <= 0x09C4) ||
  1368. (ch >= 0x09C7 && ch <= 0x09C8) ||
  1369. (ch >= 0x09CB && ch <= 0x09CD) ||
  1370. (ch == 0x09D7) ||
  1371. (ch >= 0x09E2 && ch <= 0x09E3) ||
  1372. (ch == 0x0A02) ||
  1373. (ch == 0x0A3C) ||
  1374. (ch == 0x0A3E) ||
  1375. (ch == 0x0A3F) ||
  1376. (ch >= 0x0A40 && ch <= 0x0A42) ||
  1377. (ch >= 0x0A47 && ch <= 0x0A48) ||
  1378. (ch >= 0x0A4B && ch <= 0x0A4D) ||
  1379. (ch >= 0x0A70 && ch <= 0x0A71) ||
  1380. (ch >= 0x0A81 && ch <= 0x0A83) ||
  1381. (ch == 0x0ABC) ||
  1382. (ch >= 0x0ABE && ch <= 0x0AC5) ||
  1383. (ch >= 0x0AC7 && ch <= 0x0AC9) ||
  1384. (ch >= 0x0ACB && ch <= 0x0ACD) ||
  1385. (ch >= 0x0B01 && ch <= 0x0B03) ||
  1386. (ch == 0x0B3C) ||
  1387. (ch >= 0x0B3E && ch <= 0x0B43) ||
  1388. (ch >= 0x0B47 && ch <= 0x0B48) ||
  1389. (ch >= 0x0B4B && ch <= 0x0B4D) ||
  1390. (ch >= 0x0B56 && ch <= 0x0B57) ||
  1391. (ch >= 0x0B82 && ch <= 0x0B83) ||
  1392. (ch >= 0x0BBE && ch <= 0x0BC2) ||
  1393. (ch >= 0x0BC6 && ch <= 0x0BC8) ||
  1394. (ch >= 0x0BCA && ch <= 0x0BCD) ||
  1395. (ch == 0x0BD7) ||
  1396. (ch >= 0x0C01 && ch <= 0x0C03) ||
  1397. (ch >= 0x0C3E && ch <= 0x0C44) ||
  1398. (ch >= 0x0C46 && ch <= 0x0C48) ||
  1399. (ch >= 0x0C4A && ch <= 0x0C4D) ||
  1400. (ch >= 0x0C55 && ch <= 0x0C56) ||
  1401. (ch >= 0x0C82 && ch <= 0x0C83) ||
  1402. (ch >= 0x0CBE && ch <= 0x0CC4) ||
  1403. (ch >= 0x0CC6 && ch <= 0x0CC8) ||
  1404. (ch >= 0x0CCA && ch <= 0x0CCD) ||
  1405. (ch >= 0x0CD5 && ch <= 0x0CD6) ||
  1406. (ch >= 0x0D02 && ch <= 0x0D03) ||
  1407. (ch >= 0x0D3E && ch <= 0x0D43) ||
  1408. (ch >= 0x0D46 && ch <= 0x0D48) ||
  1409. (ch >= 0x0D4A && ch <= 0x0D4D) ||
  1410. (ch == 0x0D57) ||
  1411. (ch == 0x0E31) ||
  1412. (ch >= 0x0E34 && ch <= 0x0E3A) ||
  1413. (ch >= 0x0E47 && ch <= 0x0E4E) ||
  1414. (ch == 0x0EB1) ||
  1415. (ch >= 0x0EB4 && ch <= 0x0EB9) ||
  1416. (ch >= 0x0EBB && ch <= 0x0EBC) ||
  1417. (ch >= 0x0EC8 && ch <= 0x0ECD) ||
  1418. (ch >= 0x0F18 && ch <= 0x0F19) ||
  1419. (ch == 0x0F35) ||
  1420. (ch == 0x0F37) ||
  1421. (ch == 0x0F39) ||
  1422. (ch == 0x0F3E) ||
  1423. (ch == 0x0F3F) ||
  1424. (ch >= 0x0F71 && ch <= 0x0F84) ||
  1425. (ch >= 0x0F86 && ch <= 0x0F8B) ||
  1426. (ch >= 0x0F90 && ch <= 0x0F95) ||
  1427. (ch == 0x0F97) ||
  1428. (ch >= 0x0F99 && ch <= 0x0FAD) ||
  1429. (ch >= 0x0FB1 && ch <= 0x0FB7) ||
  1430. (ch == 0x0FB9) ||
  1431. (ch >= 0x20D0 && ch <= 0x20DC) ||
  1432. (ch == 0x20E1) ||
  1433. (ch >= 0x302A && ch <= 0x302F) ||
  1434. (ch == 0x3099) ||
  1435. (ch == 0x309A);
  1436. }
  1437. private static bool IsExtender (int ch)
  1438. {
  1439. return
  1440. (ch == 0x00B7) ||
  1441. (ch == 0x02D0) ||
  1442. (ch == 0x02D1) ||
  1443. (ch == 0x0387) ||
  1444. (ch == 0x0640) ||
  1445. (ch == 0x0E46) ||
  1446. (ch == 0x0EC6) ||
  1447. (ch == 0x3005) ||
  1448. (ch >= 0x3031 && ch <= 0x3035) ||
  1449. (ch >= 0x309D && ch <= 0x309E) ||
  1450. (ch >= 0x30FC && ch <= 0x30FE);
  1451. }
  1452. #endif
  1453. public void TestIsName ()
  1454. {
  1455. Assert (XmlReader.IsName ("foo"));
  1456. Assert (!XmlReader.IsName ("1foo"));
  1457. Assert (!XmlReader.IsName (" foo"));
  1458. }
  1459. public void TestIsNameToken ()
  1460. {
  1461. Assert (XmlReader.IsNameToken ("foo"));
  1462. Assert (XmlReader.IsNameToken ("1foo"));
  1463. Assert (!XmlReader.IsNameToken (" foo"));
  1464. }
  1465. public void TestMoveToElementFromAttribute ()
  1466. {
  1467. string xml = @"<foo bar=""baz"" />";
  1468. XmlReader xmlReader =
  1469. new XmlTextReader (new StringReader (xml));
  1470. Assert (xmlReader.Read ());
  1471. AssertEquals (XmlNodeType.Element, xmlReader.NodeType);
  1472. Assert (xmlReader.MoveToFirstAttribute ());
  1473. AssertEquals (XmlNodeType.Attribute, xmlReader.NodeType);
  1474. Assert (xmlReader.MoveToElement ());
  1475. AssertEquals (XmlNodeType.Element, xmlReader.NodeType);
  1476. }
  1477. public void TestMoveToElementFromElement ()
  1478. {
  1479. string xml = @"<foo bar=""baz"" />";
  1480. XmlReader xmlReader =
  1481. new XmlTextReader (new StringReader (xml));
  1482. Assert (xmlReader.Read ());
  1483. AssertEquals (XmlNodeType.Element, xmlReader.NodeType);
  1484. Assert (!xmlReader.MoveToElement ());
  1485. AssertEquals (XmlNodeType.Element, xmlReader.NodeType);
  1486. }
  1487. public void TestMoveToFirstAttributeWithNoAttributes ()
  1488. {
  1489. string xml = @"<foo />";
  1490. XmlReader xmlReader =
  1491. new XmlTextReader (new StringReader (xml));
  1492. Assert (xmlReader.Read ());
  1493. AssertEquals (XmlNodeType.Element, xmlReader.NodeType);
  1494. Assert (!xmlReader.MoveToFirstAttribute ());
  1495. AssertEquals (XmlNodeType.Element, xmlReader.NodeType);
  1496. }
  1497. public void TestMoveToNextAttributeWithNoAttributes ()
  1498. {
  1499. string xml = @"<foo />";
  1500. XmlReader xmlReader =
  1501. new XmlTextReader (new StringReader (xml));
  1502. Assert (xmlReader.Read ());
  1503. AssertEquals (XmlNodeType.Element, xmlReader.NodeType);
  1504. Assert (!xmlReader.MoveToNextAttribute ());
  1505. AssertEquals (XmlNodeType.Element, xmlReader.NodeType);
  1506. }
  1507. public void TestMoveToNextAttribute()
  1508. {
  1509. string xml = @"<foo bar=""baz"" quux='quuux'/>";
  1510. XmlReader xmlReader =
  1511. new XmlTextReader (new StringReader (xml));
  1512. AssertStartDocument (xmlReader);
  1513. AssertNode (
  1514. xmlReader, // xmlReader
  1515. XmlNodeType.Element, // nodeType
  1516. 0, //depth
  1517. true, // isEmptyElement
  1518. "foo", // name
  1519. String.Empty, // prefix
  1520. "foo", // localName
  1521. String.Empty, // namespaceURI
  1522. String.Empty, // value
  1523. 2 // attributeCount
  1524. );
  1525. AssertAttribute (
  1526. xmlReader, // xmlReader
  1527. "bar", // name
  1528. String.Empty, // prefix
  1529. "bar", // localName
  1530. String.Empty, // namespaceURI
  1531. "baz" // value
  1532. );
  1533. AssertAttribute (
  1534. xmlReader, // xmlReader
  1535. "quux", // name
  1536. String.Empty, // prefix
  1537. "quux", // localName
  1538. String.Empty, // namespaceURI
  1539. "quuux" // value
  1540. );
  1541. Assert (xmlReader.MoveToNextAttribute ());
  1542. Assert ("bar" == xmlReader.Name || "quux" == xmlReader.Name);
  1543. Assert ("baz" == xmlReader.Value || "quuux" == xmlReader.Value);
  1544. Assert (xmlReader.MoveToNextAttribute ());
  1545. Assert ("bar" == xmlReader.Name || "quux" == xmlReader.Name);
  1546. Assert ("baz" == xmlReader.Value || "quuux" == xmlReader.Value);
  1547. Assert (!xmlReader.MoveToNextAttribute ());
  1548. Assert (xmlReader.MoveToElement ());
  1549. AssertNodeValues (
  1550. xmlReader, // xmlReader
  1551. XmlNodeType.Element, // nodeType
  1552. 0, //depth
  1553. true, // isEmptyElement
  1554. "foo", // name
  1555. String.Empty, // prefix
  1556. "foo", // localName
  1557. String.Empty, // namespaceURI
  1558. String.Empty, // value
  1559. 2 // attributeCount
  1560. );
  1561. AssertEndDocument (xmlReader);
  1562. }
  1563. }
  1564. }