From 41a0fdebbca863411855b1aa973e550f88ddd8cd Mon Sep 17 00:00:00 2001 From: Matt Ward Date: Wed, 13 May 2009 18:25:58 +0000 Subject: [PATCH] Fixed ArgumentException thrown when duplicate binary file ids are in a WiX file and the dialog is opened in the designer. git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/branches/3.0@4073 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61 --- .../WixBinding/Project/Src/WixBinaries.cs | 4 +- .../Document/DuplicateBinaryIdTestFixture.cs | 92 +++++++++++++++++++ .../WixBinding/Test/WixBinding.Tests.csproj | 1 + 3 files changed, 96 insertions(+), 1 deletion(-) create mode 100644 src/AddIns/BackendBindings/WixBinding/Test/Document/DuplicateBinaryIdTestFixture.cs diff --git a/src/AddIns/BackendBindings/WixBinding/Project/Src/WixBinaries.cs b/src/AddIns/BackendBindings/WixBinding/Project/Src/WixBinaries.cs index 485d78dbb3..9d44bc4acb 100644 --- a/src/AddIns/BackendBindings/WixBinding/Project/Src/WixBinaries.cs +++ b/src/AddIns/BackendBindings/WixBinding/Project/Src/WixBinaries.cs @@ -99,7 +99,9 @@ namespace ICSharpCode.WixBinding document.Load(textFileReader.Create(fileName)); document.FileName = fileName; foreach (WixBinaryElement element in document.GetBinaries()) { - binaries.Add(element.Id, element.FileName); + if (!binaries.ContainsKey(element.Id)) { + binaries.Add(element.Id, element.FileName); + } } } catch (FileNotFoundException) { } catch (XmlException) { diff --git a/src/AddIns/BackendBindings/WixBinding/Test/Document/DuplicateBinaryIdTestFixture.cs b/src/AddIns/BackendBindings/WixBinding/Test/Document/DuplicateBinaryIdTestFixture.cs new file mode 100644 index 0000000000..5a718d116c --- /dev/null +++ b/src/AddIns/BackendBindings/WixBinding/Test/Document/DuplicateBinaryIdTestFixture.cs @@ -0,0 +1,92 @@ +// +// +// +// +// $Revision$ +// + +using ICSharpCode.WixBinding; +using ICSharpCode.SharpDevelop.Project; +using NUnit.Framework; +using System; +using System.Drawing; +using System.Collections.Generic; +using System.IO; +using WixBinding.Tests.Utils; + +namespace WixBinding.Tests.Document +{ + /// + /// Tests that WixBinaries class does not try to add the same binary id to the hash table. + /// + [TestFixture] + public class DuplicateBinaryIdTestFixture : ITextFileReader + { + WixBinaries binaries; + string projectDirectory; + + [TestFixtureSetUp] + public void SetUpFixture() + { + WixProject p = WixBindingTestsHelper.CreateEmptyWixProject(); + projectDirectory = p.Directory; + p.Name = "MySetup"; + + FileProjectItem item = new FileProjectItem(p, ItemType.Compile); + item.Include = "Setup.wxs"; + string docFileName = item.FileName; + ProjectService.AddProjectItem(p, item); + + item = new FileProjectItem(p, ItemType.Compile); + item.Include = "Binaries.wxs"; + ProjectService.AddProjectItem(p, item); + + WixDocument doc = new WixDocument(p); + doc.FileName = docFileName; + doc.LoadXml(GetMainWixXml()); + + binaries = new WixBinaries(doc, this); + } + + + [Test] + public void GetDialogBitmapFileName() + { + string expectedFileName = Path.Combine(projectDirectory, "Bitmaps/Dialog.bmp"); + Assert.AreEqual(expectedFileName, binaries.GetBinaryFileName("Dialog")); + } + + + public TextReader Create(string fileName) + { + fileName = Path.GetFileName(fileName); + if (fileName == "Binaries.wxs") { + return new StringReader(GetWixFragmentXml()); + } + return new StringReader(GetMainWixXml()); + } + + string GetMainWixXml() + { + return "\r\n" + + "\t\r\n" + + "\t\t\r\n" + + "\t\r\n" + + ""; + } + + string GetWixFragmentXml() + { + return "\r\n" + + "\t\r\n" + + "\t\t\r\n" + + "\t\t\r\n" + + "\t\r\n" + + ""; + } + } +} diff --git a/src/AddIns/BackendBindings/WixBinding/Test/WixBinding.Tests.csproj b/src/AddIns/BackendBindings/WixBinding/Test/WixBinding.Tests.csproj index 6b8e1ffac1..34f9722c90 100644 --- a/src/AddIns/BackendBindings/WixBinding/Test/WixBinding.Tests.csproj +++ b/src/AddIns/BackendBindings/WixBinding/Test/WixBinding.Tests.csproj @@ -50,6 +50,7 @@ +