1+ using Microsoft . VisualStudio . TestTools . UnitTesting ;
2+ using System . Collections . Generic ;
3+ using Aml . Engine . CAEX ;
4+ using Aml . Engine . CAEX . Extensions ;
5+ using System . Linq ;
6+ using System ;
7+ using Opc . Ua ;
8+
9+ namespace SystemTest
10+ {
11+ [ TestClass ]
12+ public class TestStructureFieldDefinition
13+ {
14+ CAEXDocument m_document = null ;
15+
16+ #region Tests
17+ private const uint PublisherQosDataType = 3006 ;
18+
19+ [ TestMethod , Timeout ( TestHelper . UnitTestTimeout ) ]
20+ [ DataRow ( TestHelper . Uris . Root , Opc . Ua . DataTypes . AggregateConfiguration , DisplayName = "Root AggregateConfiguration" ) ]
21+ [ DataRow ( TestHelper . Uris . Test , PublisherQosDataType , DisplayName = "AutomationComponent PublisherQosDataType" ) ]
22+
23+ public void TestUnwantedAttributes ( TestHelper . Uris uriId , uint nodeId )
24+ {
25+ AttributeFamilyType objectToTest = GetTestAttribute ( uriId , nodeId ) ;
26+
27+ foreach ( AttributeType attribute in objectToTest . Attribute )
28+ {
29+ if ( attribute . Name != "NodeId" )
30+ {
31+ AttributeType structureAttribute = GetAttribute ( attribute , "StructureFieldDefinition" ) ;
32+ foreach ( AttributeType definitionAttribute in structureAttribute . Attribute )
33+ {
34+ // Make sure there is no NodeId for the StructureFieldDefinition
35+ // It's always Opc.Ua.DataTypes.StructureField (101)
36+ Assert . IsFalse ( definitionAttribute . Name . Contains ( "NodeId" ) ) ;
37+ // Make sure the structure field does not have a NodeId either.
38+ // It's always the known datatype of the field.
39+ Assert . IsNull ( definitionAttribute . Attribute [ "NodeId" ] ) ;
40+ if ( definitionAttribute . Name . Equals ( "Description" ) )
41+ {
42+ // Make sure there is no structure field Definition.
43+ // It's always a known datatype of localized text
44+ Assert . IsNull ( definitionAttribute . Attribute [ "StructureFieldDefinition" ] ,
45+ "Unexpected StructureFieldDefinition found in Description: " + structureAttribute . Name ) ;
46+ }
47+ }
48+ }
49+ }
50+ }
51+
52+ [ TestMethod , Timeout ( TestHelper . UnitTestTimeout ) ]
53+ [ DataRow ( "QosCategory" , "Name" , "QosCategory" ) ]
54+ [ DataRow ( "QosCategory" , "Description" , "Quality of Service Category" ) ]
55+ [ DataRow ( "QosCategory" , "ValueRank" , "-1" ) ]
56+ [ DataRow ( "QosCategory" , "ArrayDimensions" , null ) ]
57+ [ DataRow ( "QosCategory" , "MaxStringLength" , "123" ) ]
58+ [ DataRow ( "QosCategory" , "IsOptional" , "true" ) ]
59+ [ DataRow ( "QosCategory" , "AllowSubtypes" , "false" ) ]
60+
61+ [ DataRow ( "DatagramQos" , "Name" , "DatagramQos" ) ]
62+ [ DataRow ( "DatagramQos" , "Description" , "Transmit Quality of Service" ) ]
63+ [ DataRow ( "DatagramQos" , "ValueRank" , "2" ) ]
64+ [ DataRow ( "DatagramQos" , "MaxStringLength" , "0" ) ]
65+ [ DataRow ( "DatagramQos" , "IsOptional" , "false" ) ]
66+ [ DataRow ( "DatagramQos" , "AllowSubtypes" , "true" ) ]
67+
68+ [ DataRow ( "NoDescription" , "Name" , "NoDescription" ) ]
69+ [ DataRow ( "NoDescription" , "Description" , null ) ]
70+ [ DataRow ( "NoDescription" , "ValueRank" , "-1" ) ]
71+ [ DataRow ( "NoDescription" , "ArrayDimensions" , null ) ]
72+ [ DataRow ( "NoDescription" , "MaxStringLength" , "321" ) ]
73+ [ DataRow ( "NoDescription" , "IsOptional" , "false" ) ]
74+ [ DataRow ( "NoDescription" , "AllowSubtypes" , "false" ) ]
75+
76+ public void TestAttributeValues ( string variableName ,
77+ string attributeName ,
78+ string expectedValue )
79+ {
80+ AttributeValues ( variableName , attributeName , expectedValue ) ;
81+ }
82+
83+ [ TestMethod , Timeout ( TestHelper . UnitTestTimeout ) ]
84+ public void TestDescriptionLocale ( )
85+ {
86+ AttributeValues ( "QosCategory" , "Description" , "Quality of Service Category" , "en" ) ;
87+ }
88+
89+ [ TestMethod , Timeout ( TestHelper . UnitTestTimeout ) ]
90+ public void TestArrayDimensions ( )
91+ {
92+ AttributeType structured = GetStructured ( TestHelper . Uris . Test ,
93+ PublisherQosDataType , "DatagramQos" ) ;
94+ AttributeType attribute = GetAttribute ( structured , "ArrayDimensions" ) ;
95+ AttributeType first = GetAttribute ( attribute , "0" ) ;
96+ Assert . AreEqual ( "2" , first . Value , "Unexpected value for ArrayDimensions[0]." ) ;
97+ AttributeType second = GetAttribute ( attribute , "1" ) ;
98+ Assert . AreEqual ( "3" , second . Value , "Unexpected value for ArrayDimensions[1]." ) ;
99+ }
100+
101+ public void AttributeValues ( string variableName ,
102+ string attributeName ,
103+ string expectedValue ,
104+ string localeId = "" )
105+ {
106+ AttributeFamilyType objectToTest = GetTestAttribute ( TestHelper . Uris . Test ,
107+ PublisherQosDataType ) ;
108+
109+ AttributeType variableAttribute = GetAttribute ( objectToTest . Attribute , variableName ) ;
110+ AttributeType structured = GetAttribute ( variableAttribute , "StructureFieldDefinition" ) ;
111+ AttributeType attribute = GetAttribute ( structured . Attribute , attributeName ) ;
112+ Assert . AreEqual ( expectedValue , attribute . Value ,
113+ $ "Unexpected value for { variableName } .{ attributeName } in { structured . Name } .") ;
114+
115+ if ( ! string . IsNullOrEmpty ( localeId ) )
116+ {
117+ AttributeType locale = GetAttribute ( attribute . Attribute , localeId ) ;
118+ Assert . AreEqual ( expectedValue , locale . Value ,
119+ $ "Unexpected locale value for { variableName } .{ attributeName } in { structured . Name } .") ;
120+ }
121+ }
122+
123+
124+
125+ #endregion
126+
127+ #region Helpers
128+
129+ private CAEXDocument GetDocument ( )
130+ {
131+ if ( m_document == null )
132+ {
133+ m_document = TestHelper . GetReadOnlyDocument ( "TestAml.xml.amlx" ) ;
134+ }
135+ Assert . IsNotNull ( m_document , "Unable to retrieve Document" ) ;
136+ return m_document ;
137+ }
138+
139+ public AttributeFamilyType GetTestAttribute ( TestHelper . Uris uriId , uint nodeId )
140+ {
141+ CAEXDocument document = GetDocument ( ) ;
142+ string amlId = TestHelper . BuildAmlId ( "" , uriId , nodeId . ToString ( ) ) ;
143+ Console . WriteLine ( "Looking for " + amlId ) ;
144+ CAEXObject initialObject = document . FindByID ( amlId ) ;
145+ Assert . IsNotNull ( initialObject , "Unable to find Initial Object" ) ;
146+ AttributeFamilyType theObject = initialObject as AttributeFamilyType ;
147+ Assert . IsNotNull ( theObject , "Unable to Cast Initial Object" ) ;
148+ return theObject ;
149+ }
150+
151+ public AttributeType GetAttribute ( AttributeType attributeType , string attributeName )
152+ {
153+ Assert . IsNotNull ( attributeType , "AttributeType is null" ) ;
154+ return GetAttribute ( attributeType . Attribute , attributeName ) ;
155+ }
156+
157+ public AttributeType GetAttribute ( AttributeSequence attributes , string attributeName )
158+ {
159+ Assert . IsNotNull ( attributes , "AttributeType is null" ) ;
160+ AttributeType result = attributes [ attributeName ] ;
161+ Assert . IsNotNull ( result , "Unable to find Attribute " + attributeName ) ;
162+ return result ;
163+ }
164+
165+ public AttributeType GetStructured ( TestHelper . Uris uriId , uint nodeId , string variableName )
166+ {
167+ AttributeFamilyType objectToTest = GetTestAttribute ( uriId , nodeId ) ;
168+ AttributeType variableAttribute = GetAttribute ( objectToTest . Attribute , variableName ) ;
169+ AttributeType structured = GetAttribute ( variableAttribute , "StructureFieldDefinition" ) ;
170+ return structured ;
171+ }
172+
173+ #endregion
174+ }
175+ }
0 commit comments