~ubuntu-branches/ubuntu/trusty/baloo/trusty

« back to all changes in this revision

Viewing changes to .pc/upstream_git/0029-FileIndexingJobTest-Test-timeouts.patch/src/file/autotest/fileindexingjob/fileindexingjobtest.cpp

  • Committer: Package Import Robot
  • Author(s): Jonathan Riddell
  • Date: 2014-04-10 21:32:59 UTC
  • mfrom: (1.1.3)
  • Revision ID: package-import@ubuntu.com-20140410213259-b3hkzveqwe4hd3ax
Tags: 4:4.13.0-0ubuntu1
New upstream KDE Software Compilation release

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
 * <one line to give the library's name and an idea of what it does.>
3
 
 * Copyright (C) 2014  Vishesh Handa <me@vhanda.in>
4
 
 *
5
 
 * This library is free software; you can redistribute it and/or
6
 
 * modify it under the terms of the GNU Lesser General Public
7
 
 * License as published by the Free Software Foundation; either
8
 
 * version 2.1 of the License, or (at your option) any later version.
9
 
 *
10
 
 * This library 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 GNU
13
 
 * Lesser General Public License for more details.
14
 
 *
15
 
 * You should have received a copy of the GNU Lesser General Public
16
 
 * License along with this library; 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 "fileindexingjobtest.h"
22
 
#include "../../fileindexingjob.h"
23
 
 
24
 
#include <QSignalSpy>
25
 
#include <QTest>
26
 
 
27
 
using namespace Baloo;
28
 
 
29
 
void FileIndexingJobTest::init()
30
 
{
31
 
    // Set the correct path
32
 
    QByteArray path = qgetenv("PATH");
33
 
    path = QByteArray(BALOO_TEMP_PATH) + ":" + path;
34
 
 
35
 
    setenv("PATH", path.constData(), 1);
36
 
    unsetenv("BALOO_EXTRACTOR_FAIL_FILE");
37
 
}
38
 
 
39
 
void FileIndexingJobTest::testFileFail()
40
 
{
41
 
    QVector<uint> files;
42
 
    for (int i = 0; i<40; i++) {
43
 
        files << i;
44
 
    }
45
 
 
46
 
    putenv("BALOO_EXTRACTOR_FAIL_FILE=5");
47
 
    FileIndexingJob* job = new FileIndexingJob(files);
48
 
 
49
 
    QSignalSpy spy(job, SIGNAL(indexingFailed(uint)));
50
 
    QVERIFY(job->exec());
51
 
 
52
 
    QCOMPARE(spy.count(), 1);
53
 
    QCOMPARE(spy.at(0).size(), 1);
54
 
    QCOMPARE(spy.at(0).first().toUInt(), (uint)5);
55
 
}
56
 
 
57
 
void FileIndexingJobTest::testMultiFileFail()
58
 
{
59
 
    QVector<uint> files;
60
 
    for (int i = 0; i<40; i++) {
61
 
        files << i;
62
 
    }
63
 
 
64
 
    putenv("BALOO_EXTRACTOR_FAIL_FILE=5,18,19");
65
 
    FileIndexingJob* job = new FileIndexingJob(files);
66
 
 
67
 
    QSignalSpy spy(job, SIGNAL(indexingFailed(uint)));
68
 
    QVERIFY(job->exec());
69
 
 
70
 
    QCOMPARE(spy.count(), 3);
71
 
    QCOMPARE(spy.at(0).size(), 1);
72
 
    QCOMPARE(spy.at(0).first().toUInt(), (uint)5);
73
 
    QCOMPARE(spy.at(1).size(), 1);
74
 
    QCOMPARE(spy.at(1).first().toUInt(), (uint)18);
75
 
    QCOMPARE(spy.at(2).size(), 1);
76
 
    QCOMPARE(spy.at(2).first().toUInt(), (uint)19);
77
 
}
78
 
 
79
 
void FileIndexingJobTest::testNormalExecution()
80
 
{
81
 
    QVector<uint> files;
82
 
    files << 1 << 2 << 3 << 4 << 5 << 6;
83
 
 
84
 
    FileIndexingJob* job = new FileIndexingJob(files);
85
 
 
86
 
    QSignalSpy spy1(job, SIGNAL(indexingFailed(uint)));
87
 
    QSignalSpy spy2(job, SIGNAL(finished(KJob*)));
88
 
    QVERIFY(job->exec());
89
 
 
90
 
    QCOMPARE(spy1.count(), 0);
91
 
    QCOMPARE(spy2.count(), 1);
92
 
}
93
 
 
94
 
QTEST_MAIN(FileIndexingJobTest);