1
0
mirror of https://github.com/profanity-im/profanity.git synced 2024-11-03 19:37:16 -05:00

Merge branch 'master' into plugins

This commit is contained in:
James Booth 2016-04-07 01:05:49 +01:00
commit b69bec160d
14 changed files with 273 additions and 132 deletions

View File

@ -1179,6 +1179,8 @@ static struct cmd_t command_defs[] =
"/notify chat text on|off", "/notify chat text on|off",
"/notify room on|off", "/notify room on|off",
"/notify room mention on|off", "/notify room mention on|off",
"/notify room mention case_sensitive|case_insensitive",
"/notify room mention word_whole|word_part",
"/notify room current on|off", "/notify room current on|off",
"/notify room text on|off", "/notify room text on|off",
"/notify room trigger add <text>", "/notify room trigger add <text>",
@ -1197,26 +1199,30 @@ static struct cmd_t command_defs[] =
CMD_DESC( CMD_DESC(
"Settings for various kinds of desktop notifications.") "Settings for various kinds of desktop notifications.")
CMD_ARGS( CMD_ARGS(
{ "chat on|off", "Notifications for regular chat messages." }, { "chat on|off", "Notifications for regular chat messages." },
{ "chat current on|off", "Whether to show regular chat message notifications when the window is focussed." }, { "chat current on|off", "Whether to show regular chat message notifications when the window is focussed." },
{ "chat text on|off", "Show message text in regular message notifications." }, { "chat text on|off", "Show message text in regular message notifications." },
{ "room on|off", "Notifications for all chat room messages, 'mention' only notifies when your nick is mentioned." }, { "room on|off", "Notifications for all chat room messages, 'mention' only notifies when your nick is mentioned." },
{ "room mention on|off", "Notifications for all chat room messages when your nick is mentioned." }, { "room mention on|off", "Notifications for all chat room messages when your nick is mentioned." },
{ "room current on|off", "Whether to show all chat room messages notifications when the window is focussed." }, { "room mention case_sensitive", "Set room mention notifications as case sensitive." },
{ "room text on|off", "Show message text in chat room message notifications." }, { "room mention case_insensitive", "Set room mention notifications as case insensitive." },
{ "room trigger add <text>", "Notify when specified text included in all chat room messages." }, { "room mention word_whole", "Set room mention notifications only on whole word match, i.e. when nickname is not part of a larger word." },
{ "room trigger remove <text>", "Remove chat room notification trigger." }, { "room mention word_part", "Set room mention notifications on partial word match, i.e. nickname may be part of a larger word." },
{ "room trigger list", "List all chat room triggers." }, { "room current on|off", "Whether to show all chat room messages notifications when the window is focussed." },
{ "room trigger on|off", "Enable or disable all chat room notification triggers." }, { "room text on|off", "Show message text in chat room message notifications." },
{ "on|off", "Override the global message setting for the current chat room." }, { "room trigger add <text>", "Notify when specified text included in all chat room messages." },
{ "mention on|off", "Override the global 'mention' setting for the current chat room." }, { "room trigger remove <text>", "Remove chat room notification trigger." },
{ "trigger on|off", "Override the global 'trigger' setting for the current chat room." }, { "room trigger list", "List all chat room triggers." },
{ "reset", "Reset to global notification settings for the current chat room." }, { "room trigger on|off", "Enable or disable all chat room notification triggers." },
{ "remind <seconds>", "Notification reminder period for unread messages, use 0 to disable." }, { "on|off", "Override the global message setting for the current chat room." },
{ "typing on|off", "Notifications when contacts are typing." }, { "mention on|off", "Override the global 'mention' setting for the current chat room." },
{ "typing current on|off", "Whether typing notifications are triggered for the current window." }, { "trigger on|off", "Override the global 'trigger' setting for the current chat room." },
{ "invite on|off", "Notifications for chat room invites." }, { "reset", "Reset to global notification settings for the current chat room." },
{ "sub on|off", "Notifications for subscription requests." }) { "remind <seconds>", "Notification reminder period for unread messages, use 0 to disable." },
{ "typing on|off", "Notifications when contacts are typing." },
{ "typing current on|off", "Whether typing notifications are triggered for the current window." },
{ "invite on|off", "Notifications for chat room invites." },
{ "sub on|off", "Notifications for subscription requests." })
CMD_EXAMPLES( CMD_EXAMPLES(
"/notify chat on", "/notify chat on",
"/notify chat text on", "/notify chat text on",
@ -1943,6 +1949,7 @@ static Autocomplete notify_ac;
static Autocomplete notify_chat_ac; static Autocomplete notify_chat_ac;
static Autocomplete notify_room_ac; static Autocomplete notify_room_ac;
static Autocomplete notify_typing_ac; static Autocomplete notify_typing_ac;
static Autocomplete notify_mention_ac;
static Autocomplete notify_trigger_ac; static Autocomplete notify_trigger_ac;
static Autocomplete prefs_ac; static Autocomplete prefs_ac;
static Autocomplete sub_ac; static Autocomplete sub_ac;
@ -2111,6 +2118,14 @@ cmd_init(void)
autocomplete_add(notify_typing_ac, "off"); autocomplete_add(notify_typing_ac, "off");
autocomplete_add(notify_typing_ac, "current"); autocomplete_add(notify_typing_ac, "current");
notify_mention_ac = autocomplete_new();
autocomplete_add(notify_mention_ac, "on");
autocomplete_add(notify_mention_ac, "off");
autocomplete_add(notify_mention_ac, "case_sensitive");
autocomplete_add(notify_mention_ac, "case_insensitive");
autocomplete_add(notify_mention_ac, "word_whole");
autocomplete_add(notify_mention_ac, "word_part");
notify_trigger_ac = autocomplete_new(); notify_trigger_ac = autocomplete_new();
autocomplete_add(notify_trigger_ac, "add"); autocomplete_add(notify_trigger_ac, "add");
autocomplete_add(notify_trigger_ac, "remove"); autocomplete_add(notify_trigger_ac, "remove");
@ -2571,6 +2586,7 @@ cmd_uninit(void)
autocomplete_free(notify_chat_ac); autocomplete_free(notify_chat_ac);
autocomplete_free(notify_room_ac); autocomplete_free(notify_room_ac);
autocomplete_free(notify_typing_ac); autocomplete_free(notify_typing_ac);
autocomplete_free(notify_mention_ac);
autocomplete_free(notify_trigger_ac); autocomplete_free(notify_trigger_ac);
autocomplete_free(sub_ac); autocomplete_free(sub_ac);
autocomplete_free(titlebar_ac); autocomplete_free(titlebar_ac);
@ -2788,6 +2804,7 @@ cmd_reset_autocomplete(ProfWin *window)
autocomplete_reset(notify_chat_ac); autocomplete_reset(notify_chat_ac);
autocomplete_reset(notify_room_ac); autocomplete_reset(notify_room_ac);
autocomplete_reset(notify_typing_ac); autocomplete_reset(notify_typing_ac);
autocomplete_reset(notify_mention_ac);
autocomplete_reset(notify_trigger_ac); autocomplete_reset(notify_trigger_ac);
autocomplete_reset(sub_ac); autocomplete_reset(sub_ac);
@ -3491,7 +3508,7 @@ _notify_autocomplete(ProfWin *window, const char *const input)
} }
gchar *boolean_choices1[] = { "/notify room current", "/notify chat current", "/notify typing current", gchar *boolean_choices1[] = { "/notify room current", "/notify chat current", "/notify typing current",
"/notify room text", "/notify room mention", "/notify chat text" }; "/notify room text", "/notify chat text" };
for (i = 0; i < ARRAY_SIZE(boolean_choices1); i++) { for (i = 0; i < ARRAY_SIZE(boolean_choices1); i++) {
result = autocomplete_param_with_func(input, boolean_choices1[i], prefs_autocomplete_boolean_choice); result = autocomplete_param_with_func(input, boolean_choices1[i], prefs_autocomplete_boolean_choice);
if (result) { if (result) {
@ -3499,6 +3516,11 @@ _notify_autocomplete(ProfWin *window, const char *const input)
} }
} }
result = autocomplete_param_with_ac(input, "/notify room mention", notify_mention_ac, TRUE);
if (result) {
return result;
}
result = autocomplete_param_with_ac(input, "/notify room trigger", notify_trigger_ac, TRUE); result = autocomplete_param_with_ac(input, "/notify room trigger", notify_trigger_ac, TRUE);
if (result) { if (result) {
return result; return result;

View File

@ -4855,6 +4855,18 @@ cmd_notify(ProfWin *window, const char *const command, gchar **args)
} else if (g_strcmp0(args[2], "off") == 0) { } else if (g_strcmp0(args[2], "off") == 0) {
cons_show("Room notifications with mention disabled."); cons_show("Room notifications with mention disabled.");
prefs_set_boolean(PREF_NOTIFY_ROOM_MENTION, FALSE); prefs_set_boolean(PREF_NOTIFY_ROOM_MENTION, FALSE);
} else if (g_strcmp0(args[2], "case_sensitive") == 0) {
cons_show("Room mention matching set to case sensitive.");
prefs_set_boolean(PREF_NOTIFY_MENTION_CASE_SENSITIVE, TRUE);
} else if (g_strcmp0(args[2], "case_insensitive") == 0) {
cons_show("Room mention matching set to case insensitive.");
prefs_set_boolean(PREF_NOTIFY_MENTION_CASE_SENSITIVE, FALSE);
} else if (g_strcmp0(args[2], "word_whole") == 0) {
cons_show("Room mention matching set to whole word.");
prefs_set_boolean(PREF_NOTIFY_MENTION_WHOLE_WORD, TRUE);
} else if (g_strcmp0(args[2], "word_part") == 0) {
cons_show("Room mention matching set to partial word.");
prefs_set_boolean(PREF_NOTIFY_MENTION_WHOLE_WORD, FALSE);
} else { } else {
cons_show("Usage: /notify room mention on|off"); cons_show("Usage: /notify room mention on|off");
} }

View File

@ -199,18 +199,6 @@ str_replace(const char *string, const char *substr,
return newstr; return newstr;
} }
gboolean
str_contains_str(const char *const searchstr, const char *const substr)
{
if (!searchstr) {
return FALSE;
}
if (!substr) {
return FALSE;
}
return g_strrstr(searchstr, substr) != NULL;
}
int int
str_contains(const char str[], int size, char ch) str_contains(const char str[], int size, char ch)
{ {
@ -669,3 +657,32 @@ is_notify_enabled(void)
return notify_enabled; return notify_enabled;
} }
GSList*
prof_occurrences(const char *const needle, const char *const haystack, int offset, gboolean whole_word, GSList **result)
{
if (needle == NULL || haystack == NULL) {
return *result;
}
if (g_str_has_prefix(&haystack[offset], needle)) {
if (whole_word) {
char *prev = g_utf8_prev_char(&haystack[offset]);
char *next = g_utf8_next_char(&haystack[offset] + strlen(needle) - 1);
gunichar prevu = g_utf8_get_char(prev);
gunichar nextu = g_utf8_get_char(next);
if (!g_unichar_isalnum(prevu) && !g_unichar_isalnum(nextu)) {
*result = g_slist_append(*result, GINT_TO_POINTER(offset));
}
} else {
*result = g_slist_append(*result, GINT_TO_POINTER(offset));
}
}
if (haystack[offset+1] != '\0') {
*result = prof_occurrences(needle, haystack, offset+1, whole_word, result);
}
return *result;
}

View File

@ -103,7 +103,6 @@ gboolean p_hash_table_contains(GHashTable *hash_table, gconstpointer key);
gboolean create_dir(char *name); gboolean create_dir(char *name);
gboolean mkdir_recursive(const char *dir); gboolean mkdir_recursive(const char *dir);
char* str_replace(const char *string, const char *substr, const char *replacement); char* str_replace(const char *string, const char *substr, const char *replacement);
gboolean str_contains_str(const char *const searchstr, const char *const substr);
int str_contains(const char str[], int size, char ch); int str_contains(const char str[], int size, char ch);
gboolean strtoi_range(char *str, int *saveptr, int min, int max, char **err_msg); gboolean strtoi_range(char *str, int *saveptr, int min, int max, char **err_msg);
int utf8_display_len(const char *const str); int utf8_display_len(const char *const str);
@ -129,4 +128,7 @@ char* get_file_or_linked(char *loc, char *basedir);
char* strip_arg_quotes(const char *const input); char* strip_arg_quotes(const char *const input);
gboolean is_notify_enabled(void); gboolean is_notify_enabled(void);
GSList* prof_occurrences(const char *const needle, const char *const haystack, int offset, gboolean whole_word,
GSList **result);
#endif #endif

View File

@ -1230,6 +1230,8 @@ _get_group(preference_t pref)
case PREF_NOTIFY_ROOM_TEXT: case PREF_NOTIFY_ROOM_TEXT:
case PREF_NOTIFY_INVITE: case PREF_NOTIFY_INVITE:
case PREF_NOTIFY_SUB: case PREF_NOTIFY_SUB:
case PREF_NOTIFY_MENTION_CASE_SENSITIVE:
case PREF_NOTIFY_MENTION_WHOLE_WORD:
return PREF_GROUP_NOTIFICATIONS; return PREF_GROUP_NOTIFICATIONS;
case PREF_CHLOG: case PREF_CHLOG:
case PREF_GRLOG: case PREF_GRLOG:
@ -1332,6 +1334,10 @@ _get_key(preference_t pref)
return "invite"; return "invite";
case PREF_NOTIFY_SUB: case PREF_NOTIFY_SUB:
return "sub"; return "sub";
case PREF_NOTIFY_MENTION_CASE_SENSITIVE:
return "room.mention.casesensitive";
case PREF_NOTIFY_MENTION_WHOLE_WORD:
return "room.mention.wholeword";
case PREF_CHLOG: case PREF_CHLOG:
return "chlog"; return "chlog";
case PREF_GRLOG: case PREF_GRLOG:
@ -1488,6 +1494,8 @@ _get_default_boolean(preference_t pref)
case PREF_ROSTER_ROOMS: case PREF_ROSTER_ROOMS:
case PREF_TLS_SHOW: case PREF_TLS_SHOW:
case PREF_LASTACTIVITY: case PREF_LASTACTIVITY:
case PREF_NOTIFY_MENTION_CASE_SENSITIVE:
case PREF_NOTIFY_MENTION_WHOLE_WORD:
return TRUE; return TRUE;
default: default:
return FALSE; return FALSE;

View File

@ -113,6 +113,8 @@ typedef enum {
PREF_NOTIFY_ROOM_TEXT, PREF_NOTIFY_ROOM_TEXT,
PREF_NOTIFY_INVITE, PREF_NOTIFY_INVITE,
PREF_NOTIFY_SUB, PREF_NOTIFY_SUB,
PREF_NOTIFY_MENTION_CASE_SENSITIVE,
PREF_NOTIFY_MENTION_WHOLE_WORD,
PREF_CHLOG, PREF_CHLOG,
PREF_GRLOG, PREF_GRLOG,
PREF_AUTOAWAY_CHECK, PREF_AUTOAWAY_CHECK,

View File

@ -254,18 +254,20 @@ sv_ev_room_message(const char *const room_jid, const char *const nick, const cha
char *new_message = plugins_pre_room_message_display(room_jid, nick, message); char *new_message = plugins_pre_room_message_display(room_jid, nick, message);
char *mynick = muc_nick(mucwin->roomjid); char *mynick = muc_nick(mucwin->roomjid);
gboolean mention = FALSE; gboolean whole_word = prefs_get_boolean(PREF_NOTIFY_MENTION_WHOLE_WORD);
char *message_lower = g_utf8_strdown(new_message, -1); gboolean case_sensitive = prefs_get_boolean(PREF_NOTIFY_MENTION_CASE_SENSITIVE);
char *mynick_lower = g_utf8_strdown(mynick, -1); char *message_search = case_sensitive ? strdup(new_message) : g_utf8_strdown(new_message, -1);
if (g_strrstr(message_lower, mynick_lower)) { char *mynick_search = case_sensitive ? strdup(mynick) : g_utf8_strdown(mynick, -1);
mention = TRUE;
} GSList *mentions = NULL;
g_free(message_lower); mentions = prof_occurrences(mynick_search, message_search, 0, whole_word, &mentions);
g_free(mynick_lower); gboolean mention = g_slist_length(mentions) > 0;
g_free(message_search);
g_free(mynick_search);
GList *triggers = prefs_message_get_triggers(new_message); GList *triggers = prefs_message_get_triggers(new_message);
mucwin_message(mucwin, nick, new_message, mention, triggers); mucwin_message(mucwin, nick, new_message, mentions, triggers);
ProfWin *window = (ProfWin*)mucwin; ProfWin *window = (ProfWin*)mucwin;
int num = wins_get_num(window); int num = wins_get_num(window);

View File

@ -1550,6 +1550,16 @@ cons_notify_setting(void)
else else
cons_show("Room mention (/notify room) : OFF"); cons_show("Room mention (/notify room) : OFF");
if (prefs_get_boolean(PREF_NOTIFY_MENTION_CASE_SENSITIVE))
cons_show("Room mention case (/notify room) : Case sensitive");
else
cons_show("Room mention case (/notify room) : Case insensitive");
if (prefs_get_boolean(PREF_NOTIFY_MENTION_WHOLE_WORD))
cons_show("Room mention word (/notify room) : Whole word only");
else
cons_show("Room mention word (/notify room) : Part of word");
if (prefs_get_boolean(PREF_NOTIFY_ROOM_TRIGGER)) if (prefs_get_boolean(PREF_NOTIFY_ROOM_TRIGGER))
cons_show("Room trigger (/notify room) : ON"); cons_show("Room trigger (/notify room) : ON");
else else

View File

@ -359,33 +359,30 @@ mucwin_history(ProfMucWin *mucwin, const char *const nick, GDateTime *timestamp,
} }
static void static void
_mucwin_print_mention(ProfWin *window, const char *const message, const char *const my_nick) _mucwin_print_mention(ProfWin *window, const char *const message, const char *const nick, GSList *mentions)
{ {
char *mynick_lower = g_utf8_strdown(my_nick, -1); int last_pos = 0;
char *message_lower = g_utf8_strdown(message, -1); int pos = 0;
char message_section[strlen(message) + 1]; GSList *curr = mentions;
while (curr) {
pos = GPOINTER_TO_INT(curr->data);
int i = 0; char *before_str = g_strndup(message + last_pos, pos - last_pos);
while(!g_str_has_prefix(&message_lower[i], mynick_lower) && i < strlen(message)) { win_print(window, '-', 0, NULL, NO_DATE | NO_ME | NO_EOL, THEME_ROOMMENTION, "", before_str);
message_section[i] = message[i]; g_free(before_str);
i++; char *nick_str = g_strndup(message + pos, strlen(nick));
win_print(window, '-', 0, NULL, NO_DATE | NO_ME | NO_EOL, THEME_ROOMMENTION_TERM, "", nick_str);
g_free(nick_str);
last_pos = pos + strlen(nick);
curr = g_slist_next(curr);
} }
message_section[i] = '\0'; if (last_pos < strlen(message)) {
win_print(window, '-', 0, NULL, NO_DATE | NO_ME, THEME_ROOMMENTION, "", &message[last_pos]);
char *mention_section = strndup(&message[i], strlen(my_nick));
int used = strlen(message_section) + strlen(mention_section);
win_print(window, '-', 0, NULL, NO_DATE | NO_ME | NO_EOL, THEME_ROOMMENTION, "", message_section);
if (strlen(message) > used) {
win_print(window, '-', 0, NULL, NO_DATE | NO_ME | NO_EOL, THEME_ROOMMENTION_TERM, "", mention_section);
_mucwin_print_mention(window, &message[used], my_nick);
} else { } else {
win_print(window, '-', 0, NULL, NO_DATE | NO_ME, THEME_ROOMMENTION_TERM, "", mention_section); win_print(window, '-', 0, NULL, NO_DATE | NO_ME, THEME_ROOMMENTION, "", "");
} }
free(mention_section);
g_free(mynick_lower);
g_free(message_lower);
} }
gint gint
@ -472,17 +469,17 @@ _mucwin_print_triggers(ProfWin *window, const char *const message, GList *trigge
} }
void void
mucwin_message(ProfMucWin *mucwin, const char *const nick, const char *const message, gboolean mention, GList *triggers) mucwin_message(ProfMucWin *mucwin, const char *const nick, const char *const message, GSList *mentions, GList *triggers)
{ {
assert(mucwin != NULL); assert(mucwin != NULL);
ProfWin *window = (ProfWin*)mucwin; ProfWin *window = (ProfWin*)mucwin;
char *my_nick = muc_nick(mucwin->roomjid); char *mynick = muc_nick(mucwin->roomjid);
if (g_strcmp0(nick, my_nick) != 0) { if (g_strcmp0(nick, mynick) != 0) {
if (mention) { if (g_slist_length(mentions) > 0) {
win_print(window, '-', 0, NULL, NO_ME | NO_EOL, THEME_ROOMMENTION, nick, ""); win_print(window, '-', 0, NULL, NO_ME | NO_EOL, THEME_ROOMMENTION, nick, "");
_mucwin_print_mention(window, message, my_nick); _mucwin_print_mention(window, message, mynick, mentions);
} else if (triggers) { } else if (triggers) {
win_print(window, '-', 0, NULL, NO_ME | NO_EOL, THEME_ROOMTRIGGER, nick, ""); win_print(window, '-', 0, NULL, NO_ME | NO_EOL, THEME_ROOMTRIGGER, nick, "");
_mucwin_print_triggers(window, message, triggers); _mucwin_print_triggers(window, message, triggers);

View File

@ -157,7 +157,7 @@ void mucwin_occupant_role_and_affiliation_change(ProfMucWin *mucwin, const char
const char *const role, const char *const affiliation, const char *const actor, const char *const reason); const char *const role, const char *const affiliation, const char *const actor, const char *const reason);
void mucwin_roster(ProfMucWin *mucwin, GList *occupants, const char *const presence); void mucwin_roster(ProfMucWin *mucwin, GList *occupants, const char *const presence);
void mucwin_history(ProfMucWin *mucwin, const char *const nick, GDateTime *timestamp, const char *const message); void mucwin_history(ProfMucWin *mucwin, const char *const nick, GDateTime *timestamp, const char *const message);
void mucwin_message(ProfMucWin *mucwin, const char *const nick, const char *const message, gboolean mention, GList *triggers); void mucwin_message(ProfMucWin *mucwin, const char *const nick, const char *const message, GSList *mentions, GList *triggers);
void mucwin_subject(ProfMucWin *mucwin, const char *const nick, const char *const subject); void mucwin_subject(ProfMucWin *mucwin, const char *const nick, const char *const subject);
void mucwin_requires_config(ProfMucWin *mucwin); void mucwin_requires_config(ProfMucWin *mucwin);
void mucwin_info(ProfMucWin *mucwin); void mucwin_info(ProfMucWin *mucwin);

View File

@ -631,66 +631,138 @@ void strip_quotes_strips_both(void **state)
free(result); free(result);
} }
void str_not_contains_str(void **state) gboolean
_lists_equal(GSList *a, GSList *b)
{ {
char *main = "somestring"; if (g_slist_length(a) != g_slist_length(b)) {
char *occur = "not"; return FALSE;
}
assert_false(str_contains_str(main, occur)); GSList *curra = a;
GSList *currb = b;
while (curra) {
int aval = GPOINTER_TO_INT(curra->data);
int bval = GPOINTER_TO_INT(currb->data);
if (aval != bval) {
return FALSE;
}
curra = g_list_next(curra);
currb = g_list_next(currb);
}
return TRUE;
} }
void str_contains_str_at_start(void **state) void prof_partial_occurrences_tests(void **state)
{ {
char *main = "somestring"; GSList *actual = NULL;
char *occur = "some"; GSList *expected = NULL;
assert_true(_lists_equal(prof_occurrences(NULL, NULL, 0, FALSE, &actual), expected));
g_slist_free(actual); actual = NULL;
assert_true(str_contains_str(main, occur)); assert_true(_lists_equal(prof_occurrences(NULL, "some string", 0, FALSE, &actual), expected)); g_slist_free(actual); actual = NULL;
assert_true(_lists_equal(prof_occurrences("boothj5", NULL, 0, FALSE, &actual), expected)); g_slist_free(actual); actual = NULL;
assert_true(_lists_equal(prof_occurrences(NULL, NULL, 0, FALSE, &actual), expected)); g_slist_free(actual); actual = NULL;
assert_true(_lists_equal(prof_occurrences("boothj5", "Boothj5", 0, FALSE, &actual), expected)); g_slist_free(actual); actual = NULL;
assert_true(_lists_equal(prof_occurrences("Boothj5", "boothj5", 0, FALSE, &actual), expected)); g_slist_free(actual); actual = NULL;
expected = g_slist_append(expected, GINT_TO_POINTER(0));
assert_true(_lists_equal(prof_occurrences("boothj5", "boothj5", 0, FALSE, &actual), expected)); g_slist_free(actual); actual = NULL;
assert_true(_lists_equal(prof_occurrences("boothj5", "boothj5hello", 0, FALSE, &actual), expected)); g_slist_free(actual); actual = NULL;
assert_true(_lists_equal(prof_occurrences("boothj5", "boothj5 hello", 0, FALSE, &actual), expected)); g_slist_free(actual); actual = NULL;
g_slist_free(expected); expected = NULL;
expected = g_slist_append(expected, GINT_TO_POINTER(5));
assert_true(_lists_equal(prof_occurrences("boothj5", "helloboothj5", 0, FALSE, &actual), expected)); g_slist_free(actual); actual = NULL;
assert_true(_lists_equal(prof_occurrences("boothj5", "helloboothj5hello", 0, FALSE, &actual), expected)); g_slist_free(actual); actual = NULL;
g_slist_free(expected); expected = NULL;
expected = g_slist_append(expected, GINT_TO_POINTER(6));
assert_true(_lists_equal(prof_occurrences("boothj5", "hello boothj5", 0, FALSE, &actual), expected)); g_slist_free(actual); actual = NULL;
assert_true(_lists_equal(prof_occurrences("boothj5", "hello boothj5 hello", 0, FALSE, &actual), expected)); g_slist_free(actual); actual = NULL;
g_slist_free(expected); expected = NULL;
expected = g_slist_append(expected, GINT_TO_POINTER(0));
expected = g_slist_append(expected, GINT_TO_POINTER(7));
assert_true(_lists_equal(prof_occurrences("boothj5", "boothj5boothj5", 0, FALSE, &actual), expected)); g_slist_free(actual); actual = NULL;
g_slist_free(expected); expected = NULL;
expected = g_slist_append(expected, GINT_TO_POINTER(0));
expected = g_slist_append(expected, GINT_TO_POINTER(12));
assert_true(_lists_equal(prof_occurrences("boothj5", "boothj5helloboothj5", 0, FALSE, &actual), expected)); g_slist_free(actual); actual = NULL;
g_slist_free(expected); expected = NULL;
expected = g_slist_append(expected, GINT_TO_POINTER(0));
expected = g_slist_append(expected, GINT_TO_POINTER(14));
assert_true(_lists_equal(prof_occurrences("boothj5", "boothj5 hello boothj5", 0, FALSE, &actual), expected)); g_slist_free(actual); actual = NULL;
g_slist_free(expected); expected = NULL;
expected = g_slist_append(expected, GINT_TO_POINTER(2));
expected = g_slist_append(expected, GINT_TO_POINTER(16));
expected = g_slist_append(expected, GINT_TO_POINTER(29));
assert_true(_lists_equal(prof_occurrences("boothj5", "hiboothj5 hello boothj5there boothj5s", 0, FALSE, &actual), expected)); g_slist_free(actual); actual = NULL;
g_slist_free(expected); expected = NULL;
} }
void str_contains_str_at_end(void **state) void prof_whole_occurrences_tests(void **state)
{ {
char *main = "somestring"; GSList *actual = NULL;
char *occur = "string"; GSList *expected = NULL;
assert_true(_lists_equal(prof_occurrences(NULL, NULL, 0, FALSE, &actual), expected));
g_slist_free(actual); actual = NULL;
assert_true(str_contains_str(main, occur)); expected = g_slist_append(expected, GINT_TO_POINTER(0));
} assert_true(_lists_equal(prof_occurrences("boothj5", "boothj5", 0, TRUE, &actual), expected)); g_slist_free(actual); actual = NULL;
assert_true(_lists_equal(prof_occurrences("boothj5", "boothj5 hi", 0, TRUE, &actual), expected)); g_slist_free(actual); actual = NULL;
void str_contains_str_in_middle(void **state) assert_true(_lists_equal(prof_occurrences("boothj5", "boothj5: hi", 0, TRUE, &actual), expected)); g_slist_free(actual); actual = NULL;
{ assert_true(_lists_equal(prof_occurrences("boothj5", "boothj5, hi", 0, TRUE, &actual), expected)); g_slist_free(actual); actual = NULL;
char *main = "somestring"; g_slist_free(expected); expected = NULL;
char *occur = "str";
expected = g_slist_append(expected, GINT_TO_POINTER(6));
assert_true(str_contains_str(main, occur)); assert_true(_lists_equal(prof_occurrences("boothj5", "hello boothj5", 0, TRUE, &actual), expected)); g_slist_free(actual); actual = NULL;
} assert_true(_lists_equal(prof_occurrences("boothj5", "hello boothj5 there", 0, TRUE, &actual), expected)); g_slist_free(actual); actual = NULL;
assert_true(_lists_equal(prof_occurrences("boothj5", "heyy @boothj5, there", 0, TRUE, &actual), expected)); g_slist_free(actual); actual = NULL;
void str_contains_str_whole(void **state) g_slist_free(expected); expected = NULL;
{
char *main = "somestring"; expected = g_slist_append(expected, GINT_TO_POINTER(6));
char *occur = "somestring"; expected = g_slist_append(expected, GINT_TO_POINTER(26));
assert_true(_lists_equal(prof_occurrences("boothj5", "hello boothj5 some more a boothj5 stuff", 0, TRUE, &actual), expected)); g_slist_free(actual); actual = NULL;
assert_true(str_contains_str(main, occur)); assert_true(_lists_equal(prof_occurrences("boothj5", "hello boothj5 there ands #boothj5", 0, TRUE, &actual), expected)); g_slist_free(actual); actual = NULL;
} assert_true(_lists_equal(prof_occurrences("boothj5", "heyy @boothj5, there hows boothj5?", 0, TRUE, &actual), expected)); g_slist_free(actual); actual = NULL;
g_slist_free(expected); expected = NULL;
void str_empty_not_contains_str(void **state)
{ expected = g_slist_append(expected, GINT_TO_POINTER(6));
char *main = NULL; assert_true(_lists_equal(prof_occurrences("p", "ppppp p", 0, TRUE, &actual), expected)); g_slist_free(actual); actual = NULL;
char *occur = "str"; g_slist_free(expected); expected = NULL;
assert_false(str_contains_str(main, occur)); expected = g_slist_append(expected, GINT_TO_POINTER(0));
} assert_true(_lists_equal(prof_occurrences("p", "p ppppp", 0, TRUE, &actual), expected)); g_slist_free(actual); actual = NULL;
g_slist_free(expected); expected = NULL;
void str_not_contains_str_empty(void **state)
{ expected = g_slist_append(expected, GINT_TO_POINTER(4));
char *main = "somestring"; assert_true(_lists_equal(prof_occurrences("p", "ppp p ppp", 0, TRUE, &actual), expected)); g_slist_free(actual); actual = NULL;
char *occur = NULL; g_slist_free(expected); expected = NULL;
assert_false(str_contains_str(main, occur)); expected = NULL;
} assert_true(_lists_equal(prof_occurrences("boothj5", "boothj5hello", 0, TRUE, &actual), expected)); g_slist_free(actual); actual = NULL;
assert_true(_lists_equal(prof_occurrences("boothj5", "heyboothj5", 0, TRUE, &actual), expected)); g_slist_free(actual); actual = NULL;
void str_empty_not_contains_str_empty(void **state) assert_true(_lists_equal(prof_occurrences("boothj5", "heyboothj5hithere", 0, TRUE, &actual), expected)); g_slist_free(actual); actual = NULL;
{ assert_true(_lists_equal(prof_occurrences("boothj5", "hey boothj5hithere", 0, TRUE, &actual), expected)); g_slist_free(actual); actual = NULL;
char *main = NULL; assert_true(_lists_equal(prof_occurrences("boothj5", "hey @boothj5hithere", 0, TRUE, &actual), expected)); g_slist_free(actual); actual = NULL;
char *occur = NULL; assert_true(_lists_equal(prof_occurrences("boothj5", "heyboothj5 hithere", 0, TRUE, &actual), expected)); g_slist_free(actual); actual = NULL;
assert_true(_lists_equal(prof_occurrences("boothj5", "heyboothj5, hithere", 0, TRUE, &actual), expected)); g_slist_free(actual); actual = NULL;
assert_false(str_contains_str(main, occur)); assert_true(_lists_equal(prof_occurrences("boothj5", "boothj5boothj5", 0, TRUE, &actual), expected)); g_slist_free(actual); actual = NULL;
assert_true(_lists_equal(prof_occurrences("boothj5", "boothj5fillboothj5", 0, TRUE, &actual), expected)); g_slist_free(actual); actual = NULL;
assert_true(_lists_equal(prof_occurrences("k", "dont know", 0, TRUE, &actual), expected)); g_slist_free(actual); actual = NULL;
assert_true(_lists_equal(prof_occurrences("k", "kick", 0, TRUE, &actual), expected)); g_slist_free(actual); actual = NULL;
assert_true(_lists_equal(prof_occurrences("k", "kick kick", 0, TRUE, &actual), expected)); g_slist_free(actual); actual = NULL;
assert_true(_lists_equal(prof_occurrences("k", "kick kickk", 0, TRUE, &actual), expected)); g_slist_free(actual); actual = NULL;
assert_true(_lists_equal(prof_occurrences("k", "kic", 0, TRUE, &actual), expected)); g_slist_free(actual); actual = NULL;
assert_true(_lists_equal(prof_occurrences("k", "ick", 0, TRUE, &actual), expected)); g_slist_free(actual); actual = NULL;
assert_true(_lists_equal(prof_occurrences("k", "kk", 0, TRUE, &actual), expected)); g_slist_free(actual); actual = NULL;
assert_true(_lists_equal(prof_occurrences("k", "kkkkkkk", 0, TRUE, &actual), expected)); g_slist_free(actual); actual = NULL;
g_slist_free(expected); expected = NULL;
} }

View File

@ -64,3 +64,5 @@ void str_contains_str_whole(void **state);
void str_empty_not_contains_str(void **state); void str_empty_not_contains_str(void **state);
void str_not_contains_str_empty(void **state); void str_not_contains_str_empty(void **state);
void str_empty_not_contains_str_empty(void **state); void str_empty_not_contains_str_empty(void **state);
void prof_partial_occurrences_tests(void **state);
void prof_whole_occurrences_tests(void **state);

View File

@ -193,7 +193,7 @@ void mucwin_occupant_role_and_affiliation_change(ProfMucWin *mucwin, const char
const char * const affiliation, const char * const actor, const char * const reason) {} const char * const affiliation, const char * const actor, const char * const reason) {}
void mucwin_roster(ProfMucWin *mucwin, GList *occupants, const char * const presence) {} void mucwin_roster(ProfMucWin *mucwin, GList *occupants, const char * const presence) {}
void mucwin_history(ProfMucWin *mucwin, const char * const nick, GDateTime *timestamp, const char * const message) {} void mucwin_history(ProfMucWin *mucwin, const char * const nick, GDateTime *timestamp, const char * const message) {}
void mucwin_message(ProfMucWin *mucwin, const char * const nick, const char * const message, gboolean mention, GList *triggers) {} void mucwin_message(ProfMucWin *mucwin, const char *const nick, const char *const message, GSList *mentions, GList *triggers) {}
void mucwin_subject(ProfMucWin *mucwin, const char * const nick, const char * const subject) {} void mucwin_subject(ProfMucWin *mucwin, const char * const nick, const char * const subject) {}
void mucwin_requires_config(ProfMucWin *mucwin) {} void mucwin_requires_config(ProfMucWin *mucwin) {}
void ui_room_destroy(const char * const roomjid) {} void ui_room_destroy(const char * const roomjid) {}

View File

@ -94,14 +94,6 @@ int main(int argc, char* argv[]) {
unit_test(strip_quotes_strips_first), unit_test(strip_quotes_strips_first),
unit_test(strip_quotes_strips_last), unit_test(strip_quotes_strips_last),
unit_test(strip_quotes_strips_both), unit_test(strip_quotes_strips_both),
unit_test(str_not_contains_str),
unit_test(str_contains_str_at_start),
unit_test(str_contains_str_at_end),
unit_test(str_contains_str_in_middle),
unit_test(str_contains_str_whole),
unit_test(str_empty_not_contains_str),
unit_test(str_not_contains_str_empty),
unit_test(str_empty_not_contains_str_empty),
unit_test(clear_empty), unit_test(clear_empty),
unit_test(reset_after_create), unit_test(reset_after_create),
@ -624,6 +616,9 @@ int main(int argc, char* argv[]) {
unit_test_setup_teardown(clears_chat_sessions, unit_test_setup_teardown(clears_chat_sessions,
load_preferences, load_preferences,
close_preferences), close_preferences),
unit_test(prof_partial_occurrences_tests),
unit_test(prof_whole_occurrences_tests),
}; };
return run_tests(all_tests); return run_tests(all_tests);