diff --git a/tests/auto/placetreemodeltest.cpp b/tests/auto/placetreemodeltest.cpp index f2f1ec29..d221bc60 100644 --- a/tests/auto/placetreemodeltest.cpp +++ b/tests/auto/placetreemodeltest.cpp @@ -1,168 +1,170 @@ /* Gwenview: an image viewer Copyright 2009 Aurélien Gâteau This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "placetreemodeltest.h" // Qt #include #include // KDE #include #include #include #include #include // Local #include "../lib/placetreemodel.h" #include "testutils.h" //#define KEEP_TEMP_DIR QTEST_MAIN(PlaceTreeModelTest) using namespace Gwenview; const char* BOOKMARKS_XML = "" "" "" " " " url1" " " " " " " " " " " " 1214343736/0" " true" " " " " " " " " " url2" " " " " " " " " " " " 1214343736/1" " true" " " " " " " ""; void PlaceTreeModelTest::initTestCase() { Q_ASSERT(mTempDir.isValid()); QDir dir(mTempDir.path()); const bool dir1created = dir.mkdir("url1"); Q_ASSERT(dir1created); Q_UNUSED(dir1created); mUrl1 = QUrl::fromLocalFile(dir.filePath("url1")); const bool dir2created = dir.mkdir("url2"); Q_ASSERT(dir2created); Q_UNUSED(dir2created); mUrl2 = QUrl::fromLocalFile(dir.filePath("url2")); mUrl1Dirs << "aaa" << "zzz" << "bbb"; Q_FOREACH(const QString & dirName, mUrl1Dirs) { dir.mkdir("url1/" + dirName); } #ifdef KEEP_TEMP_DIR mTempDir.setAutoRemove(false); //qDebug() << "mTempDir:" << mTempDir.name(); #endif } void PlaceTreeModelTest::init() { QStandardPaths::setTestModeEnabled(true); TestUtils::purgeUserConfiguration(); const QString confDir = QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation); QDir().mkpath(confDir); QFile bookmark(confDir + "/user-places.xbel"); const bool bookmarkOpened = bookmark.open(QIODevice::WriteOnly); Q_ASSERT(bookmarkOpened); Q_UNUSED(bookmarkOpened); QString xml = QString(BOOKMARKS_XML) .arg(mUrl1.url()) .arg(mUrl2.url()) ; bookmark.write(xml.toUtf8()); #ifdef KEEP_TEMP_DIR mTempDir.setAutoRemove(false); //qDebug() << "mTempDir:" << mTempDir.name(); #endif } void PlaceTreeModelTest::testListPlaces() { PlaceTreeModel model(0); -#if KIO_VERSION >= QT_VERSION_CHECK(5, 41, 0) +#if KIO_VERSION >= QT_VERSION_CHECK(5, 45, 0) + QCOMPARE(model.rowCount(), 8); +#elif KIO_VERSION >= QT_VERSION_CHECK(5, 41, 0) QCOMPARE(model.rowCount(), 10); #else QCOMPARE(model.rowCount(), 2); #endif QModelIndex index; index = model.index(0, 0); QCOMPARE(model.urlForIndex(index), mUrl1); index = model.index(1, 0); QCOMPARE(model.urlForIndex(index), mUrl2); } void PlaceTreeModelTest::testListUrl1() { PlaceTreeModel model(0); QModelIndex index = model.index(0, 0); QCOMPARE(model.urlForIndex(index), mUrl1); // We should not have fetched content yet QCOMPARE(model.rowCount(index), 0); QVERIFY(model.canFetchMore(index)); while (model.canFetchMore(index)) { model.fetchMore(index); } QTest::qWait(1000); QCOMPARE(model.rowCount(index), mUrl1Dirs.length()); QStringList dirs = mUrl1Dirs; dirs.sort(); for (int row = 0; row < dirs.count(); ++row) { QModelIndex subIndex = model.index(row, 0, index); QVERIFY(subIndex.isValid()); QString dirName = model.data(subIndex).toString(); QCOMPARE(dirName, dirs.value(row)); } }