Main MRPT website > C++ reference for MRPT 1.9.9
poly_ptr_unittest.cpp
Go to the documentation of this file.
1 /* +------------------------------------------------------------------------+
2  | Mobile Robot Programming Toolkit (MRPT) |
3  | http://www.mrpt.org/ |
4  | |
5  | Copyright (c) 2005-2017, Individual contributors, see AUTHORS file |
6  | See: http://www.mrpt.org/Authors - All rights reserved. |
7  | Released under BSD License. See details in http://www.mrpt.org/License |
8  +------------------------------------------------------------------------+ */
9 
11 
12 #include <mrpt/poses/CPose2D.h>
13 #include <gtest/gtest.h>
14 
15 using namespace mrpt;
16 using namespace mrpt::utils;
17 using namespace std;
18 
19 TEST(copy_ptr, SimpleOps)
20 {
22  EXPECT_FALSE(ptr1);
23 
24  ptr1.reset(new int());
25  EXPECT_TRUE(ptr1);
26 
27  *ptr1 = 123;
28  EXPECT_TRUE(*ptr1 == 123);
29 
30  {
31  mrpt::utils::copy_ptr<int> ptr2 = ptr1;
32  EXPECT_TRUE(*ptr1 == *ptr2);
33 
34  (*ptr2)++;
35  EXPECT_FALSE(*ptr1 == *ptr2);
36  }
37  {
39  ptr2 = ptr1;
40  EXPECT_TRUE(*ptr1 == *ptr2);
41 
42  (*ptr2)++;
43  EXPECT_FALSE(*ptr1 == *ptr2);
44  }
45 }
46 
47 TEST(copy_ptr, StlContainer)
48 {
50 
51  str2d_ptr ptr;
52  EXPECT_FALSE(ptr);
53 
54  std::vector<str2d_ptr> v;
55  for (int i = 0; i < 10; i++)
56  {
57  v.push_back(str2d_ptr(new str2d_ptr::value_type));
58  v[i]->first = "xxx";
59  v[i]->second = i;
60  }
61 
62  str2d_ptr v3 = v[3];
63  EXPECT_TRUE(v3->second == 3);
64  v3->second++;
65 
66  EXPECT_TRUE(v3->second == 4);
67  EXPECT_TRUE(v[3]->second == 3);
68 }
69 
70 TEST(poly_ptr, SimpleOps)
71 {
73  EXPECT_FALSE(ptr1);
74 
75  ptr1.reset(new mrpt::poses::CPose2D());
76  EXPECT_TRUE(ptr1);
77 
78  ptr1->x(123.0);
79  EXPECT_NEAR(ptr1->x(), 123.0, 1e-9);
80 
81  {
83  EXPECT_TRUE(*ptr1 == *ptr2);
84 
85  ptr2->x_incr(1.0);
86  EXPECT_FALSE(*ptr1 == *ptr2);
87  }
88  {
90  ptr2 = ptr1;
91  EXPECT_TRUE(*ptr1 == *ptr2);
92 
93  ptr2->x_incr(1.0);
94  EXPECT_FALSE(*ptr1 == *ptr2);
95  }
96 }
97 
98 TEST(poly_ptr, StlContainer)
99 {
101 
102  str2d_ptr ptr;
103  EXPECT_FALSE(ptr);
104 
105  std::vector<str2d_ptr> v;
106  for (int i = 0; i < 10; i++)
107  {
108  v.push_back(str2d_ptr(new str2d_ptr::value_type));
109  v[i]->x(i);
110  }
111 
112  str2d_ptr v3 = v[3];
113  EXPECT_NEAR(v3->x(), 3.0, 1e-9);
114  v3->x_incr(1.0);
115 
116  EXPECT_NEAR(v3->x(), 4.0, 1e-9);
117  EXPECT_NEAR(v[3]->x(), 3.0, 1e-9);
118 }
double x() const
Common members of all points & poses classes.
Definition: CPoseOrPoint.h:135
Classes for serialization, sockets, ini-file manipulation, streams, list of properties-values, timewatch, extensions to STL.
STL namespace.
void x_incr(const double v)
Definition: CPoseOrPoint.h:162
GLfloat GLfloat GLfloat GLfloat v3
Definition: glext.h:4109
const GLdouble * v
Definition: glext.h:3678
TEST(copy_ptr, SimpleOps)
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
A class used to store a 2D pose, including the 2D coordinate point and a heading (phi) angle...
Definition: CPose2D.h:40
GLenum GLint x
Definition: glext.h:3538



Page generated by Doxygen 1.8.14 for MRPT 1.9.9 Git: ae4571287 Thu Nov 23 00:06:53 2017 +0100 at dom oct 27 23:51:55 CET 2019