33 #include <std_msgs/Int32.h> 34 #include <map_organizer_msgs/OccupancyGridArray.h> 35 #include <nav_msgs/OccupancyGrid.h> 37 #include <gtest/gtest.h> 39 void validateMap0(
const nav_msgs::OccupancyGrid& map,
const double z)
41 ASSERT_EQ(
"map_ground", map.header.frame_id);
42 ASSERT_EQ(2u, map.info.width);
43 ASSERT_EQ(4u, map.data.size());
44 ASSERT_FLOAT_EQ(0.0, map.info.origin.orientation.x);
45 ASSERT_FLOAT_EQ(0.0, map.info.origin.orientation.y);
46 ASSERT_FLOAT_EQ(0.0, map.info.origin.orientation.z);
47 ASSERT_FLOAT_EQ(1.0, map.info.origin.orientation.w);
48 ASSERT_FLOAT_EQ(0.1, map.info.resolution);
49 ASSERT_FLOAT_EQ(0.0, map.info.origin.position.x);
50 ASSERT_FLOAT_EQ(0.0, map.info.origin.position.y);
51 ASSERT_FLOAT_EQ(z, map.info.origin.position.z);
52 ASSERT_EQ(100, map.data[0]);
53 ASSERT_EQ(0, map.data[1]);
54 ASSERT_EQ(100, map.data[2]);
55 ASSERT_EQ(100, map.data[3]);
57 void validateMap1(
const nav_msgs::OccupancyGrid& map,
const double z)
59 ASSERT_EQ(
"map_ground", map.header.frame_id);
60 ASSERT_EQ(2u, map.info.width);
61 ASSERT_EQ(4u, map.data.size());
62 ASSERT_FLOAT_EQ(0.0, map.info.origin.orientation.x);
63 ASSERT_FLOAT_EQ(0.0, map.info.origin.orientation.y);
64 ASSERT_FLOAT_EQ(0.0, map.info.origin.orientation.z);
65 ASSERT_FLOAT_EQ(1.0, map.info.origin.orientation.w);
66 ASSERT_FLOAT_EQ(0.2, map.info.resolution);
67 ASSERT_FLOAT_EQ(0.1, map.info.origin.position.x);
68 ASSERT_FLOAT_EQ(0.1, map.info.origin.position.y);
69 ASSERT_FLOAT_EQ(z, map.info.origin.position.z);
70 ASSERT_EQ(100, map.data[0]);
71 ASSERT_EQ(0, map.data[1]);
72 ASSERT_EQ(0, map.data[2]);
73 ASSERT_EQ(100, map.data[3]);
76 TEST(MapOrganizer, MapArray)
80 map_organizer_msgs::OccupancyGridArray::ConstPtr
maps;
81 const boost::function<void(const map_organizer_msgs::OccupancyGridArray::ConstPtr&)>
82 cb = [&
maps](
const map_organizer_msgs::OccupancyGridArray::ConstPtr& msg) ->
void 89 for (
int i = 0; i < 100 &&
ros::ok(); ++i)
96 ASSERT_TRUE(static_cast<bool>(maps));
97 ASSERT_EQ(2u, maps->maps.size());
107 nav_msgs::OccupancyGrid::ConstPtr map[2];
108 const boost::function<void(const nav_msgs::OccupancyGrid::ConstPtr&, int)>
109 cb = [&map](
const nav_msgs::OccupancyGrid::ConstPtr& msg,
110 const int id) ->
void 115 nh.
subscribe<nav_msgs::OccupancyGrid>(
"map0", 1, boost::bind(cb, _1, 0));
117 nh.
subscribe<nav_msgs::OccupancyGrid>(
"map1", 1, boost::bind(cb, _1, 1));
120 for (
int i = 0; i < 100 &&
ros::ok(); ++i)
124 if (map[0] && map[1])
127 for (
int i = 0; i < 2; ++i)
129 ASSERT_TRUE(static_cast<bool>(map[i]));
139 nav_msgs::OccupancyGrid::ConstPtr map;
140 const boost::function<void(const nav_msgs::OccupancyGrid::ConstPtr&)>
141 cb = [&map](
const nav_msgs::OccupancyGrid::ConstPtr& msg) ->
void 146 nh.
subscribe<nav_msgs::OccupancyGrid>(
"map", 1, cb);
150 for (
int i = 0; i < 100 &&
ros::ok(); ++i)
154 if (pub.getNumSubscribers() > 0 && map)
157 ASSERT_GT(pub.getNumSubscribers(), 0u);
158 ASSERT_TRUE(static_cast<bool>(map));
161 std_msgs::Int32 floor;
166 for (
int i = 0; i < 10 &&
ros::ok(); ++i)
173 ASSERT_FALSE(static_cast<bool>(map));
179 for (
int i = 0; i < 100 &&
ros::ok(); ++i)
186 ASSERT_TRUE(static_cast<bool>(map));
190 TEST(MapOrganizer, SavedMapArray)
194 map_organizer_msgs::OccupancyGridArray::ConstPtr
maps;
195 const boost::function<void(const map_organizer_msgs::OccupancyGridArray::ConstPtr&)>
196 cb = [&
maps](
const map_organizer_msgs::OccupancyGridArray::ConstPtr& msg) ->
void 203 for (
int i = 0; i < 100 &&
ros::ok(); ++i)
210 ASSERT_TRUE(static_cast<bool>(maps));
211 ASSERT_EQ(2u, maps->maps.size());
218 std::string file_prefix;
219 if (pnh.
getParam(
"file_prefix", file_prefix))
221 ASSERT_EQ(0, system(std::string(
"rm -f " + file_prefix +
"*").c_str()));
225 int main(
int argc,
char** argv)
227 testing::InitGoogleTest(&argc, argv);
228 ros::init(argc, argv,
"test_map_organizer");
230 return RUN_ALL_TESTS();
map_organizer_msgs::OccupancyGridArray maps
TEST(MapOrganizer, MapArray)
Subscriber subscribe(const std::string &topic, uint32_t queue_size, void(T::*fp)(M), T *obj, const TransportHints &transport_hints=TransportHints())
ROSCPP_DECL void init(int &argc, char **argv, const std::string &name, uint32_t options=0)
void validateMap0(const nav_msgs::OccupancyGrid &map, const double z)
int main(int argc, char **argv)
Publisher advertise(const std::string &topic, uint32_t queue_size, bool latch=false)
void validateMap1(const nav_msgs::OccupancyGrid &map, const double z)
bool getParam(const std::string &key, std::string &s) const
ROSCPP_DECL void spinOnce()