From 54b115264f0e56741856666196305db4b70ba169 Mon Sep 17 00:00:00 2001 From: mrward Date: Sun, 5 Sep 2010 17:30:20 +0100 Subject: [PATCH] Move some IronPython and IronRuby designer code generation tests to common Scripting test project. --- .../BackendBindings/Python/PythonBinding.sln | 2 +- .../AppendNullPropertyValueTestFixture.cs | 76 ---------------- .../CallBeginInitOnLoadTestFixture.cs | 78 ++++++---------- ...ustomClassUsingTypeConverterTestFixture.cs | 54 ++--------- ...edSetUsingPropertyDescriptorTestFixture.cs | 63 ++++--------- .../GenerateAcceptButtonFormTestFixture.cs | 90 ++++++------------- ...teUserControlWithNullPropertyValueTests.cs | 45 ++++++++++ .../Test/Designer/LoadFormTestFixtureBase.cs | 44 ++------- .../Test/PythonBinding.Tests.csproj | 4 +- .../Utils/PythonCodeDomSerializerHelper.cs | 20 +++++ .../Test/Utils/PythonComponentWalkerHelper.cs | 21 +++++ .../AppendNullPropertyValueTestFixture.cs | 77 ---------------- .../CallBeginInitOnLoadTestFixture.cs | 47 ++-------- ...ustomClassUsingTypeConverterTestFixture.cs | 52 +---------- ...edSetUsingPropertyDescriptorTestFixture.cs | 57 ++++-------- ...=> GenerateAcceptButtonFormTestFixture.cs} | 0 ...teUserControlWithNullPropertyValueTests.cs | 48 ++++++++++ .../Test/Designer/LoadFormTestFixtureBase.cs | 42 ++------- .../RubyBinding/Test/RubyBinding.Tests.csproj | 6 +- .../Test/Utils/RubyCodeDomSerializerHelper.cs | 20 +++++ .../Test/Utils/RubyComponentWalkerHelper.cs | 21 +++++ .../Src/IScriptingCodeDomSerializer.cs | 1 + .../Test/Designer/CallBeginInitOnLoadTests.cs | 48 ++++++++++ .../GenerateAcceptButtonFormTestsBase.cs | 55 ++++++++++++ .../Designer/GenerateDesignerCodeTestsBase.cs | 18 ++++ ...EnabledUsingPropertyDescriptorTestsBase.cs | 46 ++++++++++ ...erControlWithNullPropertyValueTestsBase.cs | 49 ++++++++++ .../Test/Designer/LoadFormTestsBase.cs | 58 ++++++++++++ .../Test/ICSharpCode.Scripting.Tests.csproj | 7 ++ .../Test/Utils/CustomClassTypeConverter.cs | 55 ++++++++++++ .../Test/Utils/FakeCodeDomSerializer.cs | 5 ++ 31 files changed, 650 insertions(+), 559 deletions(-) delete mode 100644 src/AddIns/BackendBindings/Python/PythonBinding/Test/Designer/AppendNullPropertyValueTestFixture.cs create mode 100644 src/AddIns/BackendBindings/Python/PythonBinding/Test/Designer/GenerateUserControlWithNullPropertyValueTests.cs create mode 100644 src/AddIns/BackendBindings/Python/PythonBinding/Test/Utils/PythonCodeDomSerializerHelper.cs create mode 100644 src/AddIns/BackendBindings/Python/PythonBinding/Test/Utils/PythonComponentWalkerHelper.cs delete mode 100644 src/AddIns/BackendBindings/Ruby/RubyBinding/Test/Designer/AppendNullPropertyValueTestFixture.cs rename src/AddIns/BackendBindings/Ruby/RubyBinding/Test/Designer/{GenerateAcceptButtonTestFixture.cs => GenerateAcceptButtonFormTestFixture.cs} (100%) create mode 100644 src/AddIns/BackendBindings/Ruby/RubyBinding/Test/Designer/GenerateUserControlWithNullPropertyValueTests.cs create mode 100644 src/AddIns/BackendBindings/Ruby/RubyBinding/Test/Utils/RubyCodeDomSerializerHelper.cs create mode 100644 src/AddIns/BackendBindings/Ruby/RubyBinding/Test/Utils/RubyComponentWalkerHelper.cs create mode 100644 src/AddIns/BackendBindings/Scripting/Test/Designer/CallBeginInitOnLoadTests.cs create mode 100644 src/AddIns/BackendBindings/Scripting/Test/Designer/GenerateAcceptButtonFormTestsBase.cs create mode 100644 src/AddIns/BackendBindings/Scripting/Test/Designer/GenerateDesignerCodeTestsBase.cs create mode 100644 src/AddIns/BackendBindings/Scripting/Test/Designer/GenerateEnabledUsingPropertyDescriptorTestsBase.cs create mode 100644 src/AddIns/BackendBindings/Scripting/Test/Designer/GenerateUserControlWithNullPropertyValueTestsBase.cs create mode 100644 src/AddIns/BackendBindings/Scripting/Test/Designer/LoadFormTestsBase.cs create mode 100644 src/AddIns/BackendBindings/Scripting/Test/Utils/CustomClassTypeConverter.cs diff --git a/src/AddIns/BackendBindings/Python/PythonBinding.sln b/src/AddIns/BackendBindings/Python/PythonBinding.sln index be01461ac4..9e95cf6c2e 100644 --- a/src/AddIns/BackendBindings/Python/PythonBinding.sln +++ b/src/AddIns/BackendBindings/Python/PythonBinding.sln @@ -1,7 +1,7 @@  Microsoft Visual Studio Solution File, Format Version 11.00 # Visual Studio 2010 -# SharpDevelop 4.0.0.6511 +# SharpDevelop 4.0.0.6569 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PythonBinding", "PythonBinding\Project\PythonBinding.csproj", "{8D732610-8FC6-43BA-94C9-7126FD7FE361}" EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PythonBinding.Tests", "PythonBinding\Test\PythonBinding.Tests.csproj", "{23B517C9-1ECC-4419-A13F-0B7136D085CB}" diff --git a/src/AddIns/BackendBindings/Python/PythonBinding/Test/Designer/AppendNullPropertyValueTestFixture.cs b/src/AddIns/BackendBindings/Python/PythonBinding/Test/Designer/AppendNullPropertyValueTestFixture.cs deleted file mode 100644 index 6c6934db89..0000000000 --- a/src/AddIns/BackendBindings/Python/PythonBinding/Test/Designer/AppendNullPropertyValueTestFixture.cs +++ /dev/null @@ -1,76 +0,0 @@ -// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt) -// This code is distributed under the GNU LGPL (for details please see \doc\license.txt) - -using System; -using System.ComponentModel; -using System.ComponentModel.Design; -using System.ComponentModel.Design.Serialization; -using System.Drawing; -using System.Windows.Forms; - -using ICSharpCode.PythonBinding; -using ICSharpCode.Scripting.Tests.Utils; -using NUnit.Framework; -using PythonBinding.Tests.Utils; - -namespace PythonBinding.Tests.Designer -{ - /// - /// Tests that a null property value does not cause a NullReferenceException. - /// - [TestFixture] - public class AppendNullPropertyValueTestFixture - { - string generatedPythonCode; - - [TestFixtureSetUp] - public void SetUpFixture() - { - using (DesignSurface designSurface = new DesignSurface(typeof(UserControl))) { - IDesignerHost host = (IDesignerHost)designSurface.GetService(typeof(IDesignerHost)); - IEventBindingService eventBindingService = new MockEventBindingService(host); - UserControl userControl = (UserControl)host.RootComponent; - userControl.ClientSize = new Size(200, 300); - - NullPropertyUserControl control = (NullPropertyUserControl)host.CreateComponent(typeof(NullPropertyUserControl), "userControl1"); - control.Location = new Point(0, 0); - control.Size = new Size(10, 10); - userControl.Controls.Add(control); - - PropertyDescriptorCollection descriptors = TypeDescriptor.GetProperties(userControl); - PropertyDescriptor namePropertyDescriptor = descriptors.Find("Name", false); - namePropertyDescriptor.SetValue(userControl, "MainControl"); - - DesignerSerializationManager serializationManager = new DesignerSerializationManager(host); - using (serializationManager.CreateSession()) { - PythonCodeDomSerializer serializer = new PythonCodeDomSerializer(" "); - generatedPythonCode = serializer.GenerateInitializeComponentMethodBody(host, serializationManager); - } - } - } - - [Test] - public void GeneratedCode() - { - string expectedCode = "self._userControl1 = ICSharpCode.Scripting.Tests.Utils.NullPropertyUserControl()\r\n" + - "self.SuspendLayout()\r\n" + - "# \r\n" + - "# userControl1\r\n" + - "# \r\n" + - "self._userControl1.FooBar = None\r\n" + - "self._userControl1.Location = System.Drawing.Point(0, 0)\r\n" + - "self._userControl1.Name = \"userControl1\"\r\n" + - "self._userControl1.Size = System.Drawing.Size(10, 10)\r\n" + - "self._userControl1.TabIndex = 0\r\n" + - "# \r\n" + - "# MainControl\r\n" + - "# \r\n" + - "self.Controls.Add(self._userControl1)\r\n" + - "self.Name = \"MainControl\"\r\n" + - "self.Size = System.Drawing.Size(200, 300)\r\n" + - "self.ResumeLayout(False)\r\n"; - - Assert.AreEqual(expectedCode, generatedPythonCode, generatedPythonCode); - } - } -} diff --git a/src/AddIns/BackendBindings/Python/PythonBinding/Test/Designer/CallBeginInitOnLoadTestFixture.cs b/src/AddIns/BackendBindings/Python/PythonBinding/Test/Designer/CallBeginInitOnLoadTestFixture.cs index e21097878c..39266656d8 100644 --- a/src/AddIns/BackendBindings/Python/PythonBinding/Test/Designer/CallBeginInitOnLoadTestFixture.cs +++ b/src/AddIns/BackendBindings/Python/PythonBinding/Test/Designer/CallBeginInitOnLoadTestFixture.cs @@ -2,10 +2,8 @@ // This code is distributed under the GNU LGPL (for details please see \doc\license.txt) using System; -using System.Drawing; -using System.Windows.Forms; - -using ICSharpCode.PythonBinding; +using ICSharpCode.Scripting; +using ICSharpCode.Scripting.Tests.Designer; using ICSharpCode.Scripting.Tests.Utils; using NUnit.Framework; using PythonBinding.Tests.Utils; @@ -16,61 +14,35 @@ namespace PythonBinding.Tests.Designer /// Tests that the control's BeginInit and EndInit methods are called. /// [TestFixture] - public class CallBeginInitOnLoadTestFixture : LoadFormTestFixtureBase - { - public override string PythonCode { + public class CallBeginInitOnLoadTestFixture : CallBeginInitOnLoadTestsBase + { + public override string Code { get { - ComponentCreator.AddType("PythonBinding.Tests.Utils.SupportInitCustomControl", typeof(SupportInitCustomControl)); + ComponentCreator.AddType("ICSharpCode.Scripting.Tests.Utils.SupportInitCustomControl", typeof(SupportInitCustomControl)); - return "class TestForm(System.Windows.Forms.Form):\r\n" + - " def InitializeComponent(self):\r\n" + - " self._control = PythonBinding.Tests.Utils.SupportInitCustomControl()\r\n" + - " self._control.BeginInit()\r\n" + - " localVariable = PythonBinding.Tests.Utils.SupportInitCustomControl()\r\n" + - " localVariable.BeginInit()\r\n" + - " self.SuspendLayout()\r\n" + - " # \r\n" + - " # TestForm\r\n" + - " # \r\n" + - " self.AccessibleRole = System.Windows.Forms.AccessibleRole.None\r\n" + - " self.Controls.Add(self._control)\r\n" + - " self.Name = \"TestForm\"\r\n" + - " self._control.EndInit()\r\n" + - " localVariable.EndInit()\r\n" + - " self.ResumeLayout(False)\r\n"; + return + "class TestForm(System.Windows.Forms.Form):\r\n" + + " def InitializeComponent(self):\r\n" + + " self._control = ICSharpCode.Scripting.Tests.Utils.SupportInitCustomControl()\r\n" + + " self._control.BeginInit()\r\n" + + " localVariable = ICSharpCode.Scripting.Tests.Utils.SupportInitCustomControl()\r\n" + + " localVariable.BeginInit()\r\n" + + " self.SuspendLayout()\r\n" + + " # \r\n" + + " # TestForm\r\n" + + " # \r\n" + + " self.AccessibleRole = System.Windows.Forms.AccessibleRole.None\r\n" + + " self.Controls.Add(self._control)\r\n" + + " self.Name = \"TestForm\"\r\n" + + " self._control.EndInit()\r\n" + + " localVariable.EndInit()\r\n" + + " self.ResumeLayout(False)\r\n"; } } - - public SupportInitCustomControl Control { - get { return Form.Controls[0] as SupportInitCustomControl; } - } - - public SupportInitCustomControl LocalControl { - get { return base.ComponentCreator.GetInstance("localVariable") as SupportInitCustomControl; } - } - - [Test] - public void BeginInitCalled() - { - Assert.IsTrue(Control.IsBeginInitCalled); - } - [Test] - public void EndInitCalled() + protected override IComponentWalker CreateComponentWalker(IComponentCreator componentCreator) { - Assert.IsTrue(Control.IsEndInitCalled); + return PythonComponentWalkerHelper.CreateComponentWalker(componentCreator); } - - [Test] - public void BeginInitCalledOnLocalVariable() - { - Assert.IsTrue(LocalControl.IsBeginInitCalled); - } - - [Test] - public void EndInitCalledOnLocalVariable() - { - Assert.IsTrue(LocalControl.IsEndInitCalled); - } } } diff --git a/src/AddIns/BackendBindings/Python/PythonBinding/Test/Designer/ConvertCustomClassUsingTypeConverterTestFixture.cs b/src/AddIns/BackendBindings/Python/PythonBinding/Test/Designer/ConvertCustomClassUsingTypeConverterTestFixture.cs index 34e34ea64e..2753c7c9b6 100644 --- a/src/AddIns/BackendBindings/Python/PythonBinding/Test/Designer/ConvertCustomClassUsingTypeConverterTestFixture.cs +++ b/src/AddIns/BackendBindings/Python/PythonBinding/Test/Designer/ConvertCustomClassUsingTypeConverterTestFixture.cs @@ -2,58 +2,12 @@ // This code is distributed under the GNU LGPL (for details please see \doc\license.txt) using System; -using System.ComponentModel; -using System.ComponentModel.Design; -using System.ComponentModel.Design.Serialization; -using System.Drawing; -using System.Globalization; -using System.Reflection; -using System.Windows.Forms; using ICSharpCode.PythonBinding; +using ICSharpCode.Scripting.Tests.Utils; using NUnit.Framework; namespace PythonBinding.Tests.Designer { - [TypeConverter(typeof(CustomClassTypeConverter))] - class CustomClass - { - public string Name { get; set; } - public string Category { get; set; } - - public CustomClass() - { - } - - public CustomClass(string name, string category) - { - this.Name = name; - this.Category = category; - } - } - - class CustomClassTypeConverter : TypeConverter - { - public override object ConvertTo(ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType) - { - if (destinationType == typeof(InstanceDescriptor)) { - CustomClass c = value as CustomClass; - if (c != null) { - ConstructorInfo info = typeof(CustomClass).GetConstructor(new Type[] {typeof(String), typeof(String)}); - return new InstanceDescriptor(info, new object[] {c.Name, c.Category}); - } - } - return base.ConvertTo(context, culture, value, destinationType); - } - - public override bool CanConvertTo(ITypeDescriptorContext context, Type destinationType) - { - if (destinationType == typeof(InstanceDescriptor)) { - return true; - } - return base.CanConvertTo(context, destinationType); - } - } - /// /// Converts a custom class that has a custom TypeConverter defined. /// This type converter implements an InstanceDescriptor which is used to generate the @@ -61,12 +15,14 @@ namespace PythonBinding.Tests.Designer /// [TestFixture] public class ConvertCustomClassUsingTypeConverterTestFixture - { + { [Test] public void ConvertCustomClass() { CustomClass customClass = new CustomClass("Test", "Category"); - Assert.AreEqual("PythonBinding.Tests.Designer.CustomClass(\"Test\", \"Category\")", PythonPropertyValueAssignment.ToString(customClass)); + string text = PythonPropertyValueAssignment.ToString(customClass); + string expectedText = "ICSharpCode.Scripting.Tests.Utils.CustomClass(\"Test\", \"Category\")"; + Assert.AreEqual(expectedText, text); } } } diff --git a/src/AddIns/BackendBindings/Python/PythonBinding/Test/Designer/EnabledSetUsingPropertyDescriptorTestFixture.cs b/src/AddIns/BackendBindings/Python/PythonBinding/Test/Designer/EnabledSetUsingPropertyDescriptorTestFixture.cs index 40966f7f9c..018c9f4b58 100644 --- a/src/AddIns/BackendBindings/Python/PythonBinding/Test/Designer/EnabledSetUsingPropertyDescriptorTestFixture.cs +++ b/src/AddIns/BackendBindings/Python/PythonBinding/Test/Designer/EnabledSetUsingPropertyDescriptorTestFixture.cs @@ -2,12 +2,8 @@ // This code is distributed under the GNU LGPL (for details please see \doc\license.txt) using System; -using System.ComponentModel; -using System.ComponentModel.Design; -using System.ComponentModel.Design.Serialization; -using System.Drawing; -using System.Windows.Forms; -using ICSharpCode.PythonBinding; +using ICSharpCode.Scripting; +using ICSharpCode.Scripting.Tests.Designer; using NUnit.Framework; using PythonBinding.Tests.Utils; @@ -19,48 +15,27 @@ namespace PythonBinding.Tests.Designer /// user sets Enabled to false in the designer the value is not generated in the InitializeComponent method. /// [TestFixture] - public class EnabledSetUsingPropertyDescriptorTestFixture - { - string generatedPythonCode; - - [TestFixtureSetUp] - public void SetUpFixture() - { - using (DesignSurface designSurface = new DesignSurface(typeof(Form))) { - IDesignerHost host = (IDesignerHost)designSurface.GetService(typeof(IDesignerHost)); - Form form = (Form)host.RootComponent; - form.ClientSize = new Size(284, 264); - form.AllowDrop = false; - form.Enabled = false; - - PropertyDescriptorCollection descriptors = TypeDescriptor.GetProperties(form); - PropertyDescriptor namePropertyDescriptor = descriptors.Find("Name", false); - namePropertyDescriptor.SetValue(form, "MainForm"); - - PropertyDescriptor enabledPropertyDescriptor = descriptors.Find("Enabled", false); - enabledPropertyDescriptor.SetValue(form, false); - - DesignerSerializationManager serializationManager = new DesignerSerializationManager(host); - using (serializationManager.CreateSession()) { - PythonCodeDomSerializer serializer = new PythonCodeDomSerializer(" "); - generatedPythonCode = serializer.GenerateInitializeComponentMethodBody(host, serializationManager); - } - } - } - + public class EnabledSetUsingPropertyDescriptorTestFixture : GenerateEnabledUsingPropertyDescriptorTestsBase + { [Test] public void GeneratedCode() { - string expectedCode = "self.SuspendLayout()\r\n" + - "# \r\n" + - "# MainForm\r\n" + - "# \r\n" + - "self.ClientSize = System.Drawing.Size(284, 264)\r\n" + - "self.Enabled = False\r\n" + - "self.Name = \"MainForm\"\r\n" + - "self.ResumeLayout(False)\r\n"; + string expectedCode = + "self.SuspendLayout()\r\n" + + "# \r\n" + + "# MainForm\r\n" + + "# \r\n" + + "self.ClientSize = System.Drawing.Size(284, 264)\r\n" + + "self.Enabled = False\r\n" + + "self.Name = \"MainForm\"\r\n" + + "self.ResumeLayout(False)\r\n"; - Assert.AreEqual(expectedCode, generatedPythonCode); + Assert.AreEqual(expectedCode, generatedCode); + } + + protected override IScriptingCodeDomSerializer CreateSerializer() + { + return PythonCodeDomSerializerHelper.CreateSerializer(); } } } diff --git a/src/AddIns/BackendBindings/Python/PythonBinding/Test/Designer/GenerateAcceptButtonFormTestFixture.cs b/src/AddIns/BackendBindings/Python/PythonBinding/Test/Designer/GenerateAcceptButtonFormTestFixture.cs index bb1280243e..8e871157b3 100644 --- a/src/AddIns/BackendBindings/Python/PythonBinding/Test/Designer/GenerateAcceptButtonFormTestFixture.cs +++ b/src/AddIns/BackendBindings/Python/PythonBinding/Test/Designer/GenerateAcceptButtonFormTestFixture.cs @@ -2,79 +2,45 @@ // This code is distributed under the GNU LGPL (for details please see \doc\license.txt) using System; -using System.Collections.Generic; -using System.ComponentModel; -using System.ComponentModel.Design; -using System.ComponentModel.Design.Serialization; -using System.Drawing; -using System.Windows.Forms; - -using ICSharpCode.PythonBinding; -using ICSharpCode.Scripting.Tests.Utils; +using ICSharpCode.Scripting; +using ICSharpCode.Scripting.Tests.Designer; using NUnit.Framework; using PythonBinding.Tests.Utils; namespace PythonBinding.Tests.Designer { [TestFixture] - public class GenerateAcceptButtonFormTestFixture + public class GenerateAcceptButtonFormTestFixture : GenerateAcceptButtonFormTestsBase { - string generatedPythonCode; - - [TestFixtureSetUp] - public void SetUpFixture() - { - using (DesignSurface designSurface = new DesignSurface(typeof(Form))) { - IDesignerHost host = (IDesignerHost)designSurface.GetService(typeof(IDesignerHost)); - IEventBindingService eventBindingService = new MockEventBindingService(host); - Form form = (Form)host.RootComponent; - form.ClientSize = new Size(200, 300); - - Button button = (Button)host.CreateComponent(typeof(Button), "button1"); - button.Location = new Point(0, 0); - button.Size = new Size(10, 10); - button.Text = "button1"; - button.UseCompatibleTextRendering = false; - form.Controls.Add(button); - - PropertyDescriptorCollection descriptors = TypeDescriptor.GetProperties(form); - PropertyDescriptor acceptButtonPropertyDescriptor = descriptors.Find("AcceptButton", false); - acceptButtonPropertyDescriptor.SetValue(form, button); - - PropertyDescriptor namePropertyDescriptor = descriptors.Find("Name", false); - namePropertyDescriptor.SetValue(form, "MainForm"); - - DesignerSerializationManager serializationManager = new DesignerSerializationManager(host); - using (serializationManager.CreateSession()) { - PythonCodeDomSerializer serializer = new PythonCodeDomSerializer(" "); - generatedPythonCode = serializer.GenerateInitializeComponentMethodBody(host, serializationManager); - } - } - } - [Test] public void GeneratedCode() { - string expectedCode = "self._button1 = System.Windows.Forms.Button()\r\n" + - "self.SuspendLayout()\r\n" + - "# \r\n" + - "# button1\r\n" + - "# \r\n" + - "self._button1.Location = System.Drawing.Point(0, 0)\r\n" + - "self._button1.Name = \"button1\"\r\n" + - "self._button1.Size = System.Drawing.Size(10, 10)\r\n" + - "self._button1.TabIndex = 0\r\n" + - "self._button1.Text = \"button1\"\r\n" + - "# \r\n" + - "# MainForm\r\n" + - "# \r\n" + - "self.AcceptButton = self._button1\r\n" + - "self.ClientSize = System.Drawing.Size(200, 300)\r\n" + - "self.Controls.Add(self._button1)\r\n" + - "self.Name = \"MainForm\"\r\n" + - "self.ResumeLayout(False)\r\n"; + string expectedCode = + "self._button1 = System.Windows.Forms.Button()\r\n" + + "self.SuspendLayout()\r\n" + + "# \r\n" + + "# button1\r\n" + + "# \r\n" + + "self._button1.Location = System.Drawing.Point(0, 0)\r\n" + + "self._button1.Name = \"button1\"\r\n" + + "self._button1.Size = System.Drawing.Size(10, 10)\r\n" + + "self._button1.TabIndex = 0\r\n" + + "self._button1.Text = \"button1\"\r\n" + + "# \r\n" + + "# MainForm\r\n" + + "# \r\n" + + "self.AcceptButton = self._button1\r\n" + + "self.ClientSize = System.Drawing.Size(200, 300)\r\n" + + "self.Controls.Add(self._button1)\r\n" + + "self.Name = \"MainForm\"\r\n" + + "self.ResumeLayout(False)\r\n"; - Assert.AreEqual(expectedCode, generatedPythonCode, generatedPythonCode); + Assert.AreEqual(expectedCode, generatedCode, generatedCode); + } + + protected override IScriptingCodeDomSerializer CreateSerializer() + { + return PythonCodeDomSerializerHelper.CreateSerializer(); } } } diff --git a/src/AddIns/BackendBindings/Python/PythonBinding/Test/Designer/GenerateUserControlWithNullPropertyValueTests.cs b/src/AddIns/BackendBindings/Python/PythonBinding/Test/Designer/GenerateUserControlWithNullPropertyValueTests.cs new file mode 100644 index 0000000000..891129ce17 --- /dev/null +++ b/src/AddIns/BackendBindings/Python/PythonBinding/Test/Designer/GenerateUserControlWithNullPropertyValueTests.cs @@ -0,0 +1,45 @@ +// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt) +// This code is distributed under the GNU LGPL (for details please see \doc\license.txt) + +using System; +using ICSharpCode.Scripting; +using ICSharpCode.Scripting.Tests.Designer; +using NUnit.Framework; +using PythonBinding.Tests.Utils; + +namespace PythonBinding.Tests.Designer +{ + [TestFixture] + public class GenerateUserControlWithNullPropertyValueTests : GenerateUserControlWithNullPropertyValueTestsBase + { + [Test] + public void GeneratedCode() + { + string expectedCode = + "self._userControl1 = ICSharpCode.Scripting.Tests.Utils.NullPropertyUserControl()\r\n" + + "self.SuspendLayout()\r\n" + + "# \r\n" + + "# userControl1\r\n" + + "# \r\n" + + "self._userControl1.FooBar = None\r\n" + + "self._userControl1.Location = System.Drawing.Point(0, 0)\r\n" + + "self._userControl1.Name = \"userControl1\"\r\n" + + "self._userControl1.Size = System.Drawing.Size(10, 10)\r\n" + + "self._userControl1.TabIndex = 0\r\n" + + "# \r\n" + + "# MainControl\r\n" + + "# \r\n" + + "self.Controls.Add(self._userControl1)\r\n" + + "self.Name = \"MainControl\"\r\n" + + "self.Size = System.Drawing.Size(200, 300)\r\n" + + "self.ResumeLayout(False)\r\n"; + + Assert.AreEqual(expectedCode, generatedCode, generatedCode); + } + + protected override IScriptingCodeDomSerializer CreateSerializer() + { + return PythonCodeDomSerializerHelper.CreateSerializer(); + } + } +} diff --git a/src/AddIns/BackendBindings/Python/PythonBinding/Test/Designer/LoadFormTestFixtureBase.cs b/src/AddIns/BackendBindings/Python/PythonBinding/Test/Designer/LoadFormTestFixtureBase.cs index 253754768a..e0abdce9ca 100644 --- a/src/AddIns/BackendBindings/Python/PythonBinding/Test/Designer/LoadFormTestFixtureBase.cs +++ b/src/AddIns/BackendBindings/Python/PythonBinding/Test/Designer/LoadFormTestFixtureBase.cs @@ -7,6 +7,8 @@ using System.Reflection; using System.Windows.Forms; using ICSharpCode.PythonBinding; +using ICSharpCode.Scripting; +using ICSharpCode.Scripting.Tests.Designer; using ICSharpCode.Scripting.Tests.Utils; using NUnit.Framework; using PythonBinding.Tests.Utils; @@ -16,49 +18,19 @@ namespace PythonBinding.Tests.Designer /// /// Base class for all LoadFormTestFixture classes. /// - public class LoadFormTestFixtureBase - { - MockComponentCreator componentCreator = new MockComponentCreator(); - Form form; - - public LoadFormTestFixtureBase() - { - } - - [TestFixtureSetUp] - public void SetUpFixture() - { - BeforeSetUpFixture(); - PythonComponentWalker walker = new PythonComponentWalker(componentCreator); - form = walker.CreateComponent(PythonCode) as Form; - } - - [TestFixtureTearDown] - public void TearDownFixture() - { - form.Dispose(); - } - - /// - /// Called at the start of SetUpFixture method before anything is setup. - /// - public virtual void BeforeSetUpFixture() + public class LoadFormTestFixtureBase : LoadFormTestsBase + { + protected override IComponentWalker CreateComponentWalker(IComponentCreator componentCreator) { + return PythonComponentWalkerHelper.CreateComponentWalker(componentCreator); } - /// - /// Gets the python code that will be loaded. - /// public virtual string PythonCode { get { return String.Empty; } } - protected MockComponentCreator ComponentCreator { - get { return componentCreator; } + public override string Code { + get { return PythonCode; } } - - protected Form Form { - get { return form; } - } } } diff --git a/src/AddIns/BackendBindings/Python/PythonBinding/Test/PythonBinding.Tests.csproj b/src/AddIns/BackendBindings/Python/PythonBinding/Test/PythonBinding.Tests.csproj index ce2cdd5e51..8e670d7551 100644 --- a/src/AddIns/BackendBindings/Python/PythonBinding/Test/PythonBinding.Tests.csproj +++ b/src/AddIns/BackendBindings/Python/PythonBinding/Test/PythonBinding.Tests.csproj @@ -189,7 +189,6 @@ - @@ -252,6 +251,7 @@ + @@ -424,6 +424,8 @@ + + diff --git a/src/AddIns/BackendBindings/Python/PythonBinding/Test/Utils/PythonCodeDomSerializerHelper.cs b/src/AddIns/BackendBindings/Python/PythonBinding/Test/Utils/PythonCodeDomSerializerHelper.cs new file mode 100644 index 0000000000..48d6e8a7e7 --- /dev/null +++ b/src/AddIns/BackendBindings/Python/PythonBinding/Test/Utils/PythonCodeDomSerializerHelper.cs @@ -0,0 +1,20 @@ +// +// +// +// +// $Revision$ +// + +using System; +using ICSharpCode.PythonBinding; + +namespace PythonBinding.Tests.Utils +{ + public class PythonCodeDomSerializerHelper + { + public static PythonCodeDomSerializer CreateSerializer() + { + return new PythonCodeDomSerializer(); + } + } +} diff --git a/src/AddIns/BackendBindings/Python/PythonBinding/Test/Utils/PythonComponentWalkerHelper.cs b/src/AddIns/BackendBindings/Python/PythonBinding/Test/Utils/PythonComponentWalkerHelper.cs new file mode 100644 index 0000000000..581559451a --- /dev/null +++ b/src/AddIns/BackendBindings/Python/PythonBinding/Test/Utils/PythonComponentWalkerHelper.cs @@ -0,0 +1,21 @@ +// +// +// +// +// $Revision$ +// + +using System; +using ICSharpCode.PythonBinding; +using ICSharpCode.Scripting; + +namespace PythonBinding.Tests.Utils +{ + public class PythonComponentWalkerHelper + { + public static IComponentWalker CreateComponentWalker(IComponentCreator componentCreator) + { + return new PythonComponentWalker(componentCreator); + } + } +} diff --git a/src/AddIns/BackendBindings/Ruby/RubyBinding/Test/Designer/AppendNullPropertyValueTestFixture.cs b/src/AddIns/BackendBindings/Ruby/RubyBinding/Test/Designer/AppendNullPropertyValueTestFixture.cs deleted file mode 100644 index fff34b82dd..0000000000 --- a/src/AddIns/BackendBindings/Ruby/RubyBinding/Test/Designer/AppendNullPropertyValueTestFixture.cs +++ /dev/null @@ -1,77 +0,0 @@ -// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt) -// This code is distributed under the GNU LGPL (for details please see \doc\license.txt) - -using System; -using System.ComponentModel; -using System.ComponentModel.Design; -using System.ComponentModel.Design.Serialization; -using System.Drawing; -using System.Windows.Forms; - -using ICSharpCode.RubyBinding; -using ICSharpCode.Scripting.Tests.Utils; -using NUnit.Framework; -using RubyBinding.Tests.Utils; - -namespace RubyBinding.Tests.Designer -{ - /// - /// Tests that a null property value does not cause a NullReferenceException. - /// - [TestFixture] - public class AppendNullPropertyValueTestFixture - { - string generatedRubyCode; - - [TestFixtureSetUp] - public void SetUpFixture() - { - using (DesignSurface designSurface = new DesignSurface(typeof(UserControl))) { - IDesignerHost host = (IDesignerHost)designSurface.GetService(typeof(IDesignerHost)); - IEventBindingService eventBindingService = new MockEventBindingService(host); - UserControl userControl = (UserControl)host.RootComponent; - userControl.ClientSize = new Size(200, 300); - - NullPropertyUserControl control = (NullPropertyUserControl)host.CreateComponent(typeof(NullPropertyUserControl), "userControl1"); - control.Location = new Point(0, 0); - control.Size = new Size(10, 10); - userControl.Controls.Add(control); - - PropertyDescriptorCollection descriptors = TypeDescriptor.GetProperties(userControl); - PropertyDescriptor namePropertyDescriptor = descriptors.Find("Name", false); - namePropertyDescriptor.SetValue(userControl, "MainControl"); - - DesignerSerializationManager serializationManager = new DesignerSerializationManager(host); - using (serializationManager.CreateSession()) { - RubyCodeDomSerializer serializer = new RubyCodeDomSerializer(" "); - generatedRubyCode = serializer.GenerateInitializeComponentMethodBody(host, serializationManager); - } - } - } - - [Test] - public void GeneratedCode() - { - string expectedCode = - "@userControl1 = ICSharpCode::Scripting::Tests::Utils::NullPropertyUserControl.new()\r\n" + - "self.SuspendLayout()\r\n" + - "# \r\n" + - "# userControl1\r\n" + - "# \r\n" + - "@userControl1.FooBar = nil\r\n" + - "@userControl1.Location = System::Drawing::Point.new(0, 0)\r\n" + - "@userControl1.Name = \"userControl1\"\r\n" + - "@userControl1.Size = System::Drawing::Size.new(10, 10)\r\n" + - "@userControl1.TabIndex = 0\r\n" + - "# \r\n" + - "# MainControl\r\n" + - "# \r\n" + - "self.Controls.Add(@userControl1)\r\n" + - "self.Name = \"MainControl\"\r\n" + - "self.Size = System::Drawing::Size.new(200, 300)\r\n" + - "self.ResumeLayout(false)\r\n"; - - Assert.AreEqual(expectedCode, generatedRubyCode, generatedRubyCode); - } - } -} diff --git a/src/AddIns/BackendBindings/Ruby/RubyBinding/Test/Designer/CallBeginInitOnLoadTestFixture.cs b/src/AddIns/BackendBindings/Ruby/RubyBinding/Test/Designer/CallBeginInitOnLoadTestFixture.cs index 8c4a540448..0637d0a526 100644 --- a/src/AddIns/BackendBindings/Ruby/RubyBinding/Test/Designer/CallBeginInitOnLoadTestFixture.cs +++ b/src/AddIns/BackendBindings/Ruby/RubyBinding/Test/Designer/CallBeginInitOnLoadTestFixture.cs @@ -2,10 +2,8 @@ // This code is distributed under the GNU LGPL (for details please see \doc\license.txt) using System; -using System.Drawing; -using System.Windows.Forms; - -using ICSharpCode.RubyBinding; +using ICSharpCode.Scripting; +using ICSharpCode.Scripting.Tests.Designer; using ICSharpCode.Scripting.Tests.Utils; using NUnit.Framework; using RubyBinding.Tests.Utils; @@ -16,18 +14,18 @@ namespace RubyBinding.Tests.Designer /// Tests that the control's BeginInit and EndInit methods are called. /// [TestFixture] - public class CallBeginInitOnLoadTestFixture : LoadFormTestFixtureBase + public class CallBeginInitOnLoadTestFixture : CallBeginInitOnLoadTestsBase { - public override string RubyCode { + public override string Code { get { - ComponentCreator.AddType("RubyBinding.Tests.Utils.SupportInitCustomControl", typeof(SupportInitCustomControl)); + ComponentCreator.AddType("ICSharpCode.Scripting.Tests.Utils.SupportInitCustomControl", typeof(SupportInitCustomControl)); return "class TestForm < System::Windows::Forms::Form\r\n" + " def InitializeComponent()\r\n" + - " @control = RubyBinding::Tests::Utils::SupportInitCustomControl.new()\r\n" + + " @control = ICSharpCode::Scripting::Tests::Utils::SupportInitCustomControl.new()\r\n" + " @control.clr_member(System::ComponentModel::ISupportInitialize, :BeginInit).call()\r\n" + - " localVariable = RubyBinding::Tests::Utils::SupportInitCustomControl.new()\r\n" + + " localVariable = ICSharpCode::Scripting::Tests::Utils::SupportInitCustomControl.new()\r\n" + " localVariable.clr_member(System::ComponentModel::ISupportInitialize, :BeginInit).call()\r\n" + " self.SuspendLayout()\r\n" + " # \r\n" + @@ -43,37 +41,10 @@ namespace RubyBinding.Tests.Designer "end"; } } - - public SupportInitCustomControl Control { - get { return Form.Controls[0] as SupportInitCustomControl; } - } - - public SupportInitCustomControl LocalControl { - get { return base.ComponentCreator.GetInstance("localVariable") as SupportInitCustomControl; } - } - [Test] - public void BeginInitCalled() - { - Assert.IsTrue(Control.IsBeginInitCalled); - } - - [Test] - public void EndInitCalled() - { - Assert.IsTrue(Control.IsEndInitCalled); - } - - [Test] - public void BeginInitCalledOnLocalVariable() + protected override IComponentWalker CreateComponentWalker(IComponentCreator componentCreator) { - Assert.IsTrue(LocalControl.IsBeginInitCalled); + return RubyComponentWalkerHelper.CreateComponentWalker(componentCreator); } - - [Test] - public void EndInitCalledOnLocalVariable() - { - Assert.IsTrue(LocalControl.IsEndInitCalled); - } } } diff --git a/src/AddIns/BackendBindings/Ruby/RubyBinding/Test/Designer/ConvertCustomClassUsingTypeConverterTestFixture.cs b/src/AddIns/BackendBindings/Ruby/RubyBinding/Test/Designer/ConvertCustomClassUsingTypeConverterTestFixture.cs index 29c182f433..3526e3c076 100644 --- a/src/AddIns/BackendBindings/Ruby/RubyBinding/Test/Designer/ConvertCustomClassUsingTypeConverterTestFixture.cs +++ b/src/AddIns/BackendBindings/Ruby/RubyBinding/Test/Designer/ConvertCustomClassUsingTypeConverterTestFixture.cs @@ -2,58 +2,12 @@ // This code is distributed under the GNU LGPL (for details please see \doc\license.txt) using System; -using System.ComponentModel; -using System.ComponentModel.Design; -using System.ComponentModel.Design.Serialization; -using System.Drawing; -using System.Globalization; -using System.Reflection; -using System.Windows.Forms; using ICSharpCode.RubyBinding; +using ICSharpCode.Scripting.Tests.Utils; using NUnit.Framework; namespace RubyBinding.Tests.Designer { - [TypeConverter(typeof(CustomClassTypeConverter))] - class CustomClass - { - public string Name { get; set; } - public string Category { get; set; } - - public CustomClass() - { - } - - public CustomClass(string name, string category) - { - this.Name = name; - this.Category = category; - } - } - - class CustomClassTypeConverter : TypeConverter - { - public override object ConvertTo(ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType) - { - if (destinationType == typeof(InstanceDescriptor)) { - CustomClass c = value as CustomClass; - if (c != null) { - ConstructorInfo info = typeof(CustomClass).GetConstructor(new Type[] {typeof(String), typeof(String)}); - return new InstanceDescriptor(info, new object[] {c.Name, c.Category}); - } - } - return base.ConvertTo(context, culture, value, destinationType); - } - - public override bool CanConvertTo(ITypeDescriptorContext context, Type destinationType) - { - if (destinationType == typeof(InstanceDescriptor)) { - return true; - } - return base.CanConvertTo(context, destinationType); - } - } - /// /// Converts a custom class that has a custom TypeConverter defined. /// This type converter implements an InstanceDescriptor which is used to generate the @@ -66,7 +20,9 @@ namespace RubyBinding.Tests.Designer public void ConvertCustomClass() { CustomClass customClass = new CustomClass("Test", "Category"); - Assert.AreEqual("RubyBinding::Tests::Designer::CustomClass.new(\"Test\", \"Category\")", RubyPropertyValueAssignment.ToString(customClass)); + string text = RubyPropertyValueAssignment.ToString(customClass); + string expectedText = "ICSharpCode::Scripting::Tests::Utils::CustomClass.new(\"Test\", \"Category\")"; + Assert.AreEqual(expectedText, text); } } } diff --git a/src/AddIns/BackendBindings/Ruby/RubyBinding/Test/Designer/EnabledSetUsingPropertyDescriptorTestFixture.cs b/src/AddIns/BackendBindings/Ruby/RubyBinding/Test/Designer/EnabledSetUsingPropertyDescriptorTestFixture.cs index ddb9c8f562..a52a58b651 100644 --- a/src/AddIns/BackendBindings/Ruby/RubyBinding/Test/Designer/EnabledSetUsingPropertyDescriptorTestFixture.cs +++ b/src/AddIns/BackendBindings/Ruby/RubyBinding/Test/Designer/EnabledSetUsingPropertyDescriptorTestFixture.cs @@ -8,6 +8,8 @@ using System.ComponentModel.Design.Serialization; using System.Drawing; using System.Windows.Forms; using ICSharpCode.RubyBinding; +using ICSharpCode.Scripting; +using ICSharpCode.Scripting.Tests.Designer; using NUnit.Framework; using RubyBinding.Tests.Utils; @@ -19,48 +21,27 @@ namespace RubyBinding.Tests.Designer /// user sets Enabled to false in the designer the value is not generated in the InitializeComponent method. /// [TestFixture] - public class EnabledSetUsingPropertyDescriptorTestFixture - { - string generatedRubyCode; - - [TestFixtureSetUp] - public void SetUpFixture() - { - using (DesignSurface designSurface = new DesignSurface(typeof(Form))) { - IDesignerHost host = (IDesignerHost)designSurface.GetService(typeof(IDesignerHost)); - Form form = (Form)host.RootComponent; - form.ClientSize = new Size(284, 264); - form.AllowDrop = false; - form.Enabled = false; - - PropertyDescriptorCollection descriptors = TypeDescriptor.GetProperties(form); - PropertyDescriptor namePropertyDescriptor = descriptors.Find("Name", false); - namePropertyDescriptor.SetValue(form, "MainForm"); - - PropertyDescriptor enabledPropertyDescriptor = descriptors.Find("Enabled", false); - enabledPropertyDescriptor.SetValue(form, false); - - DesignerSerializationManager serializationManager = new DesignerSerializationManager(host); - using (serializationManager.CreateSession()) { - RubyCodeDomSerializer serializer = new RubyCodeDomSerializer(" "); - generatedRubyCode = serializer.GenerateInitializeComponentMethodBody(host, serializationManager); - } - } - } - + public class EnabledSetUsingPropertyDescriptorTestFixture : GenerateEnabledUsingPropertyDescriptorTestsBase + { [Test] public void GeneratedCode() { - string expectedCode = "self.SuspendLayout()\r\n" + - "# \r\n" + - "# MainForm\r\n" + - "# \r\n" + - "self.ClientSize = System::Drawing::Size.new(284, 264)\r\n" + - "self.Enabled = false\r\n" + - "self.Name = \"MainForm\"\r\n" + - "self.ResumeLayout(false)\r\n"; + string expectedCode = + "self.SuspendLayout()\r\n" + + "# \r\n" + + "# MainForm\r\n" + + "# \r\n" + + "self.ClientSize = System::Drawing::Size.new(284, 264)\r\n" + + "self.Enabled = false\r\n" + + "self.Name = \"MainForm\"\r\n" + + "self.ResumeLayout(false)\r\n"; - Assert.AreEqual(expectedCode, generatedRubyCode); + Assert.AreEqual(expectedCode, generatedCode); + } + + protected override IScriptingCodeDomSerializer CreateSerializer() + { + return RubyCodeDomSerializerHelper.CreateSerializer(); } } } diff --git a/src/AddIns/BackendBindings/Ruby/RubyBinding/Test/Designer/GenerateAcceptButtonTestFixture.cs b/src/AddIns/BackendBindings/Ruby/RubyBinding/Test/Designer/GenerateAcceptButtonFormTestFixture.cs similarity index 100% rename from src/AddIns/BackendBindings/Ruby/RubyBinding/Test/Designer/GenerateAcceptButtonTestFixture.cs rename to src/AddIns/BackendBindings/Ruby/RubyBinding/Test/Designer/GenerateAcceptButtonFormTestFixture.cs diff --git a/src/AddIns/BackendBindings/Ruby/RubyBinding/Test/Designer/GenerateUserControlWithNullPropertyValueTests.cs b/src/AddIns/BackendBindings/Ruby/RubyBinding/Test/Designer/GenerateUserControlWithNullPropertyValueTests.cs new file mode 100644 index 0000000000..33124d674c --- /dev/null +++ b/src/AddIns/BackendBindings/Ruby/RubyBinding/Test/Designer/GenerateUserControlWithNullPropertyValueTests.cs @@ -0,0 +1,48 @@ +// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt) +// This code is distributed under the GNU LGPL (for details please see \doc\license.txt) + +using System; +using ICSharpCode.Scripting; +using ICSharpCode.Scripting.Tests.Designer; +using NUnit.Framework; +using RubyBinding.Tests.Utils; + +namespace RubyBinding.Tests.Designer +{ + /// + /// Tests that a null property value does not cause a NullReferenceException. + /// + [TestFixture] + public class GenerateUserControlWithNullPropertyValueTests : GenerateUserControlWithNullPropertyValueTestsBase + { + [Test] + public void GeneratedCode() + { + string expectedCode = + "@userControl1 = ICSharpCode::Scripting::Tests::Utils::NullPropertyUserControl.new()\r\n" + + "self.SuspendLayout()\r\n" + + "# \r\n" + + "# userControl1\r\n" + + "# \r\n" + + "@userControl1.FooBar = nil\r\n" + + "@userControl1.Location = System::Drawing::Point.new(0, 0)\r\n" + + "@userControl1.Name = \"userControl1\"\r\n" + + "@userControl1.Size = System::Drawing::Size.new(10, 10)\r\n" + + "@userControl1.TabIndex = 0\r\n" + + "# \r\n" + + "# MainControl\r\n" + + "# \r\n" + + "self.Controls.Add(@userControl1)\r\n" + + "self.Name = \"MainControl\"\r\n" + + "self.Size = System::Drawing::Size.new(200, 300)\r\n" + + "self.ResumeLayout(false)\r\n"; + + Assert.AreEqual(expectedCode, generatedCode, generatedCode); + } + + protected override IScriptingCodeDomSerializer CreateSerializer() + { + return RubyCodeDomSerializerHelper.CreateSerializer(); + } + } +} diff --git a/src/AddIns/BackendBindings/Ruby/RubyBinding/Test/Designer/LoadFormTestFixtureBase.cs b/src/AddIns/BackendBindings/Ruby/RubyBinding/Test/Designer/LoadFormTestFixtureBase.cs index 4b32d2d83e..276c4a1e6e 100644 --- a/src/AddIns/BackendBindings/Ruby/RubyBinding/Test/Designer/LoadFormTestFixtureBase.cs +++ b/src/AddIns/BackendBindings/Ruby/RubyBinding/Test/Designer/LoadFormTestFixtureBase.cs @@ -5,8 +5,9 @@ using System; using System.Drawing; using System.Reflection; using System.Windows.Forms; - using ICSharpCode.RubyBinding; +using ICSharpCode.Scripting; +using ICSharpCode.Scripting.Tests.Designer; using ICSharpCode.Scripting.Tests.Utils; using NUnit.Framework; using RubyBinding.Tests.Utils; @@ -16,34 +17,11 @@ namespace RubyBinding.Tests.Designer /// /// Base class for all LoadFormTestFixture classes. /// - public class LoadFormTestFixtureBase - { - MockComponentCreator componentCreator = new MockComponentCreator(); - Form form; - - public LoadFormTestFixtureBase() - { - } - - [TestFixtureSetUp] - public void SetUpFixture() - { - BeforeSetUpFixture(); - RubyComponentWalker walker = new RubyComponentWalker(componentCreator); - form = walker.CreateComponent(RubyCode) as Form; - } - - [TestFixtureTearDown] - public void TearDownFixture() - { - form.Dispose(); - } - - /// - /// Called at the start of SetUpFixture method before anything is setup. - /// - public virtual void BeforeSetUpFixture() + public class LoadFormTestFixtureBase : LoadFormTestsBase + { + protected override IComponentWalker CreateComponentWalker(IComponentCreator componentCreator) { + return RubyComponentWalkerHelper.CreateComponentWalker(componentCreator); } /// @@ -53,12 +31,8 @@ namespace RubyBinding.Tests.Designer get { return String.Empty; } } - protected MockComponentCreator ComponentCreator { - get { return componentCreator; } + public override string Code { + get { return RubyCode; } } - - protected Form Form { - get { return form; } - } } } diff --git a/src/AddIns/BackendBindings/Ruby/RubyBinding/Test/RubyBinding.Tests.csproj b/src/AddIns/BackendBindings/Ruby/RubyBinding/Test/RubyBinding.Tests.csproj index aa192a022e..681f7b8d66 100644 --- a/src/AddIns/BackendBindings/Ruby/RubyBinding/Test/RubyBinding.Tests.csproj +++ b/src/AddIns/BackendBindings/Ruby/RubyBinding/Test/RubyBinding.Tests.csproj @@ -163,7 +163,7 @@ - + @@ -182,7 +182,7 @@ - + @@ -319,6 +319,8 @@ + + diff --git a/src/AddIns/BackendBindings/Ruby/RubyBinding/Test/Utils/RubyCodeDomSerializerHelper.cs b/src/AddIns/BackendBindings/Ruby/RubyBinding/Test/Utils/RubyCodeDomSerializerHelper.cs new file mode 100644 index 0000000000..735247de4e --- /dev/null +++ b/src/AddIns/BackendBindings/Ruby/RubyBinding/Test/Utils/RubyCodeDomSerializerHelper.cs @@ -0,0 +1,20 @@ +// +// +// +// +// $Revision$ +// + +using System; +using ICSharpCode.RubyBinding; + +namespace RubyBinding.Tests.Utils +{ + public class RubyCodeDomSerializerHelper + { + public static RubyCodeDomSerializer CreateSerializer() + { + return new RubyCodeDomSerializer(); + } + } +} diff --git a/src/AddIns/BackendBindings/Ruby/RubyBinding/Test/Utils/RubyComponentWalkerHelper.cs b/src/AddIns/BackendBindings/Ruby/RubyBinding/Test/Utils/RubyComponentWalkerHelper.cs new file mode 100644 index 0000000000..e0b90ea0d8 --- /dev/null +++ b/src/AddIns/BackendBindings/Ruby/RubyBinding/Test/Utils/RubyComponentWalkerHelper.cs @@ -0,0 +1,21 @@ +// +// +// +// +// $Revision$ +// + +using System; +using ICSharpCode.RubyBinding; +using ICSharpCode.Scripting; + +namespace RubyBinding.Tests.Utils +{ + public class RubyComponentWalkerHelper + { + public static IComponentWalker CreateComponentWalker(IComponentCreator componentCreator) + { + return new RubyComponentWalker(componentCreator); + } + } +} diff --git a/src/AddIns/BackendBindings/Scripting/Project/Src/IScriptingCodeDomSerializer.cs b/src/AddIns/BackendBindings/Scripting/Project/Src/IScriptingCodeDomSerializer.cs index 7a075fc974..a7888e04c2 100644 --- a/src/AddIns/BackendBindings/Scripting/Project/Src/IScriptingCodeDomSerializer.cs +++ b/src/AddIns/BackendBindings/Scripting/Project/Src/IScriptingCodeDomSerializer.cs @@ -14,5 +14,6 @@ namespace ICSharpCode.Scripting public interface IScriptingCodeDomSerializer { string GenerateInitializeComponentMethodBody(IDesignerHost host, IDesignerSerializationManager serializationManager, string rootNamespace, int initialIndent); + string GenerateInitializeComponentMethodBody(IDesignerHost host, IDesignerSerializationManager serializationManager); } } diff --git a/src/AddIns/BackendBindings/Scripting/Test/Designer/CallBeginInitOnLoadTests.cs b/src/AddIns/BackendBindings/Scripting/Test/Designer/CallBeginInitOnLoadTests.cs new file mode 100644 index 0000000000..9a61581a5d --- /dev/null +++ b/src/AddIns/BackendBindings/Scripting/Test/Designer/CallBeginInitOnLoadTests.cs @@ -0,0 +1,48 @@ +// +// +// +// +// $Revision$ +// + +using System; +using ICSharpCode.Scripting.Tests.Utils; +using NUnit.Framework; + +namespace ICSharpCode.Scripting.Tests.Designer +{ + public abstract class CallBeginInitOnLoadTestsBase : LoadFormTestsBase + { + public SupportInitCustomControl Control { + get { return Form.Controls[0] as SupportInitCustomControl; } + } + + public SupportInitCustomControl LocalControl { + get { return base.ComponentCreator.GetInstance("localVariable") as SupportInitCustomControl; } + } + + [Test] + public void BeginInitCalled() + { + Assert.IsTrue(Control.IsBeginInitCalled); + } + + [Test] + public void EndInitCalled() + { + Assert.IsTrue(Control.IsEndInitCalled); + } + + [Test] + public void BeginInitCalledOnLocalVariable() + { + Assert.IsTrue(LocalControl.IsBeginInitCalled); + } + + [Test] + public void EndInitCalledOnLocalVariable() + { + Assert.IsTrue(LocalControl.IsEndInitCalled); + } + } +} diff --git a/src/AddIns/BackendBindings/Scripting/Test/Designer/GenerateAcceptButtonFormTestsBase.cs b/src/AddIns/BackendBindings/Scripting/Test/Designer/GenerateAcceptButtonFormTestsBase.cs new file mode 100644 index 0000000000..88c395645d --- /dev/null +++ b/src/AddIns/BackendBindings/Scripting/Test/Designer/GenerateAcceptButtonFormTestsBase.cs @@ -0,0 +1,55 @@ +// +// +// +// +// $Revision$ +// + +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.ComponentModel.Design; +using System.ComponentModel.Design.Serialization; +using System.Drawing; +using System.Windows.Forms; + +using ICSharpCode.Scripting; +using ICSharpCode.Scripting.Tests.Utils; +using NUnit.Framework; + +namespace ICSharpCode.Scripting.Tests.Designer +{ + public abstract class GenerateAcceptButtonFormTestsBase : GenerateDesignerCodeTestsBase + { + [TestFixtureSetUp] + public void SetUpFixture() + { + using (DesignSurface designSurface = new DesignSurface(typeof(Form))) { + IDesignerHost host = (IDesignerHost)designSurface.GetService(typeof(IDesignerHost)); + IEventBindingService eventBindingService = new MockEventBindingService(host); + Form form = (Form)host.RootComponent; + form.ClientSize = new Size(200, 300); + + Button button = (Button)host.CreateComponent(typeof(Button), "button1"); + button.Location = new Point(0, 0); + button.Size = new Size(10, 10); + button.Text = "button1"; + button.UseCompatibleTextRendering = false; + form.Controls.Add(button); + + PropertyDescriptorCollection descriptors = TypeDescriptor.GetProperties(form); + PropertyDescriptor acceptButtonPropertyDescriptor = descriptors.Find("AcceptButton", false); + acceptButtonPropertyDescriptor.SetValue(form, button); + + PropertyDescriptor namePropertyDescriptor = descriptors.Find("Name", false); + namePropertyDescriptor.SetValue(form, "MainForm"); + + DesignerSerializationManager serializationManager = new DesignerSerializationManager(host); + using (serializationManager.CreateSession()) { + IScriptingCodeDomSerializer serializer = CreateSerializer(); + generatedCode = serializer.GenerateInitializeComponentMethodBody(host, serializationManager); + } + } + } + } +} diff --git a/src/AddIns/BackendBindings/Scripting/Test/Designer/GenerateDesignerCodeTestsBase.cs b/src/AddIns/BackendBindings/Scripting/Test/Designer/GenerateDesignerCodeTestsBase.cs new file mode 100644 index 0000000000..a64ab22ccb --- /dev/null +++ b/src/AddIns/BackendBindings/Scripting/Test/Designer/GenerateDesignerCodeTestsBase.cs @@ -0,0 +1,18 @@ +// +// +// +// +// $Revision$ +// + +using System; + +namespace ICSharpCode.Scripting.Tests.Designer +{ + public abstract class GenerateDesignerCodeTestsBase + { + protected string generatedCode; + + protected abstract IScriptingCodeDomSerializer CreateSerializer(); + } +} diff --git a/src/AddIns/BackendBindings/Scripting/Test/Designer/GenerateEnabledUsingPropertyDescriptorTestsBase.cs b/src/AddIns/BackendBindings/Scripting/Test/Designer/GenerateEnabledUsingPropertyDescriptorTestsBase.cs new file mode 100644 index 0000000000..08f41839eb --- /dev/null +++ b/src/AddIns/BackendBindings/Scripting/Test/Designer/GenerateEnabledUsingPropertyDescriptorTestsBase.cs @@ -0,0 +1,46 @@ +// +// +// +// +// $Revision$ +// + +using System; +using System.ComponentModel; +using System.ComponentModel.Design; +using System.ComponentModel.Design.Serialization; +using System.Drawing; +using System.Windows.Forms; +using ICSharpCode.Scripting; +using NUnit.Framework; + +namespace ICSharpCode.Scripting.Tests.Designer +{ + public abstract class GenerateEnabledUsingPropertyDescriptorTestsBase : GenerateDesignerCodeTestsBase + { + [TestFixtureSetUp] + public void SetUpFixture() + { + using (DesignSurface designSurface = new DesignSurface(typeof(Form))) { + IDesignerHost host = (IDesignerHost)designSurface.GetService(typeof(IDesignerHost)); + Form form = (Form)host.RootComponent; + form.ClientSize = new Size(284, 264); + form.AllowDrop = false; + form.Enabled = false; + + PropertyDescriptorCollection descriptors = TypeDescriptor.GetProperties(form); + PropertyDescriptor namePropertyDescriptor = descriptors.Find("Name", false); + namePropertyDescriptor.SetValue(form, "MainForm"); + + PropertyDescriptor enabledPropertyDescriptor = descriptors.Find("Enabled", false); + enabledPropertyDescriptor.SetValue(form, false); + + DesignerSerializationManager serializationManager = new DesignerSerializationManager(host); + using (serializationManager.CreateSession()) { + IScriptingCodeDomSerializer serializer = CreateSerializer(); + generatedCode = serializer.GenerateInitializeComponentMethodBody(host, serializationManager); + } + } + } + } +} diff --git a/src/AddIns/BackendBindings/Scripting/Test/Designer/GenerateUserControlWithNullPropertyValueTestsBase.cs b/src/AddIns/BackendBindings/Scripting/Test/Designer/GenerateUserControlWithNullPropertyValueTestsBase.cs new file mode 100644 index 0000000000..af8c4cf850 --- /dev/null +++ b/src/AddIns/BackendBindings/Scripting/Test/Designer/GenerateUserControlWithNullPropertyValueTestsBase.cs @@ -0,0 +1,49 @@ +// +// +// +// +// $Revision$ +// + +using System; +using System.ComponentModel; +using System.ComponentModel.Design; +using System.ComponentModel.Design.Serialization; +using System.Drawing; +using System.Windows.Forms; + +using ICSharpCode.Scripting; +using ICSharpCode.Scripting.Tests.Utils; +using NUnit.Framework; + +namespace ICSharpCode.Scripting.Tests.Designer +{ + public abstract class GenerateUserControlWithNullPropertyValueTestsBase : GenerateDesignerCodeTestsBase + { + [TestFixtureSetUp] + public void SetUpFixture() + { + using (DesignSurface designSurface = new DesignSurface(typeof(UserControl))) { + IDesignerHost host = (IDesignerHost)designSurface.GetService(typeof(IDesignerHost)); + IEventBindingService eventBindingService = new MockEventBindingService(host); + UserControl userControl = (UserControl)host.RootComponent; + userControl.ClientSize = new Size(200, 300); + + NullPropertyUserControl control = (NullPropertyUserControl)host.CreateComponent(typeof(NullPropertyUserControl), "userControl1"); + control.Location = new Point(0, 0); + control.Size = new Size(10, 10); + userControl.Controls.Add(control); + + PropertyDescriptorCollection descriptors = TypeDescriptor.GetProperties(userControl); + PropertyDescriptor namePropertyDescriptor = descriptors.Find("Name", false); + namePropertyDescriptor.SetValue(userControl, "MainControl"); + + DesignerSerializationManager serializationManager = new DesignerSerializationManager(host); + using (serializationManager.CreateSession()) { + IScriptingCodeDomSerializer serializer = CreateSerializer(); + generatedCode = serializer.GenerateInitializeComponentMethodBody(host, serializationManager); + } + } + } + } +} diff --git a/src/AddIns/BackendBindings/Scripting/Test/Designer/LoadFormTestsBase.cs b/src/AddIns/BackendBindings/Scripting/Test/Designer/LoadFormTestsBase.cs new file mode 100644 index 0000000000..2574e6ed29 --- /dev/null +++ b/src/AddIns/BackendBindings/Scripting/Test/Designer/LoadFormTestsBase.cs @@ -0,0 +1,58 @@ +// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt) +// This code is distributed under the GNU LGPL (for details please see \doc\license.txt) + +using System; +using System.Drawing; +using System.Reflection; +using System.Windows.Forms; + +using ICSharpCode.Scripting; +using ICSharpCode.Scripting.Tests.Utils; +using NUnit.Framework; + +namespace ICSharpCode.Scripting.Tests.Designer +{ + public abstract class LoadFormTestsBase + { + MockComponentCreator componentCreator = new MockComponentCreator(); + Form form; + + [TestFixtureSetUp] + public void SetUpFixture() + { + BeforeSetUpFixture(); + IComponentWalker walker = CreateComponentWalker(componentCreator); + form = walker.CreateComponent(Code) as Form; + } + + [TestFixtureTearDown] + public void TearDownFixture() + { + form.Dispose(); + } + + /// + /// Called at the start of SetUpFixture method before anything is setup. + /// + public virtual void BeforeSetUpFixture() + { + } + + protected abstract IComponentWalker CreateComponentWalker(IComponentCreator componentCreator); + + /// + /// Gets the code that will be loaded. + /// + public virtual string Code { + get { return String.Empty; } + } + + protected MockComponentCreator ComponentCreator { + get { return componentCreator; } + } + + protected Form Form { + get { return form; } + } + } +} diff --git a/src/AddIns/BackendBindings/Scripting/Test/ICSharpCode.Scripting.Tests.csproj b/src/AddIns/BackendBindings/Scripting/Test/ICSharpCode.Scripting.Tests.csproj index 5c8ef8a99c..d5cb130b6a 100644 --- a/src/AddIns/BackendBindings/Scripting/Test/ICSharpCode.Scripting.Tests.csproj +++ b/src/AddIns/BackendBindings/Scripting/Test/ICSharpCode.Scripting.Tests.csproj @@ -76,6 +76,12 @@ + + + + + + @@ -90,6 +96,7 @@ + diff --git a/src/AddIns/BackendBindings/Scripting/Test/Utils/CustomClassTypeConverter.cs b/src/AddIns/BackendBindings/Scripting/Test/Utils/CustomClassTypeConverter.cs new file mode 100644 index 0000000000..5fd330240d --- /dev/null +++ b/src/AddIns/BackendBindings/Scripting/Test/Utils/CustomClassTypeConverter.cs @@ -0,0 +1,55 @@ +// +// +// +// +// $Revision$ +// + +using System; +using System.ComponentModel; +using System.ComponentModel.Design.Serialization; +using System.Globalization; +using System.Reflection; + +namespace ICSharpCode.Scripting.Tests.Utils +{ + [TypeConverter(typeof(CustomClassTypeConverter))] + public class CustomClass + { + public string Name { get; set; } + public string Category { get; set; } + + public CustomClass() + { + } + + public CustomClass(string name, string category) + { + this.Name = name; + this.Category = category; + } + } + + public class CustomClassTypeConverter : TypeConverter + { + public override object ConvertTo(ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType) + { + if (destinationType == typeof(InstanceDescriptor)) { + CustomClass c = value as CustomClass; + if (c != null) { + ConstructorInfo info = typeof(CustomClass).GetConstructor(new Type[] {typeof(String), typeof(String)}); + return new InstanceDescriptor(info, new object[] {c.Name, c.Category}); + } + } + return base.ConvertTo(context, culture, value, destinationType); + } + + public override bool CanConvertTo(ITypeDescriptorContext context, Type destinationType) + { + if (destinationType == typeof(InstanceDescriptor)) { + return true; + } + return base.CanConvertTo(context, destinationType); + } + } +} diff --git a/src/AddIns/BackendBindings/Scripting/Test/Utils/FakeCodeDomSerializer.cs b/src/AddIns/BackendBindings/Scripting/Test/Utils/FakeCodeDomSerializer.cs index e4b06b79f2..81185484d0 100644 --- a/src/AddIns/BackendBindings/Scripting/Test/Utils/FakeCodeDomSerializer.cs +++ b/src/AddIns/BackendBindings/Scripting/Test/Utils/FakeCodeDomSerializer.cs @@ -29,5 +29,10 @@ namespace ICSharpCode.Scripting.Tests.Utils return MethodBodyToReturnFromGenerateMethodBodyCall; } + + public string GenerateInitializeComponentMethodBody(IDesignerHost host, IDesignerSerializationManager serializationManager) + { + return GenerateInitializeComponentMethodBody(host, serializationManager, String.Empty, 0); + } } }