Browse Source
git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/branches/3.0@3837 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61shortcuts
25 changed files with 1354 additions and 39 deletions
@ -0,0 +1,27 @@ |
|||||||
|
// <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.Windows.Forms; |
||||||
|
|
||||||
|
namespace ICSharpCode.PythonBinding |
||||||
|
{ |
||||||
|
public class PythonControlAutoScaleModeProperty : PythonControlProperty |
||||||
|
{ |
||||||
|
public PythonControlAutoScaleModeProperty() |
||||||
|
{ |
||||||
|
} |
||||||
|
|
||||||
|
public override bool IsDefaultValue(object propertyValue) |
||||||
|
{ |
||||||
|
if (propertyValue is AutoScaleMode) { |
||||||
|
return (AutoScaleMode)propertyValue == AutoScaleMode.Inherit; |
||||||
|
} |
||||||
|
return false; |
||||||
|
} |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,30 @@ |
|||||||
|
// <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.Windows.Forms; |
||||||
|
|
||||||
|
namespace ICSharpCode.PythonBinding |
||||||
|
{ |
||||||
|
/// <summary>
|
||||||
|
/// Represents the AutoValidate property for a Form or ContainerControl.
|
||||||
|
/// </summary>
|
||||||
|
public class PythonControlAutoValidateProperty : PythonControlProperty |
||||||
|
{ |
||||||
|
public PythonControlAutoValidateProperty() |
||||||
|
{ |
||||||
|
} |
||||||
|
|
||||||
|
public override bool IsDefaultValue(object propertyValue) |
||||||
|
{ |
||||||
|
if (propertyValue is AutoValidate) { |
||||||
|
return (AutoValidate)propertyValue == AutoValidate.EnablePreventFocusChange; |
||||||
|
} |
||||||
|
return false; |
||||||
|
} |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,26 @@ |
|||||||
|
// <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.PythonBinding |
||||||
|
{ |
||||||
|
public class PythonControlBooleanProperty : PythonControlProperty |
||||||
|
{ |
||||||
|
bool defaultValue; |
||||||
|
|
||||||
|
public PythonControlBooleanProperty(bool defaultValue) |
||||||
|
{ |
||||||
|
this.defaultValue = defaultValue; |
||||||
|
} |
||||||
|
|
||||||
|
public override bool IsDefaultValue(object propertyValue) |
||||||
|
{ |
||||||
|
return (bool)propertyValue == defaultValue; |
||||||
|
} |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,135 @@ |
|||||||
|
// <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.Reflection; |
||||||
|
using System.Windows.Forms; |
||||||
|
|
||||||
|
namespace ICSharpCode.PythonBinding |
||||||
|
{ |
||||||
|
/// <summary>
|
||||||
|
/// Contains the default values for all properties on a Control, Form or UserControl.
|
||||||
|
/// </summary>
|
||||||
|
public class PythonControlDefaultPropertyValues |
||||||
|
{ |
||||||
|
Dictionary<string, PythonControlProperty> defaultPropertyValues = new Dictionary<string, PythonControlProperty>(); |
||||||
|
|
||||||
|
public PythonControlDefaultPropertyValues() |
||||||
|
{ |
||||||
|
defaultPropertyValues.Add("Text", new PythonControlTextProperty()); |
||||||
|
defaultPropertyValues.Add("AutoValidate", new PythonControlAutoValidateProperty()); |
||||||
|
defaultPropertyValues.Add("Enabled", new PythonControlBooleanProperty(true)); |
||||||
|
defaultPropertyValues.Add("AutoScaleMode", new PythonControlAutoScaleModeProperty()); |
||||||
|
defaultPropertyValues.Add("DoubleBuffered", new PythonControlBooleanProperty(false)); |
||||||
|
defaultPropertyValues.Add("ImeMode", new PythonControlImeModeProperty()); |
||||||
|
defaultPropertyValues.Add("RightToLeft", new PythonControlRightToLeftProperty()); |
||||||
|
} |
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Determines if the property value has its default value.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="propertyName">The name of the property.</param>
|
||||||
|
/// <param name="obj">The object that has the property.</param>
|
||||||
|
/// <returns>False if the property does not exist.</returns>
|
||||||
|
public bool IsDefaultValue(string propertyName, object obj) |
||||||
|
{ |
||||||
|
PropertyInfo propertyInfo = obj.GetType().GetProperty(propertyName, BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static | BindingFlags.Instance); |
||||||
|
if (propertyInfo != null) { |
||||||
|
object propertyValue = propertyInfo.GetValue(obj, null); |
||||||
|
return IsDefaultValue(propertyInfo, propertyValue); |
||||||
|
} |
||||||
|
return false; |
||||||
|
} |
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Determines if the property value is the default value by checking the DefaultValueAttribute.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="propertyDescriptor">The property descriptor for the property.</param>
|
||||||
|
/// <param name="obj">The object that has the property.</param>
|
||||||
|
/// <remarks>
|
||||||
|
/// For some properties such as Form.AutoValidate there is no default value specified by the
|
||||||
|
/// DefaultValueAttribute.
|
||||||
|
/// </remarks>
|
||||||
|
public bool IsDefaultValue(PropertyDescriptor propertyDescriptor, object obj) |
||||||
|
{ |
||||||
|
PropertyInfo propertyInfo = obj.GetType().GetProperty(propertyDescriptor.Name, BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static | BindingFlags.Instance); |
||||||
|
if (propertyInfo != null) { |
||||||
|
return IsDefaultValue(propertyInfo, propertyDescriptor.GetValue(obj)); |
||||||
|
} |
||||||
|
return false; |
||||||
|
} |
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Determines if the property value is the default value by checking the DefaultValueAttribute.
|
||||||
|
/// </summary>
|
||||||
|
/// <remarks>
|
||||||
|
/// For some properties such as Form.AutoValidate there is no default value specified by the
|
||||||
|
/// DefaultValueAttribute.
|
||||||
|
/// </remarks>
|
||||||
|
public bool IsDefaultValue(PropertyInfo propertyInfo, object propertyValue) |
||||||
|
{ |
||||||
|
// Check default attribute.
|
||||||
|
DefaultValueAttribute defaultValueAttribute = (DefaultValueAttribute)Attribute.GetCustomAttribute(propertyInfo, typeof(DefaultValueAttribute), true); |
||||||
|
if (defaultValueAttribute != null) { |
||||||
|
if (defaultValueAttribute.Value != null) { |
||||||
|
return defaultValueAttribute.Value.Equals(propertyValue); |
||||||
|
} |
||||||
|
return defaultValueAttribute.Value == propertyValue; |
||||||
|
} |
||||||
|
|
||||||
|
PythonControlProperty controlProperty = null; |
||||||
|
if (defaultPropertyValues.TryGetValue(propertyInfo.Name, out controlProperty)) { |
||||||
|
return controlProperty.IsDefaultValue(propertyValue); |
||||||
|
} |
||||||
|
|
||||||
|
if (propertyInfo.Name == "BackColor") { |
||||||
|
// Default is Control.DefaultBackColor
|
||||||
|
return true; |
||||||
|
} else if (propertyInfo.Name == "Visible") { |
||||||
|
return true; |
||||||
|
} else if (propertyInfo.Name == "Icon") { |
||||||
|
return true; |
||||||
|
} else if (propertyInfo.Name == "Location") { |
||||||
|
// 0, 0
|
||||||
|
return true; |
||||||
|
} else if (propertyInfo.Name == "Margin") { |
||||||
|
// Padding.DefaultMargin.
|
||||||
|
return true; |
||||||
|
} else if (propertyInfo.Name == "MinimumSize") { |
||||||
|
// 0, 0
|
||||||
|
return true; |
||||||
|
} else if (propertyInfo.Name == "TransparencyKey") { |
||||||
|
return true; |
||||||
|
} else if (propertyInfo.Name == "AutoScrollMargin") { |
||||||
|
return true; |
||||||
|
} else if (propertyInfo.Name == "AutoScrollMinSize") { |
||||||
|
return true; |
||||||
|
} else if (propertyInfo.Name == "HorizontalScroll") { |
||||||
|
return true; |
||||||
|
} else if (propertyInfo.Name == "VerticalScroll") { |
||||||
|
return true; |
||||||
|
} else if (propertyInfo.Name == "Cursor") { |
||||||
|
// Cursors.Default
|
||||||
|
return true; |
||||||
|
} else if (propertyInfo.Name == "Font") { |
||||||
|
// Default is Control.DefaultFont
|
||||||
|
return true; |
||||||
|
} else if (propertyInfo.Name == "ForeColor") { |
||||||
|
// Default is Control.DefaultForeColor
|
||||||
|
return true; |
||||||
|
} else if (propertyInfo.Name == "Padding") { |
||||||
|
// Padding.Empty.
|
||||||
|
return true; |
||||||
|
} |
||||||
|
|
||||||
|
return false; |
||||||
|
} |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,27 @@ |
|||||||
|
// <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.Windows.Forms; |
||||||
|
|
||||||
|
namespace ICSharpCode.PythonBinding |
||||||
|
{ |
||||||
|
public class PythonControlImeModeProperty : PythonControlProperty |
||||||
|
{ |
||||||
|
public PythonControlImeModeProperty() |
||||||
|
{ |
||||||
|
} |
||||||
|
|
||||||
|
public override bool IsDefaultValue(object propertyValue) |
||||||
|
{ |
||||||
|
if (propertyValue is ImeMode) { |
||||||
|
return (ImeMode)propertyValue == ImeMode.NoControl; |
||||||
|
} |
||||||
|
return false; |
||||||
|
} |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,29 @@ |
|||||||
|
// <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.PythonBinding |
||||||
|
{ |
||||||
|
/// <summary>
|
||||||
|
/// Represents a property on a control or form.
|
||||||
|
/// </summary>
|
||||||
|
public abstract class PythonControlProperty |
||||||
|
{ |
||||||
|
public PythonControlProperty() |
||||||
|
{ |
||||||
|
} |
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Returns true if the property value matches the default for this control's property.
|
||||||
|
/// </summary>
|
||||||
|
public virtual bool IsDefaultValue(object propertyValue) |
||||||
|
{ |
||||||
|
return false; |
||||||
|
} |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,27 @@ |
|||||||
|
// <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.Windows.Forms; |
||||||
|
|
||||||
|
namespace ICSharpCode.PythonBinding |
||||||
|
{ |
||||||
|
public class PythonControlRightToLeftProperty : PythonControlProperty |
||||||
|
{ |
||||||
|
public PythonControlRightToLeftProperty() |
||||||
|
{ |
||||||
|
} |
||||||
|
|
||||||
|
public override bool IsDefaultValue(object propertyValue) |
||||||
|
{ |
||||||
|
if (propertyValue is RightToLeft) { |
||||||
|
return (RightToLeft)propertyValue == RightToLeft.No; |
||||||
|
} |
||||||
|
return false; |
||||||
|
} |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,29 @@ |
|||||||
|
// <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.PythonBinding |
||||||
|
{ |
||||||
|
/// <summary>
|
||||||
|
/// Represents a Control's Text Property.
|
||||||
|
/// </summary>
|
||||||
|
public class PythonControlTextProperty : PythonControlProperty |
||||||
|
{ |
||||||
|
public PythonControlTextProperty() |
||||||
|
{ |
||||||
|
} |
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Returns true if the Text property's value is an empty string.
|
||||||
|
/// </summary>
|
||||||
|
public override bool IsDefaultValue(object propertyValue) |
||||||
|
{ |
||||||
|
return (string)propertyValue == String.Empty; |
||||||
|
} |
||||||
|
} |
||||||
|
} |
@ -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.Drawing; |
||||||
|
using System.Windows.Forms; |
||||||
|
|
||||||
|
namespace ICSharpCode.PythonBinding |
||||||
|
{ |
||||||
|
/// <summary>
|
||||||
|
/// Represents a property value assignment in a form or control.
|
||||||
|
/// </summary>
|
||||||
|
public class PythonPropertyValueAssignment |
||||||
|
{ |
||||||
|
PythonPropertyValueAssignment() |
||||||
|
{ |
||||||
|
} |
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Converts the property assignment to the equivalent python string.
|
||||||
|
/// </summary>
|
||||||
|
/// <remarks>
|
||||||
|
/// 1) Strings are returned surrounded by double quotes.
|
||||||
|
/// 2) Objects are returned with their full name (e.g. System.Windows.Forms.Size(100, 200)).
|
||||||
|
/// 3) Enums are returned with their full name (e.g. System.Windows.Forms.AccessibleRole.None).
|
||||||
|
/// 4) By default the ToString method is used on the property value.
|
||||||
|
/// </remarks>
|
||||||
|
public static string ToString(object propertyValue) |
||||||
|
{ |
||||||
|
Type propertyType = propertyValue.GetType(); |
||||||
|
if (propertyType == typeof(String)) { |
||||||
|
return "\"" + propertyValue + "\""; |
||||||
|
} else if (propertyType == typeof(Size)) { |
||||||
|
Size size = (Size)propertyValue; |
||||||
|
return size.GetType().FullName + "(" + size.Width + ", " + size.Height + ")"; |
||||||
|
} else if (propertyType.IsEnum) { |
||||||
|
return propertyType.FullName + "." + propertyValue.ToString(); |
||||||
|
} |
||||||
|
return propertyValue.ToString(); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,69 @@ |
|||||||
|
// <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 |
||||||
|
{ |
||||||
|
/// <summary>
|
||||||
|
/// The PythonForm class should be getting the value from the PropertyDescriptor and not
|
||||||
|
/// the PropertyInfo information returned from the form object. If this is not done then when the
|
||||||
|
/// user sets Enabled to false in the designer the value is not generated in the InitializeComponent method.
|
||||||
|
/// </summary>
|
||||||
|
[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); |
||||||
|
|
||||||
|
string indentString = " "; |
||||||
|
PythonForm pythonForm = new PythonForm(indentString); |
||||||
|
generatedPythonCode = pythonForm.GenerateInitializeComponentMethod(form); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
[Test] |
||||||
|
public void GeneratedCode() |
||||||
|
{ |
||||||
|
string expectedCode = "def InitializeComponent(self):\r\n" + |
||||||
|
" self.SuspendLayout()\r\n" + |
||||||
|
" # \r\n" + |
||||||
|
" # MainForm\r\n" + |
||||||
|
" # \r\n" + |
||||||
|
" self.Name = \"MainForm\"\r\n" + |
||||||
|
" self.ClientSize = System.Drawing.Size(284, 264)\r\n" + |
||||||
|
" self.Enabled = False\r\n" + |
||||||
|
" self.ResumeLayout(False)\r\n" + |
||||||
|
" self.PerformLayout()\r\n"; |
||||||
|
|
||||||
|
Assert.AreEqual(expectedCode, generatedPythonCode); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,53 @@ |
|||||||
|
// <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.Drawing; |
||||||
|
using System.Windows.Forms; |
||||||
|
using ICSharpCode.PythonBinding; |
||||||
|
using NUnit.Framework; |
||||||
|
using PythonBinding.Tests.Utils; |
||||||
|
|
||||||
|
namespace PythonBinding.Tests.Designer |
||||||
|
{ |
||||||
|
[TestFixture] |
||||||
|
public class GenerateAccessibleRoleFormTestFixture |
||||||
|
{ |
||||||
|
string generatedPythonCode; |
||||||
|
|
||||||
|
[TestFixtureSetUp] |
||||||
|
public void SetUpFixture() |
||||||
|
{ |
||||||
|
using (Form form = new Form()) { |
||||||
|
form.Name = "MainForm"; |
||||||
|
form.ClientSize = new Size(284, 264); |
||||||
|
form.AccessibleRole = AccessibleRole.None; |
||||||
|
|
||||||
|
string indentString = " "; |
||||||
|
PythonForm pythonForm = new PythonForm(indentString); |
||||||
|
generatedPythonCode = pythonForm.GenerateInitializeComponentMethod(form); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
[Test] |
||||||
|
public void GeneratedCode() |
||||||
|
{ |
||||||
|
string expectedCode = "def InitializeComponent(self):\r\n" + |
||||||
|
" self.SuspendLayout()\r\n" + |
||||||
|
" # \r\n" + |
||||||
|
" # MainForm\r\n" + |
||||||
|
" # \r\n" + |
||||||
|
" self.ClientSize = System.Drawing.Size(284, 264)\r\n" + |
||||||
|
" self.AccessibleRole = System.Windows.Forms.AccessibleRole.None\r\n" + |
||||||
|
" self.Name = \"MainForm\"\r\n" + |
||||||
|
" self.ResumeLayout(False)\r\n" + |
||||||
|
" self.PerformLayout()\r\n"; |
||||||
|
|
||||||
|
Assert.AreEqual(expectedCode, generatedPythonCode); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,65 @@ |
|||||||
|
// <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.Drawing; |
||||||
|
using System.Windows.Forms; |
||||||
|
using ICSharpCode.PythonBinding; |
||||||
|
using NUnit.Framework; |
||||||
|
using PythonBinding.Tests.Utils; |
||||||
|
|
||||||
|
namespace PythonBinding.Tests.Designer |
||||||
|
{ |
||||||
|
/// <summary>
|
||||||
|
/// A Form has a base ContainerControl class which has an AutoScaleMode property. This has the following attributes:
|
||||||
|
///
|
||||||
|
/// Browsable = false
|
||||||
|
/// DesignerSerializationVisibility = Hidden
|
||||||
|
/// EditorBrowsable = EditorBrowsableState.Advanced
|
||||||
|
///
|
||||||
|
/// However the forms root designer overrides these and shows it in the designer.
|
||||||
|
///
|
||||||
|
/// This test fixture checks that the AutoScaleMode value will be generated in the form's code
|
||||||
|
/// by the python forms designer.
|
||||||
|
/// </summary>
|
||||||
|
[TestFixture] |
||||||
|
public class GenerateAutoScaleModeFormTestFixture |
||||||
|
{ |
||||||
|
string generatedPythonCode; |
||||||
|
|
||||||
|
[TestFixtureSetUp] |
||||||
|
public void SetUpFixture() |
||||||
|
{ |
||||||
|
using (Form form = new Form()) { |
||||||
|
form.Name = "MainForm"; |
||||||
|
form.ClientSize = new Size(284, 264); |
||||||
|
form.AutoScaleMode = AutoScaleMode.Font; |
||||||
|
|
||||||
|
string indentString = " "; |
||||||
|
PythonForm pythonForm = new PythonForm(indentString); |
||||||
|
generatedPythonCode = pythonForm.GenerateInitializeComponentMethod(form); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
[Test] |
||||||
|
public void GeneratedCode() |
||||||
|
{ |
||||||
|
string expectedCode = "def InitializeComponent(self):\r\n" + |
||||||
|
" self.SuspendLayout()\r\n" + |
||||||
|
" # \r\n" + |
||||||
|
" # MainForm\r\n" + |
||||||
|
" # \r\n" + |
||||||
|
" self.ClientSize = System.Drawing.Size(284, 264)\r\n" + |
||||||
|
" self.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font\r\n" + |
||||||
|
" self.Name = \"MainForm\"\r\n" + |
||||||
|
" self.ResumeLayout(False)\r\n" + |
||||||
|
" self.PerformLayout()\r\n"; |
||||||
|
|
||||||
|
Assert.AreEqual(expectedCode, generatedPythonCode); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,53 @@ |
|||||||
|
// <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.Drawing; |
||||||
|
using System.Windows.Forms; |
||||||
|
using ICSharpCode.PythonBinding; |
||||||
|
using NUnit.Framework; |
||||||
|
using PythonBinding.Tests.Utils; |
||||||
|
|
||||||
|
namespace PythonBinding.Tests.Designer |
||||||
|
{ |
||||||
|
[TestFixture] |
||||||
|
public class GenerateAutoScrollFormTestFixture |
||||||
|
{ |
||||||
|
string generatedPythonCode; |
||||||
|
|
||||||
|
[TestFixtureSetUp] |
||||||
|
public void SetUpFixture() |
||||||
|
{ |
||||||
|
using (Form form = new Form()) { |
||||||
|
form.Name = "MainForm"; |
||||||
|
form.ClientSize = new Size(284, 264); |
||||||
|
form.AutoScroll = true; |
||||||
|
|
||||||
|
string indentString = " "; |
||||||
|
PythonForm pythonForm = new PythonForm(indentString); |
||||||
|
generatedPythonCode = pythonForm.GenerateInitializeComponentMethod(form); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
[Test] |
||||||
|
public void GeneratedCode() |
||||||
|
{ |
||||||
|
string expectedCode = "def InitializeComponent(self):\r\n" + |
||||||
|
" self.SuspendLayout()\r\n" + |
||||||
|
" # \r\n" + |
||||||
|
" # MainForm\r\n" + |
||||||
|
" # \r\n" + |
||||||
|
" self.AutoScroll = True\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); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,68 @@ |
|||||||
|
// <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 |
||||||
|
{ |
||||||
|
/// <summary>
|
||||||
|
/// The DoubleBuffered property on the Control class is a protected method so using the GetType().GetProperty(...)
|
||||||
|
/// method will not return it. This test checks that this property is generated when creating the python code
|
||||||
|
/// for the form.
|
||||||
|
/// </summary>
|
||||||
|
[TestFixture] |
||||||
|
public class GenerateDoubleBufferedFormTestFixture |
||||||
|
{ |
||||||
|
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; |
||||||
|
|
||||||
|
PropertyDescriptorCollection descriptors = TypeDescriptor.GetProperties(form); |
||||||
|
PropertyDescriptor doubleBufferedPropertyDescriptor = descriptors.Find("DoubleBuffered", false); |
||||||
|
doubleBufferedPropertyDescriptor.SetValue(form, true); |
||||||
|
|
||||||
|
PropertyDescriptor namePropertyDescriptor = descriptors.Find("Name", false); |
||||||
|
namePropertyDescriptor.SetValue(form, "MainForm"); |
||||||
|
|
||||||
|
string indentString = " "; |
||||||
|
PythonForm pythonForm = new PythonForm(indentString); |
||||||
|
generatedPythonCode = pythonForm.GenerateInitializeComponentMethod(form); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
[Test] |
||||||
|
public void GeneratedCode() |
||||||
|
{ |
||||||
|
string expectedCode = "def InitializeComponent(self):\r\n" + |
||||||
|
" self.SuspendLayout()\r\n" + |
||||||
|
" # \r\n" + |
||||||
|
" # MainForm\r\n" + |
||||||
|
" # \r\n" + |
||||||
|
" self.DoubleBuffered = True\r\n" + |
||||||
|
" self.Name = \"MainForm\"\r\n" + |
||||||
|
" self.ClientSize = System.Drawing.Size(284, 264)\r\n" + |
||||||
|
" self.ResumeLayout(False)\r\n" + |
||||||
|
" self.PerformLayout()\r\n"; |
||||||
|
|
||||||
|
Assert.AreEqual(expectedCode, generatedPythonCode); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,62 @@ |
|||||||
|
// <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 |
||||||
|
{ |
||||||
|
[TestFixture] |
||||||
|
public class GenerateImeModeFormTestFixture |
||||||
|
{ |
||||||
|
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); |
||||||
|
|
||||||
|
PropertyDescriptorCollection descriptors = TypeDescriptor.GetProperties(form); |
||||||
|
PropertyDescriptor doubleBufferedPropertyDescriptor = descriptors.Find("ImeMode", false); |
||||||
|
doubleBufferedPropertyDescriptor.SetValue(form, ImeMode.Alpha); |
||||||
|
|
||||||
|
PropertyDescriptor namePropertyDescriptor = descriptors.Find("Name", false); |
||||||
|
namePropertyDescriptor.SetValue(form, "MainForm"); |
||||||
|
|
||||||
|
string indentString = " "; |
||||||
|
PythonForm pythonForm = new PythonForm(indentString); |
||||||
|
generatedPythonCode = pythonForm.GenerateInitializeComponentMethod(form); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
[Test] |
||||||
|
public void GeneratedCode() |
||||||
|
{ |
||||||
|
string expectedCode = "def InitializeComponent(self):\r\n" + |
||||||
|
" self.SuspendLayout()\r\n" + |
||||||
|
" # \r\n" + |
||||||
|
" # MainForm\r\n" + |
||||||
|
" # \r\n" + |
||||||
|
" self.ImeMode = System.Windows.Forms.ImeMode.Alpha\r\n" + |
||||||
|
" self.Name = \"MainForm\"\r\n" + |
||||||
|
" self.ClientSize = System.Drawing.Size(284, 264)\r\n" + |
||||||
|
" self.ResumeLayout(False)\r\n" + |
||||||
|
" self.PerformLayout()\r\n"; |
||||||
|
|
||||||
|
Assert.AreEqual(expectedCode, generatedPythonCode); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,62 @@ |
|||||||
|
// <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 |
||||||
|
{ |
||||||
|
[TestFixture] |
||||||
|
public class GenerateRightToLeftFormTestFixture |
||||||
|
{ |
||||||
|
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); |
||||||
|
|
||||||
|
PropertyDescriptorCollection descriptors = TypeDescriptor.GetProperties(form); |
||||||
|
PropertyDescriptor doubleBufferedPropertyDescriptor = descriptors.Find("RightToLeft", false); |
||||||
|
doubleBufferedPropertyDescriptor.SetValue(form, RightToLeft.Yes); |
||||||
|
|
||||||
|
PropertyDescriptor namePropertyDescriptor = descriptors.Find("Name", false); |
||||||
|
namePropertyDescriptor.SetValue(form, "MainForm"); |
||||||
|
|
||||||
|
string indentString = " "; |
||||||
|
PythonForm pythonForm = new PythonForm(indentString); |
||||||
|
generatedPythonCode = pythonForm.GenerateInitializeComponentMethod(form); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
[Test] |
||||||
|
public void GeneratedCode() |
||||||
|
{ |
||||||
|
string expectedCode = "def InitializeComponent(self):\r\n" + |
||||||
|
" self.SuspendLayout()\r\n" + |
||||||
|
" # \r\n" + |
||||||
|
" # MainForm\r\n" + |
||||||
|
" # \r\n" + |
||||||
|
" self.RightToLeft = System.Windows.Forms.RightToLeft.Yes\r\n" + |
||||||
|
" self.Name = \"MainForm\"\r\n" + |
||||||
|
" self.ClientSize = System.Drawing.Size(284, 264)\r\n" + |
||||||
|
" self.ResumeLayout(False)\r\n" + |
||||||
|
" self.PerformLayout()\r\n"; |
||||||
|
|
||||||
|
Assert.AreEqual(expectedCode, generatedPythonCode); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,59 @@ |
|||||||
|
// <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; |
||||||
|
|
||||||
|
namespace PythonBinding.Tests.Designer |
||||||
|
{ |
||||||
|
/// <summary>
|
||||||
|
/// The python form code generator should ignore any design time properties (e.g. Locked) of the form.
|
||||||
|
/// These are put in the .resx file not the source code.
|
||||||
|
/// </summary>
|
||||||
|
[TestFixture] |
||||||
|
public class IgnoreDesignTimePropertiesTestFixture |
||||||
|
{ |
||||||
|
string expectedCode = "def InitializeComponent(self):\r\n" + |
||||||
|
" self.SuspendLayout()\r\n" + |
||||||
|
" # \r\n" + |
||||||
|
" # MainForm\r\n" + |
||||||
|
" # \r\n" + |
||||||
|
" self.Name = \"MainForm\"\r\n" + |
||||||
|
" self.ClientSize = System.Drawing.Size(200, 300)\r\n" + |
||||||
|
" self.ResumeLayout(False)\r\n" + |
||||||
|
" self.PerformLayout()\r\n"; |
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Loads a form into a DesignSurface and checks that the PythonForm does not try to
|
||||||
|
/// add design time properties and does not throw a null reference exception.
|
||||||
|
/// </summary>
|
||||||
|
[Test] |
||||||
|
public void DesignTimePropertyIsIgnore() |
||||||
|
{ |
||||||
|
using (DesignSurface designSurface = new DesignSurface(typeof(Form))) { |
||||||
|
IDesignerHost host = (IDesignerHost)designSurface.GetService(typeof(IDesignerHost)); |
||||||
|
Form form = (Form)host.RootComponent; |
||||||
|
form.AllowDrop = false; |
||||||
|
form.ClientSize = new Size(200, 300); |
||||||
|
|
||||||
|
PropertyDescriptorCollection descriptors = TypeDescriptor.GetProperties(form); |
||||||
|
PropertyDescriptor namePropertyDescriptor = descriptors.Find("Name", false); |
||||||
|
namePropertyDescriptor.SetValue(form, "MainForm"); |
||||||
|
|
||||||
|
PythonForm pythonForm = new PythonForm(" "); |
||||||
|
string code = pythonForm.GenerateInitializeComponentMethod(form); |
||||||
|
|
||||||
|
Assert.AreEqual(expectedCode, code); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,114 @@ |
|||||||
|
// <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.Drawing; |
||||||
|
using System.ComponentModel; |
||||||
|
using System.ComponentModel.Design; |
||||||
|
using System.Reflection; |
||||||
|
using System.Windows.Forms; |
||||||
|
|
||||||
|
using ICSharpCode.PythonBinding; |
||||||
|
using NUnit.Framework; |
||||||
|
|
||||||
|
namespace PythonBinding.Tests.Designer |
||||||
|
{ |
||||||
|
/// <summary>
|
||||||
|
/// Tests the PythonControlDefaultPropertyValues.IsDefaultValue method.
|
||||||
|
/// This checks the property and returns true if the value of the property is the same as its default.
|
||||||
|
/// </summary>
|
||||||
|
[TestFixture] |
||||||
|
public class IsDefaultPropertyValueTests |
||||||
|
{ |
||||||
|
Form form; |
||||||
|
PythonControlDefaultPropertyValues defaultPropertyValues; |
||||||
|
|
||||||
|
[TestFixtureSetUp] |
||||||
|
public void InitFixture() |
||||||
|
{ |
||||||
|
form = new Form(); |
||||||
|
defaultPropertyValues = new PythonControlDefaultPropertyValues(); |
||||||
|
} |
||||||
|
|
||||||
|
[TestFixtureTearDown] |
||||||
|
public void TearDownFixture() |
||||||
|
{ |
||||||
|
form.Dispose(); |
||||||
|
} |
||||||
|
|
||||||
|
[Test] |
||||||
|
public void TextPropertyDefaultIsEmptyString() |
||||||
|
{ |
||||||
|
form.Text = String.Empty; |
||||||
|
Assert.IsTrue(defaultPropertyValues.IsDefaultValue("Text", form)); |
||||||
|
} |
||||||
|
|
||||||
|
[Test] |
||||||
|
public void TextPropertyIsNotEmptyString() |
||||||
|
{ |
||||||
|
form.Text = "abc"; |
||||||
|
Assert.IsFalse(defaultPropertyValues.IsDefaultValue("Text", form)); |
||||||
|
} |
||||||
|
|
||||||
|
[Test] |
||||||
|
public void AutoValidatePropertyDefaultIsEnablePreventFocusChange() |
||||||
|
{ |
||||||
|
form.AutoValidate = AutoValidate.EnablePreventFocusChange; |
||||||
|
Assert.IsTrue(defaultPropertyValues.IsDefaultValue("AutoValidate", form)); |
||||||
|
} |
||||||
|
|
||||||
|
[Test] |
||||||
|
public void AutoValidatePropertyIsDisable() |
||||||
|
{ |
||||||
|
form.AutoValidate = AutoValidate.Disable; |
||||||
|
Assert.IsFalse(defaultPropertyValues.IsDefaultValue("AutoValidate", form)); |
||||||
|
} |
||||||
|
|
||||||
|
[Test] |
||||||
|
public void EnabledPropertyDefaultIsTrue() |
||||||
|
{ |
||||||
|
form.Enabled = true; |
||||||
|
Assert.IsTrue(defaultPropertyValues.IsDefaultValue("Enabled", form)); |
||||||
|
} |
||||||
|
|
||||||
|
[Test] |
||||||
|
public void EnabledPropertyIsFalse() |
||||||
|
{ |
||||||
|
form.Enabled = false; |
||||||
|
Assert.IsFalse(defaultPropertyValues.IsDefaultValue("Enabled", form)); |
||||||
|
} |
||||||
|
|
||||||
|
[Test] |
||||||
|
public void AccessibleDescriptionDefaultValueIsNull() |
||||||
|
{ |
||||||
|
form.AccessibleDescription = null; |
||||||
|
Assert.IsTrue(defaultPropertyValues.IsDefaultValue("AccessibleDescription", form)); |
||||||
|
} |
||||||
|
|
||||||
|
[Test] |
||||||
|
public void AutoScaleModeDefaultIsInherit() |
||||||
|
{ |
||||||
|
form.AutoScaleMode = AutoScaleMode.Inherit; |
||||||
|
Assert.IsTrue(defaultPropertyValues.IsDefaultValue("AutoScaleMode", form)); |
||||||
|
} |
||||||
|
|
||||||
|
[Test] |
||||||
|
public void PropertyDoesNotExist() |
||||||
|
{ |
||||||
|
Assert.IsFalse(defaultPropertyValues.IsDefaultValue("PropertyDoesNotExist", form)); |
||||||
|
} |
||||||
|
|
||||||
|
[Test] |
||||||
|
public void DoubleBufferedDefaultIsFalse() |
||||||
|
{ |
||||||
|
PropertyInfo property = form.GetType().GetProperty("DoubleBuffered", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static | BindingFlags.Instance); |
||||||
|
property.SetValue(form, false, null); |
||||||
|
|
||||||
|
Assert.IsTrue(defaultPropertyValues.IsDefaultValue("DoubleBuffered", form)); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,53 @@ |
|||||||
|
// <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.Drawing; |
||||||
|
using System.Windows.Forms; |
||||||
|
using ICSharpCode.PythonBinding; |
||||||
|
using NUnit.Framework; |
||||||
|
using PythonBinding.Tests.Utils; |
||||||
|
|
||||||
|
namespace PythonBinding.Tests.Designer |
||||||
|
{ |
||||||
|
/// <summary>
|
||||||
|
/// Tests that the Form's AccessibleRole property can be loaded into the designer.
|
||||||
|
/// </summary>
|
||||||
|
[TestFixture] |
||||||
|
public class LoadAccessibleRoleTestFixture : LoadFormTestFixtureBase |
||||||
|
{ |
||||||
|
string pythonCode = "class TestForm(System.Windows.Forms.Form):\r\n" + |
||||||
|
" def InitializeComponent(self):\r\n" + |
||||||
|
" self.SuspendLayout()\r\n" + |
||||||
|
" # \r\n" + |
||||||
|
" # TestForm\r\n" + |
||||||
|
" # \r\n" + |
||||||
|
" self.AccessibleRole = System.Windows.Forms.AccessibleRole.None\r\n" + |
||||||
|
" self.Name = \"TestForm\"\r\n" + |
||||||
|
" self.ResumeLayout(False)\r\n"; |
||||||
|
Form form; |
||||||
|
|
||||||
|
[TestFixtureSetUp] |
||||||
|
public void SetUpFixture() |
||||||
|
{ |
||||||
|
PythonFormWalker walker = new PythonFormWalker(this); |
||||||
|
form = walker.CreateForm(pythonCode); |
||||||
|
} |
||||||
|
|
||||||
|
[TestFixtureTearDown] |
||||||
|
public void TearDownFixture() |
||||||
|
{ |
||||||
|
form.Dispose(); |
||||||
|
} |
||||||
|
|
||||||
|
[Test] |
||||||
|
public void AccessibleRoleIsNone() |
||||||
|
{ |
||||||
|
Assert.AreEqual(AccessibleRole.None, form.AccessibleRole); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,60 @@ |
|||||||
|
// <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.Drawing; |
||||||
|
using System.IO; |
||||||
|
using System.Windows.Forms; |
||||||
|
|
||||||
|
using ICSharpCode.PythonBinding; |
||||||
|
using NUnit.Framework; |
||||||
|
using PythonBinding.Tests.Utils; |
||||||
|
|
||||||
|
namespace PythonBinding.Tests.Designer |
||||||
|
{ |
||||||
|
[TestFixture] |
||||||
|
public class LoadFormWithBooleanPropertiesSetTestFixture : LoadFormTestFixtureBase |
||||||
|
{ |
||||||
|
string pythonCode = "class TestForm(System.Windows.Forms.Form):\r\n" + |
||||||
|
" def InitializeComponent(self):\r\n" + |
||||||
|
" self.SuspendLayout()\r\n" + |
||||||
|
" # \r\n" + |
||||||
|
" # TestForm\r\n" + |
||||||
|
" # \r\n" + |
||||||
|
" self.AllowDrop = False\r\n" + |
||||||
|
" self.Enabled = False\r\n" + |
||||||
|
" self.Name = \"TestForm\"\r\n" + |
||||||
|
" self.ResumeLayout(False)\r\n"; |
||||||
|
Form form; |
||||||
|
|
||||||
|
[TestFixtureSetUp] |
||||||
|
public void SetUpFixture() |
||||||
|
{ |
||||||
|
PythonFormWalker walker = new PythonFormWalker(this); |
||||||
|
form = walker.CreateForm(pythonCode); |
||||||
|
} |
||||||
|
|
||||||
|
[TestFixtureTearDown] |
||||||
|
public void TearDownFixture() |
||||||
|
{ |
||||||
|
form.Dispose(); |
||||||
|
} |
||||||
|
|
||||||
|
[Test] |
||||||
|
public void FormEnabledIsFalse() |
||||||
|
{ |
||||||
|
Assert.IsFalse(form.Enabled); |
||||||
|
} |
||||||
|
|
||||||
|
[Test] |
||||||
|
public void FormAllowDropIsFalse() |
||||||
|
{ |
||||||
|
Assert.IsFalse(form.AllowDrop); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,76 @@ |
|||||||
|
// <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.Reflection; |
||||||
|
using System.Windows.Forms; |
||||||
|
|
||||||
|
using ICSharpCode.PythonBinding; |
||||||
|
using NUnit.Framework; |
||||||
|
|
||||||
|
namespace PythonBinding.Tests.Designer |
||||||
|
{ |
||||||
|
/// <summary>
|
||||||
|
/// Tests the PythonForm.ShouldSerialize method which determines whether a form's property
|
||||||
|
/// should be serialized.
|
||||||
|
/// </summary>
|
||||||
|
[TestFixture] |
||||||
|
public class ShouldSerializeTests |
||||||
|
{ |
||||||
|
PythonForm pythonForm; |
||||||
|
Form form; |
||||||
|
|
||||||
|
[TestFixtureSetUp] |
||||||
|
public void SetUpFixture() |
||||||
|
{ |
||||||
|
form = new Form(); |
||||||
|
} |
||||||
|
|
||||||
|
[TestFixtureTearDown] |
||||||
|
public void TearDownFixture() |
||||||
|
{ |
||||||
|
form.Dispose(); |
||||||
|
} |
||||||
|
|
||||||
|
[SetUp] |
||||||
|
public void Init() |
||||||
|
{ |
||||||
|
pythonForm = new PythonForm(); |
||||||
|
} |
||||||
|
|
||||||
|
[Test] |
||||||
|
public void ShouldNotSerializePropertyWithFalseBrowseAttribute() |
||||||
|
{ |
||||||
|
AssertShouldNotSerialize("LayoutEngine", form); |
||||||
|
} |
||||||
|
|
||||||
|
[Test] |
||||||
|
public void ShouldNotSerializeEmptyStringTextProperty() |
||||||
|
{ |
||||||
|
form.Text = String.Empty; |
||||||
|
AssertShouldNotSerialize("Text", form); |
||||||
|
} |
||||||
|
|
||||||
|
void AssertShouldSerialize(string propertyName, Form form) |
||||||
|
{ |
||||||
|
AssertShouldSerialize(propertyName, form, true); |
||||||
|
} |
||||||
|
|
||||||
|
void AssertShouldNotSerialize(string propertyName, Form form) |
||||||
|
{ |
||||||
|
AssertShouldSerialize(propertyName, form, false); |
||||||
|
} |
||||||
|
|
||||||
|
void AssertShouldSerialize(string propertyName, Form form, bool isTrue) |
||||||
|
{ |
||||||
|
PropertyDescriptor property = TypeDescriptor.GetProperties(form).Find(propertyName, true); |
||||||
|
Assert.AreEqual(isTrue, pythonForm.ShouldSerialize(form, property)); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
Loading…
Reference in new issue