[asterisk-commits] file: branch file/sorcery r378542 - in /team/file/sorcery: include/asterisk/ ...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Fri Jan 4 06:27:04 CST 2013


Author: file
Date: Fri Jan  4 06:26:45 2013
New Revision: 378542

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=378542
Log:
Incorporate review feedback and remove white space.

Modified:
    team/file/sorcery/include/asterisk/sorcery.h
    team/file/sorcery/main/sorcery.c
    team/file/sorcery/tests/test_sorcery.c

Modified: team/file/sorcery/include/asterisk/sorcery.h
URL: http://svnview.digium.com/svn/asterisk/team/file/sorcery/include/asterisk/sorcery.h?view=diff&rev=378542&r1=378541&r2=378542
==============================================================================
--- team/file/sorcery/include/asterisk/sorcery.h (original)
+++ team/file/sorcery/include/asterisk/sorcery.h Fri Jan  4 06:26:45 2013
@@ -25,7 +25,7 @@
 /*!
  * \page AstSorcery Data Access Layer API
  *
- * Sorcery is a unifying data access layer which utilizies the configuration framework,
+ * Sorcery is a unifying data access layer which utilizes the configuration framework,
  * realtime, and astdb to allow object creation, retrieval, updating, and deletion.
  *
  * \par Initialization

Modified: team/file/sorcery/main/sorcery.c
URL: http://svnview.digium.com/svn/asterisk/team/file/sorcery/main/sorcery.c?view=diff&rev=378542&r1=378541&r2=378542
==============================================================================
--- team/file/sorcery/main/sorcery.c (original)
+++ team/file/sorcery/main/sorcery.c Fri Jan  4 06:26:45 2013
@@ -164,21 +164,21 @@
 
 static sorcery_field_handler sorcery_field_default_handler(enum aco_option_type type)
 {
-        switch(type) {
-        case OPT_BOOL_T: return bool_handler_fn;
-        case OPT_CHAR_ARRAY_T: return chararray_handler_fn;
-        case OPT_DOUBLE_T: return double_handler_fn;
-        case OPT_INT_T: return int_handler_fn;
-        case OPT_NOOP_T: return noop_handler_fn;
-        case OPT_SOCKADDR_T: return sockaddr_handler_fn;
-        case OPT_STRINGFIELD_T: return stringfield_handler_fn;
-        case OPT_UINT_T: return uint_handler_fn;
+	switch(type) {
+	case OPT_BOOL_T: return bool_handler_fn;
+	case OPT_CHAR_ARRAY_T: return chararray_handler_fn;
+	case OPT_DOUBLE_T: return double_handler_fn;
+	case OPT_INT_T: return int_handler_fn;
+	case OPT_NOOP_T: return noop_handler_fn;
+	case OPT_SOCKADDR_T: return sockaddr_handler_fn;
+	case OPT_STRINGFIELD_T: return stringfield_handler_fn;
+	case OPT_UINT_T: return uint_handler_fn;
 
 	default:
-        case OPT_CUSTOM_T: return NULL;
-        }
-
-        return NULL;
+	case OPT_CUSTOM_T: return NULL;
+	}
+
+	return NULL;
 }
 
 /*! \brief Hashing function for sorcery wizards */
@@ -724,7 +724,7 @@
 
 	if (ast_strlen_zero(id)) {
 		struct ast_uuid *uuid = ast_uuid_generate();
-		
+
 		if (!uuid) {
 			ao2_ref(details, -1);
 			return NULL;
@@ -782,7 +782,7 @@
 {
 	struct ast_sorcery_object_wizard *object_wizard = obj;
 
-	if (!object_wizard->caching) {
+	if (!object_wizard->caching || !object_wizard->wizard->create) {
 		return 0;
 	}
 
@@ -850,9 +850,13 @@
 				wizard->wizard->retrieve_multiple(sorcery, wizard->data, object, fields);
 			}
 		} else if (!ast_strlen_zero(id)) {
-			object = wizard->wizard->retrieve_id(sorcery, wizard->data, id);
+			if (wizard->wizard->retrieve_id) {
+				object = wizard->wizard->retrieve_id(sorcery, wizard->data, id);
+			}
 		} else if (fields && wizard->wizard->retrieve_fields) {
-			object = wizard->wizard->retrieve_fields(sorcery, wizard->data, fields);
+			if (wizard->wizard->retrieve_fields) {
+				object = wizard->wizard->retrieve_fields(sorcery, wizard->data, fields);
+			}
 		}
 
 		if ((flags & AST_RETRIEVE_FLAG_MULTIPLE) || !object) {
@@ -902,7 +906,8 @@
 {
 	const struct ast_sorcery_object_wizard *object_wizard = obj;
 
-	return (!object_wizard->wizard->update(object_wizard->data, arg) && !object_wizard->caching) ? CMP_MATCH | CMP_STOP : 0;
+	return (object_wizard->wizard->update && !object_wizard->wizard->update(object_wizard->data, arg) &&
+		!object_wizard->caching) ? CMP_MATCH | CMP_STOP : 0;
 }
 
 int ast_sorcery_update(const struct ast_sorcery *sorcery, void *object)
@@ -916,7 +921,7 @@
 	}
 
 	object_wizard = ao2_callback(object_type->wizards, 0, sorcery_wizard_update, object);
-	
+
 	return object_wizard ? 0 : -1;
 }
 
@@ -925,7 +930,8 @@
 {
 	const struct ast_sorcery_object_wizard *object_wizard = obj;
 
-	return (!object_wizard->wizard->delete(object_wizard->data, arg) && !object_wizard->caching) ? CMP_MATCH | CMP_STOP : 0;
+	return (object_wizard->wizard->delete && !object_wizard->wizard->delete(object_wizard->data, arg) &&
+		!object_wizard->caching) ? CMP_MATCH | CMP_STOP : 0;
 }
 
 int ast_sorcery_delete(const struct ast_sorcery *sorcery, void *object)

Modified: team/file/sorcery/tests/test_sorcery.c
URL: http://svnview.digium.com/svn/asterisk/team/file/sorcery/tests/test_sorcery.c?view=diff&rev=378542&r1=378541&r2=378542
==============================================================================
--- team/file/sorcery/tests/test_sorcery.c (original)
+++ team/file/sorcery/tests/test_sorcery.c Fri Jan  4 06:26:45 2013
@@ -79,10 +79,10 @@
 
 /*! \brief Configuration framework definition for test object */
 static struct aco_type test_object = {
-        .type = ACO_ITEM,
-        .category_match = ACO_BLACKLIST,
-        .category = "^general$",
-        .item_alloc = test_sorcery_object_alloc,
+	.type = ACO_ITEM,
+	.category_match = ACO_BLACKLIST,
+	.category = "^general$",
+	.item_alloc = test_sorcery_object_alloc,
 };
 
 /*! \brief Test structure for caching */
@@ -113,7 +113,7 @@
 
 static void *sorcery_test_retrieve_id(const struct ast_sorcery *sorcery, void *data, const char *id)
 {
-	return (cache.created && !cache.deleted) ? ast_sorcery_alloc(sorcery, "test", id) : NULL; 
+	return (cache.created && !cache.deleted) ? ast_sorcery_alloc(sorcery, "test", id) : NULL;
 }
 
 static int sorcery_test_update(void *data, void *object)
@@ -451,7 +451,7 @@
 	int res = AST_TEST_PASS;
 	RAII_VAR(struct ast_sorcery *, sorcery, NULL, ast_sorcery_unref);
 	RAII_VAR(struct test_sorcery_object *, obj, NULL, ao2_cleanup);
-	
+
 	switch (cmd) {
 	case TEST_INIT:
 		info->name = "object_alloc_without_id";
@@ -541,6 +541,9 @@
 
 	if (!(copy = ast_sorcery_copy(sorcery, obj))) {
 		ast_test_status_update(test, "Failed to create a copy of a known valid object\n");
+		res = AST_TEST_FAIL;
+	} else if (copy == obj) {
+		ast_test_status_update(test, "Created copy is actually the original object\n");
 		res = AST_TEST_FAIL;
 	} else if (copy->bob != obj->bob) {
 		ast_test_status_update(test, "Value of 'bob' on newly created copy is not the same as original\n");
@@ -675,7 +678,7 @@
 		ast_test_status_update(test, "Failed to create an object set for a known sane object\n");
 		return AST_TEST_FAIL;
 	}
-	
+
 	for (field = objset; field; field = field->next) {
 		if (!strcmp(field->name, "bob")) {
 			if (strcmp(field->value, "5")) {
@@ -942,40 +945,40 @@
 
 AST_TEST_DEFINE(changeset_create_unchanged)
 {
-        RAII_VAR(struct ast_variable *, original, NULL, ast_variables_destroy);
-        RAII_VAR(struct ast_variable *, changes, NULL, ast_variables_destroy);
+	RAII_VAR(struct ast_variable *, original, NULL, ast_variables_destroy);
+	RAII_VAR(struct ast_variable *, changes, NULL, ast_variables_destroy);
 	struct ast_variable *tmp;
 
-        switch (cmd) {
-        case TEST_INIT:
-                info->name = "changeset_create_unchanged";
-                info->category = "/main/sorcery/";
-                info->summary = "sorcery changeset creation unit test when no changes exist";
-                info->description =
-                        "Test changeset creation in sorcery when no changes actually exist";
-                return AST_TEST_NOT_RUN;
-        case TEST_EXECUTE:
-                break;
-        }
-
-        if (!(tmp = ast_variable_new("bananas", "purple", ""))) {
-                ast_test_status_update(test, "Failed to create first field for original objectset\n");
-                return AST_TEST_FAIL;
-        }
-        tmp->next = original;
-        original = tmp;
-
-        if (!(tmp = ast_variable_new("apples", "orange", ""))) {
-                ast_test_status_update(test, "Failed to create second field for original objectset\n");
-                return AST_TEST_FAIL;
-        }
-        tmp->next = original;
-        original = tmp;
-
-        if ((changes = ast_sorcery_changeset_create(original, original))) {
-                ast_test_status_update(test, "Created a changeset when no changes actually exist\n");
-                return AST_TEST_FAIL;
-        }
+	switch (cmd) {
+	case TEST_INIT:
+		info->name = "changeset_create_unchanged";
+		info->category = "/main/sorcery/";
+		info->summary = "sorcery changeset creation unit test when no changes exist";
+		info->description =
+			"Test changeset creation in sorcery when no changes actually exist";
+		return AST_TEST_NOT_RUN;
+	case TEST_EXECUTE:
+		break;
+	}
+
+	if (!(tmp = ast_variable_new("bananas", "purple", ""))) {
+		ast_test_status_update(test, "Failed to create first field for original objectset\n");
+		return AST_TEST_FAIL;
+	}
+	tmp->next = original;
+	original = tmp;
+
+	if (!(tmp = ast_variable_new("apples", "orange", ""))) {
+		ast_test_status_update(test, "Failed to create second field for original objectset\n");
+		return AST_TEST_FAIL;
+	}
+	tmp->next = original;
+	original = tmp;
+
+	if ((changes = ast_sorcery_changeset_create(original, original))) {
+		ast_test_status_update(test, "Created a changeset when no changes actually exist\n");
+		return AST_TEST_FAIL;
+	}
 
 	return AST_TEST_PASS;
 }
@@ -1012,8 +1015,8 @@
 		return AST_TEST_FAIL;
 	}
 
-        ast_sorcery_object_field_register(sorcery, "test", "bob", "5", OPT_UINT_T, 0, FLDSET(struct test_sorcery_object, bob));
-        ast_sorcery_object_field_register(sorcery, "test", "joe", "10", OPT_UINT_T, 0, FLDSET(struct test_sorcery_object, joe));
+	ast_sorcery_object_field_register(sorcery, "test", "bob", "5", OPT_UINT_T, 0, FLDSET(struct test_sorcery_object, bob));
+	ast_sorcery_object_field_register(sorcery, "test", "joe", "10", OPT_UINT_T, 0, FLDSET(struct test_sorcery_object, joe));
 
 	if (!(obj = ast_sorcery_alloc(sorcery, "test", "blah"))) {
 		ast_test_status_update(test, "Failed to allocate a known object type\n");
@@ -1116,7 +1119,7 @@
 		ast_test_status_update(test, "Failed to open sorcery structure\n");
 		return AST_TEST_FAIL;
 	}
-	
+
 	if (ast_sorcery_apply_default(sorcery, "test", "memory", NULL)) {
 		ast_test_status_update(test, "Failed to set a known wizard as a default\n");
 		return AST_TEST_FAIL;
@@ -1520,16 +1523,16 @@
 	int res = AST_TEST_FAIL;
 
 	switch (cmd) {
-        case TEST_INIT:
-                info->name = "caching_wizard_behavior";
-                info->category = "/main/sorcery/";
-                info->summary = "sorcery caching wizard behavior unit test";
-                info->description =
-                        "Test internal behavior of caching wizards";
-                return AST_TEST_NOT_RUN;
-        case TEST_EXECUTE:
-                break;
-        }
+	case TEST_INIT:
+		info->name = "caching_wizard_behavior";
+		info->category = "/main/sorcery/";
+		info->summary = "sorcery caching wizard behavior unit test";
+		info->description =
+			"Test internal behavior of caching wizards";
+		return AST_TEST_NOT_RUN;
+	case TEST_EXECUTE:
+		break;
+	}
 
 	if (!(config = ast_config_load2("sorcery.conf", "test_sorcery_cache", flags))) {
 		ast_test_status_update(test, "Sorcery configuration file not present - skipping caching_wizard_behavior test\n");
@@ -1538,10 +1541,10 @@
 
 	ast_config_destroy(config);
 
-        if (ast_sorcery_wizard_register(&test_wizard, NULL)) {
-                ast_test_status_update(test, "Failed to register a perfectly valid sorcery wizard\n");
-                return AST_TEST_FAIL;
-        }
+	if (ast_sorcery_wizard_register(&test_wizard, NULL)) {
+		ast_test_status_update(test, "Failed to register a perfectly valid sorcery wizard\n");
+		return AST_TEST_FAIL;
+	}
 
 	if (!(sorcery = ast_sorcery_open())) {
 		ast_test_status_update(test, "Failed to open sorcery structure\n");




More information about the asterisk-commits mailing list