[partition] Code-formatting for tests
This commit is contained in:
parent
ecdd09edcd
commit
b1ccd573f8
@ -24,10 +24,10 @@
|
|||||||
#include "utils/Logger.h"
|
#include "utils/Logger.h"
|
||||||
#include "utils/Units.h"
|
#include "utils/Units.h"
|
||||||
|
|
||||||
|
#include <core/KPMHelpers.h>
|
||||||
#include <jobs/CreatePartitionJob.h>
|
#include <jobs/CreatePartitionJob.h>
|
||||||
#include <jobs/CreatePartitionTableJob.h>
|
#include <jobs/CreatePartitionTableJob.h>
|
||||||
#include <jobs/ResizePartitionJob.h>
|
#include <jobs/ResizePartitionJob.h>
|
||||||
#include <core/KPMHelpers.h>
|
|
||||||
|
|
||||||
// CalaPM
|
// CalaPM
|
||||||
#include <backend/corebackend.h>
|
#include <backend/corebackend.h>
|
||||||
@ -59,15 +59,14 @@ public:
|
|||||||
~PartitionMounter()
|
~PartitionMounter()
|
||||||
{
|
{
|
||||||
if ( !m_mounted )
|
if ( !m_mounted )
|
||||||
|
{
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
int ret = QProcess::execute( "umount", QStringList() << m_mountPointDir.path() );
|
int ret = QProcess::execute( "umount", QStringList() << m_mountPointDir.path() );
|
||||||
QCOMPARE( ret, 0 );
|
QCOMPARE( ret, 0 );
|
||||||
}
|
}
|
||||||
|
|
||||||
QString mountPoint() const
|
QString mountPoint() const { return m_mounted ? m_mountPointDir.path() : QString(); }
|
||||||
{
|
|
||||||
return m_mounted ? m_mountPointDir.path() : QString();
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QString m_devicePath;
|
QString m_devicePath;
|
||||||
@ -119,7 +118,9 @@ firstFreePartition( PartitionNode* parent )
|
|||||||
{
|
{
|
||||||
for ( auto child : parent->children() )
|
for ( auto child : parent->children() )
|
||||||
if ( isPartitionFreeSpace( child ) )
|
if ( isPartitionFreeSpace( child ) )
|
||||||
|
{
|
||||||
return child;
|
return child;
|
||||||
|
}
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -146,7 +147,9 @@ QueueRunner::run()
|
|||||||
m_queue->start();
|
m_queue->start();
|
||||||
QEventLoop loop;
|
QEventLoop loop;
|
||||||
while ( !m_finished )
|
while ( !m_finished )
|
||||||
|
{
|
||||||
loop.processEvents();
|
loop.processEvents();
|
||||||
|
}
|
||||||
return m_success;
|
return m_success;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -169,7 +172,8 @@ CalamaresUtils::Partition::KPMManager* kpmcore = nullptr;
|
|||||||
//- PartitionJobTests ------------------------------------------------------------------
|
//- PartitionJobTests ------------------------------------------------------------------
|
||||||
PartitionJobTests::PartitionJobTests()
|
PartitionJobTests::PartitionJobTests()
|
||||||
: m_runner( &m_queue )
|
: m_runner( &m_queue )
|
||||||
{}
|
{
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
PartitionJobTests::initTestCase()
|
PartitionJobTests::initTestCase()
|
||||||
@ -178,7 +182,8 @@ PartitionJobTests::initTestCase()
|
|||||||
if ( devicePath.isEmpty() )
|
if ( devicePath.isEmpty() )
|
||||||
{
|
{
|
||||||
// The 0 is to keep the macro parameters happy
|
// The 0 is to keep the macro parameters happy
|
||||||
QSKIP( "Skipping test, CALAMARES_TEST_DISK is not set. It should point to a disk which can be safely formatted", 0 );
|
QSKIP( "Skipping test, CALAMARES_TEST_DISK is not set. It should point to a disk which can be safely formatted",
|
||||||
|
0 );
|
||||||
}
|
}
|
||||||
|
|
||||||
kpmcore = new CalamaresUtils::Partition::KPMManager();
|
kpmcore = new CalamaresUtils::Partition::KPMManager();
|
||||||
@ -224,7 +229,10 @@ PartitionJobTests::queuePartitionTableCreation( PartitionTable::TableType type)
|
|||||||
}
|
}
|
||||||
|
|
||||||
CreatePartitionJob*
|
CreatePartitionJob*
|
||||||
PartitionJobTests::newCreatePartitionJob( Partition* freeSpacePartition, PartitionRole role, FileSystem::Type type, qint64 size )
|
PartitionJobTests::newCreatePartitionJob( Partition* freeSpacePartition,
|
||||||
|
PartitionRole role,
|
||||||
|
FileSystem::Type type,
|
||||||
|
qint64 size )
|
||||||
{
|
{
|
||||||
Q_ASSERT( freeSpacePartition );
|
Q_ASSERT( freeSpacePartition );
|
||||||
|
|
||||||
@ -232,25 +240,27 @@ PartitionJobTests::newCreatePartitionJob( Partition* freeSpacePartition, Partiti
|
|||||||
qint64 lastSector;
|
qint64 lastSector;
|
||||||
|
|
||||||
if ( size > 0 )
|
if ( size > 0 )
|
||||||
|
{
|
||||||
lastSector = firstSector + size / m_device->logicalSize();
|
lastSector = firstSector + size / m_device->logicalSize();
|
||||||
|
}
|
||||||
else
|
else
|
||||||
|
{
|
||||||
lastSector = freeSpacePartition->lastSector();
|
lastSector = freeSpacePartition->lastSector();
|
||||||
FileSystem* fs = FileSystemFactory::create( type, firstSector, lastSector
|
}
|
||||||
,m_device->logicalSize()
|
FileSystem* fs = FileSystemFactory::create( type, firstSector, lastSector, m_device->logicalSize() );
|
||||||
);
|
|
||||||
|
|
||||||
Partition* partition = new Partition(
|
Partition* partition = new Partition( freeSpacePartition->parent(),
|
||||||
freeSpacePartition->parent(),
|
|
||||||
*m_device,
|
*m_device,
|
||||||
role,
|
role,
|
||||||
fs, firstSector, lastSector,
|
fs,
|
||||||
|
firstSector,
|
||||||
|
lastSector,
|
||||||
QString() /* path */,
|
QString() /* path */,
|
||||||
KPM_PARTITION_FLAG( None ) /* availableFlags */,
|
KPM_PARTITION_FLAG( None ) /* availableFlags */,
|
||||||
QString() /* mountPoint */,
|
QString() /* mountPoint */,
|
||||||
false /* mounted */,
|
false /* mounted */,
|
||||||
KPM_PARTITION_FLAG( None ) /* activeFlags */,
|
KPM_PARTITION_FLAG( None ) /* activeFlags */,
|
||||||
KPM_PARTITION_STATE(New)
|
KPM_PARTITION_STATE( New ) );
|
||||||
);
|
|
||||||
return new CreatePartitionJob( m_device.data(), partition );
|
return new CreatePartitionJob( m_device.data(), partition );
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -312,7 +322,8 @@ PartitionJobTests::testCreatePartitionExtended()
|
|||||||
|
|
||||||
freePartition = firstFreePartition( m_device->partitionTable() );
|
freePartition = firstFreePartition( m_device->partitionTable() );
|
||||||
QVERIFY( freePartition );
|
QVERIFY( freePartition );
|
||||||
job = newCreatePartitionJob( freePartition, PartitionRole( PartitionRole::Extended ), FileSystem::Extended, 10_MiB);
|
job = newCreatePartitionJob(
|
||||||
|
freePartition, PartitionRole( PartitionRole::Extended ), FileSystem::Extended, 10_MiB );
|
||||||
job->updatePreview();
|
job->updatePreview();
|
||||||
m_queue.enqueue( job_ptr( job ) );
|
m_queue.enqueue( job_ptr( job ) );
|
||||||
Partition* extendedPartition = job->partition();
|
Partition* extendedPartition = job->partition();
|
||||||
@ -376,15 +387,13 @@ PartitionJobTests::testResizePartition()
|
|||||||
|
|
||||||
Partition* freePartition = firstFreePartition( m_device->partitionTable() );
|
Partition* freePartition = firstFreePartition( m_device->partitionTable() );
|
||||||
QVERIFY( freePartition );
|
QVERIFY( freePartition );
|
||||||
Partition* partition = KPMHelpers::createNewPartition(
|
Partition* partition = KPMHelpers::createNewPartition( freePartition->parent(),
|
||||||
freePartition->parent(),
|
|
||||||
*m_device,
|
*m_device,
|
||||||
PartitionRole( PartitionRole::Primary ),
|
PartitionRole( PartitionRole::Primary ),
|
||||||
FileSystem::Ext4,
|
FileSystem::Ext4,
|
||||||
oldFirst,
|
oldFirst,
|
||||||
oldLast,
|
oldLast,
|
||||||
KPM_PARTITION_FLAG(None)
|
KPM_PARTITION_FLAG( None ) );
|
||||||
);
|
|
||||||
CreatePartitionJob* job = new CreatePartitionJob( m_device.data(), partition );
|
CreatePartitionJob* job = new CreatePartitionJob( m_device.data(), partition );
|
||||||
job->updatePreview();
|
job->updatePreview();
|
||||||
m_queue.enqueue( job_ptr( job ) );
|
m_queue.enqueue( job_ptr( job ) );
|
||||||
@ -396,7 +405,8 @@ PartitionJobTests::testResizePartition()
|
|||||||
// Write a test file in the partition
|
// Write a test file in the partition
|
||||||
refreshDevice();
|
refreshDevice();
|
||||||
QVERIFY( m_device->partitionTable() );
|
QVERIFY( m_device->partitionTable() );
|
||||||
Partition* partition = m_device->partitionTable()->findPartitionBySector( oldFirst, PartitionRole( PartitionRole::Primary ) );
|
Partition* partition
|
||||||
|
= m_device->partitionTable()->findPartitionBySector( oldFirst, PartitionRole( PartitionRole::Primary ) );
|
||||||
QVERIFY( partition );
|
QVERIFY( partition );
|
||||||
QCOMPARE( partition->firstSector(), oldFirst );
|
QCOMPARE( partition->firstSector(), oldFirst );
|
||||||
QCOMPARE( partition->lastSector(), oldLast );
|
QCOMPARE( partition->lastSector(), oldLast );
|
||||||
@ -421,7 +431,8 @@ PartitionJobTests::testResizePartition()
|
|||||||
{
|
{
|
||||||
refreshDevice();
|
refreshDevice();
|
||||||
QVERIFY( m_device->partitionTable() );
|
QVERIFY( m_device->partitionTable() );
|
||||||
Partition* partition = m_device->partitionTable()->findPartitionBySector( newFirst, PartitionRole( PartitionRole::Primary ) );
|
Partition* partition
|
||||||
|
= m_device->partitionTable()->findPartitionBySector( newFirst, PartitionRole( PartitionRole::Primary ) );
|
||||||
QVERIFY( partition );
|
QVERIFY( partition );
|
||||||
QCOMPARE( partition->firstSector(), newFirst );
|
QCOMPARE( partition->firstSector(), newFirst );
|
||||||
QCOMPARE( partition->lastSector(), newLast );
|
QCOMPARE( partition->lastSector(), newLast );
|
||||||
|
@ -72,7 +72,8 @@ private:
|
|||||||
QueueRunner m_runner;
|
QueueRunner m_runner;
|
||||||
|
|
||||||
void queuePartitionTableCreation( PartitionTable::TableType type );
|
void queuePartitionTableCreation( PartitionTable::TableType type );
|
||||||
CreatePartitionJob* newCreatePartitionJob( Partition* freeSpacePartition, PartitionRole, FileSystem::Type type, qint64 size );
|
CreatePartitionJob*
|
||||||
|
newCreatePartitionJob( Partition* freeSpacePartition, PartitionRole, FileSystem::Type type, qint64 size );
|
||||||
void refreshDevice();
|
void refreshDevice();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user