From 4bdbb361356b1bedf58a7828d2813dd7944afec3 Mon Sep 17 00:00:00 2001
From: Markus Quaritsch <markus.quaritsch@tugraz.at>
Date: Thu, 4 May 2017 16:36:17 +0200
Subject: [PATCH] adding test for reading out existing hash

---
 VectoCommon/VectoHashing/VectoHash.cs         |  3 ++-
 VectoCommon/VectoHashingTest/VectoHashTest.cs | 20 +++++++++++++++++++
 2 files changed, 22 insertions(+), 1 deletion(-)

diff --git a/VectoCommon/VectoHashing/VectoHash.cs b/VectoCommon/VectoHashing/VectoHash.cs
index 293b4976f5..a94f4bb6af 100644
--- a/VectoCommon/VectoHashing/VectoHash.cs
+++ b/VectoCommon/VectoHashing/VectoHash.cs
@@ -125,7 +125,8 @@ namespace TUGraz.VectoHashing
 
 		public bool ValidateHash(VectoComponents component, int index = 0)
 		{
-			return StructuralComparisons.StructuralEqualityComparer.Equals(ReadHash(component), ComputeHash(component));
+			return StructuralComparisons.StructuralEqualityComparer.Equals(ReadHash(component, index),
+				ComputeHash(component, index));
 		}
 
 		private static string GetHashValue(XmlDocument hashed, string elementToHash)
diff --git a/VectoCommon/VectoHashingTest/VectoHashTest.cs b/VectoCommon/VectoHashingTest/VectoHashTest.cs
index 56c569f13b..7149c3d4ae 100644
--- a/VectoCommon/VectoHashingTest/VectoHashTest.cs
+++ b/VectoCommon/VectoHashingTest/VectoHashTest.cs
@@ -48,5 +48,25 @@ namespace VectoHashingTest
 
 			Assert.AreEqual(expectedHash, hash);
 		}
+
+		[TestCase(ReferenceXMLVehicle, VectoComponents.Engine, "e0c253b643f7f8f09b963aca4a264d06fbfa599f"),
+		TestCase(ReferenceXMLVehicle, VectoComponents.Gearbox, "d14189366134120e08fa3f2c6e3328dd13c08a23")]
+		public void TestReadHash(string file, VectoComponents component, string expectedHash)
+		{
+			var h = VectoHash.Load(file);
+			var existingHash = h.ReadHash(component);
+
+			Assert.AreEqual(expectedHash, existingHash);
+		}
+
+		[TestCase(ReferenceXMLVehicle, VectoComponents.Tyre, 0, "5074334bb2c090c5e258e9a664f5d19689a3f13d"),
+		TestCase(ReferenceXMLVehicle, VectoComponents.Tyre, 1, "6074334bb2c090c5e258e9a664f5d19689a3f13d")]
+		public void TestReadHashIdx(string file, VectoComponents component, int index, string expectedHash)
+		{
+			var h = VectoHash.Load(file);
+			var existingHash = h.ReadHash(component, index);
+
+			Assert.AreEqual(expectedHash, existingHash);
+		}
 	}
 }
\ No newline at end of file
-- 
GitLab