31 | 31 |
#include <string>
|
32 | 32 |
#include <vector>
|
33 | 33 |
#include <stdlib.h>
|
|
34 |
#ifndef _WIN32
|
34 | 35 |
#include <unistd.h>
|
|
36 |
#endif
|
|
37 |
#include <boost/filesystem.hpp>
|
35 | 38 |
#include <boost/thread.hpp>
|
36 | 39 |
#include <gtest/gtest.h>
|
37 | 40 |
#include "ros/package.h"
|
|
41 |
|
|
42 |
#ifdef _WIN32
|
|
43 |
int setenv(const char *name, const char *value, int overwrite)
|
|
44 |
{
|
|
45 |
if(!overwrite)
|
|
46 |
{
|
|
47 |
size_t envsize = 0;
|
|
48 |
errno_t errcode = getenv_s(&envsize, NULL, 0, name);
|
|
49 |
if(errcode || envsize)
|
|
50 |
return errcode;
|
|
51 |
}
|
|
52 |
return _putenv_s(name, value);
|
|
53 |
}
|
|
54 |
#endif
|
38 | 55 |
|
39 | 56 |
void string_split(const std::string &s, std::vector<std::string> &t, const std::string &d)
|
40 | 57 |
{ t.clear();
|
|
49 | 66 |
t.push_back(s.substr(start));
|
50 | 67 |
}
|
51 | 68 |
|
52 | |
char g_rr_buf[1024];
|
|
69 |
std::string g_rr_path;
|
53 | 70 |
void set_env_vars(void)
|
54 | 71 |
{
|
55 | 72 |
// Point ROS_PACKAGE_PATH at the roslib directory, and point
|
56 | 73 |
// ROS_ROOT into an empty directory.
|
57 | |
getcwd(g_rr_buf, sizeof(g_rr_buf));
|
58 | |
setenv("ROS_PACKAGE_PATH", g_rr_buf, 1);
|
59 | |
strncpy(g_rr_buf+strlen(g_rr_buf), "/tmp.XXXXXX", sizeof(g_rr_buf)-strlen(g_rr_buf)-1);
|
60 | |
g_rr_buf[sizeof(g_rr_buf)-1] = '\0';
|
61 | |
mkdtemp(g_rr_buf);
|
62 | |
setenv("ROS_ROOT", g_rr_buf, 1);
|
|
74 |
char rr_buf[1024];
|
|
75 |
getcwd(rr_buf, sizeof(rr_buf));
|
|
76 |
setenv("ROS_PACKAGE_PATH", rr_buf, 1);
|
|
77 |
|
|
78 |
boost::filesystem::path temp_path = boost::filesystem::unique_path();
|
|
79 |
boost::filesystem::create_directories(temp_path);
|
|
80 |
g_rr_path = temp_path.string();
|
|
81 |
setenv("ROS_ROOT", g_rr_path.c_str(), 1);
|
63 | 82 |
}
|
64 | 83 |
void cleanup_env_vars(void)
|
65 | 84 |
{
|
66 | 85 |
// Remove the empty directory that we created in set_env_vars().
|
67 | |
rmdir(g_rr_buf);
|
68 | |
memset(g_rr_buf, 0, sizeof(g_rr_buf));
|
|
86 |
rmdir(g_rr_path.c_str());
|
|
87 |
g_rr_path.clear();
|
69 | 88 |
}
|
70 | 89 |
|
71 | 90 |
TEST(roslib, commandListNames)
|
|
117 | 136 |
for(int i=0;i<100;i++)
|
118 | 137 |
{
|
119 | 138 |
output = ros::package::command("plugins --attrib=foo roslib");
|
|
139 |
#ifndef _WIN32
|
120 | 140 |
nanosleep(&ts, NULL);
|
|
141 |
#else
|
|
142 |
boost::this_thread::sleep(boost::posix_time::milliseconds(1));
|
|
143 |
#endif
|
121 | 144 |
}
|
122 | 145 |
}
|
123 | 146 |
|