mirror of
https://github.com/ZDoom/fluidsynth.git
synced 2025-01-31 13:40:35 +00:00
Add a unit test for fluid_sample_validate()
This commit is contained in:
parent
872c6bc678
commit
76f4bc3db3
2 changed files with 107 additions and 0 deletions
|
@ -17,6 +17,7 @@ ADD_FLUID_TEST(test_synth_chorus_reverb)
|
|||
ADD_FLUID_TEST(test_snprintf)
|
||||
ADD_FLUID_TEST(test_synth_process)
|
||||
ADD_FLUID_TEST(test_ct2hz)
|
||||
ADD_FLUID_TEST(test_sample_validate)
|
||||
ADD_FLUID_TEST(test_seq_event_queue_sort)
|
||||
ADD_FLUID_TEST(test_seq_scale)
|
||||
ADD_FLUID_TEST(test_jack_obtaining_synth)
|
||||
|
|
106
test/test_sample_validate.c
Normal file
106
test/test_sample_validate.c
Normal file
|
@ -0,0 +1,106 @@
|
|||
|
||||
#include "test.h"
|
||||
#include "fluidsynth.h"
|
||||
#include "sfloader/fluid_sfont.h"
|
||||
#include "utils/fluid_sys.h"
|
||||
|
||||
|
||||
// this tests ensures that samples with invalid SfSampleType flag combinations are rejected
|
||||
int main(void)
|
||||
{
|
||||
fluid_sample_t* sample = new_fluid_sample();
|
||||
sample->start = 0;
|
||||
sample->end = 1;
|
||||
|
||||
/// valid flags
|
||||
{
|
||||
sample->sampletype = FLUID_SAMPLETYPE_OGG_VORBIS;
|
||||
TEST_SUCCESS(fluid_sample_validate(sample, 2));
|
||||
|
||||
sample->sampletype = FLUID_SAMPLETYPE_LINKED;
|
||||
TEST_SUCCESS(fluid_sample_validate(sample, 2));
|
||||
|
||||
sample->sampletype = FLUID_SAMPLETYPE_MONO;
|
||||
TEST_SUCCESS(fluid_sample_validate(sample, 2));
|
||||
|
||||
sample->sampletype = FLUID_SAMPLETYPE_RIGHT;
|
||||
TEST_SUCCESS(fluid_sample_validate(sample, 2));
|
||||
|
||||
sample->sampletype = FLUID_SAMPLETYPE_LEFT;
|
||||
TEST_SUCCESS(fluid_sample_validate(sample, 2));
|
||||
}
|
||||
|
||||
/// valid, but unsupported linked sample flags
|
||||
{
|
||||
sample->sampletype = FLUID_SAMPLETYPE_LINKED;
|
||||
TEST_SUCCESS(fluid_sample_validate(sample, 2));
|
||||
|
||||
sample->sampletype = FLUID_SAMPLETYPE_LINKED | FLUID_SAMPLETYPE_OGG_VORBIS;
|
||||
TEST_SUCCESS(fluid_sample_validate(sample, 2));
|
||||
|
||||
sample->sampletype = FLUID_SAMPLETYPE_LINKED | FLUID_SAMPLETYPE_MONO;
|
||||
TEST_SUCCESS(fluid_sample_validate(sample, 2));
|
||||
|
||||
sample->sampletype = FLUID_SAMPLETYPE_LINKED | FLUID_SAMPLETYPE_RIGHT;
|
||||
TEST_SUCCESS(fluid_sample_validate(sample, 2));
|
||||
|
||||
sample->sampletype = FLUID_SAMPLETYPE_LINKED | FLUID_SAMPLETYPE_LEFT;
|
||||
TEST_SUCCESS(fluid_sample_validate(sample, 2));
|
||||
}
|
||||
|
||||
/// valid, but rejected ROM sample flags
|
||||
{
|
||||
sample->sampletype = FLUID_SAMPLETYPE_ROM;
|
||||
TEST_ASSERT(fluid_sample_validate(sample, 2) == FLUID_FAILED);
|
||||
|
||||
sample->sampletype = FLUID_SAMPLETYPE_ROM | FLUID_SAMPLETYPE_OGG_VORBIS;
|
||||
TEST_ASSERT(fluid_sample_validate(sample, 2) == FLUID_FAILED);
|
||||
|
||||
sample->sampletype = FLUID_SAMPLETYPE_ROM | FLUID_SAMPLETYPE_LINKED;
|
||||
TEST_ASSERT(fluid_sample_validate(sample, 2) == FLUID_FAILED);
|
||||
|
||||
sample->sampletype = FLUID_SAMPLETYPE_ROM | FLUID_SAMPLETYPE_MONO;
|
||||
TEST_ASSERT(fluid_sample_validate(sample, 2) == FLUID_FAILED);
|
||||
|
||||
sample->sampletype = FLUID_SAMPLETYPE_ROM | FLUID_SAMPLETYPE_RIGHT;
|
||||
TEST_ASSERT(fluid_sample_validate(sample, 2) == FLUID_FAILED);
|
||||
|
||||
sample->sampletype = FLUID_SAMPLETYPE_ROM | FLUID_SAMPLETYPE_LEFT;
|
||||
TEST_ASSERT(fluid_sample_validate(sample, 2) == FLUID_FAILED);
|
||||
}
|
||||
|
||||
/// invalid flag combinations
|
||||
{
|
||||
// no flags set? technically illegal, but handle it as mono
|
||||
sample->sampletype = 0;
|
||||
TEST_SUCCESS(fluid_sample_validate(sample, 2));
|
||||
|
||||
sample->sampletype = FLUID_SAMPLETYPE_MONO | FLUID_SAMPLETYPE_RIGHT;
|
||||
TEST_SUCCESS(fluid_sample_validate(sample, 2));
|
||||
|
||||
sample->sampletype |= FLUID_SAMPLETYPE_LEFT;
|
||||
TEST_SUCCESS(fluid_sample_validate(sample, 2));
|
||||
|
||||
sample->sampletype |= FLUID_SAMPLETYPE_LINKED;
|
||||
TEST_SUCCESS(fluid_sample_validate(sample, 2));
|
||||
}
|
||||
|
||||
// unknown flags must be rejected (this seems to be implicitly required by SF3)
|
||||
{
|
||||
sample->sampletype = 0x20;
|
||||
TEST_ASSERT(fluid_sample_validate(sample, 2) == FLUID_FAILED);
|
||||
|
||||
sample->sampletype |= 0x40;
|
||||
TEST_ASSERT(fluid_sample_validate(sample, 2) == FLUID_FAILED);
|
||||
|
||||
sample->sampletype = 0x80;
|
||||
TEST_ASSERT(fluid_sample_validate(sample, 2) == FLUID_FAILED);
|
||||
|
||||
sample->sampletype <<= 1;
|
||||
TEST_ASSERT(fluid_sample_validate(sample, 2) == FLUID_FAILED);
|
||||
}
|
||||
|
||||
delete_fluid_sample(sample);
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
Loading…
Reference in a new issue