test_urdf.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 
37 #include <gtest/gtest.h>
38 #include <cstdlib>
39 
40 #include <dirent.h>
41 #include <sys/types.h>
42 #include <sys/param.h>
43 #include <sys/stat.h>
44 #include <unistd.h>
45 #include <stdio.h>
46 #include <string.h>
47 
48 #include <iostream>
49 #include <fstream>
50 
51 #include <urdf_parser/urdf_parser.h>
52 #include <boost/function.hpp>
53 #include <urdf_model/model.h>
54 
55 int runExternalProcess(const std::string &executable, const std::string &args)
56 {
57  return system((executable + " " + args).c_str());
58 }
59 
60 int walker( std::string & result, int& test_result)
61 {
62  DIR *d;
63  struct dirent *dir;
64  d = opendir( "robots" );
65  if( d == NULL )
66  {
67  return 1;
68  }
69  while( ( dir = readdir( d ) ) )
70  {
71  if( strcmp( dir->d_name, "." ) == 0 ||
72  strcmp( dir->d_name, ".." ) == 0 )
73  {
74  continue;
75  }
76  if( dir->d_type != DT_DIR )
77  {
78  std::string dir_name = dir->d_name;
79  if (dir_name.find(std::string(".urdf.xacro")) == dir_name.size()-11)
80  {
81  char pwd[MAXPATHLEN];
82  getcwd( pwd, MAXPATHLEN );
83  std::string name = std::string(pwd)+"/robots/"+dir_name;
84  printf("\n\ntesting: %s\n",name.c_str());
85  result += name;
86  result += " ";
87 
88  runExternalProcess("rosrun xacro xacro", name+" --inorder > `rospack find pr2_description`/test/tmp.urdf" );
89  std::string path = std::string(pwd)+"/test/tmp.urdf";
90 
91 
92  std::string xml_string;
93  std::fstream xml_file(path.c_str(), std::fstream::in);
94  while ( xml_file.good() )
95  {
96  std::string line;
97  std::getline( xml_file, line);
98  xml_string += (line + "\n");
99  }
100  xml_file.close();
101 
102  boost::shared_ptr<urdf::ModelInterface> robot = urdf::parseURDF(xml_string);
103  if (!robot) test_result = test_result || 1;
104 
105  }
106  }
107  }
108  closedir( d );
109  return test_result;
110 }
111 
112 TEST(URDF, CorrectFormat)
113 {
114  int test_result = 0;
115 
116  std::string result;
117  if( walker( result, test_result ) == 0 )
118  {
119  printf( "Found: %s\n", result.c_str() );
120  }
121  else
122  {
123  puts( "Not found" );
124  test_result = -1;
125  }
126 
127  EXPECT_TRUE(test_result == 0);
128 }
129 
130 int main(int argc, char **argv)
131 {
132  testing::InitGoogleTest(&argc, argv);
133  return RUN_ALL_TESTS();
134 }
d
int main(int argc, char **argv)
Definition: test_urdf.cpp:130
path
int walker(std::string &result, int &test_result)
Definition: test_urdf.cpp:60
int runExternalProcess(const std::string &executable, const std::string &args)
Definition: test_urdf.cpp:55
TEST(URDF, CorrectFormat)
Definition: test_urdf.cpp:112


pr2_description
Author(s): John Hsu, Eric Berger, Austin Hendrix
autogenerated on Thu Jun 6 2019 19:51:19