42 SORCERY_OBJECT(details);
53 static struct ast_sorcery *alloc_and_initialize_sorcery(
void)
73 static void deinitialize_sorcery(
struct ast_sorcery *sorcery)
87 info->name =
"object_create";
88 info->category =
"/res/sorcery_astdb/";
89 info->summary =
"sorcery astdb object creation unit test";
91 "Test object creation in sorcery using astdb wizard";
92 return AST_TEST_NOT_RUN;
97 if (!(sorcery = alloc_and_initialize_sorcery())) {
98 ast_test_status_update(
test,
"Failed to open sorcery structure\n");
103 ast_test_status_update(
test,
"Failed to allocate a known object type\n");
104 return AST_TEST_FAIL;
108 ast_test_status_update(
test,
"Failed to create object using astdb wizard\n");
109 return AST_TEST_FAIL;
110 }
else if (
ast_db_get(
"test/test",
"blah", value,
sizeof(value))) {
111 ast_test_status_update(
test,
"Object was apparently created but does not actually exist in astdb\n");
112 return AST_TEST_FAIL;
115 return AST_TEST_PASS;
125 info->name =
"object_retrieve_id";
126 info->category =
"/res/sorcery_astdb/";
127 info->summary =
"sorcery object retrieval using id unit test";
129 "Test object retrieval using id in sorcery with astdb wizard";
130 return AST_TEST_NOT_RUN;
135 if (!(sorcery = alloc_and_initialize_sorcery())) {
136 ast_test_status_update(
test,
"Failed to open sorcery structure\n");
137 return AST_TEST_FAIL;
141 ast_test_status_update(
test,
"Failed to allocate a known object type\n");
142 return AST_TEST_FAIL;
146 ast_test_status_update(
test,
"Failed to create object using astdb wizard\n");
147 return AST_TEST_FAIL;
153 ast_test_status_update(
test,
"Failed to allocate second instance of a known object type\n");
154 return AST_TEST_FAIL;
158 ast_test_status_update(
test,
"Failed to create second object using astdb wizard\n");
159 return AST_TEST_FAIL;
165 ast_test_status_update(
test,
"Failed to retrieve properly created object using id of 'blah'\n");
166 return AST_TEST_FAIL;
168 ast_test_status_update(
test,
"Retrieved object does not have correct id\n");
169 return AST_TEST_FAIL;
172 return AST_TEST_PASS;
183 info->name =
"object_retrieve_field";
184 info->category =
"/res/sorcery_astdb/";
185 info->summary =
"sorcery object retrieval using a specific field unit test";
187 "Test object retrieval using a specific field in sorcery with astdb wizard";
188 return AST_TEST_NOT_RUN;
194 ast_test_status_update(
test,
"Failed to create fields for object retrieval attempt\n");
195 return AST_TEST_FAIL;
198 if (!(sorcery = alloc_and_initialize_sorcery())) {
199 ast_test_status_update(
test,
"Failed to open sorcery structure\n");
200 return AST_TEST_FAIL;
204 ast_test_status_update(
test,
"Failed to allocate a known object type\n");
205 return AST_TEST_FAIL;
211 ast_test_status_update(
test,
"Failed to create object using astdb wizard\n");
212 return AST_TEST_FAIL;
218 ast_test_status_update(
test,
"Failed to retrieve properly created object using 'joe' field\n");
219 return AST_TEST_FAIL;
225 if (!(fields = ast_variable_new(
"joe",
"49",
""))) {
226 ast_test_status_update(
test,
"Failed to create fields for object retrieval attempt\n");
227 return AST_TEST_FAIL;
231 ast_test_status_update(
test,
"Retrieved an object using a field with an in-correct value... that should not happen\n");
232 return AST_TEST_FAIL;
235 return AST_TEST_PASS;
246 info->name =
"object_retrieve_multiple_all";
247 info->category =
"/res/sorcery_astdb/";
248 info->summary =
"sorcery multiple object retrieval unit test";
250 "Test multiple object retrieval in sorcery using astdb wizard";
251 return AST_TEST_NOT_RUN;
256 if (!(sorcery = alloc_and_initialize_sorcery())) {
257 ast_test_status_update(
test,
"Failed to open sorcery structure\n");
258 return AST_TEST_FAIL;
262 ast_test_status_update(
test,
"Failed to allocate a known object type\n");
263 return AST_TEST_FAIL;
267 ast_test_status_update(
test,
"Failed to create object using astdb wizard\n");
268 return AST_TEST_FAIL;
274 ast_test_status_update(
test,
"Failed to allocate second instance of a known object type\n");
275 return AST_TEST_FAIL;
279 ast_test_status_update(
test,
"Failed to create second object using astdb wizard\n");
280 return AST_TEST_FAIL;
284 ast_test_status_update(
test,
"Failed to retrieve a container of all objects\n");
285 return AST_TEST_FAIL;
287 ast_test_status_update(
test,
"Received a container with no objects in it when there should be some\n");
288 return AST_TEST_FAIL;
291 return AST_TEST_PASS;
303 info->name =
"object_retrieve_multiple_field";
304 info->category =
"/res/sorcery_astdb/";
305 info->summary =
"sorcery multiple object retrieval unit test";
307 "Test multiple object retrieval in sorcery using fields using astdb wizard";
308 return AST_TEST_NOT_RUN;
314 ast_test_status_update(
test,
"Failed to create fields for multiple retrieve\n");
315 return AST_TEST_FAIL;
318 if (!(sorcery = alloc_and_initialize_sorcery())) {
319 ast_test_status_update(
test,
"Failed to open sorcery structure\n");
320 return AST_TEST_FAIL;
324 ast_test_status_update(
test,
"Failed to allocate a known object type\n");
325 return AST_TEST_FAIL;
331 ast_test_status_update(
test,
"Failed to create object using astdb wizard\n");
332 return AST_TEST_FAIL;
336 ast_test_status_update(
test,
"Failed to retrieve a container of all objects\n");
337 return AST_TEST_FAIL;
339 ast_test_status_update(
test,
"Received a container with no objects in it when there should be some\n");
340 return AST_TEST_FAIL;
343 ao2_cleanup(objects);
346 if (!(fields = ast_variable_new(
"joe <",
"6",
""))) {
347 ast_test_status_update(
test,
"Failed to create fields for multiple retrieval\n");
348 return AST_TEST_FAIL;
350 ast_test_status_update(
test,
"Failed to retrieve an empty container when retrieving multiple\n");
351 return AST_TEST_FAIL;
353 ast_test_status_update(
test,
"Received a container with objects when there should be none in it\n");
354 return AST_TEST_FAIL;
357 return AST_TEST_PASS;
368 info->name =
"object_retrieve_regex";
369 info->category =
"/res/sorcery_astdb/";
370 info->summary =
"sorcery multiple object retrieval using regex unit test";
372 "Test multiple object retrieval in sorcery using regular expression for matching using astdb wizard";
373 return AST_TEST_NOT_RUN;
378 if (!(sorcery = alloc_and_initialize_sorcery())) {
379 ast_test_status_update(
test,
"Failed to open sorcery structure\n");
380 return AST_TEST_FAIL;
384 ast_test_status_update(
test,
"Failed to allocate a known object type\n");
385 return AST_TEST_FAIL;
389 ast_test_status_update(
test,
"Failed to create object using astdb wizard\n");
390 return AST_TEST_FAIL;
396 ast_test_status_update(
test,
"Failed to allocate second instance of a known object type\n");
397 return AST_TEST_FAIL;
401 ast_test_status_update(
test,
"Failed to create second object using astdb wizard\n");
402 return AST_TEST_FAIL;
408 ast_test_status_update(
test,
"Failed to allocate third instance of a known object type\n");
409 return AST_TEST_FAIL;
413 ast_test_status_update(
test,
"Failed to create third object using astdb wizard\n");
414 return AST_TEST_FAIL;
418 ast_test_status_update(
test,
"Failed to retrieve a container of objects\n");
419 return AST_TEST_FAIL;
421 ast_test_status_update(
test,
"Received a container with incorrect number of objects in it\n");
422 return AST_TEST_FAIL;
425 return AST_TEST_PASS;
436 info->name =
"object_update";
437 info->category =
"/res/sorcery_astdb/";
438 info->summary =
"sorcery object update unit test";
440 "Test object updating in sorcery using astdb wizard";
441 return AST_TEST_NOT_RUN;
446 if (!(sorcery = alloc_and_initialize_sorcery())) {
447 ast_test_status_update(
test,
"Failed to open sorcery structure\n");
448 return AST_TEST_FAIL;
452 ast_test_status_update(
test,
"Failed to allocate a known object type\n");
453 return AST_TEST_FAIL;
457 ast_test_status_update(
test,
"Failed to create object using astdb wizard\n");
458 return AST_TEST_FAIL;
462 ast_test_status_update(
test,
"Failed to allocate a known object type for updating\n");
463 return AST_TEST_FAIL;
472 ast_test_status_update(
test,
"Failed to update sorcery with new object\n");
473 return AST_TEST_FAIL;
477 ast_test_status_update(
test,
"Failed to retrieve properly updated object\n");
478 return AST_TEST_FAIL;
479 }
else if ((obj->bob != obj2->bob) || (obj->joe != obj2->joe)) {
480 ast_test_status_update(
test,
"Object retrieved is not the updated object\n");
481 return AST_TEST_FAIL;
484 return AST_TEST_PASS;
494 info->name =
"object_update_uncreated";
495 info->category =
"/res/sorcery_astdb/";
496 info->summary =
"sorcery object update unit test";
498 "Test updating of an uncreated object in sorcery using astdb wizard";
499 return AST_TEST_NOT_RUN;
504 if (!(sorcery = alloc_and_initialize_sorcery())) {
505 ast_test_status_update(
test,
"Failed to open sorcery structure\n");
506 return AST_TEST_FAIL;
510 ast_test_status_update(
test,
"Failed to allocate a known object type\n");
511 return AST_TEST_FAIL;
515 ast_test_status_update(
test,
"Successfully updated an object which has not been created yet\n");
516 return AST_TEST_FAIL;
519 return AST_TEST_PASS;
529 info->name =
"object_delete";
530 info->category =
"/res/sorcery_astdb/";
531 info->summary =
"sorcery object deletion unit test";
533 "Test object deletion in sorcery using astdb wizard";
534 return AST_TEST_NOT_RUN;
539 if (!(sorcery = alloc_and_initialize_sorcery())) {
540 ast_test_status_update(
test,
"Failed to open sorcery structure\n");
541 return AST_TEST_FAIL;
545 ast_test_status_update(
test,
"Failed to allocate a known object type\n");
546 return AST_TEST_FAIL;
550 ast_test_status_update(
test,
"Failed to create object using astdb wizard\n");
551 return AST_TEST_FAIL;
555 ast_test_status_update(
test,
"Failed to delete object using astdb wizard\n");
556 return AST_TEST_FAIL;
562 ast_test_status_update(
test,
"Retrieved deleted object that should not be there\n");
563 return AST_TEST_FAIL;
566 return AST_TEST_PASS;
576 info->name =
"object_delete_uncreated";
577 info->category =
"/res/sorcery_astdb/";
578 info->summary =
"sorcery object deletion unit test";
580 "Test object deletion of an uncreated object in sorcery using astdb wizard";
581 return AST_TEST_NOT_RUN;
586 if (!(sorcery = alloc_and_initialize_sorcery())) {
587 ast_test_status_update(
test,
"Failed to open sorcery structure\n");
588 return AST_TEST_FAIL;
592 ast_test_status_update(
test,
"Failed to allocate a known object type\n");
593 return AST_TEST_FAIL;
597 ast_test_status_update(
test,
"Successfully deleted an object which was never created\n");
598 return AST_TEST_FAIL;
601 return AST_TEST_PASS;
604 static int unload_module(
void)
606 AST_TEST_UNREGISTER(object_create);
607 AST_TEST_UNREGISTER(object_retrieve_id);
608 AST_TEST_UNREGISTER(object_retrieve_field);
609 AST_TEST_UNREGISTER(object_retrieve_multiple_all);
610 AST_TEST_UNREGISTER(object_retrieve_multiple_field);
611 AST_TEST_UNREGISTER(object_retrieve_regex);
612 AST_TEST_UNREGISTER(object_update);
613 AST_TEST_UNREGISTER(object_update_uncreated);
614 AST_TEST_UNREGISTER(object_delete);
615 AST_TEST_UNREGISTER(object_delete_uncreated);
620 static int load_module(
void)
622 AST_TEST_REGISTER(object_create);
623 AST_TEST_REGISTER(object_retrieve_id);
624 AST_TEST_REGISTER(object_retrieve_field);
625 AST_TEST_REGISTER(object_retrieve_multiple_all);
626 AST_TEST_REGISTER(object_retrieve_multiple_field);
627 AST_TEST_REGISTER(object_retrieve_regex);
628 AST_TEST_REGISTER(object_update);
629 AST_TEST_REGISTER(object_update_uncreated);
630 AST_TEST_REGISTER(object_delete);
631 AST_TEST_REGISTER(object_delete_uncreated);
636 AST_MODULE_INFO_STANDARD(
ASTERISK_GPL_KEY,
"Sorcery astdb Wizard test module");
#define ast_sorcery_object_field_register_nodoc(sorcery, type, name, default_val, opt_type, flags,...)
Register a field within an object without documentation.
Asterisk main include file. File version handling, generic pbx functions.
int ao2_container_count(struct ao2_container *c)
Returns the number of elements in a container.
void ast_variables_destroy(struct ast_variable *var)
Free variable list.
Structure for variables, used for configurations and for channel variables.
static void * test_sorcery_object_alloc(const char *id)
Internal function to allocate a test object.
Perform no matching, return all objects.
Full structure for sorcery.
Return all matching objects.
struct ao2_container * ast_sorcery_retrieve_by_regex(const struct ast_sorcery *sorcery, const char *type, const char *regex)
Retrieve multiple objects using a regular expression on their id.
void * ast_sorcery_retrieve_by_id(const struct ast_sorcery *sorcery, const char *type, const char *id)
Retrieve an object using its unique identifier.
#define ast_sorcery_unref(sorcery)
Decrease the reference count of a sorcery structure.
int ast_sorcery_create(const struct ast_sorcery *sorcery, void *object)
Create and potentially persist an object using an available wizard.
#define FLDSET(type,...)
Convert a struct and list of fields to an argument list of field offsets.
Type for default option handler for unsigned integers.
const char * ast_sorcery_object_get_id(const void *object)
Get the unique identifier of a sorcery object.
int ast_sorcery_delete(const struct ast_sorcery *sorcery, void *object)
Delete an object.
#define ast_sorcery_internal_object_register(sorcery, type, alloc, transform, apply)
Register an internal, hidden object type.
void * ast_sorcery_alloc(const struct ast_sorcery *sorcery, const char *type, const char *id)
Allocate an object.
Support for logging to various files, console and syslog Configuration in file logger.conf.
int ast_db_get(const char *family, const char *key, char *value, int valuelen)
Get key value specified by family/key.
void * ast_sorcery_retrieve_by_fields(const struct ast_sorcery *sorcery, const char *type, unsigned int flags, struct ast_variable *fields)
Retrieve an object or multiple objects using specific fields.
void * ast_sorcery_copy(const struct ast_sorcery *sorcery, const void *object)
Create a copy of an object.
#define ast_sorcery_open()
Open a new sorcery structure.
#define AST_TEST_DEFINE(hdr)
void * ast_sorcery_generic_alloc(size_t size, ao2_destructor_fn destructor)
Allocate a generic sorcery capable object.
#define ASTERISK_GPL_KEY
The text the key() function should return.
Asterisk module definitions.
#define RAII_VAR(vartype, varname, initval, dtor)
Declare a variable that will call a destructor function when it goes out of scope.
Persistent data storage (akin to *doze registry)
int ast_db_deltree(const char *family, const char *keytree)
Delete one or more entries in astdb.
Sorcery Data Access Layer API.
int ast_sorcery_update(const struct ast_sorcery *sorcery, void *object)
Update an object.