From 7987cc5727607178eca071002c5e5a3711d83fc1 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Tue, 13 Aug 2024 21:58:16 +0200 Subject: [PATCH] [partition] Repair test of partition layout There are asserts in KPMCore that are triggered when creating a partition with no (table) parent. --- .../partition/tests/CreateLayoutsTests.cpp | 27 ++++++++++--------- 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/src/modules/partition/tests/CreateLayoutsTests.cpp b/src/modules/partition/tests/CreateLayoutsTests.cpp index 87a1ea484..3562ab958 100644 --- a/src/modules/partition/tests/CreateLayoutsTests.cpp +++ b/src/modules/partition/tests/CreateLayoutsTests.cpp @@ -53,18 +53,19 @@ CreateLayoutsTests::cleanup() void CreateLayoutsTests::testFixedSizePartition() { + const PartitionRole role( PartitionRole::Role::Any ); + PartitionLayout layout = PartitionLayout(); TestDevice dev( QString( "test" ), LOGICAL_SIZE, 5_GiB / LOGICAL_SIZE ); - PartitionRole role( PartitionRole::Role::Any ); - QList< Partition* > partitions; + PartitionTable table( PartitionTable::TableType::msdos, 0, 5_GiB ); if ( !layout.addEntry( { FileSystem::Type::Ext4, QString( "/" ), QString( "5MiB" ) } ) ) { QFAIL( qPrintable( "Unable to create / partition" ) ); } - partitions = layout.createPartitions( - static_cast< Device* >( &dev ), 0, dev.totalLogical(), Config::LuksGeneration::Luks1, nullptr, nullptr, role ); + const auto partitions = layout.createPartitions( + static_cast< Device* >( &dev ), 0, dev.totalLogical(), Config::LuksGeneration::Luks1, nullptr, &table, role ); QCOMPARE( partitions.count(), 1 ); @@ -74,18 +75,19 @@ CreateLayoutsTests::testFixedSizePartition() void CreateLayoutsTests::testPercentSizePartition() { + const PartitionRole role( PartitionRole::Role::Any ); + PartitionLayout layout = PartitionLayout(); TestDevice dev( QString( "test" ), LOGICAL_SIZE, 5_GiB / LOGICAL_SIZE ); - PartitionRole role( PartitionRole::Role::Any ); - QList< Partition* > partitions; + PartitionTable table( PartitionTable::TableType::msdos, 0, 5_GiB ); if ( !layout.addEntry( { FileSystem::Type::Ext4, QString( "/" ), QString( "50%" ) } ) ) { QFAIL( qPrintable( "Unable to create / partition" ) ); } - partitions = layout.createPartitions( - static_cast< Device* >( &dev ), 0, dev.totalLogical(), Config::LuksGeneration::Luks1, nullptr, nullptr, role ); + const auto partitions = layout.createPartitions( + static_cast< Device* >( &dev ), 0, dev.totalLogical(), Config::LuksGeneration::Luks1, nullptr, &table, role ); QCOMPARE( partitions.count(), 1 ); @@ -95,10 +97,11 @@ CreateLayoutsTests::testPercentSizePartition() void CreateLayoutsTests::testMixedSizePartition() { + const PartitionRole role( PartitionRole::Role::Any ); + PartitionLayout layout = PartitionLayout(); TestDevice dev( QString( "test" ), LOGICAL_SIZE, 5_GiB / LOGICAL_SIZE ); - PartitionRole role( PartitionRole::Role::Any ); - QList< Partition* > partitions; + PartitionTable table( PartitionTable::TableType::msdos, 0, 5_GiB ); if ( !layout.addEntry( { FileSystem::Type::Ext4, QString( "/" ), QString( "5MiB" ) } ) ) { @@ -115,8 +118,8 @@ CreateLayoutsTests::testMixedSizePartition() QFAIL( qPrintable( "Unable to create /bkup partition" ) ); } - partitions = layout.createPartitions( - static_cast< Device* >( &dev ), 0, dev.totalLogical(), Config::LuksGeneration::Luks1, nullptr, nullptr, role ); + const auto partitions = layout.createPartitions( + static_cast< Device* >( &dev ), 0, dev.totalLogical(), Config::LuksGeneration::Luks1, nullptr, &table, role ); QCOMPARE( partitions.count(), 3 );