-
Notifications
You must be signed in to change notification settings - Fork 263
/
Copy pathtest_sample_validate.c
106 lines (77 loc) · 3.6 KB
/
test_sample_validate.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
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;
}