mirror of
https://github.com/parchlinux/calamares.git
synced 2025-06-28 18:05:36 -04:00
commit
638c9feeb6
3 changed files with 110 additions and 10 deletions
|
@ -112,6 +112,11 @@ QList< Device* >
|
||||||
getDevices( DeviceType which )
|
getDevices( DeviceType which )
|
||||||
{
|
{
|
||||||
CoreBackend* backend = CoreBackendManager::self()->backend();
|
CoreBackend* backend = CoreBackendManager::self()->backend();
|
||||||
|
if ( !backend )
|
||||||
|
{
|
||||||
|
cWarning() << "No KPM backend found.";
|
||||||
|
return {};
|
||||||
|
}
|
||||||
#if defined( WITH_KPMCORE4API )
|
#if defined( WITH_KPMCORE4API )
|
||||||
DeviceList devices = backend->scanDevices( /* not includeReadOnly, not includeLoopback */ ScanFlag( 0 ) );
|
DeviceList devices = backend->scanDevices( /* not includeReadOnly, not includeLoopback */ ScanFlag( 0 ) );
|
||||||
#else
|
#else
|
||||||
|
|
|
@ -15,7 +15,7 @@ include_directories(
|
||||||
)
|
)
|
||||||
|
|
||||||
calamares_add_test(
|
calamares_add_test(
|
||||||
partitionjobtests
|
partitionjobtest
|
||||||
SOURCES
|
SOURCES
|
||||||
PartitionJobTests.cpp
|
PartitionJobTests.cpp
|
||||||
${PartitionModule_SOURCE_DIR}/core/KPMHelpers.cpp
|
${PartitionModule_SOURCE_DIR}/core/KPMHelpers.cpp
|
||||||
|
@ -31,7 +31,7 @@ calamares_add_test(
|
||||||
)
|
)
|
||||||
|
|
||||||
calamares_add_test(
|
calamares_add_test(
|
||||||
clearmountsjobtests
|
partitionclearmountsjobtest
|
||||||
SOURCES
|
SOURCES
|
||||||
${PartitionModule_SOURCE_DIR}/jobs/ClearMountsJob.cpp
|
${PartitionModule_SOURCE_DIR}/jobs/ClearMountsJob.cpp
|
||||||
ClearMountsJobTests.cpp
|
ClearMountsJobTests.cpp
|
||||||
|
@ -42,27 +42,32 @@ calamares_add_test(
|
||||||
|
|
||||||
|
|
||||||
calamares_add_test(
|
calamares_add_test(
|
||||||
createlayoutstests
|
partitioncreatelayoutstest
|
||||||
SOURCES
|
SOURCES
|
||||||
|
CreateLayoutsTests.cpp
|
||||||
${PartitionModule_SOURCE_DIR}/core/KPMHelpers.cpp
|
${PartitionModule_SOURCE_DIR}/core/KPMHelpers.cpp
|
||||||
${PartitionModule_SOURCE_DIR}/core/PartitionInfo.cpp
|
${PartitionModule_SOURCE_DIR}/core/PartitionInfo.cpp
|
||||||
${PartitionModule_SOURCE_DIR}/core/PartitionLayout.cpp
|
${PartitionModule_SOURCE_DIR}/core/PartitionLayout.cpp
|
||||||
${PartitionModule_SOURCE_DIR}/core/PartUtils.cpp
|
${PartitionModule_SOURCE_DIR}/core/PartUtils.cpp
|
||||||
${PartitionModule_SOURCE_DIR}/core/DeviceModel.cpp
|
${PartitionModule_SOURCE_DIR}/core/DeviceModel.cpp
|
||||||
CreateLayoutsTests.cpp
|
|
||||||
LIBRARIES
|
LIBRARIES
|
||||||
kpmcore
|
kpmcore
|
||||||
calamares
|
Calamares::calamaresui
|
||||||
calamaresui
|
|
||||||
Qt5::Gui
|
|
||||||
DEFINITIONS ${_partition_defs}
|
DEFINITIONS ${_partition_defs}
|
||||||
)
|
)
|
||||||
|
|
||||||
calamares_add_test(
|
calamares_add_test(
|
||||||
automounttests
|
partitionautomounttest
|
||||||
SOURCES
|
SOURCES
|
||||||
${PartitionModule_SOURCE_DIR}/jobs/AutoMountManagementJob.cpp
|
${PartitionModule_SOURCE_DIR}/jobs/AutoMountManagementJob.cpp
|
||||||
AutoMountTests.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