MRPT  1.9.9
base64_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-2019, 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/random.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.
EXPECT_TRUE(mrpt::system::fileExists(ini_fil))
void randomize(const uint32_t seed)
Initialize the PRNG from the given random seed.
GLenum GLsizei n
Definition: glext.h:5136
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:88
GLsizei const GLchar ** string
Definition: glext.h:4116
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: abb8b1a1e Fri Oct 18 14:19:12 2019 +0200 at vie oct 18 14:20:13 CEST 2019