Main MRPT website > C++ reference for MRPT 1.9.9
CLogFileRecord_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 
12 #include <mrpt/system/filesystem.h>
13 #include <gtest/gtest.h>
14 
15 using namespace mrpt;
16 using namespace mrpt::utils;
17 using namespace mrpt::nav;
18 using namespace std;
19 
20 // Defined in tests/test_main.cpp
21 namespace mrpt
22 {
23 namespace utils
24 {
26 }
27 }
28 
31 };
32 
33 // Create a set of classes, then serialize and deserialize to test possible
34 // bugs:
35 TEST(NavTests, Serialization_WriteReadToMem)
36 {
37  for (size_t i = 0; i < sizeof(lstClasses) / sizeof(lstClasses[0]); i++)
38  {
39  try
40  {
41  CMemoryStream buf;
42  {
43  CSerializable* o =
44  static_cast<CSerializable*>(lstClasses[i]->createObject());
45  buf << *o;
46  delete o;
47  }
48 
49  CSerializable::Ptr recons;
50  buf.Seek(0);
51  buf >> recons;
52  }
53  catch (std::exception& e)
54  {
55  GTEST_FAIL() << "Exception during serialization test for class '"
56  << lstClasses[i]->className << "':\n"
57  << e.what() << endl;
58  }
59  }
60 }
61 
62 // Also try to convert them to octect vectors:
63 TEST(SerializeTestObs, WriteReadToOctectVectors)
64 {
65  for (size_t i = 0; i < sizeof(lstClasses) / sizeof(lstClasses[0]); i++)
66  {
67  try
68  {
70  {
71  CSerializable* o =
72  static_cast<CSerializable*>(lstClasses[i]->createObject());
74  delete o;
75  }
76 
77  CSerializable::Ptr recons;
79  }
80  catch (std::exception& e)
81  {
82  GTEST_FAIL() << "Exception during serialization test for class '"
83  << lstClasses[i]->className << "':\n"
84  << e.what() << endl;
85  }
86  }
87 }
88 
89 // Load test datalog
90 TEST(NavTests, NavLogLoadFromTestFile)
91 {
92  const string navlog_file =
94  string("/tests/serialize_test_data.reactivenavlog");
95  if (!mrpt::system::fileExists(navlog_file))
96  {
97  cerr << "WARNING: Skipping test due to missing file: " << navlog_file
98  << "\n";
99  return;
100  }
101 
102  CFileGZInputStream f(navlog_file);
103 
104  try
105  {
106  for (int i = 0; i < 2; i++)
107  {
109  f.ReadObject(&lfr);
110  }
111  }
112  catch (std::exception& e)
113  {
114  FAIL() << "Failed to parse stored navlog. Exception was:\n"
115  << e.what() << endl;
116  }
117 }
Classes for serialization, sockets, ini-file manipulation, streams, list of properties-values, timewatch, extensions to STL.
std::string MRPT_GLOBAL_UNITTEST_SRC_DIR
std::vector< uint8_t > vector_byte
Definition: types_simple.h:27
The virtual base class which provides a unified interface for all persistent objects in MRPT...
Definition: CSerializable.h:44
uint64_t Seek(uint64_t Offset, CStream::TSeekOrigin Origin=sFromBeginning) override
Introduces a pure virtual method for moving to a specified position in the streamed resource...
bool fileExists(const std::string &fileName)
Test if a given file (or directory) exists.
Definition: filesystem.cpp:127
STL namespace.
A class for storing, saving and loading a reactive navigation log record for the CReactiveNavigationS...
void OctetVectorToObject(const vector_byte &in_data, CSerializable::Ptr &obj)
Converts back (de-serializes) a sequence of binary data into a MRPT object, without prior information...
CSerializable::Ptr ReadObject()
Reads an object from stream, its class determined at runtime, and returns a smart pointer to the obje...
Definition: CStream.h:207
mrpt::utils::CObject * createObject() const
Definition: CObject.cpp:93
#define CLASS_ID(T)
Access to runtime class ID for a defined class name.
Definition: CObject.h:85
void 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:27
Transparently opens a compressed "gz" file and reads uncompressed data from it.
GLsizei const GLchar ** string
Definition: glext.h:4101
const mrpt::utils::TRuntimeClassId * lstClasses[]
std::shared_ptr< CSerializable > Ptr
Definition: CSerializable.h:47
TEST(NavTests, Serialization_WriteReadToMem)
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
A structure that holds runtime class type information.
Definition: CObject.h:31
const char * className
Definition: CObject.h:34



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