run_selftest.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 
35 #include "ros/ros.h"
36 #include "diagnostic_msgs/SelfTest.h"
37 
38 #include <gtest/gtest.h>
39 #include <string>
40 
42 {
43  diagnostic_msgs::SelfTest srv;
44 
45  if (nh.serviceClient<diagnostic_msgs::SelfTest>("self_test").call(srv))
46  {
47  diagnostic_msgs::SelfTest::Response &res = srv.response;
48 
49  std::string passfail;
50 
51  if (res.passed)
52  passfail = "PASSED";
53  else
54  passfail = "FAILED";
55 
56  printf("Self test %s for device with id: [%s]\n", passfail.c_str(), res.id.c_str());
57 
58 
59  for (size_t i = 0; i < res.status.size(); i++)
60  {
61  printf("%2zd) %s\n", i + 1, res.status[i].name.c_str());
62  if (res.status[i].level == 0)
63  printf(" [OK]: ");
64  else if (res.status[i].level == 1)
65  printf(" [WARNING]: ");
66  else
67  printf(" [ERROR]: ");
68 
69  printf("%s\n", res.status[i].message.c_str());
70 
71  for (size_t j = 0; j < res.status[i].values.size(); j++)
72  printf(" [%s] %s\n", res.status[i].values[j].key.c_str(), res.status[i].values[j].value.c_str());
73 
74  printf("\n");
75  }
76  return res.passed;
77  }
78  else
79  {
80  printf("Failed to call service.\n");
81  return false;
82  }
83 }
84 
85 int main(int argc, char **argv)
86 {
87  ros::init(argc, argv, "run_selftest", ros::init_options::AnonymousName);
88  if (argc != 2)
89  {
90  printf("usage: run_selftest name\n");
91  return 1;
92  }
93 
94  ros::NodeHandle nh(argv[1]);
95  return !doTest(nh);
96 }
97 
ros::init_options::AnonymousName
AnonymousName
ros::init
ROSCPP_DECL void init(const M_string &remappings, const std::string &name, uint32_t options=0)
gtest.h
ros.h
ros::NodeHandle::serviceClient
ServiceClient serviceClient(const std::string &service_name, bool persistent=false, const M_string &header_values=M_string())
testing::internal::string
::std::string string
Definition: gtest.h:1979
doTest
bool doTest(ros::NodeHandle nh)
Definition: run_selftest.cpp:41
main
int main(int argc, char **argv)
Definition: run_selftest.cpp:85
ros::ServiceClient::call
bool call(const MReq &req, MRes &resp, const std::string &service_md5sum)
ros::NodeHandle


self_test
Author(s): Kevin Watts, Brice Rebsamen , Jeremy Leibs and Blaise Gassend
autogenerated on Tue Nov 15 2022 03:17:24