Asterisk - The Open Source Telephony Project  18.5.0
Data Structures | Macros | Functions | Variables
test_core_format.c File Reference

Core Format API Unit Tests. More...

#include "asterisk.h"
#include "asterisk/test.h"
#include "asterisk/module.h"
#include "asterisk/codec.h"
#include "asterisk/format.h"
Include dependency graph for test_core_format.c:

Go to the source code of this file.

Data Structures

struct  callbacks_called
 Tracking object used to verify format attribute callbacks. More...
 
struct  test_core_format_pvt
 A test piece of data to associate with test_core_format_attr. More...
 

Macros

#define TEST_CATEGORY   "/main/core_format/"
 

Functions

static void __reg_module (void)
 
static void __unreg_module (void)
 
struct ast_moduleAST_MODULE_SELF_SYM (void)
 
 AST_TEST_DEFINE (format_create)
 
 AST_TEST_DEFINE (format_create_attr)
 
 AST_TEST_DEFINE (format_retrieve_attr)
 
 AST_TEST_DEFINE (format_clone)
 
 AST_TEST_DEFINE (format_cmp_same_codec)
 
 AST_TEST_DEFINE (format_cmp_different_codec)
 
 AST_TEST_DEFINE (format_attr_cmp_same_codec)
 
 AST_TEST_DEFINE (format_joint_same_codec)
 
 AST_TEST_DEFINE (format_attr_joint_same_codec)
 
 AST_TEST_DEFINE (format_joint_different_codec)
 
 AST_TEST_DEFINE (format_copy)
 
 AST_TEST_DEFINE (format_attribute_set_without_interface)
 
 AST_TEST_DEFINE (format_attribute_get_without_interface)
 
 AST_TEST_DEFINE (format_parse_sdp_fmtp_without_interface)
 
 AST_TEST_DEFINE (format_parse_and_generate_sdp_fmtp)
 
static int load_module (void)
 
static const void * test_core_format_attribute_get (const struct ast_format *format, const char *name)
 Format attribute callback for retrieving an attribute. More...
 
static struct ast_formattest_core_format_attribute_set (const struct ast_format *format, const char *name, const char *value)
 Format attribute callback for setting an attribute on a format. More...
 
static int test_core_format_clone (const struct ast_format *src, struct ast_format *dst)
 Format attribute callback called during format cloning. More...
 
static enum ast_format_cmp_res test_core_format_cmp (const struct ast_format *format1, const struct ast_format *format2)
 Format attribute callback called during format comparison. More...
 
static void test_core_format_destroy (struct ast_format *format)
 Format attribute callback for when format attributes are to be destroyed. More...
 
static void test_core_format_generate_sdp_fmtp (const struct ast_format *format, unsigned int payload, struct ast_str **str)
 Format attribute callback to generate an SDP fmtp line from a format. More...
 
static struct ast_formattest_core_format_get_joint (const struct ast_format *format1, const struct ast_format *format2)
 Format attribute callback called during joint format capability. More...
 
static int test_core_format_init (struct ast_test_info *info, struct ast_test *test)
 
static struct ast_formattest_core_format_parse_sdp_fmtp (const struct ast_format *format, const char *attributes)
 Format attribute callback to construct a format from an SDP fmtp line. More...
 
static int unload_module (void)
 

Variables

static struct ast_module_info __mod_info = { .name = AST_MODULE, .flags = AST_MODFLAG_LOAD_ORDER , .description = "Core format API test module" , .key = "This paragraph is copyright (c) 2006 by Digium, Inc. \In order for your module to load, it must return this \key via a function called \"key\". Any code which \includes this paragraph must be licensed under the GNU \General Public License version 2 or later (at your \option). In addition to Digium's general reservations \of rights, Digium expressly reserves the right to \allow other parties to license this paragraph under \different terms. Any use of Digium, Inc. trademarks or \logos (including \"Asterisk\" or \"Digium\") without \express written permission of Digium, Inc. is prohibited.\n" , .buildopt_sum = AST_BUILDOPT_SUM, .load = load_module, .unload = unload_module, .load_pri = AST_MODPRI_DEFAULT, .support_level = AST_MODULE_SUPPORT_CORE, }
 
static const struct ast_module_infoast_module_info = &__mod_info
 
static struct callbacks_called test_callbacks_called
 A global tracking object. Cleared out by the test init cb. More...
 
static struct ast_format_interface test_core_format_attr
 A format attribute 'module' used by the unit tests. More...
 
static struct ast_codec test_core_format_codec
 A test codec for these unit tests. Should be used with test_core_format. More...
 

Detailed Description

Core Format API Unit Tests.

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

Definition in file test_core_format.c.

Macro Definition Documentation

◆ TEST_CATEGORY

#define TEST_CATEGORY   "/main/core_format/"

Definition at line 39 of file test_core_format.c.

Referenced by AST_TEST_DEFINE(), and load_module().

Function Documentation

◆ __reg_module()

static void __reg_module ( void  )
static

Definition at line 1081 of file test_core_format.c.

◆ __unreg_module()

static void __unreg_module ( void  )
static

Definition at line 1081 of file test_core_format.c.

◆ AST_MODULE_SELF_SYM()

struct ast_module* AST_MODULE_SELF_SYM ( void  )

Definition at line 1081 of file test_core_format.c.

◆ AST_TEST_DEFINE() [1/15]

AST_TEST_DEFINE ( format_create  )

Definition at line 253 of file test_core_format.c.

References ao2_cleanup, ao2_ref, ast_codec_get(), ast_format_create(), ast_format_create_named(), ast_format_get_codec_id(), AST_MEDIA_TYPE_AUDIO, AST_TEST_FAIL, AST_TEST_NOT_RUN, AST_TEST_PASS, ast_test_status_update, format, sip_to_pjsip::info(), NULL, RAII_VAR, TEST_CATEGORY, TEST_EXECUTE, and TEST_INIT.

254 {
255  RAII_VAR(struct ast_codec *, codec, NULL, ao2_cleanup);
257 
258  switch (cmd) {
259  case TEST_INIT:
260  info->name = __PRETTY_FUNCTION__;
261  info->category = TEST_CATEGORY;
262  info->summary = "Format creation unit test";
263  info->description =
264  "Test creation of a format";
265  return AST_TEST_NOT_RUN;
266  case TEST_EXECUTE:
267  break;
268  }
269 
270  codec = ast_codec_get("ulaw", AST_MEDIA_TYPE_AUDIO, 8000);
271  if (!codec) {
272  ast_test_status_update(test, "Could not retrieve built-in ulaw codec\n");
273  return AST_TEST_FAIL;
274  }
275 
276  format = ast_format_create(codec);
277  if (!format) {
278  ast_test_status_update(test, "Could not create format using built-in codec\n");
279  return AST_TEST_FAIL;
280  } else if (ast_format_get_codec_id(format) != codec->id) {
281  ast_test_status_update(test, "Created format does not contain provided codec\n");
282  return AST_TEST_FAIL;
283  }
284 
285  ao2_ref(format, -1);
286  format = ast_format_create_named("super_ulaw", 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  } else if (ast_format_get_codec_id(format) != codec->id) {
291  ast_test_status_update(test, "Created format does not contain provided codec\n");
292  return AST_TEST_FAIL;
293  }
294 
295  return AST_TEST_PASS;
296 }
struct ast_format * ast_format_create(struct ast_codec *codec)
Create a new media format.
Definition: format.c:196
#define TEST_CATEGORY
Definition of a media format.
Definition: format.c:43
struct ast_codec * ast_codec_get(const char *name, enum ast_media_type type, unsigned int sample_rate)
Retrieve a codec given a name, type, and sample rate.
Definition: codec.c:326
#define NULL
Definition: resample.c:96
#define RAII_VAR(vartype, varname, initval, dtor)
Declare a variable that will call a destructor function when it goes out of scope.
Definition: utils.h:911
#define ast_test_status_update(a, b, c...)
Definition: test.h:129
#define ao2_ref(o, delta)
Definition: astobj2.h:464
def info(msg)
#define ao2_cleanup(obj)
Definition: astobj2.h:1958
struct ast_format * ast_format_create_named(const char *format_name, struct ast_codec *codec)
Create a new media format with a specific name.
Definition: format.c:157
static snd_pcm_format_t format
Definition: chan_alsa.c:102
unsigned int ast_format_get_codec_id(const struct ast_format *format)
Get the codec identifier associated with a format.
Definition: format.c:329
Represents a media codec within Asterisk.
Definition: codec.h:42

◆ AST_TEST_DEFINE() [2/15]

AST_TEST_DEFINE ( format_create_attr  )

Definition at line 298 of file test_core_format.c.

References ao2_cleanup, ast_codec_get(), ast_format_attribute_set(), ast_format_cmp(), AST_FORMAT_CMP_EQUAL, ast_format_create(), ast_format_get_codec_id(), AST_MEDIA_TYPE_AUDIO, AST_TEST_FAIL, AST_TEST_NOT_RUN, AST_TEST_PASS, ast_test_status_update, format, callbacks_called::format_attribute_set, callbacks_called::format_cmp, sip_to_pjsip::info(), NULL, RAII_VAR, test_callbacks_called, TEST_CATEGORY, TEST_EXECUTE, and TEST_INIT.

299 {
300  RAII_VAR(struct ast_codec *, codec, NULL, ao2_cleanup);
302  RAII_VAR(struct ast_format *, format_w_attr, NULL, ao2_cleanup);
303 
304  switch (cmd) {
305  case TEST_INIT:
306  info->name = __PRETTY_FUNCTION__;
307  info->category = TEST_CATEGORY;
308  info->summary = "Format creation w/ attributes unit test";
309  info->description =
310  "Test creation of a format with attributes";
311  return AST_TEST_NOT_RUN;
312  case TEST_EXECUTE:
313  break;
314  }
315 
316  codec = ast_codec_get("test_core_format_codec", AST_MEDIA_TYPE_AUDIO, 8000);
317  if (!codec) {
318  ast_test_status_update(test, "Could not retrieve test_core_format_codec codec\n");
319  return AST_TEST_FAIL;
320  }
321 
322  format = ast_format_create(codec);
323  if (!format) {
324  ast_test_status_update(test, "Could not create format using test_core_format_codec codec\n");
325  return AST_TEST_FAIL;
326  } else if (ast_format_get_codec_id(format) != codec->id) {
327  ast_test_status_update(test, "Created format does not contain provided codec\n");
328  return AST_TEST_FAIL;
329  }
330 
331  format_w_attr = ast_format_attribute_set(format, "one", "1");
332  if (!format_w_attr) {
333  ast_test_status_update(test, "Could not create format with attributes using test_core_format_codec codec\n");
334  return AST_TEST_FAIL;
335  } else if (ast_format_get_codec_id(format_w_attr) != codec->id) {
336  ast_test_status_update(test, "Created format does not contain provided codec\n");
337  return AST_TEST_FAIL;
338  } else if (ast_format_cmp(format, format_w_attr) == AST_FORMAT_CMP_EQUAL) {
339  ast_test_status_update(test, "Format with attributes should not be equal to format without attributes\n");
340  return AST_TEST_FAIL;
341  }
342 
343  ast_test_validate(test, test_callbacks_called.format_attribute_set == 1);
344  ast_test_validate(test, test_callbacks_called.format_cmp == 1);
345 
346  return AST_TEST_PASS;
347 }
struct ast_format * ast_format_create(struct ast_codec *codec)
Create a new media format.
Definition: format.c:196
#define TEST_CATEGORY
Definition of a media format.
Definition: format.c:43
struct ast_codec * ast_codec_get(const char *name, enum ast_media_type type, unsigned int sample_rate)
Retrieve a codec given a name, type, and sample rate.
Definition: codec.c:326
#define NULL
Definition: resample.c:96
enum ast_format_cmp_res ast_format_cmp(const struct ast_format *format1, const struct ast_format *format2)
Compare two formats.
Definition: format.c:201
#define RAII_VAR(vartype, varname, initval, dtor)
Declare a variable that will call a destructor function when it goes out of scope.
Definition: utils.h:911
#define ast_test_status_update(a, b, c...)
Definition: test.h:129
struct ast_format * ast_format_attribute_set(const struct ast_format *format, const char *name, const char *value)
Set an attribute on a format to a specific value.
Definition: format.c:248
static struct callbacks_called test_callbacks_called
A global tracking object. Cleared out by the test init cb.
def info(msg)
#define ao2_cleanup(obj)
Definition: astobj2.h:1958
static snd_pcm_format_t format
Definition: chan_alsa.c:102
unsigned int ast_format_get_codec_id(const struct ast_format *format)
Get the codec identifier associated with a format.
Definition: format.c:329
Represents a media codec within Asterisk.
Definition: codec.h:42

◆ AST_TEST_DEFINE() [3/15]

AST_TEST_DEFINE ( format_retrieve_attr  )

Definition at line 349 of file test_core_format.c.

References ao2_cleanup, ast_codec_get(), ast_format_attribute_get(), ast_format_attribute_set(), ast_format_create(), AST_MEDIA_TYPE_AUDIO, AST_TEST_FAIL, AST_TEST_NOT_RUN, AST_TEST_PASS, ast_test_status_update, format, sip_to_pjsip::info(), NULL, RAII_VAR, TEST_CATEGORY, TEST_EXECUTE, and TEST_INIT.

350 {
351  RAII_VAR(struct ast_codec *, codec, NULL, ao2_cleanup);
353  RAII_VAR(struct ast_format *, format_w_attr, NULL, ao2_cleanup);
354 
355  switch (cmd) {
356  case TEST_INIT:
357  info->name = __PRETTY_FUNCTION__;
358  info->category = TEST_CATEGORY;
359  info->summary = "Format attribute retrieval unit test";
360  info->description =
361  "Test retrieval of format attributes";
362  return AST_TEST_NOT_RUN;
363  case TEST_EXECUTE:
364  break;
365  }
366 
367  codec = ast_codec_get("test_core_format_codec", AST_MEDIA_TYPE_AUDIO, 8000);
368  if (!codec) {
369  ast_test_status_update(test, "Could not retrieve test_core_format_codec codec\n");
370  return AST_TEST_FAIL;
371  }
372 
373  format = ast_format_create(codec);
374  if (!format) {
375  ast_test_status_update(test, "Could not create format using test_core_format_codec codec\n");
376  return AST_TEST_FAIL;
377  }
378 
379  format_w_attr = ast_format_attribute_set(format, "one", "1");
380  if (!format_w_attr) {
381  ast_test_status_update(test, "Could not create format with attributes using test_core_format_codec codec\n");
382  return AST_TEST_FAIL;
383  }
384 
385  if (*((int *)ast_format_attribute_get(format_w_attr, "one")) != 1) {
386  ast_test_status_update(test, "Could not retrieve valid format attribute\n");
387  return AST_TEST_FAIL;
388  }
389 
390  if (ast_format_attribute_get(format_w_attr, "foo") != NULL) {
391  ast_test_status_update(test, "Retrieved invalid format attribute\n");
392  return AST_TEST_FAIL;
393  }
394 
395  return AST_TEST_PASS;
396 }
struct ast_format * ast_format_create(struct ast_codec *codec)
Create a new media format.
Definition: format.c:196
#define TEST_CATEGORY
Definition of a media format.
Definition: format.c:43
struct ast_codec * ast_codec_get(const char *name, enum ast_media_type type, unsigned int sample_rate)
Retrieve a codec given a name, type, and sample rate.
Definition: codec.c:326
#define NULL
Definition: resample.c:96
#define RAII_VAR(vartype, varname, initval, dtor)
Declare a variable that will call a destructor function when it goes out of scope.
Definition: utils.h:911
#define ast_test_status_update(a, b, c...)
Definition: test.h:129
struct ast_format * ast_format_attribute_set(const struct ast_format *format, const char *name, const char *value)
Set an attribute on a format to a specific value.
Definition: format.c:248
def info(msg)
#define ao2_cleanup(obj)
Definition: astobj2.h:1958
const void * ast_format_attribute_get(const struct ast_format *format, const char *name)
Definition: format.c:267
static snd_pcm_format_t format
Definition: chan_alsa.c:102
Represents a media codec within Asterisk.
Definition: codec.h:42

◆ AST_TEST_DEFINE() [4/15]

AST_TEST_DEFINE ( format_clone  )

Definition at line 398 of file test_core_format.c.

References ao2_cleanup, ao2_ref, ast_codec_get(), ast_format_attribute_set(), ast_format_clone(), ast_format_cmp(), AST_FORMAT_CMP_EQUAL, ast_format_create(), ast_format_get_codec_id(), AST_MEDIA_TYPE_AUDIO, AST_TEST_FAIL, AST_TEST_NOT_RUN, AST_TEST_PASS, ast_test_status_update, format, callbacks_called::format_attribute_set, callbacks_called::format_clone, callbacks_called::format_cmp, sip_to_pjsip::info(), NULL, RAII_VAR, test_callbacks_called, TEST_CATEGORY, TEST_EXECUTE, and TEST_INIT.

399 {
400  RAII_VAR(struct ast_codec *, codec, NULL, ao2_cleanup);
402  RAII_VAR(struct ast_format *, format_w_attr, NULL, ao2_cleanup);
403  RAII_VAR(struct ast_format *, clone, NULL, ao2_cleanup);
404 
405  switch (cmd) {
406  case TEST_INIT:
407  info->name = __PRETTY_FUNCTION__;
408  info->category = TEST_CATEGORY;
409  info->summary = "Format cloning unit test";
410  info->description =
411  "Test cloning of a format";
412  return AST_TEST_NOT_RUN;
413  case TEST_EXECUTE:
414  break;
415  }
416 
417  codec = ast_codec_get("test_core_format_codec", AST_MEDIA_TYPE_AUDIO, 8000);
418  if (!codec) {
419  ast_test_status_update(test, "Could not retrieve test_core_format_codec codec\n");
420  return AST_TEST_FAIL;
421  }
422 
423  format = ast_format_create(codec);
424  if (!format) {
425  ast_test_status_update(test, "Could not create format using test_core_format_codec codec\n");
426  return AST_TEST_FAIL;
427  } else if (ast_format_get_codec_id(format) != codec->id) {
428  ast_test_status_update(test, "Created format does not contain provided codec\n");
429  return AST_TEST_FAIL;
430  }
431 
432  format_w_attr = ast_format_attribute_set(format, "one", "1");
433  if (!format_w_attr) {
434  ast_test_status_update(test, "Could not create format with attributes using test_core_format_codec codec\n");
435  return AST_TEST_FAIL;
436  } else if (ast_format_get_codec_id(format_w_attr) != codec->id) {
437  ast_test_status_update(test, "Created format does not contain provided codec\n");
438  return AST_TEST_FAIL;
439  }
440 
441  /* Test cloning a format without attributes */
442  clone = ast_format_clone(format);
443  if (!clone) {
444  ast_test_status_update(test, "Could not create cloned format\n");
445  return AST_TEST_FAIL;
446  } else if (ast_format_get_codec_id(clone) != codec->id) {
447  ast_test_status_update(test, "Cloned format does not contain provided codec\n");
448  return AST_TEST_FAIL;
449  } else if (clone == format) {
450  ast_test_status_update(test, "Cloned format pointer is the same as original format pointer\n");
451  return AST_TEST_FAIL;
452  } else if (ast_format_cmp(clone, format) != AST_FORMAT_CMP_EQUAL) {
453  ast_test_status_update(test, "Cloned format is not the same as its original format\n");
454  return AST_TEST_FAIL;
455  }
456  ao2_ref(clone, -1);
457 
458  /* Test cloning a format with attributes */
459  clone = ast_format_clone(format_w_attr);
460  if (!clone) {
461  ast_test_status_update(test, "Could not create cloned format\n");
462  return AST_TEST_FAIL;
463  } else if (ast_format_get_codec_id(clone) != codec->id) {
464  ast_test_status_update(test, "Cloned format does not contain provided codec\n");
465  return AST_TEST_FAIL;
466  } else if (clone == format_w_attr) {
467  ast_test_status_update(test, "Cloned format pointer is the same as original format pointer\n");
468  return AST_TEST_FAIL;
469  } else if (ast_format_cmp(clone, format_w_attr) != AST_FORMAT_CMP_EQUAL) {
470  ast_test_status_update(test, "Cloned format is not the same as its original format\n");
471  return AST_TEST_FAIL;
472  }
473  ast_test_validate(test, test_callbacks_called.format_attribute_set == 1);
474  ast_test_validate(test, test_callbacks_called.format_clone == 3);
475  ast_test_validate(test, test_callbacks_called.format_cmp == 2);
476 
477  return AST_TEST_PASS;
478 }
struct ast_format * ast_format_create(struct ast_codec *codec)
Create a new media format.
Definition: format.c:196
#define TEST_CATEGORY
Definition of a media format.
Definition: format.c:43
struct ast_codec * ast_codec_get(const char *name, enum ast_media_type type, unsigned int sample_rate)
Retrieve a codec given a name, type, and sample rate.
Definition: codec.c:326
#define NULL
Definition: resample.c:96
struct ast_format * ast_format_clone(const struct ast_format *format)
Clone an existing media format so it can be modified.
Definition: format.c:180
enum ast_format_cmp_res ast_format_cmp(const struct ast_format *format1, const struct ast_format *format2)
Compare two formats.
Definition: format.c:201
#define RAII_VAR(vartype, varname, initval, dtor)
Declare a variable that will call a destructor function when it goes out of scope.
Definition: utils.h:911
#define ast_test_status_update(a, b, c...)
Definition: test.h:129
#define ao2_ref(o, delta)
Definition: astobj2.h:464
struct ast_format * ast_format_attribute_set(const struct ast_format *format, const char *name, const char *value)
Set an attribute on a format to a specific value.
Definition: format.c:248
static struct callbacks_called test_callbacks_called
A global tracking object. Cleared out by the test init cb.
def info(msg)
#define ao2_cleanup(obj)
Definition: astobj2.h:1958
static snd_pcm_format_t format
Definition: chan_alsa.c:102
unsigned int ast_format_get_codec_id(const struct ast_format *format)
Get the codec identifier associated with a format.
Definition: format.c:329
Represents a media codec within Asterisk.
Definition: codec.h:42

◆ AST_TEST_DEFINE() [5/15]

AST_TEST_DEFINE ( format_cmp_same_codec  )

Definition at line 480 of file test_core_format.c.

References ao2_cleanup, ast_codec_get(), ast_format_cmp(), AST_FORMAT_CMP_EQUAL, ast_format_create(), ast_format_create_named(), AST_MEDIA_TYPE_AUDIO, AST_TEST_FAIL, AST_TEST_NOT_RUN, AST_TEST_PASS, ast_test_status_update, first, sip_to_pjsip::info(), NULL, RAII_VAR, TEST_CATEGORY, TEST_EXECUTE, and TEST_INIT.

481 {
482  RAII_VAR(struct ast_codec *, codec, NULL, ao2_cleanup);
484  RAII_VAR(struct ast_format *, second, NULL, ao2_cleanup);
485  RAII_VAR(struct ast_format *, named, NULL, ao2_cleanup);
486 
487  switch (cmd) {
488  case TEST_INIT:
489  info->name = __PRETTY_FUNCTION__;
490  info->category = TEST_CATEGORY;
491  info->summary = "Format comparison unit test";
492  info->description =
493  "Test comparison of two different formats with same codec";
494  return AST_TEST_NOT_RUN;
495  case TEST_EXECUTE:
496  break;
497  }
498 
499  codec = ast_codec_get("ulaw", AST_MEDIA_TYPE_AUDIO, 8000);
500  if (!codec) {
501  ast_test_status_update(test, "Could not retrieve built-in ulaw codec\n");
502  return AST_TEST_FAIL;
503  }
504 
505  first = ast_format_create(codec);
506  if (!first) {
507  ast_test_status_update(test, "Could not create first format using built-in codec\n");
508  return AST_TEST_FAIL;
509  }
510 
511  second = ast_format_create(codec);
512  if (!second) {
513  ast_test_status_update(test, "Could not create second format using built-in codec\n");
514  return AST_TEST_FAIL;
515  }
516 
517  named = ast_format_create_named("super_ulaw", codec);
518  if (!named) {
519  ast_test_status_update(test, "Could not create named format using built-in codec\n");
520  return AST_TEST_FAIL;
521  }
522 
523  if (ast_format_cmp(first, second) != AST_FORMAT_CMP_EQUAL) {
524  ast_test_status_update(test, "Two formats that are the same compared as not being equal\n");
525  return AST_TEST_FAIL;
526  }
527 
528  if (ast_format_cmp(first, named) != AST_FORMAT_CMP_EQUAL) {
529  ast_test_status_update(test, "Two formats that are the same compared as not being equal\n");
530  return AST_TEST_FAIL;
531  }
532 
533  return AST_TEST_PASS;
534 }
struct ast_format * ast_format_create(struct ast_codec *codec)
Create a new media format.
Definition: format.c:196
#define TEST_CATEGORY
Definition of a media format.
Definition: format.c:43
struct ast_codec * ast_codec_get(const char *name, enum ast_media_type type, unsigned int sample_rate)
Retrieve a codec given a name, type, and sample rate.
Definition: codec.c:326
#define NULL
Definition: resample.c:96
enum ast_format_cmp_res ast_format_cmp(const struct ast_format *format1, const struct ast_format *format2)
Compare two formats.
Definition: format.c:201
#define RAII_VAR(vartype, varname, initval, dtor)
Declare a variable that will call a destructor function when it goes out of scope.
Definition: utils.h:911
#define ast_test_status_update(a, b, c...)
Definition: test.h:129
def info(msg)
struct sla_ringing_trunk * first
Definition: app_meetme.c:1092
#define ao2_cleanup(obj)
Definition: astobj2.h:1958
struct ast_format * ast_format_create_named(const char *format_name, struct ast_codec *codec)
Create a new media format with a specific name.
Definition: format.c:157
Represents a media codec within Asterisk.
Definition: codec.h:42

◆ AST_TEST_DEFINE() [6/15]

AST_TEST_DEFINE ( format_cmp_different_codec  )

Definition at line 536 of file test_core_format.c.

References ao2_cleanup, ast_codec_get(), ast_format_cmp(), AST_FORMAT_CMP_NOT_EQUAL, ast_format_create(), AST_MEDIA_TYPE_AUDIO, AST_TEST_FAIL, AST_TEST_NOT_RUN, AST_TEST_PASS, ast_test_status_update, first, sip_to_pjsip::info(), NULL, RAII_VAR, TEST_CATEGORY, TEST_EXECUTE, and TEST_INIT.

537 {
538  RAII_VAR(struct ast_codec *, first_codec, NULL, ao2_cleanup);
539  RAII_VAR(struct ast_codec *, second_codec, NULL, ao2_cleanup);
541  RAII_VAR(struct ast_format *, second, NULL, ao2_cleanup);
542 
543  switch (cmd) {
544  case TEST_INIT:
545  info->name = __PRETTY_FUNCTION__;
546  info->category = TEST_CATEGORY;
547  info->summary = "Format comparison unit test";
548  info->description =
549  "Test comparison of two different formats with different codec";
550  return AST_TEST_NOT_RUN;
551  case TEST_EXECUTE:
552  break;
553  }
554 
555  first_codec = ast_codec_get("ulaw", AST_MEDIA_TYPE_AUDIO, 8000);
556  if (!first_codec) {
557  ast_test_status_update(test, "Could not retrieve built-in ulaw codec\n");
558  return AST_TEST_FAIL;
559  }
560 
561  first = ast_format_create(first_codec);
562  if (!first) {
563  ast_test_status_update(test, "Could not create first format using built-in codec\n");
564  return AST_TEST_FAIL;
565  }
566 
567  second_codec = ast_codec_get("alaw", AST_MEDIA_TYPE_AUDIO, 8000);
568  if (!second_codec) {
569  ast_test_status_update(test, "Could not retrieve built-in alaw codec\n");
570  return AST_TEST_FAIL;
571  }
572 
573  second = ast_format_create(second_codec);
574  if (!second) {
575  ast_test_status_update(test, "Could not create second format using built-in codec\n");
576  return AST_TEST_FAIL;
577  }
578 
580  ast_test_status_update(test, "Two formats that have different codecs did not compare as being not equal\n");
581  return AST_TEST_FAIL;
582  }
583 
584  return AST_TEST_PASS;
585 }
struct ast_format * ast_format_create(struct ast_codec *codec)
Create a new media format.
Definition: format.c:196
#define TEST_CATEGORY
Definition of a media format.
Definition: format.c:43
struct ast_codec * ast_codec_get(const char *name, enum ast_media_type type, unsigned int sample_rate)
Retrieve a codec given a name, type, and sample rate.
Definition: codec.c:326
#define NULL
Definition: resample.c:96
enum ast_format_cmp_res ast_format_cmp(const struct ast_format *format1, const struct ast_format *format2)
Compare two formats.
Definition: format.c:201
#define RAII_VAR(vartype, varname, initval, dtor)
Declare a variable that will call a destructor function when it goes out of scope.
Definition: utils.h:911
#define ast_test_status_update(a, b, c...)
Definition: test.h:129
def info(msg)
struct sla_ringing_trunk * first
Definition: app_meetme.c:1092
#define ao2_cleanup(obj)
Definition: astobj2.h:1958
Represents a media codec within Asterisk.
Definition: codec.h:42

◆ AST_TEST_DEFINE() [7/15]

AST_TEST_DEFINE ( format_attr_cmp_same_codec  )

Definition at line 587 of file test_core_format.c.

References ao2_cleanup, ao2_ref, ast_codec_get(), ast_format_attribute_set(), ast_format_cmp(), AST_FORMAT_CMP_EQUAL, ast_format_create(), AST_MEDIA_TYPE_AUDIO, AST_TEST_FAIL, AST_TEST_NOT_RUN, AST_TEST_PASS, ast_test_status_update, first, callbacks_called::format_attribute_set, callbacks_called::format_cmp, sip_to_pjsip::info(), NULL, RAII_VAR, test_callbacks_called, TEST_CATEGORY, TEST_EXECUTE, and TEST_INIT.

588 {
589  RAII_VAR(struct ast_codec *, codec, NULL, ao2_cleanup);
591  RAII_VAR(struct ast_format *, second, NULL, ao2_cleanup);
592  RAII_VAR(struct ast_format *, original, NULL, ao2_cleanup);
593 
594  switch (cmd) {
595  case TEST_INIT:
596  info->name = __PRETTY_FUNCTION__;
597  info->category = TEST_CATEGORY;
598  info->summary = "Format with attributes comparison unit test";
599  info->description =
600  "Test comparison of two different formats with attributes with same codec";
601  return AST_TEST_NOT_RUN;
602  case TEST_EXECUTE:
603  break;
604  }
605 
606  codec = ast_codec_get("test_core_format_codec", AST_MEDIA_TYPE_AUDIO, 8000);
607  if (!codec) {
608  ast_test_status_update(test, "Could not retrieve test_core_format_codec codec\n");
609  return AST_TEST_FAIL;
610  }
611 
612  original = ast_format_create(codec);
613  if (!original) {
614  ast_test_status_update(test, "Could not create format using test_core_format_codec codec\n");
615  return AST_TEST_FAIL;
616  }
617 
618  first = ast_format_attribute_set(original, "one", "1");
619  if (!first) {
620  ast_test_status_update(test, "Could not create first format with attributes\n");
621  return AST_TEST_FAIL;
622  }
623 
624  second = ast_format_attribute_set(original, "two", "1");
625  if (!second) {
626  ast_test_status_update(test, "Could not create second format with attributes\n");
627  return AST_TEST_FAIL;
628  }
629 
630  if (ast_format_cmp(first, second) == AST_FORMAT_CMP_EQUAL) {
631  ast_test_status_update(test, "Formats with different attributes were compared to be equal when they should not\n");
632  return AST_TEST_FAIL;
633  }
634 
635  ao2_ref(second, -1);
636  second = ast_format_attribute_set(original, "one", "1");
637 
638  if (ast_format_cmp(first, second) != AST_FORMAT_CMP_EQUAL) {
639  ast_test_status_update(test, "Formats with the same attributes should be equal\n");
640  return AST_TEST_FAIL;
641  }
642 
643  ast_test_validate(test, test_callbacks_called.format_attribute_set == 3);
644  ast_test_validate(test, test_callbacks_called.format_cmp == 2);
645 
646  return AST_TEST_PASS;
647 }
struct ast_format * ast_format_create(struct ast_codec *codec)
Create a new media format.
Definition: format.c:196
#define TEST_CATEGORY
Definition of a media format.
Definition: format.c:43
struct ast_codec * ast_codec_get(const char *name, enum ast_media_type type, unsigned int sample_rate)
Retrieve a codec given a name, type, and sample rate.
Definition: codec.c:326
#define NULL
Definition: resample.c:96
enum ast_format_cmp_res ast_format_cmp(const struct ast_format *format1, const struct ast_format *format2)
Compare two formats.
Definition: format.c:201
#define RAII_VAR(vartype, varname, initval, dtor)
Declare a variable that will call a destructor function when it goes out of scope.
Definition: utils.h:911
#define ast_test_status_update(a, b, c...)
Definition: test.h:129
#define ao2_ref(o, delta)
Definition: astobj2.h:464
struct ast_format * ast_format_attribute_set(const struct ast_format *format, const char *name, const char *value)
Set an attribute on a format to a specific value.
Definition: format.c:248
static struct callbacks_called test_callbacks_called
A global tracking object. Cleared out by the test init cb.
def info(msg)
struct sla_ringing_trunk * first
Definition: app_meetme.c:1092
#define ao2_cleanup(obj)
Definition: astobj2.h:1958
Represents a media codec within Asterisk.
Definition: codec.h:42

◆ AST_TEST_DEFINE() [8/15]

AST_TEST_DEFINE ( format_joint_same_codec  )

Definition at line 649 of file test_core_format.c.

References ao2_cleanup, ast_codec_get(), ast_format_create(), ast_format_get_codec_id(), ast_format_joint(), AST_MEDIA_TYPE_AUDIO, AST_TEST_FAIL, AST_TEST_NOT_RUN, AST_TEST_PASS, ast_test_status_update, first, sip_to_pjsip::info(), NULL, RAII_VAR, TEST_CATEGORY, TEST_EXECUTE, and TEST_INIT.

650 {
651  RAII_VAR(struct ast_codec *, codec, NULL, ao2_cleanup);
653  RAII_VAR(struct ast_format *, second, NULL, ao2_cleanup);
654  RAII_VAR(struct ast_format *, joint, NULL, ao2_cleanup);
655 
656  switch (cmd) {
657  case TEST_INIT:
658  info->name = __PRETTY_FUNCTION__;
659  info->category = TEST_CATEGORY;
660  info->summary = "Joint format unit test";
661  info->description =
662  "Test joint format creation using two different formats with same codec";
663  return AST_TEST_NOT_RUN;
664  case TEST_EXECUTE:
665  break;
666  }
667 
668  codec = ast_codec_get("ulaw", AST_MEDIA_TYPE_AUDIO, 8000);
669  if (!codec) {
670  ast_test_status_update(test, "Could not retrieve built-in ulaw codec\n");
671  return AST_TEST_FAIL;
672  }
673 
674  first = ast_format_create(codec);
675  if (!first) {
676  ast_test_status_update(test, "Could not create first format using built-in codec\n");
677  return AST_TEST_FAIL;
678  }
679 
680  second = ast_format_create(codec);
681  if (!second) {
682  ast_test_status_update(test, "Could not create second format using built-in codec\n");
683  return AST_TEST_FAIL;
684  }
685 
686  joint = ast_format_joint(first, second);
687  if (!joint) {
688  ast_test_status_update(test, "Failed to create a joint format using two formats of same codec\n");
689  return AST_TEST_FAIL;
690  } else if (ast_format_get_codec_id(joint) != codec->id) {
691  ast_test_status_update(test, "Returned joint format does not contain expected codec\n");
692  return AST_TEST_FAIL;
693  }
694 
695  return AST_TEST_PASS;
696 }
struct ast_format * ast_format_create(struct ast_codec *codec)
Create a new media format.
Definition: format.c:196
#define TEST_CATEGORY
Definition of a media format.
Definition: format.c:43
struct ast_codec * ast_codec_get(const char *name, enum ast_media_type type, unsigned int sample_rate)
Retrieve a codec given a name, type, and sample rate.
Definition: codec.c:326
#define NULL
Definition: resample.c:96
struct ast_format * ast_format_joint(const struct ast_format *format1, const struct ast_format *format2)
Get a common joint capability between two formats.
Definition: format.c:226
#define RAII_VAR(vartype, varname, initval, dtor)
Declare a variable that will call a destructor function when it goes out of scope.
Definition: utils.h:911
#define ast_test_status_update(a, b, c...)
Definition: test.h:129
def info(msg)
struct sla_ringing_trunk * first
Definition: app_meetme.c:1092
#define ao2_cleanup(obj)
Definition: astobj2.h:1958
unsigned int ast_format_get_codec_id(const struct ast_format *format)
Get the codec identifier associated with a format.
Definition: format.c:329
Represents a media codec within Asterisk.
Definition: codec.h:42

◆ AST_TEST_DEFINE() [9/15]

AST_TEST_DEFINE ( format_attr_joint_same_codec  )

Definition at line 698 of file test_core_format.c.

References ao2_cleanup, ast_codec_get(), ast_format_attribute_set(), ast_format_create(), ast_format_generate_sdp_fmtp(), ast_format_get_codec_id(), ast_format_joint(), AST_MEDIA_TYPE_AUDIO, ast_str_alloca, ast_str_buffer(), AST_TEST_FAIL, AST_TEST_NOT_RUN, AST_TEST_PASS, ast_test_status_update, first, callbacks_called::format_attribute_set, callbacks_called::format_generate_sdp_fmtp, callbacks_called::format_get_joint, sip_to_pjsip::info(), NULL, RAII_VAR, test_callbacks_called, TEST_CATEGORY, TEST_EXECUTE, and TEST_INIT.

699 {
700  RAII_VAR(struct ast_codec *, codec, NULL, ao2_cleanup);
701  RAII_VAR(struct ast_format *, original, NULL, ao2_cleanup);
703  RAII_VAR(struct ast_format *, second, NULL, ao2_cleanup);
704  RAII_VAR(struct ast_format *, joint, NULL, ao2_cleanup);
705  struct ast_str *fmtp = ast_str_alloca(64);
706 
707  switch (cmd) {
708  case TEST_INIT:
709  info->name = __PRETTY_FUNCTION__;
710  info->category = TEST_CATEGORY;
711  info->summary = "Joint format attribute unit test";
712  info->description =
713  "Test joint format creation using two different formats with attributes and with same codec";
714  return AST_TEST_NOT_RUN;
715  case TEST_EXECUTE:
716  break;
717  }
718 
719  codec = ast_codec_get("test_core_format_codec", AST_MEDIA_TYPE_AUDIO, 8000);
720  if (!codec) {
721  ast_test_status_update(test, "Could not retrieve test_core_format_codec codec\n");
722  return AST_TEST_FAIL;
723  }
724 
725  original = ast_format_create(codec);
726  if (!original) {
727  ast_test_status_update(test, "Could not create format from test_core_format_codec codec\n");
728  return AST_TEST_FAIL;
729  }
730 
731  first = ast_format_attribute_set(original, "one", "2");
732  if (!first) {
733  ast_test_status_update(test, "Could not create first format using test_core_format_codec codec\n");
734  return AST_TEST_FAIL;
735  }
736 
737  second = ast_format_attribute_set(original, "one", "5");
738  if (!second) {
739  ast_test_status_update(test, "Could not create second format using test_core_format_codec codec\n");
740  return AST_TEST_FAIL;
741  }
742 
743  joint = ast_format_joint(first, second);
744  if (!joint) {
745  ast_test_status_update(test, "Failed to create a joint format using two formats of same codec\n");
746  return AST_TEST_FAIL;
747  } else if (ast_format_get_codec_id(joint) != codec->id) {
748  ast_test_status_update(test, "Returned joint format does not contain expected codec\n");
749  return AST_TEST_FAIL;
750  }
751 
752  ast_format_generate_sdp_fmtp(joint, 100, &fmtp);
753  ast_test_validate(test, strcmp("a=fmtp:100 one=5;two=0\r\n", ast_str_buffer(fmtp)) == 0);
754 
755  ast_test_validate(test, test_callbacks_called.format_attribute_set == 2);
756  ast_test_validate(test, test_callbacks_called.format_get_joint == 1);
757  ast_test_validate(test, test_callbacks_called.format_generate_sdp_fmtp == 1);
758 
759  return AST_TEST_PASS;
760 }
struct ast_format * ast_format_create(struct ast_codec *codec)
Create a new media format.
Definition: format.c:196
char * ast_str_buffer(const struct ast_str *buf)
Returns the string buffer within the ast_str buf.
Definition: strings.h:714
#define TEST_CATEGORY
Definition of a media format.
Definition: format.c:43
#define ast_str_alloca(init_len)
Definition: strings.h:800
struct ast_codec * ast_codec_get(const char *name, enum ast_media_type type, unsigned int sample_rate)
Retrieve a codec given a name, type, and sample rate.
Definition: codec.c:326
#define NULL
Definition: resample.c:96
struct ast_format * ast_format_joint(const struct ast_format *format1, const struct ast_format *format2)
Get a common joint capability between two formats.
Definition: format.c:226
#define RAII_VAR(vartype, varname, initval, dtor)
Declare a variable that will call a destructor function when it goes out of scope.
Definition: utils.h:911
#define ast_test_status_update(a, b, c...)
Definition: test.h:129
struct ast_format * ast_format_attribute_set(const struct ast_format *format, const char *name, const char *value)
Set an attribute on a format to a specific value.
Definition: format.c:248
static struct callbacks_called test_callbacks_called
A global tracking object. Cleared out by the test init cb.
The descriptor of a dynamic string XXX storage will be optimized later if needed We use the ts field ...
Definition: strings.h:584
def info(msg)
struct sla_ringing_trunk * first
Definition: app_meetme.c:1092
#define ao2_cleanup(obj)
Definition: astobj2.h:1958
void ast_format_generate_sdp_fmtp(const struct ast_format *format, unsigned int payload, struct ast_str **str)
This function is used to produce an fmtp SDP line for an Asterisk format. The attributes present on t...
Definition: format.c:305
unsigned int ast_format_get_codec_id(const struct ast_format *format)
Get the codec identifier associated with a format.
Definition: format.c:329
Represents a media codec within Asterisk.
Definition: codec.h:42

◆ AST_TEST_DEFINE() [10/15]

AST_TEST_DEFINE ( format_joint_different_codec  )

Definition at line 762 of file test_core_format.c.

References ao2_cleanup, ast_codec_get(), ast_format_create(), ast_format_joint(), AST_MEDIA_TYPE_AUDIO, AST_TEST_FAIL, AST_TEST_NOT_RUN, AST_TEST_PASS, ast_test_status_update, first, sip_to_pjsip::info(), NULL, RAII_VAR, TEST_CATEGORY, TEST_EXECUTE, and TEST_INIT.

763 {
764  RAII_VAR(struct ast_codec *, first_codec, NULL, ao2_cleanup);
765  RAII_VAR(struct ast_codec *, second_codec, NULL, ao2_cleanup);
767  RAII_VAR(struct ast_format *, second, NULL, ao2_cleanup);
768  RAII_VAR(struct ast_format *, joint, NULL, ao2_cleanup);
769 
770  switch (cmd) {
771  case TEST_INIT:
772  info->name = __PRETTY_FUNCTION__;
773  info->category = TEST_CATEGORY;
774  info->summary = "Joint format unit test";
775  info->description =
776  "Test that there is no joint format between two different formats with different codec";
777  return AST_TEST_NOT_RUN;
778  case TEST_EXECUTE:
779  break;
780  }
781 
782  first_codec = ast_codec_get("ulaw", AST_MEDIA_TYPE_AUDIO, 8000);
783  if (!first_codec) {
784  ast_test_status_update(test, "Could not retrieve built-in ulaw codec\n");
785  return AST_TEST_FAIL;
786  }
787 
788  first = ast_format_create(first_codec);
789  if (!first) {
790  ast_test_status_update(test, "Could not create first format using built-in codec\n");
791  return AST_TEST_FAIL;
792  }
793 
794  second_codec = ast_codec_get("alaw", AST_MEDIA_TYPE_AUDIO, 8000);
795  if (!second_codec) {
796  ast_test_status_update(test, "Could not retrieve built-in alaw codec\n");
797  return AST_TEST_FAIL;
798  }
799 
800  second = ast_format_create(second_codec);
801  if (!second) {
802  ast_test_status_update(test, "Could not create second format using built-in codec\n");
803  return AST_TEST_FAIL;
804  }
805 
806  joint = ast_format_joint(first, second);
807  if (joint) {
808  ast_test_status_update(test, "Got a joint format between two formats with different codecs\n");
809  return AST_TEST_FAIL;
810  }
811 
812  return AST_TEST_PASS;
813 }
struct ast_format * ast_format_create(struct ast_codec *codec)
Create a new media format.
Definition: format.c:196
#define TEST_CATEGORY
Definition of a media format.
Definition: format.c:43
struct ast_codec * ast_codec_get(const char *name, enum ast_media_type type, unsigned int sample_rate)
Retrieve a codec given a name, type, and sample rate.
Definition: codec.c:326
#define NULL
Definition: resample.c:96
struct ast_format * ast_format_joint(const struct ast_format *format1, const struct ast_format *format2)
Get a common joint capability between two formats.
Definition: format.c:226
#define RAII_VAR(vartype, varname, initval, dtor)
Declare a variable that will call a destructor function when it goes out of scope.
Definition: utils.h:911
#define ast_test_status_update(a, b, c...)
Definition: test.h:129
def info(msg)
struct sla_ringing_trunk * first
Definition: app_meetme.c:1092
#define ao2_cleanup(obj)
Definition: astobj2.h:1958
Represents a media codec within Asterisk.
Definition: codec.h:42

◆ AST_TEST_DEFINE() [11/15]

AST_TEST_DEFINE ( format_copy  )

Definition at line 815 of file test_core_format.c.

References ao2_bump, ao2_cleanup, ast_codec_get(), ast_format_create(), AST_MEDIA_TYPE_AUDIO, AST_TEST_FAIL, AST_TEST_NOT_RUN, AST_TEST_PASS, ast_test_status_update, copy(), format, sip_to_pjsip::info(), NULL, RAII_VAR, TEST_CATEGORY, TEST_EXECUTE, and TEST_INIT.

816 {
817  RAII_VAR(struct ast_codec *, codec, NULL, ao2_cleanup);
819  RAII_VAR(struct ast_format *, copy, NULL, ao2_cleanup);
820 
821  switch (cmd) {
822  case TEST_INIT:
823  info->name = __PRETTY_FUNCTION__;
824  info->category = TEST_CATEGORY;
825  info->summary = "Format copying unit test";
826  info->description =
827  "Test copying of a format";
828  return AST_TEST_NOT_RUN;
829  case TEST_EXECUTE:
830  break;
831  }
832 
833  codec = ast_codec_get("ulaw", AST_MEDIA_TYPE_AUDIO, 8000);
834  if (!codec) {
835  ast_test_status_update(test, "Could not retrieve built-in ulaw codec\n");
836  return AST_TEST_FAIL;
837  }
838 
839  format = ast_format_create(codec);
840  if (!format) {
841  ast_test_status_update(test, "Could not create format using built-in codec\n");
842  return AST_TEST_FAIL;
843  }
844 
845  copy = ao2_bump(format);
846  if (!copy) {
847  ast_test_status_update(test, "Copying of a just created format failed\n");
848  return AST_TEST_FAIL;
849  } else if (copy != format) {
850  ast_test_status_update(test, "Copying of a format returned a new format instead of the same one\n");
851  return AST_TEST_FAIL;
852  }
853 
854  return AST_TEST_PASS;
855 }
struct ast_format * ast_format_create(struct ast_codec *codec)
Create a new media format.
Definition: format.c:196
#define TEST_CATEGORY
Definition of a media format.
Definition: format.c:43
static int copy(char *infile, char *outfile)
Utility function to copy a file.
struct ast_codec * ast_codec_get(const char *name, enum ast_media_type type, unsigned int sample_rate)
Retrieve a codec given a name, type, and sample rate.
Definition: codec.c:326
#define NULL
Definition: resample.c:96
#define ao2_bump(obj)
Definition: astobj2.h:491
#define RAII_VAR(vartype, varname, initval, dtor)
Declare a variable that will call a destructor function when it goes out of scope.
Definition: utils.h:911
#define ast_test_status_update(a, b, c...)
Definition: test.h:129
def info(msg)
#define ao2_cleanup(obj)
Definition: astobj2.h:1958
static snd_pcm_format_t format
Definition: chan_alsa.c:102
Represents a media codec within Asterisk.
Definition: codec.h:42

◆ AST_TEST_DEFINE() [12/15]

AST_TEST_DEFINE ( format_attribute_set_without_interface  )

Definition at line 857 of file test_core_format.c.

References ao2_cleanup, ast_codec_get(), ast_format_attribute_set(), ast_format_create(), AST_MEDIA_TYPE_AUDIO, AST_TEST_FAIL, AST_TEST_NOT_RUN, AST_TEST_PASS, ast_test_status_update, ast_format::codec, format, sip_to_pjsip::info(), NULL, RAII_VAR, TEST_CATEGORY, TEST_EXECUTE, and TEST_INIT.

858 {
859  RAII_VAR(struct ast_codec *, codec, NULL, ao2_cleanup);
861  struct ast_format *attr_set;
862 
863  switch (cmd) {
864  case TEST_INIT:
865  info->name = __PRETTY_FUNCTION__;
866  info->category = TEST_CATEGORY;
867  info->summary = "Format attribute setting unit test";
868  info->description =
869  "Test that attribute setting on a format without an interface fails";
870  return AST_TEST_NOT_RUN;
871  case TEST_EXECUTE:
872  break;
873  }
874 
875  codec = ast_codec_get("ulaw", AST_MEDIA_TYPE_AUDIO, 8000);
876  if (!codec) {
877  ast_test_status_update(test, "Could not retrieve built-in ulaw codec\n");
878  return AST_TEST_FAIL;
879  }
880 
882  if (!format) {
883  ast_test_status_update(test, "Could not create format using built-in codec\n");
884  return AST_TEST_FAIL;
885  }
886 
887  attr_set = ast_format_attribute_set(format, "bees", "cool");
888  if (!attr_set) {
889  ast_test_status_update(test, "Successfully set an attribute on a format without an interface\n");
890  return AST_TEST_FAIL;
891  }
892  ao2_cleanup(attr_set);
893 
894  return AST_TEST_PASS;
895 }
struct ast_format * ast_format_create(struct ast_codec *codec)
Create a new media format.
Definition: format.c:196
#define TEST_CATEGORY
Definition of a media format.
Definition: format.c:43
struct ast_codec * ast_codec_get(const char *name, enum ast_media_type type, unsigned int sample_rate)
Retrieve a codec given a name, type, and sample rate.
Definition: codec.c:326
#define NULL
Definition: resample.c:96
#define RAII_VAR(vartype, varname, initval, dtor)
Declare a variable that will call a destructor function when it goes out of scope.
Definition: utils.h:911
#define ast_test_status_update(a, b, c...)
Definition: test.h:129
struct ast_format * ast_format_attribute_set(const struct ast_format *format, const char *name, const char *value)
Set an attribute on a format to a specific value.
Definition: format.c:248
def info(msg)
struct ast_codec * codec
Pointer to the codec in use for this format.
Definition: format.c:47
#define ao2_cleanup(obj)
Definition: astobj2.h:1958
static snd_pcm_format_t format
Definition: chan_alsa.c:102
Represents a media codec within Asterisk.
Definition: codec.h:42

◆ AST_TEST_DEFINE() [13/15]

AST_TEST_DEFINE ( format_attribute_get_without_interface  )

Definition at line 897 of file test_core_format.c.

References ao2_cleanup, ast_codec_get(), ast_format_attribute_get(), ast_format_create(), AST_MEDIA_TYPE_AUDIO, AST_TEST_FAIL, AST_TEST_NOT_RUN, AST_TEST_PASS, ast_test_status_update, ast_format::codec, format, sip_to_pjsip::info(), NULL, RAII_VAR, TEST_CATEGORY, TEST_EXECUTE, and TEST_INIT.

898 {
899  RAII_VAR(struct ast_codec *, codec, NULL, ao2_cleanup);
901 
902  switch (cmd) {
903  case TEST_INIT:
904  info->name = __PRETTY_FUNCTION__;
905  info->category = TEST_CATEGORY;
906  info->summary = "Format attribute retrieval unit test";
907  info->description =
908  "Test that attribute retrieval on a format without an interface fails";
909  return AST_TEST_NOT_RUN;
910  case TEST_EXECUTE:
911  break;
912  }
913 
914  codec = ast_codec_get("ulaw", AST_MEDIA_TYPE_AUDIO, 8000);
915  if (!codec) {
916  ast_test_status_update(test, "Could not retrieve built-in ulaw codec\n");
917  return AST_TEST_FAIL;
918  }
919 
921  if (!format) {
922  ast_test_status_update(test, "Could not create format using built-in codec\n");
923  return AST_TEST_FAIL;
924  }
925 
926  if (ast_format_attribute_get(format, "bees") != NULL) {
927  ast_test_status_update(test, "Successfully retrieved an attribute on a format without an interface\n");
928  return AST_TEST_FAIL;
929  }
930 
931  return AST_TEST_PASS;
932 }
struct ast_format * ast_format_create(struct ast_codec *codec)
Create a new media format.
Definition: format.c:196
#define TEST_CATEGORY
Definition of a media format.
Definition: format.c:43
struct ast_codec * ast_codec_get(const char *name, enum ast_media_type type, unsigned int sample_rate)
Retrieve a codec given a name, type, and sample rate.
Definition: codec.c:326
#define NULL
Definition: resample.c:96
#define RAII_VAR(vartype, varname, initval, dtor)
Declare a variable that will call a destructor function when it goes out of scope.
Definition: utils.h:911
#define ast_test_status_update(a, b, c...)
Definition: test.h:129
def info(msg)
struct ast_codec * codec
Pointer to the codec in use for this format.
Definition: format.c:47
#define ao2_cleanup(obj)
Definition: astobj2.h:1958
const void * ast_format_attribute_get(const struct ast_format *format, const char *name)
Definition: format.c:267
static snd_pcm_format_t format
Definition: chan_alsa.c:102
Represents a media codec within Asterisk.
Definition: codec.h:42

◆ AST_TEST_DEFINE() [14/15]

AST_TEST_DEFINE ( format_parse_sdp_fmtp_without_interface  )

Definition at line 934 of file test_core_format.c.

References ao2_cleanup, ast_codec_get(), ast_format_create(), ast_format_parse_sdp_fmtp(), AST_MEDIA_TYPE_AUDIO, AST_TEST_FAIL, AST_TEST_NOT_RUN, AST_TEST_PASS, ast_test_status_update, ast_format::codec, format, sip_to_pjsip::info(), NULL, RAII_VAR, TEST_CATEGORY, TEST_EXECUTE, and TEST_INIT.

935 {
936  RAII_VAR(struct ast_codec *, codec, NULL, ao2_cleanup);
938  RAII_VAR(struct ast_format *, generated, NULL, ao2_cleanup);
939 
940  switch (cmd) {
941  case TEST_INIT:
942  info->name = __PRETTY_FUNCTION__;
943  info->category = TEST_CATEGORY;
944  info->summary = "Format sdp parse unit test";
945  info->description =
946  "Test that sdp parsing on a format without an interface fails";
947  return AST_TEST_NOT_RUN;
948  case TEST_EXECUTE:
949  break;
950  }
951 
952  codec = ast_codec_get("ulaw", AST_MEDIA_TYPE_AUDIO, 8000);
953  if (!codec) {
954  ast_test_status_update(test, "Could not retrieve built-in ulaw codec\n");
955  return AST_TEST_FAIL;
956  }
957 
959  if (!format) {
960  ast_test_status_update(test, "Could not create format using built-in codec\n");
961  return AST_TEST_FAIL;
962  }
963 
964  generated = ast_format_parse_sdp_fmtp(format, "tacos");
965  if (generated != format) {
966  ast_test_status_update(test, "Successfully parsed SDP on a format without an interface\n");
967  return AST_TEST_FAIL;
968  }
969 
970  return AST_TEST_PASS;
971 }
struct ast_format * ast_format_create(struct ast_codec *codec)
Create a new media format.
Definition: format.c:196
#define TEST_CATEGORY
Definition of a media format.
Definition: format.c:43
struct ast_codec * ast_codec_get(const char *name, enum ast_media_type type, unsigned int sample_rate)
Retrieve a codec given a name, type, and sample rate.
Definition: codec.c:326
#define NULL
Definition: resample.c:96
#define RAII_VAR(vartype, varname, initval, dtor)
Declare a variable that will call a destructor function when it goes out of scope.
Definition: utils.h:911
#define ast_test_status_update(a, b, c...)
Definition: test.h:129
def info(msg)
struct ast_codec * codec
Pointer to the codec in use for this format.
Definition: format.c:47
#define ao2_cleanup(obj)
Definition: astobj2.h:1958
struct ast_format * ast_format_parse_sdp_fmtp(const struct ast_format *format, const char *attributes)
This function is used to have a media format aware module parse and interpret SDP attribute informati...
Definition: format.c:286
static snd_pcm_format_t format
Definition: chan_alsa.c:102
Represents a media codec within Asterisk.
Definition: codec.h:42

◆ AST_TEST_DEFINE() [15/15]

AST_TEST_DEFINE ( format_parse_and_generate_sdp_fmtp  )

Definition at line 973 of file test_core_format.c.

References ao2_cleanup, ast_codec_get(), ast_format_create(), ast_format_generate_sdp_fmtp(), ast_format_parse_sdp_fmtp(), AST_MEDIA_TYPE_AUDIO, ast_str_alloca, ast_str_buffer(), AST_TEST_FAIL, AST_TEST_NOT_RUN, AST_TEST_PASS, ast_test_status_update, ast_format::codec, format, callbacks_called::format_generate_sdp_fmtp, callbacks_called::format_parse_sdp_fmtp, sip_to_pjsip::info(), NULL, RAII_VAR, test_callbacks_called, TEST_CATEGORY, TEST_EXECUTE, and TEST_INIT.

974 {
975  RAII_VAR(struct ast_codec *, codec, NULL, ao2_cleanup);
977  RAII_VAR(struct ast_format *, generated, NULL, ao2_cleanup);
978  struct ast_str *fmtp = ast_str_alloca(64);
979 
980  switch (cmd) {
981  case TEST_INIT:
982  info->name = __PRETTY_FUNCTION__;
983  info->category = TEST_CATEGORY;
984  info->summary = "Format sdp parse/generate unit test";
985  info->description =
986  "Test that sdp parsing and generation on a format with an interface succeeds";
987  return AST_TEST_NOT_RUN;
988  case TEST_EXECUTE:
989  break;
990  }
991 
992  codec = ast_codec_get("test_core_format_codec", AST_MEDIA_TYPE_AUDIO, 8000);
993  if (!codec) {
994  ast_test_status_update(test, "Could not retrieve test_core_format_codec codec\n");
995  return AST_TEST_FAIL;
996  }
997 
998  format = ast_format_create(codec);
999  if (!format) {
1000  ast_test_status_update(test, "Could not create format using test_core_format_codec codec\n");
1001  return AST_TEST_FAIL;
1002  }
1003 
1004  generated = ast_format_parse_sdp_fmtp(format, "one=1000;two=256");
1005  if (format == generated) {
1006  ast_test_status_update(test, "Failed to parse SDP on a format without an interface\n");
1007  return AST_TEST_FAIL;
1008  }
1009 
1010  ast_format_generate_sdp_fmtp(generated, 8, &fmtp);
1011 
1012  ast_test_validate(test, strcmp("a=fmtp:8 one=1000;two=256\r\n", ast_str_buffer(fmtp)) == 0);
1013  ast_test_validate(test, test_callbacks_called.format_parse_sdp_fmtp == 1);
1014  ast_test_validate(test, test_callbacks_called.format_generate_sdp_fmtp == 1);
1015 
1016  return AST_TEST_PASS;
1017 }
struct ast_format * ast_format_create(struct ast_codec *codec)
Create a new media format.
Definition: format.c:196
char * ast_str_buffer(const struct ast_str *buf)
Returns the string buffer within the ast_str buf.
Definition: strings.h:714
#define TEST_CATEGORY
Definition of a media format.
Definition: format.c:43
#define ast_str_alloca(init_len)
Definition: strings.h:800
struct ast_codec * ast_codec_get(const char *name, enum ast_media_type type, unsigned int sample_rate)
Retrieve a codec given a name, type, and sample rate.
Definition: codec.c:326
#define NULL
Definition: resample.c:96
#define RAII_VAR(vartype, varname, initval, dtor)
Declare a variable that will call a destructor function when it goes out of scope.
Definition: utils.h:911
#define ast_test_status_update(a, b, c...)
Definition: test.h:129
static struct callbacks_called test_callbacks_called
A global tracking object. Cleared out by the test init cb.
The descriptor of a dynamic string XXX storage will be optimized later if needed We use the ts field ...
Definition: strings.h:584
def info(msg)
struct ast_codec * codec
Pointer to the codec in use for this format.
Definition: format.c:47
#define ao2_cleanup(obj)
Definition: astobj2.h:1958
struct ast_format * ast_format_parse_sdp_fmtp(const struct ast_format *format, const char *attributes)
This function is used to have a media format aware module parse and interpret SDP attribute informati...
Definition: format.c:286
void ast_format_generate_sdp_fmtp(const struct ast_format *format, unsigned int payload, struct ast_str **str)
This function is used to produce an fmtp SDP line for an Asterisk format. The attributes present on t...
Definition: format.c:305
static snd_pcm_format_t format
Definition: chan_alsa.c:102
Represents a media codec within Asterisk.
Definition: codec.h:42

◆ load_module()

static int load_module ( void  )
static

Definition at line 1047 of file test_core_format.c.

References ast_codec_register, ast_format_interface_register, ast_log, AST_LOG_ERROR, AST_MODULE_LOAD_DECLINE, AST_MODULE_LOAD_SUCCESS, AST_TEST_REGISTER, ast_test_register_init(), TEST_CATEGORY, and test_core_format_init().

1048 {
1049  /* Test codec/format interface used by this module */
1051  ast_log(AST_LOG_ERROR, "Failed to register test_core_format_codec\n");
1052  return AST_MODULE_LOAD_DECLINE;
1053  }
1054 
1055  if (ast_format_interface_register("test_core_format_codec", &test_core_format_attr)) {
1056  ast_log(AST_LOG_ERROR, "Failed to register format interface for test_core_format_codec\n");
1057  return AST_MODULE_LOAD_DECLINE;
1058  }
1059 
1060  AST_TEST_REGISTER(format_create);
1061  AST_TEST_REGISTER(format_create_attr);
1062  AST_TEST_REGISTER(format_retrieve_attr);
1063  AST_TEST_REGISTER(format_clone);
1064  AST_TEST_REGISTER(format_cmp_same_codec);
1065  AST_TEST_REGISTER(format_attr_cmp_same_codec);
1066  AST_TEST_REGISTER(format_cmp_different_codec);
1067  AST_TEST_REGISTER(format_joint_same_codec);
1068  AST_TEST_REGISTER(format_attr_joint_same_codec);
1069  AST_TEST_REGISTER(format_joint_different_codec);
1070  AST_TEST_REGISTER(format_copy);
1071  AST_TEST_REGISTER(format_attribute_set_without_interface);
1072  AST_TEST_REGISTER(format_attribute_get_without_interface);
1073  AST_TEST_REGISTER(format_parse_sdp_fmtp_without_interface);
1074  AST_TEST_REGISTER(format_parse_and_generate_sdp_fmtp);
1075 
1077 
1078  return AST_MODULE_LOAD_SUCCESS;
1079 }
int ast_test_register_init(const char *category, ast_test_init_cb_t *cb)
Definition: test.c:160
static struct ast_codec test_core_format_codec
A test codec for these unit tests. Should be used with test_core_format.
#define TEST_CATEGORY
#define AST_TEST_REGISTER(cb)
Definition: test.h:127
static struct ast_format_interface test_core_format_attr
A format attribute 'module' used by the unit tests.
#define ast_log
Definition: astobj2.c:42
#define AST_LOG_ERROR
Definition: logger.h:290
#define ast_codec_register(codec)
This function is used to register a codec with the Asterisk core. Registering allows it to be passed ...
Definition: codec.h:122
#define ast_format_interface_register(codec, interface)
Register a format interface for use with the provided codec.
Definition: format.h:273
Module has failed to load, may be in an inconsistent state.
Definition: module.h:78
static int test_core_format_init(struct ast_test_info *info, struct ast_test *test)

◆ test_core_format_attribute_get()

static const void * test_core_format_attribute_get ( const struct ast_format format,
const char *  name 
)
static

Format attribute callback for retrieving an attribute.

Definition at line 206 of file test_core_format.c.

References ast_format_get_attribute_data(), test_core_format_pvt::field_one, test_core_format_pvt::field_two, and NULL.

207 {
209 
210  if (!strcmp(name, "one")) {
211  return &pvt->field_one;
212  } else if (!strcmp(name, "two")) {
213  return &pvt->field_two;
214  }
215  return NULL;
216 }
void * ast_format_get_attribute_data(const struct ast_format *format)
Get the attribute data on a format.
Definition: format.c:125
#define NULL
Definition: resample.c:96
A test piece of data to associate with test_core_format_attr.
static const char name[]
Definition: cdr_mysql.c:74

◆ test_core_format_attribute_set()

static struct ast_format * test_core_format_attribute_set ( const struct ast_format format,
const char *  name,
const char *  value 
)
static

Format attribute callback for setting an attribute on a format.

Definition at line 185 of file test_core_format.c.

References ast_format_clone(), ast_format_get_attribute_data(), test_core_format_pvt::field_one, test_core_format_pvt::field_two, callbacks_called::format_attribute_set, NULL, and test_callbacks_called.

186 {
187  struct ast_format *clone = ast_format_clone(format);
188  struct test_core_format_pvt *clone_pvt;
189 
190  if (!clone) {
191  return NULL;
192  }
193  clone_pvt = ast_format_get_attribute_data(clone);
194 
195  if (!strcmp(name, "one")) {
196  clone_pvt->field_one = atoi(value);
197  } else if (!strcmp(name, "two")) {
198  clone_pvt->field_two = atoi(value);
199  }
201 
202  return clone;
203 }
Definition of a media format.
Definition: format.c:43
void * ast_format_get_attribute_data(const struct ast_format *format)
Get the attribute data on a format.
Definition: format.c:125
#define NULL
Definition: resample.c:96
int value
Definition: syslog.c:37
struct ast_format * ast_format_clone(const struct ast_format *format)
Clone an existing media format so it can be modified.
Definition: format.c:180
static struct callbacks_called test_callbacks_called
A global tracking object. Cleared out by the test init cb.
A test piece of data to associate with test_core_format_attr.
static const char name[]
Definition: cdr_mysql.c:74

◆ test_core_format_clone()

static int test_core_format_clone ( const struct ast_format src,
struct ast_format dst 
)
static

Format attribute callback called during format cloning.

Definition at line 112 of file test_core_format.c.

References ast_calloc, ast_format_get_attribute_data(), ast_format_set_attribute_data(), callbacks_called::format_clone, and test_callbacks_called.

113 {
115  struct test_core_format_pvt *new_pvt;
116 
117  new_pvt = ast_calloc(1, sizeof(*new_pvt));
118  if (!new_pvt) {
119  return -1;
120  }
121 
122  if (pvt) {
123  *new_pvt = *pvt;
124  }
125  ast_format_set_attribute_data(dst, new_pvt);
126 
128 
129  return 0;
130 }
void * ast_format_get_attribute_data(const struct ast_format *format)
Get the attribute data on a format.
Definition: format.c:125
static struct callbacks_called test_callbacks_called
A global tracking object. Cleared out by the test init cb.
A test piece of data to associate with test_core_format_attr.
#define ast_calloc(num, len)
A wrapper for calloc()
Definition: astmm.h:204
void ast_format_set_attribute_data(struct ast_format *format, void *attribute_data)
Set the attribute data on a format.
Definition: format.c:130

◆ test_core_format_cmp()

static enum ast_format_cmp_res test_core_format_cmp ( const struct ast_format format1,
const struct ast_format format2 
)
static

Format attribute callback called during format comparison.

Definition at line 133 of file test_core_format.c.

References AST_FORMAT_CMP_EQUAL, AST_FORMAT_CMP_NOT_EQUAL, ast_format_get_attribute_data(), test_core_format_pvt::field_one, test_core_format_pvt::field_two, callbacks_called::format_cmp, and test_callbacks_called.

134 {
135  struct test_core_format_pvt *pvt1 = ast_format_get_attribute_data(format1);
136  struct test_core_format_pvt *pvt2 = ast_format_get_attribute_data(format2);
137 
139  if (pvt1 == pvt2) {
140  return AST_FORMAT_CMP_EQUAL;
141  }
142 
143  if ((!pvt1 && pvt2 && (pvt2->field_one != 0 || pvt2->field_two != 0))
144  || (pvt1 && !pvt2 && (pvt1->field_one != 0 || pvt1->field_two != 0))) {
146  }
147 
148  if (pvt1 && pvt2) {
149  if (!memcmp(pvt1, pvt2, sizeof(*pvt1))) {
150  return AST_FORMAT_CMP_EQUAL;
151  } else {
153  }
154  }
155 
156  return AST_FORMAT_CMP_EQUAL;
157 }
void * ast_format_get_attribute_data(const struct ast_format *format)
Get the attribute data on a format.
Definition: format.c:125
static struct callbacks_called test_callbacks_called
A global tracking object. Cleared out by the test init cb.
A test piece of data to associate with test_core_format_attr.

◆ test_core_format_destroy()

static void test_core_format_destroy ( struct ast_format format)
static

Format attribute callback for when format attributes are to be destroyed.

Definition at line 103 of file test_core_format.c.

References ast_format_get_attribute_data(), ast_free, callbacks_called::format_destroy, and test_callbacks_called.

104 {
106 
107  ast_free(pvt);
109 }
void * ast_format_get_attribute_data(const struct ast_format *format)
Get the attribute data on a format.
Definition: format.c:125
static struct callbacks_called test_callbacks_called
A global tracking object. Cleared out by the test init cb.
A test piece of data to associate with test_core_format_attr.
#define ast_free(a)
Definition: astmm.h:182

◆ test_core_format_generate_sdp_fmtp()

static void test_core_format_generate_sdp_fmtp ( const struct ast_format format,
unsigned int  payload,
struct ast_str **  str 
)
static

Format attribute callback to generate an SDP fmtp line from a format.

Definition at line 240 of file test_core_format.c.

References ast_format_get_attribute_data(), ast_str_append(), test_core_format_pvt::field_one, test_core_format_pvt::field_two, callbacks_called::format_generate_sdp_fmtp, and test_callbacks_called.

241 {
243 
244  if (!pvt) {
245  return;
246  }
247 
248  ast_str_append(str, 0, "a=fmtp:%u one=%d;two=%d\r\n", payload, pvt->field_one, pvt->field_two);
249 
251 }
int ast_str_append(struct ast_str **buf, ssize_t max_len, const char *fmt,...)
Append to a thread local dynamic string.
Definition: strings.h:1091
void * ast_format_get_attribute_data(const struct ast_format *format)
Get the attribute data on a format.
Definition: format.c:125
static struct callbacks_called test_callbacks_called
A global tracking object. Cleared out by the test init cb.
A test piece of data to associate with test_core_format_attr.

◆ test_core_format_get_joint()

static struct ast_format * test_core_format_get_joint ( const struct ast_format format1,
const struct ast_format format2 
)
static

Format attribute callback called during joint format capability.

Note
Our test will assume the max of attributes field_one and field_two

Definition at line 163 of file test_core_format.c.

References ast_format_clone(), ast_format_get_attribute_data(), test_core_format_pvt::field_one, test_core_format_pvt::field_two, callbacks_called::format_get_joint, MAX, NULL, and test_callbacks_called.

164 {
165  struct test_core_format_pvt *pvt1 = ast_format_get_attribute_data(format1);
166  struct test_core_format_pvt *pvt2 = ast_format_get_attribute_data(format2);
167  struct ast_format *joint;
168  struct test_core_format_pvt *joint_pvt;
169 
170  joint = ast_format_clone(format1);
171  if (!joint) {
172  return NULL;
173  }
174  joint_pvt = ast_format_get_attribute_data(joint);
175 
176  joint_pvt->field_one = MAX(pvt1 ? pvt1->field_one : 0, pvt2 ? pvt2->field_one : 0);
177  joint_pvt->field_two = MAX(pvt2 ? pvt2->field_two : 0, pvt2 ? pvt2->field_two : 0);
178 
180 
181  return joint;
182 }
Definition of a media format.
Definition: format.c:43
void * ast_format_get_attribute_data(const struct ast_format *format)
Get the attribute data on a format.
Definition: format.c:125
#define NULL
Definition: resample.c:96
struct ast_format * ast_format_clone(const struct ast_format *format)
Clone an existing media format so it can be modified.
Definition: format.c:180
#define MAX(a, b)
Definition: utils.h:228
static struct callbacks_called test_callbacks_called
A global tracking object. Cleared out by the test init cb.
A test piece of data to associate with test_core_format_attr.

◆ test_core_format_init()

static int test_core_format_init ( struct ast_test_info info,
struct ast_test test 
)
static

Definition at line 1019 of file test_core_format.c.

References test_callbacks_called.

Referenced by load_module().

1020 {
1021  memset(&test_callbacks_called, 0, sizeof(test_callbacks_called));
1022 
1023  return 0;
1024 }
static struct callbacks_called test_callbacks_called
A global tracking object. Cleared out by the test init cb.

◆ test_core_format_parse_sdp_fmtp()

static struct ast_format * test_core_format_parse_sdp_fmtp ( const struct ast_format format,
const char *  attributes 
)
static

Format attribute callback to construct a format from an SDP fmtp line.

Definition at line 219 of file test_core_format.c.

References ao2_ref, ast_format_clone(), ast_format_get_attribute_data(), test_core_format_pvt::field_one, test_core_format_pvt::field_two, callbacks_called::format_parse_sdp_fmtp, NULL, and test_callbacks_called.

220 {
221  struct ast_format *clone = ast_format_clone(format);
222  struct test_core_format_pvt *pvt;
223 
224  if (!clone) {
225  return NULL;
226  }
227 
228  pvt = ast_format_get_attribute_data(clone);
229 
230  if (sscanf(attributes, "one=%d;two=%d", &pvt->field_one, &pvt->field_two) != 2) {
231  ao2_ref(clone, -1);
232  return NULL;
233  }
234 
236  return clone;
237 }
Definition of a media format.
Definition: format.c:43
void * ast_format_get_attribute_data(const struct ast_format *format)
Get the attribute data on a format.
Definition: format.c:125
#define NULL
Definition: resample.c:96
struct ast_format * ast_format_clone(const struct ast_format *format)
Clone an existing media format so it can be modified.
Definition: format.c:180
#define ao2_ref(o, delta)
Definition: astobj2.h:464
static struct callbacks_called test_callbacks_called
A global tracking object. Cleared out by the test init cb.
A test piece of data to associate with test_core_format_attr.

◆ unload_module()

static int unload_module ( void  )
static

Definition at line 1026 of file test_core_format.c.

References AST_TEST_UNREGISTER.

1027 {
1028  AST_TEST_UNREGISTER(format_create);
1029  AST_TEST_UNREGISTER(format_create_attr);
1030  AST_TEST_UNREGISTER(format_retrieve_attr);
1031  AST_TEST_UNREGISTER(format_clone);
1032  AST_TEST_UNREGISTER(format_cmp_same_codec);
1033  AST_TEST_UNREGISTER(format_attr_cmp_same_codec);
1034  AST_TEST_UNREGISTER(format_cmp_different_codec);
1035  AST_TEST_UNREGISTER(format_joint_same_codec);
1036  AST_TEST_UNREGISTER(format_attr_joint_same_codec);
1037  AST_TEST_UNREGISTER(format_joint_different_codec);
1038  AST_TEST_UNREGISTER(format_copy);
1039  AST_TEST_UNREGISTER(format_attribute_set_without_interface);
1040  AST_TEST_UNREGISTER(format_attribute_get_without_interface);
1041  AST_TEST_UNREGISTER(format_parse_sdp_fmtp_without_interface);
1042  AST_TEST_UNREGISTER(format_parse_and_generate_sdp_fmtp);
1043 
1044  return 0;
1045 }
#define AST_TEST_UNREGISTER(cb)
Definition: test.h:128

Variable Documentation

◆ __mod_info

struct ast_module_info __mod_info = { .name = AST_MODULE, .flags = AST_MODFLAG_LOAD_ORDER , .description = "Core format API test module" , .key = "This paragraph is copyright (c) 2006 by Digium, Inc. \In order for your module to load, it must return this \key via a function called \"key\". Any code which \includes this paragraph must be licensed under the GNU \General Public License version 2 or later (at your \option). In addition to Digium's general reservations \of rights, Digium expressly reserves the right to \allow other parties to license this paragraph under \different terms. Any use of Digium, Inc. trademarks or \logos (including \"Asterisk\" or \"Digium\") without \express written permission of Digium, Inc. is prohibited.\n" , .buildopt_sum = AST_BUILDOPT_SUM, .load = load_module, .unload = unload_module, .load_pri = AST_MODPRI_DEFAULT, .support_level = AST_MODULE_SUPPORT_CORE, }
static

Definition at line 1081 of file test_core_format.c.

◆ ast_module_info

const struct ast_module_info* ast_module_info = &__mod_info
static

Definition at line 1081 of file test_core_format.c.

◆ test_callbacks_called

struct callbacks_called test_callbacks_called
static

◆ test_core_format_attr

struct ast_format_interface test_core_format_attr
static

A format attribute 'module' used by the unit tests.

Definition at line 51 of file test_core_format.c.

◆ test_core_format_codec

struct ast_codec test_core_format_codec
static

A test codec for these unit tests. Should be used with test_core_format.

Definition at line 71 of file test_core_format.c.