Debian Codegraph @

tests/test_endpoints.c

raw symbols SCIP
1 /*
2 * Asterisk -- An open source telephony toolkit.
3 *
4 * Copyright (C) 2013, Digium, Inc.
5 *
6 * David M. Lee, II <[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 Test endpoints.
22 *
23 * \author\verbatim David M. Lee, II <[email protected]> \endverbatim
24 *
25 * \ingroup tests
26 */
27
28 /*** MODULEINFO
29 <depend>TEST_FRAMEWORK</depend>
30 <support_level>core</support_level>
31 ***/
32
33 #include "asterisk.h"
34
35 #include "asterisk/astobj2.h"
36 #include "asterisk/endpoints.h"
37 #include "asterisk/module.h"
38 #include "asterisk/stasis_endpoints.h"
39 #include "asterisk/test.h"
40
41 static const char *test_category = "/core/endpoints/";
42
43 AST_TEST_DEFINE(create)
44 {
45 RAII_VAR(struct ast_endpoint *, uut, NULL, ast_endpoint_shutdown);
46
47 switch (cmd) {
48 case TEST_INIT:
49 info->name = __func__;
50 info->category = test_category;
51 info->summary = "Test endpoint creation";
52 info->description = "Test endpoint creation";
53 return AST_TEST_NOT_RUN;
54 case TEST_EXECUTE:
55 break;
56 }
57
58 ast_test_validate(test, NULL == ast_endpoint_create(NULL, NULL));
59 ast_test_validate(test, NULL == ast_endpoint_create("", ""));
60 ast_test_validate(test, NULL == ast_endpoint_create("TEST", ""));
61 ast_test_validate(test, NULL == ast_endpoint_create("", "test_res"));
62
63 uut = ast_endpoint_create("TEST", "test_res");
64 ast_test_validate(test, NULL != uut);
65
66 ast_test_validate(test,
67 0 == strcmp("TEST", ast_endpoint_get_tech(uut)));
68 ast_test_validate(test,
69 0 == strcmp("test_res", ast_endpoint_get_resource(uut)));
70
71 return AST_TEST_PASS;
72 }
73
74
75 AST_TEST_DEFINE(defaults)
76 {
77 RAII_VAR(struct ast_endpoint *, uut, NULL, ast_endpoint_shutdown);
78 RAII_VAR(struct ast_endpoint_snapshot *, snapshot, NULL, ao2_cleanup);
79
80 switch (cmd) {
81 case TEST_INIT:
82 info->name = __func__;
83 info->category = test_category;
84 info->summary = "Test defaults for new endpoints";
85 info->description = "Test defaults for new endpoints";
86 return AST_TEST_NOT_RUN;
87 case TEST_EXECUTE:
88 break;
89 }
90
91 uut = ast_endpoint_create("TEST", "test_res");
92 ast_test_validate(test, NULL != uut);
93 snapshot = ast_endpoint_snapshot_create(uut);
94 ast_test_validate(test, NULL != snapshot);
95
96 ast_test_validate(test, 0 == strcmp("TEST/test_res", snapshot->id));
97 ast_test_validate(test, 0 == strcmp("TEST", snapshot->tech));
98 ast_test_validate(test, 0 == strcmp("test_res", snapshot->resource));
99 ast_test_validate(test, AST_ENDPOINT_UNKNOWN == snapshot->state);
100 ast_test_validate(test, -1 == snapshot->max_channels);
101 ast_test_validate(test, 0 == snapshot->num_channels);
102
103 return AST_TEST_PASS;
104 }
105
106 AST_TEST_DEFINE(setters)
107 {
108 RAII_VAR(struct ast_endpoint *, uut, NULL, ast_endpoint_shutdown);
109 RAII_VAR(struct ast_endpoint_snapshot *, snapshot, NULL, ao2_cleanup);
110
111 switch (cmd) {
112 case TEST_INIT:
113 info->name = __func__;
114 info->category = test_category;
115 info->summary = "Test endpoint setters";
116 info->description = "Test endpoint setters";
117 return AST_TEST_NOT_RUN;
118 case TEST_EXECUTE:
119 break;
120 }
121
122 uut = ast_endpoint_create("TEST", "test_res");
123 ast_test_validate(test, NULL != uut);
124
125 ast_endpoint_set_state(uut, AST_ENDPOINT_ONLINE);
126 ast_endpoint_set_max_channels(uut, 314159);
127
128 snapshot = ast_endpoint_snapshot_create(uut);
129 ast_test_validate(test, NULL != snapshot);
130
131 ast_test_validate(test, AST_ENDPOINT_ONLINE == snapshot->state);
132 ast_test_validate(test, 314159 == snapshot->max_channels);
133
134 return AST_TEST_PASS;
135 }
136
137 static int unload_module(void)
138 {
139 AST_TEST_UNREGISTER(create);
140 AST_TEST_UNREGISTER(defaults);
141 AST_TEST_UNREGISTER(setters);
142 return 0;
143 }
144
145 static int load_module(void)
146 {
147 AST_TEST_REGISTER(create);
148 AST_TEST_REGISTER(defaults);
149 AST_TEST_REGISTER(setters);
150 return AST_MODULE_LOAD_SUCCESS;
151 }
152
153 AST_MODULE_INFO(ASTERISK_GPL_KEY, AST_MODFLAG_DEFAULT, "Endpoint testing",
154 .support_level = AST_MODULE_SUPPORT_CORE,
155 .load = load_module,
156 .unload = unload_module,
157 );