mirror of
https://github.com/Facepunch/Facepunch.Steamworks.git
synced 2024-12-25 06:05:46 +03:00
Splitting client tests
This commit is contained in:
parent
15bfd887bd
commit
5ac65c9fb9
@ -78,16 +78,6 @@ public void AuthSessionTicket()
|
||||
}
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void VoiceOptimalSampleRate()
|
||||
{
|
||||
using ( var client = new Facepunch.Steamworks.Client( 252490 ) )
|
||||
{
|
||||
var rate = client.Voice.OptimalSampleRate;
|
||||
Assert.AreNotEqual( rate, 0 );
|
||||
}
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void Update()
|
||||
{
|
||||
@ -103,209 +93,5 @@ public void Update()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static MemoryStream decompressStream = new MemoryStream();
|
||||
|
||||
[TestMethod]
|
||||
public void GetVoice()
|
||||
{
|
||||
using ( var client = new Facepunch.Steamworks.Client( 252490 ) )
|
||||
{
|
||||
int unCompressed = 0;
|
||||
int compressed = 0;
|
||||
|
||||
client.Voice.OnCompressedData = ( ptr, length ) =>
|
||||
{
|
||||
compressed += length;
|
||||
|
||||
if ( !client.Voice.Decompress( ptr, 0, length, decompressStream ) )
|
||||
{
|
||||
Assert.Fail( "Decompress returned false" );
|
||||
}
|
||||
};
|
||||
|
||||
client.Voice.OnUncompressedData = ( ptr, length ) =>
|
||||
{
|
||||
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 );
|
||||
Assert.AreNotEqual( compressed, 0 );
|
||||
|
||||
// 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;
|
||||
|
||||
client.Voice.OnCompressedData = ( ptr, length ) =>
|
||||
{
|
||||
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;
|
||||
|
||||
client.Voice.OnUncompressedData = ( ptr, length ) =>
|
||||
{
|
||||
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 );
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
[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.Where( x => x.PriceRaw != "" ) )
|
||||
{
|
||||
Console.WriteLine( "{0}: {1} ({2})", i.Id, i.Name, i.Type );
|
||||
Console.WriteLine( " itemshortname: {0}", i.GetStringProperty( "itemshortname" ) );
|
||||
Console.WriteLine( " workshopdownload: {0}", i.GetStringProperty( "workshopdownload" ) );
|
||||
Console.WriteLine( " IconUrl: {0}", i.IconUrl );
|
||||
Console.WriteLine( " IconLargeUrl: {0}", i.IconLargeUrl );
|
||||
Console.WriteLine( " PriceRaw: {0}", i.PriceRaw );
|
||||
Console.WriteLine( " PriceDollars: {0}", i.PriceDollars );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void InventoryDefinitionExchange()
|
||||
{
|
||||
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 )
|
||||
{
|
||||
if ( i.Recipes == null ) continue;
|
||||
|
||||
Console.WriteLine( "Ways To Create " + i.Name );
|
||||
|
||||
foreach ( var r in i.Recipes )
|
||||
{
|
||||
Console.WriteLine( " " + string.Join( ", ", r.Ingredients.Select( x => x.Count + " x " + x.Definition.Name ) ) );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void InventoryDefinitionIngredients()
|
||||
{
|
||||
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 )
|
||||
{
|
||||
if ( i.IngredientFor == null ) continue;
|
||||
|
||||
Console.WriteLine( i.Name + " Can Be Used to Make" );
|
||||
|
||||
foreach ( var r in i.IngredientFor )
|
||||
{
|
||||
Console.WriteLine( " " + r.Result.Name );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
[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
|
||||
var timeout = Stopwatch.StartNew();
|
||||
while ( client.Inventory.Items == null )
|
||||
{
|
||||
client.Update();
|
||||
System.Threading.Thread.Sleep( 1000 );
|
||||
|
||||
if ( timeout.Elapsed.TotalSeconds > 5 )
|
||||
break;
|
||||
}
|
||||
|
||||
// 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 );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
117
Facepunch.Steamworks.Test/Client/Inventory.cs
Normal file
117
Facepunch.Steamworks.Test/Client/Inventory.cs
Normal file
@ -0,0 +1,117 @@
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
using System.Linq;
|
||||
|
||||
namespace Facepunch.Steamworks.Test
|
||||
{
|
||||
[DeploymentItem( "steam_api.dll" )]
|
||||
[DeploymentItem( "steam_api64.dll" )]
|
||||
[DeploymentItem( "steam_appid.txt" )]
|
||||
[TestClass]
|
||||
public class Inventory
|
||||
{
|
||||
[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.Where( x => x.PriceRaw != "" ) )
|
||||
{
|
||||
Console.WriteLine( "{0}: {1} ({2})", i.Id, i.Name, i.Type );
|
||||
Console.WriteLine( " itemshortname: {0}", i.GetStringProperty( "itemshortname" ) );
|
||||
Console.WriteLine( " workshopdownload: {0}", i.GetStringProperty( "workshopdownload" ) );
|
||||
Console.WriteLine( " IconUrl: {0}", i.IconUrl );
|
||||
Console.WriteLine( " IconLargeUrl: {0}", i.IconLargeUrl );
|
||||
Console.WriteLine( " PriceRaw: {0}", i.PriceRaw );
|
||||
Console.WriteLine( " PriceDollars: {0}", i.PriceDollars );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void InventoryDefinitionExchange()
|
||||
{
|
||||
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 )
|
||||
{
|
||||
if ( i.Recipes == null ) continue;
|
||||
|
||||
Console.WriteLine( "Ways To Create " + i.Name );
|
||||
|
||||
foreach ( var r in i.Recipes )
|
||||
{
|
||||
Console.WriteLine( " " + string.Join( ", ", r.Ingredients.Select( x => x.Count + " x " + x.Definition.Name ) ) );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void InventoryDefinitionIngredients()
|
||||
{
|
||||
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 )
|
||||
{
|
||||
if ( i.IngredientFor == null ) continue;
|
||||
|
||||
Console.WriteLine( i.Name + " Can Be Used to Make" );
|
||||
|
||||
foreach ( var r in i.IngredientFor )
|
||||
{
|
||||
Console.WriteLine( " " + r.Result.Name );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
[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
|
||||
var timeout = Stopwatch.StartNew();
|
||||
while ( client.Inventory.Items == null )
|
||||
{
|
||||
client.Update();
|
||||
System.Threading.Thread.Sleep( 1000 );
|
||||
|
||||
if ( timeout.Elapsed.TotalSeconds > 10 )
|
||||
break;
|
||||
}
|
||||
|
||||
// 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 );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
125
Facepunch.Steamworks.Test/Client/Voice.cs
Normal file
125
Facepunch.Steamworks.Test/Client/Voice.cs
Normal file
@ -0,0 +1,125 @@
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
|
||||
namespace Facepunch.Steamworks.Test
|
||||
{
|
||||
[DeploymentItem( "steam_api.dll" )]
|
||||
[DeploymentItem( "steam_api64.dll" )]
|
||||
[DeploymentItem( "steam_appid.txt" )]
|
||||
[TestClass]
|
||||
public class Voice
|
||||
{
|
||||
static readonly MemoryStream decompressStream = new MemoryStream();
|
||||
|
||||
[TestMethod]
|
||||
public void GetVoice()
|
||||
{
|
||||
using ( var client = new Facepunch.Steamworks.Client( 252490 ) )
|
||||
{
|
||||
int unCompressed = 0;
|
||||
int compressed = 0;
|
||||
|
||||
client.Voice.OnCompressedData = ( ptr, length ) =>
|
||||
{
|
||||
compressed += length;
|
||||
|
||||
if ( !client.Voice.Decompress( ptr, 0, length, decompressStream ) )
|
||||
{
|
||||
Assert.Fail( "Decompress returned false" );
|
||||
}
|
||||
};
|
||||
|
||||
client.Voice.OnUncompressedData = ( ptr, length ) =>
|
||||
{
|
||||
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 );
|
||||
Assert.AreNotEqual( compressed, 0 );
|
||||
|
||||
// Should really be > 0 if the mic was getting audio
|
||||
Console.WriteLine( "unCompressed: {0}", unCompressed );
|
||||
Console.WriteLine( "compressed: {0}", compressed );
|
||||
}
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void CompressedOnly()
|
||||
{
|
||||
using ( var client = new Facepunch.Steamworks.Client( 252490 ) )
|
||||
{
|
||||
int compressed = 0;
|
||||
|
||||
client.Voice.OnCompressedData = ( ptr, length ) =>
|
||||
{
|
||||
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 UnCompressedOnly()
|
||||
{
|
||||
using ( var client = new Facepunch.Steamworks.Client( 252490 ) )
|
||||
{
|
||||
int unCompressed = 0;
|
||||
|
||||
client.Voice.OnUncompressedData = ( ptr, length ) =>
|
||||
{
|
||||
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 );
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void OptimalSampleRate()
|
||||
{
|
||||
using ( var client = new Facepunch.Steamworks.Client( 252490 ) )
|
||||
{
|
||||
var rate = client.Voice.OptimalSampleRate;
|
||||
Assert.AreNotEqual( rate, 0 );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -93,6 +93,8 @@
|
||||
</Choose>
|
||||
<ItemGroup>
|
||||
<Compile Include="Client\Client.cs" />
|
||||
<Compile Include="Client\Voice.cs" />
|
||||
<Compile Include="Client\Inventory.cs" />
|
||||
<Compile Include="Client\Workshop.cs" />
|
||||
<Compile Include="Client\Networking.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
|
Loading…
Reference in New Issue
Block a user