xapian-core  1.4.21
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 <utility>
#include "safeunistd.h"
#include "testsuite.h"
#include "../common/stringutils.h"
#include "../common/log2.h"
#include "../common/closefrom.cc"
#include "../common/errno_to_string.cc"
#include "../common/fileutils.cc"
#include "../common/overflow.h"
#include "../common/parseint.h"
#include "../common/serialise-double.cc"
#include "../common/str.cc"
#include "../backends/uuids.cc"
#include "../net/length.cc"
#include "../net/serialise-error.cc"
#include "../api/error.cc"
#include "../api/sortable-serialise.cc"
#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, const std::string &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_serialiselength1 ()
 
static void test_serialiselength2 ()
 
static void test_serialiseerror1 ()
 
static void test_log2 ()
 
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_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 ()
 
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:68

Definition at line 66 of file unittest.cc.

Referenced by test_serialiselength2().

◆ UNITTEST_ASSERT_LOCATION

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

Definition at line 52 of file unittest.cc.

◆ UNITTEST_ASSERT_LOCATION_

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

Definition at line 51 of file unittest.cc.

◆ UNITTEST_ASSERT_LOCATION__

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

Definition at line 50 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 UNITTEST_ASSERT_LOCATION(MSG)
Definition: unittest.cc:52
#define rare(COND)
Definition: config.h:573

Definition at line 53 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:38

Definition at line 39 of file unittest.cc.

◆ XAPIAN_UNITTEST

#define XAPIAN_UNITTEST

Definition at line 37 of file unittest.cc.

Function Documentation

◆ check_double_serialisation()

static void check_double_serialisation ( double  u)
static

Definition at line 203 of file unittest.cc.

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

Referenced by DEFINE_TESTCASE_().

◆ DEFINE_TESTCASE_() [1/4]

DEFINE_TESTCASE_ ( simple_exceptions_work1  )

Definition at line 105 of file unittest.cc.

References TEST_EQUAL.

◆ DEFINE_TESTCASE_() [2/4]

DEFINE_TESTCASE_ ( class_exceptions_work1  )

Definition at line 115 of file unittest.cc.

◆ DEFINE_TESTCASE_() [3/4]

DEFINE_TESTCASE_ ( resolverelativepath1  )

Definition at line 129 of file unittest.cc.

References r_r_p(), and TEST_EQUAL.

◆ DEFINE_TESTCASE_() [4/4]

DEFINE_TESTCASE_ ( serialisedouble1  )

Definition at line 229 of file unittest.cc.

References check_double_serialisation().

◆ description_append()

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

◆ main()

int main ( int  argc,
char **  argv 
)

Definition at line 935 of file unittest.cc.

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

◆ parsesigned_helper()

template<typename S >
static void parsesigned_helper ( )
inlinestatic

Definition at line 872 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 843 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 123 of file unittest.cc.

References resolve_relative_path().

Referenced by DEFINE_TESTCASE_().

◆ test_addoverflows1()

static void test_addoverflows1 ( )
static

Definition at line 746 of file unittest.cc.

References add_overflows(), TEST, and TEST_EQUAL.

◆ test_closefrom1()

static void test_closefrom1 ( )
static

Definition at line 575 of file unittest.cc.

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

◆ test_log2()

static void test_log2 ( )
static

Definition at line 410 of file unittest.cc.

References log2(), and TEST_EQUAL.

◆ test_movesupport1()

static void test_movesupport1 ( )
static

◆ test_muloverflows1()

static void test_muloverflows1 ( )
static

Definition at line 815 of file unittest.cc.

References mul_overflows(), TEST, and TEST_EQUAL.

◆ test_parsesigned1()

static void test_parsesigned1 ( )
static

Definition at line 901 of file unittest.cc.

◆ test_parseunsigned1()

static void test_parseunsigned1 ( )
static

Definition at line 862 of file unittest.cc.

◆ test_serialiseerror1()

static void test_serialiseerror1 ( )
static

◆ test_serialiselength1()

static void test_serialiselength1 ( )
static

Definition at line 261 of file unittest.cc.

References decode_length(), encode_length(), TEST_EQUAL, and tout.

◆ test_serialiselength2()

static void test_serialiselength2 ( )
static

Definition at line 282 of file unittest.cc.

References decode_length_and_check(), encode_length(), TEST, TEST_EQUAL, and TEST_EXCEPTION.

◆ 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 569 of file unittest.cc.

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

◆ test_suboverflows1()

static void test_suboverflows1 ( )
static

Definition at line 799 of file unittest.cc.

References sub_overflows(), TEST, and TEST_EQUAL.

◆ test_tostring1()

static void test_tostring1 ( )
static

Definition at line 528 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 512 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 418 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(serialiselength1),
TESTCASE(serialiselength2),
TESTCASE(serialiseerror1),
TESTCASE(sortableserialise1),
TESTCASE(tostring1),
TESTCASE(strbool1),
TESTCASE(closefrom1),
TESTCASE(uuid1),
TESTCASE(movesupport1),
TESTCASE(addoverflows1),
TESTCASE(suboverflows1),
TESTCASE(muloverflows1),
TESTCASE(parseunsigned1),
TESTCASE(parsesigned1),
}
#define END_OF_TESTCASES
Definition: testmacros.h:29
double log2(double x)
Definition: log2.h:31
#define TESTCASE(T)
Definition: testmacros.h:28

Definition at line 910 of file unittest.cc.

◆ unittest_assertion_failed

const char* unittest_assertion_failed = NULL
static

Definition at line 38 of file unittest.cc.