2020-08-25 16:05:56 +02:00
|
|
|
/* === This file is part of Calamares - <https://calamares.io> ===
|
2020-08-08 22:54:59 +02:00
|
|
|
*
|
2020-05-30 16:15:03 +02:00
|
|
|
* SPDX-FileCopyrightText: 2019 Adriaan de Groot <groot@kde.org>
|
2020-08-08 22:54:59 +02:00
|
|
|
* SPDX-License-Identifier: GPL-3.0-or-later
|
2020-04-22 15:38:42 +02:00
|
|
|
*
|
2020-08-25 16:05:56 +02:00
|
|
|
* Calamares is Free Software: see the License-Identifier above.
|
2020-04-22 15:38:42 +02:00
|
|
|
*
|
2020-05-30 16:15:03 +02:00
|
|
|
*
|
2020-04-22 15:38:42 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "utils/Logger.h"
|
|
|
|
|
2020-08-09 00:00:14 +02:00
|
|
|
#include "FileSystem.h"
|
|
|
|
|
2020-04-22 15:38:42 +02:00
|
|
|
#include <kpmcore/core/partitiontable.h>
|
2020-08-08 22:54:59 +02:00
|
|
|
#include <kpmcore/fs/filesystem.h>
|
2020-04-22 15:38:42 +02:00
|
|
|
|
|
|
|
#include <QtTest/QtTest>
|
|
|
|
|
2020-04-23 11:45:12 +02:00
|
|
|
class KPMTests : public QObject
|
2020-04-22 15:38:42 +02:00
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
public:
|
|
|
|
KPMTests();
|
2020-04-23 11:45:12 +02:00
|
|
|
~KPMTests() override;
|
2020-04-22 15:38:42 +02:00
|
|
|
private Q_SLOTS:
|
|
|
|
void initTestCase();
|
|
|
|
|
|
|
|
void testFlagNames();
|
2020-08-08 22:54:59 +02:00
|
|
|
void testFSNames();
|
2020-04-22 15:38:42 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
KPMTests::KPMTests() {}
|
|
|
|
|
|
|
|
KPMTests::~KPMTests() {}
|
|
|
|
|
|
|
|
void
|
|
|
|
KPMTests::initTestCase()
|
|
|
|
{
|
|
|
|
Logger::setupLogLevel( Logger::LOGDEBUG );
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
KPMTests::testFlagNames()
|
|
|
|
{
|
2020-08-08 22:54:59 +02:00
|
|
|
cDebug() << "Partition flags according to KPMCore:";
|
2020-04-22 15:38:42 +02:00
|
|
|
int f = 1;
|
|
|
|
QStringList names;
|
|
|
|
QString s;
|
|
|
|
while ( !( s = PartitionTable::flagName( static_cast< PartitionTable::Flag >( f ) ) ).isEmpty() )
|
|
|
|
{
|
2020-08-08 22:54:59 +02:00
|
|
|
cDebug() << Logger::SubEntry << f << s;
|
2020-04-22 15:38:42 +02:00
|
|
|
names.append( s );
|
2020-04-23 11:45:12 +02:00
|
|
|
|
|
|
|
f <<= 1;
|
2020-04-22 15:38:42 +02:00
|
|
|
}
|
2020-04-23 12:16:30 +02:00
|
|
|
|
2020-04-23 13:46:09 +02:00
|
|
|
QCOMPARE( PartitionTable::flagName( static_cast< PartitionTable::Flag >( 1 ) ), QStringLiteral( "boot" ) );
|
|
|
|
|
2020-04-23 12:16:30 +02:00
|
|
|
// KPMCore 4 unifies the flags and handles them internally
|
2020-04-23 13:46:09 +02:00
|
|
|
QCOMPARE( PartitionTable::flagName( PartitionTable::Flag::Boot ), QStringLiteral( "boot" ) );
|
2020-04-23 12:16:30 +02:00
|
|
|
QVERIFY( names.contains( QStringLiteral( "boot" ) ) );
|
|
|
|
QVERIFY( !names.contains( QStringLiteral( "esp" ) ) );
|
2020-04-22 15:38:42 +02:00
|
|
|
}
|
|
|
|
|
2020-08-08 22:54:59 +02:00
|
|
|
void
|
|
|
|
KPMTests::testFSNames()
|
|
|
|
{
|
|
|
|
cDebug() << "FileSystem names according to KPMCore:";
|
|
|
|
|
|
|
|
// This uses KPMCore directly, rather than Calamares partition/FileSystem.h
|
|
|
|
// which doesn't wrap nameForType() -- it just provides more meaningful
|
|
|
|
// names for FS naming on FileSystem objects.
|
|
|
|
QStringList fsNames;
|
|
|
|
const auto fstypes = FileSystem::types();
|
|
|
|
fsNames.reserve( fstypes.count() );
|
|
|
|
for ( const auto t : fstypes )
|
|
|
|
{
|
|
|
|
QString s = FileSystem::nameForType( t, { "C" } ); // Untranslated
|
|
|
|
cDebug() << Logger::SubEntry << s;
|
|
|
|
fsNames.append( s );
|
|
|
|
}
|
|
|
|
|
|
|
|
QVERIFY( fsNames.contains( "ext2" ) );
|
|
|
|
QVERIFY( fsNames.contains( "ext4" ) );
|
|
|
|
QVERIFY( fsNames.contains( "reiser" ) );
|
2020-08-09 00:00:14 +02:00
|
|
|
|
|
|
|
QStringList calaFSNames;
|
|
|
|
calaFSNames.reserve( fstypes.count() );
|
|
|
|
for ( const auto t : fstypes )
|
|
|
|
{
|
|
|
|
QString s = CalamaresUtils::Partition::untranslatedFS( t );
|
|
|
|
calaFSNames.append( s );
|
|
|
|
}
|
|
|
|
|
|
|
|
QVERIFY( calaFSNames.contains( "ext2" ) );
|
|
|
|
QVERIFY( calaFSNames.contains( "ext4" ) );
|
|
|
|
QVERIFY( !calaFSNames.contains( "reiser" ) );
|
|
|
|
QVERIFY( calaFSNames.contains( "reiserfs" ) ); // whole point of Cala's own implementation
|
|
|
|
|
|
|
|
// Lists are the same except for .. the exceptions
|
|
|
|
QStringList exceptionalNames { "reiser", "reiserfs" };
|
|
|
|
for ( const auto& s : fsNames )
|
|
|
|
{
|
|
|
|
QVERIFY( exceptionalNames.contains( s ) || calaFSNames.contains( s ) );
|
|
|
|
}
|
|
|
|
for ( const auto& s : calaFSNames )
|
|
|
|
{
|
|
|
|
QVERIFY( exceptionalNames.contains( s ) || fsNames.contains( s ) );
|
|
|
|
}
|
2020-08-08 22:54:59 +02:00
|
|
|
}
|
|
|
|
|
2020-04-22 15:38:42 +02:00
|
|
|
|
|
|
|
QTEST_GUILESS_MAIN( KPMTests )
|
|
|
|
|
2020-04-23 12:16:30 +02:00
|
|
|
#include "utils/moc-warnings.h"
|
2020-04-22 15:38:42 +02:00
|
|
|
|
|
|
|
#include "KPMTests.moc"
|