Asterisk - The Open Source Telephony Project GIT-master-f36a736
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 (add_fd)
 
 AST_TEST_DEFINE (set_fd_grow)
 
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 ( add_fd  )

Definition at line 72 of file test_channel.c.

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
99done:
100 ast_hangup(mock_channel);
101
102 return res;
103}
#define AST_EXTENDED_FDS
Definition: channel.h:197
void ast_hangup(struct ast_channel *chan)
Hang up a channel.
Definition: channel.c:2560
#define ast_channel_alloc(needqueue, state, cid_num, cid_name, acctcode, exten, context, assignedids, requestor, amaflag,...)
Create a channel structure.
Definition: channel.h:1299
int ast_channel_fd_add(struct ast_channel *chan, int value)
Add a file descriptor to the channel without a fixed position.
int ast_channel_fd(const struct ast_channel *chan, int which)
void ast_channel_set_fd(struct ast_channel *chan, int which, int fd)
Definition: channel.c:2445
@ AST_STATE_DOWN
Definition: channelstate.h:36
def info(msg)
#define NULL
Definition: resample.c:96
Main Channel structure associated with a channel.
@ TEST_INIT
Definition: test.h:200
@ TEST_EXECUTE
Definition: test.h:201
ast_test_result_state
Definition: test.h:193
@ AST_TEST_PASS
Definition: test.h:195
@ AST_TEST_NOT_RUN
Definition: test.h:194
int done
Definition: test_amihooks.c:48

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.

◆ AST_TEST_DEFINE() [2/2]

AST_TEST_DEFINE ( set_fd_grow  )

Definition at line 38 of file test_channel.c.

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
66done:
67 ast_hangup(mock_channel);
68
69 return res;
70}
int ast_channel_fd_count(const struct ast_channel *chan)
Retrieve the number of file decriptor positions present on the channel.

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.

◆ load_module()

static int load_module ( void  )
static

Definition at line 112 of file test_channel.c.

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

References AST_MODULE_LOAD_SUCCESS, and AST_TEST_REGISTER.

◆ unload_module()

static int unload_module ( void  )
static

Definition at line 105 of file test_channel.c.

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

References AST_TEST_UNREGISTER.

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.