LCOV - code coverage report
Current view: top level - tests - api_serialise.cc (source / functions) Hit Total Coverage
Test: Test Coverage for xapian-core 954b5873a738 Lines: 284 301 94.4 %
Date: 2019-06-30 05:20:33 Functions: 30 45 66.7 %
Branches: 431 3006 14.3 %

           Branch data     Line data    Source code
       1                 :            : /** @file api_serialise.cc
       2                 :            :  * @brief Tests of serialisation functionality.
       3                 :            :  */
       4                 :            : /* Copyright 2009 Lemur Consulting Ltd
       5                 :            :  * Copyright 2009,2011,2012,2013 Olly Betts
       6                 :            :  *
       7                 :            :  * This program is free software; you can redistribute it and/or modify
       8                 :            :  * it under the terms of the GNU General Public License as published by
       9                 :            :  * the Free Software Foundation; either version 2 of the License, or
      10                 :            :  * (at your option) any later version.
      11                 :            :  *
      12                 :            :  * This program is distributed in the hope that it will be useful,
      13                 :            :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
      14                 :            :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      15                 :            :  * GNU General Public License for more details.
      16                 :            :  *
      17                 :            :  * You should have received a copy of the GNU General Public License
      18                 :            :  * along with this program; if not, write to the Free Software
      19                 :            :  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
      20                 :            :  */
      21                 :            : 
      22                 :            : #include <config.h>
      23                 :            : 
      24                 :            : #include "api_serialise.h"
      25                 :            : 
      26                 :            : #include <xapian.h>
      27                 :            : 
      28                 :            : #include <exception>
      29                 :            : #include <stdexcept>
      30                 :            : 
      31                 :            : #include "apitest.h"
      32                 :            : #include "testutils.h"
      33                 :            : 
      34                 :            : using namespace std;
      35                 :            : 
      36                 :            : // Test for serialising a document
      37                 :          1 : DEFINE_TESTCASE(serialise_document1, !backend) {
      38         [ +  - ]:          1 :     Xapian::Document doc;
      39                 :            : 
      40                 :            :     // Test serialising and unserialising an empty document.
      41 [ +  - ][ +  - ]:          2 :     Xapian::Document doc1 = Xapian::Document::unserialise(doc.serialise());
      42 [ +  - ][ -  + ]:          1 :     TEST_EQUAL(doc1.termlist_count(), 0);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
      43 [ +  - ][ -  + ]:          1 :     TEST_EQUAL(doc1.termlist_begin(), doc1.termlist_end());
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
      44 [ +  - ][ -  + ]:          1 :     TEST_EQUAL(doc1.values_count(), 0);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
      45 [ +  - ][ -  + ]:          1 :     TEST_EQUAL(doc1.values_begin(), doc1.values_end());
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
      46 [ +  - ][ +  - ]:          1 :     TEST_EQUAL(doc1.get_data(), "");
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
      47                 :            : 
      48                 :            :     // Test serialising a document with things in.
      49 [ +  - ][ +  - ]:          1 :     doc.add_term("foo", 2);
      50 [ +  - ][ +  - ]:          1 :     doc.add_posting("foo", 10);
      51 [ +  - ][ +  - ]:          1 :     doc.add_value(1, "bar");
      52 [ +  - ][ +  - ]:          1 :     doc.set_data("baz");
      53                 :            : 
      54 [ +  - ][ +  - ]:          2 :     Xapian::Document doc2 = Xapian::Document::unserialise(doc.serialise());
      55                 :            : 
      56 [ +  - ][ +  - ]:          1 :     TEST_EQUAL(doc.termlist_count(), doc2.termlist_count());
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
      57 [ +  - ][ -  + ]:          1 :     TEST_EQUAL(doc.termlist_count(), 1);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
      58                 :          2 :     Xapian::TermIterator i;
      59                 :          2 :     Xapian::PositionIterator j;
      60                 :          2 :     Xapian::ValueIterator k;
      61                 :            : 
      62 [ +  - ][ +  - ]:          1 :     i = doc.termlist_begin();
      63 [ -  + ][ #  # ]:          1 :     TEST_NOT_EQUAL(i, doc.termlist_end());
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
      64 [ +  - ][ -  + ]:          1 :     TEST_EQUAL(i.get_wdf(), 3);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
      65 [ +  - ][ +  - ]:          1 :     TEST_EQUAL(*i, "foo");
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
      66 [ +  - ][ -  + ]:          1 :     TEST_EQUAL(i.positionlist_count(), 1);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
      67 [ +  - ][ +  - ]:          1 :     j = i.positionlist_begin();
      68 [ -  + ][ #  # ]:          1 :     TEST_NOT_EQUAL(j, i.positionlist_end());
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
      69 [ +  - ][ -  + ]:          1 :     TEST_EQUAL(*j, 10);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
      70         [ +  - ]:          1 :     ++j;
      71 [ -  + ][ #  # ]:          1 :     TEST_EQUAL(j, i.positionlist_end());
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
      72         [ +  - ]:          1 :     ++i;
      73 [ -  + ][ #  # ]:          1 :     TEST_EQUAL(i, doc.termlist_end());
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
      74                 :            : 
      75 [ +  - ][ -  + ]:          1 :     TEST_EQUAL(doc.values_count(), 1);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
      76 [ +  - ][ +  - ]:          1 :     k = doc.values_begin();
      77 [ -  + ][ #  # ]:          1 :     TEST_NOT_EQUAL(k, doc.values_end());
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
      78 [ +  - ][ -  + ]:          1 :     TEST_EQUAL(k.get_valueno(), 1);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
      79 [ +  - ][ +  - ]:          1 :     TEST_EQUAL(*k, "bar");
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
      80         [ +  - ]:          1 :     ++k;
      81 [ -  + ][ #  # ]:          1 :     TEST_EQUAL(k, doc.values_end());
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
      82                 :            : 
      83 [ +  - ][ +  - ]:          1 :     TEST_EQUAL(doc.get_data(), "baz");
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
      84                 :            : 
      85 [ +  - ][ +  - ]:          1 :     i = doc2.termlist_begin();
      86 [ -  + ][ #  # ]:          1 :     TEST_NOT_EQUAL(i, doc2.termlist_end());
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
      87 [ +  - ][ -  + ]:          1 :     TEST_EQUAL(i.get_wdf(), 3);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
      88 [ +  - ][ +  - ]:          1 :     TEST_EQUAL(*i, "foo");
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
      89 [ +  - ][ -  + ]:          1 :     TEST_EQUAL(i.positionlist_count(), 1);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
      90 [ +  - ][ +  - ]:          1 :     j = i.positionlist_begin();
      91 [ -  + ][ #  # ]:          1 :     TEST_NOT_EQUAL(j, i.positionlist_end());
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
      92 [ +  - ][ -  + ]:          1 :     TEST_EQUAL(*j, 10);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
      93         [ +  - ]:          1 :     ++j;
      94 [ -  + ][ #  # ]:          1 :     TEST_EQUAL(j, i.positionlist_end());
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
      95         [ +  - ]:          1 :     ++i;
      96 [ -  + ][ #  # ]:          1 :     TEST_EQUAL(i, doc2.termlist_end());
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
      97                 :            : 
      98 [ +  - ][ -  + ]:          1 :     TEST_EQUAL(doc2.values_count(), 1);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
      99 [ +  - ][ +  - ]:          1 :     k = doc2.values_begin();
     100 [ -  + ][ #  # ]:          1 :     TEST_NOT_EQUAL(k, doc2.values_end());
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     101 [ +  - ][ -  + ]:          1 :     TEST_EQUAL(k.get_valueno(), 1);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     102 [ +  - ][ +  - ]:          1 :     TEST_EQUAL(*k, "bar");
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
     103         [ +  - ]:          1 :     ++k;
     104 [ -  + ][ #  # ]:          1 :     TEST_EQUAL(k, doc2.values_end());
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     105                 :            : 
     106 [ +  - ][ +  - ]:          1 :     TEST_EQUAL(doc2.get_data(), "baz");
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
     107                 :            : 
     108                 :          1 :     return true;
     109                 :            : }
     110                 :            : 
     111                 :            : // Test for serialising a document obtained from a database.
     112                 :          5 : DEFINE_TESTCASE(serialise_document2, writable) {
     113         [ +  - ]:          5 :     Xapian::Document origdoc;
     114 [ +  - ][ +  - ]:          5 :     origdoc.add_term("foo", 2);
     115 [ +  - ][ +  - ]:          5 :     origdoc.add_posting("foo", 10);
     116 [ +  - ][ +  - ]:          5 :     origdoc.add_value(1, "bar");
     117 [ +  - ][ +  - ]:          5 :     origdoc.set_data("baz");
     118 [ +  - ][ +  - ]:         10 :     Xapian::WritableDatabase db = get_writable_database();
     119         [ +  - ]:          5 :     db.add_document(origdoc);
     120                 :            : 
     121         [ +  - ]:         10 :     Xapian::Document doc = db.get_document(1);
     122                 :            : 
     123 [ +  - ][ +  - ]:         10 :     Xapian::Document doc2 = Xapian::Document::unserialise(doc.serialise());
     124                 :            : 
     125 [ +  - ][ +  - ]:          5 :     TEST_EQUAL(doc.termlist_count(), doc2.termlist_count());
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     126 [ +  - ][ -  + ]:          5 :     TEST_EQUAL(doc.termlist_count(), 1);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     127                 :         10 :     Xapian::TermIterator i;
     128                 :         10 :     Xapian::PositionIterator j;
     129                 :         10 :     Xapian::ValueIterator k;
     130                 :            : 
     131 [ +  - ][ +  - ]:          5 :     i = doc.termlist_begin();
     132 [ -  + ][ #  # ]:          5 :     TEST_NOT_EQUAL(i, doc.termlist_end());
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     133 [ +  - ][ -  + ]:          5 :     TEST_EQUAL(i.get_wdf(), 3);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     134 [ +  - ][ +  - ]:          5 :     TEST_EQUAL(*i, "foo");
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
     135 [ +  - ][ -  + ]:          5 :     TEST_EQUAL(i.positionlist_count(), 1);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     136 [ +  - ][ +  - ]:          5 :     j = i.positionlist_begin();
     137 [ -  + ][ #  # ]:          5 :     TEST_NOT_EQUAL(j, i.positionlist_end());
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     138 [ +  - ][ -  + ]:          5 :     TEST_EQUAL(*j, 10);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     139         [ +  - ]:          5 :     ++j;
     140 [ -  + ][ #  # ]:          5 :     TEST_EQUAL(j, i.positionlist_end());
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     141         [ +  - ]:          5 :     ++i;
     142 [ -  + ][ #  # ]:          5 :     TEST_EQUAL(i, doc.termlist_end());
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     143                 :            : 
     144 [ +  - ][ -  + ]:          5 :     TEST_EQUAL(doc.values_count(), 1);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     145 [ +  - ][ +  - ]:          5 :     k = doc.values_begin();
     146 [ -  + ][ #  # ]:          5 :     TEST_NOT_EQUAL(k, doc.values_end());
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     147 [ +  - ][ -  + ]:          5 :     TEST_EQUAL(k.get_valueno(), 1);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     148 [ +  - ][ +  - ]:          5 :     TEST_EQUAL(*k, "bar");
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
     149         [ +  - ]:          5 :     ++k;
     150 [ -  + ][ #  # ]:          5 :     TEST_EQUAL(k, doc.values_end());
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     151                 :            : 
     152 [ +  - ][ +  - ]:          5 :     TEST_EQUAL(doc.get_data(), "baz");
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
     153                 :            : 
     154 [ +  - ][ +  - ]:          5 :     i = doc2.termlist_begin();
     155 [ -  + ][ #  # ]:          5 :     TEST_NOT_EQUAL(i, doc2.termlist_end());
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     156 [ +  - ][ -  + ]:          5 :     TEST_EQUAL(i.get_wdf(), 3);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     157 [ +  - ][ +  - ]:          5 :     TEST_EQUAL(*i, "foo");
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
     158 [ +  - ][ -  + ]:          5 :     TEST_EQUAL(i.positionlist_count(), 1);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     159 [ +  - ][ +  - ]:          5 :     j = i.positionlist_begin();
     160 [ -  + ][ #  # ]:          5 :     TEST_NOT_EQUAL(j, i.positionlist_end());
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     161 [ +  - ][ -  + ]:          5 :     TEST_EQUAL(*j, 10);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     162         [ +  - ]:          5 :     ++j;
     163 [ -  + ][ #  # ]:          5 :     TEST_EQUAL(j, i.positionlist_end());
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     164         [ +  - ]:          5 :     ++i;
     165 [ -  + ][ #  # ]:          5 :     TEST_EQUAL(i, doc2.termlist_end());
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     166                 :            : 
     167 [ +  - ][ -  + ]:          5 :     TEST_EQUAL(doc2.values_count(), 1);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     168 [ +  - ][ +  - ]:          5 :     k = doc2.values_begin();
     169 [ -  + ][ #  # ]:          5 :     TEST_NOT_EQUAL(k, doc2.values_end());
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     170 [ +  - ][ -  + ]:          5 :     TEST_EQUAL(k.get_valueno(), 1);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     171 [ +  - ][ +  - ]:          5 :     TEST_EQUAL(*k, "bar");
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
     172         [ +  - ]:          5 :     ++k;
     173 [ -  + ][ #  # ]:          5 :     TEST_EQUAL(k, doc2.values_end());
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     174                 :            : 
     175 [ +  - ][ +  - ]:          5 :     TEST_EQUAL(doc2.get_data(), "baz");
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
     176                 :            : 
     177                 :          5 :     return true;
     178                 :            : }
     179                 :            : 
     180                 :            : // Test for serialising a query
     181                 :          1 : DEFINE_TESTCASE(serialise_query1, !backend) {
     182                 :          1 :     Xapian::Query q;
     183 [ +  - ][ +  - ]:          2 :     Xapian::Query q2 = Xapian::Query::unserialise(q.serialise());
                 [ +  - ]
     184 [ +  - ][ +  - ]:          1 :     TEST_EQUAL(q.get_description(), q2.get_description());
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     185 [ +  - ][ +  - ]:          1 :     TEST_EQUAL(q.get_description(), "Query()");
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
     186                 :            : 
     187 [ +  - ][ +  - ]:          1 :     q = Xapian::Query("hello");
                 [ +  - ]
     188 [ +  - ][ +  - ]:          1 :     q2 = Xapian::Query::unserialise(q.serialise());
         [ +  - ][ +  - ]
     189 [ +  - ][ +  - ]:          1 :     TEST_EQUAL(q.get_description(), q2.get_description());
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     190 [ +  - ][ +  - ]:          1 :     TEST_EQUAL(q.get_description(), "Query(hello)");
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
     191                 :            : 
     192 [ +  - ][ +  - ]:          1 :     q = Xapian::Query("hello", 1, 1);
                 [ +  - ]
     193 [ +  - ][ +  - ]:          1 :     q2 = Xapian::Query::unserialise(q.serialise());
         [ +  - ][ +  - ]
     194                 :            :     // Regression test for fix in Xapian 1.0.0.
     195 [ +  - ][ +  - ]:          1 :     TEST_EQUAL(q.get_description(), q2.get_description());
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     196 [ +  - ][ +  - ]:          1 :     TEST_EQUAL(q.get_description(), "Query(hello@1)");
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
     197                 :            : 
     198 [ +  - ][ +  - ]:          1 :     q = Xapian::Query(q.OP_OR, Xapian::Query("hello"), Xapian::Query("world"));
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
     199 [ +  - ][ +  - ]:          1 :     q2 = Xapian::Query::unserialise(q.serialise());
         [ +  - ][ +  - ]
     200 [ +  - ][ +  - ]:          1 :     TEST_EQUAL(q.get_description(), q2.get_description());
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     201 [ +  - ][ +  - ]:          1 :     TEST_EQUAL(q.get_description(), "Query((hello OR world))");
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
     202                 :            : 
     203 [ +  - ][ +  - ]:          2 :     q = Xapian::Query(q.OP_OR,
         [ +  - ][ +  - ]
                 [ +  - ]
     204                 :            :                       Xapian::Query("hello", 1, 1),
     205         [ +  - ]:          1 :                       Xapian::Query("world", 1, 1));
     206 [ +  - ][ +  - ]:          1 :     q2 = Xapian::Query::unserialise(q.serialise());
         [ +  - ][ +  - ]
     207 [ +  - ][ +  - ]:          1 :     TEST_EQUAL(q.get_description(), q2.get_description());
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     208 [ +  - ][ +  - ]:          1 :     TEST_EQUAL(q.get_description(), "Query((hello@1 OR world@1))");
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
     209                 :            : 
     210                 :            :     static const char * const phrase[] = { "shaken", "not", "stirred" };
     211 [ +  - ][ +  - ]:          1 :     q = Xapian::Query(q.OP_PHRASE, phrase, phrase + 3);
     212 [ +  - ][ +  - ]:          1 :     q = Xapian::Query(q.OP_OR, Xapian::Query("007"), q);
         [ +  - ][ +  - ]
     213 [ +  - ][ +  - ]:          1 :     q = Xapian::Query(q.OP_SCALE_WEIGHT, q, 3.14);
     214 [ +  - ][ +  - ]:          1 :     q2 = Xapian::Query::unserialise(q.serialise());
         [ +  - ][ +  - ]
     215 [ +  - ][ +  - ]:          1 :     TEST_EQUAL(q.get_description(), q2.get_description());
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     216                 :            : 
     217                 :          1 :     return true;
     218                 :            : }
     219                 :            : 
     220                 :            : // Test for serialising a query which contains a PostingSource.
     221                 :          1 : DEFINE_TESTCASE(serialise_query2, !backend) {
     222         [ +  - ]:          1 :     Xapian::ValueWeightPostingSource s1(10);
     223         [ +  - ]:          2 :     Xapian::Query q(&s1);
     224 [ +  - ][ +  - ]:          2 :     Xapian::Query q2 = Xapian::Query::unserialise(q.serialise());
                 [ +  - ]
     225 [ +  - ][ +  - ]:          1 :     TEST_EQUAL(q.get_description(), q2.get_description());
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     226 [ +  - ][ +  - ]:          1 :     TEST_EQUAL(q.get_description(), "Query(PostingSource(Xapian::ValueWeightPostingSource(slot=10)))");
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
     227                 :            : 
     228         [ +  - ]:          2 :     Xapian::ValueMapPostingSource s2(11);
     229         [ +  - ]:          1 :     s2.set_default_weight(5.0);
     230 [ +  - ][ +  - ]:          1 :     q = Xapian::Query(&s2);
     231 [ +  - ][ +  - ]:          1 :     q2 = Xapian::Query::unserialise(q.serialise());
         [ +  - ][ +  - ]
     232 [ +  - ][ +  - ]:          1 :     TEST_EQUAL(q.get_description(), q2.get_description());
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     233 [ +  - ][ +  - ]:          1 :     TEST_EQUAL(q.get_description(), "Query(PostingSource(Xapian::ValueMapPostingSource(slot=11)))");
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
     234                 :            : 
     235         [ +  - ]:          2 :     Xapian::FixedWeightPostingSource s3(5.5);
     236 [ +  - ][ +  - ]:          1 :     q = Xapian::Query(&s3);
     237 [ +  - ][ +  - ]:          1 :     q2 = Xapian::Query::unserialise(q.serialise());
         [ +  - ][ +  - ]
     238 [ +  - ][ +  - ]:          1 :     TEST_EQUAL(q.get_description(), q2.get_description());
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     239 [ +  - ][ +  - ]:          1 :     TEST_EQUAL(q.get_description(), "Query(PostingSource(Xapian::FixedWeightPostingSource(wt=5.5)))");
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
     240                 :            : 
     241                 :          1 :     return true;
     242                 :            : }
     243                 :            : 
     244                 :            : // Test for unserialising a query using the default registry.
     245                 :          1 : DEFINE_TESTCASE(serialise_query3, !backend) {
     246         [ +  - ]:          1 :     Xapian::ValueWeightPostingSource s1(10);
     247         [ +  - ]:          2 :     Xapian::Query q(&s1);
     248         [ +  - ]:          2 :     Xapian::Registry reg;
     249 [ +  - ][ +  - ]:          2 :     Xapian::Query q2 = Xapian::Query::unserialise(q.serialise(), reg);
     250 [ +  - ][ +  - ]:          1 :     TEST_EQUAL(q.get_description(), q2.get_description());
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     251 [ +  - ][ +  - ]:          1 :     TEST_EQUAL(q.get_description(), "Query(PostingSource(Xapian::ValueWeightPostingSource(slot=10)))");
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
     252                 :            : 
     253         [ +  - ]:          2 :     Xapian::ValueMapPostingSource s2(11);
     254         [ +  - ]:          1 :     s2.set_default_weight(5.0);
     255 [ +  - ][ +  - ]:          1 :     q = Xapian::Query(&s2);
     256 [ +  - ][ +  - ]:          1 :     q2 = Xapian::Query::unserialise(q.serialise(), reg);
                 [ +  - ]
     257 [ +  - ][ +  - ]:          1 :     TEST_EQUAL(q.get_description(), q2.get_description());
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     258 [ +  - ][ +  - ]:          1 :     TEST_EQUAL(q.get_description(), "Query(PostingSource(Xapian::ValueMapPostingSource(slot=11)))");
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
     259                 :            : 
     260         [ +  - ]:          2 :     Xapian::FixedWeightPostingSource s3(5.5);
     261 [ +  - ][ +  - ]:          1 :     q = Xapian::Query(&s3);
     262 [ +  - ][ +  - ]:          1 :     q2 = Xapian::Query::unserialise(q.serialise(), reg);
                 [ +  - ]
     263 [ +  - ][ +  - ]:          1 :     TEST_EQUAL(q.get_description(), q2.get_description());
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     264 [ +  - ][ +  - ]:          1 :     TEST_EQUAL(q.get_description(), "Query(PostingSource(Xapian::FixedWeightPostingSource(wt=5.5)))");
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
     265                 :            : 
     266                 :          1 :     return true;
     267                 :            : }
     268                 :            : 
     269         [ -  + ]:         28 : class MyPostingSource2 : public Xapian::ValuePostingSource {
     270                 :            :     std::string desc;
     271                 :            :   public:
     272                 :          8 :     MyPostingSource2(const std::string & desc_)
     273         [ +  - ]:          8 :             : Xapian::ValuePostingSource(0), desc(desc_)
     274                 :            :     {
     275                 :          8 :     }
     276                 :            : 
     277                 :          5 :     MyPostingSource2 * clone() const
     278                 :            :     {
     279         [ +  - ]:          5 :         return new MyPostingSource2(desc);
     280                 :            :     }
     281                 :            : 
     282                 :          5 :     std::string name() const {
     283         [ +  - ]:          5 :         return "MyPostingSource2";
     284                 :            :     }
     285                 :            : 
     286                 :          1 :     std::string serialise() const {
     287                 :          1 :         return desc;
     288                 :            :     }
     289                 :            : 
     290                 :          1 :     MyPostingSource2 * unserialise(const std::string & s) const {
     291         [ +  - ]:          1 :         return new MyPostingSource2(s);
     292                 :            :     }
     293                 :            : 
     294                 :          0 :     double get_weight() const { return 1.0; }
     295                 :            : 
     296                 :          3 :     std::string get_description() const {
     297         [ +  - ]:          3 :         return "MyPostingSource2(" + desc + ")";
     298                 :            :     }
     299                 :            : };
     300                 :            : 
     301                 :            : // Test for unserialising a query which contains a custom PostingSource.
     302                 :          1 : DEFINE_TESTCASE(serialise_query4, !backend) {
     303 [ +  - ][ +  - ]:          1 :     MyPostingSource2 s1("foo");
     304         [ +  - ]:          2 :     Xapian::Query q(&s1);
     305 [ +  - ][ +  - ]:          1 :     TEST_EQUAL(q.get_description(), "Query(PostingSource(MyPostingSource2(foo)))");
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
     306         [ +  - ]:          2 :     std::string serialised = q.serialise();
     307                 :            : 
     308 [ +  - ][ +  - ]:          1 :     TEST_EXCEPTION(Xapian::SerialisationError, Xapian::Query::unserialise(serialised));
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ -  + ]
           [ -  +  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
           #  # ][ +  - ]
     309         [ +  - ]:          2 :     Xapian::Registry reg;
     310 [ +  - ][ -  +  :          1 :     TEST_EXCEPTION(Xapian::SerialisationError, Xapian::Query::unserialise(serialised, reg));
          #  #  #  #  #  
          #  #  #  #  #  
           #  # ][ -  + ]
           [ -  +  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
           #  # ][ +  - ]
     311                 :            : 
     312         [ +  - ]:          1 :     reg.register_posting_source(s1);
     313         [ +  - ]:          2 :     Xapian::Query q2 = Xapian::Query::unserialise(serialised, reg);
     314 [ +  - ][ +  - ]:          1 :     TEST_EQUAL(q.get_description(), q2.get_description());
           [ -  +  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
                   #  # ]
     315                 :            : 
     316                 :          1 :     return true;
     317                 :            : }
     318                 :            : 
     319                 :            : /// Test for memory leaks when registering posting sources or weights twice.
     320                 :          1 : DEFINE_TESTCASE(double_register_leak, !backend) {
     321 [ +  - ][ +  - ]:          1 :     MyPostingSource2 s1("foo");
     322                 :          2 :     Xapian::BM25Weight w1;
     323                 :            : 
     324         [ +  - ]:          2 :     Xapian::Registry reg;
     325         [ +  - ]:          1 :     reg.register_posting_source(s1);
     326         [ +  - ]:          1 :     reg.register_posting_source(s1);
     327         [ +  - ]:          1 :     reg.register_posting_source(s1);
     328                 :            : 
     329         [ +  - ]:          1 :     reg.register_weighting_scheme(w1);
     330         [ +  - ]:          1 :     reg.register_weighting_scheme(w1);
     331         [ +  - ]:          1 :     reg.register_weighting_scheme(w1);
     332                 :            : 
     333                 :          1 :     return true;
     334                 :            : }
     335                 :            : 
     336         [ -  + ]:          8 : class ExceptionalPostingSource : public Xapian::PostingSource {
     337                 :            :   public:
     338                 :            :     typedef enum { NONE, CLONE } failmode;
     339                 :            : 
     340                 :            :     failmode fail;
     341                 :            : 
     342                 :          6 :     ExceptionalPostingSource(failmode fail_) : fail(fail_) { }
     343                 :            : 
     344                 :          2 :     string name() const {
     345         [ +  - ]:          2 :         return "ExceptionalPostingSource";
     346                 :            :     }
     347                 :            : 
     348                 :          2 :     PostingSource * clone() const {
     349         [ +  + ]:          2 :         if (fail == CLONE)
     350                 :          1 :             throw bad_alloc();
     351                 :          1 :         return new ExceptionalPostingSource(fail);
     352                 :            :     }
     353                 :            : 
     354                 :          0 :     void init(const Xapian::Database &) { }
     355                 :            : 
     356                 :          0 :     Xapian::doccount get_termfreq_min() const { return 0; }
     357                 :          0 :     Xapian::doccount get_termfreq_est() const { return 1; }
     358                 :          0 :     Xapian::doccount get_termfreq_max() const { return 2; }
     359                 :            : 
     360                 :          0 :     void next(double) { }
     361                 :            : 
     362                 :          0 :     void skip_to(Xapian::docid, double) { }
     363                 :            : 
     364                 :          0 :     bool at_end() const { return true; }
     365                 :          0 :     Xapian::docid get_docid() const { return 0; }
     366                 :            : };
     367                 :            : 
     368                 :            : /// Check that exceptions when registering a postingsource are handled well.
     369                 :          1 : DEFINE_TESTCASE(registry1, !backend) {
     370                 :            :     // Test that a replacement object throwing bad_alloc is handled.
     371                 :            :     {
     372         [ +  - ]:          1 :         Xapian::Registry reg;
     373                 :            : 
     374         [ +  - ]:          2 :         ExceptionalPostingSource eps(ExceptionalPostingSource::NONE);
     375 [ +  - ][ -  + ]:          1 :         TEST_EXCEPTION(Xapian::UnimplementedError, eps.serialise());
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ -  + ][ -  +  
          #  #  #  #  #  
          #  #  #  #  #  
             #  #  #  # ]
                 [ +  - ]
     376 [ +  - ][ +  - ]:          1 :         TEST_EXCEPTION(Xapian::UnimplementedError, eps.unserialise(string()));
           [ -  +  #  #  
          #  #  #  #  #  
             #  #  #  #  
              # ][ -  + ]
           [ -  +  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
           #  # ][ +  - ]
     377         [ +  - ]:          1 :         reg.register_posting_source(eps);
     378                 :            :         try {
     379                 :          1 :             ExceptionalPostingSource eps_clone(ExceptionalPostingSource::CLONE);
     380         [ -  + ]:          1 :             reg.register_posting_source(eps_clone);
     381         [ -  + ]:          1 :             return false;
     382                 :          1 :         } catch (const bad_alloc &) {
     383                 :            :         }
     384                 :            : 
     385                 :            :         // Either the old entry should be removed, or it should work.
     386                 :            :         const Xapian::PostingSource * p;
     387 [ +  - ][ +  - ]:          1 :         p = reg.get_posting_source("ExceptionalPostingSource");
     388         [ -  + ]:          1 :         if (p) {
     389   [ #  #  #  #  :          1 :             TEST_EQUAL(p->name(), "ExceptionalPostingSource");
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
             #  #  #  # ]
                 [ +  - ]
     390                 :          1 :         }
     391                 :            :     }
     392                 :            : 
     393                 :          1 :     return true;
     394                 :            : }
     395                 :            : 
     396         [ -  + ]:          8 : class ExceptionalWeight : public Xapian::Weight {
     397                 :            :   public:
     398                 :            :     typedef enum { NONE, CLONE } failmode;
     399                 :            : 
     400                 :            :     failmode fail;
     401                 :            : 
     402                 :          6 :     ExceptionalWeight(failmode fail_) : fail(fail_) { }
     403                 :            : 
     404                 :          2 :     string name() const {
     405         [ +  - ]:          2 :         return "ExceptionalWeight";
     406                 :            :     }
     407                 :            : 
     408                 :          2 :     string short_name() const {
     409         [ +  - ]:          2 :         return "excep";
     410                 :            :     }
     411                 :            : 
     412                 :          2 :     Weight * clone() const {
     413         [ +  + ]:          2 :         if (fail == CLONE)
     414                 :          1 :             throw bad_alloc();
     415                 :          1 :         return new ExceptionalWeight(fail);
     416                 :            :     }
     417                 :            : 
     418                 :          0 :     void init(double) { }
     419                 :            : 
     420                 :          0 :     double get_sumpart(Xapian::termcount, Xapian::termcount, Xapian::termcount) const {
     421                 :          0 :         return 0;
     422                 :            :     }
     423                 :          0 :     double get_maxpart() const { return 0; }
     424                 :            : 
     425                 :          0 :     double get_sumextra(Xapian::termcount, Xapian::termcount) const { return 0; }
     426                 :          0 :     double get_maxextra() const { return 0; }
     427                 :            : };
     428                 :            : 
     429                 :            : /// Check that exceptions when registering are handled well.
     430                 :          1 : DEFINE_TESTCASE(registry2, !backend) {
     431                 :            :     // Test that a replacement object throwing bad_alloc is handled.
     432                 :            :     {
     433         [ +  - ]:          1 :         Xapian::Registry reg;
     434                 :            : 
     435         [ +  - ]:          2 :         ExceptionalWeight ewt(ExceptionalWeight::NONE);
     436         [ +  - ]:          1 :         reg.register_weighting_scheme(ewt);
     437                 :            :         try {
     438                 :          1 :             ExceptionalWeight ewt_clone(ExceptionalWeight::CLONE);
     439         [ -  + ]:          1 :             reg.register_weighting_scheme(ewt_clone);
     440         [ -  + ]:          1 :             return false;
     441                 :          1 :         } catch (const bad_alloc &) {
     442                 :            :         }
     443                 :            : 
     444                 :            :         // Either the old entry should be removed, or it should work.
     445                 :            :         const Xapian::Weight * p;
     446 [ +  - ][ +  - ]:          1 :         p = reg.get_weighting_scheme("ExceptionalWeight");
     447         [ -  + ]:          1 :         if (p) {
     448   [ #  #  #  #  :          1 :             TEST_EQUAL(p->name(), "ExceptionalWeight");
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
             #  #  #  # ]
                 [ +  - ]
     449                 :          1 :         }
     450                 :            :     }
     451                 :            : 
     452                 :          1 :     return true;
     453                 :            : }
     454                 :            : 
     455         [ -  + ]:          8 : class ExceptionalMatchSpy : public Xapian::MatchSpy {
     456                 :            :   public:
     457                 :            :     typedef enum { NONE, CLONE } failmode;
     458                 :            : 
     459                 :            :     failmode fail;
     460                 :            : 
     461                 :          6 :     ExceptionalMatchSpy(failmode fail_) : fail(fail_) { }
     462                 :            : 
     463                 :          2 :     string name() const {
     464         [ +  - ]:          2 :         return "ExceptionalMatchSpy";
     465                 :            :     }
     466                 :            : 
     467                 :          2 :     MatchSpy * clone() const {
     468         [ +  + ]:          2 :         if (fail == CLONE)
     469                 :          1 :             throw bad_alloc();
     470                 :          1 :         return new ExceptionalMatchSpy(fail);
     471                 :            :     }
     472                 :            : 
     473                 :          0 :     void operator()(const Xapian::Document &, double) {
     474                 :          0 :     }
     475                 :            : };
     476                 :            : 
     477                 :            : /// Check that exceptions when registering are handled well.
     478                 :          1 : DEFINE_TESTCASE(registry3, !backend) {
     479                 :            :     // Test that a replacement object throwing bad_alloc is handled.
     480                 :            :     {
     481         [ +  - ]:          1 :         Xapian::Registry reg;
     482                 :            : 
     483         [ +  - ]:          2 :         ExceptionalMatchSpy ems(ExceptionalMatchSpy::NONE);
     484         [ +  - ]:          1 :         reg.register_match_spy(ems);
     485                 :            :         try {
     486                 :          1 :             ExceptionalMatchSpy ems_clone(ExceptionalMatchSpy::CLONE);
     487         [ -  + ]:          1 :             reg.register_match_spy(ems_clone);
     488         [ -  + ]:          1 :             return false;
     489                 :          1 :         } catch (const bad_alloc &) {
     490                 :            :         }
     491                 :            : 
     492                 :            :         // Either the old entry should be removed, or it should work.
     493                 :            :         const Xapian::MatchSpy * p;
     494 [ +  - ][ +  - ]:          1 :         p = reg.get_match_spy("ExceptionalMatchSpy");
     495         [ -  + ]:          1 :         if (p) {
     496   [ #  #  #  #  :          1 :             TEST_EQUAL(p->name(), "ExceptionalMatchSpy");
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
             #  #  #  # ]
                 [ +  - ]
     497                 :          1 :         }
     498                 :            :     }
     499                 :            : 
     500                 :          1 :     return true;
     501                 :            : }

Generated by: LCOV version 1.11