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-2018, 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>
14 #include <gtest/gtest.h>
15 
16 using namespace mrpt;
17 using namespace mrpt::nav;
18 using namespace mrpt::io;
19 using namespace mrpt::serialization;
20 using namespace std;
21 
22 // Defined in tests/test_main.cpp
23 namespace mrpt
24 {
26 }
27 
30 };
31 
32 // Create a set of classes, then serialize and deserialize to test possible
33 // bugs:
34 TEST(NavTests, Serialization_WriteReadToMem)
35 {
36  for (size_t i = 0; i < sizeof(lstClasses) / sizeof(lstClasses[0]); i++)
37  {
38  try
39  {
40  CMemoryStream buf;
41  auto arch = archiveFrom(buf);
42  {
43  CSerializable* o =
44  static_cast<CSerializable*>(lstClasses[i]->createObject());
45  arch << *o;
46  delete o;
47  }
48 
49  CSerializable::Ptr recons;
50  buf.Seek(0);
51  arch >> 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  {
69  std::vector<uint8_t> buf;
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  auto arch = archiveFrom(f);
104 
105  try
106  {
107  for (int i = 0; i < 2; i++)
108  {
110  arch.ReadObject(&lfr);
111  }
112  }
113  catch (std::exception& e)
114  {
115  FAIL() << "Failed to parse stored navlog. Exception was:\n"
116  << e.what() << endl;
117  }
118 }
bool fileExists(const std::string &fileName)
Test if a given file (or directory) exists.
Definition: filesystem.cpp:127
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:30
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:555
#define CLASS_ID(T)
Access to runtime class ID for a defined class name.
Definition: CObject.h:84
const char * className
Definition: CObject.h:33
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...
GLsizei const GLchar ** string
Definition: glext.h:4101
TEST(NavTests, Serialization_WriteReadToMem)
std::string MRPT_GLOBAL_UNITTEST_SRC_DIR
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
The virtual base class which provides a unified interface for all persistent objects in MRPT...
Definition: CSerializable.h:30
const mrpt::rtti::TRuntimeClassId * lstClasses[]
Transparently opens a compressed "gz" file and reads uncompressed data from it.
mrpt::rtti::CObject * createObject() const
Definition: CObject.cpp:79



Page generated by Doxygen 1.8.14 for MRPT 1.9.9 Git: 7d5e6d718 Fri Aug 24 01:51:28 2018 +0200 at lun nov 2 08:35:50 CET 2020