Browse Source

Empty form resource file (.resx) now being created and added to project when the python forms designer is used.

git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/branches/3.0@4338 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61
shortcuts
Matt Ward 17 years ago
parent
commit
941673ddd2
  1. 5
      src/AddIns/BackendBindings/Python/PythonBinding/Project/Src/IComponentCreator.cs
  2. 8
      src/AddIns/BackendBindings/Python/PythonBinding/Project/Src/PythonComponentWalker.cs
  3. 26
      src/AddIns/BackendBindings/Python/PythonBinding/Project/Src/PythonControl.cs
  4. 16
      src/AddIns/BackendBindings/Python/PythonBinding/Project/Src/PythonDesignerComponent.cs
  5. 13
      src/AddIns/BackendBindings/Python/PythonBinding/Project/Src/PythonDesignerGenerator.cs
  6. 28
      src/AddIns/BackendBindings/Python/PythonBinding/Project/Src/PythonDesignerLoader.cs
  7. 41
      src/AddIns/BackendBindings/Python/PythonBinding/Project/Src/PythonDesignerRootComponent.cs
  8. 136
      src/AddIns/BackendBindings/Python/PythonBinding/Test/Designer/GenerateLocalImageResourceTestFixture.cs
  9. 2
      src/AddIns/BackendBindings/Python/PythonBinding/Test/Designer/GeneratorMergeFindsInitializeComponentsTestFixture.cs
  10. 92
      src/AddIns/BackendBindings/Python/PythonBinding/Test/Designer/GetResourcesFromDesignerLoaderTestFixture.cs
  11. 75
      src/AddIns/BackendBindings/Python/PythonBinding/Test/Designer/LoadLocalImageResourceTestFixture.cs
  12. 14
      src/AddIns/BackendBindings/Python/PythonBinding/Test/Designer/MergeFormTestFixture.cs
  13. 12
      src/AddIns/BackendBindings/Python/PythonBinding/Test/Designer/MissingInitializeComponentMethodTestFixture.cs
  14. 2
      src/AddIns/BackendBindings/Python/PythonBinding/Test/Designer/NoNewLineAfterInitializeComponentTestFixture.cs
  15. 10
      src/AddIns/BackendBindings/Python/PythonBinding/Test/Designer/PythonDesignerLoaderTestFixture.cs
  16. 2
      src/AddIns/BackendBindings/Python/PythonBinding/Test/Designer/TextEditorIndentPassedToGeneratorTestFixture.cs
  17. 6
      src/AddIns/BackendBindings/Python/PythonBinding/Test/PythonBinding.Tests.csproj
  18. 48
      src/AddIns/BackendBindings/Python/PythonBinding/Test/Utils/MockComponentCreator.cs
  19. 13
      src/AddIns/BackendBindings/Python/PythonBinding/Test/Utils/MockDesignerGenerator.cs
  20. 46
      src/AddIns/BackendBindings/Python/PythonBinding/Test/Utils/MockResourceReader.cs
  21. 63
      src/AddIns/BackendBindings/Python/PythonBinding/Test/Utils/MockResourceService.cs
  22. 55
      src/AddIns/BackendBindings/Python/PythonBinding/Test/Utils/MockResourceWriter.cs

5
src/AddIns/BackendBindings/Python/PythonBinding/Project/Src/IComponentCreator.cs

@ -8,6 +8,9 @@ @@ -8,6 +8,9 @@
using System;
using System.Collections;
using System.ComponentModel;
using System.ComponentModel.Design;
using System.Globalization;
using System.Resources;
namespace ICSharpCode.PythonBinding
{
@ -20,7 +23,7 @@ namespace ICSharpCode.PythonBinding @@ -20,7 +23,7 @@ namespace ICSharpCode.PythonBinding
/// Used by the PythonFormVisitor class so it can be wired up to an
/// IDesignerHost and an IDesignerSerializationManager.
/// </summary>
public interface IComponentCreator
public interface IComponentCreator : IResourceService
{
/// <summary>
/// Creates a named component of the specified type.

8
src/AddIns/BackendBindings/Python/PythonBinding/Project/Src/PythonComponentWalker.cs

@ -10,7 +10,9 @@ using System.Collections.Generic; @@ -10,7 +10,9 @@ using System.Collections.Generic;
using System.ComponentModel;
using System.ComponentModel.Design;
using System.Drawing;
using System.Globalization;
using System.Reflection;
using System.Resources;
using System.Text;
using System.Windows.Forms;
@ -41,7 +43,7 @@ namespace ICSharpCode.PythonBinding @@ -41,7 +43,7 @@ namespace ICSharpCode.PythonBinding
/// Creates a control either a UserControl or Form from the python code.
/// </summary>
public IComponent CreateComponent(string pythonCode)
{
{
PythonParser parser = new PythonParser();
PythonAst ast = parser.CreateAst(@"Control.py", pythonCode);
ast.Walk(this);
@ -85,6 +87,10 @@ namespace ICSharpCode.PythonBinding @@ -85,6 +87,10 @@ namespace ICSharpCode.PythonBinding
if (IsInitializeComponentMethod(node)) {
Type type = GetComponentType();
component = componentCreator.CreateComponent(type, componentName);
IResourceReader reader = componentCreator.GetResourceReader(CultureInfo.InvariantCulture);
if (reader != null) {
reader.Dispose();
}
node.Body.Walk(this);
}
return false;

26
src/AddIns/BackendBindings/Python/PythonBinding/Project/Src/PythonControl.cs

@ -11,7 +11,9 @@ using System.Collections; @@ -11,7 +11,9 @@ using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.ComponentModel.Design;
using System.Globalization;
using System.Reflection;
using System.Resources;
using System.Text;
using System.Windows.Forms;
using ICSharpCode.PythonBinding;
@ -27,6 +29,7 @@ namespace ICSharpCode.PythonBinding @@ -27,6 +29,7 @@ namespace ICSharpCode.PythonBinding
{
PythonCodeBuilder codeBuilder;
string indentString = String.Empty;
IResourceService resourceService;
public PythonControl()
: this("\t")
@ -34,9 +37,16 @@ namespace ICSharpCode.PythonBinding @@ -34,9 +37,16 @@ namespace ICSharpCode.PythonBinding
}
public PythonControl(string indentString)
: this(indentString, null)
{
this.indentString = indentString;
}
public PythonControl(string indentString, IResourceService resourceService)
{
this.indentString = indentString;
this.resourceService = resourceService;
}
/// <summary>
/// Generates python code for the InitializeComponent method based on the controls added to the form.
@ -53,6 +63,7 @@ namespace ICSharpCode.PythonBinding @@ -53,6 +63,7 @@ namespace ICSharpCode.PythonBinding
codeBuilder.IncreaseIndent();
GenerateInitializeComponentMethodBodyInternal(control);
GenerateResources();
methodCodeBuilder.Append(codeBuilder.ToString());
return methodCodeBuilder.ToString();
@ -70,6 +81,7 @@ namespace ICSharpCode.PythonBinding @@ -70,6 +81,7 @@ namespace ICSharpCode.PythonBinding
codeBuilder.IncreaseIndent();
}
GenerateInitializeComponentMethodBodyInternal(control);
GenerateResources();
return codeBuilder.ToString();
}
@ -78,13 +90,23 @@ namespace ICSharpCode.PythonBinding @@ -78,13 +90,23 @@ namespace ICSharpCode.PythonBinding
{
PythonDesignerRootComponent rootDesignerComponent = PythonDesignerComponentFactory.CreateDesignerRootComponent(control);
rootDesignerComponent.AppendCreateContainerComponents(codeBuilder);
rootDesignerComponent.AppendNonVisualComponentsBeginInit(codeBuilder);
rootDesignerComponent.AppendSupportInitializeComponentsBeginInit(codeBuilder);
rootDesignerComponent.AppendChildComponentsSuspendLayout(codeBuilder);
rootDesignerComponent.AppendSuspendLayout(codeBuilder);
rootDesignerComponent.AppendComponent(codeBuilder);
rootDesignerComponent.AppendChildComponentsResumeLayout(codeBuilder);
rootDesignerComponent.AppendNonVisualComponentsEndInit(codeBuilder);
rootDesignerComponent.AppendSupportInitializeComponentsEndInit(codeBuilder);
rootDesignerComponent.AppendResumeLayout(codeBuilder);
}
void GenerateResources()
{
if (resourceService == null) {
return;
}
using (IResourceWriter writer = resourceService.GetResourceWriter(CultureInfo.InvariantCulture)) {
}
}
}
}

16
src/AddIns/BackendBindings/Python/PythonBinding/Project/Src/PythonDesignerComponent.cs

@ -141,22 +141,6 @@ namespace ICSharpCode.PythonBinding @@ -141,22 +141,6 @@ namespace ICSharpCode.PythonBinding
}
return false;
}
/// <summary>
/// A component is non-visual if it is not a control and is not hidden from the designer.
/// </summary>
public static bool IsNonVisualComponent(IComponent component)
{
Control control = component as Control;
return (control == null) && !IsHiddenFromDesigner(component);
}
/// <summary>
/// Returns true if this component is non-visual.
/// </summary>
public bool IsNonVisual {
get { return IsNonVisualComponent(component); }
}
/// <summary>
/// Gets the AddRange method on the object that is not hidden from the designer.

13
src/AddIns/BackendBindings/Python/PythonBinding/Project/Src/PythonDesignerGenerator.cs

@ -11,6 +11,7 @@ using System.CodeDom.Compiler; @@ -11,6 +11,7 @@ using System.CodeDom.Compiler;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.ComponentModel.Design;
using System.Drawing;
using System.Reflection;
using System.Text;
@ -32,7 +33,7 @@ namespace ICSharpCode.PythonBinding @@ -32,7 +33,7 @@ namespace ICSharpCode.PythonBinding
/// Updates the python form or user control's InitializeComponent method with any
/// changes to the designed form or user control.
/// </summary>
void MergeRootComponentChanges(IComponent component);
void MergeRootComponentChanges(IComponent component, IResourceService resourceService);
}
/// <summary>
@ -78,10 +79,10 @@ namespace ICSharpCode.PythonBinding @@ -78,10 +79,10 @@ namespace ICSharpCode.PythonBinding
/// <summary>
/// Updates the InitializeComponent method's body with the generated code.
/// </summary>
public void MergeRootComponentChanges(IComponent component)
public void MergeRootComponentChanges(IComponent component, IResourceService resourceService)
{
ParseInformation parseInfo = ParseFile();
Merge(component, ViewContent.DesignerCodeFileDocument, parseInfo.BestCompilationUnit, textEditorProperties);
Merge(component, ViewContent.DesignerCodeFileDocument, parseInfo.BestCompilationUnit, textEditorProperties, resourceService);
}
/// <summary>
@ -90,15 +91,15 @@ namespace ICSharpCode.PythonBinding @@ -90,15 +91,15 @@ namespace ICSharpCode.PythonBinding
/// <param name="component">The root component in the designer host.</param>
/// <param name="document">The document that the generated code will be merged into.</param>
/// <param name="parseInfo">The current compilation unit for the <paramref name="document"/>.</param>
public static void Merge(IComponent component, IDocument document, ICompilationUnit compilationUnit, ITextEditorProperties textEditorProperties)
public static void Merge(IComponent component, IDocument document, ICompilationUnit compilationUnit, ITextEditorProperties textEditorProperties, IResourceService resourceService)
{
// Get the document's initialize components method.
IMethod method = GetInitializeComponents(compilationUnit);
// Generate the python source code.
PythonControl pythonForm = new PythonControl(NRefactoryToPythonConverter.GetIndentString(textEditorProperties));
PythonControl pythonControl = new PythonControl(NRefactoryToPythonConverter.GetIndentString(textEditorProperties), resourceService);
int indent = method.Region.BeginColumn;
string methodBody = pythonForm.GenerateInitializeComponentMethodBody(component as Control, indent);
string methodBody = pythonControl.GenerateInitializeComponentMethodBody(component as Control, indent);
// Merge the code.
DomRegion methodRegion = GetBodyRegionInDocument(method);

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

@ -12,6 +12,8 @@ using System.Collections.Generic; @@ -12,6 +12,8 @@ using System.Collections.Generic;
using System.ComponentModel;
using System.ComponentModel.Design;
using System.ComponentModel.Design.Serialization;
using System.Globalization;
using System.Resources;
using System.Security.Permissions;
using ICSharpCode.FormsDesigner;
@ -116,6 +118,30 @@ namespace ICSharpCode.PythonBinding @@ -116,6 +118,30 @@ namespace ICSharpCode.PythonBinding
IEventBindingService eventBindingService = GetService(typeof(IEventBindingService)) as IEventBindingService;
return eventBindingService.GetEventProperty(e);
}
/// <summary>
/// Gets the resource reader for the specified culture.
/// </summary>
public IResourceReader GetResourceReader(CultureInfo info)
{
IResourceService resourceService = (IResourceService)LoaderHost.GetService(typeof(IResourceService));
if (resourceService != null) {
return resourceService.GetResourceReader(info);
}
return null;
}
/// <summary>
/// Gets the resource writer for the specified culture.
/// </summary>
public IResourceWriter GetResourceWriter(CultureInfo info)
{
IResourceService resourceService = (IResourceService)LoaderHost.GetService(typeof(IResourceService));
if (resourceService != null) {
return resourceService.GetResourceWriter(info);
}
return null;
}
/// <summary>
/// Passes the designer host's root component to the generator so it can update the
@ -123,7 +149,7 @@ namespace ICSharpCode.PythonBinding @@ -123,7 +149,7 @@ namespace ICSharpCode.PythonBinding
/// </summary>
protected override void PerformFlush(IDesignerSerializationManager serializationManager)
{
generator.MergeRootComponentChanges(base.LoaderHost.RootComponent);
generator.MergeRootComponentChanges(LoaderHost.RootComponent, LoaderHost.GetService(typeof(IResourceService)) as IResourceService);
}
protected override void PerformLoad(IDesignerSerializationManager serializationManager)

41
src/AddIns/BackendBindings/Python/PythonBinding/Project/Src/PythonDesignerRootComponent.cs

@ -48,46 +48,35 @@ namespace ICSharpCode.PythonBinding @@ -48,46 +48,35 @@ namespace ICSharpCode.PythonBinding
// Add root component
AppendComponentProperties(codeBuilder, false, true);
}
public PythonDesignerComponent[] GetNonVisualChildComponents()
{
List<PythonDesignerComponent> components = new List<PythonDesignerComponent>();
foreach (IComponent containerComponent in Component.Site.Container.Components) {
PythonDesignerComponent designerComponent = PythonDesignerComponentFactory.CreateDesignerComponent(this, containerComponent);
if (designerComponent.IsNonVisual) {
components.Add(designerComponent);
}
}
return components.ToArray();
}
/// <summary>
/// Adds BeginInit method call for any non-visual components that implement the
/// Adds BeginInit method call for any components that implement the
/// System.ComponentModel.ISupportInitialize interface.
/// </summary>
public void AppendNonVisualComponentsBeginInit(PythonCodeBuilder codeBuilder)
public void AppendSupportInitializeComponentsBeginInit(PythonCodeBuilder codeBuilder)
{
AppendNonVisualComponentsMethodCalls(codeBuilder, new string[] {"BeginInit()"});
AppendSupportInitializeMethodCalls(codeBuilder, new string[] {"BeginInit()"});
}
/// <summary>
/// Adds EndInit method call for any non-visual components that implement the
/// Adds EndInit method call for any that implement the
/// System.ComponentModel.ISupportInitialize interface.
/// </summary>
public void AppendNonVisualComponentsEndInit(PythonCodeBuilder codeBuilder)
public void AppendSupportInitializeComponentsEndInit(PythonCodeBuilder codeBuilder)
{
AppendNonVisualComponentsMethodCalls(codeBuilder, new string[] {"EndInit()"});
}
AppendSupportInitializeMethodCalls(codeBuilder, new string[] {"EndInit()"});
}
public void AppendNonVisualComponentsMethodCalls(PythonCodeBuilder codeBuilder, string[] methods)
public void AppendSupportInitializeMethodCalls(PythonCodeBuilder codeBuilder, string[] methods)
{
foreach (PythonDesignerComponent component in GetNonVisualChildComponents()) {
if (typeof(ISupportInitialize).IsAssignableFrom(component.GetComponentType())) {
foreach (IComponent containerComponent in Component.Site.Container.Components) {
if (typeof(ISupportInitialize).IsAssignableFrom(containerComponent.GetType())) {
PythonDesignerComponent component = PythonDesignerComponentFactory.CreateDesignerComponent(this, containerComponent);
component.AppendMethodCalls(codeBuilder, methods);
}
}
}
}
}
/// <summary>
/// Reverses the ordering when adding items to the Controls collection.
/// </summary>

136
src/AddIns/BackendBindings/Python/PythonBinding/Test/Designer/GenerateLocalImageResourceTestFixture.cs

@ -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);
}
}
}

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

@ -60,7 +60,7 @@ namespace PythonBinding.Tests.Designer @@ -60,7 +60,7 @@ namespace PythonBinding.Tests.Designer
PropertyDescriptor namePropertyDescriptor = descriptors.Find("Name", false);
namePropertyDescriptor.SetValue(form, "MainForm");
generator.MergeRootComponentChanges(form);
generator.MergeRootComponentChanges(form, new MockResourceService());
generator.Detach();
}
}

92
src/AddIns/BackendBindings/Python/PythonBinding/Test/Designer/GetResourcesFromDesignerLoaderTestFixture.cs

@ -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);
}
}
}

75
src/AddIns/BackendBindings/Python/PythonBinding/Test/Designer/LoadLocalImageResourceTestFixture.cs

@ -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);
}
}
}

14
src/AddIns/BackendBindings/Python/PythonBinding/Test/Designer/MergeFormTestFixture.cs

@ -30,10 +30,16 @@ namespace PythonBinding.Tests.Designer @@ -30,10 +30,16 @@ namespace PythonBinding.Tests.Designer
public class MergeFormTestFixture
{
IDocument document;
MockResourceService resourceService;
MockResourceWriter resourceWriter;
[TestFixtureSetUp]
public void SetUpFixture()
{
resourceWriter = new MockResourceWriter();
resourceService = new MockResourceService();
resourceService.SetResourceWriter(resourceWriter);
using (TextEditorControl textEditor = new TextEditorControl()) {
document = textEditor.Document;
textEditor.Text = GetTextEditorCode();
@ -50,7 +56,7 @@ namespace PythonBinding.Tests.Designer @@ -50,7 +56,7 @@ namespace PythonBinding.Tests.Designer
PropertyDescriptor namePropertyDescriptor = descriptors.Find("Name", false);
namePropertyDescriptor.SetValue(form, "MainForm");
PythonDesignerGenerator.Merge(form, document, compilationUnit, new MockTextEditorProperties());
PythonDesignerGenerator.Merge(form, document, compilationUnit, new MockTextEditorProperties(), resourceService);
}
}
}
@ -61,6 +67,12 @@ namespace PythonBinding.Tests.Designer @@ -61,6 +67,12 @@ namespace PythonBinding.Tests.Designer
string expectedText = GetTextEditorCode().Replace(GetTextEditorInitializeComponentMethod(), GetGeneratedInitializeComponentMethod());
Assert.AreEqual(expectedText, document.TextContent);
}
[Test]
public void ResourceWriterDisposed()
{
Assert.IsTrue(resourceWriter.IsDisposed);
}
string GetGeneratedCode()
{

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

@ -10,7 +10,9 @@ using System.Collections; @@ -10,7 +10,9 @@ using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Globalization;
using System.IO;
using System.Resources;
using System.Windows.Forms;
using ICSharpCode.PythonBinding;
@ -107,5 +109,15 @@ namespace PythonBinding.Tests.Designer @@ -107,5 +109,15 @@ namespace PythonBinding.Tests.Designer
{
return null;
}
public IResourceReader GetResourceReader(CultureInfo info)
{
return null;
}
public IResourceWriter GetResourceWriter(CultureInfo info)
{
return null;
}
}
}

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

@ -49,7 +49,7 @@ namespace PythonBinding.Tests.Designer @@ -49,7 +49,7 @@ namespace PythonBinding.Tests.Designer
PropertyDescriptor namePropertyDescriptor = descriptors.Find("Name", false);
namePropertyDescriptor.SetValue(userControl, "userControl1");
PythonDesignerGenerator.Merge(userControl, document, compilationUnit, new MockTextEditorProperties());
PythonDesignerGenerator.Merge(userControl, document, compilationUnit, new MockTextEditorProperties(), null);
}
}
}

10
src/AddIns/BackendBindings/Python/PythonBinding/Test/Designer/PythonDesignerLoaderTestFixture.cs

@ -39,6 +39,7 @@ namespace PythonBinding.Tests.Designer @@ -39,6 +39,7 @@ namespace PythonBinding.Tests.Designer
IComponent rootComponent;
Form designedForm;
MockEventBindingService mockEventBindingService;
MockResourceService mockResourceService;
[TestFixtureSetUp]
public void SetUpFixture()
@ -52,6 +53,9 @@ namespace PythonBinding.Tests.Designer @@ -52,6 +53,9 @@ namespace PythonBinding.Tests.Designer
// Begin load.
mockDesignerLoaderHost = new MockDesignerLoaderHost();
mockResourceService = new MockResourceService();
mockDesignerLoaderHost.AddService(typeof(IResourceService), mockResourceService);
mockTypeResolutionService = mockDesignerLoaderHost.TypeResolutionService;
mockExtenderProviderService = new MockExtenderProviderService();
@ -142,6 +146,12 @@ namespace PythonBinding.Tests.Designer @@ -142,6 +146,12 @@ namespace PythonBinding.Tests.Designer
{
Assert.AreEqual(designedForm, loader.RootComponent);
}
[Test]
public void ResourceServicePassedToMergeRootComponentMethod()
{
Assert.IsTrue(Object.ReferenceEquals(mockResourceService, generator.MergeChangesResourceService));
}
/// <summary>
/// The code that the designer loader will parse.

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

@ -65,7 +65,7 @@ namespace PythonBinding.Tests.Designer @@ -65,7 +65,7 @@ namespace PythonBinding.Tests.Designer
DerivedPythonDesignerGenerator generator = new DerivedPythonDesignerGenerator(textEditorProperties);
generator.ParseInfoToReturnFromParseFileMethod = parseInfo;
generator.Attach(viewContent);
generator.MergeRootComponentChanges(form);
generator.MergeRootComponentChanges(form, new MockResourceService());
}
}
}

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

@ -191,6 +191,7 @@ @@ -191,6 +191,7 @@
<Compile Include="Designer\GenerateImeModeFormTestFixture.cs" />
<Compile Include="Designer\GenerateListViewItemTestFixture.cs" />
<Compile Include="Designer\GenerateListViewSubItemsTestFixture.cs" />
<Compile Include="Designer\GenerateLocalImageResourceTestFixture.cs" />
<Compile Include="Designer\GenerateMenuStripFormTestFixture.cs" />
<Compile Include="Designer\GenerateMenuStripItemsTestFixture.cs" />
<Compile Include="Designer\GenerateMinSizeFormTestFixture.cs" />
@ -204,6 +205,7 @@ @@ -204,6 +205,7 @@
<Compile Include="Designer\GeneratorMergeFindsInitializeComponentsTestFixture.cs" />
<Compile Include="Designer\GetComponentFromDesignerLoaderTestFixture.cs" />
<Compile Include="Designer\GetInstanceFromDesignerLoaderTestFixture.cs" />
<Compile Include="Designer\GetResourcesFromDesignerLoaderTestFixture.cs" />
<Compile Include="Designer\GetSerializableContentPropertiesTestFixture.cs" />
<Compile Include="Designer\IgnoreDesignTimePropertiesTestFixture.cs" />
<Compile Include="Designer\InsertEventHandlerTestFixtureBase.cs" />
@ -223,6 +225,7 @@ @@ -223,6 +225,7 @@
<Compile Include="Designer\LoadFormWithBooleanPropertiesSetTestFixture.cs" />
<Compile Include="Designer\LoadFormWithSysPathAppendStatementTestFixture.cs" />
<Compile Include="Designer\LoadListViewFormTestFixture.cs" />
<Compile Include="Designer\LoadLocalImageResourceTestFixture.cs" />
<Compile Include="Designer\LoadMenuStripFormTestFixture.cs" />
<Compile Include="Designer\LoadSimpleFormTestFixture.cs" />
<Compile Include="Designer\LoadSimpleUserControlTestFixture.cs" />
@ -319,6 +322,9 @@ @@ -319,6 +322,9 @@
<Compile Include="Utils\MockProject.cs" />
<Compile Include="Utils\MockProjectContent.cs" />
<Compile Include="Utils\MockPropertyDescriptor.cs" />
<Compile Include="Utils\MockResourceReader.cs" />
<Compile Include="Utils\MockResourceService.cs" />
<Compile Include="Utils\MockResourceWriter.cs" />
<Compile Include="Utils\MockTextEditorProperties.cs" />
<Compile Include="Utils\MockTextEditorViewContent.cs" />
<Compile Include="Utils\MockTypeResolutionService.cs" />

48
src/AddIns/BackendBindings/Python/PythonBinding/Test/Utils/MockComponentCreator.cs

@ -10,8 +10,10 @@ using System.Collections; @@ -10,8 +10,10 @@ using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.ComponentModel.Design.Serialization;
using System.Globalization;
using System.Drawing;
using System.Reflection;
using System.Resources;
using System.Windows.Forms;
using ICSharpCode.PythonBinding;
@ -26,6 +28,12 @@ namespace PythonBinding.Tests.Utils @@ -26,6 +28,12 @@ namespace PythonBinding.Tests.Utils
PropertyDescriptor propertyDescriptor;
EventDescriptor eventDescriptor;
IComponent rootComponent;
bool getResourceReaderCalled;
CultureInfo cultureInfoPassedToGetResourceReader;
IResourceWriter resourceWriter;
bool getResourceWriterCalled;
CultureInfo cultureInfoPassedToGetResourceWriter;
IResourceReader resourceReader;
public MockComponentCreator()
{
@ -173,5 +181,45 @@ namespace PythonBinding.Tests.Utils @@ -173,5 +181,45 @@ namespace PythonBinding.Tests.Utils
}
return null;
}
public void SetResourceReader(IResourceReader reader)
{
resourceReader = reader;
}
public bool GetResourceReaderCalled {
get { return getResourceReaderCalled; }
}
public CultureInfo CultureInfoPassedToGetResourceReader {
get { return cultureInfoPassedToGetResourceReader; }
}
public IResourceReader GetResourceReader(CultureInfo info)
{
getResourceReaderCalled = true;
cultureInfoPassedToGetResourceReader = info;
return resourceReader;
}
public void SetResourceWriter(IResourceWriter writer)
{
resourceWriter = writer;
}
public IResourceWriter GetResourceWriter(CultureInfo info)
{
getResourceWriterCalled = true;
cultureInfoPassedToGetResourceWriter = info;
return resourceWriter;
}
public bool GetResourceWriterCalled {
get { return getResourceWriterCalled; }
}
public CultureInfo CultureInfoPassedToGetResourceWriter {
get { return cultureInfoPassedToGetResourceWriter; }
}
}
}

13
src/AddIns/BackendBindings/Python/PythonBinding/Test/Utils/MockDesignerGenerator.cs

@ -9,12 +9,15 @@ using System; @@ -9,12 +9,15 @@ using System;
using System.CodeDom;
using System.CodeDom.Compiler;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.ComponentModel.Design;
using System.Reflection;
using System.Windows.Forms;
using ICSharpCode.FormsDesigner;
using ICSharpCode.PythonBinding;
using ICSharpCode.SharpDevelop;
namespace PythonBinding.Tests.Utils
{
@ -25,6 +28,7 @@ namespace PythonBinding.Tests.Utils @@ -25,6 +28,7 @@ namespace PythonBinding.Tests.Utils
{
FormsDesignerViewContent viewContent;
IComponent mergeChangesRootComponent;
IResourceService mergeChangesResourceService;
public MockDesignerGenerator()
{
@ -48,7 +52,7 @@ namespace PythonBinding.Tests.Utils @@ -48,7 +52,7 @@ namespace PythonBinding.Tests.Utils
this.viewContent = null;
}
public System.Collections.Generic.IEnumerable<ICSharpCode.SharpDevelop.OpenedFile> GetSourceFiles(out ICSharpCode.SharpDevelop.OpenedFile designerCodeFile)
public IEnumerable<OpenedFile> GetSourceFiles(out OpenedFile designerCodeFile)
{
designerCodeFile = this.viewContent.DesignerCodeFile;
return new [] {designerCodeFile};
@ -58,15 +62,20 @@ namespace PythonBinding.Tests.Utils @@ -58,15 +62,20 @@ namespace PythonBinding.Tests.Utils
{
}
public void MergeRootComponentChanges(IComponent component)
public void MergeRootComponentChanges(IComponent component, IResourceService resourceService)
{
mergeChangesRootComponent = component;
mergeChangesResourceService = resourceService;
}
public IComponent MergeChangesRootComponent {
get { return mergeChangesRootComponent; }
}
public IResourceService MergeChangesResourceService {
get { return mergeChangesResourceService; }
}
public bool InsertComponentEvent(IComponent component, System.ComponentModel.EventDescriptor edesc, string eventMethodName, string body, out string file, out int position)
{
throw new NotImplementedException();

46
src/AddIns/BackendBindings/Python/PythonBinding/Test/Utils/MockResourceReader.cs

@ -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; }
}
}
}

63
src/AddIns/BackendBindings/Python/PythonBinding/Test/Utils/MockResourceService.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.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; }
}
}
}

55
src/AddIns/BackendBindings/Python/PythonBinding/Test/Utils/MockResourceWriter.cs

@ -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…
Cancel
Save