[asterisk-commits] rmudgett: branch rmudgett/ao2_red_black r371660 - /team/rmudgett/ao2_red_blac...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Fri Aug 24 23:55:17 CDT 2012


Author: rmudgett
Date: Fri Aug 24 23:55:13 2012
New Revision: 371660

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=371660
Log:
Initial rbtree unit tests.  Currently segfaults.

Modified:
    team/rmudgett/ao2_red_black/tests/test_astobj2.c

Modified: team/rmudgett/ao2_red_black/tests/test_astobj2.c
URL: http://svnview.digium.com/svn/asterisk/team/rmudgett/ao2_red_black/tests/test_astobj2.c?view=diff&rev=371660&r1=371659&r2=371660
==============================================================================
--- team/rmudgett/ao2_red_black/tests/test_astobj2.c (original)
+++ team/rmudgett/ao2_red_black/tests/test_astobj2.c Fri Aug 24 23:55:13 2012
@@ -37,10 +37,11 @@
 #include "asterisk/test.h"
 #include "asterisk/astobj2.h"
 
-/*! \todo BUGBUG rbtree tests not written */
+/*! \todo BUGBUG Specific rbtree tests not written */
 enum test_container_type {
 	TEST_CONTAINER_LIST,
 	TEST_CONTAINER_HASH,
+	TEST_CONTAINER_RBTREE,
 };
 
 /*!
@@ -63,6 +64,9 @@
 		break;
 	case TEST_CONTAINER_HASH:
 		c_type = "Hash";
+		break;
+	case TEST_CONTAINER_RBTREE:
+		c_type = "RBTree";
 		break;
 	}
 	return c_type;
@@ -457,6 +461,12 @@
 		}
 		c1 = ao2_t_container_alloc_hash(AO2_ALLOC_OPT_LOCK_MUTEX, 0, n_buckets,
 			test_hash_cb, use_sort ? test_sort_cb : NULL, test_cmp_cb, "test");
+		break;
+	case TEST_CONTAINER_RBTREE:
+		/* RBTrees just have one bucket. */
+		n_buckets = 1;
+		c1 = ao2_t_container_alloc_rbtree(AO2_ALLOC_OPT_LOCK_MUTEX, 0,
+			test_sort_cb, test_cmp_cb, "test");
 		break;
 	}
 	c2 = ao2_t_container_alloc(1, NULL, NULL, "test");
@@ -778,6 +788,10 @@
 		return res;
 	}
 
+	if ((res = astobj2_test_1_helper(4, TEST_CONTAINER_RBTREE, 1, 1000, test)) == AST_TEST_FAIL) {
+		return res;
+	}
+
 	return res;
 }
 
@@ -1072,6 +1086,9 @@
 		container = ao2_container_alloc_hash(AO2_ALLOC_OPT_LOCK_MUTEX, options, 5,
 			test_hash_cb, NULL, test_cmp_cb);
 		break;
+	case TEST_CONTAINER_RBTREE:
+		/* Container type must be sorted. */
+		break;
 	}
 
 	return container;
@@ -1101,6 +1118,10 @@
 	case TEST_CONTAINER_HASH:
 		container = ao2_t_container_alloc_hash(AO2_ALLOC_OPT_LOCK_MUTEX, options, 5,
 			test_hash_cb, test_sort_cb, test_cmp_cb, "test");
+		break;
+	case TEST_CONTAINER_RBTREE:
+		container = ao2_t_container_alloc_rbtree(AO2_ALLOC_OPT_LOCK_MUTEX, options,
+			test_sort_cb, test_cmp_cb, "test");
 		break;
 	}
 
@@ -1521,6 +1542,8 @@
 			test_hash_begin_backward, ARRAY_LEN(test_hash_begin_backward),
 			"Iteration (descending, insert begin)", test);
 		break;
+	case TEST_CONTAINER_RBTREE:
+		break;
 	}
 
 	/* Check container traversal directions */
@@ -1554,6 +1577,8 @@
 		res = test_ao2_callback_traversal(res, c2, OBJ_ORDER_DESCENDING, NULL, NULL,
 			test_hash_begin_backward, ARRAY_LEN(test_hash_begin_backward),
 			"Traversal (descending, insert begin)", test);
+		break;
+	case TEST_CONTAINER_RBTREE:
 		break;
 	}
 
@@ -1581,6 +1606,8 @@
 			test_hash_partial_backward, ARRAY_LEN(test_hash_partial_backward),
 			"Traversal OBJ_PARTIAL_KEY (descending)", test);
 		break;
+	case TEST_CONTAINER_RBTREE:
+		break;
 	}
 
 test_cleanup:
@@ -1709,6 +1736,7 @@
 
 	/* Check container iteration directions */
 	switch (type) {
+	case TEST_CONTAINER_RBTREE:
 	case TEST_CONTAINER_LIST:
 		res = test_ao2_iteration(res, c1, 0,
 			test_forward, ARRAY_LEN(test_forward),
@@ -1729,6 +1757,7 @@
 
 	/* Check container traversal directions */
 	switch (type) {
+	case TEST_CONTAINER_RBTREE:
 	case TEST_CONTAINER_LIST:
 		res = test_ao2_callback_traversal(res, c1, OBJ_ORDER_ASCENDING, NULL, NULL,
 			test_forward, ARRAY_LEN(test_forward),
@@ -1751,6 +1780,7 @@
 	partial = 6;
 	partial_key_match_range = 1;
 	switch (type) {
+	case TEST_CONTAINER_RBTREE:
 	case TEST_CONTAINER_LIST:
 		res = test_ao2_callback_traversal(res, c1, OBJ_PARTIAL_KEY | OBJ_ORDER_ASCENDING,
 			test_cmp_cb, &partial,
@@ -1960,6 +1990,7 @@
 
 	res = test_traversal_sorted(res, 3, TEST_CONTAINER_LIST, test);
 	res = test_traversal_sorted(res, 4, TEST_CONTAINER_HASH, test);
+	res = test_traversal_sorted(res, 5, TEST_CONTAINER_RBTREE, test);
 
 	return res;
 }




More information about the asterisk-commits mailing list