From 611f14dec82b58b371d13dbc361eb911467cf597 Mon Sep 17 00:00:00 2001 From: Marcel Holtmann Date: Sat, 25 Jan 2014 11:30:52 -0800 Subject: [PATCH] unit: Add basic unit test for queue handling --- .gitignore | 1 + Makefile.am | 7 ++++- doc/test-coverage.txt | 3 +- unit/test-queue.c | 68 +++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 77 insertions(+), 2 deletions(-) create mode 100644 unit/test-queue.c diff --git a/.gitignore b/.gitignore index 395e19f0e..03216679e 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 f84706278..d215c0c21 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 5cc05adc8..8d25294a9 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 000000000..7c6d2ada3 --- /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 +#endif + +#include + +#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(); +} -- 2.47.3