[libcalamares] Add tests for filesystem_use service
This commit is contained in:
parent
afdf431b77
commit
75eb2c3cd4
@ -242,7 +242,10 @@ calamares_add_test(
|
|||||||
calamares_add_test(
|
calamares_add_test(
|
||||||
libcalamarespartitiontest
|
libcalamarespartitiontest
|
||||||
SOURCES
|
SOURCES
|
||||||
|
partition/Global.cpp
|
||||||
partition/Tests.cpp
|
partition/Tests.cpp
|
||||||
|
LIBRARIES
|
||||||
|
${OPTIONAL_PRIVATE_LIBRARIES}
|
||||||
)
|
)
|
||||||
|
|
||||||
if( KPMcore_FOUND )
|
if( KPMcore_FOUND )
|
||||||
|
@ -8,32 +8,54 @@
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "Tests.h"
|
|
||||||
|
|
||||||
#include "PartitionSize.h"
|
#include "PartitionSize.h"
|
||||||
|
|
||||||
|
#include "GlobalStorage.h"
|
||||||
|
#include "utils/Logger.h"
|
||||||
|
|
||||||
|
#include <QObject>
|
||||||
|
#include <QtTest/QtTest>
|
||||||
|
|
||||||
|
// Implementation details being tested
|
||||||
|
extern bool isFilesystemUsedGS( const Calamares::GlobalStorage& gs, const QString& filesystemType );
|
||||||
|
extern void useFilesystemGS( Calamares::GlobalStorage& gs, const QString& filesystemType, bool used );
|
||||||
|
|
||||||
|
|
||||||
using SizeUnit = CalamaresUtils::Partition::SizeUnit;
|
using SizeUnit = CalamaresUtils::Partition::SizeUnit;
|
||||||
using PartitionSize = CalamaresUtils::Partition::PartitionSize;
|
using PartitionSize = CalamaresUtils::Partition::PartitionSize;
|
||||||
|
|
||||||
Q_DECLARE_METATYPE( SizeUnit )
|
Q_DECLARE_METATYPE( SizeUnit )
|
||||||
|
|
||||||
#include "utils/Logger.h"
|
class PartitionServiceTests : public QObject
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
public:
|
||||||
|
PartitionServiceTests();
|
||||||
|
~PartitionServiceTests() override;
|
||||||
|
|
||||||
#include <QtTest/QtTest>
|
private Q_SLOTS:
|
||||||
|
void initTestCase();
|
||||||
|
|
||||||
QTEST_GUILESS_MAIN( PartitionSizeTests )
|
void testUnitComparison_data();
|
||||||
|
void testUnitComparison();
|
||||||
|
|
||||||
PartitionSizeTests::PartitionSizeTests() {}
|
void testUnitNormalisation_data();
|
||||||
|
void testUnitNormalisation();
|
||||||
|
|
||||||
PartitionSizeTests::~PartitionSizeTests() {}
|
void testFilesystemGS();
|
||||||
|
};
|
||||||
|
|
||||||
|
PartitionServiceTests::PartitionServiceTests() {}
|
||||||
|
|
||||||
|
PartitionServiceTests::~PartitionServiceTests() {}
|
||||||
|
|
||||||
void
|
void
|
||||||
PartitionSizeTests::initTestCase()
|
PartitionServiceTests::initTestCase()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
PartitionSizeTests::testUnitComparison_data()
|
PartitionServiceTests::testUnitComparison_data()
|
||||||
{
|
{
|
||||||
QTest::addColumn< SizeUnit >( "u1" );
|
QTest::addColumn< SizeUnit >( "u1" );
|
||||||
QTest::addColumn< SizeUnit >( "u2" );
|
QTest::addColumn< SizeUnit >( "u2" );
|
||||||
@ -71,7 +93,7 @@ original_compare( SizeUnit m_unit, SizeUnit other_m_unit )
|
|||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
PartitionSizeTests::testUnitComparison()
|
PartitionServiceTests::testUnitComparison()
|
||||||
{
|
{
|
||||||
QFETCH( SizeUnit, u1 );
|
QFETCH( SizeUnit, u1 );
|
||||||
QFETCH( SizeUnit, u2 );
|
QFETCH( SizeUnit, u2 );
|
||||||
@ -98,7 +120,7 @@ constexpr qint64 operator""_qi( unsigned long long m )
|
|||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
PartitionSizeTests::testUnitNormalisation_data()
|
PartitionServiceTests::testUnitNormalisation_data()
|
||||||
{
|
{
|
||||||
QTest::addColumn< SizeUnit >( "u1" );
|
QTest::addColumn< SizeUnit >( "u1" );
|
||||||
QTest::addColumn< int >( "v" );
|
QTest::addColumn< int >( "v" );
|
||||||
@ -131,7 +153,7 @@ PartitionSizeTests::testUnitNormalisation_data()
|
|||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
PartitionSizeTests::testUnitNormalisation()
|
PartitionServiceTests::testUnitNormalisation()
|
||||||
{
|
{
|
||||||
QFETCH( SizeUnit, u1 );
|
QFETCH( SizeUnit, u1 );
|
||||||
QFETCH( int, v );
|
QFETCH( int, v );
|
||||||
@ -139,3 +161,50 @@ PartitionSizeTests::testUnitNormalisation()
|
|||||||
|
|
||||||
QCOMPARE( PartitionSize( v, u1 ).toBytes(), bytes );
|
QCOMPARE( PartitionSize( v, u1 ).toBytes(), bytes );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
PartitionServiceTests::testFilesystemGS()
|
||||||
|
{
|
||||||
|
// Some filesystems names, they don't have to be real
|
||||||
|
const QStringList fsNames { "ext4", "zfs", "berries", "carrot" };
|
||||||
|
// Predicate to return whether we consider this FS in use
|
||||||
|
auto pred = []( const QString& s ) { return !s.startsWith( 'z' ); };
|
||||||
|
|
||||||
|
// Fill the GS
|
||||||
|
Calamares::GlobalStorage gs;
|
||||||
|
for ( const auto& s : fsNames )
|
||||||
|
{
|
||||||
|
useFilesystemGS( gs, s, pred( s ) );
|
||||||
|
}
|
||||||
|
|
||||||
|
QVERIFY( gs.contains( "filesystem_use" ) );
|
||||||
|
{
|
||||||
|
const auto map = gs.value( "filesystem_use" ).toMap();
|
||||||
|
QCOMPARE( map.count(), fsNames.count() );
|
||||||
|
}
|
||||||
|
|
||||||
|
for ( const auto& s : fsNames )
|
||||||
|
{
|
||||||
|
QCOMPARE( isFilesystemUsedGS( gs, s ), pred( s ) );
|
||||||
|
}
|
||||||
|
QCOMPARE( isFilesystemUsedGS( gs, QStringLiteral( "derp" ) ), false );
|
||||||
|
QCOMPARE( isFilesystemUsedGS( gs, QString() ), false );
|
||||||
|
// But I can set a value for QString!
|
||||||
|
useFilesystemGS( gs, QString(), true );
|
||||||
|
QCOMPARE( isFilesystemUsedGS( gs, QString() ), true );
|
||||||
|
// .. and replace it again
|
||||||
|
useFilesystemGS( gs, QString(), false );
|
||||||
|
QCOMPARE( isFilesystemUsedGS( gs, QString() ), false );
|
||||||
|
// Now there is one more key
|
||||||
|
{
|
||||||
|
const auto map = gs.value( "filesystem_use" ).toMap();
|
||||||
|
QCOMPARE( map.count(), fsNames.count() + 1 );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
QTEST_GUILESS_MAIN( PartitionServiceTests )
|
||||||
|
|
||||||
|
#include "utils/moc-warnings.h"
|
||||||
|
|
||||||
|
#include "Tests.moc"
|
||||||
|
@ -1,33 +0,0 @@
|
|||||||
/* === This file is part of Calamares - <https://calamares.io> ===
|
|
||||||
*
|
|
||||||
* SPDX-FileCopyrightText: 2019 Adriaan de Groot <groot@kde.org>
|
|
||||||
* SPDX-License-Identifier: GPL-3.0-or-later
|
|
||||||
*
|
|
||||||
* Calamares is Free Software: see the License-Identifier above.
|
|
||||||
*
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef LIBCALAMARES_PARTITION_TESTS_H
|
|
||||||
#define LIBCALAMARES_PARTITION_TESTS_H
|
|
||||||
|
|
||||||
#include <QObject>
|
|
||||||
|
|
||||||
class PartitionSizeTests : public QObject
|
|
||||||
{
|
|
||||||
Q_OBJECT
|
|
||||||
public:
|
|
||||||
PartitionSizeTests();
|
|
||||||
~PartitionSizeTests() override;
|
|
||||||
|
|
||||||
private Q_SLOTS:
|
|
||||||
void initTestCase();
|
|
||||||
|
|
||||||
void testUnitComparison_data();
|
|
||||||
void testUnitComparison();
|
|
||||||
|
|
||||||
void testUnitNormalisation_data();
|
|
||||||
void testUnitNormalisation();
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif
|
|
Loading…
Reference in New Issue
Block a user