Commit 69b892ed authored by Evan Hunt's avatar Evan Hunt
Browse files

convert time_test

(cherry picked from commit 3bf9a1e5)
(cherry picked from commit 8d039673)
parent caac5988
......@@ -28,5 +28,5 @@ atf_test_program{name='socket_test'}
tap_test_program{name='symtab_test'}
atf_test_program{name='task_test'}
tap_test_program{name='taskpool_test'}
atf_test_program{name='time_test'}
tap_test_program{name='time_test'}
atf_test_program{name='timer_test'}
......@@ -178,8 +178,9 @@ taskpool_test@EXEEXT@: taskpool_test.@O@ isctest.@O@ ${ISCDEPLIBS}
${ISCLIBS} ${LIBS} ${CMOCKA_LIBS}
time_test@EXEEXT@: time_test.@O@ ${ISCDEPLIBS}
${LIBTOOL_MODE_LINK} ${PURIFY} ${CC} ${CFLAGS} ${LDFLAGS} -o $@ \
time_test.@O@ ${ISCLIBS} ${LIBS}
${LIBTOOL_MODE_LINK} ${PURIFY} ${CC} ${CFLAGS} ${CMOCKA_CFLAGS} \
${LDFLAGS} -o $@ time_test.@O@ \
${ISCLIBS} ${LIBS} ${CMOCKA_LIBS}
timer_test@EXEEXT@: timer_test.@O@ isctest.@O@ ${ISCDEPLIBS}
${LIBTOOL_MODE_LINK} ${PURIFY} ${CC} ${CFLAGS} ${LDFLAGS} -o $@ \
......
......@@ -10,37 +10,61 @@
*/
#include <config.h>
#if HAVE_CMOCKA
#include <stdarg.h>
#include <stddef.h>
#include <setjmp.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <atf-c.h>
#define UNIT_TESTING
#include <cmocka.h>
#include <isc/time.h>
#include <isc/print.h>
#include <isc/result.h>
#include <isc/time.h>
#include <isc/util.h>
ATF_TC(isc_time_parsehttptimestamp);
ATF_TC_HEAD(isc_time_parsehttptimestamp, tc) {
atf_tc_set_md_var(tc, "descr", "parse http time stamp");
}
ATF_TC_BODY(isc_time_parsehttptimestamp, tc) {
/* 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);
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
assert_int_equal(result, ISC_R_SUCCESS);
isc_time_formathttptimestamp(&t, buf, sizeof(buf));
result = isc_time_parsehttptimestamp(buf, &x);
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
ATF_REQUIRE_EQ(isc_time_seconds(&t), isc_time_seconds(&x));
assert_int_equal(result, ISC_R_SUCCESS);
assert_int_equal(isc_time_seconds(&t), isc_time_seconds(&x));
}
/*
* Main
*/
ATF_TP_ADD_TCS(tp) {
ATF_TP_ADD_TC(tp, isc_time_parsehttptimestamp);
return (atf_no_error());
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
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