Browse Source
git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/branches/3.0@3872 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61shortcuts
24 changed files with 397 additions and 104 deletions
@ -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(); |
||||||
|
} |
||||||
|
} |
@ -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); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
@ -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)); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
@ -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); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
Loading…
Reference in new issue