From 7c83ee02f22bed1166d3ffed208679fd016bb4b6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Helleu?= Date: Sun, 4 Jul 2021 11:38:45 +0200 Subject: tests: add tests on typing plugin functions --- src/plugins/typing/typing-status.c | 37 ++++++++++++++++++++----------------- src/plugins/typing/typing-status.h | 5 +++-- 2 files changed, 23 insertions(+), 19 deletions(-) (limited to 'src') diff --git a/src/plugins/typing/typing-status.c b/src/plugins/typing/typing-status.c index 298b9d496..1d4d540b6 100644 --- a/src/plugins/typing/typing-status.c +++ b/src/plugins/typing/typing-status.c @@ -53,6 +53,9 @@ typing_status_search_state (const char *state) { int i; + if (!state) + return -1; + for (i = 0; i < TYPING_STATUS_NUM_STATES; i++) { if (strcmp (typing_status_state_string[i], state) == 0) @@ -298,47 +301,47 @@ typing_status_nick_add (struct t_gui_buffer *buffer, const char *nick, } /* - * Removes a nick typing status from a buffer. + * Searches a nick typing status for a buffer. * - * Returns: - * 1: OK - * 0: error + * Returns pointer to t_typing_status found, NULL if not found. */ -void -typing_status_nick_remove (struct t_gui_buffer *buffer, const char *nick) +struct t_typing_status * +typing_status_nick_search (struct t_gui_buffer *buffer, const char *nick) { struct t_hashtable *ptr_nicks; - if (!typing_status_nicks) - return; + if (!typing_status_nicks || !buffer || !nick) + return NULL; ptr_nicks = weechat_hashtable_get (typing_status_nicks, buffer); if (!ptr_nicks) - return; + return NULL; - weechat_hashtable_remove (ptr_nicks, nick); + return weechat_hashtable_get (ptr_nicks, nick); } /* - * Searches a nick typing status for a buffer. + * Removes a nick typing status from a buffer. * - * Returns pointer to t_typing_status found, NULL if not found. + * Returns: + * 1: OK + * 0: error */ -struct t_typing_status * -typing_status_nick_search (struct t_gui_buffer *buffer, const char *nick) +void +typing_status_nick_remove (struct t_gui_buffer *buffer, const char *nick) { struct t_hashtable *ptr_nicks; if (!typing_status_nicks) - return NULL; + return; ptr_nicks = weechat_hashtable_get (typing_status_nicks, buffer); if (!ptr_nicks) - return NULL; + return; - return weechat_hashtable_get (ptr_nicks, nick); + weechat_hashtable_remove (ptr_nicks, nick); } /* diff --git a/src/plugins/typing/typing-status.h b/src/plugins/typing/typing-status.h index 8b5cc2417..0a1ed4e46 100644 --- a/src/plugins/typing/typing-status.h +++ b/src/plugins/typing/typing-status.h @@ -40,6 +40,7 @@ struct t_typing_status time_t last_typed; /* when was last char typed */ }; +extern char *typing_status_state_string[]; extern struct t_hashtable *typing_status_self; extern struct t_hashtable *typing_status_nicks; @@ -52,10 +53,10 @@ extern struct t_typing_status *typing_status_nick_add (struct t_gui_buffer *buff const char *nick, int state, int last_typed); -extern void typing_status_nick_remove (struct t_gui_buffer *buffer, - const char *nick); extern struct t_typing_status *typing_status_nick_search (struct t_gui_buffer *buffer, const char *nick); +extern void typing_status_nick_remove (struct t_gui_buffer *buffer, + const char *nick); extern void typing_status_end (); #endif /* WEECHAT_PLUGIN_TYPING_STATUS_H */ -- cgit v1.2.3