Main MRPT website > C++ reference for MRPT 1.5.6
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 
10 #include <mrpt/utils/poly_ptr.h>
11 #include <mrpt/utils/copy_ptr.h>
12 
13 #include <mrpt/poses/CPose2D.h>
14 #include <gtest/gtest.h>
15 
16 using namespace mrpt;
17 using namespace mrpt::utils;
18 using namespace std;
19 
20 TEST(copy_ptr, SimpleOps)
21 {
23  EXPECT_FALSE(ptr1);
24 
25  ptr1.reset(new int());
26  EXPECT_TRUE(ptr1);
27 
28  *ptr1 = 123;
29  EXPECT_TRUE(*ptr1==123);
30 
31  {
32  mrpt::utils::copy_ptr<int> ptr2 = ptr1;
33  EXPECT_TRUE(*ptr1 == *ptr2);
34 
35  (*ptr2)++;
36  EXPECT_FALSE(*ptr1 == *ptr2);
37  }
38  {
40  ptr2= ptr1;
41  EXPECT_TRUE(*ptr1 == *ptr2);
42 
43  (*ptr2)++;
44  EXPECT_FALSE(*ptr1 == *ptr2);
45  }
46 }
47 
48 TEST(copy_ptr, StlContainer)
49 {
51 
52  str2d_ptr ptr;
53  EXPECT_FALSE(ptr);
54 
55  std::vector<str2d_ptr> v;
56  for (int i = 0; i < 10; i++) {
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  v.push_back(str2d_ptr(new str2d_ptr::value_type));
108  v[i]->x(i);
109  }
110 
111  str2d_ptr v3 = v[3];
112  EXPECT_NEAR(v3->x(), 3.0, 1e-9);
113  v3->x_incr(1.0);
114 
115  EXPECT_NEAR(v3->x(), 4.0, 1e-9);
116  EXPECT_NEAR(v[3]->x(), 3.0, 1e-9);
117 }
const GLdouble * v
Definition: glew.h:1296
double x() const
Common members of all points & poses classes.
Definition: CPoseOrPoint.h:113
Smart pointer for non-polymorphic classes.
Definition: copy_ptr.h:26
void x_incr(const double v)
Definition: CPoseOrPoint.h:122
GLint GLint GLint GLint GLint x
Definition: glew.h:1166
TEST(copy_ptr, SimpleOps)
A class used to store a 2D pose, including the 2D coordinate point and a heading (phi) angle...
Definition: CPose2D.h:36
GLfloat GLfloat GLfloat GLfloat v3
Definition: glew.h:1767
Smart pointer for polymorphic classes with a clone() method.
Definition: poly_ptr.h:26



Page generated by Doxygen 1.8.6 for MRPT 1.5.6 Git: 4c65e84 Tue Apr 24 08:18:17 2018 +0200 at mar abr 24 08:26:17 CEST 2018