Asterisk - The Open Source Telephony Project GIT-master-97770a9
test_channel.c
Go to the documentation of this file.
1/*
2 * Asterisk -- An open source telephony toolkit.
3 *
4 * Copyright (C) 2017, Digium, Inc.
5 *
6 * Joshua Colp <jcolp@digium.com>
7 *
8 * See http://www.asterisk.org for more information about
9 * the Asterisk project. Please do not directly contact
10 * any of the maintainers of this project for assistance;
11 * the project provides a web site, mailing lists and IRC
12 * channels for your use.
13 *
14 * This program is free software, distributed under the terms of
15 * the GNU General Public License Version 2. See the LICENSE file
16 * at the top of the source tree.
17 */
18
19/*!
20 * \file
21 * \brief Channel unit tests
22 *
23 * \author Joshua Colp <jcolp@digium.com>
24 *
25 */
26
27/*** MODULEINFO
28 <depend>TEST_FRAMEWORK</depend>
29 <support_level>core</support_level>
30 ***/
31
32#include "asterisk.h"
33
34#include "asterisk/module.h"
35#include "asterisk/test.h"
36#include "asterisk/channel.h"
37
38AST_TEST_DEFINE(set_fd_grow)
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}
71
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}
104
105static int unload_module(void)
106{
107 AST_TEST_UNREGISTER(set_fd_grow);
108 AST_TEST_UNREGISTER(add_fd);
109 return 0;
110}
111
112static int load_module(void)
113{
114 AST_TEST_REGISTER(set_fd_grow);
115 AST_TEST_REGISTER(add_fd);
117}
118
Asterisk main include file. File version handling, generic pbx functions.
General Asterisk PBX channel definitions.
#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
int ast_channel_fd_count(const struct ast_channel *chan)
Retrieve the number of file decriptor positions present on the channel.
@ AST_STATE_DOWN
Definition: channelstate.h:36
Asterisk module definitions.
#define AST_MODULE_INFO_STANDARD(keystr, desc)
Definition: module.h:581
#define ASTERISK_GPL_KEY
The text the key() function should return.
Definition: module.h:46
@ AST_MODULE_LOAD_SUCCESS
Definition: module.h:70
def info(msg)
#define NULL
Definition: resample.c:96
Main Channel structure associated with a channel.
Test Framework API.
@ TEST_INIT
Definition: test.h:200
@ TEST_EXECUTE
Definition: test.h:201
#define AST_TEST_REGISTER(cb)
Definition: test.h:127
#define AST_TEST_UNREGISTER(cb)
Definition: test.h:128
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
AST_TEST_DEFINE(set_fd_grow)
Definition: test_channel.c:38
static int load_module(void)
Definition: test_channel.c:112
static int unload_module(void)
Definition: test_channel.c:105