17 #include <gtest/gtest.h> 21 #include <boost/date_time/posix_time/posix_time_types.hpp> 27 TEST(DeviceTimeOriginTest, testEstimateOriginByAverage)
29 const boost::posix_time::time_duration delay = boost::posix_time::milliseconds(1);
30 const boost::posix_time::ptime time_req = boost::posix_time::microsec_clock::universal_time();
31 const boost::posix_time::ptime time_res = time_req + delay;
32 const uint64_t device_timestamp = 12345 * 1e3;
35 time_req, time_res, device_timestamp);
37 time_req - boost::posix_time::milliseconds(device_timestamp) + delay / 2);
39 ASSERT_EQ(actual, expected);
42 TEST(DeviceTimeOriginTest, testEstimateOrigin)
44 const boost::posix_time::time_duration delay = boost::posix_time::milliseconds(1);
45 const boost::posix_time::ptime time_req = boost::posix_time::microsec_clock::universal_time();
46 const boost::posix_time::ptime time_res = time_req + delay;
47 const uint64_t device_timestamp = 12345 * 1e3;
53 time_req - boost::posix_time::milliseconds(device_timestamp) + delay / 2);
56 ASSERT_EQ(actual, expected);
59 TEST(DeviceTimeOriginTest, testDetectTimeJump)
72 last_origin_not_init, last_origin_not_init +
ros::Duration(1.01), 1.0));
76 int main(
int argc,
char** argv)
78 testing::InitGoogleTest(&argc, argv);
80 return RUN_ALL_TESTS();
TEST(DeviceTimeOriginTest, testEstimateOriginByAverage)
ros::Time estimateOriginByAverage(const boost::posix_time::ptime &time_request, const boost::posix_time::ptime &time_response, const uint64_t &device_timestamp)
bool detectTimeJump(const ros::Time &last_device_time_origin, const ros::Time ¤t_device_time_origin, const double allowed_device_time_origin_diff)
int main(int argc, char **argv)
ros::Time estimateOrigin(const boost::posix_time::ptime &time_response, const uint64_t &device_timestamp, const ros::Duration &communication_delay, ros::Time &time_at_device_timestamp)
static Time fromBoost(const boost::posix_time::ptime &t)