check_stream.c 4.43 KB
Newer Older
1
2
#include <check.h>

3
#include "cfg.h"
Moritz Grimm's avatar
Moritz Grimm committed
4
#include "log.h"
5
#include "mdata.h"
6
#include "stream.h"
7
#include "xalloc.h"
8
9
10
11
12
13
14

Suite * stream_suite(void);
void	setup_checked(void);
void	teardown_checked(void);

START_TEST(test_stream)
{
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
	stream_t		 s;
	mdata_t 		 m;
	char			*m_str;
	cfg_server_t		 srv_cfg;
	cfg_stream_t		 str_cfg;
	cfg_server_list_t	 servers = cfg_get_servers();
	cfg_stream_list_t	 streams = cfg_get_streams();

	s = stream_create("test-stream");
	ck_assert_ptr_ne(s, NULL);

	ck_assert_int_ne(stream_connect(s), 0);
	stream_disconnect(s);
	stream_sync(s);
	ck_assert_int_ne(stream_send(s, NULL, 0), 0);

	srv_cfg = stream_get_cfg_server(s);
	ck_assert_ptr_ne(srv_cfg, NULL);
	str_cfg = stream_get_cfg_stream(s);
	ck_assert_ptr_ne(str_cfg, NULL);
35
	ck_assert_ptr_ne(stream_get_cfg_intake(s), NULL);
36
37

	ck_assert_int_ne(stream_configure(s), 0);
38
	ck_assert_int_eq(cfg_server_set_hostname(srv_cfg, servers, "localhost", NULL), 0);
39
	ck_assert_int_ne(stream_configure(s), 0);
40
	ck_assert_int_eq(cfg_server_set_password(srv_cfg, servers, "test", NULL), 0);
41
	ck_assert_int_ne(stream_configure(s), 0);
42
	ck_assert_int_eq(cfg_server_set_tls(srv_cfg, servers, "required", NULL), 0);
43
	ck_assert_int_ne(stream_configure(s), 0);
44
	ck_assert_int_eq(cfg_server_set_tls(srv_cfg, servers, "may", NULL), 0);
45
	ck_assert_int_ne(stream_configure(s), 0);
46
	ck_assert_int_eq(cfg_server_set_tls(srv_cfg, servers, "none", NULL), 0);
47
	ck_assert_int_ne(stream_configure(s), 0);
48
	ck_assert_int_eq(cfg_stream_set_mountpoint(str_cfg, streams, "/test.ogg", NULL), 0);
49
	ck_assert_int_ne(stream_configure(s), 0);
50
	ck_assert_int_eq(cfg_stream_set_format(str_cfg, streams, "mp3", NULL), 0);
51
	ck_assert_int_eq(stream_configure(s), 0);
52
	ck_assert_int_eq(cfg_stream_set_format(str_cfg, streams, "ogg", NULL), 0);
53
	ck_assert_int_eq(stream_configure(s), 0);
54
55
56
57
58
59
60
61
62
	ck_assert_int_eq(cfg_stream_set_stream_name(str_cfg, streams, "test", NULL), 0);
	ck_assert_int_eq(cfg_stream_set_stream_url(str_cfg, streams, "test", NULL), 0);
	ck_assert_int_eq(cfg_stream_set_stream_genre(str_cfg, streams, "test", NULL), 0);
	ck_assert_int_eq(cfg_stream_set_stream_description(str_cfg, streams, "test", NULL), 0);
	ck_assert_int_eq(cfg_stream_set_stream_quality(str_cfg, streams, "test", NULL), 0);
	ck_assert_int_eq(cfg_stream_set_stream_bitrate(str_cfg, streams, "test", NULL), 0);
	ck_assert_int_eq(cfg_stream_set_stream_samplerate(str_cfg, streams, "test", NULL), 0);
	ck_assert_int_eq(cfg_stream_set_stream_channels(str_cfg, streams, "test", NULL), 0);
	ck_assert_int_eq(cfg_stream_set_public(str_cfg, streams, "true", NULL), 0);
63
64
65
	ck_assert_int_eq(stream_configure(s), 0);

	ck_assert_int_eq(stream_get_connected(s), 0);
66
67
68
69
70
71

	m = mdata_create();

	ck_assert_int_eq(mdata_parse_file(m, SRCDIR "/test01-artist+album+title.ogg"), 0);

	cfg_set_metadata_no_updates("yes", NULL);
72
	ck_assert_int_eq(stream_set_metadata(s, NULL, NULL), 0);
73
	cfg_set_metadata_no_updates("no", NULL);
74
	ck_assert_int_ne(stream_set_metadata(s, NULL, NULL), 0);
75

76
77
78
79
80
	/*
	 * Not running stream_set_metadata checked as libshout behaves
	 * different on different systems, making these unreliable ...
	 */
	m_str = NULL;
81
	stream_set_metadata(s, m, &m_str);
82
	xfree(m_str);
83
84
	m_str = NULL;
	ck_assert_int_eq(mdata_parse_file(m, SRCDIR "/test15-title.ogg"), 0);
85
	stream_set_metadata(s, m, &m_str);
86
87
	xfree(m_str);
	m_str = NULL;
88
	ck_assert_int_eq(mdata_parse_file(m, SRCDIR "/test16-nometa.ogg"), 0);
89
	stream_set_metadata(s, m, &m_str);
90
91
	xfree(m_str);
	m_str = NULL;
92
93
	cfg_set_metadata_format_str("test", NULL);
	ck_assert_int_eq(mdata_parse_file(m, SRCDIR "/test01-artist+album+title.ogg"), 0);
94
	stream_set_metadata(s, m, &m_str);
95
96
	xfree(m_str);
	m_str = NULL;
97
98

	mdata_destroy(&m);
99
100

	stream_destroy(&s);
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
}
END_TEST

Suite *
stream_suite(void)
{
	Suite	*s;
	TCase	*tc_stream;

	s = suite_create("Stream");

	tc_stream = tcase_create("Stream");
	tcase_add_checked_fixture(tc_stream, setup_checked, teardown_checked);
	tcase_add_test(tc_stream, test_stream);
	suite_add_tcase(s, tc_stream);

	return (s);
}

void
setup_checked(void)
{
123
	if (0 < cfg_init() ||
Moritz Grimm's avatar
Moritz Grimm committed
124
125
	    0 < cfg_set_program_name("check_stream", NULL) ||
	    0 < log_init(cfg_get_program_name()) ||
126
	    0 < stream_init())
127
128
129
130
131
132
133
		ck_abort_msg("setup_checked failed");
}

void
teardown_checked(void)
{
	stream_exit();
134
	cfg_exit();
135
136
137
138
139
}

int
main(void)
{
140
141
142
	int	 num_failed;
	Suite	*s;
	SRunner	*sr;
143
144
145
146
147
148
149
150
151
152
153
154

	s = stream_suite();
	sr = srunner_create(s);

	srunner_run_all(sr, CK_NORMAL);
	num_failed = srunner_ntests_failed(sr);
	srunner_free(sr);

	if (num_failed)
		return (1);
	return (0);
}