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

« back to all changes in this revision

Viewing changes to tests/testutils.h

  • 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
 
#ifndef TESTUTILS_H
21
 
#define TESTUTILS_H
22
 
 
23
 
#include <math.h>
24
 
 
25
 
// Qt
26
 
#include <QDir>
27
 
#include <QImage>
28
 
#include <QSignalSpy>
29
 
#include <QTest>
30
 
 
31
 
// KDE
32
 
#include <kdebug.h>
33
 
#include <kurl.h>
34
 
 
35
 
 
36
 
/*
37
 
 * This file contains simple helpers to access test files
38
 
 */
39
 
 
40
 
inline QString pathForTestFile(const QString& name) {
41
 
        return QString("%1/%2").arg(KDESRCDIR).arg(name);
42
 
}
43
 
 
44
 
inline KUrl urlForTestFile(const QString& name) {
45
 
        KUrl url;
46
 
        url.setPath(pathForTestFile(name));
47
 
        return url;
48
 
}
49
 
 
50
 
inline QString pathForTestOutputFile(const QString& name) {
51
 
        return QString("%1/%2").arg(QDir::currentPath()).arg(name);
52
 
}
53
 
 
54
 
inline KUrl urlForTestOutputFile(const QString& name) {
55
 
        KUrl url;
56
 
        url.setPath(pathForTestOutputFile(name));
57
 
        return url;
58
 
}
59
 
 
60
 
inline bool waitForSignal(const QSignalSpy& spy, int timeout = 5) {
61
 
        for (int x = 0; x < timeout; ++x) {
62
 
                if (spy.count() > 0) {
63
 
                        return true;
64
 
                }
65
 
                QTest::qWait(1000);
66
 
        }
67
 
        return false;
68
 
}
69
 
 
70
 
inline bool fuzzyImageCompare(const QImage& img1, const QImage& img2) {
71
 
        if (img1.size() != img2.size()) {
72
 
                kWarning() << "Different sizes" << img1.size() << img2.size();
73
 
                return false;
74
 
        }
75
 
        if (img1.format() != img2.format()) {
76
 
                kWarning() << "Different formats" << img1.format() << img2.format();
77
 
                return false;
78
 
        }
79
 
 
80
 
        for(int posY = 0; posY < img1.height(); ++posY) {
81
 
                for (int posX = 0; posX < img2.width(); ++posX) {
82
 
                        if (!(int)abs((double)img1.pixel(posX, posY) - img2.pixel(posX, posY)) > 2) {
83
 
                                kWarning() << "Different at" << QPoint(posX, posY);
84
 
                                return false;
85
 
                        }
86
 
                }
87
 
        }
88
 
        return true;
89
 
}
90
 
 
91
 
/**
92
 
 * Returns the url of the remote url dir if remote test dir was successfully
93
 
 * set up.
94
 
 * If testFile is valid, it is copied into the test dir.
95
 
 */
96
 
KUrl setUpRemoteTestDir(const QString& testFile = QString());
97
 
 
98
 
#endif /* TESTUTILS_H */