LCOV - code coverage report
Current view: top level - tests - api_valuestats.cc (source / functions) Hit Total Coverage
Test: Test Coverage for xapian-core c2b6f1024d3a Lines: 214 214 100.0 %
Date: 2019-05-16 09:13:18 Functions: 5 5 100.0 %
Branches: 472 4168 11.3 %

           Branch data     Line data    Source code
       1                 :            : /** @file api_valuestats.cc
       2                 :            :  * @brief tests of the value statistics functions.
       3                 :            :  */
       4                 :            : /* Copyright 2008 Lemur Consulting Ltd
       5                 :            :  * Copyright 2008,2009,2011,2017 Olly Betts
       6                 :            :  *
       7                 :            :  * This program is free software; you can redistribute it and/or
       8                 :            :  * modify it under the terms of the GNU General Public License as
       9                 :            :  * published by the Free Software Foundation; either version 2 of the
      10                 :            :  * License, or (at your option) any later version.
      11                 :            :  *
      12                 :            :  * This program is distributed in the hope that it will be useful,
      13                 :            :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
      14                 :            :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      15                 :            :  * GNU General Public License for more details.
      16                 :            :  *
      17                 :            :  * You should have received a copy of the GNU General Public License
      18                 :            :  * along with this program; if not, write to the Free Software
      19                 :            :  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301
      20                 :            :  * USA
      21                 :            :  */
      22                 :            : 
      23                 :            : #include <config.h>
      24                 :            : 
      25                 :            : #include "api_valuestats.h"
      26                 :            : 
      27                 :            : #include <xapian.h>
      28                 :            : #include "testsuite.h"
      29                 :            : #include "testutils.h"
      30                 :            : 
      31                 :            : #include "apitest.h"
      32                 :            : 
      33                 :            : using namespace std;
      34                 :            : 
      35                 :            : // #######################################################################
      36                 :            : // # Tests start here
      37                 :            : 
      38                 :            : /// Test of value statistics methods.
      39                 :          5 : DEFINE_TESTCASE(valuestats1, writable && valuestats) {
      40 [ +  - ][ +  - ]:          5 :     Xapian::WritableDatabase db_w = get_writable_database();
      41                 :            : 
      42                 :            :     // Check that counts are initially zero.
      43 [ +  - ][ -  + ]:          5 :     TEST_EQUAL(db_w.get_value_freq(0), 0);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
      44 [ +  - ][ +  - ]:          5 :     TEST_EQUAL(db_w.get_value_lower_bound(0), "");
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
      45 [ +  - ][ +  - ]:          5 :     TEST_EQUAL(db_w.get_value_upper_bound(0), "");
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
      46 [ +  - ][ -  + ]:          5 :     TEST_EQUAL(db_w.get_value_freq(1), 0);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
      47 [ +  - ][ +  - ]:          5 :     TEST_EQUAL(db_w.get_value_lower_bound(1), "");
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
      48 [ +  - ][ +  - ]:          5 :     TEST_EQUAL(db_w.get_value_upper_bound(1), "");
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
      49                 :            : 
      50         [ +  - ]:         10 :     Xapian::Document doc;
      51 [ +  - ][ +  - ]:          5 :     doc.add_value(0, "hello");
      52                 :            : 
      53                 :            :     // Check that statistics for the correct value slot increase when document
      54                 :            :     // is added.  (Check slot 1 first, so that cache invalidation of the last
      55                 :            :     // slot read also gets checked.)
      56         [ +  - ]:          5 :     db_w.add_document(doc);
      57 [ +  - ][ -  + ]:          5 :     TEST_EQUAL(db_w.get_value_freq(1), 0);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
      58 [ +  - ][ +  - ]:          5 :     TEST_EQUAL(db_w.get_value_lower_bound(1), "");
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
      59 [ +  - ][ +  - ]:          5 :     TEST_EQUAL(db_w.get_value_upper_bound(1), "");
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
      60 [ +  - ][ -  + ]:          5 :     TEST_EQUAL(db_w.get_value_freq(0), 1);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
      61 [ +  - ][ +  - ]:          5 :     TEST_EQUAL(db_w.get_value_lower_bound(0), "hello");
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
      62 [ +  - ][ +  - ]:          5 :     TEST_EQUAL(db_w.get_value_upper_bound(0), "hello");
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
      63                 :            : 
      64                 :            :     // Check that statistics work correctly when second document is added.
      65 [ +  - ][ +  - ]:          5 :     doc = Xapian::Document();
      66 [ +  - ][ +  - ]:          5 :     doc.add_value(0, "world");
      67 [ +  - ][ +  - ]:          5 :     doc.add_value(1, "cheese");
      68         [ +  - ]:          5 :     db_w.replace_document(2, doc);
      69 [ +  - ][ -  + ]:          5 :     TEST_EQUAL(db_w.get_value_freq(0), 2);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
      70 [ +  - ][ +  - ]:          5 :     TEST_EQUAL(db_w.get_value_lower_bound(0), "hello");
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
      71 [ +  - ][ +  - ]:          5 :     TEST_EQUAL(db_w.get_value_upper_bound(0), "world");
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
      72 [ +  - ][ -  + ]:          5 :     TEST_EQUAL(db_w.get_value_freq(1), 1);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
      73 [ +  - ][ +  - ]:          5 :     TEST_EQUAL(db_w.get_value_lower_bound(1), "cheese");
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
      74 [ +  - ][ +  - ]:          5 :     TEST_EQUAL(db_w.get_value_upper_bound(1), "cheese");
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
      75                 :            : 
      76                 :            :     // Deleting a document affects the count, but probably not the bounds.
      77                 :            :     // It may with a multi-database, if the document which was deleted
      78                 :            :     // was the only one in that shard.
      79         [ +  - ]:          5 :     db_w.delete_document(1);
      80 [ +  - ][ -  + ]:          5 :     TEST_EQUAL(db_w.get_value_freq(1), 1);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
      81 [ +  - ][ +  - ]:          5 :     TEST_EQUAL(db_w.get_value_lower_bound(1), "cheese");
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
      82 [ +  - ][ +  - ]:          5 :     TEST_EQUAL(db_w.get_value_upper_bound(1), "cheese");
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
      83 [ +  - ][ -  + ]:          5 :     TEST_EQUAL(db_w.get_value_freq(0), 1);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
      84 [ +  - ][ +  + ]:          5 :     if (!startswith(get_dbtype(), "multi")) {
      85 [ +  - ][ +  - ]:          4 :         TEST_EQUAL(db_w.get_value_lower_bound(0), "hello");
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
      86                 :            :     } else {
      87 [ +  - ][ +  - ]:          1 :         TEST_EQUAL(db_w.get_value_lower_bound(0), "world");
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
      88                 :            :     }
      89 [ +  - ][ +  - ]:          5 :     TEST_EQUAL(db_w.get_value_upper_bound(0), "world");
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
      90                 :            : 
      91                 :            :     // Deleting all the documents returns the bounds to their original value.
      92         [ +  - ]:          5 :     db_w.delete_document(2);
      93 [ +  - ][ -  + ]:          5 :     TEST_EQUAL(db_w.get_value_freq(0), 0);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
      94 [ +  - ][ +  - ]:          5 :     TEST_EQUAL(db_w.get_value_lower_bound(0), "");
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
      95 [ +  - ][ +  - ]:          5 :     TEST_EQUAL(db_w.get_value_upper_bound(0), "");
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
      96 [ +  - ][ -  + ]:          5 :     TEST_EQUAL(db_w.get_value_freq(1), 0);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
      97 [ +  - ][ +  - ]:          5 :     TEST_EQUAL(db_w.get_value_lower_bound(1), "");
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
      98 [ +  - ][ +  - ]:          5 :     TEST_EQUAL(db_w.get_value_upper_bound(1), "");
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
      99                 :            : 
     100                 :            :     // Adding a document with a value in one of the old slots should still
     101                 :            :     // end up with tight bounds on it.
     102 [ +  - ][ +  - ]:          5 :     doc = Xapian::Document();
     103 [ +  - ][ +  - ]:          5 :     doc.add_value(1, "newval");
     104         [ +  - ]:          5 :     db_w.replace_document(2, doc);
     105 [ +  - ][ -  + ]:          5 :     TEST_EQUAL(db_w.get_value_freq(1), 1);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     106 [ +  - ][ +  - ]:          5 :     TEST_EQUAL(db_w.get_value_lower_bound(1), "newval");
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
     107 [ +  - ][ +  - ]:          5 :     TEST_EQUAL(db_w.get_value_upper_bound(1), "newval");
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
     108 [ +  - ][ -  + ]:          5 :     TEST_EQUAL(db_w.get_value_freq(0), 0);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     109 [ +  - ][ +  - ]:          5 :     TEST_EQUAL(db_w.get_value_lower_bound(0), "");
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
     110 [ +  - ][ +  - ]:          5 :     TEST_EQUAL(db_w.get_value_upper_bound(0), "");
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
     111                 :            : 
     112                 :          5 :     return true;
     113                 :            : }
     114                 :            : 
     115                 :            : /// Test that value statistics stuff obeys transactions.
     116                 :          3 : DEFINE_TESTCASE(valuestats2, transactions && valuestats) {
     117 [ +  - ][ +  - ]:          3 :     Xapian::WritableDatabase db_w = get_writable_database();
     118         [ +  - ]:          6 :     Xapian::Database db = get_writable_database_as_database();
     119                 :            : 
     120                 :            :     // Check that counts are initially zero.
     121 [ +  - ][ -  + ]:          3 :     TEST_EQUAL(db_w.get_value_freq(0), 0);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     122 [ +  - ][ +  - ]:          3 :     TEST_EQUAL(db_w.get_value_lower_bound(0), "");
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
     123 [ +  - ][ +  - ]:          3 :     TEST_EQUAL(db_w.get_value_upper_bound(0), "");
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
     124 [ +  - ][ -  + ]:          3 :     TEST_EQUAL(db_w.get_value_freq(1), 0);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     125 [ +  - ][ +  - ]:          3 :     TEST_EQUAL(db_w.get_value_lower_bound(1), "");
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
     126 [ +  - ][ +  - ]:          3 :     TEST_EQUAL(db_w.get_value_upper_bound(1), "");
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
     127 [ +  - ][ -  + ]:          3 :     TEST_EQUAL(db.get_value_freq(0), 0);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     128 [ +  - ][ +  - ]:          3 :     TEST_EQUAL(db.get_value_lower_bound(0), "");
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
     129 [ +  - ][ +  - ]:          3 :     TEST_EQUAL(db.get_value_upper_bound(0), "");
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
     130 [ +  - ][ -  + ]:          3 :     TEST_EQUAL(db.get_value_freq(1), 0);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     131 [ +  - ][ +  - ]:          3 :     TEST_EQUAL(db.get_value_lower_bound(1), "");
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
     132 [ +  - ][ +  - ]:          3 :     TEST_EQUAL(db.get_value_upper_bound(1), "");
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
     133                 :            : 
     134         [ +  - ]:          6 :     Xapian::Document doc;
     135 [ +  - ][ +  - ]:          3 :     doc.add_value(0, "hello");
     136                 :            : 
     137                 :            :     // Check that statistics for the correct value slot increase when document
     138                 :            :     // is added.  (Check slot 1 first, so that cache invalidation of the last
     139                 :            :     // slot read also gets checked.)
     140         [ +  - ]:          3 :     db_w.add_document(doc);
     141 [ +  - ][ -  + ]:          3 :     TEST_EQUAL(db_w.get_value_freq(1), 0);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     142 [ +  - ][ +  - ]:          3 :     TEST_EQUAL(db_w.get_value_lower_bound(1), "");
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
     143 [ +  - ][ +  - ]:          3 :     TEST_EQUAL(db_w.get_value_upper_bound(1), "");
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
     144 [ +  - ][ -  + ]:          3 :     TEST_EQUAL(db_w.get_value_freq(0), 1);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     145 [ +  - ][ +  - ]:          3 :     TEST_EQUAL(db_w.get_value_lower_bound(0), "hello");
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
     146 [ +  - ][ +  - ]:          3 :     TEST_EQUAL(db_w.get_value_upper_bound(0), "hello");
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
     147                 :            : 
     148                 :            :     // The readonly database shouldn't change, though.
     149 [ +  - ][ -  + ]:          3 :     TEST_EQUAL(db.get_value_freq(1), 0);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     150 [ +  - ][ +  - ]:          3 :     TEST_EQUAL(db.get_value_lower_bound(1), "");
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
     151 [ +  - ][ +  - ]:          3 :     TEST_EQUAL(db.get_value_upper_bound(1), "");
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
     152 [ +  - ][ -  + ]:          3 :     TEST_EQUAL(db.get_value_freq(0), 0);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     153 [ +  - ][ +  - ]:          3 :     TEST_EQUAL(db.get_value_lower_bound(0), "");
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
     154 [ +  - ][ +  - ]:          3 :     TEST_EQUAL(db.get_value_upper_bound(0), "");
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
     155                 :            : 
     156                 :            :     // Check that statistics work correctly when second document is added.
     157 [ +  - ][ +  - ]:          3 :     doc = Xapian::Document();
     158 [ +  - ][ +  - ]:          3 :     doc.add_value(0, "world");
     159 [ +  - ][ +  - ]:          3 :     doc.add_value(1, "cheese");
     160         [ +  - ]:          3 :     db_w.replace_document(2, doc);
     161 [ +  - ][ -  + ]:          3 :     TEST_EQUAL(db_w.get_value_freq(0), 2);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     162 [ +  - ][ +  - ]:          3 :     TEST_EQUAL(db_w.get_value_lower_bound(0), "hello");
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
     163 [ +  - ][ +  - ]:          3 :     TEST_EQUAL(db_w.get_value_upper_bound(0), "world");
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
     164 [ +  - ][ -  + ]:          3 :     TEST_EQUAL(db_w.get_value_freq(1), 1);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     165 [ +  - ][ +  - ]:          3 :     TEST_EQUAL(db_w.get_value_lower_bound(1), "cheese");
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
     166 [ +  - ][ +  - ]:          3 :     TEST_EQUAL(db_w.get_value_upper_bound(1), "cheese");
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
     167                 :            : 
     168                 :            :     // The readonly database shouldn't change, though.
     169 [ +  - ][ -  + ]:          3 :     TEST_EQUAL(db.get_value_freq(0), 0);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     170 [ +  - ][ +  - ]:          3 :     TEST_EQUAL(db.get_value_lower_bound(0), "");
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
     171 [ +  - ][ +  - ]:          3 :     TEST_EQUAL(db.get_value_upper_bound(0), "");
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
     172 [ +  - ][ -  + ]:          3 :     TEST_EQUAL(db.get_value_freq(1), 0);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     173 [ +  - ][ +  - ]:          3 :     TEST_EQUAL(db.get_value_lower_bound(1), "");
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
     174 [ +  - ][ +  - ]:          3 :     TEST_EQUAL(db.get_value_upper_bound(1), "");
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
     175                 :            : 
     176                 :            :     // Check that readonly database catches up when a commit is done.
     177         [ +  - ]:          3 :     db_w.commit();
     178 [ +  - ][ -  + ]:          3 :     TEST(db.reopen());
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     179 [ +  - ][ -  + ]:          3 :     TEST_EQUAL(db.get_value_freq(1), 1);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     180 [ +  - ][ +  - ]:          3 :     TEST_EQUAL(db.get_value_lower_bound(1), "cheese");
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
     181 [ +  - ][ +  - ]:          3 :     TEST_EQUAL(db.get_value_upper_bound(1), "cheese");
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
     182 [ +  - ][ -  + ]:          3 :     TEST_EQUAL(db.get_value_freq(0), 2);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     183 [ +  - ][ +  - ]:          3 :     TEST_EQUAL(db.get_value_lower_bound(0), "hello");
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
     184 [ +  - ][ +  - ]:          3 :     TEST_EQUAL(db.get_value_upper_bound(0), "world");
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
     185                 :            : 
     186                 :            :     // Deleting a document affects the count, but not the bounds.
     187         [ +  - ]:          3 :     db_w.delete_document(1);
     188 [ +  - ][ -  + ]:          3 :     TEST_EQUAL(db_w.get_value_freq(1), 1);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     189 [ +  - ][ +  - ]:          3 :     TEST_EQUAL(db_w.get_value_lower_bound(1), "cheese");
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
     190 [ +  - ][ +  - ]:          3 :     TEST_EQUAL(db_w.get_value_upper_bound(1), "cheese");
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
     191 [ +  - ][ -  + ]:          3 :     TEST_EQUAL(db_w.get_value_freq(0), 1);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     192 [ +  - ][ +  - ]:          3 :     TEST_EQUAL(db_w.get_value_lower_bound(0), "hello");
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
     193 [ +  - ][ +  - ]:          3 :     TEST_EQUAL(db_w.get_value_upper_bound(0), "world");
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
     194                 :            : 
     195                 :            :     // Deleting all the documents returns the bounds to their original value.
     196         [ +  - ]:          3 :     db_w.delete_document(2);
     197 [ +  - ][ -  + ]:          3 :     TEST_EQUAL(db_w.get_value_freq(0), 0);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     198 [ +  - ][ +  - ]:          3 :     TEST_EQUAL(db_w.get_value_lower_bound(0), "");
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
     199 [ +  - ][ +  - ]:          3 :     TEST_EQUAL(db_w.get_value_upper_bound(0), "");
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
     200 [ +  - ][ -  + ]:          3 :     TEST_EQUAL(db_w.get_value_freq(1), 0);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     201 [ +  - ][ +  - ]:          3 :     TEST_EQUAL(db_w.get_value_lower_bound(1), "");
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
     202 [ +  - ][ +  - ]:          3 :     TEST_EQUAL(db_w.get_value_upper_bound(1), "");
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
     203                 :            : 
     204                 :            :     // Adding a document with a value in one of the old slots should still
     205                 :            :     // end up with tight bounds on it.
     206 [ +  - ][ +  - ]:          3 :     doc = Xapian::Document();
     207 [ +  - ][ +  - ]:          3 :     doc.add_value(1, "newval");
     208         [ +  - ]:          3 :     db_w.replace_document(2, doc);
     209 [ +  - ][ -  + ]:          3 :     TEST_EQUAL(db_w.get_value_freq(1), 1);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     210 [ +  - ][ +  - ]:          3 :     TEST_EQUAL(db_w.get_value_lower_bound(1), "newval");
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
     211 [ +  - ][ +  - ]:          3 :     TEST_EQUAL(db_w.get_value_upper_bound(1), "newval");
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
     212 [ +  - ][ -  + ]:          3 :     TEST_EQUAL(db_w.get_value_freq(0), 0);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     213 [ +  - ][ +  - ]:          3 :     TEST_EQUAL(db_w.get_value_lower_bound(0), "");
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
     214 [ +  - ][ +  - ]:          3 :     TEST_EQUAL(db_w.get_value_upper_bound(0), "");
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
     215                 :            : 
     216                 :            :     // Check that a readonly database gets the right statistics, too.
     217         [ +  - ]:          3 :     db_w.commit();
     218 [ +  - ][ -  + ]:          3 :     TEST(db.reopen());
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     219 [ +  - ][ -  + ]:          3 :     TEST_EQUAL(db.get_value_freq(0), 0);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     220 [ +  - ][ +  - ]:          3 :     TEST_EQUAL(db.get_value_lower_bound(0), "");
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
     221 [ +  - ][ +  - ]:          3 :     TEST_EQUAL(db.get_value_upper_bound(0), "");
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
     222 [ +  - ][ -  + ]:          3 :     TEST_EQUAL(db.get_value_freq(1), 1);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     223 [ +  - ][ +  - ]:          3 :     TEST_EQUAL(db.get_value_lower_bound(1), "newval");
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
     224 [ +  - ][ +  - ]:          3 :     TEST_EQUAL(db.get_value_upper_bound(1), "newval");
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
     225                 :            : 
     226                 :          3 :     return true;
     227                 :            : }
     228                 :            : 
     229                 :            : /// Test reading value statistics from prebuilt databases.
     230                 :          7 : DEFINE_TESTCASE(valuestats3, valuestats) {
     231 [ +  - ][ +  - ]:          7 :     Xapian::Database db = get_database("apitest_simpledata");
     232                 :            : 
     233 [ +  - ][ -  + ]:          7 :     TEST_EQUAL(db.get_value_freq(1), 6);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     234 [ +  - ][ +  - ]:          7 :     TEST_EQUAL(db.get_value_lower_bound(1), "h");
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
     235 [ +  - ][ +  - ]:          7 :     TEST_EQUAL(db.get_value_upper_bound(1), "n");
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
     236 [ +  - ][ -  + ]:          7 :     TEST_EQUAL(db.get_value_freq(2), 6);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     237 [ +  - ][ +  - ]:          7 :     TEST_EQUAL(db.get_value_lower_bound(2), "d");
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
     238 [ +  - ][ +  - ]:          7 :     TEST_EQUAL(db.get_value_upper_bound(2), "i");
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
     239 [ +  - ][ -  + ]:          7 :     TEST_EQUAL(db.get_value_freq(3), 6);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     240 [ +  - ][ +  - ]:          7 :     TEST_EQUAL(db.get_value_lower_bound(3), " ");
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
     241 [ +  - ][ +  - ]:          7 :     TEST_EQUAL(db.get_value_upper_bound(3), "s");
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
     242 [ +  - ][ -  + ]:          7 :     TEST_EQUAL(db.get_value_freq(4), 6);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     243 [ +  - ][ +  - ]:          7 :     TEST_EQUAL(db.get_value_lower_bound(4), " ");
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
     244 [ +  - ][ +  - ]:          7 :     TEST_EQUAL(db.get_value_upper_bound(4), "y");
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
     245 [ +  - ][ -  + ]:          7 :     TEST_EQUAL(db.get_value_freq(5), 6);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     246 [ +  - ][ +  - ]:          7 :     TEST_EQUAL(db.get_value_lower_bound(5), "e");
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
     247 [ +  - ][ +  - ]:          7 :     TEST_EQUAL(db.get_value_upper_bound(5), "p");
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
     248 [ +  - ][ -  + ]:          7 :     TEST_EQUAL(db.get_value_freq(6), 6);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     249 [ +  - ][ +  - ]:          7 :     TEST_EQUAL(db.get_value_lower_bound(6), "a");
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
     250 [ +  - ][ +  - ]:          7 :     TEST_EQUAL(db.get_value_upper_bound(6), "t");
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
     251 [ +  - ][ -  + ]:          7 :     TEST_EQUAL(db.get_value_freq(7), 6);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     252 [ +  - ][ +  - ]:          7 :     TEST_EQUAL(db.get_value_lower_bound(7), " ");
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
     253 [ +  - ][ +  - ]:          7 :     TEST_EQUAL(db.get_value_upper_bound(7), "r");
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
     254 [ +  - ][ -  + ]:          7 :     TEST_EQUAL(db.get_value_freq(8), 6);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     255 [ +  - ][ +  - ]:          7 :     TEST_EQUAL(db.get_value_lower_bound(8), "a");
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
     256 [ +  - ][ +  - ]:          7 :     TEST_EQUAL(db.get_value_upper_bound(8), "t");
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
     257 [ +  - ][ -  + ]:          7 :     TEST_EQUAL(db.get_value_freq(9), 6);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     258 [ +  - ][ +  - ]:          7 :     TEST_EQUAL(db.get_value_lower_bound(9), " ");
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
     259 [ +  - ][ +  - ]:          7 :     TEST_EQUAL(db.get_value_upper_bound(9), "n");
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
     260 [ +  - ][ -  + ]:          7 :     TEST_EQUAL(db.get_value_freq(10), 6);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     261 [ +  - ][ +  - ]:          7 :     TEST_EQUAL(db.get_value_lower_bound(10), "e");
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
     262 [ +  - ][ +  - ]:          7 :     TEST_EQUAL(db.get_value_upper_bound(10), "w");
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
     263 [ +  - ][ -  + ]:          7 :     TEST_EQUAL(db.get_value_freq(11), 6);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     264 [ +  - ][ +  - ]:          7 :     TEST_EQUAL(db.get_value_lower_bound(11), "\xb9P");
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
     265 [ +  - ][ +  - ]:          7 :     TEST_EQUAL(db.get_value_upper_bound(11), "\xc7\x04");
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
     266                 :            : 
     267                 :          7 :     return true;
     268                 :            : }
     269                 :            : 
     270                 :          3 : DEFINE_TESTCASE(valuestats4, transactions && valuestats) {
     271                 :          3 :     const size_t FLUSH_THRESHOLD = 10000;
     272                 :            :     {
     273 [ +  - ][ +  - ]:          3 :         Xapian::WritableDatabase db_w = get_writable_database();
     274         [ +  - ]:          6 :         Xapian::Document doc;
     275 [ +  - ][ +  - ]:          3 :         doc.add_value(1, "test");
     276         [ +  + ]:      30003 :         for (size_t i = 0; i < FLUSH_THRESHOLD; ++i) {
     277         [ +  - ]:      30000 :             db_w.add_document(doc);
     278                 :            :         }
     279                 :            : 
     280         [ +  - ]:          6 :         Xapian::Database db = get_writable_database_as_database();
     281                 :            :         // Check that we had an automatic-commit.
     282 [ +  - ][ -  + ]:          3 :         TEST_EQUAL(db.get_doccount(), FLUSH_THRESHOLD);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     283                 :            :         // Check that the value stats are there.
     284 [ +  - ][ -  + ]:          3 :         TEST_EQUAL(db.get_value_freq(1), FLUSH_THRESHOLD);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     285 [ +  - ][ +  - ]:          3 :         TEST_EQUAL(db.get_value_lower_bound(1), "test");
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
     286 [ +  - ][ +  - ]:          3 :         TEST_EQUAL(db.get_value_upper_bound(1), "test");
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
     287                 :            : 
     288         [ +  - ]:          3 :         db_w.begin_transaction();
     289 [ +  - ][ +  - ]:          3 :         doc.add_value(1, "umbrella");
     290         [ +  - ]:          6 :         db_w.cancel_transaction();
     291                 :            :     }
     292                 :            : 
     293                 :            :     {
     294         [ +  - ]:          3 :         Xapian::Database db = get_writable_database_as_database();
     295                 :            :         // Check that we had an automatic-commit.
     296 [ +  - ][ -  + ]:          3 :         TEST_EQUAL(db.get_doccount(), FLUSH_THRESHOLD);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     297                 :            :         // Check that the value stats are there.
     298 [ +  - ][ -  + ]:          3 :         TEST_EQUAL(db.get_value_freq(1), FLUSH_THRESHOLD);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     299 [ +  - ][ +  - ]:          3 :         TEST_EQUAL(db.get_value_lower_bound(1), "test");
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
     300 [ +  - ][ +  - ]:          3 :         TEST_EQUAL(db.get_value_upper_bound(1), "test");
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
     301                 :            :     }
     302                 :            : 
     303                 :          3 :     return true;
     304                 :            : }
     305                 :            : 
     306                 :            : /// Regression test for bug fixed in 1.1.1 which led to incorrect valuestats.
     307                 :          1 : DEFINE_TESTCASE(valuestats5, !backend) {
     308         [ +  - ]:          1 :     Xapian::Document doc;
     309 [ +  - ][ +  - ]:          1 :     doc.add_value(0, "zero");
     310 [ +  - ][ +  - ]:          1 :     doc.add_value(1, "one");
     311 [ +  - ][ +  - ]:          1 :     doc.add_value(2, "two");
     312 [ +  - ][ +  - ]:          1 :     doc.add_value(3, "three");
     313 [ +  - ][ +  - ]:          1 :     doc.add_value(4, "");
     314 [ +  - ][ +  - ]:          1 :     doc.add_value(5, "five");
     315         [ +  - ]:          1 :     doc.remove_value(3);
     316 [ +  - ][ +  - ]:          1 :     doc.add_value(1, "");
     317                 :            : 
     318                 :            :     // Check that we don't have any empty values reported.
     319                 :          1 :     size_t c = 0;
     320         [ +  - ]:          2 :     Xapian::ValueIterator v = doc.values_begin();
     321         [ +  + ]:          4 :     while (v != doc.values_end()) {
     322 [ +  - ][ -  + ]:          3 :         TEST(!(*v).empty());
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     323                 :          3 :         ++c;
     324         [ +  - ]:          3 :         ++v;
     325                 :            :     }
     326 [ -  + ][ #  # ]:          1 :     TEST_EQUAL(c, 3); // 0, 2, 5
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     327                 :            : 
     328                 :          1 :     return true;
     329                 :            : }

Generated by: LCOV version 1.11