[libcalamares] Test the Entropy service

This commit is contained in:
Adriaan de Groot 2020-01-29 16:14:17 +01:00
parent a574b43eb8
commit 8947f9c00c
2 changed files with 27 additions and 0 deletions

View File

@ -19,6 +19,7 @@
#include "Tests.h" #include "Tests.h"
#include "CalamaresUtilsSystem.h" #include "CalamaresUtilsSystem.h"
#include "Entropy.h"
#include "Logger.h" #include "Logger.h"
#include "UMask.h" #include "UMask.h"
#include "Yaml.h" #include "Yaml.h"
@ -176,3 +177,26 @@ LibCalamaresTests::testUmask()
QCOMPARE( CalamaresUtils::setUMask( 022 ), m ); QCOMPARE( CalamaresUtils::setUMask( 022 ), m );
QCOMPARE( CalamaresUtils::setUMask( m ), 022 ); QCOMPARE( CalamaresUtils::setUMask( m ), 022 );
} }
void
LibCalamaresTests::testEntropy()
{
QByteArray data;
auto r0 = CalamaresUtils::getEntropy( 0, data );
QCOMPARE( CalamaresUtils::EntropySource::None, r0 );
QCOMPARE( 0, data.size() );
auto r1 = CalamaresUtils::getEntropy( 16, data );
QVERIFY( r1 != CalamaresUtils::EntropySource::None );
QCOMPARE( 16, data.size() );
// This can randomly fail (but not often)
QVERIFY( data.at( data.size() - 1 ) != char( 0xcb ) );
auto r2 = CalamaresUtils::getEntropy( 8, data );
QVERIFY( r2 != CalamaresUtils::EntropySource::None );
QCOMPARE( 8, data.size() );
QCOMPARE( r1, r2 );
// This can randomly fail (but not often)
QVERIFY( data.at( data.size() - 1 ) != char( 0xcb ) );
}

View File

@ -39,6 +39,9 @@ private Q_SLOTS:
/** @brief Test that all the UMask objects work correctly. */ /** @brief Test that all the UMask objects work correctly. */
void testUmask(); void testUmask();
/** @brief Tests the entropy functions. */
void testEntropy();
}; };
#endif #endif