Permalink
Browse files

Added SetBroadcastInfo command with comments and tests. Multiple test…

…s fail due to Moq and structs...same as some of the FormatX tests.
  • Loading branch information...
1 parent 5bc47f5 commit 0103253f6f29655202ce68cbc70e02307fdc0e61 @ahawker committed Feb 27, 2012
@@ -87,6 +87,7 @@
<Compile Include="Unit\Command\RawNeedsEndianSwapTests.cs" />
<Compile Include="Unit\Command\SetAddPeakChunkTests.cs" />
<Compile Include="Unit\Command\SetAmbisonicTests.cs" />
+ <Compile Include="Unit\Command\SetBroadcastInfoTests.cs" />
<Compile Include="Unit\Command\SetClippingTests.cs" />
<Compile Include="Unit\Command\SetNormDoubleTests.cs" />
<Compile Include="Unit\Command\SetNormFloatTests.cs" />
@@ -0,0 +1,95 @@
+using System;
+using Moq;
+using NUnit.Framework;
+
+namespace NLibsndfile.Native.Tests
+{
+ [TestFixture]
+ [Category("NLibsndfileApi.Native.UnitTests.CommandApi")]
+ public class SetBroadcastInfoTests
+ {
+ [Test]
+ [ExpectedException(typeof(ArgumentException))]
+ public void SetBroadcastInfo_ShouldThrowExceptionOnZeroHandle()
+ {
+ var mock = new Mock<ILibsndfileCommandApi>();
+
+ var api = new LibsndfileCommandApi(mock.Object);
+ api.SetBroadcastInfo(IntPtr.Zero, It.IsAny<LibsndfileBroadcastInfo>());
+ }
+
+ [Test]
+ [ExpectedException(typeof(LibsndfileException))]
+ public void SetBroadcastInfo_ShouldThrowExceptionOnNegativeResult()
+ {
+ var broadcastInfo = new LibsndfileBroadcastInfo();
+
+ var unmanagedMemoryMock = new Mock<UnmanagedMemoryHandle>();
+
+ var marshallerMock = new Mock<ILibsndfileMarshaller>();
+ marshallerMock.Setup(x => x.Allocate(broadcastInfo)).Returns(unmanagedMemoryMock.Object);
+
+ var mock = new Mock<ILibsndfileApi>();
+ mock.Setup(x => x.Command(It.IsAny<IntPtr>(), It.IsAny<LibsndfileCommand>(), It.IsAny<IntPtr>(), It.IsAny<int>())).Returns(-1);
+
+ var api = new LibsndfileCommandApiNativeWrapper(mock.Object, marshallerMock.Object);
+ api.SetBroadcastInfo(new IntPtr(1), It.IsAny<LibsndfileBroadcastInfo>());
+ }
+
+ [Test]
+ [ExpectedException(typeof(LibsndfileException))]
+ public void SetBroadcastInfo_ShouldThrowExceptionOnGreaterThanOneResult()
+ {
+ var broadcastInfo = new LibsndfileBroadcastInfo();
+
+ var unmanagedMemoryMock = new Mock<UnmanagedMemoryHandle>();
+
+ var marshallerMock = new Mock<ILibsndfileMarshaller>();
+ marshallerMock.Setup(x => x.Allocate(broadcastInfo)).Returns(unmanagedMemoryMock.Object);
+
+ var mock = new Mock<ILibsndfileApi>();
+ mock.Setup(x => x.Command(It.IsAny<IntPtr>(), It.IsAny<LibsndfileCommand>(), It.IsAny<IntPtr>(), It.IsAny<int>())).Returns(2);
+
+ var api = new LibsndfileCommandApiNativeWrapper(mock.Object, marshallerMock.Object);
+ api.SetBroadcastInfo(new IntPtr(1), It.IsAny<LibsndfileBroadcastInfo>());
+ }
+
+ [Test]
+ public void SetBroadcastInfo_ShouldReturnFalseOnZeroResult()
+ {
+ var broadcastInfo = new LibsndfileBroadcastInfo();
+
+ var unmanagedMemoryMock = new Mock<UnmanagedMemoryHandle>();
+
+ var marshallerMock = new Mock<ILibsndfileMarshaller>();
+ marshallerMock.Setup(x => x.Allocate(It.IsAny<LibsndfileBroadcastInfo>())).Returns(unmanagedMemoryMock.Object);
+
+ var mock = new Mock<ILibsndfileApi>();
+ mock.Setup(x => x.Command(It.IsAny<IntPtr>(), It.IsAny<LibsndfileCommand>(), It.IsAny<IntPtr>(), It.IsAny<int>())).Returns(0);
+
+ var api = new LibsndfileCommandApiNativeWrapper(mock.Object, marshallerMock.Object);
+ var retval = api.SetBroadcastInfo(new IntPtr(1), It.IsAny<LibsndfileBroadcastInfo>());
+
+ Assert.IsFalse(retval);
+ }
+
+ [Test]
+ public void SetBroadcastInfo_ShouldReturnTrueOnOneResult()
+ {
+ var broadcastInfo = new LibsndfileBroadcastInfo();
+
+ var unmanagedMemoryMock = new Mock<UnmanagedMemoryHandle>();
+
+ var marshallerMock = new Mock<ILibsndfileMarshaller>();
+ marshallerMock.Setup(x => x.Allocate(broadcastInfo)).Returns(unmanagedMemoryMock.Object);
+
+ var mock = new Mock<ILibsndfileApi>();
+ mock.Setup(x => x.Command(It.IsAny<IntPtr>(), It.IsAny<LibsndfileCommand>(), It.IsAny<IntPtr>(), It.IsAny<int>())).Returns(1);
+
+ var api = new LibsndfileCommandApiNativeWrapper(mock.Object, marshallerMock.Object);
+ var retval = api.SetBroadcastInfo(new IntPtr(1), It.IsAny<LibsndfileBroadcastInfo>());
+
+ Assert.IsTrue(retval);
+ }
+ }
+}
@@ -260,5 +260,13 @@ public interface ILibsndfileCommandApi
/// <param name="sndfile">Audio file to examine for broadcast info chunk.</param>
/// <returns><see cref="LibsndfileBroadcastInfo"/> structure containing broadcast info.</returns>
LibsndfileBroadcastInfo GetBroadcastInfo(IntPtr sndfile);
+
+ /// <summary>
+ /// Set the Broadcast Extension chuck on the given <paramref name="sndfile"/> file.
+ /// </summary>
+ /// <param name="sndfile">Audio file to set broadcast info chunk for.</param>
+ /// <param name="broadcastInfo">Broadcast info chunk.</param>
+ /// <returns>True if broadcast info was successfully set.</returns>
+ bool SetBroadcastInfo(IntPtr sndfile, LibsndfileBroadcastInfo broadcastInfo);
}
}
@@ -508,5 +508,19 @@ public LibsndfileBroadcastInfo GetBroadcastInfo(IntPtr sndfile)
return m_Api.GetBroadcastInfo(sndfile);
}
+
+ /// <summary>
+ /// Set the Broadcast Extension chuck on the given <paramref name="sndfile"/> file.
+ /// </summary>
+ /// <param name="sndfile">Audio file to set broadcast info chunk for.</param>
+ /// <param name="broadcastInfo">Broadcast info chunk.</param>
+ /// <returns>True if broadcast info was successfully set.</returns>
+ public bool SetBroadcastInfo(IntPtr sndfile, LibsndfileBroadcastInfo broadcastInfo)
+ {
+ if (sndfile == IntPtr.Zero)
+ throw new ArgumentException("File handle is invalid/closed.");
+
+ return m_Api.SetBroadcastInfo(sndfile, broadcastInfo);
+ }
}
}
@@ -588,5 +588,23 @@ public LibsndfileBroadcastInfo GetBroadcastInfo(IntPtr sndfile)
return m_Marshaller.MemoryHandleTo<LibsndfileBroadcastInfo>(memory);
}
}
+
+ /// <summary>
+ /// Set the Broadcast Extension chuck on the given <paramref name="sndfile"/> file.
+ /// </summary>
+ /// <param name="sndfile">Audio file to set broadcast info chunk for.</param>
+ /// <param name="broadcastInfo">Broadcast info chunk.</param>
+ /// <returns>True if broadcast info was successfully set.</returns>
+ public bool SetBroadcastInfo(IntPtr sndfile, LibsndfileBroadcastInfo broadcastInfo)
+ {
+ using (var memory = m_Marshaller.Allocate(broadcastInfo))
+ {
+ var retval = m_Api.Command(sndfile, LibsndfileCommand.SetBroadcastInfo, memory, memory.Size);
+ if (!LibsndfileCommandUtilities.IsValidResult(sndfile, LibsndfileCommand.SetBroadcastInfo, retval))
+ throw new LibsndfileException("Unable to set broadcast info for the given file.");
+
+ return Convert.ToBoolean(retval);
+ }
+ }
}
}

0 comments on commit 0103253

Please sign in to comment.