00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #include <config.h>
00024
00025 #include "apitest.h"
00026
00027 #include <stdlib.h>
00028 #include <iostream>
00029 #include <string>
00030 #include <vector>
00031
00032 using namespace std;
00033
00034 #include <xapian.h>
00035 #include "testsuite.h"
00036 #include "testutils.h"
00037 #include "backendmanager.h"
00038 #include "backendmanager_flint.h"
00039 #include "backendmanager_inmemory.h"
00040 #include "backendmanager_multi.h"
00041 #include "backendmanager_quartz.h"
00042 #include "backendmanager_remoteprog.h"
00043 #include "backendmanager_remotetcp.h"
00044 #include "utils.h"
00045
00046 #include "api_all.h"
00047
00048 static BackendManager * backendmanager;
00049
00050 const char * get_dbtype()
00051 {
00052 return backendmanager->get_dbtype();
00053 }
00054
00055 Xapian::Database
00056 get_database(const string &dbname)
00057 {
00058 return backendmanager->get_database(dbname);
00059 }
00060
00061 Xapian::Database
00062 get_database(const string &dbname, const string &dbname2)
00063 {
00064 vector<string> dbnames;
00065 dbnames.push_back(dbname);
00066 dbnames.push_back(dbname2);
00067 return backendmanager->get_database(dbnames);
00068 }
00069
00070 Xapian::WritableDatabase
00071 get_writable_database(const string &dbname)
00072 {
00073 return backendmanager->get_writable_database("dbw", dbname);
00074 }
00075
00076 Xapian::WritableDatabase
00077 get_named_writable_database(const std::string &name, const std::string &source)
00078 {
00079 return backendmanager->get_writable_database("dbw__" + name, source);
00080 }
00081
00082 Xapian::Database
00083 get_remote_database(const string &dbname, unsigned int timeout)
00084 {
00085 vector<string> dbnames;
00086 dbnames.push_back(dbname);
00087 return backendmanager->get_remote_database(dbnames, timeout);
00088 }
00089
00090 Xapian::Database
00091 get_writable_database_as_database()
00092 {
00093 return backendmanager->get_writable_database_as_database();
00094 }
00095
00096 Xapian::WritableDatabase
00097 get_writable_database_again()
00098 {
00099 return backendmanager->get_writable_database_again();
00100 }
00101
00102 #define USE_BACKEND(B, S) ((B).empty() || (B) == (S))
00103
00104 int main(int argc, char **argv)
00105 {
00106 string backend_name;
00107 test_driver::add_command_line_option("backend", 'b', &backend_name);
00108
00109 test_driver::parse_command_line(argc, argv);
00110
00111 string srcdir = test_driver::get_srcdir();
00112
00113 int result = 0;
00114
00115 if (USE_BACKEND(backend_name, "none")) {
00116 backendmanager = new BackendManager;
00117 backendmanager->set_datadir(srcdir + "/testdata/");
00118
00119 bool backend = false, remote = false, transactions = false;
00120 bool positional = false, writable = false, multi = false;
00121 bool spelling = false, metadata = false;
00122 bool quartz = false, flint = false;
00123 #include "api_collated.h"
00124
00125 delete backendmanager;
00126 }
00127
00128 #ifdef XAPIAN_HAS_INMEMORY_BACKEND
00129 if (USE_BACKEND(backend_name, "inmemory")) {
00130 backendmanager = new BackendManagerInMemory;
00131 backendmanager->set_datadir(srcdir + "/testdata/");
00132
00133 bool backend = true, remote = false, transactions = false;
00134 bool positional = true, writable = true, multi = false;
00135 bool spelling = false, metadata = false;
00136 bool quartz = false, flint = false;
00137 #include "api_collated.h"
00138
00139 delete backendmanager;
00140 }
00141 #endif
00142
00143 #ifdef XAPIAN_HAS_FLINT_BACKEND
00144 if (USE_BACKEND(backend_name, "flint")) {
00145 backendmanager = new BackendManagerFlint;
00146 backendmanager->set_datadir(srcdir + "/testdata/");
00147
00148 bool backend = true, remote = false, transactions = true;
00149 bool positional = true, writable = true, multi = false;
00150 bool spelling = true, metadata = true;
00151 bool quartz = false, flint = true;
00152 #include "api_collated.h"
00153
00154 delete backendmanager;
00155 }
00156 #endif
00157
00158 #if defined(XAPIAN_HAS_FLINT_BACKEND) || defined(XAPIAN_HAS_QUARTZ_BACKEND)
00159 if (USE_BACKEND(backend_name, "multi")) {
00160 backendmanager = new BackendManagerMulti;
00161 backendmanager->set_datadir(srcdir + "/testdata/");
00162
00163 bool backend = true, remote = false, transactions = false;
00164 bool positional = true, writable = false, multi = true;
00165 bool spelling = false, metadata = false;
00166 bool quartz = false, flint = false;
00167 #include "api_collated.h"
00168
00169 delete backendmanager;
00170 }
00171 #endif
00172
00173 #ifdef XAPIAN_HAS_QUARTZ_BACKEND
00174 if (USE_BACKEND(backend_name, "quartz")) {
00175 backendmanager = new BackendManagerQuartz;
00176 backendmanager->set_datadir(srcdir + "/testdata/");
00177
00178 bool backend = true, remote = false, transactions = true;
00179 bool positional = true, writable = true, multi = false;
00180 bool spelling = false, metadata = false;
00181 bool quartz = true, flint = false;
00182 #include "api_collated.h"
00183
00184 delete backendmanager;
00185 }
00186 #endif
00187
00188 #ifdef XAPIAN_HAS_REMOTE_BACKEND
00189 if (USE_BACKEND(backend_name, "remoteprog")) {
00190 backendmanager = new BackendManagerRemoteProg;
00191 backendmanager->set_datadir(srcdir + "/testdata/");
00192
00193 bool backend = true, remote = true, transactions = true;
00194 bool positional = true, writable = true, multi = false;
00195 bool spelling = false, metadata = false;
00196 bool quartz = false, flint = false;
00197 #include "api_collated.h"
00198
00199 delete backendmanager;
00200 }
00201
00202 if (USE_BACKEND(backend_name, "remotetcp")) {
00203 backendmanager = new BackendManagerRemoteTcp;
00204 backendmanager->set_datadir(srcdir + "/testdata/");
00205
00206 bool backend = true, remote = true, transactions = true;
00207 bool positional = true, writable = true, multi = false;
00208 bool spelling = false, metadata = false;
00209 bool quartz = false, flint = false;
00210 #include "api_collated.h"
00211
00212 delete backendmanager;
00213 }
00214 #endif
00215
00216 return result;
00217 }