[libcalamares] Drop parts of InstanceKey API
- Drop the 1-argument QString constructor, it is suprising - Drop the conversion to QString - Add a toString() instead - Drop tests for the removed API - While here, apply code formatting to the tests This is done to force consumers to update to strongly-typed InstanceKeys.
This commit is contained in:
parent
7dcc6e8e07
commit
ce6f6592d4
@ -19,10 +19,16 @@
|
||||
#ifndef MODULESYSTEM_INSTANCEKEY_H
|
||||
#define MODULESYSTEM_INSTANCEKEY_H
|
||||
|
||||
#include <QString>
|
||||
#include <QList>
|
||||
#include <QPair>
|
||||
#include <QString>
|
||||
#include <QStringList>
|
||||
|
||||
namespace Logger
|
||||
{
|
||||
class CLog;
|
||||
}
|
||||
|
||||
namespace Calamares
|
||||
{
|
||||
namespace ModuleSystem
|
||||
@ -55,13 +61,6 @@ public:
|
||||
validate();
|
||||
}
|
||||
|
||||
/// @brief Create "usual" instances keys `module@module`
|
||||
explicit InstanceKey( const QString& module )
|
||||
: QPair( module, module )
|
||||
{
|
||||
validate();
|
||||
}
|
||||
|
||||
/// @brief Create unusual, invalid instance key
|
||||
InstanceKey()
|
||||
: QPair( QString(), QString() )
|
||||
@ -77,8 +76,6 @@ public:
|
||||
QString module() const { return first; }
|
||||
QString id() const { return second; }
|
||||
|
||||
explicit operator QString() const { return isValid() ? module() + '@' + id() : QString(); }
|
||||
|
||||
/// @brief Create instance key from stringified version
|
||||
static InstanceKey fromString( const QString& s )
|
||||
{
|
||||
@ -91,6 +88,11 @@ public:
|
||||
return InstanceKey( moduleEntrySplit.first(), moduleEntrySplit.last() );
|
||||
}
|
||||
|
||||
QString toString() const
|
||||
{
|
||||
return first + '@' + second;
|
||||
}
|
||||
|
||||
private:
|
||||
/** @brief Check validity and reset module and id if needed. */
|
||||
void validate()
|
||||
@ -103,6 +105,7 @@ private:
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
}
|
||||
} // namespace ModuleSystem
|
||||
} // namespace Calamares
|
||||
|
||||
#endif
|
||||
|
@ -33,7 +33,6 @@ private Q_SLOTS:
|
||||
void initTestCase();
|
||||
|
||||
void testEmptyInstanceKey();
|
||||
void testSimpleInstanceKey();
|
||||
void testCustomInstanceKey();
|
||||
void testFromStringInstanceKey();
|
||||
|
||||
@ -41,97 +40,85 @@ private Q_SLOTS:
|
||||
void testBadFromStringCases();
|
||||
};
|
||||
|
||||
void ModuleSystemTests::initTestCase()
|
||||
void
|
||||
ModuleSystemTests::initTestCase()
|
||||
{
|
||||
}
|
||||
|
||||
void assert_is_invalid( const InstanceKey& k )
|
||||
void
|
||||
assert_is_invalid( const InstanceKey& k )
|
||||
{
|
||||
QVERIFY( !k.isValid() );
|
||||
QVERIFY( !k.isCustom() );
|
||||
QVERIFY( k.module().isEmpty() );
|
||||
QVERIFY( k.id().isEmpty() );
|
||||
QVERIFY( QString( k ).isEmpty() );
|
||||
QVERIFY( k.toString().isEmpty() );
|
||||
}
|
||||
|
||||
void ModuleSystemTests::testEmptyInstanceKey()
|
||||
void
|
||||
ModuleSystemTests::testEmptyInstanceKey()
|
||||
{
|
||||
InstanceKey k0;
|
||||
assert_is_invalid( k0 );
|
||||
}
|
||||
|
||||
void ModuleSystemTests::testSimpleInstanceKey()
|
||||
{
|
||||
InstanceKey k1( "derp" );
|
||||
QVERIFY( k1.isValid() );
|
||||
QVERIFY( !k1.isCustom() );
|
||||
QCOMPARE( k1.module(), QStringLiteral( "derp" ) );
|
||||
QCOMPARE( k1.id(), QStringLiteral( "derp" ) );
|
||||
QCOMPARE( QString( k1 ), QStringLiteral( "derp@derp" ) );
|
||||
}
|
||||
|
||||
void ModuleSystemTests::testCustomInstanceKey()
|
||||
void
|
||||
ModuleSystemTests::testCustomInstanceKey()
|
||||
{
|
||||
InstanceKey k0( "derp", "derp" );
|
||||
QVERIFY( k0.isValid() );
|
||||
QVERIFY( !k0.isCustom() );
|
||||
QCOMPARE( k0.module(), QStringLiteral( "derp" ) );
|
||||
QCOMPARE( k0.id(), QStringLiteral( "derp" ) );
|
||||
QCOMPARE( QString( k0 ), QStringLiteral( "derp@derp" ) );
|
||||
QCOMPARE( k0.toString(), QStringLiteral( "derp@derp" ) );
|
||||
|
||||
InstanceKey k1( "derp", "horse" );
|
||||
QVERIFY( k1.isValid() );
|
||||
QVERIFY( k1.isCustom() );
|
||||
QCOMPARE( k1.module(), QStringLiteral( "derp" ) );
|
||||
QCOMPARE( k1.id(), QStringLiteral( "horse" ) );
|
||||
QCOMPARE( QString( k1 ), QStringLiteral( "derp@horse" ) );
|
||||
QCOMPARE( k1.toString(), QStringLiteral( "derp@horse" ) );
|
||||
|
||||
InstanceKey k4( "derp", QString() );
|
||||
QVERIFY( k4.isValid() );
|
||||
QVERIFY( !k4.isCustom() );
|
||||
QCOMPARE( k4.module(), QStringLiteral( "derp" ) );
|
||||
QCOMPARE( k4.id(), QStringLiteral( "derp" ) );
|
||||
QCOMPARE( QString( k4 ), QStringLiteral( "derp@derp" ) );
|
||||
QCOMPARE( k4.toString(), QStringLiteral( "derp@derp" ) );
|
||||
}
|
||||
|
||||
void ModuleSystemTests::testFromStringInstanceKey()
|
||||
void
|
||||
ModuleSystemTests::testFromStringInstanceKey()
|
||||
{
|
||||
InstanceKey k0 = InstanceKey::fromString( "derp@derp" );
|
||||
QVERIFY( k0.isValid() );
|
||||
QVERIFY( !k0.isCustom() );
|
||||
QCOMPARE( k0.module(), QStringLiteral( "derp" ) );
|
||||
QCOMPARE( k0.id(), QStringLiteral( "derp" ) );
|
||||
QCOMPARE( QString( k0 ), QStringLiteral( "derp@derp" ) );
|
||||
|
||||
InstanceKey k1 = InstanceKey::fromString( "derp@horse" );
|
||||
QVERIFY( k1.isValid() );
|
||||
QVERIFY( k1.isCustom() );
|
||||
QCOMPARE( k1.module(), QStringLiteral( "derp" ) );
|
||||
QCOMPARE( k1.id(), QStringLiteral( "horse" ) );
|
||||
QCOMPARE( QString( k1 ), QStringLiteral( "derp@horse" ) );
|
||||
|
||||
InstanceKey k2 = InstanceKey::fromString( "derp" );
|
||||
QVERIFY( k2.isValid() );
|
||||
QVERIFY( !k2.isCustom() );
|
||||
QCOMPARE( k2.module(), QStringLiteral( "derp" ) );
|
||||
QCOMPARE( k2.id(), QStringLiteral( "derp" ) );
|
||||
QCOMPARE( QString( k2 ), QStringLiteral( "derp@derp" ) );
|
||||
}
|
||||
|
||||
/// @brief These are expected to fail since they show bugs in the code
|
||||
void ModuleSystemTests::testBadSimpleCases()
|
||||
void
|
||||
ModuleSystemTests::testBadSimpleCases()
|
||||
{
|
||||
InstanceKey k2( "derp@derp" );
|
||||
assert_is_invalid( k2 );
|
||||
|
||||
InstanceKey k3( "derp@horse" );
|
||||
assert_is_invalid( k3 );
|
||||
|
||||
InstanceKey k4( "derp", "derp@derp" );
|
||||
assert_is_invalid( k4 );
|
||||
}
|
||||
|
||||
void ModuleSystemTests::testBadFromStringCases()
|
||||
void
|
||||
ModuleSystemTests::testBadFromStringCases()
|
||||
{
|
||||
InstanceKey k0 = InstanceKey::fromString( QString() );
|
||||
assert_is_invalid( k0 );
|
||||
|
Loading…
Reference in New Issue
Block a user