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)
42
utime(QFile::encodeName(path).data(), 0);
45
void TimeUtilsTest::testPng()
47
KUrl url = urlForTestFile("test.png");
48
KFileItem item(KFileItem::Unknown, KFileItem::Unknown, url);
49
KDateTime dateTime = TimeUtils::dateTimeForFileItem(item);
50
QCOMPARE(dateTime, item.time(KFileItem::ModificationTime));
53
void TimeUtilsTest::testJpeg()
55
KUrl url = urlForTestFile("orient6.jpg");
56
KFileItem item(KFileItem::Unknown, KFileItem::Unknown, url);
57
KDateTime dateTime = TimeUtils::dateTimeForFileItem(item);
59
const KDateTime orient6DateTime = KDateTime::fromString("2003-03-25T02:02:21");
60
QCOMPARE(dateTime, orient6DateTime);
63
void TimeUtilsTest::testCache()
65
KTemporaryFile tempFile;
66
QVERIFY(tempFile.open());
67
KUrl url = KUrl::fromLocalFile(tempFile.fileName());
68
KFileItem item1(KFileItem::Unknown, KFileItem::Unknown, url);
69
KDateTime dateTime1 = TimeUtils::dateTimeForFileItem(item1);
70
QCOMPARE(dateTime1, item1.time(KFileItem::ModificationTime));
73
touchFile(url.toLocalFile());
75
KFileItem item2(KFileItem::Unknown, KFileItem::Unknown, url);
76
KDateTime dateTime2 = TimeUtils::dateTimeForFileItem(item2);
78
QVERIFY(dateTime1 != dateTime2);
80
QCOMPARE(dateTime2, item2.time(KFileItem::ModificationTime));