Asterisk - The Open Source Telephony Project
18.5.0
|
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.
Macros | |
#define | DEFAULT_EXPECTED_EVENTS 4 |
The number of user events we should get in a dialplan test. More... | |
#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_msg_tech_registration) | |
AST_TEST_DEFINE (test_message_msg_handler_registration) | |
AST_TEST_DEFINE (test_message_manipulation) | |
AST_TEST_DEFINE (test_message_queue_dialplan_nominal) | |
AST_TEST_DEFINE (test_message_queue_handler_nominal) | |
AST_TEST_DEFINE (test_message_queue_both_nominal) | |
AST_TEST_DEFINE (test_message_has_destination_dialplan) | |
AST_TEST_DEFINE (test_message_has_destination_handler) | |
AST_TEST_DEFINE (test_message_msg_send) | |
AST_VECTOR (var_vector, struct ast_variable *) | |
The expected user event fields. More... | |
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. More... | |
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. More... | |
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. More... | |
Variables | |
static struct ast_module_info | __mod_info = { .name = AST_MODULE, .flags = AST_MODFLAG_LOAD_ORDER , .description = "Out-of-call text message support" , .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_info * | ast_module_info = &__mod_info |
static int | expected_user_events |
The number of user events we expect for this test. More... | |
static ast_cond_t | handler_cond |
Condition wait variable for test_msg_handler receiving message. More... | |
static ast_mutex_t | handler_lock = { PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP , NULL, {1, 0} } |
Mutex for handler_cond . More... | |
static int | handler_received_message |
Predicate for the test_message_handler receiving a message. More... | |
static int | message_received |
static int | received_user_events |
The current number of received user events. More... | |
static struct ast_msg_handler | test_msg_handler |
Our test message handler. More... | |
static ast_cond_t | user_event_cond |
Condition wait variable for all dialplan user events being received. More... | |
static struct manager_custom_hook | user_event_hook |
AMI event hook that verifies whether or not we've gotten our user events. More... | |
static ast_mutex_t | user_event_lock = { PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP , NULL, {1, 0} } |
Mutex for user_event_cond . More... | |
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.
Referenced by AST_TEST_DEFINE(), and test_init_cb().
#define FREE_VARIABLE_VECTOR | ( | vector | ) |
Definition at line 787 of file test_message.c.
Referenced by test_cleanup_cb().
#define TEST_CATEGORY "/main/message/" |
Definition at line 44 of file test_message.c.
Referenced by AST_TEST_DEFINE(), and load_module().
#define TEST_CONTEXT "__TEST_MESSAGE_CONTEXT__" |
Definition at line 46 of file test_message.c.
Referenced by AST_TEST_DEFINE(), and create_test_dialplan().
#define TEST_EXTENSION "test_message_extension" |
Definition at line 47 of file test_message.c.
Referenced by AST_TEST_DEFINE(), and create_test_dialplan().
|
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 | ( | 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, sip_to_pjsip::info(), 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, sip_to_pjsip::info(), TEST_CATEGORY, TEST_EXECUTE, and TEST_INIT.
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, sip_to_pjsip::info(), NULL, RAII_VAR, result, TEST_CATEGORY, TEST_EXECUTE, and TEST_INIT.
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, sip_to_pjsip::info(), 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(), sip_to_pjsip::info(), NULL, RAII_VAR, result, TEST_CATEGORY, TEST_EXECUTE, and TEST_INIT.
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_set_result(), ast_test_status_update, ast_variable_list_append, ast_variable_new, AST_VECTOR_REPLACE, DEFAULT_EXPECTED_EVENTS, handler_wait_for_message(), sip_to_pjsip::info(), NULL, RAII_VAR, result, TEST_CATEGORY, TEST_CONTEXT, TEST_EXECUTE, TEST_EXTENSION, TEST_INIT, user_event_wait_for_events(), and verify_bad_headers().
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, sip_to_pjsip::info(), 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, sip_to_pjsip::info(), NULL, RAII_VAR, result, TEST_CATEGORY, TEST_CONTEXT, TEST_EXECUTE, and TEST_INIT.
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_set_result(), ast_test_status_update, sip_to_pjsip::info(), NULL, RAII_VAR, TEST_CATEGORY, TEST_CONTEXT, TEST_EXECUTE, and TEST_INIT.
AST_VECTOR | ( | var_vector | , |
struct ast_variable * | |||
) |
The expected user event fields.
Definition at line 74 of file test_message.c.
|
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, and TEST_EXTENSION.
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_set_result(), ast_test_status_update, ast_tv(), ast_tvadd(), ast_tvnow(), error(), handler_cond, handler_lock, and handler_received_message.
Referenced by AST_TEST_DEFINE().
|
static |
Definition at line 860 of file test_message.c.
References AST_MODULE_LOAD_SUCCESS, AST_TEST_REGISTER, ast_test_register_cleanup(), ast_test_register_init(), create_test_dialplan(), TEST_CATEGORY, test_cleanup_cb(), and test_init_cb().
|
static |
Definition at line 801 of file test_message.c.
References FREE_VARIABLE_VECTOR.
Referenced by load_module().
|
static |
Definition at line 775 of file test_message.c.
References AST_VECTOR_INIT, DEFAULT_EXPECTED_EVENTS, 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 |
|
static |
Definition at line 809 of file test_message.c.
References ast_context_destroy(), ast_manager_unregister_hook(), AST_MODULE, AST_TEST_UNREGISTER, and NULL.
|
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, parse(), 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_set_result(), 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().
|
static |
Definition at line 274 of file test_message.c.
References AST_TEST_FAIL, ast_test_set_result(), ast_test_status_update, AST_VECTOR_GET, AST_VECTOR_SIZE, ast_variable::name, ast_variable::next, and ast_variable::value.
Referenced by 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, error(), LOG_ERROR, ast_variable::name, ast_variable::next, NULL, and ast_variable::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.
|
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_message_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().
|
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.
|
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.
|
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().