2015-06-15 02:04:57 -04:00
|
|
|
#include <check.h>
|
|
|
|
|
2017-09-25 14:49:59 -04:00
|
|
|
#include "cfg.h"
|
2018-01-19 05:48:57 -05:00
|
|
|
#include "log.h"
|
2017-09-25 14:49:59 -04:00
|
|
|
#include "mdata.h"
|
2015-06-15 02:04:57 -04:00
|
|
|
#include "stream.h"
|
2017-09-25 16:45:47 -04:00
|
|
|
#include "xalloc.h"
|
2015-06-15 02:04:57 -04:00
|
|
|
|
|
|
|
Suite * stream_suite(void);
|
|
|
|
void setup_checked(void);
|
|
|
|
void teardown_checked(void);
|
|
|
|
|
2021-01-06 22:19:06 -05:00
|
|
|
cfg_intake_list_t intakes;
|
|
|
|
|
2015-06-15 02:04:57 -04:00
|
|
|
START_TEST(test_stream)
|
|
|
|
{
|
2017-11-17 19:54:14 -05:00
|
|
|
stream_t s;
|
|
|
|
mdata_t m;
|
|
|
|
char *m_str;
|
|
|
|
cfg_server_t srv_cfg;
|
|
|
|
cfg_stream_t str_cfg;
|
2021-01-06 22:19:06 -05:00
|
|
|
cfg_intake_t int_cfg;
|
2017-11-17 19:54:14 -05:00
|
|
|
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);
|
2021-01-06 22:19:06 -05:00
|
|
|
int_cfg = stream_get_cfg_intake(s);
|
|
|
|
ck_assert_ptr_ne(int_cfg, NULL);
|
2017-11-17 19:54:14 -05:00
|
|
|
|
|
|
|
ck_assert_int_ne(stream_configure(s), 0);
|
2020-01-24 19:13:24 -05:00
|
|
|
ck_assert_int_eq(cfg_server_set_hostname(srv_cfg, servers, "localhost", NULL), 0);
|
2017-11-17 19:54:14 -05:00
|
|
|
ck_assert_int_ne(stream_configure(s), 0);
|
2020-01-24 19:13:24 -05:00
|
|
|
ck_assert_int_eq(cfg_server_set_password(srv_cfg, servers, "test", NULL), 0);
|
2017-11-17 19:54:14 -05:00
|
|
|
ck_assert_int_ne(stream_configure(s), 0);
|
2020-01-24 19:13:24 -05:00
|
|
|
ck_assert_int_eq(cfg_server_set_tls(srv_cfg, servers, "required", NULL), 0);
|
2017-11-17 19:54:14 -05:00
|
|
|
ck_assert_int_ne(stream_configure(s), 0);
|
2020-01-24 19:13:24 -05:00
|
|
|
ck_assert_int_eq(cfg_server_set_tls(srv_cfg, servers, "may", NULL), 0);
|
2017-11-17 19:54:14 -05:00
|
|
|
ck_assert_int_ne(stream_configure(s), 0);
|
2020-01-24 19:13:24 -05:00
|
|
|
ck_assert_int_eq(cfg_server_set_tls(srv_cfg, servers, "none", NULL), 0);
|
2017-11-17 19:54:14 -05:00
|
|
|
ck_assert_int_ne(stream_configure(s), 0);
|
2020-01-24 19:13:24 -05:00
|
|
|
ck_assert_int_eq(cfg_stream_set_mountpoint(str_cfg, streams, "/test.ogg", NULL), 0);
|
2017-11-17 19:54:14 -05:00
|
|
|
ck_assert_int_ne(stream_configure(s), 0);
|
2020-01-24 19:13:24 -05:00
|
|
|
ck_assert_int_eq(cfg_stream_set_format(str_cfg, streams, "mp3", NULL), 0);
|
2021-02-09 06:03:06 -05:00
|
|
|
log_error("MP3 stream configuration result: %d (may be due to libshout config)",
|
|
|
|
stream_configure(s));
|
|
|
|
ck_assert_int_eq(cfg_stream_set_format(str_cfg, streams, "webm", NULL), 0);
|
|
|
|
log_error("WebM stream configuration result: %d (may be due to libshout config)",
|
|
|
|
stream_configure(s));
|
|
|
|
ck_assert_int_eq(cfg_stream_set_format(str_cfg, streams, "matroska", NULL), 0);
|
|
|
|
log_error("Matroska stream configuration result: %d (may be due to libshout config)",
|
|
|
|
stream_configure(s));
|
|
|
|
ck_assert_int_eq(cfg_stream_set_format(str_cfg, streams, "ogg", NULL), 0);
|
2021-01-06 22:19:06 -05:00
|
|
|
ck_assert_int_ne(stream_configure(s), 0);
|
|
|
|
cfg_intake_set_filename(int_cfg, intakes, "stream_test", NULL);
|
2017-11-17 19:54:14 -05:00
|
|
|
ck_assert_int_eq(stream_configure(s), 0);
|
2020-01-24 19:13:24 -05:00
|
|
|
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);
|
2017-11-17 19:54:14 -05:00
|
|
|
ck_assert_int_eq(stream_configure(s), 0);
|
|
|
|
|
|
|
|
ck_assert_int_eq(stream_get_connected(s), 0);
|
2017-09-25 14:49:59 -04:00
|
|
|
|
|
|
|
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);
|
2017-11-17 19:54:14 -05:00
|
|
|
ck_assert_int_eq(stream_set_metadata(s, NULL, NULL), 0);
|
2017-09-25 14:49:59 -04:00
|
|
|
cfg_set_metadata_no_updates("no", NULL);
|
2017-11-17 19:54:14 -05:00
|
|
|
ck_assert_int_ne(stream_set_metadata(s, NULL, NULL), 0);
|
2017-09-25 14:49:59 -04:00
|
|
|
|
2017-09-25 16:45:47 -04:00
|
|
|
/*
|
|
|
|
* Not running stream_set_metadata checked as libshout behaves
|
|
|
|
* different on different systems, making these unreliable ...
|
|
|
|
*/
|
|
|
|
m_str = NULL;
|
2017-11-17 19:54:14 -05:00
|
|
|
stream_set_metadata(s, m, &m_str);
|
2017-09-25 16:45:47 -04:00
|
|
|
xfree(m_str);
|
2017-09-25 14:49:59 -04:00
|
|
|
m_str = NULL;
|
|
|
|
ck_assert_int_eq(mdata_parse_file(m, SRCDIR "/test15-title.ogg"), 0);
|
2017-11-17 19:54:14 -05:00
|
|
|
stream_set_metadata(s, m, &m_str);
|
2017-09-25 16:45:47 -04:00
|
|
|
xfree(m_str);
|
|
|
|
m_str = NULL;
|
2017-09-25 14:49:59 -04:00
|
|
|
ck_assert_int_eq(mdata_parse_file(m, SRCDIR "/test16-nometa.ogg"), 0);
|
2017-11-17 19:54:14 -05:00
|
|
|
stream_set_metadata(s, m, &m_str);
|
2017-09-25 16:45:47 -04:00
|
|
|
xfree(m_str);
|
|
|
|
m_str = NULL;
|
2017-09-25 14:49:59 -04:00
|
|
|
cfg_set_metadata_format_str("test", NULL);
|
|
|
|
ck_assert_int_eq(mdata_parse_file(m, SRCDIR "/test01-artist+album+title.ogg"), 0);
|
2017-11-17 19:54:14 -05:00
|
|
|
stream_set_metadata(s, m, &m_str);
|
2017-09-25 16:45:47 -04:00
|
|
|
xfree(m_str);
|
|
|
|
m_str = NULL;
|
2017-09-25 14:49:59 -04:00
|
|
|
|
|
|
|
mdata_destroy(&m);
|
2017-11-23 12:34:57 -05:00
|
|
|
|
|
|
|
stream_destroy(&s);
|
2015-06-15 02:04:57 -04:00
|
|
|
}
|
|
|
|
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)
|
|
|
|
{
|
2017-09-25 14:49:59 -04:00
|
|
|
if (0 < cfg_init() ||
|
2018-01-19 05:48:57 -05:00
|
|
|
0 < cfg_set_program_name("check_stream", NULL) ||
|
|
|
|
0 < log_init(cfg_get_program_name()) ||
|
2017-09-25 14:49:59 -04:00
|
|
|
0 < stream_init())
|
2015-06-15 02:04:57 -04:00
|
|
|
ck_abort_msg("setup_checked failed");
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
teardown_checked(void)
|
|
|
|
{
|
|
|
|
stream_exit();
|
2017-09-25 14:49:59 -04:00
|
|
|
cfg_exit();
|
2015-06-15 02:04:57 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
main(void)
|
|
|
|
{
|
2017-10-04 09:23:21 -04:00
|
|
|
int num_failed;
|
|
|
|
Suite *s;
|
|
|
|
SRunner *sr;
|
2015-06-15 02:04:57 -04:00
|
|
|
|
|
|
|
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);
|
|
|
|
}
|