test_format_cap.c 52 KB

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