summaryrefslogtreecommitdiff
path: root/src/channel.test.c
blob: e7f7e0616c4cf78003d702230492b77c39677613 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#include "test/mossrose-test.h"
#include <plibsys.h>

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);
}