Fawkes API  Fawkes Development Version
test_kdlparser.cpp
1 /***************************************************************************
2  * kdlparser-test.cpp - SyncPoint Unit Test
3  *
4  * Created on Mon Mar 24 15:47:30 2014
5  * Copyright (C) 2014
6  *
7  ****************************************************************************/
8 
9 /* This program is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 2 of the License, or
12  * (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  * GNU Library General Public License for more details.
18  *
19  * Read the full text in the LICENSE.GPL file in the doc directory.
20  */
21 
22 #include <gtest/gtest.h>
23 #include <libs/kdl_parser/kdl_parser.h>
24 #include <kdl/tree.hpp>
25 
26 #include <string>
27 
28 using namespace fawkes;
29 using namespace fawkes::kdl_parser;
30 using namespace std;
31 
32 /** Test Class for KDLParser */
33 class KDLParserTest : public ::testing::Test
34 {
35 
36  protected:
37  /** Load the robot description and initialize the tree */
38  virtual void SetUp()
39  {
40  urdf_file = SRCDIR"/caesar.urdf";
41  ASSERT_TRUE(tree_from_file(urdf_file, tree));
42  }
43  /** The result of parsing the URDF file */
44  KDL::Tree tree;
45  /** The URDF file path */
46  string urdf_file;
47 };
48 
49 
50 
51 TEST_F(KDLParserTest, FileDoesNotExist) {
52  string filename = "invalidFileName";
53  KDL::Tree tree;
54  ASSERT_ANY_THROW(tree_from_file(filename, tree));
55 }
56 
57 TEST_F(KDLParserTest, NumberOfJoints) {
58  EXPECT_EQ((unsigned int)9, tree.getNrOfJoints());
59  EXPECT_EQ((unsigned int)37, tree.getNrOfSegments());
60 }
61 
62 TEST_F(KDLParserTest, ChainToKatanaFinger) {
63  KDL::Chain chain;
64  ASSERT_TRUE(tree.getChain("/base_link", "katana_l_finger_link", chain));
65  EXPECT_EQ(9, chain.getNrOfSegments());
66  EXPECT_EQ(6, chain.getNrOfJoints());
67 }
68 
69 TEST_F(KDLParserTest, RootSegment) {
70  EXPECT_EQ("/base_link", tree.getRootSegment()->first);
71  EXPECT_EQ(tree.getSegment("/base_link"), tree.getRootSegment());
72 }
Fawkes library namespace.
STL namespace.
virtual void SetUp()
Load the robot description and initialize the tree.
Test Class for KDLParser.
KDL::Tree tree
The result of parsing the URDF file.
string urdf_file
The URDF file path.