[asterisk-commits] ivaxer: branch ivaxer/ast_storage r274090 - /team/ivaxer/ast_storage/res/

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Tue Jul 6 04:13:25 CDT 2010


Author: ivaxer
Date: Tue Jul  6 04:13:22 2010
New Revision: 274090

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=274090
Log:
bug fixes in create/release functions
- added "creation_test" to test creation/release functions
- added error logging in create functions
- fixed misc bugs

Modified:
    team/ivaxer/ast_storage/res/res_storage_odbc.c

Modified: team/ivaxer/ast_storage/res/res_storage_odbc.c
URL: http://svnview.digium.com/svn/asterisk/team/ivaxer/ast_storage/res/res_storage_odbc.c?view=diff&rev=274090&r1=274089&r2=274090
==============================================================================
--- team/ivaxer/ast_storage/res/res_storage_odbc.c (original)
+++ team/ivaxer/ast_storage/res/res_storage_odbc.c Tue Jul  6 04:13:22 2010
@@ -37,7 +37,7 @@
 #include "asterisk/res_odbc.h"
 #include "asterisk/app.h"
 #include "asterisk/config.h"
-#include "asterisk/cli.h"
+#include "asterisk/test.h"
 #include <unistd.h>
 #include <sys/types.h>
 #include <sys/stat.h>
@@ -101,19 +101,22 @@
 	SQLHSTMT stmt = NULL;
 	SQLLEN sqlptr;
 
-	AST_NONSTANDARD_APP_ARGS(args, tmp, '/');
-
-	pathname_len = sizeof(char) * strlen(args.pathname);
-
 	st = ast_calloc(1, sizeof(struct ast_storage));
 	if (!st) {
 		return NULL;
 	}
 
 	if (ast_strlen_zero(uri)) {
-		se_release(st);
-		return NULL;
-	}
+		ast_log(LOG_ERROR, "Invalid request uri.\n");
+		se_release(st);
+		return NULL;
+	}
+
+	ast_copy_string(tmp, uri, sizeof(tmp));
+
+	AST_NONSTANDARD_APP_ARGS(args, tmp, '/');
+
+	pathname_len = sizeof(char) * strlen(args.pathname);
 
 	pvt = ast_calloc(1, sizeof(struct odbc_storage_pvt) + pathname_len);
 	if (!pvt) {
@@ -123,16 +126,16 @@
 
 	st->storage_pvt = (void *)pvt;
 	st->be = &odbc_se;
-	ast_copy_string(tmp, uri, sizeof(tmp));
 
 	AST_RWLIST_HEAD_INIT(&pvt->columns);
 
 	ast_copy_string(pvt->odbc_class, args.class, sizeof(pvt->odbc_class));
 	ast_copy_string(pvt->tablename, args.tablename, sizeof(pvt->tablename));
-	ast_copy_string(pvt->path, args.pathname, pathname_len);
+	strcpy(pvt->path, args.pathname);
 
 	pvt->conn = ast_odbc_request_obj(pvt->odbc_class, 0);
 	if (!pvt->conn) {
+		ast_log(LOG_ERROR, "Retrieving a connected ODBC object (ast_odbc_request_obj) failed.\n");
 		se_release(st);
 		return NULL;
 	}
@@ -163,7 +166,7 @@
 			return NULL;
 		}
 
-		ast_copy_string(entry->name, columnname, columnname_len);
+		strcpy(entry->name, columnname);
 
 		SQLGetData(stmt,  5, SQL_C_SHORT, &entry->type, sizeof(entry->type), NULL);
 		SQLGetData(stmt,  7, SQL_C_LONG, &entry->size, sizeof(entry->size), NULL);
@@ -230,13 +233,67 @@
 	.listdir = se_listdir,
 };
 
+#ifdef TEST_FRAMEWORK
+
+AST_TEST_DEFINE(creation_test)
+{
+	struct ast_storage *st;
+	struct odbc_storage_pvt *pvt;
+	struct columns *column;
+	int ret;
+	char uri[] = "asterisk-storage-test/storage/path";
+
+        switch (cmd) {
+        case TEST_INIT:
+                info->name = "creating_test";
+                info->category = "main/storage/odbc";
+                info->summary = "create/release test";
+                info->description =
+                        "Tests the create/release functions";
+                return AST_TEST_NOT_RUN;
+        case TEST_EXECUTE:
+                break;
+        }
+
+	st = se_create(uri);
+	if(!st) {
+		return AST_TEST_FAIL;
+	}
+
+	pvt = (struct odbc_storage_pvt *) st->storage_pvt;
+
+	AST_RWLIST_RDLOCK(&pvt->columns);
+
+	ast_test_status_update(test, "Columns of the table '%s' in the odbc_class '%s':\n", pvt->tablename, pvt->odbc_class);
+	AST_RWLIST_TRAVERSE(&pvt->columns, column, list) {
+		ast_test_status_update(test, "%s\n", column->name);
+	}
+
+	AST_RWLIST_UNLOCK(&pvt->columns);
+
+	ret = se_release(st);
+	if(ret) {
+		return AST_TEST_FAIL;
+	}
+
+        return AST_TEST_PASS;
+}
+
+#endif
+
 static int load_module(void)
 {
+#ifdef TEST_FRAMEWORK
+	AST_TEST_REGISTER(creation_test);
+#endif
 	return ast_register_storage(&odbc_se);
 }
 
 static int unload_module(void)
 {
+#ifdef TEST_FRAMEWORK
+	AST_TEST_UNREGISTER(creation_test);
+#endif
 	return ast_unregister_storage(odbc_se.name);
 }
 




More information about the asterisk-commits mailing list