aboutsummaryrefslogtreecommitdiffstats
path: root/epan/wmem/wmem_test.c
diff options
context:
space:
mode:
authorEvan Huus <eapache@gmail.com>2013-07-06 17:47:32 +0000
committerEvan Huus <eapache@gmail.com>2013-07-06 17:47:32 +0000
commite1268955c7f11edc704b036e9deb18d0fe454acf (patch)
tree88d3ac614ccc62edc0577095e530e68219245cd0 /epan/wmem/wmem_test.c
parent519c5affa2f9713a9f196c78ebf44b2308ff4ef1 (diff)
Add wmem_array_sort() which just hands off to the standard library's qsort().
svn path=/trunk/; revision=50411
Diffstat (limited to 'epan/wmem/wmem_test.c')
-rw-r--r--epan/wmem/wmem_test.c32
1 files changed, 31 insertions, 1 deletions
diff --git a/epan/wmem/wmem_test.c b/epan/wmem/wmem_test.c
index cf43a3acff..06a7769d7e 100644
--- a/epan/wmem/wmem_test.c
+++ b/epan/wmem/wmem_test.c
@@ -94,6 +94,17 @@ wmem_test_rand_string(wmem_allocator_t *allocator, gint minlen, gint maxlen)
return str;
}
+int
+wmem_test_compare_guint32(const void *a, const void *b)
+{
+ guint32 l, r;
+
+ l = *(guint32*)a;
+ r = *(guint32*)b;
+
+ return l - r;
+}
+
/* Some helpers for properly testing callback functionality */
wmem_allocator_t *expected_allocator;
void *expected_user_data;
@@ -442,7 +453,7 @@ wmem_test_array(void)
{
wmem_allocator_t *allocator;
wmem_array_t *array;
- unsigned int i, j;
+ unsigned int i, j, k;
guint32 val, *buf;
guint32 vals[8];
@@ -486,6 +497,25 @@ wmem_test_array(void)
}
}
+ wmem_array_sort(array, wmem_test_compare_guint32);
+ for (i=0, k=0; i<8; i++) {
+ for (j=0; j<=i; j++, k++) {
+ val = *(guint32*)wmem_array_index(array, k);
+ g_assert(val == i);
+ }
+ }
+ for (j=k; k<8*(CONTAINER_ITERS+1)-j; k++) {
+ val = *(guint32*)wmem_array_index(array, k);
+ g_assert(val == ((k-j)/8)+8);
+ }
+ for (i=0; i<7; i++) {
+ for (j=0; j<7-i; j++, k++) {
+ val = *(guint32*)wmem_array_index(array, k);
+ g_assert(val == CONTAINER_ITERS+i);
+ }
+ }
+ g_assert(k == wmem_array_get_count(array));
+
wmem_destroy_allocator(allocator);
}