2018-01-22 19:51:48 -05:00
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/stat.h>
|
|
|
|
|
2018-03-21 05:09:31 -04:00
|
|
|
#include <assert.h>
|
2018-01-22 19:51:48 -05:00
|
|
|
#include <fcntl.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
|
2015-05-21 18:40:21 -04:00
|
|
|
#include <check.h>
|
|
|
|
|
2018-07-17 05:21:12 -04:00
|
|
|
#include "cfg.h"
|
2018-01-22 19:51:48 -05:00
|
|
|
#include "cfgfile_xml.h"
|
2015-05-21 18:40:21 -04:00
|
|
|
#include "log.h"
|
2019-09-06 08:56:25 -04:00
|
|
|
#include "stream.h"
|
2015-05-21 18:40:21 -04:00
|
|
|
|
2018-01-22 19:51:48 -05:00
|
|
|
static void _test_cfgfile_rw(const char *cfgfile);
|
|
|
|
|
2018-07-16 10:25:50 -04:00
|
|
|
Suite * cfgfile_xml_suite(void);
|
2015-05-21 18:40:21 -04:00
|
|
|
void setup_checked(void);
|
|
|
|
void teardown_checked(void);
|
|
|
|
|
2018-01-22 19:51:48 -05:00
|
|
|
static void
|
|
|
|
_test_cfgfile_rw(const char *cfgfile)
|
2015-05-21 18:40:21 -04:00
|
|
|
{
|
2018-01-22 19:51:48 -05:00
|
|
|
const char *testfile = BUILDDIR "/check_cfgfile_xml.xml";
|
|
|
|
FILE *fp;
|
|
|
|
int fd;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
ck_assert_int_eq(cfg_set_program_config_file(cfgfile, NULL), 0);
|
2016-10-14 10:19:39 -04:00
|
|
|
ck_assert_int_eq(cfg_file_reload(), 0);
|
2018-01-22 19:51:48 -05:00
|
|
|
|
|
|
|
fd = open(testfile, O_CREAT|O_EXCL|O_WRONLY, S_IRUSR|S_IWUSR);
|
2018-03-21 05:09:31 -04:00
|
|
|
assert(0 <= fd);
|
2018-01-22 19:51:48 -05:00
|
|
|
fp = fdopen(fd, "w");
|
|
|
|
if (NULL == fp) {
|
|
|
|
unlink(testfile);
|
|
|
|
close(fd);
|
|
|
|
}
|
|
|
|
ck_assert_ptr_ne(fp, NULL);
|
|
|
|
cfgfile_xml_print(fp);
|
|
|
|
ck_assert_int_eq(fclose(fp), 0);
|
|
|
|
|
|
|
|
ck_assert_int_eq(cfg_set_program_config_file(testfile, NULL), 0);
|
|
|
|
ret = cfg_file_reload();
|
|
|
|
ck_assert_int_eq(unlink(testfile), 0);
|
|
|
|
ck_assert_int_eq(ret, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
START_TEST(test_reload)
|
|
|
|
{
|
2019-09-06 08:56:25 -04:00
|
|
|
stream_t test_stream;
|
|
|
|
|
2018-01-22 19:51:48 -05:00
|
|
|
_test_cfgfile_rw(EXAMPLESDIR "/ezstream-file_template.xml");
|
2019-09-06 08:56:25 -04:00
|
|
|
ck_assert_int_eq(cfg_set_program_config_file(EXAMPLESDIR "/ezstream-file_template.xml",
|
|
|
|
NULL), 0);
|
|
|
|
ck_assert_int_eq(cfg_file_reload(), 0);
|
|
|
|
test_stream = stream_create(CFG_DEFAULT);
|
|
|
|
ck_assert_int_eq(stream_configure(test_stream), 0);
|
|
|
|
stream_destroy(&test_stream);
|
2018-01-22 19:51:48 -05:00
|
|
|
_test_cfgfile_rw(EXAMPLESDIR "/ezstream-full.xml");
|
2019-09-06 08:56:25 -04:00
|
|
|
ck_assert_int_eq(cfg_set_program_config_file(EXAMPLESDIR "/ezstream-full.xml",
|
|
|
|
NULL), 0);
|
|
|
|
ck_assert_int_eq(cfg_file_reload(), 0);
|
|
|
|
test_stream = stream_create(CFG_DEFAULT);
|
|
|
|
ck_assert_int_eq(stream_configure(test_stream), 0);
|
|
|
|
stream_destroy(&test_stream);
|
2018-01-22 19:51:48 -05:00
|
|
|
_test_cfgfile_rw(EXAMPLESDIR "/ezstream-metadata.xml");
|
2019-09-06 08:56:25 -04:00
|
|
|
ck_assert_int_eq(cfg_set_program_config_file(EXAMPLESDIR "/ezstream-metadata.xml",
|
|
|
|
NULL), 0);
|
|
|
|
ck_assert_int_eq(cfg_file_reload(), 0);
|
|
|
|
test_stream = stream_create(CFG_DEFAULT);
|
|
|
|
ck_assert_int_eq(stream_configure(test_stream), 0);
|
|
|
|
stream_destroy(&test_stream);
|
2018-01-22 19:51:48 -05:00
|
|
|
_test_cfgfile_rw(EXAMPLESDIR "/ezstream-minimal.xml");
|
2019-09-06 08:56:25 -04:00
|
|
|
ck_assert_int_eq(cfg_set_program_config_file(EXAMPLESDIR "/ezstream-minimal.xml",
|
|
|
|
NULL), 0);
|
|
|
|
ck_assert_int_eq(cfg_file_reload(), 0);
|
|
|
|
test_stream = stream_create(CFG_DEFAULT);
|
|
|
|
ck_assert_int_eq(stream_configure(test_stream), 0);
|
|
|
|
stream_destroy(&test_stream);
|
2018-01-22 19:51:48 -05:00
|
|
|
_test_cfgfile_rw(EXAMPLESDIR "/ezstream-stdin.xml");
|
2019-09-06 08:56:25 -04:00
|
|
|
ck_assert_int_eq(cfg_set_program_config_file(EXAMPLESDIR "/ezstream-stdin.xml",
|
|
|
|
NULL), 0);
|
|
|
|
ck_assert_int_eq(cfg_file_reload(), 0);
|
|
|
|
test_stream = stream_create(CFG_DEFAULT);
|
|
|
|
ck_assert_int_eq(stream_configure(test_stream), 0);
|
|
|
|
stream_destroy(&test_stream);
|
2018-01-22 19:51:48 -05:00
|
|
|
_test_cfgfile_rw(EXAMPLESDIR "/ezstream-video.xml");
|
2019-09-06 08:56:25 -04:00
|
|
|
ck_assert_int_eq(cfg_set_program_config_file(EXAMPLESDIR "/ezstream-video.xml",
|
2015-05-21 18:40:21 -04:00
|
|
|
NULL), 0);
|
2016-10-14 10:19:39 -04:00
|
|
|
ck_assert_int_eq(cfg_file_reload(), 0);
|
2019-09-06 08:56:25 -04:00
|
|
|
test_stream = stream_create(CFG_DEFAULT);
|
|
|
|
ck_assert_int_eq(stream_configure(test_stream), 0);
|
|
|
|
stream_destroy(&test_stream);
|
2016-10-14 10:19:39 -04:00
|
|
|
ck_assert_int_eq(cfg_file_reload(), 0);
|
2015-05-21 18:40:21 -04:00
|
|
|
ck_assert_int_eq(cfg_set_program_config_file(SRCDIR "/config-bad.xml",
|
|
|
|
NULL), 0);
|
2016-10-14 10:19:39 -04:00
|
|
|
ck_assert_int_eq(cfg_file_reload(), -1);
|
2015-05-21 18:40:21 -04:00
|
|
|
ck_assert_int_eq(cfg_set_program_config_file(SRCDIR "/config-bad2.xml",
|
|
|
|
NULL), 0);
|
2016-10-14 10:19:39 -04:00
|
|
|
ck_assert_int_eq(cfg_file_reload(), -1);
|
2015-05-21 18:40:21 -04:00
|
|
|
ck_assert_int_eq(cfg_set_program_config_file(SRCDIR "/config-bad3.xml",
|
|
|
|
NULL), 0);
|
2016-10-14 10:19:39 -04:00
|
|
|
ck_assert_int_eq(cfg_file_reload(), -1);
|
2015-05-21 18:40:21 -04:00
|
|
|
ck_assert_int_eq(cfg_set_program_config_file(SRCDIR "/config-bad4.xml",
|
|
|
|
NULL), 0);
|
2016-10-14 10:19:39 -04:00
|
|
|
ck_assert_int_eq(cfg_file_reload(), -1);
|
2017-11-17 19:54:14 -05:00
|
|
|
ck_assert_int_eq(cfg_set_program_config_file(SRCDIR "/config-bad5.xml",
|
|
|
|
NULL), 0);
|
|
|
|
ck_assert_int_eq(cfg_file_reload(), -1);
|
2017-11-23 12:34:57 -05:00
|
|
|
ck_assert_int_eq(cfg_set_program_config_file(SRCDIR "/config-bad6.xml",
|
|
|
|
NULL), 0);
|
|
|
|
ck_assert_int_eq(cfg_file_reload(), -1);
|
2015-05-21 18:40:21 -04:00
|
|
|
}
|
|
|
|
END_TEST
|
|
|
|
|
|
|
|
Suite *
|
2018-07-16 10:25:50 -04:00
|
|
|
cfgfile_xml_suite(void)
|
2015-05-21 18:40:21 -04:00
|
|
|
{
|
|
|
|
Suite *s;
|
|
|
|
TCase *tc_xmlcfg;
|
|
|
|
|
2015-05-24 05:33:24 -04:00
|
|
|
s = suite_create("Config");
|
2015-05-21 18:40:21 -04:00
|
|
|
|
2015-05-24 05:33:24 -04:00
|
|
|
tc_xmlcfg = tcase_create("XmlConfigFile");
|
2015-05-21 18:40:21 -04:00
|
|
|
tcase_add_checked_fixture(tc_xmlcfg, setup_checked, teardown_checked);
|
|
|
|
tcase_add_test(tc_xmlcfg, test_reload);
|
|
|
|
suite_add_tcase(s, tc_xmlcfg);
|
|
|
|
|
|
|
|
return (s);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
setup_checked(void)
|
|
|
|
{
|
|
|
|
if (0 < cfg_init() ||
|
2018-07-16 10:25:50 -04:00
|
|
|
0 < cfg_set_program_name("check_cfgfile_xml", NULL) ||
|
2019-09-06 08:56:25 -04:00
|
|
|
0 < log_init(cfg_get_program_name()) ||
|
|
|
|
0 < stream_init())
|
2015-05-21 18:40:21 -04:00
|
|
|
ck_abort_msg("setup_checked failed");
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
teardown_checked(void)
|
|
|
|
{
|
2019-09-06 08:56:25 -04:00
|
|
|
stream_exit();
|
2015-05-21 18:40:21 -04:00
|
|
|
log_exit();
|
|
|
|
cfg_exit();
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
main(void)
|
|
|
|
{
|
2017-10-04 09:23:21 -04:00
|
|
|
int num_failed;
|
|
|
|
Suite *s;
|
2018-07-17 04:49:24 -04:00
|
|
|
SRunner *sr;
|
2015-05-21 18:40:21 -04:00
|
|
|
|
2018-07-16 10:25:50 -04:00
|
|
|
s = cfgfile_xml_suite();
|
2015-05-21 18:40:21 -04:00
|
|
|
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);
|
|
|
|
}
|