Asterisk - The Open Source Telephony Project GIT-master-2de1a68
test_endpoints.c
Go to the documentation of this file.
1/*
2 * Asterisk -- An open source telephony toolkit.
3 *
4 * Copyright (C) 2013, Digium, Inc.
5 *
6 * David M. Lee, II <dlee@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 Test endpoints.
22 *
23 * \author\verbatim David M. Lee, II <dlee@digium.com> \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"
39#include "asterisk/test.h"
40
41static const char *test_category = "/core/endpoints/";
42
44{
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
76{
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
107{
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
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
137static 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
145static int load_module(void)
146{
147 AST_TEST_REGISTER(create);
148 AST_TEST_REGISTER(defaults);
149 AST_TEST_REGISTER(setters);
151}
152
154 .support_level = AST_MODULE_SUPPORT_CORE,
155 .load = load_module,
156 .unload = unload_module,
Asterisk main include file. File version handling, generic pbx functions.
#define ao2_cleanup(obj)
Definition: astobj2.h:1934
Endpoint abstractions.
@ AST_ENDPOINT_ONLINE
Definition: endpoints.h:57
@ AST_ENDPOINT_UNKNOWN
Definition: endpoints.h:53
void ast_endpoint_set_state(struct ast_endpoint *endpoint, enum ast_endpoint_state state)
Updates the state of the given endpoint.
const char * ast_endpoint_get_tech(const struct ast_endpoint *endpoint)
Gets the technology of the given endpoint.
void ast_endpoint_shutdown(struct ast_endpoint *endpoint)
Shutsdown an ast_endpoint.
void ast_endpoint_set_max_channels(struct ast_endpoint *endpoint, int max_channels)
Updates the maximum number of channels an endpoint supports.
const char * ast_endpoint_get_resource(const struct ast_endpoint *endpoint)
Gets the resource name of the given endpoint.
struct ast_endpoint * ast_endpoint_create(const char *tech, const char *resource)
Create an endpoint struct.
struct ast_endpoint_snapshot * ast_endpoint_snapshot_create(struct ast_endpoint *endpoint)
Create a snapshot of an endpoint.
Asterisk module definitions.
@ AST_MODFLAG_DEFAULT
Definition: module.h:315
#define AST_MODULE_INFO(keystr, flags_to_set, desc, fields...)
Definition: module.h:543
@ AST_MODULE_SUPPORT_CORE
Definition: module.h:121
#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
Endpoint abstractions.
A snapshot of an endpoint's state.
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_PASS
Definition: test.h:195
@ AST_TEST_NOT_RUN
Definition: test.h:194
AST_TEST_DEFINE(create)
static int load_module(void)
static int unload_module(void)
static const char * test_category
#define RAII_VAR(vartype, varname, initval, dtor)
Declare a variable that will call a destructor function when it goes out of scope.
Definition: utils.h:941