2016-08-17 11:22:09 -07:00
|
|
|
/*
|
2018-02-23 09:53:12 +01:00
|
|
|
* Copyright (C) Internet Systems Consortium, Inc. ("ISC")
|
2016-08-17 11:22:09 -07:00
|
|
|
*
|
|
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
2018-02-23 09:53:12 +01:00
|
|
|
*
|
|
|
|
* See the COPYRIGHT file distributed with this work for additional
|
|
|
|
* information regarding copyright ownership.
|
2016-08-17 11:22:09 -07:00
|
|
|
*/
|
|
|
|
|
2018-10-23 22:29:39 -07:00
|
|
|
#if HAVE_CMOCKA
|
|
|
|
|
2020-02-12 13:59:18 +01:00
|
|
|
#include <errno.h>
|
|
|
|
#include <setjmp.h>
|
2018-10-23 22:29:39 -07:00
|
|
|
#include <stdarg.h>
|
|
|
|
#include <stddef.h>
|
2019-07-30 21:08:40 +02:00
|
|
|
#include <stdlib.h>
|
2018-10-23 22:29:39 -07:00
|
|
|
#include <string.h>
|
2019-07-30 21:08:40 +02:00
|
|
|
|
2018-10-23 22:29:39 -07:00
|
|
|
#define UNIT_TESTING
|
|
|
|
#include <cmocka.h>
|
2016-08-17 11:22:09 -07:00
|
|
|
|
|
|
|
#include <isc/errno.h>
|
|
|
|
#include <isc/result.h>
|
2018-10-23 22:29:39 -07:00
|
|
|
#include <isc/util.h>
|
2016-08-17 11:22:09 -07:00
|
|
|
|
|
|
|
typedef struct {
|
2020-02-13 14:44:37 -08:00
|
|
|
int err;
|
2016-08-17 11:22:09 -07:00
|
|
|
isc_result_t result;
|
|
|
|
} testpair_t;
|
|
|
|
|
2020-02-12 13:59:18 +01:00
|
|
|
testpair_t testpair[] = { { EPERM, ISC_R_NOPERM },
|
|
|
|
{ ENOENT, ISC_R_FILENOTFOUND },
|
|
|
|
{ EIO, ISC_R_IOERROR },
|
|
|
|
{ EBADF, ISC_R_INVALIDFILE },
|
|
|
|
{ ENOMEM, ISC_R_NOMEMORY },
|
|
|
|
{ EACCES, ISC_R_NOPERM },
|
|
|
|
{ EEXIST, ISC_R_FILEEXISTS },
|
|
|
|
{ ENOTDIR, ISC_R_INVALIDFILE },
|
|
|
|
{ EINVAL, ISC_R_INVALIDFILE },
|
|
|
|
{ ENFILE, ISC_R_TOOMANYOPENFILES },
|
|
|
|
{ EMFILE, ISC_R_TOOMANYOPENFILES },
|
|
|
|
{ EPIPE, ISC_R_CONNECTIONRESET },
|
|
|
|
{ ENAMETOOLONG, ISC_R_INVALIDFILE },
|
|
|
|
{ ELOOP, ISC_R_INVALIDFILE },
|
2016-08-17 11:22:09 -07:00
|
|
|
#ifdef EOVERFLOW
|
2020-02-12 13:59:18 +01:00
|
|
|
{ EOVERFLOW, ISC_R_RANGE },
|
2020-02-13 21:48:23 +01:00
|
|
|
#endif /* ifdef EOVERFLOW */
|
2016-08-17 11:22:09 -07:00
|
|
|
#ifdef EAFNOSUPPORT
|
2020-02-12 13:59:18 +01:00
|
|
|
{ EAFNOSUPPORT, ISC_R_FAMILYNOSUPPORT },
|
2020-02-13 21:48:23 +01:00
|
|
|
#endif /* ifdef EAFNOSUPPORT */
|
2016-08-17 11:22:09 -07:00
|
|
|
#ifdef EADDRINUSE
|
2020-02-12 13:59:18 +01:00
|
|
|
{ EADDRINUSE, ISC_R_ADDRINUSE },
|
2020-02-13 21:48:23 +01:00
|
|
|
#endif /* ifdef EADDRINUSE */
|
2020-02-12 13:59:18 +01:00
|
|
|
{ EADDRNOTAVAIL, ISC_R_ADDRNOTAVAIL },
|
2016-08-17 11:22:09 -07:00
|
|
|
#ifdef ENETDOWN
|
2020-02-12 13:59:18 +01:00
|
|
|
{ ENETDOWN, ISC_R_NETDOWN },
|
2020-02-13 21:48:23 +01:00
|
|
|
#endif /* ifdef ENETDOWN */
|
2016-08-17 11:22:09 -07:00
|
|
|
#ifdef ENETUNREACH
|
2020-02-12 13:59:18 +01:00
|
|
|
{ ENETUNREACH, ISC_R_NETUNREACH },
|
2020-02-13 21:48:23 +01:00
|
|
|
#endif /* ifdef ENETUNREACH */
|
2016-08-17 11:22:09 -07:00
|
|
|
#ifdef ECONNABORTED
|
2020-02-12 13:59:18 +01:00
|
|
|
{ ECONNABORTED, ISC_R_CONNECTIONRESET },
|
2020-02-13 21:48:23 +01:00
|
|
|
#endif /* ifdef ECONNABORTED */
|
2016-08-17 11:22:09 -07:00
|
|
|
#ifdef ECONNRESET
|
2020-02-12 13:59:18 +01:00
|
|
|
{ ECONNRESET, ISC_R_CONNECTIONRESET },
|
2020-02-13 21:48:23 +01:00
|
|
|
#endif /* ifdef ECONNRESET */
|
2016-08-17 11:22:09 -07:00
|
|
|
#ifdef ENOBUFS
|
2020-02-12 13:59:18 +01:00
|
|
|
{ ENOBUFS, ISC_R_NORESOURCES },
|
2020-02-13 21:48:23 +01:00
|
|
|
#endif /* ifdef ENOBUFS */
|
2016-08-17 11:22:09 -07:00
|
|
|
#ifdef ENOTCONN
|
2020-02-12 13:59:18 +01:00
|
|
|
{ ENOTCONN, ISC_R_NOTCONNECTED },
|
2020-02-13 21:48:23 +01:00
|
|
|
#endif /* ifdef ENOTCONN */
|
2016-08-17 11:22:09 -07:00
|
|
|
#ifdef ETIMEDOUT
|
2020-02-12 13:59:18 +01:00
|
|
|
{ ETIMEDOUT, ISC_R_TIMEDOUT },
|
2020-02-13 21:48:23 +01:00
|
|
|
#endif /* ifdef ETIMEDOUT */
|
2020-02-12 13:59:18 +01:00
|
|
|
{ ECONNREFUSED, ISC_R_CONNREFUSED },
|
2016-08-17 11:22:09 -07:00
|
|
|
#ifdef EHOSTDOWN
|
2020-02-12 13:59:18 +01:00
|
|
|
{ EHOSTDOWN, ISC_R_HOSTDOWN },
|
2020-02-13 21:48:23 +01:00
|
|
|
#endif /* ifdef EHOSTDOWN */
|
2016-08-17 11:22:09 -07:00
|
|
|
#ifdef EHOSTUNREACH
|
2020-02-12 13:59:18 +01:00
|
|
|
{ EHOSTUNREACH, ISC_R_HOSTUNREACH },
|
2020-02-13 21:48:23 +01:00
|
|
|
#endif /* ifdef EHOSTUNREACH */
|
2020-02-12 13:59:18 +01:00
|
|
|
{ 0, ISC_R_UNEXPECTED } };
|
2016-08-17 11:22:09 -07:00
|
|
|
|
2018-10-23 22:29:39 -07:00
|
|
|
/* convert errno to ISC result */
|
|
|
|
static void
|
2020-02-13 14:44:37 -08:00
|
|
|
isc_errno_toresult_test(void **state) {
|
2016-08-17 11:22:09 -07:00
|
|
|
isc_result_t result, expect;
|
2020-02-13 14:44:37 -08:00
|
|
|
size_t i;
|
2016-08-17 11:22:09 -07:00
|
|
|
|
2018-10-23 22:29:39 -07:00
|
|
|
UNUSED(state);
|
|
|
|
|
2020-02-12 13:59:18 +01:00
|
|
|
for (i = 0; i < sizeof(testpair) / sizeof(testpair[0]); i++) {
|
2016-08-17 11:22:09 -07:00
|
|
|
result = isc_errno_toresult(testpair[i].err);
|
|
|
|
expect = testpair[i].result;
|
2018-10-23 22:29:39 -07:00
|
|
|
assert_int_equal(result, expect);
|
2016-08-17 11:22:09 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-10-23 22:29:39 -07:00
|
|
|
int
|
2020-02-13 14:44:37 -08:00
|
|
|
main(void) {
|
2018-10-23 22:29:39 -07:00
|
|
|
const struct CMUnitTest tests[] = {
|
|
|
|
cmocka_unit_test(isc_errno_toresult_test),
|
|
|
|
};
|
|
|
|
|
|
|
|
return (cmocka_run_group_tests(tests, NULL, NULL));
|
2016-08-17 11:22:09 -07:00
|
|
|
}
|
|
|
|
|
2018-10-23 22:29:39 -07:00
|
|
|
#else /* HAVE_CMOCKA */
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
|
|
|
|
int
|
2020-02-13 14:44:37 -08:00
|
|
|
main(void) {
|
2018-10-23 22:29:39 -07:00
|
|
|
printf("1..0 # Skipped: cmocka not available\n");
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
2020-02-13 21:48:23 +01:00
|
|
|
#endif /* if HAVE_CMOCKA */
|