[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:
Adriaan de Groot 2019-09-14 13:03:25 -04:00
parent 7dcc6e8e07
commit ce6f6592d4
2 changed files with 35 additions and 45 deletions

View file

@ -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()
void
ModuleSystemTests::testCustomInstanceKey()
{
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()
{
InstanceKey k0("derp", "derp");
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");
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 );