aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEvan Huus <eapache@gmail.com>2013-04-10 14:11:13 +0000
committerEvan Huus <eapache@gmail.com>2013-04-10 14:11:13 +0000
commit29b61239bc6fc8211a02a7ecc153e546f60b9ce0 (patch)
treecda8b00b40247abc3f7a749e25c9903b06c5af85
parentb85877977ab4b8ba385d38e3e22bc2e1674fdc9d (diff)
Add wmem tests for the singly-linked list implementation.
svn path=/trunk/; revision=48807
-rw-r--r--epan/wmem/wmem_test.c51
1 files changed, 50 insertions, 1 deletions
diff --git a/epan/wmem/wmem_test.c b/epan/wmem/wmem_test.c
index c3617818fa..29c5961787 100644
--- a/epan/wmem/wmem_test.c
+++ b/epan/wmem/wmem_test.c
@@ -34,6 +34,7 @@
#define MAX_SIMULTANEOUS_ALLOCS 1024
#define MAX_ALLOC_SIZE (1024*64)
+#define LIST_ITERS 10000
typedef void (*wmem_verify_func)(wmem_allocator_t *allocator);
@@ -214,7 +215,7 @@ wmem_time_allocators(void)
wmem_time_allocator(WMEM_ALLOCATOR_BLOCK);
block_time = g_test_timer_elapsed();
- printf("(simple: %lf; block: %lf)", simple_time, block_time);
+ printf("(simple: %lf; block: %lf) ", simple_time, block_time);
g_assert(simple_time > block_time);
}
@@ -236,6 +237,52 @@ wmem_test_allocator_strict(void)
wmem_test_allocator(WMEM_ALLOCATOR_STRICT, &wmem_strict_check_canaries);
}
+static void
+wmem_test_slist(void)
+{
+ wmem_allocator_t *allocator;
+ wmem_slist_t *slist;
+ wmem_slist_frame_t *frame;
+ unsigned int i;
+
+ allocator = wmem_allocator_force_new(WMEM_ALLOCATOR_STRICT);
+
+ slist = wmem_slist_new(allocator);
+ g_assert(slist);
+ g_assert(wmem_slist_count(slist) == 0);
+
+ frame = wmem_slist_front(slist);
+ g_assert(frame == NULL);
+
+ for (i=0; i<LIST_ITERS; i++) {
+ wmem_slist_prepend(slist, GINT_TO_POINTER(i));
+ g_assert(wmem_slist_count(slist) == i+1);
+
+ frame = wmem_slist_front(slist);
+ g_assert(frame);
+ g_assert(wmem_slist_frame_data(frame) == GINT_TO_POINTER(i));
+ }
+
+ i = LIST_ITERS - 1;
+ frame = wmem_slist_front(slist);
+ while (frame) {
+ g_assert(wmem_slist_frame_data(frame) == GINT_TO_POINTER(i));
+ i--;
+ frame = wmem_slist_frame_next(frame);
+ }
+
+ i = LIST_ITERS - 2;
+ while (wmem_slist_count(slist) > 1) {
+ wmem_slist_remove(slist, GINT_TO_POINTER(i));
+ i--;
+ }
+ wmem_slist_remove(slist, GINT_TO_POINTER(LIST_ITERS - 1));
+ g_assert(wmem_slist_count(slist) == 0);
+ g_assert(wmem_slist_front(slist) == NULL);
+
+ wmem_destroy_allocator(allocator);
+}
+
int
main(int argc, char **argv)
{
@@ -246,6 +293,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/datastruct/slist", wmem_test_slist);
+
return g_test_run();
}