summaryrefslogtreecommitdiffstats
path: root/contrib/ntp/tests/libntp/tstotv.c
blob: 080172752fda842381ed3c3f11ad1d5933af9cb5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#include "config.h"

#include "ntp_fp.h"
#include "timevalops.h"

#include "unity.h"

void
test_Seconds(void) {
	const l_fp input = {50, 0}; // 50.0 s
	const struct timeval expected = {50, 0};
	struct timeval actual;

	TSTOTV(&input, &actual);

	TEST_ASSERT_EQUAL(expected.tv_sec, actual.tv_sec);
	TEST_ASSERT_EQUAL(expected.tv_usec, actual.tv_usec);
}

void
test_MicrosecondsExact(void) {
	const u_long HALF = 2147483648UL;
	const l_fp input = {50, HALF}; // 50.5 s
	const struct timeval expected = {50, 500000};
	struct timeval actual;

	TSTOTV(&input, &actual);

	TEST_ASSERT_EQUAL(expected.tv_sec, actual.tv_sec);
	TEST_ASSERT_EQUAL(expected.tv_usec, actual.tv_usec);

}

void
test_MicrosecondsRounding(void) {
	const l_fp input = {50, 3865471UL}; // Should round to 50.0009
	const struct timeval expected = {50, 900};
	struct timeval actual;

	TSTOTV(&input, &actual);

	TEST_ASSERT_EQUAL(expected.tv_sec, actual.tv_sec);
	TEST_ASSERT_EQUAL(expected.tv_usec, actual.tv_usec);
}
OpenPOWER on IntegriCloud