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 "basicindexingqueuetest.h" |
22 | #include "fileindexerconfigutils.h" |
23 | |
24 | #include "../fileindexerconfig.h" |
25 | #include "../basicindexingqueue.h" |
26 | #include "../database.h" |
27 | |
28 | #include "qtest_kde.h" |
29 | |
30 | #include <QSignalSpy> |
31 | #include <QEventLoop> |
32 | |
33 | using namespace Baloo; |
34 | |
35 | void BasicIndexingQueueTest::testSimpleDirectoryStructure() |
36 | { |
37 | qRegisterMetaType<Xapian::Document>("Xapian::Document" ); |
38 | |
39 | QStringList dirs; |
40 | dirs << QLatin1String("home/" ); |
41 | dirs << QLatin1String("home/1" ); |
42 | dirs << QLatin1String("home/2" ); |
43 | dirs << QLatin1String("home/kde/" ); |
44 | dirs << QLatin1String("home/kde/1" ); |
45 | dirs << QLatin1String("home/docs/" ); |
46 | dirs << QLatin1String("home/docs/1" ); |
47 | |
48 | QScopedPointer<KTempDir> dir(Test::createTmpFilesAndFolders(dirs)); |
49 | QString p = dir->name(); |
50 | |
51 | QStringList includeFolders; |
52 | includeFolders << dir->name() + QLatin1String("home" ); |
53 | |
54 | QStringList excludeFolders; |
55 | excludeFolders << dir->name() + QLatin1String("home/kde" ); |
56 | |
57 | Test::writeIndexerConfig(includeFolders, excludeFolders); |
58 | |
59 | KTempDir dbDir; |
60 | Database db; |
61 | db.setPath(dbDir.name()); |
62 | db.init(); |
63 | |
64 | FileIndexerConfig config; |
65 | BasicIndexingQueue queue(&db, &config); |
66 | queue.enqueue(FileMapping(p + QLatin1String("home" ))); |
67 | |
68 | QSignalSpy spy(&queue, SIGNAL(newDocument(uint,Xapian::Document))); |
69 | queue.resume(); |
70 | |
71 | QEventLoop loop; |
72 | connect(&queue, SIGNAL(finishedIndexing()), &loop, SLOT(quit())); |
73 | loop.exec(); |
74 | |
75 | // kde and kde/1 are not indexed |
76 | QCOMPARE(spy.count(), 5); |
77 | } |
78 | |
79 | QTEST_KDEMAIN_CORE(BasicIndexingQueueTest) |
80 | |