LCOV - code coverage report
Current view: top level - tests - api_metadata.cc (source / functions) Hit Total Coverage
Test: Test Coverage for xapian-core 7028d852e609 Lines: 163 167 97.6 %
Date: 2019-02-17 14:59:59 Functions: 6 6 100.0 %
Branches: 373 2318 16.1 %

           Branch data     Line data    Source code
       1                 :            : /** @file api_metadata.cc
       2                 :            :  * @brief Test the user metadata functionality.
       3                 :            :  */
       4                 :            : /* Copyright (C) 2007,2009,2011 Olly Betts
       5                 :            :  * Copyright (C) 2007,2008,2009 Lemur Consulting Ltd
       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_metadata.h"
      25                 :            : 
      26                 :            : #include <xapian.h>
      27                 :            : 
      28                 :            : #include "apitest.h"
      29                 :            : #include "testsuite.h"
      30                 :            : #include "testutils.h"
      31                 :            : 
      32                 :            : #include <string>
      33                 :            : 
      34                 :            : using namespace std;
      35                 :            : 
      36                 :            : // Test basic metadata access methods.
      37                 :          5 : DEFINE_TESTCASE(metadata1, writable) {
      38 [ +  - ][ +  - ]:          5 :     Xapian::WritableDatabase db = get_writable_database();
      39                 :            : 
      40 [ +  - ][ +  - ]:          5 :     TEST_EQUAL(db.get_metadata("foo"), "");
         [ +  - ][ -  + ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
      41                 :            :     try {
      42 [ +  - ][ +  - ]:          5 :         db.set_metadata("foo", "bar");
                 [ +  - ]
      43         [ #  # ]:          0 :     } catch (const Xapian::UnimplementedError &) {
      44   [ #  #  #  #  :          0 :         SKIP_TEST("Metadata not supported by this backend");
             #  #  #  # ]
      45                 :            :     }
      46 [ +  - ][ +  - ]:          5 :     TEST_EQUAL(db.get_metadata("foo"), "bar");
         [ +  - ][ -  + ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
      47 [ +  - ][ +  - ]:          5 :     db.set_metadata("foo", "baz");
                 [ +  - ]
      48 [ +  - ][ -  + ]:          5 :     TEST_EQUAL(db.get_doccount(), 0);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
      49 [ +  - ][ +  - ]:          5 :     TEST_EQUAL(db.get_metadata("foo"), "baz");
         [ +  - ][ -  + ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
      50 [ +  - ][ +  - ]:          5 :     db.set_metadata("foo", "");
                 [ +  - ]
      51 [ +  - ][ +  - ]:          5 :     TEST_EQUAL(db.get_metadata("foo"), "");
         [ +  - ][ -  + ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
      52                 :            : 
      53 [ +  - ][ -  + ]:          5 :     TEST_EQUAL(db.get_doccount(), 0);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
      54                 :            : 
      55                 :            :     // Check for transparent handling of zero bytes.
      56 [ +  - ][ +  - ]:          5 :     db.set_metadata("foo", "value of foo");
                 [ +  - ]
      57 [ +  - ][ +  - ]:          5 :     db.set_metadata(string("foo\0bar", 7), string(1, '\0'));
                 [ +  - ]
      58 [ +  - ][ +  - ]:          5 :     db.set_metadata(string("foo\0", 4), string("foo\0bar", 7));
                 [ +  - ]
      59                 :            : 
      60 [ +  - ][ +  - ]:          5 :     TEST_EQUAL(db.get_metadata("foo"), "value of foo");
         [ +  - ][ -  + ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
      61 [ +  - ][ +  - ]:          5 :     TEST_EQUAL(db.get_metadata(string("foo\0bar", 7)), string(1, '\0'));
         [ +  - ][ -  + ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
      62 [ +  - ][ +  - ]:          5 :     TEST_EQUAL(db.get_metadata(string("foo\0", 4)), string("foo\0bar", 7));
         [ +  - ][ -  + ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
      63                 :            : 
      64         [ +  - ]:          5 :     db.commit();
      65                 :            : 
      66 [ +  - ][ +  - ]:          5 :     TEST_EQUAL(db.get_metadata("foo"), "value of foo");
         [ +  - ][ -  + ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
      67 [ +  - ][ +  - ]:          5 :     TEST_EQUAL(db.get_metadata(string("foo\0bar", 7)), string(1, '\0'));
         [ +  - ][ -  + ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
      68 [ +  - ][ +  - ]:          5 :     TEST_EQUAL(db.get_metadata(string("foo\0", 4)), string("foo\0bar", 7));
         [ +  - ][ -  + ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
      69                 :            : 
      70                 :          5 :     return true;
      71                 :            : }
      72                 :            : 
      73                 :            : // Test that metadata gets applied at same time as other changes.
      74                 :          4 : DEFINE_TESTCASE(metadata2, metadata && !inmemory) {
      75 [ +  - ][ +  - ]:          4 :     Xapian::WritableDatabase db = get_writable_database();
      76         [ +  - ]:          8 :     Xapian::Database dbr = get_writable_database_as_database();
      77                 :            : 
      78 [ +  - ][ +  - ]:          4 :     TEST_EQUAL(db.get_metadata("foo"), "");
         [ +  - ][ -  + ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
      79 [ +  - ][ +  - ]:          4 :     db.set_metadata("foo", "bar");
                 [ +  - ]
      80 [ +  - ][ +  - ]:          4 :     TEST_EQUAL(db.get_metadata("foo"), "bar");
         [ +  - ][ -  + ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
      81 [ +  - ][ +  - ]:          4 :     TEST_EQUAL(dbr.get_metadata("foo"), "");
         [ +  - ][ -  + ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
      82         [ +  - ]:          4 :     db.commit();
      83 [ +  - ][ +  - ]:          4 :     TEST_EQUAL(dbr.get_metadata("foo"), "");
         [ +  - ][ -  + ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
      84 [ +  - ][ -  + ]:          4 :     TEST(dbr.reopen());
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
      85 [ +  - ][ +  - ]:          4 :     TEST_EQUAL(db.get_metadata("foo"), "bar");
         [ +  - ][ -  + ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
      86 [ +  - ][ +  - ]:          4 :     TEST_EQUAL(dbr.get_metadata("foo"), "bar");
         [ +  - ][ -  + ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
      87 [ +  - ][ -  + ]:          4 :     TEST_EQUAL(dbr.get_doccount(), 0);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
      88                 :            : 
      89 [ +  - ][ +  - ]:          4 :     db.add_document(Xapian::Document());
      90 [ +  - ][ +  - ]:          4 :     db.set_metadata("foo", "baz");
                 [ +  - ]
      91 [ +  - ][ -  + ]:          4 :     TEST_EQUAL(db.get_doccount(), 1);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
      92 [ +  - ][ +  - ]:          4 :     TEST_EQUAL(db.get_metadata("foo"), "baz");
         [ +  - ][ -  + ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
      93         [ +  - ]:          4 :     db.commit();
      94                 :            : 
      95 [ +  - ][ +  - ]:          4 :     TEST_EQUAL(dbr.get_metadata("foo"), "bar");
         [ +  - ][ -  + ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
      96 [ +  - ][ -  + ]:          4 :     TEST(dbr.reopen());
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
      97 [ +  - ][ +  - ]:          4 :     TEST_EQUAL(dbr.get_metadata("foo"), "baz");
         [ +  - ][ -  + ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
      98                 :            : 
      99 [ +  - ][ +  - ]:          4 :     db.set_metadata("foo", "");
                 [ +  - ]
     100 [ +  - ][ +  - ]:          4 :     TEST_EQUAL(db.get_metadata("foo"), "");
         [ +  - ][ -  + ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
     101         [ +  - ]:          4 :     db.commit();
     102 [ +  - ][ +  - ]:          4 :     TEST_EQUAL(dbr.get_metadata("foo"), "baz");
         [ +  - ][ -  + ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
     103 [ +  - ][ -  + ]:          4 :     TEST(dbr.reopen());
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     104 [ +  - ][ +  - ]:          4 :     TEST_EQUAL(dbr.get_metadata("foo"), "");
         [ +  - ][ -  + ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
     105                 :            : 
     106 [ +  - ][ -  + ]:          4 :     TEST_EQUAL(db.get_doccount(), 1);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     107                 :            : 
     108                 :          4 :     return true;
     109                 :            : }
     110                 :            : 
     111                 :            : // Test the empty metadata keys give an error correctly.
     112                 :          5 : DEFINE_TESTCASE(metadata3, metadata) {
     113 [ +  - ][ +  - ]:          5 :     Xapian::WritableDatabase db = get_writable_database();
     114                 :            : 
     115 [ +  - ][ +  - ]:          5 :     TEST_EXCEPTION(Xapian::InvalidArgumentError, db.get_metadata(""));
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ -  + ]
           [ -  +  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
           #  # ][ +  - ]
     116 [ +  - ][ +  - ]:          5 :     TEST_EXCEPTION(Xapian::InvalidArgumentError, db.set_metadata("", "foo"));
         [ +  - ][ -  +  
          #  #  #  #  #  
          #  #  #  #  #  
           #  # ][ -  + ]
           [ -  +  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
           #  # ][ +  - ]
     117 [ +  - ][ +  - ]:          5 :     TEST_EXCEPTION(Xapian::InvalidArgumentError, db.get_metadata(""));
           [ -  +  #  #  
          #  #  #  #  #  
             #  #  #  #  
              # ][ -  + ]
           [ -  +  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
           #  # ][ +  - ]
     118                 :            : 
     119                 :          5 :     return true;
     120                 :            : }
     121                 :            : 
     122                 :            : // Regression test for adding a piece of metadata on its own before adding
     123                 :            : // other things.
     124                 :          4 : DEFINE_TESTCASE(metadata4, metadata && !inmemory) {
     125 [ +  - ][ +  - ]:          4 :     Xapian::WritableDatabase db = get_writable_database();
     126                 :            : 
     127 [ +  - ][ +  - ]:          4 :     db.set_metadata("foo", "foo");
                 [ +  - ]
     128         [ +  - ]:          4 :     db.commit();
     129                 :            : 
     130         [ +  - ]:          8 :     Xapian::Document doc;
     131 [ +  - ][ +  - ]:          4 :     doc.add_posting("foo", 1);
     132         [ +  - ]:          4 :     db.add_document(doc);
     133                 :            : 
     134         [ +  - ]:          4 :     Xapian::Database dbr(get_writable_database_as_database());
     135                 :            : 
     136                 :          4 :     return true;
     137                 :            : }
     138                 :            : 
     139                 :            : // Test metadata iterators.
     140                 :          5 : DEFINE_TESTCASE(metadata5, writable) {
     141 [ +  - ][ +  - ]:          5 :     Xapian::WritableDatabase db = get_writable_database();
     142                 :            : 
     143                 :            :     // Check that iterator on empty database returns nothing.
     144                 :         10 :     Xapian::TermIterator iter;
     145 [ +  - ][ +  - ]:          5 :     iter = db.metadata_keys_begin();
                 [ +  - ]
     146 [ +  - ][ -  + ]:          5 :     TEST_EQUAL(iter, db.metadata_keys_end());
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     147                 :            : 
     148                 :            :     // FIXME: inmemory doesn't implement metadata iterators yet, except in the
     149                 :            :     // trivial case of there being no keys to iterate.
     150 [ +  - ][ +  + ]:          5 :     SKIP_TEST_FOR_BACKEND("inmemory");
     151                 :            : 
     152                 :            :     try {
     153 [ +  - ][ +  - ]:          4 :         db.set_metadata("foo", "val");
                 [ +  - ]
     154         [ #  # ]:          0 :     } catch (const Xapian::UnimplementedError &) {
     155   [ #  #  #  #  :          0 :         SKIP_TEST("Metadata not supported by this backend");
             #  #  #  # ]
     156                 :            :     }
     157         [ +  - ]:          4 :     db.commit();
     158                 :            : 
     159                 :            :     // Check iterator on a database with only metadata items.
     160 [ +  - ][ +  - ]:          4 :     iter = db.metadata_keys_begin();
                 [ +  - ]
     161 [ +  - ][ -  + ]:          4 :     TEST(iter != db.metadata_keys_end());
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     162 [ +  - ][ +  - ]:          4 :     TEST_EQUAL(*iter, "foo");
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
     163         [ +  - ]:          4 :     ++iter;
     164 [ +  - ][ -  + ]:          4 :     TEST(iter == db.metadata_keys_end());
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     165                 :            : 
     166                 :            :     // Check iterator on a database with metadata items and documents.
     167         [ +  - ]:          8 :     Xapian::Document doc;
     168 [ +  - ][ +  - ]:          4 :     doc.add_posting("foo", 1);
     169         [ +  - ]:          4 :     db.add_document(doc);
     170         [ +  - ]:          4 :     db.commit();
     171                 :            : 
     172 [ +  - ][ +  - ]:          4 :     iter = db.metadata_keys_begin();
                 [ +  - ]
     173 [ +  - ][ -  + ]:          4 :     TEST(iter != db.metadata_keys_end());
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     174 [ +  - ][ +  - ]:          4 :     TEST_EQUAL(*iter, "foo");
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
     175         [ +  - ]:          4 :     ++iter;
     176 [ +  - ][ -  + ]:          4 :     TEST(iter == db.metadata_keys_end());
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     177                 :            : 
     178                 :            :     // Check iterator on a database with documents but no metadata.  Also
     179                 :            :     // checks that setting metadata to empty stops the iterator returning it.
     180 [ +  - ][ +  - ]:          4 :     db.set_metadata("foo", "");
                 [ +  - ]
     181         [ +  - ]:          4 :     db.commit();
     182 [ +  - ][ +  - ]:          4 :     iter = db.metadata_keys_begin();
                 [ +  - ]
     183 [ +  - ][ -  + ]:          4 :     TEST(iter == db.metadata_keys_end());
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     184                 :            : 
     185                 :            :     // Check use of a prefix, and skip_to.
     186 [ +  - ][ +  - ]:          4 :     db.set_metadata("a", "val");
                 [ +  - ]
     187 [ +  - ][ +  - ]:          4 :     db.set_metadata("foo", "val");
                 [ +  - ]
     188 [ +  - ][ +  - ]:          4 :     db.set_metadata("foo1", "val");
                 [ +  - ]
     189 [ +  - ][ +  - ]:          4 :     db.set_metadata("foo2", "val");
                 [ +  - ]
     190 [ +  - ][ +  - ]:          4 :     db.set_metadata("z", "val");
                 [ +  - ]
     191         [ +  - ]:          4 :     db.commit();
     192                 :            : 
     193 [ +  - ][ +  - ]:          4 :     iter = db.metadata_keys_begin();
                 [ +  - ]
     194 [ +  - ][ -  + ]:          4 :     TEST(iter != db.metadata_keys_end());
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     195 [ +  - ][ +  - ]:          4 :     TEST_EQUAL(*iter, "a");
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
     196         [ +  - ]:          4 :     ++iter;
     197 [ +  - ][ -  + ]:          4 :     TEST(iter != db.metadata_keys_end());
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     198 [ +  - ][ +  - ]:          4 :     TEST_EQUAL(*iter, "foo");
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
     199         [ +  - ]:          4 :     ++iter;
     200 [ +  - ][ -  + ]:          4 :     TEST(iter != db.metadata_keys_end());
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     201 [ +  - ][ +  - ]:          4 :     TEST_EQUAL(*iter, "foo1");
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
     202         [ +  - ]:          4 :     ++iter;
     203 [ +  - ][ -  + ]:          4 :     TEST(iter != db.metadata_keys_end());
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     204 [ +  - ][ +  - ]:          4 :     TEST_EQUAL(*iter, "foo2");
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
     205         [ +  - ]:          4 :     ++iter;
     206 [ +  - ][ -  + ]:          4 :     TEST(iter != db.metadata_keys_end());
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     207 [ +  - ][ +  - ]:          4 :     TEST_EQUAL(*iter, "z");
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
     208         [ +  - ]:          4 :     ++iter;
     209 [ +  - ][ -  + ]:          4 :     TEST(iter == db.metadata_keys_end());
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     210                 :            : 
     211 [ +  - ][ +  - ]:          4 :     iter = db.metadata_keys_begin("foo");
                 [ +  - ]
     212 [ +  - ][ -  + ]:          4 :     TEST(iter != db.metadata_keys_end("foo"));
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     213 [ +  - ][ +  - ]:          4 :     TEST_EQUAL(*iter, "foo");
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
     214         [ +  - ]:          4 :     ++iter;
     215 [ +  - ][ -  + ]:          4 :     TEST(iter != db.metadata_keys_end("foo"));
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     216 [ +  - ][ +  - ]:          4 :     TEST_EQUAL(*iter, "foo1");
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
     217         [ +  - ]:          4 :     ++iter;
     218 [ +  - ][ -  + ]:          4 :     TEST(iter != db.metadata_keys_end("foo"));
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     219 [ +  - ][ +  - ]:          4 :     TEST_EQUAL(*iter, "foo2");
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
     220         [ +  - ]:          4 :     ++iter;
     221 [ +  - ][ -  + ]:          4 :     TEST(iter == db.metadata_keys_end("foo"));
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     222                 :            : 
     223 [ +  - ][ +  - ]:          4 :     iter = db.metadata_keys_begin("foo1");
                 [ +  - ]
     224 [ +  - ][ -  + ]:          4 :     TEST(iter != db.metadata_keys_end("foo1"));
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     225 [ +  - ][ +  - ]:          4 :     TEST_EQUAL(*iter, "foo1");
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
     226         [ +  - ]:          4 :     ++iter;
     227 [ +  - ][ -  + ]:          4 :     TEST(iter == db.metadata_keys_end("foo1"));
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     228                 :            : 
     229 [ +  - ][ +  - ]:          4 :     iter = db.metadata_keys_begin();
                 [ +  - ]
     230 [ +  - ][ -  + ]:          4 :     TEST(iter != db.metadata_keys_end());
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     231 [ +  - ][ +  - ]:          4 :     TEST_EQUAL(*iter, "a");
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
     232                 :            : 
     233                 :            :     // Skip to "" should move to the first key.
     234 [ +  - ][ +  - ]:          4 :     iter.skip_to("");
     235 [ +  - ][ -  + ]:          4 :     TEST(iter != db.metadata_keys_end());
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     236 [ +  - ][ +  - ]:          4 :     TEST_EQUAL(*iter, "a");
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
     237                 :            : 
     238                 :            :     // This skip_to should skip the "foo" key.
     239 [ +  - ][ +  - ]:          4 :     iter.skip_to("foo1");
     240 [ +  - ][ -  + ]:          4 :     TEST(iter != db.metadata_keys_end());
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     241 [ +  - ][ +  - ]:          4 :     TEST_EQUAL(*iter, "foo1");
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
     242                 :            : 
     243                 :            :     // Check that skipping to the current key works.
     244 [ +  - ][ +  - ]:          4 :     iter.skip_to("foo1");
     245 [ +  - ][ -  + ]:          4 :     TEST(iter != db.metadata_keys_end());
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     246 [ +  - ][ +  - ]:          4 :     TEST_EQUAL(*iter, "foo1");
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
     247                 :            : 
     248                 :            :     // Check that skip_to a key before the current one doesn't move forwards.
     249 [ +  - ][ +  - ]:          4 :     iter.skip_to("a");
     250 [ +  - ][ -  + ]:          4 :     TEST(iter != db.metadata_keys_end());
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     251 [ +  - ][ +  - ]:          4 :     TEST_REL(*iter, <=, "foo1");
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
     252                 :            : 
     253                 :            :     // Make sure we're back on foo1.
     254 [ +  - ][ +  - ]:          4 :     iter.skip_to("foo1");
     255 [ +  - ][ -  + ]:          4 :     TEST(iter != db.metadata_keys_end());
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     256 [ +  - ][ +  - ]:          4 :     TEST_EQUAL(*iter, "foo1");
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
     257                 :            : 
     258                 :            :     // Check that advancing after a skip_to() works correctly.
     259         [ +  - ]:          4 :     ++iter;
     260 [ +  - ][ -  + ]:          4 :     TEST(iter != db.metadata_keys_end());
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     261 [ +  - ][ +  - ]:          4 :     TEST_EQUAL(*iter, "foo2");
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
     262                 :            : 
     263                 :            :     // Check that skipping to a key after the last key works.
     264 [ +  - ][ +  - ]:          4 :     iter.skip_to("zoo");
     265 [ +  - ][ -  + ]:          4 :     TEST(iter == db.metadata_keys_end());
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     266                 :            : 
     267                 :          5 :     return true;
     268                 :            : }
     269                 :            : 
     270                 :            : /// Regression test of reading after writing but not committing.
     271                 :          5 : DEFINE_TESTCASE(writeread1, writable && metadata) {
     272 [ +  - ][ +  - ]:          5 :     Xapian::WritableDatabase db_w = get_writable_database();
     273 [ +  - ][ +  - ]:          5 :     db_w.set_metadata("1", "2");
                 [ +  - ]
     274         [ +  - ]:         10 :     string longitem(20000, 'j');
     275 [ +  - ][ +  - ]:          5 :     db_w.set_metadata("2", longitem);
     276                 :            : 
     277 [ +  - ][ +  - ]:         10 :     string readitem = db_w.get_metadata("2");
     278 [ -  + ][ #  # ]:          5 :     TEST_EQUAL(readitem, longitem);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     279                 :            : 
     280                 :          5 :     return true;
     281                 :            : }

Generated by: LCOV version 1.11