Asterisk - The Open Source Telephony Project  18.5.0
Data Structures | Functions | Variables
test_event.c File Reference

Tests for the ast_event API. More...

#include "asterisk.h"
#include "asterisk/module.h"
#include "asterisk/utils.h"
#include "asterisk/test.h"
#include "asterisk/event.h"
Include dependency graph for test_event.c:

Go to the source code of this file.

Data Structures

struct  event_sub_data
 

Functions

static void __reg_module (void)
 
static void __unreg_module (void)
 
struct ast_moduleAST_MODULE_SELF_SYM (void)
 
 AST_TEST_DEFINE (event_new_test)
 
static int check_event (struct ast_event *event, struct ast_test *test, enum ast_event_type expected_type, const char *type_name, const char *str, uint32_t uint)
 
static int load_module (void)
 
static int unload_module (void)
 

Variables

static struct ast_module_info __mod_info = { .name = AST_MODULE, .flags = AST_MODFLAG_LOAD_ORDER , .description = "ast_event API Tests" , .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, .load = load_module, .unload = unload_module, .load_pri = AST_MODPRI_DEFAULT, .support_level = AST_MODULE_SUPPORT_CORE, }
 
static const struct ast_module_infoast_module_info = &__mod_info
 

Detailed Description

Tests for the ast_event API.

Author
Russell Bryant russe.nosp@m.ll@d.nosp@m.igium.nosp@m..com
Todo:
API Calls not yet touched by a test: XXX TODO

Definition in file test_event.c.

Function Documentation

◆ __reg_module()

static void __reg_module ( void  )
static

Definition at line 208 of file test_event.c.

◆ __unreg_module()

static void __unreg_module ( void  )
static

Definition at line 208 of file test_event.c.

◆ AST_MODULE_SELF_SYM()

struct ast_module* AST_MODULE_SELF_SYM ( void  )

Definition at line 208 of file test_event.c.

◆ AST_TEST_DEFINE()

AST_TEST_DEFINE ( event_new_test  )

Definition at line 96 of file test_event.c.

References ast_event_append_ie_str(), ast_event_append_ie_uint(), AST_EVENT_CUSTOM, ast_event_destroy(), ast_event_get_size(), AST_EVENT_IE_CEL_AMAFLAGS, AST_EVENT_IE_CEL_USEREVENT_NAME, AST_EVENT_IE_END, AST_EVENT_IE_PLTYPE_STR, AST_EVENT_IE_PLTYPE_UINT, ast_event_new(), AST_TEST_FAIL, AST_TEST_NOT_RUN, AST_TEST_PASS, ast_test_status_update, check_event(), sip_to_pjsip::info(), NULL, str, TEST_EXECUTE, TEST_INIT, and type.

97 {
99  struct ast_event *event = NULL, *event2 = NULL;
100 
101  static const enum ast_event_type type = AST_EVENT_CUSTOM;
102  static const char str[] = "SIP/alligatormittens";
103  static const uint32_t uint = 0xb00bface;
104 
105  switch (cmd) {
106  case TEST_INIT:
107  info->name = "ast_event_new_test";
108  info->category = "/main/event/";
109  info->summary = "Test event creation";
110  info->description =
111  "This test exercises the API calls that allow allocation "
112  "of an ast_event.";
113  return AST_TEST_NOT_RUN;
114  case TEST_EXECUTE:
115  break;
116  }
117 
118  /*
119  * Test 2 methods of event creation:
120  *
121  * 1) Dynamic via appending each IE individually.
122  * 2) Statically, with all IEs in ast_event_new().
123  */
124 
125  ast_test_status_update(test, "First, test dynamic event creation...\n");
126 
127  if (!(event = ast_event_new(type, AST_EVENT_IE_END))) {
128  ast_test_status_update(test, "Failed to allocate ast_event object.\n");
129  res = AST_TEST_FAIL;
130  goto return_cleanup;
131  }
132 
134  ast_test_status_update(test, "Failed to append str IE\n");
135  res = AST_TEST_FAIL;
136  goto return_cleanup;
137  }
138 
140  ast_test_status_update(test, "Failed to append uint IE\n");
141  res = AST_TEST_FAIL;
142  goto return_cleanup;
143  }
144 
145  if (check_event(event, test, type, "Custom", str, uint)) {
146  ast_test_status_update(test, "Dynamically generated event broken\n");
147  res = AST_TEST_FAIL;
148  goto return_cleanup;
149  }
150 
151  event2 = ast_event_new(type,
155 
156  if (!event2) {
157  ast_test_status_update(test, "Failed to allocate ast_event object.\n");
158  res = AST_TEST_FAIL;
159  goto return_cleanup;
160  }
161 
162  if (check_event(event2, test, type, "Custom", str, uint)) {
163  ast_test_status_update(test, "Statically generated event broken\n");
164  res = AST_TEST_FAIL;
165  goto return_cleanup;
166  }
167 
168  if (ast_event_get_size(event) != ast_event_get_size(event2)) {
169  ast_test_status_update(test, "Events expected to be identical have different size: %d != %d\n",
170  (int) ast_event_get_size(event),
171  (int) ast_event_get_size(event2));
172  res = AST_TEST_FAIL;
173  goto return_cleanup;
174  }
175 
176 return_cleanup:
177  if (event) {
179  event = NULL;
180  }
181 
182  if (event2) {
183  ast_event_destroy(event2);
184  event2 = NULL;
185  }
186 
187  return res;
188 }
static const char type[]
Definition: chan_ooh323.c:109
An event.
Definition: event.c:81
Definition: astman.c:222
const char * str
Definition: app_jack.c:147
#define NULL
Definition: resample.c:96
static int check_event(struct ast_event *event, struct ast_test *test, enum ast_event_type expected_type, const char *type_name, const char *str, uint32_t uint)
Definition: test_event.c:49
ast_event_type
Definition: event_defs.h:28
#define ast_test_status_update(a, b, c...)
Definition: test.h:129
Channel Event User Event Name Used by: AST_EVENT_CEL Payload type: STR.
Definition: event_defs.h:151
def info(msg)
int ast_event_append_ie_str(struct ast_event **event, enum ast_event_ie_type ie_type, const char *str)
Append an information element that has a string payload.
Definition: event.c:345
Channel Event AMA flags Used by: AST_EVENT_CEL Payload type: UINT.
Definition: event_defs.h:199
void ast_event_destroy(struct ast_event *event)
Destroy an event.
Definition: event.c:524
struct ast_event * ast_event_new(enum ast_event_type event_type,...)
Create a new event.
Definition: event.c:402
size_t ast_event_get_size(const struct ast_event *event)
Get the size of an event.
Definition: event.c:228
ast_test_result_state
Definition: test.h:200
int ast_event_append_ie_uint(struct ast_event **event, enum ast_event_ie_type ie_type, uint32_t data)
Append an information element that has an integer payload.
Definition: event.c:360

◆ check_event()

static int check_event ( struct ast_event event,
struct ast_test test,
enum ast_event_type  expected_type,
const char *  type_name,
const char *  str,
uint32_t  uint 
)
static

Definition at line 49 of file test_event.c.

References ast_event_get_ie_str(), ast_event_get_ie_uint(), ast_event_get_type(), AST_EVENT_IE_CEL_AMAFLAGS, AST_EVENT_IE_CEL_CIDNAME, AST_EVENT_IE_CEL_EVENT_TIME_USEC, AST_EVENT_IE_CEL_USEREVENT_NAME, ast_test_status_update, and type.

Referenced by AST_TEST_DEFINE().

52 {
53  enum ast_event_type type;
54  const void *foo;
55 
56  /* Check #1: Ensure event type is set properly. */
57  type = ast_event_get_type(event);
58  if (ast_event_get_type(event) != type) {
59  ast_test_status_update(test, "Expected event type: '%u', got '%u'\n",
60  expected_type, type);
61  return -1;
62  }
63 
64  /* Check #4: Check for the string IE */
66  ast_test_status_update(test, "Failed to get string IE.\n");
67  return -1;
68  }
69 
70  /* Check #5: Check for the uint IE */
72  ast_test_status_update(test, "Failed to get uint IE.\n");
73  return -1;
74  }
75 
76  /* Check #6: Check if a check for a str IE that isn't there works */
77  if ((foo = ast_event_get_ie_str(event, AST_EVENT_IE_CEL_CIDNAME))) {
78  ast_test_status_update(test, "CEL_CIDNAME IE check returned non-NULL %p\n", foo);
79  return -1;
80  }
81 
82  /* Check #7: Check if a check for a uint IE that isn't there returns 0 */
84  ast_test_status_update(test, "UNIQUEID IE should be 0\n");
85  return -1;
86  }
87 
88  ast_test_status_update(test, "Event looks good.\n");
89 
90  return 0;
91 }
static const char type[]
Definition: chan_ooh323.c:109
Channel Event CID name Used by: AST_EVENT_CEL Payload type: STR.
Definition: event_defs.h:157
enum ast_event_type ast_event_get_type(const struct ast_event *event)
Get the type for an event.
Definition: event.c:288
Channel Event Time (micro-seconds) Used by: AST_EVENT_CEL Payload type: UINT.
Definition: event_defs.h:145
const char * str
Definition: app_jack.c:147
ast_event_type
Definition: event_defs.h:28
#define ast_test_status_update(a, b, c...)
Definition: test.h:129
Channel Event User Event Name Used by: AST_EVENT_CEL Payload type: STR.
Definition: event_defs.h:151
Channel Event AMA flags Used by: AST_EVENT_CEL Payload type: UINT.
Definition: event_defs.h:199
uint32_t ast_event_get_ie_uint(const struct ast_event *event, enum ast_event_ie_type ie_type)
Get the value of an information element that has an integer payload.
Definition: event.c:293
const char * ast_event_get_ie_str(const struct ast_event *event, enum ast_event_ie_type ie_type)
Get the value of an information element that has a string payload.
Definition: event.c:302

◆ load_module()

static int load_module ( void  )
static

Definition at line 201 of file test_event.c.

References AST_MODULE_LOAD_SUCCESS, and AST_TEST_REGISTER.

202 {
203  AST_TEST_REGISTER(event_new_test);
204 
206 }
#define AST_TEST_REGISTER(cb)
Definition: test.h:127

◆ unload_module()

static int unload_module ( void  )
static

Definition at line 194 of file test_event.c.

References AST_TEST_UNREGISTER.

195 {
196  AST_TEST_UNREGISTER(event_new_test);
197 
198  return 0;
199 }
#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_LOAD_ORDER , .description = "ast_event API Tests" , .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, .load = load_module, .unload = unload_module, .load_pri = AST_MODPRI_DEFAULT, .support_level = AST_MODULE_SUPPORT_CORE, }
static

Definition at line 208 of file test_event.c.

◆ ast_module_info

const struct ast_module_info* ast_module_info = &__mod_info
static

Definition at line 208 of file test_event.c.