diff options
Diffstat (limited to 'tests')
-rw-r--r-- | tests/test_bridging.c | 292 | ||||
-rw-r--r-- | tests/test_config.c | 88 | ||||
-rw-r--r-- | tests/test_core_format.c | 5 | ||||
-rw-r--r-- | tests/test_taskprocessor.c | 2 |
4 files changed, 385 insertions, 2 deletions
diff --git a/tests/test_bridging.c b/tests/test_bridging.c new file mode 100644 index 000000000..08a2fcc1f --- /dev/null +++ b/tests/test_bridging.c @@ -0,0 +1,292 @@ +/* + * Asterisk -- An open source telephony toolkit. + * + * Copyright (C) 2017, Digium, Inc. + * + * Joshua Colp <jcolp@digium.com> + * + * See http://www.asterisk.org for more information about + * the Asterisk project. Please do not directly contact + * any of the maintainers of this project for assistance; + * the project provides a web site, mailing lists and IRC + * channels for your use. + * + * This program is free software, distributed under the terms of + * the GNU General Public License Version 2. See the LICENSE file + * at the top of the source tree. + */ + +/*! + * \file + * \brief Bridging unit tests + * + * \author Joshua Colp <jcolp@digium.com> + * + */ + +/*** MODULEINFO + <depend>TEST_FRAMEWORK</depend> + <support_level>core</support_level> + ***/ + +#include "asterisk.h" + +ASTERISK_FILE_VERSION(__FILE__, "$Revision$") + +#include "asterisk/module.h" +#include "asterisk/test.h" +#include "asterisk/channel.h" +#include "asterisk/time.h" +#include "asterisk/bridge.h" +#include "asterisk/bridge_basic.h" +#include "asterisk/features.h" +#include "asterisk/format_cache.h" + +#define TEST_CATEGORY "/main/bridging/" + +#define CHANNEL_TECH_NAME "BridgingTestChannel" + +#define TEST_CHANNEL_FORMAT ast_format_slin + +/*! \brief A private structure for the test channel */ +struct test_bridging_chan_pvt { + /* \brief The expected indication */ + int condition; + /*! \brief The number of indicated things */ + unsigned int indicated; +}; + +/*! \brief Callback function for when a frame is written to a channel */ +static int test_bridging_chan_indicate(struct ast_channel *chan, int condition, const void *data, size_t datalen) +{ + struct test_bridging_chan_pvt *test_pvt = ast_channel_tech_pvt(chan); + + if (condition == test_pvt->condition) { + test_pvt->indicated++; + } + + return 0; +} + +/*! \brief Callback function for when a channel is hung up */ +static int test_bridging_chan_hangup(struct ast_channel *chan) +{ + struct test_bridging_chan_pvt *test_pvt = ast_channel_tech_pvt(chan); + + ast_free(test_pvt); + ast_channel_tech_pvt_set(chan, NULL); + + return 0; +} + +/*! \brief A channel technology used for the unit tests */ +static struct ast_channel_tech test_bridging_chan_tech = { + .type = CHANNEL_TECH_NAME, + .description = "Mock channel technology for bridge tests", + .indicate = test_bridging_chan_indicate, + .hangup = test_bridging_chan_hangup, + .properties = AST_CHAN_TP_INTERNAL, +}; + +static void test_nanosleep(int secs, long nanosecs) +{ + struct timespec sleep_time = {secs, nanosecs}; + + while ((nanosleep(&sleep_time, &sleep_time) == -1) && (errno == EINTR)) { + } +} + +/*! \brief Wait until a channel is bridged */ +static void wait_for_bridged(struct ast_channel *channel) +{ + ast_channel_lock(channel); + while (!ast_channel_is_bridged(channel)) { + ast_channel_unlock(channel); + test_nanosleep(0, 1000000); + ast_channel_lock(channel); + } + ast_channel_unlock(channel); +} + +/*! \brief Wait until a channel is not bridged */ +static void wait_for_unbridged(struct ast_channel *channel) +{ + ast_channel_lock(channel); + while (ast_channel_is_bridged(channel)) { + ast_channel_unlock(channel); + test_nanosleep(0, 1000000); + ast_channel_lock(channel); + } + ast_channel_unlock(channel); +} + +/*! \brief Wait until a channel has no frames on its read queue */ +static void wait_for_empty_queue(struct ast_channel *channel) +{ + ast_channel_lock(channel); + while (!AST_LIST_EMPTY(ast_channel_readq(channel))) { + ast_channel_unlock(channel); + test_nanosleep(0, 1000000); + ast_channel_lock(channel); + } + ast_channel_unlock(channel); +} + +/*! \brief Create a \ref test_bridging_chan_tech for Alice. */ +#define START_ALICE(channel, pvt) START_CHANNEL(channel, pvt, "Alice", "100") + +/*! \brief Create a \ref test_bridging_chan_tech for Bob. */ +#define START_BOB(channel, pvt) START_CHANNEL(channel, pvt, "Bob", "200") + +#define START_CHANNEL(channel, pvt, name, number) do { \ + channel = ast_channel_alloc(0, AST_STATE_UP, number, name, number, number, \ + "default", NULL, NULL, 0, CHANNEL_TECH_NAME "/" name); \ + pvt = ast_calloc(1, sizeof(*pvt)); \ + ast_channel_tech_pvt_set(channel, pvt); \ + ast_channel_nativeformats_set(channel, test_bridging_chan_tech.capabilities); \ + ast_channel_set_rawwriteformat(channel, TEST_CHANNEL_FORMAT); \ + ast_channel_set_rawreadformat(channel, TEST_CHANNEL_FORMAT); \ + ast_channel_set_writeformat(channel, TEST_CHANNEL_FORMAT); \ + ast_channel_set_readformat(channel, TEST_CHANNEL_FORMAT); \ + ast_channel_unlock(channel); \ + } while (0) + +/*! \brief Hang up a test channel safely */ +#define HANGUP_CHANNEL(channel) do { \ + ao2_ref(channel, +1); \ + ast_hangup((channel)); \ + ao2_cleanup(channel); \ + channel = NULL; \ + } while (0) + +static void safe_channel_release(struct ast_channel *chan) +{ + if (!chan) { + return; + } + ast_channel_release(chan); +} + +static void safe_bridge_destroy(struct ast_bridge *bridge) +{ + if (!bridge) { + return; + } + ast_bridge_destroy(bridge, 0); +} + +static void stream_periodic_frames(struct ast_channel *chan, int ms, int interval_ms) +{ + long nanosecs; + + ast_assert(chan != NULL); + ast_assert(0 < ms); + ast_assert(0 < interval_ms); + + nanosecs = interval_ms * 1000000L; + while (0 < ms) { + ast_queue_frame(chan, &ast_null_frame); + + if (interval_ms < ms) { + ms -= interval_ms; + } else { + nanosecs = ms * 1000000L; + ms = 0; + } + test_nanosleep(0, nanosecs); + } +} + +AST_TEST_DEFINE(test_bridging_deferred_queue) +{ + RAII_VAR(struct ast_channel *, chan_alice, NULL, safe_channel_release); + struct test_bridging_chan_pvt *alice_pvt; + struct ast_control_t38_parameters t38_parameters = { + .request_response = AST_T38_REQUEST_NEGOTIATE, + }; + struct ast_frame frame = { + .frametype = AST_FRAME_CONTROL, + .subclass.integer = AST_CONTROL_T38_PARAMETERS, + .data.ptr = &t38_parameters, + .datalen = sizeof(t38_parameters), + }; + RAII_VAR(struct ast_channel *, chan_bob, NULL, safe_channel_release); + struct test_bridging_chan_pvt *bob_pvt; + RAII_VAR(struct ast_bridge *, bridge1, NULL, safe_bridge_destroy); + + switch (cmd) { + case TEST_INIT: + info->name = __func__; + info->category = TEST_CATEGORY; + info->summary = "Test that deferred frames from a channel in a bridge get written"; + info->description = + "This test creates two channels, queues a deferrable frame on one, places it into\n" + "a bridge, confirms the frame was read by the bridge, adds the second channel to the\n" + "bridge, and makes sure the deferred frame is written to it."; + return AST_TEST_NOT_RUN; + case TEST_EXECUTE: + break; + } + + /* Create the bridges */ + bridge1 = ast_bridge_basic_new(); + ast_test_validate(test, bridge1 != NULL); + + /* Create channels that will go into the bridge */ + START_ALICE(chan_alice, alice_pvt); + START_BOB(chan_bob, bob_pvt); + bob_pvt->condition = AST_CONTROL_T38_PARAMETERS; + + /* Bridge alice and wait for the frame to be deferred */ + ast_test_validate(test, !ast_bridge_impart(bridge1, chan_alice, NULL, NULL, AST_BRIDGE_IMPART_CHAN_DEPARTABLE)); + wait_for_bridged(chan_alice); + ast_queue_frame(chan_alice, &frame); + wait_for_empty_queue(chan_alice); + + /* Bridge bob for a second so it can receive the deferred T.38 request negotiate frame */ + ast_test_validate(test, !ast_bridge_impart(bridge1, chan_bob, NULL, NULL, AST_BRIDGE_IMPART_CHAN_DEPARTABLE)); + wait_for_bridged(chan_bob); + stream_periodic_frames(chan_alice, 1000, 20); + ast_test_validate(test, !ast_bridge_depart(chan_bob)); + wait_for_unbridged(chan_bob); + + /* Ensure that we received the expected indications while it was in there (request to negotiate, and to terminate) */ + ast_test_validate(test, bob_pvt->indicated == 2); + + /* Now remove alice since we are done */ + ast_test_validate(test, !ast_bridge_depart(chan_alice)); + wait_for_unbridged(chan_alice); + + /* Hangup the channels */ + HANGUP_CHANNEL(chan_alice); + HANGUP_CHANNEL(chan_bob); + + return AST_TEST_PASS; +} + +static int unload_module(void) +{ + AST_TEST_UNREGISTER(test_bridging_deferred_queue); + + ast_channel_unregister(&test_bridging_chan_tech); + ao2_cleanup(test_bridging_chan_tech.capabilities); + test_bridging_chan_tech.capabilities = NULL; + + return 0; +} + +static int load_module(void) +{ + test_bridging_chan_tech.capabilities = ast_format_cap_alloc(AST_FORMAT_CAP_FLAG_DEFAULT); + if (!test_bridging_chan_tech.capabilities) { + return AST_MODULE_LOAD_DECLINE; + } + ast_format_cap_append(test_bridging_chan_tech.capabilities, TEST_CHANNEL_FORMAT, 0); + ast_channel_register(&test_bridging_chan_tech); + + AST_TEST_REGISTER(test_bridging_deferred_queue); + + return AST_MODULE_LOAD_SUCCESS; +} + +AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "Bridging Unit Tests"); diff --git a/tests/test_config.c b/tests/test_config.c index fd14908b6..8fb473535 100644 --- a/tests/test_config.c +++ b/tests/test_config.c @@ -43,6 +43,7 @@ ASTERISK_FILE_VERSION(__FILE__, "$Revision$"); #include "asterisk/config_options.h" #include "asterisk/netsock2.h" #include "asterisk/acl.h" +#include "asterisk/app.h" #include "asterisk/pbx.h" #include "asterisk/frame.h" #include "asterisk/utils.h" @@ -1039,6 +1040,7 @@ AST_TEST_DEFINE(config_hook) res = AST_TEST_PASS; out: + ast_config_hook_unregister("test_hook"); delete_config_file(); return res; } @@ -1082,6 +1084,13 @@ enum { ast_test_status_update(test, "ast_parse_arg double failed with %f != %f\n", *r, e); \ ret = AST_TEST_FAIL; \ } \ + } else if (((flags) & PARSE_TYPE) == PARSE_TIMELEN) { \ + int *r = (int *) (void *) result; \ + int e = (int) expected_result; \ + if (*r != e) { \ + ast_test_status_update(test, "ast_parse_arg timelen failed with %d != %d\n", *r, e); \ + ret = AST_TEST_FAIL; \ + } \ } \ } \ *(result) = DEFAULTVAL; \ @@ -1092,6 +1101,7 @@ AST_TEST_DEFINE(ast_parse_arg_test) int ret = AST_TEST_PASS; int32_t int32_t_val = DEFAULTVAL; uint32_t uint32_t_val = DEFAULTVAL; + int timelen_val = DEFAULTVAL; double double_val = DEFAULTVAL; switch (cmd) { @@ -1224,6 +1234,60 @@ AST_TEST_DEFINE(ast_parse_arg_test) TEST_PARSE(" -123", EXPECT_FAIL, DEFAULTVAL, PARSE_UINT32, &uint32_t_val); + /* timelen testing */ + TEST_PARSE("123", EXPECT_SUCCEED, 123, PARSE_TIMELEN, &timelen_val, TIMELEN_MILLISECONDS); + TEST_PARSE("-123", EXPECT_SUCCEED, -123, PARSE_TIMELEN, &timelen_val, TIMELEN_MILLISECONDS); + TEST_PARSE("0", EXPECT_SUCCEED, 0, PARSE_TIMELEN, &timelen_val, TIMELEN_MILLISECONDS); + TEST_PARSE("not a number", EXPECT_FAIL, DEFAULTVAL, PARSE_TIMELEN, &timelen_val, TIMELEN_MILLISECONDS); + TEST_PARSE("7not a number", EXPECT_FAIL, DEFAULTVAL, PARSE_TIMELEN, &timelen_val, TIMELEN_MILLISECONDS); + + TEST_PARSE("123s", EXPECT_SUCCEED, 123000, PARSE_TIMELEN, &timelen_val, TIMELEN_MILLISECONDS); + TEST_PARSE("-123s", EXPECT_SUCCEED, -123000, PARSE_TIMELEN, &timelen_val, TIMELEN_MILLISECONDS); + TEST_PARSE("1m", EXPECT_SUCCEED, 60000, PARSE_TIMELEN, &timelen_val, TIMELEN_MILLISECONDS); + TEST_PARSE("1", EXPECT_SUCCEED, 60000, PARSE_TIMELEN, &timelen_val, TIMELEN_MINUTES); + TEST_PARSE("1h", EXPECT_SUCCEED, 3600000, PARSE_TIMELEN, &timelen_val, TIMELEN_MILLISECONDS); + TEST_PARSE("1", EXPECT_SUCCEED, 3600000, PARSE_TIMELEN, &timelen_val, TIMELEN_HOURS); + + TEST_PARSE("123", EXPECT_SUCCEED, 123, PARSE_TIMELEN | PARSE_DEFAULT, &timelen_val, TIMELEN_MILLISECONDS, 7); + TEST_PARSE("-123", EXPECT_SUCCEED, -123, PARSE_TIMELEN | PARSE_DEFAULT, &timelen_val, TIMELEN_MILLISECONDS, 7); + TEST_PARSE("0", EXPECT_SUCCEED, 0, PARSE_TIMELEN | PARSE_DEFAULT, &timelen_val, TIMELEN_MILLISECONDS, 7); + TEST_PARSE("not a number", EXPECT_FAIL, 7, PARSE_TIMELEN | PARSE_DEFAULT, &timelen_val, TIMELEN_MILLISECONDS, 7); + TEST_PARSE("7not a number", EXPECT_FAIL, 7, PARSE_TIMELEN | PARSE_DEFAULT, &timelen_val, TIMELEN_MILLISECONDS, 7); + + TEST_PARSE("123", EXPECT_SUCCEED, 123, PARSE_TIMELEN | PARSE_IN_RANGE, &timelen_val, TIMELEN_MILLISECONDS, 0, 200); + TEST_PARSE("-123", EXPECT_SUCCEED, -123, PARSE_TIMELEN | PARSE_IN_RANGE, &timelen_val, TIMELEN_MILLISECONDS, -200, 100); + TEST_PARSE("0", EXPECT_SUCCEED, 0, PARSE_TIMELEN | PARSE_IN_RANGE, &timelen_val, TIMELEN_MILLISECONDS, -1, 0); + TEST_PARSE("123", EXPECT_FAIL, DEFAULTVAL, PARSE_TIMELEN | PARSE_IN_RANGE, &timelen_val, TIMELEN_MILLISECONDS, 0, 122); + TEST_PARSE("-123", EXPECT_FAIL, DEFAULTVAL, PARSE_TIMELEN | PARSE_IN_RANGE, &timelen_val, TIMELEN_MILLISECONDS, -122, 100); + TEST_PARSE("0", EXPECT_FAIL, DEFAULTVAL, PARSE_TIMELEN | PARSE_IN_RANGE, &timelen_val, TIMELEN_MILLISECONDS, 1, 100); + TEST_PARSE("not a number", EXPECT_FAIL, DEFAULTVAL, PARSE_TIMELEN | PARSE_IN_RANGE, &timelen_val, TIMELEN_MILLISECONDS, INT_MIN, INT_MAX); + TEST_PARSE("7not a number", EXPECT_FAIL, DEFAULTVAL, PARSE_TIMELEN | PARSE_IN_RANGE, &timelen_val, TIMELEN_MILLISECONDS, INT_MIN, INT_MAX); + TEST_PARSE("123", EXPECT_FAIL, DEFAULTVAL, PARSE_TIMELEN | PARSE_OUT_RANGE, &timelen_val, TIMELEN_MILLISECONDS, 0, 200); + TEST_PARSE("-123", EXPECT_FAIL, DEFAULTVAL, PARSE_TIMELEN | PARSE_OUT_RANGE, &timelen_val, TIMELEN_MILLISECONDS, -200, 100); + TEST_PARSE("0", EXPECT_FAIL, DEFAULTVAL, PARSE_TIMELEN | PARSE_OUT_RANGE, &timelen_val, TIMELEN_MILLISECONDS, -1, 0); + TEST_PARSE("123", EXPECT_SUCCEED, 123, PARSE_TIMELEN | PARSE_OUT_RANGE, &timelen_val, TIMELEN_MILLISECONDS, 0, 122); + TEST_PARSE("-123", EXPECT_SUCCEED, -123, PARSE_TIMELEN | PARSE_OUT_RANGE, &timelen_val, TIMELEN_MILLISECONDS, -122, 100); + TEST_PARSE("0", EXPECT_SUCCEED, 0, PARSE_TIMELEN | PARSE_OUT_RANGE, &timelen_val, TIMELEN_MILLISECONDS, 1, 100); + TEST_PARSE("not a number", EXPECT_FAIL, DEFAULTVAL, PARSE_TIMELEN | PARSE_OUT_RANGE, &timelen_val, TIMELEN_MILLISECONDS, INT_MIN, INT_MAX); + TEST_PARSE("7not a number", EXPECT_FAIL, DEFAULTVAL, PARSE_TIMELEN | PARSE_OUT_RANGE, &timelen_val, TIMELEN_MILLISECONDS, INT_MIN, INT_MAX); + + TEST_PARSE("123", EXPECT_SUCCEED, 123, PARSE_TIMELEN | PARSE_DEFAULT | PARSE_IN_RANGE, &timelen_val, TIMELEN_MILLISECONDS, 7, 0, 200); + TEST_PARSE("-123", EXPECT_SUCCEED, -123, PARSE_TIMELEN | PARSE_DEFAULT | PARSE_IN_RANGE, &timelen_val, TIMELEN_MILLISECONDS, 7, -200, 100); + TEST_PARSE("0", EXPECT_SUCCEED, 0, PARSE_TIMELEN | PARSE_DEFAULT | PARSE_IN_RANGE, &timelen_val, TIMELEN_MILLISECONDS, 7, -1, 0); + TEST_PARSE("123", EXPECT_FAIL, 7, PARSE_TIMELEN | PARSE_DEFAULT | PARSE_IN_RANGE, &timelen_val, TIMELEN_MILLISECONDS, 7, 0, 122); + TEST_PARSE("-123", EXPECT_FAIL, 7, PARSE_TIMELEN | PARSE_DEFAULT | PARSE_IN_RANGE, &timelen_val, TIMELEN_MILLISECONDS, 7, -122, 100); + TEST_PARSE("0", EXPECT_FAIL, 7, PARSE_TIMELEN | PARSE_DEFAULT | PARSE_IN_RANGE, &timelen_val, TIMELEN_MILLISECONDS, 7, 1, 100); + TEST_PARSE("not a number", EXPECT_FAIL, 7, PARSE_TIMELEN | PARSE_DEFAULT | PARSE_IN_RANGE, &timelen_val, TIMELEN_MILLISECONDS, 7, INT_MIN, INT_MAX); + TEST_PARSE("7not a number", EXPECT_FAIL, 7, PARSE_TIMELEN | PARSE_DEFAULT | PARSE_IN_RANGE, &timelen_val, TIMELEN_MILLISECONDS, 7, INT_MIN, INT_MAX); + TEST_PARSE("123", EXPECT_FAIL, 7, PARSE_TIMELEN | PARSE_DEFAULT | PARSE_OUT_RANGE, &timelen_val, TIMELEN_MILLISECONDS, 7, 0, 200); + TEST_PARSE("-123", EXPECT_FAIL, 7, PARSE_TIMELEN | PARSE_DEFAULT | PARSE_OUT_RANGE, &timelen_val, TIMELEN_MILLISECONDS, 7, -200, 100); + TEST_PARSE("0", EXPECT_FAIL, 7, PARSE_TIMELEN | PARSE_DEFAULT | PARSE_OUT_RANGE, &timelen_val, TIMELEN_MILLISECONDS, 7, -1, 0); + TEST_PARSE("123", EXPECT_SUCCEED, 123, PARSE_TIMELEN | PARSE_DEFAULT | PARSE_OUT_RANGE, &timelen_val, TIMELEN_MILLISECONDS, 7, 0, 122); + TEST_PARSE("-123", EXPECT_SUCCEED, -123, PARSE_TIMELEN | PARSE_DEFAULT | PARSE_OUT_RANGE, &timelen_val, TIMELEN_MILLISECONDS, 7, -122, 100); + TEST_PARSE("0", EXPECT_SUCCEED, 0, PARSE_TIMELEN | PARSE_DEFAULT | PARSE_OUT_RANGE, &timelen_val, TIMELEN_MILLISECONDS, 7, 1, 100); + TEST_PARSE("not a number", EXPECT_FAIL, 7, PARSE_TIMELEN | PARSE_DEFAULT | PARSE_OUT_RANGE, &timelen_val, TIMELEN_MILLISECONDS, 7, INT_MIN, INT_MAX); + TEST_PARSE("7not a number", EXPECT_FAIL, 7, PARSE_TIMELEN | PARSE_DEFAULT | PARSE_OUT_RANGE, &timelen_val, TIMELEN_MILLISECONDS, 7, INT_MIN, INT_MAX); + /* double testing */ TEST_PARSE("123", EXPECT_SUCCEED, 123, PARSE_DOUBLE, &double_val); TEST_PARSE("123.123", EXPECT_SUCCEED, 123.123, PARSE_DOUBLE, &double_val); @@ -1283,6 +1347,10 @@ struct test_item { ); int32_t intopt; uint32_t uintopt; + int timelenopt1; + int timelenopt2; + int timelenopt3; + int timelenopt4; unsigned int flags; double doubleopt; struct ast_sockaddr sockaddropt; @@ -1437,6 +1505,8 @@ AST_TEST_DEFINE(config_options_test) #define INT_CONFIG "-1" #define UINT_DEFAULT "2" #define UINT_CONFIG "1" +#define TIMELEN_DEFAULT "2" +#define TIMELEN_CONFIG "1" #define DOUBLE_DEFAULT "1.1" #define DOUBLE_CONFIG "0.1" #define SOCKADDR_DEFAULT "4.3.2.1:4321" @@ -1471,6 +1541,10 @@ AST_TEST_DEFINE(config_options_test) /* Register all options */ aco_option_register(&cfg_info, "intopt", ACO_EXACT, config_test_conf.types, INT_DEFAULT, OPT_INT_T, 0, FLDSET(struct test_item, intopt)); aco_option_register(&cfg_info, "uintopt", ACO_EXACT, config_test_conf.types, UINT_DEFAULT, OPT_UINT_T, 0, FLDSET(struct test_item, uintopt)); + aco_option_register(&cfg_info, "timelenopt1", ACO_EXACT, config_test_conf.types, TIMELEN_DEFAULT, OPT_TIMELEN_T, 0, FLDSET(struct test_item, timelenopt1), TIMELEN_MILLISECONDS); + aco_option_register(&cfg_info, "timelenopt2", ACO_EXACT, config_test_conf.types, TIMELEN_DEFAULT, OPT_TIMELEN_T, 0, FLDSET(struct test_item, timelenopt2), TIMELEN_SECONDS); + aco_option_register(&cfg_info, "timelenopt3", ACO_EXACT, config_test_conf.types, TIMELEN_DEFAULT, OPT_TIMELEN_T, 0, FLDSET(struct test_item, timelenopt3), TIMELEN_MINUTES); + aco_option_register(&cfg_info, "timelenopt4", ACO_EXACT, config_test_conf.types, TIMELEN_DEFAULT, OPT_TIMELEN_T, 0, FLDSET(struct test_item, timelenopt4), TIMELEN_HOURS); aco_option_register(&cfg_info, "doubleopt", ACO_EXACT, config_test_conf.types, DOUBLE_DEFAULT, OPT_DOUBLE_T, 0, FLDSET(struct test_item, doubleopt)); aco_option_register(&cfg_info, "sockaddropt", ACO_EXACT, config_test_conf.types, SOCKADDR_DEFAULT, OPT_SOCKADDR_T, 0, FLDSET(struct test_item, sockaddropt)); aco_option_register(&cfg_info, "boolopt", ACO_EXACT, config_test_conf.types, BOOL_DEFAULT, OPT_BOOL_T, 1, FLDSET(struct test_item, boolopt)); @@ -1492,6 +1566,14 @@ AST_TEST_DEFINE(config_options_test) ast_parse_arg(INT_DEFAULT, PARSE_INT32, &defaults.intopt); ast_parse_arg(INT_CONFIG, PARSE_INT32, &configs.intopt); + ast_parse_arg(TIMELEN_DEFAULT, PARSE_TIMELEN, &defaults.timelenopt1, TIMELEN_MILLISECONDS); + ast_parse_arg(TIMELEN_CONFIG, PARSE_TIMELEN, &configs.timelenopt1, TIMELEN_MILLISECONDS); + ast_parse_arg(TIMELEN_DEFAULT, PARSE_TIMELEN, &defaults.timelenopt2, TIMELEN_SECONDS); + ast_parse_arg(TIMELEN_CONFIG, PARSE_TIMELEN, &configs.timelenopt2, TIMELEN_SECONDS); + ast_parse_arg(TIMELEN_DEFAULT, PARSE_TIMELEN, &defaults.timelenopt3, TIMELEN_MINUTES); + ast_parse_arg(TIMELEN_CONFIG, PARSE_TIMELEN, &configs.timelenopt3, TIMELEN_MINUTES); + ast_parse_arg(TIMELEN_DEFAULT, PARSE_TIMELEN, &defaults.timelenopt4, TIMELEN_HOURS); + ast_parse_arg(TIMELEN_CONFIG, PARSE_TIMELEN, &configs.timelenopt4, TIMELEN_HOURS); ast_parse_arg(UINT_DEFAULT, PARSE_UINT32, &defaults.uintopt); ast_parse_arg(UINT_CONFIG, PARSE_UINT32, &configs.uintopt); ast_parse_arg(DOUBLE_DEFAULT, PARSE_DOUBLE, &defaults.doubleopt); @@ -1553,6 +1635,10 @@ AST_TEST_DEFINE(config_options_test) NOT_EQUAL_FAIL(intopt, "%d"); NOT_EQUAL_FAIL(uintopt, "%u"); + NOT_EQUAL_FAIL(timelenopt1, "%d"); + NOT_EQUAL_FAIL(timelenopt2, "%d"); + NOT_EQUAL_FAIL(timelenopt3, "%d"); + NOT_EQUAL_FAIL(timelenopt4, "%d"); NOT_EQUAL_FAIL(boolopt, "%d"); NOT_EQUAL_FAIL(flags, "%u"); NOT_EQUAL_FAIL(customopt, "%d"); @@ -1592,6 +1678,8 @@ AST_TEST_DEFINE(config_options_test) configs.codeccapopt = NULL; ast_string_field_free_memory(&defaults); ast_string_field_free_memory(&configs); + aco_info_destroy(&cfg_info); + ao2_global_obj_release(global_obj); return res; } diff --git a/tests/test_core_format.c b/tests/test_core_format.c index a3819c6d0..e4199dbed 100644 --- a/tests/test_core_format.c +++ b/tests/test_core_format.c @@ -860,6 +860,7 @@ AST_TEST_DEFINE(format_attribute_set_without_interface) { RAII_VAR(struct ast_codec *, codec, NULL, ao2_cleanup); RAII_VAR(struct ast_format *, format, NULL, ao2_cleanup); + struct ast_format *attr_set; switch (cmd) { case TEST_INIT: @@ -885,10 +886,12 @@ AST_TEST_DEFINE(format_attribute_set_without_interface) return AST_TEST_FAIL; } - if (!ast_format_attribute_set(format, "bees", "cool")) { + attr_set = ast_format_attribute_set(format, "bees", "cool"); + if (!attr_set) { ast_test_status_update(test, "Successfully set an attribute on a format without an interface\n"); return AST_TEST_FAIL; } + ao2_cleanup(attr_set); return AST_TEST_PASS; } diff --git a/tests/test_taskprocessor.c b/tests/test_taskprocessor.c index be48f9248..ad2074cb8 100644 --- a/tests/test_taskprocessor.c +++ b/tests/test_taskprocessor.c @@ -677,7 +677,7 @@ AST_TEST_DEFINE(taskprocessor_push_local) { RAII_VAR(struct ast_taskprocessor *, tps, NULL, ast_taskprocessor_unreference); - struct task_data *task_data; + RAII_VAR(struct task_data *, task_data, NULL, ao2_cleanup); int local_data; int res; |