Updated tests

This commit is contained in:
Garry Newman 2020-02-22 20:29:37 +00:00
parent d8e5a48f65
commit a7954f9e21
24 changed files with 300 additions and 238 deletions

View File

@ -95,7 +95,7 @@ public void InstalledDepots()
[TestMethod]
public async Task GetFileDetails()
{
var fileinfo = await SteamApps.GetFileDetailsAsync( "hl2.exe" );
var fileinfo = await SteamApps.GetFileDetailsAsync( "RustClient.exe" );
Console.WriteLine( $"fileinfo.SizeInBytes: {fileinfo?.SizeInBytes}" );
Console.WriteLine( $"fileinfo.Sha1: {fileinfo?.Sha1}" );

View File

@ -99,6 +99,8 @@
<Compile Include="FriendsTest.cs" />
<Compile Include="InputTest.cs" />
<Compile Include="NetworkingSockets.cs" />
<Compile Include="NetworkingSocketsTest.TestConnectionInterface.cs" />
<Compile Include="NetworkingSocketsTest.TestSocketInterface.cs" />
<Compile Include="SteamMatchmakingTest.cs" />
<Compile Include="RemoteStorageTest.cs" />
<Compile Include="InventoryTest.cs" />

View File

@ -99,6 +99,8 @@
<Compile Include="FriendsTest.cs" />
<Compile Include="InputTest.cs" />
<Compile Include="NetworkingSockets.cs" />
<Compile Include="NetworkingSocketsTest.TestConnectionInterface.cs" />
<Compile Include="NetworkingSocketsTest.TestSocketInterface.cs" />
<Compile Include="SteamMatchmakingTest.cs" />
<Compile Include="RemoteStorageTest.cs" />
<Compile Include="InventoryTest.cs" />

View File

@ -7,6 +7,7 @@
namespace Steamworks
{
[DeploymentItem( "steam_api64.dll" )]
[DeploymentItem( "steam_api.dll" )]
[TestClass]
public class FriendsTest
{

View File

@ -5,7 +5,8 @@
namespace Steamworks
{
[DeploymentItem( "steam_api64.dll" )]
[TestClass]
[DeploymentItem( "steam_api.dll" )]
[TestClass]
public partial class GameServerTest
{
[TestMethod]

View File

@ -11,7 +11,8 @@ namespace Steamworks
{
[TestClass]
[DeploymentItem( "steam_api64.dll" )]
[DeploymentItem( "controller_config/game_actions_252490.vdf" )]
[DeploymentItem( "steam_api.dll" )]
[DeploymentItem( "controller_config/game_actions_252490.vdf" )]
public class InputTest
{
[TestMethod]

View File

@ -10,7 +10,8 @@ namespace Steamworks
{
[TestClass]
[DeploymentItem( "steam_api64.dll" )]
public class InventoryTest
[DeploymentItem( "steam_api.dll" )]
public class InventoryTest
{
[TestMethod]
public async Task LoadItemDefinitionsAsync()

View File

@ -9,9 +9,10 @@
namespace Steamworks
{
[TestClass]
[TestClass]
[DeploymentItem( "steam_api64.dll" )]
public class NetworkingSocketsTest
[DeploymentItem( "steam_api.dll" )]
public partial class NetworkingSocketsTest
{
[TestMethod]
@ -43,12 +44,20 @@ public async Task CreateNormalServer()
[TestMethod]
public async Task RelayEndtoEnd()
{
var socket = SteamNetworkingSockets.CreateRelaySocket<TestSocketInterface>( 7788 );
SteamNetworkingUtils.InitRelayNetworkAccess();
// For some reason giving steam a couple of seconds here
// seems to prevent it returning null connections from ConnectNormal
await Task.Delay( 2000 );
Console.WriteLine( $"----- Creating Socket Relay Socket.." );
var socket = SteamNetworkingSockets.CreateRelaySocket<TestSocketInterface>( 6 );
var server = socket.RunAsync();
await Task.Delay( 1000 );
var connection = SteamNetworkingSockets.ConnectRelay<TestConnectionInterface>( SteamClient.SteamId, 7788 );
Console.WriteLine( $"----- Connecting To Socket via SteamId ({SteamClient.SteamId})" );
var connection = SteamNetworkingSockets.ConnectRelay<TestConnectionInterface>( SteamClient.SteamId, 6 );
var client = connection.RunAsync();
await Task.WhenAll( server, client );
@ -57,231 +66,26 @@ public async Task RelayEndtoEnd()
[TestMethod]
public async Task NormalEndtoEnd()
{
// For some reason giving steam a couple of seconds here
// seems to prevent it returning null connections from ConnectNormal
await Task.Delay( 2000 );
//
// Start the server
//
Console.WriteLine( "CreateNormalSocket" );
var socket = SteamNetworkingSockets.CreateNormalSocket<TestSocketInterface>( NetAddress.AnyIp( 12445 ) );
var server = socket.RunAsync();
await Task.Delay( 1000 );
//
// Start the client
//
Console.WriteLine( "ConnectNormal" );
var connection = SteamNetworkingSockets.ConnectNormal<TestConnectionInterface>( NetAddress.From( System.Net.IPAddress.Parse( "127.0.0.1" ), 12445 ) );
var client = connection.RunAsync();
await Task.WhenAll( server, client );
}
private class TestConnectionInterface : ConnectionInterface
{
public override void OnConnectionChanged( ConnectionInfo data )
{
Console.WriteLine( $"[Connection][{Connection}] [{data.State}]" );
base.OnConnectionChanged( data );
}
public override void OnConnecting( ConnectionInfo data )
{
Console.WriteLine( $" - OnConnecting" );
base.OnConnecting( data );
}
/// <summary>
/// Client is connected. They move from connecting to Connections
/// </summary>
public override void OnConnected( ConnectionInfo data )
{
Console.WriteLine( $" - OnConnected" );
base.OnConnected( data );
}
/// <summary>
/// The connection has been closed remotely or disconnected locally. Check data.State for details.
/// </summary>
public override void OnDisconnected( ConnectionInfo data )
{
Console.WriteLine( $" - OnDisconnected" );
base.OnDisconnected( data );
}
internal async Task RunAsync()
{
Console.WriteLine( "[Connection] RunAsync" );
var sw = System.Diagnostics.Stopwatch.StartNew();
while ( Connecting )
{
await Task.Delay( 10 );
if ( sw.Elapsed.TotalSeconds > 30 )
break;
}
if ( !Connected )
{
Console.WriteLine( "[Connection] Couldn't connect!" );
Console.WriteLine( Connection.DetailedStatus() );
return;
}
Console.WriteLine( "[Connection] Hey We're Connected!" );
sw = System.Diagnostics.Stopwatch.StartNew();
while ( Connected )
{
Receive();
await Task.Delay( 100 );
if ( sw.Elapsed.TotalSeconds > 10 )
{
Assert.Fail( "Client Took Too Long" );
break;
}
}
}
public override unsafe void OnMessage( IntPtr data, int size, long messageNum, long recvTime, int channel )
{
// We're only sending strings, so it's fine to read this like this
var str = UTF8Encoding.UTF8.GetString( (byte*) data, size );
Console.WriteLine( $"[Connection][{messageNum}][{recvTime}][{channel}] \"{str}\"" );
if ( str.Contains( "Hello" ) )
{
Connection.SendMessage( "Hello, How are you!?" );
Connection.SendMessage( "How do you like 20 messages in a row?" );
for ( int i=0; i<20; i++ )
{
Connection.SendMessage( $"BLAMMO!" );
}
}
if ( str.Contains( "status" ))
{
Console.WriteLine( Connection.DetailedStatus() );
}
if ( str.Contains( "how about yourself" ) )
{
Connection.SendMessage( "I'm great, but I have to go now, bye." );
}
if ( str.Contains( "hater" ) )
{
Close();
}
}
}
private class TestSocketInterface : SocketInterface
{
public bool HasFinished = false;
public override void OnConnectionChanged( Connection connection, ConnectionInfo data )
{
Console.WriteLine( $"[Socket{Socket}][{connection}] [{data.State}]" );
base.OnConnectionChanged( connection, data );
}
public override void OnConnecting( Connection connection, ConnectionInfo data )
{
Console.WriteLine( $" - OnConnecting" );
base.OnConnecting( connection, data );
}
/// <summary>
/// Client is connected. They move from connecting to Connections
/// </summary>
public override void OnConnected( Connection connection, ConnectionInfo data )
{
Console.WriteLine( $" - OnConnected" );
base.OnConnected( connection, data );
}
/// <summary>
/// The connection has been closed remotely or disconnected locally. Check data.State for details.
/// </summary>
public override void OnDisconnected( Connection connection, ConnectionInfo data )
{
Console.WriteLine( $" - OnDisconnected" );
base.OnDisconnected( connection, data );
}
internal async Task RunAsync()
{
var sw = System.Diagnostics.Stopwatch.StartNew();
while ( Connected.Count == 0 )
{
await Task.Delay( 10 );
if ( sw.Elapsed.TotalSeconds > 2 )
{
Assert.Fail( "Client Took Too Long To Connect" );
break;
}
}
await Task.Delay( 1000 );
var singleClient = Connected.First();
singleClient.SendMessage( "Hey?" );
await Task.Delay( 100 );
singleClient.SendMessage( "Anyone?" );
await Task.Delay( 100 );
singleClient.SendMessage( "What's this?" );
await Task.Delay( 100 );
singleClient.SendMessage( "What's your status?" );
await Task.Delay( 10 );
singleClient.SendMessage( "Greetings!!??" );
await Task.Delay( 100 );
singleClient.SendMessage( "Hello Client!?" );
sw = System.Diagnostics.Stopwatch.StartNew();
while ( Connected.Contains( singleClient ) )
{
Receive();
await Task.Delay( 100 );
if ( sw.Elapsed.TotalSeconds > 10 )
{
Assert.Fail( "Socket Took Too Long" );
break;
}
}
await Task.Delay( 1000 );
Close();
}
public override unsafe void OnMessage( Connection connection, NetIdentity identity, IntPtr data, int size, long messageNum, long recvTime, int channel )
{
// We're only sending strings, so it's fine to read this like this
var str = UTF8Encoding.UTF8.GetString( (byte*)data, size );
Console.WriteLine( $"[SOCKET][{connection}[{identity}][{messageNum}][{recvTime}][{channel}] \"{str}\"" );
if ( str.Contains( "Hello, How are you" ) )
{
connection.SendMessage( "I'm great thanks, how about yourself?" );
}
if ( str.Contains( "bye" ) )
{
connection.SendMessage( "See you later, hater." );
connection.Flush();
connection.Close( true, 10, "Said Bye" );
}
}
}
}
}

View File

@ -0,0 +1,120 @@
using System;
using System.Text;
using System.Threading.Tasks;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Steamworks.Data;
namespace Steamworks
{
public partial class NetworkingSocketsTest
{
private class TestConnectionInterface : ConnectionInterface
{
public override void OnConnectionChanged( ConnectionInfo data )
{
Console.WriteLine( $"[Connection][{Connection}] [{data.State}]" );
base.OnConnectionChanged( data );
}
public override void OnConnecting( ConnectionInfo data )
{
Console.WriteLine( $" - OnConnecting" );
base.OnConnecting( data );
}
/// <summary>
/// Client is connected. They move from connecting to Connections
/// </summary>
public override void OnConnected( ConnectionInfo data )
{
Console.WriteLine( $" - OnConnected" );
base.OnConnected( data );
}
/// <summary>
/// The connection has been closed remotely or disconnected locally. Check data.State for details.
/// </summary>
public override void OnDisconnected( ConnectionInfo data )
{
Console.WriteLine( $" - OnDisconnected" );
base.OnDisconnected( data );
}
internal async Task RunAsync()
{
Console.WriteLine( "[Connection] RunAsync" );
var sw = System.Diagnostics.Stopwatch.StartNew();
while ( Connecting )
{
await Task.Delay( 10 );
if ( sw.Elapsed.TotalSeconds > 30 )
break;
}
if ( !Connected )
{
Console.WriteLine( "[Connection] Couldn't connect!" );
Console.WriteLine( Connection.DetailedStatus() );
return;
}
Console.WriteLine( "[Connection] Hey We're Connected!" );
sw = System.Diagnostics.Stopwatch.StartNew();
while ( Connected )
{
Receive();
await Task.Delay( 100 );
if ( sw.Elapsed.TotalSeconds > 10 )
{
Assert.Fail( "Client Took Too Long" );
break;
}
}
}
public override unsafe void OnMessage( IntPtr data, int size, long messageNum, long recvTime, int channel )
{
// We're only sending strings, so it's fine to read this like this
var str = UTF8Encoding.UTF8.GetString( (byte*) data, size );
Console.WriteLine( $"[Connection][{messageNum}][{recvTime}][{channel}] \"{str}\"" );
if ( str.Contains( "Hello" ) )
{
Connection.SendMessage( "Hello, How are you!?" );
Connection.SendMessage( "How do you like 20 messages in a row?" );
for ( int i=0; i<20; i++ )
{
Connection.SendMessage( $"BLAMMO!" );
}
}
if ( str.Contains( "status" ))
{
Console.WriteLine( Connection.DetailedStatus() );
}
if ( str.Contains( "how about yourself" ) )
{
Connection.SendMessage( "I'm great, but I have to go now, bye." );
}
if ( str.Contains( "hater" ) )
{
Close();
}
}
}
}
}

View File

@ -0,0 +1,119 @@
using System;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Steamworks.Data;
namespace Steamworks
{
public partial class NetworkingSocketsTest
{
private class TestSocketInterface : SocketInterface
{
public bool HasFinished = false;
public override void OnConnectionChanged( Connection connection, ConnectionInfo data )
{
Console.WriteLine( $"[Socket{Socket}][{connection}] [{data.State}]" );
base.OnConnectionChanged( connection, data );
}
public override void OnConnecting( Connection connection, ConnectionInfo data )
{
Console.WriteLine( $" - OnConnecting" );
base.OnConnecting( connection, data );
}
/// <summary>
/// Client is connected. They move from connecting to Connections
/// </summary>
public override void OnConnected( Connection connection, ConnectionInfo data )
{
Console.WriteLine( $" - OnConnected" );
base.OnConnected( connection, data );
}
/// <summary>
/// The connection has been closed remotely or disconnected locally. Check data.State for details.
/// </summary>
public override void OnDisconnected( Connection connection, ConnectionInfo data )
{
Console.WriteLine( $" - OnDisconnected" );
base.OnDisconnected( connection, data );
}
internal async Task RunAsync()
{
var sw = System.Diagnostics.Stopwatch.StartNew();
while ( Connected.Count == 0 )
{
await Task.Delay( 10 );
if ( sw.Elapsed.TotalSeconds > 5 )
{
Assert.Fail( "Client Took Too Long To Connect" );
break;
}
}
await Task.Delay( 1000 );
var singleClient = Connected.First();
singleClient.SendMessage( "Hey?" );
await Task.Delay( 100 );
singleClient.SendMessage( "Anyone?" );
await Task.Delay( 100 );
singleClient.SendMessage( "What's this?" );
await Task.Delay( 100 );
singleClient.SendMessage( "What's your status?" );
await Task.Delay( 10 );
singleClient.SendMessage( "Greetings!!??" );
await Task.Delay( 100 );
singleClient.SendMessage( "Hello Client!?" );
sw = System.Diagnostics.Stopwatch.StartNew();
while ( Connected.Contains( singleClient ) )
{
Receive();
await Task.Delay( 100 );
if ( sw.Elapsed.TotalSeconds > 10 )
{
Assert.Fail( "Socket Took Too Long" );
break;
}
}
await Task.Delay( 1000 );
Close();
}
public override unsafe void OnMessage( Connection connection, NetIdentity identity, IntPtr data, int size, long messageNum, long recvTime, int channel )
{
// We're only sending strings, so it's fine to read this like this
var str = UTF8Encoding.UTF8.GetString( (byte*)data, size );
Console.WriteLine( $"[SOCKET][{connection}[{identity}][{messageNum}][{recvTime}][{channel}] \"{str}\"" );
if ( str.Contains( "Hello, How are you" ) )
{
connection.SendMessage( "I'm great thanks, how about yourself?" );
}
if ( str.Contains( "bye" ) )
{
connection.SendMessage( "See you later, hater." );
connection.Flush();
connection.Close( true, 10, "Said Bye" );
}
}
}
}
}

View File

@ -9,9 +9,10 @@ namespace Steamworks
{
[TestClass]
[DeploymentItem( "steam_api64.dll" )]
[DeploymentItem( "steam_api.dll" )]
public class NetworkUtilsTest
{
static string GarrysLocation = "lhr=19+1,ams=25+2/25+1,par=29+2,fra=31+3/30+1,lux=33+3,vie=44+4/41+1,waw=47+4/45+1,sto2=48+4/46+2,sto=50+5/46+2,iad=107+10/91+1,sgp=186+18,gru=252+25/234+1";
static string GarrysLocation = "lhr=4+0,ams=13+1/10+0,par=17+1/12+0,lux=17+1,fra=18+1/18+0,sto=25+2,sto2=26+2,mad=27+2,vie=31+3/30+0,iad=90+9/75+0,sgp=173+17/174+17,gru=200+20/219+0";
[TestMethod]
public async Task LocalPingLocation()

View File

@ -10,7 +10,8 @@ namespace Steamworks
{
[TestClass]
[DeploymentItem( "steam_api64.dll" )]
public class RemoteStorageTest
[DeploymentItem( "steam_api.dll" )]
public class RemoteStorageTest
{
[TestMethod]
public void Quotas()

View File

@ -11,7 +11,8 @@ namespace Steamworks
{
[TestClass]
[DeploymentItem( "steam_api64.dll" )]
public partial class ServerListTest
[DeploymentItem( "steam_api.dll" )]
public partial class ServerListTest
{
[TestMethod]
public void IpAddressConversions()

View File

@ -10,7 +10,8 @@ namespace Steamworks
{
[TestClass]
[DeploymentItem( "steam_api64.dll" )]
public class SteamMatchmakingTest
[DeploymentItem( "steam_api.dll" )]
public class SteamMatchmakingTest
{
[TestMethod]
public async Task LobbyList()

View File

@ -10,7 +10,8 @@ namespace Steamworks
{
[TestClass]
[DeploymentItem( "steam_api64.dll" )]
public class SteamNetworkingTest
[DeploymentItem( "steam_api.dll" )]
public class SteamNetworkingTest
{
[TestMethod]
public async Task SendP2PPacket()

View File

@ -10,7 +10,8 @@ namespace Steamworks
{
[TestClass]
[DeploymentItem( "steam_api64.dll" )]
public class UgcEditor
[DeploymentItem( "steam_api.dll" )]
public class UgcEditor
{
[TestMethod]
public async Task CreateFile()

View File

@ -10,7 +10,8 @@ namespace Steamworks
{
[TestClass]
[DeploymentItem( "steam_api64.dll" )]
public class UgcQueryTests
[DeploymentItem( "steam_api.dll" )]
public class UgcQueryTests
{
[TestMethod]
public async Task QueryAll()

View File

@ -10,7 +10,8 @@ namespace Steamworks
{
[TestClass]
[DeploymentItem( "steam_api64.dll" )]
public class UgcTest
[DeploymentItem( "steam_api.dll" )]
public class UgcTest
{
[TestMethod]
public void Download()

View File

@ -10,7 +10,8 @@ namespace Steamworks
{
[TestClass]
[DeploymentItem( "steam_api64.dll" )]
public class UserStatsTest
[DeploymentItem( "steam_api.dll" )]
public class UserStatsTest
{
[TestMethod]
public async Task AchievementList()

View File

@ -11,7 +11,8 @@ namespace Steamworks
{
[TestClass]
[DeploymentItem( "steam_api64.dll" )]
public class UserTest
[DeploymentItem( "steam_api.dll" )]
public class UserTest
{
[TestMethod]
public void GetVoice()

View File

@ -9,7 +9,8 @@ namespace Steamworks
{
[TestClass]
[DeploymentItem( "steam_api64.dll" )]
public class UtilsTest
[DeploymentItem( "steam_api.dll" )]
public class UtilsTest
{
[TestMethod]
public void SecondsSinceAppActive()