30 #include <gtest/gtest.h> 57 EXPECT_NO_THROW(d1.
fromSec(-2147483648.0));
58 EXPECT_NO_THROW(d2.
fromSec(-2147483647.999999));
59 EXPECT_NO_THROW(d3.
fromSec(2147483647.0));
60 EXPECT_NO_THROW(d4.
fromSec(2147483647.999999));
63 EXPECT_THROW(d1.
fromSec(2147483648.0), std::runtime_error);
64 EXPECT_THROW(d2.
fromSec(6442450943.0), std::runtime_error);
65 EXPECT_THROW(d3.
fromSec(-2147483648.001), std::runtime_error);
66 EXPECT_THROW(d4.
fromSec(-6442450943.0), std::runtime_error);
75 EXPECT_NO_THROW(d1.
fromNSec(-2147483648000000000));
76 EXPECT_NO_THROW(d2.
fromNSec(-2147483647999999999));
77 EXPECT_NO_THROW(d3.
fromNSec(2147483647000000000));
78 EXPECT_NO_THROW(d4.
fromNSec(2147483647999999999));
81 EXPECT_THROW(d1.
fromSec(2147483648000000000), std::runtime_error);
82 EXPECT_THROW(d2.
fromSec(4294967296000000000), std::runtime_error);
83 EXPECT_THROW(d3.
fromSec(-2147483648000000001), std::runtime_error);
84 EXPECT_THROW(d4.
fromSec(-6442450943000000000), std::runtime_error);
93 EXPECT_THROW(d1 + d2, std::runtime_error);
97 EXPECT_THROW(d3 - d4, std::runtime_error);
98 EXPECT_THROW(d4 - d3, std::runtime_error);
103 EXPECT_NO_THROW(d7 = d5 + d6);
104 EXPECT_EQ(-2147483648000000000, d7.
toNSec());
114 EXPECT_NO_THROW(d3 = -d1);
115 EXPECT_EQ(-2147483647000000000, d3.
toNSec());
116 EXPECT_NO_THROW(d3 = -d2);
117 EXPECT_EQ(-2147483647999999999, d3.
toNSec());
120 Duration d5(-2147483648, 999999999);
123 EXPECT_NO_THROW(d7 = -d4);
124 EXPECT_EQ(2147483647000000000, d7.
toNSec());
125 EXPECT_NO_THROW(d7 = -d5);
126 EXPECT_EQ(2147483647000000001, d7.
toNSec());
127 EXPECT_NO_THROW(d7 = -d6);
128 EXPECT_EQ(2147483647999999998, d7.
toNSec());
136 EXPECT_EQ(49, d1.
sec);
137 EXPECT_EQ(0, d1.
nsec);
139 EXPECT_EQ(-49, d2.
sec);
140 EXPECT_EQ(0, d2.
nsec);
143 EXPECT_EQ(49, d3.
sec);
144 EXPECT_EQ(1, d3.
nsec);
146 EXPECT_EQ(-50, d4.
sec);
147 EXPECT_EQ(999999999, d4.
nsec);
150 EXPECT_EQ(49, d5.
sec);
151 EXPECT_EQ(999999999, d5.
nsec);
153 EXPECT_EQ(-50, d6.
sec);
154 EXPECT_EQ(1, d6.
nsec);
157 EXPECT_EQ(50, d7.
sec);
158 EXPECT_EQ(0, d7.
nsec);
160 EXPECT_EQ(-50, d8.
sec);
161 EXPECT_EQ(0, d8.
nsec);
164 int main(
int argc,
char **argv){
165 testing::InitGoogleTest(&argc, argv);
166 return RUN_ALL_TESTS();
Time representation. May either represent wall clock time or ROS clock time.
TEST(Duration, sleepWithSimTime)
bool sleep() const
sleep for the amount of time specified by this Duration. If a signal interrupts the sleep...
static void setNow(const Time &new_now)
int main(int argc, char **argv)
Duration representation for use with the Time class.
static Time now()
Retrieve the current time. If ROS clock time is in use, this returns the time according to the ROS cl...