KdlTreeParserTest.cpp
Go to the documentation of this file.
00001 #include <gtest/gtest.h>
00002 #include "robodyn_controllers/KdlTreeParser.h"
00003 
00004 #include <ros/package.h>
00005 #include <ros/init.h>
00006 
00007 class KdlTreeParserTest : public ::testing::Test
00008 {
00009 protected:
00010     virtual void SetUp()
00011     {
00012     }
00013 
00014     virtual void TearDown()
00015     {
00016     }
00017 
00018     class MyParser : public KdlTreeParser
00019     {
00020     public:
00021         MyParser() : KdlTreeParser(), initialized(false) {}
00022         void initialize()
00023         {
00024             initialized = true;
00025         }
00026         bool initialized;
00027     };
00028 
00029     MyParser parser;
00030     KDL::Tree tree;
00031 };
00032 
00033 TEST_F(KdlTreeParserTest, parserTest)
00034 {
00035     // nothing yet
00036     EXPECT_FALSE(parser.initialized);
00037     tree = parser.getTree();
00038     EXPECT_EQ(0, tree.getNrOfSegments());
00039 
00040     // load
00041     std::string packagePath = ros::package::getPath("robodyn_controllers");
00042     parser.loadFromFile(packagePath + "/test/urdf/BranchingTestRobot.xml");
00043 
00044     // check initialize was called
00045     EXPECT_TRUE(parser.initialized);
00046     tree = parser.getTree();
00047 
00048     // make sure it was loaded properly though not an exhaustive check since it is a 3rd party library
00049     EXPECT_EQ(5, tree.getNrOfSegments());
00050     EXPECT_EQ(4, tree.getNrOfJoints());
00051 
00052     // verify init calle don setTree
00053     parser.initialized = false;
00054     parser.setTree(tree);
00055     EXPECT_TRUE(parser.initialized);
00056 
00057     // check throw on bad urdf
00058     EXPECT_ANY_THROW(parser.loadFromParam("bogusParam"));
00059 }
00060 
00061 int main(int argc, char** argv)
00062 {
00063     ::testing::InitGoogleTest(&argc, argv);
00064     ros::init(argc, argv, "test");
00065     return RUN_ALL_TESTS();
00066 }


robodyn_controllers
Author(s):
autogenerated on Sat Jun 8 2019 20:20:53