Browse Source

Move some IronPython and IronRuby designer code generation tests to common Scripting test project.

pull/1/head
mrward 15 years ago
parent
commit
54b115264f
  1. 2
      src/AddIns/BackendBindings/Python/PythonBinding.sln
  2. 76
      src/AddIns/BackendBindings/Python/PythonBinding/Test/Designer/AppendNullPropertyValueTestFixture.cs
  3. 78
      src/AddIns/BackendBindings/Python/PythonBinding/Test/Designer/CallBeginInitOnLoadTestFixture.cs
  4. 52
      src/AddIns/BackendBindings/Python/PythonBinding/Test/Designer/ConvertCustomClassUsingTypeConverterTestFixture.cs
  5. 61
      src/AddIns/BackendBindings/Python/PythonBinding/Test/Designer/EnabledSetUsingPropertyDescriptorTestFixture.cs
  6. 90
      src/AddIns/BackendBindings/Python/PythonBinding/Test/Designer/GenerateAcceptButtonFormTestFixture.cs
  7. 45
      src/AddIns/BackendBindings/Python/PythonBinding/Test/Designer/GenerateUserControlWithNullPropertyValueTests.cs
  8. 42
      src/AddIns/BackendBindings/Python/PythonBinding/Test/Designer/LoadFormTestFixtureBase.cs
  9. 4
      src/AddIns/BackendBindings/Python/PythonBinding/Test/PythonBinding.Tests.csproj
  10. 20
      src/AddIns/BackendBindings/Python/PythonBinding/Test/Utils/PythonCodeDomSerializerHelper.cs
  11. 21
      src/AddIns/BackendBindings/Python/PythonBinding/Test/Utils/PythonComponentWalkerHelper.cs
  12. 77
      src/AddIns/BackendBindings/Ruby/RubyBinding/Test/Designer/AppendNullPropertyValueTestFixture.cs
  13. 47
      src/AddIns/BackendBindings/Ruby/RubyBinding/Test/Designer/CallBeginInitOnLoadTestFixture.cs
  14. 52
      src/AddIns/BackendBindings/Ruby/RubyBinding/Test/Designer/ConvertCustomClassUsingTypeConverterTestFixture.cs
  15. 55
      src/AddIns/BackendBindings/Ruby/RubyBinding/Test/Designer/EnabledSetUsingPropertyDescriptorTestFixture.cs
  16. 0
      src/AddIns/BackendBindings/Ruby/RubyBinding/Test/Designer/GenerateAcceptButtonFormTestFixture.cs
  17. 48
      src/AddIns/BackendBindings/Ruby/RubyBinding/Test/Designer/GenerateUserControlWithNullPropertyValueTests.cs
  18. 40
      src/AddIns/BackendBindings/Ruby/RubyBinding/Test/Designer/LoadFormTestFixtureBase.cs
  19. 6
      src/AddIns/BackendBindings/Ruby/RubyBinding/Test/RubyBinding.Tests.csproj
  20. 20
      src/AddIns/BackendBindings/Ruby/RubyBinding/Test/Utils/RubyCodeDomSerializerHelper.cs
  21. 21
      src/AddIns/BackendBindings/Ruby/RubyBinding/Test/Utils/RubyComponentWalkerHelper.cs
  22. 1
      src/AddIns/BackendBindings/Scripting/Project/Src/IScriptingCodeDomSerializer.cs
  23. 48
      src/AddIns/BackendBindings/Scripting/Test/Designer/CallBeginInitOnLoadTests.cs
  24. 55
      src/AddIns/BackendBindings/Scripting/Test/Designer/GenerateAcceptButtonFormTestsBase.cs
  25. 18
      src/AddIns/BackendBindings/Scripting/Test/Designer/GenerateDesignerCodeTestsBase.cs
  26. 46
      src/AddIns/BackendBindings/Scripting/Test/Designer/GenerateEnabledUsingPropertyDescriptorTestsBase.cs
  27. 49
      src/AddIns/BackendBindings/Scripting/Test/Designer/GenerateUserControlWithNullPropertyValueTestsBase.cs
  28. 58
      src/AddIns/BackendBindings/Scripting/Test/Designer/LoadFormTestsBase.cs
  29. 7
      src/AddIns/BackendBindings/Scripting/Test/ICSharpCode.Scripting.Tests.csproj
  30. 55
      src/AddIns/BackendBindings/Scripting/Test/Utils/CustomClassTypeConverter.cs
  31. 5
      src/AddIns/BackendBindings/Scripting/Test/Utils/FakeCodeDomSerializer.cs

2
src/AddIns/BackendBindings/Python/PythonBinding.sln

@ -1,7 +1,7 @@ @@ -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}"

76
src/AddIns/BackendBindings/Python/PythonBinding/Test/Designer/AppendNullPropertyValueTestFixture.cs

@ -1,76 +0,0 @@ @@ -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
{
/// <summary>
/// Tests that a null property value does not cause a NullReferenceException.
/// </summary>
[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);
}
}
}

78
src/AddIns/BackendBindings/Python/PythonBinding/Test/Designer/CallBeginInitOnLoadTestFixture.cs

@ -2,10 +2,8 @@ @@ -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 @@ -16,61 +14,35 @@ namespace PythonBinding.Tests.Designer
/// Tests that the control's BeginInit and EndInit methods are called.
/// </summary>
[TestFixture]
public class CallBeginInitOnLoadTestFixture : LoadFormTestFixtureBase
public class CallBeginInitOnLoadTestFixture : CallBeginInitOnLoadTestsBase
{
public override string PythonCode {
public override string Code {
get {
ComponentCreator.AddType("PythonBinding.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";
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 = 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()
{
Assert.IsTrue(Control.IsEndInitCalled);
}
[Test]
public void BeginInitCalledOnLocalVariable()
{
Assert.IsTrue(LocalControl.IsBeginInitCalled);
}
[Test]
public void EndInitCalledOnLocalVariable()
protected override IComponentWalker CreateComponentWalker(IComponentCreator componentCreator)
{
Assert.IsTrue(LocalControl.IsEndInitCalled);
return PythonComponentWalkerHelper.CreateComponentWalker(componentCreator);
}
}
}

52
src/AddIns/BackendBindings/Python/PythonBinding/Test/Designer/ConvertCustomClassUsingTypeConverterTestFixture.cs

@ -2,58 +2,12 @@ @@ -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);
}
}
/// <summary>
/// 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 PythonBinding.Tests.Designer @@ -66,7 +20,9 @@ namespace PythonBinding.Tests.Designer
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);
}
}
}

61
src/AddIns/BackendBindings/Python/PythonBinding/Test/Designer/EnabledSetUsingPropertyDescriptorTestFixture.cs

@ -2,12 +2,8 @@ @@ -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 @@ -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.
/// </summary>
[TestFixture]
public class EnabledSetUsingPropertyDescriptorTestFixture
public class EnabledSetUsingPropertyDescriptorTestFixture : GenerateEnabledUsingPropertyDescriptorTestsBase
{
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);
}
}
}
[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, generatedCode);
}
Assert.AreEqual(expectedCode, generatedPythonCode);
protected override IScriptingCodeDomSerializer CreateSerializer()
{
return PythonCodeDomSerializerHelper.CreateSerializer();
}
}
}

90
src/AddIns/BackendBindings/Python/PythonBinding/Test/Designer/GenerateAcceptButtonFormTestFixture.cs

@ -2,79 +2,45 @@ @@ -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, generatedCode, generatedCode);
}
Assert.AreEqual(expectedCode, generatedPythonCode, generatedPythonCode);
protected override IScriptingCodeDomSerializer CreateSerializer()
{
return PythonCodeDomSerializerHelper.CreateSerializer();
}
}
}

45
src/AddIns/BackendBindings/Python/PythonBinding/Test/Designer/GenerateUserControlWithNullPropertyValueTests.cs

@ -0,0 +1,45 @@ @@ -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();
}
}
}

42
src/AddIns/BackendBindings/Python/PythonBinding/Test/Designer/LoadFormTestFixtureBase.cs

@ -7,6 +7,8 @@ using System.Reflection; @@ -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 @@ -16,49 +18,19 @@ namespace PythonBinding.Tests.Designer
/// <summary>
/// Base class for all LoadFormTestFixture classes.
/// </summary>
public class LoadFormTestFixtureBase
public class LoadFormTestFixtureBase : LoadFormTestsBase
{
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();
}
/// <summary>
/// Called at the start of SetUpFixture method before anything is setup.
/// </summary>
public virtual void BeforeSetUpFixture()
protected override IComponentWalker CreateComponentWalker(IComponentCreator componentCreator)
{
return PythonComponentWalkerHelper.CreateComponentWalker(componentCreator);
}
/// <summary>
/// Gets the python code that will be loaded.
/// </summary>
public virtual string PythonCode {
get { return String.Empty; }
}
protected MockComponentCreator ComponentCreator {
get { return componentCreator; }
}
protected Form Form {
get { return form; }
public override string Code {
get { return PythonCode; }
}
}
}

4
src/AddIns/BackendBindings/Python/PythonBinding/Test/PythonBinding.Tests.csproj

@ -189,7 +189,6 @@ @@ -189,7 +189,6 @@
<Compile Include="Converter\VBStringConcatTestFixture.cs" />
<Compile Include="Converter\WhileLoopConversionTestFixture.cs" />
<Compile Include="Converter\XmlDocCommentConversionTestFixture.cs" />
<Compile Include="Designer\AppendNullPropertyValueTestFixture.cs" />
<Compile Include="Designer\CallBeginInitOnLoadTestFixture.cs" />
<Compile Include="Designer\ConvertCustomClassUsingTypeConverterTestFixture.cs" />
<Compile Include="Designer\CursorTypeResolutionTestFixture.cs" />
@ -252,6 +251,7 @@ @@ -252,6 +251,7 @@
<Compile Include="Designer\GenerateTimerTestFixture.cs" />
<Compile Include="Designer\GenerateToolTipFormTestFixture.cs" />
<Compile Include="Designer\GenerateTreeViewTestFixture.cs" />
<Compile Include="Designer\GenerateUserControlWithNullPropertyValueTests.cs" />
<Compile Include="Designer\IgnoreDesignTimePropertiesTestFixture.cs" />
<Compile Include="Designer\InsertEventHandlerTestFixtureBase.cs" />
<Compile Include="Designer\InsertEventHandlerWithSpaceIndentTestFixture.cs" />
@ -424,6 +424,8 @@ @@ -424,6 +424,8 @@
<Compile Include="Utils\DerivedPythonConsoleHost.cs" />
<Compile Include="Utils\DerivedPythonDesignerGenerator.cs" />
<Compile Include="Utils\DerivedPythonFormsDesignerDisplayBinding.cs" />
<Compile Include="Utils\PythonCodeDomSerializerHelper.cs" />
<Compile Include="Utils\PythonComponentWalkerHelper.cs" />
<Compile Include="Utils\PythonMSBuildEngineHelper.cs" />
<Compile Include="Utils\TestablePythonConsole.cs" />
<EmbeddedResource Include="..\Project\PythonBinding.addin">

20
src/AddIns/BackendBindings/Python/PythonBinding/Test/Utils/PythonCodeDomSerializerHelper.cs

@ -0,0 +1,20 @@ @@ -0,0 +1,20 @@
// <file>
// <copyright see="prj:///doc/copyright.txt"/>
// <license see="prj:///doc/license.txt"/>
// <owner name="Matthew Ward" email="mrward@users.sourceforge.net"/>
// <version>$Revision$</version>
// </file>
using System;
using ICSharpCode.PythonBinding;
namespace PythonBinding.Tests.Utils
{
public class PythonCodeDomSerializerHelper
{
public static PythonCodeDomSerializer CreateSerializer()
{
return new PythonCodeDomSerializer();
}
}
}

21
src/AddIns/BackendBindings/Python/PythonBinding/Test/Utils/PythonComponentWalkerHelper.cs

@ -0,0 +1,21 @@ @@ -0,0 +1,21 @@
// <file>
// <copyright see="prj:///doc/copyright.txt"/>
// <license see="prj:///doc/license.txt"/>
// <owner name="Matthew Ward" email="mrward@users.sourceforge.net"/>
// <version>$Revision$</version>
// </file>
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);
}
}
}

77
src/AddIns/BackendBindings/Ruby/RubyBinding/Test/Designer/AppendNullPropertyValueTestFixture.cs

@ -1,77 +0,0 @@ @@ -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
{
/// <summary>
/// Tests that a null property value does not cause a NullReferenceException.
/// </summary>
[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);
}
}
}

47
src/AddIns/BackendBindings/Ruby/RubyBinding/Test/Designer/CallBeginInitOnLoadTestFixture.cs

@ -2,10 +2,8 @@ @@ -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 @@ -16,18 +14,18 @@ namespace RubyBinding.Tests.Designer
/// Tests that the control's BeginInit and EndInit methods are called.
/// </summary>
[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" +
@ -44,36 +42,9 @@ namespace RubyBinding.Tests.Designer @@ -44,36 +42,9 @@ namespace RubyBinding.Tests.Designer
}
}
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()
protected override IComponentWalker CreateComponentWalker(IComponentCreator componentCreator)
{
Assert.IsTrue(LocalControl.IsEndInitCalled);
return RubyComponentWalkerHelper.CreateComponentWalker(componentCreator);
}
}
}

52
src/AddIns/BackendBindings/Ruby/RubyBinding/Test/Designer/ConvertCustomClassUsingTypeConverterTestFixture.cs

@ -2,58 +2,12 @@ @@ -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);
}
}
/// <summary>
/// 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 @@ -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);
}
}
}

55
src/AddIns/BackendBindings/Ruby/RubyBinding/Test/Designer/EnabledSetUsingPropertyDescriptorTestFixture.cs

@ -8,6 +8,8 @@ using System.ComponentModel.Design.Serialization; @@ -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 @@ -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.
/// </summary>
[TestFixture]
public class EnabledSetUsingPropertyDescriptorTestFixture
public class EnabledSetUsingPropertyDescriptorTestFixture : GenerateEnabledUsingPropertyDescriptorTestsBase
{
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);
}
}
}
[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, generatedCode);
}
Assert.AreEqual(expectedCode, generatedRubyCode);
protected override IScriptingCodeDomSerializer CreateSerializer()
{
return RubyCodeDomSerializerHelper.CreateSerializer();
}
}
}

0
src/AddIns/BackendBindings/Ruby/RubyBinding/Test/Designer/GenerateAcceptButtonTestFixture.cs → src/AddIns/BackendBindings/Ruby/RubyBinding/Test/Designer/GenerateAcceptButtonFormTestFixture.cs

48
src/AddIns/BackendBindings/Ruby/RubyBinding/Test/Designer/GenerateUserControlWithNullPropertyValueTests.cs

@ -0,0 +1,48 @@ @@ -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
{
/// <summary>
/// Tests that a null property value does not cause a NullReferenceException.
/// </summary>
[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();
}
}
}

40
src/AddIns/BackendBindings/Ruby/RubyBinding/Test/Designer/LoadFormTestFixtureBase.cs

@ -5,8 +5,9 @@ using System; @@ -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 @@ -16,34 +17,11 @@ namespace RubyBinding.Tests.Designer
/// <summary>
/// Base class for all LoadFormTestFixture classes.
/// </summary>
public class LoadFormTestFixtureBase
public class LoadFormTestFixtureBase : LoadFormTestsBase
{
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();
}
/// <summary>
/// Called at the start of SetUpFixture method before anything is setup.
/// </summary>
public virtual void BeforeSetUpFixture()
protected override IComponentWalker CreateComponentWalker(IComponentCreator componentCreator)
{
return RubyComponentWalkerHelper.CreateComponentWalker(componentCreator);
}
/// <summary>
@ -53,12 +31,8 @@ namespace RubyBinding.Tests.Designer @@ -53,12 +31,8 @@ namespace RubyBinding.Tests.Designer
get { return String.Empty; }
}
protected MockComponentCreator ComponentCreator {
get { return componentCreator; }
}
protected Form Form {
get { return form; }
public override string Code {
get { return RubyCode; }
}
}
}

6
src/AddIns/BackendBindings/Ruby/RubyBinding/Test/RubyBinding.Tests.csproj

@ -163,7 +163,7 @@ @@ -163,7 +163,7 @@
<Compile Include="Converter\VBStringConcatTestFixture.cs" />
<Compile Include="Converter\WhileLoopConversionTestFixture.cs" />
<Compile Include="Converter\XmlDocCommentConversionTestFixture.cs" />
<Compile Include="Designer\AppendNullPropertyValueTestFixture.cs" />
<Compile Include="Designer\GenerateUserControlWithNullPropertyValueTests.cs" />
<Compile Include="Designer\CallBeginInitOnLoadTestFixture.cs" />
<Compile Include="Designer\ConvertCustomClassUsingTypeConverterTestFixture.cs" />
<Compile Include="Designer\CursorTypeResolutionTestFixture.cs" />
@ -182,7 +182,7 @@ @@ -182,7 +182,7 @@
<Compile Include="Designer\FindInitializeComponentMethodTestFixture.cs" />
<Compile Include="Designer\FormBaseClassCreatedOnLoadTestFixture.cs" />
<Compile Include="Designer\FormsDesignerDisplayBindingTestFixture.cs" />
<Compile Include="Designer\GenerateAcceptButtonTestFixture.cs" />
<Compile Include="Designer\GenerateAcceptButtonFormTestFixture.cs" />
<Compile Include="Designer\GenerateAccessibleRoleFormTestFixture.cs" />
<Compile Include="Designer\GenerateAutoScaleModeFormTestFixture.cs" />
<Compile Include="Designer\GenerateAutoScrollFormTestFixture.cs" />
@ -319,6 +319,8 @@ @@ -319,6 +319,8 @@
<Compile Include="Utils\DerivedRubyDesignerGenerator.cs" />
<Compile Include="Utils\DerivedRubyFormsDesignerDisplayBinding.cs" />
<Compile Include="Utils\RubyBindingAddInFile.cs" />
<Compile Include="Utils\RubyCodeDomSerializerHelper.cs" />
<Compile Include="Utils\RubyComponentWalkerHelper.cs" />
<Compile Include="Utils\RubyMSBuildEngineHelper.cs" />
<Compile Include="Utils\RubyParserHelper.cs" />
<Compile Include="Utils\RubySelectedTestsHelper.cs" />

20
src/AddIns/BackendBindings/Ruby/RubyBinding/Test/Utils/RubyCodeDomSerializerHelper.cs

@ -0,0 +1,20 @@ @@ -0,0 +1,20 @@
// <file>
// <copyright see="prj:///doc/copyright.txt"/>
// <license see="prj:///doc/license.txt"/>
// <owner name="Matthew Ward" email="mrward@users.sourceforge.net"/>
// <version>$Revision$</version>
// </file>
using System;
using ICSharpCode.RubyBinding;
namespace RubyBinding.Tests.Utils
{
public class RubyCodeDomSerializerHelper
{
public static RubyCodeDomSerializer CreateSerializer()
{
return new RubyCodeDomSerializer();
}
}
}

21
src/AddIns/BackendBindings/Ruby/RubyBinding/Test/Utils/RubyComponentWalkerHelper.cs

@ -0,0 +1,21 @@ @@ -0,0 +1,21 @@
// <file>
// <copyright see="prj:///doc/copyright.txt"/>
// <license see="prj:///doc/license.txt"/>
// <owner name="Matthew Ward" email="mrward@users.sourceforge.net"/>
// <version>$Revision$</version>
// </file>
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);
}
}
}

1
src/AddIns/BackendBindings/Scripting/Project/Src/IScriptingCodeDomSerializer.cs

@ -14,5 +14,6 @@ namespace ICSharpCode.Scripting @@ -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);
}
}

48
src/AddIns/BackendBindings/Scripting/Test/Designer/CallBeginInitOnLoadTests.cs

@ -0,0 +1,48 @@ @@ -0,0 +1,48 @@
// <file>
// <copyright see="prj:///doc/copyright.txt"/>
// <license see="prj:///doc/license.txt"/>
// <owner name="Matthew Ward" email="mrward@users.sourceforge.net"/>
// <version>$Revision$</version>
// </file>
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);
}
}
}

55
src/AddIns/BackendBindings/Scripting/Test/Designer/GenerateAcceptButtonFormTestsBase.cs

@ -0,0 +1,55 @@ @@ -0,0 +1,55 @@
// <file>
// <copyright see="prj:///doc/copyright.txt"/>
// <license see="prj:///doc/license.txt"/>
// <owner name="Matthew Ward" email="mrward@users.sourceforge.net"/>
// <version>$Revision$</version>
// </file>
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);
}
}
}
}
}

18
src/AddIns/BackendBindings/Scripting/Test/Designer/GenerateDesignerCodeTestsBase.cs

@ -0,0 +1,18 @@ @@ -0,0 +1,18 @@
// <file>
// <copyright see="prj:///doc/copyright.txt"/>
// <license see="prj:///doc/license.txt"/>
// <owner name="Matthew Ward" email="mrward@users.sourceforge.net"/>
// <version>$Revision$</version>
// </file>
using System;
namespace ICSharpCode.Scripting.Tests.Designer
{
public abstract class GenerateDesignerCodeTestsBase
{
protected string generatedCode;
protected abstract IScriptingCodeDomSerializer CreateSerializer();
}
}

46
src/AddIns/BackendBindings/Scripting/Test/Designer/GenerateEnabledUsingPropertyDescriptorTestsBase.cs

@ -0,0 +1,46 @@ @@ -0,0 +1,46 @@
// <file>
// <copyright see="prj:///doc/copyright.txt"/>
// <license see="prj:///doc/license.txt"/>
// <owner name="Matthew Ward" email="mrward@users.sourceforge.net"/>
// <version>$Revision$</version>
// </file>
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);
}
}
}
}
}

49
src/AddIns/BackendBindings/Scripting/Test/Designer/GenerateUserControlWithNullPropertyValueTestsBase.cs

@ -0,0 +1,49 @@ @@ -0,0 +1,49 @@
// <file>
// <copyright see="prj:///doc/copyright.txt"/>
// <license see="prj:///doc/license.txt"/>
// <owner name="Matthew Ward" email="mrward@users.sourceforge.net"/>
// <version>$Revision$</version>
// </file>
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);
}
}
}
}
}

58
src/AddIns/BackendBindings/Scripting/Test/Designer/LoadFormTestsBase.cs

@ -0,0 +1,58 @@ @@ -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();
}
/// <summary>
/// Called at the start of SetUpFixture method before anything is setup.
/// </summary>
public virtual void BeforeSetUpFixture()
{
}
protected abstract IComponentWalker CreateComponentWalker(IComponentCreator componentCreator);
/// <summary>
/// Gets the code that will be loaded.
/// </summary>
public virtual string Code {
get { return String.Empty; }
}
protected MockComponentCreator ComponentCreator {
get { return componentCreator; }
}
protected Form Form {
get { return form; }
}
}
}

7
src/AddIns/BackendBindings/Scripting/Test/ICSharpCode.Scripting.Tests.csproj

@ -76,6 +76,12 @@ @@ -76,6 +76,12 @@
<Compile Include="Console\ScriptingConsoleOutputStreamTests.cs" />
<Compile Include="Console\ScriptingConsoleTextEditorTests.cs" />
<Compile Include="Console\ThreadSafeScriptingConsoleTextEditorTests.cs" />
<Compile Include="Designer\CallBeginInitOnLoadTests.cs" />
<Compile Include="Designer\GenerateAcceptButtonFormTestsBase.cs" />
<Compile Include="Designer\GenerateDesignerCodeTestsBase.cs" />
<Compile Include="Designer\GenerateEnabledUsingPropertyDescriptorTestsBase.cs" />
<Compile Include="Designer\GenerateUserControlWithNullPropertyValueTestsBase.cs" />
<Compile Include="Designer\LoadFormTestsBase.cs" />
<Compile Include="Designer\NameCreationServiceTests.cs" />
<Compile Include="Designer\ScriptingDesignerGeneratorTests.cs" />
<Compile Include="Designer\ScriptingCodeBuilderTests.cs" />
@ -90,6 +96,7 @@ @@ -90,6 +96,7 @@
<Compile Include="Utils\ConvertedFile.cs" />
<Compile Include="Utils\CreatedComponent.cs" />
<Compile Include="Utils\CreatedInstance.cs" />
<Compile Include="Utils\CustomClassTypeConverter.cs" />
<Compile Include="Utils\CustomUserControl.cs" />
<Compile Include="Utils\DerivedFormDesignerViewContent.cs" />
<Compile Include="Utils\DerivedToolStripMenuItem.cs" />

55
src/AddIns/BackendBindings/Scripting/Test/Utils/CustomClassTypeConverter.cs

@ -0,0 +1,55 @@ @@ -0,0 +1,55 @@
// <file>
// <copyright see="prj:///doc/copyright.txt"/>
// <license see="prj:///doc/license.txt"/>
// <owner name="Matthew Ward" email="mrward@users.sourceforge.net"/>
// <version>$Revision$</version>
// </file>
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);
}
}
}

5
src/AddIns/BackendBindings/Scripting/Test/Utils/FakeCodeDomSerializer.cs

@ -29,5 +29,10 @@ namespace ICSharpCode.Scripting.Tests.Utils @@ -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);
}
}
}

Loading…
Cancel
Save