~mzanetti/unity8/fix-left-edge-on-spread

« back to all changes in this revision

Viewing changes to tests/plugins/Wizard/tst_system.cpp

  • Committer: Michael Zanetti
  • Date: 2015-01-12 11:21:17 UTC
  • mfrom: (1459.1.85 unity8)
  • Revision ID: michael.zanetti@canonical.com-20150112112117-0x9srs9dx0ndp60g
merge trunk

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright (C) 2014 Canonical Ltd.
 
3
 *
 
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.
 
7
 *
 
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.
 
12
 *
 
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/>.
 
15
 */
 
16
 
 
17
#include "System.h"
 
18
 
 
19
#include <QDebug>
 
20
#include <QObject>
 
21
#include <QSignalSpy>
 
22
#include <QTemporaryDir>
 
23
#include <QTest>
 
24
 
 
25
class SystemTest: public QObject
 
26
{
 
27
    Q_OBJECT
 
28
 
 
29
public:
 
30
    SystemTest();
 
31
 
 
32
private Q_SLOTS:
 
33
    void testEnable();
 
34
    void testDisable();
 
35
    void testNoticeChanges();
 
36
 
 
37
private:
 
38
    void enable();
 
39
    void disable();
 
40
    bool isEnabled();
 
41
 
 
42
    QTemporaryDir dir;
 
43
    QDir enableDir;
 
44
    QFile enableFile;
 
45
};
 
46
 
 
47
SystemTest::SystemTest()
 
48
{
 
49
    qputenv("HOME", dir.path().toUtf8());
 
50
    enableDir.setPath(dir.path() + "/.config/ubuntu-system-settings");
 
51
    enableFile.setFileName(enableDir.filePath("wizard-has-run"));
 
52
}
 
53
 
 
54
void SystemTest::enable()
 
55
{
 
56
    enableFile.remove();
 
57
    QCOMPARE(isEnabled(), true);
 
58
}
 
59
 
 
60
void SystemTest::disable()
 
61
{
 
62
    enableDir.mkpath(".");
 
63
    enableFile.open(QIODevice::WriteOnly);
 
64
    enableFile.close();
 
65
    QCOMPARE(isEnabled(), false);
 
66
}
 
67
 
 
68
bool SystemTest::isEnabled()
 
69
{
 
70
    return !enableFile.exists();
 
71
}
 
72
 
 
73
void SystemTest::testEnable()
 
74
{
 
75
    disable();
 
76
 
 
77
    System system;
 
78
    QVERIFY(!system.wizardEnabled());
 
79
 
 
80
    system.setWizardEnabled(true);
 
81
    QVERIFY(system.wizardEnabled());
 
82
    QVERIFY(isEnabled());
 
83
}
 
84
 
 
85
void SystemTest::testDisable()
 
86
{
 
87
    enable();
 
88
 
 
89
    System system;
 
90
    QVERIFY(system.wizardEnabled());
 
91
 
 
92
    system.setWizardEnabled(false);
 
93
    QVERIFY(!system.wizardEnabled());
 
94
    QVERIFY(!isEnabled());
 
95
}
 
96
 
 
97
void SystemTest::testNoticeChanges()
 
98
{
 
99
    enable();
 
100
 
 
101
    System system;
 
102
    QSignalSpy spy(&system, SIGNAL(wizardEnabledChanged()));
 
103
 
 
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.
 
109
 
 
110
    system.setWizardEnabled(false);
 
111
    QTRY_COMPARE(spy.count(), 1);
 
112
 
 
113
    system.setWizardEnabled(true);
 
114
    QTRY_COMPARE(spy.count(), 2);
 
115
 
 
116
    system.setWizardEnabled(false);
 
117
    QTRY_COMPARE(spy.count(), 3);
 
118
 
 
119
    system.setWizardEnabled(true);
 
120
    QTRY_COMPARE(spy.count(), 4);
 
121
}
 
122
 
 
123
QTEST_MAIN(SystemTest)
 
124
#include "tst_system.moc"