[libcalamares] Simplify constructors of InstanceDescription

- no more weights in constructors; do that in fromSettings() only.
- simplify test to drop those constructors
- set config file also for "normal" descriptors; fix test
main
Adriaan de Groot 4 years ago
parent e507338f4c
commit 4968efdaa7

@ -81,15 +81,9 @@ InstanceDescription::InstanceDescription( const Calamares::ModuleSystem::Instanc
{
m_weight = 0;
}
}
InstanceDescription::InstanceDescription( Calamares::ModuleSystem::InstanceKey&& key, int weight )
: m_instanceKey( key )
, m_weight( qBound( 1, weight, 100 ) )
{
if ( !isValid() )
else
{
m_weight = 0;
m_configFileName = key.module() + QStringLiteral( ".conf" );
}
}
@ -97,14 +91,16 @@ InstanceDescription
InstanceDescription::fromSettings( const QVariantMap& m )
{
InstanceDescription r(
Calamares::ModuleSystem::InstanceKey( m.value( "module" ).toString(), m.value( "id" ).toString() ),
m.value( "weight" ).toInt() );
Calamares::ModuleSystem::InstanceKey( m.value( "module" ).toString(), m.value( "id" ).toString() ) );
if ( r.isValid() )
{
r.m_configFileName = m.value( "config" ).toString();
if ( r.m_configFileName.isEmpty() )
int w = qBound( 1, m.value( "weight" ).toInt(), 100 );
r.m_weight = w;
QString c = m.value( "config" ).toString();
if ( !c.isEmpty() )
{
r.m_configFileName = r.key().module() + QStringLiteral( ".conf" );
r.m_configFileName = c;
}
}
return r;
@ -276,8 +272,8 @@ Settings::validateSequence()
if ( k.isValid() && k.isCustom() )
{
targetKey = k;
const auto it = std::find_if(
m_moduleInstances.constBegin(), m_moduleInstances.constEnd(), moduleFinder );
const auto it
= std::find_if( m_moduleInstances.constBegin(), m_moduleInstances.constEnd(), moduleFinder );
if ( it == m_moduleInstances.constEnd() )
{
cWarning() << "Custom instance key" << instance << "is not listed in the *instances*";
@ -287,8 +283,8 @@ Settings::validateSequence()
if ( k.isValid() && !k.isCustom() )
{
targetKey = k;
const auto it = std::find_if(
m_moduleInstances.constBegin(), m_moduleInstances.constEnd(), moduleFinder );
const auto it
= std::find_if( m_moduleInstances.constBegin(), m_moduleInstances.constEnd(), moduleFinder );
if ( it == m_moduleInstances.constEnd() )
{
// Non-custom instance, just mentioned in *sequence*

@ -46,11 +46,6 @@ class DLLEXPORT InstanceDescription
{
using InstanceKey = Calamares::ModuleSystem::InstanceKey;
#ifdef BUILD_AS_TEST
public:
#endif
InstanceDescription( InstanceKey&& key, int weight );
public:
/** @brief An invalid InstanceDescription
*

@ -273,15 +273,7 @@ TestLibCalamares::testInstanceDescription()
}
{
InstanceDescription d( InstanceKey(), 0 );
QVERIFY( !d.isValid() );
QVERIFY( !d.isCustom() );
QCOMPARE( d.weight(), 0 );
QVERIFY( d.configFileName().isEmpty() );
}
{
InstanceDescription d( InstanceKey(), 100 );
InstanceDescription d( InstanceKey {} ); // most-vexing, use brace-init instead
QVERIFY( !d.isValid() );
QVERIFY( !d.isCustom() );
QCOMPARE( d.weight(), 0 );
@ -290,30 +282,23 @@ TestLibCalamares::testInstanceDescription()
// Private constructor
//
// This doesn't set up the config file yet.
// This does set up the config file, to default values
{
InstanceDescription d( InstanceKey::fromString( "welcome" ), 0 );
InstanceDescription d( InstanceKey::fromString( "welcome" ) );
QVERIFY( d.isValid() );
QVERIFY( !d.isCustom() );
QCOMPARE( d.weight(), 1 ); // **now** the constraints kick in
QVERIFY( d.configFileName().isEmpty() );
QVERIFY( !d.configFileName().isEmpty() );
QCOMPARE( d.configFileName(), QStringLiteral( "welcome.conf" ) );
}
{
InstanceDescription d( InstanceKey::fromString( "welcome@hi" ), 0 );
InstanceDescription d( InstanceKey::fromString( "welcome@hi" ) );
QVERIFY( d.isValid() );
QVERIFY( d.isCustom() );
QCOMPARE( d.weight(), 1 ); // **now** the constraints kick in
QVERIFY( d.configFileName().isEmpty() );
}
{
InstanceDescription d( InstanceKey::fromString( "welcome@hi" ), 75 );
QCOMPARE( d.weight(), 75 );
}
{
InstanceDescription d( InstanceKey::fromString( "welcome@hi" ), 105 );
QCOMPARE( d.weight(), 100 );
QVERIFY( !d.configFileName().isEmpty() );
QCOMPARE( d.configFileName(), QStringLiteral( "welcome.conf" ) );
}

Loading…
Cancel
Save