mirror of
https://github.com/asterisk/asterisk.git
synced 2025-09-30 10:33:13 +00:00
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/ git-svn-id: https://origsvn.digium.com/svn/asterisk/branches/13@425611 65c4cc65-6c06-0410-ace0-fbb531ad65f3
This commit is contained in:
@@ -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);
|
||||
|
Reference in New Issue
Block a user