]> granicus.if.org Git - neomutt/commitdiff
test: fix config tests 1726/head
authorRichard Russon <rich@flatcap.org>
Tue, 28 May 2019 14:20:44 +0000 (15:20 +0100)
committerRichard Russon <rich@flatcap.org>
Mon, 3 Jun 2019 10:54:19 +0000 (11:54 +0100)
20 files changed:
config/set.c
mutt/notify.c
test/config/account.c
test/config/address.c
test/config/bool.c
test/config/command.c
test/config/common.c
test/config/common.h
test/config/initial.c
test/config/long.c
test/config/magic.c
test/config/mbtable.c
test/config/number.c
test/config/path.c
test/config/quad.c
test/config/regex.c
test/config/set.c
test/config/sort.c
test/config/string.c
test/config/synonym.c

index 461e6954499a991adb9f52669f7a375cb6cdbeeb..fd65700f1af6b98089ca2f3580464fde1f695381 100644 (file)
@@ -177,6 +177,7 @@ void cs_free(struct ConfigSet **cs)
     return;
 
   mutt_hash_free(&(*cs)->hash);
+  notify_free(&(*cs)->notify);
   FREE(cs);
 }
 
index 9bed9cc1f8a45d10b0fc3f5e42e5aa34548307b2..777a5b837467f2d6aae43c018ac75fc975b5a3ac 100644 (file)
@@ -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, &notify->observers, entries)
   {
-    if (np->observer->callback == callback)
+    if (!callback || (np->observer->callback == callback))
     {
       STAILQ_REMOVE(&notify->observers, np, ObserverNode, entries);
       FREE(&np->observer);
index 278aa56abfd86f8ac6d53a1fb8d7130db675cca7..7f5586d9cb4f98126ce88aff21f31facc4c64982 100644 (file)
@@ -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[] = {
index 460e871f6774a3effee2f30c7997e5fc3dafcf93..1d1af2aa6c649c95a9097995eb779e1f1584755a 100644 (file)
@@ -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);
 
index 8b76ef1c4e8e9287d93ecdd92df5c6499eaad770..adc641645008afc2811a43b47857e7b9df06345e 100644 (file)
@@ -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);
 
index 9f165e7b3b5df8b7184810ab8d946234eec20d43..51665335467a02d4ada0a72703631345f2dfa72d 100644 (file)
@@ -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);
 
index 5bd26f6deb7eb62bd519fd0dcd74efd63b34dfce..2be588bb43c7d7601d47fdc2efc78c2b5171b1ee 100644 (file)
@@ -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;
index 0321ff2e5cc3c8a6afbcacea74b575ea02d944a5..0ce9b9b7151f3a326c2b01b458b0549ca601720c 100644 (file)
@@ -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);
 
index 2a220ec18cc6f41684cee305cb6a9f650080407d..be82e403d83c52d41673ed1b43ba9e2bea6aad42 100644 (file)
@@ -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);
 
index 1ae7f1e0db4adf99de280929d1e523afabf65787..eefa5a5bf6b27d3ecc0af22ea89bd04565fc581e 100644 (file)
@@ -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);
 
index 77a18e4300ef3bf8cf8fa811679df2d84a62f338..aa9d5298e9f083912c232a5c6ddfc0f545bf5d48 100644 (file)
@@ -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);
 
index 98954cef9f44104c0d0d82ee311ff2e88369cebc..9825a74f5da5d628ac305d2516712c6dce7bc87c 100644 (file)
@@ -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);
 
index 50ea8ce611597b8fac1ea45f83fa0442751a7acc..fa3603b16a37f4ce7ea2af79edad42b77d23d065 100644 (file)
@@ -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);
 
index 1cc586279f6fe9710d4138af4ecbe9d9bb701998..ba767874166f3683fa3c9034a8d5cb1ae96d69bc 100644 (file)
@@ -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);
 
index 9ea9b4618051d0720bab5aa8b74afbeb9eb2a749..040a4ad9e256dca2c2d0696fb3cbc1099f368bff 100644 (file)
@@ -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);
 
index f456af8ff5cff9d27b025f19637f7a50e1dda2dd..f8ad60cedd31bacfe8ec0cc737591ec18e27a0b5 100644 (file)
@@ -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);
 
index be5611b9f82502326f7e7aa8438b634dcee951b3..4892f6ca2f21239d8e2027a4c73c2ac43ab091e3 100644 (file)
@@ -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,
   };
index d8443901622430980609a51d667e8b61d15dbbbe..2a2fef43ad50f19ee1353c9af003277a66fd7e10 100644 (file)
@@ -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);
 
index 7b529c596cd047e905d51738a3b580249734bcb4..bfefd3cbf71f24d84857912f1d0b4091ab5e005e 100644 (file)
@@ -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);
 
index 6b56017c624196fbf4bc32a4bc1aa0fe96d2ef09..ef48127eb0de3359b52e0d3246f13aa69671a562 100644 (file)
@@ -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);