LCOV - code coverage report
Current view: top level - tests - api_query.cc (source / functions) Hit Total Coverage
Test: Test Coverage for xapian-core c2b6f1024d3a Lines: 582 585 99.5 %
Date: 2019-05-16 09:13:18 Functions: 37 37 100.0 %
Branches: 1212 5308 22.8 %

           Branch data     Line data    Source code
       1                 :            : /** @file api_query.cc
       2                 :            :  * @brief Query-related tests.
       3                 :            :  */
       4                 :            : /* Copyright (C) 2008,2009,2012,2013,2015,2016,2017,2018,2019 Olly Betts
       5                 :            :  *
       6                 :            :  * This program is free software; you can redistribute it and/or
       7                 :            :  * modify it under the terms of the GNU General Public License as
       8                 :            :  * published by the Free Software Foundation; either version 2 of the
       9                 :            :  * License, or (at your option) any later version.
      10                 :            :  *
      11                 :            :  * This program is distributed in the hope that it will be useful,
      12                 :            :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
      13                 :            :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      14                 :            :  * GNU General Public License for more details.
      15                 :            :  *
      16                 :            :  * You should have received a copy of the GNU General Public License
      17                 :            :  * along with this program; if not, write to the Free Software
      18                 :            :  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301
      19                 :            :  * USA
      20                 :            :  */
      21                 :            : 
      22                 :            : #include <config.h>
      23                 :            : 
      24                 :            : #include "api_query.h"
      25                 :            : 
      26                 :            : #include <xapian.h>
      27                 :            : 
      28                 :            : #include "testsuite.h"
      29                 :            : #include "testutils.h"
      30                 :            : 
      31                 :            : #include "apitest.h"
      32                 :            : 
      33                 :            : using namespace std;
      34                 :            : 
      35                 :            : /// Regression test - in 1.0.10 and earlier "" was included in the list.
      36                 :          1 : DEFINE_TESTCASE(queryterms1, !backend) {
      37         [ +  - ]:          1 :     Xapian::Query query = Xapian::Query::MatchAll;
      38 [ +  - ][ -  + ]:          1 :     TEST(query.get_terms_begin() == query.get_terms_end());
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
      39 [ +  - ][ +  - ]:          1 :     query = Xapian::Query(query.OP_AND_NOT, query, Xapian::Query("fair"));
         [ +  - ][ +  - ]
      40 [ +  - ][ +  - ]:          1 :     TEST_EQUAL(*query.get_terms_begin(), "fair");
         [ +  - ][ -  + ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
      41                 :          1 :     return true;
      42                 :            : }
      43                 :            : 
      44                 :          1 : DEFINE_TESTCASE(matchall2, !backend) {
      45 [ +  - ][ -  + ]:          1 :     TEST_STRINGS_EQUAL(Xapian::Query::MatchAll.get_description(),
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
      46                 :            :                        "Query(<alldocuments>)");
      47                 :          1 :     return true;
      48                 :            : }
      49                 :            : 
      50                 :          1 : DEFINE_TESTCASE(matchnothing1, !backend) {
      51 [ +  - ][ +  - ]:          1 :     TEST_STRINGS_EQUAL(Xapian::Query::MatchNothing.get_description(),
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
      52                 :            :                        "Query()");
      53                 :          1 :     vector<Xapian::Query> subqs;
      54 [ +  - ][ +  - ]:          1 :     subqs.push_back(Xapian::Query("foo"));
                 [ +  - ]
      55         [ +  - ]:          1 :     subqs.push_back(Xapian::Query::MatchNothing);
      56         [ +  - ]:          2 :     Xapian::Query q(Xapian::Query::OP_AND, subqs.begin(), subqs.end());
      57 [ +  - ][ +  - ]:          1 :     TEST_STRINGS_EQUAL(q.get_description(), "Query()");
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
      58                 :            : 
      59                 :            :     Xapian::Query q2(Xapian::Query::OP_AND,
      60 [ +  - ][ +  - ]:          2 :                      Xapian::Query("foo"), Xapian::Query::MatchNothing);
                 [ +  - ]
      61 [ +  - ][ +  - ]:          1 :     TEST_STRINGS_EQUAL(q2.get_description(), "Query()");
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
      62                 :          1 :     return true;
      63                 :            : }
      64                 :            : 
      65                 :          1 : DEFINE_TESTCASE(overload1, !backend) {
      66                 :          1 :     Xapian::Query q;
      67 [ +  - ][ +  - ]:          1 :     q = Xapian::Query("foo") & Xapian::Query("bar");
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
      68 [ +  - ][ +  - ]:          1 :     TEST_STRINGS_EQUAL(q.get_description(), "Query((foo AND bar))");
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
      69                 :            : 
      70                 :            :     // Test &= appends a same-type subquery (since Xapian 1.4.10).
      71 [ +  - ][ +  - ]:          1 :     q &= Xapian::Query("baz");
                 [ +  - ]
      72 [ +  - ][ +  - ]:          1 :     TEST_STRINGS_EQUAL(q.get_description(), "Query((foo AND bar AND baz))");
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
      73                 :            :     // But not if the RHS is the same query:
      74 [ +  - ][ +  - ]:          1 :     q = Xapian::Query("foo") & Xapian::Query("bar");
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
      75                 :            : #ifdef __has_warning
      76                 :            : # if __has_warning("-Wself-assign-overloaded")
      77                 :            :     // Suppress warning from newer clang about self-assignment so we can
      78                 :            :     // test that self-assignment works!
      79                 :            : #  pragma clang diagnostic push
      80                 :            : #  pragma clang diagnostic ignored "-Wself-assign-overloaded"
      81                 :            : # endif
      82                 :            : #endif
      83         [ +  - ]:          1 :     q &= q;
      84                 :            : #ifdef __has_warning
      85                 :            : # if __has_warning("-Wself-assign-overloaded")
      86                 :            : #  pragma clang diagnostic pop
      87                 :            : # endif
      88                 :            : #endif
      89 [ +  - ][ +  - ]:          1 :     TEST_STRINGS_EQUAL(q.get_description(), "Query(((foo AND bar) AND (foo AND bar)))");
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
      90                 :            :     {
      91                 :            :         // Also not if the query has a refcount > 1.
      92 [ +  - ][ +  - ]:          1 :         q = Xapian::Query("foo") & Xapian::Query("bar");
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
      93         [ +  - ]:          1 :         Xapian::Query qcopy = q;
      94 [ +  - ][ +  - ]:          1 :         qcopy &= Xapian::Query("baz");
                 [ +  - ]
      95 [ +  - ][ +  - ]:          1 :         TEST_STRINGS_EQUAL(qcopy.get_description(), "Query(((foo AND bar) AND baz))");
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
      96                 :            :         // And q shouldn't change.
      97 [ +  - ][ +  - ]:          1 :         TEST_STRINGS_EQUAL(q.get_description(), "Query((foo AND bar))");
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
      98                 :            :     }
      99                 :            :     // Check that MatchNothing still results in MatchNothing:
     100 [ +  - ][ +  - ]:          1 :     q = Xapian::Query("foo") & Xapian::Query("bar");
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
     101         [ +  - ]:          1 :     q &= Xapian::Query::MatchNothing;
     102 [ +  - ][ +  - ]:          1 :     TEST_STRINGS_EQUAL(q.get_description(), "Query()");
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     103                 :            :     // Check we don't combine for other operators:
     104 [ +  - ][ +  - ]:          1 :     q = Xapian::Query("foo") | Xapian::Query("bar");
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
     105 [ +  - ][ +  - ]:          1 :     q &= Xapian::Query("baz");
                 [ +  - ]
     106 [ +  - ][ +  - ]:          1 :     TEST_STRINGS_EQUAL(q.get_description(), "Query(((foo OR bar) AND baz))");
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     107                 :            : 
     108                 :            :     // Test |= appends a same-type subquery (since Xapian 1.4.10).
     109 [ +  - ][ +  - ]:          1 :     q = Xapian::Query("foo") | Xapian::Query("bar");
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
     110 [ +  - ][ +  - ]:          1 :     q |= Xapian::Query("baz");
                 [ +  - ]
     111 [ +  - ][ +  - ]:          1 :     TEST_STRINGS_EQUAL(q.get_description(), "Query((foo OR bar OR baz))");
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     112                 :            :     // But not if the RHS is the same query:
     113 [ +  - ][ +  - ]:          1 :     q = Xapian::Query("foo") | Xapian::Query("bar");
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
     114                 :            : #ifdef __has_warning
     115                 :            : # if __has_warning("-Wself-assign-overloaded")
     116                 :            :     // Suppress warning from newer clang about self-assignment so we can
     117                 :            :     // test that self-assignment works!
     118                 :            : #  pragma clang diagnostic push
     119                 :            : #  pragma clang diagnostic ignored "-Wself-assign-overloaded"
     120                 :            : # endif
     121                 :            : #endif
     122         [ +  - ]:          1 :     q |= q;
     123                 :            : #ifdef __has_warning
     124                 :            : # if __has_warning("-Wself-assign-overloaded")
     125                 :            : #  pragma clang diagnostic pop
     126                 :            : # endif
     127                 :            : #endif
     128 [ +  - ][ +  - ]:          1 :     TEST_STRINGS_EQUAL(q.get_description(), "Query(((foo OR bar) OR (foo OR bar)))");
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     129                 :            :     {
     130                 :            :         // Also not if the query has a refcount > 1.
     131 [ +  - ][ +  - ]:          1 :         q = Xapian::Query("foo") | Xapian::Query("bar");
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
     132         [ +  - ]:          1 :         Xapian::Query qcopy = q;
     133 [ +  - ][ +  - ]:          1 :         qcopy |= Xapian::Query("baz");
                 [ +  - ]
     134 [ +  - ][ +  - ]:          1 :         TEST_STRINGS_EQUAL(qcopy.get_description(), "Query(((foo OR bar) OR baz))");
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     135                 :            :         // And q shouldn't change.
     136 [ +  - ][ +  - ]:          1 :         TEST_STRINGS_EQUAL(q.get_description(), "Query((foo OR bar))");
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     137                 :            :     }
     138                 :            :     // Check that MatchNothing still results in no change:
     139 [ +  - ][ +  - ]:          1 :     q = Xapian::Query("foo") | Xapian::Query("bar");
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
     140         [ +  - ]:          1 :     q |= Xapian::Query::MatchNothing;
     141 [ +  - ][ +  - ]:          1 :     TEST_STRINGS_EQUAL(q.get_description(), "Query((foo OR bar))");
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     142                 :            :     // Check we don't combine for other operators:
     143 [ +  - ][ +  - ]:          1 :     q = Xapian::Query("foo") & Xapian::Query("bar");
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
     144 [ +  - ][ +  - ]:          1 :     q |= Xapian::Query("baz");
                 [ +  - ]
     145 [ +  - ][ +  - ]:          1 :     TEST_STRINGS_EQUAL(q.get_description(), "Query(((foo AND bar) OR baz))");
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     146                 :            : 
     147                 :            :     // Test ^= appends a same-type subquery (since Xapian 1.4.10).
     148 [ +  - ][ +  - ]:          1 :     q = Xapian::Query("foo") ^ Xapian::Query("bar");
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
     149 [ +  - ][ +  - ]:          1 :     q ^= Xapian::Query("baz");
                 [ +  - ]
     150 [ +  - ][ +  - ]:          1 :     TEST_STRINGS_EQUAL(q.get_description(), "Query((foo XOR bar XOR baz))");
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     151                 :            :     // But a query ^= itself gives an empty query.
     152 [ +  - ][ +  - ]:          1 :     q = Xapian::Query("foo") ^ Xapian::Query("bar");
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
     153                 :            : #ifdef __has_warning
     154                 :            : # if __has_warning("-Wself-assign-overloaded")
     155                 :            :     // Suppress warning from newer clang about self-assignment so we can
     156                 :            :     // test that self-assignment works!
     157                 :            : #  pragma clang diagnostic push
     158                 :            : #  pragma clang diagnostic ignored "-Wself-assign-overloaded"
     159                 :            : # endif
     160                 :            : #endif
     161         [ +  - ]:          1 :     q ^= q;
     162                 :            : #ifdef __has_warning
     163                 :            : # if __has_warning("-Wself-assign-overloaded")
     164                 :            : #  pragma clang diagnostic pop
     165                 :            : # endif
     166                 :            : #endif
     167 [ +  - ][ +  - ]:          1 :     TEST_STRINGS_EQUAL(q.get_description(), "Query()");
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     168                 :            :     {
     169                 :            :         // Even if the reference count > 1.
     170 [ +  - ][ +  - ]:          1 :         q = Xapian::Query("foo") ^ Xapian::Query("bar");
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
     171         [ +  - ]:          1 :         Xapian::Query qcopy = q;
     172         [ +  - ]:          1 :         q ^= qcopy;
     173 [ +  - ][ +  - ]:          1 :         TEST_STRINGS_EQUAL(q.get_description(), "Query()");
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     174                 :            :     }
     175                 :            :     {
     176                 :            :         // Also not if the query has a refcount > 1.
     177 [ +  - ][ +  - ]:          1 :         q = Xapian::Query("foo") ^ Xapian::Query("bar");
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
     178         [ +  - ]:          1 :         Xapian::Query qcopy = q;
     179 [ +  - ][ +  - ]:          1 :         qcopy ^= Xapian::Query("baz");
                 [ +  - ]
     180 [ +  - ][ +  - ]:          1 :         TEST_STRINGS_EQUAL(qcopy.get_description(), "Query(((foo XOR bar) XOR baz))");
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     181                 :            :         // And q shouldn't change.
     182 [ +  - ][ +  - ]:          1 :         TEST_STRINGS_EQUAL(q.get_description(), "Query((foo XOR bar))");
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     183                 :            :     }
     184                 :            :     // Check that MatchNothing still results in no change:
     185 [ +  - ][ +  - ]:          1 :     q = Xapian::Query("foo") ^ Xapian::Query("bar");
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
     186         [ +  - ]:          1 :     q ^= Xapian::Query::MatchNothing;
     187 [ +  - ][ +  - ]:          1 :     TEST_STRINGS_EQUAL(q.get_description(), "Query((foo XOR bar))");
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     188                 :            :     // Check we don't combine for other operators:
     189 [ +  - ][ +  - ]:          1 :     q = Xapian::Query("foo") & Xapian::Query("bar");
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
     190 [ +  - ][ +  - ]:          1 :     q ^= Xapian::Query("baz");
                 [ +  - ]
     191 [ +  - ][ +  - ]:          1 :     TEST_STRINGS_EQUAL(q.get_description(), "Query(((foo AND bar) XOR baz))");
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     192                 :            : 
     193 [ +  - ][ +  - ]:          1 :     q = Xapian::Query("foo") &~ Xapian::Query("bar");
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
     194 [ +  - ][ +  - ]:          1 :     TEST_STRINGS_EQUAL(q.get_description(), "Query((foo AND_NOT bar))");
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     195                 :            :     // In 1.4.9 and earlier this gave (foo AND (<alldocuments> AND_NOT bar)).
     196 [ +  - ][ +  - ]:          1 :     q = Xapian::Query("foo");
                 [ +  - ]
     197 [ +  - ][ +  - ]:          1 :     q &= ~Xapian::Query("bar");
                 [ +  - ]
     198 [ +  - ][ +  - ]:          1 :     TEST_STRINGS_EQUAL(q.get_description(), "Query((foo AND_NOT bar))");
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     199 [ +  - ][ +  - ]:          1 :     q = ~Xapian::Query("bar");
         [ +  - ][ +  - ]
     200 [ +  - ][ +  - ]:          1 :     TEST_STRINGS_EQUAL(q.get_description(), "Query((<alldocuments> AND_NOT bar))");
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     201 [ +  - ][ +  - ]:          1 :     q = Xapian::Query("foo") & Xapian::Query::MatchNothing;
         [ +  - ][ +  - ]
     202 [ +  - ][ +  - ]:          1 :     TEST_STRINGS_EQUAL(q.get_description(), "Query()");
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     203 [ +  - ][ +  - ]:          1 :     q = Xapian::Query("foo") | Xapian::Query("bar");
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
     204 [ +  - ][ +  - ]:          1 :     TEST_STRINGS_EQUAL(q.get_description(), "Query((foo OR bar))");
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     205 [ +  - ][ +  - ]:          1 :     q = Xapian::Query("foo") | Xapian::Query::MatchNothing;
         [ +  - ][ +  - ]
     206 [ +  - ][ +  - ]:          1 :     TEST_STRINGS_EQUAL(q.get_description(), "Query(foo)");
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     207 [ +  - ][ +  - ]:          1 :     q = Xapian::Query("foo") ^ Xapian::Query("bar");
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
     208 [ +  - ][ +  - ]:          1 :     TEST_STRINGS_EQUAL(q.get_description(), "Query((foo XOR bar))");
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     209 [ +  - ][ +  - ]:          1 :     q = Xapian::Query("foo") ^ Xapian::Query::MatchNothing;
         [ +  - ][ +  - ]
     210 [ +  - ][ +  - ]:          1 :     TEST_STRINGS_EQUAL(q.get_description(), "Query(foo)");
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     211 [ +  - ][ +  - ]:          1 :     q = 1.25 * (Xapian::Query("one") | Xapian::Query("two"));
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
                 [ +  - ]
     212 [ +  - ][ +  - ]:          1 :     TEST_STRINGS_EQUAL(q.get_description(), "Query(1.25 * (one OR two))");
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     213 [ +  - ][ +  - ]:          1 :     q = (Xapian::Query("one") & Xapian::Query("two")) * 42;
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
                 [ +  - ]
     214 [ +  - ][ +  - ]:          1 :     TEST_STRINGS_EQUAL(q.get_description(), "Query(42 * (one AND two))");
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     215 [ +  - ][ +  - ]:          1 :     q = Xapian::Query("one") / 2.0;
         [ +  - ][ +  - ]
     216 [ +  - ][ +  - ]:          1 :     TEST_STRINGS_EQUAL(q.get_description(), "Query(0.5 * one)");
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     217                 :          1 :     return true;
     218                 :            : }
     219                 :            : 
     220                 :            : /** Regression test and feature test.
     221                 :            :  *
     222                 :            :  *  This threw AssertionError in 1.0.9 and earlier (bug#201) and gave valgrind
     223                 :            :  *  errors in 1.0.11 and earlier (bug#349).
     224                 :            :  *
     225                 :            :  *  Currently the OR-subquery case is supported, other operators aren't.
     226                 :            :  */
     227                 :          5 : DEFINE_TESTCASE(possubqueries1, writable) {
     228 [ +  - ][ +  - ]:          5 :     Xapian::WritableDatabase db = get_writable_database();
     229         [ +  - ]:         10 :     Xapian::Document doc;
     230 [ +  - ][ +  - ]:          5 :     doc.add_posting("a", 1);
     231 [ +  - ][ +  - ]:          5 :     doc.add_posting("b", 2);
     232 [ +  - ][ +  - ]:          5 :     doc.add_posting("c", 3);
     233         [ +  - ]:          5 :     db.add_document(doc);
     234                 :            : 
     235                 :            :     Xapian::Query a_or_b(Xapian::Query::OP_OR,
     236                 :            :                          Xapian::Query("a"),
     237 [ +  - ][ +  - ]:         10 :                          Xapian::Query("b"));
         [ +  - ][ +  - ]
                 [ +  - ]
     238         [ +  - ]:         10 :     Xapian::Query near(Xapian::Query::OP_NEAR, a_or_b, a_or_b);
     239                 :            :     // As of 1.3.0, we no longer rearrange queries at this point, so check
     240                 :            :     // that we don't.
     241 [ +  - ][ +  - ]:          5 :     TEST_STRINGS_EQUAL(near.get_description(),
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     242                 :            :                        "Query(((a OR b) NEAR 2 (a OR b)))");
     243         [ +  - ]:         10 :     Xapian::Query phrase(Xapian::Query::OP_PHRASE, a_or_b, a_or_b);
     244 [ +  - ][ +  - ]:          5 :     TEST_STRINGS_EQUAL(phrase.get_description(),
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     245                 :            :                        "Query(((a OR b) PHRASE 2 (a OR b)))");
     246                 :            : 
     247                 :            :     Xapian::Query a_and_b(Xapian::Query::OP_AND,
     248                 :            :                           Xapian::Query("a"),
     249 [ +  - ][ +  - ]:         10 :                           Xapian::Query("b"));
         [ +  - ][ +  - ]
                 [ +  - ]
     250                 :            :     Xapian::Query a_near_b(Xapian::Query::OP_NEAR,
     251                 :            :                            Xapian::Query("a"),
     252 [ +  - ][ +  - ]:         10 :                            Xapian::Query("b"));
         [ +  - ][ +  - ]
                 [ +  - ]
     253                 :            :     Xapian::Query a_phrs_b(Xapian::Query::OP_PHRASE,
     254                 :            :                            Xapian::Query("a"),
     255 [ +  - ][ +  - ]:         10 :                            Xapian::Query("b"));
         [ +  - ][ +  - ]
                 [ +  - ]
     256 [ +  - ][ +  - ]:         10 :     Xapian::Query c("c");
     257                 :            : 
     258                 :            :     // FIXME: The plan is to actually try to support the cases below, but
     259                 :            :     // for now at least ensure they are cleanly rejected.
     260         [ +  - ]:         10 :     Xapian::Enquire enq(db);
     261                 :            : 
     262 [ +  - ][ -  + ]:          5 :     TEST_EXCEPTION(Xapian::UnimplementedError,
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ -  + ][ -  +  
          #  #  #  #  #  
          #  #  #  #  #  
             #  #  #  # ]
                 [ +  - ]
     263                 :            :         Xapian::Query q(Xapian::Query::OP_NEAR, a_and_b, c);
     264                 :            :         enq.set_query(q);
     265                 :            :         (void)enq.get_mset(0, 10));
     266                 :            : 
     267 [ +  - ][ -  +  :          5 :     TEST_EXCEPTION(Xapian::UnimplementedError,
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
              # ][ -  + ]
           [ -  +  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
           #  # ][ +  - ]
     268                 :            :         Xapian::Query q(Xapian::Query::OP_NEAR, a_near_b, c);
     269                 :            :         enq.set_query(q);
     270                 :            :         (void)enq.get_mset(0, 10));
     271                 :            : 
     272 [ +  - ][ -  +  :          5 :     TEST_EXCEPTION(Xapian::UnimplementedError,
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
              # ][ -  + ]
           [ -  +  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
           #  # ][ +  - ]
     273                 :            :         Xapian::Query q(Xapian::Query::OP_NEAR, a_phrs_b, c);
     274                 :            :         enq.set_query(q);
     275                 :            :         (void)enq.get_mset(0, 10));
     276                 :            : 
     277 [ +  - ][ -  +  :          5 :     TEST_EXCEPTION(Xapian::UnimplementedError,
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
              # ][ -  + ]
           [ -  +  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
           #  # ][ +  - ]
     278                 :            :         Xapian::Query q(Xapian::Query::OP_PHRASE, a_and_b, c);
     279                 :            :         enq.set_query(q);
     280                 :            :         (void)enq.get_mset(0, 10));
     281                 :            : 
     282 [ +  - ][ -  +  :          5 :     TEST_EXCEPTION(Xapian::UnimplementedError,
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
              # ][ -  + ]
           [ -  +  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
           #  # ][ +  - ]
     283                 :            :         Xapian::Query q(Xapian::Query::OP_PHRASE, a_near_b, c);
     284                 :            :         enq.set_query(q);
     285                 :            :         (void)enq.get_mset(0, 10));
     286                 :            : 
     287 [ +  - ][ -  +  :          5 :     TEST_EXCEPTION(Xapian::UnimplementedError,
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
              # ][ -  + ]
           [ -  +  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
           #  # ][ +  - ]
     288                 :            :         Xapian::Query q(Xapian::Query::OP_PHRASE, a_phrs_b, c);
     289                 :            :         enq.set_query(q);
     290                 :            :         (void)enq.get_mset(0, 10));
     291                 :            : 
     292                 :          5 :     return true;
     293                 :            : }
     294                 :            : 
     295                 :            : /// Test that XOR handles all remaining subqueries running out at the same
     296                 :            : //  time.
     297                 :          7 : DEFINE_TESTCASE(xor3, backend) {
     298 [ +  - ][ +  - ]:          7 :     Xapian::Database db = get_database("apitest_simpledata");
     299                 :            : 
     300                 :            :     static const char * const subqs[] = {
     301                 :            :         "hack", "which", "paragraph", "is", "return"
     302                 :            :     };
     303                 :            :     // Document where the subqueries run out *does* match XOR:
     304         [ +  - ]:         14 :     Xapian::Query q(Xapian::Query::OP_XOR, subqs, subqs + 5);
     305         [ +  - ]:         14 :     Xapian::Enquire enq(db);
     306         [ +  - ]:          7 :     enq.set_query(q);
     307         [ +  - ]:         14 :     Xapian::MSet mset = enq.get_mset(0, 10);
     308                 :            : 
     309 [ +  - ][ -  + ]:          7 :     TEST_EQUAL(mset.size(), 3);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     310 [ +  - ][ +  - ]:          7 :     TEST_EQUAL(*mset[0], 4);
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     311 [ +  - ][ +  - ]:          7 :     TEST_EQUAL(*mset[1], 2);
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     312 [ +  - ][ +  - ]:          7 :     TEST_EQUAL(*mset[2], 3);
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     313                 :            : 
     314                 :            :     // Document where the subqueries run out *does not* match XOR:
     315 [ +  - ][ +  - ]:          7 :     q = Xapian::Query(Xapian::Query::OP_XOR, subqs, subqs + 4);
     316         [ +  - ]:          7 :     enq.set_query(q);
     317 [ +  - ][ +  - ]:          7 :     mset = enq.get_mset(0, 10);
     318                 :            : 
     319 [ +  - ][ -  + ]:          7 :     TEST_EQUAL(mset.size(), 4);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     320 [ +  - ][ +  - ]:          7 :     TEST_EQUAL(*mset[0], 5);
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     321 [ +  - ][ +  - ]:          7 :     TEST_EQUAL(*mset[1], 4);
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     322 [ +  - ][ +  - ]:          7 :     TEST_EQUAL(*mset[2], 2);
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     323 [ +  - ][ +  - ]:          7 :     TEST_EQUAL(*mset[3], 3);
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     324                 :            : 
     325                 :          7 :     return true;
     326                 :            : }
     327                 :            : 
     328                 :            : /// Check encoding of non-UTF8 terms in query descriptions.
     329                 :          1 : DEFINE_TESTCASE(nonutf8termdesc1, !backend) {
     330 [ +  - ][ +  - ]:          1 :     TEST_EQUAL(Xapian::Query("\xc0\x80\xf5\x80\x80\x80\xfe\xff").get_description(),
         [ +  - ][ +  - ]
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
     331                 :            :                "Query(\\xc0\\x80\\xf5\\x80\\x80\\x80\\xfe\\xff)");
     332 [ +  - ][ +  - ]:          1 :     TEST_EQUAL(Xapian::Query(string("\x00\x1f", 2)).get_description(),
         [ +  - ][ +  - ]
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
     333                 :            :                "Query(\\x00\\x1f)");
     334                 :            :     // Check that backslashes are encoded so output isn't ambiguous.
     335 [ +  - ][ +  - ]:          1 :     TEST_EQUAL(Xapian::Query("back\\slash").get_description(),
         [ +  - ][ +  - ]
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
     336                 :            :                "Query(back\\x5cslash)");
     337                 :            :     // Check that \x7f is escaped.
     338 [ +  - ][ +  - ]:          1 :     TEST_EQUAL(Xapian::Query("D\x7f_\x7f~").get_description(),
         [ +  - ][ +  - ]
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
     339                 :            :                "Query(D\\x7f_\\x7f~)");
     340                 :          1 :     return true;
     341                 :            : }
     342                 :            : 
     343                 :            : /// Test introspection on Query objects.
     344                 :          1 : DEFINE_TESTCASE(queryintro1, !backend) {
     345 [ -  + ][ #  # ]:          1 :     TEST_EQUAL(Xapian::Query::MatchAll.get_type(), Xapian::Query::LEAF_MATCH_ALL);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     346 [ -  + ][ #  # ]:          1 :     TEST_EQUAL(Xapian::Query::MatchAll.get_num_subqueries(), 0);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     347 [ -  + ][ #  # ]:          1 :     TEST_EQUAL(Xapian::Query::MatchNothing.get_type(), Xapian::Query::LEAF_MATCH_NOTHING);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     348 [ -  + ][ #  # ]:          1 :     TEST_EQUAL(Xapian::Query::MatchNothing.get_num_subqueries(), 0);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     349                 :            : 
     350                 :          1 :     Xapian::Query q;
     351 [ +  - ][ +  - ]:          1 :     q = Xapian::Query(q.OP_AND_NOT, Xapian::Query::MatchAll, Xapian::Query("fair"));
         [ +  - ][ +  - ]
     352 [ -  + ][ #  # ]:          1 :     TEST_EQUAL(q.get_type(), q.OP_AND_NOT);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     353 [ -  + ][ #  # ]:          1 :     TEST_EQUAL(q.get_num_subqueries(), 2);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     354 [ +  - ][ -  + ]:          1 :     TEST_EQUAL(q.get_subquery(0).get_type(), q.LEAF_MATCH_ALL);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     355 [ +  - ][ -  + ]:          1 :     TEST_EQUAL(q.get_subquery(1).get_type(), q.LEAF_TERM);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     356                 :            : 
     357 [ +  - ][ +  - ]:          1 :     q = Xapian::Query("foo", 2, 1);
                 [ +  - ]
     358 [ +  - ][ -  + ]:          1 :     TEST_EQUAL(q.get_leaf_wqf(), 2);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     359 [ +  - ][ -  + ]:          1 :     TEST_EQUAL(q.get_leaf_pos(), 1);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     360                 :            : 
     361 [ +  - ][ +  - ]:          1 :     q = Xapian::Query("bar");
                 [ +  - ]
     362 [ +  - ][ -  + ]:          1 :     TEST_EQUAL(q.get_leaf_wqf(), 1);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     363 [ +  - ][ -  + ]:          1 :     TEST_EQUAL(q.get_leaf_pos(), 0);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     364                 :            : 
     365 [ +  - ][ +  - ]:          1 :     q = Xapian::Query("foo") & Xapian::Query("bar");
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
     366 [ -  + ][ #  # ]:          1 :     TEST_EQUAL(q.get_type(), q.OP_AND);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     367                 :            : 
     368 [ +  - ][ +  - ]:          1 :     q = Xapian::Query("foo") &~ Xapian::Query("bar");
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
     369 [ -  + ][ #  # ]:          1 :     TEST_EQUAL(q.get_type(), q.OP_AND_NOT);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     370                 :            : 
     371 [ +  - ][ +  - ]:          1 :     q = ~Xapian::Query("bar");
         [ +  - ][ +  - ]
     372 [ -  + ][ #  # ]:          1 :     TEST_EQUAL(q.get_type(), q.OP_AND_NOT);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     373                 :            : 
     374 [ +  - ][ +  - ]:          1 :     q = Xapian::Query("foo") | Xapian::Query("bar");
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
     375 [ -  + ][ #  # ]:          1 :     TEST_EQUAL(q.get_type(), q.OP_OR);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     376                 :            : 
     377 [ +  - ][ +  - ]:          1 :     q = Xapian::Query("foo") ^ Xapian::Query("bar");
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
     378 [ -  + ][ #  # ]:          1 :     TEST_EQUAL(q.get_type(), q.OP_XOR);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     379                 :            : 
     380 [ +  - ][ +  - ]:          1 :     q = 1.25 * (Xapian::Query("one") | Xapian::Query("two"));
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
                 [ +  - ]
     381 [ -  + ][ #  # ]:          1 :     TEST_EQUAL(q.get_type(), q.OP_SCALE_WEIGHT);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     382 [ -  + ][ #  # ]:          1 :     TEST_EQUAL(q.get_num_subqueries(), 1);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     383 [ +  - ][ -  + ]:          1 :     TEST_EQUAL(q.get_subquery(0).get_type(), q.OP_OR);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     384                 :            : 
     385 [ +  - ][ +  - ]:          1 :     q = Xapian::Query("one") / 2.0;
         [ +  - ][ +  - ]
     386 [ -  + ][ #  # ]:          1 :     TEST_EQUAL(q.get_type(), q.OP_SCALE_WEIGHT);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     387 [ -  + ][ #  # ]:          1 :     TEST_EQUAL(q.get_num_subqueries(), 1);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     388 [ +  - ][ -  + ]:          1 :     TEST_EQUAL(q.get_subquery(0).get_type(), q.LEAF_TERM);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     389                 :            : 
     390 [ +  - ][ +  - ]:          1 :     q = Xapian::Query(q.OP_NEAR, Xapian::Query("a"), Xapian::Query("b"));
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
     391 [ -  + ][ #  # ]:          1 :     TEST_EQUAL(q.get_type(), q.OP_NEAR);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     392 [ -  + ][ #  # ]:          1 :     TEST_EQUAL(q.get_num_subqueries(), 2);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     393 [ +  - ][ -  + ]:          1 :     TEST_EQUAL(q.get_subquery(0).get_type(), q.LEAF_TERM);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     394 [ +  - ][ -  + ]:          1 :     TEST_EQUAL(q.get_subquery(1).get_type(), q.LEAF_TERM);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     395                 :            : 
     396 [ +  - ][ +  - ]:          1 :     q = Xapian::Query(q.OP_PHRASE, Xapian::Query("c"), Xapian::Query("d"));
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
     397 [ -  + ][ #  # ]:          1 :     TEST_EQUAL(q.get_type(), q.OP_PHRASE);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     398 [ -  + ][ #  # ]:          1 :     TEST_EQUAL(q.get_num_subqueries(), 2);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     399 [ +  - ][ -  + ]:          1 :     TEST_EQUAL(q.get_subquery(0).get_type(), q.LEAF_TERM);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     400 [ +  - ][ -  + ]:          1 :     TEST_EQUAL(q.get_subquery(1).get_type(), q.LEAF_TERM);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     401                 :            : 
     402                 :          1 :     return true;
     403                 :            : }
     404                 :            : 
     405                 :            : /// Regression test for bug introduced in 1.3.1 and fixed in 1.3.3.
     406                 :            : //  We were incorrectly converting a term which indexed all docs and was used
     407                 :            : //  in an unweighted phrase into an all docs postlist, so check that this
     408                 :            : //  case actually works.
     409                 :          7 : DEFINE_TESTCASE(phrasealldocs1, backend) {
     410 [ +  - ][ +  - ]:          7 :     Xapian::Database db = get_database("apitest_declen");
     411                 :         14 :     Xapian::Query q;
     412                 :            :     static const char * const phrase[] = { "this", "is", "the" };
     413 [ +  - ][ +  - ]:         14 :     q = Xapian::Query(q.OP_AND_NOT,
         [ +  - ][ +  - ]
     414                 :            :             Xapian::Query("paragraph"),
     415         [ +  - ]:          7 :             Xapian::Query(q.OP_PHRASE, phrase, phrase + 3));
     416         [ +  - ]:         14 :     Xapian::Enquire enq(db);
     417         [ +  - ]:          7 :     enq.set_query(q);
     418         [ +  - ]:         14 :     Xapian::MSet mset = enq.get_mset(0, 10);
     419 [ +  - ][ -  + ]:          7 :     TEST_EQUAL(mset.size(), 3);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     420                 :            : 
     421                 :          7 :     return true;
     422                 :            : }
     423                 :            : 
     424                 :            : struct wildcard_testcase {
     425                 :            :     const char * pattern;
     426                 :            :     Xapian::termcount max_expansion;
     427                 :            :     char max_type;
     428                 :            :     const char * terms[4];
     429                 :            : };
     430                 :            : 
     431                 :            : #define WILDCARD_EXCEPTION { 0, 0, 0, "" }
     432                 :            : static const
     433                 :            : wildcard_testcase wildcard1_testcases[] = {
     434                 :            :     // Tries to expand to 7 terms.
     435                 :            :     { "th",   6, 'E', WILDCARD_EXCEPTION },
     436                 :            :     { "thou", 1, 'E', { "though", 0, 0, 0 } },
     437                 :            :     { "s",    2, 'F', { "say", "search", 0, 0 } },
     438                 :            :     { "s",    2, 'M', { "simpl", "so", 0, 0 } }
     439                 :            : };
     440                 :            : 
     441                 :          7 : DEFINE_TESTCASE(wildcard1, backend) {
     442                 :            :     // FIXME: The counting of terms the wildcard expands to is per subdatabase,
     443                 :            :     // so the wildcard may expand to more terms than the limit if some aren't
     444                 :            :     // in all subdatabases.  Also WILDCARD_LIMIT_MOST_FREQUENT uses the
     445                 :            :     // frequency from the subdatabase, and so may select different terms in
     446                 :            :     // each subdatabase.
     447 [ +  - ][ +  + ]:          7 :     SKIP_TEST_FOR_BACKEND("multi");
     448 [ +  - ][ +  - ]:          6 :     Xapian::Database db = get_database("apitest_simpledata");
     449         [ +  - ]:         12 :     Xapian::Enquire enq(db);
     450                 :          6 :     const Xapian::Query::op o = Xapian::Query::OP_WILDCARD;
     451                 :            : 
     452         [ +  + ]:         30 :     for (auto&& test : wildcard1_testcases) {
     453 [ +  - ][ +  - ]:         24 :         tout << test.pattern << endl;
     454                 :         24 :         auto tend = test.terms + 4;
     455         [ +  + ]:         66 :         while (tend[-1] == NULL) --tend;
     456 [ +  + ][ +  - ]:         24 :         bool expect_exception = (tend - test.terms == 4 && tend[-1][0] == '\0');
     457                 :         24 :         Xapian::Query q;
     458         [ +  - ]:         24 :         if (test.max_type) {
     459                 :            :             int max_type;
     460   [ +  +  +  - ]:         24 :             switch (test.max_type) {
     461                 :            :                 case 'E':
     462                 :         12 :                     max_type = Xapian::Query::WILDCARD_LIMIT_ERROR;
     463                 :         12 :                     break;
     464                 :            :                 case 'F':
     465                 :          6 :                     max_type = Xapian::Query::WILDCARD_LIMIT_FIRST;
     466                 :          6 :                     break;
     467                 :            :                 case 'M':
     468                 :          6 :                     max_type = Xapian::Query::WILDCARD_LIMIT_MOST_FREQUENT;
     469                 :          6 :                     break;
     470                 :            :                 default:
     471                 :          0 :                     return false;
     472                 :            :             }
     473 [ +  - ][ +  - ]:         24 :             q = Xapian::Query(o, test.pattern, test.max_expansion, max_type);
                 [ +  - ]
     474                 :            :         } else {
     475 [ #  # ][ #  # ]:          0 :             q = Xapian::Query(o, test.pattern, test.max_expansion);
                 [ #  # ]
     476                 :            :         }
     477         [ +  - ]:         24 :         enq.set_query(q);
     478                 :            :         try {
     479         [ +  + ]:         24 :             Xapian::MSet mset = enq.get_mset(0, 10);
     480 [ -  + ][ #  # ]:         18 :             TEST(!expect_exception);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
     481 [ +  - ][ +  - ]:         18 :             q = Xapian::Query(q.OP_SYNONYM, test.terms, tend);
     482         [ +  - ]:         18 :             enq.set_query(q);
     483         [ +  - ]:         36 :             Xapian::MSet mset2 = enq.get_mset(0, 10);
     484 [ +  - ][ +  - ]:         18 :             TEST_EQUAL(mset.size(), mset2.size());
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     485 [ +  - ][ +  - ]:         48 :             TEST(mset_range_is_same(mset, 0, mset2, 0, mset.size()));
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ +  - ]
     486 [ -  + ][ +  - ]:         12 :         } catch (const Xapian::WildcardError &) {
     487   [ -  +  #  #  :          6 :             TEST(expect_exception);
          #  #  #  #  #  
          #  #  #  #  #  
                   #  # ]
     488                 :            :         }
     489                 :         24 :     }
     490                 :            : 
     491                 :         12 :     return true;
     492                 :            : }
     493                 :            : 
     494                 :            : /// Regression test for #696, fixed in 1.3.4.
     495                 :          7 : DEFINE_TESTCASE(wildcard2, backend) {
     496                 :            :     // FIXME: The counting of terms the wildcard expands to is per subdatabase,
     497                 :            :     // so the wildcard may expand to more terms than the limit if some aren't
     498                 :            :     // in all subdatabases.  Also WILDCARD_LIMIT_MOST_FREQUENT uses the
     499                 :            :     // frequency from the subdatabase, and so may select different terms in
     500                 :            :     // each subdatabase.
     501 [ +  - ][ +  + ]:          7 :     SKIP_TEST_FOR_BACKEND("multi");
     502 [ +  - ][ +  - ]:          6 :     Xapian::Database db = get_database("apitest_simpledata");
     503         [ +  - ]:         12 :     Xapian::Enquire enq(db);
     504                 :          6 :     const Xapian::Query::op o = Xapian::Query::OP_WILDCARD;
     505                 :            : 
     506                 :          6 :     const int max_type = Xapian::Query::WILDCARD_LIMIT_MOST_FREQUENT;
     507 [ +  - ][ +  - ]:         12 :     Xapian::Query q0(o, "w", 2, max_type);
     508 [ +  - ][ +  - ]:         12 :     Xapian::Query q(o, "s", 2, max_type);
     509 [ +  - ][ +  - ]:         12 :     Xapian::Query q2(o, "t", 2, max_type);
     510 [ +  - ][ +  - ]:          6 :     q = Xapian::Query(q.OP_OR, q0, q);
     511 [ +  - ][ +  - ]:          6 :     q = Xapian::Query(q.OP_OR, q, q2);
     512         [ +  - ]:          6 :     enq.set_query(q);
     513         [ +  - ]:         12 :     Xapian::MSet mset = enq.get_mset(0, 10);
     514 [ +  - ][ -  + ]:          6 :     TEST_EQUAL(mset.size(), 6);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     515                 :            : 
     516                 :          6 :     return true;
     517                 :            : }
     518                 :            : 
     519                 :            : /// Regression test for bug fixed in 1.4.12 - if any terms start with A-Z then
     520                 :            : //  the next term that doesn't isn't considered.
     521                 :          3 : DEFINE_TESTCASE(wildcard3, generated) {
     522                 :            :     Xapian::Database db = get_database("wildcard3",
     523                 :            :                                        [](Xapian::WritableDatabase& wdb,
     524                 :          9 :                                           const string&)
     525                 :            :                                        {
     526         [ +  - ]:          3 :                                            Xapian::Document doc;
     527 [ +  - ][ +  - ]:          3 :                                            doc.add_term("Zfoo");
     528 [ +  - ][ +  - ]:          3 :                                            doc.add_term("a");
     529         [ +  - ]:          3 :                                            wdb.add_document(doc);
     530 [ +  - ][ +  - ]:          3 :                                            doc.add_term("abc");
     531         [ +  - ]:          3 :                                            wdb.add_document(doc);
     532 [ +  - ][ +  - ]:         12 :                                        });
                 [ +  - ]
     533                 :            : 
     534         [ +  - ]:          6 :     Xapian::Enquire enq(db);
     535                 :            :     Xapian::Query q(Xapian::Query::OP_WILDCARD, "?", 0,
     536 [ +  - ][ +  - ]:          6 :                     Xapian::Query::WILDCARD_PATTERN_GLOB);
     537         [ +  - ]:          3 :     enq.set_query(q);
     538         [ +  - ]:          6 :     Xapian::MSet mset = enq.get_mset(0, 10);
     539 [ +  - ][ -  + ]:          3 :     TEST_EQUAL(mset.size(), 2);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     540                 :            : 
     541                 :          3 :     return true;
     542                 :            : }
     543                 :            : 
     544                 :          7 : DEFINE_TESTCASE(dualprefixwildcard1, backend) {
     545 [ +  - ][ +  - ]:          7 :     Xapian::Database db = get_database("apitest_simpledata");
     546                 :            :     Xapian::Query q(Xapian::Query::OP_SYNONYM,
     547                 :            :                     Xapian::Query(Xapian::Query::OP_WILDCARD, "fo"),
     548 [ +  - ][ +  - ]:         14 :                     Xapian::Query(Xapian::Query::OP_WILDCARD, "Sfo"));
         [ +  - ][ +  - ]
                 [ +  - ]
     549 [ +  - ][ +  - ]:          7 :     tout << q.get_description() << endl;
                 [ +  - ]
     550         [ +  - ]:         14 :     Xapian::Enquire enq(db);
     551         [ +  - ]:          7 :     enq.set_query(q);
     552 [ +  - ][ +  - ]:          7 :     TEST_EQUAL(enq.get_mset(0, 5).size(), 2);
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     553                 :          7 :     return true;
     554                 :            : }
     555                 :            : 
     556                 :            : /// Test special case wildcards.
     557                 :          1 : DEFINE_TESTCASE(specialwildcard1, !backend) {
     558                 :          1 :     const Xapian::Query::op o = Xapian::Query::OP_WILDCARD;
     559                 :          1 :     const auto f = Xapian::Query::WILDCARD_PATTERN_GLOB;
     560                 :            : 
     561                 :            :     // Empty wildcard -> MatchNothing.
     562 [ +  - ][ +  - ]:          1 :     TEST_EQUAL(Xapian::Query(o, "", 0, f).get_description(), "Query()");
         [ +  - ][ +  - ]
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
     563                 :            : 
     564                 :            :     // "*", "?*", etc -> MatchAll.
     565                 :            : #define QUERY_ALLDOCS "Query(<alldocuments>)"
     566 [ +  - ][ +  - ]:          1 :     TEST_EQUAL(Xapian::Query(o, "*", 0, f).get_description(), QUERY_ALLDOCS);
         [ +  - ][ +  - ]
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
     567 [ +  - ][ +  - ]:          1 :     TEST_EQUAL(Xapian::Query(o, "**", 0, f).get_description(), QUERY_ALLDOCS);
         [ +  - ][ +  - ]
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
     568 [ +  - ][ +  - ]:          1 :     TEST_EQUAL(Xapian::Query(o, "?*", 0, f).get_description(), QUERY_ALLDOCS);
         [ +  - ][ +  - ]
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
     569 [ +  - ][ +  - ]:          1 :     TEST_EQUAL(Xapian::Query(o, "*?", 0, f).get_description(), QUERY_ALLDOCS);
         [ +  - ][ +  - ]
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
     570 [ +  - ][ +  - ]:          1 :     TEST_EQUAL(Xapian::Query(o, "*?*", 0, f).get_description(), QUERY_ALLDOCS);
         [ +  - ][ +  - ]
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
     571                 :            : 
     572                 :          1 :     return true;
     573                 :            : }
     574                 :            : 
     575                 :            : /// Test `?` extended wildcard.
     576                 :          5 : DEFINE_TESTCASE(singlecharwildcard1, writable) {
     577 [ +  - ][ +  - ]:          5 :     Xapian::WritableDatabase db = get_writable_database();
     578                 :            :     {
     579         [ +  - ]:          5 :         Xapian::Document doc;
     580 [ +  - ][ +  - ]:          5 :         doc.add_term("test");
     581         [ +  - ]:          5 :         db.add_document(doc);
     582                 :            :     }
     583                 :            :     {
     584         [ +  - ]:          5 :         Xapian::Document doc;
     585 [ +  - ][ +  - ]:          5 :         doc.add_term("t\xc3\xaast");
     586         [ +  - ]:          5 :         db.add_document(doc);
     587                 :            :     }
     588                 :            :     {
     589         [ +  - ]:          5 :         Xapian::Document doc;
     590 [ +  - ][ +  - ]:          5 :         doc.add_term("t\xe1\x80\x80st");
     591         [ +  - ]:          5 :         db.add_document(doc);
     592                 :            :     }
     593                 :            :     {
     594         [ +  - ]:          5 :         Xapian::Document doc;
     595 [ +  - ][ +  - ]:          5 :         doc.add_term("t\xf3\x80\x80\x80st");
     596         [ +  - ]:          5 :         db.add_document(doc);
     597                 :            :     }
     598                 :            :     {
     599         [ +  - ]:          5 :         Xapian::Document doc;
     600 [ +  - ][ +  - ]:          5 :         doc.add_term("toast");
     601         [ +  - ]:          5 :         db.add_document(doc);
     602                 :            :     }
     603                 :            :     {
     604         [ +  - ]:          5 :         Xapian::Document doc;
     605 [ +  - ][ +  - ]:          5 :         doc.add_term("t*t");
     606         [ +  - ]:          5 :         db.add_document(doc);
     607                 :            :     }
     608         [ +  - ]:          5 :     db.commit();
     609                 :            : 
     610         [ +  - ]:         10 :     Xapian::Enquire enq(db);
     611         [ +  - ]:          5 :     enq.set_weighting_scheme(Xapian::BoolWeight());
     612                 :            : 
     613                 :          5 :     const Xapian::Query::op o = Xapian::Query::OP_WILDCARD;
     614                 :          5 :     const auto f = Xapian::Query::WILDCARD_PATTERN_SINGLE;
     615                 :            : 
     616                 :            :     {
     617                 :            :         // Check that `?` matches one Unicode character.
     618 [ +  - ][ +  - ]:          5 :         enq.set_query(Xapian::Query(o, "t?st", 0, f));
                 [ +  - ]
     619         [ +  - ]:          5 :         Xapian::MSet mset = enq.get_mset(0, 100);
     620         [ +  - ]:          5 :         mset_expect_order(mset, 1, 2, 3, 4);
     621                 :            :     }
     622                 :            : 
     623                 :            :     {
     624                 :            :         // Check that `??` doesn't match a single two-byte UTF-8 character.
     625 [ +  - ][ +  - ]:          5 :         enq.set_query(Xapian::Query(o, "t??st", 0, f));
                 [ +  - ]
     626         [ +  - ]:          5 :         Xapian::MSet mset = enq.get_mset(0, 100);
     627         [ +  - ]:          5 :         mset_expect_order(mset, 5);
     628                 :            :     }
     629                 :            : 
     630                 :            :     {
     631                 :            :         // Check that `*` is handled as a literal character not a wildcard.
     632 [ +  - ][ +  - ]:          5 :         enq.set_query(Xapian::Query(o, "t*t", 0, f));
                 [ +  - ]
     633         [ +  - ]:          5 :         Xapian::MSet mset = enq.get_mset(0, 100);
     634         [ +  - ]:          5 :         mset_expect_order(mset, 6);
     635                 :            :     }
     636                 :            : 
     637                 :          5 :     return true;
     638                 :            : }
     639                 :            : 
     640                 :            : /// Test `*` extended wildcard.
     641                 :          5 : DEFINE_TESTCASE(multicharwildcard1, writable) {
     642 [ +  - ][ +  - ]:          5 :     Xapian::WritableDatabase db = get_writable_database();
     643                 :            :     {
     644         [ +  - ]:          5 :         Xapian::Document doc;
     645 [ +  - ][ +  - ]:          5 :         doc.add_term("ananas");
     646         [ +  - ]:          5 :         db.add_document(doc);
     647                 :            :     }
     648                 :            :     {
     649         [ +  - ]:          5 :         Xapian::Document doc;
     650 [ +  - ][ +  - ]:          5 :         doc.add_term("annas");
     651         [ +  - ]:          5 :         db.add_document(doc);
     652                 :            :     }
     653                 :            :     {
     654         [ +  - ]:          5 :         Xapian::Document doc;
     655 [ +  - ][ +  - ]:          5 :         doc.add_term("bananas");
     656         [ +  - ]:          5 :         db.add_document(doc);
     657                 :            :     }
     658                 :            :     {
     659         [ +  - ]:          5 :         Xapian::Document doc;
     660 [ +  - ][ +  - ]:          5 :         doc.add_term("banannas");
     661         [ +  - ]:          5 :         db.add_document(doc);
     662                 :            :     }
     663                 :            :     {
     664         [ +  - ]:          5 :         Xapian::Document doc;
     665 [ +  - ][ +  - ]:          5 :         doc.add_term("b?nanas");
     666         [ +  - ]:          5 :         db.add_document(doc);
     667                 :            :     }
     668         [ +  - ]:          5 :     db.commit();
     669                 :            : 
     670         [ +  - ]:         10 :     Xapian::Enquire enq(db);
     671         [ +  - ]:          5 :     enq.set_weighting_scheme(Xapian::BoolWeight());
     672                 :            : 
     673                 :          5 :     const Xapian::Query::op o = Xapian::Query::OP_WILDCARD;
     674                 :          5 :     const auto f = Xapian::Query::WILDCARD_PATTERN_MULTI;
     675                 :            : 
     676                 :            :     {
     677                 :            :         // Check `*` can handle partial matches before and after.
     678 [ +  - ][ +  - ]:          5 :         enq.set_query(Xapian::Query(o, "b*anas", 0, f));
                 [ +  - ]
     679         [ +  - ]:          5 :         Xapian::MSet mset = enq.get_mset(0, 100);
     680         [ +  - ]:          5 :         mset_expect_order(mset, 3, 5);
     681                 :            :     }
     682                 :            : 
     683                 :            :     {
     684                 :            :         // Check leading `*` works.
     685 [ +  - ][ +  - ]:          5 :         enq.set_query(Xapian::Query(o, "*anas", 0, f));
                 [ +  - ]
     686         [ +  - ]:          5 :         Xapian::MSet mset = enq.get_mset(0, 100);
     687         [ +  - ]:          5 :         mset_expect_order(mset, 1, 3, 5);
     688                 :            :     }
     689                 :            : 
     690                 :            :     {
     691                 :            :         // Check more than one `*` works.
     692 [ +  - ][ +  - ]:          5 :         enq.set_query(Xapian::Query(o, "*ann*", 0, f));
                 [ +  - ]
     693         [ +  - ]:          5 :         Xapian::MSet mset = enq.get_mset(0, 100);
     694         [ +  - ]:          5 :         mset_expect_order(mset, 2, 4);
     695                 :            :     }
     696                 :            : 
     697                 :            :     {
     698                 :            :         // Check that `?` is handled as a literal character not a wildcard.
     699 [ +  - ][ +  - ]:          5 :         enq.set_query(Xapian::Query(o, "b?n*", 0, f));
                 [ +  - ]
     700         [ +  - ]:          5 :         Xapian::MSet mset = enq.get_mset(0, 100);
     701         [ +  - ]:          5 :         mset_expect_order(mset, 5);
     702                 :            :     }
     703                 :            : 
     704                 :          5 :     return true;
     705                 :            : }
     706                 :            : 
     707                 :            : struct editdist_testcase {
     708                 :            :     const char* target;
     709                 :            :     unsigned edit_distance;
     710                 :            :     Xapian::termcount max_expansion;
     711                 :            :     char max_type;
     712                 :            :     const char* terms[4];
     713                 :            : };
     714                 :            : 
     715                 :            : #define EDITDIST_EXCEPTION { 0, 0, 0, "" }
     716                 :            : static const
     717                 :            : editdist_testcase editdist1_testcases[] = {
     718                 :            :     // Tries to expand to 9 terms.
     719                 :            :     { "muse", 2, 8, 'E', EDITDIST_EXCEPTION },
     720                 :            :     { "museum",       3, 3, 'E', { "mset", "must", "use", 0 } },
     721                 :            :     { "thou", 0, 9, 'E', { 0, 0, 0, 0 } },
     722                 :            :     { "though",       0, 9, 'E', { "though", 0, 0, 0 } },
     723                 :            :     { "museum",       3, 1, 'F', { "mset", 0, 0, 0 } },
     724                 :            :     { "museum",       3, 1, 'M', { "use", 0, 0, 0 } },
     725                 :            : };
     726                 :            : 
     727                 :          7 : DEFINE_TESTCASE(editdist1, backend) {
     728                 :            :     // FIXME: The counting of terms the subquery expands to is per subdatabase,
     729                 :            :     // so it may expand to more terms than the limit if some aren't in all
     730                 :            :     // subdatabases.  Also WILDCARD_LIMIT_MOST_FREQUENT uses the frequency from
     731                 :            :     // the subdatabase, and so may select different terms in each subdatabase.
     732 [ +  - ][ +  + ]:          7 :     SKIP_TEST_FOR_BACKEND("multi");
     733 [ +  - ][ +  - ]:          6 :     Xapian::Database db = get_database("apitest_simpledata");
     734         [ +  - ]:         12 :     Xapian::Enquire enq(db);
     735                 :          6 :     const Xapian::Query::op o = Xapian::Query::OP_EDIT_DISTANCE;
     736                 :            : 
     737         [ +  + ]:         42 :     for (auto&& test : editdist1_testcases) {
     738 [ +  - ][ +  - ]:         36 :         tout << test.target << endl;
     739                 :         36 :         auto tend = test.terms + 4;
     740 [ +  + ][ +  + ]:        120 :         while (tend > test.terms && tend[-1] == NULL) --tend;
     741 [ +  + ][ +  - ]:         36 :         bool expect_exception = (tend - test.terms == 4 && tend[-1][0] == '\0');
     742                 :         36 :         Xapian::Query q;
     743                 :            :         int max_type;
     744   [ +  +  +  - ]:         36 :         switch (test.max_type) {
     745                 :            :             case 'E':
     746                 :         24 :                 max_type = Xapian::Query::WILDCARD_LIMIT_ERROR;
     747                 :         24 :                 break;
     748                 :            :             case 'F':
     749                 :          6 :                 max_type = Xapian::Query::WILDCARD_LIMIT_FIRST;
     750                 :          6 :                 break;
     751                 :            :             case 'M':
     752                 :          6 :                 max_type = Xapian::Query::WILDCARD_LIMIT_MOST_FREQUENT;
     753                 :          6 :                 break;
     754                 :            :             default:
     755                 :          0 :                 return false;
     756                 :            :         }
     757 [ +  - ][ +  - ]:         72 :         q = Xapian::Query(o, test.target, test.max_expansion, max_type,
     758         [ +  - ]:         36 :                           q.OP_SYNONYM, test.edit_distance);
     759         [ +  - ]:         36 :         enq.set_query(q);
     760 [ +  - ][ +  - ]:         36 :         tout << q.get_description() << endl;
                 [ +  - ]
     761                 :            :         try {
     762         [ +  + ]:         36 :             Xapian::MSet mset = enq.get_mset(0, 10);
     763 [ -  + ][ #  # ]:         30 :             TEST(!expect_exception);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
     764 [ +  - ][ +  - ]:         30 :             q = Xapian::Query(q.OP_SYNONYM, test.terms, tend);
     765         [ +  - ]:         30 :             enq.set_query(q);
     766         [ +  - ]:         60 :             Xapian::MSet mset2 = enq.get_mset(0, 10);
     767 [ +  - ][ +  - ]:         30 :             TEST_EQUAL(mset.size(), mset2.size());
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     768 [ +  - ][ +  - ]:         72 :             TEST(mset_range_is_same(mset, 0, mset2, 0, mset.size()));
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ +  - ]
     769 [ -  + ][ +  - ]:         12 :         } catch (const Xapian::WildcardError&) {
     770   [ -  +  #  #  :          6 :             TEST(expect_exception);
          #  #  #  #  #  
          #  #  #  #  #  
                   #  # ]
     771                 :            :         }
     772                 :         36 :     }
     773                 :            : 
     774                 :         12 :     return true;
     775                 :            : }
     776                 :            : 
     777                 :          3 : DEFINE_TESTCASE(dualprefixeditdist1, generated) {
     778                 :            :     Xapian::Database db = get_database("dualprefixeditdist1",
     779                 :            :                                        [](Xapian::WritableDatabase& wdb,
     780                 :          9 :                                           const string&)
     781                 :            :                                        {
     782         [ +  - ]:          3 :                                            Xapian::Document doc;
     783 [ +  - ][ +  - ]:          3 :                                            doc.add_term("opossum");
     784 [ +  - ][ +  - ]:          3 :                                            doc.add_term("possum");
     785         [ +  - ]:          3 :                                            wdb.add_document(doc);
     786         [ +  - ]:          3 :                                            doc.clear_terms();
     787 [ +  - ][ +  - ]:          3 :                                            doc.add_term("Spossums");
     788         [ +  - ]:          3 :                                            wdb.add_document(doc);
     789 [ +  - ][ +  - ]:         12 :                                        });
                 [ +  - ]
     790                 :            : 
     791                 :          3 :     auto OP_EDIT_DISTANCE = Xapian::Query::OP_EDIT_DISTANCE;
     792                 :          3 :     auto OP_SYNONYM = Xapian::Query::OP_SYNONYM;
     793 [ +  - ][ +  - ]:          6 :     Xapian::Query q0(OP_EDIT_DISTANCE, "possum");
     794 [ +  - ][ +  - ]:          6 :     Xapian::Query q1(OP_EDIT_DISTANCE, "Spossum", 0, 0, OP_SYNONYM, 2, 1);
     795         [ +  - ]:          6 :     Xapian::Query q(OP_SYNONYM, q0, q1);
     796 [ +  - ][ +  - ]:          3 :     tout << q.get_description() << endl;
                 [ +  - ]
     797         [ +  - ]:          6 :     Xapian::Enquire enq(db);
     798         [ +  - ]:          3 :     enq.set_query(q0);
     799         [ +  - ]:          6 :     Xapian::MSet mset = enq.get_mset(0, 5);
     800 [ +  - ][ -  + ]:          3 :     TEST_EQUAL(mset.size(), 1);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     801 [ +  - ][ +  - ]:          3 :     TEST_EQUAL(*mset[0], 1);
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     802         [ +  - ]:          3 :     enq.set_query(q1);
     803 [ +  - ][ +  - ]:          3 :     mset = enq.get_mset(0, 5);
     804 [ +  - ][ -  + ]:          3 :     TEST_EQUAL(mset.size(), 1);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     805 [ +  - ][ +  - ]:          3 :     TEST_EQUAL(*mset[0], 2);
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     806         [ +  - ]:          3 :     enq.set_query(q);
     807 [ +  - ][ +  - ]:          3 :     mset = enq.get_mset(0, 5);
     808 [ +  - ][ -  + ]:          3 :     TEST_EQUAL(mset.size(), 2);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     809                 :            : 
     810                 :          3 :     return true;
     811                 :            : }
     812                 :            : 
     813                 :            : struct positional_testcase {
     814                 :            :     int window;
     815                 :            :     const char * terms[4];
     816                 :            :     Xapian::docid result;
     817                 :            : };
     818                 :            : 
     819                 :            : static const
     820                 :            : positional_testcase loosephrase1_testcases[] = {
     821                 :            :     { 5, { "expect", "to", "mset", 0 }, 0 },
     822                 :            :     { 5, { "word", "well", "the", 0 }, 2 },
     823                 :            :     { 5, { "if", "word", "doesnt", 0 }, 0 },
     824                 :            :     { 5, { "at", "line", "three", 0 }, 0 },
     825                 :            :     { 5, { "paragraph", "other", "the", 0 }, 0 },
     826                 :            :     { 5, { "other", "the", "with", 0 }, 0 }
     827                 :            : };
     828                 :            : 
     829                 :            : /// Regression test for bug fixed in 1.3.3 and 1.2.21.
     830                 :          7 : DEFINE_TESTCASE(loosephrase1, backend) {
     831 [ +  - ][ +  - ]:          7 :     Xapian::Database db = get_database("apitest_simpledata");
     832         [ +  - ]:         14 :     Xapian::Enquire enq(db);
     833                 :            : 
     834         [ +  + ]:         49 :     for (auto&& test : loosephrase1_testcases) {
     835                 :         42 :         auto tend = test.terms + 4;
     836         [ +  + ]:         84 :         while (tend[-1] == NULL) --tend;
     837                 :         42 :         auto OP_PHRASE = Xapian::Query::OP_PHRASE;
     838         [ +  - ]:         42 :         Xapian::Query q(OP_PHRASE, test.terms, tend, test.window);
     839         [ +  - ]:         42 :         enq.set_query(q);
     840         [ +  - ]:         84 :         Xapian::MSet mset = enq.get_mset(0, 10);
     841         [ +  + ]:         42 :         if (test.result == 0) {
     842 [ +  - ][ -  + ]:         35 :             TEST(mset.empty());
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     843                 :            :         } else {
     844 [ +  - ][ -  + ]:          7 :             TEST_EQUAL(mset.size(), 1);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     845 [ +  - ][ +  - ]:          7 :             TEST_EQUAL(*mset[0], test.result);
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     846                 :            :         }
     847                 :         42 :     }
     848                 :            : 
     849                 :          7 :     return true;
     850                 :            : }
     851                 :            : 
     852                 :            : static const
     853                 :            : positional_testcase loosenear1_testcases[] = {
     854                 :            :     { 4, { "test", "the", "with", 0 }, 1 },
     855                 :            :     { 4, { "expect", "word", "the", 0 }, 2 },
     856                 :            :     { 4, { "line", "be", "blank", 0 }, 1 },
     857                 :            :     { 2, { "banana", "banana", 0, 0 }, 0 },
     858                 :            :     { 3, { "banana", "banana", 0, 0 }, 0 },
     859                 :            :     { 2, { "word", "word", 0, 0 }, 2 },
     860                 :            :     { 4, { "work", "meant", "work", 0 }, 0 },
     861                 :            :     { 4, { "this", "one", "yet", "one" }, 0 }
     862                 :            : };
     863                 :            : 
     864                 :            : /// Regression tests for bugs fixed in 1.3.3 and 1.2.21.
     865                 :          7 : DEFINE_TESTCASE(loosenear1, backend) {
     866 [ +  - ][ +  - ]:          7 :     Xapian::Database db = get_database("apitest_simpledata");
     867         [ +  - ]:         14 :     Xapian::Enquire enq(db);
     868                 :            : 
     869         [ +  + ]:         63 :     for (auto&& test : loosenear1_testcases) {
     870                 :         56 :         auto tend = test.terms + 4;
     871         [ +  + ]:        126 :         while (tend[-1] == NULL) --tend;
     872         [ +  - ]:         56 :         Xapian::Query q(Xapian::Query::OP_NEAR, test.terms, tend, test.window);
     873         [ +  - ]:         56 :         enq.set_query(q);
     874         [ +  - ]:        112 :         Xapian::MSet mset = enq.get_mset(0, 10);
     875         [ +  + ]:         56 :         if (test.result == 0) {
     876 [ +  - ][ -  + ]:         28 :             TEST(mset.empty());
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     877                 :            :         } else {
     878 [ +  - ][ -  + ]:         28 :             TEST_EQUAL(mset.size(), 1);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     879 [ +  - ][ +  - ]:         28 :             TEST_EQUAL(*mset[0], test.result);
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     880                 :            :         }
     881                 :         56 :     }
     882                 :            : 
     883                 :          7 :     return true;
     884                 :            : }
     885                 :            : 
     886                 :            : /// Regression test for bug fixed in 1.3.6 - the first case segfaulted in 1.3.x.
     887                 :          7 : DEFINE_TESTCASE(complexphrase1, backend) {
     888 [ +  - ][ +  - ]:          7 :     Xapian::Database db = get_database("apitest_simpledata");
     889         [ +  - ]:         14 :     Xapian::Enquire enq(db);
     890                 :            :     Xapian::Query query(Xapian::Query::OP_PHRASE,
     891 [ +  - ][ +  - ]:         14 :             Xapian::Query("a") | Xapian::Query("b"),
         [ +  - ][ +  - ]
                 [ +  - ]
     892 [ +  - ][ +  - ]:         28 :             Xapian::Query("i"));
                 [ +  - ]
     893         [ +  - ]:          7 :     enq.set_query(query);
     894 [ +  - ][ +  - ]:          7 :     TEST(enq.get_mset(0, 10).empty());
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
     895                 :            :     Xapian::Query query2(Xapian::Query::OP_PHRASE,
     896 [ +  - ][ +  - ]:         14 :             Xapian::Query("a") | Xapian::Query("b"),
         [ +  - ][ +  - ]
                 [ +  - ]
     897 [ +  - ][ +  - ]:         28 :             Xapian::Query("c"));
                 [ +  - ]
     898         [ +  - ]:          7 :     enq.set_query(query2);
     899 [ +  - ][ +  - ]:          7 :     TEST(enq.get_mset(0, 10).empty());
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
     900                 :          7 :     return true;
     901                 :            : }
     902                 :            : 
     903                 :            : /// Regression test for bug fixed in 1.3.6 - the first case segfaulted in 1.3.x.
     904                 :          7 : DEFINE_TESTCASE(complexnear1, backend) {
     905 [ +  - ][ +  - ]:          7 :     Xapian::Database db = get_database("apitest_simpledata");
     906         [ +  - ]:         14 :     Xapian::Enquire enq(db);
     907                 :            :     Xapian::Query query(Xapian::Query::OP_NEAR,
     908 [ +  - ][ +  - ]:         14 :             Xapian::Query("a") | Xapian::Query("b"),
         [ +  - ][ +  - ]
                 [ +  - ]
     909 [ +  - ][ +  - ]:         28 :             Xapian::Query("i"));
                 [ +  - ]
     910         [ +  - ]:          7 :     enq.set_query(query);
     911 [ +  - ][ +  - ]:          7 :     TEST(enq.get_mset(0, 10).empty());
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
     912                 :            :     Xapian::Query query2(Xapian::Query::OP_NEAR,
     913 [ +  - ][ +  - ]:         14 :             Xapian::Query("a") | Xapian::Query("b"),
         [ +  - ][ +  - ]
                 [ +  - ]
     914 [ +  - ][ +  - ]:         28 :             Xapian::Query("c"));
                 [ +  - ]
     915         [ +  - ]:          7 :     enq.set_query(query2);
     916 [ +  - ][ +  - ]:          7 :     TEST(enq.get_mset(0, 10).empty());
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
     917                 :          7 :     return true;
     918                 :            : }
     919                 :            : 
     920                 :            : /// Check subqueries of MatchAll, MatchNothing and PostingSource are supported.
     921                 :          7 : DEFINE_TESTCASE(complexphrase2, backend) {
     922 [ +  - ][ +  - ]:          7 :     Xapian::Database db = get_database("apitest_simpledata");
     923         [ +  - ]:         14 :     Xapian::Enquire enq(db);
     924         [ +  - ]:         14 :     Xapian::ValueWeightPostingSource ps(0);
     925                 :            :     Xapian::Query subqs[3] = {
     926                 :            :         Xapian::Query(Xapian::Query::OP_PHRASE,
     927                 :            :             Xapian::Query("a"),
     928                 :            :             Xapian::Query(&ps)),
     929                 :            :         Xapian::Query(Xapian::Query::OP_PHRASE,
     930                 :            :             Xapian::Query("and"),
     931                 :            :             Xapian::Query::MatchAll),
     932                 :            :         Xapian::Query(Xapian::Query::OP_PHRASE,
     933                 :            :             Xapian::Query("at"),
     934                 :            :             Xapian::Query::MatchNothing)
     935 [ +  - ][ +  - ]:         35 :     };
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  + ][ #  #  
             #  #  #  # ]
     936         [ +  - ]:         14 :     Xapian::Query query(Xapian::Query::OP_OR, subqs, subqs + 3);
     937         [ +  - ]:          7 :     enq.set_query(query);
     938         [ +  - ]:          7 :     (void)enq.get_mset(0, 10);
     939                 :          7 :     return true;
     940                 :            : }
     941                 :            : 
     942                 :            : /// Check subqueries of MatchAll, MatchNothing and PostingSource are supported.
     943                 :          7 : DEFINE_TESTCASE(complexnear2, backend) {
     944 [ +  - ][ +  - ]:          7 :     Xapian::Database db = get_database("apitest_simpledata");
     945         [ +  - ]:         14 :     Xapian::Enquire enq(db);
     946         [ +  - ]:         14 :     Xapian::ValueWeightPostingSource ps(0);
     947                 :            :     Xapian::Query subqs[3] = {
     948                 :            :         Xapian::Query(Xapian::Query::OP_NEAR,
     949                 :            :             Xapian::Query("a"),
     950                 :            :             Xapian::Query(&ps)),
     951                 :            :         Xapian::Query(Xapian::Query::OP_NEAR,
     952                 :            :             Xapian::Query("and"),
     953                 :            :             Xapian::Query::MatchAll),
     954                 :            :         Xapian::Query(Xapian::Query::OP_NEAR,
     955                 :            :             Xapian::Query("at"),
     956                 :            :             Xapian::Query::MatchNothing)
     957 [ +  - ][ +  - ]:         35 :     };
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  + ][ #  #  
             #  #  #  # ]
     958         [ +  - ]:         14 :     Xapian::Query query(Xapian::Query::OP_OR, subqs, subqs + 3);
     959         [ +  - ]:          7 :     enq.set_query(query);
     960         [ +  - ]:          7 :     (void)enq.get_mset(0, 10);
     961                 :          7 :     return true;
     962                 :            : }
     963                 :            : 
     964                 :            : /// A zero estimated number of matches broke the code to round the estimate.
     965                 :          7 : DEFINE_TESTCASE(zeroestimate1, backend) {
     966 [ +  - ][ +  - ]:          7 :     Xapian::Enquire enquire(get_database("apitest_simpledata"));
                 [ +  - ]
     967                 :            :     Xapian::Query phrase(Xapian::Query::OP_PHRASE,
     968                 :            :                          Xapian::Query("absolute"),
     969 [ +  - ][ +  - ]:         14 :                          Xapian::Query("rubbish"));
         [ +  - ][ +  - ]
                 [ +  - ]
     970 [ +  - ][ +  - ]:          7 :     enquire.set_query(phrase &~ Xapian::Query("queri"));
         [ +  - ][ +  - ]
     971         [ +  - ]:         14 :     Xapian::MSet mset = enquire.get_mset(0, 0);
     972 [ +  - ][ -  + ]:          7 :     TEST_EQUAL(mset.get_matches_estimated(), 0);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     973                 :          7 :     return true;
     974                 :            : }
     975                 :            : 
     976                 :            : /// Feature test for OR under OP_PHRASE support added in 1.4.3.
     977                 :          7 : DEFINE_TESTCASE(complexphrase3, backend) {
     978 [ +  - ][ +  - ]:          7 :     Xapian::Database db = get_database("apitest_simpledata");
     979         [ +  - ]:         14 :     Xapian::Enquire enq(db);
     980                 :            :     Xapian::Query query(Xapian::Query::OP_PHRASE,
     981 [ +  - ][ +  - ]:         14 :             Xapian::Query("is") | Xapian::Query("as") | Xapian::Query("be"),
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
     982 [ +  - ][ +  - ]:         28 :             Xapian::Query("a"));
                 [ +  - ]
     983         [ +  - ]:          7 :     enq.set_query(query);
     984 [ +  - ][ +  - ]:          7 :     mset_expect_order(enq.get_mset(0, 10), 1);
     985                 :            :     Xapian::Query query2(Xapian::Query::OP_PHRASE,
     986                 :            :             Xapian::Query("a"),
     987 [ +  - ][ +  - ]:         14 :             Xapian::Query("is") | Xapian::Query("as") | Xapian::Query("be"));
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
                 [ +  - ]
     988         [ +  - ]:          7 :     enq.set_query(query2);
     989 [ +  - ][ +  - ]:          7 :     mset_expect_order(enq.get_mset(0, 10));
     990                 :            :     Xapian::Query query3(Xapian::Query::OP_PHRASE,
     991 [ +  - ][ +  - ]:         14 :             Xapian::Query("one") | Xapian::Query("with"),
         [ +  - ][ +  - ]
                 [ +  - ]
     992 [ +  - ][ +  - ]:         28 :             Xapian::Query("the") | Xapian::Query("of") | Xapian::Query("line"));
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
                 [ +  - ]
     993         [ +  - ]:          7 :     enq.set_query(query3);
     994 [ +  - ][ +  - ]:          7 :     mset_expect_order(enq.get_mset(0, 10), 1, 4, 5);
     995                 :            :     Xapian::Query query4(Xapian::Query::OP_PHRASE,
     996 [ +  - ][ +  - ]:         14 :             Xapian::Query("the") | Xapian::Query("of") | Xapian::Query("line"),
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
     997 [ +  - ][ +  - ]:         28 :             Xapian::Query("one") | Xapian::Query("with"));
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
     998         [ +  - ]:          7 :     enq.set_query(query4);
     999 [ +  - ][ +  - ]:          7 :     mset_expect_order(enq.get_mset(0, 10));
    1000                 :          7 :     return true;
    1001                 :            : }
    1002                 :            : 
    1003                 :            : /// Feature test for OR under OP_NEAR support added in 1.4.3.
    1004                 :          7 : DEFINE_TESTCASE(complexnear3, backend) {
    1005 [ +  - ][ +  - ]:          7 :     Xapian::Database db = get_database("apitest_simpledata");
    1006         [ +  - ]:         14 :     Xapian::Enquire enq(db);
    1007                 :            :     Xapian::Query query(Xapian::Query::OP_NEAR,
    1008 [ +  - ][ +  - ]:         14 :             Xapian::Query("is") | Xapian::Query("as") | Xapian::Query("be"),
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
    1009 [ +  - ][ +  - ]:         28 :             Xapian::Query("a"));
                 [ +  - ]
    1010         [ +  - ]:          7 :     enq.set_query(query);
    1011 [ +  - ][ +  - ]:          7 :     mset_expect_order(enq.get_mset(0, 10), 1);
    1012                 :            :     Xapian::Query query2(Xapian::Query::OP_NEAR,
    1013                 :            :             Xapian::Query("a"),
    1014 [ +  - ][ +  - ]:         14 :             Xapian::Query("is") | Xapian::Query("as") | Xapian::Query("be"));
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
                 [ +  - ]
    1015         [ +  - ]:          7 :     enq.set_query(query2);
    1016 [ +  - ][ +  - ]:          7 :     mset_expect_order(enq.get_mset(0, 10), 1);
    1017                 :            :     Xapian::Query query3(Xapian::Query::OP_NEAR,
    1018 [ +  - ][ +  - ]:         14 :             Xapian::Query("one") | Xapian::Query("with"),
         [ +  - ][ +  - ]
                 [ +  - ]
    1019 [ +  - ][ +  - ]:         28 :             Xapian::Query("the") | Xapian::Query("of") | Xapian::Query("line"));
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
                 [ +  - ]
    1020         [ +  - ]:          7 :     enq.set_query(query3);
    1021 [ +  - ][ +  - ]:          7 :     mset_expect_order(enq.get_mset(0, 10), 1, 4, 5);
    1022                 :            :     Xapian::Query query4(Xapian::Query::OP_NEAR,
    1023 [ +  - ][ +  - ]:         14 :             Xapian::Query("the") | Xapian::Query("of") | Xapian::Query("line"),
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
    1024 [ +  - ][ +  - ]:         28 :             Xapian::Query("one") | Xapian::Query("with"));
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
    1025         [ +  - ]:          7 :     enq.set_query(query4);
    1026 [ +  - ][ +  - ]:          7 :     mset_expect_order(enq.get_mset(0, 10), 1, 4, 5);
    1027                 :          7 :     return true;
    1028                 :            : }
    1029                 :            : 
    1030                 :            : static void
    1031                 :          3 : gen_subdbwithoutpos1_db(Xapian::WritableDatabase& db, const string&)
    1032                 :            : {
    1033         [ +  - ]:          3 :     Xapian::Document doc;
    1034 [ +  - ][ +  - ]:          3 :     doc.add_term("this");
    1035 [ +  - ][ +  - ]:          3 :     doc.add_term("paragraph");
    1036 [ +  - ][ +  - ]:          3 :     doc.add_term("wibble", 5);
    1037         [ +  - ]:          3 :     db.add_document(doc);
    1038                 :          3 : }
    1039                 :            : 
    1040                 :          3 : DEFINE_TESTCASE(subdbwithoutpos1, generated) {
    1041 [ +  - ][ +  - ]:          3 :     Xapian::Database db(get_database("apitest_simpledata"));
    1042                 :            : 
    1043                 :            :     Xapian::Query q(Xapian::Query::OP_PHRASE,
    1044                 :            :                     Xapian::Query("this"),
    1045 [ +  - ][ +  - ]:          6 :                     Xapian::Query("paragraph"));
         [ +  - ][ +  - ]
                 [ +  - ]
    1046                 :            : 
    1047         [ +  - ]:          6 :     Xapian::Enquire enq1(db);
    1048         [ +  - ]:          3 :     enq1.set_query(q);
    1049         [ +  - ]:          6 :     Xapian::MSet mset1 = enq1.get_mset(0, 10);
    1050 [ +  - ][ -  + ]:          3 :     TEST_EQUAL(mset1.size(), 3);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
    1051                 :            : 
    1052                 :            :     Xapian::Database db2 =
    1053 [ +  - ][ +  - ]:          6 :         get_database("subdbwithoutpos1", gen_subdbwithoutpos1_db);
                 [ +  - ]
    1054                 :            : 
    1055                 :            :     // If a database has no positional info, OP_PHRASE -> OP_AND.
    1056         [ +  - ]:          6 :     Xapian::Enquire enq2(db2);
    1057         [ +  - ]:          3 :     enq2.set_query(q);
    1058         [ +  - ]:          6 :     Xapian::MSet mset2 = enq2.get_mset(0, 10);
    1059 [ +  - ][ -  + ]:          3 :     TEST_EQUAL(mset2.size(), 1);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
    1060                 :            : 
    1061                 :            :     // If one sub-database in a combined database has no positional info but
    1062                 :            :     // other sub-databases do, then we shouldn't convert OP_PHRASE to OP_AND
    1063                 :            :     // (but prior to 1.4.3 we did).
    1064         [ +  - ]:          3 :     db.add_database(db2);
    1065         [ +  - ]:          6 :     Xapian::Enquire enq3(db);
    1066         [ +  - ]:          3 :     enq3.set_query(q);
    1067         [ +  - ]:          6 :     Xapian::MSet mset3 = enq3.get_mset(0, 10);
    1068 [ +  - ][ -  + ]:          3 :     TEST_EQUAL(mset3.size(), 3);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
    1069                 :            :     // Regression test for bug introduced in 1.4.3 which led to a division by
    1070                 :            :     // zero and then (at least on Linux) we got 1% here.
    1071 [ +  - ][ +  - ]:          3 :     TEST_EQUAL(mset3[0].get_percent(), 100);
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
    1072                 :            : 
    1073                 :            :     // Regression test for https://trac.xapian.org/ticket/752
    1074 [ +  - ][ +  - ]:          3 :     enq3.set_query((Xapian::Query("this") & q) | Xapian::Query("wibble"));
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
                 [ +  - ]
    1075 [ +  - ][ +  - ]:          3 :     mset3 = enq3.get_mset(0, 10);
    1076 [ +  - ][ -  + ]:          3 :     TEST_EQUAL(mset3.size(), 4);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
    1077                 :            : 
    1078                 :          3 :     return true;
    1079                 :            : }
    1080                 :            : 
    1081                 :            : // Regression test for bug fixed in 1.4.4 and 1.2.25.
    1082                 :          7 : DEFINE_TESTCASE(notandor1, backend) {
    1083 [ +  - ][ +  - ]:          7 :     Xapian::Database db(get_database("etext"));
    1084                 :            :     using Xapian::Query;
    1085 [ +  - ][ +  - ]:         14 :     Query q = Query("the") &~ (Query("friedrich") &
                 [ +  - ]
    1086 [ +  - ][ +  - ]:         28 :                                (Query("day") | Query("night")));
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
    1087         [ +  - ]:         14 :     Xapian::Enquire enq(db);
    1088         [ +  - ]:          7 :     enq.set_query(q);
    1089                 :            : 
    1090 [ +  - ][ +  - ]:         14 :     Xapian::MSet mset = enq.get_mset(0, 10, db.get_doccount());
    1091 [ +  - ][ -  + ]:          7 :     TEST_EQUAL(mset.get_matches_estimated(), 344);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
    1092                 :            : 
    1093                 :          7 :     return true;
    1094                 :            : }
    1095                 :            : 
    1096                 :            : // Regression test for bug fixed in git master before 1.5.0.
    1097                 :          7 : DEFINE_TESTCASE(boolorbug1, backend) {
    1098 [ +  - ][ +  - ]:          7 :     Xapian::Database db(get_database("etext"));
    1099                 :            :     using Xapian::Query;
    1100 [ +  - ][ +  - ]:         14 :     Query q = Query("the") &~ Query(Query::OP_WILDCARD, "pru");
         [ +  - ][ +  - ]
                 [ +  - ]
    1101         [ +  - ]:         14 :     Xapian::Enquire enq(db);
    1102         [ +  - ]:          7 :     enq.set_query(q);
    1103                 :            : 
    1104 [ +  - ][ +  - ]:         14 :     Xapian::MSet mset = enq.get_mset(0, 10, db.get_doccount());
    1105                 :            :     // Due to a bug in BoolOrPostList this returned 330 results.
    1106 [ +  - ][ -  + ]:          7 :     TEST_EQUAL(mset.get_matches_estimated(), 331);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
    1107                 :            : 
    1108                 :          7 :     return true;
    1109                 :            : }

Generated by: LCOV version 1.11