xapian-core  1.4.27
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, write to the Free Software
21  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301
22  * USA
23  */
24 
25 #include <config.h>
26 
27 #include "apitest.h"
28 
29 #include "api_all.h"
30 #include "backendmanager.h"
31 #include "stringutils.h"
32 #include "testrunner.h"
33 #include "testsuite.h"
34 
35 #include <xapian.h>
36 
37 #include <string>
38 #include <vector>
39 
40 using namespace std;
41 
42 std::string get_dbtype()
43 {
44  return backendmanager->get_dbtype();
45 }
46 
48 get_database(const string &dbname)
49 {
50  return backendmanager->get_database(dbname);
51 }
52 
54 get_database(const string &dbname, const string &dbname2)
55 {
56  vector<string> dbnames;
57  dbnames.push_back(dbname);
58  dbnames.push_back(dbname2);
59  return backendmanager->get_database(dbnames);
60 }
61 
63 get_database(const std::string &dbname,
65  const std::string &),
66  const std::string &arg)
67 {
68  return backendmanager->get_database(dbname, gen, arg);
69 }
70 
71 string
72 get_database_path(const string &dbname)
73 {
74  return backendmanager->get_database_path(dbname);
75 }
76 
77 string
78 get_database_path(const std::string &dbname,
80  const std::string &),
81  const std::string &arg)
82 {
83  return backendmanager->get_database_path(dbname, gen, arg);
84 }
85 
87 get_writable_database(const string &dbname)
88 {
89  return backendmanager->get_writable_database("dbw", dbname);
90 }
91 
93 get_named_writable_database(const std::string &name, const std::string &source)
94 {
95  return backendmanager->get_writable_database("dbw__" + name, source);
96 }
97 
98 std::string
100 {
101  return backendmanager->get_writable_database_path("dbw__" + name);
102 }
103 
104 std::string
105 get_compaction_output_path(const std::string& name)
106 {
108 }
109 
111 get_remote_database(const string &dbname, unsigned int timeout)
112 {
113  vector<string> dbnames;
114  dbnames.push_back(dbname);
115  return backendmanager->get_remote_database(dbnames, timeout);
116 }
117 
120 {
122 }
123 
126 {
128 }
129 
130 void
131 skip_test_unless_backend(const std::string & backend_prefix)
132 {
133  if (!startswith(get_dbtype(), backend_prefix)) {
134  SKIP_TEST("Test only supported for " << backend_prefix << " backend");
135  }
136 }
137 
138 void
139 skip_test_for_backend(const std::string & backend_prefix)
140 {
141  if (startswith(get_dbtype(), backend_prefix)) {
142  SKIP_TEST("Test not supported for " << backend_prefix << " backend");
143  }
144 }
145 
146 void
147 XFAIL_FOR_BACKEND(const std::string& backend_prefix,
148  const char* msg)
149 {
150  if (startswith(get_dbtype(), backend_prefix)) {
151  XFAIL(msg);
152  }
153 }
154 
155 class ApiTestRunner : public TestRunner
156 {
157  public:
158  int run() const {
159  int result = 0;
160 #include "api_collated.h"
162  "backend " + backendmanager->get_dbtype());
165  return result;
166  }
167 };
168 
169 int main(int argc, char **argv)
170 {
171  ApiTestRunner runner;
172  return runner.run_tests(argc, argv);
173 }
virtual Xapian::Database get_remote_database(const std::vector< std::string > &files, unsigned int timeout)
Get a remote database instance with the specified timeout.
Run multiple tests for different backends.
const std::string & get_dbtype() const
Get the database type currently in use.
This class is used to access a database, or a group of databases.
Definition: database.h:68
unsigned timeout
A timeout value in milliseconds.
Definition: types.h:100
Xapian::Database get_database(const std::vector< std::string > &files)
Get a database instance of the current type.
void skip_test_unless_backend(const std::string &backend_prefix)
Definition: apitest.cc:131
static void report(const test_driver::result &r, const std::string &desc)
Print summary of tests passed, failed, and skipped.
Definition: testsuite.cc:783
Xapian::WritableDatabase get_writable_database(const string &dbname)
Definition: apitest.cc:87
static result subtotal
Definition: testsuite.h:199
std::string get_database_path(const std::vector< std::string > &files)
Get the path of a database instance, if such a thing exists.
a generic test suite engine
static const char * dbnames
Xapian::WritableDatabase get_writable_database_again()
Definition: apitest.cc:125
STL namespace.
virtual std::string get_writable_database_path(const std::string &name)
Get the path of a writable database instance, if such a thing exists.
virtual Xapian::WritableDatabase get_writable_database(const std::string &name, const std::string &file)
Get a writable database instance.
Xapian::WritableDatabase get_named_writable_database(const std::string &name, const std::string &source)
Definition: apitest.cc:93
test functionality of the Xapian API
int run_tests(int argc, char **argv)
Run all the tests.
Definition: testrunner.cc:136
virtual Xapian::WritableDatabase get_writable_database_again()
Create a WritableDatabase object for the last opened WritableDatabase.
Base class for backend handling in test harness.
string get_database_path(const string &dbname)
Definition: apitest.cc:72
std::string get_named_writable_database_path(const std::string &name)
Definition: apitest.cc:99
This class provides read/write access to a database.
Definition: database.h:789
Public interfaces for the Xapian library.
void XFAIL(const char *msg)
Mark a testcase as expected to fail.
Definition: testsuite.h:332
static result total
Definition: testsuite.h:202
BackendManager * backendmanager
backendmanager is global so that it can be accessed by individual tests.
Definition: testrunner.cc:42
std::string get_dbtype()
Definition: apitest.cc:42
A test runner, which runs the tests (implemented by subclassing it) with a variety of backends...
Definition: testrunner.h:36
Xapian::Database get_writable_database_as_database()
Definition: apitest.cc:119
bool startswith(const std::string &s, char pfx)
Definition: stringutils.h:51
static mt19937 gen
Definition: soaktest.cc:37
std::string get_compaction_output_path(const std::string &name)
Definition: apitest.cc:105
int main(int argc, char **argv)
Definition: apitest.cc:169
Xapian::Database get_database(const string &dbname)
Definition: apitest.cc:48
#define SKIP_TEST(MSG)
Skip the current testcase with message MSG.
Definition: testsuite.h:74
void XFAIL_FOR_BACKEND(const std::string &backend_prefix, const char *msg)
Definition: apitest.cc:147
void skip_test_for_backend(const std::string &backend_prefix)
Definition: apitest.cc:139
Various handy helpers which std::string really should provide.
int run() const
Run the tests with a particular backend.
Definition: apitest.cc:158
virtual Xapian::Database get_writable_database_as_database()
Create a Database object for the last opened WritableDatabase.
Definition: header.h:151
virtual std::string get_compaction_output_path(const std::string &name)
Get a path to compact a database to.
Xapian::Database get_remote_database(const string &dbname, unsigned int timeout)
Definition: apitest.cc:111