LCOV - code coverage report
Current view: top level - tests - api_valuestream.cc (source / functions) Hit Total Coverage
Test: Test Coverage for xapian-core fcfb185a9dd5 Lines: 387 387 100.0 %
Date: 2019-04-18 16:33:14 Functions: 12 12 100.0 %
Branches: 531 3023 17.6 %

           Branch data     Line data    Source code
       1                 :            : /** @file api_valuestream.cc
       2                 :            :  * @brief Tests of valuestream functionality.
       3                 :            :  */
       4                 :            : /* Copyright (C) 2008,2009,2010 Olly Betts
       5                 :            :  * Copyright (C) 2009 Lemur Consulting Ltd
       6                 :            :  *
       7                 :            :  * This program is free software; you can redistribute it and/or
       8                 :            :  * modify it under the terms of the GNU General Public License as
       9                 :            :  * published by the Free Software Foundation; either version 2 of the
      10                 :            :  * License, or (at your option) any later version.
      11                 :            :  *
      12                 :            :  * This program is distributed in the hope that it will be useful,
      13                 :            :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
      14                 :            :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      15                 :            :  * GNU General Public License for more details.
      16                 :            :  *
      17                 :            :  * You should have received a copy of the GNU General Public License
      18                 :            :  * along with this program; if not, write to the Free Software
      19                 :            :  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301
      20                 :            :  * USA
      21                 :            :  */
      22                 :            : 
      23                 :            : #include <config.h>
      24                 :            : 
      25                 :            : #include "api_valuestream.h"
      26                 :            : 
      27                 :            : #include <xapian.h>
      28                 :            : #include "testsuite.h"
      29                 :            : #include "testutils.h"
      30                 :            : 
      31                 :            : #include "apitest.h"
      32                 :            : 
      33                 :            : using namespace std;
      34                 :            : 
      35                 :            : /// Feature test simple valuestream iteration.
      36                 :          6 : DEFINE_TESTCASE(valuestream1, backend && !multi) {
      37                 :            :     // FIXME: enable for multi once support is in place.
      38 [ +  - ][ +  - ]:          6 :     Xapian::Database db = get_database("apitest_simpledata");
      39                 :            : 
      40         [ +  + ]:         96 :     for (Xapian::valueno slot = 0; slot < 15; ++slot) {
      41 [ +  - ][ +  - ]:         90 :         tout << "testing valuestream iteration for slot " << slot << endl;
                 [ +  - ]
      42         [ +  - ]:         90 :         Xapian::ValueIterator it = db.valuestream_begin(slot);
      43         [ +  + ]:        594 :         while (it != db.valuestream_end(slot)) {
      44 [ +  - ][ -  + ]:        504 :             TEST_EQUAL(it.get_valueno(), slot);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
      45         [ +  - ]:        504 :             string value = *it;
      46         [ +  - ]:        504 :             Xapian::docid did = it.get_docid();
      47                 :            : 
      48         [ +  - ]:       1008 :             Xapian::Document doc = db.get_document(did);
      49 [ +  - ][ -  + ]:        504 :             TEST_EQUAL(doc.get_value(slot), value);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
      50                 :            : 
      51         [ +  - ]:        504 :             ++it;
      52                 :        504 :         }
      53                 :         90 :     }
      54                 :            : 
      55                 :          6 :     return true;
      56                 :            : }
      57                 :            : 
      58                 :            : /// Test skip_to() on a valuestream iterator.
      59                 :          7 : DEFINE_TESTCASE(valuestream2, backend) {
      60 [ +  - ][ +  - ]:          7 :     Xapian::Database db = get_database("etext");
      61                 :            : 
      62         [ +  + ]:        112 :     for (Xapian::valueno slot = 0; slot < 15; ++slot) {
      63                 :        105 :         unsigned interval = 1;
      64         [ +  + ]:        889 :         while (interval < 1999) {
      65 [ +  - ][ +  - ]:        791 :             tout.str(string());
      66 [ +  - ][ +  - ]:        791 :             tout << "testing valuestream skip_to for slot " << slot
      67 [ +  - ][ +  - ]:        791 :                  << " with interval " << interval << endl;
                 [ +  - ]
      68                 :        791 :             Xapian::docid did = 1;
      69         [ +  - ]:        791 :             Xapian::ValueIterator it = db.valuestream_begin(slot);
      70         [ +  + ]:        791 :             if (it == db.valuestream_end(slot)) break;
      71 [ +  - ][ +  + ]:      93702 :             while (it.skip_to(did), it != db.valuestream_end(slot)) {
      72 [ +  - ][ -  + ]:      92918 :                 TEST_EQUAL(it.get_valueno(), slot);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
      73         [ +  - ]:      92918 :                 string value = *it;
      74                 :            : 
      75                 :            :                 // Check that the skipped documents had no values.
      76         [ +  - ]:      92918 :                 Xapian::docid actual_did = it.get_docid();
      77 [ -  + ][ #  # ]:      92918 :                 TEST_REL(actual_did,>=,did);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
      78         [ +  + ]:     104055 :                 while (did < actual_did) {
      79         [ +  - ]:      11137 :                     Xapian::Document doc = db.get_document(did);
      80 [ +  - ][ -  + ]:      11137 :                     TEST(doc.get_value(slot).empty());
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
      81                 :      11137 :                     ++did;
      82                 :      11137 :                 }
      83                 :            : 
      84         [ +  - ]:     185836 :                 Xapian::Document doc = db.get_document(actual_did);
      85 [ +  - ][ -  + ]:      92918 :                 TEST_EQUAL(doc.get_value(slot), value);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
      86                 :      92918 :                 did += interval;
      87                 :      92918 :             }
      88         [ +  + ]:        791 :             interval = interval * 3 - 1;
      89                 :        791 :         }
      90                 :            :     }
      91                 :            : 
      92                 :          7 :     return true;
      93                 :            : }
      94                 :            : 
      95                 :            : /// Test check() on a valuestream iterator.
      96                 :          7 : DEFINE_TESTCASE(valuestream3, backend) {
      97 [ +  - ][ +  - ]:          7 :     Xapian::Database db = get_database("etext");
      98                 :            : 
      99                 :            :     // Check combinations of check with other operations.
     100                 :            :     typedef enum {
     101                 :            :         CHECK, CHECK_AND_NEXT, CHECK2, SKIP_TO, CHECK_AND_LOOP
     102                 :            :     } test_op;
     103                 :          7 :     test_op operation = CHECK;
     104                 :            : 
     105         [ +  + ]:        112 :     for (Xapian::valueno slot = 0; slot < 15; ++slot) {
     106                 :        105 :         unsigned interval = 1;
     107         [ +  + ]:        889 :         while (interval < 1999) {
     108 [ +  - ][ +  - ]:        791 :             tout << "testing valuestream check for slot " << slot
     109 [ +  - ][ +  - ]:        791 :                  << " with interval " << interval << endl;
                 [ +  - ]
     110                 :        791 :             Xapian::docid did = 1;
     111         [ +  - ]:        791 :             Xapian::ValueIterator it = db.valuestream_begin(slot);
     112         [ +  + ]:        791 :             if (it == db.valuestream_end(slot)) break;
     113                 :            :             while (true) {
     114                 :      95403 :                 bool positioned = true;
     115   [ +  +  +  +  :      95403 :                 switch (operation) {
                      - ]
     116                 :            :                     case CHECK_AND_LOOP:
     117                 :      23847 :                         operation = CHECK;
     118                 :            :                         // FALLTHRU.
     119                 :            :                     case CHECK: case CHECK2:
     120         [ +  - ]:      47703 :                         positioned = it.check(did);
     121                 :      47703 :                         break;
     122                 :            :                     case CHECK_AND_NEXT: {
     123         [ +  - ]:      23851 :                         bool was_skip_to = it.check(did);
     124 [ +  + ][ +  - ]:      23851 :                         if (!was_skip_to) ++it;
     125                 :      23851 :                         break;
     126                 :            :                     }
     127                 :            :                     case SKIP_TO:
     128         [ +  - ]:      23849 :                         it.skip_to(did);
     129                 :      23849 :                         break;
     130                 :            :                 }
     131                 :      95403 :                 operation = test_op(operation + 1);
     132         [ +  + ]:      95403 :                 if (positioned) {
     133         [ +  + ]:      93453 :                     if (it == db.valuestream_end(slot)) break;
     134 [ +  - ][ -  + ]:      92669 :                     TEST_EQUAL(it.get_valueno(), slot);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     135         [ +  - ]:      92669 :                     string value = *it;
     136                 :            : 
     137                 :            :                     // Check that the skipped documents had no values.
     138         [ +  - ]:      92669 :                     Xapian::docid actual_did = it.get_docid();
     139         [ +  + ]:     101841 :                     while (did < actual_did) {
     140         [ +  - ]:       9172 :                         Xapian::Document doc = db.get_document(did);
     141 [ +  - ][ -  + ]:       9172 :                         TEST(doc.get_value(slot).empty());
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     142                 :       9172 :                         ++did;
     143                 :       9172 :                     }
     144                 :            : 
     145         [ +  - ]:     185338 :                     Xapian::Document doc = db.get_document(actual_did);
     146 [ +  - ][ -  + ]:     185338 :                     TEST_EQUAL(doc.get_value(slot), value);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     147                 :            :                 }
     148         [ +  + ]:      95410 :                 did += interval;
     149                 :            :             }
     150                 :        784 :             interval = interval * 3 - 1;
     151                 :        791 :         }
     152                 :            :     }
     153                 :            : 
     154                 :          7 :     return true;
     155                 :            : }
     156                 :            : 
     157                 :            : /** Check that valueweightsource handles last_docid of 0xffffffff.
     158                 :            :  *
     159                 :            :  *  The original implementation went into an infinite loop in this case.
     160                 :            :  */
     161                 :          5 : DEFINE_TESTCASE(valueweightsource5, writable && valuestats) {
     162                 :            :     // inmemory's memory use is currently O(last_docid)!
     163 [ +  - ][ +  + ]:          5 :     SKIP_TEST_FOR_BACKEND("inmemory");
     164                 :            :     // remote's value slot iteration is very slow for this case currently
     165                 :            :     // because it throws and catches DocNotFoundError across the link 2^32-3
     166                 :            :     // times.
     167 [ +  - ][ +  + ]:          4 :     SKIP_TEST_FOR_BACKEND("remote");
     168 [ +  - ][ +  - ]:          2 :     Xapian::WritableDatabase db = get_writable_database();
     169         [ +  - ]:          4 :     Xapian::Document doc;
     170 [ +  - ][ +  - ]:          2 :     doc.add_value(1, Xapian::sortable_serialise(3.14));
     171         [ +  - ]:          2 :     db.replace_document(1, doc);
     172         [ +  - ]:          2 :     db.replace_document(0xffffffff, doc);
     173         [ +  - ]:          2 :     db.commit();
     174                 :            : 
     175         [ +  - ]:          4 :     Xapian::ValueWeightPostingSource src(1);
     176         [ +  - ]:          2 :     src.init(db);
     177         [ +  - ]:          2 :     src.next(0.0);
     178 [ +  - ][ -  + ]:          2 :     TEST(!src.at_end());
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     179 [ +  - ][ -  + ]:          2 :     TEST_EQUAL(src.get_docid(), 1);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     180         [ +  - ]:          2 :     src.next(0.0);
     181 [ +  - ][ -  + ]:          2 :     TEST(!src.at_end());
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     182 [ +  - ][ -  + ]:          2 :     TEST_EQUAL(src.get_docid(), 0xffffffff);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     183         [ +  - ]:          2 :     src.next(0.0);
     184 [ +  - ][ -  + ]:          2 :     TEST(src.at_end());
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     185                 :            : 
     186                 :          2 :     return true;
     187                 :            : }
     188                 :            : 
     189                 :            : // Check that ValueMapPostingSource works correctly.
     190                 :            : // the test db has value 13 set to:
     191                 :            : //      1   Thi
     192                 :            : //      2   The
     193                 :            : //      3   You
     194                 :            : //      4   War
     195                 :            : //      5   Fri
     196                 :            : //      6   Ins
     197                 :            : //      7   Whi
     198                 :            : //      8   Com
     199                 :            : //      9   A p
     200                 :            : //      10  Tel
     201                 :            : //      11  Tel
     202                 :            : //      12  Enc
     203                 :            : //      13  Get
     204                 :            : //      14  Doe
     205                 :            : //      15  fir
     206                 :            : //      16  Pad
     207                 :            : //      17  Pad
     208                 :            : //
     209                 :          7 : DEFINE_TESTCASE(valuemapsource1, backend) {
     210 [ +  - ][ +  - ]:          7 :     Xapian::Database db(get_database("apitest_phrase"));
     211         [ +  - ]:         14 :     Xapian::Enquire enq(db);
     212                 :            : 
     213         [ +  - ]:         14 :     Xapian::ValueMapPostingSource src(13);
     214 [ +  - ][ +  - ]:          7 :     src.add_mapping("Thi", 2.0);
     215 [ +  - ][ +  - ]:          7 :     src.add_mapping("The", 1.0);
     216 [ +  - ][ +  - ]:          7 :     src.add_mapping("You", 3.0);
     217 [ +  - ][ +  - ]:          7 :     src.add_mapping("War", 4.0);
     218 [ +  - ][ +  - ]:          7 :     src.add_mapping("Fri", 5.0);
     219                 :            : 
     220                 :            :     // check mset size and order
     221 [ +  - ][ +  - ]:          7 :     enq.set_query(Xapian::Query(&src));
     222         [ +  - ]:         14 :     Xapian::MSet mset = enq.get_mset(0, 5);
     223                 :            : 
     224 [ +  - ][ -  + ]:          7 :     TEST(mset.size() == 5);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     225         [ +  - ]:          7 :     mset_expect_order(mset, 5, 4, 3, 1, 2);
     226                 :            : 
     227                 :            :     // and with default weight
     228         [ +  - ]:          7 :     src.clear_mappings();
     229         [ +  - ]:          7 :     src.set_default_weight(3.5);
     230 [ +  - ][ +  - ]:          7 :     src.add_mapping("Thi", 2.0);
     231 [ +  - ][ +  - ]:          7 :     src.add_mapping("The", 1.0);
     232 [ +  - ][ +  - ]:          7 :     src.add_mapping("You", 3.0);
     233 [ +  - ][ +  - ]:          7 :     src.add_mapping("War", 4.0);
     234 [ +  - ][ +  - ]:          7 :     src.add_mapping("Fri", 5.0);
     235                 :            : 
     236 [ +  - ][ +  - ]:          7 :     enq.set_query(Xapian::Query(&src));
     237 [ +  - ][ +  - ]:          7 :     mset = enq.get_mset(0, 5);
     238                 :            : 
     239 [ +  - ][ -  + ]:          7 :     TEST(mset.size() == 5);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     240         [ +  - ]:          7 :     mset_expect_order(mset, 5, 4, 6, 7, 8);
     241                 :            : 
     242                 :          7 :     return true;
     243                 :            : }
     244                 :            : 
     245                 :            : // Regression test for valuepostingsource subclasses: used to segfault if skip_to()
     246                 :            : // called on an empty list.
     247                 :          6 : DEFINE_TESTCASE(valuemapsource2, backend && !multi) {
     248 [ +  - ][ +  - ]:          6 :     Xapian::Database db(get_database("apitest_phrase"));
     249                 :            : 
     250                 :            :     {
     251         [ +  - ]:          6 :         Xapian::ValueMapPostingSource src(100);
     252         [ +  - ]:          6 :         src.init(db);
     253 [ +  - ][ -  + ]:          6 :         TEST(src.at_end() == false);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     254         [ +  - ]:          6 :         src.next(0.0);
     255 [ +  - ][ -  + ]:          6 :         TEST(src.at_end() == true);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     256                 :            :     }
     257                 :            : 
     258                 :            :     {
     259         [ +  - ]:          6 :         Xapian::ValueMapPostingSource src(100);
     260         [ +  - ]:          6 :         src.init(db);
     261 [ +  - ][ -  + ]:          6 :         TEST(src.at_end() == false);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     262         [ +  - ]:          6 :         src.skip_to(1, 0.0);
     263 [ +  - ][ -  + ]:          6 :         TEST(src.at_end() == true);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     264                 :            :     }
     265                 :            : 
     266                 :            :     {
     267         [ +  - ]:          6 :         Xapian::ValueMapPostingSource src(100);
     268         [ +  - ]:          6 :         src.init(db);
     269 [ +  - ][ -  + ]:          6 :         TEST(src.at_end() == false);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     270         [ +  - ]:          6 :         src.check(1, 0.0);
     271 [ +  - ][ -  + ]:          6 :         TEST(src.at_end() == true);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     272                 :            :     }
     273                 :            : 
     274                 :          6 :     return true;
     275                 :            : }
     276                 :            : 
     277                 :            : // Regression test for fixedweightpostingsource: used to segfault if skip_to()
     278                 :            : // called on an empty list.
     279                 :          1 : DEFINE_TESTCASE(fixedweightsource2, !backend) {
     280         [ +  - ]:          1 :     Xapian::Database db;
     281                 :            : 
     282                 :            :     {
     283         [ +  - ]:          1 :         Xapian::FixedWeightPostingSource src(5.0);
     284         [ +  - ]:          1 :         src.init(db);
     285 [ +  - ][ -  + ]:          1 :         TEST(src.at_end() == false);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     286         [ +  - ]:          1 :         src.next(0.0);
     287 [ +  - ][ -  + ]:          1 :         TEST(src.at_end() == true);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     288                 :            :     }
     289                 :            : 
     290                 :            :     {
     291         [ +  - ]:          1 :         Xapian::FixedWeightPostingSource src(5.0);
     292         [ +  - ]:          1 :         src.init(db);
     293 [ +  - ][ -  + ]:          1 :         TEST(src.at_end() == false);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     294         [ +  - ]:          1 :         src.skip_to(1, 0.0);
     295 [ +  - ][ -  + ]:          1 :         TEST(src.at_end() == true);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     296                 :            :     }
     297                 :            : 
     298                 :            :     // No need to test behaviour of check() - check is only allowed to be
     299                 :            :     // called with document IDs which exist, so can never be called for a
     300                 :            :     // FixedWeightPostingSource with an empty database.
     301                 :            : 
     302                 :          1 :     return true;
     303                 :            : }
     304                 :            : 
     305                 :            : // Test DecreasingValueWeightPostingSource.
     306                 :          5 : DEFINE_TESTCASE(decvalwtsource1, writable) {
     307 [ +  - ][ +  - ]:          5 :     Xapian::WritableDatabase db = get_writable_database();
     308                 :            : 
     309         [ +  - ]:         10 :     Xapian::Document doc;
     310 [ +  - ][ +  - ]:          5 :     doc.add_value(1, Xapian::sortable_serialise(3));
     311         [ +  - ]:          5 :     db.add_document(doc);
     312 [ +  - ][ +  - ]:          5 :     doc.add_value(1, Xapian::sortable_serialise(2));
     313         [ +  - ]:          5 :     db.add_document(doc);
     314 [ +  - ][ +  - ]:          5 :     doc.add_value(1, Xapian::sortable_serialise(1));
     315         [ +  - ]:          5 :     db.add_document(doc);
     316         [ +  - ]:          5 :     db.commit();
     317                 :            : 
     318                 :            :     // Check basic function
     319                 :            :     {
     320         [ +  - ]:          5 :         Xapian::DecreasingValueWeightPostingSource src(1);
     321         [ +  - ]:          5 :         src.init(db);
     322                 :            : 
     323         [ +  - ]:          5 :         src.next(0.0);
     324 [ +  - ][ -  + ]:          5 :         TEST(!src.at_end());
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     325 [ +  - ][ -  + ]:          5 :         TEST_EQUAL(src.get_docid(), 1);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     326                 :            : 
     327         [ +  - ]:          5 :         src.next(0.0);
     328 [ +  - ][ -  + ]:          5 :         TEST(!src.at_end());
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     329 [ +  - ][ -  + ]:          5 :         TEST_EQUAL(src.get_docid(), 2);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     330                 :            : 
     331         [ +  - ]:          5 :         src.next(0.0);
     332 [ +  - ][ -  + ]:          5 :         TEST(!src.at_end());
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     333 [ +  - ][ -  + ]:          5 :         TEST_EQUAL(src.get_docid(), 3);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     334                 :            : 
     335         [ +  - ]:          5 :         src.next(0.0);
     336 [ +  - ][ -  + ]:          5 :         TEST(src.at_end());
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     337                 :            :     }
     338                 :            : 
     339                 :            :     // Check skipping to end of list due to weight
     340                 :            :     {
     341         [ +  - ]:          5 :         Xapian::DecreasingValueWeightPostingSource src(1);
     342         [ +  - ]:          5 :         src.init(db);
     343                 :            : 
     344         [ +  - ]:          5 :         src.next(1.5);
     345 [ +  - ][ -  + ]:          5 :         TEST(!src.at_end());
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     346 [ +  - ][ -  + ]:          5 :         TEST_EQUAL(src.get_docid(), 1);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     347                 :            : 
     348         [ +  - ]:          5 :         src.next(1.5);
     349 [ +  - ][ -  + ]:          5 :         TEST(!src.at_end());
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     350 [ +  - ][ -  + ]:          5 :         TEST_EQUAL(src.get_docid(), 2);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     351                 :            : 
     352         [ +  - ]:          5 :         src.next(1.5);
     353 [ +  - ][ -  + ]:          5 :         TEST(src.at_end());
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     354                 :            :     }
     355                 :            : 
     356                 :            :     // Check behaviour with a restricted range
     357 [ +  - ][ +  - ]:          5 :     doc.add_value(1, Xapian::sortable_serialise(2));
     358         [ +  - ]:          5 :     db.add_document(doc);
     359                 :            : 
     360                 :            :     {
     361         [ +  - ]:          5 :         Xapian::DecreasingValueWeightPostingSource src(1, 1, 3);
     362         [ +  - ]:          5 :         src.init(db);
     363                 :            : 
     364         [ +  - ]:          5 :         src.next(1.5);
     365 [ +  - ][ -  + ]:          5 :         TEST(!src.at_end());
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     366 [ +  - ][ -  + ]:          5 :         TEST_EQUAL(src.get_docid(), 1);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     367                 :            : 
     368         [ +  - ]:          5 :         src.next(1.5);
     369 [ +  - ][ -  + ]:          5 :         TEST(!src.at_end());
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     370 [ +  - ][ -  + ]:          5 :         TEST_EQUAL(src.get_docid(), 2);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     371                 :            : 
     372         [ +  - ]:          5 :         src.next(1.5);
     373 [ +  - ][ -  + ]:          5 :         TEST(!src.at_end());
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     374 [ +  - ][ -  + ]:          5 :         TEST_EQUAL(src.get_docid(), 4);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     375                 :            : 
     376         [ +  - ]:          5 :         src.next(1.5);
     377 [ +  - ][ -  + ]:          5 :         TEST(src.at_end());
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     378                 :            :     }
     379                 :            : 
     380                 :            :     {
     381         [ +  - ]:          5 :         Xapian::DecreasingValueWeightPostingSource src(1, 1, 3);
     382         [ +  - ]:          5 :         src.init(db);
     383                 :            : 
     384         [ +  - ]:          5 :         src.next(1.5);
     385 [ +  - ][ -  + ]:          5 :         TEST(!src.at_end());
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     386 [ +  - ][ -  + ]:          5 :         TEST_EQUAL(src.get_docid(), 1);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     387                 :            : 
     388         [ +  - ]:          5 :         src.skip_to(3, 1.5);
     389 [ +  - ][ -  + ]:          5 :         TEST(!src.at_end());
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     390 [ +  - ][ -  + ]:          5 :         TEST_EQUAL(src.get_docid(), 4);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     391                 :            : 
     392         [ +  - ]:          5 :         src.next(1.5);
     393 [ +  - ][ -  + ]:          5 :         TEST(src.at_end());
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     394                 :            :     }
     395                 :            : 
     396                 :            :     {
     397         [ +  - ]:          5 :         Xapian::DecreasingValueWeightPostingSource src(1, 1, 3);
     398         [ +  - ]:          5 :         src.init(db);
     399                 :            : 
     400         [ +  - ]:          5 :         src.next(1.5);
     401 [ +  - ][ -  + ]:          5 :         TEST(!src.at_end());
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     402 [ +  - ][ -  + ]:          5 :         TEST_EQUAL(src.get_docid(), 1);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     403                 :            : 
     404 [ +  - ][ -  + ]:          5 :         TEST(src.check(3, 1.5));
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     405 [ +  - ][ -  + ]:          5 :         TEST(!src.at_end());
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     406 [ +  - ][ -  + ]:          5 :         TEST_EQUAL(src.get_docid(), 4);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     407                 :            : 
     408         [ +  - ]:          5 :         src.next(1.5);
     409 [ +  - ][ -  + ]:          5 :         TEST(src.at_end());
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     410                 :            :     }
     411                 :            : 
     412                 :          5 :     return true;
     413                 :            : }
     414                 :            : 
     415                 :            : // Test DecreasingValueWeightPostingSource with out-of-order sections at
     416                 :            : // start, and with repeated weights.
     417                 :          5 : DEFINE_TESTCASE(decvalwtsource2, writable) {
     418 [ +  - ][ +  - ]:          5 :     Xapian::WritableDatabase db = get_writable_database();
     419                 :            : 
     420         [ +  - ]:         10 :     Xapian::Document doc;
     421 [ +  - ][ +  - ]:          5 :     doc.add_value(1, Xapian::sortable_serialise(1));
     422         [ +  - ]:          5 :     db.add_document(doc);
     423 [ +  - ][ +  - ]:          5 :     doc.add_value(1, Xapian::sortable_serialise(3));
     424         [ +  - ]:          5 :     db.add_document(doc);
     425 [ +  - ][ +  - ]:          5 :     doc.add_value(1, Xapian::sortable_serialise(3));
     426         [ +  - ]:          5 :     db.add_document(doc);
     427 [ +  - ][ +  - ]:          5 :     doc.add_value(1, Xapian::sortable_serialise(1));
     428         [ +  - ]:          5 :     db.add_document(doc);
     429         [ +  - ]:          5 :     db.commit();
     430                 :            : 
     431                 :            :     // Check basic function
     432                 :            :     {
     433         [ +  - ]:          5 :         Xapian::DecreasingValueWeightPostingSource src(1);
     434         [ +  - ]:          5 :         src.init(db);
     435                 :            : 
     436         [ +  - ]:          5 :         src.next(0.0);
     437 [ +  - ][ -  + ]:          5 :         TEST(!src.at_end());
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     438 [ +  - ][ -  + ]:          5 :         TEST_EQUAL(src.get_docid(), 1);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     439                 :            : 
     440         [ +  - ]:          5 :         src.next(0.0);
     441 [ +  - ][ -  + ]:          5 :         TEST(!src.at_end());
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     442 [ +  - ][ -  + ]:          5 :         TEST_EQUAL(src.get_docid(), 2);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     443                 :            : 
     444         [ +  - ]:          5 :         src.next(0.0);
     445 [ +  - ][ -  + ]:          5 :         TEST(!src.at_end());
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     446 [ +  - ][ -  + ]:          5 :         TEST_EQUAL(src.get_docid(), 3);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     447                 :            : 
     448         [ +  - ]:          5 :         src.next(0.0);
     449 [ +  - ][ -  + ]:          5 :         TEST(!src.at_end());
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     450 [ +  - ][ -  + ]:          5 :         TEST_EQUAL(src.get_docid(), 4);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     451                 :            : 
     452         [ +  - ]:          5 :         src.next(0.0);
     453 [ +  - ][ -  + ]:          5 :         TEST(src.at_end());
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     454                 :            :     }
     455                 :            : 
     456                 :            :     // Check skipping to end of list due to weight
     457                 :            :     {
     458         [ +  - ]:          5 :         Xapian::DecreasingValueWeightPostingSource src(1, 2);
     459         [ +  - ]:          5 :         src.init(db);
     460                 :            : 
     461         [ +  - ]:          5 :         src.next(1.5);
     462 [ +  - ][ -  + ]:          5 :         TEST(!src.at_end());
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     463 [ +  - ][ -  + ]:          5 :         TEST_EQUAL(src.get_docid(), 1);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     464                 :            : 
     465         [ +  - ]:          5 :         src.next(1.5);
     466 [ +  - ][ -  + ]:          5 :         TEST(!src.at_end());
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     467 [ +  - ][ -  + ]:          5 :         TEST_EQUAL(src.get_docid(), 2);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     468                 :            : 
     469         [ +  - ]:          5 :         src.next(1.5);
     470 [ +  - ][ -  + ]:          5 :         TEST(!src.at_end());
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     471 [ +  - ][ -  + ]:          5 :         TEST_EQUAL(src.get_docid(), 3);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     472                 :            : 
     473         [ +  - ]:          5 :         src.next(1.5);
     474 [ +  - ][ -  + ]:          5 :         TEST(src.at_end());
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     475                 :            :     }
     476                 :            : 
     477                 :            :     // Check behaviour with a restricted range
     478 [ +  - ][ +  - ]:          5 :     doc.add_value(1, Xapian::sortable_serialise(2));
     479         [ +  - ]:          5 :     db.add_document(doc);
     480                 :            : 
     481                 :            :     {
     482         [ +  - ]:          5 :         Xapian::DecreasingValueWeightPostingSource src(1, 2, 4);
     483         [ +  - ]:          5 :         src.init(db);
     484                 :            : 
     485         [ +  - ]:          5 :         src.next(1.5);
     486 [ +  - ][ -  + ]:          5 :         TEST(!src.at_end());
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     487 [ +  - ][ -  + ]:          5 :         TEST_EQUAL(src.get_docid(), 1);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     488                 :            : 
     489         [ +  - ]:          5 :         src.next(1.5);
     490 [ +  - ][ -  + ]:          5 :         TEST(!src.at_end());
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     491 [ +  - ][ -  + ]:          5 :         TEST_EQUAL(src.get_docid(), 2);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     492                 :            : 
     493         [ +  - ]:          5 :         src.next(1.5);
     494 [ +  - ][ -  + ]:          5 :         TEST(!src.at_end());
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     495 [ +  - ][ -  + ]:          5 :         TEST_EQUAL(src.get_docid(), 3);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     496                 :            : 
     497         [ +  - ]:          5 :         src.next(1.5);
     498 [ +  - ][ -  + ]:          5 :         TEST(!src.at_end());
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     499 [ +  - ][ -  + ]:          5 :         TEST_EQUAL(src.get_docid(), 5);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     500                 :            : 
     501         [ +  - ]:          5 :         src.next(1.5);
     502 [ +  - ][ -  + ]:          5 :         TEST(src.at_end());
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     503                 :            :     }
     504                 :            : 
     505                 :            :     {
     506         [ +  - ]:          5 :         Xapian::DecreasingValueWeightPostingSource src(1, 2, 4);
     507         [ +  - ]:          5 :         src.init(db);
     508                 :            : 
     509 [ +  - ][ -  + ]:          5 :         TEST(src.check(1, 1.5));
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     510 [ +  - ][ -  + ]:          5 :         TEST(!src.at_end());
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     511 [ +  - ][ -  + ]:          5 :         TEST_EQUAL(src.get_docid(), 1);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     512                 :            : 
     513         [ +  - ]:          5 :         src.next(1.5);
     514 [ +  - ][ -  + ]:          5 :         TEST(!src.at_end());
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     515 [ +  - ][ -  + ]:          5 :         TEST_EQUAL(src.get_docid(), 2);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     516                 :            : 
     517         [ +  - ]:          5 :         src.skip_to(4, 1.5);
     518 [ +  - ][ -  + ]:          5 :         TEST(!src.at_end());
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     519 [ +  - ][ -  + ]:          5 :         TEST_EQUAL(src.get_docid(), 5);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     520                 :            : 
     521         [ +  - ]:          5 :         src.next(1.5);
     522 [ +  - ][ -  + ]:          5 :         TEST(src.at_end());
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     523                 :            :     }
     524                 :            : 
     525                 :            :     {
     526         [ +  - ]:          5 :         Xapian::DecreasingValueWeightPostingSource src(1, 2, 4);
     527         [ +  - ]:          5 :         src.init(db);
     528                 :            : 
     529 [ +  - ][ -  + ]:          5 :         TEST(src.check(1, 1.5));
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     530 [ +  - ][ -  + ]:          5 :         TEST(!src.at_end());
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     531 [ +  - ][ -  + ]:          5 :         TEST_EQUAL(src.get_docid(), 1);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     532                 :            : 
     533         [ +  - ]:          5 :         src.next(1.5);
     534 [ +  - ][ -  + ]:          5 :         TEST(!src.at_end());
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     535 [ +  - ][ -  + ]:          5 :         TEST_EQUAL(src.get_docid(), 2);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     536                 :            : 
     537 [ +  - ][ -  + ]:          5 :         TEST(src.check(4, 1.5));
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     538 [ +  - ][ -  + ]:          5 :         TEST(!src.at_end());
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     539 [ +  - ][ -  + ]:          5 :         TEST_EQUAL(src.get_docid(), 5);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     540                 :            : 
     541         [ +  - ]:          5 :         src.next(1.5);
     542 [ +  - ][ -  + ]:          5 :         TEST(src.at_end());
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     543                 :            :     }
     544                 :            : 
     545                 :          5 :     return true;
     546                 :            : }
     547                 :            : 
     548                 :            : // Test DecreasingValueWeightPostingSource with an actual query.
     549                 :          5 : DEFINE_TESTCASE(decvalwtsource3, writable) {
     550 [ +  - ][ +  - ]:          5 :     Xapian::WritableDatabase db = get_writable_database();
     551                 :            : 
     552         [ +  - ]:         10 :     Xapian::Document doc;
     553 [ +  - ][ +  - ]:          5 :     doc.add_term("foo");
     554 [ +  - ][ +  - ]:          5 :     doc.add_value(1, Xapian::sortable_serialise(1));
     555         [ +  - ]:          5 :     db.add_document(doc);
     556 [ +  - ][ +  - ]:          5 :     doc.add_value(1, Xapian::sortable_serialise(3));
     557         [ +  - ]:          5 :     db.add_document(doc);
     558 [ +  - ][ +  - ]:          5 :     doc.add_term("bar");
     559 [ +  - ][ +  - ]:          5 :     doc.add_value(1, Xapian::sortable_serialise(3));
     560         [ +  - ]:          5 :     db.add_document(doc);
     561 [ +  - ][ +  - ]:          5 :     doc.add_value(1, Xapian::sortable_serialise(1));
     562         [ +  - ]:          5 :     db.add_document(doc);
     563         [ +  - ]:          5 :     db.commit();
     564                 :            : 
     565         [ +  - ]:         10 :     Xapian::DecreasingValueWeightPostingSource ps(1, 2, 5);
     566         [ +  - ]:         10 :     Xapian::Query q(&ps);
     567         [ +  - ]:         10 :     Xapian::Enquire enq(db);
     568         [ +  - ]:          5 :     enq.set_query(q);
     569                 :            : 
     570         [ +  - ]:         10 :     Xapian::MSet mset1(enq.get_mset(0, 1));
     571         [ +  - ]:         10 :     Xapian::MSet mset2(enq.get_mset(0, 2));
     572         [ +  - ]:         10 :     Xapian::MSet mset3(enq.get_mset(0, 3));
     573         [ +  - ]:         10 :     Xapian::MSet mset4(enq.get_mset(0, 4));
     574                 :            : 
     575 [ +  - ][ -  + ]:          5 :     TEST_EQUAL(mset1.size(), 1);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     576 [ +  - ][ -  + ]:          5 :     TEST_EQUAL(mset2.size(), 2);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     577 [ +  - ][ -  + ]:          5 :     TEST_EQUAL(mset3.size(), 3);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     578 [ +  - ][ -  + ]:          5 :     TEST_EQUAL(mset4.size(), 4);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     579                 :            : 
     580 [ +  - ][ -  + ]:          5 :     TEST(mset_range_is_same(mset1, 0, mset2, 0, 1));
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     581 [ +  - ][ -  + ]:          5 :     TEST(mset_range_is_same(mset2, 0, mset3, 0, 2));
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     582 [ +  - ][ -  + ]:          5 :     TEST(mset_range_is_same(mset3, 0, mset4, 0, 3));
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     583                 :            : 
     584                 :          5 :     return true;
     585                 :            : }
     586                 :            : 
     587                 :            : // Test DecreasingValueWeightPostingSource with an actual query on a fixed
     588                 :            : // dataset (so we can cover the remote backend too).
     589                 :          6 : DEFINE_TESTCASE(decvalwtsource4, backend && !multi) {
     590 [ +  - ][ +  - ]:          6 :     Xapian::Database db = get_database("apitest_declen");
     591                 :            : 
     592         [ +  - ]:         12 :     Xapian::DecreasingValueWeightPostingSource ps(11, 2, 5);
     593         [ +  - ]:         12 :     Xapian::Query q(&ps);
     594         [ +  - ]:         12 :     Xapian::Enquire enq(db);
     595         [ +  - ]:          6 :     enq.set_query(q);
     596                 :            : 
     597         [ +  - ]:         12 :     Xapian::MSet mset1(enq.get_mset(0, 1));
     598         [ +  - ]:         12 :     Xapian::MSet mset2(enq.get_mset(0, 2));
     599         [ +  - ]:         12 :     Xapian::MSet mset3(enq.get_mset(0, 3));
     600         [ +  - ]:         12 :     Xapian::MSet mset4(enq.get_mset(0, 4));
     601                 :            : 
     602 [ +  - ][ -  + ]:          6 :     TEST_EQUAL(mset1.size(), 1);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     603 [ +  - ][ -  + ]:          6 :     TEST_EQUAL(mset2.size(), 2);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     604 [ +  - ][ -  + ]:          6 :     TEST_EQUAL(mset3.size(), 3);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     605 [ +  - ][ -  + ]:          6 :     TEST_EQUAL(mset4.size(), 4);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     606                 :            : 
     607 [ +  - ][ -  + ]:          6 :     TEST(mset_range_is_same(mset1, 0, mset2, 0, 1));
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     608 [ +  - ][ -  + ]:          6 :     TEST(mset_range_is_same(mset2, 0, mset3, 0, 2));
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     609 [ +  - ][ -  + ]:          6 :     TEST(mset_range_is_same(mset3, 0, mset4, 0, 3));
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     610                 :            : 
     611                 :          6 :     return true;
     612                 :            : }
     613                 :            : 
     614                 :            : // Regression test - used to get segfaults if
     615                 :            : // DecreasingValueWeightPostingSource was pointed at an empty slot.
     616                 :          5 : DEFINE_TESTCASE(decvalwtsource5, writable) {
     617 [ +  - ][ +  - ]:          5 :     Xapian::WritableDatabase db = get_writable_database();
     618                 :            : 
     619         [ +  - ]:         10 :     Xapian::Document doc;
     620 [ +  - ][ +  - ]:          5 :     doc.add_value(1, Xapian::sortable_serialise(1));
     621         [ +  - ]:          5 :     db.add_document(doc);
     622 [ +  - ][ +  - ]:          5 :     doc.add_value(2, Xapian::sortable_serialise(1));
     623         [ +  - ]:          5 :     db.add_document(doc);
     624         [ +  - ]:          5 :     db.commit();
     625                 :            : 
     626                 :            :     {
     627         [ +  - ]:          5 :         Xapian::DecreasingValueWeightPostingSource ps(1);
     628         [ +  - ]:         10 :         Xapian::Query q(&ps);
     629         [ +  - ]:         10 :         Xapian::Enquire enq(db);
     630         [ +  - ]:          5 :         enq.set_query(q);
     631         [ +  - ]:         10 :         Xapian::MSet mset1(enq.get_mset(0, 3));
     632 [ +  - ][ -  + ]:         10 :         TEST_EQUAL(mset1.size(), 2);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     633                 :            :     }
     634                 :            :     {
     635         [ +  - ]:          5 :         Xapian::DecreasingValueWeightPostingSource ps(2);
     636         [ +  - ]:         10 :         Xapian::Query q(&ps);
     637         [ +  - ]:         10 :         Xapian::Enquire enq(db);
     638         [ +  - ]:          5 :         enq.set_query(q);
     639         [ +  - ]:         10 :         Xapian::MSet mset1(enq.get_mset(0, 3));
     640 [ +  - ][ -  + ]:         10 :         TEST_EQUAL(mset1.size(), 1);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     641                 :            :     }
     642                 :            :     {
     643         [ +  - ]:          5 :         Xapian::DecreasingValueWeightPostingSource ps(3);
     644         [ +  - ]:         10 :         Xapian::Query q(&ps);
     645         [ +  - ]:         10 :         Xapian::Enquire enq(db);
     646         [ +  - ]:          5 :         enq.set_query(q);
     647         [ +  - ]:         10 :         Xapian::MSet mset1(enq.get_mset(0, 3));
     648 [ +  - ][ -  + ]:         10 :         TEST_EQUAL(mset1.size(), 0);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     649                 :            :     }
     650                 :            : 
     651                 :          5 :     return true;
     652                 :            : }

Generated by: LCOV version 1.11