-
Notifications
You must be signed in to change notification settings - Fork 93
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #170 from bevanweiss/nullids_remastered
OPC-UA Spec has a number of 'null' NodeId values.
- Loading branch information
Showing
8 changed files
with
331 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<OutputType>Exe</OutputType> | ||
<TargetFramework>net8.0</TargetFramework> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
<Nullable>enable</Nullable> | ||
<DebugType>pdbonly</DebugType> | ||
<DebugSymbols>true</DebugSymbols> | ||
<ProduceReferenceAssembly>True</ProduceReferenceAssembly> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="BenchmarkDotNet" Version="0.13.12" /> | ||
<PackageReference Include="BenchmarkDotNet.Diagnostics.Windows" Version="0.13.12" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\LibUA\LibUA.csproj" /> | ||
</ItemGroup> | ||
|
||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
using BenchmarkDotNet.Attributes; | ||
using LibUA.Core; | ||
|
||
namespace LibUA.Benchmarks | ||
{ | ||
[MarkdownExporter] | ||
[MemoryDiagnoser(false)] | ||
public class NodeId_Benchmarks | ||
{ | ||
public readonly static NodeId[] NullNodes = | ||
[ | ||
new NodeId(0,0), | ||
new NodeId(0, null, NodeIdNetType.String), | ||
new NodeId(0, string.Empty), | ||
new NodeId(0, null, NodeIdNetType.Guid), | ||
new NodeId(0, Guid.Empty.ToByteArray(), NodeIdNetType.Guid), | ||
new NodeId(0, null, NodeIdNetType.ByteString), | ||
new NodeId(0, [], NodeIdNetType.ByteString) | ||
]; | ||
|
||
public readonly static NodeId[] NumericNodes = | ||
[ | ||
new NodeId(2, 1), | ||
new NodeId(2, 100), | ||
new NodeId(2, 200), | ||
new NodeId(2, 300), | ||
new NodeId(2, 400), | ||
new NodeId(2, 500), | ||
new NodeId(2, 600), | ||
new NodeId(2, 700), | ||
new NodeId(2, 800), | ||
new NodeId(2, 900), | ||
new NodeId(2, 1000), | ||
]; | ||
|
||
public readonly static NodeId[] StringNodes = | ||
[ | ||
new NodeId(2, "Test String 1"), | ||
new NodeId(2, "Test String 2"), | ||
new NodeId(2, "Test String 3"), | ||
new NodeId(2, "Test String 4"), | ||
new NodeId(2, "Test String 5"), | ||
new NodeId(2, "Test String 6"), | ||
new NodeId(2, "Test String 7"), | ||
new NodeId(2, "Test String 8"), | ||
new NodeId(2, "Test String 9"), | ||
new NodeId(2, "Test String 10"), | ||
]; | ||
|
||
public readonly static NodeId[] GuidNodes = | ||
[ | ||
new NodeId(2, new Guid().ToByteArray(), NodeIdNetType.Guid), | ||
new NodeId(2, new Guid().ToByteArray(), NodeIdNetType.Guid), | ||
new NodeId(2, new Guid().ToByteArray(), NodeIdNetType.Guid), | ||
new NodeId(2, new Guid().ToByteArray(), NodeIdNetType.Guid), | ||
new NodeId(2, new Guid().ToByteArray(), NodeIdNetType.Guid), | ||
new NodeId(2, new Guid().ToByteArray(), NodeIdNetType.Guid), | ||
new NodeId(2, new Guid().ToByteArray(), NodeIdNetType.Guid), | ||
new NodeId(2, new Guid().ToByteArray(), NodeIdNetType.Guid), | ||
new NodeId(2, new Guid().ToByteArray(), NodeIdNetType.Guid), | ||
new NodeId(2, new Guid().ToByteArray(), NodeIdNetType.Guid), | ||
]; | ||
|
||
public readonly static NodeId[] ByteStringNodes = | ||
[ | ||
new NodeId(2, new byte[] { 0, 1, 2, 3 }, NodeIdNetType.Guid), | ||
new NodeId(2, new byte[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }, NodeIdNetType.Guid), | ||
new NodeId(2, new byte[] { 2, 1, 2, 3 }, NodeIdNetType.Guid), | ||
new NodeId(2, new byte[] { 0, 3, 2, 3 }, NodeIdNetType.Guid), | ||
new NodeId(2, new byte[] { 0, 1, 2, 1 }, NodeIdNetType.Guid), | ||
new NodeId(2, new byte[] { 0, 6, 2, 3, 7, 5, 6, 4, 255 }, NodeIdNetType.Guid), | ||
new NodeId(2, new byte[] { 0, 1, 8, 3 }, NodeIdNetType.Guid), | ||
new NodeId(2, new byte[] { 0, 9, 2, 3 }, NodeIdNetType.Guid), | ||
new NodeId(2, new byte[] { 0, 1, 2, 0, 1, 5, 6, 7 }, NodeIdNetType.Guid), | ||
]; | ||
|
||
public readonly static NodeId[] Nodes = | ||
[ | ||
.. NullNodes, | ||
.. StringNodes, | ||
.. GuidNodes, | ||
.. ByteStringNodes | ||
]; | ||
|
||
|
||
[Benchmark] | ||
public void NodeIdEquivalency() | ||
{ | ||
for(int i = 0; i < Nodes.Length; i++) | ||
{ | ||
for(int j = 0; j < Nodes.Length; j++) | ||
{ | ||
_ = Nodes[i].Equals(Nodes[j]); | ||
} | ||
} | ||
} | ||
|
||
[Benchmark] | ||
public void NodeIdAllocations() | ||
{ | ||
NodeId[] nodes = new NodeId[1_000_000]; | ||
for (int i = 0; i < 1_000_000; i++) | ||
{ | ||
nodes[i] = new NodeId(0, 0); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
using BenchmarkDotNet.Configs; | ||
using BenchmarkDotNet.Running; | ||
|
||
internal class Program | ||
{ | ||
private static void Main(string[] args) | ||
{ | ||
var summary = BenchmarkRunner.Run(typeof(Program).Assembly); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>net8.0</TargetFramework> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
<Nullable>enable</Nullable> | ||
<IsPackable>false</IsPackable> | ||
<IsTestProject>true</IsTestProject> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="coverlet.collector" Version="6.0.0" /> | ||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.8.0" /> | ||
<PackageReference Include="xunit" Version="2.5.3" /> | ||
<PackageReference Include="xunit.runner.visualstudio" Version="2.5.3" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\LibUA\LibUA.csproj" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<Using Include="Xunit" /> | ||
</ItemGroup> | ||
|
||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,118 @@ | ||
using LibUA.Core; | ||
|
||
namespace LibUA.Tests | ||
{ | ||
public class NodeId_Tests | ||
{ | ||
// OPC 10000-3: Address Space Model | ||
// 8.2.4 Identifier value | ||
// A canonical null NodeId has an IdType equal to Numeric, a NamespaceIndex equal to 0 and an | ||
// Identifier equal to 0. | ||
// | ||
// In addition to the canonical null NodeId the alternative values defined in Table 23 shall be | ||
// considered a null NodeId. | ||
// IdType NamespaceIndex Null Value | ||
// String 0 A null or Empty String(“”) | ||
// Guid 0 A Guid initialised with zeros(e.g. 00000000-0000-0000-0000-000000) | ||
// Opaque 0 A null or Empty ByteString | ||
[Fact] | ||
public void NodeId_NullEquivalence() | ||
{ | ||
NodeId nullNumeric = new NodeId(0, 0); | ||
NodeId nullString = new NodeId(0, null); | ||
NodeId emptyString = new NodeId(0, string.Empty); | ||
NodeId nullGuid = new NodeId(0, null, NodeIdNetType.Guid); | ||
NodeId emptyGuid = new NodeId(0, new Guid().ToByteArray(), NodeIdNetType.Guid); | ||
NodeId nullBytes = new NodeId(0, null, NodeIdNetType.ByteString); | ||
NodeId emptyBytes = new NodeId(0, new byte[0], NodeIdNetType.ByteString); | ||
|
||
Assert.Equal(nullNumeric, nullNumeric); | ||
Assert.Equal(nullNumeric, nullString); | ||
Assert.Equal(nullNumeric, emptyString); | ||
Assert.Equal(nullNumeric, nullGuid); | ||
Assert.Equal(nullNumeric, emptyGuid); | ||
Assert.Equal(nullNumeric, nullBytes); | ||
Assert.Equal(nullNumeric, emptyBytes); | ||
} | ||
|
||
[Fact] | ||
public void NodeId_NumericEquivalence() | ||
{ | ||
Assert.Equal(new NodeId(2, 100), new NodeId(2, 100)); | ||
} | ||
|
||
[Fact] | ||
public void NodeId_NumericNamespaceNonEquivalence() | ||
{ | ||
Assert.NotEqual(new NodeId(2, 100), new NodeId(3, 100)); | ||
} | ||
|
||
[Fact] | ||
public void NodeId_NumericValueNonEquivalence() | ||
{ | ||
Assert.NotEqual(new NodeId(2, 100), new NodeId(2, 101)); | ||
} | ||
|
||
[Fact] | ||
public void NodeId_StringEquivalence() | ||
{ | ||
Assert.Equal(new NodeId(2, "Test String"), new NodeId(2, "Test String")); | ||
} | ||
|
||
[Fact] | ||
public void NodeId_StringNamespaceNonEquivalence() | ||
{ | ||
Assert.NotEqual(new NodeId(2, "Test String"), new NodeId(3, "Test String")); | ||
} | ||
|
||
[Fact] | ||
public void NodeId_StringValueNonEquivalence() | ||
{ | ||
Assert.NotEqual(new NodeId(2, "Test String"), new NodeId(2, "Test String2")); | ||
} | ||
|
||
[Fact] | ||
public void NodeId_GuidEquivalence() | ||
{ | ||
var guid = new Guid(); | ||
var guid2 = new Guid(guid.ToByteArray()); | ||
Assert.Equal(new NodeId(2, guid.ToByteArray(), NodeIdNetType.Guid), new NodeId(2, guid2.ToByteArray(), NodeIdNetType.Guid)); | ||
} | ||
|
||
[Fact] | ||
public void NodeId_GuidNamespaceNonEquivalence() | ||
{ | ||
var guid = new Guid(); | ||
var guid2 = new Guid(guid.ToByteArray()); | ||
Assert.NotEqual(new NodeId(2, guid.ToByteArray(), NodeIdNetType.Guid), new NodeId(3, guid2.ToByteArray(), NodeIdNetType.Guid)); | ||
} | ||
|
||
[Fact] | ||
public void NodeId_GuidValueNonEquivalence() | ||
{ | ||
var byteArray1 = Enumerable.Range(0, 16).Select(x => (byte)x).ToArray(); | ||
var byteArray2 = Enumerable.Range(1, 16).Select(x => (byte)x).ToArray(); | ||
var guid1 = new Guid(byteArray1); | ||
var guid2 = new Guid(byteArray2); | ||
Assert.NotEqual(new NodeId(2, guid1.ToByteArray(), NodeIdNetType.Guid), new NodeId(2, guid2.ToByteArray(), NodeIdNetType.Guid)); | ||
} | ||
|
||
[Fact] | ||
public void NodeId_OpaqueEquivalence() | ||
{ | ||
Assert.Equal(new NodeId(2, [0, 1, 2, 3, 4], NodeIdNetType.ByteString), new NodeId(2, [0, 1, 2, 3, 4], NodeIdNetType.ByteString)); | ||
} | ||
|
||
[Fact] | ||
public void NodeId_OpaqueNamespaceNonEquivalence() | ||
{ | ||
Assert.NotEqual(new NodeId(2, [0, 1, 2, 3, 4], NodeIdNetType.ByteString), new NodeId(3, [0, 1, 2, 3, 4], NodeIdNetType.ByteString)); | ||
} | ||
|
||
[Fact] | ||
public void NodeId_OpaqueValueNonEquivalence() | ||
{ | ||
Assert.NotEqual(new NodeId(2, [0, 1, 2, 3, 4], NodeIdNetType.ByteString), new NodeId(2, [0, 1, 2, 3, 5], NodeIdNetType.ByteString)); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.