File: test_base64.cc

package info (click to toggle)
logserver 1.13.2-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 720 kB
  • sloc: cpp: 10,815; makefile: 3
file content (28 lines) | stat: -rw-r--r-- 608 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#include <iostream>
#include <list>
#include <random>
#include <vector>

#include "test.h"

#include "base64.h"

using namespace std;

/* randomly convert to and from base64, should be the same */
TEST_CASE("base64 random use") {
	mt19937 rng(random_device{}());
	uniform_int_distribution<uint8_t> char_dist;
	for (int i = 0; i < 100; ++i) {
		uniform_int_distribution<int> len_dist(10, 1000);
		size_t len = len_dist(rng);
		string s;
		s.reserve(len);
		for (size_t j = 0; j < len; ++j) {
			char c = static_cast<char>(char_dist(rng));
			s += c;
		}
		CHECK(Base64::decode(Base64::encode(s)) == s);
	}
}