From 2ea8585c4828481c16867402567101f51d1acb8f Mon Sep 17 00:00:00 2001 From: Garry Newman Date: Mon, 15 Apr 2019 11:06:32 +0100 Subject: [PATCH] User Test --- Facepunch.Steamworks.Test/Client/AppTest.cs | 4 +- Facepunch.Steamworks.Test/Client/UserTest.cs | 119 +++++++++++++++++ Facepunch.Steamworks.Test/Client/VoiceTest.cs | 123 ------------------ .../Facepunch.Steamworks.Test.csproj | 2 +- Facepunch.Steamworks/Redux/Apps.cs | 2 +- Facepunch.Steamworks/Redux/User.cs | 22 ++-- 6 files changed, 136 insertions(+), 136 deletions(-) create mode 100644 Facepunch.Steamworks.Test/Client/UserTest.cs delete mode 100644 Facepunch.Steamworks.Test/Client/VoiceTest.cs diff --git a/Facepunch.Steamworks.Test/Client/AppTest.cs b/Facepunch.Steamworks.Test/Client/AppTest.cs index a796796..f9bc8ce 100644 --- a/Facepunch.Steamworks.Test/Client/AppTest.cs +++ b/Facepunch.Steamworks.Test/Client/AppTest.cs @@ -69,7 +69,7 @@ public void InstalledDepots() [TestMethod] public async Task GetFileDetails() { - var fileinfo = await Apps.GetFileDetails( "hl2.exe" ); + var fileinfo = await Apps.GetFileDetailsAsync( "hl2.exe" ); Console.WriteLine( $"fileinfo.Found: {fileinfo.Found}" ); Console.WriteLine( $"fileinfo.SizeInBytes: {fileinfo.SizeInBytes}" ); @@ -78,7 +78,7 @@ public async Task GetFileDetails() } [TestMethod] - public async Task CommandLine() + public void CommandLine() { var cl = Apps.CommandLine; diff --git a/Facepunch.Steamworks.Test/Client/UserTest.cs b/Facepunch.Steamworks.Test/Client/UserTest.cs new file mode 100644 index 0000000..3c1e54e --- /dev/null +++ b/Facepunch.Steamworks.Test/Client/UserTest.cs @@ -0,0 +1,119 @@ +using System; +using System.Diagnostics; +using System.IO; +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" )] + public class UserTest + { + [TestMethod] + public void GetVoice() + { + using ( var stream = new MemoryStream() ) + { + int compressed = 0; + + User.VoiceRecord = true; + + var sw = Stopwatch.StartNew(); + + while ( sw.Elapsed.TotalSeconds < 3 ) + { + System.Threading.Thread.Sleep( 10 ); + compressed += User.ReadVoiceData( stream ); + } + + Assert.AreEqual( compressed, stream.Length ); + Console.WriteLine( $"compressed: {compressed}", compressed ); + Console.WriteLine( $"stream.Length: {stream.Length}", stream.Length ); + } + } + [TestMethod] + public void OptimalSampleRate() + { + var rate = User.OptimalSampleRate; + Assert.AreNotEqual( rate, 0 ); + Console.WriteLine( $"User.OptimalSampleRate: {User.OptimalSampleRate}" ); + } + + [TestMethod] + public void IsLoggedOn() + { + Assert.AreNotEqual( false, User.IsLoggedOn ); + Console.WriteLine( $"User.IsLoggedOn: {User.IsLoggedOn}" ); + } + + [TestMethod] + public void SteamID() + { + Assert.AreNotEqual( 0, User.SteamID.Value ); + Console.WriteLine( $"User.SteamID: {User.SteamID.Value}" ); + } + + [TestMethod] + public void AuthSession() + { + var ticket = User.GetAuthSessionTicket(); + + Assert.AreNotEqual( 0, ticket.Handle ); + Assert.AreNotEqual( 0, ticket.Data.Length ); + Console.WriteLine( $"ticket.Handle: {ticket.Handle}" ); + Console.WriteLine( $"ticket.Data: { string.Join( "", ticket.Data.Select( x => x.ToString( "x" ) ) ) }" ); + + var result = User.BeginAuthSession( ticket.Data, User.SteamID ); + Console.WriteLine( $"result: { result }" ); + Assert.AreEqual( result, SteamNative.BeginAuthSessionResult.OK ); + + User.EndAuthSession( User.SteamID ); + } + + + [TestMethod] + public void SteamLevel() + { + Assert.AreNotEqual( 0, User.SteamLevel ); + Console.WriteLine( $"User.SteamLevel: {User.SteamLevel}" ); + } + + [TestMethod] + public async Task GetStoreAuthUrlAsync() + { + var rustskins = await User.GetStoreAuthUrlAsync( "https://store.steampowered.com/itemstore/252490/" ); + + Assert.IsNotNull( rustskins ); + Console.WriteLine( $"rustskins: {rustskins}" ); + } + + [TestMethod] + public void IsPhoneVerified() + { + Console.WriteLine( $"User.IsPhoneVerified: {User.IsPhoneVerified}" ); + } + + [TestMethod] + public void IsTwoFactorEnabled() + { + Console.WriteLine( $"User.IsTwoFactorEnabled: {User.IsTwoFactorEnabled}" ); + } + + [TestMethod] + public void IsPhoneIdentifying() + { + Console.WriteLine( $"User.IsPhoneIdentifying: {User.IsPhoneIdentifying}" ); + } + + [TestMethod] + public void IsPhoneRequiringVerification() + { + Console.WriteLine( $"User.IsPhoneRequiringVerification: {User.IsPhoneRequiringVerification}" ); + } + } + +} diff --git a/Facepunch.Steamworks.Test/Client/VoiceTest.cs b/Facepunch.Steamworks.Test/Client/VoiceTest.cs deleted file mode 100644 index 18f6543..0000000 --- a/Facepunch.Steamworks.Test/Client/VoiceTest.cs +++ /dev/null @@ -1,123 +0,0 @@ -using System; -using System.Diagnostics; -using System.IO; -using Microsoft.VisualStudio.TestTools.UnitTesting; - -namespace Facepunch.Steamworks.Test -{ - [DeploymentItem( "steam_api64.dll" )] - [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 = ( buffer, length ) => - { - compressed += length; - - if ( !client.Voice.Decompress( buffer, length, decompressStream ) ) - { - Assert.Fail( "Decompress returned false" ); - } - }; - - client.Voice.OnUncompressedData = ( buffer, 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 = ( buffer, 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 = ( buffer, 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 0695875..8e500dd 100644 --- a/Facepunch.Steamworks.Test/Facepunch.Steamworks.Test.csproj +++ b/Facepunch.Steamworks.Test/Facepunch.Steamworks.Test.csproj @@ -89,6 +89,7 @@ + @@ -96,7 +97,6 @@ - diff --git a/Facepunch.Steamworks/Redux/Apps.cs b/Facepunch.Steamworks/Redux/Apps.cs index d06b4bf..02c3dbe 100644 --- a/Facepunch.Steamworks/Redux/Apps.cs +++ b/Facepunch.Steamworks/Redux/Apps.cs @@ -235,7 +235,7 @@ public static DownloadProgress DlcDownloadProgress( AppId appid ) /// Asynchronously retrieves metadata details about a specific file in the depot manifest. /// Currently provides: /// - public static async Task GetFileDetails( string filename ) + public static async Task GetFileDetailsAsync( string filename ) { var r = await Internal.GetFileDetails( filename ); diff --git a/Facepunch.Steamworks/Redux/User.cs b/Facepunch.Steamworks/Redux/User.cs index 68766cd..15d0f57 100644 --- a/Facepunch.Steamworks/Redux/User.cs +++ b/Facepunch.Steamworks/Redux/User.cs @@ -121,20 +121,24 @@ internal static void InstallEvents() public static CSteamID SteamID => Internal.GetSteamID(); + static bool _recordingVoice; + /// - /// Starts voice recording. + /// Starts/Stops voice recording. /// Once started, use GetAvailableVoice and GetVoice to get the data, and then call StopVoiceRecording /// when the user has released their push-to-talk hotkey or the game session has completed. /// - public static void StartVoiceRecording() => Internal.StartVoiceRecording(); - /// - /// Stops voice recording. - /// Because people often release push-to-talk keys early, the system will keep recording for a little bit - /// after this function is called.As such, GetVoice should continue to be called until it returns k_EVoiceResultNotRecording, - /// only then will voice recording be stopped. - /// - public static void StopVoiceRecording() => Internal.StopVoiceRecording(); + public static bool VoiceRecord + { + get => _recordingVoice; + set + { + _recordingVoice = value; + if ( value ) Internal.StartVoiceRecording(); + else Internal.StopVoiceRecording(); + } + } ///