Remove building with NOCRYPTO option
[minix.git] / external / bsd / bind / dist / lib / isc / tests / queue_test.c
blobe74a9340ed1d2cdc2b9bfcf797cc77373af3630c
1 /* $NetBSD: queue_test.c,v 1.1.1.4 2014/12/10 03:34:44 christos Exp $ */
3 /*
4 * Copyright (C) 2011, 2012 Internet Systems Consortium, Inc. ("ISC")
6 * Permission to use, copy, modify, and/or distribute this software for any
7 * purpose with or without fee is hereby granted, provided that the above
8 * copyright notice and this permission notice appear in all copies.
10 * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
11 * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
12 * AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
13 * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
14 * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
15 * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
16 * PERFORMANCE OF THIS SOFTWARE.
19 /* Id */
21 /*! \file */
23 #include <config.h>
25 #include <atf-c.h>
27 #include <unistd.h>
28 #include <time.h>
30 #include <isc/queue.h>
32 #include "isctest.h"
34 typedef struct item item_t;
35 struct item {
36 int value;
37 ISC_QLINK(item_t) qlink;
40 typedef ISC_QUEUE(item_t) item_queue_t;
42 static void
43 item_init(item_t *item, int value) {
44 item->value = value;
45 ISC_QLINK_INIT(item, qlink);
49 * Individual unit tests
52 /* Test UDP sendto/recv (IPv4) */
53 ATF_TC(queue_valid);
54 ATF_TC_HEAD(queue_valid, tc) {
55 atf_tc_set_md_var(tc, "descr", "Check queue validity");
57 ATF_TC_BODY(queue_valid, tc) {
58 isc_result_t result;
59 item_queue_t queue;
60 item_t one, two, three, four, five;
61 item_t *p;
63 UNUSED(tc);
65 ISC_QUEUE_INIT(queue, qlink);
67 item_init(&one, 1);
68 item_init(&two, 2);
69 item_init(&three, 3);
70 item_init(&four, 4);
71 item_init(&five, 5);
73 result = isc_test_begin(NULL, ISC_TRUE);
74 ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
76 ATF_CHECK(ISC_QUEUE_EMPTY(queue));
78 ISC_QUEUE_POP(queue, qlink, p);
79 ATF_CHECK(p == NULL);
81 ATF_CHECK(! ISC_QLINK_LINKED(&one, qlink));
82 ISC_QUEUE_PUSH(queue, &one, qlink);
83 ATF_CHECK(ISC_QLINK_LINKED(&one, qlink));
85 ATF_CHECK(! ISC_QUEUE_EMPTY(queue));
87 ISC_QUEUE_POP(queue, qlink, p);
88 ATF_REQUIRE(p != NULL);
89 ATF_CHECK_EQ(p->value, 1);
90 ATF_CHECK(ISC_QUEUE_EMPTY(queue));
91 ATF_CHECK(! ISC_QLINK_LINKED(p, qlink));
93 ISC_QUEUE_PUSH(queue, p, qlink);
94 ATF_CHECK(! ISC_QUEUE_EMPTY(queue));
95 ATF_CHECK(ISC_QLINK_LINKED(p, qlink));
97 ATF_CHECK(! ISC_QLINK_LINKED(&two, qlink));
98 ISC_QUEUE_PUSH(queue, &two, qlink);
99 ATF_CHECK(ISC_QLINK_LINKED(&two, qlink));
101 ATF_CHECK(! ISC_QLINK_LINKED(&three, qlink));
102 ISC_QUEUE_PUSH(queue, &three, qlink);
103 ATF_CHECK(ISC_QLINK_LINKED(&three, qlink));
105 ATF_CHECK(! ISC_QLINK_LINKED(&four, qlink));
106 ISC_QUEUE_PUSH(queue, &four, qlink);
107 ATF_CHECK(ISC_QLINK_LINKED(&four, qlink));
109 ATF_CHECK(! ISC_QLINK_LINKED(&five, qlink));
110 ISC_QUEUE_PUSH(queue, &five, qlink);
111 ATF_CHECK(ISC_QLINK_LINKED(&five, qlink));
113 /* Test unlink by removing one item from the middle */
114 ISC_QUEUE_UNLINK(queue, &three, qlink);
116 ISC_QUEUE_POP(queue, qlink, p);
117 ATF_REQUIRE(p != NULL);
118 ATF_CHECK_EQ(p->value, 1);
120 ISC_QUEUE_POP(queue, qlink, p);
121 ATF_REQUIRE(p != NULL);
122 ATF_CHECK_EQ(p->value, 2);
124 ISC_QUEUE_POP(queue, qlink, p);
125 ATF_REQUIRE(p != NULL);
126 ATF_CHECK_EQ(p->value, 4);
128 ISC_QUEUE_POP(queue, qlink, p);
129 ATF_REQUIRE(p != NULL);
130 ATF_CHECK_EQ(p->value, 5);
132 ATF_CHECK(ISC_QUEUE_EMPTY(queue));
134 ISC_QUEUE_DESTROY(queue);
135 isc_test_end();
139 * Main
141 ATF_TP_ADD_TCS(tp) {
142 ATF_TP_ADD_TC(tp, queue_valid);
144 return (atf_no_error());