Debian Codegraph @

tests/test_channel.c

raw symbols SCIP
1 /*
2 * Asterisk -- An open source telephony toolkit.
3 *
4 * Copyright (C) 2017, Digium, Inc.
5 *
6 * Joshua Colp <[email protected]>
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 <[email protected]>
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
38 AST_TEST_DEFINE(set_fd_grow)
39 {
40 struct ast_channel *mock_channel;
41 enum ast_test_result_state res = AST_TEST_PASS;
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 }
71
72 AST_TEST_DEFINE(add_fd)
73 {
74 struct ast_channel *mock_channel;
75 enum ast_test_result_state res = AST_TEST_PASS;
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 }
104
105 static int unload_module(void)
106 {
107 AST_TEST_UNREGISTER(set_fd_grow);
108 AST_TEST_UNREGISTER(add_fd);
109 return 0;
110 }
111
112 static int load_module(void)
113 {
114 AST_TEST_REGISTER(set_fd_grow);
115 AST_TEST_REGISTER(add_fd);
116 return AST_MODULE_LOAD_SUCCESS;
117 }
118
119 AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "Channel Unit Tests");