1/*	$NetBSD: refnumtoa.c,v 1.2 2020/05/25 20:47:36 christos Exp $	*/
2
3#include "config.h"
4
5#include "ntp_net.h"
6#include "ntp_refclock.h"
7
8#include "unity.h"
9
10
11/* Might need to be updated if a new refclock gets this id. */
12static const int UNUSED_REFCLOCK_ID = 250;
13
14void setUp(void);
15void test_LocalClock(void);
16void test_UnknownId(void);
17
18
19void
20setUp(void)
21{
22	init_lib();
23
24	return;
25}
26
27
28void
29test_LocalClock(void) {
30#ifdef REFCLOCK		/* clockname() is useless otherwise */
31	/* We test with a refclock address of type LOCALCLOCK.
32	 * with id 8
33	 */
34	u_int32 addr = REFCLOCK_ADDR;
35	addr |= REFCLK_LOCALCLOCK << 8;
36	addr |= 0x8;
37
38	sockaddr_u address;
39	address.sa4.sin_family = AF_INET;
40	address.sa4.sin_addr.s_addr = htonl(addr);
41
42	char stringStart[100]= "";
43
44	strcat(stringStart, clockname(REFCLK_LOCALCLOCK));
45	strcat(stringStart, "(8)");
46
47	char * expected = stringStart;
48
49	TEST_ASSERT_EQUAL_STRING(expected, refnumtoa(&address));
50#else
51	TEST_IGNORE_MESSAGE("REFCLOCK NOT DEFINED, SKIPPING TEST");
52#endif	/* REFCLOCK */
53}
54
55void
56test_UnknownId(void) {
57#ifdef REFCLOCK		/* refnumtoa() is useless otherwise */
58	/* We test with a currently unused refclock ID */
59	u_int32 addr = REFCLOCK_ADDR;
60	addr |= UNUSED_REFCLOCK_ID << 8;
61	addr |= 0x4;
62
63	sockaddr_u address;
64	address.sa4.sin_family = AF_INET;
65	address.sa4.sin_addr.s_addr = htonl(addr);
66
67	char stringStart[100]= "REFCLK(";
68	char value[100] ;
69	snprintf(value, sizeof(value), "%d", UNUSED_REFCLOCK_ID);
70	strcat(stringStart,value);
71	strcat(stringStart,",4)");
72	char * expected = stringStart;
73
74	TEST_ASSERT_EQUAL_STRING(expected, refnumtoa(&address));
75#else
76	TEST_IGNORE_MESSAGE("REFCLOCK NOT DEFINED, SKIPPING TEST");
77#endif	/* REFCLOCK */
78}
79