config_test.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2011, 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 the 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 #include <rviz/config.h>
32 
33 #include <ros/package.h> // For ros::package::getPath()
34 
35 TEST(Config, set_then_get)
36 {
37  rviz::Config c;
38  c.mapSetValue("a", "1");
39  int a;
40  EXPECT_TRUE(c.mapGetInt("a", &a));
41  EXPECT_EQ(a, 1);
42  float aa;
43  EXPECT_TRUE(c.mapGetFloat("a", &aa));
44  EXPECT_EQ(aa, 1.0);
45  QString aaa;
46  EXPECT_TRUE(c.mapGetString("a", &aaa));
47  EXPECT_EQ(aaa, "1");
48 }
49 
50 TEST(Config, parse_floats)
51 {
52  rviz::Config c;
53  c.mapSetValue("f", "1.1");
54  float f;
55  EXPECT_TRUE(c.mapGetFloat("f", &f));
56  EXPECT_EQ(f, 1.1f);
57 
58  // In Europe they use "," for a decimal point.
59  c.mapSetValue("f", "1,2");
60  EXPECT_TRUE(c.mapGetFloat("f", &f));
61  EXPECT_EQ(f, 1.2f);
62 }
63 
64 TEST(Config, set_get_empty_value)
65 {
66  rviz::Config c;
67  c.mapSetValue("key", "");
68 
69  QString s;
70  EXPECT_TRUE(c.mapGetString("key", &s));
71  EXPECT_EQ("", s);
72 }
73 
74 int main(int argc, char** argv)
75 {
76  testing::InitGoogleTest(&argc, argv);
77  return RUN_ALL_TESTS();
78 }
s
XmlRpcServer s
f
f
package.h
rviz::Config::mapGetString
bool mapGetString(const QString &key, QString *value_out) const
Convenience function for looking up a named string.
Definition: config.cpp:288
config.h
rviz::Config::mapGetInt
bool mapGetInt(const QString &key, int *value_out) const
Convenience function for looking up a named integer.
Definition: config.cpp:235
main
int main(int argc, char **argv)
Definition: config_test.cpp:74
TEST
TEST(Config, set_then_get)
Definition: config_test.cpp:35
rviz::Config::mapGetFloat
bool mapGetFloat(const QString &key, float *value_out) const
Convenience function for looking up a named float.
Definition: config.cpp:251
rviz::Config
Configuration data storage class.
Definition: config.h:124
rviz::Config::mapSetValue
void mapSetValue(const QString &key, const QVariant &value)
Set a named child to the given value.
Definition: config.cpp:183


rviz
Author(s): Dave Hershberger, David Gossow, Josh Faust, William Woodall
autogenerated on Fri Dec 13 2024 03:31:02