Skip to content
Snippets Groups Projects
Commit 98b02d98 authored by Jonathan Rose's avatar Jonathan Rose
Browse files

res_parking: Unit tests

Adds the following unit tests:
* create_lot: tests adding and removal of a new parking lot (baseline)
* park_extensions: creates a parking lot that registers extensions and
      then confirms that all of the expected extensions exist
* extensions_conflicts: creates numerous parking lots to test that
      extension conflicts in parking lots result in parking lot
      creation failing
* dynamic_parking_variables: Tests that the creation of dynamic
      parking lots respects the related channel variables set on the
      channel that requests them.
* park_call: Tests adding a channel to a parking lot's holding bridge
      by standard parking functions.
* retrieve_call: Tests pulling a channel out of a parking lot's
      holding bridge via parked call retrieval functions.

(closes issue ASTERISK-22138)
Reported by: Matt Jordan
Review: https://reviewboard.asterisk.org/r/2714/



git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@396175 65c4cc65-6c06-0410-ace0-fbb531ad65f3
parent 357b2752
No related branches found
No related tags found
No related merge requests found
......@@ -359,7 +359,10 @@ static void bridge_parking_pull(struct ast_bridge_parking *self, struct ast_brid
}
ao2_unlock(pu);
parking_notify_metermaids(pu->parking_space, self->lot->cfg->parking_con, AST_DEVICE_NOT_INUSE);
/* Pull can still happen after the bridge starts dissolving, so make sure we still have a lot before trying to notify metermaids. */
if (self->lot) {
parking_notify_metermaids(pu->parking_space, self->lot->cfg->parking_con, AST_DEVICE_NOT_INUSE);
}
switch (pu->resolution) {
case PARK_UNSET:
......
This diff is collapsed.
......@@ -110,6 +110,20 @@ struct parked_user {
enum park_call_resolution resolution; /*!< How did the parking session end? If the call is in a bridge, lock parked_user before checking/setting */
};
#if defined(TEST_FRAMEWORK)
/*!
* \since 12.0.0
* \brief Create an empty parking lot configuration structure
* useful for unit tests.
*
* \param cat name given to the parking lot
*
* \retval NULL failure
* \retval non-NULL successfully allocated parking lot
*/
struct parking_lot_cfg *parking_lot_cfg_create(const char *cat);
#endif
/*!
* \since 12.0.0
* \brief If a parking lot exists in the parking lot list already, update its status to match the provided
......@@ -268,10 +282,25 @@ struct parking_lot *parking_lot_find_by_name(const char *lot_name);
* \retval NULL on error
*
* \note This should be called only after verifying that the named parking lot doesn't already exist in a non-dynamic way.
* The parking lots container should be locked before verifying and remain locked until after this function is called.
*/
struct parking_lot *parking_create_dynamic_lot(const char *name, struct ast_channel *chan);
#if defined(TEST_FRAMEWORK)
/*!
* \since 12.0.0
* \brief Create a dynamic parking lot without respect to whether they are enabled by configuration
*
* \param name Dynamic parking lot name to create
* \param chan Channel parkee to get the dynamic parking lot parameters from
*
* \retval dynamically created parking lot on success
* \retval NULL on error
*
* \note This should be called only after verifying that the named parking lot doesn't already exist in a non-dynamic way.
*/
struct parking_lot *parking_create_dynamic_lot_forced(const char *name, struct ast_channel *chan);
#endif
/*!
* \since 12.0.0
* \brief Find parking lot name from channel
......@@ -525,3 +554,21 @@ int load_parking_devstate(void);
* \brief Unregister Parking devstate handler
*/
void unload_parking_devstate(void);
/*!
* \since 12.0.0
* \brief Register parking unit tests
*
* \retval 0 on success
* \retval nonzero on failure
*/
int load_parking_tests(void);
/*!
* \since 12.0.0
* \brief Unregister parking unit tests
*
* \retval 0 on success
* \retval nonzero on failure
*/
int unload_parking_tests(void);
......@@ -432,6 +432,13 @@ static void *parking_lot_cfg_alloc(const char *cat)
return lot_cfg;
}
#if defined(TEST_FRAMEWORK)
struct parking_lot_cfg *parking_lot_cfg_create(const char *cat)
{
return parking_lot_cfg_alloc(cat);
}
#endif
/*!
* XXX This is actually incredibly generic and might be better placed in something like astobj2 if there isn't already an equivalent
* \brief find an item in a container by its name
......@@ -928,7 +935,7 @@ static struct parking_lot_cfg *clone_parkinglot_cfg(struct parking_lot_cfg *sour
return cfg;
}
struct parking_lot *parking_create_dynamic_lot(const char *name, struct ast_channel *chan)
static struct parking_lot *create_dynamic_lot_full(const char *name, struct ast_channel *chan, int forced)
{
RAII_VAR(struct parking_lot_cfg *, cfg, NULL, ao2_cleanup);
RAII_VAR(struct parking_lot *, template_lot, NULL, ao2_cleanup);
......@@ -942,7 +949,7 @@ struct parking_lot *parking_create_dynamic_lot(const char *name, struct ast_chan
int dyn_start;
int dyn_end;
if (!parking_dynamic_lots_enabled()) {
if (!forced && !parking_dynamic_lots_enabled()) {
return NULL;
}
......@@ -1017,6 +1024,16 @@ struct parking_lot *parking_create_dynamic_lot(const char *name, struct ast_chan
return lot;
}
struct parking_lot *parking_create_dynamic_lot(const char *name, struct ast_channel *chan){
return create_dynamic_lot_full(name, chan, 0);
}
#if defined(TEST_FRAMEWORK)
struct parking_lot *parking_create_dynamic_lot_forced(const char *name, struct ast_channel *chan) {
return create_dynamic_lot_full(name, chan, 1);
}
#endif
/* Preapply */
static int verify_default_parking_lot(void)
......@@ -1208,9 +1225,14 @@ static int load_module(void)
goto error;
}
if (load_parking_tests()) {
goto error;
}
return AST_MODULE_LOAD_SUCCESS;
error:
/* XXX errored loads don't currently do a good job of cleaning up after themselves */
ao2_cleanup(parking_lot_container);
aco_info_destroy(&cfg_info);
return AST_MODULE_LOAD_DECLINE;
......@@ -1240,6 +1262,7 @@ static int unload_module(void)
* destroy existing parking lots
* uninstall parking related bridge features
* remove extensions owned by the parking registrar
* unload currently loaded unit tests, CLI/AMI commands, etc.
*/
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment