diff options
author | Dario Lombardo <lomato@gmail.com> | 2017-02-06 16:51:57 +0100 |
---|---|---|
committer | Dario Lombardo <lomato@gmail.com> | 2017-02-08 12:44:26 +0000 |
commit | db5c8e1ae185730cb83d2175841e4a5314b04c32 (patch) | |
tree | 034c801dd44c6b62642f8b73679c0d869fe42ab3 /epan/wmem/wmem_test.c | |
parent | 40fe50fbed4a16b29aaafd2e46712e657d3baabd (diff) |
wmem_list: add wmem_list_insert_sorted.
This mimics the function g_list_insert_sorted.
Change-Id: I6f7ac01155588006662c8c0c138d88cea753868c
Reviewed-on: https://code.wireshark.org/review/19978
Reviewed-by: Dario Lombardo <lomato@gmail.com>
Diffstat (limited to 'epan/wmem/wmem_test.c')
-rw-r--r-- | epan/wmem/wmem_test.c | 63 |
1 files changed, 63 insertions, 0 deletions
diff --git a/epan/wmem/wmem_test.c b/epan/wmem/wmem_test.c index 96338946c5..fb46a83501 100644 --- a/epan/wmem/wmem_test.c +++ b/epan/wmem/wmem_test.c @@ -711,6 +711,18 @@ check_val_list(gpointer val, gpointer val_to_check) g_assert(val == val_to_check); } +static gint +int_compare(gconstpointer a, gconstpointer b) +{ + return GPOINTER_TO_INT(a) - GPOINTER_TO_INT(b); +} + +static gint +str_compare(gconstpointer a, gconstpointer b) +{ + return strcmp((const char*)a, (const char*)b); +} + static void wmem_test_list(void) { @@ -718,6 +730,10 @@ wmem_test_list(void) wmem_list_t *list; wmem_list_frame_t *frame; unsigned int i; + int int1; + int int2; + char* str1; + char* str2; allocator = wmem_allocator_new(WMEM_ALLOCATOR_STRICT); @@ -805,6 +821,53 @@ wmem_test_list(void) } wmem_list_foreach(list, check_val_list, GINT_TO_POINTER(1)); wmem_destroy_list(list); + + list = wmem_list_new(NULL); + wmem_list_insert_sorted(list, GINT_TO_POINTER(5), int_compare); + wmem_list_insert_sorted(list, GINT_TO_POINTER(8), int_compare); + wmem_list_insert_sorted(list, GINT_TO_POINTER(1), int_compare); + wmem_list_insert_sorted(list, GINT_TO_POINTER(2), int_compare); + wmem_list_insert_sorted(list, GINT_TO_POINTER(9), int_compare); + frame = wmem_list_head(list); + int1 = GPOINTER_TO_INT(wmem_list_frame_data(frame)); + while ((frame = wmem_list_frame_next(frame))) { + int2 = GPOINTER_TO_INT(wmem_list_frame_data(frame)); + g_assert(int1 <= int2); + int1 = int2; + } + wmem_destroy_list(list); + + list = wmem_list_new(NULL); + wmem_list_insert_sorted(list, GINT_TO_POINTER(5), int_compare); + wmem_list_insert_sorted(list, GINT_TO_POINTER(1), int_compare); + wmem_list_insert_sorted(list, GINT_TO_POINTER(7), int_compare); + wmem_list_insert_sorted(list, GINT_TO_POINTER(3), int_compare); + wmem_list_insert_sorted(list, GINT_TO_POINTER(2), int_compare); + wmem_list_insert_sorted(list, GINT_TO_POINTER(2), int_compare); + frame = wmem_list_head(list); + int1 = GPOINTER_TO_INT(wmem_list_frame_data(frame)); + while ((frame = wmem_list_frame_next(frame))) { + int2 = GPOINTER_TO_INT(wmem_list_frame_data(frame)); + g_assert(int1 <= int2); + int1 = int2; + } + wmem_destroy_list(list); + + list = wmem_list_new(NULL); + wmem_list_insert_sorted(list, "abc", str_compare); + wmem_list_insert_sorted(list, "bcd", str_compare); + wmem_list_insert_sorted(list, "aaa", str_compare); + wmem_list_insert_sorted(list, "bbb", str_compare); + wmem_list_insert_sorted(list, "zzz", str_compare); + wmem_list_insert_sorted(list, "ggg", str_compare); + frame = wmem_list_head(list); + str1 = (char*)wmem_list_frame_data(frame); + while ((frame = wmem_list_frame_next(frame))) { + str2 = (char*)wmem_list_frame_data(frame); + g_assert(strcmp(str1, str2) <= 0); + str1 = str2; + } + wmem_destroy_list(list); } void |