38 #include <boost/filesystem.hpp> 39 #include <boost/thread.hpp> 40 #include <gtest/gtest.h> 44 int setenv(
const char *name,
const char *value,
int overwrite)
49 errno_t errcode = getenv_s(&envsize, NULL, 0, name);
50 if(errcode || envsize)
53 return _putenv_s(name, value);
57 void string_split(
const std::string &s, std::vector<std::string> &t,
const std::string &d)
59 size_t start = 0, end;
60 while ((end = s.find_first_of(d, start)) != std::string::npos)
63 t.push_back(s.substr(start, end-start));
67 t.push_back(s.substr(start));
76 getcwd(rr_buf,
sizeof(rr_buf));
77 setenv(
"ROS_PACKAGE_PATH", rr_buf, 1);
79 boost::filesystem::path temp_path = boost::filesystem::unique_path();
80 boost::filesystem::create_directories(temp_path);
81 g_rr_path = temp_path.string();
82 setenv(
"ROS_ROOT", g_rr_path.c_str(), 1);
87 rmdir(g_rr_path.c_str());
91 TEST(roslib, commandListNames)
96 std::vector<std::string> output_list;
98 ASSERT_EQ((
int)output_list.size(), 1);
99 ASSERT_STREQ(output_list[0].c_str(),
"roslib");
109 std::vector<std::string> output_list;
110 std::vector<std::string> name_path;
112 ASSERT_EQ((
int)output_list.size(), 1);
114 ASSERT_EQ((
int)name_path.size(), 2);
115 ASSERT_STREQ(name_path[0].c_str(),
"roslib");
124 std::vector<std::string> output_list;
126 ASSERT_EQ((
int)output_list.size(), 1);
127 ASSERT_STREQ(output_list[0].c_str(),
"roslib");
135 struct timespec ts = {0, 100000};
137 for(
int i=0;i<100;i++)
141 nanosleep(&ts, NULL);
143 boost::this_thread::sleep(boost::posix_time::milliseconds(1));
148 TEST(roslib, concurrent_access)
152 boost::thread t[size];
153 for(
int i=0;i<size; i++)
155 for(
int i=0;i<size; i++)
160 int main(
int argc,
char **argv)
162 testing::InitGoogleTest(&argc, argv);
163 return RUN_ALL_TESTS();
ROSLIB_DECL bool getAll(V_string &packages)
Gets a list of all packages. Returns false if it could not run the command.
void cleanup_env_vars(void)
ROSLIB_DECL std::string command(const std::string &cmd)
Runs a rospack command of the form 'rospack <cmd>', returning the output as a single string...
int main(int argc, char **argv)
TEST(roslib, commandListNames)
void string_split(const std::string &s, std::vector< std::string > &t, const std::string &d)