mirror of
https://github.com/parchlinux/calamares.git
synced 2025-02-25 03:15:44 -05:00
[libcalamares] Tests for UMask handling
This commit is contained in:
parent
0685e3a96c
commit
aa3f909be7
2 changed files with 36 additions and 0 deletions
|
@ -20,12 +20,17 @@
|
|||
|
||||
#include "CalamaresUtilsSystem.h"
|
||||
#include "Logger.h"
|
||||
#include "UMask.h"
|
||||
#include "Yaml.h"
|
||||
|
||||
#include <QTemporaryFile>
|
||||
|
||||
#include <QtTest/QtTest>
|
||||
|
||||
#include <fcntl.h>
|
||||
#include <sys/stat.h>
|
||||
#include <unistd.h>
|
||||
|
||||
QTEST_GUILESS_MAIN( LibCalamaresTests )
|
||||
|
||||
LibCalamaresTests::LibCalamaresTests() {}
|
||||
|
@ -141,3 +146,31 @@ LibCalamaresTests::testCommands()
|
|||
r = System::runCommand( System::RunLocation::RunInHost, { "/bin/ls" }, "/tmp" );
|
||||
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 );
|
||||
}
|
||||
|
|
|
@ -36,6 +36,9 @@ private Q_SLOTS:
|
|||
void testLoadSaveYamlExtended(); // Do a find() in the src dir
|
||||
|
||||
void testCommands();
|
||||
|
||||
/** @brief Test that all the UMask objects work correctly. */
|
||||
void testUmask();
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
Loading…
Add table
Reference in a new issue