From 1213f5d091b73d5dfc2c53f715f2280d5ff0c291 Mon Sep 17 00:00:00 2001 From: tom-englert Date: Thu, 16 Jun 2022 17:53:59 +0200 Subject: [PATCH 1/2] Add failing test to reproduce #859 --- Test/Mono.Cecil.Tests/ImageWriteTests.cs | 44 ++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 Test/Mono.Cecil.Tests/ImageWriteTests.cs diff --git a/Test/Mono.Cecil.Tests/ImageWriteTests.cs b/Test/Mono.Cecil.Tests/ImageWriteTests.cs new file mode 100644 index 000000000..a73da2e14 --- /dev/null +++ b/Test/Mono.Cecil.Tests/ImageWriteTests.cs @@ -0,0 +1,44 @@ +using System.IO; +using System.Linq; +using NUnit.Framework; + +namespace Mono.Cecil.Tests { + [TestFixture] + public class ImageWriteTests : BaseTestFixture { + + [TestCase("EmbeddedPdbTarget.exe")] + // [TestCase("ExternalPdbDeterministic.dll")] + public void MultipleWriteOperationsShouldReturnSameOutput (string testee) + { + TestModule (testee, module => { + Assert.IsTrue (module.HasDebugHeader); + + const int numberOfStreams = 5; + + MemoryStream Write(int _) + { + var stream = new MemoryStream (); + module.Write (stream, new WriterParameters { WriteSymbols = true }); + return stream; + } + + var streams = Enumerable.Range (0, numberOfStreams) + .Select (Write) + .ToArray (); + + static bool AreStreamsEqual ((MemoryStream First, MemoryStream Second) pair) + { + var buffer1 = pair.First.GetBuffer (); + var buffer2 = pair.Second.GetBuffer (); + return buffer1.SequenceEqual (buffer2); + } + + var results = streams.Zip (streams.Skip (1)) + .Select (AreStreamsEqual) + .ToArray (); + + Assert.That (results, Is.EquivalentTo (results.Select (_ => true))); + }); + } + } +} \ No newline at end of file From 5ffe42f337c6038850518c0ca7ecb9120f387df4 Mon Sep 17 00:00:00 2001 From: tom-englert Date: Thu, 16 Jun 2022 18:03:37 +0200 Subject: [PATCH 2/2] Omit test that does not run in Net40 --- Test/Mono.Cecil.Tests/ImageWriteTests.cs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/Test/Mono.Cecil.Tests/ImageWriteTests.cs b/Test/Mono.Cecil.Tests/ImageWriteTests.cs index a73da2e14..2a797a882 100644 --- a/Test/Mono.Cecil.Tests/ImageWriteTests.cs +++ b/Test/Mono.Cecil.Tests/ImageWriteTests.cs @@ -2,6 +2,8 @@ using System.Linq; using NUnit.Framework; +#if NETCOREAPP + namespace Mono.Cecil.Tests { [TestFixture] public class ImageWriteTests : BaseTestFixture { @@ -41,4 +43,6 @@ static bool AreStreamsEqual ((MemoryStream First, MemoryStream Second) pair) }); } } -} \ No newline at end of file +} + +#endif \ No newline at end of file