diff options
author | Jonathan Rose <jrose@digium.com> | 2014-10-15 19:17:29 +0000 |
---|---|---|
committer | Jonathan Rose <jrose@digium.com> | 2014-10-15 19:17:29 +0000 |
commit | 3d58066de94ffd2a2c44986be36bf26d49b1ce64 (patch) | |
tree | 3d786f427046e650bb87557d75e97e2a5b66855d | |
parent | 90c98d384b8e8dec92d3a913993160cb2bb1580e (diff) |
parking_tests: Fix assertions and possibly crashes in res_parking unit tests
Assertions were caused by attempting to play music on hold to a channel with
no formats. Parking unit test channels were given formats and a technology so
that they would be able to pretend to read/write frames.
ASTERISK-24413 #close
Reported by: Matt Jordan
Review: https://reviewboard.asterisk.org/r/4075/
........
Merged revisions 425611 from http://svn.asterisk.org/svn/asterisk/branches/13
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@425613 65c4cc65-6c06-0410-ace0-fbb531ad65f3
-rw-r--r-- | res/parking/parking_tests.c | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/res/parking/parking_tests.c b/res/parking/parking_tests.c index 26cb084ee..dbe749b39 100644 --- a/res/parking/parking_tests.c +++ b/res/parking/parking_tests.c @@ -36,6 +36,7 @@ ASTERISK_FILE_VERSION(__FILE__, "$Revision$") #include "asterisk/time.h" #include "asterisk/causes.h" #include "asterisk/pbx.h" +#include "asterisk/format_cache.h" #if defined(TEST_FRAMEWORK) @@ -50,6 +51,44 @@ static const struct ast_party_caller alice_callerid = { .id.number.valid = 1, }; +static int parking_test_write(struct ast_channel *chan, struct ast_frame *frame) +{ + return 0; +} + +static struct ast_frame *parking_test_read(struct ast_channel *chan) +{ + return &ast_null_frame; +} + +static const struct ast_channel_tech parking_test_tech = { + .type = CHANNEL_TECH_NAME, + .description = "Parking unit test technology", + .write = parking_test_write, + .read = parking_test_read, +}; + +/*! \brief Set ulaw format on the channel */ +static int set_test_formats(struct ast_channel *chan) +{ + struct ast_format_cap *caps; + + caps = ast_format_cap_alloc(AST_FORMAT_CAP_FLAG_DEFAULT); + if (!caps) { + return -1; + } + + ast_format_cap_append(caps, ast_format_ulaw, 0); + ast_channel_nativeformats_set(chan, caps); + ast_channel_set_writeformat(chan, ast_format_ulaw); + ast_channel_set_rawwriteformat(chan, ast_format_ulaw); + ast_channel_set_readformat(chan, ast_format_ulaw); + ast_channel_set_rawreadformat(chan, ast_format_ulaw); + ao2_ref(caps, -1); + + return 0; +} + /*! \brief Create a \ref test_cdr_chan_tech for Alice */ static struct ast_channel *create_alice_channel(void) { @@ -61,6 +100,14 @@ static struct ast_channel *create_alice_channel(void) return NULL; } + if (set_test_formats(alice)) { + ast_channel_unlock(alice); + ast_channel_release(alice); + return NULL; + } + + ast_channel_tech_set(alice, &parking_test_tech); + ast_channel_set_caller(alice, &alice_callerid, NULL); ast_channel_unlock(alice); |