xapian-core  2.0.0
apitest.cc
Go to the documentation of this file.
1 
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
8  *
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.
13  *
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.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program; if not, see
21  * <https://www.gnu.org/licenses/>.
22  */
23 
24 #include <config.h>
25 
26 #include "apitest.h"
27 
28 #include "api_all.h"
29 #include "backendmanager.h"
30 #include "stringutils.h"
31 #include "testrunner.h"
32 #include "testsuite.h"
33 
34 #include <xapian.h>
35 
36 #include <string>
37 #include <vector>
38 
39 using namespace std;
40 
41 std::string get_dbtype()
42 {
43  return backendmanager->get_dbtype();
44 }
45 
47 get_database(const string &dbname)
48 {
49  return backendmanager->get_database(dbname);
50 }
51 
53 get_database(const string &dbname, const string &dbname2)
54 {
55  vector<string> dbnames;
56  dbnames.push_back(dbname);
57  dbnames.push_back(dbname2);
59 }
60 
62 get_database(const std::string &dbname,
64  const std::string &),
65  const std::string &arg)
66 {
67  return backendmanager->get_database(dbname, gen, arg);
68 }
69 
70 string
71 get_database_path(const string &dbname)
72 {
73  return backendmanager->get_database_path(dbname);
74 }
75 
76 string
77 get_database_path(const std::string &dbname,
79  const std::string &),
80  const std::string &arg)
81 {
82  return backendmanager->get_database_path(dbname, gen, arg);
83 }
84 
86 get_writable_database(const string &dbname)
87 {
88  return backendmanager->get_writable_database("dbw", dbname);
89 }
90 
92 get_named_writable_database(const std::string &name, const std::string &source)
93 {
94  return backendmanager->get_writable_database("dbw__" + name, source);
95 }
96 
97 std::string
99 {
101 }
102 
103 std::string
104 get_compaction_output_path(const std::string& name)
105 {
107 }
108 
110 get_remote_database(const string& dbname,
111  unsigned int timeout,
112  int* port_ptr)
113 {
114  vector<string> dbnames;
115  dbnames.push_back(dbname);
116  return backendmanager->get_remote_database(dbnames, timeout, port_ptr);
117 }
118 
119 void
121 {
123 }
124 
127 {
129 }
130 
133 {
135 }
136 
137 void
138 skip_test_unless_backend(const std::string & backend_prefix)
139 {
140  if (!startswith(get_dbtype(), backend_prefix)) {
141  SKIP_TEST("Test only supported for " << backend_prefix << " backend");
142  }
143 }
144 
145 void
146 skip_test_for_backend(const std::string & backend_prefix)
147 {
148  if (startswith(get_dbtype(), backend_prefix)) {
149  SKIP_TEST("Test not supported for " << backend_prefix << " backend");
150  }
151 }
152 
153 void
154 XFAIL_FOR_BACKEND(const std::string& backend_prefix,
155  const char* msg)
156 {
157  if (startswith(get_dbtype(), backend_prefix)) {
158  XFAIL(msg);
159  }
160 }
161 
162 class ApiTestRunner : public TestRunner
163 {
164  public:
165  int run() const {
166  int result = 0;
167 #include "api_collated.h"
169  "backend " + backendmanager->get_dbtype());
172  return result;
173  }
174 };
175 
176 int main(int argc, char **argv)
177 {
178  ApiTestRunner runner;
179  return runner.run_tests(argc, argv);
180 }
std::string get_dbtype()
Definition: apitest.cc:41
int main(int argc, char **argv)
Definition: apitest.cc:176
Xapian::Database get_writable_database_as_database()
Definition: apitest.cc:126
void skip_test_for_backend(const std::string &backend_prefix)
Definition: apitest.cc:146
string get_database_path(const string &dbname)
Definition: apitest.cc:71
void skip_test_unless_backend(const std::string &backend_prefix)
Definition: apitest.cc:138
Xapian::WritableDatabase get_writable_database(const string &dbname)
Definition: apitest.cc:86
std::string get_named_writable_database_path(const std::string &name)
Definition: apitest.cc:98
Xapian::WritableDatabase get_writable_database_again()
Definition: apitest.cc:132
std::string get_compaction_output_path(const std::string &name)
Definition: apitest.cc:104
Xapian::Database get_database(const string &dbname)
Definition: apitest.cc:47
Xapian::WritableDatabase get_named_writable_database(const std::string &name, const std::string &source)
Definition: apitest.cc:92
void kill_remote(const Xapian::Database &db)
Kill the server associated with remote database db.
Definition: apitest.cc:120
void XFAIL_FOR_BACKEND(const std::string &backend_prefix, const char *msg)
Definition: apitest.cc:154
Xapian::Database get_remote_database(const string &dbname, unsigned int timeout, int *port_ptr)
Definition: apitest.cc:110
test functionality of the Xapian API
Base class for backend handling in test harness.
int run() const
Run the tests with a particular backend.
Definition: apitest.cc:165
Xapian::Database get_database(const std::vector< std::string > &files)
Get a database instance of the current type.
virtual std::string get_compaction_output_path(const std::string &name)
Get a path to compact a database to.
virtual Xapian::WritableDatabase get_writable_database_again()
Create a WritableDatabase object for the last opened WritableDatabase.
std::string get_database_path(const std::vector< std::string > &files)
Get the path of a database instance, if such a thing exists.
virtual std::string get_writable_database_path(const std::string &name)
Get the path of a writable database instance, if such a thing exists.
const std::string & get_dbtype() const
Get the database type currently in use.
virtual Xapian::Database get_writable_database_as_database()
Create a Database object for the last opened WritableDatabase.
virtual Xapian::Database get_remote_database(const std::vector< std::string > &files, unsigned int timeout, int *port_ptr)
Get a remote database instance with the specified timeout.
virtual void kill_remote(const Xapian::Database &db)
Kill the remote server associated with db.
virtual Xapian::WritableDatabase get_writable_database(const std::string &name, const std::string &file)
Get a writable database instance.
A test runner, which runs the tests (implemented by subclassing it) with a variety of backends.
Definition: testrunner.h:35
int run_tests(int argc, char **argv)
Run all the tests.
Definition: testrunner.cc:131
An indexed database of documents.
Definition: database.h:75
This class provides read/write access to a database.
Definition: database.h:964
static void report(const test_driver::result &r, const std::string &desc)
Print summary of tests passed, failed, and skipped.
Definition: testsuite.cc:811
static result subtotal
Definition: testsuite.h:197
static result total
Definition: testsuite.h:200
static const char * dbnames
static mt19937 gen
Definition: soaktest.cc:36
Various handy string-related helpers.
bool startswith(std::string_view s, char pfx)
Definition: stringutils.h:56
Definition: header.h:215
BackendManager * backendmanager
backendmanager is global so that it can be accessed by individual tests.
Definition: testrunner.cc:41
Run multiple tests for different backends.
a generic test suite engine
#define SKIP_TEST(MSG)
Skip the current testcase with message MSG.
Definition: testsuite.h:71
void XFAIL(const char *msg)
Mark a testcase as expected to fail.
Definition: testsuite.h:328
Public interfaces for the Xapian library.