Browse Source
git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/branches/3.0@3990 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61shortcuts
38 changed files with 298 additions and 119 deletions
@ -0,0 +1,72 @@ |
|||||||
|
// <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 LoadSimpleUserControlTestFixture |
||||||
|
{ |
||||||
|
MockComponentCreator componentCreator = new MockComponentCreator(); |
||||||
|
UserControl userControl; |
||||||
|
|
||||||
|
public string PythonCode { |
||||||
|
get { |
||||||
|
return "class MainForm(System.Windows.Forms.UserControl):\r\n" + |
||||||
|
" def InitializeComponent(self):\r\n" + |
||||||
|
" self.SuspendLayout()\r\n" + |
||||||
|
" # \r\n" + |
||||||
|
" # userControl1\r\n" + |
||||||
|
" # \r\n" + |
||||||
|
" self.ClientSize = System.Drawing.Size(300, 400)\r\n" + |
||||||
|
" self.Name = \"userControl1\"\r\n" + |
||||||
|
" self.ResumeLayout(False)\r\n"; |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
[TestFixtureSetUp] |
||||||
|
public void SetUpFixture() |
||||||
|
{ |
||||||
|
PythonComponentWalker walker = new PythonComponentWalker(componentCreator); |
||||||
|
userControl = walker.CreateComponent(PythonCode) as UserControl; |
||||||
|
} |
||||||
|
|
||||||
|
[TestFixtureTearDown] |
||||||
|
public void TearDownFixture() |
||||||
|
{ |
||||||
|
userControl.Dispose(); |
||||||
|
} |
||||||
|
|
||||||
|
[Test] |
||||||
|
public void UserControlCreated() |
||||||
|
{ |
||||||
|
Assert.IsNotNull(userControl); |
||||||
|
} |
||||||
|
|
||||||
|
[Test] |
||||||
|
public void UserControlName() |
||||||
|
{ |
||||||
|
Assert.AreEqual("userControl1", userControl.Name); |
||||||
|
} |
||||||
|
|
||||||
|
[Test] |
||||||
|
public void UserControlClientSize() |
||||||
|
{ |
||||||
|
Size size = new Size(300, 400); |
||||||
|
Assert.AreEqual(size, userControl.ClientSize); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
@ -0,0 +1,74 @@ |
|||||||
|
// <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 ICSharpCode.PythonBinding; |
||||||
|
using IronPython.Compiler.Ast; |
||||||
|
using NUnit.Framework; |
||||||
|
|
||||||
|
namespace PythonBinding.Tests.Designer |
||||||
|
{ |
||||||
|
[TestFixture] |
||||||
|
public class PythonBaseClassTests |
||||||
|
{ |
||||||
|
[Test] |
||||||
|
public void FormBaseClass() |
||||||
|
{ |
||||||
|
string code = "class MainForm(System.Windows.Forms.Form):\r\n" + |
||||||
|
" def InitializeComponent(self):\r\n" + |
||||||
|
" self.SuspendLayout()\r\n" + |
||||||
|
" # \r\n" + |
||||||
|
" # MainForm\r\n" + |
||||||
|
" # \r\n" + |
||||||
|
" self.ClientSize = System.Drawing.Size(300, 400)\r\n" + |
||||||
|
" self.Name = \"MainForm\"\r\n" + |
||||||
|
" self.ResumeLayout(False)\r\n"; |
||||||
|
|
||||||
|
ClassDefinition classDef = GetClassDefinition(code); |
||||||
|
|
||||||
|
Assert.AreEqual("System.Windows.Forms.Form", PythonComponentWalker.GetBaseClassName(classDef)); |
||||||
|
} |
||||||
|
|
||||||
|
[Test] |
||||||
|
public void NoBaseClass() |
||||||
|
{ |
||||||
|
string code = "class MainForm:\r\n" + |
||||||
|
" def InitializeComponent(self):\r\n" + |
||||||
|
" pass\r\n"; |
||||||
|
|
||||||
|
ClassDefinition classDef = GetClassDefinition(code); |
||||||
|
|
||||||
|
Assert.AreEqual(String.Empty, PythonComponentWalker.GetBaseClassName(classDef)); |
||||||
|
} |
||||||
|
|
||||||
|
[Test] |
||||||
|
public void UnqualifiedBaseClass() |
||||||
|
{ |
||||||
|
string code = "class MainForm(Form):\r\n" + |
||||||
|
" def InitializeComponent(self):\r\n" + |
||||||
|
" self.SuspendLayout()\r\n" + |
||||||
|
" # \r\n" + |
||||||
|
" # MainForm\r\n" + |
||||||
|
" # \r\n" + |
||||||
|
" self.ClientSize = System.Drawing.Size(300, 400)\r\n" + |
||||||
|
" self.Name = \"MainForm\"\r\n" + |
||||||
|
" self.ResumeLayout(False)\r\n"; |
||||||
|
|
||||||
|
ClassDefinition classDef = GetClassDefinition(code); |
||||||
|
|
||||||
|
Assert.AreEqual("Form", PythonComponentWalker.GetBaseClassName(classDef)); |
||||||
|
} |
||||||
|
|
||||||
|
ClassDefinition GetClassDefinition(string code) |
||||||
|
{ |
||||||
|
PythonParser parser = new PythonParser(); |
||||||
|
PythonAst ast = parser.CreateAst(@"test.py", code); |
||||||
|
SuiteStatement suite = ast.Body as SuiteStatement; |
||||||
|
return suite.Statements[0] as ClassDefinition; |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
Loading…
Reference in new issue