[libcalamares] Tests for UMask handling

This commit is contained in:
Adriaan de Groot 2019-07-02 22:46:49 +02:00
parent 0685e3a96c
commit aa3f909be7
2 changed files with 36 additions and 0 deletions

View file

@ -20,12 +20,17 @@
#include "CalamaresUtilsSystem.h" #include "CalamaresUtilsSystem.h"
#include "Logger.h" #include "Logger.h"
#include "UMask.h"
#include "Yaml.h" #include "Yaml.h"
#include <QTemporaryFile> #include <QTemporaryFile>
#include <QtTest/QtTest> #include <QtTest/QtTest>
#include <fcntl.h>
#include <sys/stat.h>
#include <unistd.h>
QTEST_GUILESS_MAIN( LibCalamaresTests ) QTEST_GUILESS_MAIN( LibCalamaresTests )
LibCalamaresTests::LibCalamaresTests() {} LibCalamaresTests::LibCalamaresTests() {}
@ -141,3 +146,31 @@ LibCalamaresTests::testCommands()
r = System::runCommand( System::RunLocation::RunInHost, { "/bin/ls" }, "/tmp" ); r = System::runCommand( System::RunLocation::RunInHost, { "/bin/ls" }, "/tmp" );
QVERIFY( r.getOutput().contains( tfn.fileName() ) ); QVERIFY( r.getOutput().contains( tfn.fileName() ) );
} }
void
LibCalamaresTests::testUmask()
{
struct stat mystat;
QTemporaryFile ft;
QVERIFY( ft.open() );
mode_t m = CalamaresUtils::setUMask( 022 );
QCOMPARE( CalamaresUtils::setUMask( m ), m );
for ( int i = 0; i <= 0777 /* octal! */; ++i )
{
QByteArray name = ( ft.fileName() + QChar( '.' ) + QString::number( i, 8 ) ).toLatin1();
CalamaresUtils::UMask um( i );
int fd = creat( name, 0777 );
QVERIFY( fd >= 0 );
close( fd );
QFileInfo fi( name );
QVERIFY( fi.exists() );
QCOMPARE( stat( name, &mystat ), 0 );
QCOMPARE( mystat.st_mode & 0777, 0777 & ~i );
QCOMPARE( unlink( name ), 0 );
}
QCOMPARE( CalamaresUtils::setUMask( 022 ), m );
QCOMPARE( CalamaresUtils::setUMask( m ), 022 );
}

View file

@ -36,6 +36,9 @@ private Q_SLOTS:
void testLoadSaveYamlExtended(); // Do a find() in the src dir void testLoadSaveYamlExtended(); // Do a find() in the src dir
void testCommands(); void testCommands();
/** @brief Test that all the UMask objects work correctly. */
void testUmask();
}; };
#endif #endif