Asterisk - The Open Source Telephony Project  18.5.0
Functions | Variables
test_core_codec.c File Reference

Core Codec API Unit Tests. More...

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

Go to the source code of this file.

Functions

static void __reg_module (void)
 
static void __unreg_module (void)
 
struct ast_moduleAST_MODULE_SELF_SYM (void)
 
 AST_TEST_DEFINE (codec_register)
 
 AST_TEST_DEFINE (codec_register_twice)
 
 AST_TEST_DEFINE (codec_register_unknown)
 
 AST_TEST_DEFINE (codec_register_audio_no_sample_rate)
 
 AST_TEST_DEFINE (codec_get)
 
 AST_TEST_DEFINE (codec_get_unregistered)
 
 AST_TEST_DEFINE (codec_get_unknown)
 
 AST_TEST_DEFINE (codec_get_id)
 
static int load_module (void)
 
static int unload_module (void)
 

Variables

static struct ast_module_info __mod_info = { .name = AST_MODULE, .flags = AST_MODFLAG_LOAD_ORDER , .description = "Core codec 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 ast_codec audio_get
 
static struct ast_codec audio_get_id
 
static struct ast_codec audio_get_unknown
 
static struct ast_codec audio_without_rate
 
static struct ast_codec doubly
 
static struct ast_codec known_unknown
 
static struct ast_codec unknown
 

Detailed Description

Core Codec API Unit Tests.

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

Definition in file test_core_codec.c.

Function Documentation

◆ __reg_module()

static void __reg_module ( void  )
static

Definition at line 367 of file test_core_codec.c.

◆ __unreg_module()

static void __unreg_module ( void  )
static

Definition at line 367 of file test_core_codec.c.

◆ AST_MODULE_SELF_SYM()

struct ast_module* AST_MODULE_SELF_SYM ( void  )

Definition at line 367 of file test_core_codec.c.

◆ AST_TEST_DEFINE() [1/8]

AST_TEST_DEFINE ( codec_register  )

Definition at line 107 of file test_core_codec.c.

References ast_codec_register, AST_TEST_FAIL, AST_TEST_NOT_RUN, AST_TEST_PASS, ast_test_status_update, sip_to_pjsip::info(), TEST_EXECUTE, and TEST_INIT.

108 {
109  switch (cmd) {
110  case TEST_INIT:
111  info->name = "codec_register";
112  info->category = "/main/core_codec/";
113  info->summary = "codec registration unit test";
114  info->description =
115  "Test registration of a core codec that is known to be unknown";
116  return AST_TEST_NOT_RUN;
117  case TEST_EXECUTE:
118  break;
119  }
120 
122  ast_test_status_update(test, "Unsuccessfully registered a codec that is known to be unknown\n");
123  return AST_TEST_FAIL;
124  }
125 
126  return AST_TEST_PASS;
127 }
#define ast_test_status_update(a, b, c...)
Definition: test.h:129
#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
def info(msg)
static struct ast_codec known_unknown

◆ AST_TEST_DEFINE() [2/8]

AST_TEST_DEFINE ( codec_register_twice  )

Definition at line 129 of file test_core_codec.c.

References ast_codec_register, AST_TEST_FAIL, AST_TEST_NOT_RUN, AST_TEST_PASS, ast_test_status_update, sip_to_pjsip::info(), TEST_EXECUTE, and TEST_INIT.

130 {
131  switch (cmd) {
132  case TEST_INIT:
133  info->name = "codec_register_twice";
134  info->category = "/main/core_codec/";
135  info->summary = "codec registration unit test";
136  info->description =
137  "Test double registration of a core codec to confirm it fails";
138  return AST_TEST_NOT_RUN;
139  case TEST_EXECUTE:
140  break;
141  }
142 
143  if (ast_codec_register(&doubly)) {
144  ast_test_status_update(test, "Unsuccessfully registered a codec that is known to be unknown\n");
145  return AST_TEST_FAIL;
146  }
147 
148  if (!ast_codec_register(&doubly)) {
149  ast_test_status_update(test, "Successfully registered a codec twice\n");
150  return AST_TEST_FAIL;
151  }
152 
153  return AST_TEST_PASS;
154 }
#define ast_test_status_update(a, b, c...)
Definition: test.h:129
#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
def info(msg)
static struct ast_codec doubly

◆ AST_TEST_DEFINE() [3/8]

AST_TEST_DEFINE ( codec_register_unknown  )

Definition at line 156 of file test_core_codec.c.

References ast_codec_register, AST_TEST_FAIL, AST_TEST_NOT_RUN, AST_TEST_PASS, ast_test_status_update, sip_to_pjsip::info(), TEST_EXECUTE, and TEST_INIT.

157 {
158  switch (cmd) {
159  case TEST_INIT:
160  info->name = "codec_register_unknown";
161  info->category = "/main/core_codec/";
162  info->summary = "codec registration unit test";
163  info->description =
164  "Test that registration of an unknown codec type fails";
165  return AST_TEST_NOT_RUN;
166  case TEST_EXECUTE:
167  break;
168  }
169 
170  if (!ast_codec_register(&unknown)) {
171  ast_test_status_update(test, "Successfully registered a codec with an unknown media type\n");
172  return AST_TEST_FAIL;
173  }
174 
175  return AST_TEST_PASS;
176 }
#define ast_test_status_update(a, b, c...)
Definition: test.h:129
#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
def info(msg)
static struct ast_codec unknown

◆ AST_TEST_DEFINE() [4/8]

AST_TEST_DEFINE ( codec_register_audio_no_sample_rate  )

Definition at line 178 of file test_core_codec.c.

References ast_codec_register, AST_TEST_FAIL, AST_TEST_NOT_RUN, AST_TEST_PASS, ast_test_status_update, sip_to_pjsip::info(), TEST_EXECUTE, and TEST_INIT.

179 {
180  switch (cmd) {
181  case TEST_INIT:
182  info->name = "codec_register_audio_no_sample_rate";
183  info->category = "/main/core_codec/";
184  info->summary = "codec registration unit test";
185  info->description =
186  "Test that registration of an audio codec without sample rate fails";
187  return AST_TEST_NOT_RUN;
188  case TEST_EXECUTE:
189  break;
190  }
191 
193  ast_test_status_update(test, "Successfully registered an audio codec without a sample rate\n");
194  return AST_TEST_FAIL;
195  }
196 
197  return AST_TEST_PASS;
198 }
static struct ast_codec audio_without_rate
#define ast_test_status_update(a, b, c...)
Definition: test.h:129
#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
def info(msg)

◆ AST_TEST_DEFINE() [5/8]

AST_TEST_DEFINE ( codec_get  )

Definition at line 200 of file test_core_codec.c.

References ao2_cleanup, ast_codec_get(), ast_codec_register, AST_MEDIA_TYPE_AUDIO, AST_TEST_FAIL, AST_TEST_NOT_RUN, AST_TEST_PASS, ast_test_status_update, sip_to_pjsip::info(), ast_codec::name, NULL, RAII_VAR, ast_codec::sample_rate, TEST_EXECUTE, TEST_INIT, and ast_codec::type.

201 {
202  RAII_VAR(struct ast_codec *, codec, NULL, ao2_cleanup);
203 
204  switch (cmd) {
205  case TEST_INIT:
206  info->name = "codec_get";
207  info->category = "/main/core_codec/";
208  info->summary = "codec get unit test";
209  info->description =
210  "Test that getting of a known codec succeeds";
211  return AST_TEST_NOT_RUN;
212  case TEST_EXECUTE:
213  break;
214  }
215 
217  ast_test_status_update(test, "Unsucessfully registered a codec for getting\n");
218  return AST_TEST_FAIL;
219  }
220 
221  codec = ast_codec_get("unit_test_audio_get", AST_MEDIA_TYPE_AUDIO, 8000);
222  if (!codec) {
223  ast_test_status_update(test, "Unsuccessfully retrieved a codec we just registered\n");
224  return AST_TEST_FAIL;
225  } else if (strcmp(codec->name, audio_get.name)) {
226  ast_test_status_update(test, "Name of retrieved codec does not match registered codec\n");
227  return AST_TEST_FAIL;
228  } else if (codec->type != audio_get.type) {
229  ast_test_status_update(test, "Type of retrieved codec does not match registered codec\n");
230  return AST_TEST_FAIL;
231  } else if (codec->sample_rate != audio_get.sample_rate) {
232  ast_test_status_update(test, "Sample rate of retrieved codec does not match registered codec\n");
233  return AST_TEST_FAIL;
234  }
235 
236  return AST_TEST_PASS;
237 }
const char * name
Name for this codec.
Definition: codec.h:46
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 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
def info(msg)
unsigned int sample_rate
Sample rate (number of samples carried in a second)
Definition: codec.h:52
#define ao2_cleanup(obj)
Definition: astobj2.h:1958
enum ast_media_type type
Type of media this codec contains.
Definition: codec.h:50
static struct ast_codec audio_get
Represents a media codec within Asterisk.
Definition: codec.h:42

◆ AST_TEST_DEFINE() [6/8]

AST_TEST_DEFINE ( codec_get_unregistered  )

Definition at line 239 of file test_core_codec.c.

References ao2_cleanup, ast_codec_get(), AST_MEDIA_TYPE_AUDIO, AST_TEST_FAIL, AST_TEST_NOT_RUN, AST_TEST_PASS, ast_test_status_update, sip_to_pjsip::info(), test::name, NULL, RAII_VAR, TEST_EXECUTE, and TEST_INIT.

240 {
241  RAII_VAR(struct ast_codec *, codec, NULL, ao2_cleanup);
242 
243  switch (cmd) {
244  case TEST_INIT:
245  info->name = "codec_get_unregistered";
246  info->category = "/main/core_codec/";
247  info->summary = "codec get unit test";
248  info->description =
249  "Test that getting of a codec that is not registered fails";
250  return AST_TEST_NOT_RUN;
251  case TEST_EXECUTE:
252  break;
253  }
254 
255  codec = ast_codec_get("goats", AST_MEDIA_TYPE_AUDIO, 8000);
256  if (codec) {
257  ast_test_status_update(test, "Successfully got a codec named '%s' when getting a codec named 'goats'\n",
258  codec->name);
259  return AST_TEST_FAIL;
260  }
261 
262  return AST_TEST_PASS;
263 }
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
const char * name
Definition: test_logger.c:44
#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
Represents a media codec within Asterisk.
Definition: codec.h:42

◆ AST_TEST_DEFINE() [7/8]

AST_TEST_DEFINE ( codec_get_unknown  )

Definition at line 265 of file test_core_codec.c.

References ao2_cleanup, ast_codec_get(), ast_codec_register, AST_MEDIA_TYPE_UNKNOWN, AST_TEST_FAIL, AST_TEST_NOT_RUN, AST_TEST_PASS, ast_test_status_update, sip_to_pjsip::info(), ast_codec::name, NULL, RAII_VAR, ast_codec::sample_rate, TEST_EXECUTE, TEST_INIT, and ast_codec::type.

266 {
267  RAII_VAR(struct ast_codec *, codec, NULL, ao2_cleanup);
268 
269  switch (cmd) {
270  case TEST_INIT:
271  info->name = "codec_get_unknown";
272  info->category = "/main/core_codec/";
273  info->summary = "codec get unit test";
274  info->description =
275  "Test that getting of a known codec using name and unknown type succeeds";
276  return AST_TEST_NOT_RUN;
277  case TEST_EXECUTE:
278  break;
279  }
280 
282  ast_test_status_update(test, "Unsucessfully registered a codec for getting\n");
283  return AST_TEST_FAIL;
284  }
285 
286  codec = ast_codec_get("unit_test_audio_get_unknown", AST_MEDIA_TYPE_UNKNOWN, 8000);
287  if (!codec) {
288  ast_test_status_update(test, "Unsuccessfully retrieved a codec we just registered\n");
289  return AST_TEST_FAIL;
290  } else if (strcmp(codec->name, audio_get_unknown.name)) {
291  ast_test_status_update(test, "Name of retrieved codec does not match registered codec\n");
292  return AST_TEST_FAIL;
293  } else if (codec->type != audio_get_unknown.type) {
294  ast_test_status_update(test, "Type of retrieved codec does not match registered codec\n");
295  return AST_TEST_FAIL;
296  } else if (codec->sample_rate != audio_get_unknown.sample_rate) {
297  ast_test_status_update(test, "Sample rate of retrieved codec does not match registered codec\n");
298  return AST_TEST_FAIL;
299  }
300 
301  return AST_TEST_PASS;
302 }
const char * name
Name for this codec.
Definition: codec.h:46
static struct ast_codec audio_get_unknown
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 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
def info(msg)
unsigned int sample_rate
Sample rate (number of samples carried in a second)
Definition: codec.h:52
#define ao2_cleanup(obj)
Definition: astobj2.h:1958
enum ast_media_type type
Type of media this codec contains.
Definition: codec.h:50
Represents a media codec within Asterisk.
Definition: codec.h:42

◆ AST_TEST_DEFINE() [8/8]

AST_TEST_DEFINE ( codec_get_id  )

Definition at line 304 of file test_core_codec.c.

References ao2_cleanup, ast_codec_get(), ast_codec_get_by_id(), ast_codec_register, AST_MEDIA_TYPE_AUDIO, AST_TEST_FAIL, AST_TEST_NOT_RUN, AST_TEST_PASS, ast_test_status_update, sip_to_pjsip::info(), NULL, RAII_VAR, TEST_EXECUTE, and TEST_INIT.

305 {
306  RAII_VAR(struct ast_codec *, named, NULL, ao2_cleanup);
307  RAII_VAR(struct ast_codec *, codec, NULL, ao2_cleanup);
308 
309  switch (cmd) {
310  case TEST_INIT:
311  info->name = "codec_get_unknown";
312  info->category = "/main/core_codec/";
313  info->summary = "codec get unit test";
314  info->description =
315  "Test that getting of a known codec using name and unknown type succeeds";
316  return AST_TEST_NOT_RUN;
317  case TEST_EXECUTE:
318  break;
319  }
320 
322  ast_test_status_update(test, "Unsucessfully registered a codec for getting\n");
323  return AST_TEST_FAIL;
324  }
325 
326  named = ast_codec_get("unit_test_audio_get_id", AST_MEDIA_TYPE_AUDIO, 8000);
327  if (!named) {
328  ast_test_status_update(test, "Unsuccessfully retrieved a codec we just registered\n");
329  return AST_TEST_FAIL;
330  }
331 
332  codec = ast_codec_get_by_id(named->id);
333  if (!codec) {
334  ast_test_status_update(test, "Unsuccessfully retrieved a codec using id of a named codec we just got\n");
335  return AST_TEST_FAIL;
336  }
337 
338  return AST_TEST_PASS;
339 }
struct ast_codec * ast_codec_get_by_id(int id)
Retrieve a codec given the unique identifier.
Definition: codec.c:337
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 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
def info(msg)
static struct ast_codec audio_get_id
#define ao2_cleanup(obj)
Definition: astobj2.h:1958
Represents a media codec within Asterisk.
Definition: codec.h:42

◆ load_module()

static int load_module ( void  )
static

Definition at line 354 of file test_core_codec.c.

References AST_MODULE_LOAD_SUCCESS, and AST_TEST_REGISTER.

355 {
356  AST_TEST_REGISTER(codec_register);
357  AST_TEST_REGISTER(codec_register_twice);
358  AST_TEST_REGISTER(codec_register_unknown);
359  AST_TEST_REGISTER(codec_register_audio_no_sample_rate);
360  AST_TEST_REGISTER(codec_get);
361  AST_TEST_REGISTER(codec_get_unregistered);
362  AST_TEST_REGISTER(codec_get_unknown);
363  AST_TEST_REGISTER(codec_get_id);
365 }
#define AST_TEST_REGISTER(cb)
Definition: test.h:127

◆ unload_module()

static int unload_module ( void  )
static

Definition at line 341 of file test_core_codec.c.

References AST_TEST_UNREGISTER.

342 {
343  AST_TEST_UNREGISTER(codec_register);
344  AST_TEST_UNREGISTER(codec_register_twice);
345  AST_TEST_UNREGISTER(codec_register_unknown);
346  AST_TEST_UNREGISTER(codec_register_audio_no_sample_rate);
347  AST_TEST_UNREGISTER(codec_get);
348  AST_TEST_UNREGISTER(codec_get_unregistered);
349  AST_TEST_UNREGISTER(codec_get_unknown);
350  AST_TEST_UNREGISTER(codec_get_id);
351  return 0;
352 }
#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 codec 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 367 of file test_core_codec.c.

◆ ast_module_info

const struct ast_module_info* ast_module_info = &__mod_info
static

Definition at line 367 of file test_core_codec.c.

◆ audio_get

struct ast_codec audio_get
static

Definition at line 77 of file test_core_codec.c.

◆ audio_get_id

struct ast_codec audio_get_id
static

Definition at line 97 of file test_core_codec.c.

◆ audio_get_unknown

struct ast_codec audio_get_unknown
static

Definition at line 87 of file test_core_codec.c.

◆ audio_without_rate

struct ast_codec audio_without_rate
static

Definition at line 68 of file test_core_codec.c.

◆ doubly

struct ast_codec doubly
static

Definition at line 48 of file test_core_codec.c.

◆ known_unknown

struct ast_codec known_unknown
static

Definition at line 38 of file test_core_codec.c.

◆ unknown

struct ast_codec unknown
static

Definition at line 58 of file test_core_codec.c.

Referenced by odbc_log().