Code development platform for open source projects from the European Union institutions :large_blue_circle: EU Login authentication by SMS has been phased out. To see alternatives please check here

Skip to content
Snippets Groups Projects
Commit 31147c6c authored by Markus Quaritsch's avatar Markus Quaritsch
Browse files

Pull request #871: Bugfix/VECTO-1550 error in hashing tool

Merge in VECTO/vecto-sim from VECTO/mq_vecto-sim:bugfix/VECTO-1550-error-in-hashing-tool to develop

* commit '8c9f4d48':
  sort tire nodes by axle number in job xml
  adding testcase showing error in reading and re-calculating hash of tires (if the order changes in the input)
parents d7a62bf3 8c9f4d48
Branches
Tags
No related merge requests found
......@@ -168,8 +168,10 @@ namespace TUGraz.VectoHashing
throw new Exception(string.Format("index exceeds number of components found! index: {0}, #components: {1}", index,
nodes.Count));
}
var componentId = nodes[index].Attributes[XMLNames.Component_ID_Attr].Value;
return GetHashValueFromSig(DoComputeHash(nodes[index], canonicalization, digestMethod), componentId);
var sortedNodes = SortComponentNodes(component, nodes);
var componentId = sortedNodes[index].Attributes[XMLNames.Component_ID_Attr].Value ?? "";
return GetHashValueFromSig(DoComputeHash(sortedNodes[index], canonicalization, digestMethod), componentId);
}
private static XmlDocument DoComputeHash(XmlNode dataNode, IEnumerable<string> canonicalization, string digestMethod)
......@@ -381,7 +383,7 @@ namespace TUGraz.VectoHashing
return ReadHashValue(nodes[index]);
}
private XmlNodeList GetNodes(VectoComponents? component, int index)
private XmlNode[] GetNodes(VectoComponents? component, int index)
{
var nodes = Document.SelectNodes(GetComponentQueryString(component));
if (nodes == null || nodes.Count == 0) {
......@@ -393,7 +395,17 @@ namespace TUGraz.VectoHashing
throw new Exception(string.Format("index exceeds number of components found! index: {0}, #components: {1}", index,
nodes.Count));
}
return nodes;
return SortComponentNodes(component, nodes);
}
private XmlNode[] SortComponentNodes(VectoComponents? component, XmlNodeList nodes)
{
if (component != null && component == VectoComponents.Tyre) {
return nodes.Cast<XmlNode>()
.OrderBy(x => x.SelectSingleNode("./ancestor-or-self::*[@axleNumber]/@axleNumber")?.Value.ToInt() ?? 0).ToArray();
}
return nodes.Cast<XmlNode>().ToArray();
}
......
Source diff could not be displayed: it is too large. Options to address this: view the blob.
......@@ -132,10 +132,10 @@ namespace VectoHashingTest
Assert.AreEqual(expectedHash, existingHash);
}
[TestCase]
public void TestReadTyres1Index()
[TestCase(@"Testdata\XML\ToHash\vecto_vehicle-sample_3axle1.xml"),
TestCase(@"Testdata\XML\ToHash\vecto_vehicle-sample_3axle1_unsortedAxle.xml")]
public void TestReadTyres1Index(string file)
{
var file = @"Testdata\XML\ToHash\vecto_vehicle-sample_3axle1.xml";
var h = VectoHash.Load(file);
var expectedHash = new[] {
"5074334bb2c090c5e258e9a664f5d19689a3f13d",
......@@ -146,7 +146,7 @@ namespace VectoHashingTest
for (int i = 0; i < expectedHash.Length; i++) {
var existingHash = h.ReadHash(VectoComponents.Tyre, i);
Assert.AreEqual(expectedHash[i], existingHash);
Assert.AreEqual(expectedHash[i], existingHash, $"component index {i}");
}
}
......@@ -171,10 +171,10 @@ namespace VectoHashingTest
"index exceeds number of components found! index: 3, #components: 3");
}
[TestCase]
public void TestComputeTyres1Index()
[TestCase(@"Testdata\XML\ToHash\vecto_vehicle-sample_3axle1.xml"),
TestCase(@"Testdata\XML\ToHash\vecto_vehicle-sample_3axle1_unsortedAxle.xml")]
public void TestComputeTyres1Index(string file)
{
var file = @"Testdata\XML\ToHash\vecto_vehicle-sample_3axle1.xml";
var h = VectoHash.Load(file);
var hash1 = h.ComputeHash(VectoComponents.Tyre, 1);
......
......@@ -196,6 +196,9 @@
<Content Include="Testdata\XML\ToHash\vecto_gearbox-input_nodata.xml">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="Testdata\XML\ToHash\vecto_vehicle-sample_3axle1_unsortedAxle.xml">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="Testdata\XML\ToHash\vecto_vehicle-sample_3axle1.xml">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment