MRPT  2.0.3
CLogFileRecord_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>
14 #include <mrpt/system/filesystem.h>
15 #include <test_mrpt_common.h>
16 
17 using namespace mrpt;
18 using namespace mrpt::nav;
19 using namespace mrpt::io;
20 using namespace mrpt::serialization;
21 using namespace std;
22 
25 };
26 
27 // Create a set of classes, then serialize and deserialize to test possible
28 // bugs:
29 TEST(NavTests, Serialization_WriteReadToMem)
30 {
31  for (auto& cl : lstClasses)
32  {
33  try
34  {
35  CMemoryStream buf;
36  auto arch = archiveFrom(buf);
37  {
38  auto o =
39  mrpt::ptr_cast<CSerializable>::from(cl->createObject());
40  arch << *o;
41  }
42 
43  CSerializable::Ptr recons;
44  buf.Seek(0);
45  arch >> recons;
46  }
47  catch (const std::exception& e)
48  {
49  GTEST_FAIL() << "Exception during serialization test for class '"
50  << cl->className << "':\n"
51  << e.what() << endl;
52  }
53  }
54 }
55 
56 // Also try to convert them to octect vectors:
57 TEST(SerializeTestObs, WriteReadToOctectVectors)
58 {
59  for (auto& cl : lstClasses)
60  {
61  try
62  {
63  std::vector<uint8_t> buf;
64  {
65  auto o =
66  mrpt::ptr_cast<CSerializable>::from(cl->createObject());
68  }
69 
70  CSerializable::Ptr recons;
72  }
73  catch (const std::exception& e)
74  {
75  GTEST_FAIL() << "Exception during serialization test for class '"
76  << cl->className << "':\n"
77  << e.what() << endl;
78  }
79  }
80 }
81 
82 // Load test datalog
83 TEST(NavTests, NavLogLoadFromTestFile)
84 {
85  const string navlog_file =
86  UNITTEST_BASEDIR + string("/tests/serialize_test_data.reactivenavlog");
87  if (!mrpt::system::fileExists(navlog_file))
88  {
89  cerr << "WARNING: Skipping test due to missing file: " << navlog_file
90  << "\n";
91  return;
92  }
93 
94  CFileGZInputStream f(navlog_file);
95  auto arch = archiveFrom(f);
96 
97  try
98  {
99  for (int i = 0; i < 2; i++)
100  {
102  arch.ReadObject(&lfr);
103  }
104  }
105  catch (const std::exception& e)
106  {
107  FAIL() << "Failed to parse stored navlog. Exception was:\n"
108  << e.what() << endl;
109  }
110 }
mrpt::io::CMemoryStream::Seek
uint64_t Seek(int64_t Offset, CStream::TSeekOrigin Origin=sFromBeginning) override
Introduces a pure virtual method for moving to a specified position in the streamed resource.
Definition: CMemoryStream.cpp:126
filesystem.h
mrpt::nav::CLogFileRecord
A class for storing, saving and loading a reactive navigation log record for the CReactiveNavigationS...
Definition: CLogFileRecord.h:29
mrpt::rtti::TRuntimeClassId
A structure that holds runtime class type information.
Definition: CObject.h:31
mrpt::io
Definition: img/CImage.h:24
mrpt::serialization::CSerializable::Ptr
std::shared_ptr< CSerializable > Ptr
Definition: CSerializable.h:36
TEST
TEST(NavTests, Serialization_WriteReadToMem)
Definition: CLogFileRecord_unittest.cpp:29
mrpt::nav
Definition: CAbstractHolonomicReactiveMethod.h:20
mrpt
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
Definition: BaseAppDataSource.h:15
mrpt::system::fileExists
bool fileExists(const std::string &fileName)
Test if a given file (or directory) exists.
Definition: filesystem.cpp:128
mrpt::io::CFileGZInputStream
Transparently opens a compressed "gz" file and reads uncompressed data from it.
Definition: io/CFileGZInputStream.h:26
mrpt::ptr_cast::from
static CAST_TO::Ptr from(const CAST_FROM_PTR &ptr)
Definition: CObject.h:356
mrpt::io::CMemoryStream
This CStream derived class allow using a memory buffer as a CStream.
Definition: io/CMemoryStream.h:26
mrpt::serialization
Definition: aligned_serialization.h:13
CLogFileRecord.h
mrpt::serialization::OctetVectorToObject
void OctetVectorToObject(const std::vector< uint8_t > &in_data, CSerializable::Ptr &obj)
Converts back (de-serializes) a sequence of binary data into a MRPT object, without prior information...
Definition: CSerializable.cpp:29
mrpt::serialization::archiveFrom
CArchiveStreamBase< STREAM > archiveFrom(STREAM &s)
Helper function to create a templatized wrapper CArchive object for a: MRPT's CStream,...
Definition: CArchive.h:592
CLASS_ID
#define CLASS_ID(T)
Access to runtime class ID for a defined class name.
Definition: CObject.h:102
CFileGZInputStream.h
lstClasses
const mrpt::rtti::TRuntimeClassId * lstClasses[]
Definition: CLogFileRecord_unittest.cpp:23
mrpt::serialization::ObjectToOctetVector
void ObjectToOctetVector(const CSerializable *o, std::vector< uint8_t > &out_vector)
Converts (serializes) an MRPT object into an array of bytes.
Definition: CSerializable.cpp:21
CArchive.h



Page generated by Doxygen 1.8.17 for MRPT 2.0.3 at Fri May 15 23:51:15 UTC 2020