2 Gwenview: an image viewer
3 Copyright 2007 Aurélien Gâteau <aurelien.gateau@free.fr>
5 This program is free software; you can redistribute it and/or
6 modify it under the terms of the GNU General Public License
7 as published by the Free Software Foundation; either version 2
8 of the License, or (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20 #include "thumbnailloadjobtest.moc"
28 #include <qtest_kde.h>
30 #include <kio/deletejob.h>
33 #include "../lib/thumbnailloadjob.h"
34 #include "testutils.h"
37 using namespace Gwenview
;
40 QTEST_KDEMAIN(ThumbnailLoadJobTest
, GUI
)
43 QString
sandBoxPath() {
44 return QDir::currentPath() + "/sandbox";
48 void createTestImage(const QString
& name
, int width
, int height
, const QColor
& color
) {
49 QImage
image(width
, height
, QImage::Format_RGB32
);
50 QPainter
painter(&image
);
51 painter
.fillRect(image
.rect(), color
);
53 image
.save(sandBoxPath() + '/' + name
, "png");
57 void ThumbnailLoadJobTest::init() {
58 ThumbnailLoadJob::setThumbnailBaseDir(sandBoxPath() + "/thumbnails/");
59 QDir
dir(sandBoxPath());
61 KUrl
sandBoxUrl("file://" + sandBoxPath());
62 KIO::Job
* job
= KIO::del(sandBoxUrl
);
63 QVERIFY2(job
->exec(), "Couldn't delete sandbox");
66 createTestImage("red.png", 300, 200, Qt::red
);
67 createTestImage("blue.png", 200, 300, Qt::blue
);
68 createTestImage("small.png", 50, 50, Qt::green
);
72 void ThumbnailLoadJobTest::testLoadLocal() {
73 QDir
dir(sandBoxPath());
76 Q_FOREACH(const QFileInfo
& info
, dir
.entryInfoList()) {
77 KUrl
url("file://" + info
.absoluteFilePath());
78 KFileItem
item(KFileItem::Unknown
, KFileItem::Unknown
, url
);
81 QPointer
<ThumbnailLoadJob
> job
= new ThumbnailLoadJob(list
, ThumbnailGroup::Normal
);
82 // FIXME: job->exec() causes a double free(), so wait for the job to be
90 QDir thumbnailDir
= ThumbnailLoadJob::thumbnailBaseDir(ThumbnailGroup::Normal
);
91 // There should be 2 files, because small.png is too small to have a
93 QStringList entryList
= thumbnailDir
.entryList(QStringList("*.png"));
94 QCOMPARE(entryList
.count(), 2);
98 void ThumbnailLoadJobTest::testLoadRemote() {
99 QString testTarGzPath
= pathForTestFile("test.tar.gz");
101 url
.setProtocol("tar");
102 url
.setPath(testTarGzPath
+ "/test.png");
105 KFileItem
item(KFileItem::Unknown
, KFileItem::Unknown
, url
);
108 QPointer
<ThumbnailLoadJob
> job
= new ThumbnailLoadJob(list
, ThumbnailGroup::Normal
);
109 // FIXME: job->exec() causes a double free(), so wait for the job to be
117 QDir thumbnailDir
= ThumbnailLoadJob::thumbnailBaseDir(ThumbnailGroup::Normal
);
118 QStringList entryList
= thumbnailDir
.entryList(QStringList("*.png"));
119 QCOMPARE(entryList
.count(), 1);