diff --git a/.gitignore b/.gitignore new file mode 100644 index 00000000..1614457d --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +# VIM +.*.sw? diff --git a/urdf/CMakeLists.txt b/urdf/CMakeLists.txt index 6d706bc1..a109db0f 100644 --- a/urdf/CMakeLists.txt +++ b/urdf/CMakeLists.txt @@ -53,6 +53,8 @@ if(CATKIN_ENABLE_TESTING) find_package(catkin REQUIRED COMPONENTS rostest) add_rostest_gtest(test_urdf_parser test/test_robot_model_parser.launch test/test_robot_model_parser.cpp) target_link_libraries(test_urdf_parser ${PROJECT_NAME}) + + catkin_add_gtest(urdfdom_compatibility_test test/urdfdom_compatibility.cpp) endif() # no idea how CATKIN does this diff --git a/urdf/test/urdfdom_compatibility.cpp b/urdf/test/urdfdom_compatibility.cpp new file mode 100644 index 00000000..13524811 --- /dev/null +++ b/urdf/test/urdfdom_compatibility.cpp @@ -0,0 +1,53 @@ +/********************************************************************* +* Software License Agreement (BSD License) +* +* Copyright (c) 2017 Open Source Robotics Foundation +* All rights reserved. +* +* Redistribution and use in source and binary forms, with or without +* modification, are permitted provided that the following conditions +* are met: +* +* * Redistributions of source code must retain the above copyright +* notice, this list of conditions and the following disclaimer. +* * Redistributions in binary form must reproduce the above +* copyright notice, this list of conditions and the following +* disclaimer in the documentation and/or other materials provided +* with the distribution. +* * Neither the name of the Willow Garage nor the names of its +* contributors may be used to endorse or promote products derived +* from this software without specific prior written permission. +* +* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS +* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE +* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, +* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN +* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +* POSSIBILITY OF SUCH DAMAGE. +*********************************************************************/ + +#include +#include "urdf/model.h" + + +TEST(UrdfCompatibility, UpcastSharedPtr) +{ + urdf::ModelSharedPtr model(new urdf::Model); + model->name_ = "UpcastSharedPtr"; + urdf::ModelInterfaceSharedPtr interface = model; + EXPECT_EQ(std::string("UpcastSharedPtr"), interface->getName()); +} + + +int main(int argc, char** argv) +{ + testing::InitGoogleTest(&argc, argv); + return RUN_ALL_TESTS(); +} + diff --git a/urdf/urdfdom_compatibility.h.in b/urdf/urdfdom_compatibility.h.in index c355b30d..7ee6cba2 100644 --- a/urdf/urdfdom_compatibility.h.in +++ b/urdf/urdfdom_compatibility.h.in @@ -41,7 +41,8 @@ #define URDFDOM_HEADERS_MINOR_VERSION @URDFDOM_HEADERS_MINOR_VERSION@ #define URDFDOM_HEADERS_REVISION_VERSION @URDFDOM_HEADERS_REVISION_VERSION@ -// for Wily: maintain compatibility between urdfdom 0.3 and 0.4 (definining SharedPtr types) +// Define shared pointers for urdfdom versions less than 0.4 +// Plus define ModelSharedPtr for 0.4 #if URDFDOM_HEADERS_MAJOR_VERSION == 0 && URDFDOM_HEADERS_MINOR_VERSION <= 4 #include @@ -54,6 +55,8 @@ typedef boost::shared_ptr Class##ConstSharedPtr; \ typedef boost::weak_ptr Class##WeakPtr namespace urdf { +// These shared_ptrs were added to urdfdom in 0.4.0, +// so if urdfdom == 0.4 this is duplicate work URDF_TYPEDEF_CLASS_POINTER(Box); URDF_TYPEDEF_CLASS_POINTER(Collision); URDF_TYPEDEF_CLASS_POINTER(Cylinder); @@ -74,6 +77,8 @@ URDF_TYPEDEF_CLASS_POINTER(Sphere); URDF_TYPEDEF_CLASS_POINTER(Visual); URDF_TYPEDEF_CLASS_POINTER(ModelInterface); + +// ModelSharedPtr is the only one that needs to be defined for urdfdom 0.4 URDF_TYPEDEF_CLASS_POINTER(Model); } @@ -89,6 +94,9 @@ typedef std::shared_ptr ModelInterfaceSharedPtr; typedef std::shared_ptr ModelInterfaceConstSharedPtr; typedef std::weak_ptr ModelInterfaceWeakPtr; +// Forward declaration +class Model; + typedef std::shared_ptr ModelSharedPtr; typedef std::shared_ptr ModelConstSharedPtr; typedef std::weak_ptr ModelWeakPtr;