diff options
author | Evan Huus <eapache@gmail.com> | 2013-04-22 15:40:48 +0000 |
---|---|---|
committer | Evan Huus <eapache@gmail.com> | 2013-04-22 15:40:48 +0000 |
commit | 4983d994757df05113333293f76781b9e17f0bf9 (patch) | |
tree | ef48dcdc88fbb95edf873d06ebecb0a3dcf95f01 /epan/wmem | |
parent | 049399b2fac1327070c75e7365c6b9500e5f6329 (diff) |
Improve wmem strbuf tests, add tests for string util. functions
svn path=/trunk/; revision=48964
Diffstat (limited to 'epan/wmem')
-rw-r--r-- | epan/wmem/wmem_test.c | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/epan/wmem/wmem_test.c b/epan/wmem/wmem_test.c index 6a40bd9623..6618a1e45e 100644 --- a/epan/wmem/wmem_test.c +++ b/epan/wmem/wmem_test.c @@ -238,6 +238,37 @@ wmem_test_allocator_strict(void) } static void +wmem_test_strutls(void) +{ + wmem_allocator_t *allocator; + const char *orig_str; + char *new_str; + + allocator = wmem_allocator_force_new(WMEM_ALLOCATOR_STRICT); + + orig_str = "TEST1"; + new_str = wmem_strdup(allocator, orig_str); + g_assert_cmpstr(new_str, ==, orig_str); + new_str[0] = 'X'; + g_assert_cmpstr(new_str, >, orig_str); + wmem_strict_check_canaries(allocator); + + orig_str = "TEST123456789"; + new_str = wmem_strndup(allocator, orig_str, 6); + g_assert_cmpstr(new_str, ==, "TEST12"); + g_assert_cmpstr(new_str, <, orig_str); + new_str[0] = 'X'; + g_assert_cmpstr(new_str, >, orig_str); + wmem_strict_check_canaries(allocator); + + new_str = wmem_strdup_printf(allocator, "abc %s %% %d", "boo", 23); + g_assert_cmpstr(new_str, ==, "abc boo % 23"); + wmem_strict_check_canaries(allocator); + + wmem_destroy_allocator(allocator); +} + +static void wmem_test_slist(void) { wmem_allocator_t *allocator; @@ -288,6 +319,7 @@ wmem_test_strbuf(void) { wmem_allocator_t *allocator; wmem_strbuf_t *strbuf; + int i; allocator = wmem_allocator_force_new(WMEM_ALLOCATOR_STRICT); @@ -317,6 +349,21 @@ wmem_test_strbuf(void) g_assert_cmpstr(wmem_strbuf_get_str(strbuf), ==, "FUZZ3abcd"); g_assert(wmem_strbuf_get_len(strbuf) == 9); + wmem_free_all(allocator); + + strbuf = wmem_strbuf_new(allocator, "TEST"); + for (i=0; i<1024; i++) { + if (g_test_rand_bit()) { + wmem_strbuf_append(strbuf, "ABC"); + } + else { + wmem_strbuf_append_printf(strbuf, "%d%d", 3, 777); + } + wmem_strict_check_canaries(allocator); + } + g_assert(strlen(wmem_strbuf_get_str(strbuf)) == + wmem_strbuf_get_len(strbuf)); + wmem_destroy_allocator(allocator); } @@ -330,6 +377,8 @@ main(int argc, char **argv) g_test_add_func("/wmem/allocator/strict", wmem_test_allocator_strict); g_test_add_func("/wmem/allocator/times", wmem_time_allocators); + g_test_add_func("/wmem/utils/strings", wmem_test_strutls); + g_test_add_func("/wmem/datastruct/slist", wmem_test_slist); g_test_add_func("/wmem/datastruct/strbuf", wmem_test_strbuf); |