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

« back to all changes in this revision

Viewing changes to tests/testutils.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 2010 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
 
#include "testutils.h"
21
 
 
22
 
// KDE
23
 
#include <kdebug.h>
24
 
#include <kio/deletejob.h>
25
 
#include <kio/netaccess.h>
26
 
#include <kio/job.h>
27
 
 
28
 
static void rm_rf(const QString& pathOrUrl) {
29
 
        KIO::Job* job = KIO::del(pathOrUrl, KIO::HideProgressInfo);
30
 
        job->setUiDelegate(0);
31
 
        KIO::NetAccess::synchronousRun(job, 0);
32
 
}
33
 
 
34
 
static bool mkdir(const QString& pathOrUrl) {
35
 
        KIO::Job* job = KIO::mkdir(pathOrUrl, -1);
36
 
        job->setUiDelegate(0);
37
 
        return KIO::NetAccess::synchronousRun(job, 0);
38
 
}
39
 
 
40
 
static bool cp(const QString& src, const QString& _dst) {
41
 
        KIO::Job* job = KIO::file_copy(src, _dst, -1, KIO::Overwrite | KIO::HideProgressInfo);
42
 
        job->setUiDelegate(0);
43
 
        return KIO::NetAccess::synchronousRun(job, 0);
44
 
}
45
 
 
46
 
KUrl setUpRemoteTestDir(const QString& testFile) {
47
 
        if (!qgetenv("NO_REMOTE_TESTS").isEmpty()) {
48
 
                kWarning() << "Remote tests disabled";
49
 
                return KUrl();
50
 
        }
51
 
 
52
 
        QString testDir("/tmp/gwenview-remote-tests/");
53
 
        rm_rf(testDir);
54
 
 
55
 
        if (!mkdir(testDir)) {
56
 
                kFatal() << "Could not create dir" << testDir;
57
 
                return KUrl();
58
 
        }
59
 
 
60
 
        if (!testFile.isEmpty()) {
61
 
                if (!cp(pathForTestFile(testFile), testDir + testFile)) {
62
 
                        kFatal() << "Could not copy" << testFile << "to" << testDir;
63
 
                        return KUrl();
64
 
                }
65
 
        }
66
 
 
67
 
        return KUrl("sftp://localhost" + testDir);
68
 
}