// -----------------------------------------
// SoundScribe (TM) and related software.
//
// Copyright (C) 2007-2011 Vannatech
// http://www.vannatech.com
// All rights reserved.
//
// This source code is subject to the MIT License.
// http://www.opensource.org/licenses/mit-license.php
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
// -----------------------------------------
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Vannatech.CoreAudio.Constants;
using Vannatech.CoreAudio.Enumerations;
using Vannatech.CoreAudio.Externals;
using Vannatech.CoreAudio.Interfaces;
namespace CoreAudioTests.Common
{
///
/// Base class for tests that utilize MMDevice Activation or AudioClient Services.
///
/// The interface type.
public abstract class TestClass
{
///
/// The COM IID.
///
protected virtual string ComIID
{
get
{
var interfaceName = typeof(T).Name;
var fieldInfo = typeof(ComIIDs).GetField(interfaceName + "IID");
if (fieldInfo == null)
throw new ArgumentException("Could not find the COM IID for the specified ");
return fieldInfo.GetValue(null) as string;
}
}
///
/// Gets the test manager used to run tests.
///
protected TestManager Manager
{
get;
private set;
}
///
/// Runs tests via a custom test manager.
///
/// The test manager.
/// The test method to use.
protected void ExecuteCustomTest(TestManager testManager, TestReadyDelegate onTestReady)
{
Manager = testManager;
Manager.OnTestReady = onTestReady;
Manager.Run();
}
///
/// Runs each test, creating the specified interface from the IMMDevice.Activate method.
///
/// The test method to use.
protected virtual void ExecuteDeviceActivationTest(TestReadyDelegate onTestReady)
{
Manager = DeviceActivationTestManager.Create(ComIID);
Manager.OnTestReady = onTestReady;
Manager.Run();
}
///
/// Runs each test, creating the specified interface from the IPart.Activate method.
///
/// The test method to use.
protected virtual void ExecutePartActivationTest(TestReadyDelegate onTestReady)
{
Manager = PartActivationTestManager.Create(ComIID);
Manager.OnTestReady = onTestReady;
Manager.Run();
}
///
/// Runs each test, creating the specified interface from the IAudioClient.GetService method.
/// Tests are run in both shared and exclusive mode.
///
/// The test method to use.
protected virtual void ExecuteServiceTest(TestReadyDelegate onTestReady)
{
Manager = ServiceTestManager.Create(ComIID, false);
Manager.OnTestReady = onTestReady;
Manager.Run();
Manager = ServiceTestManager.Create(ComIID, true);
Manager.OnTestReady = onTestReady;
Manager.Run();
}
///
/// Runs each test, creating the specified interface from the IAudioClient.GetService method.
/// Tests are run only in the specified share mode.
///
/// The audio client share mode.
/// The test method to use.
protected virtual void ExecuteServiceTest(AUDCLNT_SHAREMODE shareMode, TestReadyDelegate onTestReady)
{
var exclusiveMode = (shareMode == AUDCLNT_SHAREMODE.AUDCLNT_SHAREMODE_EXCLUSIVE);
Manager = ServiceTestManager.Create(ComIID, exclusiveMode);
Manager.OnTestReady = onTestReady;
Manager.Run();
}
///
/// Runs each test, creating the specified interface from the IAudioClient.GetService method.
/// Tests are run in both shared and exclusive mode, with the audio client in the running (started) state.
///
/// The test method to use.
protected virtual void ExecuteRunningServiceTest(TestReadyDelegate onTestReady)
{
var serviceTestManager = ServiceTestManager.Create(ComIID, false);
serviceTestManager.AutoStartClient = true;
Manager = serviceTestManager;
Manager.OnTestReady = onTestReady;
Manager.Run();
serviceTestManager = ServiceTestManager.Create(ComIID, true);
serviceTestManager.AutoStartClient = true;
Manager = serviceTestManager;
Manager.OnTestReady = onTestReady;
Manager.Run();
}
///
/// Runs each test, creating the specified interface from the IAudioClient.GetService method.
/// Tests are run only in the specified share mode, with the audio client in the running (started) state.
///
/// The audio client share mode.
/// The test method to use.
protected virtual void ExecuteRunningServiceTest(AUDCLNT_SHAREMODE shareMode, TestReadyDelegate onTestReady)
{
var exclusiveMode = (shareMode == AUDCLNT_SHAREMODE.AUDCLNT_SHAREMODE_EXCLUSIVE);
var serviceTestManager = ServiceTestManager.Create(ComIID, exclusiveMode);
serviceTestManager.AutoStartClient = true;
Manager = serviceTestManager;
Manager.OnTestReady = onTestReady;
Manager.Run();
}
}
}