[libcalamares] Split paths-tests into own test executable

- Since these tests all want a system object, and a GS
   with a sensible setup, give them one with its own initTestCase().

This could have been done with one executable, running tests from
multiple classes, but there's not much overall benefit there.
This commit is contained in:
Adriaan de Groot 2020-02-07 13:49:06 +01:00
parent 31878dd43b
commit daa5b804b3
4 changed files with 101 additions and 27 deletions

View File

@ -171,6 +171,18 @@ if ( ECM_FOUND AND BUILD_TESTING )
)
calamares_automoc( libcalamarestest )
ecm_add_test(
utils/TestPaths.cpp
TEST_NAME
libcalamarestestpaths
LINK_LIBRARIES
calamares
Qt5::Core
Qt5::Test
)
calamares_automoc( libcalamarestestpaths )
ecm_add_test(
geoip/GeoIPTests.cpp
${geoip_src}

View File

@ -0,0 +1,89 @@
/* === This file is part of Calamares - <https://github.com/calamares> ===
*
* Copyright 2018, Adriaan de Groot <groot@kde.org>
*
* Calamares is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Calamares is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Calamares. If not, see <http://www.gnu.org/licenses/>.
*/
#include "CalamaresUtilsSystem.h"
#include "Entropy.h"
#include "Logger.h"
#include "UMask.h"
#include "Yaml.h"
#include "GlobalStorage.h"
#include "JobQueue.h"
#include <QTemporaryFile>
#include <QtTest/QtTest>
#include <fcntl.h>
#include <sys/stat.h>
#include <unistd.h>
class TestPaths : public QObject
{
Q_OBJECT
public:
TestPaths() {};
virtual ~TestPaths() {};
private Q_SLOTS:
void initTestCase();
void testTargetPath();
private:
CalamaresUtils::System* m_system; // Points to singleton instance, not owned
};
void
TestPaths::initTestCase()
{
Logger::setupLogLevel( Logger::LOGDEBUG );
// Ensure we have a system object, expect it to be a "bogus" one
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" );
m_system = system;
}
void
TestPaths::testTargetPath()
{
// Paths mapped normally
QCOMPARE( m_system->targetPath( "/etc/calamares" ), QStringLiteral( "/tmp/etc/calamares" ) );
QCOMPARE( m_system->targetPath( "//etc//calamares" ), QStringLiteral( "/tmp/etc/calamares" ) ); // extra /
QCOMPARE( m_system->targetPath( "etc/calamares" ), QString() ); // NOT ABSOLUTE
}
QTEST_GUILESS_MAIN( TestPaths )
#include "utils/moc-warnings.h"
#include "TestPaths.moc"

View File

@ -224,27 +224,3 @@ 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
}

View File

@ -43,9 +43,6 @@ private Q_SLOTS:
/** @brief Tests the entropy functions. */
void testEntropy();
void testPrintableEntropy();
/** @brief Tests file creation and removal. */
void testTargetPath();
};
#endif