1#include "test.h"
2#include <gtest/gtest.h>
3
4#include <base/system.h>
5
6TEST(SecureRandom, Fill)
7{
8 unsigned int Bits = 0;
9 while(~Bits)
10 {
11 unsigned int Random;
12 secure_random_fill(bytes: &Random, length: sizeof(Random));
13 Bits |= Random;
14 }
15}
16
17TEST(SecureRandom, Below1)
18{
19 EXPECT_EQ(secure_rand_below(1), 0);
20}
21
22TEST(SecureRandom, Below)
23{
24 const int BOUNDS[] = {2, 3, 4, 5, 10, 100, 127, 128, 129};
25 for(auto Below : BOUNDS)
26 {
27 for(int j = 0; j < 10; j++)
28 {
29 int Random = secure_rand_below(below: Below);
30 EXPECT_GE(Random, 0);
31 EXPECT_LT(Random, Below);
32 }
33 }
34}
35