PageRenderTime 43ms CodeModel.GetById 12ms RepoModel.GetById 0ms app.codeStats 0ms

/mcs/class/System.Xaml/Test/System.Xaml/XamlLanguageTest.cs

https://bitbucket.org/danipen/mono
C# | 865 lines | 653 code | 106 blank | 106 comment | 34 complexity | 4c21929898871db4cdb5c23d8da3a5fd MD5 | raw file
Possible License(s): Unlicense, Apache-2.0, LGPL-2.0, MPL-2.0-no-copyleft-exception, CC-BY-SA-3.0, GPL-2.0
  1. //
  2. // Copyright (C) 2010 Novell Inc. http://novell.com
  3. //
  4. // Permission is hereby granted, free of charge, to any person obtaining
  5. // a copy of this software and associated documentation files (the
  6. // "Software"), to deal in the Software without restriction, including
  7. // without limitation the rights to use, copy, modify, merge, publish,
  8. // distribute, sublicense, and/or sell copies of the Software, and to
  9. // permit persons to whom the Software is furnished to do so, subject to
  10. // the following conditions:
  11. //
  12. // The above copyright notice and this permission notice shall be
  13. // included in all copies or substantial portions of the Software.
  14. //
  15. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  16. // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  17. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  18. // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  19. // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  20. // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  21. // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  22. //
  23. using System;
  24. using System.Collections;
  25. using System.Collections.Generic;
  26. using System.ComponentModel;
  27. using System.Linq;
  28. using System.Reflection;
  29. using System.Windows.Markup;
  30. using System.Xaml;
  31. using System.Xaml.Schema;
  32. using System.Xml;
  33. using NUnit.Framework;
  34. using CategoryAttribute = NUnit.Framework.CategoryAttribute;
  35. namespace MonoTests.System.Xaml
  36. {
  37. [TestFixture]
  38. public class XamlLanguageTest
  39. {
  40. [Test]
  41. public void XamlNamepaces ()
  42. {
  43. var l = XamlLanguage.XamlNamespaces;
  44. Assert.AreEqual (1, l.Count, "#1");
  45. Assert.AreEqual (XamlLanguage.Xaml2006Namespace, l [0], "#2");
  46. }
  47. [Test]
  48. public void XmlNamepaces ()
  49. {
  50. var l = XamlLanguage.XmlNamespaces;
  51. Assert.AreEqual (1, l.Count, "#1");
  52. Assert.AreEqual (XamlLanguage.Xml1998Namespace, l [0], "#2");
  53. }
  54. [Test]
  55. public void AllDirectives ()
  56. {
  57. var l = XamlLanguage.AllDirectives;
  58. Assert.AreEqual (24, l.Count, "count");
  59. Assert.IsTrue (l.Contains (XamlLanguage.Arguments), "#0");
  60. Assert.IsTrue (l.Contains (XamlLanguage.AsyncRecords), "#1");
  61. Assert.IsTrue (l.Contains (XamlLanguage.Base), "#2");
  62. Assert.IsTrue (l.Contains (XamlLanguage.Class), "#3");
  63. Assert.IsTrue (l.Contains (XamlLanguage.ClassAttributes), "#4");
  64. Assert.IsTrue (l.Contains (XamlLanguage.ClassModifier), "#5");
  65. Assert.IsTrue (l.Contains (XamlLanguage.Code), "#6");
  66. Assert.IsTrue (l.Contains (XamlLanguage.ConnectionId), "#7");
  67. Assert.IsTrue (l.Contains (XamlLanguage.FactoryMethod), "#8");
  68. Assert.IsTrue (l.Contains (XamlLanguage.FieldModifier), "#9");
  69. Assert.IsTrue (l.Contains (XamlLanguage.Initialization), "#10");
  70. Assert.IsTrue (l.Contains (XamlLanguage.Items), "#11");
  71. Assert.IsTrue (l.Contains (XamlLanguage.Key), "#12");
  72. Assert.IsTrue (l.Contains (XamlLanguage.Lang), "#13");
  73. Assert.IsTrue (l.Contains (XamlLanguage.Members), "#14");
  74. Assert.IsTrue (l.Contains (XamlLanguage.Name), "#15");
  75. Assert.IsTrue (l.Contains (XamlLanguage.PositionalParameters), "#16");
  76. Assert.IsTrue (l.Contains (XamlLanguage.Space), "#17");
  77. Assert.IsTrue (l.Contains (XamlLanguage.Subclass), "#18");
  78. Assert.IsTrue (l.Contains (XamlLanguage.SynchronousMode), "#19");
  79. Assert.IsTrue (l.Contains (XamlLanguage.Shared), "#20");
  80. Assert.IsTrue (l.Contains (XamlLanguage.TypeArguments), "#21");
  81. Assert.IsTrue (l.Contains (XamlLanguage.Uid), "#22");
  82. Assert.IsTrue (l.Contains (XamlLanguage.UnknownContent), "#23");
  83. }
  84. [Test]
  85. public void AllTypes ()
  86. {
  87. var l = XamlLanguage.AllTypes;
  88. Assert.AreEqual (21, l.Count, "count");
  89. Assert.IsTrue (l.Contains (XamlLanguage.Array), "#0");
  90. Assert.IsTrue (l.Contains (XamlLanguage.Boolean), "#1");
  91. Assert.IsTrue (l.Contains (XamlLanguage.Byte), "#2");
  92. Assert.IsTrue (l.Contains (XamlLanguage.Char), "#3");
  93. Assert.IsTrue (l.Contains (XamlLanguage.Decimal), "#4");
  94. Assert.IsTrue (l.Contains (XamlLanguage.Double), "#5");
  95. Assert.IsTrue (l.Contains (XamlLanguage.Int16), "#6");
  96. Assert.IsTrue (l.Contains (XamlLanguage.Int32), "#7");
  97. Assert.IsTrue (l.Contains (XamlLanguage.Int64), "#8");
  98. Assert.IsTrue (l.Contains (XamlLanguage.Member), "#9");
  99. Assert.IsTrue (l.Contains (XamlLanguage.Null), "#10");
  100. Assert.IsTrue (l.Contains (XamlLanguage.Object), "#11");
  101. Assert.IsTrue (l.Contains (XamlLanguage.Property), "#12");
  102. Assert.IsTrue (l.Contains (XamlLanguage.Reference), "#13");
  103. Assert.IsTrue (l.Contains (XamlLanguage.Single), "#14");
  104. Assert.IsTrue (l.Contains (XamlLanguage.Static), "#15");
  105. Assert.IsTrue (l.Contains (XamlLanguage.String), "#16");
  106. Assert.IsTrue (l.Contains (XamlLanguage.TimeSpan), "#17");
  107. Assert.IsTrue (l.Contains (XamlLanguage.Type), "#18");
  108. Assert.IsTrue (l.Contains (XamlLanguage.Uri), "#19");
  109. Assert.IsTrue (l.Contains (XamlLanguage.XData), "#20");
  110. }
  111. // directive property details
  112. [Test]
  113. public void Arguments ()
  114. {
  115. var d = XamlLanguage.Arguments;
  116. TestXamlDirectiveCommon (d, "Arguments", AllowedMemberLocations.Any, typeof (List<object>));
  117. }
  118. [Test]
  119. public void AsyncRecords ()
  120. {
  121. var d = XamlLanguage.AsyncRecords;
  122. TestXamlDirectiveCommon (d, "AsyncRecords", AllowedMemberLocations.Attribute, typeof (string));
  123. }
  124. [Test]
  125. public void Base ()
  126. {
  127. var d = XamlLanguage.Base;
  128. TestXamlDirectiveCommon (d, "base", XamlLanguage.Xml1998Namespace, AllowedMemberLocations.Attribute, typeof (string));
  129. }
  130. [Test]
  131. public void Class ()
  132. {
  133. var d = XamlLanguage.Class;
  134. TestXamlDirectiveCommon (d, "Class", AllowedMemberLocations.Attribute, typeof (string));
  135. }
  136. [Test]
  137. public void ClassAttributes ()
  138. {
  139. var d = XamlLanguage.ClassAttributes;
  140. TestXamlDirectiveCommon (d, "ClassAttributes", AllowedMemberLocations.MemberElement, typeof (List<Attribute>));
  141. }
  142. [Test]
  143. public void ClassModifier ()
  144. {
  145. var d = XamlLanguage.ClassModifier;
  146. TestXamlDirectiveCommon (d, "ClassModifier", AllowedMemberLocations.Attribute, typeof (string));
  147. }
  148. [Test]
  149. public void Code ()
  150. {
  151. var d = XamlLanguage.Code;
  152. TestXamlDirectiveCommon (d, "Code", AllowedMemberLocations.Attribute, typeof (string));
  153. }
  154. [Test]
  155. public void ConnectionId ()
  156. {
  157. var d = XamlLanguage.ConnectionId;
  158. TestXamlDirectiveCommon (d, "ConnectionId", AllowedMemberLocations.Any, typeof (string));
  159. }
  160. [Test]
  161. public void FactoryMethod ()
  162. {
  163. var d = XamlLanguage.FactoryMethod;
  164. TestXamlDirectiveCommon (d, "FactoryMethod", AllowedMemberLocations.Any, typeof (string));
  165. }
  166. [Test]
  167. public void FieldModifier ()
  168. {
  169. var d = XamlLanguage.FieldModifier;
  170. TestXamlDirectiveCommon (d, "FieldModifier", AllowedMemberLocations.Attribute, typeof (string));
  171. }
  172. [Test]
  173. public void Initialization ()
  174. {
  175. var d = XamlLanguage.Initialization;
  176. // weird name
  177. TestXamlDirectiveCommon (d, "_Initialization", AllowedMemberLocations.Any, typeof (object));
  178. }
  179. [Test]
  180. [ExpectedException (typeof (NotSupportedException))]
  181. public void InitializationGetValue ()
  182. {
  183. XamlLanguage.Initialization.Invoker.GetValue ("foo");
  184. }
  185. [Test]
  186. public void Items ()
  187. {
  188. var d = XamlLanguage.Items;
  189. // weird name
  190. TestXamlDirectiveCommon (d, "_Items", AllowedMemberLocations.Any, typeof (List<object>));
  191. }
  192. [Test]
  193. public void Key ()
  194. {
  195. var d = XamlLanguage.Key;
  196. TestXamlDirectiveCommon (d, "Key", AllowedMemberLocations.Any, typeof (object));
  197. }
  198. [Test]
  199. public void Lang ()
  200. {
  201. var d = XamlLanguage.Lang;
  202. TestXamlDirectiveCommon (d, "lang", XamlLanguage.Xml1998Namespace, AllowedMemberLocations.Attribute, typeof (string));
  203. }
  204. [Test]
  205. public void Members ()
  206. {
  207. var d = XamlLanguage.Members;
  208. TestXamlDirectiveCommon (d, "Members", AllowedMemberLocations.MemberElement, typeof (List<MemberDefinition>));
  209. }
  210. [Test]
  211. public void Name ()
  212. {
  213. var d = XamlLanguage.Name;
  214. TestXamlDirectiveCommon (d, "Name", AllowedMemberLocations.Attribute, typeof (string));
  215. }
  216. [Test]
  217. public void PositionalParameters ()
  218. {
  219. var d = XamlLanguage.PositionalParameters;
  220. // weird name
  221. TestXamlDirectiveCommon (d, "_PositionalParameters", AllowedMemberLocations.Any, typeof (List<object>));
  222. // LAMESPEC: In [MS-XAML-2009] AllowedLocations is None, unlike this Any value.
  223. }
  224. [Test]
  225. public void Subclass ()
  226. {
  227. var d = XamlLanguage.Subclass;
  228. TestXamlDirectiveCommon (d, "Subclass", AllowedMemberLocations.Attribute, typeof (string));
  229. }
  230. [Test]
  231. public void SynchronousMode ()
  232. {
  233. var d = XamlLanguage.SynchronousMode;
  234. TestXamlDirectiveCommon (d, "SynchronousMode", AllowedMemberLocations.Attribute, typeof (string));
  235. }
  236. [Test]
  237. public void Shared ()
  238. {
  239. var d = XamlLanguage.Shared;
  240. TestXamlDirectiveCommon (d, "Shared", AllowedMemberLocations.Attribute, typeof (string));
  241. }
  242. [Test]
  243. public void Space ()
  244. {
  245. var d = XamlLanguage.Space;
  246. TestXamlDirectiveCommon (d, "space", XamlLanguage.Xml1998Namespace, AllowedMemberLocations.Attribute, typeof (string));
  247. }
  248. [Test]
  249. public void TypeArguments ()
  250. {
  251. var d = XamlLanguage.TypeArguments;
  252. TestXamlDirectiveCommon (d, "TypeArguments", AllowedMemberLocations.Attribute, typeof (string));
  253. }
  254. [Test]
  255. public void Uid ()
  256. {
  257. var d = XamlLanguage.Uid;
  258. TestXamlDirectiveCommon (d, "Uid", AllowedMemberLocations.Attribute, typeof (string));
  259. }
  260. [Test]
  261. public void UnknownContent ()
  262. {
  263. var d = XamlLanguage.UnknownContent;
  264. // weird name
  265. TestXamlDirectiveCommon (d, "_UnknownContent", XamlLanguage.Xaml2006Namespace, AllowedMemberLocations.MemberElement, typeof (object), true);
  266. }
  267. void TestXamlDirectiveCommon (XamlDirective d, string name, AllowedMemberLocations allowedLocation, Type type)
  268. {
  269. TestXamlDirectiveCommon (d, name, XamlLanguage.Xaml2006Namespace, allowedLocation, type);
  270. }
  271. void TestXamlDirectiveCommon (XamlDirective d, string name, string ns, AllowedMemberLocations allowedLocation, Type type)
  272. {
  273. TestXamlDirectiveCommon (d, name, ns, allowedLocation, type, false);
  274. }
  275. void TestXamlDirectiveCommon (XamlDirective d, string name, string ns, AllowedMemberLocations allowedLocation, Type type, bool isUnknown)
  276. {
  277. Assert.AreEqual (allowedLocation, d.AllowedLocation, "#1");
  278. Assert.IsNull (d.DeclaringType, "#2");
  279. Assert.IsNotNull (d.Invoker, "#3");
  280. Assert.IsNull (d.Invoker.UnderlyingGetter, "#3-2");
  281. Assert.IsNull (d.Invoker.UnderlyingSetter, "#3-3");
  282. Assert.AreEqual (isUnknown, d.IsUnknown, "#4");
  283. Assert.IsTrue (d.IsReadPublic, "#5");
  284. Assert.IsTrue (d.IsWritePublic, "#6");
  285. Assert.AreEqual (name, d.Name, "#7");
  286. Assert.IsTrue (d.IsNameValid, "#8");
  287. Assert.AreEqual (ns, d.PreferredXamlNamespace, "#9");
  288. Assert.IsNull (d.TargetType, "#10");
  289. Assert.IsNotNull (d.Type, "#11");
  290. Assert.AreEqual (type, d.Type.UnderlyingType, "#11-2");
  291. // .NET returns StringConverter, but it should not premise that key must be string (it is object)
  292. if (name == "Key")
  293. ;//Assert.IsNull (d.TypeConverter, "#12")
  294. else if (type.IsGenericType || name == "_Initialization" || name == "_UnknownContent")
  295. Assert.IsNull (d.TypeConverter, "#12");
  296. else
  297. Assert.IsNotNull (d.TypeConverter, "#12");
  298. Assert.IsNull (d.ValueSerializer, "#13");
  299. Assert.IsNull (d.DeferringLoader, "#14");
  300. Assert.IsNull (d.UnderlyingMember, "#15");
  301. Assert.IsFalse (d.IsReadOnly, "#16");
  302. Assert.IsFalse (d.IsWriteOnly, "#17");
  303. Assert.IsFalse (d.IsAttachable, "#18");
  304. Assert.IsFalse (d.IsEvent, "#19");
  305. Assert.IsTrue (d.IsDirective, "#20");
  306. Assert.IsNotNull (d.DependsOn, "#21");
  307. Assert.AreEqual (0, d.DependsOn.Count, "#21-2");
  308. Assert.IsFalse (d.IsAmbient, "#22");
  309. Assert.AreEqual (DesignerSerializationVisibility.Visible, d.SerializationVisibility, "#23");
  310. }
  311. // type property details
  312. // extension types
  313. [Test]
  314. public void Array ()
  315. {
  316. var t = XamlLanguage.Array;
  317. TestXamlTypeExtension (t, "ArrayExtension", typeof (ArrayExtension), typeof (Array), true);
  318. Assert.IsNotNull (t.ContentProperty, "#27");
  319. Assert.AreEqual ("Items", t.ContentProperty.Name, "#27-2");
  320. var l = t.GetAllMembers ().ToArray ();
  321. Assert.AreEqual (2, l.Length, "#31");
  322. var items = l.First (m => m.Name == "Items");
  323. Assert.IsFalse (items == XamlLanguage.Items, "#31-2");
  324. l.First (m => m.Name == "Type");
  325. l = t.GetAllAttachableMembers ().ToArray ();
  326. Assert.AreEqual (0, l.Length, "#32");
  327. }
  328. [Test]
  329. public void Array_Items ()
  330. {
  331. var m = XamlLanguage.Array.GetMember ("Items");
  332. TestMemberCommon (m, "Items", typeof (IList), typeof (ArrayExtension), false);
  333. }
  334. [Test]
  335. public void Array_Type ()
  336. {
  337. var m = XamlLanguage.Array.GetMember ("Type");
  338. TestMemberCommon (m, "Type", typeof (Type), typeof (ArrayExtension), true);
  339. }
  340. [Test]
  341. public void Null ()
  342. {
  343. var t = XamlLanguage.Null;
  344. TestXamlTypeExtension (t, "NullExtension", typeof (NullExtension), typeof (object), true);
  345. Assert.IsNull (t.ContentProperty, "#27");
  346. var l = t.GetAllMembers ().ToArray ();
  347. Assert.AreEqual (0, l.Length, "#31");
  348. l = t.GetAllAttachableMembers ().ToArray ();
  349. Assert.AreEqual (0, l.Length, "#32");
  350. }
  351. [Test]
  352. public void Static ()
  353. {
  354. var t = XamlLanguage.Static;
  355. TestXamlTypeExtension (t, "StaticExtension", typeof (StaticExtension), typeof (object), false);
  356. var tc = t.TypeConverter.ConverterInstance;
  357. Assert.IsNotNull (tc, "#25-2");
  358. Assert.IsFalse (tc.CanConvertFrom (typeof (string)), "#25-3");
  359. Assert.IsTrue (tc.CanConvertTo (typeof (string)), "#25-4");
  360. Assert.IsNull (t.ContentProperty, "#27");
  361. var l = t.GetAllMembers ().ToArray ();
  362. Assert.AreEqual (2, l.Length, "#31");
  363. l.First (m => m.Name == "Member");
  364. l.First (m => m.Name == "MemberType");
  365. l = t.GetAllAttachableMembers ().ToArray ();
  366. Assert.AreEqual (0, l.Length, "#32");
  367. }
  368. [Test]
  369. public void Static_Member ()
  370. {
  371. var m = XamlLanguage.Static.GetMember ("Member");
  372. TestMemberCommon (m, "Member", typeof (string), typeof (StaticExtension), true);
  373. }
  374. [Test]
  375. public void Static_MemberType ()
  376. {
  377. var m = XamlLanguage.Static.GetMember ("MemberType");
  378. TestMemberCommon (m, "MemberType", typeof (Type), typeof (StaticExtension), true);
  379. }
  380. [Test]
  381. public void Type ()
  382. {
  383. var t = XamlLanguage.Type;
  384. TestXamlTypeExtension (t, "TypeExtension", typeof (TypeExtension), typeof (Type), false);
  385. Assert.IsNotNull (t.TypeConverter.ConverterInstance, "#25-2");
  386. Assert.IsNull (t.ContentProperty, "#27");
  387. var l = t.GetAllMembers ().ToArray ();
  388. Assert.AreEqual (2, l.Length, "#31");
  389. l.First (m => m.Name == "TypeName");
  390. l.First (m => m.Name == "Type");
  391. l = t.GetAllAttachableMembers ().ToArray ();
  392. Assert.AreEqual (0, l.Length, "#32");
  393. }
  394. [Test]
  395. public void Type_TypeName ()
  396. {
  397. var m = XamlLanguage.Type.GetMember ("TypeName");
  398. TestMemberCommon (m, "TypeName", typeof (string), typeof (TypeExtension), true);
  399. }
  400. [Test]
  401. public void Type_Type ()
  402. {
  403. var m = XamlLanguage.Type.GetMember ("Type");
  404. TestMemberCommon (m, "Type", typeof (Type), typeof (TypeExtension), true);
  405. Assert.AreNotEqual (XamlLanguage.Type, m.Type, "#1");
  406. }
  407. // primitive types
  408. [Test]
  409. public void Byte ()
  410. {
  411. var t = XamlLanguage.Byte;
  412. TestXamlTypePrimitive (t, "Byte", typeof (byte), false, false);
  413. /* Those properties are pointless regarding practical use. Those "members" does not participate in serialization.
  414. var l = t.GetAllAttachableMembers ().ToArray ();
  415. Assert.AreEqual (1, l.Length, "#32");
  416. */
  417. }
  418. [Test]
  419. public void Char ()
  420. {
  421. var t = XamlLanguage.Char;
  422. TestXamlTypePrimitive (t, "Char", typeof (char), false, false);
  423. /* Those properties are pointless regarding practical use. Those "members" does not participate in serialization.
  424. var l = t.GetAllAttachableMembers ().ToArray ();
  425. Assert.AreEqual (3, l.Length, "#32");
  426. l.First (m => m.Name == "UnicodeCategory");
  427. l.First (m => m.Name == "NumericValue");
  428. l.First (m => m.Name == "HashCodeOfPtr");
  429. */
  430. }
  431. [Test]
  432. public void Decimal ()
  433. {
  434. var t = XamlLanguage.Decimal;
  435. TestXamlTypePrimitive (t, "Decimal", typeof (decimal), false, false);
  436. /* Those properties are pointless regarding practical use. Those "members" does not participate in serialization.
  437. var l = t.GetAllAttachableMembers ().ToArray ();
  438. Assert.AreEqual (2, l.Length, "#32");
  439. l.First (m => m.Name == "Bits");
  440. l.First (m => m.Name == "HashCodeOfPtr");
  441. */
  442. }
  443. [Test]
  444. public void Double ()
  445. {
  446. var t = XamlLanguage.Double;
  447. TestXamlTypePrimitive (t, "Double", typeof (double), false, false);
  448. /* Those properties are pointless regarding practical use. Those "members" does not participate in serialization.
  449. var l = t.GetAllAttachableMembers ().ToArray ();
  450. Assert.AreEqual (1, l.Length, "#32");
  451. l.First (m => m.Name == "HashCodeOfPtr");
  452. */
  453. }
  454. [Test]
  455. public void Int16 ()
  456. {
  457. var t = XamlLanguage.Int16;
  458. TestXamlTypePrimitive (t, "Int16", typeof (short), false, false);
  459. /* Those properties are pointless regarding practical use. Those "members" does not participate in serialization.
  460. var l = t.GetAllAttachableMembers ().ToArray ();
  461. Assert.AreEqual (1, l.Length, "#32");
  462. l.First (m => m.Name == "HashCodeOfPtr");
  463. */
  464. }
  465. [Test]
  466. public void Int32 ()
  467. {
  468. var t = XamlLanguage.Int32;
  469. TestXamlTypePrimitive (t, "Int32", typeof (int), false, false);
  470. try {
  471. t.Invoker.CreateInstance (new object [] {1});
  472. Assert.Fail ("Should expect .ctor() and fail");
  473. } catch (MissingMethodException) {
  474. }
  475. /* Those properties are pointless regarding practical use. Those "members" does not participate in serialization.
  476. var l = t.GetAllAttachableMembers ().ToArray ();
  477. Assert.AreEqual (1, l.Length, "#32");
  478. l.First (m => m.Name == "HashCodeOfPtr");
  479. */
  480. }
  481. [Test]
  482. public void Int64 ()
  483. {
  484. var t = XamlLanguage.Int64;
  485. TestXamlTypePrimitive (t, "Int64", typeof (long), false, false);
  486. /* Those properties are pointless regarding practical use. Those "members" does not participate in serialization.
  487. var l = t.GetAllAttachableMembers ().ToArray ();
  488. Assert.AreEqual (1, l.Length, "#32");
  489. l.First (m => m.Name == "HashCodeOfPtr");
  490. */
  491. }
  492. [Test]
  493. public void Object ()
  494. {
  495. var t = XamlLanguage.Object;
  496. TestXamlTypePrimitive (t, "Object", typeof (object), true, false);
  497. Assert.IsNull (t.BaseType, "#x1");
  498. /* Those properties are pointless regarding practical use. Those "members" does not participate in serialization.
  499. var l = t.GetAllAttachableMembers ().ToArray ();
  500. Assert.AreEqual (0, l.Length, "#32");
  501. */
  502. }
  503. [Test]
  504. public void Single ()
  505. {
  506. var t = XamlLanguage.Single;
  507. TestXamlTypePrimitive (t, "Single", typeof (float), false, false);
  508. /* Those properties are pointless regarding practical use. Those "members" does not participate in serialization.
  509. var l = t.GetAllAttachableMembers ().ToArray ();
  510. Assert.AreEqual (1, l.Length, "#32");
  511. l.First (m => m.Name == "HashCodeOfPtr");
  512. */
  513. }
  514. [Test]
  515. public void String ()
  516. {
  517. var t = XamlLanguage.String;
  518. TestXamlTypePrimitive (t, "String", typeof (string), true, true);
  519. Assert.IsNotNull (XamlLanguage.AllTypes.First (tt => tt.Name == "String").ValueSerializer, "#x");
  520. Assert.IsNotNull (XamlLanguage.String.ValueSerializer, "#y");
  521. try {
  522. t.Invoker.CreateInstance (new object [] {"foo"});
  523. Assert.Fail ("Should expect .ctor() and fail");
  524. } catch (MissingMethodException) {
  525. }
  526. /* Those properties are pointless regarding practical use. Those "members" does not participate in serialization.
  527. var l = t.GetAllAttachableMembers ().ToArray ();
  528. Assert.AreEqual (0, l.Length, "#32");
  529. */
  530. }
  531. [Test]
  532. public void TimeSpan ()
  533. {
  534. var t = XamlLanguage.TimeSpan;
  535. TestXamlTypePrimitive (t, "TimeSpan", typeof (TimeSpan), false, false);
  536. /* Those properties are pointless regarding practical use. Those "members" does not participate in serialization.
  537. var l = t.GetAllAttachableMembers ().ToArray ();
  538. Assert.AreEqual (1, l.Length, "#32");
  539. l.First (m => m.Name == "HashCodeOfPtr");
  540. */
  541. }
  542. [Test]
  543. public void Uri ()
  544. {
  545. var t = XamlLanguage.Uri;
  546. TestXamlTypePrimitive (t, "Uri", typeof (Uri), true, true);
  547. /* Those properties are pointless regarding practical use. Those "members" does not participate in serialization.
  548. var l = t.GetAllAttachableMembers ().ToArray ();
  549. Assert.AreEqual (0, l.Length, "#32");
  550. */
  551. }
  552. // miscellaneous
  553. [Test]
  554. public void Member ()
  555. {
  556. var t = XamlLanguage.Member;
  557. TestXamlTypeCommon (t, "Member", typeof (MemberDefinition), true, true, false);
  558. Assert.IsNull (t.TypeConverter, "#25");
  559. // FIXME: test remaining members
  560. var l = t.GetAllMembers ().ToArray ();
  561. Assert.AreEqual (1, l.Length, "#31");
  562. l.First (m => m.Name == "Name");
  563. }
  564. [Test]
  565. public void Member_Name ()
  566. {
  567. var m = XamlLanguage.Member.GetMember ("Name");
  568. TestMemberCommon (m, "Name", typeof (string), typeof (MemberDefinition), true);
  569. }
  570. [Test]
  571. public void Property ()
  572. {
  573. var t = XamlLanguage.Property;
  574. TestXamlTypeCommon (t, "Property", typeof (PropertyDefinition), true);
  575. Assert.IsNull (t.TypeConverter, "#25");
  576. // FIXME: test remaining members
  577. var l = t.GetAllMembers ().ToArray ();
  578. Assert.AreEqual (4, l.Length, "#31");
  579. l.First (m => m.Name == "Name");
  580. l.First (m => m.Name == "Type");
  581. l.First (m => m.Name == "Modifier");
  582. l.First (m => m.Name == "Attributes");
  583. }
  584. [Test]
  585. public void Property_Name ()
  586. {
  587. var m = XamlLanguage.Property.GetMember ("Name");
  588. TestMemberCommon (m, "Name", typeof (string), typeof (PropertyDefinition), true);
  589. }
  590. [Test]
  591. public void Property_Type ()
  592. {
  593. var m = XamlLanguage.Property.GetMember ("Type");
  594. TestMemberCommon (m, "Type", typeof (XamlType), typeof (PropertyDefinition), true);
  595. Assert.IsNotNull (m.TypeConverter, "#1");
  596. Assert.IsNull (m.ValueSerializer, "#2");
  597. }
  598. [Test]
  599. public void Property_Modifier ()
  600. {
  601. var m = XamlLanguage.Property.GetMember ("Modifier");
  602. TestMemberCommon (m, "Modifier", typeof (string), typeof (PropertyDefinition), true);
  603. }
  604. [Test]
  605. public void Property_Attributes ()
  606. {
  607. var m = XamlLanguage.Property.GetMember ("Attributes");
  608. TestMemberCommon (m, "Attributes", typeof (IList<Attribute>), typeof (PropertyDefinition), false);
  609. }
  610. [Test]
  611. public void Reference ()
  612. {
  613. var t = XamlLanguage.Reference;
  614. TestXamlTypeCommon (t, "Reference", typeof (Reference), true);
  615. Assert.IsNull (t.TypeConverter, "#25");
  616. // FIXME: test remaining members
  617. var l = t.GetAllMembers ().ToArray ();
  618. Assert.AreEqual (1, l.Length, "#31");
  619. l.First (m => m.Name == "Name");
  620. Assert.AreEqual (l [0], t.ContentProperty, "#32");
  621. }
  622. [Test]
  623. public void Reference_Name ()
  624. {
  625. var m = XamlLanguage.Reference.GetMember ("Name");
  626. TestMemberCommon (m, "Name", typeof (string), typeof (Reference), true);
  627. }
  628. [Test]
  629. public void XData ()
  630. {
  631. var t = XamlLanguage.XData;
  632. TestXamlTypeCommon (t, "XData", typeof (XData), true);
  633. Assert.IsNull (t.TypeConverter, "#25");
  634. // FIXME: test remaining members
  635. var l = t.GetAllMembers ().ToArray ();
  636. Assert.AreEqual (2, l.Length, "#31");
  637. l.First (m => m.Name == "Text");
  638. l.First (m => m.Name == "XmlReader");
  639. }
  640. [Test]
  641. public void XData_Text ()
  642. {
  643. var m = XamlLanguage.XData.GetMember ("Text");
  644. TestMemberCommon (m, "Text", typeof (string), typeof (XData), true);
  645. }
  646. [Test]
  647. public void XData_XmlReader ()
  648. {
  649. var m = XamlLanguage.XData.GetMember ("XmlReader");
  650. // it does not use XmlReader type ...
  651. TestMemberCommon (m, "XmlReader", typeof (object), typeof (XData), true);
  652. }
  653. // common test methods
  654. void TestXamlTypeCommon (XamlType t, string name, Type underlyingType, bool nullable)
  655. {
  656. TestXamlTypeCommon (t, name, underlyingType, nullable, false);
  657. }
  658. void TestXamlTypeCommon (XamlType t, string name, Type underlyingType, bool nullable, bool constructionRequiresArguments)
  659. {
  660. TestXamlTypeCommon (t, name, underlyingType, nullable, constructionRequiresArguments, true);
  661. }
  662. void TestXamlTypeCommon (XamlType t, string name, Type underlyingType, bool nullable, bool constructionRequiresArguments, bool isConstructible)
  663. {
  664. Assert.IsNotNull (t.Invoker, "#1");
  665. Assert.IsTrue (t.IsNameValid, "#2");
  666. Assert.IsFalse (t.IsUnknown, "#3");
  667. // FIXME: test names (some extension types have wrong name.
  668. //Assert.AreEqual (name, t.Name, "#4");
  669. Assert.AreEqual (XamlLanguage.Xaml2006Namespace, t.PreferredXamlNamespace, "#5");
  670. Assert.IsNull (t.TypeArguments, "#6");
  671. Assert.AreEqual (underlyingType, t.UnderlyingType, "#7");
  672. Assert.AreEqual (constructionRequiresArguments, t.ConstructionRequiresArguments, "#8");
  673. Assert.IsFalse (t.IsArray, "#9");
  674. Assert.IsFalse (t.IsCollection, "#10");
  675. // FIXME: test here (very inconsistent with the spec)
  676. Assert.AreEqual (isConstructible, t.IsConstructible, "#11");
  677. Assert.IsFalse (t.IsDictionary, "#12");
  678. Assert.IsFalse (t.IsGeneric, "#13");
  679. Assert.IsFalse (t.IsNameScope, "#15");
  680. Assert.AreEqual (nullable, t.IsNullable, "#16");
  681. Assert.IsTrue (t.IsPublic, "#17");
  682. Assert.IsFalse (t.IsUsableDuringInitialization, "#18");
  683. Assert.IsFalse (t.IsWhitespaceSignificantCollection, "#19");
  684. Assert.IsFalse (t.IsXData, "#20");
  685. Assert.IsFalse (t.TrimSurroundingWhitespace, "#21");
  686. Assert.IsFalse (t.IsAmbient, "#22");
  687. Assert.IsNull (t.AllowedContentTypes, "#23");
  688. Assert.IsNull (t.ContentWrappers, "#24");
  689. // string is a special case.
  690. if (t == XamlLanguage.String)
  691. Assert.IsNotNull (t.ValueSerializer, "#26");
  692. else
  693. Assert.IsNull (t.ValueSerializer, "#26");
  694. //Assert.IsNull (t.DeferringLoader, "#28");
  695. }
  696. void TestXamlTypePrimitive (XamlType t, string name, Type underlyingType, bool nullable, bool constructorRequiresArguments)
  697. {
  698. TestXamlTypeCommon (t, name, underlyingType, nullable, constructorRequiresArguments);
  699. Assert.IsFalse (t.IsMarkupExtension, "#14");
  700. Assert.IsNotNull (t.TypeConverter, "#25");
  701. Assert.IsNull (t.ContentProperty, "#27");
  702. Assert.IsNull (t.MarkupExtensionReturnType, "#29");
  703. var l = t.GetAllMembers ().ToArray ();
  704. Assert.AreEqual (0, l.Length, "#31");
  705. }
  706. void TestXamlTypeExtension (XamlType t, string name, Type underlyingType, Type extReturnType, bool noTypeConverter)
  707. {
  708. TestXamlTypeCommon (t, name, underlyingType, true, false);
  709. Assert.IsTrue (t.IsMarkupExtension, "#14");
  710. if (noTypeConverter)
  711. Assert.IsNull (t.TypeConverter, "#25");
  712. else
  713. Assert.IsNotNull (t.TypeConverter, "#25");
  714. Assert.IsNotNull (t.MarkupExtensionReturnType, "#29");
  715. Assert.AreEqual (extReturnType, t.MarkupExtensionReturnType.UnderlyingType, "#29-2");
  716. Assert.IsNull (t.Invoker.SetMarkupExtensionHandler, "#31"); // orly?
  717. }
  718. void TestMemberCommon (XamlMember m, string name, Type type, Type declType, bool hasSetter)
  719. {
  720. Assert.IsNotNull (m, "#1");
  721. Assert.IsNotNull (m.DeclaringType, "#2");
  722. Assert.AreEqual (declType, m.DeclaringType.UnderlyingType, "#2-2");
  723. Assert.IsNotNull (m.Invoker, "#3");
  724. Assert.IsNotNull (m.Invoker.UnderlyingGetter, "#3-2");
  725. if (hasSetter)
  726. Assert.IsNotNull (m.Invoker.UnderlyingSetter, "#3-3");
  727. else
  728. Assert.IsNull (m.Invoker.UnderlyingSetter, "#3-3");
  729. Assert.IsFalse (m.IsUnknown, "#4");
  730. Assert.IsTrue (m.IsReadPublic, "#5");
  731. Assert.AreEqual (hasSetter, m.IsWritePublic, "#6");
  732. Assert.AreEqual (name, m.Name, "#7");
  733. Assert.IsTrue (m.IsNameValid, "#8");
  734. Assert.AreEqual (XamlLanguage.Xaml2006Namespace, m.PreferredXamlNamespace, "#9");
  735. // use declType here (mostly identical to targetType)
  736. Assert.AreEqual (new XamlType (declType, m.TargetType.SchemaContext), m.TargetType, "#10");
  737. Assert.IsNotNull (m.Type, "#11");
  738. Assert.AreEqual (type, m.Type.UnderlyingType, "#11-2");
  739. // Property.Type is a special case here.
  740. if (name == "Type" && m.DeclaringType != XamlLanguage.Property)
  741. Assert.AreEqual (m.Type.TypeConverter, m.TypeConverter, "#12");
  742. // String type is a special case here.
  743. if (type == typeof (string))
  744. Assert.AreEqual (m.Type.ValueSerializer, m.ValueSerializer, "#13a");
  745. else
  746. Assert.IsNull (m.ValueSerializer, "#13b");
  747. Assert.IsNull (m.DeferringLoader, "#14");
  748. Assert.IsNotNull (m.UnderlyingMember, "#15");
  749. Assert.AreEqual (!hasSetter, m.IsReadOnly, "#16");
  750. Assert.IsFalse (m.IsWriteOnly, "#17");
  751. Assert.IsFalse (m.IsAttachable, "#18");
  752. Assert.IsFalse (m.IsEvent, "#19");
  753. Assert.IsFalse (m.IsDirective, "#20");
  754. Assert.IsNotNull (m.DependsOn, "#21");
  755. Assert.AreEqual (0, m.DependsOn.Count, "#21-2");
  756. Assert.IsFalse (m.IsAmbient, "#22");
  757. }
  758. }
  759. }