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.c75
1 files changed, 75 insertions, 0 deletions
diff --git a/src/channel.test.c b/src/channel.test.c
index 067879f..1b07350 100644
--- a/src/channel.test.c
+++ b/src/channel.test.c
@@ -68,6 +68,9 @@ void test_channel_init()
lily_assert_null(chan.sound.left);
lily_assert_null(chan.sound.right);
lily_assert_int_equal(chan.pos, 0);
+
+ lily_assert_null(chan.callback);
+ lily_assert_null(chan.userdata);
}
@@ -76,10 +79,12 @@ void test_channel_reset_last_loop()
struct channel_t chan;
chan.shared.active = true;
chan.shared.loops = 1;
+ chan.shared.trigger_callback = 0;
channel_reset(&chan);
lily_assert_int_equal(chan.shared.active, false);
+ lily_assert_int_equal(chan.shared.trigger_callback, 1);
}
@@ -113,6 +118,19 @@ void test_channel_reset_infinite_loop()
}
+void test_channel_reset_trigger_callback()
+{
+ struct channel_t chan;
+ chan.shared.active = true;
+ chan.shared.loops = 1;
+ chan.shared.trigger_callback = 0;
+
+ channel_reset(&chan);
+
+ lily_assert_int_equal(chan.shared.trigger_callback, 1);
+}
+
+
void test_channel_pause()
{
struct channel_t chan;
@@ -187,6 +205,59 @@ void test_channel_set_pan()
}
+void test_cb(int c, void *d) {}
+
+void test_channel_set_callback()
+{
+ struct channel_t chan;
+ chan.callback = NULL;
+ chan.userdata = NULL;
+ chan.shared.trigger_callback = 15;
+
+ channel_set_callback(&chan, test_cb, &chan);
+
+ lily_assert_int_equal(chan.shared.trigger_callback, 0);
+ lily_assert_ptr_equal(chan.callback, test_cb);
+ lily_assert_ptr_equal(chan.userdata, &chan);
+}
+
+
+void test_cb2(int c, void *d)
+{
+ int *x = d;
+ *x += 1;
+}
+
+void test_channel_poll_callbacks()
+{
+ struct channel_t chan;
+ chan.callback = test_cb2;
+ int x = 0;
+ chan.userdata = &x;
+ chan.shared.trigger_callback = 5;
+
+ channel_poll_callbacks(&chan, 0);
+
+ lily_assert_int_equal(x, 5);
+ lily_assert_int_equal(chan.shared.trigger_callback, 0);
+}
+
+
+void test_channel_poll_callbacks_none()
+{
+ struct channel_t chan;
+ chan.callback = test_cb2;
+ int x = 0;
+ chan.userdata = &x;
+ chan.shared.trigger_callback = 0;
+
+ channel_poll_callbacks(&chan, 0);
+
+ lily_assert_int_equal(x, 0);
+ lily_assert_int_equal(chan.shared.trigger_callback, 0);
+}
+
+
void test_channel_sound_load()
{
lily_mock_use(&mock_p_mutex_lock);
@@ -677,6 +748,7 @@ void suite_channel()
lily_run_test(test_channel_reset_last_loop);
lily_run_test(test_channel_reset_penultimate_loop);
lily_run_test(test_channel_reset_infinite_loop);
+ lily_run_test(test_channel_reset_trigger_callback);
lily_run_test(test_channel_sound_load);
lily_run_test(test_channel_sound_load_mono);
@@ -692,6 +764,9 @@ void suite_channel()
lily_run_test(test_channel_get_next_sample_mono_panned);
lily_run_test(test_channel_get_next_sample_panned);
+ lily_run_test(test_channel_poll_callbacks);
+ lily_run_test(test_channel_poll_callbacks_none);
+
lily_mock_destroy(mock_p_mutex_new);
lily_mock_destroy(mock_p_mutex_trylock);
lily_mock_destroy(mock_p_mutex_unlock);