Linux bluetooth development
 help / color / mirror / Atom feed
From: Andrei Emeltchenko <Andrei.Emeltchenko.news@gmail.com>
To: linux-bluetooth@vger.kernel.org
Subject: [RFCv3 2/9] unit/avdtp: Refactor context destroy
Date: Fri, 20 Feb 2015 14:43:16 +0200	[thread overview]
Message-ID: <1424436203-28935-3-git-send-email-Andrei.Emeltchenko.news@gmail.com> (raw)
In-Reply-To: <1424436203-28935-1-git-send-email-Andrei.Emeltchenko.news@gmail.com>

From: Andrei Emeltchenko <andrei.emeltchenko@intel.com>

destroy_context() function will be used for dummy_tests without
context_execute()
---
 unit/test-avdtp.c | 58 +++++++++++++++++++++----------------------------------
 1 file changed, 22 insertions(+), 36 deletions(-)

diff --git a/unit/test-avdtp.c b/unit/test-avdtp.c
index a293a1d..805f08d 100644
--- a/unit/test-avdtp.c
+++ b/unit/test-avdtp.c
@@ -264,10 +264,16 @@ static struct context *create_context(uint16_t version, gconstpointer data)
 	return context_new(version, 672, 672, data);
 }
 
-static void execute_context(struct context *context)
+static void unregister_sep(void *data)
 {
-	g_main_loop_run(context->main_loop);
+	struct avdtp_local_sep *sep = data;
+
+	/* Removed from the queue by caller */
+	avdtp_unregister_sep(NULL, sep);
+}
 
+static void destroy_context(struct context *context)
+{
 	if (context->source > 0)
 		g_source_remove(context->source);
 	avdtp_unref(context->session);
@@ -275,9 +281,18 @@ static void execute_context(struct context *context)
 	g_main_loop_unref(context->main_loop);
 
 	test_free(context->data);
+	queue_destroy(context->lseps, unregister_sep);
+
 	g_free(context);
 }
 
+static void execute_context(struct context *context)
+{
+	g_main_loop_run(context->main_loop);
+
+	destroy_context(context);
+}
+
 static gboolean sep_getcap_ind(struct avdtp *session,
 					struct avdtp_local_sep *sep,
 					GSList **caps, uint8_t *err,
@@ -513,13 +528,11 @@ static void test_server(gconstpointer data)
 					AVDTP_MEDIA_TYPE_AUDIO,
 					0x00, FALSE, &sep_ind, &sep_cfm,
 					context);
+	g_assert(sep);
 
 	g_idle_add(send_pdu, context);
 
 	execute_context(context);
-
-	avdtp_unregister_sep(context->lseps, sep);
-	queue_destroy(context->lseps, NULL);
 }
 
 static void test_server_1_3(gconstpointer data)
@@ -530,13 +543,11 @@ static void test_server_1_3(gconstpointer data)
 	sep = avdtp_register_sep(context->lseps, AVDTP_SEP_TYPE_SOURCE,
 					AVDTP_MEDIA_TYPE_AUDIO,
 					0x00, TRUE, &sep_ind, NULL, context);
+	g_assert(sep);
 
 	g_idle_add(send_pdu, context);
 
 	execute_context(context);
-
-	avdtp_unregister_sep(context->lseps, sep);
-	queue_destroy(context->lseps, NULL);
 }
 
 static void test_server_1_3_sink(gconstpointer data)
@@ -547,13 +558,11 @@ static void test_server_1_3_sink(gconstpointer data)
 	sep = avdtp_register_sep(context->lseps, AVDTP_SEP_TYPE_SINK,
 					AVDTP_MEDIA_TYPE_AUDIO,
 					0x00, TRUE, &sep_ind, NULL, context);
+	g_assert(sep);
 
 	g_idle_add(send_pdu, context);
 
 	execute_context(context);
-
-	avdtp_unregister_sep(context->lseps, sep);
-	queue_destroy(context->lseps, NULL);
 }
 
 static void test_server_0_sep(gconstpointer data)
@@ -565,14 +574,6 @@ static void test_server_0_sep(gconstpointer data)
 	execute_context(context);
 }
 
-static void unregister_sep(void *data)
-{
-	struct avdtp_local_sep *sep = data;
-
-	/* Removed from the queue by caller */
-	avdtp_unregister_sep(NULL, sep);
-}
-
 static void test_server_seid(gconstpointer data)
 {
 	struct context *context = create_context(0x0103, data);
@@ -594,8 +595,7 @@ static void test_server_seid(gconstpointer data)
 						context);
 	g_assert(!sep);
 
-	/* Remove all SEPs */
-	queue_destroy(context->lseps, unregister_sep);
+	destroy_context(context);
 }
 
 static void test_server_seid_duplicate(gconstpointer data)
@@ -630,9 +630,6 @@ static void test_server_seid_duplicate(gconstpointer data)
 	g_idle_add(send_pdu, context);
 
 	execute_context(context);
-
-	/* Remove all SEPs */
-	queue_destroy(context->lseps, unregister_sep);
 }
 
 static gboolean sep_getcap_ind_frg(struct avdtp *session,
@@ -684,13 +681,11 @@ static void test_server_frg(gconstpointer data)
 						AVDTP_MEDIA_TYPE_AUDIO,
 						0x00, TRUE, &sep_ind_frg,
 						NULL, context);
+	g_assert(sep);
 
 	g_idle_add(send_pdu, context);
 
 	execute_context(context);
-
-	avdtp_unregister_sep(context->lseps, sep);
-	queue_destroy(context->lseps, NULL);
 }
 
 static void discover_cb(struct avdtp *session, GSList *seps,
@@ -774,9 +769,6 @@ static void test_client(gconstpointer data)
 	avdtp_discover(context->session, discover_cb, context);
 
 	execute_context(context);
-
-	avdtp_unregister_sep(context->lseps, sep);
-	queue_destroy(context->lseps, NULL);
 }
 
 static void test_client_1_3(gconstpointer data)
@@ -793,9 +785,6 @@ static void test_client_1_3(gconstpointer data)
 	avdtp_discover(context->session, discover_cb, context);
 
 	execute_context(context);
-
-	avdtp_unregister_sep(context->lseps, sep);
-	queue_destroy(context->lseps, NULL);
 }
 
 static void test_client_frg(gconstpointer data)
@@ -812,9 +801,6 @@ static void test_client_frg(gconstpointer data)
 	avdtp_discover(context->session, discover_cb, context);
 
 	execute_context(context);
-
-	avdtp_unregister_sep(context->lseps, sep);
-	queue_destroy(context->lseps, NULL);
 }
 
 int main(int argc, char *argv[])
-- 
2.1.0


  parent reply	other threads:[~2015-02-20 12:43 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-02-20 12:43 [RFCv3 0/9] Refactoring profiles/audio code Andrei Emeltchenko
2015-02-20 12:43 ` [RFCv3 1/9] android/avdtp: Refactor local SEP list handling Andrei Emeltchenko
2015-02-20 12:43 ` Andrei Emeltchenko [this message]
2015-02-20 12:43 ` [RFCv3 3/9] android/avdtp: Remove extra check Andrei Emeltchenko
2015-02-20 12:43 ` [RFCv3 4/9] audio/avdtp: Use bitfield id generation Andrei Emeltchenko
2015-02-20 12:43 ` [RFCv3 5/9] audio/avdtp: Refactor avdtp and a2dp code Andrei Emeltchenko
2015-02-20 12:43 ` [RFCv3 6/9] audio/avdtp: Replace GSList with queue for SEP list Andrei Emeltchenko
2015-02-20 12:43 ` [RFCv3 7/9] audi: Refactor avdtp_get function Andrei Emeltchenko
2015-02-20 12:43 ` [RFCv3 8/9] audio/avdtp: Move avdtp_server from avdtp SEP structures Andrei Emeltchenko
2015-02-20 12:43 ` [RFCv3 9/9] audio/avdtp: Use SEP queue instead of avdtp_server in avdtp code Andrei Emeltchenko
2015-02-22 20:51 ` [RFCv3 0/9] Refactoring profiles/audio code Szymon Janc

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1424436203-28935-3-git-send-email-Andrei.Emeltchenko.news@gmail.com \
    --to=andrei.emeltchenko.news@gmail.com \
    --cc=linux-bluetooth@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox