2
Gwenview: an image viewer
3
Copyright 2008 Aurélien Gâteau <agateau@kde.org>
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.
21
#include "timeutilstest.moc"
27
#include <kfileitem.h>
28
#include <ktemporaryfile.h>
29
#include <qtest_kde.h>
32
#include "../lib/timeutils.h"
34
#include "testutils.h"
36
QTEST_KDEMAIN( TimeUtilsTest, GUI )
38
using namespace Gwenview;
40
static void touchFile(const QString& path) {
41
utime(QFile::encodeName(path).data(), 0);
44
void TimeUtilsTest::testPng() {
45
KUrl url = urlForTestFile("test.png");
46
KFileItem item(KFileItem::Unknown, KFileItem::Unknown, url);
47
KDateTime dateTime = TimeUtils::dateTimeForFileItem(item);
48
QCOMPARE(dateTime, item.time(KFileItem::ModificationTime));
52
void TimeUtilsTest::testJpeg() {
53
KUrl url = urlForTestFile("orient6.jpg");
54
KFileItem item(KFileItem::Unknown, KFileItem::Unknown, url);
55
KDateTime dateTime = TimeUtils::dateTimeForFileItem(item);
57
const KDateTime orient6DateTime = KDateTime::fromString("2003-03-25T02:02:21");
58
QCOMPARE(dateTime, orient6DateTime);
62
void TimeUtilsTest::testCache() {
63
KTemporaryFile tempFile;
64
QVERIFY(tempFile.open());
65
KUrl url = KUrl::fromLocalFile(tempFile.fileName());
66
KFileItem item1(KFileItem::Unknown, KFileItem::Unknown, url);
67
KDateTime dateTime1 = TimeUtils::dateTimeForFileItem(item1);
68
QCOMPARE(dateTime1, item1.time(KFileItem::ModificationTime));
71
touchFile(url.toLocalFile());
73
KFileItem item2(KFileItem::Unknown, KFileItem::Unknown, url);
74
KDateTime dateTime2 = TimeUtils::dateTimeForFileItem(item2);
76
QVERIFY(dateTime1 != dateTime2);
78
QCOMPARE(dateTime2, item2.time(KFileItem::ModificationTime));