stream: Add stream topology unit tests and fix uncovered bugs.

This change adds unit tests for the various API calls relating
to stream topologies. This includes creation, destruction,
inspection, and manipulation.

Through this a few bugs were uncovered in the implementation:

1. Creating a topology using a format capabilities would fail as
the code considered a return value of 0 from the append stream
function to indicate an error which is incorrect.

2. Not all functions which placed a stream into a topology
set the position on the stream itself.

3. Appending a stream would cause a frack if the position
provided was the last one. This occurred because the existing
stream was queried but the index was outside of what the
vector was currently at for size.

ASTERISK-26786

Change-Id: Id5590e87c8a605deea1a89e53169a9c011d66fa0
This commit is contained in:
Joshua Colp
2017-02-13 17:00:42 +00:00
parent 8b72ec312b
commit 6c4657e28e
2 changed files with 409 additions and 4 deletions

View File

@@ -239,6 +239,8 @@ int ast_stream_topology_append_stream(struct ast_stream_topology *topology, stru
return -1;
}
stream->position = AST_VECTOR_SIZE(&topology->streams) - 1;
return AST_VECTOR_SIZE(&topology->streams) - 1;
}
@@ -268,15 +270,18 @@ int ast_stream_topology_set_stream(struct ast_stream_topology *topology,
return -1;
}
existing_stream = AST_VECTOR_GET(&topology->streams, position);
ast_stream_destroy(existing_stream);
if (position < AST_VECTOR_SIZE(&topology->streams)) {
existing_stream = AST_VECTOR_GET(&topology->streams, position);
ast_stream_destroy(existing_stream);
}
stream->position = position;
if (position == AST_VECTOR_SIZE(&topology->streams)) {
AST_VECTOR_APPEND(&topology->streams, stream);
return 0;
}
stream->position = position;
return AST_VECTOR_REPLACE(&topology->streams, position, stream);
}
@@ -323,7 +328,7 @@ struct ast_stream_topology *ast_stream_topology_create_from_format_cap(
/* We're transferring the initial ref so no bump needed */
stream->formats = new_cap;
stream->state = AST_STREAM_STATE_SENDRECV;
if (!ast_stream_topology_append_stream(topology, stream)) {
if (ast_stream_topology_append_stream(topology, stream) == -1) {
ast_stream_destroy(stream);
ast_stream_topology_destroy(topology);
return NULL;