MRPT  2.0.4
zip_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>
11 #include <mrpt/io/zip.h>
12 
13 using namespace mrpt;
14 using namespace mrpt::io;
15 using namespace std;
16 
17 TEST(Compress, DataBlockGZ)
18 {
19  const size_t N = 20000;
20 
21  // Create a random "input" data vector
22  std::vector<uint8_t> in_data(N);
23  for (size_t i = 0; i < N; i++)
24  in_data[i] = static_cast<uint8_t>(
25  i); // We need low entropy for compression to have something to do!
26 
27  // Compress it:
28  std::vector<uint8_t> compress_data;
29 
30  // cout << "[test_compress_main] Invoking compress_gz_data_block" << endl;
31 
32  if (!mrpt::io::zip::compress_gz_data_block(in_data, compress_data))
33  GTEST_FAIL() << "Error in compress_gz_data_block\n";
34 
35  // cout << "Compressed gz-data: " << N << " -> " << compress_data.size() <<
36  //" bytes." << endl;
37 
38  std::vector<uint8_t> recovered_data;
39  if (!mrpt::io::zip::decompress_gz_data_block(compress_data, recovered_data))
40  GTEST_FAIL() << "Error in decompress_gz_data_block\n";
41 
42  // cout << "Decompressed data: " << recovered_data.size() << " bytes." <<
43  // endl;
44 
45  EXPECT_EQ(in_data.size(), recovered_data.size());
46  if (in_data.size() == recovered_data.size())
47  {
48  bool all_eq = true;
49  for (size_t i = 0; i < in_data.size(); i++)
50  if (in_data[i] != recovered_data[i]) all_eq = false;
51  EXPECT_TRUE(all_eq) << "Mismatch after compressing/decompressing";
52  }
53 }
EXPECT_TRUE(mrpt::system::fileExists(ini_fil))
STL namespace.
TEST(Compress, DataBlockGZ)
bool compress_gz_data_block(const std::vector< uint8_t > &in_data, std::vector< uint8_t > &out_gz_data, const int compress_level=9)
Compress a memory buffer in gz-file format and return it as a block a memory.
Definition: zip.cpp:260
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
bool decompress_gz_data_block(const std::vector< uint8_t > &in_gz_data, std::vector< uint8_t > &out_data)
Decompress an array of bytes storing a gz-compressed stream of data into a memory buffer...
Definition: zip.cpp:358
EXPECT_EQ(out.image_pair_was_used.size(), NUM_IMGS)



Page generated by Doxygen 1.8.14 for MRPT 2.0.4 Git: 33de1d0ad Sat Jun 20 11:02:42 2020 +0200 at sáb jun 20 17:35:17 CEST 2020