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