From: Arman Uguray <armansito@chromium.org>
To: linux-bluetooth@vger.kernel.org
Cc: Arman Uguray <armansito@chromium.org>
Subject: [PATCH BlueZ 3/5] unit/test-queue: Add /queue/insert_after test
Date: Tue, 25 Nov 2014 21:26:47 -0800 [thread overview]
Message-ID: <1416979609-3056-4-git-send-email-armansito@chromium.org> (raw)
In-Reply-To: <1416979609-3056-1-git-send-email-armansito@chromium.org>
This tests the queue_insert_after function.
---
unit/test-queue.c | 41 +++++++++++++++++++++++++++++++++++++++++
1 file changed, 41 insertions(+)
diff --git a/unit/test-queue.c b/unit/test-queue.c
index 9fe15ba..e5f9178 100644
--- a/unit/test-queue.c
+++ b/unit/test-queue.c
@@ -118,6 +118,46 @@ static void test_destroy_remove(void)
queue_destroy(static_queue, destroy_remove);
}
+static void test_insert_after(void)
+{
+ struct queue *queue;
+ unsigned int len, i;
+
+ queue = queue_new();
+ g_assert(queue != NULL);
+
+ /*
+ * Pre-populate queue. Initial elements are:
+ * [ NULL, 2, 5 ]
+ */
+ g_assert(queue_push_tail(queue, NULL));
+ g_assert(queue_push_tail(queue, UINT_TO_PTR(2)));
+ g_assert(queue_push_tail(queue, UINT_TO_PTR(5)));
+ g_assert(queue_length(queue) == 3);
+
+ /* Invalid insertion */
+ g_assert(!queue_insert_after(queue, UINT_TO_PTR(6), UINT_TO_PTR(1)));
+
+ /* Valid insertions */
+ g_assert(queue_insert_after(queue, NULL, UINT_TO_PTR(1)));
+ g_assert(queue_insert_after(queue, UINT_TO_PTR(2), UINT_TO_PTR(3)));
+ g_assert(queue_insert_after(queue, UINT_TO_PTR(3), UINT_TO_PTR(4)));
+ g_assert(queue_insert_after(queue, UINT_TO_PTR(5), UINT_TO_PTR(6)));
+
+ g_assert(queue_peek_head(queue) == NULL);
+ g_assert(queue_peek_tail(queue) == UINT_TO_PTR(6));
+
+ /*
+ * Queue should contain 7 elements:
+ * [ NULL, 1, 2, 3, 4, 5, 6 ]
+ */
+ len = queue_length(queue);
+ g_assert(len == 7);
+
+ for (i = 0; i < 7; i++)
+ g_assert(queue_pop_head(queue) == UINT_TO_PTR(i));
+}
+
int main(int argc, char *argv[])
{
g_test_init(&argc, &argv, NULL);
@@ -126,6 +166,7 @@ int main(int argc, char *argv[])
g_test_add_func("/queue/foreach_destroy", test_foreach_destroy);
g_test_add_func("/queue/foreach_remove_all", test_foreach_remove_all);
g_test_add_func("/queue/destroy_remove", test_destroy_remove);
+ g_test_add_func("/queue/insert_after", test_insert_after);
return g_test_run();
}
--
2.2.0.rc0.207.ga3a616c
next prev parent reply other threads:[~2014-11-26 5:26 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-11-26 5:26 [PATCH BlueZ 0/5] shared/gatt-db: Add support for client role Arman Uguray
2014-11-26 5:26 ` [PATCH BlueZ 1/5] shared/gatt-db: Add high-level functions for client Arman Uguray
2014-11-26 10:37 ` Luiz Augusto von Dentz
2014-11-26 21:48 ` Arman Uguray
2014-11-26 5:26 ` [PATCH BlueZ 2/5] shared: Add function to insert element after entry Arman Uguray
2014-11-26 10:15 ` Luiz Augusto von Dentz
2014-11-26 5:26 ` Arman Uguray [this message]
2014-11-26 5:26 ` [PATCH BlueZ 4/5] shared/gatt-db: Add gatt_db_insert_service function Arman Uguray
2014-11-26 5:26 ` [PATCH BlueZ 5/5] shared/gatt-db: Add clear functions Arman Uguray
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=1416979609-3056-4-git-send-email-armansito@chromium.org \
--to=armansito@chromium.org \
--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;
as well as URLs for NNTP newsgroup(s).