Diff between 27afdad8c7a81e41ce2626d16405f3df6c2bf168 and 611f14dec82b58b371d13dbc361eb911467cf597

Changed Files

File Additions Deletions Status
.gitignore +1 -0 modified
Makefile.am +6 -1 modified
doc/test-coverage.txt +2 -1 modified
unit/test-queue.c +68 -0 added

Full Patch

diff --git a/.gitignore b/.gitignore
index 395e19f..0321667 100644
--- a/.gitignore
+++ b/.gitignore
@@ -74,6 +74,7 @@ tools/obexctl
 test/sap_client.pyc
 test/bluezutils.pyc
 unit/test-ringbuf
+unit/test-queue
 unit/test-eir
 unit/test-uuid
 unit/test-crc
diff --git a/Makefile.am b/Makefile.am
index f847062..d215c0c 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -237,13 +237,18 @@ unit_test_textfile_LDADD = @GLIB_LIBS@
 unit_test_crc_SOURCES = unit/test-crc.c monitor/crc.h monitor/crc.c
 unit_test_crc_LDADD = @GLIB_LIBS@
 
-unit_tests += unit/test-ringbuf
+unit_tests += unit/test-ringbuf unit/test-queue
 
 unit_test_ringbuf_SOURCES = unit/test-ringbuf.c \
 				src/shared/util.h src/shared/util.c \
 				src/shared/ringbuf.h src/shared/ringbuf.c
 unit_test_ringbuf_LDADD = @GLIB_LIBS@
 
+unit_test_queue_SOURCES = unit/test-queue.c \
+				src/shared/util.h src/shared/util.c \
+				src/shared/queue.h src/shared/queue.c
+unit_test_queue_LDADD = @GLIB_LIBS@
+
 unit_tests += unit/test-mgmt
 
 unit_test_mgmt_SOURCES = unit/test-mgmt.c \
diff --git a/doc/test-coverage.txt b/doc/test-coverage.txt
index 5cc05ad..8d25294 100644
--- a/doc/test-coverage.txt
+++ b/doc/test-coverage.txt
@@ -15,6 +15,7 @@ test-uuid		  30	UUID conversion handling
 test-mgmt		   2	Management interface handling
 test-textfile		   4	Old textfile storage format
 test-ringbuf		   3    Ring buffer functionality
+test-queue		   1	Queue handling functionality
 test-avdtp		  60	AVDTP qualification test cases
 test-gobex		  31	Generic OBEX functionality
 test-gobex-packet	   9	OBEX packet handling
@@ -23,7 +24,7 @@ test-gobex-apparam	  18	OBEX apparam handling
 test-gobex-transfer	  36	OBEX transfer handling
 test-gdbus-client	  12	D-Bus client handling
 			-----
-			 403
+			 404
 
 
 Automated end-to-end testing
diff --git a/unit/test-queue.c b/unit/test-queue.c
new file mode 100644
index 0000000..7c6d2ad
--- /dev/null
+++ b/unit/test-queue.c
@@ -0,0 +1,68 @@
+/*
+ *
+ *  BlueZ - Bluetooth protocol stack for Linux
+ *
+ *  Copyright (C) 2012  Intel Corporation. All rights reserved.
+ *
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, write to the Free Software
+ *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+ *
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <glib.h>
+
+#include "src/shared/util.h"
+#include "src/shared/queue.h"
+
+static void test_basic(void)
+{
+	struct queue *queue;
+	unsigned int n, i;
+
+	queue = queue_new();
+	g_assert(queue != NULL);
+
+	for (n = 0; n < 1024; n++) {
+		for (i = 1; i < n + 2; i++)
+			queue_push_tail(queue, UINT_TO_PTR(i));
+
+		g_assert(queue_length(queue) == n + 1);
+
+		for (i = 1; i < n + 2; i++) {
+			void *ptr;
+
+			ptr = queue_pop_head(queue);
+			g_assert(ptr != NULL);
+			g_assert(i == PTR_TO_UINT(ptr));
+		}
+
+		g_assert(queue_isempty(queue) == true);
+	}
+
+	queue_destroy(queue, NULL);
+}
+
+int main(int argc, char *argv[])
+{
+	g_test_init(&argc, &argv, NULL);
+
+	g_test_add_func("/queue/basic", test_basic);
+
+	return g_test_run();
+}