summaryrefslogtreecommitdiff
path: root/unit/test-avdtp.c
diff options
context:
space:
mode:
authorAndrei Emeltchenko <andrei.emeltchenko@intel.com>2015-02-20 14:43:15 +0200
committerSzymon Janc <szymon.janc@tieto.com>2015-02-22 21:26:25 +0100
commit37c942ff2ba1fc4e42a95957c8f24c19e468d4f0 (patch)
tree92c2c12f6d0e2fc8108c61eec2aefd418fd3320a /unit/test-avdtp.c
parent49450bf6f01f8f08ee585bda8f75ac7d7f40d0af (diff)
downloadbluez-37c942ff2ba1fc4e42a95957c8f24c19e468d4f0.tar.gz
android/avdtp: Refactor local SEP list handling
In order to deduplicate similar code in android/ and profiles/ we need to handle local SEP queue outside of avdtp.c. GSList is transformed to queue.
Diffstat (limited to 'unit/test-avdtp.c')
-rw-r--r--unit/test-avdtp.c95
1 files changed, 54 insertions, 41 deletions
diff --git a/unit/test-avdtp.c b/unit/test-avdtp.c
index 34820d1c3..a293a1d31 100644
--- a/unit/test-avdtp.c
+++ b/unit/test-avdtp.c
@@ -36,13 +36,12 @@
#include <glib.h>
#include "src/shared/util.h"
+#include "src/shared/queue.h"
#include "src/log.h"
#include "android/avdtp.h"
#define MAX_SEID 0x3E
-GSList *lseps = NULL;
-
struct test_pdu {
bool valid;
bool fragmented;
@@ -89,6 +88,7 @@ struct context {
struct avdtp *session;
struct avdtp_local_sep *sep;
struct avdtp_stream *stream;
+ struct queue *lseps;
guint source;
guint process;
int fd;
@@ -233,7 +233,11 @@ static struct context *context_new(uint16_t version, uint16_t imtu,
err = socketpair(AF_UNIX, SOCK_SEQPACKET | SOCK_CLOEXEC, 0, sv);
g_assert(err == 0);
- context->session = avdtp_new(sv[0], imtu, omtu, version);
+ context->lseps = queue_new();
+ g_assert(context->lseps);
+
+ context->session = avdtp_new(sv[0], imtu, omtu, version,
+ context->lseps);
g_assert(context->session != NULL);
channel = g_io_channel_unix_new(sv[1]);
@@ -505,7 +509,8 @@ static void test_server(gconstpointer data)
struct context *context = create_context(0x0100, data);
struct avdtp_local_sep *sep;
- sep = avdtp_register_sep(AVDTP_SEP_TYPE_SOURCE, AVDTP_MEDIA_TYPE_AUDIO,
+ sep = avdtp_register_sep(context->lseps, AVDTP_SEP_TYPE_SOURCE,
+ AVDTP_MEDIA_TYPE_AUDIO,
0x00, FALSE, &sep_ind, &sep_cfm,
context);
@@ -513,7 +518,8 @@ static void test_server(gconstpointer data)
execute_context(context);
- avdtp_unregister_sep(sep);
+ avdtp_unregister_sep(context->lseps, sep);
+ queue_destroy(context->lseps, NULL);
}
static void test_server_1_3(gconstpointer data)
@@ -521,14 +527,16 @@ static void test_server_1_3(gconstpointer data)
struct context *context = create_context(0x0103, data);
struct avdtp_local_sep *sep;
- sep = avdtp_register_sep(AVDTP_SEP_TYPE_SOURCE, AVDTP_MEDIA_TYPE_AUDIO,
+ sep = avdtp_register_sep(context->lseps, AVDTP_SEP_TYPE_SOURCE,
+ AVDTP_MEDIA_TYPE_AUDIO,
0x00, TRUE, &sep_ind, NULL, context);
g_idle_add(send_pdu, context);
execute_context(context);
- avdtp_unregister_sep(sep);
+ avdtp_unregister_sep(context->lseps, sep);
+ queue_destroy(context->lseps, NULL);
}
static void test_server_1_3_sink(gconstpointer data)
@@ -536,14 +544,16 @@ static void test_server_1_3_sink(gconstpointer data)
struct context *context = create_context(0x0103, data);
struct avdtp_local_sep *sep;
- sep = avdtp_register_sep(AVDTP_SEP_TYPE_SINK, AVDTP_MEDIA_TYPE_AUDIO,
+ sep = avdtp_register_sep(context->lseps, AVDTP_SEP_TYPE_SINK,
+ AVDTP_MEDIA_TYPE_AUDIO,
0x00, TRUE, &sep_ind, NULL, context);
g_idle_add(send_pdu, context);
execute_context(context);
- avdtp_unregister_sep(sep);
+ avdtp_unregister_sep(context->lseps, sep);
+ queue_destroy(context->lseps, NULL);
}
static void test_server_0_sep(gconstpointer data)
@@ -559,7 +569,8 @@ static void unregister_sep(void *data)
{
struct avdtp_local_sep *sep = data;
- avdtp_unregister_sep(sep);
+ /* Removed from the queue by caller */
+ avdtp_unregister_sep(NULL, sep);
}
static void test_server_seid(gconstpointer data)
@@ -569,25 +580,22 @@ static void test_server_seid(gconstpointer data)
unsigned int i;
for (i = 0; i < sizeof(int) * 8; i++) {
- sep = avdtp_register_sep(AVDTP_SEP_TYPE_SINK,
+ sep = avdtp_register_sep(context->lseps, AVDTP_SEP_TYPE_SINK,
AVDTP_MEDIA_TYPE_AUDIO,
0x00, TRUE, &sep_ind, NULL,
context);
g_assert(sep);
-
- lseps = g_slist_append(lseps, sep);
}
/* Now add (MAX_SEID + 1) SEP -> it shall fail */
- sep = avdtp_register_sep(AVDTP_SEP_TYPE_SINK,
+ sep = avdtp_register_sep(context->lseps, AVDTP_SEP_TYPE_SINK,
AVDTP_MEDIA_TYPE_AUDIO,
0x00, TRUE, &sep_ind, NULL,
context);
g_assert(!sep);
/* Remove all SEPs */
- g_slist_free_full(lseps, unregister_sep);
- lseps = NULL;
+ queue_destroy(context->lseps, unregister_sep);
}
static void test_server_seid_duplicate(gconstpointer data)
@@ -597,37 +605,34 @@ static void test_server_seid_duplicate(gconstpointer data)
int i;
for (i = 0; i < 2; i++) {
- sep = avdtp_register_sep(AVDTP_SEP_TYPE_SINK,
+ sep = avdtp_register_sep(context->lseps, AVDTP_SEP_TYPE_SINK,
AVDTP_MEDIA_TYPE_AUDIO,
0x00, TRUE, &sep_ind, NULL,
context);
g_assert(sep);
-
- lseps = g_slist_append(lseps, sep);
}
/* Remove 1st element */
- sep = g_slist_nth_data(lseps, 0);
- lseps = g_slist_remove(lseps, sep);
- avdtp_unregister_sep(sep);
+ sep = queue_peek_head(context->lseps);
+ g_assert(sep);
+
+ avdtp_unregister_sep(context->lseps, sep);
/* Now register new element */
- sep = avdtp_register_sep(AVDTP_SEP_TYPE_SINK,
+ sep = avdtp_register_sep(context->lseps, AVDTP_SEP_TYPE_SINK,
AVDTP_MEDIA_TYPE_AUDIO,
0x00, TRUE, &sep_ind, NULL,
context);
g_assert(sep);
- lseps = g_slist_append(lseps, sep);
- /* Check SEID ids */
+ /* Check SEID ids with DISCOVER */
g_idle_add(send_pdu, context);
execute_context(context);
/* Remove all SEPs */
- g_slist_free_full(lseps, unregister_sep);
- lseps = NULL;
+ queue_destroy(context->lseps, unregister_sep);
}
static gboolean sep_getcap_ind_frg(struct avdtp *session,
@@ -675,7 +680,8 @@ static void test_server_frg(gconstpointer data)
struct context *context = context_new(0x0100, 48, 48, data);
struct avdtp_local_sep *sep;
- sep = avdtp_register_sep(AVDTP_SEP_TYPE_SOURCE, AVDTP_MEDIA_TYPE_AUDIO,
+ sep = avdtp_register_sep(context->lseps, AVDTP_SEP_TYPE_SOURCE,
+ AVDTP_MEDIA_TYPE_AUDIO,
0x00, TRUE, &sep_ind_frg,
NULL, context);
@@ -683,7 +689,8 @@ static void test_server_frg(gconstpointer data)
execute_context(context);
- avdtp_unregister_sep(sep);
+ avdtp_unregister_sep(context->lseps, sep);
+ queue_destroy(context->lseps, NULL);
}
static void discover_cb(struct avdtp *session, GSList *seps,
@@ -758,16 +765,18 @@ static void test_client(gconstpointer data)
struct context *context = create_context(0x0100, data);
struct avdtp_local_sep *sep;
- sep = avdtp_register_sep(AVDTP_SEP_TYPE_SINK, AVDTP_MEDIA_TYPE_AUDIO,
- 0x00, FALSE, NULL, &sep_cfm,
- context);
+ sep = avdtp_register_sep(context->lseps, AVDTP_SEP_TYPE_SINK,
+ AVDTP_MEDIA_TYPE_AUDIO,
+ 0x00, FALSE, NULL, &sep_cfm, context);
+
context->sep = sep;
avdtp_discover(context->session, discover_cb, context);
execute_context(context);
- avdtp_unregister_sep(sep);
+ avdtp_unregister_sep(context->lseps, sep);
+ queue_destroy(context->lseps, NULL);
}
static void test_client_1_3(gconstpointer data)
@@ -775,16 +784,18 @@ static void test_client_1_3(gconstpointer data)
struct context *context = create_context(0x0103, data);
struct avdtp_local_sep *sep;
- sep = avdtp_register_sep(AVDTP_SEP_TYPE_SINK, AVDTP_MEDIA_TYPE_AUDIO,
- 0x00, TRUE, NULL, &sep_cfm,
- context);
+ sep = avdtp_register_sep(context->lseps, AVDTP_SEP_TYPE_SINK,
+ AVDTP_MEDIA_TYPE_AUDIO,
+ 0x00, TRUE, NULL, &sep_cfm, context);
+
context->sep = sep;
avdtp_discover(context->session, discover_cb, context);
execute_context(context);
- avdtp_unregister_sep(sep);
+ avdtp_unregister_sep(context->lseps, sep);
+ queue_destroy(context->lseps, NULL);
}
static void test_client_frg(gconstpointer data)
@@ -792,16 +803,18 @@ static void test_client_frg(gconstpointer data)
struct context *context = context_new(0x0100, 48, 48, data);
struct avdtp_local_sep *sep;
- sep = avdtp_register_sep(AVDTP_SEP_TYPE_SINK, AVDTP_MEDIA_TYPE_AUDIO,
- 0x00, TRUE, NULL, &sep_cfm,
- context);
+ sep = avdtp_register_sep(context->lseps, AVDTP_SEP_TYPE_SINK,
+ AVDTP_MEDIA_TYPE_AUDIO,
+ 0x00, TRUE, NULL, &sep_cfm, context);
+
context->sep = sep;
avdtp_discover(context->session, discover_cb, context);
execute_context(context);
- avdtp_unregister_sep(sep);
+ avdtp_unregister_sep(context->lseps, sep);
+ queue_destroy(context->lseps, NULL);
}
int main(int argc, char *argv[])