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

           Branch data     Line data    Source code
       1                 :            : /** @file api_none.cc
       2                 :            :  * @brief tests which don't need a backend
       3                 :            :  */
       4                 :            : /* Copyright (C) 2009 Richard Boulton
       5                 :            :  * Copyright (C) 2009,2010 Olly Betts
       6                 :            :  *
       7                 :            :  * This program is free software; you can redistribute it and/or
       8                 :            :  * modify it under the terms of the GNU General Public License as
       9                 :            :  * published by the Free Software Foundation; either version 2 of the
      10                 :            :  * License, or (at your option) any later version.
      11                 :            :  *
      12                 :            :  * This program is distributed in the hope that it will be useful,
      13                 :            :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
      14                 :            :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      15                 :            :  * GNU General Public License for more details.
      16                 :            :  *
      17                 :            :  * You should have received a copy of the GNU General Public License
      18                 :            :  * along with this program; if not, write to the Free Software
      19                 :            :  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301
      20                 :            :  * USA
      21                 :            :  */
      22                 :            : 
      23                 :            : #include <config.h>
      24                 :            : 
      25                 :            : #include "api_none.h"
      26                 :            : 
      27                 :            : #include <xapian.h>
      28                 :            : 
      29                 :            : #include "apitest.h"
      30                 :            : #include "testsuite.h"
      31                 :            : #include "testutils.h"
      32                 :            : 
      33                 :            : using namespace std;
      34                 :            : 
      35                 :            : // Regression test: various methods on Database() used to segfault or cause
      36                 :            : // division by 0.  Fixed in 1.1.4 and 1.0.18.  Ticket#415.
      37                 :          1 : DEFINE_TESTCASE(nosubdatabases1, !backend) {
      38                 :          1 :     Xapian::Database db;
      39                 :            :     // Fails to compile with g++ 3.3.5 on OpenBSD (ticket#458):
      40                 :            :     // TEST_EQUAL(db.get_metadata("foo"), std::string());
      41 [ -  + ][ #  # ]:          1 :     TEST(db.get_metadata("foo").empty());
      42 [ -  + ][ #  # ]:          1 :     TEST_EQUAL(db.metadata_keys_begin(), db.metadata_keys_end());
      43 [ +  - ][ -  + ]:          2 :     TEST_EXCEPTION(Xapian::DocNotFoundError, db.termlist_begin(1));
         [ #  # ][ -  + ]
      44 [ -  + ][ #  # ]:          1 :     TEST_EQUAL(db.allterms_begin(), db.allterms_end());
      45 [ -  + ][ #  # ]:          1 :     TEST_EQUAL(db.allterms_begin("foo"), db.allterms_end("foo"));
      46 [ +  - ][ -  + ]:          4 :     TEST_EXCEPTION(Xapian::DocNotFoundError, db.positionlist_begin(1, "foo"));
         [ #  # ][ -  + ]
      47   [ -  +  #  # ]:          1 :     TEST_EQUAL(db.get_lastdocid(), 0);
      48 [ -  + ][ #  # ]:          1 :     TEST_EQUAL(db.valuestream_begin(7), db.valuestream_end(7));
      49 [ +  - ][ -  + ]:          2 :     TEST_EXCEPTION(Xapian::DocNotFoundError, db.get_doclength(1));
         [ #  # ][ -  + ]
      50 [ +  - ][ -  + ]:          2 :     TEST_EXCEPTION(Xapian::DocNotFoundError, db.get_document(1));
         [ #  # ][ -  + ]
      51                 :          1 :     return true;
      52                 :            : }
      53                 :            : 
      54                 :            : /// Feature test for Document::add_boolean_term(), new in 1.0.18/1.1.4.
      55                 :          1 : DEFINE_TESTCASE(document1, !backend) {
      56                 :          1 :     Xapian::Document doc;
      57                 :          1 :     doc.add_boolean_term("Hxapian.org");
      58   [ -  +  #  # ]:          1 :     TEST_EQUAL(doc.termlist_count(), 1);
      59                 :          1 :     Xapian::TermIterator t = doc.termlist_begin();
      60 [ -  + ][ #  # ]:          1 :     TEST(t != doc.termlist_end());
      61 [ -  + ][ #  # ]:          1 :     TEST_EQUAL(*t, "Hxapian.org");
      62 [ -  + ][ #  # ]:          1 :     TEST_EQUAL(t.get_wdf(), 0);
      63 [ -  + ][ #  # ]:          1 :     TEST(++t == doc.termlist_end());
      64                 :          1 :     doc.remove_term("Hxapian.org");
      65   [ -  +  #  # ]:          1 :     TEST_EQUAL(doc.termlist_count(), 0);
      66 [ -  + ][ #  # ]:          1 :     TEST(doc.termlist_begin() == doc.termlist_end());
      67                 :          1 :     return true;
      68                 :            : }
      69                 :            : 
      70                 :            : /// Regression test - the docid wasn't initialised prior to 1.0.22/1.2.4.
      71                 :          1 : DEFINE_TESTCASE(document2, !backend) {
      72                 :          1 :     Xapian::Document doc;
      73                 :            :     // The return value is uninitialised, so running under valgrind this
      74                 :            :     // will fail reliably prior to the fix.
      75   [ -  +  #  # ]:          1 :     TEST_EQUAL(doc.get_docid(), 0);
      76                 :          1 :     return true;
      77                 :            : }

Generated by: LCOV version 1.8