39 #if defined(TEST_FRAMEWORK) 41 #define TEST_CATEGORY "/res/parking/" 43 #define CHANNEL_TECH_NAME "ParkingTestChannel" 48 .id.number.str =
"100",
64 .description =
"Parking unit test technology",
94 "100",
"Alice",
"100",
"100",
"default",
NULL,
NULL, 0,
134 while ((nanosleep(to_sleep, to_sleep) == -1) && (
errno == EINTR)) {
138 #define TEST_LOT_NAME "unit_tests_res_parking_test_lot" 150 test_cfg->parking_start = low_space;
151 test_cfg->parking_stop = high_space;
152 test_cfg->parkingtime = 10;
153 test_cfg->comebackdialtime = 10;
154 test_cfg->parkfindnext = 1;
155 test_cfg->parkext_exclusive = 1;
161 ast_test_status_update(test,
"Extensions for parking lot '%s' could not be registered. Extension Creation failed.\n", name);
182 if ((expect_destruction && !found_lot) || (!expect_destruction && found_lot)) {
196 info->name =
"create_lot";
198 info->summary =
"Parking lot creation";
200 "Creates a parking lot and then disposes of it.";
240 struct timespec to_sleep = {1, 0};
244 info->name =
"park_channel";
246 info->summary =
"Park a Channel";
248 "Creates a parking lot, parks a channel in it, then removes it from the parking lot bridge.";
273 if (!parking_bridge) {
383 struct timespec to_sleep = {1, 0};
388 .parker_dial_string =
"ParkingTestChannel/Alice",
395 info->name =
"park_retrieve";
397 info->summary =
"Retrieve a parked channel";
399 "Creates a parking lot, parks a channel in it, then removes it from the parking lot bridge.";
424 if (!parking_bridge) {
440 if (!retrieved_user) {
454 if (retrieved_user->chan != chan_alice) {
476 char search_buffer[4];
481 if (check ? !expected : expected) {
484 expected ?
"not present" :
"present",
485 expected ?
"should" :
"should not");
487 }
else if (check && expected) {
489 ast_test_status_update(test,
"An extension '700' has the wrong application associated with it. Got '%s' expected 'Park'.\n",
497 for (extens = 701; extens <= 703; extens++) {
498 sprintf(search_buffer,
"%d", extens);
503 if (check ? !expected : expected) {
507 expected ?
"not present" :
"present",
508 expected ?
"should" :
"should not");
510 }
else if (check && expected) {
512 ast_test_status_update(test,
"An extension '%s' has the wrong application associated with it. Got '%s', expected 'ParkedCall'.\n",
530 info->name =
"park_extensions";
532 info->summary =
"Parking lot extension creation tests";
534 "Creates parking lots and checks that they registered the expected extensions, then removes them.";
551 ast_test_status_update(
test,
"Extensions for the test parking lot were verified. Cleaning up and verifying their removal.\n");
561 ast_log(
LOG_ERROR,
"Test 'park_extensions' failed to clean up after itself properly.\n");
587 info->name =
"extension_conflicts";
589 info->summary =
"Tests the addition of parking lot extensions to make sure conflicts are detected";
591 "Creates parking lots with overlapping extensions to test for conflicts";
606 cur_lot_name =
"unit_tests_res_parking_test_lot_fail1";
609 801, 803,
"700",
"unit_test_res_parking_create_lot_con",
618 cur_lot_name =
"unit_tests_res_parking_test_lot_fail2";
620 702, 705,
"800",
"unit_test_res_parking_create_lot_con",
628 cur_lot_name =
"unit_tests_res_parking_test_lot_fail3";
630 698, 700,
"testfail3",
"unit_test_res_parking_create_lot_con",
638 cur_lot_name =
"unit_tests_res_parking_test_lot_fail4";
640 704, 706,
"703",
"unit_test_res_parking_create_lot_con",
648 cur_lot_name =
"unit_tests_res_parking_test_lot_success1";
650 701, 703,
"700",
"unit_test_res_parking_create_lot_con_2",
652 if (!expect_success1) {
658 cur_lot_name =
"unit_tests_res_parking_test_lot_success2";
660 601, 605,
"600",
"unit_test_res_parking_create_lot_con",
662 if (!expect_success2) {
668 cur_lot_name =
"unit_tests_res_parking_test_lot_success3";
670 704, 706,
"testsuccess3",
"unit_test_res_parking_create_lot_con",
672 if (!expect_success3) {
678 cur_lot_name =
"unit_tests_res_parking_test_lot_success4";
680 697, 699,
"testsuccess4",
"unit_test_res_parking_create_lot_con",
682 if (!expect_success4) {
746 info->name =
"dynamic_parking_variables";
748 info->summary =
"Tests whether dynamic parking lot creation respects channel variables";
750 "Creates a template parking lot, creates a channel, sets dynamic parking variables, and then creates a parking lot for that channel";
765 expected_cfg->parking_start = 751;
766 expected_cfg->parking_stop = 760;
767 expected_cfg->parkingtime = 10;
768 expected_cfg->comebackdialtime = 10;
769 expected_cfg->parkfindnext = 1;
770 expected_cfg->parkext_exclusive = 1;
773 ast_string_field_set(expected_cfg, comebackcontext,
"unit_test_res_parking_create_lot_comeback");
841 #if defined(TEST_FRAMEWORK) 856 #if defined(TEST_FRAMEWORK) static struct ast_channel * create_alice_channel(void)
Create a test_cdr_chan_tech for Alice.
Main Channel structure associated with a channel.
Asterisk main include file. File version handling, generic pbx functions.
ast_exten: An extension The dialplan is saved as a linked list with each context having it's own link...
unsigned int comebackdialtime
static int parking_test_write(struct ast_channel *chan, struct ast_frame *frame)
void ast_channel_set_writeformat(struct ast_channel *chan, struct ast_format *format)
static void safe_channel_release(struct ast_channel *chan)
static struct ast_frame * parking_test_read(struct ast_channel *chan)
Time-related functions and macros.
struct ast_party_name name
Subscriber name.
void ast_channel_hangupcause_set(struct ast_channel *chan, int value)
struct ast_bridge * parking_bridge
struct ast_channel * ast_channel_release(struct ast_channel *chan)
Unlink and release reference to a channel.
void ast_channel_set_rawwriteformat(struct ast_channel *chan, struct ast_format *format)
const char * ast_get_extension_app(struct ast_exten *e)
int load_parking_tests(void)
Register parking unit tests.
void ast_channel_set_caller(struct ast_channel *chan, const struct ast_party_caller *caller, const struct ast_set_party_caller *update)
Set the caller id information in the Asterisk channel.
#define AST_TEST_REGISTER(cb)
char * str
Subscriber name (Malloced)
const ast_string_field comebackcontext
static void do_sleep(struct timespec *to_sleep)
static int check_retrieve_call_extensions(struct ast_test *test, int expected)
static struct timespec to_sleep
A 1 second sleep.
struct parked_user * parking_lot_retrieve_parked_user(struct parking_lot *lot, int target)
Determine if there is a parked user in a parking space and pull it from the parking lot if there is...
int parking_lot_cfg_create_extensions(struct parking_lot_cfg *lot_cfg)
Add extensions for a parking lot configuration.
void ast_channel_tech_set(struct ast_channel *chan, const struct ast_channel_tech *value)
static const struct ast_party_caller alice_callerid
struct ast_party_id id
Caller party ID.
void ast_channel_set_rawreadformat(struct ast_channel *chan, struct ast_format *format)
int ast_bridge_impart(struct ast_bridge *bridge, struct ast_channel *chan, struct ast_channel *swap, struct ast_bridge_features *features, enum ast_bridge_impart_flags flags) attribute_warn_unused_result
Impart a channel to a bridge (non-blocking)
const ast_string_field parking_con
static int parked_users_match(const struct parked_user *actual, const struct parked_user *expected, struct ast_test *test)
AST_TEST_DEFINE(create_lot)
struct ast_bridge * park_application_setup(struct ast_channel *parkee, struct ast_channel *parker, const char *app_data, int *silence_announcements)
Function to prepare a channel for parking by determining which parking bridge should be used...
#define RAII_VAR(vartype, varname, initval, dtor)
Declare a variable that will call a destructor function when it goes out of scope.
#define ast_test_status_update(a, b, c...)
void ast_channel_nativeformats_set(struct ast_channel *chan, struct ast_format_cap *value)
int parking_lot_remove_if_unused(struct parking_lot *lot)
Remove a parking lot from the usable lists if it is no longer involved in any calls and no configurat...
char * parker_dial_string
struct parking_lot_cfg * parking_lot_cfg_create(const char *cat)
Create an empty parking lot configuration structure useful for unit tests.
static int dispose_test_lot(struct parking_lot *test_lot, int expect_destruction)
Caller Party information.
#define ao2_ref(o, delta)
void ast_channel_set_readformat(struct ast_channel *chan, struct ast_format *format)
Structure to describe a channel "technology", ie a channel driver See for examples: ...
enum park_call_resolution resolution
Core PBX routines and definitions.
#define CHANNEL_TECH_NAME
Structure that contains information about a bridge.
static int set_test_formats(struct ast_channel *chan)
Set ulaw format on the channel.
#define AST_TEST_UNREGISTER(cb)
struct parking_lot * parking_lot_build_or_update(struct parking_lot_cfg *cfg, int dynamic)
If a parking lot exists in the parking lot list already, update its status to match the provided conf...
int ast_bridge_depart(struct ast_channel *chan)
Depart a channel from a bridge.
void unload_parking_tests(void)
Unregister parking unit tests.
static int parking_lot_cfgs_match(const struct parking_lot_cfg *actual, const struct parking_lot_cfg *expected, struct ast_test *test)
#define ast_channel_unlock(chan)
static void test_cleanup(void)
unsigned int parkfindnext
void ast_hangup(struct ast_channel *chan)
Hang up a channel.
const ast_string_field name
static void * cleanup(void *unused)
int pbx_builtin_setvar_helper(struct ast_channel *chan, const char *name, const char *value)
Add a variable to the channel variable stack, removing the most recently set value for the same name...
struct ast_frame ast_null_frame
enum parking_lot_modes mode
const ast_string_field parkext
const char * ast_channel_name(const struct ast_channel *chan)
void ast_channel_state_set(struct ast_channel *chan, enum ast_channel_state)
Data structure associated with a single frame of data.
Internal Asterisk hangup causes.
static struct ast_channel * hangup_channel(struct ast_channel *chan, int hangup_cause)
Hang up a test channel safely.
struct parking_lot * parking_lot_find_by_name(const char *lot_name)
Find a parking lot based on its name.
Call Parking Resource Internal API.
struct parking_lot * parking_create_dynamic_lot_forced(const char *name, struct ast_channel *chan)
Create a dynamic parking lot without respect to whether they are enabled by configuration.
#define ast_channel_alloc(needqueue, state, cid_num, cid_name, acctcode, exten, context, assignedids, requestor, amaflag,...)
Create a channel structure.
Asterisk module definitions.
struct ast_exten * pbx_find_extension(struct ast_channel *chan, struct ast_context *bypass, struct pbx_find_info *q, const char *context, const char *exten, int priority, const char *label, const char *callerid, enum ext_match_t action)
unsigned int parkext_exclusive
static struct parking_lot * generate_test_parking_lot(const char *name, int low_space, int high_space, const char *park_exten, const char *park_context, struct ast_test *test)
#define ast_string_field_set(x, field, data)
Set a field to a simple string value.
static const struct ast_channel_tech parking_test_tech