Refactor out the view into its own class and add autotest for it
[ambit.git] / autotests / view / viewtest.cpp
blob460476e9e12306d266fff37cbd30edd2ee6b0d99
1 /**
2 * Copyright (C) 2007 Benjamin C. Meyer
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation; either version 2
7 * of the License, or (at your option) any later version.
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.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19 #include <QtTest/QtTest>
20 #include <QtGui/QtGui>
22 #include "view.h"
23 #include "qfilesystemmodel_p.h"
25 class ViewTest : public QObject
27 Q_OBJECT
29 private slots:
30 void empty();
31 void mode();
32 void rootIndex();
35 void ViewTest::empty()
37 View view;
38 QCOMPARE(QModelIndex(), view.rootIndex());
39 QCOMPARE(View::Icon, view.currentMode());
40 QCOMPARE(0, ((int)view.currentView()));
41 QVERIFY(view.history != 0);
42 view.setCurrentMode(View::List);
43 view.goUp();
44 view.setRootIndex(QModelIndex());
45 view.fileOpen();
48 void ViewTest::mode()
50 View view;
51 QFileSystemModel model;
52 view.createViews(&model);
54 QCOMPARE(View::Icon, view.currentMode());
55 view.setCurrentMode(View::List);
56 QCOMPARE(View::List, view.currentMode());
57 view.setCurrentMode(View::Column);
58 QCOMPARE(View::Column, view.currentMode());
59 view.setCurrentMode(View::Icon);
60 QCOMPARE(View::Icon, view.currentMode());
63 void ViewTest::rootIndex()
65 qRegisterMetaType<QModelIndex>("QModelIndex");
66 View view;
67 QFileSystemModel model;
68 view.createViews(&model);
70 QSignalSpy spy(&view, SIGNAL(currentFolderChanged(const QModelIndex &)));
71 QModelIndex home = model.index(QDir::homePath());
72 view.setRootIndex(home);
73 QCOMPARE(view.rootIndex(), home);
74 QCOMPARE(spy.count(), 1);
77 QTEST_MAIN(ViewTest)
78 #include "viewtest.moc"