proxygen
MockTime.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2015-present, Facebook, Inc.
3  * All rights reserved.
4  *
5  * This source code is licensed under the BSD-style license found in the
6  * LICENSE file in the root directory of this source tree. An additional grant
7  * of patent rights can be found in the PATENTS file in the same directory.
8  *
9  */
10 #pragma once
11 
12 #include <glog/logging.h>
14 
15 namespace proxygen {
16 
17 template <typename ClockType = std::chrono::steady_clock>
18 class MockTimeUtilGeneric : public TimeUtilGeneric<ClockType> {
19  public:
20 
21  void advance(std::chrono::milliseconds ms) {
22  t_ += ms;
23  }
24 
25  void setCurrentTime(std::chrono::time_point<ClockType> t) {
26  CHECK(t.time_since_epoch() > t_.time_since_epoch())
27  << "Time can not move backwards";
28  t_ = t;
29  }
30 
31  void verifyAndClear() {
32  }
33 
34  std::chrono::time_point<ClockType> now() const override {
35  return t_;
36  }
37 
38  private:
39  std::chrono::time_point<ClockType> t_;
40 };
41 
43 
44 }
std::chrono::time_point< ClockType > t_
Definition: MockTime.h:39
void setCurrentTime(std::chrono::time_point< ClockType > t)
Definition: MockTime.h:25
std::chrono::time_point< ClockType > now() const override
Definition: MockTime.h:34
void advance(std::chrono::milliseconds ms)
Definition: MockTime.h:21