Asterisk - The Open Source Telephony Project  21.4.1
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"

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.
 
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.
 
static int test_core_format_clone (const struct ast_format *src, struct ast_format *dst)
 Format attribute callback called during format cloning.
 
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.
 
static void test_core_format_destroy (struct ast_format *format)
 Format attribute callback for when format attributes are to be destroyed.
 
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.
 
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.
 
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.
 
static struct ast_format_interface test_core_format_attr
 A format attribute 'module' used by the unit tests.
 
static struct ast_codec test_core_format_codec
 A test codec for these unit tests. Should be used with test_core_format.
 

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.

Function Documentation

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, 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
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.