2019-09-14 15:21:37 +02:00
|
|
|
/* === This file is part of Calamares - <https://github.com/calamares> ===
|
|
|
|
*
|
|
|
|
* Copyright 2019, Adriaan de Groot <groot@kde.org>
|
|
|
|
*
|
|
|
|
* Calamares is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* Calamares is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with Calamares. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "modulesystem/InstanceKey.h"
|
|
|
|
|
|
|
|
#include <QtTest/QtTest>
|
|
|
|
|
|
|
|
using Calamares::ModuleSystem::InstanceKey;
|
|
|
|
|
|
|
|
class ModuleSystemTests : public QObject
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
public:
|
|
|
|
ModuleSystemTests() {}
|
|
|
|
virtual ~ModuleSystemTests() {}
|
|
|
|
|
|
|
|
private Q_SLOTS:
|
|
|
|
void initTestCase();
|
|
|
|
|
|
|
|
void testEmptyInstanceKey();
|
|
|
|
void testCustomInstanceKey();
|
|
|
|
void testFromStringInstanceKey();
|
|
|
|
|
|
|
|
void testBadSimpleCases();
|
|
|
|
void testBadFromStringCases();
|
|
|
|
};
|
|
|
|
|
2019-09-14 19:03:25 +02:00
|
|
|
void
|
|
|
|
ModuleSystemTests::initTestCase()
|
2019-09-14 15:21:37 +02:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2019-09-14 19:03:25 +02:00
|
|
|
void
|
|
|
|
assert_is_invalid( const InstanceKey& k )
|
2019-09-14 15:21:37 +02:00
|
|
|
{
|
|
|
|
QVERIFY( !k.isValid() );
|
|
|
|
QVERIFY( !k.isCustom() );
|
|
|
|
QVERIFY( k.module().isEmpty() );
|
|
|
|
QVERIFY( k.id().isEmpty() );
|
2019-09-30 17:54:44 +02:00
|
|
|
if ( k.toString().isEmpty() )
|
|
|
|
{
|
|
|
|
QVERIFY( k.toString().isEmpty() );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
QCOMPARE( k.toString(), QString() );
|
|
|
|
}
|
2019-09-14 15:21:37 +02:00
|
|
|
}
|
|
|
|
|
2019-09-14 19:03:25 +02:00
|
|
|
void
|
|
|
|
ModuleSystemTests::testEmptyInstanceKey()
|
2019-09-14 15:21:37 +02:00
|
|
|
{
|
|
|
|
InstanceKey k0;
|
|
|
|
assert_is_invalid( k0 );
|
|
|
|
}
|
|
|
|
|
2019-09-14 19:03:25 +02:00
|
|
|
void
|
|
|
|
ModuleSystemTests::testCustomInstanceKey()
|
2019-09-14 15:21:37 +02:00
|
|
|
{
|
2019-09-14 19:03:25 +02:00
|
|
|
InstanceKey k0( "derp", "derp" );
|
2019-09-14 15:21:37 +02:00
|
|
|
QVERIFY( k0.isValid() );
|
|
|
|
QVERIFY( !k0.isCustom() );
|
|
|
|
QCOMPARE( k0.module(), QStringLiteral( "derp" ) );
|
|
|
|
QCOMPARE( k0.id(), QStringLiteral( "derp" ) );
|
2019-09-14 19:03:25 +02:00
|
|
|
QCOMPARE( k0.toString(), QStringLiteral( "derp@derp" ) );
|
2019-09-14 15:21:37 +02:00
|
|
|
|
2019-09-14 19:03:25 +02:00
|
|
|
InstanceKey k1( "derp", "horse" );
|
2019-09-14 15:21:37 +02:00
|
|
|
QVERIFY( k1.isValid() );
|
|
|
|
QVERIFY( k1.isCustom() );
|
|
|
|
QCOMPARE( k1.module(), QStringLiteral( "derp" ) );
|
|
|
|
QCOMPARE( k1.id(), QStringLiteral( "horse" ) );
|
2019-09-14 19:03:25 +02:00
|
|
|
QCOMPARE( k1.toString(), QStringLiteral( "derp@horse" ) );
|
2019-09-14 17:14:54 +02:00
|
|
|
|
|
|
|
InstanceKey k4( "derp", QString() );
|
|
|
|
QVERIFY( k4.isValid() );
|
|
|
|
QVERIFY( !k4.isCustom() );
|
|
|
|
QCOMPARE( k4.module(), QStringLiteral( "derp" ) );
|
|
|
|
QCOMPARE( k4.id(), QStringLiteral( "derp" ) );
|
2019-09-14 19:03:25 +02:00
|
|
|
QCOMPARE( k4.toString(), QStringLiteral( "derp@derp" ) );
|
2019-09-14 15:21:37 +02:00
|
|
|
}
|
|
|
|
|
2019-09-14 19:03:25 +02:00
|
|
|
void
|
|
|
|
ModuleSystemTests::testFromStringInstanceKey()
|
2019-09-14 15:21:37 +02:00
|
|
|
{
|
|
|
|
InstanceKey k0 = InstanceKey::fromString( "derp@derp" );
|
|
|
|
QVERIFY( k0.isValid() );
|
|
|
|
QVERIFY( !k0.isCustom() );
|
|
|
|
QCOMPARE( k0.module(), QStringLiteral( "derp" ) );
|
|
|
|
QCOMPARE( k0.id(), QStringLiteral( "derp" ) );
|
|
|
|
|
|
|
|
InstanceKey k1 = InstanceKey::fromString( "derp@horse" );
|
|
|
|
QVERIFY( k1.isValid() );
|
|
|
|
QVERIFY( k1.isCustom() );
|
|
|
|
QCOMPARE( k1.module(), QStringLiteral( "derp" ) );
|
|
|
|
QCOMPARE( k1.id(), QStringLiteral( "horse" ) );
|
|
|
|
|
|
|
|
InstanceKey k2 = InstanceKey::fromString( "derp" );
|
|
|
|
QVERIFY( k2.isValid() );
|
|
|
|
QVERIFY( !k2.isCustom() );
|
|
|
|
QCOMPARE( k2.module(), QStringLiteral( "derp" ) );
|
|
|
|
QCOMPARE( k2.id(), QStringLiteral( "derp" ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
/// @brief These are expected to fail since they show bugs in the code
|
2019-09-14 19:03:25 +02:00
|
|
|
void
|
|
|
|
ModuleSystemTests::testBadSimpleCases()
|
2019-09-14 15:21:37 +02:00
|
|
|
{
|
2019-09-14 17:14:54 +02:00
|
|
|
InstanceKey k4( "derp", "derp@derp" );
|
|
|
|
assert_is_invalid( k4 );
|
2019-09-14 15:21:37 +02:00
|
|
|
}
|
|
|
|
|
2019-09-14 19:03:25 +02:00
|
|
|
void
|
|
|
|
ModuleSystemTests::testBadFromStringCases()
|
2019-09-14 15:21:37 +02:00
|
|
|
{
|
|
|
|
InstanceKey k0 = InstanceKey::fromString( QString() );
|
|
|
|
assert_is_invalid( k0 );
|
|
|
|
|
|
|
|
k0 = InstanceKey::fromString( "derp@derp@derp" );
|
|
|
|
assert_is_invalid( k0 );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
QTEST_GUILESS_MAIN( ModuleSystemTests )
|
|
|
|
|
2019-09-23 11:50:06 +02:00
|
|
|
#include "utils/moc-warnings.h"
|
2019-09-14 15:21:37 +02:00
|
|
|
#include "Tests.moc"
|