MCPcopy Create free account
hub / github.com/apache/brpc / TEST_F

Function TEST_F

test/time_unittest.cc:57–93  ·  view source on GitHub ↗

Test conversions to/from time_t and exploding/unexploding.

Source from the content-addressed store, hash-verified

55
56// Test conversions to/from time_t and exploding/unexploding.
57TEST_F(TimeTest, TimeT) {
58 // C library time and exploded time.
59 time_t now_t_1 = time(NULL);
60 struct tm tms;
61#if defined(OS_WIN)
62 localtime_s(&tms, &now_t_1);
63#elif defined(OS_POSIX)
64 localtime_r(&now_t_1, &tms);
65#endif
66
67 // Convert to ours.
68 Time our_time_1 = Time::FromTimeT(now_t_1);
69 Time::Exploded exploded;
70 our_time_1.LocalExplode(&exploded);
71
72 // This will test both our exploding and our time_t -> Time conversion.
73 EXPECT_EQ(tms.tm_year + 1900, exploded.year);
74 EXPECT_EQ(tms.tm_mon + 1, exploded.month);
75 EXPECT_EQ(tms.tm_mday, exploded.day_of_month);
76 EXPECT_EQ(tms.tm_hour, exploded.hour);
77 EXPECT_EQ(tms.tm_min, exploded.minute);
78 EXPECT_EQ(tms.tm_sec, exploded.second);
79
80 // Convert exploded back to the time struct.
81 Time our_time_2 = Time::FromLocalExploded(exploded);
82 EXPECT_TRUE(our_time_1 == our_time_2);
83
84 time_t now_t_2 = our_time_2.ToTimeT();
85 EXPECT_EQ(now_t_1, now_t_2);
86
87 EXPECT_EQ(10, Time().FromTimeT(10).ToTimeT());
88 EXPECT_EQ(10.0, Time().FromTimeT(10).ToDoubleT());
89
90 // Conversions of 0 should stay 0.
91 EXPECT_EQ(0, Time().ToTimeT());
92 EXPECT_EQ(0, Time::FromTimeT(0).ToInternalValue());
93}
94
95// Test conversions to/from javascript time.
96TEST_F(TimeTest, JsTime) {

Callers

nothing calls this directly

Calls 15

FromLocalExplodedFunction · 0.85
FromUTCExplodedFunction · 0.85
FromStringFunction · 0.85
FromInternalValueFunction · 0.85
ToTimeTMethod · 0.80
FromTimeTMethod · 0.80
ToDoubleTMethod · 0.80
ToJsTimeMethod · 0.80
ToTimeValMethod · 0.80
LocalMidnightMethod · 0.80
HasValidValuesMethod · 0.80
InDaysMethod · 0.80

Tested by

no test coverage detected