$search
00001 /* 00002 * Copyright (c) 2008, Willow Garage, Inc. 00003 * All rights reserved. 00004 * 00005 * Redistribution and use in source and binary forms, with or without 00006 * modification, are permitted provided that the following conditions are met: 00007 * 00008 * * Redistributions of source code must retain the above copyright 00009 * notice, this list of conditions and the following disclaimer. 00010 * * Redistributions in binary form must reproduce the above copyright 00011 * notice, this list of conditions and the following disclaimer in the 00012 * documentation and/or other materials provided with the distribution. 00013 * * Neither the name of the Willow Garage, Inc. nor the names of its 00014 * contributors may be used to endorse or promote products derived from 00015 * this software without specific prior written permission. 00016 * 00017 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 00018 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 00019 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 00020 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 00021 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 00022 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 00023 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 00024 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 00025 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 00026 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 00027 * POSSIBILITY OF SUCH DAMAGE. 00028 */ 00029 00030 /* Author: Brian Gerkey */ 00031 00032 #include <stdexcept> // for std::runtime_error 00033 #include <gtest/gtest.h> 00034 #include "map_server/image_loader.h" 00035 #include "test_constants.h" 00036 00037 /* Try to load a valid PNG file. Succeeds if no exception is thrown, and if 00038 * the loaded image matches the known dimensions and content of the file. 00039 * 00040 * This test can fail on OS X, due to an apparent limitation of the 00041 * underlying SDL_Image library. */ 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 /* Try to load a valid BMP file. Succeeds if no exception is thrown, and if 00062 * the loaded image matches the known dimensions and content of the file. */ 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 /* Try to load an invalid file. Succeeds if a std::runtime_error exception 00083 * is thrown. */ 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 }