Debian Codegraph @

tests/tests.cpp

raw
1 /*
2 * Copyright © 2018 Simon Désaulniers
3 * Author: Simon Désaulniers <[email protected]>
4 *
5 * This file is part of dpaste.
6 *
7 * dpaste is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * dpaste is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with dpaste. If not, see <http://www.gnu.org/licenses/>.
19 */
20
21 #include <random>
22
23 #define CATCH_CONFIG_MAIN
24 #include <catch.hpp>
25
26 namespace dpaste {
27 namespace tests {
28
29 static std::uniform_int_distribution<uint32_t> dist;
30 static std::mt19937_64 rand_;
31
32 void init() {
33 static bool initialized = false;
34 if (initialized)
35 return;
36
37 rand_.seed(Catch::rngSeed());
38
39 initialized = true;
40 }
41
42 int random_number() {
43 init();
44 return dist(rand_);
45 }
46
47 std::string random_pin() {
48 const auto i = random_number();
49 std::stringstream ss;
50 ss << std::hex << i;
51 return ss.str();
52 }
53
54 } /* tests */
55 } /* dpaste */
56
57 /* vim: set ts=4 sw=4 tw=120 et :*/
58