[asterisk-commits] dvossel: branch dvossel/test_api r234057 - /team/dvossel/test_api/main/test.c

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Wed Dec 9 17:57:12 CST 2009


Author: dvossel
Date: Wed Dec  9 17:57:09 2009
New Revision: 234057

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=234057
Log:
ast_test_register function

created ast_test_register function, includes some debug
code for developer purposes that will be removed soon

Modified:
    team/dvossel/test_api/main/test.c

Modified: team/dvossel/test_api/main/test.c
URL: http://svnview.digium.com/svn/asterisk/team/dvossel/test_api/main/test.c?view=diff&rev=234057&r1=234056&r2=234057
==============================================================================
--- team/dvossel/test_api/main/test.c (original)
+++ team/dvossel/test_api/main/test.c Wed Dec  9 17:57:09 2009
@@ -31,7 +31,6 @@
 #include "asterisk/logger.h"
 #include "asterisk/linkedlists.h"
 #include "asterisk/utils.h"
-
 
 enum ast_test_result_state {
 	AST_TEST_NOT_RUN = 0,
@@ -70,8 +69,26 @@
 static int test_insert(struct ast_test *test);
 static struct ast_test *test_remove(ast_test_cb_t *cb);
 
+/* todohere remove, this is just for debuggin purposes during initial development */
+static void tests_print(void)
+{
+	struct ast_test *cur = NULL;
+	AST_LIST_LOCK(&tests);
+	AST_LIST_TRAVERSE_SAFE_BEGIN(&tests, cur, entry) {
+		ast_log(LOG_NOTICE, "Name %s Catagory %s \n", cur->name, cur->catagory);
+	}
+	AST_LIST_TRAVERSE_SAFE_END;
+	AST_LIST_UNLOCK(&tests);
+}
+
 int ast_test_init()
 {
+	//todohere register cli commands?!
+	//todohere remove these tests, they are just to verify list order, registration, and removal
+
+	tests_print();
+	//todohere end of tests
+
 	return 0;
 }
 
@@ -135,11 +152,26 @@
 {
 	struct ast_test *cur = NULL;
 	int res = 0;
-
+	int i = 0;
+
+	/* This is a slow operation that may need to be optimized in the future
+	 * as the test framework expands.  At the moment we are doing string
+	 * comparisons on every item within the list to insert in sorted order. */
 	AST_LIST_LOCK(&tests);
 	AST_LIST_TRAVERSE_SAFE_BEGIN(&tests, cur, entry) {
-		//todohere compare test to cur and see what's up.  
-		//todohere if dup, res = -1 and break
+		if ((i = strcmp(test->catagory, cur->catagory)) < 0) {
+			AST_LIST_INSERT_BEFORE_CURRENT(test, entry);
+			break;
+		} else if (!i) {  /* same catagory, now insert by name within that catagory*/
+			if ((i = strcmp(test->name, cur->name)) < 0) {
+				AST_LIST_INSERT_BEFORE_CURRENT(test, entry);
+				break;
+			} else if (!i) {
+				/* Error, duplicate found */
+				res = -1;
+				break;
+			}
+		}
 	}
 	AST_LIST_TRAVERSE_SAFE_END;
 	AST_LIST_UNLOCK(&tests);




More information about the asterisk-commits mailing list