PointerTest.cpp
Go to the documentation of this file.
1 /******************************************************************************
2  * Copyright (C) 2014 by Ralf Kaestner *
3  * ralf.kaestner@gmail.com *
4  * *
5  * This program is free software; you can redistribute it and/or modify *
6  * it under the terms of the Lesser GNU General Public License as published by*
7  * the Free Software Foundation; either version 3 of the License, or *
8  * (at your option) any later version. *
9  * *
10  * This program is distributed in the hope that it will be useful, *
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13  * Lesser GNU General Public License for more details. *
14  * *
15  * You should have received a copy of the Lesser GNU General Public License *
16  * along with this program. If not, see <http://www.gnu.org/licenses/>. *
17  ******************************************************************************/
18 
19 #include <gtest/gtest.h>
20 
21 #include <variant_msgs/Test.h>
22 
26 
27 using namespace variant_topic_tools;
28 
29 TEST(Pointer, Builtin) {
30  BuiltinPointer<int> p1(new int());
32 
33  EXPECT_TRUE(p1);
34  EXPECT_NO_THROW(*p1);
35 
36  EXPECT_FALSE(p2);
37  EXPECT_ANY_THROW(*p2);
38 }
39 
40 TEST(Pointer, Array) {
41  boost::array<int, 3>* a1 = new boost::array<int, 3>();
42  (*a1)[0] = 0;
43  (*a1)[1] = 1;
44  (*a1)[2] = 2;
46 
47  std::vector<int>* a2 = new std::vector<int>(3);
48  (*a2)[0] = 0;
49  (*a2)[1] = 1;
50  (*a2)[2] = 2;
51  ArrayMemberPointer<int[]> p2(a2, 1);
53 
54  EXPECT_EQ(a1, p1.getArray().get());
55  EXPECT_EQ(1, p1.getIndex());
56  EXPECT_EQ(1, *p1);
57 
58  EXPECT_EQ(a2, p2.getArray().get());
59  EXPECT_EQ(1, p2.getIndex());
60  EXPECT_EQ(1, *p2);
61 
62  EXPECT_EQ(a2, p3.getArray().get());
63  EXPECT_EQ(2, p3.getIndex());
64  EXPECT_EQ(2, *p3);
65 }
66 
68  variant_msgs::Test* m1 = new variant_msgs::Test();
69  m1->builtin_int = 42;
70  m1->builtin_string = "Test";
71 
73  offsetof(variant_msgs::Test, builtin_int));
75  p1.getMessage(), offsetof(variant_msgs::Test, builtin_string));
76 
77  EXPECT_EQ(m1, p1.getMessage().get());
78  EXPECT_EQ(offsetof(variant_msgs::Test, builtin_int), p1.getOffset());
79  EXPECT_EQ(m1->builtin_int, *p1);
80 
81  EXPECT_EQ(m1, p2.getMessage().get());
82  EXPECT_EQ(offsetof(variant_msgs::Test, builtin_string), p2.getOffset());
83  EXPECT_EQ(m1->builtin_string, *p2);
84 }
85 
86 TEST(Pointer, ArrayOfMessages) {
87  variant_msgs::Test* m1 = new variant_msgs::Test();
88  m1->string_array[1].data = "Test";
89 
91  p1(m1, offsetof(variant_msgs::Test, string_array));
94  p3(p2, offsetof(std_msgs::String, data));
95 
96  EXPECT_EQ(m1, p1.getMessage().get());
97  EXPECT_EQ(offsetof(variant_msgs::Test, string_array), p1.getOffset());
98 
99  EXPECT_EQ(&m1->string_array, p2.getArray().get());
100  EXPECT_EQ(1, p2.getIndex());
101 
102  EXPECT_EQ(&m1->string_array[1], p3.getMessage().get());
103  EXPECT_EQ(offsetof(std_msgs::String, data), p3.getOffset());
104 
105  EXPECT_NO_THROW(p1.reset());
106  EXPECT_ANY_THROW(*p1);
107  EXPECT_NO_THROW(*p2);
108  EXPECT_NO_THROW(*p3);
109  EXPECT_EQ("Test", *p3);
110  EXPECT_NO_THROW(p2.reset());
111  EXPECT_ANY_THROW(*p2);
112  EXPECT_NO_THROW(*p3);
113  EXPECT_EQ("Test", *p3);
114  EXPECT_NO_THROW(p3.reset());
115 }
Generic message type.
Definition: Message.h:43
Shared pointer to an array member.
size_t getOffset() const
Retrieve the message member offset.
T * get() const
Retrieve the stored pointer.
const Pointer< ValueType > & getMessage() const
Retrieve the message.
size_t getIndex() const
Retrieve the array member index.
Header file providing the BuiltinPointer class interface.
TEST(Pointer, Builtin)
Definition: PointerTest.cpp:29
Shared pointer.
Definition: Pointer.h:33
Shared pointer to a built-in variable.
Header file providing the ArrayMemberPointer class interface.
const Pointer< ValueType > & getArray() const
Retrieve the array.
Header file providing the MessageMemberPointer class interface.


variant_topic_tools
Author(s): Ralf Kaestner
autogenerated on Sat Jan 9 2021 03:56:50