proxygen
ChronoTest.cpp
Go to the documentation of this file.
1 /*
2  * Copyright 2017-present Facebook, Inc.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #include <folly/Chrono.h>
19 
20 using namespace std::chrono;
21 using namespace folly::chrono;
22 
23 namespace {
24 
25 class ChronoTest : public testing::Test {};
26 } // namespace
27 
28 TEST_F(ChronoTest, ceil_duration) {
29  EXPECT_EQ(seconds(7), ceil<seconds>(seconds(7)));
30  EXPECT_EQ(seconds(7), ceil<seconds>(milliseconds(7000)));
31  EXPECT_EQ(seconds(7), ceil<seconds>(milliseconds(6200)));
32 }
33 
34 TEST_F(ChronoTest, ceil_time_point) {
35  auto const point = steady_clock::time_point{};
36  EXPECT_EQ(point + seconds(7), ceil<seconds>(point + seconds(7)));
37  EXPECT_EQ(point + seconds(7), ceil<seconds>(point + milliseconds(7000)));
38  EXPECT_EQ(point + seconds(7), ceil<seconds>(point + milliseconds(6200)));
39 }
40 
41 TEST_F(ChronoTest, floor_duration) {
42  EXPECT_EQ(seconds(7), floor<seconds>(seconds(7)));
43  EXPECT_EQ(seconds(7), floor<seconds>(milliseconds(7000)));
44  EXPECT_EQ(seconds(7), floor<seconds>(milliseconds(7800)));
45 }
46 
47 TEST_F(ChronoTest, floor_time_point) {
48  auto const point = steady_clock::time_point{};
49  EXPECT_EQ(point + seconds(7), floor<seconds>(point + seconds(7)));
50  EXPECT_EQ(point + seconds(7), floor<seconds>(point + milliseconds(7000)));
51  EXPECT_EQ(point + seconds(7), floor<seconds>(point + milliseconds(7800)));
52 }
53 
54 TEST_F(ChronoTest, round_duration) {
55  EXPECT_EQ(seconds(7), round<seconds>(seconds(7)));
56  EXPECT_EQ(seconds(6), round<seconds>(milliseconds(6200)));
57  EXPECT_EQ(seconds(6), round<seconds>(milliseconds(6500)));
58  EXPECT_EQ(seconds(7), round<seconds>(milliseconds(6800)));
59  EXPECT_EQ(seconds(7), round<seconds>(milliseconds(7000)));
60  EXPECT_EQ(seconds(7), round<seconds>(milliseconds(7200)));
61  EXPECT_EQ(seconds(8), round<seconds>(milliseconds(7500)));
62  EXPECT_EQ(seconds(8), round<seconds>(milliseconds(7800)));
63 }
64 
65 TEST_F(ChronoTest, round_time_point) {
66  auto const point = steady_clock::time_point{};
67  EXPECT_EQ(point + seconds(7), round<seconds>(point + seconds(7)));
68  EXPECT_EQ(point + seconds(6), round<seconds>(point + milliseconds(6200)));
69  EXPECT_EQ(point + seconds(6), round<seconds>(point + milliseconds(6500)));
70  EXPECT_EQ(point + seconds(7), round<seconds>(point + milliseconds(6800)));
71  EXPECT_EQ(point + seconds(7), round<seconds>(point + milliseconds(7000)));
72  EXPECT_EQ(point + seconds(7), round<seconds>(point + milliseconds(7200)));
73  EXPECT_EQ(point + seconds(8), round<seconds>(point + milliseconds(7500)));
74  EXPECT_EQ(point + seconds(8), round<seconds>(point + milliseconds(7800)));
75 }
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
TEST_F(ChronoTest, ceil_duration)
Definition: ChronoTest.cpp:28