unit: Add basic unit test for queue handling

This commit is contained in:
Marcel Holtmann 2014-01-25 11:30:52 -08:00
parent 27afdad8c7
commit 611f14dec8
4 changed files with 77 additions and 2 deletions

1
.gitignore vendored
View File

@ -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

View File

@ -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 \

View File

@ -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

68
unit/test-queue.c Normal file
View File

@ -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();
}