MRPT  2.0.4
poly_ptr_unittest.cpp
Go to the documentation of this file.
1 /* +------------------------------------------------------------------------+
2  | Mobile Robot Programming Toolkit (MRPT) |
3  | https://www.mrpt.org/ |
4  | |
5  | Copyright (c) 2005-2020, Individual contributors, see AUTHORS file |
6  | See: https://www.mrpt.org/Authors - All rights reserved. |
7  | Released under BSD License. See: https://www.mrpt.org/License |
8  +------------------------------------------------------------------------+ */
9 
10 #include <gtest/gtest.h>
12 #include <mrpt/core/common.h> // TODO
13 #include <mrpt/poses/CPose2D.h>
14 
15 using namespace mrpt;
16 using namespace std;
17 
18 TEST(copy_ptr, SimpleOps)
19 {
21  EXPECT_FALSE(ptr1);
22 
23  ptr1.reset(new int());
24  EXPECT_TRUE(ptr1);
25 
26  *ptr1 = 123;
27  EXPECT_TRUE(*ptr1 == 123);
28 
29  {
31  EXPECT_TRUE(*ptr1 == *ptr2);
32 
33  (*ptr2)++;
34  EXPECT_FALSE(*ptr1 == *ptr2);
35  }
36  {
38  ptr2 = ptr1;
39  EXPECT_TRUE(*ptr1 == *ptr2);
40 
41  (*ptr2)++;
42  EXPECT_FALSE(*ptr1 == *ptr2);
43  }
44 }
45 
46 TEST(copy_ptr, StlContainer)
47 {
49 
50  str2d_ptr ptr;
51  EXPECT_FALSE(ptr);
52 
53  std::vector<str2d_ptr> v;
54  for (int i = 0; i < 10; i++)
55  {
56  v.push_back(str2d_ptr(new str2d_ptr::value_type));
57  v[i]->first = "xxx";
58  v[i]->second = i;
59  }
60 
61  str2d_ptr v3 = v[3];
62  EXPECT_TRUE(v3->second == 3);
63  v3->second++;
64 
65  EXPECT_TRUE(v3->second == 4);
66  EXPECT_TRUE(v[3]->second == 3);
67 }
68 
69 TEST(poly_ptr, SimpleOps)
70 {
72  EXPECT_FALSE(ptr1);
73 
74  ptr1.reset(new mrpt::poses::CPose2D());
75  EXPECT_TRUE(ptr1);
76 
77  ptr1->x(123.0);
78  EXPECT_NEAR(ptr1->x(), 123.0, 1e-9);
79 
80  {
82  EXPECT_TRUE(*ptr1 == *ptr2);
83 
84  ptr2->x_incr(1.0);
85  EXPECT_FALSE(*ptr1 == *ptr2);
86  }
87  {
89  ptr2 = ptr1;
90  EXPECT_TRUE(*ptr1 == *ptr2);
91 
92  ptr2->x_incr(1.0);
93  EXPECT_FALSE(*ptr1 == *ptr2);
94  }
95 }
96 
97 TEST(poly_ptr, StlContainer)
98 {
100 
101  str2d_ptr ptr;
102  EXPECT_FALSE(ptr);
103 
104  std::vector<str2d_ptr> v;
105  for (int i = 0; i < 10; i++)
106  {
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 }
EXPECT_TRUE(mrpt::system::fileExists(ini_fil))
internal::generic_copier_ptr< T, internal::CopyCloner< T > > poly_ptr
Smart pointer for polymorphic classes with a clone() method.
Definition: deepcopy_ptr.h:153
STL namespace.
double x() const
Common members of all points & poses classes.
Definition: CPoseOrPoint.h:143
TEST(copy_ptr, SimpleOps)
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
void x_incr(const double v)
Definition: CPoseOrPoint.h:170
A class used to store a 2D pose, including the 2D coordinate point and a heading (phi) angle...
Definition: CPose2D.h:39
internal::generic_copier_ptr< T, internal::CopyStatic< T > > copy_ptr
Smart pointer for non-polymorphic classes.
Definition: deepcopy_ptr.h:161
EXPECT_NEAR(out.cam_params.rightCameraPose.x, 0.1194, 0.005)



Page generated by Doxygen 1.8.14 for MRPT 2.0.4 Git: 33de1d0ad Sat Jun 20 11:02:42 2020 +0200 at sáb jun 20 17:35:17 CEST 2020