1 /*
2 * Wslay - The WebSocket Library
3 *
4 * Copyright (c) 2011, 2012 Tatsuhiro Tsujikawa
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining
7 * a copy of this software and associated documentation files (the
8 * "Software"), to deal in the Software without restriction, including
9 * without limitation the rights to use, copy, modify, merge, publish,
10 * distribute, sublicense, and/or sell copies of the Software, and to
11 * permit persons to whom the Software is furnished to do so, subject to
12 * the following conditions:
13 *
14 * The above copyright notice and this permission notice shall be
15 * included in all copies or substantial portions of the Software.
16 *
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
18 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
20 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
21 * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
22 * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
23 * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24 */
25 #include "wslay_queue_test.h"
26
27 #include <CUnit/CUnit.h>
28
29 #include "wslay_queue.h"
30 #include "wslay_macro.h"
31
32 struct queue_entry {
33 struct wslay_queue_entry qe;
34 int value;
35 };
36
test_wslay_queue(void)37 void test_wslay_queue(void) {
38 struct queue_entry ents[] = {
39 {{0}, 1}, {{0}, 2}, {{0}, 3}, {{0}, 4}, {{0}, 5},
40 };
41 int i;
42 struct wslay_queue queue;
43 wslay_queue_init(&queue);
44 CU_ASSERT(wslay_queue_empty(&queue));
45 for (i = 0; i < 5; ++i) {
46 wslay_queue_push(&queue, &ents[i].qe);
47 CU_ASSERT_EQUAL(ents[0].value, wslay_struct_of(wslay_queue_top(&queue),
48 struct queue_entry, qe)
49 ->value);
50 CU_ASSERT(!wslay_queue_empty(&queue));
51 }
52 for (i = 0; i < 5; ++i) {
53 CU_ASSERT_EQUAL(ents[i].value, wslay_struct_of(wslay_queue_top(&queue),
54 struct queue_entry, qe)
55 ->value);
56 wslay_queue_pop(&queue);
57 }
58 CU_ASSERT(wslay_queue_empty(&queue));
59
60 for (i = 0; i < 5; ++i) {
61 wslay_queue_push_front(&queue, &ents[i].qe);
62 CU_ASSERT_EQUAL(ents[i].value, wslay_struct_of(wslay_queue_top(&queue),
63 struct queue_entry, qe)
64 ->value);
65 CU_ASSERT(!wslay_queue_empty(&queue));
66 }
67 for (i = 4; i >= 0; --i) {
68 CU_ASSERT_EQUAL(ents[i].value, wslay_struct_of(wslay_queue_top(&queue),
69 struct queue_entry, qe)
70 ->value);
71 wslay_queue_pop(&queue);
72 }
73 CU_ASSERT(wslay_queue_empty(&queue));
74 wslay_queue_deinit(&queue);
75 }
76