aboutsummaryrefslogtreecommitdiffhomepage
path: root/test/cpp/util/time_test.cc
diff options
context:
space:
mode:
authorGravatar Yang Gao <yangg@google.com>2015-03-20 23:55:04 -0700
committerGravatar Yang Gao <yangg@google.com>2015-03-20 23:55:04 -0700
commitcdb2a6e071dd57c1cf6f3658d3954bf959519be5 (patch)
tree61e2a0e34f3b843378e3a96e1d56699f5630d6e3 /test/cpp/util/time_test.cc
parentb7b965c842c4cd238b54a1c8e00fba3edb6a3dc7 (diff)
Protect on some overflow scenarios, add a test and build/run the test
Diffstat (limited to 'test/cpp/util/time_test.cc')
-rw-r--r--test/cpp/util/time_test.cc15
1 files changed, 14 insertions, 1 deletions
diff --git a/test/cpp/util/time_test.cc b/test/cpp/util/time_test.cc
index 2e17add67f..4641fdb4da 100644
--- a/test/cpp/util/time_test.cc
+++ b/test/cpp/util/time_test.cc
@@ -61,11 +61,24 @@ TEST_F(TimeTest, AbsolutePointTest) {
EXPECT_TRUE(tp == tp_converted_2);
}
-// gpr_inf_future is treated specially and mapped to time_point::max()
+// gpr_inf_future is treated specially and mapped to/from time_point::max()
TEST_F(TimeTest, InfFuture) {
EXPECT_EQ(system_clock::time_point::max(),
Timespec2Timepoint(gpr_inf_future));
+ gpr_timespec from_time_point_max;
+ Timepoint2Timespec(system_clock::time_point::max(), &from_time_point_max);
+ EXPECT_EQ(0, gpr_time_cmp(gpr_inf_future, from_time_point_max));
+ // This will cause an overflow
+ Timepoint2Timespec(
+ std::chrono::time_point<system_clock, std::chrono::seconds>::max(),
+ &from_time_point_max);
+ EXPECT_EQ(0, gpr_time_cmp(gpr_inf_future, from_time_point_max));
}
} // namespace
} // namespace grpc
+
+int main(int argc, char** argv) {
+ ::testing::InitGoogleTest(&argc, argv);
+ return RUN_ALL_TESTS();
+}