1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124
|
/*
* Copyright (C) 2014 Canonical Ltd.
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 3, as published
* by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranties of
* MERCHANTABILITY, SATISFACTORY QUALITY, 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 "System.h"
#include <QDebug>
#include <QObject>
#include <QSignalSpy>
#include <QTemporaryDir>
#include <QTest>
class SystemTest: public QObject
{
Q_OBJECT
public:
SystemTest();
private Q_SLOTS:
void testEnable();
void testDisable();
void testNoticeChanges();
private:
void enable();
void disable();
bool isEnabled();
QTemporaryDir dir;
QDir enableDir;
QFile enableFile;
};
SystemTest::SystemTest()
{
qputenv("HOME", dir.path().toUtf8());
enableDir.setPath(dir.path() + "/.config/lomiri-system-settings");
enableFile.setFileName(enableDir.filePath("wizard-has-run"));
}
void SystemTest::enable()
{
enableFile.remove();
QCOMPARE(isEnabled(), true);
}
void SystemTest::disable()
{
enableDir.mkpath(".");
enableFile.open(QIODevice::WriteOnly);
enableFile.close();
QCOMPARE(isEnabled(), false);
}
bool SystemTest::isEnabled()
{
return !enableFile.exists();
}
void SystemTest::testEnable()
{
disable();
System system;
QVERIFY(!system.wizardEnabled());
system.setWizardEnabled(true);
QVERIFY(system.wizardEnabled());
QVERIFY(isEnabled());
}
void SystemTest::testDisable()
{
enable();
System system;
QVERIFY(system.wizardEnabled());
system.setWizardEnabled(false);
QVERIFY(!system.wizardEnabled());
QVERIFY(!isEnabled());
}
void SystemTest::testNoticeChanges()
{
enable();
System system;
QSignalSpy spy(&system, SIGNAL(wizardEnabledChanged()));
// System only guarantees its signals work correcty when using its own set
// methods (i.e. it won't necessarily notice if we modify the file behind
// the scenes). This is because watching all parent directories of the
// wizard-has-run file with QFileSystemWatcher is a nightmare and waste of
// resources for the corner case it is. So we'll just test the set method.
system.setWizardEnabled(false);
QTRY_COMPARE(spy.count(), 1);
system.setWizardEnabled(true);
QTRY_COMPARE(spy.count(), 2);
system.setWizardEnabled(false);
QTRY_COMPARE(spy.count(), 3);
system.setWizardEnabled(true);
QTRY_COMPARE(spy.count(), 4);
}
QTEST_MAIN(SystemTest)
#include "tst_system.moc"
|