IAudioSessionEnumeratorTest.cs 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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 System.Runtime.InteropServices;
  25. namespace CoreAudioTests.Wasapi
  26. {
  27. /// <summary>
  28. /// Tests all methods of the IAudioSessionEnumerator interface.
  29. /// </summary>
  30. /// <remarks>
  31. /// This test class uses the context of IAudioSessionManager2 because
  32. /// that interface must be used to retrieve the IAudioSessionEnumerator instance.
  33. /// </remarks>
  34. [TestClass]
  35. public class IAudioSessionEnumeratorTest : TestClass<IAudioSessionManager2>
  36. {
  37. /// <summary>
  38. /// Tests that the count may be received, for each available session enumerator.
  39. /// </summary>
  40. [TestMethod]
  41. public void IAudioSessionEnumerator_GetCount()
  42. {
  43. var tested = false;
  44. ExecuteDeviceActivationTest(activation =>
  45. {
  46. IAudioSessionEnumerator sessionList;
  47. var result = activation.GetSessionEnumerator(out sessionList);
  48. if (result != 0) return;
  49. Manager.EnsureDisposal(sessionList);
  50. var count = Int32.MinValue;
  51. result = sessionList.GetCount(out count);
  52. AssertCoreAudio.IsHResultOk(result);
  53. Assert.AreNotEqual(Int32.MinValue, count, "The count was not received.");
  54. tested = true;
  55. });
  56. if (!tested) Assert.Inconclusive("No valid session enumerator interfaces could be created.");
  57. }
  58. /// <summary>
  59. /// Tests that each specific session may be received, for each available session enumerator.
  60. /// </summary>
  61. [TestMethod]
  62. public void IAudioSessionEnumerator_GetSession()
  63. {
  64. var tested = false;
  65. ExecuteDeviceActivationTest(activation =>
  66. {
  67. IAudioSessionEnumerator sessionList;
  68. var result = activation.GetSessionEnumerator(out sessionList);
  69. if (result != 0) return;
  70. Manager.EnsureDisposal(sessionList);
  71. Int32 count;
  72. sessionList.GetCount(out count);
  73. for (int i = 0; i < count; i++)
  74. {
  75. IAudioSessionControl session;
  76. result = sessionList.GetSession(i, out session);
  77. AssertCoreAudio.IsHResultOk(result);
  78. Manager.EnsureDisposal(session);
  79. tested = true;
  80. }
  81. });
  82. if (!tested) Assert.Inconclusive("No valid session enumerator interfaces could be created.");
  83. }
  84. }
  85. }