XmlTextReaderTests.cs 34 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242
  1. //
  2. // XmlTextReaderTests.cs
  3. //
  4. // Authors:
  5. // Jason Diamond ([email protected])
  6. // Martin Willemoes Hansen ([email protected])
  7. //
  8. // (C) 2001, 2002 Jason Diamond http://injektilo.org/
  9. //
  10. using System;
  11. using System.IO;
  12. using System.Xml;
  13. using System.Text;
  14. using NUnit.Framework;
  15. namespace MonoTests.System.Xml
  16. {
  17. [TestFixture]
  18. public class XmlTextReaderTests
  19. {
  20. private void AssertStartDocument (XmlReader xmlReader)
  21. {
  22. Assertion.Assert (xmlReader.ReadState == ReadState.Initial);
  23. Assertion.Assert (xmlReader.NodeType == XmlNodeType.None);
  24. Assertion.Assert (xmlReader.Depth == 0);
  25. Assertion.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. Assertion.Assert (xmlReader.Read ());
  40. Assertion.Assert (xmlReader.ReadState == ReadState.Interactive);
  41. Assertion.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. Assertion.AssertEquals ("NodeType", nodeType, xmlReader.NodeType);
  57. Assertion.AssertEquals ("Depth", depth, xmlReader.Depth);
  58. Assertion.AssertEquals ("IsEmptyElement", isEmptyElement, xmlReader.IsEmptyElement);
  59. Assertion.AssertEquals ("name", name, xmlReader.Name);
  60. Assertion.AssertEquals ("prefix", prefix, xmlReader.Prefix);
  61. Assertion.AssertEquals ("localName", localName, xmlReader.LocalName);
  62. Assertion.AssertEquals ("namespaceURI", namespaceURI, xmlReader.NamespaceURI);
  63. Assertion.AssertEquals ("hasValue", (value != String.Empty), xmlReader.HasValue);
  64. Assertion.AssertEquals ("Value", value, xmlReader.Value);
  65. Assertion.AssertEquals ("hasAttributes", attributeCount > 0, xmlReader.HasAttributes);
  66. Assertion.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. Assertion.AssertEquals ("value", value, xmlReader [name]);
  77. Assertion.Assert (xmlReader.GetAttribute (name) == value);
  78. if (namespaceURI != String.Empty) {
  79. Assertion.Assert (xmlReader[localName, namespaceURI] == value);
  80. Assertion.Assert (xmlReader.GetAttribute (localName, namespaceURI) == value);
  81. }
  82. }
  83. private void AssertEndDocument (XmlReader xmlReader)
  84. {
  85. Assertion.Assert ("could read", !xmlReader.Read ());
  86. Assertion.AssertEquals ("NodeType is not XmlNodeType.None", XmlNodeType.None, xmlReader.NodeType);
  87. Assertion.AssertEquals ("Depth is not 0", 0, xmlReader.Depth);
  88. Assertion.AssertEquals ("ReadState is not ReadState.EndOfFile", ReadState.EndOfFile, xmlReader.ReadState);
  89. Assertion.Assert ("not EOF", xmlReader.EOF);
  90. xmlReader.Close ();
  91. Assertion.AssertEquals ("ReadState is not ReadState.Cosed", ReadState.Closed, xmlReader.ReadState);
  92. }
  93. // expecting parser error
  94. [Test]
  95. public void EmptyElementWithBadName ()
  96. {
  97. string xml = "<1foo/>";
  98. XmlReader xmlReader =
  99. new XmlTextReader (new StringReader (xml));
  100. bool caughtXmlException = false;
  101. try {
  102. xmlReader.Read();
  103. } catch (XmlException) {
  104. caughtXmlException = true;
  105. }
  106. Assertion.Assert(caughtXmlException);
  107. }
  108. // checking parser
  109. [Test]
  110. public void EmptyElementWithStartAndEndTagWithWhitespace ()
  111. {
  112. string xml = "<foo ></foo >";
  113. XmlReader xmlReader =
  114. new XmlTextReader (new StringReader (xml));
  115. AssertStartDocument (xmlReader);
  116. AssertNode (
  117. xmlReader, // xmlReader
  118. XmlNodeType.Element, // nodeType
  119. 0, //depth
  120. false, // isEmptyElement
  121. "foo", // name
  122. String.Empty, // prefix
  123. "foo", // localName
  124. String.Empty, // namespaceURI
  125. String.Empty, // value
  126. 0 // attributeCount
  127. );
  128. AssertNode (
  129. xmlReader, // xmlReader
  130. XmlNodeType.EndElement, // nodeType
  131. 0, //depth
  132. false, // isEmptyElement
  133. "foo", // name
  134. String.Empty, // prefix
  135. "foo", // localName
  136. String.Empty, // namespaceURI
  137. String.Empty, // value
  138. 0 // attributeCount
  139. );
  140. AssertEndDocument (xmlReader);
  141. }
  142. [Test]
  143. public void EntityReferenceInAttribute ()
  144. {
  145. string xml = "<foo bar='&baz;'/>";
  146. XmlReader xmlReader =
  147. new XmlTextReader (new StringReader (xml));
  148. AssertStartDocument (xmlReader);
  149. AssertNode (
  150. xmlReader, // xmlReader
  151. XmlNodeType.Element, // nodeType
  152. 0, //depth
  153. true, // isEmptyElement
  154. "foo", // name
  155. String.Empty, // prefix
  156. "foo", // localName
  157. String.Empty, // namespaceURI
  158. String.Empty, // value
  159. 1 // attributeCount
  160. );
  161. AssertAttribute (
  162. xmlReader, // xmlReader
  163. "bar", // name
  164. String.Empty, // prefix
  165. "bar", // localName
  166. String.Empty, // namespaceURI
  167. "&baz;" // value
  168. );
  169. AssertEndDocument (xmlReader);
  170. }
  171. [Test]
  172. public void PredefinedEntitiesInAttribute ()
  173. {
  174. string xml = "<foo bar='&lt;&gt;&amp;&apos;&quot;'/>";
  175. XmlReader xmlReader =
  176. new XmlTextReader (new StringReader (xml));
  177. AssertStartDocument (xmlReader);
  178. AssertNode (
  179. xmlReader, // xmlReader
  180. XmlNodeType.Element, // nodeType
  181. 0, //depth
  182. true, // isEmptyElement
  183. "foo", // name
  184. String.Empty, // prefix
  185. "foo", // localName
  186. String.Empty, // namespaceURI
  187. String.Empty, // value
  188. 1 // attributeCount
  189. );
  190. AssertAttribute (
  191. xmlReader, // xmlReader
  192. "bar", // name
  193. String.Empty, // prefix
  194. "bar", // localName
  195. String.Empty, // namespaceURI
  196. "<>&'\"" // value
  197. );
  198. AssertEndDocument (xmlReader);
  199. }
  200. [Test]
  201. public void CharacterReferencesInAttribute ()
  202. {
  203. string xml = "<foo bar='&#70;&#x4F;&#x4f;'/>";
  204. XmlReader xmlReader =
  205. new XmlTextReader (new StringReader (xml));
  206. AssertStartDocument (xmlReader);
  207. AssertNode (
  208. xmlReader, // xmlReader
  209. XmlNodeType.Element, // nodeType
  210. 0, //depth
  211. true, // isEmptyElement
  212. "foo", // name
  213. String.Empty, // prefix
  214. "foo", // localName
  215. String.Empty, // namespaceURI
  216. String.Empty, // value
  217. 1 // attributeCount
  218. );
  219. AssertAttribute (
  220. xmlReader, // xmlReader
  221. "bar", // name
  222. String.Empty, // prefix
  223. "bar", // localName
  224. String.Empty, // namespaceURI
  225. "FOO" // value
  226. );
  227. AssertEndDocument (xmlReader);
  228. }
  229. [Test]
  230. public void CDATA ()
  231. {
  232. string xml = "<foo><![CDATA[<>&]]></foo>";
  233. XmlReader xmlReader =
  234. new XmlTextReader (new StringReader (xml));
  235. AssertStartDocument (xmlReader);
  236. AssertNode (
  237. xmlReader, // xmlReader
  238. XmlNodeType.Element, // nodeType
  239. 0, //depth
  240. false, // isEmptyElement
  241. "foo", // name
  242. String.Empty, // prefix
  243. "foo", // localName
  244. String.Empty, // namespaceURI
  245. String.Empty, // value
  246. 0 // attributeCount
  247. );
  248. AssertNode (
  249. xmlReader, // xmlReader
  250. XmlNodeType.CDATA, // nodeType
  251. 1, //depth
  252. false, // isEmptyElement
  253. String.Empty, // name
  254. String.Empty, // prefix
  255. String.Empty, // localName
  256. String.Empty, // namespaceURI
  257. "<>&", // value
  258. 0 // attributeCount
  259. );
  260. AssertNode (
  261. xmlReader, // xmlReader
  262. XmlNodeType.EndElement, // 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. AssertEndDocument (xmlReader);
  273. }
  274. [Test]
  275. public void EmptyElementInNamespace ()
  276. {
  277. string xml = @"<foo:bar xmlns:foo='http://foo/' />";
  278. XmlReader xmlReader =
  279. new XmlTextReader (new StringReader (xml));
  280. AssertStartDocument (xmlReader);
  281. AssertNode (
  282. xmlReader, // xmlReader
  283. XmlNodeType.Element, // nodeType
  284. 0, // depth
  285. true, // isEmptyElement
  286. "foo:bar", // name
  287. "foo", // prefix
  288. "bar", // localName
  289. "http://foo/", // namespaceURI
  290. String.Empty, // value
  291. 1 // attributeCount
  292. );
  293. AssertAttribute (
  294. xmlReader, // xmlReader
  295. "xmlns:foo", // name
  296. "xmlns", // prefix
  297. "foo", // localName
  298. "http://www.w3.org/2000/xmlns/", // namespaceURI
  299. "http://foo/" // value
  300. );
  301. Assertion.AssertEquals ("http://foo/", xmlReader.LookupNamespace ("foo"));
  302. AssertEndDocument (xmlReader);
  303. }
  304. [Test]
  305. public void EmptyElementInDefaultNamespace ()
  306. {
  307. string xml = @"<foo xmlns='http://foo/' />";
  308. XmlReader xmlReader =
  309. new XmlTextReader (new StringReader (xml));
  310. AssertStartDocument (xmlReader);
  311. AssertNode (
  312. xmlReader, // xmlReader
  313. XmlNodeType.Element, // nodeType
  314. 0, // depth
  315. true, // isEmptyElement
  316. "foo", // name
  317. String.Empty, // prefix
  318. "foo", // localName
  319. "http://foo/", // namespaceURI
  320. String.Empty, // value
  321. 1 // attributeCount
  322. );
  323. AssertAttribute (
  324. xmlReader, // xmlReader
  325. "xmlns", // name
  326. String.Empty, // prefix
  327. "xmlns", // localName
  328. "http://www.w3.org/2000/xmlns/", // namespaceURI
  329. "http://foo/" // value
  330. );
  331. Assertion.AssertEquals ("http://foo/", xmlReader.LookupNamespace (String.Empty));
  332. AssertEndDocument (xmlReader);
  333. }
  334. [Test]
  335. public void ChildElementInNamespace ()
  336. {
  337. string xml = @"<foo:bar xmlns:foo='http://foo/'><baz:quux xmlns:baz='http://baz/' /></foo:bar>";
  338. XmlReader xmlReader =
  339. new XmlTextReader (new StringReader (xml));
  340. AssertStartDocument (xmlReader);
  341. AssertNode (
  342. xmlReader, // xmlReader
  343. XmlNodeType.Element, // nodeType
  344. 0, // depth
  345. false, // isEmptyElement
  346. "foo:bar", // name
  347. "foo", // prefix
  348. "bar", // localName
  349. "http://foo/", // namespaceURI
  350. String.Empty, // value
  351. 1 // attributeCount
  352. );
  353. AssertAttribute (
  354. xmlReader, // xmlReader
  355. "xmlns:foo", // name
  356. "xmlns", // prefix
  357. "foo", // localName
  358. "http://www.w3.org/2000/xmlns/", // namespaceURI
  359. "http://foo/" // value
  360. );
  361. Assertion.AssertEquals ("http://foo/", xmlReader.LookupNamespace ("foo"));
  362. AssertNode (
  363. xmlReader, // xmlReader
  364. XmlNodeType.Element, // nodeType
  365. 1, // depth
  366. true, // isEmptyElement
  367. "baz:quux", // name
  368. "baz", // prefix
  369. "quux", // localName
  370. "http://baz/", // namespaceURI
  371. String.Empty, // value
  372. 1 // attributeCount
  373. );
  374. AssertAttribute (
  375. xmlReader, // xmlReader
  376. "xmlns:baz", // name
  377. "xmlns", // prefix
  378. "baz", // localName
  379. "http://www.w3.org/2000/xmlns/", // namespaceURI
  380. "http://baz/" // value
  381. );
  382. Assertion.AssertEquals ("http://foo/", xmlReader.LookupNamespace ("foo"));
  383. Assertion.AssertEquals ("http://baz/", xmlReader.LookupNamespace ("baz"));
  384. AssertNode (
  385. xmlReader, // xmlReader
  386. XmlNodeType.EndElement, // nodeType
  387. 0, // depth
  388. false, // isEmptyElement
  389. "foo:bar", // name
  390. "foo", // prefix
  391. "bar", // localName
  392. "http://foo/", // namespaceURI
  393. String.Empty, // value
  394. 0 // attributeCount
  395. );
  396. Assertion.AssertEquals ("http://foo/", xmlReader.LookupNamespace ("foo"));
  397. Assertion.AssertNull (xmlReader.LookupNamespace ("baz"));
  398. AssertEndDocument (xmlReader);
  399. }
  400. [Test]
  401. public void ChildElementInDefaultNamespace ()
  402. {
  403. string xml = @"<foo:bar xmlns:foo='http://foo/'><baz xmlns='http://baz/' /></foo:bar>";
  404. XmlReader xmlReader =
  405. new XmlTextReader (new StringReader (xml));
  406. AssertStartDocument (xmlReader);
  407. AssertNode (
  408. xmlReader, // xmlReader
  409. XmlNodeType.Element, // nodeType
  410. 0, // depth
  411. false, // isEmptyElement
  412. "foo:bar", // name
  413. "foo", // prefix
  414. "bar", // localName
  415. "http://foo/", // namespaceURI
  416. String.Empty, // value
  417. 1 // attributeCount
  418. );
  419. AssertAttribute (
  420. xmlReader, // xmlReader
  421. "xmlns:foo", // name
  422. "xmlns", // prefix
  423. "foo", // localName
  424. "http://www.w3.org/2000/xmlns/", // namespaceURI
  425. "http://foo/" // value
  426. );
  427. Assertion.AssertEquals ("http://foo/", xmlReader.LookupNamespace ("foo"));
  428. AssertNode (
  429. xmlReader, // xmlReader
  430. XmlNodeType.Element, // nodeType
  431. 1, // depth
  432. true, // isEmptyElement
  433. "baz", // name
  434. String.Empty, // prefix
  435. "baz", // localName
  436. "http://baz/", // namespaceURI
  437. String.Empty, // value
  438. 1 // attributeCount
  439. );
  440. AssertAttribute (
  441. xmlReader, // xmlReader
  442. "xmlns", // name
  443. String.Empty, // prefix
  444. "xmlns", // localName
  445. "http://www.w3.org/2000/xmlns/", // namespaceURI
  446. "http://baz/" // value
  447. );
  448. Assertion.AssertEquals ("http://foo/", xmlReader.LookupNamespace ("foo"));
  449. Assertion.AssertEquals ("http://baz/", xmlReader.LookupNamespace (String.Empty));
  450. AssertNode (
  451. xmlReader, // xmlReader
  452. XmlNodeType.EndElement, // nodeType
  453. 0, // depth
  454. false, // isEmptyElement
  455. "foo:bar", // name
  456. "foo", // prefix
  457. "bar", // localName
  458. "http://foo/", // namespaceURI
  459. String.Empty, // value
  460. 0 // attributeCount
  461. );
  462. Assertion.AssertEquals ("http://foo/", xmlReader.LookupNamespace ("foo"));
  463. AssertEndDocument (xmlReader);
  464. }
  465. [Test]
  466. public void AttributeInNamespace ()
  467. {
  468. string xml = @"<foo bar:baz='quux' xmlns:bar='http://bar/' />";
  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. true, // isEmptyElement
  477. "foo", // name
  478. String.Empty, // prefix
  479. "foo", // localName
  480. String.Empty, // namespaceURI
  481. String.Empty, // value
  482. 2 // attributeCount
  483. );
  484. AssertAttribute (
  485. xmlReader, // xmlReader
  486. "bar:baz", // name
  487. "bar", // prefix
  488. "baz", // localName
  489. "http://bar/", // namespaceURI
  490. "quux" // value
  491. );
  492. AssertAttribute (
  493. xmlReader, // xmlReader
  494. "xmlns:bar", // name
  495. "xmlns", // prefix
  496. "bar", // localName
  497. "http://www.w3.org/2000/xmlns/", // namespaceURI
  498. "http://bar/" // value
  499. );
  500. Assertion.AssertEquals ("http://bar/", xmlReader.LookupNamespace ("bar"));
  501. AssertEndDocument (xmlReader);
  502. }
  503. // The following is #if'ed out because it's specific to the Mono
  504. // implementation and won't compile when testing Microsoft's code.
  505. // Feel free to turn it on if you want to test Mono's name tables.
  506. #if false
  507. [Test]
  508. public void IsFirstNameCharTest ()
  509. {
  510. for (int ch = 0; ch <= 0xFFFF; ++ch) {
  511. Assertion.Assert (
  512. XmlChar.IsFirstNameChar (ch) ==
  513. IsFirstNameChar (ch));
  514. }
  515. }
  516. [Test]
  517. public void IsNameCharTest ()
  518. {
  519. for (int ch = 0; ch <= 0xFFFF; ++ch) {
  520. Assertion.Assert (
  521. XmlChar.IsNameChar (ch) ==
  522. IsNameChar (ch));
  523. }
  524. }
  525. private static bool IsFirstNameChar (int ch)
  526. {
  527. return
  528. IsLetter (ch) ||
  529. (ch == '_') ||
  530. (ch == ':');
  531. }
  532. private static bool IsNameChar (int ch)
  533. {
  534. return
  535. IsLetter (ch) ||
  536. IsDigit (ch) ||
  537. (ch == '.') ||
  538. (ch == '-') ||
  539. (ch == '_') ||
  540. (ch == ':') ||
  541. IsCombiningChar (ch) ||
  542. IsExtender (ch);
  543. }
  544. private static bool IsLetter (int ch)
  545. {
  546. return
  547. IsBaseChar (ch) ||
  548. IsIdeographic (ch);
  549. }
  550. private static bool IsBaseChar (int ch)
  551. {
  552. return
  553. (ch >= 0x0041 && ch <= 0x005A) ||
  554. (ch >= 0x0061 && ch <= 0x007A) ||
  555. (ch >= 0x00C0 && ch <= 0x00D6) ||
  556. (ch >= 0x00D8 && ch <= 0x00F6) ||
  557. (ch >= 0x00F8 && ch <= 0x00FF) ||
  558. (ch >= 0x0100 && ch <= 0x0131) ||
  559. (ch >= 0x0134 && ch <= 0x013E) ||
  560. (ch >= 0x0141 && ch <= 0x0148) ||
  561. (ch >= 0x014A && ch <= 0x017E) ||
  562. (ch >= 0x0180 && ch <= 0x01C3) ||
  563. (ch >= 0x01CD && ch <= 0x01F0) ||
  564. (ch >= 0x01F4 && ch <= 0x01F5) ||
  565. (ch >= 0x01FA && ch <= 0x0217) ||
  566. (ch >= 0x0250 && ch <= 0x02A8) ||
  567. (ch >= 0x02BB && ch <= 0x02C1) ||
  568. (ch == 0x0386) ||
  569. (ch >= 0x0388 && ch <= 0x038A) ||
  570. (ch == 0x038C) ||
  571. (ch >= 0x038E && ch <= 0x03A1) ||
  572. (ch >= 0x03A3 && ch <= 0x03CE) ||
  573. (ch >= 0x03D0 && ch <= 0x03D6) ||
  574. (ch == 0x03DA) ||
  575. (ch == 0x03DC) ||
  576. (ch == 0x03DE) ||
  577. (ch == 0x03E0) ||
  578. (ch >= 0x03E2 && ch <= 0x03F3) ||
  579. (ch >= 0x0401 && ch <= 0x040C) ||
  580. (ch >= 0x040E && ch <= 0x044F) ||
  581. (ch >= 0x0451 && ch <= 0x045C) ||
  582. (ch >= 0x045E && ch <= 0x0481) ||
  583. (ch >= 0x0490 && ch <= 0x04C4) ||
  584. (ch >= 0x04C7 && ch <= 0x04C8) ||
  585. (ch >= 0x04CB && ch <= 0x04CC) ||
  586. (ch >= 0x04D0 && ch <= 0x04EB) ||
  587. (ch >= 0x04EE && ch <= 0x04F5) ||
  588. (ch >= 0x04F8 && ch <= 0x04F9) ||
  589. (ch >= 0x0531 && ch <= 0x0556) ||
  590. (ch == 0x0559) ||
  591. (ch >= 0x0561 && ch <= 0x0586) ||
  592. (ch >= 0x05D0 && ch <= 0x05EA) ||
  593. (ch >= 0x05F0 && ch <= 0x05F2) ||
  594. (ch >= 0x0621 && ch <= 0x063A) ||
  595. (ch >= 0x0641 && ch <= 0x064A) ||
  596. (ch >= 0x0671 && ch <= 0x06B7) ||
  597. (ch >= 0x06BA && ch <= 0x06BE) ||
  598. (ch >= 0x06C0 && ch <= 0x06CE) ||
  599. (ch >= 0x06D0 && ch <= 0x06D3) ||
  600. (ch == 0x06D5) ||
  601. (ch >= 0x06E5 && ch <= 0x06E6) ||
  602. (ch >= 0x0905 && ch <= 0x0939) ||
  603. (ch == 0x093D) ||
  604. (ch >= 0x0958 && ch <= 0x0961) ||
  605. (ch >= 0x0985 && ch <= 0x098C) ||
  606. (ch >= 0x098F && ch <= 0x0990) ||
  607. (ch >= 0x0993 && ch <= 0x09A8) ||
  608. (ch >= 0x09AA && ch <= 0x09B0) ||
  609. (ch == 0x09B2) ||
  610. (ch >= 0x09B6 && ch <= 0x09B9) ||
  611. (ch >= 0x09DC && ch <= 0x09DD) ||
  612. (ch >= 0x09DF && ch <= 0x09E1) ||
  613. (ch >= 0x09F0 && ch <= 0x09F1) ||
  614. (ch >= 0x0A05 && ch <= 0x0A0A) ||
  615. (ch >= 0x0A0F && ch <= 0x0A10) ||
  616. (ch >= 0x0A13 && ch <= 0x0A28) ||
  617. (ch >= 0x0A2A && ch <= 0x0A30) ||
  618. (ch >= 0x0A32 && ch <= 0x0A33) ||
  619. (ch >= 0x0A35 && ch <= 0x0A36) ||
  620. (ch >= 0x0A38 && ch <= 0x0A39) ||
  621. (ch >= 0x0A59 && ch <= 0x0A5C) ||
  622. (ch == 0x0A5E) ||
  623. (ch >= 0x0A72 && ch <= 0x0A74) ||
  624. (ch >= 0x0A85 && ch <= 0x0A8B) ||
  625. (ch == 0x0A8D) ||
  626. (ch >= 0x0A8F && ch <= 0x0A91) ||
  627. (ch >= 0x0A93 && ch <= 0x0AA8) ||
  628. (ch >= 0x0AAA && ch <= 0x0AB0) ||
  629. (ch >= 0x0AB2 && ch <= 0x0AB3) ||
  630. (ch >= 0x0AB5 && ch <= 0x0AB9) ||
  631. (ch == 0x0ABD) ||
  632. (ch == 0x0AE0) ||
  633. (ch >= 0x0B05 && ch <= 0x0B0C) ||
  634. (ch >= 0x0B0F && ch <= 0x0B10) ||
  635. (ch >= 0x0B13 && ch <= 0x0B28) ||
  636. (ch >= 0x0B2A && ch <= 0x0B30) ||
  637. (ch >= 0x0B32 && ch <= 0x0B33) ||
  638. (ch >= 0x0B36 && ch <= 0x0B39) ||
  639. (ch == 0x0B3D) ||
  640. (ch >= 0x0B5C && ch <= 0x0B5D) ||
  641. (ch >= 0x0B5F && ch <= 0x0B61) ||
  642. (ch >= 0x0B85 && ch <= 0x0B8A) ||
  643. (ch >= 0x0B8E && ch <= 0x0B90) ||
  644. (ch >= 0x0B92 && ch <= 0x0B95) ||
  645. (ch >= 0x0B99 && ch <= 0x0B9A) ||
  646. (ch == 0x0B9C) ||
  647. (ch >= 0x0B9E && ch <= 0x0B9F) ||
  648. (ch >= 0x0BA3 && ch <= 0x0BA4) ||
  649. (ch >= 0x0BA8 && ch <= 0x0BAA) ||
  650. (ch >= 0x0BAE && ch <= 0x0BB5) ||
  651. (ch >= 0x0BB7 && ch <= 0x0BB9) ||
  652. (ch >= 0x0C05 && ch <= 0x0C0C) ||
  653. (ch >= 0x0C0E && ch <= 0x0C10) ||
  654. (ch >= 0x0C12 && ch <= 0x0C28) ||
  655. (ch >= 0x0C2A && ch <= 0x0C33) ||
  656. (ch >= 0x0C35 && ch <= 0x0C39) ||
  657. (ch >= 0x0C60 && ch <= 0x0C61) ||
  658. (ch >= 0x0C85 && ch <= 0x0C8C) ||
  659. (ch >= 0x0C8E && ch <= 0x0C90) ||
  660. (ch >= 0x0C92 && ch <= 0x0CA8) ||
  661. (ch >= 0x0CAA && ch <= 0x0CB3) ||
  662. (ch >= 0x0CB5 && ch <= 0x0CB9) ||
  663. (ch == 0x0CDE) ||
  664. (ch >= 0x0CE0 && ch <= 0x0CE1) ||
  665. (ch >= 0x0D05 && ch <= 0x0D0C) ||
  666. (ch >= 0x0D0E && ch <= 0x0D10) ||
  667. (ch >= 0x0D12 && ch <= 0x0D28) ||
  668. (ch >= 0x0D2A && ch <= 0x0D39) ||
  669. (ch >= 0x0D60 && ch <= 0x0D61) ||
  670. (ch >= 0x0E01 && ch <= 0x0E2E) ||
  671. (ch == 0x0E30) ||
  672. (ch >= 0x0E32 && ch <= 0x0E33) ||
  673. (ch >= 0x0E40 && ch <= 0x0E45) ||
  674. (ch >= 0x0E81 && ch <= 0x0E82) ||
  675. (ch == 0x0E84) ||
  676. (ch >= 0x0E87 && ch <= 0x0E88) ||
  677. (ch == 0x0E8A) ||
  678. (ch == 0x0E8D) ||
  679. (ch >= 0x0E94 && ch <= 0x0E97) ||
  680. (ch >= 0x0E99 && ch <= 0x0E9F) ||
  681. (ch >= 0x0EA1 && ch <= 0x0EA3) ||
  682. (ch == 0x0EA5) ||
  683. (ch == 0x0EA7) ||
  684. (ch >= 0x0EAA && ch <= 0x0EAB) ||
  685. (ch >= 0x0EAD && ch <= 0x0EAE) ||
  686. (ch == 0x0EB0) ||
  687. (ch >= 0x0EB2 && ch <= 0x0EB3) ||
  688. (ch == 0x0EBD) ||
  689. (ch >= 0x0EC0 && ch <= 0x0EC4) ||
  690. (ch >= 0x0F40 && ch <= 0x0F47) ||
  691. (ch >= 0x0F49 && ch <= 0x0F69) ||
  692. (ch >= 0x10A0 && ch <= 0x10C5) ||
  693. (ch >= 0x10D0 && ch <= 0x10F6) ||
  694. (ch == 0x1100) ||
  695. (ch >= 0x1102 && ch <= 0x1103) ||
  696. (ch >= 0x1105 && ch <= 0x1107) ||
  697. (ch == 0x1109) ||
  698. (ch >= 0x110B && ch <= 0x110C) ||
  699. (ch >= 0x110E && ch <= 0x1112) ||
  700. (ch == 0x113C) ||
  701. (ch == 0x113E) ||
  702. (ch == 0x1140) ||
  703. (ch == 0x114C) ||
  704. (ch == 0x114E) ||
  705. (ch == 0x1150) ||
  706. (ch >= 0x1154 && ch <= 0x1155) ||
  707. (ch == 0x1159) ||
  708. (ch >= 0x115F && ch <= 0x1161) ||
  709. (ch == 0x1163) ||
  710. (ch == 0x1165) ||
  711. (ch == 0x1167) ||
  712. (ch == 0x1169) ||
  713. (ch >= 0x116D && ch <= 0x116E) ||
  714. (ch >= 0x1172 && ch <= 0x1173) ||
  715. (ch == 0x1175) ||
  716. (ch == 0x119E) ||
  717. (ch == 0x11A8) ||
  718. (ch == 0x11AB) ||
  719. (ch >= 0x11AE && ch <= 0x11AF) ||
  720. (ch >= 0x11B7 && ch <= 0x11B8) ||
  721. (ch == 0x11BA) ||
  722. (ch >= 0x11BC && ch <= 0x11C2) ||
  723. (ch == 0x11EB) ||
  724. (ch == 0x11F0) ||
  725. (ch == 0x11F9) ||
  726. (ch >= 0x1E00 && ch <= 0x1E9B) ||
  727. (ch >= 0x1EA0 && ch <= 0x1EF9) ||
  728. (ch >= 0x1F00 && ch <= 0x1F15) ||
  729. (ch >= 0x1F18 && ch <= 0x1F1D) ||
  730. (ch >= 0x1F20 && ch <= 0x1F45) ||
  731. (ch >= 0x1F48 && ch <= 0x1F4D) ||
  732. (ch >= 0x1F50 && ch <= 0x1F57) ||
  733. (ch == 0x1F59) ||
  734. (ch == 0x1F5B) ||
  735. (ch == 0x1F5D) ||
  736. (ch >= 0x1F5F && ch <= 0x1F7D) ||
  737. (ch >= 0x1F80 && ch <= 0x1FB4) ||
  738. (ch >= 0x1FB6 && ch <= 0x1FBC) ||
  739. (ch == 0x1FBE) ||
  740. (ch >= 0x1FC2 && ch <= 0x1FC4) ||
  741. (ch >= 0x1FC6 && ch <= 0x1FCC) ||
  742. (ch >= 0x1FD0 && ch <= 0x1FD3) ||
  743. (ch >= 0x1FD6 && ch <= 0x1FDB) ||
  744. (ch >= 0x1FE0 && ch <= 0x1FEC) ||
  745. (ch >= 0x1FF2 && ch <= 0x1FF4) ||
  746. (ch >= 0x1FF6 && ch <= 0x1FFC) ||
  747. (ch == 0x2126) ||
  748. (ch >= 0x212A && ch <= 0x212B) ||
  749. (ch == 0x212E) ||
  750. (ch >= 0x2180 && ch <= 0x2182) ||
  751. (ch >= 0x3041 && ch <= 0x3094) ||
  752. (ch >= 0x30A1 && ch <= 0x30FA) ||
  753. (ch >= 0x3105 && ch <= 0x312C) ||
  754. (ch >= 0xAC00 && ch <= 0xD7A3);
  755. }
  756. private static bool IsIdeographic (int ch)
  757. {
  758. return
  759. (ch >= 0x4E00 && ch <= 0x9FA5) ||
  760. (ch == 0x3007) ||
  761. (ch >= 0x3021 && ch <= 0x3029);
  762. }
  763. private static bool IsDigit (int ch)
  764. {
  765. return
  766. (ch >= 0x0030 && ch <= 0x0039) ||
  767. (ch >= 0x0660 && ch <= 0x0669) ||
  768. (ch >= 0x06F0 && ch <= 0x06F9) ||
  769. (ch >= 0x0966 && ch <= 0x096F) ||
  770. (ch >= 0x09E6 && ch <= 0x09EF) ||
  771. (ch >= 0x0A66 && ch <= 0x0A6F) ||
  772. (ch >= 0x0AE6 && ch <= 0x0AEF) ||
  773. (ch >= 0x0B66 && ch <= 0x0B6F) ||
  774. (ch >= 0x0BE7 && ch <= 0x0BEF) ||
  775. (ch >= 0x0C66 && ch <= 0x0C6F) ||
  776. (ch >= 0x0CE6 && ch <= 0x0CEF) ||
  777. (ch >= 0x0D66 && ch <= 0x0D6F) ||
  778. (ch >= 0x0E50 && ch <= 0x0E59) ||
  779. (ch >= 0x0ED0 && ch <= 0x0ED9) ||
  780. (ch >= 0x0F20 && ch <= 0x0F29);
  781. }
  782. private static bool IsCombiningChar (int ch)
  783. {
  784. return
  785. (ch >= 0x0300 && ch <= 0x0345) ||
  786. (ch >= 0x0360 && ch <= 0x0361) ||
  787. (ch >= 0x0483 && ch <= 0x0486) ||
  788. (ch >= 0x0591 && ch <= 0x05A1) ||
  789. (ch >= 0x05A3 && ch <= 0x05B9) ||
  790. (ch >= 0x05BB && ch <= 0x05BD) ||
  791. (ch == 0x05BF) ||
  792. (ch >= 0x05C1 && ch <= 0x05C2) ||
  793. (ch == 0x05C4) ||
  794. (ch >= 0x064B && ch <= 0x0652) ||
  795. (ch == 0x0670) ||
  796. (ch >= 0x06D6 && ch <= 0x06DC) ||
  797. (ch >= 0x06DD && ch <= 0x06DF) ||
  798. (ch >= 0x06E0 && ch <= 0x06E4) ||
  799. (ch >= 0x06E7 && ch <= 0x06E8) ||
  800. (ch >= 0x06EA && ch <= 0x06ED) ||
  801. (ch >= 0x0901 && ch <= 0x0903) ||
  802. (ch == 0x093C) ||
  803. (ch >= 0x093E && ch <= 0x094C) ||
  804. (ch == 0x094D) ||
  805. (ch >= 0x0951 && ch <= 0x0954) ||
  806. (ch >= 0x0962 && ch <= 0x0963) ||
  807. (ch >= 0x0981 && ch <= 0x0983) ||
  808. (ch == 0x09BC) ||
  809. (ch == 0x09BE) ||
  810. (ch == 0x09BF) ||
  811. (ch >= 0x09C0 && ch <= 0x09C4) ||
  812. (ch >= 0x09C7 && ch <= 0x09C8) ||
  813. (ch >= 0x09CB && ch <= 0x09CD) ||
  814. (ch == 0x09D7) ||
  815. (ch >= 0x09E2 && ch <= 0x09E3) ||
  816. (ch == 0x0A02) ||
  817. (ch == 0x0A3C) ||
  818. (ch == 0x0A3E) ||
  819. (ch == 0x0A3F) ||
  820. (ch >= 0x0A40 && ch <= 0x0A42) ||
  821. (ch >= 0x0A47 && ch <= 0x0A48) ||
  822. (ch >= 0x0A4B && ch <= 0x0A4D) ||
  823. (ch >= 0x0A70 && ch <= 0x0A71) ||
  824. (ch >= 0x0A81 && ch <= 0x0A83) ||
  825. (ch == 0x0ABC) ||
  826. (ch >= 0x0ABE && ch <= 0x0AC5) ||
  827. (ch >= 0x0AC7 && ch <= 0x0AC9) ||
  828. (ch >= 0x0ACB && ch <= 0x0ACD) ||
  829. (ch >= 0x0B01 && ch <= 0x0B03) ||
  830. (ch == 0x0B3C) ||
  831. (ch >= 0x0B3E && ch <= 0x0B43) ||
  832. (ch >= 0x0B47 && ch <= 0x0B48) ||
  833. (ch >= 0x0B4B && ch <= 0x0B4D) ||
  834. (ch >= 0x0B56 && ch <= 0x0B57) ||
  835. (ch >= 0x0B82 && ch <= 0x0B83) ||
  836. (ch >= 0x0BBE && ch <= 0x0BC2) ||
  837. (ch >= 0x0BC6 && ch <= 0x0BC8) ||
  838. (ch >= 0x0BCA && ch <= 0x0BCD) ||
  839. (ch == 0x0BD7) ||
  840. (ch >= 0x0C01 && ch <= 0x0C03) ||
  841. (ch >= 0x0C3E && ch <= 0x0C44) ||
  842. (ch >= 0x0C46 && ch <= 0x0C48) ||
  843. (ch >= 0x0C4A && ch <= 0x0C4D) ||
  844. (ch >= 0x0C55 && ch <= 0x0C56) ||
  845. (ch >= 0x0C82 && ch <= 0x0C83) ||
  846. (ch >= 0x0CBE && ch <= 0x0CC4) ||
  847. (ch >= 0x0CC6 && ch <= 0x0CC8) ||
  848. (ch >= 0x0CCA && ch <= 0x0CCD) ||
  849. (ch >= 0x0CD5 && ch <= 0x0CD6) ||
  850. (ch >= 0x0D02 && ch <= 0x0D03) ||
  851. (ch >= 0x0D3E && ch <= 0x0D43) ||
  852. (ch >= 0x0D46 && ch <= 0x0D48) ||
  853. (ch >= 0x0D4A && ch <= 0x0D4D) ||
  854. (ch == 0x0D57) ||
  855. (ch == 0x0E31) ||
  856. (ch >= 0x0E34 && ch <= 0x0E3A) ||
  857. (ch >= 0x0E47 && ch <= 0x0E4E) ||
  858. (ch == 0x0EB1) ||
  859. (ch >= 0x0EB4 && ch <= 0x0EB9) ||
  860. (ch >= 0x0EBB && ch <= 0x0EBC) ||
  861. (ch >= 0x0EC8 && ch <= 0x0ECD) ||
  862. (ch >= 0x0F18 && ch <= 0x0F19) ||
  863. (ch == 0x0F35) ||
  864. (ch == 0x0F37) ||
  865. (ch == 0x0F39) ||
  866. (ch == 0x0F3E) ||
  867. (ch == 0x0F3F) ||
  868. (ch >= 0x0F71 && ch <= 0x0F84) ||
  869. (ch >= 0x0F86 && ch <= 0x0F8B) ||
  870. (ch >= 0x0F90 && ch <= 0x0F95) ||
  871. (ch == 0x0F97) ||
  872. (ch >= 0x0F99 && ch <= 0x0FAD) ||
  873. (ch >= 0x0FB1 && ch <= 0x0FB7) ||
  874. (ch == 0x0FB9) ||
  875. (ch >= 0x20D0 && ch <= 0x20DC) ||
  876. (ch == 0x20E1) ||
  877. (ch >= 0x302A && ch <= 0x302F) ||
  878. (ch == 0x3099) ||
  879. (ch == 0x309A);
  880. }
  881. private static bool IsExtender (int ch)
  882. {
  883. return
  884. (ch == 0x00B7) ||
  885. (ch == 0x02D0) ||
  886. (ch == 0x02D1) ||
  887. (ch == 0x0387) ||
  888. (ch == 0x0640) ||
  889. (ch == 0x0E46) ||
  890. (ch == 0x0EC6) ||
  891. (ch == 0x3005) ||
  892. (ch >= 0x3031 && ch <= 0x3035) ||
  893. (ch >= 0x309D && ch <= 0x309E) ||
  894. (ch >= 0x30FC && ch <= 0x30FE);
  895. }
  896. #endif
  897. [Test]
  898. public void IsName ()
  899. {
  900. Assertion.Assert (XmlReader.IsName ("foo"));
  901. Assertion.Assert (!XmlReader.IsName ("1foo"));
  902. Assertion.Assert (!XmlReader.IsName (" foo"));
  903. }
  904. [Test]
  905. public void IsNameToken ()
  906. {
  907. Assertion.Assert (XmlReader.IsNameToken ("foo"));
  908. Assertion.Assert (XmlReader.IsNameToken ("1foo"));
  909. Assertion.Assert (!XmlReader.IsNameToken (" foo"));
  910. }
  911. [Test]
  912. public void MoveToElementFromAttribute ()
  913. {
  914. string xml = @"<foo bar=""baz"" />";
  915. XmlReader xmlReader =
  916. new XmlTextReader (new StringReader (xml));
  917. Assertion.Assert (xmlReader.Read ());
  918. Assertion.AssertEquals (XmlNodeType.Element, xmlReader.NodeType);
  919. Assertion.Assert (xmlReader.MoveToFirstAttribute ());
  920. Assertion.AssertEquals (XmlNodeType.Attribute, xmlReader.NodeType);
  921. Assertion.Assert (xmlReader.MoveToElement ());
  922. Assertion.AssertEquals (XmlNodeType.Element, xmlReader.NodeType);
  923. }
  924. [Test]
  925. public void MoveToElementFromElement ()
  926. {
  927. string xml = @"<foo bar=""baz"" />";
  928. XmlReader xmlReader =
  929. new XmlTextReader (new StringReader (xml));
  930. Assertion.Assert (xmlReader.Read ());
  931. Assertion.AssertEquals (XmlNodeType.Element, xmlReader.NodeType);
  932. Assertion.Assert (!xmlReader.MoveToElement ());
  933. Assertion.AssertEquals (XmlNodeType.Element, xmlReader.NodeType);
  934. }
  935. [Test]
  936. public void MoveToFirstAttributeWithNoAttributes ()
  937. {
  938. string xml = @"<foo />";
  939. XmlReader xmlReader =
  940. new XmlTextReader (new StringReader (xml));
  941. Assertion.Assert (xmlReader.Read ());
  942. Assertion.AssertEquals (XmlNodeType.Element, xmlReader.NodeType);
  943. Assertion.Assert (!xmlReader.MoveToFirstAttribute ());
  944. Assertion.AssertEquals (XmlNodeType.Element, xmlReader.NodeType);
  945. }
  946. [Test]
  947. public void MoveToNextAttributeWithNoAttributes ()
  948. {
  949. string xml = @"<foo />";
  950. XmlReader xmlReader =
  951. new XmlTextReader (new StringReader (xml));
  952. Assertion.Assert (xmlReader.Read ());
  953. Assertion.AssertEquals (XmlNodeType.Element, xmlReader.NodeType);
  954. Assertion.Assert (!xmlReader.MoveToNextAttribute ());
  955. Assertion.AssertEquals (XmlNodeType.Element, xmlReader.NodeType);
  956. }
  957. [Test]
  958. public void MoveToNextAttribute()
  959. {
  960. string xml = @"<foo bar=""baz"" quux='quuux'/>";
  961. XmlReader xmlReader =
  962. new XmlTextReader (new StringReader (xml));
  963. AssertStartDocument (xmlReader);
  964. AssertNode (
  965. xmlReader, // xmlReader
  966. XmlNodeType.Element, // nodeType
  967. 0, //depth
  968. true, // isEmptyElement
  969. "foo", // name
  970. String.Empty, // prefix
  971. "foo", // localName
  972. String.Empty, // namespaceURI
  973. String.Empty, // value
  974. 2 // attributeCount
  975. );
  976. AssertAttribute (
  977. xmlReader, // xmlReader
  978. "bar", // name
  979. String.Empty, // prefix
  980. "bar", // localName
  981. String.Empty, // namespaceURI
  982. "baz" // value
  983. );
  984. AssertAttribute (
  985. xmlReader, // xmlReader
  986. "quux", // name
  987. String.Empty, // prefix
  988. "quux", // localName
  989. String.Empty, // namespaceURI
  990. "quuux" // value
  991. );
  992. Assertion.Assert (xmlReader.MoveToNextAttribute ());
  993. Assertion.Assert ("bar" == xmlReader.Name || "quux" == xmlReader.Name);
  994. Assertion.Assert ("baz" == xmlReader.Value || "quuux" == xmlReader.Value);
  995. Assertion.Assert (xmlReader.MoveToNextAttribute ());
  996. Assertion.Assert ("bar" == xmlReader.Name || "quux" == xmlReader.Name);
  997. Assertion.Assert ("baz" == xmlReader.Value || "quuux" == xmlReader.Value);
  998. Assertion.Assert (!xmlReader.MoveToNextAttribute ());
  999. Assertion.Assert (xmlReader.MoveToElement ());
  1000. AssertNodeValues (
  1001. xmlReader, // xmlReader
  1002. XmlNodeType.Element, // nodeType
  1003. 0, //depth
  1004. true, // isEmptyElement
  1005. "foo", // name
  1006. String.Empty, // prefix
  1007. "foo", // localName
  1008. String.Empty, // namespaceURI
  1009. String.Empty, // value
  1010. 2 // attributeCount
  1011. );
  1012. AssertEndDocument (xmlReader);
  1013. }
  1014. [Test]
  1015. public void AttributeOrder ()
  1016. {
  1017. string xml = @"<foo _1='1' _2='2' _3='3' />";
  1018. XmlReader xmlReader =
  1019. new XmlTextReader (new StringReader (xml));
  1020. Assertion.Assert (xmlReader.Read ());
  1021. Assertion.AssertEquals (XmlNodeType.Element, xmlReader.NodeType);
  1022. Assertion.Assert (xmlReader.MoveToFirstAttribute ());
  1023. Assertion.AssertEquals ("_1", xmlReader.Name);
  1024. Assertion.Assert (xmlReader.MoveToNextAttribute ());
  1025. Assertion.AssertEquals ("_2", xmlReader.Name);
  1026. Assertion.Assert (xmlReader.MoveToNextAttribute ());
  1027. Assertion.AssertEquals ("_3", xmlReader.Name);
  1028. Assertion.Assert (!xmlReader.MoveToNextAttribute ());
  1029. }
  1030. [Test]
  1031. public void FragmentConstructor()
  1032. {
  1033. XmlDocument doc = new XmlDocument();
  1034. // doc.LoadXml("<root/>");
  1035. string xml = @"<foo><bar xmlns=""NSURI"">TEXT NODE</bar></foo>";
  1036. MemoryStream ms = new MemoryStream(Encoding.Default.GetBytes(xml));
  1037. XmlParserContext ctx = new XmlParserContext(doc.NameTable, new XmlNamespaceManager(doc.NameTable), "", "", "", "",
  1038. doc.BaseURI, "", XmlSpace.Default, Encoding.Default);
  1039. XmlTextReader xmlReader = new XmlTextReader(ms, XmlNodeType.Element, ctx);
  1040. AssertNode(xmlReader, XmlNodeType.Element, 0, false, "foo", "", "foo", "", "", 0);
  1041. AssertNode(xmlReader, XmlNodeType.Element, 1, false, "bar", "", "bar", "NSURI", "", 1);
  1042. AssertNode(xmlReader, XmlNodeType.Text, 2, false, "", "", "", "NSURI", "TEXT NODE", 0);
  1043. AssertNode(xmlReader, XmlNodeType.EndElement, 1, false, "bar", "", "bar", "NSURI", "", 0);
  1044. AssertNode(xmlReader, XmlNodeType.EndElement, 0, false, "foo", "", "foo", "", "", 0);
  1045. AssertEndDocument (xmlReader);
  1046. }
  1047. [Test]
  1048. public void AttributeWithCharacterReference ()
  1049. {
  1050. string xml = @"<a value='hello &amp; world' />";
  1051. XmlReader xmlReader =
  1052. new XmlTextReader (new StringReader (xml));
  1053. xmlReader.Read ();
  1054. Assertion.AssertEquals ("hello & world", xmlReader ["value"]);
  1055. }
  1056. [Test]
  1057. public void AttributeWithEntityReference ()
  1058. {
  1059. string xml = @"<a value='hello &ent; world' />";
  1060. XmlReader xmlReader =
  1061. new XmlTextReader (new StringReader (xml));
  1062. xmlReader.Read ();
  1063. xmlReader.MoveToFirstAttribute ();
  1064. xmlReader.ReadAttributeValue ();
  1065. Assertion.AssertEquals ("hello ", xmlReader.Value);
  1066. xmlReader.ReadAttributeValue ();
  1067. Assertion.AssertEquals (XmlNodeType.EntityReference, xmlReader.NodeType);
  1068. Assertion.AssertEquals ("ent", xmlReader.Name);
  1069. Assertion.AssertEquals (XmlNodeType.EntityReference, xmlReader.NodeType);
  1070. xmlReader.ReadAttributeValue ();
  1071. Assertion.AssertEquals (" world", xmlReader.Value);
  1072. Assertion.AssertEquals (XmlNodeType.Text, xmlReader.NodeType);
  1073. xmlReader.ReadAttributeValue ();
  1074. Assertion.AssertEquals (XmlNodeType.None, xmlReader.NodeType);
  1075. xmlReader.ReadAttributeValue ();
  1076. Assertion.AssertEquals (XmlNodeType.None, xmlReader.NodeType);
  1077. }
  1078. [Test]
  1079. public void QuoteChar ()
  1080. {
  1081. string xml = @"<a value='hello &amp; world' value2="""" />";
  1082. XmlReader xmlReader =
  1083. new XmlTextReader (new StringReader (xml));
  1084. xmlReader.Read ();
  1085. xmlReader.MoveToFirstAttribute ();
  1086. Assertion.AssertEquals ("First", '\'', xmlReader.QuoteChar);
  1087. xmlReader.MoveToNextAttribute ();
  1088. Assertion.AssertEquals ("Next", '"', xmlReader.QuoteChar);
  1089. xmlReader.MoveToFirstAttribute ();
  1090. Assertion.AssertEquals ("First.Again", '\'', xmlReader.QuoteChar);
  1091. }
  1092. [Test]
  1093. public void ReadInnerXmlWrongInit ()
  1094. {
  1095. // This behavior is different from XmlNodeReader.
  1096. XmlReader reader = new XmlTextReader (new StringReader ("<root>test of <b>mixed</b> string.</root>"));
  1097. reader.ReadInnerXml ();
  1098. Assertion.AssertEquals ("initial.ReadState", ReadState.Initial, reader.ReadState);
  1099. Assertion.AssertEquals ("initial.EOF", false, reader.EOF);
  1100. Assertion.AssertEquals ("initial.NodeType", XmlNodeType.None, reader.NodeType);
  1101. }
  1102. }
  1103. }