IAudioChannelConfigTest.cs 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  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. namespace CoreAudioTests.DeviceTopologyApi
  25. {
  26. /// <summary>
  27. /// Tests all methods of the IAudioChannelConfig interface.
  28. /// </summary>
  29. [TestClass]
  30. public class IAudioChannelConfigTest : TestClass<IAudioChannelConfig>
  31. {
  32. /// <summary>
  33. /// Tests that the channel configuration can be recieved, for each applicable part in the system.
  34. /// </summary>
  35. [TestMethod]
  36. public void IAudioChannelConfig_GetChannelConfig()
  37. {
  38. ExecutePartActivationTest(activation =>
  39. {
  40. var configMin = 0x1;
  41. var configMax = 0x46665;
  42. UInt32 config = UInt32.MaxValue;
  43. var result = activation.GetChannelConfig(out config);
  44. AssertCoreAudio.IsHResultOk(result);
  45. Assert.IsTrue((config >= configMin) && (config <= configMax), "The channel configuration value is not within the valid range.");
  46. });
  47. }
  48. /// <summary>
  49. /// Tests that the channel configuration can be set, for each applicable part in the system.
  50. /// </summary>
  51. [TestMethod]
  52. public void IAudioChannelConfig_SetChannelConfig()
  53. {
  54. ExecutePartActivationTest(activation =>
  55. {
  56. var context = Guid.NewGuid();
  57. UInt32 valOrig, valTest;
  58. activation.GetChannelConfig(out valOrig);
  59. // Test various valid values.
  60. var result = activation.SetChannelConfig(0x1, context);
  61. AssertCoreAudio.IsHResultOk(result);
  62. activation.GetChannelConfig(out valTest);
  63. Assert.AreEqual(0x1, valTest, "The channel configuration value was not set properly.");
  64. result = activation.SetChannelConfig(0x28, context);
  65. AssertCoreAudio.IsHResultOk(result);
  66. activation.GetChannelConfig(out valTest);
  67. Assert.AreEqual(0x28, valTest, "The channel configuration value was not set properly.");
  68. result = activation.SetChannelConfig(0x2000, context);
  69. AssertCoreAudio.IsHResultOk(result);
  70. activation.GetChannelConfig(out valTest);
  71. Assert.AreEqual(0x2000, valTest, "The channel configuration value was not set properly.");
  72. // Return to original configuration.
  73. result = activation.SetChannelConfig(valOrig, context);
  74. AssertCoreAudio.IsHResultOk(result);
  75. });
  76. }
  77. }
  78. }