diff options
author | Michael J. Bishop <mbtyke@gmail.com> | 2013-06-21 13:42:17 -0400 |
---|---|---|
committer | Michael J. Bishop <mbtyke@gmail.com> | 2013-06-21 13:42:17 -0400 |
commit | 5c97a8d4bd2254f54b21e8094d581e8c0126844b (patch) | |
tree | b575ef12f00c33e47a70962f84b8ad78d2454c33 | |
parent | 1911d7bdd0c4571a0cbc0a97321cc1c4dbdb863e (diff) |
Added test to make sure channel allocation failed when it
was exhausted.
To run it:
python tests/runner.py browser.test_sdl_audio_mix_channels
-rwxr-xr-x | tests/runner.py | 7 | ||||
-rw-r--r-- | tests/sdl_audio_mix_channels.c | 59 |
2 files changed, 66 insertions, 0 deletions
diff --git a/tests/runner.py b/tests/runner.py index 610a39f6..1b4b1f0f 100755 --- a/tests/runner.py +++ b/tests/runner.py @@ -12401,6 +12401,13 @@ elif 'browser' in str(sys.argv): Popen([PYTHON, EMCC, '-O2', '--closure', '1', '--minify', '0', os.path.join(self.get_dir(), 'sdl_audio.c'), '--preload-file', 'sound.ogg', '--preload-file', 'sound2.wav', '--preload-file', 'bad.ogg', '-o', 'page.html', '-s', 'EXPORTED_FUNCTIONS=["_main", "_play", "_play2"]']).communicate() self.run_browser('page.html', '', '/report_result?1') + def test_sdl_audio_mix_channels(self): + shutil.copyfile(path_from_root('tests', 'sounds', 'noise.ogg'), os.path.join(self.get_dir(), 'sound.ogg')) + open(os.path.join(self.get_dir(), 'sdl_audio_mix_channels.c'), 'w').write(self.with_report_result(open(path_from_root('tests', 'sdl_audio_mix_channels.c')).read())) + + Popen([PYTHON, EMCC, '-O2', '--minify', '0', os.path.join(self.get_dir(), 'sdl_audio_mix_channels.c'), '--preload-file', 'sound.ogg', '-o', 'page.html']).communicate() + self.run_browser('page.html', '', '/report_result?1') + def test_sdl_audio_mix(self): shutil.copyfile(path_from_root('tests', 'sounds', 'pluck.ogg'), os.path.join(self.get_dir(), 'sound.ogg')) shutil.copyfile(path_from_root('tests', 'sounds', 'the_entertainer.ogg'), os.path.join(self.get_dir(), 'music.ogg')) diff --git a/tests/sdl_audio_mix_channels.c b/tests/sdl_audio_mix_channels.c new file mode 100644 index 00000000..dd91d594 --- /dev/null +++ b/tests/sdl_audio_mix_channels.c @@ -0,0 +1,59 @@ +#include <stdio.h> +#include <SDL/SDL.h> +#include <SDL/SDL_mixer.h> +#include <assert.h> +#include <emscripten.h> + +static Mix_Chunk *sound = NULL; +static Mix_Chunk *noiseLoop = NULL; +static Mix_Music *music = NULL; + +static int soundChannel = 0; +static int noiseLoopChannel = 0; + +static const int kNumChannels = 40; + +static int loadAndPlay() +{ + return Mix_PlayChannel(-1, sound, -1); +} + +int main(int argc, char **argv) { + SDL_Init(SDL_INIT_AUDIO); + Mix_Init(MIX_INIT_OGG); + + int ret = Mix_OpenAudio(0, 0, 0, 0); // we ignore all these.. + assert(ret == 0); + + Mix_AllocateChannels(kNumChannels); + + sound = Mix_LoadWAV("sound.ogg"); + + // allocate all the channels + for ( int i = 0; i < kNumChannels; i++ ) + { + assert(loadAndPlay() != -1); + } + + // This point, we should have exhausted our channels + + + + + int lastChannel = loadAndPlay(); + +#if EMSCRIPTEN + int result = (lastChannel == -1); + REPORT_RESULT(); +#endif + + assert(lastChannel == -1); + + // force a quit + while(Mix_Init(0)) + Mix_Quit(); + Mix_CloseAudio(); + + return 0; +} + |