Skip to content

Commit

Permalink
Fix misc. build issues and warnings (OPCFoundation#2908)
Browse files Browse the repository at this point in the history
- Fix errors and warnings on stricter build systems.
- Some Linux distri do not support brainpool, detect if tests can be run.
  • Loading branch information
mregen authored Dec 13, 2024
1 parent dc661ba commit 9a434b8
Show file tree
Hide file tree
Showing 25 changed files with 83 additions and 49 deletions.
1 change: 1 addition & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ root = true
# All files
[*]
indent_style = space
tab_width = 4

# Code files
[*.{cs,csx,vb,vbx}]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
* ======================================================================*/

using System;

using System.Globalization;
using Opc.Ua;

#pragma warning disable CS1591
Expand Down Expand Up @@ -272,7 +272,7 @@ private ServiceResult OnShelve(
}
else
{
dueTo = " due to TimedShelve of " + shelvingTime.ToString();
dueTo = " due to TimedShelve of " + shelvingTime.ToString(CultureInfo.InvariantCulture);
}
}
else
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
* ======================================================================*/

using System;

using System.Globalization;
using Opc.Ua;

#pragma warning disable CS0219
Expand Down Expand Up @@ -85,7 +85,7 @@ public override void SetValue(string message = "")

if (message.Length == 0)
{
message = "Discrete Alarm analog value = " + value.ToString() + ", active = " + active.ToString();
message = "Discrete Alarm analog value = " + value.ToString(CultureInfo.InvariantCulture) + ", active = " + active.ToString();
}

base.SetValue(message);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
using Opc.Ua.Server;
using Opc.Ua.Sample;
using System.Reflection;
using System.Globalization;

namespace MemoryBuffer
{
Expand Down Expand Up @@ -234,7 +235,7 @@ protected override object GetManagerHandle(ISystemContext context, NodeId nodeId
}

// check range on offset.
uint offset = Convert.ToUInt32(offsetText);
uint offset = Convert.ToUInt32(offsetText, CultureInfo.InvariantCulture);

if (offset >= buffer.SizeInBytes.Value)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<PropertyGroup>
<AssemblyName>Opc.Ua.Client.ComplexTypes</AssemblyName>
<TargetFrameworks>$(LibxTargetFrameworks)</TargetFrameworks>
<PackageId>OPCFoundation.NetStandard.Opc.Ua.Client.ComplexTypes</PackageId>
<PackageId>$(PackagePrefix).Opc.Ua.Client.ComplexTypes</PackageId>
<RootNameSpace>Opc.Ua.Client.ComplexTypes</RootNameSpace>
<Description>OPC UA Complex Types Client Class Library</Description>
<IsPackable>true</IsPackable>
Expand Down
2 changes: 1 addition & 1 deletion Libraries/Opc.Ua.Client/Opc.Ua.Client.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<DefineConstants>$(DefineConstants);CLIENT_ASYNC</DefineConstants>
<AssemblyName>Opc.Ua.Client</AssemblyName>
<TargetFrameworks>$(LibTargetFrameworks)</TargetFrameworks>
<PackageId>OPCFoundation.NetStandard.Opc.Ua.Client</PackageId>
<PackageId>$(PackagePrefix).Opc.Ua.Client</PackageId>
<RootNamespace>Opc.Ua.Client</RootNamespace>
<Description>OPC UA Client Class Library</Description>
<IsPackable>true</IsPackable>
Expand Down
13 changes: 6 additions & 7 deletions Libraries/Opc.Ua.Client/Session/TraceableSession.cs
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ public int OperationTimeout

/// <inheritdoc/>
public bool CheckDomain => m_session.CheckDomain;

/// <inheritdoc/>
public ContinuationPointPolicy ContinuationPointPolicy
{
Expand Down Expand Up @@ -661,7 +661,7 @@ public void ReadValues(IList<NodeId> variableIds, IList<Type> expectedTypes, out
m_session.ReadValues(variableIds, expectedTypes, out values, out errors);
}
}

/// <inheritdoc/>
public byte[] ReadByteStringInChunks(NodeId nodeId)
{
Expand All @@ -671,8 +671,8 @@ public byte[] ReadByteStringInChunks(NodeId nodeId)
}
}

/// <inheritdoc/>
public void ReadDisplayName(IList<NodeId> nodeIds, out IList<string> displayNames, out IList<ServiceResult> errors)
/// <inheritdoc/>
public void ReadDisplayName(IList<NodeId> nodeIds, out IList<string> displayNames, out IList<ServiceResult> errors)
{
using (Activity activity = ActivitySource.StartActivity())
{
Expand Down Expand Up @@ -1289,18 +1289,17 @@ public void ManagedBrowse(RequestHeader requestHeader, ViewDescription view, ILi
{
m_session.ManagedBrowse(requestHeader, view, nodesToBrowse, maxResultsToReturn, browseDirection, referenceTypeId, includeSubtypes, nodeClassMask, out result, out errors);
}

}

/// <inheritdoc/>
public async Task<(
public Task<(
IList<ReferenceDescriptionCollection>,
IList<ServiceResult>
)> ManagedBrowseAsync(RequestHeader requestHeader, ViewDescription view, IList<NodeId> nodesToBrowse, uint maxResultsToReturn, BrowseDirection browseDirection, NodeId referenceTypeId, bool includeSubtypes, uint nodeClassMask, CancellationToken ct = default)
{
using (Activity activity = ActivitySource.StartActivity())
{
return await m_session.ManagedBrowseAsync(requestHeader, view, nodesToBrowse, maxResultsToReturn, browseDirection, referenceTypeId, includeSubtypes, nodeClassMask, ct);
return m_session.ManagedBrowseAsync(requestHeader, view, nodesToBrowse, maxResultsToReturn, browseDirection, referenceTypeId, includeSubtypes, nodeClassMask, ct);
}
}

Expand Down
2 changes: 1 addition & 1 deletion Libraries/Opc.Ua.Configuration/Opc.Ua.Configuration.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<PropertyGroup>
<AssemblyName>Opc.Ua.Configuration</AssemblyName>
<TargetFrameworks>$(LibTargetFrameworks)</TargetFrameworks>
<PackageId>OPCFoundation.NetStandard.Opc.Ua.Configuration</PackageId>
<PackageId>$(PackagePrefix).Opc.Ua.Configuration</PackageId>
<RootNamespace>Opc.Ua.Configuration</RootNamespace>
<Description>OPC UA Configuration Class Library</Description>
<IsPackable>true</IsPackable>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<PropertyGroup>
<AssemblyName>Opc.Ua.Gds.Client.Common</AssemblyName>
<TargetFrameworks>$(LibTargetFrameworks)</TargetFrameworks>
<PackageId>OPCFoundation.NetStandard.Opc.Ua.Gds.Client.Common</PackageId>
<PackageId>$(PackagePrefix).Opc.Ua.Gds.Client.Common</PackageId>
<RootNamespace>Opc.Ua.Gds.Client</RootNamespace>
<NoWarn>$(NoWarn);CS1591</NoWarn>
<Description>OPC UA GDS Client Class Library</Description>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<PropertyGroup>
<AssemblyName>Opc.Ua.Gds.Server.Common</AssemblyName>
<TargetFrameworks>$(LibTargetFrameworks)</TargetFrameworks>
<PackageId>OPCFoundation.NetStandard.Opc.Ua.Gds.Server.Common</PackageId>
<PackageId>$(PackagePrefix).Opc.Ua.Gds.Server.Common</PackageId>
<RootNamespace>Opc.Ua.Gds.Server</RootNamespace>
<NoWarn>$(NoWarn);CS1591</NoWarn>
<Description>OPC UA GDS Server Class Library</Description>
Expand Down
2 changes: 1 addition & 1 deletion Libraries/Opc.Ua.PubSub/Opc.Ua.PubSub.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<PropertyGroup>
<AssemblyName>Opc.Ua.PubSub</AssemblyName>
<TargetFrameworks>$(LibxTargetFrameworks)</TargetFrameworks>
<PackageId>OPCFoundation.NetStandard.Opc.Ua.PubSub</PackageId>
<PackageId>$(PackagePrefix).Opc.Ua.PubSub</PackageId>
<RootNamespace>Opc.Ua.PubSub</RootNamespace>
<Description>OPC UA PubSub Class Library</Description>
<IsPackable>true</IsPackable>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<PropertyGroup>
<AssemblyName>Opc.Ua.Security.Certificates</AssemblyName>
<TargetFrameworks>$(LibCoreTargetFrameworks)</TargetFrameworks>
<PackageId>OPCFoundation.NetStandard.Opc.Ua.Security.Certificates</PackageId>
<PackageId>$(PackagePrefix).Opc.Ua.Security.Certificates</PackageId>
<RootNamespace>Opc.Ua.Security.Certificates</RootNamespace>
<Description>OPC UA Security X509 Certificates Class Library</Description>
<IsPackable>true</IsPackable>
Expand Down
2 changes: 1 addition & 1 deletion Libraries/Opc.Ua.Server/Opc.Ua.Server.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<PropertyGroup>
<AssemblyName>Opc.Ua.Server</AssemblyName>
<TargetFrameworks>$(LibTargetFrameworks)</TargetFrameworks>
<PackageId>OPCFoundation.NetStandard.Opc.Ua.Server</PackageId>
<PackageId>$(PackagePrefix).Opc.Ua.Server</PackageId>
<RootNamespace>Opc.Ua.Server</RootNamespace>
<Description>OPC UA Server Class Library</Description>
<RestoreProjectStyle>PackageReference</RestoreProjectStyle>
Expand Down
2 changes: 1 addition & 1 deletion Stack/Opc.Ua.Bindings.Https/Opc.Ua.Bindings.Https.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<SuppressTfmSupportBuildWarnings>true</SuppressTfmSupportBuildWarnings>
<TargetFrameworks>$(HttpsTargetFrameworks)</TargetFrameworks>
<AssemblyName>Opc.Ua.Bindings.Https</AssemblyName>
<PackageId>OPCFoundation.NetStandard.Opc.Ua.Bindings.Https</PackageId>
<PackageId>$(PackagePrefix).Opc.Ua.Bindings.Https</PackageId>
<RootNamespace>Opc.Ua.Bindings</RootNamespace>
<Description>OPC UA Https Binding Library for a Opc.Ua.Server.</Description>
<IsPackable>true</IsPackable>
Expand Down
2 changes: 1 addition & 1 deletion Stack/Opc.Ua.Core/Opc.Ua.Core.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<DefineConstants>$(DefineConstants);NET_STANDARD;NET_STANDARD_ASYNC</DefineConstants>
<TargetFrameworks>$(LibCoreTargetFrameworks)</TargetFrameworks>
<AssemblyName>Opc.Ua.Core</AssemblyName>
<PackageId>OPCFoundation.NetStandard.Opc.Ua.Core</PackageId>
<PackageId>$(PackagePrefix).Opc.Ua.Core</PackageId>
<RootNamespace>Opc.Ua</RootNamespace>
<Description>OPC UA Core Class Library</Description>
<IsPackable>true</IsPackable>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1120,6 +1120,7 @@ await GetIssuerNoExceptionAsync(certificate, explicitList, certificateStore, che
/// <param name="endpoint">The endpoint for domain validation.</param>
/// <param name="ct">The cancellation token.</param>
/// <exception cref="ServiceResultException">If certificate[0] cannot be accepted</exception>
[System.Diagnostics.CodeAnalysis.SuppressMessage("Roslynanalyzer", "IA5352:Do not set X509RevocationMode.NoCheck", Justification = "Revocation is already checked.")]
protected virtual async Task InternalValidateAsync(X509Certificate2Collection certificates, ConfiguredEndpoint endpoint, CancellationToken ct = default)
{
X509Certificate2 certificate = certificates[0];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,11 +88,17 @@ public SecuredApplication ReadConfiguration(string filePath)
{
FileStream reader = File.Open(configFilePath, FileMode.Open, FileAccess.Read, FileShare.Read);


try
{
byte[] data = new byte[reader.Length];
reader.Read(data, 0, (int)reader.Length);
int bytesRead = reader.Read(data, 0, (int)reader.Length);
if (reader.Length != bytesRead)
{
throw ServiceResultException.Create(
StatusCodes.BadNotReadable,
"Cannot read all bytes of the configuration file: {0}<{1}",
bytesRead, reader.Length);
}

// find the SecuredApplication element in the file.
if (data.ToString().Contains("SecuredApplication"))
Expand Down
3 changes: 2 additions & 1 deletion Stack/Opc.Ua.Core/Stack/Tcp/TcpTransportListener.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.Linq;
using System.Net;
using System.Net.Sockets;
Expand Down Expand Up @@ -413,7 +414,7 @@ public void UpdateChannelLastActiveTime(string globalChannelId)
try
{
var channelIdString = globalChannelId.Substring(ListenerId.Length + 1);
var channelId = Convert.ToUInt32(channelIdString);
var channelId = Convert.ToUInt32(channelIdString, CultureInfo.InvariantCulture);

TcpListenerChannel channel = null;
if (channelId > 0 &&
Expand Down
2 changes: 1 addition & 1 deletion Tests/Opc.Ua.Client.Tests/ContinuationPointInBatchTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1073,7 +1073,7 @@ private void VerifyExpectedResults(List<string> memoryLogPass,
// get the part of the error message after the time stamp:
string msg = s.Substring(s.IndexOf("ManagedBrowse"));
// create error message from expected results
String expectedString = String.Format(
String expectedString = Utils.Format(
"ManagedBrowse: in pass {0}, {1} {2} occured with a status code {3}.",
pass,
expectedResults.ExpectedNumberOfBadNoCPSCs[pass],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,7 @@ public void ArraySegmentStreamWrite(
Assert.That(position, Is.EqualTo(chunkSize * i));
}

int bytesRead;
switch (random.Next(3))
{
case 0:
Expand All @@ -215,15 +216,17 @@ public void ArraySegmentStreamWrite(
break;
default:
#if NET5_0_OR_GREATER
writer.Read(buffer.AsSpan(0, chunkSize));
bytesRead = writer.Read(buffer.AsSpan(0, chunkSize));
Assert.That(chunkSize, Is.EqualTo(bytesRead));
for (int v = 0; v < chunkSize; v++)
{
Assert.That(buffer[v], Is.EqualTo((byte)i));
}
break;
#endif
case 1:
writer.Read(buffer, 0, chunkSize);
bytesRead = writer.Read(buffer, 0, chunkSize);
Assert.That(chunkSize, Is.EqualTo(bytesRead));
for (int v = 0; v < chunkSize; v++)
{
Assert.That(buffer[v], Is.EqualTo((byte)i));
Expand Down
4 changes: 2 additions & 2 deletions Tests/Opc.Ua.Core.Tests/Types/Utils/UtilsIsEqualTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public class UtilsIsEqualTests
[Params(32, 128, 1024, 4096, 65536)]
public int PayLoadSize { get; set; } = 1024;

private bool _windows = RuntimeInformation.IsOSPlatform(OSPlatform.Windows);
private bool m_windows = RuntimeInformation.IsOSPlatform(OSPlatform.Windows);

/// <summary>
/// Test IsEqual using the generic IsEqual from previous versions.
Expand Down Expand Up @@ -134,7 +134,7 @@ public bool ForLoopBinaryCompare()
[Benchmark]
public bool MemCmpByteArrayCompare()
{
if (_windows)
if (m_windows)
{
// Validate buffers are the same length.
// This also ensures that the count does not exceed the length of either buffer.
Expand Down
15 changes: 8 additions & 7 deletions Tests/Opc.Ua.PubSub.Tests/Encoding/MessagesHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
using System.ComponentModel;
using System.Threading;
using Opc.Ua.PubSub.PublishedData;
using System.Globalization;

namespace Opc.Ua.PubSub.Tests.Encoding
{
Expand Down Expand Up @@ -2841,21 +2842,21 @@ public static void UpdateSnapshotData(UaPubSubApplication pubSubApplication, UIn
DataValue boolToggle = pubSubApplication.DataStore.ReadPublishedDataItem(new NodeId("BoolToggle", namespaceIndexAllTypes), Attributes.Value);
if (boolToggle.Value is bool)
{
bool boolVal = Convert.ToBoolean(boolToggle.Value);
bool boolVal = Convert.ToBoolean(boolToggle.Value, CultureInfo.InvariantCulture);
boolToggle.Value = !boolVal;
pubSubApplication.DataStore.WritePublishedDataItem(new NodeId("BoolToggle", namespaceIndexAllTypes), Attributes.Value, boolToggle);
}
DataValue byteValue = pubSubApplication.DataStore.ReadPublishedDataItem(new NodeId("Byte", namespaceIndexAllTypes), Attributes.Value);
if (byteValue.Value is byte)
{
byte byteVal = Convert.ToByte(byteValue.Value);
byte byteVal = Convert.ToByte(byteValue.Value, CultureInfo.InvariantCulture);
byteValue.Value = ++byteVal;
pubSubApplication.DataStore.WritePublishedDataItem(new NodeId("Byte", namespaceIndexAllTypes), Attributes.Value, byteValue);
}
DataValue int16Value = pubSubApplication.DataStore.ReadPublishedDataItem(new NodeId("Int16", namespaceIndexAllTypes), Attributes.Value);
if (int16Value.Value is Int16)
{
Int16 int16Val = Convert.ToInt16(int16Value.Value);
Int16 int16Val = Convert.ToInt16(int16Value.Value, CultureInfo.InvariantCulture);
int intIdentifier = int16Val;
Interlocked.CompareExchange(ref intIdentifier, 0, Int16.MaxValue);
int16Value.Value = (Int16)Interlocked.Increment(ref intIdentifier);
Expand All @@ -2864,7 +2865,7 @@ public static void UpdateSnapshotData(UaPubSubApplication pubSubApplication, UIn
DataValue int32Value = pubSubApplication.DataStore.ReadPublishedDataItem(new NodeId("Int32", namespaceIndexAllTypes), Attributes.Value);
if (int32Value.Value is Int32)
{
Int32 int32Val = Convert.ToInt32(int16Value.Value);
Int32 int32Val = Convert.ToInt32(int16Value.Value, CultureInfo.InvariantCulture);
int intIdentifier = int32Val;
Interlocked.CompareExchange(ref intIdentifier, 0, Int32.MaxValue);
int32Value.Value = (Int32)Interlocked.Increment(ref intIdentifier);
Expand All @@ -2873,7 +2874,7 @@ public static void UpdateSnapshotData(UaPubSubApplication pubSubApplication, UIn
DataValue uInt16Value = pubSubApplication.DataStore.ReadPublishedDataItem(new NodeId("UInt16", namespaceIndexAllTypes), Attributes.Value);
if (uInt16Value.Value is UInt16)
{
UInt16 uInt16Val = Convert.ToUInt16(uInt16Value.Value);
UInt16 uInt16Val = Convert.ToUInt16(uInt16Value.Value, CultureInfo.InvariantCulture);
int intIdentifier = uInt16Val;
Interlocked.CompareExchange(ref intIdentifier, 0, UInt16.MaxValue);
uInt16Value.Value = (UInt16)Interlocked.Increment(ref intIdentifier);
Expand All @@ -2882,7 +2883,7 @@ public static void UpdateSnapshotData(UaPubSubApplication pubSubApplication, UIn
DataValue uInt32Value = pubSubApplication.DataStore.ReadPublishedDataItem(new NodeId("UInt32", namespaceIndexAllTypes), Attributes.Value);
if (uInt32Value.Value is UInt32)
{
UInt32 uInt32Val = Convert.ToUInt32(uInt32Value.Value);
UInt32 uInt32Val = Convert.ToUInt32(uInt32Value.Value, CultureInfo.InvariantCulture);
long longIdentifier = uInt32Val;
Interlocked.CompareExchange(ref longIdentifier, 0, UInt32.MaxValue);
uInt32Value.Value = (UInt32)Interlocked.Increment(ref longIdentifier);
Expand All @@ -2891,7 +2892,7 @@ public static void UpdateSnapshotData(UaPubSubApplication pubSubApplication, UIn
DataValue doubleValue = pubSubApplication.DataStore.ReadPublishedDataItem(new NodeId("Double", namespaceIndexAllTypes), Attributes.Value);
if (doubleValue.Value is double)
{
double doubleVal = Convert.ToDouble(doubleValue.Value);
double doubleVal = Convert.ToDouble(doubleValue.Value, CultureInfo.InvariantCulture);
Interlocked.CompareExchange(ref doubleVal, 0, double.MaxValue);
doubleValue.Value = ++doubleVal;
pubSubApplication.DataStore.WritePublishedDataItem(new NodeId("Double", namespaceIndexAllTypes), Attributes.Value, doubleValue);
Expand Down
Loading

0 comments on commit 9a434b8

Please sign in to comment.