refnumtoa.c revision 1.1.1.3
1/* $NetBSD: refnumtoa.c,v 1.1.1.3 2015/10/23 17:47:45 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 test_LocalClock(void); 15void test_UnknownId(void); 16 17 18void 19test_LocalClock(void) { 20#ifdef REFCLOCK /* clockname() is useless otherwise */ 21 /* We test with a refclock address of type LOCALCLOCK. 22 * with id 8 23 */ 24 u_int32 addr = REFCLOCK_ADDR; 25 addr |= REFCLK_LOCALCLOCK << 8; 26 addr |= 0x8; 27 28 sockaddr_u address; 29 address.sa4.sin_family = AF_INET; 30 address.sa4.sin_addr.s_addr = htonl(addr); 31 32 char stringStart[100]= ""; 33 34 strcat(stringStart, clockname(REFCLK_LOCALCLOCK)); 35 strcat(stringStart, "(8)"); 36 37 char * expected = stringStart; 38 39 TEST_ASSERT_EQUAL_STRING(expected, refnumtoa(&address)); 40#else 41 TEST_IGNORE_MESSAGE("REFCLOCK NOT DEFINED, SKIPPING TEST"); 42#endif /* REFCLOCK */ 43} 44 45void 46test_UnknownId(void) { 47#ifdef REFCLOCK /* refnumtoa() is useless otherwise */ 48 /* We test with a currently unused refclock ID */ 49 u_int32 addr = REFCLOCK_ADDR; 50 addr |= UNUSED_REFCLOCK_ID << 8; 51 addr |= 0x4; 52 53 sockaddr_u address; 54 address.sa4.sin_family = AF_INET; 55 address.sa4.sin_addr.s_addr = htonl(addr); 56 57 char stringStart[100]= "REFCLK("; 58 char value[100] ; 59 snprintf(value, sizeof(value), "%d", UNUSED_REFCLOCK_ID); 60 strcat(stringStart,value); 61 strcat(stringStart,",4)"); 62 char * expected = stringStart; 63 64 TEST_ASSERT_EQUAL_STRING(expected, refnumtoa(&address)); 65#else 66 TEST_IGNORE_MESSAGE("REFCLOCK NOT DEFINED, SKIPPING TEST"); 67#endif /* REFCLOCK */ 68} 69