#ifndef RTABMAP_CORELIB_TEST_TESTUTILS_H_ #define RTABMAP_CORELIB_TEST_TESTUTILS_H_ #include #include #ifdef _WIN32 #include #else #include #endif namespace rtabmap { namespace test { // Portable PID. MSVC has _getpid() in ; POSIX has getpid() in // . Tests typically use this to disambiguate temp file names // across parallel runs. inline int getPid() { #ifdef _WIN32 return _getpid(); #else return ::getpid(); #endif } // Portable replacement for hardcoded "/tmp/". /tmp doesn't exist on // Windows so any test that wrote there failed to open the file. This honors // TEMP/TMP on Windows and TMPDIR on POSIX, with an OS-appropriate fallback. // Forward slash is accepted by Win32 APIs so we don't bother converting. inline std::string tempPath(const std::string & name) { #ifdef _WIN32 const char * dir = std::getenv("TEMP"); if(!dir) dir = std::getenv("TMP"); if(!dir) dir = "C:/Temp"; #else const char * dir = std::getenv("TMPDIR"); if(!dir) dir = "/tmp"; #endif return std::string(dir) + "/" + name; } } // namespace test } // namespace rtabmap #endif // RTABMAP_CORELIB_TEST_TESTUTILS_H_