Skip to content

Commit 3cf99e2

Browse files
committed
Add tests for checking available openal extensions
1 parent 4595376 commit 3cf99e2

File tree

2 files changed

+75
-0
lines changed

2 files changed

+75
-0
lines changed

test/openal_extensions.c

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
// So far just does some sanity checks for the available extensions.
2+
//
3+
// In the future, could also try to enable different extensions and test for
4+
// output correctness.
5+
6+
#include <stdio.h>
7+
#include <stdlib.h>
8+
#ifdef __EMSCRIPTEN__
9+
#include <emscripten.h>
10+
#define ASSUME_AL_FLOAT32
11+
#endif
12+
#include <AL/al.h>
13+
#include <AL/alc.h>
14+
#include <AL/alext.h>
15+
16+
static int result = EXIT_SUCCESS;
17+
18+
static void end_test() {
19+
#ifdef __EMSCRIPTEN__
20+
REPORT_RESULT(result);
21+
#endif
22+
exit(result);
23+
}
24+
25+
#define NUM_ALC_EXTENSIONS 2
26+
static const ALCchar *alc_extensions[NUM_ALC_EXTENSIONS] = {
27+
"ALC_SOFT_pause_device",
28+
"ALC_SOFT_HRTF",
29+
};
30+
31+
#define NUM_AL_EXTENSIONS 5
32+
static const ALCchar *al_extensions[NUM_AL_EXTENSIONS] = {
33+
"AL_EXT_float32",
34+
"AL_SOFT_loop_points",
35+
"AL_SOFT_source_length",
36+
"AL_EXT_source_distance_model",
37+
"AL_SOFT_source_spatialize",
38+
};
39+
40+
static void check_alc_extension(const ALCchar *extension) {
41+
ALCdevice *device = alcOpenDevice(NULL);
42+
if (!device) {
43+
fprintf(stderr, "Failed to open default device.");
44+
result = EXIT_FAILURE;
45+
return;
46+
}
47+
48+
if (alcIsExtensionPresent(device, extension) != ALC_TRUE) {
49+
fprintf(stderr, "Extension %s was not present.", extension);
50+
result = EXIT_FAILURE;
51+
}
52+
}
53+
54+
static void check_al_extension(const ALchar *extension) {
55+
if (alIsExtensionPresent(extension) != ALC_TRUE) {
56+
fprintf(stderr, "Extension %s was not present.", extension);
57+
result = EXIT_FAILURE;
58+
}
59+
}
60+
61+
int main() {
62+
63+
for(int i = 0; i < NUM_ALC_EXTENSIONS; i++) {
64+
check_alc_extension(alc_extensions[i]);
65+
}
66+
67+
for(int i = 0; i < NUM_AL_EXTENSIONS; i++) {
68+
check_al_extension(al_extensions[i]);
69+
}
70+
71+
end_test();
72+
}

test/test_browser.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2297,6 +2297,9 @@ def test_openal_error(self, args):
22972297
def test_openal_capture_sanity(self):
22982298
self.btest('openal_capture_sanity.c', expected='0')
22992299

2300+
def test_openal_extensions(self):
2301+
self.btest('openal_extensions.c', expected='0')
2302+
23002303
def test_runtimelink(self):
23012304
create_file('header.h', r'''
23022305
struct point {

0 commit comments

Comments
 (0)