test_format_cap.c 52 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477
  1. /*
  2. * Asterisk -- An open source telephony toolkit.
  3. *
  4. * Copyright (C) 2014, 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 Format Capabilities API 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. #include "asterisk/test.h"
  31. #include "asterisk/module.h"
  32. #include "asterisk/codec.h"
  33. #include "asterisk/frame.h"
  34. #include "asterisk/format.h"
  35. #include "asterisk/format_cap.h"
  36. AST_TEST_DEFINE(format_cap_alloc)
  37. {
  38. struct ast_format_cap *caps;
  39. switch (cmd) {
  40. case TEST_INIT:
  41. info->name = "format_cap_alloc";
  42. info->category = "/main/format_cap/";
  43. info->summary = "format capabilities allocation unit test";
  44. info->description =
  45. "Test that allocation of a format capabilities structure succeeds";
  46. return AST_TEST_NOT_RUN;
  47. case TEST_EXECUTE:
  48. break;
  49. }
  50. caps = ast_format_cap_alloc(AST_FORMAT_CAP_FLAG_DEFAULT);
  51. if (!caps) {
  52. ast_test_status_update(test, "Could not allocate an empty format capabilities structure\n");
  53. return AST_TEST_FAIL;
  54. }
  55. ao2_ref(caps, -1);
  56. return AST_TEST_PASS;
  57. }
  58. AST_TEST_DEFINE(format_cap_append_single)
  59. {
  60. RAII_VAR(struct ast_format_cap *, caps, NULL, ao2_cleanup);
  61. RAII_VAR(struct ast_codec *, codec, NULL, ao2_cleanup);
  62. RAII_VAR(struct ast_format *, format, NULL, ao2_cleanup);
  63. RAII_VAR(struct ast_format *, retrieved, NULL, ao2_cleanup);
  64. switch (cmd) {
  65. case TEST_INIT:
  66. info->name = __PRETTY_FUNCTION__;
  67. info->category = "/main/format_cap/";
  68. info->summary = "format capabilities adding unit test";
  69. info->description =
  70. "Test that adding a single format to a format capabilities structure succeeds";
  71. return AST_TEST_NOT_RUN;
  72. case TEST_EXECUTE:
  73. break;
  74. }
  75. caps = ast_format_cap_alloc(AST_FORMAT_CAP_FLAG_DEFAULT);
  76. if (!caps) {
  77. ast_test_status_update(test, "Could not allocate an empty format capabilities structure\n");
  78. return AST_TEST_FAIL;
  79. }
  80. codec = ast_codec_get("ulaw", AST_MEDIA_TYPE_AUDIO, 8000);
  81. if (!codec) {
  82. ast_test_status_update(test, "Could not retrieve built-in ulaw codec\n");
  83. return AST_TEST_FAIL;
  84. }
  85. format = ast_format_create(codec);
  86. if (!format) {
  87. ast_test_status_update(test, "Could not create format using built-in codec\n");
  88. return AST_TEST_FAIL;
  89. }
  90. if (ast_format_cap_append(caps, format, 42)) {
  91. ast_test_status_update(test, "Could not add newly created format to capabilities structure\n");
  92. return AST_TEST_FAIL;
  93. } else if (ast_format_cap_count(caps) != 1) {
  94. ast_test_status_update(test, "Number of formats in capabilities structure should be 1 but is %zu\n",
  95. ast_format_cap_count(caps));
  96. return AST_TEST_FAIL;
  97. }
  98. retrieved = ast_format_cap_get_format(caps, 0);
  99. if (!retrieved) {
  100. ast_test_status_update(test, "Attempted to get single format from capabilities structure but got nothing\n");
  101. return AST_TEST_FAIL;
  102. } else if (retrieved != format) {
  103. ast_test_status_update(test, "Retrieved format is not the same as the one we added\n");
  104. return AST_TEST_FAIL;
  105. } else if (ast_format_cap_get_format_framing(caps, retrieved) != 42) {
  106. ast_test_status_update(test, "Framing for format in capabilities structure does not match what we provided\n");
  107. return AST_TEST_FAIL;
  108. }
  109. return AST_TEST_PASS;
  110. }
  111. AST_TEST_DEFINE(format_cap_append_multiple)
  112. {
  113. RAII_VAR(struct ast_format_cap *, caps, NULL, ao2_cleanup);
  114. RAII_VAR(struct ast_codec *, ulaw, NULL, ao2_cleanup);
  115. RAII_VAR(struct ast_format *, ulaw_format, NULL, ao2_cleanup);
  116. RAII_VAR(struct ast_codec *, alaw, NULL, ao2_cleanup);
  117. RAII_VAR(struct ast_format *, alaw_format, NULL, ao2_cleanup);
  118. RAII_VAR(struct ast_format *, retrieved, NULL, ao2_cleanup);
  119. switch (cmd) {
  120. case TEST_INIT:
  121. info->name = __PRETTY_FUNCTION__;
  122. info->category = "/main/format_cap/";
  123. info->summary = "format capabilities adding unit test";
  124. info->description =
  125. "Test that adding multiple formats to a format capabilities structure succeeds";
  126. return AST_TEST_NOT_RUN;
  127. case TEST_EXECUTE:
  128. break;
  129. }
  130. caps = ast_format_cap_alloc(AST_FORMAT_CAP_FLAG_DEFAULT);
  131. if (!caps) {
  132. ast_test_status_update(test, "Could not allocate an empty format capabilities structure\n");
  133. return AST_TEST_FAIL;
  134. }
  135. ulaw = ast_codec_get("ulaw", AST_MEDIA_TYPE_AUDIO, 8000);
  136. if (!ulaw) {
  137. ast_test_status_update(test, "Could not retrieve built-in ulaw codec\n");
  138. return AST_TEST_FAIL;
  139. }
  140. ulaw_format = ast_format_create(ulaw);
  141. if (!ulaw_format) {
  142. ast_test_status_update(test, "Could not create ulaw format using built-in codec\n");
  143. return AST_TEST_FAIL;
  144. }
  145. alaw = ast_codec_get("alaw", AST_MEDIA_TYPE_AUDIO, 8000);
  146. if (!alaw) {
  147. ast_test_status_update(test, "Could not retrieve built-in alaw codec\n");
  148. return AST_TEST_FAIL;
  149. }
  150. alaw_format = ast_format_create(alaw);
  151. if (!alaw_format) {
  152. ast_test_status_update(test, "Could not create alaw format using built-in codec\n");
  153. return AST_TEST_FAIL;
  154. }
  155. if (ast_format_cap_append(caps, ulaw_format, 42)) {
  156. ast_test_status_update(test, "Could not add newly created ulaw format to capabilities structure\n");
  157. return AST_TEST_FAIL;
  158. } else if (ast_format_cap_append(caps, alaw_format, 84)) {
  159. ast_test_status_update(test, "Could not add newly created alaw format to capabilities structure\n");
  160. return AST_TEST_FAIL;
  161. } else if (ast_format_cap_count(caps) != 2) {
  162. ast_test_status_update(test, "Number of formats in capabilities structure should be 2 but is %zu\n",
  163. ast_format_cap_count(caps));
  164. return AST_TEST_FAIL;
  165. }
  166. retrieved = ast_format_cap_get_format(caps, 0);
  167. if (!retrieved) {
  168. ast_test_status_update(test, "Attempted to get first format from capabilities structure but got nothing\n");
  169. return AST_TEST_FAIL;
  170. } else if (retrieved != ulaw_format) {
  171. ast_test_status_update(test, "First retrieved format is not the ulaw one we added\n");
  172. return AST_TEST_FAIL;
  173. } else if (ast_format_cap_get_format_framing(caps, retrieved) != 42) {
  174. ast_test_status_update(test, "Framing for ulaw format in capabilities structure does not match what we provided\n");
  175. }
  176. ao2_ref(retrieved, -1);
  177. retrieved = ast_format_cap_get_format(caps, 1);
  178. if (!retrieved) {
  179. ast_test_status_update(test, "Attempted to get second format from capabilities structure but got nothing\n");
  180. return AST_TEST_FAIL;
  181. } else if (retrieved != alaw_format) {
  182. ast_test_status_update(test, "First retrieved format is not the alaw one we added\n");
  183. return AST_TEST_FAIL;
  184. } else if (ast_format_cap_get_format_framing(caps, retrieved) != 84) {
  185. ast_test_status_update(test, "Framing for alaw format in capabilities structure does not match what we provided\n");
  186. }
  187. return AST_TEST_PASS;
  188. }
  189. AST_TEST_DEFINE(format_cap_append_all_unknown)
  190. {
  191. RAII_VAR(struct ast_format_cap *, caps, NULL, ao2_cleanup);
  192. switch (cmd) {
  193. case TEST_INIT:
  194. info->name = __PRETTY_FUNCTION__;
  195. info->category = "/main/format_cap/";
  196. info->summary = "format capabilities adding unit test";
  197. info->description =
  198. "Test that adding of all formats to a format capabilities structure succeeds";
  199. return AST_TEST_NOT_RUN;
  200. case TEST_EXECUTE:
  201. break;
  202. }
  203. caps = ast_format_cap_alloc(AST_FORMAT_CAP_FLAG_DEFAULT);
  204. if (!caps) {
  205. ast_test_status_update(test, "Could not allocate an empty format capabilities structure\n");
  206. return AST_TEST_FAIL;
  207. } else if (ast_format_cap_append_by_type(caps, AST_MEDIA_TYPE_UNKNOWN)) {
  208. ast_test_status_update(test, "Failed to add all media formats of all types to capabilities structure\n");
  209. return AST_TEST_FAIL;
  210. } else if (!ast_format_cap_has_type(caps, AST_MEDIA_TYPE_AUDIO)) {
  211. ast_test_status_update(test, "Added all media formats but no audio formats exist when they should\n");
  212. return AST_TEST_FAIL;
  213. } else if (!ast_format_cap_has_type(caps, AST_MEDIA_TYPE_VIDEO)) {
  214. ast_test_status_update(test, "Added all media formats but no video formats exist when they should\n");
  215. return AST_TEST_FAIL;
  216. } else if ((ast_format_cap_count(caps) + 1) != (ast_codec_get_max() - 1)) {
  217. ast_test_status_update(test, "The number of formats in the capabilities structure does not match known number\n");
  218. return AST_TEST_FAIL;
  219. }
  220. return AST_TEST_PASS;
  221. }
  222. AST_TEST_DEFINE(format_cap_append_all_audio)
  223. {
  224. RAII_VAR(struct ast_format_cap *, caps, NULL, ao2_cleanup);
  225. switch (cmd) {
  226. case TEST_INIT:
  227. info->name = __PRETTY_FUNCTION__;
  228. info->category = "/main/format_cap/";
  229. info->summary = "format capabilities adding unit test";
  230. info->description =
  231. "Test that adding of all audio formats to a format capabilities structure succeeds";
  232. return AST_TEST_NOT_RUN;
  233. case TEST_EXECUTE:
  234. break;
  235. }
  236. caps = ast_format_cap_alloc(AST_FORMAT_CAP_FLAG_DEFAULT);
  237. if (!caps) {
  238. ast_test_status_update(test, "Could not allocate an empty format capabilities structure\n");
  239. return AST_TEST_FAIL;
  240. } else if (ast_format_cap_append_by_type(caps, AST_MEDIA_TYPE_AUDIO)) {
  241. ast_test_status_update(test, "Failed to add all audio media formats to capabilities structure\n");
  242. return AST_TEST_FAIL;
  243. } else if (!ast_format_cap_has_type(caps, AST_MEDIA_TYPE_AUDIO)) {
  244. ast_test_status_update(test, "Added audio media formats but no audio formats exist when they should\n");
  245. return AST_TEST_FAIL;
  246. } else if (ast_format_cap_has_type(caps, AST_MEDIA_TYPE_VIDEO)) {
  247. ast_test_status_update(test, "Added only audio media formats but video formats exist when they should not\n");
  248. return AST_TEST_FAIL;
  249. } else if (ast_format_cap_has_type(caps, AST_MEDIA_TYPE_TEXT)) {
  250. ast_test_status_update(test, "Added only audio media formats but text formats exist when they should not\n");
  251. return AST_TEST_FAIL;
  252. } else if (ast_format_cap_has_type(caps, AST_MEDIA_TYPE_IMAGE)) {
  253. ast_test_status_update(test, "Added only audio media formats but image formats exist when they should not\n");
  254. return AST_TEST_FAIL;
  255. }
  256. return AST_TEST_PASS;
  257. }
  258. AST_TEST_DEFINE(format_cap_append_duplicate)
  259. {
  260. RAII_VAR(struct ast_format_cap *, caps, NULL, ao2_cleanup);
  261. RAII_VAR(struct ast_codec *, codec, NULL, ao2_cleanup);
  262. RAII_VAR(struct ast_format *, format, NULL, ao2_cleanup);
  263. RAII_VAR(struct ast_format *, format_named, NULL, ao2_cleanup);
  264. RAII_VAR(struct ast_format *, retrieved, NULL, ao2_cleanup);
  265. switch (cmd) {
  266. case TEST_INIT:
  267. info->name = __PRETTY_FUNCTION__;
  268. info->category = "/main/format_cap/";
  269. info->summary = "format capabilities duplication unit test";
  270. info->description =
  271. "Test that adding a single format multiple times to a capabilities structure results in only a single format";
  272. return AST_TEST_NOT_RUN;
  273. case TEST_EXECUTE:
  274. break;
  275. }
  276. caps = ast_format_cap_alloc(AST_FORMAT_CAP_FLAG_DEFAULT);
  277. if (!caps) {
  278. ast_test_status_update(test, "Could not allocate an empty format capabilities structure\n");
  279. return AST_TEST_FAIL;
  280. }
  281. codec = ast_codec_get("ulaw", AST_MEDIA_TYPE_AUDIO, 8000);
  282. if (!codec) {
  283. ast_test_status_update(test, "Could not retrieve built-in ulaw codec\n");
  284. return AST_TEST_FAIL;
  285. }
  286. format = ast_format_create(codec);
  287. if (!format) {
  288. ast_test_status_update(test, "Could not create format using built-in codec\n");
  289. return AST_TEST_FAIL;
  290. }
  291. format_named = ast_format_create_named("ulaw@20", codec);
  292. if (!format_named) {
  293. ast_test_status_update(test, "Could not create named format using built-in codec\n");
  294. return AST_TEST_FAIL;
  295. }
  296. if (ast_format_cap_append(caps, format, 42)) {
  297. ast_test_status_update(test, "Could not add newly created format to capabilities structure\n");
  298. return AST_TEST_FAIL;
  299. } else if (ast_format_cap_count(caps) != 1) {
  300. ast_test_status_update(test, "Number of formats in capabilities structure should be 1 but is %zu\n",
  301. ast_format_cap_count(caps));
  302. return AST_TEST_FAIL;
  303. }
  304. /* Note: regardless of it being a duplicate, ast_format_cap_append should return success */
  305. if (ast_format_cap_append(caps, format, 0)) {
  306. ast_test_status_update(test, "Adding of duplicate format to capabilities structure failed\n");
  307. return AST_TEST_FAIL;
  308. } else if (ast_format_cap_count(caps) != 1) {
  309. ast_test_status_update(test, "Number of formats in capabilities structure should be 1 but is %zu\n",
  310. ast_format_cap_count(caps));
  311. return AST_TEST_FAIL;
  312. }
  313. if (ast_format_cap_append(caps, format_named, 0)) {
  314. ast_test_status_update(test, "Adding of duplicate named format to capabilities structure failed\n");
  315. return AST_TEST_FAIL;
  316. } else if (ast_format_cap_count(caps) != 1) {
  317. ast_test_status_update(test, "Number of formats in capabilities structure should be 1 but is %zu\n",
  318. ast_format_cap_count(caps));
  319. return AST_TEST_FAIL;
  320. }
  321. retrieved = ast_format_cap_get_format(caps, 0);
  322. if (!retrieved) {
  323. ast_test_status_update(test, "Attempted to get single format from capabilities structure but got nothing\n");
  324. return AST_TEST_FAIL;
  325. } else if (retrieved != format) {
  326. ast_test_status_update(test, "Retrieved format is not the same as the one we added\n");
  327. return AST_TEST_FAIL;
  328. } else if (ast_format_cap_get_format_framing(caps, retrieved) != 42) {
  329. ast_test_status_update(test, "Framing for format in capabilities structure does not match what we provided\n");
  330. return AST_TEST_FAIL;
  331. }
  332. return AST_TEST_PASS;
  333. }
  334. AST_TEST_DEFINE(format_cap_append_from_cap)
  335. {
  336. RAII_VAR(struct ast_format_cap *, dst_caps, NULL, ao2_cleanup);
  337. RAII_VAR(struct ast_format_cap *, src_caps, NULL, ao2_cleanup);
  338. switch (cmd) {
  339. case TEST_INIT:
  340. info->name = __PRETTY_FUNCTION__;
  341. info->category = "/main/format_cap/";
  342. info->summary = "format capabilities append unit test";
  343. info->description =
  344. "Test that appending video formats from one capabilities structure to another succeeds";
  345. return AST_TEST_NOT_RUN;
  346. case TEST_EXECUTE:
  347. break;
  348. }
  349. dst_caps = ast_format_cap_alloc(AST_FORMAT_CAP_FLAG_DEFAULT);
  350. if (!dst_caps) {
  351. ast_test_status_update(test, "Could not allocate an empty format capabilities structure\n");
  352. return AST_TEST_FAIL;
  353. } else if (ast_format_cap_append_by_type(dst_caps, AST_MEDIA_TYPE_AUDIO)) {
  354. ast_test_status_update(test, "Failed to add all audio media formats to capabilities structure\n");
  355. return AST_TEST_FAIL;
  356. }
  357. src_caps = ast_format_cap_alloc(AST_FORMAT_CAP_FLAG_DEFAULT);
  358. if (!src_caps) {
  359. ast_test_status_update(test, "Could not allocate an empty format capabilities structure\n");
  360. return AST_TEST_FAIL;
  361. } else if (ast_format_cap_append_by_type(src_caps, AST_MEDIA_TYPE_VIDEO)) {
  362. ast_test_status_update(test, "Failed to add all video media formats to capabilities structure\n");
  363. return AST_TEST_FAIL;
  364. }
  365. if (ast_format_cap_append_from_cap(dst_caps, src_caps, AST_MEDIA_TYPE_UNKNOWN)) {
  366. ast_test_status_update(test, "Failed to append formats to capabilities structure\n");
  367. return AST_TEST_FAIL;
  368. } else if (!ast_format_cap_has_type(dst_caps, AST_MEDIA_TYPE_AUDIO)) {
  369. ast_test_status_update(test, "Successfully appended video formats to destination capabilities but it no longer contains audio formats\n");
  370. return AST_TEST_FAIL;
  371. } else if (!ast_format_cap_has_type(dst_caps, AST_MEDIA_TYPE_VIDEO)) {
  372. ast_test_status_update(test, "Successfully appended formats but video formats do not exist in destination capabilities\n");
  373. return AST_TEST_FAIL;
  374. }
  375. return AST_TEST_PASS;
  376. }
  377. AST_TEST_DEFINE(format_cap_append_from_cap_duplicate)
  378. {
  379. RAII_VAR(struct ast_format_cap *, dst_caps, NULL, ao2_cleanup);
  380. RAII_VAR(struct ast_format_cap *, src_caps, NULL, ao2_cleanup);
  381. unsigned int count;
  382. unsigned int total_count;
  383. switch (cmd) {
  384. case TEST_INIT:
  385. info->name = __PRETTY_FUNCTION__;
  386. info->category = "/main/format_cap/";
  387. info->summary = "format capabilities append duplicate unit test";
  388. info->description =
  389. "Test that appending capabilities structures multiple times does not result in duplicate formats";
  390. return AST_TEST_NOT_RUN;
  391. case TEST_EXECUTE:
  392. break;
  393. }
  394. dst_caps = ast_format_cap_alloc(AST_FORMAT_CAP_FLAG_DEFAULT);
  395. if (!dst_caps) {
  396. ast_test_status_update(test, "Could not allocate an empty format capabilities structure\n");
  397. return AST_TEST_FAIL;
  398. } else if (ast_format_cap_append_by_type(dst_caps, AST_MEDIA_TYPE_AUDIO)) {
  399. ast_test_status_update(test, "Failed to add all audio media formats to capabilities structure\n");
  400. return AST_TEST_FAIL;
  401. }
  402. src_caps = ast_format_cap_alloc(AST_FORMAT_CAP_FLAG_DEFAULT);
  403. if (!src_caps) {
  404. ast_test_status_update(test, "Could not allocate an empty format capabilities structure\n");
  405. return AST_TEST_FAIL;
  406. } else if (ast_format_cap_append_by_type(src_caps, AST_MEDIA_TYPE_VIDEO)) {
  407. ast_test_status_update(test, "Failed to add all video media formats to capabilities structure\n");
  408. return AST_TEST_FAIL;
  409. }
  410. total_count = ast_format_cap_count(src_caps) + ast_format_cap_count(dst_caps);
  411. if (ast_format_cap_append_from_cap(dst_caps, src_caps, AST_MEDIA_TYPE_UNKNOWN)) {
  412. ast_test_status_update(test, "Failed to append formats to capabilities structure\n");
  413. return AST_TEST_FAIL;
  414. } else if (!ast_format_cap_has_type(dst_caps, AST_MEDIA_TYPE_AUDIO)) {
  415. ast_test_status_update(test, "Successfully appended video formats to destination capabilities but it no longer contains audio formats\n");
  416. return AST_TEST_FAIL;
  417. } else if (!ast_format_cap_has_type(dst_caps, AST_MEDIA_TYPE_VIDEO)) {
  418. ast_test_status_update(test, "Successfully appended formats but video formats do not exist in destination capabilities\n");
  419. return AST_TEST_FAIL;
  420. }
  421. count = ast_format_cap_count(dst_caps);
  422. if (ast_format_cap_append_from_cap(dst_caps, src_caps, AST_MEDIA_TYPE_UNKNOWN)) {
  423. ast_test_status_update(test, "Failed to append duplicate formats to capabilities structure\n");
  424. return AST_TEST_FAIL;
  425. }
  426. ast_test_validate(test, count == ast_format_cap_count(dst_caps));
  427. ast_test_validate(test, count == total_count);
  428. return AST_TEST_PASS;
  429. }
  430. AST_TEST_DEFINE(format_cap_set_framing)
  431. {
  432. RAII_VAR(struct ast_format_cap *, caps, NULL, ao2_cleanup);
  433. RAII_VAR(struct ast_codec *, ulaw, NULL, ao2_cleanup);
  434. RAII_VAR(struct ast_format *, ulaw_format, NULL, ao2_cleanup);
  435. RAII_VAR(struct ast_codec *, alaw, NULL, ao2_cleanup);
  436. RAII_VAR(struct ast_format *, alaw_format, NULL, ao2_cleanup);
  437. switch (cmd) {
  438. case TEST_INIT:
  439. info->name = "format_cap_set_framing";
  440. info->category = "/main/format_cap/";
  441. info->summary = "format capabilities framing unit test";
  442. info->description =
  443. "Test that global framing on a format capabilities structure is used when it should be";
  444. return AST_TEST_NOT_RUN;
  445. case TEST_EXECUTE:
  446. break;
  447. }
  448. caps = ast_format_cap_alloc(AST_FORMAT_CAP_FLAG_DEFAULT);
  449. if (!caps) {
  450. ast_test_status_update(test, "Could not allocate an empty format capabilities structure\n");
  451. return AST_TEST_FAIL;
  452. }
  453. ast_format_cap_set_framing(caps, 160);
  454. ast_test_validate(test, ast_format_cap_get_framing(caps) == 160);
  455. ulaw = ast_codec_get("ulaw", AST_MEDIA_TYPE_AUDIO, 8000);
  456. if (!ulaw) {
  457. ast_test_status_update(test, "Could not retrieve built-in ulaw codec\n");
  458. return AST_TEST_FAIL;
  459. }
  460. ulaw_format = ast_format_create(ulaw);
  461. if (!ulaw_format) {
  462. ast_test_status_update(test, "Could not create ulaw format using built-in codec\n");
  463. return AST_TEST_FAIL;
  464. }
  465. alaw = ast_codec_get("alaw", AST_MEDIA_TYPE_AUDIO, 8000);
  466. if (!alaw) {
  467. ast_test_status_update(test, "Could not retrieve built-in alaw codec\n");
  468. return AST_TEST_FAIL;
  469. }
  470. alaw_format = ast_format_create(alaw);
  471. if (!alaw_format) {
  472. ast_test_status_update(test, "Could not create alaw format using built-in codec\n");
  473. return AST_TEST_FAIL;
  474. }
  475. if (ast_format_cap_append(caps, ulaw_format, 42)) {
  476. ast_test_status_update(test, "Could not add newly created ulaw format to capabilities structure\n");
  477. return AST_TEST_FAIL;
  478. } else if (ast_format_cap_append(caps, alaw_format, 0)) {
  479. ast_test_status_update(test, "Could not add newly created alaw format to capabilities structure\n");
  480. return AST_TEST_FAIL;
  481. }
  482. if (ast_format_cap_get_format_framing(caps, ulaw_format) != 42) {
  483. ast_test_status_update(test, "Added ulaw format to capabilities structure with explicit framing but did not get it back\n");
  484. return AST_TEST_FAIL;
  485. } else if (ast_format_cap_get_format_framing(caps, alaw_format) != ast_format_get_default_ms(alaw_format)) {
  486. ast_test_status_update(test, "Added alaw format to capabilities structure with no explicit framing but did not get global back\n");
  487. return AST_TEST_FAIL;
  488. }
  489. ast_test_validate(test, ast_format_cap_get_framing(caps) == ast_format_get_default_ms(alaw_format));
  490. return AST_TEST_PASS;
  491. }
  492. AST_TEST_DEFINE(format_cap_remove_single)
  493. {
  494. RAII_VAR(struct ast_format_cap *, caps, NULL, ao2_cleanup);
  495. RAII_VAR(struct ast_codec *, codec, NULL, ao2_cleanup);
  496. RAII_VAR(struct ast_format *, format, NULL, ao2_cleanup);
  497. switch (cmd) {
  498. case TEST_INIT:
  499. info->name = "format_cap_remove_single";
  500. info->category = "/main/format_cap/";
  501. info->summary = "format capabilities removal unit test";
  502. info->description =
  503. "Test that removing a single format from a format capabilities structure succeeds";
  504. return AST_TEST_NOT_RUN;
  505. case TEST_EXECUTE:
  506. break;
  507. }
  508. caps = ast_format_cap_alloc(AST_FORMAT_CAP_FLAG_DEFAULT);
  509. if (!caps) {
  510. ast_test_status_update(test, "Could not allocate an empty format capabilities structure\n");
  511. return AST_TEST_FAIL;
  512. }
  513. codec = ast_codec_get("ulaw", AST_MEDIA_TYPE_AUDIO, 8000);
  514. if (!codec) {
  515. ast_test_status_update(test, "Could not retrieve built-in ulaw codec\n");
  516. return AST_TEST_FAIL;
  517. }
  518. format = ast_format_create(codec);
  519. if (!format) {
  520. ast_test_status_update(test, "Could not create format using built-in codec\n");
  521. return AST_TEST_FAIL;
  522. }
  523. if (ast_format_cap_append(caps, format, 42)) {
  524. ast_test_status_update(test, "Could not add newly created format to capabilities structure\n");
  525. return AST_TEST_FAIL;
  526. } else if (ast_format_cap_remove(caps, format)) {
  527. ast_test_status_update(test, "Could not remove format that was just added to capabilities structure\n");
  528. return AST_TEST_FAIL;
  529. } else if (!ast_format_cap_remove(caps, format)) {
  530. ast_test_status_update(test, "Successfully removed a format twice from the capabilities structure\n");
  531. return AST_TEST_FAIL;
  532. } else if (ast_format_cap_count(caps)) {
  533. ast_test_status_update(test, "Capabilities structure should be empty but instead it contains '%zu' formats\n",
  534. ast_format_cap_count(caps));
  535. return AST_TEST_FAIL;
  536. }
  537. return AST_TEST_PASS;
  538. }
  539. AST_TEST_DEFINE(format_cap_remove_multiple)
  540. {
  541. RAII_VAR(struct ast_format_cap *, caps, NULL, ao2_cleanup);
  542. RAII_VAR(struct ast_codec *, ulaw, NULL, ao2_cleanup);
  543. RAII_VAR(struct ast_format *, ulaw_format, NULL, ao2_cleanup);
  544. RAII_VAR(struct ast_codec *, alaw, NULL, ao2_cleanup);
  545. RAII_VAR(struct ast_format *, alaw_format, NULL, ao2_cleanup);
  546. RAII_VAR(struct ast_format *, retrieved, NULL, ao2_cleanup);
  547. switch (cmd) {
  548. case TEST_INIT:
  549. info->name = "format_cap_remove_multiple";
  550. info->category = "/main/format_cap/";
  551. info->summary = "format capabilities removal unit test";
  552. info->description =
  553. "Test that removing a format from a format capabilities structure containing multiple formats succeeds";
  554. return AST_TEST_NOT_RUN;
  555. case TEST_EXECUTE:
  556. break;
  557. }
  558. caps = ast_format_cap_alloc(AST_FORMAT_CAP_FLAG_DEFAULT);
  559. if (!caps) {
  560. ast_test_status_update(test, "Could not allocate an empty format capabilities structure\n");
  561. return AST_TEST_FAIL;
  562. }
  563. ulaw = ast_codec_get("ulaw", AST_MEDIA_TYPE_AUDIO, 8000);
  564. if (!ulaw) {
  565. ast_test_status_update(test, "Could not retrieve built-in ulaw codec\n");
  566. return AST_TEST_FAIL;
  567. }
  568. ulaw_format = ast_format_create(ulaw);
  569. if (!ulaw_format) {
  570. ast_test_status_update(test, "Could not create ulaw format using built-in codec\n");
  571. return AST_TEST_FAIL;
  572. }
  573. alaw = ast_codec_get("alaw", AST_MEDIA_TYPE_AUDIO, 8000);
  574. if (!alaw) {
  575. ast_test_status_update(test, "Could not retrieve built-in alaw codec\n");
  576. return AST_TEST_FAIL;
  577. }
  578. alaw_format = ast_format_create(alaw);
  579. if (!alaw_format) {
  580. ast_test_status_update(test, "Could not create alaw format using built-in codec\n");
  581. return AST_TEST_FAIL;
  582. }
  583. if (ast_format_cap_append(caps, ulaw_format, 42)) {
  584. ast_test_status_update(test, "Could not add newly created ulaw format to capabilities structure\n");
  585. return AST_TEST_FAIL;
  586. } else if (ast_format_cap_append(caps, alaw_format, 84)) {
  587. ast_test_status_update(test, "Could not add newly created alaw format to capabilities structure\n");
  588. return AST_TEST_FAIL;
  589. } else if (ast_format_cap_remove(caps, ulaw_format)) {
  590. ast_test_status_update(test, "Could not remove the ulaw format we just added to capabilities structure\n");
  591. return AST_TEST_FAIL;
  592. } else if (ast_format_cap_count(caps) != 1) {
  593. ast_test_status_update(test, "Capabilities structure should contain 1 format but it contains '%zu'\n",
  594. ast_format_cap_count(caps));
  595. return AST_TEST_FAIL;
  596. }
  597. retrieved = ast_format_cap_get_format(caps, 0);
  598. if (!retrieved) {
  599. ast_test_status_update(test, "Attempted to get first format from capabilities structure but got nothing\n");
  600. return AST_TEST_FAIL;
  601. } else if (retrieved != alaw_format) {
  602. ast_test_status_update(test, "First retrieved format is not the alaw one we added\n");
  603. return AST_TEST_FAIL;
  604. }
  605. return AST_TEST_PASS;
  606. }
  607. AST_TEST_DEFINE(format_cap_remove_bytype)
  608. {
  609. RAII_VAR(struct ast_format_cap *, caps, NULL, ao2_cleanup);
  610. switch (cmd) {
  611. case TEST_INIT:
  612. info->name = "format_cap_remove_bytype";
  613. info->category = "/main/format_cap/";
  614. info->summary = "format capabilities removal unit test";
  615. info->description =
  616. "Test that removal of a specific type of format from a format capabilities structure succeeds";
  617. return AST_TEST_NOT_RUN;
  618. case TEST_EXECUTE:
  619. break;
  620. }
  621. caps = ast_format_cap_alloc(AST_FORMAT_CAP_FLAG_DEFAULT);
  622. if (!caps) {
  623. ast_test_status_update(test, "Could not allocate an empty format capabilities structure\n");
  624. return AST_TEST_FAIL;
  625. } else if (ast_format_cap_append_by_type(caps, AST_MEDIA_TYPE_UNKNOWN)) {
  626. ast_test_status_update(test, "Failed to add all media formats of all types to capabilities structure\n");
  627. return AST_TEST_FAIL;
  628. }
  629. ast_format_cap_remove_by_type(caps, AST_MEDIA_TYPE_AUDIO);
  630. if (ast_format_cap_has_type(caps, AST_MEDIA_TYPE_AUDIO)) {
  631. ast_test_status_update(test, "Removed all audio type formats from capabilities structure but some remain\n");
  632. return AST_TEST_FAIL;
  633. } else if (!ast_format_cap_has_type(caps, AST_MEDIA_TYPE_VIDEO)) {
  634. ast_test_status_update(test, "Removed audio type formats from capabilities structure but video are gone as well\n");
  635. return AST_TEST_FAIL;
  636. }
  637. return AST_TEST_PASS;
  638. }
  639. AST_TEST_DEFINE(format_cap_remove_all)
  640. {
  641. RAII_VAR(struct ast_format_cap *, caps, NULL, ao2_cleanup);
  642. switch (cmd) {
  643. case TEST_INIT:
  644. info->name = "format_cap_remove_all";
  645. info->category = "/main/format_cap/";
  646. info->summary = "format capabilities removal unit test";
  647. info->description =
  648. "Test that removal of all formats from a format capabilities structure succeeds";
  649. return AST_TEST_NOT_RUN;
  650. case TEST_EXECUTE:
  651. break;
  652. }
  653. caps = ast_format_cap_alloc(AST_FORMAT_CAP_FLAG_DEFAULT);
  654. if (!caps) {
  655. ast_test_status_update(test, "Could not allocate an empty format capabilities structure\n");
  656. return AST_TEST_FAIL;
  657. } else if (ast_format_cap_append_by_type(caps, AST_MEDIA_TYPE_UNKNOWN)) {
  658. ast_test_status_update(test, "Failed to add all media formats of all types to capabilities structure\n");
  659. return AST_TEST_FAIL;
  660. }
  661. ast_format_cap_remove_by_type(caps, AST_MEDIA_TYPE_UNKNOWN);
  662. if (ast_format_cap_count(caps)) {
  663. ast_test_status_update(test, "Removed all formats from capabilities structure but some remain\n");
  664. return AST_TEST_FAIL;
  665. }
  666. return AST_TEST_PASS;
  667. }
  668. AST_TEST_DEFINE(format_cap_get_compatible_format)
  669. {
  670. RAII_VAR(struct ast_format_cap *, caps, NULL, ao2_cleanup);
  671. RAII_VAR(struct ast_codec *, ulaw, NULL, ao2_cleanup);
  672. RAII_VAR(struct ast_format *, ulaw_format, NULL, ao2_cleanup);
  673. RAII_VAR(struct ast_codec *, alaw, NULL, ao2_cleanup);
  674. RAII_VAR(struct ast_format *, alaw_format, NULL, ao2_cleanup);
  675. RAII_VAR(struct ast_format *, compatible, NULL, ao2_cleanup);
  676. switch (cmd) {
  677. case TEST_INIT:
  678. info->name = "format_cap_get_compatible_format";
  679. info->category = "/main/format_cap/";
  680. info->summary = "format capabilities negotiation unit test";
  681. info->description =
  682. "Test that getting a compatible format from a capabilities structure succeeds";
  683. return AST_TEST_NOT_RUN;
  684. case TEST_EXECUTE:
  685. break;
  686. }
  687. caps = ast_format_cap_alloc(AST_FORMAT_CAP_FLAG_DEFAULT);
  688. if (!caps) {
  689. ast_test_status_update(test, "Could not allocate an empty format capabilities structure\n");
  690. return AST_TEST_FAIL;
  691. }
  692. ulaw = ast_codec_get("ulaw", AST_MEDIA_TYPE_AUDIO, 8000);
  693. if (!ulaw) {
  694. ast_test_status_update(test, "Could not retrieve built-in ulaw codec\n");
  695. return AST_TEST_FAIL;
  696. }
  697. ulaw_format = ast_format_create(ulaw);
  698. if (!ulaw_format) {
  699. ast_test_status_update(test, "Could not create ulaw format using built-in codec\n");
  700. return AST_TEST_FAIL;
  701. }
  702. alaw = ast_codec_get("alaw", AST_MEDIA_TYPE_AUDIO, 8000);
  703. if (!alaw) {
  704. ast_test_status_update(test, "Could not retrieve built-in alaw codec\n");
  705. return AST_TEST_FAIL;
  706. }
  707. alaw_format = ast_format_create(alaw);
  708. if (!alaw_format) {
  709. ast_test_status_update(test, "Could not create alaw format using built-in codec\n");
  710. return AST_TEST_FAIL;
  711. }
  712. if (ast_format_cap_append(caps, ulaw_format, 42)) {
  713. ast_test_status_update(test, "Could not add newly created ulaw format to capabilities structure\n");
  714. return AST_TEST_FAIL;
  715. }
  716. compatible = ast_format_cap_get_compatible_format(caps, alaw_format);
  717. if (compatible) {
  718. ast_test_status_update(test, "Retrieved a compatible format from capabilities structure when none should exist\n");
  719. return AST_TEST_FAIL;
  720. }
  721. compatible = ast_format_cap_get_compatible_format(caps, ulaw_format);
  722. if (!compatible) {
  723. ast_test_status_update(test, "Did not retrieve a compatible format from capabilities structure when there should be one\n");
  724. return AST_TEST_FAIL;
  725. } else if (compatible != ulaw_format) {
  726. ast_test_status_update(test, "Compatible format is not the format we added to the capabilities structure\n");
  727. return AST_TEST_FAIL;
  728. }
  729. return AST_TEST_PASS;
  730. }
  731. AST_TEST_DEFINE(format_cap_iscompatible_format)
  732. {
  733. RAII_VAR(struct ast_format_cap *, caps, NULL, ao2_cleanup);
  734. RAII_VAR(struct ast_codec *, ulaw, NULL, ao2_cleanup);
  735. RAII_VAR(struct ast_format *, ulaw_format, NULL, ao2_cleanup);
  736. RAII_VAR(struct ast_codec *, alaw, NULL, ao2_cleanup);
  737. RAII_VAR(struct ast_format *, alaw_format, NULL, ao2_cleanup);
  738. switch (cmd) {
  739. case TEST_INIT:
  740. info->name = "format_cap_iscompatible_format";
  741. info->category = "/main/format_cap/";
  742. info->summary = "format capabilities negotiation unit test";
  743. info->description =
  744. "Test that checking whether a format is compatible with a capabilities structure succeeds";
  745. return AST_TEST_NOT_RUN;
  746. case TEST_EXECUTE:
  747. break;
  748. }
  749. caps = ast_format_cap_alloc(AST_FORMAT_CAP_FLAG_DEFAULT);
  750. if (!caps) {
  751. ast_test_status_update(test, "Could not allocate an empty format capabilities structure\n");
  752. return AST_TEST_FAIL;
  753. }
  754. ulaw = ast_codec_get("ulaw", AST_MEDIA_TYPE_AUDIO, 8000);
  755. if (!ulaw) {
  756. ast_test_status_update(test, "Could not retrieve built-in ulaw codec\n");
  757. return AST_TEST_FAIL;
  758. }
  759. ulaw_format = ast_format_create(ulaw);
  760. if (!ulaw_format) {
  761. ast_test_status_update(test, "Could not create ulaw format using built-in codec\n");
  762. return AST_TEST_FAIL;
  763. }
  764. alaw = ast_codec_get("alaw", AST_MEDIA_TYPE_AUDIO, 8000);
  765. if (!alaw) {
  766. ast_test_status_update(test, "Could not retrieve built-in alaw codec\n");
  767. return AST_TEST_FAIL;
  768. }
  769. alaw_format = ast_format_create(alaw);
  770. if (!alaw_format) {
  771. ast_test_status_update(test, "Could not create alaw format using built-in codec\n");
  772. return AST_TEST_FAIL;
  773. }
  774. if (ast_format_cap_append(caps, ulaw_format, 42)) {
  775. ast_test_status_update(test, "Could not add newly created ulaw format to capabilities structure\n");
  776. return AST_TEST_FAIL;
  777. } else if (ast_format_cap_iscompatible_format(caps, alaw_format) != AST_FORMAT_CMP_NOT_EQUAL) {
  778. ast_test_status_update(test, "Alaw format is compatible with capabilities structure when it only contains ulaw\n");
  779. return AST_TEST_FAIL;
  780. } else if (ast_format_cap_iscompatible_format(caps, ulaw_format) == AST_FORMAT_CMP_NOT_EQUAL) {
  781. ast_test_status_update(test, "Ulaw format is not compatible with capabilities structure when it should be\n");
  782. return AST_TEST_FAIL;
  783. }
  784. return AST_TEST_PASS;
  785. }
  786. AST_TEST_DEFINE(format_cap_get_compatible)
  787. {
  788. RAII_VAR(struct ast_format_cap *, alaw_caps, NULL, ao2_cleanup);
  789. RAII_VAR(struct ast_format_cap *, ulaw_caps, NULL, ao2_cleanup);
  790. RAII_VAR(struct ast_format_cap *, compatible_caps, NULL, ao2_cleanup);
  791. RAII_VAR(struct ast_codec *, ulaw, NULL, ao2_cleanup);
  792. RAII_VAR(struct ast_format *, ulaw_format, NULL, ao2_cleanup);
  793. RAII_VAR(struct ast_codec *, alaw, NULL, ao2_cleanup);
  794. RAII_VAR(struct ast_format *, alaw_format, NULL, ao2_cleanup);
  795. switch (cmd) {
  796. case TEST_INIT:
  797. info->name = "format_cap_get_compatible";
  798. info->category = "/main/format_cap/";
  799. info->summary = "format capabilities negotiation unit test";
  800. info->description =
  801. "Test that getting the compatible formats between two capabilities structures succeeds";
  802. return AST_TEST_NOT_RUN;
  803. case TEST_EXECUTE:
  804. break;
  805. }
  806. alaw_caps = ast_format_cap_alloc(AST_FORMAT_CAP_FLAG_DEFAULT);
  807. if (!alaw_caps) {
  808. ast_test_status_update(test, "Could not allocate an empty format capabilities structure\n");
  809. return AST_TEST_FAIL;
  810. }
  811. ulaw_caps = ast_format_cap_alloc(AST_FORMAT_CAP_FLAG_DEFAULT);
  812. if (!ulaw_caps) {
  813. ast_test_status_update(test, "Could not allocate an empty format capabilities structure\n");
  814. return AST_TEST_FAIL;
  815. }
  816. compatible_caps = ast_format_cap_alloc(AST_FORMAT_CAP_FLAG_DEFAULT);
  817. if (!compatible_caps) {
  818. ast_test_status_update(test, "Could not allocate an empty format capabilities structure\n");
  819. return AST_TEST_FAIL;
  820. }
  821. ulaw = ast_codec_get("ulaw", AST_MEDIA_TYPE_AUDIO, 8000);
  822. if (!ulaw) {
  823. ast_test_status_update(test, "Could not retrieve built-in ulaw codec\n");
  824. return AST_TEST_FAIL;
  825. }
  826. ulaw_format = ast_format_create(ulaw);
  827. if (!ulaw_format) {
  828. ast_test_status_update(test, "Could not create ulaw format using built-in codec\n");
  829. return AST_TEST_FAIL;
  830. }
  831. alaw = ast_codec_get("alaw", AST_MEDIA_TYPE_AUDIO, 8000);
  832. if (!alaw) {
  833. ast_test_status_update(test, "Could not retrieve built-in alaw codec\n");
  834. return AST_TEST_FAIL;
  835. }
  836. alaw_format = ast_format_create(alaw);
  837. if (!alaw_format) {
  838. ast_test_status_update(test, "Could not create alaw format using built-in codec\n");
  839. return AST_TEST_FAIL;
  840. }
  841. if (ast_format_cap_append(ulaw_caps, ulaw_format, 0)) {
  842. ast_test_status_update(test, "Could not add ulaw format to ulaw capabilities\n");
  843. return AST_TEST_FAIL;
  844. } else if (ast_format_cap_append(alaw_caps, alaw_format, 0)) {
  845. ast_test_status_update(test, "Could not add alaw format to alaw capabilities\n");
  846. return AST_TEST_FAIL;
  847. }
  848. ast_format_cap_get_compatible(ulaw_caps, alaw_caps, compatible_caps);
  849. if (ast_format_cap_count(compatible_caps)) {
  850. ast_test_status_update(test, "A compatible format exists when none should\n");
  851. return AST_TEST_FAIL;
  852. }
  853. ast_format_cap_get_compatible(ulaw_caps, ulaw_caps, compatible_caps);
  854. if (!ast_format_cap_count(compatible_caps)) {
  855. ast_test_status_update(test, "No compatible formats exist when 1 should\n");
  856. return AST_TEST_FAIL;
  857. }
  858. return AST_TEST_PASS;
  859. }
  860. AST_TEST_DEFINE(format_cap_iscompatible)
  861. {
  862. RAII_VAR(struct ast_format_cap *, alaw_caps, NULL, ao2_cleanup);
  863. RAII_VAR(struct ast_format_cap *, ulaw_caps, NULL, ao2_cleanup);
  864. RAII_VAR(struct ast_codec *, ulaw, NULL, ao2_cleanup);
  865. RAII_VAR(struct ast_format *, ulaw_format, NULL, ao2_cleanup);
  866. RAII_VAR(struct ast_codec *, alaw, NULL, ao2_cleanup);
  867. RAII_VAR(struct ast_format *, alaw_format, NULL, ao2_cleanup);
  868. switch (cmd) {
  869. case TEST_INIT:
  870. info->name = "format_cap_iscompatible";
  871. info->category = "/main/format_cap/";
  872. info->summary = "format capabilities negotiation unit test";
  873. info->description =
  874. "Test that checking if there are compatible formats between two capabilities structures succeeds";
  875. return AST_TEST_NOT_RUN;
  876. case TEST_EXECUTE:
  877. break;
  878. }
  879. alaw_caps = ast_format_cap_alloc(AST_FORMAT_CAP_FLAG_DEFAULT);
  880. if (!alaw_caps) {
  881. ast_test_status_update(test, "Could not allocate an empty format capabilities structure\n");
  882. return AST_TEST_FAIL;
  883. }
  884. ulaw_caps = ast_format_cap_alloc(AST_FORMAT_CAP_FLAG_DEFAULT);
  885. if (!ulaw_caps) {
  886. ast_test_status_update(test, "Could not allocate an empty format capabilities structure\n");
  887. return AST_TEST_FAIL;
  888. }
  889. ulaw = ast_codec_get("ulaw", AST_MEDIA_TYPE_AUDIO, 8000);
  890. if (!ulaw) {
  891. ast_test_status_update(test, "Could not retrieve built-in ulaw codec\n");
  892. return AST_TEST_FAIL;
  893. }
  894. ulaw_format = ast_format_create(ulaw);
  895. if (!ulaw_format) {
  896. ast_test_status_update(test, "Could not create ulaw format using built-in codec\n");
  897. return AST_TEST_FAIL;
  898. }
  899. alaw = ast_codec_get("alaw", AST_MEDIA_TYPE_AUDIO, 8000);
  900. if (!alaw) {
  901. ast_test_status_update(test, "Could not retrieve built-in alaw codec\n");
  902. return AST_TEST_FAIL;
  903. }
  904. alaw_format = ast_format_create(alaw);
  905. if (!alaw_format) {
  906. ast_test_status_update(test, "Could not create alaw format using built-in codec\n");
  907. return AST_TEST_FAIL;
  908. }
  909. if (ast_format_cap_append(ulaw_caps, ulaw_format, 0)) {
  910. ast_test_status_update(test, "Could not add ulaw format to ulaw capabilities\n");
  911. return AST_TEST_FAIL;
  912. } else if (ast_format_cap_append(alaw_caps, alaw_format, 0)) {
  913. ast_test_status_update(test, "Could not add alaw format to alaw capabilities\n");
  914. return AST_TEST_FAIL;
  915. } else if (ast_format_cap_iscompatible(ulaw_caps, alaw_caps)) {
  916. ast_test_status_update(test, "Two capability structures that should not be compatible are\n");
  917. return AST_TEST_FAIL;
  918. } else if (!ast_format_cap_iscompatible(ulaw_caps, ulaw_caps)) {
  919. ast_test_status_update(test, "Capability structure is not compatible with itself\n");
  920. return AST_TEST_FAIL;
  921. }
  922. return AST_TEST_PASS;
  923. }
  924. AST_TEST_DEFINE(format_cap_get_names)
  925. {
  926. RAII_VAR(struct ast_format_cap *, empty_caps, NULL, ao2_cleanup);
  927. RAII_VAR(struct ast_format_cap *, multi_caps, NULL, ao2_cleanup);
  928. RAII_VAR(struct ast_format_cap *, alaw_caps, NULL, ao2_cleanup);
  929. RAII_VAR(struct ast_format_cap *, ulaw_caps, NULL, ao2_cleanup);
  930. RAII_VAR(struct ast_codec *, ulaw, NULL, ao2_cleanup);
  931. RAII_VAR(struct ast_format *, ulaw_format, NULL, ao2_cleanup);
  932. RAII_VAR(struct ast_codec *, alaw, NULL, ao2_cleanup);
  933. RAII_VAR(struct ast_format *, alaw_format, NULL, ao2_cleanup);
  934. struct ast_str *buffer = ast_str_alloca(AST_FORMAT_CAP_NAMES_LEN);
  935. switch (cmd) {
  936. case TEST_INIT:
  937. info->name = "format_cap_get_names";
  938. info->category = "/main/format_cap/";
  939. info->summary = "Test getting the names of formats";
  940. info->description =
  941. "Test that obtaining the names from a format capabilities structure\n"
  942. "produces the expected output.";
  943. return AST_TEST_NOT_RUN;
  944. case TEST_EXECUTE:
  945. break;
  946. }
  947. empty_caps = ast_format_cap_alloc(AST_FORMAT_CAP_FLAG_DEFAULT);
  948. if (!empty_caps) {
  949. ast_test_status_update(test, "Could not allocate an empty format capabilities structure\n");
  950. return AST_TEST_FAIL;
  951. }
  952. multi_caps = ast_format_cap_alloc(AST_FORMAT_CAP_FLAG_DEFAULT);
  953. if (!multi_caps) {
  954. ast_test_status_update(test, "Could not allocate an empty format capabilities structure\n");
  955. return AST_TEST_FAIL;
  956. }
  957. alaw_caps = ast_format_cap_alloc(AST_FORMAT_CAP_FLAG_DEFAULT);
  958. if (!alaw_caps) {
  959. ast_test_status_update(test, "Could not allocate an empty format capabilities structure\n");
  960. return AST_TEST_FAIL;
  961. }
  962. ulaw_caps = ast_format_cap_alloc(AST_FORMAT_CAP_FLAG_DEFAULT);
  963. if (!ulaw_caps) {
  964. ast_test_status_update(test, "Could not allocate an empty format capabilities structure\n");
  965. return AST_TEST_FAIL;
  966. }
  967. ulaw = ast_codec_get("ulaw", AST_MEDIA_TYPE_AUDIO, 8000);
  968. if (!ulaw) {
  969. ast_test_status_update(test, "Could not retrieve built-in ulaw codec\n");
  970. return AST_TEST_FAIL;
  971. }
  972. ulaw_format = ast_format_create(ulaw);
  973. if (!ulaw_format) {
  974. ast_test_status_update(test, "Could not create ulaw format using built-in codec\n");
  975. return AST_TEST_FAIL;
  976. }
  977. alaw = ast_codec_get("alaw", AST_MEDIA_TYPE_AUDIO, 8000);
  978. if (!alaw) {
  979. ast_test_status_update(test, "Could not retrieve built-in alaw codec\n");
  980. return AST_TEST_FAIL;
  981. }
  982. alaw_format = ast_format_create(alaw);
  983. if (!alaw_format) {
  984. ast_test_status_update(test, "Could not create alaw format using built-in codec\n");
  985. return AST_TEST_FAIL;
  986. }
  987. if (ast_format_cap_append(ulaw_caps, ulaw_format, 0)) {
  988. ast_test_status_update(test, "Could not add ulaw format to ulaw capabilities\n");
  989. return AST_TEST_FAIL;
  990. } else if (ast_format_cap_append(alaw_caps, alaw_format, 0)) {
  991. ast_test_status_update(test, "Could not add alaw format to alaw capabilities\n");
  992. return AST_TEST_FAIL;
  993. } else if (ast_format_cap_append(multi_caps, ulaw_format, 0)) {
  994. ast_test_status_update(test, "Could not add ulaw format to multi capabilities\n");
  995. return AST_TEST_FAIL;
  996. } else if (ast_format_cap_append(multi_caps, alaw_format, 0)) {
  997. ast_test_status_update(test, "Could not add alaw format to multi capabilities\n");
  998. return AST_TEST_FAIL;
  999. }
  1000. ast_format_cap_get_names(empty_caps, &buffer);
  1001. ast_test_validate(test, !strcmp(ast_str_buffer(buffer), "(nothing)"));
  1002. ast_format_cap_get_names(ulaw_caps, &buffer);
  1003. ast_test_validate(test, !strcmp(ast_str_buffer(buffer), "(ulaw)"));
  1004. ast_format_cap_get_names(alaw_caps, &buffer);
  1005. ast_test_validate(test, !strcmp(ast_str_buffer(buffer), "(alaw)"));
  1006. ast_format_cap_get_names(multi_caps, &buffer);
  1007. ast_test_validate(test, !strcmp(ast_str_buffer(buffer), "(ulaw|alaw)"));
  1008. return AST_TEST_PASS;
  1009. }
  1010. AST_TEST_DEFINE(format_cap_best_by_type)
  1011. {
  1012. RAII_VAR(struct ast_format_cap *, caps, NULL, ao2_cleanup);
  1013. RAII_VAR(struct ast_codec *, ulaw, NULL, ao2_cleanup);
  1014. RAII_VAR(struct ast_format *, ulaw_format, NULL, ao2_cleanup);
  1015. RAII_VAR(struct ast_codec *, alaw, NULL, ao2_cleanup);
  1016. RAII_VAR(struct ast_format *, alaw_format, NULL, ao2_cleanup);
  1017. RAII_VAR(struct ast_codec *, h263, NULL, ao2_cleanup);
  1018. RAII_VAR(struct ast_format *, h263_format, NULL, ao2_cleanup);
  1019. RAII_VAR(struct ast_format *, best_format, NULL, ao2_cleanup);
  1020. switch (cmd) {
  1021. case TEST_INIT:
  1022. info->name = __PRETTY_FUNCTION__;
  1023. info->category = "/main/format_cap/";
  1024. info->summary = "format capabilities best by type unit test";
  1025. info->description =
  1026. "Test that we can get the best format type out of a capabilities structure";
  1027. return AST_TEST_NOT_RUN;
  1028. case TEST_EXECUTE:
  1029. break;
  1030. }
  1031. caps = ast_format_cap_alloc(AST_FORMAT_CAP_FLAG_DEFAULT);
  1032. if (!caps) {
  1033. ast_test_status_update(test, "Could not allocate an empty format capabilities structure\n");
  1034. return AST_TEST_FAIL;
  1035. }
  1036. ulaw = ast_codec_get("ulaw", AST_MEDIA_TYPE_AUDIO, 8000);
  1037. if (!ulaw) {
  1038. ast_test_status_update(test, "Could not retrieve built-in ulaw codec\n");
  1039. return AST_TEST_FAIL;
  1040. }
  1041. ulaw_format = ast_format_create(ulaw);
  1042. if (!ulaw_format) {
  1043. ast_test_status_update(test, "Could not create ulaw format using built-in codec\n");
  1044. return AST_TEST_FAIL;
  1045. }
  1046. alaw = ast_codec_get("alaw", AST_MEDIA_TYPE_AUDIO, 8000);
  1047. if (!alaw) {
  1048. ast_test_status_update(test, "Could not retrieve built-in alaw codec\n");
  1049. return AST_TEST_FAIL;
  1050. }
  1051. alaw_format = ast_format_create(alaw);
  1052. if (!alaw_format) {
  1053. ast_test_status_update(test, "Could not create alaw format using built-in codec\n");
  1054. return AST_TEST_FAIL;
  1055. }
  1056. h263 = ast_codec_get("h263", AST_MEDIA_TYPE_VIDEO, 0);
  1057. if (!h263) {
  1058. ast_test_status_update(test, "Could not retrieve built-in h263 codec\n");
  1059. return AST_TEST_FAIL;
  1060. }
  1061. h263_format = ast_format_create(h263);
  1062. if (!alaw_format) {
  1063. ast_test_status_update(test, "Could not create h263 format using built-in codec\n");
  1064. return AST_TEST_FAIL;
  1065. }
  1066. if (ast_format_cap_append(caps, ulaw_format, 0)) {
  1067. ast_test_status_update(test, "Could not add ulaw format to capabilities\n");
  1068. return AST_TEST_FAIL;
  1069. } else if (ast_format_cap_append(caps, alaw_format, 0)) {
  1070. ast_test_status_update(test, "Could not add alaw format to capabilities\n");
  1071. return AST_TEST_FAIL;
  1072. } else if (ast_format_cap_append(caps, h263_format, 0)) {
  1073. ast_test_status_update(test, "Could not add h263 format to capabilities\n");
  1074. return AST_TEST_FAIL;
  1075. }
  1076. best_format = ast_format_cap_get_best_by_type(caps, AST_MEDIA_TYPE_UNKNOWN);
  1077. ast_test_validate(test, ast_format_cmp(best_format, ulaw_format) == AST_FORMAT_CMP_EQUAL);
  1078. ao2_ref(best_format, -1);
  1079. best_format = ast_format_cap_get_best_by_type(caps, AST_MEDIA_TYPE_AUDIO);
  1080. ast_test_validate(test, ast_format_cmp(best_format, ulaw_format) == AST_FORMAT_CMP_EQUAL);
  1081. ao2_ref(best_format, -1);
  1082. best_format = ast_format_cap_get_best_by_type(caps, AST_MEDIA_TYPE_VIDEO);
  1083. ast_test_validate(test, ast_format_cmp(best_format, h263_format) == AST_FORMAT_CMP_EQUAL);
  1084. ao2_ref(best_format, -1);
  1085. best_format = ast_format_cap_get_best_by_type(caps, AST_MEDIA_TYPE_IMAGE);
  1086. ast_test_validate(test, best_format == NULL);
  1087. best_format = ast_format_cap_get_best_by_type(caps, AST_MEDIA_TYPE_TEXT);
  1088. ast_test_validate(test, best_format == NULL);
  1089. return AST_TEST_PASS;
  1090. }
  1091. static int test_law_samples(struct ast_frame *frame)
  1092. {
  1093. return frame->datalen;
  1094. }
  1095. static int test_law_length(unsigned int samples)
  1096. {
  1097. return samples;
  1098. }
  1099. static struct ast_codec test_law = {
  1100. .name = "test_law",
  1101. .description = "format cap unit test codec",
  1102. .type = AST_MEDIA_TYPE_AUDIO,
  1103. .sample_rate = 8000,
  1104. .minimum_ms = 10,
  1105. .maximum_ms = 150,
  1106. .default_ms = 20,
  1107. .samples_count = test_law_samples,
  1108. .get_length = test_law_length,
  1109. .smooth = 1,
  1110. };
  1111. static enum ast_format_cmp_res test_law_cmp(const struct ast_format *format1, const struct ast_format *format2)
  1112. {
  1113. ast_log(LOG_ERROR, "Comparing format1 %p and format2 %p\n", format1, format2);
  1114. return format1 == format2 ? AST_FORMAT_CMP_EQUAL : AST_FORMAT_CMP_NOT_EQUAL;
  1115. }
  1116. static void test_law_destroy(struct ast_format *format)
  1117. {
  1118. }
  1119. static int test_law_clone(const struct ast_format *src, struct ast_format *dst)
  1120. {
  1121. return 0;
  1122. }
  1123. static struct ast_format_interface test_law_interface = {
  1124. .format_cmp = test_law_cmp,
  1125. .format_clone = test_law_clone,
  1126. .format_destroy = test_law_destroy,
  1127. };
  1128. AST_TEST_DEFINE(format_cap_replace_from_cap)
  1129. {
  1130. RAII_VAR(struct ast_format_cap *, caps, NULL, ao2_cleanup);
  1131. RAII_VAR(struct ast_format_cap *, replace_caps, NULL, ao2_cleanup);
  1132. RAII_VAR(struct ast_format_cap *, result_caps, NULL, ao2_cleanup);
  1133. RAII_VAR(struct ast_codec *, ulaw, NULL, ao2_cleanup);
  1134. RAII_VAR(struct ast_format *, ulaw_format, NULL, ao2_cleanup);
  1135. RAII_VAR(struct ast_format *, ulaw_format_variant, NULL, ao2_cleanup);
  1136. RAII_VAR(struct ast_codec *, alaw, NULL, ao2_cleanup);
  1137. RAII_VAR(struct ast_format *, alaw_format, NULL, ao2_cleanup);
  1138. switch (cmd) {
  1139. case TEST_INIT:
  1140. info->name = __PRETTY_FUNCTION__;
  1141. info->category = "/main/format_cap/";
  1142. info->summary = "format capabilities adding unit test";
  1143. info->description =
  1144. "Test that adding multiple formats to a format capabilities structure succeeds";
  1145. return AST_TEST_NOT_RUN;
  1146. case TEST_EXECUTE:
  1147. break;
  1148. }
  1149. caps = ast_format_cap_alloc(AST_FORMAT_CAP_FLAG_DEFAULT);
  1150. replace_caps = ast_format_cap_alloc(AST_FORMAT_CAP_FLAG_DEFAULT);
  1151. result_caps = ast_format_cap_alloc(AST_FORMAT_CAP_FLAG_DEFAULT);
  1152. if (!caps || !replace_caps || !result_caps) {
  1153. ast_test_status_update(test, "Could not allocate an empty format capabilities structure\n");
  1154. return AST_TEST_FAIL;
  1155. }
  1156. ulaw = ast_codec_get("test_law", AST_MEDIA_TYPE_AUDIO, 8000);
  1157. if (!ulaw) {
  1158. ast_test_status_update(test, "Could not retrieve test_law codec\n");
  1159. return AST_TEST_FAIL;
  1160. }
  1161. ulaw_format = ast_format_create(ulaw);
  1162. if (!ulaw_format) {
  1163. ast_test_status_update(test, "Could not create ulaw format using built-in codec\n");
  1164. return AST_TEST_FAIL;
  1165. }
  1166. ulaw_format_variant = ast_format_create(ulaw);
  1167. if (!ulaw_format_variant) {
  1168. ast_test_status_update(test, "Could not create ulaw format variant using built-in codec\n");
  1169. return AST_TEST_FAIL;
  1170. }
  1171. alaw = ast_codec_get("alaw", AST_MEDIA_TYPE_AUDIO, 8000);
  1172. if (!alaw) {
  1173. ast_test_status_update(test, "Could not retrieve built-in alaw codec\n");
  1174. return AST_TEST_FAIL;
  1175. }
  1176. alaw_format = ast_format_create(alaw);
  1177. if (!alaw_format) {
  1178. ast_test_status_update(test, "Could not create alaw format using built-in codec\n");
  1179. return AST_TEST_FAIL;
  1180. }
  1181. /* fill caps with ulaw and alaw */
  1182. if (ast_format_cap_append(caps, ulaw_format, 42)) {
  1183. ast_test_status_update(test, "Could not add ulaw format to capabilities structure\n");
  1184. return AST_TEST_FAIL;
  1185. }
  1186. if (ast_format_cap_append(caps, alaw_format, 84)) {
  1187. ast_test_status_update(test, "Could not add alaw format to capabilities structure\n");
  1188. return AST_TEST_FAIL;
  1189. }
  1190. if (ast_format_cap_count(caps) != 2) {
  1191. ast_test_status_update(test, "Number of formats in capabilities structure should be 2 but is %zu\n",
  1192. ast_format_cap_count(caps));
  1193. return AST_TEST_FAIL;
  1194. }
  1195. /* fill replace_caps with the ulaw variant */
  1196. if (ast_format_cap_append(replace_caps, ulaw_format_variant, 42)) {
  1197. ast_test_status_update(test, "Could not add ulaw format to capabilities structure\n");
  1198. return AST_TEST_FAIL;
  1199. }
  1200. if (ast_format_cap_count(replace_caps) != 1) {
  1201. ast_test_status_update(test, "Number of formats in capabilities structure should be 1 but is %zu\n",
  1202. ast_format_cap_count(replace_caps));
  1203. return AST_TEST_FAIL;
  1204. }
  1205. /* fill result_caps with ulaw_variant and alaw */
  1206. if (ast_format_cap_append(result_caps, ulaw_format_variant, 42)) {
  1207. ast_test_status_update(test, "Could not add ulaw variant to capabilities structure\n");
  1208. return AST_TEST_FAIL;
  1209. }
  1210. if (ast_format_cap_append(result_caps, alaw_format, 84)) {
  1211. ast_test_status_update(test, "Could not add alaw format to capabilities structure\n");
  1212. return AST_TEST_FAIL;
  1213. }
  1214. if (ast_format_cap_count(result_caps) != 2) {
  1215. ast_test_status_update(test, "Number of formats in capabilities structure should be 2 but is %zu\n",
  1216. ast_format_cap_count(result_caps));
  1217. return AST_TEST_FAIL;
  1218. }
  1219. /* replace caps formats from replace_caps */
  1220. ast_format_cap_replace_from_cap(caps, replace_caps, AST_MEDIA_TYPE_UNKNOWN);
  1221. /* compare result_caps with caps */
  1222. if (!ast_format_cap_identical(caps, result_caps)) {
  1223. ast_test_status_update(test, "Actual and expected result caps differ\n");
  1224. return AST_TEST_FAIL;
  1225. }
  1226. return AST_TEST_PASS;
  1227. }
  1228. static int unload_module(void)
  1229. {
  1230. AST_TEST_UNREGISTER(format_cap_alloc);
  1231. AST_TEST_UNREGISTER(format_cap_append_single);
  1232. AST_TEST_UNREGISTER(format_cap_append_multiple);
  1233. AST_TEST_UNREGISTER(format_cap_append_all_unknown);
  1234. AST_TEST_UNREGISTER(format_cap_append_all_audio);
  1235. AST_TEST_UNREGISTER(format_cap_append_duplicate);
  1236. AST_TEST_UNREGISTER(format_cap_append_from_cap);
  1237. AST_TEST_UNREGISTER(format_cap_append_from_cap_duplicate);
  1238. AST_TEST_UNREGISTER(format_cap_set_framing);
  1239. AST_TEST_UNREGISTER(format_cap_remove_single);
  1240. AST_TEST_UNREGISTER(format_cap_remove_multiple);
  1241. AST_TEST_UNREGISTER(format_cap_remove_bytype);
  1242. AST_TEST_UNREGISTER(format_cap_remove_all);
  1243. AST_TEST_UNREGISTER(format_cap_get_names);
  1244. AST_TEST_UNREGISTER(format_cap_get_compatible_format);
  1245. AST_TEST_UNREGISTER(format_cap_iscompatible_format);
  1246. AST_TEST_UNREGISTER(format_cap_get_compatible);
  1247. AST_TEST_UNREGISTER(format_cap_iscompatible);
  1248. AST_TEST_UNREGISTER(format_cap_best_by_type);
  1249. AST_TEST_UNREGISTER(format_cap_replace_from_cap);
  1250. return 0;
  1251. }
  1252. static int load_module(void)
  1253. {
  1254. AST_TEST_REGISTER(format_cap_alloc);
  1255. AST_TEST_REGISTER(format_cap_append_single);
  1256. AST_TEST_REGISTER(format_cap_append_multiple);
  1257. AST_TEST_REGISTER(format_cap_append_all_unknown);
  1258. AST_TEST_REGISTER(format_cap_append_all_audio);
  1259. AST_TEST_REGISTER(format_cap_append_duplicate);
  1260. AST_TEST_REGISTER(format_cap_append_from_cap);
  1261. AST_TEST_REGISTER(format_cap_append_from_cap_duplicate);
  1262. AST_TEST_REGISTER(format_cap_set_framing);
  1263. AST_TEST_REGISTER(format_cap_remove_single);
  1264. AST_TEST_REGISTER(format_cap_remove_multiple);
  1265. AST_TEST_REGISTER(format_cap_remove_bytype);
  1266. AST_TEST_REGISTER(format_cap_remove_all);
  1267. AST_TEST_REGISTER(format_cap_get_names);
  1268. AST_TEST_REGISTER(format_cap_get_compatible_format);
  1269. AST_TEST_REGISTER(format_cap_iscompatible_format);
  1270. AST_TEST_REGISTER(format_cap_get_compatible);
  1271. AST_TEST_REGISTER(format_cap_iscompatible);
  1272. AST_TEST_REGISTER(format_cap_best_by_type);
  1273. AST_TEST_REGISTER(format_cap_replace_from_cap);
  1274. ast_codec_register(&test_law);
  1275. ast_format_interface_register("test_law", &test_law_interface);
  1276. return AST_MODULE_LOAD_SUCCESS;
  1277. }
  1278. AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "Format capabilities API test module");