Use << instead of + with FAIL_TEST and SKIP_TEST
[xapian.git] / xapian-core / tests / apitest.cc
blob463f9ca44a32fa245b0faacb1c45159f9900f575
1 /* apitest.cc: tests the Xapian API
3 * Copyright 1999,2000,2001 BrightStation PLC
4 * Copyright 2002 Ananova Ltd
5 * Copyright 2003,2004,2006,2007,2008,2009 Olly Betts
6 * Copyright 2008 Lemur Consulting Ltd
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License as
10 * published by the Free Software Foundation; either version 2 of the
11 * License, or (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301
21 * USA
24 #include <config.h>
26 #include "apitest.h"
28 #include "api_all.h"
29 #include "backendmanager.h"
30 #include "stringutils.h"
31 #include "testrunner.h"
32 #include "testsuite.h"
34 #include <xapian.h>
36 #include <string>
37 #include <vector>
39 using namespace std;
41 std::string get_dbtype()
43 return backendmanager->get_dbtype();
46 Xapian::Database
47 get_database(const string &dbname)
49 return backendmanager->get_database(dbname);
52 Xapian::Database
53 get_database(const string &dbname, const string &dbname2)
55 vector<string> dbnames;
56 dbnames.push_back(dbname);
57 dbnames.push_back(dbname2);
58 return backendmanager->get_database(dbnames);
61 Xapian::Database
62 get_database(const std::string &dbname,
63 void (*gen)(Xapian::WritableDatabase&,
64 const std::string &),
65 const std::string &arg)
67 return backendmanager->get_database(dbname, gen, arg);
70 string
71 get_database_path(const string &dbname)
73 return backendmanager->get_database_path(dbname);
76 string
77 get_database_path(const std::string &dbname,
78 void (*gen)(Xapian::WritableDatabase&,
79 const std::string &),
80 const std::string &arg)
82 return backendmanager->get_database_path(dbname, gen, arg);
85 Xapian::WritableDatabase
86 get_writable_database(const string &dbname)
88 return backendmanager->get_writable_database("dbw", dbname);
91 Xapian::WritableDatabase
92 get_named_writable_database(const std::string &name, const std::string &source)
94 return backendmanager->get_writable_database("dbw__" + name, source);
97 std::string
98 get_named_writable_database_path(const std::string &name)
100 return backendmanager->get_writable_database_path("dbw__" + name);
103 Xapian::Database
104 get_remote_database(const string &dbname, unsigned int timeout)
106 vector<string> dbnames;
107 dbnames.push_back(dbname);
108 return backendmanager->get_remote_database(dbnames, timeout);
111 Xapian::Database
112 get_writable_database_as_database()
114 return backendmanager->get_writable_database_as_database();
117 Xapian::WritableDatabase
118 get_writable_database_again()
120 return backendmanager->get_writable_database_again();
123 void
124 skip_test_unless_backend(const std::string & backend_prefix)
126 if (!startswith(get_dbtype(), backend_prefix)) {
127 SKIP_TEST("Test only supported for " << backend_prefix << " backend");
131 void
132 skip_test_for_backend(const std::string & backend_prefix)
134 if (startswith(get_dbtype(), backend_prefix)) {
135 SKIP_TEST("Test not supported for " << backend_prefix << " backend");
139 class ApiTestRunner : public TestRunner
141 public:
142 int run() const {
143 int result = 0;
144 #include "api_collated.h"
145 test_driver::report(test_driver::subtotal,
146 "backend " + backendmanager->get_dbtype());
147 test_driver::total += test_driver::subtotal;
148 test_driver::subtotal.reset();
149 return result;
153 int main(int argc, char **argv)
155 ApiTestRunner runner;
156 return runner.run_tests(argc, argv);