XmlTextReaderTests.cs 43 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785
  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 MonoTests.System.Xml
  14. {
  15. public class XmlTextReaderTests : TestCase
  16. {
  17. public XmlTextReaderTests () : base ("MonoTests.System.Xml.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. public void TestAttributeOrder ()
  1564. {
  1565. string xml = @"<foo _1='1' _2='2' _3='3' />";
  1566. XmlReader xmlReader =
  1567. new XmlTextReader (new StringReader (xml));
  1568. Assert (xmlReader.Read ());
  1569. AssertEquals (XmlNodeType.Element, xmlReader.NodeType);
  1570. Assert (xmlReader.MoveToFirstAttribute ());
  1571. AssertEquals ("_1", xmlReader.Name);
  1572. Assert (xmlReader.MoveToNextAttribute ());
  1573. AssertEquals ("_2", xmlReader.Name);
  1574. Assert (xmlReader.MoveToNextAttribute ());
  1575. AssertEquals ("_3", xmlReader.Name);
  1576. Assert (!xmlReader.MoveToNextAttribute ());
  1577. }
  1578. }
  1579. }