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 17ca0c22 authored by Markus Quaritsch's avatar Markus Quaritsch
Browse files

Pull request #914: Feature/VECTO-1652 additional tyre dimension

Merge in VECTO/vecto-sim from VECTO/mq_vecto-sim:feature/VECTO-1652-additional-tyre-dimension to develop

* commit '2ffcf700':
  xmlvalidator: handle the case where validationeventargs may be null
  update hashing tool to read the error message from the correct fields
  extending xml validation to check it the tyre dimension is valid
  updating xml schema version 2.5: remove restrictions for tyre dimension adding xml reader for tyre in version 2.5 adding testcase to read vehicle with 2.5 tyres adding tyre xml version 2.5
  adding new tyre dimensions
  correcting typo
  adding sample xml for tyre in version 2.5 adding testcase to generate tyre XML in version 2.5 for all tyre dimensions listed in wheels.csv adding testcase for syntactically invalid dimension strings
  adding XML schema for tyres  with regex for tyre dimension string
parents 3236c4b4 2ffcf700
Branches
Tags
No related merge requests found
Showing
with 3856 additions and 13 deletions
......@@ -183,6 +183,10 @@ hashingcmd.exe
{
var args = evt.ValidationEventArgs;
if (severity == XmlSeverityType.Error) {
if (args == null) {
throw new Exception(string.Format("Validation error: {0}", evt.Exception.Message), evt.Exception.InnerException);
}
throw new Exception(string.Format("Validation error: {0}" + Environment.NewLine +
"Line: {1}", args.Message, args.Exception.LineNumber), evt.Exception);
} else {
......
......@@ -285,12 +285,12 @@ namespace HashingTool.ViewModel.UserControl
(s, e) => {
Application.Current.Dispatcher.Invoke(
() => {
if (e.ValidationEventArgs == null) {
LogError(
string.Format(
"XML file does not validate against a supported version of {0}",
_expectedDocumentType.ToString()));
} else {
//if (e.ValidationEventArgs == null) {
// LogError(
// string.Format(
// "XML file does not validate against a supported version of {0}",
// _expectedDocumentType.ToString()));
//} else {
LogError(
string.Format(
"Validation {0} Line {2}: {1}",
......@@ -302,7 +302,7 @@ namespace HashingTool.ViewModel.UserControl
: "")
: e.ValidationEventArgs.Message,
e.ValidationEventArgs == null ? 0 : e.ValidationEventArgs.Exception.LineNumber));
}
//}
}
);
}
......
......@@ -157,7 +157,7 @@ namespace TUGraz.VectoHashing
/// <summary>
/// Computes the hash-value of the outer Data element and adds the according Signature element
/// after the Data element.
/// The default CaonocalizationMethods and DigestMethod are used.
/// The default CanocalizationMethods and DigestMethod are used.
/// Note: the id attribute is added to the Data element automatically. if an id attribute is already
/// present its value is overwritten unless its lenth is more than 5 characters.
/// </summary>
......
<?xml version="1.0" encoding="utf-8"?>
<tns:VectoInputDeclaration xmlns="urn:tugraz:ivt:VectoAPI:DeclarationDefinitions:v2.3" xmlns:tns="urn:tugraz:ivt:VectoAPI:DeclarationComponent:v2.1"
xmlns:v2.0="urn:tugraz:ivt:VectoAPI:DeclarationDefinitions:v2.0" xmlns:v2.3="urn:tugraz:ivt:VectoAPI:DeclarationDefinitions:v2.3"
xmlns:di="http://www.w3.org/2000/09/xmldsig#" schemaVersion="2.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="urn:tugraz:ivt:VectoAPI:DeclarationComponent E:\QUAM\Workspace\VECTO_quam\VectoCore\VectoCore\Resources\XSD\VectoDeclarationComponent.xsd">
<tns:Tyre xmlns:v2.5="urn:tugraz:ivt:VectoAPI:DeclarationDefinitions:v2.5">
<v2.0:Data xsi:type="TyreDataDeclarationType" id="TYR-123" xmlns="urn:tugraz:ivt:VectoAPI:DeclarationDefinitions:v2.5">
<Manufacturer>Generic Vendor</Manufacturer>
<Model>ADC 20</Model>
<CertificationNumber>xyz-abc-def</CertificationNumber>
<Date>2021-11-18T14:09:17.2810263Z</Date>
<AppVersion>Some Application v1.0</AppVersion>
<Dimension>###SOME_DIMENSION###</Dimension>
<TyreClass>C1</TyreClass>
<FuelEfficiencyClass>A</FuelEfficiencyClass>
<RRCDeclared>0.0055</RRCDeclared>
<FzISO>33500</FzISO>
</v2.0:Data>
</tns:Tyre>
</tns:VectoInputDeclaration>
\ No newline at end of file
......@@ -32,11 +32,16 @@
using System;
using System.IO;
using System.Linq;
using System.Security.Cryptography.Xml;
using System.Text;
using System.Xml;
using System.Xml.Linq;
using System.Xml.Schema;
using System.Xml.XPath;
using System.Xml.Xsl;
using NUnit.Framework;
using TUGraz.VectoCommon.Hashing;
using TUGraz.VectoCore.Models.Declaration;
using TUGraz.VectoCore.Utils;
using TUGraz.VectoHashing;
using VectoHashingTest.Utils;
......@@ -523,5 +528,207 @@ namespace VectoHashingTest
var h = VectoHash.Load(file);
Assert.IsTrue(h.ValidateHash());
}
private const string WheelsFileToHash25 = @"Testdata\XML\ToHash\Tyre_v25.xml";
[TestCase(WheelsFileToHash25)]
public void TestTyreValidDimension(string file)
{
var validDimensions = DeclarationData.Wheels.GetWheelsDimensions();
foreach (var dimension in validDimensions) {
var modified = GetModifiedXML(file, dimension);
var xmlDoc = new XmlDocument();
xmlDoc.Load(modified);
var h = VectoHash.Load(xmlDoc);
var hashed = h.AddHash();
var validator = new XMLValidator(XmlReader.Create(new StringReader(hashed.ToString())));
Assert.IsTrue(validator.ValidateXML(XmlDocumentType.DeclarationComponentData));
}
}
[
TestCase(WheelsFileToHash25, "255/70 R22.5", "255/70 R22.5"),
TestCase(WheelsFileToHash25, "255/70 R22.5", " 255/70 R22.5"),
TestCase(WheelsFileToHash25, "255/70 R22.5", "255/70 R22.5 "),
TestCase(WheelsFileToHash25, "255/70 R22.5", "255/70 R22.5"),
TestCase(WheelsFileToHash25, " 255/70 R22.5", "255/70 R22.5"),
TestCase(WheelsFileToHash25, "255/70 R22.5 ", "255/70 R22.5"),
]
public void TestTyreValidDimensionVariationHash(string file, string dimension, string dimensionVaried)
{
// create XML with dimension string and hash it
var reference = GetModifiedXML(file, dimension);
var xmlDoc = new XmlDocument();
xmlDoc.Load(reference);
var h = VectoHash.Load(xmlDoc);
var hashed = h.AddHash();
// created XML needs to be valid
var validator = new XMLValidator(XmlReader.Create(new StringReader(hashed.ToString())));
Assert.IsTrue(validator.ValidateXML(XmlDocumentType.DeclarationComponentData));
// change the dimension string to something else and load the modified XML
var variation = GetModifiedXML(hashed, dimensionVaried);
var xmlDocV = new XmlDocument();
xmlDocV.Load(variation);
var h2 = VectoHash.Load(xmlDocV);
// the hash has to be valid
var variationValid = h2.ValidateHash();
Assert.IsTrue(variationValid);
var validatorV = new XMLValidator(xmlDocV);
Assert.IsTrue(validatorV.ValidateXML(XmlDocumentType.DeclarationComponentData));
}
[
TestCase(WheelsFileToHash25, "255/70 R22.5 ", "255/70 R22.5"), // the hash is still the same but the tyre dimension is invalid
//TestCase(WheelsFileToHash25, "255/70 R22.5 ", "255/70 R 22.5"),
//TestCase(WheelsFileToHash25, "255/70 R22.5 ", "255 / 70 R 22.5"),
]
public void TestTyreInvalidDimensionVariationHash(string file, string dimension, string dimensionVaried)
{
// create XML with dimension string and hash it
var reference = GetModifiedXML(file, dimension);
var xmlDoc = new XmlDocument();
xmlDoc.Load(reference);
var h = VectoHash.Load(xmlDoc);
var hashed = h.AddHash();
// created XML needs to be valid
var validator = new XMLValidator(XmlReader.Create(new StringReader(hashed.ToString())));
Assert.IsTrue(validator.ValidateXML(XmlDocumentType.DeclarationComponentData));
// change the dimension string to something else and load the modified XML
var variation = GetModifiedXML(hashed, dimensionVaried);
var xmlDocV = new XmlDocument();
xmlDocV.Load(variation);
var h2 = VectoHash.Load(xmlDocV);
// the hash has to be valid
var variationValid = h2.ValidateHash();
Assert.IsTrue(variationValid);
var message = "";
var validatorV = new XMLValidator(xmlDocV, validationErrorAction: (s, ve) => message = ve.Exception.Message);
var result = validatorV.ValidateXML(XmlDocumentType.DeclarationComponentData);
Assert.IsFalse(result);
Assert.IsTrue(message.Contains("Invalid tyre dimension"));
}
[
TestCase(WheelsFileToHash25, "255/70 R22.5", "255/70 R 22.5"),
TestCase(WheelsFileToHash25, "255/70 R22.5", "255 / 70 R 22.5"),
]
public void TestTyreIDimensionVariationInvalidHash(string file, string dimension, string dimensionVaried)
{
// create XML with dimension string and hash it
var reference = GetModifiedXML(file, dimension);
var xmlDoc = new XmlDocument();
xmlDoc.Load(reference);
var h = VectoHash.Load(xmlDoc);
var hashed = h.AddHash();
// created XML needs to be valid
var validator = new XMLValidator(XmlReader.Create(new StringReader(hashed.ToString())));
Assert.IsTrue(validator.ValidateXML(XmlDocumentType.DeclarationComponentData));
// change the dimension string to something else and load the modified XML
var variation = GetModifiedXML(hashed, dimensionVaried);
var xmlDocV = new XmlDocument();
xmlDocV.Load(variation);
var h2 = VectoHash.Load(xmlDocV);
// the hash is no longer valid
var variationValid = h2.ValidateHash();
Assert.IsFalse(variationValid);
}
[
TestCase(WheelsFileToHash25, "asdf"),
TestCase(WheelsFileToHash25, "250/70R14XX"),
TestCase(WheelsFileToHash25, "V425/55 R19.5"),
TestCase(WheelsFileToHash25, "425 / 55 R 19.5"),
TestCase(WheelsFileToHash25, "255 / 70 R22.5"),
TestCase(WheelsFileToHash25, "255/70 R22.5"),
TestCase(WheelsFileToHash25, " 255/70 R22.5 "),
TestCase(WheelsFileToHash25, " 255/70 R22.5 "),
TestCase(WheelsFileToHash25, "255/70 R22.5"),
]
public void TestTyreInValidDimension(string file, string dimension)
{
var modified = GetModifiedXML(file, dimension);
var xmlDoc = new XmlDocument();
xmlDoc.Load(modified);
var h = VectoHash.Load(xmlDoc);
var hashed = h.AddHash();
string message = "";
var validator = new XMLValidator(XmlReader.Create(new StringReader(hashed.ToString())),
validationErrorAction: (s, ve) => message = ve.Exception.Message);
var result = validator.ValidateXML(XmlDocumentType.DeclarationComponentData);
Assert.IsFalse(result);
Assert.IsTrue(message.Contains("Invalid tyre dimension"));
}
private XmlReader GetModifiedXML(XDocument doc, string dimension)
{
var tyreDimension = doc.XPathSelectElement("//*[local-name()='Dimension']");
Assert.NotNull(tyreDimension);
tyreDimension.Value = dimension;
var xmlString = "";
using (MemoryStream ms = new MemoryStream()) {
using (XmlWriter xw = XmlWriter.Create(ms, new XmlWriterSettings { Indent = true })) {
doc.WriteTo(xw);
xw.Flush();
}
ms.Flush();
ms.Seek(0, SeekOrigin.Begin);
using (var reader = new StreamReader(ms)) {
xmlString = reader.ReadToEnd();
}
}
var modified = XmlReader.Create(new StringReader(xmlString));
return modified;
}
private XmlReader GetModifiedXML(string file, string dimension)
{
var inputXml = new XmlDocument();
inputXml.Load(file);
var tyreDimension = inputXml.SelectSingleNode("//*[local-name()='Dimension']");
Assert.NotNull(tyreDimension);
tyreDimension.InnerText = dimension;
var modified = XmlReader.Create(new StringReader(inputXml.OuterXml));
return modified;
}
// [TestCase()]
//public void TestXSLTransform()
//{
// var dimension = " 425 / 55 R 19.5 ";
// var modified = GetModifiedXML(WheelsFileToHash25, dimension);
// var xmlDoc = new XmlDocument();
// xmlDoc.Load(modified);
// var transform = new XmlDsigExcC14NTransform();
// transform.LoadInput(xmlDoc);
// var output = transform.GetOutput() as Stream;
// var sr = new StreamReader(output);
// var xml = sr.ReadToEnd();
//}
}
}
......@@ -178,6 +178,9 @@
<Content Include="Testdata\XML\ToHash\multiple_components.xml">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="Testdata\XML\ToHash\Tyre_v25.xml">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="Testdata\XML\ToHash\vecto_engine-input_emptyDate.xml">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
......
......@@ -144,4 +144,21 @@ namespace TUGraz.VectoCore.InputData.FileIO.XML.Declaration.DataProvider
//public override string FuelEfficiencyClass => GetString("FuelEfficiencyClass");
}
// ---------------------------------------------------------------------------------------
public class XMLDeclarationTyreDataProviderV25 : XMLDeclarationTyreDataProviderV23
{
public new static readonly XNamespace NAMESPACE_URI = XMLDefinitions.DECLARATION_DEFINITIONS_NAMESPACE_URI_V25;
//public new const string XSD_TYPE = "TyreComponentDeclarationType";
public new static readonly string QUALIFIED_XSD_TYPE = XMLHelper.CombineNamespace(NAMESPACE_URI.NamespaceName, XSD_TYPE);
public XMLDeclarationTyreDataProviderV25(IXMLDeclarationVehicleData vehicle, XmlNode componentNode, string sourceFile)
: base(vehicle, componentNode, sourceFile) { }
protected override XNamespace SchemaNamespace => NAMESPACE_URI;
}
}
using Ninject.Modules;
using TUGraz.VectoCore.InputData.FileIO.XML.Declaration.DataProvider;
using TUGraz.VectoCore.InputData.FileIO.XML.Declaration.Interfaces;
namespace TUGraz.VectoCore.InputData.FileIO.XML.Declaration.NinjectModules
{
public class XMLDeclarationInputDataV25InjectModule : NinjectModule
{
public override void Load()
{
Bind<IXMLTyreDeclarationInputData>().To<XMLDeclarationTyreDataProviderV25>().Named(
XMLDeclarationTyreDataProviderV25.QUALIFIED_XSD_TYPE);
}
}
}
\ No newline at end of file
......@@ -54,6 +54,7 @@ namespace TUGraz.VectoCore.InputData.FileIO.XML.Declaration
new XMLDeclarationInputDataV22InjectModule(),
new XMLDeclarationInputDataV221InjectModule(),
new XMLDeclarationInputDataV23InjectModule(),
new XMLDeclarationInputDataV25InjectModule(),
});
#endregion
......
......@@ -109,3 +109,16 @@ LT265/75 R16 , 267 , 0.75 , 16
#
205/70 R17C , 209 , 0.7 , 17 , 720 , 2.01 , 3.03 , motor vehicles <7.5t
285/55 R16C , 297 , 0.55 , 16 , 720 , 2.54 , 3.03 , motor vehicles <7.5t
## Update Q4/2022
225/70 R19.5 , 226 , 0.7 , 19.5 , 811 , 6.44 , 3.05 ,
255/55 R18CP , 265 , 0.55 , 18 , 737 , 3.00 , 3.03 ,
315/55 R17C , 328 , 0.55 , 17 , 778 , 3.13 , 3.03 ,
LT245/70 R17 , 248 , 0.7 , 17 , 776 , 3.30 , 3.03 ,
13.00 R20 , 336 , 0.95 , 20 , 1176 , 23.92 , 3.05 ,
245/75 R17.5 , 248 , 0.75 , 17.5 , 813 , 4.80 , 3.05 ,
325/90 R24.5 , 327 , 0.9 , 24.5 , 1208 , 26.05 , 3.05 ,
195/70 R15C , 201 , 0.7 , 15 , 655 , 1.85 , 3.03 ,
215/60 R16C , 221 , 0.6 , 16 , 664 , 1.50 , 3.03 ,
215/65 R15C , 221 , 0.65 , 15 , 661 , 1.45 , 3.03 ,
225/55 R17C , 233 , 0.55 , 17 , 680 , 1.90 , 3.03 ,
225/60 R16C , 228 , 0.6 , 16 , 676 , 1.70 , 3.03 ,
<?xml version="1.0" encoding="UTF-8"?>
<!-- edited with XMLSpy v2021 (x64) (http://www.altova.com) by Markus Quaritsch (Technische Universität Graz) -->
<xs:schema xmlns:tns="urn:tugraz:ivt:VectoAPI:DeclarationDefinitions:v2.5" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:vectoParam="urn:tugraz:ivt:VectoAPI:ParameterDocumentation" xmlns:di="http://www.w3.org/2000/09/xmldsig#" xmlns:v1.0="urn:tugraz:ivt:VectoAPI:DeclarationDefinitions:v1.0" xmlns:v2.0="urn:tugraz:ivt:VectoAPI:DeclarationDefinitions:v2.0" xmlns:v2.1="urn:tugraz:ivt:VectoAPI:DeclarationDefinitions:v2.1" xmlns:ns1="urn:tugraz:ivt:VectoAPI:DeclarationDefinitions:v2.5" targetNamespace="urn:tugraz:ivt:VectoAPI:DeclarationDefinitions:v2.5" elementFormDefault="qualified" attributeFormDefault="unqualified" xsi:schemaLocation="urn:tugraz:ivt:VectoAPI:ParameterDocumentation ParameterDocumentation.xsd">
<xs:import namespace="http://www.w3.org/2000/09/xmldsig#" schemaLocation="xmldsig-core-schema.xsd"/>
<xs:import namespace="urn:tugraz:ivt:VectoAPI:DeclarationDefinitions:v1.0" schemaLocation="VectoDeclarationDefinitions.1.0.xsd"/>
<xs:import namespace="urn:tugraz:ivt:VectoAPI:DeclarationDefinitions:v2.0" schemaLocation="VectoDeclarationDefinitions.2.0.xsd"/>
<xs:import namespace="urn:tugraz:ivt:VectoAPI:DeclarationDefinitions:v2.1" schemaLocation="VectoDeclarationDefinitions.2.1.xsd"/>
<xs:complexType name="TyreDataDeclarationType">
<xs:complexContent>
<xs:extension base="v1.0:AbstractTyreDataDeclarationType">
<xs:sequence>
<xs:element name="Manufacturer" type="v1.0:ManufacturerType">
<xs:annotation>
<xs:documentation>P230 - [-]</xs:documentation>
</xs:annotation>
</xs:element>
<xs:element name="Model" type="v1.0:ModelType">
<xs:annotation>
<xs:documentation>P231 - [-]</xs:documentation>
</xs:annotation>
</xs:element>
<xs:element name="CertificationNumber" type="v1.0:CertificationNumberType">
<xs:annotation>
<xs:documentation>P267 - [-]</xs:documentation>
</xs:annotation>
</xs:element>
<xs:element name="Date" type="v1.0:DateTimeWithTimezone">
<xs:annotation>
<xs:documentation>P233 - [-]</xs:documentation>
</xs:annotation>
</xs:element>
<xs:element name="AppVersion" type="v1.0:AppVersionType">
<xs:annotation>
<xs:documentation>P234 - [-]</xs:documentation>
</xs:annotation>
</xs:element>
<xs:element name="Dimension" type="tns:TyreDimensionType">
<xs:annotation>
<xs:documentation>P108 - enum</xs:documentation>
</xs:annotation>
</xs:element>
<xs:element name="TyreClass">
<xs:annotation>
<xs:documentation>P370 - enum</xs:documentation>
<xs:appinfo>
<vectoParam:description>
<vectoParam:parameterId component="Tyre">370</vectoParam:parameterId>
<vectoParam:unit>-</vectoParam:unit>
</vectoParam:description>
</xs:appinfo>
</xs:annotation>
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:minLength value="1"/>
<xs:enumeration value="C1"/>
<xs:enumeration value="C2"/>
<xs:enumeration value="C3"/>
<xs:enumeration value="N/A"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
<xs:element name="FuelEfficiencyClass">
<xs:annotation>
<xs:documentation>P371 - enum</xs:documentation>
<xs:appinfo>
<vectoParam:description>
<vectoParam:parameterId component="Tyre">371</vectoParam:parameterId>
<vectoParam:unit>-</vectoParam:unit>
</vectoParam:description>
</xs:appinfo>
</xs:annotation>
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:enumeration value="A"/>
<xs:enumeration value="B"/>
<xs:enumeration value="C"/>
<xs:enumeration value="D"/>
<xs:enumeration value="E"/>
<xs:enumeration value="F"/>
<xs:enumeration value="G"/>
<xs:enumeration value="N/A"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
<xs:element name="RRCDeclared" type="v1.0:TyreRRCISOType">
<xs:annotation>
<xs:documentation>P046 - [-]</xs:documentation>
</xs:annotation>
</xs:element>
<xs:element name="FzISO" type="v1.0:TyreFzISOType">
<xs:annotation>
<xs:documentation>P047 - [N]</xs:documentation>
</xs:annotation>
</xs:element>
</xs:sequence>
</xs:extension>
</xs:complexContent>
</xs:complexType>
<xs:simpleType name="TyreDimensionType">
<xs:restriction base="xs:token"/>
</xs:simpleType>
</xs:schema>
......@@ -12,4 +12,5 @@
<xs:import namespace="urn:tugraz:ivt:VectoAPI:DeclarationDefinitions:v2.2" schemaLocation="VectoDeclarationDefinitions.2.2.xsd"/>
<xs:import namespace="urn:tugraz:ivt:VectoAPI:DeclarationDefinitions:v2.2.1" schemaLocation="VectoDeclarationDefinitions.2.2.1.xsd"/>
<xs:import namespace="urn:tugraz:ivt:VectoAPI:DeclarationDefinitions:v2.3" schemaLocation="VectoDeclarationDefinitions.2.3.xsd"/>
<xs:import namespace="urn:tugraz:ivt:VectoAPI:DeclarationDefinitions:v2.5" schemaLocation="VectoDeclarationDefinitions.2.5.xsd"/>
</xs:schema>
......@@ -82,6 +82,8 @@ namespace TUGraz.VectoCore.Utils
public const string DECLARATION_DEFINITIONS_NAMESPACE_URI_V23 = DECLARATION_NAMESPACE + ":v2.3";
public const string DECLARATION_DEFINITIONS_NAMESPACE_URI_V25 = DECLARATION_NAMESPACE + ":v2.5";
public const string DECLARATION_INPUT_NAMESPACE = "urn:tugraz:ivt:VectoAPI:DeclarationInput";
public const string DECLARATION_INPUT_NAMESPACE_URI_V10 = DECLARATION_INPUT_NAMESPACE + ":v1.0";
......
......@@ -38,7 +38,9 @@ using System.Threading.Tasks;
using System.Xml;
using System.Xml.Schema;
using TUGraz.VectoCommon.Exceptions;
using TUGraz.VectoCommon.Resources;
using TUGraz.VectoCommon.Utils;
using TUGraz.VectoCore.Models.Declaration;
namespace TUGraz.VectoCore.Utils
{
......@@ -74,6 +76,7 @@ namespace TUGraz.VectoCore.Utils
public bool ValidateXML(XmlDocumentType docType)
{
_valid = true;
InternalValidationMessage = "";
if (_doc.DocumentElement == null) {
throw new Exception("empty XML document");
}
......@@ -84,24 +87,49 @@ namespace TUGraz.VectoCore.Utils
if (_doc.SchemaInfo.Validity != XmlSchemaValidity.Valid || _doc.DocumentElement?.SchemaInfo == null ||
_doc.DocumentElement.SchemaInfo.SchemaType == null) {
ValidationCallBack(null, null);
InternalValidationMessage = string.Format("XML file does not validate against a supported version of {0}", docType);
ValidationCallBack(this, null);
_valid = false;
}
var tyreNodes = _doc.SelectNodes(XMLHelper.QueryLocalName(XMLNames.AxleWheels_Axles_Axle_Tyre,
XMLNames.ComponentDataWrapper, XMLNames.AxleWheels_Axles_Axle_Dimension));
if (tyreNodes != null) {
foreach (XmlNode tyreNode in tyreNodes) {
var dimension = tyreNode.InnerText;
var validDimension = DeclarationData.Wheels.GetWheelsDimensions().Contains(dimension.Trim());
if (validDimension) {
continue;
}
InternalValidationMessage =
$"Invalid tyre dimension '{dimension.Trim()}'. Please check Wheels.csv for valid tyre dimensions.";
ValidationCallBack(this, null);
}
}
return _valid;
}
protected string InternalValidationMessage { get; set; }
private void ValidationCallBack(object sender, ValidationEventArgs args)
{
_resultAction(false);
_valid = false;
_validationErrorAction(args?.Severity ?? XmlSeverityType.Error, new ValidationEvent { ValidationEventArgs = args });
var validationEvent = new ValidationEvent { ValidationEventArgs = args };
if (sender == this) {
validationEvent = new ValidationEvent()
{ Exception = new VectoXMLException(InternalValidationMessage) };
}
_validationErrorAction(args?.Severity ?? XmlSeverityType.Error, validationEvent);
}
public static void CallBackExceptionOnError(XmlSeverityType severity, ValidationEvent evt)
{
if (severity == XmlSeverityType.Error) {
throw new VectoException("Validation error: {0}", evt.ValidationEventArgs.Message);
throw new VectoException("Validation error: {0}", evt.ValidationEventArgs?.Message ?? evt.Exception?.Message);
}
}
......
......@@ -179,6 +179,7 @@
<Compile Include="InputData\FileIO\XML\Declaration\NinjectModules\XMLDeclarationInputDataV221InjectModule.cs" />
<Compile Include="InputData\FileIO\XML\Declaration\NinjectModules\XMLDeclarationInputDataV22InjectModule.cs" />
<Compile Include="InputData\FileIO\XML\Declaration\NinjectModules\XMLDeclarationInputDataV23InjectModule.cs" />
<Compile Include="InputData\FileIO\XML\Declaration\NinjectModules\XMLDeclarationInputDataV25InjectModule.cs" />
<Compile Include="InputData\FileIO\XML\Declaration\Reader\Impl\AbstractComponentReader.cs" />
<Compile Include="InputData\FileIO\XML\Declaration\Reader\Impl\XMLADASReader.cs" />
<Compile Include="InputData\FileIO\XML\Declaration\Reader\Impl\XMLComponentReader.cs" />
......@@ -844,6 +845,9 @@
<EmbeddedResource Include="Resources\XSD\VTPReport.0.11.xsd">
<SubType>Designer</SubType>
</EmbeddedResource>
<EmbeddedResource Include="Resources\XSD\VectoDeclarationDefinitions.2.5.xsd">
<SubType>Designer</SubType>
</EmbeddedResource>
<None Include="Utils\VectoVersionCore.tt">
<Generator>TextTemplatingFileGenerator</Generator>
<LastGenOutput>VectoVersionCore.cs</LastGenOutput>
......
Source diff could not be displayed: it is too large. Options to address this: view the blob.
<?xml version="1.0" encoding="UTF-8"?>
<tns:VectoInputDeclaration
xmlns="urn:tugraz:ivt:VectoAPI:DeclarationDefinitions:v2.5"
xmlns:v2.0="urn:tugraz:ivt:VectoAPI:DeclarationDefinitions:v2.0"
xmlns:tns="urn:tugraz:ivt:VectoAPI:DeclarationComponent:v2.0"
xmlns:di="http://www.w3.org/2000/09/xmldsig#" schemaVersion="2.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="urn:tugraz:ivt:VectoAPI:DeclarationComponent E:\QUAM\Workspace\VECTO_quam\VectoCore\VectoCore\Resources\XSD/VectoDeclarationComponent.xsd">
<tns:Tyre>
<v2.0:Data id="TYR-gooZah3D" xsi:type="TyreDataDeclarationType">
<Manufacturer>Generic Tyre Manufacturer</Manufacturer>
<Model>Generic Tyre Model</Model>
<CertificationNumber>e12*0815/8051*2017/05T0000*00</CertificationNumber>
<Date>2017-02-15T11:00:00Z</Date>
<AppVersion>DemoTyreApp 1.0</AppVersion>
<Dimension>315/45 R22.5</Dimension>
<TyreClass>C1</TyreClass>
<FuelEfficiencyClass>A</FuelEfficiencyClass>
<RRCDeclared>0.0055</RRCDeclared>
<FzISO>33500</FzISO>
</v2.0:Data>
<v2.0:Signature>
<di:Reference URI="#TYR-gooZah3D">
<di:Transforms>
<di:Transform Algorithm="urn:vecto:xml:2017:canonicalization" />
<di:Transform Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#" />
</di:Transforms>
<di:DigestMethod Algorithm="http://www.w3.org/2001/04/xmlenc#sha256" />
<di:DigestValue>JWEwzKSP0lXvwRgQZTiWJm9dpdtQ72FOX0CC5Vy6f2Y=</di:DigestValue>
</di:Reference>
</v2.0:Signature>
</tns:Tyre>
</tns:VectoInputDeclaration>
\ No newline at end of file
......@@ -3928,6 +3928,9 @@
<Content Include="TestData\XML\XMLReaderDeclaration\SchemaVersion2.1\vecto_vehicle-exempted-sample.xml">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="TestData\XML\XMLReaderDeclaration\SchemaVersion2.1\vecto_vehicle-tyre25.xml">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="TestData\XML\XMLReaderDeclaration\SchemaVersion2.1\vecto_vehicle-new_parameters-sample.xml">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
......@@ -3952,6 +3955,9 @@
<Content Include="TestData\XML\XMLReaderDeclaration\SchemaVersion2.2\vecto_vehicle-sample_LNG.xml">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="TestData\XML\XMLReaderDeclaration\SchemaVersion2.5\TyreSample.xml">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="TestData\XML\XMLReaderDeclaration\Tractor_4x2_vehicle-class-5_5_t_0.xml">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
......
......@@ -33,6 +33,7 @@ using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Reflection.Emit;
using System.Xml;
using System.Xml.XPath;
using Ninject;
......@@ -54,7 +55,9 @@ using TUGraz.VectoCore.Utils;
using NUnit.Framework;
using TUGraz.VectoCommon.InputData;
using TUGraz.VectoCore.InputData.FileIO.XML;
using TUGraz.VectoCore.InputData.FileIO.XML.Declaration.Reader.Impl;
using TUGraz.VectoCore.InputData.Reader.DataObjectAdapter;
using XmlDocumentType = TUGraz.VectoCore.Utils.XmlDocumentType;
namespace TUGraz.VectoCore.Tests.XML
{
......@@ -748,6 +751,62 @@ namespace TUGraz.VectoCore.Tests.XML
}
}
public const string SampleTyreXML = @"TestData\XML\XMLReaderDeclaration\SchemaVersion2.5\TyreSample.xml";
[TestCase()]
public void TestWheelsSupportedInXML()
{
var tyreDimensions = DeclarationData.Wheels.GetWheelsDimensions();
foreach (var tyreDimension in tyreDimensions) {
var reader = XmlReader.Create(SampleTyreXML);
var doc = new XmlDocument();
doc.Load(reader);
var nav = doc.CreateNavigator();
var manager = new XmlNamespaceManager(nav.NameTable);
var helper = new XPathHelper(ExecutionMode.Declaration);
helper.AddNamespaces(manager);
var tyredimensionNode = nav.SelectSingleNode(XMLHelper.QueryLocalName(XMLNames.AxleWheels_Axles_Axle_Dimension));
tyredimensionNode.SetValue(tyreDimension);
var modified = XmlReader.Create(new StringReader(nav.OuterXml));
var validator = new XMLValidator(modified, null, XMLValidator.CallBackExceptionOnError);
var valid = validator.ValidateXML(XmlDocumentType.DeclarationComponentData);
Assert.IsTrue(valid, $"error validating XML with dimension {tyreDimension}");
}
}
[
TestCase("285/55R16C"), // invalid space
//TestCase("285/55 R16C"), // allowed, as xs:token already combines multiple whitespaces
TestCase("85/55 R16C"), // invalid section width
TestCase("285/1231 R16C"), // invalid aspect ratio width
TestCase("285/55 X16C"), // invalid construction type
TestCase("85/55 R16112C"), // invalid rim diameter
TestCase("85/55 R16x"), // invalid suffix
TestCase("1.0001 R12"), //
TestCase("9 R12111"), // invalid rim diameter
TestCase("9 R12x"), // invalid suffix
TestCase("9R12"), // invalid space
//TestCase("9 R12"), // allowed, as xs:token already combines multiple whitespaces
]
public void TestInvalidWheelsDimensionString(string dim)
{
var reader = XmlReader.Create(SampleTyreXML);
var doc = new XmlDocument();
doc.Load(reader);
var nav = doc.CreateNavigator();
var manager = new XmlNamespaceManager(nav.NameTable);
var helper = new XPathHelper(ExecutionMode.Declaration);
helper.AddNamespaces(manager);
var tyredimensionNode = nav.SelectSingleNode(XMLHelper.QueryLocalName(XMLNames.AxleWheels_Axles_Axle_Dimension));
tyredimensionNode.SetValue(dim);
var modified = XmlReader.Create(new StringReader(nav.OuterXml));
var validator = new XMLValidator(modified, null, XMLValidator.CallBackExceptionOnError);
AssertHelper.Exception<VectoException>(() => validator.ValidateXML(XmlDocumentType.DeclarationComponentData), messageContains: "Validation error:");
}
[TestCase]
public void TestPTOTypeTypes()
{
......
......@@ -105,6 +105,12 @@ namespace TUGraz.VectoCore.Tests.XML
ReadDeclarationJob(jobFile);
}
[TestCase(@"SchemaVersion2.1\vecto_vehicle-tyre25.xml")]
public void TestReadingJobVersion_V21_Tyre25(string jobFile)
{
ReadDeclarationJob(jobFile);
}
[TestCase(@"SchemaVersion2.2\Tractor_4x2_vehicle-class-5_5_t_0.xml")]
public void TestReadingJobVersion_V22(string jobFile)
{
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment