]> CyberLeo.Net >> Repos - FreeBSD/releng/10.2.git/blob - contrib/ntp/tests/libntp/g_humandate.cpp
Fix a regression with SA-15:24 patch that prevented NIS from
[FreeBSD/releng/10.2.git] / contrib / ntp / tests / libntp / g_humandate.cpp
1 #include "g_libntptest.h"
2
3 #include <sstream>
4 #include <string>
5
6 class humandateTest : public libntptest {
7 };
8
9 TEST_F(humandateTest, RegularTime) {
10         time_t sample = 1276601278;
11         std::ostringstream expected;
12
13         tm* time;
14         time = localtime(&sample);
15         ASSERT_TRUE(time != NULL);
16
17         expected << std::setfill('0')
18                          << std::setw(2) << time->tm_hour << ":"
19                          << std::setw(2) << time->tm_min << ":"
20                          << std::setw(2) << time->tm_sec;
21
22         EXPECT_STREQ(expected.str().c_str(), humantime(sample));
23 }
24
25 TEST_F(humandateTest, CurrentTime) {
26         time_t sample;
27         std::ostringstream expected;
28
29         time(&sample);
30
31         tm* time;
32         time = localtime(&sample);
33         ASSERT_TRUE(time != NULL);
34
35         expected << std::setfill('0')
36                          << std::setw(2) << time->tm_hour << ":"
37                          << std::setw(2) << time->tm_min << ":"
38                          << std::setw(2) << time->tm_sec;
39
40         EXPECT_STREQ(expected.str().c_str(), humantime(sample));
41 }