XmlTextReaderTests.cs 44 KB

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