diff --git a/VectoCommon/VectoHashing/VectoHash.cs b/VectoCommon/VectoHashing/VectoHash.cs index 293b4976f58ce3e533a366646a5446e18ff3a9dc..a94f4bb6af54515f8e8e0f9dc6b9c02970ff7036 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 56c569f13b38a8f50571f6eb94ebdac83bcf6608..7149c3d4ae33bca7d63ea64bd09f3fdf1fc29bae 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