Browse Source
git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/branches/3.0@4571 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61shortcuts
5 changed files with 265 additions and 13 deletions
@ -0,0 +1,109 @@ |
|||||||
|
// <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.Drawing; |
||||||
|
using System.Windows.Forms; |
||||||
|
using ICSharpCode.PythonBinding; |
||||||
|
using NUnit.Framework; |
||||||
|
using PythonBinding.Tests.Utils; |
||||||
|
|
||||||
|
namespace PythonBinding.Tests.Designer |
||||||
|
{ |
||||||
|
class ProtectedPanelBaseForm : Form |
||||||
|
{ |
||||||
|
protected Panel panel1 = new Panel(); |
||||||
|
Button button1 = new Button(); |
||||||
|
|
||||||
|
public ProtectedPanelBaseForm() |
||||||
|
{ |
||||||
|
button1.Name = "button1"; |
||||||
|
|
||||||
|
panel1.Name = "panel1"; |
||||||
|
panel1.Location = new Point(5, 10); |
||||||
|
panel1.Size = new Size(200, 100); |
||||||
|
panel1.Controls.Add(button1); |
||||||
|
|
||||||
|
Controls.Add(panel1); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
class ProtectedPanelDerivedForm : ProtectedPanelBaseForm |
||||||
|
{ |
||||||
|
[EditorBrowsableAttribute(EditorBrowsableState.Never)] |
||||||
|
internal Point PanelLocation { |
||||||
|
get { return panel1.Location; } |
||||||
|
set { panel1.Location = value; } |
||||||
|
} |
||||||
|
|
||||||
|
[EditorBrowsableAttribute(EditorBrowsableState.Never)] |
||||||
|
internal Size PanelSize { |
||||||
|
get { return panel1.Size; } |
||||||
|
set { panel1.Size = value; } |
||||||
|
} |
||||||
|
|
||||||
|
[EditorBrowsableAttribute(EditorBrowsableState.Never)] |
||||||
|
internal Panel GetPanel() |
||||||
|
{ |
||||||
|
return panel1; |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Tests that no code is generated for a protected panel control in the base class
|
||||||
|
/// that has child controls.
|
||||||
|
/// </summary>
|
||||||
|
[TestFixture] |
||||||
|
public class GenerateInheritedProtectedPanelFormTestFixture |
||||||
|
{ |
||||||
|
string generatedPythonCode; |
||||||
|
|
||||||
|
[TestFixtureSetUp] |
||||||
|
public void SetUpFixture() |
||||||
|
{ |
||||||
|
using (DesignSurface designSurface = new DesignSurface(typeof(ProtectedPanelDerivedForm))) { |
||||||
|
IDesignerHost host = (IDesignerHost)designSurface.GetService(typeof(IDesignerHost)); |
||||||
|
Form form = (Form)host.RootComponent; |
||||||
|
form.ClientSize = new Size(284, 264); |
||||||
|
|
||||||
|
PropertyDescriptorCollection descriptors = TypeDescriptor.GetProperties(form); |
||||||
|
PropertyDescriptor namePropertyDescriptor = descriptors.Find("Name", false); |
||||||
|
namePropertyDescriptor.SetValue(form, "MainForm"); |
||||||
|
|
||||||
|
// Move protected panel so we generate code for the new location.
|
||||||
|
ProtectedPanelDerivedForm derivedForm = (ProtectedPanelDerivedForm)form; |
||||||
|
derivedForm.PanelLocation = new Point(10, 15); |
||||||
|
|
||||||
|
string indentString = " "; |
||||||
|
PythonControl pythonForm = new PythonControl(indentString); |
||||||
|
generatedPythonCode = pythonForm.GenerateInitializeComponentMethod(form); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
[Test] |
||||||
|
public void GeneratedCode() |
||||||
|
{ |
||||||
|
string expectedCode = "def InitializeComponent(self):\r\n" + |
||||||
|
" self.SuspendLayout()\r\n" + |
||||||
|
" # \r\n" + |
||||||
|
" # panel1\r\n" + |
||||||
|
" # \r\n" + |
||||||
|
" self.panel1.Location = System.Drawing.Point(10, 15)\r\n" + |
||||||
|
" # \r\n" + |
||||||
|
" # MainForm\r\n" + |
||||||
|
" # \r\n" + |
||||||
|
" self.ClientSize = System.Drawing.Size(284, 264)\r\n" + |
||||||
|
" self.Name = \"MainForm\"\r\n" + |
||||||
|
" self.ResumeLayout(False)\r\n" + |
||||||
|
" self.PerformLayout()\r\n"; |
||||||
|
|
||||||
|
Assert.AreEqual(expectedCode, generatedPythonCode, generatedPythonCode); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,90 @@ |
|||||||
|
// <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.Drawing; |
||||||
|
using System.IO; |
||||||
|
using System.Windows.Forms; |
||||||
|
|
||||||
|
using ICSharpCode.PythonBinding; |
||||||
|
using IronPython.Compiler.Ast; |
||||||
|
using NUnit.Framework; |
||||||
|
using PythonBinding.Tests.Utils; |
||||||
|
|
||||||
|
namespace PythonBinding.Tests.Designer |
||||||
|
{ |
||||||
|
[TestFixture] |
||||||
|
public class LoadInheritedProtectedPanelFormTestFixture : LoadFormTestFixtureBase |
||||||
|
{ |
||||||
|
public override string PythonCode { |
||||||
|
get { |
||||||
|
base.ComponentCreator.AddType("PythonBinding.Tests.Designer.ProtectedPanelDerivedForm", typeof(ProtectedPanelDerivedForm)); |
||||||
|
|
||||||
|
return "class MainForm(PythonBinding.Tests.Designer.ProtectedPanelDerivedForm):\r\n" + |
||||||
|
" def InitializeComponent(self):\r\n" + |
||||||
|
" self.SuspendLayout()\r\n" + |
||||||
|
" # \r\n" + |
||||||
|
" # panel1\r\n" + |
||||||
|
" # \r\n" + |
||||||
|
" self.panel1.Location = System.Drawing.Point(10, 15)\r\n" + |
||||||
|
" self.panel1.Size = System.Drawing.Size(108, 120)\r\n" + |
||||||
|
" # \r\n" + |
||||||
|
" # form1\r\n" + |
||||||
|
" # \r\n" + |
||||||
|
" self.Location = System.Drawing.Point(10, 20)\r\n" + |
||||||
|
" self.Name = \"form1\"\r\n" + |
||||||
|
" self.Controls.Add(self._textBox1)\r\n" + |
||||||
|
" self.ResumeLayout(False)\r\n"; |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
ProtectedPanelDerivedForm DerivedForm { |
||||||
|
get { return Form as ProtectedPanelDerivedForm; } |
||||||
|
} |
||||||
|
|
||||||
|
[Test] |
||||||
|
public void PanelLocation() |
||||||
|
{ |
||||||
|
Assert.AreEqual(new Point(10, 15), DerivedForm.PanelLocation); |
||||||
|
} |
||||||
|
|
||||||
|
[Test] |
||||||
|
public void PanelSize() |
||||||
|
{ |
||||||
|
Assert.AreEqual(new Size(108, 120), DerivedForm.PanelSize); |
||||||
|
} |
||||||
|
|
||||||
|
[Test] |
||||||
|
public void GetProtectedPanelObject() |
||||||
|
{ |
||||||
|
Assert.AreEqual(DerivedForm.GetPanel(), PythonControlFieldExpression.GetInheritedObject("panel1", DerivedForm)); |
||||||
|
} |
||||||
|
|
||||||
|
[Test] |
||||||
|
public void GetProtectedPanelObjectIncorrectCase() |
||||||
|
{ |
||||||
|
Assert.AreEqual(DerivedForm.GetPanel(), PythonControlFieldExpression.GetInheritedObject("PANEL1", DerivedForm)); |
||||||
|
} |
||||||
|
|
||||||
|
[Test] |
||||||
|
public void GetInheritedObjectPassedNull() |
||||||
|
{ |
||||||
|
Assert.IsNull(PythonControlFieldExpression.GetInheritedObject("panel1", null)); |
||||||
|
} |
||||||
|
|
||||||
|
[Test] |
||||||
|
public void GetInheritedPanelObjectFromFieldExpression() |
||||||
|
{ |
||||||
|
AssignmentStatement statement = PythonParserHelper.GetAssignmentStatement("self.panel1.Name = \"abc\""); |
||||||
|
PythonControlFieldExpression field = PythonControlFieldExpression.Create(statement.Left[0] as MemberExpression); |
||||||
|
|
||||||
|
Assert.AreEqual(DerivedForm.GetPanel(), field.GetObject(ComponentCreator)); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
Loading…
Reference in new issue