File indexing completed on 2024-05-12 04:19:57
0001 // vim: set tabstop=4 shiftwidth=4 expandtab: 0002 /* 0003 Gwenview: an image viewer 0004 Copyright 2013 Aurélien Gâteau <agateau@kde.org> 0005 0006 This program is free software; you can redistribute it and/or 0007 modify it under the terms of the GNU General Public License 0008 as published by the Free Software Foundation; either version 2 0009 of the License, or (at your option) any later version. 0010 0011 This program is distributed in the hope that it will be useful, 0012 but WITHOUT ANY WARRANTY; without even the implied warranty of 0013 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 0014 GNU General Public License for more details. 0015 0016 You should have received a copy of the GNU General Public License 0017 along with this program; if not, write to the Free Software 0018 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 0019 0020 */ 0021 // Self 0022 #include "contextmanagertest.h" 0023 0024 // Local 0025 #include <lib/contextmanager.h> 0026 #include <lib/semanticinfo/sorteddirmodel.h> 0027 0028 // Qt 0029 #include <QEventLoop> 0030 #include <QItemSelectionModel> 0031 #include <QTest> 0032 0033 // KF 0034 #include <KDirLister> 0035 0036 using namespace Gwenview; 0037 using namespace TestUtils; 0038 0039 QTEST_MAIN(ContextManagerTest) 0040 0041 void ContextManagerTest::testRemove() 0042 { 0043 // When the current image is removed Gwenview must go to the next image if 0044 // there is any, otherwise to the previous image. 0045 0046 SandBoxDir sandBox; 0047 sandBox.fill(QStringList() << QStringLiteral("a") << QStringLiteral("b") << QStringLiteral("c")); 0048 QUrl dirUrl = QUrl::fromLocalFile(sandBox.absolutePath()); 0049 0050 SortedDirModel dirModel; 0051 { 0052 QEventLoop loop; 0053 connect(dirModel.dirLister(), SIGNAL(completed()), &loop, SLOT(quit())); 0054 dirModel.dirLister()->openUrl(dirUrl); 0055 loop.exec(); 0056 } 0057 0058 QCOMPARE(dirModel.rowCount(), 3); 0059 0060 ContextManager manager(&dirModel, nullptr); 0061 // Select second row 0062 manager.selectionModel()->setCurrentIndex(dirModel.index(1, 0), QItemSelectionModel::Select); 0063 0064 // Remove "b", `manager` should select "c" 0065 sandBox.remove(QStringLiteral("b")); 0066 dirModel.dirLister()->updateDirectory(dirUrl); 0067 while (dirModel.rowCount() == 3) { 0068 QTest::qWait(100); 0069 } 0070 0071 QModelIndex currentIndex = manager.selectionModel()->currentIndex(); 0072 QCOMPARE(currentIndex.row(), 1); 0073 QCOMPARE(currentIndex.data(Qt::DisplayRole).toString(), QStringLiteral("c")); 0074 0075 // Remove "c", `manager` should select "a" 0076 sandBox.remove(QStringLiteral("c")); 0077 dirModel.dirLister()->updateDirectory(dirUrl); 0078 while (dirModel.rowCount() == 2) { 0079 QTest::qWait(100); 0080 } 0081 0082 currentIndex = manager.selectionModel()->currentIndex(); 0083 QCOMPARE(currentIndex.row(), 0); 0084 QCOMPARE(currentIndex.data(Qt::DisplayRole).toString(), QStringLiteral("a")); 0085 } 0086 0087 #include "moc_contextmanagertest.cpp"