diff -Nru ros-roscpp-core-0.6.11/cpp_common/CHANGELOG.rst ros-roscpp-core-0.6.12/cpp_common/CHANGELOG.rst --- ros-roscpp-core-0.6.11/cpp_common/CHANGELOG.rst 2018-06-06 16:20:24.000000000 +0000 +++ ros-roscpp-core-0.6.12/cpp_common/CHANGELOG.rst 2019-03-05 00:06:24.000000000 +0000 @@ -2,6 +2,12 @@ Changelog for package cpp_common ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +0.6.12 (2019-03-04) +------------------- +* update the use of macros in platform.h (`#99 `_) +* avoid unnecessary memory allocation (std::string) (`#95 `_) +* fix bug in HAVE_CXXABI_H compiler check (`#89 `_) + 0.6.11 (2018-06-06) ------------------- diff -Nru ros-roscpp-core-0.6.11/cpp_common/CMakeLists.txt ros-roscpp-core-0.6.12/cpp_common/CMakeLists.txt --- ros-roscpp-core-0.6.11/cpp_common/CMakeLists.txt 2018-06-06 16:20:24.000000000 +0000 +++ ros-roscpp-core-0.6.12/cpp_common/CMakeLists.txt 2019-03-05 00:06:24.000000000 +0000 @@ -22,7 +22,7 @@ endif(HAVE_EXECINFO_H) # do we have demangle capability? # CHECK_INCLUDE_FILE doesn't work here for some reason -CHECK_CXX_SOURCE_COMPILES("#include\nintmain(intargc,char**argv){}" HAVE_CXXABI_H) +CHECK_CXX_SOURCE_COMPILES("#include\nint main(int argc,char**argv){}" HAVE_CXXABI_H) if(HAVE_CXXABI_H) add_definitions(-DHAVE_CXXABI_H=1) endif() diff -Nru ros-roscpp-core-0.6.11/cpp_common/include/ros/platform.h ros-roscpp-core-0.6.12/cpp_common/include/ros/platform.h --- ros-roscpp-core-0.6.11/cpp_common/include/ros/platform.h 2018-06-06 16:20:24.000000000 +0000 +++ ros-roscpp-core-0.6.12/cpp_common/include/ros/platform.h 2019-03-05 00:06:24.000000000 +0000 @@ -31,27 +31,10 @@ #define CPP_COMMON_PLATFORM_H_ /****************************************************************************** -* Includes -******************************************************************************/ - -#ifdef WIN32 - #ifdef _MSC_VER - #define WIN32_LEAN_AND_MEAN // slimmer compile times - #define _WINSOCKAPI_ // stops windows.h from including winsock.h (and lets us include winsock2.h) - #define NOMINMAX // windows c++ pollutes the environment like any factory - #endif - #include -#endif - - - -/****************************************************************************** * Cross Platform Functions ******************************************************************************/ -#ifndef _MSC_VER - #include // getenv -#endif +#include // getenv, _dupenv_s #include namespace ros { diff -Nru ros-roscpp-core-0.6.11/cpp_common/package.xml ros-roscpp-core-0.6.12/cpp_common/package.xml --- ros-roscpp-core-0.6.11/cpp_common/package.xml 2018-06-06 16:20:24.000000000 +0000 +++ ros-roscpp-core-0.6.12/cpp_common/package.xml 2019-03-05 00:06:24.000000000 +0000 @@ -1,6 +1,6 @@ cpp_common - 0.6.11 + 0.6.12 cpp_common contains C++ code for doing things that are not necessarily ROS related, but are useful for multiple packages. This includes things like diff -Nru ros-roscpp-core-0.6.11/cpp_common/src/header.cpp ros-roscpp-core-0.6.12/cpp_common/src/header.cpp --- ros-roscpp-core-0.6.11/cpp_common/src/header.cpp 2018-06-06 16:20:24.000000000 +0000 +++ ros-roscpp-core-0.6.12/cpp_common/src/header.cpp 2019-03-05 00:06:24.000000000 +0000 @@ -37,7 +37,7 @@ #include "console_bridge/console.h" #include - +#include #include #include @@ -76,6 +76,7 @@ bool Header::parse(uint8_t* buffer, uint32_t size, std::string& error_msg) { + std::string key_; uint8_t* buf = buffer; while (buf < buffer + size) { @@ -90,12 +91,12 @@ return false; } - std::string line((char*)buf, len); + boost::string_ref line((char*)buf, len); buf += len; //printf(":%s:\n", line.c_str()); - size_t eqpos = line.find_first_of("=", 0); + size_t eqpos = line.find_first_of("="); if (eqpos == string::npos) { error_msg = "Received an invalid TCPROS header. Each line must have an equals sign."; @@ -103,10 +104,12 @@ return false; } - string key = line.substr(0, eqpos); - string value = line.substr(eqpos+1); + boost::string_ref key_ref = line.substr(0, eqpos); + boost::string_ref value_ref = line.substr(eqpos+1); + + key_.assign(key_ref.data(), key_ref.length()); - (*read_map_)[key] = value; + (*read_map_)[key_].assign(value_ref.data(), value_ref.length()); } return true; diff -Nru ros-roscpp-core-0.6.11/debian/changelog ros-roscpp-core-0.6.12/debian/changelog --- ros-roscpp-core-0.6.11/debian/changelog 2018-07-17 13:03:26.000000000 +0000 +++ ros-roscpp-core-0.6.12/debian/changelog 2019-07-31 11:17:07.000000000 +0000 @@ -1,8 +1,12 @@ -ros-roscpp-core (0.6.11-2build1) cosmic; urgency=medium +ros-roscpp-core (0.6.12-1) unstable; urgency=medium - * No-change rebuild for boost soname change. + * New upstream version 0.6.12 + * Bump policy version (no changes) + * switch to debhelper-compat and debhelper 12 + * cleanup rules + * add Salsa CI - -- Matthias Klose Tue, 17 Jul 2018 13:03:26 +0000 + -- Jochen Sprickerhof Wed, 31 Jul 2019 13:17:07 +0200 ros-roscpp-core (0.6.11-2) unstable; urgency=medium diff -Nru ros-roscpp-core-0.6.11/debian/compat ros-roscpp-core-0.6.12/debian/compat --- ros-roscpp-core-0.6.11/debian/compat 2018-03-31 20:39:52.000000000 +0000 +++ ros-roscpp-core-0.6.12/debian/compat 1970-01-01 00:00:00.000000000 +0000 @@ -1 +0,0 @@ -11 diff -Nru ros-roscpp-core-0.6.11/debian/control ros-roscpp-core-0.6.12/debian/control --- ros-roscpp-core-0.6.11/debian/control 2018-06-21 19:01:45.000000000 +0000 +++ ros-roscpp-core-0.6.12/debian/control 2019-07-31 11:14:57.000000000 +0000 @@ -5,8 +5,8 @@ Leopold Palomo-Avellaneda Section: libs Priority: optional -Build-Depends: debhelper (>= 11), catkin, libboost-system-dev, libboost-thread-dev, libconsole-bridge-dev, libboost-date-time-dev, libgtest-dev -Standards-Version: 4.1.4 +Build-Depends: debhelper-compat (= 12), catkin, libboost-system-dev, libboost-thread-dev, libconsole-bridge-dev, libboost-date-time-dev, libgtest-dev +Standards-Version: 4.4.0 Vcs-Browser: https://salsa.debian.org/science-team/ros-roscpp-core Vcs-Git: https://salsa.debian.org/science-team/ros-roscpp-core.git Rules-Requires-Root: no diff -Nru ros-roscpp-core-0.6.11/debian/gitlab-ci.yml ros-roscpp-core-0.6.12/debian/gitlab-ci.yml --- ros-roscpp-core-0.6.11/debian/gitlab-ci.yml 1970-01-01 00:00:00.000000000 +0000 +++ ros-roscpp-core-0.6.12/debian/gitlab-ci.yml 2019-07-31 11:15:36.000000000 +0000 @@ -0,0 +1,3 @@ +include: + - https://salsa.debian.org/salsa-ci-team/pipeline/raw/master/salsa-ci.yml + - https://salsa.debian.org/salsa-ci-team/pipeline/raw/master/pipeline-jobs.yml diff -Nru ros-roscpp-core-0.6.11/debian/rules ros-roscpp-core-0.6.12/debian/rules --- ros-roscpp-core-0.6.11/debian/rules 2017-07-01 08:56:45.000000000 +0000 +++ ros-roscpp-core-0.6.12/debian/rules 2019-07-31 11:15:22.000000000 +0000 @@ -1,9 +1,4 @@ #!/usr/bin/make -f -DPKG_EXPORT_BUILDFLAGS = 1 -include /usr/share/dpkg/default.mk %: dh $@ --buildsystem=cmake - -get-orig-source: - uscan --verbose --force-download --repack --compress xz diff -Nru ros-roscpp-core-0.6.11/roscpp_core/package.xml ros-roscpp-core-0.6.12/roscpp_core/package.xml --- ros-roscpp-core-0.6.11/roscpp_core/package.xml 2018-06-06 16:20:24.000000000 +0000 +++ ros-roscpp-core-0.6.12/roscpp_core/package.xml 2019-03-05 00:06:24.000000000 +0000 @@ -1,6 +1,6 @@ roscpp_core - 0.6.11 + 0.6.12 Underlying data libraries for roscpp messages. diff -Nru ros-roscpp-core-0.6.11/roscpp_serialization/CHANGELOG.rst ros-roscpp-core-0.6.12/roscpp_serialization/CHANGELOG.rst --- ros-roscpp-core-0.6.11/roscpp_serialization/CHANGELOG.rst 2018-06-06 16:20:24.000000000 +0000 +++ ros-roscpp-core-0.6.12/roscpp_serialization/CHANGELOG.rst 2019-03-05 00:06:24.000000000 +0000 @@ -2,6 +2,10 @@ Changelog for package roscpp_serialization ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +0.6.12 (2019-03-04) +------------------- +* fix GCC8 class-memaccess in VectorSerializer (`#102 `_) + 0.6.11 (2018-06-06) ------------------- * replace reinterpret_cast with memcpy to avoid undefined behaviour/alignment issues (`#83 `_) diff -Nru ros-roscpp-core-0.6.11/roscpp_serialization/include/ros/serialization.h ros-roscpp-core-0.6.12/roscpp_serialization/include/ros/serialization.h --- ros-roscpp-core-0.6.11/roscpp_serialization/include/ros/serialization.h 2018-06-06 16:20:24.000000000 +0000 +++ ros-roscpp-core-0.6.12/roscpp_serialization/include/ros/serialization.h 2019-03-05 00:06:24.000000000 +0000 @@ -408,7 +408,7 @@ if (len > 0) { const uint32_t data_len = (uint32_t)sizeof(T) * len; - memcpy(&v.front(), stream.advance(data_len), data_len); + memcpy(static_cast(&v.front()), stream.advance(data_len), data_len); } } diff -Nru ros-roscpp-core-0.6.11/roscpp_serialization/package.xml ros-roscpp-core-0.6.12/roscpp_serialization/package.xml --- ros-roscpp-core-0.6.11/roscpp_serialization/package.xml 2018-06-06 16:20:24.000000000 +0000 +++ ros-roscpp-core-0.6.12/roscpp_serialization/package.xml 2019-03-05 00:06:24.000000000 +0000 @@ -1,6 +1,6 @@ roscpp_serialization - 0.6.11 + 0.6.12 roscpp_serialization contains the code for serialization as described in MessagesSerializationAndAdaptingTypes. diff -Nru ros-roscpp-core-0.6.11/roscpp_traits/CHANGELOG.rst ros-roscpp-core-0.6.12/roscpp_traits/CHANGELOG.rst --- ros-roscpp-core-0.6.11/roscpp_traits/CHANGELOG.rst 2018-06-06 16:20:24.000000000 +0000 +++ ros-roscpp-core-0.6.12/roscpp_traits/CHANGELOG.rst 2019-03-05 00:06:24.000000000 +0000 @@ -2,6 +2,9 @@ Changelog for package roscpp_traits ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +0.6.12 (2019-03-04) +------------------- + 0.6.11 (2018-06-06) ------------------- diff -Nru ros-roscpp-core-0.6.11/roscpp_traits/package.xml ros-roscpp-core-0.6.12/roscpp_traits/package.xml --- ros-roscpp-core-0.6.11/roscpp_traits/package.xml 2018-06-06 16:20:24.000000000 +0000 +++ ros-roscpp-core-0.6.12/roscpp_traits/package.xml 2019-03-05 00:06:24.000000000 +0000 @@ -1,6 +1,6 @@ roscpp_traits - 0.6.11 + 0.6.12 roscpp_traits contains the message traits code as described in MessagesTraits. diff -Nru ros-roscpp-core-0.6.11/rostime/CHANGELOG.rst ros-roscpp-core-0.6.12/rostime/CHANGELOG.rst --- ros-roscpp-core-0.6.11/rostime/CHANGELOG.rst 2018-06-06 16:20:24.000000000 +0000 +++ ros-roscpp-core-0.6.12/rostime/CHANGELOG.rst 2019-03-05 00:06:24.000000000 +0000 @@ -2,6 +2,16 @@ Changelog for package rostime ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +0.6.12 (2019-03-04) +------------------- +* use std::numeric_limits instead of * _MAX macros for range checking (`#103 `_) +* use std::this_thread::sleep_for instead of WaitableTimer (`#101 `_) +* include windows.h in time.cpp (`#100 `_) +* fix duration bug and add tests. (`#98 `_) +* fix for Duration::fromSec() which had rounding issues (`#93 `_) +* fix bug in HAVE_CXXABI_H compiler check (`#89 `_) +* add ROSTIME_DECL storage-class attribute (`#90 `_) + 0.6.11 (2018-06-06) ------------------- * argument to boost microseconds must be integral for Boost 1.67 and newer compatibility (`#79 `_) diff -Nru ros-roscpp-core-0.6.11/rostime/include/ros/duration.h ros-roscpp-core-0.6.12/rostime/include/ros/duration.h --- ros-roscpp-core-0.6.11/rostime/include/ros/duration.h 2018-06-06 16:20:24.000000000 +0000 +++ ros-roscpp-core-0.6.12/rostime/include/ros/duration.h 2019-03-05 00:06:24.000000000 +0000 @@ -153,8 +153,8 @@ bool sleep() const; }; -std::ostream &operator <<(std::ostream &os, const Duration &rhs); -std::ostream &operator <<(std::ostream &os, const WallDuration &rhs); +ROSTIME_DECL std::ostream &operator <<(std::ostream &os, const Duration &rhs); +ROSTIME_DECL std::ostream &operator <<(std::ostream &os, const WallDuration &rhs); } diff -Nru ros-roscpp-core-0.6.11/rostime/include/ros/impl/duration.h ros-roscpp-core-0.6.12/rostime/include/ros/impl/duration.h --- ros-roscpp-core-0.6.11/rostime/include/ros/impl/duration.h 2018-06-06 16:20:24.000000000 +0000 +++ ros-roscpp-core-0.6.12/rostime/include/ros/impl/duration.h 2019-03-05 00:06:24.000000000 +0000 @@ -37,6 +37,7 @@ #include #include #include +#include namespace ros { // @@ -53,21 +54,27 @@ T& DurationBase::fromSec(double d) { int64_t sec64 = (int64_t)floor(d); - if (sec64 < INT_MIN || sec64 > INT_MAX) + if (sec64 < std::numeric_limits::min() || sec64 > std::numeric_limits::max()) throw std::runtime_error("Duration is out of dual 32-bit range"); sec = (int32_t)sec64; - nsec = (int32_t)(nearbyint((d - (double)sec)*1000000000)); + nsec = (int32_t)boost::math::round((d - sec) * 1e9); + int32_t rollover = nsec / 1000000000ul; + sec += rollover; + nsec %= 1000000000ul; return *static_cast(this); } template T& DurationBase::fromNSec(int64_t t) { - int64_t sec64 = t / 1000000000; - if (sec64 < INT_MIN || sec64 > INT_MAX) + int64_t sec64 = t / 1000000000LL; + if (sec64 < std::numeric_limits::min() || sec64 > std::numeric_limits::max()) throw std::runtime_error("Duration is out of dual 32-bit range"); sec = (int32_t)sec64; - nsec = (int32_t)(t % 1000000000); + nsec = (int32_t)(t % 1000000000LL); + + normalizeSecNSecSigned(sec, nsec); + return *static_cast(this); } diff -Nru ros-roscpp-core-0.6.11/rostime/include/ros/time.h ros-roscpp-core-0.6.12/rostime/include/ros/time.h --- ros-roscpp-core-0.6.11/rostime/include/ros/time.h 2018-06-06 16:20:24.000000000 +0000 +++ ros-roscpp-core-0.6.12/rostime/include/ros/time.h 2019-03-05 00:06:24.000000000 +0000 @@ -95,7 +95,7 @@ }; /** - * @brief Thrown if windoze high perf. timestamping is unavailable. + * @brief Thrown if windows high perf. timestamping is unavailable. * * @sa getWallTime */ @@ -153,7 +153,7 @@ double toSec() const { return (double)sec + 1e-9*(double)nsec; }; T& fromSec(double t) { int64_t sec64 = (int64_t)floor(t); - if (sec64 < 0 || sec64 > UINT_MAX) + if (sec64 < 0 || sec64 > std::numeric_limits::max()) throw std::runtime_error("Time is out of dual 32-bit range"); sec = (uint32_t)sec64; nsec = (uint32_t)boost::math::round((t-sec) * 1e9); diff -Nru ros-roscpp-core-0.6.11/rostime/package.xml ros-roscpp-core-0.6.12/rostime/package.xml --- ros-roscpp-core-0.6.11/rostime/package.xml 2018-06-06 16:20:24.000000000 +0000 +++ ros-roscpp-core-0.6.12/rostime/package.xml 2019-03-05 00:06:24.000000000 +0000 @@ -1,6 +1,6 @@ rostime - 0.6.11 + 0.6.12 Time and Duration implementations for C++ libraries, including roscpp. diff -Nru ros-roscpp-core-0.6.11/rostime/src/duration.cpp ros-roscpp-core-0.6.12/rostime/src/duration.cpp --- ros-roscpp-core-0.6.11/rostime/src/duration.cpp 2018-06-06 16:20:24.000000000 +0000 +++ ros-roscpp-core-0.6.12/rostime/src/duration.cpp 2019-03-05 00:06:24.000000000 +0000 @@ -54,7 +54,7 @@ --sec_part; } - if (sec_part < INT_MIN || sec_part > INT_MAX) + if (sec_part < std::numeric_limits::min() || sec_part > std::numeric_limits::max()) throw std::runtime_error("Duration is out of dual 32-bit range"); sec = sec_part; diff -Nru ros-roscpp-core-0.6.11/rostime/src/time.cpp ros-roscpp-core-0.6.12/rostime/src/time.cpp --- ros-roscpp-core-0.6.11/rostime/src/time.cpp 2018-06-06 16:20:24.000000000 +0000 +++ ros-roscpp-core-0.6.12/rostime/src/time.cpp 2019-03-05 00:06:24.000000000 +0000 @@ -42,8 +42,8 @@ #include #include #include -#include #include +#include // time related includes for macOS #if defined(__APPLE__) @@ -51,6 +51,12 @@ #include #endif // defined(__APPLE__) +#ifdef _WINDOWS +#include +#include +#include +#endif + #include #include #include @@ -101,14 +107,14 @@ #if HAS_CLOCK_GETTIME timespec start; clock_gettime(CLOCK_REALTIME, &start); - if (start.tv_sec < 0 || start.tv_sec > UINT_MAX) + if (start.tv_sec < 0 || start.tv_sec > std::numeric_limits::max()) throw std::runtime_error("Timespec is out of dual 32-bit range"); sec = start.tv_sec; nsec = start.tv_nsec; #else struct timeval timeofday; gettimeofday(&timeofday,NULL); - if (timeofday.tv_sec < 0 || timeofday.tv_sec > UINT_MAX) + if (timeofday.tv_sec < 0 || timeofday.tv_sec > std::numeric_limits::max()) throw std::runtime_error("Timeofday is out of dual signed 32-bit range"); sec = timeofday.tv_sec; nsec = timeofday.tv_usec * 1000; @@ -148,7 +154,7 @@ start_li.QuadPart -= 116444736000000000ULL; #endif int64_t start_sec64 = start_li.QuadPart / 10000000; // 100-ns units - if (start_sec64 < 0 || start_sec64 > UINT_MAX) + if (start_sec64 < 0 || start_sec64 > std::numeric_limits::max()) throw std::runtime_error("SystemTime is out of dual 32-bit range"); start_sec = (uint32_t)start_sec64; start_nsec = (start_li.LowPart % 10000000) * 100; @@ -228,27 +234,7 @@ int ros_nanosleep(const uint32_t &sec, const uint32_t &nsec) { #if defined(WIN32) - HANDLE timer = NULL; - LARGE_INTEGER sleepTime; - sleepTime.QuadPart = - - static_cast(sec)*10000000LL - - static_cast(nsec) / 100LL; - - timer = CreateWaitableTimer(NULL, TRUE, NULL); - if (timer == NULL) - { - return -1; - } - - if (!SetWaitableTimer (timer, &sleepTime, 0, NULL, NULL, 0)) - { - return -1; - } - - if (WaitForSingleObject (timer, INFINITE) != WAIT_OBJECT_0) - { - return -1; - } + std::this_thread::sleep_for(std::chrono::nanoseconds(static_cast(sec * 1e9 + nsec))); return 0; #else timespec req = { sec, nsec }; @@ -376,7 +362,7 @@ { Time t; int64_t sec64 = d.total_seconds(); - if (sec64 < 0 || sec64 > UINT_MAX) + if (sec64 < 0 || sec64 > std::numeric_limits::max()) throw std::runtime_error("time_duration is out of dual 32-bit range"); t.sec = (uint32_t)sec64; #if defined(BOOST_DATE_TIME_HAS_NANOSECONDS) @@ -552,7 +538,7 @@ uint64_t nsec_part = nsec % 1000000000UL; uint64_t sec_part = nsec / 1000000000UL; - if (sec + sec_part > UINT_MAX) + if (sec + sec_part > std::numeric_limits::max()) throw std::runtime_error("Time is out of dual 32-bit range"); sec += sec_part; @@ -580,7 +566,7 @@ --sec_part; } - if (sec_part < 0 || sec_part > UINT_MAX) + if (sec_part < 0 || sec_part > std::numeric_limits::max()) throw std::runtime_error("Time is out of dual 32-bit range"); sec = sec_part; diff -Nru ros-roscpp-core-0.6.11/rostime/test/duration.cpp ros-roscpp-core-0.6.12/rostime/test/duration.cpp --- ros-roscpp-core-0.6.11/rostime/test/duration.cpp 2018-06-06 16:20:24.000000000 +0000 +++ ros-roscpp-core-0.6.12/rostime/test/duration.cpp 2019-03-05 00:06:24.000000000 +0000 @@ -128,6 +128,39 @@ EXPECT_EQ(2147483647999999998, d7.toNSec()); } +TEST(Duration, rounding) +{ + ros::Time::init(); + + Duration d1(49.0000000004); + EXPECT_EQ(49, d1.sec); + EXPECT_EQ(0, d1.nsec); + Duration d2(-49.0000000004); + EXPECT_EQ(-49, d2.sec); + EXPECT_EQ(0, d2.nsec); + + Duration d3(49.0000000006); + EXPECT_EQ(49, d3.sec); + EXPECT_EQ(1, d3.nsec); + Duration d4(-49.0000000006); + EXPECT_EQ(-50, d4.sec); + EXPECT_EQ(999999999, d4.nsec); + + Duration d5(49.9999999994); + EXPECT_EQ(49, d5.sec); + EXPECT_EQ(999999999, d5.nsec); + Duration d6(-49.9999999994); + EXPECT_EQ(-50, d6.sec); + EXPECT_EQ(1, d6.nsec); + + Duration d7(49.9999999996); + EXPECT_EQ(50, d7.sec); + EXPECT_EQ(0, d7.nsec); + Duration d8(-49.9999999996); + EXPECT_EQ(-50, d8.sec); + EXPECT_EQ(0, d8.nsec); +} + int main(int argc, char **argv){ testing::InitGoogleTest(&argc, argv); return RUN_ALL_TESTS(); diff -Nru ros-roscpp-core-0.6.11/rostime/test/time.cpp ros-roscpp-core-0.6.12/rostime/test/time.cpp --- ros-roscpp-core-0.6.11/rostime/test/time.cpp 2018-06-06 16:20:24.000000000 +0000 +++ ros-roscpp-core-0.6.12/rostime/test/time.cpp 2019-03-05 00:06:24.000000000 +0000 @@ -32,7 +32,9 @@ #include #include #include +#ifndef _WIN32 #include +#endif #include @@ -45,9 +47,13 @@ void seed_rand() { //Seed random number generator with current microseond count +#ifndef _WIN32 timeval temp_time_struct; gettimeofday(&temp_time_struct,NULL); srand(temp_time_struct.tv_usec); +#else + srand(time(nullptr)); +#endif }; void generate_rand_times(uint32_t range, uint64_t runs, std::vector& values1, std::vector& values2) @@ -409,6 +415,21 @@ EXPECT_EQ(ros::Duration(-0.5), ros::Duration(0, -500000000LL)); } +TEST(Duration, FromNSec) +{ + ros::Duration t; + t.fromNSec(-500000000LL); + EXPECT_EQ(ros::Duration(-0.5), t); + + t.fromNSec(-1500000000LL); + EXPECT_EQ(ros::Duration(-1.5), t); + + t.fromNSec(500000000LL); + EXPECT_EQ(ros::Duration(0.5), t); + + t.fromNSec(1500000000LL); + EXPECT_EQ(ros::Duration(1.5), t); +} TEST(Duration, OperatorPlus) { @@ -442,6 +463,13 @@ } + ros::Time t1(1.1); + ros::Time t2(1.3); + ros::Duration time_diff = t1 - t2; //=-0.2 + + EXPECT_NEAR(time_diff.toSec(), -0.2, epsilon); + EXPECT_LE(time_diff, ros::Duration(-0.19)); + EXPECT_GE(time_diff, ros::Duration(-0.21)); } TEST(Duration, OperatorTimes) @@ -509,8 +537,11 @@ TEST(Duration, sleepWithSignal) { +#ifndef _WIN32 signal(SIGALRM, alarmHandler); alarm(1); +#endif + Time start = Time::now(); Duration d(2.0); bool rc = d.sleep();