2015-05-05 16:39:09 -07:00
|
|
|
/*
|
2018-02-23 09:53:12 +01:00
|
|
|
* Copyright (C) Internet Systems Consortium, Inc. ("ISC")
|
2015-05-05 16:39:09 -07:00
|
|
|
*
|
2016-06-27 14:56:38 +10: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
|
2020-09-14 16:20:40 -07:00
|
|
|
* file, you can obtain one at https://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.
|
2015-05-05 16:39:09 -07:00
|
|
|
*/
|
|
|
|
|
2018-11-09 17:40:31 -08:00
|
|
|
#if HAVE_CMOCKA
|
2015-05-05 16:39:09 -07:00
|
|
|
|
2020-02-12 13:59:18 +01:00
|
|
|
#include <setjmp.h>
|
2018-11-09 17:40:31 -08:00
|
|
|
#include <stdarg.h>
|
|
|
|
#include <stddef.h>
|
2021-04-21 13:52:15 +02:00
|
|
|
#include <stdio.h>
|
2019-07-30 21:08:40 +02:00
|
|
|
#include <stdlib.h>
|
2015-05-11 12:16:07 +10:00
|
|
|
#include <string.h>
|
|
|
|
|
2018-11-09 17:40:31 -08:00
|
|
|
#define UNIT_TESTING
|
|
|
|
#include <cmocka.h>
|
|
|
|
|
2015-05-05 16:39:09 -07:00
|
|
|
#include <isc/result.h>
|
2018-11-09 17:40:31 -08:00
|
|
|
#include <isc/util.h>
|
|
|
|
|
|
|
|
/* convert result to identifier string */
|
|
|
|
static void
|
2020-02-13 14:44:37 -08:00
|
|
|
isc_result_toid_test(void **state) {
|
2018-11-09 17:40:31 -08:00
|
|
|
const char *id;
|
|
|
|
|
|
|
|
UNUSED(state);
|
|
|
|
|
|
|
|
id = isc_result_toid(ISC_R_SUCCESS);
|
|
|
|
assert_string_equal("ISC_R_SUCCESS", id);
|
|
|
|
|
|
|
|
id = isc_result_toid(ISC_R_FAILURE);
|
|
|
|
assert_string_equal("ISC_R_FAILURE", id);
|
2018-11-10 10:21:44 +11:00
|
|
|
}
|
2018-11-09 17:40:31 -08:00
|
|
|
|
|
|
|
/* convert result to description string */
|
|
|
|
static void
|
2020-02-13 14:44:37 -08:00
|
|
|
isc_result_totext_test(void **state) {
|
2018-11-09 17:40:31 -08:00
|
|
|
const char *str;
|
|
|
|
|
|
|
|
UNUSED(state);
|
|
|
|
|
|
|
|
str = isc_result_totext(ISC_R_SUCCESS);
|
|
|
|
assert_string_equal("success", str);
|
|
|
|
|
|
|
|
str = isc_result_totext(ISC_R_FAILURE);
|
|
|
|
assert_string_equal("failure", str);
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2020-02-13 14:44:37 -08:00
|
|
|
main(void) {
|
2018-11-09 17:40:31 -08:00
|
|
|
const struct CMUnitTest tests[] = {
|
|
|
|
cmocka_unit_test(isc_result_toid_test),
|
|
|
|
cmocka_unit_test(isc_result_totext_test),
|
|
|
|
};
|
2015-05-05 16:39:09 -07:00
|
|
|
|
2018-11-09 17:40:31 -08:00
|
|
|
return (cmocka_run_group_tests(tests, NULL, NULL));
|
2015-05-05 16:39:09 -07:00
|
|
|
}
|
|
|
|
|
2018-11-09 17:40:31 -08:00
|
|
|
#else /* HAVE_CMOCKA */
|
2015-05-05 16:39:09 -07:00
|
|
|
|
2018-11-09 17:40:31 -08:00
|
|
|
#include <stdio.h>
|
2015-05-05 16:39:09 -07:00
|
|
|
|
2018-11-09 17:40:31 -08:00
|
|
|
int
|
2020-02-13 14:44:37 -08:00
|
|
|
main(void) {
|
2018-11-09 17:40:31 -08:00
|
|
|
printf("1..0 # Skipped: cmocka not available\n");
|
2021-01-18 19:15:44 +01:00
|
|
|
return (SKIPPED_TEST_EXIT_CODE);
|
2015-05-05 16:39:09 -07:00
|
|
|
}
|
|
|
|
|
2020-02-13 21:48:23 +01:00
|
|
|
#endif /* if HAVE_CMOCKA */
|