Asterisk - The Open Source Telephony Project GIT-master-b023714
|
Test module for out-of-call text message module. More...
#include "asterisk.h"
#include <regex.h>
#include "asterisk/module.h"
#include "asterisk/test.h"
#include "asterisk/message.h"
#include "asterisk/pbx.h"
#include "asterisk/manager.h"
#include "asterisk/vector.h"
Go to the source code of this file.
Data Structures | |
struct | var_vector |
The expected user event fields. More... | |
Macros | |
#define | DEFAULT_EXPECTED_EVENTS 4 |
The number of user events we should get in a dialplan test. | |
#define | FREE_VARIABLE_VECTOR(vector) |
#define | TEST_CATEGORY "/main/message/" |
#define | TEST_CONTEXT "__TEST_MESSAGE_CONTEXT__" |
#define | TEST_EXTENSION "test_message_extension" |
Functions | |
static void | __reg_module (void) |
static void | __unreg_module (void) |
struct ast_module * | AST_MODULE_SELF_SYM (void) |
static void | ast_msg_safe_destroy (void *obj) |
AST_TEST_DEFINE (test_message_has_destination_dialplan) | |
AST_TEST_DEFINE (test_message_has_destination_handler) | |
AST_TEST_DEFINE (test_message_manipulation) | |
AST_TEST_DEFINE (test_message_msg_handler_registration) | |
AST_TEST_DEFINE (test_message_msg_send) | |
AST_TEST_DEFINE (test_message_msg_tech_registration) | |
AST_TEST_DEFINE (test_message_queue_both_nominal) | |
AST_TEST_DEFINE (test_message_queue_dialplan_nominal) | |
AST_TEST_DEFINE (test_message_queue_handler_nominal) | |
static int | create_test_dialplan (void) |
static int | handler_wait_for_message (struct ast_test *test) |
Wait for the test_msg_handler to receive the message. | |
static int | load_module (void) |
static int | test_cleanup_cb (struct ast_test_info *info, struct ast_test *test) |
static int | test_init_cb (struct ast_test_info *info, struct ast_test *test) |
static int | test_msg_handle_msg_cb (struct ast_msg *msg) |
static int | test_msg_has_destination_cb (const struct ast_msg *msg) |
static int | test_msg_send (const struct ast_msg *msg, const char *to, const char *from) |
static int | unload_module (void) |
static int | user_event_hook_cb (int category, const char *event, char *body) |
static int | user_event_wait_for_events (struct ast_test *test, int expected_events) |
Wait for the expected number of user events to be received. | |
static int | verify_bad_headers (struct ast_test *test) |
static int | verify_user_event_fields (int user_event, const char *header, const char *value) |
Verifies a user event header/value pair. | |
Variables | ||
static struct ast_module_info | __mod_info = { .name = AST_MODULE, .flags = AST_MODFLAG_LOAD_ORDER , .description = "Out-of-call text message support" , .key = ASTERISK_GPL_KEY , .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_info * | ast_module_info = &__mod_info | |
struct { | ||
size_t current | ||
struct ast_variable ** elems | ||
size_t max | ||
} | bad_headers | |
If a user event fails, the bad headers that didn't match. | ||
struct var_vector | expected_user_event_fields | |
static int | expected_user_events | |
The number of user events we expect for this test. | ||
static ast_cond_t | handler_cond | |
Condition wait variable for test_msg_handler receiving message. | ||
static ast_mutex_t | handler_lock = AST_MUTEX_INIT_VALUE | |
Mutex for handler_cond . | ||
static int | handler_received_message | |
Predicate for the test_msg_handler receiving a message. | ||
static int | message_received | |
static int | received_user_events | |
The current number of received user events. | ||
static struct ast_msg_handler | test_msg_handler | |
Our test message handler. | ||
static struct ast_msg_tech | test_msg_tech | |
static ast_cond_t | user_event_cond | |
Condition wait variable for all dialplan user events being received. | ||
static struct manager_custom_hook | user_event_hook | |
AMI event hook that verifies whether or not we've gotten our user events. | ||
static ast_mutex_t | user_event_lock = AST_MUTEX_INIT_VALUE | |
Mutex for user_event_cond . | ||
Test module for out-of-call text message module.
Definition in file test_message.c.
#define DEFAULT_EXPECTED_EVENTS 4 |
The number of user events we should get in a dialplan test.
Definition at line 50 of file test_message.c.
#define FREE_VARIABLE_VECTOR | ( | vector | ) |
Definition at line 787 of file test_message.c.
#define TEST_CATEGORY "/main/message/" |
Definition at line 44 of file test_message.c.
#define TEST_CONTEXT "__TEST_MESSAGE_CONTEXT__" |
Definition at line 46 of file test_message.c.
#define TEST_EXTENSION "test_message_extension" |
Definition at line 47 of file test_message.c.
|
static |
Definition at line 881 of file test_message.c.
|
static |
Definition at line 881 of file test_message.c.
struct ast_module * AST_MODULE_SELF_SYM | ( | void | ) |
Definition at line 881 of file test_message.c.
|
static |
Definition at line 365 of file test_message.c.
References ast_msg_destroy().
Referenced by AST_TEST_DEFINE(), AST_TEST_DEFINE(), AST_TEST_DEFINE(), AST_TEST_DEFINE(), AST_TEST_DEFINE(), AST_TEST_DEFINE(), and AST_TEST_DEFINE().
AST_TEST_DEFINE | ( | test_message_has_destination_dialplan | ) |
Definition at line 652 of file test_message.c.
References ast_msg_alloc(), ast_msg_has_destination(), ast_msg_safe_destroy(), ast_msg_set_context(), ast_msg_set_exten(), AST_TEST_NOT_RUN, AST_TEST_PASS, NULL, RAII_VAR, TEST_CATEGORY, TEST_CONTEXT, TEST_EXECUTE, TEST_EXTENSION, and TEST_INIT.
AST_TEST_DEFINE | ( | test_message_has_destination_handler | ) |
Definition at line 693 of file test_message.c.
References ast_msg_alloc(), ast_msg_handler_register(), ast_msg_handler_unregister(), ast_msg_has_destination(), ast_msg_safe_destroy(), ast_msg_set_context(), ast_msg_set_exten(), ast_msg_set_to(), AST_TEST_NOT_RUN, AST_TEST_PASS, NULL, RAII_VAR, result, TEST_CATEGORY, TEST_CONTEXT, TEST_EXECUTE, TEST_INIT, and test_msg_handler.
AST_TEST_DEFINE | ( | test_message_manipulation | ) |
Definition at line 374 of file test_message.c.
References ast_msg_alloc(), ast_msg_get_body(), ast_msg_get_endpoint(), ast_msg_get_from(), ast_msg_get_tech(), ast_msg_get_to(), ast_msg_get_var(), ast_msg_safe_destroy(), ast_msg_set_body(), ast_msg_set_endpoint(), ast_msg_set_from(), ast_msg_set_tech(), ast_msg_set_to(), ast_msg_set_var(), ast_msg_set_var_outbound(), ast_msg_var_iterator_destroy(), ast_msg_var_iterator_init(), ast_msg_var_iterator_next(), ast_msg_var_unref_current(), AST_TEST_NOT_RUN, AST_TEST_PASS, NULL, RAII_VAR, result, TEST_CATEGORY, TEST_EXECUTE, and TEST_INIT.
AST_TEST_DEFINE | ( | test_message_msg_handler_registration | ) |
Definition at line 332 of file test_message.c.
References ast_msg_handler_register(), ast_msg_handler_unregister(), AST_TEST_NOT_RUN, AST_TEST_PASS, TEST_CATEGORY, TEST_EXECUTE, TEST_INIT, and test_msg_handler.
AST_TEST_DEFINE | ( | test_message_msg_send | ) |
Definition at line 734 of file test_message.c.
References ast_msg_alloc(), ast_msg_handler_register(), ast_msg_handler_unregister(), ast_msg_has_destination(), ast_msg_safe_destroy(), ast_msg_send(), ast_msg_set_context(), ast_msg_set_exten(), ast_msg_set_to(), ast_msg_tech_register(), ast_msg_tech_unregister(), AST_TEST_FAIL, AST_TEST_NOT_RUN, AST_TEST_PASS, ast_test_status_update, NULL, RAII_VAR, TEST_CATEGORY, TEST_CONTEXT, TEST_EXECUTE, TEST_INIT, test_msg_handler, and test_msg_tech.
AST_TEST_DEFINE | ( | test_message_msg_tech_registration | ) |
Definition at line 299 of file test_message.c.
References ast_msg_tech_register(), ast_msg_tech_unregister(), AST_TEST_NOT_RUN, AST_TEST_PASS, TEST_CATEGORY, TEST_EXECUTE, TEST_INIT, and test_msg_tech.
AST_TEST_DEFINE | ( | test_message_queue_both_nominal | ) |
Definition at line 577 of file test_message.c.
References ast_msg_alloc(), ast_msg_handler_register(), ast_msg_handler_unregister(), ast_msg_queue(), ast_msg_safe_destroy(), ast_msg_set_body(), ast_msg_set_context(), ast_msg_set_exten(), ast_msg_set_from(), ast_msg_set_to(), AST_TEST_FAIL, AST_TEST_NOT_RUN, AST_TEST_PASS, ast_test_status_update, ast_variable_list_append, ast_variable_new, AST_VECTOR_REPLACE, DEFAULT_EXPECTED_EVENTS, expected_user_event_fields, handler_wait_for_message(), NULL, RAII_VAR, result, TEST_CATEGORY, TEST_CONTEXT, TEST_EXECUTE, TEST_EXTENSION, TEST_INIT, test_msg_handler, user_event_wait_for_events(), and verify_bad_headers().
AST_TEST_DEFINE | ( | test_message_queue_dialplan_nominal | ) |
Definition at line 465 of file test_message.c.
References ast_msg_alloc(), ast_msg_queue(), ast_msg_safe_destroy(), ast_msg_set_body(), ast_msg_set_context(), ast_msg_set_exten(), ast_msg_set_from(), ast_msg_set_to(), ast_msg_set_var_outbound(), AST_TEST_FAIL, AST_TEST_NOT_RUN, AST_TEST_PASS, ast_test_status_update, ast_variable_list_append, ast_variable_new, AST_VECTOR_REPLACE, DEFAULT_EXPECTED_EVENTS, expected_user_event_fields, NULL, RAII_VAR, TEST_CATEGORY, TEST_CONTEXT, TEST_EXECUTE, TEST_EXTENSION, TEST_INIT, user_event_wait_for_events(), and verify_bad_headers().
AST_TEST_DEFINE | ( | test_message_queue_handler_nominal | ) |
Definition at line 537 of file test_message.c.
References ast_msg_alloc(), ast_msg_handler_register(), ast_msg_handler_unregister(), ast_msg_queue(), ast_msg_safe_destroy(), ast_msg_set_body(), ast_msg_set_from(), ast_msg_set_to(), AST_TEST_NOT_RUN, AST_TEST_PASS, handler_wait_for_message(), NULL, RAII_VAR, result, TEST_CATEGORY, TEST_EXECUTE, TEST_INIT, and test_msg_handler.
|
static |
Definition at line 828 of file test_message.c.
References ast_add_extension(), ast_context_find_or_create(), ast_manager_register_hook(), AST_MODULE, NULL, TEST_CONTEXT, TEST_EXTENSION, and user_event_hook.
Referenced by load_module().
|
static |
Wait for the test_msg_handler to receive the message.
Definition at line 230 of file test_message.c.
References ast_cond_timedwait, ast_mutex_lock, ast_mutex_unlock, AST_TEST_FAIL, ast_test_status_update, ast_tv(), ast_tvadd(), ast_tvnow(), error(), handler_cond, handler_lock, and handler_received_message.
Referenced by AST_TEST_DEFINE(), and AST_TEST_DEFINE().
|
static |
Definition at line 860 of file test_message.c.
References AST_MODULE_LOAD_SUCCESS, AST_TEST_REGISTER, create_test_dialplan(), TEST_CATEGORY, test_cleanup_cb(), and test_init_cb().
|
static |
Definition at line 801 of file test_message.c.
References bad_headers, expected_user_event_fields, and FREE_VARIABLE_VECTOR.
Referenced by load_module().
|
static |
Definition at line 775 of file test_message.c.
References AST_VECTOR_INIT, bad_headers, DEFAULT_EXPECTED_EVENTS, expected_user_event_fields, handler_received_message, message_received, and received_user_events.
Referenced by load_module().
|
static |
Definition at line 177 of file test_message.c.
References ast_cond_signal, ast_mutex_lock, ast_mutex_unlock, handler_cond, handler_lock, and handler_received_message.
|
static |
Definition at line 187 of file test_message.c.
References ast_msg_get_to(), and ast_strlen_zero().
|
static |
Definition at line 170 of file test_message.c.
References message_received.
|
static |
Definition at line 809 of file test_message.c.
References ast_context_destroy(), ast_manager_unregister_hook(), AST_MODULE, AST_TEST_UNREGISTER, NULL, and user_event_hook.
|
static |
Definition at line 196 of file test_message.c.
References ast_cond_signal, ast_mutex_lock, ast_mutex_unlock, ast_skip_blanks(), ast_strdupa, ast_strlen_zero(), ast_trim_blanks(), expected_user_events, received_user_events, strsep(), user_event_cond, user_event_lock, value, and verify_user_event_fields().
|
static |
Wait for the expected number of user events to be received.
Definition at line 251 of file test_message.c.
References ast_cond_timedwait, ast_mutex_lock, ast_mutex_unlock, AST_TEST_FAIL, ast_test_status_update, ast_tv(), ast_tvadd(), ast_tvnow(), error(), expected_user_events, received_user_events, user_event_cond, and user_event_lock.
Referenced by AST_TEST_DEFINE(), and AST_TEST_DEFINE().
|
static |
Definition at line 274 of file test_message.c.
References AST_TEST_FAIL, ast_test_status_update, AST_VECTOR_GET, AST_VECTOR_SIZE, bad_headers, current, test::name, and ast_variable::next.
Referenced by AST_TEST_DEFINE(), and AST_TEST_DEFINE().
|
static |
Verifies a user event header/value pair.
user_event | which user event to check |
header | The header to verify |
value | The value read from the event |
-1 | on error or evaluation failure |
0 | if match not needed or success |
Definition at line 114 of file test_message.c.
References ast_log, ast_variable_list_append, ast_variable_new, AST_VECTOR_GET, AST_VECTOR_REPLACE, AST_VECTOR_SIZE, bad_headers, current, error(), expected_user_event_fields, LOG_ERROR, ast_variable::next, NULL, and value.
Referenced by user_event_hook_cb().
|
static |
Definition at line 881 of file test_message.c.
|
static |
Definition at line 881 of file test_message.c.
struct { ... } bad_headers |
If a user event fails, the bad headers that didn't match.
Referenced by test_cleanup_cb(), test_init_cb(), verify_bad_headers(), and verify_user_event_fields().
size_t current |
Definition at line 77 of file test_message.c.
Referenced by verify_bad_headers(), and verify_user_event_fields().
struct ast_variable* * elems |
Definition at line 77 of file test_message.c.
struct var_vector expected_user_event_fields |
Referenced by AST_TEST_DEFINE(), AST_TEST_DEFINE(), test_cleanup_cb(), test_init_cb(), and verify_user_event_fields().
|
static |
The number of user events we expect for this test.
Definition at line 56 of file test_message.c.
Referenced by user_event_hook_cb(), and user_event_wait_for_events().
|
static |
Condition wait variable for test_msg_handler receiving message.
Definition at line 68 of file test_message.c.
Referenced by handler_wait_for_message(), and test_msg_handle_msg_cb().
|
static |
Mutex for handler_cond
.
Definition at line 71 of file test_message.c.
Referenced by handler_wait_for_message(), and test_msg_handle_msg_cb().
|
static |
Predicate for the test_msg_handler receiving a message.
Definition at line 59 of file test_message.c.
Referenced by handler_wait_for_message(), test_init_cb(), and test_msg_handle_msg_cb().
size_t max |
Definition at line 77 of file test_message.c.
|
static |
Definition at line 168 of file test_message.c.
Referenced by test_init_cb(), and test_msg_send().
|
static |
The current number of received user events.
Definition at line 53 of file test_message.c.
Referenced by test_init_cb(), user_event_hook_cb(), and user_event_wait_for_events().
|
static |
Our test message handler.
Definition at line 90 of file test_message.c.
Referenced by AST_TEST_DEFINE(), AST_TEST_DEFINE(), AST_TEST_DEFINE(), AST_TEST_DEFINE(), and AST_TEST_DEFINE().
|
static |
Definition at line 81 of file test_message.c.
Referenced by AST_TEST_DEFINE(), and AST_TEST_DEFINE().
|
static |
Condition wait variable for all dialplan user events being received.
Definition at line 62 of file test_message.c.
Referenced by user_event_hook_cb(), and user_event_wait_for_events().
|
static |
AMI event hook that verifies whether or not we've gotten our user events.
Definition at line 99 of file test_message.c.
Referenced by create_test_dialplan(), and unload_module().
|
static |
Mutex for user_event_cond
.
Definition at line 65 of file test_message.c.
Referenced by user_event_hook_cb(), and user_event_wait_for_events().