From 15bca702c1adefa0ab71ea2ee2181601544858d0 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Fri, 7 Feb 2020 11:51:13 +0100 Subject: [PATCH] [libcalamares] Add tests for path functions (part 1) --- src/libcalamares/utils/Tests.cpp | 27 +++++++++++++++++++++++++++ src/libcalamares/utils/Tests.h | 3 +++ 2 files changed, 30 insertions(+) diff --git a/src/libcalamares/utils/Tests.cpp b/src/libcalamares/utils/Tests.cpp index 16faec9a1..7f9f7f2bf 100644 --- a/src/libcalamares/utils/Tests.cpp +++ b/src/libcalamares/utils/Tests.cpp @@ -24,6 +24,9 @@ #include "UMask.h" #include "Yaml.h" +#include "GlobalStorage.h" +#include "JobQueue.h" + #include #include @@ -221,3 +224,27 @@ LibCalamaresTests::testPrintableEntropy() QVERIFY( c.cell() < 127 ); } } + +void +LibCalamaresTests::testTargetPath() +{ + // Ensure we have a system object, expect it to be a "bogus" one + const CalamaresUtils::System* system = CalamaresUtils::System::instance(); + QVERIFY( system ); + QVERIFY( system->doChroot() ); + + // Ensure we have a system-wide GlobalStorage with /tmp as root + if ( !Calamares::JobQueue::instance() ) + { + (void)new Calamares::JobQueue(); + } + Calamares::GlobalStorage* gs + = Calamares::JobQueue::instance() ? Calamares::JobQueue::instance()->globalStorage() : nullptr; + QVERIFY( gs ); + gs->insert( "rootMountPoint", "/tmp" ); + + // Paths mapped normally + QCOMPARE( system->targetPath( "/etc/calamares" ), QStringLiteral( "/tmp/etc/calamares" ) ); + QCOMPARE( system->targetPath( "//etc//calamares" ), QStringLiteral( "/tmp/etc/calamares" ) ); // extra / + QCOMPARE( system->targetPath( "etc/calamares" ), QString() ); // NOT ABSOLUTE +} diff --git a/src/libcalamares/utils/Tests.h b/src/libcalamares/utils/Tests.h index d369ed4cb..8ea9aa0ce 100644 --- a/src/libcalamares/utils/Tests.h +++ b/src/libcalamares/utils/Tests.h @@ -43,6 +43,9 @@ private Q_SLOTS: /** @brief Tests the entropy functions. */ void testEntropy(); void testPrintableEntropy(); + + /** @brief Tests file creation and removal. */ + void testTargetPath(); }; #endif