From 876660fc17a8f3607b7f700b1b73c50335a01966 Mon Sep 17 00:00:00 2001 From: Moritz Grimm Date: Sat, 16 May 2015 00:39:36 +0200 Subject: [PATCH] Test and fix cfg_*_get() --- src/cfg_decoder.c | 2 ++ src/cfg_encoder.c | 2 ++ tests/check_cfg.c | 36 +++++++++++++++++++++++++++++++++++- 3 files changed, 39 insertions(+), 1 deletion(-) diff --git a/src/cfg_decoder.c b/src/cfg_decoder.c index b7ab57e..5f4c003 100644 --- a/src/cfg_decoder.c +++ b/src/cfg_decoder.c @@ -87,6 +87,8 @@ cfg_decoder_get(const char *name) d->name = xstrdup(name); TAILQ_INIT(&d->exts); + TAILQ_INSERT_TAIL(&cfg_decoders, d, entry); + return (d); } diff --git a/src/cfg_encoder.c b/src/cfg_encoder.c index b0e5923..c322bb1 100644 --- a/src/cfg_encoder.c +++ b/src/cfg_encoder.c @@ -73,6 +73,8 @@ cfg_encoder_get(const char *name) e = xcalloc(1UL, sizeof(*e)); e->name = xstrdup(name); + TAILQ_INSERT_TAIL(&cfg_encoders, e, entry); + return (e); } diff --git a/tests/check_cfg.c b/tests/check_cfg.c index 8703074..d23d363 100644 --- a/tests/check_cfg.c +++ b/tests/check_cfg.c @@ -449,11 +449,37 @@ START_TEST(test_metadata_no_updates) } END_TEST +START_TEST(test_decoder_get) +{ + cfg_decoder_t dec, dec2; + + ck_assert_ptr_eq(cfg_decoder_get(NULL), NULL); + ck_assert_ptr_eq(cfg_decoder_get(""), NULL); + + dec = cfg_decoder_get("TeSt"); + dec2 = cfg_decoder_get("test"); + ck_assert_ptr_eq(dec, dec2); +} +END_TEST + +START_TEST(test_encoder_get) +{ + cfg_encoder_t enc, enc2; + + ck_assert_ptr_eq(cfg_encoder_get(NULL), NULL); + ck_assert_ptr_eq(cfg_encoder_get(""), NULL); + + enc = cfg_encoder_get("TeSt"); + enc2 = cfg_encoder_get("test"); + ck_assert_ptr_eq(enc, enc2); +} +END_TEST + Suite * cfg_suite(void) { Suite *s; - TCase *tc_core; + TCase *tc_core, *tc_decoder, *tc_encoder; s = suite_create("Config"); @@ -501,6 +527,14 @@ cfg_suite(void) tcase_add_test(tc_core, test_metadata_no_updates); suite_add_tcase(s, tc_core); + tc_decoder = tcase_create("Decoder"); + tcase_add_test(tc_decoder, test_decoder_get); + suite_add_tcase(s, tc_decoder); + + tc_encoder = tcase_create("Encoder"); + tcase_add_test(tc_encoder, test_encoder_get); + suite_add_tcase(s, tc_encoder); + return (s); }