public void TestReadNoOpen() { Mpg123 mpg123 = new Mpg123(); uint done = 0; byte[] buffer = new byte[100]; Assert.That(() => mpg123.Read(buffer, ref done), Throws.TypeOf <Mpg123.ErrorException>()); }
public void TestReadNullBuffer() { string dirName = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location); string path = Path.Combine(dirName, "bensound-epic.mp3"); Mpg123 mpg123 = new Mpg123(); mpg123.Open(path); uint done = 0; Assert.That(() => mpg123.Read(null, ref done), Throws.TypeOf <NullReferenceException>()); }
public void TestFeedReadNeedMore() { Mpg123 mpg123 = new Mpg123(); mpg123.OpenFeed(); byte[] inBuffer = new byte[8]; byte[] outBuffer = new byte[8]; uint done = 0; mpg123.Feed(inBuffer); Assert.That(mpg123.Read(outBuffer, ref done), Is.EqualTo(Mpg123.Errors.NEED_MORE)); }
public void TestReadOpen() { string dirName = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location); string path = Path.Combine(dirName, "bensound-epic.mp3"); byte[] buffer = new byte[1000]; Mpg123 mpg123 = new Mpg123(); mpg123.Open(path); uint done = 0; Assert.That(() => mpg123.Read(buffer, ref done), Throws.Nothing); }
public void TestReadNewFormat() { string dirName = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location); string path = Path.Combine(dirName, "bensound-epic.mp3"); Mpg123 mpg123 = new Mpg123(); mpg123.Open(path); uint done = 0; byte[] buffer = new byte[1000]; Assert.That(mpg123.Read(buffer, ref done), Is.EqualTo(Mpg123.Errors.NEW_FORMAT)); }
public void TestReadDoneBytes() { string dirName = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location); string path = Path.Combine(dirName, "bensound-scifi.mp3"); Mpg123 mpg123 = new Mpg123(); mpg123.Open(path); uint done = 0; byte[] buffer = new byte[1000]; while (mpg123.Read(buffer, ref done) != Mpg123.Errors.OK) { } Assert.That(done, Is.EqualTo(1000)); }
public void TestSeekToEndWithStreamLoaded() { string dirName = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location); string path = Path.Combine(dirName, "bensound-scifi.mp3"); Mpg123 mpg123 = new Mpg123(); mpg123.Open(path); byte[] buffer = new byte[1000]; uint end = 0; while (mpg123.Read(buffer, ref end) != Mpg123.Errors.OK) { } long seekOffset = mpg123.Seek(0, SeekOrigin.End); Assert.That(seekOffset, Is.GreaterThan(0)); }
public void TestReadNeedMore() { Mpg123 mpg123 = new Mpg123(); mpg123.OpenFeed(); byte[] buffer = new byte[8]; uint done = 0; int b = 0, c = 0; long a = 0; mpg123.GetFormat(ref a, ref b, ref c); Mpg123.Errors error = Mpg123.Errors.OK; Assert.That(() => error = mpg123.Read(buffer, ref done), Throws.Nothing); Assert.That(error, Is.EqualTo(Mpg123.Errors.NEED_MORE)); }
public void TestTellWithLoadedStream() { string dirName = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location); string path = Path.Combine(dirName, "bensound-scifi.mp3"); byte[] buffer = new byte[1000]; Mpg123 mpg123 = new Mpg123(); mpg123.Open(path); uint end = 0; while (mpg123.Read(buffer, ref end) != Mpg123.Errors.OK) { } long seekPosition = mpg123.Tell(); Assert.That(seekPosition, Is.GreaterThan(0)); }
public void TestReadEmptyBuffer() { string dirName = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location); string path = Path.Combine(dirName, "bensound-epic.mp3"); Mpg123 mpg123 = new Mpg123(); mpg123.Open(path); uint done = 0; byte[] buffer = new byte[0]; Mpg123.Errors error = Mpg123.Errors.OK; while (error == Mpg123.Errors.OK) { Assert.That(() => error = mpg123.Read(buffer, ref done), Throws.Nothing); } Assert.That(done, Is.EqualTo(0)); }
public void TestFeedReadNoNeedMore() { Mpg123 mpg123 = new Mpg123(); mpg123.OpenFeed(); string dirName = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location); string path = Path.Combine(dirName, "bensound-epic.mp3"); byte[] inBuffer = File.ReadAllBytes(path); byte[] outBuffer = new byte[inBuffer.Length]; uint done = 0; mpg123.Feed(inBuffer); long a = 0; int b = 0, c = 0; mpg123.GetFormat(ref a, ref b, ref c); Assert.That(mpg123.Read(outBuffer, ref done), Is.EqualTo(Mpg123.Errors.OK)); Assert.That(done, Is.EqualTo(inBuffer.Length)); }
public void TestSeekEndOutOfBounds() { string dirName = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location); string path = Path.Combine(dirName, "bensound-scifi.mp3"); Mpg123 mpg123 = new Mpg123(); mpg123.Open(path); byte[] buffer = new byte[1000]; uint end = 0; while (mpg123.Read(buffer, ref end) != Mpg123.Errors.OK) { } long offsets = 0; long step = 0; ulong fill = 0; mpg123.Index(ref offsets, ref step, ref fill); //i expect to get an exception because the seek will be set to (end + 1) Assert.That(() => mpg123.Seek(-1, SeekOrigin.Begin), Throws.TypeOf <Mpg123.ErrorException>()); }