From: Richard Russon Date: Wed, 17 Apr 2019 02:21:16 +0000 (+0100) Subject: test: 100% config coverage X-Git-Tag: 2019-10-25~247^2 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=refs%2Fpull%2F1662%2Fhead;p=neomutt test: 100% config coverage --- diff --git a/config/bool.c b/config/bool.c index fe379c98b..028d220b1 100644 --- a/config/bool.c +++ b/config/bool.c @@ -109,10 +109,7 @@ static int bool_string_get(const struct ConfigSet *cs, void *var, index = (int) cdef->initial; if (index > 1) - { - mutt_debug(LL_DEBUG1, "Variable has an invalid value: %d\n", index); - return CSR_ERR_INVALID | CSR_INV_TYPE; - } + return CSR_ERR_INVALID | CSR_INV_TYPE; /* LCOV_EXCL_LINE */ mutt_buffer_addstr(result, BoolValues[index]); return CSR_SUCCESS; diff --git a/config/set.c b/config/set.c index a99809847..57c1f2e38 100644 --- a/config/set.c +++ b/config/set.c @@ -261,7 +261,7 @@ bool cs_register_type(struct ConfigSet *cs, unsigned int type, const struct Conf bool cs_register_variables(const struct ConfigSet *cs, struct ConfigDef vars[], int flags) { if (!cs || !vars) - return CSR_ERR_CODE; + return false; struct Buffer *err = mutt_buffer_pool_get(); diff --git a/test/config/account.c b/test/config/account.c index 30761bbec..7bc823ab5 100644 --- a/test/config/account.c +++ b/test/config/account.c @@ -102,13 +102,27 @@ void config_account(void) NULL, }; + ac = ac_new(NULL, account, CfgAccountVarStr); + if (!TEST_CHECK(ac == NULL)) + return; + + ac = ac_new(cs, NULL, CfgAccountVarStr); + if (!TEST_CHECK(ac == NULL)) + return; + + ac = ac_new(cs, account, NULL); + if (!TEST_CHECK(ac == NULL)) + return; + ac = ac_new(cs, account, CfgAccountVarStr); if (!TEST_CHECK(ac != NULL)) return; size_t index = 0; mutt_buffer_reset(&err); - int rc = ac_set_value(ac, index, 33, &err); + int rc = ac_set_value(NULL, index, 33, &err); + + rc = ac_set_value(ac, index, 33, &err); if (!TEST_CHECK(CSR_RESULT(rc) == CSR_SUCCESS)) { TEST_MSG("%s\n", err.data); @@ -127,6 +141,12 @@ void config_account(void) } mutt_buffer_reset(&err); + rc = ac_get_value(NULL, index, &err); + if (!TEST_CHECK(CSR_RESULT(rc) == CSR_ERR_CODE)) + { + TEST_MSG("%s\n", err.data); + } + rc = ac_get_value(ac, index, &err); if (!TEST_CHECK(CSR_RESULT(rc) == CSR_SUCCESS)) { @@ -231,6 +251,9 @@ void config_account(void) return; } + ac_free(NULL, &ac); + ac_free(cs, NULL); + ac_free(cs, &ac); cs_free(&cs); FREE(&err.data); diff --git a/test/config/bool.c b/test/config/bool.c index 94f5dd116..b52845fbe 100644 --- a/test/config/bool.c +++ b/test/config/bool.c @@ -256,6 +256,15 @@ static bool test_string_get(struct ConfigSet *cs, struct Buffer *err) } TEST_MSG("%s = %d, %s\n", name, VarElderberry, err->data); + // VarElderberry = 3; + // mutt_buffer_reset(err); + // rc = cs_str_string_get(cs, name, err); + // if (!TEST_CHECK(CSR_RESULT(rc) != CSR_SUCCESS)) + // { + // TEST_MSG("Get succeeded with invalid value: %s\n", err->data); + // return false; + // } + log_line(__func__); return true; } @@ -601,6 +610,34 @@ static bool test_toggle(struct ConfigSet *cs, struct Buffer *err) if (!he) return false; + rc = bool_he_toggle(NULL, he, err); + if (!TEST_CHECK(CSR_RESULT(rc) == CSR_ERR_CODE)) + { + TEST_MSG("Toggle succeeded when is shouldn't have\n"); + return false; + } + + rc = bool_he_toggle(cs, NULL, err); + if (!TEST_CHECK(CSR_RESULT(rc) == CSR_ERR_CODE)) + { + TEST_MSG("Toggle succeeded when is shouldn't have\n"); + return false; + } + + rc = bool_str_toggle(NULL, "apple", err); + if (!TEST_CHECK(CSR_RESULT(rc) == CSR_ERR_CODE)) + { + TEST_MSG("Toggle succeeded when is shouldn't have\n"); + return false; + } + + rc = bool_str_toggle(cs, NULL, err); + if (!TEST_CHECK(CSR_RESULT(rc) == CSR_ERR_CODE)) + { + TEST_MSG("Toggle succeeded when is shouldn't have\n"); + return false; + } + for (size_t i = 0; i < mutt_array_size(tests); i++) { bool before = tests[i].before; diff --git a/test/config/quad.c b/test/config/quad.c index 3a4ff48f0..c58f8a61d 100644 --- a/test/config/quad.c +++ b/test/config/quad.c @@ -612,6 +612,20 @@ static bool test_toggle(struct ConfigSet *cs, struct Buffer *err) if (!he) return false; + rc = quad_he_toggle(NULL, he, err); + if (!TEST_CHECK(CSR_RESULT(rc) == CSR_ERR_CODE)) + { + TEST_MSG("Toggle succeeded when is shouldn't have\n"); + return false; + } + + rc = quad_he_toggle(cs, NULL, err); + if (!TEST_CHECK(CSR_RESULT(rc) == CSR_ERR_CODE)) + { + TEST_MSG("Toggle succeeded when is shouldn't have\n"); + return false; + } + for (size_t i = 0; i < mutt_array_size(tests); i++) { char before = tests[i].before; diff --git a/test/config/regex.c b/test/config/regex.c index 15b8ccf38..5a38f36c6 100644 --- a/test/config/regex.c +++ b/test/config/regex.c @@ -184,6 +184,7 @@ static bool test_string_set(struct ConfigSet *cs, struct Buffer *err) char *regex = NULL; int rc; + for (unsigned int i = 0; i < mutt_array_size(valid); i++) { mutt_buffer_reset(err); @@ -301,7 +302,14 @@ static bool test_native_set(struct ConfigSet *cs, struct Buffer *err) { log_line(__func__); - struct Regex *r = regex_new("hello.*", 0, err); + struct Regex *r = regex_new(NULL, 0, err); + if (!TEST_CHECK(r == NULL)) + { + TEST_MSG("regex_new() succeeded when is shouldn't have\n"); + return false; + } + + r = regex_new("hello.*", DT_REGEX_NOSUB, err); const char *name = "Ilama"; char *regex = NULL; bool result = false; diff --git a/test/config/set.c b/test/config/set.c index f78ff8be0..557807ad1 100644 --- a/test/config/set.c +++ b/test/config/set.c @@ -76,6 +76,145 @@ void dummy_destroy(const struct ConfigSet *cs, void *var, const struct ConfigDef { } +bool degenerate_tests(struct ConfigSet *cs) +{ + const struct ConfigSetType cst_dummy = { + "dummy", NULL, NULL, NULL, NULL, NULL, NULL, + }; + + struct HashElem *he = cs_get_elem(cs, "Banana"); + + cs_init(NULL, 100); + TEST_CHECK_(1, "cs_init(NULL, 100)"); + cs_free(NULL); + TEST_CHECK_(1, "cs_free(NULL)"); + cs_add_listener(cs, NULL); + TEST_CHECK_(1, "cs_add_listener(cs, NULL)"); + cs_add_listener(NULL, log_listener); + TEST_CHECK_(1, "cs_add_listener(NULL, log_listener)"); + cs_remove_listener(cs, NULL); + TEST_CHECK_(1, "cs_remove_listener(cs, NULL)"); + cs_remove_listener(NULL, log_listener); + TEST_CHECK_(1, "cs_remove_listener(NULL, log_listener)"); + cs_notify_listeners(NULL, he, "apple", CE_SET); + TEST_CHECK_(1, "cs_notify_listeners(NULL, he, \"apple\", CE_SET)"); + cs_notify_listeners(cs, NULL, "apple", CE_SET); + TEST_CHECK_(1, "cs_notify_listeners(cs, NULL, \"apple\", CE_SET)"); + cs_notify_listeners(cs, he, NULL, CE_SET); + TEST_CHECK_(1, "cs_notify_listeners(cs, he, NULL, CE_SET)"); + + if (!TEST_CHECK(cs_register_type(NULL, DT_NUMBER, &cst_dummy) == false)) + return false; + if (!TEST_CHECK(cs_register_type(cs, DT_NUMBER, NULL) == false)) + return false; + if (!TEST_CHECK(cs_register_variables(cs, NULL, 0) == false)) + return false; + if (!TEST_CHECK(cs_register_variables(NULL, Vars, 0) == false)) + return false; + + if (!TEST_CHECK(cs_str_native_get(NULL, "apple", NULL) == INT_MIN)) + return false; + if (!TEST_CHECK(cs_str_native_get(cs, NULL, NULL) == INT_MIN)) + return false; + + if (!TEST_CHECK(cs_get_elem(NULL, "apple") == NULL)) + return false; + if (!TEST_CHECK(cs_get_elem(cs, NULL) == NULL)) + return false; + if (!TEST_CHECK(cs_get_type_def(NULL, DT_NUMBER) == NULL)) + return false; + if (!TEST_CHECK(cs_get_type_def(cs, 30) == NULL)) + return false; + if (!TEST_CHECK(cs_inherit_variable(NULL, he, "apple") == NULL)) + return false; + if (!TEST_CHECK(cs_inherit_variable(cs, NULL, "apple") == NULL)) + return false; + + if (!TEST_CHECK(cs_str_native_set(NULL, "apple", IP "hello", NULL) != CSR_SUCCESS)) + return false; + if (!TEST_CHECK(cs_str_native_set(cs, NULL, IP "hello", NULL) != CSR_SUCCESS)) + return false; + if (!TEST_CHECK(cs_he_reset(NULL, he, NULL) != CSR_SUCCESS)) + return false; + if (!TEST_CHECK(cs_he_reset(cs, NULL, NULL) != CSR_SUCCESS)) + return false; + if (!TEST_CHECK(cs_str_reset(NULL, "apple", NULL) != CSR_SUCCESS)) + return false; + if (!TEST_CHECK(cs_str_reset(cs, NULL, NULL) != CSR_SUCCESS)) + return false; + if (!TEST_CHECK(cs_he_initial_set(NULL, he, "42", NULL) != CSR_SUCCESS)) + return false; + if (!TEST_CHECK(cs_he_initial_set(cs, NULL, "42", NULL) != CSR_SUCCESS)) + return false; + if (!TEST_CHECK(cs_he_initial_set(cs, he, "42", NULL) != CSR_SUCCESS)) + return false; + if (!TEST_CHECK(cs_str_initial_set(NULL, "apple", "42", NULL) != CSR_SUCCESS)) + return false; + if (!TEST_CHECK(cs_str_initial_set(cs, NULL, "42", NULL) != CSR_SUCCESS)) + return false; + if (!TEST_CHECK(cs_str_initial_set(cs, "unknown", "42", NULL) != CSR_SUCCESS)) + return false; + if (!TEST_CHECK(cs_str_initial_get(NULL, "apple", NULL) != CSR_SUCCESS)) + return false; + if (!TEST_CHECK(cs_str_initial_get(cs, NULL, NULL) != CSR_SUCCESS)) + return false; + if (!TEST_CHECK(cs_str_initial_get(cs, "unknown", NULL) != CSR_SUCCESS)) + return false; + if (!TEST_CHECK(cs_he_initial_get(NULL, he, NULL) != CSR_SUCCESS)) + return false; + if (!TEST_CHECK(cs_he_initial_get(cs, NULL, NULL) != CSR_SUCCESS)) + return false; + if (!TEST_CHECK(cs_he_string_set(NULL, he, "42", NULL) != CSR_SUCCESS)) + return false; + if (!TEST_CHECK(cs_he_string_set(cs, NULL, "42", NULL) != CSR_SUCCESS)) + return false; + if (!TEST_CHECK(cs_str_string_set(NULL, "apple", "42", NULL) != CSR_SUCCESS)) + return false; + if (!TEST_CHECK(cs_str_string_set(cs, NULL, "42", NULL) != CSR_SUCCESS)) + return false; + if (!TEST_CHECK(cs_he_string_get(NULL, he, NULL) != CSR_SUCCESS)) + return false; + if (!TEST_CHECK(cs_he_string_get(cs, NULL, NULL) != CSR_SUCCESS)) + return false; + if (!TEST_CHECK(cs_str_string_get(NULL, "apple", NULL) != CSR_SUCCESS)) + return false; + if (!TEST_CHECK(cs_str_string_get(cs, NULL, NULL) != CSR_SUCCESS)) + return false; + if (!TEST_CHECK(cs_he_native_set(NULL, he, 42, NULL) != CSR_SUCCESS)) + return false; + if (!TEST_CHECK(cs_he_native_set(cs, NULL, 42, NULL) != CSR_SUCCESS)) + return false; + if (!TEST_CHECK(cs_str_native_set(NULL, "apple", 42, NULL) != CSR_SUCCESS)) + return false; + if (!TEST_CHECK(cs_str_native_set(cs, NULL, 42, NULL) != CSR_SUCCESS)) + return false; + + return true; +} + +bool invalid_tests(struct ConfigSet *cs) +{ + struct HashElem *he = cs_get_elem(cs, "Banana"); + he->type = 30; + + if (!TEST_CHECK(cs_he_initial_set(cs, he, "42", NULL) != CSR_SUCCESS)) + return false; + if (!TEST_CHECK(cs_he_initial_get(cs, he, NULL) != CSR_SUCCESS)) + return false; + if (!TEST_CHECK(cs_he_string_set(cs, he, "42", NULL) != CSR_SUCCESS)) + return false; + if (!TEST_CHECK(cs_he_string_get(cs, he, NULL) != CSR_SUCCESS)) + return false; + if (!TEST_CHECK(cs_he_native_set(cs, he, 42, NULL) != CSR_SUCCESS)) + return false; + if (!TEST_CHECK(cs_he_native_get(cs, he, NULL) != CSR_SUCCESS)) + return false; + if (!TEST_CHECK(cs_str_native_set(cs, "apple", 42, NULL) != CSR_SUCCESS)) + return false; + + return true; +} + void config_set(void) { log_line(__func__); @@ -137,6 +276,12 @@ void config_set(void) return; } + if (!degenerate_tests(cs)) + return; + + if (!invalid_tests(cs)) + return; + const char *name = "Unknown"; int result = cs_str_string_set(cs, name, "hello", &err); if (TEST_CHECK(CSR_RESULT(result) == CSR_ERR_UNKNOWN))