[partition] Repair test of partition layout

There are asserts in KPMCore that are triggered when
creating a partition with no (table) parent.
This commit is contained in:
Adriaan de Groot 2024-08-13 21:58:16 +02:00
parent 2042b338a7
commit 7987cc5727

View File

@ -53,18 +53,19 @@ CreateLayoutsTests::cleanup()
void void
CreateLayoutsTests::testFixedSizePartition() CreateLayoutsTests::testFixedSizePartition()
{ {
const PartitionRole role( PartitionRole::Role::Any );
PartitionLayout layout = PartitionLayout(); PartitionLayout layout = PartitionLayout();
TestDevice dev( QString( "test" ), LOGICAL_SIZE, 5_GiB / LOGICAL_SIZE ); TestDevice dev( QString( "test" ), LOGICAL_SIZE, 5_GiB / LOGICAL_SIZE );
PartitionRole role( PartitionRole::Role::Any ); PartitionTable table( PartitionTable::TableType::msdos, 0, 5_GiB );
QList< Partition* > partitions;
if ( !layout.addEntry( { FileSystem::Type::Ext4, QString( "/" ), QString( "5MiB" ) } ) ) if ( !layout.addEntry( { FileSystem::Type::Ext4, QString( "/" ), QString( "5MiB" ) } ) )
{ {
QFAIL( qPrintable( "Unable to create / partition" ) ); QFAIL( qPrintable( "Unable to create / partition" ) );
} }
partitions = layout.createPartitions( const auto partitions = layout.createPartitions(
static_cast< Device* >( &dev ), 0, dev.totalLogical(), Config::LuksGeneration::Luks1, nullptr, nullptr, role ); static_cast< Device* >( &dev ), 0, dev.totalLogical(), Config::LuksGeneration::Luks1, nullptr, &table, role );
QCOMPARE( partitions.count(), 1 ); QCOMPARE( partitions.count(), 1 );
@ -74,18 +75,19 @@ CreateLayoutsTests::testFixedSizePartition()
void void
CreateLayoutsTests::testPercentSizePartition() CreateLayoutsTests::testPercentSizePartition()
{ {
const PartitionRole role( PartitionRole::Role::Any );
PartitionLayout layout = PartitionLayout(); PartitionLayout layout = PartitionLayout();
TestDevice dev( QString( "test" ), LOGICAL_SIZE, 5_GiB / LOGICAL_SIZE ); TestDevice dev( QString( "test" ), LOGICAL_SIZE, 5_GiB / LOGICAL_SIZE );
PartitionRole role( PartitionRole::Role::Any ); PartitionTable table( PartitionTable::TableType::msdos, 0, 5_GiB );
QList< Partition* > partitions;
if ( !layout.addEntry( { FileSystem::Type::Ext4, QString( "/" ), QString( "50%" ) } ) ) if ( !layout.addEntry( { FileSystem::Type::Ext4, QString( "/" ), QString( "50%" ) } ) )
{ {
QFAIL( qPrintable( "Unable to create / partition" ) ); QFAIL( qPrintable( "Unable to create / partition" ) );
} }
partitions = layout.createPartitions( const auto partitions = layout.createPartitions(
static_cast< Device* >( &dev ), 0, dev.totalLogical(), Config::LuksGeneration::Luks1, nullptr, nullptr, role ); static_cast< Device* >( &dev ), 0, dev.totalLogical(), Config::LuksGeneration::Luks1, nullptr, &table, role );
QCOMPARE( partitions.count(), 1 ); QCOMPARE( partitions.count(), 1 );
@ -95,10 +97,11 @@ CreateLayoutsTests::testPercentSizePartition()
void void
CreateLayoutsTests::testMixedSizePartition() CreateLayoutsTests::testMixedSizePartition()
{ {
const PartitionRole role( PartitionRole::Role::Any );
PartitionLayout layout = PartitionLayout(); PartitionLayout layout = PartitionLayout();
TestDevice dev( QString( "test" ), LOGICAL_SIZE, 5_GiB / LOGICAL_SIZE ); TestDevice dev( QString( "test" ), LOGICAL_SIZE, 5_GiB / LOGICAL_SIZE );
PartitionRole role( PartitionRole::Role::Any ); PartitionTable table( PartitionTable::TableType::msdos, 0, 5_GiB );
QList< Partition* > partitions;
if ( !layout.addEntry( { FileSystem::Type::Ext4, QString( "/" ), QString( "5MiB" ) } ) ) if ( !layout.addEntry( { FileSystem::Type::Ext4, QString( "/" ), QString( "5MiB" ) } ) )
{ {
@ -115,8 +118,8 @@ CreateLayoutsTests::testMixedSizePartition()
QFAIL( qPrintable( "Unable to create /bkup partition" ) ); QFAIL( qPrintable( "Unable to create /bkup partition" ) );
} }
partitions = layout.createPartitions( const auto partitions = layout.createPartitions(
static_cast< Device* >( &dev ), 0, dev.totalLogical(), Config::LuksGeneration::Luks1, nullptr, nullptr, role ); static_cast< Device* >( &dev ), 0, dev.totalLogical(), Config::LuksGeneration::Luks1, nullptr, &table, role );
QCOMPARE( partitions.count(), 3 ); QCOMPARE( partitions.count(), 3 );