Asterisk - The Open Source Telephony Project GIT-master-7e7a603
Macros | Enumerations | Functions | Variables
test_optional_api.c File Reference

Test optional API. More...

#include "asterisk.h"
#include "asterisk/module.h"
#include "asterisk/optional_api.h"
#include "asterisk/test.h"
Include dependency graph for test_optional_api.c:

Go to the source code of this file.

Macros

#define CATEGORY   "/main/optional_api/"
 
#define SYMNAME   "test_option"
 

Enumerations

enum  was_called { NONE , STUB , IMPL }
 

Functions

static void __reg_module (void)
 
static void __unreg_module (void)
 
struct ast_moduleAST_MODULE_SELF_SYM (void)
 
 AST_TEST_DEFINE (test_provide_first)
 
 AST_TEST_DEFINE (test_provide_last)
 
static int load_module (void)
 
static void test_optional (void)
 
static void test_optional_impl (void)
 
static void test_optional_stub (void)
 
static int unload_module (void)
 

Variables

static struct ast_module_info __mod_info = { .name = AST_MODULE, .flags = AST_MODFLAG_DEFAULT , .description = "ARI testing" , .key = "This paragraph is copyright (c) 2006 by Digium, Inc. \In order for your module to load, it must return this \key via a function called \"key\". Any code which \includes this paragraph must be licensed under the GNU \General Public License version 2 or later (at your \option). In addition to Digium's general reservations \of rights, Digium expressly reserves the right to \allow other parties to license this paragraph under \different terms. Any use of Digium, Inc. trademarks or \logos (including \"Asterisk\" or \"Digium\") without \express written permission of Digium, Inc. is prohibited.\n" , .buildopt_sum = AST_BUILDOPT_SUM, .support_level = AST_MODULE_SUPPORT_CORE, .load = load_module, .unload = unload_module, }
 
static const struct ast_module_infoast_module_info = &__mod_info
 
ast_optional_fn test_optional_ref
 
enum was_called was_called_result
 

Detailed Description

Test optional API.

This tests exercise the underlying implementation functions. Actual usage won't look anything like this; it would use the wrapper macros.

Author
David M. Lee, II <dlee@digium.com> 

Definition in file test_optional_api.c.

Macro Definition Documentation

◆ CATEGORY

#define CATEGORY   "/main/optional_api/"

Definition at line 43 of file test_optional_api.c.

◆ SYMNAME

#define SYMNAME   "test_option"

Definition at line 73 of file test_optional_api.c.

Enumeration Type Documentation

◆ was_called

enum was_called
Enumerator
NONE 
STUB 
IMPL 

Definition at line 45 of file test_optional_api.c.

45 {
46 NONE,
47 STUB,
48 IMPL
49};
@ STUB
@ NONE
@ IMPL

Function Documentation

◆ __reg_module()

static void __reg_module ( void  )
static

Definition at line 187 of file test_optional_api.c.

◆ __unreg_module()

static void __unreg_module ( void  )
static

Definition at line 187 of file test_optional_api.c.

◆ AST_MODULE_SELF_SYM()

struct ast_module * AST_MODULE_SELF_SYM ( void  )

Definition at line 187 of file test_optional_api.c.

◆ AST_TEST_DEFINE() [1/2]

AST_TEST_DEFINE ( test_provide_first  )

Definition at line 75 of file test_optional_api.c.

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}
#define AST_MODULE
def info(msg)
@ TEST_INIT
Definition: test.h:200
@ TEST_EXECUTE
Definition: test.h:201
#define ast_test_status_update(a, b, c...)
Definition: test.h:129
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
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

References AST_MODULE, AST_TEST_FAIL, AST_TEST_NOT_RUN, AST_TEST_PASS, ast_test_status_update, CATEGORY, done, IMPL, sip_to_pjsip::info(), SYMNAME, TEST_EXECUTE, TEST_INIT, test_optional(), test_optional_impl(), test_optional_ref, test_optional_stub(), and was_called_result.

◆ AST_TEST_DEFINE() [2/2]

AST_TEST_DEFINE ( test_provide_last  )

Definition at line 114 of file test_optional_api.c.

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}

References AST_MODULE, AST_TEST_FAIL, AST_TEST_NOT_RUN, AST_TEST_PASS, ast_test_status_update, CATEGORY, done, IMPL, sip_to_pjsip::info(), STUB, SYMNAME, TEST_EXECUTE, TEST_INIT, test_optional(), test_optional_impl(), test_optional_ref, test_optional_stub(), and was_called_result.

◆ load_module()

static int load_module ( void  )
static

Definition at line 176 of file test_optional_api.c.

177{
178 AST_TEST_REGISTER(test_provide_first);
179 AST_TEST_REGISTER(test_provide_last);
181}
@ AST_MODULE_LOAD_SUCCESS
Definition: module.h:70
#define AST_TEST_REGISTER(cb)
Definition: test.h:127

References AST_MODULE_LOAD_SUCCESS, and AST_TEST_REGISTER.

◆ test_optional()

static void test_optional ( void  )
static

Definition at line 65 of file test_optional_api.c.

66{
70 }
71}

References NONE, test_optional_ref, and was_called_result.

Referenced by AST_TEST_DEFINE().

◆ test_optional_impl()

static void test_optional_impl ( void  )
static

Definition at line 60 of file test_optional_api.c.

61{
63}

References IMPL, and was_called_result.

Referenced by AST_TEST_DEFINE().

◆ test_optional_stub()

static void test_optional_stub ( void  )
static

Definition at line 55 of file test_optional_api.c.

56{
58}

References STUB, and was_called_result.

Referenced by AST_TEST_DEFINE().

◆ unload_module()

static int unload_module ( void  )
static

Definition at line 169 of file test_optional_api.c.

170{
171 AST_TEST_UNREGISTER(test_provide_first);
172 AST_TEST_UNREGISTER(test_provide_last);
173 return 0;
174}
#define AST_TEST_UNREGISTER(cb)
Definition: test.h:128

References AST_TEST_UNREGISTER.

Variable Documentation

◆ __mod_info

struct ast_module_info __mod_info = { .name = AST_MODULE, .flags = AST_MODFLAG_DEFAULT , .description = "ARI testing" , .key = "This paragraph is copyright (c) 2006 by Digium, Inc. \In order for your module to load, it must return this \key via a function called \"key\". Any code which \includes this paragraph must be licensed under the GNU \General Public License version 2 or later (at your \option). In addition to Digium's general reservations \of rights, Digium expressly reserves the right to \allow other parties to license this paragraph under \different terms. Any use of Digium, Inc. trademarks or \logos (including \"Asterisk\" or \"Digium\") without \express written permission of Digium, Inc. is prohibited.\n" , .buildopt_sum = AST_BUILDOPT_SUM, .support_level = AST_MODULE_SUPPORT_CORE, .load = load_module, .unload = unload_module, }
static

Definition at line 187 of file test_optional_api.c.

◆ ast_module_info

const struct ast_module_info* ast_module_info = &__mod_info
static

Definition at line 187 of file test_optional_api.c.

◆ test_optional_ref

ast_optional_fn test_optional_ref

Definition at line 53 of file test_optional_api.c.

Referenced by AST_TEST_DEFINE(), and test_optional().

◆ was_called_result

enum was_called was_called_result