Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mono/debugger-libs.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJeffrey Stedfast <jestedfa@microsoft.com>2019-06-06 22:19:52 +0300
committerJeffrey Stedfast <jestedfa@microsoft.com>2019-06-06 22:51:05 +0300
commitad9b5345b3f15ea7334d7609da1ea854e5c56390 (patch)
treeef6db8a26adccc1132e23e5dfef2a0674696c8f2 /UnitTests
parent7bca91a582a8161b0765e9121abb61b2aa285412 (diff)
[Mono.Debugging] Improved source checksum logic for UNIX and DOS line endings
Since it is possible that the assemblies being debugged could have been compiled on a different system (potentially with different line endings), compute hashes for the source code in 3 formats: 1. The source code file with line endings as-is 2. The source code file with DOS line endings 3. The source code file with UNIX line endings Note: sometimes source code may have mixed line endings, so it is important to calculate the source code as-is and not just canonicalized UNIX and DOS line endings. Fixes https://devdiv.visualstudio.com/DevDiv/_workitems/edit/642329 Fixes issue #5260
Diffstat (limited to 'UnitTests')
-rw-r--r--UnitTests/Mono.Debugging.Tests/Shared/SourceLocationTests.cs99
1 files changed, 99 insertions, 0 deletions
diff --git a/UnitTests/Mono.Debugging.Tests/Shared/SourceLocationTests.cs b/UnitTests/Mono.Debugging.Tests/Shared/SourceLocationTests.cs
new file mode 100644
index 0000000..9da44cd
--- /dev/null
+++ b/UnitTests/Mono.Debugging.Tests/Shared/SourceLocationTests.cs
@@ -0,0 +1,99 @@
+//
+// SourceLocationTests.cs
+//
+// Author:
+// Jeffrey Stedfast <jestedfa@microsoft.com>
+//
+// Copyright (c) 2019 Microsoft Corp.
+//
+// Permission is hereby granted, free of charge, to any person obtaining a copy
+// of this software and associated documentation files (the "Software"), to deal
+// in the Software without restriction, including without limitation the rights
+// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+// copies of the Software, and to permit persons to whom the Software is
+// furnished to do so, subject to the following conditions:
+//
+// The above copyright notice and this permission notice shall be included in
+// all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+// THE SOFTWARE.
+
+using System;
+using System.IO;
+using System.Text;
+using System.Security.Cryptography;
+
+using Mono.Debugging.Client;
+
+using NUnit.Framework;
+
+namespace Mono.Debugging.Tests
+{
+ [TestFixture]
+ public class SourceLocationTests
+ {
+ static void TestCheckFileHash (string algorithm, string text, string mode)
+ {
+ var buffer = Encoding.ASCII.GetBytes (text);
+
+ using (var hash = HashAlgorithm.Create (algorithm)) {
+ var checksum = hash.ComputeHash (buffer);
+ string tmp;
+
+ tmp = Path.GetTempFileName ();
+ File.WriteAllBytes (tmp, buffer);
+
+ Assert.IsTrue (SourceLocation.CheckFileHash (tmp, checksum), "CheckFileHash {0} ({1})", algorithm, mode);
+
+ if (checksum.Length > 16) {
+ var roslyn = new byte[16];
+
+ roslyn[0] = (byte) checksum.Length;
+ for (int i = 1; i < 16; i++)
+ roslyn[i] = checksum[i - 1];
+
+ Assert.IsTrue (SourceLocation.CheckFileHash (tmp, checksum), "CheckFileHash Roslyn {0} ({1})", algorithm, mode);
+ }
+ }
+ }
+
+ static void TestCheckFileHash (string algorithm)
+ {
+ string text = "This is line 1.\nThis is line 2.\r\nThis is line 3.\r\nThis is line 4.\nThis is line 5.\n";
+
+ TestCheckFileHash (algorithm, text, "MIXED");
+
+ text = text.Replace ("\r\n", "\n");
+
+ TestCheckFileHash (algorithm, text, "UNIX");
+
+ text = text.Replace ("\n", "\r\n");
+
+ TestCheckFileHash (algorithm, text, "DOS");
+ }
+
+ [Test]
+ public void TestCheckFileHashSha1 ()
+ {
+ TestCheckFileHash ("SHA1");
+ }
+
+ [Test]
+ public void TestCheckFileHashSha256 ()
+ {
+ TestCheckFileHash ("SHA256");
+ }
+
+ [Test]
+ public void TestCheckFileHashMd5 ()
+ {
+ TestCheckFileHash ("MD5");
+ }
+ }
+}