test
realtime_clock_tests.cpp
Go to the documentation of this file.
1
/*
2
* Copyright (c) 2019, Open Source Robotics Foundation, Inc.
3
* All rights reserved.
4
*
5
* Redistribution and use in source and binary forms, with or without
6
* modification, are permitted provided that the following conditions are met:
7
*
8
* * Redistributions of source code must retain the above copyright
9
* notice, this list of conditions and the following disclaimer.
10
* * Redistributions in binary form must reproduce the above copyright
11
* notice, this list of conditions and the following disclaimer in the
12
* documentation and/or other materials provided with the distribution.
13
* * Neither the name of the Willow Garage, Inc. nor the names of its
14
* contributors may be used to endorse or promote products derived from
15
* this software without specific prior written permission.
16
*
17
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
21
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27
* POSSIBILITY OF SUCH DAMAGE.
28
*/
29
30
#include <gmock/gmock.h>
31
#include <
realtime_tools/realtime_clock.h
>
32
#include <chrono>
33
#include <thread>
34
35
using
realtime_tools::RealtimeClock
;
36
37
TEST
(
RealtimeClock
, get_system_time)
38
{
39
const
int
ATTEMPTS
= 10;
40
const
std::chrono::milliseconds
DELAY
(1);
41
42
RealtimeClock
rt_clock;
43
// Wait for time to be available
44
ros::Time
last_rt_time;
45
for
(
int
i = 0; i <
ATTEMPTS
&&
ros::Time
() == last_rt_time; ++i)
46
{
47
std::this_thread::sleep_for(
DELAY
);
48
last_rt_time = rt_clock.
getSystemTime
(
ros::Time
());
49
}
50
ASSERT_NE(
ros::Time
(), last_rt_time);
51
52
// This test assumes system time will not jump backwards during it
53
EXPECT_GT(rt_clock.
getSystemTime
(last_rt_time), last_rt_time);
54
}
55
56
int
main
(
int
argc,
char
** argv) {
57
::testing::InitGoogleTest(&argc, argv);
58
ros::Time::init
();
59
return
RUN_ALL_TESTS();
60
}
ATTEMPTS
const size_t ATTEMPTS
Definition:
realtime_server_goal_handle_tests.cpp:44
main
int main(int argc, char **argv)
Definition:
realtime_clock_tests.cpp:56
realtime_tools::RealtimeClock
Definition:
realtime_clock.h:50
realtime_clock.h
DELAY
const std::chrono::milliseconds DELAY(250)
ros::Time::init
static void init()
realtime_tools::RealtimeClock::getSystemTime
ros::Time getSystemTime(const ros::Time &realtime_time)
Definition:
realtime_clock.cpp:61
ros::Time
TEST
TEST(RealtimeClock, get_system_time)
Definition:
realtime_clock_tests.cpp:37
realtime_tools
Author(s): Stuart Glaser
autogenerated on Mon Jan 8 2024 03:20:12