]> cloud.milkyroute.net Git - dolphin.git/blob - src/tests/viewpropertiestest.cpp
c459f68746fa8d9458dcd6eab524262b56208513
[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 <qtest_kde.h>
21
22 #include "dolphin_generalsettings.h"
23 #include "views/viewproperties.h"
24 #include "testdir.h"
25
26 #include <QDebug>
27 #include <QDir>
28
29 class ViewPropertiesTest : public QObject
30 {
31 Q_OBJECT
32
33 private slots:
34 void init();
35 void cleanup();
36
37 void testReadOnlyBehavior();
38 void testAutoSave();
39
40 private:
41 bool m_globalViewProps;
42 TestDir* m_testDir;
43 };
44
45 void ViewPropertiesTest::init()
46 {
47 m_globalViewProps = GeneralSettings::self()->globalViewProps();
48 GeneralSettings::self()->setGlobalViewProps(false);
49
50 // It is mandatory to create the test-directory inside the home-directory
51 // of the user: ViewProperties does not write inside directories
52 // outside the home-directory to prevent overwriting other user-settings
53 // in case if write-permissions are given.
54 m_testDir = new TestDir(QDir::homePath() + "/.viewPropertiesTest-");
55 }
56
57 void ViewPropertiesTest::cleanup()
58 {
59 delete m_testDir;
60 m_testDir = 0;
61
62 GeneralSettings::self()->setGlobalViewProps(m_globalViewProps);
63 }
64
65 /**
66 * Test whether only reading properties won't result in creating
67 * a .directory file when destructing the ViewProperties instance
68 * and autosaving is enabled.
69 */
70 void ViewPropertiesTest::testReadOnlyBehavior()
71 {
72 QString dotDirectoryFile = m_testDir->url().toLocalFile() + ".directory";
73 QVERIFY(!QFile::exists(dotDirectoryFile));
74
75 ViewProperties* props = new ViewProperties(m_testDir->url());
76 QVERIFY(props->isAutoSaveEnabled());
77 const QByteArray sortRole = props->sortRole();
78 Q_UNUSED(sortRole);
79 delete props;
80 props = 0;
81
82 QVERIFY(!QFile::exists(dotDirectoryFile));
83 }
84
85 void ViewPropertiesTest::testAutoSave()
86 {
87 QString dotDirectoryFile = m_testDir->url().toLocalFile() + ".directory";
88 QVERIFY(!QFile::exists(dotDirectoryFile));
89
90 ViewProperties* props = new ViewProperties(m_testDir->url());
91 QVERIFY(props->isAutoSaveEnabled());
92 props->setSortRole("someNewSortRole");
93 delete props;
94 props = 0;
95
96 QVERIFY(QFile::exists(dotDirectoryFile));
97 }
98
99 QTEST_KDEMAIN(ViewPropertiesTest, NoGUI)
100
101 #include "viewpropertiestest.moc"