IAudioSessionControlTest.cs 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  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 IAudioSessionControl interface.
  29. /// </summary>
  30. [TestClass]
  31. public class IAudioSessionControlTest : TestClass<IAudioSessionControl>
  32. {
  33. /// <summary>
  34. /// Tests that the icon path may be received, for each available audio client.
  35. /// </summary>
  36. [TestMethod]
  37. public void IAudioSessionControl_GetIconPath()
  38. {
  39. ExecuteServiceTest(service =>
  40. {
  41. string iconPath = "abc123";
  42. var result = service.GetIconPath(out iconPath);
  43. AssertCoreAudio.IsHResultOk(result);
  44. Assert.AreNotEqual("abc123", iconPath, "The icon path was not received.");
  45. });
  46. }
  47. /// <summary>
  48. /// Tests that the display name may be received, for each available audio client.
  49. /// </summary>
  50. [TestMethod]
  51. public void IAudioSessionControl_GetDisplayName()
  52. {
  53. ExecuteServiceTest(service =>
  54. {
  55. string displayName = "abc123";
  56. var result = service.GetDisplayName(out displayName);
  57. AssertCoreAudio.IsHResultOk(result);
  58. Assert.AreNotEqual("abc123", displayName, "The display name was not received.");
  59. });
  60. }
  61. /// <summary>
  62. /// Tests that the grouping parameter may be received, for each available audio client.
  63. /// </summary>
  64. [TestMethod]
  65. public void IAudioSessionControl_GetGroupingParam()
  66. {
  67. ExecuteServiceTest(service =>
  68. {
  69. var groupingId = Guid.NewGuid();
  70. var guidOrig = new Guid(groupingId.ToByteArray());
  71. var result = service.GetGroupingParam(out groupingId);
  72. AssertCoreAudio.IsHResultOk(result);
  73. Assert.AreNotEqual(guidOrig, groupingId, "The grouping ID was not received.");
  74. });
  75. }
  76. /// <summary>
  77. /// This method is not applicable.
  78. /// </summary>
  79. [TestMethod]
  80. public void IAudioSessionControl_GetLastActivation()
  81. {
  82. // This method is not defined in audiopolicy.h file, but is on MSDN.
  83. // It appears this was removed when moving from Vista to Win7.
  84. }
  85. /// <summary>
  86. /// This method is not applicable.
  87. /// </summary>
  88. [TestMethod]
  89. public void IAudioSessionControl_GetLastInactivation()
  90. {
  91. // This method is not defined in audiopolicy.h file, but is on MSDN.
  92. // It appears this was removed when moving from Vista to Win7.
  93. }
  94. /// <summary>
  95. /// Tests that the state may be received, for each available audio client.
  96. /// </summary>
  97. [TestMethod]
  98. public void IAudioSessionControl_GetState()
  99. {
  100. ExecuteServiceTest(service =>
  101. {
  102. var stateOne = AudioSessionState.AudioSessionStateActive;
  103. var stateTwo = AudioSessionState.AudioSessionStateInactive;
  104. var result = service.GetState(out stateOne);
  105. AssertCoreAudio.IsHResultOk(result);
  106. result = service.GetState(out stateTwo);
  107. AssertCoreAudio.IsHResultOk(result);
  108. Assert.AreEqual(stateOne, stateTwo, "The state was not received.");
  109. });
  110. }
  111. /// <summary>
  112. ///
  113. /// </summary>
  114. [TestMethod]
  115. public void IAudioSessionControl_RegisterAudioSessionNotification()
  116. {
  117. Assert.Fail("TODO: Implement test for RegisterAudioSessionNotification method");
  118. }
  119. /// <summary>
  120. /// Tests that the display name may be set, for each available audio client.
  121. /// </summary>
  122. [TestMethod]
  123. public void IAudioSessionControl_SetDisplayName()
  124. {
  125. ExecuteServiceTest(service =>
  126. {
  127. var result = service.SetDisplayName("abc123", Guid.NewGuid());
  128. AssertCoreAudio.IsHResultOk(result);
  129. string nameVerify;
  130. service.GetDisplayName(out nameVerify);
  131. Assert.AreEqual("abc123", nameVerify, "The display name was not set.");
  132. });
  133. }
  134. /// <summary>
  135. /// Tests that the grouping parameter may be set, for each available audio client.
  136. /// </summary>
  137. [TestMethod]
  138. public void IAudioSessionControl_SetGroupingParam()
  139. {
  140. ExecuteServiceTest(service =>
  141. {
  142. var groupingId = Guid.NewGuid();
  143. var result = service.SetGroupingParam(groupingId, Guid.NewGuid());
  144. AssertCoreAudio.IsHResultOk(result);
  145. Guid guidVerify;
  146. service.GetGroupingParam(out guidVerify);
  147. Assert.AreEqual(groupingId, guidVerify, "The grouping ID was not set.");
  148. });
  149. }
  150. /// <summary>
  151. /// Tests that the icon path may be set, for each available audio client.
  152. /// </summary>
  153. [TestMethod]
  154. public void IAudioSessionControl_SetIconPath()
  155. {
  156. ExecuteServiceTest(service =>
  157. {
  158. var result = service.SetIconPath("abc123", Guid.NewGuid());
  159. AssertCoreAudio.IsHResultOk(result);
  160. string pathVerify;
  161. service.GetIconPath(out pathVerify);
  162. Assert.AreEqual("abc123", pathVerify, "The icon path was not set.");
  163. });
  164. }
  165. /// <summary>
  166. ///
  167. /// </summary>
  168. [TestMethod]
  169. public void IAudioSessionControl_UnregisterAudioSessionNotification()
  170. {
  171. Assert.Fail("TODO: Implement test for UnregisterAudioSessionNotification method");
  172. }
  173. }
  174. }