1 /* $NetBSD: queue_test.c,v 1.1.1.4 2014/12/10 03:34:44 christos Exp $ */
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.
30 #include <isc/queue.h>
34 typedef struct item item_t
;
37 ISC_QLINK(item_t
) qlink
;
40 typedef ISC_QUEUE(item_t
) item_queue_t
;
43 item_init(item_t
*item
, int value
) {
45 ISC_QLINK_INIT(item
, qlink
);
49 * Individual unit tests
52 /* Test UDP sendto/recv (IPv4) */
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
) {
60 item_t one
, two
, three
, four
, five
;
65 ISC_QUEUE_INIT(queue
, qlink
);
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
);
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
);
142 ATF_TP_ADD_TC(tp
, queue_valid
);
144 return (atf_no_error());