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 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73
|
/* vi: set sw=4 ts=4:
*
* Copyright (C) 2023 Christian Hohnstaedt.
*
* All rights reserved.
*/
#include <QTest>
#include <QFile>
#include <QByteArray>
#include <QString>
#include <QDebug>
#include <QRegularExpression>
#include "entropy.h"
QString getUserSettingsDir()
{
return QString(".");
}
void dbg(QtMsgType , const QMessageLogContext &, const QString &) { }
class test_entropy: public QObject
{
Q_OBJECT
Entropy *e{};
QString rnd{};
private slots:
void initTestCase();
void cleanupTestCase();
void start();
void muchSalt();
};
void test_entropy::initTestCase()
{
rnd = getUserSettingsDir() + "/.rnd";
qInstallMessageHandler(dbg);
e = new Entropy();
QCOMPARE(QFileInfo::exists(rnd), false);
}
void test_entropy::cleanupTestCase()
{
delete e;
QVERIFY(QFileInfo::exists(rnd));
QFile::remove(rnd);
qInstallMessageHandler(0);
}
void test_entropy::start()
{
e->add(17);
QVERIFY(e->strength() > 0);
e->add_buf((unsigned char*)"SomeText", 8);
}
void test_entropy::muchSalt()
{
QRegularExpression rx("^T[0-9a-z]{16}$");
QString s1, s2;
for (int i=0; i<100; i++) {
s1 = e->makeSalt();
QVERIFY(s1.contains(rx));
QCOMPARE(s1.size(), 17);
QVERIFY(s1 != s2);
s2 = s1;
}
}
QTEST_MAIN(test_entropy)
#include "test_entropy.moc"
|