Skip to content

Commit 4485956

Browse files
Remove NodeId from Interface Inverse Name (#106)
1 parent 02b91ce commit 4485956

File tree

3 files changed

+179
-2
lines changed

3 files changed

+179
-2
lines changed

NodeSetToAML.cs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2634,7 +2634,19 @@ private void ProcessReferenceType(ref InterfaceClassLibType icl, NodeId nodeId)
26342634
OverrideBooleanAttribute(added.Attribute, "Symmetric", refnode.Symmetric);
26352635

26362636
if (refnode.InverseName != null)
2637-
AddModifyAttribute(added.Attribute, "InverseName", "LocalizedText", refnode.InverseName[0].Value);
2637+
{
2638+
AttributeType inverseNameAttribute = AddModifyAttribute(added.Attribute,
2639+
"InverseName", "LocalizedText", refnode.InverseName[0].Value);
2640+
2641+
if ( inverseNameAttribute != null )
2642+
{
2643+
AttributeType unwantedNodeIdAttribute = inverseNameAttribute.Attribute["NodeId"];
2644+
if ( unwantedNodeIdAttribute != null )
2645+
{
2646+
inverseNameAttribute.Attribute.RemoveElement(unwantedNodeIdAttribute);
2647+
}
2648+
}
2649+
}
26382650

26392651
OverrideAttribute(added, IsSource, "xs:boolean", true);
26402652
OverrideAttribute(added, RefClassConnectsToPath, "xs:string", (inverseAdded != null ? inverseAdded.CAEXPath() : added.CAEXPath()));

SystemTest/TestHelper.cs

Lines changed: 48 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,38 @@
88
using System.IO;
99
using System.IO.Compression;
1010
using System.Linq;
11+
using System.Net;
1112

1213
namespace SystemTest
1314
{
14-
internal class TestHelper
15+
public class TestHelper
1516
{
1617
public const string ExtractPrefix = "Extract_";
1718
public const string Opc2AmlName = "Opc2AmlConsole";
1819
public const string Opc2Aml = Opc2AmlName + ".exe";
1920

2021
public const string TestAmlUri = "http://opcfoundation.org/UA/FX/AML/TESTING";
2122

23+
public enum Uris
24+
{
25+
Root,
26+
Di,
27+
Data,
28+
Ac,
29+
Test,
30+
AmlFxTest
31+
}
32+
33+
public static readonly Dictionary<Uris, string> UriMap = new Dictionary<Uris, string>()
34+
{
35+
{ Uris.Root, "http://opcfoundation.org/UA/"},
36+
{ Uris.Di, "http://opcfoundation.org/UA/DI/"},
37+
{ Uris.Data, "http://opcfoundation.org/UA/FX/Data/"},
38+
{ Uris.Ac, "http://opcfoundation.org/UA/FX/AC/"},
39+
{ Uris.Test, TestHelper.TestAmlUri },
40+
{ Uris.AmlFxTest, "http://opcfoundation.org/UA/FX/AML/TESTING/AmlFxTest/"}
41+
};
42+
2243
public const int UnitTestTimeout = 480000;
2344

2445
static bool Executed = false;
@@ -297,5 +318,31 @@ static public bool WriteFile(string fileName, List<string> lines)
297318
return success;
298319
}
299320

321+
static public string GetUri( Uris uriEnum )
322+
{
323+
string uri = string.Empty;
324+
325+
TestHelper.UriMap.TryGetValue(uriEnum, out uri);
326+
327+
return uri;
328+
}
329+
330+
static public string BuildAmlId( string prefix, Uris uriEnum, string numericNodeId )
331+
{
332+
string uri = TestHelper.GetUri( uriEnum );
333+
Assert.IsFalse(string.IsNullOrEmpty(uri));
334+
Assert.IsFalse(string.IsNullOrEmpty(numericNodeId));
335+
336+
string workingId = string.Empty;
337+
if (!string.IsNullOrEmpty(prefix))
338+
{
339+
workingId = prefix + ";";
340+
}
341+
342+
string unencoded = workingId + "nsu=" + uri + ";i=" + numericNodeId;
343+
344+
return WebUtility.UrlEncode(unencoded);
345+
}
346+
300347
}
301348
}
Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
using Microsoft.VisualStudio.TestTools.UnitTesting;
2+
using System;
3+
using System.IO;
4+
using Aml.Engine.AmlObjects;
5+
using Aml.Engine.CAEX;
6+
using Aml.Engine.CAEX.Extensions;
7+
using Opc.Ua;
8+
using Microsoft.VisualStudio.TestPlatform.ObjectModel;
9+
10+
11+
namespace SystemTest
12+
{
13+
[TestClass]
14+
public class TestInverseNameNodeId
15+
{
16+
// Test is to address issue 94 -
17+
// The Namespaces of BrowseNames differ between the generated AML file and the original Nodeset file.
18+
// Test Both NodeId NamespaceUris and BrowseNameUris
19+
20+
private const string FxIdPrefix = "nsu%3Dhttp%3A%2F%2Fopcfoundation.org%2FUA%2FFX%2FAC%2F%3Bi%3D";
21+
private const string AmlFxTestPrefix = "nsu%3Dhttp%3A%2F%2Fopcfoundation.org%2FUA%2FFX%2FAML%2FTESTING%2FAmlFxTest%2F%3Bi%3D";
22+
public const string TestAmlUri = "http://opcfoundation.org/UA/FX/AML/TESTING/AmlFxTest/";
23+
private const string FxAcUri = "http://opcfoundation.org/UA/FX/AC/";
24+
private const string DiUri = "http://opcfoundation.org/UA/DI/";
25+
26+
CAEXDocument m_document = null;
27+
28+
#region Tests
29+
30+
[TestMethod]
31+
public void TestAll()
32+
{
33+
CAEXDocument document = GetDocument();
34+
35+
int counter = 0;
36+
foreach( InterfaceClassLibType classLibType in document.InterfaceClassLib )
37+
{
38+
foreach( InterfaceFamilyType interfaceType in classLibType )
39+
{
40+
AttributeType inverse = interfaceType.Attribute["InverseName"];
41+
if ( inverse != null )
42+
{
43+
Assert.IsNull(inverse.Attribute["NodeId"]);
44+
counter++;
45+
}
46+
}
47+
}
48+
Console.WriteLine("Tested " + counter.ToString() + " interface types");
49+
}
50+
51+
[TestMethod, Timeout(TestHelper.UnitTestTimeout)]
52+
[DataRow("41", TestHelper.Uris.Root, DisplayName = "GeneratesEvent")]
53+
// [DataRow("6467", TestHelper.Uris.Di, DisplayName = "ConnectsToParent = Does not have inverse name!")]
54+
[DataRow("6031", TestHelper.Uris.Di, DisplayName = "IsOnline")]
55+
[DataRow("35", TestHelper.Uris.Ac, DisplayName = "HasPart")]
56+
57+
public void TestInterfaceEntity(string nodeId, TestHelper.Uris uriEnum)
58+
{
59+
InterfaceFamilyType testObject = GetTestObject( nodeId, uriEnum );
60+
61+
// Node Id Attribute should be correct.
62+
AttributeType nodeIdAttribute = GetAttribute(testObject.Attribute, "NodeId");
63+
AttributeType root = GetAttribute(nodeIdAttribute.Attribute, "RootNodeId");
64+
65+
Assert.AreEqual(
66+
TestHelper.GetUri(uriEnum),
67+
GetAttributeValue(root.Attribute, "NamespaceUri"));
68+
69+
Assert.AreEqual( nodeId, GetAttributeValue(root.Attribute, "NumericId"));
70+
71+
AttributeType inverse = GetAttribute(testObject.Attribute, "InverseName");
72+
73+
// Inverse Name should not have nodeId
74+
Assert.IsNull(inverse.Attribute["NodeId"], "Inverse Name should not have a nodeId");
75+
}
76+
77+
#endregion
78+
79+
#region Helpers
80+
81+
public string GetAttributeValue(AttributeSequence sequence, string attributeName)
82+
{
83+
AttributeType attribute = GetAttribute( sequence, attributeName );
84+
Assert.IsNotNull( attribute.Value );
85+
return attribute.Value;
86+
}
87+
88+
public AttributeType GetAttribute( AttributeSequence sequence, string attributeName )
89+
{
90+
AttributeType attribute = sequence[attributeName];
91+
Assert.IsNotNull(attribute);
92+
return attribute;
93+
}
94+
95+
private CAEXDocument GetDocument()
96+
{
97+
if (m_document == null)
98+
{
99+
m_document = TestHelper.GetReadOnlyDocument("AmlFxTest.xml.amlx");
100+
}
101+
Assert.IsNotNull(m_document, "Unable to retrieve Document");
102+
return m_document;
103+
}
104+
105+
public InterfaceFamilyType GetTestObject(string nodeId, TestHelper.Uris uriEnum)
106+
{
107+
CAEXDocument document = GetDocument();
108+
string id = TestHelper.BuildAmlId( "f", uriEnum, nodeId);
109+
CAEXObject initialObject = document.FindByID(id);
110+
Assert.IsNotNull(initialObject, "Unable to find Initial Object");
111+
InterfaceFamilyType theObject = initialObject as InterfaceFamilyType;
112+
Assert.IsNotNull(theObject, "Unable to Cast Initial Object");
113+
return theObject;
114+
}
115+
116+
#endregion
117+
}
118+
}

0 commit comments

Comments
 (0)