2016-07-06 19:37:25 +03:00
|
|
|
|
using System;
|
|
|
|
|
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
|
|
|
|
|
|
|
|
|
namespace Facepunch.Steamworks.Test
|
|
|
|
|
{
|
|
|
|
|
[TestClass]
|
2016-07-07 14:09:03 +03:00
|
|
|
|
[DeploymentItem( "FacepunchSteamworksApi.dll" )]
|
|
|
|
|
[DeploymentItem( "steam_appid.txt" )]
|
2016-07-13 19:14:16 +03:00
|
|
|
|
public partial class Client
|
2016-07-06 19:37:25 +03:00
|
|
|
|
{
|
|
|
|
|
[TestMethod]
|
2016-07-07 18:55:08 +03:00
|
|
|
|
public void Init()
|
2016-07-06 19:37:25 +03:00
|
|
|
|
{
|
|
|
|
|
using ( var client = new Facepunch.Steamworks.Client( 252490 ) )
|
|
|
|
|
{
|
|
|
|
|
Assert.IsTrue( client.Valid );
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[TestMethod]
|
2016-07-07 18:55:08 +03:00
|
|
|
|
public void Name()
|
2016-07-06 19:37:25 +03:00
|
|
|
|
{
|
|
|
|
|
using ( var client = new Facepunch.Steamworks.Client( 252490 ) )
|
|
|
|
|
{
|
|
|
|
|
var username = client.Username;
|
|
|
|
|
Console.WriteLine( username );
|
|
|
|
|
Assert.IsTrue( client.Valid );
|
2016-07-07 15:47:47 +03:00
|
|
|
|
Assert.IsNotNull( username );
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[TestMethod]
|
2016-07-07 18:55:08 +03:00
|
|
|
|
public void SteamId()
|
2016-07-07 15:47:47 +03:00
|
|
|
|
{
|
|
|
|
|
using ( var client = new Facepunch.Steamworks.Client( 252490 ) )
|
|
|
|
|
{
|
|
|
|
|
var steamid = client.SteamId;
|
|
|
|
|
Console.WriteLine( steamid );
|
|
|
|
|
Assert.IsTrue( client.Valid );
|
|
|
|
|
Assert.AreNotEqual( 0, steamid );
|
2016-07-06 19:37:25 +03:00
|
|
|
|
}
|
|
|
|
|
}
|
2016-07-07 16:04:15 +03:00
|
|
|
|
|
|
|
|
|
[TestMethod]
|
2016-07-07 18:55:08 +03:00
|
|
|
|
public void AuthSessionTicket()
|
2016-07-07 16:04:15 +03:00
|
|
|
|
{
|
|
|
|
|
using ( var client = new Facepunch.Steamworks.Client( 252490 ) )
|
|
|
|
|
{
|
2016-07-07 16:11:23 +03:00
|
|
|
|
var ticket = client.Auth.GetAuthSessionTicket();
|
2016-07-07 16:04:15 +03:00
|
|
|
|
|
|
|
|
|
Assert.IsTrue( ticket != null );
|
|
|
|
|
Assert.IsTrue( ticket.Handle != 0 );
|
|
|
|
|
Assert.IsTrue( ticket.Data.Length > 0 );
|
|
|
|
|
|
2016-07-15 19:26:06 +03:00
|
|
|
|
ticket.Cancel();
|
2016-07-07 16:04:15 +03:00
|
|
|
|
|
|
|
|
|
Assert.IsTrue( ticket.Handle == 0 );
|
|
|
|
|
}
|
|
|
|
|
}
|
2016-07-07 16:15:09 +03:00
|
|
|
|
|
|
|
|
|
[TestMethod]
|
2016-07-07 18:55:08 +03:00
|
|
|
|
public void VoiceOptimalSampleRate()
|
2016-07-07 16:15:09 +03:00
|
|
|
|
{
|
|
|
|
|
using ( var client = new Facepunch.Steamworks.Client( 252490 ) )
|
|
|
|
|
{
|
|
|
|
|
var rate = client.Voice.OptimalSampleRate;
|
|
|
|
|
Assert.AreNotEqual( rate, 0 );
|
|
|
|
|
}
|
|
|
|
|
}
|
2016-07-07 16:41:28 +03:00
|
|
|
|
|
|
|
|
|
[TestMethod]
|
2016-07-07 18:55:08 +03:00
|
|
|
|
public void Update()
|
2016-07-07 16:41:28 +03:00
|
|
|
|
{
|
|
|
|
|
using ( var client = new Facepunch.Steamworks.Client( 252490 ) )
|
|
|
|
|
{
|
|
|
|
|
for( int i=0; i<32; i++ )
|
|
|
|
|
{
|
|
|
|
|
client.Update();
|
|
|
|
|
System.Threading.Thread.Sleep( 10 );
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[TestMethod]
|
2016-07-07 18:55:08 +03:00
|
|
|
|
public void GetVoice()
|
2016-07-07 16:41:28 +03:00
|
|
|
|
{
|
|
|
|
|
using ( var client = new Facepunch.Steamworks.Client( 252490 ) )
|
|
|
|
|
{
|
|
|
|
|
int dataRead = 0;
|
|
|
|
|
|
|
|
|
|
client.Voice.OnCompressedData = ( data ) =>
|
|
|
|
|
{
|
|
|
|
|
dataRead += data.Length;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
client.Voice.OnUncompressedData = ( data ) =>
|
|
|
|
|
{
|
|
|
|
|
dataRead += data.Length;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
client.Voice.WantsRecording = true;
|
|
|
|
|
|
|
|
|
|
for ( int i = 0; i < 32; i++ )
|
|
|
|
|
{
|
|
|
|
|
client.Update();
|
|
|
|
|
System.Threading.Thread.Sleep( 10 );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Should really be > 0 if the mic was getting audio
|
|
|
|
|
Console.Write( dataRead );
|
|
|
|
|
}
|
|
|
|
|
}
|
2016-07-07 18:55:08 +03:00
|
|
|
|
|
|
|
|
|
[TestMethod]
|
|
|
|
|
public void GetServers()
|
|
|
|
|
{
|
|
|
|
|
using ( var client = new Facepunch.Steamworks.Client( 252490 ) )
|
|
|
|
|
{
|
|
|
|
|
var query = client.ServerList.Test();
|
|
|
|
|
|
|
|
|
|
for ( int i = 0; i < 100 ; i++ )
|
|
|
|
|
{
|
|
|
|
|
client.Update();
|
|
|
|
|
System.Threading.Thread.Sleep( 5 );
|
|
|
|
|
|
|
|
|
|
if ( query.Finished )
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Console.WriteLine( "Responded: " + query.Responded.Count.ToString() );
|
|
|
|
|
Console.WriteLine( "Unresponsive: " + query.Unresponsive.Count.ToString() );
|
|
|
|
|
}
|
|
|
|
|
}
|
2016-07-13 17:30:51 +03:00
|
|
|
|
|
|
|
|
|
[TestMethod]
|
|
|
|
|
public void InventoryDefinitions()
|
|
|
|
|
{
|
|
|
|
|
using ( var client = new Facepunch.Steamworks.Client( 252490 ) )
|
|
|
|
|
{
|
|
|
|
|
Assert.IsNotNull( client.Inventory.Definitions );
|
|
|
|
|
Assert.AreNotEqual( 0, client.Inventory.Definitions.Length );
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[TestMethod]
|
|
|
|
|
public void InventoryItemList()
|
|
|
|
|
{
|
|
|
|
|
using ( var client = new Facepunch.Steamworks.Client( 252490 ) )
|
|
|
|
|
{
|
|
|
|
|
bool CallbackCalled = false;
|
|
|
|
|
|
|
|
|
|
// OnUpdate hsould be called when we receive a list of our items
|
|
|
|
|
client.Inventory.OnUpdate = () => { CallbackCalled = true; };
|
|
|
|
|
|
|
|
|
|
// tell steam to download the items
|
|
|
|
|
client.Inventory.Refresh();
|
|
|
|
|
|
|
|
|
|
// Wait for the items
|
|
|
|
|
while ( client.Inventory.Items == null )
|
|
|
|
|
{
|
|
|
|
|
client.Update();
|
|
|
|
|
System.Threading.Thread.Sleep( 10 );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// make sure callback was called
|
|
|
|
|
Assert.IsTrue( CallbackCalled );
|
|
|
|
|
|
|
|
|
|
// Make sure items are valid
|
|
|
|
|
foreach ( var item in client.Inventory.Items )
|
|
|
|
|
{
|
|
|
|
|
Assert.IsNotNull( item );
|
|
|
|
|
Assert.IsNotNull( item.Definition );
|
|
|
|
|
|
|
|
|
|
Console.WriteLine( item.Definition.Name + " - " + item.Id );
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2016-07-06 19:37:25 +03:00
|
|
|
|
}
|
|
|
|
|
}
|