From 91726809f9e97d8d4fb7b6c0642234ff96535bdd Mon Sep 17 00:00:00 2001 From: sanine Date: Sun, 28 Aug 2022 12:41:53 -0500 Subject: add channel_init() and channel_reset() --- src/channel.test.c | 58 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) (limited to 'src/channel.test.c') diff --git a/src/channel.test.c b/src/channel.test.c index 96b7364..e7f7e06 100644 --- a/src/channel.test.c +++ b/src/channel.test.c @@ -1,6 +1,64 @@ #include "test/mossrose-test.h" +#include + +PMutex * mock_p_mutex_new_(); + +#define p_mutex_new mock_p_mutex_new_ +#include "channel.c" +#undef p_mutex_new + + +lily_mock_t *mock_p_mutex_new = NULL; +PMutex * mock_p_mutex_new_() +{ + mock_p_mutex_new->n_calls += 1; + return p_mutex_new(); +} + + +void test_channel_init() +{ + lily_mock_use(&mock_p_mutex_new); + + struct channel_t chan; + channel_init(&chan); + + lily_assert_int_equal(mock_p_mutex_new->n_calls, 1); + + 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, 0); + + lily_assert_null(chan.sound.left); + lily_assert_null(chan.sound.right); + lily_assert_int_equal(chan.pos, 0); +} + + +void test_channel_reset() +{ + struct channel_t chan; + chan.pos = 255; + chan.active = true; + chan.paused = true; + chan.volume = 5; + chan.pan = 30; + + channel_reset(&chan); + + 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, 0); +} void suite_channel() { + lily_run_test(test_channel_init); + lily_run_test(test_channel_reset); + + lily_mock_destroy(mock_p_mutex_new); } -- cgit v1.2.1