]> cloud.milkyroute.net Git - dolphin.git/blob - src/tests/viewpropertiestest.cpp
0cd55662d2cd709772475283da96e77536a8736c
[dolphin.git] / src / tests / viewpropertiestest.cpp
1 /***************************************************************************
2 * Copyright (C) 2012 by Peter Penz <peter.penz19@gmail.com> *
3 * *
4 * This program is free software; you can redistribute it and/or modify *
5 * it under the terms of the GNU General Public License as published by *
6 * the Free Software Foundation; either version 2 of the License, or *
7 * (at your option) any later version. *
8 * *
9 * This program is distributed in the hope that it will be useful, *
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
12 * GNU General Public License for more details. *
13 * *
14 * You should have received a copy of the GNU General Public License *
15 * along with this program; if not, write to the *
16 * Free Software Foundation, Inc., *
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
18 ***************************************************************************/
19
20 #include "dolphin_generalsettings.h"
21 #include "views/viewproperties.h"
22 #include "testdir.h"
23
24 #include <QTest>
25
26 class ViewPropertiesTest : public QObject
27 {
28 Q_OBJECT
29
30 private slots:
31 void init();
32 void cleanup();
33
34 void testReadOnlyBehavior();
35 void testAutoSave();
36
37 private:
38 bool m_globalViewProps;
39 TestDir* m_testDir;
40 };
41
42 void ViewPropertiesTest::init()
43 {
44 m_globalViewProps = GeneralSettings::self()->globalViewProps();
45 GeneralSettings::self()->setGlobalViewProps(false);
46 GeneralSettings::self()->save();
47
48 // It is mandatory to create the test-directory inside the home-directory
49 // of the user: ViewProperties does not write inside directories
50 // outside the home-directory to prevent overwriting other user-settings
51 // in case if write-permissions are given.
52 m_testDir = new TestDir(QDir::homePath() + "/.viewPropertiesTest-");
53 }
54
55 void ViewPropertiesTest::cleanup()
56 {
57 delete m_testDir;
58 m_testDir = nullptr;
59
60 GeneralSettings::self()->setGlobalViewProps(m_globalViewProps);
61 GeneralSettings::self()->save();
62 }
63
64 /**
65 * Test whether only reading properties won't result in creating
66 * a .directory file when destructing the ViewProperties instance
67 * and autosaving is enabled.
68 */
69 void ViewPropertiesTest::testReadOnlyBehavior()
70 {
71 QString dotDirectoryFile = m_testDir->url().toLocalFile() + "/.directory";
72 QVERIFY(!QFile::exists(dotDirectoryFile));
73
74 QScopedPointer<ViewProperties> props(new ViewProperties(m_testDir->url()));
75 QVERIFY(props->isAutoSaveEnabled());
76 const QByteArray sortRole = props->sortRole();
77 Q_UNUSED(sortRole);
78 props.reset();
79
80 QVERIFY(!QFile::exists(dotDirectoryFile));
81 }
82
83 void ViewPropertiesTest::testAutoSave()
84 {
85 QString dotDirectoryFile = m_testDir->url().toLocalFile() + "/.directory";
86 QVERIFY(!QFile::exists(dotDirectoryFile));
87
88 QScopedPointer<ViewProperties> props(new ViewProperties(m_testDir->url()));
89 QVERIFY(props->isAutoSaveEnabled());
90 props->setSortRole("someNewSortRole");
91 props.reset();
92
93 QVERIFY(QFile::exists(dotDirectoryFile));
94 }
95
96 QTEST_GUILESS_MAIN(ViewPropertiesTest)
97
98 #include "viewpropertiestest.moc"