LCOV - code coverage report
Current view: top level - tests - api_matchspy.cc (source / functions) Hit Total Coverage
Test: Test Coverage for xapian-core 954b5873a738 Lines: 191 193 99.0 %
Date: 2019-06-30 05:20:33 Functions: 13 14 92.9 %
Branches: 284 1434 19.8 %

           Branch data     Line data    Source code
       1                 :            : /** @file api_matchspy.cc
       2                 :            :  * @brief tests of MatchSpy usage
       3                 :            :  */
       4                 :            : /* Copyright 2007,2009 Lemur Consulting Ltd
       5                 :            :  * Copyright 2009,2011,2012,2015,2019 Olly Betts
       6                 :            :  * Copyright 2010 Richard Boulton
       7                 :            :  *
       8                 :            :  * This program is free software; you can redistribute it and/or
       9                 :            :  * modify it under the terms of the GNU General Public License as
      10                 :            :  * published by the Free Software Foundation; either version 2 of the
      11                 :            :  * License, or (at your option) any later version.
      12                 :            :  *
      13                 :            :  * This program is distributed in the hope that it will be useful,
      14                 :            :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
      15                 :            :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      16                 :            :  * GNU General Public License for more details.
      17                 :            :  *
      18                 :            :  * You should have received a copy of the GNU General Public License
      19                 :            :  * along with this program; if not, write to the Free Software
      20                 :            :  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301
      21                 :            :  * USA
      22                 :            :  */
      23                 :            : 
      24                 :            : #include <config.h>
      25                 :            : 
      26                 :            : #include "api_matchspy.h"
      27                 :            : 
      28                 :            : #include <xapian.h>
      29                 :            : 
      30                 :            : #include <cmath>
      31                 :            : #include <map>
      32                 :            : #include <vector>
      33                 :            : 
      34                 :            : #include "backendmanager.h"
      35                 :            : #include "str.h"
      36                 :            : #include "testsuite.h"
      37                 :            : #include "testutils.h"
      38                 :            : #include "apitest.h"
      39                 :            : 
      40                 :            : using namespace std;
      41                 :            : 
      42                 :            : // #######################################################################
      43                 :            : // # Tests start here
      44                 :            : 
      45         [ -  + ]:         20 : class SimpleMatchSpy : public Xapian::MatchSpy {
      46                 :            :   public:
      47                 :            :     // Vector which will be filled with all the document contents seen.
      48                 :            :     std::vector<std::string> seen;
      49                 :            : 
      50                 :         30 :     void operator()(const Xapian::Document &doc, double) {
      51                 :            :         // Note that this is not recommended usage of get_data() - you
      52                 :            :         // generally shouldn't call get_data() from inside a MatchSpy, because
      53                 :            :         // it is (likely to be) a slow operation resulting in considerable IO.
      54         [ +  - ]:         30 :         seen.push_back(doc.get_data());
      55                 :         30 :     }
      56                 :            : };
      57                 :            : 
      58                 :            : // Basic test of a matchspy.
      59                 :          5 : DEFINE_TESTCASE(matchspy1, backend && !remote) {
      60 [ +  - ][ +  - ]:          5 :     Xapian::Database db(get_database("apitest_simpledata"));
      61         [ +  - ]:         10 :     Xapian::Enquire enquire(db);
      62 [ +  - ][ +  - ]:          5 :     enquire.set_query(Xapian::Query("this"));
                 [ +  - ]
      63                 :            : 
      64                 :         10 :     SimpleMatchSpy myspy;
      65                 :            : 
      66         [ +  - ]:         10 :     Xapian::MSet nospymset = enquire.get_mset(0, 100);
      67         [ +  - ]:          5 :     enquire.add_matchspy(&myspy);
      68         [ +  - ]:         10 :     Xapian::MSet spymset = enquire.get_mset(0, 100);
      69                 :            : 
      70                 :            :     // Check that the match estimates aren't affected by the matchspy.
      71 [ +  - ][ -  + ]:          5 :     TEST_EQUAL(nospymset, spymset);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
      72                 :            : 
      73 [ +  - ][ +  - ]:         10 :     vector<bool> docid_checked(db.get_lastdocid());
      74                 :            : 
      75                 :            :     // Check that we get the expected number of matches, and that the stored
      76                 :            :     // document contents are right.
      77         [ +  - ]:         10 :     Xapian::MSetIterator i = spymset.begin();
      78 [ +  - ][ -  + ]:          5 :     TEST(i != spymset.end());
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
      79 [ +  - ][ -  + ]:          5 :     TEST_EQUAL(spymset.size(), 6);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
      80 [ +  - ][ -  + ]:          5 :     TEST_EQUAL(myspy.seen.size(), spymset.size());
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
      81                 :            : 
      82         [ +  - ]:          5 :     std::sort(myspy.seen.begin(), myspy.seen.end());
      83                 :            : 
      84                 :         10 :     std::vector<std::string> seen2;
      85 [ +  - ][ +  + ]:         35 :     for ( ; i != spymset.end(); ++i) {
      86         [ +  - ]:         30 :         const Xapian::Document doc(i.get_document());
      87 [ +  - ][ +  - ]:         30 :         seen2.push_back(doc.get_data());
      88                 :         30 :     }
      89         [ +  - ]:          5 :     std::sort(seen2.begin(), seen2.end());
      90                 :            : 
      91 [ -  + ][ #  # ]:          5 :     TEST_EQUAL(myspy.seen.size(), seen2.size());
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
      92                 :          5 :     std::vector<std::string>::const_iterator j = myspy.seen.begin();
      93                 :          5 :     std::vector<std::string>::const_iterator j2 = seen2.begin();
      94         [ +  + ]:         35 :     for (; j != myspy.seen.end(); ++j, ++j2) {
      95 [ -  + ][ #  # ]:         30 :         TEST_EQUAL(*j, *j2);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
      96                 :            :     }
      97                 :            : 
      98                 :          5 :     return true;
      99                 :            : }
     100                 :            : 
     101                 :         18 : static string values_to_repr(const Xapian::ValueCountMatchSpy & spy) {
     102         [ +  - ]:         18 :     string resultrepr("|");
     103         [ +  - ]:        396 :     for (Xapian::TermIterator i = spy.values_begin();
           [ +  -  +  + ]
     104                 :        264 :          i != spy.values_end();
     105                 :            :          ++i) {
     106 [ +  - ][ +  - ]:        114 :         resultrepr += *i;
     107         [ +  - ]:        114 :         resultrepr += ':';
     108 [ +  - ][ +  - ]:        114 :         resultrepr += str(i.get_termfreq());
                 [ +  - ]
     109         [ +  - ]:        114 :         resultrepr += '|';
     110                 :         18 :     }
     111                 :         18 :     return resultrepr;
     112                 :            : }
     113                 :            : 
     114                 :            : static void
     115                 :          5 : make_matchspy2_db(Xapian::WritableDatabase &db, const string &)
     116                 :            : {
     117         [ +  + ]:        130 :     for (int c = 1; c <= 25; ++c) {
     118         [ +  - ]:        125 :         Xapian::Document doc;
     119 [ +  - ][ +  - ]:        125 :         doc.set_data("Document " + str(c));
                 [ +  - ]
     120                 :        125 :         int factors = 0;
     121         [ +  + ]:       1750 :         for (int factor = 1; factor <= c; ++factor) {
     122 [ +  - ][ +  - ]:       1625 :             doc.add_term("all");
     123         [ +  + ]:       1625 :             if (c % factor == 0) {
     124 [ +  - ][ +  - ]:        435 :                 doc.add_term("XFACT" + str(factor));
                 [ +  - ]
     125                 :        435 :                 ++factors;
     126                 :            :             }
     127                 :            :         }
     128                 :            : 
     129                 :            :         // Number of factors.
     130 [ +  - ][ +  - ]:        125 :         doc.add_value(0, str(factors));
     131                 :            :         // Units digits.
     132 [ +  - ][ +  - ]:        125 :         doc.add_value(1, str(c % 10));
     133                 :            :         // Constant.
     134 [ +  - ][ +  - ]:        125 :         doc.add_value(2, "fish");
     135                 :            :         // Number of digits.
     136 [ +  - ][ +  - ]:        125 :         doc.add_value(3, str(str(c).size()));
                 [ +  - ]
     137                 :            : 
     138         [ +  - ]:        125 :         db.add_document(doc);
     139                 :        125 :     }
     140                 :          5 : }
     141                 :            : 
     142                 :          6 : DEFINE_TESTCASE(matchspy2, generated)
     143                 :            : {
     144 [ +  - ][ +  - ]:          6 :     Xapian::Database db = get_database("matchspy2", make_matchspy2_db);
                 [ +  - ]
     145                 :            : 
     146         [ +  - ]:         12 :     Xapian::ValueCountMatchSpy spy0(0);
     147         [ +  - ]:         12 :     Xapian::ValueCountMatchSpy spy1(1);
     148         [ +  - ]:         12 :     Xapian::ValueCountMatchSpy spy3(3);
     149                 :            : 
     150         [ +  - ]:         12 :     Xapian::Enquire enq(db);
     151                 :            : 
     152 [ +  - ][ +  - ]:          6 :     enq.set_query(Xapian::Query("all"));
                 [ +  - ]
     153 [ +  - ][ +  + ]:          6 :     if (startswith(get_dbtype(), "multi")) {
     154                 :            :         // Without this, we short-cut on the second shard because we don't get
     155                 :            :         // the documents in ascending weight order.
     156         [ +  - ]:          1 :         enq.set_weighting_scheme(Xapian::CoordWeight());
     157                 :            :     }
     158                 :            : 
     159         [ +  - ]:          6 :     enq.add_matchspy(&spy0);
     160         [ +  - ]:          6 :     enq.add_matchspy(&spy1);
     161         [ +  - ]:          6 :     enq.add_matchspy(&spy3);
     162         [ +  - ]:         12 :     Xapian::MSet mset = enq.get_mset(0, 10);
     163                 :            : 
     164 [ -  + ][ #  # ]:          6 :     TEST_EQUAL(spy0.get_total(), 25);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     165 [ -  + ][ #  # ]:          6 :     TEST_EQUAL(spy1.get_total(), 25);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     166 [ -  + ][ #  # ]:          6 :     TEST_EQUAL(spy3.get_total(), 25);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     167                 :            : 
     168                 :            :     static const char * const results[] = {
     169                 :            :         "|1:1|2:9|3:3|4:7|5:1|6:3|8:1|",
     170                 :            :         "|0:2|1:3|2:3|3:3|4:3|5:3|6:2|7:2|8:2|9:2|",
     171                 :            :         "|1:9|2:16|",
     172                 :            :     };
     173 [ +  - ][ +  - ]:          6 :     TEST_STRINGS_EQUAL(values_to_repr(spy0), results[0]);
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     174 [ +  - ][ +  - ]:          6 :     TEST_STRINGS_EQUAL(values_to_repr(spy1), results[1]);
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     175 [ +  - ][ +  - ]:          6 :     TEST_STRINGS_EQUAL(values_to_repr(spy3), results[2]);
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     176                 :            : 
     177                 :          6 :     return true;
     178                 :            : }
     179                 :            : 
     180                 :          6 : DEFINE_TESTCASE(matchspy4, generated)
     181                 :            : {
     182 [ +  - ][ +  - ]:          6 :     Xapian::Database db = get_database("matchspy2", make_matchspy2_db);
                 [ +  - ]
     183                 :            : 
     184                 :            :     // We're going to run the match twice - once sorted by relevance, and once
     185                 :            :     // sorted by a value.  This is a regression test - the matcher used to fail
     186                 :            :     // to show some documents to the spy when sorting by non-pure-relevance.
     187         [ +  - ]:         12 :     Xapian::ValueCountMatchSpy spya0(0);
     188         [ +  - ]:         12 :     Xapian::ValueCountMatchSpy spya1(1);
     189         [ +  - ]:         12 :     Xapian::ValueCountMatchSpy spya3(3);
     190         [ +  - ]:         12 :     Xapian::ValueCountMatchSpy spyb0(0);
     191         [ +  - ]:         12 :     Xapian::ValueCountMatchSpy spyb1(1);
     192         [ +  - ]:         12 :     Xapian::ValueCountMatchSpy spyb3(3);
     193                 :            : 
     194         [ +  - ]:         12 :     Xapian::Enquire enqa(db);
     195         [ +  - ]:         12 :     Xapian::Enquire enqb(db);
     196                 :            : 
     197 [ +  - ][ +  - ]:          6 :     enqa.set_query(Xapian::Query("all"));
                 [ +  - ]
     198 [ +  - ][ +  + ]:          6 :     if (startswith(get_dbtype(), "multi")) {
     199                 :            :         // Without this, we short-cut on the second shard because we don't get
     200                 :            :         // the documents in ascending weight order.
     201         [ +  - ]:          1 :         enqa.set_weighting_scheme(Xapian::CoordWeight());
     202                 :            :     }
     203 [ +  - ][ +  - ]:          6 :     enqb.set_query(Xapian::Query("all"));
                 [ +  - ]
     204                 :            : 
     205         [ +  - ]:          6 :     enqa.add_matchspy(&spya0);
     206         [ +  - ]:          6 :     enqa.add_matchspy(&spya1);
     207         [ +  - ]:          6 :     enqa.add_matchspy(&spya3);
     208         [ +  - ]:          6 :     enqb.add_matchspy(&spyb0);
     209         [ +  - ]:          6 :     enqb.add_matchspy(&spyb1);
     210         [ +  - ]:          6 :     enqb.add_matchspy(&spyb3);
     211                 :            : 
     212         [ +  - ]:         12 :     Xapian::MSet mseta = enqa.get_mset(0, 10);
     213         [ +  - ]:          6 :     enqb.set_sort_by_value(0, false);
     214         [ +  - ]:         12 :     Xapian::MSet msetb = enqb.get_mset(0, 10, 100);
     215                 :            : 
     216 [ -  + ][ #  # ]:          6 :     TEST_EQUAL(spya0.get_total(), 25);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     217 [ -  + ][ #  # ]:          6 :     TEST_EQUAL(spya1.get_total(), 25);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     218 [ -  + ][ #  # ]:          6 :     TEST_EQUAL(spya3.get_total(), 25);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     219 [ -  + ][ #  # ]:          6 :     TEST_EQUAL(spyb0.get_total(), 25);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     220 [ -  + ][ #  # ]:          6 :     TEST_EQUAL(spyb1.get_total(), 25);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     221 [ -  + ][ #  # ]:          6 :     TEST_EQUAL(spyb3.get_total(), 25);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     222                 :            : 
     223                 :            :     static const char * const results[] = {
     224                 :            :         "|2:9|4:7|3:3|6:3|1:1|5:1|8:1|",
     225                 :            :         "|1:3|2:3|3:3|4:3|5:3|0:2|6:2|7:2|8:2|9:2|",
     226                 :            :         "|",
     227                 :            :         "|2:16|1:9|",
     228                 :            :         "|2:9|4:7|3:3|6:3|1:1|5:1|8:1|",
     229                 :            :         "|1:3|2:3|3:3|4:3|5:3|0:2|6:2|7:2|8:2|9:2|",
     230                 :            :         "|",
     231                 :            :         "|2:16|1:9|",
     232                 :            :         NULL
     233                 :            :     };
     234                 :         12 :     std::vector<Xapian::ValueCountMatchSpy *> spies;
     235         [ +  - ]:          6 :     spies.push_back(&spya0);
     236         [ +  - ]:          6 :     spies.push_back(&spya1);
     237         [ +  - ]:          6 :     spies.push_back(NULL);
     238         [ +  - ]:          6 :     spies.push_back(&spya3);
     239         [ +  - ]:          6 :     spies.push_back(&spyb0);
     240         [ +  - ]:          6 :     spies.push_back(&spyb1);
     241         [ +  - ]:          6 :     spies.push_back(NULL);
     242         [ +  - ]:          6 :     spies.push_back(&spyb3);
     243         [ +  + ]:         54 :     for (Xapian::valueno v = 0; results[v]; ++v) {
     244 [ +  - ][ +  - ]:         48 :         tout << "value " << v << endl;
                 [ +  - ]
     245                 :         48 :         Xapian::ValueCountMatchSpy * spy = spies[v];
     246         [ +  - ]:         48 :         string allvals_str("|");
     247         [ +  + ]:         48 :         if (spy != NULL) {
     248                 :         36 :             size_t allvals_size = 0;
     249 [ +  - ][ +  - ]:        792 :             for (Xapian::TermIterator i = spy->top_values_begin(100);
                 [ +  + ]
     250                 :        528 :                  i != spy->top_values_end(100);
     251                 :            :                  ++i, ++allvals_size) {
     252 [ +  - ][ +  - ]:        228 :                 allvals_str += *i;
     253         [ +  - ]:        228 :                 allvals_str += ':';
     254 [ +  - ][ +  - ]:        228 :                 allvals_str += str(i.get_termfreq());
                 [ +  - ]
     255         [ +  - ]:        228 :                 allvals_str += '|';
     256                 :         36 :             }
     257 [ +  - ][ +  - ]:         36 :             tout << allvals_str << endl;
     258 [ +  - ][ -  + ]:         36 :             TEST_STRINGS_EQUAL(allvals_str, results[v]);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     259                 :            : 
     260         [ +  + ]:        264 :             for (size_t count = 0; count < allvals_size; ++count) {
     261 [ +  - ][ +  - ]:        228 :                 tout << "count " << count << endl;
                 [ +  - ]
     262 [ +  - ][ +  - ]:       3324 :                 for (Xapian::TermIterator i = spy->top_values_begin(100),
         [ +  - ][ +  + ]
     263         [ +  - ]:        456 :                      j = spy->top_values_begin(count);
     264   [ +  -  +  + ]:       4128 :                      i != spy->top_values_end(100) &&
                 [ -  + ]
     265         [ +  - ]:       2064 :                      j != spy->top_values_end(count);
     266                 :            :                      ++i, ++j) {
     267 [ +  - ][ +  - ]:        804 :                     tout << "j " << j << endl;
                 [ +  - ]
     268 [ +  - ][ +  - ]:        804 :                     TEST_EQUAL(*i, *j);
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     269 [ +  - ][ +  - ]:        804 :                     TEST_EQUAL(i.get_termfreq(), j.get_termfreq());
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     270                 :        228 :                 }
     271                 :            :             }
     272                 :            :         }
     273                 :         48 :     }
     274                 :            : 
     275                 :          6 :     return true;
     276                 :            : }
     277                 :            : 
     278                 :            : // Test builtin match spies
     279                 :          7 : DEFINE_TESTCASE(matchspy5, backend)
     280                 :            : {
     281 [ +  - ][ +  - ]:          7 :     Xapian::Database db(get_database("apitest_simpledata"));
     282         [ +  - ]:         14 :     Xapian::Enquire enquire(db);
     283 [ +  - ][ +  - ]:          7 :     enquire.set_query(Xapian::Query("this"));
                 [ +  - ]
     284                 :            : 
     285         [ +  - ]:         14 :     Xapian::ValueCountMatchSpy myspy1(1);
     286         [ +  - ]:         14 :     Xapian::ValueCountMatchSpy myspy2(1);
     287                 :            : 
     288         [ +  - ]:          7 :     enquire.add_matchspy(&myspy1);
     289         [ +  - ]:          7 :     enquire.add_matchspy(&myspy2);
     290         [ +  - ]:         14 :     Xapian::MSet mymset = enquire.get_mset(0, 100);
     291 [ +  - ][ -  + ]:          7 :     TEST_EQUAL(mymset.size(), 6);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     292                 :            : 
     293         [ +  - ]:         14 :     Xapian::TermIterator i = myspy1.values_begin();
     294 [ -  + ][ #  # ]:          7 :     TEST(i != myspy1.values_end());
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
     295 [ +  - ][ +  - ]:          7 :     TEST(*i == "h");
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
     296 [ +  - ][ -  + ]:          7 :     TEST_EQUAL(i.get_termfreq(), 5);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     297         [ +  - ]:          7 :     ++i;
     298 [ -  + ][ #  # ]:          7 :     TEST(i != myspy1.values_end());
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
     299 [ +  - ][ +  - ]:          7 :     TEST(*i == "n");
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
     300 [ +  - ][ -  + ]:          7 :     TEST_EQUAL(i.get_termfreq(), 1);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     301         [ +  - ]:          7 :     ++i;
     302 [ -  + ][ #  # ]:          7 :     TEST(i == myspy1.values_end());
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
     303                 :            : 
     304 [ +  - ][ +  - ]:          7 :     i = myspy2.values_begin();
     305 [ -  + ][ #  # ]:          7 :     TEST(i != myspy2.values_end());
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
     306 [ +  - ][ +  - ]:          7 :     TEST(*i == "h");
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
     307 [ +  - ][ -  + ]:          7 :     TEST_EQUAL(i.get_termfreq(), 5);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     308         [ +  - ]:          7 :     ++i;
     309 [ -  + ][ #  # ]:          7 :     TEST(i != myspy2.values_end());
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
     310 [ +  - ][ +  - ]:          7 :     TEST(*i == "n");
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
     311 [ +  - ][ -  + ]:          7 :     TEST_EQUAL(i.get_termfreq(), 1);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     312         [ +  - ]:          7 :     ++i;
     313 [ -  + ][ #  # ]:          7 :     TEST(i == myspy2.values_end());
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
     314                 :            : 
     315                 :          7 :     return true;
     316                 :            : }
     317                 :            : 
     318         [ -  + ]:          4 : class MySpy : public Xapian::MatchSpy {
     319                 :          0 :     void operator()(const Xapian::Document &, double) {
     320                 :          0 :     }
     321                 :            : };
     322                 :            : 
     323                 :            : // Test exceptions from matchspy base class, and get_description method.
     324                 :          1 : DEFINE_TESTCASE(matchspy6, !backend)
     325                 :            : {
     326                 :          1 :     MySpy spy;
     327                 :            : 
     328 [ +  - ][ -  + ]:          1 :     TEST_EXCEPTION(Xapian::UnimplementedError, spy.clone());
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ -  + ][ -  +  
          #  #  #  #  #  
          #  #  #  #  #  
             #  #  #  # ]
                 [ +  - ]
     329 [ +  - ][ -  +  :          1 :     TEST_EXCEPTION(Xapian::UnimplementedError, spy.name());
          #  #  #  #  #  
          #  #  #  #  #  
           #  # ][ -  + ]
           [ -  +  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
           #  # ][ +  - ]
     330 [ +  - ][ -  +  :          1 :     TEST_EXCEPTION(Xapian::UnimplementedError, spy.serialise());
          #  #  #  #  #  
          #  #  #  #  #  
           #  # ][ -  + ]
           [ -  +  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
           #  # ][ +  - ]
     331 [ +  - ][ +  - ]:          1 :     TEST_EXCEPTION(Xapian::UnimplementedError,
         [ +  - ][ -  +  
          #  #  #  #  #  
          #  #  #  #  #  
           #  # ][ -  + ]
           [ -  +  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
           #  # ][ +  - ]
     332                 :            :                    spy.unserialise(std::string(), Xapian::Registry()));
     333 [ +  - ][ -  +  :          1 :     TEST_EXCEPTION(Xapian::UnimplementedError, spy.serialise_results());
          #  #  #  #  #  
          #  #  #  #  #  
           #  # ][ -  + ]
           [ -  +  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
           #  # ][ +  - ]
     334 [ +  - ][ +  - ]:          1 :     TEST_EXCEPTION(Xapian::UnimplementedError,
           [ -  +  #  #  
          #  #  #  #  #  
             #  #  #  #  
              # ][ -  + ]
           [ -  +  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
           #  # ][ +  - ]
     335                 :            :                    spy.merge_results(std::string()));
     336 [ +  - ][ +  - ]:          1 :     TEST_EQUAL(spy.get_description(), "Xapian::MatchSpy()");
           [ -  +  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
             #  #  #  #  
                      # ]
     337                 :            : 
     338                 :          1 :     return true;
     339                 :            : }
     340                 :            : 
     341                 :            : /// Regression test for bug fixed in 1.4.12.
     342                 :          1 : DEFINE_TESTCASE(matchspy7, !backend)
     343                 :            : {
     344         [ +  - ]:          1 :     Xapian::ValueCountMatchSpy myspy(1);
     345         [ +  - ]:          2 :     string s = myspy.serialise_results();
     346                 :            :     // Append a string which overflows a 64-bit type when decoded with
     347                 :            :     // pack_uint().
     348         [ +  - ]:          1 :     s += "xxxxxxxxx";
     349                 :            :     // This merge_results() call used to enter an infinite loop.
     350 [ +  - ][ -  + ]:          1 :     TEST_EXCEPTION(Xapian::SerialisationError, myspy.merge_results(s));
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ -  + ][ -  +  
          #  #  #  #  #  
          #  #  #  #  #  
             #  #  #  # ]
                 [ +  - ]
     351                 :            : 
     352                 :          1 :     return true;
     353                 :            : }

Generated by: LCOV version 1.11