Asterisk - The Open Source Telephony Project GIT-master-f36a736
test_optional_api.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 optional API.
22 *
23 * This tests exercise the underlying implementation functions. Actual usage
24 * won't look anything like this; it would use the wrapper macros.
25 *
26 * \author\verbatim David M. Lee, II <dlee@digium.com> \endverbatim
27 *
28 * \ingroup tests
29 */
30
31/*** MODULEINFO
32 <depend>TEST_FRAMEWORK</depend>
33 <depend>OPTIONAL_API</depend>
34 <support_level>core</support_level>
35 ***/
36
37#include "asterisk.h"
38
39#include "asterisk/module.h"
41#include "asterisk/test.h"
42
43#define CATEGORY "/main/optional_api/"
44
48 IMPL
49};
50
52
53ast_optional_fn test_optional_ref;
54
55static void test_optional_stub(void)
56{
58}
59
60static void test_optional_impl(void)
61{
63}
64
65static void test_optional(void)
66{
70 }
71}
72
73#define SYMNAME "test_option"
74
75AST_TEST_DEFINE(test_provide_first)
76{
77 enum ast_test_result_state res;
78
79 switch (cmd) {
80 case TEST_INIT:
81 info->name = __func__;
82 info->category = CATEGORY;
83 info->summary = "Test optional API publishing.";
84 info->description = "Test optional API publishing.";
85 return AST_TEST_NOT_RUN;
86 case TEST_EXECUTE:
87 break;
88 }
89
90 res = AST_TEST_FAIL;
92
93 ast_optional_api_provide(SYMNAME, test_optional_impl);
94
95 ast_optional_api_use(SYMNAME, &test_optional_ref, test_optional_stub,
97
99
100 if (was_called_result != IMPL) {
101 ast_test_status_update(test, "Expected %d, was %u",
103 goto done;
104 }
105
106 res = AST_TEST_PASS;
107
108 done:
109 ast_optional_api_unuse(SYMNAME, &test_optional_ref, AST_MODULE);
110 ast_optional_api_unprovide(SYMNAME, test_optional_impl);
111 return res;
112}
113
114AST_TEST_DEFINE(test_provide_last)
115{
116 enum ast_test_result_state res;
117
118 switch (cmd) {
119 case TEST_INIT:
120 info->name = __func__;
121 info->category = CATEGORY;
122 info->summary = "Test optional API publishing.";
123 info->description = "Test optional API publishing.";
124 return AST_TEST_NOT_RUN;
125 case TEST_EXECUTE:
126 break;
127 }
128
129 res = AST_TEST_FAIL;
131
132 ast_optional_api_use(SYMNAME, &test_optional_ref, test_optional_stub,
133 AST_MODULE);
134
136 if (was_called_result != STUB) {
137 ast_test_status_update(test, "Expected %d, was %u",
139 goto done;
140 }
141
142 ast_optional_api_provide(SYMNAME, test_optional_impl);
143
145 if (was_called_result != IMPL) {
146 ast_test_status_update(test, "Expected %d, was %u",
148 ast_optional_api_unprovide(SYMNAME, test_optional_impl);
149 goto done;
150 }
151
152 ast_optional_api_unprovide(SYMNAME, test_optional_impl);
153
155 if (was_called_result != STUB) {
156 ast_test_status_update(test, "Expected %d, was %u",
158 ast_optional_api_unprovide(SYMNAME, test_optional_impl);
159 goto done;
160 }
161
162 res = AST_TEST_PASS;
163
164 done:
165 ast_optional_api_unuse(SYMNAME, &test_optional_ref, AST_MODULE);
166 return res;
167}
168
169static int unload_module(void)
170{
171 AST_TEST_UNREGISTER(test_provide_first);
172 AST_TEST_UNREGISTER(test_provide_last);
173 return 0;
174}
175
176static int load_module(void)
177{
178 AST_TEST_REGISTER(test_provide_first);
179 AST_TEST_REGISTER(test_provide_last);
181}
182
184 .support_level = AST_MODULE_SUPPORT_CORE,
185 .load = load_module,
186 .unload = unload_module,
#define AST_MODULE
Asterisk main include file. File version handling, generic pbx functions.
Asterisk module definitions.
@ AST_MODFLAG_DEFAULT
Definition: module.h:329
#define AST_MODULE_INFO(keystr, flags_to_set, desc, fields...)
Definition: module.h:557
@ 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)
Optional API function macros.
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_status_update(a, b, c...)
Definition: test.h:129
#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_FAIL
Definition: test.h:196
@ AST_TEST_NOT_RUN
Definition: test.h:194
int done
Definition: test_amihooks.c:48
was_called
@ STUB
@ NONE
@ IMPL
static void test_optional_stub(void)
static void test_optional(void)
ast_optional_fn test_optional_ref
static void test_optional_impl(void)
#define CATEGORY
#define SYMNAME
enum was_called was_called_result
static int load_module(void)
static int unload_module(void)
AST_TEST_DEFINE(test_provide_first)