utest.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2008, Willow Garage, Inc.
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions are met:
7  *
8  * * Redistributions of source code must retain the above copyright
9  * notice, this list of conditions and the following disclaimer.
10  * * Redistributions in binary form must reproduce the above copyright
11  * notice, this list of conditions and the following disclaimer in the
12  * documentation and/or other materials provided with the distribution.
13  * * Neither the name of the Willow Garage, Inc. nor the names of its
14  * contributors may be used to endorse or promote products derived from
15  * this software without specific prior written permission.
16  *
17  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
21  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27  * POSSIBILITY OF SUCH DAMAGE.
28  */
29 
30 /* Author: Brian Gerkey */
31 
32 #include <stdexcept> // for std::runtime_error
33 #include <gtest/gtest.h>
35 #include "test_constants.h"
36 
37 /* Try to load a valid PNG file. Succeeds if no exception is thrown, and if
38  * the loaded image matches the known dimensions and content of the file.
39  *
40  * This test can fail on OS X, due to an apparent limitation of the
41  * underlying SDL_Image library. */
42 TEST(MapServer, loadValidPNG)
43 {
44  try
45  {
46  nav_msgs::GetMap::Response map_resp;
47  double origin[3] = { 0.0, 0.0, 0.0 };
48  map_server::loadMapFromFile(&map_resp, g_valid_png_file, g_valid_image_res, false, 0.65, 0.1, origin);
49  EXPECT_FLOAT_EQ(map_resp.map.info.resolution, g_valid_image_res);
50  EXPECT_EQ(map_resp.map.info.width, g_valid_image_width);
51  EXPECT_EQ(map_resp.map.info.height, g_valid_image_height);
52  for(unsigned int i=0; i < map_resp.map.info.width * map_resp.map.info.height; i++)
53  EXPECT_EQ(g_valid_image_content[i], map_resp.map.data[i]);
54  }
55  catch(...)
56  {
57  ADD_FAILURE() << "Uncaught exception : " << "This is OK on OS X";
58  }
59 }
60 
61 /* Try to load a valid BMP file. Succeeds if no exception is thrown, and if
62  * the loaded image matches the known dimensions and content of the file. */
63 TEST(MapServer, loadValidBMP)
64 {
65  try
66  {
67  nav_msgs::GetMap::Response map_resp;
68  double origin[3] = { 0.0, 0.0, 0.0 };
69  map_server::loadMapFromFile(&map_resp, g_valid_bmp_file, g_valid_image_res, false, 0.65, 0.1, origin);
70  EXPECT_FLOAT_EQ(map_resp.map.info.resolution, g_valid_image_res);
71  EXPECT_EQ(map_resp.map.info.width, g_valid_image_width);
72  EXPECT_EQ(map_resp.map.info.height, g_valid_image_height);
73  for(unsigned int i=0; i < map_resp.map.info.width * map_resp.map.info.height; i++)
74  EXPECT_EQ(g_valid_image_content[i], map_resp.map.data[i]);
75  }
76  catch(...)
77  {
78  ADD_FAILURE() << "Uncaught exception";
79  }
80 }
81 
82 /* Try to load an invalid file. Succeeds if a std::runtime_error exception
83  * is thrown. */
84 TEST(MapServer, loadInvalidFile)
85 {
86  try
87  {
88  nav_msgs::GetMap::Response map_resp;
89  double origin[3] = { 0.0, 0.0, 0.0 };
90  map_server::loadMapFromFile(&map_resp, "foo", 0.1, false, 0.65, 0.1, origin);
91  }
92  catch(std::runtime_error &e)
93  {
94  SUCCEED();
95  return;
96  }
97  catch(...)
98  {
99  FAIL() << "Uncaught exception";
100  }
101  ADD_FAILURE() << "Didn't throw exception as expected";
102 }
103 
104 int main(int argc, char **argv)
105 {
106  testing::InitGoogleTest(&argc, argv);
107  return RUN_ALL_TESTS();
108 }
TEST(MapServer, loadValidPNG)
Definition: utest.cpp:42
const unsigned int g_valid_image_height
const unsigned int g_valid_image_width
int main(int argc, char **argv)
Definition: utest.cpp:104
void loadMapFromFile(nav_msgs::GetMap::Response *resp, const char *fname, double res, bool negate, double occ_th, double free_th, double *origin, MapMode mode=TRINARY)
const float g_valid_image_res
const char * g_valid_png_file
const char * g_valid_bmp_file
const char g_valid_image_content[]


map_server
Author(s): Brian Gerkey, Tony Pratkanis, contradict@gmail.com
autogenerated on Thu Jan 21 2021 04:05:35