Main MRPT website > C++ reference for MRPT 1.5.6
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 { namespace utils {
23  }
24 }
25 
28 };
29 
30 // Create a set of classes, then serialize and deserialize to test possible bugs:
31 TEST(NavTests, Serialization_WriteReadToMem)
32 {
33  for (size_t i = 0; i<sizeof(lstClasses) / sizeof(lstClasses[0]); i++)
34  {
35  try
36  {
37  CMemoryStream buf;
38  {
39  CSerializable* o = static_cast<CSerializable*>(lstClasses[i]->createObject());
40  buf << *o;
41  delete o;
42  }
43 
44  CSerializablePtr recons;
45  buf.Seek(0);
46  buf >> recons;
47  }
48  catch (std::exception &e)
49  {
50  GTEST_FAIL() <<
51  "Exception during serialization test for class '" << lstClasses[i]->className << "':\n" << e.what() << endl;
52  }
53  }
54 }
55 
56 // Also try to convert them to octect vectors:
57 TEST(SerializeTestObs, WriteReadToOctectVectors)
58 {
59  for (size_t i = 0; i<sizeof(lstClasses) / sizeof(lstClasses[0]); i++)
60  {
61  try
62  {
64  {
65  CSerializable* o = static_cast<CSerializable*>(lstClasses[i]->createObject());
67  delete o;
68  }
69 
70  CSerializablePtr recons;
72  }
73  catch (std::exception &e)
74  {
75  GTEST_FAIL() <<
76  "Exception during serialization test for class '" << lstClasses[i]->className << "':\n" << e.what() << endl;
77  }
78  }
79 }
80 
81 
82 
83 
84 // Load test datalog
85 TEST(NavTests, NavLogLoadFromTestFile)
86 {
87  const string navlog_file = MRPT_GLOBAL_UNITTEST_SRC_DIR + string("/tests/serialize_test_data.reactivenavlog");
88  if (!mrpt::system::fileExists(navlog_file))
89  {
90  cerr << "WARNING: Skipping test due to missing file: " << navlog_file << "\n";
91  return;
92  }
93 
94  CFileGZInputStream f(navlog_file);
95 
96  try
97  {
98  for (int i=0;i<2;i++)
99  {
101  f.ReadObject(&lfr);
102  }
103  }
104  catch (std::exception &e)
105  {
106  FAIL() << "Failed to parse stored navlog. Exception was:\n" << e.what() << endl;
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...
CSerializablePtr ReadObject()
Reads an object from stream, its class determined at runtime, and returns a smart pointer to the obje...
Definition: CStream.cpp:486
Classes for serialization, sockets, ini-file manipulation, streams, list of properties-values, timewatch, extensions to STL.
Definition: zip.h:16
std::string MRPT_GLOBAL_UNITTEST_SRC_DIR
std::vector< uint8_t > vector_byte
Definition: types_simple.h:26
The virtual base class which provides a unified interface for all persistent objects in MRPT...
Definition: CSerializable.h:39
bool BASE_IMPEXP fileExists(const std::string &fileName)
Test if a given file (or directory) exists.
Definition: filesystem.cpp:124
STL namespace.
A class for storing, saving and loading a reactive navigation log record for the CReactiveNavigationS...
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
Transparently opens a compressed "gz" file and reads uncompressed data from it.
GLsizei const GLchar ** string
Definition: glext.h:3919
const mrpt::utils::TRuntimeClassId * lstClasses[]
TEST(NavTests, Serialization_WriteReadToMem)
#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.
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...
A structure that holds runtime class type information.
Definition: CObject.h:46
const char * className
Definition: CObject.h:48



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