File indexing completed on 2024-12-01 03:40:24

0001 /*
0002     This file is part of the KDE project
0003     SPDX-FileCopyrightText: 2013 Dawit Alemayehu <adawit@kde.org>
0004 
0005     SPDX-License-Identifier: LGPL-2.0-or-later
0006 */
0007 
0008 #include "globaltest.h"
0009 #include <QTest>
0010 
0011 #include "global.h"
0012 #include "kioglobal_p.h"
0013 
0014 #include <QFile>
0015 
0016 #include <sys/stat.h>
0017 
0018 QTEST_MAIN(GlobalTest)
0019 
0020 void GlobalTest::testUserPermissionConversion()
0021 {
0022     const int permissions = S_IRUSR | S_IWUSR | S_IXUSR;
0023     QFile::Permissions qPermissions = KIO::convertPermissions(permissions);
0024 
0025     QFile::Permissions perms = (QFile::ReadOwner | QFile::WriteOwner | QFile::ExeOwner);
0026     QCOMPARE(qPermissions & perms, perms);
0027 
0028     perms = (QFile::ReadGroup | QFile::WriteGroup | QFile::ExeGroup);
0029     QCOMPARE(qPermissions & perms, 0);
0030 
0031     perms = (QFile::ReadOther | QFile::WriteOther | QFile::ExeOther);
0032     QCOMPARE(qPermissions & perms, 0);
0033 }
0034 
0035 void GlobalTest::testGroupPermissionConversion()
0036 {
0037     const int permissions = S_IRGRP | S_IWGRP | S_IXGRP;
0038     QFile::Permissions qPermissions = KIO::convertPermissions(permissions);
0039 
0040     QFile::Permissions perms = (QFile::ReadOwner | QFile::WriteOwner | QFile::ExeOwner);
0041     QCOMPARE(qPermissions & perms, 0);
0042 
0043     perms = (QFile::ReadGroup | QFile::WriteGroup | QFile::ExeGroup);
0044     QCOMPARE(qPermissions & perms, perms);
0045 
0046     perms = (QFile::ReadOther | QFile::WriteOther | QFile::ExeOther);
0047     QCOMPARE(qPermissions & perms, 0);
0048 }
0049 
0050 void GlobalTest::testOtherPermissionConversion()
0051 {
0052     const int permissions = S_IROTH | S_IWOTH | S_IXOTH;
0053     QFile::Permissions qPermissions = KIO::convertPermissions(permissions);
0054 
0055     QFile::Permissions perms = (QFile::ReadOwner | QFile::WriteOwner | QFile::ExeOwner);
0056     QCOMPARE(qPermissions & perms, 0);
0057 
0058     perms = (QFile::ReadGroup | QFile::WriteGroup | QFile::ExeGroup);
0059     QCOMPARE(qPermissions & perms, 0);
0060 
0061     perms = (QFile::ReadOther | QFile::WriteOther | QFile::ExeOther);
0062     QCOMPARE(qPermissions & perms, perms);
0063 }
0064 
0065 #include "moc_globaltest.cpp"