aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorAlon Zakai <alonzakai@gmail.com>2013-03-11 12:27:07 -0700
committerAlon Zakai <alonzakai@gmail.com>2013-03-11 12:27:07 -0700
commit4b2e7f4c10ab3f39012e4f7789ced834b14fc697 (patch)
tree98273aad127f7cdc9119a32751303a53c310c879 /tests
parent05cff2488488207978871fb81bd3949869f6d204 (diff)
parent81cdeaa3766e34acfb2f5cbaa25cf71d7d761bcc (diff)
Merge pull request #936 from michaeljbishop/add-mix-reservechannels
Add Mix_ReserveChannels
Diffstat (limited to 'tests')
-rwxr-xr-xtests/runner.py9
-rw-r--r--tests/sdl_audio_mix.c83
-rw-r--r--tests/sounds/pluck.oggbin0 -> 69092 bytes
-rw-r--r--tests/sounds/the_entertainer.oggbin0 -> 557640 bytes
4 files changed, 92 insertions, 0 deletions
diff --git a/tests/runner.py b/tests/runner.py
index eb0f8e7b..d46ca369 100755
--- a/tests/runner.py
+++ b/tests/runner.py
@@ -10779,6 +10779,15 @@ elif 'browser' in str(sys.argv):
Popen([PYTHON, EMCC, '-O2', '--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(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'))
+ open(os.path.join(self.get_dir(), 'sdl_audio_mix.c'), 'w').write(self.with_report_result(open(path_from_root('tests', 'sdl_audio_mix.c')).read()))
+
+ # use closure to check for a possible bug with closure minifying away newer Audio() attributes
+ Popen([PYTHON, EMCC, '-O2', '--minify', '0', os.path.join(self.get_dir(), 'sdl_audio_mix.c'), '--preload-file', 'sound.ogg', '--preload-file', 'music.ogg', '-o', 'page.html']).communicate()
+ self.run_browser('page.html', '', '/report_result?1')
+
def test_sdl_audio_quickload(self):
open(os.path.join(self.get_dir(), 'sdl_audio_quickload.c'), 'w').write(self.with_report_result(open(path_from_root('tests', 'sdl_audio_quickload.c')).read()))
diff --git a/tests/sdl_audio_mix.c b/tests/sdl_audio_mix.c
new file mode 100644
index 00000000..e3431e0c
--- /dev/null
+++ b/tests/sdl_audio_mix.c
@@ -0,0 +1,83 @@
+#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_Music *music = NULL;
+
+static int soundChannel = 0;
+
+void one_iter();
+void one_iter() {
+ static int frames = 0;
+ frames++;
+
+ switch( frames ) {
+ case 1:
+ soundChannel = Mix_PlayChannel(-1, sound, 0);
+ printf("channel = %d", soundChannel);
+ assert(soundChannel != -1 && soundChannel != 0);
+ break;
+ case 2:
+ printf("channel %d is playing = %d", soundChannel, Mix_Playing(soundChannel));
+ assert(Mix_Playing(soundChannel));
+ break;
+ case 30:
+ Mix_Pause(soundChannel);
+ Mix_PlayMusic(music, 1);
+ break;
+ case 31:
+ assert(Mix_Paused(soundChannel));
+ assert(Mix_PlayingMusic());
+ break;
+ case 60:
+ Mix_Resume(soundChannel);
+ Mix_PauseMusic();
+ break;
+ case 61:
+ assert(Mix_Playing(soundChannel));
+ assert(Mix_PausedMusic());
+ break;
+ case 90:
+ Mix_ResumeMusic();
+ break;
+ case 91:
+ assert(Mix_PlayingMusic());
+ break;
+ case 120:
+ Mix_HaltChannel(soundChannel);
+ Mix_HaltMusic();
+ break;
+ };
+}
+
+
+int main(int argc, char **argv) {
+ SDL_Init(SDL_INIT_AUDIO);
+ Mix_Init(MIX_INIT_OGG);
+
+ // This reserves channel 0 for other purposes.
+ // We are just going to verify that we are not
+ // allocated channel 0 when we call Mix_PlayChannel(-1, ...)
+ Mix_ReserveChannels(1);
+
+ int ret = Mix_OpenAudio(0, 0, 0, 0); // we ignore all these..
+ assert(ret == 0);
+
+ sound = Mix_LoadWAV("sound.ogg");
+ assert(sound);
+ music = Mix_LoadMUS("music.ogg");
+ assert(music);
+
+ emscripten_set_main_loop(one_iter, 30, 0);
+
+ // force a quit
+ while(Mix_Init(0))
+ Mix_Quit();
+ Mix_CloseAudio();
+
+ return 0;
+}
+
diff --git a/tests/sounds/pluck.ogg b/tests/sounds/pluck.ogg
new file mode 100644
index 00000000..20f7b854
--- /dev/null
+++ b/tests/sounds/pluck.ogg
Binary files differ
diff --git a/tests/sounds/the_entertainer.ogg b/tests/sounds/the_entertainer.ogg
new file mode 100644
index 00000000..249e74f7
--- /dev/null
+++ b/tests/sounds/the_entertainer.ogg
Binary files differ