tests/apitest.cc

Go to the documentation of this file.
00001 /* apitest.cc: tests the Xapian API
00002  *
00003  * Copyright 1999,2000,2001 BrightStation PLC
00004  * Copyright 2002 Ananova Ltd
00005  * Copyright 2003,2004,2006,2007,2009 Olly Betts
00006  *
00007  * This program is free software; you can redistribute it and/or
00008  * modify it under the terms of the GNU General Public License as
00009  * published by the Free Software Foundation; either version 2 of the
00010  * License, or (at your option) any later version.
00011  *
00012  * This program is distributed in the hope that it will be useful,
00013  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015  * GNU General Public License for more details.
00016  *
00017  * You should have received a copy of the GNU General Public License
00018  * along with this program; if not, write to the Free Software
00019  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301
00020  * USA
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 string
00071 get_database_path(const string &dbname)
00072 {
00073     return backendmanager->get_database_path(dbname);
00074 }
00075 
00076 string
00077 get_database_path(const std::string &dbname,
00078                   void (*gen)(Xapian::WritableDatabase&,
00079                               const std::string &),
00080                   const std::string &arg)
00081 {
00082     return backendmanager->get_database_path(dbname, gen, arg);
00083 }
00084 
00085 Xapian::WritableDatabase
00086 get_writable_database(const string &dbname)
00087 {
00088     return backendmanager->get_writable_database("dbw", dbname);
00089 }
00090 
00091 Xapian::WritableDatabase
00092 get_named_writable_database(const std::string &name, const std::string &source)
00093 {
00094    return backendmanager->get_writable_database("dbw__" + name, source);
00095 }
00096 
00097 std::string
00098 get_named_writable_database_path(const std::string &name)
00099 {
00100    return backendmanager->get_writable_database_path("dbw__" + name);
00101 }
00102 
00103 Xapian::Database
00104 get_remote_database(const string &dbname, unsigned int timeout)
00105 {
00106     vector<string> dbnames;
00107     dbnames.push_back(dbname);
00108     return backendmanager->get_remote_database(dbnames, timeout);
00109 }
00110 
00111 Xapian::Database
00112 get_writable_database_as_database()
00113 {
00114     return backendmanager->get_writable_database_as_database();
00115 }
00116 
00117 Xapian::WritableDatabase
00118 get_writable_database_again()
00119 {
00120     return backendmanager->get_writable_database_again();
00121 }
00122 
00123 #define USE_BACKEND(B, S) ((B).empty() || (B) == (S))
00124 
00125 int main(int argc, char **argv)
00126 {
00127     string backend_name;
00128     test_driver::add_command_line_option("backend", 'b', &backend_name);
00129 
00130     test_driver::parse_command_line(argc, argv);
00131 
00132     string srcdir = test_driver::get_srcdir();
00133 
00134     int result = 0;
00135 
00136     if (USE_BACKEND(backend_name, "none")) {
00137         backendmanager = new BackendManager;
00138         backendmanager->set_datadir(srcdir + "/testdata/");
00139 
00140         bool backend = false, remote = false, transactions = false;
00141         bool positional = false, writable = false, multi = false;
00142         bool spelling = false, metadata = false;
00143         bool quartz = false, flint = false, inmemory = false;
00144 #include "api_collated.h"
00145 
00146         delete backendmanager;
00147     }
00148 
00149 #ifdef XAPIAN_HAS_INMEMORY_BACKEND
00150     if (USE_BACKEND(backend_name, "inmemory")) {
00151         backendmanager = new BackendManagerInMemory;
00152         backendmanager->set_datadir(srcdir + "/testdata/");
00153 
00154         bool backend = true, remote = false, transactions = false;
00155         bool positional = true, writable = true, multi = false;
00156         bool spelling = false, metadata = true;
00157         bool quartz = false, flint = false, inmemory = true;
00158 #include "api_collated.h"
00159 
00160         delete backendmanager;
00161     }
00162 #endif
00163 
00164 #ifdef XAPIAN_HAS_FLINT_BACKEND
00165     if (USE_BACKEND(backend_name, "flint")) {
00166         backendmanager = new BackendManagerFlint;
00167         backendmanager->set_datadir(srcdir + "/testdata/");
00168 
00169         bool backend = true, remote = false, transactions = true;
00170         bool positional = true, writable = true, multi = false;
00171         bool spelling = true, metadata = true;
00172         bool quartz = false, flint = true, inmemory = false;
00173 #include "api_collated.h"
00174 
00175         delete backendmanager;
00176     }
00177 #endif
00178 
00179 #if defined(XAPIAN_HAS_FLINT_BACKEND) || defined(XAPIAN_HAS_QUARTZ_BACKEND)
00180     if (USE_BACKEND(backend_name, "multi")) {
00181         backendmanager = new BackendManagerMulti;
00182         backendmanager->set_datadir(srcdir + "/testdata/");
00183 
00184         bool backend = true, remote = false, transactions = false;
00185         bool positional = true, writable = false, multi = true;
00186         bool spelling = false, metadata = false;
00187         bool quartz = false, flint = false, inmemory = false;
00188 #include "api_collated.h"
00189 
00190         delete backendmanager;
00191     }
00192 #endif
00193 
00194 #ifdef XAPIAN_HAS_QUARTZ_BACKEND
00195     if (USE_BACKEND(backend_name, "quartz")) {
00196         backendmanager = new BackendManagerQuartz;
00197         backendmanager->set_datadir(srcdir + "/testdata/");
00198 
00199         bool backend = true, remote = false, transactions = true;
00200         bool positional = true, writable = true, multi = false;
00201         bool spelling = false, metadata = false;
00202         bool quartz = true, flint = false, inmemory = false;
00203 #include "api_collated.h"
00204 
00205         delete backendmanager;
00206     }
00207 #endif
00208 
00209 #ifdef XAPIAN_HAS_REMOTE_BACKEND
00210     if (USE_BACKEND(backend_name, "remoteprog")) {
00211         backendmanager = new BackendManagerRemoteProg;
00212         backendmanager->set_datadir(srcdir + "/testdata/");
00213 
00214         bool backend = true, remote = true, transactions = true;
00215         bool positional = true, writable = true, multi = false;
00216         bool spelling = false, metadata = false;
00217         bool quartz = false, flint = false, inmemory = false;
00218 #include "api_collated.h"
00219 
00220         delete backendmanager;
00221     }
00222 
00223     if (USE_BACKEND(backend_name, "remotetcp")) {
00224         backendmanager = new BackendManagerRemoteTcp;
00225         backendmanager->set_datadir(srcdir + "/testdata/");
00226 
00227         bool backend = true, remote = true, transactions = true;
00228         bool positional = true, writable = true, multi = false;
00229         bool spelling = false, metadata = false;
00230         bool quartz = false, flint = false, inmemory = false;
00231 #include "api_collated.h"
00232 
00233         delete backendmanager;
00234     }
00235 #endif
00236 
00237     return result;
00238 }

Documentation for Xapian (version 1.0.20).
Generated on 28 Apr 2010 by Doxygen 1.5.2.