00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032 #include <stdexcept>
00033 #include <string>
00034 #include <vector>
00035 #include <stdlib.h>
00036 #include <unistd.h>
00037 #include <stdio.h>
00038 #include <time.h>
00039 #include <gtest/gtest.h>
00040 #include <boost/thread/thread.hpp>
00041 #include "rospack/rospack.h"
00042
00044
00045 TEST(rospack, lflags_embedded_newline)
00046 {
00047 rospack::ROSPack rp;
00048 std::string input1("-lloki \n-lfoo");
00049 std::string output1("loki foo");
00050
00051 std::string lflags;
00052
00053 lflags = rp.snarf_libs(input1);
00054 EXPECT_EQ(output1, lflags);
00055 }
00056
00057 TEST(rospack, lflags_escaped_string)
00058 {
00059 rospack::ROSPack rp;
00060 std::string input1("-lloki \\-lfoo");
00061 std::string output1("loki");
00062
00063 std::string lflags;
00064
00065 lflags = rp.snarf_libs(input1);
00066 EXPECT_EQ(output1, lflags);
00067 }
00068
00069 TEST(rospack, lflags_embedded_whitespace)
00070 {
00071 rospack::ROSPack rp;
00072 std::string input1("-lloki -lfoo\\ bar");
00073 std::string output1("loki foo\\ bar");
00074
00075 std::string lflags;
00076
00077 lflags = rp.snarf_libs(input1);
00078 EXPECT_EQ(output1, lflags);
00079 }
00080
00081 TEST(rospack, lflags_no_trailing_whitespace)
00082 {
00083 rospack::ROSPack rp;
00084 std::string input1("-lloki");
00085 std::string input2("-lloki -lfoo");
00086 std::string output1("loki");
00087 std::string output2("loki foo");
00088
00089 std::string lflags;
00090
00091 lflags = rp.snarf_libs(input1);
00092 EXPECT_EQ(output1, lflags);
00093
00094 lflags = rp.snarf_libs(input2);
00095 EXPECT_EQ(output2, lflags);
00096 }
00097
00098 TEST(rospack, lflags_embedded_dashl)
00099 {
00100 rospack::ROSPack rp;
00101 std::string input("-L/u/wheeler/ros/ros-pkg/3rdparty/loki-lib/loki-svn/lib -lloki ");
00102 std::string lib_output("loki");
00103 std::string libdir_output("/u/wheeler/ros/ros-pkg/3rdparty/loki-lib/loki-svn/lib");
00104
00105 std::string lflags;
00106
00107 lflags = rp.snarf_flags(input, "-L");
00108 EXPECT_EQ(libdir_output, lflags);
00109
00110 lflags = rp.snarf_libs(input);
00111 EXPECT_EQ(lib_output, lflags);
00112 }
00113
00114 TEST(rospack, lflags_static_libs)
00115 {
00116 rospack::ROSPack rp;
00117 std::string input("-L/blah/blah -lfoo /bar/baz/bom.a -lzom -Wl,other");
00118 std::string lib_output("foo /bar/baz/bom.a zom");
00119 std::string libdir_output("/blah/blah");
00120 std::string other_output("-Wl,other");
00121
00122 std::string lflags;
00123
00124 lflags = rp.snarf_flags(input, "-L");
00125 EXPECT_EQ(libdir_output, lflags);
00126
00127 lflags = rp.snarf_libs(input);
00128 EXPECT_EQ(lib_output, lflags);
00129
00130 lflags = rp.snarf_libs(input, true);
00131 lflags = rp.snarf_flags(lflags, "-L", true);
00132 EXPECT_EQ(other_output, lflags);
00133 }
00134
00135 TEST(rospack, reentrant)
00136 {
00137 char buf[1024];
00138 std::string rr = std::string(getcwd(buf, sizeof(buf))) + "/test2";
00139 setenv("ROS_ROOT", rr.c_str(), 1);
00140 unsetenv("ROS_PACKAGE_PATH");
00141
00142 rospack::ROSPack rp;
00143 int ret = rp.run(std::string("plugins --attrib=foo --top=precedence1 roslang"));
00144 ASSERT_EQ(ret, 0);
00145 ret = rp.run(std::string("find roslang"));
00146 ASSERT_EQ(ret, 0);
00147 ret = rp.run(std::string("list-names"));
00148 ASSERT_EQ(ret, 0);
00149 std::vector<std::string> output_list;
00150 rospack::string_split(rp.getOutput(), output_list, "\n");
00151 ASSERT_EQ((int)output_list.size(), 4);
00152 ret = rp.run(std::string("list"));
00153 ASSERT_EQ(ret, 0);
00154 rospack::string_split(rp.getOutput(), output_list, "\n");
00155 ASSERT_EQ((int)output_list.size(), 4);
00156 std::vector<std::string> path_name;
00157 rospack::string_split(output_list[0], path_name, " ");
00158 ASSERT_EQ((int)path_name.size(), 2);
00159 }
00160
00161 TEST(rospack, multiple_rospack_objects)
00162 {
00163 char buf[1024];
00164 std::string rr = std::string(getcwd(buf, sizeof(buf))) + "/test2";
00165 setenv("ROS_ROOT", rr.c_str(), 1);
00166 unsetenv("ROS_PACKAGE_PATH");
00167
00168 rospack::ROSPack rp;
00169 int ret = rp.run(std::string("plugins --attrib=foo --top=precedence1 roslang"));
00170 ASSERT_EQ(ret, 0);
00171 ret = rp.run(std::string("find roslang"));
00172 ASSERT_EQ(ret, 0);
00173 ret = rp.run(std::string("list-names"));
00174 ASSERT_EQ(ret, 0);
00175 std::vector<std::string> output_list;
00176 rospack::string_split(rp.getOutput(), output_list, "\n");
00177 ASSERT_EQ((int)output_list.size(), 4);
00178 ret = rp.run(std::string("list"));
00179 ASSERT_EQ(ret, 0);
00180 rospack::string_split(rp.getOutput(), output_list, "\n");
00181 ASSERT_EQ((int)output_list.size(), 4);
00182 std::vector<std::string> path_name;
00183 rospack::string_split(output_list[0], path_name, " ");
00184 ASSERT_EQ((int)path_name.size(), 2);
00185
00186 rospack::ROSPack rp2;
00187 ret = rp2.run(std::string("plugins --attrib=foo --top=precedence1 roslang"));
00188 ASSERT_EQ(ret, 0);
00189 ret = rp2.run(std::string("find roslang"));
00190 ASSERT_EQ(ret, 0);
00191 ret = rp2.run(std::string("list-names"));
00192 ASSERT_EQ(ret, 0);
00193 output_list.clear();
00194 rospack::string_split(rp2.getOutput(), output_list, "\n");
00195 ASSERT_EQ((int)output_list.size(), 4);
00196 ret = rp2.run(std::string("list"));
00197 ASSERT_EQ(ret, 0);
00198 rospack::string_split(rp2.getOutput(), output_list, "\n");
00199 ASSERT_EQ((int)output_list.size(), 4);
00200 path_name.clear();
00201 rospack::string_split(output_list[0], path_name, " ");
00202 ASSERT_EQ((int)path_name.size(), 2);
00203 }
00204
00205 TEST(rospack, deduplicate_tokens)
00206 {
00207 rospack::ROSPack rp;
00208 std::string input = "foo foo bar bat bar foobar batbar";
00209 std::string truth = "foo bar bat foobar batbar";
00210 std::string output = rp.deduplicate_tokens(input);
00211 ASSERT_EQ(truth, output);
00212 }
00213
00214
00216
00217 int main(int argc, char **argv)
00218 {
00219 testing::InitGoogleTest(&argc, argv);
00220 return RUN_ALL_TESTS();
00221 }