2
* Copyright (C) 2013 Felix Geyer <debfx@fobos.de>
4
* This program is free software: you can redistribute it and/or modify
5
* it under the terms of the GNU General Public License as published by
6
* the Free Software Foundation, either version 2 or (at your option)
7
* version 3 of the License.
9
* This program is distributed in the hope that it will be useful,
10
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
* GNU General Public License for more details.
14
* You should have received a copy of the GNU General Public License
15
* along with this program. If not, see <http://www.gnu.org/licenses/>.
18
#include "TestRandomGenerator.h"
20
#include "core/Global.h"
21
#include "crypto/Random.h"
25
QTEST_GUILESS_MAIN(TestRandomGenerator)
27
void TestRandomGenerator::testArray()
29
auto ba = randomGen()->randomArray(10);
30
QCOMPARE(ba.size(), 10);
31
QVERIFY(ba != QByteArray(10, '\0'));
34
randomGen()->randomize(ba2);
38
void TestRandomGenerator::testUInt()
40
QVERIFY(randomGen()->randomUInt(0) == 0);
41
QVERIFY(randomGen()->randomUInt(1) == 0);
43
// Run a bunch of trials creating random numbers to ensure we meet the standard
44
for (int i = 0; i < 100; ++i) {
45
QVERIFY(randomGen()->randomUInt(5) < 5);
46
QVERIFY(randomGen()->randomUInt(100) < 100);
47
QVERIFY(randomGen()->randomUInt(100000U) < 100000U);
48
QVERIFY(randomGen()->randomUInt((QUINT32_MAX / 2U) + 1U) < QUINT32_MAX / 2U + 1U);
52
void TestRandomGenerator::testUIntRange()
54
// Run a bunch of trials to ensure we stay within the range
55
for (int i = 0; i < 100; ++i) {
56
auto rand = randomGen()->randomUIntRange(100, 200);