diff options
Diffstat (limited to 'tests/libntp/g_humandate.cpp')
-rw-r--r-- | tests/libntp/g_humandate.cpp | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/tests/libntp/g_humandate.cpp b/tests/libntp/g_humandate.cpp new file mode 100644 index 0000000000000..a50ae53408930 --- /dev/null +++ b/tests/libntp/g_humandate.cpp @@ -0,0 +1,41 @@ +#include "g_libntptest.h" + +#include <sstream> +#include <string> + +class humandateTest : public libntptest { +}; + +TEST_F(humandateTest, RegularTime) { + time_t sample = 1276601278; + std::ostringstream expected; + + tm* time; + time = localtime(&sample); + ASSERT_TRUE(time != NULL); + + expected << std::setfill('0') + << std::setw(2) << time->tm_hour << ":" + << std::setw(2) << time->tm_min << ":" + << std::setw(2) << time->tm_sec; + + EXPECT_STREQ(expected.str().c_str(), humantime(sample)); +} + +TEST_F(humandateTest, CurrentTime) { + time_t sample; + std::ostringstream expected; + + time(&sample); + + tm* time; + time = localtime(&sample); + ASSERT_TRUE(time != NULL); + + expected << std::setfill('0') + << std::setw(2) << time->tm_hour << ":" + << std::setw(2) << time->tm_min << ":" + << std::setw(2) << time->tm_sec; + + EXPECT_STREQ(expected.str().c_str(), humantime(sample)); +} |