Files
bind9/lib/isc/tests/time_test.c
Evan Hunt 69b892edc7 convert time_test
(cherry picked from commit 3bf9a1e567)
(cherry picked from commit 8d0396737c)
2018-11-15 17:45:47 -08:00

71 lines
1.4 KiB
C

/*
* Copyright (C) Internet Systems Consortium, Inc. ("ISC")
*
* 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/.
*
* See the COPYRIGHT file distributed with this work for additional
* information regarding copyright ownership.
*/
#include <config.h>
#if HAVE_CMOCKA
#include <stdarg.h>
#include <stddef.h>
#include <setjmp.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define UNIT_TESTING
#include <cmocka.h>
#include <isc/print.h>
#include <isc/result.h>
#include <isc/time.h>
#include <isc/util.h>
/* parse http time stamp */
static void
isc_time_parsehttptimestamp_test(void **state) {
isc_result_t result;
isc_time_t t, x;
char buf[ISC_FORMATHTTPTIMESTAMP_SIZE];
UNUSED(state);
setenv("TZ", "PST8PDT", 1);
result = isc_time_now(&t);
assert_int_equal(result, ISC_R_SUCCESS);
isc_time_formathttptimestamp(&t, buf, sizeof(buf));
result = isc_time_parsehttptimestamp(buf, &x);
assert_int_equal(result, ISC_R_SUCCESS);
assert_int_equal(isc_time_seconds(&t), isc_time_seconds(&x));
}
int
main(void) {
const struct CMUnitTest tests[] = {
cmocka_unit_test(isc_time_parsehttptimestamp_test),
};
return (cmocka_run_group_tests(tests, NULL, NULL));
}
#else /* HAVE_CMOCKA */
#include <stdio.h>
int
main(void) {
printf("1..0 # Skipped: cmocka not available\n");
return (0);
}
#endif