Skip to content
Snippets Groups Projects
test_sorcery_astdb.c 19.1 KiB
Newer Older
  • Learn to ignore specific revisions
  • /*
     * Asterisk -- An open source telephony toolkit.
     *
     * Copyright (C) 2013, Digium, Inc.
     *
     * Joshua Colp <jcolp@digium.com>
     *
     * See http://www.asterisk.org for more information about
     * the Asterisk project. Please do not directly contact
     * any of the maintainers of this project for assistance;
     * the project provides a web site, mailing lists and IRC
     * channels for your use.
     *
     * This program is free software, distributed under the terms of
     * the GNU General Public License Version 2. See the LICENSE file
     * at the top of the source tree.
     */
    
    /*!
     * \file
     * \brief Sorcery Unit Tests
     *
     * \author Joshua Colp <jcolp@digium.com>
     *
     */
    
    /*** MODULEINFO
    	<depend>TEST_FRAMEWORK</depend>
    	<support_level>core</support_level>
     ***/
    
    #include "asterisk.h"
    
    
    ASTERISK_REGISTER_FILE()
    
    
    #include "asterisk/test.h"
    #include "asterisk/module.h"
    #include "asterisk/sorcery.h"
    #include "asterisk/astdb.h"
    #include "asterisk/logger.h"
    
    /*! \brief Dummy sorcery object */
    struct test_sorcery_object {
    	SORCERY_OBJECT(details);
    	unsigned int bob;
    	unsigned int joe;
    };
    
    /*! \brief Internal function to allocate a test object */
    static void *test_sorcery_object_alloc(const char *id)
    {
    
    	return ast_sorcery_generic_alloc(sizeof(struct test_sorcery_object), NULL);
    
    }
    
    static struct ast_sorcery *alloc_and_initialize_sorcery(void)
    {
    	struct ast_sorcery *sorcery;
    
    	if (!(sorcery = ast_sorcery_open())) {
    		return NULL;
    	}
    
    
    	if ((ast_sorcery_apply_default(sorcery, "test", "astdb", "test") != AST_SORCERY_APPLY_SUCCESS) ||
    
    Matthew Jordan's avatar
    Matthew Jordan committed
    		ast_sorcery_internal_object_register(sorcery, "test", test_sorcery_object_alloc, NULL, NULL)) {
    
    Matthew Jordan's avatar
    Matthew Jordan committed
    	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));
    
    71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638
    
    	return sorcery;
    }
    
    static void deinitialize_sorcery(struct ast_sorcery *sorcery)
    {
    	ast_db_deltree("test/test", NULL);
    	ast_sorcery_unref(sorcery);
    }
    
    AST_TEST_DEFINE(object_create)
    {
    	RAII_VAR(struct ast_sorcery *, sorcery, NULL, deinitialize_sorcery);
    	RAII_VAR(struct test_sorcery_object *, obj, NULL, ao2_cleanup);
    	char value[2];
    
    	switch (cmd) {
    	case TEST_INIT:
    		info->name = "object_create";
    		info->category = "/res/sorcery_astdb/";
    		info->summary = "sorcery astdb object creation unit test";
    		info->description =
    			"Test object creation in sorcery using astdb wizard";
    		return AST_TEST_NOT_RUN;
    	case TEST_EXECUTE:
    		break;
    	}
    
    	if (!(sorcery = alloc_and_initialize_sorcery())) {
    		ast_test_status_update(test, "Failed to open sorcery structure\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 astdb wizard\n");
    		return AST_TEST_FAIL;
    	} else if (ast_db_get("test/test", "blah", value, sizeof(value))) {
    		ast_test_status_update(test, "Object was apparently created but does not actually exist in astdb\n");
    		return AST_TEST_FAIL;
    	}
    
    	return AST_TEST_PASS;
    }
    
    AST_TEST_DEFINE(object_retrieve_id)
    {
    	RAII_VAR(struct ast_sorcery *, sorcery, NULL, deinitialize_sorcery);
    	RAII_VAR(struct test_sorcery_object *, obj, NULL, ao2_cleanup);
    
    	switch (cmd) {
    	case TEST_INIT:
    		info->name = "object_retrieve_id";
    		info->category = "/res/sorcery_astdb/";
    		info->summary = "sorcery object retrieval using id unit test";
    		info->description =
    			"Test object retrieval using id in sorcery with astdb wizard";
    		return AST_TEST_NOT_RUN;
    	case TEST_EXECUTE:
    		break;
    	}
    
    	if (!(sorcery = alloc_and_initialize_sorcery())) {
    		ast_test_status_update(test, "Failed to open sorcery structure\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 astdb wizard\n");
    		return AST_TEST_FAIL;
    	}
    
    	ao2_cleanup(obj);
    
    	if (!(obj = ast_sorcery_alloc(sorcery, "test", "blah2"))) {
    		ast_test_status_update(test, "Failed to allocate second instance of a known object type\n");
    		return AST_TEST_FAIL;
    	}
    
    	if (ast_sorcery_create(sorcery, obj)) {
    		ast_test_status_update(test, "Failed to create second object using astdb wizard\n");
    		return AST_TEST_FAIL;
    	}
    
    	ao2_cleanup(obj);
    
    	if (!(obj = ast_sorcery_retrieve_by_id(sorcery, "test", "blah"))) {
    		ast_test_status_update(test, "Failed to retrieve properly created object using id of 'blah'\n");
    		return AST_TEST_FAIL;
    	} else if (strcmp(ast_sorcery_object_get_id(obj), "blah")) {
    		ast_test_status_update(test, "Retrieved object does not have correct id\n");
    		return AST_TEST_FAIL;
    	}
    
    	return AST_TEST_PASS;
    }
    
    AST_TEST_DEFINE(object_retrieve_field)
    {
    	RAII_VAR(struct ast_sorcery *, sorcery, NULL, deinitialize_sorcery);
    	RAII_VAR(struct test_sorcery_object *, obj, NULL, ao2_cleanup);
    	RAII_VAR(struct ast_variable *, fields, ast_variable_new("joe", "42", ""), ast_variables_destroy);
    
    	switch (cmd) {
    	case TEST_INIT:
    		info->name = "object_retrieve_field";
    		info->category = "/res/sorcery_astdb/";
    		info->summary = "sorcery object retrieval using a specific field unit test";
    		info->description =
    			"Test object retrieval using a specific field in sorcery with astdb wizard";
    		return AST_TEST_NOT_RUN;
    	case TEST_EXECUTE:
    		break;
    	}
    
    	if (!fields) {
    		ast_test_status_update(test, "Failed to create fields for object retrieval attempt\n");
    		return AST_TEST_FAIL;
    	}
    
    	if (!(sorcery = alloc_and_initialize_sorcery())) {
    		ast_test_status_update(test, "Failed to open sorcery structure\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;
    	}
    
    	obj->joe = 42;
    
    	if (ast_sorcery_create(sorcery, obj)) {
    		ast_test_status_update(test, "Failed to create object using astdb wizard\n");
    		return AST_TEST_FAIL;
    	}
    
    	ao2_cleanup(obj);
    
    	if (!(obj = ast_sorcery_retrieve_by_fields(sorcery, "test", AST_RETRIEVE_FLAG_DEFAULT, fields))) {
    		ast_test_status_update(test, "Failed to retrieve properly created object using 'joe' field\n");
    		return AST_TEST_FAIL;
    	}
    
    	ao2_cleanup(obj);
    	ast_variables_destroy(fields);
    
    	if (!(fields = ast_variable_new("joe", "49", ""))) {
    		ast_test_status_update(test, "Failed to create fields for object retrieval attempt\n");
    		return AST_TEST_FAIL;
    	}
    
    	if ((obj = ast_sorcery_retrieve_by_fields(sorcery, "test", AST_RETRIEVE_FLAG_DEFAULT, fields))) {
    		ast_test_status_update(test, "Retrieved an object using a field with an in-correct value... that should not happen\n");
    		return AST_TEST_FAIL;
    	}
    
    	return AST_TEST_PASS;
    }
    
    AST_TEST_DEFINE(object_retrieve_multiple_all)
    {
    	RAII_VAR(struct ast_sorcery *, sorcery, NULL, deinitialize_sorcery);
    	RAII_VAR(struct test_sorcery_object *, obj, NULL, ao2_cleanup);
    	RAII_VAR(struct ao2_container *, objects, NULL, ao2_cleanup);
    
    	switch (cmd) {
    	case TEST_INIT:
    		info->name = "object_retrieve_multiple_all";
    		info->category = "/res/sorcery_astdb/";
    		info->summary = "sorcery multiple object retrieval unit test";
    		info->description =
    			"Test multiple object retrieval in sorcery using astdb wizard";
    		return AST_TEST_NOT_RUN;
    	case TEST_EXECUTE:
    		break;
    	}
    
    	if (!(sorcery = alloc_and_initialize_sorcery())) {
    		ast_test_status_update(test, "Failed to open sorcery structure\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 astdb wizard\n");
    		return AST_TEST_FAIL;
    	}
    
    	ao2_cleanup(obj);
    
    	if (!(obj = ast_sorcery_alloc(sorcery, "test", "blah2"))) {
    		ast_test_status_update(test, "Failed to allocate second instance of a known object type\n");
    		return AST_TEST_FAIL;
    	}
    
    	if (ast_sorcery_create(sorcery, obj)) {
    		ast_test_status_update(test, "Failed to create second object using astdb wizard\n");
    		return AST_TEST_FAIL;
    	}
    
    	if (!(objects = ast_sorcery_retrieve_by_fields(sorcery, "test", AST_RETRIEVE_FLAG_MULTIPLE | AST_RETRIEVE_FLAG_ALL, NULL))) {
    		ast_test_status_update(test, "Failed to retrieve a container of all objects\n");
    		return AST_TEST_FAIL;
    	} else if (ao2_container_count(objects) != 2) {
    		ast_test_status_update(test, "Received a container with no objects in it when there should be some\n");
    		return AST_TEST_FAIL;
    	}
    
    	return AST_TEST_PASS;
    }
    
    AST_TEST_DEFINE(object_retrieve_multiple_field)
    {
    	RAII_VAR(struct ast_sorcery *, sorcery, NULL, deinitialize_sorcery);
    	RAII_VAR(struct test_sorcery_object *, obj, NULL, ao2_cleanup);
    	RAII_VAR(struct ao2_container *, objects, NULL, ao2_cleanup);
    	RAII_VAR(struct ast_variable *, fields, ast_variable_new("joe", "6", ""), ast_variables_destroy);
    
    	switch (cmd) {
    	case TEST_INIT:
    		info->name = "object_retrieve_multiple_field";
    		info->category = "/res/sorcery_astdb/";
    		info->summary = "sorcery multiple object retrieval unit test";
    		info->description =
    			"Test multiple object retrieval in sorcery using fields using astdb wizard";
    		return AST_TEST_NOT_RUN;
    	case TEST_EXECUTE:
    		break;
    	}
    
    	if (!fields) {
    		ast_test_status_update(test, "Failed to create fields for multiple retrieve\n");
    		return AST_TEST_FAIL;
    	}
    
    	if (!(sorcery = alloc_and_initialize_sorcery())) {
    		ast_test_status_update(test, "Failed to open sorcery structure\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;
    	}
    
    	obj->joe = 6;
    
    	if (ast_sorcery_create(sorcery, obj)) {
    		ast_test_status_update(test, "Failed to create object using astdb wizard\n");
    		return AST_TEST_FAIL;
    	}
    
    	if (!(objects = ast_sorcery_retrieve_by_fields(sorcery, "test", AST_RETRIEVE_FLAG_MULTIPLE, fields))) {
    		ast_test_status_update(test, "Failed to retrieve a container of all objects\n");
    		return AST_TEST_FAIL;
    	} else if (ao2_container_count(objects) != 1) {
    		ast_test_status_update(test, "Received a container with no objects in it when there should be some\n");
    		return AST_TEST_FAIL;
    	}
    
    	ao2_cleanup(objects);
    	ast_variables_destroy(fields);
    
    	if (!(fields = ast_variable_new("joe", "7", ""))) {
    		ast_test_status_update(test, "Failed to create fields for multiple retrieval\n");
    		return AST_TEST_FAIL;
    	} else if (!(objects = ast_sorcery_retrieve_by_fields(sorcery, "test", AST_RETRIEVE_FLAG_MULTIPLE, fields))) {
    		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;
    	}
    
    	return AST_TEST_PASS;
    }
    
    AST_TEST_DEFINE(object_retrieve_regex)
    {
    	RAII_VAR(struct ast_sorcery *, sorcery, NULL, deinitialize_sorcery);
    	RAII_VAR(struct test_sorcery_object *, obj, NULL, ao2_cleanup);
    	RAII_VAR(struct ao2_container *, objects, NULL, ao2_cleanup);
    
    	switch (cmd) {
    	case TEST_INIT:
    		info->name = "object_retrieve_regex";
    		info->category = "/res/sorcery_astdb/";
    		info->summary = "sorcery multiple object retrieval using regex unit test";
    		info->description =
    			"Test multiple object retrieval in sorcery using regular expression for matching using astdb wizard";
    		return AST_TEST_NOT_RUN;
    	case TEST_EXECUTE:
    		break;
    	}
    
    	if (!(sorcery = alloc_and_initialize_sorcery())) {
    		ast_test_status_update(test, "Failed to open sorcery structure\n");
    		return AST_TEST_FAIL;
    	}
    
    	if (!(obj = ast_sorcery_alloc(sorcery, "test", "blah-98joe"))) {
    		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 astdb wizard\n");
    		return AST_TEST_FAIL;
    	}
    
    	ao2_cleanup(obj);
    
    	if (!(obj = ast_sorcery_alloc(sorcery, "test", "blah-93joe"))) {
    		ast_test_status_update(test, "Failed to allocate second instance of a known object type\n");
    		return AST_TEST_FAIL;
    	}
    
    	if (ast_sorcery_create(sorcery, obj)) {
    		ast_test_status_update(test, "Failed to create second object using astdb wizard\n");
    		return AST_TEST_FAIL;
    	}
    
    	ao2_cleanup(obj);
    
    	if (!(obj = ast_sorcery_alloc(sorcery, "test", "neener-93joe"))) {
    		ast_test_status_update(test, "Failed to allocate third instance of a known object type\n");
    		return AST_TEST_FAIL;
    	}
    
    	if (ast_sorcery_create(sorcery, obj)) {
    		ast_test_status_update(test, "Failed to create third object using astdb wizard\n");
    		return AST_TEST_FAIL;
    	}
    
    	if (!(objects = ast_sorcery_retrieve_by_regex(sorcery, "test", "^blah-"))) {
    		ast_test_status_update(test, "Failed to retrieve a container of objects\n");
    		return AST_TEST_FAIL;
    	} else if (ao2_container_count(objects) != 2) {
    		ast_test_status_update(test, "Received a container with incorrect number of objects in it\n");
    		return AST_TEST_FAIL;
    	}
    
    	return AST_TEST_PASS;
    }
    
    AST_TEST_DEFINE(object_update)
    {
    	RAII_VAR(struct ast_sorcery *, sorcery, NULL, deinitialize_sorcery);
    	RAII_VAR(struct test_sorcery_object *, obj, NULL, ao2_cleanup);
    	RAII_VAR(struct test_sorcery_object *, obj2, NULL, ao2_cleanup);
    
    	switch (cmd) {
    	case TEST_INIT:
    		info->name = "object_update";
    		info->category = "/res/sorcery_astdb/";
    		info->summary = "sorcery object update unit test";
    		info->description =
    			"Test object updating in sorcery using astdb wizard";
    		return AST_TEST_NOT_RUN;
    	case TEST_EXECUTE:
    		break;
    	}
    
    	if (!(sorcery = alloc_and_initialize_sorcery())) {
    		ast_test_status_update(test, "Failed to open sorcery structure\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 astdb wizard\n");
    		return AST_TEST_FAIL;
    	}
    
    	if (!(obj2 = ast_sorcery_copy(sorcery, obj))) {
    		ast_test_status_update(test, "Failed to allocate a known object type for updating\n");
    		return AST_TEST_FAIL;
    	}
    
    	ao2_cleanup(obj);
    
    	obj2->bob = 1000;
    	obj2->joe = 2000;
    
    	if (ast_sorcery_update(sorcery, obj2)) {
    		ast_test_status_update(test, "Failed to update sorcery with new object\n");
    		return AST_TEST_FAIL;
    	}
    
    	if (!(obj = ast_sorcery_retrieve_by_id(sorcery, "test", "blah"))) {
    		ast_test_status_update(test, "Failed to retrieve properly updated object\n");
    		return AST_TEST_FAIL;
    	} else if ((obj->bob != obj2->bob) || (obj->joe != obj2->joe)) {
    		ast_test_status_update(test, "Object retrieved is not the updated object\n");
    		return AST_TEST_FAIL;
    	}
    
    	return AST_TEST_PASS;
    }
    
    AST_TEST_DEFINE(object_update_uncreated)
    {
    	RAII_VAR(struct ast_sorcery *, sorcery, NULL, deinitialize_sorcery);
    	RAII_VAR(struct test_sorcery_object *, obj, NULL, ao2_cleanup);
    
    	switch (cmd) {
    	case TEST_INIT:
    		info->name = "object_update_uncreated";
    		info->category = "/res/sorcery_astdb/";
    		info->summary = "sorcery object update unit test";
    		info->description =
    			"Test updating of an uncreated object in sorcery using astdb wizard";
    		return AST_TEST_NOT_RUN;
    	case TEST_EXECUTE:
    		break;
    	}
    
    	if (!(sorcery = alloc_and_initialize_sorcery())) {
    		ast_test_status_update(test, "Failed to open sorcery structure\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_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, deinitialize_sorcery);
    	RAII_VAR(struct test_sorcery_object *, obj, NULL, ao2_cleanup);
    
    	switch (cmd) {
    	case TEST_INIT:
    		info->name = "object_delete";
    		info->category = "/res/sorcery_astdb/";
    		info->summary = "sorcery object deletion unit test";
    		info->description =
    			"Test object deletion in sorcery using astdb wizard";
    		return AST_TEST_NOT_RUN;
    	case TEST_EXECUTE:
    		break;
    	}
    
    	if (!(sorcery = alloc_and_initialize_sorcery())) {
    		ast_test_status_update(test, "Failed to open sorcery structure\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 astdb wizard\n");
    		return AST_TEST_FAIL;
    	}
    
    	if (ast_sorcery_delete(sorcery, obj)) {
    		ast_test_status_update(test, "Failed to delete object using astdb wizard\n");
    		return AST_TEST_FAIL;
    	}
    
    	ao2_cleanup(obj);
    
    	if ((obj = ast_sorcery_retrieve_by_id(sorcery, "test", "blah"))) {
    		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, deinitialize_sorcery);
    	RAII_VAR(struct test_sorcery_object *, obj, NULL, ao2_cleanup);
    
    	switch (cmd) {
    	case TEST_INIT:
    		info->name = "object_delete_uncreated";
    		info->category = "/res/sorcery_astdb/";
    		info->summary = "sorcery object deletion unit test";
    		info->description =
    			"Test object deletion of an uncreated object in sorcery using astdb wizard";
    		return AST_TEST_NOT_RUN;
    	case TEST_EXECUTE:
    		break;
    	}
    
    	if (!(sorcery = alloc_and_initialize_sorcery())) {
    		ast_test_status_update(test, "Failed to open sorcery structure\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;
    	}
    
    	return AST_TEST_PASS;
    }
    
    static int unload_module(void)
    {
    	AST_TEST_UNREGISTER(object_create);
    	AST_TEST_UNREGISTER(object_retrieve_id);
    	AST_TEST_UNREGISTER(object_retrieve_field);
    	AST_TEST_UNREGISTER(object_retrieve_multiple_all);
    	AST_TEST_UNREGISTER(object_retrieve_multiple_field);
    	AST_TEST_UNREGISTER(object_retrieve_regex);
    	AST_TEST_UNREGISTER(object_update);
    	AST_TEST_UNREGISTER(object_update_uncreated);
    	AST_TEST_UNREGISTER(object_delete);
    	AST_TEST_UNREGISTER(object_delete_uncreated);
    
    	return 0;
    }
    
    static int load_module(void)
    {
    	AST_TEST_REGISTER(object_create);
    	AST_TEST_REGISTER(object_retrieve_id);
    	AST_TEST_REGISTER(object_retrieve_field);
    	AST_TEST_REGISTER(object_retrieve_multiple_all);
    	AST_TEST_REGISTER(object_retrieve_multiple_field);
    	AST_TEST_REGISTER(object_retrieve_regex);
    	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;
    }
    
    AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "Sorcery astdb Wizard test module");