public void IAudioEndpointVolumeEx_GetVolumeRangeChannel() { var tested = false; ExecuteDeviceActivationTest(activation => { var count = UInt32.MaxValue; activation.GetChannelCount(out count); for (int i = 0; i < count; i++) { float volumeMin = 123.456f, volumeMax = 123.456f, volumeStep = 123.456f; var result = activation.GetVolumeRangeChannel((UInt32)i, out volumeMin, out volumeMax, out volumeStep); AssertCoreAudio.IsHResultOk(result); Assert.AreNotEqual(123.456f, volumeMin, "The min volume value was not received."); Assert.AreNotEqual(123.456f, volumeMax, "The max volume value was not received."); Assert.AreNotEqual(123.456f, volumeStep, "The volume step value was not received."); tested = true; } }); if (!tested) { Assert.Inconclusive("There were not channels available to test against."); } }
public void IControlInterface_GetIID() { int result = 0; var allParts = TestUtilities.CreateIPartCollection(); try { foreach (var part in allParts) { UInt32 count; part.GetControlInterfaceCount(out count); for (uint i = 0; i < count; i++) { IControlInterface ctrl; part.GetControlInterface(i, out ctrl); Guid iid = Guid.Empty; result = ctrl.GetIID(out iid); Marshal.FinalReleaseComObject(ctrl); AssertCoreAudio.IsHResultOk(result); Assert.AreNotEqual(Guid.Empty, iid, "The control IID was not received."); } } } finally { foreach (var part in allParts) { Marshal.FinalReleaseComObject(part); } } }
public void IControlInterface_GetName() { int result = 0; var allParts = TestUtilities.CreateIPartCollection(); try { foreach (var part in allParts) { UInt32 count; part.GetControlInterfaceCount(out count); for (uint i = 0; i < count; i++) { IControlInterface ctrl; part.GetControlInterface(i, out ctrl); string name = "abc123"; result = ctrl.GetName(out name); Marshal.FinalReleaseComObject(ctrl); AssertCoreAudio.IsHResultOk(result); Assert.AreNotEqual("abc123", name, "The control name was not received."); } } } finally { foreach (var part in allParts) { Marshal.FinalReleaseComObject(part); } } }
public void IAudioChannelConfig_SetChannelConfig() { ExecutePartActivationTest(activation => { var context = Guid.NewGuid(); UInt32 valOrig, valTest; activation.GetChannelConfig(out valOrig); // Test various valid values. var result = activation.SetChannelConfig(0x1, context); AssertCoreAudio.IsHResultOk(result); activation.GetChannelConfig(out valTest); Assert.AreEqual(0x1, valTest, "The channel configuration value was not set properly."); result = activation.SetChannelConfig(0x28, context); AssertCoreAudio.IsHResultOk(result); activation.GetChannelConfig(out valTest); Assert.AreEqual(0x28, valTest, "The channel configuration value was not set properly."); result = activation.SetChannelConfig(0x2000, context); AssertCoreAudio.IsHResultOk(result); activation.GetChannelConfig(out valTest); Assert.AreEqual(0x2000, valTest, "The channel configuration value was not set properly."); // Return to original configuration. result = activation.SetChannelConfig(valOrig, context); AssertCoreAudio.IsHResultOk(result); }); }
public void IPart_GetControlInterface() { var tested = false; ExecuteCustomTest(new PartTestManager(), part => { UInt32 count; part.GetControlInterfaceCount(out count); for (uint i = 0; i < count; i++) { IControlInterface ctrl; var result = part.GetControlInterface(i, out ctrl); Manager.EnsureDisposal(ctrl); AssertCoreAudio.IsHResultOk(result); tested = true; } }); if (!tested) { Assert.Inconclusive("The test cannot be run properly. No control interfaces were found."); } }
public void IConnector_GetDeviceIdConnectedTo() { int result = 0; IEnumerable <IConnector> allConnectors; ToConnectors(TestUtilities.CreateIPartCollection(), out allConnectors); foreach (var con in allConnectors) { bool isConnected; con.IsConnected(out isConnected); if (isConnected) { IConnector cTo; con.GetConnectedTo(out cTo); IDeviceTopology topology; ((IPart)cTo).GetTopologyObject(out topology); string expectedId, devIdConTo; topology.GetDeviceId(out expectedId); result = con.GetDeviceIdConnectedTo(out devIdConTo); AssertCoreAudio.IsHResultOk(result); Assert.AreEqual(expectedId, devIdConTo, "The connected to device ID does not match the actual device ID."); } } }
public void IConnector_GetType() { int result = 0; IEnumerable <IConnector> allConnectors; ToConnectors(TestUtilities.CreateIPartCollection(), out allConnectors); foreach (var con in allConnectors) { // Try confiming that the type is changed from unknown. var cType = ConnectorType.Unknown_Connector; result = con.GetType(out cType); AssertCoreAudio.IsHResultOk(result); if (cType == ConnectorType.Unknown_Connector) { // If it's still unknown, verify that this is correct. var cType2 = ConnectorType.Network; con.GetType(out cType2); AssertCoreAudio.IsHResultOk(result); Assert.AreEqual(ConnectorType.Unknown_Connector, cType2, "The connector type was not received."); } else { // The value being changed is enough to verify correctness of the method. } } }
public void IDeviceTopology_GetConnector() { var tested = false; ExecuteDeviceActivationTest(activation => { UInt32 count; activation.GetConnectorCount(out count); for (uint i = 0; i < count; i++) { IConnector connector; var result = activation.GetConnector(i, out connector); Marshal.FinalReleaseComObject(connector); AssertCoreAudio.IsHResultOk(result); tested = true; } }); if (!tested) { Assert.Inconclusive("The test cannot be run properly. No subunits were found."); } }
public void IConnector_GetConnectorIdConnectedTo() { int result = 0; IEnumerable <IConnector> allConnectors; ToConnectors(TestUtilities.CreateIPartCollection(), out allConnectors); foreach (var con in allConnectors) { bool isConnected; con.IsConnected(out isConnected); if (isConnected) { IConnector cTo; con.GetConnectedTo(out cTo); string expectedId, idConTo; ((IPart)cTo).GetGlobalId(out expectedId); result = con.GetConnectorIdConnectedTo(out idConTo); AssertCoreAudio.IsHResultOk(result); Assert.AreEqual(expectedId, idConTo, "The connected to ID does not match the actual ID of the part."); } } }
public void IAudioEndpointVolume_GetChannelVolumeLevelScalar() { var tested = false; ExecuteDeviceActivationTest(activation => { var count = UInt32.MaxValue; activation.GetChannelCount(out count); for (uint i = 0; i < count; i++) { float level = 123.456f; var result = activation.GetChannelVolumeLevelScalar(i, out level); AssertCoreAudio.IsHResultOk(result); Assert.AreNotEqual(123.456f, level, "The level value was not received."); tested = true; } }); if (!tested) { Assert.Inconclusive("No channels were available to test against."); } }
public void IAudioEndpointVolume_SetMasterVolumeLevelScalar() { ExecuteDeviceActivationTest(activation => { // get the original level. float levelOrig, levelNew, levelCheck; activation.GetMasterVolumeLevelScalar(out levelOrig); // create a random valid level var rand = new Random(); levelNew = (float)rand.NextDouble(); // set the new level. Guid context = Guid.NewGuid(); var result = activation.SetMasterVolumeLevelScalar(levelNew, context); AssertCoreAudio.IsHResultOk(result); // check that the level was set. activation.GetMasterVolumeLevelScalar(out levelCheck); Assert.AreEqual(levelNew, levelCheck, 0.001f, "The new volume level was not set properly."); // reset the level to the original. result = activation.SetMasterVolumeLevelScalar(levelOrig, context); }); }
public void IAudioEndpointVolume_SetMasterVolumeLevel() { ExecuteDeviceActivationTest(activation => { // determine valid range. float volumeMin, volumeMax, volumeStep; activation.GetVolumeRange(out volumeMin, out volumeMax, out volumeStep); // get the original level. float levelOrig, levelNew, levelCheck; activation.GetMasterVolumeLevel(out levelOrig); // create a random valid level var rand = new Random(); levelNew = (float)rand.Next((int)volumeMin, (int)volumeMax); // set the new level. Guid context = Guid.NewGuid(); var result = activation.SetMasterVolumeLevel(levelNew, context); AssertCoreAudio.IsHResultOk(result); // check that the level was set. activation.GetMasterVolumeLevel(out levelCheck); Assert.AreEqual(levelNew, levelCheck, volumeStep, "The new volume level was not set properly."); // reset the level to the original. result = activation.SetMasterVolumeLevel(levelOrig, context); }); }
public void IChannelAudioVolume_SetChannelVolume() { ExecuteServiceTest(service => { UInt32 channelCount; service.GetChannelCount(out channelCount); for (uint i = 0; i < channelCount; i++) { float valOrig; service.GetChannelVolume(i, out valOrig); // Set to test value. var context = Guid.NewGuid(); var result = service.SetChannelVolume(i, 0.5f, context); AssertCoreAudio.IsHResultOk(result); // Check new value. float valNew; service.GetChannelVolume(i, out valNew); Assert.AreEqual(0.5f, valNew, "The channel volume was not set."); // Return to original value. result = service.SetChannelVolume(i, valOrig, context); AssertCoreAudio.IsHResultOk(result); } }); }
public void IChannelAudioVolume_SetAllVolumes() { ExecuteServiceTest(service => { UInt32 channelCount; service.GetChannelCount(out channelCount); float[] valOrig = new float[channelCount]; service.GetAllVolumes(channelCount, valOrig); // Set to test values. var context = Guid.NewGuid(); var result = service.SetAllVolumes(channelCount, Enumerable.Repeat(0.5f, (int)channelCount).ToArray(), context); AssertCoreAudio.IsHResultOk(result); // Check new values. float[] valNew = new float[channelCount]; service.GetAllVolumes(channelCount, valNew); Assert.IsFalse(valNew.Any(val => val != 0.5f), "One or more volumes were not set."); // Return to original value. result = service.SetAllVolumes(channelCount, valOrig, context); AssertCoreAudio.IsHResultOk(result); }); }
public void IKsJackDescription2_GetJackDescription2() { var tested = false; ExecutePartActivationTest(activation => { UInt32 count; activation.GetJackCount(out count); for (uint i = 0; i < count; i++) { KSJACK_DESCRIPTION2 description = new KSJACK_DESCRIPTION2(); description.JackCapabilities = UInt32.MaxValue; var result = activation.GetJackDescription(i, out description); AssertCoreAudio.IsHResultOk(result); Assert.AreNotEqual(UInt32.MaxValue, description.JackCapabilities, "The jack capabilities was not received."); tested = true; } }); if (!tested) { Assert.Inconclusive("The test cannot be run properly. No jacks were found."); } }
public void ISimpleAudioVolume_SetMute() { ExecuteServiceTest(service => { var context = Guid.NewGuid(); bool valOrig, valNew; service.GetMute(out valOrig); // Test set mute to on. var result = service.SetMute(true, context); AssertCoreAudio.IsHResultOk(result); service.GetMute(out valNew); Assert.AreEqual(true, valNew, "The mute state was not set."); // Test set mute to off. result = service.SetMute(false, context); AssertCoreAudio.IsHResultOk(result); service.GetMute(out valNew); Assert.AreEqual(false, valNew, "The mute state was not set."); // Return to original value. result = service.SetMute(valOrig, context); AssertCoreAudio.IsHResultOk(result); }); }
public void IMMDeviceEnumerator_GetDevice() { int result = 0; var enumerator = TestUtilities.CreateIMMDeviceEnumerator(); var allDevices = TestUtilities.CreateIMMDeviceCollection(EDataFlow.eAll, DEVICE_STATE_XXX.DEVICE_STATEMASK_ALL); foreach (var device in allDevices) { // Get the device ID. string deviceId = null; result = device.GetId(out deviceId); AssertCoreAudio.IsHResultOk(result); Assert.IsNotNull(deviceId, "The device string is null."); // Get the IMMDevice directly from the ID. IMMDevice deviceFromId = null; result = enumerator.GetDevice(deviceId, out deviceFromId); AssertCoreAudio.IsHResultOk(result); Assert.IsNotNull(deviceFromId, "The IMMDevice object is null."); // Ensure the IDs of each device match. string deviceId2 = null; result = deviceFromId.GetId(out deviceId2); AssertCoreAudio.IsHResultOk(result); Assert.IsNotNull(deviceId2, "The device string is null."); Assert.AreEqual(deviceId, deviceId2, "The device IDs are not equal."); } }
internal void ExecuteGetLevelTest() { var tested = false; ExecutePartActivationTest(activation => { var count = UInt32.MaxValue; activation.GetChannelCount(out count); for (uint i = 0; i < count; i++) { var level = 123.456f; var result = activation.GetLevel(i, out level); AssertCoreAudio.IsHResultOk(result); Assert.AreNotEqual(123.456f, level, "The level was not received."); tested = true; } }); if (!tested) { Assert.Inconclusive("No channels were available to test against."); } }
internal void ExecuteGetLevelRangeTest() { var tested = false; ExecutePartActivationTest(activation => { var count = UInt32.MaxValue; activation.GetChannelCount(out count); for (uint i = 0; i < count; i++) { float volMin = 123.456f, volMax = 123.456f, volStep = 123.456f; var result = activation.GetLevelRange(i, out volMin, out volMax, out volStep); AssertCoreAudio.IsHResultOk(result); Assert.AreNotEqual(123.456f, volMin, "The minimum volume was not received."); Assert.AreNotEqual(123.456f, volMax, "The maximum volume was not received."); Assert.AreNotEqual(123.456f, volStep, "The volume increment was not received."); tested = true; } }); if (!tested) { Assert.Inconclusive("No channels were available to test against."); } }
public void IMMDeviceCollection_GetCount() { int result = 0; var enumerator = TestUtilities.CreateIMMDeviceEnumerator(); IMMDeviceCollection allCaptureDevices; IMMDeviceCollection allRenderDevices; IMMDeviceCollection allDevices; enumerator.EnumAudioEndpoints(EDataFlow.eCapture, DEVICE_STATE_XXX.DEVICE_STATEMASK_ALL, out allCaptureDevices); enumerator.EnumAudioEndpoints(EDataFlow.eRender, DEVICE_STATE_XXX.DEVICE_STATEMASK_ALL, out allRenderDevices); enumerator.EnumAudioEndpoints(EDataFlow.eAll, DEVICE_STATE_XXX.DEVICE_STATEMASK_ALL, out allDevices); Assert.IsNotNull(allCaptureDevices, "The IMMDeviceCollection object is null."); Assert.IsNotNull(allRenderDevices, "The IMMDeviceCollection object is null."); Assert.IsNotNull(allDevices, "The IMMDeviceCollection object is null."); UInt32 captureCount = UInt32.MaxValue, renderCount = UInt32.MaxValue, allCount = UInt32.MaxValue; result = allCaptureDevices.GetCount(out captureCount); AssertCoreAudio.IsHResultOk(result); Assert.AreNotEqual(UInt32.MaxValue, captureCount, "Device count was not received."); result = allRenderDevices.GetCount(out renderCount); AssertCoreAudio.IsHResultOk(result); Assert.AreNotEqual(UInt32.MaxValue, renderCount, "Device count was not received."); result = allDevices.GetCount(out allCount); AssertCoreAudio.IsHResultOk(result); Assert.AreNotEqual(UInt32.MaxValue, allDevices, "Device count was not received."); Assert.AreEqual(allCount, captureCount + renderCount, "The combined number of capture and render devices is not equal to the total device count."); }
public void IAudioSessionEnumerator_GetCount() { var tested = false; ExecuteDeviceActivationTest(activation => { IAudioSessionEnumerator sessionList; var result = activation.GetSessionEnumerator(out sessionList); if (result != 0) { return; } Manager.EnsureDisposal(sessionList); var count = Int32.MinValue; result = sessionList.GetCount(out count); AssertCoreAudio.IsHResultOk(result); Assert.AreNotEqual(Int32.MinValue, count, "The count was not received."); tested = true; }); if (!tested) { Assert.Inconclusive("No valid session enumerator interfaces could be created."); } }
public void IAudioSessionEnumerator_GetSession() { var tested = false; ExecuteDeviceActivationTest(activation => { IAudioSessionEnumerator sessionList; var result = activation.GetSessionEnumerator(out sessionList); if (result != 0) { return; } Manager.EnsureDisposal(sessionList); Int32 count; sessionList.GetCount(out count); for (int i = 0; i < count; i++) { IAudioSessionControl session; result = sessionList.GetSession(i, out session); AssertCoreAudio.IsHResultOk(result); Manager.EnsureDisposal(session); tested = true; } }); if (!tested) { Assert.Inconclusive("No valid session enumerator interfaces could be created."); } }
public void IKsJackDescription_GetJackDescription() { var tested = false; ExecutePartActivationTest(activation => { UInt32 count; activation.GetJackCount(out count); for (uint i = 0; i < count; i++) { KSJACK_DESCRIPTION description = new KSJACK_DESCRIPTION(); description.ChannelMapping = Int32.MinValue; description.ConnectionType = Int32.MinValue; description.GenLocation = Int32.MinValue; description.GeoLocation = Int32.MinValue; var result = activation.GetJackDescription(i, out description); AssertCoreAudio.IsHResultOk(result); Assert.AreNotEqual(Int32.MinValue, description.ChannelMapping, "Part of the structure was not received."); Assert.AreNotEqual(Int32.MinValue, description.ConnectionType, "Part of the structure was not received."); Assert.AreNotEqual(Int32.MinValue, description.GenLocation, "Part of the structure was not received."); Assert.AreNotEqual(Int32.MinValue, description.GeoLocation, "Part of the structure was not received."); tested = true; } }); if (!tested) { Assert.Inconclusive("The test cannot be run properly. No jacks were found."); } }
public void IAudioSessionControl2_GetSessionIdentifier() { var tested = false; ExecuteServiceTest(service => { var sc2 = ToAudioSessionControl2(service); if (sc2 == null) { return; } Manager.EnsureDisposal(sc2); var sessionId = "abc123"; var result = sc2.GetSessionIdentifier(out sessionId); AssertCoreAudio.IsHResultOk(result); Assert.AreNotEqual("abc123", sessionId, "The session ID was not received."); tested = true; }); if (!tested) { Assert.Inconclusive("No audio clients were found which supported the IAudioSessionControl2 interface."); } }
public void IAudioSessionControl2_GetProcessId() { var tested = false; ExecuteServiceTest(service => { var sc2 = ToAudioSessionControl2(service); if (sc2 == null) { return; } Manager.EnsureDisposal(sc2); var processId = UInt32.MaxValue; var result = sc2.GetProcessId(out processId); AssertCoreAudio.IsHResultOk(result); Assert.AreNotEqual(UInt32.MaxValue, processId, "The process ID was not received."); tested = true; }); if (!tested) { Assert.Inconclusive("No audio clients were found which supported the IAudioSessionControl2 interface."); } }
public void IAudioSessionControl2_SetDuckingPreference() { var tested = false; ExecuteServiceTest(service => { var sc2 = ToAudioSessionControl2(service); if (sc2 == null) { return; } Manager.EnsureDisposal(sc2); var result = sc2.SetDuckingPreference(true); // Check for wrong endpoint type. // This method call is only valid for render devices. if ((uint)result == 0x88890003) { return; } AssertCoreAudio.IsHResultOk(result); result = sc2.SetDuckingPreference(false); AssertCoreAudio.IsHResultOk(result); tested = true; }); if (!tested) { Assert.Inconclusive("No audio clients were found which supported the IAudioSessionControl2 interface."); } }
internal void ExecuteSetLevelAllChannelsTest() { var tested = false; ExecutePartActivationTest(activation => { var count = UInt32.MaxValue; activation.GetChannelCount(out count); var levelsOrig = new float[count]; var levelsLow = new float[count]; var levelsHigh = new float[count]; float volStep = 0f; for (uint i = 0; i < count; i++) { activation.GetLevel(i, out levelsOrig[i]); float volMin, volMax; activation.GetLevelRange(i, out volMin, out volMax, out volStep); levelsLow[i] = volMin + volStep; levelsHigh[i] = volMax - volStep; } var context = Guid.NewGuid(); var result = activation.SetLevelAllChannels(levelsLow, count, context); AssertCoreAudio.IsHResultOk(result); for (uint i = 0; i < count; i++) { float levelNew; activation.GetLevel(i, out levelNew); Assert.AreEqual(levelsLow[i], levelNew, volStep, "The channel volume was not set properly."); } result = activation.SetLevelAllChannels(levelsHigh, count, context); AssertCoreAudio.IsHResultOk(result); for (uint i = 0; i < count; i++) { float levelNew; activation.GetLevel(i, out levelNew); Assert.AreEqual(levelsHigh[i], levelNew, volStep, "The channel volume was not set properly."); } // return to original levels for (uint i = 0; i < count; i++) { activation.SetLevel(i, levelsOrig[i], context); tested = true; } }); if (!tested) { Assert.Inconclusive("No channels were available to test against."); } }
public void IAudioEndpointVolume_RegisterControlChangeNotify() { ExecuteDeviceActivationTest(activation => { var client = new AudioEndpointVolumeCallback(); var result = activation.RegisterControlChangeNotify(client); AssertCoreAudio.IsHResultOk(result); }); }
public void IAudioSessionManager_GetSimpleAudioVolume() { ExecuteDeviceActivationTest(activation => { ISimpleAudioVolume audioVolume; var result = activation.GetSimpleAudioVolume(Guid.NewGuid(), 0, out audioVolume); AssertCoreAudio.IsHResultOk(result); Manager.EnsureDisposal(audioVolume); }); }
public void IAudioSessionManager_GetAudioSessionControl() { ExecuteDeviceActivationTest(activation => { IAudioSessionControl sessionControl; var result = activation.GetAudioSessionControl(Guid.NewGuid(), 0, out sessionControl); AssertCoreAudio.IsHResultOk(result); Manager.EnsureDisposal(sessionControl); }); }