~ubuntu-branches/ubuntu/precise/gwenview/precise-proposed

« back to all changes in this revision

Viewing changes to tests/timeutilstest.cpp

  • Committer: Package Import Robot
  • Author(s): Jonathan Riddell
  • Date: 2011-12-15 14:17:54 UTC
  • mto: This revision was merged to the branch mainline in revision 12.
  • Revision ID: package-import@ubuntu.com-20111215141754-z043hyx69dulbggf
Tags: upstream-4.7.90
Import upstream version 4.7.90

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
Gwenview: an image viewer
3
 
Copyright 2008 Aurélien Gâteau <agateau@kde.org>
4
 
 
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.
9
 
 
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.
14
 
 
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.
18
 
 
19
 
*/
20
 
 
21
 
#include "timeutilstest.moc"
22
 
 
23
 
// libc
24
 
#include <utime.h>
25
 
 
26
 
// KDE
27
 
#include <kfileitem.h>
28
 
#include <ktemporaryfile.h>
29
 
#include <qtest_kde.h>
30
 
 
31
 
// Local
32
 
#include "../lib/timeutils.h"
33
 
 
34
 
#include "testutils.h"
35
 
 
36
 
QTEST_KDEMAIN( TimeUtilsTest, GUI )
37
 
 
38
 
using namespace Gwenview;
39
 
 
40
 
static void touchFile(const QString& path) {
41
 
        utime(QFile::encodeName(path).data(), 0);
42
 
}
43
 
 
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));
49
 
}
50
 
 
51
 
 
52
 
void TimeUtilsTest::testJpeg() {
53
 
        KUrl url = urlForTestFile("orient6.jpg");
54
 
        KFileItem item(KFileItem::Unknown, KFileItem::Unknown, url);
55
 
        KDateTime dateTime = TimeUtils::dateTimeForFileItem(item);
56
 
 
57
 
        const KDateTime orient6DateTime = KDateTime::fromString("2003-03-25T02:02:21");
58
 
        QCOMPARE(dateTime, orient6DateTime);
59
 
}
60
 
 
61
 
 
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));
69
 
 
70
 
        QTest::qWait(1200);
71
 
        touchFile(url.toLocalFile());
72
 
 
73
 
        KFileItem item2(KFileItem::Unknown, KFileItem::Unknown, url);
74
 
        KDateTime dateTime2 = TimeUtils::dateTimeForFileItem(item2);
75
 
 
76
 
        QVERIFY(dateTime1 != dateTime2);
77
 
 
78
 
        QCOMPARE(dateTime2, item2.time(KFileItem::ModificationTime));
79
 
}