39 #include <gtest/gtest.h> 40 #include <boost/algorithm/string.hpp> 41 #include <boost/filesystem.hpp> 50 int ret = rp.
run(std::string(
"plugins --attrib=foo --top=precedence1 roslang"));
52 ret = rp.
run(std::string(
"find roslang"));
54 ret = rp.
run(std::string(
"list-names"));
56 std::vector<std::string> output_list;
59 boost::split(output_list, output, boost::is_any_of(
"\n"));
60 ASSERT_EQ((
int)output_list.size(), 4);
61 ret = rp.
run(std::string(
"list"));
65 boost::split(output_list, output, boost::is_any_of(
"\n"));
66 ASSERT_EQ((
int)output_list.size(), 4);
67 std::vector<std::string> path_name;
68 boost::split(path_name, output_list[0], boost::is_any_of(
" "));
69 ASSERT_EQ((
int)path_name.size(), 2);
76 int ret = rp.
run(std::string(
"plugins --attrib=foo --top=precedence1 roslang"));
78 ret = rp.
run(std::string(
"find roslang"));
80 ret = rp.
run(std::string(
"list-names"));
82 std::vector<std::string> output_list;
85 boost::split(output_list, output, boost::is_any_of(
"\n"));
86 ASSERT_EQ((
int)output_list.size(), 4);
87 ret = rp.
run(std::string(
"list"));
91 boost::split(output_list, output, boost::is_any_of(
"\n"));
92 ASSERT_EQ((
int)output_list.size(), 4);
93 std::vector<std::string> path_name;
94 boost::split(path_name, output_list[0], boost::is_any_of(
" "));
95 ASSERT_EQ((
int)path_name.size(), 2);
98 ret = rp2.
run(std::string(
"plugins --attrib=foo --top=precedence1 roslang"));
100 ret = rp2.run(std::string(
"find roslang"));
102 ret = rp2.run(std::string(
"list-names"));
105 output = rp2.getOutput();
107 boost::split(output_list, output, boost::is_any_of(
"\n"));
108 ASSERT_EQ((
int)output_list.size(), 4);
109 ret = rp2.run(std::string(
"list"));
111 output = rp2.getOutput();
113 boost::split(output_list, output, boost::is_any_of(
"\n"));
114 ASSERT_EQ((
int)output_list.size(), 4);
116 boost::split(path_name, output_list[0], boost::is_any_of(
" "));
117 ASSERT_EQ((
int)path_name.size(), 2);
122 std::string input =
"foo foo bar bat bar foobar batbar";
123 std::string truth =
"foo bar bat foobar batbar";
126 ASSERT_EQ(truth, output);
133 char* oldrpp = getenv(
"ROS_PACKAGE_PATH");
138 std::string rr = std::string(getcwd(buf,
sizeof(buf))) +
"/test2";
139 setenv(
"ROS_PACKAGE_PATH", rr.c_str(), 1);
140 std::vector<std::string> test_pkgs;
141 test_pkgs.push_back(
"precedence1");
142 test_pkgs.push_back(
"precedence2");
143 test_pkgs.push_back(
"precedence3");
144 test_pkgs.push_back(
"roslang");
146 int ret = rp.
run(std::string(
"list-names"));
148 std::vector<std::string> output_list;
151 boost::split(output_list, output, boost::is_any_of(
"\n"));
154 EXPECT_EQ(output_list.size(), test_pkgs.size());
155 for(std::vector<std::string>::const_iterator it = output_list.begin();
156 it != output_list.end();
160 for(std::vector<std::string>::const_iterator it2 = test_pkgs.begin();
161 it2 != test_pkgs.end();
174 rr = std::string(getcwd(buf,
sizeof(buf))) +
"/test3";
175 setenv(
"ROS_PACKAGE_PATH", rr.c_str(), 1);
177 test_pkgs.push_back(
"precedence1");
178 test_pkgs.push_back(
"precedence2");
179 test_pkgs.push_back(
"precedence3");
180 ret = rp.
run(std::string(
"list-names"));
185 boost::split(output_list, output, boost::is_any_of(
"\n"));
188 EXPECT_EQ(output_list.size(), test_pkgs.size());
189 for(std::vector<std::string>::const_iterator it = output_list.begin();
190 it != output_list.end();
194 for(std::vector<std::string>::const_iterator it2 = test_pkgs.begin();
195 it2 != test_pkgs.end();
208 rr = std::string(getcwd(buf,
sizeof(buf))) +
"/test_empty";
209 setenv(
"ROS_PACKAGE_PATH", rr.c_str(), 1);
210 ret = rp.
run(std::string(
"list-names"));
214 EXPECT_EQ(output, std::string());
217 setenv(
"ROS_PACKAGE_PATH", oldrpp, 1);
220 int main(
int argc,
char **argv)
227 std::string rr = std::string(getcwd(buf,
sizeof(buf))) +
"/test2";
228 setenv(
"ROS_PACKAGE_PATH", rr.c_str(), 1);
230 if(getcwd(path,
sizeof(path)))
232 boost::filesystem::path p(path);
234 std::string newpath = p.string();
235 char* oldpath = getenv(
"PATH");
237 newpath += std::string(
":") + oldpath;
238 setenv(
"PATH", newpath.c_str(), 1);
241 testing::InitGoogleTest(&argc, argv);
242 return RUN_ALL_TESTS();
void deduplicate_tokens(const std::string &instring, bool last, std::string &outstring)
int main(int argc, char **argv)
static const char * ROSSTACK_NAME
static const char * ROSPACK_NAME
int run(int argc, char **argv)
Run rospack with the given arguments. Call getOutput() to get the result.
std::string getOutput()
Get the output from the last successful run() call.
Backward compatibility API for librospack (DEPRECATED).