~ubuntu-branches/ubuntu/oneiric/strigi/oneiric

« back to all changes in this revision

Viewing changes to tests/indextesters/indexreadertester.cpp

  • Committer: Package Import Robot
  • Author(s): Fathi Boudra
  • Date: 2011-09-20 08:50:25 UTC
  • mto: (1.1.20 upstream) (5.1.6 sid)
  • mto: This revision was merged to the branch mainline in revision 44.
  • Revision ID: package-import@ubuntu.com-20110920085025-wszfu6x8rshrjq0e
ImportĀ upstreamĀ versionĀ 0.7.6

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* This file is part of Strigi Desktop Search
2
 
 *
3
 
 * Copyright (C) 2007 Flavio Castelli <flavio.castelli@gmail.com>
4
 
 *
5
 
 * This library is free software; you can redistribute it and/or
6
 
 * modify it under the terms of the GNU Library General Public
7
 
 * License as published by the Free Software Foundation; either
8
 
 * version 2 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
 
 * Library General Public License for more details.
14
 
 *
15
 
 * You should have received a copy of the GNU Library General Public License
16
 
 * along with this library; see the file COPYING.LIB.  If not, write to
17
 
 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18
 
 * Boston, MA 02110-1301, USA.
19
 
 */
20
 
#include "indexreadertester.h"
21
 
 
22
 
#include "analysisresult.h"
23
 
#include "indexwriter.h"
24
 
#include "indexreader.h"
25
 
#include "fieldtypes.h"
26
 
#include "query.h"
27
 
#include "queryparser.h"
28
 
 
29
 
#include <sstream>
30
 
#include <ostream>
31
 
 
32
 
using namespace std;
33
 
using namespace strigiunittest;
34
 
using namespace Strigi;
35
 
 
36
 
void
37
 
IndexReaderTest::setUp() {
38
 
    IndexTest::setUp();
39
 
    m_streamAnalyzer = new Strigi::StreamAnalyzer( m_analyzerConfiguration );
40
 
}
41
 
 
42
 
void
43
 
IndexReaderTest::tearDown() {
44
 
    delete m_streamAnalyzer;
45
 
    IndexTest::tearDown();
46
 
}
47
 
 
48
 
void
49
 
IndexReaderTest::testChildrenRetrieval() {
50
 
    // FIXME
51
 
}
52
 
 
53
 
void
54
 
IndexReaderTest::addAndCount() {
55
 
    static const int m = 20;
56
 
 
57
 
    m_writer->deleteAllEntries();
58
 
    ostringstream str;
59
 
    for (int i=0; i<m; ++i) {
60
 
        str << "/" << i;
61
 
        string s(str.str());
62
 
        { AnalysisResult idx(s, 0, *m_writer, *m_streamAnalyzer); }
63
 
        str.str("");
64
 
    }
65
 
    m_writer->commit();
66
 
 
67
 
    int n = m_reader->countDocuments();
68
 
 
69
 
    str.str("");
70
 
    CPPUNIT_ASSERT_EQUAL_MESSAGE(str.str(), m, n);
71
 
}
72
 
 
73
 
void
74
 
IndexReaderTest::testNumberQuery() {
75
 
    m_writer->deleteAllEntries();
76
 
    // add numbers to the database
77
 
    int m = 200;
78
 
    ostringstream str;
79
 
    for (int i=1; i<=m; ++i) {
80
 
        str << i;
81
 
        string value(str.str());
82
 
        string name('/'+value);
83
 
        {
84
 
            AnalysisResult idx(name, 0, *m_writer, *m_streamAnalyzer);
85
 
            idx.addValue(idx.config().fieldRegister().sizeField, value);
86
 
        }
87
 
        str.str("");
88
 
    }
89
 
    m_writer->commit();
90
 
    QueryParser parser;
91
 
    Query q = parser.buildQuery("contentSize>0");
92
 
    int count = m_reader->countHits(q);
93
 
 
94
 
    str.str("");
95
 
    CPPUNIT_ASSERT_EQUAL_MESSAGE(str.str(), m, count);
96
 
}