Commit b59107e6 authored by Evan Hunt's avatar Evan Hunt
Browse files

convert queue_test

(cherry picked from commit b3db0266)
parent 3b956580
......@@ -17,7 +17,7 @@ atf_test_program{name='netaddr_test'}
tap_test_program{name='parse_test'}
atf_test_program{name='pool_test'}
atf_test_program{name='print_test'}
atf_test_program{name='queue_test'}
tap_test_program{name='queue_test'}
tap_test_program{name='radix_test'}
atf_test_program{name='random_test'}
atf_test_program{name='regex_test'}
......
......@@ -125,8 +125,9 @@ print_test@EXEEXT@: print_test.@O@ ${ISCDEPLIBS}
print_test.@O@ ${ISCLIBS} ${LIBS}
queue_test@EXEEXT@: queue_test.@O@ isctest.@O@ ${ISCDEPLIBS}
${LIBTOOL_MODE_LINK} ${PURIFY} ${CC} ${CFLAGS} ${LDFLAGS} -o $@ \
queue_test.@O@ isctest.@O@ ${ISCLIBS} ${LIBS}
${LIBTOOL_MODE_LINK} ${PURIFY} ${CC} ${CFLAGS} ${CMOCKA_CFLAGS} \
${LDFLAGS} -o $@ queue_test.@O@ isctest.@O@ \
${ISCLIBS} ${LIBS} ${CMOCKA_LIBS}
radix_test@EXEEXT@: radix_test.@O@ isctest.@O@ ${ISCDEPLIBS}
${LIBTOOL_MODE_LINK} ${PURIFY} ${CC} ${CFLAGS} ${CMOCKA_CFLAGS} \
......
......@@ -9,19 +9,48 @@
* information regarding copyright ownership.
*/
/*! \file */
#include <config.h>
#include <atf-c.h>
#if HAVE_CMOCKA
#include <stdarg.h>
#include <stddef.h>
#include <setjmp.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <time.h>
#define UNIT_TESTING
#include <cmocka.h>
#include <isc/queue.h>
#include <isc/util.h>
#include "isctest.h"
static int
_setup(void **state) {
isc_result_t result;
UNUSED(state);
result = isc_test_begin(NULL, true, 0);
assert_int_equal(result, ISC_R_SUCCESS);
return (0);
}
static int
_teardown(void **state) {
UNUSED(state);
isc_test_end();
return (0);
}
typedef struct item item_t;
struct item {
int value;
......@@ -36,22 +65,14 @@ item_init(item_t *item, int value) {
ISC_QLINK_INIT(item, qlink);
}
/*
* Individual unit tests
*/
/* Test UDP sendto/recv (IPv4) */
ATF_TC(queue_valid);
ATF_TC_HEAD(queue_valid, tc) {
atf_tc_set_md_var(tc, "descr", "Check queue validity");
}
ATF_TC_BODY(queue_valid, tc) {
isc_result_t result;
static void
queue_valid(void **state) {
item_queue_t queue;
item_t one, two, three, four, five;
item_t *p;
UNUSED(tc);
UNUSED(state);
ISC_QUEUE_INIT(queue, qlink);
......@@ -61,77 +82,85 @@ ATF_TC_BODY(queue_valid, tc) {
item_init(&four, 4);
item_init(&five, 5);
result = isc_test_begin(NULL, true, 0);
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
ATF_CHECK(ISC_QUEUE_EMPTY(queue));
assert_true(ISC_QUEUE_EMPTY(queue));
ISC_QUEUE_POP(queue, qlink, p);
ATF_CHECK(p == NULL);
assert_null(p);
ATF_CHECK(! ISC_QLINK_LINKED(&one, qlink));
assert_false(ISC_QLINK_LINKED(&one, qlink));
ISC_QUEUE_PUSH(queue, &one, qlink);
ATF_CHECK(ISC_QLINK_LINKED(&one, qlink));
assert_true(ISC_QLINK_LINKED(&one, qlink));
ATF_CHECK(! ISC_QUEUE_EMPTY(queue));
assert_false(ISC_QUEUE_EMPTY(queue));
ISC_QUEUE_POP(queue, qlink, p);
ATF_REQUIRE(p != NULL);
ATF_CHECK_EQ(p->value, 1);
ATF_CHECK(ISC_QUEUE_EMPTY(queue));
ATF_CHECK(! ISC_QLINK_LINKED(p, qlink));
assert_non_null(p);
assert_int_equal(p->value, 1);
assert_true(ISC_QUEUE_EMPTY(queue));
assert_false(ISC_QLINK_LINKED(p, qlink));
ISC_QUEUE_PUSH(queue, p, qlink);
ATF_CHECK(! ISC_QUEUE_EMPTY(queue));
ATF_CHECK(ISC_QLINK_LINKED(p, qlink));
assert_false(ISC_QUEUE_EMPTY(queue));
assert_true(ISC_QLINK_LINKED(p, qlink));
ATF_CHECK(! ISC_QLINK_LINKED(&two, qlink));
assert_false(ISC_QLINK_LINKED(&two, qlink));
ISC_QUEUE_PUSH(queue, &two, qlink);
ATF_CHECK(ISC_QLINK_LINKED(&two, qlink));
assert_true(ISC_QLINK_LINKED(&two, qlink));
ATF_CHECK(! ISC_QLINK_LINKED(&three, qlink));
assert_false(ISC_QLINK_LINKED(&three, qlink));
ISC_QUEUE_PUSH(queue, &three, qlink);
ATF_CHECK(ISC_QLINK_LINKED(&three, qlink));
assert_true(ISC_QLINK_LINKED(&three, qlink));
ATF_CHECK(! ISC_QLINK_LINKED(&four, qlink));
assert_false(ISC_QLINK_LINKED(&four, qlink));
ISC_QUEUE_PUSH(queue, &four, qlink);
ATF_CHECK(ISC_QLINK_LINKED(&four, qlink));
assert_true(ISC_QLINK_LINKED(&four, qlink));
ATF_CHECK(! ISC_QLINK_LINKED(&five, qlink));
assert_false(ISC_QLINK_LINKED(&five, qlink));
ISC_QUEUE_PUSH(queue, &five, qlink);
ATF_CHECK(ISC_QLINK_LINKED(&five, qlink));
assert_true(ISC_QLINK_LINKED(&five, qlink));
/* Test unlink by removing one item from the middle */
ISC_QUEUE_UNLINK(queue, &three, qlink);
ISC_QUEUE_POP(queue, qlink, p);
ATF_REQUIRE(p != NULL);
ATF_CHECK_EQ(p->value, 1);
assert_non_null(p);
assert_int_equal(p->value, 1);
ISC_QUEUE_POP(queue, qlink, p);
ATF_REQUIRE(p != NULL);
ATF_CHECK_EQ(p->value, 2);
assert_non_null(p);
assert_int_equal(p->value, 2);
ISC_QUEUE_POP(queue, qlink, p);
ATF_REQUIRE(p != NULL);
ATF_CHECK_EQ(p->value, 4);
assert_non_null(p);
assert_int_equal(p->value, 4);
ISC_QUEUE_POP(queue, qlink, p);
ATF_REQUIRE(p != NULL);
ATF_CHECK_EQ(p->value, 5);
assert_non_null(p);
assert_int_equal(p->value, 5);
ATF_CHECK(ISC_QUEUE_EMPTY(queue));
assert_true(ISC_QUEUE_EMPTY(queue));
ISC_QUEUE_DESTROY(queue);
isc_test_end();
}
/*
* Main
*/
ATF_TP_ADD_TCS(tp) {
ATF_TP_ADD_TC(tp, queue_valid);
int
main(void) {
const struct CMUnitTest tests[] = {
cmocka_unit_test_setup_teardown(queue_valid,
_setup, _teardown),
};
return (cmocka_run_group_tests(tests, NULL, NULL));
}
#else /* HAVE_CMOCKA */
#include <stdio.h>
return (atf_no_error());
int
main(void) {
printf("1..0 # Skipped: cmocka not available\n");
return (0);
}
#endif
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment