Added test case for #3003.
authorAtsushi Eno <atsushi@ximian.com>
Fri, 9 Mar 2012 09:59:46 +0000 (18:59 +0900)
committerAtsushi Eno <atsushi@ximian.com>
Fri, 9 Mar 2012 09:59:46 +0000 (18:59 +0900)
mcs/class/System.Xaml/Test/System.Xaml/TestedTypes.cs
mcs/class/System.Xaml/Test/System.Xaml/XamlObjectWriterTest.cs
mcs/class/System.Xaml/Test/System.Xaml/XamlSchemaContextTest.cs

index 88fcce250dd29a404f2e5085b8b0250f5205e53f..5795722a2d80f4a0d24e0720d97d30163e55bc68 100755 (executable)
@@ -23,6 +23,7 @@
 using System;
 using System.Collections;
 using System.Collections.Generic;
+using System.Collections.ObjectModel;
 using System.ComponentModel;
 using System.Diagnostics;
 using System.Globalization;
@@ -39,6 +40,9 @@ using System.Xml.Serialization;
 [assembly: XmlnsDefinition ("http://www.domain.com/path", "XamlTest")] // bug #680385
 [assembly: XmlnsDefinition ("http://www.domain.com/path", "SecondTest")] // bug #681045, same xmlns key for different clrns.
 
+[assembly: XmlnsDefinition ("http://schemas.example.com/test", "XamarinBug3003")] // bug #3003
+[assembly: XmlnsPrefix ("http://schemas.example.com/test", "test")] // bug #3003
+
 namespace MonoTests.System.Xaml
 {
        public class ArgumentAttributed
@@ -1164,4 +1168,138 @@ namespace XamarinBug2927
 }
 #endregion
 
+#region "xamarin bug 3003"
+
+namespace XamarinBug3003
+{
+       public static class TestContext
+       {
+               public static StringWriter Writer = new StringWriter ();
+               
+               public const string XmlInput = @"<Parent xmlns='http://schemas.example.com/test' Title='Parent Title'>
+       <Child Parent.AssociatedProperty='child 1' Title='Child Title 1'></Child>       
+       <Child Parent.AssociatedProperty='child 2' Title='Child Title 2'></Child>       
+</Parent>";
+               
+               // In bug #3003 repro, there is output "Item 'Child' inserted at index 'x'" , but I couldn't get it in the output either on .NET or Mono.
+               // On the other hand, in the standalone repro case they are in the output either in mono or in .NET. So I just stopped caring about that as it works as expected.
+               public const string ExpectedResult = @"
+Parent Constructed
+ISupportInitialize.BeginInit: Parent
+XamlObjectWriterSettings.AfterBeginInit: Parent
+XamlObjectWriterSettings.BeforeProperties: Parent
+XamlObjectWriterSettings.XamlSetValue: Parent Title, Member: Title
+Parent.Title_set: Parent
+Child Constructed
+ISupportInitialize.BeginInit: Child
+XamlObjectWriterSettings.AfterBeginInit: Child
+XamlObjectWriterSettings.BeforeProperties: Child
+XamlObjectWriterSettings.XamlSetValue: child 1, Member: AssociatedProperty
+Parent.SetAssociatedProperty: child 1
+XamlObjectWriterSettings.XamlSetValue: Child Title 1, Member: Title
+Child.Title_set: Child
+XamlObjectWriterSettings.AfterProperties: Child
+ISupportInitialize.EndInit: Child
+XamlObjectWriterSettings.AfterEndInit: Child
+Child Constructed
+ISupportInitialize.BeginInit: Child
+XamlObjectWriterSettings.AfterBeginInit: Child
+XamlObjectWriterSettings.BeforeProperties: Child
+XamlObjectWriterSettings.XamlSetValue: child 2, Member: AssociatedProperty
+Parent.SetAssociatedProperty: child 2
+XamlObjectWriterSettings.XamlSetValue: Child Title 2, Member: Title
+Child.Title_set: Child
+XamlObjectWriterSettings.AfterProperties: Child
+ISupportInitialize.EndInit: Child
+XamlObjectWriterSettings.AfterEndInit: Child
+XamlObjectWriterSettings.AfterProperties: Parent
+ISupportInitialize.EndInit: Parent
+XamlObjectWriterSettings.AfterEndInit: Parent
+Loaded Parent
+";
+       }
+
+       public class BaseItemCollection : Collection<BaseItem>
+       {
+               protected override void InsertItem (int index, BaseItem item)
+               {
+                       base.InsertItem (index, item);
+                       Console.WriteLine ("Item '{0}' inserted at index '{1}'", item, index);
+               }
+       }
+
+       public class BaseItem : ISupportInitialize
+       {
+               Dictionary<string, object> properties = new Dictionary<string, object> ();
+               
+               public Dictionary<string, object> Properties
+               {
+                       get { return properties; }
+               }
+
+               string title;
+
+               public string Title
+               {
+                       get { return title; }
+                       set
+                       {
+                               title = value;
+                               TestContext.Writer.WriteLine ("{0}.Title_set: {0}", this.GetType ().Name, value);
+                       }
+               }
+
+               public BaseItem ()
+               {
+                       TestContext.Writer.WriteLine ("{0} Constructed", this.GetType ().Name);
+               }
+
+
+               public void BeginInit ()
+               {
+                       TestContext.Writer.WriteLine ("ISupportInitialize.BeginInit: {0}", this);
+               }
+
+               public void EndInit ()
+               {
+                       TestContext.Writer.WriteLine ("ISupportInitialize.EndInit: {0}", this);
+               }
 
+               public override string ToString ()
+               {
+                       return this.GetType ().Name.ToString ();
+               }
+       }
+
+       public class Child : BaseItem
+       {
+       }
+
+       [ContentProperty ("Children")]
+       public class Parent : BaseItem
+       {
+               BaseItemCollection children = new BaseItemCollection ();
+               
+               public BaseItemCollection Children
+               {
+                       get { return children; }
+               }
+               
+               
+               public static string GetAssociatedProperty (Child child)
+               {
+                       object value;
+                       if (child.Properties.TryGetValue ("myassociatedproperty", out value)) return value as string;
+                       return null;
+               }
+               
+               public static void SetAssociatedProperty (Child child, string value)
+               {
+                       TestContext.Writer.WriteLine ("Parent.SetAssociatedProperty: {0}", value);
+                       child.Properties ["myassociatedproperty"] = value;
+               }
+               
+       }
+}
+
+#endregion
index 95e32c14fa69094d5adfbc2bc1420f7d5a50d58f..f3e89003b3ba19c1a82a7d3c051456d0172a771f 100755 (executable)
@@ -737,6 +737,45 @@ namespace MonoTests.System.Xaml
                        var ret = xow.Result as TestClass3;
                        Assert.IsNotNull (ret.Nested, "#8");
                }
+               
+               [Test] // bug #3003 repro
+               public void EventsAndProcessingOrder ()
+               {
+                       var asm = Assembly.GetExecutingAssembly ();
+                       var context = new XamlSchemaContext (new Assembly [] { asm });
+                       var output = XamarinBug3003.TestContext.Writer;
+                       output.WriteLine ();
+
+                       var reader = new XamlXmlReader (XmlReader.Create (new StringReader (XamarinBug3003.TestContext.XmlInput)), context);
+
+                       var writerSettings = new XamlObjectWriterSettings ();
+                       writerSettings.AfterBeginInitHandler = (sender, e) => {
+                               output.WriteLine ("XamlObjectWriterSettings.AfterBeginInit: {0}", e.Instance);
+                       };
+                       writerSettings.AfterEndInitHandler = (sender, e) => {
+                               output.WriteLine ("XamlObjectWriterSettings.AfterEndInit: {0}", e.Instance);
+                       };
+
+                       writerSettings.BeforePropertiesHandler = (sender, e) => {
+                               output.WriteLine ("XamlObjectWriterSettings.BeforeProperties: {0}", e.Instance);
+                       };
+                       writerSettings.AfterPropertiesHandler = (sender, e) => {
+                               output.WriteLine ("XamlObjectWriterSettings.AfterProperties: {0}", e.Instance);
+                       };
+                       writerSettings.XamlSetValueHandler = (sender, e) => {
+                               output.WriteLine ("XamlObjectWriterSettings.XamlSetValue: {0}, Member: {1}", e.Value, e.Member.Name);
+                       };
+
+                       var writer = new XamlObjectWriter (context, writerSettings);
+                       XamlServices.Transform (reader, writer);
+                       var obj = writer.Result as XamarinBug3003.Parent;
+
+                       output.WriteLine ("Loaded {0}", obj);
+
+                       Assert.AreEqual (XamarinBug3003.TestContext.ExpectedResult.Replace ("\r\n", "\n"), output.ToString ().Replace ("\r\n", "\n"), "#1");
+
+                       Assert.AreEqual (2, obj.Children.Count, "#2");
+               }
 
                // extra use case based tests.
 
index bd011f3fe2bb8a9e538fb3704c2fc84d876f09e7..5cccd52073162f459276a0eec0a02c7a9f716056 100644 (file)
@@ -84,7 +84,7 @@ namespace MonoTests.System.Xaml
                {
                        var ctx = new XamlSchemaContext (null, null);
                        var arr = ctx.GetAllXamlNamespaces ().ToArray ();
-                       Assert.AreEqual (4, arr.Length, "#1");
+                       Assert.AreEqual (5, arr.Length, "#1");
                        Assert.IsTrue (arr.Contains (XamlLanguage.Xaml2006Namespace), "#1-2");
                        Assert.IsTrue (arr.Contains ("urn:mono-test"), "#1-3");
                        Assert.IsTrue (arr.Contains ("urn:mono-test2"), "#1-4");
@@ -96,7 +96,7 @@ namespace MonoTests.System.Xaml
 
                        ctx = NewThisAssemblyContext ();
                        arr = ctx.GetAllXamlNamespaces ().ToArray ();
-                       Assert.AreEqual (3, arr.Length, "#3");
+                       Assert.AreEqual (4, arr.Length, "#3");
                        Assert.IsTrue (arr.Contains ("urn:mono-test"), "#3-2");
                        Assert.IsTrue (arr.Contains ("urn:mono-test2"), "#3-3");
                }