summaryrefslogtreecommitdiff
path: root/src/channel.test.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/channel.test.c')
-rw-r--r--src/channel.test.c172
1 files changed, 169 insertions, 3 deletions
diff --git a/src/channel.test.c b/src/channel.test.c
index c0a7e73..cab741b 100644
--- a/src/channel.test.c
+++ b/src/channel.test.c
@@ -3,10 +3,12 @@
PMutex * mock_p_mutex_new_();
pboolean mock_p_mutex_trylock_();
+pboolean mock_p_mutex_lock_();
pboolean mock_p_mutex_unlock_();
#define p_mutex_new mock_p_mutex_new_
#define p_mutex_trylock mock_p_mutex_trylock_
+#define p_mutex_lock mock_p_mutex_lock_
#define p_mutex_unlock mock_p_mutex_unlock_
#include "channel.c"
#undef p_mutex_new
@@ -31,6 +33,12 @@ pboolean mock_p_mutex_trylock_(PMutex *m)
return result;
}
+lily_mock_t *mock_p_mutex_lock = NULL;
+pboolean mock_p_mutex_lock_(PMutex *m)
+{
+ mock_p_mutex_lock->n_calls += 1;
+ return TRUE;
+}
lily_mock_t *mock_p_mutex_unlock = NULL;
pboolean mock_p_mutex_unlock_(PMutex *m)
@@ -78,9 +86,6 @@ void test_channel_reset()
lily_assert_int_equal(chan.pos, 0);
lily_assert_int_equal(chan.active, false);
lily_assert_int_equal(chan.paused, false);
- lily_assert_int_equal(chan.volume, 255);
- lily_assert_int_equal(chan.pan_left, -128);
- lily_assert_int_equal(chan.pan_right, 128);
}
@@ -158,6 +163,162 @@ void test_channel_set_pan()
}
+void test_channel_sound_load()
+{
+ lily_mock_use(&mock_p_mutex_lock);
+ lily_mock_use(&mock_p_mutex_unlock);
+
+ float audio_left[] = { 0.2, 0.5, 1.0 };
+ float audio_right[] = { 1.0, 0.5, 0.2 };
+ struct mossrose_sound_t sound;
+ sound.left = audio_left;
+ sound.right = audio_right;
+ sound.mono = false;
+ sound.len = 3;
+
+ struct channel_t chan;
+ chan.active = false;
+ chan.sound.left = NULL;
+ chan.sound.right = NULL;
+
+ int result = channel_sound_load(&chan, &sound, false);
+
+ lily_assert_int_equal(mock_p_mutex_lock->n_calls, 1);
+ lily_assert_int_equal(mock_p_mutex_unlock->n_calls, 1);
+ lily_assert_int_equal(result, 0);
+
+ lily_assert_int_equal(chan.active, true);
+ lily_assert_int_equal(chan.paused, false);
+ lily_assert_int_equal(chan.volume, 255);
+ lily_assert_int_equal(chan.pan_left, -128);
+ lily_assert_int_equal(chan.pan_right, 128);
+
+ lily_assert_memory_equal(chan.sound.left, audio_left, sizeof(audio_left));
+ lily_assert_memory_equal(chan.sound.right, audio_right, sizeof(audio_right));
+ lily_assert_int_equal(chan.sound.mono, false);
+ lily_assert_int_equal(chan.pos, 0);
+}
+
+
+void test_channel_sound_load_mono()
+{
+ lily_mock_use(&mock_p_mutex_lock);
+ lily_mock_use(&mock_p_mutex_unlock);
+
+ float audio[] = { 0.2, 0.5, 1.0 };
+ struct mossrose_sound_t sound;
+ sound.left = audio;
+ sound.right = NULL;
+ sound.mono = true;
+ sound.len = 3;
+
+ struct channel_t chan;
+ chan.active = false;
+ chan.sound.left = NULL;
+ chan.sound.right = NULL;
+
+ int result = channel_sound_load(&chan, &sound, false);
+
+ lily_assert_int_equal(mock_p_mutex_lock->n_calls, 1);
+ lily_assert_int_equal(mock_p_mutex_unlock->n_calls, 1);
+ lily_assert_int_equal(result, 0);
+
+ lily_assert_int_equal(chan.active, true);
+ lily_assert_int_equal(chan.paused, false);
+ lily_assert_int_equal(chan.volume, 255);
+ lily_assert_int_equal(chan.pan_left, 0);
+ lily_assert_int_equal(chan.pan_right, 0);
+
+ lily_assert_memory_equal(chan.sound.left, audio, sizeof(audio));
+ lily_assert_null(chan.sound.right);
+ lily_assert_int_equal(chan.sound.mono, true);
+ lily_assert_int_equal(chan.pos, 0);
+}
+
+
+void test_channel_sound_load_preserve()
+{
+ lily_mock_use(&mock_p_mutex_lock);
+ lily_mock_use(&mock_p_mutex_unlock);
+
+ float audio_left[] = { 0.2, 0.5, 1.0 };
+ float audio_right[] = { 1.0, 0.5, 0.2 };
+ struct mossrose_sound_t sound;
+ sound.left = audio_left;
+ sound.right = audio_right;
+ sound.mono = false;
+ sound.len = 3;
+
+ struct channel_t chan;
+ chan.active = false;
+ chan.sound.left = NULL;
+ chan.sound.right = NULL;
+ chan.volume = 127;
+ chan.pan_left = 0;
+ chan.pan_right = 64;
+
+ int result = channel_sound_load(&chan, &sound, true);
+
+ lily_assert_int_equal(mock_p_mutex_lock->n_calls, 1);
+ lily_assert_int_equal(mock_p_mutex_unlock->n_calls, 1);
+ lily_assert_int_equal(result, 0);
+
+ lily_assert_int_equal(chan.active, true);
+ lily_assert_int_equal(chan.paused, false);
+ lily_assert_int_equal(chan.volume, 127);
+ lily_assert_int_equal(chan.pan_left, 0);
+ lily_assert_int_equal(chan.pan_right, 64);
+
+ lily_assert_memory_equal(chan.sound.left, audio_left, sizeof(audio_left));
+ lily_assert_memory_equal(chan.sound.right, audio_right, sizeof(audio_right));
+ lily_assert_int_equal(chan.sound.mono, false);
+ lily_assert_int_equal(chan.pos, 0);
+}
+
+
+void test_channel_sound_fail()
+{
+ lily_mock_use(&mock_p_mutex_lock);
+ lily_mock_use(&mock_p_mutex_unlock);
+
+ float audio_left[] = { 0.2, 0.5, 1.0 };
+ float audio_right[] = { 1.0, 0.5, 0.2 };
+ struct mossrose_sound_t sound;
+ sound.left = audio_left;
+ sound.right = audio_right;
+ sound.mono = false;
+ sound.len = 3;
+
+ struct channel_t chan;
+ chan.active = true;
+ chan.paused = true;
+ chan.volume = 2;
+ chan.pan_left = 4;
+ chan.pan_right = 4;
+ chan.sound.left = NULL;
+ chan.sound.right = NULL;
+ chan.sound.mono = true;
+ chan.pos = 6;
+
+ int result = channel_sound_load(&chan, &sound, false);
+
+ lily_assert_int_equal(mock_p_mutex_lock->n_calls, 0);
+ lily_assert_int_equal(mock_p_mutex_unlock->n_calls, 0);
+ lily_assert_int_equal(result, 1);
+
+ lily_assert_int_equal(chan.active, true);
+ lily_assert_int_equal(chan.paused, true);
+ lily_assert_int_equal(chan.volume, 2);
+ lily_assert_int_equal(chan.pan_left, 4);
+ lily_assert_int_equal(chan.pan_right, 4);
+
+ lily_assert_null(chan.sound.left);
+ lily_assert_null(chan.sound.right);
+ lily_assert_int_equal(chan.sound.mono, true);
+ lily_assert_int_equal(chan.pos, 6);
+}
+
+
/* get_next_sample tests */
void test_channel_get_next_sample_inactive()
{
@@ -471,6 +632,11 @@ void suite_channel()
lily_run_test(test_channel_set_volume);
lily_run_test(test_channel_set_pan);
+ lily_run_test(test_channel_sound_load);
+ lily_run_test(test_channel_sound_load_mono);
+ lily_run_test(test_channel_sound_load_preserve);
+ lily_run_test(test_channel_sound_fail);
+
lily_run_test(test_channel_get_next_sample_inactive);
lily_run_test(test_channel_get_next_sample_paused);
lily_run_test(test_channel_get_next_sample_normal);