]> cloud.milkyroute.net Git - dolphin.git/blob - src/tests/dolphindetailsviewtest.cpp
Add some debug output to DolphinDetailsViewTest
[dolphin.git] / src / tests / dolphindetailsviewtest.cpp
1 /***************************************************************************
2 * Copyright (C) 2010 by Frank Reininghaus (frank78ac@googlemail.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 "testhelper.h"
23
24 #include "views/dolphindetailsview.h"
25 #include "views/dolphinview.h"
26 #include "views/dolphinmodel.h"
27 #include "views/dolphindirlister.h"
28 #include "views/dolphinsortfilterproxymodel.h"
29 #include "views/zoomlevelinfo.h"
30
31 #include <KTempDir>
32
33 #include <QtCore/QDir>
34
35 #include "kdebug.h"
36
37 class DolphinDetailsViewTest : public QObject
38 {
39 Q_OBJECT
40
41 private slots:
42
43 void initTestCase();
44 void cleanupTestCase();
45
46 void bug234600_overlappingIconsWhenZooming();
47
48 private:
49
50 TestHelper* m_helper;
51 DolphinView* m_view;
52 };
53
54 void DolphinDetailsViewTest::initTestCase()
55 {
56 // add time stamps to find origin of test failures due to timeout at
57 // http://my.cdash.org/index.php?project=kdebase&date=
58 qputenv("KDE_DEBUG_TIMESTAMP", QByteArray("1"));
59
60 m_helper = new TestHelper;
61 m_view = m_helper->view();
62 }
63
64 void DolphinDetailsViewTest::cleanupTestCase()
65 {
66 delete m_helper;
67 }
68
69 /**
70 * When the icon size is changed, we have to make sure that the maximumSize given
71 * to KFileItemDelegate for rendering each item is updated correctly. If this is not
72 * done, the visualRects are clipped by the incorrect maximum size, and the icons
73 * may overlap, see
74 *
75 * https://bugs.kde.org/show_bug.cgi?id=234600
76 */
77
78 void DolphinDetailsViewTest::bug234600_overlappingIconsWhenZooming()
79 {
80 QStringList files;
81 files << "a" << "b" << "c" << "d";
82 m_helper->createFiles(files);
83
84 m_view->setMode(DolphinView::DetailsView);
85 DolphinDetailsView* detailsView = qobject_cast<DolphinDetailsView*>(m_helper->itemView());
86 QVERIFY(detailsView);
87 m_view->resize(400, 400);
88 m_view->show();
89 QTest::qWaitForWindowShown(m_view);
90
91 // We have to make sure that the view has loaded the directory before we start the test.
92 // TODO: This will be needed frequently. Maybe move to TestHelper.
93 kDebug() << "Reloading view and waiting for the finishedPathLoading(const KUrl&) signal...";
94 QSignalSpy finished(m_view, SIGNAL(finishedPathLoading(const KUrl&)));
95 m_view->reload();
96 while (finished.count() != 1) {
97 QTest::qWait(50);
98 }
99 kDebug() << "...signal received, continuing";
100
101 QModelIndex index0 = detailsView->model()->index(0, 0);
102 detailsView->setCurrentIndex(index0);
103 QCOMPARE(detailsView->currentIndex(), index0);
104
105 // Setting the zoom level to the minimum value and triggering DolphinDetailsView::currentChanged(...)
106 // should make sure that the bug is triggered.
107 int zoomLevel = ZoomLevelInfo::minimumLevel();
108 m_view->setZoomLevel(zoomLevel);
109
110 QModelIndex index1 = detailsView->model()->index(1, 0);
111 detailsView->setCurrentIndex(index1);
112 QCOMPARE(detailsView->currentIndex(), index1);
113
114 kDebug() << "Now checking zoom levels...";
115
116 // Increase the zoom level successively to the maximum.
117 while(zoomLevel < ZoomLevelInfo::maximumLevel()) {
118 zoomLevel++;
119 kDebug() << "Testing zoom level" << zoomLevel;
120 m_view->setZoomLevel(zoomLevel);
121
122 //Check for each zoom level that the height of each item is at least the icon size.
123 QVERIFY(detailsView->visualRect(index1).height() >= ZoomLevelInfo::iconSizeForZoomLevel(zoomLevel));
124 }
125
126 m_view->hide();
127
128 kDebug() << "Cleaning up test directory...";
129 m_helper->cleanupTestDir();
130 kDebug() << "Done.";
131 }
132
133 QTEST_KDEMAIN(DolphinDetailsViewTest, GUI)
134
135 #include "dolphindetailsviewtest.moc"