Browse Source

Python forms designer now supports Form Color properties.

git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/branches/3.0@3872 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61
shortcuts
Matt Ward 17 years ago
parent
commit
d0884088c2
  1. 74
      src/AddIns/BackendBindings/Python/PythonBinding/Project/Src/PythonCodeDeserializer.cs
  2. 10
      src/AddIns/BackendBindings/Python/PythonBinding/Project/Src/PythonControlDefaultPropertyValues.cs
  3. 2
      src/AddIns/BackendBindings/Python/PythonBinding/Project/Src/PythonDesignerLoader.cs
  4. 6
      src/AddIns/BackendBindings/Python/PythonBinding/Project/Src/PythonForm.cs
  5. 60
      src/AddIns/BackendBindings/Python/PythonBinding/Project/Src/PythonFormWalker.cs
  6. 30
      src/AddIns/BackendBindings/Python/PythonBinding/Project/Src/PythonPropertyValueAssignment.cs
  7. 32
      src/AddIns/BackendBindings/Python/PythonBinding/Test/Designer/CursorTypeResolutionTestFixture.cs
  8. 48
      src/AddIns/BackendBindings/Python/PythonBinding/Test/Designer/DeserializeAssignmentTestFixtureBase.cs
  9. 45
      src/AddIns/BackendBindings/Python/PythonBinding/Test/Designer/DeserializeColorFromArgbTestFixture.cs
  10. 63
      src/AddIns/BackendBindings/Python/PythonBinding/Test/Designer/GenerateFormColorTestFixture.cs
  11. 28
      src/AddIns/BackendBindings/Python/PythonBinding/Test/Designer/IsDefaultPropertyValueTests.cs
  12. 2
      src/AddIns/BackendBindings/Python/PythonBinding/Test/Designer/LoadAccessibleRoleTestFixture.cs
  13. 53
      src/AddIns/BackendBindings/Python/PythonBinding/Test/Designer/LoadColorFromArgbTestFixture.cs
  14. 2
      src/AddIns/BackendBindings/Python/PythonBinding/Test/Designer/LoadCursorTestFixture.cs
  15. 4
      src/AddIns/BackendBindings/Python/PythonBinding/Test/Designer/LoadFormTestFixtureBase.cs
  16. 2
      src/AddIns/BackendBindings/Python/PythonBinding/Test/Designer/LoadFormWithBooleanPropertiesSetTestFixture.cs
  17. 2
      src/AddIns/BackendBindings/Python/PythonBinding/Test/Designer/LoadSimpleFormTestFixture.cs
  18. 2
      src/AddIns/BackendBindings/Python/PythonBinding/Test/Designer/LoadTextBoxTestFixture.cs
  19. 6
      src/AddIns/BackendBindings/Python/PythonBinding/Test/Designer/MissingInitializeComponentMethodTestFixture.cs
  20. 16
      src/AddIns/BackendBindings/Python/PythonBinding/Test/Designer/PythonCodeDeserializerTests.cs
  21. 2
      src/AddIns/BackendBindings/Python/PythonBinding/Test/Designer/TextBoxNotAddedToFormTestFixture.cs
  22. 2
      src/AddIns/BackendBindings/Python/PythonBinding/Test/Designer/UnknownTypeTestFixture.cs
  23. 4
      src/AddIns/BackendBindings/Python/PythonBinding/Test/PythonBinding.Tests.csproj
  24. 6
      src/AddIns/BackendBindings/Python/PythonBinding/Test/Utils/MockTypeResolutionService.cs

74
src/AddIns/BackendBindings/Python/PythonBinding/Project/Src/PythonCodeDeserializer.cs

@ -6,6 +6,7 @@ @@ -6,6 +6,7 @@
// </file>
using System;
using System.Collections.Generic;
using System.ComponentModel.Design;
using System.Reflection;
using IronPython.Compiler.Ast;
@ -17,14 +18,28 @@ namespace ICSharpCode.PythonBinding @@ -17,14 +18,28 @@ namespace ICSharpCode.PythonBinding
/// </summary>
public class PythonCodeDeserializer
{
IDesignerHost designerHost;
const BindingFlags propertyBindingFlags = BindingFlags.Public | BindingFlags.GetField | BindingFlags.Static | BindingFlags.Instance;
public PythonCodeDeserializer(IDesignerHost designerHost)
IComponentCreator componentCreator;
public PythonCodeDeserializer(IComponentCreator componentCreator)
{
this.designerHost = designerHost;
this.componentCreator = componentCreator;
}
/// <summary>
/// Gets the arguments passed to the call expression.
/// </summary>
public static List<object> GetArguments(CallExpression expression)
{
List<object> args = new List<object>();
foreach (Arg a in expression.Args) {
ConstantExpression constantExpression = a.Expression as ConstantExpression;
if (constantExpression != null) {
args.Add(constantExpression.Value);
}
}
return args;
}
/// <summary>
/// Creates or gets the object specified in the python AST.
/// </summary>
@ -36,10 +51,48 @@ namespace ICSharpCode.PythonBinding @@ -36,10 +51,48 @@ namespace ICSharpCode.PythonBinding
if (node == null) {
throw new ArgumentNullException("node");
}
PythonControlFieldExpression field = PythonControlFieldExpression.Create(node as MemberExpression);
Type type = designerHost.GetType(PythonControlFieldExpression.GetPrefix(field.FullMemberName));
MemberExpression memberExpression = node as MemberExpression;
CallExpression callExpression = node as CallExpression;
if (callExpression != null) {
return Deserialize(callExpression);
}
return Deserialize(memberExpression);
}
/// <summary>
/// Deserializes expressions of the form:
///
/// 1) System.Drawing.Color.FromArgb(0, 192, 0)
/// </summary>
object Deserialize(CallExpression callExpression)
{
MemberExpression memberExpression = callExpression.Target as MemberExpression;
PythonControlFieldExpression field = PythonControlFieldExpression.Create(memberExpression);
Type type = GetType(field);
if (type != null) {
foreach (MethodInfo method in type.GetMethods(BindingFlags.Public | BindingFlags.Static)) {
if (method.Name == field.MemberName) {
if (method.GetParameters().Length == callExpression.Args.Length) {
return method.Invoke(null, GetArguments(callExpression).ToArray());
}
}
}
}
return null;
}
/// <summary>
/// Deserializes expressions of the form:
///
/// 1) System.Windows.Forms.Cursors.AppStarting
/// </summary>
object Deserialize(MemberExpression memberExpression)
{
PythonControlFieldExpression field = PythonControlFieldExpression.Create(memberExpression);
Type type = GetType(field);
if (type != null) {
BindingFlags propertyBindingFlags = BindingFlags.Public | BindingFlags.GetField | BindingFlags.Static | BindingFlags.Instance;
PropertyInfo propertyInfo = type.GetProperty(field.MemberName, propertyBindingFlags);
if (propertyInfo != null) {
return propertyInfo.GetValue(type, null);
@ -47,5 +100,10 @@ namespace ICSharpCode.PythonBinding @@ -47,5 +100,10 @@ namespace ICSharpCode.PythonBinding
}
return null;
}
Type GetType(PythonControlFieldExpression field)
{
return componentCreator.GetType(PythonControlFieldExpression.GetPrefix(field.FullMemberName));
}
}
}

10
src/AddIns/BackendBindings/Python/PythonBinding/Project/Src/PythonControlDefaultPropertyValues.cs

@ -37,6 +37,8 @@ namespace ICSharpCode.PythonBinding @@ -37,6 +37,8 @@ namespace ICSharpCode.PythonBinding
defaultPropertyValues.Add("AutoScrollMargin", new Size(0, 0));
defaultPropertyValues.Add("Location", new Point(0, 0));
defaultPropertyValues.Add("Padding", Padding.Empty);
defaultPropertyValues.Add("BackColor", Control.DefaultBackColor);
defaultPropertyValues.Add("ForeColor", Control.DefaultForeColor);
}
/// <summary>
@ -96,19 +98,13 @@ namespace ICSharpCode.PythonBinding @@ -96,19 +98,13 @@ namespace ICSharpCode.PythonBinding
return defaultPropertyValue.Equals(propertyValue);
}
if (propertyInfo.Name == "BackColor") {
// Default is Control.DefaultBackColor
return true;
} else if (propertyInfo.Name == "Icon") {
if (propertyInfo.Name == "Icon") {
return true;
} else if (propertyInfo.Name == "TransparencyKey") {
return true;
} else if (propertyInfo.Name == "Font") {
// Default is Control.DefaultFont
return true;
} else if (propertyInfo.Name == "ForeColor") {
// Default is Control.DefaultForeColor
return true;
}
return false;
}

2
src/AddIns/BackendBindings/Python/PythonBinding/Project/Src/PythonDesignerLoader.cs

@ -91,7 +91,7 @@ namespace ICSharpCode.PythonBinding @@ -91,7 +91,7 @@ namespace ICSharpCode.PythonBinding
{
// Create designer root object.
this.serializationManager = serializationManager;
PythonFormWalker visitor = new PythonFormWalker(this, base.LoaderHost);
PythonFormWalker visitor = new PythonFormWalker(this);
visitor.CreateForm(generator.ViewContent.DesignerCodeFileContent);
}
}

6
src/AddIns/BackendBindings/Python/PythonBinding/Project/Src/PythonForm.cs

@ -142,11 +142,7 @@ namespace ICSharpCode.PythonBinding @@ -142,11 +142,7 @@ namespace ICSharpCode.PythonBinding
/// Appends a property to the InitializeComponents method.
/// </summary>
void AppendProperty(object obj, PropertyDescriptor propertyDescriptor)
{
if (propertyDescriptor.Name == "Text") {
Console.WriteLine("asfads");
}
{
object propertyValue = propertyDescriptor.GetValue(obj);
if (propertyValue == null) {
return;

60
src/AddIns/BackendBindings/Python/PythonBinding/Project/Src/PythonFormWalker.cs

@ -31,10 +31,10 @@ namespace ICSharpCode.PythonBinding @@ -31,10 +31,10 @@ namespace ICSharpCode.PythonBinding
string formName = String.Empty;
PythonCodeDeserializer deserializer;
public PythonFormWalker(IComponentCreator componentCreator, IDesignerHost designerHost)
public PythonFormWalker(IComponentCreator componentCreator)
{
this.componentCreator = componentCreator;
deserializer = new PythonCodeDeserializer(designerHost);
deserializer = new PythonCodeDeserializer(componentCreator);
}
/// <summary>
@ -107,12 +107,21 @@ namespace ICSharpCode.PythonBinding @@ -107,12 +107,21 @@ namespace ICSharpCode.PythonBinding
MemberExpression memberExpression = node.Target as MemberExpression;
if (memberExpression != null) {
string name = PythonControlFieldExpression.GetMemberName(memberExpression);
if (walkingAssignment) {
Type type = GetType(name);
List<object> args = GetArguments(node);
object instance = componentCreator.CreateInstance(type, args, fieldExpression.MemberName, false);
if (!SetPropertyValue(form, fieldExpression.MemberName, instance)) {
AddComponent(fieldExpression.MemberName, instance);
if (walkingAssignment) {
Type type = componentCreator.GetType(name);
if (type != null) {
List<object> args = PythonCodeDeserializer.GetArguments(node);
object instance = componentCreator.CreateInstance(type, args, fieldExpression.MemberName, false);
if (!SetPropertyValue(form, fieldExpression.MemberName, instance)) {
AddComponent(fieldExpression.MemberName, instance);
}
} else {
object obj = deserializer.Deserialize(node);
if (obj != null) {
SetPropertyValue(form, fieldExpression.MemberName, obj);
} else {
throw new PythonFormWalkerException(String.Format("Could not find type '{0}'.", name));
}
}
} else if (name == "self.Controls.Add") {
string controlName = PythonControlFieldExpression.GetControlNameBeingAdded(node);
@ -127,21 +136,6 @@ namespace ICSharpCode.PythonBinding @@ -127,21 +136,6 @@ namespace ICSharpCode.PythonBinding
SetPropertyValue(fieldExpression.MemberName, node.Name.ToString());
return false;
}
/// <summary>
/// Gets the arguments passed to the call expression.
/// </summary>
static List<object> GetArguments(CallExpression expression)
{
List<object> args = new List<object>();
foreach (Arg a in expression.Args) {
ConstantExpression constantExpression = a.Expression as ConstantExpression;
if (constantExpression != null) {
args.Add(constantExpression.Value);
}
}
return args;
}
static bool IsInitializeComponentMethod(FunctionDefinition node)
{
@ -185,16 +179,7 @@ namespace ICSharpCode.PythonBinding @@ -185,16 +179,7 @@ namespace ICSharpCode.PythonBinding
}
return propertyValue;
}
Type GetType(string typeName)
{
Type type = componentCreator.GetType(typeName);
if (type == null) {
throw new PythonFormWalkerException(String.Format("Could not find type '{0}'.", typeName));
}
return type;
}
/// <summary>
/// Looks for the control with the specified name in the objects that have been
/// created whilst processing the InitializeComponent method.
@ -218,15 +203,6 @@ namespace ICSharpCode.PythonBinding @@ -218,15 +203,6 @@ namespace ICSharpCode.PythonBinding
createdObjects.Add(variableName, component);
}
static string GetFirstArgumentAsString(CallExpression node)
{
List<object> args = GetArguments(node);
if (args.Count > 0) {
return args[0] as String;
}
return null;
}
Control GetCurrentControl()
{
string variableName = PythonControlFieldExpression.GetVariableNameFromSelfReference(fieldExpression.FullMemberName);

30
src/AddIns/BackendBindings/Python/PythonBinding/Project/Src/PythonPropertyValueAssignment.cs

@ -41,18 +41,21 @@ namespace ICSharpCode.PythonBinding @@ -41,18 +41,21 @@ namespace ICSharpCode.PythonBinding
} else if (propertyType.IsEnum) {
return propertyType.FullName + "." + propertyValue.ToString();
} else if (propertyType == typeof(Cursor)) {
return GetCursorToString(propertyValue as Cursor);
return GetCursorAsString(propertyValue as Cursor);
} else if (propertyType == typeof(Point)) {
Point point = (Point)propertyValue;
return point.GetType().FullName + "(" + point.X + ", " + point.Y + ")";
} else if (propertyType == typeof(Padding)) {
Padding padding = (Padding)propertyValue;
return padding.GetType().FullName + "(" + padding.Left + ", " + padding.Top + ", " + padding.Right + ", " + padding.Bottom + ")";
} else if (propertyType == typeof(Color)) {
Color color = (Color)propertyValue;
return GetColorAsString(color);
}
return propertyValue.ToString();
}
static string GetCursorToString(Cursor cursor)
static string GetCursorAsString(Cursor cursor)
{
foreach (PropertyInfo propertyInfo in typeof(Cursors).GetProperties(BindingFlags.Public | BindingFlags.Static)) {
Cursor standardCursor = (Cursor)propertyInfo.GetValue(null, null);
@ -62,5 +65,28 @@ namespace ICSharpCode.PythonBinding @@ -62,5 +65,28 @@ namespace ICSharpCode.PythonBinding
}
return String.Empty;
}
static string GetColorAsString(Color color)
{
if (color.IsSystemColor) {
return GetColorAsString(color, typeof(SystemColors));
} else if (color.IsNamedColor) {
return GetColorAsString(color, typeof(Color));
}
// Custom color.
return color.GetType().FullName + ".FromArgb(" + color.R + ", " + color.G + ", " + color.B + ")";
}
static string GetColorAsString(Color color, Type type)
{
foreach (PropertyInfo property in type.GetProperties(BindingFlags.Public | BindingFlags.Static)) {
Color standardColor = (Color)property.GetValue(null, null);
if (color == standardColor) {
return type.FullName + "." + standardColor.Name;
}
}
return String.Empty;
}
}
}

32
src/AddIns/BackendBindings/Python/PythonBinding/Test/Designer/CursorTypeResolutionTestFixture.cs

@ -22,45 +22,23 @@ namespace PythonBinding.Tests.Designer @@ -22,45 +22,23 @@ namespace PythonBinding.Tests.Designer
/// PythonCodeDeserializer.
/// </summary>
[TestFixture]
public class CursorTypeResolutionTestFixture
public class CursorTypeResolutionTestFixture : DeserializeAssignmentTestFixtureBase
{
string pythonCode = "self.Cursors = System.Windows.Forms.Cursors.AppStarting";
Node rhsAssignmentNode;
object obj;
MockDesignerLoaderHost mockDesignerLoaderHost;
MockTypeResolutionService typeResolutionService;
[TestFixtureSetUp]
public void SetUpFixture()
{
PythonParser parser = new PythonParser();
PythonAst ast = parser.CreateAst(@"snippet.py", pythonCode);
SuiteStatement suiteStatement = (SuiteStatement)ast.Body;
AssignmentStatement assignment = suiteStatement.Statements[0] as AssignmentStatement;
rhsAssignmentNode = assignment.Right;
mockDesignerLoaderHost = new MockDesignerLoaderHost();
typeResolutionService = mockDesignerLoaderHost.TypeResolutionService;
PythonCodeDeserializer deserializer = new PythonCodeDeserializer(mockDesignerLoaderHost);
obj = deserializer.Deserialize(rhsAssignmentNode);
}
[Test]
public void RhsAssignmentNodeExists()
public override string GetPythonCode()
{
Assert.IsNotNull(rhsAssignmentNode);
return "self.Cursors = System.Windows.Forms.Cursors.AppStarting";
}
[Test]
public void DeserializedObjectIsCursorsAppStarting()
{
Assert.AreEqual(Cursors.AppStarting, obj);
Assert.AreEqual(Cursors.AppStarting, deserializedObject);
}
[Test]
public void CursorsTypeResolved()
{
Assert.AreEqual("System.Windows.Forms.Cursors", typeResolutionService.LastTypeNameResolved);
Assert.AreEqual("System.Windows.Forms.Cursors", base.LastTypeNameResolved);
}
}
}

48
src/AddIns/BackendBindings/Python/PythonBinding/Test/Designer/DeserializeAssignmentTestFixtureBase.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 System.ComponentModel;
using System.ComponentModel.Design;
using System.Drawing;
using System.Windows.Forms;
using ICSharpCode.PythonBinding;
using IronPython.Compiler.Ast;
using NUnit.Framework;
using PythonBinding.Tests.Utils;
namespace PythonBinding.Tests.Designer
{
/// <summary>
/// Base class for all tests of the PythonCodeDeserialize when deserializing an
/// assignment.
/// </summary>
public abstract class DeserializeAssignmentTestFixtureBase : LoadFormTestFixtureBase
{
protected Node rhsAssignmentNode;
protected object deserializedObject;
protected MockDesignerLoaderHost mockDesignerLoaderHost;
protected MockTypeResolutionService typeResolutionService;
[TestFixtureSetUp]
public void SetUpFixture()
{
PythonParser parser = new PythonParser();
PythonAst ast = parser.CreateAst(@"snippet.py", GetPythonCode());
SuiteStatement suiteStatement = (SuiteStatement)ast.Body;
AssignmentStatement assignment = suiteStatement.Statements[0] as AssignmentStatement;
rhsAssignmentNode = assignment.Right;
mockDesignerLoaderHost = new MockDesignerLoaderHost();
typeResolutionService = mockDesignerLoaderHost.TypeResolutionService;
PythonCodeDeserializer deserializer = new PythonCodeDeserializer(this);
deserializedObject = deserializer.Deserialize(rhsAssignmentNode);
}
public abstract string GetPythonCode();
}
}

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

@ -0,0 +1,45 @@ @@ -0,0 +1,45 @@
// <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 IronPython.Compiler.Ast;
using NUnit.Framework;
using PythonBinding.Tests.Utils;
namespace PythonBinding.Tests.Designer
{
/// <summary>
/// Tests that the string "System.Drawing.Color.FromArgb(0, 192, 10)" can be converted to an object by the
/// PythonCodeDeserializer.
/// </summary>
[TestFixture]
public class DeserializeColorFromArgbTestFixture : DeserializeAssignmentTestFixtureBase
{
public override string GetPythonCode()
{
return "self.BackColor = System.Drawing.Color.FromArgb(0, 192, 10)";
}
[Test]
public void DeserializedObjectIsExpectedCustomColor()
{
Color customColor = Color.FromArgb(0, 192, 10);
Assert.AreEqual(customColor, deserializedObject);
}
[Test]
public void ColorTypeResolved()
{
Assert.AreEqual("System.Drawing.Color", LastTypeNameResolved);
}
}
}

63
src/AddIns/BackendBindings/Python/PythonBinding/Test/Designer/GenerateFormColorTestFixture.cs

@ -0,0 +1,63 @@ @@ -0,0 +1,63 @@
// <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 GenerateFormColorTestFixture
{
string generatedPythonCode;
[TestFixtureSetUp]
public void SetUpFixture()
{
using (Form form = new Form()) {
form.Name = "MainForm";
form.ClientSize = new Size(284, 264);
form.BackColor = SystemColors.HotTrack;
form.ForeColor = Color.Red;
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.BackColor = System.Drawing.SystemColors.HotTrack\r\n" +
" self.ClientSize = System.Drawing.Size(284, 264)\r\n" +
" self.ForeColor = System.Drawing.Color.Red\r\n" +
" self.Name = \"MainForm\"\r\n" +
" self.Visible = False\r\n" +
" self.ResumeLayout(False)\r\n" +
" self.PerformLayout()\r\n";
Assert.AreEqual(expectedCode, generatedPythonCode);
}
[Test]
public void ConvertCustomColorToString()
{
Color customColor = Color.FromArgb(0, 192, 10);
Assert.AreEqual("System.Drawing.Color.FromArgb(0, 192, 10)", PythonPropertyValueAssignment.ToString(customColor));
}
}
}

28
src/AddIns/BackendBindings/Python/PythonBinding/Test/Designer/IsDefaultPropertyValueTests.cs

@ -210,6 +210,34 @@ namespace PythonBinding.Tests.Designer @@ -210,6 +210,34 @@ namespace PythonBinding.Tests.Designer
{
form.Padding = new Padding(10, 10, 10, 10);
Assert.IsFalse(defaultPropertyValues.IsDefaultValue("Padding", form));
}
[Test]
public void BackColorPropertyDefaultIsControlDefaultBackColor()
{
form.BackColor = Control.DefaultBackColor;
Assert.IsTrue(defaultPropertyValues.IsDefaultValue("BackColor", form));
}
[Test]
public void NonDefaultBackColorProperty()
{
form.BackColor = Color.Blue;
Assert.IsFalse(defaultPropertyValues.IsDefaultValue("BackColor", form));
}
[Test]
public void ForeColorPropertyDefaultIsControlDefaultForeColor()
{
form.ForeColor = Control.DefaultForeColor;
Assert.IsTrue(defaultPropertyValues.IsDefaultValue("ForeColor", form));
}
[Test]
public void NonDefaultForeColorProperty()
{
form.ForeColor = Color.Blue;
Assert.IsFalse(defaultPropertyValues.IsDefaultValue("ForeColor", form));
}
}
}

2
src/AddIns/BackendBindings/Python/PythonBinding/Test/Designer/LoadAccessibleRoleTestFixture.cs

@ -34,7 +34,7 @@ namespace PythonBinding.Tests.Designer @@ -34,7 +34,7 @@ namespace PythonBinding.Tests.Designer
[TestFixtureSetUp]
public void SetUpFixture()
{
PythonFormWalker walker = new PythonFormWalker(this, new MockDesignerLoaderHost());
PythonFormWalker walker = new PythonFormWalker(this);
form = walker.CreateForm(pythonCode);
}

53
src/AddIns/BackendBindings/Python/PythonBinding/Test/Designer/LoadColorFromArgbTestFixture.cs

@ -0,0 +1,53 @@ @@ -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.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 LoadColorFromArgbTestFixture : 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.BackColor = System.Drawing.Color.FromArgb(10, 190, 0)\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 FormBackColor()
{
Assert.AreEqual(Color.FromArgb(10, 190, 0), form.BackColor);
}
}
}

2
src/AddIns/BackendBindings/Python/PythonBinding/Test/Designer/LoadCursorTestFixture.cs

@ -34,7 +34,7 @@ namespace PythonBinding.Tests.Designer @@ -34,7 +34,7 @@ namespace PythonBinding.Tests.Designer
[TestFixtureSetUp]
public void SetUpFixture()
{
PythonFormWalker walker = new PythonFormWalker(this, new MockDesignerLoaderHost());
PythonFormWalker walker = new PythonFormWalker(this);
form = walker.CreateForm(pythonCode);
}

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

@ -88,6 +88,10 @@ namespace PythonBinding.Tests.Designer @@ -88,6 +88,10 @@ namespace PythonBinding.Tests.Designer
protected List<string> TypeNames {
get { return typeNames; }
}
protected string LastTypeNameResolved {
get { return TypeNames[TypeNames.Count - 1]; }
}
protected CreatedInstance GetCreatedInstance(Type type)
{

2
src/AddIns/BackendBindings/Python/PythonBinding/Test/Designer/LoadFormWithBooleanPropertiesSetTestFixture.cs

@ -35,7 +35,7 @@ namespace PythonBinding.Tests.Designer @@ -35,7 +35,7 @@ namespace PythonBinding.Tests.Designer
[TestFixtureSetUp]
public void SetUpFixture()
{
PythonFormWalker walker = new PythonFormWalker(this, new MockDesignerLoaderHost());
PythonFormWalker walker = new PythonFormWalker(this);
form = walker.CreateForm(pythonCode);
}

2
src/AddIns/BackendBindings/Python/PythonBinding/Test/Designer/LoadSimpleFormTestFixture.cs

@ -37,7 +37,7 @@ namespace PythonBinding.Tests.Designer @@ -37,7 +37,7 @@ namespace PythonBinding.Tests.Designer
[TestFixtureSetUp]
public void SetUpFixture()
{
PythonFormWalker walker = new PythonFormWalker(this, new MockDesignerLoaderHost());
PythonFormWalker walker = new PythonFormWalker(this);
form = walker.CreateForm(pythonCode);
if (CreatedComponents.Count > 0) {

2
src/AddIns/BackendBindings/Python/PythonBinding/Test/Designer/LoadTextBoxTestFixture.cs

@ -41,7 +41,7 @@ namespace PythonBinding.Tests.Designer @@ -41,7 +41,7 @@ namespace PythonBinding.Tests.Designer
[TestFixtureSetUp]
public void SetUpFixture()
{
PythonFormWalker walker = new PythonFormWalker(this, new MockDesignerLoaderHost());
PythonFormWalker walker = new PythonFormWalker(this);
form = walker.CreateForm(pythonCode);
if (form.Controls.Count > 0) {
textBox = form.Controls[0] as TextBox;

6
src/AddIns/BackendBindings/Python/PythonBinding/Test/Designer/MissingInitializeComponentMethodTestFixture.cs

@ -38,7 +38,7 @@ namespace PythonBinding.Tests.Designer @@ -38,7 +38,7 @@ namespace PythonBinding.Tests.Designer
[ExpectedException(typeof(PythonFormWalkerException))]
public void PythonFormWalkerExceptionThrown()
{
PythonFormWalker walker = new PythonFormWalker(this, new MockDesignerLoaderHost());
PythonFormWalker walker = new PythonFormWalker(this);
walker.CreateForm(pythonCode);
Assert.Fail("Exception should have been thrown before this.");
}
@ -50,7 +50,7 @@ namespace PythonBinding.Tests.Designer @@ -50,7 +50,7 @@ namespace PythonBinding.Tests.Designer
public void ClassWithNoBody()
{
ClassDefinition classDef = new ClassDefinition(new SymbolId(10), null, null);
PythonFormWalker walker = new PythonFormWalker(this, new MockDesignerLoaderHost());
PythonFormWalker walker = new PythonFormWalker(this);
walker.Walk(classDef);
}
@ -63,7 +63,7 @@ namespace PythonBinding.Tests.Designer @@ -63,7 +63,7 @@ namespace PythonBinding.Tests.Designer
{
List<Expression> lhs = new List<Expression>();
AssignmentStatement assign = new AssignmentStatement(lhs.ToArray(), null);
PythonFormWalker walker = new PythonFormWalker(this, new MockDesignerLoaderHost());
PythonFormWalker walker = new PythonFormWalker(this);
walker.Walk(assign);
}
}

16
src/AddIns/BackendBindings/Python/PythonBinding/Test/Designer/PythonCodeDeserializerTests.cs

@ -14,14 +14,14 @@ using PythonBinding.Tests.Utils; @@ -14,14 +14,14 @@ using PythonBinding.Tests.Utils;
namespace PythonBinding.Tests.Designer
{
[TestFixture]
public class PythonCodeDeserializerTests
public class PythonCodeDeserializerTests : LoadFormTestFixtureBase
{
PythonCodeDeserializer deserializer;
[TestFixtureSetUp]
public void SetUpFixture()
{
deserializer = new PythonCodeDeserializer(new MockDesignerLoaderHost());
deserializer = new PythonCodeDeserializer(this);
}
[Test]
@ -52,6 +52,18 @@ namespace PythonBinding.Tests.Designer @@ -52,6 +52,18 @@ namespace PythonBinding.Tests.Designer
SuiteStatement suiteStatement = (SuiteStatement)ast.Body;
AssignmentStatement assignment = suiteStatement.Statements[0] as AssignmentStatement;
Assert.IsNull(deserializer.Deserialize(assignment.Right));
}
[Test]
public void UnknownTypeNameInCallExpression()
{
string pythonCode = "self.Cursors = System.Windows.Forms.UnknownType.CreateDefaultCursor()";
PythonParser parser = new PythonParser();
PythonAst ast = parser.CreateAst(@"snippet.py", pythonCode);
SuiteStatement suiteStatement = (SuiteStatement)ast.Body;
AssignmentStatement assignment = suiteStatement.Statements[0] as AssignmentStatement;
Assert.IsNull(deserializer.Deserialize(assignment.Right));
}
}

2
src/AddIns/BackendBindings/Python/PythonBinding/Test/Designer/TextBoxNotAddedToFormTestFixture.cs

@ -45,7 +45,7 @@ namespace PythonBinding.Tests.Designer @@ -45,7 +45,7 @@ namespace PythonBinding.Tests.Designer
[TestFixtureSetUp]
public void SetUpFixture()
{
PythonFormWalker walker = new PythonFormWalker(this, new MockDesignerLoaderHost());
PythonFormWalker walker = new PythonFormWalker(this);
form = walker.CreateForm(pythonCode);
}

2
src/AddIns/BackendBindings/Python/PythonBinding/Test/Designer/UnknownTypeTestFixture.cs

@ -38,7 +38,7 @@ namespace PythonBinding.Tests.Designer @@ -38,7 +38,7 @@ namespace PythonBinding.Tests.Designer
[ExpectedException(typeof(PythonFormWalkerException))]
public void PythonFormWalkerExceptionThrown()
{
PythonFormWalker walker = new PythonFormWalker(this, new MockDesignerLoaderHost());
PythonFormWalker walker = new PythonFormWalker(this);
walker.CreateForm(pythonCode);
Assert.Fail("Exception should have been thrown before this.");
}

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

@ -146,6 +146,8 @@ @@ -146,6 +146,8 @@
<Compile Include="Converter\VBStringConcatTestFixture.cs" />
<Compile Include="Converter\WhileLoopConversionTestFixture.cs" />
<Compile Include="Designer\CursorTypeResolutionTestFixture.cs" />
<Compile Include="Designer\DeserializeAssignmentTestFixtureBase.cs" />
<Compile Include="Designer\DeserializeColorFromArgbTestFixture.cs" />
<Compile Include="Designer\EnabledSetUsingPropertyDescriptorTestFixture.cs" />
<Compile Include="Designer\FindInitializeComponentMethodTestFixture.cs" />
<Compile Include="Designer\GenerateAccessibleRoleFormTestFixture.cs" />
@ -153,6 +155,7 @@ @@ -153,6 +155,7 @@
<Compile Include="Designer\GenerateAutoScrollFormTestFixture.cs" />
<Compile Include="Designer\GenerateCursorFormTestFixture.cs" />
<Compile Include="Designer\GenerateDoubleBufferedFormTestFixture.cs" />
<Compile Include="Designer\GenerateFormColorTestFixture.cs" />
<Compile Include="Designer\GenerateFormLocationTestFixture.cs" />
<Compile Include="Designer\GenerateFormPaddingTestFixture.cs" />
<Compile Include="Designer\GenerateImeModeFormTestFixture.cs" />
@ -165,6 +168,7 @@ @@ -165,6 +168,7 @@
<Compile Include="Designer\IsDefaultPropertyValueTests.cs" />
<Compile Include="Designer\IsFullyQualifiedBaseClassFormDesignableTestFixture.cs" />
<Compile Include="Designer\LoadAccessibleRoleTestFixture.cs" />
<Compile Include="Designer\LoadColorFromArgbTestFixture.cs" />
<Compile Include="Designer\LoadCursorTestFixture.cs" />
<Compile Include="Designer\LoadFormTestFixtureBase.cs" />
<Compile Include="Designer\LoadFormWithBooleanPropertiesSetTestFixture.cs" />

6
src/AddIns/BackendBindings/Python/PythonBinding/Test/Utils/MockTypeResolutionService.cs

@ -7,6 +7,7 @@ @@ -7,6 +7,7 @@
using System;
using System.ComponentModel.Design;
using System.Drawing;
using System.Reflection;
using System.Windows.Forms;
@ -53,6 +54,11 @@ namespace PythonBinding.Tests.Utils @@ -53,6 +54,11 @@ namespace PythonBinding.Tests.Utils
return type;
}
type = typeof(Color).Assembly.GetType(name, false);
if (type != null) {
return type;
}
return Type.GetType(name);
}

Loading…
Cancel
Save