Merge branch 'issue-1767' into calamares

FIXES #1767
main
Adriaan de Groot 3 years ago
commit 638c9feeb6

@ -112,6 +112,11 @@ QList< Device* >
getDevices( DeviceType which )
{
CoreBackend* backend = CoreBackendManager::self()->backend();
if ( !backend )
{
cWarning() << "No KPM backend found.";
return {};
}
#if defined( WITH_KPMCORE4API )
DeviceList devices = backend->scanDevices( /* not includeReadOnly, not includeLoopback */ ScanFlag( 0 ) );
#else

@ -15,7 +15,7 @@ include_directories(
)
calamares_add_test(
partitionjobtests
partitionjobtest
SOURCES
PartitionJobTests.cpp
${PartitionModule_SOURCE_DIR}/core/KPMHelpers.cpp
@ -31,7 +31,7 @@ calamares_add_test(
)
calamares_add_test(
clearmountsjobtests
partitionclearmountsjobtest
SOURCES
${PartitionModule_SOURCE_DIR}/jobs/ClearMountsJob.cpp
ClearMountsJobTests.cpp
@ -42,27 +42,32 @@ calamares_add_test(
calamares_add_test(
createlayoutstests
partitioncreatelayoutstest
SOURCES
CreateLayoutsTests.cpp
${PartitionModule_SOURCE_DIR}/core/KPMHelpers.cpp
${PartitionModule_SOURCE_DIR}/core/PartitionInfo.cpp
${PartitionModule_SOURCE_DIR}/core/PartitionLayout.cpp
${PartitionModule_SOURCE_DIR}/core/PartUtils.cpp
${PartitionModule_SOURCE_DIR}/core/DeviceModel.cpp
CreateLayoutsTests.cpp
LIBRARIES
kpmcore
calamares
calamaresui
Qt5::Gui
Calamares::calamaresui
DEFINITIONS ${_partition_defs}
)
calamares_add_test(
automounttests
partitionautomounttest
SOURCES
${PartitionModule_SOURCE_DIR}/jobs/AutoMountManagementJob.cpp
AutoMountTests.cpp
)
calamares_add_test(
partitiondevicestest
SOURCES
DevicesTests.cpp
${PartitionModule_SOURCE_DIR}/core/DeviceList.cpp
LIBRARIES
calamares
kpmcore
)

@ -0,0 +1,90 @@
/* === This file is part of Calamares - <https://calamares.io> ===
*
* SPDX-FileCopyrightText: 2021 Adriaan de Groot <groot@kde.org>
* SPDX-License-Identifier: GPL-3.0-or-later
*
* Calamares is Free Software: see the License-Identifier above.
*
*/
#include "core/DeviceList.h"
#include "partition/KPMManager.h"
#include "utils/Logger.h"
#include <kpmcore/backend/corebackend.h>
#include <kpmcore/backend/corebackendmanager.h>
#include <QObject>
#include <QtTest/QtTest>
#include <memory>
#include <unistd.h>
class DevicesTests : public QObject
{
Q_OBJECT
public:
DevicesTests();
private Q_SLOTS:
void testKPMScanDevices();
void testPartUtilScanDevices();
private:
std::unique_ptr< CalamaresUtils::Partition::KPMManager > m_d;
bool m_isRoot = false;
};
DevicesTests::DevicesTests()
: m_d( std::make_unique< CalamaresUtils::Partition::KPMManager >() )
, m_isRoot( geteuid() == 0 )
{
}
void
DevicesTests::testKPMScanDevices()
{
Logger::setupLogLevel( Logger::LOGVERBOSE );
cDebug() << "Getting devices via KPMCore";
CoreBackend* backend = CoreBackendManager::self()->backend();
QVERIFY( backend );
#if defined( WITH_KPMCORE4API )
auto flags = ScanFlag( ~0 );
#else
auto flags = true;
#endif
auto devices = backend->scanDevices( flags ); // These flags try to get "all"
cDebug() << Logger::SubEntry << "Done getting devices.";
if ( !m_isRoot )
{
QEXPECT_FAIL( "", "Test invalid when not root", Continue );
}
QVERIFY( devices.count() > 0 );
}
void
DevicesTests::testPartUtilScanDevices()
{
Logger::setupLogLevel( Logger::LOGVERBOSE );
cDebug() << "Getting devices via PartUtils";
auto devices = PartUtils::getDevices();
cDebug() << Logger::SubEntry << "Done getting devices.";
if ( !m_isRoot )
{
QEXPECT_FAIL( "", "Test invalid when not root", Continue );
}
QVERIFY( devices.count() > 0 );
}
QTEST_GUILESS_MAIN( DevicesTests )
#include "utils/moc-warnings.h"
#include "DevicesTests.moc"
Loading…
Cancel
Save