IDeviceTopologyTest.cs 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215
  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 System.Linq;
  21. using CoreAudioTests.Common;
  22. using Microsoft.VisualStudio.TestTools.UnitTesting;
  23. using Vannatech.CoreAudio.Interfaces;
  24. using Vannatech.CoreAudio.Constants;
  25. using System.Runtime.InteropServices;
  26. namespace CoreAudioTests.DeviceTopologyApi
  27. {
  28. /// <summary>
  29. /// Tests all methods of the IDeviceTopology interface.
  30. /// </summary>
  31. [TestClass]
  32. public class IDeviceTopologyTest : TestClass<IDeviceTopology>
  33. {
  34. /// <summary>
  35. /// Tests that the connectors for a device topology may be received, for each available endpoint.
  36. /// </summary>
  37. [TestMethod]
  38. public void IDeviceTopology_GetConnector()
  39. {
  40. var tested = false;
  41. ExecuteDeviceActivationTest(activation =>
  42. {
  43. UInt32 count;
  44. activation.GetConnectorCount(out count);
  45. for (uint i = 0; i < count; i++)
  46. {
  47. IConnector connector;
  48. var result = activation.GetConnector(i, out connector);
  49. Marshal.FinalReleaseComObject(connector);
  50. AssertCoreAudio.IsHResultOk(result);
  51. tested = true;
  52. }
  53. });
  54. if (!tested) Assert.Inconclusive("The test cannot be run properly. No subunits were found.");
  55. }
  56. /// <summary>
  57. /// Tests that the connector count for a device topology may be received, for each available endpoint.
  58. /// </summary>
  59. [TestMethod]
  60. public void IDeviceTopology_GetConnectorCount()
  61. {
  62. ExecuteDeviceActivationTest(activation =>
  63. {
  64. var count = UInt32.MaxValue;
  65. var result = activation.GetConnectorCount(out count);
  66. AssertCoreAudio.IsHResultOk(result);
  67. Assert.AreNotEqual(UInt32.MaxValue, count, "The connector count was not received.");
  68. });
  69. }
  70. /// <summary>
  71. /// Tests that the device ID for a device topology may be received, for each available endpoint.
  72. /// </summary>
  73. [TestMethod]
  74. public void IDeviceTopology_GetDeviceId()
  75. {
  76. ExecuteDeviceActivationTest(activation =>
  77. {
  78. string devId = "abc123";
  79. var result = activation.GetDeviceId(out devId);
  80. AssertCoreAudio.IsHResultOk(result);
  81. Assert.AreNotEqual("abc123", devId, "The device ID was not received.");
  82. });
  83. }
  84. /// <summary>
  85. /// Tests that parts in a device topology may be received by ID, for each available endpoint.
  86. /// </summary>
  87. [TestMethod]
  88. public void IDeviceTopology_GetPartById()
  89. {
  90. ExecuteDeviceActivationTest(activation =>
  91. {
  92. IConnector connector;
  93. activation.GetConnector(0, out connector);
  94. UInt32 partId;
  95. string globalId;
  96. ((IPart)connector).GetLocalId(out partId);
  97. ((IPart)connector).GetGlobalId(out globalId);
  98. IPart part;
  99. var result = activation.GetPartById(partId, out part);
  100. AssertCoreAudio.IsHResultOk(result);
  101. string verifyId;
  102. part.GetGlobalId(out verifyId);
  103. Assert.AreEqual(globalId, verifyId, "The part received did not match the expected part.");
  104. Marshal.FinalReleaseComObject(connector);
  105. Marshal.FinalReleaseComObject(part);
  106. });
  107. }
  108. /// <summary>
  109. /// Tests that a signal path can be resolved by a device topology, for each available endpoint.
  110. /// </summary>
  111. [TestMethod]
  112. public void IDeviceTopology_GetSignalPath()
  113. {
  114. var tested = false;
  115. ExecuteDeviceActivationTest(activation =>
  116. {
  117. var allParts = TestUtilities.CreateIPartCollection();
  118. try
  119. {
  120. for (int p1 = 0; p1 < allParts.Count(); p1++)
  121. {
  122. for (int p2 = 0; p2 < allParts.Count(); p2++)
  123. {
  124. IPartsList partsList;
  125. var result = activation.GetSignalPath(allParts.ElementAt(p1), allParts.ElementAt(p2), false, out partsList);
  126. if ((uint)result == TestUtilities.HRESULTS.E_NOTFOUND)
  127. continue;
  128. AssertCoreAudio.IsHResultOk(result);
  129. var pCount = UInt32.MaxValue;
  130. partsList.GetCount(out pCount);
  131. Marshal.FinalReleaseComObject(partsList);
  132. Assert.AreNotEqual(UInt32.MaxValue, pCount, "There count of parts cound was not received. This indicates an error in the signal path.");
  133. tested = true;
  134. }
  135. }
  136. }
  137. finally
  138. {
  139. foreach (var part in allParts)
  140. Marshal.FinalReleaseComObject(part);
  141. }
  142. });
  143. if (!tested) Assert.Inconclusive("The test cannot be run properly. No valid signal paths were found.");
  144. }
  145. /// <summary>
  146. /// Tests that the subunits for a device topology may be received, for each available endpoint.
  147. /// </summary>
  148. [TestMethod]
  149. public void IDeviceTopology_GetSubunit()
  150. {
  151. var tested = false;
  152. ExecuteDeviceActivationTest(activation =>
  153. {
  154. UInt32 count;
  155. activation.GetSubunitCount(out count);
  156. for (uint i = 0; i < count; i++)
  157. {
  158. ISubunit subunit;
  159. var result = activation.GetSubunit(i, out subunit);
  160. Marshal.FinalReleaseComObject(subunit);
  161. AssertCoreAudio.IsHResultOk(result);
  162. tested = true;
  163. }
  164. });
  165. if (!tested) Assert.Inconclusive("The test cannot be run properly. No subunits were found.");
  166. }
  167. /// <summary>
  168. /// Tests that the subunit count for a device topology may be received, for each available endpoint.
  169. /// </summary>
  170. [TestMethod]
  171. public void IDeviceTopology_GetSubunitCount()
  172. {
  173. ExecuteDeviceActivationTest(activation =>
  174. {
  175. var count = UInt32.MaxValue;
  176. var result = activation.GetSubunitCount(out count);
  177. AssertCoreAudio.IsHResultOk(result);
  178. Assert.AreNotEqual(UInt32.MaxValue, count, "The subunit count was not received.");
  179. });
  180. }
  181. }
  182. }