From 81c3d2e825cc0cc3e665b03a5e0728dc2a533683 Mon Sep 17 00:00:00 2001 From: Archie Miller <62433534+Archie-Miller@users.noreply.github.com> Date: Thu, 28 Nov 2024 10:39:01 -0700 Subject: [PATCH 1/5] Investigation --- NodeSetToAML.cs | 92 +++++++++++++++++-- Opc2AmlConsole/Properties/launchSettings.json | 3 +- SystemTest/NodeSetFiles/TestAml.xml | 8 +- 3 files changed, 91 insertions(+), 12 deletions(-) diff --git a/NodeSetToAML.cs b/NodeSetToAML.cs index ec93bb2..f6a2939 100644 --- a/NodeSetToAML.cs +++ b/NodeSetToAML.cs @@ -586,22 +586,94 @@ private void AddBaseNodeClassAttributes( AttributeSequence seq, UANode uanode, U uriatt.Value = myuri; } - if (uanode.DisplayName != null && - uanode.DisplayName.Length > 0 && - uanode.DisplayName[0].Value != uanode.DecodedBrowseName.Name) + if ( uanode.BrowseName.Equals( "1:Test_ConnectorType" ) ) { - AddModifyAttribute(seq, "DisplayName", "LocalizedText", - uanode.DisplayName[0].Value); + bool gonnaWait = true; } - if (uanode.Description != null && - uanode.Description.Length > 0 && - uanode.Description[0].Value.Length > 0) + if( uanode.DisplayName != null ) { - AddModifyAttribute(seq, "Description", "LocalizedText", - uanode.Description[0].Value); + if ( uanode.DisplayName.Length > 1 ) + { + List names = new List(); + foreach( NodeSet.LocalizedText lt in uanode.DisplayName) + { + names.Add(lt.Value); + } + + AddModifyAttribute( seq, "DisplayName", "LocalizedText", + new Variant(names), bListOf:true ); + + AttributeType displayNameAttribute = seq[ "DisplayName" ]; + if ( displayNameAttribute != null ) + { + for( int index = 0; index < uanode.DisplayName.Length; index++ ) + { + if ( !String.IsNullOrEmpty( uanode.DisplayName[ index ].Locale ) ) + { + AttributeType indexed = displayNameAttribute.Attribute[ index.ToString() ]; + if( indexed != null ) + { + AddModifyAttribute( indexed.Attribute, "Locale", "String", + uanode.DisplayName[ index ].Locale ); + } + } + } + + } + } + else if( uanode.DisplayName.Length > 0 && + uanode.DisplayName[ 0 ].Value != uanode.DecodedBrowseName.Name ) + { + AddModifyAttribute( seq, "DisplayName", "LocalizedText", + uanode.DisplayName[ 0 ].Value ); + } } + if( uanode.Description != null ) + { + if ( uanode.Description.Length > 1 ) + { + AttributeType descriptionAttribute = AddModifyAttribute( seq, "Description", "LocalizedText", + new Variant(), bListOf: true ); + + if( descriptionAttribute != null ) + { + for( int index = 0; index < uanode.Description.Length; index++ ) + { + AttributeType indexed = AddModifyAttribute( + descriptionAttribute.Attribute, index.ToString(), "LocalizedText", + new Variant() ); + + if( indexed != null ) + { + AddModifyAttribute( indexed.Attribute, "Value", "String", + uanode.Description[ index ].Value ); + if( !String.IsNullOrEmpty( uanode.Description[ index ].Locale ) ) + { + AddModifyAttribute( indexed.Attribute, "Locale", "String", + uanode.Description[ index ].Locale ); + } + } + } + } + } + else if( uanode.Description.Length > 0 && + uanode.Description[ 0 ].Value.Length > 0 ) + { + AddModifyAttribute( seq, "Description", "LocalizedText", + uanode.Description[ 0 ].Value ); + } + } + + //if( uanode.Description != null && + // uanode.Description.Length > 0 && + // uanode.Description[0].Value.Length > 0) + //{ + // AddModifyAttribute(seq, "Description", "LocalizedText", + // uanode.Description[0].Value); + //} + UAType uaType = uanode as UAType; if ( uaType != null && uaType.IsAbstract ) { diff --git a/Opc2AmlConsole/Properties/launchSettings.json b/Opc2AmlConsole/Properties/launchSettings.json index db1f0ae..71b4db4 100644 --- a/Opc2AmlConsole/Properties/launchSettings.json +++ b/Opc2AmlConsole/Properties/launchSettings.json @@ -1,7 +1,8 @@ { "profiles": { "Opc2AmlConsole": { - "commandName": "Project" + "commandName": "Project", + "commandLineArgs": "--Nodeset TestAml.xml" } } } \ No newline at end of file diff --git a/SystemTest/NodeSetFiles/TestAml.xml b/SystemTest/NodeSetFiles/TestAml.xml index 13c3d7d..627d90b 100644 --- a/SystemTest/NodeSetFiles/TestAml.xml +++ b/SystemTest/NodeSetFiles/TestAml.xml @@ -242,7 +242,13 @@ - Test Connector Type Display Name + Multiple Descriptions + Multiple Descriptions with Locale + Descriptions multiples avec paramètres régionaux + Mehrere Beschreibungen mit Gebietsschema + Test Connector Type Display Name + Type de connecteur de test Nom d'affichage + Anzeigename des Teststeckertyps i=58 ns=1;i=6014 From 955831c5fdf165d3c8efac1fb936e76b717f24ac Mon Sep 17 00:00:00 2001 From: Archie Miller <62433534+Archie-Miller@users.noreply.github.com> Date: Wed, 11 Dec 2024 09:28:03 -0700 Subject: [PATCH 2/5] Save Work in Progress --- NodeSetToAML.cs | 144 +++++++++++++++++----------- SystemTest/NodeSetFiles/TestAml.xml | 13 ++- 2 files changed, 100 insertions(+), 57 deletions(-) diff --git a/NodeSetToAML.cs b/NodeSetToAML.cs index f6a2939..40dfa59 100644 --- a/NodeSetToAML.cs +++ b/NodeSetToAML.cs @@ -586,94 +586,83 @@ private void AddBaseNodeClassAttributes( AttributeSequence seq, UANode uanode, U uriatt.Value = myuri; } - if ( uanode.BrowseName.Equals( "1:Test_ConnectorType" ) ) - { - bool gonnaWait = true; - } - if( uanode.DisplayName != null ) { if ( uanode.DisplayName.Length > 1 ) { - List names = new List(); - foreach( NodeSet.LocalizedText lt in uanode.DisplayName) - { - names.Add(lt.Value); - } - - AddModifyAttribute( seq, "DisplayName", "LocalizedText", - new Variant(names), bListOf:true ); + AddModifyAttribute( seq, "DisplayName", "LocalizedText", Variant.Null ); AttributeType displayNameAttribute = seq[ "DisplayName" ]; if ( displayNameAttribute != null ) { + string previousLocaleId = string.Empty; + string defaultLocaleId = GetLocaleId( uanode.DisplayName[ 0 ], ref previousLocaleId ); + AttributeType arrayRoot = AddModifyAttribute( displayNameAttribute.Attribute, defaultLocaleId, "String", + uanode.DisplayName[ 0 ].Value ); + + // Redo first element + previousLocaleId = string.Empty; for( int index = 0; index < uanode.DisplayName.Length; index++ ) { - if ( !String.IsNullOrEmpty( uanode.DisplayName[ index ].Locale ) ) - { - AttributeType indexed = displayNameAttribute.Attribute[ index.ToString() ]; - if( indexed != null ) - { - AddModifyAttribute( indexed.Attribute, "Locale", "String", - uanode.DisplayName[ index ].Locale ); - } - } + string localeId = GetLocaleId( uanode.DisplayName[ index ], ref previousLocaleId ); + AddModifyAttribute( arrayRoot.Attribute, "aml-lang=" + localeId, "String", uanode.DisplayName[ index ].Value ); } - } } else if( uanode.DisplayName.Length > 0 && uanode.DisplayName[ 0 ].Value != uanode.DecodedBrowseName.Name ) { - AddModifyAttribute( seq, "DisplayName", "LocalizedText", - uanode.DisplayName[ 0 ].Value ); + AddModifyAttribute( seq, "DisplayName", "LocalizedText", Variant.Null ); + AttributeType displayNameAttribute = seq[ "DisplayName" ]; + if( displayNameAttribute != null ) + { + string previousLocaleId = string.Empty; + string defaultLocaleId = GetLocaleId( uanode.DisplayName[ 0 ], ref previousLocaleId ); + AddModifyAttribute( displayNameAttribute.Attribute, defaultLocaleId, "String", + uanode.DisplayName[ 0 ].Value ); + } } } if( uanode.Description != null ) { - if ( uanode.Description.Length > 1 ) + if( uanode.Description.Length > 1 ) { - AttributeType descriptionAttribute = AddModifyAttribute( seq, "Description", "LocalizedText", - new Variant(), bListOf: true ); + AddModifyAttribute( seq, "Description", "LocalizedText", + new Variant() ); + AttributeType descriptionAttribute = seq[ "Description" ]; if( descriptionAttribute != null ) { + string previousLocaleId = string.Empty; + string defaultLocaleId = GetLocaleId( uanode.Description[ 0 ], ref previousLocaleId ); + AttributeType arrayRoot = AddModifyAttribute( descriptionAttribute.Attribute, defaultLocaleId, "String", + uanode.DisplayName[ 0 ].Value ); + + // Redo first element + previousLocaleId = string.Empty; for( int index = 0; index < uanode.Description.Length; index++ ) { - AttributeType indexed = AddModifyAttribute( - descriptionAttribute.Attribute, index.ToString(), "LocalizedText", - new Variant() ); - - if( indexed != null ) - { - AddModifyAttribute( indexed.Attribute, "Value", "String", - uanode.Description[ index ].Value ); - if( !String.IsNullOrEmpty( uanode.Description[ index ].Locale ) ) - { - AddModifyAttribute( indexed.Attribute, "Locale", "String", - uanode.Description[ index ].Locale ); - } - } + string localeId = GetLocaleId( uanode.Description[ index ], ref previousLocaleId ); + AddModifyAttribute( arrayRoot.Attribute, "aml-lang=" + localeId, "String", + uanode.Description[ index ].Value ); } } } - else if( uanode.Description.Length > 0 && - uanode.Description[ 0 ].Value.Length > 0 ) + else if( uanode.Description.Length > 0 ) { - AddModifyAttribute( seq, "Description", "LocalizedText", - uanode.Description[ 0 ].Value ); + AddModifyAttribute( seq, "Description", "LocalizedText", Variant.Null ); + AttributeType descriptionAttribute = seq[ "Description" ]; + if( descriptionAttribute != null ) + { + string previousLocaleId = string.Empty; + string defaultLocaleId = GetLocaleId( uanode.Description[ 0 ], ref previousLocaleId ); + AddModifyAttribute( descriptionAttribute.Attribute, defaultLocaleId, "String", + uanode.Description[ 0 ].Value ); + } } } - //if( uanode.Description != null && - // uanode.Description.Length > 0 && - // uanode.Description[0].Value.Length > 0) - //{ - // AddModifyAttribute(seq, "Description", "LocalizedText", - // uanode.Description[0].Value); - //} - UAType uaType = uanode as UAType; if ( uaType != null && uaType.IsAbstract ) { @@ -681,6 +670,53 @@ private void AddBaseNodeClassAttributes( AttributeSequence seq, UANode uanode, U } } + private string GetLocaleId( NodeSet.LocalizedText localizedText, ref string lastUnknownLocale ) + { + string localeId = string.Empty; + + if ( localizedText != null ) + { + if ( String.IsNullOrEmpty( localizedText.Locale ) ) + { + if ( String.IsNullOrEmpty( lastUnknownLocale ) ) + { + localeId = "qaa"; + } + else + { + if ( lastUnknownLocale.Length == 3 && lastUnknownLocale[0] == 'q' ) + { + char secondChar = lastUnknownLocale[1]; + char lastChar = lastUnknownLocale[ 2 ]; + if ( lastChar == 'z' ) + { + // It's pretty impractical to have 20*26 unknown locales for a single node. + if( secondChar < 't' ) + { + secondChar++; + localeId = "q" + secondChar + 'a'; + } + } + else + { + localeId = "q" + secondChar + (char)( lastChar + 1 ); + } + } + } + lastUnknownLocale = localeId; + } + else + { + localeId = localizedText.Locale; + } + + return localeId; + } + + return localeId; + } + + private AttributeType AddModifyAttribute(AttributeSequence seq, string name, string refDataType, Variant val, bool bListOf = false, string sURI = uaNamespaceURI) { string sUADataType = refDataType; diff --git a/SystemTest/NodeSetFiles/TestAml.xml b/SystemTest/NodeSetFiles/TestAml.xml index 627d90b..a58da53 100644 --- a/SystemTest/NodeSetFiles/TestAml.xml +++ b/SystemTest/NodeSetFiles/TestAml.xml @@ -2132,7 +2132,8 @@ - OneDimension + OneDimensionArray + A One Dimensional Array ns=1;i=5011 i=63 @@ -2153,7 +2154,10 @@ - TwoDimensions + TwoDimensionArray + aTwoDimensionalArray + A Different Two Dimension Array + Another Two Dimension Array ns=1;i=5011 i=63 @@ -2174,7 +2178,10 @@ - FiveDimensions + FiveDimensionArray + A Five DimensionArray + Another Five Dimension Array + ns=1;i=5011 i=63 From 4882c6d1c6d18b80025ac20480c014cad9fd1aff Mon Sep 17 00:00:00 2001 From: Archie Miller <62433534+Archie-Miller@users.noreply.github.com> Date: Fri, 13 Dec 2024 14:13:22 -0700 Subject: [PATCH 3/5] Setup Test file for testing --- SystemTest/NodeSetFiles/TestAml.xml | 113 +++++++++++++++++++++++++++- 1 file changed, 111 insertions(+), 2 deletions(-) diff --git a/SystemTest/NodeSetFiles/TestAml.xml b/SystemTest/NodeSetFiles/TestAml.xml index a58da53..6663cc6 100644 --- a/SystemTest/NodeSetFiles/TestAml.xml +++ b/SystemTest/NodeSetFiles/TestAml.xml @@ -3100,13 +3100,122 @@ + + Localized Text Attributes + + i=85 + i=61 + + + + + + i=63 + ns=1;i=5024 + + + + Attributes do not have display name or description + + + + + + Single Localized Text + A Single Description with no Locale + + i=63 + ns=1;i=5024 + + + + Attributes have display name and description, but no Locale + + + + + + Single Localized Text with Locale + A Single Description with a Locale + + i=63 + ns=1;i=5024 + + + + en + Attributes have display name and description with a single Locale + + + + + First DisplayName with no Locale + First Description with no Locale + Second DisplayName with a Locale + Second Description with a Locale + Troisième texte localisé avec paramètres régionaux + Troisième description avec un paramètre régional + Letzter lokalisierter Text mit Gebietsschema + Letzte Beschreibung mit einem Gebietsschema + + i=63 + ns=1;i=5024 + + + + en + Multiple DisplayNames and Descriptions, first without a Locale + + + + + + First DisplayName with a Locale + First Description with a Locale + Deuxième DisplayName avec une locale + Deuxième description avec une locale + Dritter DisplayName mit einem Gebietsschema + Dritte Beschreibung mit einem Gebietsschema + Last DisplayName with no Locale + Last Description with no Locale + + i=63 + ns=1;i=5024 + + + + en + Multiple DisplayNames and Descriptions, last without a Locale + + + + + First DisplayName with no Locale + First Description with no Locale + Second DisplayName with no Locale + Second Description with no Locale + Third DisplayName with no Locale + Third Description with no Locale + Last DisplayName with no Locale + Last Description with no Locale + + i=63 + ns=1;i=5024 + + + + Multiple DisplayNames and Descriptions, all without a Locale + + + + From 9f47dc95b7afd086cdb31992f6c01b47cc42309b Mon Sep 17 00:00:00 2001 From: Archie Miller <62433534+Archie-Miller@users.noreply.github.com> Date: Mon, 16 Dec 2024 16:04:36 -0700 Subject: [PATCH 4/5] Write test files Fix test files that were broken by accident --- NodeSetToAML.cs | 104 ++++++++---------- SystemTest/NodeSetFiles/TestAml.xml | 62 +++++++---- SystemTest/TestLocalizedText.cs | 159 ++++++++++++++++++++++++++++ 3 files changed, 242 insertions(+), 83 deletions(-) create mode 100644 SystemTest/TestLocalizedText.cs diff --git a/NodeSetToAML.cs b/NodeSetToAML.cs index 40dfa59..0939b44 100644 --- a/NodeSetToAML.cs +++ b/NodeSetToAML.cs @@ -586,87 +586,62 @@ private void AddBaseNodeClassAttributes( AttributeSequence seq, UANode uanode, U uriatt.Value = myuri; } - if( uanode.DisplayName != null ) + BuildLocalizedTextAttribute( seq, "DisplayName", uanode.DisplayName, + uanode.DecodedBrowseName.Name, ignoreEqual: true ); + BuildLocalizedTextAttribute( seq, "Description", uanode.Description, + uanode.DecodedBrowseName.Name, ignoreEqual: false ); + + UAType uaType = uanode as UAType; + if ( uaType != null && uaType.IsAbstract ) + { + AddModifyAttribute(seq, "IsAbstract", "Boolean", uaType.IsAbstract); + } + } + + private void BuildLocalizedTextAttribute( + AttributeSequence seq, + string attributeName, + NodeSet.LocalizedText[] localizedTexts, + string equalityString, bool ignoreEqual ) + { + if( localizedTexts != null ) { - if ( uanode.DisplayName.Length > 1 ) + if( localizedTexts.Length > 1 ) { - AddModifyAttribute( seq, "DisplayName", "LocalizedText", Variant.Null ); + AddModifyAttribute( seq, attributeName, "LocalizedText", localizedTexts[ 0 ].Value ); - AttributeType displayNameAttribute = seq[ "DisplayName" ]; - if ( displayNameAttribute != null ) + AttributeType displayNameAttribute = seq[ attributeName ]; + if( displayNameAttribute != null ) { string previousLocaleId = string.Empty; - string defaultLocaleId = GetLocaleId( uanode.DisplayName[ 0 ], ref previousLocaleId ); + string defaultLocaleId = GetLocaleId( localizedTexts[ 0 ], ref previousLocaleId ); AttributeType arrayRoot = AddModifyAttribute( displayNameAttribute.Attribute, defaultLocaleId, "String", - uanode.DisplayName[ 0 ].Value ); + localizedTexts[ 0 ].Value ); // Redo first element previousLocaleId = string.Empty; - for( int index = 0; index < uanode.DisplayName.Length; index++ ) + for( int index = 0; index < localizedTexts.Length; index++ ) { - string localeId = GetLocaleId( uanode.DisplayName[ index ], ref previousLocaleId ); - AddModifyAttribute( arrayRoot.Attribute, "aml-lang=" + localeId, "String", uanode.DisplayName[ index ].Value ); + string localeId = GetLocaleId( localizedTexts[ index ], ref previousLocaleId ); + AddModifyAttribute( arrayRoot.Attribute, "aml-lang=" + localeId, + "String", localizedTexts[ index ].Value ); } } } - else if( uanode.DisplayName.Length > 0 && - uanode.DisplayName[ 0 ].Value != uanode.DecodedBrowseName.Name ) - { - AddModifyAttribute( seq, "DisplayName", "LocalizedText", Variant.Null ); - AttributeType displayNameAttribute = seq[ "DisplayName" ]; - if( displayNameAttribute != null ) - { - string previousLocaleId = string.Empty; - string defaultLocaleId = GetLocaleId( uanode.DisplayName[ 0 ], ref previousLocaleId ); - AddModifyAttribute( displayNameAttribute.Attribute, defaultLocaleId, "String", - uanode.DisplayName[ 0 ].Value ); - } - } - } - - if( uanode.Description != null ) - { - if( uanode.Description.Length > 1 ) + else if( localizedTexts.Length > 0 ) { - AddModifyAttribute( seq, "Description", "LocalizedText", - new Variant() ); - - AttributeType descriptionAttribute = seq[ "Description" ]; - if( descriptionAttribute != null ) + NodeSet.LocalizedText localizedText = localizedTexts[ 0 ]; + if( ignoreEqual == false || + localizedText.Value != equalityString ) { - string previousLocaleId = string.Empty; - string defaultLocaleId = GetLocaleId( uanode.Description[ 0 ], ref previousLocaleId ); - AttributeType arrayRoot = AddModifyAttribute( descriptionAttribute.Attribute, defaultLocaleId, "String", - uanode.DisplayName[ 0 ].Value ); + AttributeType root = AddModifyAttribute( seq, attributeName, "LocalizedText", localizedText.Value ); - // Redo first element - previousLocaleId = string.Empty; - for( int index = 0; index < uanode.Description.Length; index++ ) + if( !String.IsNullOrEmpty( localizedText.Locale ) ) { - string localeId = GetLocaleId( uanode.Description[ index ], ref previousLocaleId ); - AddModifyAttribute( arrayRoot.Attribute, "aml-lang=" + localeId, "String", - uanode.Description[ index ].Value ); + AddModifyAttribute( root.Attribute, localizedText.Locale, "LocalizedText", localizedText.Value ); } } } - else if( uanode.Description.Length > 0 ) - { - AddModifyAttribute( seq, "Description", "LocalizedText", Variant.Null ); - AttributeType descriptionAttribute = seq[ "Description" ]; - if( descriptionAttribute != null ) - { - string previousLocaleId = string.Empty; - string defaultLocaleId = GetLocaleId( uanode.Description[ 0 ], ref previousLocaleId ); - AddModifyAttribute( descriptionAttribute.Attribute, defaultLocaleId, "String", - uanode.Description[ 0 ].Value ); - } - } - } - - UAType uaType = uanode as UAType; - if ( uaType != null && uaType.IsAbstract ) - { - AddModifyAttribute(seq, "IsAbstract", "Boolean", uaType.IsAbstract); } } @@ -716,7 +691,6 @@ private string GetLocaleId( NodeSet.LocalizedText localizedText, ref string last return localeId; } - private AttributeType AddModifyAttribute(AttributeSequence seq, string name, string refDataType, Variant val, bool bListOf = false, string sURI = uaNamespaceURI) { string sUADataType = refDataType; @@ -1018,7 +992,13 @@ private AttributeType AddModifyAttribute(AttributeSequence seq, string name, str if( localizedText != null && localizedText.Text != null ) { a.DefaultAttributeValue = a.AttributeValue = localizedText.Text; + if ( !string.IsNullOrEmpty( localizedText.Locale ) ) + { + AddModifyAttribute(a.Attribute, localizedText.Locale, + "String", localizedText.Text); + } } + break; } diff --git a/SystemTest/NodeSetFiles/TestAml.xml b/SystemTest/NodeSetFiles/TestAml.xml index 6663cc6..c411ce1 100644 --- a/SystemTest/NodeSetFiles/TestAml.xml +++ b/SystemTest/NodeSetFiles/TestAml.xml @@ -242,13 +242,7 @@ - Multiple Descriptions - Multiple Descriptions with Locale - Descriptions multiples avec paramètres régionaux - Mehrere Beschreibungen mit Gebietsschema - Test Connector Type Display Name - Type de connecteur de test Nom d'affichage - Anzeigename des Teststeckertyps + Test Connector Type Display Name i=58 ns=1;i=6014 @@ -3149,7 +3143,7 @@ - + First DisplayName with no Locale First Description with no Locale Second DisplayName with a Locale @@ -3163,14 +3157,23 @@ ns=1;i=5024 - - en - Multiple DisplayNames and Descriptions, first without a Locale - + + + Multiple + + + en + DisplayNames and Descriptions + + + en + first without a locale + + - + First DisplayName with a Locale First Description with a Locale Deuxième DisplayName avec une locale @@ -3184,14 +3187,23 @@ ns=1;i=5024 - - en - Multiple DisplayNames and Descriptions, last without a Locale - + + + en + Multiple + + + en + DisplayNames and Descriptions + + + last without a locale + + - + First DisplayName with no Locale First Description with no Locale Second DisplayName with no Locale @@ -3205,9 +3217,17 @@ ns=1;i=5024 - - Multiple DisplayNames and Descriptions, all without a Locale - + + + Multiple + + + DisplayNames and Descriptions + + + all without a locale + + diff --git a/SystemTest/TestLocalizedText.cs b/SystemTest/TestLocalizedText.cs new file mode 100644 index 0000000..f939186 --- /dev/null +++ b/SystemTest/TestLocalizedText.cs @@ -0,0 +1,159 @@ +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System.IO; +using Aml.Engine.AmlObjects; +using Aml.Engine.CAEX; +using Aml.Engine.CAEX.Extensions; +using Opc.Ua; +using static System.Net.Mime.MediaTypeNames; + + +namespace SystemTest +{ + [TestClass] + public class TestLocalizedText + { + CAEXDocument m_document = null; + + #region Tests + + [TestMethod] + [DataRow( "DisplayName", DisplayName = "No LocalizedText DisplayName" )] + [DataRow( "Description", DisplayName = "No LocalizedText Description" )] + public void NoLocalizedText( string attributeName ) + { + SystemUnitClassType objectToTest = GetTestObject( "6227" ); + AttributeType attributeType = objectToTest.Attribute[ attributeName ]; + Assert.IsNull( attributeType, "Unexpected attribute found for " + attributeName ); + } + + + [TestMethod] + [DataRow("6228", "DisplayName", "", "Single Localized Text", + DisplayName = "Single no Locale DisplayName")] + [DataRow( "6228", "Description", "", "A Single Description with no Locale", + DisplayName = "Single no Locale Description" )] + [DataRow( "6229", "DisplayName", "en", "Single Localized Text with Locale", + DisplayName = "Single with Locale DisplayName" )] + [DataRow( "6229", "Description", "en", "A Single Description with a Locale", + DisplayName = "Single with Locale Description" )] + public void SingleLocalizedText(string nodeId, string attributeName, string localeId, string text ) + { + SystemUnitClassType objectToTest = GetTestObject( nodeId ); + AttributeType attributeType = ValidateAttribute( objectToTest.Attribute, attributeName, text ); + + if( string.IsNullOrEmpty( localeId ) ) + { + Assert.AreEqual( 0, attributeType.Attribute.Count, 1 ); + } + else + { + ValidateAttribute( attributeType.Attribute, localeId, text ); + } + } + + [TestMethod] + [DataRow( "6230", "DisplayName", + new string[] { "qaa", "en", "fr", "de"}, + new string[] { + "First DisplayName with no Locale", + "Second DisplayName with a Locale", + "Troisième texte localisé avec paramètres régionaux", + "Letzter lokalisierter Text mit Gebietsschema" }, + DisplayName = "Multiple Starting with no Locale DisplayName" )] + [DataRow( "6230", "Description", + new string[] { "qaa", "en", "fr", "de" }, + new string[] { + "First Description with no Locale", + "Second Description with a Locale", + "Troisième description avec un paramètre régional", + "Letzte Beschreibung mit einem Gebietsschema" }, + DisplayName = "Multiple Starting with no Locale Description" )] + [DataRow( "6231", "DisplayName", + new string[] { "en", "fr", "de", "qaa"}, + new string[] { + "First DisplayName with a Locale", + "Deuxième DisplayName avec une locale", + "Dritter DisplayName mit einem Gebietsschema", + "Last DisplayName with no Locale" }, + DisplayName = "Multiple Ending with no Locale DisplayName" )] + [DataRow( "6231", "Description", + new string[] { "en", "fr", "de", "qaa" }, + new string[] { + "First Description with a Locale", + "Deuxième description avec une locale", + "Dritte Beschreibung mit einem Gebietsschema", + "Last Description with no Locale" }, + DisplayName = "Multiple Ending with no Locale Description" )] + + + [DataRow( "6232", "DisplayName", + new string[] { "qaa", "qab", "qac", "qad" }, + new string[] { + "First DisplayName with no Locale", + "Second DisplayName with no Locale", + "Third DisplayName with no Locale", + "Last DisplayName with no Locale" }, + DisplayName = "Multiple no Locale DisplayName" )] + [DataRow( "6232", "Description", + new string[] { "qaa", "qab", "qac", "qad" }, + new string[] { + "First Description with no Locale", + "Second Description with no Locale", + "Third Description with no Locale", + "Last Description with no Locale" }, + DisplayName = "Multiple no Locale Description" )] + public void MultipleLocalizedText( string nodeId, string attributeName, string[] localeId, string[] text ) + { + SystemUnitClassType objectToTest = GetTestObject( nodeId ); + AttributeType topLevel = ValidateAttribute( objectToTest.Attribute, attributeName, text[ 0 ] ); + AttributeType textLevel = ValidateAttribute( topLevel.Attribute, localeId[0], text[ 0 ] ); + + for( int index = 0; index < localeId.Length; index++ ) + { + string subLocale = "aml-lang=" + localeId[ index ]; + ValidateAttribute( textLevel.Attribute, subLocale, text[index] ); + } + } + + private AttributeType ValidateAttribute( AttributeSequence sequence, string attributeName, string attributeValue ) + { + Assert.IsNotNull( sequence, "AttributeSequence not found" ); + AttributeType attributeType = sequence[ attributeName ]; + Assert.IsNotNull( attributeType, attributeName + " attribute not found" ); + Assert.IsNotNull( attributeType.Value, attributeName + " attribute valid not found" ); + Assert.AreEqual( attributeValue, attributeType.Value, "Unexpected value for " + attributeName ); + return attributeType; + } + + #endregion + + #region Helpers + + private CAEXDocument GetDocument() + { + if( m_document == null ) + { + m_document = TestHelper.GetReadOnlyDocument( "TestAml.xml.amlx" ); + } + Assert.IsNotNull( m_document, "Unable to retrieve Document" ); + return m_document; + } + + public SystemUnitClassType GetTestObject(string nodeId, bool foundationRoot = false) + { + CAEXDocument document = GetDocument(); + string rootName = TestHelper.GetRootName(); + if ( foundationRoot ) + { + rootName = TestHelper.GetOpcRootName(); + } + CAEXObject initialObject = document.FindByID(rootName + nodeId); + Assert.IsNotNull(initialObject, "Unable to find Initial Object"); + SystemUnitClassType theObject = initialObject as SystemUnitClassType; + Assert.IsNotNull(theObject, "Unable to Cast Initial Object"); + return theObject; + } + + #endregion + } +} From 3ef514d6437c29bfb1296dace0a8883565aac6cc Mon Sep 17 00:00:00 2001 From: Archie Miller <62433534+Archie-Miller@users.noreply.github.com> Date: Mon, 16 Dec 2024 16:42:06 -0700 Subject: [PATCH 5/5] Testing complete for Localized Texts --- SystemTest/NodeSetFiles/TestAml.xml | 5 -- SystemTest/TestLocalizedText.cs | 72 +++++++++++++++++++++++++++++ 2 files changed, 72 insertions(+), 5 deletions(-) diff --git a/SystemTest/NodeSetFiles/TestAml.xml b/SystemTest/NodeSetFiles/TestAml.xml index c411ce1..06e97ef 100644 --- a/SystemTest/NodeSetFiles/TestAml.xml +++ b/SystemTest/NodeSetFiles/TestAml.xml @@ -3107,11 +3107,6 @@ i=63 ns=1;i=5024 - - - Attributes do not have display name or description - - diff --git a/SystemTest/TestLocalizedText.cs b/SystemTest/TestLocalizedText.cs index f939186..c5934a6 100644 --- a/SystemTest/TestLocalizedText.cs +++ b/SystemTest/TestLocalizedText.cs @@ -16,6 +16,78 @@ public class TestLocalizedText #region Tests + [TestMethod] + public void TestNoValue( ) + { + SystemUnitClassType objectToTest = GetTestObject( "6227" ); + AttributeType attributeType = objectToTest.Attribute[ "Value" ]; + Assert.IsNotNull( attributeType ); + Assert.IsNull( attributeType.Value, "Unexpected Value found" ); + } + + [TestMethod] + [DataRow( "6228", "", "Attributes have display name and description, but no Locale", + DisplayName = "Single value no Locale" )] + [DataRow( "6229", "en", "Attributes have display name and description with a single Locale", + DisplayName = "Single value with Locale" )] + public void TestScalarValue( string node, string locale, string text ) + { + SystemUnitClassType objectToTest = GetTestObject( node ); + AttributeType value = ValidateAttribute( objectToTest.Attribute, "Value", text ); + + if( string.IsNullOrEmpty( locale ) ) + { + Assert.AreEqual( 0, value.Attribute.Count ); + } + else + { + ValidateAttribute( value.Attribute, locale, text ); + } + } + + [TestMethod] + [DataRow( "6230", new string[] { "", "en", "en" }, + new string[] { + "Multiple", + "DisplayNames and Descriptions", + "first without a locale" }, + DisplayName = "Multiple Starting with no Locale" )] + + [DataRow( "6231", new string[] { "en", "en", "" }, + new string[] { + "Multiple", + "DisplayNames and Descriptions", + "last without a locale" }, + DisplayName = "Multiple Ending with no Locale" )] + + [DataRow( "6232", new string[] { "", "", "" }, + new string[] { + "Multiple", + "DisplayNames and Descriptions", + "all without a locale" }, + DisplayName = "Multiple all without no Locale" )] + + public void TestArrayValue( string node, string[] locales, string[] values ) + { + SystemUnitClassType objectToTest = GetTestObject( node ); + AttributeType attributeType = objectToTest.Attribute[ "Value" ]; + Assert.IsNotNull( attributeType ); + Assert.IsNull( attributeType.Value, "Unexpected Value found" ); + + for( int index = 0; index < locales.Length; index++ ) + { + AttributeType indexed = ValidateAttribute( attributeType.Attribute, index.ToString(), values[ index ] ); + if( string.IsNullOrEmpty( locales[ index ] ) ) + { + Assert.AreEqual( 0, indexed.Attribute.Count, "Unexpected Locale found" ); + } + else + { + ValidateAttribute( indexed.Attribute, locales[ index ], values[ index ] ); + } + } + } + [TestMethod] [DataRow( "DisplayName", DisplayName = "No LocalizedText DisplayName" )] [DataRow( "Description", DisplayName = "No LocalizedText Description" )]