]> cloud.milkyroute.net Git - dolphin.git/blobdiff - src/tests/kitemlistcontrollertest.cpp
Fix crash when triggereing the "Compare files" action via D-Bus
[dolphin.git] / src / tests / kitemlistcontrollertest.cpp
index 8044f9ac946dda66821170d21f9ee4401ecb1e55..60e93e539abc9f87926ba7c9c0dcbf36440a4569 100644 (file)
@@ -98,7 +98,7 @@ void KItemListControllerTest::initTestCase()
         << "b1"
         << "c1" << "c2" << "c3" << "c4" << "c5"
         << "d1" << "d2" << "d3" << "d4"
-        << "e1" << "e2" << "e3" << "e4" << "e5" << "e6" << "e7";
+        << "e" << "e 2" << "e 3" << "e 4" << "e 5" << "e 6" << "e 7";
 
     m_testDir->createFiles(files);
     m_model->loadDirectory(m_testDir->url());
@@ -282,7 +282,14 @@ void KItemListControllerTest::testKeyboardNavigation_data()
                         << qMakePair(KeyPress(Qt::Key_Home), ViewState(0, QSet<int>() << 0))
                         << qMakePair(KeyPress(Qt::Key_Space, Qt::ControlModifier), ViewState(0, QSet<int>()))
                         << qMakePair(KeyPress(Qt::Key_Enter), ViewState(0, QSet<int>(), true))
-                        << qMakePair(KeyPress(Qt::Key_Space, Qt::ControlModifier), ViewState(0, QSet<int>() << 0));
+                        << qMakePair(KeyPress(Qt::Key_Space, Qt::ControlModifier), ViewState(0, QSet<int>() << 0))
+                        << qMakePair(KeyPress(Qt::Key_Space, Qt::ControlModifier), ViewState(0, QSet<int>()))
+                        << qMakePair(KeyPress(Qt::Key_Space), ViewState(0, QSet<int>() << 0))
+                        << qMakePair(KeyPress(Qt::Key_E), ViewState(13, QSet<int>() << 13))
+                        << qMakePair(KeyPress(Qt::Key_Space), ViewState(14, QSet<int>() << 14))
+                        << qMakePair(KeyPress(Qt::Key_3), ViewState(15, QSet<int>() << 15))
+                        << qMakePair(KeyPress(Qt::Key_Home), ViewState(0, QSet<int>() << 0))
+                        << qMakePair(KeyPress(Qt::Key_Escape), ViewState(0, QSet<int>()));
 
                     // Next, we test combinations of key presses which only work for a
                     // particular number of columns and either enabled or disabled grouping.
@@ -521,12 +528,9 @@ void KItemListControllerTest::testMouseClickActivation()
     adjustGeometryForColumnCount(5);
 
     // Make sure that the first item is visible in the view.
-    QTest::keyClick(m_container, Qt::Key_End, Qt::NoModifier);
-    QTest::keyClick(m_container, Qt::Key_Home, Qt::NoModifier);
-    while (m_view->firstVisibleIndex() > 0) {
-        QTest::qWait(50);
-    }
-    
+    m_view->setScrollOffset(0);
+    QCOMPARE(m_view->firstVisibleIndex(), 0);
+
     const QPointF pos = m_view->itemContextRect(0).center();
 
     // Save the "single click" setting.
@@ -544,33 +548,52 @@ void KItemListControllerTest::testMouseClickActivation()
     mouseReleaseEvent.setPos(pos);
     mouseReleaseEvent.setButton(Qt::LeftButton);
     mouseReleaseEvent.setButtons(Qt::NoButton);
-    
+
     QSignalSpy spyItemActivated(m_controller, SIGNAL(itemActivated(int)));
-        
+
     // Default setting: single click activation.
     group.writeEntry("SingleClick", true, KConfig::Persistent|KConfig::Global);
     config.sync();
     KGlobalSettings::self()->emitChange(KGlobalSettings::SettingsChanged, KGlobalSettings::SETTINGS_MOUSE);
-    while (!KGlobalSettings::singleClick()) {
+
+    int iterations = 0;
+    const int maxIterations = 20;
+    while (!KGlobalSettings::singleClick() && iterations < maxIterations) {
         QTest::qWait(50);
+        ++iterations;
+    }
+
+    if (!KGlobalSettings::singleClick()) {
+        // TODO: Try to find a way to make sure that changing the global setting works.
+        QSKIP("Failed to change the KGlobalSettings::singleClick() setting!", SkipSingle);
     }
+
     m_view->event(&mousePressEvent);
     m_view->event(&mouseReleaseEvent);
     QCOMPARE(spyItemActivated.count(), 1);
     spyItemActivated.clear();
-    
+
     // Set the global setting to "double click activation".
     group.writeEntry("SingleClick", false, KConfig::Persistent|KConfig::Global);
     config.sync();
     KGlobalSettings::self()->emitChange(KGlobalSettings::SettingsChanged, KGlobalSettings::SETTINGS_MOUSE);
-    while (KGlobalSettings::singleClick()) {
+
+    iterations = 0;
+    while (KGlobalSettings::singleClick() && iterations < maxIterations) {
         QTest::qWait(50);
+        ++iterations;
     }
+
+    if (KGlobalSettings::singleClick()) {
+        // TODO: Try to find a way to make sure that changing the global setting works.
+        QSKIP("Failed to change the KGlobalSettings::singleClick() setting!", SkipSingle);
+    }
+
     m_view->event(&mousePressEvent);
     m_view->event(&mouseReleaseEvent);
     QCOMPARE(spyItemActivated.count(), 0);
     spyItemActivated.clear();
-    
+
     // Enforce single click activation in the controller.
     m_controller->setSingleClickActivationEnforced(true);
     m_view->event(&mousePressEvent);
@@ -584,19 +607,28 @@ void KItemListControllerTest::testMouseClickActivation()
     m_view->event(&mouseReleaseEvent);
     QCOMPARE(spyItemActivated.count(), 0);
     spyItemActivated.clear();
-    
+
     // Set the global setting back to "single click activation".
     group.writeEntry("SingleClick", true, KConfig::Persistent|KConfig::Global);
     config.sync();
     KGlobalSettings::self()->emitChange(KGlobalSettings::SettingsChanged, KGlobalSettings::SETTINGS_MOUSE);
-    while (!KGlobalSettings::singleClick()) {
+
+    iterations = 0;
+    while (!KGlobalSettings::singleClick() && iterations < maxIterations) {
         QTest::qWait(50);
+        ++iterations;
     }
+
+    if (!KGlobalSettings::singleClick()) {
+        // TODO: Try to find a way to make sure that changing the global setting works.
+        QSKIP("Failed to change the KGlobalSettings::singleClick() setting!", SkipSingle);
+    }
+
     m_view->event(&mousePressEvent);
     m_view->event(&mouseReleaseEvent);
     QCOMPARE(spyItemActivated.count(), 1);
     spyItemActivated.clear();
-    
+
     // Enforce single click activation in the controller.
     m_controller->setSingleClickActivationEnforced(true);
     m_view->event(&mousePressEvent);
@@ -609,8 +641,16 @@ void KItemListControllerTest::testMouseClickActivation()
     group.writeEntry("SingleClick", restoreKGlobalSettingsSingleClick, KConfig::Persistent|KConfig::Global);
     config.sync();
     KGlobalSettings::self()->emitChange(KGlobalSettings::SettingsChanged, KGlobalSettings::SETTINGS_MOUSE);
-    while (KGlobalSettings::singleClick() != restoreKGlobalSettingsSingleClick) {
+    
+    iterations = 0;
+    while (KGlobalSettings::singleClick() != restoreKGlobalSettingsSingleClick && iterations < maxIterations) {
         QTest::qWait(50);
+        ++iterations;
+    }
+
+    if (KGlobalSettings::singleClick() != restoreKGlobalSettingsSingleClick) {
+        // TODO: Try to find a way to make sure that changing the global setting works.
+        QSKIP("Failed to change the KGlobalSettings::singleClick() setting!", SkipSingle);
     }
 }