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

« back to all changes in this revision

Viewing changes to tests/auto/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
{
 
42
    utime(QFile::encodeName(path).data(), 0);
 
43
}
 
44
 
 
45
void TimeUtilsTest::testPng()
 
46
{
 
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));
 
51
}
 
52
 
 
53
void TimeUtilsTest::testJpeg()
 
54
{
 
55
    KUrl url = urlForTestFile("orient6.jpg");
 
56
    KFileItem item(KFileItem::Unknown, KFileItem::Unknown, url);
 
57
    KDateTime dateTime = TimeUtils::dateTimeForFileItem(item);
 
58
 
 
59
    const KDateTime orient6DateTime = KDateTime::fromString("2003-03-25T02:02:21");
 
60
    QCOMPARE(dateTime, orient6DateTime);
 
61
}
 
62
 
 
63
void TimeUtilsTest::testCache()
 
64
{
 
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));
 
71
 
 
72
    QTest::qWait(1200);
 
73
    touchFile(url.toLocalFile());
 
74
 
 
75
    KFileItem item2(KFileItem::Unknown, KFileItem::Unknown, url);
 
76
    KDateTime dateTime2 = TimeUtils::dateTimeForFileItem(item2);
 
77
 
 
78
    QVERIFY(dateTime1 != dateTime2);
 
79
 
 
80
    QCOMPARE(dateTime2, item2.time(KFileItem::ModificationTime));
 
81
}