[asterisk-commits] file: branch file/sorcery r378215 - in /team/file/sorcery: main/ tests/

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Sat Dec 29 13:15:40 CST 2012


Author: file
Date: Sat Dec 29 13:15:35 2012
New Revision: 378215

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=378215
Log:
Add a few more tests.

Modified:
    team/file/sorcery/main/sorcery.c
    team/file/sorcery/tests/test_sorcery.c

Modified: team/file/sorcery/main/sorcery.c
URL: http://svnview.digium.com/svn/asterisk/team/file/sorcery/main/sorcery.c?view=diff&rev=378215&r1=378214&r2=378215
==============================================================================
--- team/file/sorcery/main/sorcery.c (original)
+++ team/file/sorcery/main/sorcery.c Sat Dec 29 13:15:35 2012
@@ -878,8 +878,9 @@
 {
 	const struct ast_sorcery_object_details *details = object;
 
-	ast_assert(sorcery != NULL);
-	ast_assert(details->wizard != NULL);
+	if (!details->wizard) {
+		return -1;
+	}
 
 	return details->wizard->wizard->update(details->wizard->data, object);
 }
@@ -888,8 +889,9 @@
 {
 	const struct ast_sorcery_object_details *details = object;
 
-	ast_assert(sorcery != NULL);
-	ast_assert(details->wizard != NULL);
+	if (!details->wizard) {
+		return -1;
+	}
 
 	return details->wizard->wizard->delete(details->wizard->data, 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=378215&r1=378214&r2=378215
==============================================================================
--- team/file/sorcery/tests/test_sorcery.c (original)
+++ team/file/sorcery/tests/test_sorcery.c Sat Dec 29 13:15:35 2012
@@ -702,6 +702,61 @@
 	return res;
 }
 
+AST_TEST_DEFINE(objectset_apply_invalid)
+{
+	RAII_VAR(struct ast_sorcery *, sorcery, NULL, ast_sorcery_unref);
+	RAII_VAR(struct test_sorcery_object *, obj, NULL, ao2_cleanup);
+	RAII_VAR(struct ast_variable *, objset, NULL, ast_variables_destroy);
+
+	switch (cmd) {
+	case TEST_INIT:
+		info->name = "objectset_apply_invalid";
+		info->category = "/main/sorcery/";
+		info->summary = "sorcery object invalid apply unit test";
+		info->description =
+			"Test object set applying of an invalid set in sorcery";
+		return AST_TEST_NOT_RUN;
+	case TEST_EXECUTE:
+		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_object, 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 (!(obj = ast_sorcery_alloc(sorcery, "test", "blah"))) {
+		ast_test_status_update(test, "Failed to allocate a known object type\n");
+		return AST_TEST_FAIL;
+	}
+
+	if (!(objset = ast_variable_new("fred", "99", ""))) {
+		ast_test_status_update(test, "Failed to create an object set, test could not occur\n");
+		return AST_TEST_FAIL;
+	} else if (!ast_sorcery_objectset_apply(sorcery, obj, objset)) {
+		ast_test_status_update(test, "Successfully applied an invalid object set\n");
+		return AST_TEST_FAIL;
+	} else if ((obj->bob != 5) || (obj->joe != 10)) {
+		ast_test_status_update(test, "Object set modified object fields when it should not have\n");
+		return AST_TEST_FAIL;
+	}
+
+	return AST_TEST_PASS;
+}
+
 AST_TEST_DEFINE(objectset_transform)
 {
 	RAII_VAR(struct ast_sorcery *, sorcery, NULL, ast_sorcery_unref);
@@ -1258,18 +1313,18 @@
 	return AST_TEST_PASS;
 }
 
-AST_TEST_DEFINE(object_delete)
+AST_TEST_DEFINE(object_update_uncreated)
 {
 	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_delete";
-		info->category = "/main/sorcery/";
-		info->summary = "sorcery object deletion unit test";
-		info->description =
-			"Test object deletion in sorcery";
+		info->name = "object_update_uncreated";
+		info->category = "/main/sorcery/";
+		info->summary = "sorcery object update unit test";
+		info->description =
+			"Test updating of an uncreated object in sorcery";
 		return AST_TEST_NOT_RUN;
 	case TEST_EXECUTE:
 		break;
@@ -1295,6 +1350,51 @@
 		return AST_TEST_FAIL;
 	}
 
+	if (!ast_sorcery_update(sorcery, obj)) {
+		ast_test_status_update(test, "Successfully updated an object which has not been created yet\n");
+		return AST_TEST_FAIL;
+	}
+
+	return AST_TEST_PASS;
+}
+
+AST_TEST_DEFINE(object_delete)
+{
+	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_delete";
+		info->category = "/main/sorcery/";
+		info->summary = "sorcery object deletion unit test";
+		info->description =
+			"Test object deletion in sorcery";
+		return AST_TEST_NOT_RUN;
+	case TEST_EXECUTE:
+		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_object, NULL, NULL)) {
+		ast_test_status_update(test, "Failed to register object type\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");
+		return AST_TEST_FAIL;
+	}
+
 	if (ast_sorcery_create(sorcery, obj)) {
 		ast_test_status_update(test, "Failed to create object using in-memory wizard\n");
 		return AST_TEST_FAIL;
@@ -1309,6 +1409,51 @@
 
 	if ((obj = ast_sorcery_retrieve(sorcery, "test", AST_RETRIEVE_FLAG_DEFAULT, AST_RETRIEVE_PARAM_ID, "blah", AST_RETRIEVE_PARAM_END))) {
 		ast_test_status_update(test, "Retrieved deleted object that should not be there\n");
+		return AST_TEST_FAIL;
+	}
+
+	return AST_TEST_PASS;
+}
+
+AST_TEST_DEFINE(object_delete_uncreated)
+{
+	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_delete_uncreated";
+		info->category = "/main/sorcery/";
+		info->summary = "sorcery object deletion unit test";
+		info->description =
+			"Test object deletion of an uncreated object in sorcery";
+		return AST_TEST_NOT_RUN;
+	case TEST_EXECUTE:
+		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_object, NULL, NULL)) {
+		ast_test_status_update(test, "Failed to register object type\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");
+		return AST_TEST_FAIL;
+	}
+
+	if (!ast_sorcery_delete(sorcery, obj)) {
+		ast_test_status_update(test, "Successfully deleted an object which was never created\n");
 		return AST_TEST_FAIL;
 	}
 
@@ -1330,6 +1475,7 @@
 	AST_TEST_UNREGISTER(object_diff);
 	AST_TEST_UNREGISTER(objectset_create);
 	AST_TEST_UNREGISTER(objectset_apply);
+	AST_TEST_UNREGISTER(objectset_apply_invalid);
 	AST_TEST_UNREGISTER(objectset_transform);
 	AST_TEST_UNREGISTER(changeset_create);
 	AST_TEST_UNREGISTER(changeset_create_unchanged);
@@ -1339,7 +1485,9 @@
 	AST_TEST_UNREGISTER(object_retrieve_multiple_all);
 	AST_TEST_UNREGISTER(object_retrieve_multiple_field);
 	AST_TEST_UNREGISTER(object_update);
+	AST_TEST_UNREGISTER(object_update_uncreated);
 	AST_TEST_UNREGISTER(object_delete);
+	AST_TEST_UNREGISTER(object_delete_uncreated);
 	return 0;
 }
 
@@ -1358,6 +1506,7 @@
 	AST_TEST_REGISTER(object_diff);
 	AST_TEST_REGISTER(objectset_create);
 	AST_TEST_REGISTER(objectset_apply);
+	AST_TEST_REGISTER(objectset_apply_invalid);
 	AST_TEST_REGISTER(objectset_transform);
 	AST_TEST_REGISTER(changeset_create);
 	AST_TEST_REGISTER(changeset_create_unchanged);
@@ -1367,7 +1516,9 @@
 	AST_TEST_REGISTER(object_retrieve_multiple_all);
 	AST_TEST_REGISTER(object_retrieve_multiple_field);
 	AST_TEST_REGISTER(object_update);
+	AST_TEST_REGISTER(object_update_uncreated);
 	AST_TEST_REGISTER(object_delete);
+	AST_TEST_REGISTER(object_delete_uncreated);
 	return AST_MODULE_LOAD_SUCCESS;
 }
 




More information about the asterisk-commits mailing list