2 * Asterisk -- An open source telephony toolkit.
4 * Copyright (C) 2013, Digium, Inc.
6 * Kinsey Moore <kmoore@digium.com>
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.
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.
21 * \brief CEL unit tests
23 * \author Kinsey Moore <kmoore@digium.com>
28 <depend>TEST_FRAMEWORK</depend>
29 <support_level>core</support_level>
34 ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
37 #include "asterisk/module.h"
38 #include "asterisk/test.h"
39 #include "asterisk/cel.h"
40 #include "asterisk/channel.h"
41 #include "asterisk/linkedlists.h"
42 #include "asterisk/chanvars.h"
43 #include "asterisk/utils.h"
44 #include "asterisk/causes.h"
45 #include "asterisk/time.h"
46 #include "asterisk/bridge.h"
47 #include "asterisk/bridge_basic.h"
48 #include "asterisk/pickup.h"
49 #include "asterisk/stasis_channels.h"
50 #include "asterisk/stasis_bridges.h"
51 #include "asterisk/json.h"
52 #include "asterisk/features.h"
53 #include "asterisk/core_local.h"
55 #define TEST_CATEGORY "/main/cel/"
57 #define CHANNEL_TECH_NAME "CELTestChannel"
59 #define TEST_BACKEND_NAME "CEL Test Logging"
61 /*! \brief A placeholder for Asterisk's 'real' CEL configuration */
62 static struct ast_cel_general_config *saved_config;
64 /*! \brief The CEL config used for CEL unit tests */
65 static struct ast_cel_general_config *cel_test_config;
67 /*! \brief Lock used for synchronizing test execution stages with received events */
68 ast_mutex_t mid_test_sync_lock;
70 /*! \brief Lock used with sync_out for checking the end of test execution */
71 ast_mutex_t sync_lock;
73 /*! \brief Condition used for checking the end of test execution */
76 /*! \brief Flag used to trigger a mid-test synchronization, access controlled by mid_test_sync_lock */
77 int do_mid_test_sync = 0;
79 /*! \brief A channel technology used for the unit tests */
80 static struct ast_channel_tech test_cel_chan_tech = {
81 .type = CHANNEL_TECH_NAME,
82 .description = "Mock channel technology for CEL tests",
85 /*! \brief A 1 second sleep */
86 static struct timespec to_sleep = {1, 0};
88 static void do_sleep(void)
90 while ((nanosleep(&to_sleep, &to_sleep) == -1) && (errno == EINTR));
93 #define APPEND_EVENT(chan, ev_type, userevent, extra) do { \
94 if (append_expected_event(chan, ev_type, userevent, extra)) { \
95 return AST_TEST_FAIL; \
99 #define APPEND_EVENT_SNAPSHOT(snapshot, ev_type, userevent, extra) do { \
100 if (append_expected_event_snapshot(snapshot, ev_type, userevent, extra)) { \
101 return AST_TEST_FAIL; \
105 #define APPEND_DUMMY_EVENT() do { \
106 if (append_dummy_event()) { \
107 return AST_TEST_FAIL; \
111 #define BRIDGE_EXIT(channel, bridge) do { \
112 ast_test_validate(test, 0 == ast_bridge_depart(channel)); \
113 BRIDGE_EXIT_EVENT(channel, bridge); \
117 #define BRIDGE_EXIT_EVENT(channel, bridge) do { \
118 RAII_VAR(struct ast_json *, extra, NULL, ast_json_unref); \
119 extra = ast_json_pack("{s: s}", "bridge_id", bridge->uniqueid); \
120 ast_test_validate(test, extra != NULL); \
121 APPEND_EVENT(channel, AST_CEL_BRIDGE_EXIT, NULL, extra); \
124 #define BRIDGE_EXIT_SNAPSHOT(channel, bridge) do { \
125 RAII_VAR(struct ast_json *, extra, NULL, ast_json_unref); \
126 extra = ast_json_pack("{s: s}", "bridge_id", bridge->uniqueid); \
127 ast_test_validate(test, extra != NULL); \
128 APPEND_EVENT_SNAPSHOT(channel, AST_CEL_BRIDGE_EXIT, NULL, extra); \
131 #define BRIDGE_ENTER(channel, bridge) do { \
132 ast_test_validate(test, 0 == ast_bridge_impart(bridge, channel, NULL, NULL, 0)); \
134 BRIDGE_ENTER_EVENT(channel, bridge); \
138 #define BRIDGE_ENTER_EVENT(channel, bridge) do { \
139 RAII_VAR(struct ast_json *, extra, NULL, ast_json_unref); \
140 extra = ast_json_pack("{s: s}", "bridge_id", bridge->uniqueid); \
141 ast_test_validate(test, extra != NULL); \
142 APPEND_EVENT(channel, AST_CEL_BRIDGE_ENTER, NULL, extra); \
145 #define BLINDTRANSFER_EVENT(channel, bridge, extension, context) do { \
146 RAII_VAR(struct ast_json *, extra, NULL, ast_json_unref); \
147 extra = ast_json_pack("{s: s, s: s, s: s}", \
148 "extension", extension, \
149 "context", context, \
150 "bridge_id", bridge->uniqueid); \
151 ast_test_validate(test, extra != NULL); \
152 APPEND_EVENT(channel, AST_CEL_BLINDTRANSFER, NULL, extra); \
155 #define ATTENDEDTRANSFER_BRIDGE(channel1, bridge1, channel2, bridge2) do { \
156 RAII_VAR(struct ast_json *, extra, NULL, ast_json_unref); \
157 extra = ast_json_pack("{s: s, s: s, s: s}", \
158 "bridge1_id", bridge1->uniqueid, \
159 "channel2_name", ast_channel_name(channel2), \
160 "bridge2_id", bridge2->uniqueid); \
161 ast_test_validate(test, extra != NULL); \
162 APPEND_EVENT(channel1, AST_CEL_ATTENDEDTRANSFER, NULL, extra); \
165 /*! \brief Alice's Caller ID */
166 #define ALICE_CALLERID { .id.name.str = "Alice", .id.name.valid = 1, .id.number.str = "100", .id.number.valid = 1, }
168 /*! \brief Bob's Caller ID */
169 #define BOB_CALLERID { .id.name.str = "Bob", .id.name.valid = 1, .id.number.str = "200", .id.number.valid = 1, }
171 /*! \brief Charlie's Caller ID */
172 #define CHARLIE_CALLERID { .id.name.str = "Charlie", .id.name.valid = 1, .id.number.str = "300", .id.number.valid = 1, }
174 /*! \brief David's Caller ID */
175 #define DAVID_CALLERID { .id.name.str = "David", .id.name.valid = 1, .id.number.str = "400", .id.number.valid = 1, }
177 /*! \brief Create a \ref test_cel_chan_tech for Alice. */
178 #define CREATE_ALICE_CHANNEL(channel_var, caller_id) do { \
179 (channel_var) = ast_channel_alloc(0, AST_STATE_DOWN, (caller_id)->id.number.str, (caller_id)->id.name.str, "100", "100", "default", NULL, 0, CHANNEL_TECH_NAME "/Alice"); \
180 APPEND_EVENT(channel_var, AST_CEL_CHANNEL_START, NULL, NULL); \
183 /*! \brief Create a \ref test_cel_chan_tech for Bob. */
184 #define CREATE_BOB_CHANNEL(channel_var, caller_id) do { \
185 (channel_var) = ast_channel_alloc(0, AST_STATE_DOWN, (caller_id)->id.number.str, (caller_id)->id.name.str, "200", "200", "default", NULL, 0, CHANNEL_TECH_NAME "/Bob"); \
186 APPEND_EVENT(channel_var, AST_CEL_CHANNEL_START, NULL, NULL); \
189 /*! \brief Create a \ref test_cel_chan_tech for Charlie. */
190 #define CREATE_CHARLIE_CHANNEL(channel_var, caller_id) do { \
191 (channel_var) = ast_channel_alloc(0, AST_STATE_DOWN, (caller_id)->id.number.str, (caller_id)->id.name.str, "300", "300", "default", NULL, 0, CHANNEL_TECH_NAME "/Charlie"); \
192 APPEND_EVENT(channel_var, AST_CEL_CHANNEL_START, NULL, NULL); \
195 /*! \brief Create a \ref test_cel_chan_tech for David. */
196 #define CREATE_DAVID_CHANNEL(channel_var, caller_id) do { \
197 (channel_var) = ast_channel_alloc(0, AST_STATE_DOWN, (caller_id)->id.number.str, (caller_id)->id.name.str, "400", "400", "default", NULL, 0, CHANNEL_TECH_NAME "/David"); \
198 APPEND_EVENT(channel_var, AST_CEL_CHANNEL_START, NULL, NULL); \
201 /*! \brief Emulate a channel entering into an application */
202 #define EMULATE_APP_DATA(channel, priority, application, data) do { \
203 if ((priority) > 0) { \
204 ast_channel_priority_set((channel), (priority)); \
206 ast_channel_appl_set((channel), (application)); \
207 ast_channel_data_set((channel), (data)); \
208 ast_channel_publish_snapshot((channel)); \
211 #define ANSWER_CHANNEL(chan) do { \
212 EMULATE_APP_DATA(chan, 1, "Answer", ""); \
213 ANSWER_NO_APP(chan); \
216 #define ANSWER_NO_APP(chan) do { \
217 ast_setstate(chan, AST_STATE_UP); \
218 APPEND_EVENT(chan, AST_CEL_ANSWER, NULL, NULL); \
221 /*! \brief Hang up a test channel safely */
222 #define HANGUP_CHANNEL(channel, cause, dialstatus) do { \
223 ast_channel_hangupcause_set((channel), (cause)); \
224 ao2_ref(channel, +1); \
225 ast_hangup((channel)); \
226 HANGUP_EVENT(channel, cause, dialstatus); \
227 APPEND_EVENT(channel, AST_CEL_CHANNEL_END, NULL, NULL); \
228 stasis_topic_wait(ast_channel_topic_all_cached()); \
229 ao2_cleanup(stasis_cache_get(ast_channel_cache(), \
230 ast_channel_snapshot_type(), ast_channel_uniqueid(channel))); \
231 ao2_cleanup(channel); \
235 #define HANGUP_EVENT(channel, cause, dialstatus) do { \
236 RAII_VAR(struct ast_json *, extra, NULL, ast_json_unref); \
237 extra = ast_json_pack("{s: i, s: s, s: s}", \
238 "hangupcause", cause, \
239 "hangupsource", "", \
240 "dialstatus", dialstatus); \
241 ast_test_validate(test, extra != NULL); \
242 APPEND_EVENT(channel, AST_CEL_HANGUP, NULL, extra); \
245 static void mid_test_sync(void);
247 static int append_expected_event(
248 struct ast_channel *chan,
249 enum ast_cel_event_type type,
250 const char *userdefevname,
251 struct ast_json *extra);
253 static int append_expected_event_snapshot(
254 struct ast_channel_snapshot *snapshot,
255 enum ast_cel_event_type type,
256 const char *userdefevname,
257 struct ast_json *extra);
259 static int append_dummy_event(void);
261 static void safe_channel_release(struct ast_channel *chan)
266 ast_channel_release(chan);
269 AST_TEST_DEFINE(test_cel_channel_creation)
271 RAII_VAR(struct ast_channel *, chan, NULL, safe_channel_release);
272 struct ast_party_caller caller = ALICE_CALLERID;
276 info->name = __func__;
277 info->category = TEST_CATEGORY;
278 info->summary = "Test the CEL records created when a channel is created";
280 "Test the CEL records created when a channel is created";
281 return AST_TEST_NOT_RUN;
286 CREATE_ALICE_CHANNEL(chan, (&caller));
288 HANGUP_CHANNEL(chan, AST_CAUSE_NORMAL, "");
290 return AST_TEST_PASS;
293 AST_TEST_DEFINE(test_cel_unanswered_inbound_call)
295 RAII_VAR(struct ast_channel *, chan, NULL, safe_channel_release);
296 struct ast_party_caller caller = ALICE_CALLERID;
300 info->name = __func__;
301 info->category = TEST_CATEGORY;
302 info->summary = "Test inbound unanswered calls";
304 "Test CEL records for a call that is\n"
305 "inbound to Asterisk, executes some dialplan, but\n"
306 "is never answered.\n";
307 return AST_TEST_NOT_RUN;
312 CREATE_ALICE_CHANNEL(chan, &caller);
314 EMULATE_APP_DATA(chan, 1, "Wait", "1");
316 HANGUP_CHANNEL(chan, AST_CAUSE_NORMAL, "");
318 return AST_TEST_PASS;
321 AST_TEST_DEFINE(test_cel_unanswered_outbound_call)
323 RAII_VAR(struct ast_channel *, chan, NULL, safe_channel_release);
324 struct ast_party_caller caller = {
328 .id.number.valid = 1, };
332 info->name = __func__;
333 info->category = TEST_CATEGORY;
334 info->summary = "Test outbound unanswered calls";
336 "Test CEL records for a call that is\n"
337 "outbound to Asterisk but is never answered.\n";
338 return AST_TEST_NOT_RUN;
343 CREATE_ALICE_CHANNEL(chan, &caller);
345 ast_channel_exten_set(chan, "s");
346 ast_channel_context_set(chan, "default");
347 ast_set_flag(ast_channel_flags(chan), AST_FLAG_ORIGINATED);
348 EMULATE_APP_DATA(chan, 0, "AppDial", "(Outgoing Line)");
349 HANGUP_CHANNEL(chan, AST_CAUSE_NORMAL, "");
351 return AST_TEST_PASS;
354 AST_TEST_DEFINE(test_cel_single_party)
356 RAII_VAR(struct ast_channel *, chan, NULL, safe_channel_release);
357 struct ast_party_caller caller = ALICE_CALLERID;
361 info->name = __func__;
362 info->category = TEST_CATEGORY;
363 info->summary = "Test CEL for a single party";
365 "Test CEL records for a call that is\n"
366 "answered, but only involves a single channel\n";
367 return AST_TEST_NOT_RUN;
371 CREATE_ALICE_CHANNEL(chan, &caller);
373 ANSWER_CHANNEL(chan);
374 EMULATE_APP_DATA(chan, 2, "VoiceMailMain", "1");
376 HANGUP_CHANNEL(chan, AST_CAUSE_NORMAL, "");
378 return AST_TEST_PASS;
381 AST_TEST_DEFINE(test_cel_single_bridge)
383 RAII_VAR(struct ast_channel *, chan, NULL, safe_channel_release);
384 RAII_VAR(struct ast_bridge *, bridge, NULL, ao2_cleanup);
386 struct ast_party_caller caller = ALICE_CALLERID;
390 info->name = __func__;
391 info->category = TEST_CATEGORY;
392 info->summary = "Test CEL for a single party entering/leaving a bridge";
394 "Test CEL records for a call that is\n"
395 "answered, enters a bridge, and leaves it.\n";
396 return AST_TEST_NOT_RUN;
400 bridge = ast_bridge_basic_new();
401 ast_test_validate(test, bridge != NULL);
403 CREATE_ALICE_CHANNEL(chan, &caller);
405 ANSWER_CHANNEL(chan);
406 EMULATE_APP_DATA(chan, 2, "Bridge", "");
409 BRIDGE_ENTER(chan, bridge);
413 BRIDGE_EXIT(chan, bridge);
415 HANGUP_CHANNEL(chan, AST_CAUSE_NORMAL, "");
417 return AST_TEST_PASS;
420 AST_TEST_DEFINE(test_cel_single_bridge_continue)
422 RAII_VAR(struct ast_channel *, chan, NULL, safe_channel_release);
423 RAII_VAR(struct ast_bridge *, bridge, NULL, ao2_cleanup);
424 struct ast_party_caller caller = ALICE_CALLERID;
428 info->name = __func__;
429 info->category = TEST_CATEGORY;
430 info->summary = "Test CEL for a single party entering/leaving a bridge";
432 "Test CEL records for a call that is\n"
433 "answered, enters a bridge, and leaves it.\n";
434 return AST_TEST_NOT_RUN;
438 bridge = ast_bridge_basic_new();
439 ast_test_validate(test, bridge != NULL);
441 CREATE_ALICE_CHANNEL(chan, &caller);
443 ANSWER_CHANNEL(chan);
444 EMULATE_APP_DATA(chan, 2, "Bridge", "");
447 BRIDGE_ENTER(chan, bridge);
451 BRIDGE_EXIT(chan, bridge);
453 EMULATE_APP_DATA(chan, 3, "Wait", "");
455 /* And then it hangs up */
456 HANGUP_CHANNEL(chan, AST_CAUSE_NORMAL, "");
458 return AST_TEST_PASS;
461 AST_TEST_DEFINE(test_cel_single_twoparty_bridge_a)
463 RAII_VAR(struct ast_channel *, chan_alice, NULL, safe_channel_release);
464 RAII_VAR(struct ast_channel *, chan_bob, NULL, safe_channel_release);
465 RAII_VAR(struct ast_bridge *, bridge, NULL, ao2_cleanup);
466 struct ast_party_caller caller_alice = ALICE_CALLERID;
467 struct ast_party_caller caller_bob = BOB_CALLERID;
471 info->name = __func__;
472 info->category = TEST_CATEGORY;
473 info->summary = "Test CEL for a single party entering/leaving a bridge";
475 "Test CEL records for a call that is\n"
476 "answered, enters a bridge, and leaves it. In this scenario, the\n"
477 "Party A should answer the bridge first.\n";
478 return AST_TEST_NOT_RUN;
482 bridge = ast_bridge_basic_new();
483 ast_test_validate(test, bridge != NULL);
485 CREATE_ALICE_CHANNEL(chan_alice, &caller_alice);
487 CREATE_BOB_CHANNEL(chan_bob, &caller_bob);
489 ANSWER_CHANNEL(chan_alice);
490 EMULATE_APP_DATA(chan_alice, 2, "Bridge", "");
492 BRIDGE_ENTER(chan_alice, bridge);
495 ANSWER_CHANNEL(chan_bob);
496 EMULATE_APP_DATA(chan_bob, 2, "Bridge", "");
498 BRIDGE_ENTER(chan_bob, bridge);
500 BRIDGE_EXIT(chan_alice, bridge);
501 BRIDGE_EXIT(chan_bob, bridge);
503 HANGUP_CHANNEL(chan_alice, AST_CAUSE_NORMAL, "");
504 HANGUP_CHANNEL(chan_bob, AST_CAUSE_NORMAL, "");
506 return AST_TEST_PASS;
509 AST_TEST_DEFINE(test_cel_single_twoparty_bridge_b)
511 RAII_VAR(struct ast_channel *, chan_alice, NULL, safe_channel_release);
512 RAII_VAR(struct ast_channel *, chan_bob, NULL, safe_channel_release);
513 RAII_VAR(struct ast_bridge *, bridge, NULL, ao2_cleanup);
514 struct ast_party_caller caller_alice = ALICE_CALLERID;
515 struct ast_party_caller caller_bob = BOB_CALLERID;
519 info->name = __func__;
520 info->category = TEST_CATEGORY;
521 info->summary = "Test CEL for a single party entering/leaving a bridge";
523 "Test CEL records for a call that is\n"
524 "answered, enters a bridge, and leaves it. In this scenario, the\n"
525 "Party B should answer the bridge first.\n";
526 return AST_TEST_NOT_RUN;
530 bridge = ast_bridge_basic_new();
531 ast_test_validate(test, bridge != NULL);
533 CREATE_ALICE_CHANNEL(chan_alice, &caller_alice);
535 CREATE_BOB_CHANNEL(chan_bob, &caller_bob);
537 ANSWER_CHANNEL(chan_alice);
538 EMULATE_APP_DATA(chan_alice, 2, "Bridge", "");
540 ANSWER_CHANNEL(chan_bob);
541 EMULATE_APP_DATA(chan_bob, 2, "Bridge", "");
544 BRIDGE_ENTER(chan_bob, bridge);
546 BRIDGE_ENTER(chan_alice, bridge);
548 BRIDGE_EXIT(chan_alice, bridge);
549 BRIDGE_EXIT(chan_bob, bridge);
551 HANGUP_CHANNEL(chan_alice, AST_CAUSE_NORMAL, "");
552 HANGUP_CHANNEL(chan_bob, AST_CAUSE_NORMAL, "");
554 return AST_TEST_PASS;
557 /* XXX Validation needs to be reworked on a per-channel basis before
558 * test_cel_single_multiparty_bridge and test_cel_dial_answer_multiparty
559 * can operate properly. */
561 AST_TEST_DEFINE(test_cel_single_multiparty_bridge)
563 RAII_VAR(struct ast_channel *, chan_alice, NULL, safe_channel_release);
564 RAII_VAR(struct ast_channel *, chan_bob, NULL, safe_channel_release);
565 RAII_VAR(struct ast_channel *, chan_charlie, NULL, safe_channel_release);
566 RAII_VAR(struct ast_bridge *, bridge, NULL, ao2_cleanup);
567 struct ast_party_caller caller_alice = ALICE_CALLERID;
568 struct ast_party_caller caller_bob = BOB_CALLERID;
569 struct ast_party_caller caller_charlie = CHARLIE_CALLERID;
573 info->name = __func__;
574 info->category = TEST_CATEGORY;
575 info->summary = "Test CEL for a single party entering/leaving a multi-party bridge";
577 "Test CEL records for a call that is\n"
578 "answered, enters a bridge, and leaves it. A total of three\n"
579 "parties perform this action.\n";
580 return AST_TEST_NOT_RUN;
584 bridge = ast_bridge_basic_new();
585 ast_test_validate(test, bridge != NULL);
587 CREATE_ALICE_CHANNEL(chan_alice, &caller_alice);
588 CREATE_BOB_CHANNEL(chan_bob, &caller_bob);
589 CREATE_CHARLIE_CHANNEL(chan_charlie, &caller_charlie);
591 ANSWER_CHANNEL(chan_alice);
592 EMULATE_APP_DATA(chan_alice, 2, "Bridge", "");
596 BRIDGE_ENTER(chan_alice, bridge);
598 ANSWER_CHANNEL(chan_bob);
599 EMULATE_APP_DATA(chan_bob, 2, "Bridge", "");
602 BRIDGE_ENTER(chan_bob, bridge);
604 ANSWER_CHANNEL(chan_charlie);
605 EMULATE_APP_DATA(chan_charlie, 2, "Bridge", "");
607 BRIDGE_ENTER(chan_charlie, bridge);
609 BRIDGE_EXIT(chan_alice, bridge);
610 BRIDGE_EXIT(chan_bob, bridge);
611 BRIDGE_EXIT(chan_charlie, bridge);
613 HANGUP_CHANNEL(chan_alice, AST_CAUSE_NORMAL, "");
614 HANGUP_CHANNEL(chan_bob, AST_CAUSE_NORMAL, "");
615 HANGUP_CHANNEL(chan_charlie, AST_CAUSE_NORMAL, "");
617 return AST_TEST_PASS;
621 #define EMULATE_DIAL(channel, dialstring) do { \
622 EMULATE_APP_DATA(channel, 1, "Dial", dialstring); \
623 if (append_expected_event(channel, AST_CEL_APP_START, NULL, NULL)) { \
624 return AST_TEST_FAIL; \
628 #define START_DIALED(caller, callee) \
629 START_DIALED_FULL(caller, callee, "200", "Bob")
631 #define START_DIALED_FULL(caller, callee, number, name) do { \
632 callee = ast_channel_alloc(0, AST_STATE_DOWN, NULL, NULL, number, NULL, NULL, ast_channel_linkedid(caller), 0, CHANNEL_TECH_NAME "/" name); \
633 if (append_expected_event(callee, AST_CEL_CHANNEL_START, NULL, NULL)) { \
634 return AST_TEST_FAIL; \
636 ast_set_flag(ast_channel_flags(callee), AST_FLAG_OUTGOING); \
637 EMULATE_APP_DATA(callee, 0, "AppDial", "(Outgoing Line)"); \
638 ast_channel_publish_dial(caller, callee, name, NULL); \
641 AST_TEST_DEFINE(test_cel_dial_unanswered)
643 RAII_VAR(struct ast_channel *, chan_caller, NULL, safe_channel_release);
644 RAII_VAR(struct ast_channel *, chan_callee, NULL, safe_channel_release);
645 struct ast_party_caller caller = ALICE_CALLERID;
649 info->name = __func__;
650 info->category = TEST_CATEGORY;
651 info->summary = "Test CEL for a dial that isn't answered";
653 "Test CEL records for a channel that\n"
654 "performs a dial operation that isn't answered\n";
655 return AST_TEST_NOT_RUN;
660 CREATE_ALICE_CHANNEL(chan_caller, &caller);
662 EMULATE_DIAL(chan_caller, CHANNEL_TECH_NAME "/Bob");
664 START_DIALED(chan_caller, chan_callee);
666 ast_channel_state_set(chan_caller, AST_STATE_RINGING);
667 ast_channel_publish_dial(chan_caller, chan_callee, NULL, "NOANSWER");
669 HANGUP_CHANNEL(chan_caller, AST_CAUSE_NO_ANSWER, "NOANSWER");
670 HANGUP_CHANNEL(chan_callee, AST_CAUSE_NO_ANSWER, "");
672 return AST_TEST_PASS;
676 AST_TEST_DEFINE(test_cel_dial_busy)
678 RAII_VAR(struct ast_channel *, chan_caller, NULL, safe_channel_release);
679 RAII_VAR(struct ast_channel *, chan_callee, NULL, safe_channel_release);
680 struct ast_party_caller caller = ALICE_CALLERID;
684 info->name = __func__;
685 info->category = TEST_CATEGORY;
686 info->summary = "Test CEL for a dial that results in a busy";
688 "Test CEL records for a channel that\n"
689 "performs a dial operation to an endpoint that's busy\n";
690 return AST_TEST_NOT_RUN;
695 CREATE_ALICE_CHANNEL(chan_caller, &caller);
697 EMULATE_DIAL(chan_caller, CHANNEL_TECH_NAME "/Bob");
699 START_DIALED(chan_caller, chan_callee);
701 ast_channel_state_set(chan_caller, AST_STATE_RINGING);
702 ast_channel_publish_dial(chan_caller, chan_callee, NULL, "BUSY");
704 HANGUP_CHANNEL(chan_caller, AST_CAUSE_BUSY, "BUSY");
705 HANGUP_CHANNEL(chan_callee, AST_CAUSE_BUSY, "");
707 return AST_TEST_PASS;
710 AST_TEST_DEFINE(test_cel_dial_congestion)
712 RAII_VAR(struct ast_channel *, chan_caller, NULL, safe_channel_release);
713 RAII_VAR(struct ast_channel *, chan_callee, NULL, safe_channel_release);
714 struct ast_party_caller caller = ALICE_CALLERID;
718 info->name = __func__;
719 info->category = TEST_CATEGORY;
720 info->summary = "Test CEL for a dial that results in congestion";
722 "Test CEL records for a channel that\n"
723 "performs a dial operation to an endpoint that's congested\n";
724 return AST_TEST_NOT_RUN;
729 CREATE_ALICE_CHANNEL(chan_caller, &caller);
731 EMULATE_DIAL(chan_caller, CHANNEL_TECH_NAME "/Bob");
733 START_DIALED(chan_caller, chan_callee);
735 ast_channel_state_set(chan_caller, AST_STATE_RINGING);
736 ast_channel_publish_dial(chan_caller, chan_callee, NULL, "CONGESTION");
738 HANGUP_CHANNEL(chan_caller, AST_CAUSE_CONGESTION, "CONGESTION");
739 HANGUP_CHANNEL(chan_callee, AST_CAUSE_CONGESTION, "");
741 return AST_TEST_PASS;
744 AST_TEST_DEFINE(test_cel_dial_unavailable)
746 RAII_VAR(struct ast_channel *, chan_caller, NULL, safe_channel_release);
747 RAII_VAR(struct ast_channel *, chan_callee, NULL, safe_channel_release);
748 struct ast_party_caller caller = ALICE_CALLERID;
752 info->name = __func__;
753 info->category = TEST_CATEGORY;
754 info->summary = "Test CEL for a dial that results in unavailable";
756 "Test CEL records for a channel that\n"
757 "performs a dial operation to an endpoint that's unavailable\n";
758 return AST_TEST_NOT_RUN;
763 CREATE_ALICE_CHANNEL(chan_caller, &caller);
765 EMULATE_DIAL(chan_caller, CHANNEL_TECH_NAME "/Bob");
767 START_DIALED(chan_caller, chan_callee);
769 ast_channel_state_set(chan_caller, AST_STATE_RINGING);
770 ast_channel_publish_dial(chan_caller, chan_callee, NULL, "CHANUNAVAIL");
772 HANGUP_CHANNEL(chan_caller, AST_CAUSE_NO_ROUTE_DESTINATION, "CHANUNAVAIL");
773 HANGUP_CHANNEL(chan_callee, AST_CAUSE_NO_ROUTE_DESTINATION, "");
775 return AST_TEST_PASS;
778 AST_TEST_DEFINE(test_cel_dial_caller_cancel)
780 RAII_VAR(struct ast_channel *, chan_caller, NULL, safe_channel_release);
781 RAII_VAR(struct ast_channel *, chan_callee, NULL, safe_channel_release);
782 struct ast_party_caller caller = ALICE_CALLERID;
786 info->name = __func__;
787 info->category = TEST_CATEGORY;
788 info->summary = "Test CEL for a dial where the caller cancels";
790 "Test CEL records for a channel that\n"
791 "performs a dial operation to an endpoint but then decides\n"
792 "to hang up, cancelling the dial\n";
793 return AST_TEST_NOT_RUN;
798 CREATE_ALICE_CHANNEL(chan_caller, &caller);
800 EMULATE_DIAL(chan_caller, CHANNEL_TECH_NAME "/Bob");
802 START_DIALED(chan_caller, chan_callee);
804 ast_channel_state_set(chan_caller, AST_STATE_RINGING);
805 ast_channel_publish_dial(chan_caller, chan_callee, NULL, "CANCEL");
807 HANGUP_CHANNEL(chan_callee, AST_CAUSE_NORMAL, "");
808 HANGUP_CHANNEL(chan_caller, AST_CAUSE_NORMAL, "CANCEL");
810 return AST_TEST_PASS;
813 AST_TEST_DEFINE(test_cel_dial_parallel_failed)
815 RAII_VAR(struct ast_channel *, chan_caller, NULL, safe_channel_release);
816 RAII_VAR(struct ast_channel *, chan_bob, NULL, safe_channel_release);
817 RAII_VAR(struct ast_channel *, chan_charlie, NULL, safe_channel_release);
818 RAII_VAR(struct ast_channel *, chan_david, NULL, safe_channel_release);
819 struct ast_party_caller caller = ALICE_CALLERID;
823 info->name = __func__;
824 info->category = TEST_CATEGORY;
825 info->summary = "Test a parallel dial where all channels fail to answer";
827 "This tests dialing three parties: Bob, Charlie, David. Charlie\n"
828 "returns BUSY; David returns CONGESTION; Bob fails to answer and\n"
829 "Alice hangs up. Three records are created for Alice as a result.\n";
830 return AST_TEST_NOT_RUN;
835 CREATE_ALICE_CHANNEL(chan_caller, &caller);
837 /* Channel enters Dial app */
838 EMULATE_DIAL(chan_caller, CHANNEL_TECH_NAME "/Bob&" CHANNEL_TECH_NAME "/Charlie&" CHANNEL_TECH_NAME "/David");
840 /* Outbound channels are created */
841 START_DIALED_FULL(chan_caller, chan_bob, "200", "Bob");
842 START_DIALED_FULL(chan_caller, chan_charlie, "300", "Charlie");
843 START_DIALED_FULL(chan_caller, chan_david, "400", "David");
846 ast_channel_state_set(chan_caller, AST_STATE_RINGING);
848 /* Charlie is busy */
849 ast_channel_publish_dial(chan_caller, chan_charlie, NULL, "BUSY");
850 HANGUP_CHANNEL(chan_charlie, AST_CAUSE_BUSY, "");
852 /* David is congested */
853 ast_channel_publish_dial(chan_caller, chan_david, NULL, "CONGESTION");
854 HANGUP_CHANNEL(chan_david, AST_CAUSE_CONGESTION, "");
856 /* Bob is canceled */
857 ast_channel_publish_dial(chan_caller, chan_bob, NULL, "CANCEL");
858 HANGUP_CHANNEL(chan_bob, AST_CAUSE_NORMAL, "");
861 HANGUP_CHANNEL(chan_caller, AST_CAUSE_NORMAL, "BUSY");
863 return AST_TEST_PASS;
866 AST_TEST_DEFINE(test_cel_dial_answer_no_bridge)
868 RAII_VAR(struct ast_channel *, chan_caller, NULL, safe_channel_release);
869 RAII_VAR(struct ast_channel *, chan_callee, NULL, safe_channel_release);
870 struct ast_party_caller caller = ALICE_CALLERID;
874 info->name = __func__;
875 info->category = TEST_CATEGORY;
876 info->summary = "Test dialing, answering, and not going into a bridge.";
878 "This is a weird one, but theoretically possible. You can perform\n"
879 "a dial, then bounce both channels to different priorities and\n"
880 "never have them enter a bridge together. Ew. This makes sure that\n"
881 "when we answer, we get a CEL, it gets ended at that point, and\n"
882 "that it gets finalized appropriately.\n";
883 return AST_TEST_NOT_RUN;
888 CREATE_ALICE_CHANNEL(chan_caller, &caller);
890 EMULATE_DIAL(chan_caller, CHANNEL_TECH_NAME "/Bob");
892 START_DIALED(chan_caller, chan_callee);
894 ast_channel_state_set(chan_caller, AST_STATE_RINGING);
895 ast_channel_publish_dial(chan_caller, chan_callee, NULL, "ANSWER");
897 ANSWER_NO_APP(chan_caller);
898 ast_clear_flag(ast_channel_flags(chan_callee), AST_FLAG_OUTGOING);
899 ANSWER_NO_APP(chan_callee);
901 EMULATE_APP_DATA(chan_caller, 2, "Wait", "1");
902 EMULATE_APP_DATA(chan_callee, 1, "Wait", "1");
904 HANGUP_CHANNEL(chan_caller, AST_CAUSE_NORMAL, "ANSWER");
905 HANGUP_CHANNEL(chan_callee, AST_CAUSE_NORMAL, "");
907 return AST_TEST_PASS;
910 AST_TEST_DEFINE(test_cel_dial_answer_twoparty_bridge_a)
912 RAII_VAR(struct ast_channel *, chan_caller, NULL, safe_channel_release);
913 RAII_VAR(struct ast_channel *, chan_callee, NULL, safe_channel_release);
914 RAII_VAR(struct ast_bridge *, bridge, NULL, ao2_cleanup);
915 struct ast_party_caller caller = ALICE_CALLERID;
919 info->name = __func__;
920 info->category = TEST_CATEGORY;
921 info->summary = "Test dialing, answering, and going into a 2-party bridge";
923 "The most 'basic' of scenarios\n";
924 return AST_TEST_NOT_RUN;
928 bridge = ast_bridge_basic_new();
929 ast_test_validate(test, bridge != NULL);
931 CREATE_ALICE_CHANNEL(chan_caller, &caller);
933 EMULATE_DIAL(chan_caller, CHANNEL_TECH_NAME "/Bob");
935 START_DIALED(chan_caller, chan_callee);
937 ast_channel_state_set(chan_caller, AST_STATE_RINGING);
938 ast_channel_publish_dial(chan_caller, chan_callee, NULL, "ANSWER");
940 ANSWER_NO_APP(chan_caller);
941 ANSWER_NO_APP(chan_callee);
945 BRIDGE_ENTER(chan_caller, bridge);
946 BRIDGE_ENTER(chan_callee, bridge);
948 BRIDGE_EXIT(chan_caller, bridge);
949 BRIDGE_EXIT(chan_callee, bridge);
951 HANGUP_CHANNEL(chan_caller, AST_CAUSE_NORMAL, "ANSWER");
952 HANGUP_CHANNEL(chan_callee, AST_CAUSE_NORMAL, "");
954 return AST_TEST_PASS;
957 AST_TEST_DEFINE(test_cel_dial_answer_twoparty_bridge_b)
959 RAII_VAR(struct ast_channel *, chan_caller, NULL, safe_channel_release);
960 RAII_VAR(struct ast_channel *, chan_callee, NULL, safe_channel_release);
961 RAII_VAR(struct ast_bridge *, bridge, NULL, ao2_cleanup);
962 struct ast_party_caller caller = ALICE_CALLERID;
966 info->name = __func__;
967 info->category = TEST_CATEGORY;
968 info->summary = "Test dialing, answering, and going into a 2-party bridge";
970 "The most 'basic' of scenarios\n";
971 return AST_TEST_NOT_RUN;
975 bridge = ast_bridge_basic_new();
976 ast_test_validate(test, bridge != NULL);
978 CREATE_ALICE_CHANNEL(chan_caller, &caller);
980 EMULATE_DIAL(chan_caller, CHANNEL_TECH_NAME "/Bob");
982 START_DIALED(chan_caller, chan_callee);
984 ast_channel_state_set(chan_caller, AST_STATE_RINGING);
985 ast_channel_publish_dial(chan_caller, chan_callee, NULL, "ANSWER");
987 ANSWER_NO_APP(chan_caller);
988 ANSWER_NO_APP(chan_callee);
991 BRIDGE_ENTER(chan_callee, bridge);
992 BRIDGE_ENTER(chan_caller, bridge);
994 BRIDGE_EXIT(chan_caller, bridge);
995 BRIDGE_EXIT(chan_callee, bridge);
997 HANGUP_CHANNEL(chan_caller, AST_CAUSE_NORMAL, "ANSWER");
998 HANGUP_CHANNEL(chan_callee, AST_CAUSE_NORMAL, "");
1000 return AST_TEST_PASS;
1004 AST_TEST_DEFINE(test_cel_dial_answer_multiparty)
1006 RAII_VAR(struct ast_channel *, chan_alice, NULL, safe_channel_release);
1007 RAII_VAR(struct ast_channel *, chan_bob, NULL, safe_channel_release);
1008 RAII_VAR(struct ast_channel *, chan_charlie, NULL, safe_channel_release);
1009 RAII_VAR(struct ast_channel *, chan_david, NULL, safe_channel_release);
1010 RAII_VAR(struct ast_bridge *, bridge, NULL, ao2_cleanup);
1011 struct ast_party_caller alice_caller = ALICE_CALLERID;
1012 struct ast_party_caller charlie_caller = CHARLIE_CALLERID;
1016 info->name = __func__;
1017 info->category = TEST_CATEGORY;
1018 info->summary = "Test dialing, answering, and going into a multi-party bridge";
1020 "A little tricky to get to do, but possible with some redirects.\n";
1021 return AST_TEST_NOT_RUN;
1025 bridge = ast_bridge_basic_new();
1026 ast_test_validate(test, bridge != NULL);
1028 CREATE_ALICE_CHANNEL(chan_alice, &alice_caller);
1030 EMULATE_DIAL(chan_alice, CHANNEL_TECH_NAME "/Bob");
1032 START_DIALED(chan_alice, chan_bob);
1035 CREATE_CHARLIE_CHANNEL(chan_charlie, &charlie_caller);
1037 EMULATE_DIAL(chan_charlie, CHANNEL_TECH_NAME "/Bob");
1040 START_DIALED_FULL(chan_charlie, chan_david, "400", "David");
1042 ast_channel_state_set(chan_alice, AST_STATE_RINGING);
1044 ast_channel_state_set(chan_charlie, AST_STATE_RINGING);
1046 ast_channel_publish_dial(chan_alice, chan_bob, NULL, "ANSWER");
1048 ast_channel_publish_dial(chan_charlie, chan_david, NULL, "ANSWER");
1051 ANSWER_NO_APP(chan_alice);
1053 ANSWER_NO_APP(chan_bob);
1055 ANSWER_NO_APP(chan_charlie);
1057 ANSWER_NO_APP(chan_david);
1061 BRIDGE_ENTER(chan_charlie, bridge);
1062 BRIDGE_ENTER(chan_david, bridge);
1063 BRIDGE_ENTER(chan_bob, bridge);
1064 BRIDGE_ENTER(chan_alice, bridge);
1066 BRIDGE_EXIT(chan_alice, bridge);
1067 BRIDGE_EXIT(chan_bob, bridge);
1068 BRIDGE_EXIT(chan_charlie, bridge);
1069 BRIDGE_EXIT(chan_david, bridge);
1071 HANGUP_CHANNEL(chan_alice, AST_CAUSE_NORMAL, "ANSWER");
1072 HANGUP_CHANNEL(chan_bob, AST_CAUSE_NORMAL, "");
1073 HANGUP_CHANNEL(chan_charlie, AST_CAUSE_NORMAL, "ANSWER");
1074 HANGUP_CHANNEL(chan_david, AST_CAUSE_NORMAL, "");
1076 return AST_TEST_PASS;
1080 AST_TEST_DEFINE(test_cel_blind_transfer)
1082 RAII_VAR(struct ast_channel *, chan_alice, NULL, safe_channel_release);
1083 RAII_VAR(struct ast_channel *, chan_bob, NULL, safe_channel_release);
1084 RAII_VAR(struct ast_bridge *, bridge, NULL, ao2_cleanup);
1085 struct ast_party_caller alice_caller = ALICE_CALLERID;
1086 struct ast_party_caller bob_caller = BOB_CALLERID;
1087 struct ast_bridge_channel_pair pair;
1091 info->name = __func__;
1092 info->category = TEST_CATEGORY;
1093 info->summary = "Test blind transfers to an extension";
1095 "This test creates two channels, bridges them, and then"
1096 " blind transfers the bridge to an extension.\n";
1097 return AST_TEST_NOT_RUN;
1101 bridge = ast_bridge_basic_new();
1102 ast_test_validate(test, bridge != NULL);
1104 CREATE_ALICE_CHANNEL(chan_alice, &alice_caller);
1105 CREATE_BOB_CHANNEL(chan_bob, &bob_caller);
1107 ANSWER_NO_APP(chan_alice);
1108 ANSWER_NO_APP(chan_bob);
1110 BRIDGE_ENTER(chan_bob, bridge);
1111 BRIDGE_ENTER(chan_alice, bridge);
1113 pair.bridge = bridge;
1114 pair.channel = chan_alice;
1115 ast_bridge_publish_blind_transfer(1, AST_BRIDGE_TRANSFER_SUCCESS,
1116 &pair, "transfer_context", "transfer_extension");
1117 BLINDTRANSFER_EVENT(chan_alice, bridge, "transfer_extension", "transfer_context");
1119 BRIDGE_EXIT(chan_alice, bridge);
1120 BRIDGE_EXIT(chan_bob, bridge);
1122 HANGUP_CHANNEL(chan_alice, AST_CAUSE_NORMAL, "");
1124 HANGUP_CHANNEL(chan_bob, AST_CAUSE_NORMAL, "");
1126 return AST_TEST_PASS;
1129 AST_TEST_DEFINE(test_cel_attended_transfer_bridges_swap)
1131 RAII_VAR(struct ast_channel *, chan_alice, NULL, safe_channel_release);
1132 RAII_VAR(struct ast_channel *, chan_bob, NULL, safe_channel_release);
1133 RAII_VAR(struct ast_channel *, chan_charlie, NULL, safe_channel_release);
1134 RAII_VAR(struct ast_channel *, chan_david, NULL, safe_channel_release);
1135 RAII_VAR(struct ast_bridge *, bridge1, NULL, ao2_cleanup);
1136 RAII_VAR(struct ast_bridge *, bridge2, NULL, ao2_cleanup);
1137 struct ast_party_caller alice_caller = ALICE_CALLERID;
1138 struct ast_party_caller bob_caller = BOB_CALLERID;
1139 struct ast_party_caller charlie_caller = CHARLIE_CALLERID;
1140 struct ast_party_caller david_caller = ALICE_CALLERID;
1144 info->name = __func__;
1145 info->category = TEST_CATEGORY;
1146 info->summary = "Test attended transfers between two pairs of bridged parties";
1148 "This test creates four channels, places each pair in"
1149 " a bridge, and then attended transfers the bridges"
1151 return AST_TEST_NOT_RUN;
1155 /* Create first set of bridged parties */
1156 bridge1 = ast_bridge_basic_new();
1157 ast_test_validate(test, bridge1 != NULL);
1159 CREATE_ALICE_CHANNEL(chan_alice, &alice_caller);
1160 CREATE_BOB_CHANNEL(chan_bob, &bob_caller);
1161 ANSWER_NO_APP(chan_alice);
1162 ANSWER_NO_APP(chan_bob);
1164 BRIDGE_ENTER(chan_bob, bridge1);
1165 BRIDGE_ENTER(chan_alice, bridge1);
1167 /* Create second set of bridged parties */
1168 bridge2 = ast_bridge_basic_new();
1169 ast_test_validate(test, bridge2 != NULL);
1171 CREATE_DAVID_CHANNEL(chan_david, &david_caller);
1172 CREATE_CHARLIE_CHANNEL(chan_charlie, &charlie_caller);
1173 ANSWER_NO_APP(chan_david);
1174 ANSWER_NO_APP(chan_charlie);
1176 BRIDGE_ENTER(chan_charlie, bridge2);
1178 BRIDGE_ENTER(chan_david, bridge2);
1179 BRIDGE_EXIT_EVENT(chan_bob, bridge1);
1182 /* Perform attended transfer */
1183 ast_bridge_transfer_attended(chan_alice, chan_david);
1185 BRIDGE_ENTER_EVENT(chan_bob, bridge2);
1187 BRIDGE_EXIT_EVENT(chan_david, bridge2);
1188 ATTENDEDTRANSFER_BRIDGE(chan_alice, bridge1, chan_david, bridge2);
1189 BRIDGE_EXIT_EVENT(chan_alice, bridge1);
1192 BRIDGE_EXIT(chan_bob, bridge2);
1193 BRIDGE_EXIT(chan_charlie, bridge2);
1195 HANGUP_CHANNEL(chan_alice, AST_CAUSE_NORMAL, "");
1197 HANGUP_CHANNEL(chan_bob, AST_CAUSE_NORMAL, "");
1199 HANGUP_CHANNEL(chan_david, AST_CAUSE_NORMAL, "");
1201 HANGUP_CHANNEL(chan_charlie, AST_CAUSE_NORMAL, "");
1203 return AST_TEST_PASS;
1206 AST_TEST_DEFINE(test_cel_attended_transfer_bridges_merge)
1208 RAII_VAR(struct ast_channel *, chan_alice, NULL, safe_channel_release);
1209 RAII_VAR(struct ast_channel *, chan_bob, NULL, safe_channel_release);
1210 RAII_VAR(struct ast_channel *, chan_charlie, NULL, safe_channel_release);
1211 RAII_VAR(struct ast_channel *, chan_david, NULL, safe_channel_release);
1212 RAII_VAR(struct ast_bridge *, bridge1, NULL, ao2_cleanup);
1213 RAII_VAR(struct ast_bridge *, bridge2, NULL, ao2_cleanup);
1214 struct ast_party_caller alice_caller = ALICE_CALLERID;
1215 struct ast_party_caller bob_caller = BOB_CALLERID;
1216 struct ast_party_caller charlie_caller = CHARLIE_CALLERID;
1217 struct ast_party_caller david_caller = ALICE_CALLERID;
1221 info->name = __func__;
1222 info->category = TEST_CATEGORY;
1223 info->summary = "Test attended transfers between two pairs of"
1224 " bridged parties that results in a bridge merge";
1226 "This test creates four channels, places each pair"
1227 " in a bridge, and then attended transfers the bridges"
1228 " together causing a bridge merge.\n";
1229 return AST_TEST_NOT_RUN;
1233 /* Create first set of bridged parties */
1234 bridge1 = ast_bridge_base_new(AST_BRIDGE_CAPABILITY_1TO1MIX | AST_BRIDGE_CAPABILITY_NATIVE | AST_BRIDGE_CAPABILITY_MULTIMIX,
1235 AST_BRIDGE_FLAG_SWAP_INHIBIT_FROM | AST_BRIDGE_FLAG_TRANSFER_PROHIBITED | AST_BRIDGE_FLAG_SMART);
1236 ast_test_validate(test, bridge1 != NULL);
1238 CREATE_ALICE_CHANNEL(chan_alice, &alice_caller);
1239 CREATE_BOB_CHANNEL(chan_bob, &bob_caller);
1240 ANSWER_NO_APP(chan_alice);
1241 ANSWER_NO_APP(chan_bob);
1243 BRIDGE_ENTER(chan_bob, bridge1);
1244 BRIDGE_ENTER(chan_alice, bridge1);
1246 /* Create second set of bridged parties */
1247 bridge2 = ast_bridge_base_new(AST_BRIDGE_CAPABILITY_1TO1MIX | AST_BRIDGE_CAPABILITY_NATIVE | AST_BRIDGE_CAPABILITY_MULTIMIX,
1248 AST_BRIDGE_FLAG_SWAP_INHIBIT_FROM | AST_BRIDGE_FLAG_TRANSFER_PROHIBITED | AST_BRIDGE_FLAG_SMART);
1249 ast_test_validate(test, bridge2 != NULL);
1251 CREATE_DAVID_CHANNEL(chan_david, &david_caller);
1252 CREATE_CHARLIE_CHANNEL(chan_charlie, &charlie_caller);
1253 ANSWER_NO_APP(chan_david);
1254 ANSWER_NO_APP(chan_charlie);
1256 BRIDGE_ENTER(chan_charlie, bridge2);
1258 BRIDGE_ENTER(chan_david, bridge2);
1260 /* Perform attended transfer */
1261 ast_bridge_transfer_attended(chan_alice, chan_david);
1263 BRIDGE_EXIT_EVENT(chan_charlie, bridge2);
1264 BRIDGE_ENTER_EVENT(chan_charlie, bridge1);
1265 BRIDGE_EXIT_EVENT(chan_david, bridge2);
1266 BRIDGE_EXIT_EVENT(chan_alice, bridge1);
1268 ATTENDEDTRANSFER_BRIDGE(chan_alice, bridge1, chan_david, bridge2);
1271 BRIDGE_EXIT(chan_bob, bridge1);
1272 BRIDGE_EXIT(chan_charlie, bridge1);
1274 HANGUP_CHANNEL(chan_alice, AST_CAUSE_NORMAL, "");
1276 HANGUP_CHANNEL(chan_bob, AST_CAUSE_NORMAL, "");
1278 HANGUP_CHANNEL(chan_david, AST_CAUSE_NORMAL, "");
1280 HANGUP_CHANNEL(chan_charlie, AST_CAUSE_NORMAL, "");
1282 return AST_TEST_PASS;
1285 AST_TEST_DEFINE(test_cel_attended_transfer_bridges_link)
1287 RAII_VAR(struct ast_channel *, chan_alice, NULL, safe_channel_release);
1288 RAII_VAR(struct ast_channel *, chan_bob, NULL, safe_channel_release);
1289 RAII_VAR(struct ast_channel *, chan_charlie, NULL, safe_channel_release);
1290 RAII_VAR(struct ast_channel *, chan_david, NULL, safe_channel_release);
1291 RAII_VAR(struct ast_bridge *, bridge1, NULL, ao2_cleanup);
1292 RAII_VAR(struct ast_bridge *, bridge2, NULL, ao2_cleanup);
1293 struct ast_party_caller alice_caller = ALICE_CALLERID;
1294 struct ast_party_caller bob_caller = BOB_CALLERID;
1295 struct ast_party_caller charlie_caller = CHARLIE_CALLERID;
1296 struct ast_party_caller david_caller = ALICE_CALLERID;
1300 info->name = __func__;
1301 info->category = TEST_CATEGORY;
1302 info->summary = "Test attended transfers between two pairs of"
1303 " bridged parties that results in a bridge merge";
1305 "This test creates four channels, places each pair"
1306 " in a bridge, and then attended transfers the bridges"
1307 " together causing a bridge link.\n";
1308 return AST_TEST_NOT_RUN;
1312 /* Create first set of bridged parties */
1313 bridge1 = ast_bridge_base_new(AST_BRIDGE_CAPABILITY_1TO1MIX | AST_BRIDGE_CAPABILITY_NATIVE | AST_BRIDGE_CAPABILITY_MULTIMIX,
1314 AST_BRIDGE_FLAG_MERGE_INHIBIT_TO | AST_BRIDGE_FLAG_MERGE_INHIBIT_FROM
1315 | AST_BRIDGE_FLAG_SWAP_INHIBIT_TO | AST_BRIDGE_FLAG_SWAP_INHIBIT_FROM
1316 | AST_BRIDGE_FLAG_TRANSFER_PROHIBITED | AST_BRIDGE_FLAG_SMART);
1317 ast_test_validate(test, bridge1 != NULL);
1319 CREATE_ALICE_CHANNEL(chan_alice, &alice_caller);
1320 CREATE_BOB_CHANNEL(chan_bob, &bob_caller);
1321 ANSWER_NO_APP(chan_alice);
1322 ANSWER_NO_APP(chan_bob);
1324 BRIDGE_ENTER(chan_bob, bridge1);
1325 BRIDGE_ENTER(chan_alice, bridge1);
1327 /* Create second set of bridged parties */
1328 bridge2 = ast_bridge_base_new(AST_BRIDGE_CAPABILITY_1TO1MIX | AST_BRIDGE_CAPABILITY_NATIVE | AST_BRIDGE_CAPABILITY_MULTIMIX,
1329 AST_BRIDGE_FLAG_MERGE_INHIBIT_TO | AST_BRIDGE_FLAG_MERGE_INHIBIT_FROM
1330 | AST_BRIDGE_FLAG_SWAP_INHIBIT_TO | AST_BRIDGE_FLAG_SWAP_INHIBIT_FROM
1331 | AST_BRIDGE_FLAG_TRANSFER_PROHIBITED | AST_BRIDGE_FLAG_SMART);
1332 ast_test_validate(test, bridge2 != NULL);
1334 CREATE_DAVID_CHANNEL(chan_david, &david_caller);
1335 CREATE_CHARLIE_CHANNEL(chan_charlie, &charlie_caller);
1336 ANSWER_NO_APP(chan_david);
1337 ANSWER_NO_APP(chan_charlie);
1339 BRIDGE_ENTER(chan_charlie, bridge2);
1340 BRIDGE_ENTER(chan_david, bridge2);
1342 /* Perform attended transfer */
1344 /* The following events can not be matched directly since nothing is known
1345 * about the linking local channel.
1346 * local channel ;1 and ;2 creation and ;2 answer */
1347 APPEND_DUMMY_EVENT();
1348 APPEND_DUMMY_EVENT();
1349 APPEND_DUMMY_EVENT();
1351 ATTENDEDTRANSFER_BRIDGE(chan_alice, bridge1, chan_david, bridge2);
1353 ast_bridge_transfer_attended(chan_alice, chan_david);
1356 /* ;1 and ;2 BRIDGE_ENTER and ;1 ANSWER */
1357 APPEND_DUMMY_EVENT();
1358 APPEND_DUMMY_EVENT();
1359 APPEND_DUMMY_EVENT();
1361 /* BRIDGE_EXIT alice and david */
1362 APPEND_DUMMY_EVENT();
1363 APPEND_DUMMY_EVENT();
1366 BRIDGE_EXIT(chan_bob, bridge1);
1367 BRIDGE_EXIT(chan_charlie, bridge2);
1369 HANGUP_CHANNEL(chan_alice, AST_CAUSE_NORMAL, "");
1371 HANGUP_CHANNEL(chan_bob, AST_CAUSE_NORMAL, "");
1373 HANGUP_CHANNEL(chan_david, AST_CAUSE_NORMAL, "");
1375 HANGUP_CHANNEL(chan_charlie, AST_CAUSE_NORMAL, "");
1377 return AST_TEST_PASS;
1380 AST_TEST_DEFINE(test_cel_dial_pickup)
1382 RAII_VAR(struct ast_channel *, chan_caller, NULL, safe_channel_release);
1383 RAII_VAR(struct ast_channel *, chan_callee, NULL, safe_channel_release);
1384 RAII_VAR(struct ast_channel *, chan_charlie, NULL, safe_channel_release);
1385 struct ast_party_caller caller = ALICE_CALLERID;
1386 struct ast_party_caller charlie_caller = CHARLIE_CALLERID;
1390 info->name = __func__;
1391 info->category = TEST_CATEGORY;
1392 info->summary = "Test call pickup";
1394 "Test CEL records for a call that is\n"
1395 "inbound to Asterisk, executes some dialplan, and\n"
1397 return AST_TEST_NOT_RUN;
1402 CREATE_ALICE_CHANNEL(chan_caller, &caller);
1404 EMULATE_DIAL(chan_caller, CHANNEL_TECH_NAME "/Bob");
1406 START_DIALED(chan_caller, chan_callee);
1408 ast_channel_state_set(chan_caller, AST_STATE_RINGING);
1410 CREATE_CHARLIE_CHANNEL(chan_charlie, &charlie_caller);
1413 RAII_VAR(struct ast_json *, extra, NULL, ast_json_unref);
1414 SCOPED_CHANNELLOCK(lock, chan_callee);
1416 extra = ast_json_pack("{s: s}", "pickup_channel", ast_channel_name(chan_charlie));
1417 ast_test_validate(test, extra != NULL);
1419 APPEND_EVENT(chan_callee, AST_CEL_PICKUP, NULL, extra);
1420 ast_test_validate(test, 0 == ast_do_pickup(chan_charlie, chan_callee));
1423 /* Hang up the masqueraded zombie */
1424 HANGUP_CHANNEL(chan_charlie, AST_CAUSE_NORMAL, "");
1426 ast_channel_publish_dial(chan_caller, chan_callee, NULL, "ANSWER");
1428 HANGUP_CHANNEL(chan_caller, AST_CAUSE_NORMAL, "ANSWER");
1429 HANGUP_CHANNEL(chan_callee, AST_CAUSE_NORMAL, "");
1431 return AST_TEST_PASS;
1434 AST_TEST_DEFINE(test_cel_local_optimize)
1436 RAII_VAR(struct ast_channel *, chan_alice, NULL, safe_channel_release);
1437 RAII_VAR(struct ast_channel *, chan_bob, NULL, safe_channel_release);
1438 struct ast_party_caller alice_caller = ALICE_CALLERID;
1439 struct ast_party_caller bob_caller = BOB_CALLERID;
1440 RAII_VAR(struct ast_multi_channel_blob *, mc_blob, NULL, ao2_cleanup);
1441 RAII_VAR(struct ast_channel_snapshot *, alice_snapshot, NULL, ao2_cleanup);
1442 RAII_VAR(struct ast_channel_snapshot *, bob_snapshot, NULL, ao2_cleanup);
1443 RAII_VAR(struct stasis_message *, local_opt_begin, NULL, ao2_cleanup);
1444 RAII_VAR(struct stasis_message *, local_opt_end, NULL, ao2_cleanup);
1445 RAII_VAR(struct ast_json *, extra, NULL, ast_json_unref);
1449 info->name = __func__;
1450 info->category = TEST_CATEGORY;
1451 info->summary = "Test local channel optimization record generation";
1453 "Test CEL records for two local channels being optimized\n"
1454 "out by sending a messages indicating local optimization\n"
1456 return AST_TEST_NOT_RUN;
1461 mc_blob = ast_multi_channel_blob_create(ast_json_null());
1462 ast_test_validate(test, mc_blob != NULL);
1464 CREATE_ALICE_CHANNEL(chan_alice, &alice_caller);
1465 CREATE_BOB_CHANNEL(chan_bob, &bob_caller);
1467 alice_snapshot = ast_channel_snapshot_create(chan_alice);
1468 ast_test_validate(test, alice_snapshot != NULL);
1470 bob_snapshot = ast_channel_snapshot_create(chan_bob);
1471 ast_test_validate(test, bob_snapshot != NULL);
1473 ast_multi_channel_blob_add_channel(mc_blob, "1", alice_snapshot);
1474 ast_multi_channel_blob_add_channel(mc_blob, "2", bob_snapshot);
1476 local_opt_begin = stasis_message_create(ast_local_optimization_begin_type(), mc_blob);
1477 ast_test_validate(test, local_opt_begin != NULL);
1479 local_opt_end = stasis_message_create(ast_local_optimization_end_type(), mc_blob);
1480 ast_test_validate(test, local_opt_end != NULL);
1482 stasis_publish(ast_channel_topic(chan_alice), local_opt_begin);
1483 stasis_publish(ast_channel_topic(chan_alice), local_opt_end);
1485 extra = ast_json_pack("{s: s}", "local_two", bob_snapshot->name);
1486 ast_test_validate(test, extra != NULL);
1488 APPEND_EVENT_SNAPSHOT(alice_snapshot, AST_CEL_LOCAL_OPTIMIZE, NULL, extra);
1490 HANGUP_CHANNEL(chan_alice, AST_CAUSE_NORMAL, "");
1491 HANGUP_CHANNEL(chan_bob, AST_CAUSE_NORMAL, "");
1493 return AST_TEST_PASS;
1496 /*! Container for astobj2 duplicated ast_events */
1497 static struct ao2_container *cel_received_events = NULL;
1499 /*! Container for expected CEL events */
1500 static struct ao2_container *cel_expected_events = NULL;
1502 static struct ast_event *ao2_dup_event(const struct ast_event *event)
1504 struct ast_event *event_dup;
1507 event_len = ast_event_get_size(event);
1509 event_dup = ao2_alloc(event_len, NULL);
1514 memcpy(event_dup, event, event_len);
1519 static void mid_test_sync(void)
1521 ast_mutex_lock(&mid_test_sync_lock);
1522 if (ao2_container_count(cel_expected_events) <= ao2_container_count(cel_received_events)) {
1523 ast_mutex_unlock(&mid_test_sync_lock);
1527 do_mid_test_sync = 1;
1528 ast_mutex_unlock(&mid_test_sync_lock);
1531 struct timeval start = ast_tvnow();
1532 struct timespec end = {
1533 .tv_sec = start.tv_sec + 15,
1534 .tv_nsec = start.tv_usec * 1000
1537 SCOPED_MUTEX(lock, &sync_lock);
1538 ast_cond_timedwait(&sync_out, &sync_lock, &end);
1542 static int append_event(struct ast_event *ev)
1544 RAII_VAR(struct ast_event *, ao2_ev, NULL, ao2_cleanup);
1545 ao2_ev = ao2_dup_event(ev);
1550 ao2_link(cel_expected_events, ao2_ev);
1554 static int append_dummy_event(void)
1556 RAII_VAR(struct ast_event *, ev, NULL, ast_free);
1557 RAII_VAR(struct ast_event *, ao2_ev, NULL, ao2_cleanup);
1559 ev = ast_event_new(AST_EVENT_CUSTOM, AST_EVENT_IE_END);
1564 return append_event(ev);
1567 static int append_expected_event_snapshot(
1568 struct ast_channel_snapshot *snapshot,
1569 enum ast_cel_event_type type,
1570 const char *userdefevname,
1571 struct ast_json *extra)
1573 RAII_VAR(struct ast_event *, ev, NULL, ast_free);
1574 ev = ast_cel_create_event(snapshot, type, userdefevname, extra);
1579 return append_event(ev);
1582 static int append_expected_event(
1583 struct ast_channel *chan,
1584 enum ast_cel_event_type type,
1585 const char *userdefevname,
1586 struct ast_json *extra)
1588 RAII_VAR(struct ast_channel_snapshot *, snapshot, NULL, ao2_cleanup);
1589 snapshot = ast_channel_snapshot_create(chan);
1594 return append_expected_event_snapshot(snapshot, type, userdefevname, extra);
1597 static void test_sub(struct ast_event *event)
1599 struct ast_event *event_dup = ao2_dup_event(event);
1600 SCOPED_MUTEX(mid_test_lock, &mid_test_sync_lock);
1606 /* save the event for later processing */
1607 ao2_link(cel_received_events, event_dup);
1609 if (do_mid_test_sync) {
1610 int expected = ao2_container_count(cel_expected_events);
1611 int received = ao2_container_count(cel_received_events);
1612 if (expected <= received) {
1614 SCOPED_MUTEX(lock, &sync_lock);
1615 ast_cond_signal(&sync_out);
1616 do_mid_test_sync = 0;
1624 * \brief Callback function called before each test executes
1626 static int test_cel_init_cb(struct ast_test_info *info, struct ast_test *test)
1628 ast_assert(cel_received_events == NULL);
1629 ast_assert(cel_expected_events == NULL);
1631 ast_mutex_init(&mid_test_sync_lock);
1632 ast_mutex_init(&sync_lock);
1633 ast_cond_init(&sync_out, NULL);
1635 /* Back up the real CEL config and insert the test's config */
1636 saved_config = ast_cel_get_config();
1637 ast_cel_set_config(cel_test_config);
1639 /* init CEL event storage (degenerate hash table becomes a linked list) */
1640 cel_received_events = ao2_container_alloc(1, NULL, NULL);
1641 cel_expected_events = ao2_container_alloc(1, NULL, NULL);
1643 /* start the CEL event callback */
1644 if (ast_cel_backend_register(TEST_BACKEND_NAME, test_sub)) {
1650 /*! \brief Check an IE value from two events, */
1651 static int match_ie_val(
1652 const struct ast_event *event1,
1653 const struct ast_event *event2,
1654 enum ast_event_ie_type type)
1656 enum ast_event_ie_pltype pltype = ast_event_get_ie_pltype(type);
1659 case AST_EVENT_IE_PLTYPE_UINT:
1661 uint32_t val = ast_event_get_ie_uint(event2, type);
1663 return (val == ast_event_get_ie_uint(event1, type)) ? 1 : 0;
1665 case AST_EVENT_IE_PLTYPE_STR:
1669 str = ast_event_get_ie_str(event2, type);
1671 const char *e1str, *e2str;
1672 e1str = ast_event_get_ie_str(event1, type);
1675 if (!strcmp(e1str, e2str)) {
1688 static int events_are_equal(struct ast_test *test, struct ast_event *received, struct ast_event *expected)
1690 struct ast_event_iterator iterator;
1693 if (ast_event_get_type(expected) == AST_EVENT_CUSTOM) {
1694 /* this event is flagged as a wildcard match */
1698 for (res = ast_event_iterator_init(&iterator, received); !res; res = ast_event_iterator_next(&iterator)) {
1699 /* XXX ignore sec/usec for now */
1700 int ie_type = ast_event_iterator_get_ie_type(&iterator);
1701 if (ie_type != AST_EVENT_IE_CEL_EVENT_TIME_USEC
1702 && ie_type != AST_EVENT_IE_CEL_EVENT_TIME
1703 && !match_ie_val(received, expected, ie_type)) {
1704 ast_test_status_update(test, "Failed matching on field %s\n", ast_event_get_ie_type_name(ie_type));
1712 static int dump_event(struct ast_test *test, struct ast_event *event)
1714 struct ast_event_iterator i;
1716 if (ast_event_iterator_init(&i, event)) {
1717 ast_test_status_update(test, "Failed to initialize event iterator. :-(\n");
1721 ast_test_status_update(test, "Event: %s\n",
1722 ast_cel_get_type_name(ast_event_get_ie_uint(event, AST_EVENT_IE_CEL_EVENT_TYPE)));
1725 enum ast_event_ie_type ie_type;
1726 enum ast_event_ie_pltype ie_pltype;
1727 const char *ie_type_name;
1729 ie_type = ast_event_iterator_get_ie_type(&i);
1730 ie_type_name = ast_event_get_ie_type_name(ie_type);
1731 ie_pltype = ast_event_get_ie_pltype(ie_type);
1733 switch (ie_pltype) {
1734 case AST_EVENT_IE_PLTYPE_UNKNOWN:
1735 case AST_EVENT_IE_PLTYPE_STR:
1736 ast_test_status_update(test, "%.30s: %s\n", ie_type_name,
1737 ast_event_iterator_get_ie_str(&i));
1739 case AST_EVENT_IE_PLTYPE_UINT:
1740 ast_test_status_update(test, "%.30s: %u\n", ie_type_name,
1741 ast_event_iterator_get_ie_uint(&i));
1746 } while (!ast_event_iterator_next(&i));
1748 ast_test_status_update(test, "\n");
1753 static int check_events(struct ast_test *test, struct ao2_container *local_expected, struct ao2_container *local_received)
1755 struct ao2_iterator expected_it, received_it;
1756 struct ast_event *rx_event, *ex_event;
1759 if (ao2_container_count(local_expected) != ao2_container_count(local_received)) {
1760 ast_test_status_update(test, "Increasing verbosity since the number of expected events (%d)"
1761 " did not match number of received events (%d).\n",
1762 ao2_container_count(local_expected),
1763 ao2_container_count(local_received));
1767 expected_it = ao2_iterator_init(local_expected, 0);
1768 received_it = ao2_iterator_init(local_received, 0);
1769 rx_event = ao2_iterator_next(&received_it);
1770 ex_event = ao2_iterator_next(&expected_it);
1771 while (rx_event && ex_event) {
1772 if (!events_are_equal(test, rx_event, ex_event)) {
1773 ast_test_status_update(test, "Received event:\n");
1774 dump_event(test, rx_event);
1775 ast_test_status_update(test, "Expected event:\n");
1776 dump_event(test, ex_event);
1780 ast_test_status_update(test, "Compared events successfully%s\n", ast_event_get_type(ex_event) == AST_EVENT_CUSTOM ? " (wildcard match)" : "");
1781 dump_event(test, rx_event);
1783 ao2_cleanup(rx_event);
1784 ao2_cleanup(ex_event);
1785 rx_event = ao2_iterator_next(&received_it);
1786 ex_event = ao2_iterator_next(&expected_it);
1790 ast_test_status_update(test, "Received event:\n");
1791 dump_event(test, rx_event);
1792 ao2_cleanup(rx_event);
1796 ast_test_status_update(test, "Expected event:\n");
1797 dump_event(test, ex_event);
1798 ao2_cleanup(ex_event);
1806 * \brief Callback function called after each test executes.
1809 * In addition to cleanup, this function also performs verification
1810 * that the events received during a test match the events that were
1811 * expected to have been generated during the test.
1813 static int cel_verify_and_cleanup_cb(struct ast_test_info *info, struct ast_test *test)
1815 RAII_VAR(struct ao2_container *, local_expected, cel_expected_events, ao2_cleanup);
1816 RAII_VAR(struct ao2_container *, local_received, cel_received_events, ao2_cleanup);
1817 ast_assert(cel_received_events != NULL);
1818 ast_assert(cel_expected_events != NULL);
1822 /* stop the CEL event callback and clean up storage structures*/
1823 ast_cel_backend_unregister(TEST_BACKEND_NAME);
1825 /* cleaned up by RAII_VAR's */
1826 cel_expected_events = NULL;
1827 cel_received_events = NULL;
1830 ast_test_validate(test, !check_events(test, local_expected, local_received));
1832 /* Restore the real CEL config */
1833 ast_cel_set_config(saved_config);
1834 ao2_cleanup(saved_config);
1835 saved_config = NULL;
1837 /* clean up the locks */
1838 ast_mutex_destroy(&sync_lock);
1839 ast_mutex_destroy(&mid_test_sync_lock);
1840 ast_cond_destroy(&sync_out);
1844 static int unload_module(void)
1846 AST_TEST_UNREGISTER(test_cel_channel_creation);
1847 AST_TEST_UNREGISTER(test_cel_unanswered_inbound_call);
1848 AST_TEST_UNREGISTER(test_cel_unanswered_outbound_call);
1849 AST_TEST_UNREGISTER(test_cel_single_party);
1850 AST_TEST_UNREGISTER(test_cel_single_bridge);
1851 AST_TEST_UNREGISTER(test_cel_single_bridge_continue);
1852 AST_TEST_UNREGISTER(test_cel_single_twoparty_bridge_a);
1853 AST_TEST_UNREGISTER(test_cel_single_twoparty_bridge_b);
1855 AST_TEST_UNREGISTER(test_cel_single_multiparty_bridge);
1858 AST_TEST_UNREGISTER(test_cel_dial_unanswered);
1859 AST_TEST_UNREGISTER(test_cel_dial_congestion);
1860 AST_TEST_UNREGISTER(test_cel_dial_busy);
1861 AST_TEST_UNREGISTER(test_cel_dial_unavailable);
1862 AST_TEST_UNREGISTER(test_cel_dial_caller_cancel);
1863 AST_TEST_UNREGISTER(test_cel_dial_parallel_failed);
1864 AST_TEST_UNREGISTER(test_cel_dial_answer_no_bridge);
1865 AST_TEST_UNREGISTER(test_cel_dial_answer_twoparty_bridge_a);
1866 AST_TEST_UNREGISTER(test_cel_dial_answer_twoparty_bridge_b);
1868 AST_TEST_UNREGISTER(test_cel_dial_answer_multiparty);
1871 AST_TEST_UNREGISTER(test_cel_blind_transfer);
1872 AST_TEST_UNREGISTER(test_cel_attended_transfer_bridges_swap);
1873 AST_TEST_UNREGISTER(test_cel_attended_transfer_bridges_merge);
1874 AST_TEST_UNREGISTER(test_cel_attended_transfer_bridges_link);
1876 AST_TEST_UNREGISTER(test_cel_dial_pickup);
1878 AST_TEST_UNREGISTER(test_cel_local_optimize);
1880 ast_channel_unregister(&test_cel_chan_tech);
1882 ao2_cleanup(cel_test_config);
1883 cel_test_config = NULL;
1888 static int load_module(void)
1890 /* build the test config */
1891 cel_test_config = ast_cel_general_config_alloc();
1892 if (!cel_test_config) {
1895 cel_test_config->enable = 1;
1896 if (ast_str_container_add(cel_test_config->apps, "dial")) {
1899 if (ast_str_container_add(cel_test_config->apps, "park")) {
1902 if (ast_str_container_add(cel_test_config->apps, "queue")) {
1905 cel_test_config->events |= 1<<AST_CEL_APP_START;
1906 cel_test_config->events |= 1<<AST_CEL_CHANNEL_START;
1907 cel_test_config->events |= 1<<AST_CEL_CHANNEL_END;
1908 cel_test_config->events |= 1<<AST_CEL_ANSWER;
1909 cel_test_config->events |= 1<<AST_CEL_HANGUP;
1910 cel_test_config->events |= 1<<AST_CEL_BRIDGE_ENTER;
1911 cel_test_config->events |= 1<<AST_CEL_BRIDGE_EXIT;
1912 cel_test_config->events |= 1<<AST_CEL_BLINDTRANSFER;
1913 cel_test_config->events |= 1<<AST_CEL_ATTENDEDTRANSFER;
1914 cel_test_config->events |= 1<<AST_CEL_PICKUP;
1915 cel_test_config->events |= 1<<AST_CEL_LOCAL_OPTIMIZE;
1917 ast_channel_register(&test_cel_chan_tech);
1919 AST_TEST_REGISTER(test_cel_channel_creation);
1920 AST_TEST_REGISTER(test_cel_unanswered_inbound_call);
1921 AST_TEST_REGISTER(test_cel_unanswered_outbound_call);
1923 AST_TEST_REGISTER(test_cel_single_party);
1924 AST_TEST_REGISTER(test_cel_single_bridge);
1925 AST_TEST_REGISTER(test_cel_single_bridge_continue);
1926 AST_TEST_REGISTER(test_cel_single_twoparty_bridge_a);
1927 AST_TEST_REGISTER(test_cel_single_twoparty_bridge_b);
1929 AST_TEST_REGISTER(test_cel_single_multiparty_bridge);
1932 AST_TEST_REGISTER(test_cel_dial_unanswered);
1933 AST_TEST_REGISTER(test_cel_dial_congestion);
1934 AST_TEST_REGISTER(test_cel_dial_busy);
1935 AST_TEST_REGISTER(test_cel_dial_unavailable);
1936 AST_TEST_REGISTER(test_cel_dial_caller_cancel);
1937 AST_TEST_REGISTER(test_cel_dial_parallel_failed);
1938 AST_TEST_REGISTER(test_cel_dial_answer_no_bridge);
1939 AST_TEST_REGISTER(test_cel_dial_answer_twoparty_bridge_a);
1940 AST_TEST_REGISTER(test_cel_dial_answer_twoparty_bridge_b);
1942 AST_TEST_REGISTER(test_cel_dial_answer_multiparty);
1945 AST_TEST_REGISTER(test_cel_blind_transfer);
1946 AST_TEST_REGISTER(test_cel_attended_transfer_bridges_swap);
1947 AST_TEST_REGISTER(test_cel_attended_transfer_bridges_merge);
1948 AST_TEST_REGISTER(test_cel_attended_transfer_bridges_link);
1950 AST_TEST_REGISTER(test_cel_dial_pickup);
1952 AST_TEST_REGISTER(test_cel_local_optimize);
1954 /* ast_test_register_* has to happen after AST_TEST_REGISTER */
1955 /* Verify received vs expected events and clean things up after every test */
1956 ast_test_register_init(TEST_CATEGORY, test_cel_init_cb);
1957 ast_test_register_cleanup(TEST_CATEGORY, cel_verify_and_cleanup_cb);
1959 return AST_MODULE_LOAD_SUCCESS;
1962 AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "CEL unit tests");