[fsresizer] Give the FSResizerJob some accessors

- This is primarily for the tests: then they can drop the
   #define private public hack and be "proper" consumers.
main
Adriaan de Groot 6 years ago
parent 80606cc38d
commit e520c66bb9

@ -54,6 +54,21 @@ public:
m_size.isValid(); m_size.isValid();
} }
QString name() const
{
return m_fsname.isEmpty() ? m_devicename : m_fsname;
}
Calamares::PartitionSize size() const
{
return m_size;
}
Calamares::PartitionSize minimumSize() const
{
return m_atleast;
}
private: private:
Calamares::PartitionSize m_size; Calamares::PartitionSize m_size;
Calamares::PartitionSize m_atleast; Calamares::PartitionSize m_atleast;

@ -30,9 +30,7 @@
#include <QFileInfo> #include <QFileInfo>
#include <QStringList> #include <QStringList>
#define private public
#include "ResizeFSJob.h" #include "ResizeFSJob.h"
#undef private
QTEST_GUILESS_MAIN( FSResizerTests ) QTEST_GUILESS_MAIN( FSResizerTests )
@ -55,10 +53,9 @@ void FSResizerTests::testConfigurationRobust()
// Empty config // Empty config
j.setConfigurationMap( QVariantMap() ); j.setConfigurationMap( QVariantMap() );
QVERIFY( j.m_fsname.isEmpty() ); QVERIFY( j.name().isEmpty() );
QVERIFY( j.m_devicename.isEmpty() ); QCOMPARE( j.size().unit(), Calamares::SizeUnit::None );
QCOMPARE( j.m_size.unit(), Calamares::SizeUnit::None ); QCOMPARE( j.minimumSize().unit(), Calamares::SizeUnit::None );
QCOMPARE( j.m_atleast.unit(), Calamares::SizeUnit::None );
// Config is missing fs and dev, so it isn't valid // Config is missing fs and dev, so it isn't valid
YAML::Node doc0 = YAML::Load( R"(--- YAML::Node doc0 = YAML::Load( R"(---
@ -66,12 +63,11 @@ size: 100%
atleast: 600MiB atleast: 600MiB
)" ); )" );
j.setConfigurationMap( CalamaresUtils::yamlMapToVariant( doc0 ).toMap() ); j.setConfigurationMap( CalamaresUtils::yamlMapToVariant( doc0 ).toMap() );
QVERIFY( j.m_fsname.isEmpty() ); QVERIFY( j.name().isEmpty() );
QVERIFY( j.m_devicename.isEmpty() ); QCOMPARE( j.size().unit(), Calamares::SizeUnit::None );
QCOMPARE( j.m_size.unit(), Calamares::SizeUnit::None ); QCOMPARE( j.minimumSize().unit(), Calamares::SizeUnit::None );
QCOMPARE( j.m_atleast.unit(), Calamares::SizeUnit::None ); QCOMPARE( j.size().value(), 0 );
QCOMPARE( j.m_size.value(), 0 ); QCOMPARE( j.minimumSize().value(), 0 );
QCOMPARE( j.m_atleast.value(), 0 );
} }
void FSResizerTests::testConfigurationValues() void FSResizerTests::testConfigurationValues()
@ -85,12 +81,11 @@ size: 100%
atleast: 600MiB atleast: 600MiB
)" ); )" );
j.setConfigurationMap( CalamaresUtils::yamlMapToVariant( doc0 ).toMap() ); j.setConfigurationMap( CalamaresUtils::yamlMapToVariant( doc0 ).toMap() );
QVERIFY( !j.m_fsname.isEmpty() ); QVERIFY( j.name().isEmpty() );
QVERIFY( j.m_devicename.isEmpty() ); QCOMPARE( j.size().unit(), Calamares::SizeUnit::Percent );
QCOMPARE( j.m_size.unit(), Calamares::SizeUnit::Percent ); QCOMPARE( j.minimumSize().unit(), Calamares::SizeUnit::MiB );
QCOMPARE( j.m_atleast.unit(), Calamares::SizeUnit::MiB ); QCOMPARE( j.size().value(), 100 );
QCOMPARE( j.m_size.value(), 100 ); QCOMPARE( j.minimumSize().value(), 600 );
QCOMPARE( j.m_atleast.value(), 600 );
// Silly config // Silly config
doc0 = YAML::Load( R"(--- doc0 = YAML::Load( R"(---
@ -100,12 +95,11 @@ size: 72 MiB
atleast: 127 % atleast: 127 %
)" ); )" );
j.setConfigurationMap( CalamaresUtils::yamlMapToVariant( doc0 ).toMap() ); j.setConfigurationMap( CalamaresUtils::yamlMapToVariant( doc0 ).toMap() );
QVERIFY( !j.m_fsname.isEmpty() ); QVERIFY( !j.name().isEmpty() );
QVERIFY( !j.m_devicename.isEmpty() ); QCOMPARE( j.size().unit(), Calamares::SizeUnit::MiB );
QCOMPARE( j.m_size.unit(), Calamares::SizeUnit::MiB ); QCOMPARE( j.minimumSize().unit(), Calamares::SizeUnit::None );
QCOMPARE( j.m_atleast.unit(), Calamares::SizeUnit::None ); QCOMPARE( j.size().value(), 72 );
QCOMPARE( j.m_size.value(), 72 ); QCOMPARE( j.minimumSize().value(), 0 );
QCOMPARE( j.m_atleast.value(), 0 );
// Silly config // Silly config
doc0 = YAML::Load( R"(--- doc0 = YAML::Load( R"(---
@ -115,10 +109,9 @@ size: 71MiB
# atleast: 127% # atleast: 127%
)" ); )" );
j.setConfigurationMap( CalamaresUtils::yamlMapToVariant( doc0 ).toMap() ); j.setConfigurationMap( CalamaresUtils::yamlMapToVariant( doc0 ).toMap() );
QVERIFY( !j.m_fsname.isEmpty() ); QVERIFY( j.name().isEmpty() );
QVERIFY( j.m_devicename.isEmpty() ); QCOMPARE( j.size().unit(), Calamares::SizeUnit::MiB );
QCOMPARE( j.m_size.unit(), Calamares::SizeUnit::MiB ); QCOMPARE( j.minimumSize().unit(), Calamares::SizeUnit::None );
QCOMPARE( j.m_atleast.unit(), Calamares::SizeUnit::None ); QCOMPARE( j.size().value(), 71 );
QCOMPARE( j.m_size.value(), 71 ); QCOMPARE( j.minimumSize().value(), 0 );
QCOMPARE( j.m_atleast.value(), 0 );
} }

Loading…
Cancel
Save