Main MRPT website > C++ reference for MRPT 1.5.9
base64_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 
11 #include <mrpt/random.h>
12 #include <gtest/gtest.h>
13 
14 using namespace mrpt;
15 using namespace mrpt::utils;
16 using namespace mrpt::math;
17 using namespace mrpt::random;
18 using namespace std;
19 
20 
21 // Load data from constant file and check for exact match.
22 TEST(Base64, RandomEncDec)
23 {
24  for (size_t seed=0;seed<500;seed++)
25  {
27 
28  const size_t block_len = randomGenerator.drawUniform32bit() % 567;
29 
30  vector_byte myData(block_len);
31  for (size_t n=0;n<block_len;n++)
32  myData[n] = static_cast<uint8_t>(randomGenerator.drawUniform32bit());
33 
34  std::string myStr;
35  mrpt::system::encodeBase64(myData,myStr);
36 
37  vector_byte outData;
38  if (!mrpt::system::decodeBase64(myStr,outData))
39  GTEST_FAIL() << "Error decoding the just encoded data!\n";
40 
41  // Compare data:
42  EXPECT_EQ(outData.size(),myData.size());
43 
44  if (!myData.empty())
45  {
46  EXPECT_TRUE(outData == myData ) << "64-decoded data does not match original data!!\n";
47  }
48  }
49 }
50 
A namespace of pseudo-random numbers genrators of diferent distributions.
uint32_t drawUniform32bit()
Generate a uniformly distributed pseudo-random number using the MT19937 algorithm, in the whole range of 32-bit integers.
Classes for serialization, sockets, ini-file manipulation, streams, list of properties-values, timewatch, extensions to STL.
Definition: zip.h:16
std::vector< uint8_t > vector_byte
Definition: types_simple.h:26
BASE_IMPEXP CRandomGenerator randomGenerator
A static instance of a CRandomGenerator class, for use in single-thread applications.
void randomize(const uint32_t seed)
Initialize the PRNG from the given random seed.
GLenum GLsizei n
Definition: glext.h:4618
void BASE_IMPEXP encodeBase64(const vector_byte &inputData, std::string &outString)
Encode a sequence of bytes as a string in base-64.
Definition: base64.cpp:27
STL namespace.
This base provides a set of functions for maths stuff.
Definition: CArrayNumeric.h:19
bool BASE_IMPEXP decodeBase64(const std::string &inString, vector_byte &outData)
Decode a base-64 string into the original sequence of bytes.
Definition: base64.cpp:87
GLsizei const GLchar ** string
Definition: glext.h:3919
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
TEST(Base64, RandomEncDec)



Page generated by Doxygen 1.8.14 for MRPT 1.5.9 Git: 690a4699f Wed Apr 15 19:29:53 2020 +0200 at miƩ abr 15 19:30:12 CEST 2020