diff options
author | James Booth <boothj5@gmail.com> | 2016-04-07 01:01:27 +0100 |
---|---|---|
committer | James Booth <boothj5@gmail.com> | 2016-04-07 01:01:27 +0100 |
commit | f243e333fcb6740ff8d09cc04db27d88040f5f7d (patch) | |
tree | 63a10e47de649d46779c081ce84ff7d16f36aa19 /tests/unittests | |
parent | 6edf3b3f94eb81413826e1559ee96be0604f3adf (diff) | |
download | profani-tty-f243e333fcb6740ff8d09cc04db27d88040f5f7d.tar.gz |
Added whole word matches for room mention
Diffstat (limited to 'tests/unittests')
-rw-r--r-- | tests/unittests/test_common.c | 243 | ||||
-rw-r--r-- | tests/unittests/test_common.h | 3 | ||||
-rw-r--r-- | tests/unittests/ui/stub_ui.c | 2 | ||||
-rw-r--r-- | tests/unittests/unittests.c | 3 |
4 files changed, 139 insertions, 112 deletions
diff --git a/tests/unittests/test_common.c b/tests/unittests/test_common.c index e80edb1c..76128edf 100644 --- a/tests/unittests/test_common.c +++ b/tests/unittests/test_common.c @@ -631,113 +631,138 @@ void strip_quotes_strips_both(void **state) free(result); } -void prof_strstr_contains(void **state) -{ - assert_true(prof_strstr(NULL, "some string", FALSE, FALSE) == FALSE); - assert_true(prof_strstr("boothj5", NULL, FALSE, FALSE) == FALSE); - assert_true(prof_strstr(NULL, NULL, FALSE, FALSE) == FALSE); - - assert_true(prof_strstr("boothj5", "boothj5", FALSE, FALSE) == TRUE); - assert_true(prof_strstr("boothj5", "boothj5 hello", FALSE, FALSE) == TRUE); - assert_true(prof_strstr("boothj5", "hello boothj5", FALSE, FALSE) == TRUE); - assert_true(prof_strstr("boothj5", "hello boothj5 there", FALSE, FALSE) == TRUE); - assert_true(prof_strstr("boothj5", "helloboothj5test", FALSE, FALSE) == TRUE); - - assert_true(prof_strstr("boothj5", "BoothJ5", FALSE, FALSE) == TRUE); - assert_true(prof_strstr("boothj5", "BoothJ5 hello", FALSE, FALSE) == TRUE); - assert_true(prof_strstr("boothj5", "hello BoothJ5", FALSE, FALSE) == TRUE); - assert_true(prof_strstr("boothj5", "hello BoothJ5 there", FALSE, FALSE) == TRUE); - assert_true(prof_strstr("boothj5", "helloBoothJ5test", FALSE, FALSE) == TRUE); - - assert_true(prof_strstr("BoothJ5", "boothj5", FALSE, FALSE) == TRUE); - assert_true(prof_strstr("BoothJ5", "boothj5 hello", FALSE, FALSE) == TRUE); - assert_true(prof_strstr("BoothJ5", "hello boothj5", FALSE, FALSE) == TRUE); - assert_true(prof_strstr("BoothJ5", "hello boothj5 there", FALSE, FALSE) == TRUE); - assert_true(prof_strstr("BoothJ5", "helloboothj5test", FALSE, FALSE) == TRUE); - - assert_true(prof_strstr("boothj5", "BoothJ5", TRUE, FALSE) == FALSE); - assert_true(prof_strstr("boothj5", "BoothJ5 hello", TRUE, FALSE) == FALSE); - assert_true(prof_strstr("boothj5", "hello BoothJ5", TRUE, FALSE) == FALSE); - assert_true(prof_strstr("boothj5", "hello BoothJ5 there", TRUE, FALSE) == FALSE); - assert_true(prof_strstr("boothj5", "helloBoothJ5test", TRUE, FALSE) == FALSE); - - assert_true(prof_strstr("BoothJ5", "boothj5", TRUE, FALSE) == FALSE); - assert_true(prof_strstr("BoothJ5", "boothj5 hello", TRUE, FALSE) == FALSE); - assert_true(prof_strstr("BoothJ5", "hello boothj5", TRUE, FALSE) == FALSE); - assert_true(prof_strstr("BoothJ5", "hello boothj5 there", TRUE, FALSE) == FALSE); - assert_true(prof_strstr("BoothJ5", "helloboothj5test", TRUE, FALSE) == FALSE); - - assert_true(prof_strstr("boothj5", "boothj5", FALSE, TRUE) == TRUE); - assert_true(prof_strstr("boothj5", "boothj5 hello", FALSE, TRUE) == TRUE); - assert_true(prof_strstr("boothj5", "hello boothj5", FALSE, TRUE) == TRUE); - assert_true(prof_strstr("boothj5", "hello boothj5 there", FALSE, TRUE) == TRUE); - assert_true(prof_strstr("boothj5", "boothj5test", FALSE, TRUE) == FALSE); - assert_true(prof_strstr("boothj5", "helloboothj5", FALSE, TRUE) == FALSE); - assert_true(prof_strstr("boothj5", "helloboothj5test", FALSE, TRUE) == FALSE); - - assert_true(prof_strstr("boothj5", "BoothJ5", TRUE, TRUE) == FALSE); - assert_true(prof_strstr("boothj5", "BoothJ5 hello", TRUE, TRUE) == FALSE); - assert_true(prof_strstr("boothj5", "hello BoothJ5", TRUE, TRUE) == FALSE); - assert_true(prof_strstr("boothj5", "hello BoothJ5 there", TRUE, TRUE) == FALSE); - assert_true(prof_strstr("boothj5", "BoothJ5test", TRUE, TRUE) == FALSE); - assert_true(prof_strstr("boothj5", "helloBoothJ5", TRUE, TRUE) == FALSE); - assert_true(prof_strstr("boothj5", "helloBoothJ5test", TRUE, TRUE) == FALSE); - - assert_true(prof_strstr("BoothJ5", "boothj5", TRUE, TRUE) == FALSE); - assert_true(prof_strstr("BoothJ5", "boothj5 hello", TRUE, TRUE) == FALSE); - assert_true(prof_strstr("BoothJ5", "hello boothj5", TRUE, TRUE) == FALSE); - assert_true(prof_strstr("BoothJ5", "hello boothj5 there", TRUE, TRUE) == FALSE); - assert_true(prof_strstr("BoothJ5", "boothj5test", TRUE, TRUE) == FALSE); - assert_true(prof_strstr("BoothJ5", "helloboothj5", TRUE, TRUE) == FALSE); - assert_true(prof_strstr("BoothJ5", "helloboothj5test", TRUE, TRUE) == FALSE); - - assert_true(prof_strstr("boothj5", "boothj5:", FALSE, TRUE) == TRUE); - assert_true(prof_strstr("boothj5", "boothj5,", FALSE, TRUE) == TRUE); - assert_true(prof_strstr("boothj5", "boothj5-", FALSE, TRUE) == TRUE); - assert_true(prof_strstr("boothj5", ":boothj5", FALSE, TRUE) == TRUE); - assert_true(prof_strstr("boothj5", ",boothj5", FALSE, TRUE) == TRUE); - assert_true(prof_strstr("boothj5", "-boothj5", FALSE, TRUE) == TRUE); - assert_true(prof_strstr("boothj5", ":boothj5:", FALSE, TRUE) == TRUE); - assert_true(prof_strstr("boothj5", ",boothj5,", FALSE, TRUE) == TRUE); - assert_true(prof_strstr("boothj5", "-boothj5-", FALSE, TRUE) == TRUE); - - assert_true(prof_strstr("boothj5", "BoothJ5:", FALSE, TRUE) == TRUE); - assert_true(prof_strstr("boothj5", "BoothJ5,", FALSE, TRUE) == TRUE); - assert_true(prof_strstr("boothj5", "BoothJ5-", FALSE, TRUE) == TRUE); - assert_true(prof_strstr("boothj5", ":BoothJ5", FALSE, TRUE) == TRUE); - assert_true(prof_strstr("boothj5", ",BoothJ5", FALSE, TRUE) == TRUE); - assert_true(prof_strstr("boothj5", "-BoothJ5", FALSE, TRUE) == TRUE); - assert_true(prof_strstr("boothj5", ":BoothJ5:", FALSE, TRUE) == TRUE); - assert_true(prof_strstr("boothj5", ",BoothJ5,", FALSE, TRUE) == TRUE); - assert_true(prof_strstr("boothj5", "-BoothJ5-", FALSE, TRUE) == TRUE); - - assert_true(prof_strstr("boothj5", "BoothJ5:", TRUE, TRUE) == FALSE); - assert_true(prof_strstr("boothj5", "BoothJ5,", TRUE, TRUE) == FALSE); - assert_true(prof_strstr("boothj5", "BoothJ5-", TRUE, TRUE) == FALSE); - assert_true(prof_strstr("boothj5", ":BoothJ5", TRUE, TRUE) == FALSE); - assert_true(prof_strstr("boothj5", ",BoothJ5", TRUE, TRUE) == FALSE); - assert_true(prof_strstr("boothj5", "-BoothJ5", TRUE, TRUE) == FALSE); - assert_true(prof_strstr("boothj5", ":BoothJ5:", TRUE, TRUE) == FALSE); - assert_true(prof_strstr("boothj5", ",BoothJ5,", TRUE, TRUE) == FALSE); - assert_true(prof_strstr("boothj5", "-BoothJ5-", TRUE, TRUE) == FALSE); - - assert_true(prof_strstr("K", "don't know", FALSE, FALSE) == TRUE); - assert_true(prof_strstr("K", "don't know", TRUE, FALSE) == FALSE); - assert_true(prof_strstr("K", "don't know", FALSE, TRUE) == FALSE); - assert_true(prof_strstr("K", "don't know", TRUE, TRUE) == FALSE); - - assert_true(prof_strstr("K", "don't Know", FALSE, FALSE) == TRUE); - assert_true(prof_strstr("K", "don't Know", TRUE, FALSE) == TRUE); - assert_true(prof_strstr("K", "don't Know", FALSE, TRUE) == FALSE); - assert_true(prof_strstr("K", "don't Know", TRUE, TRUE) == FALSE); - - assert_true(prof_strstr("K", "backwards", FALSE, FALSE) == TRUE); - assert_true(prof_strstr("K", "backwards", TRUE, FALSE) == FALSE); - assert_true(prof_strstr("K", "backwards", FALSE, TRUE) == FALSE); - assert_true(prof_strstr("K", "backwards", TRUE, TRUE) == FALSE); - - assert_true(prof_strstr("K", "BACKWARDS", FALSE, FALSE) == TRUE); - assert_true(prof_strstr("K", "BACKWARDS", TRUE, FALSE) == TRUE); - assert_true(prof_strstr("K", "BACKWARDS", FALSE, TRUE) == FALSE); - assert_true(prof_strstr("K", "BACKWARDS", TRUE, TRUE) == FALSE); +gboolean +_lists_equal(GSList *a, GSList *b) +{ + if (g_slist_length(a) != g_slist_length(b)) { + return FALSE; + } + + 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 prof_partial_occurrences_tests(void **state) +{ + GSList *actual = NULL; + GSList *expected = 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(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 prof_whole_occurrences_tests(void **state) +{ + GSList *actual = NULL; + GSList *expected = NULL; + assert_true(_lists_equal(prof_occurrences(NULL, NULL, 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, 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; + 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; + 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, 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; + g_slist_free(expected); expected = NULL; + + expected = g_slist_append(expected, GINT_TO_POINTER(6)); + 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(_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; + + expected = g_slist_append(expected, GINT_TO_POINTER(6)); + assert_true(_lists_equal(prof_occurrences("p", "ppppp p", 0, TRUE, &actual), expected)); g_slist_free(actual); actual = NULL; + g_slist_free(expected); expected = NULL; + + 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; + + expected = g_slist_append(expected, GINT_TO_POINTER(4)); + assert_true(_lists_equal(prof_occurrences("p", "ppp p ppp", 0, TRUE, &actual), expected)); g_slist_free(actual); actual = NULL; + g_slist_free(expected); expected = NULL; + + 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; + 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; + assert_true(_lists_equal(prof_occurrences("boothj5", "hey @boothj5hithere", 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_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", "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; } diff --git a/tests/unittests/test_common.h b/tests/unittests/test_common.h index f0e901a7..3a790017 100644 --- a/tests/unittests/test_common.h +++ b/tests/unittests/test_common.h @@ -64,4 +64,5 @@ void str_contains_str_whole(void **state); void str_empty_not_contains_str(void **state); void str_not_contains_str_empty(void **state); void str_empty_not_contains_str_empty(void **state); -void prof_strstr_contains(void **state); +void prof_partial_occurrences_tests(void **state); +void prof_whole_occurrences_tests(void **state); diff --git a/tests/unittests/ui/stub_ui.c b/tests/unittests/ui/stub_ui.c index 4881d831..f9de0859 100644 --- a/tests/unittests/ui/stub_ui.c +++ b/tests/unittests/ui/stub_ui.c @@ -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) {} 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_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_requires_config(ProfMucWin *mucwin) {} void ui_room_destroy(const char * const roomjid) {} diff --git a/tests/unittests/unittests.c b/tests/unittests/unittests.c index 8826f2ec..572d1a4f 100644 --- a/tests/unittests/unittests.c +++ b/tests/unittests/unittests.c @@ -617,7 +617,8 @@ int main(int argc, char* argv[]) { load_preferences, close_preferences), - unit_test(prof_strstr_contains), + unit_test(prof_partial_occurrences_tests), + unit_test(prof_whole_occurrences_tests), }; return run_tests(all_tests); |