Browse Source
git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/branches/3.0@4338 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61shortcuts
22 changed files with 654 additions and 59 deletions
@ -0,0 +1,136 @@
@@ -0,0 +1,136 @@
|
||||
// <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.ComponentModel.Design; |
||||
using System.ComponentModel.Design.Serialization; |
||||
using System.Drawing; |
||||
using System.Globalization; |
||||
using System.Windows.Forms; |
||||
using ICSharpCode.PythonBinding; |
||||
using NUnit.Framework; |
||||
using PythonBinding.Tests.Utils; |
||||
|
||||
namespace PythonBinding.Tests.Designer |
||||
{ |
||||
[TestFixture] |
||||
public class GenerateLocalImageResourceTestFixture |
||||
{ |
||||
MockResourceWriter resourceWriter; |
||||
MockComponentCreator componentCreator; |
||||
string generatedPythonCode; |
||||
MockResourceWriter resourceWriter2; |
||||
MockComponentCreator componentCreator2; |
||||
|
||||
[TestFixtureSetUp] |
||||
public void SetUpFixture() |
||||
{ |
||||
resourceWriter = new MockResourceWriter(); |
||||
componentCreator = new MockComponentCreator(); |
||||
componentCreator.SetResourceWriter(resourceWriter); |
||||
|
||||
resourceWriter2 = new MockResourceWriter(); |
||||
componentCreator2 = new MockComponentCreator(); |
||||
componentCreator2.SetResourceWriter(resourceWriter2); |
||||
|
||||
using (DesignSurface designSurface = new DesignSurface(typeof(Form))) { |
||||
IDesignerHost host = (IDesignerHost)designSurface.GetService(typeof(IDesignerHost)); |
||||
IEventBindingService eventBindingService = new MockEventBindingService(host); |
||||
Form form = (Form)host.RootComponent; |
||||
form.ClientSize = new Size(200, 300); |
||||
|
||||
PropertyDescriptorCollection descriptors = TypeDescriptor.GetProperties(form); |
||||
PropertyDescriptor namePropertyDescriptor = descriptors.Find("Name", false); |
||||
namePropertyDescriptor.SetValue(form, "MainForm"); |
||||
|
||||
// Add picture box
|
||||
PictureBox pictureBox = (PictureBox)host.CreateComponent(typeof(PictureBox), "pictureBox1"); |
||||
pictureBox.Location = new Point(0, 0); |
||||
//pictureBox.Image = new Bitmap(10, 10);
|
||||
pictureBox.Size = new Size(100, 120); |
||||
pictureBox.TabIndex = 0; |
||||
form.Controls.Add(pictureBox); |
||||
|
||||
PythonControl pythonControl = new PythonControl(" ", componentCreator); |
||||
generatedPythonCode = pythonControl.GenerateInitializeComponentMethod(form); |
||||
|
||||
// Check that calling the GenerateInitializeComponentMethodBody also generates a resource file.
|
||||
PythonControl pythonControl2 = new PythonControl(" ", componentCreator2); |
||||
pythonControl2.GenerateInitializeComponentMethodBody(form, 0); |
||||
} |
||||
} |
||||
|
||||
[Test] |
||||
public void GeneratedCode() |
||||
{ |
||||
string expectedCode = "def InitializeComponent(self):\r\n" + |
||||
//" resources = System.Windows.Forms.ComponentModel(clr.GetType(MainForm))\r\n" +
|
||||
" self._pictureBox1 = System.Windows.Forms.PictureBox()\r\n" + |
||||
" self._pictureBox1.BeginInit()\r\n" + |
||||
" self.SuspendLayout()\r\n" + |
||||
" # \r\n" + |
||||
" # pictureBox1\r\n" + |
||||
" # \r\n" + |
||||
" self._pictureBox1.Location = System.Drawing.Point(0, 0)\r\n" + |
||||
//" self._pictureBox1.Image = resources.GetObject(\"pictureBox1.Image\")\r\n" +
|
||||
" self._pictureBox1.Name = \"pictureBox1\"\r\n" + |
||||
" self._pictureBox1.Size = System.Drawing.Size(100, 120)\r\n" + |
||||
" self._pictureBox1.TabIndex = 0\r\n" + |
||||
" self._pictureBox1.TabStop = False\r\n" + |
||||
" # \r\n" + |
||||
" # MainForm\r\n" + |
||||
" # \r\n" + |
||||
" self.ClientSize = System.Drawing.Size(200, 300)\r\n" + |
||||
" self.Controls.Add(self._pictureBox1)\r\n" + |
||||
" self.Name = \"MainForm\"\r\n" + |
||||
" self._pictureBox1.EndInit()\r\n" + |
||||
" self.ResumeLayout(False)\r\n" + |
||||
" self.PerformLayout()\r\n"; |
||||
|
||||
Assert.AreEqual(expectedCode, generatedPythonCode, generatedPythonCode); |
||||
} |
||||
|
||||
[Test] |
||||
public void ResourceWriterRetrievedFromComponentCreator() |
||||
{ |
||||
Assert.IsTrue(componentCreator.GetResourceWriterCalled); |
||||
} |
||||
|
||||
[Test] |
||||
public void CultureInfoInvariantCulturePassedToGetResourceWriter() |
||||
{ |
||||
Assert.AreEqual(CultureInfo.InvariantCulture, componentCreator.CultureInfoPassedToGetResourceWriter); |
||||
} |
||||
|
||||
[Test] |
||||
public void ResourceWriterIsDisposed() |
||||
{ |
||||
Assert.IsTrue(resourceWriter.IsDisposed); |
||||
} |
||||
|
||||
[Test] |
||||
public void ResourceWriterRetrievedFromComponentCreator2() |
||||
{ |
||||
Assert.IsTrue(componentCreator2.GetResourceWriterCalled); |
||||
} |
||||
|
||||
[Test] |
||||
public void CultureInfoInvariantCulturePassedToGetResourceWriter2() |
||||
{ |
||||
Assert.AreEqual(CultureInfo.InvariantCulture, componentCreator2.CultureInfoPassedToGetResourceWriter); |
||||
} |
||||
|
||||
[Test] |
||||
public void ResourceWriter2IsDisposed() |
||||
{ |
||||
Assert.IsTrue(resourceWriter2.IsDisposed); |
||||
} |
||||
|
||||
} |
||||
} |
||||
@ -0,0 +1,92 @@
@@ -0,0 +1,92 @@
|
||||
// <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.ComponentModel.Design.Serialization; |
||||
using System.Globalization; |
||||
using System.Resources; |
||||
using System.Windows.Forms; |
||||
using ICSharpCode.PythonBinding; |
||||
using NUnit.Framework; |
||||
using PythonBinding.Tests.Utils; |
||||
|
||||
namespace PythonBinding.Tests.Designer |
||||
{ |
||||
/// <summary>
|
||||
/// Tests the GetResourceReader method of the PythonDesignerLoader.
|
||||
/// </summary>
|
||||
[TestFixture] |
||||
public class GetResourcesFromDesignerLoaderTestFixture |
||||
{ |
||||
PythonDesignerLoader loader; |
||||
MockDesignerLoaderHost host; |
||||
MockResourceReader reader; |
||||
MockResourceService resourceService; |
||||
MockResourceReader dummyReader; |
||||
MockResourceWriter dummyWriter; |
||||
MockResourceWriter writer; |
||||
|
||||
[SetUp] |
||||
public void Init() |
||||
{ |
||||
dummyReader = new MockResourceReader(); |
||||
dummyWriter = new MockResourceWriter(); |
||||
resourceService = new MockResourceService(); |
||||
resourceService.SetResourceReader(dummyReader); |
||||
resourceService.SetResourceWriter(dummyWriter); |
||||
host = new MockDesignerLoaderHost(); |
||||
host.AddService(typeof(IResourceService), resourceService); |
||||
loader = new PythonDesignerLoader(new MockDesignerGenerator()); |
||||
loader.BeginLoad(host); |
||||
|
||||
reader = loader.GetResourceReader(CultureInfo.InvariantCulture) as MockResourceReader; |
||||
writer = loader.GetResourceWriter(CultureInfo.InvariantCulture) as MockResourceWriter; |
||||
} |
||||
|
||||
[Test] |
||||
public void ResourceReaderInstance() |
||||
{ |
||||
Assert.IsTrue(Object.ReferenceEquals(dummyReader, reader)); |
||||
} |
||||
|
||||
[Test] |
||||
public void CultureInfoPassedToResourceServiceForReader() |
||||
{ |
||||
Assert.AreEqual(CultureInfo.InvariantCulture, resourceService.ResourceReaderCultureInfo); |
||||
} |
||||
|
||||
[Test] |
||||
public void GetReaderWhenNoResourceService() |
||||
{ |
||||
PythonDesignerLoader loader = new PythonDesignerLoader(new MockDesignerGenerator()); |
||||
loader.BeginLoad(new MockDesignerLoaderHost()); |
||||
Assert.IsNull(loader.GetResourceReader(CultureInfo.InvariantCulture)); |
||||
} |
||||
|
||||
[Test] |
||||
public void GetWriterWhenNoResourceService() |
||||
{ |
||||
PythonDesignerLoader loader = new PythonDesignerLoader(new MockDesignerGenerator()); |
||||
loader.BeginLoad(new MockDesignerLoaderHost()); |
||||
Assert.IsNull(loader.GetResourceWriter(CultureInfo.InvariantCulture)); |
||||
} |
||||
|
||||
[Test] |
||||
public void ResourceWriterInstance() |
||||
{ |
||||
Assert.IsTrue(Object.ReferenceEquals(dummyWriter, writer)); |
||||
} |
||||
|
||||
[Test] |
||||
public void CultureInfoPassedToResourceServiceForWriter() |
||||
{ |
||||
Assert.AreEqual(CultureInfo.InvariantCulture, resourceService.ResourceWriterCultureInfo); |
||||
} |
||||
} |
||||
} |
||||
@ -0,0 +1,75 @@
@@ -0,0 +1,75 @@
|
||||
// <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.ComponentModel.Design; |
||||
using System.Drawing; |
||||
using System.Globalization; |
||||
using System.IO; |
||||
using System.Windows.Forms; |
||||
|
||||
using ICSharpCode.PythonBinding; |
||||
using NUnit.Framework; |
||||
using PythonBinding.Tests.Utils; |
||||
|
||||
namespace PythonBinding.Tests.Designer |
||||
{ |
||||
[TestFixture] |
||||
public class LoadLocalImageResourceTestFixture : LoadFormTestFixtureBase |
||||
{ |
||||
MockResourceReader reader; |
||||
|
||||
public override string PythonCode { |
||||
get { |
||||
reader = new MockResourceReader(); |
||||
ComponentCreator.SetResourceReader(reader); |
||||
return "class TestForm(System.Windows.Forms.Form):\r\n" + |
||||
" def InitializeComponent(self):\r\n" + |
||||
// " resources = System.ComponentModel.ComponentResourceManager(clr.GetClrType(TestForm))\r\n" +
|
||||
// " self._pictureBox1 = System.Windows.Forms.PictureBox()\r\n" +
|
||||
// " self.SuspendLayout()\r\n" +
|
||||
// " # \r\n" +
|
||||
// " # pictureBox1\r\n" +
|
||||
// " # \r\n" +
|
||||
// " self._pictureBox1.Location = System.Drawing.Point(0, 0)\r\n" +
|
||||
// " self._pictureBox1.Name = \"button1\"\r\n" +
|
||||
// " self._pictureBox1.Size = System.Drawing.Size(10, 10)\r\n" +
|
||||
// " self._button1.TabIndex = 0\r\n" +
|
||||
// " self._button1.Text = \"button1\"\r\n" +
|
||||
// " # \r\n" +
|
||||
// " # MainForm\r\n" +
|
||||
// " # \r\n" +
|
||||
// " self.AcceptButton = self._button1\r\n" +
|
||||
// " self.ClientSize = System.Drawing.Size(200, 300)\r\n" +
|
||||
" self.Name = \"MainForm\"\r\n" + |
||||
// " self.Controls.Add(self._pictureBox1)\r\n" +
|
||||
// " self.ResumeLayout(False)\r\n";
|
||||
""; |
||||
} |
||||
} |
||||
|
||||
[Test] |
||||
public void ResourceReaderRetrievedFromComponentCreator() |
||||
{ |
||||
Assert.IsTrue(ComponentCreator.GetResourceReaderCalled); |
||||
} |
||||
|
||||
[Test] |
||||
public void CultureInfoInvariantCulturePassedToGetResourceReader() |
||||
{ |
||||
Assert.AreEqual(CultureInfo.InvariantCulture, ComponentCreator.CultureInfoPassedToGetResourceReader); |
||||
} |
||||
|
||||
[Test] |
||||
public void ResourceReaderIsDisposed() |
||||
{ |
||||
Assert.IsTrue(reader.IsDisposed); |
||||
} |
||||
} |
||||
} |
||||
@ -0,0 +1,46 @@
@@ -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.Collections; |
||||
using System.Resources; |
||||
|
||||
namespace PythonBinding.Tests.Utils |
||||
{ |
||||
public class MockResourceReader : IResourceReader |
||||
{ |
||||
bool disposed; |
||||
|
||||
public MockResourceReader() |
||||
{ |
||||
} |
||||
|
||||
public void Close() |
||||
{ |
||||
throw new NotImplementedException(); |
||||
} |
||||
|
||||
public IDictionaryEnumerator GetEnumerator() |
||||
{ |
||||
throw new NotImplementedException(); |
||||
} |
||||
|
||||
IEnumerator IEnumerable.GetEnumerator() |
||||
{ |
||||
return null; |
||||
} |
||||
|
||||
public void Dispose() |
||||
{ |
||||
disposed = true; |
||||
} |
||||
|
||||
public bool IsDisposed { |
||||
get { return disposed; } |
||||
} |
||||
} |
||||
} |
||||
@ -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.ComponentModel.Design; |
||||
using System.Globalization; |
||||
using System.Resources; |
||||
|
||||
namespace PythonBinding.Tests.Utils |
||||
{ |
||||
public class MockResourceService : IResourceService |
||||
{ |
||||
IResourceReader reader; |
||||
IResourceWriter writer; |
||||
CultureInfo readerCultureInfo; |
||||
CultureInfo writerCultureInfo; |
||||
|
||||
public MockResourceService() |
||||
{ |
||||
reader = new MockResourceReader(); |
||||
} |
||||
|
||||
public void SetResourceReader(IResourceReader reader) |
||||
{ |
||||
this.reader = reader; |
||||
} |
||||
|
||||
public void SetResourceWriter(IResourceWriter writer) |
||||
{ |
||||
this.writer = writer; |
||||
} |
||||
|
||||
public IResourceReader GetResourceReader(CultureInfo info) |
||||
{ |
||||
readerCultureInfo = info; |
||||
return reader; |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Gets the culture passed to GetResourceReader.
|
||||
/// </summary>
|
||||
public CultureInfo ResourceReaderCultureInfo { |
||||
get { return readerCultureInfo; } |
||||
} |
||||
|
||||
public IResourceWriter GetResourceWriter(CultureInfo info) |
||||
{ |
||||
writerCultureInfo = info; |
||||
return writer; |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Gets the culture passed to GetResourceWriter.
|
||||
/// </summary>
|
||||
public CultureInfo ResourceWriterCultureInfo { |
||||
get { return writerCultureInfo; } |
||||
} |
||||
} |
||||
} |
||||
@ -0,0 +1,55 @@
@@ -0,0 +1,55 @@
|
||||
// <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.Resources; |
||||
|
||||
namespace PythonBinding.Tests.Utils |
||||
{ |
||||
public class MockResourceWriter : IResourceWriter |
||||
{ |
||||
bool disposed; |
||||
|
||||
public MockResourceWriter() |
||||
{ |
||||
} |
||||
|
||||
public void AddResource(string name, string value) |
||||
{ |
||||
throw new NotImplementedException(); |
||||
} |
||||
|
||||
public void AddResource(string name, object value) |
||||
{ |
||||
throw new NotImplementedException(); |
||||
} |
||||
|
||||
public void AddResource(string name, byte[] value) |
||||
{ |
||||
throw new NotImplementedException(); |
||||
} |
||||
|
||||
public void Close() |
||||
{ |
||||
throw new NotImplementedException(); |
||||
} |
||||
|
||||
public void Generate() |
||||
{ |
||||
throw new NotImplementedException(); |
||||
} |
||||
|
||||
public void Dispose() |
||||
{ |
||||
disposed = true; |
||||
} |
||||
|
||||
public bool IsDisposed { |
||||
get { return disposed; } |
||||
} |
||||
} |
||||
} |
||||
Loading…
Reference in new issue