LCOV - code coverage report
Current view: top level - tests - unittest.cc (source / functions) Hit Total Coverage
Test: Test Coverage for xapian-core 954b5873a738 Lines: 426 432 98.6 %
Date: 2019-06-30 05:20:33 Functions: 48 48 100.0 %
Branches: 1099 7398 14.9 %

           Branch data     Line data    Source code
       1                 :            : /** @file unittest.cc
       2                 :            :  * @brief Unit tests of non-Xapian-specific internal code.
       3                 :            :  */
       4                 :            : /* Copyright (C) 2006,2007,2009,2010,2012,2015,2016,2017,2018,2019 Olly Betts
       5                 :            :  * Copyright (C) 2007 Richard Boulton
       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 <cctype>
      26                 :            : #include <cerrno>
      27                 :            : #include <cfloat>
      28                 :            : #include <climits>
      29                 :            : #include <cmath>
      30                 :            : #include <cstring>
      31                 :            : #include <iostream>
      32                 :            : #include <limits>
      33                 :            : #include <utility>
      34                 :            : 
      35                 :            : #include "safeunistd.h"
      36                 :            : 
      37                 :            : #define XAPIAN_UNITTEST
      38                 :            : static const char * unittest_assertion_failed = NULL;
      39                 :            : #define UNITTEST_CHECK_EXCEPTION \
      40                 :            :     if (unittest_assertion_failed) { \
      41                 :            :         const char * unittest_assertion_failed_ = unittest_assertion_failed;\
      42                 :            :         unittest_assertion_failed = NULL;\
      43                 :            :         throw unittest_assertion_failed_;\
      44                 :            :     }
      45                 :            : 
      46                 :            : #include "testsuite.h"
      47                 :            : 
      48                 :            : using namespace std;
      49                 :            : 
      50                 :            : #define UNITTEST_ASSERT_LOCATION__(LINE,MSG) __FILE__":"#LINE": "#MSG
      51                 :            : #define UNITTEST_ASSERT_LOCATION_(LINE,MSG) UNITTEST_ASSERT_LOCATION__(LINE,MSG)
      52                 :            : #define UNITTEST_ASSERT_LOCATION(MSG) UNITTEST_ASSERT_LOCATION_(__LINE__,MSG)
      53                 :            : #define UNITTEST_ASSERT_NOTHROW(COND, RET) \
      54                 :            :     do {\
      55                 :            :         if (rare(!(COND))) {\
      56                 :            :             unittest_assertion_failed = UNITTEST_ASSERT_LOCATION(COND);\
      57                 :            :             return RET;\
      58                 :            :         }\
      59                 :            :     } while (false)
      60                 :            : 
      61                 :            : // Utility code we use:
      62                 :            : #include "../backends/multi.h"
      63                 :            : #include "../common/stringutils.h"
      64                 :            : #include "../common/log2.h"
      65                 :            : 
      66                 :            : // Simpler version of TEST_EXCEPTION macro.
      67                 :            : #define TEST_EXCEPTION(TYPE, CODE) \
      68                 :            :     do { \
      69                 :            :         try { \
      70                 :            :             CODE; \
      71                 :            :             UNITTEST_CHECK_EXCEPTION \
      72                 :            :             FAIL_TEST("Expected exception "#TYPE" not thrown"); \
      73                 :            :         } catch (const TYPE &) { \
      74                 :            :         } \
      75                 :            :     } while (0)
      76                 :            : 
      77                 :            : // Code we're unit testing:
      78                 :            : #include "../common/closefrom.cc"
      79                 :            : #include "../common/errno_to_string.cc"
      80                 :            : #include "../common/fileutils.cc"
      81                 :            : #include "../common/overflow.h"
      82                 :            : #include "../common/pack.cc"
      83                 :            : #include "../common/parseint.h"
      84                 :            : #include "../common/serialise-double.cc"
      85                 :            : #include "../common/str.cc"
      86                 :            : #include "../backends/uuids.cc"
      87                 :            : #include "../net/serialise-error.cc"
      88                 :            : #include "../api/error.cc"
      89                 :            : #include "../api/sortable-serialise.cc"
      90                 :            : #include "../include/xapian/intrusive_ptr.h"
      91                 :            : 
      92                 :            : // fileutils.cc uses opendir(), etc though not in a function we currently test.
      93                 :            : #include "../common/msvc_dirent.cc"
      94                 :            : 
      95                 :            : // The UUID code uses hexdigit().
      96                 :            : #include "../api/constinfo.cc"
      97                 :            : 
      98                 :            : // Stub replacement, which doesn't deal with escaping or producing valid UTF-8.
      99                 :            : // The full implementation needs Xapian::Utf8Iterator and
     100                 :            : // Xapian::Unicode::append_utf8().
     101                 :            : void
     102                 :          1 : description_append(std::string & desc, const std::string &s)
     103                 :            : {
     104                 :          1 :     desc += s;
     105                 :          1 : }
     106                 :            : 
     107                 :          1 : DEFINE_TESTCASE_(simple_exceptions_work1) {
     108                 :            :     try {
     109                 :          2 :         throw 42;
     110         [ -  + ]:          1 :     } catch (int val) {
     111 [ -  + ][ -  +  :          1 :         TEST_EQUAL(val, 42);
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
             #  #  #  #  
                      # ]
     112                 :          1 :         return true;
     113                 :            :     }
     114                 :            :     return false;
     115                 :            : }
     116                 :            : 
     117                 :            : class TestException { };
     118                 :            : 
     119                 :          1 : DEFINE_TESTCASE_(class_exceptions_work1) {
     120                 :            :     try {
     121         [ -  + ]:          2 :         throw TestException();
     122                 :          1 :     } catch (const TestException &) {
     123                 :          1 :         return true;
     124                 :            :     }
     125                 :            :     return false;
     126                 :            : }
     127                 :            : 
     128                 :            : static inline string
     129                 :         24 : r_r_p(string a, const string & b)
     130                 :            : {
     131                 :         24 :     resolve_relative_path(a, b);
     132                 :         24 :     return a;
     133                 :            : }
     134                 :            : 
     135                 :          1 : DEFINE_TESTCASE_(resolverelativepath1) {
     136 [ +  - ][ +  - ]:          1 :     TEST_EQUAL(r_r_p("/abs/o/lute", ""), "/abs/o/lute");
         [ +  - ][ +  - ]
         [ -  + ][ -  + ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     137 [ +  - ][ +  - ]:          1 :     TEST_EQUAL(r_r_p("/abs/o/lute", "/"), "/abs/o/lute");
         [ +  - ][ +  - ]
         [ -  + ][ -  + ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     138 [ +  - ][ +  - ]:          1 :     TEST_EQUAL(r_r_p("/abs/o/lute", "//"), "/abs/o/lute");
         [ +  - ][ +  - ]
         [ -  + ][ -  + ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     139 [ +  - ][ +  - ]:          1 :     TEST_EQUAL(r_r_p("/abs/o/lute", "foo"), "/abs/o/lute");
         [ +  - ][ +  - ]
         [ -  + ][ -  + ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     140 [ +  - ][ +  - ]:          1 :     TEST_EQUAL(r_r_p("/abs/o/lute", "foo/"), "/abs/o/lute");
         [ +  - ][ +  - ]
         [ -  + ][ -  + ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     141 [ +  - ][ +  - ]:          1 :     TEST_EQUAL(r_r_p("/abs/o/lute", "/foo"), "/abs/o/lute");
         [ +  - ][ +  - ]
         [ -  + ][ -  + ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     142 [ +  - ][ +  - ]:          1 :     TEST_EQUAL(r_r_p("/abs/o/lute", "/foo/"), "/abs/o/lute");
         [ +  - ][ +  - ]
         [ -  + ][ -  + ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     143 [ +  - ][ +  - ]:          1 :     TEST_EQUAL(r_r_p("/abs/o/lute", "foo/bar"), "/abs/o/lute");
         [ +  - ][ +  - ]
         [ -  + ][ -  + ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     144 [ +  - ][ +  - ]:          1 :     TEST_EQUAL(r_r_p("/abs/o/lute", "foo/bar/"), "/abs/o/lute");
         [ +  - ][ +  - ]
         [ -  + ][ -  + ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     145 [ +  - ][ +  - ]:          1 :     TEST_EQUAL(r_r_p("/abs/o/lute", "/foo/bar"), "/abs/o/lute");
         [ +  - ][ +  - ]
         [ -  + ][ -  + ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     146 [ +  - ][ +  - ]:          1 :     TEST_EQUAL(r_r_p("/abs/o/lute", "/foo/bar/"), "/abs/o/lute");
         [ +  - ][ +  - ]
         [ -  + ][ -  + ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     147 [ +  - ][ +  - ]:          1 :     TEST_EQUAL(r_r_p("rel/a/tive", ""), "rel/a/tive");
         [ +  - ][ +  - ]
         [ -  + ][ -  + ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     148 [ +  - ][ +  - ]:          1 :     TEST_EQUAL(r_r_p("rel/a/tive", "/"), "/rel/a/tive");
         [ +  - ][ +  - ]
         [ -  + ][ -  + ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     149 [ +  - ][ +  - ]:          1 :     TEST_EQUAL(r_r_p("rel/a/tive", "//"), "//rel/a/tive");
         [ +  - ][ +  - ]
         [ -  + ][ -  + ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     150 [ +  - ][ +  - ]:          1 :     TEST_EQUAL(r_r_p("rel/a/tive", "foo"), "rel/a/tive");
         [ +  - ][ +  - ]
         [ -  + ][ -  + ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     151 [ +  - ][ +  - ]:          1 :     TEST_EQUAL(r_r_p("rel/a/tive", "foo/"), "foo/rel/a/tive");
         [ +  - ][ +  - ]
         [ -  + ][ -  + ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     152 [ +  - ][ +  - ]:          1 :     TEST_EQUAL(r_r_p("rel/a/tive", "/foo"), "/rel/a/tive");
         [ +  - ][ +  - ]
         [ -  + ][ -  + ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     153 [ +  - ][ +  - ]:          1 :     TEST_EQUAL(r_r_p("rel/a/tive", "/foo/"), "/foo/rel/a/tive");
         [ +  - ][ +  - ]
         [ -  + ][ -  + ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     154 [ +  - ][ +  - ]:          1 :     TEST_EQUAL(r_r_p("rel/a/tive", "foo/bar"), "foo/rel/a/tive");
         [ +  - ][ +  - ]
         [ -  + ][ -  + ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     155 [ +  - ][ +  - ]:          1 :     TEST_EQUAL(r_r_p("rel/a/tive", "foo/bar/"), "foo/bar/rel/a/tive");
         [ +  - ][ +  - ]
         [ -  + ][ -  + ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     156 [ +  - ][ +  - ]:          1 :     TEST_EQUAL(r_r_p("rel/a/tive", "/foo/bar"), "/foo/rel/a/tive");
         [ +  - ][ +  - ]
         [ -  + ][ -  + ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     157 [ +  - ][ +  - ]:          1 :     TEST_EQUAL(r_r_p("rel/a/tive", "/foo/bar/"), "/foo/bar/rel/a/tive");
         [ +  - ][ +  - ]
         [ -  + ][ -  + ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     158                 :            : #ifndef __WIN32__
     159 [ +  - ][ +  - ]:          1 :     TEST_EQUAL(r_r_p("/abs/o/lute", "/foo\\bar"), "/abs/o/lute");
         [ +  - ][ +  - ]
         [ -  + ][ -  + ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     160 [ +  - ][ +  - ]:          1 :     TEST_EQUAL(r_r_p("rel/a/tive", "/foo\\bar"), "/rel/a/tive");
         [ +  - ][ +  - ]
         [ -  + ][ -  + ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     161                 :            : #else
     162                 :            :     TEST_EQUAL(r_r_p("\\dos\\path", ""), "\\dos\\path");
     163                 :            :     TEST_EQUAL(r_r_p("\\dos\\path", "/"), "\\dos\\path");
     164                 :            :     TEST_EQUAL(r_r_p("\\dos\\path", "\\"), "\\dos\\path");
     165                 :            :     TEST_EQUAL(r_r_p("\\dos\\path", "c:"), "c:\\dos\\path");
     166                 :            :     TEST_EQUAL(r_r_p("\\dos\\path", "c:\\"), "c:\\dos\\path");
     167                 :            :     TEST_EQUAL(r_r_p("\\dos\\path", "c:\\temp"), "c:\\dos\\path");
     168                 :            :     TEST_EQUAL(r_r_p("\\dos\\path", "c:\\temp\\"), "c:\\dos\\path");
     169                 :            :     TEST_EQUAL(r_r_p("rel/a/tive", "\\"), "\\rel/a/tive");
     170                 :            :     TEST_EQUAL(r_r_p("rel/a/tive", "foo\\"), "foo\\rel/a/tive");
     171                 :            :     TEST_EQUAL(r_r_p("rel\\a\\tive", "/foo/"), "/foo/rel\\a\\tive");
     172                 :            :     TEST_EQUAL(r_r_p("rel/a/tive", "c:/foo/bar"), "c:/foo/rel/a/tive");
     173                 :            :     TEST_EQUAL(r_r_p("rel/a/tive", "c:foo/bar/"), "c:foo/bar/rel/a/tive");
     174                 :            :     TEST_EQUAL(r_r_p("rel/a/tive", "c:"), "c:rel/a/tive");
     175                 :            :     TEST_EQUAL(r_r_p("rel/a/tive", "c:\\"), "c:\\rel/a/tive");
     176                 :            :     TEST_EQUAL(r_r_p("C:rel/a/tive", "c:\\foo\\bar"), "C:\\foo\\rel/a/tive");
     177                 :            :     TEST_EQUAL(r_r_p("C:rel/a/tive", "c:"), "C:rel/a/tive");
     178                 :            :     // This one is impossible to reliably resolve without knowing the current
     179                 :            :     // drive - if it is C:, then the answer is: "C:/abs/o/rel/a/tive"
     180                 :            :     TEST_EQUAL(r_r_p("C:rel/a/tive", "/abs/o/lute"), "C:rel/a/tive");
     181                 :            :     // UNC paths tests:
     182                 :            :     TEST_EQUAL(r_r_p("\\\\SRV\\VOL\\FILE", "/a/b"), "\\\\SRV\\VOL\\FILE");
     183                 :            :     TEST_EQUAL(r_r_p("rel/a/tive", "\\\\SRV\\VOL\\DIR\\FILE"), "\\\\SRV\\VOL\\DIR\\rel/a/tive");
     184                 :            :     TEST_EQUAL(r_r_p("/abs/o/lute", "\\\\SRV\\VOL\\FILE"), "\\\\SRV\\VOL/abs/o/lute");
     185                 :            :     TEST_EQUAL(r_r_p("/abs/o/lute", "\\\\S\\V\\FILE"), "\\\\S\\V/abs/o/lute");
     186                 :            :     TEST_EQUAL(r_r_p("/abs/o/lute", "\\\\S\\V\\"), "\\\\S\\V/abs/o/lute");
     187                 :            :     TEST_EQUAL(r_r_p("/abs/o/lute", "\\\\S\\V"), "\\\\S\\V/abs/o/lute");
     188                 :            :     TEST_EQUAL(r_r_p("//SRV/VOL/FILE", "/a/b"), "//SRV/VOL/FILE");
     189                 :            :     TEST_EQUAL(r_r_p("rel/a/tive", "//SRV/VOL/DIR/FILE"), "//SRV/VOL/DIR/rel/a/tive");
     190                 :            :     TEST_EQUAL(r_r_p("/abs/o/lute", "//SRV/VOL/FILE"), "//SRV/VOL/abs/o/lute");
     191                 :            :     TEST_EQUAL(r_r_p("/abs/o/lute", "//S/V/FILE"), "//S/V/abs/o/lute");
     192                 :            :     TEST_EQUAL(r_r_p("/abs/o/lute", "//S/V/"), "//S/V/abs/o/lute");
     193                 :            :     TEST_EQUAL(r_r_p("/abs/o/lute", "//S/V"), "//S/V/abs/o/lute");
     194                 :            :     TEST_EQUAL(r_r_p("/abs/o/lute", "\\\\?\\C:\\wibble"), "\\\\?\\C:\\abs\\o\\lute");
     195                 :            :     TEST_EQUAL(r_r_p("/abs/o/lute", "\\\\?\\UNC\\S\\V"), "\\\\?\\UNC\\S\\V\\abs\\o\\lute");
     196                 :            :     TEST_EQUAL(r_r_p("/abs/o/lute", "\\\\?\\UNC\\S\\V\\"), "\\\\?\\UNC\\S\\V\\abs\\o\\lute");
     197                 :            :     TEST_EQUAL(r_r_p("/abs/o/lute", "\\\\?\\UNC\\S\\V\\TMP\\README.TXT"), "\\\\?\\UNC\\S\\V\\abs\\o\\lute");
     198                 :            :     TEST_EQUAL(r_r_p("r/elativ/e", "\\\\?\\C:\\wibble"), "\\\\?\\C:\\r\\elativ\\e");
     199                 :            :     TEST_EQUAL(r_r_p("r/elativ/e", "\\\\?\\C:\\wibble\\wobble"), "\\\\?\\C:\\wibble\\r\\elativ\\e");
     200                 :            : #if 0 // Is this a valid testcase?  It fails, but isn't relevant to Xapian.
     201                 :            :     TEST_EQUAL(r_r_p("r/elativ/e", "\\\\?\\UNC\\S\\V"), "\\\\?\\UNC\\S\\V\\r\\elativ\\e");
     202                 :            : #endif
     203                 :            :     TEST_EQUAL(r_r_p("r/elativ/e", "\\\\?\\UNC\\S\\V\\"), "\\\\?\\UNC\\S\\V\\r\\elativ\\e");
     204                 :            :     TEST_EQUAL(r_r_p("r/elativ/e", "\\\\?\\UNC\\S\\V\\TMP\\README.TXT"), "\\\\?\\UNC\\S\\V\\TMP\\r\\elativ\\e");
     205                 :            : #endif
     206                 :          1 :     return true;
     207                 :            : }
     208                 :            : 
     209                 :            : static void
     210                 :         39 : check_double_serialisation(double u)
     211                 :            : {
     212                 :            :     // Commonly C++ string implementations keep the string nul-terminated, and
     213                 :            :     // encoded.data() returns a pointer to a buffer including the nul (the same
     214                 :            :     // as encoded.c_str()).  This means that valgrind won't catch a read one
     215                 :            :     // past the end of the serialised value, so we copy just the serialised
     216                 :            :     // value into a temporary buffer.
     217                 :            :     char buf[16];
     218         [ +  - ]:         39 :     string encoded = serialise_double(u);
     219 [ -  + ][ -  + ]:         39 :     TEST(encoded.size() < sizeof(buf));
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     220                 :         39 :     memcpy(buf, encoded.data(), encoded.size());
     221                 :            :     // Put a NULL pointer either side, to catch incrementing/decrementing at
     222                 :            :     // the wrong level of indirection (regression test for a bug in an
     223                 :            :     // unreleased version).
     224                 :         39 :     const char * ptr[3] = { NULL, buf, NULL };
     225                 :         39 :     const char * end = ptr[1] + encoded.size();
     226         [ +  - ]:         39 :     double v = unserialise_double(&(ptr[1]), end);
     227 [ +  - ][ -  + ]:         39 :     if (ptr[1] != end || u != v) {
     228 [ #  # ][ #  # ]:          0 :         cout << u << " -> " << v << ", difference = " << v - u << endl;
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
     229 [ #  # ][ #  # ]:          0 :         cout << "FLT_RADIX = " << FLT_RADIX << endl;
                 [ #  # ]
     230 [ #  # ][ #  # ]:          0 :         cout << "DBL_MAX_EXP = " << DBL_MAX_EXP << endl;
                 [ #  # ]
     231                 :            :     }
     232 [ -  + ][ -  + ]:         39 :     TEST_EQUAL(static_cast<const void*>(ptr[1]), static_cast<const void*>(end));
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
     233                 :         39 : }
     234                 :            : 
     235                 :            : // Check serialisation of doubles.
     236                 :          1 : DEFINE_TESTCASE_(serialisedouble1) {
     237                 :            :     static const double test_values[] = {
     238                 :            :         3.14159265,
     239                 :            :         1e57,
     240                 :            :         123.1,
     241                 :            :         257.12,
     242                 :            :         1234.567e123,
     243                 :            :         255.5,
     244                 :            :         256.125,
     245                 :            :         257.03125,
     246                 :            :     };
     247                 :            : 
     248                 :          1 :     check_double_serialisation(0.0);
     249                 :          1 :     check_double_serialisation(1.0);
     250                 :          1 :     check_double_serialisation(-1.0);
     251                 :          1 :     check_double_serialisation(DBL_MAX);
     252                 :          1 :     check_double_serialisation(-DBL_MAX);
     253                 :          1 :     check_double_serialisation(DBL_MIN);
     254                 :          1 :     check_double_serialisation(-DBL_MIN);
     255                 :            : 
     256                 :            :     const double *p;
     257         [ +  + ]:          9 :     for (p = test_values; p < test_values + sizeof(test_values) / sizeof(double); ++p) {
     258                 :          8 :         double val = *p;
     259                 :          8 :         check_double_serialisation(val);
     260                 :          8 :         check_double_serialisation(-val);
     261                 :          8 :         check_double_serialisation(1.0 / val);
     262                 :          8 :         check_double_serialisation(-1.0 / val);
     263                 :            :     }
     264                 :            : 
     265                 :          1 :     return true;
     266                 :            : }
     267                 :            : 
     268                 :            : // Test pack_uint() and unpack_uint().
     269                 :          1 : static bool test_packuint1()
     270                 :            : {
     271                 :          1 :     size_t n = 0;
     272         [ +  + ]:      84754 :     while (n < 0xff000000) {
     273         [ +  - ]:      84753 :         string s;
     274         [ +  - ]:      84753 :         pack_uint(s, n);
     275                 :      84753 :         const char* p = s.data();
     276                 :      84753 :         const char* p_end = p + s.size();
     277                 :            :         size_t decoded_n;
     278 [ -  + ][ -  + ]:      84753 :         TEST(unpack_uint(&p, p_end, &decoded_n));
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     279 [ +  - ][ -  + ]:      84753 :         if (n != decoded_n || p != p_end) tout << "[" << s << "]" << endl;
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
     280 [ -  + ][ -  + ]:      84753 :         TEST_EQUAL(n, decoded_n);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
     281 [ -  + ][ -  + ]:      84753 :         TEST_EQUAL(p_end - p, 0);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
     282         [ +  + ]:      84753 :         if (n < 5000) {
     283                 :       5000 :             ++n;
     284                 :            :         } else {
     285                 :      79753 :             n += 53643;
     286                 :            :         }
     287                 :      84753 :     }
     288                 :            : 
     289                 :          1 :     return true;
     290                 :            : }
     291                 :            : 
     292                 :            : static void
     293                 :          9 : packstring1_helper(size_t len)
     294                 :            : {
     295         [ +  - ]:          9 :     string s;
     296 [ +  - ][ +  - ]:          9 :     pack_string(s, string(len, 'x'));
     297                 :            :     {
     298                 :          9 :         const char* p = s.data();
     299                 :          9 :         const char* p_end = p + s.size();
     300                 :            :         // unpack_string() should overwrite any existing value.
     301         [ +  - ]:          9 :         string r = "dummy";
     302 [ +  - ][ -  + ]:          9 :         TEST(unpack_string(&p, p_end, r));
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
     303 [ -  + ][ -  + ]:          9 :         TEST_EQUAL(r.size(), len);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
     304 [ -  + ][ -  + ]:          9 :         TEST_EQUAL(r.find_first_not_of('x'), r.npos);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
     305 [ -  + ][ -  + ]:          9 :         TEST(p == p_end);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     306                 :            :     }
     307         [ +  - ]:          9 :     s += 'x';
     308                 :            :     {
     309                 :          9 :         const char* p = s.data();
     310                 :          9 :         const char* p_end = p + s.size();
     311                 :            :         // unpack_string() should overwrite any existing value.
     312         [ +  - ]:          9 :         string r = "dummy";
     313 [ +  - ][ -  + ]:          9 :         TEST(unpack_string(&p, p_end, r));
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
     314 [ -  + ][ -  + ]:          9 :         TEST_EQUAL(r.size(), len);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
     315 [ -  + ][ -  + ]:          9 :         TEST_EQUAL(r.find_first_not_of('x'), r.npos);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
     316 [ -  + ][ -  + ]:          9 :         TEST_EQUAL(p_end - p, 1);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
     317                 :            :     }
     318                 :            :     // Test truncated encodings fail to unpack.
     319                 :          9 :     size_t trunc_len = s.size() - 2;
     320         [ +  + ]:         44 :     do {
     321                 :         44 :         const char* p = s.data();
     322                 :         44 :         const char* p_end = p + trunc_len;
     323         [ +  - ]:         44 :         string r;
     324 [ +  - ][ -  + ]:         44 :         TEST(!unpack_string(&p, p_end, r));
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
     325 [ -  + ][ -  + ]:         44 :         TEST(!p);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     326                 :         44 :         trunc_len >>= 1;
     327                 :          9 :     } while (trunc_len);
     328                 :          9 : }
     329                 :            : 
     330                 :            : // Test pack_string() and unpack_string().
     331                 :          1 : static bool test_packstring1()
     332                 :            : {
     333                 :          1 :     packstring1_helper(0);
     334                 :          1 :     packstring1_helper(1);
     335                 :            :     // Nothing magic here, just test a range of odd and even values.
     336         [ +  + ]:          8 :     for (size_t n = 2; n < 1000; n = (n + 1) * 2 + (n >> 1)) {
     337                 :          7 :         packstring1_helper(n);
     338                 :            :     }
     339                 :            : 
     340                 :          1 :     return true;
     341                 :            : }
     342                 :            : 
     343                 :            : // Test pack_string_empty()
     344                 :          1 : static bool test_packstring2()
     345                 :            : {
     346         [ +  - ]:          1 :     string s;
     347 [ +  - ][ +  - ]:          1 :     pack_string(s, string());
     348         [ +  - ]:          2 :     string s_empty;
     349         [ +  - ]:          1 :     pack_string_empty(s_empty);
     350 [ -  + ][ -  + ]:          1 :     TEST_EQUAL(s, s_empty);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
     351                 :          1 :     return true;
     352                 :            : }
     353                 :            : 
     354                 :            : #ifdef XAPIAN_HAS_REMOTE_BACKEND
     355                 :            : // Check serialisation of Xapian::Error.
     356                 :          1 : static bool test_serialiseerror1()
     357                 :            : {
     358         [ +  - ]:          1 :     string enoent_msg = errno_to_string(ENOENT);
     359 [ +  - ][ +  - ]:          2 :     Xapian::DatabaseOpeningError e("Failed to open database", ENOENT);
     360                 :            :     // Regression test for bug in 1.0.0 - it didn't convert errno values for
     361                 :            :     // get_description() if they hadn't already been converted.
     362 [ +  - ][ +  - ]:          1 :     TEST_STRINGS_EQUAL(e.get_description(), "DatabaseOpeningError: Failed to open database (" + enoent_msg + ")");
         [ +  - ][ -  + ]
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     363                 :            : 
     364 [ +  - ][ +  - ]:          1 :     TEST_STRINGS_EQUAL(e.get_error_string(), enoent_msg);
         [ -  + ][ -  + ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
     365                 :            : 
     366         [ +  - ]:          2 :     string serialisation = serialise_error(e);
     367                 :            : 
     368                 :            :     // Test if unserialise_error() throws with a flag to avoid the possibility
     369                 :            :     // of an "unreachable code" warning when we get around to marking
     370                 :            :     // unserialise_error() as "noreturn".
     371                 :          1 :     bool threw = false;
     372                 :            :     try {
     373                 :            :         // unserialise_error throws an exception.
     374 [ +  - ][ +  - ]:          1 :         unserialise_error(serialisation, "", "");
     375         [ -  + ]:          2 :     } catch (const Xapian::Error & ecaught) {
     376 [ -  + ][ -  + ]:          1 :         TEST_STRINGS_EQUAL(ecaught.get_error_string(), enoent_msg);
         [ -  + ][ -  +  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
             #  #  #  # ]
     377                 :          1 :         threw = true;
     378                 :            :     }
     379   [ -  +  #  #  :          1 :     TEST(threw);
          #  #  #  #  #  
          #  #  #  #  #  
             #  #  -  + ]
     380                 :            : 
     381                 :            :     // Check that the original is still OK.
     382 [ +  - ][ +  - ]:          1 :     TEST_STRINGS_EQUAL(e.get_error_string(), enoent_msg);
         [ -  + ][ -  +  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
             #  #  #  # ]
     383                 :            : 
     384                 :            :     // Regression test - in 1.0.0, copying used to duplicate the error_string
     385                 :            :     // pointer, resulting in double calls to free().
     386         [ +  - ]:          2 :     Xapian::DatabaseOpeningError ecopy(e);
     387 [ +  - ][ +  - ]:          1 :     TEST_STRINGS_EQUAL(ecopy.get_error_string(), enoent_msg);
         [ -  + ][ -  +  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
             #  #  #  # ]
     388                 :            : 
     389                 :          1 :     return true;
     390                 :            : }
     391                 :            : #endif
     392                 :            : 
     393                 :            : // Test log2() (which might be our replacement version).
     394                 :          1 : static bool test_log2()
     395                 :            : {
     396 [ -  + ][ -  + ]:          1 :     TEST_EQUAL(log2(1.0), 0.0);
                 [ #  # ]
     397 [ -  + ][ -  + ]:          1 :     TEST_EQUAL(log2(2.0), 1.0);
                 [ #  # ]
     398 [ -  + ][ -  + ]:          1 :     TEST_EQUAL(log2(1024.0), 10.0);
                 [ #  # ]
     399 [ -  + ][ -  + ]:          1 :     TEST_EQUAL(log2(0.5), -1.0);
                 [ #  # ]
     400                 :          1 :     return true;
     401                 :            : }
     402                 :            : 
     403                 :            : static const double test_sortableserialise_numbers[] = {
     404                 :            : #ifdef INFINITY
     405                 :            :     -INFINITY,
     406                 :            : #endif
     407                 :            :     -HUGE_VAL,
     408                 :            :     -DBL_MAX,
     409                 :            :     -exp2(1022),
     410                 :            :     -1024.5,
     411                 :            :     -3.14159265358979323846,
     412                 :            :     -3,
     413                 :            :     -2,
     414                 :            :     -1.8,
     415                 :            :     -1.1,
     416                 :            :     -1,
     417                 :            :     -0.5,
     418                 :            :     -0.2,
     419                 :            :     -0.1,
     420                 :            :     -0.000005,
     421                 :            :     -0.000002,
     422                 :            :     -0.000001,
     423                 :            :     -exp2(-1023),
     424                 :            :     -exp2(-1024),
     425                 :            :     -exp2(-1074),
     426                 :            :     -DBL_MIN,
     427                 :            :     0,
     428                 :            :     DBL_MIN,
     429                 :            :     exp2(-1074),
     430                 :            :     exp2(-1024),
     431                 :            :     exp2(-1023),
     432                 :            :     0.000001,
     433                 :            :     0.000002,
     434                 :            :     0.000005,
     435                 :            :     0.1,
     436                 :            :     0.2,
     437                 :            :     0.5,
     438                 :            :     1,
     439                 :            :     1.1,
     440                 :            :     1.8,
     441                 :            :     2,
     442                 :            :     3,
     443                 :            :     3.14159265358979323846,
     444                 :            :     1024.5,
     445                 :            :     exp2(1022),
     446                 :            :     DBL_MAX,
     447                 :            :     HUGE_VAL,
     448                 :            : #ifdef INFINITY
     449                 :            :     INFINITY,
     450                 :            : #endif
     451                 :            : 
     452                 :            :     64 // Magic number which we stop at.
     453                 :            : };
     454                 :            : 
     455                 :            : // Test serialisation and unserialisation of various numbers.
     456                 :            : // This is actually a public API, but we want extra assertions in the code
     457                 :            : // while we test it.
     458                 :          1 : static bool test_sortableserialise1()
     459                 :            : {
     460                 :          1 :     double prevnum = 0;
     461         [ +  - ]:          1 :     string prevstr;
     462                 :          1 :     bool started = false;
     463         [ +  + ]:         44 :     for (const double *p = test_sortableserialise_numbers; *p != 64; ++p) {
     464                 :         43 :         double num = *p;
     465 [ +  - ][ +  - ]:         43 :         tout << "Number: " << num << '\n';
                 [ +  - ]
     466         [ +  - ]:         43 :         string str = Xapian::sortable_serialise(num);
     467 [ +  - ][ +  - ]:         43 :         tout << "String: " << str << '\n';
                 [ +  - ]
     468 [ -  + ][ -  + ]:         43 :         TEST_EQUAL(Xapian::sortable_unserialise(str), num);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
     469                 :            : 
     470         [ +  + ]:         43 :         if (started) {
     471                 :         42 :             int num_cmp = 0;
     472         [ +  + ]:         42 :             if (prevnum < num) {
     473                 :         38 :                 num_cmp = -1;
     474         [ +  + ]:          4 :             } else if (prevnum > num) {
     475                 :          2 :                 num_cmp = 1;
     476                 :            :             }
     477                 :         42 :             int str_cmp = 0;
     478 [ +  - ][ +  + ]:         42 :             if (prevstr < str) {
     479                 :         38 :                 str_cmp = -1;
     480 [ +  - ][ +  + ]:          4 :             } else if (prevstr > str) {
     481                 :          2 :                 str_cmp = 1;
     482                 :            :             }
     483                 :            : 
     484 [ -  + ][ -  + ]:         42 :             TEST_AND_EXPLAIN(num_cmp == str_cmp,
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     485                 :            :                              "Numbers " << prevnum << " and " << num <<
     486                 :            :                              " don't sort the same way as their string "
     487                 :            :                              "counterparts");
     488                 :            :         }
     489                 :            : 
     490                 :         43 :         prevnum = num;
     491         [ +  - ]:         43 :         prevstr = str;
     492                 :         43 :         started = true;
     493                 :         43 :     }
     494                 :          1 :     return true;
     495                 :            : }
     496                 :            : 
     497                 :            : template<typename S>
     498                 :          5 : inline static void tostring_helper() {
     499                 :          5 :     const S max_val = numeric_limits<S>::max();
     500                 :          5 :     const S min_val = numeric_limits<S>::min();
     501 [ +  - ][ +  - ]:          5 :     tout << "Testing with tostring_helper" << endl;
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
     502 [ +  - ][ +  - ]:          5 :     std::ostringstream oss;
         [ +  - ][ +  - ]
                 [ +  - ]
     503 [ +  - ][ +  - ]:          5 :     oss << (long long)max_val;
         [ +  - ][ +  - ]
                 [ +  - ]
     504 [ +  - ][ +  - ]:          5 :     TEST_EQUAL(str(max_val), oss.str());
         [ -  + ][ -  + ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ +  - ][ +  - ]
         [ -  + ][ -  + ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ +  - ][ +  - ]
         [ -  + ][ -  + ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ +  - ][ +  - ]
         [ -  + ][ -  + ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ +  - ][ +  - ]
         [ -  + ][ -  + ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
     505 [ +  - ][ +  - ]:          5 :     oss.str("");
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
     506   [ +  -  +  -  :          5 :     oss.clear();
          +  -  +  -  +  
                      - ]
     507                 :            : 
     508 [ +  - ][ +  - ]:          5 :     oss << (long long)min_val;
         [ +  - ][ +  - ]
                 [ +  - ]
     509 [ +  - ][ +  - ]:          5 :     TEST_EQUAL(str(min_val), oss.str());
         [ -  + ][ -  + ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ +  - ][ +  - ]
         [ -  + ][ -  + ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ +  - ][ +  - ]
         [ -  + ][ -  + ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ +  - ][ +  - ]
         [ -  + ][ -  + ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ +  - ][ +  - ]
         [ -  + ][ -  + ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
     510 [ +  - ][ +  - ]:          5 :     oss.str("");
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
     511 [ +  - ][ +  - ]:          5 :     oss.clear();
         [ +  - ][ +  - ]
                 [ +  - ]
     512                 :          5 : }
     513                 :            : 
     514                 :          1 : static bool test_tostring1()
     515                 :            : {
     516 [ +  - ][ -  + ]:          1 :     TEST_EQUAL(str(0), "0");
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     517 [ +  - ][ -  + ]:          1 :     TEST_EQUAL(str(0u), "0");
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     518 [ +  - ][ -  + ]:          1 :     TEST_EQUAL(str(1), "1");
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     519 [ +  - ][ -  + ]:          1 :     TEST_EQUAL(str(1u), "1");
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     520 [ +  - ][ -  + ]:          1 :     TEST_EQUAL(str(9), "9");
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     521 [ +  - ][ -  + ]:          1 :     TEST_EQUAL(str(9u), "9");
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     522 [ +  - ][ -  + ]:          1 :     TEST_EQUAL(str(10), "10");
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     523 [ +  - ][ -  + ]:          1 :     TEST_EQUAL(str(10u), "10");
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     524 [ +  - ][ -  + ]:          1 :     TEST_EQUAL(str(-1), "-1");
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     525 [ +  - ][ -  + ]:          1 :     TEST_EQUAL(str(-9), "-9");
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     526 [ +  - ][ -  + ]:          1 :     TEST_EQUAL(str(-10), "-10");
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     527 [ +  - ][ -  + ]:          1 :     TEST_EQUAL(str(0x7f), "127");
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     528 [ +  - ][ -  + ]:          1 :     TEST_EQUAL(str(-0x80), "-128");
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     529 [ +  - ][ -  + ]:          1 :     TEST_EQUAL(str(0x7fff), "32767");
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     530 [ +  - ][ -  + ]:          1 :     TEST_EQUAL(str(0xffffffff), "4294967295");
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     531 [ +  - ][ -  + ]:          1 :     TEST_EQUAL(str(0x7fffffff), "2147483647");
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     532 [ +  - ][ -  + ]:          1 :     TEST_EQUAL(str(0x7fffffffu), "2147483647");
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     533 [ +  - ][ -  + ]:          1 :     TEST_EQUAL(str(-0x7fffffff), "-2147483647");
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     534                 :            : 
     535                 :          1 :     tostring_helper<char>();
     536                 :          1 :     tostring_helper<short>();
     537                 :          1 :     tostring_helper<int>();
     538                 :          1 :     tostring_helper<long>();
     539                 :          1 :     tostring_helper<long long>();
     540                 :            : 
     541                 :            : #ifdef __WIN32__
     542                 :            :     /* Test the 64 bit integer conversion to string.
     543                 :            :      * (Currently only exists for windows.)
     544                 :            :      */
     545                 :            :     TEST_EQUAL(str(10ll), "10");
     546                 :            :     TEST_EQUAL(str(-10ll), "-10");
     547                 :            :     TEST_EQUAL(str(0x200000000ll), "8589934592");
     548                 :            : // We don't currently have an "unsigned long long" version since it's not required
     549                 :            : // anywhere in the library.
     550                 :            : //    TEST_EQUAL(str(0x200000000ull), "8589934592");
     551                 :            : #endif
     552                 :            : 
     553                 :          1 :     return true;
     554                 :            : }
     555                 :            : 
     556                 :            : /// Regression test for bug fixed in 1.1.1.
     557                 :          1 : static bool test_strbool1()
     558                 :            : {
     559 [ +  - ][ -  + ]:          1 :     TEST_EQUAL(str(true), "1");
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     560 [ +  - ][ -  + ]:          1 :     TEST_EQUAL(str(false), "0");
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     561                 :          1 :     return true;
     562                 :            : }
     563                 :            : 
     564                 :          1 : static bool test_closefrom1()
     565                 :            : {
     566                 :            : #ifndef __WIN32__
     567                 :            :     // Simple test.
     568                 :          1 :     closefrom(8);
     569                 :            : 
     570                 :            :     // Simple test when there are definitely no fds to close.
     571                 :          1 :     closefrom(42);
     572                 :            : 
     573                 :            :     // Test passing a really high threshold.
     574                 :          1 :     closefrom(INT_MAX);
     575                 :            : 
     576                 :            :     // Open some fds and check the expected ones are closed.
     577 [ -  + ][ -  + ]:          1 :     TEST_EQUAL(dup2(1, 14), 14);
                 [ #  # ]
     578 [ -  + ][ -  + ]:          1 :     TEST_EQUAL(dup2(1, 15), 15);
                 [ #  # ]
     579 [ -  + ][ -  + ]:          1 :     TEST_EQUAL(dup2(1, 18), 18);
                 [ #  # ]
     580                 :          1 :     closefrom(15);
     581 [ -  + ][ -  + ]:          1 :     TEST_EQUAL(close(14), 0);
                 [ #  # ]
     582 [ +  - ][ -  + ]:          1 :     TEST(close(15) == -1 && errno == EBADF);
         [ -  + ][ -  + ]
                 [ #  # ]
     583 [ +  - ][ -  + ]:          1 :     TEST(close(18) == -1 && errno == EBADF);
         [ -  + ][ -  + ]
                 [ #  # ]
     584                 :            : #endif
     585                 :          1 :     return true;
     586                 :            : }
     587                 :            : 
     588                 :          1 : static bool test_shard1()
     589                 :            : {
     590         [ +  + ]:         10 :     for (Xapian::docid did = 1; did != 10; ++did) {
     591         [ +  + ]:         90 :         for (size_t n = 1; n != 10; ++n) {
     592                 :         81 :             Xapian::docid s_did = shard_docid(did, n);
     593                 :         81 :             size_t shard = shard_number(did, n);
     594 [ -  + ][ -  + ]:         81 :             TEST_EQUAL(s_did, (did - 1) / n + 1);
                 [ #  # ]
     595 [ -  + ][ -  + ]:         81 :             TEST_EQUAL(shard, (did - 1) % n);
                 [ #  # ]
     596         [ +  + ]:         81 :             if (n == 1)
     597 [ -  + ][ -  + ]:          9 :                 TEST_EQUAL(did, s_did);
                 [ #  # ]
     598         [ +  + ]:         81 :             if (did == 1)
     599 [ -  + ][ -  + ]:          9 :                 TEST_EQUAL(s_did, 1);
                 [ #  # ]
     600         [ +  + ]:         81 :             if (s_did == 1)
     601 [ -  + ][ -  + ]:         45 :                 TEST(did <= n);
                 [ #  # ]
     602 [ -  + ][ -  + ]:         81 :             TEST(s_did != 0);
                 [ #  # ]
     603 [ -  + ][ -  + ]:         81 :             TEST(s_did <= did);
                 [ #  # ]
     604 [ -  + ][ -  + ]:         81 :             TEST(shard < n);
                 [ #  # ]
     605 [ -  + ][ -  + ]:         81 :             TEST_EQUAL(did, unshard(s_did, shard, n));
                 [ #  # ]
     606                 :            :         }
     607                 :            :     }
     608                 :          1 :     return true;
     609                 :            : }
     610                 :            : 
     611                 :          1 : static bool test_uuid1()
     612                 :            : {
     613                 :          1 :     Uuid uuid, uuid2;
     614                 :            : 
     615                 :            :     // Test a generated uuid.
     616         [ +  - ]:          1 :     uuid.generate();
     617 [ -  + ][ -  + ]:          1 :     TEST(!uuid.is_null());
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     618         [ +  - ]:          1 :     string str = uuid.to_string();
     619 [ -  + ][ -  + ]:          1 :     TEST_EQUAL(str.size(), 36);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
     620 [ +  - ][ -  + ]:          1 :     TEST_NOT_EQUAL(str, "00000000-0000-0000-0000-000000000000");
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     621                 :            :     // Check UUID pattern is correct and that upper case is not used.
     622         [ +  + ]:          9 :     for (int i = 0; i != 8; ++i) {
     623         [ +  - ]:          8 :         unsigned char ch = str[i];
     624 [ -  + ][ -  + ]:          8 :         TEST(isxdigit(ch));
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     625 [ -  + ][ -  + ]:          8 :         TEST(!isupper(ch));
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     626                 :            :     }
     627 [ +  - ][ -  + ]:          1 :     TEST_EQUAL(str[8], '-');
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
     628         [ +  + ]:          5 :     for (int i = 9; i != 13; ++i) {
     629         [ +  - ]:          4 :         unsigned char ch = str[i];
     630 [ -  + ][ -  + ]:          4 :         TEST(isxdigit(ch));
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     631 [ -  + ][ -  + ]:          4 :         TEST(!isupper(ch));
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     632                 :            :     }
     633 [ +  - ][ -  + ]:          1 :     TEST_EQUAL(str[13], '-');
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
     634         [ +  + ]:          5 :     for (int i = 14; i != 18; ++i) {
     635         [ +  - ]:          4 :         unsigned char ch = str[i];
     636 [ -  + ][ -  + ]:          4 :         TEST(isxdigit(ch));
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     637 [ -  + ][ -  + ]:          4 :         TEST(!isupper(ch));
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     638                 :            :     }
     639 [ +  - ][ -  + ]:          1 :     TEST_EQUAL(str[18], '-');
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
     640         [ +  + ]:          5 :     for (int i = 19; i != 23; ++i) {
     641         [ +  - ]:          4 :         unsigned char ch = str[i];
     642 [ -  + ][ -  + ]:          4 :         TEST(isxdigit(ch));
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     643 [ -  + ][ -  + ]:          4 :         TEST(!isupper(ch));
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     644                 :            :     }
     645 [ +  - ][ -  + ]:          1 :     TEST_EQUAL(str[23], '-');
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
     646         [ +  + ]:         13 :     for (int i = 24; i != 36; ++i) {
     647         [ +  - ]:         12 :         unsigned char ch = str[i];
     648 [ -  + ][ -  + ]:         12 :         TEST(isxdigit(ch));
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     649 [ -  + ][ -  + ]:         12 :         TEST(!isupper(ch));
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     650                 :            :     }
     651                 :            : 
     652         [ +  - ]:          1 :     uuid2.parse(str);
     653 [ -  + ][ -  + ]:          1 :     TEST(memcmp(uuid.data(), uuid2.data(), uuid.BINARY_SIZE) == 0);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     654                 :            : 
     655                 :            :     // Check the variant is "10x" and the version between 1 and 5.  Mostly this
     656                 :            :     // is to catch bugs where the platform's API for generating UUIDs uses a
     657                 :            :     // different endianness for fields (which we've run into under both WIN32
     658                 :            :     // and FreeBSD).
     659 [ -  + ][ -  + ]:          1 :     TEST_EQUAL(uuid.data()[8] & 0xc0, 0x80);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
     660 [ +  - ][ -  + ]:          1 :     TEST_REL(str[19], >=, '8');
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
     661 [ +  - ][ -  + ]:          1 :     TEST_REL(str[19], <=, 'b');
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
     662 [ -  + ][ -  + ]:          1 :     TEST_REL(int(uuid.data()[6]), >=, 0x10);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
     663 [ -  + ][ -  + ]:          1 :     TEST_REL(int(uuid.data()[6]), <=, 0x5f);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
     664 [ +  - ][ -  + ]:          1 :     TEST_REL(str[14], >=, '1');
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
     665 [ +  - ][ -  + ]:          1 :     TEST_REL(str[14], <=, '5');
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
     666                 :            : 
     667                 :            :     // Test generating another uuid gives us a different non-null uuid.
     668         [ +  - ]:          1 :     uuid2.generate();
     669 [ -  + ][ -  + ]:          1 :     TEST(!uuid2.is_null());
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     670 [ -  + ][ -  + ]:          1 :     TEST(memcmp(uuid.data(), uuid2.data(), uuid.BINARY_SIZE) != 0);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     671                 :            : 
     672                 :            :     // Test null uuid.
     673                 :          1 :     uuid.clear();
     674 [ -  + ][ -  + ]:          1 :     TEST(uuid.is_null());
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     675 [ +  - ][ +  - ]:          1 :     str = uuid.to_string();
     676 [ +  - ][ -  + ]:          1 :     TEST_EQUAL(str, "00000000-0000-0000-0000-000000000000");
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     677         [ +  - ]:          1 :     uuid2.generate();
     678 [ -  + ][ -  + ]:          1 :     TEST(!uuid2.is_null());
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     679         [ +  - ]:          1 :     uuid2.parse(str);
     680 [ -  + ][ -  + ]:          1 :     TEST(memcmp(uuid.data(), uuid2.data(), uuid.BINARY_SIZE) == 0);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     681                 :            : 
     682                 :          1 :     return true;
     683                 :            : }
     684                 :            : 
     685                 :            : // Classes used by movesupport1 test
     686                 :            : class A : public Xapian::Internal::intrusive_base {
     687                 :            :     int x = 0;
     688                 :            :   public:
     689                 :          6 :     explicit A(int x_) : x(x_) {}
     690                 :            : 
     691                 :          4 :     int get_x() const {
     692                 :          4 :         return x;
     693                 :            :     }
     694                 :            : };
     695                 :            : 
     696                 :            : class B : public Xapian::Internal::opt_intrusive_base {
     697                 :            :     int x = 0;
     698                 :            :     bool & alive;
     699                 :            :   public:
     700                 :          2 :     B(int x_, bool & alive_) : x(x_), alive(alive_) {
     701                 :          1 :         alive = true;
     702                 :          1 :     }
     703                 :            : 
     704                 :          3 :     ~B() {
     705                 :          1 :         alive = false;
     706         [ -  + ]:          2 :     }
     707                 :            : 
     708                 :          2 :     int get_x() const {
     709                 :          2 :         return x;
     710                 :            :     }
     711                 :            : 
     712                 :          1 :     B * release() {
     713                 :          1 :         opt_intrusive_base::release();
     714                 :          1 :         return this;
     715                 :            :     }
     716                 :            : };
     717                 :            : 
     718                 :          1 : static bool test_movesupport1()
     719                 :            : {
     720                 :            :     {
     721                 :            :         // Test move semantics support for intrusive_ptr class
     722         [ +  - ]:          1 :         Xapian::Internal::intrusive_ptr<A> p1(new A{5});
     723                 :          2 :         Xapian::Internal::intrusive_ptr<A> p3;
     724                 :            : 
     725                 :            :         // Test move constructor
     726                 :          2 :         Xapian::Internal::intrusive_ptr<A> p2(std::move(p1));
     727 [ -  + ][ -  + ]:          1 :         TEST_EQUAL(p2->get_x(), 5);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
     728 [ -  + ][ -  + ]:          1 :         TEST_EQUAL(p1.get(), 0);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
     729                 :            : 
     730                 :            :         // Test move assignment
     731         [ +  - ]:          1 :         p3 = std::move(p2);
     732 [ -  + ][ -  + ]:          1 :         TEST_EQUAL(p3->get_x(), 5);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
     733 [ -  + ][ -  + ]:          2 :         TEST_EQUAL(p2.get(), 0);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
     734                 :            :     }
     735                 :            : 
     736                 :            :     {
     737                 :            :         // Same test for intrusive_ptr_nonnull class
     738         [ +  - ]:          1 :         Xapian::Internal::intrusive_ptr_nonnull<A> p1(new A{5});
     739         [ +  - ]:          2 :         Xapian::Internal::intrusive_ptr_nonnull<A> p3(new A{6});
     740                 :            : 
     741                 :            :         // Test move constructor
     742                 :          2 :         Xapian::Internal::intrusive_ptr_nonnull<A> p2(std::move(p1));
     743 [ -  + ][ -  + ]:          1 :         TEST_EQUAL(p2->get_x(), 5);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
     744                 :            : 
     745                 :            :         // Test move assignment
     746         [ +  - ]:          1 :         p3 = std::move(p2);
     747 [ -  + ][ -  + ]:          2 :         TEST_EQUAL(p3->get_x(), 5);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
     748                 :            :     }
     749                 :            : 
     750                 :          1 :     bool alive = false;
     751                 :            :     {
     752                 :            :         // Same test for opt_intrusive_ptr class
     753         [ +  - ]:          1 :         B * b1 = new B{5, alive};
     754                 :          1 :         b1->release();
     755                 :          1 :         Xapian::Internal::opt_intrusive_ptr<B> p1(b1);
     756                 :          2 :         Xapian::Internal::opt_intrusive_ptr<B> p3;
     757                 :            : 
     758                 :            :         // Test move constructor
     759                 :          2 :         Xapian::Internal::opt_intrusive_ptr<B> p2(std::move(p1));
     760 [ -  + ][ -  + ]:          1 :         TEST_EQUAL(p2->get_x(), 5);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
     761 [ -  + ][ -  + ]:          1 :         TEST_EQUAL(p1.get(), 0);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
     762 [ -  + ][ -  + ]:          1 :         TEST_EQUAL(alive, true);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
     763                 :            : 
     764                 :            :         // Test move assignment
     765         [ +  - ]:          1 :         p3 = std::move(p2);
     766 [ -  + ][ -  + ]:          1 :         TEST_EQUAL(p3->get_x(), 5);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
     767 [ -  + ][ -  + ]:          1 :         TEST_EQUAL(p2.get(), 0);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
     768 [ -  + ][ -  + ]:          2 :         TEST_EQUAL(alive, true);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
     769                 :            :     }
     770                 :            :     // Test that object b1 has been deleted.
     771 [ -  + ][ -  + ]:          1 :     TEST_EQUAL(alive, false);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
     772                 :          1 :     return true;
     773                 :            : }
     774                 :            : 
     775                 :          1 : static bool test_addoverflows1()
     776                 :            : {
     777                 :            :     unsigned long res;
     778 [ -  + ][ -  + ]:          1 :     TEST(!add_overflows(0UL, 0UL, res));
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     779 [ -  + ][ -  + ]:          1 :     TEST_EQUAL(res, 0);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
     780                 :            : 
     781 [ -  + ][ -  + ]:          1 :     TEST(add_overflows(ULONG_MAX, 1UL, res));
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     782 [ -  + ][ -  + ]:          1 :     TEST_EQUAL(res, 0);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
     783                 :            : 
     784 [ -  + ][ -  + ]:          1 :     TEST(add_overflows(1UL, ULONG_MAX, res));
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     785 [ -  + ][ -  + ]:          1 :     TEST_EQUAL(res, 0);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
     786                 :            : 
     787 [ -  + ][ -  + ]:          1 :     TEST(add_overflows(ULONG_MAX, ULONG_MAX, res));
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     788 [ -  + ][ -  + ]:          1 :     TEST_EQUAL(res, ULONG_MAX - 1UL);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
     789                 :            : 
     790                 :          1 :     return true;
     791                 :            : }
     792                 :            : 
     793                 :          1 : static bool test_muloverflows1()
     794                 :            : {
     795                 :            :     unsigned long res;
     796 [ -  + ][ -  + ]:          1 :     TEST(!mul_overflows(0UL, 0UL, res));
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     797 [ -  + ][ -  + ]:          1 :     TEST_EQUAL(res, 0);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
     798                 :            : 
     799 [ -  + ][ -  + ]:          1 :     TEST(!mul_overflows(ULONG_MAX, 0UL, res));
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     800 [ -  + ][ -  + ]:          1 :     TEST_EQUAL(res, 0);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
     801                 :            : 
     802 [ -  + ][ -  + ]:          1 :     TEST(!mul_overflows(0UL, ULONG_MAX, res));
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     803 [ -  + ][ -  + ]:          1 :     TEST_EQUAL(res, 0);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
     804                 :            : 
     805 [ -  + ][ -  + ]:          1 :     TEST(!mul_overflows(ULONG_MAX, 1UL, res));
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     806 [ -  + ][ -  + ]:          1 :     TEST_EQUAL(res, ULONG_MAX);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
     807                 :            : 
     808 [ -  + ][ -  + ]:          1 :     TEST(!mul_overflows(1UL, ULONG_MAX, res));
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     809 [ -  + ][ -  + ]:          1 :     TEST_EQUAL(res, ULONG_MAX);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
     810                 :            : 
     811 [ -  + ][ -  + ]:          1 :     TEST(mul_overflows((ULONG_MAX >> 1UL) + 1UL, 2UL, res));
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     812 [ -  + ][ -  + ]:          1 :     TEST_EQUAL(res, 0);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
     813                 :            : 
     814 [ -  + ][ -  + ]:          1 :     TEST(mul_overflows(2UL, (ULONG_MAX >> 1UL) + 1UL, res));
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     815 [ -  + ][ -  + ]:          1 :     TEST_EQUAL(res, 0);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
     816                 :            : 
     817 [ -  + ][ -  + ]:          1 :     TEST(mul_overflows(ULONG_MAX, ULONG_MAX, res));
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     818                 :            : 
     819                 :          1 :     return true;
     820                 :            : }
     821                 :            : 
     822                 :            : template<typename U>
     823                 :          5 : inline static void parseunsigned_helper() {
     824                 :            :     U val;
     825                 :          5 :     const U max_val = numeric_limits<U>::max();
     826 [ +  - ][ +  - ]:          5 :     tout << "Testing with parseunsigned_helper" << endl;
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
     827 [ +  - ][ -  + ]:          5 :     TEST(parse_unsigned("0", val));
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ +  - ][ -  + ]
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ +  - ][ -  + ]
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ +  - ][ -  + ]
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ +  - ][ -  + ]
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
     828 [ -  + ][ -  + ]:          5 :     TEST_EQUAL(val, 0);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ -  + ][ -  + ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ -  + ][ -  + ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ -  + ][ -  + ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ -  + ][ -  + ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
     829 [ +  - ][ -  + ]:          5 :     TEST(parse_unsigned("99", val));
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ +  - ][ -  + ]
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ +  - ][ -  + ]
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ +  - ][ -  + ]
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ +  - ][ -  + ]
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
     830 [ -  + ][ -  + ]:          5 :     TEST_EQUAL(val, 99);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ -  + ][ -  + ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ -  + ][ -  + ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ -  + ][ -  + ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ -  + ][ -  + ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
     831 [ +  - ][ +  - ]:          5 :     TEST(parse_unsigned(str(max_val).c_str(), val));
         [ -  + ][ -  + ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ +  - ]
         [ +  - ][ -  + ]
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ +  - ][ +  - ]
         [ -  + ][ -  + ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ +  - ]
         [ +  - ][ -  + ]
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ +  - ][ +  - ]
         [ -  + ][ -  + ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     832 [ -  + ][ -  + ]:          5 :     TEST_EQUAL(val, max_val);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ -  + ][ -  + ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ -  + ][ -  + ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ -  + ][ -  + ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ -  + ][ -  + ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
     833 [ +  - ][ -  + ]:          5 :     TEST(!parse_unsigned("", val));
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ +  - ][ -  + ]
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ +  - ][ -  + ]
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ +  - ][ -  + ]
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ +  - ][ -  + ]
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
     834 [ +  - ][ -  + ]:          5 :     TEST(!parse_unsigned("-1", val));
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ +  - ][ -  + ]
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ +  - ][ -  + ]
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ +  - ][ -  + ]
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ +  - ][ -  + ]
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
     835 [ +  - ][ -  + ]:          5 :     TEST(!parse_unsigned("abc", val));
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ +  - ][ -  + ]
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ +  - ][ -  + ]
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ +  - ][ -  + ]
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ +  - ][ -  + ]
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
     836 [ +  - ][ -  + ]:          5 :     TEST(!parse_unsigned("0a", val));
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ +  - ][ -  + ]
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ +  - ][ -  + ]
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ +  - ][ -  + ]
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ +  - ][ -  + ]
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
     837                 :            :     // Only test if we can construct a value one larger easily.
     838                 :            :     if (max_val + 1ull != 0)
     839 [ +  - ][ +  - ]:          3 :         TEST(!parse_unsigned(str(max_val + 1ull).c_str(), val));
         [ -  + ][ -  + ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ +  - ]
         [ +  - ][ -  + ]
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ +  - ][ +  - ]
         [ -  + ][ -  + ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     840                 :          5 : }
     841                 :            : 
     842                 :          1 : static bool test_parseunsigned1()
     843                 :            : {
     844                 :          1 :     parseunsigned_helper<unsigned char>();
     845                 :          1 :     parseunsigned_helper<unsigned short>();
     846                 :          1 :     parseunsigned_helper<unsigned>();
     847                 :          1 :     parseunsigned_helper<unsigned long>();
     848                 :          1 :     parseunsigned_helper<unsigned long long>();
     849                 :            : 
     850                 :          1 :     return true;
     851                 :            : }
     852                 :            : 
     853                 :            : template<typename S>
     854                 :          5 : inline static void parsesigned_helper() {
     855                 :            :     S val;
     856                 :          5 :     const S max_val = numeric_limits<S>::max();
     857                 :          5 :     const S min_val = numeric_limits<S>::min();
     858 [ +  - ][ +  - ]:          5 :     tout << "Testing with parsesigned_helper" << endl;
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
     859 [ +  - ][ -  + ]:          5 :     TEST(parse_signed("0", val));
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ +  - ][ -  + ]
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ +  - ][ -  + ]
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ +  - ][ -  + ]
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ +  - ][ -  + ]
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
     860 [ -  + ][ -  + ]:          5 :     TEST_EQUAL(val, 0);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ -  + ][ -  + ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ -  + ][ -  + ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ -  + ][ -  + ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ -  + ][ -  + ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
     861 [ +  - ][ -  + ]:          5 :     TEST(parse_signed("99", val));
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ +  - ][ -  + ]
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ +  - ][ -  + ]
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ +  - ][ -  + ]
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ +  - ][ -  + ]
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
     862 [ -  + ][ -  + ]:          5 :     TEST_EQUAL(val, 99);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ -  + ][ -  + ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ -  + ][ -  + ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ -  + ][ -  + ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ -  + ][ -  + ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
     863 [ +  - ][ -  + ]:          5 :     TEST(parse_signed("-99", val));
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ +  - ][ -  + ]
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ +  - ][ -  + ]
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ +  - ][ -  + ]
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ +  - ][ -  + ]
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
     864 [ -  + ][ -  + ]:          5 :     TEST_EQUAL(val, -99);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ -  + ][ -  + ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ -  + ][ -  + ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ -  + ][ -  + ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ -  + ][ -  + ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
     865 [ +  - ][ +  - ]:          5 :     TEST(parse_signed(str(max_val).c_str(), val));
         [ -  + ][ -  + ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ +  - ]
         [ +  - ][ -  + ]
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ +  - ][ +  - ]
         [ -  + ][ -  + ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ +  - ]
         [ +  - ][ -  + ]
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ +  - ][ +  - ]
         [ -  + ][ -  + ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     866 [ -  + ][ -  + ]:          5 :     TEST_EQUAL(val, max_val);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ -  + ][ -  + ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ -  + ][ -  + ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ -  + ][ -  + ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ -  + ][ -  + ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
     867 [ +  - ][ +  - ]:          5 :     TEST(parse_signed(str(min_val).c_str(), val));
         [ -  + ][ -  + ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ +  - ]
         [ +  - ][ -  + ]
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ +  - ][ +  - ]
         [ -  + ][ -  + ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ +  - ]
         [ +  - ][ -  + ]
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ +  - ][ +  - ]
         [ -  + ][ -  + ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     868 [ -  + ][ -  + ]:          5 :     TEST_EQUAL(val, min_val);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ -  + ][ -  + ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ -  + ][ -  + ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ -  + ][ -  + ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ -  + ][ -  + ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
     869 [ +  - ][ -  + ]:          5 :     TEST(!parse_signed("", val));
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ +  - ][ -  + ]
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ +  - ][ -  + ]
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ +  - ][ -  + ]
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ +  - ][ -  + ]
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
     870 [ +  - ][ -  + ]:          5 :     TEST(!parse_signed("abc", val));
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ +  - ][ -  + ]
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ +  - ][ -  + ]
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ +  - ][ -  + ]
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ +  - ][ -  + ]
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
     871 [ +  - ][ -  + ]:          5 :     TEST(!parse_signed("0a", val));
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ +  - ][ -  + ]
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ +  - ][ -  + ]
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ +  - ][ -  + ]
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ +  - ][ -  + ]
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
     872 [ +  - ][ -  + ]:          5 :     TEST(!parse_signed("-99a", val));
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ +  - ][ -  + ]
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ +  - ][ -  + ]
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ +  - ][ -  + ]
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ +  - ][ -  + ]
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
     873 [ +  - ][ -  + ]:          5 :     TEST(!parse_signed("-a99", val));
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ +  - ][ -  + ]
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ +  - ][ -  + ]
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ +  - ][ -  + ]
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ +  - ][ -  + ]
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
     874 [ +  - ][ -  + ]:          5 :     TEST(!parse_signed("--99", val));
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ +  - ][ -  + ]
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ +  - ][ -  + ]
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ +  - ][ -  + ]
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ +  - ][ -  + ]
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
     875                 :            : 
     876                 :          5 :     unsigned long long one_too_large = max_val + 1ull;
     877 [ +  - ][ +  - ]:          5 :     TEST(!parse_signed(str(one_too_large).c_str(), val));
         [ -  + ][ -  + ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ +  - ]
         [ +  - ][ -  + ]
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ +  - ][ +  - ]
         [ -  + ][ -  + ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ +  - ]
         [ +  - ][ -  + ]
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ +  - ][ +  - ]
         [ -  + ][ -  + ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     878                 :            : 
     879                 :          5 :     unsigned long long one_too_small_negated = 1ull - min_val;
     880 [ +  - ][ +  - ]:          5 :     TEST(!parse_signed(("-" + str(one_too_small_negated)).c_str(), val));
         [ +  - ][ -  + ]
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ +  - ][ +  - ]
         [ +  - ][ -  + ]
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ +  - ][ +  - ]
         [ +  - ][ -  + ]
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ +  - ][ +  - ]
         [ +  - ][ -  + ]
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ +  - ][ +  - ]
         [ +  - ][ -  + ]
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
     881                 :          5 : }
     882                 :            : 
     883                 :          1 : static bool test_parsesigned1()
     884                 :            : {
     885                 :          1 :     parsesigned_helper<signed char>();
     886                 :          1 :     parsesigned_helper<short>();
     887                 :          1 :     parsesigned_helper<int>();
     888                 :          1 :     parsesigned_helper<long>();
     889                 :          1 :     parsesigned_helper<long long>();
     890                 :            : 
     891                 :          1 :     return true;
     892                 :            : }
     893                 :            : 
     894                 :            : static const test_desc tests[] = {
     895                 :            :     TESTCASE(simple_exceptions_work1),
     896                 :            :     TESTCASE(class_exceptions_work1),
     897                 :            :     TESTCASE(resolverelativepath1),
     898                 :            :     TESTCASE(serialisedouble1),
     899                 :            :     TESTCASE(packuint1),
     900                 :            :     TESTCASE(packstring1),
     901                 :            :     TESTCASE(packstring2),
     902                 :            : #ifdef XAPIAN_HAS_REMOTE_BACKEND
     903                 :            :     TESTCASE(serialiseerror1),
     904                 :            : #endif
     905                 :            :     TESTCASE(log2),
     906                 :            :     TESTCASE(sortableserialise1),
     907                 :            :     TESTCASE(tostring1),
     908                 :            :     TESTCASE(strbool1),
     909                 :            :     TESTCASE(closefrom1),
     910                 :            :     TESTCASE(shard1),
     911                 :            :     TESTCASE(uuid1),
     912                 :            :     TESTCASE(movesupport1),
     913                 :            :     TESTCASE(addoverflows1),
     914                 :            :     TESTCASE(muloverflows1),
     915                 :            :     TESTCASE(parseunsigned1),
     916                 :            :     TESTCASE(parsesigned1),
     917                 :            :     END_OF_TESTCASES
     918                 :            : };
     919                 :            : 
     920                 :          1 : int main(int argc, char **argv)
     921                 :            : try {
     922         [ +  - ]:          1 :     test_driver::parse_command_line(argc, argv);
     923         [ +  - ]:          1 :     return test_driver::run(tests);
     924         [ #  # ]:          0 : } catch (const char * e) {
     925   [ #  #  #  # ]:          0 :     cout << e << endl;
     926                 :          0 :     return 1;
     927 [ +  - ][ +  - ]:          4 : }

Generated by: LCOV version 1.11