File indexing completed on 2024-05-12 04:19:58
0001 // vim: set tabstop=4 shiftwidth=4 expandtab: 0002 /* 0003 Gwenview: an image viewer 0004 Copyright 2011 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 "sorteddirmodeltest.h" 0023 0024 // Local 0025 #include <lib/semanticinfo/sorteddirmodel.h> 0026 0027 // Qt 0028 #include <QTemporaryDir> 0029 #include <QTest> 0030 0031 // KF 0032 #include <KDirLister> 0033 0034 using namespace Gwenview; 0035 0036 QTEST_MAIN(SortedDirModelTest) 0037 0038 void SortedDirModelTest::initTestCase() 0039 { 0040 mSandBoxDir.mkdir("empty_dir"); 0041 mSandBoxDir.mkdir("dirs_only"); 0042 mSandBoxDir.mkdir("dirs_only/dir1"); 0043 mSandBoxDir.mkdir("dirs_only/dir2"); 0044 mSandBoxDir.mkdir("dirs_and_docs"); 0045 mSandBoxDir.mkdir("dirs_and_docs/dir"); 0046 createEmptyFile(mSandBoxDir.absoluteFilePath("dirs_and_docs/file.png")); 0047 mSandBoxDir.mkdir("docs_only"); 0048 createEmptyFile(mSandBoxDir.absoluteFilePath("docs_only/file.png")); 0049 } 0050 0051 void SortedDirModelTest::testHasDocuments_data() 0052 { 0053 QTest::addColumn<QString>("dir"); 0054 QTest::addColumn<bool>("hasDocuments"); 0055 #define NEW_ROW(dir, hasDocuments) QTest::newRow(QString(dir).toLocal8Bit().data()) << mSandBoxDir.absoluteFilePath(dir) << hasDocuments 0056 NEW_ROW("empty_dir", false); 0057 NEW_ROW("dirs_only", false); 0058 NEW_ROW("dirs_and_docs", true); 0059 NEW_ROW("docs_only", true); 0060 #undef NEW_ROW 0061 } 0062 0063 void SortedDirModelTest::testHasDocuments() 0064 { 0065 QFETCH(QString, dir); 0066 QFETCH(bool, hasDocuments); 0067 QUrl url = QUrl::fromLocalFile(dir); 0068 0069 SortedDirModel model; 0070 QEventLoop loop; 0071 connect(model.dirLister(), SIGNAL(completed()), &loop, SLOT(quit())); 0072 model.dirLister()->openUrl(url); 0073 loop.exec(); 0074 QCOMPARE(model.hasDocuments(), hasDocuments); 0075 } 0076 0077 #include "moc_sorteddirmodeltest.cpp"