From: Richard Russon Date: Tue, 28 May 2019 14:20:44 +0000 (+0100) Subject: test: fix config tests X-Git-Tag: 2019-10-25~176^2 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=5ba0442ce17e128eb61c9bdf9fa836ccaa0828bf;p=neomutt test: fix config tests --- diff --git a/config/set.c b/config/set.c index 461e69544..fd65700f1 100644 --- a/config/set.c +++ b/config/set.c @@ -177,6 +177,7 @@ void cs_free(struct ConfigSet **cs) return; mutt_hash_free(&(*cs)->hash); + notify_free(&(*cs)->notify); FREE(cs); } diff --git a/mutt/notify.c b/mutt/notify.c index 9bed9cc1f..777a5b837 100644 --- a/mutt/notify.c +++ b/mutt/notify.c @@ -68,9 +68,10 @@ void notify_free(struct Notify **ptr) if (!ptr || !*ptr) return; - // struct Notify *notify = *ptr; + struct Notify *notify = *ptr; // NOTIFY observers - // FREE observers + + notify_observer_remove(notify, NULL); FREE(ptr); } @@ -181,16 +182,18 @@ bool notify_observer_add(struct Notify *notify, enum NotifyType type, * @param notify Notification handler * @param callback Function to call on a matching event, see ::observer_t * @retval true If successful + * + * If callback is NULL, all the observers will be removed. */ bool notify_observer_remove(struct Notify *notify, observer_t callback) { - if (!notify || !callback) + if (!notify) return false; struct ObserverNode *np = NULL; STAILQ_FOREACH(np, ¬ify->observers, entries) { - if (np->observer->callback == callback) + if (!callback || (np->observer->callback == callback)) { STAILQ_REMOVE(¬ify->observers, np, ObserverNode, entries); FREE(&np->observer); diff --git a/test/config/account.c b/test/config/account.c index 278aa56ab..7f5586d9c 100644 --- a/test/config/account.c +++ b/test/config/account.c @@ -60,7 +60,7 @@ void config_account(void) set_list(cs); - cs_add_observer(cs, log_observer); + notify_observer_add(cs->notify, NT_CONFIG, 0, log_observer, 0); const char *account = "damaged"; const char *BrokenVarStr[] = { diff --git a/test/config/address.c b/test/config/address.c index 460e871f6..1d1af2aa6 100644 --- a/test/config/address.c +++ b/test/config/address.c @@ -611,7 +611,7 @@ void config_address(void) return; dont_fail = false; - cs_add_observer(cs, log_observer); + notify_observer_add(cs->notify, NT_CONFIG, 0, log_observer, 0); set_list(cs); diff --git a/test/config/bool.c b/test/config/bool.c index 8b76ef1c4..adc641645 100644 --- a/test/config/bool.c +++ b/test/config/bool.c @@ -765,7 +765,7 @@ void config_bool(void) return; dont_fail = false; - cs_add_observer(cs, log_observer); + notify_observer_add(cs->notify, NT_CONFIG, 0, log_observer, 0); set_list(cs); diff --git a/test/config/command.c b/test/config/command.c index 9f165e7b3..516653354 100644 --- a/test/config/command.c +++ b/test/config/command.c @@ -638,7 +638,7 @@ void config_command(void) return; dont_fail = false; - cs_add_observer(cs, log_observer); + notify_observer_add(cs->notify, NT_CONFIG, 0, log_observer, 0); set_list(cs); diff --git a/test/config/common.c b/test/config/common.c index 5bd26f6de..2be588bb4 100644 --- a/test/config/common.c +++ b/test/config/common.c @@ -81,9 +81,13 @@ void short_line(void) TEST_MSG("%s\n", line + 40); } -bool log_observer(const struct ConfigSet *cs, struct HashElem *he, - const char *name, enum ConfigEvent ev) +int log_observer(struct NotifyCallback *nc) { + if (!nc) + return -1; + + struct EventConfig *ec = (struct EventConfig *) nc->event; + struct Buffer result; mutt_buffer_init(&result); result.dsize = 256; @@ -93,12 +97,12 @@ bool log_observer(const struct ConfigSet *cs, struct HashElem *he, mutt_buffer_reset(&result); - if (ev != CE_INITIAL_SET) - cs_he_string_get(cs, he, &result); + if (nc->event_type != NT_CONFIG_INITIAL_SET) + cs_he_string_get(ec->cs, ec->he, &result); else - cs_he_initial_get(cs, he, &result); + cs_he_initial_get(ec->cs, ec->he, &result); - TEST_MSG("Event: %s has been %s to '%s'\n", name, events[ev - 1], result.data); + TEST_MSG("Event: %s has been %s to '%s'\n", ec->name, events[nc->event_type - 1], result.data); FREE(&result.data); return true; diff --git a/test/config/common.h b/test/config/common.h index 0321ff2e5..0ce9b9b71 100644 --- a/test/config/common.h +++ b/test/config/common.h @@ -30,6 +30,7 @@ struct Buffer; struct Hash; struct HashElem; +struct NotifyCallback; extern const char *line; extern bool dont_fail; @@ -40,7 +41,7 @@ int validator_fail (const struct ConfigSet *cs, const struct ConfigDef *cdef, void log_line(const char *fn); void short_line(void); -bool log_observer(const struct ConfigSet *cs, struct HashElem *he, const char *name, enum ConfigEvent ev); +int log_observer(struct NotifyCallback *nc); void set_list(const struct ConfigSet *cs); void cs_dump_set(const struct ConfigSet *cs); diff --git a/test/config/initial.c b/test/config/initial.c index 2a220ec18..be82e403d 100644 --- a/test/config/initial.c +++ b/test/config/initial.c @@ -103,7 +103,7 @@ void config_initial(void) if (!cs_register_variables(cs, Vars, 0)) return; - cs_add_observer(cs, log_observer); + notify_observer_add(cs->notify, NT_CONFIG, 0, log_observer, 0); set_list(cs); diff --git a/test/config/long.c b/test/config/long.c index 1ae7f1e0d..eefa5a5bf 100644 --- a/test/config/long.c +++ b/test/config/long.c @@ -589,7 +589,7 @@ void config_long(void) return; dont_fail = false; - cs_add_observer(cs, log_observer); + notify_observer_add(cs->notify, NT_CONFIG, 0, log_observer, 0); set_list(cs); diff --git a/test/config/magic.c b/test/config/magic.c index 77a18e430..aa9d5298e 100644 --- a/test/config/magic.c +++ b/test/config/magic.c @@ -576,7 +576,7 @@ void config_magic(void) return; dont_fail = false; - cs_add_observer(cs, log_observer); + notify_observer_add(cs->notify, NT_CONFIG, 0, log_observer, 0); set_list(cs); diff --git a/test/config/mbtable.c b/test/config/mbtable.c index 98954cef9..9825a74f5 100644 --- a/test/config/mbtable.c +++ b/test/config/mbtable.c @@ -627,7 +627,7 @@ void config_mbtable(void) return; dont_fail = false; - cs_add_observer(cs, log_observer); + notify_observer_add(cs->notify, NT_CONFIG, 0, log_observer, 0); set_list(cs); diff --git a/test/config/number.c b/test/config/number.c index 50ea8ce61..fa3603b16 100644 --- a/test/config/number.c +++ b/test/config/number.c @@ -608,7 +608,7 @@ void config_number(void) return; dont_fail = false; - cs_add_observer(cs, log_observer); + notify_observer_add(cs->notify, NT_CONFIG, 0, log_observer, 0); set_list(cs); diff --git a/test/config/path.c b/test/config/path.c index 1cc586279..ba7678741 100644 --- a/test/config/path.c +++ b/test/config/path.c @@ -638,7 +638,7 @@ void config_path(void) return; dont_fail = false; - cs_add_observer(cs, log_observer); + notify_observer_add(cs->notify, NT_CONFIG, 0, log_observer, 0); set_list(cs); diff --git a/test/config/quad.c b/test/config/quad.c index 9ea9b4618..040a4ad9e 100644 --- a/test/config/quad.c +++ b/test/config/quad.c @@ -703,7 +703,7 @@ void config_quad(void) return; dont_fail = false; - cs_add_observer(cs, log_observer); + notify_observer_add(cs->notify, NT_CONFIG, 0, log_observer, 0); set_list(cs); diff --git a/test/config/regex.c b/test/config/regex.c index f456af8ff..f8ad60ced 100644 --- a/test/config/regex.c +++ b/test/config/regex.c @@ -687,7 +687,7 @@ void config_regex(void) return; dont_fail = false; - cs_add_observer(cs, log_observer); + notify_observer_add(cs->notify, NT_CONFIG, 0, log_observer, 0); set_list(cs); diff --git a/test/config/set.c b/test/config/set.c index be5611b9f..4892f6ca2 100644 --- a/test/config/set.c +++ b/test/config/set.c @@ -88,20 +88,12 @@ bool degenerate_tests(struct ConfigSet *cs) TEST_CHECK_(1, "cs_init(NULL, 100)"); cs_free(NULL); TEST_CHECK_(1, "cs_free(NULL)"); - cs_add_observer(cs, NULL); - TEST_CHECK_(1, "cs_add_observer(cs, NULL)"); - cs_add_observer(NULL, log_observer); - TEST_CHECK_(1, "cs_add_observer(NULL, log_observer)"); - cs_remove_observer(cs, NULL); - TEST_CHECK_(1, "cs_remove_observer(cs, NULL)"); - cs_remove_observer(NULL, log_observer); - TEST_CHECK_(1, "cs_remove_observer(NULL, log_observer)"); - cs_notify_observers(NULL, he, "apple", CE_SET); - TEST_CHECK_(1, "cs_notify_observers(NULL, he, \"apple\", CE_SET)"); - cs_notify_observers(cs, NULL, "apple", CE_SET); - TEST_CHECK_(1, "cs_notify_observers(cs, NULL, \"apple\", CE_SET)"); - cs_notify_observers(cs, he, NULL, CE_SET); - TEST_CHECK_(1, "cs_notify_observers(cs, he, NULL, CE_SET)"); + cs_notify_observers(NULL, he, "apple", NT_CONFIG_SET); + TEST_CHECK_(1, "cs_notify_observers(NULL, he, \"apple\", NT_CONFIG_SET)"); + cs_notify_observers(cs, NULL, "apple", NT_CONFIG_SET); + TEST_CHECK_(1, "cs_notify_observers(cs, NULL, \"apple\", NT_CONFIG_SET)"); + cs_notify_observers(cs, he, NULL, NT_CONFIG_SET); + TEST_CHECK_(1, "cs_notify_observers(cs, he, NULL, NT_CONFIG_SET)"); if (!TEST_CHECK(cs_register_type(NULL, DT_NUMBER, &cst_dummy) == false)) return false; @@ -229,11 +221,6 @@ void config_set(void) if (!TEST_CHECK(cs != NULL)) return; - cs_add_observer(cs, log_observer); - cs_add_observer(cs, log_observer); /* dupe */ - cs_remove_observer(cs, log_observer); - cs_remove_observer(cs, log_observer); /* non-existant */ - const struct ConfigSetType cst_dummy = { "dummy", NULL, NULL, NULL, NULL, NULL, NULL, }; diff --git a/test/config/sort.c b/test/config/sort.c index d84439016..2a2fef43a 100644 --- a/test/config/sort.c +++ b/test/config/sort.c @@ -733,7 +733,7 @@ void config_sort(void) return; dont_fail = false; - cs_add_observer(cs, log_observer); + notify_observer_add(cs->notify, NT_CONFIG, 0, log_observer, 0); set_list(cs); diff --git a/test/config/string.c b/test/config/string.c index 7b529c596..bfefd3cbf 100644 --- a/test/config/string.c +++ b/test/config/string.c @@ -638,7 +638,7 @@ void config_string(void) return; dont_fail = false; - cs_add_observer(cs, log_observer); + notify_observer_add(cs->notify, NT_CONFIG, 0, log_observer, 0); set_list(cs); diff --git a/test/config/synonym.c b/test/config/synonym.c index 6b56017c6..ef48127eb 100644 --- a/test/config/synonym.c +++ b/test/config/synonym.c @@ -203,7 +203,7 @@ void config_synonym(void) return; } - cs_add_observer(cs, log_observer); + notify_observer_add(cs->notify, NT_CONFIG, 0, log_observer, 0); set_list(cs);