MRPT  1.9.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-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 
11 #include <mrpt/random.h>
12 #include <gtest/gtest.h>
13 
14 using namespace mrpt;
15 using namespace mrpt::random;
16 using namespace std;
17 
18 // Load data from constant file and check for exact match.
19 TEST(Base64, RandomEncDec)
20 {
21  for (unsigned int seed = 0; seed < 500; seed++)
22  {
24 
25  const size_t block_len = getRandomGenerator().drawUniform32bit() % 567;
26 
27  std::vector<uint8_t> myData(block_len);
28  for (size_t n = 0; n < block_len; n++)
29  myData[n] =
30  static_cast<uint8_t>(getRandomGenerator().drawUniform32bit());
31 
32  std::string myStr;
33  mrpt::system::encodeBase64(myData, myStr);
34 
35  std::vector<uint8_t> outData;
36  if (!mrpt::system::decodeBase64(myStr, outData))
37  GTEST_FAIL() << "Error decoding the just encoded data!\n";
38 
39  // Compare data:
40  EXPECT_EQ(outData.size(), myData.size());
41 
42  if (!myData.empty())
43  {
44  EXPECT_TRUE(outData == myData)
45  << "64-decoded data does not match original data!!\n";
46  }
47  }
48 }
A namespace of pseudo-random numbers generators 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.
void randomize(const uint32_t seed)
Initialize the PRNG from the given random seed.
GLenum GLsizei n
Definition: glext.h:5074
STL namespace.
bool decodeBase64(const std::string &inString, std::vector< uint8_t > &outData)
Decode a base-64 string into the original sequence of bytes.
Definition: base64.cpp:89
GLsizei const GLchar ** string
Definition: glext.h:4101
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
void encodeBase64(const std::vector< uint8_t > &inputData, std::string &outString)
Encode a sequence of bytes as a string in base-64.
Definition: base64.cpp:29
TEST(Base64, RandomEncDec)
CRandomGenerator & getRandomGenerator()
A static instance of a CRandomGenerator class, for use in single-thread applications.



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