test: extend util unit test
This commit is contained in:
parent
4bbc768652
commit
5384a93645
1 changed files with 27 additions and 0 deletions
|
@ -4,6 +4,7 @@
|
||||||
void test_unit(void) {
|
void test_unit(void) {
|
||||||
NTP_int64 ntp_ts, ntp_fuzz;
|
NTP_int64 ntp_ts, ntp_fuzz;
|
||||||
struct timespec ts, ts2;
|
struct timespec ts, ts2;
|
||||||
|
struct timeval tv;
|
||||||
struct sockaddr_un sun;
|
struct sockaddr_un sun;
|
||||||
double x, y;
|
double x, y;
|
||||||
Float f;
|
Float f;
|
||||||
|
@ -40,6 +41,32 @@ void test_unit(void) {
|
||||||
TEST_CHECK(UTI_DoubleToNtp32(1000000) == htonl(0xffffffff));
|
TEST_CHECK(UTI_DoubleToNtp32(1000000) == htonl(0xffffffff));
|
||||||
TEST_CHECK(UTI_DoubleToNtp32(-1.0) == htonl(0));
|
TEST_CHECK(UTI_DoubleToNtp32(-1.0) == htonl(0));
|
||||||
|
|
||||||
|
UTI_DoubleToTimeval(0.4e-6, &tv);
|
||||||
|
TEST_CHECK(tv.tv_sec == 0);
|
||||||
|
TEST_CHECK(tv.tv_usec == 0);
|
||||||
|
UTI_DoubleToTimeval(-0.4e-6, &tv);
|
||||||
|
TEST_CHECK(tv.tv_sec == 0);
|
||||||
|
TEST_CHECK(tv.tv_usec == 0);
|
||||||
|
UTI_DoubleToTimeval(0.5e-6, &tv);
|
||||||
|
TEST_CHECK(tv.tv_sec == 0);
|
||||||
|
TEST_CHECK(tv.tv_usec == 1);
|
||||||
|
UTI_DoubleToTimeval(-0.5e-6, &tv);
|
||||||
|
TEST_CHECK(tv.tv_sec == -1);
|
||||||
|
TEST_CHECK(tv.tv_usec == 999999);
|
||||||
|
|
||||||
|
UTI_DoubleToTimespec(0.9e-9, &ts);
|
||||||
|
TEST_CHECK(ts.tv_sec == 0);
|
||||||
|
TEST_CHECK(ts.tv_nsec == 0);
|
||||||
|
UTI_DoubleToTimespec(1.0e-9, &ts);
|
||||||
|
TEST_CHECK(ts.tv_sec == 0);
|
||||||
|
TEST_CHECK(ts.tv_nsec == 1);
|
||||||
|
UTI_DoubleToTimespec(-0.9e-9, &ts);
|
||||||
|
TEST_CHECK(ts.tv_sec == 0);
|
||||||
|
TEST_CHECK(ts.tv_nsec == 0);
|
||||||
|
UTI_DoubleToTimespec(-1.0e-9, &ts);
|
||||||
|
TEST_CHECK(ts.tv_sec == -1);
|
||||||
|
TEST_CHECK(ts.tv_nsec == 999999999);
|
||||||
|
|
||||||
ntp_ts.hi = htonl(JAN_1970);
|
ntp_ts.hi = htonl(JAN_1970);
|
||||||
ntp_ts.lo = 0xffffffff;
|
ntp_ts.lo = 0xffffffff;
|
||||||
UTI_Ntp64ToTimespec(&ntp_ts, &ts);
|
UTI_Ntp64ToTimespec(&ntp_ts, &ts);
|
||||||
|
|
Loading…
Reference in a new issue