2
* Copyright (C) 2014 Canonical Ltd.
4
* This program is free software: you can redistribute it and/or modify it
5
* under the terms of the GNU General Public License version 3, as published
6
* by the Free Software Foundation.
8
* This program is distributed in the hope that it will be useful, but
9
* WITHOUT ANY WARRANTY; without even the implied warranties of
10
* MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
11
* PURPOSE. See the GNU General Public License for more details.
13
* You should have received a copy of the GNU General Public License along
14
* with this program. If not, see <http://www.gnu.org/licenses/>.
22
#include <QTemporaryDir>
25
class SystemTest: public QObject
35
void testNoticeChanges();
47
SystemTest::SystemTest()
49
qputenv("HOME", dir.path().toUtf8());
50
enableDir.setPath(dir.path() + "/.config/ubuntu-system-settings");
51
enableFile.setFileName(enableDir.filePath("wizard-has-run"));
54
void SystemTest::enable()
57
QCOMPARE(isEnabled(), true);
60
void SystemTest::disable()
62
enableDir.mkpath(".");
63
enableFile.open(QIODevice::WriteOnly);
65
QCOMPARE(isEnabled(), false);
68
bool SystemTest::isEnabled()
70
return !enableFile.exists();
73
void SystemTest::testEnable()
78
QVERIFY(!system.wizardEnabled());
80
system.setWizardEnabled(true);
81
QVERIFY(system.wizardEnabled());
85
void SystemTest::testDisable()
90
QVERIFY(system.wizardEnabled());
92
system.setWizardEnabled(false);
93
QVERIFY(!system.wizardEnabled());
94
QVERIFY(!isEnabled());
97
void SystemTest::testNoticeChanges()
102
QSignalSpy spy(&system, SIGNAL(wizardEnabledChanged()));
104
// System only guarantees its signals work correcty when using its own set
105
// methods (i.e. it won't necessarily notice if we modify the file behind
106
// the scenes). This is because watching all parent directories of the
107
// wizard-has-run file with QFileSystemWatcher is a nightmare and waste of
108
// resources for the corner case it is. So we'll just test the set method.
110
system.setWizardEnabled(false);
111
QTRY_COMPARE(spy.count(), 1);
113
system.setWizardEnabled(true);
114
QTRY_COMPARE(spy.count(), 2);
116
system.setWizardEnabled(false);
117
QTRY_COMPARE(spy.count(), 3);
119
system.setWizardEnabled(true);
120
QTRY_COMPARE(spy.count(), 4);
123
QTEST_MAIN(SystemTest)
124
#include "tst_system.moc"