| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
#include "asterisk.h" |
| 43 |
|
| 44 |
#include "asterisk/module.h" |
| 45 |
#include "asterisk/utils.h" |
| 46 |
#include "asterisk/test.h" |
| 47 |
#include "asterisk/event.h" |
| 48 |
|
| 49 |
static int check_event(struct ast_event *event, struct ast_test *test, |
| 50 |
enum ast_event_type expected_type, const char *type_name, |
| 51 |
const char *str, uint32_t uint) |
| 52 |
{ |
| 53 |
enum ast_event_type type; |
| 54 |
const void *foo; |
| 55 |
|
| 56 |
|
| 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 |
|
| 65 |
if (strcmp(str, ast_event_get_ie_str(event, AST_EVENT_IE_CEL_USEREVENT_NAME))) { |
| 66 |
ast_test_status_update(test, "Failed to get string IE.\n"); |
| 67 |
return -1; |
| 68 |
} |
| 69 |
|
| 70 |
|
| 71 |
if (uint != ast_event_get_ie_uint(event, AST_EVENT_IE_CEL_AMAFLAGS)) { |
| 72 |
ast_test_status_update(test, "Failed to get uint IE.\n"); |
| 73 |
return -1; |
| 74 |
} |
| 75 |
|
| 76 |
|
| 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 |
|
| 83 |
if (ast_event_get_ie_uint(event, AST_EVENT_IE_CEL_EVENT_TIME_USEC)) { |
| 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 |
} |
| 92 |
|
| 93 |
|
| 94 |
|
| 95 |
|
| 96 |
AST_TEST_DEFINE(event_new_test) |
| 97 |
{ |
| 98 |
enum ast_test_result_state res = AST_TEST_PASS; |
| 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 |
|
| 120 |
|
| 121 |
|
| 122 |
|
| 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 |
|
| 133 |
if (ast_event_append_ie_str(&event, AST_EVENT_IE_CEL_USEREVENT_NAME, str)) { |
| 134 |
ast_test_status_update(test, "Failed to append str IE\n"); |
| 135 |
res = AST_TEST_FAIL; |
| 136 |
goto return_cleanup; |
| 137 |
} |
| 138 |
|
| 139 |
if (ast_event_append_ie_uint(&event, AST_EVENT_IE_CEL_AMAFLAGS, uint)) { |
| 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, |
| 152 |
AST_EVENT_IE_CEL_USEREVENT_NAME, AST_EVENT_IE_PLTYPE_STR, str, |
| 153 |
AST_EVENT_IE_CEL_AMAFLAGS, AST_EVENT_IE_PLTYPE_UINT, uint, |
| 154 |
AST_EVENT_IE_END); |
| 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) { |
| 178 |
ast_event_destroy(event); |
| 179 |
event = NULL; |
| 180 |
} |
| 181 |
|
| 182 |
if (event2) { |
| 183 |
ast_event_destroy(event2); |
| 184 |
event2 = NULL; |
| 185 |
} |
| 186 |
|
| 187 |
return res; |
| 188 |
} |
| 189 |
|
| 190 |
struct event_sub_data { |
| 191 |
unsigned int count; |
| 192 |
}; |
| 193 |
|
| 194 |
static int unload_module(void) |
| 195 |
{ |
| 196 |
AST_TEST_UNREGISTER(event_new_test); |
| 197 |
|
| 198 |
return 0; |
| 199 |
} |
| 200 |
|
| 201 |
static int load_module(void) |
| 202 |
{ |
| 203 |
AST_TEST_REGISTER(event_new_test); |
| 204 |
|
| 205 |
return AST_MODULE_LOAD_SUCCESS; |
| 206 |
} |
| 207 |
|
| 208 |
AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "ast_event API Tests"); |