Asterisk - The Open Source Telephony Project GIT-master-2de1a68
test_voicemail_api.c
Go to the documentation of this file.
1/*
2 * Asterisk -- An open source telephony toolkit.
3 *
4 * Copyright (C) 2012, Matt Jordan
5 *
6 * Matt Jordan <mjordan@digium.com>
7 *
8 * See http://www.asterisk.org for more information about
9 * the Asterisk project. Please do not directly contact
10 * any of the maintainers of this project for assistance;
11 * the project provides a web site, mailing lists and IRC
12 * channels for your use.
13 *
14 * This program is free software, distributed under the terms of
15 * the GNU General Public License Version 2. See the LICENSE file
16 * at the top of the source tree.
17 */
18
19/*!
20 * \file
21 * \brief Skeleton Test
22 *
23 * \author\verbatim Matt Jordan <mjordan@digium.com> \endverbatim
24 *
25 * Tests for the publicly exposed Voicemail API
26 * \ingroup tests
27 */
28
29/*** MODULEINFO
30 <depend>TEST_FRAMEWORK</depend>
31 <support_level>core</support_level>
32 ***/
33
34#include "asterisk.h"
35
36#include <sys/stat.h>
37
38#include "asterisk/utils.h"
39#include "asterisk/module.h"
40#include "asterisk/test.h"
41#include "asterisk/paths.h"
42#include "asterisk/channel.h"
43#include "asterisk/app.h"
45
46/*!
47 * \internal
48 * \brief Permissions to set on the voicemail directories we create
49 *
50 * \note taken from app_voicemail
51 */
52#define VOICEMAIL_DIR_MODE 0777
53
54/*!
55 * \internal
56 * \brief Permissions to set on the voicemail files we create
57 *
58 * \note taken from app_voicemail
59 */
60#define VOICEMAIL_FILE_MODE 0666
61
62/*!
63 * \internal
64 * \brief The number of mock snapshot objects we use for tests
65 */
66#define TOTAL_SNAPSHOTS 4
67
68/*!
69 * \internal
70 * \brief Create and populate the mock message objects and create the
71 * envelope files on the file system
72 */
73#define VM_API_TEST_SETUP do { \
74 if (!ast_vm_is_registered()) { \
75 ast_test_status_update(test, "No voicemail provider registered.\n"); \
76 return AST_TEST_FAIL; \
77 } else if (test_vm_api_test_setup()) { \
78 VM_API_TEST_CLEANUP; \
79 ast_test_status_update(test, "Failed to set up necessary mock objects for voicemail API test\n"); \
80 return AST_TEST_FAIL; \
81 } else { \
82 int i = 0; \
83 for (; i < TOTAL_SNAPSHOTS; i++) { \
84 ast_test_status_update(test, "Created message in %s/%s with ID %s\n", \
85 test_snapshots[i]->exten, test_snapshots[i]->folder_name, test_snapshots[i]->msg_id); \
86 } \
87} } while (0)
88
89/*!
90 * \internal
91 * \brief Safely cleanup after a test run.
92 *
93 * \note This should be called both when a test fails and when it passes
94 */
95#define VM_API_TEST_CLEANUP test_vm_api_test_teardown()
96
97/*!
98 * \internal
99 * \brief Safely cleanup a snapshot and a test run.
100 *
101 * \note It assumes that the mailbox snapshot object is test_mbox_snapshot
102 */
103#define VM_API_SNAPSHOT_TEST_CLEANUP \
104 if (test_mbox_snapshot) { \
105 test_mbox_snapshot = ast_vm_mailbox_snapshot_destroy(test_mbox_snapshot); \
106 } \
107 VM_API_TEST_CLEANUP; \
108
109/*!
110 * \internal
111 * \brief Verify the expected result from two string values obtained
112 * from a mailbox snapshot.
113 *
114 * \note It assumes the mailbox snapshot object is test_mbox_snapshot
115 */
116#define VM_API_STRING_FIELD_VERIFY(expected, actual) do { \
117 if (strcmp((expected), (actual))) { \
118 ast_test_status_update(test, "Test failed for parameter %s: Expected [%s], Actual [%s]\n", #actual, expected, actual); \
119 VM_API_SNAPSHOT_TEST_CLEANUP; \
120 return AST_TEST_FAIL; \
121 } } while (0)
122
123/*!
124 * \internal
125 * \brief Verify the expected result from two integer values.
126 *
127 * \note It assumes the mailbox snapshot object is test_mbox_snapshot
128 */
129#define VM_API_INT_VERIFY(expected, actual) do { \
130 if ((expected) != (actual)) { \
131 ast_test_status_update(test, "Test failed for parameter %s: Expected [%d], Actual [%d]\n", #actual, (int)expected, (int)actual); \
132 VM_API_SNAPSHOT_TEST_CLEANUP; \
133 return AST_TEST_FAIL; \
134 } } while (0)
135
136/*!
137 * \internal
138 * \brief Verify that a mailbox snapshot contains the expected message
139 * snapshot, in the correct position, with the expected values.
140 *
141 * \note It assumes the mailbox snapshot object is test_mbox_snapshot
142 */
143#define VM_API_SNAPSHOT_MSG_VERIFY(expected, actual, expected_folder, expected_index) do { \
144 struct ast_vm_msg_snapshot *msg; \
145 int found = 0; \
146 int counter = 0; \
147 AST_LIST_TRAVERSE(&((actual)->snapshots[get_folder_by_name(expected_folder)]), msg, msg) { \
148 if (!(strcmp(msg->msg_id, (expected)->msg_id))) { \
149 ast_test_status_update(test, "Found message %s in snapshot\n", msg->msg_id); \
150 found = 1; \
151 if ((expected_index) != counter) { \
152 ast_test_status_update(test, "Expected message %s at index %d; Actual [%d]\n", \
153 (expected)->msg_id, (expected_index), counter); \
154 VM_API_SNAPSHOT_TEST_CLEANUP; \
155 return AST_TEST_FAIL; \
156 } \
157 VM_API_STRING_FIELD_VERIFY((expected)->callerid, msg->callerid); \
158 VM_API_STRING_FIELD_VERIFY((expected)->callerchan, msg->callerchan); \
159 VM_API_STRING_FIELD_VERIFY((expected)->exten, msg->exten); \
160 VM_API_STRING_FIELD_VERIFY((expected)->origdate, msg->origdate); \
161 VM_API_STRING_FIELD_VERIFY((expected)->origtime, msg->origtime); \
162 VM_API_STRING_FIELD_VERIFY((expected)->duration, msg->duration); \
163 VM_API_STRING_FIELD_VERIFY((expected)->folder_name, msg->folder_name); \
164 VM_API_STRING_FIELD_VERIFY((expected)->flag, msg->flag); \
165 VM_API_INT_VERIFY((expected)->msg_number, msg->msg_number); \
166 break; \
167 } \
168 ++counter; \
169 } \
170 if (!found) { \
171 ast_test_status_update(test, "Test failed for message snapshot %s: not found in mailbox snapshot\n", (expected)->msg_id); \
172 VM_API_SNAPSHOT_TEST_CLEANUP; \
173 return AST_TEST_FAIL; \
174} } while (0)
175
176
177/*!
178 * \internal
179 * \brief Create a message snapshot, failing the test if the snapshot could not be created.
180 *
181 * \note This requires having a snapshot named test_mbox_snapshot.
182 */
183#define VM_API_SNAPSHOT_CREATE(mailbox, context, folder, desc, sort, old_and_inbox) do { \
184 if (!(test_mbox_snapshot = ast_vm_mailbox_snapshot_create( \
185 (mailbox), (context), (folder), (desc), (sort), (old_and_inbox)))) { \
186 ast_test_status_update(test, "Failed to create voicemail mailbox snapshot\n"); \
187 VM_API_TEST_CLEANUP; \
188 return AST_TEST_FAIL; \
189 } } while (0)
190
191/*!
192 * \internal
193 * \brief Create a message snapshot, failing the test if the snapshot could be created.
194 *
195 * \note This is used to test off nominal conditions.
196 * \note This requires having a snapshot named test_mbox_snapshot.
197 */
198#define VM_API_SNAPSHOT_OFF_NOMINAL_TEST(mailbox, context, folder, desc, sort, old_and_inbox) do { \
199 if ((test_mbox_snapshot = ast_vm_mailbox_snapshot_create( \
200 (mailbox), (context), (folder), (desc), (sort), (old_and_inbox)))) { \
201 ast_test_status_update(test, "Created mailbox snapshot when none was expected\n"); \
202 test_mbox_snapshot = ast_vm_mailbox_snapshot_destroy(test_mbox_snapshot); \
203 VM_API_TEST_CLEANUP; \
204 return AST_TEST_FAIL; \
205 } } while (0)
206
207/*!
208 * \internal
209 * \brief Move a voicemail message, failing the test if the message could not be moved
210 */
211#define VM_API_MOVE_MESSAGE(mailbox, context, number_of_messages, source, message_numbers_in, dest) do { \
212 if (ast_vm_msg_move((mailbox), (context), (number_of_messages), (source), (message_numbers_in), (dest))) { \
213 ast_test_status_update(test, "Failed to move message %s@%s from %s to %s\n", \
214 (mailbox) ? (mailbox): "(NULL)", (context) ? (context) : "(NULL)", (source) ? (source) : "(NULL)", (dest) ? (dest) : "(NULL)"); \
215 VM_API_TEST_CLEANUP; \
216 return AST_TEST_FAIL; \
217 } } while (0)
218
219/*!
220 * \internal
221 * \brief Attempt to move a voicemail message, failing the test if the message could be moved
222 */
223#define VM_API_MOVE_MESSAGE_OFF_NOMINAL(mailbox, context, number_of_messages, source, message_numbers_in, dest) do { \
224 if (!ast_vm_msg_move((mailbox), (context), (number_of_messages), (source), (message_numbers_in), (dest))) { \
225 ast_test_status_update(test, "Succeeded to move message %s@%s from %s to %s when we really shouldn't\n", \
226 (mailbox) ? (mailbox): "(NULL)", (context) ? (context) : "(NULL)", (source) ? (source) : "(NULL)", (dest) ? (dest) : "(NULL)"); \
227 VM_API_TEST_CLEANUP; \
228 return AST_TEST_FAIL; \
229 } } while (0)
230
231/*!
232 * \internal
233 * \brief Remove a message, failing the test if the method failed or if the message is still present.
234 */
235#define VM_API_REMOVE_MESSAGE(mailbox, context, number_of_messages, folder, message_numbers_in) do { \
236 if (ast_vm_msg_remove((mailbox), (context), (number_of_messages), (folder), (message_numbers_in))) { \
237 ast_test_status_update(test, "Failed to remove message from mailbox %s@%s, folder %s", \
238 (mailbox) ? (mailbox): "(NULL)", (context) ? (context) : "(NULL)", (folder) ? (folder) : "(NULL)"); \
239 VM_API_TEST_CLEANUP; \
240 return AST_TEST_FAIL; \
241 } \
242 VM_API_SNAPSHOT_CREATE((mailbox), (context), (folder), 0, AST_VM_SNAPSHOT_SORT_BY_TIME, 0); \
243 VM_API_INT_VERIFY(0, test_mbox_snapshot->total_msg_num); \
244 test_mbox_snapshot = ast_vm_mailbox_snapshot_destroy(test_mbox_snapshot); \
245} while (0)
246
247/*!
248 * \internal
249 * \brief Remove a message, failing the test if the method succeeds
250 */
251#define VM_API_REMOVE_MESSAGE_OFF_NOMINAL(mailbox, context, number_of_messages, folder, message_numbers_in) do { \
252 if (!ast_vm_msg_remove((mailbox), (context), (number_of_messages), (folder), (message_numbers_in))) { \
253 ast_test_status_update(test, "Succeeded in removing message from mailbox %s@%s, folder %s, when expected result was failure\n", \
254 (mailbox) ? (mailbox): "(NULL)", (context) ? (context) : "(NULL)", (folder) ? (folder) : "(NULL)"); \
255 VM_API_TEST_CLEANUP; \
256 return AST_TEST_FAIL; \
257 } } while (0)
258
259/*!
260 * \internal
261 * \brief Forward a message, failing the test if the message could not be forwarded
262 */
263# 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) do { \
264 if (ast_vm_msg_forward((from_mailbox), (from_context), (from_folder), (to_mailbox), (to_context), (to_folder), (number_of_messages), (message_numbers_in), (delete_old))) { \
265 ast_test_status_update(test, "Failed to forward message from %s@%s [%s] to %s@%s [%s]\n", \
266 (from_mailbox) ? (from_mailbox) : "(NULL)", (from_context) ? (from_context) : "(NULL)", (from_folder) ? (from_folder) : "(NULL)", \
267 (to_mailbox) ? (to_mailbox) : "(NULL)", (to_context) ? (to_context) : "(NULL)", (to_folder) ? (to_folder) : "(NULL)"); \
268 VM_API_TEST_CLEANUP; \
269 return AST_TEST_FAIL; \
270 } } while (0)
271
272/*!
273 * \internal
274 * \brief Forward a message, failing the test if the message was successfully forwarded
275 */
276#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) do { \
277 if (!ast_vm_msg_forward((from_mailbox), (from_context), (from_folder), (to_mailbox), (to_context), (to_folder), (number_of_messages), (message_numbers_in), (delete_old))) { \
278 ast_test_status_update(test, "Succeeded in forwarding message from %s@%s [%s] to %s@%s [%s] when expected result was fail\n", \
279 (from_mailbox) ? (from_mailbox) : "(NULL)", (from_context) ? (from_context) : "(NULL)", (from_folder) ? (from_folder) : "(NULL)", \
280 (to_mailbox) ? (to_mailbox) : "(NULL)", (to_context) ? (to_context) : "(NULL)", (to_folder) ? (to_folder) : "(NULL)"); \
281 VM_API_TEST_CLEANUP; \
282 return AST_TEST_FAIL; \
283 } } while (0)
284
285/*!
286 * \internal
287 * \brief Playback a message on a channel or callback function
288 *
289 * \note The channel name must be test_channel.
290 * \note Fail the test if the message could not be played.
291 */
292#define VM_API_PLAYBACK_MESSAGE(channel, mailbox, context, folder, message, callback_fn) do { \
293 if (ast_vm_msg_play((channel), (mailbox), (context), (folder), (message), (callback_fn))) { \
294 ast_test_status_update(test, "Failed nominal playback message test\n"); \
295 ast_hangup(test_channel); \
296 VM_API_TEST_CLEANUP; \
297 return AST_TEST_FAIL; \
298 } } while (0)
299
300/*!
301 * \internal
302 * \brief Playback a message on a channel or callback function.
303 *
304 * \note The channel name must be test_channel.
305 * \note Fail the test if the message is successfully played
306 */
307#define VM_API_PLAYBACK_MESSAGE_OFF_NOMINAL(channel, mailbox, context, folder, message, callback_fn) do { \
308 if (!ast_vm_msg_play((channel), (mailbox), (context), (folder), (message), (callback_fn))) { \
309 ast_test_status_update(test, "Succeeded in playing back of message when expected result was to fail\n"); \
310 ast_hangup(test_channel); \
311 VM_API_TEST_CLEANUP; \
312 return AST_TEST_FAIL; \
313 } } while (0)
314
315
316/*!
317 * \internal
318 * \brief Possible names of folders.
319 *
320 * \note Taken from app_voicemail
321 */
322static const char * const mailbox_folders[] = {
323 "INBOX",
324 "Old",
325 "Work",
326 "Family",
327 "Friends",
328 "Cust1",
329 "Cust2",
330 "Cust3",
331 "Cust4",
332 "Cust5",
333 "Deleted",
334 "Urgent",
335};
336
337/*!
338 * \internal
339 * \brief Message snapshots representing the messages that are used by the various tests
340 */
342
343/*!
344 * \internal
345 * \brief Tracks whether or not we entered into the message playback callback function
346 */
348
349/*!
350 * \internal
351 * \brief Get a folder index by its name
352 */
353static int get_folder_by_name(const char *folder)
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}
365
366/*!
367 * \internal
368 * \brief Get a mock snapshot object
369 *
370 * \param context The mailbox context
371 * \param exten The mailbox extension
372 * \param callerid The caller ID of the person leaving the message
373 *
374 * \returns an ast_vm_msg_snapshot object on success
375 * \returns NULL on error
376 */
377static struct ast_vm_msg_snapshot *test_vm_api_create_mock_snapshot(const char *context, const char *exten, const char *callerid)
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}
397
398/*!
399 * \internal
400 * \brief Destroy a mock snapshot object
401 */
403{
404 if (snapshot) {
406 ast_free(snapshot);
407 }
408}
409
410/*!
411 * \internal
412 * \brief Make a voicemail mailbox folder based on the values provided in a message snapshot
413 *
414 * \param folder_path The snapshot containing the information to create the folder from
415 *
416 * \returns 0 on success
417 * \returns 1 on failure
418 */
419static int test_vm_api_create_voicemail_folder(const char *folder_path)
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}
430
431/*!
432 * \internal
433 * \brief Create the voicemail files specified by a snapshot
434 *
435 * \param context The context of the mailbox
436 * \param mailbox The actual mailbox
437 * \param snapshot The message snapshot object containing the relevant envelope data
438 *
439 * \note This will symbolic link the sound file 'beep.gsm' to act as the 'sound' portion of the voicemail.
440 * Certain actions in app_voicemail will fail if an actual sound file does not exist
441 *
442 * \returns 0 on success
443 * \returns 1 on any failure
444 */
445static int test_vm_api_create_voicemail_files(const char *context, const char *mailbox, struct ast_vm_msg_snapshot *snapshot)
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}
528
529/*!
530 * \internal
531 * \brief Destroy the voicemail on the file system associated with a snapshot
532 *
533 * \param snapshot The snapshot describing the voicemail
534 */
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}
557
558/*!
559 * \internal
560 * \brief Destroy the voicemails associated with a mailbox snapshot
561 *
562 * \param mailbox The actual mailbox name
563 * \param mailbox_snapshot The mailbox snapshot containing the voicemails to destroy
564 *
565 * \note It is necessary to specify not just the snapshot, but the mailbox itself. The
566 * message snapshots contained in the snapshot may have originated from a different mailbox
567 * then the one we're destroying, which means that we can't determine the files to delete
568 * without knowing the actual mailbox they exist in.
569 */
570static void test_vm_api_destroy_mailbox_voicemails(const char *mailbox, struct ast_vm_mailbox_snapshot *mailbox_snapshot)
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}
582
583/*!
584 * \internal
585 * \brief Use snapshots to remove all messages in the mailboxes
586 */
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}
607
608/*!
609 * \internal
610 * \brief Set up the necessary voicemails for a unit test run
611 *
612 * \details
613 * This creates 4 voicemails, stores them on the file system, and creates snapshot objects
614 * representing them for expected/actual value comparisons in the array test_snapshots.
615 *
616 * test_snapshots[0] => in test_vm_1234\@default, folder INBOX, message 0
617 * test_snapshots[1] => in test_vm_1234\@default, folder Old, message 0
618 * test_snapshots[2] => in test_vm_2345\@default, folder INBOX, message 0
619 * test_snapshots[3] => in test_vm_2345\@default, folder Old, message 1
620 *
621 * \returns 0 on success
622 * \returns 1 on failure
623 */
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}
713
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}
731
732/*!
733 * \internal
734 * \brief Update the test snapshots with a new mailbox snapshot
735 *
736 * \param mailbox_snapshot The new mailbox shapshot to update the test snapshots with
737 */
739{
740 int i, j;
741 struct ast_vm_msg_snapshot *msg;
742
743 for (i = 0; i < TOTAL_SNAPSHOTS; ++i) {
744 for (j = 0; j < 12; ++j) {
745 AST_LIST_TRAVERSE(&mailbox_snapshot->snapshots[j], msg, msg) {
746 if (!strcmp(msg->msg_id, test_snapshots[i]->msg_id)) {
755 test_snapshots[i]->msg_number = msg->msg_number;
756 }
757 }
758 }
759 }
760}
761
762/*!
763 * \internal
764 * \brief A callback function for message playback
765 *
766 * \param chan The channel the file would be played back on
767 * \param file The file to play back
768 * \param duration The duration of the file
769 *
770 * \note This sets global_entered_playback_callback to 1 if the parameters
771 * passed to the callback are minimally valid
772 */
773static void message_playback_callback_fn(struct ast_channel *chan, const char *file, int duration)
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}
781
782/*!
783 * \internal
784 * \brief Dummy channel write function for mock_channel_tech
785 */
786static int test_vm_api_mock_channel_write(struct ast_channel *chan, struct ast_frame *frame)
787{
788 return 0;
789}
790
791/*!
792 * \internal
793 * \brief Dummy channel read function for mock_channel_tech
794 */
796{
797 return &ast_null_frame;
798}
799
800/*!
801 * \internal
802 * \brief A dummy channel technology
803 */
804static const struct ast_channel_tech mock_channel_tech = {
807};
808
809/*!
810 * \internal
811 * \brief Create a dummy channel suitable for 'playing back' gsm sound files on
812 *
813 * \returns a channel on success
814 * \returns NULL on failure
815 */
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}
837
838AST_TEST_DEFINE(voicemail_api_nominal_snapshot)
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}
921
922AST_TEST_DEFINE(voicemail_api_off_nominal_snapshot)
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}
963
964AST_TEST_DEFINE(voicemail_api_nominal_move)
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}
1034
1035AST_TEST_DEFINE(voicemail_api_off_nominal_move)
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}
1110
1111AST_TEST_DEFINE(voicemail_api_nominal_remove)
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}
1152
1153AST_TEST_DEFINE(voicemail_api_off_nominal_remove)
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}
1217
1218AST_TEST_DEFINE(voicemail_api_nominal_forward)
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}
1325
1326AST_TEST_DEFINE(voicemail_api_off_nominal_forward)
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}
1410
1411AST_TEST_DEFINE(voicemail_api_nominal_msg_playback)
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}
1469
1470AST_TEST_DEFINE(voicemail_api_off_nominal_msg_playback)
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}
1527
1528static int unload_module(void)
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}
1551
1552static int load_module(void)
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}
1576
1577AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "Core Voicemail API Tests");
Asterisk main include file. File version handling, generic pbx functions.
#define PATH_MAX
Definition: asterisk.h:40
#define ast_free(a)
Definition: astmm.h:180
#define ast_calloc(num, len)
A wrapper for calloc()
Definition: astmm.h:202
#define ast_log
Definition: astobj2.c:42
General Asterisk PBX channel definitions.
void ast_hangup(struct ast_channel *chan)
Hang up a channel.
Definition: channel.c:2541
#define ast_channel_alloc(needqueue, state, cid_num, cid_name, acctcode, exten, context, assignedids, requestor, amaflag,...)
Create a channel structure.
Definition: channel.h:1258
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)
#define AST_MAX_CONTEXT
Definition: channel.h:135
void ast_channel_tech_set(struct ast_channel *chan, const struct ast_channel_tech *value)
#define ast_channel_unlock(chan)
Definition: channel.h:2923
#define AST_MAX_EXTENSION
Definition: channel.h:134
void ast_channel_set_writeformat(struct ast_channel *chan, struct ast_format *format)
@ AST_STATE_DOWN
Definition: channelstate.h:36
long int flag
Definition: f2c.h:83
Media Format Cache API.
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
Application convenience functions, designed to give consistent look and feel to Asterisk apps.
@ AST_LOCK_FAILURE
@ AST_VM_SNAPSHOT_SORT_BY_ID
@ AST_VM_SNAPSHOT_SORT_BY_TIME
enum AST_LOCK_RESULT ast_lock_path(const char *path)
Lock a filesystem path.
Definition: main/app.c:2604
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
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
int ast_unlock_path(const char *path)
Unlock a path.
Definition: main/app.c:2620
struct ast_frame ast_null_frame
Definition: main/frame.c:79
#define AST_LOG_WARNING
#define AST_LOG_ERROR
#define AST_LIST_TRAVERSE(head, var, field)
Loops over (traverses) the entries in a list.
Definition: linkedlists.h:491
int errno
Asterisk module definitions.
#define AST_MODULE_INFO_STANDARD(keystr, desc)
Definition: module.h:567
#define ASTERISK_GPL_KEY
The text the key() function should return.
Definition: module.h:46
@ AST_MODULE_LOAD_SUCCESS
Definition: module.h:70
def info(msg)
Asterisk file paths, configured in asterisk.conf.
const char * ast_config_AST_DATA_DIR
Definition: options.c:158
const char * ast_config_AST_SPOOL_DIR
Definition: options.c:154
#define NULL
Definition: resample.c:96
#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
#define ast_string_field_free_memory(x)
free all memory - to be called before destroying the object
Definition: stringfields.h:374
static force_inline int attribute_pure ast_str_hash(const char *str)
Compute a hash value on a string.
Definition: strings.h:1259
static force_inline int attribute_pure ast_strlen_zero(const char *s)
Definition: strings.h:65
Structure to describe a channel "technology", ie a channel driver See for examples:
Definition: channel.h:628
int(*const write)(struct ast_channel *chan, struct ast_frame *frame)
Write a frame, in standard format (see frame.h)
Definition: channel.h:750
Main Channel structure associated with a channel.
Format capabilities structure, holds formats + preference order + etc.
Definition: format_cap.c:54
Data structure associated with a single frame of data.
struct ast_vm_mailbox_snapshot::@185 * snapshots
const ast_string_field folder_name
const ast_string_field callerid
const ast_string_field origtime
struct ast_vm_msg_snapshot::@184 msg
const ast_string_field msg_id
const ast_string_field exten
const ast_string_field callerchan
const ast_string_field duration
const ast_string_field origdate
const ast_string_field flag
Test Framework API.
@ TEST_INIT
Definition: test.h:200
@ TEST_EXECUTE
Definition: test.h:201
#define AST_TEST_REGISTER(cb)
Definition: test.h:127
#define ast_test_status_update(a, b, c...)
Definition: test.h:129
#define AST_TEST_UNREGISTER(cb)
Definition: test.h:128
@ AST_TEST_PASS
Definition: test.h:195
@ AST_TEST_FAIL
Definition: test.h:196
@ AST_TEST_NOT_RUN
Definition: test.h:194
#define VM_API_STRING_FIELD_VERIFY(expected, actual)
#define VM_API_INT_VERIFY(expected, actual)
#define VM_API_SNAPSHOT_MSG_VERIFY(expected, actual, expected_folder, expected_index)
#define TOTAL_SNAPSHOTS
#define VOICEMAIL_DIR_MODE
static int test_vm_api_mock_channel_write(struct ast_channel *chan, struct ast_frame *frame)
static void test_vm_api_destroy_mailbox_voicemails(const char *mailbox, struct ast_vm_mailbox_snapshot *mailbox_snapshot)
static int test_vm_api_test_setup(void)
#define VM_API_MOVE_MESSAGE_OFF_NOMINAL(mailbox, context, number_of_messages, source, message_numbers_in, dest)
static struct ast_frame * test_vm_api_mock_channel_read(struct ast_channel *chan)
static void test_vm_api_test_teardown(void)
static struct ast_vm_msg_snapshot * test_snapshots[TOTAL_SNAPSHOTS]
static void test_vm_api_destroy_mock_snapshot(struct ast_vm_msg_snapshot *snapshot)
#define VM_API_SNAPSHOT_CREATE(mailbox, context, folder, desc, sort, old_and_inbox)
#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_TEST_CLEANUP
static void test_vm_api_remove_all_messages(void)
#define VM_API_MOVE_MESSAGE(mailbox, context, number_of_messages, source, message_numbers_in, dest)
static struct ast_vm_msg_snapshot * test_vm_api_create_mock_snapshot(const char *context, const char *exten, const char *callerid)
#define VM_API_PLAYBACK_MESSAGE_OFF_NOMINAL(channel, mailbox, context, folder, message, callback_fn)
static void test_vm_api_remove_voicemail(struct ast_vm_msg_snapshot *snapshot)
#define VM_API_REMOVE_MESSAGE_OFF_NOMINAL(mailbox, context, number_of_messages, folder, message_numbers_in)
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)
static const struct ast_channel_tech mock_channel_tech
#define VM_API_PLAYBACK_MESSAGE(channel, mailbox, context, folder, message, callback_fn)
static int load_module(void)
static int global_entered_playback_callback
#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)
static int unload_module(void)
AST_TEST_DEFINE(voicemail_api_nominal_snapshot)
static int test_vm_api_create_voicemail_files(const char *context, const char *mailbox, struct ast_vm_msg_snapshot *snapshot)
#define VOICEMAIL_FILE_MODE
static int get_folder_by_name(const char *folder)
#define VM_API_TEST_SETUP
#define VM_API_SNAPSHOT_OFF_NOMINAL_TEST(mailbox, context, folder, desc, sort, old_and_inbox)
static int test_vm_api_create_voicemail_folder(const char *folder_path)
static void test_vm_api_update_test_snapshots(struct ast_vm_mailbox_snapshot *mailbox_snapshot)
static const char *const mailbox_folders[]
#define VM_API_REMOVE_MESSAGE(mailbox, context, number_of_messages, folder, message_numbers_in)
Utility functions.
int ast_mkdir(const char *path, int mode)
Recursively create directory path.
Definition: utils.c:2479
#define ARRAY_LEN(a)
Definition: utils.h:666