Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion NodeSetToAML.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2627,7 +2627,19 @@ private void ProcessReferenceType(ref InterfaceClassLibType icl, NodeId nodeId)
OverrideBooleanAttribute(added.Attribute, "Symmetric", refnode.Symmetric);

if (refnode.InverseName != null)
AddModifyAttribute(added.Attribute, "InverseName", "LocalizedText", refnode.InverseName[0].Value);
{
AttributeType inverseNameAttribute = AddModifyAttribute(added.Attribute,
"InverseName", "LocalizedText", refnode.InverseName[0].Value);

if ( inverseNameAttribute != null )
{
AttributeType unwantedNodeIdAttribute = inverseNameAttribute.Attribute["NodeId"];
if ( unwantedNodeIdAttribute != null )
{
inverseNameAttribute.Attribute.RemoveElement(unwantedNodeIdAttribute);
}
}
}

OverrideAttribute(added, IsSource, "xs:boolean", true);
OverrideAttribute(added, RefClassConnectsToPath, "xs:string", (inverseAdded != null ? inverseAdded.CAEXPath() : added.CAEXPath()));
Expand Down
49 changes: 48 additions & 1 deletion SystemTest/TestHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,38 @@
using System.IO;
using System.IO.Compression;
using System.Linq;
using System.Net;

namespace SystemTest
{
internal class TestHelper
public class TestHelper
{
public const string ExtractPrefix = "Extract_";
public const string Opc2AmlName = "Opc2AmlConsole";
public const string Opc2Aml = Opc2AmlName + ".exe";

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

public enum Uris
{
Root,
Di,
Data,
Ac,
Test,
AmlFxTest
}

public static readonly Dictionary<Uris, string> UriMap = new Dictionary<Uris, string>()
{
{ Uris.Root, "http://opcfoundation.org/UA/"},
{ Uris.Di, "http://opcfoundation.org/UA/DI/"},
{ Uris.Data, "http://opcfoundation.org/UA/FX/Data/"},
{ Uris.Ac, "http://opcfoundation.org/UA/FX/AC/"},
{ Uris.Test, TestHelper.TestAmlUri },
{ Uris.AmlFxTest, "http://opcfoundation.org/UA/FX/AML/TESTING/AmlFxTest/"}
};

public const int UnitTestTimeout = 480000;

static bool Executed = false;
Expand Down Expand Up @@ -297,5 +318,31 @@ static public bool WriteFile(string fileName, List<string> lines)
return success;
}

static public string GetUri( Uris uriEnum )
{
string uri = string.Empty;

TestHelper.UriMap.TryGetValue(uriEnum, out uri);

return uri;
}

static public string BuildAmlId( string prefix, Uris uriEnum, string numericNodeId )
{
string uri = TestHelper.GetUri( uriEnum );
Assert.IsFalse(string.IsNullOrEmpty(uri));
Assert.IsFalse(string.IsNullOrEmpty(numericNodeId));

string workingId = string.Empty;
if (!string.IsNullOrEmpty(prefix))
{
workingId = prefix + ";";
}

string unencoded = workingId + "nsu=" + uri + ";i=" + numericNodeId;

return WebUtility.UrlEncode(unencoded);
}

}
}
118 changes: 118 additions & 0 deletions SystemTest/TestInverseNameNodeId.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
using System.IO;
using Aml.Engine.AmlObjects;
using Aml.Engine.CAEX;
using Aml.Engine.CAEX.Extensions;
using Opc.Ua;
using Microsoft.VisualStudio.TestPlatform.ObjectModel;


namespace SystemTest
{
[TestClass]
public class TestInverseNameNodeId
{
// Test is to address issue 94 -
// The Namespaces of BrowseNames differ between the generated AML file and the original Nodeset file.
// Test Both NodeId NamespaceUris and BrowseNameUris

private const string FxIdPrefix = "nsu%3Dhttp%3A%2F%2Fopcfoundation.org%2FUA%2FFX%2FAC%2F%3Bi%3D";
private const string AmlFxTestPrefix = "nsu%3Dhttp%3A%2F%2Fopcfoundation.org%2FUA%2FFX%2FAML%2FTESTING%2FAmlFxTest%2F%3Bi%3D";
public const string TestAmlUri = "http://opcfoundation.org/UA/FX/AML/TESTING/AmlFxTest/";
private const string FxAcUri = "http://opcfoundation.org/UA/FX/AC/";
private const string DiUri = "http://opcfoundation.org/UA/DI/";

CAEXDocument m_document = null;

#region Tests

[TestMethod]
public void TestAll()
{
CAEXDocument document = GetDocument();

int counter = 0;
foreach( InterfaceClassLibType classLibType in document.InterfaceClassLib )
{
foreach( InterfaceFamilyType interfaceType in classLibType )
{
AttributeType inverse = interfaceType.Attribute["InverseName"];
if ( inverse != null )
{
Assert.IsNull(inverse.Attribute["NodeId"]);
counter++;
}
}
}
Console.WriteLine("Tested " + counter.ToString() + " interface types");
}

[TestMethod, Timeout(TestHelper.UnitTestTimeout)]
[DataRow("41", TestHelper.Uris.Root, DisplayName = "GeneratesEvent")]
// [DataRow("6467", TestHelper.Uris.Di, DisplayName = "ConnectsToParent = Does not have inverse name!")]
[DataRow("6031", TestHelper.Uris.Di, DisplayName = "IsOnline")]
[DataRow("35", TestHelper.Uris.Ac, DisplayName = "HasPart")]

public void TestInterfaceEntity(string nodeId, TestHelper.Uris uriEnum)
{
InterfaceFamilyType testObject = GetTestObject( nodeId, uriEnum );

// Node Id Attribute should be correct.
AttributeType nodeIdAttribute = GetAttribute(testObject.Attribute, "NodeId");
AttributeType root = GetAttribute(nodeIdAttribute.Attribute, "RootNodeId");

Assert.AreEqual(
TestHelper.GetUri(uriEnum),
GetAttributeValue(root.Attribute, "NamespaceUri"));

Assert.AreEqual( nodeId, GetAttributeValue(root.Attribute, "NumericId"));

AttributeType inverse = GetAttribute(testObject.Attribute, "InverseName");

// Inverse Name should not have nodeId
Assert.IsNull(inverse.Attribute["NodeId"], "Inverse Name should not have a nodeId");
}

#endregion

#region Helpers

public string GetAttributeValue(AttributeSequence sequence, string attributeName)
{
AttributeType attribute = GetAttribute( sequence, attributeName );
Assert.IsNotNull( attribute.Value );
return attribute.Value;
}

public AttributeType GetAttribute( AttributeSequence sequence, string attributeName )
{
AttributeType attribute = sequence[attributeName];
Assert.IsNotNull(attribute);
return attribute;
}

private CAEXDocument GetDocument()
{
if (m_document == null)
{
m_document = TestHelper.GetReadOnlyDocument("AmlFxTest.xml.amlx");
}
Assert.IsNotNull(m_document, "Unable to retrieve Document");
return m_document;
}

public InterfaceFamilyType GetTestObject(string nodeId, TestHelper.Uris uriEnum)
{
CAEXDocument document = GetDocument();
string id = TestHelper.BuildAmlId( "f", uriEnum, nodeId);
CAEXObject initialObject = document.FindByID(id);
Assert.IsNotNull(initialObject, "Unable to find Initial Object");
InterfaceFamilyType theObject = initialObject as InterfaceFamilyType;
Assert.IsNotNull(theObject, "Unable to Cast Initial Object");
return theObject;
}

#endregion
}
}