예제 #1
0
        public void CommandDouble_ShouldThrowExceptionOnZeroHandleWithNonStaticCommand()
        {
            var doubleRef = It.IsAny <double>();
            var api       = new LibsndfileApi();

            api.Command(IntPtr.Zero, LibsndfileCommand.GetLogInfo, ref doubleRef, It.IsAny <int>());
        }
예제 #2
0
        public void ReadShortItems_ShouldThrowExceptionOnEmptyBuffer()
        {
            var api    = new LibsndfileApi();
            var buffer = new short[] { };

            api.ReadItems(new IntPtr(1), buffer, It.IsAny <long>());
        }
예제 #3
0
        public void Open_ShouldThrowExceptionOnNullPath()
        {
            var api = new LibsndfileApi();
            var info = new LibsndfileInfo();

            api.Open(null, LibsndfileMode.Read, ref info);
        }
예제 #4
0
        public void ReadShortItems_ShouldThrowExceptionOnLessThanZeroItems()
        {
            var api    = new LibsndfileApi();
            var buffer = new short[1];

            api.ReadItems(new IntPtr(1), buffer, -1);
        }
예제 #5
0
        public void CommandDoubleArray_ShouldThrowExceptionOnEmptyData()
        {
            var api  = new LibsndfileApi();
            var data = new double[] { };

            api.Command(new IntPtr(1), It.IsAny <LibsndfileCommand>(), data, It.IsAny <int>());
        }
예제 #6
0
        public void WriteDoubleItems_ShouldThrowExceptionOnEmptyBuffer()
        {
            var api    = new LibsndfileApi();
            var buffer = new double[] { };

            api.WriteItems(new IntPtr(1), buffer, It.IsAny <long>());
        }
예제 #7
0
        public void WriteShortItems_ShouldThrowExceptionOnNullBuffer()
        {
            var api = new LibsndfileApi();

            short[] buffer = null;
            api.WriteItems(new IntPtr(1), buffer, It.IsAny <long>());
        }
예제 #8
0
        public void WriteFloatItems_ShouldThrowExceptionOnLessThanZeroItems()
        {
            var api    = new LibsndfileApi();
            var buffer = new float[1];

            api.WriteItems(new IntPtr(1), buffer, -1);
        }
예제 #9
0
        public void ReadIntItems_ShouldThrowExceptionOnNullBuffer()
        {
            var api = new LibsndfileApi();

            int[] buffer = null;
            api.ReadItems(new IntPtr(1), buffer, It.IsAny <long>());
        }
예제 #10
0
        public void Open_ShouldThrowExceptionOnEmptyPath()
        {
            var api = new LibsndfileApi();
            var info = new LibsndfileInfo();

            api.Open(string.Empty, LibsndfileMode.Read, ref info);
        }
예제 #11
0
        public void Open_ShouldThrowExceptionOnEmptyPath()
        {
            var api  = new LibsndfileApi();
            var info = new LibsndfileInfo();

            api.Open(string.Empty, LibsndfileMode.Read, ref info);
        }
예제 #12
0
        public void Open_ShouldThrowExceptionOnNullPath()
        {
            var api  = new LibsndfileApi();
            var info = new LibsndfileInfo();

            api.Open(null, LibsndfileMode.Read, ref info);
        }
예제 #13
0
        public void OpenFileDescriptor_ShouldThrowExceptionOnZeroHandle()
        {
            var api = new LibsndfileApi();
            var info = new LibsndfileInfo();

            api.OpenFileDescriptor(0, LibsndfileMode.Read, ref info, 0);
        }
예제 #14
0
        public void GetLibVersion_ReturnsCorrectVersion()
        {
            var api = new LibsndfileApi();

            var version = api.Commands.GetLibVersion();
            Assert.That(!string.IsNullOrEmpty(version));
        }
예제 #15
0
        public void ReadDoubleFrames_ShouldThrowExceptionOnEmptyBuffer()
        {
            var api    = new LibsndfileApi();
            var buffer = new double[] { };

            api.ReadFrames(new IntPtr(1), buffer, It.IsAny <long>());
        }
예제 #16
0
        public void ReadDoubleFrames_ShouldThrowExceptionOnLessThanZeroItems()
        {
            var api    = new LibsndfileApi();
            var buffer = new double[1];

            api.ReadFrames(new IntPtr(1), buffer, -1);
        }
예제 #17
0
        public void FormatCheck_ShouldThrowExceptionOnDefaultInfoStruct()
        {
            var api = new LibsndfileApi();
            var info = new LibsndfileInfo();

            api.FormatCheck(ref info);
        }
예제 #18
0
        public void ReadShortFrames_ShouldThrowExceptionOnNullBuffer()
        {
            var api = new LibsndfileApi();

            short[] buffer = null;
            api.ReadFrames(new IntPtr(1), buffer, It.IsAny <long>());
        }
예제 #19
0
        public void WriteRaw_ShouldThrowExceptionOnNullBuffer()
        {
            var api = new LibsndfileApi();

            byte[] buffer = null;
            api.WriteRaw(new IntPtr(1), buffer, It.IsAny <long>());
        }
예제 #20
0
        public void OpenFileDescriptor_ShouldThrowExceptionOnNegativeOneHandle()
        {
            var api  = new LibsndfileApi();
            var info = new LibsndfileInfo();

            api.OpenFileDescriptor(-1, LibsndfileMode.Read, ref info, 0);
        }
예제 #21
0
        public void FormatCheck_ShouldThrowExceptionOnDefaultInfoStruct()
        {
            var api  = new LibsndfileApi();
            var info = new LibsndfileInfo();

            api.FormatCheck(ref info);
        }
예제 #22
0
        public void WriteRaw_ShouldThrowExceptionOnEmptyBuffer()
        {
            var api    = new LibsndfileApi();
            var buffer = new byte[] { };

            api.WriteRaw(new IntPtr(1), buffer, It.IsAny <long>());
        }
예제 #23
0
        public void WriteRaw_ShouldThrowExceptionOnLessThanZeroItems()
        {
            var api    = new LibsndfileApi();
            var buffer = new byte[1];

            api.WriteRaw(new IntPtr(1), buffer, -1);
        }
예제 #24
0
        public void Close_ShouldThrowExceptionOnErrorResult()
        {
            var mock = new Mock<ILibsndfileApi>();
            mock.Setup(x => x.Close(It.IsAny<IntPtr>())).Returns(LibsndfileError.MalformedFile);

            var api = new LibsndfileApi(mock.Object);
            api.Close(new IntPtr(1));
        }
예제 #25
0
        public void GetLibVersion_ReturnsCorrectVersion()
        {
            var api = new LibsndfileApi();

            var version = api.Commands.GetLibVersion();

            Assert.That(!string.IsNullOrEmpty(version));
        }
예제 #26
0
        public void ErrorString_ShouldThrowExceptionOnEmptyStringReturned()
        {
            var mock = new Mock<ILibsndfileApi>();
            mock.Setup(x => x.ErrorString(It.IsAny<IntPtr>())).Returns(string.Empty);

            var api = new LibsndfileApi(mock.Object);
            api.ErrorString(new IntPtr(1));
        }
예제 #27
0
        public void ErrorNumber_ShouldThrowExceptionOnNullStringReturned()
        {
            var mock = new Mock<ILibsndfileApi>();
            mock.Setup(x => x.ErrorNumber(It.IsAny<int>())).Returns((string)null);

            var api = new LibsndfileApi(mock.Object);
            api.ErrorNumber(1);
        }
예제 #28
0
        public void Seek_ShouldThrowExceptionOnNegativeOffset()
        {
            var mock = new Mock<ILibsndfileApi>();
            mock.Setup(x => x.Seek(It.IsAny<IntPtr>(), It.IsAny<long>(), It.IsAny<int>())).Returns(-1);

            var api = new LibsndfileApi(mock.Object);
            api.Seek(new IntPtr(1), 1, 1);
        }
예제 #29
0
        public void CommandDoubleArray_ShouldThrowExceptionOnInvalidResult()
        {
            var data = new double[1];
            var mock = new Mock<ILibsndfileApi>();
            mock.Setup(x => x.Command(It.IsAny<IntPtr>(), It.IsAny<LibsndfileCommand>(), data, It.IsAny<int>())).Returns(-1);

            var api = new LibsndfileApi(mock.Object);
            api.Command(new IntPtr(1), It.IsAny<LibsndfileCommand>(), data, It.IsAny<int>());
        }
예제 #30
0
        public void Close_ShouldPassOnNoErrorResult()
        {
            var mock = new Mock<ILibsndfileApi>();
            mock.Setup(x => x.Close(It.IsAny<IntPtr>())).Returns(LibsndfileError.NoError);

            var api = new LibsndfileApi(mock.Object);
            var retval = api.Close(new IntPtr(1));

            Assert.AreEqual(LibsndfileError.NoError, retval);
        }
예제 #31
0
        public void SetString_ShouldPassOnNoErrorResult()
        {
            var mock = new Mock<ILibsndfileApi>();
            mock.Setup(x => x.SetString(It.IsAny<IntPtr>(), It.IsAny<LibsndfileStringType>(), It.IsAny<string>())).Returns(LibsndfileError.NoError);

            var api = new LibsndfileApi(mock.Object);
            var retval = api.SetString(new IntPtr(1), LibsndfileStringType.Album, "album");

            Assert.AreEqual(LibsndfileError.NoError, retval);
        }
예제 #32
0
        public void Seek_ShouldThrowExceptionOnNegativeOffset()
        {
            var mock = new Mock <ILibsndfileApi>();

            mock.Setup(x => x.Seek(It.IsAny <IntPtr>(), It.IsAny <long>(), It.IsAny <int>())).Returns(-1);

            var api = new LibsndfileApi(mock.Object);

            api.Seek(new IntPtr(1), 1, 1);
        }
예제 #33
0
        public void ErrorNumber_ShouldThrowExceptionOnNullStringReturned()
        {
            var mock = new Mock <ILibsndfileApi>();

            mock.Setup(x => x.ErrorNumber(It.IsAny <int>())).Returns((string)null);

            var api = new LibsndfileApi(mock.Object);

            api.ErrorNumber(1);
        }
예제 #34
0
        public void Close_ShouldThrowExceptionOnErrorResult()
        {
            var mock = new Mock <ILibsndfileApi>();

            mock.Setup(x => x.Close(It.IsAny <IntPtr>())).Returns(LibsndfileError.MalformedFile);

            var api = new LibsndfileApi(mock.Object);

            api.Close(new IntPtr(1));
        }
예제 #35
0
        public void CommandIntPtr_ShouldThrowExceptionOnInvalidResult()
        {
            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 LibsndfileApi(mock.Object);

            api.Command(new IntPtr(1), It.IsAny <LibsndfileCommand>(), It.IsAny <IntPtr>(), It.IsAny <int>());
        }
예제 #36
0
        public void SetString_ShouldThrowExceptionOnErrorResult()
        {
            var mock = new Mock <ILibsndfileApi>();

            mock.Setup(x => x.SetString(It.IsAny <IntPtr>(), It.IsAny <LibsndfileStringType>(), It.IsAny <string>())).Returns(LibsndfileError.MalformedFile);

            var api = new LibsndfileApi(mock.Object);

            api.SetString(new IntPtr(1), LibsndfileStringType.Album, "album");
        }
예제 #37
0
        public void ErrorString_ShouldThrowExceptionOnEmptyStringReturned()
        {
            var mock = new Mock <ILibsndfileApi>();

            mock.Setup(x => x.ErrorString(It.IsAny <IntPtr>())).Returns(string.Empty);

            var api = new LibsndfileApi(mock.Object);

            api.ErrorString(new IntPtr(1));
        }
예제 #38
0
        public void Close_ShouldPassOnNoErrorResult()
        {
            var mock = new Mock <ILibsndfileApi>();

            mock.Setup(x => x.Close(It.IsAny <IntPtr>())).Returns(LibsndfileError.NoError);

            var api    = new LibsndfileApi(mock.Object);
            var retval = api.Close(new IntPtr(1));

            Assert.AreEqual(LibsndfileError.NoError, retval);
        }
예제 #39
0
        public void CommandDoubleArray_ShouldPassOnZeroHandleWithStaticCommand()
        {
            var data = new double[1];
            var mock = new Mock<ILibsndfileApi>();
            mock.Setup(x => x.Command(It.IsAny<IntPtr>(), It.IsAny<LibsndfileCommand>(), It.IsAny<double[]>(), It.IsAny<int>())).Returns(1);

            var api = new LibsndfileApi(mock.Object);
            var retval = api.Command(IntPtr.Zero, LibsndfileCommand.GetLibVersion, data, It.IsAny<int>());

            Assert.Greater(retval, 0);
        }
예제 #40
0
        public void SetString_ShouldPassOnNoErrorResult()
        {
            var mock = new Mock <ILibsndfileApi>();

            mock.Setup(x => x.SetString(It.IsAny <IntPtr>(), It.IsAny <LibsndfileStringType>(), It.IsAny <string>())).Returns(LibsndfileError.NoError);

            var api    = new LibsndfileApi(mock.Object);
            var retval = api.SetString(new IntPtr(1), LibsndfileStringType.Album, "album");

            Assert.AreEqual(LibsndfileError.NoError, retval);
        }
예제 #41
0
        public void CommandIntPtr_ShouldPassOnZeroHandleWithStaticCommand()
        {
            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 LibsndfileApi(mock.Object);
            var retval = api.Command(IntPtr.Zero, LibsndfileCommand.GetLibVersion, IntPtr.Zero, It.IsAny <int>());

            Assert.Greater(retval, 0);
        }
예제 #42
0
        public void GetString_ShouldReturnValidString()
        {
            const string Tag = "AlbumTag";

            var mock = new Mock<ILibsndfileApi>();
            mock.Setup(x => x.GetString(It.IsAny<IntPtr>(), It.IsAny<LibsndfileStringType>())).Returns(Tag);

            var api = new LibsndfileApi(mock.Object);
            var retval = api.GetString(new IntPtr(1), It.IsAny<LibsndfileStringType>());

            Assert.AreEqual(Tag, retval);
        }
예제 #43
0
        public void OpenFileDescriptor_ShouldThrowExceptionOnZeroFileHandle()
        {
            var info = new LibsndfileInfo();

            var mock = new Mock<ILibsndfileApi>();
            mock.Setup(x => x.OpenFileDescriptor(It.IsAny<int>(), It.IsAny<LibsndfileMode>(), ref info, It.IsAny<int>())).Returns(IntPtr.Zero);

            var api = new LibsndfileApi(mock.Object);
            var retval = api.OpenFileDescriptor(20, LibsndfileMode.Read, ref info, 0);

            Assert.AreEqual(IntPtr.Zero, retval);
        }
예제 #44
0
        public void ErrorString_ShouldReturnValidErrorString()
        {
            const string ErrorString = "Libsndfile encountered no errors.";

            var mock = new Mock<ILibsndfileApi>();
            mock.Setup(x => x.ErrorString(It.IsAny<IntPtr>())).Returns(ErrorString);

            var api = new LibsndfileApi(mock.Object);
            var retval = api.ErrorString(new IntPtr(1));

            Assert.AreEqual(ErrorString, retval);
        }
예제 #45
0
        public void Seek_ShouldPassOnCorrectOffsetFromBeginning()
        {
            const int Result = 42;

            var mock = new Mock<ILibsndfileApi>();
            mock.Setup(x => x.Seek(It.IsAny<IntPtr>(), It.IsAny<long>(), It.IsAny<int>())).Returns(Result);

            var api = new LibsndfileApi(mock.Object);
            var retval = api.Seek(new IntPtr(1), 42, 1);

            Assert.AreEqual(Result, retval);
        }
예제 #46
0
        public void Open_ShouldReturnZeroHandleOnEmptyFileHandle()
        {
            var info = new LibsndfileInfo();

            var mock = new Mock<ILibsndfileApi>();
            mock.Setup(x => x.Open(It.IsAny<string>(), It.IsAny<LibsndfileMode>(), ref info)).Returns(IntPtr.Zero);

            var api = new LibsndfileApi(mock.Object);
            var retval = api.Open("junk.txt", LibsndfileMode.Read, ref info);

            Assert.AreEqual(IntPtr.Zero, retval);
        }
예제 #47
0
        public void ReadDoubleItems_ShouldReturnSameAsItemsRequested()
        {
            const long Items = 10;

            var mock = new Mock<ILibsndfileApi>();
            mock.Setup(x => x.ReadItems(It.IsAny<IntPtr>(), It.IsAny<double[]>(), It.IsAny<long>())).Returns(Items);

            var api = new LibsndfileApi(mock.Object);
            var buffer = new double[1];
            var retval = api.ReadItems(new IntPtr(1), buffer, Items);

            Assert.AreEqual(Items, retval);
        }
예제 #48
0
        public void ReadRaw_ShouldReturnSameAsItemsRequested()
        {
            const long Bytes = 10;

            var mock = new Mock<ILibsndfileApi>();
            mock.Setup(x => x.ReadRaw(It.IsAny<IntPtr>(), It.IsAny<byte[]>(), It.IsAny<long>())).Returns(Bytes);

            var api = new LibsndfileApi(mock.Object);
            var buffer = new byte[1];
            var retval = api.ReadRaw(new IntPtr(1), buffer, Bytes);

            Assert.AreEqual(Bytes, retval);
        }
예제 #49
0
        public void WriteFloatFrames_ShouldReturnSameAsItemsRequested()
        {
            const long Frames = 10;

            var mock = new Mock<ILibsndfileApi>();
            mock.Setup(x => x.WriteFrames(It.IsAny<IntPtr>(), It.IsAny<float[]>(), It.IsAny<long>())).Returns(Frames);

            var api = new LibsndfileApi(mock.Object);
            var buffer = new float[1];
            var retval = api.WriteFrames(new IntPtr(1), buffer, Frames);

            Assert.AreEqual(Frames, retval);
        }
예제 #50
0
        public void OpenFileDescriptor_ShouldThrowExceptionOnZeroFileHandle()
        {
            var info = new LibsndfileInfo();

            var mock = new Mock <ILibsndfileApi>();

            mock.Setup(x => x.OpenFileDescriptor(It.IsAny <int>(), It.IsAny <LibsndfileMode>(), ref info, It.IsAny <int>())).Returns(IntPtr.Zero);

            var api    = new LibsndfileApi(mock.Object);
            var retval = api.OpenFileDescriptor(20, LibsndfileMode.Read, ref info, 0);

            Assert.AreEqual(IntPtr.Zero, retval);
        }
예제 #51
0
        public void OpenWav_ReadWriteModeReturnsValidHandle()
        {
            var api = new LibsndfileApi();
            var info = TestConfiguration.GetValidWavFileInfo();

            Assert.That(File.Exists(TestConfiguration.ValidWavFile));

            var open = api.Open(TestConfiguration.ValidWavFile, LibsndfileMode.Rdwr, ref info);
            Assert.That(open != IntPtr.Zero);

            var close = api.Close(open);
            Assert.That(close == LibsndfileError.NoError);
        }
예제 #52
0
        public void Open_ShouldReturnZeroHandleOnEmptyFileHandle()
        {
            var info = new LibsndfileInfo();

            var mock = new Mock <ILibsndfileApi>();

            mock.Setup(x => x.Open(It.IsAny <string>(), It.IsAny <LibsndfileMode>(), ref info)).Returns(IntPtr.Zero);

            var api    = new LibsndfileApi(mock.Object);
            var retval = api.Open("junk.txt", LibsndfileMode.Read, ref info);

            Assert.AreEqual(IntPtr.Zero, retval);
        }
예제 #53
0
        public void FormatCheck_ShouldPassOnValidFormat()
        {
            const bool Result = true;

            var info = new LibsndfileInfo { Format = LibsndfileFormat.Wav, Channels = 1, SampleRate = 1 };

            var mock = new Mock<ILibsndfileApi>();
            mock.Setup(x => x.FormatCheck(ref info)).Returns(Result);

            var api = new LibsndfileApi(mock.Object);
            var retval = api.FormatCheck(ref info);

            Assert.AreEqual(Result, retval);
        }
예제 #54
0
        public void CalcMaxAllChannels_ReturnsValidData()
        {
            var api = new LibsndfileApi();
            var info = new LibsndfileInfo();

            var sndfile = api.Open(TestConfiguration.ValidWavFile, LibsndfileMode.Read, ref info);
            Assert.That(sndfile != IntPtr.Zero);

            var max = api.Commands.CalcMaxAllChannels(sndfile, info.Channels);
            Assert.That(max != null);
            Assert.That(max.Length == info.Channels);

            var close = api.Close(sndfile);
            Assert.That(close == LibsndfileError.NoError);
        }
예제 #55
0
        public void OpenWav_WriteModeReturnsValidHandle()
        {
            var api = new LibsndfileApi();
            var info = TestConfiguration.GetValidWavFileInfo();
            var filename = string.Format("tmp_{0}", TestConfiguration.ValidWavFile);

            var open = api.Open(filename, LibsndfileMode.Write, ref info);
            Assert.That(open != IntPtr.Zero);
            Assert.That(File.Exists(filename));

            var close = api.Close(open);
            Assert.That(close == LibsndfileError.NoError);

            File.Delete(filename);
            Assert.That(!File.Exists(filename));
        }
예제 #56
0
        public void ReadFramesShort_ReturnsValidData()
        {
            const long Items = 50;

            var api = new LibsndfileApi();
            var info = new LibsndfileInfo();

            var open = api.Open(TestConfiguration.ValidWavFile, LibsndfileMode.Read, ref info);
            Assert.That(open != IntPtr.Zero);

            var buffer = new short[Items];
            var read = api.ReadFrames(open, buffer, Items);
            Assert.That(Items == read);
            Assert.That(buffer != null);
            Assert.That(buffer.Length == Items);

            var close = api.Close(open);
            Assert.That(close == LibsndfileError.NoError);
        }
예제 #57
0
        public void ReadRaw_ShouldReturnLessThanItemsRequestedThenZeroOnNextRead()
        {
            const long Bytes = 10;
            const long PartialBytes = 10 - 5;

            var mock = new Mock<ILibsndfileApi>();
            mock.Setup(x => x.ReadRaw(It.IsAny<IntPtr>(), It.IsAny<byte[]>(), It.IsAny<long>())).Returns(PartialBytes);

            var api = new LibsndfileApi(mock.Object);
            var buffer = new byte[1];
            var retval = api.ReadRaw(new IntPtr(1), buffer, Bytes);

            Assert.AreEqual(PartialBytes, retval);

            mock.Setup(x => x.ReadRaw(It.IsAny<IntPtr>(), It.IsAny<byte[]>(), It.IsAny<long>())).Returns(0);
            retval = api.ReadRaw(new IntPtr(1), buffer, Bytes);

            Assert.AreEqual(0, retval);
        }
예제 #58
0
 public void ReadRaw_ShouldThrowExceptionOnLessThanZeroItems()
 {
     var api = new LibsndfileApi();
     var buffer = new byte[1];
     api.ReadRaw(new IntPtr(1), buffer, -1);
 }
예제 #59
0
 public void ReadRaw_ShouldThrowExceptionOnNullBuffer()
 {
     var api = new LibsndfileApi();
     byte[] buffer = null;
     api.ReadRaw(new IntPtr(1), buffer, It.IsAny<long>());
 }
예제 #60
0
 public void ReadRaw_ShouldThrowExceptionOnZeroHandle()
 {
     var api = new LibsndfileApi();
     api.ReadRaw(IntPtr.Zero, It.IsAny<byte[]>(), It.IsAny<long>());
 }