Adjust new comments to match existing
[xapian.git] / xapian-letor / tests / apitest.cc
blob312b2cc3d37a72228dbff3257022309c0ca7bf96
1 /** @file
2 * @brief tests the Xapian Letor 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,
112 unsigned int timeout,
113 int* port_ptr)
115 vector<string> dbnames;
116 dbnames.push_back(dbname);
117 return backendmanager->get_remote_database(dbnames, timeout, port_ptr);
120 void
121 kill_remote(const Xapian::Database& db)
123 backendmanager->kill_remote(db);
126 Xapian::Database
127 get_writable_database_as_database()
129 return backendmanager->get_writable_database_as_database();
132 Xapian::WritableDatabase
133 get_writable_database_again()
135 return backendmanager->get_writable_database_again();
138 void
139 skip_test_unless_backend(const std::string & backend_prefix)
141 if (!startswith(get_dbtype(), backend_prefix)) {
142 SKIP_TEST("Test only supported for " << backend_prefix << " backend");
146 void
147 skip_test_for_backend(const std::string & backend_prefix)
149 if (startswith(get_dbtype(), backend_prefix)) {
150 SKIP_TEST("Test not supported for " << backend_prefix << " backend");
154 void
155 XFAIL_FOR_BACKEND(const std::string& backend_prefix,
156 const char* msg)
158 if (startswith(get_dbtype(), backend_prefix)) {
159 XFAIL(msg);
163 class ApiTestRunner : public TestRunner
165 public:
166 int run() const {
167 int result = 0;
168 #include "api_collated.h"
169 test_driver::report(test_driver::subtotal,
170 "backend " + backendmanager->get_dbtype());
171 test_driver::total += test_driver::subtotal;
172 test_driver::subtotal.reset();
173 return result;
177 int main(int argc, char **argv)
179 ApiTestRunner runner;
180 return runner.run_tests(argc, argv);