1284990Scy#include "config.h"
2284990Scy
3284990Scy#include "ntp_net.h"
4284990Scy#include "ntp_refclock.h"
5284990Scy
6284990Scy#include "unity.h"
7284990Scy
8284990Scy
9284990Scy/* Might need to be updated if a new refclock gets this id. */
10284990Scystatic const int UNUSED_REFCLOCK_ID = 250;
11284990Scy
12293650Sglebiusvoid setUp(void);
13289997Sglebiusvoid test_LocalClock(void);
14289997Sglebiusvoid test_UnknownId(void);
15284990Scy
16289997Sglebius
17289997Sglebiusvoid
18293650SglebiussetUp(void)
19293650Sglebius{
20293650Sglebius	init_lib();
21293650Sglebius
22293650Sglebius	return;
23293650Sglebius}
24293650Sglebius
25293650Sglebius
26293650Sglebiusvoid
27289997Sglebiustest_LocalClock(void) {
28284990Scy#ifdef REFCLOCK		/* clockname() is useless otherwise */
29284990Scy	/* We test with a refclock address of type LOCALCLOCK.
30284990Scy	 * with id 8
31284990Scy	 */
32284990Scy	u_int32 addr = REFCLOCK_ADDR;
33284990Scy	addr |= REFCLK_LOCALCLOCK << 8;
34284990Scy	addr |= 0x8;
35284990Scy
36284990Scy	sockaddr_u address;
37284990Scy	address.sa4.sin_family = AF_INET;
38284990Scy	address.sa4.sin_addr.s_addr = htonl(addr);
39293650Sglebius
40289997Sglebius	char stringStart[100]= "";
41284990Scy
42289997Sglebius	strcat(stringStart, clockname(REFCLK_LOCALCLOCK));
43289997Sglebius	strcat(stringStart, "(8)");
44284990Scy
45284990Scy	char * expected = stringStart;
46284990Scy
47284990Scy	TEST_ASSERT_EQUAL_STRING(expected, refnumtoa(&address));
48293650Sglebius#else
49284990Scy	TEST_IGNORE_MESSAGE("REFCLOCK NOT DEFINED, SKIPPING TEST");
50284990Scy#endif	/* REFCLOCK */
51284990Scy}
52284990Scy
53289997Sglebiusvoid
54289997Sglebiustest_UnknownId(void) {
55284990Scy#ifdef REFCLOCK		/* refnumtoa() is useless otherwise */
56284990Scy	/* We test with a currently unused refclock ID */
57284990Scy	u_int32 addr = REFCLOCK_ADDR;
58284990Scy	addr |= UNUSED_REFCLOCK_ID << 8;
59284990Scy	addr |= 0x4;
60284990Scy
61284990Scy	sockaddr_u address;
62284990Scy	address.sa4.sin_family = AF_INET;
63284990Scy	address.sa4.sin_addr.s_addr = htonl(addr);
64293650Sglebius
65289997Sglebius	char stringStart[100]= "REFCLK(";
66293650Sglebius	char value[100] ;
67284990Scy	snprintf(value, sizeof(value), "%d", UNUSED_REFCLOCK_ID);
68284990Scy	strcat(stringStart,value);
69284990Scy	strcat(stringStart,",4)");
70284990Scy	char * expected = stringStart;
71284990Scy
72284990Scy	TEST_ASSERT_EQUAL_STRING(expected, refnumtoa(&address));
73293650Sglebius#else
74284990Scy	TEST_IGNORE_MESSAGE("REFCLOCK NOT DEFINED, SKIPPING TEST");
75284990Scy#endif	/* REFCLOCK */
76284990Scy}
77