test_sorcery_astdb.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638
  1. /*
  2. * Asterisk -- An open source telephony toolkit.
  3. *
  4. * Copyright (C) 2013, Digium, Inc.
  5. *
  6. * Joshua Colp <jcolp@digium.com>
  7. *
  8. * See http://www.asterisk.org for more information about
  9. * the Asterisk project. Please do not directly contact
  10. * any of the maintainers of this project for assistance;
  11. * the project provides a web site, mailing lists and IRC
  12. * channels for your use.
  13. *
  14. * This program is free software, distributed under the terms of
  15. * the GNU General Public License Version 2. See the LICENSE file
  16. * at the top of the source tree.
  17. */
  18. /*!
  19. * \file
  20. * \brief Sorcery Unit Tests
  21. *
  22. * \author Joshua Colp <jcolp@digium.com>
  23. *
  24. */
  25. /*** MODULEINFO
  26. <depend>TEST_FRAMEWORK</depend>
  27. <support_level>core</support_level>
  28. ***/
  29. #include "asterisk.h"
  30. ASTERISK_FILE_VERSION(__FILE__, "")
  31. #include "asterisk/test.h"
  32. #include "asterisk/module.h"
  33. #include "asterisk/sorcery.h"
  34. #include "asterisk/astdb.h"
  35. #include "asterisk/logger.h"
  36. /*! \brief Dummy sorcery object */
  37. struct test_sorcery_object {
  38. SORCERY_OBJECT(details);
  39. unsigned int bob;
  40. unsigned int joe;
  41. };
  42. /*! \brief Internal function to allocate a test object */
  43. static void *test_sorcery_object_alloc(const char *id)
  44. {
  45. return ast_sorcery_generic_alloc(sizeof(struct test_sorcery_object), NULL);
  46. }
  47. static struct ast_sorcery *alloc_and_initialize_sorcery(void)
  48. {
  49. struct ast_sorcery *sorcery;
  50. if (!(sorcery = ast_sorcery_open())) {
  51. return NULL;
  52. }
  53. if ((ast_sorcery_apply_default(sorcery, "test", "astdb", "test") != AST_SORCERY_APPLY_SUCCESS) ||
  54. ast_sorcery_internal_object_register(sorcery, "test", test_sorcery_object_alloc, NULL, NULL)) {
  55. ast_sorcery_unref(sorcery);
  56. return NULL;
  57. }
  58. ast_sorcery_object_field_register_nodoc(sorcery, "test", "bob", "5", OPT_UINT_T, 0, FLDSET(struct test_sorcery_object, bob));
  59. ast_sorcery_object_field_register_nodoc(sorcery, "test", "joe", "10", OPT_UINT_T, 0, FLDSET(struct test_sorcery_object, joe));
  60. return sorcery;
  61. }
  62. static void deinitialize_sorcery(struct ast_sorcery *sorcery)
  63. {
  64. ast_db_deltree("test/test", NULL);
  65. ast_sorcery_unref(sorcery);
  66. }
  67. AST_TEST_DEFINE(object_create)
  68. {
  69. RAII_VAR(struct ast_sorcery *, sorcery, NULL, deinitialize_sorcery);
  70. RAII_VAR(struct test_sorcery_object *, obj, NULL, ao2_cleanup);
  71. char value[2];
  72. switch (cmd) {
  73. case TEST_INIT:
  74. info->name = "object_create";
  75. info->category = "/res/sorcery_astdb/";
  76. info->summary = "sorcery astdb object creation unit test";
  77. info->description =
  78. "Test object creation in sorcery using astdb wizard";
  79. return AST_TEST_NOT_RUN;
  80. case TEST_EXECUTE:
  81. break;
  82. }
  83. if (!(sorcery = alloc_and_initialize_sorcery())) {
  84. ast_test_status_update(test, "Failed to open sorcery structure\n");
  85. return AST_TEST_FAIL;
  86. }
  87. if (!(obj = ast_sorcery_alloc(sorcery, "test", "blah"))) {
  88. ast_test_status_update(test, "Failed to allocate a known object type\n");
  89. return AST_TEST_FAIL;
  90. }
  91. if (ast_sorcery_create(sorcery, obj)) {
  92. ast_test_status_update(test, "Failed to create object using astdb wizard\n");
  93. return AST_TEST_FAIL;
  94. } else if (ast_db_get("test/test", "blah", value, sizeof(value))) {
  95. ast_test_status_update(test, "Object was apparently created but does not actually exist in astdb\n");
  96. return AST_TEST_FAIL;
  97. }
  98. return AST_TEST_PASS;
  99. }
  100. AST_TEST_DEFINE(object_retrieve_id)
  101. {
  102. RAII_VAR(struct ast_sorcery *, sorcery, NULL, deinitialize_sorcery);
  103. RAII_VAR(struct test_sorcery_object *, obj, NULL, ao2_cleanup);
  104. switch (cmd) {
  105. case TEST_INIT:
  106. info->name = "object_retrieve_id";
  107. info->category = "/res/sorcery_astdb/";
  108. info->summary = "sorcery object retrieval using id unit test";
  109. info->description =
  110. "Test object retrieval using id in sorcery with astdb wizard";
  111. return AST_TEST_NOT_RUN;
  112. case TEST_EXECUTE:
  113. break;
  114. }
  115. if (!(sorcery = alloc_and_initialize_sorcery())) {
  116. ast_test_status_update(test, "Failed to open sorcery structure\n");
  117. return AST_TEST_FAIL;
  118. }
  119. if (!(obj = ast_sorcery_alloc(sorcery, "test", "blah"))) {
  120. ast_test_status_update(test, "Failed to allocate a known object type\n");
  121. return AST_TEST_FAIL;
  122. }
  123. if (ast_sorcery_create(sorcery, obj)) {
  124. ast_test_status_update(test, "Failed to create object using astdb wizard\n");
  125. return AST_TEST_FAIL;
  126. }
  127. ao2_cleanup(obj);
  128. if (!(obj = ast_sorcery_alloc(sorcery, "test", "blah2"))) {
  129. ast_test_status_update(test, "Failed to allocate second instance of a known object type\n");
  130. return AST_TEST_FAIL;
  131. }
  132. if (ast_sorcery_create(sorcery, obj)) {
  133. ast_test_status_update(test, "Failed to create second object using astdb wizard\n");
  134. return AST_TEST_FAIL;
  135. }
  136. ao2_cleanup(obj);
  137. if (!(obj = ast_sorcery_retrieve_by_id(sorcery, "test", "blah"))) {
  138. ast_test_status_update(test, "Failed to retrieve properly created object using id of 'blah'\n");
  139. return AST_TEST_FAIL;
  140. } else if (strcmp(ast_sorcery_object_get_id(obj), "blah")) {
  141. ast_test_status_update(test, "Retrieved object does not have correct id\n");
  142. return AST_TEST_FAIL;
  143. }
  144. return AST_TEST_PASS;
  145. }
  146. AST_TEST_DEFINE(object_retrieve_field)
  147. {
  148. RAII_VAR(struct ast_sorcery *, sorcery, NULL, deinitialize_sorcery);
  149. RAII_VAR(struct test_sorcery_object *, obj, NULL, ao2_cleanup);
  150. RAII_VAR(struct ast_variable *, fields, ast_variable_new("joe", "42", ""), ast_variables_destroy);
  151. switch (cmd) {
  152. case TEST_INIT:
  153. info->name = "object_retrieve_field";
  154. info->category = "/res/sorcery_astdb/";
  155. info->summary = "sorcery object retrieval using a specific field unit test";
  156. info->description =
  157. "Test object retrieval using a specific field in sorcery with astdb wizard";
  158. return AST_TEST_NOT_RUN;
  159. case TEST_EXECUTE:
  160. break;
  161. }
  162. if (!fields) {
  163. ast_test_status_update(test, "Failed to create fields for object retrieval attempt\n");
  164. return AST_TEST_FAIL;
  165. }
  166. if (!(sorcery = alloc_and_initialize_sorcery())) {
  167. ast_test_status_update(test, "Failed to open sorcery structure\n");
  168. return AST_TEST_FAIL;
  169. }
  170. if (!(obj = ast_sorcery_alloc(sorcery, "test", "blah"))) {
  171. ast_test_status_update(test, "Failed to allocate a known object type\n");
  172. return AST_TEST_FAIL;
  173. }
  174. obj->joe = 42;
  175. if (ast_sorcery_create(sorcery, obj)) {
  176. ast_test_status_update(test, "Failed to create object using astdb wizard\n");
  177. return AST_TEST_FAIL;
  178. }
  179. ao2_cleanup(obj);
  180. if (!(obj = ast_sorcery_retrieve_by_fields(sorcery, "test", AST_RETRIEVE_FLAG_DEFAULT, fields))) {
  181. ast_test_status_update(test, "Failed to retrieve properly created object using 'joe' field\n");
  182. return AST_TEST_FAIL;
  183. }
  184. ao2_cleanup(obj);
  185. ast_variables_destroy(fields);
  186. if (!(fields = ast_variable_new("joe", "49", ""))) {
  187. ast_test_status_update(test, "Failed to create fields for object retrieval attempt\n");
  188. return AST_TEST_FAIL;
  189. }
  190. if ((obj = ast_sorcery_retrieve_by_fields(sorcery, "test", AST_RETRIEVE_FLAG_DEFAULT, fields))) {
  191. ast_test_status_update(test, "Retrieved an object using a field with an in-correct value... that should not happen\n");
  192. return AST_TEST_FAIL;
  193. }
  194. return AST_TEST_PASS;
  195. }
  196. AST_TEST_DEFINE(object_retrieve_multiple_all)
  197. {
  198. RAII_VAR(struct ast_sorcery *, sorcery, NULL, deinitialize_sorcery);
  199. RAII_VAR(struct test_sorcery_object *, obj, NULL, ao2_cleanup);
  200. RAII_VAR(struct ao2_container *, objects, NULL, ao2_cleanup);
  201. switch (cmd) {
  202. case TEST_INIT:
  203. info->name = "object_retrieve_multiple_all";
  204. info->category = "/res/sorcery_astdb/";
  205. info->summary = "sorcery multiple object retrieval unit test";
  206. info->description =
  207. "Test multiple object retrieval in sorcery using astdb wizard";
  208. return AST_TEST_NOT_RUN;
  209. case TEST_EXECUTE:
  210. break;
  211. }
  212. if (!(sorcery = alloc_and_initialize_sorcery())) {
  213. ast_test_status_update(test, "Failed to open sorcery structure\n");
  214. return AST_TEST_FAIL;
  215. }
  216. if (!(obj = ast_sorcery_alloc(sorcery, "test", "blah"))) {
  217. ast_test_status_update(test, "Failed to allocate a known object type\n");
  218. return AST_TEST_FAIL;
  219. }
  220. if (ast_sorcery_create(sorcery, obj)) {
  221. ast_test_status_update(test, "Failed to create object using astdb wizard\n");
  222. return AST_TEST_FAIL;
  223. }
  224. ao2_cleanup(obj);
  225. if (!(obj = ast_sorcery_alloc(sorcery, "test", "blah2"))) {
  226. ast_test_status_update(test, "Failed to allocate second instance of a known object type\n");
  227. return AST_TEST_FAIL;
  228. }
  229. if (ast_sorcery_create(sorcery, obj)) {
  230. ast_test_status_update(test, "Failed to create second object using astdb wizard\n");
  231. return AST_TEST_FAIL;
  232. }
  233. if (!(objects = ast_sorcery_retrieve_by_fields(sorcery, "test", AST_RETRIEVE_FLAG_MULTIPLE | AST_RETRIEVE_FLAG_ALL, NULL))) {
  234. ast_test_status_update(test, "Failed to retrieve a container of all objects\n");
  235. return AST_TEST_FAIL;
  236. } else if (ao2_container_count(objects) != 2) {
  237. ast_test_status_update(test, "Received a container with no objects in it when there should be some\n");
  238. return AST_TEST_FAIL;
  239. }
  240. return AST_TEST_PASS;
  241. }
  242. AST_TEST_DEFINE(object_retrieve_multiple_field)
  243. {
  244. RAII_VAR(struct ast_sorcery *, sorcery, NULL, deinitialize_sorcery);
  245. RAII_VAR(struct test_sorcery_object *, obj, NULL, ao2_cleanup);
  246. RAII_VAR(struct ao2_container *, objects, NULL, ao2_cleanup);
  247. RAII_VAR(struct ast_variable *, fields, ast_variable_new("joe >=", "6", ""), ast_variables_destroy);
  248. switch (cmd) {
  249. case TEST_INIT:
  250. info->name = "object_retrieve_multiple_field";
  251. info->category = "/res/sorcery_astdb/";
  252. info->summary = "sorcery multiple object retrieval unit test";
  253. info->description =
  254. "Test multiple object retrieval in sorcery using fields using astdb wizard";
  255. return AST_TEST_NOT_RUN;
  256. case TEST_EXECUTE:
  257. break;
  258. }
  259. if (!fields) {
  260. ast_test_status_update(test, "Failed to create fields for multiple retrieve\n");
  261. return AST_TEST_FAIL;
  262. }
  263. if (!(sorcery = alloc_and_initialize_sorcery())) {
  264. ast_test_status_update(test, "Failed to open sorcery structure\n");
  265. return AST_TEST_FAIL;
  266. }
  267. if (!(obj = ast_sorcery_alloc(sorcery, "test", "blah"))) {
  268. ast_test_status_update(test, "Failed to allocate a known object type\n");
  269. return AST_TEST_FAIL;
  270. }
  271. obj->joe = 6;
  272. if (ast_sorcery_create(sorcery, obj)) {
  273. ast_test_status_update(test, "Failed to create object using astdb wizard\n");
  274. return AST_TEST_FAIL;
  275. }
  276. if (!(objects = ast_sorcery_retrieve_by_fields(sorcery, "test", AST_RETRIEVE_FLAG_MULTIPLE, fields))) {
  277. ast_test_status_update(test, "Failed to retrieve a container of all objects\n");
  278. return AST_TEST_FAIL;
  279. } else if (ao2_container_count(objects) != 1) {
  280. ast_test_status_update(test, "Received a container with no objects in it when there should be some\n");
  281. return AST_TEST_FAIL;
  282. }
  283. ao2_cleanup(objects);
  284. ast_variables_destroy(fields);
  285. if (!(fields = ast_variable_new("joe <", "6", ""))) {
  286. ast_test_status_update(test, "Failed to create fields for multiple retrieval\n");
  287. return AST_TEST_FAIL;
  288. } else if (!(objects = ast_sorcery_retrieve_by_fields(sorcery, "test", AST_RETRIEVE_FLAG_MULTIPLE, fields))) {
  289. ast_test_status_update(test, "Failed to retrieve an empty container when retrieving multiple\n");
  290. return AST_TEST_FAIL;
  291. } else if (ao2_container_count(objects)) {
  292. ast_test_status_update(test, "Received a container with objects when there should be none in it\n");
  293. return AST_TEST_FAIL;
  294. }
  295. return AST_TEST_PASS;
  296. }
  297. AST_TEST_DEFINE(object_retrieve_regex)
  298. {
  299. RAII_VAR(struct ast_sorcery *, sorcery, NULL, deinitialize_sorcery);
  300. RAII_VAR(struct test_sorcery_object *, obj, NULL, ao2_cleanup);
  301. RAII_VAR(struct ao2_container *, objects, NULL, ao2_cleanup);
  302. switch (cmd) {
  303. case TEST_INIT:
  304. info->name = "object_retrieve_regex";
  305. info->category = "/res/sorcery_astdb/";
  306. info->summary = "sorcery multiple object retrieval using regex unit test";
  307. info->description =
  308. "Test multiple object retrieval in sorcery using regular expression for matching using astdb wizard";
  309. return AST_TEST_NOT_RUN;
  310. case TEST_EXECUTE:
  311. break;
  312. }
  313. if (!(sorcery = alloc_and_initialize_sorcery())) {
  314. ast_test_status_update(test, "Failed to open sorcery structure\n");
  315. return AST_TEST_FAIL;
  316. }
  317. if (!(obj = ast_sorcery_alloc(sorcery, "test", "blah-98joe"))) {
  318. ast_test_status_update(test, "Failed to allocate a known object type\n");
  319. return AST_TEST_FAIL;
  320. }
  321. if (ast_sorcery_create(sorcery, obj)) {
  322. ast_test_status_update(test, "Failed to create object using astdb wizard\n");
  323. return AST_TEST_FAIL;
  324. }
  325. ao2_cleanup(obj);
  326. if (!(obj = ast_sorcery_alloc(sorcery, "test", "blah-93joe"))) {
  327. ast_test_status_update(test, "Failed to allocate second instance of a known object type\n");
  328. return AST_TEST_FAIL;
  329. }
  330. if (ast_sorcery_create(sorcery, obj)) {
  331. ast_test_status_update(test, "Failed to create second object using astdb wizard\n");
  332. return AST_TEST_FAIL;
  333. }
  334. ao2_cleanup(obj);
  335. if (!(obj = ast_sorcery_alloc(sorcery, "test", "neener-93joe"))) {
  336. ast_test_status_update(test, "Failed to allocate third instance of a known object type\n");
  337. return AST_TEST_FAIL;
  338. }
  339. if (ast_sorcery_create(sorcery, obj)) {
  340. ast_test_status_update(test, "Failed to create third object using astdb wizard\n");
  341. return AST_TEST_FAIL;
  342. }
  343. if (!(objects = ast_sorcery_retrieve_by_regex(sorcery, "test", "^blah-"))) {
  344. ast_test_status_update(test, "Failed to retrieve a container of objects\n");
  345. return AST_TEST_FAIL;
  346. } else if (ao2_container_count(objects) != 2) {
  347. ast_test_status_update(test, "Received a container with incorrect number of objects in it\n");
  348. return AST_TEST_FAIL;
  349. }
  350. return AST_TEST_PASS;
  351. }
  352. AST_TEST_DEFINE(object_update)
  353. {
  354. RAII_VAR(struct ast_sorcery *, sorcery, NULL, deinitialize_sorcery);
  355. RAII_VAR(struct test_sorcery_object *, obj, NULL, ao2_cleanup);
  356. RAII_VAR(struct test_sorcery_object *, obj2, NULL, ao2_cleanup);
  357. switch (cmd) {
  358. case TEST_INIT:
  359. info->name = "object_update";
  360. info->category = "/res/sorcery_astdb/";
  361. info->summary = "sorcery object update unit test";
  362. info->description =
  363. "Test object updating in sorcery using astdb wizard";
  364. return AST_TEST_NOT_RUN;
  365. case TEST_EXECUTE:
  366. break;
  367. }
  368. if (!(sorcery = alloc_and_initialize_sorcery())) {
  369. ast_test_status_update(test, "Failed to open sorcery structure\n");
  370. return AST_TEST_FAIL;
  371. }
  372. if (!(obj = ast_sorcery_alloc(sorcery, "test", "blah"))) {
  373. ast_test_status_update(test, "Failed to allocate a known object type\n");
  374. return AST_TEST_FAIL;
  375. }
  376. if (ast_sorcery_create(sorcery, obj)) {
  377. ast_test_status_update(test, "Failed to create object using astdb wizard\n");
  378. return AST_TEST_FAIL;
  379. }
  380. if (!(obj2 = ast_sorcery_copy(sorcery, obj))) {
  381. ast_test_status_update(test, "Failed to allocate a known object type for updating\n");
  382. return AST_TEST_FAIL;
  383. }
  384. ao2_cleanup(obj);
  385. obj2->bob = 1000;
  386. obj2->joe = 2000;
  387. if (ast_sorcery_update(sorcery, obj2)) {
  388. ast_test_status_update(test, "Failed to update sorcery with new object\n");
  389. return AST_TEST_FAIL;
  390. }
  391. if (!(obj = ast_sorcery_retrieve_by_id(sorcery, "test", "blah"))) {
  392. ast_test_status_update(test, "Failed to retrieve properly updated object\n");
  393. return AST_TEST_FAIL;
  394. } else if ((obj->bob != obj2->bob) || (obj->joe != obj2->joe)) {
  395. ast_test_status_update(test, "Object retrieved is not the updated object\n");
  396. return AST_TEST_FAIL;
  397. }
  398. return AST_TEST_PASS;
  399. }
  400. AST_TEST_DEFINE(object_update_uncreated)
  401. {
  402. RAII_VAR(struct ast_sorcery *, sorcery, NULL, deinitialize_sorcery);
  403. RAII_VAR(struct test_sorcery_object *, obj, NULL, ao2_cleanup);
  404. switch (cmd) {
  405. case TEST_INIT:
  406. info->name = "object_update_uncreated";
  407. info->category = "/res/sorcery_astdb/";
  408. info->summary = "sorcery object update unit test";
  409. info->description =
  410. "Test updating of an uncreated object in sorcery using astdb wizard";
  411. return AST_TEST_NOT_RUN;
  412. case TEST_EXECUTE:
  413. break;
  414. }
  415. if (!(sorcery = alloc_and_initialize_sorcery())) {
  416. ast_test_status_update(test, "Failed to open sorcery structure\n");
  417. return AST_TEST_FAIL;
  418. }
  419. if (!(obj = ast_sorcery_alloc(sorcery, "test", "blah"))) {
  420. ast_test_status_update(test, "Failed to allocate a known object type\n");
  421. return AST_TEST_FAIL;
  422. }
  423. if (!ast_sorcery_update(sorcery, obj)) {
  424. ast_test_status_update(test, "Successfully updated an object which has not been created yet\n");
  425. return AST_TEST_FAIL;
  426. }
  427. return AST_TEST_PASS;
  428. }
  429. AST_TEST_DEFINE(object_delete)
  430. {
  431. RAII_VAR(struct ast_sorcery *, sorcery, NULL, deinitialize_sorcery);
  432. RAII_VAR(struct test_sorcery_object *, obj, NULL, ao2_cleanup);
  433. switch (cmd) {
  434. case TEST_INIT:
  435. info->name = "object_delete";
  436. info->category = "/res/sorcery_astdb/";
  437. info->summary = "sorcery object deletion unit test";
  438. info->description =
  439. "Test object deletion in sorcery using astdb wizard";
  440. return AST_TEST_NOT_RUN;
  441. case TEST_EXECUTE:
  442. break;
  443. }
  444. if (!(sorcery = alloc_and_initialize_sorcery())) {
  445. ast_test_status_update(test, "Failed to open sorcery structure\n");
  446. return AST_TEST_FAIL;
  447. }
  448. if (!(obj = ast_sorcery_alloc(sorcery, "test", "blah"))) {
  449. ast_test_status_update(test, "Failed to allocate a known object type\n");
  450. return AST_TEST_FAIL;
  451. }
  452. if (ast_sorcery_create(sorcery, obj)) {
  453. ast_test_status_update(test, "Failed to create object using astdb wizard\n");
  454. return AST_TEST_FAIL;
  455. }
  456. if (ast_sorcery_delete(sorcery, obj)) {
  457. ast_test_status_update(test, "Failed to delete object using astdb wizard\n");
  458. return AST_TEST_FAIL;
  459. }
  460. ao2_cleanup(obj);
  461. if ((obj = ast_sorcery_retrieve_by_id(sorcery, "test", "blah"))) {
  462. ast_test_status_update(test, "Retrieved deleted object that should not be there\n");
  463. return AST_TEST_FAIL;
  464. }
  465. return AST_TEST_PASS;
  466. }
  467. AST_TEST_DEFINE(object_delete_uncreated)
  468. {
  469. RAII_VAR(struct ast_sorcery *, sorcery, NULL, deinitialize_sorcery);
  470. RAII_VAR(struct test_sorcery_object *, obj, NULL, ao2_cleanup);
  471. switch (cmd) {
  472. case TEST_INIT:
  473. info->name = "object_delete_uncreated";
  474. info->category = "/res/sorcery_astdb/";
  475. info->summary = "sorcery object deletion unit test";
  476. info->description =
  477. "Test object deletion of an uncreated object in sorcery using astdb wizard";
  478. return AST_TEST_NOT_RUN;
  479. case TEST_EXECUTE:
  480. break;
  481. }
  482. if (!(sorcery = alloc_and_initialize_sorcery())) {
  483. ast_test_status_update(test, "Failed to open sorcery structure\n");
  484. return AST_TEST_FAIL;
  485. }
  486. if (!(obj = ast_sorcery_alloc(sorcery, "test", "blah"))) {
  487. ast_test_status_update(test, "Failed to allocate a known object type\n");
  488. return AST_TEST_FAIL;
  489. }
  490. if (!ast_sorcery_delete(sorcery, obj)) {
  491. ast_test_status_update(test, "Successfully deleted an object which was never created\n");
  492. return AST_TEST_FAIL;
  493. }
  494. return AST_TEST_PASS;
  495. }
  496. static int unload_module(void)
  497. {
  498. AST_TEST_UNREGISTER(object_create);
  499. AST_TEST_UNREGISTER(object_retrieve_id);
  500. AST_TEST_UNREGISTER(object_retrieve_field);
  501. AST_TEST_UNREGISTER(object_retrieve_multiple_all);
  502. AST_TEST_UNREGISTER(object_retrieve_multiple_field);
  503. AST_TEST_UNREGISTER(object_retrieve_regex);
  504. AST_TEST_UNREGISTER(object_update);
  505. AST_TEST_UNREGISTER(object_update_uncreated);
  506. AST_TEST_UNREGISTER(object_delete);
  507. AST_TEST_UNREGISTER(object_delete_uncreated);
  508. return 0;
  509. }
  510. static int load_module(void)
  511. {
  512. AST_TEST_REGISTER(object_create);
  513. AST_TEST_REGISTER(object_retrieve_id);
  514. AST_TEST_REGISTER(object_retrieve_field);
  515. AST_TEST_REGISTER(object_retrieve_multiple_all);
  516. AST_TEST_REGISTER(object_retrieve_multiple_field);
  517. AST_TEST_REGISTER(object_retrieve_regex);
  518. AST_TEST_REGISTER(object_update);
  519. AST_TEST_REGISTER(object_update_uncreated);
  520. AST_TEST_REGISTER(object_delete);
  521. AST_TEST_REGISTER(object_delete_uncreated);
  522. return AST_MODULE_LOAD_SUCCESS;
  523. }
  524. AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "Sorcery astdb Wizard test module");