From 07d5b4a23560b8e667dea0d6364dd2452183451b Mon Sep 17 00:00:00 2001 From: Olly Betts Date: Thu, 21 Dec 2017 17:56:49 +1300 Subject: [PATCH] Start to add honey to test harness --- xapian-core/tests/harness/Makefile.mk | 6 ++ xapian-core/tests/harness/backendmanager_honey.cc | 84 +++++++++++++++++++++++ xapian-core/tests/harness/backendmanager_honey.h | 58 ++++++++++++++++ 3 files changed, 148 insertions(+) create mode 100644 xapian-core/tests/harness/backendmanager_honey.cc create mode 100644 xapian-core/tests/harness/backendmanager_honey.h diff --git a/xapian-core/tests/harness/Makefile.mk b/xapian-core/tests/harness/Makefile.mk index 352eb3251..4c05b0931 100644 --- a/xapian-core/tests/harness/Makefile.mk +++ b/xapian-core/tests/harness/Makefile.mk @@ -4,6 +4,7 @@ EXTRA_DIST +=\ noinst_HEADERS +=\ harness/backendmanager.h\ harness/backendmanager_glass.h\ + harness/backendmanager_honey.h\ harness/backendmanager_inmemory.h\ harness/backendmanager_local.h\ harness/backendmanager_multi.h\ @@ -47,6 +48,11 @@ testharness_sources +=\ harness/backendmanager_singlefile.cc endif +if BUILD_BACKEND_HONEY +testharness_sources +=\ + harness/backendmanager_honey.cc +endif + if BUILD_BACKEND_INMEMORY testharness_sources += harness/backendmanager_inmemory.cc endif diff --git a/xapian-core/tests/harness/backendmanager_honey.cc b/xapian-core/tests/harness/backendmanager_honey.cc new file mode 100644 index 000000000..98faefdf4 --- /dev/null +++ b/xapian-core/tests/harness/backendmanager_honey.cc @@ -0,0 +1,84 @@ +/** @file backendmanager_honey.cc + * @brief BackendManager subclass for honey databases + */ +/* Copyright (C) 2007,2008,2009,2013,2017 Olly Betts + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 2 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#include + +#include "backendmanager_honey.h" + +#include "filetests.h" +#include "index_utils.h" +#include "unixcmds.h" + +#include // For rename(). + +using namespace std; + +string +BackendManagerHoney::get_dbtype() const +{ + return "honey"; +} + +string +BackendManagerHoney::createdb_honey(const vector & files) +{ + string dbdir = ".honey"; + create_dir_if_needed(dbdir); + + string dbname = "db"; + vector::const_iterator i; + for (i = files.begin(); i != files.end(); ++i) { + dbname += "__"; + dbname += *i; + } + string dbpath = dbdir + "/" + dbname; + + if (file_exists(dbpath)) return dbpath; + + string db_source = dbpath + ".src"; + int flags = Xapian::DB_CREATE_OR_OVERWRITE | Xapian::DB_BACKEND_GLASS; + + string tmpfile = dbpath; + tmpfile += ".tmp"; + + Xapian::WritableDatabase db(db_source, flags); + FileIndexer(get_datadir(), files).index_to(db); + db.commit(); + db.compact(tmpfile/*, DBCOMPACT_HONEY*/); + db.close(); + + rm_rf(db_source); + + rename(tmpfile.c_str(), dbpath.c_str()); + + return dbpath; +} + +string +BackendManagerHoney::do_get_database_path(const vector & files) +{ + return createdb_honey(files); +} + +Xapian::WritableDatabase +BackendManagerHoney::get_writable_database(const string &, const string &) +{ + throw Xapian::UnimplementedError("Honey databases don't support writing"); +} diff --git a/xapian-core/tests/harness/backendmanager_honey.h b/xapian-core/tests/harness/backendmanager_honey.h new file mode 100644 index 000000000..5dfeeea8c --- /dev/null +++ b/xapian-core/tests/harness/backendmanager_honey.h @@ -0,0 +1,58 @@ +/** @file backendmanager_honey.h + * @brief BackendManager subclass for honey databases. + */ +/* Copyright (C) 2007,2008,2009,2017 Olly Betts + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 2 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#ifndef XAPIAN_INCLUDED_BACKENDMANAGER_HONEY_H +#define XAPIAN_INCLUDED_BACKENDMANAGER_HONEY_H + +#include "backendmanager.h" + +#include + +#include +#include + +/// BackendManager subclass for honey databases. +class BackendManagerHoney : public BackendManager { + /// Don't allow assignment. + void operator=(const BackendManagerHoney &); + + /// Don't allow copying. + BackendManagerHoney(const BackendManagerHoney &); + + /// The path of the last writable database used. + std::string last_wdb_name; + + std::string createdb_honey(const std::vector & files); + + protected: + /// Get the path of Honey Xapian::Database instance. + std::string do_get_database_path(const std::vector & files); + + public: + BackendManagerHoney() { } + + /// Return a string representing the current database type. + std::string get_dbtype() const; + + /// Create a Xapian::WritableDatabase object. + Xapian::WritableDatabase get_writable_database(const std::string & name, const std::string & file); +}; + +#endif // XAPIAN_INCLUDED_BACKENDMANAGER_HONEY_H -- 2.11.4.GIT