2019-05-02 17:23:47 +03:00
|
|
|
|
using System;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Threading;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
|
|
|
|
|
|
|
|
|
namespace Steamworks
|
|
|
|
|
{
|
|
|
|
|
[TestClass]
|
|
|
|
|
[DeploymentItem( "steam_api64.dll" )]
|
2020-02-22 23:29:37 +03:00
|
|
|
|
[DeploymentItem( "steam_api.dll" )]
|
2019-05-02 17:23:47 +03:00
|
|
|
|
public class NetworkUtilsTest
|
|
|
|
|
{
|
2020-02-22 23:29:37 +03:00
|
|
|
|
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";
|
2019-05-02 17:23:47 +03:00
|
|
|
|
|
|
|
|
|
[TestMethod]
|
|
|
|
|
public async Task LocalPingLocation()
|
|
|
|
|
{
|
|
|
|
|
await SteamNetworkingUtils.WaitForPingDataAsync();
|
|
|
|
|
|
|
|
|
|
for ( int i = 0; i < 10; i++ )
|
|
|
|
|
{
|
|
|
|
|
var pl = SteamNetworkingUtils.LocalPingLocation;
|
|
|
|
|
if ( !pl.HasValue )
|
|
|
|
|
{
|
|
|
|
|
await Task.Delay( 1000 );
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Console.WriteLine( $"{i} Seconds Until Result: {pl}" );
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Assert.Fail();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[TestMethod]
|
|
|
|
|
public void PingLocationParse()
|
|
|
|
|
{
|
2020-02-24 11:58:09 +03:00
|
|
|
|
var pl = Data.NetPingLocation.TryParseFromString( GarrysLocation );
|
2019-05-02 17:23:47 +03:00
|
|
|
|
|
|
|
|
|
Assert.IsTrue( pl.HasValue );
|
|
|
|
|
|
|
|
|
|
Console.WriteLine( $"Parsed OKAY! {pl}" );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[TestMethod]
|
|
|
|
|
public async Task GetEstimatedPing()
|
|
|
|
|
{
|
|
|
|
|
await SteamNetworkingUtils.WaitForPingDataAsync();
|
|
|
|
|
|
2020-02-24 11:58:09 +03:00
|
|
|
|
var garrysping = Data.NetPingLocation.TryParseFromString( GarrysLocation );
|
2019-05-02 17:23:47 +03:00
|
|
|
|
Assert.IsTrue( garrysping.HasValue );
|
|
|
|
|
|
|
|
|
|
var ping = SteamNetworkingUtils.EstimatePingTo( garrysping.Value );
|
|
|
|
|
Assert.IsTrue( ping > 0 );
|
|
|
|
|
|
|
|
|
|
Console.WriteLine( $"Ping returned: {ping}" );
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-02-22 23:29:37 +03:00
|
|
|
|
}
|