xapian-core  1.4.19
testutils.h
Go to the documentation of this file.
1 
4 /* Copyright 1999,2000,2001 BrightStation PLC
5  * Copyright 2002,2003,2007,2008,2015 Olly Betts
6  *
7  * This program is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License as
9  * published by the Free Software Foundation; either version 2 of the
10  * License, or (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301
20  * USA
21  */
22 
23 #ifndef OM_HGUARD_TESTUTILS_H
24 #define OM_HGUARD_TESTUTILS_H
25 
26 #include "testsuite.h"
27 #include <xapian.h>
28 
29 // ######################################################################
30 // Useful display operators
31 
32 std::ostream &operator<<(std::ostream &os,
33  const std::vector<Xapian::docid> &ints);
34 
35 // ######################################################################
36 // Useful comparison operators
37 
38 // Test that the weights and docids in two mset ranges are the same.
39 bool
40 mset_range_is_same(const Xapian::MSet &mset1, unsigned int first1,
41  const Xapian::MSet &mset2, unsigned int first2,
42  unsigned int count);
43 
44 // Test that the weights and docids in the mset and an array are the same.
45 bool
46 mset_range_is_same(const Xapian::MSet& mset, unsigned int first,
47  const std::pair<Xapian::docid, double> to_compare[],
48  unsigned int count);
49 
50 // Test that the weights in two mset ranges are the same, ignoring docids.
51 bool
52 mset_range_is_same_weights(const Xapian::MSet &mset1, unsigned int first1,
53  const Xapian::MSet &mset2, unsigned int first2,
54  unsigned int count);
55 
56 bool operator==(const Xapian::MSet &first, const Xapian::MSet &second);
57 
58 inline bool operator!=(const Xapian::MSet &first, const Xapian::MSet &second)
59 {
60  return !(first == second);
61 }
62 
63 void mset_expect_order(const Xapian::MSet &A,
64  Xapian::docid d1 = 0, Xapian::docid d2 = 0,
65  Xapian::docid d3 = 0, Xapian::docid d4 = 0,
66  Xapian::docid d5 = 0, Xapian::docid d6 = 0,
67  Xapian::docid d7 = 0, Xapian::docid d8 = 0,
68  Xapian::docid d9 = 0, Xapian::docid d10 = 0,
69  Xapian::docid d11 = 0, Xapian::docid d12 = 0);
70 
71 void test_mset_order_equal(const Xapian::MSet &mset1,
72  const Xapian::MSet &mset2);
73 
74 // ######################################################################
75 // Useful test macros
76 
78 #define TEST_MSET_SIZE(M, S) TEST_AND_EXPLAIN(((M).size() == (S)), \
79  "MSet '" STRINGIZE(M) "' is not of expected size: was '" << \
80  (M).size() << "' expected '" << (S) << "':\n" << \
81  "Full mset was:\n" << (M))
82 
84 #define TEST_EXCEPTION_(TYPE, CODE, EXACT) \
85  do { \
86  expected_exception = STRINGIZE(TYPE); \
87  if (strncmp(expected_exception, "Xapian::", \
88  CONST_STRLEN("Xapian::")) == 0) { \
89  expected_exception += CONST_STRLEN("Xapian::"); \
90  } \
91  try { \
92  CODE; \
93  FAIL_TEST("Expected " << expected_exception << " not thrown"); \
94  } catch (const TYPE& xap_ex_obj_) { \
95  if (EXACT) { \
96  if (strcmp(expected_exception, xap_ex_obj_.get_type()) != 0) { \
97  FAIL_TEST("Caught subclass " << xap_ex_obj_.get_type() << \
98  " of expected " << expected_exception); \
99  } \
100  } \
101  } \
102  expected_exception = NULL;\
103  } while (0)
104 
106 #define TEST_EXCEPTION_BASE_CLASS(TYPE, CODE) TEST_EXCEPTION_(TYPE, CODE, false)
107 
109 #define TEST_EXCEPTION(TYPE, CODE) TEST_EXCEPTION_(TYPE, CODE, true)
110 
111 #endif // OM_HGUARD_TESTUTILS_H
a generic test suite engine
Class representing a list of search results.
Definition: mset.h:44
std::ostream & operator<<(std::ostream &os, const std::vector< Xapian::docid > &ints)
Definition: testutils.cc:35
Definition: unittest.cc:672
void mset_expect_order(const Xapian::MSet &A, Xapian::docid d1=0, Xapian::docid d2=0, Xapian::docid d3=0, Xapian::docid d4=0, Xapian::docid d5=0, Xapian::docid d6=0, Xapian::docid d7=0, Xapian::docid d8=0, Xapian::docid d9=0, Xapian::docid d10=0, Xapian::docid d11=0, Xapian::docid d12=0)
Definition: testutils.cc:225
bool operator!=(const Xapian::MSet &first, const Xapian::MSet &second)
Definition: testutils.h:58
bool operator==(const Xapian::MSet &first, const Xapian::MSet &second)
Definition: testutils.cc:141
Public interfaces for the Xapian library.
bool mset_range_is_same(const Xapian::MSet &mset1, unsigned int first1, const Xapian::MSet &mset2, unsigned int first2, unsigned int count)
Definition: testutils.cc:46
void test_mset_order_equal(const Xapian::MSet &mset1, const Xapian::MSet &mset2)
Definition: testutils.cc:234
unsigned XAPIAN_DOCID_BASE_TYPE docid
A unique identifier for a document.
Definition: types.h:52
bool mset_range_is_same_weights(const Xapian::MSet &mset1, unsigned int first1, const Xapian::MSet &mset2, unsigned int first2, unsigned int count)
Definition: testutils.cc:111