00001
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #include <config.h>
00023
00024 #include "api_query.h"
00025
00026 #include <xapian.h>
00027
00028 #include "testsuite.h"
00029 #include "testutils.h"
00030 #include "utils.h"
00031
00032 #include "apitest.h"
00033
00034 using namespace std;
00035
00037 DEFINE_TESTCASE(queryterms1, !backend) {
00038 Xapian::Query query = Xapian::Query::MatchAll;
00039 TEST(query.get_terms_begin() == query.get_terms_end());
00040 query = Xapian::Query(query.OP_AND_NOT, query, Xapian::Query("fair"));
00041 TEST_EQUAL(*query.get_terms_begin(), "fair");
00042 return true;
00043 }
00044
00045 DEFINE_TESTCASE(matchnothing1, !backend) {
00046 vector<Xapian::Query> subqs;
00047 subqs.push_back(Xapian::Query("foo"));
00048 subqs.push_back(Xapian::Query::MatchNothing);
00049 Xapian::Query q(Xapian::Query::OP_AND, subqs.begin(), subqs.end());
00050 TEST_STRINGS_EQUAL(q.get_description(), "Xapian::Query()");
00051
00052 Xapian::Query q2(Xapian::Query::OP_AND,
00053 Xapian::Query("foo"), Xapian::Query::MatchNothing);
00054 TEST_STRINGS_EQUAL(q2.get_description(), "Xapian::Query()");
00055 return true;
00056 }
00057
00066 DEFINE_TESTCASE(nearsubqueries1, !backend) {
00067 Xapian::Query a_or_b(Xapian::Query::OP_OR,
00068 Xapian::Query("a"),
00069 Xapian::Query("b"));
00070 Xapian::Query near(Xapian::Query::OP_NEAR, a_or_b, a_or_b);
00071 TEST_STRINGS_EQUAL(near.get_description(),
00072 "Xapian::Query(((a NEAR 2 a) OR (b NEAR 2 a) OR (b NEAR 2 b) OR (a NEAR 2 b)))");
00073
00074 Xapian::Query a_near_b(Xapian::Query::OP_NEAR,
00075 Xapian::Query("a"),
00076 Xapian::Query("b"));
00077 Xapian::Query x_phrs_y(Xapian::Query::OP_PHRASE,
00078 Xapian::Query("a"),
00079 Xapian::Query("b"));
00080
00081 TEST_EXCEPTION(Xapian::UnimplementedError,
00082 Xapian::Query q(Xapian::Query::OP_NEAR,
00083 a_near_b,
00084 Xapian::Query("c"))
00085 );
00086
00087 TEST_EXCEPTION(Xapian::UnimplementedError,
00088 Xapian::Query q(Xapian::Query::OP_NEAR,
00089 x_phrs_y,
00090 Xapian::Query("c"))
00091 );
00092
00093 TEST_EXCEPTION(Xapian::UnimplementedError,
00094 Xapian::Query q(Xapian::Query::OP_PHRASE,
00095 a_near_b,
00096 Xapian::Query("c"))
00097 );
00098
00099 TEST_EXCEPTION(Xapian::UnimplementedError,
00100 Xapian::Query q(Xapian::Query::OP_PHRASE,
00101 x_phrs_y,
00102 Xapian::Query("c"))
00103 );
00104
00105 return true;
00106 }