/* 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.moc" // Qt #include #include // KDE #include #include #include // Local #include "../lib/placetreemodel.h" #include "testutils.h" //#define KEEP_TEMP_DIR QTEST_KDEMAIN(PlaceTreeModelTest, GUI) using namespace Gwenview; const char* BOOKMARKS_XML = "" "" "" " " " url1" " " " " " " " " " " " 1214343736/0" " true" " " " " " " " " " url2" " " " " " " " " " " " 1214343736/1" " true" " " " " " " ""; void PlaceTreeModelTest::initTestCase() { Q_ASSERT(mTempDir.exists()); QDir dir(mTempDir.name()); const bool dir1created = dir.mkdir("url1"); Q_ASSERT(dir1created); Q_UNUSED(dir1created); mUrl1 = KUrl::fromPath(dir.filePath("url1")); const bool dir2created = dir.mkdir("url2"); Q_ASSERT(dir2created); Q_UNUSED(dir2created); mUrl2 = KUrl::fromPath(dir.filePath("url2")); mUrl1Dirs << "aaa" << "zzz" << "bbb"; Q_FOREACH(const QString & dirName, mUrl1Dirs) { dir.mkdir("url1/" + dirName); } #ifdef KEEP_TEMP_DIR mTempDir.setAutoRemove(false); kDebug() << "mTempDir:" << mTempDir.name(); #endif } void PlaceTreeModelTest::init() { TestUtils::purgeUserConfiguration(); QFile bookmark(KStandardDirs::locateLocal("data", "kfileplaces/bookmarks.xml")); const bool bookmarkOpened = bookmark.open(QIODevice::WriteOnly); Q_ASSERT(bookmarkOpened); Q_UNUSED(bookmarkOpened); QString xml = QString(BOOKMARKS_XML) .arg(mUrl1.toLocalFile()) .arg(mUrl2.toLocalFile()) ; bookmark.write(xml.toUtf8()); #ifdef KEEP_TEMP_DIR mTempDir.setAutoRemove(false); kDebug() << "mTempDir:" << mTempDir.name(); #endif } void PlaceTreeModelTest::testListPlaces() { PlaceTreeModel model(0); QCOMPARE(model.rowCount(), 2); 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)); } }