Update for 1.4.20
[xapian.git] / xapian-core / tests / apitest.cc
blob27e94bc7f8fd9a607c7fe5d3907b290b88522e7a
1 /** @file
2 * @brief tests the Xapian API
3 */
4 /* Copyright 1999,2000,2001 BrightStation PLC
5 * Copyright 2002 Ananova Ltd
6 * Copyright 2003,2004,2006,2007,2008,2009,2018 Olly Betts
7 * Copyright 2008 Lemur Consulting Ltd
9 * This program is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU General Public License as
11 * published by the Free Software Foundation; either version 2 of the
12 * License, or (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301
22 * USA
25 #include <config.h>
27 #include "apitest.h"
29 #include "api_all.h"
30 #include "backendmanager.h"
31 #include "stringutils.h"
32 #include "testrunner.h"
33 #include "testsuite.h"
35 #include <xapian.h>
37 #include <string>
38 #include <vector>
40 using namespace std;
42 std::string get_dbtype()
44 return backendmanager->get_dbtype();
47 Xapian::Database
48 get_database(const string &dbname)
50 return backendmanager->get_database(dbname);
53 Xapian::Database
54 get_database(const string &dbname, const string &dbname2)
56 vector<string> dbnames;
57 dbnames.push_back(dbname);
58 dbnames.push_back(dbname2);
59 return backendmanager->get_database(dbnames);
62 Xapian::Database
63 get_database(const std::string &dbname,
64 void (*gen)(Xapian::WritableDatabase&,
65 const std::string &),
66 const std::string &arg)
68 return backendmanager->get_database(dbname, gen, arg);
71 string
72 get_database_path(const string &dbname)
74 return backendmanager->get_database_path(dbname);
77 string
78 get_database_path(const std::string &dbname,
79 void (*gen)(Xapian::WritableDatabase&,
80 const std::string &),
81 const std::string &arg)
83 return backendmanager->get_database_path(dbname, gen, arg);
86 Xapian::WritableDatabase
87 get_writable_database(const string &dbname)
89 return backendmanager->get_writable_database("dbw", dbname);
92 Xapian::WritableDatabase
93 get_named_writable_database(const std::string &name, const std::string &source)
95 return backendmanager->get_writable_database("dbw__" + name, source);
98 std::string
99 get_named_writable_database_path(const std::string &name)
101 return backendmanager->get_writable_database_path("dbw__" + name);
104 std::string
105 get_compaction_output_path(const std::string& name)
107 return backendmanager->get_compaction_output_path(name);
110 Xapian::Database
111 get_remote_database(const string &dbname, unsigned int timeout)
113 vector<string> dbnames;
114 dbnames.push_back(dbname);
115 return backendmanager->get_remote_database(dbnames, timeout);
118 Xapian::Database
119 get_writable_database_as_database()
121 return backendmanager->get_writable_database_as_database();
124 Xapian::WritableDatabase
125 get_writable_database_again()
127 return backendmanager->get_writable_database_again();
130 void
131 skip_test_unless_backend(const std::string & backend_prefix)
133 if (!startswith(get_dbtype(), backend_prefix)) {
134 SKIP_TEST("Test only supported for " << backend_prefix << " backend");
138 void
139 skip_test_for_backend(const std::string & backend_prefix)
141 if (startswith(get_dbtype(), backend_prefix)) {
142 SKIP_TEST("Test not supported for " << backend_prefix << " backend");
146 void
147 XFAIL_FOR_BACKEND(const std::string& backend_prefix,
148 const char* msg)
150 if (startswith(get_dbtype(), backend_prefix)) {
151 XFAIL(msg);
155 class ApiTestRunner : public TestRunner
157 public:
158 int run() const {
159 int result = 0;
160 #include "api_collated.h"
161 test_driver::report(test_driver::subtotal,
162 "backend " + backendmanager->get_dbtype());
163 test_driver::total += test_driver::subtotal;
164 test_driver::subtotal.reset();
165 return result;
169 int main(int argc, char **argv)
171 ApiTestRunner runner;
172 return runner.run_tests(argc, argv);