Main MRPT website > C++ reference for MRPT 1.5.6
zip_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 
10 #include <mrpt/compress.h>
11 #include <mrpt/math/ops_vectors.h>
12 #include <gtest/gtest.h>
13 
14 using namespace mrpt;
15 using namespace mrpt::utils;
16 using namespace mrpt::math;
17 using namespace std;
18 
19 
20 TEST(Compress, DataBlockGZ)
21 {
22  const size_t N = 20000;
23 
24  // Create a random "input" data vector
25  vector_byte in_data(N);
26  for (size_t i=0;i<N;i++)
27  in_data[i] = static_cast<uint8_t>(i); // We need low entropy for compression to have something to do!
28 
29  // Compress it:
31 
32 // cout << "[test_compress_main] Invoking compress_gz_data_block" << endl;
33 
34  if (!mrpt::compress::zip::compress_gz_data_block(in_data,compress_data))
35  GTEST_FAIL() << "Error in compress_gz_data_block\n";
36 
37 // cout << "Compressed gz-data: " << N << " -> " << compress_data.size() << " bytes." << endl;
38 
39  vector_byte recovered_data;
40  if (!mrpt::compress::zip::decompress_gz_data_block(compress_data, recovered_data))
41  GTEST_FAIL() << "Error in decompress_gz_data_block\n";
42 
43 // cout << "Decompressed data: " << recovered_data.size() << " bytes." << endl;
44 
45  uint8_t err = mrpt::math::sum( recovered_data - in_data );
46 
47  EXPECT_EQ(0, err ) << "Differences after compressing & decompressing with GZ\n";
48 }
49 
compress_data(j_compress_ptr cinfo, JSAMPIMAGE input_buf)
Definition: jccoefct.cpp:140
std::vector< uint8_t > vector_byte
Definition: types_simple.h:26
bool BASE_IMPEXP decompress_gz_data_block(const vector_byte &in_gz_data, vector_byte &out_data)
Decompress an array of bytes storing a gz-compressed stream of data into a memory buffer...
Definition: zip.cpp:435
unsigned char uint8_t
Definition: rptypes.h:43
CONTAINER::Scalar sum(const CONTAINER &v)
Computes the sum of all the elements.
TEST(Compress, DataBlockGZ)
bool BASE_IMPEXP compress_gz_data_block(const vector_byte &in_data, vector_byte &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:325



Page generated by Doxygen 1.8.6 for MRPT 1.5.6 Git: 4c65e84 Tue Apr 24 08:18:17 2018 +0200 at mar abr 24 08:26:17 CEST 2018