xapian-core  2.0.0
Classes | Macros | Functions | Variables
unittest.cc File Reference

Unit tests of non-Xapian-specific internal code. More...

#include <config.h>
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <climits>
#include <cmath>
#include <cstring>
#include <iostream>
#include <limits>
#include <memory>
#include <string_view>
#include <utility>
#include "safeunistd.h"
#include "testsuite.h"
#include "../backends/multi.h"
#include "../common/stringutils.h"
#include "../backends/uuids.cc"
#include "../common/closefrom.cc"
#include "../common/errno_to_string.cc"
#include "../common/io_utils.cc"
#include "../common/fileutils.cc"
#include "../common/overflow.h"
#include "../common/pack.cc"
#include "../common/parseint.h"
#include "../common/posixy_wrapper.cc"
#include "../common/serialise-double.cc"
#include "../common/str.cc"
#include "../net/serialise-error.cc"
#include "../api/error.cc"
#include "../api/smallvector.cc"
#include "../api/sortable-serialise.cc"
#include "../include/xapian/intrusive_ptr.h"
#include "../common/msvc_dirent.cc"
#include "../api/constinfo.cc"
+ Include dependency graph for unittest.cc:

Go to the source code of this file.

Classes

class  TestException
 
class  A
 
class  B
 

Macros

#define XAPIAN_UNITTEST
 
#define UNITTEST_CHECK_EXCEPTION
 
#define UNITTEST_ASSERT_LOCATION__(LINE, MSG)   __FILE__":"#LINE": "#MSG
 
#define UNITTEST_ASSERT_LOCATION_(LINE, MSG)   UNITTEST_ASSERT_LOCATION__(LINE,MSG)
 
#define UNITTEST_ASSERT_LOCATION(MSG)   UNITTEST_ASSERT_LOCATION_(__LINE__,MSG)
 
#define UNITTEST_ASSERT_NOTHROW(COND, RET)
 
#define TEST_EXCEPTION(TYPE, CODE)
 

Functions

void description_append (std::string &desc, std::string_view s)
 
 DEFINE_TESTCASE (simple_exceptions_work1)
 
 DEFINE_TESTCASE (class_exceptions_work1)
 
static string r_r_p (string a, const string &b)
 
 DEFINE_TESTCASE (resolverelativepath1)
 
static void check_double_serialisation (double u)
 
 DEFINE_TESTCASE (serialisedouble1)
 
static void test_packuint1 ()
 
static void packstring1_helper (size_t len)
 
static void test_packstring1 ()
 
static void test_packstring2 ()
 
static void test_sortableserialise1 ()
 
template<typename S >
static void tostring_helper ()
 
static void test_tostring1 ()
 
static void test_strbool1 ()
 Regression test for bug fixed in 1.1.1. More...
 
static void test_closefrom1 ()
 
static void test_shard1 ()
 
static void test_uuid1 ()
 
static void test_movesupport1 ()
 
static void test_addoverflows1 ()
 
static void test_suboverflows1 ()
 
static void test_muloverflows1 ()
 
template<typename U >
static void parseunsigned_helper ()
 
static void test_parseunsigned1 ()
 
template<typename S >
static void parsesigned_helper ()
 
static void test_parsesigned1 ()
 
static void test_ioblock1 ()
 Test working with a block-based file using functions from io_utils.h. More...
 
 DEFINE_TESTCASE (vec1)
 
 DEFINE_TESTCASE (vecdeleter1)
 
int main (int argc, char **argv)
 

Variables

static const char * unittest_assertion_failed = NULL
 
static const double test_sortableserialise_numbers []
 
static const test_desc tests []
 

Detailed Description

Unit tests of non-Xapian-specific internal code.

Definition in file unittest.cc.

Macro Definition Documentation

◆ TEST_EXCEPTION

#define TEST_EXCEPTION (   TYPE,
  CODE 
)
Value:
do { \
try { \
CODE; \
FAIL_TEST("Expected exception "#TYPE" not thrown"); \
} catch (const TYPE &) { \
} \
} while (0)
#define FAIL_TEST(MSG)
Fail the current testcase with message MSG.
Definition: testsuite.h:65

Definition at line 65 of file unittest.cc.

◆ UNITTEST_ASSERT_LOCATION

#define UNITTEST_ASSERT_LOCATION (   MSG)    UNITTEST_ASSERT_LOCATION_(__LINE__,MSG)

Definition at line 51 of file unittest.cc.

◆ UNITTEST_ASSERT_LOCATION_

#define UNITTEST_ASSERT_LOCATION_ (   LINE,
  MSG 
)    UNITTEST_ASSERT_LOCATION__(LINE,MSG)

Definition at line 50 of file unittest.cc.

◆ UNITTEST_ASSERT_LOCATION__

#define UNITTEST_ASSERT_LOCATION__ (   LINE,
  MSG 
)    __FILE__":"#LINE": "#MSG

Definition at line 49 of file unittest.cc.

◆ UNITTEST_ASSERT_NOTHROW

#define UNITTEST_ASSERT_NOTHROW (   COND,
  RET 
)
Value:
do {\
if (rare(!(COND))) {\
unittest_assertion_failed = UNITTEST_ASSERT_LOCATION(COND);\
return RET;\
}\
} while (false)
#define rare(COND)
Definition: config.h:607
#define UNITTEST_ASSERT_LOCATION(MSG)
Definition: unittest.cc:51

Definition at line 52 of file unittest.cc.

◆ UNITTEST_CHECK_EXCEPTION

#define UNITTEST_CHECK_EXCEPTION
Value:
const char * unittest_assertion_failed_ = unittest_assertion_failed;\
unittest_assertion_failed = NULL;\
throw unittest_assertion_failed_;\
}
static const char * unittest_assertion_failed
Definition: unittest.cc:39

Definition at line 40 of file unittest.cc.

◆ XAPIAN_UNITTEST

#define XAPIAN_UNITTEST

Definition at line 38 of file unittest.cc.

Function Documentation

◆ check_double_serialisation()

static void check_double_serialisation ( double  u)
static

Definition at line 208 of file unittest.cc.

References serialise_double(), TEST, TEST_EQUAL, and unserialise_double().

Referenced by DEFINE_TESTCASE().

◆ DEFINE_TESTCASE() [1/6]

DEFINE_TESTCASE ( class_exceptions_work1  )

Definition at line 120 of file unittest.cc.

◆ DEFINE_TESTCASE() [2/6]

DEFINE_TESTCASE ( resolverelativepath1  )

Definition at line 134 of file unittest.cc.

References r_r_p(), and TEST_EQUAL.

◆ DEFINE_TESTCASE() [3/6]

DEFINE_TESTCASE ( serialisedouble1  )

Definition at line 234 of file unittest.cc.

References check_double_serialisation().

◆ DEFINE_TESTCASE() [4/6]

DEFINE_TESTCASE ( simple_exceptions_work1  )

Definition at line 110 of file unittest.cc.

References TEST_EQUAL.

◆ DEFINE_TESTCASE() [5/6]

DEFINE_TESTCASE ( vec1  )

◆ DEFINE_TESTCASE() [6/6]

DEFINE_TESTCASE ( vecdeleter1  )

◆ description_append()

void description_append ( std::string &  desc,
std::string_view  s 
)

◆ main()

int main ( int  argc,
char **  argv 
)

Definition at line 1070 of file unittest.cc.

References test_driver::parse_command_line(), test_driver::run(), and tests.

◆ packstring1_helper()

static void packstring1_helper ( size_t  len)
static

Definition at line 285 of file unittest.cc.

References p, pack_string(), TEST, TEST_EQUAL, and unpack_string().

Referenced by test_packstring1().

◆ parsesigned_helper()

template<typename S >
static void parsesigned_helper ( )
inlinestatic

Definition at line 874 of file unittest.cc.

References parse_signed(), Xapian::Internal::str(), TEST, TEST_EQUAL, and tout.

◆ parseunsigned_helper()

template<typename U >
static void parseunsigned_helper ( )
inlinestatic

Definition at line 845 of file unittest.cc.

References parse_unsigned(), Xapian::Internal::str(), TEST, TEST_EQUAL, and tout.

◆ r_r_p()

static string r_r_p ( string  a,
const string &  b 
)
inlinestatic

Definition at line 128 of file unittest.cc.

References resolve_relative_path().

Referenced by DEFINE_TESTCASE().

◆ test_addoverflows1()

static void test_addoverflows1 ( )
static

Definition at line 748 of file unittest.cc.

References add_overflows(), TEST, and TEST_EQUAL.

◆ test_closefrom1()

static void test_closefrom1 ( )
static

Definition at line 531 of file unittest.cc.

References close(), Xapian::Internal::closefrom(), TEST, and TEST_EQUAL.

◆ test_ioblock1()

static void test_ioblock1 ( )
static

◆ test_movesupport1()

static void test_movesupport1 ( )
static

◆ test_muloverflows1()

static void test_muloverflows1 ( )
static

Definition at line 817 of file unittest.cc.

References mul_overflows(), TEST, and TEST_EQUAL.

◆ test_packstring1()

static void test_packstring1 ( )
static

Definition at line 323 of file unittest.cc.

References packstring1_helper().

◆ test_packstring2()

static void test_packstring2 ( )
static

Definition at line 334 of file unittest.cc.

References pack_string(), pack_string_empty(), and TEST_EQUAL.

◆ test_packuint1()

static void test_packuint1 ( )
static

Definition at line 263 of file unittest.cc.

References p, pack_uint(), TEST, TEST_EQUAL, tout, and unpack_uint().

◆ test_parsesigned1()

static void test_parsesigned1 ( )
static

Definition at line 911 of file unittest.cc.

◆ test_parseunsigned1()

static void test_parseunsigned1 ( )
static

Definition at line 864 of file unittest.cc.

◆ test_shard1()

static void test_shard1 ( )
static

Definition at line 555 of file unittest.cc.

References shard_docid(), shard_number(), TEST, TEST_EQUAL, and unshard().

◆ test_sortableserialise1()

static void test_sortableserialise1 ( )
static

◆ test_strbool1()

static void test_strbool1 ( )
static

Regression test for bug fixed in 1.1.1.

Definition at line 525 of file unittest.cc.

References Xapian::Internal::str(), and TEST_EQUAL.

◆ test_suboverflows1()

static void test_suboverflows1 ( )
static

Definition at line 801 of file unittest.cc.

References sub_overflows(), TEST, and TEST_EQUAL.

◆ test_tostring1()

static void test_tostring1 ( )
static

Definition at line 484 of file unittest.cc.

References Xapian::Internal::str(), and TEST_EQUAL.

◆ test_uuid1()

static void test_uuid1 ( )
static

◆ tostring_helper()

template<typename S >
static void tostring_helper ( )
inlinestatic

Definition at line 468 of file unittest.cc.

References Xapian::Internal::str(), TEST_EQUAL, and tout.

Variable Documentation

◆ test_sortableserialise_numbers

const double test_sortableserialise_numbers[]
static

Definition at line 380 of file unittest.cc.

Referenced by test_sortableserialise1().

◆ tests

const test_desc tests[]
static
Initial value:
= {
TESTCASE(simple_exceptions_work1),
TESTCASE(class_exceptions_work1),
TESTCASE(resolverelativepath1),
TESTCASE(serialisedouble1),
TESTCASE(packuint1),
TESTCASE(packstring1),
TESTCASE(packstring2),
TESTCASE(sortableserialise1),
TESTCASE(tostring1),
TESTCASE(strbool1),
TESTCASE(closefrom1),
TESTCASE(shard1),
TESTCASE(uuid1),
TESTCASE(movesupport1),
TESTCASE(addoverflows1),
TESTCASE(suboverflows1),
TESTCASE(muloverflows1),
TESTCASE(parseunsigned1),
TESTCASE(parsesigned1),
TESTCASE(ioblock1),
TESTCASE(vec1),
TESTCASE(vecdeleter1),
}
#define END_OF_TESTCASES
Definition: testmacros.h:32
#define TESTCASE(T)
Definition: testmacros.h:31

Definition at line 1041 of file unittest.cc.

Referenced by main().

◆ unittest_assertion_failed

const char* unittest_assertion_failed = NULL
static

Definition at line 39 of file unittest.cc.