diff options
author | Jordi Vilalta Prat | 2009-02-15 06:10:59 +0000 |
---|---|---|
committer | Jordi Vilalta Prat | 2009-02-15 06:10:59 +0000 |
commit | fa6e10e9cec163845aa29e7940c86e9c9ab8a2bc (patch) | |
tree | ce87338830cc8c149e1de545246bcefe4f45da00 /engines/sci/sfx/tests/tests.cpp | |
parent | 7c148ddf021c990fa866b7600f979aac9a5b26c9 (diff) | |
download | scummvm-rg350-fa6e10e9cec163845aa29e7940c86e9c9ab8a2bc.tar.gz scummvm-rg350-fa6e10e9cec163845aa29e7940c86e9c9ab8a2bc.tar.bz2 scummvm-rg350-fa6e10e9cec163845aa29e7940c86e9c9ab8a2bc.zip |
Import the SCI engine sources from the FreeSCI Glutton branch (it doesn't compile yet)
svn-id: r38192
Diffstat (limited to 'engines/sci/sfx/tests/tests.cpp')
-rw-r--r-- | engines/sci/sfx/tests/tests.cpp | 172 |
1 files changed, 172 insertions, 0 deletions
diff --git a/engines/sci/sfx/tests/tests.cpp b/engines/sci/sfx/tests/tests.cpp new file mode 100644 index 0000000000..10eacc0de2 --- /dev/null +++ b/engines/sci/sfx/tests/tests.cpp @@ -0,0 +1,172 @@ +#include <stdio.h> +#include <sfx_iterator.h> + +#define TESTEQUAL(x, y) if(x != y) printf("test failure: expected %04x, got %04x @ file %s line %d \n", x, y, __FILE__, __LINE__); + +static char calledDeathListenerCallback; + +static unsigned char song[] = { +// PCM not present +0, +// channel defs +0, 0x20, 0, 0x21, 0, 0, 0, 0, +0, 0, 0, 0, 0, 0, 0, 0, +0, 0, 0, 0, 0, 0, 0, 0, +0, 0, 0, 0, 0, 0, 0, 0, +// note on, wait, note off +0xAA, +0x90, 0xAA, 0xAA, +0xAA, +0x80, 0xAA, 0xAA, +0xAA, +0x91, 0xAA, 0xAA, +0xAA, +0x81, 0xAA, 0xAA, +0xAA, +// end track +0xFC}; + +#define SONG_CMD_COUNT 10 + +#define TEST_SETUP() \ + unsigned char cmds[4] = {0}; \ + int result = 0; \ + int message; \ + int i; \ +\ + song_iterator_t *it = songit_new(song, sizeof(song), 0, 0); \ + it->init(it); \ + SIMSG_SEND(it, SIMSG_SET_PLAYMASK(0x20));\ + calledDeathListenerCallback = 0; + +#define TEST_TEARDOWN() \ + songit_free(it); + + +void testFinishSong() +{ + TEST_SETUP(); + message = songit_next(&it, &cmds, &result, IT_READER_MASK_ALL); + TESTEQUAL(0xAA, message); + + message = songit_next(&it, &cmds, &result, IT_READER_MASK_ALL); + TESTEQUAL(0, message); + TESTEQUAL(3, result); + + for (i=0; i < SONG_CMD_COUNT - 2; i++) + { + message = songit_next(&it, &cmds, &result, IT_READER_MASK_ALL); + } + + TESTEQUAL(SI_FINISHED, message); + + TEST_TEARDOWN(); +} + + +void DeathListenerCallback(void *v1, void *v2) +{ + calledDeathListenerCallback++; + return; +} + +void testDeathListener() +{ + TEST_SETUP(); + + song_iterator_add_death_listener( + it, + it, + (void (*)(void *, void*))DeathListenerCallback); + + for (i=0; i < SONG_CMD_COUNT; i++) + { + message = songit_next(&it, &cmds, &result, IT_READER_MASK_ALL); + } + + TESTEQUAL(SI_FINISHED, message); + + TEST_TEARDOWN(); + + TESTEQUAL(1, calledDeathListenerCallback); +} + +void testMultipleDeathListeners() +{ + TEST_SETUP(); + + song_iterator_add_death_listener( + it, + it, + (void (*)(void *, void*))DeathListenerCallback); + + song_iterator_add_death_listener( + it, + it, + (void (*)(void *, void*))DeathListenerCallback); + + for (i=0; i < SONG_CMD_COUNT; i++) + { + message = songit_next(&it, &cmds, &result, IT_READER_MASK_ALL); + } + + TESTEQUAL(SI_FINISHED, message); + + TEST_TEARDOWN(); + + TESTEQUAL(2, calledDeathListenerCallback); +} + +void testStopSong() +{ + TEST_SETUP(); + SIMSG_SEND(it, SIMSG_STOP); + + message = songit_next(&it, &cmds, &result, IT_READER_MASK_ALL); + TESTEQUAL(SI_FINISHED, message); + + TEST_TEARDOWN(); +} + +void testStopLoopedSong() +{ + TEST_SETUP(); + + SIMSG_SEND(it, SIMSG_SET_LOOPS(3)); + message = songit_next(&it, &cmds, &result, IT_READER_MASK_ALL); + TESTEQUAL(0xAA, message); + + SIMSG_SEND(it, SIMSG_STOP); + message = songit_next(&it, &cmds, &result, IT_READER_MASK_ALL); + TESTEQUAL(SI_FINISHED, message); + + TEST_TEARDOWN(); +} + +void testChangeSongMask() +{ + TEST_SETUP(); + + message = songit_next(&it, &cmds, &result, IT_READER_MASK_ALL); + TESTEQUAL(0xAA, message); + + SIMSG_SEND(it, SIMSG_SET_PLAYMASK(0x40)); + message = songit_next(&it, &cmds, &result, IT_READER_MASK_ALL); + TESTEQUAL(0, message); + TESTEQUAL(0, result); + + TEST_TEARDOWN(); +} + + +int main(int argc, char* argv[]) +{ + testFinishSong(); + testDeathListener(); + testMultipleDeathListeners(); + testStopSong(); + testStopLoopedSong(); + testChangeSongMask(); + return 0; +} + |