parameter_validation.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2010, Willow Garage, Inc.
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions are met:
7  *
8  * * Redistributions of source code must retain the above copyright
9  * notice, this list of conditions and the following disclaimer.
10  * * Redistributions in binary form must reproduce the above copyright
11  * notice, this list of conditions and the following disclaimer in the
12  * documentation and/or other materials provided with the distribution.
13  * * Neither the name of Willow Garage, Inc. nor the names of its
14  * contributors may be used to endorse or promote products derived from
15  * this software without specific prior written permission.
16  *
17  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
21  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27  * POSSIBILITY OF SUCH DAMAGE.
28  */
29 
30 #include <gtest/gtest.h>
31 
32 #include <ros/ros.h>
33 
34 #include <test_roscpp/TestEmpty.h>
35 
36 #define ASSERT_THROWS(expr) \
37  try \
38  { \
39  expr; \
40  FAIL(); \
41  } \
42  catch (std::exception& e) \
43  { \
44  ROS_INFO("Caught exception: %s", e.what());\
45  }
46 
47 void callback(const test_roscpp::TestEmptyConstPtr&)
48 {
49 
50 }
51 
52 TEST(ParameterValidation, subscribeEmptyMD5Sum)
53 {
54  ros::NodeHandle nh;
56  ops.init<test_roscpp::TestEmpty>("blah", 0, callback);
57  ops.md5sum.clear();
58  ASSERT_THROWS(nh.subscribe(ops));
59 }
60 
61 TEST(ParameterValidation, subscribeEmptyDataType)
62 {
63  ros::NodeHandle nh;
65  ops.init<test_roscpp::TestEmpty>("blah", 0, callback);
66  ops.datatype.clear();
67  ASSERT_THROWS(nh.subscribe(ops));
68 }
69 
70 TEST(ParameterValidation, subscribeNoCallback)
71 {
72  ros::NodeHandle nh;
73  ros::SubscribeOptions ops("blah", 0, "blah", "blah");
74  ASSERT_THROWS(nh.subscribe(ops));
75 }
76 
77 TEST(ParameterValidation, advertiseEmptyMD5Sum)
78 {
79  ros::NodeHandle nh;
80  ros::AdvertiseOptions ops("blah", 0, "", "blah", "blah");
81  ASSERT_THROWS(nh.advertise(ops));
82 }
83 
84 TEST(ParameterValidation, advertiseEmptyDataType)
85 {
86  ros::NodeHandle nh;
87  ros::AdvertiseOptions ops("blah", 0, "blah", "", "blah");
88  ASSERT_THROWS(nh.advertise(ops));
89 }
90 
91 TEST(ParameterValidation, advertiseStarMD5Sum)
92 {
93  ros::NodeHandle nh;
94  ros::AdvertiseOptions ops("blah", 0, "*", "blah", "blah");
95  ASSERT_THROWS(nh.advertise(ops));
96 }
97 
98 TEST(ParameterValidation, advertiseStarDataType)
99 {
100  ros::NodeHandle nh;
101  ros::AdvertiseOptions ops("blah", 0, "blah", "*", "blah");
102  ASSERT_THROWS(nh.advertise(ops));
103 }
104 
105 int main(int argc, char** argv)
106 {
107  testing::InitGoogleTest(&argc, argv);
108  ros::init(argc, argv, "parameter_validation");
109 
110  ros::NodeHandle nh;
111 
112  return RUN_ALL_TESTS();
113 }
void callback(const test_roscpp::TestEmptyConstPtr &)
int main(int argc, char **argv)
Subscriber subscribe(const std::string &topic, uint32_t queue_size, void(T::*fp)(M), T *obj, const TransportHints &transport_hints=TransportHints())
ROSCPP_DECL void init(int &argc, char **argv, const std::string &name, uint32_t options=0)
TEST(ParameterValidation, subscribeEmptyMD5Sum)
Publisher advertise(const std::string &topic, uint32_t queue_size, bool latch=false)
#define ASSERT_THROWS(expr)
void init(const std::string &_topic, uint32_t _queue_size, const boost::function< void(const boost::shared_ptr< M const > &)> &_callback, const boost::function< boost::shared_ptr< M >(void)> &factory_fn=DefaultMessageCreator< M >())


test_roscpp
Author(s): Morgan Quigley, Josh Faust, Brian Gerkey, Troy Straszheim, Dirk Thomas
autogenerated on Mon Nov 2 2020 03:52:46