using Amphora; using System; using UnitTestSharp; using static StbVorbisSharp.StbVorbis; namespace Susurrus.UnitTests { public class OggFailureKindTests : TestFixture { public static readonly OggFailureKind Sample = new OggFailureKind("Susurrus.UnitTests.Ogg"); public static string DescriptionOf(STBVorbisError error) { return Sample.Fail(error).Describe(); } public class CtorTests : TestFixture { public void KeepsItsName() { CheckEqual("Susurrus.UnitTests.Ogg", Sample.Name); } } public class FailTests : TestFixture { public void ReturnsAFailureOfThisKind() { Status status = Sample.Fail(STBVorbisError.VORBIS_invalid_setup); CheckFalse(status.IsOk); CheckTrue(ReferenceEquals(Sample, status.Kind)); } } public class ReadTests : TestFixture { public void ReturnsTheErrorTheFailureCarries() { Status status = Sample.Fail(STBVorbisError.VORBIS_cant_find_last_page); CheckEqual(STBVorbisError.VORBIS_cant_find_last_page, Sample.Read(in status)); } public void AFailureOfAnotherKind_Throws() { Status status = DetailFailureKindTests.Sample.Fail("the cause"); CheckThrow(typeof(ArgumentException)); Sample.Read(in status); } } public class DescribeTests : TestFixture { public void EachKnownError_HasItsOwnMessage() { CheckEqual("The file ends before the data the decoder needs.", DescriptionOf(STBVorbisError.VORBIS_need_more_data)); CheckEqual("The decoder was used in a way it doesn't allow.", DescriptionOf(STBVorbisError.VORBIS_invalid_api_mixing)); CheckEqual("The decoder ran out of memory.", DescriptionOf(STBVorbisError.VORBIS_outofmem)); CheckEqual("The file uses a Vorbis feature the decoder doesn't support.", DescriptionOf(STBVorbisError.VORBIS_feature_not_supported)); CheckEqual("The file has more channels than the decoder supports.", DescriptionOf(STBVorbisError.VORBIS_too_many_channels)); CheckEqual("The decoder couldn't open the file.", DescriptionOf(STBVorbisError.VORBIS_file_open_failure)); CheckEqual("The decoder can't seek in a file whose length it doesn't know.", DescriptionOf(STBVorbisError.VORBIS_seek_without_length)); CheckEqual("The file ends before the audio does.", DescriptionOf(STBVorbisError.VORBIS_unexpected_eof)); CheckEqual("The decoder was asked to seek past the end of the audio.", DescriptionOf(STBVorbisError.VORBIS_seek_invalid)); CheckEqual("The file's Vorbis setup header is invalid.", DescriptionOf(STBVorbisError.VORBIS_invalid_setup)); CheckEqual("The file's Vorbis stream is invalid.", DescriptionOf(STBVorbisError.VORBIS_invalid_stream)); CheckEqual("The file doesn't have an Ogg page where one should start.", DescriptionOf(STBVorbisError.VORBIS_missing_capture_pattern)); CheckEqual("The file's Ogg stream structure version isn't one the decoder supports.", DescriptionOf(STBVorbisError.VORBIS_invalid_stream_structure_version)); CheckEqual("An Ogg page in the file has a wrong continued-packet flag.", DescriptionOf(STBVorbisError.VORBIS_continued_packet_flag_invalid)); CheckEqual("An Ogg page in the file belongs to a different stream.", DescriptionOf(STBVorbisError.VORBIS_incorrect_stream_serial_number)); CheckEqual("The file's first Ogg page isn't a Vorbis header.", DescriptionOf(STBVorbisError.VORBIS_invalid_first_page)); CheckEqual("A Vorbis packet in the file has a type the decoder doesn't know.", DescriptionOf(STBVorbisError.VORBIS_bad_packet_type)); CheckEqual("The file's last Ogg page can't be found, so its length is unknown.", DescriptionOf(STBVorbisError.VORBIS_cant_find_last_page)); CheckEqual("The decoder failed to seek in the file.", DescriptionOf(STBVorbisError.VORBIS_seek_failed)); CheckEqual("The file uses Ogg Skeleton, which the decoder doesn't support.", DescriptionOf(STBVorbisError.VORBIS_ogg_skeleton_not_supported)); } public void AnErrorTheDecoderHasNoNameFor_GivesItsNumber() { CheckEqual("The Ogg Vorbis decoder failed with error 99.", DescriptionOf((STBVorbisError)99)); } } } }