test.cpp
Go to the documentation of this file.
00001 /*********************************************************************
00002 * Software License Agreement (BSD License)
00003 *
00004 *  Copyright (c) 2008, Willow Garage, Inc.
00005 *  All rights reserved.
00006 *
00007 *  Redistribution and use in source and binary forms, with or without
00008 *  modification, are permitted provided that the following conditions
00009 *  are met:
00010 *
00011 *   * Redistributions of source code must retain the above copyright
00012 *     notice, this list of conditions and the following disclaimer.
00013 *   * Redistributions in binary form must reproduce the above
00014 *     copyright notice, this list of conditions and the following
00015 *     disclaimer in the documentation and/or other materials provided
00016 *     with the distribution.
00017 *   * Neither the name of the Willow Garage nor the names of its
00018 *     contributors may be used to endorse or promote products derived
00019 *     from this software without specific prior written permission.
00020 *
00021 *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
00022 *  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
00023 *  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
00024 *  FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
00025 *  COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
00026 *  INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
00027 *  BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
00028 *  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
00029 *  CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
00030 *  LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
00031 *  ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00032 *  POSSIBILITY OF SUCH DAMAGE.
00033 *********************************************************************/
00034 
00035 #include <gtest/gtest.h>
00036 
00037 #include <resource_retriever/retriever.h>
00038 #include <ros/package.h>
00039 #include <ros/console.h>
00040 
00041 using namespace resource_retriever;
00042 
00043 TEST(Retriever, getByPackage)
00044 {
00045   try
00046   {
00047     Retriever r;
00048     MemoryResource res = r.get("package://"ROS_PACKAGE_NAME"/test/test.txt");
00049 
00050     ASSERT_EQ(res.size, 1);
00051     ASSERT_EQ(res.data[0], 'A');
00052   }
00053   catch (Exception& e)
00054   {
00055     FAIL();
00056   }
00057 }
00058 
00059 TEST(Retriever, largeFile)
00060 {
00061   try
00062   {
00063     std::string path = ros::package::getPath(ROS_PACKAGE_NAME) + "/test/large_file.dat";
00064 
00065     FILE* f = fopen(path.c_str(), "w");
00066 
00067     ASSERT_TRUE(f);
00068 
00069     for (int i = 0; i < 1024*1024*50; ++i)
00070     {
00071       fprintf(f, "A");
00072     }
00073     fclose(f);
00074 
00075     Retriever r;
00076     MemoryResource res = r.get("package://"ROS_PACKAGE_NAME"/test/large_file.dat");
00077 
00078     ASSERT_EQ(res.size, 1024*1024*50);
00079   }
00080   catch (Exception& e)
00081   {
00082     FAIL();
00083   }
00084 }
00085 
00086 TEST(Retriever, http)
00087 {
00088   try
00089   {
00090     Retriever r;
00091     MemoryResource res = r.get("http://pr.willowgarage.com/downloads/svnmerge.py");
00092 
00093     ASSERT_GT(res.size, 0);
00094   }
00095   catch (Exception& e)
00096   {
00097     FAIL();
00098   }
00099 }
00100 
00101 TEST(Retriever, invalidFiles)
00102 {
00103   Retriever r;
00104 
00105   try
00106   {
00107     r.get("file://fail");
00108     FAIL();
00109   }
00110   catch (Exception& e)
00111   {
00112     ROS_INFO("%s", e.what());
00113   }
00114 
00115   try
00116   {
00117     r.get("package://roscpp");
00118     FAIL();
00119   }
00120   catch (Exception& e)
00121   {
00122     ROS_INFO("%s", e.what());
00123   }
00124 
00125   try
00126   {
00127     r.get("package://invalid_package_blah/test.xml");
00128     FAIL();
00129   }
00130   catch (Exception& e)
00131   {
00132     ROS_INFO("%s", e.what());
00133   }
00134 }
00135 
00136 int main(int argc, char **argv){
00137   testing::InitGoogleTest(&argc, argv);
00138   return RUN_ALL_TESTS();
00139 }
00140 


resource_retriever
Author(s): Josh Faust
autogenerated on Thu Aug 27 2015 14:40:57