Asterisk - The Open Source Telephony Project  18.5.0
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 <[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"
39 #include "asterisk/test.h"
40 
41 static 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 
75 AST_TEST_DEFINE(defaults)
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 
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);
151 }
152 
154  .support_level = AST_MODULE_SUPPORT_CORE,
155  .load = load_module,
156  .unload = unload_module,
157 );
Asterisk main include file. File version handling, generic pbx functions.
static int unload_module(void)
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.
const char * ast_endpoint_get_tech(const struct ast_endpoint *endpoint)
Gets the technology of the given endpoint.
AST_TEST_DEFINE(create)
Test Framework API.
static const char * test_category
#define AST_TEST_REGISTER(cb)
Definition: test.h:127
void ast_endpoint_set_state(struct ast_endpoint *endpoint, enum ast_endpoint_state state)
Updates the state of the given endpoint.
Endpoint abstractions.
#define NULL
Definition: resample.c:96
const char * ast_endpoint_get_resource(const struct ast_endpoint *endpoint)
Gets the resource name of the given endpoint.
#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:911
A snapshot of an endpoint&#39;s state.
#define AST_TEST_UNREGISTER(cb)
Definition: test.h:128
def info(msg)
AST_MODULE_INFO(ASTERISK_GPL_KEY, AST_MODFLAG_GLOBAL_SYMBOLS|AST_MODFLAG_LOAD_ORDER, "HTTP Phone Provisioning",.support_level=AST_MODULE_SUPPORT_EXTENDED,.load=load_module,.unload=unload_module,.reload=reload,.load_pri=AST_MODPRI_CHANNEL_DEPEND,.requires="http",)
void ast_endpoint_set_max_channels(struct ast_endpoint *endpoint, int max_channels)
Updates the maximum number of channels an endpoint supports.
#define ao2_cleanup(obj)
Definition: astobj2.h:1958
void ast_endpoint_shutdown(struct ast_endpoint *endpoint)
Shutsdown an ast_endpoint.
#define ASTERISK_GPL_KEY
The text the key() function should return.
Definition: module.h:46
Asterisk module definitions.
Endpoint abstractions.
static int load_module(void)