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