Marcel Holtmann | 611f14d | 2014-01-25 11:30:52 -0800 | [diff] [blame^] | 1 | /* |
| 2 | * |
| 3 | * BlueZ - Bluetooth protocol stack for Linux |
| 4 | * |
| 5 | * Copyright (C) 2012 Intel Corporation. All rights reserved. |
| 6 | * |
| 7 | * |
| 8 | * This program is free software; you can redistribute it and/or modify |
| 9 | * it under the terms of the GNU General Public License as published by |
| 10 | * the Free Software Foundation; either version 2 of the License, or |
| 11 | * (at your option) any later version. |
| 12 | * |
| 13 | * This program is distributed in the hope that it will be useful, |
| 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 16 | * GNU General Public License for more details. |
| 17 | * |
| 18 | * You should have received a copy of the GNU General Public License |
| 19 | * along with this program; if not, write to the Free Software |
| 20 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
| 21 | * |
| 22 | */ |
| 23 | |
| 24 | #ifdef HAVE_CONFIG_H |
| 25 | #include <config.h> |
| 26 | #endif |
| 27 | |
| 28 | #include <glib.h> |
| 29 | |
| 30 | #include "src/shared/util.h" |
| 31 | #include "src/shared/queue.h" |
| 32 | |
| 33 | static void test_basic(void) |
| 34 | { |
| 35 | struct queue *queue; |
| 36 | unsigned int n, i; |
| 37 | |
| 38 | queue = queue_new(); |
| 39 | g_assert(queue != NULL); |
| 40 | |
| 41 | for (n = 0; n < 1024; n++) { |
| 42 | for (i = 1; i < n + 2; i++) |
| 43 | queue_push_tail(queue, UINT_TO_PTR(i)); |
| 44 | |
| 45 | g_assert(queue_length(queue) == n + 1); |
| 46 | |
| 47 | for (i = 1; i < n + 2; i++) { |
| 48 | void *ptr; |
| 49 | |
| 50 | ptr = queue_pop_head(queue); |
| 51 | g_assert(ptr != NULL); |
| 52 | g_assert(i == PTR_TO_UINT(ptr)); |
| 53 | } |
| 54 | |
| 55 | g_assert(queue_isempty(queue) == true); |
| 56 | } |
| 57 | |
| 58 | queue_destroy(queue, NULL); |
| 59 | } |
| 60 | |
| 61 | int main(int argc, char *argv[]) |
| 62 | { |
| 63 | g_test_init(&argc, &argv, NULL); |
| 64 | |
| 65 | g_test_add_func("/queue/basic", test_basic); |
| 66 | |
| 67 | return g_test_run(); |
| 68 | } |