LCOV - code coverage report
Current view: top level - tests - api_wrdb.cc (source / functions) Hit Total Coverage
Test: Test Coverage for xapian-core 954b5873a738 Lines: 1287 1289 99.8 %
Date: 2019-06-30 05:20:33 Functions: 36 36 100.0 %
Branches: 2250 13886 16.2 %

           Branch data     Line data    Source code
       1                 :            : /** @file api_wrdb.cc
       2                 :            :  * @brief tests which need a writable backend
       3                 :            :  */
       4                 :            : /* Copyright 1999,2000,2001 BrightStation PLC
       5                 :            :  * Copyright 2001 Hein Ragas
       6                 :            :  * Copyright 2002 Ananova Ltd
       7                 :            :  * Copyright 2002,2003,2004,2005,2006,2007,2008,2009,2010,2011,2012,2014,2015,2018 Olly Betts
       8                 :            :  * Copyright 2006 Richard Boulton
       9                 :            :  * Copyright 2007 Lemur Consulting Ltd
      10                 :            :  *
      11                 :            :  * This program is free software; you can redistribute it and/or
      12                 :            :  * modify it under the terms of the GNU General Public License as
      13                 :            :  * published by the Free Software Foundation; either version 2 of the
      14                 :            :  * License, or (at your option) any later version.
      15                 :            :  *
      16                 :            :  * This program is distributed in the hope that it will be useful,
      17                 :            :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
      18                 :            :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      19                 :            :  * GNU General Public License for more details.
      20                 :            :  *
      21                 :            :  * You should have received a copy of the GNU General Public License
      22                 :            :  * along with this program; if not, write to the Free Software
      23                 :            :  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301
      24                 :            :  * USA
      25                 :            :  */
      26                 :            : 
      27                 :            : #include <config.h>
      28                 :            : 
      29                 :            : #include "api_wrdb.h"
      30                 :            : 
      31                 :            : #include <xapian.h>
      32                 :            : 
      33                 :            : #include "filetests.h"
      34                 :            : #include "omassert.h"
      35                 :            : #include "str.h"
      36                 :            : #include "stringutils.h"
      37                 :            : #include "testsuite.h"
      38                 :            : #include "testutils.h"
      39                 :            : #include "unixcmds.h"
      40                 :            : 
      41                 :            : #include "apitest.h"
      42                 :            : 
      43                 :            : #include "safeunistd.h"
      44                 :            : #include <cmath>
      45                 :            : #include <cstdlib>
      46                 :            : #include <map>
      47                 :            : #include <string>
      48                 :            : 
      49                 :            : using namespace std;
      50                 :            : 
      51                 :            : // #######################################################################
      52                 :            : // # Tests start here
      53                 :            : 
      54                 :            : // test that indexing a term more than once at the same position increases
      55                 :            : // the wdf
      56                 :          5 : DEFINE_TESTCASE(adddoc1, writable) {
      57 [ +  - ][ +  - ]:          5 :     Xapian::WritableDatabase db = get_writable_database();
      58                 :            : 
      59 [ +  - ][ +  - ]:         10 :     Xapian::Document doc1, doc2, doc3;
                 [ +  - ]
      60                 :            : 
      61                 :            :     // doc1 should come top, but if term "foo" gets wdf of 1, doc2 will beat it
      62                 :            :     // doc3 should beat both
      63                 :            :     // Note: all docs have same length
      64 [ +  - ][ +  - ]:          5 :     doc1.set_data(string("tom"));
      65 [ +  - ][ +  - ]:          5 :     doc1.add_posting("foo", 1);
      66 [ +  - ][ +  - ]:          5 :     doc1.add_posting("foo", 1);
      67 [ +  - ][ +  - ]:          5 :     doc1.add_posting("foo", 1);
      68 [ +  - ][ +  - ]:          5 :     doc1.add_posting("bar", 3);
      69 [ +  - ][ +  - ]:          5 :     doc1.add_posting("bar", 4);
      70         [ +  - ]:          5 :     db.add_document(doc1);
      71                 :            : 
      72 [ +  - ][ +  - ]:          5 :     doc2.set_data(string("dick"));
      73 [ +  - ][ +  - ]:          5 :     doc2.add_posting("foo", 1);
      74 [ +  - ][ +  - ]:          5 :     doc2.add_posting("foo", 2);
      75 [ +  - ][ +  - ]:          5 :     doc2.add_posting("bar", 3);
      76 [ +  - ][ +  - ]:          5 :     doc2.add_posting("bar", 3);
      77 [ +  - ][ +  - ]:          5 :     doc2.add_posting("bar", 3);
      78         [ +  - ]:          5 :     db.add_document(doc2);
      79                 :            : 
      80 [ +  - ][ +  - ]:          5 :     doc3.set_data(string("harry"));
      81 [ +  - ][ +  - ]:          5 :     doc3.add_posting("foo", 1);
      82 [ +  - ][ +  - ]:          5 :     doc3.add_posting("foo", 1);
      83 [ +  - ][ +  - ]:          5 :     doc3.add_posting("foo", 2);
      84 [ +  - ][ +  - ]:          5 :     doc3.add_posting("foo", 2);
      85 [ +  - ][ +  - ]:          5 :     doc3.add_posting("bar", 3);
      86         [ +  - ]:          5 :     db.add_document(doc3);
      87                 :            : 
      88 [ +  - ][ +  - ]:         10 :     Xapian::Query query("foo");
      89                 :            : 
      90         [ +  - ]:         10 :     Xapian::Enquire enq(db);
      91         [ +  - ]:          5 :     enq.set_query(query);
      92                 :            : 
      93         [ +  - ]:         10 :     Xapian::MSet mset = enq.get_mset(0, 10);
      94                 :            : 
      95         [ +  - ]:          5 :     mset_expect_order(mset, 3, 1, 2);
      96                 :            : 
      97                 :          5 :     return true;
      98                 :            : }
      99                 :            : 
     100                 :            : // test that removing a posting and removing a term works
     101                 :          4 : DEFINE_TESTCASE(adddoc2, writable && !multi) {
     102                 :            :     // FIXME: With multi, get_termfreq() on a TermIterator from a Document
     103                 :            :     // currently returns the termfreq for just the shard the doc is in.
     104 [ +  - ][ +  - ]:          4 :     Xapian::WritableDatabase db = get_writable_database();
     105                 :            : 
     106         [ +  - ]:          8 :     Xapian::Document doc1;
     107                 :            : 
     108 [ +  - ][ +  - ]:          4 :     doc1.add_posting("foo", 1);
     109 [ +  - ][ +  - ]:          4 :     doc1.add_posting("foo", 1);
     110 [ +  - ][ +  - ]:          4 :     doc1.add_posting("foo", 2);
     111 [ +  - ][ +  - ]:          4 :     doc1.add_posting("foo", 2);
     112 [ +  - ][ +  - ]:          4 :     doc1.add_posting("bar", 3);
     113 [ +  - ][ +  - ]:          4 :     doc1.add_posting("gone", 1);
     114                 :            :     // Quartz had a bug handling a term >= 128 characters longer than the
     115                 :            :     // preceding term in the sort order - this is "foo" + 130 "X"s
     116 [ +  - ][ +  - ]:          4 :     doc1.add_posting("fooXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX", 1);
     117                 :            :     Xapian::docid did;
     118                 :            : 
     119 [ +  - ][ +  - ]:          8 :     Xapian::Document doc2 = db.get_document(did = db.add_document(doc1));
     120 [ -  + ][ #  # ]:          4 :     TEST_EQUAL(did, 1);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     121                 :            : 
     122         [ +  - ]:          8 :     Xapian::TermIterator iter1 = doc1.termlist_begin();
     123         [ +  - ]:          8 :     Xapian::TermIterator iter2 = doc2.termlist_begin();
     124 [ -  + ][ #  # ]:          4 :     TEST(iter1 != doc1.termlist_end());
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
     125 [ -  + ][ #  # ]:          4 :     TEST(iter2 != doc2.termlist_end());
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
     126 [ +  - ][ +  - ]:          4 :     TEST_EQUAL(*iter1, "bar");
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
     127 [ +  - ][ +  - ]:          4 :     TEST_EQUAL(*iter2, *iter1);
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     128 [ +  - ][ -  + ]:          4 :     TEST_EQUAL(iter1.get_wdf(), 1);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     129 [ +  - ][ -  + ]:          4 :     TEST_EQUAL(iter2.get_wdf(), 1);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     130                 :            :     // TEST_EQUAL(iter1.get_termfreq(), 0);
     131 [ +  - ][ -  + ]:          4 :     TEST_EQUAL(iter2.get_termfreq(), 1);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     132                 :            : 
     133         [ +  - ]:          4 :     iter1++;
     134         [ +  - ]:          4 :     iter2++;
     135 [ -  + ][ #  # ]:          4 :     TEST(iter1 != doc1.termlist_end());
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
     136 [ -  + ][ #  # ]:          4 :     TEST(iter2 != doc2.termlist_end());
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
     137 [ +  - ][ +  - ]:          4 :     TEST_EQUAL(*iter1, "foo");
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
     138 [ +  - ][ +  - ]:          4 :     TEST_EQUAL(*iter2, *iter1);
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     139 [ +  - ][ -  + ]:          4 :     TEST_EQUAL(iter1.get_wdf(), 4);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     140 [ +  - ][ -  + ]:          4 :     TEST_EQUAL(iter2.get_wdf(), 4);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     141                 :            :     // TEST_EQUAL(iter1.get_termfreq(), 0);
     142 [ +  - ][ -  + ]:          4 :     TEST_EQUAL(iter2.get_termfreq(), 1);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     143                 :            : 
     144         [ +  - ]:          4 :     iter1++;
     145         [ +  - ]:          4 :     iter2++;
     146 [ -  + ][ #  # ]:          4 :     TEST(iter1 != doc1.termlist_end());
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
     147 [ -  + ][ #  # ]:          4 :     TEST(iter2 != doc2.termlist_end());
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
     148 [ +  - ][ +  - ]:          4 :     TEST_EQUAL(*iter1, "fooXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX");
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
     149 [ +  - ][ +  - ]:          4 :     TEST_EQUAL(*iter2, *iter1);
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     150 [ +  - ][ -  + ]:          4 :     TEST_EQUAL(iter1.get_wdf(), 1);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     151 [ +  - ][ -  + ]:          4 :     TEST_EQUAL(iter2.get_wdf(), 1);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     152                 :            :     // assertion fails in debug build! TEST_EQUAL(iter1.get_termfreq(), 0);
     153 [ +  - ][ -  + ]:          4 :     TEST_EQUAL(iter2.get_termfreq(), 1);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     154                 :            : 
     155         [ +  - ]:          4 :     iter1++;
     156         [ +  - ]:          4 :     iter2++;
     157 [ -  + ][ #  # ]:          4 :     TEST(iter1 != doc1.termlist_end());
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
     158 [ -  + ][ #  # ]:          4 :     TEST(iter2 != doc2.termlist_end());
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
     159 [ +  - ][ +  - ]:          4 :     TEST_EQUAL(*iter1, "gone");
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
     160 [ +  - ][ +  - ]:          4 :     TEST_EQUAL(*iter2, *iter1);
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     161 [ +  - ][ -  + ]:          4 :     TEST_EQUAL(iter1.get_wdf(), 1);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     162 [ +  - ][ -  + ]:          4 :     TEST_EQUAL(iter2.get_wdf(), 1);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     163                 :            :     // assertion fails in debug build! TEST_EQUAL(iter1.get_termfreq(), 0);
     164 [ +  - ][ -  + ]:          4 :     TEST_EQUAL(iter2.get_termfreq(), 1);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     165                 :            : 
     166         [ +  - ]:          4 :     iter1++;
     167         [ +  - ]:          4 :     iter2++;
     168 [ -  + ][ #  # ]:          4 :     TEST(iter1 == doc1.termlist_end());
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
     169 [ -  + ][ #  # ]:          4 :     TEST(iter2 == doc2.termlist_end());
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
     170                 :            : 
     171 [ +  - ][ +  - ]:          4 :     doc2.remove_posting("foo", 1, 5);
     172 [ +  - ][ +  - ]:          4 :     doc2.add_term("bat", 0);
     173 [ +  - ][ +  - ]:          4 :     doc2.add_term("bar", 8);
     174 [ +  - ][ +  - ]:          4 :     doc2.add_term("bag", 0);
     175 [ +  - ][ +  - ]:          4 :     doc2.remove_term("gone");
     176 [ +  - ][ +  - ]:          4 :     doc2.remove_term("fooXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX");
     177                 :            : 
     178                 :            :     // Should have (doc,wdf) pairs: (bag,0)(bar,9)(bat,0)(foo,0)
     179                 :            :     // positionlists (bag,none)(bar,3)(bat,none)(foo,2)
     180                 :            : 
     181 [ +  - ][ +  - ]:          4 :     iter2 = doc2.termlist_begin();
     182 [ -  + ][ #  # ]:          4 :     TEST(iter2 != doc2.termlist_end());
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
     183 [ +  - ][ +  - ]:          4 :     TEST_EQUAL(*iter2, "bag");
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
     184                 :            :     // TEST_EQUAL(iter2.get_termfreq(), 0);
     185         [ +  - ]:          4 :     iter2++;
     186 [ -  + ][ #  # ]:          4 :     TEST(iter2 != doc2.termlist_end());
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
     187 [ +  - ][ +  - ]:          4 :     TEST_EQUAL(*iter2, "bar");
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
     188                 :            :     // TEST_EQUAL(iter2.get_termfreq(), 0);
     189         [ +  - ]:          4 :     iter2++;
     190 [ -  + ][ #  # ]:          4 :     TEST(iter2 != doc2.termlist_end());
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
     191 [ +  - ][ +  - ]:          4 :     TEST_EQUAL(*iter2, "bat");
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
     192                 :            :     // TEST_EQUAL(iter2.get_termfreq(), 0);
     193         [ +  - ]:          4 :     iter2++;
     194 [ -  + ][ #  # ]:          4 :     TEST(iter2 != doc2.termlist_end());
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
     195 [ +  - ][ +  - ]:          4 :     TEST_EQUAL(*iter2, "foo");
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
     196                 :            :     // TEST_EQUAL(iter2.get_termfreq(), 0);
     197         [ +  - ]:          4 :     iter2++;
     198 [ -  + ][ #  # ]:          4 :     TEST(iter2 == doc2.termlist_end());
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
     199                 :            : 
     200 [ +  - ][ +  - ]:          4 :     doc1 = db.get_document(did = db.add_document(doc2));
                 [ +  - ]
     201 [ -  + ][ #  # ]:          4 :     TEST_EQUAL(did, 2);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     202                 :            : 
     203 [ +  - ][ +  - ]:          4 :     iter1 = doc1.termlist_begin();
     204 [ +  - ][ +  - ]:          4 :     iter2 = doc2.termlist_begin();
     205 [ -  + ][ #  # ]:          4 :     TEST(iter1 != doc1.termlist_end());
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
     206 [ -  + ][ #  # ]:          4 :     TEST(iter2 != doc2.termlist_end());
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
     207 [ +  - ][ +  - ]:          4 :     TEST_EQUAL(*iter1, "bag");
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
     208 [ +  - ][ +  - ]:          4 :     TEST_EQUAL(*iter2, *iter1);
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     209 [ +  - ][ -  + ]:          4 :     TEST_EQUAL(iter1.get_wdf(), 0);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     210 [ +  - ][ -  + ]:          4 :     TEST_EQUAL(iter2.get_wdf(), 0);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     211 [ +  - ][ -  + ]:          4 :     TEST_EQUAL(iter1.get_termfreq(), 1);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     212                 :            :     // TEST_EQUAL(iter2.get_termfreq(), 0);
     213 [ +  - ][ -  + ]:          4 :     TEST(iter1.positionlist_begin() == iter1.positionlist_end());
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     214 [ +  - ][ -  + ]:          4 :     TEST(iter2.positionlist_begin() == iter2.positionlist_end());
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     215                 :            : 
     216         [ +  - ]:          4 :     iter1++;
     217         [ +  - ]:          4 :     iter2++;
     218 [ -  + ][ #  # ]:          4 :     TEST(iter1 != doc1.termlist_end());
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
     219 [ -  + ][ #  # ]:          4 :     TEST(iter2 != doc2.termlist_end());
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
     220 [ +  - ][ +  - ]:          4 :     TEST_EQUAL(*iter1, "bar");
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
     221 [ +  - ][ +  - ]:          4 :     TEST_EQUAL(*iter2, *iter1);
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     222 [ +  - ][ -  + ]:          4 :     TEST_EQUAL(iter1.get_wdf(), 9);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     223 [ +  - ][ -  + ]:          4 :     TEST_EQUAL(iter2.get_wdf(), 9);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     224 [ +  - ][ -  + ]:          4 :     TEST_EQUAL(iter1.get_termfreq(), 2);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     225                 :            :     // TEST_EQUAL(iter2.get_termfreq(), 0);
     226                 :            : 
     227                 :          8 :     Xapian::PositionIterator pi1;
     228 [ +  - ][ +  - ]:          4 :     pi1 = iter1.positionlist_begin();
     229         [ +  - ]:          8 :     Xapian::PositionIterator pi2 = iter2.positionlist_begin();
     230 [ +  - ][ -  + ]:          4 :     TEST_EQUAL(*pi1, 3); pi1++;
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ +  - ]
     231 [ +  - ][ -  + ]:          4 :     TEST_EQUAL(*pi2, 3); pi2++;
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ +  - ]
     232 [ -  + ][ #  # ]:          4 :     TEST(pi1 == iter1.positionlist_end());
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
     233 [ -  + ][ #  # ]:          4 :     TEST(pi2 == iter2.positionlist_end());
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
     234                 :            : 
     235         [ +  - ]:          4 :     iter1++;
     236         [ +  - ]:          4 :     iter2++;
     237 [ -  + ][ #  # ]:          4 :     TEST(iter1 != doc1.termlist_end());
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
     238 [ -  + ][ #  # ]:          4 :     TEST(iter2 != doc2.termlist_end());
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
     239 [ +  - ][ +  - ]:          4 :     TEST_EQUAL(*iter1, "bat");
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
     240 [ +  - ][ +  - ]:          4 :     TEST_EQUAL(*iter2, *iter1);
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     241 [ +  - ][ -  + ]:          4 :     TEST_EQUAL(iter1.get_wdf(), 0);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     242 [ +  - ][ -  + ]:          4 :     TEST_EQUAL(iter2.get_wdf(), 0);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     243 [ +  - ][ -  + ]:          4 :     TEST_EQUAL(iter1.get_termfreq(), 1);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     244                 :            :     // TEST_EQUAL(iter2.get_termfreq(), 0);
     245 [ +  - ][ -  + ]:          4 :     TEST(iter1.positionlist_begin() == iter1.positionlist_end());
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     246 [ +  - ][ -  + ]:          4 :     TEST(iter2.positionlist_begin() == iter2.positionlist_end());
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     247                 :            : 
     248         [ +  - ]:          4 :     iter1++;
     249         [ +  - ]:          4 :     iter2++;
     250 [ -  + ][ #  # ]:          4 :     TEST(iter1 != doc1.termlist_end());
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
     251 [ -  + ][ #  # ]:          4 :     TEST(iter2 != doc2.termlist_end());
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
     252 [ +  - ][ +  - ]:          4 :     TEST_EQUAL(*iter1, "foo");
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
     253 [ +  - ][ +  - ]:          4 :     TEST_EQUAL(*iter2, *iter1);
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     254 [ +  - ][ -  + ]:          4 :     TEST_EQUAL(iter1.get_wdf(), 0);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     255 [ +  - ][ -  + ]:          4 :     TEST_EQUAL(iter2.get_wdf(), 0);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     256 [ +  - ][ -  + ]:          4 :     TEST_EQUAL(iter1.get_termfreq(), 2);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     257                 :            :     // TEST_EQUAL(iter2.get_termfreq(), 0);
     258                 :            : 
     259         [ +  - ]:          8 :     Xapian::PositionIterator temp1 = iter1.positionlist_begin();
     260         [ +  - ]:          4 :     pi1 = temp1;
     261         [ +  - ]:          8 :     Xapian::PositionIterator temp2 = iter2.positionlist_begin();
     262         [ +  - ]:          4 :     pi2 = temp2;
     263 [ +  - ][ -  + ]:          4 :     TEST_EQUAL(*pi1, 2); pi1++;
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ +  - ]
     264 [ +  - ][ -  + ]:          4 :     TEST_EQUAL(*pi2, 2); pi2++;
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ +  - ]
     265 [ -  + ][ #  # ]:          4 :     TEST(pi1 == iter1.positionlist_end());
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
     266 [ -  + ][ #  # ]:          4 :     TEST(pi2 == iter2.positionlist_end());
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
     267                 :            : 
     268         [ +  - ]:          4 :     iter1++;
     269         [ +  - ]:          4 :     iter2++;
     270 [ -  + ][ #  # ]:          4 :     TEST(iter1 == doc1.termlist_end());
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
     271 [ -  + ][ #  # ]:          4 :     TEST(iter2 == doc2.termlist_end());
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
     272                 :            : 
     273                 :          4 :     return true;
     274                 :            : }
     275                 :            : 
     276                 :            : // test that adding lots of documents works, and doesn't leak memory
     277                 :            : // REGRESSION FIXED:2003-09-07
     278                 :          5 : DEFINE_TESTCASE(adddoc3, writable) {
     279 [ +  - ][ +  - ]:          5 :     Xapian::WritableDatabase db = get_writable_database();
     280                 :            : 
     281         [ +  + ]:      10505 :     for (Xapian::doccount i = 0; i < 2100; ++i) {
     282         [ +  - ]:      10500 :         Xapian::Document doc;
     283         [ +  + ]:    1060500 :         for (Xapian::termcount t = 0; t < 100; ++t) {
     284         [ +  - ]:    1050000 :             string term("foo");
     285         [ +  - ]:    1050000 :             term += char(t ^ 70 ^ i);
     286         [ +  - ]:    1050000 :             doc.add_posting(term, t);
     287                 :    1050000 :         }
     288         [ +  - ]:      10500 :         db.add_document(doc);
     289                 :      10500 :     }
     290                 :          5 :     return true;
     291                 :            : }
     292                 :            : 
     293                 :            : // We originally wanted to test that a termlist starting with a 48 character
     294                 :            : // long term worked since that required special handling in flint for
     295                 :            : // historical reasons.  That's no longer relevant, but it seems useful to
     296                 :            : // continue to test term lists starting with various term lengths work.
     297                 :          5 : DEFINE_TESTCASE(adddoc4, writable) {
     298 [ +  - ][ +  - ]:          5 :     Xapian::WritableDatabase db = get_writable_database();
     299                 :            : 
     300         [ +  + ]:       1205 :     for (Xapian::doccount i = 1; i <= 240; ++i) {
     301         [ +  - ]:       1200 :         Xapian::Document doc;
     302         [ +  - ]:       2400 :         string term(i, 'X');
     303         [ +  - ]:       1200 :         doc.add_term(term);
     304         [ +  - ]:       1200 :         db.add_document(doc);
     305                 :       1200 :     }
     306 [ +  - ][ +  - ]:          5 :     db.add_document(Xapian::Document());
     307         [ +  - ]:          5 :     db.commit();
     308                 :            : 
     309         [ +  + ]:       1205 :     for (Xapian::doccount i = 1; i <= 240; ++i) {
     310         [ +  - ]:       1200 :         Xapian::Document doc = db.get_document(i);
     311         [ +  - ]:       2400 :         Xapian::TermIterator t = doc.termlist_begin();
     312 [ -  + ][ #  # ]:       1200 :         TEST(t != doc.termlist_end());
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
     313 [ +  - ][ -  + ]:       1200 :         TEST_EQUAL((*t).size(), i);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     314         [ +  - ]:       1200 :         ++t;
     315 [ -  + ][ #  # ]:       1200 :         TEST(t == doc.termlist_end());
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
     316                 :       1200 :     }
     317                 :            : 
     318                 :            :     // And test a document with no terms.
     319         [ +  - ]:         10 :     Xapian::Document doc = db.get_document(241);
     320 [ +  - ][ -  + ]:          5 :     TEST(doc.termlist_begin() == doc.termlist_end());
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     321                 :            : 
     322                 :          5 :     return true;
     323                 :            : }
     324                 :            : 
     325                 :            : // Test adding a document, and checking that it got added correctly.
     326                 :            : // This testcase used to be adddoc2 in quartztest.
     327                 :          4 : DEFINE_TESTCASE(adddoc5, writable && !multi) {
     328                 :            :     // FIXME: With multi, get_termfreq() on a TermIterator from a Document
     329                 :            :     // currently returns the termfreq for just the shard the doc is in.
     330                 :            : 
     331                 :            :     // Inmemory doesn't support get_writable_database_as_database().
     332 [ +  - ][ +  + ]:          4 :     SKIP_TEST_FOR_BACKEND("inmemory");
     333                 :            : 
     334                 :            :     Xapian::docid did;
     335         [ +  - ]:          3 :     Xapian::Document document_in;
     336 [ +  - ][ +  - ]:          3 :     document_in.set_data("Foobar rising");
     337 [ +  - ][ +  - ]:          3 :     document_in.add_value(7, "Value7");
     338 [ +  - ][ +  - ]:          3 :     document_in.add_value(13, "Value13");
     339 [ +  - ][ +  - ]:          3 :     document_in.add_posting("foobar", 1);
     340 [ +  - ][ +  - ]:          3 :     document_in.add_posting("rising", 2);
     341 [ +  - ][ +  - ]:          3 :     document_in.add_posting("foobar", 3);
     342                 :            : 
     343         [ +  - ]:          6 :     Xapian::Document document_in2;
     344 [ +  - ][ +  - ]:          3 :     document_in2.set_data("Foobar falling");
     345 [ +  - ][ +  - ]:          3 :     document_in2.add_posting("foobar", 1);
     346 [ +  - ][ +  - ]:          3 :     document_in2.add_posting("falling", 2);
     347                 :            :     {
     348 [ +  - ][ +  - ]:          3 :         Xapian::WritableDatabase database(get_writable_database());
     349                 :            : 
     350 [ +  - ][ -  + ]:          3 :         TEST_EQUAL(database.get_doccount(), 0);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     351 [ +  - ][ -  + ]:          3 :         TEST_EQUAL(database.get_avlength(), 0);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     352                 :            : 
     353         [ +  - ]:          3 :         did = database.add_document(document_in);
     354 [ +  - ][ -  + ]:          3 :         TEST_EQUAL(database.get_doccount(), 1);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     355 [ +  - ][ -  + ]:          3 :         TEST_EQUAL(database.get_avlength(), 3);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     356                 :            : 
     357 [ +  - ][ +  - ]:          3 :         TEST_EQUAL(database.get_termfreq("foobar"), 1);
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     358 [ +  - ][ +  - ]:          3 :         TEST_EQUAL(database.get_collection_freq("foobar"), 2);
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     359 [ +  - ][ +  - ]:          3 :         TEST_EQUAL(database.get_termfreq("rising"), 1);
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     360 [ +  - ][ +  - ]:          3 :         TEST_EQUAL(database.get_collection_freq("rising"), 1);
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     361 [ +  - ][ +  - ]:          3 :         TEST_EQUAL(database.get_termfreq("falling"), 0);
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     362 [ +  - ][ +  - ]:          3 :         TEST_EQUAL(database.get_collection_freq("falling"), 0);
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     363                 :            : 
     364         [ +  - ]:          3 :         Xapian::docid did2 = database.add_document(document_in2);
     365 [ +  - ][ -  + ]:          3 :         TEST_EQUAL(database.get_doccount(), 2);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     366 [ -  + ][ #  # ]:          3 :         TEST_NOT_EQUAL(did, did2);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     367 [ +  - ][ -  + ]:          3 :         TEST_EQUAL(database.get_avlength(), 5.0 / 2.0);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     368                 :            : 
     369 [ +  - ][ +  - ]:          3 :         TEST_EQUAL(database.get_termfreq("foobar"), 2);
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     370 [ +  - ][ +  - ]:          3 :         TEST_EQUAL(database.get_collection_freq("foobar"), 3);
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     371 [ +  - ][ +  - ]:          3 :         TEST_EQUAL(database.get_termfreq("rising"), 1);
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     372 [ +  - ][ +  - ]:          3 :         TEST_EQUAL(database.get_collection_freq("rising"), 1);
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     373 [ +  - ][ +  - ]:          3 :         TEST_EQUAL(database.get_termfreq("falling"), 1);
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     374 [ +  - ][ +  - ]:          3 :         TEST_EQUAL(database.get_collection_freq("falling"), 1);
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     375                 :            : 
     376         [ +  - ]:          3 :         database.delete_document(did);
     377 [ +  - ][ -  + ]:          3 :         TEST_EQUAL(database.get_doccount(), 1);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     378 [ +  - ][ -  + ]:          3 :         TEST_EQUAL(database.get_avlength(), 2);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     379                 :            : 
     380 [ +  - ][ +  - ]:          3 :         TEST_EQUAL(database.get_termfreq("foobar"), 1);
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     381 [ +  - ][ +  - ]:          3 :         TEST_EQUAL(database.get_collection_freq("foobar"), 1);
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     382 [ +  - ][ +  - ]:          3 :         TEST_EQUAL(database.get_termfreq("rising"), 0);
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     383 [ +  - ][ +  - ]:          3 :         TEST_EQUAL(database.get_collection_freq("rising"), 0);
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     384 [ +  - ][ +  - ]:          3 :         TEST_EQUAL(database.get_termfreq("falling"), 1);
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     385 [ +  - ][ +  - ]:          3 :         TEST_EQUAL(database.get_collection_freq("falling"), 1);
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     386                 :            : 
     387         [ +  - ]:          3 :         did = database.add_document(document_in);
     388 [ +  - ][ -  + ]:          3 :         TEST_EQUAL(database.get_doccount(), 2);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     389 [ +  - ][ -  + ]:          3 :         TEST_EQUAL(database.get_avlength(), 5.0 / 2.0);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     390                 :            : 
     391 [ +  - ][ +  - ]:          3 :         TEST_EQUAL(database.get_termfreq("foobar"), 2);
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     392 [ +  - ][ +  - ]:          3 :         TEST_EQUAL(database.get_collection_freq("foobar"), 3);
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     393 [ +  - ][ +  - ]:          3 :         TEST_EQUAL(database.get_termfreq("rising"), 1);
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     394 [ +  - ][ +  - ]:          3 :         TEST_EQUAL(database.get_collection_freq("rising"), 1);
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     395 [ +  - ][ +  - ]:          3 :         TEST_EQUAL(database.get_termfreq("falling"), 1);
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     396 [ +  - ][ +  - ]:          3 :         TEST_EQUAL(database.get_collection_freq("falling"), 1);
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     397                 :            :     }
     398                 :            : 
     399                 :            :     {
     400         [ +  - ]:          3 :         Xapian::Database database(get_writable_database_as_database());
     401 [ +  - ][ +  - ]:          6 :         Xapian::Document document_out = database.get_document(did);
     402                 :            : 
     403 [ +  - ][ +  - ]:          3 :         TEST_EQUAL(document_in.get_data(), document_out.get_data());
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     404                 :            : 
     405                 :            :         {
     406         [ +  - ]:          3 :             Xapian::ValueIterator i(document_in.values_begin());
     407         [ +  - ]:          6 :             Xapian::ValueIterator j(document_out.values_begin());
     408 [ +  - ][ +  - ]:          9 :             for (; i != document_in.values_end(); i++, j++) {
                 [ +  + ]
     409 [ -  + ][ #  # ]:          6 :                 TEST_NOT_EQUAL(j, document_out.values_end());
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     410 [ +  - ][ +  - ]:          6 :                 TEST_EQUAL(*i, *j);
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     411 [ +  - ][ +  - ]:          6 :                 TEST_EQUAL(i.get_valueno(), j.get_valueno());
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     412                 :            :             }
     413 [ -  + ][ #  # ]:          6 :             TEST_EQUAL(j, document_out.values_end());
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     414                 :            :         }
     415                 :            : 
     416                 :            :         {
     417                 :            :             // Regression test for bug fixed in 1.0.5 - values_begin() didn't
     418                 :            :             // ensure that values had been read.  However, values_end() did
     419                 :            :             // (and so did values_count()) so this wasn't generally an issue
     420                 :            :             // but it shouldn't happen anyway.
     421         [ +  - ]:          3 :             Xapian::Document doc_tmp = database.get_document(did);
     422         [ +  - ]:          6 :             Xapian::ValueIterator i = document_in.values_begin();
     423         [ +  - ]:          6 :             Xapian::ValueIterator j = doc_tmp.values_begin();
     424 [ +  - ][ +  - ]:          6 :             TEST_EQUAL(*i, *j);
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     425                 :            :         }
     426                 :            : 
     427                 :            :         {
     428         [ +  - ]:          3 :             Xapian::TermIterator i(document_in.termlist_begin());
     429 [ +  - ][ +  - ]:          6 :             Xapian::TermIterator j(document_out.termlist_begin());
     430 [ +  - ][ +  - ]:          9 :             for (; i != document_in.termlist_end(); i++, j++) {
                 [ +  + ]
     431 [ -  + ][ #  # ]:          6 :                 TEST_NOT_EQUAL(j, document_out.termlist_end());
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     432 [ +  - ][ +  - ]:          6 :                 TEST_EQUAL(*i, *j);
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     433 [ +  - ][ +  - ]:          6 :                 TEST_EQUAL(i.get_wdf(), j.get_wdf());
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     434                 :            :                 // Actually use termfreq to stop compiler optimising away the
     435                 :            :                 // call to get_termfreq().
     436 [ +  - ][ -  + ]:          6 :                 TEST_EXCEPTION(Xapian::InvalidOperationError,
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ -  + ]
           [ -  +  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
           #  # ][ +  - ]
     437                 :            :                                if (i.get_termfreq()) return false);
     438 [ +  - ][ -  +  :          6 :                 TEST_NOT_EQUAL(0, j.get_termfreq());
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
                   #  # ]
     439 [ +  - ][ +  - ]:          6 :                 if (*i == "foobar") {
                 [ +  + ]
     440                 :            :                     // termfreq of foobar is 2
     441 [ +  - ][ -  +  :          3 :                     TEST_EQUAL(2, j.get_termfreq());
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
                   #  # ]
     442                 :            :                 } else {
     443                 :            :                     // termfreq of rising is 1
     444 [ +  - ][ +  - ]:          3 :                     TEST_EQUAL(*i, "rising");
           [ -  +  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
             #  #  #  #  
                      # ]
     445 [ +  - ][ -  +  :          3 :                     TEST_EQUAL(1, j.get_termfreq());
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
                   #  # ]
     446                 :            :                 }
     447         [ +  - ]:          6 :                 Xapian::PositionIterator k(i.positionlist_begin());
     448         [ +  - ]:         12 :                 Xapian::PositionIterator l(j.positionlist_begin());
     449 [ +  - ][ +  - ]:         15 :                 for (; k != i.positionlist_end(); k++, l++) {
                 [ +  + ]
     450   [ -  +  #  #  :          9 :                     TEST_NOT_EQUAL(l, j.positionlist_end());
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
                #  #  # ]
     451 [ +  - ][ +  - ]:          9 :                     TEST_EQUAL(*k, *l);
           [ -  +  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
                   #  # ]
     452                 :            :                 }
     453   [ -  +  #  #  :          6 :                 TEST_EQUAL(l, j.positionlist_end());
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
                #  #  # ]
     454                 :          6 :             }
     455 [ -  + ][ #  # ]:          6 :             TEST_EQUAL(j, document_out.termlist_end());
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ +  - ]
                 [ +  - ]
     456                 :          3 :         }
     457                 :            :     }
     458                 :            : 
     459                 :          6 :     return true;
     460                 :            : }
     461                 :            : 
     462                 :            : // Test adding a document, and checking that it got added correctly.
     463                 :            : // This testcase used to be adddoc3 in quartztest.
     464                 :          5 : DEFINE_TESTCASE(adddoc6, writable) {
     465                 :            :     // Inmemory doesn't support get_writable_database_again().
     466 [ +  - ][ +  + ]:          5 :     SKIP_TEST_FOR_BACKEND("inmemory");
     467                 :            : 
     468                 :            :     Xapian::docid did;
     469         [ +  - ]:          4 :     Xapian::Document document_in;
     470 [ +  - ][ +  - ]:          4 :     document_in.set_data("Foobar rising");
     471 [ +  - ][ +  - ]:          4 :     document_in.add_value(7, "Value7");
     472 [ +  - ][ +  - ]:          4 :     document_in.add_value(13, "Value13");
     473 [ +  - ][ +  - ]:          4 :     document_in.add_posting("foo", 1);
     474 [ +  - ][ +  - ]:          4 :     document_in.add_posting("bar", 2);
     475                 :            : 
     476                 :            :     {
     477 [ +  - ][ +  - ]:          4 :         Xapian::WritableDatabase database(get_writable_database());
     478                 :            : 
     479         [ +  - ]:          4 :         did = database.add_document(document_in);
     480 [ -  + ][ #  # ]:          4 :         TEST_EQUAL(did, 1);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     481 [ +  - ][ -  + ]:          4 :         TEST_EQUAL(database.get_doccount(), 1);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     482 [ +  - ][ -  + ]:          4 :         TEST_EQUAL(database.get_avlength(), 2);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     483                 :            :     }
     484                 :            : 
     485                 :            :     {
     486         [ +  - ]:          4 :         Xapian::WritableDatabase database(get_writable_database_again());
     487                 :            : 
     488 [ +  - ][ +  - ]:          4 :         document_in.remove_term("foo");
     489 [ +  - ][ +  - ]:          4 :         document_in.add_posting("baz", 1);
     490                 :            : 
     491         [ +  - ]:          4 :         database.replace_document(1, document_in);
     492                 :            : 
     493         [ +  - ]:          4 :         database.delete_document(1);
     494                 :            : 
     495 [ +  - ][ -  + ]:          4 :         TEST_EQUAL(database.get_doccount(), 0);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     496 [ +  - ][ -  + ]:          4 :         TEST_EQUAL(database.get_avlength(), 0);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     497 [ +  - ][ +  - ]:          4 :         TEST_EQUAL(database.get_termfreq("foo"), 0);
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     498 [ +  - ][ +  - ]:          4 :         TEST_EQUAL(database.get_collection_freq("foo"), 0);
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     499 [ +  - ][ +  - ]:          4 :         TEST_EQUAL(database.get_termfreq("bar"), 0);
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     500 [ +  - ][ +  - ]:          4 :         TEST_EQUAL(database.get_collection_freq("bar"), 0);
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     501 [ +  - ][ +  - ]:          4 :         TEST_EQUAL(database.get_termfreq("baz"), 0);
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     502 [ +  - ][ +  - ]:          4 :         TEST_EQUAL(database.get_collection_freq("baz"), 0);
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     503                 :            :     }
     504                 :            : 
     505                 :          4 :     return true;
     506                 :            : }
     507                 :            : 
     508                 :            : // tests that database destructors commit if it isn't done explicitly
     509                 :          5 : DEFINE_TESTCASE(implicitendsession1, writable) {
     510 [ +  - ][ +  - ]:          5 :     Xapian::WritableDatabase db = get_writable_database();
     511                 :            : 
     512         [ +  - ]:         10 :     Xapian::Document doc;
     513                 :            : 
     514 [ +  - ][ +  - ]:          5 :     doc.set_data(string("top secret"));
     515 [ +  - ][ +  - ]:          5 :     doc.add_posting("cia", 1);
     516 [ +  - ][ +  - ]:          5 :     doc.add_posting("nsa", 2);
     517 [ +  - ][ +  - ]:          5 :     doc.add_posting("fbi", 3);
     518         [ +  - ]:          5 :     db.add_document(doc);
     519                 :            : 
     520                 :          5 :     return true;
     521                 :            : }
     522                 :            : 
     523                 :            : // tests that assignment of Xapian::Database and Xapian::WritableDatabase works
     524                 :            : // as expected
     525                 :          5 : DEFINE_TESTCASE(databaseassign1, writable) {
     526 [ +  - ][ +  - ]:          5 :     Xapian::WritableDatabase wdb = get_writable_database();
     527 [ +  - ][ +  - ]:         10 :     Xapian::Database db = get_database("");
     528         [ +  - ]:         10 :     Xapian::Database actually_wdb = wdb;
     529         [ +  - ]:         10 :     Xapian::WritableDatabase w1(wdb);
     530         [ +  - ]:          5 :     w1 = wdb;
     531         [ +  - ]:         10 :     Xapian::Database d1(wdb);
     532         [ +  - ]:         10 :     Xapian::Database d2(actually_wdb);
     533         [ +  - ]:          5 :     d2 = wdb;
     534         [ +  - ]:          5 :     d2 = actually_wdb;
     535                 :            : #ifdef __has_warning
     536                 :            : # if __has_warning("-Wself-assign-overloaded")
     537                 :            :     // Suppress warning from newer clang about self-assignment so we can
     538                 :            :     // test that self-assignment works!
     539                 :            : #  pragma clang diagnostic push
     540                 :            : #  pragma clang diagnostic ignored "-Wself-assign-overloaded"
     541                 :            : # endif
     542                 :            : #endif
     543         [ +  - ]:          5 :     wdb = wdb; // check assign to itself works
     544         [ +  - ]:          5 :     db = db; // check assign to itself works
     545                 :            : #ifdef __has_warning
     546                 :            : # if __has_warning("-Wself-assign-overloaded")
     547                 :            : #  pragma clang diagnostic pop
     548                 :            : # endif
     549                 :            : #endif
     550                 :          5 :     return true;
     551                 :            : }
     552                 :            : 
     553                 :            : // tests that deletion and updating of documents works as expected
     554                 :          5 : DEFINE_TESTCASE(deldoc1, writable) {
     555 [ +  - ][ +  - ]:          5 :     Xapian::WritableDatabase db = get_writable_database();
     556                 :            : 
     557         [ +  - ]:         10 :     Xapian::Document doc1;
     558                 :            : 
     559 [ +  - ][ +  - ]:          5 :     doc1.add_posting("foo", 1);
     560 [ +  - ][ +  - ]:          5 :     doc1.add_posting("foo", 1);
     561 [ +  - ][ +  - ]:          5 :     doc1.add_posting("foo", 2);
     562 [ +  - ][ +  - ]:          5 :     doc1.add_posting("foo", 2);
     563 [ +  - ][ +  - ]:          5 :     doc1.add_posting("bar", 3);
     564 [ +  - ][ +  - ]:          5 :     doc1.add_posting("gone", 1);
     565                 :            : 
     566         [ +  - ]:          5 :     Xapian::docid did = db.add_document(doc1);
     567 [ -  + ][ #  # ]:          5 :     TEST_EQUAL(did, 1);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     568                 :            : 
     569 [ +  - ][ +  - ]:          5 :     doc1.remove_term("gone");
     570                 :            : 
     571         [ +  - ]:          5 :     did = db.add_document(doc1);
     572 [ -  + ][ #  # ]:          5 :     TEST_EQUAL(did, 2);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     573                 :            : 
     574 [ +  - ][ +  - ]:          5 :     doc1.add_term("new", 1);
     575         [ +  - ]:          5 :     did = db.add_document(doc1);
     576 [ -  + ][ #  # ]:          5 :     TEST_EQUAL(did, 3);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     577                 :            : 
     578         [ +  - ]:          5 :     db.delete_document(1);
     579                 :            : 
     580 [ +  - ][ -  + ]:          5 :     TEST_EXCEPTION(Xapian::DocNotFoundError, db.get_document(1));
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ -  + ][ -  +  
          #  #  #  #  #  
          #  #  #  #  #  
             #  #  #  # ]
                 [ +  - ]
     581                 :            : 
     582 [ +  - ][ +  - ]:          5 :     doc1 = db.get_document(2);
     583 [ +  - ][ +  - ]:          5 :     doc1.remove_term("foo");
     584 [ +  - ][ +  - ]:          5 :     doc1.add_term("fwing");
     585         [ +  - ]:          5 :     db.replace_document(2, doc1);
     586                 :            : 
     587         [ +  - ]:         10 :     Xapian::Document doc2 = db.get_document(2);
     588         [ +  - ]:         10 :     Xapian::TermIterator tit = doc2.termlist_begin();
     589   [ -  +  #  #  :          5 :     TEST_NOT_EQUAL(tit, doc2.termlist_end());
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
                #  #  # ]
     590 [ +  - ][ +  - ]:          5 :     TEST_EQUAL(*tit, "bar");
           [ -  +  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
             #  #  #  #  
                      # ]
     591         [ +  - ]:          5 :     tit++;
     592   [ -  +  #  #  :          5 :     TEST_NOT_EQUAL(tit, doc2.termlist_end());
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
                #  #  # ]
     593 [ +  - ][ +  - ]:          5 :     TEST_EQUAL(*tit, "fwing");
           [ -  +  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
             #  #  #  #  
                      # ]
     594         [ +  - ]:          5 :     tit++;
     595   [ -  +  #  #  :          5 :     TEST_EQUAL(tit, doc2.termlist_end());
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
                #  #  # ]
     596                 :            : 
     597                 :          5 :     return true;
     598                 :            : }
     599                 :            : 
     600                 :            : // tests that deletion and updating of documents works as expected
     601                 :          5 : DEFINE_TESTCASE(deldoc2, writable) {
     602 [ +  - ][ +  - ]:          5 :     Xapian::WritableDatabase db = get_writable_database();
     603                 :            : 
     604         [ +  - ]:         10 :     Xapian::Document doc1;
     605                 :            : 
     606 [ +  - ][ +  - ]:          5 :     doc1.add_posting("one", 1);
     607 [ +  - ][ +  - ]:          5 :     doc1.add_posting("two", 2);
     608 [ +  - ][ +  - ]:          5 :     doc1.add_posting("two", 3);
     609                 :            :     Xapian::docid did;
     610                 :            : 
     611         [ +  - ]:          5 :     did = db.add_document(doc1);
     612 [ -  + ][ #  # ]:          5 :     TEST_EQUAL(did, 1);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     613                 :            : 
     614 [ +  - ][ +  - ]:          5 :     doc1.remove_term("one");
     615 [ +  - ][ +  - ]:          5 :     doc1.add_posting("three", 4);
     616                 :            : 
     617         [ +  - ]:          5 :     did = db.add_document(doc1);
     618 [ -  + ][ #  # ]:          5 :     TEST_EQUAL(did, 2);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     619                 :            : 
     620 [ +  - ][ +  - ]:          5 :     doc1.add_posting("one", 7);
     621 [ +  - ][ +  - ]:          5 :     doc1.remove_term("two");
     622                 :            : 
     623         [ +  - ]:          5 :     did = db.add_document(doc1);
     624 [ -  + ][ #  # ]:          5 :     TEST_EQUAL(did, 3);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     625                 :            : 
     626         [ +  - ]:          5 :     db.commit();
     627                 :            : 
     628                 :            :     // reopen() on a writable database shouldn't do anything.
     629 [ +  - ][ -  + ]:          5 :     TEST(!db.reopen());
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     630                 :            : 
     631         [ +  - ]:          5 :     db.delete_document(1);
     632         [ +  - ]:          5 :     db.delete_document(2);
     633         [ +  - ]:          5 :     db.delete_document(3);
     634                 :            : 
     635         [ +  - ]:          5 :     db.commit();
     636                 :            : 
     637                 :            :     // reopen() on a writable database shouldn't do anything.
     638 [ +  - ][ -  + ]:          5 :     TEST(!db.reopen());
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     639                 :            : 
     640 [ +  - ][ +  - ]:          5 :     TEST_EQUAL(db.postlist_begin("one"), db.postlist_end("one"));
         [ +  - ][ -  + ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     641 [ +  - ][ +  - ]:          5 :     TEST_EQUAL(db.postlist_begin("two"), db.postlist_end("two"));
         [ +  - ][ -  + ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     642 [ +  - ][ +  - ]:          5 :     TEST_EQUAL(db.postlist_begin("three"), db.postlist_end("three"));
         [ +  - ][ -  + ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     643                 :            : 
     644 [ +  - ][ -  + ]:          5 :     TEST_EXCEPTION(Xapian::DocNotFoundError, db.termlist_begin(1));
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ -  + ][ -  +  
          #  #  #  #  #  
          #  #  #  #  #  
             #  #  #  # ]
                 [ +  - ]
     645 [ +  - ][ -  +  :          5 :     TEST_EXCEPTION(Xapian::DocNotFoundError, db.termlist_begin(2));
          #  #  #  #  #  
          #  #  #  #  #  
           #  # ][ -  + ]
           [ -  +  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
           #  # ][ +  - ]
     646 [ +  - ][ -  +  :          5 :     TEST_EXCEPTION(Xapian::DocNotFoundError, db.termlist_begin(3));
          #  #  #  #  #  
          #  #  #  #  #  
           #  # ][ -  + ]
           [ -  +  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
           #  # ][ +  - ]
     647 [ +  - ][ -  +  :          5 :     TEST_EXCEPTION(Xapian::DocNotFoundError, db.termlist_begin(4));
          #  #  #  #  #  
          #  #  #  #  #  
           #  # ][ -  + ]
           [ -  +  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
           #  # ][ +  - ]
     648                 :            : 
     649                 :            :     // test positionlist_{begin,end}?
     650                 :            : 
     651 [ +  - ][ -  +  :          5 :     TEST_EQUAL(db.get_doccount(), 0);
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
                   #  # ]
     652 [ +  - ][ -  +  :          5 :     TEST_EQUAL(db.get_avlength(), 0);
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
                   #  # ]
     653 [ +  - ][ +  - ]:          5 :     TEST_EQUAL(db.get_termfreq("one"), 0);
           [ -  +  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
                   #  # ]
     654 [ +  - ][ +  - ]:          5 :     TEST_EQUAL(db.get_termfreq("two"), 0);
           [ -  +  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
                   #  # ]
     655 [ +  - ][ +  - ]:          5 :     TEST_EQUAL(db.get_termfreq("three"), 0);
           [ -  +  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
                   #  # ]
     656                 :            : 
     657 [ +  - ][ +  - ]:          5 :     TEST(!db.term_exists("one"));
           [ -  +  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
                   #  # ]
     658 [ +  - ][ +  - ]:          5 :     TEST(!db.term_exists("two"));
           [ -  +  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
                   #  # ]
     659 [ +  - ][ +  - ]:          5 :     TEST(!db.term_exists("three"));
           [ -  +  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
                   #  # ]
     660                 :            : 
     661 [ +  - ][ +  - ]:          5 :     TEST_EQUAL(db.get_collection_freq("one"), 0);
           [ -  +  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
                   #  # ]
     662 [ +  - ][ +  - ]:          5 :     TEST_EQUAL(db.get_collection_freq("two"), 0);
           [ -  +  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
                   #  # ]
     663 [ +  - ][ +  - ]:          5 :     TEST_EQUAL(db.get_collection_freq("three"), 0);
           [ -  +  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
                   #  # ]
     664                 :            : 
     665 [ +  - ][ -  +  :          5 :     TEST_EXCEPTION(Xapian::DocNotFoundError, db.get_doclength(1));
          #  #  #  #  #  
          #  #  #  #  #  
           #  # ][ -  + ]
           [ -  +  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
           #  # ][ +  - ]
     666 [ +  - ][ -  +  :          5 :     TEST_EXCEPTION(Xapian::DocNotFoundError, db.get_doclength(2));
          #  #  #  #  #  
          #  #  #  #  #  
           #  # ][ -  + ]
           [ -  +  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
           #  # ][ +  - ]
     667 [ +  - ][ -  +  :          5 :     TEST_EXCEPTION(Xapian::DocNotFoundError, db.get_doclength(3));
          #  #  #  #  #  
          #  #  #  #  #  
           #  # ][ -  + ]
           [ -  +  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
           #  # ][ +  - ]
     668                 :            : 
     669 [ +  - ][ -  +  :          5 :     TEST_EXCEPTION(Xapian::DocNotFoundError, db.get_unique_terms(1));
          #  #  #  #  #  
          #  #  #  #  #  
           #  # ][ -  + ]
           [ -  +  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
           #  # ][ +  - ]
     670 [ +  - ][ -  +  :          5 :     TEST_EXCEPTION(Xapian::DocNotFoundError, db.get_unique_terms(2));
          #  #  #  #  #  
          #  #  #  #  #  
           #  # ][ -  + ]
           [ -  +  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
           #  # ][ +  - ]
     671 [ +  - ][ -  +  :          5 :     TEST_EXCEPTION(Xapian::DocNotFoundError, db.get_unique_terms(3));
          #  #  #  #  #  
          #  #  #  #  #  
           #  # ][ -  + ]
           [ -  +  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
           #  # ][ +  - ]
     672                 :            : 
     673 [ +  - ][ -  +  :          5 :     TEST_EXCEPTION(Xapian::DocNotFoundError, db.get_document(1));
          #  #  #  #  #  
          #  #  #  #  #  
           #  # ][ -  + ]
           [ -  +  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
           #  # ][ +  - ]
     674 [ +  - ][ -  +  :          5 :     TEST_EXCEPTION(Xapian::DocNotFoundError, db.get_document(2));
          #  #  #  #  #  
          #  #  #  #  #  
           #  # ][ -  + ]
           [ -  +  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
           #  # ][ +  - ]
     675 [ +  - ][ -  +  :          5 :     TEST_EXCEPTION(Xapian::DocNotFoundError, db.get_document(3));
          #  #  #  #  #  
          #  #  #  #  #  
           #  # ][ -  + ]
           [ -  +  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
           #  # ][ +  - ]
     676                 :            : 
     677 [ +  - ][ +  - ]:          5 :     TEST_EQUAL(db.allterms_begin(), db.allterms_end());
         [ +  - ][ -  +  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
                      # ]
     678                 :            : 
     679                 :          5 :     return true;
     680                 :            : }
     681                 :            : 
     682                 :            : // another test of deletion of documents, a cut-down version of deldoc2
     683                 :          5 : DEFINE_TESTCASE(deldoc3, writable) {
     684 [ +  - ][ +  - ]:          5 :     Xapian::WritableDatabase db = get_writable_database();
     685                 :            : 
     686         [ +  - ]:         10 :     Xapian::Document doc1;
     687                 :            : 
     688 [ +  - ][ +  - ]:          5 :     doc1.add_posting("one", 1);
     689                 :            : 
     690         [ +  - ]:          5 :     Xapian::docid did = db.add_document(doc1);
     691 [ -  + ][ #  # ]:          5 :     TEST_EQUAL(did, 1);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     692                 :            : 
     693         [ +  - ]:          5 :     db.commit();
     694                 :            : 
     695                 :            :     // reopen() on a writable database shouldn't do anything.
     696 [ +  - ][ -  + ]:          5 :     TEST(!db.reopen());
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     697                 :            : 
     698         [ +  - ]:          5 :     db.delete_document(1);
     699                 :            : 
     700         [ +  - ]:          5 :     db.commit();
     701                 :            : 
     702                 :            :     // reopen() on a writable database shouldn't do anything.
     703 [ +  - ][ -  + ]:          5 :     TEST(!db.reopen());
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     704                 :            : 
     705 [ +  - ][ +  - ]:          5 :     TEST_EQUAL(db.postlist_begin("one"), db.postlist_end("one"));
         [ +  - ][ -  + ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     706                 :            : 
     707 [ +  - ][ -  + ]:          5 :     TEST_EXCEPTION(Xapian::DocNotFoundError, db.termlist_begin(1));
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ -  + ][ -  +  
          #  #  #  #  #  
          #  #  #  #  #  
             #  #  #  # ]
                 [ +  - ]
     708 [ +  - ][ -  +  :          5 :     TEST_EXCEPTION(Xapian::DocNotFoundError, db.termlist_begin(2));
          #  #  #  #  #  
          #  #  #  #  #  
           #  # ][ -  + ]
           [ -  +  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
           #  # ][ +  - ]
     709                 :            : 
     710                 :            :     // test positionlist_{begin,end}?
     711                 :            : 
     712 [ +  - ][ -  +  :          5 :     TEST_EQUAL(db.get_doccount(), 0);
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
                   #  # ]
     713 [ +  - ][ -  +  :          5 :     TEST_EQUAL(db.get_avlength(), 0);
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
                   #  # ]
     714 [ +  - ][ +  - ]:          5 :     TEST_EQUAL(db.get_termfreq("one"), 0);
           [ -  +  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
                   #  # ]
     715                 :            : 
     716 [ +  - ][ +  - ]:          5 :     TEST(!db.term_exists("one"));
           [ -  +  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
                   #  # ]
     717                 :            : 
     718 [ +  - ][ +  - ]:          5 :     TEST_EQUAL(db.get_collection_freq("one"), 0);
           [ -  +  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
                   #  # ]
     719                 :            : 
     720 [ +  - ][ -  +  :          5 :     TEST_EXCEPTION(Xapian::DocNotFoundError, db.get_doclength(1));
          #  #  #  #  #  
          #  #  #  #  #  
           #  # ][ -  + ]
           [ -  +  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
           #  # ][ +  - ]
     721 [ +  - ][ -  +  :          5 :     TEST_EXCEPTION(Xapian::DocNotFoundError, db.get_doclength(2));
          #  #  #  #  #  
          #  #  #  #  #  
           #  # ][ -  + ]
           [ -  +  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
           #  # ][ +  - ]
     722                 :            : 
     723 [ +  - ][ -  +  :          5 :     TEST_EXCEPTION(Xapian::DocNotFoundError, db.get_unique_terms(1));
          #  #  #  #  #  
          #  #  #  #  #  
           #  # ][ -  + ]
           [ -  +  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
           #  # ][ +  - ]
     724 [ +  - ][ -  +  :          5 :     TEST_EXCEPTION(Xapian::DocNotFoundError, db.get_unique_terms(2));
          #  #  #  #  #  
          #  #  #  #  #  
           #  # ][ -  + ]
           [ -  +  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
           #  # ][ +  - ]
     725                 :            : 
     726 [ +  - ][ -  +  :          5 :     TEST_EXCEPTION(Xapian::DocNotFoundError, db.get_document(1));
          #  #  #  #  #  
          #  #  #  #  #  
           #  # ][ -  + ]
           [ -  +  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
           #  # ][ +  - ]
     727 [ +  - ][ -  +  :          5 :     TEST_EXCEPTION(Xapian::DocNotFoundError, db.get_document(2));
          #  #  #  #  #  
          #  #  #  #  #  
           #  # ][ -  + ]
           [ -  +  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
           #  # ][ +  - ]
     728                 :            : 
     729 [ +  - ][ +  - ]:          5 :     TEST_EQUAL(db.allterms_begin(), db.allterms_end());
         [ +  - ][ -  +  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
                      # ]
     730                 :            : 
     731                 :          5 :     return true;
     732                 :            : }
     733                 :            : 
     734                 :            : // tests that deletion and updating of (lots of) documents works as expected
     735                 :          5 : DEFINE_TESTCASE(deldoc4, writable) {
     736 [ +  - ][ +  - ]:          5 :     Xapian::WritableDatabase db = get_writable_database();
     737                 :            : 
     738         [ +  - ]:         10 :     Xapian::Document doc1;
     739                 :            : 
     740 [ +  - ][ +  - ]:          5 :     doc1.add_posting("one", 1);
     741 [ +  - ][ +  - ]:          5 :     doc1.add_posting("two", 2);
     742 [ +  - ][ +  - ]:          5 :     doc1.add_posting("two", 3);
     743                 :            : 
     744         [ +  - ]:         10 :     Xapian::Document doc2 = doc1;
     745 [ +  - ][ +  - ]:          5 :     doc2.remove_term("one");
     746 [ +  - ][ +  - ]:          5 :     doc2.add_posting("three", 4);
     747                 :            : 
     748         [ +  - ]:         10 :     Xapian::Document doc3 = doc2;
     749 [ +  - ][ +  - ]:          5 :     doc3.add_posting("one", 7);
     750 [ +  - ][ +  - ]:          5 :     doc3.remove_term("two");
     751                 :            : 
     752                 :          5 :     const Xapian::docid maxdoc = 1000 * 3;
     753                 :            :     Xapian::docid did;
     754         [ +  + ]:       5005 :     for (Xapian::docid i = 0; i < maxdoc / 3; ++i) {
     755         [ +  - ]:       5000 :         did = db.add_document(doc1);
     756 [ -  + ][ #  # ]:       5000 :         TEST_EQUAL(did, i * 3 + 1);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     757         [ +  - ]:       5000 :         did = db.add_document(doc2);
     758 [ -  + ][ #  # ]:       5000 :         TEST_EQUAL(did, i * 3 + 2);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     759         [ +  - ]:       5000 :         did = db.add_document(doc3);
     760 [ -  + ][ #  # ]:       5000 :         TEST_EQUAL(did, i * 3 + 3);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     761                 :            : 
     762                 :       5000 :         bool is_power_of_two = ((i & (i - 1)) == 0);
     763         [ +  + ]:       5000 :         if (is_power_of_two) {
     764         [ +  - ]:         55 :             db.commit();
     765                 :            :             // reopen() on a writable database shouldn't do anything.
     766 [ +  - ][ -  + ]:         55 :             TEST(!db.reopen());
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     767                 :            :         }
     768                 :            :     }
     769         [ +  - ]:          5 :     db.commit();
     770                 :            :     // reopen() on a writable database shouldn't do anything.
     771 [ +  - ][ -  + ]:          5 :     TEST(!db.reopen());
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     772                 :            : 
     773                 :            :     /* delete the documents in a peculiar order */
     774         [ +  + ]:       5005 :     for (Xapian::docid i = 0; i < maxdoc / 3; ++i) {
     775         [ +  - ]:       5000 :         db.delete_document(maxdoc - i);
     776         [ +  - ]:       5000 :         db.delete_document(maxdoc / 3 + i + 1);
     777         [ +  - ]:       5000 :         db.delete_document(i + 1);
     778                 :            :     }
     779                 :            : 
     780         [ +  - ]:          5 :     db.commit();
     781                 :            :     // reopen() on a writable database shouldn't do anything.
     782 [ +  - ][ -  + ]:          5 :     TEST(!db.reopen());
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     783                 :            : 
     784 [ +  - ][ +  - ]:          5 :     TEST_EQUAL(db.postlist_begin("one"), db.postlist_end("one"));
         [ +  - ][ -  + ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     785 [ +  - ][ +  - ]:          5 :     TEST_EQUAL(db.postlist_begin("two"), db.postlist_end("two"));
         [ +  - ][ -  + ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     786 [ +  - ][ +  - ]:          5 :     TEST_EQUAL(db.postlist_begin("three"), db.postlist_end("three"));
         [ +  - ][ -  + ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     787                 :            : 
     788         [ +  + ]:      15005 :     for (Xapian::docid i = 1; i <= maxdoc; ++i) {
     789                 :            :         // TEST_EXCEPTION writes to tout each time if the test is run
     790                 :            :         // in verbose mode and some string stream implementations get
     791                 :            :         // very inefficient with large strings, so clear tout on each pass of
     792                 :            :         // the loop to speed up the test since the older information isn't
     793                 :            :         // interesting anyway.
     794 [ +  - ][ +  - ]:      15000 :         tout.str(string());
     795 [ +  - ][ -  + ]:      15000 :         TEST_EXCEPTION(Xapian::DocNotFoundError, db.termlist_begin(i));
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ -  + ][ -  +  
          #  #  #  #  #  
          #  #  #  #  #  
             #  #  #  # ]
                 [ +  - ]
     796 [ +  - ][ -  +  :      15000 :         TEST_EXCEPTION(Xapian::DocNotFoundError, db.get_doclength(i));
          #  #  #  #  #  
          #  #  #  #  #  
           #  # ][ -  + ]
           [ -  +  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
           #  # ][ +  - ]
     797 [ +  - ][ -  +  :      15000 :         TEST_EXCEPTION(Xapian::DocNotFoundError, db.get_unique_terms(i));
          #  #  #  #  #  
          #  #  #  #  #  
           #  # ][ -  + ]
           [ -  +  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
           #  # ][ +  - ]
     798 [ +  - ][ -  +  :      15000 :         TEST_EXCEPTION(Xapian::DocNotFoundError, db.get_document(i));
          #  #  #  #  #  
          #  #  #  #  #  
           #  # ][ -  + ]
           [ -  +  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
           #  # ][ +  - ]
     799                 :            :     }
     800                 :            : 
     801                 :            :     // test positionlist_{begin,end}?
     802                 :            : 
     803 [ +  - ][ -  + ]:          5 :     TEST_EQUAL(db.get_doccount(), 0);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     804 [ +  - ][ -  + ]:          5 :     TEST_EQUAL(db.get_avlength(), 0);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     805 [ +  - ][ +  - ]:          5 :     TEST_EQUAL(db.get_termfreq("one"), 0);
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     806 [ +  - ][ +  - ]:          5 :     TEST_EQUAL(db.get_termfreq("two"), 0);
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     807 [ +  - ][ +  - ]:          5 :     TEST_EQUAL(db.get_termfreq("three"), 0);
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     808                 :            : 
     809 [ +  - ][ +  - ]:          5 :     TEST(!db.term_exists("one"));
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
     810 [ +  - ][ +  - ]:          5 :     TEST(!db.term_exists("two"));
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
     811 [ +  - ][ +  - ]:          5 :     TEST(!db.term_exists("three"));
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
     812                 :            : 
     813 [ +  - ][ +  - ]:          5 :     TEST_EQUAL(db.get_collection_freq("one"), 0);
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     814 [ +  - ][ +  - ]:          5 :     TEST_EQUAL(db.get_collection_freq("two"), 0);
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     815 [ +  - ][ +  - ]:          5 :     TEST_EQUAL(db.get_collection_freq("three"), 0);
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     816                 :            : 
     817 [ +  - ][ +  - ]:          5 :     TEST_EQUAL(db.allterms_begin(), db.allterms_end());
         [ +  - ][ -  + ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     818                 :            : 
     819                 :          5 :     return true;
     820                 :            : }
     821                 :            : 
     822                 :            : // Test deleting a document which was added in the same batch.
     823                 :          5 : DEFINE_TESTCASE(deldoc5, writable) {
     824 [ +  - ][ +  - ]:          5 :     Xapian::WritableDatabase db = get_writable_database();
     825                 :            : 
     826         [ +  - ]:         10 :     Xapian::Document doc1;
     827                 :            : 
     828 [ +  - ][ +  - ]:          5 :     doc1.add_posting("foo", 1);
     829 [ +  - ][ +  - ]:          5 :     doc1.add_posting("bar", 2);
     830 [ +  - ][ +  - ]:          5 :     doc1.add_posting("aardvark", 3);
     831                 :            : 
     832         [ +  - ]:          5 :     Xapian::docid did = db.add_document(doc1);
     833 [ -  + ][ #  # ]:          5 :     TEST_EQUAL(did, 1);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     834                 :            : 
     835 [ +  - ][ +  - ]:          5 :     doc1.remove_term("bar");
     836 [ +  - ][ +  - ]:          5 :     doc1.add_term("hello");
     837                 :            : 
     838         [ +  - ]:          5 :     did = db.add_document(doc1);
     839 [ -  + ][ #  # ]:          5 :     TEST_EQUAL(did, 2);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     840                 :            : 
     841 [ +  - ][ +  - ]:          5 :     doc1.add_term("world", 1);
     842         [ +  - ]:          5 :     did = db.add_document(doc1);
     843 [ -  + ][ #  # ]:          5 :     TEST_EQUAL(did, 3);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     844                 :            : 
     845         [ +  - ]:          5 :     db.delete_document(2);
     846                 :            : 
     847 [ +  - ][ -  + ]:          5 :     TEST_EXCEPTION(Xapian::DocNotFoundError, db.get_document(2));
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ -  + ][ -  +  
          #  #  #  #  #  
          #  #  #  #  #  
             #  #  #  # ]
                 [ +  - ]
     848                 :            : 
     849         [ +  - ]:          5 :     db.commit();
     850                 :            : 
     851 [ +  - ][ -  +  :          5 :     TEST_EXCEPTION(Xapian::DocNotFoundError, db.get_document(2));
          #  #  #  #  #  
          #  #  #  #  #  
           #  # ][ -  + ]
           [ -  +  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
           #  # ][ +  - ]
     852                 :            : 
     853 [ +  - ][ +  - ]:          5 :     TEST_EQUAL(db.get_termfreq("foo"), 2);
           [ -  +  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
                   #  # ]
     854 [ +  - ][ +  - ]:          5 :     TEST_EQUAL(db.get_termfreq("aardvark"), 2);
           [ -  +  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
                   #  # ]
     855 [ +  - ][ +  - ]:          5 :     TEST_EQUAL(db.get_termfreq("hello"), 1);
           [ -  +  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
                   #  # ]
     856                 :            : 
     857 [ +  - ][ +  - ]:         10 :     Xapian::PostingIterator p = db.postlist_begin("foo");
     858 [ +  - ][ -  +  :          5 :     TEST_NOT_EQUAL(p, db.postlist_end("foo"));
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
                   #  # ]
     859 [ +  - ][ -  +  :          5 :     TEST_EQUAL(*p, 1);
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
                   #  # ]
     860         [ +  - ]:          5 :     ++p;
     861 [ +  - ][ -  +  :          5 :     TEST_NOT_EQUAL(p, db.postlist_end("foo"));
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
                   #  # ]
     862 [ +  - ][ -  +  :          5 :     TEST_EQUAL(*p, 3);
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
                   #  # ]
     863         [ +  - ]:          5 :     ++p;
     864 [ +  - ][ -  +  :          5 :     TEST_EQUAL(p, db.postlist_end("foo"));
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
                   #  # ]
     865                 :            : 
     866                 :          5 :     return true;
     867                 :            : }
     868                 :            : 
     869                 :            : // Regression test for bug in quartz and flint, fixed in 1.0.2.
     870                 :          5 : DEFINE_TESTCASE(deldoc6, writable) {
     871 [ +  - ][ +  - ]:          5 :     Xapian::WritableDatabase db = get_writable_database();
     872                 :            : 
     873         [ +  - ]:         10 :     Xapian::Document doc1;
     874                 :            : 
     875 [ +  - ][ +  - ]:          5 :     doc1.add_posting("foo", 1);
     876 [ +  - ][ +  - ]:          5 :     doc1.add_posting("bar", 2);
     877 [ +  - ][ +  - ]:          5 :     doc1.add_posting("aardvark", 3);
     878                 :            : 
     879         [ +  - ]:          5 :     Xapian::docid did = db.add_document(doc1);
     880 [ -  + ][ #  # ]:          5 :     TEST_EQUAL(did, 1);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     881                 :            : 
     882 [ +  - ][ +  - ]:          5 :     doc1.remove_term("bar");
     883 [ +  - ][ +  - ]:          5 :     doc1.add_term("hello");
     884                 :            : 
     885         [ +  - ]:          5 :     did = db.add_document(doc1);
     886 [ -  + ][ #  # ]:          5 :     TEST_EQUAL(did, 2);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     887                 :            : 
     888         [ +  - ]:          5 :     db.commit();
     889                 :            : 
     890         [ +  - ]:          5 :     db.delete_document(2);
     891 [ +  - ][ -  + ]:          5 :     TEST_EXCEPTION(Xapian::DocNotFoundError, db.delete_document(3));
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ -  + ][ -  +  
          #  #  #  #  #  
          #  #  #  #  #  
             #  #  #  # ]
                 [ +  - ]
     892                 :            : 
     893         [ +  - ]:          5 :     db.commit();
     894                 :            : 
     895 [ +  - ][ -  +  :          5 :     TEST_EXCEPTION(Xapian::DocNotFoundError, db.get_document(2));
          #  #  #  #  #  
          #  #  #  #  #  
           #  # ][ -  + ]
           [ -  +  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
           #  # ][ +  - ]
     896                 :            : 
     897                 :          5 :     return true;
     898                 :            : }
     899                 :            : 
     900                 :          5 : DEFINE_TESTCASE(replacedoc1, writable) {
     901 [ +  - ][ +  - ]:          5 :     Xapian::WritableDatabase db = get_writable_database();
     902                 :            : 
     903         [ +  - ]:         10 :     Xapian::Document doc1;
     904                 :            : 
     905 [ +  - ][ +  - ]:          5 :     doc1.add_posting("foo", 1);
     906 [ +  - ][ +  - ]:          5 :     doc1.add_posting("foo", 2);
     907 [ +  - ][ +  - ]:          5 :     doc1.add_posting("gone", 3);
     908 [ +  - ][ +  - ]:          5 :     doc1.add_posting("bar", 4);
     909 [ +  - ][ +  - ]:          5 :     doc1.add_posting("foo", 5);
     910                 :            :     Xapian::docid did;
     911                 :            : 
     912         [ +  - ]:          5 :     did = db.add_document(doc1);
     913 [ -  + ][ #  # ]:          5 :     TEST_EQUAL(did, 1);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     914                 :            : 
     915         [ +  - ]:         10 :     Xapian::Document doc2;
     916                 :            : 
     917 [ +  - ][ +  - ]:          5 :     doc2.add_posting("foo", 1);
     918 [ +  - ][ +  - ]:          5 :     doc2.add_posting("pipco", 2);
     919 [ +  - ][ +  - ]:          5 :     doc2.add_posting("bar", 4);
     920 [ +  - ][ +  - ]:          5 :     doc2.add_posting("foo", 5);
     921                 :            : 
     922         [ +  - ]:          5 :     db.replace_document(did, doc2);
     923                 :            : 
     924         [ +  - ]:         10 :     Xapian::Document doc3 = db.get_document(did);
     925         [ +  - ]:         10 :     Xapian::TermIterator t_iter = doc3.termlist_begin();
     926 [ +  - ][ +  - ]:          5 :     TEST_EQUAL(*t_iter, "bar");
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
     927         [ +  - ]:         10 :     Xapian::PositionIterator p_iter = t_iter.positionlist_begin();
     928 [ +  - ][ -  + ]:          5 :     TEST_EQUAL(*p_iter, 4);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     929         [ +  - ]:          5 :     ++t_iter;
     930 [ +  - ][ +  - ]:          5 :     TEST_EQUAL(*t_iter, "foo");
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
     931         [ +  - ]:         10 :     Xapian::PositionIterator q_iter = t_iter.positionlist_begin();
     932 [ +  - ][ -  + ]:          5 :     TEST_EQUAL(*q_iter, 1);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     933         [ +  - ]:          5 :     ++q_iter;
     934 [ +  - ][ -  + ]:          5 :     TEST_EQUAL(*q_iter, 5);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     935         [ +  - ]:          5 :     ++t_iter;
     936 [ +  - ][ +  - ]:          5 :     TEST_EQUAL(*t_iter, "pipco");
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
     937         [ +  - ]:         10 :     Xapian::PositionIterator r_iter = t_iter.positionlist_begin();
     938 [ +  - ][ -  + ]:          5 :     TEST_EQUAL(*r_iter, 2);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     939         [ +  - ]:          5 :     ++t_iter;
     940 [ -  + ][ #  # ]:          5 :     TEST_EQUAL(t_iter, doc3.termlist_end());
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     941                 :          5 :     return true;
     942                 :            : }
     943                 :            : 
     944                 :            : // Test of new feature: WritableDatabase::replace_document accepts a docid
     945                 :            : // which doesn't yet exist as of Xapian 0.8.2.
     946                 :          5 : DEFINE_TESTCASE(replacedoc2, writable) {
     947 [ +  - ][ +  - ]:          5 :     Xapian::WritableDatabase db = get_writable_database();
     948                 :            : 
     949         [ +  - ]:         10 :     Xapian::Document doc1;
     950                 :            : 
     951 [ +  - ][ +  - ]:          5 :     doc1.add_posting("foo", 1);
     952 [ +  - ][ +  - ]:          5 :     doc1.add_posting("foo", 2);
     953 [ +  - ][ +  - ]:          5 :     doc1.add_posting("gone", 3);
     954 [ +  - ][ +  - ]:          5 :     doc1.add_posting("bar", 4);
     955 [ +  - ][ +  - ]:          5 :     doc1.add_posting("foo", 5);
     956                 :          5 :     Xapian::docid did = 31770;
     957                 :            : 
     958         [ +  - ]:          5 :     db.replace_document(did, doc1);
     959                 :            : 
     960                 :            :     // Regression tests for bug in the InMemory backend - fixed in 1.0.2.
     961 [ +  - ][ -  + ]:          5 :     TEST_EXCEPTION(Xapian::DocNotFoundError, db.get_document(1));
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ -  + ][ -  +  
          #  #  #  #  #  
          #  #  #  #  #  
             #  #  #  # ]
                 [ +  - ]
     962 [ +  - ][ +  - ]:         10 :     Xapian::PostingIterator postit = db.postlist_begin("");
     963 [ +  - ][ -  +  :          5 :     TEST(postit != db.postlist_end(""));
          #  #  #  #  #  
          #  #  #  #  #  
             #  #  #  # ]
     964 [ +  - ][ -  +  :          5 :     TEST_EQUAL(*postit, 31770);
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
                   #  # ]
     965                 :            : 
     966         [ +  - ]:         10 :     Xapian::Document doc2;
     967                 :            : 
     968 [ +  - ][ +  - ]:          5 :     doc2.add_posting("foo", 1);
     969 [ +  - ][ +  - ]:          5 :     doc2.add_posting("pipco", 2);
     970 [ +  - ][ +  - ]:          5 :     doc2.add_posting("bar", 4);
     971 [ +  - ][ +  - ]:          5 :     doc2.add_posting("foo", 5);
     972                 :            : 
     973         [ +  - ]:          5 :     db.replace_document(did, doc2);
     974 [ +  - ][ -  +  :          5 :     TEST_EQUAL(db.get_doccount(), 1);
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
                   #  # ]
     975                 :            : 
     976         [ +  - ]:         10 :     Xapian::Document doc3 = db.get_document(did);
     977         [ +  - ]:         10 :     Xapian::TermIterator t_iter = doc3.termlist_begin();
     978 [ +  - ][ +  - ]:          5 :     TEST_EQUAL(*t_iter, "bar");
           [ -  +  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
             #  #  #  #  
                      # ]
     979         [ +  - ]:         10 :     Xapian::PositionIterator p_iter = t_iter.positionlist_begin();
     980 [ +  - ][ -  +  :          5 :     TEST_EQUAL(*p_iter, 4);
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
                   #  # ]
     981         [ +  - ]:          5 :     ++t_iter;
     982 [ +  - ][ +  - ]:          5 :     TEST_EQUAL(*t_iter, "foo");
           [ -  +  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
             #  #  #  #  
                      # ]
     983         [ +  - ]:         10 :     Xapian::PositionIterator q_iter = t_iter.positionlist_begin();
     984 [ +  - ][ -  +  :          5 :     TEST_EQUAL(*q_iter, 1);
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
                   #  # ]
     985         [ +  - ]:          5 :     ++q_iter;
     986 [ +  - ][ -  +  :          5 :     TEST_EQUAL(*q_iter, 5);
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
                   #  # ]
     987         [ +  - ]:          5 :     ++t_iter;
     988 [ +  - ][ +  - ]:          5 :     TEST_EQUAL(*t_iter, "pipco");
           [ -  +  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
             #  #  #  #  
                      # ]
     989         [ +  - ]:         10 :     Xapian::PositionIterator r_iter = t_iter.positionlist_begin();
     990 [ +  - ][ -  +  :          5 :     TEST_EQUAL(*r_iter, 2);
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
                   #  # ]
     991         [ +  - ]:          5 :     ++t_iter;
     992   [ -  +  #  #  :          5 :     TEST_EQUAL(t_iter, doc3.termlist_end());
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
                #  #  # ]
     993                 :            : 
     994         [ +  - ]:          5 :     did = db.add_document(doc1);
     995   [ -  +  #  #  :          5 :     TEST_EQUAL(did, 31771);
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
                #  #  # ]
     996 [ +  - ][ -  +  :          5 :     TEST_EQUAL(db.get_doccount(), 2);
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
                   #  # ]
     997                 :            : 
     998 [ +  - ][ -  +  :          5 :     TEST_EXCEPTION(Xapian::InvalidArgumentError, db.replace_document(0, doc2));
          #  #  #  #  #  
          #  #  #  #  #  
           #  # ][ -  + ]
           [ -  +  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
           #  # ][ +  - ]
     999                 :            : 
    1000                 :          5 :     return true;
    1001                 :            : }
    1002                 :            : 
    1003                 :            : // Test replacing a document which was added in the same batch.
    1004                 :          5 : DEFINE_TESTCASE(replacedoc3, writable) {
    1005 [ +  - ][ +  - ]:          5 :     Xapian::WritableDatabase db = get_writable_database();
    1006                 :            : 
    1007         [ +  - ]:         10 :     Xapian::Document doc1;
    1008                 :            : 
    1009 [ +  - ][ +  - ]:          5 :     doc1.add_posting("foo", 1);
    1010 [ +  - ][ +  - ]:          5 :     doc1.add_posting("bar", 2);
    1011 [ +  - ][ +  - ]:          5 :     doc1.add_posting("aardvark", 3);
    1012                 :            : 
    1013         [ +  - ]:          5 :     Xapian::docid did = db.add_document(doc1);
    1014 [ -  + ][ #  # ]:          5 :     TEST_EQUAL(did, 1);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
    1015                 :            : 
    1016 [ +  - ][ +  - ]:          5 :     doc1.remove_term("bar");
    1017 [ +  - ][ +  - ]:          5 :     doc1.add_term("hello");
    1018                 :            : 
    1019         [ +  - ]:          5 :     did = db.add_document(doc1);
    1020 [ -  + ][ #  # ]:          5 :     TEST_EQUAL(did, 2);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
    1021                 :            : 
    1022 [ +  - ][ +  - ]:          5 :     doc1.add_term("world", 1);
    1023         [ +  - ]:          5 :     did = db.add_document(doc1);
    1024 [ -  + ][ #  # ]:          5 :     TEST_EQUAL(did, 3);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
    1025                 :            : 
    1026         [ +  - ]:         10 :     Xapian::Document doc2;
    1027 [ +  - ][ +  - ]:          5 :     doc2.add_term("world");
    1028         [ +  - ]:          5 :     db.replace_document(2, doc2);
    1029                 :            : 
    1030         [ +  - ]:          5 :     db.commit();
    1031                 :            : 
    1032                 :            :     // Check that the document exists (no DocNotFoundError).
    1033 [ +  - ][ +  - ]:          5 :     doc2 = db.get_document(2);
    1034                 :            : 
    1035 [ +  - ][ +  - ]:          5 :     TEST_EQUAL(db.get_termfreq("foo"), 2);
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
    1036 [ +  - ][ +  - ]:          5 :     TEST_EQUAL(db.get_termfreq("aardvark"), 2);
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
    1037 [ +  - ][ +  - ]:          5 :     TEST_EQUAL(db.get_termfreq("hello"), 1);
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
    1038 [ +  - ][ +  - ]:          5 :     TEST_EQUAL(db.get_termfreq("world"), 2);
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
    1039                 :            : 
    1040 [ +  - ][ -  + ]:          5 :     TEST_EQUAL(db.get_doclength(1), 3);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
    1041 [ +  - ][ -  + ]:          5 :     TEST_EQUAL(db.get_doclength(2), 1);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
    1042 [ +  - ][ -  + ]:          5 :     TEST_EQUAL(db.get_doclength(3), 4);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
    1043                 :            : 
    1044 [ +  - ][ -  + ]:          5 :     TEST_EQUAL(db.get_unique_terms(1), 3);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
    1045 [ +  - ][ -  + ]:          5 :     TEST_EQUAL(db.get_unique_terms(2), 1);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
    1046 [ +  - ][ -  + ]:          5 :     TEST_EQUAL(db.get_unique_terms(3), 4);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
    1047                 :            : 
    1048 [ +  - ][ +  - ]:         10 :     Xapian::PostingIterator p = db.postlist_begin("foo");
    1049 [ +  - ][ -  + ]:          5 :     TEST_NOT_EQUAL(p, db.postlist_end("foo"));
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
    1050 [ +  - ][ -  + ]:          5 :     TEST_EQUAL(*p, 1);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
    1051 [ +  - ][ -  + ]:          5 :     TEST_EQUAL(p.get_doclength(), 3);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
    1052 [ +  - ][ -  + ]:          5 :     TEST_EQUAL(p.get_unique_terms(), 3);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
    1053         [ +  - ]:          5 :     ++p;
    1054 [ +  - ][ -  + ]:          5 :     TEST_NOT_EQUAL(p, db.postlist_end("foo"));
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
    1055 [ +  - ][ -  + ]:          5 :     TEST_EQUAL(*p, 3);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
    1056 [ +  - ][ -  + ]:          5 :     TEST_EQUAL(p.get_doclength(), 4);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
    1057 [ +  - ][ -  + ]:          5 :     TEST_EQUAL(p.get_unique_terms(), 4);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
    1058         [ +  - ]:          5 :     ++p;
    1059 [ +  - ][ -  + ]:          5 :     TEST_EQUAL(p, db.postlist_end("foo"));
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
    1060                 :            : 
    1061 [ +  - ][ +  - ]:          5 :     p = db.postlist_begin("world");
                 [ +  - ]
    1062 [ +  - ][ -  + ]:          5 :     TEST_NOT_EQUAL(p, db.postlist_end("world"));
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
    1063 [ +  - ][ -  + ]:          5 :     TEST_EQUAL(*p, 2);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
    1064 [ +  - ][ -  + ]:          5 :     TEST_EQUAL(p.get_doclength(), 1);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
    1065 [ +  - ][ -  + ]:          5 :     TEST_EQUAL(p.get_unique_terms(), 1);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
    1066         [ +  - ]:          5 :     ++p;
    1067 [ +  - ][ -  + ]:          5 :     TEST_NOT_EQUAL(p, db.postlist_end("world"));
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
    1068 [ +  - ][ -  + ]:          5 :     TEST_EQUAL(*p, 3);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
    1069 [ +  - ][ -  + ]:          5 :     TEST_EQUAL(p.get_doclength(), 4);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
    1070 [ +  - ][ -  + ]:          5 :     TEST_EQUAL(p.get_unique_terms(), 4);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
    1071         [ +  - ]:          5 :     ++p;
    1072 [ +  - ][ -  + ]:          5 :     TEST_EQUAL(p, db.postlist_end("world"));
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
    1073                 :            : 
    1074                 :          5 :     return true;
    1075                 :            : }
    1076                 :            : 
    1077                 :            : // Test replacing a document which was deleted in the same batch.
    1078                 :          5 : DEFINE_TESTCASE(replacedoc4, writable) {
    1079 [ +  - ][ +  - ]:          5 :     Xapian::WritableDatabase db = get_writable_database();
    1080                 :            : 
    1081         [ +  - ]:         10 :     Xapian::Document doc1;
    1082                 :            : 
    1083 [ +  - ][ +  - ]:          5 :     doc1.add_posting("foo", 1);
    1084 [ +  - ][ +  - ]:          5 :     doc1.add_posting("bar", 2);
    1085 [ +  - ][ +  - ]:          5 :     doc1.add_posting("aardvark", 3);
    1086                 :            : 
    1087         [ +  - ]:          5 :     Xapian::docid did = db.add_document(doc1);
    1088 [ -  + ][ #  # ]:          5 :     TEST_EQUAL(did, 1);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
    1089                 :            : 
    1090 [ +  - ][ +  - ]:          5 :     doc1.remove_term("bar");
    1091 [ +  - ][ +  - ]:          5 :     doc1.add_term("hello");
    1092                 :            : 
    1093         [ +  - ]:          5 :     did = db.add_document(doc1);
    1094 [ -  + ][ #  # ]:          5 :     TEST_EQUAL(did, 2);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
    1095                 :            : 
    1096 [ +  - ][ +  - ]:          5 :     doc1.add_term("world", 1);
    1097         [ +  - ]:          5 :     did = db.add_document(doc1);
    1098 [ -  + ][ #  # ]:          5 :     TEST_EQUAL(did, 3);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
    1099                 :            : 
    1100         [ +  - ]:          5 :     db.delete_document(2);
    1101                 :            : 
    1102         [ +  - ]:         10 :     Xapian::Document doc2;
    1103 [ +  - ][ +  - ]:          5 :     doc2.add_term("world");
    1104         [ +  - ]:          5 :     db.replace_document(2, doc2);
    1105                 :            : 
    1106         [ +  - ]:          5 :     db.commit();
    1107                 :            : 
    1108                 :            :     // Check that the document exists (no DocNotFoundError).
    1109 [ +  - ][ +  - ]:          5 :     doc2 = db.get_document(2);
    1110                 :            : 
    1111 [ +  - ][ +  - ]:          5 :     TEST_EQUAL(db.get_termfreq("foo"), 2);
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
    1112 [ +  - ][ +  - ]:          5 :     TEST_EQUAL(db.get_termfreq("aardvark"), 2);
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
    1113 [ +  - ][ +  - ]:          5 :     TEST_EQUAL(db.get_termfreq("hello"), 1);
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
    1114 [ +  - ][ +  - ]:          5 :     TEST_EQUAL(db.get_termfreq("world"), 2);
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
    1115                 :            : 
    1116 [ +  - ][ +  - ]:         10 :     Xapian::PostingIterator p = db.postlist_begin("foo");
    1117 [ +  - ][ -  + ]:          5 :     TEST_NOT_EQUAL(p, db.postlist_end("foo"));
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
    1118 [ +  - ][ -  + ]:          5 :     TEST_EQUAL(*p, 1);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
    1119         [ +  - ]:          5 :     ++p;
    1120 [ +  - ][ -  + ]:          5 :     TEST_NOT_EQUAL(p, db.postlist_end("foo"));
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
    1121 [ +  - ][ -  + ]:          5 :     TEST_EQUAL(*p, 3);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
    1122         [ +  - ]:          5 :     ++p;
    1123 [ +  - ][ -  + ]:          5 :     TEST_EQUAL(p, db.postlist_end("foo"));
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
    1124                 :            : 
    1125 [ +  - ][ +  - ]:          5 :     p = db.postlist_begin("world");
                 [ +  - ]
    1126 [ +  - ][ -  + ]:          5 :     TEST_NOT_EQUAL(p, db.postlist_end("world"));
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
    1127 [ +  - ][ -  + ]:          5 :     TEST_EQUAL(*p, 2);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
    1128         [ +  - ]:          5 :     ++p;
    1129 [ +  - ][ -  + ]:          5 :     TEST_NOT_EQUAL(p, db.postlist_end("world"));
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
    1130 [ +  - ][ -  + ]:          5 :     TEST_EQUAL(*p, 3);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
    1131         [ +  - ]:          5 :     ++p;
    1132 [ +  - ][ -  + ]:          5 :     TEST_EQUAL(p, db.postlist_end("world"));
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
    1133                 :            : 
    1134                 :          5 :     return true;
    1135                 :            : }
    1136                 :            : 
    1137                 :            : // Test replacing a document with itself without modifying postings.
    1138                 :            : // Regression test for bug in 0.9.9 and earlier - there flint and quartz
    1139                 :            : // lost all positional information for the document when you did this.
    1140                 :          5 : DEFINE_TESTCASE(replacedoc5, writable) {
    1141 [ +  - ][ +  - ]:          5 :     Xapian::WritableDatabase db = get_writable_database();
    1142                 :            : 
    1143                 :            :     {
    1144         [ +  - ]:          5 :         Xapian::Document doc;
    1145 [ +  - ][ +  - ]:          5 :         doc.add_posting("hello", 1);
    1146 [ +  - ][ +  - ]:          5 :         doc.add_posting("world", 2);
    1147                 :            : 
    1148         [ +  - ]:          5 :         Xapian::docid did = db.add_document(doc);
    1149 [ -  + ][ #  # ]:          5 :         TEST_EQUAL(did, 1);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
    1150         [ +  - ]:          5 :         db.commit();
    1151                 :            :     }
    1152                 :            : 
    1153                 :            :     {
    1154         [ +  - ]:          5 :         Xapian::Document doc = db.get_document(1);
    1155 [ +  - ][ -  + ]:          5 :         TEST(db.has_positions());
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
    1156 [ +  - ][ +  - ]:          5 :         TEST(db.positionlist_begin(1, "hello") != db.positionlist_end(1, "hello"));
         [ +  - ][ -  + ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
    1157 [ +  - ][ +  - ]:          5 :         TEST(db.positionlist_begin(1, "world") != db.positionlist_end(1, "world"));
         [ +  - ][ -  + ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
    1158         [ +  - ]:          5 :         db.replace_document(1, doc);
    1159         [ +  - ]:          5 :         db.commit();
    1160                 :            : 
    1161 [ +  - ][ -  + ]:          5 :         TEST(db.has_positions());
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
    1162 [ +  - ][ +  - ]:          5 :         TEST(db.positionlist_begin(1, "hello") != db.positionlist_end(1, "hello"));
         [ +  - ][ -  + ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
    1163 [ +  - ][ +  - ]:          5 :         TEST(db.positionlist_begin(1, "world") != db.positionlist_end(1, "world"));
         [ +  - ][ -  + ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
    1164                 :            :     }
    1165                 :            : 
    1166                 :            :     // The backends now spot simple cases of replacing the same document and
    1167                 :            :     // don't do needless work.  Force them to actually do the replacement to
    1168                 :            :     // make sure that case works.
    1169                 :            : 
    1170                 :            :     {
    1171         [ +  - ]:          5 :         Xapian::Document doc;
    1172 [ +  - ][ +  - ]:          5 :         doc.add_term("Q2");
    1173         [ +  - ]:          5 :         db.add_document(doc);
    1174         [ +  - ]:          5 :         db.commit();
    1175                 :            :     }
    1176                 :            : 
    1177                 :            :     {
    1178         [ +  - ]:          5 :         Xapian::Document doc = db.get_document(1);
    1179 [ +  - ][ -  + ]:          5 :         TEST(db.has_positions());
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
    1180 [ +  - ][ +  - ]:          5 :         TEST(db.positionlist_begin(1, "hello") != db.positionlist_end(1, "hello"));
         [ +  - ][ -  + ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
    1181 [ +  - ][ +  - ]:          5 :         TEST(db.positionlist_begin(1, "world") != db.positionlist_end(1, "world"));
         [ +  - ][ -  + ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
    1182         [ +  - ]:          5 :         (void)db.get_document(2);
    1183         [ +  - ]:          5 :         db.replace_document(1, doc);
    1184         [ +  - ]:          5 :         db.commit();
    1185                 :            : 
    1186 [ +  - ][ -  + ]:          5 :         TEST(db.has_positions());
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
    1187 [ +  - ][ +  - ]:          5 :         TEST(db.positionlist_begin(1, "hello") != db.positionlist_end(1, "hello"));
         [ +  - ][ -  + ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
    1188 [ +  - ][ +  - ]:          5 :         TEST(db.positionlist_begin(1, "world") != db.positionlist_end(1, "world"));
         [ +  - ][ -  + ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
    1189                 :            :     }
    1190                 :            : 
    1191                 :          5 :     return true;
    1192                 :            : }
    1193                 :            : 
    1194                 :            : // Test replacing a document while adding values, without changing anything
    1195                 :            : // else.  Regression test for a bug introduced while implementing lazy update,
    1196                 :            : // and also covers a few other code paths.
    1197                 :          5 : DEFINE_TESTCASE(replacedoc6, writable) {
    1198 [ +  - ][ +  - ]:          5 :     Xapian::WritableDatabase db = get_writable_database();
    1199                 :            : 
    1200         [ +  - ]:         10 :     Xapian::Document doc;
    1201         [ +  - ]:          5 :     Xapian::docid did = db.add_document(doc);
    1202 [ -  + ][ #  # ]:          5 :     TEST_EQUAL(did, 1);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
    1203         [ +  - ]:          5 :     db.commit();
    1204                 :            : 
    1205                 :            :     // Add document
    1206 [ +  - ][ +  - ]:          5 :     doc = db.get_document(1);
    1207 [ +  - ][ +  - ]:          5 :     TEST_EQUAL(doc.get_value(1), "");
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
    1208 [ +  - ][ +  - ]:          5 :     TEST_EQUAL(doc.get_value(2), "");
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
    1209 [ +  - ][ +  - ]:          5 :     doc.add_value(1, "banana1");
    1210         [ +  - ]:          5 :     db.replace_document(1, doc);
    1211                 :            : 
    1212 [ +  - ][ +  - ]:          5 :     doc = db.get_document(1);
    1213 [ +  - ][ +  - ]:          5 :     TEST_EQUAL(doc.get_value(1), "banana1");
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
    1214 [ +  - ][ +  - ]:          5 :     TEST_EQUAL(doc.get_value(2), "");
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
    1215         [ +  - ]:          5 :     db.commit();
    1216                 :            : 
    1217 [ +  - ][ +  - ]:          5 :     doc = db.get_document(1);
    1218 [ +  - ][ +  - ]:          5 :     TEST_EQUAL(doc.get_value(1), "banana1");
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
    1219 [ +  - ][ +  - ]:          5 :     TEST_EQUAL(doc.get_value(2), "");
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
    1220 [ +  - ][ +  - ]:          5 :     doc.add_value(2, "banana2");
    1221         [ +  - ]:          5 :     db.replace_document(1, doc);
    1222                 :            : 
    1223 [ +  - ][ +  - ]:          5 :     TEST_EQUAL(doc.get_value(1), "banana1");
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
    1224 [ +  - ][ +  - ]:          5 :     TEST_EQUAL(doc.get_value(2), "banana2");
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
    1225         [ +  - ]:          5 :     db.commit();
    1226                 :            : 
    1227 [ +  - ][ +  - ]:          5 :     doc = db.get_document(1);
    1228 [ +  - ][ +  - ]:          5 :     TEST_EQUAL(doc.get_value(1), "banana1");
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
    1229 [ +  - ][ +  - ]:          5 :     TEST_EQUAL(doc.get_value(2), "banana2");
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
    1230                 :            : 
    1231                 :          5 :     return true;
    1232                 :            : }
    1233                 :            : 
    1234                 :            : // Test of new feature: WritableDatabase::replace_document and delete_document
    1235                 :            : // can take a unique termname instead of a document id as of Xapian 0.8.2.
    1236                 :          5 : DEFINE_TESTCASE(uniqueterm1, writable) {
    1237 [ +  - ][ +  - ]:          5 :     Xapian::WritableDatabase db = get_writable_database();
    1238                 :            : 
    1239         [ +  + ]:        105 :     for (int n = 1; n <= 20; ++n) {
    1240         [ +  - ]:        100 :         Xapian::Document doc;
    1241 [ +  - ][ +  - ]:        200 :         string uterm = "U" + str(n % 16);
    1242         [ +  - ]:        100 :         doc.add_term(uterm);
    1243 [ +  - ][ +  - ]:        100 :         doc.add_term(str(n));
    1244 [ +  - ][ +  - ]:        100 :         doc.add_term(str(n ^ 9));
    1245 [ +  - ][ +  - ]:        100 :         doc.add_term("all");
    1246 [ +  - ][ +  - ]:        100 :         doc.set_data("pass1");
    1247         [ +  - ]:        100 :         db.add_document(doc);
    1248                 :        100 :     }
    1249                 :            : 
    1250 [ +  - ][ -  + ]:          5 :     TEST_EQUAL(db.get_doccount(), 20);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
    1251                 :            : 
    1252                 :            :     static const Xapian::doccount sizes[20] = {
    1253                 :            :         19, 17, 16, 15,
    1254                 :            :         15, 15, 15, 15,
    1255                 :            :         15, 15, 15, 15,
    1256                 :            :         15, 15, 15, 15,
    1257                 :            :         15, 15, 15, 15
    1258                 :            :     };
    1259         [ +  + ]:        105 :     for (int n = 1; n <= 20; ++n) {
    1260 [ +  - ][ +  - ]:        100 :         string uterm = "U" + str(n % 16);
    1261 [ +  - ][ +  + ]:        100 :         if (uterm == "U2") {
    1262         [ +  - ]:         10 :             db.delete_document(uterm);
    1263                 :            :         } else {
    1264         [ +  - ]:         90 :             Xapian::Document doc;
    1265         [ +  - ]:         90 :             doc.add_term(uterm);
    1266 [ +  - ][ +  - ]:         90 :             doc.add_term(str(n));
    1267 [ +  - ][ +  - ]:         90 :             doc.add_term(str(n ^ 9));
    1268 [ +  - ][ +  - ]:         90 :             doc.add_term("all");
    1269 [ +  - ][ +  - ]:         90 :             doc.set_data("pass2");
    1270         [ +  - ]:         90 :             db.replace_document(uterm, doc);
    1271                 :            :         }
    1272 [ +  - ][ -  + ]:        100 :         TEST_EQUAL(db.get_doccount(), sizes[n - 1]);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
    1273                 :        100 :     }
    1274                 :            : 
    1275         [ +  - ]:         10 :     string uterm = "U571";
    1276         [ +  - ]:         10 :     Xapian::Document doc;
    1277         [ +  - ]:          5 :     doc.add_term(uterm);
    1278 [ +  - ][ +  - ]:          5 :     doc.set_data("pass3");
    1279         [ +  - ]:          5 :     db.replace_document(uterm, doc);
    1280                 :            : 
    1281 [ +  - ][ -  + ]:          5 :     TEST_EQUAL(db.get_doccount(), 16);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
    1282                 :            : 
    1283 [ +  - ][ +  - ]:          5 :     db.delete_document("U2");
    1284                 :            : 
    1285 [ +  - ][ -  + ]:          5 :     TEST_EQUAL(db.get_doccount(), 16);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
    1286                 :            : 
    1287                 :          5 :     return true;
    1288                 :            : }
    1289                 :            : 
    1290                 :            : // tests all document postlists
    1291                 :          5 : DEFINE_TESTCASE(allpostlist2, writable) {
    1292 [ +  - ][ +  - ]:          5 :     Xapian::WritableDatabase db(get_writable_database("apitest_manydocs"));
    1293 [ +  - ][ +  - ]:         10 :     Xapian::PostingIterator i = db.postlist_begin("");
    1294                 :          5 :     unsigned int j = 1;
    1295 [ +  - ][ +  + ]:       2565 :     while (i != db.postlist_end("")) {
    1296 [ +  - ][ -  + ]:       2560 :         TEST_EQUAL(*i, j);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
    1297         [ +  - ]:       2560 :         i++;
    1298                 :       2560 :         j++;
    1299                 :            :     }
    1300 [ -  + ][ #  # ]:          5 :     TEST_EQUAL(j, 513);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
    1301                 :            : 
    1302         [ +  - ]:          5 :     db.delete_document(1);
    1303         [ +  - ]:          5 :     db.delete_document(50);
    1304         [ +  - ]:          5 :     db.delete_document(512);
    1305                 :            : 
    1306 [ +  - ][ +  - ]:          5 :     i = db.postlist_begin("");
                 [ +  - ]
    1307                 :          5 :     j = 2;
    1308 [ +  - ][ +  + ]:       2550 :     while (i != db.postlist_end("")) {
    1309 [ +  - ][ -  + ]:       2545 :         TEST_EQUAL(*i, j);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
    1310         [ +  - ]:       2545 :         i++;
    1311                 :       2545 :         j++;
    1312         [ +  + ]:       2545 :         if (j == 50) j++;
    1313                 :            :     }
    1314 [ -  + ][ #  # ]:          5 :     TEST_EQUAL(j, 512);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
    1315                 :            : 
    1316 [ +  - ][ +  - ]:          5 :     i = db.postlist_begin("");
                 [ +  - ]
    1317                 :          5 :     j = 2;
    1318 [ +  - ][ +  + ]:       2500 :     while (i != db.postlist_end("")) {
    1319 [ +  - ][ -  + ]:       2495 :         TEST_EQUAL(*i, j);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
    1320         [ +  - ]:       2495 :         i++;
    1321                 :       2495 :         j++;
    1322         [ +  + ]:       2495 :         if (j == 40) {
    1323                 :          5 :             j += 10;
    1324         [ +  - ]:          5 :             i.skip_to(j);
    1325                 :          5 :             j++;
    1326                 :            :         }
    1327                 :            :     }
    1328 [ -  + ][ #  # ]:          5 :     TEST_EQUAL(j, 512);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
    1329                 :            : 
    1330                 :          5 :     return true;
    1331                 :            : }
    1332                 :            : 
    1333                 :         35 : static void test_emptyterm2_helper(Xapian::WritableDatabase & db)
    1334                 :            : {
    1335                 :            :     // Don't bother with postlist_begin() because allpostlist tests cover that.
    1336 [ +  - ][ +  - ]:         35 :     TEST_EXCEPTION(Xapian::InvalidArgumentError, db.positionlist_begin(1, ""));
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ -  + ]
           [ -  +  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
                   #  # ]
    1337 [ +  - ][ -  +  :         35 :     TEST_EQUAL(db.get_doccount(), db.get_termfreq(""));
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
                #  +  - ]
    1338 [ +  - ][ +  - ]:         35 :     TEST_EQUAL(db.get_doccount() != 0, db.term_exists(""));
           [ -  +  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
             #  #  #  # ]
    1339 [ +  - ][ +  - ]:         35 :     TEST_EQUAL(db.get_doccount(), db.get_collection_freq(""));
           [ -  +  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
             #  #  #  # ]
    1340                 :         35 : }
    1341                 :            : 
    1342                 :            : // tests results of passing an empty term to various methods
    1343                 :            : // equivalent of emptyterm1 for a writable database
    1344                 :          5 : DEFINE_TESTCASE(emptyterm2, writable) {
    1345                 :            :     {
    1346 [ +  - ][ +  - ]:          5 :         Xapian::WritableDatabase db(get_writable_database("apitest_manydocs"));
    1347 [ +  - ][ -  + ]:          5 :         TEST_EQUAL(db.get_doccount(), 512);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
    1348         [ +  - ]:          5 :         test_emptyterm2_helper(db);
    1349         [ +  - ]:          5 :         db.delete_document(1);
    1350 [ +  - ][ -  + ]:          5 :         TEST_EQUAL(db.get_doccount(), 511);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
    1351         [ +  - ]:          5 :         test_emptyterm2_helper(db);
    1352         [ +  - ]:          5 :         db.delete_document(50);
    1353 [ +  - ][ -  + ]:          5 :         TEST_EQUAL(db.get_doccount(), 510);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
    1354         [ +  - ]:          5 :         test_emptyterm2_helper(db);
    1355         [ +  - ]:          5 :         db.delete_document(512);
    1356 [ +  - ][ -  + ]:          5 :         TEST_EQUAL(db.get_doccount(), 509);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
    1357         [ +  - ]:          5 :         test_emptyterm2_helper(db);
    1358                 :            :     }
    1359                 :            : 
    1360                 :            :     {
    1361 [ +  - ][ +  - ]:          5 :         Xapian::WritableDatabase db(get_writable_database("apitest_onedoc"));
    1362 [ +  - ][ -  + ]:          5 :         TEST_EQUAL(db.get_doccount(), 1);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
    1363         [ +  - ]:          5 :         test_emptyterm2_helper(db);
    1364         [ +  - ]:          5 :         db.delete_document(1);
    1365 [ +  - ][ -  + ]:          5 :         TEST_EQUAL(db.get_doccount(), 0);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
    1366         [ +  - ]:          5 :         test_emptyterm2_helper(db);
    1367                 :            :     }
    1368                 :            : 
    1369                 :            :     {
    1370 [ +  - ][ +  - ]:          5 :         Xapian::WritableDatabase db(get_writable_database());
    1371 [ +  - ][ -  + ]:          5 :         TEST_EQUAL(db.get_doccount(), 0);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
    1372         [ +  - ]:          5 :         test_emptyterm2_helper(db);
    1373                 :            :     }
    1374                 :            : 
    1375                 :          5 :     return true;
    1376                 :            : }
    1377                 :            : 
    1378                 :            : // Check that PHRASE/NEAR becomes AND if there's no positional info in the
    1379                 :            : // database.
    1380                 :          5 : DEFINE_TESTCASE(phraseorneartoand1, writable) {
    1381 [ +  - ][ +  - ]:          5 :     Xapian::WritableDatabase db = get_writable_database();
    1382                 :            : 
    1383         [ +  + ]:        105 :     for (int n = 1; n <= 20; ++n) {
    1384         [ +  - ]:        100 :         Xapian::Document doc;
    1385 [ +  - ][ +  - ]:        100 :         doc.add_term(str(n));
    1386 [ +  - ][ +  - ]:        100 :         doc.add_term(str(n ^ 9));
    1387 [ +  - ][ +  - ]:        100 :         doc.add_term("all");
    1388 [ +  - ][ +  - ]:        100 :         doc.set_data("pass1");
    1389         [ +  - ]:        100 :         db.add_document(doc);
    1390                 :        100 :     }
    1391         [ +  - ]:          5 :     db.commit();
    1392                 :            : 
    1393         [ +  - ]:         10 :     Xapian::Enquire enquire(db);
    1394         [ +  - ]:         10 :     Xapian::MSet mymset;
    1395                 :            : 
    1396                 :            :     static const char * const q1[] = { "all", "1" };
    1397 [ +  - ][ +  - ]:          5 :     enquire.set_query(Xapian::Query(Xapian::Query::OP_PHRASE, q1, q1 + 2));
    1398 [ +  - ][ +  - ]:          5 :     mymset = enquire.get_mset(0, 10);
    1399 [ +  - ][ -  + ]:          5 :     TEST_EQUAL(2, mymset.size());
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
    1400                 :            : 
    1401 [ +  - ][ +  - ]:          5 :     enquire.set_query(Xapian::Query(Xapian::Query::OP_NEAR, q1, q1 + 2));
    1402 [ +  - ][ +  - ]:          5 :     mymset = enquire.get_mset(0, 10);
    1403 [ +  - ][ -  + ]:          5 :     TEST_EQUAL(2, mymset.size());
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
    1404                 :            : 
    1405                 :            :     static const char * const q2[] = { "1", "2" };
    1406 [ +  - ][ +  - ]:          5 :     enquire.set_query(Xapian::Query(Xapian::Query::OP_PHRASE, q2, q2 + 2));
    1407 [ +  - ][ +  - ]:          5 :     mymset = enquire.get_mset(0, 10);
    1408 [ +  - ][ -  + ]:          5 :     TEST_EQUAL(0, mymset.size());
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]