54 lines
2.4 KiB
C#
54 lines
2.4 KiB
C#
using Shouldly;
|
|
using Xunit;
|
|
|
|
namespace ZB.MOM.WW.OtOpcUa.Driver.Historian.Sql.Common.Tests;
|
|
|
|
/// <summary>The pinned SDK is the oracle for the info-bit constants (StatusCodeParityTests covers the named codes).</summary>
|
|
public sealed class StatusCodeOracleTests
|
|
{
|
|
[Fact]
|
|
public void Calculated_bits_match_the_SDK()
|
|
{
|
|
var sdk = Opc.Ua.StatusCodes.Good.WithAggregateBits(Opc.Ua.AggregateBits.Calculated);
|
|
sdk.Code.ShouldBe(HistorianInfoBits.WithCalculated(HistorianStatusCodes.Good));
|
|
((uint)Opc.Ua.AggregateBits.Calculated).ShouldBe(HistorianInfoBits.HistorianCalculated);
|
|
}
|
|
|
|
[Fact]
|
|
public void Interpolated_bits_match_the_SDK()
|
|
{
|
|
var sdk = Opc.Ua.StatusCodes.Good.WithAggregateBits(Opc.Ua.AggregateBits.Interpolated);
|
|
sdk.Code.ShouldBe(HistorianInfoBits.WithInterpolated(HistorianStatusCodes.Good));
|
|
((uint)Opc.Ua.AggregateBits.Interpolated).ShouldBe(HistorianInfoBits.HistorianInterpolated);
|
|
}
|
|
|
|
/// <summary>
|
|
/// A stored status that already carries a historian bit (a sample written via HistoryUpdate with the Calculated
|
|
/// bit, say) must come back with ONE historian bit, never both: the existing pair is masked off first. The SDK
|
|
/// agrees — <c>WithAggregateBits</c> replaces, it does not OR.
|
|
/// </summary>
|
|
[Fact]
|
|
public void Setting_one_historian_bit_clears_the_other()
|
|
{
|
|
var calculatedUncertain = HistorianStatusCodes.UncertainDataSubNormal | 0x400u | HistorianInfoBits.HistorianCalculated;
|
|
var interpolated = HistorianInfoBits.WithInterpolated(calculatedUncertain);
|
|
interpolated.ShouldBe(HistorianStatusCodes.UncertainDataSubNormal | 0x400u | HistorianInfoBits.HistorianInterpolated);
|
|
new Opc.Ua.StatusCode(interpolated).AggregateBits.ShouldBe(Opc.Ua.AggregateBits.Interpolated);
|
|
|
|
var interpolatedGood = 0x400u | HistorianInfoBits.HistorianInterpolated;
|
|
HistorianInfoBits.WithCalculated(interpolatedGood).ShouldBe(0x400u | HistorianInfoBits.HistorianCalculated);
|
|
}
|
|
|
|
[Fact]
|
|
public void Partial_bit_matches_the_SDK() =>
|
|
((uint)Opc.Ua.AggregateBits.Partial).ShouldBe(HistorianInfoBits.HistorianPartial);
|
|
|
|
[Fact]
|
|
public void Generic_bad_matches_the_SDK() =>
|
|
HistorianStatusCodes.Bad.ShouldBe(Opc.Ua.StatusCodes.Bad.Code);
|
|
|
|
[Fact]
|
|
public void Info_type_is_data_value() =>
|
|
HistorianInfoBits.InfoTypeDataValue.ShouldBe(0x400u);
|
|
}
|