LCOV - code coverage report
Current view: top level - home/olly/git/atia-xapian/xapian-core/tests - api_query.cc (source / functions) Hit Total Coverage
Test: Test Coverage for xapian-core r Lines: 26 26 100.0 %
Date: 2011-08-21 Functions: 3 3 100.0 %
Branches: 17 52 32.7 %

           Branch data     Line data    Source code
       1                 :            : /** @file api_query.cc
       2                 :            :  * @brief Query-related tests which don't need a backend.
       3                 :            :  */
       4                 :            : /* Copyright (C) 2008,2009 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                 :            : #include "utils.h"
      31                 :            : 
      32                 :            : #include "apitest.h"
      33                 :            : 
      34                 :            : using namespace std;
      35                 :            : 
      36                 :            : /// Regression test - in 1.0.10 and earlier "" was included in the list.
      37                 :          1 : DEFINE_TESTCASE(queryterms1, !backend) {
      38                 :          1 :     Xapian::Query query = Xapian::Query::MatchAll;
      39 [ -  + ][ #  # ]:          1 :     TEST(query.get_terms_begin() == query.get_terms_end());
      40                 :          1 :     query = Xapian::Query(query.OP_AND_NOT, query, Xapian::Query("fair"));
      41 [ -  + ][ #  # ]:          1 :     TEST_EQUAL(*query.get_terms_begin(), "fair");
      42                 :          1 :     return true;
      43                 :            : }
      44                 :            : 
      45                 :          1 : DEFINE_TESTCASE(matchnothing1, !backend) {
      46                 :          1 :     vector<Xapian::Query> subqs;
      47                 :          1 :     subqs.push_back(Xapian::Query("foo"));
      48                 :          1 :     subqs.push_back(Xapian::Query::MatchNothing);
      49                 :          1 :     Xapian::Query q(Xapian::Query::OP_AND, subqs.begin(), subqs.end());
      50 [ -  + ][ #  # ]:          1 :     TEST_STRINGS_EQUAL(q.get_description(), "Xapian::Query()");
      51                 :            : 
      52                 :            :     Xapian::Query q2(Xapian::Query::OP_AND,
      53                 :          1 :                      Xapian::Query("foo"), Xapian::Query::MatchNothing);
      54 [ -  + ][ #  # ]:          1 :     TEST_STRINGS_EQUAL(q2.get_description(), "Xapian::Query()");
      55                 :          1 :     return true;
      56                 :            : }
      57                 :            : 
      58                 :            : /** Regression test and feature test.
      59                 :            :  *
      60                 :            :  *  This threw AssertionError in 1.0.9 and earlier (bug#201) and gave valgrind
      61                 :            :  *  errors in 1.0.11 and earlier (bug#349).
      62                 :            :  *
      63                 :            :  *  Having two non-leaf subqueries with OP_NEAR used to be expected to throw
      64                 :            :  *  UnimplementedError, but now actually works.
      65                 :            :  */
      66                 :          1 : DEFINE_TESTCASE(nearsubqueries1, !backend) {
      67                 :            :     Xapian::Query a_or_b(Xapian::Query::OP_OR,
      68                 :            :                          Xapian::Query("a"),
      69                 :          1 :                          Xapian::Query("b"));
      70                 :          1 :     Xapian::Query near(Xapian::Query::OP_NEAR, a_or_b, a_or_b);
      71 [ -  + ][ #  # ]:          1 :     TEST_STRINGS_EQUAL(near.get_description(),
      72                 :            :                        "Xapian::Query(((a NEAR 2 a) OR (b NEAR 2 a) OR (b NEAR 2 b) OR (a NEAR 2 b)))");
      73                 :            : 
      74                 :            :     Xapian::Query a_near_b(Xapian::Query::OP_NEAR,
      75                 :            :                            Xapian::Query("a"),
      76                 :          1 :                            Xapian::Query("b"));
      77                 :            :     Xapian::Query x_phrs_y(Xapian::Query::OP_PHRASE,
      78                 :            :                            Xapian::Query("a"),
      79                 :          1 :                            Xapian::Query("b"));
      80                 :            : 
      81 [ +  - ][ -  + ]:          5 :     TEST_EXCEPTION(Xapian::UnimplementedError,
         [ #  # ][ -  + ]
      82                 :            :                    Xapian::Query q(Xapian::Query::OP_NEAR,
      83                 :            :                                    a_near_b,
      84                 :            :                                    Xapian::Query("c"))
      85                 :            :     );
      86                 :            : 
      87 [ +  - ][ -  + ]:          5 :     TEST_EXCEPTION(Xapian::UnimplementedError,
         [ #  # ][ -  + ]
      88                 :            :                    Xapian::Query q(Xapian::Query::OP_NEAR,
      89                 :            :                                    x_phrs_y,
      90                 :            :                                    Xapian::Query("c"))
      91                 :            :     );
      92                 :            : 
      93 [ +  - ][ -  + ]:          5 :     TEST_EXCEPTION(Xapian::UnimplementedError,
         [ #  # ][ -  + ]
      94                 :            :                    Xapian::Query q(Xapian::Query::OP_PHRASE,
      95                 :            :                                    a_near_b,
      96                 :            :                                    Xapian::Query("c"))
      97                 :            :     );
      98                 :            : 
      99 [ +  - ][ -  + ]:          5 :     TEST_EXCEPTION(Xapian::UnimplementedError,
         [ #  # ][ -  + ]
     100                 :            :                    Xapian::Query q(Xapian::Query::OP_PHRASE,
     101                 :            :                                    x_phrs_y,
     102                 :            :                                    Xapian::Query("c"))
     103                 :            :     );
     104                 :            : 
     105                 :          1 :     return true;
     106                 :            : }

Generated by: LCOV version 1.8