]> CyberLeo.Net >> Repos - FreeBSD/releng/10.2.git/blob - contrib/ntp/tests/libntp/g_refnumtoa.cpp
Fix a regression with SA-15:24 patch that prevented NIS from
[FreeBSD/releng/10.2.git] / contrib / ntp / tests / libntp / g_refnumtoa.cpp
1 #include "g_libntptest.h"
2
3 #include "ntp_net.h"
4 #include "ntp_refclock.h"
5
6 #include <sstream>
7
8 class refnumtoaTest : public libntptest {
9 protected:
10         /* Might need to be updated if a new refclock gets this id. */
11         static const int UNUSED_REFCLOCK_ID = 250;
12 };
13
14 #ifdef REFCLOCK         /* clockname() is useless otherwise */
15 TEST_F(refnumtoaTest, LocalClock) {
16         /* We test with a refclock address of type LOCALCLOCK.
17          * with id 8
18          */
19         u_int32 addr = REFCLOCK_ADDR;
20         addr |= REFCLK_LOCALCLOCK << 8;
21         addr |= 0x8;
22
23         sockaddr_u address;
24         address.sa4.sin_family = AF_INET;
25         address.sa4.sin_addr.s_addr = htonl(addr);
26
27         std::ostringstream expected;
28         expected << clockname(REFCLK_LOCALCLOCK)
29                          << "(8)";
30
31         EXPECT_STREQ(expected.str().c_str(), refnumtoa(&address));
32 }
33 #endif  /* REFCLOCK */
34
35 #ifdef REFCLOCK         /* refnumtoa() is useless otherwise */
36 TEST_F(refnumtoaTest, UnknownId) {
37         /* We test with a currently unused refclock ID */
38         u_int32 addr = REFCLOCK_ADDR;
39         addr |= UNUSED_REFCLOCK_ID << 8;
40         addr |= 0x4;
41
42         sockaddr_u address;
43         address.sa4.sin_family = AF_INET;
44         address.sa4.sin_addr.s_addr = htonl(addr);
45
46         std::ostringstream expected;
47         expected << "REFCLK(" << UNUSED_REFCLOCK_ID
48                          << ",4)";
49
50         EXPECT_STREQ(expected.str().c_str(), refnumtoa(&address));
51 }
52 #endif  /* REFCLOCK */