refnumtoa.c revision 284990
138166Sache#include "config.h" 238166Sache 353943Sache#include "ntp_net.h" 438166Sache#include "ntp_refclock.h" 5174990Sache 638166Sache#include "unity.h" 738166Sache 838166Sache 938166Sache/* Might need to be updated if a new refclock gets this id. */ 1038166Sachestatic const int UNUSED_REFCLOCK_ID = 250; 1138166Sache 1238166Sache 1338166Sachevoid test_LocalClock() { 1438166Sache#ifdef REFCLOCK /* clockname() is useless otherwise */ 1538166Sache /* We test with a refclock address of type LOCALCLOCK. 1638166Sache * with id 8 1738166Sache */ 1838166Sache u_int32 addr = REFCLOCK_ADDR; 1938166Sache addr |= REFCLK_LOCALCLOCK << 8; 20174990Sache addr |= 0x8; 2138166Sache 2238166Sache sockaddr_u address; 2338166Sache address.sa4.sin_family = AF_INET; 2438166Sache address.sa4.sin_addr.s_addr = htonl(addr); 2538166Sache 2638166Sache char stringStart [100]= ""; 2738166Sache 2838166Sache strcat(stringStart,clockname(REFCLK_LOCALCLOCK)); 2938166Sache strcat(stringStart,"(8)"); 3038166Sache 3138166Sache char * expected = stringStart; 3238166Sache 3338166Sache TEST_ASSERT_EQUAL_STRING(expected, refnumtoa(&address)); 3438166Sache#else 3538166Sache TEST_IGNORE_MESSAGE("REFCLOCK NOT DEFINED, SKIPPING TEST"); 3638166Sache#endif /* REFCLOCK */ 3738166Sache} 3838166Sache 3938166Sache 4038166Sache 4138166Sachevoid test_UnknownId() { 4238166Sache#ifdef REFCLOCK /* refnumtoa() is useless otherwise */ 4338166Sache /* We test with a currently unused refclock ID */ 4438166Sache u_int32 addr = REFCLOCK_ADDR; 4538166Sache addr |= UNUSED_REFCLOCK_ID << 8; 4638166Sache addr |= 0x4; 4738166Sache 4838166Sache sockaddr_u address; 4938166Sache address.sa4.sin_family = AF_INET; 5038166Sache address.sa4.sin_addr.s_addr = htonl(addr); 5138166Sache 5238166Sache char stringStart [100]= "REFCLK("; 5338166Sache char value [100] ; 5438166Sache snprintf(value, sizeof(value), "%d", UNUSED_REFCLOCK_ID); 5538166Sache strcat(stringStart,value); 5638166Sache strcat(stringStart,",4)"); 5738166Sache char * expected = stringStart; 5838166Sache 5938166Sache TEST_ASSERT_EQUAL_STRING(expected, refnumtoa(&address)); 6038166Sache#else 6138166Sache TEST_IGNORE_MESSAGE("REFCLOCK NOT DEFINED, SKIPPING TEST"); 6238166Sache#endif /* REFCLOCK */ 6338166Sache} 6438166Sache 6554090Sache