tests/harness/testutils.h

Go to the documentation of this file.
00001 /* testutils.h: Xapian-specific test helper functions and macros.
00002  *
00003  * Copyright 1999,2000,2001 BrightStation PLC
00004  * Copyright 2002,2003,2007,2008 Olly Betts
00005  *
00006  * This program is free software; you can redistribute it and/or
00007  * modify it under the terms of the GNU General Public License as
00008  * published by the Free Software Foundation; either version 2 of the
00009  * License, or (at your option) any later version.
00010  *
00011  * This program is distributed in the hope that it will be useful,
00012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014  * GNU General Public License for more details.
00015  *
00016  * You should have received a copy of the GNU General Public License
00017  * along with this program; if not, write to the Free Software
00018  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301
00019  * USA
00020  */
00021 
00022 #ifndef OM_HGUARD_TESTUTILS_H
00023 #define OM_HGUARD_TESTUTILS_H
00024 
00025 #include "testsuite.h"
00026 #include <xapian.h>
00027 
00028 // ######################################################################
00029 // Useful display operators
00030 
00031 std::ostream &operator<<(std::ostream &os,
00032                          const std::vector<unsigned int> &ints);
00033 
00034 // ######################################################################
00035 // Useful comparison operators
00036 
00037 // Test that the weights and docids in two mset ranges are the same.
00038 bool
00039 mset_range_is_same(const Xapian::MSet &mset1, unsigned int first1,
00040                    const Xapian::MSet &mset2, unsigned int first2,
00041                    unsigned int count);
00042 
00043 // Test that the weights in two mset ranges are the same, ignoring docids.
00044 bool
00045 mset_range_is_same_weights(const Xapian::MSet &mset1, unsigned int first1,
00046                            const Xapian::MSet &mset2, unsigned int first2,
00047                            unsigned int count);
00048 
00049 // Test that the percentages in two mset ranges are the same, ignoring docids.
00050 bool
00051 mset_range_is_same_percents(const Xapian::MSet &mset1, unsigned int first1,
00052                             const Xapian::MSet &mset2, unsigned int first2,
00053                             unsigned int count);
00054 
00055 bool operator==(const Xapian::MSet &first, const Xapian::MSet &second);
00056 
00057 inline bool operator!=(const Xapian::MSet &first, const Xapian::MSet &second)
00058 {
00059     return !(first == second);
00060 }
00061 
00062 
00063 void mset_expect_order(const Xapian::MSet &A,
00064                        Xapian::docid d1 = 0, Xapian::docid d2 = 0,
00065                        Xapian::docid d3 = 0, Xapian::docid d4 = 0,
00066                        Xapian::docid d5 = 0, Xapian::docid d6 = 0,
00067                        Xapian::docid d7 = 0, Xapian::docid d8 = 0,
00068                        Xapian::docid d9 = 0, Xapian::docid d10 = 0,
00069                        Xapian::docid d11 = 0, Xapian::docid d12 = 0);
00070 
00071 void test_mset_order_equal(const Xapian::MSet &mset1,
00072                            const Xapian::MSet &mset2);
00073 
00074 // ######################################################################
00075 // Useful test macros
00076 
00078 #define TEST_MSET_SIZE(M, S) TEST_AND_EXPLAIN(((M).size() == (S)), \
00079         "MSet `"STRINGIZE(M)"' is not of expected size: was `" << \
00080         (M).size() << "' expected `" << (S) << "':\n" << \
00081         "Full mset was:\n" << (M))
00082 
00084 #define TEST_EXCEPTION(a,b) do {\
00085         expected_exception = STRINGIZE(a);\
00086         if (strncmp(expected_exception, "Xapian::", 8) == 0)\
00087             expected_exception += 8;\
00088         if (verbose)\
00089             tout << "Expecting exception " << expected_exception << endl;\
00090         try {b;FAIL_TEST(TESTCASE_LOCN(Expected #a));}\
00091         catch (const a &e) {\
00092             if (verbose)\
00093                 tout << "Caught expected " << expected_exception\
00094                      << " exception: " << e.get_description() << endl;\
00095         }\
00096         expected_exception = NULL;\
00097     } while (0)
00098 
00099 #endif // OM_HGUARD_TESTUTILS_H

Documentation for Xapian (version 1.0.10).
Generated on 24 Dec 2008 by Doxygen 1.5.2.