MRPT  1.9.9
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 }
bool fileExists(const std::string &fileName)
Test if a given file (or directory) exists.
Definition: filesystem.cpp:128
void ObjectToOctetVector(const CSerializable *o, std::vector< uint8_t > &out_vector)
Converts (serializes) an MRPT object into an array of bytes.
A structure that holds runtime class type information.
Definition: CObject.h:31
STL namespace.
A class for storing, saving and loading a reactive navigation log record for the CReactiveNavigationS...
CArchiveStreamBase< STREAM > archiveFrom(STREAM &s)
Helper function to create a templatized wrapper CArchive object for a: MRPT&#39;s CStream, std::istream, std::ostream, std::stringstream.
Definition: CArchive.h:592
#define CLASS_ID(T)
Access to runtime class ID for a defined class name.
Definition: CObject.h:102
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...
This CStream derived class allow using a memory buffer as a CStream.
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...
TEST(NavTests, Serialization_WriteReadToMem)
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
static CAST_TO::Ptr from(const CAST_FROM_PTR &ptr)
Definition: CObject.h:356
const mrpt::rtti::TRuntimeClassId * lstClasses[]
Transparently opens a compressed "gz" file and reads uncompressed data from it.



Page generated by Doxygen 1.8.14 for MRPT 1.9.9 Git: c7a3bec24 Sun Mar 29 18:33:13 2020 +0200 at dom mar 29 18:50:38 CEST 2020