Facepunch.Steamworks/Facepunch.Steamworks.Test/Client/Client.cs

257 lines
7.4 KiB
C#
Raw Normal View History

2016-07-06 19:37:25 +03:00
using System;
2016-07-19 15:32:14 +03:00
using System.Diagnostics;
2016-10-07 13:07:35 +03:00
using System.IO;
2016-07-06 19:37:25 +03:00
using Microsoft.VisualStudio.TestTools.UnitTesting;
namespace Facepunch.Steamworks.Test
{
[TestClass]
2016-10-25 12:29:35 +03:00
[DeploymentItem( "steam_api.dll" )]
[DeploymentItem( "steam_api64.dll" )]
2016-07-07 14:09:03 +03:00
[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 ) )
{
2016-10-05 14:44:01 +03:00
Assert.IsTrue( client.IsValid );
2016-07-06 19:37:25 +03:00
}
}
2016-10-07 13:07:35 +03:00
[TestMethod]
2016-10-25 13:16:05 +03:00
public void Init_10()
2016-10-07 13:07:35 +03:00
{
2016-10-25 13:16:05 +03:00
for ( int i = 0; i < 10; i++ )
2016-10-07 13:07:35 +03:00
{
using ( var client = new Facepunch.Steamworks.Client( 252490 ) )
{
Assert.IsTrue( client.IsValid );
}
2016-10-07 13:50:49 +03:00
GC.Collect();
2016-10-07 13:07:35 +03:00
}
}
2016-07-06 19:37:25 +03:00
[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 ) )
{
2016-10-25 13:16:05 +03:00
Assert.IsTrue( client.IsValid );
2016-07-06 19:37:25 +03:00
var username = client.Username;
Console.WriteLine( username );
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 ) )
{
2016-10-25 13:16:05 +03:00
Assert.IsTrue( client.IsValid );
2016-07-07 15:47:47 +03:00
var steamid = client.SteamId;
Console.WriteLine( steamid );
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 );
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 ) )
{
2016-10-07 13:57:50 +03:00
for( int i=0; i<1024; i++ )
2016-07-07 16:41:28 +03:00
{
client.Update();
}
}
}
2016-10-07 13:07:35 +03:00
static MemoryStream decompressStream = new MemoryStream();
2016-07-07 16:41:28 +03:00
[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 unCompressed = 0;
int compressed = 0;
2016-07-07 16:41:28 +03:00
2016-10-07 13:07:35 +03:00
client.Voice.OnCompressedData = ( ptr, length ) =>
2016-07-07 16:41:28 +03:00
{
2016-10-07 13:07:35 +03:00
compressed += length;
if ( !client.Voice.Decompress( ptr, 0, length, decompressStream ) )
{
Assert.Fail( "Decompress returned false" );
}
2016-07-07 16:41:28 +03:00
};
2016-10-07 13:07:35 +03:00
client.Voice.OnUncompressedData = ( ptr, length ) =>
2016-07-07 16:41:28 +03:00
{
2016-10-07 13:07:35 +03:00
unCompressed += length;
2016-07-07 16:41:28 +03:00
};
client.Voice.WantsRecording = true;
var sw = Stopwatch.StartNew();
while ( sw.Elapsed.TotalSeconds < 3 )
2016-07-07 16:41:28 +03:00
{
client.Update();
System.Threading.Thread.Sleep( 10 );
}
Assert.AreNotEqual( unCompressed, 0 );
Assert.AreNotEqual( compressed, 0 );
2016-07-07 16:41:28 +03:00
// Should really be > 0 if the mic was getting audio
Console.WriteLine( "unCompressed: {0}", unCompressed );
Console.WriteLine( "compressed: {0}", compressed );
}
}
[TestMethod]
public void GetVoice_Compressed_Only()
{
using ( var client = new Facepunch.Steamworks.Client( 252490 ) )
{
int compressed = 0;
2016-10-07 13:07:35 +03:00
client.Voice.OnCompressedData = ( ptr, length ) =>
{
2016-10-07 13:07:35 +03:00
compressed += length;
};
client.Voice.WantsRecording = true;
var sw = Stopwatch.StartNew();
while ( sw.Elapsed.TotalSeconds < 3 )
{
client.Update();
System.Threading.Thread.Sleep( 10 );
}
Assert.AreNotEqual( compressed, 0 );
Console.WriteLine( "compressed: {0}", compressed );
}
}
[TestMethod]
public void GetVoice_UnCompressed_Only()
{
using ( var client = new Facepunch.Steamworks.Client( 252490 ) )
{
int unCompressed = 0;
2016-10-07 13:07:35 +03:00
client.Voice.OnUncompressedData = ( ptr, length ) =>
{
2016-10-07 13:07:35 +03:00
unCompressed += length;
};
client.Voice.WantsRecording = true;
var sw = Stopwatch.StartNew();
while ( sw.Elapsed.TotalSeconds < 3 )
{
client.Update();
System.Threading.Thread.Sleep( 10 );
}
Assert.AreNotEqual( unCompressed, 0 );
// Should really be > 0 if the mic was getting audio
Console.WriteLine( "unCompressed: {0}", unCompressed );
2016-07-07 16:41:28 +03:00
}
}
2016-07-07 18:55:08 +03:00
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 );
foreach ( var i in client.Inventory.Definitions )
{
Console.WriteLine( "{0}: {1}", i.Id, i.Name );
}
}
2016-07-13 17:30:51 +03:00
}
[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
2016-07-19 15:32:14 +03:00
var timeout = Stopwatch.StartNew();
2016-07-13 17:30:51 +03:00
while ( client.Inventory.Items == null )
{
client.Update();
2016-07-19 15:32:14 +03:00
System.Threading.Thread.Sleep( 1000 );
if ( timeout.Elapsed.TotalSeconds > 5 )
break;
2016-07-13 17:30:51 +03:00
}
// 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
}
}