IPartTest.cs 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270
  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. using System.Runtime.InteropServices;
  26. namespace CoreAudioTests.DeviceTopologyApi
  27. {
  28. /// <summary>
  29. /// Tests all methods of the IPart interface.
  30. /// </summary>
  31. [TestClass]
  32. public class IPartTest : TestClass<IPart>
  33. {
  34. /// <summary>
  35. /// Tests that any valid interface can be activated, for each available part in the system.
  36. /// </summary>
  37. [TestMethod]
  38. public void IPart_Activate()
  39. {
  40. // There's should be no need to test this method. It's implicitly tested through other classes which require this method to work.
  41. // TODO: Add a test (low priority).
  42. }
  43. /// <summary>
  44. /// Tests that an incoming parts list may be enumerated, for each applicable part in the system.
  45. /// </summary>
  46. [TestMethod]
  47. public void IPart_EnumPartsIncoming()
  48. {
  49. ExecuteCustomTest(new PartTestManager(), part =>
  50. {
  51. IPartsList partsList;
  52. var result = part.EnumPartsIncoming(out partsList);
  53. Manager.EnsureDisposal(partsList);
  54. // HRESULT of E_NOTFOUND is valid when no incoming parts exist.
  55. if ((uint)result == TestUtilities.HRESULTS.E_NOTFOUND) return;
  56. AssertCoreAudio.IsHResultOk(result);
  57. });
  58. }
  59. /// <summary>
  60. /// Tests that an incoming parts list may be enumerated, for each applicable part in the system.
  61. /// </summary>
  62. [TestMethod]
  63. public void IPart_EnumPartsOutgoing()
  64. {
  65. ExecuteCustomTest(new PartTestManager(), part =>
  66. {
  67. IPartsList partsList;
  68. var result = part.EnumPartsOutgoing(out partsList);
  69. Manager.EnsureDisposal(partsList);
  70. // HRESULT of E_NOTFOUND is valid when no outgoing parts exist.
  71. if ((uint)result == TestUtilities.HRESULTS.E_NOTFOUND) return;
  72. AssertCoreAudio.IsHResultOk(result);
  73. });
  74. }
  75. /// <summary>
  76. /// Tests that a control interface can be received, for each available part in the system.
  77. /// </summary>
  78. [TestMethod]
  79. public void IPart_GetControlInterface()
  80. {
  81. var tested = false;
  82. ExecuteCustomTest(new PartTestManager(), part =>
  83. {
  84. UInt32 count;
  85. part.GetControlInterfaceCount(out count);
  86. for (uint i = 0; i < count; i++)
  87. {
  88. IControlInterface ctrl;
  89. var result = part.GetControlInterface(i, out ctrl);
  90. Manager.EnsureDisposal(ctrl);
  91. AssertCoreAudio.IsHResultOk(result);
  92. tested = true;
  93. }
  94. });
  95. if (!tested) Assert.Inconclusive("The test cannot be run properly. No control interfaces were found.");
  96. }
  97. /// <summary>
  98. /// Tests that the control interface count can be received, for each available part in the system.
  99. /// </summary>
  100. [TestMethod]
  101. public void IPart_GetControlInterfaceCount()
  102. {
  103. ExecuteCustomTest(new PartTestManager(), part =>
  104. {
  105. var count = UInt32.MaxValue;
  106. var result = part.GetControlInterfaceCount(out count);
  107. AssertCoreAudio.IsHResultOk(result);
  108. Assert.AreNotEqual(UInt32.MaxValue, count, "The count was not received.");
  109. });
  110. }
  111. /// <summary>
  112. /// Tests that the global ID can be received, for each available part in the system.
  113. /// </summary>
  114. [TestMethod]
  115. public void IPart_GetGlobalId()
  116. {
  117. ExecuteCustomTest(new PartTestManager(), part =>
  118. {
  119. string globalId = "abc123";
  120. var result = part.GetGlobalId(out globalId);
  121. AssertCoreAudio.IsHResultOk(result);
  122. Assert.AreNotEqual("abc123", globalId, "The global ID was not received.");
  123. });
  124. }
  125. /// <summary>
  126. /// Tests that the local ID can be received, for each available part in the system.
  127. /// </summary>
  128. [TestMethod]
  129. public void IPart_GetLocalId()
  130. {
  131. ExecuteCustomTest(new PartTestManager(), part =>
  132. {
  133. UInt32 localId = UInt32.MaxValue;
  134. var result = part.GetLocalId(out localId);
  135. AssertCoreAudio.IsHResultOk(result);
  136. Assert.AreNotEqual(UInt32.MaxValue, localId, "The local ID was not received.");
  137. });
  138. }
  139. /// <summary>
  140. /// Tests that the global ID can be received, for each available part in the system.
  141. /// </summary>
  142. [TestMethod]
  143. public void IPart_GetName()
  144. {
  145. ExecuteCustomTest(new PartTestManager(), part =>
  146. {
  147. string name = "abc123";
  148. var result = part.GetName(out name);
  149. AssertCoreAudio.IsHResultOk(result);
  150. Assert.AreNotEqual("abc123", name, "The name was not received.");
  151. });
  152. }
  153. /// <summary>
  154. /// Tests that the part type can be received, for each available part in the system.
  155. /// </summary>
  156. [TestMethod]
  157. public void IPart_GetPartType()
  158. {
  159. ExecuteCustomTest(new PartTestManager(), part =>
  160. {
  161. PartType typeOne = PartType.Connector;
  162. PartType typeTwo = PartType.Subunit;
  163. var result = part.GetPartType(out typeOne);
  164. AssertCoreAudio.IsHResultOk(result);
  165. result = part.GetPartType(out typeTwo);
  166. AssertCoreAudio.IsHResultOk(result);
  167. Assert.AreEqual(typeOne, typeTwo, "The part type was not received.");
  168. });
  169. }
  170. /// <summary>
  171. /// Tests that the part type can be received, for each available part in the system.
  172. /// </summary>
  173. [TestMethod]
  174. public void IPart_GetSubType()
  175. {
  176. ExecuteCustomTest(new PartTestManager(), part =>
  177. {
  178. var subType = Guid.Empty;
  179. var result = part.GetSubType(out subType);
  180. AssertCoreAudio.IsHResultOk(result);
  181. Assert.AreNotEqual(Guid.Empty, subType, "The sub type was not received.");
  182. });
  183. }
  184. /// <summary>
  185. /// Tests that the topology object can be received, for each available part in the system.
  186. /// </summary>
  187. [TestMethod]
  188. public void IPart_GetTopologyObject()
  189. {
  190. ExecuteCustomTest(new PartTestManager(), part =>
  191. {
  192. IDeviceTopology topology;
  193. var result = part.GetTopologyObject(out topology);
  194. Manager.EnsureDisposal(topology);
  195. AssertCoreAudio.IsHResultOk(result);
  196. });
  197. }
  198. /// <summary>
  199. ///
  200. /// </summary>
  201. [TestMethod]
  202. public void IPart_RegisterControlChangeCallback()
  203. {
  204. Assert.Fail("TODO: Implement test for RegisterControlChangeCallback method");
  205. }
  206. /// <summary>
  207. ///
  208. /// </summary>
  209. [TestMethod]
  210. public void IPart_UnregisterControlChangeCallback()
  211. {
  212. Assert.Fail("TODO: Implement test for UnregisterControlChangeCallback method");
  213. }
  214. /// <summary>
  215. /// Class used to manage testing of IPart interface.
  216. /// </summary>
  217. private class PartTestManager : TestManager<IPart>
  218. {
  219. protected override void OnRun()
  220. {
  221. var allParts = TestUtilities.CreateIPartCollection();
  222. try
  223. {
  224. foreach (var part in allParts)
  225. {
  226. OnTestReady(part);
  227. }
  228. }
  229. finally
  230. {
  231. foreach (var part in allParts)
  232. Marshal.FinalReleaseComObject(part);
  233. }
  234. }
  235. }
  236. }
  237. }