aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Bishop <mbtyke@gmail.com>2013-03-01 13:49:13 -0500
committerMichael Bishop <mbtyke@gmail.com>2013-03-08 17:26:18 -0500
commit404380d16573f326cd04363dd926cdd303662dc6 (patch)
tree4a261f9162dc673dcf7fadeba2d758ce16133d40
parent03c82a1c25d6551675d3191810eecd628df04b3c (diff)
Added test that tests the basic functionality of SDL_Mixer including pausing and resuming both the Sound channels and Music channel.
-rwxr-xr-xtests/runner.py9
-rw-r--r--tests/sdl_audio_mix.c75
-rw-r--r--tests/sounds/pluck.oggbin0 -> 69092 bytes
-rw-r--r--tests/sounds/the_entertainer.oggbin0 -> 557640 bytes
4 files changed, 84 insertions, 0 deletions
diff --git a/tests/runner.py b/tests/runner.py
index cdc8684b..fce374c8 100755
--- a/tests/runner.py
+++ b/tests/runner.py
@@ -10633,6 +10633,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..6866f555
--- /dev/null
+++ b/tests/sdl_audio_mix.c
@@ -0,0 +1,75 @@
+#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);
+ assert(soundChannel != -1);
+ break;
+ case 2:
+ 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);
+
+ 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