Asterisk - The Open Source Telephony Project GIT-master-b023714
Loading...
Searching...
No Matches
Data Structures | Functions | Variables
test_sorcery_astdb.c File Reference

Sorcery Unit Tests. More...

#include "asterisk.h"
#include "asterisk/test.h"
#include "asterisk/module.h"
#include "asterisk/sorcery.h"
#include "asterisk/astdb.h"
#include "asterisk/logger.h"
Include dependency graph for test_sorcery_astdb.c:

Go to the source code of this file.

Data Structures

struct  test_sorcery_object
 Dummy sorcery object. More...
 

Functions

static void __reg_module (void)
 
static void __unreg_module (void)
 
static struct ast_sorceryalloc_and_initialize_sorcery (void)
 
struct ast_moduleAST_MODULE_SELF_SYM (void)
 
 AST_TEST_DEFINE (object_create)
 
 AST_TEST_DEFINE (object_delete)
 
 AST_TEST_DEFINE (object_delete_uncreated)
 
 AST_TEST_DEFINE (object_retrieve_field)
 
 AST_TEST_DEFINE (object_retrieve_id)
 
 AST_TEST_DEFINE (object_retrieve_multiple_all)
 
 AST_TEST_DEFINE (object_retrieve_multiple_field)
 
 AST_TEST_DEFINE (object_retrieve_regex)
 
 AST_TEST_DEFINE (object_update)
 
 AST_TEST_DEFINE (object_update_uncreated)
 
static void deinitialize_sorcery (struct ast_sorcery *sorcery)
 
static int load_module (void)
 
static void * test_sorcery_object_alloc (const char *id)
 Internal function to allocate a test object.
 
static int unload_module (void)
 

Variables

static struct ast_module_info __mod_info = { .name = AST_MODULE, .flags = AST_MODFLAG_LOAD_ORDER , .description = "Sorcery astdb Wizard test module" , .key = ASTERISK_GPL_KEY , .buildopt_sum = AST_BUILDOPT_SUM, .load = load_module, .unload = unload_module, .load_pri = AST_MODPRI_DEFAULT, .support_level = AST_MODULE_SUPPORT_CORE, }
 
static const struct ast_module_infoast_module_info = &__mod_info
 

Detailed Description

Sorcery Unit Tests.

Author
Joshua Colp jcolp.nosp@m.@dig.nosp@m.ium.c.nosp@m.om

Definition in file test_sorcery_astdb.c.

Function Documentation

◆ __reg_module()

static void __reg_module ( void  )
static

Definition at line 643 of file test_sorcery_astdb.c.

◆ __unreg_module()

static void __unreg_module ( void  )
static

Definition at line 643 of file test_sorcery_astdb.c.

◆ alloc_and_initialize_sorcery()

static struct ast_sorcery * alloc_and_initialize_sorcery ( void  )
static

Definition at line 53 of file test_sorcery_astdb.c.

54{
55 struct ast_sorcery *sorcery;
56
57 if (!(sorcery = ast_sorcery_open())) {
58 return NULL;
59 }
60
61 if ((ast_sorcery_apply_default(sorcery, "test", "astdb", "test") != AST_SORCERY_APPLY_SUCCESS) ||
64 return NULL;
65 }
66
69
70 return sorcery;
71}
#define FLDSET(type,...)
Convert a struct and list of fields to an argument list of field offsets.
@ OPT_UINT_T
Type for default option handler for unsigned integers.
static struct ast_sorcery * sorcery
#define NULL
Definition resample.c:96
#define ast_sorcery_unref(sorcery)
Decrease the reference count of a sorcery structure.
Definition sorcery.h:1500
#define ast_sorcery_object_field_register_nodoc(sorcery, type, name, default_val, opt_type, flags,...)
Register a field within an object without documentation.
Definition sorcery.h:987
#define ast_sorcery_internal_object_register(sorcery, type, alloc, transform, apply)
Register an internal, hidden object type.
Definition sorcery.h:867
#define ast_sorcery_apply_default(sorcery, type, name, data)
Definition sorcery.h:476
#define ast_sorcery_open()
Open a new sorcery structure.
Definition sorcery.h:406
@ AST_SORCERY_APPLY_SUCCESS
Definition sorcery.h:427
Full structure for sorcery.
Definition sorcery.c:231
Dummy sorcery object.
static void * test_sorcery_object_alloc(const char *id)
Internal function to allocate a test object.

References ast_sorcery_apply_default, AST_SORCERY_APPLY_SUCCESS, ast_sorcery_internal_object_register, ast_sorcery_object_field_register_nodoc, ast_sorcery_open, ast_sorcery_unref, FLDSET, NULL, OPT_UINT_T, sorcery, and test_sorcery_object_alloc().

Referenced by AST_TEST_DEFINE(), AST_TEST_DEFINE(), AST_TEST_DEFINE(), AST_TEST_DEFINE(), AST_TEST_DEFINE(), AST_TEST_DEFINE(), AST_TEST_DEFINE(), AST_TEST_DEFINE(), AST_TEST_DEFINE(), and AST_TEST_DEFINE().

◆ AST_MODULE_SELF_SYM()

struct ast_module * AST_MODULE_SELF_SYM ( void  )

Definition at line 643 of file test_sorcery_astdb.c.

◆ AST_TEST_DEFINE() [1/10]

AST_TEST_DEFINE ( object_create  )

Definition at line 79 of file test_sorcery_astdb.c.

80{
83 char value[2];
84
85 switch (cmd) {
86 case TEST_INIT:
87 info->name = "object_create";
88 info->category = "/res/sorcery_astdb/";
89 info->summary = "sorcery astdb object creation unit test";
90 info->description =
91 "Test object creation in sorcery using astdb wizard";
92 return AST_TEST_NOT_RUN;
93 case TEST_EXECUTE:
94 break;
95 }
96
98 ast_test_status_update(test, "Failed to open sorcery structure\n");
99 return AST_TEST_FAIL;
100 }
101
102 if (!(obj = ast_sorcery_alloc(sorcery, "test", "blah"))) {
103 ast_test_status_update(test, "Failed to allocate a known object type\n");
104 return AST_TEST_FAIL;
105 }
106
107 if (ast_sorcery_create(sorcery, obj)) {
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;
113 }
114
115 return AST_TEST_PASS;
116}
int ast_db_get(const char *family, const char *key, char *value, int valuelen)
Get key value specified by family/key.
Definition db.c:421
#define ao2_cleanup(obj)
Definition astobj2.h:1934
int ast_sorcery_create(const struct ast_sorcery *sorcery, void *object)
Create and potentially persist an object using an available wizard.
Definition sorcery.c:2126
void * ast_sorcery_alloc(const struct ast_sorcery *sorcery, const char *type, const char *id)
Allocate an object.
Definition sorcery.c:1808
int value
Definition syslog.c:37
@ TEST_INIT
Definition test.h:200
@ TEST_EXECUTE
Definition test.h:201
#define ast_test_status_update(a, b, c...)
Definition test.h:129
@ AST_TEST_PASS
Definition test.h:195
@ AST_TEST_FAIL
Definition test.h:196
@ AST_TEST_NOT_RUN
Definition test.h:194
static struct ast_sorcery * alloc_and_initialize_sorcery(void)
static void deinitialize_sorcery(struct ast_sorcery *sorcery)
#define RAII_VAR(vartype, varname, initval, dtor)
Declare a variable that will call a destructor function when it goes out of scope.
Definition utils.h:978

References alloc_and_initialize_sorcery(), ao2_cleanup, ast_db_get(), ast_sorcery_alloc(), ast_sorcery_create(), AST_TEST_FAIL, AST_TEST_NOT_RUN, AST_TEST_PASS, ast_test_status_update, deinitialize_sorcery(), NULL, RAII_VAR, sorcery, TEST_EXECUTE, TEST_INIT, and value.

◆ AST_TEST_DEFINE() [2/10]

AST_TEST_DEFINE ( object_delete  )

Definition at line 529 of file test_sorcery_astdb.c.

530{
533
534 switch (cmd) {
535 case TEST_INIT:
536 info->name = "object_delete";
537 info->category = "/res/sorcery_astdb/";
538 info->summary = "sorcery object deletion unit test";
539 info->description =
540 "Test object deletion in sorcery using astdb wizard";
541 return AST_TEST_NOT_RUN;
542 case TEST_EXECUTE:
543 break;
544 }
545
547 ast_test_status_update(test, "Failed to open sorcery structure\n");
548 return AST_TEST_FAIL;
549 }
550
551 if (!(obj = ast_sorcery_alloc(sorcery, "test", "blah"))) {
552 ast_test_status_update(test, "Failed to allocate a known object type\n");
553 return AST_TEST_FAIL;
554 }
555
556 if (ast_sorcery_create(sorcery, obj)) {
557 ast_test_status_update(test, "Failed to create object using astdb wizard\n");
558 return AST_TEST_FAIL;
559 }
560
561 if (ast_sorcery_delete(sorcery, obj)) {
562 ast_test_status_update(test, "Failed to delete object using astdb wizard\n");
563 return AST_TEST_FAIL;
564 }
565
566 ao2_cleanup(obj);
567
568 if ((obj = ast_sorcery_retrieve_by_id(sorcery, "test", "blah"))) {
569 ast_test_status_update(test, "Retrieved deleted object that should not be there\n");
570 return AST_TEST_FAIL;
571 }
572
573 return AST_TEST_PASS;
574}
void * ast_sorcery_retrieve_by_id(const struct ast_sorcery *sorcery, const char *type, const char *id)
Retrieve an object using its unique identifier.
Definition sorcery.c:1917
int ast_sorcery_delete(const struct ast_sorcery *sorcery, void *object)
Delete an object.
Definition sorcery.c:2302

References alloc_and_initialize_sorcery(), ao2_cleanup, ast_sorcery_alloc(), ast_sorcery_create(), ast_sorcery_delete(), ast_sorcery_retrieve_by_id(), AST_TEST_FAIL, AST_TEST_NOT_RUN, AST_TEST_PASS, ast_test_status_update, deinitialize_sorcery(), NULL, RAII_VAR, sorcery, TEST_EXECUTE, and TEST_INIT.

◆ AST_TEST_DEFINE() [3/10]

AST_TEST_DEFINE ( object_delete_uncreated  )

Definition at line 576 of file test_sorcery_astdb.c.

577{
580
581 switch (cmd) {
582 case TEST_INIT:
583 info->name = "object_delete_uncreated";
584 info->category = "/res/sorcery_astdb/";
585 info->summary = "sorcery object deletion unit test";
586 info->description =
587 "Test object deletion of an uncreated object in sorcery using astdb wizard";
588 return AST_TEST_NOT_RUN;
589 case TEST_EXECUTE:
590 break;
591 }
592
594 ast_test_status_update(test, "Failed to open sorcery structure\n");
595 return AST_TEST_FAIL;
596 }
597
598 if (!(obj = ast_sorcery_alloc(sorcery, "test", "blah"))) {
599 ast_test_status_update(test, "Failed to allocate a known object type\n");
600 return AST_TEST_FAIL;
601 }
602
603 if (!ast_sorcery_delete(sorcery, obj)) {
604 ast_test_status_update(test, "Successfully deleted an object which was never created\n");
605 return AST_TEST_FAIL;
606 }
607
608 return AST_TEST_PASS;
609}

References alloc_and_initialize_sorcery(), ao2_cleanup, ast_sorcery_alloc(), ast_sorcery_delete(), AST_TEST_FAIL, AST_TEST_NOT_RUN, AST_TEST_PASS, ast_test_status_update, deinitialize_sorcery(), NULL, RAII_VAR, sorcery, TEST_EXECUTE, and TEST_INIT.

◆ AST_TEST_DEFINE() [4/10]

AST_TEST_DEFINE ( object_retrieve_field  )

Definition at line 175 of file test_sorcery_astdb.c.

176{
179 RAII_VAR(struct ast_variable *, fields, ast_variable_new("joe", "42", ""), ast_variables_destroy);
180
181 switch (cmd) {
182 case TEST_INIT:
183 info->name = "object_retrieve_field";
184 info->category = "/res/sorcery_astdb/";
185 info->summary = "sorcery object retrieval using a specific field unit test";
186 info->description =
187 "Test object retrieval using a specific field in sorcery with astdb wizard";
188 return AST_TEST_NOT_RUN;
189 case TEST_EXECUTE:
190 break;
191 }
192
193 if (!fields) {
194 ast_test_status_update(test, "Failed to create fields for object retrieval attempt\n");
195 return AST_TEST_FAIL;
196 }
197
199 ast_test_status_update(test, "Failed to open sorcery structure\n");
200 return AST_TEST_FAIL;
201 }
202
203 if (!(obj = ast_sorcery_alloc(sorcery, "test", "blah"))) {
204 ast_test_status_update(test, "Failed to allocate a known object type\n");
205 return AST_TEST_FAIL;
206 }
207
208 obj->joe = 42;
209
210 if (ast_sorcery_create(sorcery, obj)) {
211 ast_test_status_update(test, "Failed to create object using astdb wizard\n");
212 return AST_TEST_FAIL;
213 }
214
215 ao2_cleanup(obj);
216
218 ast_test_status_update(test, "Failed to retrieve properly created object using 'joe' field\n");
219 return AST_TEST_FAIL;
220 }
221
222 ao2_cleanup(obj);
223 ast_variables_destroy(fields);
224
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;
228 }
229
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;
233 }
234
235 return AST_TEST_PASS;
236}
#define ast_variable_new(name, value, filename)
void ast_variables_destroy(struct ast_variable *var)
Free variable list.
Definition extconf.c:1260
@ AST_RETRIEVE_FLAG_DEFAULT
Default retrieval flags.
Definition sorcery.h:117
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.
Definition sorcery.c:1961
Structure for variables, used for configurations and for channel variables.

References alloc_and_initialize_sorcery(), ao2_cleanup, AST_RETRIEVE_FLAG_DEFAULT, ast_sorcery_alloc(), ast_sorcery_create(), ast_sorcery_retrieve_by_fields(), AST_TEST_FAIL, AST_TEST_NOT_RUN, AST_TEST_PASS, ast_test_status_update, ast_variable_new, ast_variables_destroy(), deinitialize_sorcery(), NULL, RAII_VAR, sorcery, TEST_EXECUTE, and TEST_INIT.

◆ AST_TEST_DEFINE() [5/10]

AST_TEST_DEFINE ( object_retrieve_id  )

Definition at line 118 of file test_sorcery_astdb.c.

119{
122
123 switch (cmd) {
124 case TEST_INIT:
125 info->name = "object_retrieve_id";
126 info->category = "/res/sorcery_astdb/";
127 info->summary = "sorcery object retrieval using id unit test";
128 info->description =
129 "Test object retrieval using id in sorcery with astdb wizard";
130 return AST_TEST_NOT_RUN;
131 case TEST_EXECUTE:
132 break;
133 }
134
136 ast_test_status_update(test, "Failed to open sorcery structure\n");
137 return AST_TEST_FAIL;
138 }
139
140 if (!(obj = ast_sorcery_alloc(sorcery, "test", "blah"))) {
141 ast_test_status_update(test, "Failed to allocate a known object type\n");
142 return AST_TEST_FAIL;
143 }
144
145 if (ast_sorcery_create(sorcery, obj)) {
146 ast_test_status_update(test, "Failed to create object using astdb wizard\n");
147 return AST_TEST_FAIL;
148 }
149
150 ao2_cleanup(obj);
151
152 if (!(obj = ast_sorcery_alloc(sorcery, "test", "blah2"))) {
153 ast_test_status_update(test, "Failed to allocate second instance of a known object type\n");
154 return AST_TEST_FAIL;
155 }
156
157 if (ast_sorcery_create(sorcery, obj)) {
158 ast_test_status_update(test, "Failed to create second object using astdb wizard\n");
159 return AST_TEST_FAIL;
160 }
161
162 ao2_cleanup(obj);
163
164 if (!(obj = ast_sorcery_retrieve_by_id(sorcery, "test", "blah"))) {
165 ast_test_status_update(test, "Failed to retrieve properly created object using id of 'blah'\n");
166 return AST_TEST_FAIL;
167 } else if (strcmp(ast_sorcery_object_get_id(obj), "blah")) {
168 ast_test_status_update(test, "Retrieved object does not have correct id\n");
169 return AST_TEST_FAIL;
170 }
171
172 return AST_TEST_PASS;
173}
const char * ast_sorcery_object_get_id(const void *object)
Get the unique identifier of a sorcery object.
Definition sorcery.c:2381

References alloc_and_initialize_sorcery(), ao2_cleanup, ast_sorcery_alloc(), ast_sorcery_create(), ast_sorcery_object_get_id(), ast_sorcery_retrieve_by_id(), AST_TEST_FAIL, AST_TEST_NOT_RUN, AST_TEST_PASS, ast_test_status_update, deinitialize_sorcery(), NULL, RAII_VAR, sorcery, TEST_EXECUTE, and TEST_INIT.

◆ AST_TEST_DEFINE() [6/10]

AST_TEST_DEFINE ( object_retrieve_multiple_all  )

Definition at line 238 of file test_sorcery_astdb.c.

239{
242 RAII_VAR(struct ao2_container *, objects, NULL, ao2_cleanup);
243
244 switch (cmd) {
245 case TEST_INIT:
246 info->name = "object_retrieve_multiple_all";
247 info->category = "/res/sorcery_astdb/";
248 info->summary = "sorcery multiple object retrieval unit test";
249 info->description =
250 "Test multiple object retrieval in sorcery using astdb wizard";
251 return AST_TEST_NOT_RUN;
252 case TEST_EXECUTE:
253 break;
254 }
255
257 ast_test_status_update(test, "Failed to open sorcery structure\n");
258 return AST_TEST_FAIL;
259 }
260
261 if (!(obj = ast_sorcery_alloc(sorcery, "test", "blah"))) {
262 ast_test_status_update(test, "Failed to allocate a known object type\n");
263 return AST_TEST_FAIL;
264 }
265
266 if (ast_sorcery_create(sorcery, obj)) {
267 ast_test_status_update(test, "Failed to create object using astdb wizard\n");
268 return AST_TEST_FAIL;
269 }
270
271 ao2_cleanup(obj);
272
273 if (!(obj = ast_sorcery_alloc(sorcery, "test", "blah2"))) {
274 ast_test_status_update(test, "Failed to allocate second instance of a known object type\n");
275 return AST_TEST_FAIL;
276 }
277
278 if (ast_sorcery_create(sorcery, obj)) {
279 ast_test_status_update(test, "Failed to create second object using astdb wizard\n");
280 return AST_TEST_FAIL;
281 }
282
284 ast_test_status_update(test, "Failed to retrieve a container of all objects\n");
285 return AST_TEST_FAIL;
286 } else if (ao2_container_count(objects) != 2) {
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;
289 }
290
291 return AST_TEST_PASS;
292}
int ao2_container_count(struct ao2_container *c)
Returns the number of elements in a container.
@ AST_RETRIEVE_FLAG_MULTIPLE
Return all matching objects.
Definition sorcery.h:120
@ AST_RETRIEVE_FLAG_ALL
Perform no matching, return all objects.
Definition sorcery.h:123
Generic container type.

References alloc_and_initialize_sorcery(), ao2_cleanup, ao2_container_count(), AST_RETRIEVE_FLAG_ALL, AST_RETRIEVE_FLAG_MULTIPLE, ast_sorcery_alloc(), ast_sorcery_create(), ast_sorcery_retrieve_by_fields(), AST_TEST_FAIL, AST_TEST_NOT_RUN, AST_TEST_PASS, ast_test_status_update, deinitialize_sorcery(), NULL, RAII_VAR, sorcery, TEST_EXECUTE, and TEST_INIT.

◆ AST_TEST_DEFINE() [7/10]

AST_TEST_DEFINE ( object_retrieve_multiple_field  )

Definition at line 294 of file test_sorcery_astdb.c.

295{
298 RAII_VAR(struct ao2_container *, objects, NULL, ao2_cleanup);
299 RAII_VAR(struct ast_variable *, fields, ast_variable_new("joe >=", "6", ""), ast_variables_destroy);
300
301 switch (cmd) {
302 case TEST_INIT:
303 info->name = "object_retrieve_multiple_field";
304 info->category = "/res/sorcery_astdb/";
305 info->summary = "sorcery multiple object retrieval unit test";
306 info->description =
307 "Test multiple object retrieval in sorcery using fields using astdb wizard";
308 return AST_TEST_NOT_RUN;
309 case TEST_EXECUTE:
310 break;
311 }
312
313 if (!fields) {
314 ast_test_status_update(test, "Failed to create fields for multiple retrieve\n");
315 return AST_TEST_FAIL;
316 }
317
319 ast_test_status_update(test, "Failed to open sorcery structure\n");
320 return AST_TEST_FAIL;
321 }
322
323 if (!(obj = ast_sorcery_alloc(sorcery, "test", "blah"))) {
324 ast_test_status_update(test, "Failed to allocate a known object type\n");
325 return AST_TEST_FAIL;
326 }
327
328 obj->joe = 6;
329
330 if (ast_sorcery_create(sorcery, obj)) {
331 ast_test_status_update(test, "Failed to create object using astdb wizard\n");
332 return AST_TEST_FAIL;
333 }
334
335 if (!(objects = ast_sorcery_retrieve_by_fields(sorcery, "test", AST_RETRIEVE_FLAG_MULTIPLE, fields))) {
336 ast_test_status_update(test, "Failed to retrieve a container of all objects\n");
337 return AST_TEST_FAIL;
338 } else if (ao2_container_count(objects) != 1) {
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;
341 }
342
343 ao2_cleanup(objects);
344 ast_variables_destroy(fields);
345
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;
349 } else if (!(objects = ast_sorcery_retrieve_by_fields(sorcery, "test", AST_RETRIEVE_FLAG_MULTIPLE, fields))) {
350 ast_test_status_update(test, "Failed to retrieve an empty container when retrieving multiple\n");
351 return AST_TEST_FAIL;
352 } else if (ao2_container_count(objects)) {
353 ast_test_status_update(test, "Received a container with objects when there should be none in it\n");
354 return AST_TEST_FAIL;
355 }
356
357 return AST_TEST_PASS;
358}

References alloc_and_initialize_sorcery(), ao2_cleanup, ao2_container_count(), AST_RETRIEVE_FLAG_MULTIPLE, ast_sorcery_alloc(), ast_sorcery_create(), ast_sorcery_retrieve_by_fields(), AST_TEST_FAIL, AST_TEST_NOT_RUN, AST_TEST_PASS, ast_test_status_update, ast_variable_new, ast_variables_destroy(), deinitialize_sorcery(), NULL, RAII_VAR, sorcery, TEST_EXECUTE, and TEST_INIT.

◆ AST_TEST_DEFINE() [8/10]

AST_TEST_DEFINE ( object_retrieve_regex  )

Definition at line 360 of file test_sorcery_astdb.c.

361{
364 RAII_VAR(struct ao2_container *, objects, NULL, ao2_cleanup);
365
366 switch (cmd) {
367 case TEST_INIT:
368 info->name = "object_retrieve_regex";
369 info->category = "/res/sorcery_astdb/";
370 info->summary = "sorcery multiple object retrieval using regex unit test";
371 info->description =
372 "Test multiple object retrieval in sorcery using regular expression for matching using astdb wizard";
373 return AST_TEST_NOT_RUN;
374 case TEST_EXECUTE:
375 break;
376 }
377
379 ast_test_status_update(test, "Failed to open sorcery structure\n");
380 return AST_TEST_FAIL;
381 }
382
383 if (!(obj = ast_sorcery_alloc(sorcery, "test", "blah-98joe"))) {
384 ast_test_status_update(test, "Failed to allocate a known object type\n");
385 return AST_TEST_FAIL;
386 }
387
388 if (ast_sorcery_create(sorcery, obj)) {
389 ast_test_status_update(test, "Failed to create object using astdb wizard\n");
390 return AST_TEST_FAIL;
391 }
392
393 ao2_cleanup(obj);
394
395 if (!(obj = ast_sorcery_alloc(sorcery, "test", "blah-93joe"))) {
396 ast_test_status_update(test, "Failed to allocate second instance of a known object type\n");
397 return AST_TEST_FAIL;
398 }
399
400 if (ast_sorcery_create(sorcery, obj)) {
401 ast_test_status_update(test, "Failed to create second object using astdb wizard\n");
402 return AST_TEST_FAIL;
403 }
404
405 ao2_cleanup(obj);
406
407 if (!(obj = ast_sorcery_alloc(sorcery, "test", "neener-93joe"))) {
408 ast_test_status_update(test, "Failed to allocate third instance of a known object type\n");
409 return AST_TEST_FAIL;
410 }
411
412 if (ast_sorcery_create(sorcery, obj)) {
413 ast_test_status_update(test, "Failed to create third object using astdb wizard\n");
414 return AST_TEST_FAIL;
415 }
416
417 if (!(objects = ast_sorcery_retrieve_by_regex(sorcery, "test", "^blah-"))) {
418 ast_test_status_update(test, "Failed to retrieve a container of objects\n");
419 return AST_TEST_FAIL;
420 } else if (ao2_container_count(objects) != 2) {
421 ast_test_status_update(test, "Received a container with incorrect number of objects in it\n");
422 return AST_TEST_FAIL;
423 }
424
425 return AST_TEST_PASS;
426}
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.
Definition sorcery.c:2018

References alloc_and_initialize_sorcery(), ao2_cleanup, ao2_container_count(), ast_sorcery_alloc(), ast_sorcery_create(), ast_sorcery_retrieve_by_regex(), AST_TEST_FAIL, AST_TEST_NOT_RUN, AST_TEST_PASS, ast_test_status_update, deinitialize_sorcery(), NULL, RAII_VAR, sorcery, TEST_EXECUTE, and TEST_INIT.

◆ AST_TEST_DEFINE() [9/10]

AST_TEST_DEFINE ( object_update  )

Definition at line 428 of file test_sorcery_astdb.c.

429{
433
434 switch (cmd) {
435 case TEST_INIT:
436 info->name = "object_update";
437 info->category = "/res/sorcery_astdb/";
438 info->summary = "sorcery object update unit test";
439 info->description =
440 "Test object updating in sorcery using astdb wizard";
441 return AST_TEST_NOT_RUN;
442 case TEST_EXECUTE:
443 break;
444 }
445
447 ast_test_status_update(test, "Failed to open sorcery structure\n");
448 return AST_TEST_FAIL;
449 }
450
451 if (!(obj = ast_sorcery_alloc(sorcery, "test", "blah"))) {
452 ast_test_status_update(test, "Failed to allocate a known object type\n");
453 return AST_TEST_FAIL;
454 }
455
456 if (ast_sorcery_create(sorcery, obj)) {
457 ast_test_status_update(test, "Failed to create object using astdb wizard\n");
458 return AST_TEST_FAIL;
459 }
460
461 if (!(obj2 = ast_sorcery_copy(sorcery, obj))) {
462 ast_test_status_update(test, "Failed to allocate a known object type for updating\n");
463 return AST_TEST_FAIL;
464 }
465
466 ao2_cleanup(obj);
467
468 obj2->bob = 1000;
469 obj2->joe = 2000;
470
471 if (ast_sorcery_update(sorcery, obj2)) {
472 ast_test_status_update(test, "Failed to update sorcery with new object\n");
473 return AST_TEST_FAIL;
474 }
475
476 if (!(obj = ast_sorcery_retrieve_by_id(sorcery, "test", "blah"))) {
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;
482 }
483
484 return AST_TEST_PASS;
485}
int ast_sorcery_update(const struct ast_sorcery *sorcery, void *object)
Update an object.
Definition sorcery.c:2214
void * ast_sorcery_copy(const struct ast_sorcery *sorcery, const void *object)
Create a copy of an object.
Definition sorcery.c:1842

References alloc_and_initialize_sorcery(), ao2_cleanup, ast_sorcery_alloc(), ast_sorcery_copy(), ast_sorcery_create(), ast_sorcery_retrieve_by_id(), ast_sorcery_update(), AST_TEST_FAIL, AST_TEST_NOT_RUN, AST_TEST_PASS, ast_test_status_update, deinitialize_sorcery(), NULL, RAII_VAR, sorcery, TEST_EXECUTE, and TEST_INIT.

◆ AST_TEST_DEFINE() [10/10]

AST_TEST_DEFINE ( object_update_uncreated  )

Definition at line 487 of file test_sorcery_astdb.c.

488{
491
492 switch (cmd) {
493 case TEST_INIT:
494 info->name = "object_update_uncreated";
495 info->category = "/res/sorcery_astdb/";
496 info->summary = "sorcery object update unit test";
497 info->description =
498 "Test updating of an uncreated object in sorcery using astdb wizard";
499 return AST_TEST_NOT_RUN;
500 case TEST_EXECUTE:
501 break;
502 }
503
505 ast_test_status_update(test, "Failed to open sorcery structure\n");
506 return AST_TEST_FAIL;
507 }
508
509 if (!(obj = ast_sorcery_alloc(sorcery, "test", "blah"))) {
510 ast_test_status_update(test, "Failed to allocate a known object type\n");
511 return AST_TEST_FAIL;
512 }
513
515 if (!ast_sorcery_update(sorcery, obj)) {
516 ast_test_status_update(test, "Successfully updated an object which has not been created yet\n");
517 return AST_TEST_FAIL;
518 }
519
521 if (ast_sorcery_update(sorcery, obj)) {
522 ast_test_status_update(test, "Failed to create object when update() finds no object in a backend\n");
523 return AST_TEST_FAIL;
524 }
525
526 return AST_TEST_PASS;
527}
int ast_sorcery_update_or_create_on_update_miss
Global control for optional update->create fallback in backends.
Definition sorcery.c:288

References alloc_and_initialize_sorcery(), ao2_cleanup, ast_sorcery_alloc(), ast_sorcery_update(), ast_sorcery_update_or_create_on_update_miss, AST_TEST_FAIL, AST_TEST_NOT_RUN, AST_TEST_PASS, ast_test_status_update, deinitialize_sorcery(), NULL, RAII_VAR, sorcery, TEST_EXECUTE, and TEST_INIT.

◆ deinitialize_sorcery()

static void deinitialize_sorcery ( struct ast_sorcery sorcery)
static

Definition at line 73 of file test_sorcery_astdb.c.

74{
75 ast_db_deltree("test/test", NULL);
77}
int ast_db_deltree(const char *family, const char *keytree)
Delete one or more entries in astdb.
Definition db.c:559

References ast_db_deltree(), ast_sorcery_unref, NULL, and sorcery.

Referenced by AST_TEST_DEFINE(), AST_TEST_DEFINE(), AST_TEST_DEFINE(), AST_TEST_DEFINE(), AST_TEST_DEFINE(), AST_TEST_DEFINE(), AST_TEST_DEFINE(), AST_TEST_DEFINE(), AST_TEST_DEFINE(), and AST_TEST_DEFINE().

◆ load_module()

static int load_module ( void  )
static

Definition at line 627 of file test_sorcery_astdb.c.

628{
629 AST_TEST_REGISTER(object_create);
630 AST_TEST_REGISTER(object_retrieve_id);
631 AST_TEST_REGISTER(object_retrieve_field);
632 AST_TEST_REGISTER(object_retrieve_multiple_all);
633 AST_TEST_REGISTER(object_retrieve_multiple_field);
634 AST_TEST_REGISTER(object_retrieve_regex);
635 AST_TEST_REGISTER(object_update);
636 AST_TEST_REGISTER(object_update_uncreated);
637 AST_TEST_REGISTER(object_delete);
638 AST_TEST_REGISTER(object_delete_uncreated);
639
641}
@ AST_MODULE_LOAD_SUCCESS
Definition module.h:70
#define AST_TEST_REGISTER(cb)
Definition test.h:127

References AST_MODULE_LOAD_SUCCESS, and AST_TEST_REGISTER.

◆ test_sorcery_object_alloc()

static void * test_sorcery_object_alloc ( const char *  id)
static

Internal function to allocate a test object.

Definition at line 48 of file test_sorcery_astdb.c.

49{
51}
void * ast_sorcery_generic_alloc(size_t size, ao2_destructor_fn destructor)
Allocate a generic sorcery capable object.
Definition sorcery.c:1792

References ast_sorcery_generic_alloc(), and NULL.

Referenced by alloc_and_initialize_sorcery().

◆ unload_module()

static int unload_module ( void  )
static

Definition at line 611 of file test_sorcery_astdb.c.

612{
613 AST_TEST_UNREGISTER(object_create);
614 AST_TEST_UNREGISTER(object_retrieve_id);
615 AST_TEST_UNREGISTER(object_retrieve_field);
616 AST_TEST_UNREGISTER(object_retrieve_multiple_all);
617 AST_TEST_UNREGISTER(object_retrieve_multiple_field);
618 AST_TEST_UNREGISTER(object_retrieve_regex);
619 AST_TEST_UNREGISTER(object_update);
620 AST_TEST_UNREGISTER(object_update_uncreated);
621 AST_TEST_UNREGISTER(object_delete);
622 AST_TEST_UNREGISTER(object_delete_uncreated);
623
624 return 0;
625}
#define AST_TEST_UNREGISTER(cb)
Definition test.h:128

References AST_TEST_UNREGISTER.

Variable Documentation

◆ __mod_info

struct ast_module_info __mod_info = { .name = AST_MODULE, .flags = AST_MODFLAG_LOAD_ORDER , .description = "Sorcery astdb Wizard test module" , .key = ASTERISK_GPL_KEY , .buildopt_sum = AST_BUILDOPT_SUM, .load = load_module, .unload = unload_module, .load_pri = AST_MODPRI_DEFAULT, .support_level = AST_MODULE_SUPPORT_CORE, }
static

Definition at line 643 of file test_sorcery_astdb.c.

◆ ast_module_info

const struct ast_module_info* ast_module_info = &__mod_info
static

Definition at line 643 of file test_sorcery_astdb.c.