diff --git a/mcs/class/System.Xaml/ChangeLog b/mcs/class/System.Xaml/ChangeLog index f821b3b52659..a6cd5b74afc0 100644 --- a/mcs/class/System.Xaml/ChangeLog +++ b/mcs/class/System.Xaml/ChangeLog @@ -1,3 +1,7 @@ +2010-04-09 Atsushi Enomoto + + * System.Xaml_test.dll.sources : add XamlLanguageTest.cs. + 2010-04-09 Atsushi Enomoto * System.Xaml.dll.sources diff --git a/mcs/class/System.Xaml/System.Windows.Markup/ArrayExtension.cs b/mcs/class/System.Xaml/System.Windows.Markup/ArrayExtension.cs index f853083180b7..7a1425a13a47 100755 --- a/mcs/class/System.Xaml/System.Windows.Markup/ArrayExtension.cs +++ b/mcs/class/System.Xaml/System.Windows.Markup/ArrayExtension.cs @@ -34,6 +34,29 @@ namespace System.Windows.Markup [ContentProperty ("Items")] public class ArrayExtension : MarkupExtension { + public ArrayExtension () + { + Items = new List (); + } + + public ArrayExtension (Array elements) + { + if (elements == null) + throw new ArgumentNullException ("elements"); + Items = elements; + } + + public ArrayExtension (Type arrayType) + { + if (arrayType == null) + throw new ArgumentNullException ("arrayType"); + Type = arrayType; + Items = (IList) Activator.CreateInstance (typeof (List<>).MakeGenericType (arrayType), new object [0]); + } + + public IList Items { get; private set; } + public Type Type { get; set; } + public void AddChild (Object value) { throw new NotImplementedException (); diff --git a/mcs/class/System.Xaml/System.Windows.Markup/ChangeLog b/mcs/class/System.Xaml/System.Windows.Markup/ChangeLog index 268b0dc47570..1256e703a36b 100644 --- a/mcs/class/System.Xaml/System.Windows.Markup/ChangeLog +++ b/mcs/class/System.Xaml/System.Windows.Markup/ChangeLog @@ -1,3 +1,7 @@ +2010-04-09 Atsushi Enomoto + + * ArrayExtension.cs, TypeExtension.cs : add missing members. + 2010-04-08 Atsushi Enomoto * ValueSerializer.cs : add missing members. diff --git a/mcs/class/System.Xaml/System.Windows.Markup/TypeExtension.cs b/mcs/class/System.Xaml/System.Windows.Markup/TypeExtension.cs index 8a868b5bc860..e9565a7d227f 100755 --- a/mcs/class/System.Xaml/System.Windows.Markup/TypeExtension.cs +++ b/mcs/class/System.Xaml/System.Windows.Markup/TypeExtension.cs @@ -31,6 +31,10 @@ namespace System.Windows.Markup [MarkupExtensionReturnType (typeof (Type))] public class TypeExtension : MarkupExtension { + public TypeExtension () + { + } + public TypeExtension (string typeName) { TypeName = typeName; diff --git a/mcs/class/System.Xaml/System.Xaml/ChangeLog b/mcs/class/System.Xaml/System.Xaml/ChangeLog index 429937c673ac..fc06b6db331a 100644 --- a/mcs/class/System.Xaml/System.Xaml/ChangeLog +++ b/mcs/class/System.Xaml/System.Xaml/ChangeLog @@ -1,3 +1,11 @@ +2010-04-09 Atsushi Enomoto + + * TypeExtension.cs + XamlMember.cs + XamlDirective.cs + XamlType.cs + XamlLanguage.cs : ongoing implementation. + 2010-04-09 Atsushi Enomoto * XamlType.cs : implemented lots of members. diff --git a/mcs/class/System.Xaml/System.Xaml/TypeExtension.cs b/mcs/class/System.Xaml/System.Xaml/TypeExtension.cs index 0de624493d6d..15d000112597 100644 --- a/mcs/class/System.Xaml/System.Xaml/TypeExtension.cs +++ b/mcs/class/System.Xaml/System.Xaml/TypeExtension.cs @@ -31,7 +31,7 @@ namespace System.Xaml { - static class TypeExtension + static class TypeExtensionMethods { public static string GetXamlName (this Type type) { diff --git a/mcs/class/System.Xaml/System.Xaml/XamlDirective.cs b/mcs/class/System.Xaml/System.Xaml/XamlDirective.cs index 6056ec559baf..1e07a29accdd 100644 --- a/mcs/class/System.Xaml/System.Xaml/XamlDirective.cs +++ b/mcs/class/System.Xaml/System.Xaml/XamlDirective.cs @@ -71,6 +71,11 @@ public XamlDirective (IEnumerable xamlNamespaces, string name, XamlType bool is_unknown; IList xaml_namespaces; + // this is for XamlLanguage.UnknownContent + internal bool InternalIsUnknown { + set { is_unknown = value; } + } + public override int GetHashCode () { throw new NotImplementedException (); diff --git a/mcs/class/System.Xaml/System.Xaml/XamlLanguage.cs b/mcs/class/System.Xaml/System.Xaml/XamlLanguage.cs index 535f582fa77b..737aadfc2c86 100644 --- a/mcs/class/System.Xaml/System.Xaml/XamlLanguage.cs +++ b/mcs/class/System.Xaml/System.Xaml/XamlLanguage.cs @@ -25,164 +25,143 @@ using System.Collections.ObjectModel; using System.Globalization; using System.Reflection; -using System.Xaml; +using System.Xaml.Schema; using System.Windows.Markup; -namespace System.Xaml.Schema +namespace System.Xaml { public static class XamlLanguage { public const string Xaml2006Namespace = "http://schemas.microsoft.com/winfx/2006/xaml"; public const string Xml1998Namespace = "http://www.w3.org/XML/1998/namespace"; - public static ReadOnlyCollection AllDirectives { - get { throw new NotImplementedException (); } - } - public static ReadOnlyCollection AllTypes { - get { throw new NotImplementedException (); } - } - public static XamlDirective Arguments { - get { throw new NotImplementedException (); } - } - public static XamlType Array { - get { throw new NotImplementedException (); } - } - public static XamlDirective AsyncRecords { - get { throw new NotImplementedException (); } - } - public static XamlDirective Base { - get { throw new NotImplementedException (); } - } - public static XamlType Boolean { - get { throw new NotImplementedException (); } - } - public static XamlType Byte { - get { throw new NotImplementedException (); } - } - public static XamlType Char { - get { throw new NotImplementedException (); } - } - public static XamlDirective Class { - get { throw new NotImplementedException (); } - } - public static XamlDirective ClassAttributes { - get { throw new NotImplementedException (); } - } - public static XamlDirective ClassModifier { - get { throw new NotImplementedException (); } - } - public static XamlDirective Code { - get { throw new NotImplementedException (); } - } - public static XamlDirective ConnectionId { - get { throw new NotImplementedException (); } - } - public static XamlType Decimal { - get { throw new NotImplementedException (); } - } - public static XamlType Double { - get { throw new NotImplementedException (); } - } - public static XamlDirective FactoryMethod { - get { throw new NotImplementedException (); } - } - public static XamlDirective FieldModifier { - get { throw new NotImplementedException (); } - } - public static XamlDirective Initialization { - get { throw new NotImplementedException (); } - } - public static XamlType Int16 { - get { throw new NotImplementedException (); } - } - public static XamlType Int32 { - get { throw new NotImplementedException (); } - } - public static XamlType Int64 { - get { throw new NotImplementedException (); } - } - public static XamlDirective Items { - get { throw new NotImplementedException (); } - } - public static XamlDirective Key { - get { throw new NotImplementedException (); } - } - public static XamlDirective Lang { - get { throw new NotImplementedException (); } - } - public static XamlType Member { - get { throw new NotImplementedException (); } - } - public static XamlDirective Members { - get { throw new NotImplementedException (); } - } - public static XamlDirective Name { - get { throw new NotImplementedException (); } - } - public static XamlType Null { - get { throw new NotImplementedException (); } - } - public static XamlType Object { - get { throw new NotImplementedException (); } - } - public static XamlDirective PositionalParameters { - get { throw new NotImplementedException (); } - } - public static XamlType Property { - get { throw new NotImplementedException (); } - } - public static XamlType Reference { - get { throw new NotImplementedException (); } - } - public static XamlDirective Shared { - get { throw new NotImplementedException (); } - } - public static XamlType Single { - get { throw new NotImplementedException (); } - } - public static XamlDirective Space { - get { throw new NotImplementedException (); } - } - public static XamlType Static { - get { throw new NotImplementedException (); } - } - public static XamlType String { - get { throw new NotImplementedException (); } - } - public static XamlDirective Subclass { - get { throw new NotImplementedException (); } - } - public static XamlDirective SynchronousMode { - get { throw new NotImplementedException (); } - } - public static XamlType TimeSpan { - get { throw new NotImplementedException (); } - } - public static XamlType Type { - get { throw new NotImplementedException (); } - } - public static XamlDirective TypeArguments { - get { throw new NotImplementedException (); } - } - public static XamlDirective Uid { - get { throw new NotImplementedException (); } - } - public static XamlDirective UnknownContent { - get { throw new NotImplementedException (); } + static readonly XamlSchemaContext sctx = new XamlSchemaContext (null, null); + + static XamlType XT () + { + return new XamlType (typeof (T), sctx); } - public static XamlType Uri { - get { throw new NotImplementedException (); } + + static XamlLanguage () + { + // types + + Array = new XamlType (typeof (ArrayExtension), sctx); + Boolean = new XamlType (typeof (bool), sctx); + Byte = new XamlType (typeof (byte), sctx); + Char = new XamlType (typeof (char), sctx); + Decimal = new XamlType (typeof (decimal), sctx); + Double = new XamlType (typeof (double), sctx); + Int16 = new XamlType (typeof (short), sctx); + Int32 = new XamlType (typeof (int), sctx); + Int64 = new XamlType (typeof (long), sctx); + Member = new XamlType (typeof (MemberDefinition), sctx); + Null = new XamlType (typeof (NullExtension), sctx); + Object = new XamlType (typeof (object), sctx); + Property = new XamlType (typeof (PropertyDefinition), sctx); + Reference = new XamlType (typeof (Reference), sctx); + Single = new XamlType (typeof (float), sctx); + Static = new XamlType (typeof (StaticExtension), sctx); + String = new XamlType (typeof (string), sctx); + TimeSpan = new XamlType (typeof (TimeSpan), sctx); + Type = new XamlType (typeof (TypeExtension), sctx); + Uri = new XamlType (typeof (Uri), sctx); + XData = new XamlType (typeof (XData), sctx); + + AllTypes = new ReadOnlyCollection (new XamlType [] {Array, Boolean, Byte, Char, Decimal, Double, Int16, Int32, Int64, Member, Null, Object, Property, Reference, Single, Static, String, TimeSpan, Type, Uri, XData}); + + // directives + + var nss = new string [] {XamlLanguage.Xaml2006Namespace}; + var nssXml = new string [] {XamlLanguage.Xml1998Namespace}; + + Arguments = new XamlDirective (nss, "Arguments", XT> (), null, AllowedMemberLocations.Any); + AsyncRecords = new XamlDirective (nss, "AsyncRecords", XT (), null, AllowedMemberLocations.Attribute); + Base = new XamlDirective (nssXml, "base", XT (), null, AllowedMemberLocations.Attribute); + Class = new XamlDirective (nss, "Class", XT (), null, AllowedMemberLocations.Attribute); + ClassAttributes = new XamlDirective (nss, "ClassAttributes", XT> (), null, AllowedMemberLocations.MemberElement); + ClassModifier = new XamlDirective (nss, "ClassModifier", XT (), null, AllowedMemberLocations.Attribute); + Code = new XamlDirective (nss, "Code", XT (), null, AllowedMemberLocations.Attribute); + ConnectionId = new XamlDirective (nss, "ConnectionId", XT (), null, AllowedMemberLocations.Any); + FactoryMethod = new XamlDirective (nss, "FactoryMethod", XT (), null, AllowedMemberLocations.Any); + FieldModifier = new XamlDirective (nss, "FieldModifier", XT (), null, AllowedMemberLocations.Attribute); + Initialization = new XamlDirective (nss, "_Initialization", XT (), null, AllowedMemberLocations.Any); + Items = new XamlDirective (nss, "_Items", XT> (), null, AllowedMemberLocations.Any); + Key = new XamlDirective (nss, "Key", XT (), null, AllowedMemberLocations.Any); + Lang = new XamlDirective (nssXml, "lang", XT (), null, AllowedMemberLocations.Attribute); + Members = new XamlDirective (nss, "Members", XT> (), null, AllowedMemberLocations.MemberElement); + Name = new XamlDirective (nss, "Name", XT (), null, AllowedMemberLocations.Attribute); + PositionalParameters = new XamlDirective (nss, "_PositionalParameters", XT> (), null, AllowedMemberLocations.Any); + Space = new XamlDirective (nssXml, "space", XT (), null, AllowedMemberLocations.Attribute); + Subclass = new XamlDirective (nss, "Subclass", XT (), null, AllowedMemberLocations.Attribute); + SynchronousMode = new XamlDirective (nss, "SynchronousMode", XT (), null, AllowedMemberLocations.Attribute); + Shared = new XamlDirective (nss, "Shared", XT (), null, AllowedMemberLocations.Attribute); + TypeArguments = new XamlDirective (nss, "TypeArguments", XT (), null, AllowedMemberLocations.Attribute); + Uid = new XamlDirective (nss, "Uid", XT (), null, AllowedMemberLocations.Attribute); + UnknownContent = new XamlDirective (nss, "_UnknownContent", XT (), null, AllowedMemberLocations.MemberElement) { InternalIsUnknown = true }; + + AllDirectives = new ReadOnlyCollection (new XamlDirective [] {Arguments, AsyncRecords, Base, Class, ClassAttributes, ClassModifier, Code, ConnectionId, FactoryMethod, FieldModifier, Initialization, Items, Key, Lang, Members, Name, PositionalParameters, Space, Subclass, SynchronousMode, Shared, TypeArguments, Uid, UnknownContent}); } + public static IList XamlNamespaces { get { throw new NotImplementedException (); } } - public static XamlType XData { - get { throw new NotImplementedException (); } - } + public static IList XmlNamespaces { get { throw new NotImplementedException (); } } + public static ReadOnlyCollection AllDirectives { get; private set; } + + public static XamlDirective Arguments { get; private set; } + public static XamlDirective AsyncRecords { get; private set; } + public static XamlDirective Base { get; private set; } + public static XamlDirective Class { get; private set; } + public static XamlDirective ClassAttributes { get; private set; } + public static XamlDirective ClassModifier { get; private set; } + public static XamlDirective Code { get; private set; } + public static XamlDirective ConnectionId { get; private set; } + public static XamlDirective FactoryMethod { get; private set; } + public static XamlDirective FieldModifier { get; private set; } + public static XamlDirective Initialization { get; private set; } + public static XamlDirective Items { get; private set; } + public static XamlDirective Key { get; private set; } + public static XamlDirective Lang { get; private set; } + public static XamlDirective Members { get; private set; } + public static XamlDirective Name { get; private set; } + public static XamlDirective PositionalParameters { get; private set; } + public static XamlDirective Subclass { get; private set; } + public static XamlDirective SynchronousMode { get; private set; } + public static XamlDirective Shared { get; private set; } + public static XamlDirective Space { get; private set; } + public static XamlDirective TypeArguments { get; private set; } + public static XamlDirective Uid { get; private set; } + public static XamlDirective UnknownContent { get; private set; } + + public static ReadOnlyCollection AllTypes { get; private set; } + + public static XamlType Array { get; private set; } + public static XamlType Boolean { get; private set; } + public static XamlType Byte { get; private set; } + public static XamlType Char { get; private set; } + public static XamlType Decimal { get; private set; } + public static XamlType Double { get; private set; } + public static XamlType Int16 { get; private set; } + public static XamlType Int32 { get; private set; } + public static XamlType Int64 { get; private set; } + public static XamlType Member { get; private set; } + public static XamlType Null { get; private set; } + public static XamlType Object { get; private set; } + public static XamlType Property { get; private set; } + public static XamlType Reference { get; private set; } + public static XamlType Single { get; private set; } + public static XamlType Static { get; private set; } + public static XamlType String { get; private set; } + public static XamlType TimeSpan { get; private set; } + public static XamlType Type { get; private set; } + public static XamlType Uri { get; private set; } + public static XamlType XData { get; private set; } + internal static bool IsValidXamlName (string name) { if (string.IsNullOrEmpty (name)) diff --git a/mcs/class/System.Xaml/System.Xaml/XamlMember.cs b/mcs/class/System.Xaml/System.Xaml/XamlMember.cs index 1994ad2424a3..71b163dec0a1 100644 --- a/mcs/class/System.Xaml/System.Xaml/XamlMember.cs +++ b/mcs/class/System.Xaml/System.Xaml/XamlMember.cs @@ -230,14 +230,38 @@ internal XamlMember (bool isDirective, string ns, string name) get { return LookupValueSerializer (); } } - public override bool Equals (object obj) + public static bool operator == (XamlMember left, XamlMember right) { - throw new NotImplementedException (); + return IsNull (left) ? IsNull (right) : left.Equals (right); + } + + static bool IsNull (XamlMember a) + { + return Object.ReferenceEquals (a, null); + } + + public static bool operator != (XamlMember left, XamlMember right) + { + return !(left == right); + } + + public override bool Equals (object other) + { + var x = other as XamlMember; + return Equals (x); } public bool Equals (XamlMember other) { - throw new NotImplementedException (); + return !IsNull (other) && + context == other.context && + underlying_member == other.underlying_member && + underlying_getter == other.underlying_getter && + underlying_setter == other.underlying_setter && + Name == other.Name && + PreferredXamlNamespace == other.PreferredXamlNamespace && + directive_ns == other.directive_ns && + is_attachable == other.is_attachable; } public override int GetHashCode () diff --git a/mcs/class/System.Xaml/System.Xaml/XamlType.cs b/mcs/class/System.Xaml/System.Xaml/XamlType.cs index 13c899cad5d4..26bdf97fbe16 100644 --- a/mcs/class/System.Xaml/System.Xaml/XamlType.cs +++ b/mcs/class/System.Xaml/System.Xaml/XamlType.cs @@ -38,6 +38,10 @@ public XamlType (Type underlyingType, XamlSchemaContext schemaContext) { } + static readonly Type [] predefined_types = { + typeof (XData), typeof (Uri), typeof (TimeSpan), typeof (PropertyDefinition), typeof (MemberDefinition), typeof (Reference) + }; + public XamlType (Type underlyingType, XamlSchemaContext schemaContext, XamlTypeInvoker invoker) : this (schemaContext, invoker) { @@ -48,8 +52,12 @@ public XamlType (Type underlyingType, XamlSchemaContext schemaContext, XamlTypeI Name = type.GetXamlName (); // FIXME: remove this hack - if (Type.GetTypeCode (type) == TypeCode.Object && type != typeof (object)) - PreferredXamlNamespace = String.Format ("clr-namespace:{0};assembly={1}", type.Namespace, type.Assembly.GetName ().Name); + if (Type.GetTypeCode (type) == TypeCode.Object && type != typeof (object)) { + if (predefined_types.Contains (type) || typeof (MarkupExtension).IsAssignableFrom (type) && type.Assembly == typeof (XamlType).Assembly) + PreferredXamlNamespace = XamlLanguage.Xaml2006Namespace; + else + PreferredXamlNamespace = String.Format ("clr-namespace:{0};assembly={1}", type.Namespace, type.Assembly.GetName ().Name); + } else PreferredXamlNamespace = XamlLanguage.Xaml2006Namespace; } @@ -364,9 +372,21 @@ protected virtual bool LookupConstructionRequiresArguments () if (UnderlyingType == null) return false; + // not sure if it is required, but TypeDefinition and MemberDefinition return true while they are abstract and it makes no sense. + if (UnderlyingType.IsAbstract) + return true; + // FIXME: probably some primitive types are treated as special. - if (Type.GetTypeCode (UnderlyingType) != TypeCode.Object) + switch (Type.GetTypeCode (UnderlyingType)) { + case TypeCode.String: + return true; + case TypeCode.Object: + if (UnderlyingType == typeof (TimeSpan)) + return false; + break; + default: return false; + } return UnderlyingType.GetConstructor (BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance, null, Type.EmptyTypes, null) == null; } @@ -410,8 +430,9 @@ protected virtual bool LookupIsConstructible () if (IsMarkupExtension) return false; // FIXME: handle x:Code - if (IsXData) - return false; + // FIXME: commented out. + //if (IsXData) + // return false; // FIXME: this check is extraneous to spec. 5.2. if (ConstructionRequiresArguments) @@ -453,7 +474,9 @@ protected virtual bool LookupIsWhitespaceSignificantCollection () protected virtual bool LookupIsXData () { - return typeof (XData).IsAssignableFrom (UnderlyingType); + // huh? XamlLanguage.XData.IsXData returns false(!) + // return typeof (XData).IsAssignableFrom (UnderlyingType); + return false; } protected virtual XamlType LookupItemType () diff --git a/mcs/class/System.Xaml/System.Xaml_test.dll.sources b/mcs/class/System.Xaml/System.Xaml_test.dll.sources index 88629f9d4cff..03e69facfea9 100644 --- a/mcs/class/System.Xaml/System.Xaml_test.dll.sources +++ b/mcs/class/System.Xaml/System.Xaml_test.dll.sources @@ -5,6 +5,7 @@ System.Xaml/AttachableMemberIdentifierTest.cs System.Xaml/NamespaceDeclarationTest.cs System.Xaml/XamlDirectiveTest.cs System.Xaml/XamlDuplicateMemberExceptionTest.cs +System.Xaml/XamlLanguageTest.cs System.Xaml/XamlMemberTest.cs System.Xaml/XamlObjectEventArgsTest.cs System.Xaml/XamlObjectReaderSettingsTest.cs diff --git a/mcs/class/System.Xaml/Test/System.Xaml/ChangeLog b/mcs/class/System.Xaml/Test/System.Xaml/ChangeLog index 1ac7f2384024..75bf5b2a8609 100644 --- a/mcs/class/System.Xaml/Test/System.Xaml/ChangeLog +++ b/mcs/class/System.Xaml/Test/System.Xaml/ChangeLog @@ -1,3 +1,8 @@ +2010-04-09 Atsushi Enomoto + + * XamlLanguageTest.cs : new test. + * XamlDirectiveTest.cs : add another ns test. + 2010-04-09 Atsushi Enomoto * XamlTypeTest.cs : added a lot of new tests. diff --git a/mcs/class/System.Xaml/Test/System.Xaml/XamlDirectiveTest.cs b/mcs/class/System.Xaml/Test/System.Xaml/XamlDirectiveTest.cs index 7f7cda0c35f2..30d584a1f9a0 100755 --- a/mcs/class/System.Xaml/Test/System.Xaml/XamlDirectiveTest.cs +++ b/mcs/class/System.Xaml/Test/System.Xaml/XamlDirectiveTest.cs @@ -53,6 +53,12 @@ public void ConstructorNamespaceNull () new XamlDirective (null, "Foo"); } + [Test] + public void ConstructorNamespaceXamlNS () + { + new XamlDirective (XamlLanguage.Xaml2006Namespace, "Foo"); + } + [Test] [ExpectedException (typeof (ArgumentNullException))] public void ConstructorComplexParamsTypeNull () diff --git a/mcs/class/System.Xaml/Test/System.Xaml/XamlLanguageTest.cs b/mcs/class/System.Xaml/Test/System.Xaml/XamlLanguageTest.cs new file mode 100644 index 000000000000..155ebb89c2f0 --- /dev/null +++ b/mcs/class/System.Xaml/Test/System.Xaml/XamlLanguageTest.cs @@ -0,0 +1,531 @@ +// +// Copyright (C) 2010 Novell Inc. http://novell.com +// +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// +using System; +using System.Collections; +using System.Collections.Generic; +using System.ComponentModel; +using System.Reflection; +using System.Windows.Markup; +using System.Xaml; +using System.Xaml.Schema; +using NUnit.Framework; + +using Category = NUnit.Framework.CategoryAttribute; + +namespace MonoTests.System.Xaml +{ + [TestFixture] + public class XamlLanguageTest + { + [Test] + public void AllDirectives () + { + var l = XamlLanguage.AllDirectives; + Assert.AreEqual (24, l.Count, "count"); + Assert.IsTrue (l.Contains (XamlLanguage.Arguments), "#0"); + Assert.IsTrue (l.Contains (XamlLanguage.AsyncRecords), "#1"); + Assert.IsTrue (l.Contains (XamlLanguage.Base), "#2"); + Assert.IsTrue (l.Contains (XamlLanguage.Class), "#3"); + Assert.IsTrue (l.Contains (XamlLanguage.ClassAttributes), "#4"); + Assert.IsTrue (l.Contains (XamlLanguage.ClassModifier), "#5"); + Assert.IsTrue (l.Contains (XamlLanguage.Code), "#6"); + Assert.IsTrue (l.Contains (XamlLanguage.ConnectionId), "#7"); + Assert.IsTrue (l.Contains (XamlLanguage.FactoryMethod), "#8"); + Assert.IsTrue (l.Contains (XamlLanguage.FieldModifier), "#9"); + Assert.IsTrue (l.Contains (XamlLanguage.Initialization), "#10"); + Assert.IsTrue (l.Contains (XamlLanguage.Items), "#11"); + Assert.IsTrue (l.Contains (XamlLanguage.Key), "#12"); + Assert.IsTrue (l.Contains (XamlLanguage.Lang), "#13"); + Assert.IsTrue (l.Contains (XamlLanguage.Members), "#14"); + Assert.IsTrue (l.Contains (XamlLanguage.Name), "#15"); + Assert.IsTrue (l.Contains (XamlLanguage.PositionalParameters), "#16"); + Assert.IsTrue (l.Contains (XamlLanguage.Space), "#17"); + Assert.IsTrue (l.Contains (XamlLanguage.Subclass), "#18"); + Assert.IsTrue (l.Contains (XamlLanguage.SynchronousMode), "#19"); + Assert.IsTrue (l.Contains (XamlLanguage.Shared), "#20"); + Assert.IsTrue (l.Contains (XamlLanguage.TypeArguments), "#21"); + Assert.IsTrue (l.Contains (XamlLanguage.Uid), "#22"); + Assert.IsTrue (l.Contains (XamlLanguage.UnknownContent), "#23"); + } + + [Test] + public void AllTypes () + { + var l = XamlLanguage.AllTypes; + Assert.AreEqual (21, l.Count, "count"); + Assert.IsTrue (l.Contains (XamlLanguage.Array), "#0"); + Assert.IsTrue (l.Contains (XamlLanguage.Boolean), "#1"); + Assert.IsTrue (l.Contains (XamlLanguage.Byte), "#2"); + Assert.IsTrue (l.Contains (XamlLanguage.Char), "#3"); + Assert.IsTrue (l.Contains (XamlLanguage.Decimal), "#4"); + Assert.IsTrue (l.Contains (XamlLanguage.Double), "#5"); + Assert.IsTrue (l.Contains (XamlLanguage.Int16), "#6"); + Assert.IsTrue (l.Contains (XamlLanguage.Int32), "#7"); + Assert.IsTrue (l.Contains (XamlLanguage.Int64), "#8"); + Assert.IsTrue (l.Contains (XamlLanguage.Member), "#9"); + Assert.IsTrue (l.Contains (XamlLanguage.Null), "#10"); + Assert.IsTrue (l.Contains (XamlLanguage.Object), "#11"); + Assert.IsTrue (l.Contains (XamlLanguage.Property), "#12"); + Assert.IsTrue (l.Contains (XamlLanguage.Reference), "#13"); + Assert.IsTrue (l.Contains (XamlLanguage.Single), "#14"); + Assert.IsTrue (l.Contains (XamlLanguage.Static), "#15"); + Assert.IsTrue (l.Contains (XamlLanguage.String), "#16"); + Assert.IsTrue (l.Contains (XamlLanguage.TimeSpan), "#17"); + Assert.IsTrue (l.Contains (XamlLanguage.Type), "#18"); + Assert.IsTrue (l.Contains (XamlLanguage.Uri), "#19"); + Assert.IsTrue (l.Contains (XamlLanguage.XData), "#20"); + } + + // directive property details + + [Test] + public void Arguments () + { + var d = XamlLanguage.Arguments; + TestXamlDirectiveCommon (d, "Arguments", AllowedMemberLocations.Any, typeof (List)); + } + + [Test] + public void AsyncRecords () + { + var d = XamlLanguage.AsyncRecords; + TestXamlDirectiveCommon (d, "AsyncRecords", AllowedMemberLocations.Attribute, typeof (string)); + } + + [Test] + public void Base () + { + var d = XamlLanguage.Base; + TestXamlDirectiveCommon (d, "base", XamlLanguage.Xml1998Namespace, AllowedMemberLocations.Attribute, typeof (string)); + } + + [Test] + public void Class () + { + var d = XamlLanguage.Class; + TestXamlDirectiveCommon (d, "Class", AllowedMemberLocations.Attribute, typeof (string)); + } + + [Test] + public void ClassAttributes () + { + var d = XamlLanguage.ClassAttributes; + TestXamlDirectiveCommon (d, "ClassAttributes", AllowedMemberLocations.MemberElement, typeof (List)); + } + + [Test] + public void ClassModifier () + { + var d = XamlLanguage.ClassModifier; + TestXamlDirectiveCommon (d, "ClassModifier", AllowedMemberLocations.Attribute, typeof (string)); + } + + [Test] + public void Code () + { + var d = XamlLanguage.Code; + TestXamlDirectiveCommon (d, "Code", AllowedMemberLocations.Attribute, typeof (string)); + } + + [Test] + public void ConnectionId () + { + var d = XamlLanguage.ConnectionId; + TestXamlDirectiveCommon (d, "ConnectionId", AllowedMemberLocations.Any, typeof (string)); + } + + [Test] + public void FactoryMethod () + { + var d = XamlLanguage.FactoryMethod; + TestXamlDirectiveCommon (d, "FactoryMethod", AllowedMemberLocations.Any, typeof (string)); + } + + [Test] + public void FieldModifier () + { + var d = XamlLanguage.FieldModifier; + TestXamlDirectiveCommon (d, "FieldModifier", AllowedMemberLocations.Attribute, typeof (string)); + } + + [Test] + public void Initialization () + { + var d = XamlLanguage.Initialization; + // weird name + TestXamlDirectiveCommon (d, "_Initialization", AllowedMemberLocations.Any, typeof (object)); + } + + [Test] + public void Items () + { + var d = XamlLanguage.Items; + // weird name + TestXamlDirectiveCommon (d, "_Items", AllowedMemberLocations.Any, typeof (List)); + } + + [Test] + public void Key () + { + var d = XamlLanguage.Key; + TestXamlDirectiveCommon (d, "Key", AllowedMemberLocations.Any, typeof (object)); + } + + [Test] + public void Lang () + { + var d = XamlLanguage.Lang; + TestXamlDirectiveCommon (d, "lang", XamlLanguage.Xml1998Namespace, AllowedMemberLocations.Attribute, typeof (string)); + } + + [Test] + public void Members () + { + var d = XamlLanguage.Members; + TestXamlDirectiveCommon (d, "Members", AllowedMemberLocations.MemberElement, typeof (List)); + } + + [Test] + public void Name () + { + var d = XamlLanguage.Name; + TestXamlDirectiveCommon (d, "Name", AllowedMemberLocations.Attribute, typeof (string)); + } + + [Test] + public void PositionalParameters () + { + var d = XamlLanguage.PositionalParameters; + // weird name + TestXamlDirectiveCommon (d, "_PositionalParameters", AllowedMemberLocations.Any, typeof (List)); + } + + [Test] + public void Subclass () + { + var d = XamlLanguage.Subclass; + TestXamlDirectiveCommon (d, "Subclass", AllowedMemberLocations.Attribute, typeof (string)); + } + + [Test] + public void SynchronousMode () + { + var d = XamlLanguage.SynchronousMode; + TestXamlDirectiveCommon (d, "SynchronousMode", AllowedMemberLocations.Attribute, typeof (string)); + } + + [Test] + public void Shared () + { + var d = XamlLanguage.Shared; + TestXamlDirectiveCommon (d, "Shared", AllowedMemberLocations.Attribute, typeof (string)); + } + + [Test] + public void Space () + { + var d = XamlLanguage.Space; + TestXamlDirectiveCommon (d, "space", XamlLanguage.Xml1998Namespace, AllowedMemberLocations.Attribute, typeof (string)); + } + + [Test] + public void TypeArguments () + { + var d = XamlLanguage.TypeArguments; + TestXamlDirectiveCommon (d, "TypeArguments", AllowedMemberLocations.Attribute, typeof (string)); + } + + [Test] + public void Uid () + { + var d = XamlLanguage.Uid; + TestXamlDirectiveCommon (d, "Uid", AllowedMemberLocations.Attribute, typeof (string)); + } + + [Test] + public void UnknownContent () + { + var d = XamlLanguage.UnknownContent; + // weird name + TestXamlDirectiveCommon (d, "_UnknownContent", XamlLanguage.Xaml2006Namespace, AllowedMemberLocations.MemberElement, typeof (object), true); + } + + void TestXamlDirectiveCommon (XamlDirective d, string name, AllowedMemberLocations allowedLocation, Type type) + { + TestXamlDirectiveCommon (d, name, XamlLanguage.Xaml2006Namespace, allowedLocation, type); + } + + // FIXME: enable TypeConverter test + void TestXamlDirectiveCommon (XamlDirective d, string name, string ns, AllowedMemberLocations allowedLocation, Type type) + { + TestXamlDirectiveCommon (d, name, ns, allowedLocation, type, false); + } + + void TestXamlDirectiveCommon (XamlDirective d, string name, string ns, AllowedMemberLocations allowedLocation, Type type, bool isUnknown) + { + Assert.AreEqual (allowedLocation, d.AllowedLocation, "#1"); + Assert.IsNull (d.DeclaringType, "#2"); + Assert.IsNotNull (d.Invoker, "#3"); + Assert.IsNull (d.Invoker.UnderlyingGetter, "#3-2"); + Assert.IsNull (d.Invoker.UnderlyingSetter, "#3-3"); + Assert.AreEqual (isUnknown, d.IsUnknown, "#4"); + Assert.IsTrue (d.IsReadPublic, "#5"); + Assert.IsTrue (d.IsWritePublic, "#6"); + Assert.AreEqual (name, d.Name, "#7"); + Assert.IsTrue (d.IsNameValid, "#8"); + Assert.AreEqual (ns, d.PreferredXamlNamespace, "#9"); + Assert.IsNull (d.TargetType, "#10"); + Assert.IsNotNull (d.Type, "#11"); + Assert.AreEqual (type, d.Type.UnderlyingType, "#11-2"); + //Assert.IsNull (d.TypeConverter, "#12"); + Assert.IsNull (d.ValueSerializer, "#13"); + Assert.IsNull (d.DeferringLoader, "#14"); + Assert.IsNull (d.UnderlyingMember, "#15"); + Assert.IsFalse (d.IsReadOnly, "#16"); + Assert.IsFalse (d.IsWriteOnly, "#17"); + Assert.IsFalse (d.IsAttachable, "#18"); + Assert.IsFalse (d.IsEvent, "#19"); + Assert.IsTrue (d.IsDirective, "#20"); + Assert.IsNotNull (d.DependsOn, "#21"); + Assert.AreEqual (0, d.DependsOn.Count, "#21-2"); + Assert.IsFalse (d.IsAmbient, "#22"); + Assert.AreEqual (DesignerSerializationVisibility.Visible, d.SerializationVisibility, "#23"); + } + + // type property details + + // extension types + [Test] + public void Array () + { + var t = XamlLanguage.Array; + TestXamlTypeExtension (t, "ArrayExtension", typeof (ArrayExtension), typeof (Array)); + Assert.IsNotNull (t.ContentProperty, "#27"); + Assert.AreEqual ("Items", t.ContentProperty.Name, "#27-2"); + } + + [Test] + public void Null () + { + var t = XamlLanguage.Null; + TestXamlTypeExtension (t, "NullExtension", typeof (NullExtension), typeof (object)); + Assert.IsNull (t.ContentProperty, "#27"); + } + + [Test] + public void Static () + { + var t = XamlLanguage.Static; + TestXamlTypeExtension (t, "StaticExtension", typeof (StaticExtension), typeof (object)); + Assert.IsNull (t.ContentProperty, "#27"); + } + + [Test] + public void Type () + { + var t = XamlLanguage.Type; + TestXamlTypeExtension (t, "TypeExtension", typeof (TypeExtension), typeof (Type)); + Assert.IsNull (t.ContentProperty, "#27"); + } + + // primitive types + + [Test] + public void Byte () + { + var t = XamlLanguage.Byte; + TestXamlTypePrimitive (t, "Byte", typeof (byte), false, false); + } + + [Test] + public void Char () + { + var t = XamlLanguage.Char; + TestXamlTypePrimitive (t, "Char", typeof (char), false, false); + } + + [Test] + public void Decimal () + { + var t = XamlLanguage.Decimal; + TestXamlTypePrimitive (t, "Decimal", typeof (decimal), false, false); + } + + [Test] + public void Double () + { + var t = XamlLanguage.Double; + TestXamlTypePrimitive (t, "Double", typeof (double), false, false); + } + + [Test] + public void Int16 () + { + var t = XamlLanguage.Int16; + TestXamlTypePrimitive (t, "Int16", typeof (short), false, false); + } + + [Test] + public void Int32 () + { + var t = XamlLanguage.Int32; + TestXamlTypePrimitive (t, "Int32", typeof (int), false, false); + } + + [Test] + public void Int64 () + { + var t = XamlLanguage.Int64; + TestXamlTypePrimitive (t, "Int64", typeof (long), false, false); + } + + [Test] + public void Object () + { + var t = XamlLanguage.Object; + TestXamlTypePrimitive (t, "Object", typeof (object), true, false); + } + + [Test] + public void Single () + { + var t = XamlLanguage.Single; + TestXamlTypePrimitive (t, "Single", typeof (float), false, false); + } + + [Test] + public void String () + { + var t = XamlLanguage.String; + TestXamlTypePrimitive (t, "String", typeof (string), true, true); + } + + [Test] + public void TimeSpan () + { + var t = XamlLanguage.TimeSpan; + TestXamlTypePrimitive (t, "TimeSpan", typeof (TimeSpan), false, false); + } + + [Test] + public void Uri () + { + var t = XamlLanguage.Uri; + TestXamlTypePrimitive (t, "Uri", typeof (Uri), true, true); + } + + // miscellaneous + + [Test] + public void Member () + { + var t = XamlLanguage.Member; + TestXamlTypeCommon (t, "Member", typeof (MemberDefinition), true, true, false); + // FIXME: test remaining members + } + + [Test] + public void Property () + { + var t = XamlLanguage.Property; + TestXamlTypeCommon (t, "Property", typeof (PropertyDefinition), true); + // FIXME: test remaining members + } + + [Test] + public void Reference () + { + var t = XamlLanguage.Reference; + TestXamlTypeCommon (t, "Reference", typeof (Reference), true); + // FIXME: test remaining members + } + + [Test] + public void XData () + { + var t = XamlLanguage.XData; + TestXamlTypeCommon (t, "XData", typeof (XData), true); + // FIXME: test remaining members + } + + // common test methods + + void TestXamlTypeCommon (XamlType t, string name, Type underlyingType, bool nullable) + { + TestXamlTypeCommon (t, name, underlyingType, nullable, false); + } + + void TestXamlTypeCommon (XamlType t, string name, Type underlyingType, bool nullable, bool constructionRequiresArguments) + { + TestXamlTypeCommon (t, name, underlyingType, nullable, constructionRequiresArguments, true); + } + + void TestXamlTypeCommon (XamlType t, string name, Type underlyingType, bool nullable, bool constructionRequiresArguments, bool isConstructible) + { + Assert.IsNotNull (t.Invoker, "#1"); + Assert.IsTrue (t.IsNameValid, "#2"); + Assert.IsFalse (t.IsUnknown, "#3"); + // FIXME: test names (some extension types have wrong name. + //Assert.AreEqual (name, t.Name, "#4"); + Assert.AreEqual (XamlLanguage.Xaml2006Namespace, t.PreferredXamlNamespace, "#5"); + Assert.IsNull (t.TypeArguments, "#6"); + Assert.AreEqual (underlyingType, t.UnderlyingType, "#7"); + Assert.AreEqual (constructionRequiresArguments, t.ConstructionRequiresArguments, "#8"); + Assert.IsFalse (t.IsArray, "#9"); + Assert.IsFalse (t.IsCollection, "#10"); + // FIXME: test here (very inconsistent with the spec) + //Assert.AreEqual (isConstructible, t.IsConstructible, "#11"); + Assert.IsFalse (t.IsDictionary, "#12"); + Assert.IsFalse (t.IsGeneric, "#13"); + Assert.IsFalse (t.IsNameScope, "#15"); + Assert.AreEqual (nullable, t.IsNullable, "#16"); + Assert.IsTrue (t.IsPublic, "#17"); + Assert.IsFalse (t.IsUsableDuringInitialization, "#18"); + Assert.IsFalse (t.IsWhitespaceSignificantCollection, "#19"); + Assert.IsFalse (t.IsXData, "#20"); + Assert.IsFalse (t.TrimSurroundingWhitespace, "#21"); + Assert.IsFalse (t.IsAmbient, "#22"); + //Assert.IsNull (t.AllowedContentTypes, "#23"); + //Assert.IsNull (t.ContentWrappers, "#24"); + //Assert.IsNotNull (t.TypeConverter, "#25"); + //Assert.IsNull (t.ValueSerializer, "#26"); + //Assert.IsNull (t.DeferringLoader, "#28"); + } + + void TestXamlTypePrimitive (XamlType t, string name, Type underlyingType, bool nullable, bool constructorRequiresArguments) + { + TestXamlTypeCommon (t, name, underlyingType, nullable, constructorRequiresArguments); + Assert.IsFalse (t.IsMarkupExtension, "#14"); + Assert.IsNull (t.ContentProperty, "#27"); + Assert.IsNull (t.MarkupExtensionReturnType, "#29"); + } + + void TestXamlTypeExtension (XamlType t, string name, Type underlyingType, Type extReturnType) + { + TestXamlTypeCommon (t, name, underlyingType, true, false); + Assert.IsTrue (t.IsMarkupExtension, "#14"); + Assert.IsNotNull (t.MarkupExtensionReturnType, "#29"); + Assert.AreEqual (extReturnType, t.MarkupExtensionReturnType.UnderlyingType, "#29-2"); + } + } +}