[asterisk-commits] jrose: trunk r425613 - in /trunk: ./ res/parking/parking_tests.c

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Wed Oct 15 14:17:31 CDT 2014


Author: jrose
Date: Wed Oct 15 14:17:29 2014
New Revision: 425613

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=425613
Log:
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

Modified:
    trunk/   (props changed)
    trunk/res/parking/parking_tests.c

Propchange: trunk/
------------------------------------------------------------------------------
Binary property 'branch-13-merged' - no diff available.

Modified: trunk/res/parking/parking_tests.c
URL: http://svnview.digium.com/svn/asterisk/trunk/res/parking/parking_tests.c?view=diff&rev=425613&r1=425612&r2=425613
==============================================================================
--- trunk/res/parking/parking_tests.c (original)
+++ trunk/res/parking/parking_tests.c Wed Oct 15 14:17:29 2014
@@ -36,6 +36,7 @@
 #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 @@
 	.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)
 {
@@ -60,6 +99,14 @@
 	if (!alice) {
 		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);
 




More information about the asterisk-commits mailing list