[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-commits
Subject: KDE/kdebase/apps/dolphin/src/tests
From: Frank Reininghaus <frank78ac () googlemail ! com>
Date: 2011-01-26 13:38:20
Message-ID: 20110126133820.25CCFAC8BB () svn ! kde ! org
[Download RAW message or body]
SVN commit 1217270 by freininghaus:
Some additions to DolphinDetailsViewTest_AllViewModes.
In particular, tests for changing the zoom level and for saving and
restoring the view state.
M +4 -4 CMakeLists.txt
M +153 -2 dolphinviewtest_allviewmodes.cpp
M +2 -0 dolphinviewtest_allviewmodes.h
--- trunk/KDE/kdebase/apps/dolphin/src/tests/CMakeLists.txt #1217269:1217270
@@ -1,5 +1,5 @@
set( EXECUTABLE_OUTPUT_PATH ${CMAKE_CURRENT_BINARY_DIR} )
-include_directories( ${CMAKE_CURRENT_SOURCE_DIR}/.. ${KDE4_INCLUDES} )
+include_directories( ${CMAKE_CURRENT_SOURCE_DIR}/.. ${CMAKE_CURRENT_BUILD_DIR}/.. \
${KDE4_INCLUDES} )
kde4_add_unit_test(dolphintreeviewtest TEST dolphintreeviewtest.cpp)
target_link_libraries(dolphintreeviewtest dolphinprivate ${KDE4_KDEUI_LIBS} \
${QT_QTTEST_LIBRARY}) @@ -7,11 +7,11 @@
kde4_add_unit_test(dolphindetailsviewtest TEST dolphindetailsviewtest.cpp \
testbase.cpp ../views/zoomlevelinfo.cpp) \
target_link_libraries(dolphindetailsviewtest dolphinprivate ${KDE4_KIO_LIBS} \
${QT_QTTEST_LIBRARY})
-kde4_add_unit_test(dolphinviewtest_icons TEST dolphinviewtest_icons.cpp \
dolphinviewtest_allviewmodes.cpp testbase.cpp) \
+kde4_add_unit_test(dolphinviewtest_icons TEST dolphinviewtest_icons.cpp \
dolphinviewtest_allviewmodes.cpp testbase.cpp ../views/zoomlevelinfo.cpp) \
target_link_libraries(dolphinviewtest_icons dolphinprivate ${KDE4_KIO_LIBS} \
${QT_QTTEST_LIBRARY})
-kde4_add_unit_test(dolphinviewtest_details TEST dolphinviewtest_details.cpp \
dolphinviewtest_allviewmodes.cpp testbase.cpp) \
+kde4_add_unit_test(dolphinviewtest_details TEST dolphinviewtest_details.cpp \
dolphinviewtest_allviewmodes.cpp testbase.cpp ../views/zoomlevelinfo.cpp) \
target_link_libraries(dolphinviewtest_details dolphinprivate ${KDE4_KIO_LIBS} \
${QT_QTTEST_LIBRARY})
-kde4_add_unit_test(dolphinviewtest_columns TEST dolphinviewtest_columns.cpp \
dolphinviewtest_allviewmodes.cpp testbase.cpp) \
+kde4_add_unit_test(dolphinviewtest_columns TEST dolphinviewtest_columns.cpp \
dolphinviewtest_allviewmodes.cpp testbase.cpp ../views/zoomlevelinfo.cpp) \
target_link_libraries(dolphinviewtest_columns dolphinprivate ${KDE4_KIO_LIBS} \
${QT_QTTEST_LIBRARY})
--- trunk/KDE/kdebase/apps/dolphin/src/tests/dolphinviewtest_allviewmodes.cpp \
#1217269:1217270 @@ -27,7 +27,10 @@
#include "views/dolphinmodel.h"
#include "views/dolphindirlister.h"
#include "views/dolphinsortfilterproxymodel.h"
+#include "views/zoomlevelinfo.h"
+#include <QtGui/QScrollBar>
+
#include <qtestmouse.h>
#include <qtestkeyboard.h>
@@ -105,15 +108,22 @@
QTest::mouseClick(itemView()->viewport(), Qt::LeftButton, Qt::ControlModifier, \
itemView()->visualRect(index).center()); verifySelectedItemsCount(1);
- index = itemView()->model()->index(45, 0);
+ index = itemView()->model()->index(totalItems - 5, 0);
itemView()->scrollTo(index);
QTest::mouseClick(itemView()->viewport(), Qt::LeftButton, Qt::ControlModifier, \
itemView()->visualRect(index).center()); verifySelectedItemsCount(2);
- index = itemView()->model()->index(48, 0);
+ index = itemView()->model()->index(totalItems - 2, 0);
itemView()->scrollTo(index);
QTest::mouseClick(itemView()->viewport(), Qt::LeftButton, Qt::ShiftModifier, \
itemView()->visualRect(index).center()); verifySelectedItemsCount(5);
+
+ m_view->invertSelection();
+ verifySelectedItemsCount(totalItems - 5);
+
+ // Pressing Esc should clear the selection
+ QTest::keyClick(itemView()->viewport(), Qt::Key_Escape);
+ verifySelectedItemsCount(0);
}
/**
@@ -214,6 +224,147 @@
}
/**
+ * testZoomLevel() checks that setting the zoom level works, both using \
DolphinView's API and using Ctrl+mouse wheel. + */
+
+void DolphinViewTest_AllViewModes::testZoomLevel()
+{
+ createFiles(QStringList() << "a" << "b");
+ reloadViewAndWait();
+
+ m_view->setShowPreview(false);
+ QVERIFY(!m_view->showPreview());
+
+ int zoomLevelBackup = m_view->zoomLevel();
+
+ int zoomLevel = ZoomLevelInfo::minimumLevel();
+ m_view->setZoomLevel(zoomLevel);
+ QCOMPARE(m_view->zoomLevel(), zoomLevel);
+
+ // Increase the zoom level successively to the maximum.
+ while(zoomLevel < ZoomLevelInfo::maximumLevel()) {
+ zoomLevel++;
+ m_view->setZoomLevel(zoomLevel);
+ QCOMPARE(m_view->zoomLevel(), zoomLevel);
+ }
+
+ // Try setting a zoom level larger than the maximum
+ m_view->setZoomLevel(ZoomLevelInfo::maximumLevel() + 1);
+ QCOMPARE(m_view->zoomLevel(), ZoomLevelInfo::maximumLevel());
+
+ // Turn previews on and try setting a zoom level smaller than the minimum
+ m_view->setShowPreview(true);
+ QVERIFY(m_view->showPreview());
+ m_view->setZoomLevel(ZoomLevelInfo::minimumLevel() - 1);
+ QCOMPARE(m_view->zoomLevel(), ZoomLevelInfo::minimumLevel());
+
+ // Turn previews off again and check that the zoom level is restored
+ m_view->setShowPreview(false);
+ QVERIFY(!m_view->showPreview());
+ QCOMPARE(m_view->zoomLevel(), ZoomLevelInfo::maximumLevel());
+
+ // Change the zoom level using Ctrl+mouse wheel
+ QModelIndex index = itemView()->model()->index(0, 0);
+ itemView()->scrollTo(index);
+
+ while (m_view->zoomLevel() > ZoomLevelInfo::minimumLevel()) {
+ int oldZoomLevel = m_view->zoomLevel();
+ QWheelEvent wheelEvent(itemView()->visualRect(index).center(), -1, \
Qt::NoButton, Qt::ControlModifier); + bool wheelEventReceived = \
qApp->notify(itemView()->viewport(), &wheelEvent); + \
QVERIFY(wheelEventReceived); + QVERIFY(m_view->zoomLevel() < oldZoomLevel);
+ }
+ QCOMPARE(m_view->zoomLevel(), ZoomLevelInfo::minimumLevel());
+
+ while (m_view->zoomLevel() < ZoomLevelInfo::maximumLevel()) {
+ int oldZoomLevel = m_view->zoomLevel();
+ QWheelEvent wheelEvent(itemView()->visualRect(index).center(), 1, \
Qt::NoButton, Qt::ControlModifier); + bool wheelEventReceived = \
qApp->notify(itemView()->viewport(), &wheelEvent); + \
QVERIFY(wheelEventReceived); + QVERIFY(m_view->zoomLevel() > oldZoomLevel);
+ }
+ QCOMPARE(m_view->zoomLevel(), ZoomLevelInfo::maximumLevel());
+
+ // Turn previews on again and check that the zoom level is restored
+ m_view->setShowPreview(true);
+ QVERIFY(m_view->showPreview());
+ QCOMPARE(m_view->zoomLevel(), ZoomLevelInfo::minimumLevel());
+
+ // Restore the initial state
+ m_view->setZoomLevel(zoomLevelBackup);
+ m_view->setShowPreview(false);
+ m_view->setZoomLevel(zoomLevelBackup);
+}
+
+/**
+ * testSaveAndRestoreState() checks if saving and restoring the view state (current \
item, scroll position). + *
+ * Note that we call qApp->sendPostedEvents() every time the view's \
finishedPathLoading(const KUrl&) signal + * is received. The reason is that the \
scroll position is restored in the slot restoreContentsPosition(), + * which is been \
invoked using a queued connection in DolphinView::slotLoadingCompleted(). To make \
sure + * that this slot is really executed before we proceed, we have to empty the \
event queue using qApp->sendPostedEvents(). + */
+
+void DolphinViewTest_AllViewModes::testSaveAndRestoreState()
+{
+ const int totalItems = 50;
+
+ for (int i = 0; i < totalItems; i++) {
+ createFile(QString("%1").arg(i));
+ }
+ createDir("51");
+ reloadViewAndWait();
+
+ // Set sorting settings to the default to make sure that the item positions are \
reproducible. + m_view->setSorting(DolphinView::SortByName);
+ QCOMPARE(m_view->sorting(), DolphinView::SortByName);
+ m_view->setSortOrder(Qt::AscendingOrder);
+ QCOMPARE(m_view->sortOrder(), Qt::AscendingOrder);
+
+ const QModelIndex index45 = itemView()->model()->index(45, 0);
+ itemView()->scrollTo(index45);
+ itemView()->setCurrentIndex(index45);
+ const int scrollPosX = itemView()->horizontalScrollBar()->value();
+ const int scrollPosY = itemView()->verticalScrollBar()->value();
+
+ // Save the view state
+ QByteArray viewState;
+ QDataStream saveStream(&viewState, QIODevice::WriteOnly);
+ m_view->saveState(saveStream);
+
+ // Change the URL and then go back
+ m_view->setUrl(m_path + "/51");
+ QVERIFY(QTest::kWaitForSignal(m_view, SIGNAL(finishedPathLoading(const KUrl&)), \
2000)); + qApp->sendPostedEvents();
+
+ m_view->setUrl(m_path);
+ QVERIFY(QTest::kWaitForSignal(m_view, SIGNAL(finishedPathLoading(const KUrl&)), \
2000)); + qApp->sendPostedEvents();
+
+ // Verify that the view is scrolled to top and that item 45 is not the current \
item + QVERIFY(itemView()->currentIndex() != index45);
+ QCOMPARE(itemView()->horizontalScrollBar()->value(), 0);
+ QCOMPARE(itemView()->verticalScrollBar()->value(), 0);
+
+ // Change the URL again
+ m_view->setUrl(m_path + "/51");
+ QVERIFY(QTest::kWaitForSignal(m_view, SIGNAL(finishedPathLoading(const KUrl&)), \
2000)); + qApp->sendPostedEvents();
+
+ // Check that the current item and scroll position are correct if \
DolphinView::restoreState() + // is called after the URL change
+ m_view->setUrl(m_path);
+ QDataStream restoreStream(viewState);
+ m_view->restoreState(restoreStream);
+ QVERIFY(QTest::kWaitForSignal(m_view, SIGNAL(finishedPathLoading(const KUrl&)), \
2000)); + qApp->sendPostedEvents();
+
+ QCOMPARE(itemView()->currentIndex(), index45);
+ QCOMPARE(itemView()->horizontalScrollBar()->value(), scrollPosX);
+ QCOMPARE(itemView()->verticalScrollBar()->value(), scrollPosY);
+}
+
+/**
* testKeyboardFocus() checks whether a view grabs the keyboard focus.
*
* A view may never grab the keyboard focus itself and must respect the focus-state
--- trunk/KDE/kdebase/apps/dolphin/src/tests/dolphinviewtest_allviewmodes.h \
#1217269:1217270 @@ -50,6 +50,8 @@
void testSelection();
void testViewPropertySettings();
+ void testZoomLevel();
+ void testSaveAndRestoreState();
void testKeyboardFocus();
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic