mirror of
https://gitlab.isc.org/isc-projects/bind9
synced 2025-09-02 07:35:26 +00:00
convert time_test
This commit is contained in:
@@ -10,31 +10,54 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
/*! \file */
|
|
||||||
|
|
||||||
#include <config.h>
|
#include <config.h>
|
||||||
|
|
||||||
#include <atf-c.h>
|
#if HAVE_CMOCKA
|
||||||
|
|
||||||
|
#include <stdarg.h>
|
||||||
|
#include <stddef.h>
|
||||||
|
#include <setjmp.h>
|
||||||
|
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <stdio.h>
|
||||||
#include <inttypes.h>
|
#include <inttypes.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|
||||||
|
#define UNIT_TESTING
|
||||||
|
#include <cmocka.h>
|
||||||
|
|
||||||
|
#include <isc/util.h>
|
||||||
|
|
||||||
#include <dns/time.h>
|
#include <dns/time.h>
|
||||||
|
|
||||||
#include "dnstest.h"
|
#include "dnstest.h"
|
||||||
|
|
||||||
#define TEST_ORIGIN "test"
|
#define TEST_ORIGIN "test"
|
||||||
|
|
||||||
/*
|
static int
|
||||||
* Individual unit tests
|
_setup(void **state) {
|
||||||
*/
|
isc_result_t result;
|
||||||
|
|
||||||
|
UNUSED(state);
|
||||||
|
|
||||||
|
result = dns_test_begin(NULL, false);
|
||||||
|
assert_int_equal(result, ISC_R_SUCCESS);
|
||||||
|
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
|
|
||||||
|
static int
|
||||||
|
_teardown(void **state) {
|
||||||
|
UNUSED(state);
|
||||||
|
|
||||||
|
dns_test_end();
|
||||||
|
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
|
|
||||||
/* value = 0xfffffffff <-> 19691231235959 */
|
/* value = 0xfffffffff <-> 19691231235959 */
|
||||||
ATF_TC(epoch_minus_one);
|
static void
|
||||||
ATF_TC_HEAD(epoch_minus_one, tc) {
|
epoch_minus_one_test(void **state) {
|
||||||
atf_tc_set_md_var(tc, "descr", "0xffffffff <-> 19691231235959");
|
|
||||||
}
|
|
||||||
ATF_TC_BODY(epoch_minus_one, tc) {
|
|
||||||
const char *test_text = "19691231235959";
|
const char *test_text = "19691231235959";
|
||||||
const uint32_t test_time = 0xffffffff;
|
const uint32_t test_time = 0xffffffff;
|
||||||
isc_result_t result;
|
isc_result_t result;
|
||||||
@@ -42,27 +65,21 @@ ATF_TC_BODY(epoch_minus_one, tc) {
|
|||||||
uint32_t when;
|
uint32_t when;
|
||||||
char buf[128];
|
char buf[128];
|
||||||
|
|
||||||
UNUSED(tc);
|
UNUSED(state);
|
||||||
|
|
||||||
result = dns_test_begin(NULL, false);
|
|
||||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
|
||||||
memset(buf, 0, sizeof(buf));
|
memset(buf, 0, sizeof(buf));
|
||||||
isc_buffer_init(&target, buf, sizeof(buf));
|
isc_buffer_init(&target, buf, sizeof(buf));
|
||||||
result = dns_time32_totext(test_time, &target);
|
result = dns_time32_totext(test_time, &target);
|
||||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
assert_int_equal(result, ISC_R_SUCCESS);
|
||||||
ATF_REQUIRE_STREQ(buf, test_text);
|
assert_string_equal(buf, test_text);
|
||||||
result = dns_time32_fromtext(test_text, &when);
|
result = dns_time32_fromtext(test_text, &when);
|
||||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
assert_int_equal(result, ISC_R_SUCCESS);
|
||||||
ATF_REQUIRE_EQ(when, test_time);
|
assert_int_equal(when, test_time);
|
||||||
dns_test_end();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* value = 0x000000000 <-> 19700101000000*/
|
/* value = 0x000000000 <-> 19700101000000*/
|
||||||
ATF_TC(epoch);
|
static void
|
||||||
ATF_TC_HEAD(epoch, tc) {
|
epoch_test(void **state) {
|
||||||
atf_tc_set_md_var(tc, "descr", "0x00000000 <-> 19700101000000");
|
|
||||||
}
|
|
||||||
ATF_TC_BODY(epoch, tc) {
|
|
||||||
const char *test_text = "19700101000000";
|
const char *test_text = "19700101000000";
|
||||||
const uint32_t test_time = 0x00000000;
|
const uint32_t test_time = 0x00000000;
|
||||||
isc_result_t result;
|
isc_result_t result;
|
||||||
@@ -70,27 +87,21 @@ ATF_TC_BODY(epoch, tc) {
|
|||||||
uint32_t when;
|
uint32_t when;
|
||||||
char buf[128];
|
char buf[128];
|
||||||
|
|
||||||
UNUSED(tc);
|
UNUSED(state);
|
||||||
|
|
||||||
result = dns_test_begin(NULL, false);
|
|
||||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
|
||||||
memset(buf, 0, sizeof(buf));
|
memset(buf, 0, sizeof(buf));
|
||||||
isc_buffer_init(&target, buf, sizeof(buf));
|
isc_buffer_init(&target, buf, sizeof(buf));
|
||||||
result = dns_time32_totext(test_time, &target);
|
result = dns_time32_totext(test_time, &target);
|
||||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
assert_int_equal(result, ISC_R_SUCCESS);
|
||||||
ATF_REQUIRE_STREQ(buf, test_text);
|
assert_string_equal(buf, test_text);
|
||||||
result = dns_time32_fromtext(test_text, &when);
|
result = dns_time32_fromtext(test_text, &when);
|
||||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
assert_int_equal(result, ISC_R_SUCCESS);
|
||||||
ATF_REQUIRE_EQ(when, test_time);
|
assert_int_equal(when, test_time);
|
||||||
dns_test_end();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* value = 0x7fffffff <-> 20380119031407 */
|
/* value = 0x7fffffff <-> 20380119031407 */
|
||||||
ATF_TC(half_maxint);
|
static void
|
||||||
ATF_TC_HEAD(half_maxint, tc) {
|
half_maxint_test(void **state) {
|
||||||
atf_tc_set_md_var(tc, "descr", "0x7fffffff <-> 20380119031407");
|
|
||||||
}
|
|
||||||
ATF_TC_BODY(half_maxint, tc) {
|
|
||||||
const char *test_text = "20380119031407";
|
const char *test_text = "20380119031407";
|
||||||
const uint32_t test_time = 0x7fffffff;
|
const uint32_t test_time = 0x7fffffff;
|
||||||
isc_result_t result;
|
isc_result_t result;
|
||||||
@@ -98,27 +109,21 @@ ATF_TC_BODY(half_maxint, tc) {
|
|||||||
uint32_t when;
|
uint32_t when;
|
||||||
char buf[128];
|
char buf[128];
|
||||||
|
|
||||||
UNUSED(tc);
|
UNUSED(state);
|
||||||
|
|
||||||
result = dns_test_begin(NULL, false);
|
|
||||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
|
||||||
memset(buf, 0, sizeof(buf));
|
memset(buf, 0, sizeof(buf));
|
||||||
isc_buffer_init(&target, buf, sizeof(buf));
|
isc_buffer_init(&target, buf, sizeof(buf));
|
||||||
result = dns_time32_totext(test_time, &target);
|
result = dns_time32_totext(test_time, &target);
|
||||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
assert_int_equal(result, ISC_R_SUCCESS);
|
||||||
ATF_REQUIRE_STREQ(buf, test_text);
|
assert_string_equal(buf, test_text);
|
||||||
result = dns_time32_fromtext(test_text, &when);
|
result = dns_time32_fromtext(test_text, &when);
|
||||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
assert_int_equal(result, ISC_R_SUCCESS);
|
||||||
ATF_REQUIRE_EQ(when, test_time);
|
assert_int_equal(when, test_time);
|
||||||
dns_test_end();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* value = 0x80000000 <-> 20380119031408 */
|
/* value = 0x80000000 <-> 20380119031408 */
|
||||||
ATF_TC(half_plus_one);
|
static void
|
||||||
ATF_TC_HEAD(half_plus_one, tc) {
|
half_plus_one_test(void **state) {
|
||||||
atf_tc_set_md_var(tc, "descr", "0x80000000 <-> 20380119031408");
|
|
||||||
}
|
|
||||||
ATF_TC_BODY(half_plus_one, tc) {
|
|
||||||
const char *test_text = "20380119031408";
|
const char *test_text = "20380119031408";
|
||||||
const uint32_t test_time = 0x80000000;
|
const uint32_t test_time = 0x80000000;
|
||||||
isc_result_t result;
|
isc_result_t result;
|
||||||
@@ -126,27 +131,21 @@ ATF_TC_BODY(half_plus_one, tc) {
|
|||||||
uint32_t when;
|
uint32_t when;
|
||||||
char buf[128];
|
char buf[128];
|
||||||
|
|
||||||
UNUSED(tc);
|
UNUSED(state);
|
||||||
|
|
||||||
result = dns_test_begin(NULL, false);
|
|
||||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
|
||||||
memset(buf, 0, sizeof(buf));
|
memset(buf, 0, sizeof(buf));
|
||||||
isc_buffer_init(&target, buf, sizeof(buf));
|
isc_buffer_init(&target, buf, sizeof(buf));
|
||||||
result = dns_time32_totext(test_time, &target);
|
result = dns_time32_totext(test_time, &target);
|
||||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
assert_int_equal(result, ISC_R_SUCCESS);
|
||||||
ATF_REQUIRE_STREQ(buf, test_text);
|
assert_string_equal(buf, test_text);
|
||||||
result = dns_time32_fromtext(test_text, &when);
|
result = dns_time32_fromtext(test_text, &when);
|
||||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
assert_int_equal(result, ISC_R_SUCCESS);
|
||||||
ATF_REQUIRE_EQ(when, test_time);
|
assert_int_equal(when, test_time);
|
||||||
dns_test_end();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* value = 0xef68f5d0 <-> 19610307130000 */
|
/* value = 0xef68f5d0 <-> 19610307130000 */
|
||||||
ATF_TC(fifty_before);
|
static void
|
||||||
ATF_TC_HEAD(fifty_before, tc) {
|
fifty_before_test(void **state) {
|
||||||
atf_tc_set_md_var(tc, "descr", "0xef68f5d0 <-> 19610307130000");
|
|
||||||
}
|
|
||||||
ATF_TC_BODY(fifty_before, tc) {
|
|
||||||
isc_result_t result;
|
isc_result_t result;
|
||||||
const char *test_text = "19610307130000";
|
const char *test_text = "19610307130000";
|
||||||
const uint32_t test_time = 0xef68f5d0;
|
const uint32_t test_time = 0xef68f5d0;
|
||||||
@@ -154,27 +153,21 @@ ATF_TC_BODY(fifty_before, tc) {
|
|||||||
uint32_t when;
|
uint32_t when;
|
||||||
char buf[128];
|
char buf[128];
|
||||||
|
|
||||||
UNUSED(tc);
|
UNUSED(state);
|
||||||
|
|
||||||
result = dns_test_begin(NULL, false);
|
|
||||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
|
||||||
memset(buf, 0, sizeof(buf));
|
memset(buf, 0, sizeof(buf));
|
||||||
isc_buffer_init(&target, buf, sizeof(buf));
|
isc_buffer_init(&target, buf, sizeof(buf));
|
||||||
result = dns_time32_totext(test_time, &target);
|
result = dns_time32_totext(test_time, &target);
|
||||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
assert_int_equal(result, ISC_R_SUCCESS);
|
||||||
ATF_REQUIRE_STREQ(buf, test_text);
|
assert_string_equal(buf, test_text);
|
||||||
result = dns_time32_fromtext(test_text, &when);
|
result = dns_time32_fromtext(test_text, &when);
|
||||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
assert_int_equal(result, ISC_R_SUCCESS);
|
||||||
ATF_REQUIRE_EQ(when, test_time);
|
assert_int_equal(when, test_time);
|
||||||
dns_test_end();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* value = 0x4d74d6d0 <-> 20110307130000 */
|
/* value = 0x4d74d6d0 <-> 20110307130000 */
|
||||||
ATF_TC(some_ago);
|
static void
|
||||||
ATF_TC_HEAD(some_ago, tc) {
|
some_ago_test(void **state) {
|
||||||
atf_tc_set_md_var(tc, "descr", "0x4d74d6d0 <-> 20110307130000");
|
|
||||||
}
|
|
||||||
ATF_TC_BODY(some_ago, tc) {
|
|
||||||
const char *test_text = "20110307130000";
|
const char *test_text = "20110307130000";
|
||||||
const uint32_t test_time = 0x4d74d6d0;
|
const uint32_t test_time = 0x4d74d6d0;
|
||||||
isc_result_t result;
|
isc_result_t result;
|
||||||
@@ -182,32 +175,46 @@ ATF_TC_BODY(some_ago, tc) {
|
|||||||
uint32_t when;
|
uint32_t when;
|
||||||
char buf[128];
|
char buf[128];
|
||||||
|
|
||||||
UNUSED(tc);
|
UNUSED(state);
|
||||||
|
|
||||||
result = dns_test_begin(NULL, false);
|
|
||||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
|
||||||
memset(buf, 0, sizeof(buf));
|
memset(buf, 0, sizeof(buf));
|
||||||
isc_buffer_init(&target, buf, sizeof(buf));
|
isc_buffer_init(&target, buf, sizeof(buf));
|
||||||
result = dns_time32_totext(test_time, &target);
|
result = dns_time32_totext(test_time, &target);
|
||||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
assert_int_equal(result, ISC_R_SUCCESS);
|
||||||
ATF_REQUIRE_STREQ(buf, test_text);
|
assert_string_equal(buf, test_text);
|
||||||
result = dns_time32_fromtext(test_text, &when);
|
result = dns_time32_fromtext(test_text, &when);
|
||||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
assert_int_equal(result, ISC_R_SUCCESS);
|
||||||
ATF_REQUIRE_EQ(when, test_time);
|
assert_int_equal(when, test_time);
|
||||||
dns_test_end();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
int
|
||||||
* Main
|
main(void) {
|
||||||
*/
|
const struct CMUnitTest tests[] = {
|
||||||
ATF_TP_ADD_TCS(tp) {
|
cmocka_unit_test_setup_teardown(epoch_minus_one_test,
|
||||||
ATF_TP_ADD_TC(tp, epoch_minus_one);
|
_setup, _teardown),
|
||||||
ATF_TP_ADD_TC(tp, epoch);
|
cmocka_unit_test_setup_teardown(epoch_test,
|
||||||
ATF_TP_ADD_TC(tp, half_maxint);
|
_setup, _teardown),
|
||||||
ATF_TP_ADD_TC(tp, half_plus_one);
|
cmocka_unit_test_setup_teardown(half_maxint_test,
|
||||||
ATF_TP_ADD_TC(tp, fifty_before);
|
_setup, _teardown),
|
||||||
ATF_TP_ADD_TC(tp, some_ago);
|
cmocka_unit_test_setup_teardown(half_plus_one_test,
|
||||||
|
_setup, _teardown),
|
||||||
|
cmocka_unit_test_setup_teardown(fifty_before_test,
|
||||||
|
_setup, _teardown),
|
||||||
|
cmocka_unit_test_setup_teardown(some_ago_test,
|
||||||
|
_setup, _teardown),
|
||||||
|
};
|
||||||
|
|
||||||
return (atf_no_error());
|
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
|
||||||
|
Reference in New Issue
Block a user