test.cpp
Go to the documentation of this file.
1 /*********************************************************************
2 * Software License Agreement (BSD License)
3 *
4 * Copyright (c) 2008, Willow Garage, Inc.
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 *
11 * * Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * * Redistributions in binary form must reproduce the above
14 * copyright notice, this list of conditions and the following
15 * disclaimer in the documentation and/or other materials provided
16 * with the distribution.
17 * * Neither the name of the Willow Garage nor the names of its
18 * contributors may be used to endorse or promote products derived
19 * from this software without specific prior written permission.
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
24 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
25 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
26 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
27 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
28 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
29 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
31 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32 * POSSIBILITY OF SUCH DAMAGE.
33 *********************************************************************/
34 
35 #include <gtest/gtest.h>
36 
38 #include <ros/package.h>
39 #include <ros/console.h>
40 
41 using namespace resource_retriever;
42 
43 TEST(Retriever, getByPackage)
44 {
45  try
46  {
47  Retriever r;
48  MemoryResource res = r.get("package://" ROS_PACKAGE_NAME "/test/test.txt");
49 
50  ASSERT_EQ(res.size, 1);
51  ASSERT_EQ(res.data[0], 'A');
52  }
53  catch (Exception& e)
54  {
55  FAIL();
56  }
57 }
58 
59 TEST(Retriever, largeFile)
60 {
61  try
62  {
63  std::string path = ros::package::getPath(ROS_PACKAGE_NAME) + "/test/large_file.dat";
64 
65  FILE* f = fopen(path.c_str(), "w");
66 
67  ASSERT_TRUE(f);
68 
69  for (int i = 0; i < 1024*1024*50; ++i)
70  {
71  fprintf(f, "A");
72  }
73  fclose(f);
74 
75  Retriever r;
76  MemoryResource res = r.get("package://" ROS_PACKAGE_NAME "/test/large_file.dat");
77 
78  ASSERT_EQ(res.size, 1024*1024*50);
79  }
80  catch (Exception& e)
81  {
82  FAIL();
83  }
84 }
85 
87 {
88  try
89  {
90  Retriever r;
91  MemoryResource res = r.get("http://packages.ros.org/ros.key");
92 
93  ASSERT_GT(res.size, 0);
94  }
95  catch (Exception& e)
96  {
97  FAIL();
98  }
99 }
100 
101 TEST(Retriever, invalidFiles)
102 {
103  Retriever r;
104 
105  try
106  {
107  r.get("file://fail");
108  FAIL();
109  }
110  catch (Exception& e)
111  {
112  ROS_INFO("%s", e.what());
113  }
114 
115  try
116  {
117  r.get("package://roscpp");
118  FAIL();
119  }
120  catch (Exception& e)
121  {
122  ROS_INFO("%s", e.what());
123  }
124 
125  try
126  {
127  r.get("package://invalid_package_blah/test.xml");
128  FAIL();
129  }
130  catch (Exception& e)
131  {
132  ROS_INFO("%s", e.what());
133  }
134 }
135 
136 int main(int argc, char **argv){
137  testing::InitGoogleTest(&argc, argv);
138  return RUN_ALL_TESTS();
139 }
140 
TEST
TEST(Retriever, getByPackage)
Definition: test.cpp:43
resource_retriever::MemoryResource::size
uint32_t size
Definition: retriever.h:59
ros::package::getPath
ROSLIB_DECL std::string getPath(const std::string &package_name)
resource_retriever
Definition: retriever.h:38
resource_retriever::MemoryResource
A combination of a pointer to data in memory along with the data's size.
Definition: retriever.h:52
resource_retriever::MemoryResource::data
boost::shared_array< uint8_t > data
Definition: retriever.h:58
f
f
console.h
resource_retriever::Retriever::get
MemoryResource get(const std::string &url)
Get a file and store it in memory.
Definition: retriever.cpp:98
resource_retriever::Retriever
Retrieves files from from a url. Caches a CURL handle so multiple accesses to a single url will keep ...
Definition: retriever.h:66
retriever.h
package.h
main
int main(int argc, char **argv)
Definition: test.cpp:136
resource_retriever::Exception
Definition: retriever.h:41
ROS_INFO
#define ROS_INFO(...)


resource_retriever
Author(s): Josh Faust , Ioan Sucan
autogenerated on Wed Dec 20 2023 03:35:35