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