test_names.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2009, 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 /* Author: Josh Faust */
31 
32 /*
33  * Test Header serialization/deserialization
34  */
35 
36 #include <gtest/gtest.h>
37 #include "ros/init.h"
38 #include "ros/names.h"
39 
40 using namespace ros;
41 
42 TEST(Names, validation)
43 {
44  std::string error;
45  EXPECT_TRUE(names::validate("", error));
46  EXPECT_TRUE(names::validate("hello", error));
47  EXPECT_TRUE(names::validate("/hello/asdf", error));
48  EXPECT_TRUE(names::validate("hello/fdas", error));
49  EXPECT_TRUE(names::validate("/hello", error));
50  EXPECT_TRUE(names::validate("~hello", error));
51  EXPECT_TRUE(names::validate("/hello_world/blah_world", error));
52  EXPECT_TRUE(names::validate("hello123_421", error));
53  EXPECT_FALSE(names::validate("123hello", error));
54  EXPECT_FALSE(names::validate("_hello", error));
55  EXPECT_FALSE(names::validate("h~ello", error));
56  EXPECT_FALSE(names::validate("%hello", error));
57  EXPECT_FALSE(names::validate("h ello", error));
58  EXPECT_FALSE(names::validate("h*ello", error));
59  EXPECT_FALSE(names::validate("h?ello", error));
60 }
61 
62 TEST(Names, parentNamespace)
63 {
64  //edge casee
65  EXPECT_STREQ(std::string("").c_str(), names::parentNamespace("").c_str());
66  EXPECT_STREQ(std::string("/").c_str(), names::parentNamespace("/").c_str());
67  EXPECT_STREQ(std::string("/").c_str(), names::parentNamespace("/a").c_str());
68  EXPECT_STREQ(std::string("/").c_str(), names::parentNamespace("/a/").c_str()); //trailing slash
69 
70  //2 long
71  EXPECT_STREQ(std::string("/a").c_str(), names::parentNamespace("/a/b").c_str());
72  EXPECT_STREQ(std::string("/a").c_str(), names::parentNamespace("/a/b/").c_str()); //trailing slash
73  EXPECT_STREQ(std::string("/asdf").c_str(), names::parentNamespace("/asdf/b").c_str());
74 
75  //3 long
76  EXPECT_STREQ(std::string("/z/a").c_str(), names::parentNamespace("/z/a/b").c_str());
77  EXPECT_STREQ(std::string("/z/a").c_str(), names::parentNamespace("/z/a/b/").c_str()); //trailing slash
78  EXPECT_STREQ(std::string("/z/asdf").c_str(), names::parentNamespace("/z/asdf/b").c_str());
79 }
80 
81 TEST(Names, init_empty_node_name)
82 {
83  int argc = 0;
84  char** argv = NULL;
85  EXPECT_THROW(ros::init(argc, argv, ""), ros::InvalidNameException);
86 }
87 
88 int
89 main(int argc, char** argv)
90 {
91  testing::InitGoogleTest(&argc, argv);
92  return RUN_ALL_TESTS();
93 }
94 
95 
TEST(Names, validation)
Definition: test_names.cpp:42
ROSCPP_DECL std::string parentNamespace(const std::string &name)
ROSCPP_DECL void init(int &argc, char **argv, const std::string &name, uint32_t options=0)
ROSCPP_DECL bool validate(const std::string &name, std::string &error)
int main(int argc, char **argv)
Definition: test_names.cpp:89


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