[libcalamares] Add some tests for CreationResult

- More important is the compiler warning that will show up
   if we add more failure states.
This commit is contained in:
Adriaan de Groot 2020-02-14 13:21:16 +01:00
parent 274115c727
commit f6526f7d9f

View File

@ -46,6 +46,7 @@ private Q_SLOTS:
void init();
void cleanupTestCase();
void testCreationResult();
void testTargetPath();
void testCreateTarget();
void testCreateTargetBasedirs();
@ -95,6 +96,42 @@ TestPaths::init()
m_gs->insert( "rootMountPoint", "/tmp" );
}
void TestPaths::testCreationResult()
{
using Code = CalamaresUtils::CreationResult::Code;
for( auto c : { Code::OK, Code::AlreadyExists, Code::Failed, Code::Invalid } )
{
auto r = CalamaresUtils::CreationResult( c );
QVERIFY( r.path().isEmpty() );
QCOMPARE( r.path(), QString() );
// Get a warning from Clang if we're not covering everything
switch( r.code() )
{
case Code::OK:
QVERIFY( !r.failed() );
QVERIFY( r );
break;
case Code::AlreadyExists:
QVERIFY( !r.failed() );
QVERIFY( !r );
break;
case Code::Failed:
case Code::Invalid:
QVERIFY( r.failed() );
QVERIFY( !r );
break;
}
}
QString path( "/etc/os-release" );
auto r = CalamaresUtils::CreationResult( path );
QVERIFY( !r.failed() );
QVERIFY( r );
QCOMPARE( r.code(), Code::OK );
QCOMPARE( r.path(), path );
}
void
TestPaths::testTargetPath()