~halega/+junk/sharpdevelop

« back to all changes in this revision

Viewing changes to src/AddIns/BackendBindings/Python/PythonBinding/Test/Designer/GenerateNestedPanelFormTestFixture.cs

  • Committer: sk
  • Date: 2011-09-10 05:17:57 UTC
  • Revision ID: halega@halega.com-20110910051757-qfouz1llya9m6boy
4.1.0.7915 Release Candidate 1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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)
 
3
 
 
4
using System;
 
5
using System.ComponentModel;
 
6
using System.ComponentModel.Design;
 
7
using System.ComponentModel.Design.Serialization;
 
8
using System.Drawing;
 
9
using System.Windows.Forms;
 
10
using ICSharpCode.PythonBinding;
 
11
using NUnit.Framework;
 
12
using PythonBinding.Tests.Utils;
 
13
 
 
14
namespace PythonBinding.Tests.Designer
 
15
{
 
16
        /// <summary>
 
17
        /// Ensures that SuspendLayout and ResumeLayout methods are generated for a panel containing controls and sitting on top of 
 
18
        /// another panel.
 
19
        /// </summary>
 
20
        [TestFixture]
 
21
        public class GenerateNestedPanelFormTestFixture
 
22
        {
 
23
                string generatedPythonCode;
 
24
                
 
25
                [TestFixtureSetUp]
 
26
                public void SetUpFixture()
 
27
                {
 
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);
 
32
                                
 
33
                                PropertyDescriptorCollection descriptors = TypeDescriptor.GetProperties(form);
 
34
                                PropertyDescriptor namePropertyDescriptor = descriptors.Find("Name", false);
 
35
                                namePropertyDescriptor.SetValue(form, "MainForm");
 
36
                                
 
37
                                Panel panel1 = (Panel)host.CreateComponent(typeof(Panel), "panel1");
 
38
                                panel1.Location = new Point(0, 0);
 
39
                                panel1.TabIndex = 0;
 
40
                                panel1.Size = new Size(200, 220);
 
41
                                
 
42
                                Panel panel2 = (Panel)host.CreateComponent(typeof(Panel), "panel2");
 
43
                                panel2.Location = new Point(10, 15);
 
44
                                panel2.TabIndex = 0;
 
45
                                panel2.Size = new Size(100, 120);
 
46
                                TextBox textBox = (TextBox)host.CreateComponent(typeof(TextBox), "textBox1");
 
47
                                textBox.Location = new Point(5, 5);
 
48
                                textBox.TabIndex = 0;
 
49
                                textBox.Size = new Size(110, 20);
 
50
                                panel2.Controls.Add(textBox);
 
51
                                
 
52
                                panel1.Controls.Add(panel2);
 
53
                                form.Controls.Add(panel1);
 
54
                                
 
55
                                DesignerSerializationManager serializationManager = new DesignerSerializationManager(host);
 
56
                                using (serializationManager.CreateSession()) {                                  
 
57
                                        PythonCodeDomSerializer serializer = new PythonCodeDomSerializer("    ");
 
58
                                        generatedPythonCode = serializer.GenerateInitializeComponentMethodBody(host, serializationManager, String.Empty, 1);
 
59
                                }
 
60
                        }
 
61
                }
 
62
                
 
63
                [Test]
 
64
                public void GeneratedCode()
 
65
                {
 
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" +
 
72
                                                                "    # \r\n" +
 
73
                                                                "    # panel1\r\n" +
 
74
                                                                "    # \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" +
 
80
                                                                "    # \r\n" +
 
81
                                                                "    # panel2\r\n" +
 
82
                                                                "    # \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" +
 
88
                                                                "    # \r\n" +
 
89
                                                                "    # textBox1\r\n" +
 
90
                                                                "    # \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" +
 
95
                                                                "    # \r\n" +
 
96
                                                                "    # MainForm\r\n" +
 
97
                                                                "    # \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";
 
105
                        
 
106
                        Assert.AreEqual(expectedCode, generatedPythonCode, generatedPythonCode);
 
107
                }
 
108
        }
 
109
}