2 * @brief Xapian-specific test helper functions and macros.
4 /* Copyright 1999,2000,2001 BrightStation PLC
5 * Copyright 2002,2003,2007,2008,2015 Olly Betts
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.
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.
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
23 #ifndef OM_HGUARD_TESTUTILS_H
24 #define OM_HGUARD_TESTUTILS_H
26 #include "testsuite.h"
29 // ######################################################################
30 // Useful display operators
32 std::ostream
&operator<<(std::ostream
&os
,
33 const std::vector
<Xapian::docid
> &ints
);
35 // ######################################################################
36 // Useful comparison operators
38 // Test that the weights and docids in two mset ranges are the same.
40 mset_range_is_same(const Xapian::MSet
&mset1
, unsigned int first1
,
41 const Xapian::MSet
&mset2
, unsigned int first2
,
44 // Test that the weights in two mset ranges are the same, ignoring docids.
46 mset_range_is_same_weights(const Xapian::MSet
&mset1
, unsigned int first1
,
47 const Xapian::MSet
&mset2
, unsigned int first2
,
50 bool operator==(const Xapian::MSet
&first
, const Xapian::MSet
&second
);
52 inline bool operator!=(const Xapian::MSet
&first
, const Xapian::MSet
&second
)
54 return !(first
== second
);
58 void mset_expect_order(const Xapian::MSet
&A
,
59 Xapian::docid d1
= 0, Xapian::docid d2
= 0,
60 Xapian::docid d3
= 0, Xapian::docid d4
= 0,
61 Xapian::docid d5
= 0, Xapian::docid d6
= 0,
62 Xapian::docid d7
= 0, Xapian::docid d8
= 0,
63 Xapian::docid d9
= 0, Xapian::docid d10
= 0,
64 Xapian::docid d11
= 0, Xapian::docid d12
= 0);
66 void test_mset_order_equal(const Xapian::MSet
&mset1
,
67 const Xapian::MSet
&mset2
);
69 // ######################################################################
72 /// Check MSet M has size S.
73 #define TEST_MSET_SIZE(M, S) TEST_AND_EXPLAIN(((M).size() == (S)), \
74 "MSet '" STRINGIZE(M) "' is not of expected size: was '" << \
75 (M).size() << "' expected '" << (S) << "':\n" << \
76 "Full mset was:\n" << (M))
78 /// Check that a piece of code throws an expected exception.
79 #define TEST_EXCEPTION(a,b) do {\
80 expected_exception = STRINGIZE(a);\
81 if (strncmp(expected_exception, "Xapian::", 8) == 0)\
82 expected_exception += 8;\
84 tout << "Expecting exception " << expected_exception << endl;\
85 try {b;FAIL_TEST(TESTCASE_LOCN(Expected #a));}\
88 tout << "Caught expected " << expected_exception\
89 << " exception: " << e.get_description() << endl;\
91 expected_exception = NULL;\
94 #endif // OM_HGUARD_TESTUTILS_H