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