Asterisk - The Open Source Telephony Project GIT-master-f36a736
Macros | Functions | Variables
test_voicemail_api.c File Reference

Skeleton Test. More...

#include "asterisk.h"
#include <sys/stat.h>
#include "asterisk/utils.h"
#include "asterisk/module.h"
#include "asterisk/test.h"
#include "asterisk/paths.h"
#include "asterisk/channel.h"
#include "asterisk/app.h"
#include "asterisk/format_cache.h"
Include dependency graph for test_voicemail_api.c:

Go to the source code of this file.

Macros

#define TOTAL_SNAPSHOTS   4
 
#define VM_API_FORWARD_MESSAGE(from_mailbox, from_context, from_folder, to_mailbox, to_context, to_folder, number_of_messages, message_numbers_in, delete_old)
 
#define VM_API_FORWARD_MESSAGE_OFF_NOMINAL(from_mailbox, from_context, from_folder, to_mailbox, to_context, to_folder, number_of_messages, message_numbers_in, delete_old)
 
#define VM_API_INT_VERIFY(expected, actual)
 
#define VM_API_MOVE_MESSAGE(mailbox, context, number_of_messages, source, message_numbers_in, dest)
 
#define VM_API_MOVE_MESSAGE_OFF_NOMINAL(mailbox, context, number_of_messages, source, message_numbers_in, dest)
 
#define VM_API_PLAYBACK_MESSAGE(channel, mailbox, context, folder, message, callback_fn)
 
#define VM_API_PLAYBACK_MESSAGE_OFF_NOMINAL(channel, mailbox, context, folder, message, callback_fn)
 
#define VM_API_REMOVE_MESSAGE(mailbox, context, number_of_messages, folder, message_numbers_in)
 
#define VM_API_REMOVE_MESSAGE_OFF_NOMINAL(mailbox, context, number_of_messages, folder, message_numbers_in)
 
#define VM_API_SNAPSHOT_CREATE(mailbox, context, folder, desc, sort, old_and_inbox)
 
#define VM_API_SNAPSHOT_MSG_VERIFY(expected, actual, expected_folder, expected_index)
 
#define VM_API_SNAPSHOT_OFF_NOMINAL_TEST(mailbox, context, folder, desc, sort, old_and_inbox)
 
#define VM_API_SNAPSHOT_TEST_CLEANUP
 
#define VM_API_STRING_FIELD_VERIFY(expected, actual)
 
#define VM_API_TEST_CLEANUP   test_vm_api_test_teardown()
 
#define VM_API_TEST_SETUP
 
#define VOICEMAIL_DIR_MODE   0777
 
#define VOICEMAIL_FILE_MODE   0666
 

Functions

static void __reg_module (void)
 
static void __unreg_module (void)
 
struct ast_moduleAST_MODULE_SELF_SYM (void)
 
 AST_TEST_DEFINE (voicemail_api_nominal_forward)
 
 AST_TEST_DEFINE (voicemail_api_nominal_move)
 
 AST_TEST_DEFINE (voicemail_api_nominal_msg_playback)
 
 AST_TEST_DEFINE (voicemail_api_nominal_remove)
 
 AST_TEST_DEFINE (voicemail_api_nominal_snapshot)
 
 AST_TEST_DEFINE (voicemail_api_off_nominal_forward)
 
 AST_TEST_DEFINE (voicemail_api_off_nominal_move)
 
 AST_TEST_DEFINE (voicemail_api_off_nominal_msg_playback)
 
 AST_TEST_DEFINE (voicemail_api_off_nominal_remove)
 
 AST_TEST_DEFINE (voicemail_api_off_nominal_snapshot)
 
static int get_folder_by_name (const char *folder)
 
static int load_module (void)
 
static void message_playback_callback_fn (struct ast_channel *chan, const char *file, int duration)
 
static struct ast_channeltest_vm_api_create_mock_channel (void)
 
static struct ast_vm_msg_snapshottest_vm_api_create_mock_snapshot (const char *context, const char *exten, const char *callerid)
 
static int test_vm_api_create_voicemail_files (const char *context, const char *mailbox, struct ast_vm_msg_snapshot *snapshot)
 
static int test_vm_api_create_voicemail_folder (const char *folder_path)
 
static void test_vm_api_destroy_mailbox_voicemails (const char *mailbox, struct ast_vm_mailbox_snapshot *mailbox_snapshot)
 
static void test_vm_api_destroy_mock_snapshot (struct ast_vm_msg_snapshot *snapshot)
 
static struct ast_frametest_vm_api_mock_channel_read (struct ast_channel *chan)
 
static int test_vm_api_mock_channel_write (struct ast_channel *chan, struct ast_frame *frame)
 
static void test_vm_api_remove_all_messages (void)
 
static void test_vm_api_remove_voicemail (struct ast_vm_msg_snapshot *snapshot)
 
static int test_vm_api_test_setup (void)
 
static void test_vm_api_test_teardown (void)
 
static void test_vm_api_update_test_snapshots (struct ast_vm_mailbox_snapshot *mailbox_snapshot)
 
static int unload_module (void)
 

Variables

static struct ast_module_info __mod_info = { .name = AST_MODULE, .flags = AST_MODFLAG_LOAD_ORDER , .description = "Core Voicemail 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
 
static int global_entered_playback_callback = 0
 
static const char *const mailbox_folders []
 
static const struct ast_channel_tech mock_channel_tech
 
static struct ast_vm_msg_snapshottest_snapshots [TOTAL_SNAPSHOTS]
 

Detailed Description

Skeleton Test.

Author
Matt Jordan <mjordan@digium.com> 

Tests for the publicly exposed Voicemail API

Definition in file test_voicemail_api.c.

Macro Definition Documentation

◆ TOTAL_SNAPSHOTS

#define TOTAL_SNAPSHOTS   4

Definition at line 66 of file test_voicemail_api.c.

◆ VM_API_FORWARD_MESSAGE

#define VM_API_FORWARD_MESSAGE (   from_mailbox,
  from_context,
  from_folder,
  to_mailbox,
  to_context,
  to_folder,
  number_of_messages,
  message_numbers_in,
  delete_old 
)

Definition at line 263 of file test_voicemail_api.c.

◆ VM_API_FORWARD_MESSAGE_OFF_NOMINAL

#define VM_API_FORWARD_MESSAGE_OFF_NOMINAL (   from_mailbox,
  from_context,
  from_folder,
  to_mailbox,
  to_context,
  to_folder,
  number_of_messages,
  message_numbers_in,
  delete_old 
)

Definition at line 276 of file test_voicemail_api.c.

◆ VM_API_INT_VERIFY

#define VM_API_INT_VERIFY (   expected,
  actual 
)

Definition at line 129 of file test_voicemail_api.c.

◆ VM_API_MOVE_MESSAGE

#define VM_API_MOVE_MESSAGE (   mailbox,
  context,
  number_of_messages,
  source,
  message_numbers_in,
  dest 
)

Definition at line 211 of file test_voicemail_api.c.

◆ VM_API_MOVE_MESSAGE_OFF_NOMINAL

#define VM_API_MOVE_MESSAGE_OFF_NOMINAL (   mailbox,
  context,
  number_of_messages,
  source,
  message_numbers_in,
  dest 
)

Definition at line 223 of file test_voicemail_api.c.

◆ VM_API_PLAYBACK_MESSAGE

#define VM_API_PLAYBACK_MESSAGE (   channel,
  mailbox,
  context,
  folder,
  message,
  callback_fn 
)

Definition at line 292 of file test_voicemail_api.c.

◆ VM_API_PLAYBACK_MESSAGE_OFF_NOMINAL

#define VM_API_PLAYBACK_MESSAGE_OFF_NOMINAL (   channel,
  mailbox,
  context,
  folder,
  message,
  callback_fn 
)

Definition at line 307 of file test_voicemail_api.c.

◆ VM_API_REMOVE_MESSAGE

#define VM_API_REMOVE_MESSAGE (   mailbox,
  context,
  number_of_messages,
  folder,
  message_numbers_in 
)

Definition at line 235 of file test_voicemail_api.c.

◆ VM_API_REMOVE_MESSAGE_OFF_NOMINAL

#define VM_API_REMOVE_MESSAGE_OFF_NOMINAL (   mailbox,
  context,
  number_of_messages,
  folder,
  message_numbers_in 
)

Definition at line 251 of file test_voicemail_api.c.

◆ VM_API_SNAPSHOT_CREATE

#define VM_API_SNAPSHOT_CREATE (   mailbox,
  context,
  folder,
  desc,
  sort,
  old_and_inbox 
)

Definition at line 183 of file test_voicemail_api.c.

◆ VM_API_SNAPSHOT_MSG_VERIFY

#define VM_API_SNAPSHOT_MSG_VERIFY (   expected,
  actual,
  expected_folder,
  expected_index 
)

Definition at line 143 of file test_voicemail_api.c.

◆ VM_API_SNAPSHOT_OFF_NOMINAL_TEST

#define VM_API_SNAPSHOT_OFF_NOMINAL_TEST (   mailbox,
  context,
  folder,
  desc,
  sort,
  old_and_inbox 
)

Definition at line 198 of file test_voicemail_api.c.

◆ VM_API_SNAPSHOT_TEST_CLEANUP

#define VM_API_SNAPSHOT_TEST_CLEANUP
Value:
if (test_mbox_snapshot) { \
test_mbox_snapshot = ast_vm_mailbox_snapshot_destroy(test_mbox_snapshot); \
} \
VM_API_TEST_CLEANUP; \
struct ast_vm_mailbox_snapshot * ast_vm_mailbox_snapshot_destroy(struct ast_vm_mailbox_snapshot *mailbox_snapshot)
destroy a snapshot
Definition: main/app.c:675

Definition at line 103 of file test_voicemail_api.c.

◆ VM_API_STRING_FIELD_VERIFY

#define VM_API_STRING_FIELD_VERIFY (   expected,
  actual 
)

Definition at line 116 of file test_voicemail_api.c.

◆ VM_API_TEST_CLEANUP

#define VM_API_TEST_CLEANUP   test_vm_api_test_teardown()

Definition at line 95 of file test_voicemail_api.c.

◆ VM_API_TEST_SETUP

#define VM_API_TEST_SETUP

Definition at line 73 of file test_voicemail_api.c.

◆ VOICEMAIL_DIR_MODE

#define VOICEMAIL_DIR_MODE   0777

Definition at line 52 of file test_voicemail_api.c.

◆ VOICEMAIL_FILE_MODE

#define VOICEMAIL_FILE_MODE   0666

Definition at line 60 of file test_voicemail_api.c.

Function Documentation

◆ __reg_module()

static void __reg_module ( void  )
static

Definition at line 1577 of file test_voicemail_api.c.

◆ __unreg_module()

static void __unreg_module ( void  )
static

Definition at line 1577 of file test_voicemail_api.c.

◆ AST_MODULE_SELF_SYM()

struct ast_module * AST_MODULE_SELF_SYM ( void  )

Definition at line 1577 of file test_voicemail_api.c.

◆ AST_TEST_DEFINE() [1/10]

AST_TEST_DEFINE ( voicemail_api_nominal_forward  )

Definition at line 1218 of file test_voicemail_api.c.

1219{
1220 struct ast_vm_mailbox_snapshot *test_mbox_snapshot = NULL;
1221 const char *inbox_msg_id;
1222 const char *multi_msg_ids[2];
1223
1224 switch (cmd) {
1225 case TEST_INIT:
1226 info->name = "nominal_forward";
1227 info->category = "/main/voicemail_api/";
1228 info->summary = "Nominal message forward tests";
1229 info->description =
1230 "Tests the nominal cases of forwarding messages"
1231 " between mailboxes";
1232 return AST_TEST_NOT_RUN;
1233 case TEST_EXECUTE:
1234 break;
1235 }
1236
1238
1239 inbox_msg_id = test_snapshots[1]->msg_id;
1240
1241 multi_msg_ids[0] = test_snapshots[2]->msg_id;
1242 multi_msg_ids[1] = test_snapshots[3]->msg_id;
1243
1244 ast_test_status_update(test, "Test forwarding message 0 from test_vm_api_1234 INBOX to test_vm_api_2345 INBOX\n");
1245 VM_API_FORWARD_MESSAGE("test_vm_api_1234", "default", "INBOX", "test_vm_api_2345", "default", "INBOX", 1, &inbox_msg_id, 0);
1246
1247 /* Make sure we didn't delete the message */
1248 VM_API_SNAPSHOT_CREATE("test_vm_api_1234", "default", "INBOX", 0, AST_VM_SNAPSHOT_SORT_BY_TIME, 0);
1249 VM_API_INT_VERIFY(1, test_mbox_snapshot->total_msg_num);
1250 test_mbox_snapshot = ast_vm_mailbox_snapshot_destroy(test_mbox_snapshot);
1251
1252 /* We should now have a total of 3 messages in test_vm_api_2345 INBOX */
1253 VM_API_SNAPSHOT_CREATE("test_vm_api_2345", "default", "INBOX", 0, AST_VM_SNAPSHOT_SORT_BY_TIME, 0);
1254 VM_API_INT_VERIFY(3, test_mbox_snapshot->total_msg_num);
1255 test_mbox_snapshot = ast_vm_mailbox_snapshot_destroy(test_mbox_snapshot);
1256
1257 ast_test_status_update(test, "Test forwarding message 0 from test_vm_api_1234 INBOX with default context to test_vm_api_2345 INBOX\n");
1258 VM_API_FORWARD_MESSAGE("test_vm_api_1234", NULL, "INBOX", "test_vm_api_2345", "default", "INBOX", 1, &inbox_msg_id, 0);
1259
1260 /* Make sure we didn't delete the message */
1261 VM_API_SNAPSHOT_CREATE("test_vm_api_1234", "default", "INBOX", 0, AST_VM_SNAPSHOT_SORT_BY_TIME, 0);
1262 VM_API_INT_VERIFY(1, test_mbox_snapshot->total_msg_num);
1263 test_mbox_snapshot = ast_vm_mailbox_snapshot_destroy(test_mbox_snapshot);
1264
1265 /* We should now have a total of 4 messages in test_vm_api_2345 INBOX */
1266 VM_API_SNAPSHOT_CREATE("test_vm_api_2345", "default", "INBOX", 0, AST_VM_SNAPSHOT_SORT_BY_TIME, 0);
1267 VM_API_INT_VERIFY(4, test_mbox_snapshot->total_msg_num);
1268 test_mbox_snapshot = ast_vm_mailbox_snapshot_destroy(test_mbox_snapshot);
1269
1270 ast_test_status_update(test, "Test forwarding message 0 from test_vm_api_1234 INBOX to test_vm_api_2345 INBOX with default context\n");
1271 VM_API_FORWARD_MESSAGE("test_vm_api_1234", "default", "INBOX", "test_vm_api_2345", NULL, "INBOX", 1, &inbox_msg_id, 0);
1272
1273 /* Make sure we didn't delete the message */
1274 VM_API_SNAPSHOT_CREATE("test_vm_api_1234", "default", "INBOX", 0, AST_VM_SNAPSHOT_SORT_BY_TIME, 0);
1275 VM_API_INT_VERIFY(1, test_mbox_snapshot->total_msg_num);
1276 test_mbox_snapshot = ast_vm_mailbox_snapshot_destroy(test_mbox_snapshot);
1277
1278 /* We should now have a total of 5 messages in test_vm_api_2345 INBOX */
1279 VM_API_SNAPSHOT_CREATE("test_vm_api_2345", "default", "INBOX", 0, AST_VM_SNAPSHOT_SORT_BY_TIME, 0);
1280 VM_API_INT_VERIFY(5, test_mbox_snapshot->total_msg_num);
1281 test_mbox_snapshot = ast_vm_mailbox_snapshot_destroy(test_mbox_snapshot);
1282
1283 ast_test_status_update(test, "Test forwarding message 0 from test_vm_api_1234 INBOX to test_vm_api_2345 INBOX, deleting original\n");
1284 VM_API_FORWARD_MESSAGE("test_vm_api_1234", "default", "INBOX", "test_vm_api_2345", NULL, "INBOX", 1, &inbox_msg_id, 1);
1285
1286 /* Make sure we deleted the message */
1287 VM_API_SNAPSHOT_CREATE("test_vm_api_1234", "default", "INBOX", 0, AST_VM_SNAPSHOT_SORT_BY_TIME, 0);
1288 VM_API_INT_VERIFY(0, test_mbox_snapshot->total_msg_num);
1289 test_mbox_snapshot = ast_vm_mailbox_snapshot_destroy(test_mbox_snapshot);
1290
1291 /* We should now have a total of 6 messages in test_vm_api_2345 INBOX */
1292 VM_API_SNAPSHOT_CREATE("test_vm_api_2345", "default", "INBOX", 0, AST_VM_SNAPSHOT_SORT_BY_TIME, 0);
1293 VM_API_INT_VERIFY(6, test_mbox_snapshot->total_msg_num);
1294 test_mbox_snapshot = ast_vm_mailbox_snapshot_destroy(test_mbox_snapshot);
1295
1296 ast_test_status_update(test, "Test forwarding 2 messages from test_vm_api_2345 INBOX to test_vm_api_1234 INBOX");
1297 VM_API_FORWARD_MESSAGE("test_vm_api_2345", "default", "INBOX", "test_vm_api_1234", "default", "INBOX", 2, multi_msg_ids, 0);
1298
1299 /* Make sure we didn't delete the messages */
1300 VM_API_SNAPSHOT_CREATE("test_vm_api_2345", "default", "INBOX", 0, AST_VM_SNAPSHOT_SORT_BY_TIME, 0);
1301 VM_API_INT_VERIFY(6, test_mbox_snapshot->total_msg_num);
1302 test_mbox_snapshot = ast_vm_mailbox_snapshot_destroy(test_mbox_snapshot);
1303
1304 /* We should now have a total of 2 messages in test_vm_api_1234 INBOX */
1305 VM_API_SNAPSHOT_CREATE("test_vm_api_1234", "default", "INBOX", 0, AST_VM_SNAPSHOT_SORT_BY_TIME, 0);
1306 VM_API_INT_VERIFY(2, test_mbox_snapshot->total_msg_num);
1307 test_mbox_snapshot = ast_vm_mailbox_snapshot_destroy(test_mbox_snapshot);
1308
1309 ast_test_status_update(test, "Test forwarding 2 messages from test_vm_api_2345 INBOX to test_vm_api_1234 Family, deleting original\n");
1310 VM_API_FORWARD_MESSAGE("test_vm_api_2345", "default", "INBOX", "test_vm_api_1234", "default", "Family", 2, multi_msg_ids, 1);
1311 /* Make sure we deleted the messages */
1312 VM_API_SNAPSHOT_CREATE("test_vm_api_2345", "default", "INBOX", 0, AST_VM_SNAPSHOT_SORT_BY_TIME, 0);
1313 VM_API_INT_VERIFY(4, test_mbox_snapshot->total_msg_num);
1314 test_mbox_snapshot = ast_vm_mailbox_snapshot_destroy(test_mbox_snapshot);
1315
1316 /* We should now have a total of 2 messages in test_vm_api_1234 Family */
1317 VM_API_SNAPSHOT_CREATE("test_vm_api_1234", "default", "Family", 0, AST_VM_SNAPSHOT_SORT_BY_TIME, 0);
1318 VM_API_INT_VERIFY(2, test_mbox_snapshot->total_msg_num);
1319 test_mbox_snapshot = ast_vm_mailbox_snapshot_destroy(test_mbox_snapshot);
1320
1322
1323 return AST_TEST_PASS;
1324}
@ AST_VM_SNAPSHOT_SORT_BY_TIME
def info(msg)
#define NULL
Definition: resample.c:96
const ast_string_field msg_id
@ TEST_INIT
Definition: test.h:200
@ TEST_EXECUTE
Definition: test.h:201
#define ast_test_status_update(a, b, c...)
Definition: test.h:129
@ AST_TEST_PASS
Definition: test.h:195
@ AST_TEST_NOT_RUN
Definition: test.h:194
#define VM_API_INT_VERIFY(expected, actual)
static struct ast_vm_msg_snapshot * test_snapshots[TOTAL_SNAPSHOTS]
#define VM_API_SNAPSHOT_CREATE(mailbox, context, folder, desc, sort, old_and_inbox)
#define VM_API_TEST_CLEANUP
#define VM_API_FORWARD_MESSAGE(from_mailbox, from_context, from_folder, to_mailbox, to_context, to_folder, number_of_messages, message_numbers_in, delete_old)
#define VM_API_TEST_SETUP

References AST_TEST_NOT_RUN, AST_TEST_PASS, ast_test_status_update, ast_vm_mailbox_snapshot_destroy(), AST_VM_SNAPSHOT_SORT_BY_TIME, sip_to_pjsip::info(), ast_vm_msg_snapshot::msg_id, NULL, TEST_EXECUTE, TEST_INIT, test_snapshots, ast_vm_mailbox_snapshot::total_msg_num, VM_API_FORWARD_MESSAGE, VM_API_INT_VERIFY, VM_API_SNAPSHOT_CREATE, VM_API_TEST_CLEANUP, and VM_API_TEST_SETUP.

◆ AST_TEST_DEFINE() [2/10]

AST_TEST_DEFINE ( voicemail_api_nominal_move  )

Definition at line 964 of file test_voicemail_api.c.

965{
966 struct ast_vm_mailbox_snapshot *test_mbox_snapshot = NULL;
967 const char *inbox_msg_id;
968 const char *old_msg_id;
969 const char *multi_msg_ids[2];
970
971 switch (cmd) {
972 case TEST_INIT:
973 info->name = "nominal_move";
974 info->category = "/main/voicemail_api/";
975 info->summary = "Nominal move voicemail tests";
976 info->description =
977 "Test nominal requests to move a voicemail to a different"
978 " folder. This includes moving messages given a context,"
979 " given a NULL context, and moving multiple messages";
980 return AST_TEST_NOT_RUN;
981 case TEST_EXECUTE:
982 break;
983 }
984
986 old_msg_id = test_snapshots[0]->msg_id;
987 inbox_msg_id = test_snapshots[1]->msg_id;
988
989 multi_msg_ids[0] = test_snapshots[2]->msg_id;
990 multi_msg_ids[1] = test_snapshots[3]->msg_id;
991
992 ast_test_status_update(test, "Test move of test_vm_api_1234 message from INBOX to Family\n");
993 VM_API_MOVE_MESSAGE("test_vm_api_1234", "default", 1, "INBOX", &inbox_msg_id, "Family");
994
995 ast_test_status_update(test, "Test move of test_vm_api_1234 message from Old to Family\n");
996 VM_API_MOVE_MESSAGE("test_vm_api_1234", NULL, 1, "Old", &old_msg_id, "Family");
997
998 /* Take a snapshot and update the test snapshots for verification */
999 VM_API_SNAPSHOT_CREATE("test_vm_api_1234", "default", "Family", 0, AST_VM_SNAPSHOT_SORT_BY_TIME, 0);
1000 test_vm_api_update_test_snapshots(test_mbox_snapshot);
1001 test_mbox_snapshot = ast_vm_mailbox_snapshot_destroy(test_mbox_snapshot);
1002
1003 VM_API_STRING_FIELD_VERIFY("Family", test_snapshots[0]->folder_name);
1004 VM_API_STRING_FIELD_VERIFY("Family", test_snapshots[1]->folder_name);
1005 VM_API_INT_VERIFY(0, test_snapshots[1]->msg_number);
1006 VM_API_INT_VERIFY(1, test_snapshots[0]->msg_number);
1007
1008 /* Move both of the 2345 messages to Family */
1009 ast_test_status_update(test, "Test move of test_vm_api_2345 messages from Inbox to Family\n");
1010 VM_API_MOVE_MESSAGE("test_vm_api_2345", "default", 2, "INBOX", multi_msg_ids, "Family");
1011
1012 /* Take a snapshot and update the test snapshots for verification */
1013 VM_API_SNAPSHOT_CREATE("test_vm_api_2345", "default", "Family", 0, AST_VM_SNAPSHOT_SORT_BY_TIME, 0);
1014 test_vm_api_update_test_snapshots(test_mbox_snapshot);
1015 test_mbox_snapshot = ast_vm_mailbox_snapshot_destroy(test_mbox_snapshot);
1016
1017 VM_API_STRING_FIELD_VERIFY("Family", test_snapshots[2]->folder_name);
1018 VM_API_STRING_FIELD_VERIFY("Family", test_snapshots[3]->folder_name);
1019
1020 ast_test_status_update(test, "Test move of test_vm_api_2345 message from Family to INBOX\n");
1021 VM_API_MOVE_MESSAGE("test_vm_api_2345", "default", 2, "Family", multi_msg_ids, "INBOX");
1022
1023 VM_API_SNAPSHOT_CREATE("test_vm_api_2345", "default", "INBOX", 0, AST_VM_SNAPSHOT_SORT_BY_TIME, 0);
1024 test_vm_api_update_test_snapshots(test_mbox_snapshot);
1025 test_mbox_snapshot = ast_vm_mailbox_snapshot_destroy(test_mbox_snapshot);
1026
1027 VM_API_STRING_FIELD_VERIFY("INBOX", test_snapshots[2]->folder_name);
1028 VM_API_STRING_FIELD_VERIFY("INBOX", test_snapshots[3]->folder_name);
1029
1031
1032 return AST_TEST_PASS;
1033}
#define VM_API_STRING_FIELD_VERIFY(expected, actual)
#define VM_API_MOVE_MESSAGE(mailbox, context, number_of_messages, source, message_numbers_in, dest)
static void test_vm_api_update_test_snapshots(struct ast_vm_mailbox_snapshot *mailbox_snapshot)

References AST_TEST_NOT_RUN, AST_TEST_PASS, ast_test_status_update, ast_vm_mailbox_snapshot_destroy(), AST_VM_SNAPSHOT_SORT_BY_TIME, sip_to_pjsip::info(), ast_vm_msg_snapshot::msg_id, NULL, TEST_EXECUTE, TEST_INIT, test_snapshots, test_vm_api_update_test_snapshots(), VM_API_INT_VERIFY, VM_API_MOVE_MESSAGE, VM_API_SNAPSHOT_CREATE, VM_API_STRING_FIELD_VERIFY, VM_API_TEST_CLEANUP, and VM_API_TEST_SETUP.

◆ AST_TEST_DEFINE() [3/10]

AST_TEST_DEFINE ( voicemail_api_nominal_msg_playback  )

Definition at line 1411 of file test_voicemail_api.c.

1412{
1413 struct ast_vm_mailbox_snapshot *test_mbox_snapshot = NULL;
1414 struct ast_channel *test_channel;
1415 const char *message_id_1234;
1416 const char *message_id_2345[2];
1417
1418 switch (cmd) {
1419 case TEST_INIT:
1420 info->name = "nominal_msg_playback";
1421 info->category = "/main/voicemail_api/";
1422 info->summary = "Nominal message playback";
1423 info->description =
1424 "Tests playing back a message on a provided"
1425 " channel or callback function";
1426 return AST_TEST_NOT_RUN;
1427 case TEST_EXECUTE:
1428 break;
1429 }
1430
1432
1433 message_id_1234 = test_snapshots[1]->msg_id;
1434 message_id_2345[0] = test_snapshots[2]->msg_id;
1435 message_id_2345[1] = test_snapshots[3]->msg_id;
1436
1437 if (!(test_channel = test_vm_api_create_mock_channel())) {
1438 ast_log(AST_LOG_ERROR, "Failed to create mock channel for testing\n");
1440 return AST_TEST_FAIL;
1441 }
1442
1443 ast_test_status_update(test, "Playing back message from test_vm_api_1234 to mock channel\n");
1444 VM_API_PLAYBACK_MESSAGE(test_channel, "test_vm_api_1234", "default", "INBOX", message_id_1234, NULL);
1445
1446 ast_test_status_update(test, "Playing back message from test_vm_api_2345 to callback function\n");
1447 VM_API_PLAYBACK_MESSAGE(test_channel, "test_vm_api_2345", "default", "INBOX", message_id_2345[0], &message_playback_callback_fn);
1450
1451 ast_test_status_update(test, "Playing back message from test_vm_api_2345 to callback function with default context\n");
1452 VM_API_PLAYBACK_MESSAGE(test_channel, "test_vm_api_2345", NULL, "INBOX", message_id_2345[1], &message_playback_callback_fn);
1455
1456 VM_API_SNAPSHOT_CREATE("test_vm_api_1234", "default", "Old", 0, AST_VM_SNAPSHOT_SORT_BY_TIME, 0);
1457 VM_API_INT_VERIFY(2, test_mbox_snapshot->total_msg_num);
1458 test_mbox_snapshot = ast_vm_mailbox_snapshot_destroy(test_mbox_snapshot);
1459
1460 VM_API_SNAPSHOT_CREATE("test_vm_api_2345", "default", "Old", 0, AST_VM_SNAPSHOT_SORT_BY_TIME, 0);
1461 VM_API_INT_VERIFY(2, test_mbox_snapshot->total_msg_num);
1462 test_mbox_snapshot = ast_vm_mailbox_snapshot_destroy(test_mbox_snapshot);
1463
1464 ast_hangup(test_channel);
1466
1467 return AST_TEST_PASS;
1468}
#define ast_log
Definition: astobj2.c:42
void ast_hangup(struct ast_channel *chan)
Hang up a channel.
Definition: channel.c:2560
#define AST_LOG_ERROR
Main Channel structure associated with a channel.
@ AST_TEST_FAIL
Definition: test.h:196
static void message_playback_callback_fn(struct ast_channel *chan, const char *file, int duration)
static struct ast_channel * test_vm_api_create_mock_channel(void)
#define VM_API_PLAYBACK_MESSAGE(channel, mailbox, context, folder, message, callback_fn)
static int global_entered_playback_callback

References ast_hangup(), ast_log, AST_LOG_ERROR, AST_TEST_FAIL, AST_TEST_NOT_RUN, AST_TEST_PASS, ast_test_status_update, ast_vm_mailbox_snapshot_destroy(), AST_VM_SNAPSHOT_SORT_BY_TIME, global_entered_playback_callback, sip_to_pjsip::info(), message_playback_callback_fn(), ast_vm_msg_snapshot::msg_id, NULL, TEST_EXECUTE, TEST_INIT, test_snapshots, test_vm_api_create_mock_channel(), ast_vm_mailbox_snapshot::total_msg_num, VM_API_INT_VERIFY, VM_API_PLAYBACK_MESSAGE, VM_API_SNAPSHOT_CREATE, VM_API_TEST_CLEANUP, and VM_API_TEST_SETUP.

◆ AST_TEST_DEFINE() [4/10]

AST_TEST_DEFINE ( voicemail_api_nominal_remove  )

Definition at line 1111 of file test_voicemail_api.c.

1112{
1113 struct ast_vm_mailbox_snapshot *test_mbox_snapshot = NULL;
1114 const char *inbox_msg_id;
1115 const char *old_msg_id;
1116 const char *multi_msg_ids[2];
1117
1118 switch (cmd) {
1119 case TEST_INIT:
1120 info->name = "nominal_remove";
1121 info->category = "/main/voicemail_api/";
1122 info->summary = "Nominal mailbox remove message tests";
1123 info->description =
1124 "Tests removing messages from voicemail folders. Includes"
1125 " both removing messages one at a time, and in a set";
1126 return AST_TEST_NOT_RUN;
1127 case TEST_EXECUTE:
1128 break;
1129 }
1130
1132
1133 old_msg_id = test_snapshots[0]->msg_id;
1134 inbox_msg_id = test_snapshots[1]->msg_id;
1135
1136 multi_msg_ids[0] = test_snapshots[2]->msg_id;
1137 multi_msg_ids[1] = test_snapshots[3]->msg_id;
1138
1139 ast_test_status_update(test, "Test removing a single message from INBOX\n");
1140 VM_API_REMOVE_MESSAGE("test_vm_api_1234", "default", 1, "INBOX", &inbox_msg_id);
1141
1142 ast_test_status_update(test, "Test removing a single message from Old\n");
1143 VM_API_REMOVE_MESSAGE("test_vm_api_1234", "default", 1, "Old", &old_msg_id);
1144
1145 ast_test_status_update(test, "Test removing multiple messages from INBOX\n");
1146 VM_API_REMOVE_MESSAGE("test_vm_api_2345", "default", 2, "INBOX", multi_msg_ids);
1147
1149
1150 return AST_TEST_PASS;
1151}
#define VM_API_REMOVE_MESSAGE(mailbox, context, number_of_messages, folder, message_numbers_in)

References AST_TEST_NOT_RUN, AST_TEST_PASS, ast_test_status_update, sip_to_pjsip::info(), ast_vm_msg_snapshot::msg_id, NULL, TEST_EXECUTE, TEST_INIT, test_snapshots, VM_API_REMOVE_MESSAGE, VM_API_TEST_CLEANUP, and VM_API_TEST_SETUP.

◆ AST_TEST_DEFINE() [5/10]

AST_TEST_DEFINE ( voicemail_api_nominal_snapshot  )

Definition at line 838 of file test_voicemail_api.c.

839{
840 struct ast_vm_mailbox_snapshot *test_mbox_snapshot = NULL;
841
842 switch (cmd) {
843 case TEST_INIT:
844 info->name = "nominal_snapshot";
845 info->category = "/main/voicemail_api/";
846 info->summary = "Nominal mailbox snapshot tests";
847 info->description =
848 "Test retrieving mailbox snapshots";
849 return AST_TEST_NOT_RUN;
850 case TEST_EXECUTE:
851 break;
852 }
853
855
856 ast_test_status_update(test, "Test retrieving message 1 from INBOX of test_vm_1234\n");
857 VM_API_SNAPSHOT_CREATE("test_vm_api_1234", "default", "INBOX", 0, AST_VM_SNAPSHOT_SORT_BY_TIME, 0);
858 VM_API_INT_VERIFY(1, test_mbox_snapshot->total_msg_num);
859 VM_API_SNAPSHOT_MSG_VERIFY(test_snapshots[1], test_mbox_snapshot, "INBOX", 0);
860 ast_vm_mailbox_snapshot_destroy(test_mbox_snapshot);
861
862 ast_test_status_update(test, "Test retrieving message 0 from Old of test_vm_1234\n");
863 VM_API_SNAPSHOT_CREATE("test_vm_api_1234", "default", "Old", 0, AST_VM_SNAPSHOT_SORT_BY_TIME, 0);
864 VM_API_INT_VERIFY(1, test_mbox_snapshot->total_msg_num);
865 VM_API_SNAPSHOT_MSG_VERIFY(test_snapshots[0], test_mbox_snapshot, "Old", 0);
866 ast_vm_mailbox_snapshot_destroy(test_mbox_snapshot);
867
868 ast_test_status_update(test, "Test retrieving message 0, 1 from Old and INBOX of test_vm_1234 ordered by time\n");
869 VM_API_SNAPSHOT_CREATE("test_vm_api_1234", "default", "INBOX", 0, AST_VM_SNAPSHOT_SORT_BY_TIME, 1);
870 VM_API_INT_VERIFY(2, test_mbox_snapshot->total_msg_num);
871 VM_API_SNAPSHOT_MSG_VERIFY(test_snapshots[0], test_mbox_snapshot, "INBOX", 0);
872 VM_API_SNAPSHOT_MSG_VERIFY(test_snapshots[1], test_mbox_snapshot, "INBOX", 1);
873 ast_vm_mailbox_snapshot_destroy(test_mbox_snapshot);
874
875 ast_test_status_update(test, "Test retrieving message 1, 0 from Old and INBOX of test_vm_1234 ordered by time desc\n");
876 VM_API_SNAPSHOT_CREATE("test_vm_api_1234", "default", "INBOX", 1, AST_VM_SNAPSHOT_SORT_BY_TIME, 1);
877 VM_API_INT_VERIFY(2, test_mbox_snapshot->total_msg_num);
878 VM_API_SNAPSHOT_MSG_VERIFY(test_snapshots[1], test_mbox_snapshot, "INBOX", 0);
879 VM_API_SNAPSHOT_MSG_VERIFY(test_snapshots[0], test_mbox_snapshot, "INBOX", 1);
880 ast_vm_mailbox_snapshot_destroy(test_mbox_snapshot);
881
882 ast_test_status_update(test, "Test retrieving message 0, 1 from Old and INBOX of test_vm_1234 ordered by id\n");
883 VM_API_SNAPSHOT_CREATE("test_vm_api_1234", "default", "INBOX", 0, AST_VM_SNAPSHOT_SORT_BY_ID, 1);
884 VM_API_INT_VERIFY(2, test_mbox_snapshot->total_msg_num);
885 VM_API_SNAPSHOT_MSG_VERIFY(test_snapshots[1], test_mbox_snapshot, "INBOX", 0);
886 VM_API_SNAPSHOT_MSG_VERIFY(test_snapshots[0], test_mbox_snapshot, "INBOX", 1);
887 ast_vm_mailbox_snapshot_destroy(test_mbox_snapshot);
888
889 ast_test_status_update(test, "Test retrieving message 1, 0 from Old and INBOX of test_vm_1234 ordered by id desc\n");
890 VM_API_SNAPSHOT_CREATE("test_vm_api_1234", "default", "INBOX", 1, AST_VM_SNAPSHOT_SORT_BY_ID, 1);
891 VM_API_INT_VERIFY(2, test_mbox_snapshot->total_msg_num);
892 VM_API_SNAPSHOT_MSG_VERIFY(test_snapshots[0], test_mbox_snapshot, "INBOX", 0);
893 VM_API_SNAPSHOT_MSG_VERIFY(test_snapshots[1], test_mbox_snapshot, "INBOX", 1);
894 ast_vm_mailbox_snapshot_destroy(test_mbox_snapshot);
895
896 ast_test_status_update(test, "Test retrieving message 0, 1 from all folders of test_vm_1234 ordered by id\n");
897 VM_API_SNAPSHOT_CREATE("test_vm_api_1234", "default", NULL, 0, AST_VM_SNAPSHOT_SORT_BY_ID, 0);
898 VM_API_INT_VERIFY(2, test_mbox_snapshot->total_msg_num);
899 VM_API_SNAPSHOT_MSG_VERIFY(test_snapshots[0], test_mbox_snapshot, "Old", 0);
900 VM_API_SNAPSHOT_MSG_VERIFY(test_snapshots[1], test_mbox_snapshot, "INBOX", 0);
901 ast_vm_mailbox_snapshot_destroy(test_mbox_snapshot);
902
903 ast_test_status_update(test, "Test retrieving message 0, 1 from all folders of test_vm_1234 ordered by time\n");
904 VM_API_SNAPSHOT_CREATE("test_vm_api_1234", "default", NULL, 0, AST_VM_SNAPSHOT_SORT_BY_TIME, 0);
905 VM_API_INT_VERIFY(2, test_mbox_snapshot->total_msg_num);
906 VM_API_SNAPSHOT_MSG_VERIFY(test_snapshots[0], test_mbox_snapshot, "Old", 0);
907 VM_API_SNAPSHOT_MSG_VERIFY(test_snapshots[1], test_mbox_snapshot, "INBOX", 0);
908 ast_vm_mailbox_snapshot_destroy(test_mbox_snapshot);
909
910 ast_test_status_update(test, "Test retrieving message 0, 1 from all folders of test_vm_1234, default context ordered by time\n");
912 VM_API_INT_VERIFY(2, test_mbox_snapshot->total_msg_num);
913 VM_API_SNAPSHOT_MSG_VERIFY(test_snapshots[0], test_mbox_snapshot, "Old", 0);
914 VM_API_SNAPSHOT_MSG_VERIFY(test_snapshots[1], test_mbox_snapshot, "INBOX", 0);
915 ast_vm_mailbox_snapshot_destroy(test_mbox_snapshot);
916
918
919 return AST_TEST_PASS;
920}
@ AST_VM_SNAPSHOT_SORT_BY_ID
#define VM_API_SNAPSHOT_MSG_VERIFY(expected, actual, expected_folder, expected_index)

References AST_TEST_NOT_RUN, AST_TEST_PASS, ast_test_status_update, ast_vm_mailbox_snapshot_destroy(), AST_VM_SNAPSHOT_SORT_BY_ID, AST_VM_SNAPSHOT_SORT_BY_TIME, sip_to_pjsip::info(), NULL, TEST_EXECUTE, TEST_INIT, test_snapshots, ast_vm_mailbox_snapshot::total_msg_num, VM_API_INT_VERIFY, VM_API_SNAPSHOT_CREATE, VM_API_SNAPSHOT_MSG_VERIFY, VM_API_TEST_CLEANUP, and VM_API_TEST_SETUP.

◆ AST_TEST_DEFINE() [6/10]

AST_TEST_DEFINE ( voicemail_api_off_nominal_forward  )

Definition at line 1326 of file test_voicemail_api.c.

1327{
1328 const char *inbox_msg_id;
1329 const char *multi_msg_ids[4];
1330
1331 const char *empty_msg_ids = "";
1332
1333 switch (cmd) {
1334 case TEST_INIT:
1335 info->name = "off_nominal_forward";
1336 info->category = "/main/voicemail_api/";
1337 info->summary = "Off nominal message forwarding tests";
1338 info->description =
1339 "Test off nominal forwarding of messages. This includes:\n"
1340 " * Invalid/NULL from mailbox\n"
1341 " * Invalid from context\n"
1342 " * Invalid/NULL from folder\n"
1343 " * Invalid/NULL to mailbox\n"
1344 " * Invalid to context\n"
1345 " * Invalid/NULL to folder\n"
1346 " * Invalid message numbers\n"
1347 " * Invalid number of messages";
1348 return AST_TEST_NOT_RUN;
1349 case TEST_EXECUTE:
1350 break;
1351 }
1352
1354
1355 inbox_msg_id = test_snapshots[1]->msg_id;
1356
1357 multi_msg_ids[0] = test_snapshots[0]->msg_id;
1358 multi_msg_ids[1] = test_snapshots[1]->msg_id;
1359 multi_msg_ids[2] = test_snapshots[2]->msg_id;
1360 multi_msg_ids[3] = test_snapshots[3]->msg_id;
1361
1362 ast_test_status_update(test, "Test forwarding from an invalid mailbox\n");
1363 VM_API_FORWARD_MESSAGE_OFF_NOMINAL("test_vm_api_3456", "default", "INBOX", "test_vm_api_2345", "default", "INBOX", 1, &inbox_msg_id, 0);
1364
1365 ast_test_status_update(test, "Test forwarding from a NULL mailbox\n");
1366 VM_API_FORWARD_MESSAGE_OFF_NOMINAL(NULL, "default", "INBOX", "test_vm_api_2345", "default", "INBOX", 1, &inbox_msg_id, 0);
1367
1368 ast_test_status_update(test, "Test forwarding from an invalid context\n");
1369 VM_API_FORWARD_MESSAGE_OFF_NOMINAL("test_vm_api_1234", "defunct", "INBOX", "test_vm_api_2345", "default", "INBOX", 1, &inbox_msg_id, 0);
1370
1371 ast_test_status_update(test, "Test forwarding from an invalid folder\n");
1372 VM_API_FORWARD_MESSAGE_OFF_NOMINAL("test_vm_api_1234", "default", "POTTEDMEAT", "test_vm_api_2345", "default", "INBOX", 1, &inbox_msg_id, 0);
1373
1374 ast_test_status_update(test, "Test forwarding from a NULL folder\n");
1375 VM_API_FORWARD_MESSAGE_OFF_NOMINAL("test_vm_api_1234", "default", NULL, "test_vm_api_2345", "default", "INBOX", 1, &inbox_msg_id, 0);
1376
1377 ast_test_status_update(test, "Test forwarding to an invalid mailbox\n");
1378 VM_API_FORWARD_MESSAGE_OFF_NOMINAL("test_vm_api_1234", "default", "INBOX", "test_vm_api_3456", "default", "INBOX", 1, &inbox_msg_id, 0);
1379
1380 ast_test_status_update(test, "Test forwarding to a NULL mailbox\n");
1381 VM_API_FORWARD_MESSAGE_OFF_NOMINAL("test_vm_api_1234", "default", "INBOX", NULL, "default", "INBOX", 1, &inbox_msg_id, 0);
1382
1383 ast_test_status_update(test, "Test forwarding to an invalid context\n");
1384 VM_API_FORWARD_MESSAGE_OFF_NOMINAL("test_vm_api_1234", "default", "INBOX", "test_vm_api_2345", "defunct", "INBOX", 1, &inbox_msg_id, 0);
1385
1386 ast_test_status_update(test, "Test forwarding to an invalid folder\n");
1387
1388 VM_API_FORWARD_MESSAGE_OFF_NOMINAL("test_vm_api_1234", "default", "INBOX", "test_vm_api_2345", "default", "POTTEDMEAT", 1, &inbox_msg_id, 0);
1389
1390 ast_test_status_update(test, "Test forwarding to a NULL folder\n");
1391 VM_API_FORWARD_MESSAGE_OFF_NOMINAL("test_vm_api_1234", "default", "INBOX", "test_vm_api_2345", "default", NULL, 1, &inbox_msg_id, 0);
1392
1393 ast_test_status_update(test, "Test forwarding when no messages are select\n");
1394 VM_API_FORWARD_MESSAGE_OFF_NOMINAL("test_vm_api_1234", "default", "INBOX", "test_vm_api_2345", "default", "INBOX", 0, &empty_msg_ids, 0);
1395
1396 ast_test_status_update(test, "Test forwarding a message that doesn't exist\n");
1397 inbox_msg_id = "POOPOO";
1398 VM_API_FORWARD_MESSAGE_OFF_NOMINAL("test_vm_api_1234", "default", "INBOX", "test_vm_api_2345", "default", "INBOX", 1, &inbox_msg_id, 0);
1399
1400 ast_test_status_update(test, "Test forwarding multiple messages, where some messages don't exist\n");
1401 VM_API_FORWARD_MESSAGE_OFF_NOMINAL("test_vm_api_2345", "default", "INBOX", "test_vm_api_1234", "default", "INBOX", 4, multi_msg_ids, 0);
1402
1403 ast_test_status_update(test, "Test forwarding a message with an invalid size specifier\n");
1404 VM_API_FORWARD_MESSAGE_OFF_NOMINAL("test_vm_api_1234", "default", "INBOX", "test_vm_api_2345", "default", "INBOX", -30, &inbox_msg_id, 0);
1405
1407
1408 return AST_TEST_PASS;
1409}
#define VM_API_FORWARD_MESSAGE_OFF_NOMINAL(from_mailbox, from_context, from_folder, to_mailbox, to_context, to_folder, number_of_messages, message_numbers_in, delete_old)

References AST_TEST_NOT_RUN, AST_TEST_PASS, ast_test_status_update, sip_to_pjsip::info(), ast_vm_msg_snapshot::msg_id, NULL, TEST_EXECUTE, TEST_INIT, test_snapshots, VM_API_FORWARD_MESSAGE_OFF_NOMINAL, VM_API_TEST_CLEANUP, and VM_API_TEST_SETUP.

◆ AST_TEST_DEFINE() [7/10]

AST_TEST_DEFINE ( voicemail_api_off_nominal_move  )

Definition at line 1035 of file test_voicemail_api.c.

1036{
1037 const char *inbox_msg_id;
1038 const char *multi_msg_ids[4];
1039
1040 switch (cmd) {
1041 case TEST_INIT:
1042 info->name = "off_nominal_move";
1043 info->category = "/main/voicemail_api/";
1044 info->summary = "Off nominal mailbox message move tests";
1045 info->description =
1046 "Test nominal requests to move a voicemail to a different"
1047 " folder. This includes testing the following:\n"
1048 " * Moving to a non-existent mailbox\n"
1049 " * Moving to a NULL mailbox\n"
1050 " * Moving to a non-existent context\n"
1051 " * Moving to/from non-existent folder\n"
1052 " * Moving to/from NULL folder\n"
1053 " * Invalid message identifier(s)";
1054 return AST_TEST_NOT_RUN;
1055 case TEST_EXECUTE:
1056 break;
1057 }
1058
1060
1061 inbox_msg_id = test_snapshots[1]->msg_id;
1062
1063 multi_msg_ids[0] = test_snapshots[0]->msg_id;
1064 multi_msg_ids[1] = test_snapshots[1]->msg_id;
1065 multi_msg_ids[2] = test_snapshots[2]->msg_id;
1066 multi_msg_ids[3] = test_snapshots[3]->msg_id;
1067
1068 ast_test_status_update(test, "Test move attempt for invalid mailbox test_vm_3456\n");
1069 VM_API_MOVE_MESSAGE_OFF_NOMINAL("test_vm_api_3456", "default", 1, "INBOX", &inbox_msg_id, "Family");
1070
1071 VM_API_MOVE_MESSAGE_OFF_NOMINAL(NULL, "default", 1, "INBOX", &inbox_msg_id, "Family");
1072
1073 ast_test_status_update(test, "Test move attempt for invalid context test_vm_api_defunct\n");
1074 VM_API_MOVE_MESSAGE_OFF_NOMINAL("test_vm_api_1234", "test_vm_api_defunct", 1, "INBOX", &inbox_msg_id, "Family");
1075
1076 ast_test_status_update(test, "Test move attempt to invalid folder\n");
1077 VM_API_MOVE_MESSAGE_OFF_NOMINAL("test_vm_api_1234", "default", 1, "INBOX", &inbox_msg_id, "SPAMALOT");
1078
1079 ast_test_status_update(test, "Test move attempt from invalid folder\n");
1080 VM_API_MOVE_MESSAGE_OFF_NOMINAL("test_vm_api_1234", "default", 1, "MEATINACAN", &inbox_msg_id, "Family");
1081
1082 ast_test_status_update(test, "Test move attempt to NULL folder\n");
1083 VM_API_MOVE_MESSAGE_OFF_NOMINAL("test_vm_api_1234", "default", 1, "INBOX", &inbox_msg_id, NULL);
1084
1085 ast_test_status_update(test, "Test move attempt from NULL folder\n");
1086 VM_API_MOVE_MESSAGE_OFF_NOMINAL("test_vm_api_1234", "default", 1, NULL, &inbox_msg_id, "Family");
1087
1088 ast_test_status_update(test, "Test move attempt with non-existent message number\n");
1089 inbox_msg_id = "6";
1090 VM_API_MOVE_MESSAGE_OFF_NOMINAL("test_vm_api_1234", "default", 1, "INBOX", &inbox_msg_id, "Family");
1091
1092 ast_test_status_update(test, "Test move attempt with invalid message number\n");
1093 inbox_msg_id = "";
1094 VM_API_MOVE_MESSAGE_OFF_NOMINAL("test_vm_api_1234", "default", 1, "INBOX", &inbox_msg_id, "Family");
1095
1096 ast_test_status_update(test, "Test move attempt with 0 number of messages\n");
1097 inbox_msg_id = test_snapshots[1]->msg_id;
1098 VM_API_MOVE_MESSAGE_OFF_NOMINAL("test_vm_api_1234", "default", 0, "INBOX", &inbox_msg_id, "Family");
1099
1100 ast_test_status_update(test, "Test move attempt with invalid number of messages\n");
1101 VM_API_MOVE_MESSAGE_OFF_NOMINAL("test_vm_api_1234", "default", -30, "INBOX", &inbox_msg_id, "Family");
1102
1103 ast_test_status_update(test, "Test move attempt with non-existent multiple messages, where some messages exist\n");
1104 VM_API_MOVE_MESSAGE_OFF_NOMINAL("test_vm_api_1234", "default", 4, "INBOX", multi_msg_ids, "Family");
1105
1107
1108 return AST_TEST_PASS;
1109}
#define VM_API_MOVE_MESSAGE_OFF_NOMINAL(mailbox, context, number_of_messages, source, message_numbers_in, dest)

References AST_TEST_NOT_RUN, AST_TEST_PASS, ast_test_status_update, sip_to_pjsip::info(), ast_vm_msg_snapshot::msg_id, NULL, TEST_EXECUTE, TEST_INIT, test_snapshots, VM_API_MOVE_MESSAGE_OFF_NOMINAL, VM_API_TEST_CLEANUP, and VM_API_TEST_SETUP.

◆ AST_TEST_DEFINE() [8/10]

AST_TEST_DEFINE ( voicemail_api_off_nominal_msg_playback  )

Definition at line 1470 of file test_voicemail_api.c.

1471{
1472 struct ast_channel *test_channel;
1473 const char *msg_id;
1474 const char *invalid_msg_id = "POOPOO";
1475
1476 switch (cmd) {
1477 case TEST_INIT:
1478 info->name = "off_nominal_msg_playback";
1479 info->category = "/main/voicemail_api/";
1480 info->summary = "Off nominal message playback";
1481 info->description =
1482 "Tests off nominal conditions in playing back a "
1483 "message. This includes:\n"
1484 " * Invalid/NULL mailbox\n"
1485 " * Invalid context\n"
1486 " * Invalid/NULL folder\n"
1487 " * Invalid message identifiers";
1488 return AST_TEST_NOT_RUN;
1489 case TEST_EXECUTE:
1490 break;
1491 }
1492
1494 msg_id = test_snapshots[0]->msg_id;
1495
1496 if (!(test_channel = test_vm_api_create_mock_channel())) {
1497 ast_log(AST_LOG_ERROR, "Failed to create mock channel for testing\n");
1499 return AST_TEST_FAIL;
1500 }
1501
1502 ast_test_status_update(test, "Playing back message from invalid mailbox\n");
1503 VM_API_PLAYBACK_MESSAGE_OFF_NOMINAL(test_channel, "test_vm_api_3456", "default", "INBOX", msg_id, NULL);
1504
1505 ast_test_status_update(test, "Playing back message from NULL mailbox\n");
1506 VM_API_PLAYBACK_MESSAGE_OFF_NOMINAL(test_channel, NULL, "default", "INBOX", msg_id, NULL);
1507
1508 ast_test_status_update(test, "Playing back message from invalid context\n");
1509 VM_API_PLAYBACK_MESSAGE_OFF_NOMINAL(test_channel, "test_vm_api_1234", "defunct", "INBOX", msg_id, NULL);
1510
1511 ast_test_status_update(test, "Playing back message from invalid folder\n");
1512 VM_API_PLAYBACK_MESSAGE_OFF_NOMINAL(test_channel, "test_vm_api_1234", "default", "BACON", msg_id, NULL);
1513
1514 ast_test_status_update(test, "Playing back message from NULL folder\n");
1515 VM_API_PLAYBACK_MESSAGE_OFF_NOMINAL(test_channel, "test_vm_api_1234", "default", NULL, msg_id, NULL);
1516
1517 ast_test_status_update(test, "Playing back message with invalid message specifier\n");
1518 VM_API_PLAYBACK_MESSAGE_OFF_NOMINAL(test_channel, "test_vm_api_1234", "default", "INBOX", invalid_msg_id, NULL);
1519
1520 ast_test_status_update(test, "Playing back message with NULL message specifier\n");
1521 VM_API_PLAYBACK_MESSAGE_OFF_NOMINAL(test_channel, "test_vm_api_1234", "default", "INBOX", NULL, NULL);
1522 ast_hangup(test_channel);
1524
1525 return AST_TEST_PASS;
1526}
#define VM_API_PLAYBACK_MESSAGE_OFF_NOMINAL(channel, mailbox, context, folder, message, callback_fn)

References ast_hangup(), ast_log, AST_LOG_ERROR, AST_TEST_FAIL, AST_TEST_NOT_RUN, AST_TEST_PASS, ast_test_status_update, sip_to_pjsip::info(), ast_vm_msg_snapshot::msg_id, NULL, TEST_EXECUTE, TEST_INIT, test_snapshots, test_vm_api_create_mock_channel(), VM_API_PLAYBACK_MESSAGE_OFF_NOMINAL, VM_API_TEST_CLEANUP, and VM_API_TEST_SETUP.

◆ AST_TEST_DEFINE() [9/10]

AST_TEST_DEFINE ( voicemail_api_off_nominal_remove  )

Definition at line 1153 of file test_voicemail_api.c.

1154{
1155 const char *inbox_msg_id;
1156 const char *multi_msg_ids[2];
1157 const char *empty_msg_ids = "";
1158
1159 switch (cmd) {
1160 case TEST_INIT:
1161 info->name = "off_nominal_remove";
1162 info->category = "/main/voicemail_api/";
1163 info->summary = "Off nominal mailbox message removal tests";
1164 info->description =
1165 "Test off nominal requests for removing messages from "
1166 "a mailbox. This includes:\n"
1167 " * Removing messages with an invalid mailbox\n"
1168 " * Removing messages from a NULL mailbox\n"
1169 " * Removing messages from an invalid context\n"
1170 " * Removing messages from an invalid folder\n"
1171 " * Removing messages from a NULL folder\n"
1172 " * Removing messages with bad identifiers";
1173 return AST_TEST_NOT_RUN;
1174 case TEST_EXECUTE:
1175 break;
1176 }
1177
1179
1180 inbox_msg_id = test_snapshots[1]->msg_id;
1181 multi_msg_ids[0] = test_snapshots[2]->msg_id;
1182 multi_msg_ids[1] = test_snapshots[3]->msg_id;
1183
1184 ast_test_status_update(test, "Test removing a single message with an invalid mailbox\n");
1185 VM_API_REMOVE_MESSAGE_OFF_NOMINAL("test_vm_api_3456", "default", 1, "INBOX", &inbox_msg_id);
1186
1187 ast_test_status_update(test, "Test removing a single message with a NULL mailbox\n");
1188 VM_API_REMOVE_MESSAGE_OFF_NOMINAL(NULL, "default", 1, "INBOX", &inbox_msg_id);
1189
1190 ast_test_status_update(test, "Test removing a single message with an invalid context\n");
1191 VM_API_REMOVE_MESSAGE_OFF_NOMINAL("test_vm_api_1234", "defunct", 1, "INBOX", &inbox_msg_id);
1192
1193 ast_test_status_update(test, "Test removing a single message with an invalid folder\n");
1194 VM_API_REMOVE_MESSAGE_OFF_NOMINAL("test_vm_api_1234", "default", 1, "SPAMINACAN", &inbox_msg_id);
1195
1196 ast_test_status_update(test, "Test removing a single message with a NULL folder\n");
1197 VM_API_REMOVE_MESSAGE_OFF_NOMINAL("test_vm_api_1234", "default", 1, NULL, &inbox_msg_id);
1198
1199 ast_test_status_update(test, "Test removing a single message with an invalid message number\n");
1200 inbox_msg_id = "POOPOO";
1201 VM_API_REMOVE_MESSAGE_OFF_NOMINAL("test_vm_api_1234", "default", 1, "INBOX", &inbox_msg_id);
1202
1203 ast_test_status_update(test, "Test removing multiple messages with a single invalid message number\n");
1204 multi_msg_ids[1] = "POOPOO";
1205 VM_API_REMOVE_MESSAGE_OFF_NOMINAL("test_vm_api_2345", "default", 2, "INBOX", multi_msg_ids);
1206
1207 ast_test_status_update(test, "Test removing no messages with no message numbers\n");
1208 VM_API_REMOVE_MESSAGE_OFF_NOMINAL("test_vm_api_1234", "default", 0, "INBOX", &empty_msg_ids);
1209
1210 ast_test_status_update(test, "Test removing multiple messages with an invalid size specifier\n");
1211 VM_API_REMOVE_MESSAGE_OFF_NOMINAL("test_vm_api_2345", "default", -30, "INBOX", multi_msg_ids);
1212
1214
1215 return AST_TEST_PASS;
1216}
#define VM_API_REMOVE_MESSAGE_OFF_NOMINAL(mailbox, context, number_of_messages, folder, message_numbers_in)

References AST_TEST_NOT_RUN, AST_TEST_PASS, ast_test_status_update, sip_to_pjsip::info(), ast_vm_msg_snapshot::msg_id, NULL, TEST_EXECUTE, TEST_INIT, test_snapshots, VM_API_REMOVE_MESSAGE_OFF_NOMINAL, VM_API_TEST_CLEANUP, and VM_API_TEST_SETUP.

◆ AST_TEST_DEFINE() [10/10]

AST_TEST_DEFINE ( voicemail_api_off_nominal_snapshot  )

Definition at line 922 of file test_voicemail_api.c.

923{
924 struct ast_vm_mailbox_snapshot *test_mbox_snapshot = NULL;
925
926 switch (cmd) {
927 case TEST_INIT:
928 info->name = "off_nominal_snapshot";
929 info->category = "/main/voicemail_api/";
930 info->summary = "Off nominal mailbox snapshot tests";
931 info->description =
932 "Test off nominal requests for mailbox snapshots. This includes"
933 " testing the following:\n"
934 " * Access to non-exisstent mailbox\n"
935 " * Access to NULL mailbox\n"
936 " * Access to non-existent context\n"
937 " * Access to non-existent folder\n"
938 " * Access to NULL folder\n"
939 " * Invalid sort identifier";
940 return AST_TEST_NOT_RUN;
941 case TEST_EXECUTE:
942 break;
943 }
944
946
947 ast_test_status_update(test, "Test access to non-existent mailbox test_vm_api_3456\n");
948 VM_API_SNAPSHOT_OFF_NOMINAL_TEST("test_vm_api_3456", "default", "INBOX", 0, AST_VM_SNAPSHOT_SORT_BY_TIME, 0);
949
950 ast_test_status_update(test, "Test access to null mailbox\n");
952
953 ast_test_status_update(test, "Test access non-existent context test_vm_api_defunct\n");
954 VM_API_SNAPSHOT_OFF_NOMINAL_TEST("test_vm_api_1234", "test_vm_api_defunct", "INBOX", 0, AST_VM_SNAPSHOT_SORT_BY_TIME, 0);
955
956 ast_test_status_update(test, "Test non-existent folder test_vm_api_platypus\n");
957 VM_API_SNAPSHOT_OFF_NOMINAL_TEST("test_vm_api_1234", "default", "test_vm_api_platypus", 0, AST_VM_SNAPSHOT_SORT_BY_TIME, 0);
958
960
961 return AST_TEST_PASS;
962}
#define VM_API_SNAPSHOT_OFF_NOMINAL_TEST(mailbox, context, folder, desc, sort, old_and_inbox)

References AST_TEST_NOT_RUN, AST_TEST_PASS, ast_test_status_update, AST_VM_SNAPSHOT_SORT_BY_TIME, sip_to_pjsip::info(), NULL, TEST_EXECUTE, TEST_INIT, VM_API_SNAPSHOT_OFF_NOMINAL_TEST, VM_API_TEST_CLEANUP, and VM_API_TEST_SETUP.

◆ get_folder_by_name()

static int get_folder_by_name ( const char *  folder)
static

Definition at line 353 of file test_voicemail_api.c.

354{
355 size_t i;
356
357 for (i = 0; i < ARRAY_LEN(mailbox_folders); i++) {
358 if (strcasecmp(folder, mailbox_folders[i]) == 0) {
359 return i;
360 }
361 }
362
363 return -1;
364}
static const char *const mailbox_folders[]
#define ARRAY_LEN(a)
Definition: utils.h:666

References ARRAY_LEN, and mailbox_folders.

◆ load_module()

static int load_module ( void  )
static

Definition at line 1552 of file test_voicemail_api.c.

1553{
1554 /* Snapshot tests */
1555 AST_TEST_REGISTER(voicemail_api_nominal_snapshot);
1556 AST_TEST_REGISTER(voicemail_api_off_nominal_snapshot);
1557
1558 /* Move Tests */
1559 AST_TEST_REGISTER(voicemail_api_nominal_move);
1560 AST_TEST_REGISTER(voicemail_api_off_nominal_move);
1561
1562 /* Remove Tests */
1563 AST_TEST_REGISTER(voicemail_api_nominal_remove);
1564 AST_TEST_REGISTER(voicemail_api_off_nominal_remove);
1565
1566 /* Forward Tests */
1567 AST_TEST_REGISTER(voicemail_api_nominal_forward);
1568 AST_TEST_REGISTER(voicemail_api_off_nominal_forward);
1569
1570 /* Message Playback Tests */
1571 AST_TEST_REGISTER(voicemail_api_nominal_msg_playback);
1572 AST_TEST_REGISTER(voicemail_api_off_nominal_msg_playback);
1573
1575}
@ AST_MODULE_LOAD_SUCCESS
Definition: module.h:70
#define AST_TEST_REGISTER(cb)
Definition: test.h:127

References AST_MODULE_LOAD_SUCCESS, and AST_TEST_REGISTER.

◆ message_playback_callback_fn()

static void message_playback_callback_fn ( struct ast_channel chan,
const char *  file,
int  duration 
)
static

Definition at line 773 of file test_voicemail_api.c.

774{
775 if ((chan) && !ast_strlen_zero(file) && duration > 0) {
777 } else {
778 ast_log(AST_LOG_WARNING, "Entered into message playback callback function with invalid parameters\n");
779 }
780}
#define AST_LOG_WARNING
static force_inline int attribute_pure ast_strlen_zero(const char *s)
Definition: strings.h:65

References ast_log, AST_LOG_WARNING, ast_strlen_zero(), ast_vm_msg_snapshot::duration, make_ari_stubs::file, and global_entered_playback_callback.

Referenced by AST_TEST_DEFINE().

◆ test_vm_api_create_mock_channel()

static struct ast_channel * test_vm_api_create_mock_channel ( void  )
static

Definition at line 816 of file test_voicemail_api.c.

817{
818 struct ast_channel *mock_channel;
819 struct ast_format_cap *native_formats;
820
821 if (!(mock_channel = ast_channel_alloc(0, AST_STATE_DOWN, NULL, NULL, NULL, NULL, NULL, NULL, NULL, 0, "TestChannel"))) {
822 return NULL;
823 }
824
830 native_formats = ast_channel_nativeformats(mock_channel);
831 ast_format_cap_append(native_formats, ast_channel_writeformat(mock_channel), 0);
832
833 ast_channel_unlock(mock_channel);
834
835 return mock_channel;
836}
#define ast_channel_alloc(needqueue, state, cid_num, cid_name, acctcode, exten, context, assignedids, requestor, amaflag,...)
Create a channel structure.
Definition: channel.h:1299
struct ast_format_cap * ast_channel_nativeformats(const struct ast_channel *chan)
void ast_channel_set_rawreadformat(struct ast_channel *chan, struct ast_format *format)
void ast_channel_set_rawwriteformat(struct ast_channel *chan, struct ast_format *format)
void ast_channel_set_readformat(struct ast_channel *chan, struct ast_format *format)
struct ast_format * ast_channel_writeformat(struct ast_channel *chan)
void ast_channel_tech_set(struct ast_channel *chan, const struct ast_channel_tech *value)
#define ast_channel_unlock(chan)
Definition: channel.h:2969
void ast_channel_set_writeformat(struct ast_channel *chan, struct ast_format *format)
@ AST_STATE_DOWN
Definition: channelstate.h:36
struct ast_format * ast_format_gsm
Built-in cached gsm format.
Definition: format_cache.c:96
#define ast_format_cap_append(cap, format, framing)
Add format capability to capabilities structure.
Definition: format_cap.h:99
Format capabilities structure, holds formats + preference order + etc.
Definition: format_cap.c:54
static const struct ast_channel_tech mock_channel_tech

References ast_channel_alloc, ast_channel_nativeformats(), ast_channel_set_rawreadformat(), ast_channel_set_rawwriteformat(), ast_channel_set_readformat(), ast_channel_set_writeformat(), ast_channel_tech_set(), ast_channel_unlock, ast_channel_writeformat(), ast_format_cap_append, ast_format_gsm, AST_STATE_DOWN, mock_channel_tech, and NULL.

Referenced by AST_TEST_DEFINE().

◆ test_vm_api_create_mock_snapshot()

static struct ast_vm_msg_snapshot * test_vm_api_create_mock_snapshot ( const char *  context,
const char *  exten,
const char *  callerid 
)
static

Definition at line 377 of file test_voicemail_api.c.

378{
379 char msg_id_hash[AST_MAX_CONTEXT + AST_MAX_EXTENSION + sizeof(callerid) + 1];
380 char msg_id_buf[256];
381 struct ast_vm_msg_snapshot *snapshot;
382
383 snprintf(msg_id_hash, sizeof(msg_id_hash), "%s%s%s", exten, context, callerid);
384 snprintf(msg_id_buf, sizeof(msg_id_buf), "%ld-%d", (long)time(NULL), ast_str_hash(msg_id_hash));
385
386 if ((snapshot = ast_calloc(1, sizeof(*snapshot)))) {
387 if (ast_string_field_init(snapshot, 128)) {
388 ast_free(snapshot);
389 return NULL;
390 }
391 ast_string_field_set(snapshot, msg_id, msg_id_buf);
392 ast_string_field_set(snapshot, exten, exten);
394 }
395 return snapshot;
396}
#define ast_free(a)
Definition: astmm.h:180
#define ast_calloc(num, len)
A wrapper for calloc()
Definition: astmm.h:202
#define AST_MAX_CONTEXT
Definition: channel.h:135
#define AST_MAX_EXTENSION
Definition: channel.h:134
#define ast_string_field_set(x, field, data)
Set a field to a simple string value.
Definition: stringfields.h:521
#define ast_string_field_init(x, size)
Initialize a field pool and fields.
Definition: stringfields.h:359
static force_inline int attribute_pure ast_str_hash(const char *str)
Compute a hash value on a string.
Definition: strings.h:1259
const ast_string_field callerid
const ast_string_field exten

References ast_calloc, ast_free, AST_MAX_CONTEXT, AST_MAX_EXTENSION, ast_str_hash(), ast_string_field_init, ast_string_field_set, ast_vm_msg_snapshot::callerid, voicemailpwcheck::context, ast_vm_msg_snapshot::exten, ast_vm_msg_snapshot::msg_id, and NULL.

Referenced by test_vm_api_test_setup().

◆ test_vm_api_create_voicemail_files()

static int test_vm_api_create_voicemail_files ( const char *  context,
const char *  mailbox,
struct ast_vm_msg_snapshot snapshot 
)
static

Definition at line 445 of file test_voicemail_api.c.

446{
447 FILE *msg_file;
448 char folder_path[PATH_MAX];
449 char msg_path[PATH_MAX];
450 char snd_path[PATH_MAX];
451 char beep_path[PATH_MAX];
452
453 /* Note that we create both the text and a dummy sound file here. Without
454 * the sound file, a number of the voicemail operations 'silently' fail, as it
455 * does not believe that an actual voicemail exists
456 */
457 snprintf(folder_path, sizeof(folder_path), "%s/voicemail/%s/%s/%s",
459 snprintf(msg_path, sizeof(msg_path), "%s/msg%04u.txt",
460 folder_path, snapshot->msg_number);
461 snprintf(snd_path, sizeof(snd_path), "%s/msg%04u.gsm",
462 folder_path, snapshot->msg_number);
463 snprintf(beep_path, sizeof(beep_path), "%s/sounds/en/beep.gsm", ast_config_AST_DATA_DIR);
464
465 if (test_vm_api_create_voicemail_folder(folder_path)) {
466 return 1;
467 }
468
469 if (ast_lock_path(folder_path) == AST_LOCK_FAILURE) {
470 ast_log(AST_LOG_ERROR, "Unable to lock directory %s\n", folder_path);
471 return 1;
472 }
473
474 if (symlink(beep_path, snd_path)) {
475 ast_unlock_path(folder_path);
476 ast_log(AST_LOG_ERROR, "Failed to create a symbolic link from %s to %s: %s\n",
477 beep_path, snd_path, strerror(errno));
478 return 1;
479 }
480
481 if (!(msg_file = fopen(msg_path, "w"))) {
482 /* Attempt to remove the sound file */
483 unlink(snd_path);
484 ast_unlock_path(folder_path);
485 ast_log(AST_LOG_ERROR, "Failed to open %s for writing\n", msg_path);
486 return 1;
487 }
488
489 fprintf(msg_file, ";\n; Message Information file\n;\n"
490 "[message]\n"
491 "origmailbox=%s\n"
492 "context=%s\n"
493 "exten=%s\n"
494 "rdnis=%s\n"
495 "priority=%d\n"
496 "callerchan=%s\n"
497 "callerid=%s\n"
498 "origdate=%s\n"
499 "origtime=%s\n"
500 "category=%s\n"
501 "msg_id=%s\n"
502 "flag=%s\n"
503 "duration=%s\n",
504 mailbox,
505 context,
506 snapshot->exten,
507 "unknown",
508 1,
509 snapshot->callerchan,
510 snapshot->callerid,
511 snapshot->origdate,
512 snapshot->origtime,
513 "",
514 snapshot->msg_id,
515 snapshot->flag,
516 snapshot->duration);
517 fclose(msg_file);
518
519 if (chmod(msg_path, VOICEMAIL_FILE_MODE) < 0) {
520 ast_unlock_path(folder_path);
521 ast_log(AST_LOG_ERROR, "Couldn't set permissions on voicemail text file %s: %s", msg_path, strerror(errno));
522 return 1;
523 }
524 ast_unlock_path(folder_path);
525
526 return 0;
527}
#define PATH_MAX
Definition: asterisk.h:40
@ AST_LOCK_FAILURE
enum AST_LOCK_RESULT ast_lock_path(const char *path)
Lock a filesystem path.
Definition: main/app.c:2614
int ast_unlock_path(const char *path)
Unlock a path.
Definition: main/app.c:2630
int errno
const char * ast_config_AST_DATA_DIR
Definition: options.c:158
const char * ast_config_AST_SPOOL_DIR
Definition: options.c:154
const ast_string_field folder_name
const ast_string_field origtime
const ast_string_field callerchan
const ast_string_field duration
const ast_string_field origdate
const ast_string_field flag
#define VOICEMAIL_FILE_MODE
static int test_vm_api_create_voicemail_folder(const char *folder_path)

References ast_config_AST_DATA_DIR, ast_config_AST_SPOOL_DIR, AST_LOCK_FAILURE, ast_lock_path(), ast_log, AST_LOG_ERROR, ast_unlock_path(), ast_vm_msg_snapshot::callerchan, ast_vm_msg_snapshot::callerid, voicemailpwcheck::context, ast_vm_msg_snapshot::duration, errno, ast_vm_msg_snapshot::exten, ast_vm_msg_snapshot::flag, ast_vm_msg_snapshot::folder_name, voicemailpwcheck::mailbox, ast_vm_msg_snapshot::msg_id, ast_vm_msg_snapshot::msg_number, ast_vm_msg_snapshot::origdate, ast_vm_msg_snapshot::origtime, PATH_MAX, test_vm_api_create_voicemail_folder(), and VOICEMAIL_FILE_MODE.

Referenced by test_vm_api_test_setup().

◆ test_vm_api_create_voicemail_folder()

static int test_vm_api_create_voicemail_folder ( const char *  folder_path)
static

Definition at line 419 of file test_voicemail_api.c.

420{
421 mode_t mode = VOICEMAIL_DIR_MODE;
422 int res;
423
424 if ((res = ast_mkdir(folder_path, mode))) {
425 ast_log(AST_LOG_ERROR, "ast_mkdir '%s' failed: %s\n", folder_path, strerror(res));
426 return 1;
427 }
428 return 0;
429}
#define VOICEMAIL_DIR_MODE
int ast_mkdir(const char *path, int mode)
Recursively create directory path.
Definition: utils.c:2479

References ast_log, AST_LOG_ERROR, ast_mkdir(), and VOICEMAIL_DIR_MODE.

Referenced by test_vm_api_create_voicemail_files().

◆ test_vm_api_destroy_mailbox_voicemails()

static void test_vm_api_destroy_mailbox_voicemails ( const char *  mailbox,
struct ast_vm_mailbox_snapshot mailbox_snapshot 
)
static

Definition at line 570 of file test_voicemail_api.c.

571{
572 struct ast_vm_msg_snapshot *msg;
573 int i;
574
575 for (i = 0; i < 12; ++i) {
576 AST_LIST_TRAVERSE(&mailbox_snapshot->snapshots[i], msg, msg) {
579 }
580 }
581}
#define AST_LIST_TRAVERSE(head, var, field)
Loops over (traverses) the entries in a list.
Definition: linkedlists.h:491
struct ast_vm_mailbox_snapshot::@185 * snapshots
struct ast_vm_msg_snapshot::@184 msg
static void test_vm_api_remove_voicemail(struct ast_vm_msg_snapshot *snapshot)

References AST_LIST_TRAVERSE, ast_string_field_set, ast_vm_msg_snapshot::exten, voicemailpwcheck::mailbox, ast_vm_msg_snapshot::msg, ast_vm_mailbox_snapshot::snapshots, and test_vm_api_remove_voicemail().

Referenced by test_vm_api_remove_all_messages().

◆ test_vm_api_destroy_mock_snapshot()

static void test_vm_api_destroy_mock_snapshot ( struct ast_vm_msg_snapshot snapshot)
static

Definition at line 402 of file test_voicemail_api.c.

403{
404 if (snapshot) {
406 ast_free(snapshot);
407 }
408}
#define ast_string_field_free_memory(x)
free all memory - to be called before destroying the object
Definition: stringfields.h:374

References ast_free, and ast_string_field_free_memory.

Referenced by test_vm_api_test_setup(), and test_vm_api_test_teardown().

◆ test_vm_api_mock_channel_read()

static struct ast_frame * test_vm_api_mock_channel_read ( struct ast_channel chan)
static

Definition at line 795 of file test_voicemail_api.c.

796{
797 return &ast_null_frame;
798}
struct ast_frame ast_null_frame
Definition: main/frame.c:79

References ast_null_frame.

◆ test_vm_api_mock_channel_write()

static int test_vm_api_mock_channel_write ( struct ast_channel chan,
struct ast_frame frame 
)
static

Definition at line 786 of file test_voicemail_api.c.

787{
788 return 0;
789}

◆ test_vm_api_remove_all_messages()

static void test_vm_api_remove_all_messages ( void  )
static

Definition at line 587 of file test_voicemail_api.c.

588{
589 struct ast_vm_mailbox_snapshot *mailbox_snapshot;
590
591 /* Take a snapshot of each mailbox and remove the contents. Note that we need to use
592 * snapshots of the mailboxes in addition to our tracked test snapshots, as there's a good chance
593 * we've created copies of the snapshots */
594 if ((mailbox_snapshot = ast_vm_mailbox_snapshot_create("test_vm_api_1234", "default", NULL, 0, AST_VM_SNAPSHOT_SORT_BY_ID, 0))) {
595 test_vm_api_destroy_mailbox_voicemails("test_vm_api_1234", mailbox_snapshot);
596 mailbox_snapshot = ast_vm_mailbox_snapshot_destroy(mailbox_snapshot);
597 } else {
598 ast_log(AST_LOG_WARNING, "Failed to create mailbox snapshot - could not remove test messages for test_vm_api_1234\n");
599 }
600 if ((mailbox_snapshot = ast_vm_mailbox_snapshot_create("test_vm_api_2345", "default", NULL, 0, AST_VM_SNAPSHOT_SORT_BY_ID, 0))) {
601 test_vm_api_destroy_mailbox_voicemails("test_vm_api_2345", mailbox_snapshot);
602 mailbox_snapshot = ast_vm_mailbox_snapshot_destroy(mailbox_snapshot);
603 } else {
604 ast_log(AST_LOG_WARNING, "Failed to create mailbox snapshot - could not remove test messages for test_vm_api_2345\n");
605 }
606}
struct ast_vm_mailbox_snapshot * ast_vm_mailbox_snapshot_create(const char *mailbox, const char *context, const char *folder, int descending, enum ast_vm_snapshot_sort_val sort_val, int combine_INBOX_and_OLD)
Create a snapshot of a mailbox which contains information about every msg.
Definition: main/app.c:661
static void test_vm_api_destroy_mailbox_voicemails(const char *mailbox, struct ast_vm_mailbox_snapshot *mailbox_snapshot)

References ast_log, AST_LOG_WARNING, ast_vm_mailbox_snapshot_create(), ast_vm_mailbox_snapshot_destroy(), AST_VM_SNAPSHOT_SORT_BY_ID, NULL, and test_vm_api_destroy_mailbox_voicemails().

Referenced by test_vm_api_test_setup(), and test_vm_api_test_teardown().

◆ test_vm_api_remove_voicemail()

static void test_vm_api_remove_voicemail ( struct ast_vm_msg_snapshot snapshot)
static

Definition at line 535 of file test_voicemail_api.c.

536{
537 char msg_path[PATH_MAX];
538 char snd_path[PATH_MAX];
539 char folder_path[PATH_MAX];
540
541 if (!snapshot) {
542 return;
543 }
544
545 snprintf(folder_path, sizeof(folder_path), "%s/voicemail/%s/%s/%s",
546 ast_config_AST_SPOOL_DIR, "default", snapshot->exten, snapshot->folder_name);
547
548 snprintf(msg_path, sizeof(msg_path), "%s/msg%04u.txt",
549 folder_path, snapshot->msg_number);
550 snprintf(snd_path, sizeof(snd_path), "%s/msg%04u.gsm",
551 folder_path, snapshot->msg_number);
552 unlink(msg_path);
553 unlink(snd_path);
554
555 return;
556}

References ast_config_AST_SPOOL_DIR, ast_vm_msg_snapshot::exten, ast_vm_msg_snapshot::folder_name, ast_vm_msg_snapshot::msg_number, and PATH_MAX.

Referenced by test_vm_api_destroy_mailbox_voicemails(), and test_vm_api_test_teardown().

◆ test_vm_api_test_setup()

static int test_vm_api_test_setup ( void  )
static

Definition at line 624 of file test_voicemail_api.c.

625{
626 int i, res = 0;
627 struct ast_vm_msg_snapshot *msg_one = NULL;
628 struct ast_vm_msg_snapshot *msg_two = NULL;
629 struct ast_vm_msg_snapshot *msg_three = NULL;
630 struct ast_vm_msg_snapshot *msg_four = NULL;
631
632 /* Make the four sample voicemails */
633 if ( !((msg_one = test_vm_api_create_mock_snapshot("default", "test_vm_api_1234", "\"Phil\" <2000>")))
634 || !((msg_two = test_vm_api_create_mock_snapshot("default", "test_vm_api_1234", "\"Noel\" <8000>")))
635 || !((msg_three = test_vm_api_create_mock_snapshot("default", "test_vm_api_2345", "\"Phil\" <2000>")))
636 || !((msg_four = test_vm_api_create_mock_snapshot("default", "test_vm_api_2345", "\"Bill\" <3000>")))) {
637 ast_log(AST_LOG_ERROR, "Failed to create mock snapshots for test\n");
642 return 1;
643 }
644
645 /* Create the voicemail users */
646 if (ast_vm_test_create_user("default", "test_vm_api_1234")
647 || ast_vm_test_create_user("default", "test_vm_api_2345")) {
648 ast_log(AST_LOG_ERROR, "Failed to create test voicemail users\n");
653 /* Note that the cleanup macro will ensure that any test user that
654 * was successfully created is removed
655 */
656 return 1;
657 }
658
659 /* Now that the users exist from the perspective of the voicemail
660 * application, attempt to remove any existing voicemails
661 */
663
664 /* Set the basic properties on each */
665 ast_string_field_set(msg_one, callerchan, "SIP/2000-00000000");
666 ast_string_field_set(msg_one, origdate, "Mon Mar 19 04:14:21 PM UTC 2012");
667 ast_string_field_set(msg_one, origtime, "1332173661");
668 ast_string_field_set(msg_one, duration, "8");
669 ast_string_field_set(msg_one, folder_name, "Old");
670 msg_one->msg_number = 0;
671 test_snapshots[0] = msg_one;
672
673 ast_string_field_set(msg_two, callerchan, "SIP/8000-00000001");
674 ast_string_field_set(msg_two, origdate, "Mon Mar 19 06:16:13 PM UTC 2012");
675 ast_string_field_set(msg_two, origtime, "1332180973");
676 ast_string_field_set(msg_two, duration, "24");
677 ast_string_field_set(msg_two, folder_name, "INBOX");
678 msg_two->msg_number = 0;
679 test_snapshots[1] = msg_two;
680
681 ast_string_field_set(msg_three, callerchan, "IAX/2000-000000a3");
682 ast_string_field_set(msg_three, origdate, "Thu Mar 22 23:13:03 PM UTC 2012");
683 ast_string_field_set(msg_three, origtime, "1332181251");
684 ast_string_field_set(msg_three, duration, "25");
685 ast_string_field_set(msg_three, folder_name, "INBOX");
686 msg_three->msg_number = 0;
687 test_snapshots[2] = msg_three;
688
689 ast_string_field_set(msg_four, callerchan, "DAHDI/3000-00000010");
690 ast_string_field_set(msg_four, origdate, "Fri Mar 23 03:01:03 AM UTC 2012");
691 ast_string_field_set(msg_four, origtime, "1332181362");
692 ast_string_field_set(msg_four, duration, "13");
693 ast_string_field_set(msg_four, folder_name, "INBOX");
694 msg_three->msg_number = 1;
695 test_snapshots[3] = msg_four;
696
697 /* Store the messages */
698 for (i = 0; i < TOTAL_SNAPSHOTS; ++i) {
700 /* On a failure, the test_vm_api_test_teardown method will remove and
701 * unlink any created files. Since we failed to create the file, clean
702 * up the object here instead */
703 ast_log(AST_LOG_ERROR, "Failed to store voicemail %s/%s\n",
704 "default", test_snapshots[i]->exten);
706 test_snapshots[i] = NULL;
707 res = 1;
708 }
709 }
710
711 return res;
712}
#define TOTAL_SNAPSHOTS
static void test_vm_api_destroy_mock_snapshot(struct ast_vm_msg_snapshot *snapshot)
static void test_vm_api_remove_all_messages(void)
static struct ast_vm_msg_snapshot * test_vm_api_create_mock_snapshot(const char *context, const char *exten, const char *callerid)
static int test_vm_api_create_voicemail_files(const char *context, const char *mailbox, struct ast_vm_msg_snapshot *snapshot)

References ast_log, AST_LOG_ERROR, ast_string_field_set, ast_vm_msg_snapshot::callerchan, ast_vm_msg_snapshot::duration, ast_vm_msg_snapshot::exten, ast_vm_msg_snapshot::folder_name, ast_vm_msg_snapshot::msg_number, NULL, ast_vm_msg_snapshot::origdate, ast_vm_msg_snapshot::origtime, test_snapshots, test_vm_api_create_mock_snapshot(), test_vm_api_create_voicemail_files(), test_vm_api_destroy_mock_snapshot(), test_vm_api_remove_all_messages(), and TOTAL_SNAPSHOTS.

◆ test_vm_api_test_teardown()

static void test_vm_api_test_teardown ( void  )
static

Definition at line 714 of file test_voicemail_api.c.

715{
716 int i;
717
718 /* Remove our test message snapshots */
719 for (i = 0; i < TOTAL_SNAPSHOTS; ++i) {
722 test_snapshots[i] = NULL;
723 }
724
726
727 /* Remove the test users */
728 ast_vm_test_destroy_user("default", "test_vm_api_1234");
729 ast_vm_test_destroy_user("default", "test_vm_api_2345");
730}

References NULL, test_snapshots, test_vm_api_destroy_mock_snapshot(), test_vm_api_remove_all_messages(), test_vm_api_remove_voicemail(), and TOTAL_SNAPSHOTS.

◆ test_vm_api_update_test_snapshots()

static void test_vm_api_update_test_snapshots ( struct ast_vm_mailbox_snapshot mailbox_snapshot)
static

◆ unload_module()

static int unload_module ( void  )
static

Definition at line 1528 of file test_voicemail_api.c.

1529{
1530 /* Snapshot tests */
1531 AST_TEST_UNREGISTER(voicemail_api_nominal_snapshot);
1532 AST_TEST_UNREGISTER(voicemail_api_off_nominal_snapshot);
1533
1534 /* Move Tests */
1535 AST_TEST_UNREGISTER(voicemail_api_nominal_move);
1536 AST_TEST_UNREGISTER(voicemail_api_off_nominal_move);
1537
1538 /* Remove Tests */
1539 AST_TEST_UNREGISTER(voicemail_api_nominal_remove);
1540 AST_TEST_UNREGISTER(voicemail_api_off_nominal_remove);
1541
1542 /* Forward Tests */
1543 AST_TEST_UNREGISTER(voicemail_api_nominal_forward);
1544 AST_TEST_UNREGISTER(voicemail_api_off_nominal_forward);
1545
1546 /* Message Playback Tests */
1547 AST_TEST_UNREGISTER(voicemail_api_nominal_msg_playback);
1548 AST_TEST_UNREGISTER(voicemail_api_off_nominal_msg_playback);
1549 return 0;
1550}
#define AST_TEST_UNREGISTER(cb)
Definition: test.h:128

References AST_TEST_UNREGISTER.

Variable Documentation

◆ __mod_info

struct ast_module_info __mod_info = { .name = AST_MODULE, .flags = AST_MODFLAG_LOAD_ORDER , .description = "Core Voicemail 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 1577 of file test_voicemail_api.c.

◆ ast_module_info

const struct ast_module_info* ast_module_info = &__mod_info
static

Definition at line 1577 of file test_voicemail_api.c.

◆ global_entered_playback_callback

int global_entered_playback_callback = 0
static

Definition at line 347 of file test_voicemail_api.c.

Referenced by AST_TEST_DEFINE(), and message_playback_callback_fn().

◆ mailbox_folders

const char* const mailbox_folders[]
static

Definition at line 322 of file test_voicemail_api.c.

Referenced by get_folder_by_name().

◆ mock_channel_tech

const struct ast_channel_tech mock_channel_tech
static
Initial value:
= {
}
static int test_vm_api_mock_channel_write(struct ast_channel *chan, struct ast_frame *frame)
static struct ast_frame * test_vm_api_mock_channel_read(struct ast_channel *chan)

Definition at line 804 of file test_voicemail_api.c.

Referenced by test_vm_api_create_mock_channel().

◆ test_snapshots

struct ast_vm_msg_snapshot* test_snapshots[TOTAL_SNAPSHOTS]
static