From e66adeddcd679f54a6bf32179f0ecf168cfef5dd Mon Sep 17 00:00:00 2001 From: Rodrigo Kumpera Date: Thu, 5 Jan 2012 09:11:34 -0200 Subject: [PATCH] Add regression test for bxc #1147. --- mono/tests/Makefile.am | 6 ++-- mono/tests/bug-1147.cs | 94 ++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 98 insertions(+), 2 deletions(-) create mode 100644 mono/tests/bug-1147.cs diff --git a/mono/tests/Makefile.am b/mono/tests/Makefile.am index cffc5aaea80..929731fe068 100644 --- a/mono/tests/Makefile.am +++ b/mono/tests/Makefile.am @@ -377,7 +377,8 @@ BASE_TEST_CS_SRC= \ sgen-long-vtype.cs \ delegate-invoke.cs \ bug-696593.cs \ - bug-705140.cs + bug-705140.cs \ + bug-1147.cs TEST_CS_SRC_DIST= \ $(BASE_TEST_CS_SRC) \ @@ -902,7 +903,8 @@ GSHARED_TESTS = \ generic-stack-traces.2.exe generic-stack-traces2.2.exe \ bug-472600.2.exe bug-473482.2.exe bug-473999.2.exe \ bug-479763.2.exe generic-xdomain.2.exe \ - generic-type-load-exception.2.exe bug-616463.exe + generic-type-load-exception.2.exe bug-616463.exe \ + bug-1147.exe test-generic-sharing-normal: $(GSHARED_TESTS) @for fn in $+ ; do \ diff --git a/mono/tests/bug-1147.cs b/mono/tests/bug-1147.cs new file mode 100644 index 00000000000..9190c9b888a --- /dev/null +++ b/mono/tests/bug-1147.cs @@ -0,0 +1,94 @@ +using System; +using System.Collections.Generic; + +namespace Program { + public class AxControlEventArgs : EventArgs where T : WindowlessControl +{ + public T Control { get; private set; } + + public AxControlEventArgs(T control) { + Control = control; + } + } + public class AxControlEventArgs : AxControlEventArgs { + public AxControlEventArgs(WindowlessControl c) : base(c) { } + } + + public class AlignPadLayoutPanel : AlignPadLayoutPanel { +} + + public class AlignPadLayoutPanel : WindowlessControl where T : +WindowlessControl { + protected override void OnControlAdded(AxControlEventArgs e) { + e.Control.Resize += Content_Resize; //OK if removed + base.OnControlAdded(e); + } + + private void Content_Resize(object sender, EventArgs e) { } + } + + public class GroupBox : AlignPadLayoutPanel { } //NOT OK + //public class GroupBox : AlignPadLayoutPanel {} //OK + + public class Program { + public static readonly AttachedProperty EDITING_TEXT = new +AttachedProperty(null); + + static void Main(string[] args) { + Console.WriteLine("Program 6"); + + var gr = new GroupBox(); + + //gr.InsertControl(0, new WindowlessControl()); //OK + + /* need this block(A) this to crash */ + var item = new WindowlessControl(); + + new AlignPadLayoutPanel().InsertControl(0, +item); //OK if removed + + item.SetAttachedProperty(EDITING_TEXT, "label.Text"); + /*end block(A)*/ + + gr.InsertControl(0, new WindowlessControl()); //NOT OK + + var wc = new WindowlessControl(); + wc.SetAttachedProperty(EDITING_TEXT, "label.Text"); + var str = wc.GetAttachedProperty(EDITING_TEXT); + + Console.WriteLine("DONE"); + } + } + + public class WindowlessControl { + internal readonly Dictionary _AttachedProperties = new +Dictionary(); + + public void SetAttachedProperty(AttachedProperty prop, T val) { + Console.WriteLine("SetAttachedProperty 1"); + _AttachedProperties[prop] = val; + Console.WriteLine("SetAttachedProperty 2"); + } + + public T GetAttachedProperty(AttachedProperty prop) { + Console.WriteLine("GET AttachedProperty"); + return (T)(_AttachedProperties[prop] ?? prop.DefaultValue); + } + + public event EventHandler Resize; + + public void InsertControl(int index, WindowlessControl control) { + OnControlAdded(new AxControlEventArgs(control)); + } + + protected virtual void OnControlAdded(AxControlEventArgs e) { } + } + + public struct AttachedProperty { + public T DefaultValue { get; private set; } + + public AttachedProperty(T defaultValue) : this() { + DefaultValue = defaultValue; + } + } +} -- 2.11.4.GIT