IAudioClock2Test.cs 3.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. // -----------------------------------------
  2. // SoundScribe (TM) and related software.
  3. //
  4. // Copyright (C) 2007-2011 Vannatech
  5. // http://www.vannatech.com
  6. // All rights reserved.
  7. //
  8. // This source code is subject to the MIT License.
  9. // http://www.opensource.org/licenses/mit-license.php
  10. //
  11. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  12. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  13. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  14. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  15. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  16. // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  17. // THE SOFTWARE.
  18. // -----------------------------------------
  19. using System;
  20. using CoreAudioTests.Common;
  21. using Microsoft.VisualStudio.TestTools.UnitTesting;
  22. using Vannatech.CoreAudio.Interfaces;
  23. using Vannatech.CoreAudio.Constants;
  24. using Vannatech.CoreAudio.Enumerations;
  25. namespace CoreAudioTests.Wasapi
  26. {
  27. /// <summary>
  28. /// Tests all methods of the IAudioClock2 interface.
  29. /// </summary>
  30. [TestClass]
  31. public class IAudioClock2Test
  32. {
  33. /// <summary>
  34. /// Tests that the device position may be received, for each available audio client.
  35. /// </summary>
  36. [TestMethod]
  37. public void IAudioClock2_GetDevicePosition()
  38. {
  39. var result = 0;
  40. var tested = false;
  41. var exclusive = false;
  42. //beginTest:
  43. var audioClients = TestUtilities.CreateAudioClientServiceCollection<IAudioClock>(ComIIDs.IAudioClockIID, exclusive);
  44. try
  45. {
  46. foreach (var ac in audioClients)
  47. {
  48. // Start the audio client.
  49. result = ac.AudioClient.Start();
  50. if (result != 0) continue;
  51. // Slight delay is required.
  52. System.Threading.Thread.Sleep(100);
  53. UInt64 devicePos = UInt64.MaxValue;
  54. UInt64 counterPos = UInt64.MaxValue;
  55. var clock2 = (IAudioClock2)ac.ServiceInterface;
  56. result = clock2.GetDevicePosition(out devicePos, out counterPos);
  57. ac.AudioClient.Stop();
  58. // Not all IAudioClock instances support IAudioClock2.
  59. if ((uint)result == TestUtilities.HRESULTS.E_NOINTERFACE) continue;
  60. AssertCoreAudio.IsHResultOk(result);
  61. // TODO: Determine if these tests need to exist. Method doesn't always set the output variables.
  62. //Assert.AreNotEqual(UInt64.MaxValue, devicePos, (exclusive ? "Exclusive Mode: " : "Shared Mode: ") + "The device position was not received.");
  63. //Assert.AreNotEqual(UInt64.MaxValue, counterPos, (exclusive ? "Exclusive Mode: " : "Shared Mode: ") + "The counter position was not received.");
  64. tested = true;
  65. }
  66. }
  67. finally
  68. {
  69. foreach (var ac in audioClients)
  70. ac.Dispose();
  71. }
  72. if (!tested) Assert.Inconclusive((exclusive ? "Exclusive Mode: " : "Shared Mode: ") + "No valid calls to GetDevicePosition were made without WASAPI errors.");
  73. // TODO: Determine if this should work in exclusive mode. All calls to QueryInterface (from IAudioClock to IAudioClock2) currently return E_NOINTERFACE.
  74. //if (!exclusive)
  75. //{
  76. // // Rerun test in exclusive mode.
  77. // tested = false;
  78. // exclusive = true;
  79. // goto beginTest;
  80. //}
  81. }
  82. }
  83. }