Main MRPT website > C++ reference for MRPT 1.5.6
CSerializable_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 #define MRPT_NO_WARN_BIG_HDR // Yes, we really want to include all classes.
11 #include <mrpt/obs.h>
12 
14 #include <gtest/gtest.h>
15 
16 using namespace mrpt;
17 using namespace mrpt::obs;
18 using namespace mrpt::utils;
19 using namespace mrpt::math;
20 using namespace std;
21 
22 // Defined in tests/test_main.cpp
23 namespace mrpt { namespace utils {
25  }
26 }
27 
29  // Observations:
45 #if MRPT_HAS_OPENCV // These classes need CImage serialization
48 #endif
53  // Actions:
56  };
57 
58 
59 // Create a set of classes, then serialize and deserialize to test possible bugs:
60 TEST(SerializeTestObs, WriteReadToMem)
61 {
62  for (size_t i=0;i<sizeof(lstClasses)/sizeof(lstClasses[0]);i++)
63  {
64  try
65  {
66  CMemoryStream buf;
67  {
68  CSerializable* o = static_cast<CSerializable*>(lstClasses[i]->createObject());
69  buf << *o;
70  delete o;
71  }
72 
73  CSerializablePtr recons;
74  buf.Seek(0);
75  buf >> recons;
76  }
77  catch(std::exception &e)
78  {
79  GTEST_FAIL() <<
80  "Exception during serialization test for class '"<< lstClasses[i]->className <<"':\n" << e.what() << endl;
81  }
82  }
83 }
84 
85 // Also try to convert them to octect vectors:
86 TEST(SerializeTestObs, WriteReadToOctectVectors)
87 {
88  for (size_t i=0;i<sizeof(lstClasses)/sizeof(lstClasses[0]);i++)
89  {
90  try
91  {
93  {
94  CSerializable* o = static_cast<CSerializable*>(lstClasses[i]->createObject());
96  delete o;
97  }
98 
99  CSerializablePtr recons;
101  }
102  catch(std::exception &e)
103  {
104  GTEST_FAIL() <<
105  "Exception during serialization test for class '"<< lstClasses[i]->className <<"':\n" << e.what() << endl;
106  }
107  }
108 }
109 
void BASE_IMPEXP OctetVectorToObject(const vector_byte &in_data, CSerializablePtr &obj)
Converts back (de-serializes) a sequence of binary data into a MRPT object, without prior information...
This "observation" is actually a placeholder for a text block with comments or additional parameters ...
Declares a class derived from "CObservation" that encapsules an image from a camera, whose relative pose to robot is also stored.
This represents a measurement of the batteries on the robot.
Declares a class derived from "CObservation" that encapsules an omnidirectional RGBD measurement from...
Declares a class derived from "CObservation" that encapsules a single range measurement, and associated parameters.
Classes for serialization, sockets, ini-file manipulation, streams, list of properties-values, timewatch, extensions to STL.
Definition: zip.h:16
A CObservation-derived class for RAW DATA (and optionally, point cloud) of scans from 3D Velodyne LID...
std::string MRPT_GLOBAL_UNITTEST_SRC_DIR
std::vector< uint8_t > vector_byte
Definition: types_simple.h:26
TEST(SerializeTestObs, WriteReadToMem)
The virtual base class which provides a unified interface for all persistent objects in MRPT...
Definition: CSerializable.h:39
This class stores a message from a CAN BUS with the protocol J1939.
Declares a class derived from "CObservation" that encapsules a 3D range scan measurement, as from a time-of-flight range camera or any other RGBD sensor.
Declares a class derived from "CObservation" that represents one (or more) range measurements to labe...
Declares a class derived from "CObservation" that encapsules a single short-range reflectivity measur...
STL namespace.
This class stores measurements from an Inertial Measurement Unit (IMU) (attitude estimation, raw gyroscope and accelerometer values), altimeters or magnetometers.
Represents a probabilistic 3D (6D) movement.
Represents a probabilistic 2D movement of the robot mobile base.
This base provides a set of functions for maths stuff.
Definition: CArrayNumeric.h:19
mrpt::utils::CObject * createObject() const
Definition: CObject.cpp:89
void BASE_IMPEXP ObjectToOctetVector(const CSerializable *o, vector_byte &out_vector)
Converts (serializes) an MRPT object into an array of bytes.
This CStream derived class allow using a memory buffer as a CStream.
Definition: CMemoryStream.h:26
Observation class for either a pair of left+right or left+disparity images from a stereo camera...
This namespace contains representation of robot actions and observations.
Declares a class derived from "CObservation" that represents a set of readings from gas sensors...
GLsizei const GLchar ** string
Definition: glext.h:3919
Store raw data from a Data Acquisition (DAQ) device, such that input or output analog and digital cha...
This represents a measurement of the wireless strength perceived by the robot.
#define CLASS_ID(class_name)
Access to runtime class ID for a defined class name.
Definition: CObject.h:92
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
A "CObservation"-derived class that represents a 2D range scan measurement (typically from a laser sc...
An observation of one or more "features" or "objects", possibly identified with a unique ID...
This observation represents a number of range-bearing value pairs, each one for a detected landmark...
uint64_t Seek(int64_t Offset, CStream::TSeekOrigin Origin=sFromBeginning) MRPT_OVERRIDE
Introduces a pure virtual method for moving to a specified position in the streamed resource...
const mrpt::utils::TRuntimeClassId * lstClasses[]
This represents one or more RFID tags observed by a receiver.
A structure that holds runtime class type information.
Definition: CObject.h:46
An observation of the current (cumulative) odometry for a wheeled robot.
const char * className
Definition: CObject.h:48
This class stores messages from GNSS or GNSS+IMU devices, from consumer-grade inexpensive GPS receive...



Page generated by Doxygen 1.8.14 for MRPT 1.5.6 Git: 4c65e8431 Tue Apr 24 08:18:17 2018 +0200 at lun oct 28 01:35:26 CET 2019