Skip to content

Commit

Permalink
update analyser
Browse files Browse the repository at this point in the history
  • Loading branch information
lucasteles committed Mar 19, 2024
1 parent 0eba8db commit de78781
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 8 deletions.
2 changes: 1 addition & 1 deletion Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
</ItemGroup>

<ItemGroup Condition="'$(MSBuildProjectExtension)' == '.csproj'">
<PackageReference Include="SonarAnalyzer.CSharp" Version="9.20.0.85982">
<PackageReference Include="SonarAnalyzer.CSharp" Version="9.21.0.86780">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
Expand Down
4 changes: 2 additions & 2 deletions samples/LobbyServer/UdpListenerService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,9 @@ protected override async Task ExecuteAsync(CancellationToken stoppingToken)
entry.Peer.Endpoint = remoteEndPoint;
entry.LastRead = time.GetUtcNow();
}
catch (OperationCanceledException)
catch (OperationCanceledException ex)
{
logger.LogInformation("UDP: operation cancelled");
logger.LogInformation(ex, "UDP: operation cancelled");
break;
}
catch (Exception ex)
Expand Down
2 changes: 1 addition & 1 deletion samples/SpaceWar.Shared/Logic/GameState.cs
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ public void UpdateShip(in Ship ship, in GameInput inputs)
}

ship.Thrust = Math.Sign(inputs.Thrust);
if (inputs.Thrust != 0)
if (ship.Thrust != 0)
{
ship.Velocity += (dir * inputs.Thrust).RoundTo();
var magnitude = ship.Velocity.Length();
Expand Down
8 changes: 4 additions & 4 deletions src/Backdash/Network/PeerConnection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -125,10 +125,10 @@ public void Update()
syncRequest.Update();
break;
case ProtocolStatus.Running:
{
CheckDisconnection();
break;
}
{
CheckDisconnection();
break;
}
case ProtocolStatus.Disconnected:
break;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@
using Backdash.Tests.TestUtils.Types;

// ReSharper disable CompareOfFloatsByEqualityOperator
#pragma warning disable S1244

namespace Backdash.Tests.Specs.Unit.Serialization;

[Collection(SerialCollectionDefinition.Name)]
public class BinarySpanReadWriteValueTests
{
Expand All @@ -20,6 +23,7 @@ public bool SingleByte(byte value, Endianness endianness)
reader.ReadCount.Should().Be(size);
return value == read;
}

[PropertyTest]
public bool SingleSByte(sbyte value, Endianness endianness)
{
Expand All @@ -30,6 +34,7 @@ public bool SingleSByte(sbyte value, Endianness endianness)
reader.ReadCount.Should().Be(size);
return value == read;
}

[PropertyTest]
public bool SingleBool(bool value, Endianness endianness)
{
Expand All @@ -40,6 +45,7 @@ public bool SingleBool(bool value, Endianness endianness)
reader.ReadCount.Should().Be(size);
return value == read;
}

[PropertyTest]
public bool SingleChar(char value, Endianness endianness)
{
Expand All @@ -50,6 +56,7 @@ public bool SingleChar(char value, Endianness endianness)
reader.ReadCount.Should().Be(size);
return value == read;
}

[PropertyTest]
public bool SingleShort(short value, Endianness endianness)
{
Expand All @@ -60,6 +67,7 @@ public bool SingleShort(short value, Endianness endianness)
reader.ReadCount.Should().Be(size);
return value == read;
}

[PropertyTest]
public bool SingleUShort(ushort value, Endianness endianness)
{
Expand All @@ -70,6 +78,7 @@ public bool SingleUShort(ushort value, Endianness endianness)
reader.ReadCount.Should().Be(size);
return value == read;
}

[PropertyTest]
public bool SingleInt(int value, Endianness endianness)
{
Expand All @@ -80,6 +89,7 @@ public bool SingleInt(int value, Endianness endianness)
reader.ReadCount.Should().Be(size);
return value == read;
}

[PropertyTest]
public bool SingleUInt(uint value, Endianness endianness)
{
Expand All @@ -90,6 +100,7 @@ public bool SingleUInt(uint value, Endianness endianness)
reader.ReadCount.Should().Be(size);
return value == read;
}

[PropertyTest]
public bool SingleLong(long value, Endianness endianness)
{
Expand All @@ -100,6 +111,7 @@ public bool SingleLong(long value, Endianness endianness)
reader.ReadCount.Should().Be(size);
return value == read;
}

[PropertyTest]
public bool SingleULong(ulong value, Endianness endianness)
{
Expand All @@ -110,6 +122,7 @@ public bool SingleULong(ulong value, Endianness endianness)
reader.ReadCount.Should().Be(size);
return value == read;
}

[PropertyTest]
public bool SingleInt128(Int128 value, Endianness endianness)
{
Expand All @@ -120,6 +133,7 @@ public bool SingleInt128(Int128 value, Endianness endianness)
reader.ReadCount.Should().Be(size);
return value == read;
}

[PropertyTest]
public bool SingleIntU128(UInt128 value, Endianness endianness)
{
Expand All @@ -130,6 +144,7 @@ public bool SingleIntU128(UInt128 value, Endianness endianness)
reader.ReadCount.Should().Be(size);
return value == read;
}

[PropertyTest]
public bool SingleHalf(Half value, Endianness endianness)
{
Expand All @@ -140,6 +155,7 @@ public bool SingleHalf(Half value, Endianness endianness)
reader.ReadCount.Should().Be(size);
return value == read;
}

[PropertyTest]
public bool SingleFloat(float value, Endianness endianness)
{
Expand All @@ -150,6 +166,7 @@ public bool SingleFloat(float value, Endianness endianness)
reader.ReadCount.Should().Be(size);
return value == read;
}

[PropertyTest]
public bool SingleDouble(double value, Endianness endianness)
{
Expand All @@ -160,6 +177,7 @@ public bool SingleDouble(double value, Endianness endianness)
reader.ReadCount.Should().Be(size);
return value == read;
}

[PropertyTest]
public bool SingleVector2(Vector2 value, Endianness endianness)
{
Expand All @@ -170,6 +188,7 @@ public bool SingleVector2(Vector2 value, Endianness endianness)
reader.ReadCount.Should().Be(size);
return value == read;
}

[PropertyTest]
public bool SingleVector3(Vector3 value, Endianness endianness)
{
Expand All @@ -180,6 +199,7 @@ public bool SingleVector3(Vector3 value, Endianness endianness)
reader.ReadCount.Should().Be(size);
return value == read;
}

[PropertyTest]
public bool SingleVector4(Vector4 value, Endianness endianness)
{
Expand All @@ -190,6 +210,7 @@ public bool SingleVector4(Vector4 value, Endianness endianness)
reader.ReadCount.Should().Be(size);
return value == read;
}

[PropertyTest]
public bool SingleQuaternion(Quaternion value, Endianness endianness)
{
Expand All @@ -200,8 +221,10 @@ public bool SingleQuaternion(Quaternion value, Endianness endianness)
reader.ReadCount.Should().Be(size);
return value == read;
}

static int writeOffset;
static int readOffset;

static int Setup<T>(
Endianness endianness,
out BinarySpanWriter writer,
Expand All @@ -222,25 +245,32 @@ out BinarySpanReader reader
};
return size;
}

[Collection(SerialCollectionDefinition.Name)]
public class ReadWriteEnumTests
{
[PropertyTest] public bool TestIntEnum(IntEnum value, Endianness endianness) => TestEnum(value, endianness);
[PropertyTest] public bool TestUIntEnum(UIntEnum value, Endianness endianness) => TestEnum(value, endianness);
[PropertyTest] public bool TestLongEnum(LongEnum value, Endianness endianness) => TestEnum(value, endianness);

[PropertyTest]
public bool TestULongEnum(ULongEnum value, Endianness endianness) =>
TestEnum(value, endianness);

[PropertyTest]
public bool TestShortEnum(ShortEnum value, Endianness endianness) =>
TestEnum(value, endianness);

[PropertyTest]
public bool TestUShortEnum(UShortEnum value, Endianness endianness) =>
TestEnum(value, endianness);

[PropertyTest] public bool TestByteEnum(ByteEnum value, Endianness endianness) => TestEnum(value, endianness);

[PropertyTest]
public bool TestSByteEnum(SByteEnum value, Endianness endianness) =>
TestEnum(value, endianness);

bool TestEnum<T>(T value, Endianness endianness) where T : unmanaged, Enum
{
var size = Setup<T>(endianness, out var writer, out var reader);
Expand All @@ -251,25 +281,32 @@ bool TestEnum<T>(T value, Endianness endianness) where T : unmanaged, Enum
return EqualityComparer<T>.Default.Equals(read, value);
}
}

[Collection(SerialCollectionDefinition.Name)]
public class ReadWriteBinaryIntegerTests
{
[PropertyTest] public bool TestInt(int value, Endianness endianness) => TestInteger(value, endianness);
[PropertyTest] public bool TestUInt(uint value, Endianness endianness) => TestInteger(value, endianness);
[PropertyTest] public bool TestLong(long value, Endianness endianness) => TestInteger(value, endianness);

[PropertyTest]
public bool TestULong(ulong value, Endianness endianness) =>
TestInteger(value, endianness);

[PropertyTest]
public bool TestShort(short value, Endianness endianness) =>
TestInteger(value, endianness);

[PropertyTest]
public bool TestUShort(ushort value, Endianness endianness) =>
TestInteger(value, endianness);

[PropertyTest] public bool TestByte(byte value, Endianness endianness) => TestInteger(value, endianness);

[PropertyTest]
public bool TestSByte(sbyte value, Endianness endianness) =>
TestInteger(value, endianness);

bool TestInteger<T>(T value, Endianness endianness) where T : unmanaged, IBinaryInteger<T>, IMinMaxValue<T>
{
var size = Setup<T>(endianness, out var writer, out var reader);
Expand Down

0 comments on commit de78781

Please sign in to comment.