-
Notifications
You must be signed in to change notification settings - Fork 495
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
88 additions
and
0 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,81 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.IO; | ||
using System.Threading.Tasks; | ||
using SteamKit2; | ||
using SteamKit2.Internal; | ||
using Xunit; | ||
|
||
#nullable enable | ||
namespace Tests | ||
{ | ||
public class PacketFacts | ||
{ | ||
internal record struct TestPacket( EMsg EMsg, byte[] Data ); | ||
|
||
private static Type? GetCallback( EMsg msg ) => msg switch | ||
{ | ||
EMsg.ClientPICSProductInfoResponse => typeof( SteamApps.PICSProductInfoCallback ), | ||
_ => null, | ||
}; | ||
|
||
[Fact] | ||
public async Task PostsExpectedCallbacks() | ||
{ | ||
var steamClient = new SteamClient(); | ||
|
||
await foreach ( var (eMsg, data) in GetPackets( "in" ) ) | ||
{ | ||
var expectedCallback = GetCallback( eMsg ); | ||
Assert.NotNull( expectedCallback ); | ||
|
||
var packetMsg = CMClient.GetPacketMsg( data, steamClient ); | ||
Assert.NotNull( packetMsg ); | ||
Assert.IsAssignableFrom<PacketClientMsgProtobuf>( packetMsg ); | ||
|
||
Assert.Null( steamClient.GetCallback() ); // There must be no callbacks queued | ||
|
||
steamClient.ReceiveTestPacketMsg( packetMsg ); | ||
|
||
var callback = steamClient.GetCallback(); | ||
Assert.NotNull( callback ); | ||
Assert.Equal( expectedCallback, callback.GetType() ); | ||
} | ||
} | ||
|
||
private static async IAsyncEnumerable<TestPacket> GetPackets( string direction ) | ||
{ | ||
var folder = Path.Join( AppDomain.CurrentDomain.BaseDirectory, "Packets" ); | ||
var files = Directory.GetFiles( folder, "*.bin" ); | ||
|
||
foreach ( var filename in files ) | ||
{ | ||
var packet = await GetPacket( filename, direction ); | ||
|
||
if ( packet.HasValue ) | ||
{ | ||
yield return packet.Value; | ||
} | ||
} | ||
} | ||
|
||
private static async Task<TestPacket?> GetPacket( string filename, string direction ) | ||
{ | ||
var parts = Path.GetFileNameWithoutExtension( filename ).Split( '_' ); | ||
|
||
Assert.True( parts.Length > 3 ); | ||
|
||
if ( parts[ 1 ] != direction ) | ||
{ | ||
return null; | ||
} | ||
|
||
var emsg = ( EMsg )uint.Parse( parts[ 2 ] ); | ||
|
||
var data = await File.ReadAllBytesAsync( filename ); | ||
|
||
return new( emsg, data ); | ||
} | ||
} | ||
} | ||
#nullable disable |
Binary file added
BIN
+120 Bytes
SteamKit2/Tests/Packets/001_in_8904_k_EMsgClientPICSProductInfoResponse_app480_metadata.bin
Binary file not shown.
Binary file added
BIN
+3.24 KB
SteamKit2/Tests/Packets/002_in_8904_k_EMsgClientPICSProductInfoResponse_app480.bin
Binary file not shown.
Binary file added
BIN
+9.13 KB
SteamKit2/Tests/Packets/003_in_8904_k_EMsgClientPICSProductInfoResponse_sub0.bin
Binary file not shown.
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