diff options
author | Michael Vetter <jubalh@iodoru.org> | 2023-03-13 09:18:18 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-03-13 09:18:18 +0100 |
commit | e5e8ff221a08939b43edf488fa2a3b8fe95169ea (patch) | |
tree | bab370288daa0ec39923f61697f9f82787246755 /tests/unittests/test_common.c | |
parent | f618b9cc16c37aa832202340f2f4cf2b29348026 (diff) | |
parent | 2936b09a63728c9ac0c1e92786d37fec673da8d2 (diff) | |
download | profani-tty-e5e8ff221a08939b43edf488fa2a3b8fe95169ea.tar.gz |
Merge pull request #1796 from profanity-im/minor-improvements
Minor improvements
Diffstat (limited to 'tests/unittests/test_common.c')
-rw-r--r-- | tests/unittests/test_common.c | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/tests/unittests/test_common.c b/tests/unittests/test_common.c index fa5dd59e..3812cccb 100644 --- a/tests/unittests/test_common.c +++ b/tests/unittests/test_common.c @@ -536,6 +536,28 @@ _lists_equal(GSList* a, GSList* b) } void +prof_occurrences_of_large_message_tests(void** state) +{ + GSList* actual = NULL; + GSList* expected = NULL; + /* use this with the old implementation to create a segfault + * const size_t haystack_sz = 1024 * 1024; + */ + const size_t haystack_sz = 1024; + size_t haystack_cur = 0; + char* haystack = malloc(haystack_sz); + const char needle[] = "needle "; + while (haystack_sz - haystack_cur > sizeof(needle)) { + memcpy(&haystack[haystack_cur], needle, sizeof(needle) - 1); + expected = g_slist_append(expected, GINT_TO_POINTER(haystack_cur)); + haystack_cur += sizeof(needle) - 1; + } + assert_true(_lists_equal(prof_occurrences("needle", haystack, 0, FALSE, &actual), expected)); + g_slist_free(actual); + g_slist_free(expected); +} + +void prof_partial_occurrences_tests(void** state) { GSList* actual = NULL; |