1
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
2
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
5
using System.ComponentModel;
6
using System.ComponentModel.Design;
7
using System.ComponentModel.Design.Serialization;
9
using System.Windows.Forms;
10
using ICSharpCode.PythonBinding;
11
using NUnit.Framework;
12
using PythonBinding.Tests.Utils;
14
namespace PythonBinding.Tests.Designer
17
/// Ensures that SuspendLayout and ResumeLayout methods are generated for a panel containing controls and sitting on top of
21
public class GenerateNestedPanelFormTestFixture
23
string generatedPythonCode;
26
public void SetUpFixture()
28
using (DesignSurface designSurface = new DesignSurface(typeof(Form))) {
29
IDesignerHost host = (IDesignerHost)designSurface.GetService(typeof(IDesignerHost));
30
Form form = (Form)host.RootComponent;
31
form.ClientSize = new Size(284, 264);
33
PropertyDescriptorCollection descriptors = TypeDescriptor.GetProperties(form);
34
PropertyDescriptor namePropertyDescriptor = descriptors.Find("Name", false);
35
namePropertyDescriptor.SetValue(form, "MainForm");
37
Panel panel1 = (Panel)host.CreateComponent(typeof(Panel), "panel1");
38
panel1.Location = new Point(0, 0);
40
panel1.Size = new Size(200, 220);
42
Panel panel2 = (Panel)host.CreateComponent(typeof(Panel), "panel2");
43
panel2.Location = new Point(10, 15);
45
panel2.Size = new Size(100, 120);
46
TextBox textBox = (TextBox)host.CreateComponent(typeof(TextBox), "textBox1");
47
textBox.Location = new Point(5, 5);
49
textBox.Size = new Size(110, 20);
50
panel2.Controls.Add(textBox);
52
panel1.Controls.Add(panel2);
53
form.Controls.Add(panel1);
55
DesignerSerializationManager serializationManager = new DesignerSerializationManager(host);
56
using (serializationManager.CreateSession()) {
57
PythonCodeDomSerializer serializer = new PythonCodeDomSerializer(" ");
58
generatedPythonCode = serializer.GenerateInitializeComponentMethodBody(host, serializationManager, String.Empty, 1);
64
public void GeneratedCode()
66
string expectedCode = " self._panel1 = System.Windows.Forms.Panel()\r\n" +
67
" self._panel2 = System.Windows.Forms.Panel()\r\n" +
68
" self._textBox1 = System.Windows.Forms.TextBox()\r\n" +
69
" self._panel1.SuspendLayout()\r\n" +
70
" self._panel2.SuspendLayout()\r\n" +
71
" self.SuspendLayout()\r\n" +
75
" self._panel1.Controls.Add(self._panel2)\r\n" +
76
" self._panel1.Location = System.Drawing.Point(0, 0)\r\n" +
77
" self._panel1.Name = \"panel1\"\r\n" +
78
" self._panel1.Size = System.Drawing.Size(200, 220)\r\n" +
79
" self._panel1.TabIndex = 0\r\n" +
83
" self._panel2.Controls.Add(self._textBox1)\r\n" +
84
" self._panel2.Location = System.Drawing.Point(10, 15)\r\n" +
85
" self._panel2.Name = \"panel2\"\r\n" +
86
" self._panel2.Size = System.Drawing.Size(100, 120)\r\n" +
87
" self._panel2.TabIndex = 0\r\n" +
91
" self._textBox1.Location = System.Drawing.Point(5, 5)\r\n" +
92
" self._textBox1.Name = \"textBox1\"\r\n" +
93
" self._textBox1.Size = System.Drawing.Size(110, 20)\r\n" +
94
" self._textBox1.TabIndex = 0\r\n" +
98
" self.ClientSize = System.Drawing.Size(284, 264)\r\n" +
99
" self.Controls.Add(self._panel1)\r\n" +
100
" self.Name = \"MainForm\"\r\n" +
101
" self._panel1.ResumeLayout(False)\r\n" +
102
" self._panel2.ResumeLayout(False)\r\n" +
103
" self._panel2.PerformLayout()\r\n" +
104
" self.ResumeLayout(False)\r\n";
106
Assert.AreEqual(expectedCode, generatedPythonCode, generatedPythonCode);