From 5ac65c9fb910b4666146d4d78bf48e73e6d334a0 Mon Sep 17 00:00:00 2001 From: Garry Newman Date: Thu, 1 Dec 2016 11:17:03 +0000 Subject: [PATCH] Splitting client tests --- Facepunch.Steamworks.Test/Client/Client.cs | 214 ------------------ Facepunch.Steamworks.Test/Client/Inventory.cs | 117 ++++++++++ Facepunch.Steamworks.Test/Client/Voice.cs | 125 ++++++++++ .../Facepunch.Steamworks.Test.csproj | 2 + 4 files changed, 244 insertions(+), 214 deletions(-) create mode 100644 Facepunch.Steamworks.Test/Client/Inventory.cs create mode 100644 Facepunch.Steamworks.Test/Client/Voice.cs diff --git a/Facepunch.Steamworks.Test/Client/Client.cs b/Facepunch.Steamworks.Test/Client/Client.cs index 359fb48..b466d6a 100644 --- a/Facepunch.Steamworks.Test/Client/Client.cs +++ b/Facepunch.Steamworks.Test/Client/Client.cs @@ -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 ); - } - } - } } } diff --git a/Facepunch.Steamworks.Test/Client/Inventory.cs b/Facepunch.Steamworks.Test/Client/Inventory.cs new file mode 100644 index 0000000..d9c65c2 --- /dev/null +++ b/Facepunch.Steamworks.Test/Client/Inventory.cs @@ -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 ); + } + } + } + } +} diff --git a/Facepunch.Steamworks.Test/Client/Voice.cs b/Facepunch.Steamworks.Test/Client/Voice.cs new file mode 100644 index 0000000..46c4c8a --- /dev/null +++ b/Facepunch.Steamworks.Test/Client/Voice.cs @@ -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 ); + } + } + } +} diff --git a/Facepunch.Steamworks.Test/Facepunch.Steamworks.Test.csproj b/Facepunch.Steamworks.Test/Facepunch.Steamworks.Test.csproj index 673b7b3..250379b 100644 --- a/Facepunch.Steamworks.Test/Facepunch.Steamworks.Test.csproj +++ b/Facepunch.Steamworks.Test/Facepunch.Steamworks.Test.csproj @@ -93,6 +93,8 @@ + +