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

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Wed Jan 23 08:04:06 CST 2013


Author: file
Date: Wed Jan 23 08:04:01 2013
New Revision: 380001

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=380001
Log:
Incorporate review feedback.

Modified:
    team/file/sorcery/include/asterisk/sorcery.h
    team/file/sorcery/main/sorcery.c
    team/file/sorcery/res/res_sorcery_config.c
    team/file/sorcery/res/res_sorcery_memory.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=380001&r1=380000&r2=380001
==============================================================================
--- team/file/sorcery/include/asterisk/sorcery.h (original)
+++ team/file/sorcery/include/asterisk/sorcery.h Wed Jan 23 08:04:01 2013
@@ -1,7 +1,7 @@
 /*
  * Asterisk -- An open source telephony toolkit.
  *
- * Copyright (C) 2012, Digium, Inc.
+ * Copyright (C) 2012 - 2013, Digium, Inc.
  *
  * Joshua Colp <jcolp at digium.com>
  *
@@ -391,6 +391,9 @@
  *
  * \retval 0 success
  * \retval -1 failure
+ *
+ * \note This operation is *not* atomic. If this fails it is possible for the object to be left with a partially
+ *       applied object set.
  */
 int ast_sorcery_objectset_apply(const struct ast_sorcery *sorcery, void *object, struct ast_variable *objectset);
 
@@ -447,7 +450,7 @@
  struct ast_variable *ast_sorcery_diff(const struct ast_sorcery *sorcery, const void *original, const void *modified);
 
 /*!
- * \brief Persist an object
+ * \brief Create and potentially persist an object using an available wizard
  *
  * \param sorcery Pointer to a sorcery structure
  * \param object Pointer to a sorcery object

Modified: team/file/sorcery/main/sorcery.c
URL: http://svnview.digium.com/svn/asterisk/team/file/sorcery/main/sorcery.c?view=diff&rev=380001&r1=380000&r2=380001
==============================================================================
--- team/file/sorcery/main/sorcery.c (original)
+++ team/file/sorcery/main/sorcery.c Wed Jan 23 08:04:01 2013
@@ -1,7 +1,7 @@
 /*
  * Asterisk -- An open source telephony toolkit.
  *
- * Copyright (C) 2012, Digium, Inc.
+ * Copyright (C) 2012 - 2013, Digium, Inc.
  *
  * Joshua Colp <jcolp at digium.com>
  *
@@ -248,9 +248,7 @@
 	ast_verb(2, "Sorcery registered wizard '%s'\n", interface->name);
 
 done:
-	if (wizard) {
-		ao2_ref(wizard, -1);
-	}
+	ao2_cleanup(wizard);
 	ao2_unlock(wizards);
 
 	return res;
@@ -373,7 +371,9 @@
 		object_wizard->wizard->close(object_wizard->data);
 	}
 
-	ast_module_unref(object_wizard->wizard->module);
+	if (object_wizard->wizard) {
+		ast_module_unref(object_wizard->wizard->module);
+	}
 }
 
 /*! \brief Internal function which creates an object type and adds a wizard mapping */
@@ -381,10 +381,10 @@
 {
 	RAII_VAR(struct ast_sorcery_object_type *, object_type,  ao2_find(sorcery->types, type, OBJ_KEY), ao2_cleanup);
 	RAII_VAR(struct ast_sorcery_wizard *, wizard, ao2_find(wizards, name, OBJ_KEY), ao2_cleanup);
-	RAII_VAR(struct ast_sorcery_object_wizard *, object_wizard, NULL, ao2_cleanup);
+	RAII_VAR(struct ast_sorcery_object_wizard *, object_wizard, ao2_alloc(sizeof(*object_wizard), sorcery_object_wizard_destructor), ao2_cleanup);
 	int created = 0;
 
-	if (!wizard) {
+	if (!wizard || !object_wizard) {
 		return -1;
 	}
 
@@ -393,10 +393,6 @@
 			return -1;
 		}
 		created = 1;
-	}
-
-	if (!(object_wizard = ao2_alloc(sizeof(*object_wizard), sorcery_object_wizard_destructor))) {
-		return -1;
 	}
 
 	if (wizard->open && !(object_wizard->data = wizard->open(data))) {
@@ -429,8 +425,10 @@
 	}
 
 	for (mapping = ast_variable_browse(config, name); mapping; mapping = mapping->next) {
-		char *options = ast_strdupa(mapping->name), *name = strsep(&options, "/");
-		char *data = ast_strdupa(mapping->value), *wizard = strsep(&data, ",");
+		RAII_VAR(char *, mapping_name, ast_strdup(mapping->name), ast_free);
+		RAII_VAR(char *, mapping_value, ast_strdup(mapping->value), ast_free);
+		char *options = mapping_name, *name = strsep(&options, "/");
+		char *data = mapping_value, *wizard = strsep(&data, ",");
 		unsigned int caching = 0;
 
 		/* If no wizard exists just skip, nothing we can do */
@@ -690,6 +688,11 @@
 	struct ast_variable *changes = NULL;
 	int res = 0;
 
+	/* Unless the ast_variable list changes when examined... it can't differ from itself */
+	if (original == modified) {
+		return NULL;
+	}
+
 	for (field = modified; field; field = field->next) {
 		const struct ast_variable *old = sorcery_find_field(original, field->name);
 
@@ -814,7 +817,7 @@
 	for (param = va_arg(args, enum ast_sorcery_retrieve_params);
 	     param != AST_RETRIEVE_PARAM_END;
 	     param = va_arg(args, enum ast_sorcery_retrieve_params)) {
-		if (param == AST_RETRIEVE_PARAM_ID) {
+		if (param == AST_RETRIEVE_PARAM_ID && !id) {
 			id = va_arg(args, const char *);
 		} else if (param == AST_RETRIEVE_PARAM_FIELD) {
 			const char *name = va_arg(args, const char *), *value = va_arg(args, const char *);

Modified: team/file/sorcery/res/res_sorcery_config.c
URL: http://svnview.digium.com/svn/asterisk/team/file/sorcery/res/res_sorcery_config.c?view=diff&rev=380001&r1=380000&r2=380001
==============================================================================
--- team/file/sorcery/res/res_sorcery_config.c (original)
+++ team/file/sorcery/res/res_sorcery_config.c Wed Jan 23 08:04:01 2013
@@ -1,7 +1,7 @@
 /*
  * Asterisk -- An open source telephony toolkit.
  *
- * Copyright (C) 2012, Digium, Inc.
+ * Copyright (C) 2012 - 2013, Digium, Inc.
  *
  * Joshua Colp <jcolp at digium.com>
  *

Modified: team/file/sorcery/res/res_sorcery_memory.c
URL: http://svnview.digium.com/svn/asterisk/team/file/sorcery/res/res_sorcery_memory.c?view=diff&rev=380001&r1=380000&r2=380001
==============================================================================
--- team/file/sorcery/res/res_sorcery_memory.c (original)
+++ team/file/sorcery/res/res_sorcery_memory.c Wed Jan 23 08:04:01 2013
@@ -1,7 +1,7 @@
 /*
  * Asterisk -- An open source telephony toolkit.
  *
- * Copyright (C) 2012, Digium, Inc.
+ * Copyright (C) 2012 - 2013, Digium, Inc.
  *
  * Joshua Colp <jcolp at digium.com>
  *

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=380001&r1=380000&r2=380001
==============================================================================
--- team/file/sorcery/tests/test_sorcery.c (original)
+++ team/file/sorcery/tests/test_sorcery.c Wed Jan 23 08:04:01 2013
@@ -1,7 +1,7 @@
 /*
  * Asterisk -- An open source telephony toolkit.
  *
- * Copyright (C) 2012, Digium, Inc.
+ * Copyright (C) 2012 - 2013, Digium, Inc.
  *
  * Joshua Colp <jcolp at digium.com>
  *
@@ -129,6 +129,26 @@
 	.delete = sorcery_test_delete,
 };
 
+static struct ast_sorcery *alloc_and_initialize_sorcery(void)
+{
+	struct ast_sorcery *sorcery;
+
+        if (!(sorcery = ast_sorcery_open())) {
+		return NULL;
+        }
+
+        if (ast_sorcery_apply_default(sorcery, "test", "memory", NULL) ||
+	    ast_sorcery_object_register(sorcery, "test", test_sorcery_object_alloc, NULL, NULL)) {
+		ast_sorcery_unref(sorcery);
+		return NULL;
+        }
+
+        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));
+
+	return sorcery;
+}
+
 AST_TEST_DEFINE(wizard_registration)
 {
 	switch (cmd) {
@@ -252,6 +272,12 @@
 		return AST_TEST_NOT_RUN;
 	}
 
+	if (!ast_category_get(config, "test_sorcery")) {
+		ast_test_status_update(test, "Sorcery configuration file does not have test_sorcery section\n");
+		ast_config_destroy(config);
+		return AST_TEST_NOT_RUN;
+	}
+
 	ast_config_destroy(config);
 
 	if (!(sorcery = ast_sorcery_open())) {
@@ -397,23 +423,10 @@
 		break;
 	}
 
-	if (!(sorcery = ast_sorcery_open())) {
-		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;
-	}
-
-	if (ast_sorcery_object_register(sorcery, "test", test_sorcery_object_alloc, NULL, NULL)) {
-		ast_test_status_update(test, "Failed to register object type\n");
-		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));
+	if (!(sorcery = alloc_and_initialize_sorcery())) {
+		ast_test_status_update(test, "Failed to open sorcery structure\n");
+		return AST_TEST_FAIL;
+	}
 
 	if (!(obj = ast_sorcery_alloc(sorcery, "test", "blah"))) {
 		ast_test_status_update(test, "Failed to allocate a known object type\n");
@@ -456,23 +469,10 @@
 		break;
 	}
 
-	if (!(sorcery = ast_sorcery_open())) {
-		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;
-	}
-
-	if (ast_sorcery_object_register(sorcery, "test", test_sorcery_object_alloc, NULL, NULL)) {
-		ast_test_status_update(test, "Failed to register object type\n");
-		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));
+	if (!(sorcery = alloc_and_initialize_sorcery())) {
+		ast_test_status_update(test, "Failed to open sorcery structure\n");
+		return AST_TEST_FAIL;
+	}
 
 	if (!(obj = ast_sorcery_alloc(sorcery, "test", NULL))) {
 		ast_test_status_update(test, "Failed to allocate a known object type\n");
@@ -505,23 +505,10 @@
 		break;
 	}
 
-	if (!(sorcery = ast_sorcery_open())) {
-		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;
-	}
-
-	if (ast_sorcery_object_register(sorcery, "test", test_sorcery_object_alloc, NULL, NULL)) {
-		ast_test_status_update(test, "Failed to register object type\n");
-		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));
+	if (!(sorcery = alloc_and_initialize_sorcery())) {
+		ast_test_status_update(test, "Failed to open sorcery structure\n");
+		return AST_TEST_FAIL;
+	}
 
 	if (!(obj = ast_sorcery_alloc(sorcery, "test", "blah"))) {
 		ast_test_status_update(test, "Failed to allocate a known object type\n");
@@ -569,23 +556,10 @@
 	       break;
        }
 
-       if (!(sorcery = ast_sorcery_open())) {
+       if (!(sorcery = alloc_and_initialize_sorcery())) {
 	       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;
-       }
-
-       if (ast_sorcery_object_register(sorcery, "test", test_sorcery_object_alloc, NULL, NULL)) {
-	       ast_test_status_update(test, "Failed to register object type\n");
-	       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));
 
        if (!(obj1 = ast_sorcery_alloc(sorcery, "test", "blah"))) {
 	       ast_test_status_update(test, "Failed to allocate a known object type\n");
@@ -643,23 +617,10 @@
 		break;
 	}
 
-	if (!(sorcery = ast_sorcery_open())) {
-		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;
-	}
-
-	if (ast_sorcery_object_register(sorcery, "test", test_sorcery_object_alloc, NULL, NULL)) {
-		ast_test_status_update(test, "Failed to register object type\n");
-		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));
+	if (!(sorcery = alloc_and_initialize_sorcery())) {
+		ast_test_status_update(test, "Failed to open sorcery structure\n");
+		return AST_TEST_FAIL;
+	}
 
 	if (!(obj = ast_sorcery_alloc(sorcery, "test", "blah"))) {
 		ast_test_status_update(test, "Failed to allocate a known object type\n");
@@ -710,23 +671,10 @@
 		break;
 	}
 
-	if (!(sorcery = ast_sorcery_open())) {
-		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;
-	}
-
-	if (ast_sorcery_object_register(sorcery, "test", test_sorcery_object_alloc, NULL, NULL)) {
-		ast_test_status_update(test, "Failed to register object type\n");
-		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));
+	if (!(sorcery = alloc_and_initialize_sorcery())) {
+		ast_test_status_update(test, "Failed to open sorcery structure\n");
+		return AST_TEST_FAIL;
+	}
 
 	if (!(obj = ast_sorcery_alloc(sorcery, "test", "blah"))) {
 		ast_test_status_update(test, "Failed to allocate a known object type\n");
@@ -765,23 +713,10 @@
 		break;
 	}
 
-	if (!(sorcery = ast_sorcery_open())) {
-		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;
-	}
-
-	if (ast_sorcery_object_register(sorcery, "test", test_sorcery_object_alloc, NULL, NULL)) {
-		ast_test_status_update(test, "Failed to register object type\n");
-		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));
+	if (!(sorcery = alloc_and_initialize_sorcery())) {
+		ast_test_status_update(test, "Failed to open sorcery structure\n");
+		return AST_TEST_FAIL;
+	}
 
 	if (!(obj = ast_sorcery_alloc(sorcery, "test", "blah"))) {
 		ast_test_status_update(test, "Failed to allocate a known object type\n");
@@ -824,7 +759,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;
@@ -939,6 +874,7 @@
 {
 	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 *, same, NULL, ast_variables_destroy);
 	struct ast_variable *tmp;
 
 	switch (cmd) {
@@ -972,6 +908,25 @@
 		return AST_TEST_FAIL;
 	}
 
+	if (!(tmp = ast_variable_new("bananas", "purple", ""))) {
+		ast_test_status_update(test, "Failed to create first field for same objectset\n");
+		return AST_TEST_FAIL;
+	}
+	tmp->next = same;
+	same = tmp;
+
+	if (!(tmp = ast_variable_new("apples", "orange", ""))) {
+		ast_test_status_update(test, "Failed to create second field for same objectset\n");
+		return AST_TEST_FAIL;
+	}
+	tmp->next = same;
+	same = tmp;
+
+	if ((changes = ast_sorcery_changeset_create(original, same))) {
+		ast_test_status_update(test, "Created a changeset between two different objectsets when no changes actually exist\n");
+		return AST_TEST_FAIL;
+	}
+
 	return AST_TEST_PASS;
 }
 
@@ -992,23 +947,10 @@
 		break;
 	}
 
-	if (!(sorcery = ast_sorcery_open())) {
-		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;
-	}
-
-	if (ast_sorcery_object_register(sorcery, "test", test_sorcery_object_alloc, NULL, NULL)) {
-		ast_test_status_update(test, "Failed to register object type\n");
-		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));
+	if (!(sorcery = alloc_and_initialize_sorcery())) {
+		ast_test_status_update(test, "Failed to open sorcery structure\n");
+		return AST_TEST_FAIL;
+	}
 
 	if (!(obj = ast_sorcery_alloc(sorcery, "test", "blah"))) {
 		ast_test_status_update(test, "Failed to allocate a known object type\n");
@@ -1040,18 +982,8 @@
 		break;
 	}
 
-	if (!(sorcery = ast_sorcery_open())) {
-		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;
-	}
-
-	if (ast_sorcery_object_register(sorcery, "test", test_sorcery_object_alloc, NULL, NULL)) {
-		ast_test_status_update(test, "Failed to register object type\n");
+	if (!(sorcery = alloc_and_initialize_sorcery())) {
+		ast_test_status_update(test, "Failed to open sorcery structure\n");
 		return AST_TEST_FAIL;
 	}
 
@@ -1107,23 +1039,10 @@
 		break;
 	}
 
-	if (!(sorcery = ast_sorcery_open())) {
-		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;
-	}
-
-	if (ast_sorcery_object_register(sorcery, "test", test_sorcery_object_alloc, NULL, NULL)) {
-		ast_test_status_update(test, "Failed to register object type\n");
-		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));
+	if (!(sorcery = alloc_and_initialize_sorcery())) {
+		ast_test_status_update(test, "Failed to open sorcery structure\n");
+		return AST_TEST_FAIL;
+	}
 
 	if (!(obj = ast_sorcery_alloc(sorcery, "test", "blah"))) {
 		ast_test_status_update(test, "Failed to allocate a known object type\n");
@@ -1172,18 +1091,8 @@
 		break;
 	}
 
-	if (!(sorcery = ast_sorcery_open())) {
-		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;
-	}
-
-	if (ast_sorcery_object_register(sorcery, "test", test_sorcery_object_alloc, NULL, NULL)) {
-		ast_test_status_update(test, "Failed to register object type\n");
+	if (!(sorcery = alloc_and_initialize_sorcery())) {
+		ast_test_status_update(test, "Failed to open sorcery structure\n");
 		return AST_TEST_FAIL;
 	}
 
@@ -1238,23 +1147,10 @@
 		break;
 	}
 
-	if (!(sorcery = ast_sorcery_open())) {
-		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;
-	}
-
-	if (ast_sorcery_object_register(sorcery, "test", test_sorcery_object_alloc, NULL, NULL)) {
-		ast_test_status_update(test, "Failed to register object type\n");
-		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));
+	if (!(sorcery = alloc_and_initialize_sorcery())) {
+		ast_test_status_update(test, "Failed to open sorcery structure\n");
+		return AST_TEST_FAIL;
+	}
 
 	if (!(obj = ast_sorcery_alloc(sorcery, "test", "blah"))) {
 		ast_test_status_update(test, "Failed to allocate a known object type\n");
@@ -1271,7 +1167,7 @@
 	if (!(objects = ast_sorcery_retrieve(sorcery, "test", AST_RETRIEVE_FLAG_MULTIPLE, AST_RETRIEVE_PARAM_FIELD, "joe", "6", AST_RETRIEVE_PARAM_END))) {
 		ast_test_status_update(test, "Failed to retrieve a container of all objects\n");
 		return AST_TEST_FAIL;
-	} else if (!ao2_container_count(objects)) {
+	} else if (ao2_container_count(objects) != 1) {
 		ast_test_status_update(test, "Received a container with no objects in it when there should be some\n");
 		return AST_TEST_FAIL;
 	}
@@ -1307,23 +1203,10 @@
 		break;
 	}
 
-	if (!(sorcery = ast_sorcery_open())) {
-		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;
-	}
-
-	if (ast_sorcery_object_register(sorcery, "test", test_sorcery_object_alloc, NULL, NULL)) {
-		ast_test_status_update(test, "Failed to register object type\n");
-		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));
+	if (!(sorcery = alloc_and_initialize_sorcery())) {
+		ast_test_status_update(test, "Failed to open sorcery structure\n");
+		return AST_TEST_FAIL;
+	}
 
 	if (!(obj = ast_sorcery_alloc(sorcery, "test", "blah"))) {
 		ast_test_status_update(test, "Failed to allocate a known object type\n");
@@ -1375,18 +1258,8 @@
 		break;
 	}
 
-	if (!(sorcery = ast_sorcery_open())) {
-		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;
-	}
-
-	if (ast_sorcery_object_register(sorcery, "test", test_sorcery_object_alloc, NULL, NULL)) {
-		ast_test_status_update(test, "Failed to register object type\n");
+	if (!(sorcery = alloc_and_initialize_sorcery())) {
+		ast_test_status_update(test, "Failed to open sorcery structure\n");
 		return AST_TEST_FAIL;
 	}
 
@@ -1420,18 +1293,8 @@
 		break;
 	}
 
-	if (!(sorcery = ast_sorcery_open())) {
-		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;
-	}
-
-	if (ast_sorcery_object_register(sorcery, "test", test_sorcery_object_alloc, NULL, NULL)) {
-		ast_test_status_update(test, "Failed to register object type\n");
+	if (!(sorcery = alloc_and_initialize_sorcery())) {
+		ast_test_status_update(test, "Failed to open sorcery structure\n");
 		return AST_TEST_FAIL;
 	}
 
@@ -1477,18 +1340,8 @@
 		break;
 	}
 
-	if (!(sorcery = ast_sorcery_open())) {
-		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;
-	}
-
-	if (ast_sorcery_object_register(sorcery, "test", test_sorcery_object_alloc, NULL, NULL)) {
-		ast_test_status_update(test, "Failed to register object type\n");
+	if (!(sorcery = alloc_and_initialize_sorcery())) {
+		ast_test_status_update(test, "Failed to open sorcery structure\n");
 		return AST_TEST_FAIL;
 	}
 
@@ -1528,6 +1381,12 @@
 
 	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");
+		return AST_TEST_NOT_RUN;
+	}
+
+	if (!ast_category_get(config, "test_sorcery_cache")) {
+		ast_test_status_update(test, "Sorcery configuration file does not contain 'test_sorcery_cache' section\n");
+		ast_config_destroy(config);
 		return AST_TEST_NOT_RUN;
 	}
 
@@ -1903,7 +1762,7 @@
 	if (!(objects = ast_sorcery_retrieve(sorcery, "test", AST_RETRIEVE_FLAG_MULTIPLE, AST_RETRIEVE_PARAM_FIELD, "joe", "41", AST_RETRIEVE_PARAM_END))) {
 		ast_test_status_update(test, "Failed to retrieve a container when retrieving multiple\n");
 		return AST_TEST_FAIL;
-	} else if (!ao2_container_count(objects)) {
+	} else if (ao2_container_count(objects) != 1) {
 		ast_test_status_update(test, "Received a container with no objects in it when there should be\n");
 		return AST_TEST_FAIL;
 	}




More information about the asterisk-commits mailing list