IControlInterfaceTest.cs 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  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.DeviceTopologyApi
  26. {
  27. /// <summary>
  28. /// Tests all methods of the IControlInterface interface.
  29. /// </summary>
  30. [TestClass]
  31. public class IControlInterfaceTest
  32. {
  33. /// <summary>
  34. /// Tests that the ID can be received, for each available control interface in the system.
  35. /// </summary>
  36. [TestMethod]
  37. public void IControlInterface_GetIID()
  38. {
  39. int result = 0;
  40. var allParts = TestUtilities.CreateIPartCollection();
  41. try
  42. {
  43. foreach (var part in allParts)
  44. {
  45. UInt32 count;
  46. part.GetControlInterfaceCount(out count);
  47. for (uint i = 0; i < count; i++)
  48. {
  49. IControlInterface ctrl;
  50. part.GetControlInterface(i, out ctrl);
  51. Guid iid = Guid.Empty;
  52. result = ctrl.GetIID(out iid);
  53. Marshal.FinalReleaseComObject(ctrl);
  54. AssertCoreAudio.IsHResultOk(result);
  55. Assert.AreNotEqual(Guid.Empty, iid, "The control IID was not received.");
  56. }
  57. }
  58. }
  59. finally
  60. {
  61. foreach (var part in allParts)
  62. Marshal.FinalReleaseComObject(part);
  63. }
  64. }
  65. /// <summary>
  66. /// Tests that the name can be received, for each available control interface in the system.
  67. /// </summary>
  68. [TestMethod]
  69. public void IControlInterface_GetName()
  70. {
  71. int result = 0;
  72. var allParts = TestUtilities.CreateIPartCollection();
  73. try
  74. {
  75. foreach (var part in allParts)
  76. {
  77. UInt32 count;
  78. part.GetControlInterfaceCount(out count);
  79. for (uint i = 0; i < count; i++)
  80. {
  81. IControlInterface ctrl;
  82. part.GetControlInterface(i, out ctrl);
  83. string name = "abc123";
  84. result = ctrl.GetName(out name);
  85. Marshal.FinalReleaseComObject(ctrl);
  86. AssertCoreAudio.IsHResultOk(result);
  87. Assert.AreNotEqual("abc123", name, "The control name was not received.");
  88. }
  89. }
  90. }
  91. finally
  92. {
  93. foreach (var part in allParts)
  94. Marshal.FinalReleaseComObject(part);
  95. }
  96. }
  97. }
  98. }