Skip to content

Commit

Permalink
Let's not forget unit testing
Browse files Browse the repository at this point in the history
  • Loading branch information
nixxquality committed May 2, 2014
1 parent be19cd3 commit 1f1a52f
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 1 deletion.
26 changes: 25 additions & 1 deletion FFMSsharp.Tests/UnitTest1.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public void IndexerMatroska()
}

[TestMethod]
[ExpectedException(typeof(FFMSFileReadException))] // Yes. This surprised me too. It's not a NO_FILE error.
[ExpectedException(typeof(FileLoadException))]
public void IndexerFileNotFound()
{
Indexer indexer = new Indexer("this file doesn't exist.avi");
Expand Down Expand Up @@ -170,6 +170,30 @@ public void VideoSourceAndAPIFunctions()
Assert.AreEqual(71.939, source.LastTime);
}

[TestMethod]
[ExpectedException(typeof(FileLoadException))]
public void VideoSourceFileLoadException()
{
Index index = new Index("h264_720p_hp_5.1_3mbps_vorbis_styled_and_unstyled_subs_suzumiya.ffindex");
VideoSource source = index.VideoSource("this file doesn't exist.avi", 0);
}

[TestMethod]
[ExpectedException(typeof(ArgumentException))]
public void VideoSourceArgumentException()
{
Index index = new Index("h264_720p_hp_5.1_3mbps_vorbis_styled_and_unstyled_subs_suzumiya.ffindex");
VideoSource source = index.VideoSource("h264_720p_hp_5.1_3mbps_vorbis_styled_and_unstyled_subs_suzumiya.mkv", 10);
}

[TestMethod]
[ExpectedException(typeof(InvalidOperationException))]
public void VideoSourceInvalidOperationException()
{
Index index = new Index("h264_720p_hp_5.1_3mbps_vorbis_styled_and_unstyled_subs_suzumiya.ffindex");
VideoSource source = index.VideoSource("h264_720p_hp_3.1_600kbps_aac_mp3_dual_audio_harry_potter.mkv", 0);
}

[TestMethod]
[ExpectedException(typeof(ArgumentOutOfRangeException))]
public void VideoSourceGetFrameIntOutOfRange()
Expand Down
1 change: 1 addition & 0 deletions FFMSsharp/FFMSsharp.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions FFMSsharp/Index.cs
Original file line number Diff line number Diff line change
Expand Up @@ -448,6 +448,7 @@ public bool BelongsToFile(string sourceFile)
/// <seealso cref="AudioSource"/>
/// <seealso cref="GetFirstTrackOfType"/>
/// <seealso cref="GetFirstIndexedTrackOfType"/>
/// <exception cref="System.IO.FileLoadException">Failure to open the <paramref name="sourceFile"/></exception>
/// <exception cref="ArgumentException">Trying to make a VideoSource out of an invalid track</exception>
/// <exception cref="InvalidOperationException">Supplying the wrong <paramref name="sourceFile"/></exception>
public VideoSource VideoSource(string sourceFile, int track, int threads = 1, SeekMode seekMode = SeekMode.Normal)
Expand All @@ -461,6 +462,8 @@ public VideoSource VideoSource(string sourceFile, int track, int threads = 1, Se

if (videoSource == IntPtr.Zero)
{
if (err.ErrorType == FFMS_Errors.FFMS_ERROR_PARSER && err.SubType == FFMS_Errors.FFMS_ERROR_FILE_READ)
throw new System.IO.FileLoadException(err.Buffer);
if (err.ErrorType == FFMS_Errors.FFMS_ERROR_INDEX && err.SubType == FFMS_Errors.FFMS_ERROR_INVALID_ARGUMENT)
throw new ArgumentException(err.Buffer);
if (err.ErrorType == FFMS_Errors.FFMS_ERROR_INDEX && err.SubType == FFMS_Errors.FFMS_ERROR_FILE_MISMATCH)
Expand Down

0 comments on commit 1f1a52f

Please sign in to comment.