diff options
Diffstat (limited to '')
| -rw-r--r-- | tests/msgs.c (renamed from tests/catalog.c) | 132 |
1 files changed, 49 insertions, 83 deletions
diff --git a/tests/catalog.c b/tests/msgs.c index 4464fbe..37c8890 100644 --- a/tests/catalog.c +++ b/tests/msgs.c @@ -1,12 +1,9 @@ -#include "../src/catalog.c" +#include "../src/msgs.c" #include "../src/testing.h" -#include "../src/util.h" #include "slurp.h" -static const char *const -FNAME = __FILE__ ".txt"; enum TEST_MSGCATALOG_ID { MSG_X_FIRST, @@ -16,10 +13,8 @@ enum TEST_MSGCATALOG_ID { MSG_STANDALONE, }; -#define TEST_MSGS_LEN 6U - static const char *const -TEST_MSGS[TEST_MSGS_LEN] = { +TEST_MSGS[] = { [MSG_X_FIRST]="First line\n", [MSG_X_1]="a second\n", [MSG_X_2]="a third\n", @@ -28,11 +23,19 @@ TEST_MSGS[TEST_MSGS_LEN] = { NULL }; +static size_t +TEST_MSGS_LEN = nelem(TEST_MSGS); + +static const char +FNAME[] = __FILE__ ".txt"; + + + static int -test_i18n_init_msgs(void) { +test_msgs_init(void) { int rc = -1; - test_start("i18n_init_msgs()"); + test_start("msgs_init()"); { testing("simple call without touching the environment"); @@ -43,8 +46,8 @@ test_i18n_init_msgs(void) { goto out; } - if (i18n_init_msgs(TEST_MSGS)) { - logerr("i18n_init_msgs()"); + if (msgs_init(TEST_MSGS)) { + logerr("msgs_init()"); goto out; } assert(msgs_length == TEST_MSGS_LEN - 1U); @@ -54,18 +57,18 @@ test_i18n_init_msgs(void) { rc = 0; out: - if (i18n_destroy()) { - logerr("i18n_destroy()"); + if (msgs_end()) { + logerr("msgs_end()"); rc = -1; } return rc; } static int -test_s_print_msgs(void) { +test_msgs_print_ids(void) { int rc = -1; - test_start("s_print_msgs()"); + test_start("msgs_print_ids()"); FILE *file = NULL; char *str = NULL; @@ -73,13 +76,13 @@ test_s_print_msgs(void) { testing("message in range"); file = fopen(FNAME, "w"); - if (!file) { + if (file == NULL) { perror("fopen(FNAME, \"w\")"); goto out; } - if (s_print_msgs(TEST_MSGS, file, MSG_X_FIRST, MSG_X_LAST)) { - logerr("s_print_msgs()"); + if (msgs_print_ids(TEST_MSGS, file, MSG_X_FIRST, MSG_X_LAST)) { + logerr("msgs_print_ids()"); goto out; } @@ -95,7 +98,7 @@ test_s_print_msgs(void) { goto out; } - const char *const expected = + const char expected[] = "First line\n" "a second\n" "a third\n" @@ -104,7 +107,9 @@ test_s_print_msgs(void) { assert(strcmp(expected, str) == 0); - freeit((void *)&str); + free(str); + str = NULL; + test_ok(); } { @@ -116,8 +121,8 @@ test_s_print_msgs(void) { goto out; } - if (s_print_msgs(TEST_MSGS, file, MSG_X_FIRST, MSG_X_FIRST)) { - logerr("s_print_msgs()"); + if (msgs_print_ids(TEST_MSGS, file, MSG_X_FIRST, MSG_X_FIRST)) { + logerr("msgs_print_ids()"); goto out; } @@ -133,50 +138,13 @@ test_s_print_msgs(void) { goto out; } - const char *const expected = + const char expected[] = "First line\n"; assert(strcmp(expected, str) == 0); - freeit((void *)&str); - - test_ok(); - } - - rc = 0; -out: - if (str != NULL) { - freeit((void *)&str); - } - if (file != NULL) { - if (fclose(file)) { - logerr("fclose(): %s", strerror(errno)); - rc = -1; - } - } - return rc; -} - -static int -test_s(void) { - int rc = -1; - - test_start("_()"); - FILE *file = NULL; - char *str = NULL; - - { - testing("empty string"); - - file = fopen(FNAME, "w"); - if (!file) { - perror("fopen(FNAME, \"w\")"); - goto out; - } - - // FIXME: implement correct test - - + free(str); + str = NULL; test_ok(); } @@ -184,7 +152,8 @@ test_s(void) { rc = 0; out: if (str != NULL) { - freeit((void *)&str); + free(str); + str = NULL; } if (file != NULL) { if (fclose(file)) { @@ -204,8 +173,8 @@ test_i18n_destroy(void) { { testing("simple call without init first"); - if (i18n_destroy()) { - logerr("i18n_destroy()"); + if (msgs_end()) { + logerr("msgs_end()"); goto out; } @@ -218,10 +187,10 @@ out: } static int -test_s_print_msg(void) { +test_msgs_print_id(void) { int rc = -1; - test_start("s_print_msg()"); + test_start("msgs_print_id()"); FILE *file = NULL; char *str = NULL; @@ -234,8 +203,8 @@ test_s_print_msg(void) { goto out; } - if (s_print_msg(TEST_MSGS, file, MSG_STANDALONE)) { - logerr("s_print_msg()"); + if (msgs_print_id(TEST_MSGS, file, MSG_STANDALONE)) { + logerr("msgs_print_id()"); goto out; } @@ -251,12 +220,13 @@ test_s_print_msg(void) { goto out; } - const char *const expected = + const char expected[] = "single line message\n"; assert(strcmp(expected, str) == 0); - freeit((void *)&str); + free(str); + str = NULL; test_ok(); } @@ -264,7 +234,8 @@ test_s_print_msg(void) { rc = 0; out: if (str != NULL) { - freeit((void *)&str); + free(str); + str = NULL; } if (file != NULL) { if (fclose(file)) { @@ -279,8 +250,8 @@ int main(void) { int rc = EXIT_FAILURE; - if (test_i18n_init_msgs()) { - logerr("test_i18n_init_msgs()"); + if (test_msgs_init()) { + logerr("test_msgs_init()"); goto out; } @@ -289,18 +260,13 @@ main(void) { goto out; } - if (test_s()) { - logerr("test_s()"); - goto out; - } - - if (test_s_print_msgs()) { - logerr("test_s_print_msgs()"); + if (test_msgs_print_ids()) { + logerr("test_msgs_print_ids()"); goto out; } - if (test_s_print_msg()) { - logerr("test_s_print_msg()"); + if (test_msgs_print_id()) { + logerr("test_msgs_print_id()"); goto out; } |
