Go to the documentation of this file.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 <gtest/gtest.h>
00034 #include "map_server/image_loader.h"
00035 #include "test_constants.h"
00036
00037
00038
00039
00040
00041
00042 TEST(MapServer, loadValidPNG)
00043 {
00044 try
00045 {
00046 nav_msgs::GetMap::Response map_resp;
00047 double origin[3] = { 0.0, 0.0, 0.0 };
00048 map_server::loadMapFromFile(&map_resp, g_valid_png_file, g_valid_image_res, false, 0.65, 0.1, origin);
00049 EXPECT_FLOAT_EQ(map_resp.map.info.resolution, g_valid_image_res);
00050 EXPECT_EQ(map_resp.map.info.width, g_valid_image_width);
00051 EXPECT_EQ(map_resp.map.info.height, g_valid_image_height);
00052 for(unsigned int i=0; i < map_resp.map.info.width * map_resp.map.info.height; i++)
00053 EXPECT_EQ(g_valid_image_content[i], map_resp.map.data[i]);
00054 }
00055 catch(...)
00056 {
00057 ADD_FAILURE() << "Uncaught exception : " << "This is OK on OS X";
00058 }
00059 }
00060
00061
00062
00063 TEST(MapServer, loadValidBMP)
00064 {
00065 try
00066 {
00067 nav_msgs::GetMap::Response map_resp;
00068 double origin[3] = { 0.0, 0.0, 0.0 };
00069 map_server::loadMapFromFile(&map_resp, g_valid_bmp_file, g_valid_image_res, false, 0.65, 0.1, origin);
00070 EXPECT_FLOAT_EQ(map_resp.map.info.resolution, g_valid_image_res);
00071 EXPECT_EQ(map_resp.map.info.width, g_valid_image_width);
00072 EXPECT_EQ(map_resp.map.info.height, g_valid_image_height);
00073 for(unsigned int i=0; i < map_resp.map.info.width * map_resp.map.info.height; i++)
00074 EXPECT_EQ(g_valid_image_content[i], map_resp.map.data[i]);
00075 }
00076 catch(...)
00077 {
00078 ADD_FAILURE() << "Uncaught exception";
00079 }
00080 }
00081
00082
00083
00084 TEST(MapServer, loadInvalidFile)
00085 {
00086 try
00087 {
00088 nav_msgs::GetMap::Response map_resp;
00089 double origin[3] = { 0.0, 0.0, 0.0 };
00090 map_server::loadMapFromFile(&map_resp, "foo", 0.1, false, 0.65, 0.1, origin);
00091 }
00092 catch(std::runtime_error &e)
00093 {
00094 SUCCEED();
00095 return;
00096 }
00097 catch(...)
00098 {
00099 FAIL() << "Uncaught exception";
00100 }
00101 ADD_FAILURE() << "Didn't throw exception as expected";
00102 }
00103
00104 int main(int argc, char **argv)
00105 {
00106 testing::InitGoogleTest(&argc, argv);
00107 return RUN_ALL_TESTS();
00108 }