1284990Scy#include "config.h" 2284990Scy 3284990Scy#include "ntp_net.h" 4284990Scy#include "ntp_refclock.h" 5284990Scy 6284990Scy#include "unity.h" 7284990Scy 8284990Scy 9284990Scy/* Might need to be updated if a new refclock gets this id. */ 10284990Scystatic const int UNUSED_REFCLOCK_ID = 250; 11284990Scy 12293893Sglebiusvoid setUp(void); 13289999Sglebiusvoid test_LocalClock(void); 14289999Sglebiusvoid test_UnknownId(void); 15284990Scy 16289999Sglebius 17289999Sglebiusvoid 18293893SglebiussetUp(void) 19293893Sglebius{ 20293893Sglebius init_lib(); 21293893Sglebius 22293893Sglebius return; 23293893Sglebius} 24293893Sglebius 25293893Sglebius 26293893Sglebiusvoid 27289999Sglebiustest_LocalClock(void) { 28284990Scy#ifdef REFCLOCK /* clockname() is useless otherwise */ 29284990Scy /* We test with a refclock address of type LOCALCLOCK. 30284990Scy * with id 8 31284990Scy */ 32284990Scy u_int32 addr = REFCLOCK_ADDR; 33284990Scy addr |= REFCLK_LOCALCLOCK << 8; 34284990Scy addr |= 0x8; 35284990Scy 36284990Scy sockaddr_u address; 37284990Scy address.sa4.sin_family = AF_INET; 38284990Scy address.sa4.sin_addr.s_addr = htonl(addr); 39293893Sglebius 40289999Sglebius char stringStart[100]= ""; 41284990Scy 42289999Sglebius strcat(stringStart, clockname(REFCLK_LOCALCLOCK)); 43289999Sglebius strcat(stringStart, "(8)"); 44284990Scy 45284990Scy char * expected = stringStart; 46284990Scy 47284990Scy TEST_ASSERT_EQUAL_STRING(expected, refnumtoa(&address)); 48293893Sglebius#else 49284990Scy TEST_IGNORE_MESSAGE("REFCLOCK NOT DEFINED, SKIPPING TEST"); 50284990Scy#endif /* REFCLOCK */ 51284990Scy} 52284990Scy 53289999Sglebiusvoid 54289999Sglebiustest_UnknownId(void) { 55284990Scy#ifdef REFCLOCK /* refnumtoa() is useless otherwise */ 56284990Scy /* We test with a currently unused refclock ID */ 57284990Scy u_int32 addr = REFCLOCK_ADDR; 58284990Scy addr |= UNUSED_REFCLOCK_ID << 8; 59284990Scy addr |= 0x4; 60284990Scy 61284990Scy sockaddr_u address; 62284990Scy address.sa4.sin_family = AF_INET; 63284990Scy address.sa4.sin_addr.s_addr = htonl(addr); 64293893Sglebius 65289999Sglebius char stringStart[100]= "REFCLK("; 66293893Sglebius char value[100] ; 67284990Scy snprintf(value, sizeof(value), "%d", UNUSED_REFCLOCK_ID); 68284990Scy strcat(stringStart,value); 69284990Scy strcat(stringStart,",4)"); 70284990Scy char * expected = stringStart; 71284990Scy 72284990Scy TEST_ASSERT_EQUAL_STRING(expected, refnumtoa(&address)); 73293893Sglebius#else 74284990Scy TEST_IGNORE_MESSAGE("REFCLOCK NOT DEFINED, SKIPPING TEST"); 75284990Scy#endif /* REFCLOCK */ 76284990Scy} 77