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

Channel unit tests. More...

#include "asterisk.h"
#include "asterisk/module.h"
#include "asterisk/test.h"
#include "asterisk/channel.h"
Include dependency graph for test_channel.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 (set_fd_grow)
 
 AST_TEST_DEFINE (add_fd)
 
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 = "Channel Unit Tests" , .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
 

Detailed Description

Channel unit tests.

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

Definition in file test_channel.c.

Function Documentation

◆ __reg_module()

static void __reg_module ( void  )
static

Definition at line 119 of file test_channel.c.

◆ __unreg_module()

static void __unreg_module ( void  )
static

Definition at line 119 of file test_channel.c.

◆ AST_MODULE_SELF_SYM()

struct ast_module* AST_MODULE_SELF_SYM ( void  )

Definition at line 119 of file test_channel.c.

◆ AST_TEST_DEFINE() [1/2]

AST_TEST_DEFINE ( set_fd_grow  )

Definition at line 38 of file test_channel.c.

References ast_channel_alloc, ast_channel_fd(), ast_channel_fd_count(), ast_channel_set_fd(), AST_EXTENDED_FDS, ast_hangup(), AST_STATE_DOWN, AST_TEST_NOT_RUN, AST_TEST_PASS, done, sip_to_pjsip::info(), NULL, TEST_EXECUTE, and TEST_INIT.

39 {
40  struct ast_channel *mock_channel;
42  int pos;
43 
44  switch (cmd) {
45  case TEST_INIT:
46  info->name = "set_fd_grow";
47  info->category = "/main/channel/";
48  info->summary = "channel setting file descriptor with growth test";
49  info->description =
50  "Test that setting a file descriptor on a high position of a channel results in -1 set on any new positions";
51  return AST_TEST_NOT_RUN;
52  case TEST_EXECUTE:
53  break;
54  }
55 
56  mock_channel = ast_channel_alloc(0, AST_STATE_DOWN, NULL, NULL, NULL, NULL, NULL, NULL, NULL, 0, "TestChannel");
57  ast_test_validate_cleanup(test, mock_channel, res, done);
58 
59  ast_channel_set_fd(mock_channel, AST_EXTENDED_FDS + 10, 1);
60  ast_test_validate_cleanup(test, ast_channel_fd_count(mock_channel) == AST_EXTENDED_FDS + 11, res, done);
61 
62  for (pos = AST_EXTENDED_FDS; (pos < AST_EXTENDED_FDS + 10); pos++) {
63  ast_test_validate_cleanup(test, ast_channel_fd(mock_channel, pos) == -1, res, done);
64  }
65 
66 done:
67  ast_hangup(mock_channel);
68 
69  return res;
70 }
Main Channel structure associated with a channel.
#define NULL
Definition: resample.c:96
int done
Definition: test_amihooks.c:48
#define AST_EXTENDED_FDS
Definition: channel.h:196
def info(msg)
void ast_hangup(struct ast_channel *chan)
Hang up a channel.
Definition: channel.c:2548
void ast_channel_set_fd(struct ast_channel *chan, int which, int fd)
Definition: channel.c:2431
int ast_channel_fd(const struct ast_channel *chan, int which)
int ast_channel_fd_count(const struct ast_channel *chan)
Retrieve the number of file decriptor positions present on the channel.
#define ast_channel_alloc(needqueue, state, cid_num, cid_name, acctcode, exten, context, assignedids, requestor, amaflag,...)
Create a channel structure.
Definition: channel.h:1259
ast_test_result_state
Definition: test.h:200

◆ AST_TEST_DEFINE() [2/2]

AST_TEST_DEFINE ( add_fd  )

Definition at line 72 of file test_channel.c.

References ast_channel_alloc, ast_channel_fd(), ast_channel_fd_add(), ast_channel_set_fd(), AST_EXTENDED_FDS, ast_hangup(), AST_STATE_DOWN, AST_TEST_NOT_RUN, AST_TEST_PASS, done, sip_to_pjsip::info(), NULL, TEST_EXECUTE, and TEST_INIT.

73 {
74  struct ast_channel *mock_channel;
76  int pos;
77 
78  switch (cmd) {
79  case TEST_INIT:
80  info->name = "add_fd";
81  info->category = "/main/channel/";
82  info->summary = "channel adding file descriptor test";
83  info->description =
84  "Test that adding a file descriptor to a channel places it in the expected position";
85  return AST_TEST_NOT_RUN;
86  case TEST_EXECUTE:
87  break;
88  }
89 
90  mock_channel = ast_channel_alloc(0, AST_STATE_DOWN, NULL, NULL, NULL, NULL, NULL, NULL, NULL, 0, "TestChannel");
91  ast_test_validate_cleanup(test, mock_channel, res, done);
92 
93  pos = ast_channel_fd_add(mock_channel, 1);
94  ast_test_validate_cleanup(test, pos == AST_EXTENDED_FDS, res, done);
95 
96  ast_channel_set_fd(mock_channel, pos, -1);
97  ast_test_validate_cleanup(test, ast_channel_fd(mock_channel, pos) == -1, res, done);
98 
99 done:
100  ast_hangup(mock_channel);
101 
102  return res;
103 }
Main Channel structure associated with a channel.
#define NULL
Definition: resample.c:96
int done
Definition: test_amihooks.c:48
int ast_channel_fd_add(struct ast_channel *chan, int value)
Add a file descriptor to the channel without a fixed position.
#define AST_EXTENDED_FDS
Definition: channel.h:196
def info(msg)
void ast_hangup(struct ast_channel *chan)
Hang up a channel.
Definition: channel.c:2548
void ast_channel_set_fd(struct ast_channel *chan, int which, int fd)
Definition: channel.c:2431
int ast_channel_fd(const struct ast_channel *chan, int which)
#define ast_channel_alloc(needqueue, state, cid_num, cid_name, acctcode, exten, context, assignedids, requestor, amaflag,...)
Create a channel structure.
Definition: channel.h:1259
ast_test_result_state
Definition: test.h:200

◆ load_module()

static int load_module ( void  )
static

Definition at line 112 of file test_channel.c.

References AST_MODULE_LOAD_SUCCESS, and AST_TEST_REGISTER.

113 {
114  AST_TEST_REGISTER(set_fd_grow);
115  AST_TEST_REGISTER(add_fd);
117 }
#define AST_TEST_REGISTER(cb)
Definition: test.h:127

◆ unload_module()

static int unload_module ( void  )
static

Definition at line 105 of file test_channel.c.

References AST_TEST_UNREGISTER.

106 {
107  AST_TEST_UNREGISTER(set_fd_grow);
108  AST_TEST_UNREGISTER(add_fd);
109  return 0;
110 }
#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 = "Channel Unit Tests" , .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 119 of file test_channel.c.

◆ ast_module_info

const struct ast_module_info* ast_module_info = &__mod_info
static

Definition at line 119 of file test_channel.c.