mirror of https://github.com/cutefishos/calamares
Merge branch 'master' into fix-swap-ui
commit
779542a5d1
Binary file not shown.
@ -0,0 +1,59 @@
|
|||||||
|
/* === 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 "Tests.h"
|
||||||
|
|
||||||
|
#include "utils/Logger.h"
|
||||||
|
|
||||||
|
#include <QtTest/QtTest>
|
||||||
|
|
||||||
|
QTEST_GUILESS_MAIN( LibCalamaresTests )
|
||||||
|
|
||||||
|
LibCalamaresTests::LibCalamaresTests()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
LibCalamaresTests::~LibCalamaresTests()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
LibCalamaresTests::initTestCase()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
LibCalamaresTests::testDebugLevels()
|
||||||
|
{
|
||||||
|
Logger::setupLogLevel( Logger::LOG_DISABLE );
|
||||||
|
|
||||||
|
QCOMPARE( Logger::logLevel(), static_cast<unsigned int>( Logger::LOG_DISABLE ) );
|
||||||
|
|
||||||
|
for ( unsigned int level = 0; level <= Logger::LOGVERBOSE ; ++level )
|
||||||
|
{
|
||||||
|
Logger::setupLogLevel( level );
|
||||||
|
QCOMPARE( Logger::logLevel(), level );
|
||||||
|
QVERIFY( Logger::logLevelEnabled( level ) );
|
||||||
|
|
||||||
|
for ( unsigned int xlevel = 0; xlevel <= Logger::LOGVERBOSE; ++xlevel )
|
||||||
|
{
|
||||||
|
QCOMPARE( Logger::logLevelEnabled( xlevel ), xlevel <= level );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,36 @@
|
|||||||
|
/* === 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/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef TESTS_H
|
||||||
|
#define TESTS_H
|
||||||
|
|
||||||
|
#include <QObject>
|
||||||
|
|
||||||
|
class LibCalamaresTests : public QObject
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
public:
|
||||||
|
LibCalamaresTests();
|
||||||
|
~LibCalamaresTests() override;
|
||||||
|
|
||||||
|
private Q_SLOTS:
|
||||||
|
void initTestCase();
|
||||||
|
void testDebugLevels();
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
Binary file not shown.
@ -0,0 +1,75 @@
|
|||||||
|
/* === This file is part of Calamares - <https://github.com/calamares> ===
|
||||||
|
*
|
||||||
|
* Copyright (C) 2018 Scott Harvey <scott@spharvey.me>
|
||||||
|
*
|
||||||
|
* This program 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.
|
||||||
|
*
|
||||||
|
* This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <QString>
|
||||||
|
#include <QStringList>
|
||||||
|
#include "permissions.h"
|
||||||
|
|
||||||
|
Permissions::Permissions() :
|
||||||
|
m_username(),
|
||||||
|
m_group(),
|
||||||
|
m_valid(false),
|
||||||
|
m_value(0)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Permissions::Permissions(QString p) : Permissions()
|
||||||
|
{
|
||||||
|
parsePermissions(p);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Permissions::parsePermissions(const QString& p) {
|
||||||
|
|
||||||
|
QStringList segments = p.split(":");
|
||||||
|
|
||||||
|
if (segments.length() != 3) {
|
||||||
|
m_valid = false;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (segments[0].isEmpty() || segments[1].isEmpty()) {
|
||||||
|
m_valid = false;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool ok;
|
||||||
|
int octal = segments[2].toInt(&ok, 8);
|
||||||
|
if (!ok || octal == 0) {
|
||||||
|
m_valid = false;
|
||||||
|
return;
|
||||||
|
} else {
|
||||||
|
m_value = octal;
|
||||||
|
}
|
||||||
|
|
||||||
|
// We have exactly three segments and the third is valid octal,
|
||||||
|
// so we can declare the string valid and set the user and group names
|
||||||
|
m_valid = true;
|
||||||
|
m_username = segments[0];
|
||||||
|
m_group = segments[1];
|
||||||
|
|
||||||
|
return;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -0,0 +1,62 @@
|
|||||||
|
/* === This file is part of Calamares - <https://github.com/calamares> ===
|
||||||
|
*
|
||||||
|
* Copyright (C) 2018 Scott Harvey <scott@spharvey.me>
|
||||||
|
*
|
||||||
|
* This program 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.
|
||||||
|
*
|
||||||
|
* This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef PERMISSIONS_H
|
||||||
|
#define PERMISSIONS_H
|
||||||
|
|
||||||
|
#include <QString>
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief The Permissions class takes a QString @p in the form of
|
||||||
|
* <user>:<group>:<permissions>, checks it for validity, and makes the three
|
||||||
|
* components available indivdually.
|
||||||
|
*/
|
||||||
|
class Permissions
|
||||||
|
{
|
||||||
|
|
||||||
|
public:
|
||||||
|
|
||||||
|
/** @brief Constructor
|
||||||
|
*
|
||||||
|
* Splits the string @p at the colon (":") into separate elements for
|
||||||
|
* <user>, <group>, and <value> (permissions), where <value> is returned as
|
||||||
|
* an **octal** integer.
|
||||||
|
*/
|
||||||
|
Permissions(QString p);
|
||||||
|
|
||||||
|
/** @brief Default constructor of an invalid Permissions. */
|
||||||
|
Permissions();
|
||||||
|
|
||||||
|
bool isValid() const { return m_valid; }
|
||||||
|
QString username() const { return m_username; }
|
||||||
|
QString group() const { return m_group; }
|
||||||
|
int value() const { return m_value; }
|
||||||
|
QString octal() const { return QString::number( m_value, 8 ); }
|
||||||
|
|
||||||
|
private:
|
||||||
|
void parsePermissions(QString const &p);
|
||||||
|
|
||||||
|
QString m_username;
|
||||||
|
QString m_group;
|
||||||
|
bool m_valid;
|
||||||
|
int m_value;
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // PERMISSIONS_H
|
Loading…
Reference in New Issue