Asterisk - The Open Source Telephony Project  18.5.0
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. Acutal usage won't look anything like this; it would use the wrapper macros.

Author
David M. Lee, II <[email protected]> 

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.

Referenced by AST_TEST_DEFINE().

◆ SYMNAME

#define SYMNAME   "test_option"

Definition at line 73 of file test_optional_api.c.

Referenced by AST_TEST_DEFINE().

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 };

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.

References AST_MODULE, ast_optional_api_provide(), ast_optional_api_unprovide(), ast_optional_api_unuse(), ast_optional_api_use(), 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.

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 
94 
96  AST_MODULE);
97 
98  test_optional();
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:
111  return res;
112 }
ast_optional_fn test_optional_ref
void ast_optional_api_provide(const char *symname, ast_optional_fn impl)
Definition: optional_api.c:212
#define SYMNAME
enum was_called was_called_result
int done
Definition: test_amihooks.c:48
#define ast_test_status_update(a, b, c...)
Definition: test.h:129
static void test_optional(void)
void ast_optional_api_unprovide(const char *symname, ast_optional_fn impl)
Definition: optional_api.c:222
static void test_optional_stub(void)
def info(msg)
void ast_optional_api_use(const char *symname, ast_optional_fn *optional_ref, ast_optional_fn stub, const char *module)
Definition: optional_api.c:232
void ast_optional_api_unuse(const char *symname, ast_optional_fn *optional_ref, const char *module)
Definition: optional_api.c:257
#define CATEGORY
#define AST_MODULE
static void test_optional_impl(void)
ast_test_result_state
Definition: test.h:200

◆ AST_TEST_DEFINE() [2/2]

AST_TEST_DEFINE ( test_provide_last  )

Definition at line 114 of file test_optional_api.c.

References AST_MODULE, ast_optional_api_provide(), ast_optional_api_unprovide(), ast_optional_api_unuse(), ast_optional_api_use(), 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.

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;
130  test_optional_ref = 0;
131 
133  AST_MODULE);
134 
135  test_optional();
136  if (was_called_result != STUB) {
137  ast_test_status_update(test, "Expected %d, was %u",
139  goto done;
140  }
141 
143 
144  test_optional();
145  if (was_called_result != IMPL) {
146  ast_test_status_update(test, "Expected %d, was %u",
149  goto done;
150  }
151 
153 
154  test_optional();
155  if (was_called_result != STUB) {
156  ast_test_status_update(test, "Expected %d, was %u",
159  goto done;
160  }
161 
162  res = AST_TEST_PASS;
163 
164  done:
166  return res;
167 }
ast_optional_fn test_optional_ref
void ast_optional_api_provide(const char *symname, ast_optional_fn impl)
Definition: optional_api.c:212
#define SYMNAME
enum was_called was_called_result
int done
Definition: test_amihooks.c:48
#define ast_test_status_update(a, b, c...)
Definition: test.h:129
static void test_optional(void)
void ast_optional_api_unprovide(const char *symname, ast_optional_fn impl)
Definition: optional_api.c:222
static void test_optional_stub(void)
def info(msg)
void ast_optional_api_use(const char *symname, ast_optional_fn *optional_ref, ast_optional_fn stub, const char *module)
Definition: optional_api.c:232
void ast_optional_api_unuse(const char *symname, ast_optional_fn *optional_ref, const char *module)
Definition: optional_api.c:257
#define CATEGORY
#define AST_MODULE
static void test_optional_impl(void)
ast_test_result_state
Definition: test.h:200

◆ load_module()

static int load_module ( void  )
static

Definition at line 176 of file test_optional_api.c.

References AST_MODFLAG_DEFAULT, AST_MODULE_INFO(), AST_MODULE_LOAD_SUCCESS, AST_MODULE_SUPPORT_CORE, AST_TEST_REGISTER, ASTERISK_GPL_KEY, and unload_module().

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

◆ test_optional()

static void test_optional ( void  )
static

Definition at line 65 of file test_optional_api.c.

References NONE, test_optional_ref, and was_called_result.

Referenced by AST_TEST_DEFINE().

66 {
68  if (test_optional_ref) {
70  }
71 }
ast_optional_fn test_optional_ref
enum was_called was_called_result

◆ test_optional_impl()

static void test_optional_impl ( void  )
static

Definition at line 60 of file test_optional_api.c.

References IMPL, and was_called_result.

Referenced by AST_TEST_DEFINE().

61 {
63 }
enum was_called was_called_result

◆ test_optional_stub()

static void test_optional_stub ( void  )
static

Definition at line 55 of file test_optional_api.c.

References STUB, and was_called_result.

Referenced by AST_TEST_DEFINE().

56 {
58 }
enum was_called was_called_result

◆ unload_module()

static int unload_module ( void  )
static

Definition at line 169 of file test_optional_api.c.

References AST_TEST_UNREGISTER.

Referenced by load_module().

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

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