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 
50 int runExternalProcess(const std::string &executable, const std::string &args)
51 {
52  return system((executable + " " + args).c_str());
53 }
54 
55 int walker( char *result, int& test_result)
56 {
57  DIR *d;
58  struct dirent *dir;
59  d = opendir( "robots" );
60  if( d == NULL )
61  {
62  return 1;
63  }
64  while( ( dir = readdir( d ) ) )
65  {
66  if( strcmp( dir->d_name, "." ) == 0 ||
67  strcmp( dir->d_name, ".." ) == 0 )
68  {
69  continue;
70  }
71  if( dir->d_type != DT_DIR )
72  {
73  std::string dir_name = dir->d_name;
74  if (dir_name.find(std::string(".urdf.xacro")) == dir_name.size()-11)
75  {
76  char pwd[MAXPATHLEN];
77  getcwd( pwd, MAXPATHLEN );
78  printf("\n\ntesting: %s\n",(std::string(pwd)+"/robots/"+dir_name).c_str());
79  runExternalProcess("python `rospack find xacro`/xacro --inorder", std::string(pwd)+"/robots/"+dir_name+" > `rospack find turtlebot_description`/test/tmp.urdf");
80  test_result = test_result || runExternalProcess("`rospack find urdf_parser`/bin/check_urdf", "`rospack find turtlebot_description`/test/tmp.urdf");
81  //break;
82  }
83  }
84  }
85  closedir( d );
86  return *result == 0;
87 }
88 
89 TEST(URDF, CorrectFormat)
90 {
91  int test_result = 0;
92 
93  char buf[MAXPATHLEN] = { 0 };
94  if( walker( buf, test_result ) == 0 )
95  {
96  printf( "Found: %s\n", buf );
97  }
98  else
99  {
100  puts( "Not found" );
101  }
102 
103  EXPECT_TRUE(test_result == 0);
104 }
105 
106 int main(int argc, char **argv)
107 {
108  testing::InitGoogleTest(&argc, argv);
109  return RUN_ALL_TESTS();
110 }
d
int main(int argc, char **argv)
Definition: test_urdf.cpp:106
int walker(char *result, int &test_result)
Definition: test_urdf.cpp:55
int runExternalProcess(const std::string &executable, const std::string &args)
Definition: test_urdf.cpp:50
TEST(URDF, CorrectFormat)
Definition: test_urdf.cpp:89


turtlebot_description
Author(s): Melonee Wise, Daniel Stonier
autogenerated on Mon Jun 10 2019 15:41:44