mirror of
https://github.com/parchlinux/calamares.git
synced 2025-06-28 09:55:37 -04:00
commit
638c9feeb6
3 changed files with 110 additions and 10 deletions
|
@ -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
|
||||
LIBRARIES
|
||||
calamares
|
||||
)
|
||||
|
||||
calamares_add_test(
|
||||
partitiondevicestest
|
||||
SOURCES
|
||||
DevicesTests.cpp
|
||||
${PartitionModule_SOURCE_DIR}/core/DeviceList.cpp
|
||||
LIBRARIES
|
||||
kpmcore
|
||||
)
|
||||
|
|
90
src/modules/partition/tests/DevicesTests.cpp
Normal file
90
src/modules/partition/tests/DevicesTests.cpp
Normal file
|
@ -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…
Add table
Add a link
Reference in a new issue