From 13acdace42e60043be01ce375ca87c6ee4f64d7d Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Sat, 11 Nov 2023 23:46:00 +0100 Subject: [PATCH] [partition] Start of tests for config --- src/modules/partition/tests/CMakeLists.txt | 13 ++++ src/modules/partition/tests/ConfigTests.cpp | 86 +++++++++++++++++++++ 2 files changed, 99 insertions(+) create mode 100644 src/modules/partition/tests/ConfigTests.cpp diff --git a/src/modules/partition/tests/CMakeLists.txt b/src/modules/partition/tests/CMakeLists.txt index 9c5dd3257..17b79265f 100644 --- a/src/modules/partition/tests/CMakeLists.txt +++ b/src/modules/partition/tests/CMakeLists.txt @@ -61,3 +61,16 @@ calamares_add_test( LIBRARIES calamares::kpmcore DEFINITIONS ${_partition_defs} ) + +calamares_add_test( + partitionconfigtest + SOURCES + ConfigTests.cpp + ${PartitionModule_SOURCE_DIR}/core/DeviceModel.cpp + ${PartitionModule_SOURCE_DIR}/core/PartitionInfo.cpp + ${PartitionModule_SOURCE_DIR}/core/PartUtils.cpp + ${PartitionModule_SOURCE_DIR}/Config.cpp + LIBRARIES calamares::kpmcore Calamares::calamaresui + DEFINITIONS + ${_partition_defs} +) diff --git a/src/modules/partition/tests/ConfigTests.cpp b/src/modules/partition/tests/ConfigTests.cpp new file mode 100644 index 000000000..9ef30d720 --- /dev/null +++ b/src/modules/partition/tests/ConfigTests.cpp @@ -0,0 +1,86 @@ +/* === This file is part of Calamares - === + * + * SPDX-FileCopyrightText: 2023 Adriaan de Groot + * SPDX-License-Identifier: GPL-3.0-or-later + * + * Calamares is Free Software: see the License-Identifier above. + * + */ + +#include "Config.h" + +#include "GlobalStorage.h" +#include "JobQueue.h" +#include "utils/Logger.h" +#include "utils/System.h" + +#include "core/PartUtils.h" + +#include +#include + +using Calamares::Units::operator""_MiB; + +class ConfigTests : public QObject +{ + Q_OBJECT + +public: + ConfigTests(); + +private Q_SLOTS: + void initTestCase(); + void testEmptyConfig(); +}; + +ConfigTests::ConfigTests() = default; + +void +ConfigTests::initTestCase() +{ + Logger::setupLogLevel( Logger::LOGDEBUG ); + + // Ensure we have a system object, expect it to be a "bogus" one + Calamares::System* system = Calamares::System::instance(); + QVERIFY( system ); + QVERIFY( system->doChroot() ); + + // Ensure we have a system-wide GlobalStorage with /tmp as root + if ( !Calamares::JobQueue::instance() ) + { + cDebug() << "Creating new JobQueue"; + (void)new Calamares::JobQueue(); + } + Calamares::GlobalStorage* gs + = Calamares::JobQueue::instance() ? Calamares::JobQueue::instance()->globalStorage() : nullptr; + QVERIFY( gs ); +} + + +void +ConfigTests::testEmptyConfig() +{ + Logger::setupLogLevel( Logger::LOGVERBOSE ); + + Config c( nullptr ); + c.setConfigurationMap( {} ); + + const auto* gs = Calamares::JobQueue::instanceGlobalStorage(); + QVERIFY( gs ); + + QVERIFY( c.initialInstallChoice() == Config::InstallChoice::NoChoice ); + QVERIFY( !gs->value( PartUtils::efiFilesystemRecommendedSizeGSKey() ).isValid() ); // Nothing filled in + QCOMPARE( PartUtils::efiFilesystemRecommendedSize(), 300_MiB ); // Default value + QCOMPARE( PartUtils::efiFilesystemMinimumSize(), 300_MiB ); // Default value + + const auto firmware = gs->value( "firmwareType" ).toString(); + QVERIFY( firmware == "efi" || firmware == "bios" ); + + QCOMPARE( gs->value( "efiSystemPartition" ).toString(), "/boot/efi" ); // Default +} + +QTEST_GUILESS_MAIN( ConfigTests ) + +#include "utils/moc-warnings.h" + +#include "ConfigTests.moc"