DeviceActivationTestManager.cs 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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.Collections.Generic;
  21. using System.Linq;
  22. using System.Runtime.InteropServices;
  23. using System.Text;
  24. using Microsoft.VisualStudio.TestTools.UnitTesting;
  25. using Vannatech.CoreAudio.Constants;
  26. using Vannatech.CoreAudio.Enumerations;
  27. using Vannatech.CoreAudio.Externals;
  28. using Vannatech.CoreAudio.Interfaces;
  29. namespace CoreAudioTests.Common
  30. {
  31. /// <summary>
  32. /// Test manager used to run tests within the context of an MMDeviceActivation object.
  33. /// </summary>
  34. /// <typeparam name="T">The interface type.</typeparam>
  35. public class DeviceActivationTestManager<T> : TestManager<T>
  36. {
  37. /// <summary>
  38. /// Creats a new test manager instance.
  39. /// </summary>
  40. /// <typeparam name="T">The interface type.</typeparam>
  41. /// <param name="comIId">The COM IID of the interface.</param>
  42. /// <returns>A new activation test manager instance.</returns>
  43. public static DeviceActivationTestManager<T> Create(string comIId)
  44. {
  45. return new DeviceActivationTestManager<T>(TestUtilities.CreateDeviceActivationCollection<T>(comIId));
  46. }
  47. /// <summary>
  48. /// A list of device activation objects to test against.
  49. /// </summary>
  50. protected IEnumerable<DeviceActivation<T>> Items
  51. {
  52. get;
  53. set;
  54. }
  55. /// <summary>
  56. /// Creates a new instance of the class.
  57. /// </summary>
  58. /// <param name="items">A list of device activations to use.</param>
  59. public DeviceActivationTestManager(IEnumerable<DeviceActivation<T>> items)
  60. {
  61. Items = items;
  62. }
  63. /// <summary>
  64. /// Runs the tests.
  65. /// </summary>
  66. protected override void OnRun()
  67. {
  68. foreach (var i in Items)
  69. {
  70. try
  71. {
  72. OnTestReady(i.ActiveInterface);
  73. }
  74. finally
  75. {
  76. EnsureDisposal(i);
  77. }
  78. }
  79. }
  80. }
  81. }