[asterisk-commits] file: branch file/sorcery r378657 - /team/file/sorcery/tests/test_sorcery.c

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Tue Jan 8 11:30:21 CST 2013


Author: file
Date: Tue Jan  8 11:30:17 2013
New Revision: 378657

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=378657
Log:
Let there be... tests!

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

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=378657&r1=378656&r2=378657
==============================================================================
--- team/file/sorcery/tests/test_sorcery.c (original)
+++ team/file/sorcery/tests/test_sorcery.c Tue Jan  8 11:30:17 2013
@@ -1618,6 +1618,362 @@
 	}
 
 	return res;
+}
+
+AST_TEST_DEFINE(configuration_file_wizard)
+{
+	struct ast_flags flags = { CONFIG_FLAG_NOCACHE };
+	struct ast_config *config;
+	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 = "configuration_file_wizard";
+		info->category = "/main/sorcery/";
+		info->summary = "sorcery configuration file wizard unit test";
+		info->description =
+			"Test the configuration file wizard in sorcery";
+		return AST_TEST_NOT_RUN;
+	case TEST_EXECUTE:
+		break;
+	}
+
+	if (!(config = ast_config_load2("test_sorcery.conf", "test_sorcery", flags))) {
+		ast_test_status_update(test, "Test sorcery configuration file wizard file not present - skipping configuration_file_wizard test\n");
+		return AST_TEST_NOT_RUN;
+	}
+
+	ast_config_destroy(config);
+
+	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", "config", "test_sorcery.conf")) {
+		ast_test_status_update(test, "Could not set a default wizard of the 'config' type, so skipping since it may not be loaded\n");
+		return AST_TEST_NOT_RUN;
+	}
+
+	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));
+
+	ast_sorcery_load(sorcery);
+
+	if ((obj = ast_sorcery_retrieve(sorcery, "test", AST_RETRIEVE_FLAG_DEFAULT, AST_RETRIEVE_PARAM_ID, "hey2", AST_RETRIEVE_PARAM_END))) {
+		ast_test_status_update(test, "Retrieved object which has an unknown field\n");
+		return AST_TEST_FAIL;
+	} else if (!(obj = ast_sorcery_retrieve(sorcery, "test", AST_RETRIEVE_FLAG_DEFAULT, AST_RETRIEVE_PARAM_ID, "hey", AST_RETRIEVE_PARAM_END))) {
+		ast_test_status_update(test, "Failed to retrieve a known object that has been configured in the configuration file\n");
+		return AST_TEST_FAIL;
+	} else if (obj->bob != 98) {
+		ast_test_status_update(test, "Value of 'bob' on object is not what is configured in configuration file\n");
+		return AST_TEST_FAIL;
+	} else if (obj->joe != 41) {
+		ast_test_status_update(test, "Value of 'joe' on object is not what is configured in configuration file\n");
+		return AST_TEST_FAIL;
+	}
+
+	return AST_TEST_PASS;
+}
+
+AST_TEST_DEFINE(configuration_file_wizard_with_file_integrity)
+{
+	struct ast_flags flags = { CONFIG_FLAG_NOCACHE };
+	struct ast_config *config;
+	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 = "configuration_file_wizard_with_file_integrity";
+		info->category = "/main/sorcery/";
+		info->summary = "sorcery configuration file wizard file integrity unit test";
+		info->description =
+			"Test the configuration file wizard with file integrity turned on in sorcery";
+		return AST_TEST_NOT_RUN;
+	case TEST_EXECUTE:
+		break;
+	}
+
+	if (!(config = ast_config_load2("test_sorcery.conf", "test_sorcery", flags))) {
+		ast_test_status_update(test, "Test sorcery configuration file wizard file not present - skipping configuration_file_wizard_with_file_integrity test\n");
+		return AST_TEST_NOT_RUN;
+	}
+
+	ast_config_destroy(config);
+
+	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", "config", "test_sorcery.conf,integrity=file")) {
+		ast_test_status_update(test, "Could not set a default wizard of the 'config' type, so skipping since it may not be loaded\n");
+		return AST_TEST_NOT_RUN;
+	}
+
+	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));
+
+	ast_sorcery_load(sorcery);
+
+	if ((obj = ast_sorcery_retrieve(sorcery, "test", AST_RETRIEVE_FLAG_DEFAULT, AST_RETRIEVE_PARAM_ID, "hey", AST_RETRIEVE_PARAM_END))) {
+		ast_test_status_update(test, "Retrieved object which has an unknown field\n");
+		return AST_TEST_FAIL;
+	}
+
+	return AST_TEST_PASS;
+}
+
+AST_TEST_DEFINE(configuration_file_wizard_with_criteria)
+{
+	struct ast_flags flags = { CONFIG_FLAG_NOCACHE };
+	struct ast_config *config;
+	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 = "configuration_file_wizard_with_criteria";
+		info->category = "/main/sorcery/";
+		info->summary = "sorcery configuration file wizard with criteria unit test";
+		info->description =
+			"Test the configuration file wizard with criteria matching in sorcery";
+		return AST_TEST_NOT_RUN;
+	case TEST_EXECUTE:
+		break;
+	}
+
+	if (!(config = ast_config_load2("test_sorcery.conf", "test_sorcery", flags))) {
+		ast_test_status_update(test, "Test sorcery configuration file wizard file not present - skipping configuration_file_wizard_with_criteria test\n");
+		return AST_TEST_NOT_RUN;
+	}
+
+	ast_config_destroy(config);
+
+	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", "config", "test_sorcery.conf,criteria=type=zombies")) {
+		ast_test_status_update(test, "Could not set a default wizard of the 'config' type, so skipping since it may not be loaded\n");
+		return AST_TEST_NOT_RUN;
+	}
+
+	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));
+	ast_sorcery_object_field_register(sorcery, "test", "type", NULL, OPT_NOOP_T, 0, NULL);
+
+	ast_sorcery_load(sorcery);
+
+	if ((obj = ast_sorcery_retrieve(sorcery, "test", AST_RETRIEVE_FLAG_DEFAULT, AST_RETRIEVE_PARAM_ID, "hey", AST_RETRIEVE_PARAM_END))) {
+		ast_test_status_update(test, "Retrieved object which did not match criteria\n");
+		return AST_TEST_FAIL;
+	} else if (!(obj = ast_sorcery_retrieve(sorcery, "test", AST_RETRIEVE_FLAG_DEFAULT, AST_RETRIEVE_PARAM_ID, "hey2", AST_RETRIEVE_PARAM_END))) {
+		ast_test_status_update(test, "Failed to retrieve a known object which matches criteria\n");
+		return AST_TEST_FAIL;
+	}
+
+	return AST_TEST_PASS;
+}
+
+AST_TEST_DEFINE(configuration_file_wizard_retrieve_field)
+{
+	struct ast_flags flags = { CONFIG_FLAG_NOCACHE };
+	struct ast_config *config;
+	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 = "configuration_file_wizard_retrieve_field";
+		info->category = "/main/sorcery/";
+		info->summary = "sorcery configuration file wizard field retrieval unit test";
+		info->description =
+			"Test the configuration file wizard retrieval using field in sorcery";
+		return AST_TEST_NOT_RUN;
+	case TEST_EXECUTE:
+		break;
+	}
+
+	if (!(config = ast_config_load2("test_sorcery.conf", "test_sorcery", flags))) {
+		ast_test_status_update(test, "Test sorcery configuration file wizard file not present - skipping configuration_file_wizard_retrieve_field test\n");
+		return AST_TEST_NOT_RUN;
+	}
+
+	ast_config_destroy(config);
+
+	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", "config", "test_sorcery.conf")) {
+		ast_test_status_update(test, "Could not set a default wizard of the 'config' type, so skipping since it may not be loaded\n");
+		return AST_TEST_NOT_RUN;
+	}
+
+	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));
+
+	ast_sorcery_load(sorcery);
+
+	if (!(obj = ast_sorcery_retrieve(sorcery, "test", AST_RETRIEVE_FLAG_DEFAULT, AST_RETRIEVE_PARAM_FIELD, "joe", "41", AST_RETRIEVE_PARAM_END))) {
+		ast_test_status_update(test, "Failed to retrieve a known object that has been configured with the correct field\n");
+		return AST_TEST_FAIL;
+	} else if (strcmp(ast_sorcery_object_get_id(obj), "hey")) {
+		ast_test_status_update(test, "Retrieved object has incorrect object id of '%s'\n", ast_sorcery_object_get_id(obj));
+		return AST_TEST_FAIL;
+	}
+
+	return AST_TEST_PASS;
+}
+
+AST_TEST_DEFINE(configuration_file_wizard_retrieve_multiple)
+{
+	struct ast_flags flags = { CONFIG_FLAG_NOCACHE };
+	struct ast_config *config;
+	RAII_VAR(struct ast_sorcery *, sorcery, NULL, ast_sorcery_unref);
+	RAII_VAR(struct ao2_container *, objects, NULL, ao2_cleanup);
+
+	switch (cmd) {
+	case TEST_INIT:
+		info->name = "configuration_file_wizard_retrieve_multiple";
+		info->category = "/main/sorcery/";
+		info->summary = "sorcery configuration file wizard multiple retrieval unit test";
+		info->description =
+			"Test the configuration file wizard multiple retrieval in sorcery";
+		return AST_TEST_NOT_RUN;
+	case TEST_EXECUTE:
+		break;
+	}
+
+	if (!(config = ast_config_load2("test_sorcery.conf", "test_sorcery", flags))) {
+		ast_test_status_update(test, "Test sorcery configuration file wizard file not present - skipping configuration_file_wizard_retrieve_multiple test\n");
+		return AST_TEST_NOT_RUN;
+	}
+
+	ast_config_destroy(config);
+
+	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", "config", "test_sorcery.conf")) {
+		ast_test_status_update(test, "Could not set a default wizard of the 'config' type, so skipping since it may not be loaded\n");
+		return AST_TEST_NOT_RUN;
+	}
+
+	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));
+
+	ast_sorcery_load(sorcery);
+
+	if (!(objects = ast_sorcery_retrieve(sorcery, "test", AST_RETRIEVE_FLAG_MULTIPLE, AST_RETRIEVE_PARAM_FIELD, "joe", "99", AST_RETRIEVE_PARAM_END))) {
+		ast_test_status_update(test, "Failed to retrieve an empty container when retrieving multiple\n");
+		return AST_TEST_FAIL;
+	} else if (ao2_container_count(objects)) {
+		ast_test_status_update(test, "Received a container with objects when there should be none in it\n");
+		return AST_TEST_FAIL;
+	}
+
+	ao2_cleanup(objects);
+
+	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)) {
+		ast_test_status_update(test, "Received a container with no objects in it when there should be\n");
+		return AST_TEST_FAIL;
+	}
+
+	return AST_TEST_PASS;
+}
+
+AST_TEST_DEFINE(configuration_file_wizard_retrieve_multiple_all)
+{
+	struct ast_flags flags = { CONFIG_FLAG_NOCACHE };
+	struct ast_config *config;
+	RAII_VAR(struct ast_sorcery *, sorcery, NULL, ast_sorcery_unref);
+	RAII_VAR(struct ao2_container *, objects, NULL, ao2_cleanup);
+
+	switch (cmd) {
+	case TEST_INIT:
+		info->name = "configuration_file_wizard_retrieve_multiple_all";
+		info->category = "/main/sorcery/";
+		info->summary = "sorcery configuration file wizard multiple retrieve all unit test";
+		info->description =
+			"Test the configuration file wizard multiple retrieve all in sorcery";
+		return AST_TEST_NOT_RUN;
+	case TEST_EXECUTE:
+		break;
+	}
+
+	if (!(config = ast_config_load2("test_sorcery.conf", "test_sorcery", flags))) {
+		ast_test_status_update(test, "Test sorcery configuration file wizard file not present - skipping configuration_file_wizard_retrieve_multiple_all test\n");
+		return AST_TEST_NOT_RUN;
+	}
+
+	ast_config_destroy(config);
+
+	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", "config", "test_sorcery.conf")) {
+		ast_test_status_update(test, "Could not set a default wizard of the 'config' type, so skipping since it may not be loaded\n");
+		return AST_TEST_NOT_RUN;
+	}
+
+	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));
+
+	ast_sorcery_load(sorcery);
+
+	if (!(objects = ast_sorcery_retrieve(sorcery, "test", AST_RETRIEVE_FLAG_MULTIPLE | AST_RETRIEVE_FLAG_ALL, AST_RETRIEVE_PARAM_END))) {
+		ast_test_status_update(test, "Failed to retrieve a container with all objects when there should be one\n");
+		return AST_TEST_FAIL;
+	} else if (ao2_container_count(objects) != 2) {
+		ast_test_status_update(test, "Returned container does not have the correct number of objects in it\n");
+		return AST_TEST_FAIL;
+	}
+
+	return AST_TEST_PASS;
 }
 
 static int unload_module(void)
@@ -1649,6 +2005,12 @@
 	AST_TEST_UNREGISTER(object_delete);
 	AST_TEST_UNREGISTER(object_delete_uncreated);
 	AST_TEST_UNREGISTER(caching_wizard_behavior);
+	AST_TEST_UNREGISTER(configuration_file_wizard);
+	AST_TEST_UNREGISTER(configuration_file_wizard_with_file_integrity);
+	AST_TEST_UNREGISTER(configuration_file_wizard_with_criteria);
+	AST_TEST_UNREGISTER(configuration_file_wizard_retrieve_field);
+	AST_TEST_UNREGISTER(configuration_file_wizard_retrieve_multiple);
+	AST_TEST_UNREGISTER(configuration_file_wizard_retrieve_multiple_all);
 	return 0;
 }
 
@@ -1681,6 +2043,12 @@
 	AST_TEST_REGISTER(object_delete);
 	AST_TEST_REGISTER(object_delete_uncreated);
 	AST_TEST_REGISTER(caching_wizard_behavior);
+	AST_TEST_REGISTER(configuration_file_wizard);
+	AST_TEST_REGISTER(configuration_file_wizard_with_file_integrity);
+	AST_TEST_REGISTER(configuration_file_wizard_with_criteria);
+	AST_TEST_REGISTER(configuration_file_wizard_retrieve_field);
+	AST_TEST_REGISTER(configuration_file_wizard_retrieve_multiple);
+	AST_TEST_REGISTER(configuration_file_wizard_retrieve_multiple_all);
 	return AST_MODULE_LOAD_SUCCESS;
 }
 




More information about the asterisk-commits mailing list