|
|
|
@ -138,6 +138,9 @@ struct sorcery_test_caching {
|
|
|
|
|
/*! \brief Whether the object has been deleted from the cache or not */
|
|
|
|
|
unsigned int deleted:1;
|
|
|
|
|
|
|
|
|
|
/*! \brief Whether the object is stale or not */
|
|
|
|
|
unsigned int is_stale:1;
|
|
|
|
|
|
|
|
|
|
/*! \brief Object to return when asked */
|
|
|
|
|
struct test_sorcery_object object;
|
|
|
|
|
};
|
|
|
|
@ -217,6 +220,12 @@ static int sorcery_test_delete(const struct ast_sorcery *sorcery, void *data, vo
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static int sorcery_test_is_stale(const struct ast_sorcery *sorcery, void *data, void *object)
|
|
|
|
|
{
|
|
|
|
|
cache.is_stale = 1;
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*! \brief Dummy sorcery wizards, not actually used so we only populate the name and nothing else */
|
|
|
|
|
static struct ast_sorcery_wizard test_wizard = {
|
|
|
|
|
.name = "test",
|
|
|
|
@ -234,6 +243,7 @@ static struct ast_sorcery_wizard test_wizard2 = {
|
|
|
|
|
.retrieve_id = sorcery_test_retrieve_id,
|
|
|
|
|
.update = sorcery_test_update,
|
|
|
|
|
.delete = sorcery_test_delete,
|
|
|
|
|
.is_stale = sorcery_test_is_stale,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
static void sorcery_observer_created(const void *object)
|
|
|
|
@ -2223,6 +2233,84 @@ AST_TEST_DEFINE(object_delete_uncreated)
|
|
|
|
|
return AST_TEST_PASS;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
AST_TEST_DEFINE(object_is_stale)
|
|
|
|
|
{
|
|
|
|
|
RAII_VAR(struct ast_sorcery *, sorcery, NULL, ast_sorcery_unref);
|
|
|
|
|
RAII_VAR(struct ast_sorcery_wizard *, wizard1, &test_wizard, ast_sorcery_wizard_unregister);
|
|
|
|
|
RAII_VAR(struct ast_sorcery_wizard *, wizard2, &test_wizard2, ast_sorcery_wizard_unregister);
|
|
|
|
|
RAII_VAR(struct test_sorcery_object *, obj1, NULL, ao2_cleanup);
|
|
|
|
|
RAII_VAR(struct test_sorcery_object *, obj2, NULL, ao2_cleanup);
|
|
|
|
|
|
|
|
|
|
switch (cmd) {
|
|
|
|
|
case TEST_INIT:
|
|
|
|
|
info->name = "object_is_stale";
|
|
|
|
|
info->category = "/main/sorcery/";
|
|
|
|
|
info->summary = "sorcery object staleness unit test";
|
|
|
|
|
info->description =
|
|
|
|
|
"Test whether sorcery will query a wizard correctly if asked\n"
|
|
|
|
|
"if an object is stale.";
|
|
|
|
|
return AST_TEST_NOT_RUN;
|
|
|
|
|
case TEST_EXECUTE:
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (ast_sorcery_wizard_register(&test_wizard)) {
|
|
|
|
|
ast_test_status_update(test, "Failed to register a perfectly valid sorcery wizard\n");
|
|
|
|
|
return AST_TEST_FAIL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (ast_sorcery_wizard_register(&test_wizard2)) {
|
|
|
|
|
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");
|
|
|
|
|
return AST_TEST_FAIL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ((ast_sorcery_apply_default(sorcery, "test", "test", NULL) != AST_SORCERY_APPLY_SUCCESS) ||
|
|
|
|
|
ast_sorcery_internal_object_register(sorcery, "test", test_sorcery_object_alloc, NULL, NULL)) {
|
|
|
|
|
return AST_TEST_FAIL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ast_sorcery_object_field_register_nodoc(sorcery, "test", "bob", "5", OPT_UINT_T, 0, FLDSET(struct test_sorcery_object, bob));
|
|
|
|
|
ast_sorcery_object_field_register_nodoc(sorcery, "test", "joe", "10", OPT_UINT_T, 0, FLDSET(struct test_sorcery_object, joe));
|
|
|
|
|
ast_sorcery_object_field_register_custom_nodoc(sorcery, "test", "jim", "444", jim_handler, NULL, jim_vl, 0, 0);
|
|
|
|
|
ast_sorcery_object_field_register_custom_nodoc(sorcery, "test", "jack", "888,999", jack_handler, jack_str, NULL, 0, 0);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if ((ast_sorcery_apply_default(sorcery, "test2", "test2", "test2data") != AST_SORCERY_APPLY_SUCCESS) ||
|
|
|
|
|
ast_sorcery_internal_object_register(sorcery, "test2", test_sorcery_object_alloc, NULL, NULL)) {
|
|
|
|
|
return AST_TEST_FAIL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ast_sorcery_object_field_register_nodoc(sorcery, "test2", "bob", "5", OPT_UINT_T, 0, FLDSET(struct test_sorcery_object, bob));
|
|
|
|
|
ast_sorcery_object_field_register_nodoc(sorcery, "test2", "joe", "10", OPT_UINT_T, 0, FLDSET(struct test_sorcery_object, joe));
|
|
|
|
|
ast_sorcery_object_field_register_custom_nodoc(sorcery, "test2", "jim", "444", jim_handler, NULL, jim_vl, 0, 0);
|
|
|
|
|
ast_sorcery_object_field_register_custom_nodoc(sorcery, "test2", "jack", "888,999", jack_handler, jack_str, NULL, 0, 0);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!(obj1 = ast_sorcery_alloc(sorcery, "test", "blah"))) {
|
|
|
|
|
ast_test_status_update(test, "Failed to allocate a known object type\n");
|
|
|
|
|
return AST_TEST_FAIL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!(obj2 = ast_sorcery_alloc(sorcery, "test2", "blah"))) {
|
|
|
|
|
ast_test_status_update(test, "Failed to allocate a known object type\n");
|
|
|
|
|
return AST_TEST_FAIL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* The 'test' wizard has no is_stale callback */
|
|
|
|
|
ast_test_validate(test, ast_sorcery_is_stale(sorcery, obj1) == 0);
|
|
|
|
|
|
|
|
|
|
/* The 'test2' wizard should return stale */
|
|
|
|
|
ast_test_validate(test, ast_sorcery_is_stale(sorcery, obj2) == 1);
|
|
|
|
|
ast_test_validate(test, cache.is_stale == 1);
|
|
|
|
|
|
|
|
|
|
return AST_TEST_PASS;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
AST_TEST_DEFINE(caching_wizard_behavior)
|
|
|
|
|
{
|
|
|
|
|
struct ast_flags flags = { CONFIG_FLAG_NOCACHE };
|
|
|
|
@ -3505,6 +3593,7 @@ static int unload_module(void)
|
|
|
|
|
AST_TEST_UNREGISTER(object_update_uncreated);
|
|
|
|
|
AST_TEST_UNREGISTER(object_delete);
|
|
|
|
|
AST_TEST_UNREGISTER(object_delete_uncreated);
|
|
|
|
|
AST_TEST_UNREGISTER(object_is_stale);
|
|
|
|
|
AST_TEST_UNREGISTER(caching_wizard_behavior);
|
|
|
|
|
AST_TEST_UNREGISTER(object_type_observer);
|
|
|
|
|
AST_TEST_UNREGISTER(configuration_file_wizard);
|
|
|
|
@ -3561,6 +3650,7 @@ static int load_module(void)
|
|
|
|
|
AST_TEST_REGISTER(object_update_uncreated);
|
|
|
|
|
AST_TEST_REGISTER(object_delete);
|
|
|
|
|
AST_TEST_REGISTER(object_delete_uncreated);
|
|
|
|
|
AST_TEST_REGISTER(object_is_stale);
|
|
|
|
|
AST_TEST_REGISTER(caching_wizard_behavior);
|
|
|
|
|
AST_TEST_REGISTER(object_type_observer);
|
|
|
|
|
AST_TEST_REGISTER(configuration_file_wizard);
|
|
|
|
|